@contentstack/studio-react-editor 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/BuildingIllustration.js +8 -0
- package/dist/components/BuildingIllustration.js.map +1 -0
- package/dist/components/EditableRenderer.js +29 -6
- package/dist/components/EditableRenderer.js.map +1 -1
- package/dist/components/Element.js +61 -29
- package/dist/components/Element.js.map +1 -1
- package/dist/components/PreviewRenderer.js +4 -0
- package/dist/components/PreviewRenderer.js.map +1 -1
- package/dist/components/Slot.js +31 -4
- package/dist/components/Slot.js.map +1 -1
- package/dist/components/WelcomeState.js +33 -0
- package/dist/components/WelcomeState.js.map +1 -0
- package/dist/components/elements/ConditionBlock.js +4 -0
- package/dist/components/elements/ConditionBlock.js.map +1 -1
- package/dist/components/elements/Repeater.js +24 -7
- package/dist/components/elements/Repeater.js.map +1 -1
- package/dist/components/elements/SectionComposition.js +94 -0
- package/dist/components/elements/SectionComposition.js.map +1 -0
- package/dist/components/elements/SectionSlot.js +154 -0
- package/dist/components/elements/SectionSlot.js.map +1 -0
- package/dist/components/elements/Symbol.js +6 -2
- package/dist/components/elements/Symbol.js.map +1 -1
- package/dist/components/styles.js +85 -0
- package/dist/components/styles.js.map +1 -1
- package/dist/contexts/providers/renderer.provider.js +1 -0
- package/dist/contexts/providers/renderer.provider.js.map +1 -1
- package/dist/contexts/providers/symbol-ui.provider.js +18 -6
- package/dist/contexts/providers/symbol-ui.provider.js.map +1 -1
- package/dist/hooks/use-active-node-path.hook.js +5 -1
- package/dist/hooks/use-active-node-path.hook.js.map +1 -1
- package/dist/hooks/use-canvas-events.hook.js +7 -2
- package/dist/hooks/use-canvas-events.hook.js.map +1 -1
- package/dist/hooks/use-condition-block-context.js +5 -1
- package/dist/hooks/use-condition-block-context.js.map +1 -1
- package/dist/hooks/use-design-preview.hook.js +5 -1
- package/dist/hooks/use-design-preview.hook.js.map +1 -1
- package/dist/hooks/use-preview-mode.hook.js +5 -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 +5 -1
- package/dist/hooks/use-renderer.hook.js.map +1 -1
- package/dist/hooks/use-repeater.hook.js +5 -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 +8 -1
- package/dist/hooks/use-should-show-design.hook.js.map +1 -1
- package/dist/hooks/use-spec-data-listener.hook.js +335 -10
- 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/package.json +11 -11
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Button, EDIT_COMPOSITION_LABEL } from '@contentstack/studio-core';
|
|
3
|
+
import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
|
|
4
|
+
import { COMPOSABLE_DATA_ATTRIBUTES } from '@contentstack/studio-client';
|
|
5
|
+
import { SectionCompositionProvider } from '@contentstack/studio-react-components/basic-components';
|
|
6
|
+
import { DataCtxProvider } from '@contentstack/studio-react-components/contexts';
|
|
7
|
+
import { useData } from '@contentstack/studio-react-components/hooks';
|
|
8
|
+
import { css } from 'goober';
|
|
9
|
+
import { useCallback, useMemo } from 'react';
|
|
10
|
+
import { PreviewRenderer } from '../PreviewRenderer.js';
|
|
11
|
+
import { styleFactory } from '../styles.js';
|
|
12
|
+
|
|
13
|
+
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
14
|
+
/** Reads sectionExposedProps from the section spec's UI metadata. */
|
|
15
|
+
function getExposedPropDefs(spec) {
|
|
16
|
+
const compositionEntry = spec.compositionEntry;
|
|
17
|
+
return (compositionEntry?.ui?.metadata?.sectionExposedProps ?? []);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Builds a map of { [ep.uid]: resolvedValue } from the props that
|
|
21
|
+
* retrievePropValue already resolved for the page-level section node.
|
|
22
|
+
*
|
|
23
|
+
* retrievePropValue resolves the bindings the page composer set on the section
|
|
24
|
+
* node's exposed props (e.g. template.heroTitle) and spreads them onto this
|
|
25
|
+
* component. The page node's binding is the SOLE source of truth for an exposed
|
|
26
|
+
* prop, so we emit an entry for EVERY exposed prop — including cleared/empty
|
|
27
|
+
* ones (value `undefined`/`""`). That lets a cleared prop render its empty value
|
|
28
|
+
* downstream instead of falling back to the section's internal binding.
|
|
29
|
+
*/
|
|
30
|
+
function buildOverrideValues(exposedPropDefs, rest) {
|
|
31
|
+
const overrides = {};
|
|
32
|
+
for (const ep of exposedPropDefs) {
|
|
33
|
+
overrides[ep.uid] = rest[ep.uid];
|
|
34
|
+
}
|
|
35
|
+
return overrides;
|
|
36
|
+
}
|
|
37
|
+
// ─── Icon ────────────────────────────────────────────────────────────────────
|
|
38
|
+
function StudioIcon() {
|
|
39
|
+
return (jsxs("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("path", { fillRule: "evenodd", clipRule: "evenodd", 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", fill: "#6C5CE7" }), jsx("path", { fillRule: "evenodd", clipRule: "evenodd", 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", fill: "#6C5CE7" }), jsx("path", { fillRule: "evenodd", clipRule: "evenodd", 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", fill: "#6C5CE7" }), jsx("path", { fillRule: "evenodd", clipRule: "evenodd", 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", fill: "#6C5CE7" }), jsx("path", { 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", fill: "#6C5CE7" })] }));
|
|
40
|
+
}
|
|
41
|
+
// ─── Component ───────────────────────────────────────────────────────────────
|
|
42
|
+
function SectionComposition({ spec, compositionUID, studioAttributes, className, ...rest }) {
|
|
43
|
+
const styles = styleFactory(css);
|
|
44
|
+
const handleEditClick = useCallback((event) => {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
event.stopPropagation();
|
|
47
|
+
composableStudioEventManager?.send(POST_MESSAGE_EVENTS.OPEN_IN_COMPOSABLE_STUDIO_EVENT_MESSAGE, { compositionEntryUid: compositionUID, compositionQuery: null });
|
|
48
|
+
}, [compositionUID]);
|
|
49
|
+
// Definitions of which props are exposed (uid, bindingAtExposeTime, etc.)
|
|
50
|
+
const exposedPropDefs = useMemo(() => getExposedPropDefs(spec), [spec]);
|
|
51
|
+
// Map of { [ep.uid]: resolvedPageValue } — values already resolved by
|
|
52
|
+
// retrievePropValue against the page's data context and spread into rest.
|
|
53
|
+
const overrideValues = useMemo(() => buildOverrideValues(exposedPropDefs, rest), [
|
|
54
|
+
exposedPropDefs,
|
|
55
|
+
JSON.stringify(exposedPropDefs.map((ep) => rest[ep.uid])),
|
|
56
|
+
]);
|
|
57
|
+
// Exclude exposed prop keys and their $-prefixed CSLP counterparts from DOM
|
|
58
|
+
// spread. retrievePropValue adds both `uid` (resolved value) and `$uid` (CSLP
|
|
59
|
+
// live-preview tag) to the resolved props — both are invalid as div attributes.
|
|
60
|
+
const domProps = useMemo(() => {
|
|
61
|
+
const excluded = new Set(exposedPropDefs.flatMap((ep) => [ep.uid, `$${ep.uid}`]));
|
|
62
|
+
return Object.fromEntries(Object.entries(rest).filter(([k]) => !excluded.has(k)));
|
|
63
|
+
}, [exposedPropDefs, rest]);
|
|
64
|
+
return (jsxs("div", { ...domProps, ...studioAttributes, className: [styles.embeddedSectionHost, className]
|
|
65
|
+
.filter(Boolean)
|
|
66
|
+
.join(" "), children: [jsxs(Button, { className: `cs-embedded-section-edit-btn ${styles.embeddedSectionButton}`, onClick: handleEditClick, type: "button", "data-studio-ui": true, children: [jsx(StudioIcon, {}), EDIT_COMPOSITION_LABEL] }), jsx(SectionCompositionProvider, { uid: compositionUID, instanceUid: studioAttributes?.[COMPOSABLE_DATA_ATTRIBUTES.ID], exposedPropDefs: exposedPropDefs, overrideValues: overrideValues, children: jsx(SectionDataMerger, { spec: spec, children: jsx(PreviewRenderer, { spec: spec }) }) })] }));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Merges the section's own `spec.data.static_value` into the active data
|
|
70
|
+
* context so static-value-bound props authored inside the section (e.g. a
|
|
71
|
+
* SectionSlot's `label`, or any Text/Number/etc. inside the section's body)
|
|
72
|
+
* resolve against the section's persisted values when the section is
|
|
73
|
+
* consumed in a page. Without this, child Elements call useData() and get
|
|
74
|
+
* the page's data, which doesn't contain the section's static_value keys.
|
|
75
|
+
*/
|
|
76
|
+
function SectionDataMerger({ spec, children, }) {
|
|
77
|
+
const outerData = useData();
|
|
78
|
+
const merged = useMemo(() => {
|
|
79
|
+
const sectionStatic = spec?.data?.static_value;
|
|
80
|
+
if (!sectionStatic || typeof sectionStatic !== "object")
|
|
81
|
+
return outerData;
|
|
82
|
+
return {
|
|
83
|
+
...outerData,
|
|
84
|
+
static_value: {
|
|
85
|
+
...(outerData?.static_value || {}),
|
|
86
|
+
...sectionStatic,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}, [outerData, spec]);
|
|
90
|
+
return jsx(DataCtxProvider, { value: merged, children: children });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { SectionComposition };
|
|
94
|
+
//# sourceMappingURL=SectionComposition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SectionComposition.js","sources":["../../../src/components/elements/SectionComposition.tsx"],"sourcesContent":["import { Button, EDIT_COMPOSITION_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 { useData } 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\";\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 [key: string]: any;\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\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// ─── 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 ...rest\n}: SectionCompositionProps) {\n const styles = styleFactory(css);\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 // 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 );\n return Object.fromEntries(\n Object.entries(rest).filter(([k]) => !excluded.has(k)),\n );\n }, [exposedPropDefs, rest]);\n\n return (\n <div\n {...domProps}\n {...studioAttributes}\n className={[styles.embeddedSectionHost, className]\n .filter(Boolean)\n .join(\" \")}\n >\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_COMPOSITION_LABEL}\n </Button>\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 <SectionCompositionProvider\n uid={compositionUID}\n instanceUid={studioAttributes?.[COMPOSABLE_DATA_ATTRIBUTES.ID]}\n exposedPropDefs={exposedPropDefs}\n overrideValues={overrideValues}\n >\n <SectionDataMerger spec={spec}>\n <PreviewRenderer spec={spec as any} />\n </SectionDataMerger>\n </SectionCompositionProvider>\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":";;;;;;;;;;;;AA+CA;AAEA;AACA,SAAS,kBAAkB,CAAC,IAAiB,EAAA;AAC3C,IAAA,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAEjB;IACb,QACG,gBAAgB,EAAE,EAAE,EAAE,QAAQ,EAAE,mBAEnB,IAAI,EAAE;AAExB;AAEA;;;;;;;;;;AAUG;AACH,SAAS,mBAAmB,CAC1B,eAAiC,EAC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AA,CAAC,eAAe,EAAA,EAAC,KAAK,EAAE,MAAa,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAmB;AAC5E;;;;"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { ELEMENT_TO_NODE, COMPOSABLE_DATA_ATTRIBUTES, NODE_TO_PARENT, NODE_TO_PATH_NODE } from '@contentstack/studio-client';
|
|
3
|
+
import { SectionInstanceSlotsCtx, DataCtxProvider, CurrentNodeContext } from '@contentstack/studio-react-components/contexts';
|
|
4
|
+
import { useCurrentNode, useData } from '@contentstack/studio-react-components/hooks';
|
|
5
|
+
import { css } from 'goober';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import { useContext, useCallback, useMemo } from 'react';
|
|
8
|
+
import { styleFactory } from '../styles.js';
|
|
9
|
+
import { SelectedNodeProvider } from '../../contexts/providers/selected-node.provider.js';
|
|
10
|
+
import { PreviewModeContext } from '../../contexts/providers/preview-mode.provider.js';
|
|
11
|
+
import MemoizedElement from '../Element.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Editor variant of section-slot. Two modes:
|
|
15
|
+
*
|
|
16
|
+
* 1. **Authoring mode** (no SectionInstanceSlotsCtx in scope) — the section
|
|
17
|
+
* composition is being authored. Render a labelled drop-zone-style
|
|
18
|
+
* placeholder; not droppable into (section slots only accept drops when
|
|
19
|
+
* the section is consumed in a page composition).
|
|
20
|
+
*
|
|
21
|
+
* 2. **Consumption mode** (SectionInstanceSlotsCtx present) — the section
|
|
22
|
+
* is being rendered inside a page composition. Look up the page-side
|
|
23
|
+
* slots map by this slot's stable uid (== this node's uid). If filled,
|
|
24
|
+
* transclude the children via <Element> with their paths anchored to
|
|
25
|
+
* the page-side section-composition node, and lift them out of preview
|
|
26
|
+
* mode so they're individually selectable / hover-targetable / draggable
|
|
27
|
+
* like any other page-tree node. If empty, render a labelled drop
|
|
28
|
+
* target that itself acts as a builder node (attributes mapped to the
|
|
29
|
+
* page-side section-composition parent), so hover highlights only the
|
|
30
|
+
* slot zone — not the whole section.
|
|
31
|
+
*/
|
|
32
|
+
function SectionSlot({ studioAttributes, label, _uid, }) {
|
|
33
|
+
// ALL hooks unconditionally at the top — React doesn't allow conditional
|
|
34
|
+
// hook calls and the component returns early for authoring/empty modes.
|
|
35
|
+
const sectionCtx = useContext(SectionInstanceSlotsCtx);
|
|
36
|
+
const { currentNodePath: parentNodePath = [] } = useCurrentNode();
|
|
37
|
+
// Current section-local data (template scoped to section, in-section
|
|
38
|
+
// repeater item if surrounding, etc.). Slot children inherit this as
|
|
39
|
+
// their *default* context — the user's authored bindings on slot
|
|
40
|
+
// children resolve against this by default.
|
|
41
|
+
const sectionLocalData = useData();
|
|
42
|
+
const slotDomRef = useCallback((el) => {
|
|
43
|
+
if (el && sectionCtx?.sectionNode) {
|
|
44
|
+
ELEMENT_TO_NODE.set(el, sectionCtx.sectionNode);
|
|
45
|
+
}
|
|
46
|
+
}, [sectionCtx?.sectionNode]);
|
|
47
|
+
// Slot child's data context namespace:
|
|
48
|
+
//
|
|
49
|
+
// dataSources.template = section-local scoped template; if the
|
|
50
|
+
// slot sits inside an in-section
|
|
51
|
+
// Repeater that's currently iterating,
|
|
52
|
+
// this is the active iteration item.
|
|
53
|
+
// Matches what the Data Picker writes
|
|
54
|
+
// when authoring against fields from
|
|
55
|
+
// the slot's surrounding section scope.
|
|
56
|
+
// dataSources.repeater[uid] = in-section Repeater map (full
|
|
57
|
+
// per-uid context). Inherited from
|
|
58
|
+
// sectionLocal via {...sectionDS}.
|
|
59
|
+
// dataSources.static_value = section's persisted static values.
|
|
60
|
+
// dataSources.page = OUTERMOST page-level namespace
|
|
61
|
+
// ({ template, contentstack,
|
|
62
|
+
// contentstack_queries, ... }).
|
|
63
|
+
// Always points to the real page even
|
|
64
|
+
// across recursive slot nesting — see
|
|
65
|
+
// `truePageNamespace` below.
|
|
66
|
+
//
|
|
67
|
+
// Until Phase 8 lands, picker emits `dataSources.<src>.X` paths only.
|
|
68
|
+
// retrieve-data.ts retries unresolved `dataSources.<src>.X` lookups under
|
|
69
|
+
// `dataSources.page.<src>.X` so page-level bindings authored on slot
|
|
70
|
+
// children still resolve.
|
|
71
|
+
const slotChildData = useMemo(() => {
|
|
72
|
+
const sectionLocal = sectionLocalData || {};
|
|
73
|
+
const pageOuter = sectionCtx?.pageOuterData || {};
|
|
74
|
+
const pageDS = pageOuter?.dataSources || {};
|
|
75
|
+
const sectionDS = sectionLocal?.dataSources || {};
|
|
76
|
+
const repeaterMap = (sectionDS.repeater || {});
|
|
77
|
+
const repeaterUids = Object.keys(repeaterMap);
|
|
78
|
+
const activeRepeaterUid = repeaterUids.length > 0
|
|
79
|
+
? repeaterUids[repeaterUids.length - 1]
|
|
80
|
+
: undefined;
|
|
81
|
+
const activeItem = activeRepeaterUid
|
|
82
|
+
? repeaterMap[activeRepeaterUid]?.context
|
|
83
|
+
: undefined;
|
|
84
|
+
const sectionLocalTemplate = activeItem ?? sectionDS.template;
|
|
85
|
+
// Slot child's default namespace = section-local context AS IS (template,
|
|
86
|
+
// repeater, static_value, …). Page-level sources are nested under `page.*`
|
|
87
|
+
// as the explicit escape. This matches what the Data Picker writes when
|
|
88
|
+
// authoring a slot child (picker shows the slot child's surrounding
|
|
89
|
+
// scope, so its `template.X` / `repeater[uid].context.X` paths resolve
|
|
90
|
+
// natively without rewriting).
|
|
91
|
+
//
|
|
92
|
+
// For nested cases (Section B in Section A's slot), `page` must always
|
|
93
|
+
// point to the OUTERMOST page context — not to Section A's slot-local
|
|
94
|
+
// view. Otherwise each nesting level shadows `page` with the surrounding
|
|
95
|
+
// section's local, and `dataSources.page.template.title` would resolve
|
|
96
|
+
// to a modular_block item instead of the page entry. So: if the outer
|
|
97
|
+
// dataSources already has its own `page` key (because the section we're
|
|
98
|
+
// inside is itself in another slot), inherit THAT — it's the real page.
|
|
99
|
+
const outerPage = pageDS?.page;
|
|
100
|
+
const truePageNamespace = outerPage ?? pageDS;
|
|
101
|
+
return {
|
|
102
|
+
...sectionLocal,
|
|
103
|
+
dataSources: {
|
|
104
|
+
...sectionDS,
|
|
105
|
+
template: sectionLocalTemplate,
|
|
106
|
+
page: truePageNamespace,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}, [sectionLocalData, sectionCtx?.pageOuterData]);
|
|
110
|
+
// ALL hooks above are unconditional. From here, branch based on mode.
|
|
111
|
+
const styles = styleFactory(css);
|
|
112
|
+
const text = label && label.trim().length > 0 ? label : "Drop Here";
|
|
113
|
+
const slotUid = _uid ||
|
|
114
|
+
studioAttributes?.[COMPOSABLE_DATA_ATTRIBUTES.ID] ||
|
|
115
|
+
"section-slot";
|
|
116
|
+
// Authoring mode: section is the top-level composition being edited.
|
|
117
|
+
if (!sectionCtx) {
|
|
118
|
+
return (jsx("div", { [COMPOSABLE_DATA_ATTRIBUTES.SLOT]: true,
|
|
119
|
+
[COMPOSABLE_DATA_ATTRIBUTES.SLOT_UID]: slotUid, ...studioAttributes, className: classNames(styles.slotStyle), children: jsxs("span", { className: styles.slotDropText, children: [jsx(AddIcon, {}), " ", text] }) }));
|
|
120
|
+
}
|
|
121
|
+
// Consumption mode.
|
|
122
|
+
const filled = (sectionCtx.slotsMap[slotUid] || []);
|
|
123
|
+
const dropZoneAttrs = {
|
|
124
|
+
[COMPOSABLE_DATA_ATTRIBUTES.BUILDER]: true,
|
|
125
|
+
[COMPOSABLE_DATA_ATTRIBUTES.NODE]: true,
|
|
126
|
+
[COMPOSABLE_DATA_ATTRIBUTES.ID]: sectionCtx.sectionInstanceUid,
|
|
127
|
+
[COMPOSABLE_DATA_ATTRIBUTES.SLOT]: true,
|
|
128
|
+
[COMPOSABLE_DATA_ATTRIBUTES.SLOT_UID]: slotUid,
|
|
129
|
+
};
|
|
130
|
+
if (filled.length === 0) {
|
|
131
|
+
return (jsx("div", { ref: slotDomRef, ...dropZoneAttrs, ...studioAttributes, className: classNames(styles.slotStyle), children: jsxs("span", { className: styles.slotDropText, children: [jsx(AddIcon, {}), " ", text] }) }));
|
|
132
|
+
}
|
|
133
|
+
// Transclude filled children. Anchor each child's slate path under the
|
|
134
|
+
// page-side section-composition node + this slot's uid, exit preview
|
|
135
|
+
// mode so Element's internalAttributes get applied — making each child
|
|
136
|
+
// selectable, hover-highlightable, and draggable like a normal node.
|
|
137
|
+
return (jsx(DataCtxProvider, { value: slotChildData, children: jsx(PreviewModeContext.Provider, { value: false, children: jsx("div", { ref: slotDomRef, ...dropZoneAttrs, ...studioAttributes, style: { display: "contents" }, children: filled.map((child, idx) => {
|
|
138
|
+
if (!child || typeof child !== "object")
|
|
139
|
+
return null;
|
|
140
|
+
NODE_TO_PARENT.set(child, sectionCtx.sectionNode);
|
|
141
|
+
NODE_TO_PATH_NODE.set(child, [slotUid, idx]);
|
|
142
|
+
const childPath = [...parentNodePath, [slotUid, idx]];
|
|
143
|
+
return (jsx(CurrentNodeContext.Provider, { value: {
|
|
144
|
+
currentNodeUid: child.uid,
|
|
145
|
+
currentNodePath: childPath,
|
|
146
|
+
}, children: jsx(SelectedNodeProvider, { children: jsx(MemoizedElement, { node: child, renderError: () => null }) }) }, child.uid));
|
|
147
|
+
}) }) }) }));
|
|
148
|
+
}
|
|
149
|
+
const AddIcon = () => {
|
|
150
|
+
return (jsxs("svg", { width: "22", height: "22", viewBox: "0 0 22 22", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("rect", { x: "0.5", y: "0.5", width: "21", height: "21", rx: "4.5", fill: "white" }), jsx("rect", { x: "0.5", y: "0.5", width: "21", height: "21", rx: "4.5", stroke: "#475161" }), jsx("path", { 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", fill: "#475161" })] }));
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export { SectionSlot };
|
|
154
|
+
//# sourceMappingURL=SectionSlot.js.map
|
|
@@ -0,0 +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 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 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 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, exit preview\n // mode so Element's internalAttributes get applied — making each child\n // selectable, hover-highlightable, and draggable like a normal node.\n return (\n <DataCtxProvider value={slotChildData}>\n <PreviewModeContext.Provider value={false}>\n <div\n ref={slotDomRef as any}\n {...dropZoneAttrs}\n {...studioAttributes}\n style={{ display: \"contents\" }}\n >\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 </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":";;;;;;;;;;;;AA8BA;;;;;;;;;;;;;;;;;;AAkBG;AACG,SAAU,WAAW,CAAC,EAC1B,gBAAgB,EAChB,KAAK,EACL,IAAI,GACmB,EAAA;;;AAGvB,IAAA,MAAM,UAAU,GAAG,UAAU,CAAC,uBAAuB,CAAC;IACtD,MAAM,EAAE,eAAe,EAAE,cAAc,GAAG,EAAE,EAAE,GAAG,cAAc,EAAE;;;;;AAKjE,IAAA,MAAM,gBAAgB,GAAG,OAAO,EAAE;AAClC,IAAA,MAAM,UAAU,GAAG,WAAW,CAC5B,CAAC,EAAsB,KAAI;AACzB,QAAA,IAAI,EAAE,IAAI,UAAU,EAAE,WAAW,EAAE;YACjC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,WAAW,CAAC;QACjD;AACF,IAAA,CAAC,EACD,CAAC,UAAU,EAAE,WAAW,CAAC,CAC1B;;;;;;;;;;;;;;;;;;;;;;;;;AAyBD,IAAA,MAAM,aAAa,GAAG,OAAO,CAAC,MAAK;AACjC,QAAA,MAAM,YAAY,GAAQ,gBAAgB,IAAI,EAAE;AAChD,QAAA,MAAM,SAAS,GAAQ,UAAU,EAAE,aAAa,IAAI,EAAE;AACtD,QAAA,MAAM,MAAM,GAAG,SAAS,EAAE,WAAW,IAAI,EAAE;AAC3C,QAAA,MAAM,SAAS,GAAG,YAAY,EAAE,WAAW,IAAI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A,MAAA,EAAA,EAAM,CAAC,EAAC,KAAK,EAAC,CAAC,EAAC,KAAK,EAAC,KAAK,EAAC,IAAI,EAAC,MAAM,EAAC,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;;;;"}
|
|
@@ -4,15 +4,19 @@ import { useData } from '@contentstack/studio-react-components/hooks';
|
|
|
4
4
|
import { DATA_SOURCES } from '@contentstack/studio-registry';
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
6
|
import '@contentstack/studio-client';
|
|
7
|
+
import '@contentstack/studio-messenger';
|
|
8
|
+
import '@contentstack/studio-internal';
|
|
9
|
+
import '@contentstack/studio-core';
|
|
10
|
+
import '@contentstack/studio-react-components/basic-components';
|
|
11
|
+
import 'goober';
|
|
12
|
+
import { PreviewRenderer } from '../PreviewRenderer.js';
|
|
7
13
|
import '../../contexts/providers/renderer.provider.js';
|
|
8
14
|
import '../../contexts/providers/active-node.provider.js';
|
|
9
|
-
import '@contentstack/studio-messenger';
|
|
10
15
|
import 'immer';
|
|
11
16
|
import '../../contexts/providers/use-design-preview.provider.js';
|
|
12
17
|
import '../../contexts/providers/use-repeater.provider.js';
|
|
13
18
|
import '../../contexts/providers/use-condition-block.provider.js';
|
|
14
19
|
import '../../contexts/providers/preview-mode.provider.js';
|
|
15
|
-
import { PreviewRenderer } from '../PreviewRenderer.js';
|
|
16
20
|
import { useSymbolUIListener } from '../../hooks/use-symbol-ui-listener.hook.js';
|
|
17
21
|
|
|
18
22
|
function EditSymbolRenderer({ ui, studioAttributes, }) {
|
|
@@ -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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tEA,GAAA,CAAC,kBAAkB,EAAA,EAAA,GAAM,KAAiC,EAAA,CAAI,CAC/D,EAAA,CACmB;AAE1B;;;;"}
|
|
@@ -37,6 +37,36 @@ const styleFactory = (css) => ({
|
|
|
37
37
|
marginBottom: 0,
|
|
38
38
|
marginTop: 0,
|
|
39
39
|
}),
|
|
40
|
+
slotColumnStyle: css({
|
|
41
|
+
flexDirection: "column",
|
|
42
|
+
gap: "4px",
|
|
43
|
+
}),
|
|
44
|
+
slotDropText: css({
|
|
45
|
+
display: "inline-flex",
|
|
46
|
+
alignItems: "center",
|
|
47
|
+
gap: "4px",
|
|
48
|
+
}),
|
|
49
|
+
slotHintStyle: css({
|
|
50
|
+
textAlign: "center",
|
|
51
|
+
margin: 0,
|
|
52
|
+
}),
|
|
53
|
+
embeddedSectionHost: css({
|
|
54
|
+
position: "relative",
|
|
55
|
+
".cs-embedded-section-edit-btn": {
|
|
56
|
+
display: "none",
|
|
57
|
+
},
|
|
58
|
+
"&:hover": {
|
|
59
|
+
".cs-embedded-section-edit-btn": {
|
|
60
|
+
display: "flex",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
embeddedSectionButton: css({
|
|
65
|
+
position: "absolute",
|
|
66
|
+
top: "0.75rem",
|
|
67
|
+
right: "0.75rem",
|
|
68
|
+
zIndex: 2,
|
|
69
|
+
}),
|
|
40
70
|
rendererErrorComponent: css({
|
|
41
71
|
boxSizing: "border-box",
|
|
42
72
|
backgroundColor: "#fff0ed",
|
|
@@ -71,6 +101,61 @@ const styleFactory = (css) => ({
|
|
|
71
101
|
margin: 0,
|
|
72
102
|
},
|
|
73
103
|
}),
|
|
104
|
+
welcomeContainer: css({
|
|
105
|
+
display: "flex",
|
|
106
|
+
flexDirection: "column",
|
|
107
|
+
alignItems: "center",
|
|
108
|
+
justifyContent: "center",
|
|
109
|
+
padding: "40px 20px",
|
|
110
|
+
textAlign: "center",
|
|
111
|
+
minHeight: "400px",
|
|
112
|
+
}),
|
|
113
|
+
welcomeTitle: css({
|
|
114
|
+
fontSize: "20px",
|
|
115
|
+
fontWeight: "600",
|
|
116
|
+
color: "#475161",
|
|
117
|
+
margin: "20px 0 10px 0",
|
|
118
|
+
fontFamily: "Inter, sans-serif",
|
|
119
|
+
}),
|
|
120
|
+
welcomeSubtitle: css({
|
|
121
|
+
fontSize: "14px",
|
|
122
|
+
color: "#6E6B86",
|
|
123
|
+
margin: "0 0 30px 0",
|
|
124
|
+
maxWidth: "400px",
|
|
125
|
+
fontFamily: "Inter, sans-serif",
|
|
126
|
+
lineHeight: "1.5",
|
|
127
|
+
}),
|
|
128
|
+
welcomeSteps: css({
|
|
129
|
+
display: "flex",
|
|
130
|
+
flexDirection: "column",
|
|
131
|
+
gap: "16px",
|
|
132
|
+
maxWidth: "1000px",
|
|
133
|
+
width: "100%",
|
|
134
|
+
}),
|
|
135
|
+
welcomeStep: css({
|
|
136
|
+
padding: "16px",
|
|
137
|
+
border: "1px solid #DDE3EE",
|
|
138
|
+
borderRadius: "8px",
|
|
139
|
+
textAlign: "left",
|
|
140
|
+
"& h3": {
|
|
141
|
+
fontSize: "16px",
|
|
142
|
+
fontWeight: "600",
|
|
143
|
+
color: "#475161",
|
|
144
|
+
margin: "0 0 8px 0",
|
|
145
|
+
fontFamily: "Inter, sans-serif",
|
|
146
|
+
},
|
|
147
|
+
"& p": {
|
|
148
|
+
fontSize: "14px",
|
|
149
|
+
color: "#6E6B86",
|
|
150
|
+
margin: 0,
|
|
151
|
+
fontFamily: "Inter, sans-serif",
|
|
152
|
+
lineHeight: "1.4",
|
|
153
|
+
},
|
|
154
|
+
}),
|
|
155
|
+
activeWelcomeStep: css({
|
|
156
|
+
backgroundColor: "#F9F8FF",
|
|
157
|
+
border: "1px solid #6C5CE7",
|
|
158
|
+
}),
|
|
74
159
|
});
|
|
75
160
|
|
|
76
161
|
export { styleFactory };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sources":["../../src/components/styles.ts"],"sourcesContent":["import { css as gooberCss } from \"goober\";\n\nexport const styleFactory = (css: typeof gooberCss) => ({\n embedStyle: css({\n height: \"100%\",\n width: \"100%\",\n display: \"grid\",\n placeItems: \"center\",\n padding: \"1rem\",\n border: \"1px solid #dde3ee\",\n }),\n embedIconStyle: css({\n opacity: 0.5,\n }),\n pageStyle: css({\n height: \"100%\",\n }),\n slotStyle: css({\n boxSizing: \"border-box\",\n // width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n gap: \"4px\",\n alignItems: \"center\",\n justifyContent: \"center\",\n border: \"1px dashed #6c5ce7\",\n color: \"#475161\",\n fontSize: \"14px\",\n fontStyle: \"normal\",\n fontWeight: 400,\n lineHeight: \"24px\",\n userSelect: \"none\",\n fontFamily: \"Inter\",\n paddingInline: \"2rem\",\n paddingBlock: \"1rem\",\n transition: \"background-color 0.3s ease\",\n }),\n slotContentStyle: css({\n marginBottom: 0,\n marginTop: 0,\n }),\n rendererErrorComponent: css({\n boxSizing: \"border-box\",\n backgroundColor: \"#fff0ed\",\n borderWidth: \"1px\",\n borderStyle: \"solid\",\n borderColor: \"#fdafa3\",\n boxShadow: `0px 2px 4px rgba(0, 0, 0, 0.14),\n 0px 5px 5px rgba(0, 0, 0, 0.12),\n 0px 1px 10px rgba(108, 92, 231, 0.2)`,\n borderRadius: \"4px\",\n padding: \"1rem\",\n color: \"#475161\",\n fontFamily: \"Inter, sans-serif\",\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"1rem\",\n \".header\": {\n display: \"flex\",\n alignItems: \"center\",\n gap: \"0.5rem\",\n },\n h3: {\n fontSize: \"14px\",\n fontWeight: 600,\n margin: 0,\n },\n p: {\n fontSize: \"1rem\",\n fontWeight: 400,\n lineHeight: \"24px\",\n letterSpacing: \"1%\",\n margin: 0,\n },\n }),\n});\n"],"names":[],"mappings":"MAEa,YAAY,GAAG,CAAC,GAAqB,MAAM;IACtD,UAAU,EAAE,GAAG,CAAC;AACd,QAAA,MAAM,EAAE,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;AACnB,QAAA,OAAO,EAAE,MAAM;AACf,QAAA,KAAK,EAAE,SAAS;AAChB,QAAA,UAAU,EAAE,mBAAmB;AAC/B,QAAA,OAAO,EAAE,MAAM;AACf,QAAA,aAAa,EAAE,QAAQ;AACvB,QAAA,GAAG,EAAE,MAAM;AACX,QAAA,SAAS,EAAE;AACT,YAAA,OAAO,EAAE,MAAM;AACf,YAAA,UAAU,EAAE,QAAQ;AACpB,YAAA,GAAG,EAAE,QAAQ;AACd,SAAA;AACD,QAAA,EAAE,EAAE;AACF,YAAA,QAAQ,EAAE,MAAM;AAChB,YAAA,UAAU,EAAE,GAAG;AACf,YAAA,MAAM,EAAE,CAAC;AACV,SAAA;AACD,QAAA,CAAC,EAAE;AACD,YAAA,QAAQ,EAAE,MAAM;AAChB,YAAA,UAAU,EAAE,GAAG;AACf,YAAA,UAAU,EAAE,MAAM;AAClB,YAAA,aAAa,EAAE,IAAI;AACnB,YAAA,MAAM,EAAE,CAAC;AACV,SAAA;KACF,CAAC;AACH,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"styles.js","sources":["../../src/components/styles.ts"],"sourcesContent":["import { css as gooberCss } from \"goober\";\n\nexport const styleFactory = (css: typeof gooberCss) => ({\n embedStyle: css({\n height: \"100%\",\n width: \"100%\",\n display: \"grid\",\n placeItems: \"center\",\n padding: \"1rem\",\n border: \"1px solid #dde3ee\",\n }),\n embedIconStyle: css({\n opacity: 0.5,\n }),\n pageStyle: css({\n height: \"100%\",\n }),\n slotStyle: css({\n boxSizing: \"border-box\",\n // width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n gap: \"4px\",\n alignItems: \"center\",\n justifyContent: \"center\",\n border: \"1px dashed #6c5ce7\",\n color: \"#475161\",\n fontSize: \"14px\",\n fontStyle: \"normal\",\n fontWeight: 400,\n lineHeight: \"24px\",\n userSelect: \"none\",\n fontFamily: \"Inter\",\n paddingInline: \"2rem\",\n paddingBlock: \"1rem\",\n transition: \"background-color 0.3s ease\",\n }),\n slotContentStyle: css({\n marginBottom: 0,\n marginTop: 0,\n }),\n slotColumnStyle: css({\n flexDirection: \"column\",\n gap: \"4px\",\n }),\n slotDropText: css({\n display: \"inline-flex\",\n alignItems: \"center\",\n gap: \"4px\",\n }),\n slotHintStyle: css({\n textAlign: \"center\",\n margin: 0,\n }),\n embeddedSectionHost: css({\n position: \"relative\",\n \".cs-embedded-section-edit-btn\": {\n display: \"none\",\n },\n \"&:hover\": {\n \".cs-embedded-section-edit-btn\": {\n display: \"flex\",\n },\n },\n }),\n embeddedSectionButton: css({\n position: \"absolute\",\n top: \"0.75rem\",\n right: \"0.75rem\",\n zIndex: 2,\n }),\n rendererErrorComponent: css({\n boxSizing: \"border-box\",\n backgroundColor: \"#fff0ed\",\n borderWidth: \"1px\",\n borderStyle: \"solid\",\n borderColor: \"#fdafa3\",\n boxShadow: `0px 2px 4px rgba(0, 0, 0, 0.14),\n 0px 5px 5px rgba(0, 0, 0, 0.12),\n 0px 1px 10px rgba(108, 92, 231, 0.2)`,\n borderRadius: \"4px\",\n padding: \"1rem\",\n color: \"#475161\",\n fontFamily: \"Inter, sans-serif\",\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"1rem\",\n \".header\": {\n display: \"flex\",\n alignItems: \"center\",\n gap: \"0.5rem\",\n },\n h3: {\n fontSize: \"14px\",\n fontWeight: 600,\n margin: 0,\n },\n p: {\n fontSize: \"1rem\",\n fontWeight: 400,\n lineHeight: \"24px\",\n letterSpacing: \"1%\",\n margin: 0,\n },\n }),\n welcomeContainer: css({\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n justifyContent: \"center\",\n padding: \"40px 20px\",\n textAlign: \"center\",\n minHeight: \"400px\",\n }),\n welcomeTitle: css({\n fontSize: \"20px\",\n fontWeight: \"600\",\n color: \"#475161\",\n margin: \"20px 0 10px 0\",\n fontFamily: \"Inter, sans-serif\",\n }),\n welcomeSubtitle: css({\n fontSize: \"14px\",\n color: \"#6E6B86\",\n margin: \"0 0 30px 0\",\n maxWidth: \"400px\",\n fontFamily: \"Inter, sans-serif\",\n lineHeight: \"1.5\",\n }),\n welcomeSteps: css({\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"16px\",\n maxWidth: \"1000px\",\n width: \"100%\",\n }),\n welcomeStep: css({\n padding: \"16px\",\n border: \"1px solid #DDE3EE\",\n borderRadius: \"8px\",\n textAlign: \"left\",\n \"& h3\": {\n fontSize: \"16px\",\n fontWeight: \"600\",\n color: \"#475161\",\n margin: \"0 0 8px 0\",\n fontFamily: \"Inter, sans-serif\",\n },\n \"& p\": {\n fontSize: \"14px\",\n color: \"#6E6B86\",\n margin: 0,\n fontFamily: \"Inter, sans-serif\",\n lineHeight: \"1.4\",\n },\n }),\n activeWelcomeStep: css({\n backgroundColor: \"#F9F8FF\",\n border: \"1px solid #6C5CE7\",\n }),\n});\n"],"names":[],"mappings":"MAEa,YAAY,GAAG,CAAC,GAAqB,MAAM;IACtD,UAAU,EAAE,GAAG,CAAC;AACd,QAAA,MAAM,EAAE,MAAM;AACd,QAAA,KAAK,EAAE,MAAM;AACb,QAAA,OAAO,EAAE,MAAM;AACf,QAAA,UAAU,EAAE,QAAQ;AACpB,QAAA,OAAO,EAAE,MAAM;AACf,QAAA,MAAM,EAAE,mBAAmB;KAC5B,CAAC;IACF,cAAc,EAAE,GAAG,CAAC;AAClB,QAAA,OAAO,EAAE,GAAG;KACb,CAAC;IACF,SAAS,EAAE,GAAG,CAAC;AACb,QAAA,MAAM,EAAE,MAAM;KACf,CAAC;IACF,SAAS,EAAE,GAAG,CAAC;AACb,QAAA,SAAS,EAAE,YAAY;;AAEvB,QAAA,MAAM,EAAE,MAAM;AACd,QAAA,OAAO,EAAE,MAAM;AACf,QAAA,GAAG,EAAE,KAAK;AACV,QAAA,UAAU,EAAE,QAAQ;AACpB,QAAA,cAAc,EAAE,QAAQ;AACxB,QAAA,MAAM,EAAE,oBAAoB;AAC5B,QAAA,KAAK,EAAE,SAAS;AAChB,QAAA,QAAQ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EAAE,GAAG,CAAC;AACnB,QAAA,QAAQ,EAAE,MAAM;AAChB,QAAA,KAAK,EAAE,SAAS;AAChB,QAAA,MAAM,EAAE,YAAY;AACpB,QAAA,QAAQ,EAAE,OAAO;AACjB,QAAA,UAAU,EAAE,mBAAmB;AAC/B,QAAA,UAAU,EAAE,KAAK;KAClB,CAAC;IACF,YAAY,EAAE,GAAG,CAAC;AAChB,QAAA,OAAO,EAAE,MAAM;AACf,QAAA,aAAa,EAAE,QAAQ;AACvB,QAAA,GAAG,EAAE,MAAM;AACX,QAAA,QAAQ,EAAE,QAAQ;AAClB,QAAA,KAAK,EAAE,MAAM;KACd,CAAC;IACF,WAAW,EAAE,GAAG,CAAC;AACf,QAAA,OAAO,EAAE,MAAM;AACf,QAAA,MAAM,EAAE,mBAAmB;AAC3B,QAAA,YAAY,EAAE,KAAK;AACnB,QAAA,SAAS,EAAE,MAAM;AACjB,QAAA,MAAM,EAAE;AACN,YAAA,QAAQ,EAAE,MAAM;AAChB,YAAA,UAAU,EAAE,KAAK;AACjB,YAAA,KAAK,EAAE,SAAS;AAChB,YAAA,MAAM,EAAE,WAAW;AACnB,YAAA,UAAU,EAAE,mBAAmB;AAChC,SAAA;AACD,QAAA,KAAK,EAAE;AACL,YAAA,QAAQ,EAAE,MAAM;AAChB,YAAA,KAAK,EAAE,SAAS;AAChB,YAAA,MAAM,EAAE,CAAC;AACT,YAAA,UAAU,EAAE,mBAAmB;AAC/B,YAAA,UAAU,EAAE,KAAK;AAClB,SAAA;KACF,CAAC;IACF,iBAAiB,EAAE,GAAG,CAAC;AACrB,QAAA,eAAe,EAAE,SAAS;AAC1B,QAAA,MAAM,EAAE,mBAAmB;KAC5B,CAAC;AACH,CAAA;;;;"}
|
|
@@ -13,6 +13,7 @@ const RendererProvider = (props) => {
|
|
|
13
13
|
return {
|
|
14
14
|
isCompositionBeingEdited: isCompositionEdited,
|
|
15
15
|
componentRegistry,
|
|
16
|
+
compositionPlacement: spec?.compositionEntry?.place_composition_as,
|
|
16
17
|
};
|
|
17
18
|
}, [spec, componentRegistry]);
|
|
18
19
|
return jsx(Provider, { value: value, children: children });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.provider.js","sources":["../../../src/contexts/providers/renderer.provider.tsx"],"sourcesContent":["import {\n StudioSpec,\n isCompositionBeingEdited,\n} from \"@contentstack/studio-client\";\nimport { createContext, FC, useMemo } from \"react\";\nimport { ComponentRegistryType } from \"../../types/renderer.type\";\n\ninterface RendererContext {\n isCompositionBeingEdited: boolean;\n componentRegistry: ComponentRegistryType;\n}\n\ninterface RendererProviderProps {\n componentRegistry: ComponentRegistryType;\n spec: StudioSpec;\n children: React.ReactNode;\n}\n\nexport const rendererContext = createContext<RendererContext>({\n isCompositionBeingEdited: false,\n} as RendererContext);\n\nconst { Provider } = rendererContext;\n\nexport const RendererProvider: FC<RendererProviderProps> = (props) => {\n const { children, spec, componentRegistry } = props;\n const value = useMemo(() => {\n const isCompositionEdited = isCompositionBeingEdited(\n spec?.compositionEntry?.composable_uid ?? \"\",\n );\n return {\n isCompositionBeingEdited: isCompositionEdited,\n componentRegistry,\n };\n }, [spec, componentRegistry]);\n return <Provider value={value}>{children}</Provider>;\n};\n"],"names":["_jsx"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"renderer.provider.js","sources":["../../../src/contexts/providers/renderer.provider.tsx"],"sourcesContent":["import {\n StudioSpec,\n isCompositionBeingEdited,\n type CompositionPlacement,\n} from \"@contentstack/studio-client\";\nimport { createContext, FC, useMemo } from \"react\";\nimport { ComponentRegistryType } from \"../../types/renderer.type\";\n\ninterface RendererContext {\n isCompositionBeingEdited: boolean;\n componentRegistry: ComponentRegistryType;\n compositionPlacement?: CompositionPlacement;\n}\n\ninterface RendererProviderProps {\n componentRegistry: ComponentRegistryType;\n spec: StudioSpec;\n children: React.ReactNode;\n}\n\nexport const rendererContext = createContext<RendererContext>({\n isCompositionBeingEdited: false,\n} as RendererContext);\n\nconst { Provider } = rendererContext;\n\nexport const RendererProvider: FC<RendererProviderProps> = (props) => {\n const { children, spec, componentRegistry } = props;\n const value = useMemo(() => {\n const isCompositionEdited = isCompositionBeingEdited(\n spec?.compositionEntry?.composable_uid ?? \"\",\n );\n return {\n isCompositionBeingEdited: isCompositionEdited,\n componentRegistry,\n compositionPlacement: spec?.compositionEntry?.place_composition_as,\n };\n }, [spec, componentRegistry]);\n return <Provider value={value}>{children}</Provider>;\n};\n"],"names":["_jsx"],"mappings":";;;;AAoBO,MAAM,eAAe,GAAG,aAAa,CAAkB;AAC5D,IAAA,wBAAwB,EAAE,KAAK;AACb,CAAA;AAEpB,MAAM,EAAE,QAAQ,EAAE,GAAG,eAAe;AAE7B,MAAM,gBAAgB,GAA8B,CAAC,KAAK,KAAI;IACnE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,KAAK;AACnD,IAAA,MAAM,KAAK,GAAG,OAAO,CAAC,MAAK;AACzB,QAAA,MAAM,mBAAmB,GAAG,wBAAwB,CAClD,IAAI,EAAE,gBAAgB,EAAE,cAAc,IAAI,EAAE,CAC7C;QACD,OAAO;AACL,YAAA,wBAAwB,EAAE,mBAAmB;YAC7C,iBAAiB;AACjB,YAAA,oBAAoB,EAAE,IAAI,EAAE,gBAAgB,EAAE,oBAAoB;SACnE;AACH,IAAA,CAAC,EAAE,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IAC7B,OAAOA,GAAA,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAY;AACtD;;;;"}
|
|
@@ -4,14 +4,20 @@ 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
|
|
8
|
-
import
|
|
7
|
+
import '@contentstack/studio-internal';
|
|
8
|
+
import '@contentstack/studio-core';
|
|
9
|
+
import '@contentstack/studio-react-components/basic-components';
|
|
10
|
+
import '@contentstack/studio-react-components/hooks';
|
|
11
|
+
import 'goober';
|
|
12
|
+
import '../../components/Element.js';
|
|
9
13
|
import './renderer.provider.js';
|
|
10
14
|
import './active-node.provider.js';
|
|
11
15
|
import './use-design-preview.provider.js';
|
|
12
16
|
import './use-repeater.provider.js';
|
|
13
17
|
import './use-condition-block.provider.js';
|
|
14
18
|
import './preview-mode.provider.js';
|
|
19
|
+
import { useRenderer } from '../../hooks/use-renderer.hook.js';
|
|
20
|
+
import { registerSymbolComponent } from '../../hooks/use-register-symbol.hook.js';
|
|
15
21
|
|
|
16
22
|
const SymbolUIProvider = ({ symbols, children, }) => {
|
|
17
23
|
const { componentRegistry } = useRenderer();
|
|
@@ -20,11 +26,17 @@ const SymbolUIProvider = ({ symbols, children, }) => {
|
|
|
20
26
|
return acc;
|
|
21
27
|
}, {}));
|
|
22
28
|
useEffect(() => {
|
|
23
|
-
|
|
24
|
-
acc
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
if (symbols.length > 0) {
|
|
30
|
+
setSymbolUIs(symbols.reduce((acc, symbol) => {
|
|
31
|
+
acc[symbol.uid] = symbol;
|
|
32
|
+
return acc;
|
|
33
|
+
}, {}));
|
|
34
|
+
}
|
|
27
35
|
}, [symbols]);
|
|
36
|
+
// UPDATE_SYMBOLS / GET_SYMBOLS are handled by use-symbol-events.hook.ts,
|
|
37
|
+
// which updates `state.symbols` — that flows down here as the `symbols`
|
|
38
|
+
// prop and is picked up by the useEffect above. Registering another
|
|
39
|
+
// listener here just produced a duplicate-registration warning.
|
|
28
40
|
useEffect(() => {
|
|
29
41
|
const handleApplySymbolOperation = (data) => {
|
|
30
42
|
const { uid, operations } = data;
|
|
@@ -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 setSymbolUIs(\n
|
|
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,i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ger';
|
|
7
7
|
import '@contentstack/studio-react-components/contexts';
|
|
8
8
|
import 'immer';
|
|
9
|
+
import '@contentstack/studio-internal';
|
|
10
|
+
import '@contentstack/studio-core';
|
|
11
|
+
import '@contentstack/studio-react-components/basic-components';
|
|
9
12
|
import '@contentstack/studio-react-components/hooks';
|
|
10
|
-
import '
|
|
13
|
+
import 'goober';
|
|
11
14
|
import '../components/Element.js';
|
|
15
|
+
import '@contentstack/studio-registry';
|
|
12
16
|
import '../contexts/providers/use-design-preview.provider.js';
|
|
13
17
|
import '../contexts/providers/use-repeater.provider.js';
|
|
14
18
|
import '../contexts/providers/use-condition-block.provider.js';
|