diff --git a/ui/guest/src/contentController.ts b/ui/guest/src/contentController.ts index 360db06585..77867c48cf 100644 --- a/ui/guest/src/contentController.ts +++ b/ui/guest/src/contentController.ts @@ -170,9 +170,9 @@ export function byPathFetchIfNotLoaded(path: string): Observable Boolean(paths[path])), - map((paths) => paths[path]), - map((modelId) => models$.value[modelId]) + map((paths) => models$.value[paths[path]]) ); } else { requestedPaths[path] = true; diff --git a/ui/guest/src/elementRegistry.ts b/ui/guest/src/elementRegistry.ts index d56055e2f6..80339697b0 100644 --- a/ui/guest/src/elementRegistry.ts +++ b/ui/guest/src/elementRegistry.ts @@ -133,18 +133,18 @@ export function register(payload: ElementRecordRegistration): number { ? fieldId : fieldId.split(',').map((str) => str.trim()); - function create() { + function create(inheritanceParentModelId?: string) { // Create/register the physical record db[id] = { id, element, - modelId, + modelId: inheritanceParentModelId ?? modelId, index, label, fieldId: fieldIds, iceIds, complete: false, - inherited: fieldIds.some((fieldId) => isInheritedField(modelId, fieldId)) + inherited: fieldIds.some((fieldId) => isInheritedField(inheritanceParentModelId ?? modelId, fieldId)) }; } @@ -154,11 +154,12 @@ export function register(payload: ElementRecordRegistration): number { // for the model to be loaded. if (isInheritedField(model.craftercms.id, fieldId)) { byPathFetchIfNotLoaded(model.craftercms.sourceMap?.[fieldId]).subscribe((response) => { + const sourceModelId = response.craftercms.id; model$(response.craftercms.id) .pipe(take(1)) .subscribe(() => { - create(); - completeDeferredRegistration(id); + create(sourceModelId); + completeDeferredRegistration(id, sourceModelId); }); }); } else { @@ -183,13 +184,13 @@ export function register(payload: ElementRecordRegistration): number { return id; } -export function completeDeferredRegistration(id: number): void { +export function completeDeferredRegistration(id: number, inheritanceParentModelId?: string): void { const record = db[id]; const { modelId, index, fieldId: fieldIds, iceIds } = record; if (fieldIds.length > 0) { fieldIds.forEach((fieldId) => { - const iceId = iceRegistry.register({ modelId, index, fieldId }); + const iceId = iceRegistry.register({ modelId: inheritanceParentModelId ?? modelId, index, fieldId }); if (!registry[iceId]) { registry[iceId] = []; } @@ -197,7 +198,7 @@ export function completeDeferredRegistration(id: number): void { !iceIds.includes(iceId) && iceIds.push(iceId); }); } else { - const iceId = iceRegistry.register({ modelId, index }); + const iceId = iceRegistry.register({ modelId: inheritanceParentModelId ?? modelId, index }); if (!registry[iceId]) { registry[iceId] = []; } diff --git a/ui/guest/src/react/GuestProxy.tsx b/ui/guest/src/react/GuestProxy.tsx index c4e9f5fce8..0159782efb 100644 --- a/ui/guest/src/react/GuestProxy.tsx +++ b/ui/guest/src/react/GuestProxy.tsx @@ -381,6 +381,9 @@ export function GuestProxy() { spinner = spinner.firstChild as HTMLDivElement; const daddy = getParentElementFromICEProps(modelId, fieldId, targetIndex); + // 'daddy' element contains the model of the item that inherits field. Retrieving the model for latter usage + // when rendering the new component. + const inheritedModelId = daddy.getAttribute('data-craftercms-model-id'); // If daddy has children, get the closest one to the one that is being added, and get its width to set it // to the spinner container. @@ -422,8 +425,8 @@ export function GuestProxy() { ifrm.onload = function () { spinner.remove(); - const itemElement = ifrm.contentWindow.document.documentElement.querySelector( - `[data-craftercms-model-id="${modelId}"][data-craftercms-field-id="${fieldId}"][data-craftercms-index="${targetIndex}"]` + let itemElement = ifrm.contentWindow.document.documentElement.querySelector( + `[data-craftercms-model-id="${inheritedModelId}"][data-craftercms-field-id="${fieldId}"][data-craftercms-index="${targetIndex}"]` ); let component = document.createElement('div'); component.innerHTML = itemElement?.outerHTML; diff --git a/ui/guest/src/react/ZoneMenu.tsx b/ui/guest/src/react/ZoneMenu.tsx index e387faa977..c570c3c056 100644 --- a/ui/guest/src/react/ZoneMenu.tsx +++ b/ui/guest/src/react/ZoneMenu.tsx @@ -180,7 +180,7 @@ export function ZoneMenu(props: ZoneMenuProps) { const itemFieldId = isNodeSelectorItem ? nodeSelectorItemRecord.fieldId : fieldId; const itemIndex = isNodeSelectorItem ? nodeSelectorItemRecord.index : index; const parentModelId = getParentModelId(itemModelId, models, modelHierarchyMap); - const path = models[parentModelId ?? itemModelId].craftercms.path; + const path = modelPath; return { path, itemModelId, itemFieldId, itemIndex }; };