From 347e898190f84cd79ec67fb6e6cb851d2c6f8875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Mon, 24 Feb 2025 19:50:29 +0100 Subject: [PATCH] simplifying the use of props (#18430) --- .../src/packages/rte/components/rte-base.element.ts | 11 +++-------- .../input-tiny-mce/input-tiny-mce.element.ts | 1 + .../tiny-mce/property-editor-ui-tiny-mce.element.ts | 6 +++--- .../components/input-tiptap/input-tiptap.element.ts | 1 + .../tiptap/property-editor-ui-tiptap.element.ts | 6 +++--- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/rte/components/rte-base.element.ts b/src/Umbraco.Web.UI.Client/src/packages/rte/components/rte-base.element.ts index 9e4c70c5c3..07b52ae1b5 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/rte/components/rte-base.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/rte/components/rte-base.element.ts @@ -34,7 +34,7 @@ export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement im public set value(value: UmbPropertyEditorUiValueType | undefined) { if (!value) { this._value = undefined; - this._markup = this._latestMarkup = ''; + this._markup = ''; this.#managerContext.setLayouts([]); this.#managerContext.setContents([]); this.#managerContext.setSettings([]); @@ -52,7 +52,7 @@ export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement im this._value = buildUpValue as UmbPropertyEditorUiValueType; // Only update the actual editor markup if it is not the same as the value. - if (this._latestMarkup !== this._value.markup) { + if (this._markup !== this._value.markup) { this._markup = this._value.markup; } @@ -84,11 +84,6 @@ export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement im @state() protected _markup = ''; - /** - * The latest value gotten from the RTE editor. - */ - protected _latestMarkup = ''; - readonly #managerContext = new UmbBlockRteManagerContext(this); readonly #entriesContext = new UmbBlockRteEntriesContext(this); @@ -141,7 +136,7 @@ export abstract class UmbPropertyEditorUiRteElementBase extends UmbLitElement im this._value = undefined; } else { this._value = { - markup: this._latestMarkup, + markup: this._markup, blocks: { layout: { [UMB_BLOCK_RTE_PROPERTY_EDITOR_SCHEMA_ALIAS]: layouts }, contentData: contents, diff --git a/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/components/input-tiny-mce/input-tiny-mce.element.ts b/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/components/input-tiny-mce/input-tiny-mce.element.ts index c61116da94..bcd7a805bc 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/components/input-tiny-mce/input-tiny-mce.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/components/input-tiny-mce/input-tiny-mce.element.ts @@ -61,6 +61,7 @@ export class UmbInputTinyMceElement extends UUIFormControlMixin(UmbLitElement, ' } override set value(newValue: FormDataEntryValue | FormData) { + if (newValue === this.value) return; super.value = newValue; const newContent = typeof newValue === 'string' ? newValue : ''; diff --git a/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/property-editors/tiny-mce/property-editor-ui-tiny-mce.element.ts b/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/property-editors/tiny-mce/property-editor-ui-tiny-mce.element.ts index 9d375b8f38..bbbf2d8071 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/property-editors/tiny-mce/property-editor-ui-tiny-mce.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/property-editors/tiny-mce/property-editor-ui-tiny-mce.element.ts @@ -43,16 +43,16 @@ export class UmbPropertyEditorUITinyMceElement extends UmbPropertyEditorUiRteEle // Then get the content of the editor and update the value. // maybe in this way doc.body.innerHTML; - this._latestMarkup = markup; + this._markup = markup; if (this.value) { this.value = { ...this.value, - markup: this._latestMarkup, + markup: this._markup, }; } else { this.value = { - markup: this._latestMarkup, + markup: this._markup, blocks: { layout: {}, contentData: [], diff --git a/src/Umbraco.Web.UI.Client/src/packages/tiptap/components/input-tiptap/input-tiptap.element.ts b/src/Umbraco.Web.UI.Client/src/packages/tiptap/components/input-tiptap/input-tiptap.element.ts index 9213cd8be1..748a3c6f50 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/tiptap/components/input-tiptap/input-tiptap.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/tiptap/components/input-tiptap/input-tiptap.element.ts @@ -19,6 +19,7 @@ const TIPTAP_CORE_EXTENSION_ALIAS = 'Umb.Tiptap.RichTextEssentials'; export class UmbInputTiptapElement extends UmbFormControlMixin(UmbLitElement) { @property({ type: String }) override set value(value: string) { + if (value === this.#value) return; this.#value = value; // Try to set the value to the editor if it is ready. diff --git a/src/Umbraco.Web.UI.Client/src/packages/tiptap/property-editors/tiptap/property-editor-ui-tiptap.element.ts b/src/Umbraco.Web.UI.Client/src/packages/tiptap/property-editors/tiptap/property-editor-ui-tiptap.element.ts index cff1839022..ae0ba95d23 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/tiptap/property-editors/tiptap/property-editor-ui-tiptap.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/tiptap/property-editors/tiptap/property-editor-ui-tiptap.element.ts @@ -36,16 +36,16 @@ export class UmbPropertyEditorUiTiptapElement extends UmbPropertyEditorUiRteElem this._filterUnusedBlocks(usedContentKeys); - this._latestMarkup = value; + this._markup = value; if (this.value) { this.value = { ...this.value, - markup: this._latestMarkup, + markup: this._markup, }; } else { this.value = { - markup: this._latestMarkup, + markup: this._markup, blocks: { layout: {}, contentData: [],