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

@@ -1,4 +1,3 @@
import {handleDropdown} from "../helpers/dropdowns";
import {EditorContainerUiElement, EditorUiElement} from "../core";
import {EditorBasicButtonDefinition, EditorButton} from "../buttons";
import {el} from "../../../utils/dom";
@@ -8,6 +7,7 @@ export type EditorDropdownButtonOptions = {
showOnHover?: boolean;
direction?: 'vertical'|'horizontal';
showAside?: boolean;
hideOnAction?: boolean;
button: EditorBasicButtonDefinition|EditorButton;
};
@@ -15,6 +15,7 @@ const defaultOptions: EditorDropdownButtonOptions = {
showOnHover: false,
direction: 'horizontal',
showAside: undefined,
hideOnAction: true,
button: {label: 'Menu'},
}
@@ -40,7 +41,7 @@ export class EditorDropdownButton extends EditorContainerUiElement {
},
isActive: () => {
return this.open;
}
},
});
}
@@ -65,7 +66,7 @@ export class EditorDropdownButton extends EditorContainerUiElement {
class: 'editor-dropdown-menu-container',
}, [button, menu]);
handleDropdown({toggle: button, menu : menu,
this.getContext().manager.dropdowns.handle({toggle: button, menu : menu,
showOnHover: this.options.showOnHover,
showAside: typeof this.options.showAside === 'boolean' ? this.options.showAside : (this.options.direction === 'vertical'),
onOpen : () => {
@@ -76,6 +77,12 @@ export class EditorDropdownButton extends EditorContainerUiElement {
this.getContext().manager.triggerStateUpdateForElement(this.button);
}});
if (this.options.hideOnAction) {
this.onEvent('button-action', () => {
this.getContext().manager.dropdowns.closeAll();
}, wrapper);
}
return wrapper;
}
}