@contentstack/studio-react-editor 1.3.0 → 1.3.1

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.
Files changed (53) hide show
  1. package/dist/components/BuildingIllustration.js +8 -0
  2. package/dist/components/BuildingIllustration.js.map +1 -0
  3. package/dist/components/EditableRenderer.js +29 -6
  4. package/dist/components/EditableRenderer.js.map +1 -1
  5. package/dist/components/Element.js +52 -25
  6. package/dist/components/Element.js.map +1 -1
  7. package/dist/components/PreviewRenderer.js +4 -0
  8. package/dist/components/PreviewRenderer.js.map +1 -1
  9. package/dist/components/Slot.js +26 -4
  10. package/dist/components/Slot.js.map +1 -1
  11. package/dist/components/WelcomeState.js +33 -0
  12. package/dist/components/WelcomeState.js.map +1 -0
  13. package/dist/components/elements/ConditionBlock.js +4 -0
  14. package/dist/components/elements/ConditionBlock.js.map +1 -1
  15. package/dist/components/elements/Repeater.js +8 -38
  16. package/dist/components/elements/Repeater.js.map +1 -1
  17. package/dist/components/elements/SectionComposition.js +94 -0
  18. package/dist/components/elements/SectionComposition.js.map +1 -0
  19. package/dist/components/elements/SectionSlot.js +154 -0
  20. package/dist/components/elements/SectionSlot.js.map +1 -0
  21. package/dist/components/elements/Symbol.js +6 -2
  22. package/dist/components/elements/Symbol.js.map +1 -1
  23. package/dist/components/styles.js +72 -0
  24. package/dist/components/styles.js.map +1 -1
  25. package/dist/contexts/providers/renderer.provider.js +1 -0
  26. package/dist/contexts/providers/renderer.provider.js.map +1 -1
  27. package/dist/contexts/providers/symbol-ui.provider.js +18 -6
  28. package/dist/contexts/providers/symbol-ui.provider.js.map +1 -1
  29. package/dist/hooks/use-active-node-path.hook.js +5 -1
  30. package/dist/hooks/use-active-node-path.hook.js.map +1 -1
  31. package/dist/hooks/use-canvas-events.hook.js +5 -2
  32. package/dist/hooks/use-canvas-events.hook.js.map +1 -1
  33. package/dist/hooks/use-condition-block-context.js +5 -1
  34. package/dist/hooks/use-condition-block-context.js.map +1 -1
  35. package/dist/hooks/use-design-preview.hook.js +5 -1
  36. package/dist/hooks/use-design-preview.hook.js.map +1 -1
  37. package/dist/hooks/use-preview-mode.hook.js +5 -1
  38. package/dist/hooks/use-preview-mode.hook.js.map +1 -1
  39. package/dist/hooks/use-register-section.hook.js +110 -0
  40. package/dist/hooks/use-register-section.hook.js.map +1 -0
  41. package/dist/hooks/use-renderer.hook.js +5 -1
  42. package/dist/hooks/use-renderer.hook.js.map +1 -1
  43. package/dist/hooks/use-repeater.hook.js +5 -1
  44. package/dist/hooks/use-repeater.hook.js.map +1 -1
  45. package/dist/hooks/use-section-events.hook.js +63 -0
  46. package/dist/hooks/use-section-events.hook.js.map +1 -0
  47. package/dist/hooks/use-should-show-design.hook.js +8 -1
  48. package/dist/hooks/use-should-show-design.hook.js.map +1 -1
  49. package/dist/hooks/use-spec-data-listener.hook.js +335 -10
  50. package/dist/hooks/use-spec-data-listener.hook.js.map +1 -1
  51. package/dist/hooks/use-symbol-events.hook.js +13 -0
  52. package/dist/hooks/use-symbol-events.hook.js.map +1 -1
  53. package/package.json +10 -10
