simplifying the use of props (#18430)

This commit is contained in:
Niels Lyngsø
2025-02-24 19:50:29 +01:00
committed by GitHub
parent 3e291894e5
commit 347e898190
5 changed files with 11 additions and 14 deletions

View File

@@ -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,

View File

@@ -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 : '';

View File

@@ -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: [],

View File

@@ -19,6 +19,7 @@ const TIPTAP_CORE_EXTENSION_ALIAS = 'Umb.Tiptap.RichTextEssentials';
export class UmbInputTiptapElement extends UmbFormControlMixin<string, typeof UmbLitElement, string>(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.

View File

@@ -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: [],