Skip to content

Commit

Permalink
Merge pull request #15277 from opf/fix/move-dropdowns-into-top-layer
Browse files Browse the repository at this point in the history
Fix/move dropdowns into top layer
  • Loading branch information
oliverguenther committed Apr 16, 2024
2 parents 1f65b10 + 4abe814 commit 538f733
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl

@Input() public macros:ICKEditorMacroType;

@Input() public removePlugins:string[] = [];

@Input() public resource?:object;

@Input() public turboMode = false;
Expand Down Expand Up @@ -130,6 +132,7 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
type: this.editorType,
resource: this.halResource,
previewContext: this.previewContext,
removePlugins: this.removePlugins,
};
if (this.readOnly) {
this.context.macros = 'none';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class CKEditorSetupService {

public initialize() {
this.prefetch = this.load();
this.watchTopLayer();
}

/**
Expand All @@ -45,7 +46,8 @@ export class CKEditorSetupService {
* @returns {Promise<ICKEditorWatchdog>}
*/
public async create(
wrapper:HTMLElement, context:ICKEditorContext,
wrapper:HTMLElement,
context:ICKEditorContext,
initialData:string|null = null,
):Promise<ICKEditorWatchdog> {
// Load the bundle and the matching locale, if found.
Expand All @@ -62,6 +64,7 @@ export class CKEditorSetupService {

const config = {
openProject: this.createConfig(context),
removePlugins: context.removePlugins,
initialData,
language: {
ui: uiLocale,
Expand Down Expand Up @@ -144,4 +147,31 @@ export class CKEditorSetupService {
pluginContext: window.OpenProject.pluginContext.value,
};
}

private watchTopLayer() {
const targetClassNames = ['ck-body-wrapper', 'ck-inspector-'];

const observer = new MutationObserver((mutations) => {
const dialog = document.querySelector('dialog[open]');
if (!dialog) {
return;
}

mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (!(node instanceof HTMLElement)) {
return;
}

if (targetClassNames.some((className) => node.classList.contains(className))) {
dialog.append(node);
}
});
});
});

observer.observe(document.body, {
childList: true,
});
}
}
3 changes: 2 additions & 1 deletion lib/primer/open_project/forms/rich_text_area.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
inputs: @rich_text_options.reverse_merge(
{
textareaSelector: "##{builder.field_id(@input.name)}",
macros: 'resource',
removePlugins: ["CodeBlock"],
macros: false,
turboMode: true
}
)
Expand Down

0 comments on commit 538f733

Please sign in to comment.