From fdb13f296e57a314f5891d1470473a4aa5334673 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Fri, 23 Jun 2023 14:54:08 +0200 Subject: [PATCH] fetch and merge config with plugin toolbar config --- ...-tiny-mce-toolbar-configuration.element.ts | 68 +++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/property-editors/uis/tiny-mce/config/toolbar/property-editor-ui-tiny-mce-toolbar-configuration.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/property-editors/uis/tiny-mce/config/toolbar/property-editor-ui-tiny-mce-toolbar-configuration.element.ts index e094a3f741..51e779b28a 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/property-editors/uis/tiny-mce/config/toolbar/property-editor-ui-tiny-mce-toolbar-configuration.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/property-editors/uis/tiny-mce/config/toolbar/property-editor-ui-tiny-mce-toolbar-configuration.element.ts @@ -1,21 +1,81 @@ import { UUITextStyles } from '@umbraco-cms/backoffice/external/uui'; -import { customElement, css, html, property } from '@umbraco-cms/backoffice/external/lit'; +import { customElement, css, html, property, map, state, PropertyValueMap } from '@umbraco-cms/backoffice/external/lit'; import { UmbLitElement } from '@umbraco-cms/internal/lit-element'; +import { UmbPropertyEditorExtensionElement, umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry'; +import { firstValueFrom } from '@umbraco-cms/backoffice/external/rxjs'; +import { UmbDataTypePropertyCollection } from '@umbraco-cms/backoffice/components'; + +type ToolbarConfig = { + alias: string; + label: string; + icon: string; + selected: boolean; +}; /** * @element umb-property-editor-ui-tiny-mce-toolbar-configuration */ @customElement('umb-property-editor-ui-tiny-mce-toolbar-configuration') -export class UmbPropertyEditorUITinyMceToolbarConfigurationElement extends UmbLitElement { +export class UmbPropertyEditorUITinyMceToolbarConfigurationElement + extends UmbLitElement + implements UmbPropertyEditorExtensionElement +{ @property() value: string[] = []; @property({ type: Array, attribute: false }) - public config = []; + config?: UmbDataTypePropertyCollection; + + @state() + private _toolbarConfig: ToolbarConfig[] = []; + + async firstUpdated(_changedProperties: PropertyValueMap) { + super.firstUpdated(_changedProperties); + + this.config?.getValueByAlias('toolbar')?.forEach((v) => { + this._toolbarConfig.push({ + ...v, + selected: this.value.includes(v.alias), + }); + }); + + await this.getToolbarPlugins(); + + this.requestUpdate('_toolbarConfig'); + } + + async getToolbarPlugins(): Promise { + // Get all the toolbar plugins + const plugin$ = umbExtensionsRegistry.extensionsOfType('tinyMcePlugin'); + + const plugins = await firstValueFrom(plugin$); + + plugins.forEach((p) => { + // If the plugin has a toolbar, add it to the config + if (p.meta?.toolbar) { + p.meta.toolbar.forEach((t) => { + this._toolbarConfig.push({ + alias: t.alias, + label: t.label, + icon: t.icon ?? 'umb:autofill', + selected: this.value.includes(t.alias), + }); + }); + } + }); + } render() { return html`
    - ${this.value.map((v) => html`
  • ${v}
  • `)} + ${map( + this._toolbarConfig, + (v) => html`
  • + + + ${v.label} + +
  • ` + )}
`; }