@contentstack/studio-react-editor 1.9.0 β 1.11.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/EditableRenderer.js +2 -1
- package/dist/components/EditableRenderer.js.map +1 -1
- package/dist/components/Element.js +35 -32
- package/dist/components/Element.js.map +1 -1
- package/dist/components/PermanentDropZone.js +77 -0
- package/dist/components/PermanentDropZone.js.map +1 -0
- package/dist/components/WelcomeState.js +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 +16 -50
- package/dist/components/elements/SectionSlot.js.map +1 -1
- package/dist/components/styles.js +76 -52
- 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/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-can-show-permanent-drop-zones.hook.js +20 -0
- package/dist/hooks/use-can-show-permanent-drop-zones.hook.js.map +1 -0
- 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-should-show-design.hook.js +47 -35
- package/dist/hooks/use-should-show-design.hook.js.map +1 -1
- package/dist/hooks/use-slot-copy-color.hook.js +13 -10
- package/dist/hooks/use-slot-copy-color.hook.js.map +1 -1
- package/dist/hooks/use-spec-data-listener.hook.js +39 -29
- 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/renderer.util.js +105 -35
- package/dist/utils/renderer.util.js.map +1 -1
- package/package.json +8 -8
|
@@ -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;;;;"}
|
|
@@ -6,7 +6,14 @@ import { useDesignPreviewContext } from './use-design-preview.hook.js';
|
|
|
6
6
|
import { useRenderer } from './use-renderer.hook.js';
|
|
7
7
|
import { useRepeaterContext } from './use-repeater.hook.js';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The design-or-preview rule for a Repeater or Condition block rendered in the
|
|
11
|
+
* calling component's context, as a function of the node's own `mode`. Code
|
|
12
|
+
* that judges a slot's children before they render, like permanent drop zone
|
|
13
|
+
* placement, calls it with each child's `metadata.mode` to get the answer the
|
|
14
|
+
* child will reach.
|
|
15
|
+
*/
|
|
16
|
+
function useRendersDesignForMode() {
|
|
10
17
|
const { isCompositionBeingEdited } = useRenderer();
|
|
11
18
|
const { isInsideRepeater } = useRepeaterContext();
|
|
12
19
|
const { isInsideConditionBlock } = useConditionBlockContext();
|
|
@@ -18,41 +25,46 @@ function useShouldShowDesign(mode) {
|
|
|
18
25
|
// `isInsideStudioFrame()` (URL-param-gated) so Visual Builder's iframe
|
|
19
26
|
// (which should render preview) is correctly excluded.
|
|
20
27
|
const isInsideStudio = clientRendererModeUtil.isInsideStudioFrame();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
return (mode) => {
|
|
29
|
+
if (!isCompositionBeingEdited && !isInsideStudio)
|
|
30
|
+
return false;
|
|
31
|
+
// A placed section forces the mode of everything inside it β a single
|
|
32
|
+
// per-placement switch that overrides each inner node's own `mode`. Only set
|
|
33
|
+
// inside a section placement in the editor; null everywhere else.
|
|
34
|
+
// - PREVIEW always wins β render preview.
|
|
35
|
+
// - DESIGN keeps the section's own drop-zones visible, BUT when the section
|
|
36
|
+
// is itself nested inside an enclosing PREVIEW repeater its internal data
|
|
37
|
+
// repeaters must still iterate β otherwise a data-bound slot child can
|
|
38
|
+
// never resolve its per-iteration context (SP7.1: a slot-bearing section
|
|
39
|
+
// defaults to design via COMS-1595, which froze its inner repeaters). So
|
|
40
|
+
// defer to the enclosing preview context in that case. At the page root
|
|
41
|
+
// designPreviewContext is "none", so design is preserved (the slot's own
|
|
42
|
+
// drop-zone-vs-collapsed rendering reads SectionModeContext directly and
|
|
43
|
+
// is unaffected either way).
|
|
44
|
+
if (sectionMode === "preview")
|
|
45
|
+
return false;
|
|
46
|
+
if (sectionMode === "design")
|
|
47
|
+
return designPreviewContext !== "preview";
|
|
48
|
+
if (isInsideRepeater || isInsideConditionBlock) {
|
|
49
|
+
// If composition is being edited and current node(Repeater or Condition Block) inside another repeater or condition block,
|
|
50
|
+
// and no designPreviewContext is provided, then show design
|
|
51
|
+
if (!designPreviewContext)
|
|
52
|
+
return true;
|
|
53
|
+
// If designPreviewContext is provided,
|
|
54
|
+
// then show design based on designPreviewContext
|
|
55
|
+
return designPreviewContext === "design";
|
|
56
|
+
}
|
|
57
|
+
// if no mode is provided, then show design
|
|
58
|
+
if (!mode) {
|
|
44
59
|
return true;
|
|
45
|
-
|
|
46
|
-
// then show design based on
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
// If mode is provided, then show design based on mode
|
|
54
|
-
return mode === "design";
|
|
60
|
+
}
|
|
61
|
+
// If mode is provided, then show design based on mode
|
|
62
|
+
return mode === "design";
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function useShouldShowDesign(mode) {
|
|
66
|
+
return useRendersDesignForMode()(mode);
|
|
55
67
|
}
|
|
56
68
|
|
|
57
|
-
export { useShouldShowDesign };
|
|
69
|
+
export { useRendersDesignForMode, useShouldShowDesign };
|
|
58
70
|
//# sourceMappingURL=use-should-show-design.hook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-should-show-design.hook.js","sources":["../../src/hooks/use-should-show-design.hook.ts"],"sourcesContent":["import { clientRendererModeUtil } from \"@contentstack/studio-client\";\nimport { useContext } from \"react\";\nimport { SectionModeContext } from \"../contexts/providers/section-mode.provider\";\nimport { useConditionBlockContext } from \"./use-condition-block-context\";\nimport { useDesignPreviewContext } from \"./use-design-preview.hook\";\nimport { useRenderer } from \"./use-renderer.hook\";\nimport { useRepeaterContext } from \"./use-repeater.hook\";\n\
|
|
1
|
+
{"version":3,"file":"use-should-show-design.hook.js","sources":["../../src/hooks/use-should-show-design.hook.ts"],"sourcesContent":["import { clientRendererModeUtil } from \"@contentstack/studio-client\";\nimport { useContext } from \"react\";\nimport type { DesignPreviewMode, RendersDesignForMode } from \"../types\";\nimport { SectionModeContext } from \"../contexts/providers/section-mode.provider\";\nimport { useConditionBlockContext } from \"./use-condition-block-context\";\nimport { useDesignPreviewContext } from \"./use-design-preview.hook\";\nimport { useRenderer } from \"./use-renderer.hook\";\nimport { useRepeaterContext } from \"./use-repeater.hook\";\n\n/**\n * The design-or-preview rule for a Repeater or Condition block rendered in the\n * calling component's context, as a function of the node's own `mode`. Code\n * that judges a slot's children before they render, like permanent drop zone\n * placement, calls it with each child's `metadata.mode` to get the answer the\n * child will reach.\n */\nexport function useRendersDesignForMode(): RendersDesignForMode {\n const { isCompositionBeingEdited } = useRenderer();\n const { isInsideRepeater } = useRepeaterContext();\n const { isInsideConditionBlock } = useConditionBlockContext();\n const designPreviewContext = useDesignPreviewContext();\n const sectionMode = useContext(SectionModeContext);\n // Treat the Studio editor frame as design-mode-eligible from the very first\n // render β even before `isCompositionBeingEdited` has resolved β to avoid a\n // one-frame preview render that would inject items[0] context. Use\n // `isInsideStudioFrame()` (URL-param-gated) so Visual Builder's iframe\n // (which should render preview) is correctly excluded.\n const isInsideStudio = clientRendererModeUtil.isInsideStudioFrame();\n return (mode) => {\n if (!isCompositionBeingEdited && !isInsideStudio) return false;\n\n // A placed section forces the mode of everything inside it β a single\n // per-placement switch that overrides each inner node's own `mode`. Only set\n // inside a section placement in the editor; null everywhere else.\n // - PREVIEW always wins β render preview.\n // - DESIGN keeps the section's own drop-zones visible, BUT when the section\n // is itself nested inside an enclosing PREVIEW repeater its internal data\n // repeaters must still iterate β otherwise a data-bound slot child can\n // never resolve its per-iteration context (SP7.1: a slot-bearing section\n // defaults to design via COMS-1595, which froze its inner repeaters). So\n // defer to the enclosing preview context in that case. At the page root\n // designPreviewContext is \"none\", so design is preserved (the slot's own\n // drop-zone-vs-collapsed rendering reads SectionModeContext directly and\n // is unaffected either way).\n if (sectionMode === \"preview\") return false;\n if (sectionMode === \"design\") return designPreviewContext !== \"preview\";\n\n if (isInsideRepeater || isInsideConditionBlock) {\n // If composition is being edited and current node(Repeater or Condition Block) inside another repeater or condition block,\n // and no designPreviewContext is provided, then show design\n if (!designPreviewContext) return true;\n // If designPreviewContext is provided,\n // then show design based on designPreviewContext\n return designPreviewContext === \"design\";\n }\n // if no mode is provided, then show design\n if (!mode) {\n return true;\n }\n // If mode is provided, then show design based on mode\n return mode === \"design\";\n };\n}\n\nexport function useShouldShowDesign(mode: DesignPreviewMode) {\n return useRendersDesignForMode()(mode);\n}\n"],"names":[],"mappings":";;;;;;;;AASA;;;;;;AAMG;SACa,uBAAuB,GAAA;AACrC,IAAA,MAAM,EAAE,wBAAwB,EAAE,GAAG,WAAW,EAAE;AAClD,IAAA,MAAM,EAAE,gBAAgB,EAAE,GAAG,kBAAkB,EAAE;AACjD,IAAA,MAAM,EAAE,sBAAsB,EAAE,GAAG,wBAAwB,EAAE;AAC7D,IAAA,MAAM,oBAAoB,GAAG,uBAAuB,EAAE;AACtD,IAAA,MAAM,WAAW,GAAG,UAAU,CAAC,kBAAkB,CAAC;;;;;;AAMlD,IAAA,MAAM,cAAc,GAAG,sBAAsB,CAAC,mBAAmB,EAAE;IACnE,OAAO,CAAC,IAAI,KAAI;AACd,QAAA,IAAI,CAAC,wBAAwB,IAAI,CAAC,cAAc;AAAE,YAAA,OAAO,KAAK;;;;;;;;;;;;;;QAe9D,IAAI,WAAW,KAAK,SAAS;AAAE,YAAA,OAAO,KAAK;QAC3C,IAAI,WAAW,KAAK,QAAQ;YAAE,OAAO,oBAAoB,KAAK,SAAS;AAEvE,QAAA,IAAI,gBAAgB,IAAI,sBAAsB,EAAE;;;AAG9C,YAAA,IAAI,CAAC,oBAAoB;AAAE,gBAAA,OAAO,IAAI;;;YAGtC,OAAO,oBAAoB,KAAK,QAAQ;QAC1C;;QAEA,IAAI,CAAC,IAAI,EAAE;AACT,YAAA,OAAO,IAAI;QACb;;QAEA,OAAO,IAAI,KAAK,QAAQ;AAC1B,IAAA,CAAC;AACH;AAEM,SAAU,mBAAmB,CAAC,IAAuB,EAAA;AACzD,IAAA,OAAO,uBAAuB,EAAE,CAAC,IAAI,CAAC;AACxC;;;;"}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { css } from 'goober';
|
|
2
|
+
import { isEqual } from 'lodash-es';
|
|
2
3
|
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
3
4
|
import { styleFactory } from '../components/styles.js';
|
|
4
5
|
import { watchBackdropChanges } from '../utils/backdrop-watcher.util.js';
|
|
5
6
|
import { resolveBackdropColor, pickChromeMode, STUDIO_CHROME_MODES, needsStroke, needsSurface } from '../utils/copy-color.util.js';
|
|
6
7
|
|
|
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
8
|
function useSlotCopyColor() {
|
|
16
|
-
|
|
9
|
+
// `undefined` until the first measurement; `null` when the page colour
|
|
10
|
+
// could not be read.
|
|
11
|
+
const [measured, setMeasured] = useState(undefined);
|
|
17
12
|
const styles = styleFactory(css);
|
|
18
13
|
const node = useRef(null);
|
|
19
14
|
const measure = useCallback((element) => {
|
|
@@ -21,7 +16,14 @@ function useSlotCopyColor() {
|
|
|
21
16
|
if (!parent)
|
|
22
17
|
return;
|
|
23
18
|
const backdrop = resolveBackdropColor(parent);
|
|
24
|
-
|
|
19
|
+
const nextMeasurement = backdrop
|
|
20
|
+
? { mode: pickChromeMode(backdrop), backdrop }
|
|
21
|
+
: null;
|
|
22
|
+
// The watcher re-measures on any style change in the page; keep the same
|
|
23
|
+
// state when the answer hasn't changed, so the chrome doesn't re-render.
|
|
24
|
+
setMeasured((previousMeasurement) => isEqual(previousMeasurement, nextMeasurement)
|
|
25
|
+
? previousMeasurement
|
|
26
|
+
: nextMeasurement);
|
|
25
27
|
}, []);
|
|
26
28
|
// Identity must stay stable: a fresh callback each render would make React
|
|
27
29
|
// detach and reattach the node, re-measuring forever.
|
|
@@ -37,6 +39,7 @@ function useSlotCopyColor() {
|
|
|
37
39
|
ref,
|
|
38
40
|
mode: measured?.mode ?? null,
|
|
39
41
|
backdrop: measured?.backdrop ?? null,
|
|
42
|
+
hasMeasuredBackdrop: measured !== undefined,
|
|
40
43
|
tokens: measured ? STUDIO_CHROME_MODES[measured.mode] : null,
|
|
41
44
|
surfaceNeeded: measured
|
|
42
45
|
? needsSurface(measured.mode, measured.backdrop)
|
|
@@ -1 +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
|
|
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 { isEqual } from \"lodash-es\";\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 * False until the page colour behind the element has been read once, even\n * if it turned out unreadable. Chrome that animates its colours stays out of\n * layout until then, so it never paints the fallback and fades from it.\n */\n hasMeasuredBackdrop: boolean;\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 */\n/** The page colour behind the chrome and the mode picked for it. */\ninterface BackdropMeasurement {\n mode: StudioChromeMode;\n backdrop: Rgb;\n}\n\nexport function useSlotCopyColor<T extends HTMLElement>(): SlotChrome<T> {\n // `undefined` until the first measurement; `null` when the page colour\n // could not be read.\n const [measured, setMeasured] = useState<\n BackdropMeasurement | null | undefined\n >(undefined);\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 const nextMeasurement: BackdropMeasurement | null = backdrop\n ? { mode: pickChromeMode(backdrop), backdrop }\n : null;\n // The watcher re-measures on any style change in the page; keep the same\n // state when the answer hasn't changed, so the chrome doesn't re-render.\n setMeasured((previousMeasurement) =>\n isEqual(previousMeasurement, nextMeasurement)\n ? previousMeasurement\n : nextMeasurement,\n );\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 hasMeasuredBackdrop: measured !== undefined,\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":";;;;;;;SA+DgB,gBAAgB,GAAA;;;IAG9B,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAEtC,SAAS,CAAC;AACZ,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,MAAM,eAAe,GAA+B;cAChD,EAAE,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,QAAQ;cAC1C,IAAI;;;QAGR,WAAW,CAAC,CAAC,mBAAmB,KAC9B,OAAO,CAAC,mBAAmB,EAAE,eAAe;AAC1C,cAAE;cACA,eAAe,CACpB;IACH,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;QACpC,mBAAmB,EAAE,QAAQ,KAAK,SAAS;AAC3C,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,7 +1,8 @@
|
|
|
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
7
|
import { Immer } from 'immer';
|
|
7
8
|
|
|
@@ -41,6 +42,18 @@ function refreshNodeWeakMaps(root) {
|
|
|
41
42
|
};
|
|
42
43
|
visit(root);
|
|
43
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
|
+
}
|
|
44
57
|
const useSpecDataListener = (setState,
|
|
45
58
|
// Read into `stateRef` only β listener bodies use `stateRef.current` (not
|
|
46
59
|
// `state` directly) so the effect's deps don't include `state.data`, which
|
|
@@ -74,6 +87,7 @@ state, composableUid) => {
|
|
|
74
87
|
}
|
|
75
88
|
: dataSources[SECTION_COMPOSITIONS_KEY] || {};
|
|
76
89
|
const pageTemplate = dataSources.template;
|
|
90
|
+
const pageDataSources = pageDataSourcesOf(dataSources);
|
|
77
91
|
/**
|
|
78
92
|
* The document an instance's section data lives in (ADR 0017).
|
|
79
93
|
*
|
|
@@ -250,21 +264,22 @@ state, composableUid) => {
|
|
|
250
264
|
// iframe loaded with getSpecFromParent and never fetched the section's
|
|
251
265
|
// data sources itself β the studio pushes them later via
|
|
252
266
|
// UPDATE_SPEC_DATA. Pool-keyed maps would be ideal but the listener
|
|
253
|
-
// doesn't have access to them;
|
|
254
|
-
// 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.
|
|
255
270
|
const refreshedContentstack = dataSources.contentstack && typeof dataSources.contentstack === "object"
|
|
256
|
-
?
|
|
271
|
+
? dataSources.contentstack
|
|
257
272
|
: prev.contentstack || {};
|
|
258
273
|
const refreshedQueries = dataSources.contentstack_queries &&
|
|
259
274
|
typeof dataSources.contentstack_queries === "object"
|
|
260
|
-
?
|
|
275
|
+
? dataSources.contentstack_queries
|
|
261
276
|
: prev.contentstack_queries || {};
|
|
262
277
|
const next = {
|
|
263
278
|
...prev,
|
|
264
279
|
template: scopedTemplate,
|
|
265
280
|
contentstack: refreshedContentstack,
|
|
266
281
|
contentstack_queries: refreshedQueries,
|
|
267
|
-
page:
|
|
282
|
+
page: pageDataSources,
|
|
268
283
|
repeater: repeater ?? prev.repeater,
|
|
269
284
|
// Carry binding metadata so SectionCompositionProvider can re-scope the
|
|
270
285
|
// template from the LIVE per-iteration repeater item. The scopedTemplate
|
|
@@ -278,13 +293,10 @@ state, composableUid) => {
|
|
|
278
293
|
cardinality: binding?.cardinality,
|
|
279
294
|
componentPropsFallback: binding?.componentPropsFallback,
|
|
280
295
|
};
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
prev.contentstack_queries !== next.contentstack_queries ||
|
|
286
|
-
prev.componentPropsFallback !== next.componentPropsFallback) {
|
|
287
|
-
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;
|
|
288
300
|
changed = true;
|
|
289
301
|
}
|
|
290
302
|
}
|
|
@@ -395,16 +407,13 @@ state, composableUid) => {
|
|
|
395
407
|
...(data?.dataSources || {}),
|
|
396
408
|
[SECTION_COMPOSITIONS_KEY]: mergedSections,
|
|
397
409
|
};
|
|
398
|
-
const mergedData = {
|
|
410
|
+
const mergedData = keepEqualData(state.data, {
|
|
399
411
|
...state.data,
|
|
400
412
|
...data,
|
|
401
413
|
dataSources: mergedDataSources,
|
|
402
|
-
};
|
|
414
|
+
});
|
|
403
415
|
const rebuilt = rebuildScopedFromBindings(mergedData);
|
|
404
|
-
return {
|
|
405
|
-
...state,
|
|
406
|
-
data: rebuilt,
|
|
407
|
-
};
|
|
416
|
+
return rebuilt === state.data ? state : { ...state, data: rebuilt };
|
|
408
417
|
});
|
|
409
418
|
});
|
|
410
419
|
const previewEntryChangeListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.REPLACE_PREVIEW_ENTRY, async (event) => {
|
|
@@ -419,13 +428,13 @@ state, composableUid) => {
|
|
|
419
428
|
// dataSources β don't wipe sibling slices like `repeater` or
|
|
420
429
|
// `section_compositions`, which would cause a flicker for sections
|
|
421
430
|
// inside a Repeater (their item context would disappear).
|
|
422
|
-
const mergedData = {
|
|
431
|
+
const mergedData = keepEqualData(prevState.data, {
|
|
423
432
|
...prevState?.data,
|
|
424
433
|
[DATA_SOURCES_PREFIX]: {
|
|
425
434
|
...(prevState?.data?.[DATA_SOURCES_PREFIX] || {}),
|
|
426
435
|
...data?.dataSources,
|
|
427
436
|
},
|
|
428
|
-
};
|
|
437
|
+
});
|
|
429
438
|
// The merge updates dataSources.template, but each section's SCOPED
|
|
430
439
|
// template in section_scoped_data is derived from it β re-scope here,
|
|
431
440
|
// else a section keeps its stale (often null) scope and renders the
|
|
@@ -433,7 +442,9 @@ state, composableUid) => {
|
|
|
433
442
|
// UPDATE_SPEC_DATA handler already rebuilds; this is the equivalent for
|
|
434
443
|
// the preview-entry change path that EntryPickerBtn sends.)
|
|
435
444
|
const rebuilt = rebuildScopedFromBindings(mergedData);
|
|
436
|
-
return
|
|
445
|
+
return rebuilt === prevState.data
|
|
446
|
+
? prevState
|
|
447
|
+
: { ...prevState, data: rebuilt };
|
|
437
448
|
});
|
|
438
449
|
});
|
|
439
450
|
const applyOperationListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.APPLY_OPERATION, (event) => {
|
|
@@ -547,13 +558,13 @@ state, composableUid) => {
|
|
|
547
558
|
? { ...incoming, cardinality: prev.cardinality }
|
|
548
559
|
: incoming;
|
|
549
560
|
}
|
|
550
|
-
const mergedData = {
|
|
561
|
+
const mergedData = keepEqualData(prevState.data, {
|
|
551
562
|
...prevState.data,
|
|
552
563
|
dataSources: {
|
|
553
564
|
...prevState.data?.dataSources,
|
|
554
565
|
[SECTION_COMPOSITIONS_KEY]: merged,
|
|
555
566
|
},
|
|
556
|
-
};
|
|
567
|
+
});
|
|
557
568
|
// Pass the MERGED entries for the incoming uids (not the raw incoming)
|
|
558
569
|
// β rebuildScopedFromBindings spreads incomingBindings over the slice,
|
|
559
570
|
// so raw entries would reintroduce the dropped cardinality.
|
|
@@ -562,10 +573,9 @@ state, composableUid) => {
|
|
|
562
573
|
merged[uid],
|
|
563
574
|
]));
|
|
564
575
|
const finalData = rebuildScopedFromBindings(mergedData, incomingMerged);
|
|
565
|
-
return
|
|
566
|
-
|
|
567
|
-
data: finalData
|
|
568
|
-
};
|
|
576
|
+
return finalData === prevState.data
|
|
577
|
+
? prevState
|
|
578
|
+
: { ...prevState, data: finalData };
|
|
569
579
|
});
|
|
570
580
|
});
|
|
571
581
|
// Signal to Studio that our editorβiframe post-message listeners are now
|