@webiny/website-builder-react 6.6.0-alpha.1 → 6.6.0-alpha.11

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.
Files changed (98) hide show
  1. package/components/ConnectToEditor.d.ts +3 -1
  2. package/components/ConnectToEditor.js +7 -5
  3. package/components/ConnectToEditor.js.map +1 -1
  4. package/components/ContentClientContext.d.ts +3 -0
  5. package/components/ContentClientContext.js +6 -0
  6. package/components/ContentClientContext.js.map +1 -0
  7. package/components/ContentClientProvider.d.ts +12 -0
  8. package/components/ContentClientProvider.js +9 -0
  9. package/components/ContentClientProvider.js.map +1 -0
  10. package/components/ContentClientProvider.test.d.ts +1 -0
  11. package/components/ContentClientProvider.test.js +143 -0
  12. package/components/ContentClientProvider.test.js.map +1 -0
  13. package/components/DocumentRenderer.d.ts +8 -3
  14. package/components/DocumentRenderer.js +22 -10
  15. package/components/DocumentRenderer.js.map +1 -1
  16. package/components/DocumentStoreProvider.d.ts +7 -0
  17. package/components/DocumentStoreProvider.js +24 -5
  18. package/components/DocumentStoreProvider.js.map +1 -1
  19. package/components/DocumentStoreProvider.test.d.ts +1 -0
  20. package/components/DocumentStoreProvider.test.js +66 -0
  21. package/components/DocumentStoreProvider.test.js.map +1 -0
  22. package/components/EditingElementRenderer/EditingElementRenderer.d.ts +5 -0
  23. package/components/EditingElementRenderer/EditingElementRenderer.js +21 -9
  24. package/components/EditingElementRenderer/EditingElementRenderer.js.map +1 -1
  25. package/components/EditingElementRenderer/EditingElementRenderer.presenter.d.ts +2 -2
  26. package/components/EditingElementRenderer/EditingElementRenderer.presenter.js +4 -3
  27. package/components/EditingElementRenderer/EditingElementRenderer.presenter.js.map +1 -1
  28. package/components/ElementRenderer.js +17 -4
  29. package/components/ElementRenderer.js.map +1 -1
  30. package/components/ElementSlot.js +5 -2
  31. package/components/ElementSlot.js.map +1 -1
  32. package/components/FragmentsProvider.js +4 -3
  33. package/components/FragmentsProvider.js.map +1 -1
  34. package/components/GlobalComponent.d.ts +10 -0
  35. package/components/GlobalComponent.js +17 -0
  36. package/components/GlobalComponent.js.map +1 -0
  37. package/components/GlobalPlacement.d.ts +11 -0
  38. package/components/GlobalPlacement.js +27 -0
  39. package/components/GlobalPlacement.js.map +1 -0
  40. package/components/LayoutAreas.d.ts +19 -0
  41. package/components/LayoutAreas.js +15 -0
  42. package/components/LayoutAreas.js.map +1 -0
  43. package/components/LayoutRenderer.d.ts +14 -0
  44. package/components/LayoutRenderer.js +60 -0
  45. package/components/LayoutRenderer.js.map +1 -0
  46. package/components/LayoutRenderer.test.d.ts +1 -0
  47. package/components/LayoutRenderer.test.js +138 -0
  48. package/components/LayoutRenderer.test.js.map +1 -0
  49. package/components/LiveElementRenderer.js +9 -3
  50. package/components/LiveElementRenderer.js.map +1 -1
  51. package/components/PageLayout.d.ts +40 -0
  52. package/components/PageLayout.js +71 -0
  53. package/components/PageLayout.js.map +1 -0
  54. package/components/PreviewElementSlot.js +11 -1
  55. package/components/PreviewElementSlot.js.map +1 -1
  56. package/components/SlotLabel.d.ts +15 -0
  57. package/components/SlotLabel.js +13 -0
  58. package/components/SlotLabel.js.map +1 -0
  59. package/components/index.d.ts +7 -0
  60. package/components/index.js +6 -0
  61. package/components/renderWithLayout.d.ts +5 -0
  62. package/components/renderWithLayout.js +7 -0
  63. package/components/renderWithLayout.js.map +1 -0
  64. package/components/useContentClient.d.ts +6 -0
  65. package/components/useContentClient.js +11 -0
  66. package/components/useContentClient.js.map +1 -0
  67. package/components/useIsElementSelected.d.ts +8 -0
  68. package/components/useIsElementSelected.js +22 -0
  69. package/components/useIsElementSelected.js.map +1 -0
  70. package/components/useSeededDocumentStore.d.ts +10 -0
  71. package/components/useSeededDocumentStore.js +22 -0
  72. package/components/useSeededDocumentStore.js.map +1 -0
  73. package/contentEntry/useContentEntryList.d.ts +22 -0
  74. package/contentEntry/useContentEntryList.js +51 -0
  75. package/contentEntry/useContentEntryList.js.map +1 -0
  76. package/editorComponents/Grid.d.ts +1 -1
  77. package/editorComponents/Grid.js +3 -2
  78. package/editorComponents/Grid.js.map +1 -1
  79. package/editorComponents/LayoutContent.d.ts +6 -0
  80. package/editorComponents/LayoutContent.js +121 -0
  81. package/editorComponents/LayoutContent.js.map +1 -0
  82. package/editorComponents/LayoutContent.manifest.d.ts +10 -0
  83. package/editorComponents/LayoutContent.manifest.js +32 -0
  84. package/editorComponents/LayoutContent.manifest.js.map +1 -0
  85. package/editorComponents/LayoutContentLabel.d.ts +2 -0
  86. package/editorComponents/LayoutContentLabel.js +7 -0
  87. package/editorComponents/LayoutContentLabel.js.map +1 -0
  88. package/editorComponents/LayoutContentLabel.test.d.ts +1 -0
  89. package/editorComponents/LayoutContentLabel.test.js +23 -0
  90. package/editorComponents/LayoutContentLabel.test.js.map +1 -0
  91. package/editorComponents/index.js +4 -1
  92. package/editorComponents/index.js.map +1 -1
  93. package/image/getImageProps.test.js +1 -1
  94. package/image/getImageProps.test.js.map +1 -1
  95. package/index.d.ts +2 -1
  96. package/index.js +2 -1
  97. package/package.json +11 -9
  98. package/types.d.ts +2 -0