@@ -0,0 +1,110 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { preProcessStaticValues } from '@contentstack/studio-client';
3
+ import { Node } from '@contentstack/studio-internal';
4
+ import { useMemo } from 'react';
5
+ import { SectionComposition } from '../components/elements/SectionComposition.js';
6
+ import { useRenderer } from './use-renderer.hook.js';
7
+
8
+ /**
9
+ * Reads sectionExposedProps from the section's UI metadata and converts them
10
+ * into the Props format that the component registry understands.
11
+ *
12
+ * This is what makes retrievePropValue resolve exposed-prop bindings on the
13
+ * page-level section-composition node — without these registered props the
14
+ * resolver skips them entirely and the override values never reach the section.
15
+ *
16
+ * Each exposed prop is enriched with the FULL schema of the internal component
17
+ * prop it was exposed from (looked up via the internal node's registered
18
+ * component). Registering only { type, displayName } loses `placeholder` and
19
+ * `defaultValue`, so a CLEARED exposed prop resolves to an empty value instead
20
+ * of the component's editor placeholder (e.g. "Your text here"). With the full
21
+ * schema, a cleared exposed prop resolves exactly like a normal unbound node —
22
+ * showing the placeholder in Studio — and the override carries it down to the
23
+ * internal node. The editor panel registration enriches the same way.
24
+ */
25
+ function buildRegisteredProps(section, componentRegistry) {
26
+ const exposedPropDefs = section.ui?.metadata?.sectionExposedProps ?? [];
27
+ // Index the section's internal nodes by uid so each exposed prop can recover
28
+ // its originating component prop schema.
29
+ const nodeByUid = new Map();
30
+ if (section.ui) {
31
+ for (const [node] of Node.nodes(section.ui)) {
32
+ if (node?.uid)
33
+ nodeByUid.set(node.uid, node);
34
+ }
35
+ }
36
+ const props = Object.fromEntries(exposedPropDefs.map((ep) => {
37
+ const internalNode = nodeByUid.get(ep.nodeUid);
38
+ const fullProp = internalNode
39
+ ? componentRegistry.getComponentByNode(internalNode)?.props?.[ep.propKey]
40
+ : undefined;
41
+ return [
42
+ ep.uid,
43
+ {
44
+ ...(fullProp ?? {}),
45
+ type: ep.propType,
46
+ displayName: ep.displayName,
47
+ },
48
+ ];
49
+ }));
50
+ return props;
51
+ }
52
+ /**
53
+ * Registers section composition entries as React components in the component registry.
54
+ * Each section is registered with its exposed props so the page-level binding
55
+ * resolver can resolve override values and pass them down to SectionComposition.
56
+ */
57
+ const registerSectionComponents = (sections, componentRegistry) => {
58
+ const sectionConfigs = sections.map((section) => {
59
+ // Section entries store `static_value` in raw shape (`{ text: [...] }`).
60
+ // The data binder expects the pre-processed flat shape (`{ key: value }`),
61
+ // so transform here before handing the section's spec to the renderer.
62
+ // Without this, every string prop on the section (e.g. SectionSlot's
63
+ // `label`) resolves to empty in consumption mode.
64
+ const rawStaticValue = (section?.static_value ?? {});
65
+ const sectionSpec = {
66
+ ui: section.ui,
67
+ data: {
68
+ dataSources: {},
69
+ static_value: preProcessStaticValues(rawStaticValue),
70
+ },
71
+ compositionEntry: section,
72
+ symbols: [],
73
+ sectionCompositions: sections,
74
+ };
75
+ return {
76
+ type: section.uid,
77
+ displayName: section.title,
78
+ thumbnailUrl: section?.ui_preview?.url,
79
+ wrap: false,
80
+ // Exposed props registered here so retrievePropValue resolves their
81
+ // page-level bindings and passes the values to SectionComposition.
82
+ props: buildRegisteredProps(section, componentRegistry),
83
+ component: (props) => {
84
+ return (jsx(SectionComposition, { ...props, compositionUID: section.uid, spec: sectionSpec }));
85
+ },
86
+ metadata: {
87
+ uid: section.uid,
88
+ type: "section-composition",
89
+ },
90
+ };
91
+ });
92
+ componentRegistry.registerSectionComponent(sectionConfigs);
93
+ };
94
+ /**
95
+ * React hook that registers section components when sections array changes.
96
+ * Automatically handles component registration lifecycle in React components.
97
+ *
98
+ * @param sections - Optional array of section composition entries
99
+ */
100
+ const useRegisterSectionComponents = (sections) => {
101
+ const { componentRegistry } = useRenderer();
102
+ useMemo(() => {
103
+ if (!sections?.length)
104
+ return;
105
+ registerSectionComponents(sections, componentRegistry);
106
+ }, [sections, componentRegistry]);
107
+ };
108
+
109
+ export { registerSectionComponents, useRegisterSectionComponents };
110
+ //# sourceMappingURL=use-register-section.hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-register-section.hook.js","sources":["../../src/hooks/use-register-section.hook.tsx"],"sourcesContent":["import {\n SectionCompositionEntry,\n StudioSpec,\n preProcessStaticValues,\n} from \"@contentstack/studio-client\";\nimport {\n ComponentRegistry,\n Props,\n RegisterComponentOptionsInput,\n} from \"@contentstack/studio-registry\";\nimport { Node, NodePropType } from \"@contentstack/studio-internal\";\nimport { ReactNode, useMemo } from \"react\";\nimport { SectionComposition } from \"../components/elements/SectionComposition\";\nimport { useRenderer } from \"./use-renderer.hook\";\n\ninterface ExposedPropDef {\n uid: string;\n nodeUid: string;\n propKey: string;\n propType: string;\n displayName: string;\n}\n\ntype SectionRegistryConfig = RegisterComponentOptionsInput<\n (props?: any) => ReactNode\n>;\n\n/**\n * Reads sectionExposedProps from the section's UI metadata and converts them\n * into the Props format that the component registry understands.\n *\n * This is what makes retrievePropValue resolve exposed-prop bindings on the\n * page-level section-composition node — without these registered props the\n * resolver skips them entirely and the override values never reach the section.\n *\n * Each exposed prop is enriched with the FULL schema of the internal component\n * prop it was exposed from (looked up via the internal node's registered\n * component). Registering only { type, displayName } loses `placeholder` and\n * `defaultValue`, so a CLEARED exposed prop resolves to an empty value instead\n * of the component's editor placeholder (e.g. \"Your text here\"). With the full\n * schema, a cleared exposed prop resolves exactly like a normal unbound node —\n * showing the placeholder in Studio — and the override carries it down to the\n * internal node. The editor panel registration enriches the same way.\n */\nfunction buildRegisteredProps(\n section: SectionCompositionEntry,\n componentRegistry: ComponentRegistry<unknown>,\n): Props {\n const exposedPropDefs: ExposedPropDef[] =\n (section.ui?.metadata?.sectionExposedProps as\n | ExposedPropDef[]\n | undefined) ?? [];\n\n // Index the section's internal nodes by uid so each exposed prop can recover\n // its originating component prop schema.\n const nodeByUid = new Map<string, Node>();\n if (section.ui) {\n for (const [node] of Node.nodes(section.ui as Node)) {\n if (node?.uid) nodeByUid.set(node.uid, node as Node);\n }\n }\n\n const props = Object.fromEntries(\n exposedPropDefs.map((ep) => {\n const internalNode = nodeByUid.get(ep.nodeUid);\n const fullProp = internalNode\n ? componentRegistry.getComponentByNode(internalNode)?.props?.[\n ep.propKey\n ]\n : undefined;\n return [\n ep.uid,\n {\n ...(fullProp ?? {}),\n type: ep.propType as NodePropType,\n displayName: ep.displayName,\n } as Props[string],\n ];\n }),\n );\n\n return props;\n}\n\n/**\n * Registers section composition entries as React components in the component registry.\n * Each section is registered with its exposed props so the page-level binding\n * resolver can resolve override values and pass them down to SectionComposition.\n */\nexport const registerSectionComponents = (\n sections: SectionCompositionEntry[],\n componentRegistry: ComponentRegistry<unknown>,\n) => {\n const sectionConfigs: SectionRegistryConfig[] = sections.map((section) => {\n // Section entries store `static_value` in raw shape (`{ text: [...] }`).\n // The data binder expects the pre-processed flat shape (`{ key: value }`),\n // so transform here before handing the section's spec to the renderer.\n // Without this, every string prop on the section (e.g. SectionSlot's\n // `label`) resolves to empty in consumption mode.\n const rawStaticValue = ((section as any)?.static_value ?? {}) as any;\n const sectionSpec: StudioSpec = {\n ui: section.ui,\n data: {\n dataSources: {},\n static_value: preProcessStaticValues(rawStaticValue),\n },\n compositionEntry: section,\n symbols: [],\n sectionCompositions: sections,\n };\n\n return {\n type: section.uid,\n displayName: section.title,\n thumbnailUrl: section?.ui_preview?.url,\n wrap: false,\n // Exposed props registered here so retrievePropValue resolves their\n // page-level bindings and passes the values to SectionComposition.\n props: buildRegisteredProps(section, componentRegistry),\n component: (props) => {\n return (\n <SectionComposition\n {...props}\n compositionUID={section.uid}\n spec={sectionSpec}\n />\n );\n },\n metadata: {\n uid: section.uid,\n type: \"section-composition\",\n },\n };\n });\n\n componentRegistry.registerSectionComponent(sectionConfigs);\n};\n\n/**\n * React hook that registers section components when sections array changes.\n * Automatically handles component registration lifecycle in React components.\n *\n * @param sections - Optional array of section composition entries\n */\nexport const useRegisterSectionComponents = (\n sections?: SectionCompositionEntry[],\n) => {\n const { componentRegistry } = useRenderer();\n\n useMemo(() => {\n if (!sections?.length) return;\n registerSectionComponents(sections, componentRegistry);\n }, [sections, componentRegistry]);\n};\n"],"names":["_jsx"],"mappings":"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"}
@@ -6,9 +6,13 @@ import '@contentstack/studio-messenger';
6
6
  import '@contentstack/studio-react-components/contexts';
