fix: revert back to single value updates in multiple observers to avoid issues where a value set in one array would "remove" the other values, because this ends up triggering the property value change
This commit is contained in:
@@ -120,7 +120,34 @@ export abstract class UmbRteBaseElement extends UmbLitElement implements UmbProp
|
||||
'observePropertyAlias',
|
||||
);
|
||||
|
||||
this.observe(
|
||||
this.observe(this.#entriesContext.layoutEntries, (layouts) => {
|
||||
// Update manager:
|
||||
this.#managerContext.setLayouts(layouts);
|
||||
});
|
||||
|
||||
// Observe the value of the property and update the editor value.
|
||||
this.observe(this.#managerContext.layouts, (layouts) => {
|
||||
this._value = {
|
||||
...this._value,
|
||||
blocks: { ...this._value.blocks, layout: { [UMB_BLOCK_RTE_PROPERTY_EDITOR_SCHEMA_ALIAS]: layouts } },
|
||||
};
|
||||
this._fireChangeEvent();
|
||||
});
|
||||
this.observe(this.#managerContext.contents, (contents) => {
|
||||
this._value = { ...this._value, blocks: { ...this._value.blocks, contentData: contents } };
|
||||
this._fireChangeEvent();
|
||||
});
|
||||
this.observe(this.#managerContext.settings, (settings) => {
|
||||
this._value = { ...this._value, blocks: { ...this._value.blocks, settingsData: settings } };
|
||||
this._fireChangeEvent();
|
||||
});
|
||||
this.observe(this.#managerContext.exposes, (exposes) => {
|
||||
this._value = { ...this._value, blocks: { ...this._value.blocks, expose: exposes } };
|
||||
this._fireChangeEvent();
|
||||
});
|
||||
|
||||
// The above could potentially be replaced with a single observeMultiple call, but it is not done for now to avoid potential issues with the order of the updates.
|
||||
/*this.observe(
|
||||
observeMultiple([
|
||||
this.#managerContext.layouts,
|
||||
this.#managerContext.contents,
|
||||
@@ -141,7 +168,7 @@ export abstract class UmbRteBaseElement extends UmbLitElement implements UmbProp
|
||||
this._fireChangeEvent();
|
||||
},
|
||||
'motherObserver',
|
||||
);
|
||||
);*/
|
||||
});
|
||||
this.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, (context) => {
|
||||
this.#managerContext.setVariantId(context.getVariantId());
|
||||
@@ -154,6 +181,10 @@ export abstract class UmbRteBaseElement extends UmbLitElement implements UmbProp
|
||||
}
|
||||
|
||||
protected _filterUnusedBlocks(usedContentKeys: (string | null)[]) {
|
||||
const unusedBlockContents = this.#managerContext.getContents().filter((x) => usedContentKeys.indexOf(x.key) === -1);
|
||||
unusedBlockContents.forEach((blockContent) => {
|
||||
this.#managerContext.removeOneContent(blockContent.key);
|
||||
});
|
||||
const unusedBlocks = this.#managerContext.getLayouts().filter((x) => usedContentKeys.indexOf(x.contentKey) === -1);
|
||||
unusedBlocks.forEach((blockLayout) => {
|
||||
this.#managerContext.removeOneLayout(blockLayout.contentKey);
|
||||
|
||||
Reference in New Issue
Block a user