Skip to content

Commit a447561

Browse files
committed
WYSIWYG: Aligned double click to set label for details functionality
Aligned the behaviour across the WYSIWYG editors, and also for nested details blocks (which wasn't working in the TinyMCE implementation). Closes #6059
1 parent fa1dc16 commit a447561

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

resources/js/wysiwyg-tinymce/plugins-details.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function setSummary(editor, summaryContent) {
1919
}
2020
summary.textContent = summaryContent;
2121
});
22+
23+
editor.selection.select(details);
2224
}
2325

2426
/**
@@ -202,8 +204,12 @@ function register(editor) {
202204
});
203205

204206
editor.on('dblclick', event => {
205-
if (!getSelectedDetailsBlock(editor) || event.target.closest('doc-root')) return;
206-
showDetailLabelEditWindow(editor);
207+
const domElClass = event?.target?.ownerDocument?.defaultView?.HTMLDetailsElement;
208+
if (domElClass && event.target instanceof domElClass && getSelectedDetailsBlock(editor)) {
209+
showDetailLabelEditWindow(editor);
210+
event.preventDefault();
211+
event.stopPropagation();
212+
}
207213
});
208214

209215
editor.ui.registry.addButton('toggledetails', {

resources/js/wysiwyg/lexical/core/LexicalEditor.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {LineBreakNode} from './nodes/LexicalLineBreakNode';
4545
import {ParagraphNode} from './nodes/LexicalParagraphNode';
4646
import {RootNode} from './nodes/LexicalRootNode';
4747
import {TabNode} from './nodes/LexicalTabNode';
48+
import {EditorUiContext} from "../../ui/framework/core";
4849

4950
export type Spread<T1, T2> = Omit<T2, keyof T1> & T1;
5051

@@ -621,6 +622,8 @@ export class LexicalEditor {
621622
_editable: boolean;
622623
/** @internal */
623624
_blockCursorElement: null | HTMLDivElement;
625+
/** @internal */
626+
_context: null | EditorUiContext;
624627

625628
/** @internal */
626629
constructor(
@@ -682,6 +685,7 @@ export class LexicalEditor {
682685
this._headless = parentEditor !== null && parentEditor._headless;
683686
this._window = null;
684687
this._blockCursorElement = null;
688+
this._context = null;
685689
}
686690

687691
/**
@@ -1285,6 +1289,21 @@ export class LexicalEditor {
12851289
triggerListeners('editable', this, true, editable);
12861290
}
12871291
}
1292+
1293+
/**
1294+
* Set the UI context that this editor is intended to be part of.
1295+
*/
1296+
setUiContext(context: EditorUiContext) {
1297+
this._context = context;
1298+
}
1299+
1300+
/**
1301+
* Get the UI context that this editor is considered to be part of.
1302+
*/
1303+
getUiContext(): EditorUiContext|null {
1304+
return this._context;
1305+
}
1306+
12881307
/**
12891308
* Returns a JSON-serializable javascript object NOT a JSON string.
12901309
* You still must call JSON.stringify (or something else) to turn the

resources/js/wysiwyg/lexical/rich-text/LexicalDetailsNode.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from 'lexical';
1010

1111
import {extractDirectionFromElement} from "lexical/nodes/common";
12+
import {$showDetailsForm} from "../../ui/defaults/forms/objects";
1213

1314
export type SerializedDetailsNode = Spread<{
1415
id: string;
@@ -90,6 +91,16 @@ export class DetailsNode extends ElementNode {
9091
});
9192
});
9293

94+
summary.addEventListener('dblclick', event => {
95+
event.preventDefault();
96+
const uiContext = _editor.getUiContext();
97+
if (uiContext) {
98+
_editor.read(() => {
99+
$showDetailsForm(this, uiContext);
100+
});
101+
}
102+
});
103+
93104
el.append(summary);
94105

95106
return el;

resources/js/wysiwyg/ui/defaults/buttons/objects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export const detailsEditLabel: EditorButtonDefinition = {
221221
if ($isDetailsNode(details)) {
222222
$showDetailsForm(details, context);
223223
}
224-
})
224+
});
225225
},
226226
isActive(selection: BaseSelection | null): boolean {
227227
return false;

resources/js/wysiwyg/ui/framework/manager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class EditorUIManager {
2929
setContext(context: EditorUiContext) {
3030
this.context = context;
3131
this.setupEventListeners();
32-
this.setupEditor(context.editor);
32+
this.setupEditor(context.editor, context);
3333
}
3434

3535
getContext(): EditorUiContext {
@@ -256,7 +256,10 @@ export class EditorUIManager {
256256
}
257257
}
258258

259-
protected setupEditor(editor: LexicalEditor) {
259+
protected setupEditor(editor: LexicalEditor, context: EditorUiContext) {
260+
// Pass the context to the editor
261+
editor.setUiContext(context);
262+
260263
// Register our DOM decorate listener with the editor
261264
const domDecorateListener: DecoratorListener<EditorDecoratorAdapter> = (decorators: Record<NodeKey, EditorDecoratorAdapter>) => {
262265
editor.getEditorState().read(() => {

0 commit comments

Comments
 (0)