@contentstack/studio-react-editor 1.4.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/BuildingIllustration.js +8 -0
- package/dist/components/BuildingIllustration.js.map +1 -0
- package/dist/components/EditableRenderer.js +29 -4
- package/dist/components/EditableRenderer.js.map +1 -1
- package/dist/components/Element.js +70 -22
- package/dist/components/Element.js.map +1 -1
- package/dist/components/PreviewRenderer.js +7 -0
- package/dist/components/PreviewRenderer.js.map +1 -1
- package/dist/components/Slot.js +26 -4
- package/dist/components/Slot.js.map +1 -1
- package/dist/components/WelcomeState.js +67 -0
- package/dist/components/WelcomeState.js.map +1 -0
- package/dist/components/elements/ConditionBlock.js +7 -0
- package/dist/components/elements/ConditionBlock.js.map +1 -1
- package/dist/components/elements/Repeater.js +11 -38
- package/dist/components/elements/Repeater.js.map +1 -1
- package/dist/components/elements/SectionComposition.js +226 -0
- package/dist/components/elements/SectionComposition.js.map +1 -0
- package/dist/components/elements/SectionSlot.js +199 -0
- package/dist/components/elements/SectionSlot.js.map +1 -0
- package/dist/components/elements/Symbol.js +9 -2
- package/dist/components/elements/Symbol.js.map +1 -1
- package/dist/components/styles.js +72 -0
- package/dist/components/styles.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/renderer.provider.js +1 -0
- package/dist/contexts/providers/renderer.provider.js.map +1 -1
- package/dist/contexts/providers/section-mode.provider.js +15 -0
- package/dist/contexts/providers/section-mode.provider.js.map +1 -0
- package/dist/contexts/providers/symbol-ui.provider.js +21 -6
- package/dist/contexts/providers/symbol-ui.provider.js.map +1 -1
- package/dist/hooks/use-active-node-path.hook.js +8 -1
- package/dist/hooks/use-active-node-path.hook.js.map +1 -1
- package/dist/hooks/use-condition-block-context.js +8 -1
- package/dist/hooks/use-condition-block-context.js.map +1 -1
- package/dist/hooks/use-design-preview.hook.js +8 -1
- 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 +8 -1
- package/dist/hooks/use-preview-mode.hook.js.map +1 -1
- package/dist/hooks/use-register-section.hook.js +110 -0
- package/dist/hooks/use-register-section.hook.js.map +1 -0
- package/dist/hooks/use-renderer.hook.js +8 -1
- package/dist/hooks/use-renderer.hook.js.map +1 -1
- package/dist/hooks/use-repeater.hook.js +8 -1
- package/dist/hooks/use-repeater.hook.js.map +1 -1
- package/dist/hooks/use-section-events.hook.js +63 -0
- package/dist/hooks/use-section-events.hook.js.map +1 -0
- package/dist/hooks/use-should-show-design.hook.js +48 -2
- package/dist/hooks/use-should-show-design.hook.js.map +1 -1
- package/dist/hooks/use-spec-data-listener.hook.js +402 -12
- package/dist/hooks/use-spec-data-listener.hook.js.map +1 -1
- package/dist/hooks/use-symbol-events.hook.js +13 -0
- package/dist/hooks/use-symbol-events.hook.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/package.json +11 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-spec-data-listener.hook.js","sources":["../../src/hooks/use-spec-data-listener.hook.ts"],"sourcesContent":["import {\n isCompositionBeingEdited,\n StudioSpec,\n applyOperation,\n} from \"@contentstack/studio-client\";\nimport { Operation } from \"@contentstack/studio-internal\";\nimport {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} from \"@contentstack/studio-messenger\";\nimport {\n StudioSpecData,\n DataSourceItem,\n DATA_SOURCES_PREFIX,\n} from \"@contentstack/studio-registry\";\nimport { useEffect } from \"react\";\nimport { produce, setAutoFreeze } from \"immer\";\n\n// NOTE: Immer (produce) automatically freezes the state to prevent mutations.\n// However, while resolving metadata bindings (which currently only include styles),\n// we need to add binding values directly to the node object.\n// Since the state is frozen by default, this throws an error.\n// To work around this, we disable auto-freezing here.\nsetAutoFreeze(false);\n\nexport const useSpecDataListener = (\n setState: React.Dispatch<React.SetStateAction<StudioSpec>>,\n state?: StudioSpec,\n composableUid?: string,\n) => {\n // HOOK TO UPDATE THE STATE WITH THE LATEST SPEC DATA\n useEffect(() => {\n if (!isCompositionBeingEdited(composableUid || \"\")) return;\n const specDataChangeListener =\n composableStudioEventManager?.on<StudioSpecData>(\n POST_MESSAGE_EVENTS.UPDATE_SPEC_DATA,\n async (event) => {\n const { data } = event;\n if (!data || !state?.data) return;\n\n setState((state: StudioSpec) => {\n if (!state) return state;\n return {\n ...state,\n data: data,\n };\n });\n },\n );\n\n const previewEntryChangeListener = composableStudioEventManager?.on<{\n dataSources: DataSourceItem[];\n }>(POST_MESSAGE_EVENTS.REPLACE_PREVIEW_ENTRY, async (event) => {\n const { data } = event;\n if (!data?.dataSources || !state?.data) return;\n\n setState((prevState: StudioSpec) => {\n if (!prevState) return prevState;\n return {\n ...prevState,\n data: { ...state?.data, [DATA_SOURCES_PREFIX]: data?.dataSources },\n };\n });\n });\n\n const applyOperationListener = composableStudioEventManager?.on<{\n operations: Operation[];\n }>(POST_MESSAGE_EVENTS.APPLY_OPERATION, (event) => {\n const { data } = event;\n setState((prevState: StudioSpec) => {\n if (!prevState?.ui || !data?.operations) return prevState;\n const newUI = produce(prevState.ui, (ui) => {\n const operations = data.operations;\n return applyOperation(ui, operations);\n });\n return { ...prevState, ui: newUI };\n });\n });\n return () => {\n applyOperationListener?.unregister();\n specDataChangeListener?.unregister();\n previewEntryChangeListener?.unregister();\n };\n }, [state?.compositionEntry?.uid, state?.data, composableUid]);\n};\n"],"names":[],"mappings":";;;;;;AAkBA;AACA;AACA;AACA;AACA;AACA,aAAa,CAAC,KAAK,CAAC;AAEb,MAAM,mBAAmB,GAAG,CACjC,QAA0D,EAC1D,KAAkB,EAClB,aAAsB,KACpB;;IAEF,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,wBAAwB,CAAC,aAAa,IAAI,EAAE,CAAC;YAAE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,UAAU;AAAE,oBAAA,OAAO,SAAS;gBACzD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,KAAI;AACzC,oBAAA,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU;AAClC,oBAAA,OAAO,cAAc,CAAC,EAAE,EAAE,UAAU,CAAC;AACvC,gBAAA,CAAC,CAAC;gBACF,OAAO,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE;AACpC,YAAA,CAAC,CAAC;AACJ,QAAA,CAAC,CAAC;AACF,QAAA,OAAO,MAAK;YACV,sBAAsB,EAAE,UAAU,EAAE;YACpC,sBAAsB,EAAE,UAAU,EAAE;YACpC,0BAA0B,EAAE,UAAU,EAAE;AAC1C,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;AAChE;;;;"}
|
|
1
|
+
{"version":3,"file":"use-spec-data-listener.hook.js","sources":["../../src/hooks/use-spec-data-listener.hook.ts"],"sourcesContent":["import {\n isCompositionBeingEdited,\n StudioSpec,\n applyOperation,\n SECTION_COMPOSITIONS_KEY,\n clientRendererModeUtil,\n NODE_TO_PARENT,\n NODE_TO_PATH_NODE,\n SectionCompositionEntry,\n} from \"@contentstack/studio-client\";\nimport { Operation } from \"@contentstack/studio-internal\";\nimport {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} from \"@contentstack/studio-messenger\";\nimport {\n StudioSpecData,\n DataSourceItem,\n DATA_SOURCES_PREFIX,\n} from \"@contentstack/studio-registry\";\nimport { seedSectionInstanceBindings } from \"@contentstack/studio-react-components/utils\";\nimport { useEffect, useRef } from \"react\";\nimport { produce, setAutoFreeze } from \"immer\";\n\n// NOTE: Immer (produce) automatically freezes the state to prevent mutations.\n// However, while resolving metadata bindings (which currently only include styles),\n// we need to add binding values directly to the node object.\n// Since the state is frozen by default, this throws an error.\n// To work around this, we disable auto-freezing here.\nsetAutoFreeze(false);\n\n/**\n * Walk a fresh UI tree (post-Immer-produce) and populate the NODE_TO_PARENT\n * and NODE_TO_PATH_NODE WeakMaps for every node. These maps are normally\n * populated during React render (in Element.tsx). After APPLY_OPERATION\n * produces a brand-new tree via Immer, the maps still hold entries for\n * stale node refs — `findPath` (used to compute hover/highlight paths sent\n * back to Studio) returns stale paths until the next React commit. Calling\n * this immediately after applyOperation closes that window.\n */\nfunction refreshNodeWeakMaps(root: any): void {\n if (!root || typeof root !== \"object\") return;\n NODE_TO_PARENT.set(root, undefined);\n const visit = (parent: any) => {\n const slots = parent?.slots || {};\n for (const slotUid of Object.keys(slots)) {\n const children = slots[slotUid] || [];\n for (let idx = 0; idx < children.length; idx++) {\n const child = children[idx];\n if (!child || typeof child !== \"object\") continue;\n NODE_TO_PARENT.set(child, parent);\n NODE_TO_PATH_NODE.set(child, [slotUid, idx] as any);\n visit(child);\n }\n }\n };\n visit(root);\n}\n\nexport const useSpecDataListener = (\n setState: React.Dispatch<React.SetStateAction<StudioSpec>>,\n // Read into `stateRef` only — listener bodies use `stateRef.current` (not\n // `state` directly) so the effect's deps don't include `state.data`, which\n // would force re-register on every data change and create a window with\n // zero handlers between unregister/re-register (the original\n // `NO_REQUEST_LISTENER_FOUND` cause).\n state?: StudioSpec,\n composableUid?: string,\n) => {\n // Keep a ref to the latest state so the listener registrations don't have\n // to depend on state.data — they can read latest via stateRef.current\n // synchronously. Without this, every state.data change tore down + re-registered\n // the listeners, creating a window where Studio's UPDATE_SECTION_CONTEXTS\n // message was dropped with NO_REQUEST_LISTENER_FOUND.\n const stateRef = useRef(state);\n stateRef.current = state;\n\n // Rebuild section_scoped_data entries for instances whose binding metadata\n // (selectedField / uidRemapping / parentRepeaterUID) is present in the\n // legacy section_compositions slice. Mirrors build-scoped-data.ts logic\n // inline so the hook can rebuild without re-running the full fetchSpec\n // pipeline. Needed because Studio's fresh per-instance bindings arrive via\n // UPDATE_SPEC_DATA (and UPDATE_SECTION_CONTEXTS), while the provider only\n // reads from section_scoped_data — without this rebuild, sections render\n // the stale pre-computed scope from the initial fetchSpec (selectedField\n // missing from UI metadata on cold load → scoped template = whole page\n // template → placeholder text).\n const rebuildScopedFromBindings = (\n prevData: any,\n incomingBindings?: Record<string, unknown>,\n ): any => {\n const dataSources = prevData?.dataSources || {};\n const sectionBindings: Record<string, any> =\n incomingBindings && Object.keys(incomingBindings).length\n ? {\n ...(dataSources[SECTION_COMPOSITIONS_KEY] || {}),\n ...incomingBindings,\n }\n : dataSources[SECTION_COMPOSITIONS_KEY] || {};\n\n const pageTemplate = dataSources.template;\n const prevScoped = prevData?.section_scoped_data || {};\n const nextScoped: Record<string, any> = { ...prevScoped };\n\n const getScopedData = (obj: any, selectedField?: string): any => {\n if (!selectedField) return obj;\n return (\n selectedField.split(\".\").reduce((val: any, seg: string) => {\n if (val == null) return val;\n const arrayMatch = seg.match(/^(.*?)\\[(\\d+)\\]$/);\n if (arrayMatch) {\n const [, name, idxStr] = arrayMatch;\n const next = name ? val[name] : val;\n return next == null ? next : next[Number(idxStr)];\n }\n // Non-indexed field access landing on an ARRAY → default to the first\n // element so an un-indexed array-ancestor path (e.g.\n // \"navigation_menu_3.menu_subitems\", where navigation_menu_3 is a\n // multiple group) still resolves instead of `array[field]` →\n // undefined → null. Indexed pushes (`navigation_menu_3[1]…`) override\n // this with the picked instance.\n if (Array.isArray(val)) {\n const first = val[0];\n return first == null ? null : first[seg];\n }\n return val[seg];\n }, obj) ?? null\n );\n };\n\n const applyUidRemapping = (\n scoped: any,\n uidRemapping: Record<string, string> = {},\n ): any => {\n if (\n !scoped ||\n typeof scoped !== \"object\" ||\n Object.keys(uidRemapping).length === 0\n ) {\n return scoped;\n }\n if (Array.isArray(scoped)) {\n return scoped.map((item: any) => applyUidRemapping(item, uidRemapping));\n }\n const remapped: Record<string, unknown> = {};\n const pageKeyValues = new Set(Object.values(uidRemapping));\n for (const [sectionKey, pageKey] of Object.entries(uidRemapping)) {\n remapped[sectionKey] = applyUidRemapping(scoped[pageKey], uidRemapping);\n }\n for (const key of Object.keys(scoped)) {\n if (!pageKeyValues.has(key) && !(key in uidRemapping)) {\n remapped[key] = applyUidRemapping(scoped[key], uidRemapping);\n }\n }\n return remapped;\n };\n\n let changed = false;\n for (const [instanceUid, bindingUnknown] of Object.entries(\n sectionBindings,\n )) {\n const binding = bindingUnknown as {\n selectedField?: string;\n uidRemapping?: Record<string, string>;\n parentRepeaterUID?: string | null;\n context?: unknown;\n componentPropsFallback?: Record<string, unknown>;\n };\n // Skip context-only legacy shape — no selectedField to re-scope from.\n if (binding && \"context\" in binding && !(\"selectedField\" in binding)) {\n continue;\n }\n const scopedTemplate = applyUidRemapping(\n getScopedData(pageTemplate, binding?.selectedField),\n binding?.uidRemapping,\n );\n let repeater: Record<string, { context: unknown }> | undefined;\n if (binding?.parentRepeaterUID) {\n const ctx = dataSources.repeater?.[binding.parentRepeaterUID];\n if (ctx !== undefined) {\n repeater = { [binding.parentRepeaterUID]: ctx };\n }\n }\n const prev = prevScoped[instanceUid] || {};\n // Refresh contentstack / contentstack_queries from the live page\n // dataSources every time we rebuild. The initial scoped data built\n // during fetchSpec may have stale (or empty) entries because the\n // iframe loaded with getSpecFromParent and never fetched the section's\n // data sources itself — the studio pushes them later via\n // UPDATE_SPEC_DATA. Pool-keyed maps would be ideal but the listener\n // doesn't have access to them; copying the full page slice is a safe\n // superset (same composite-key format the resolver expects).\n const refreshedContentstack =\n dataSources.contentstack && typeof dataSources.contentstack === \"object\"\n ? { ...dataSources.contentstack }\n : prev.contentstack || {};\n const refreshedQueries =\n dataSources.contentstack_queries &&\n typeof dataSources.contentstack_queries === \"object\"\n ? { ...dataSources.contentstack_queries }\n : prev.contentstack_queries || {};\n\n const next = {\n ...prev,\n template: scopedTemplate,\n contentstack: refreshedContentstack,\n contentstack_queries: refreshedQueries,\n page: dataSources,\n repeater: repeater ?? prev.repeater,\n // Carry binding metadata so SectionCompositionProvider can re-scope the\n // template from the LIVE per-iteration repeater item. The scopedTemplate\n // above is page-root-scoped and shared across every iteration of this\n // instance, so it can't represent per-iteration values on its own.\n parentRepeaterUID: binding?.parentRepeaterUID ?? null,\n selectedField: binding?.selectedField,\n uidRemapping: binding?.uidRemapping,\n componentPropsFallback: binding?.componentPropsFallback,\n };\n if (\n prev.template !== next.template ||\n prev.page !== next.page ||\n prev.repeater !== next.repeater ||\n prev.contentstack !== next.contentstack ||\n prev.contentstack_queries !== next.contentstack_queries ||\n prev.componentPropsFallback !== next.componentPropsFallback\n ) {\n nextScoped[instanceUid] = next;\n changed = true;\n }\n }\n if (!changed) return prevData;\n return { ...prevData, section_scoped_data: nextScoped };\n };\n\n // Self-heal when the section catalog arrives after the initial seed.\n // `sectionCompositions` (each section's `linked_schemas` + authored UI) is\n // fetched asynchronously (GET_SECTIONS / UPDATE_SECTIONS_CATALOG) and can land\n // AFTER the first `seedSectionInstanceBindings` run (on GET_COMPOSITION_SPEC).\n // A root section seeded without the catalog gets `selectedField=\"\"` → its\n // scoped template resolves to the whole page (renders the page root, e.g. the\n // page title, instead of its bound field) and stays wedged unless Studio's\n // UPDATE_SECTION_CONTEXTS push wins the race. This is especially visible after\n // a preview-entry switch, which re-navigates the canvas iframe (a fresh cold\n // load). Re-run the seeder — which now heals empty root scopes from the\n // freshly-available `linked_schemas` — and rebuild `section_scoped_data` so the\n // render picks up the corrected scope without depending on the timing of\n // Studio's push. No-op when the seeder heals nothing (`seeded === prev`), so\n // working specs are unaffected and this can't loop.\n useEffect(() => {\n // Editor-only heal — mirror every other effect in this hook, which\n // early-returns outside the Studio frame. No reason to re-seed/commit in a\n // standalone or published render.\n if (!clientRendererModeUtil.isInsideStudioFrame()) return;\n if (!state?.sectionCompositions?.length) return;\n setState((prev: StudioSpec) => {\n if (!prev?.ui || !prev?.data) return prev;\n const seeded = seedSectionInstanceBindings(prev);\n // Gate the rebuild + commit on the seeder's own no-op signal.\n // `rebuildScopedFromBindings` re-spreads the live `contentstack` /\n // `contentstack_queries` slices on every call, so for a page that has\n // sections it never returns its input unchanged — testing its result\n // would commit a fresh state (extra render + full scoped rebuild) on\n // every `sectionCompositions` ref change (Studio re-pushes the catalog on\n // refetch/refocus), not just when a cold-load scope actually heals.\n if (seeded === prev) return prev;\n return { ...seeded, data: rebuildScopedFromBindings(seeded.data) };\n });\n // Re-run whenever EITHER input the root-scope heal depends on lands:\n // • `sectionCompositions` — the section catalog (`linked_schemas`), and\n // • `connected_content_type` — the page CT that selects which linked\n // schema supplies the anchor field.\n // Both arrive asynchronously after a (re)load and in either order; keying on\n // only one leaves a race where the heal runs before the other is present,\n // computes an empty scope, and never retries — re-wedging the section.\n // The setState above changes neither dep, so this can't self-trigger.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n state?.sectionCompositions,\n (state?.compositionEntry as any)?.connected_content_type,\n ]);\n\n // HOOK TO UPDATE THE STATE WITH THE LATEST SPEC DATA\n // Listeners are registered as soon as we're inside the Studio frame, before\n // spec has been fetched. Studio decides when to push UPDATE_SECTION_CONTEXTS\n // and UPDATE_SPEC_DATA based on its own readiness signal; the SDK can't\n // gate on `isCompositionBeingEdited(composableUid)` because that requires the\n // spec — and the parent reaches \"ready\" before the SDK's setState effect\n // has propagated, producing NO_REQUEST_LISTENER_FOUND.\n // The handlers themselves still defensively check `stateRef.current?.data`\n // before acting, so registering early is safe.\n useEffect(() => {\n if (!clientRendererModeUtil.isInsideStudioFrame()) return;\n const specDataChangeListener =\n composableStudioEventManager?.on<StudioSpecData>(\n POST_MESSAGE_EVENTS.UPDATE_SPEC_DATA,\n async (event) => {\n const { data } = event;\n if (!data || !stateRef.current?.data) return;\n\n setState((state: StudioSpec) => {\n if (!state) return state;\n // Merge incoming over existing — never replace dataSources\n // wholesale. Studio's UPDATE_SPEC_DATA pushes can carry only\n // a subset of slices (e.g., only `template` + `section_compositions`),\n // and a naive overwrite would wipe slices the SDK relied on\n // (e.g., the `repeater` item context populated earlier from\n // preview data resolution). Result was a visible flicker as\n // sections inside a Repeater suddenly lost their item context.\n // Also merge section_compositions key-by-key so SDK-seeded\n // per-instance bindings survive when Studio's push is partial.\n const incomingSections =\n (data as any)?.dataSources?.[SECTION_COMPOSITIONS_KEY] || {};\n const existingSections =\n (state.data as any)?.dataSources?.[SECTION_COMPOSITIONS_KEY] ||\n {};\n const mergedDataSources = {\n ...((state.data as any)?.dataSources || {}),\n ...((data as any)?.dataSources || {}),\n [SECTION_COMPOSITIONS_KEY]: {\n ...existingSections,\n ...incomingSections,\n },\n };\n const mergedData = {\n ...state.data,\n ...data,\n dataSources: mergedDataSources,\n };\n const rebuilt = rebuildScopedFromBindings(mergedData);\n return {\n ...state,\n data: rebuilt,\n };\n });\n },\n );\n\n const previewEntryChangeListener = composableStudioEventManager?.on<{\n dataSources: DataSourceItem[];\n }>(POST_MESSAGE_EVENTS.REPLACE_PREVIEW_ENTRY, async (event) => {\n const { data } = event;\n if (!data?.dataSources || !stateRef.current?.data) return;\n\n setState((prevState: StudioSpec) => {\n if (!prevState) return prevState;\n // REPLACE_PREVIEW_ENTRY pushes dataSources for the preview-entry change\n // (typically just `template`/`contentstack` slices). Merge into existing\n // dataSources — don't wipe sibling slices like `repeater` or\n // `section_compositions`, which would cause a flicker for sections\n // inside a Repeater (their item context would disappear).\n const mergedData = {\n ...prevState?.data,\n [DATA_SOURCES_PREFIX]: {\n ...((prevState?.data as any)?.[DATA_SOURCES_PREFIX] || {}),\n ...(data?.dataSources as any),\n },\n };\n // The merge updates dataSources.template, but each section's SCOPED\n // template in section_scoped_data is derived from it — re-scope here,\n // else a section keeps its stale (often null) scope and renders the\n // empty placeholder after the preview entry is set/switched. (The\n // UPDATE_SPEC_DATA handler already rebuilds; this is the equivalent for\n // the preview-entry change path that EntryPickerBtn sends.)\n const rebuilt = rebuildScopedFromBindings(mergedData);\n return { ...prevState, data: rebuilt };\n });\n });\n\n const applyOperationListener = composableStudioEventManager?.on<{\n operations: Operation[];\n }>(POST_MESSAGE_EVENTS.APPLY_OPERATION, (event) => {\n const { data } = event;\n\n // Self-heal section catalog: if any op inserts a section-composition\n // node whose compositionUID isn't in the locally-known catalog\n // (race between Studio's section store hydration and the iframe's\n // initial GET_SECTIONS reply), re-fetch the catalog and merge.\n // Without this the section renders with \"Component … is not\n // registered\" until the page is saved + reloaded.\n const newSectionUids = new Set<string>();\n for (const op of data?.operations || []) {\n const node = (op as any)?.node;\n if (\n op &&\n (op as any).type === \"insert_node\" &&\n node &&\n typeof node === \"object\" &&\n node.type === \"section-composition\" &&\n typeof node.metadata?.compositionUID === \"string\"\n ) {\n newSectionUids.add(node.metadata.compositionUID as string);\n }\n }\n const known = new Set(\n (stateRef.current?.sectionCompositions || []).map(\n (s: SectionCompositionEntry) => s.uid,\n ),\n );\n const unknown = [...newSectionUids].filter((u) => !known.has(u));\n if (unknown.length > 0) {\n composableStudioEventManager\n ?.send<{ sectionCompositions: SectionCompositionEntry[] }>(\n POST_MESSAGE_EVENTS.GET_SECTIONS,\n {},\n )\n .then((resp) => {\n if (!resp?.sectionCompositions) return;\n setState((prevState: StudioSpec) => ({\n ...prevState,\n sectionCompositions: resp.sectionCompositions,\n }));\n })\n .catch(() => {});\n }\n\n setState((prevState: StudioSpec) => {\n if (!prevState?.ui || !data?.operations) return prevState;\n const newUI = produce(prevState.ui, (ui) => {\n const operations = data.operations;\n return applyOperation(ui, operations);\n });\n // Eagerly refresh the NODE_TO_PARENT / NODE_TO_PATH_NODE WeakMaps for\n // the new tree. These WeakMaps are otherwise only populated during\n // React render (Element.tsx) and `findPath` (used by hover/highlight\n // postMessages back to Studio) reads from them. Without this refresh\n // there is a window between APPLY_OPERATION and the next React commit\n // where mouse-move events emit paths derived from old node refs —\n // those paths don't exist in Studio's now-updated slate editor and\n // surface as \"Cannot find a descendant at path\" errors.\n refreshNodeWeakMaps(newUI as any);\n // Re-seed per-instance section bindings ONLY when the slate op might\n // have moved/inserted/removed a section-composition node. Property /\n // style / text-content ops can't change the section-instance graph,\n // so the seeder's full UI walk on those is wasted work. The seeder\n // itself is idempotent (it short-circuits when nothing mutated), but\n // skipping the walk altogether keeps interactive ops (typing, style\n // edits) cheap on large pages.\n const ops = data.operations as any[];\n const opAffectsSectionInstances = ops.some(\n (op) =>\n op?.type === \"insert_node\" ||\n op?.type === \"remove_node\" ||\n op?.type === \"move_node\" ||\n op?.type === \"merge_node\" ||\n op?.type === \"split_node\",\n );\n if (!opAffectsSectionInstances) {\n return { ...prevState, ui: newUI };\n }\n return seedSectionInstanceBindings({ ...prevState, ui: newUI });\n });\n });\n\n // Studio pushes only the section_compositions slice when section contexts\n // are recomputed (e.g. after a section node is added/moved/removed). We\n // patch just that slice on top of existing dataSources so other data\n // (template, contentstack, query results) isn't clobbered.\n //\n // We ALSO rebuild the matching `section_scoped_data[instanceUid].template`\n // (and repeater slot) using the fresh selectedField / uidRemapping /\n // parentRepeaterUID Studio just sent. Without this, SectionCompositionProvider\n // would keep rendering the stale pre-computed scoped data from fetchSpec\n // (which can be wrong on cold load if the UI node lacked\n // metadata.selectedField), because the provider prefers section_scoped_data\n // and never falls back to the legacy section_compositions slot when it\n // exists.\n const sectionContextsListener = composableStudioEventManager?.on<{\n sectionCompositions: Record<string, unknown>;\n }>(POST_MESSAGE_EVENTS.UPDATE_SECTION_CONTEXTS, (event) => {\n const { data } = event;\n if (!data?.sectionCompositions) return;\n // Merge key-by-key on top of SDK-seeded defaults. Studio only pushes\n // user-driven overrides for specific instance nodes; replacing the whole\n // slice would wipe the SDK's seeded baseline for all other instances.\n setState((prevState: StudioSpec) => {\n if (!prevState?.data) return prevState;\n const existing =\n (prevState.data as any)?.dataSources?.[SECTION_COMPOSITIONS_KEY] ||\n {};\n const mergedData = {\n ...prevState.data,\n dataSources: {\n ...prevState.data?.dataSources,\n [SECTION_COMPOSITIONS_KEY]: {\n ...existing,\n ...data.sectionCompositions,\n },\n },\n } as any;\n const finalData = rebuildScopedFromBindings(\n mergedData,\n data.sectionCompositions,\n );\n return {\n ...prevState,\n data: finalData,\n };\n });\n });\n\n // Signal to Studio that our editor→iframe post-message listeners are now\n // in the handler map. Studio gates UPDATE_SPEC_DATA (and similar) on this\n // event because earlier readiness signals (SDK_SPEC_RESOLVED, INIT_STUDIO)\n // fire before EditableRenderer commits its first render and race against\n // the .on(...) calls above.\n composableStudioEventManager\n ?.send(POST_MESSAGE_EVENTS.LISTENERS_READY, { composableUid })\n .then(() => {})\n .catch(() => {\n // Studio may not have its LISTENERS_READY handler registered yet on\n // very first paint — the bridge resolves this via its message queue,\n // so a dropped first emit is harmless. Not an error worth surfacing.\n });\n\n return () => {\n applyOperationListener?.unregister();\n specDataChangeListener?.unregister();\n previewEntryChangeListener?.unregister();\n sectionContextsListener?.unregister();\n };\n // Deps deliberately exclude state.data — see stateRef above. Re-registering\n // on every data change creates a window where Studio's pushes are dropped\n // with NO_REQUEST_LISTENER_FOUND. We do re-register on composableUid change\n // (e.g. switching to a different composition without unmount); the\n // LISTENERS_READY emit above re-signals Studio after each rebind.\n }, [composableUid]);\n};\n"],"names":[],"mappings":";;;;;;;AAwBA;AACA;AACA;AACA;AACA;AACA,aAAa,CAAC,KAAK,CAAC;AAEpB;;;;;;;;AAQG;AACH,SAAS,mBAAmB,CAAC,IAAS,EAAA;AACpC,IAAA,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE;AACvC,IAAA,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC;AACnC,IAAA,MAAM,KAAK,GAAG,CAAC,MAAW,KAAI;AAC5B,QAAA,MAAM,KAAK,GAAG,MAAM,EAAE,KAAK,IAAI,EAAE;QACjC,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACxC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE;AACrC,YAAA,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;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,CAAC,MAAK;;;;AAIZ,QAAA,CAAC,CAAC;AAEJ,QAAA,OAAO,MAAK;YACV,sBAAsB,EAAE,UAAU,EAAE;YACpC,sBAAsB,EAAE,UAAU,EAAE;YACpC,0BAA0B,EAAE,UAAU,EAAE;YACxC,uBAAuB,EAAE,UAAU,EAAE;AACvC,QAAA,CAAC;;;;;;AAMH,IAAA,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;AACrB;;;;"}
|
|
@@ -22,6 +22,19 @@ const useSymbolsEvents = (setState, state, composableUid) => {
|
|
|
22
22
|
};
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
|
+
// Pull current symbols from Studio now that listener is ready.
|
|
26
|
+
// Avoids race where UPDATE_SYMBOLS fires before this listener mounts.
|
|
27
|
+
composableStudioEventManager
|
|
28
|
+
?.send(POST_MESSAGE_EVENTS.GET_SYMBOLS, {})
|
|
29
|
+
.then((data) => {
|
|
30
|
+
if (data?.symbols?.length) {
|
|
31
|
+
setState((prevState) => ({
|
|
32
|
+
...prevState,
|
|
33
|
+
symbols: data.symbols,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
.catch(() => { });
|
|
25
38
|
return () => {
|
|
26
39
|
symbolEventListener?.unregister();
|
|
27
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-symbol-events.hook.js","sources":["../../src/hooks/use-symbol-events.hook.ts"],"sourcesContent":["import {\n StudioSpec,\n isCompositionBeingEdited,\n SymbolEntry,\n} from \"@contentstack/studio-client\";\nimport {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} from \"@contentstack/studio-messenger\";\nimport { useEffect } from \"react\";\nimport { useRegisterSymbolComponents } from \"./use-register-symbol.hook\";\n\n/**\n * This hook is used to listen to the symbols events and update the state with the latest symbols.\n */\nexport const useSymbolsEvents = (\n setState: React.Dispatch<React.SetStateAction<StudioSpec>>,\n state?: StudioSpec,\n composableUid?: string,\n) => {\n useRegisterSymbolComponents(state?.symbols || []);\n useEffect(() => {\n if (!isCompositionBeingEdited(composableUid || \"\")) return;\n const symbolEventListener = composableStudioEventManager?.on<{\n symbols: SymbolEntry[];\n }>(POST_MESSAGE_EVENTS.UPDATE_SYMBOLS, (event) => {\n const { data } = event;\n if (!data?.symbols) return;\n setState((prevState: StudioSpec) => {\n return {\n ...prevState,\n symbols: data.symbols,\n };\n });\n });\n return () => {\n symbolEventListener?.unregister();\n };\n }, [state?.compositionEntry?.uid, composableUid]);\n};\n"],"names":[],"mappings":";;;;;AAYA;;AAEG;AACI,MAAM,gBAAgB,GAAG,CAC9B,QAA0D,EAC1D,KAAkB,EAClB,aAAsB,KACpB;AACF,IAAA,2BAA2B,CAAC,KAAK,EAAE,OAAO,IAAI,EAAE,CAAC;IACjD,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,wBAAwB,CAAC,aAAa,IAAI,EAAE,CAAC;YAAE;AACpD,QAAA,MAAM,mBAAmB,GAAG,4BAA4B,EAAE,EAAE,CAEzD,mBAAmB,CAAC,cAAc,EAAE,CAAC,KAAK,KAAI;AAC/C,YAAA,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK;YACtB,IAAI,CAAC,IAAI,EAAE,OAAO;gBAAE;AACpB,YAAA,QAAQ,CAAC,CAAC,SAAqB,KAAI;gBACjC,OAAO;AACL,oBAAA,GAAG,SAAS;oBACZ,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB;AACH,YAAA,CAAC,CAAC;AACJ,QAAA,CAAC,CAAC;AACF,QAAA,OAAO,MAAK;YACV,mBAAmB,EAAE,UAAU,EAAE;AACnC,QAAA,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;AACnD;;;;"}
|
|
1
|
+
{"version":3,"file":"use-symbol-events.hook.js","sources":["../../src/hooks/use-symbol-events.hook.ts"],"sourcesContent":["import {\n StudioSpec,\n isCompositionBeingEdited,\n SymbolEntry,\n} from \"@contentstack/studio-client\";\nimport {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} from \"@contentstack/studio-messenger\";\nimport { useEffect } from \"react\";\nimport { useRegisterSymbolComponents } from \"./use-register-symbol.hook\";\n\n/**\n * This hook is used to listen to the symbols events and update the state with the latest symbols.\n */\nexport const useSymbolsEvents = (\n setState: React.Dispatch<React.SetStateAction<StudioSpec>>,\n state?: StudioSpec,\n composableUid?: string,\n) => {\n useRegisterSymbolComponents(state?.symbols || []);\n useEffect(() => {\n if (!isCompositionBeingEdited(composableUid || \"\")) return;\n const symbolEventListener = composableStudioEventManager?.on<{\n symbols: SymbolEntry[];\n }>(POST_MESSAGE_EVENTS.UPDATE_SYMBOLS, (event) => {\n const { data } = event;\n if (!data?.symbols) return;\n setState((prevState: StudioSpec) => {\n return {\n ...prevState,\n symbols: data.symbols,\n };\n });\n });\n\n // Pull current symbols from Studio now that listener is ready.\n // Avoids race where UPDATE_SYMBOLS fires before this listener mounts.\n composableStudioEventManager\n ?.send<{ symbols: SymbolEntry[] }>(POST_MESSAGE_EVENTS.GET_SYMBOLS, {})\n .then((data) => {\n if (data?.symbols?.length) {\n setState((prevState: StudioSpec) => ({\n ...prevState,\n symbols: data.symbols,\n }));\n }\n })\n .catch(() => {});\n\n return () => {\n symbolEventListener?.unregister();\n };\n }, [state?.compositionEntry?.uid, composableUid]);\n};\n"],"names":[],"mappings":";;;;;AAYA;;AAEG;AACI,MAAM,gBAAgB,GAAG,CAC9B,QAA0D,EAC1D,KAAkB,EAClB,aAAsB,KACpB;AACF,IAAA,2BAA2B,CAAC,KAAK,EAAE,OAAO,IAAI,EAAE,CAAC;IACjD,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,wBAAwB,CAAC,aAAa,IAAI,EAAE,CAAC;YAAE;AACpD,QAAA,MAAM,mBAAmB,GAAG,4BAA4B,EAAE,EAAE,CAEzD,mBAAmB,CAAC,cAAc,EAAE,CAAC,KAAK,KAAI;AAC/C,YAAA,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK;YACtB,IAAI,CAAC,IAAI,EAAE,OAAO;gBAAE;AACpB,YAAA,QAAQ,CAAC,CAAC,SAAqB,KAAI;gBACjC,OAAO;AACL,oBAAA,GAAG,SAAS;oBACZ,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB;AACH,YAAA,CAAC,CAAC;AACJ,QAAA,CAAC,CAAC;;;QAIF;AACE,cAAE,IAAI,CAA6B,mBAAmB,CAAC,WAAW,EAAE,EAAE;AACrE,aAAA,IAAI,CAAC,CAAC,IAAI,KAAI;AACb,YAAA,IAAI,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE;AACzB,gBAAA,QAAQ,CAAC,CAAC,SAAqB,MAAM;AACnC,oBAAA,GAAG,SAAS;oBACZ,OAAO,EAAE,IAAI,CAAC,OAAO;AACtB,iBAAA,CAAC,CAAC;YACL;AACF,QAAA,CAAC;AACA,aAAA,KAAK,CAAC,MAAK,EAAE,CAAC,CAAC;AAElB,QAAA,OAAO,MAAK;YACV,mBAAmB,EAAE,UAAU,EAAE;AACnC,QAAA,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;AACnD;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
2
3
|
import { StudioSpec } from '@contentstack/studio-client';
|
|
3
4
|
import { ComponentRegistry, ComposableStudioData } from '@contentstack/studio-registry';
|
|
4
|
-
import { ReactNode } from 'react';
|
|
5
5
|
|
|
6
6
|
type ComponentRegistryType = ComponentRegistry<(props?: any) => ReactNode>;
|
|
7
7
|
|
|
@@ -15,6 +15,6 @@ interface EditableRendererHOCProps {
|
|
|
15
15
|
}
|
|
16
16
|
declare function EditableRendererHOC(props: EditableRendererHOCProps & {
|
|
17
17
|
children: React.ReactNode;
|
|
18
|
-
}):
|
|
18
|
+
}): react.JSX.Element;
|
|
19
19
|
|
|
20
20
|
export { EditableRendererHOC as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/studio-react-editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Contains all logic of editing for react based environment",
|
|
5
5
|
"author": "RavenColEvol <ravilamkoti@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/contentstack/composable-studio-sdk#readme",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"url": "https://github.com/contentstack/composable-studio-sdk/issues"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"react": "
|
|
39
|
-
"react-dom": "
|
|
38
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
39
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@contentstack/common-config": "^1.1
|
|
42
|
+
"@contentstack/common-config": "^1.2.1",
|
|
43
43
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
44
44
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
45
45
|
"@rollup/plugin-terser": "^1.0.0",
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
"@types/react-dom": "^18.3.5",
|
|
50
50
|
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
51
51
|
"@typescript-eslint/parser": "^7.2.0",
|
|
52
|
-
"esbuild-plugin-preserve-directives": "^0.0.11",
|
|
53
52
|
"eslint": "^8.57.0",
|
|
54
53
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
55
54
|
"eslint-plugin-react-refresh": "^0.4.6",
|
|
@@ -60,20 +59,17 @@
|
|
|
60
59
|
"typescript": "^5.2.2"
|
|
61
60
|
},
|
|
62
61
|
"dependencies": {
|
|
63
|
-
"@contentstack/studio-client": "^1.
|
|
64
|
-
"@contentstack/studio-core": "^1.1
|
|
65
|
-
"@contentstack/studio-internal": "^1.
|
|
66
|
-
"@contentstack/studio-messenger": "^1.
|
|
67
|
-
"@contentstack/studio-react-components": "^1.
|
|
68
|
-
"@contentstack/studio-registry": "^1.
|
|
62
|
+
"@contentstack/studio-client": "^1.7.1",
|
|
63
|
+
"@contentstack/studio-core": "^1.2.1",
|
|
64
|
+
"@contentstack/studio-internal": "^1.3.1",
|
|
65
|
+
"@contentstack/studio-messenger": "^1.5.1",
|
|
66
|
+
"@contentstack/studio-react-components": "^1.7.1",
|
|
67
|
+
"@contentstack/studio-registry": "^1.6.1",
|
|
69
68
|
"classnames": "^2.5.1",
|
|
70
69
|
"goober": "^2.1.16",
|
|
71
70
|
"immer": "^10.1.1",
|
|
72
71
|
"lodash-es": "^4.18.1",
|
|
73
72
|
"react-error-boundary": "^6.0.0"
|
|
74
73
|
},
|
|
75
|
-
"
|
|
76
|
-
"access": "public"
|
|
77
|
-
},
|
|
78
|
-
"gitHead": "1877b45f4a73ffb0c570ea06c197ba95504c014a"
|
|
74
|
+
"gitHead": "27539dc404d9358c9aa334ccbe6cd98e0405c205"
|
|
79
75
|
}
|