@@ -1 +1 @@
1
- {"version":3,"file":"components/LiveElementRenderer.js","sources":["../../src/components/LiveElementRenderer.tsx"],"sourcesContent":["\"use client\";\nimport React, { useCallback, useEffect, useState } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport type {\n DocumentElement,\n DocumentElementBindings,\n OnResolved\n} from \"@webiny/website-builder-sdk\";\nimport { contentSdk } from \"@webiny/website-builder-sdk\";\nimport { ElementSlot } from \"./ElementSlot.js\";\nimport { useViewport } from \"./useViewportInfo.js\";\nimport { useBindingsForElement } from \"./useBindingsForElement.js\";\nimport { useDocumentState } from \"./useDocumentState.js\";\n\ninterface LiveElementRendererProps {\n element: DocumentElement;\n bindings?: DocumentElementBindings;\n}\n\nexport const LiveElementRenderer = observer(({ element }: LiveElementRendererProps) => {\n const viewport = useViewport();\n\n // 1. Start breakpoint as \"desktop\" on both server and initial client render.\n const [breakpoint, setBreakpoint] = useState<\"desktop\" | string>(\"desktop\");\n\n // 2. Update breakpoint on the client after mount, using real viewport value.\n useEffect(() => {\n if (viewport.breakpoint && viewport.breakpoint !== breakpoint) {\n setBreakpoint(viewport.breakpoint);\n }\n }, [viewport.breakpoint, breakpoint]);\n\n // Bindings for current breakpoint\n const elementBindings = useBindingsForElement(element.id, breakpoint); // pass breakpoint explicitly if possible\n const state = useDocumentState();\n\n const onResolved = useCallback(\n ((value, input) => {\n if (input.type === \"slot\") {\n return (\n <ElementSlot\n key={element.id}\n parentId={element.id}\n slot={input.name}\n elements={input.list ? value : [value]}\n />\n );\n }\n return value;\n }) as OnResolved,\n [element.id]\n );\n\n if (!element || !element.component) {\n return null;\n }\n\n const instances = contentSdk.resolveElement({\n element,\n state,\n elementBindings,\n onResolved\n });\n\n if (!instances) {\n return null;\n }\n\n return (\n <>\n {instances.map((resolvedElement, index) => {\n const { component: Component, inputs, styles, manifest } = resolvedElement;\n const props = { inputs, styles, element, breakpoint: viewport.breakpoint };\n const autoApplyStyles = manifest.autoApplyStyles !== false;\n\n const userElement = <Component key={element.id} {...props} />;\n\n if (!autoApplyStyles) {\n return userElement;\n }\n\n return (\n <div key={index} style={styles}>\n {userElement}\n </div>\n );\n })}\n </>\n );\n});\n"],"names":["LiveElementRenderer","observer","element","viewport","useViewport","breakpoint","setBreakpoint","useState","useEffect","elementBindings","useBindingsForElement","state","useDocumentState","onResolved","useCallback","value","input","ElementSlot","instances","contentSdk","resolvedElement","index","Component","inputs","styles","manifest","props","autoApplyStyles","userElement"],"mappings":";;;;;;;;AAmBO,MAAMA,sBAAsBC,SAAS,CAAC,EAAEC,OAAO,EAA4B;IAC9E,MAAMC,WAAWC;IAGjB,MAAM,CAACC,YAAYC,cAAc,GAAGC,SAA6B;IAGjEC,UAAU;QACN,IAAIL,SAAS,UAAU,IAAIA,SAAS,UAAU,KAAKE,YAC/CC,cAAcH,SAAS,UAAU;IAEzC,GAAG;QAACA,SAAS,UAAU;QAAEE;KAAW;IAGpC,MAAMI,kBAAkBC,sBAAsBR,QAAQ,EAAE,EAAEG;IAC1D,MAAMM,QAAQC;IAEd,MAAMC,aAAaC,YACd,CAACC,OAAOC;QACL,IAAIA,AAAe,WAAfA,MAAM,IAAI,EACV,OAAO,WAAP,GACI,oBAACC,aAAWA;YACR,KAAKf,QAAQ,EAAE;YACf,UAAUA,QAAQ,EAAE;YACpB,MAAMc,MAAM,IAAI;YAChB,UAAUA,MAAM,IAAI,GAAGD,QAAQ;gBAACA;aAAM;;QAIlD,OAAOA;IACX,GACA;QAACb,QAAQ,EAAE;KAAC;IAGhB,IAAI,CAACA,WAAW,CAACA,QAAQ,SAAS,EAC9B,OAAO;IAGX,MAAMgB,YAAYC,WAAW,cAAc,CAAC;QACxCjB;QACAS;QACAF;QACAI;IACJ;IAEA,IAAI,CAACK,WACD,OAAO;IAGX,OAAO,WAAP,GACI,0CACKA,UAAU,GAAG,CAAC,CAACE,iBAAiBC;QAC7B,MAAM,EAAE,WAAWC,SAAS,EAAEC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAE,GAAGL;QAC3D,MAAMM,QAAQ;YAAEH;YAAQC;YAAQtB;YAAS,YAAYC,SAAS,UAAU;QAAC;QACzE,MAAMwB,kBAAkBF,AAA6B,UAA7BA,SAAS,eAAe;QAEhD,MAAMG,cAAc,WAAdA,GAAc,oBAACN,WAAAA;YAAU,KAAKpB,QAAQ,EAAE;YAAG,GAAGwB,KAAK;;QAEzD,IAAI,CAACC,iBACD,OAAOC;QAGX,OAAO,WAAP,GACI,oBAAC;YAAI,KAAKP;YAAO,OAAOG;WACnBI;IAGb;AAGZ"}
1
+ {"version":3,"file":"components/LiveElementRenderer.js","sources":["../../src/components/LiveElementRenderer.tsx"],"sourcesContent":["\"use client\";\nimport React, { useCallback, useEffect, useState } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport type {\n DocumentElement,\n DocumentElementBindings,\n OnResolved\n} from \"@webiny/website-builder-sdk\";\nimport { ElementSlot } from \"./ElementSlot.js\";\nimport { useViewport } from \"./useViewportInfo.js\";\nimport { useBindingsForElement } from \"./useBindingsForElement.js\";\nimport { useDocumentState } from \"./useDocumentState.js\";\nimport { useDocumentStore } from \"./DocumentStoreProvider.js\";\nimport { useContentClient } from \"./useContentClient.js\";\n\ninterface LiveElementRendererProps {\n element: DocumentElement;\n bindings?: DocumentElementBindings;\n}\n\nexport const LiveElementRenderer = observer(({ element }: LiveElementRendererProps) => {\n const viewport = useViewport();\n const client = useContentClient();\n\n // 1. Start breakpoint as \"desktop\" on both server and initial client render.\n const [breakpoint, setBreakpoint] = useState<\"desktop\" | string>(\"desktop\");\n\n // 2. Update breakpoint on the client after mount, using real viewport value.\n useEffect(() => {\n if (viewport.breakpoint && viewport.breakpoint !== breakpoint) {\n setBreakpoint(viewport.breakpoint);\n }\n }, [viewport.breakpoint, breakpoint]);\n\n // Bindings for current breakpoint\n const elementBindings = useBindingsForElement(element.id, breakpoint); // pass breakpoint explicitly if possible\n const state = useDocumentState();\n const documentStore = useDocumentStore();\n const document = documentStore.getDocument();\n\n const onResolved = useCallback(\n ((value, input) => {\n if (input.type === \"slot\") {\n return (\n <ElementSlot\n key={element.id}\n parentId={element.id}\n slot={input.name}\n elements={input.list ? value : [value]}\n />\n );\n }\n return value;\n }) as OnResolved,\n [element.id]\n );\n\n if (!element || !element.component) {\n return null;\n }\n\n const instances = client.resolveElement({\n element,\n state,\n elementBindings,\n cache: document?.__cache,\n onResolved\n });\n\n if (!instances) {\n return null;\n }\n\n return (\n <>\n {instances.map((resolvedElement, index) => {\n const { component: Component, inputs, styles, manifest } = resolvedElement;\n const props = {\n inputs,\n styles,\n element,\n breakpoint: viewport.breakpoint,\n breakpoints: viewport.breakpoints.map(bp => bp.name)\n };\n const autoApplyStyles = manifest.autoApplyStyles !== false;\n\n const userElement = <Component key={element.id} {...props} />;\n\n if (!autoApplyStyles) {\n return userElement;\n }\n\n return (\n <div key={index} style={styles}>\n {userElement}\n </div>\n );\n })}\n </>\n );\n});\n"],"names":["LiveElementRenderer","observer","element","viewport","useViewport","client","useContentClient","breakpoint","setBreakpoint","useState","useEffect","elementBindings","useBindingsForElement","state","useDocumentState","documentStore","useDocumentStore","document","onResolved","useCallback","value","input","ElementSlot","instances","resolvedElement","index","Component","inputs","styles","manifest","props","bp","autoApplyStyles","userElement"],"mappings":";;;;;;;;;AAoBO,MAAMA,sBAAsBC,SAAS,CAAC,EAAEC,OAAO,EAA4B;IAC9E,MAAMC,WAAWC;IACjB,MAAMC,SAASC;IAGf,MAAM,CAACC,YAAYC,cAAc,GAAGC,SAA6B;IAGjEC,UAAU;QACN,IAAIP,SAAS,UAAU,IAAIA,SAAS,UAAU,KAAKI,YAC/CC,cAAcL,SAAS,UAAU;IAEzC,GAAG;QAACA,SAAS,UAAU;QAAEI;KAAW;IAGpC,MAAMI,kBAAkBC,sBAAsBV,QAAQ,EAAE,EAAEK;IAC1D,MAAMM,QAAQC;IACd,MAAMC,gBAAgBC;IACtB,MAAMC,WAAWF,cAAc,WAAW;IAE1C,MAAMG,aAAaC,YACd,CAACC,OAAOC;QACL,IAAIA,AAAe,WAAfA,MAAM,IAAI,EACV,OAAO,WAAP,GACI,oBAACC,aAAWA;YACR,KAAKpB,QAAQ,EAAE;YACf,UAAUA,QAAQ,EAAE;YACpB,MAAMmB,MAAM,IAAI;YAChB,UAAUA,MAAM,IAAI,GAAGD,QAAQ;gBAACA;aAAM;;QAIlD,OAAOA;IACX,GACA;QAAClB,QAAQ,EAAE;KAAC;IAGhB,IAAI,CAACA,WAAW,CAACA,QAAQ,SAAS,EAC9B,OAAO;IAGX,MAAMqB,YAAYlB,OAAO,cAAc,CAAC;QACpCH;QACAW;QACAF;QACA,OAAOM,UAAU;QACjBC;IACJ;IAEA,IAAI,CAACK,WACD,OAAO;IAGX,OAAO,WAAP,GACI,0CACKA,UAAU,GAAG,CAAC,CAACC,iBAAiBC;QAC7B,MAAM,EAAE,WAAWC,SAAS,EAAEC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAE,GAAGL;QAC3D,MAAMM,QAAQ;YACVH;YACAC;YACA1B;YACA,YAAYC,SAAS,UAAU;YAC/B,aAAaA,SAAS,WAAW,CAAC,GAAG,CAAC4B,CAAAA,KAAMA,GAAG,IAAI;QACvD;QACA,MAAMC,kBAAkBH,AAA6B,UAA7BA,SAAS,eAAe;QAEhD,MAAMI,cAAc,WAAdA,GAAc,oBAACP,WAAAA;YAAU,KAAKxB,QAAQ,EAAE;YAAG,GAAG4B,KAAK;;QAEzD,IAAI,CAACE,iBACD,OAAOC;QAGX,OAAO,WAAP,GACI,oBAAC;YAAI,KAAKR;YAAO,OAAOG;WACnBK;IAGb;AAGZ"}
@@ -0,0 +1,40 @@
1
+ import React from "react";
2
+ import type { DocumentStore } from "@webiny/website-builder-sdk";
3
+ import { type DocumentLayout } from "./renderWithLayout.js";
4
+ interface PageLayoutContextValue {
5
+ pageStore: DocumentStore;
6
+ }
7
+ /**
8
+ * Set while rendering the elements of a page's layout. They belong to the layout, not to the page: in the
9
+ * page editor, they can be selected (to override their inputs on the page), but not moved or dropped into.
10
+ */
11
+ export declare const usePageLayout: () => PageLayoutContextValue | undefined;
12
+ /**
13
+ * Render from the page again, from within its layout: the page content, and the instances of the global
14
+ * components the layout places (they come with the page, and the page editor edits them there).
15
+ */
16
+ export declare const PageScope: ({ children }: {
17
+ children: React.ReactNode;
18
+ }) => React.JSX.Element;
19
+ /**
20
+ * Everything inside renders as on the live site, even in the editor: it can't be selected or dropped into
21
+ * (e.g., the page previewed inside a layout in the layout editor).
22
+ */
23
+ export declare const ReadOnlyScope: ({ children }: {
24
+ children: React.ReactNode;
25
+ }) => React.JSX.Element;
26
+ export declare const useIsReadOnlyScope: () => boolean;
27
+ /**
28
+ * Render the page in its layout: the one picked in the page settings, built in the layout editor, or
29
+ * else the `layout` the frontend passes to <DocumentRenderer>.
30
+ */
31
+ export declare const PageWithLayout: (({ layout }: {
32
+ layout?: DocumentLayout;
33
+ }) => string | number | bigint | boolean | React.JSX.Element | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | Iterable<React.ReactNode> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | React.ReactPortal | null | undefined> | null | undefined) & React.NamedExoticComponent<{
34
+ layout?: DocumentLayout;
35
+ }> & {
36
+ readonly type: ({ layout }: {
37
+ layout?: DocumentLayout;
38
+ }) => string | number | bigint | boolean | React.JSX.Element | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | Iterable<React.ReactNode> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | React.ReactPortal | null | undefined> | null | undefined;
39
+ };
40
+ export {};
@@ -0,0 +1,71 @@
1
+ "use client";
2
+ import react, { useContext, useMemo } from "react";
3
+ import { observer } from "mobx-react-lite";
4
+ import { toJS } from "mobx";
5
+ import { DocumentStoreScope, useDocumentStore } from "./DocumentStoreProvider.js";
6
+ import { ElementRenderer } from "./ElementRenderer.js";
7
+ import { useSeededDocumentStore } from "./useSeededDocumentStore.js";
8
+ import { renderWithLayout } from "./renderWithLayout.js";
9
+ const PageLayoutContext = /*#__PURE__*/ react.createContext(void 0);
10
+ const usePageLayout = ()=>useContext(PageLayoutContext);
11
+ const PageScope = ({ children })=>{
12
+ const pageLayout = usePageLayout();
13
+ if (!pageLayout) return /*#__PURE__*/ react.createElement(react.Fragment, null, children);
14
+ return /*#__PURE__*/ react.createElement(PageLayoutContext.Provider, {
15
+ value: void 0
16
+ }, /*#__PURE__*/ react.createElement(DocumentStoreScope, {
17
+ store: pageLayout.pageStore
18
+ }, children));
19
+ };
20
+ const ReadOnlyContext = /*#__PURE__*/ react.createContext(false);
21
+ const ReadOnlyScope = ({ children })=>/*#__PURE__*/ react.createElement(ReadOnlyContext.Provider, {
22
+ value: true
23
+ }, children);
24
+ const useIsReadOnlyScope = ()=>useContext(ReadOnlyContext);
25
+ const toLayoutDocument = (layout)=>({
26
+ id: layout.id,
27
+ version: 1,
28
+ state: {},
29
+ properties: {
30
+ id: layout.id
31
+ },
32
+ metadata: {
33
+ documentType: "layout"
34
+ },
35
+ extensions: {},
36
+ elements: layout.elements ?? {},
37
+ bindings: layout.bindings ?? {}
38
+ });
39
+ const PageLayoutRenderer = ({ layoutJson })=>{
40
+ const pageStore = useDocumentStore();
41
+ const context = useMemo(()=>({
42
+ pageStore
43
+ }), [
44
+ pageStore
45
+ ]);
46
+ const document = useMemo(()=>JSON.parse(layoutJson), [
47
+ layoutJson
48
+ ]);
49
+ const layoutStore = useSeededDocumentStore(document);
50
+ return /*#__PURE__*/ react.createElement(PageLayoutContext.Provider, {
51
+ value: context
52
+ }, /*#__PURE__*/ react.createElement(DocumentStoreScope, {
53
+ store: layoutStore
54
+ }, /*#__PURE__*/ react.createElement(ElementRenderer, {
55
+ id: "root"
56
+ })));
57
+ };
58
+ const PageWithLayout = observer(({ layout })=>{
59
+ const pageStore = useDocumentStore();
60
+ const page = pageStore.getDocument();
61
+ const layoutJson = page?.layout ? JSON.stringify(toLayoutDocument(toJS(page.layout))) : null;
62
+ if (layoutJson) return /*#__PURE__*/ react.createElement(PageLayoutRenderer, {
63
+ layoutJson: layoutJson
64
+ });
65
+ return renderWithLayout(/*#__PURE__*/ react.createElement(ElementRenderer, {
66
+ id: "root"
67
+ }), layout);
68
+ });
69
+ export { PageScope, PageWithLayout, ReadOnlyScope, useIsReadOnlyScope, usePageLayout };
70
+
71
+ //# sourceMappingURL=PageLayout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components/PageLayout.js","sources":["../../src/components/PageLayout.tsx"],"sourcesContent":["\"use client\";\nimport React, { useContext, useMemo } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { toJS } from \"mobx\";\nimport type {\n Document,\n DocumentStore,\n PageLayout as PageLayoutData\n} from \"@webiny/website-builder-sdk\";\nimport { DocumentStoreScope, useDocumentStore } from \"./DocumentStoreProvider.js\";\nimport { ElementRenderer } from \"./ElementRenderer.js\";\nimport { useSeededDocumentStore } from \"./useSeededDocumentStore.js\";\nimport { type DocumentLayout, renderWithLayout } from \"./renderWithLayout.js\";\n\ninterface PageLayoutContextValue {\n // The store of the page the layout is rendered around.\n pageStore: DocumentStore;\n}\n\nconst PageLayoutContext = React.createContext<PageLayoutContextValue | undefined>(undefined);\n\n/**\n * Set while rendering the elements of a page's layout. They belong to the layout, not to the page: in the\n * page editor, they can be selected (to override their inputs on the page), but not moved or dropped into.\n */\nexport const usePageLayout = () => {\n return useContext(PageLayoutContext);\n};\n\n/**\n * Render from the page again, from within its layout: the page content, and the instances of the global\n * components the layout places (they come with the page, and the page editor edits them there).\n */\nexport const PageScope = ({ children }: { children: React.ReactNode }) => {\n const pageLayout = usePageLayout();\n if (!pageLayout) {\n return <>{children}</>;\n }\n\n return (\n <PageLayoutContext.Provider value={undefined}>\n <DocumentStoreScope store={pageLayout.pageStore}>{children}</DocumentStoreScope>\n </PageLayoutContext.Provider>\n );\n};\n\nconst ReadOnlyContext = React.createContext(false);\n\n/**\n * Everything inside renders as on the live site, even in the editor: it can't be selected or dropped into\n * (e.g., the page previewed inside a layout in the layout editor).\n */\nexport const ReadOnlyScope = ({ children }: { children: React.ReactNode }) => {\n return <ReadOnlyContext.Provider value={true}>{children}</ReadOnlyContext.Provider>;\n};\n\nexport const useIsReadOnlyScope = () => {\n return useContext(ReadOnlyContext);\n};\n\n/**\n * The layout comes complete: on the live site the backend merges the page's overrides of the layout's\n * elements into it, and the page editor sends it to the preview the same way.\n */\nconst toLayoutDocument = (layout: PageLayoutData): Document => {\n return {\n id: layout.id,\n version: 1,\n state: {},\n properties: { id: layout.id },\n metadata: { documentType: \"layout\" },\n extensions: {},\n elements: layout.elements ?? {},\n bindings: layout.bindings ?? {}\n };\n};\n\nconst PageLayoutRenderer = ({ layoutJson }: { layoutJson: string }) => {\n const pageStore = useDocumentStore();\n const context = useMemo(() => ({ pageStore }), [pageStore]);\n // The layout comes with the page's overrides merged in, so it is different for every page: each render\n // gets its own store, never one shared by layout id across pages (or across requests on the server).\n const document = useMemo<Document>(() => JSON.parse(layoutJson), [layoutJson]);\n // A changed layout (e.g. patched in the page editor) goes into the same store.\n const layoutStore = useSeededDocumentStore(document);\n\n return (\n <PageLayoutContext.Provider value={context}>\n <DocumentStoreScope store={layoutStore}>\n <ElementRenderer id={\"root\"} />\n </DocumentStoreScope>\n </PageLayoutContext.Provider>\n );\n};\n\n/**\n * Render the page in its layout: the one picked in the page settings, built in the layout editor, or\n * else the `layout` the frontend passes to <DocumentRenderer>.\n */\nexport const PageWithLayout = observer(({ layout }: { layout?: DocumentLayout }) => {\n const pageStore = useDocumentStore();\n const page = pageStore.getDocument();\n // In the page editor, the layout is patched in place: reading all of it re-renders on any change.\n const layoutJson = page?.layout ? JSON.stringify(toLayoutDocument(toJS(page.layout))) : null;\n\n if (layoutJson) {\n return <PageLayoutRenderer layoutJson={layoutJson} />;\n }\n\n return renderWithLayout(<ElementRenderer id={\"root\"} />, layout);\n});\n"],"names":["PageLayoutContext","React","undefined","usePageLayout","useContext","PageScope","children","pageLayout","DocumentStoreScope","ReadOnlyContext","ReadOnlyScope","useIsReadOnlyScope","toLayoutDocument","layout","PageLayoutRenderer","layoutJson","pageStore","useDocumentStore","context","useMemo","document","JSON","layoutStore","useSeededDocumentStore","ElementRenderer","PageWithLayout","observer","page","toJS","renderWithLayout"],"mappings":";;;;;;;;AAmBA,MAAMA,oBAAoB,WAAHA,GAAGC,MAAAA,aAAmB,CAAqCC;AAM3E,MAAMC,gBAAgB,IAClBC,WAAWJ;AAOf,MAAMK,YAAY,CAAC,EAAEC,QAAQ,EAAiC;IACjE,MAAMC,aAAaJ;IACnB,IAAI,CAACI,YACD,OAAO,WAAP,GAAO,0CAAGD;IAGd,OAAO,WAAP,GACI,oBAACN,kBAAkB,QAAQ;QAAC,OAAOE;qBAC/B,oBAACM,oBAAkBA;QAAC,OAAOD,WAAW,SAAS;OAAGD;AAG9D;AAEA,MAAMG,kBAAkB,WAAHA,GAAGR,MAAAA,aAAmB,CAAC;AAMrC,MAAMS,gBAAgB,CAAC,EAAEJ,QAAQ,EAAiC,GAC9D,WAAP,GAAO,oBAACG,gBAAgB,QAAQ;QAAC,OAAO;OAAOH;AAG5C,MAAMK,qBAAqB,IACvBP,WAAWK;AAOtB,MAAMG,mBAAmB,CAACC,SACf;QACH,IAAIA,OAAO,EAAE;QACb,SAAS;QACT,OAAO,CAAC;QACR,YAAY;YAAE,IAAIA,OAAO,EAAE;QAAC;QAC5B,UAAU;YAAE,cAAc;QAAS;QACnC,YAAY,CAAC;QACb,UAAUA,OAAO,QAAQ,IAAI,CAAC;QAC9B,UAAUA,OAAO,QAAQ,IAAI,CAAC;IAClC;AAGJ,MAAMC,qBAAqB,CAAC,EAAEC,UAAU,EAA0B;IAC9D,MAAMC,YAAYC;IAClB,MAAMC,UAAUC,QAAQ,IAAO;YAAEH;QAAU,IAAI;QAACA;KAAU;IAG1D,MAAMI,WAAWD,QAAkB,IAAME,KAAK,KAAK,CAACN,aAAa;QAACA;KAAW;IAE7E,MAAMO,cAAcC,uBAAuBH;IAE3C,OAAO,WAAP,GACI,oBAACpB,kBAAkB,QAAQ;QAAC,OAAOkB;qBAC/B,oBAACV,oBAAkBA;QAAC,OAAOc;qBACvB,oBAACE,iBAAeA;QAAC,IAAI;;AAIrC;AAMO,MAAMC,iBAAiBC,SAAS,CAAC,EAAEb,MAAM,EAA+B;IAC3E,MAAMG,YAAYC;IAClB,MAAMU,OAAOX,UAAU,WAAW;IAElC,MAAMD,aAAaY,MAAM,SAASN,KAAK,SAAS,CAACT,iBAAiBgB,KAAKD,KAAK,MAAM,MAAM;IAExF,IAAIZ,YACA,OAAO,WAAP,GAAO,oBAACD,oBAAkBA;QAAC,YAAYC;;IAG3C,OAAOc,iBAAiB,WAADA,GAAC,oBAACL,iBAAeA;QAAC,IAAI;QAAYX;AAC7D"}
@@ -2,8 +2,10 @@
2
2
  import react from "react";
