Skip to content

Commit 7caf006

Browse files
committed
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
1 parent deef2ab commit 7caf006

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/packages/rte/components/rte-base.element.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,34 @@ export abstract class UmbRteBaseElement extends UmbLitElement implements UmbProp
120120
'observePropertyAlias',
121121
);
122122

123-
this.observe(
123+
this.observe(this.#entriesContext.layoutEntries, (layouts) => {
124+
// Update manager:
125+
this.#managerContext.setLayouts(layouts);
126+
});
127+
128+
// Observe the value of the property and update the editor value.
129+
this.observe(this.#managerContext.layouts, (layouts) => {
130+
this._value = {
131+
...this._value,
132+
blocks: { ...this._value.blocks, layout: { [UMB_BLOCK_RTE_PROPERTY_EDITOR_SCHEMA_ALIAS]: layouts } },
133+
};
134+
this._fireChangeEvent();
135+
});
136+
this.observe(this.#managerContext.contents, (contents) => {
137+
this._value = { ...this._value, blocks: { ...this._value.blocks, contentData: contents } };
138+
this._fireChangeEvent();
139+
});
140+
this.observe(this.#managerContext.settings, (settings) => {
141+
this._value = { ...this._value, blocks: { ...this._value.blocks, settingsData: settings } };
142+
this._fireChangeEvent();
143+
});
144+
this.observe(this.#managerContext.exposes, (exposes) => {
145+
this._value = { ...this._value, blocks: { ...this._value.blocks, expose: exposes } };
146+
this._fireChangeEvent();
147+
});
148+
149+
// 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.
150+
/*this.observe(
124151
observeMultiple([
125152
this.#managerContext.layouts,
126153
this.#managerContext.contents,
@@ -141,7 +168,7 @@ export abstract class UmbRteBaseElement extends UmbLitElement implements UmbProp
141168
this._fireChangeEvent();
142169
},
143170
'motherObserver',
144-
);
171+
);*/
145172
});
146173
this.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, (context) => {
147174
this.#managerContext.setVariantId(context.getVariantId());
@@ -154,6 +181,10 @@ export abstract class UmbRteBaseElement extends UmbLitElement implements UmbProp
154181
}
155182

156183
protected _filterUnusedBlocks(usedContentKeys: (string | null)[]) {
184+
const unusedBlockContents = this.#managerContext.getContents().filter((x) => usedContentKeys.indexOf(x.key) === -1);
185+
unusedBlockContents.forEach((blockContent) => {
186+
this.#managerContext.removeOneContent(blockContent.key);
187+
});
157188
const unusedBlocks = this.#managerContext.getLayouts().filter((x) => usedContentKeys.indexOf(x.contentKey) === -1);
158189
unusedBlocks.forEach((blockLayout) => {
159190
this.#managerContext.removeOneLayout(blockLayout.contentKey);

0 commit comments

Comments
 (0)