chore: change the button to a toggle button and add an onSetup callback to toggle the button active/inactive when you click on elements
This commit is contained in:
@@ -6,10 +6,22 @@ export default class UmbTinyMceEmbeddedMediaPlugin extends UmbTinyMcePluginBase
|
||||
constructor(args: TinyMcePluginArguments) {
|
||||
super(args);
|
||||
|
||||
this.editor.ui.registry.addButton('umbembeddialog', {
|
||||
this.editor.ui.registry.addToggleButton('umbembeddialog', {
|
||||
icon: 'embed',
|
||||
tooltip: 'Embed',
|
||||
onAction: () => this.#onAction(),
|
||||
onSetup: (api) => {
|
||||
const editor = this.editor;
|
||||
const onNodeChange = () => {
|
||||
const selectedElm = editor.selection.getNode();
|
||||
api.setActive(
|
||||
selectedElm.nodeName.toUpperCase() === 'DIV' && selectedElm.classList.contains('umb-embed-holder'),
|
||||
);
|
||||
};
|
||||
|
||||
editor.on('NodeChange', onNodeChange);
|
||||
return () => editor.off('NodeChange', onNodeChange);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user