7
7
  import 'immer';
8
8
  import { useContext } from 'react';
9
+ import '@contentstack/studio-internal';
10
+ import '@contentstack/studio-core';
11
+ import '@contentstack/studio-react-components/basic-components';
9
12
  import '@contentstack/studio-react-components/hooks';
10
- import '@contentstack/studio-registry';
13
+ import 'goober';
11
14
  import '../components/Element.js';
15
+ import '@contentstack/studio-registry';
12
16
  import '../contexts/providers/use-design-preview.provider.js';
13
17
  import '../contexts/providers/use-repeater.provider.js';
14
18
  import '../contexts/providers/use-condition-block.provider.js';
@@ -1 +1 @@
1
- {"version":3,"file":"use-renderer.hook.js","sources":["../../src/hooks/use-renderer.hook.ts"],"sourcesContent":["import { rendererContext } from \"../contexts/providers\";\nimport { useContext } from \"react\";\n\nexport const useRenderer = () => {\n const context = useContext(rendererContext);\n return context;\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGO,MAAM,WAAW,GAAG,MAAK;AAC9B,IAAA,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC;AAC3C,IAAA,OAAO,OAAO;AAChB;;;;"}
1
+ {"version":3,"file":"use-renderer.hook.js","sources":["../../src/hooks/use-renderer.hook.ts"],"sourcesContent":["import { rendererContext } from \"../contexts/providers\";\nimport { useContext } from \"react\";\n\nexport const useRenderer = () => {\n const context = useContext(rendererContext);\n return context;\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAGO,MAAM,WAAW,GAAG,MAAK;AAC9B,IAAA,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC;AAC3C,IAAA,OAAO,OAAO;AAChB;;;;"}
@@ -6,9 +6,13 @@ import '@contentstack/studio-client';
6
6
  import '@contentstack/studio-messenger';
7
7
  import '@contentstack/studio-react-components/contexts';
8
8
  import 'immer';
9
+ import '@contentstack/studio-internal';
10
+ import '@contentstack/studio-core';
11
+ import '@contentstack/studio-react-components/basic-components';
9
12
  import '@contentstack/studio-react-components/hooks';
10
- import '@contentstack/studio-registry';
13
+ import 'goober';
11
14
  import '../components/Element.js';
15
+ import '@contentstack/studio-registry';
12
16
  import '../contexts/providers/use-design-preview.provider.js';
13
17
  import { RepeaterContext } from '../contexts/providers/use-repeater.provider.js';
14
18
  import '../contexts/providers/use-condition-block.provider.js';
@@ -1 +1 @@
1
- {"version":3,"file":"use-repeater.hook.js","sources":["../../src/hooks/use-repeater.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { RepeaterContext } from \"../contexts/providers\";\n\nexport const useRepeaterContext = () => useContext(RepeaterContext);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGO,MAAM,kBAAkB,GAAG,MAAM,UAAU,CAAC,eAAe;;;;"}
1
+ {"version":3,"file":"use-repeater.hook.js","sources":["../../src/hooks/use-repeater.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { RepeaterContext } from \"../contexts/providers\";\n\nexport const useRepeaterContext = () => useContext(RepeaterContext);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAGO,MAAM,kBAAkB,GAAG,MAAM,UAAU,CAAC,eAAe;;;;"}
@@ -0,0 +1,63 @@
1
+ import { clientRendererModeUtil, isCompositionBeingEdited } from '@contentstack/studio-client';
2
+ import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
3
+ import { useEffect } from 'react';
4
+
5
+ /**
6
+ * React hook that manages section composition events from the Studio.
7
+ * Pulls current sections after mount to avoid losing registrations during initial load,
8
+ * AND re-fetches whenever the spec UI references a section uid that isn't yet
9
+ * known locally (e.g. a section was just dropped in Studio).
10
+ *
11
+ * @param setState - State setter function to update the spec
12
+ * @param state - Current studio spec state
13
+ * @param composableUid - UID of the composition being edited
14
+ */
15
+ const useSectionEvents = (setState, state, composableUid) => {
16
+ // Register the catalog-update listener AS SOON AS the iframe is inside
17
+ // the Studio frame — independent of spec arrival. Studio's
18
+ // `useSectionCompositions` pushes the full catalog the moment its React
19
+ // Query resolves; that push can arrive before the iframe has received
20
+ // its first GET_COMPOSITION_SPEC response and populated `composableUid`,
21
+ // so gating the listener on the latter caused NO_REQUEST_LISTENER_FOUND
22
+ // on every fresh page load.
23
+ useEffect(() => {
24
+ if (!clientRendererModeUtil.isInsideStudioFrame())
25
+ return;
26
+ const catalogListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.UPDATE_SECTIONS_CATALOG, (event) => {
27
+ if (!event.data?.sectionCompositions)
28
+ return;
29
+ setState((prevState) => ({
30
+ ...prevState,
31
+ sectionCompositions: event.data.sectionCompositions,
32
+ }));
33
+ });
34
+ return () => {
35
+ catalogListener?.unregister();
36
+ };
37
+ // Register once on mount; the handler reads via setState's prev so it
38
+ // doesn't need state in deps.
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, []);
41
+ // GET_SECTIONS one-shot fetch — runs after the composition is known so
42
+ // the initial section catalog is populated even when Studio's React
43
+ // Query was already resolved before the iframe mounted (no catalog push
44
+ // is fired in that case).
45
+ useEffect(() => {
46
+ if (!isCompositionBeingEdited(composableUid || ""))
47
+ return;
48
+ composableStudioEventManager
49
+ ?.send(POST_MESSAGE_EVENTS.GET_SECTIONS, {})
50
+ .then((data) => {
51
+ if (!data || !("sectionCompositions" in data))
52
+ return;
53
+ setState((prevState) => ({
54
+ ...prevState,
55
+ sectionCompositions: data.sectionCompositions,
56
+ }));
57
+ })
58
+ .catch(() => { });
59
+ }, [state?.compositionEntry?.uid, composableUid]);
60
+ };
61
+
62
+ export { useSectionEvents };
63
+ //# sourceMappingURL=use-section-events.hook.js.map
@@ -0,0 +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 {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} 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":";;;;AAYA;;;;;;;;;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;;;;"}
@@ -1,3 +1,4 @@
1
+ import { clientRendererModeUtil } from '@contentstack/studio-client';
1
2
  import { useConditionBlockContext } from './use-condition-block-context.js';
2
3
  import { useDesignPreviewContext } from './use-design-preview.hook.js';
3
4
  import { useRenderer } from './use-renderer.hook.js';
@@ -8,7 +9,13 @@ function useShouldShowDesign(mode) {
8
9
  const { isInsideRepeater } = useRepeaterContext();
9
10
  const { isInsideConditionBlock } = useConditionBlockContext();
10
11
  const designPreviewContext = useDesignPreviewContext();
11
- if (!isCompositionBeingEdited)
12
+ // Treat the Studio editor frame as design-mode-eligible from the very first
13
+ // render — even before `isCompositionBeingEdited` has resolved — to avoid a
14
+ // one-frame preview render that would inject items[0] context. Use
15
+ // `isInsideStudioFrame()` (URL-param-gated) so Visual Builder's iframe
16
+ // (which should render preview) is correctly excluded.
17
+ const isInsideStudio = clientRendererModeUtil.isInsideStudioFrame();
18
+ if (!isCompositionBeingEdited && !isInsideStudio)
12
19
  return false;
13
20
  if (isInsideRepeater || isInsideConditionBlock) {
14
21
  // If composition is being edited and current node(Repeater or Condition Block) inside another repeater or condition block,
@@ -1 +1 @@
1
- {"version":3,"file":"use-should-show-design.hook.js","sources":["../../src/hooks/use-should-show-design.hook.ts"],"sourcesContent":["import { 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\nexport function useShouldShowDesign(mode: \"design\" | \"preview\") {\n const { isCompositionBeingEdited } = useRenderer();\n const { isInsideRepeater } = useRepeaterContext();\n const { isInsideConditionBlock } = useConditionBlockContext();\n const designPreviewContext = useDesignPreviewContext();\n if (!isCompositionBeingEdited) return false;\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"],"names":[],"mappings":";;;;;AAKM,SAAU,mBAAmB,CAAC,IAA0B,EAAA;AAC5D,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,IAAI,CAAC,wBAAwB;AAAE,QAAA,OAAO,KAAK;AAE3C,IAAA,IAAI,gBAAgB,IAAI,sBAAsB,EAAE;;;AAG9C,QAAA,IAAI,CAAC,oBAAoB;AAAE,YAAA,OAAO,IAAI;;;QAGtC,OAAO,oBAAoB,KAAK,QAAQ;IAC1C;;IAEA,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,OAAO,IAAI;IACb;;IAEA,OAAO,IAAI,KAAK,QAAQ;AAC1B;;;;"}
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 { 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\nexport function useShouldShowDesign(mode: \"design\" | \"preview\") {\n const { isCompositionBeingEdited } = useRenderer();\n const { isInsideRepeater } = useRepeaterContext();\n const { isInsideConditionBlock } = useConditionBlockContext();\n const designPreviewContext = useDesignPreviewContext();\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 if (!isCompositionBeingEdited && !isInsideStudio) return false;\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"],"names":[],"mappings":";;;;;;AAMM,SAAU,mBAAmB,CAAC,IAA0B,EAAA;AAC5D,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;;;;;;AAMtD,IAAA,MAAM,cAAc,GAAG,sBAAsB,CAAC,mBAAmB,EAAE;AACnE,IAAA,IAAI,CAAC,wBAAwB,IAAI,CAAC,cAAc;AAAE,QAAA,OAAO,KAAK;AAE9D,IAAA,IAAI,gBAAgB,IAAI,sBAAsB,EAAE;;;AAG9C,QAAA,IAAI,CAAC,oBAAoB;AAAE,YAAA,OAAO,IAAI;;;QAGtC,OAAO,oBAAoB,KAAK,QAAQ;IAC1C;;IAEA,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,OAAO,IAAI;IACb;;IAEA,OAAO,IAAI,KAAK,QAAQ;AAC1B;;;;"}