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:
Jacob Overgaard
2024-05-03 15:17:24 +02:00
parent 6f2cd918d9
commit ac59563ddb

View File

@@ -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);
},
});
}