From 7290f47be9438377dcd7d5832d66a142fa602faf Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Mon, 12 Jun 2023 20:40:43 +1000 Subject: [PATCH] update code editor modal to init editor correctly --- .../code-editor/code-editor-modal.element.ts | 58 +++++++++++++------ .../plugins/tiny-mce-code-editor.plugin.ts | 4 +- .../code-editor/code-editor.element.ts | 2 + 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/modal/common/code-editor/code-editor-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/modal/common/code-editor/code-editor-modal.element.ts index 1a36ae30e5..83498c0147 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/modal/common/code-editor/code-editor-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/modal/common/code-editor/code-editor-modal.element.ts @@ -1,17 +1,24 @@ -import { customElement, query } from 'lit/decorators.js'; -import { css, html } from 'lit'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { UmbCodeEditorElement } from '@umbraco-cms/backoffice/code-editor'; -import { UUITextStyles } from '@umbraco-cms/backoffice/external/uui'; +import { css, html, ifDefined, customElement, query } from '@umbraco-cms/backoffice/external/lit'; +import { loadCodeEditor, type UmbCodeEditorElement } from '@umbraco-cms/backoffice/code-editor'; +import { UUITextStyles, UUIInputEvent } from '@umbraco-cms/backoffice/external/uui'; import { UmbCodeEditorModalData, UmbCodeEditorModalResult } from '@umbraco-cms/backoffice/modal'; -import { UmbInputEvent } from '@umbraco-cms/backoffice/events'; import { UmbModalBaseElement } from '@umbraco-cms/internal/modal'; +import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api'; @customElement('umb-code-editor-modal') export class UmbCodeEditorModalElement extends UmbModalBaseElement { + #isCodeEditorReady = new UmbBooleanState(false); + isCodeEditorReady = this.#isCodeEditorReady.asObservable(); + @query('umb-code-editor') _codeEditor?: UmbCodeEditorElement; + constructor() { + super(); + + this.#loadCodeEditor(); + } + #handleConfirm() { this.modalContext?.submit({ content: this.data?.content ?? '' }); } @@ -20,25 +27,42 @@ export class UmbCodeEditorModalElement extends UmbModalBaseElement debounce? - #onCodeEditorInput(e: UmbInputEvent) { + #onCodeEditorInput(e: UUIInputEvent) { e.preventDefault(); if (!this.data) { return; } - this.data.content = this._codeEditor?.code ?? ''; + this.data.content = this._codeEditor?.code ?? ''; + } + + #renderCodeEditor() { + return html``; + } + + #renderLoading() { + return html`
+ +
`; } render() { return html` -
- -
+
${this.isCodeEditorReady ? this.#renderCodeEditor() : this.#renderLoading()}
Cancel ): void {