@contentstack/studio-react-editor 1.5.0 → 1.7.0-alpha-20260721T1325-1838437.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 +4 -1
- package/dist/components/EditableRenderer.js.map +1 -1
- package/dist/components/Element.js +2 -0
- package/dist/components/Element.js.map +1 -1
- package/dist/components/PreviewRenderer.js +2 -0
- package/dist/components/PreviewRenderer.js.map +1 -1
- package/dist/components/WelcomeState.js +53 -19
- package/dist/components/WelcomeState.js.map +1 -1
- package/dist/components/elements/ConditionBlock.js +2 -0
- package/dist/components/elements/ConditionBlock.js.map +1 -1
- package/dist/components/elements/Repeater.js +2 -0
- package/dist/components/elements/Repeater.js.map +1 -1
- package/dist/components/elements/SectionComposition.js +25 -7
- package/dist/components/elements/SectionComposition.js.map +1 -1
- package/dist/components/elements/SectionSlot.js +39 -4
- package/dist/components/elements/SectionSlot.js.map +1 -1
- package/dist/components/elements/Symbol.js +2 -0
- package/dist/components/elements/Symbol.js.map +1 -1
- package/dist/contexts/providers/edit-context.provider.js +14 -0
- package/dist/contexts/providers/edit-context.provider.js.map +1 -0
- package/dist/contexts/providers/symbol-ui.provider.js +2 -0
- package/dist/contexts/providers/symbol-ui.provider.js.map +1 -1
- package/dist/hooks/use-active-node-path.hook.js +2 -0
- package/dist/hooks/use-active-node-path.hook.js.map +1 -1
- package/dist/hooks/use-condition-block-context.js +2 -0
- package/dist/hooks/use-condition-block-context.js.map +1 -1
- package/dist/hooks/use-design-preview.hook.js +2 -0
- package/dist/hooks/use-design-preview.hook.js.map +1 -1
- package/dist/hooks/use-edit-context-listener.hook.js +48 -0
- package/dist/hooks/use-edit-context-listener.hook.js.map +1 -0
- package/dist/hooks/use-preview-mode.hook.js +2 -0
- package/dist/hooks/use-preview-mode.hook.js.map +1 -1
- package/dist/hooks/use-renderer.hook.js +2 -0
- package/dist/hooks/use-renderer.hook.js.map +1 -1
- package/dist/hooks/use-repeater.hook.js +2 -0
- package/dist/hooks/use-repeater.hook.js.map +1 -1
- package/dist/hooks/use-should-show-design.hook.js +2 -0
- package/dist/hooks/use-should-show-design.hook.js.map +1 -1
- package/dist/hooks/use-spec-data-listener.hook.js +50 -0
- package/dist/hooks/use-spec-data-listener.hook.js.map +1 -1
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SectionComposition.js","sources":["../../../src/components/elements/SectionComposition.tsx"],"sourcesContent":["import { Button, EDIT_SECTIONS_LABEL } from \"@contentstack/studio-core\";\nimport {\n POST_MESSAGE_EVENTS,\n composableStudioEventManager,\n} from \"@contentstack/studio-messenger\";\nimport { COMPOSABLE_DATA_ATTRIBUTES } from \"@contentstack/studio-client\";\nimport { SectionCompositionProvider } from \"@contentstack/studio-react-components/basic-components\";\nimport { DataCtxProvider } from \"@contentstack/studio-react-components/contexts\";\nimport {\n useCurrentNode,\n useData,\n} from \"@contentstack/studio-react-components/hooks\";\nimport { css } from \"goober\";\nimport { MouseEvent, useCallback, useMemo } from \"react\";\nimport { PreviewRenderer } from \"../PreviewRenderer\";\nimport { StudioAttributes } from \"../../types\";\nimport { styleFactory } from \"../styles\";\nimport { SectionModeContext } from \"../../contexts/providers/section-mode.provider\";\nimport { useDesignPreviewContext } from \"../../hooks/use-design-preview.hook\";\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\ninterface BindingValue {\n path?: Record<string, unknown>;\n [key: string]: unknown;\n}\n\nexport interface ExposedPropDef {\n uid: string;\n nodeUid: string;\n propKey: string;\n /** The binding the internal node had at expose-time (e.g. template.title).\n * SectionCompositionProvider uses this to know which field in the\n * section-scoped template to override. */\n bindingAtExposeTime?: { type: string; value: BindingValue };\n}\n\ntype SectionSpec = {\n compositionEntry?: {\n uid: string;\n };\n ui?: any;\n [key: string]: any;\n};\n\ninterface SectionCompositionProps extends StudioAttributes {\n spec: SectionSpec;\n compositionUID: string;\n className?: string;\n /** Per-placement design/preview mode from the placed node's `metadata.mode`. */\n mode?: \"design\" | \"preview\";\n [key: string]: any;\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\n/** Whether the section's authored UI contains at least one section-slot. */\nfunction sectionHasSlot(ui: any): boolean {\n if (!ui || typeof ui !== \"object\") return false;\n if (ui.type === \"section-slot\") return true;\n const slots = ui.slots || {};\n for (const slotId of Object.keys(slots)) {\n for (const child of slots[slotId] || []) {\n if (sectionHasSlot(child)) return true;\n }\n }\n return false;\n}\n\n/**\n * Effective design/preview mode for a placed section. The placement's explicit\n * `metadata.mode` (passed as the `mode` prop) wins; otherwise derive from the\n * section's content — `design` if it has a section-slot (so its drop-zones stay\n * visible) else `preview`. Mirrors `deriveSectionMode` on the Studio side.\n */\nfunction resolveSectionMode(\n mode: \"design\" | \"preview\" | undefined,\n spec: SectionSpec,\n): \"design\" | \"preview\" {\n if (mode === \"design\" || mode === \"preview\") return mode;\n return sectionHasSlot(spec?.ui) ? \"design\" : \"preview\";\n}\n\n/** Reads sectionExposedProps from the section spec's UI metadata. */\nfunction getExposedPropDefs(spec: SectionSpec): ExposedPropDef[] {\n const compositionEntry = spec.compositionEntry as\n | { ui?: { metadata?: Record<string, unknown> } }\n | undefined;\n return (\n (compositionEntry?.ui?.metadata?.sectionExposedProps as\n | ExposedPropDef[]\n | undefined) ?? []\n );\n}\n\n/**\n * Builds a map of { [ep.uid]: resolvedValue } from the props that\n * retrievePropValue already resolved for the page-level section node.\n *\n * retrievePropValue resolves the bindings the page composer set on the section\n * node's exposed props (e.g. template.heroTitle) and spreads them onto this\n * component. The page node's binding is the SOLE source of truth for an exposed\n * prop, so we emit an entry for EVERY exposed prop — including cleared/empty\n * ones (value `undefined`/`\"\"`). That lets a cleared prop render its empty value\n * downstream instead of falling back to the section's internal binding.\n */\nfunction buildOverrideValues(\n exposedPropDefs: ExposedPropDef[],\n rest: Record<string, unknown>,\n): Record<string, unknown> {\n const overrides: Record<string, unknown> = {};\n for (const ep of exposedPropDefs) {\n overrides[ep.uid] = rest[ep.uid];\n }\n return overrides;\n}\n\n/**\n * Builds a map of { [ep.uid]: cslpTag } from the `$<ep.uid>` CSLP props\n * retrievePropValue resolved for the page-level section node. Forwarded to the\n * provider so an overridden exposed prop keeps its `data-cslp` edit tag — the\n * override short-circuits retrievePropValue before it would compute one, and\n * the page-level tag (e.g. blog_post.<entry>.<locale>.hero_card.title) is the\n * correct target for the edit overlay. `domProps` strips these `$`-keys from the\n * DOM spread, so capture them here first.\n */\nfunction buildOverrideCslp(\n exposedPropDefs: ExposedPropDef[],\n rest: Record<string, unknown>,\n): Record<string, unknown> {\n const cslp: Record<string, unknown> = {};\n for (const ep of exposedPropDefs) {\n cslp[ep.uid] = rest[`$${ep.uid}`];\n }\n return cslp;\n}\n\n// ─── Icon ────────────────────────────────────────────────────────────────────\n\nfunction StudioIcon() {\n return (\n <svg\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 20 20\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2.5 5.37989C2.5 4.39075 3.36764 3.62971 4.34018 3.76578L4.96257 3.85287C8.30481 4.3205 11.6952 4.3205 15.0374 3.85287L15.6598 3.76579C16.6324 3.62971 17.5 4.39075 17.5 5.37989V12.1389C17.5 13.1281 16.6324 13.8891 15.6598 13.753L15.2334 13.6934C14.9921 13.6596 14.8236 13.4351 14.8571 13.192C14.8907 12.9489 15.1135 12.7792 15.3548 12.8129L15.7812 12.8726C16.2233 12.9345 16.6176 12.5885 16.6176 12.1389V5.37989C16.6176 4.93028 16.2233 4.58436 15.7812 4.64621L15.1588 4.73329C11.736 5.21219 8.26397 5.21219 4.84118 4.73329L4.2188 4.64621C3.77673 4.58436 3.38235 4.93028 3.38235 5.37989V12.1389C3.38235 12.5885 3.77673 12.9345 4.2188 12.8726L4.64519 12.8129C4.88653 12.7792 5.10934 12.9489 5.14286 13.192C5.17638 13.4351 5.00791 13.6596 4.76657 13.6934L4.34019 13.753C3.36764 13.8891 2.5 13.1281 2.5 12.1389V5.37989Z\"\n fill=\"#6C5CE7\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M6.02941 9.0557C6.02941 8.64661 6.35861 8.31497 6.76471 8.31497H8.52941C8.9355 8.31497 9.26471 8.64661 9.26471 9.0557V10.801C9.26471 11.2101 8.9355 11.5418 8.52941 11.5418H6.76471C6.35861 11.5418 6.02941 11.2101 6.02941 10.801V9.0557ZM6.91176 9.20384V10.6529H8.38235V9.20384H6.91176Z\"\n fill=\"#6C5CE7\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M10.1471 8.16682C10.1471 7.59409 10.6079 7.1298 11.1765 7.1298H13.5294C14.0979 7.1298 14.5588 7.59409 14.5588 8.16682V10.5047C14.5588 11.0775 14.0979 11.5418 13.5294 11.5418H11.1765C10.6079 11.5418 10.1471 11.0775 10.1471 10.5047V8.16682ZM11.1765 8.01868C11.0953 8.01868 11.0294 8.08501 11.0294 8.16682V10.5047C11.0294 10.5866 11.0953 10.6529 11.1765 10.6529H13.5294C13.6106 10.6529 13.6765 10.5866 13.6765 10.5047V8.16682C13.6765 8.08501 13.6106 8.01868 13.5294 8.01868H11.1765Z\"\n fill=\"#6C5CE7\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M10 12.4306C10.5685 12.4306 11.0294 12.8949 11.0294 13.4677V15.838C11.0294 16.4107 10.5685 16.875 10 16.875H7.05882C6.49029 16.875 6.02941 16.4107 6.02941 15.838L6.02941 13.4677C6.02941 12.8949 6.49029 12.4306 7.05882 12.4306H10ZM10.1471 13.4677C10.1471 13.3858 10.0812 13.3195 10 13.3195H7.05882C6.97761 13.3195 6.91176 13.3858 6.91176 13.4677V15.838C6.91176 15.9198 6.97761 15.9861 7.05882 15.9861H10C10.0812 15.9861 10.1471 15.9198 10.1471 15.838V13.4677Z\"\n fill=\"#6C5CE7\"\n />\n <path\n d=\"M12.7134 12.9508C12.7104 12.902 12.7639 12.8707 12.8044 12.8976L14.6152 14.0966C14.6598 14.1261 14.6455 14.1954 14.5929 14.2045L13.6175 14.3742C13.6036 14.3766 13.5911 14.3839 13.5821 14.3948L12.9517 15.1636C12.9177 15.205 12.8509 15.1832 12.8476 15.1295L12.7134 12.9508Z\"\n fill=\"#6C5CE7\"\n />\n </svg>\n );\n}\n\n// ─── Component ───────────────────────────────────────────────────────────────\n\nexport function SectionComposition({\n spec,\n compositionUID,\n studioAttributes,\n className,\n mode,\n ...rest\n}: SectionCompositionProps) {\n const styles = styleFactory(css);\n const data = useData();\n // The page-side instance uid keys this section's per-instance scoped data\n // (section_scoped_data[instanceUid] — carries selectedField/parentRepeaterUID\n // for per-iteration re-scope). It is normally read from the builder node id in\n // `studioAttributes`, but the editor strips that attribute when a node renders\n // in PREVIEW mode (e.g. a section transcluded into a section-slot whose\n // enclosing placed section has Preview Mode on — see SectionSlot). Falling back\n // to the surrounding CurrentNodeContext keeps the instance identity (and thus\n // the correct scoped entry) intact in preview, so a slot-nested section still\n // binds to its per-iteration repeater item instead of the page root.\n const { currentNodeUid } = useCurrentNode();\n const instanceUid =\n studioAttributes?.[COMPOSABLE_DATA_ATTRIBUTES.ID] ?? currentNodeUid;\n\n // A single section-composition node renders ONCE PER ITERATION when wrapped\n // by an iterating ancestor Repeater (page-side OR section-internal). Each\n // render produces its own \"Edit Composition\" button — all pointing at the\n // same compositionUID. Show the button only when every ancestor Repeater is\n // at iteration 0 (or there are no iterating ancestors). This collapses the\n // N-button UI down to one without restructuring the render tree.\n //\n // The map contains only ancestor Repeaters because the editor's Repeater\n // spreads its new entry on top of the inherited map; siblings can't reach\n // this subtree through React context. Design-mode Repeaters don't push a\n // context entry at all, so they don't trigger the gate.\n const isFirstIteration = useMemo(() => {\n const repeaterMap = (data as any)?.dataSources?.repeater;\n if (!repeaterMap || typeof repeaterMap !== \"object\") return true;\n for (const uid of Object.keys(repeaterMap)) {\n const idx = repeaterMap[uid]?.index;\n if (typeof idx === \"number\" && idx !== 0) return false;\n }\n return true;\n }, [data]);\n\n // Mode for everything inside this section. The topmost mode node owns it: if\n // this section is itself inside a repeater/condition-block, that ancestor's\n // DesignPreviewContext (design|preview) wins, overriding the section's own\n // mode. Otherwise the section owns it — explicit placement value, else derived\n // from content. `none` = no enclosing mode node.\n const enclosingMode = useDesignPreviewContext();\n const sectionMode =\n enclosingMode === \"design\" || enclosingMode === \"preview\"\n ? enclosingMode\n : resolveSectionMode(mode, spec);\n\n const handleEditClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n event.stopPropagation();\n composableStudioEventManager?.send(\n POST_MESSAGE_EVENTS.OPEN_IN_COMPOSABLE_STUDIO_EVENT_MESSAGE,\n { compositionEntryUid: compositionUID, compositionQuery: null },\n );\n },\n [compositionUID],\n );\n\n // Definitions of which props are exposed (uid, bindingAtExposeTime, etc.)\n const exposedPropDefs = useMemo(() => getExposedPropDefs(spec), [spec]);\n\n // Map of { [ep.uid]: resolvedPageValue } — values already resolved by\n // retrievePropValue against the page's data context and spread into rest.\n const overrideValues = useMemo(\n () => buildOverrideValues(exposedPropDefs, rest),\n [\n exposedPropDefs,\n JSON.stringify(exposedPropDefs.map((ep) => rest[ep.uid])),\n ],\n );\n\n // Page composer's LIVE binding type per exposed prop (emitted by\n // retrievePropValue for section-composition nodes). Lets the provider tell an\n // untouched repeater seed from a real page-level override.\n const exposedBindingTypes = (rest.section_exposed_binding_types ??\n {}) as Record<string, string>;\n // Which exposed props are still auto-seeded (untouched) — those defer to the\n // section's internal binding so they follow schema switches / repeater context.\n const exposedAutoSeeded = (rest.section_exposed_auto_seeded ?? {}) as Record<\n string,\n boolean\n >;\n // Map of { [ep.uid]: cslpTag } — the page-resolved `$<ep.uid>` tags, forwarded\n // so overridden exposed props keep their live-preview edit tag.\n const overrideCslp = useMemo(\n () => buildOverrideCslp(exposedPropDefs, rest),\n [\n exposedPropDefs,\n JSON.stringify(exposedPropDefs.map((ep) => rest[`$${ep.uid}`])),\n ],\n );\n\n // Exclude exposed prop keys and their $-prefixed CSLP counterparts from DOM\n // spread. retrievePropValue adds both `uid` (resolved value) and `$uid` (CSLP\n // live-preview tag) to the resolved props — both are invalid as div attributes.\n const domProps = useMemo(() => {\n const excluded = new Set([\n ...exposedPropDefs.flatMap((ep) => [ep.uid, `$${ep.uid}`]),\n \"section_exposed_binding_types\",\n \"section_exposed_auto_seeded\",\n ]);\n return Object.fromEntries(\n Object.entries(rest).filter(([k]) => !excluded.has(k)),\n );\n }, [exposedPropDefs, rest]);\n\n // Keep the section instance's id on its host even in PREVIEW mode, where the\n // editor (Element) strips builder attributes from slot children. The id alone\n // carries no selection affordance — interaction is driven by the\n // ELEMENT_TO_NODE map the builder ref populates, which preview omits — but it\n // preserves the per-instance DOM identity the \"Edit Composition\" button is\n // scoped under and keeps a stable hook for each placed section.\n const instanceIdAttr = instanceUid\n ? { [COMPOSABLE_DATA_ATTRIBUTES.ID]: instanceUid }\n : {};\n\n return (\n <div\n {...domProps}\n {...instanceIdAttr}\n {...studioAttributes}\n className={[styles.embeddedSectionHost, className]\n .filter(Boolean)\n .join(\" \")}\n >\n {isFirstIteration && (\n <Button\n className={`cs-embedded-section-edit-btn ${styles.embeddedSectionButton}`}\n onClick={handleEditClick}\n type=\"button\"\n data-studio-ui={true}\n >\n <StudioIcon />\n {EDIT_SECTIONS_LABEL}\n </Button>\n )}\n\n {/*\n * exposedPropDefs + overrideValues are forwarded to the provider so it\n * can inject the page-composer's override values into the section-scoped\n * template before the internal UI tree renders.\n */}\n <SectionModeContext.Provider value={sectionMode}>\n <SectionCompositionProvider\n uid={compositionUID}\n instanceUid={instanceUid}\n exposedPropDefs={exposedPropDefs}\n overrideValues={overrideValues}\n exposedBindingTypes={exposedBindingTypes}\n exposedAutoSeeded={exposedAutoSeeded}\n overrideCslp={overrideCslp}\n >\n <SectionDataMerger spec={spec}>\n <PreviewRenderer spec={spec as any} />\n </SectionDataMerger>\n </SectionCompositionProvider>\n </SectionModeContext.Provider>\n </div>\n );\n}\n\n/**\n * Merges the section's own `spec.data.static_value` into the active data\n * context so static-value-bound props authored inside the section (e.g. a\n * SectionSlot's `label`, or any Text/Number/etc. inside the section's body)\n * resolve against the section's persisted values when the section is\n * consumed in a page. Without this, child Elements call useData() and get\n * the page's data, which doesn't contain the section's static_value keys.\n */\nfunction SectionDataMerger({\n spec,\n children,\n}: {\n spec: SectionSpec;\n children: React.ReactNode;\n}) {\n const outerData = useData();\n const merged = useMemo(() => {\n const sectionStatic = (spec as any)?.data?.static_value;\n if (!sectionStatic || typeof sectionStatic !== \"object\") return outerData;\n return {\n ...(outerData as any),\n static_value: {\n ...((outerData as any)?.static_value || {}),\n ...sectionStatic,\n },\n };\n }, [outerData, spec]);\n return <DataCtxProvider value={merged as any}>{children}</DataCtxProvider>;\n}\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;;AAsDA;AAEA;AACA,SAAS,cAAc,CAAC,EAAO,EAAA;AAC7B,IAAA,IAAI,CAAC,EAAE,IAAI,OAAO,EAAE,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;AAC/C,IAAA,IAAI,EAAE,CAAC,IAAI,KAAK,cAAc;AAAE,QAAA,OAAO,IAAI;AAC3C,IAAA,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,IAAI,EAAE;IAC5B,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACvC,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE;YACvC,IAAI,cAAc,CAAC,KAAK,CAAC;AAAE,gBAAA,OAAO,IAAI;QACxC;IACF;AACA,IAAA,OAAO,KAAK;AACd;AAEA;;;;;AAKG;AACH,SAAS,kBAAkB,CACzB,IAAsC,EACtC,IAAiB,EAAA;AAEjB,IAAA,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS;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,CACb,CACV,EAODA,GAAA,CAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,WAAW,EAAA,QAAA,EAC7CA,GAAA,CAAC,0BAA0B,IACzB,GAAG,EAAE,cAAc,EACnB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,EAChC,cAAc,EAAE,cAAc,EAC9B,mBAAmB,EAAE,mBAAmB,EACxC,iBAAiB,EAAE,iBAAiB,EACpC,YAAY,EAAE,YAAY,YAE1BA,GAAA,CAAC,iBAAiB,IAAC,IAAI,EAAE,IAAI,EAAA,QAAA,EAC3BA,GAAA,CAAC,eAAe,EAAA,EAAC,IAAI,EAAE,IAAW,EAAA,CAAI,GACpB,EAAA,CACO,EAAA,CACD,CAAA,EAAA,CAC1B;AAEV;AAEA;;;;;;;AAOG;AACH,SAAS,iBAAiB,CAAC,EACzB,IAAI,EACJ,QAAQ,GAIT,EAAA;AACC,IAAA,MAAM,SAAS,GAAG,OAAO,EAAE;AAC3B,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAK;AAC1B,QAAA,MAAM,aAAa,GAAI,IAAY,EAAE,IAAI,EAAE,YAAY;AACvD,QAAA,IAAI,CAAC,aAAa,IAAI,OAAO,aAAa,KAAK,QAAQ;AAAE,YAAA,OAAO,SAAS;QACzE,OAAO;AACL,YAAA,GAAI,SAAiB;AACrB,YAAA,YAAY,EAAE;AACZ,gBAAA,IAAK,SAAiB,EAAE,YAAY,IAAI,EAAE,CAAC;AAC3C,gBAAA,GAAG,aAAa;AACjB,aAAA;SACF;AACH,IAAA,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACrB,OAAOA,GAAA,CAAC,eAAe,EAAA,EAAC,KAAK,EAAE,MAAa,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAmB;AAC5E;;;;"}
|
|
1
|
+
{"version":3,"file":"SectionComposition.js","sources":["../../../src/components/elements/SectionComposition.tsx"],"sourcesContent":["import { Button, EDIT_SECTIONS_LABEL } from \"@contentstack/studio-core\";\nimport {\n POST_MESSAGE_EVENTS,\n composableStudioEventManager,\n} from \"@contentstack/studio-messenger\";\nimport { COMPOSABLE_DATA_ATTRIBUTES } from \"@contentstack/studio-client\";\nimport { SectionCompositionProvider } from \"@contentstack/studio-react-components/basic-components\";\nimport {\n DataCtxProvider,\n DefaultChainCtx,\n} from \"@contentstack/studio-react-components/contexts\";\nimport {\n useCurrentNode,\n useData,\n} from \"@contentstack/studio-react-components/hooks\";\nimport { css } from \"goober\";\nimport { MouseEvent, useCallback, useContext, useMemo } from \"react\";\nimport { PreviewRenderer } from \"../PreviewRenderer\";\nimport { StudioAttributes } from \"../../types\";\nimport { styleFactory } from \"../styles\";\nimport { SectionModeContext } from \"../../contexts/providers/section-mode.provider\";\nimport { useDesignPreviewContext } from \"../../hooks/use-design-preview.hook\";\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\ninterface BindingValue {\n path?: Record<string, unknown>;\n [key: string]: unknown;\n}\n\nexport interface ExposedPropDef {\n uid: string;\n nodeUid: string;\n propKey: string;\n /** The binding the internal node had at expose-time (e.g. template.title).\n * SectionCompositionProvider uses this to know which field in the\n * section-scoped template to override. */\n bindingAtExposeTime?: { type: string; value: BindingValue };\n}\n\ntype SectionSpec = {\n compositionEntry?: {\n uid: string;\n };\n ui?: any;\n [key: string]: any;\n};\n\ninterface SectionCompositionProps extends StudioAttributes {\n spec: SectionSpec;\n compositionUID: string;\n className?: string;\n /** Per-placement design/preview mode from the placed node's `metadata.mode`. */\n mode?: \"design\" | \"preview\";\n [key: string]: any;\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\n/** Whether the section's authored UI contains at least one section-slot. */\nfunction sectionHasSlot(ui: any): boolean {\n if (!ui || typeof ui !== \"object\") return false;\n if (ui.type === \"section-slot\") return true;\n const slots = ui.slots || {};\n for (const slotId of Object.keys(slots)) {\n for (const child of slots[slotId] || []) {\n if (sectionHasSlot(child)) return true;\n }\n }\n return false;\n}\n\n/**\n * Effective design/preview mode for a placed section. The placement's explicit\n * `metadata.mode` (passed as the `mode` prop) wins; otherwise derive from the\n * section's content — `design` if it has a section-slot (so its drop-zones stay\n * visible) else `preview`. Mirrors `deriveSectionMode` on the Studio side.\n */\nfunction resolveSectionMode(\n mode: \"design\" | \"preview\" | undefined,\n spec: SectionSpec,\n): \"design\" | \"preview\" {\n if (mode === \"design\" || mode === \"preview\") return mode;\n return sectionHasSlot(spec?.ui) ? \"design\" : \"preview\";\n}\n\n/** Reads sectionExposedProps from the section spec's UI metadata. */\nfunction getExposedPropDefs(spec: SectionSpec): ExposedPropDef[] {\n const compositionEntry = spec.compositionEntry as\n | { ui?: { metadata?: Record<string, unknown> } }\n | undefined;\n return (\n (compositionEntry?.ui?.metadata?.sectionExposedProps as\n | ExposedPropDef[]\n | undefined) ?? []\n );\n}\n\n/**\n * Builds a map of { [ep.uid]: resolvedValue } from the props that\n * retrievePropValue already resolved for the page-level section node.\n *\n * retrievePropValue resolves the bindings the page composer set on the section\n * node's exposed props (e.g. template.heroTitle) and spreads them onto this\n * component. The page node's binding is the SOLE source of truth for an exposed\n * prop, so we emit an entry for EVERY exposed prop — including cleared/empty\n * ones (value `undefined`/`\"\"`). That lets a cleared prop render its empty value\n * downstream instead of falling back to the section's internal binding.\n */\nfunction buildOverrideValues(\n exposedPropDefs: ExposedPropDef[],\n rest: Record<string, unknown>,\n): Record<string, unknown> {\n const overrides: Record<string, unknown> = {};\n for (const ep of exposedPropDefs) {\n overrides[ep.uid] = rest[ep.uid];\n }\n return overrides;\n}\n\n/**\n * Builds a map of { [ep.uid]: cslpTag } from the `$<ep.uid>` CSLP props\n * retrievePropValue resolved for the page-level section node. Forwarded to the\n * provider so an overridden exposed prop keeps its `data-cslp` edit tag — the\n * override short-circuits retrievePropValue before it would compute one, and\n * the page-level tag (e.g. blog_post.<entry>.<locale>.hero_card.title) is the\n * correct target for the edit overlay. `domProps` strips these `$`-keys from the\n * DOM spread, so capture them here first.\n */\nfunction buildOverrideCslp(\n exposedPropDefs: ExposedPropDef[],\n rest: Record<string, unknown>,\n): Record<string, unknown> {\n const cslp: Record<string, unknown> = {};\n for (const ep of exposedPropDefs) {\n cslp[ep.uid] = rest[`$${ep.uid}`];\n }\n return cslp;\n}\n\n// ─── Icon ────────────────────────────────────────────────────────────────────\n\nfunction StudioIcon() {\n return (\n <svg\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 20 20\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2.5 5.37989C2.5 4.39075 3.36764 3.62971 4.34018 3.76578L4.96257 3.85287C8.30481 4.3205 11.6952 4.3205 15.0374 3.85287L15.6598 3.76579C16.6324 3.62971 17.5 4.39075 17.5 5.37989V12.1389C17.5 13.1281 16.6324 13.8891 15.6598 13.753L15.2334 13.6934C14.9921 13.6596 14.8236 13.4351 14.8571 13.192C14.8907 12.9489 15.1135 12.7792 15.3548 12.8129L15.7812 12.8726C16.2233 12.9345 16.6176 12.5885 16.6176 12.1389V5.37989C16.6176 4.93028 16.2233 4.58436 15.7812 4.64621L15.1588 4.73329C11.736 5.21219 8.26397 5.21219 4.84118 4.73329L4.2188 4.64621C3.77673 4.58436 3.38235 4.93028 3.38235 5.37989V12.1389C3.38235 12.5885 3.77673 12.9345 4.2188 12.8726L4.64519 12.8129C4.88653 12.7792 5.10934 12.9489 5.14286 13.192C5.17638 13.4351 5.00791 13.6596 4.76657 13.6934L4.34019 13.753C3.36764 13.8891 2.5 13.1281 2.5 12.1389V5.37989Z\"\n fill=\"#6C5CE7\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M6.02941 9.0557C6.02941 8.64661 6.35861 8.31497 6.76471 8.31497H8.52941C8.9355 8.31497 9.26471 8.64661 9.26471 9.0557V10.801C9.26471 11.2101 8.9355 11.5418 8.52941 11.5418H6.76471C6.35861 11.5418 6.02941 11.2101 6.02941 10.801V9.0557ZM6.91176 9.20384V10.6529H8.38235V9.20384H6.91176Z\"\n fill=\"#6C5CE7\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M10.1471 8.16682C10.1471 7.59409 10.6079 7.1298 11.1765 7.1298H13.5294C14.0979 7.1298 14.5588 7.59409 14.5588 8.16682V10.5047C14.5588 11.0775 14.0979 11.5418 13.5294 11.5418H11.1765C10.6079 11.5418 10.1471 11.0775 10.1471 10.5047V8.16682ZM11.1765 8.01868C11.0953 8.01868 11.0294 8.08501 11.0294 8.16682V10.5047C11.0294 10.5866 11.0953 10.6529 11.1765 10.6529H13.5294C13.6106 10.6529 13.6765 10.5866 13.6765 10.5047V8.16682C13.6765 8.08501 13.6106 8.01868 13.5294 8.01868H11.1765Z\"\n fill=\"#6C5CE7\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M10 12.4306C10.5685 12.4306 11.0294 12.8949 11.0294 13.4677V15.838C11.0294 16.4107 10.5685 16.875 10 16.875H7.05882C6.49029 16.875 6.02941 16.4107 6.02941 15.838L6.02941 13.4677C6.02941 12.8949 6.49029 12.4306 7.05882 12.4306H10ZM10.1471 13.4677C10.1471 13.3858 10.0812 13.3195 10 13.3195H7.05882C6.97761 13.3195 6.91176 13.3858 6.91176 13.4677V15.838C6.91176 15.9198 6.97761 15.9861 7.05882 15.9861H10C10.0812 15.9861 10.1471 15.9198 10.1471 15.838V13.4677Z\"\n fill=\"#6C5CE7\"\n />\n <path\n d=\"M12.7134 12.9508C12.7104 12.902 12.7639 12.8707 12.8044 12.8976L14.6152 14.0966C14.6598 14.1261 14.6455 14.1954 14.5929 14.2045L13.6175 14.3742C13.6036 14.3766 13.5911 14.3839 13.5821 14.3948L12.9517 15.1636C12.9177 15.205 12.8509 15.1832 12.8476 15.1295L12.7134 12.9508Z\"\n fill=\"#6C5CE7\"\n />\n </svg>\n );\n}\n\n// ─── Component ───────────────────────────────────────────────────────────────\n\nexport function SectionComposition({\n spec,\n compositionUID,\n studioAttributes,\n className,\n mode,\n ...rest\n}: SectionCompositionProps) {\n const styles = styleFactory(css);\n const data = useData();\n // The page-side instance uid keys this section's per-instance scoped data\n // (section_scoped_data[instanceUid] — carries selectedField/parentRepeaterUID\n // for per-iteration re-scope). It is normally read from the builder node id in\n // `studioAttributes`, but the editor strips that attribute when a node renders\n // in PREVIEW mode (e.g. a section transcluded into a section-slot whose\n // enclosing placed section has Preview Mode on — see SectionSlot). Falling back\n // to the surrounding CurrentNodeContext keeps the instance identity (and thus\n // the correct scoped entry) intact in preview, so a slot-nested section still\n // binds to its per-iteration repeater item instead of the page root.\n const { currentNodeUid } = useCurrentNode();\n const instanceUid =\n studioAttributes?.[COMPOSABLE_DATA_ATTRIBUTES.ID] ?? currentNodeUid;\n\n // A single section-composition node renders ONCE PER ITERATION when wrapped\n // by an iterating ancestor Repeater (page-side OR section-internal). Each\n // render produces its own \"Edit Composition\" button — all pointing at the\n // same compositionUID. Show the button only when every ancestor Repeater is\n // at iteration 0 (or there are no iterating ancestors). This collapses the\n // N-button UI down to one without restructuring the render tree.\n //\n // The map contains only ancestor Repeaters because the editor's Repeater\n // spreads its new entry on top of the inherited map; siblings can't reach\n // this subtree through React context. Design-mode Repeaters don't push a\n // context entry at all, so they don't trigger the gate.\n const isFirstIteration = useMemo(() => {\n const repeaterMap = (data as any)?.dataSources?.repeater;\n if (!repeaterMap || typeof repeaterMap !== \"object\") return true;\n for (const uid of Object.keys(repeaterMap)) {\n const idx = repeaterMap[uid]?.index;\n if (typeof idx === \"number\" && idx !== 0) return false;\n }\n return true;\n }, [data]);\n\n // Mode for everything inside this section. The topmost mode node owns it: if\n // this section is itself inside a repeater/condition-block, that ancestor's\n // DesignPreviewContext (design|preview) wins, overriding the section's own\n // mode. Otherwise the section owns it — explicit placement value, else derived\n // from content. `none` = no enclosing mode node.\n const enclosingMode = useDesignPreviewContext();\n // A section nested inside another section's slot must follow the enclosing\n // section's mode too — not just an enclosing repeater's (COMS-1659). A\n // slot-bearing nested section derives `design`, so its own SectionModeContext\n // Provider (below) would clobber the inherited preview and freeze its data\n // Repeaters (they iterate only when useShouldShowDesign sees section preview).\n // Only PREVIEW cascades (design is not inherited); the enclosing-repeater path\n // still takes precedence, so the working repeater-context behavior is intact.\n const enclosingSectionMode = useContext(SectionModeContext);\n // Ancestor section chain on this render path (COMS-1659 cycle guard).\n const defaultChain = useContext(DefaultChainCtx);\n const sectionMode =\n enclosingMode === \"design\" || enclosingMode === \"preview\"\n ? enclosingMode\n : enclosingSectionMode === \"preview\"\n ? \"preview\"\n : resolveSectionMode(mode, spec);\n\n const handleEditClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n event.stopPropagation();\n composableStudioEventManager?.send(\n POST_MESSAGE_EVENTS.OPEN_IN_COMPOSABLE_STUDIO_EVENT_MESSAGE,\n { compositionEntryUid: compositionUID, compositionQuery: null },\n );\n },\n [compositionUID],\n );\n\n // Definitions of which props are exposed (uid, bindingAtExposeTime, etc.)\n const exposedPropDefs = useMemo(() => getExposedPropDefs(spec), [spec]);\n\n // Map of { [ep.uid]: resolvedPageValue } — values already resolved by\n // retrievePropValue against the page's data context and spread into rest.\n const overrideValues = useMemo(\n () => buildOverrideValues(exposedPropDefs, rest),\n [\n exposedPropDefs,\n JSON.stringify(exposedPropDefs.map((ep) => rest[ep.uid])),\n ],\n );\n\n // Page composer's LIVE binding type per exposed prop (emitted by\n // retrievePropValue for section-composition nodes). Lets the provider tell an\n // untouched repeater seed from a real page-level override.\n const exposedBindingTypes = (rest.section_exposed_binding_types ??\n {}) as Record<string, string>;\n // Which exposed props are still auto-seeded (untouched) — those defer to the\n // section's internal binding so they follow schema switches / repeater context.\n const exposedAutoSeeded = (rest.section_exposed_auto_seeded ?? {}) as Record<\n string,\n boolean\n >;\n // Map of { [ep.uid]: cslpTag } — the page-resolved `$<ep.uid>` tags, forwarded\n // so overridden exposed props keep their live-preview edit tag.\n const overrideCslp = useMemo(\n () => buildOverrideCslp(exposedPropDefs, rest),\n [\n exposedPropDefs,\n JSON.stringify(exposedPropDefs.map((ep) => rest[`$${ep.uid}`])),\n ],\n );\n\n // Exclude exposed prop keys and their $-prefixed CSLP counterparts from DOM\n // spread. retrievePropValue adds both `uid` (resolved value) and `$uid` (CSLP\n // live-preview tag) to the resolved props — both are invalid as div attributes.\n const domProps = useMemo(() => {\n const excluded = new Set([\n ...exposedPropDefs.flatMap((ep) => [ep.uid, `$${ep.uid}`]),\n \"section_exposed_binding_types\",\n \"section_exposed_auto_seeded\",\n ]);\n return Object.fromEntries(\n Object.entries(rest).filter(([k]) => !excluded.has(k)),\n );\n }, [exposedPropDefs, rest]);\n\n // Keep the section instance's id on its host even in PREVIEW mode, where the\n // editor (Element) strips builder attributes from slot children. The id alone\n // carries no selection affordance — interaction is driven by the\n // ELEMENT_TO_NODE map the builder ref populates, which preview omits — but it\n // preserves the per-instance DOM identity the \"Edit Composition\" button is\n // scoped under and keeps a stable hook for each placed section.\n const instanceIdAttr = instanceUid\n ? { [COMPOSABLE_DATA_ATTRIBUTES.ID]: instanceUid }\n : {};\n\n // Cycle guard (COMS-1659): if this section's compositionUID is already an\n // ancestor on the path, a slot-default chain loops back on itself\n // (A→B→…→A). Render nothing to cut the back-edge — terminates at the first\n // repeat, no fetch, safe even for cycles saved directly via the CMA.\n if (compositionUID && defaultChain.has(compositionUID)) return null;\n\n return (\n <DefaultChainCtx.Provider\n value={new Set([...defaultChain, compositionUID])}\n >\n <div\n {...domProps}\n {...instanceIdAttr}\n {...studioAttributes}\n className={[styles.embeddedSectionHost, className]\n .filter(Boolean)\n .join(\" \")}\n >\n {isFirstIteration && (\n <Button\n className={`cs-embedded-section-edit-btn ${styles.embeddedSectionButton}`}\n onClick={handleEditClick}\n type=\"button\"\n data-studio-ui={true}\n >\n <StudioIcon />\n {EDIT_SECTIONS_LABEL}\n </Button>\n )}\n\n {/*\n * exposedPropDefs + overrideValues are forwarded to the provider so it\n * can inject the page-composer's override values into the section-scoped\n * template before the internal UI tree renders.\n */}\n <SectionModeContext.Provider value={sectionMode}>\n <SectionCompositionProvider\n uid={compositionUID}\n instanceUid={instanceUid}\n exposedPropDefs={exposedPropDefs}\n overrideValues={overrideValues}\n exposedBindingTypes={exposedBindingTypes}\n exposedAutoSeeded={exposedAutoSeeded}\n overrideCslp={overrideCslp}\n >\n <SectionDataMerger spec={spec}>\n <PreviewRenderer spec={spec as any} />\n </SectionDataMerger>\n </SectionCompositionProvider>\n </SectionModeContext.Provider>\n </div>\n </DefaultChainCtx.Provider>\n );\n}\n\n/**\n * Merges the section's own `spec.data.static_value` into the active data\n * context so static-value-bound props authored inside the section (e.g. a\n * SectionSlot's `label`, or any Text/Number/etc. inside the section's body)\n * resolve against the section's persisted values when the section is\n * consumed in a page. Without this, child Elements call useData() and get\n * the page's data, which doesn't contain the section's static_value keys.\n */\nfunction SectionDataMerger({\n spec,\n children,\n}: {\n spec: SectionSpec;\n children: React.ReactNode;\n}) {\n const outerData = useData();\n const merged = useMemo(() => {\n const sectionStatic = (spec as any)?.data?.static_value;\n if (!sectionStatic || typeof sectionStatic !== \"object\") return outerData;\n return {\n ...(outerData as any),\n static_value: {\n ...((outerData as any)?.static_value || {}),\n ...sectionStatic,\n },\n };\n }, [outerData, spec]);\n return <DataCtxProvider value={merged as any}>{children}</DataCtxProvider>;\n}\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;;AAyDA;AAEA;AACA,SAAS,cAAc,CAAC,EAAO,EAAA;AAC7B,IAAA,IAAI,CAAC,EAAE,IAAI,OAAO,EAAE,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;AAC/C,IAAA,IAAI,EAAE,CAAC,IAAI,KAAK,cAAc;AAAE,QAAA,OAAO,IAAI;AAC3C,IAAA,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,IAAI,EAAE;IAC5B,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACvC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,SAAS,iBAAiB,CAAC,EACzB,IAAI,EACJ,QAAQ,GAIT,EAAA;AACC,IAAA,MAAM,SAAS,GAAG,OAAO,EAAE;AAC3B,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAK;AAC1B,QAAA,MAAM,aAAa,GAAI,IAAY,EAAE,IAAI,EAAE,YAAY;AACvD,QAAA,IAAI,CAAC,aAAa,IAAI,OAAO,aAAa,KAAK,QAAQ;AAAE,YAAA,OAAO,SAAS;QACzE,OAAO;AACL,YAAA,GAAI,SAAiB;AACrB,YAAA,YAAY,EAAE;AACZ,gBAAA,IAAK,SAAiB,EAAE,YAAY,IAAI,EAAE,CAAC;AAC3C,gBAAA,GAAG,aAAa;AACjB,aAAA;SACF;AACH,IAAA,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACrB,OAAOA,GAAA,CAAC,eAAe,EAAA,EAAC,KAAK,EAAE,MAAa,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAmB;AAC5E;;;;"}
|
|
@@ -11,6 +11,29 @@ import { PreviewModeContext } from '../../contexts/providers/preview-mode.provid
|
|
|
11
11
|
import { SectionModeContext } from '../../contexts/providers/section-mode.provider.js';
|
|
12
12
|
import MemoizedElement from '../Element.js';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* In-memory `section-composition` node for a slot's authored default. Rendered
|
|
16
|
+
* through the normal element path so the default's spec resolves by
|
|
17
|
+
* `compositionUID` and nested defaults recurse. Stable uid → no remount. Never
|
|
18
|
+
* persisted into the placement.
|
|
19
|
+
*/
|
|
20
|
+
function makeDefaultSectionNode(instanceUid, slotUid, defaultUid) {
|
|
21
|
+
// Key by the enclosing placement instance too (COMS-1659): the same section
|
|
22
|
+
// placed twice shares one internal `slotUid`, so a slot-uid-only key would
|
|
23
|
+
// collide across placements and make their empty-slot defaults share one
|
|
24
|
+
// uid-keyed data context. The instance uid makes each placement's default
|
|
25
|
+
// distinct.
|
|
26
|
+
const prefix = instanceUid ? `${instanceUid}-` : "";
|
|
27
|
+
return {
|
|
28
|
+
type: "section-composition",
|
|
29
|
+
uid: `${prefix}${slotUid}-default-${defaultUid}`,
|
|
30
|
+
metadata: { compositionUID: defaultUid, mode: "preview" },
|
|
31
|
+
attrs: {},
|
|
32
|
+
props: {},
|
|
33
|
+
slots: {},
|
|
34
|
+
styles: {},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
14
37
|
/**
|
|
15
38
|
* Editor variant of section-slot. Two modes:
|
|
16
39
|
*
|
|
@@ -30,7 +53,7 @@ import MemoizedElement from '../Element.js';
|
|
|
30
53
|
* page-side section-composition parent), so hover highlights only the
|
|
31
54
|
* slot zone — not the whole section.
|
|
32
55
|
*/
|
|
33
|
-
function SectionSlot({ studioAttributes, label, _uid, }) {
|
|
56
|
+
function SectionSlot({ studioAttributes, label, _uid, defaultSection, }) {
|
|
34
57
|
// ALL hooks unconditionally at the top — React doesn't allow conditional
|
|
35
58
|
// hook calls and the component returns early for authoring/empty modes.
|
|
36
59
|
const sectionCtx = useContext(SectionInstanceSlotsCtx);
|
|
@@ -133,9 +156,21 @@ function SectionSlot({ studioAttributes, label, _uid, }) {
|
|
|
133
156
|
[COMPOSABLE_DATA_ATTRIBUTES.SLOT_UID]: slotUid,
|
|
134
157
|
};
|
|
135
158
|
if (filled.length === 0) {
|
|
136
|
-
// Preview mode: an empty slot
|
|
137
|
-
|
|
138
|
-
|
|
159
|
+
// Preview mode: an empty slot falls back to its authored default section
|
|
160
|
+
// (COMS-1659), rendered like production — non-interactive, no drop chrome.
|
|
161
|
+
// With no default it collapses to nothing. Design mode always shows the
|
|
162
|
+
// dropzone below (default never shown while authoring the placement).
|
|
163
|
+
if (isSectionPreview) {
|
|
164
|
+
if (!defaultSection)
|
|
165
|
+
return null;
|
|
166
|
+
const synth = makeDefaultSectionNode(sectionCtx.sectionInstanceUid, slotUid, defaultSection);
|
|
167
|
+
NODE_TO_PARENT.set(synth, sectionCtx.sectionNode);
|
|
168
|
+
NODE_TO_PATH_NODE.set(synth, [slotUid, 0]);
|
|
169
|
+
return (jsx(DataCtxProvider, { value: slotChildData, children: jsx(PreviewModeContext.Provider, { value: true, children: jsx("div", { style: { display: "contents" }, children: jsx(SectionInstanceSlotsCtx.Provider, { value: undefined, children: jsx(CurrentNodeContext.Provider, { value: {
|
|
170
|
+
currentNodeUid: synth.uid,
|
|
171
|
+
currentNodePath: [...parentNodePath, [slotUid, 0]],
|
|
172
|
+
}, children: jsx(MemoizedElement, { node: synth, renderError: () => null }) }) }) }) }) }));
|
|
173
|
+
}
|
|
139
174
|
return (jsx("div", { ref: slotDomRef, ...dropZoneAttrs, ...studioAttributes, className: classNames(styles.slotStyle), children: jsxs("span", { className: styles.slotDropText, children: [jsx(AddIcon, {}), " ", text] }) }));
|
|
140
175
|
}
|
|
141
176
|
// Transclude filled children. Anchor each child's slate path under the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SectionSlot.js","sources":["../../../src/components/elements/SectionSlot.tsx"],"sourcesContent":["import {\n COMPOSABLE_DATA_ATTRIBUTES,\n ELEMENT_TO_NODE,\n NODE_TO_PARENT,\n NODE_TO_PATH_NODE,\n} from \"@contentstack/studio-client\";\nimport { Node, Path } from \"@contentstack/studio-internal\";\nimport {\n CurrentNodeContext,\n DataCtxProvider,\n SectionInstanceSlotsCtx,\n} from \"@contentstack/studio-react-components/contexts\";\nimport {\n useCurrentNode,\n useData,\n} from \"@contentstack/studio-react-components/hooks\";\nimport { css } from \"goober\";\nimport classNames from \"classnames\";\nimport { useCallback, useContext, useMemo } from \"react\";\nimport { styleFactory } from \"../styles\";\nimport { StudioAttributes } from \"../../types\";\nimport { SelectedNodeProvider } from \"../../contexts/providers/selected-node.provider\";\nimport { PreviewModeContext } from \"../../contexts/providers/preview-mode.provider\";\nimport { SectionModeContext } from \"../../contexts/providers/section-mode.provider\";\nimport Element from \"../Element\";\n\ninterface SectionSlotEditorProps extends StudioAttributes {\n label?: string;\n _uid?: string;\n}\n\n/**\n * Editor variant of section-slot. Two modes:\n *\n * 1. **Authoring mode** (no SectionInstanceSlotsCtx in scope) — the section\n * composition is being authored. Render a labelled drop-zone-style\n * placeholder; not droppable into (section slots only accept drops when\n * the section is consumed in a page composition).\n *\n * 2. **Consumption mode** (SectionInstanceSlotsCtx present) — the section\n * is being rendered inside a page composition. Look up the page-side\n * slots map by this slot's stable uid (== this node's uid). If filled,\n * transclude the children via <Element> with their paths anchored to\n * the page-side section-composition node, and lift them out of preview\n * mode so they're individually selectable / hover-targetable / draggable\n * like any other page-tree node. If empty, render a labelled drop\n * target that itself acts as a builder node (attributes mapped to the\n * page-side section-composition parent), so hover highlights only the\n * slot zone — not the whole section.\n */\nexport function SectionSlot({\n studioAttributes,\n label,\n _uid,\n}: SectionSlotEditorProps) {\n // ALL hooks unconditionally at the top — React doesn't allow conditional\n // hook calls and the component returns early for authoring/empty modes.\n const sectionCtx = useContext(SectionInstanceSlotsCtx);\n // When the enclosing placed section is in preview mode, the slot renders like\n // production: an empty slot collapses to nothing and a filled slot drops its\n // drop-chrome / selection affordances.\n const isSectionPreview = useContext(SectionModeContext) === \"preview\";\n const { currentNodePath: parentNodePath = [] } = useCurrentNode();\n // Current section-local data (template scoped to section, in-section\n // repeater item if surrounding, etc.). Slot children inherit this as\n // their *default* context — the user's authored bindings on slot\n // children resolve against this by default.\n const sectionLocalData = useData();\n const slotDomRef = useCallback(\n (el: HTMLElement | null) => {\n if (el && sectionCtx?.sectionNode) {\n ELEMENT_TO_NODE.set(el, sectionCtx.sectionNode);\n }\n },\n [sectionCtx?.sectionNode],\n );\n // Slot child's data context namespace:\n //\n // dataSources.template = section-local scoped template; if the\n // slot sits inside an in-section\n // Repeater that's currently iterating,\n // this is the active iteration item.\n // Matches what the Data Picker writes\n // when authoring against fields from\n // the slot's surrounding section scope.\n // dataSources.repeater[uid] = in-section Repeater map (full\n // per-uid context). Inherited from\n // sectionLocal via {...sectionDS}.\n // dataSources.static_value = section's persisted static values.\n // dataSources.page = OUTERMOST page-level namespace\n // ({ template, contentstack,\n // contentstack_queries, ... }).\n // Always points to the real page even\n // across recursive slot nesting — see\n // `truePageNamespace` below.\n //\n // Until Phase 8 lands, picker emits `dataSources.<src>.X` paths only.\n // retrieve-data.ts retries unresolved `dataSources.<src>.X` lookups under\n // `dataSources.page.<src>.X` so page-level bindings authored on slot\n // children still resolve.\n const slotChildData = useMemo(() => {\n const sectionLocal: any = sectionLocalData || {};\n const pageOuter: any = sectionCtx?.pageOuterData || {};\n const pageDS = pageOuter?.dataSources || {};\n const sectionDS = sectionLocal?.dataSources || {};\n\n const repeaterMap = (sectionDS.repeater || {}) as Record<string, any>;\n const repeaterUids = Object.keys(repeaterMap);\n const activeRepeaterUid =\n repeaterUids.length > 0\n ? repeaterUids[repeaterUids.length - 1]\n : undefined;\n const activeItem = activeRepeaterUid\n ? repeaterMap[activeRepeaterUid]?.context\n : undefined;\n const sectionLocalTemplate = activeItem ?? sectionDS.template;\n\n // Slot child's default namespace = section-local context AS IS (template,\n // repeater, static_value, …). Page-level sources are nested under `page.*`\n // as the explicit escape. This matches what the Data Picker writes when\n // authoring a slot child (picker shows the slot child's surrounding\n // scope, so its `template.X` / `repeater[uid].context.X` paths resolve\n // natively without rewriting).\n //\n // For nested cases (Section B in Section A's slot), `page` must always\n // point to the OUTERMOST page context — not to Section A's slot-local\n // view. Otherwise each nesting level shadows `page` with the surrounding\n // section's local, and `dataSources.page.template.title` would resolve\n // to a modular_block item instead of the page entry. So: if the outer\n // dataSources already has its own `page` key (because the section we're\n // inside is itself in another slot), inherit THAT — it's the real page.\n const outerPage = (pageDS as any)?.page;\n const truePageNamespace = outerPage ?? pageDS;\n return {\n ...sectionLocal,\n dataSources: {\n ...sectionDS,\n template: sectionLocalTemplate,\n page: truePageNamespace,\n },\n };\n }, [sectionLocalData, sectionCtx?.pageOuterData]);\n\n // ALL hooks above are unconditional. From here, branch based on mode.\n const styles = styleFactory(css);\n const text = label && label.trim().length > 0 ? label : \"Drop Here\";\n const slotUid =\n _uid ||\n (studioAttributes as any)?.[COMPOSABLE_DATA_ATTRIBUTES.ID] ||\n \"section-slot\";\n\n // Authoring mode: section is the top-level composition being edited.\n if (!sectionCtx) {\n return (\n <div\n {...{\n [COMPOSABLE_DATA_ATTRIBUTES.SLOT]: true,\n [COMPOSABLE_DATA_ATTRIBUTES.SLOT_UID]: slotUid,\n }}\n {...studioAttributes}\n className={classNames(styles.slotStyle)}\n >\n <span className={styles.slotDropText}>\n <AddIcon /> {text}\n </span>\n </div>\n );\n }\n\n // Consumption mode.\n const filled = (sectionCtx.slotsMap[slotUid] || []) as Node[];\n const dropZoneAttrs = {\n [COMPOSABLE_DATA_ATTRIBUTES.BUILDER]: true,\n [COMPOSABLE_DATA_ATTRIBUTES.NODE]: true,\n [COMPOSABLE_DATA_ATTRIBUTES.ID]: sectionCtx.sectionInstanceUid,\n [COMPOSABLE_DATA_ATTRIBUTES.SLOT]: true,\n [COMPOSABLE_DATA_ATTRIBUTES.SLOT_UID]: slotUid,\n };\n\n if (filled.length === 0) {\n // Preview mode: an empty slot renders nothing, exactly like production.\n if (isSectionPreview) return null;\n return (\n <div\n ref={slotDomRef as any}\n {...dropZoneAttrs}\n {...studioAttributes}\n className={classNames(styles.slotStyle)}\n >\n <span className={styles.slotDropText}>\n <AddIcon /> {text}\n </span>\n </div>\n );\n }\n\n // Transclude filled children. Anchor each child's slate path under the\n // page-side section-composition node + this slot's uid. In design mode, exit\n // preview so Element's internalAttributes get applied — making each child\n // selectable, hover-highlightable, and draggable like a normal node. In\n // preview mode, keep them inside preview (non-interactive) and drop the\n // drop-zone attributes so the slot reads like production.\n return (\n <DataCtxProvider value={slotChildData}>\n <PreviewModeContext.Provider value={isSectionPreview}>\n <div\n ref={slotDomRef as any}\n {...(isSectionPreview ? {} : dropZoneAttrs)}\n {...studioAttributes}\n style={{ display: \"contents\" }}\n >\n {/*\n * The filled children are PAGE-authored content the composer dropped\n * into this slot — not part of the section's authored body. Clear the\n * section-instance context for them so their own internal slots render\n * normally (e.g. an empty Repeater dropped here shows its \"Drop Here\"\n * placeholder instead of being suppressed by Slot.tsx's\n * in-section-consumption guard, which would make it disappear).\n */}\n <SectionInstanceSlotsCtx.Provider value={undefined}>\n {filled.map((child, idx) => {\n if (!child || typeof child !== \"object\") return null;\n NODE_TO_PARENT.set(child, sectionCtx.sectionNode);\n NODE_TO_PATH_NODE.set(child, [slotUid, idx]);\n const childPath: Path = [...parentNodePath, [slotUid, idx]];\n return (\n <CurrentNodeContext.Provider\n key={child.uid}\n value={{\n currentNodeUid: child.uid,\n currentNodePath: childPath,\n }}\n >\n <SelectedNodeProvider>\n <Element node={child} renderError={() => null as any} />\n </SelectedNodeProvider>\n </CurrentNodeContext.Provider>\n );\n })}\n </SectionInstanceSlotsCtx.Provider>\n </div>\n </PreviewModeContext.Provider>\n </DataCtxProvider>\n );\n}\n\nconst AddIcon: React.FC = () => {\n return (\n <svg\n width=\"22\"\n height=\"22\"\n viewBox=\"0 0 22 22\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <rect x=\"0.5\" y=\"0.5\" width=\"21\" height=\"21\" rx=\"4.5\" fill=\"white\" />\n <rect x=\"0.5\" y=\"0.5\" width=\"21\" height=\"21\" rx=\"4.5\" stroke=\"#475161\" />\n <path\n d=\"M11.2808 6.78125C11.2808 6.62592 11.1548 6.5 10.9995 6.5C10.8442 6.5 10.7183 6.62592 10.7183 6.78125V10.7184H6.78125C6.62592 10.7184 6.5 10.8443 6.5 10.9996C6.5 11.155 6.62592 11.2809 6.78125 11.2809H10.7183V15.218C10.7183 15.3733 10.8442 15.4993 10.9995 15.4993C11.1548 15.4993 11.2808 15.3733 11.2808 15.218V11.2809H15.218C15.3733 11.2809 15.4993 11.155 15.4993 10.9996C15.4993 10.8443 15.3733 10.7184 15.218 10.7184H11.2808V6.78125Z\"\n fill=\"#475161\"\n />\n </svg>\n );\n};\n"],"names":["_jsx","_jsxs","Element"],"mappings":";;;;;;;;;;;;;AA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AAC,IAAI,EAAC,EAAE,EAAC,KAAK,EAAC,MAAM,EAAC,SAAS,GAAG,EACzEA,GAAA,CAAA,MAAA,EAAA,EACE,CAAC,EAAC,qbAAqb,EACvb,IAAI,EAAC,SAAS,EAAA,CACd,CAAA,EAAA,CACE;AAEV,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"SectionSlot.js","sources":["../../../src/components/elements/SectionSlot.tsx"],"sourcesContent":["import {\n COMPOSABLE_DATA_ATTRIBUTES,\n ELEMENT_TO_NODE,\n NODE_TO_PARENT,\n NODE_TO_PATH_NODE,\n} from \"@contentstack/studio-client\";\nimport { Node, Path } from \"@contentstack/studio-internal\";\nimport {\n CurrentNodeContext,\n DataCtxProvider,\n SectionInstanceSlotsCtx,\n} from \"@contentstack/studio-react-components/contexts\";\nimport {\n useCurrentNode,\n useData,\n} from \"@contentstack/studio-react-components/hooks\";\nimport { css } from \"goober\";\nimport classNames from \"classnames\";\nimport { useCallback, useContext, useMemo } from \"react\";\nimport { styleFactory } from \"../styles\";\nimport { StudioAttributes } from \"../../types\";\nimport { SelectedNodeProvider } from \"../../contexts/providers/selected-node.provider\";\nimport { PreviewModeContext } from \"../../contexts/providers/preview-mode.provider\";\nimport { SectionModeContext } from \"../../contexts/providers/section-mode.provider\";\nimport Element from \"../Element\";\n\ninterface SectionSlotEditorProps extends StudioAttributes {\n label?: string;\n _uid?: string;\n /** Authored Slot default section uid (COMS-1659). Rendered when the slot is\n * empty in preview mode; design mode keeps the dropzone. */\n defaultSection?: string;\n}\n\n/**\n * In-memory `section-composition` node for a slot's authored default. Rendered\n * through the normal element path so the default's spec resolves by\n * `compositionUID` and nested defaults recurse. Stable uid → no remount. Never\n * persisted into the placement.\n */\nfunction makeDefaultSectionNode(\n instanceUid: string | undefined,\n slotUid: string,\n defaultUid: string,\n): Node {\n // Key by the enclosing placement instance too (COMS-1659): the same section\n // placed twice shares one internal `slotUid`, so a slot-uid-only key would\n // collide across placements and make their empty-slot defaults share one\n // uid-keyed data context. The instance uid makes each placement's default\n // distinct.\n const prefix = instanceUid ? `${instanceUid}-` : \"\";\n return {\n type: \"section-composition\",\n uid: `${prefix}${slotUid}-default-${defaultUid}`,\n metadata: { compositionUID: defaultUid, mode: \"preview\" },\n attrs: {},\n props: {},\n slots: {},\n styles: {},\n } as Node;\n}\n\n/**\n * Editor variant of section-slot. Two modes:\n *\n * 1. **Authoring mode** (no SectionInstanceSlotsCtx in scope) — the section\n * composition is being authored. Render a labelled drop-zone-style\n * placeholder; not droppable into (section slots only accept drops when\n * the section is consumed in a page composition).\n *\n * 2. **Consumption mode** (SectionInstanceSlotsCtx present) — the section\n * is being rendered inside a page composition. Look up the page-side\n * slots map by this slot's stable uid (== this node's uid). If filled,\n * transclude the children via <Element> with their paths anchored to\n * the page-side section-composition node, and lift them out of preview\n * mode so they're individually selectable / hover-targetable / draggable\n * like any other page-tree node. If empty, render a labelled drop\n * target that itself acts as a builder node (attributes mapped to the\n * page-side section-composition parent), so hover highlights only the\n * slot zone — not the whole section.\n */\nexport function SectionSlot({\n studioAttributes,\n label,\n _uid,\n defaultSection,\n}: SectionSlotEditorProps) {\n // ALL hooks unconditionally at the top — React doesn't allow conditional\n // hook calls and the component returns early for authoring/empty modes.\n const sectionCtx = useContext(SectionInstanceSlotsCtx);\n // When the enclosing placed section is in preview mode, the slot renders like\n // production: an empty slot collapses to nothing and a filled slot drops its\n // drop-chrome / selection affordances.\n const isSectionPreview = useContext(SectionModeContext) === \"preview\";\n const { currentNodePath: parentNodePath = [] } = useCurrentNode();\n // Current section-local data (template scoped to section, in-section\n // repeater item if surrounding, etc.). Slot children inherit this as\n // their *default* context — the user's authored bindings on slot\n // children resolve against this by default.\n const sectionLocalData = useData();\n const slotDomRef = useCallback(\n (el: HTMLElement | null) => {\n if (el && sectionCtx?.sectionNode) {\n ELEMENT_TO_NODE.set(el, sectionCtx.sectionNode);\n }\n },\n [sectionCtx?.sectionNode],\n );\n // Slot child's data context namespace:\n //\n // dataSources.template = section-local scoped template; if the\n // slot sits inside an in-section\n // Repeater that's currently iterating,\n // this is the active iteration item.\n // Matches what the Data Picker writes\n // when authoring against fields from\n // the slot's surrounding section scope.\n // dataSources.repeater[uid] = in-section Repeater map (full\n // per-uid context). Inherited from\n // sectionLocal via {...sectionDS}.\n // dataSources.static_value = section's persisted static values.\n // dataSources.page = OUTERMOST page-level namespace\n // ({ template, contentstack,\n // contentstack_queries, ... }).\n // Always points to the real page even\n // across recursive slot nesting — see\n // `truePageNamespace` below.\n //\n // Until Phase 8 lands, picker emits `dataSources.<src>.X` paths only.\n // retrieve-data.ts retries unresolved `dataSources.<src>.X` lookups under\n // `dataSources.page.<src>.X` so page-level bindings authored on slot\n // children still resolve.\n const slotChildData = useMemo(() => {\n const sectionLocal: any = sectionLocalData || {};\n const pageOuter: any = sectionCtx?.pageOuterData || {};\n const pageDS = pageOuter?.dataSources || {};\n const sectionDS = sectionLocal?.dataSources || {};\n\n const repeaterMap = (sectionDS.repeater || {}) as Record<string, any>;\n const repeaterUids = Object.keys(repeaterMap);\n const activeRepeaterUid =\n repeaterUids.length > 0\n ? repeaterUids[repeaterUids.length - 1]\n : undefined;\n const activeItem = activeRepeaterUid\n ? repeaterMap[activeRepeaterUid]?.context\n : undefined;\n const sectionLocalTemplate = activeItem ?? sectionDS.template;\n\n // Slot child's default namespace = section-local context AS IS (template,\n // repeater, static_value, …). Page-level sources are nested under `page.*`\n // as the explicit escape. This matches what the Data Picker writes when\n // authoring a slot child (picker shows the slot child's surrounding\n // scope, so its `template.X` / `repeater[uid].context.X` paths resolve\n // natively without rewriting).\n //\n // For nested cases (Section B in Section A's slot), `page` must always\n // point to the OUTERMOST page context — not to Section A's slot-local\n // view. Otherwise each nesting level shadows `page` with the surrounding\n // section's local, and `dataSources.page.template.title` would resolve\n // to a modular_block item instead of the page entry. So: if the outer\n // dataSources already has its own `page` key (because the section we're\n // inside is itself in another slot), inherit THAT — it's the real page.\n const outerPage = (pageDS as any)?.page;\n const truePageNamespace = outerPage ?? pageDS;\n return {\n ...sectionLocal,\n dataSources: {\n ...sectionDS,\n template: sectionLocalTemplate,\n page: truePageNamespace,\n },\n };\n }, [sectionLocalData, sectionCtx?.pageOuterData]);\n\n // ALL hooks above are unconditional. From here, branch based on mode.\n const styles = styleFactory(css);\n const text = label && label.trim().length > 0 ? label : \"Drop Here\";\n const slotUid =\n _uid ||\n (studioAttributes as any)?.[COMPOSABLE_DATA_ATTRIBUTES.ID] ||\n \"section-slot\";\n\n // Authoring mode: section is the top-level composition being edited.\n if (!sectionCtx) {\n return (\n <div\n {...{\n [COMPOSABLE_DATA_ATTRIBUTES.SLOT]: true,\n [COMPOSABLE_DATA_ATTRIBUTES.SLOT_UID]: slotUid,\n }}\n {...studioAttributes}\n className={classNames(styles.slotStyle)}\n >\n <span className={styles.slotDropText}>\n <AddIcon /> {text}\n </span>\n </div>\n );\n }\n\n // Consumption mode.\n const filled = (sectionCtx.slotsMap[slotUid] || []) as Node[];\n const dropZoneAttrs = {\n [COMPOSABLE_DATA_ATTRIBUTES.BUILDER]: true,\n [COMPOSABLE_DATA_ATTRIBUTES.NODE]: true,\n [COMPOSABLE_DATA_ATTRIBUTES.ID]: sectionCtx.sectionInstanceUid,\n [COMPOSABLE_DATA_ATTRIBUTES.SLOT]: true,\n [COMPOSABLE_DATA_ATTRIBUTES.SLOT_UID]: slotUid,\n };\n\n if (filled.length === 0) {\n // Preview mode: an empty slot falls back to its authored default section\n // (COMS-1659), rendered like production — non-interactive, no drop chrome.\n // With no default it collapses to nothing. Design mode always shows the\n // dropzone below (default never shown while authoring the placement).\n if (isSectionPreview) {\n if (!defaultSection) return null;\n const synth = makeDefaultSectionNode(\n sectionCtx.sectionInstanceUid,\n slotUid,\n defaultSection,\n );\n NODE_TO_PARENT.set(synth, sectionCtx.sectionNode);\n NODE_TO_PATH_NODE.set(synth, [slotUid, 0]);\n return (\n <DataCtxProvider value={slotChildData}>\n <PreviewModeContext.Provider value={true}>\n <div style={{ display: \"contents\" }}>\n <SectionInstanceSlotsCtx.Provider value={undefined}>\n <CurrentNodeContext.Provider\n value={{\n currentNodeUid: synth.uid,\n currentNodePath: [...parentNodePath, [slotUid, 0]],\n }}\n >\n <Element node={synth} renderError={() => null as any} />\n </CurrentNodeContext.Provider>\n </SectionInstanceSlotsCtx.Provider>\n </div>\n </PreviewModeContext.Provider>\n </DataCtxProvider>\n );\n }\n return (\n <div\n ref={slotDomRef as any}\n {...dropZoneAttrs}\n {...studioAttributes}\n className={classNames(styles.slotStyle)}\n >\n <span className={styles.slotDropText}>\n <AddIcon /> {text}\n </span>\n </div>\n );\n }\n\n // Transclude filled children. Anchor each child's slate path under the\n // page-side section-composition node + this slot's uid. In design mode, exit\n // preview so Element's internalAttributes get applied — making each child\n // selectable, hover-highlightable, and draggable like a normal node. In\n // preview mode, keep them inside preview (non-interactive) and drop the\n // drop-zone attributes so the slot reads like production.\n return (\n <DataCtxProvider value={slotChildData}>\n <PreviewModeContext.Provider value={isSectionPreview}>\n <div\n ref={slotDomRef as any}\n {...(isSectionPreview ? {} : dropZoneAttrs)}\n {...studioAttributes}\n style={{ display: \"contents\" }}\n >\n {/*\n * The filled children are PAGE-authored content the composer dropped\n * into this slot — not part of the section's authored body. Clear the\n * section-instance context for them so their own internal slots render\n * normally (e.g. an empty Repeater dropped here shows its \"Drop Here\"\n * placeholder instead of being suppressed by Slot.tsx's\n * in-section-consumption guard, which would make it disappear).\n */}\n <SectionInstanceSlotsCtx.Provider value={undefined}>\n {filled.map((child, idx) => {\n if (!child || typeof child !== \"object\") return null;\n NODE_TO_PARENT.set(child, sectionCtx.sectionNode);\n NODE_TO_PATH_NODE.set(child, [slotUid, idx]);\n const childPath: Path = [...parentNodePath, [slotUid, idx]];\n return (\n <CurrentNodeContext.Provider\n key={child.uid}\n value={{\n currentNodeUid: child.uid,\n currentNodePath: childPath,\n }}\n >\n <SelectedNodeProvider>\n <Element node={child} renderError={() => null as any} />\n </SelectedNodeProvider>\n </CurrentNodeContext.Provider>\n );\n })}\n </SectionInstanceSlotsCtx.Provider>\n </div>\n </PreviewModeContext.Provider>\n </DataCtxProvider>\n );\n}\n\nconst AddIcon: React.FC = () => {\n return (\n <svg\n width=\"22\"\n height=\"22\"\n viewBox=\"0 0 22 22\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <rect x=\"0.5\" y=\"0.5\" width=\"21\" height=\"21\" rx=\"4.5\" fill=\"white\" />\n <rect x=\"0.5\" y=\"0.5\" width=\"21\" height=\"21\" rx=\"4.5\" stroke=\"#475161\" />\n <path\n d=\"M11.2808 6.78125C11.2808 6.62592 11.1548 6.5 10.9995 6.5C10.8442 6.5 10.7183 6.62592 10.7183 6.78125V10.7184H6.78125C6.62592 10.7184 6.5 10.8443 6.5 10.9996C6.5 11.155 6.62592 11.2809 6.78125 11.2809H10.7183V15.218C10.7183 15.3733 10.8442 15.4993 10.9995 15.4993C11.1548 15.4993 11.2808 15.3733 11.2808 15.218V11.2809H15.218C15.3733 11.2809 15.4993 11.155 15.4993 10.9996C15.4993 10.8443 15.3733 10.7184 15.218 10.7184H11.2808V6.78125Z\"\n fill=\"#475161\"\n />\n </svg>\n );\n};\n"],"names":["_jsx","_jsxs","Element"],"mappings":";;;;;;;;;;;;;AAkCA;;;;;AAKG;AACH,SAAS,sBAAsB,CAC7B,WAA+B,EAC/B,OAAe,EACf,UAAkB,EAAA;;;;;;AAOlB,IAAA,MAAM,MAAM,GAAG,WAAW,GAAG,CAAA,EAAG,WAAW,CAAA,CAAA,CAAG,GAAG,EAAE;IACnD,OAAO;AACL,QAAA,IAAI,EAAE,qBAAqB;AAC3B,QAAA,GAAG,EAAE,CAAA,EAAG,MAAM,GAAG,OAAO,CAAA,SAAA,EAAY,UAAU,CAAA,CAAE;QAChD,QAAQ,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;AACzD,QAAA,KAAK,EAAE,EAAE;AACT,QAAA,KAAK,EAAE,EAAE;AACT,QAAA,KAAK,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
import { DATA_SOURCES } from '@contentstack/studio-registry';
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
6
|
import '@contentstack/studio-client';
|
|
7
|
+
import '../../hooks/use-edit-context-listener.hook.js';
|
|
7
8
|
import '@contentstack/studio-messenger';
|
|
8
9
|
import '@contentstack/studio-internal';
|
|
9
10
|
import '@contentstack/studio-core';
|
|
@@ -12,6 +13,7 @@ import 'goober';
|
|
|
12
13
|
import { PreviewRenderer } from '../PreviewRenderer.js';
|
|
13
14
|
import '../../contexts/providers/section-mode.provider.js';
|
|
14
15
|
import '../../contexts/providers/renderer.provider.js';
|
|
16
|
+
import '../../contexts/providers/edit-context.provider.js';
|
|
15
17
|
import '../../contexts/providers/active-node.provider.js';
|
|
16
18
|
import 'immer';
|
|
17
19
|
import '../../contexts/providers/use-design-preview.provider.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Symbol.js","sources":["../../../src/components/elements/Symbol.tsx"],"sourcesContent":["/**\n * Symbol component will be used to render when a symbol is in edit mode.\n * @param props:\n * @returns\n */\n\nimport { StudioSpec } from \"@contentstack/studio-client\";\nimport { DataCtxProvider } from \"@contentstack/studio-react-components/contexts\";\nimport { useData } from \"@contentstack/studio-react-components/hooks\";\nimport { DATA_SOURCES } from \"@contentstack/studio-registry\";\nimport { useMemo } from \"react\";\nimport { useSymbolUIListener } from \"../../hooks\";\nimport { PreviewRenderer } from \"../PreviewRenderer\";\n\n/*\n * SymbolEditRenderer is used by the renderer when symbol is in edit mode\n */\ninterface EditSymbolRendererProps {\n ui: React.ReactElement;\n [key: string]: any;\n}\n\nexport function EditSymbolRenderer({\n ui,\n studioAttributes,\n}: EditSymbolRendererProps) {\n return (\n <div {...studioAttributes} style={{ display: \"contents\" }}>\n {ui}\n </div>\n );\n}\n\n/*\n * SymbolRenderer is used by the renderer when symbol is in view mode\n */\ninterface ViewOnlySymbolRendererProps {\n ui: null;\n spec: Omit<StudioSpec, \"compositionEntry\">;\n symbolUID: string;\n studioAttributes: Record<string, any>;\n [key: string]: any;\n}\n\nexport function ViewOnlySymbolRenderer({\n symbolUID,\n spec,\n studioAttributes,\n}: ViewOnlySymbolRendererProps) {\n const activeSpec = useSymbolUIListener(spec, symbolUID);\n const data = useData();\n // This was required as two nested symbols were added because of this this component itself was rendered for type symbol and again it was rendering it for same json\n const activeSpecWithoutSymbolWrapper = useMemo(() => {\n const ui = activeSpec.ui;\n const uiWithFragment = {\n ...ui,\n type: \"fragment\",\n slots: ui.slots,\n };\n return {\n ...activeSpec,\n data,\n ui: uiWithFragment,\n };\n }, [activeSpec, data]);\n return (\n <div {...studioAttributes} style={{ display: \"contents\" }}>\n <PreviewRenderer spec={activeSpecWithoutSymbolWrapper} />\n </div>\n );\n}\n\ntype SymbolProps = ViewOnlySymbolRendererProps | EditSymbolRendererProps;\n\nfunction WithSymbolPropsData(props: SymbolProps) {\n const data = useData();\n // Can't memoize it because data doesn't change when symbol changes\n const dataWithSymbol = {\n ...data,\n [DATA_SOURCES.SYMBOL_PROPS]: {\n ...(data[DATA_SOURCES.SYMBOL_PROPS] || {}),\n ...(props.symbol_props || {}),\n },\n };\n return (\n <DataCtxProvider value={dataWithSymbol}>{props.children}</DataCtxProvider>\n );\n}\nexport function Symbol(props: SymbolProps) {\n const isEditing = props.symbol_internal_props?.isEditing;\n return (\n <WithSymbolPropsData {...props}>\n {!isEditing ? (\n <ViewOnlySymbolRenderer {...(props as ViewOnlySymbolRendererProps)} />\n ) : (\n <EditSymbolRenderer {...(props as EditSymbolRendererProps)} />\n )}\n </WithSymbolPropsData>\n );\n}\n"],"names":["_jsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Symbol.js","sources":["../../../src/components/elements/Symbol.tsx"],"sourcesContent":["/**\n * Symbol component will be used to render when a symbol is in edit mode.\n * @param props:\n * @returns\n */\n\nimport { StudioSpec } from \"@contentstack/studio-client\";\nimport { DataCtxProvider } from \"@contentstack/studio-react-components/contexts\";\nimport { useData } from \"@contentstack/studio-react-components/hooks\";\nimport { DATA_SOURCES } from \"@contentstack/studio-registry\";\nimport { useMemo } from \"react\";\nimport { useSymbolUIListener } from \"../../hooks\";\nimport { PreviewRenderer } from \"../PreviewRenderer\";\n\n/*\n * SymbolEditRenderer is used by the renderer when symbol is in edit mode\n */\ninterface EditSymbolRendererProps {\n ui: React.ReactElement;\n [key: string]: any;\n}\n\nexport function EditSymbolRenderer({\n ui,\n studioAttributes,\n}: EditSymbolRendererProps) {\n return (\n <div {...studioAttributes} style={{ display: \"contents\" }}>\n {ui}\n </div>\n );\n}\n\n/*\n * SymbolRenderer is used by the renderer when symbol is in view mode\n */\ninterface ViewOnlySymbolRendererProps {\n ui: null;\n spec: Omit<StudioSpec, \"compositionEntry\">;\n symbolUID: string;\n studioAttributes: Record<string, any>;\n [key: string]: any;\n}\n\nexport function ViewOnlySymbolRenderer({\n symbolUID,\n spec,\n studioAttributes,\n}: ViewOnlySymbolRendererProps) {\n const activeSpec = useSymbolUIListener(spec, symbolUID);\n const data = useData();\n // This was required as two nested symbols were added because of this this component itself was rendered for type symbol and again it was rendering it for same json\n const activeSpecWithoutSymbolWrapper = useMemo(() => {\n const ui = activeSpec.ui;\n const uiWithFragment = {\n ...ui,\n type: \"fragment\",\n slots: ui.slots,\n };\n return {\n ...activeSpec,\n data,\n ui: uiWithFragment,\n };\n }, [activeSpec, data]);\n return (\n <div {...studioAttributes} style={{ display: \"contents\" }}>\n <PreviewRenderer spec={activeSpecWithoutSymbolWrapper} />\n </div>\n );\n}\n\ntype SymbolProps = ViewOnlySymbolRendererProps | EditSymbolRendererProps;\n\nfunction WithSymbolPropsData(props: SymbolProps) {\n const data = useData();\n // Can't memoize it because data doesn't change when symbol changes\n const dataWithSymbol = {\n ...data,\n [DATA_SOURCES.SYMBOL_PROPS]: {\n ...(data[DATA_SOURCES.SYMBOL_PROPS] || {}),\n ...(props.symbol_props || {}),\n },\n };\n return (\n <DataCtxProvider value={dataWithSymbol}>{props.children}</DataCtxProvider>\n );\n}\nexport function Symbol(props: SymbolProps) {\n const isEditing = props.symbol_internal_props?.isEditing;\n return (\n <WithSymbolPropsData {...props}>\n {!isEditing ? (\n <ViewOnlySymbolRenderer {...(props as ViewOnlySymbolRendererProps)} />\n ) : (\n <EditSymbolRenderer {...(props as EditSymbolRendererProps)} />\n )}\n </WithSymbolPropsData>\n );\n}\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;SAsBgB,kBAAkB,CAAC,EACjC,EAAE,EACF,gBAAgB,GACQ,EAAA;AACxB,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAA,GAAS,gBAAgB,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAA,QAAA,EACtD,EAAE,EAAA,CACC;AAEV;AAaM,SAAU,sBAAsB,CAAC,EACrC,SAAS,EACT,IAAI,EACJ,gBAAgB,GACY,EAAA;IAC5B,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,EAAE,SAAS,CAAC;AACvD,IAAA,MAAM,IAAI,GAAG,OAAO,EAAE;;AAEtB,IAAA,MAAM,8BAA8B,GAAG,OAAO,CAAC,MAAK;AAClD,QAAA,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE;AACxB,QAAA,MAAM,cAAc,GAAG;AACrB,YAAA,GAAG,EAAE;AACL,YAAA,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,EAAE,CAAC,KAAK;SAChB;QACD,OAAO;AACL,YAAA,GAAG,UAAU;YACb,IAAI;AACJ,YAAA,EAAE,EAAE,cAAc;SACnB;AACH,IAAA,CAAC,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACtB,QACEA,gBAAS,gBAAgB,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAA,QAAA,EACvDA,GAAA,CAAC,eAAe,EAAA,EAAC,IAAI,EAAE,8BAA8B,EAAA,CAAI,EAAA,CACrD;AAEV;AAIA,SAAS,mBAAmB,CAAC,KAAkB,EAAA;AAC7C,IAAA,MAAM,IAAI,GAAG,OAAO,EAAE;;AAEtB,IAAA,MAAM,cAAc,GAAG;AACrB,QAAA,GAAG,IAAI;AACP,QAAA,CAAC,YAAY,CAAC,YAAY,GAAG;YAC3B,IAAI,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;AAC1C,YAAA,IAAI,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC;AAC9B,SAAA;KACF;AACD,IAAA,QACEA,GAAA,CAAC,eAAe,EAAA,EAAC,KAAK,EAAE,cAAc,EAAA,QAAA,EAAG,KAAK,CAAC,QAAQ,EAAA,CAAmB;AAE9E;AACM,SAAU,MAAM,CAAC,KAAkB,EAAA;AACvC,IAAA,MAAM,SAAS,GAAG,KAAK,CAAC,qBAAqB,EAAE,SAAS;AACxD,IAAA,QACEA,GAAA,CAAC,mBAAmB,EAAA,EAAA,GAAK,KAAK,EAAA,QAAA,EAC3B,CAAC,SAAS,IACTA,IAAC,sBAAsB,EAAA,EAAA,GAAM,KAAqC,EAAA,CAAI,KAEtEA,GAAA,CAAC,kBAAkB,EAAA,EAAA,GAAM,KAAiC,EAAA,CAAI,CAC/D,EAAA,CACmB;AAE1B;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { DataStepMode } from '@contentstack/studio-messenger';
|
|
3
|
+
export { DataStepMode } from '@contentstack/studio-messenger';
|
|
4
|
+
import { createContext } from 'react';
|
|
5
|
+
|
|
6
|
+
const editContext = createContext({
|
|
7
|
+
dataStepMode: DataStepMode.SchemaOrPin,
|
|
8
|
+
});
|
|
9
|
+
const EditContextProvider = ({ value, children }) => {
|
|
10
|
+
return jsx(editContext.Provider, { value: value, children: children });
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { EditContextProvider, editContext };
|
|
14
|
+
//# sourceMappingURL=edit-context.provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit-context.provider.js","sources":["../../../src/contexts/providers/edit-context.provider.tsx"],"sourcesContent":["import { DataStepMode } from \"@contentstack/studio-messenger\";\nimport { createContext, FC } from \"react\";\n\n// Re-exported so editor-internal consumers keep importing from the providers\n// barrel; the enum's single source of truth is @contentstack/studio-messenger.\nexport { DataStepMode };\n\n/**\n * Per-composition editor context that Studio computes and pushes into the\n * iframe (pulled via `GET_EDIT_CONTEXT`, updated live via `SET_EDIT_CONTEXT`).\n * Read directly by descendants such as `WelcomeState` — it must live INSIDE\n * `EditableRenderer` (which owns the stateful spec), not the outer\n * `RendererProvider` (which is fed the one-shot initial spec).\n */\nexport interface EditContextValue {\n /**\n * Defaults to `schema-or-pin` so older Studio / anything that can't answer\n * keeps the existing \"Connect a schema or pin data\" copy.\n */\n dataStepMode: DataStepMode;\n}\n\nexport const editContext = createContext<EditContextValue>({\n dataStepMode: DataStepMode.SchemaOrPin,\n});\n\nexport const EditContextProvider: FC<{\n value: EditContextValue;\n children: React.ReactNode;\n}> = ({ value, children }) => {\n return <editContext.Provider value={value}>{children}</editContext.Provider>;\n};\n"],"names":["_jsx"],"mappings":";;;;;AAsBO,MAAM,WAAW,GAAG,aAAa,CAAmB;IACzD,YAAY,EAAE,YAAY,CAAC,WAAW;AACvC,CAAA;AAEM,MAAM,mBAAmB,GAG3B,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAI;IAC3B,OAAOA,GAAA,CAAC,WAAW,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAwB;AAC9E;;;;"}
|
|
@@ -4,6 +4,7 @@ import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack
|
|
|
4
4
|
import { SymbolUICtx } from '@contentstack/studio-react-components/contexts';
|
|
5
5
|
import { produce } from 'immer';
|
|
6
6
|
import { useState, useEffect } from 'react';
|
|
7
|
+
import '../../hooks/use-edit-context-listener.hook.js';
|
|
7
8
|
import '@contentstack/studio-internal';
|
|
8
9
|
import '@contentstack/studio-core';
|
|
9
10
|
import '@contentstack/studio-react-components/basic-components';
|
|
@@ -11,6 +12,7 @@ import '@contentstack/studio-react-components/hooks';
|
|
|
11
12
|
import 'goober';
|
|
12
13
|
import '../../components/Element.js';
|
|
13
14
|
import './renderer.provider.js';
|
|
15
|
+
import './edit-context.provider.js';
|
|
14
16
|
import './active-node.provider.js';
|
|
15
17
|
import './use-design-preview.provider.js';
|
|
16
18
|
import './use-repeater.provider.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"symbol-ui.provider.js","sources":["../../../src/contexts/providers/symbol-ui.provider.tsx"],"sourcesContent":["import { applyOperation, SymbolEntry } from \"@contentstack/studio-client\";\nimport { Operation } from \"@contentstack/studio-internal\";\nimport {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} from \"@contentstack/studio-messenger\";\nimport { SymbolUICtx } from \"@contentstack/studio-react-components/contexts\";\nimport { produce } from \"immer\";\nimport { useEffect, useState } from \"react\";\nimport { registerSymbolComponent, useRenderer } from \"../../hooks\";\n\nexport interface SymbolUIProvider {\n [uid: string]: SymbolEntry;\n}\ninterface SymbolUIProviderProps {\n children: React.ReactNode;\n symbols: SymbolEntry[];\n}\nexport const SymbolUIProvider = ({\n symbols,\n children,\n}: SymbolUIProviderProps) => {\n const { componentRegistry } = useRenderer();\n const [symbolUIs, setSymbolUIs] = useState<SymbolUIProvider>(\n symbols.reduce((acc, symbol) => {\n acc[symbol.uid] = symbol;\n return acc;\n }, {} as SymbolUIProvider),\n );\n\n useEffect(() => {\n if (symbols.length > 0) {\n setSymbolUIs(\n symbols.reduce((acc, symbol) => {\n acc[symbol.uid] = symbol;\n return acc;\n }, {} as SymbolUIProvider),\n );\n }\n }, [symbols]);\n\n // UPDATE_SYMBOLS / GET_SYMBOLS are handled by use-symbol-events.hook.ts,\n // which updates `state.symbols` — that flows down here as the `symbols`\n // prop and is picked up by the useEffect above. Registering another\n // listener here just produced a duplicate-registration warning.\n\n useEffect(() => {\n const handleApplySymbolOperation = (data: {\n operations: Operation[];\n uid: string;\n }) => {\n const { uid, operations } = data;\n setSymbolUIs((symbolUIs) => {\n if (!symbolUIs[uid]) return symbolUIs;\n const newSymbolUIs = produce(symbolUIs, (draft) => {\n const symbol = draft[uid];\n if (!symbol) return;\n const newSymbol = applyOperation(symbol.ui, operations);\n symbol.ui = newSymbol;\n draft[uid] = {\n ...symbol,\n };\n });\n registerSymbolComponent([newSymbolUIs[uid]], componentRegistry);\n return newSymbolUIs;\n });\n };\n\n const applySymbolOperationListener = composableStudioEventManager?.on<{\n operations: Operation[];\n uid: string;\n }>(POST_MESSAGE_EVENTS.APPLY_SYMBOL_OPERATION, (event) => {\n handleApplySymbolOperation(event.data);\n });\n return () => {\n applySymbolOperationListener?.unregister();\n };\n }, []);\n\n useEffect(() => {\n const newSymbolListener = composableStudioEventManager?.on<{\n symbol: SymbolEntry;\n }>(POST_MESSAGE_EVENTS.ADD_NEW_SYMBOL, (event) => {\n const { symbol } = event.data;\n registerSymbolComponent([symbol], componentRegistry);\n setSymbolUIs((symbolUIs) => {\n return produce(symbolUIs, (draft) => {\n draft[symbol.uid] = symbol;\n });\n });\n });\n return () => {\n newSymbolListener?.unregister();\n };\n }, []);\n return (\n <SymbolUICtx.Provider value={symbolUIs}>{children}</SymbolUICtx.Provider>\n );\n};\n"],"names":["_jsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"symbol-ui.provider.js","sources":["../../../src/contexts/providers/symbol-ui.provider.tsx"],"sourcesContent":["import { applyOperation, SymbolEntry } from \"@contentstack/studio-client\";\nimport { Operation } from \"@contentstack/studio-internal\";\nimport {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} from \"@contentstack/studio-messenger\";\nimport { SymbolUICtx } from \"@contentstack/studio-react-components/contexts\";\nimport { produce } from \"immer\";\nimport { useEffect, useState } from \"react\";\nimport { registerSymbolComponent, useRenderer } from \"../../hooks\";\n\nexport interface SymbolUIProvider {\n [uid: string]: SymbolEntry;\n}\ninterface SymbolUIProviderProps {\n children: React.ReactNode;\n symbols: SymbolEntry[];\n}\nexport const SymbolUIProvider = ({\n symbols,\n children,\n}: SymbolUIProviderProps) => {\n const { componentRegistry } = useRenderer();\n const [symbolUIs, setSymbolUIs] = useState<SymbolUIProvider>(\n symbols.reduce((acc, symbol) => {\n acc[symbol.uid] = symbol;\n return acc;\n }, {} as SymbolUIProvider),\n );\n\n useEffect(() => {\n if (symbols.length > 0) {\n setSymbolUIs(\n symbols.reduce((acc, symbol) => {\n acc[symbol.uid] = symbol;\n return acc;\n }, {} as SymbolUIProvider),\n );\n }\n }, [symbols]);\n\n // UPDATE_SYMBOLS / GET_SYMBOLS are handled by use-symbol-events.hook.ts,\n // which updates `state.symbols` — that flows down here as the `symbols`\n // prop and is picked up by the useEffect above. Registering another\n // listener here just produced a duplicate-registration warning.\n\n useEffect(() => {\n const handleApplySymbolOperation = (data: {\n operations: Operation[];\n uid: string;\n }) => {\n const { uid, operations } = data;\n setSymbolUIs((symbolUIs) => {\n if (!symbolUIs[uid]) return symbolUIs;\n const newSymbolUIs = produce(symbolUIs, (draft) => {\n const symbol = draft[uid];\n if (!symbol) return;\n const newSymbol = applyOperation(symbol.ui, operations);\n symbol.ui = newSymbol;\n draft[uid] = {\n ...symbol,\n };\n });\n registerSymbolComponent([newSymbolUIs[uid]], componentRegistry);\n return newSymbolUIs;\n });\n };\n\n const applySymbolOperationListener = composableStudioEventManager?.on<{\n operations: Operation[];\n uid: string;\n }>(POST_MESSAGE_EVENTS.APPLY_SYMBOL_OPERATION, (event) => {\n handleApplySymbolOperation(event.data);\n });\n return () => {\n applySymbolOperationListener?.unregister();\n };\n }, []);\n\n useEffect(() => {\n const newSymbolListener = composableStudioEventManager?.on<{\n symbol: SymbolEntry;\n }>(POST_MESSAGE_EVENTS.ADD_NEW_SYMBOL, (event) => {\n const { symbol } = event.data;\n registerSymbolComponent([symbol], componentRegistry);\n setSymbolUIs((symbolUIs) => {\n return produce(symbolUIs, (draft) => {\n draft[symbol.uid] = symbol;\n });\n });\n });\n return () => {\n newSymbolListener?.unregister();\n };\n }, []);\n return (\n <SymbolUICtx.Provider value={symbolUIs}>{children}</SymbolUICtx.Provider>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBO,MAAM,gBAAgB,GAAG,CAAC,EAC/B,OAAO,EACP,QAAQ,GACc,KAAI;AAC1B,IAAA,MAAM,EAAE,iBAAiB,EAAE,GAAG,WAAW,EAAE;AAC3C,IAAA,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CACxC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,KAAI;AAC7B,QAAA,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM;AACxB,QAAA,OAAO,GAAG;AACZ,IAAA,CAAC,EAAE,EAAsB,CAAC,CAC3B;IAED,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;YACtB,YAAY,CACV,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,KAAI;AAC7B,gBAAA,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM;AACxB,gBAAA,OAAO,GAAG;AACZ,YAAA,CAAC,EAAE,EAAsB,CAAC,CAC3B;QACH;AACF,IAAA,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;;;;;IAOb,SAAS,CAAC,MAAK;AACb,QAAA,MAAM,0BAA0B,GAAG,CAAC,IAGnC,KAAI;AACH,YAAA,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,IAAI;AAChC,YAAA,YAAY,CAAC,CAAC,SAAS,KAAI;AACzB,gBAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;AAAE,oBAAA,OAAO,SAAS;gBACrC,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,EAAE,C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C,CAAC;AACF,QAAA,OAAO,MAAK;YACV,iBAAiB,EAAE,UAAU,EAAE;AACjC,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;AACN,IAAA,QACEA,GAAA,CAAC,WAAW,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,SAAS,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAwB;AAE7E;;;;"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { highlightNodeManager } from '@contentstack/studio-client';
|
|
2
2
|
import { useContext, useState, useEffect } from 'react';
|
|
3
3
|
import '../contexts/providers/renderer.provider.js';
|
|
4
|
+
import '../contexts/providers/edit-context.provider.js';
|
|
4
5
|
import { ActiveComponentPathContext } from '../contexts/providers/active-node.provider.js';
|
|
5
6
|
import 'react/jsx-runtime';
|
|
6
7
|
import '@contentstack/studio-messenger';
|
|
7
8
|
import '@contentstack/studio-react-components/contexts';
|
|
8
9
|
import 'immer';
|
|
10
|
+
import './use-edit-context-listener.hook.js';
|
|
9
11
|
import '@contentstack/studio-internal';
|
|
10
12
|
import '@contentstack/studio-core';
|
|
11
13
|
import '@contentstack/studio-react-components/basic-components';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-active-node-path.hook.js","sources":["../../src/hooks/use-active-node-path.hook.ts"],"sourcesContent":["import { StudioSpec, highlightNodeManager } from \"@contentstack/studio-client\";\nimport { Path } from \"@contentstack/studio-internal\";\nimport { useContext, useEffect, useState } from \"react\";\nimport {\n ActiveComponentPathContext,\n ActiveComponentPathContextType,\n} from \"../contexts/providers\";\n\nexport function useActiveComponentPath() {\n const activeComponentPath = useContext(ActiveComponentPathContext);\n return activeComponentPath;\n}\n\nexport function useGetActiveComponentPathContext(\n spec: StudioSpec,\n): ActiveComponentPathContextType {\n const [activeComponentPath, setActiveComponentPath] =\n useState<ActiveComponentPathContextType>({\n activeNodeUid: null,\n activeNodePath: null,\n });\n\n useEffect(() => {\n function getActiveNodeCallback(\n activeNodeUid: string,\n activeNodePath: Path,\n ) {\n if (!spec) return;\n\n setActiveComponentPath({\n activeNodeUid,\n activeNodePath,\n });\n }\n\n highlightNodeManager.onActiveNodeChange(getActiveNodeCallback, {\n syncToExistingValue: true,\n });\n\n return () => {\n highlightNodeManager.unsubscribeFromActiveNodeChange(\n getActiveNodeCallback,\n );\n };\n }, [spec]);\n\n return activeComponentPath;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-active-node-path.hook.js","sources":["../../src/hooks/use-active-node-path.hook.ts"],"sourcesContent":["import { StudioSpec, highlightNodeManager } from \"@contentstack/studio-client\";\nimport { Path } from \"@contentstack/studio-internal\";\nimport { useContext, useEffect, useState } from \"react\";\nimport {\n ActiveComponentPathContext,\n ActiveComponentPathContextType,\n} from \"../contexts/providers\";\n\nexport function useActiveComponentPath() {\n const activeComponentPath = useContext(ActiveComponentPathContext);\n return activeComponentPath;\n}\n\nexport function useGetActiveComponentPathContext(\n spec: StudioSpec,\n): ActiveComponentPathContextType {\n const [activeComponentPath, setActiveComponentPath] =\n useState<ActiveComponentPathContextType>({\n activeNodeUid: null,\n activeNodePath: null,\n });\n\n useEffect(() => {\n function getActiveNodeCallback(\n activeNodeUid: string,\n activeNodePath: Path,\n ) {\n if (!spec) return;\n\n setActiveComponentPath({\n activeNodeUid,\n activeNodePath,\n });\n }\n\n highlightNodeManager.onActiveNodeChange(getActiveNodeCallback, {\n syncToExistingValue: true,\n });\n\n return () => {\n highlightNodeManager.unsubscribeFromActiveNodeChange(\n getActiveNodeCallback,\n );\n };\n }, [spec]);\n\n return activeComponentPath;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;SAQgB,sBAAsB,GAAA;AACpC,IAAA,MAAM,mBAAmB,GAAG,UAAU,CAAC,0BAA0B,CAAC;AAClE,IAAA,OAAO,mBAAmB;AAC5B;AAEM,SAAU,gCAAgC,CAC9C,IAAgB,EAAA;AAEhB,IAAA,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GACjD,QAAQ,CAAiC;AACvC,QAAA,aAAa,EAAE,IAAI;AACnB,QAAA,cAAc,EAAE,IAAI;AACrB,KAAA,CAAC;IAEJ,SAAS,CAAC,MAAK;AACb,QAAA,SAAS,qBAAqB,CAC5B,aAAqB,EACrB,cAAoB,EAAA;AAEpB,YAAA,IAAI,CAAC,IAAI;gBAAE;AAEX,YAAA,sBAAsB,CAAC;gBACrB,aAAa;gBACb,cAAc;AACf,aAAA,CAAC;QACJ;AAEA,QAAA,oBAAoB,CAAC,kBAAkB,CAAC,qBAAqB,EAAE;AAC7D,YAAA,mBAAmB,EAAE,IAAI;AAC1B,SAAA,CAAC;AAEF,QAAA,OAAO,MAAK;AACV,YAAA,oBAAoB,CAAC,+BAA+B,CAClD,qBAAqB,CACtB;AACH,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAEV,IAAA,OAAO,mBAAmB;AAC5B;;;;"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import '../contexts/providers/renderer.provider.js';
|
|
3
|
+
import '../contexts/providers/edit-context.provider.js';
|
|
3
4
|
import '../contexts/providers/active-node.provider.js';
|
|
4
5
|
import 'react/jsx-runtime';
|
|
5
6
|
import '@contentstack/studio-client';
|
|
6
7
|
import '@contentstack/studio-messenger';
|
|
7
8
|
import '@contentstack/studio-react-components/contexts';
|
|
8
9
|
import 'immer';
|
|
10
|
+
import './use-edit-context-listener.hook.js';
|
|
9
11
|
import '@contentstack/studio-internal';
|
|
10
12
|
import '@contentstack/studio-core';
|
|
11
13
|
import '@contentstack/studio-react-components/basic-components';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-condition-block-context.js","sources":["../../src/hooks/use-condition-block-context.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { ConditionBlockContext } from \"../contexts/providers\";\n\nexport const useConditionBlockContext = () => useContext(ConditionBlockContext);\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-condition-block-context.js","sources":["../../src/hooks/use-condition-block-context.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { ConditionBlockContext } from \"../contexts/providers\";\n\nexport const useConditionBlockContext = () => useContext(ConditionBlockContext);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGO,MAAM,wBAAwB,GAAG,MAAM,UAAU,CAAC,qBAAqB;;;;"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import '../contexts/providers/renderer.provider.js';
|
|
3
|
+
import '../contexts/providers/edit-context.provider.js';
|
|
3
4
|
import '../contexts/providers/active-node.provider.js';
|
|
4
5
|
import 'react/jsx-runtime';
|
|
5
6
|
import '@contentstack/studio-client';
|
|
6
7
|
import '@contentstack/studio-messenger';
|
|
7
8
|
import '@contentstack/studio-react-components/contexts';
|
|
8
9
|
import 'immer';
|
|
10
|
+
import './use-edit-context-listener.hook.js';
|
|
9
11
|
import '@contentstack/studio-internal';
|
|
10
12
|
import '@contentstack/studio-core';
|
|
11
13
|
import '@contentstack/studio-react-components/basic-components';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-design-preview.hook.js","sources":["../../src/hooks/use-design-preview.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { DesignPreviewContext } from \"../contexts/providers\";\n\nexport const useDesignPreviewContext = () => useContext(DesignPreviewContext);\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-design-preview.hook.js","sources":["../../src/hooks/use-design-preview.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { DesignPreviewContext } from \"../contexts/providers\";\n\nexport const useDesignPreviewContext = () => useContext(DesignPreviewContext);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGO,MAAM,uBAAuB,GAAG,MAAM,UAAU,CAAC,oBAAoB;;;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { clientRendererModeUtil } from '@contentstack/studio-client';
|
|
2
|
+
import { DataStepMode, composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
import '../contexts/providers/edit-context.provider.js';
|
|
5
|
+
|
|
6
|
+
const DATA_STEP_MODES = Object.values(DataStepMode);
|
|
7
|
+
const isDataStepMode = (v) => DATA_STEP_MODES.includes(v);
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the per-composition editor context Studio owns (currently just
|
|
10
|
+
* `dataStepMode` — see composable-studio ADR 0008).
|
|
11
|
+
*
|
|
12
|
+
* Init is a PULL: once this effect runs (our handlers are mounted) we request
|
|
13
|
+
* the value from Studio, so it can never race an init-time push. A separate
|
|
14
|
+
* `SET_EDIT_CONTEXT` listener applies later live changes (e.g. the Freeform
|
|
15
|
+
* plan toggled mid-session). Defaults to `schema-or-pin` so anything that can't
|
|
16
|
+
* answer keeps the existing copy.
|
|
17
|
+
*/
|
|
18
|
+
const useEditContextListener = (composableUid) => {
|
|
19
|
+
const [dataStepMode, setDataStepMode] = useState(DataStepMode.SchemaOrPin);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!clientRendererModeUtil.isInsideStudioFrame())
|
|
22
|
+
return;
|
|
23
|
+
let cancelled = false;
|
|
24
|
+
composableStudioEventManager
|
|
25
|
+
?.send(POST_MESSAGE_EVENTS.GET_EDIT_CONTEXT, { composableUid })
|
|
26
|
+
.then((res) => {
|
|
27
|
+
if (!cancelled && isDataStepMode(res?.dataStepMode)) {
|
|
28
|
+
setDataStepMode(res.dataStepMode);
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
.catch(() => {
|
|
32
|
+
// Older Studio has no responder — keep the default.
|
|
33
|
+
});
|
|
34
|
+
const listener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.SET_EDIT_CONTEXT, (event) => {
|
|
35
|
+
if (isDataStepMode(event?.data?.dataStepMode)) {
|
|
36
|
+
setDataStepMode(event.data.dataStepMode);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return () => {
|
|
40
|
+
cancelled = true;
|
|
41
|
+
listener?.unregister();
|
|
42
|
+
};
|
|
43
|
+
}, [composableUid]);
|
|
44
|
+
return { dataStepMode };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { useEditContextListener };
|
|
48
|
+
//# sourceMappingURL=use-edit-context-listener.hook.js.map
|
|
@@ -0,0 +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 {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} 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":";;;;;AAQA,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,11 +1,13 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import '../contexts/providers/renderer.provider.js';
|
|
3
|
+
import '../contexts/providers/edit-context.provider.js';
|
|
3
4
|
import '../contexts/providers/active-node.provider.js';
|
|
4
5
|
import 'react/jsx-runtime';
|
|
5
6
|
import '@contentstack/studio-client';
|
|
6
7
|
import '@contentstack/studio-messenger';
|
|
7
8
|
import '@contentstack/studio-react-components/contexts';
|
|
8
9
|
import 'immer';
|
|
10
|
+
import './use-edit-context-listener.hook.js';
|
|
9
11
|
import '@contentstack/studio-internal';
|
|
10
12
|
import '@contentstack/studio-core';
|
|
11
13
|
import '@contentstack/studio-react-components/basic-components';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-preview-mode.hook.js","sources":["../../src/hooks/use-preview-mode.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { PreviewModeContext } from \"../contexts/providers\";\n\nexport const usePreviewMode = () => {\n return useContext(PreviewModeContext);\n};\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-preview-mode.hook.js","sources":["../../src/hooks/use-preview-mode.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { PreviewModeContext } from \"../contexts/providers\";\n\nexport const usePreviewMode = () => {\n return useContext(PreviewModeContext);\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGO,MAAM,cAAc,GAAG,MAAK;AACjC,IAAA,OAAO,UAAU,CAAC,kBAAkB,CAAC;AACvC;;;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { rendererContext } from '../contexts/providers/renderer.provider.js';
|
|
2
|
+
import '../contexts/providers/edit-context.provider.js';
|
|
2
3
|
import '../contexts/providers/active-node.provider.js';
|
|
3
4
|
import 'react/jsx-runtime';
|
|
4
5
|
import '@contentstack/studio-client';
|
|
@@ -6,6 +7,7 @@ import '@contentstack/studio-messenger';
|
|
|
6
7
|
import '@contentstack/studio-react-components/contexts';
|
|
7
8
|
import 'immer';
|
|
8
9
|
import { useContext } from 'react';
|
|
10
|
+
import './use-edit-context-listener.hook.js';
|
|
9
11
|
import '@contentstack/studio-internal';
|
|
10
12
|
import '@contentstack/studio-core';
|
|
11
13
|
import '@contentstack/studio-react-components/basic-components';
|
|
@@ -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":"
|
|
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,11 +1,13 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import '../contexts/providers/renderer.provider.js';
|
|
3
|
+
import '../contexts/providers/edit-context.provider.js';
|
|
3
4
|
import '../contexts/providers/active-node.provider.js';
|
|
4
5
|
import 'react/jsx-runtime';
|
|
5
6
|
import '@contentstack/studio-client';
|
|
6
7
|
import '@contentstack/studio-messenger';
|
|
7
8
|
import '@contentstack/studio-react-components/contexts';
|
|
8
9
|
import 'immer';
|
|
10
|
+
import './use-edit-context-listener.hook.js';
|
|
9
11
|
import '@contentstack/studio-internal';
|
|
10
12
|
import '@contentstack/studio-core';
|
|
11
13
|
import '@contentstack/studio-react-components/basic-components';
|
|
@@ -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":"
|
|
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,11 +1,13 @@
|
|
|
1
1
|
import { clientRendererModeUtil } from '@contentstack/studio-client';
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
import '../contexts/providers/renderer.provider.js';
|
|
4
|
+
import '../contexts/providers/edit-context.provider.js';
|
|
4
5
|
import '../contexts/providers/active-node.provider.js';
|
|
5
6
|
import 'react/jsx-runtime';
|
|
6
7
|
import '@contentstack/studio-messenger';
|
|
7
8
|
import '@contentstack/studio-react-components/contexts';
|
|
8
9
|
import 'immer';
|
|
10
|
+
import './use-edit-context-listener.hook.js';
|
|
9
11
|
import '@contentstack/studio-internal';
|
|
10
12
|
import '@contentstack/studio-core';
|
|
11
13
|
import '@contentstack/studio-react-components/basic-components';
|