3
3
  import { LiveElementSlot } from "./LiveElementSlot.js";
4
4
  import { useElementSlotDepth } from "./ElementSlotDepthProvider.js";
5
+ import { useSlotLabel } from "./SlotLabel.js";
5
6
  const PreviewElementSlot = ({ parentId, slot, elements = [] })=>{
6
7
  const depth = useElementSlotDepth();
8
+ const label = useSlotLabel(parentId, slot);
7
9
  if (!elements.length) return /*#__PURE__*/ react.createElement("div", {
8
10
  style: {
9
11
  height: 100,
@@ -14,7 +16,15 @@ const PreviewElementSlot = ({ parentId, slot, elements = [] })=>{
14
16
  "data-parent-slot": slot,
15
17
  "data-depth": depth,
16
18
  "data-empty": true
17
- });
19
+ }, label ? /*#__PURE__*/ react.createElement("span", {
20
+ style: {
21
+ display: "block",
22
+ padding: 8,
23
+ fontSize: 12,
24
+ lineHeight: "16px",
25
+ color: "#6b6b6b"
26
+ }
27
+ }, label) : null);
18
28
  return /*#__PURE__*/ react.createElement(LiveElementSlot, {
19
29
  elements: elements
20
30
  });
@@ -1 +1 @@
1
- {"version":3,"file":"components/PreviewElementSlot.js","sources":["../../src/components/PreviewElementSlot.tsx"],"sourcesContent":["\"use client\";\nimport React from \"react\";\nimport { LiveElementSlot } from \"./LiveElementSlot.js\";\nimport { useElementSlotDepth } from \"./ElementSlotDepthProvider.js\";\n\ninterface ElementSlotProps {\n // Element that contains this slot.\n parentId: string;\n // Path to the array of elements within the element's data structure.\n slot: string;\n // IDs of the elements to render.\n elements: string[];\n}\n\nexport const PreviewElementSlot = ({ parentId, slot, elements = [] }: ElementSlotProps) => {\n const depth = useElementSlotDepth();\n\n if (!elements.length) {\n return (\n <div\n style={{ height: 100, width: \"100% !important\" }}\n data-role={\"element-slot\"}\n data-parent-id={parentId}\n data-parent-slot={slot}\n data-depth={depth}\n data-empty={true}\n />\n );\n }\n\n return <LiveElementSlot elements={elements} />;\n};\n"],"names":["PreviewElementSlot","parentId","slot","elements","depth","useElementSlotDepth","LiveElementSlot"],"mappings":";;;;AAcO,MAAMA,qBAAqB,CAAC,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,WAAW,EAAE,EAAoB;IAClF,MAAMC,QAAQC;IAEd,IAAI,CAACF,SAAS,MAAM,EAChB,OAAO,WAAP,GACI,oBAAC;QACG,OAAO;YAAE,QAAQ;YAAK,OAAO;QAAkB;QAC/C,aAAW;QACX,kBAAgBF;QAChB,oBAAkBC;QAClB,cAAYE;QACZ,cAAY;;IAKxB,OAAO,WAAP,GAAO,oBAACE,iBAAeA;QAAC,UAAUH;;AACtC"}
1
+ {"version":3,"file":"components/PreviewElementSlot.js","sources":["../../src/components/PreviewElementSlot.tsx"],"sourcesContent":["\"use client\";\nimport React from \"react\";\nimport { LiveElementSlot } from \"./LiveElementSlot.js\";\nimport { useElementSlotDepth } from \"./ElementSlotDepthProvider.js\";\nimport { useSlotLabel } from \"./SlotLabel.js\";\n\ninterface ElementSlotProps {\n // Element that contains this slot.\n parentId: string;\n // Path to the array of elements within the element's data structure.\n slot: string;\n // IDs of the elements to render.\n elements: string[];\n}\n\nexport const PreviewElementSlot = ({ parentId, slot, elements = [] }: ElementSlotProps) => {\n const depth = useElementSlotDepth();\n const label = useSlotLabel(parentId, slot);\n\n if (!elements.length) {\n return (\n <div\n style={{ height: 100, width: \"100% !important\" }}\n data-role={\"element-slot\"}\n data-parent-id={parentId}\n data-parent-slot={slot}\n data-depth={depth}\n data-empty={true}\n >\n {label ? (\n <span\n style={{\n display: \"block\",\n padding: 8,\n fontSize: 12,\n lineHeight: \"16px\",\n color: \"#6b6b6b\"\n }}\n >\n {label}\n </span>\n ) : null}\n </div>\n );\n }\n\n return <LiveElementSlot elements={elements} />;\n};\n"],"names":["PreviewElementSlot","parentId","slot","elements","depth","useElementSlotDepth","label","useSlotLabel","LiveElementSlot"],"mappings":";;;;;AAeO,MAAMA,qBAAqB,CAAC,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,WAAW,EAAE,EAAoB;IAClF,MAAMC,QAAQC;IACd,MAAMC,QAAQC,aAAaN,UAAUC;IAErC,IAAI,CAACC,SAAS,MAAM,EAChB,OAAO,WAAP,GACI,oBAAC;QACG,OAAO;YAAE,QAAQ;YAAK,OAAO;QAAkB;QAC/C,aAAW;QACX,kBAAgBF;QAChB,oBAAkBC;QAClB,cAAYE;QACZ,cAAY;OAEXE,QAAQ,WAARA,GACG,oBAAC;QACG,OAAO;YACH,SAAS;YACT,SAAS;YACT,UAAU;YACV,YAAY;YACZ,OAAO;QACX;OAECA,SAEL;IAKhB,OAAO,WAAP,GAAO,oBAACE,iBAAeA;QAAC,UAAUL;;AACtC"}
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ interface SlotLabelValue {
3
+ parentId: string;
4
+ slot: string;
5
+ label: string;
6
+ }
7
+ /**
8
+ * Name one slot in the editor: while it's empty, its drop area shows the label (e.g., the page content
9
+ * area of a layout it belongs to). Other slots rendered inside are not labeled.
10
+ */
11
+ export declare const SlotLabel: ({ children, ...value }: SlotLabelValue & {
12
+ children: React.ReactNode;
13
+ }) => React.JSX.Element;
14
+ export declare const useSlotLabel: (parentId: string, slot: string) => string | undefined;
15
+ export {};
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import react, { useContext } from "react";
3
+ const SlotLabelContext = /*#__PURE__*/ react.createContext(void 0);
4
+ const SlotLabel = ({ children, ...value })=>/*#__PURE__*/ react.createElement(SlotLabelContext.Provider, {
5
+ value: value
6
+ }, children);
7
+ const useSlotLabel = (parentId, slot)=>{
8
+ const value = useContext(SlotLabelContext);
9
+ return value && value.parentId === parentId && value.slot === slot ? value.label : void 0;
10
+ };
11
+ export { SlotLabel, useSlotLabel };
12
+
13
+ //# sourceMappingURL=SlotLabel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components/SlotLabel.js","sources":["../../src/components/SlotLabel.tsx"],"sourcesContent":["\"use client\";\nimport React, { useContext } from \"react\";\n\ninterface SlotLabelValue {\n parentId: string;\n slot: string;\n label: string;\n}\n\nconst SlotLabelContext = React.createContext<SlotLabelValue | undefined>(undefined);\n\n/**\n * Name one slot in the editor: while it's empty, its drop area shows the label (e.g., the page content\n * area of a layout it belongs to). Other slots rendered inside are not labeled.\n */\nexport const SlotLabel = ({\n children,\n ...value\n}: SlotLabelValue & { children: React.ReactNode }) => {\n return <SlotLabelContext.Provider value={value}>{children}</SlotLabelContext.Provider>;\n};\n\nexport const useSlotLabel = (parentId: string, slot: string) => {\n const value = useContext(SlotLabelContext);\n return value && value.parentId === parentId && value.slot === slot ? value.label : undefined;\n};\n"],"names":["SlotLabelContext","React","undefined","SlotLabel","children","value","useSlotLabel","parentId","slot","useContext"],"mappings":";;AASA,MAAMA,mBAAmB,WAAHA,GAAGC,MAAAA,aAAmB,CAA6BC;AAMlE,MAAMC,YAAY,CAAC,EACtBC,QAAQ,EACR,GAAGC,OAC0C,GACtC,WAAP,GAAO,oBAACL,iBAAiB,QAAQ;QAAC,OAAOK;OAAQD;AAG9C,MAAME,eAAe,CAACC,UAAkBC;IAC3C,MAAMH,QAAQI,WAAWT;IACzB,OAAOK,SAASA,MAAM,QAAQ,KAAKE,YAAYF,MAAM,IAAI,KAAKG,OAAOH,MAAM,KAAK,GAAGH;AACvF"}
@@ -2,3 +2,10 @@ export * from "./DocumentRenderer.js";
2
2
  export * from "./DocumentFragment.js";
3
3
  export * from "./ElementSlot.js";
4
4
  export * from "./DocumentStoreProvider.js";
5
+ export * from "./GlobalComponent.js";
6
+ export * from "./LayoutRenderer.js";
7
+ export { usePageLayout } from "./PageLayout.js";
8
+ export { useIsElementSelected } from "./useIsElementSelected.js";
9
+ export type { DocumentLayout } from "./renderWithLayout.js";
10
+ export * from "./ContentClientProvider.js";
11
+ export * from "./useContentClient.js";
@@ -2,3 +2,9 @@ export * from "./DocumentRenderer.js";
2
2
  export * from "./DocumentFragment.js";
3
3
  export * from "./ElementSlot.js";
4
4
  export * from "./DocumentStoreProvider.js";
5
+ export * from "./GlobalComponent.js";
6
+ export * from "./LayoutRenderer.js";
7
+ export * from "./ContentClientProvider.js";
8
+ export * from "./useContentClient.js";
9
+ export { usePageLayout } from "./PageLayout.js";
10
+ export { useIsElementSelected } from "./useIsElementSelected.js";
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ export type DocumentLayout = (args: {
3
+ content: React.ReactNode;
4
+ }) => React.ReactNode;
5
+ export declare const renderWithLayout: (content: React.ReactNode, layout?: DocumentLayout) => string | number | bigint | boolean | React.JSX.Element | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | Iterable<React.ReactNode> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | React.ReactPortal | null | undefined> | null | undefined;
@@ -0,0 +1,7 @@
1
+ import react from "react";
2
+ const renderWithLayout = (content, layout)=>layout ? /*#__PURE__*/ react.createElement(react.Fragment, null, layout({
3
+ content
4
+ })) : content;
5
+ export { renderWithLayout };
6
+
7
+ //# sourceMappingURL=renderWithLayout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components/renderWithLayout.js","sources":["../../src/components/renderWithLayout.tsx"],"sourcesContent":["import React from \"react\";\n\nexport type DocumentLayout = (args: { content: React.ReactNode }) => React.ReactNode;\n\nexport const renderWithLayout = (content: React.ReactNode, layout?: DocumentLayout) => {\n return layout ? <>{layout({ content })}</> : content;\n};\n"],"names":["renderWithLayout","content","layout"],"mappings":";AAIO,MAAMA,mBAAmB,CAACC,SAA0BC,SAChDA,SAAS,WAATA,GAAS,0CAAGA,OAAO;QAAED;IAAQ,MAASA"}
@@ -0,0 +1,6 @@
1
+ import type { ContentClient } from "@webiny/website-builder-sdk";
2
+ /**
3
+ * Returns the client from the nearest `ContentClientProvider`, or the `contentSdk` singleton
4
+ * when there is none.
5
+ */
6
+ export declare const useContentClient: () => ContentClient;
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import { useContext } from "react";
3
+ import { contentSdk } from "@webiny/website-builder-sdk";
4
+ import { ContentClientContext } from "./ContentClientContext.js";
5
+ const useContentClient = ()=>{
6
+ const client = useContext(ContentClientContext);
7
+ return client ?? contentSdk;
8
+ };
9
+ export { useContentClient };
10
+
11
+ //# sourceMappingURL=useContentClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components/useContentClient.js","sources":["../../src/components/useContentClient.ts"],"sourcesContent":["\"use client\";\nimport { useContext } from \"react\";\nimport type { ContentClient } from \"@webiny/website-builder-sdk\";\nimport { contentSdk } from \"@webiny/website-builder-sdk\";\nimport { ContentClientContext } from \"./ContentClientContext.js\";\n\n/**\n * Returns the client from the nearest `ContentClientProvider`, or the `contentSdk` singleton\n * when there is none.\n */\nexport const useContentClient = (): ContentClient => {\n const client = useContext(ContentClientContext);\n return client ?? contentSdk;\n};\n"],"names":["useContentClient","client","useContext","ContentClientContext","contentSdk"],"mappings":";;;;AAUO,MAAMA,mBAAmB;IAC5B,MAAMC,SAASC,WAAWC;IAC1B,OAAOF,UAAUG;AACrB"}
@@ -0,0 +1,8 @@
1
+ import { type DocumentElement } from "@webiny/website-builder-sdk";
2
+ /**
3
+ * Whether this component's element, or an element inside it, is selected in the editor.
4
+ * Use it to show content that is normally hidden, e.g. a dialog opens itself while it's selected,
5
+ * or an accordion expands while one of its items is selected.
6
+ * Always `false` outside the editor.
7
+ */
8
+ export declare const useIsElementSelected: (element: Pick<DocumentElement, "id">) => boolean;
@@ -0,0 +1,22 @@
1
+ "use client";
2
+ import { useEffect, useState } from "react";
3
+ import { autorun } from "mobx";
4
+ import { useContentClient } from "./useContentClient.js";
5
+ const useIsElementSelected = (element)=>{
6
+ const client = useContentClient();
7
+ const [isSelected, setIsSelected] = useState(false);
8
+ useEffect(()=>{
9
+ const editingSdk = client.getEditingSdk();
10
+ if (!editingSdk) return;
11
+ return autorun(()=>{
12
+ setIsSelected(editingSdk.isElementSelected(element.id));
13
+ });
14
+ }, [
15
+ element.id,
16
+ client
17
+ ]);
18
+ return isSelected;
19
+ };
20
+ export { useIsElementSelected };
21
+
22
+ //# sourceMappingURL=useIsElementSelected.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components/useIsElementSelected.js","sources":["../../src/components/useIsElementSelected.tsx"],"sourcesContent":["\"use client\";\nimport { useEffect, useState } from \"react\";\nimport { autorun } from \"mobx\";\nimport { type DocumentElement } from \"@webiny/website-builder-sdk\";\nimport { useContentClient } from \"./useContentClient.js\";\n\n/**\n * Whether this component's element, or an element inside it, is selected in the editor.\n * Use it to show content that is normally hidden, e.g. a dialog opens itself while it's selected,\n * or an accordion expands while one of its items is selected.\n * Always `false` outside the editor.\n */\nexport const useIsElementSelected = (element: Pick<DocumentElement, \"id\">): boolean => {\n const client = useContentClient();\n const [isSelected, setIsSelected] = useState(false);\n\n useEffect(() => {\n const editingSdk = client.getEditingSdk();\n if (!editingSdk) {\n return;\n }\n\n return autorun(() => {\n setIsSelected(editingSdk.isElementSelected(element.id));\n });\n }, [element.id, client]);\n\n return isSelected;\n};\n"],"names":["useIsElementSelected","element","client","useContentClient","isSelected","setIsSelected","useState","useEffect","editingSdk","autorun"],"mappings":";;;;AAYO,MAAMA,uBAAuB,CAACC;IACjC,MAAMC,SAASC;IACf,MAAM,CAACC,YAAYC,cAAc,GAAGC,SAAS;IAE7CC,UAAU;QACN,MAAMC,aAAaN,OAAO,aAAa;QACvC,IAAI,CAACM,YACD;QAGJ,OAAOC,QAAQ;YACXJ,cAAcG,WAAW,iBAAiB,CAACP,QAAQ,EAAE;QACzD;IACJ,GAAG;QAACA,QAAQ,EAAE;QAAEC;KAAO;IAEvB,OAAOE;AACX"}
@@ -0,0 +1,10 @@
1
+ import { type Document, DocumentStore } from "@webiny/website-builder-sdk";
2
+ /**
3
+ * A store of its own for a document rendered inside another one (a page's layout, the page previewed in the
4
+ * layout editor): never one shared by id across renders, or across requests on the server.
5
+ *
6
+ * It's seeded on creation, so the first render (and the server render) has the document. A changed document
7
+ * goes into the store after render: writing an observable store while rendering would update its observers
8
+ * during someone else's render.
9
+ */
10
+ export declare const useSeededDocumentStore: (document: Document) => DocumentStore<Document>;
@@ -0,0 +1,22 @@
1
+ "use client";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { DocumentStore } from "@webiny/website-builder-sdk";
4
+ const useSeededDocumentStore = (document)=>{
5
+ const [store] = useState(()=>{
6
+ const store = new DocumentStore();
7
+ store.setDocument(document);
8
+ return store;
9
+ });
10
+ const appliedDocument = useRef(document);
11
+ useEffect(()=>{
12
+ if (appliedDocument.current === document) return;
13
+ appliedDocument.current = document;
14
+ store.setDocument(document);
15
+ }, [
16
+ document
17
+ ]);
18
+ return store;
19
+ };
20
+ export { useSeededDocumentStore };
21
+
22
+ //# sourceMappingURL=useSeededDocumentStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components/useSeededDocumentStore.js","sources":["../../src/components/useSeededDocumentStore.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { type Document, DocumentStore } from \"@webiny/website-builder-sdk\";\n\n/**\n * A store of its own for a document rendered inside another one (a page's layout, the page previewed in the\n * layout editor): never one shared by id across renders, or across requests on the server.\n *\n * It's seeded on creation, so the first render (and the server render) has the document. A changed document\n * goes into the store after render: writing an observable store while rendering would update its observers\n * during someone else's render.\n */\nexport const useSeededDocumentStore = (document: Document) => {\n const [store] = useState(() => {\n const store = new DocumentStore();\n store.setDocument(document);\n return store;\n });\n const appliedDocument = useRef(document);\n\n useEffect(() => {\n if (appliedDocument.current === document) {\n return;\n }\n appliedDocument.current = document;\n store.setDocument(document);\n }, [document]);\n\n return store;\n};\n"],"names":["useSeededDocumentStore","document","store","useState","DocumentStore","appliedDocument","useRef","useEffect"],"mappings":";;;AAYO,MAAMA,yBAAyB,CAACC;IACnC,MAAM,CAACC,MAAM,GAAGC,SAAS;QACrB,MAAMD,QAAQ,IAAIE;QAClBF,MAAM,WAAW,CAACD;QAClB,OAAOC;IACX;IACA,MAAMG,kBAAkBC,OAAOL;IAE/BM,UAAU;QACN,IAAIF,gBAAgB,OAAO,KAAKJ,UAC5B;QAEJI,gBAAgB,OAAO,GAAGJ;QAC1BC,MAAM,WAAW,CAACD;IACtB,GAAG;QAACA;KAAS;IAEb,OAAOC;AACX"}
@@ -0,0 +1,22 @@
1
+ import type { ResolvedContentEntryQuery } from "@webiny/website-builder-sdk";
2
+ export type { ResolvedContentEntryQuery, ContentEntryQuerySpec } from "@webiny/website-builder-sdk";
3
+ export interface ContentEntryList<T = unknown> {
4
+ /** The loaded entries (first page + any loaded via loadMore). */
5
+ items: T[];
6
+ /** Whether more pages are available (and pagination is enabled). */
7
+ hasMore: boolean;
8
+ /** True while a loadMore fetch is in flight. */
9
+ loading: boolean;
10
+ /** Fetch and append the next page. No-op when nothing more to load. */
11
+ loadMore: () => void;
12
+ }
13
+ /**
14
+ * Client hook for a query-mode `contentEntry` input. Seeds from the server-resolved
15
+ * first page (SSR-safe — no fetch on mount) and loads further pages on demand from
16
+ * the embedded query + cursor. Re-seeds when the underlying query changes (e.g. the
17
+ * editor tweaks sort/limit/search in preview).
18
+ *
19
+ * Pagination is active only when the input enables it (the resolved value then
20
+ * carries a `query`); otherwise `hasMore` is always false and `loadMore` is a no-op.
21
+ */
22
+ export declare function useContentEntryList<T = unknown>(value: ResolvedContentEntryQuery<T> | null | undefined): ContentEntryList<T>;
@@ -0,0 +1,51 @@
1
+ "use client";
2
+ import { useCallback, useState } from "react";
3
+ import { contentSdk } from "@webiny/cms-sdk";
4
+ function useContentEntryList(value) {
5
+ const query = value?.query;
6
+ const signature = JSON.stringify({
7
+ query,
8
+ cursor: value?.pageInfo?.cursor ?? null
9
+ });
10
+ const seed = ()=>({
11
+ signature,
12
+ items: value?.items ?? [],
13
+ cursor: value?.pageInfo?.cursor ?? null,
14
+ apiHasMore: value?.pageInfo?.hasMore ?? false
15
+ });
16
+ const [state, setState] = useState(seed);
17
+ const [loading, setLoading] = useState(false);
18
+ if (state.signature !== signature) setState(seed());
19
+ const loadMore = useCallback(()=>{
20
+ if (!query || loading || !state.apiHasMore || !state.cursor) return;
21
+ setLoading(true);
22
+ contentSdk.listEntries({
23
+ ...query,
24
+ after: state.cursor
25
+ }).then((result)=>{
26
+ setState((prev)=>({
27
+ ...prev,
28
+ items: [
29
+ ...prev.items,
30
+ ...result.data
31
+ ],
32
+ cursor: result.meta.cursor,
33
+ apiHasMore: result.meta.hasMoreItems
34
+ }));
35
+ }).finally(()=>setLoading(false));
36
+ }, [
37
+ query,
38
+ loading,
39
+ state.apiHasMore,
40
+ state.cursor
41
+ ]);
42
+ return {
43
+ items: state.items,
44
+ hasMore: Boolean(query) && state.apiHasMore,
45
+ loading,
46
+ loadMore
47
+ };
48
+ }
49
+ export { useContentEntryList };
50
+
51
+ //# sourceMappingURL=useContentEntryList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contentEntry/useContentEntryList.js","sources":["../../src/contentEntry/useContentEntryList.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useState } from \"react\";\nimport { contentSdk } from \"@webiny/cms-sdk\";\nimport type { ResolvedContentEntryQuery } from \"@webiny/website-builder-sdk\";\n\nexport type { ResolvedContentEntryQuery, ContentEntryQuerySpec } from \"@webiny/website-builder-sdk\";\n\nexport interface ContentEntryList<T = unknown> {\n /** The loaded entries (first page + any loaded via loadMore). */\n items: T[];\n /** Whether more pages are available (and pagination is enabled). */\n hasMore: boolean;\n /** True while a loadMore fetch is in flight. */\n loading: boolean;\n /** Fetch and append the next page. No-op when nothing more to load. */\n loadMore: () => void;\n}\n\ninterface PageState<T> {\n signature: string;\n items: T[];\n cursor: string | null;\n apiHasMore: boolean;\n}\n\n/**\n * Client hook for a query-mode `contentEntry` input. Seeds from the server-resolved\n * first page (SSR-safe — no fetch on mount) and loads further pages on demand from\n * the embedded query + cursor. Re-seeds when the underlying query changes (e.g. the\n * editor tweaks sort/limit/search in preview).\n *\n * Pagination is active only when the input enables it (the resolved value then\n * carries a `query`); otherwise `hasMore` is always false and `loadMore` is a no-op.\n */\nexport function useContentEntryList<T = unknown>(\n value: ResolvedContentEntryQuery<T> | null | undefined\n): ContentEntryList<T> {\n const query = value?.query;\n const signature = JSON.stringify({ query, cursor: value?.pageInfo?.cursor ?? null });\n\n const seed = (): PageState<T> => ({\n signature,\n items: value?.items ?? [],\n cursor: value?.pageInfo?.cursor ?? null,\n apiHasMore: value?.pageInfo?.hasMore ?? false\n });\n\n const [state, setState] = useState<PageState<T>>(seed);\n const [loading, setLoading] = useState(false);\n\n // Re-seed (on the client) when the resolved page changes — e.g. the editor edits\n // the query. The first/SSR render already has the right data via useState.\n if (state.signature !== signature) {\n setState(seed());\n }\n\n const loadMore = useCallback(() => {\n if (!query || loading || !state.apiHasMore || !state.cursor) {\n return;\n }\n setLoading(true);\n contentSdk\n .listEntries({ ...query, after: state.cursor })\n .then(result => {\n setState(prev => ({\n ...prev,\n items: [...prev.items, ...(result.data as T[])],\n cursor: result.meta.cursor,\n apiHasMore: result.meta.hasMoreItems\n }));\n })\n .finally(() => setLoading(false));\n }, [query, loading, state.apiHasMore, state.cursor]);\n\n return {\n items: state.items,\n hasMore: Boolean(query) && state.apiHasMore,\n loading,\n loadMore\n };\n}\n"],"names":["useContentEntryList","value","query","signature","JSON","seed","state","setState","useState","loading","setLoading","loadMore","useCallback","contentSdk","result","prev","Boolean"],"mappings":";;;AAkCO,SAASA,oBACZC,KAAsD;IAEtD,MAAMC,QAAQD,OAAO;IACrB,MAAME,YAAYC,KAAK,SAAS,CAAC;QAAEF;QAAO,QAAQD,OAAO,UAAU,UAAU;IAAK;IAElF,MAAMI,OAAO,IAAqB;YAC9BF;YACA,OAAOF,OAAO,SAAS,EAAE;YACzB,QAAQA,OAAO,UAAU,UAAU;YACnC,YAAYA,OAAO,UAAU,WAAW;QAC5C;IAEA,MAAM,CAACK,OAAOC,SAAS,GAAGC,SAAuBH;IACjD,MAAM,CAACI,SAASC,WAAW,GAAGF,SAAS;IAIvC,IAAIF,MAAM,SAAS,KAAKH,WACpBI,SAASF;IAGb,MAAMM,WAAWC,YAAY;QACzB,IAAI,CAACV,SAASO,WAAW,CAACH,MAAM,UAAU,IAAI,CAACA,MAAM,MAAM,EACvD;QAEJI,WAAW;QACXG,WAAAA,WACgB,CAAC;YAAE,GAAGX,KAAK;YAAE,OAAOI,MAAM,MAAM;QAAC,GAC5C,IAAI,CAACQ,CAAAA;YACFP,SAASQ,CAAAA,OAAS;oBACd,GAAGA,IAAI;oBACP,OAAO;2BAAIA,KAAK,KAAK;2BAAMD,OAAO,IAAI;qBAAS;oBAC/C,QAAQA,OAAO,IAAI,CAAC,MAAM;oBAC1B,YAAYA,OAAO,IAAI,CAAC,YAAY;gBACxC;QACJ,GACC,OAAO,CAAC,IAAMJ,WAAW;IAClC,GAAG;QAACR;QAAOO;QAASH,MAAM,UAAU;QAAEA,MAAM,MAAM;KAAC;IAEnD,OAAO;QACH,OAAOA,MAAM,KAAK;QAClB,SAASU,QAAQd,UAAUI,MAAM,UAAU;QAC3CG;QACAE;IACJ;AACJ"}
@@ -15,5 +15,5 @@ type GridProps = ComponentProps<{
15
15
  stackAtBreakpoint?: string;
16
16
  reverseWhenStacked?: boolean;
17
17
  }>;
18
- export declare const GridComponent: ({ inputs, styles, breakpoint }: GridProps) => React.JSX.Element;
18
+ export declare const GridComponent: ({ inputs, styles, breakpoint, breakpoints }: GridProps) => React.JSX.Element;
19
19
  export {};
@@ -1,12 +1,13 @@
1
1
  import react from "react";
2
2
  const GridColumnComponent = ({ inputs })=>/*#__PURE__*/ react.createElement(react.Fragment, null, inputs.children);
3
- const GridComponent = ({ inputs, styles, breakpoint })=>{
3
+ const GridComponent = ({ inputs, styles, breakpoint, breakpoints })=>{
4
4
  const { gridLayout = "12", columns, columnGap, stackAtBreakpoint, reverseWhenStacked } = inputs;
5
5
  const rowConfig = gridLayout.split("-").map((size)=>parseInt(size));
6
6
  const rows = [];
7
7
  for(let i = 0; i < columns.length; i += rowConfig.length)rows.push(columns.slice(i, i + rowConfig.length));
8
8
  const cellWidthReduction = columnGap ? columnGap - columnGap / rowConfig.length : 0;
9
- const stackColumns = breakpoint === stackAtBreakpoint;
9
+ const stackFrom = stackAtBreakpoint ? breakpoints.indexOf(stackAtBreakpoint) : -1;
10
+ const stackColumns = -1 !== stackFrom && breakpoints.indexOf(breakpoint) >= stackFrom;
10
11
  if (stackColumns) styles.flexDirection = reverseWhenStacked ? "column-reverse" : "column";
11
12
  return /*#__PURE__*/ react.createElement("div", {
12
13
  style: styles
@@ -1 +1 @@
1
- {"version":3,"file":"editorComponents/Grid.js","sources":["../../src/editorComponents/Grid.tsx"],"sourcesContent":["import React from \"react\";\nimport type { ComponentProps, ComponentPropsWithChildren } from \"~/types.js\";\n\nexport const GridColumnComponent = ({\n inputs\n}: {\n inputs: ComponentPropsWithChildren[\"inputs\"];\n}) => {\n return <>{inputs.children}</>;\n};\n\nexport interface Column {\n children: React.ReactNode;\n}\n\ntype GridProps = ComponentProps<{\n gridLayout: string;\n rowCount: number;\n rowGap: number;\n columnGap: number;\n columns: Column[];\n stackAtBreakpoint?: string;\n reverseWhenStacked?: boolean;\n}>;\n\nexport const GridComponent = ({ inputs, styles, breakpoint }: GridProps) => {\n const { gridLayout = \"12\", columns, columnGap, stackAtBreakpoint, reverseWhenStacked } = inputs;\n const rowConfig = gridLayout.split(\"-\").map(size => parseInt(size));\n const rows: Column[][] = [];\n\n // Chunk columns into rows\n for (let i = 0; i < columns.length; i += rowConfig.length) {\n rows.push(columns.slice(i, i + rowConfig.length));\n }\n\n // Number of pixels we need to subtract from each cell to ensure they fit in the grid with column gap\n const cellWidthReduction = columnGap ? columnGap - columnGap / rowConfig.length : 0;\n\n const stackColumns = breakpoint === stackAtBreakpoint;\n\n if (stackColumns) {\n styles.flexDirection = reverseWhenStacked ? \"column-reverse\" : \"column\";\n }\n\n return (\n <div style={styles}>\n {rows.map(columns => {\n return columns.map((column, i) => (\n <Span\n key={i}\n stackColumns={stackColumns}\n size={rowConfig[i]}\n reductionInPx={cellWidthReduction}\n >\n <GridColumnComponent key={i} inputs={{ children: column.children }} />\n </Span>\n ));\n })}\n </div>\n );\n};\n\ninterface SpanProps {\n size: number;\n reductionInPx: number;\n stackColumns: boolean;\n children: React.ReactNode;\n}\n\nconst Span = ({ size, children, reductionInPx, stackColumns }: SpanProps) => {\n const width = stackColumns ? \"100%\" : `calc(${(size / 12) * 100}% - ${reductionInPx}px)`;\n\n return (\n <div\n style={{\n flex: `0 0 ${width}`,\n maxWidth: width,\n boxSizing: \"border-box\"\n }}\n >\n {children}\n </div>\n );\n};\n"],"names":["GridColumnComponent","inputs","GridComponent","styles","breakpoint","gridLayout","columns","columnGap","stackAtBreakpoint","reverseWhenStacked","rowConfig","size","parseInt","rows","i","cellWidthReduction","stackColumns","column","Span","children","reductionInPx","width"],"mappings":";AAGO,MAAMA,sBAAsB,CAAC,EAChCC,MAAM,EAGT,GACU,WAAP,GAAO,0CAAGA,OAAO,QAAQ;AAiBtB,MAAMC,gBAAgB,CAAC,EAAED,MAAM,EAAEE,MAAM,EAAEC,UAAU,EAAa;IACnE,MAAM,EAAEC,aAAa,IAAI,EAAEC,OAAO,EAAEC,SAAS,EAAEC,iBAAiB,EAAEC,kBAAkB,EAAE,GAAGR;IACzF,MAAMS,YAAYL,WAAW,KAAK,CAAC,KAAK,GAAG,CAACM,CAAAA,OAAQC,SAASD;IAC7D,MAAME,OAAmB,EAAE;IAG3B,IAAK,IAAIC,IAAI,GAAGA,IAAIR,QAAQ,MAAM,EAAEQ,KAAKJ,UAAU,MAAM,CACrDG,KAAK,IAAI,CAACP,QAAQ,KAAK,CAACQ,GAAGA,IAAIJ,UAAU,MAAM;IAInD,MAAMK,qBAAqBR,YAAYA,YAAYA,YAAYG,UAAU,MAAM,GAAG;IAElF,MAAMM,eAAeZ,eAAeI;IAEpC,IAAIQ,cACAb,OAAO,aAAa,GAAGM,qBAAqB,mBAAmB;IAGnE,OAAO,WAAP,GACI,oBAAC;QAAI,OAAON;OACPU,KAAK,GAAG,CAACP,CAAAA,UACCA,QAAQ,GAAG,CAAC,CAACW,QAAQH,IAAAA,WAAAA,GACxB,oBAACI,MAAIA;gBACD,KAAKJ;gBACL,cAAcE;gBACd,MAAMN,SAAS,CAACI,EAAE;gBAClB,eAAeC;6BAEf,oBAACf,qBAAmBA;gBAAC,KAAKc;gBAAG,QAAQ;oBAAE,UAAUG,OAAO,QAAQ;gBAAC;;AAMzF;AASA,MAAMC,OAAO,CAAC,EAAEP,IAAI,EAAEQ,QAAQ,EAAEC,aAAa,EAAEJ,YAAY,EAAa;IACpE,MAAMK,QAAQL,eAAe,SAAS,CAAC,KAAK,EAAGL,OAAO,KAAM,IAAI,IAAI,EAAES,cAAc,GAAG,CAAC;IAExF,OAAO,WAAP,GACI,oBAAC;QACG,OAAO;YACH,MAAM,CAAC,IAAI,EAAEC,OAAO;YACpB,UAAUA;YACV,WAAW;QACf;OAECF;AAGb"}
1
+ {"version":3,"file":"editorComponents/Grid.js","sources":["../../src/editorComponents/Grid.tsx"],"sourcesContent":["import React from \"react\";\nimport type { ComponentProps, ComponentPropsWithChildren } from \"~/types.js\";\n\nexport const GridColumnComponent = ({\n inputs\n}: {\n inputs: ComponentPropsWithChildren[\"inputs\"];\n}) => {\n return <>{inputs.children}</>;\n};\n\nexport interface Column {\n children: React.ReactNode;\n}\n\ntype GridProps = ComponentProps<{\n gridLayout: string;\n rowCount: number;\n rowGap: number;\n columnGap: number;\n columns: Column[];\n stackAtBreakpoint?: string;\n reverseWhenStacked?: boolean;\n}>;\n\nexport const GridComponent = ({ inputs, styles, breakpoint, breakpoints }: GridProps) => {\n const { gridLayout = \"12\", columns, columnGap, stackAtBreakpoint, reverseWhenStacked } = inputs;\n const rowConfig = gridLayout.split(\"-\").map(size => parseInt(size));\n const rows: Column[][] = [];\n\n // Chunk columns into rows\n for (let i = 0; i < columns.length; i += rowConfig.length) {\n rows.push(columns.slice(i, i + rowConfig.length));\n }\n\n // Number of pixels we need to subtract from each cell to ensure they fit in the grid with column gap\n const cellWidthReduction = columnGap ? columnGap - columnGap / rowConfig.length : 0;\n\n // Stack at the chosen breakpoint and every narrower one.\n const stackFrom = stackAtBreakpoint ? breakpoints.indexOf(stackAtBreakpoint) : -1;\n const stackColumns = stackFrom !== -1 && breakpoints.indexOf(breakpoint) >= stackFrom;\n\n if (stackColumns) {\n styles.flexDirection = reverseWhenStacked ? \"column-reverse\" : \"column\";\n }\n\n return (\n <div style={styles}>\n {rows.map(columns => {\n return columns.map((column, i) => (\n <Span\n key={i}\n stackColumns={stackColumns}\n size={rowConfig[i]}\n reductionInPx={cellWidthReduction}\n >\n <GridColumnComponent key={i} inputs={{ children: column.children }} />\n </Span>\n ));\n })}\n </div>\n );\n};\n\ninterface SpanProps {\n size: number;\n reductionInPx: number;\n stackColumns: boolean;\n children: React.ReactNode;\n}\n\nconst Span = ({ size, children, reductionInPx, stackColumns }: SpanProps) => {\n const width = stackColumns ? \"100%\" : `calc(${(size / 12) * 100}% - ${reductionInPx}px)`;\n\n return (\n <div\n style={{\n flex: `0 0 ${width}`,\n maxWidth: width,\n boxSizing: \"border-box\"\n }}\n >\n {children}\n </div>\n );\n};\n"],"names":["GridColumnComponent","inputs","GridComponent","styles","breakpoint","breakpoints","gridLayout","columns","columnGap","stackAtBreakpoint","reverseWhenStacked","rowConfig","size","parseInt","rows","i","cellWidthReduction","stackFrom","stackColumns","column","Span","children","reductionInPx","width"],"mappings":";AAGO,MAAMA,sBAAsB,CAAC,EAChCC,MAAM,EAGT,GACU,WAAP,GAAO,0CAAGA,OAAO,QAAQ;AAiBtB,MAAMC,gBAAgB,CAAC,EAAED,MAAM,EAAEE,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAa;IAChF,MAAM,EAAEC,aAAa,IAAI,EAAEC,OAAO,EAAEC,SAAS,EAAEC,iBAAiB,EAAEC,kBAAkB,EAAE,GAAGT;IACzF,MAAMU,YAAYL,WAAW,KAAK,CAAC,KAAK,GAAG,CAACM,CAAAA,OAAQC,SAASD;IAC7D,MAAME,OAAmB,EAAE;IAG3B,IAAK,IAAIC,IAAI,GAAGA,IAAIR,QAAQ,MAAM,EAAEQ,KAAKJ,UAAU,MAAM,CACrDG,KAAK,IAAI,CAACP,QAAQ,KAAK,CAACQ,GAAGA,IAAIJ,UAAU,MAAM;IAInD,MAAMK,qBAAqBR,YAAYA,YAAYA,YAAYG,UAAU,MAAM,GAAG;IAGlF,MAAMM,YAAYR,oBAAoBJ,YAAY,OAAO,CAACI,qBAAqB;IAC/E,MAAMS,eAAeD,AAAc,OAAdA,aAAoBZ,YAAY,OAAO,CAACD,eAAea;IAE5E,IAAIC,cACAf,OAAO,aAAa,GAAGO,qBAAqB,mBAAmB;IAGnE,OAAO,WAAP,GACI,oBAAC;QAAI,OAAOP;OACPW,KAAK,GAAG,CAACP,CAAAA,UACCA,QAAQ,GAAG,CAAC,CAACY,QAAQJ,IAAAA,WAAAA,GACxB,oBAACK,MAAIA;gBACD,KAAKL;gBACL,cAAcG;gBACd,MAAMP,SAAS,CAACI,EAAE;gBAClB,eAAeC;6BAEf,oBAAChB,qBAAmBA;gBAAC,KAAKe;gBAAG,QAAQ;oBAAE,UAAUI,OAAO,QAAQ;gBAAC;;AAMzF;AASA,MAAMC,OAAO,CAAC,EAAER,IAAI,EAAES,QAAQ,EAAEC,aAAa,EAAEJ,YAAY,EAAa;IACpE,MAAMK,QAAQL,eAAe,SAAS,CAAC,KAAK,EAAGN,OAAO,KAAM,IAAI,IAAI,EAAEU,cAAc,GAAG,CAAC;IAExF,OAAO,WAAP,GACI,oBAAC;QACG,OAAO;YACH,MAAM,CAAC,IAAI,EAAEC,OAAO;YACpB,UAAUA;YACV,WAAW;QACf;OAECF;AAGb"}
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ import type { ComponentProps } from "../types.js";
3
+ export declare const MainContentComponent: ({ element }: ComponentProps) => React.JSX.Element;
4
+ export declare const NamedContentComponent: ({ inputs, element }: ComponentProps<{
5
+ area?: string;
6
+ }>) => React.JSX.Element;