@contentstack/studio-react-editor 1.8.0 β 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/AddIcon.js +18 -0
- package/dist/components/AddIcon.js.map +1 -0
- package/dist/components/BuildingIllustration.js +1 -1
- package/dist/components/BuildingIllustration.js.map +1 -1
- package/dist/components/EditableRenderer.js +6 -4
- package/dist/components/EditableRenderer.js.map +1 -1
- package/dist/components/Element.js +60 -29
- package/dist/components/Element.js.map +1 -1
- package/dist/components/Slot.js +5 -4
- package/dist/components/Slot.js.map +1 -1
- package/dist/components/WelcomeState.js +44 -11
- package/dist/components/WelcomeState.js.map +1 -1
- package/dist/components/elements/ConditionBlock.js +7 -20
- package/dist/components/elements/ConditionBlock.js.map +1 -1
- package/dist/components/elements/SectionComposition.js +2 -1
- package/dist/components/elements/SectionComposition.js.map +1 -1
- package/dist/components/elements/SectionSlot.js +13 -42
- package/dist/components/elements/SectionSlot.js.map +1 -1
- package/dist/components/styles.js +71 -67
- package/dist/components/styles.js.map +1 -1
- package/dist/contexts/providers/edit-context.provider.js +2 -2
- package/dist/contexts/providers/edit-context.provider.js.map +1 -1
- package/dist/contexts/providers/selected-node.provider.js +7 -1
- package/dist/contexts/providers/selected-node.provider.js.map +1 -1
- package/dist/hooks/use-active-node-path.hook.js +1 -1
- package/dist/hooks/use-active-node-path.hook.js.map +1 -1
- package/dist/hooks/use-canvas-events.hook.js +2 -1
- package/dist/hooks/use-canvas-events.hook.js.map +1 -1
- package/dist/hooks/use-edit-context-listener.hook.js +2 -1
- package/dist/hooks/use-edit-context-listener.hook.js.map +1 -1
- package/dist/hooks/use-section-events.hook.js +2 -1
- package/dist/hooks/use-section-events.hook.js.map +1 -1
- package/dist/hooks/use-slot-copy-color.hook.js +54 -0
- package/dist/hooks/use-slot-copy-color.hook.js.map +1 -0
- package/dist/hooks/use-spec-data-listener.hook.js +153 -44
- package/dist/hooks/use-spec-data-listener.hook.js.map +1 -1
- package/dist/hooks/use-static-values-listener.hook.js +10 -2
- package/dist/hooks/use-static-values-listener.hook.js.map +1 -1
- package/dist/utils/backdrop-watcher.util.js +79 -0
- package/dist/utils/backdrop-watcher.util.js.map +1 -0
- package/dist/utils/copy-color.util.js +300 -0
- package/dist/utils/copy-color.util.js.map +1 -0
- package/dist/utils/renderer.util.js +103 -1
- package/dist/utils/renderer.util.js.map +1 -1
- package/package.json +9 -10
- package/LICENSE +0 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-canvas-events.hook.js","sources":["../../src/hooks/use-canvas-events.hook.ts"],"sourcesContent":["import {\n addBreakpointEventListeners,\n addContextMenuEventListeners,\n
|
|
1
|
+
{"version":3,"file":"use-canvas-events.hook.js","sources":["../../src/hooks/use-canvas-events.hook.ts"],"sourcesContent":["import {\n addBreakpointEventListeners,\n addContextMenuEventListeners,\n addUrlChangeListeners,\n isCompositionBeingEdited,\n clientRendererModeUtil,\n isInsideVisualBuilderFrame,\n updateStyleOnStyleNodeChange,\n} from \"@contentstack/studio-client\";\nimport {\n dndEventListener,\n getNodeScreenshotEvent,\n hiddenElementNotificationEventEmitter,\n} from \"@contentstack/studio-client/editor\";\nimport {\n addHighlightNodeEventListeners,\n addHighlightSpacingEventListeners,\n compositionSaveEventListener,\n} from \"@contentstack/studio-client/editor\";\nimport { useEffect } from \"react\";\n\nexport const useCanvasEvents = (composableUid?: string) => {\n // HOOK TO ADD HIGHLIGHT NODE EVENT LISTENERS\n useEffect(() => {\n // π― STUDIO CONTEXT CHECK: Only add event listeners when inside Studio, not standalone\n const shouldAddStudioEventListeners =\n isCompositionBeingEdited(composableUid || \"\") &&\n clientRendererModeUtil.isInsideStudioFrame();\n if (!shouldAddStudioEventListeners) return;\n const highlightNodeEventListener = addHighlightNodeEventListeners();\n const urlChangeEventListener = addUrlChangeListeners();\n const highlightSpacingEventListener = addHighlightSpacingEventListeners();\n const contextMenuEventListener = addContextMenuEventListeners();\n const breakpointEventListener = addBreakpointEventListeners();\n const dndListener = dndEventListener();\n const updatedStyleEventListener = updateStyleOnStyleNodeChange();\n const hiddenElementNotificationEventListener =\n hiddenElementNotificationEventEmitter();\n const getNodeScreenshotEventListener = getNodeScreenshotEvent();\n\n return () => {\n highlightNodeEventListener?.removeEventListeners();\n urlChangeEventListener?.removeEventListeners();\n highlightSpacingEventListener?.removeEventListeners();\n contextMenuEventListener?.removeEventListeners();\n breakpointEventListener?.removeEventListeners();\n dndListener?.removeEventListeners();\n updatedStyleEventListener?.removeEventListeners();\n hiddenElementNotificationEventListener?.unregister();\n getNodeScreenshotEventListener?.unregister();\n };\n }, [composableUid]);\n\n useEffect(() => {\n if (!isInsideVisualBuilderFrame()) return;\n const cleanup = compositionSaveEventListener();\n return () => {\n cleanup?.unregister();\n };\n }, []);\n};\n"],"names":[],"mappings":";;;;AAqBO,MAAM,eAAe,GAAG,CAAC,aAAsB,KAAI;;IAExD,SAAS,CAAC,MAAK;;AAEb,QAAA,MAAM,6BAA6B,GACjC,wBAAwB,CAAC,aAAa,IAAI,EAAE,CAAC;YAC7C,sBAAsB,CAAC,mBAAmB,EAAE;AAC9C,QAAA,IAAI,CAAC,6BAA6B;YAAE;AACpC,QAAA,MAAM,0BAA0B,GAAG,8BAA8B,EAAE;AACnE,QAAA,MAAM,sBAAsB,GAAG,qBAAqB,EAAE;AACtD,QAAA,MAAM,6BAA6B,GAAG,iCAAiC,EAAE;AACzE,QAAA,MAAM,wBAAwB,GAAG,4BAA4B,EAAE;AAC/D,QAAA,MAAM,uBAAuB,GAAG,2BAA2B,EAAE;AAC7D,QAAA,MAAM,WAAW,GAAG,gBAAgB,EAAE;AACtC,QAAA,MAAM,yBAAyB,GAAG,4BAA4B,EAAE;AAChE,QAAA,MAAM,sCAAsC,GAC1C,qCAAqC,EAAE;AACzC,QAAA,MAAM,8BAA8B,GAAG,sBAAsB,EAAE;AAE/D,QAAA,OAAO,MAAK;YACV,0BAA0B,EAAE,oBAAoB,EAAE;YAClD,sBAAsB,EAAE,oBAAoB,EAAE;YAC9C,6BAA6B,EAAE,oBAAoB,EAAE;YACrD,wBAAwB,EAAE,oBAAoB,EAAE;YAChD,uBAAuB,EAAE,oBAAoB,EAAE;YAC/C,WAAW,EAAE,oBAAoB,EAAE;YACnC,yBAAyB,EAAE,oBAAoB,EAAE;YACjD,sCAAsC,EAAE,UAAU,EAAE;YACpD,8BAA8B,EAAE,UAAU,EAAE;AAC9C,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;IAEnB,SAAS,CAAC,MAAK;QACb,IAAI,CAAC,0BAA0B,EAAE;YAAE;AACnC,QAAA,MAAM,OAAO,GAAG,4BAA4B,EAAE;AAC9C,QAAA,OAAO,MAAK;YACV,OAAO,EAAE,UAAU,EAAE;AACvB,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;AACR;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { clientRendererModeUtil } from '@contentstack/studio-client';
|
|
2
|
-
import { DataStepMode,
|
|
2
|
+
import { DataStepMode, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger/constants';
|
|
3
|
+
import { composableStudioEventManager } from '@contentstack/studio-messenger';
|
|
3
4
|
import { useState, useEffect } from 'react';
|
|
4
5
|
import '../contexts/providers/edit-context.provider.js';
|
|
5
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-edit-context-listener.hook.js","sources":["../../src/hooks/use-edit-context-listener.hook.ts"],"sourcesContent":["import { clientRendererModeUtil } from \"@contentstack/studio-client\";\nimport {\
|
|
1
|
+
{"version":3,"file":"use-edit-context-listener.hook.js","sources":["../../src/hooks/use-edit-context-listener.hook.ts"],"sourcesContent":["import { clientRendererModeUtil } from \"@contentstack/studio-client\";\nimport { POST_MESSAGE_EVENTS } from \"@contentstack/studio-messenger/constants\";\nimport { composableStudioEventManager } from \"@contentstack/studio-messenger\";\nimport { useEffect, useState } from \"react\";\nimport { DataStepMode } from \"../contexts/providers/edit-context.provider\";\n\nconst DATA_STEP_MODES = Object.values(DataStepMode) as DataStepMode[];\nconst isDataStepMode = (v: unknown): v is DataStepMode =>\n DATA_STEP_MODES.includes(v as DataStepMode);\n\n/**\n * Resolves the per-composition editor context Studio owns (currently just\n * `dataStepMode` β see composable-studio ADR 0008).\n *\n * Init is a PULL: once this effect runs (our handlers are mounted) we request\n * the value from Studio, so it can never race an init-time push. A separate\n * `SET_EDIT_CONTEXT` listener applies later live changes (e.g. the Freeform\n * plan toggled mid-session). Defaults to `schema-or-pin` so anything that can't\n * answer keeps the existing copy.\n */\nexport const useEditContextListener = (\n composableUid?: string,\n): { dataStepMode: DataStepMode } => {\n const [dataStepMode, setDataStepMode] = useState<DataStepMode>(\n DataStepMode.SchemaOrPin,\n );\n\n useEffect(() => {\n if (!clientRendererModeUtil.isInsideStudioFrame()) return;\n\n let cancelled = false;\n\n composableStudioEventManager\n ?.send<{ dataStepMode?: DataStepMode }>(\n POST_MESSAGE_EVENTS.GET_EDIT_CONTEXT,\n { composableUid },\n )\n .then((res) => {\n if (!cancelled && isDataStepMode(res?.dataStepMode)) {\n setDataStepMode(res.dataStepMode);\n }\n })\n .catch(() => {\n // Older Studio has no responder β keep the default.\n });\n\n const listener = composableStudioEventManager?.on<{\n dataStepMode?: DataStepMode;\n }>(POST_MESSAGE_EVENTS.SET_EDIT_CONTEXT, (event) => {\n if (isDataStepMode(event?.data?.dataStepMode)) {\n setDataStepMode(event.data.dataStepMode as DataStepMode);\n }\n });\n\n return () => {\n cancelled = true;\n listener?.unregister();\n };\n }, [composableUid]);\n\n return { dataStepMode };\n};\n"],"names":[],"mappings":";;;;;;AAMA,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAmB;AACrE,MAAM,cAAc,GAAG,CAAC,CAAU,KAChC,eAAe,CAAC,QAAQ,CAAC,CAAiB,CAAC;AAE7C;;;;;;;;;AASG;AACI,MAAM,sBAAsB,GAAG,CACpC,aAAsB,KACY;AAClC,IAAA,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAC9C,YAAY,CAAC,WAAW,CACzB;IAED,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,sBAAsB,CAAC,mBAAmB,EAAE;YAAE;QAEnD,IAAI,SAAS,GAAG,KAAK;QAErB;cACI,IAAI,CACJ,mBAAmB,CAAC,gBAAgB,EACpC,EAAE,aAAa,EAAE;AAElB,aAAA,IAAI,CAAC,CAAC,GAAG,KAAI;YACZ,IAAI,CAAC,SAAS,IAAI,cAAc,CAAC,GAAG,EAAE,YAAY,CAAC,EAAE;AACnD,gBAAA,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC;YACnC;AACF,QAAA,CAAC;aACA,KAAK,CAAC,MAAK;;AAEZ,QAAA,CAAC,CAAC;AAEJ,QAAA,MAAM,QAAQ,GAAG,4BAA4B,EAAE,EAAE,CAE9C,mBAAmB,CAAC,gBAAgB,EAAE,CAAC,KAAK,KAAI;YACjD,IAAI,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,EAAE;AAC7C,gBAAA,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,YAA4B,CAAC;YAC1D;AACF,QAAA,CAAC,CAAC;AAEF,QAAA,OAAO,MAAK;YACV,SAAS,GAAG,IAAI;YAChB,QAAQ,EAAE,UAAU,EAAE;AACxB,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;IAEnB,OAAO,EAAE,YAAY,EAAE;AACzB;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { clientRendererModeUtil, isCompositionBeingEdited } from '@contentstack/studio-client';
|
|
2
|
-
import {
|
|
2
|
+
import { POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger/constants';
|
|
3
|
+
import { composableStudioEventManager } from '@contentstack/studio-messenger';
|
|
3
4
|
import { useEffect } from 'react';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-section-events.hook.js","sources":["../../src/hooks/use-section-events.hook.ts"],"sourcesContent":["import {\n SectionCompositionEntry,\n StudioSpec,\n clientRendererModeUtil,\n isCompositionBeingEdited,\n} from \"@contentstack/studio-client\";\nimport {\
|
|
1
|
+
{"version":3,"file":"use-section-events.hook.js","sources":["../../src/hooks/use-section-events.hook.ts"],"sourcesContent":["import {\n SectionCompositionEntry,\n StudioSpec,\n clientRendererModeUtil,\n isCompositionBeingEdited,\n} from \"@contentstack/studio-client\";\nimport { POST_MESSAGE_EVENTS } from \"@contentstack/studio-messenger/constants\";\nimport { composableStudioEventManager } from \"@contentstack/studio-messenger\";\nimport { useEffect } from \"react\";\n\n/**\n * React hook that manages section composition events from the Studio.\n * Pulls current sections after mount to avoid losing registrations during initial load,\n * AND re-fetches whenever the spec UI references a section uid that isn't yet\n * known locally (e.g. a section was just dropped in Studio).\n *\n * @param setState - State setter function to update the spec\n * @param state - Current studio spec state\n * @param composableUid - UID of the composition being edited\n */\nexport const useSectionEvents = (\n setState: React.Dispatch<React.SetStateAction<StudioSpec>>,\n state?: StudioSpec,\n composableUid?: string,\n) => {\n // Register the catalog-update listener AS SOON AS the iframe is inside\n // the Studio frame β independent of spec arrival. Studio's\n // `useSectionCompositions` pushes the full catalog the moment its React\n // Query resolves; that push can arrive before the iframe has received\n // its first GET_COMPOSITION_SPEC response and populated `composableUid`,\n // so gating the listener on the latter caused NO_REQUEST_LISTENER_FOUND\n // on every fresh page load.\n useEffect(() => {\n if (!clientRendererModeUtil.isInsideStudioFrame()) return;\n const catalogListener = composableStudioEventManager?.on<{\n sectionCompositions: SectionCompositionEntry[];\n }>(POST_MESSAGE_EVENTS.UPDATE_SECTIONS_CATALOG, (event) => {\n if (!event.data?.sectionCompositions) return;\n setState((prevState: StudioSpec) => ({\n ...prevState,\n sectionCompositions: event.data.sectionCompositions,\n }));\n });\n return () => {\n catalogListener?.unregister();\n };\n // Register once on mount; the handler reads via setState's prev so it\n // doesn't need state in deps.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // GET_SECTIONS one-shot fetch β runs after the composition is known so\n // the initial section catalog is populated even when Studio's React\n // Query was already resolved before the iframe mounted (no catalog push\n // is fired in that case).\n useEffect(() => {\n if (!isCompositionBeingEdited(composableUid || \"\")) return;\n composableStudioEventManager\n ?.send<{ sectionCompositions: SectionCompositionEntry[] }>(\n POST_MESSAGE_EVENTS.GET_SECTIONS,\n {},\n )\n .then((data) => {\n if (!data || !(\"sectionCompositions\" in data)) return;\n setState((prevState: StudioSpec) => ({\n ...prevState,\n sectionCompositions: data.sectionCompositions,\n }));\n })\n .catch(() => {});\n }, [state?.compositionEntry?.uid, composableUid]);\n};\n"],"names":[],"mappings":";;;;;AAUA;;;;;;;;;AASG;AACI,MAAM,gBAAgB,GAAG,CAC9B,QAA0D,EAC1D,KAAkB,EAClB,aAAsB,KACpB;;;;;;;;IAQF,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,sBAAsB,CAAC,mBAAmB,EAAE;YAAE;AACnD,QAAA,MAAM,eAAe,GAAG,4BAA4B,EAAE,EAAE,CAErD,mBAAmB,CAAC,uBAAuB,EAAE,CAAC,KAAK,KAAI;AACxD,YAAA,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,mBAAmB;gBAAE;AACtC,YAAA,QAAQ,CAAC,CAAC,SAAqB,MAAM;AACnC,gBAAA,GAAG,SAAS;AACZ,gBAAA,mBAAmB,EAAE,KAAK,CAAC,IAAI,CAAC,mBAAmB;AACpD,aAAA,CAAC,CAAC;AACL,QAAA,CAAC,CAAC;AACF,QAAA,OAAO,MAAK;YACV,eAAe,EAAE,UAAU,EAAE;AAC/B,QAAA,CAAC;;;;IAIH,CAAC,EAAE,EAAE,CAAC;;;;;IAMN,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,wBAAwB,CAAC,aAAa,IAAI,EAAE,CAAC;YAAE;QACpD;AACE,cAAE,IAAI,CACJ,mBAAmB,CAAC,YAAY,EAChC,EAAE;AAEH,aAAA,IAAI,CAAC,CAAC,IAAI,KAAI;YACb,IAAI,CAAC,IAAI,IAAI,EAAE,qBAAqB,IAAI,IAAI,CAAC;gBAAE;AAC/C,YAAA,QAAQ,CAAC,CAAC,SAAqB,MAAM;AACnC,gBAAA,GAAG,SAAS;gBACZ,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;AAC9C,aAAA,CAAC,CAAC;AACL,QAAA,CAAC;AACA,aAAA,KAAK,CAAC,MAAK,EAAE,CAAC,CAAC;IACpB,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;AACnD;;;;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { css } from 'goober';
|
|
2
|
+
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
3
|
+
import { styleFactory } from '../components/styles.js';
|
|
4
|
+
import { watchBackdropChanges } from '../utils/backdrop-watcher.util.js';
|
|
5
|
+
import { resolveBackdropColor, pickChromeMode, STUDIO_CHROME_MODES, needsStroke, needsSurface } from '../utils/copy-color.util.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolves which mode a piece of slot chrome should render in, from the page
|
|
9
|
+
* colour behind it.
|
|
10
|
+
*
|
|
11
|
+
* Measures from the element's parent so the walk starts outside the chrome
|
|
12
|
+
* itself. Pages whose background cannot be read from computed styles β a
|
|
13
|
+
* gradient, photo or video β fall back to a treatment that needs no measuring.
|
|
14
|
+
*/
|
|
15
|
+
function useSlotCopyColor() {
|
|
16
|
+
const [measured, setMeasured] = useState(null);
|
|
17
|
+
const styles = styleFactory(css);
|
|
18
|
+
const node = useRef(null);
|
|
19
|
+
const measure = useCallback((element) => {
|
|
20
|
+
const parent = element?.parentElement;
|
|
21
|
+
if (!parent)
|
|
22
|
+
return;
|
|
23
|
+
const backdrop = resolveBackdropColor(parent);
|
|
24
|
+
setMeasured(backdrop ? { mode: pickChromeMode(backdrop), backdrop } : null);
|
|
25
|
+
}, []);
|
|
26
|
+
// Identity must stay stable: a fresh callback each render would make React
|
|
27
|
+
// detach and reattach the node, re-measuring forever.
|
|
28
|
+
const ref = useCallback((element) => {
|
|
29
|
+
node.current = element;
|
|
30
|
+
measure(element);
|
|
31
|
+
}, [measure]);
|
|
32
|
+
// The page can change under the chrome after it mounts β a host with its own
|
|
33
|
+
// dark-mode toggle leaves a colour that was chosen for the previous
|
|
34
|
+
// background, and it can land as low as 1.05:1 against the new one.
|
|
35
|
+
useEffect(() => watchBackdropChanges(() => measure(node.current)), [measure]);
|
|
36
|
+
return {
|
|
37
|
+
ref,
|
|
38
|
+
mode: measured?.mode ?? null,
|
|
39
|
+
backdrop: measured?.backdrop ?? null,
|
|
40
|
+
tokens: measured ? STUDIO_CHROME_MODES[measured.mode] : null,
|
|
41
|
+
surfaceNeeded: measured
|
|
42
|
+
? needsSurface(measured.mode, measured.backdrop)
|
|
43
|
+
: false,
|
|
44
|
+
colorClassName: measured
|
|
45
|
+
? styles.slotCopyColors[measured.mode]
|
|
46
|
+
: styles.slotCopyOverImage,
|
|
47
|
+
strokeClassName: measured && needsStroke(measured.mode, measured.backdrop)
|
|
48
|
+
? styles.slotCopyStroke[measured.mode]
|
|
49
|
+
: null,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { useSlotCopyColor };
|
|
54
|
+
//# sourceMappingURL=use-slot-copy-color.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-slot-copy-color.hook.js","sources":["../../src/hooks/use-slot-copy-color.hook.ts"],"sourcesContent":["import { css } from \"goober\";\nimport { RefCallback, useCallback, useEffect, useRef, useState } from \"react\";\nimport { styleFactory } from \"../components/styles\";\nimport { watchBackdropChanges } from \"../utils/backdrop-watcher.util\";\nimport {\n needsStroke,\n needsSurface,\n pickChromeMode,\n resolveBackdropColor,\n Rgb,\n STUDIO_CHROME_MODES,\n StudioChromeMode,\n} from \"../utils/copy-color.util\";\n\nexport interface SlotChrome<T extends HTMLElement> {\n /**\n * Attach to the element carrying the chrome. A callback ref rather than an\n * object one: it measures the moment the node attaches, and it types the same\n * way against React 18 and 19.\n */\n ref: RefCallback<T>;\n /** Ink colour class to apply alongside the element's own class. */\n colorClassName: string;\n /** The mode in use, or null while the page colour could not be read. */\n mode: StudioChromeMode | null;\n /** The measured page colour, or null when it could not be read. */\n backdrop: Rgb | null;\n /**\n * True where the mode's ink cannot carry body copy on the page itself, so\n * chrome with more than a label in it needs the mode's surface behind it.\n */\n surfaceNeeded: boolean;\n /** The mode's Venus tokens, or null while unmeasured. */\n tokens: (typeof STUDIO_CHROME_MODES)[StudioChromeMode] | null;\n /**\n * Stroke class for a bare label the ink alone cannot carry on this page, or\n * null where it can. Only chrome that is a bare label needs this; anything\n * with a surface available should take the surface instead.\n */\n strokeClassName: string | null;\n}\n\n/**\n * Resolves which mode a piece of slot chrome should render in, from the page\n * colour behind it.\n *\n * Measures from the element's parent so the walk starts outside the chrome\n * itself. Pages whose background cannot be read from computed styles β a\n * gradient, photo or video β fall back to a treatment that needs no measuring.\n */\nexport function useSlotCopyColor<T extends HTMLElement>(): SlotChrome<T> {\n const [measured, setMeasured] = useState<{\n mode: StudioChromeMode;\n backdrop: Rgb;\n } | null>(null);\n const styles = styleFactory(css);\n\n const node = useRef<T | null>(null);\n\n const measure = useCallback((element: T | null) => {\n const parent = element?.parentElement;\n if (!parent) return;\n const backdrop = resolveBackdropColor(parent);\n setMeasured(backdrop ? { mode: pickChromeMode(backdrop), backdrop } : null);\n }, []);\n\n // Identity must stay stable: a fresh callback each render would make React\n // detach and reattach the node, re-measuring forever.\n const ref = useCallback<RefCallback<T>>(\n (element) => {\n node.current = element;\n measure(element);\n },\n [measure],\n );\n\n // The page can change under the chrome after it mounts β a host with its own\n // dark-mode toggle leaves a colour that was chosen for the previous\n // background, and it can land as low as 1.05:1 against the new one.\n useEffect(() => watchBackdropChanges(() => measure(node.current)), [measure]);\n\n return {\n ref,\n mode: measured?.mode ?? null,\n backdrop: measured?.backdrop ?? null,\n tokens: measured ? STUDIO_CHROME_MODES[measured.mode] : null,\n surfaceNeeded: measured\n ? needsSurface(measured.mode, measured.backdrop)\n : false,\n colorClassName: measured\n ? styles.slotCopyColors[measured.mode]\n : styles.slotCopyOverImage,\n strokeClassName:\n measured && needsStroke(measured.mode, measured.backdrop)\n ? styles.slotCopyStroke[measured.mode]\n : null,\n };\n}\n"],"names":[],"mappings":";;;;;;AA0CA;;;;;;;AAOG;SACa,gBAAgB,GAAA;IAC9B,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAG9B,IAAI,CAAC;AACf,IAAA,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC;AAEhC,IAAA,MAAM,IAAI,GAAG,MAAM,CAAW,IAAI,CAAC;AAEnC,IAAA,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,OAAiB,KAAI;AAChD,QAAA,MAAM,MAAM,GAAG,OAAO,EAAE,aAAa;AACrC,QAAA,IAAI,CAAC,MAAM;YAAE;AACb,QAAA,MAAM,QAAQ,GAAG,oBAAoB,CAAC,MAAM,CAAC;QAC7C,WAAW,CAAC,QAAQ,GAAG,EAAE,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC7E,CAAC,EAAE,EAAE,CAAC;;;AAIN,IAAA,MAAM,GAAG,GAAG,WAAW,CACrB,CAAC,OAAO,KAAI;AACV,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;QACtB,OAAO,CAAC,OAAO,CAAC;AAClB,IAAA,CAAC,EACD,CAAC,OAAO,CAAC,CACV;;;;IAKD,SAAS,CAAC,MAAM,oBAAoB,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAE7E,OAAO;QACL,GAAG;AACH,QAAA,IAAI,EAAE,QAAQ,EAAE,IAAI,IAAI,IAAI;AAC5B,QAAA,QAAQ,EAAE,QAAQ,EAAE,QAAQ,IAAI,IAAI;AACpC,QAAA,MAAM,EAAE,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI;AAC5D,QAAA,aAAa,EAAE;cACX,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ;AAC/C,cAAE,KAAK;AACT,QAAA,cAAc,EAAE;cACZ,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI;cACnC,MAAM,CAAC,iBAAiB;AAC5B,QAAA,eAAe,EACb,QAAQ,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ;cACpD,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI;AACrC,cAAE,IAAI;KACX;AACH;;;;"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { clientRendererModeUtil, SECTION_COMPOSITIONS_KEY, applyOperation, NODE_TO_PARENT, NODE_TO_PATH_NODE } from '@contentstack/studio-client';
|
|
2
|
-
import {
|
|
2
|
+
import { POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger/constants';
|
|
3
|
+
import { composableStudioEventManager } from '@contentstack/studio-messenger';
|
|
3
4
|
import { DATA_SOURCES_PREFIX } from '@contentstack/studio-registry';
|
|
4
|
-
import { seedSectionInstanceBindings } from '@contentstack/studio-react-components/utils';
|
|
5
|
+
import { seedSectionInstanceBindings, pageDataSourcesOf, keepEqualReferences } from '@contentstack/studio-react-components/utils';
|
|
5
6
|
import { useRef, useEffect } from 'react';
|
|
6
|
-
import {
|
|
7
|
+
import { Immer } from 'immer';
|
|
7
8
|
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
|
|
9
|
+
// Immer freezes what it produces, but metadata-binding resolution (currently
|
|
10
|
+
// just styles) writes onto the produced node afterwards, which throws on frozen
|
|
11
|
+
// state β so this module needs a non-freezing `produce`. Scoped to an isolated
|
|
12
|
+
// instance rather than the global `setAutoFreeze(false)`: this is a published
|
|
13
|
+
// package, and the global switch would silently remove the mutation guard for
|
|
14
|
+
// the consuming app's own Immer usage.
|
|
15
|
+
const { produce } = new Immer({ autoFreeze: false });
|
|
14
16
|
/**
|
|
15
17
|
* Walk a fresh UI tree (post-Immer-produce) and populate the NODE_TO_PARENT
|
|
16
18
|
* and NODE_TO_PATH_NODE WeakMaps for every node. These maps are normally
|
|
@@ -40,6 +42,18 @@ function refreshNodeWeakMaps(root) {
|
|
|
40
42
|
};
|
|
41
43
|
visit(root);
|
|
42
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* `next` with every data slice `prev` already holds kept at its old reference,
|
|
47
|
+
* one level into `dataSources` as well. Studio's pushes cross postMessage, so
|
|
48
|
+
* they arrive as new objects even when nothing changed; without this, every
|
|
49
|
+
* push re-renders the page.
|
|
50
|
+
*/
|
|
51
|
+
function keepEqualData(prev, next) {
|
|
52
|
+
return keepEqualReferences(prev, {
|
|
53
|
+
...next,
|
|
54
|
+
[DATA_SOURCES_PREFIX]: keepEqualReferences(prev?.[DATA_SOURCES_PREFIX], next?.[DATA_SOURCES_PREFIX]),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
43
57
|
const useSpecDataListener = (setState,
|
|
44
58
|
// Read into `stateRef` only β listener bodies use `stateRef.current` (not
|
|
45
59
|
// `state` directly) so the effect's deps don't include `state.data`, which
|
|
@@ -73,19 +87,96 @@ state, composableUid) => {
|
|
|
73
87
|
}
|
|
74
88
|
: dataSources[SECTION_COMPOSITIONS_KEY] || {};
|
|
75
89
|
const pageTemplate = dataSources.template;
|
|
90
|
+
const pageDataSources = pageDataSourcesOf(dataSources);
|
|
91
|
+
/**
|
|
92
|
+
* The document an instance's section data lives in (ADR 0017).
|
|
93
|
+
*
|
|
94
|
+
* The editor re-scopes every section from `dataSources.template` β the page
|
|
95
|
+
* template entry. A FREEFORM page has none, so a section whose Section data
|
|
96
|
+
* points at a pinned entry or a query resolved to `undefined` here and
|
|
97
|
+
* rendered component defaults, even though the binding was stored
|
|
98
|
+
* correctly and the fetch/cold-load path (build-scoped-data) resolved it
|
|
99
|
+
* fine. This is the same hardcoded-anchor bug, in the live editor path.
|
|
100
|
+
*/
|
|
101
|
+
const resolveFetchRootDocument = (fetchRootKey) => {
|
|
102
|
+
if (!fetchRootKey || fetchRootKey === "template")
|
|
103
|
+
return pageTemplate;
|
|
104
|
+
if (fetchRootKey.startsWith("query:")) {
|
|
105
|
+
const qUid = fetchRootKey.slice("query:".length);
|
|
106
|
+
return (dataSources.contentstack_queries || {})[qUid];
|
|
107
|
+
}
|
|
108
|
+
// `<ct>:<uid>` β the same composite key the contentstack resolver uses.
|
|
109
|
+
return (dataSources.contentstack || {})[fetchRootKey];
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Reference stubs, followed to their pooled entry β the step this scoper was
|
|
113
|
+
* missing entirely (the fetch path's `build-scoped-data` has it at every
|
|
114
|
+
* traversal step).
|
|
115
|
+
*
|
|
116
|
+
* CDA returns `{uid, _content_type_uid}` at a reference field unless the
|
|
117
|
+
* request included it, and Studio's read funnel pools the resolved entry
|
|
118
|
+
* separately under its `<ct>:<uid>` key. Without following the stub, a
|
|
119
|
+
* Section data whose path CROSSES a reference resolved to the stub object:
|
|
120
|
+
* the section's own fields were absent from it, so the canvas rendered
|
|
121
|
+
* component defaults while the deployed site β which does follow β was
|
|
122
|
+
* correct (COMS-2031: DR5.5, and the wrapper half of DR7.4).
|
|
123
|
+
*/
|
|
124
|
+
const META_KEYS = new Set([
|
|
125
|
+
"uid",
|
|
126
|
+
"_content_type_uid",
|
|
127
|
+
"_version",
|
|
128
|
+
"locale",
|
|
129
|
+
"ACL",
|
|
130
|
+
"_metadata",
|
|
131
|
+
// Live-preview edit tags. The Preview service stamps `$` onto every entry
|
|
132
|
+
// and reference stub in the editor, so a bare stub arrives as
|
|
133
|
+
// `{uid, _content_type_uid, $}` β three keys, one of which used to read as
|
|
134
|
+
// "this stub already carries a payload". The stub was then handed back
|
|
135
|
+
// unfollowed and a Section data whose path crosses a reference resolved to
|
|
136
|
+
// the stub instead of the entry (E2E DR7.4). Metadata, never content.
|
|
137
|
+
"$",
|
|
138
|
+
]);
|
|
139
|
+
const followReference = (v) => {
|
|
140
|
+
if (!v ||
|
|
141
|
+
typeof v !== "object" ||
|
|
142
|
+
Array.isArray(v) ||
|
|
143
|
+
typeof v.uid !== "string" ||
|
|
144
|
+
typeof v._content_type_uid !== "string") {
|
|
145
|
+
return v;
|
|
146
|
+
}
|
|
147
|
+
// CDA may already have inlined the entry into the stub object; anything
|
|
148
|
+
// beyond the meta keys means it is resolved already.
|
|
149
|
+
if (Object.keys(v).some((k) => !META_KEYS.has(k)))
|
|
150
|
+
return v;
|
|
151
|
+
const resolved = (dataSources.contentstack || {})[`${v._content_type_uid}:${v.uid}`];
|
|
152
|
+
return resolved !== undefined ? resolved : v;
|
|
153
|
+
};
|
|
154
|
+
const followAll = (v) => Array.isArray(v) ? v.map(followReference) : followReference(v);
|
|
76
155
|
const prevScoped = prevData?.section_scoped_data || {};
|
|
77
156
|
const nextScoped = { ...prevScoped };
|
|
78
157
|
const getScopedData = (obj, selectedField) => {
|
|
79
158
|
if (!selectedField)
|
|
80
|
-
return obj;
|
|
81
|
-
|
|
159
|
+
return followAll(obj);
|
|
160
|
+
const traversed = selectedField
|
|
161
|
+
.split(".")
|
|
162
|
+
.reduce((val, seg) => {
|
|
82
163
|
if (val == null)
|
|
83
164
|
return val;
|
|
165
|
+
// Swap a stub for its resolved entry BEFORE drilling into it.
|
|
166
|
+
val = followReference(val);
|
|
84
167
|
const arrayMatch = seg.match(/^(.*?)\[(\d+)\]$/);
|
|
85
168
|
if (arrayMatch) {
|
|
86
169
|
const [, name, idxStr] = arrayMatch;
|
|
87
170
|
const next = name ? val[name] : val;
|
|
88
|
-
return next == null ? next : next[Number(idxStr)];
|
|
171
|
+
return next == null ? next : followReference(next[Number(idxStr)]);
|
|
172
|
+
}
|
|
173
|
+
// A bare NUMERIC segment is an array index. Contentstack bindings
|
|
174
|
+
// encode one as a plain segment (`page_sections.17.keynote_speakers`)
|
|
175
|
+
// rather than bracket notation, so this must precede the
|
|
176
|
+
// arrayβfirst-element fallback below, which would otherwise look `17`
|
|
177
|
+
// up as a key on element [0].
|
|
178
|
+
if (Array.isArray(val) && /^\d+$/.test(seg)) {
|
|
179
|
+
return followReference(val[Number(seg)]);
|
|
89
180
|
}
|
|
90
181
|
// Non-indexed field access landing on an ARRAY β default to the first
|
|
91
182
|
// element so an un-indexed array-ancestor path (e.g.
|
|
@@ -94,11 +185,12 @@ state, composableUid) => {
|
|
|
94
185
|
// undefined β null. Indexed pushes (`navigation_menu_3[1]β¦`) override
|
|
95
186
|
// this with the picked instance.
|
|
96
187
|
if (Array.isArray(val)) {
|
|
97
|
-
const first = val[0];
|
|
98
|
-
return first == null ? null : first[seg];
|
|
188
|
+
const first = followReference(val[0]);
|
|
189
|
+
return first == null ? null : followReference(first[seg]);
|
|
99
190
|
}
|
|
100
|
-
return val[seg];
|
|
101
|
-
}, obj)
|
|
191
|
+
return followReference(val[seg]);
|
|
192
|
+
}, obj);
|
|
193
|
+
return ((Array.isArray(traversed) ? followAll(traversed) : traversed) ?? null);
|
|
102
194
|
};
|
|
103
195
|
const applyUidRemapping = (scoped, uidRemapping = {}) => {
|
|
104
196
|
if (!scoped ||
|
|
@@ -128,7 +220,17 @@ state, composableUid) => {
|
|
|
128
220
|
if (binding && "context" in binding && !("selectedField" in binding)) {
|
|
129
221
|
continue;
|
|
130
222
|
}
|
|
131
|
-
|
|
223
|
+
// A non-template fetch root carries its own in-document path; the
|
|
224
|
+
// legacy `selectedField` is a page-template path and does not apply.
|
|
225
|
+
const fetchRootKey = binding?.fetchRootKey;
|
|
226
|
+
const fetchRootPrefix = binding
|
|
227
|
+
?.fetchRootPrefix;
|
|
228
|
+
const usesPageTemplate = !fetchRootKey || fetchRootKey === "template";
|
|
229
|
+
const rootDocument = resolveFetchRootDocument(fetchRootKey);
|
|
230
|
+
const rootScopePath = usesPageTemplate
|
|
231
|
+
? binding?.selectedField
|
|
232
|
+
: fetchRootPrefix?.join(".");
|
|
233
|
+
let scopedTemplate = applyUidRemapping(getScopedData(rootDocument, rootScopePath), binding?.uidRemapping);
|
|
132
234
|
// Single-element section: `selectedField` stays index-free, so an
|
|
133
235
|
// un-indexed terminal array resolves to the WHOLE array. Collapse to the
|
|
134
236
|
// first element (the deploy default β the preview instance is session-only)
|
|
@@ -139,6 +241,15 @@ state, composableUid) => {
|
|
|
139
241
|
if (binding?.cardinality === "single" && Array.isArray(scopedTemplate)) {
|
|
140
242
|
scopedTemplate = scopedTemplate[0] ?? null;
|
|
141
243
|
}
|
|
244
|
+
// A CT-anchored section is ONE document. When its scope reached it through
|
|
245
|
+
// a REFERENCE β a wrapper pinned at `settings_ref` rebasing its slot
|
|
246
|
+
// children (ADR 0017) β CDA's array arrives instead of the entry, and the
|
|
247
|
+
// section's own fields are not on an array. Collapse to the document.
|
|
248
|
+
if (binding
|
|
249
|
+
?.expectsSingleDocument &&
|
|
250
|
+
Array.isArray(scopedTemplate)) {
|
|
251
|
+
scopedTemplate = scopedTemplate[0] ?? null;
|
|
252
|
+
}
|
|
142
253
|
let repeater;
|
|
143
254
|
if (binding?.parentRepeaterUID) {
|
|
144
255
|
const ctx = dataSources.repeater?.[binding.parentRepeaterUID];
|
|
@@ -153,21 +264,22 @@ state, composableUid) => {
|
|
|
153
264
|
// iframe loaded with getSpecFromParent and never fetched the section's
|
|
154
265
|
// data sources itself β the studio pushes them later via
|
|
155
266
|
// UPDATE_SPEC_DATA. Pool-keyed maps would be ideal but the listener
|
|
156
|
-
// doesn't have access to them;
|
|
157
|
-
// superset (same composite-key format the resolver expects).
|
|
267
|
+
// doesn't have access to them; sharing the full page slice is a safe
|
|
268
|
+
// superset (same composite-key format the resolver expects). Shared by
|
|
269
|
+
// reference, not copied, so an unchanged slice compares by identity.
|
|
158
270
|
const refreshedContentstack = dataSources.contentstack && typeof dataSources.contentstack === "object"
|
|
159
|
-
?
|
|
271
|
+
? dataSources.contentstack
|
|
160
272
|
: prev.contentstack || {};
|
|
161
273
|
const refreshedQueries = dataSources.contentstack_queries &&
|
|
162
274
|
typeof dataSources.contentstack_queries === "object"
|
|
163
|
-
?
|
|
275
|
+
? dataSources.contentstack_queries
|
|
164
276
|
: prev.contentstack_queries || {};
|
|
165
277
|
const next = {
|
|
166
278
|
...prev,
|
|
167
279
|
template: scopedTemplate,
|
|
168
280
|
contentstack: refreshedContentstack,
|
|
169
281
|
contentstack_queries: refreshedQueries,
|
|
170
|
-
page:
|
|
282
|
+
page: pageDataSources,
|
|
171
283
|
repeater: repeater ?? prev.repeater,
|
|
172
284
|
// Carry binding metadata so SectionCompositionProvider can re-scope the
|
|
173
285
|
// template from the LIVE per-iteration repeater item. The scopedTemplate
|
|
@@ -175,17 +287,16 @@ state, composableUid) => {
|
|
|
175
287
|
// instance, so it can't represent per-iteration values on its own.
|
|
176
288
|
parentRepeaterUID: binding?.parentRepeaterUID ?? null,
|
|
177
289
|
selectedField: binding?.selectedField,
|
|
290
|
+
fetchRootKey,
|
|
291
|
+
fetchRootPrefix,
|
|
178
292
|
uidRemapping: binding?.uidRemapping,
|
|
179
293
|
cardinality: binding?.cardinality,
|
|
180
294
|
componentPropsFallback: binding?.componentPropsFallback,
|
|
181
295
|
};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
prev.contentstack_queries !== next.contentstack_queries ||
|
|
187
|
-
prev.componentPropsFallback !== next.componentPropsFallback) {
|
|
188
|
-
nextScoped[instanceUid] = next;
|
|
296
|
+
// Keep the old entry when its content is unchanged.
|
|
297
|
+
const kept = keepEqualReferences(prev, next);
|
|
298
|
+
if (kept !== prev) {
|
|
299
|
+
nextScoped[instanceUid] = kept;
|
|
189
300
|
changed = true;
|
|
190
301
|
}
|
|
191
302
|
}
|
|
@@ -296,16 +407,13 @@ state, composableUid) => {
|
|
|
296
407
|
...(data?.dataSources || {}),
|
|
297
408
|
[SECTION_COMPOSITIONS_KEY]: mergedSections,
|
|
298
409
|
};
|
|
299
|
-
const mergedData = {
|
|
410
|
+
const mergedData = keepEqualData(state.data, {
|
|
300
411
|
...state.data,
|
|
301
412
|
...data,
|
|
302
413
|
dataSources: mergedDataSources,
|
|
303
|
-
};
|
|
414
|
+
});
|
|
304
415
|
const rebuilt = rebuildScopedFromBindings(mergedData);
|
|
305
|
-
return {
|
|
306
|
-
...state,
|
|
307
|
-
data: rebuilt,
|
|
308
|
-
};
|
|
416
|
+
return rebuilt === state.data ? state : { ...state, data: rebuilt };
|
|
309
417
|
});
|
|
310
418
|
});
|
|
311
419
|
const previewEntryChangeListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.REPLACE_PREVIEW_ENTRY, async (event) => {
|
|
@@ -320,13 +428,13 @@ state, composableUid) => {
|
|
|
320
428
|
// dataSources β don't wipe sibling slices like `repeater` or
|
|
321
429
|
// `section_compositions`, which would cause a flicker for sections
|
|
322
430
|
// inside a Repeater (their item context would disappear).
|
|
323
|
-
const mergedData = {
|
|
431
|
+
const mergedData = keepEqualData(prevState.data, {
|
|
324
432
|
...prevState?.data,
|
|
325
433
|
[DATA_SOURCES_PREFIX]: {
|
|
326
434
|
...(prevState?.data?.[DATA_SOURCES_PREFIX] || {}),
|
|
327
435
|
...data?.dataSources,
|
|
328
436
|
},
|
|
329
|
-
};
|
|
437
|
+
});
|
|
330
438
|
// The merge updates dataSources.template, but each section's SCOPED
|
|
331
439
|
// template in section_scoped_data is derived from it β re-scope here,
|
|
332
440
|
// else a section keeps its stale (often null) scope and renders the
|
|
@@ -334,7 +442,9 @@ state, composableUid) => {
|
|
|
334
442
|
// UPDATE_SPEC_DATA handler already rebuilds; this is the equivalent for
|
|
335
443
|
// the preview-entry change path that EntryPickerBtn sends.)
|
|
336
444
|
const rebuilt = rebuildScopedFromBindings(mergedData);
|
|
337
|
-
return
|
|
445
|
+
return rebuilt === prevState.data
|
|
446
|
+
? prevState
|
|
447
|
+
: { ...prevState, data: rebuilt };
|
|
338
448
|
});
|
|
339
449
|
});
|
|
340
450
|
const applyOperationListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.APPLY_OPERATION, (event) => {
|
|
@@ -448,13 +558,13 @@ state, composableUid) => {
|
|
|
448
558
|
? { ...incoming, cardinality: prev.cardinality }
|
|
449
559
|
: incoming;
|
|
450
560
|
}
|
|
451
|
-
const mergedData = {
|
|
561
|
+
const mergedData = keepEqualData(prevState.data, {
|
|
452
562
|
...prevState.data,
|
|
453
563
|
dataSources: {
|
|
454
564
|
...prevState.data?.dataSources,
|
|
455
565
|
[SECTION_COMPOSITIONS_KEY]: merged,
|
|
456
566
|
},
|
|
457
|
-
};
|
|
567
|
+
});
|
|
458
568
|
// Pass the MERGED entries for the incoming uids (not the raw incoming)
|
|
459
569
|
// β rebuildScopedFromBindings spreads incomingBindings over the slice,
|
|
460
570
|
// so raw entries would reintroduce the dropped cardinality.
|
|
@@ -463,10 +573,9 @@ state, composableUid) => {
|
|
|
463
573
|
merged[uid],
|
|
464
574
|
]));
|
|
465
575
|
const finalData = rebuildScopedFromBindings(mergedData, incomingMerged);
|
|
466
|
-
return
|
|
467
|
-
|
|
468
|
-
data: finalData
|
|
469
|
-
};
|
|
576
|
+
return finalData === prevState.data
|
|
577
|
+
? prevState
|
|
578
|
+
: { ...prevState, data: finalData };
|
|
470
579
|
});
|
|
471
580
|
});
|
|
472
581
|
// Signal to Studio that our editorβiframe post-message listeners are now
|