@contentstack/studio-react-editor 0.0.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/README.md +11 -0
- package/dist/components/EditableRenderer.js +92 -0
- package/dist/components/EditableRenderer.js.map +1 -0
- package/dist/components/Element.js +235 -0
- package/dist/components/Element.js.map +1 -0
- package/dist/components/ErrorComponent.js +13 -0
- package/dist/components/ErrorComponent.js.map +1 -0
- package/dist/components/PreviewRenderer.js +23 -0
- package/dist/components/PreviewRenderer.js.map +1 -0
- package/dist/components/RenderErrorHOC.js +21 -0
- package/dist/components/RenderErrorHOC.js.map +1 -0
- package/dist/components/RendererErrorBoundary.js +18 -0
- package/dist/components/RendererErrorBoundary.js.map +1 -0
- package/dist/components/Slot.js +18 -0
- package/dist/components/Slot.js.map +1 -0
- package/dist/components/TextPlaceholder.js +29 -0
- package/dist/components/TextPlaceholder.js.map +1 -0
- package/dist/components/elements/ConditionBlock.js +62 -0
- package/dist/components/elements/ConditionBlock.js.map +1 -0
- package/dist/components/elements/Repeater.js +70 -0
- package/dist/components/elements/Repeater.js.map +1 -0
- package/dist/components/elements/Symbol.js +58 -0
- package/dist/components/elements/Symbol.js.map +1 -0
- package/dist/components/styles.js +77 -0
- package/dist/components/styles.js.map +1 -0
- package/dist/contexts/providers/active-node.provider.js +9 -0
- package/dist/contexts/providers/active-node.provider.js.map +1 -0
- package/dist/contexts/providers/preview-mode.provider.js +6 -0
- package/dist/contexts/providers/preview-mode.provider.js.map +1 -0
- package/dist/contexts/providers/renderer.provider.js +22 -0
- package/dist/contexts/providers/renderer.provider.js.map +1 -0
- package/dist/contexts/providers/selected-node.provider.js +11 -0
- package/dist/contexts/providers/selected-node.provider.js.map +1 -0
- package/dist/contexts/providers/symbol-ui.provider.js +73 -0
- package/dist/contexts/providers/symbol-ui.provider.js.map +1 -0
- package/dist/contexts/providers/use-condition-block.provider.js +8 -0
- package/dist/contexts/providers/use-condition-block.provider.js.map +1 -0
- package/dist/contexts/providers/use-design-preview.provider.js +6 -0
- package/dist/contexts/providers/use-design-preview.provider.js.map +1 -0
- package/dist/contexts/providers/use-repeater.provider.js +6 -0
- package/dist/contexts/providers/use-repeater.provider.js.map +1 -0
- package/dist/hooks/use-active-node-path.hook.js +46 -0
- package/dist/hooks/use-active-node-path.hook.js.map +1 -0
- package/dist/hooks/use-canvas-events.hook.js +39 -0
- package/dist/hooks/use-canvas-events.hook.js.map +1 -0
- package/dist/hooks/use-condition-block-context.js +20 -0
- package/dist/hooks/use-condition-block-context.js.map +1 -0
- package/dist/hooks/use-design-preview.hook.js +20 -0
- package/dist/hooks/use-design-preview.hook.js.map +1 -0
- package/dist/hooks/use-is-node-selected.js +26 -0
- package/dist/hooks/use-is-node-selected.js.map +1 -0
- package/dist/hooks/use-preview-mode.hook.js +22 -0
- package/dist/hooks/use-preview-mode.hook.js.map +1 -0
- package/dist/hooks/use-register-symbol.hook.js +54 -0
- package/dist/hooks/use-register-symbol.hook.js.map +1 -0
- package/dist/hooks/use-renderer.hook.js +23 -0
- package/dist/hooks/use-renderer.hook.js.map +1 -0
- package/dist/hooks/use-repeater.hook.js +20 -0
- package/dist/hooks/use-repeater.hook.js.map +1 -0
- package/dist/hooks/use-should-show-design.hook.js +31 -0
- package/dist/hooks/use-should-show-design.hook.js.map +1 -0
- package/dist/hooks/use-spec-data-listener.hook.js +65 -0
- package/dist/hooks/use-spec-data-listener.hook.js.map +1 -0
- package/dist/hooks/use-static-values-listener.hook.js +33 -0
- package/dist/hooks/use-static-values-listener.hook.js.map +1 -0
- package/dist/hooks/use-symbol-events.hook.js +32 -0
- package/dist/hooks/use-symbol-events.hook.js.map +1 -0
- package/dist/hooks/use-symbol-ui-listener.hook.js +17 -0
- package/dist/hooks/use-symbol-ui-listener.hook.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/renderer.util.js +12 -0
- package/dist/utils/renderer.util.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { evaluateCondition } from '@contentstack/studio-client';
|
|
3
|
+
import { getBindingString, getRepeaterContextPath } from '@contentstack/studio-registry';
|
|
4
|
+
import { produce } from 'immer';
|
|
5
|
+
import { get, set } from 'lodash-es';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { DataCtxProvider } from '@contentstack/studio-react-components/contexts';
|
|
8
|
+
import { useData } from '@contentstack/studio-react-components/hooks';
|
|
9
|
+
import '../../contexts/providers/renderer.provider.js';
|
|
10
|
+
import '../../contexts/providers/active-node.provider.js';
|
|
11
|
+
import '@contentstack/studio-messenger';
|
|
12
|
+
import '../Element.js';
|
|
13
|
+
import { useShouldShowDesign } from '../../hooks/use-should-show-design.hook.js';
|
|
14
|
+
import { DesignPreviewContext } from '../../contexts/providers/use-design-preview.provider.js';
|
|
15
|
+
import '../../contexts/providers/use-repeater.provider.js';
|
|
16
|
+
import { ConditionBlockContext } from '../../contexts/providers/use-condition-block.provider.js';
|
|
17
|
+
import '../../contexts/providers/preview-mode.provider.js';
|
|
18
|
+
|
|
19
|
+
function ConditionBlock({ condition, children, mode, studioAttributes, }) {
|
|
20
|
+
const showDesign = useShouldShowDesign(mode);
|
|
21
|
+
if (showDesign) {
|
|
22
|
+
return (jsx(ConditionBlockContext.Provider, { value: { isInsideConditionBlock: true }, children: jsx(DesignPreviewContext.Provider, { value: "design", children: jsx("div", { ...studioAttributes, style: { display: "contents" }, children: children }) }) }));
|
|
23
|
+
}
|
|
24
|
+
return (jsx(ConditionPreview, { condition: condition, studioAttributes: studioAttributes, children: children }));
|
|
25
|
+
}
|
|
26
|
+
function ConditionPreview({ condition, children, studioAttributes, }) {
|
|
27
|
+
const data = useData();
|
|
28
|
+
if (!condition)
|
|
29
|
+
return null;
|
|
30
|
+
let conditionAppliedData = data;
|
|
31
|
+
const { dataBinding: binding } = condition;
|
|
32
|
+
let shouldRender = evaluateCondition(condition, conditionAppliedData);
|
|
33
|
+
const dataPath = binding && getBindingString(binding);
|
|
34
|
+
const repeaterPath = binding &&
|
|
35
|
+
getRepeaterContextPath(binding.value);
|
|
36
|
+
if (dataPath) {
|
|
37
|
+
const conditionalData = get(data, dataPath);
|
|
38
|
+
if (conditionalData && repeaterPath) {
|
|
39
|
+
conditionAppliedData = produce(data, (draft) => {
|
|
40
|
+
set(draft, repeaterPath, conditionalData);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const { "data-cslp": dataCslp, ...rest } = studioAttributes || {};
|
|
45
|
+
const conditionCSLP = {
|
|
46
|
+
dataCslp: dataCslp,
|
|
47
|
+
};
|
|
48
|
+
const childrenWithCSLP = React.Children.map(children, (child, index) => {
|
|
49
|
+
const newProps = index === 0 ? conditionCSLP : {};
|
|
50
|
+
if (React.isValidElement(child)) {
|
|
51
|
+
return React.cloneElement(child, {
|
|
52
|
+
key: index,
|
|
53
|
+
...newProps,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
// Only render children if condition is met
|
|
58
|
+
return shouldRender ? (jsx(ConditionBlockContext.Provider, { value: { isInsideConditionBlock: true }, children: jsx(DesignPreviewContext.Provider, { value: "preview", children: jsx(DataCtxProvider, { value: conditionAppliedData, children: jsx("div", { ...rest, style: { display: "contents" }, children: childrenWithCSLP }) }) }) })) : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { ConditionBlock };
|
|
62
|
+
//# sourceMappingURL=ConditionBlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionBlock.js","sources":["../../../src/components/elements/ConditionBlock.tsx"],"sourcesContent":["import { evaluateCondition } from \"@contentstack/studio-client\";\nimport { Condition } from \"@contentstack/studio-internal\";\nimport {\n getBindingString,\n getRepeaterContextPath,\n RepeaterBindingValue,\n} from \"@contentstack/studio-registry\";\nimport { produce } from \"immer\";\nimport { get, set } from \"lodash-es\";\nimport React from \"react\";\nimport { DataCtxProvider } from \"@contentstack/studio-react-components/contexts\";\nimport { useData } from \"@contentstack/studio-react-components/hooks\";\nimport {\n ConditionBlockContext,\n DesignPreviewContext,\n} from \"../../contexts/providers\";\nimport { useShouldShowDesign } from \"../../hooks\";\n\ninterface ConditionBlockProps {\n condition: Condition;\n children: React.ReactNode;\n mode: \"design\" | \"preview\";\n studioAttributes: any;\n}\n\nexport function ConditionBlock({\n condition,\n children,\n mode,\n studioAttributes,\n}: ConditionBlockProps) {\n const showDesign = useShouldShowDesign(mode);\n\n if (showDesign) {\n return (\n <ConditionBlockContext.Provider value={{ isInsideConditionBlock: true }}>\n <DesignPreviewContext.Provider value=\"design\">\n <div {...studioAttributes} style={{ display: \"contents\" }}>\n {children}\n </div>\n </DesignPreviewContext.Provider>\n </ConditionBlockContext.Provider>\n );\n }\n return (\n <ConditionPreview condition={condition} studioAttributes={studioAttributes}>\n {children}\n </ConditionPreview>\n );\n}\n\nfunction ConditionPreview({\n condition,\n children,\n studioAttributes,\n}: Omit<ConditionBlockProps, \"mode\">) {\n const data = useData();\n if (!condition) return null;\n let conditionAppliedData = data;\n const { dataBinding: binding } = condition;\n let shouldRender = evaluateCondition(condition, conditionAppliedData);\n const dataPath = binding && getBindingString(binding);\n const repeaterPath =\n binding &&\n getRepeaterContextPath(binding.value as unknown as RepeaterBindingValue);\n if (dataPath) {\n const conditionalData = get(data, dataPath);\n if (conditionalData && repeaterPath) {\n conditionAppliedData = produce(data, (draft) => {\n set(draft, repeaterPath, conditionalData);\n });\n }\n }\n const { \"data-cslp\": dataCslp, ...rest } = studioAttributes || {};\n\n const conditionCSLP = {\n dataCslp: dataCslp,\n };\n const childrenWithCSLP = React.Children.map(children, (child, index) => {\n const newProps = index === 0 ? conditionCSLP : {};\n if (React.isValidElement(child)) {\n return React.cloneElement(child, {\n key: index,\n ...newProps,\n });\n }\n });\n // Only render children if condition is met\n return shouldRender ? (\n <ConditionBlockContext.Provider value={{ isInsideConditionBlock: true }}>\n <DesignPreviewContext.Provider value=\"preview\">\n <DataCtxProvider value={conditionAppliedData}>\n <div {...rest} style={{ display: \"contents\" }}>\n {childrenWithCSLP}\n </div>\n </DataCtxProvider>\n </DesignPreviewContext.Provider>\n </ConditionBlockContext.Provider>\n ) : null;\n}\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;AAyBM,SAAU,cAAc,CAAC,EAC7B,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,gBAAgB,GACI,EAAA;AACpB,IAAA,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,CAAC;IAE5C,IAAI,UAAU,EAAE;AACd,QAAA,QACEA,GAAA,CAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,sBAAsB,EAAE,IAAI,EAAE,YACrEA,GAAA,CAAC,oBAAoB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAC,QAAQ,EAAA,QAAA,EAC3CA,GAAA,CAAA,KAAA,EAAA,EAAA,GAAS,gBAAgB,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAA,QAAA,EACtD,QAAQ,GACL,EAAA,CACwB,EAAA,CACD;IAErC;AACA,IAAA,QACEA,GAAA,CAAC,gBAAgB,EAAA,EAAC,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,EAAA,QAAA,EACvE,QAAQ,EAAA,CACQ;AAEvB;AAEA,SAAS,gBAAgB,CAAC,EACxB,SAAS,EACT,QAAQ,EACR,gBAAgB,GACkB,EAAA;AAClC,IAAA,MAAM,IAAI,GAAG,OAAO,EAAE;AACtB,IAAA,IAAI,CAAC,SAAS;AAAE,QAAA,OAAO,IAAI;IAC3B,IAAI,oBAAoB,GAAG,IAAI;AAC/B,IAAA,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,SAAS;IAC1C,IAAI,YAAY,GAAG,iBAAiB,CAAC,SAAS,EAAE,oBAAoB,CAAC;I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AA,EAAC,KAAK,EAAE,oBAAoB,EAAA,QAAA,EAC1CA,GAAA,CAAA,KAAA,EAAA,EAAA,GAAS,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAA,QAAA,EAC1C,gBAAgB,EAAA,CACb,EAAA,CACU,EAAA,CACY,EAAA,CACD,IAC/B,IAAI;AACV;;;;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { DataCtxProvider } from '@contentstack/studio-react-components/contexts';
|
|
3
|
+
import { useData } from '@contentstack/studio-react-components/hooks';
|
|
4
|
+
import { Children, isValidElement, cloneElement } from 'react';
|
|
5
|
+
import '../../contexts/providers/renderer.provider.js';
|
|
6
|
+
import '../../contexts/providers/active-node.provider.js';
|
|
7
|
+
import '@contentstack/studio-client';
|
|
8
|
+
import '@contentstack/studio-messenger';
|
|
9
|
+
import 'immer';
|
|
10
|
+
import '@contentstack/studio-registry';
|
|
11
|
+
import '../Element.js';
|
|
12
|
+
import { useShouldShowDesign } from '../../hooks/use-should-show-design.hook.js';
|
|
13
|
+
import { DesignPreviewContext } from '../../contexts/providers/use-design-preview.provider.js';
|
|
14
|
+
import { RepeaterContext } from '../../contexts/providers/use-repeater.provider.js';
|
|
15
|
+
import '../../contexts/providers/use-condition-block.provider.js';
|
|
16
|
+
import '../../contexts/providers/preview-mode.provider.js';
|
|
17
|
+
|
|
18
|
+
function RepeaterPreview({ children, studioAttributes, items = [], _uid, $items, }) {
|
|
19
|
+
const data = useData();
|
|
20
|
+
// Get uid from builder attributes or generate a fallback
|
|
21
|
+
const uid = _uid || studioAttributes?.["data-composable-studio-id"] || "default";
|
|
22
|
+
return (jsx(RepeaterContext.Provider, { value: { isInsideRepeater: true }, children: jsx(DesignPreviewContext.Provider, { value: "preview", children: items.map((item, index) => {
|
|
23
|
+
// Create a new data context for each item with uid in path
|
|
24
|
+
const itemContext = {
|
|
25
|
+
...data,
|
|
26
|
+
dataSources: {
|
|
27
|
+
...data?.dataSources,
|
|
28
|
+
repeater: {
|
|
29
|
+
[uid]: {
|
|
30
|
+
context: item,
|
|
31
|
+
index,
|
|
32
|
+
},
|
|
33
|
+
...data?.dataSources?.repeater,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const instanceCSLP = {};
|
|
38
|
+
if ($items) {
|
|
39
|
+
instanceCSLP.dataCslp = `${$items["data-cslp"]}.${index}`;
|
|
40
|
+
}
|
|
41
|
+
// Clone children with the new context
|
|
42
|
+
const childrenWithCSLP = Children.map(children, (child) => {
|
|
43
|
+
if (isValidElement(child)) {
|
|
44
|
+
return cloneElement(child, {
|
|
45
|
+
...instanceCSLP,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return (
|
|
50
|
+
//TODO: Handle key with slot uid and support cslp tags
|
|
51
|
+
jsx(DataCtxProvider, { value: itemContext, children: jsx("div", { ...studioAttributes, style: { display: "contents" }, children: childrenWithCSLP }) }, `${uid}-${index}`));
|
|
52
|
+
}) }) }));
|
|
53
|
+
}
|
|
54
|
+
// Optimize repeater
|
|
55
|
+
function Repeater({ children, studioAttributes, items = [], _uid, mode, $items, }) {
|
|
56
|
+
const showDesign = useShouldShowDesign(mode);
|
|
57
|
+
if (!Array.isArray(items)) {
|
|
58
|
+
console.warn("Repeater items is not an array:", items);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
// In canvas
|
|
62
|
+
if (showDesign) {
|
|
63
|
+
return (jsx(RepeaterContext.Provider, { value: { isInsideRepeater: true }, children: jsx(DesignPreviewContext.Provider, { value: "design", children: jsx("div", { ...studioAttributes, style: { display: "contents" }, children: children }) }) }));
|
|
64
|
+
}
|
|
65
|
+
// Production renderer or mode === "preview"
|
|
66
|
+
return (jsx(RepeaterPreview, { items: items, children: children, studioAttributes: studioAttributes, _uid: _uid, "$items": $items }));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { Repeater };
|
|
70
|
+
//# sourceMappingURL=Repeater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Repeater.js","sources":["../../../src/components/elements/Repeater.tsx"],"sourcesContent":["import { DataCtxProvider } from \"@contentstack/studio-react-components/contexts\";\nimport { useData } from \"@contentstack/studio-react-components/hooks\";\nimport React, { Children, cloneElement, isValidElement } from \"react\";\nimport {\n DesignPreviewContext,\n RepeaterContext,\n} from \"../../contexts/providers\";\nimport { useShouldShowDesign } from \"../../hooks\";\n\ntype CSLP = { \"data-cslp\": string };\ninterface RepeaterProps {\n children: React.ReactNode;\n studioAttributes?: any;\n items?: any[];\n data?: any;\n _uid: string;\n mode: \"design\" | \"preview\";\n $items?: CSLP;\n}\n\nfunction RepeaterPreview({\n children,\n studioAttributes,\n items = [],\n _uid,\n $items,\n}: Omit<RepeaterProps, \"mode\">) {\n const data = useData();\n // Get uid from builder attributes or generate a fallback\n const uid =\n _uid || studioAttributes?.[\"data-composable-studio-id\"] || \"default\";\n return (\n <RepeaterContext.Provider value={{ isInsideRepeater: true }}>\n <DesignPreviewContext.Provider value=\"preview\">\n {items.map((item, index) => {\n // Create a new data context for each item with uid in path\n const itemContext = {\n ...data,\n dataSources: {\n ...data?.dataSources,\n repeater: {\n [uid]: {\n context: item,\n index,\n },\n ...data?.dataSources?.repeater,\n },\n },\n };\n const instanceCSLP: any = {};\n if ($items) {\n instanceCSLP.dataCslp = `${$items[\"data-cslp\"]}.${index}`;\n }\n\n // Clone children with the new context\n const childrenWithCSLP = Children.map(children, (child) => {\n if (isValidElement(child)) {\n return cloneElement(child, {\n ...instanceCSLP,\n });\n }\n });\n return (\n //TODO: Handle key with slot uid and support cslp tags\n <DataCtxProvider value={itemContext} key={`${uid}-${index}`}>\n <div {...studioAttributes} style={{ display: \"contents\" }}>\n {childrenWithCSLP}\n </div>\n </DataCtxProvider>\n );\n })}\n </DesignPreviewContext.Provider>\n </RepeaterContext.Provider>\n );\n}\n\n// Optimize repeater\nexport function Repeater({\n children,\n studioAttributes,\n items = [],\n _uid,\n mode,\n $items,\n}: RepeaterProps) {\n const showDesign = useShouldShowDesign(mode);\n\n if (!Array.isArray(items)) {\n console.warn(\"Repeater items is not an array:\", items);\n return null;\n }\n\n // In canvas\n if (showDesign) {\n return (\n <RepeaterContext.Provider value={{ isInsideRepeater: true }}>\n <DesignPreviewContext.Provider value=\"design\">\n <div {...studioAttributes} style={{ display: \"contents\" }}>\n {children}\n </div>\n </DesignPreviewContext.Provider>\n </RepeaterContext.Provider>\n );\n }\n // Production renderer or mode === \"preview\"\n return (\n <RepeaterPreview\n items={items}\n children={children}\n studioAttributes={studioAttributes}\n _uid={_uid}\n $items={$items}\n />\n );\n}\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,SAAS,eAAe,CAAC,EACvB,QAAQ,EACR,gBAAgB,EAChB,KAAK,GAAG,EAAE,EACV,IAAI,EACJ,MAAM,GACsB,EAAA;AAC5B,IAAA,MAAM,IAAI,GAAG,OAAO,EAAE;;IAEtB,MAAM,GAAG,GACP,IAAI,IAAI,gBAAgB,GAAG,2BAA2B,CAAC,IAAI,SAAS;AACtE,IAAA,QACEA,GAAA,CAAC,eAAe,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,YACzDA,GAAA,CAAC,oBAAoB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAC,SAAS,YAC3C,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,KAAI;;AAEzB,gBAAA,MAAM,WAAW,GAAG;AAClB,oBAAA,GAAG,IAAI;AACP,oBAAA,WAAW,EAAE;wBACX,GAAG,IAAI,EAAE,WAAW;AACpB,wBAAA,QAAQ,EAAE;4BACR,CAAC,GAAG,GAAG;AACL,gCAAA,OAAO,EAAE,IAAI;gCACb,KAAK;AACN,6BAAA;AACD,4BAAA,GAAG,IAAI,EAAE,WAAW,EAAE,QAAQ;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AAE,IAAI,EAAE,YACzDA,GAAA,CAAC,oBAAoB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAC,QAAQ,EAAA,QAAA,EAC3CA,GAAA,CAAA,KAAA,EAAA,EAAA,GAAS,gBAAgB,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAA,QAAA,EACtD,QAAQ,GACL,EAAA,CACwB,EAAA,CACP;IAE/B;;IAEA,QACEA,IAAC,eAAe,EAAA,EACd,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,gBAAgB,EAClC,IAAI,EAAE,IAAI,EAAA,QAAA,EACF,MAAM,EAAA,CACd;AAEN;;;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { DataCtxProvider } from '@contentstack/studio-react-components/contexts';
|
|
3
|
+
import { useData } from '@contentstack/studio-react-components/hooks';
|
|
4
|
+
import { DATA_SOURCES } from '@contentstack/studio-registry';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
import '@contentstack/studio-client';
|
|
7
|
+
import '../../contexts/providers/renderer.provider.js';
|
|
8
|
+
import '../../contexts/providers/active-node.provider.js';
|
|
9
|
+
import '@contentstack/studio-messenger';
|
|
10
|
+
import 'immer';
|
|
11
|
+
import '../../contexts/providers/use-design-preview.provider.js';
|
|
12
|
+
import '../../contexts/providers/use-repeater.provider.js';
|
|
13
|
+
import '../../contexts/providers/use-condition-block.provider.js';
|
|
14
|
+
import '../../contexts/providers/preview-mode.provider.js';
|
|
15
|
+
import { PreviewRenderer } from '../PreviewRenderer.js';
|
|
16
|
+
import { useSymbolUIListener } from '../../hooks/use-symbol-ui-listener.hook.js';
|
|
17
|
+
|
|
18
|
+
function EditSymbolRenderer({ ui, studioAttributes, }) {
|
|
19
|
+
return (jsx("div", { ...studioAttributes, style: { display: "contents" }, children: ui }));
|
|
20
|
+
}
|
|
21
|
+
function ViewOnlySymbolRenderer({ symbolUID, spec, studioAttributes, }) {
|
|
22
|
+
const activeSpec = useSymbolUIListener(spec, symbolUID);
|
|
23
|
+
const data = useData();
|
|
24
|
+
// 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
|
|
25
|
+
const activeSpecWithoutSymbolWrapper = useMemo(() => {
|
|
26
|
+
const ui = activeSpec.ui;
|
|
27
|
+
const uiWithFragment = {
|
|
28
|
+
...ui,
|
|
29
|
+
type: "fragment",
|
|
30
|
+
slots: ui.slots,
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
...activeSpec,
|
|
34
|
+
data,
|
|
35
|
+
ui: uiWithFragment,
|
|
36
|
+
};
|
|
37
|
+
}, [activeSpec, data]);
|
|
38
|
+
return (jsx("div", { ...studioAttributes, style: { display: "contents" }, children: jsx(PreviewRenderer, { spec: activeSpecWithoutSymbolWrapper }) }));
|
|
39
|
+
}
|
|
40
|
+
function WithSymbolPropsData(props) {
|
|
41
|
+
const data = useData();
|
|
42
|
+
// Can't memoize it because data doesn't change when symbol changes
|
|
43
|
+
const dataWithSymbol = {
|
|
44
|
+
...data,
|
|
45
|
+
[DATA_SOURCES.SYMBOL_PROPS]: {
|
|
46
|
+
...(data[DATA_SOURCES.SYMBOL_PROPS] || {}),
|
|
47
|
+
...(props.symbol_props || {}),
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
return (jsx(DataCtxProvider, { value: dataWithSymbol, children: props.children }));
|
|
51
|
+
}
|
|
52
|
+
function Symbol(props) {
|
|
53
|
+
const isEditing = props.symbol_internal_props?.isEditing;
|
|
54
|
+
return (jsx(WithSymbolPropsData, { ...props, children: !isEditing ? (jsx(ViewOnlySymbolRenderer, { ...props })) : (jsx(EditSymbolRenderer, { ...props })) }));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { EditSymbolRenderer, Symbol, ViewOnlySymbolRenderer };
|
|
58
|
+
//# sourceMappingURL=Symbol.js.map
|
|
@@ -0,0 +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":";;;;;;;;;;;;;;;;;SAsBgB,kBAAkB,CAAC,EACjC,EAAE,EACF,gBAAgB,GACQ,EAAA;AACxB,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAA,GAAS,gBAAgB,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAA,QAAA,EACtD,EAAE,EAAA,CACC;AAEV;AAaM,SAAU,sBAAsB,CAAC,EACrC,SAAS,EACT,IAAI,EACJ,gBAAgB,GACY,EAAA;IAC5B,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,EAAE,SAAS,CAAC;AACvD,IAAA,MAAM,IAAI,GAAG,OAAO,EAAE;;AAEtB,IAAA,MAAM,8BAA8B,GAAG,OAAO,CAAC,MAAK;AAClD,QAAA,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE;AACxB,QAAA,MAAM,cAAc,GAAG;AACrB,YAAA,GAAG,EAAE;AACL,YAAA,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,EAAE,CAAC,KAAK;SAChB;QACD,OAAO;AACL,YAAA,GAAG,UAAU;YACb,IAAI;AACJ,YAAA,EAAE,EAAE,cAAc;SACnB;AACH,IAAA,CAAC,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACtB,QACEA,gBAAS,gBAAgB,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAA,QAAA,EACvDA,GAAA,CAAC,eAAe,EAAA,EAAC,IAAI,EAAE,8BAA8B,EAAA,CAAI,EAAA,CACrD;AAEV;AAIA,SAAS,mBAAmB,CAAC,KAAkB,EAAA;AAC7C,IAAA,MAAM,IAAI,GAAG,OAAO,EAAE;;AAEtB,IAAA,MAAM,cAAc,GAAG;AACrB,QAAA,GAAG,IAAI;AACP,QAAA,CAAC,YAAY,CAAC,YAAY,GAAG;YAC3B,IAAI,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;AAC1C,YAAA,IAAI,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC;AAC9B,SAAA;KACF;AACD,IAAA,QACEA,GAAA,CAAC,eAAe,EAAA,EAAC,KAAK,EAAE,cAAc,EAAA,QAAA,EAAG,KAAK,CAAC,QAAQ,EAAA,CAAmB;AAE9E;AACM,SAAU,MAAM,CAAC,KAAkB,EAAA;AACvC,IAAA,MAAM,SAAS,GAAG,KAAK,CAAC,qBAAqB,EAAE,SAAS;AACxD,IAAA,QACEA,GAAA,CAAC,mBAAmB,EAAA,EAAA,GAAK,KAAK,EAAA,QAAA,EAC3B,CAAC,SAAS,IACTA,IAAC,sBAAsB,EAAA,EAAA,GAAM,KAAqC,EAAA,CAAI,KAEtEA,GAAA,CAAC,kBAAkB,EAAA,EAAA,GAAM,KAAiC,EAAA,CAAI,CAC/D,EAAA,CACmB;AAE1B;;;;"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const styleFactory = (css) => ({
|
|
2
|
+
embedStyle: css({
|
|
3
|
+
height: "100%",
|
|
4
|
+
width: "100%",
|
|
5
|
+
display: "grid",
|
|
6
|
+
placeItems: "center",
|
|
7
|
+
padding: "1rem",
|
|
8
|
+
border: "1px solid #dde3ee",
|
|
9
|
+
}),
|
|
10
|
+
embedIconStyle: css({
|
|
11
|
+
opacity: 0.5,
|
|
12
|
+
}),
|
|
13
|
+
pageStyle: css({
|
|
14
|
+
height: "100%",
|
|
15
|
+
}),
|
|
16
|
+
slotStyle: css({
|
|
17
|
+
boxSizing: "border-box",
|
|
18
|
+
// width: "100%",
|
|
19
|
+
height: "100%",
|
|
20
|
+
display: "flex",
|
|
21
|
+
gap: "4px",
|
|
22
|
+
alignItems: "center",
|
|
23
|
+
justifyContent: "center",
|
|
24
|
+
border: "1px dashed #6c5ce7",
|
|
25
|
+
color: "#475161",
|
|
26
|
+
fontSize: "14px",
|
|
27
|
+
fontStyle: "normal",
|
|
28
|
+
fontWeight: 400,
|
|
29
|
+
lineHeight: "24px",
|
|
30
|
+
userSelect: "none",
|
|
31
|
+
fontFamily: "Inter",
|
|
32
|
+
paddingInline: "2rem",
|
|
33
|
+
paddingBlock: "1rem",
|
|
34
|
+
transition: "background-color 0.3s ease",
|
|
35
|
+
}),
|
|
36
|
+
slotContentStyle: css({
|
|
37
|
+
marginBottom: 0,
|
|
38
|
+
marginTop: 0,
|
|
39
|
+
}),
|
|
40
|
+
rendererErrorComponent: css({
|
|
41
|
+
boxSizing: "border-box",
|
|
42
|
+
backgroundColor: "#fff0ed",
|
|
43
|
+
borderWidth: "1px",
|
|
44
|
+
borderStyle: "solid",
|
|
45
|
+
borderColor: "#fdafa3",
|
|
46
|
+
boxShadow: `0px 2px 4px rgba(0, 0, 0, 0.14),
|
|
47
|
+
0px 5px 5px rgba(0, 0, 0, 0.12),
|
|
48
|
+
0px 1px 10px rgba(108, 92, 231, 0.2)`,
|
|
49
|
+
borderRadius: "4px",
|
|
50
|
+
padding: "1rem",
|
|
51
|
+
color: "#475161",
|
|
52
|
+
fontFamily: "Inter, sans-serif",
|
|
53
|
+
display: "flex",
|
|
54
|
+
flexDirection: "column",
|
|
55
|
+
gap: "1rem",
|
|
56
|
+
".header": {
|
|
57
|
+
display: "flex",
|
|
58
|
+
alignItems: "center",
|
|
59
|
+
gap: "0.5rem",
|
|
60
|
+
},
|
|
61
|
+
h3: {
|
|
62
|
+
fontSize: "14px",
|
|
63
|
+
fontWeight: 600,
|
|
64
|
+
margin: 0,
|
|
65
|
+
},
|
|
66
|
+
p: {
|
|
67
|
+
fontSize: "1rem",
|
|
68
|
+
fontWeight: 400,
|
|
69
|
+
lineHeight: "24px",
|
|
70
|
+
letterSpacing: "1%",
|
|
71
|
+
margin: 0,
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export { styleFactory };
|
|
77
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +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,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,EAAE,MAAM;AAChB,QAAA,SAAS,EAAE,QAAQ;AACnB,QAAA,UAAU,EAAE,GAAG;AACf,QAAA,UAAU,EAAE,MAAM;AAClB,QAAA,UAAU,EAAE,MAAM;AAClB,QAAA,UAAU,EAAE,OAAO;AACnB,QAAA,aAAa,EAAE,MAAM;AACrB,QAAA,YAAY,EAAE,MAAM;AACpB,QAAA,UAAU,EAAE,4BAA4B;KACzC,CAAC;IACF,gBAAgB,EAAE,GAAG,CAAC;AACpB,QAAA,YAAY,EAAE,CAAC;AACf,QAAA,SAAS,EAAE,CAAC;KACb,CAAC;IACF,sBAAsB,EAAE,GAAG,CAAC;AAC1B,QAAA,SAAS,EAAE,YAAY;AACvB,QAAA,eAAe,EAAE,SAAS;AAC1B,QAAA,WAAW,EAAE,KAAK;AAClB,QAAA,WAAW,EAAE,OAAO;AACpB,QAAA,WAAW,EAAE,SAAS;AACtB,QAAA,SAAS,EAAE,CAAA;;AAE4B,0CAAA,CAAA;AACvC,QAAA,YAAY,EAAE,KAAK;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;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-node.provider.js","sources":["../../../src/contexts/providers/active-node.provider.tsx"],"sourcesContent":["import { Path } from \"@contentstack/studio-internal\";\nimport { createContext } from \"react\";\n\nexport type ActiveComponentPathContextType = {\n activeNodeUid: string | null;\n activeNodePath: Path | null;\n};\n\nexport const ActiveComponentPathContext =\n createContext<ActiveComponentPathContextType>({\n activeNodeUid: null,\n activeNodePath: null,\n });\n"],"names":[],"mappings":";;AAQO,MAAM,0BAA0B,GACrC,aAAa,CAAiC;AAC5C,IAAA,aAAa,EAAE,IAAI;AACnB,IAAA,cAAc,EAAE,IAAI;AACrB,CAAA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-mode.provider.js","sources":["../../../src/contexts/providers/preview-mode.provider.tsx"],"sourcesContent":["import { createContext } from \"react\";\n\nexport type PreviewModeContextType = boolean;\n\nexport const PreviewModeContext = createContext<PreviewModeContextType>(false);\n"],"names":[],"mappings":";;MAIa,kBAAkB,GAAG,aAAa,CAAyB,KAAK;;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { isCompositionBeingEdited } from '@contentstack/studio-client';
|
|
3
|
+
import { createContext, useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
const rendererContext = createContext({
|
|
6
|
+
isCompositionBeingEdited: false,
|
|
7
|
+
});
|
|
8
|
+
const { Provider } = rendererContext;
|
|
9
|
+
const RendererProvider = (props) => {
|
|
10
|
+
const { children, spec, componentRegistry } = props;
|
|
11
|
+
const value = useMemo(() => {
|
|
12
|
+
const isCompositionEdited = isCompositionBeingEdited(spec?.compositionEntry?.composable_uid ?? "");
|
|
13
|
+
return {
|
|
14
|
+
isCompositionBeingEdited: isCompositionEdited,
|
|
15
|
+
componentRegistry,
|
|
16
|
+
};
|
|
17
|
+
}, [spec, componentRegistry]);
|
|
18
|
+
return jsx(Provider, { value: value, children: children });
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { RendererProvider, rendererContext };
|
|
22
|
+
//# sourceMappingURL=renderer.provider.js.map
|
|
@@ -0,0 +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":";;;;AAkBO,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;SAClB;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;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { SelectedNodeContext } from '@contentstack/studio-react-components/contexts';
|
|
3
|
+
import { useIsNodeSelected } from '../../hooks/use-is-node-selected.js';
|
|
4
|
+
|
|
5
|
+
function SelectedNodeProvider({ children, }) {
|
|
6
|
+
const isSelected = useIsNodeSelected();
|
|
7
|
+
return (jsx(SelectedNodeContext.Provider, { value: { isSelected }, children: children }));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { SelectedNodeProvider };
|
|
11
|
+
//# sourceMappingURL=selected-node.provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selected-node.provider.js","sources":["../../../src/contexts/providers/selected-node.provider.tsx"],"sourcesContent":["import { SelectedNodeContext } from \"@contentstack/studio-react-components/contexts\";\nimport { useIsNodeSelected } from \"../../hooks/use-is-node-selected\";\n\nexport function SelectedNodeProvider({\n children,\n}: {\n children: React.ReactNode;\n}) {\n const isSelected = useIsNodeSelected();\n\n return (\n <SelectedNodeContext.Provider value={{ isSelected }}>\n {children}\n </SelectedNodeContext.Provider>\n );\n}\n"],"names":["_jsx"],"mappings":";;;;AAGM,SAAU,oBAAoB,CAAC,EACnC,QAAQ,GAGT,EAAA;AACC,IAAA,MAAM,UAAU,GAAG,iBAAiB,EAAE;AAEtC,IAAA,QACEA,GAAA,CAAC,mBAAmB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,EAAE,UAAU,EAAE,EAAA,QAAA,EAChD,QAAQ,EAAA,CACoB;AAEnC;;;;"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { applyOperation } from '@contentstack/studio-client';
|
|
3
|
+
import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
|
|
4
|
+
import { SymbolUICtx } from '@contentstack/studio-react-components/contexts';
|
|
5
|
+
import { produce } from 'immer';
|
|
6
|
+
import { useState, useEffect } from 'react';
|
|
7
|
+
import { useRenderer } from '../../hooks/use-renderer.hook.js';
|
|
8
|
+
import { registerSymbolComponent } from '../../hooks/use-register-symbol.hook.js';
|
|
9
|
+
import './renderer.provider.js';
|
|
10
|
+
import './active-node.provider.js';
|
|
11
|
+
import './use-design-preview.provider.js';
|
|
12
|
+
import './use-repeater.provider.js';
|
|
13
|
+
import './use-condition-block.provider.js';
|
|
14
|
+
import './preview-mode.provider.js';
|
|
15
|
+
|
|
16
|
+
const SymbolUIProvider = ({ symbols, children, }) => {
|
|
17
|
+
const { componentRegistry } = useRenderer();
|
|
18
|
+
const [symbolUIs, setSymbolUIs] = useState(symbols.reduce((acc, symbol) => {
|
|
19
|
+
acc[symbol.uid] = symbol;
|
|
20
|
+
return acc;
|
|
21
|
+
}, {}));
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
setSymbolUIs(symbols.reduce((acc, symbol) => {
|
|
24
|
+
acc[symbol.uid] = symbol;
|
|
25
|
+
return acc;
|
|
26
|
+
}, {}));
|
|
27
|
+
}, [symbols]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const handleApplySymbolOperation = (data) => {
|
|
30
|
+
const { uid, operations } = data;
|
|
31
|
+
setSymbolUIs((symbolUIs) => {
|
|
32
|
+
if (!symbolUIs[uid])
|
|
33
|
+
return symbolUIs;
|
|
34
|
+
const newSymbolUIs = produce(symbolUIs, (draft) => {
|
|
35
|
+
const symbol = draft[uid];
|
|
36
|
+
if (!symbol)
|
|
37
|
+
return;
|
|
38
|
+
const newSymbol = applyOperation(symbol.ui, operations);
|
|
39
|
+
symbol.ui = newSymbol;
|
|
40
|
+
draft[uid] = {
|
|
41
|
+
...symbol,
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
registerSymbolComponent([newSymbolUIs[uid]], componentRegistry);
|
|
45
|
+
return newSymbolUIs;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
const applySymbolOperationListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.APPLY_SYMBOL_OPERATION, (event) => {
|
|
49
|
+
handleApplySymbolOperation(event.data);
|
|
50
|
+
});
|
|
51
|
+
return () => {
|
|
52
|
+
applySymbolOperationListener?.unregister();
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const newSymbolListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.ADD_NEW_SYMBOL, (event) => {
|
|
57
|
+
const { symbol } = event.data;
|
|
58
|
+
registerSymbolComponent([symbol], componentRegistry);
|
|
59
|
+
setSymbolUIs((symbolUIs) => {
|
|
60
|
+
return produce(symbolUIs, (draft) => {
|
|
61
|
+
draft[symbol.uid] = symbol;
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
return () => {
|
|
66
|
+
newSymbolListener?.unregister();
|
|
67
|
+
};
|
|
68
|
+
}, []);
|
|
69
|
+
return (jsx(SymbolUICtx.Provider, { value: symbolUIs, children: children }));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { SymbolUIProvider };
|
|
73
|
+
//# sourceMappingURL=symbol-ui.provider.js.map
|
|
@@ -0,0 +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 symbols.reduce((acc, symbol) => {\n acc[symbol.uid] = symbol;\n return acc;\n }, {} as SymbolUIProvider),\n );\n }, [symbols]);\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":";;;;;;;;;;;;;;;AA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"file":"use-condition-block.provider.js","sources":["../../../src/contexts/providers/use-condition-block.provider.tsx"],"sourcesContent":["import { createContext } from \"react\";\n\nexport const ConditionBlockContext = createContext({\n isInsideConditionBlock: false,\n});\n"],"names":[],"mappings":";;AAEO,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACjD,IAAA,sBAAsB,EAAE,KAAK;AAC9B,CAAA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-design-preview.provider.js","sources":["../../../src/contexts/providers/use-design-preview.provider.tsx"],"sourcesContent":["import { createContext } from \"react\";\n\nexport const DesignPreviewContext = createContext(\"none\");\n"],"names":[],"mappings":";;MAEa,oBAAoB,GAAG,aAAa,CAAC,MAAM;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-repeater.provider.js","sources":["../../../src/contexts/providers/use-repeater.provider.tsx"],"sourcesContent":["import { createContext } from \"react\";\n\nexport const RepeaterContext = createContext({ isInsideRepeater: false });\n"],"names":[],"mappings":";;AAEO,MAAM,eAAe,GAAG,aAAa,CAAC,EAAE,gBAAgB,EAAE,KAAK,EAAE;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { highlightNodeManager } from '@contentstack/studio-client';
|
|
2
|
+
import { useContext, useState, useEffect } from 'react';
|
|
3
|
+
import '../contexts/providers/renderer.provider.js';
|
|
4
|
+
import { ActiveComponentPathContext } from '../contexts/providers/active-node.provider.js';
|
|
5
|
+
import 'react/jsx-runtime';
|
|
6
|
+
import '@contentstack/studio-messenger';
|
|
7
|
+
import '@contentstack/studio-react-components/contexts';
|
|
8
|
+
import 'immer';
|
|
9
|
+
import '@contentstack/studio-react-components/hooks';
|
|
10
|
+
import '@contentstack/studio-registry';
|
|
11
|
+
import '../components/Element.js';
|
|
12
|
+
import '../contexts/providers/use-design-preview.provider.js';
|
|
13
|
+
import '../contexts/providers/use-repeater.provider.js';
|
|
14
|
+
import '../contexts/providers/use-condition-block.provider.js';
|
|
15
|
+
import '../contexts/providers/preview-mode.provider.js';
|
|
16
|
+
|
|
17
|
+
function useActiveComponentPath() {
|
|
18
|
+
const activeComponentPath = useContext(ActiveComponentPathContext);
|
|
19
|
+
return activeComponentPath;
|
|
20
|
+
}
|
|
21
|
+
function useGetActiveComponentPathContext(spec) {
|
|
22
|
+
const [activeComponentPath, setActiveComponentPath] = useState({
|
|
23
|
+
activeNodeUid: null,
|
|
24
|
+
activeNodePath: null,
|
|
25
|
+
});
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
function getActiveNodeCallback(activeNodeUid, activeNodePath) {
|
|
28
|
+
if (!spec)
|
|
29
|
+
return;
|
|
30
|
+
setActiveComponentPath({
|
|
31
|
+
activeNodeUid,
|
|
32
|
+
activeNodePath,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
highlightNodeManager.onActiveNodeChange(getActiveNodeCallback, {
|
|
36
|
+
syncToExistingValue: true,
|
|
37
|
+
});
|
|
38
|
+
return () => {
|
|
39
|
+
highlightNodeManager.unsubscribeFromActiveNodeChange(getActiveNodeCallback);
|
|
40
|
+
};
|
|
41
|
+
}, [spec]);
|
|
42
|
+
return activeComponentPath;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { useActiveComponentPath, useGetActiveComponentPathContext };
|
|
46
|
+
//# sourceMappingURL=use-active-node-path.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-active-node-path.hook.js","sources":["../../src/hooks/use-active-node-path.hook.ts"],"sourcesContent":["import { StudioSpec, highlightNodeManager } from \"@contentstack/studio-client\";\nimport { Path } from \"@contentstack/studio-internal\";\nimport { useContext, useEffect, useState } from \"react\";\nimport {\n ActiveComponentPathContext,\n ActiveComponentPathContextType,\n} from \"../contexts/providers\";\n\nexport function useActiveComponentPath() {\n const activeComponentPath = useContext(ActiveComponentPathContext);\n return activeComponentPath;\n}\n\nexport function useGetActiveComponentPathContext(\n spec: StudioSpec,\n): ActiveComponentPathContextType {\n const [activeComponentPath, setActiveComponentPath] =\n useState<ActiveComponentPathContextType>({\n activeNodeUid: null,\n activeNodePath: null,\n });\n\n useEffect(() => {\n function getActiveNodeCallback(\n activeNodeUid: string,\n activeNodePath: Path,\n ) {\n if (!spec) return;\n\n setActiveComponentPath({\n activeNodeUid,\n activeNodePath,\n });\n }\n\n highlightNodeManager.onActiveNodeChange(getActiveNodeCallback, {\n syncToExistingValue: true,\n });\n\n return () => {\n highlightNodeManager.unsubscribeFromActiveNodeChange(\n getActiveNodeCallback,\n );\n };\n }, [spec]);\n\n return activeComponentPath;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;SAQgB,sBAAsB,GAAA;AACpC,IAAA,MAAM,mBAAmB,GAAG,UAAU,CAAC,0BAA0B,CAAC;AAClE,IAAA,OAAO,mBAAmB;AAC5B;AAEM,SAAU,gCAAgC,CAC9C,IAAgB,EAAA;AAEhB,IAAA,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GACjD,QAAQ,CAAiC;AACvC,QAAA,aAAa,EAAE,IAAI;AACnB,QAAA,cAAc,EAAE,IAAI;AACrB,KAAA,CAAC;IAEJ,SAAS,CAAC,MAAK;AACb,QAAA,SAAS,qBAAqB,CAC5B,aAAqB,EACrB,cAAoB,EAAA;AAEpB,YAAA,IAAI,CAAC,IAAI;gBAAE;AAEX,YAAA,sBAAsB,CAAC;gBACrB,aAAa;gBACb,cAAc;AACf,aAAA,CAAC;QACJ;AAEA,QAAA,oBAAoB,CAAC,kBAAkB,CAAC,qBAAqB,EAAE;AAC7D,YAAA,mBAAmB,EAAE,IAAI;AAC1B,SAAA,CAAC;AAEF,QAAA,OAAO,MAAK;AACV,YAAA,oBAAoB,CAAC,+BAA+B,CAClD,qBAAqB,CACtB;AACH,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAEV,IAAA,OAAO,mBAAmB;AAC5B;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isCompositionBeingEdited, addHighlightNodeEventListeners, addHighlightSpacingEventListeners, addContextMenuEventListeners, addBreakpointEventListeners, dndEventListener, updateStyleOnStyleNodeChange, hiddenElementNotificationEventEmitter, getNodeScreenshotEvent, isInsideVisualBuilderFrame, compositionSaveEventListener } from '@contentstack/studio-client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
const useCanvasEvents = (composableUid) => {
|
|
5
|
+
// HOOK TO ADD HIGHLIGHT NODE EVENT LISTENERS
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!isCompositionBeingEdited(composableUid || ""))
|
|
8
|
+
return;
|
|
9
|
+
const highlightNodeEventListener = addHighlightNodeEventListeners();
|
|
10
|
+
const highlightSpacingEventListener = addHighlightSpacingEventListeners();
|
|
11
|
+
const contextMenuEventListener = addContextMenuEventListeners();
|
|
12
|
+
const breakpointEventListener = addBreakpointEventListeners();
|
|
13
|
+
const dndListener = dndEventListener();
|
|
14
|
+
const updatedStyleEventListener = updateStyleOnStyleNodeChange();
|
|
15
|
+
const hiddenElementNotificationEventListener = hiddenElementNotificationEventEmitter();
|
|
16
|
+
const getNodeScreenshotEventListener = getNodeScreenshotEvent();
|
|
17
|
+
return () => {
|
|
18
|
+
highlightNodeEventListener?.removeEventListeners();
|
|
19
|
+
highlightSpacingEventListener?.removeEventListeners();
|
|
20
|
+
contextMenuEventListener?.removeEventListeners();
|
|
21
|
+
breakpointEventListener?.removeEventListeners();
|
|
22
|
+
dndListener?.removeEventListeners();
|
|
23
|
+
updatedStyleEventListener?.removeEventListeners();
|
|
24
|
+
hiddenElementNotificationEventListener?.unregister();
|
|
25
|
+
getNodeScreenshotEventListener?.unregister();
|
|
26
|
+
};
|
|
27
|
+
}, [composableUid]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!isInsideVisualBuilderFrame())
|
|
30
|
+
return;
|
|
31
|
+
const cleanup = compositionSaveEventListener();
|
|
32
|
+
return () => {
|
|
33
|
+
cleanup?.unregister();
|
|
34
|
+
};
|
|
35
|
+
}, []);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { useCanvasEvents };
|
|
39
|
+
//# sourceMappingURL=use-canvas-events.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-canvas-events.hook.js","sources":["../../src/hooks/use-canvas-events.hook.ts"],"sourcesContent":["import {\n addBreakpointEventListeners,\n addContextMenuEventListeners,\n addHighlightNodeEventListeners,\n addHighlightSpacingEventListeners,\n compositionSaveEventListener,\n dndEventListener,\n getNodeScreenshotEvent,\n hiddenElementNotificationEventEmitter,\n isCompositionBeingEdited,\n isInsideVisualBuilderFrame,\n updateStyleOnStyleNodeChange,\n} from \"@contentstack/studio-client\";\nimport { useEffect } from \"react\";\n\nexport const useCanvasEvents = (composableUid?: string) => {\n // HOOK TO ADD HIGHLIGHT NODE EVENT LISTENERS\n useEffect(() => {\n if (!isCompositionBeingEdited(composableUid || \"\")) return;\n const highlightNodeEventListener = addHighlightNodeEventListeners();\n const highlightSpacingEventListener = addHighlightSpacingEventListeners();\n const contextMenuEventListener = addContextMenuEventListeners();\n const breakpointEventListener = addBreakpointEventListeners();\n const dndListener = dndEventListener();\n const updatedStyleEventListener = updateStyleOnStyleNodeChange();\n const hiddenElementNotificationEventListener =\n hiddenElementNotificationEventEmitter();\n const getNodeScreenshotEventListener = getNodeScreenshotEvent();\n\n return () => {\n highlightNodeEventListener?.removeEventListeners();\n highlightSpacingEventListener?.removeEventListeners();\n contextMenuEventListener?.removeEventListeners();\n breakpointEventListener?.removeEventListeners();\n dndListener?.removeEventListeners();\n updatedStyleEventListener?.removeEventListeners();\n hiddenElementNotificationEventListener?.unregister();\n getNodeScreenshotEventListener?.unregister();\n };\n }, [composableUid]);\n\n useEffect(() => {\n if (!isInsideVisualBuilderFrame()) return;\n const cleanup = compositionSaveEventListener();\n return () => {\n cleanup?.unregister();\n };\n }, []);\n};\n"],"names":[],"mappings":";;;AAeO,MAAM,eAAe,GAAG,CAAC,aAAsB,KAAI;;IAExD,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,wBAAwB,CAAC,aAAa,IAAI,EAAE,CAAC;YAAE;AACpD,QAAA,MAAM,0BAA0B,GAAG,8BAA8B,EAAE;AACnE,QAAA,MAAM,6BAA6B,GAAG,iCAAiC,EAAE;AACzE,QAAA,MAAM,wBAAwB,GAAG,4BAA4B,EAAE;AAC/D,QAAA,MAAM,uBAAuB,GAAG,2BAA2B,EAAE;AAC7D,QAAA,MAAM,WAAW,GAAG,gBAAgB,EAAE;AACtC,QAAA,MAAM,yBAAyB,GAAG,4BAA4B,EAAE;AAChE,QAAA,MAAM,sCAAsC,GAC1C,qCAAqC,EAAE;AACzC,QAAA,MAAM,8BAA8B,GAAG,sBAAsB,EAAE;AAE/D,QAAA,OAAO,MAAK;YACV,0BAA0B,EAAE,oBAAoB,EAAE;YAClD,6BAA6B,EAAE,oBAAoB,EAAE;YACrD,wBAAwB,EAAE,oBAAoB,EAAE;YAChD,uBAAuB,EAAE,oBAAoB,EAAE;YAC/C,WAAW,EAAE,oBAAoB,EAAE;YACnC,yBAAyB,EAAE,oBAAoB,EAAE;YACjD,sCAAsC,EAAE,UAAU,EAAE;YACpD,8BAA8B,EAAE,UAAU,EAAE;AAC9C,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;IAEnB,SAAS,CAAC,MAAK;QACb,IAAI,CAAC,0BAA0B,EAAE;YAAE;AACnC,QAAA,MAAM,OAAO,GAAG,4BAA4B,EAAE;AAC9C,QAAA,OAAO,MAAK;YACV,OAAO,EAAE,UAAU,EAAE;AACvB,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;AACR;;;;"}
|