@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,20 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import '../contexts/providers/renderer.provider.js';
|
|
3
|
+
import '../contexts/providers/active-node.provider.js';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import '@contentstack/studio-client';
|
|
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 { ConditionBlockContext } from '../contexts/providers/use-condition-block.provider.js';
|
|
15
|
+
import '../contexts/providers/preview-mode.provider.js';
|
|
16
|
+
|
|
17
|
+
const useConditionBlockContext = () => useContext(ConditionBlockContext);
|
|
18
|
+
|
|
19
|
+
export { useConditionBlockContext };
|
|
20
|
+
//# sourceMappingURL=use-condition-block-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-condition-block-context.js","sources":["../../src/hooks/use-condition-block-context.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { ConditionBlockContext } from \"../contexts/providers\";\n\nexport const useConditionBlockContext = () => useContext(ConditionBlockContext);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGO,MAAM,wBAAwB,GAAG,MAAM,UAAU,CAAC,qBAAqB;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import '../contexts/providers/renderer.provider.js';
|
|
3
|
+
import '../contexts/providers/active-node.provider.js';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import '@contentstack/studio-client';
|
|
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 { DesignPreviewContext } from '../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
|
+
const useDesignPreviewContext = () => useContext(DesignPreviewContext);
|
|
18
|
+
|
|
19
|
+
export { useDesignPreviewContext };
|
|
20
|
+
//# sourceMappingURL=use-design-preview.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-design-preview.hook.js","sources":["../../src/hooks/use-design-preview.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { DesignPreviewContext } from \"../contexts/providers\";\n\nexport const useDesignPreviewContext = () => useContext(DesignPreviewContext);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGO,MAAM,uBAAuB,GAAG,MAAM,UAAU,CAAC,oBAAoB;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Path } from '@contentstack/studio-internal';
|
|
2
|
+
import { useCurrentNode } from '@contentstack/studio-react-components/hooks';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { useActiveComponentPath } from './use-active-node-path.hook.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Evaluates whether the current node is selected.
|
|
8
|
+
* This is an internal hook that stores the result in the `SelectedNodeContext`.
|
|
9
|
+
* That value is then used by the `useSelected` hook to determine if the current node is selected.
|
|
10
|
+
* @returns whether the current node is selected
|
|
11
|
+
*/
|
|
12
|
+
function useIsNodeSelected() {
|
|
13
|
+
const { currentNodePath } = useCurrentNode();
|
|
14
|
+
const { activeNodePath } = useActiveComponentPath();
|
|
15
|
+
return useMemo(() => {
|
|
16
|
+
if (!activeNodePath || !currentNodePath) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const isSameNode = Path.equals(currentNodePath, activeNodePath);
|
|
20
|
+
const isCurrentNodeAncestorOfActiveNode = Path.isAncestor(currentNodePath, activeNodePath);
|
|
21
|
+
return isSameNode || isCurrentNodeAncestorOfActiveNode;
|
|
22
|
+
}, [activeNodePath, currentNodePath]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { useIsNodeSelected };
|
|
26
|
+
//# sourceMappingURL=use-is-node-selected.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-is-node-selected.js","sources":["../../src/hooks/use-is-node-selected.ts"],"sourcesContent":["import { Path } from \"@contentstack/studio-internal\";\nimport { useCurrentNode } from \"@contentstack/studio-react-components/hooks\";\nimport { useMemo } from \"react\";\nimport { useActiveComponentPath } from \"./use-active-node-path.hook\";\n\n/**\n * Evaluates whether the current node is selected.\n * This is an internal hook that stores the result in the `SelectedNodeContext`.\n * That value is then used by the `useSelected` hook to determine if the current node is selected.\n * @returns whether the current node is selected\n */\nexport function useIsNodeSelected(): boolean {\n const { currentNodePath } = useCurrentNode();\n const { activeNodePath } = useActiveComponentPath();\n\n return useMemo(() => {\n if (!activeNodePath || !currentNodePath) {\n return false;\n }\n\n const isSameNode = Path.equals(currentNodePath, activeNodePath);\n\n const isCurrentNodeAncestorOfActiveNode = Path.isAncestor(\n currentNodePath,\n activeNodePath,\n );\n\n return isSameNode || isCurrentNodeAncestorOfActiveNode;\n }, [activeNodePath, currentNodePath]);\n}\n"],"names":[],"mappings":";;;;;AAKA;;;;;AAKG;SACa,iBAAiB,GAAA;AAC/B,IAAA,MAAM,EAAE,eAAe,EAAE,GAAG,cAAc,EAAE;AAC5C,IAAA,MAAM,EAAE,cAAc,EAAE,GAAG,sBAAsB,EAAE;IAEnD,OAAO,OAAO,CAAC,MAAK;AAClB,QAAA,IAAI,CAAC,cAAc,IAAI,CAAC,eAAe,EAAE;AACvC,YAAA,OAAO,KAAK;QACd;QAEA,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,cAAc,CAAC;QAE/D,MAAM,iCAAiC,GAAG,IAAI,CAAC,UAAU,CACvD,eAAe,EACf,cAAc,CACf;QAED,OAAO,UAAU,IAAI,iCAAiC;AACxD,IAAA,CAAC,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AACvC;;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import '../contexts/providers/renderer.provider.js';
|
|
3
|
+
import '../contexts/providers/active-node.provider.js';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import '@contentstack/studio-client';
|
|
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 { PreviewModeContext } from '../contexts/providers/preview-mode.provider.js';
|
|
16
|
+
|
|
17
|
+
const usePreviewMode = () => {
|
|
18
|
+
return useContext(PreviewModeContext);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { usePreviewMode };
|
|
22
|
+
//# sourceMappingURL=use-preview-mode.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-preview-mode.hook.js","sources":["../../src/hooks/use-preview-mode.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { PreviewModeContext } from \"../contexts/providers\";\n\nexport const usePreviewMode = () => {\n return useContext(PreviewModeContext);\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGO,MAAM,cAAc,GAAG,MAAK;AACjC,IAAA,OAAO,UAAU,CAAC,kBAAkB,CAAC;AACvC;;;;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { Symbol } from '../components/elements/Symbol.js';
|
|
4
|
+
import { useRenderer } from './use-renderer.hook.js';
|
|
5
|
+
|
|
6
|
+
const registerSymbolComponent = (symbols, componentRegistry) => {
|
|
7
|
+
const symbolsConfig = symbols.map((symbol) => {
|
|
8
|
+
const symbolSpec = {
|
|
9
|
+
ui: symbol.ui,
|
|
10
|
+
// TODO: Need to get the data sources from the symbol
|
|
11
|
+
data: {
|
|
12
|
+
dataSources: [],
|
|
13
|
+
static_value: {},
|
|
14
|
+
},
|
|
15
|
+
symbols: [],
|
|
16
|
+
};
|
|
17
|
+
const props = {
|
|
18
|
+
ui: {
|
|
19
|
+
type: "slot",
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const symbolProps = symbol.ui.metadata.symbolProps || [];
|
|
23
|
+
for (const symbolProp of symbolProps) {
|
|
24
|
+
const { uid } = symbolProp;
|
|
25
|
+
props[uid] = symbolProp;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
type: symbol.uid,
|
|
29
|
+
displayName: symbol.title,
|
|
30
|
+
thumbnailUrl: symbol?.ui_preview?.url,
|
|
31
|
+
wrap: false,
|
|
32
|
+
props,
|
|
33
|
+
component: (props) => {
|
|
34
|
+
return jsx(Symbol, { ...props, spec: symbolSpec, symbolUID: symbol.uid });
|
|
35
|
+
},
|
|
36
|
+
metadata: {
|
|
37
|
+
uid: symbol.uid,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
componentRegistry.registerSymbolComponent(symbolsConfig);
|
|
42
|
+
};
|
|
43
|
+
const useRegisterSymbolComponents = (symbols) => {
|
|
44
|
+
// Using useMemo to doing it in same render cycle
|
|
45
|
+
const { componentRegistry } = useRenderer();
|
|
46
|
+
useMemo(() => {
|
|
47
|
+
if (!symbols)
|
|
48
|
+
return;
|
|
49
|
+
registerSymbolComponent(symbols, componentRegistry);
|
|
50
|
+
}, [symbols]);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { registerSymbolComponent, useRegisterSymbolComponents };
|
|
54
|
+
//# sourceMappingURL=use-register-symbol.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-register-symbol.hook.js","sources":["../../src/hooks/use-register-symbol.hook.tsx"],"sourcesContent":["import { StudioSpec, SymbolEntry } from \"@contentstack/studio-client\";\nimport {\n ComponentRegistry,\n RegisterComponentOptionsInput,\n} from \"@contentstack/studio-registry\";\nimport { ReactNode, useMemo } from \"react\";\nimport { Symbol } from \"../components/elements/Symbol\";\nimport { useRenderer } from \"./use-renderer.hook\";\n\ntype SymbolRegistryConfig = RegisterComponentOptionsInput<\n (props?: any) => ReactNode\n>;\nexport const registerSymbolComponent = (\n symbols: SymbolEntry[],\n componentRegistry: ComponentRegistry<unknown>,\n) => {\n const symbolsConfig: SymbolRegistryConfig[] = symbols.map((symbol) => {\n const symbolSpec: Omit<StudioSpec, \"compositionEntry\"> = {\n ui: symbol.ui,\n // TODO: Need to get the data sources from the symbol\n data: {\n dataSources: [],\n static_value: {},\n },\n symbols: [],\n };\n const props: Record<string, any> = {\n ui: {\n type: \"slot\",\n },\n };\n const symbolProps = symbol.ui.metadata.symbolProps || [];\n for (const symbolProp of symbolProps) {\n const { uid } = symbolProp;\n props[uid] = symbolProp;\n }\n return {\n type: symbol.uid,\n displayName: symbol.title,\n thumbnailUrl: symbol?.ui_preview?.url,\n wrap: false,\n props,\n component: (props) => {\n return <Symbol {...props} spec={symbolSpec} symbolUID={symbol.uid} />;\n },\n metadata: {\n uid: symbol.uid,\n },\n };\n });\n componentRegistry.registerSymbolComponent(symbolsConfig);\n};\nexport const useRegisterSymbolComponents = (symbols?: SymbolEntry[]) => {\n // Using useMemo to doing it in same render cycle\n const { componentRegistry } = useRenderer();\n useMemo(() => {\n if (!symbols) return;\n registerSymbolComponent(symbols, componentRegistry);\n }, [symbols]);\n};\n"],"names":["_jsx"],"mappings":";;;;;MAYa,uBAAuB,GAAG,CACrC,OAAsB,EACtB,iBAA6C,KAC3C;IACF,MAAM,aAAa,GAA2B,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,KAAI;AACnE,QAAA,MAAM,UAAU,GAAyC;YACvD,EAAE,EAAE,MAAM,CAAC,EAAE;;AAEb,YAAA,IAAI,EAAE;AACJ,gBAAA,WAAW,EAAE,EAAE;AACf,gBAAA,YAAY,EAAE,EAAE;AACjB,aAAA;AACD,YAAA,OAAO,EAAE,EAAE;SACZ;AACD,QAAA,MAAM,KAAK,GAAwB;AACjC,YAAA,EAAE,EAAE;AACF,gBAAA,IAAI,EAAE,MAAM;AACb,aAAA;SACF;QACD,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,WAAW,IAAI,EAAE;AACxD,QAAA,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;AACpC,YAAA,MAAM,EAAE,GAAG,EAAE,GAAG,UAAU;AAC1B,YAAA,KAAK,CAAC,GAAG,CAAC,GAAG,UAAU;QACzB;QACA,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,GAAG;YAChB,WAAW,EAAE,MAAM,CAAC,KAAK;AACzB,YAAA,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG;AACrC,YAAA,IAAI,EAAE,KAAK;YACX,KAAK;AACL,YAAA,SAAS,EAAE,CAAC,KAAK,KAAI;AACnB,gBAAA,OAAOA,GAAA,CAAC,MAAM,EAAA,EAAA,GAAK,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,GAAI;YACvE,CAAC;AACD,YAAA,QAAQ,EAAE;gBACR,GAAG,EAAE,MAAM,CAAC,GAAG;AAChB,aAAA;SACF;AACH,IAAA,CAAC,CAAC;AACF,IAAA,iBAAiB,CAAC,uBAAuB,CAAC,aAAa,CAAC;AAC1D;AACO,MAAM,2BAA2B,GAAG,CAAC,OAAuB,KAAI;;AAErE,IAAA,MAAM,EAAE,iBAAiB,EAAE,GAAG,WAAW,EAAE;IAC3C,OAAO,CAAC,MAAK;AACX,QAAA,IAAI,CAAC,OAAO;YAAE;AACd,QAAA,uBAAuB,CAAC,OAAO,EAAE,iBAAiB,CAAC;AACrD,IAAA,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AACf;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { rendererContext } from '../contexts/providers/renderer.provider.js';
|
|
2
|
+
import '../contexts/providers/active-node.provider.js';
|
|
3
|
+
import 'react/jsx-runtime';
|
|
4
|
+
import '@contentstack/studio-client';
|
|
5
|
+
import '@contentstack/studio-messenger';
|
|
6
|
+
import '@contentstack/studio-react-components/contexts';
|
|
7
|
+
import 'immer';
|
|
8
|
+
import { useContext } from 'react';
|
|
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
|
+
const useRenderer = () => {
|
|
18
|
+
const context = useContext(rendererContext);
|
|
19
|
+
return context;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { useRenderer };
|
|
23
|
+
//# sourceMappingURL=use-renderer.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-renderer.hook.js","sources":["../../src/hooks/use-renderer.hook.ts"],"sourcesContent":["import { rendererContext } from \"../contexts/providers\";\nimport { useContext } from \"react\";\n\nexport const useRenderer = () => {\n const context = useContext(rendererContext);\n return context;\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGO,MAAM,WAAW,GAAG,MAAK;AAC9B,IAAA,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC;AAC3C,IAAA,OAAO,OAAO;AAChB;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import '../contexts/providers/renderer.provider.js';
|
|
3
|
+
import '../contexts/providers/active-node.provider.js';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import '@contentstack/studio-client';
|
|
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 { RepeaterContext } from '../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
|
+
const useRepeaterContext = () => useContext(RepeaterContext);
|
|
18
|
+
|
|
19
|
+
export { useRepeaterContext };
|
|
20
|
+
//# sourceMappingURL=use-repeater.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-repeater.hook.js","sources":["../../src/hooks/use-repeater.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { RepeaterContext } from \"../contexts/providers\";\n\nexport const useRepeaterContext = () => useContext(RepeaterContext);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGO,MAAM,kBAAkB,GAAG,MAAM,UAAU,CAAC,eAAe;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useConditionBlockContext } from './use-condition-block-context.js';
|
|
2
|
+
import { useDesignPreviewContext } from './use-design-preview.hook.js';
|
|
3
|
+
import { useRenderer } from './use-renderer.hook.js';
|
|
4
|
+
import { useRepeaterContext } from './use-repeater.hook.js';
|
|
5
|
+
|
|
6
|
+
function useShouldShowDesign(mode) {
|
|
7
|
+
const { isCompositionBeingEdited } = useRenderer();
|
|
8
|
+
const { isInsideRepeater } = useRepeaterContext();
|
|
9
|
+
const { isInsideConditionBlock } = useConditionBlockContext();
|
|
10
|
+
const designPreviewContext = useDesignPreviewContext();
|
|
11
|
+
if (!isCompositionBeingEdited)
|
|
12
|
+
return false;
|
|
13
|
+
if (isInsideRepeater || isInsideConditionBlock) {
|
|
14
|
+
// If composition is being edited and current node(Repeater or Condition Block) inside another repeater or condition block,
|
|
15
|
+
// and no designPreviewContext is provided, then show design
|
|
16
|
+
if (!designPreviewContext)
|
|
17
|
+
return true;
|
|
18
|
+
// If designPreviewContext is provided,
|
|
19
|
+
// then show design based on designPreviewContext
|
|
20
|
+
return designPreviewContext === "design";
|
|
21
|
+
}
|
|
22
|
+
// if no mode is provided, then show design
|
|
23
|
+
if (!mode) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
// If mode is provided, then show design based on mode
|
|
27
|
+
return mode === "design";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { useShouldShowDesign };
|
|
31
|
+
//# sourceMappingURL=use-should-show-design.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-should-show-design.hook.js","sources":["../../src/hooks/use-should-show-design.hook.ts"],"sourcesContent":["import { useConditionBlockContext } from \"./use-condition-block-context\";\nimport { useDesignPreviewContext } from \"./use-design-preview.hook\";\nimport { useRenderer } from \"./use-renderer.hook\";\nimport { useRepeaterContext } from \"./use-repeater.hook\";\n\nexport function useShouldShowDesign(mode: \"design\" | \"preview\") {\n const { isCompositionBeingEdited } = useRenderer();\n const { isInsideRepeater } = useRepeaterContext();\n const { isInsideConditionBlock } = useConditionBlockContext();\n const designPreviewContext = useDesignPreviewContext();\n if (!isCompositionBeingEdited) return false;\n\n if (isInsideRepeater || isInsideConditionBlock) {\n // If composition is being edited and current node(Repeater or Condition Block) inside another repeater or condition block,\n // and no designPreviewContext is provided, then show design\n if (!designPreviewContext) return true;\n // If designPreviewContext is provided,\n // then show design based on designPreviewContext\n return designPreviewContext === \"design\";\n }\n // if no mode is provided, then show design\n if (!mode) {\n return true;\n }\n // If mode is provided, then show design based on mode\n return mode === \"design\";\n}\n"],"names":[],"mappings":";;;;;AAKM,SAAU,mBAAmB,CAAC,IAA0B,EAAA;AAC5D,IAAA,MAAM,EAAE,wBAAwB,EAAE,GAAG,WAAW,EAAE;AAClD,IAAA,MAAM,EAAE,gBAAgB,EAAE,GAAG,kBAAkB,EAAE;AACjD,IAAA,MAAM,EAAE,sBAAsB,EAAE,GAAG,wBAAwB,EAAE;AAC7D,IAAA,MAAM,oBAAoB,GAAG,uBAAuB,EAAE;AACtD,IAAA,IAAI,CAAC,wBAAwB;AAAE,QAAA,OAAO,KAAK;AAE3C,IAAA,IAAI,gBAAgB,IAAI,sBAAsB,EAAE;;;AAG9C,QAAA,IAAI,CAAC,oBAAoB;AAAE,YAAA,OAAO,IAAI;;;QAGtC,OAAO,oBAAoB,KAAK,QAAQ;IAC1C;;IAEA,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,OAAO,IAAI;IACb;;IAEA,OAAO,IAAI,KAAK,QAAQ;AAC1B;;;;"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isCompositionBeingEdited, applyOperation } from '@contentstack/studio-client';
|
|
2
|
+
import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
|
|
3
|
+
import { DATA_SOURCES_PREFIX } from '@contentstack/studio-registry';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { setAutoFreeze, produce } from 'immer';
|
|
6
|
+
|
|
7
|
+
// NOTE: Immer (produce) automatically freezes the state to prevent mutations.
|
|
8
|
+
// However, while resolving metadata bindings (which currently only include styles),
|
|
9
|
+
// we need to add binding values directly to the node object.
|
|
10
|
+
// Since the state is frozen by default, this throws an error.
|
|
11
|
+
// To work around this, we disable auto-freezing here.
|
|
12
|
+
setAutoFreeze(false);
|
|
13
|
+
const useSpecDataListener = (setState, state, composableUid) => {
|
|
14
|
+
// HOOK TO UPDATE THE STATE WITH THE LATEST SPEC DATA
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!isCompositionBeingEdited(composableUid || ""))
|
|
17
|
+
return;
|
|
18
|
+
const specDataChangeListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.UPDATE_SPEC_DATA, async (event) => {
|
|
19
|
+
const { data } = event;
|
|
20
|
+
if (!data || !state?.data)
|
|
21
|
+
return;
|
|
22
|
+
setState((state) => {
|
|
23
|
+
if (!state)
|
|
24
|
+
return state;
|
|
25
|
+
return {
|
|
26
|
+
...state,
|
|
27
|
+
data: data,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
const previewEntryChangeListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.REPLACE_PREVIEW_ENTRY, async (event) => {
|
|
32
|
+
const { data } = event;
|
|
33
|
+
if (!data?.dataSources || !state?.data)
|
|
34
|
+
return;
|
|
35
|
+
setState((prevState) => {
|
|
36
|
+
if (!prevState)
|
|
37
|
+
return prevState;
|
|
38
|
+
return {
|
|
39
|
+
...prevState,
|
|
40
|
+
data: { ...state?.data, [DATA_SOURCES_PREFIX]: data?.dataSources },
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
const applyOperationListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.APPLY_OPERATION, (event) => {
|
|
45
|
+
const { data } = event;
|
|
46
|
+
setState((prevState) => {
|
|
47
|
+
if (!prevState?.ui || !data?.operations)
|
|
48
|
+
return prevState;
|
|
49
|
+
const newUI = produce(prevState.ui, (ui) => {
|
|
50
|
+
const operations = data.operations;
|
|
51
|
+
return applyOperation(ui, operations);
|
|
52
|
+
});
|
|
53
|
+
return { ...prevState, ui: newUI };
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
return () => {
|
|
57
|
+
applyOperationListener?.unregister();
|
|
58
|
+
specDataChangeListener?.unregister();
|
|
59
|
+
previewEntryChangeListener?.unregister();
|
|
60
|
+
};
|
|
61
|
+
}, [state?.compositionEntry?.uid, state?.data, composableUid]);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { useSpecDataListener };
|
|
65
|
+
//# sourceMappingURL=use-spec-data-listener.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-spec-data-listener.hook.js","sources":["../../src/hooks/use-spec-data-listener.hook.ts"],"sourcesContent":["import {\n isCompositionBeingEdited,\n StudioSpec,\n applyOperation,\n} from \"@contentstack/studio-client\";\nimport { Operation } from \"@contentstack/studio-internal\";\nimport {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} from \"@contentstack/studio-messenger\";\nimport {\n StudioSpecData,\n DataSourceItem,\n DATA_SOURCES_PREFIX,\n} from \"@contentstack/studio-registry\";\nimport { useEffect } from \"react\";\nimport { produce, setAutoFreeze } from \"immer\";\n\n// NOTE: Immer (produce) automatically freezes the state to prevent mutations.\n// However, while resolving metadata bindings (which currently only include styles),\n// we need to add binding values directly to the node object.\n// Since the state is frozen by default, this throws an error.\n// To work around this, we disable auto-freezing here.\nsetAutoFreeze(false);\n\nexport const useSpecDataListener = (\n setState: React.Dispatch<React.SetStateAction<StudioSpec>>,\n state?: StudioSpec,\n composableUid?: string,\n) => {\n // HOOK TO UPDATE THE STATE WITH THE LATEST SPEC DATA\n useEffect(() => {\n if (!isCompositionBeingEdited(composableUid || \"\")) return;\n const specDataChangeListener =\n composableStudioEventManager?.on<StudioSpecData>(\n POST_MESSAGE_EVENTS.UPDATE_SPEC_DATA,\n async (event) => {\n const { data } = event;\n if (!data || !state?.data) return;\n\n setState((state: StudioSpec) => {\n if (!state) return state;\n return {\n ...state,\n data: data,\n };\n });\n },\n );\n\n const previewEntryChangeListener = composableStudioEventManager?.on<{\n dataSources: DataSourceItem[];\n }>(POST_MESSAGE_EVENTS.REPLACE_PREVIEW_ENTRY, async (event) => {\n const { data } = event;\n if (!data?.dataSources || !state?.data) return;\n\n setState((prevState: StudioSpec) => {\n if (!prevState) return prevState;\n return {\n ...prevState,\n data: { ...state?.data, [DATA_SOURCES_PREFIX]: data?.dataSources },\n };\n });\n });\n\n const applyOperationListener = composableStudioEventManager?.on<{\n operations: Operation[];\n }>(POST_MESSAGE_EVENTS.APPLY_OPERATION, (event) => {\n const { data } = event;\n setState((prevState: StudioSpec) => {\n if (!prevState?.ui || !data?.operations) return prevState;\n const newUI = produce(prevState.ui, (ui) => {\n const operations = data.operations;\n return applyOperation(ui, operations);\n });\n return { ...prevState, ui: newUI };\n });\n });\n return () => {\n applyOperationListener?.unregister();\n specDataChangeListener?.unregister();\n previewEntryChangeListener?.unregister();\n };\n }, [state?.compositionEntry?.uid, state?.data, composableUid]);\n};\n"],"names":[],"mappings":";;;;;;AAkBA;AACA;AACA;AACA;AACA;AACA,aAAa,CAAC,KAAK,CAAC;AAEb,MAAM,mBAAmB,GAAG,CACjC,QAA0D,EAC1D,KAAkB,EAClB,aAAsB,KACpB;;IAEF,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,wBAAwB,CAAC,aAAa,IAAI,EAAE,CAAC;YAAE;AACpD,QAAA,MAAM,sBAAsB,GAC1B,4BAA4B,EAAE,EAAE,CAC9B,mBAAmB,CAAC,gBAAgB,EACpC,OAAO,KAAK,KAAI;AACd,YAAA,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK;AACtB,YAAA,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI;gBAAE;AAE3B,YAAA,QAAQ,CAAC,CAAC,KAAiB,KAAI;AAC7B,gBAAA,IAAI,CAAC,KAAK;AAAE,oBAAA,OAAO,KAAK;gBACxB,OAAO;AACL,oBAAA,GAAG,KAAK;AACR,oBAAA,IAAI,EAAE,IAAI;iBACX;AACH,YAAA,CAAC,CAAC;AACJ,QAAA,CAAC,CACF;AAEH,QAAA,MAAM,0BAA0B,GAAG,4BAA4B,EAAE,EAAE,CAEhE,mBAAmB,CAAC,qBAAqB,EAAE,OAAO,KAAK,KAAI;AAC5D,YAAA,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK;YACtB,IAAI,CAAC,IAAI,EAAE,WAAW,IAAI,CAAC,KAAK,EAAE,IAAI;gBAAE;AAExC,YAAA,QAAQ,CAAC,CAAC,SAAqB,KAAI;AACjC,gBAAA,IAAI,CAAC,SAAS;AAAE,oBAAA,OAAO,SAAS;gBAChC,OAAO;AACL,oBAAA,GAAG,SAAS;AACZ,oBAAA,IAAI,EAAE,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,CAAC,mBAAmB,GAAG,IAAI,EAAE,WAAW,EAAE;iBACnE;AACH,YAAA,CAAC,CAAC;AACJ,QAAA,CAAC,CAAC;AAEF,QAAA,MAAM,sBAAsB,GAAG,4BAA4B,EAAE,EAAE,CAE5D,mBAAmB,CAAC,eAAe,EAAE,CAAC,KAAK,KAAI;AAChD,YAAA,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK;AACtB,YAAA,QAAQ,CAAC,CAAC,SAAqB,KAAI;gBACjC,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU;AAAE,oBAAA,OAAO,SAAS;gBACzD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,KAAI;AACzC,oBAAA,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU;AAClC,oBAAA,OAAO,cAAc,CAAC,EAAE,EAAE,UAAU,CAAC;AACvC,gBAAA,CAAC,CAAC;gBACF,OAAO,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE;AACpC,YAAA,CAAC,CAAC;AACJ,QAAA,CAAC,CAAC;AACF,QAAA,OAAO,MAAK;YACV,sBAAsB,EAAE,UAAU,EAAE;YACpC,sBAAsB,EAAE,UAAU,EAAE;YACpC,0BAA0B,EAAE,UAAU,EAAE;AAC1C,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;AAChE;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isCompositionBeingEdited, preProcessStaticValues } from '@contentstack/studio-client';
|
|
2
|
+
import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
|
|
3
|
+
import { DATA_SOURCES } from '@contentstack/studio-registry';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
|
|
6
|
+
const useStaticValuesListener = (setState, state, composableUid) => {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (!isCompositionBeingEdited(composableUid || ""))
|
|
9
|
+
return;
|
|
10
|
+
const staticValueChangeListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.UPDATE_STATIC_VALUE, (event) => {
|
|
11
|
+
const { data } = event;
|
|
12
|
+
if (!data)
|
|
13
|
+
return;
|
|
14
|
+
setState((prevState) => {
|
|
15
|
+
if (!prevState)
|
|
16
|
+
return prevState;
|
|
17
|
+
return {
|
|
18
|
+
...prevState,
|
|
19
|
+
data: {
|
|
20
|
+
...prevState.data,
|
|
21
|
+
[DATA_SOURCES.STATIC_VALUE]: preProcessStaticValues(data.staticValue),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
return () => {
|
|
27
|
+
staticValueChangeListener?.unregister();
|
|
28
|
+
};
|
|
29
|
+
}, [state?.compositionEntry?.uid, composableUid]);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { useStaticValuesListener };
|
|
33
|
+
//# sourceMappingURL=use-static-values-listener.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-static-values-listener.hook.js","sources":["../../src/hooks/use-static-values-listener.hook.ts"],"sourcesContent":["import {\n isCompositionBeingEdited,\n StudioSpec,\n preProcessStaticValues,\n} from \"@contentstack/studio-client\";\nimport {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} from \"@contentstack/studio-messenger\";\nimport { RawStaticValue, DATA_SOURCES } from \"@contentstack/studio-registry\";\nimport { useEffect } from \"react\";\n\nexport const useStaticValuesListener = (\n setState: React.Dispatch<React.SetStateAction<StudioSpec>>,\n state?: StudioSpec,\n composableUid?: string,\n) => {\n useEffect(() => {\n if (!isCompositionBeingEdited(composableUid || \"\")) return;\n const staticValueChangeListener = composableStudioEventManager?.on<{\n staticValue: RawStaticValue;\n }>(POST_MESSAGE_EVENTS.UPDATE_STATIC_VALUE, (event) => {\n const { data } = event;\n if (!data) return;\n setState((prevState: StudioSpec) => {\n if (!prevState) return prevState;\n return {\n ...prevState,\n data: {\n ...prevState.data,\n [DATA_SOURCES.STATIC_VALUE]: preProcessStaticValues(\n data.staticValue,\n ),\n },\n };\n });\n });\n\n return () => {\n staticValueChangeListener?.unregister();\n };\n }, [state?.compositionEntry?.uid, composableUid]);\n};\n"],"names":[],"mappings":";;;;;AAYO,MAAM,uBAAuB,GAAG,CACrC,QAA0D,EAC1D,KAAkB,EAClB,aAAsB,KACpB;IACF,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,wBAAwB,CAAC,aAAa,IAAI,EAAE,CAAC;YAAE;AACpD,QAAA,MAAM,yBAAyB,GAAG,4BAA4B,EAAE,EAAE,CAE/D,mBAAmB,CAAC,mBAAmB,EAAE,CAAC,KAAK,KAAI;AACpD,YAAA,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK;AACtB,YAAA,IAAI,CAAC,IAAI;gBAAE;AACX,YAAA,QAAQ,CAAC,CAAC,SAAqB,KAAI;AACjC,gBAAA,IAAI,CAAC,SAAS;AAAE,oBAAA,OAAO,SAAS;gBAChC,OAAO;AACL,oBAAA,GAAG,SAAS;AACZ,oBAAA,IAAI,EAAE;wBACJ,GAAG,SAAS,CAAC,IAAI;wBACjB,CAAC,YAAY,CAAC,YAAY,GAAG,sBAAsB,CACjD,IAAI,CAAC,WAAW,CACjB;AACF,qBAAA;iBACF;AACH,YAAA,CAAC,CAAC;AACJ,QAAA,CAAC,CAAC;AAEF,QAAA,OAAO,MAAK;YACV,yBAAyB,EAAE,UAAU,EAAE;AACzC,QAAA,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;AACnD;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isCompositionBeingEdited } from '@contentstack/studio-client';
|
|
2
|
+
import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { useRegisterSymbolComponents } from './use-register-symbol.hook.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This hook is used to listen to the symbols events and update the state with the latest symbols.
|
|
8
|
+
*/
|
|
9
|
+
const useSymbolsEvents = (setState, state, composableUid) => {
|
|
10
|
+
useRegisterSymbolComponents(state?.symbols || []);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!isCompositionBeingEdited(composableUid || ""))
|
|
13
|
+
return;
|
|
14
|
+
const symbolEventListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.UPDATE_SYMBOLS, (event) => {
|
|
15
|
+
const { data } = event;
|
|
16
|
+
if (!data?.symbols)
|
|
17
|
+
return;
|
|
18
|
+
setState((prevState) => {
|
|
19
|
+
return {
|
|
20
|
+
...prevState,
|
|
21
|
+
symbols: data.symbols,
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
return () => {
|
|
26
|
+
symbolEventListener?.unregister();
|
|
27
|
+
};
|
|
28
|
+
}, [state?.compositionEntry?.uid, composableUid]);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { useSymbolsEvents };
|
|
32
|
+
//# sourceMappingURL=use-symbol-events.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-symbol-events.hook.js","sources":["../../src/hooks/use-symbol-events.hook.ts"],"sourcesContent":["import {\n StudioSpec,\n isCompositionBeingEdited,\n SymbolEntry,\n} from \"@contentstack/studio-client\";\nimport {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} from \"@contentstack/studio-messenger\";\nimport { useEffect } from \"react\";\nimport { useRegisterSymbolComponents } from \"./use-register-symbol.hook\";\n\n/**\n * This hook is used to listen to the symbols events and update the state with the latest symbols.\n */\nexport const useSymbolsEvents = (\n setState: React.Dispatch<React.SetStateAction<StudioSpec>>,\n state?: StudioSpec,\n composableUid?: string,\n) => {\n useRegisterSymbolComponents(state?.symbols || []);\n useEffect(() => {\n if (!isCompositionBeingEdited(composableUid || \"\")) return;\n const symbolEventListener = composableStudioEventManager?.on<{\n symbols: SymbolEntry[];\n }>(POST_MESSAGE_EVENTS.UPDATE_SYMBOLS, (event) => {\n const { data } = event;\n if (!data?.symbols) return;\n setState((prevState: StudioSpec) => {\n return {\n ...prevState,\n symbols: data.symbols,\n };\n });\n });\n return () => {\n symbolEventListener?.unregister();\n };\n }, [state?.compositionEntry?.uid, composableUid]);\n};\n"],"names":[],"mappings":";;;;;AAYA;;AAEG;AACI,MAAM,gBAAgB,GAAG,CAC9B,QAA0D,EAC1D,KAAkB,EAClB,aAAsB,KACpB;AACF,IAAA,2BAA2B,CAAC,KAAK,EAAE,OAAO,IAAI,EAAE,CAAC;IACjD,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,wBAAwB,CAAC,aAAa,IAAI,EAAE,CAAC;YAAE;AACpD,QAAA,MAAM,mBAAmB,GAAG,4BAA4B,EAAE,EAAE,CAEzD,mBAAmB,CAAC,cAAc,EAAE,CAAC,KAAK,KAAI;AAC/C,YAAA,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK;YACtB,IAAI,CAAC,IAAI,EAAE,OAAO;gBAAE;AACpB,YAAA,QAAQ,CAAC,CAAC,SAAqB,KAAI;gBACjC,OAAO;AACL,oBAAA,GAAG,SAAS;oBACZ,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB;AACH,YAAA,CAAC,CAAC;AACJ,QAAA,CAAC,CAAC;AACF,QAAA,OAAO,MAAK;YACV,mBAAmB,EAAE,UAAU,EAAE;AACnC,QAAA,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;AACnD;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SymbolUICtx } from '@contentstack/studio-react-components/contexts';
|
|
2
|
+
import { useContext, useMemo } from 'react';
|
|
3
|
+
|
|
4
|
+
const useSymbolUIListener = (spec, symbolUID) => {
|
|
5
|
+
const symbolUIs = useContext(SymbolUICtx);
|
|
6
|
+
const symbol = symbolUIs[symbolUID];
|
|
7
|
+
const activeSpec = useMemo(() => {
|
|
8
|
+
return {
|
|
9
|
+
...spec,
|
|
10
|
+
ui: symbol.ui,
|
|
11
|
+
};
|
|
12
|
+
}, [symbol]);
|
|
13
|
+
return activeSpec;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { useSymbolUIListener };
|
|
17
|
+
//# sourceMappingURL=use-symbol-ui-listener.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-symbol-ui-listener.hook.js","sources":["../../src/hooks/use-symbol-ui-listener.hook.ts"],"sourcesContent":["import { StudioSpec } from \"@contentstack/studio-client\";\nimport { SymbolUICtx } from \"@contentstack/studio-react-components/contexts\";\nimport { useContext, useMemo } from \"react\";\n\nexport const useSymbolUIListener = (\n spec: Omit<StudioSpec, \"compositionEntry\">,\n symbolUID: string,\n) => {\n const symbolUIs = useContext(SymbolUICtx);\n const symbol = symbolUIs[symbolUID];\n const activeSpec = useMemo(() => {\n return {\n ...spec,\n ui: symbol.ui,\n };\n }, [symbol]);\n return activeSpec;\n};\n"],"names":[],"mappings":";;;MAIa,mBAAmB,GAAG,CACjC,IAA0C,EAC1C,SAAiB,KACf;AACF,IAAA,MAAM,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC;AACzC,IAAA,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC;AACnC,IAAA,MAAM,UAAU,GAAG,OAAO,CAAC,MAAK;QAC9B,OAAO;AACL,YAAA,GAAG,IAAI;YACP,EAAE,EAAE,MAAM,CAAC,EAAE;SACd;AACH,IAAA,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AACZ,IAAA,OAAO,UAAU;AACnB;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { StudioSpec } from '@contentstack/studio-client';
|
|
3
|
+
import { ComponentRegistry, ComposableStudioData } from '@contentstack/studio-registry';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
type ComponentRegistryType = ComponentRegistry<(props?: any) => ReactNode>;
|
|
7
|
+
|
|
8
|
+
interface EditableRendererHOCProps {
|
|
9
|
+
spec: StudioSpec;
|
|
10
|
+
data: ComposableStudioData;
|
|
11
|
+
componentRegistry: ComponentRegistryType;
|
|
12
|
+
renderError: (props: {
|
|
13
|
+
error: Error;
|
|
14
|
+
}) => JSX.Element;
|
|
15
|
+
}
|
|
16
|
+
declare function EditableRendererHOC(props: EditableRendererHOCProps & {
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
}): react_jsx_runtime.JSX.Element;
|
|
19
|
+
|
|
20
|
+
export { EditableRendererHOC as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const shouldRenderSlot = (componentRegistry, parent, nodes, isCompositionBeingEdited) => {
|
|
2
|
+
if (!isCompositionBeingEdited)
|
|
3
|
+
return false;
|
|
4
|
+
if (!componentRegistry?.hasComponent(parent)) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const isEmpty = nodes.length === 0;
|
|
8
|
+
return isEmpty;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { shouldRenderSlot };
|
|
12
|
+
//# sourceMappingURL=renderer.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.util.js","sources":["../../src/utils/renderer.util.ts"],"sourcesContent":["import type { Node } from \"@contentstack/studio-internal\";\nimport { ComponentRegistry } from \"@contentstack/studio-registry\";\nimport { ReactNode } from \"react\";\n\nexport const shouldRenderSlot = (\n componentRegistry: ComponentRegistry<(props?: any) => ReactNode>,\n parent: Node,\n nodes: Node[],\n isCompositionBeingEdited: boolean,\n) => {\n if (!isCompositionBeingEdited) return false;\n if (!componentRegistry?.hasComponent(parent)) {\n return false;\n }\n const isEmpty = nodes.length === 0;\n\n return isEmpty;\n};\n"],"names":[],"mappings":"AAIO,MAAM,gBAAgB,GAAG,CAC9B,iBAAgE,EAChE,MAAY,EACZ,KAAa,EACb,wBAAiC,KAC/B;AACF,IAAA,IAAI,CAAC,wBAAwB;AAAE,QAAA,OAAO,KAAK;IAC3C,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE;AAC5C,QAAA,OAAO,KAAK;IACd;AACA,IAAA,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,KAAK,CAAC;AAElC,IAAA,OAAO,OAAO;AAChB;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contentstack/studio-react-editor",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Contains all logic of editing for react based environment",
|
|
5
|
+
"author": "RavenColEvol <ravilamkoti@gmail.com>",
|
|
6
|
+
"homepage": "https://github.com/contentstack/composable-studio-sdk#readme",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"module": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist/"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/contentstack/composable-studio-sdk.git"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"dev": "rollup -c ./rollup.config.mjs --watch",
|
|
29
|
+
"build": "rollup -c ./rollup.config.mjs",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"test:watch": "vitest watch",
|
|
32
|
+
"test:coverage": "vitest run --coverage"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/contentstack/composable-studio-sdk/issues"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": ">=16.0.0",
|
|
39
|
+
"react-dom": ">=16.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@contentstack/common-config": "1.0.2",
|
|
43
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
44
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
45
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
46
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
47
|
+
"@types/lodash": "^4.17.5",
|
|
48
|
+
"@types/react": "^18.3.5",
|
|
49
|
+
"@types/react-dom": "^18.3.5",
|
|
50
|
+
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
51
|
+
"@typescript-eslint/parser": "^7.2.0",
|
|
52
|
+
"esbuild-plugin-preserve-directives": "^0.0.11",
|
|
53
|
+
"eslint": "^8.57.0",
|
|
54
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
55
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
56
|
+
"jsdom": "^24.1.0",
|
|
57
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
58
|
+
"rollup-plugin-node-externals": "^8.0.1",
|
|
59
|
+
"rollup-plugin-preserve-directives": "^0.4.0",
|
|
60
|
+
"typescript": "^5.2.2"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@contentstack/studio-client": "file:../studio-client",
|
|
64
|
+
"@contentstack/studio-core": "file:../studio-core",
|
|
65
|
+
"@contentstack/studio-internal": "file:../studio-internal",
|
|
66
|
+
"@contentstack/studio-messenger": "file:../studio-messenger",
|
|
67
|
+
"@contentstack/studio-react-components": "file:../studio-react-components",
|
|
68
|
+
"@contentstack/studio-registry": "file:../studio-registry",
|
|
69
|
+
"classnames": "^2.5.1",
|
|
70
|
+
"goober": "^2.1.16",
|
|
71
|
+
"immer": "^10.1.1",
|
|
72
|
+
"lodash-es": "^4.17.21",
|
|
73
|
+
"react-error-boundary": "^6.0.0"
|
|
74
|
+
}
|
|
75
|
+
}
|