1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-07 23:03:00 +03:00

Lexical: Updated dropdown handling to match tinymce behaviour

Now toolbars stay open on mouse-out, and close on other toolbar open,
outside click or an accepted action.
To support:
- Added new system to track and manage open dropdowns.
- Added way for buttons to optionally emit events upon actions.
- Added way to listen for events.
- Used the above to control when dropdowns should hide on action, since
  some dont (like overflow containers and split dropdown buttons).
This commit is contained in:
Dan Brown
2025-05-25 16:28:42 +01:00
parent 3280919370
commit 1243108e0f
7 changed files with 120 additions and 43 deletions

View File

@@ -10,7 +10,12 @@ export interface EditorBasicButtonDefinition {
}
export interface EditorButtonDefinition extends EditorBasicButtonDefinition {
action: (context: EditorUiContext, button: EditorButton) => void;
/**
* The action to perform when the button is used.
* This can return false to indicate that the completion of the action should
* NOT be communicated to parent UI elements, which is what occurs by default.
*/
action: (context: EditorUiContext, button: EditorButton) => void|false;
isActive: (selection: BaseSelection|null, context: EditorUiContext) => boolean;
isDisabled?: (selection: BaseSelection|null, context: EditorUiContext) => boolean;
setup?: (context: EditorUiContext, button: EditorButton) => void;
@@ -78,7 +83,10 @@ export class EditorButton extends EditorUiElement {
}
protected onClick() {
this.definition.action(this.getContext(), this);
const result = this.definition.action(this.getContext(), this);
if (result !== false) {
this.emitEvent('button-action');
}
}
protected updateActiveState(selection: BaseSelection|null) {