@webiny/website-builder-react 0.0.0-unstable.461c047ab7 → 0.0.0-unstable.48a4e5b6c1
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 +10 -2
- package/components/ConnectToEditor.d.ts +3 -1
- package/components/ConnectToEditor.js +21 -21
- package/components/ConnectToEditor.js.map +1 -1
- package/components/ContentClientContext.d.ts +3 -0
- package/components/ContentClientContext.js +6 -0
- package/components/ContentClientContext.js.map +1 -0
- package/components/ContentClientProvider.d.ts +12 -0
- package/components/ContentClientProvider.js +9 -0
- package/components/ContentClientProvider.js.map +1 -0
- package/components/ContentClientProvider.test.d.ts +1 -0
- package/components/ContentClientProvider.test.js +143 -0
- package/components/ContentClientProvider.test.js.map +1 -0
- package/components/DocumentFragment.d.ts +10 -3
- package/components/DocumentFragment.js +5 -6
- package/components/DocumentFragment.js.map +1 -1
- package/components/DocumentRenderer.d.ts +8 -3
- package/components/DocumentRenderer.js +55 -43
- package/components/DocumentRenderer.js.map +1 -1
- package/components/DocumentStoreProvider.d.ts +8 -1
- package/components/DocumentStoreProvider.js +35 -22
- package/components/DocumentStoreProvider.js.map +1 -1
- package/components/DocumentStoreProvider.test.d.ts +1 -0
- package/components/DocumentStoreProvider.test.js +66 -0
- package/components/DocumentStoreProvider.test.js.map +1 -0
- package/components/EditingElementRenderer/EditingElementRenderer.d.ts +7 -2
- package/components/EditingElementRenderer/EditingElementRenderer.js +48 -40
- package/components/EditingElementRenderer/EditingElementRenderer.js.map +1 -1
- package/components/EditingElementRenderer/EditingElementRenderer.presenter.d.ts +2 -2
- package/components/EditingElementRenderer/EditingElementRenderer.presenter.js +31 -36
- package/components/EditingElementRenderer/EditingElementRenderer.presenter.js.map +1 -1
- package/components/EditingElementRenderer/index.js +0 -2
- package/components/ElementIndexProvider.js +9 -14
- package/components/ElementIndexProvider.js.map +1 -1
- package/components/ElementRenderer.d.ts +2 -2
- package/components/ElementRenderer.js +25 -17
- package/components/ElementRenderer.js.map +1 -1
- package/components/ElementSlot.js +11 -11
- package/components/ElementSlot.js.map +1 -1
- package/components/ElementSlotDepthProvider.js +9 -14
- package/components/ElementSlotDepthProvider.js.map +1 -1
- package/components/FragmentsProvider.d.ts +10 -1
- package/components/FragmentsProvider.js +33 -25
- package/components/FragmentsProvider.js.map +1 -1
- package/components/GlobalComponent.d.ts +10 -0
- package/components/GlobalComponent.js +17 -0
- package/components/GlobalComponent.js.map +1 -0
- package/components/GlobalPlacement.d.ts +11 -0
- package/components/GlobalPlacement.js +27 -0
- package/components/GlobalPlacement.js.map +1 -0
- package/components/LayoutAreas.d.ts +19 -0
- package/components/LayoutAreas.js +15 -0
- package/components/LayoutAreas.js.map +1 -0
- package/components/LayoutRenderer.d.ts +14 -0
- package/components/LayoutRenderer.js +60 -0
- package/components/LayoutRenderer.js.map +1 -0
- package/components/LayoutRenderer.test.d.ts +1 -0
- package/components/LayoutRenderer.test.js +138 -0
- package/components/LayoutRenderer.test.js.map +1 -0
- package/components/LiveElementRenderer.d.ts +2 -2
- package/components/LiveElementRenderer.js +64 -73
- package/components/LiveElementRenderer.js.map +1 -1
- package/components/LiveElementSlot.d.ts +1 -1
- package/components/LiveElementSlot.js +15 -17
- package/components/LiveElementSlot.js.map +1 -1
- package/components/PageLayout.d.ts +40 -0
- package/components/PageLayout.js +71 -0
- package/components/PageLayout.js.map +1 -0
- package/components/PreviewElementSlot.js +29 -25
- package/components/PreviewElementSlot.js.map +1 -1
- package/components/SlotLabel.d.ts +15 -0
- package/components/SlotLabel.js +13 -0
- package/components/SlotLabel.js.map +1 -0
- package/components/index.d.ts +7 -0
- package/components/index.js +6 -2
- package/components/renderWithLayout.d.ts +5 -0
- package/components/renderWithLayout.js +7 -0
- package/components/renderWithLayout.js.map +1 -0
- package/components/useBindingsForElement.d.ts +246 -112
- package/components/useBindingsForElement.js +16 -14
- package/components/useBindingsForElement.js.map +1 -1
- package/components/useContentClient.d.ts +6 -0
- package/components/useContentClient.js +11 -0
- package/components/useContentClient.js.map +1 -0
- package/components/useDocumentState.d.ts +1 -1
- package/components/useDocumentState.js +7 -5
- package/components/useDocumentState.js.map +1 -1
- package/components/useIsElementSelected.d.ts +8 -0
- package/components/useIsElementSelected.js +22 -0
- package/components/useIsElementSelected.js.map +1 -0
- package/components/useSeededDocumentStore.d.ts +10 -0
- package/components/useSeededDocumentStore.js +22 -0
- package/components/useSeededDocumentStore.js.map +1 -0
- package/components/useSelectFromState.d.ts +2 -2
- package/components/useSelectFromState.js +29 -35
- package/components/useSelectFromState.js.map +1 -1
- package/components/useSelectFromState.test.d.ts +1 -0
- package/components/useSelectFromState.test.js +67 -0
- package/components/useSelectFromState.test.js.map +1 -0
- package/components/useViewportInfo.js +5 -6
- package/components/useViewportInfo.js.map +1 -1
- package/contentEntry/useContentEntryList.d.ts +22 -0
- package/contentEntry/useContentEntryList.js +51 -0
- package/contentEntry/useContentEntryList.js.map +1 -0
- package/createComponent.d.ts +1 -2
- package/createComponent.js +1 -16
- package/createComponent.test.d.ts +1 -0
- package/createComponent.test.js +118 -0
- package/createComponent.test.js.map +1 -0
- package/editorComponents/Box.d.ts +1 -1
- package/editorComponents/Box.js +3 -6
- package/editorComponents/Box.js.map +1 -1
- package/editorComponents/Box.manifest.d.ts +1 -1
- package/editorComponents/Box.manifest.js +17 -16
- package/editorComponents/Box.manifest.js.map +1 -1
- package/editorComponents/Fragment.d.ts +2 -2
- package/editorComponents/Fragment.js +24 -27
- package/editorComponents/Fragment.js.map +1 -1
- package/editorComponents/Fragment.manifest.js +16 -13
- package/editorComponents/Fragment.manifest.js.map +1 -1
- package/editorComponents/Grid.d.ts +3 -2
- package/editorComponents/Grid.js +34 -61
- package/editorComponents/Grid.js.map +1 -1
- package/editorComponents/Grid.manifest.d.ts +0 -1
- package/editorComponents/Grid.manifest.js +165 -168
- package/editorComponents/Grid.manifest.js.map +1 -1
- package/editorComponents/GridColumn.d.ts +1 -1
- package/editorComponents/GridColumn.js +3 -6
- package/editorComponents/GridColumn.js.map +1 -1
- package/editorComponents/GridColumn.manifest.js +22 -19
- package/editorComponents/GridColumn.manifest.js.map +1 -1
- package/editorComponents/Image.d.ts +2 -2
- package/editorComponents/Image.js +99 -119
- package/editorComponents/Image.js.map +1 -1
- package/editorComponents/Image.manifest.js +35 -33
- package/editorComponents/Image.manifest.js.map +1 -1
- package/editorComponents/LayoutContent.d.ts +6 -0
- package/editorComponents/LayoutContent.js +121 -0
- package/editorComponents/LayoutContent.js.map +1 -0
- package/editorComponents/LayoutContent.manifest.d.ts +10 -0
- package/editorComponents/LayoutContent.manifest.js +32 -0
- package/editorComponents/LayoutContent.manifest.js.map +1 -0
- package/editorComponents/LayoutContentLabel.d.ts +2 -0
- package/editorComponents/LayoutContentLabel.js +7 -0
- package/editorComponents/LayoutContentLabel.js.map +1 -0
- package/editorComponents/LayoutContentLabel.test.d.ts +1 -0
- package/editorComponents/LayoutContentLabel.test.js +23 -0
- package/editorComponents/LayoutContentLabel.test.js.map +1 -0
- package/editorComponents/Lexical.d.ts +3 -3
- package/editorComponents/Lexical.js +13 -25
- package/editorComponents/Lexical.js.map +1 -1
- package/editorComponents/Lexical.manifest.js +19 -16
- package/editorComponents/Lexical.manifest.js.map +1 -1
- package/editorComponents/Root.d.ts +1 -1
- package/editorComponents/Root.js +3 -6
- package/editorComponents/Root.js.map +1 -1
- package/editorComponents/Root.manifest.d.ts +1 -1
- package/editorComponents/Root.manifest.js +9 -8
- package/editorComponents/Root.manifest.js.map +1 -1
- package/editorComponents/index.d.ts +1 -1
- package/editorComponents/index.js +15 -3
- package/editorComponents/index.js.map +1 -1
- package/image/BackgroundImage.d.ts +33 -0
- package/image/BackgroundImage.js +61 -0
- package/image/BackgroundImage.js.map +1 -0
- package/image/Image.d.ts +29 -0
- package/image/Image.js +43 -0
- package/image/Image.js.map +1 -0
- package/image/getImageProps.d.ts +42 -0
- package/image/getImageProps.js +18 -0
- package/image/getImageProps.js.map +1 -0
- package/image/getImageProps.test.d.ts +1 -0
- package/image/getImageProps.test.js +70 -0
- package/image/getImageProps.test.js.map +1 -0
- package/image/index.d.ts +3 -0
- package/image/index.js +3 -0
- package/index.d.ts +4 -3
- package/index.js +2 -4
- package/package.json +19 -19
- package/types.d.ts +40 -2
- package/types.js +0 -3
- package/components/EditingElementRenderer/index.js.map +0 -1
- package/components/index.js.map +0 -1
- package/createComponent.js.map +0 -1
- package/index.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
import react, { useEffect } from "react";
|
|
3
|
+
import { useContentClient } from "./useContentClient.js";
|
|
4
|
+
const FragmentsContext = /*#__PURE__*/ react.createContext(void 0);
|
|
5
|
+
const FragmentsProvider = ({ fragments, children })=>{
|
|
6
|
+
const client = useContentClient();
|
|
7
|
+
useEffect(()=>{
|
|
8
|
+
if (client.isEditing()) {
|
|
9
|
+
const fragmentsData = fragments.map((fragment)=>{
|
|
10
|
+
if ("fixed" === fragment.type) return {
|
|
11
|
+
type: "fixed",
|
|
12
|
+
name: fragment.name
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
type: "component",
|
|
16
|
+
component: fragment.component,
|
|
17
|
+
inputs: fragment.inputs
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
client.getEditingSdk().messenger.send("document.fragments", {
|
|
21
|
+
fragments: fragmentsData
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}, [
|
|
25
|
+
fragments.length
|
|
26
|
+
]);
|
|
27
|
+
return /*#__PURE__*/ react.createElement(FragmentsContext.Provider, {
|
|
28
|
+
value: fragments
|
|
29
|
+
}, children);
|
|
21
30
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
return context;
|
|
31
|
+
const useDocumentFragments = ()=>{
|
|
32
|
+
const context = react.useContext(FragmentsContext);
|
|
33
|
+
if (!context) return [];
|
|
34
|
+
return context;
|
|
28
35
|
};
|
|
36
|
+
export { FragmentsProvider, useDocumentFragments };
|
|
29
37
|
|
|
30
38
|
//# sourceMappingURL=FragmentsProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"components/FragmentsProvider.js","sources":["../../src/components/FragmentsProvider.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect } from \"react\";\nimport { useContentClient } from \"./useContentClient.js\";\n\ntype FragmentConfig =\n | {\n type: \"fixed\";\n name: string;\n element: React.ReactNode;\n }\n | { type: \"component\"; component: string; inputs: Record<string, any> };\n\nexport type DocumentFragments = FragmentConfig[];\n\nconst FragmentsContext = React.createContext<DocumentFragments | undefined>(undefined);\n\ninterface FragmentsProviderProps {\n fragments: DocumentFragments;\n children: React.ReactNode;\n}\n\nexport const FragmentsProvider = ({ fragments, children }: FragmentsProviderProps) => {\n const client = useContentClient();\n\n useEffect(() => {\n if (client.isEditing()) {\n // Extract serializable data\n const fragmentsData = fragments.map(fragment => {\n if (fragment.type === \"fixed\") {\n return {\n type: \"fixed\",\n name: fragment.name\n };\n }\n\n return {\n type: \"component\",\n component: fragment.component,\n inputs: fragment.inputs\n };\n });\n\n client\n .getEditingSdk()!\n .messenger.send(\"document.fragments\", { fragments: fragmentsData });\n }\n }, [fragments.length]);\n\n return <FragmentsContext.Provider value={fragments}>{children}</FragmentsContext.Provider>;\n};\n\nexport const useDocumentFragments = () => {\n const context = React.useContext(FragmentsContext);\n if (!context) {\n return [];\n }\n\n return context;\n};\n"],"names":["FragmentsContext","React","undefined","FragmentsProvider","fragments","children","client","useContentClient","useEffect","fragmentsData","fragment","useDocumentFragments","context"],"mappings":";;;AAcA,MAAMA,mBAAmB,WAAnBA,GAAmBC,MAAAA,aAAmB,CAAgCC;AAOrE,MAAMC,oBAAoB,CAAC,EAAEC,SAAS,EAAEC,QAAQ,EAA0B;IAC7E,MAAMC,SAASC;IAEfC,UAAU;QACN,IAAIF,OAAO,SAAS,IAAI;YAEpB,MAAMG,gBAAgBL,UAAU,GAAG,CAACM,CAAAA;gBAChC,IAAIA,AAAkB,YAAlBA,SAAS,IAAI,EACb,OAAO;oBACH,MAAM;oBACN,MAAMA,SAAS,IAAI;gBACvB;gBAGJ,OAAO;oBACH,MAAM;oBACN,WAAWA,SAAS,SAAS;oBAC7B,QAAQA,SAAS,MAAM;gBAC3B;YACJ;YAEAJ,OACK,aAAa,GACb,SAAS,CAAC,IAAI,CAAC,sBAAsB;gBAAE,WAAWG;YAAc;QACzE;IACJ,GAAG;QAACL,UAAU,MAAM;KAAC;IAErB,OAAO,WAAP,GAAO,oBAACJ,iBAAiB,QAAQ;QAAC,OAAOI;OAAYC;AACzD;AAEO,MAAMM,uBAAuB;IAChC,MAAMC,UAAUX,MAAAA,UAAgB,CAACD;IACjC,IAAI,CAACY,SACD,OAAO,EAAE;IAGb,OAAOA;AACX"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface GlobalComponentProps {
|
|
3
|
+
component: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Render the single, site-wide instance of a global component.
|
|
7
|
+
* Use it inside the `layout` of a <DocumentRenderer> to decide where the global appears.
|
|
8
|
+
* The page is delivered with its global components, so the element is read from the page itself.
|
|
9
|
+
*/
|
|
10
|
+
export declare const GlobalComponent: ({ component }: GlobalComponentProps) => React.JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import react from "react";
|
|
3
|
+
import { GlobalElementId } from "@webiny/website-builder-sdk";
|
|
4
|
+
import { ElementRenderer } from "./ElementRenderer.js";
|
|
5
|
+
import { useContentClient } from "./useContentClient.js";
|
|
6
|
+
const GlobalComponent = ({ component })=>{
|
|
7
|
+
const client = useContentClient();
|
|
8
|
+
const registered = client.getComponent(component);
|
|
9
|
+
if (!registered) throw new Error(`<GlobalComponent component="${component}">: the component is not registered. Pass it to <DocumentRenderer components={...}>.`);
|
|
10
|
+
if (!registered.manifest.global) throw new Error(`<GlobalComponent component="${component}">: the component is not global. Set \`global: true\` in its manifest.`);
|
|
11
|
+
return /*#__PURE__*/ react.createElement(ElementRenderer, {
|
|
12
|
+
id: GlobalElementId.fromName(component).toString()
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export { GlobalComponent };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=GlobalComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/GlobalComponent.js","sources":["../../src/components/GlobalComponent.tsx"],"sourcesContent":["\"use client\";\nimport React from \"react\";\nimport { GlobalElementId } from \"@webiny/website-builder-sdk\";\nimport { ElementRenderer } from \"./ElementRenderer.js\";\nimport { useContentClient } from \"./useContentClient.js\";\n\nexport interface GlobalComponentProps {\n // Name of a registered component whose manifest has `global: true`.\n component: string;\n}\n\n/**\n * Render the single, site-wide instance of a global component.\n * Use it inside the `layout` of a <DocumentRenderer> to decide where the global appears.\n * The page is delivered with its global components, so the element is read from the page itself.\n */\nexport const GlobalComponent = ({ component }: GlobalComponentProps) => {\n const client = useContentClient();\n const registered = client.getComponent(component);\n if (!registered) {\n throw new Error(\n `<GlobalComponent component=\"${component}\">: the component is not registered. Pass it to <DocumentRenderer components={...}>.`\n );\n }\n\n if (!registered.manifest.global) {\n throw new Error(\n `<GlobalComponent component=\"${component}\">: the component is not global. Set \\`global: true\\` in its manifest.`\n );\n }\n\n return <ElementRenderer id={GlobalElementId.fromName(component).toString()} />;\n};\n"],"names":["GlobalComponent","component","client","useContentClient","registered","Error","ElementRenderer","GlobalElementId"],"mappings":";;;;;AAgBO,MAAMA,kBAAkB,CAAC,EAAEC,SAAS,EAAwB;IAC/D,MAAMC,SAASC;IACf,MAAMC,aAAaF,OAAO,YAAY,CAACD;IACvC,IAAI,CAACG,YACD,MAAM,IAAIC,MACN,CAAC,4BAA4B,EAAEJ,UAAU,oFAAoF,CAAC;IAItI,IAAI,CAACG,WAAW,QAAQ,CAAC,MAAM,EAC3B,MAAM,IAAIC,MACN,CAAC,4BAA4B,EAAEJ,UAAU,sEAAsE,CAAC;IAIxH,OAAO,WAAP,GAAO,oBAACK,iBAAeA;QAAC,IAAIC,gBAAgB,QAAQ,CAACN,WAAW,QAAQ;;AAC5E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type DocumentElement } from "@webiny/website-builder-sdk";
|
|
3
|
+
interface GlobalPlacementProps {
|
|
4
|
+
placement: DocumentElement;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Render a placement of a global component: the global's single instance, at the placement's place.
|
|
8
|
+
* In a layout rendered around a page, the instance comes with the page.
|
|
9
|
+
*/
|
|
10
|
+
export declare const GlobalPlacement: ({ placement }: GlobalPlacementProps) => React.JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import react from "react";
|
|
3
|
+
import { observer } from "mobx-react-lite";
|
|
4
|
+
import { GlobalElementId, environment } from "@webiny/website-builder-sdk";
|
|
5
|
+
import { EditingElementRenderer } from "./EditingElementRenderer/EditingElementRenderer.js";
|
|
6
|
+
import { LiveElementRenderer } from "./LiveElementRenderer.js";
|
|
7
|
+
import { useDocumentStore } from "./DocumentStoreProvider.js";
|
|
8
|
+
import { PageScope, useIsReadOnlyScope } from "./PageLayout.js";
|
|
9
|
+
const PlacedInstance = observer(({ placement })=>{
|
|
10
|
+
const documentStore = useDocumentStore();
|
|
11
|
+
const readOnly = useIsReadOnlyScope();
|
|
12
|
+
const instance = documentStore.getElement(GlobalElementId.fromName(placement.component.name).toString());
|
|
13
|
+
if (!instance) return null;
|
|
14
|
+
if (environment.isEditing() && !readOnly) return /*#__PURE__*/ react.createElement(EditingElementRenderer, {
|
|
15
|
+
element: placement,
|
|
16
|
+
instance: instance
|
|
17
|
+
});
|
|
18
|
+
return /*#__PURE__*/ react.createElement(LiveElementRenderer, {
|
|
19
|
+
element: instance
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
const GlobalPlacement = ({ placement })=>/*#__PURE__*/ react.createElement(PageScope, null, /*#__PURE__*/ react.createElement(PlacedInstance, {
|
|
23
|
+
placement: placement
|
|
24
|
+
}));
|
|
25
|
+
export { GlobalPlacement };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=GlobalPlacement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/GlobalPlacement.js","sources":["../../src/components/GlobalPlacement.tsx"],"sourcesContent":["\"use client\";\nimport React from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { type DocumentElement, environment, GlobalElementId } from \"@webiny/website-builder-sdk\";\nimport { EditingElementRenderer } from \"./EditingElementRenderer/EditingElementRenderer.js\";\nimport { LiveElementRenderer } from \"./LiveElementRenderer.js\";\nimport { useDocumentStore } from \"./DocumentStoreProvider.js\";\nimport { PageScope, useIsReadOnlyScope } from \"./PageLayout.js\";\n\ninterface GlobalPlacementProps {\n placement: DocumentElement;\n}\n\nconst PlacedInstance = observer(({ placement }: GlobalPlacementProps) => {\n const documentStore = useDocumentStore();\n const readOnly = useIsReadOnlyScope();\n const instance = documentStore.getElement(\n GlobalElementId.fromName(placement.component.name).toString()\n );\n\n if (!instance) {\n return null;\n }\n\n // In the editor, the placement is what's selected, moved and deleted; it shows the instance's values.\n if (environment.isEditing() && !readOnly) {\n return <EditingElementRenderer element={placement} instance={instance} />;\n }\n\n return <LiveElementRenderer element={instance} />;\n});\n\n/**\n * Render a placement of a global component: the global's single instance, at the placement's place.\n * In a layout rendered around a page, the instance comes with the page.\n */\nexport const GlobalPlacement = ({ placement }: GlobalPlacementProps) => {\n return (\n <PageScope>\n <PlacedInstance placement={placement} />\n </PageScope>\n );\n};\n"],"names":["PlacedInstance","observer","placement","documentStore","useDocumentStore","readOnly","useIsReadOnlyScope","instance","GlobalElementId","environment","EditingElementRenderer","LiveElementRenderer","GlobalPlacement","PageScope"],"mappings":";;;;;;;;AAaA,MAAMA,iBAAiBC,SAAS,CAAC,EAAEC,SAAS,EAAwB;IAChE,MAAMC,gBAAgBC;IACtB,MAAMC,WAAWC;IACjB,MAAMC,WAAWJ,cAAc,UAAU,CACrCK,gBAAgB,QAAQ,CAACN,UAAU,SAAS,CAAC,IAAI,EAAE,QAAQ;IAG/D,IAAI,CAACK,UACD,OAAO;IAIX,IAAIE,YAAY,SAAS,MAAM,CAACJ,UAC5B,OAAO,WAAP,GAAO,oBAACK,wBAAsBA;QAAC,SAASR;QAAW,UAAUK;;IAGjE,OAAO,WAAP,GAAO,oBAACI,qBAAmBA;QAAC,SAASJ;;AACzC;AAMO,MAAMK,kBAAkB,CAAC,EAAEV,SAAS,EAAwB,GACxD,WAAP,GACI,oBAACW,WAASA,MAAAA,WAAAA,GACN,oBAACb,gBAAAA;QAAe,WAAWE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { LayoutContentArea } from "@webiny/website-builder-sdk";
|
|
3
|
+
export interface LayoutAreasValue {
|
|
4
|
+
main: React.ReactNode;
|
|
5
|
+
areas: Record<string, React.ReactNode>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Set while <LayoutRenderer> renders a layout around content from code (e.g. a CMS entry): its content areas
|
|
9
|
+
* render that content, not a page's.
|
|
10
|
+
*/
|
|
11
|
+
export declare const LayoutAreasProvider: ({ value, children }: {
|
|
12
|
+
value: LayoutAreasValue | undefined;
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
}) => React.JSX.Element;
|
|
15
|
+
export declare const useLayoutAreas: () => LayoutAreasValue | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The content of one area. An area with no name, or a name nothing was given for, stays empty.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getLayoutAreaContent: (value: LayoutAreasValue, area: LayoutContentArea) => React.ReactNode;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import react, { useContext } from "react";
|
|
3
|
+
const LayoutAreasContext = /*#__PURE__*/ react.createContext(void 0);
|
|
4
|
+
const LayoutAreasProvider = ({ value, children })=>/*#__PURE__*/ react.createElement(LayoutAreasContext.Provider, {
|
|
5
|
+
value: value
|
|
6
|
+
}, children);
|
|
7
|
+
const useLayoutAreas = ()=>useContext(LayoutAreasContext);
|
|
8
|
+
const getLayoutAreaContent = (value, area)=>{
|
|
9
|
+
if (area.isMain()) return value.main;
|
|
10
|
+
const name = area.name();
|
|
11
|
+
return name ? value.areas[name] ?? null : null;
|
|
12
|
+
};
|
|
13
|
+
export { LayoutAreasProvider, getLayoutAreaContent, useLayoutAreas };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=LayoutAreas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/LayoutAreas.js","sources":["../../src/components/LayoutAreas.tsx"],"sourcesContent":["\"use client\";\nimport React, { useContext } from \"react\";\nimport type { LayoutContentArea } from \"@webiny/website-builder-sdk\";\n\nexport interface LayoutAreasValue {\n // What goes in the layout's Main content.\n main: React.ReactNode;\n // What goes in each named content area, by the area's name.\n areas: Record<string, React.ReactNode>;\n}\n\nconst LayoutAreasContext = React.createContext<LayoutAreasValue | undefined>(undefined);\n\n/**\n * Set while <LayoutRenderer> renders a layout around content from code (e.g. a CMS entry): its content areas\n * render that content, not a page's.\n */\nexport const LayoutAreasProvider = ({\n value,\n children\n}: {\n value: LayoutAreasValue | undefined;\n children: React.ReactNode;\n}) => {\n return <LayoutAreasContext.Provider value={value}>{children}</LayoutAreasContext.Provider>;\n};\n\nexport const useLayoutAreas = () => {\n return useContext(LayoutAreasContext);\n};\n\n/**\n * The content of one area. An area with no name, or a name nothing was given for, stays empty.\n */\nexport const getLayoutAreaContent = (value: LayoutAreasValue, area: LayoutContentArea) => {\n if (area.isMain()) {\n return value.main;\n }\n\n const name = area.name();\n return name ? (value.areas[name] ?? null) : null;\n};\n"],"names":["LayoutAreasContext","React","undefined","LayoutAreasProvider","value","children","useLayoutAreas","useContext","getLayoutAreaContent","area","name"],"mappings":";;AAWA,MAAMA,qBAAqB,WAArBA,GAAqBC,MAAAA,aAAmB,CAA+BC;AAMtE,MAAMC,sBAAsB,CAAC,EAChCC,KAAK,EACLC,QAAQ,EAIX,GACU,WAAP,GAAO,oBAACL,mBAAmB,QAAQ;QAAC,OAAOI;OAAQC;AAGhD,MAAMC,iBAAiB,IACnBC,WAAWP;AAMf,MAAMQ,uBAAuB,CAACJ,OAAyBK;IAC1D,IAAIA,KAAK,MAAM,IACX,OAAOL,MAAM,IAAI;IAGrB,MAAMM,OAAOD,KAAK,IAAI;IACtB,OAAOC,OAAQN,MAAM,KAAK,CAACM,KAAK,IAAI,OAAQ;AAChD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type Component, type PublicLayout } from "@webiny/website-builder-sdk";
|
|
3
|
+
export interface LayoutRendererProps {
|
|
4
|
+
layout: PublicLayout;
|
|
5
|
+
components: Component[];
|
|
6
|
+
areas?: Record<string, React.ReactNode>;
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Render content from code (e.g. a CMS entry) in a layout built in the layout editor: `children` go in its
|
|
11
|
+
* Main content, and `areas` in its named content areas. It always renders as on the live site, also inside an
|
|
12
|
+
* editor's preview: nothing in it can be selected.
|
|
13
|
+
*/
|
|
14
|
+
export declare const LayoutRenderer: ({ layout, components, areas, children }: LayoutRendererProps) => React.JSX.Element;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import react, { useMemo } from "react";
|
|
3
|
+
import { DocumentStore, withGlobalElementDefaults } from "@webiny/website-builder-sdk";
|
|
4
|
+
import { editorComponents } from "../editorComponents/index.js";
|
|
5
|
+
import { DocumentStoreScope } from "./DocumentStoreProvider.js";
|
|
6
|
+
import { PageWithLayout, ReadOnlyScope } from "./PageLayout.js";
|
|
7
|
+
import { LayoutAreasProvider } from "./LayoutAreas.js";
|
|
8
|
+
import { useContentClient } from "./useContentClient.js";
|
|
9
|
+
const toLayoutPage = (layout, client)=>{
|
|
10
|
+
const id = `layout:${layout.layout.id}`;
|
|
11
|
+
const globals = withGlobalElementDefaults({
|
|
12
|
+
elements: layout.elements ?? {},
|
|
13
|
+
bindings: layout.bindings ?? {}
|
|
14
|
+
}, client.getComponentManifests());
|
|
15
|
+
return {
|
|
16
|
+
id,
|
|
17
|
+
version: 1,
|
|
18
|
+
state: {},
|
|
19
|
+
properties: {
|
|
20
|
+
id
|
|
21
|
+
},
|
|
22
|
+
metadata: {},
|
|
23
|
+
extensions: {},
|
|
24
|
+
elements: globals.elements,
|
|
25
|
+
bindings: globals.bindings,
|
|
26
|
+
layout: layout.layout
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const LayoutRenderer = ({ layout, components, areas, children })=>{
|
|
30
|
+
const client = useContentClient();
|
|
31
|
+
[
|
|
32
|
+
...editorComponents,
|
|
33
|
+
...components
|
|
34
|
+
].forEach((blueprint)=>client.registerComponent(blueprint));
|
|
35
|
+
const store = useMemo(()=>{
|
|
36
|
+
const store = new DocumentStore();
|
|
37
|
+
store.setDocument(toLayoutPage(layout, client));
|
|
38
|
+
return store;
|
|
39
|
+
}, [
|
|
40
|
+
layout,
|
|
41
|
+
client
|
|
42
|
+
]);
|
|
43
|
+
const content = useMemo(()=>({
|
|
44
|
+
main: children,
|
|
45
|
+
areas: areas ?? {}
|
|
46
|
+
}), [
|
|
47
|
+
children,
|
|
48
|
+
areas
|
|
49
|
+
]);
|
|
50
|
+
return /*#__PURE__*/ react.createElement("div", {
|
|
51
|
+
"data-role": "layout-renderer"
|
|
52
|
+
}, /*#__PURE__*/ react.createElement(ReadOnlyScope, null, /*#__PURE__*/ react.createElement(LayoutAreasProvider, {
|
|
53
|
+
value: content
|
|
54
|
+
}, /*#__PURE__*/ react.createElement(DocumentStoreScope, {
|
|
55
|
+
store: store
|
|
56
|
+
}, /*#__PURE__*/ react.createElement(PageWithLayout, null)))));
|
|
57
|
+
};
|
|
58
|
+
export { LayoutRenderer };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=LayoutRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/LayoutRenderer.js","sources":["../../src/components/LayoutRenderer.tsx"],"sourcesContent":["\"use client\";\nimport React, { useMemo } from \"react\";\nimport {\n type Component,\n type ContentClient,\n type Document,\n DocumentStore,\n type PublicLayout,\n withGlobalElementDefaults\n} from \"@webiny/website-builder-sdk\";\nimport { editorComponents } from \"../editorComponents/index.js\";\nimport { DocumentStoreScope } from \"./DocumentStoreProvider.js\";\nimport { PageWithLayout, ReadOnlyScope } from \"./PageLayout.js\";\nimport { LayoutAreasProvider, type LayoutAreasValue } from \"./LayoutAreas.js\";\nimport { useContentClient } from \"./useContentClient.js\";\n\nexport interface LayoutRendererProps {\n // A layout delivered by slug, e.g. `sdk.wb.getLayout({ slug: model.settings.layout })`.\n layout: PublicLayout;\n // The components the layout uses, as for <DocumentRenderer>.\n components: Component[];\n // Content for the layout's named content areas, by area name. Areas not listed stay empty.\n areas?: Record<string, React.ReactNode>;\n // Rendered in the layout's Main content.\n children?: React.ReactNode;\n}\n\n/**\n * The layout comes composed like a page with no content of its own: the instances of the global components it\n * places, and the layout. A global that was never saved is rendered from its manifest defaults.\n */\nconst toLayoutPage = (layout: PublicLayout, client: ContentClient): Document => {\n const id = `layout:${layout.layout.id}`;\n const globals = withGlobalElementDefaults(\n { elements: layout.elements ?? {}, bindings: layout.bindings ?? {} },\n client.getComponentManifests()\n );\n\n return {\n id,\n version: 1,\n state: {},\n properties: { id },\n metadata: {},\n extensions: {},\n elements: globals.elements,\n bindings: globals.bindings,\n layout: layout.layout\n };\n};\n\n/**\n * Render content from code (e.g. a CMS entry) in a layout built in the layout editor: `children` go in its\n * Main content, and `areas` in its named content areas. It always renders as on the live site, also inside an\n * editor's preview: nothing in it can be selected.\n */\nexport const LayoutRenderer = ({ layout, components, areas, children }: LayoutRendererProps) => {\n const client = useContentClient();\n [...editorComponents, ...components].forEach(blueprint => client.registerComponent(blueprint));\n\n // Its own store, seeded on creation: never one shared by id across renders (or requests on the server).\n const store = useMemo(() => {\n const store = new DocumentStore();\n store.setDocument(toLayoutPage(layout, client));\n return store;\n }, [layout, client]);\n\n const content = useMemo<LayoutAreasValue>(\n () => ({ main: children, areas: areas ?? {} }),\n [children, areas]\n );\n\n return (\n <div data-role={\"layout-renderer\"}>\n <ReadOnlyScope>\n <LayoutAreasProvider value={content}>\n <DocumentStoreScope store={store}>\n <PageWithLayout />\n </DocumentStoreScope>\n </LayoutAreasProvider>\n </ReadOnlyScope>\n </div>\n );\n};\n"],"names":["toLayoutPage","layout","client","id","globals","withGlobalElementDefaults","LayoutRenderer","components","areas","children","useContentClient","editorComponents","blueprint","store","useMemo","DocumentStore","content","ReadOnlyScope","LayoutAreasProvider","DocumentStoreScope","PageWithLayout"],"mappings":";;;;;;;;AA+BA,MAAMA,eAAe,CAACC,QAAsBC;IACxC,MAAMC,KAAK,CAAC,OAAO,EAAEF,OAAO,MAAM,CAAC,EAAE,EAAE;IACvC,MAAMG,UAAUC,0BACZ;QAAE,UAAUJ,OAAO,QAAQ,IAAI,CAAC;QAAG,UAAUA,OAAO,QAAQ,IAAI,CAAC;IAAE,GACnEC,OAAO,qBAAqB;IAGhC,OAAO;QACHC;QACA,SAAS;QACT,OAAO,CAAC;QACR,YAAY;YAAEA;QAAG;QACjB,UAAU,CAAC;QACX,YAAY,CAAC;QACb,UAAUC,QAAQ,QAAQ;QAC1B,UAAUA,QAAQ,QAAQ;QAC1B,QAAQH,OAAO,MAAM;IACzB;AACJ;AAOO,MAAMK,iBAAiB,CAAC,EAAEL,MAAM,EAAEM,UAAU,EAAEC,KAAK,EAAEC,QAAQ,EAAuB;IACvF,MAAMP,SAASQ;IACf;WAAIC;WAAqBJ;KAAW,CAAC,OAAO,CAACK,CAAAA,YAAaV,OAAO,iBAAiB,CAACU;IAGnF,MAAMC,QAAQC,QAAQ;QAClB,MAAMD,QAAQ,IAAIE;QAClBF,MAAM,WAAW,CAACb,aAAaC,QAAQC;QACvC,OAAOW;IACX,GAAG;QAACZ;QAAQC;KAAO;IAEnB,MAAMc,UAAUF,QACZ,IAAO;YAAE,MAAML;YAAU,OAAOD,SAAS,CAAC;QAAE,IAC5C;QAACC;QAAUD;KAAM;IAGrB,OAAO,WAAP,GACI,oBAAC;QAAI,aAAW;qBACZ,oBAACS,eAAaA,MAAAA,WAAAA,GACV,oBAACC,qBAAmBA;QAAC,OAAOF;qBACxB,oBAACG,oBAAkBA;QAAC,OAAON;qBACvB,oBAACO,gBAAcA;AAMvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import react from "react";
|
|
2
|
+
import { renderToString } from "react-dom/server";
|
|
3
|
+
import { beforeAll, describe, expect, it } from "vitest";
|
|
4
|
+
import { contentSdk, createTextInput } from "@webiny/website-builder-sdk";
|
|
5
|
+
import { createComponent } from "../createComponent.js";
|
|
6
|
+
import { LayoutRenderer } from "./LayoutRenderer.js";
|
|
7
|
+
const Header = createComponent(({ inputs })=>/*#__PURE__*/ react.createElement("header", null, inputs.title), {
|
|
8
|
+
name: "Test/Header",
|
|
9
|
+
global: true,
|
|
10
|
+
inputs: [
|
|
11
|
+
createTextInput({
|
|
12
|
+
name: "title",
|
|
13
|
+
defaultValue: "Welcome"
|
|
14
|
+
})
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
const LayoutRenderer_test_element = (id, name, parentId)=>({
|
|
18
|
+
type: "Webiny/Element",
|
|
19
|
+
id,
|
|
20
|
+
component: {
|
|
21
|
+
name
|
|
22
|
+
},
|
|
23
|
+
parent: parentId ? {
|
|
24
|
+
id: parentId,
|
|
25
|
+
slot: "children"
|
|
26
|
+
} : void 0
|
|
27
|
+
});
|
|
28
|
+
const createLayout = (globals)=>({
|
|
29
|
+
...globals,
|
|
30
|
+
layout: {
|
|
31
|
+
id: "layout-1",
|
|
32
|
+
elements: {
|
|
33
|
+
root: LayoutRenderer_test_element("root", "Webiny/Root"),
|
|
34
|
+
header: LayoutRenderer_test_element("header", "Test/Header", "root"),
|
|
35
|
+
main: LayoutRenderer_test_element("main", "Webiny/LayoutContent", "root"),
|
|
36
|
+
sidebar: LayoutRenderer_test_element("sidebar", "Webiny/NamedContent", "root"),
|
|
37
|
+
promo: LayoutRenderer_test_element("promo", "Webiny/NamedContent", "root")
|
|
38
|
+
},
|
|
39
|
+
bindings: {
|
|
40
|
+
root: {
|
|
41
|
+
inputs: {
|
|
42
|
+
children: {
|
|
43
|
+
id: "children",
|
|
44
|
+
type: "slot",
|
|
45
|
+
list: true,
|
|
46
|
+
static: [
|
|
47
|
+
"header",
|
|
48
|
+
"main",
|
|
49
|
+
"sidebar",
|
|
50
|
+
"promo"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
sidebar: {
|
|
56
|
+
inputs: {
|
|
57
|
+
area: {
|
|
58
|
+
id: "sidebar-area",
|
|
59
|
+
type: "text",
|
|
60
|
+
static: "sidebar"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
promo: {
|
|
65
|
+
inputs: {
|
|
66
|
+
area: {
|
|
67
|
+
id: "promo-area",
|
|
68
|
+
type: "text",
|
|
69
|
+
static: "promo"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const render = (layout, areas)=>renderToString(/*#__PURE__*/ react.createElement(LayoutRenderer, {
|
|
77
|
+
layout: layout,
|
|
78
|
+
components: [
|
|
79
|
+
Header
|
|
80
|
+
],
|
|
81
|
+
areas: areas
|
|
82
|
+
}, /*#__PURE__*/ react.createElement("article", null, "The entry")));
|
|
83
|
+
describe("LayoutRenderer", ()=>{
|
|
84
|
+
beforeAll(()=>{
|
|
85
|
+
contentSdk.init({
|
|
86
|
+
apiKey: "key",
|
|
87
|
+
apiHost: "https://api.test",
|
|
88
|
+
apiTenant: "root"
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
it("renders the children in Main content, inside the layout", ()=>{
|
|
92
|
+
const html = render(createLayout({
|
|
93
|
+
elements: {},
|
|
94
|
+
bindings: {}
|
|
95
|
+
}));
|
|
96
|
+
expect(html).toContain("<article>The entry</article>");
|
|
97
|
+
expect(html.indexOf("<header>")).toBeLessThan(html.indexOf("<article>"));
|
|
98
|
+
});
|
|
99
|
+
it("renders a global the layout places from its manifest defaults when it was never saved", ()=>{
|
|
100
|
+
const html = render(createLayout({
|
|
101
|
+
elements: {},
|
|
102
|
+
bindings: {}
|
|
103
|
+
}));
|
|
104
|
+
expect(html).toContain("<header>Welcome</header>");
|
|
105
|
+
});
|
|
106
|
+
it("renders a global the layout places with its delivered values", ()=>{
|
|
107
|
+
const html = render(createLayout({
|
|
108
|
+
elements: {
|
|
109
|
+
"$global:Test/Header": LayoutRenderer_test_element("$global:Test/Header", "Test/Header")
|
|
110
|
+
},
|
|
111
|
+
bindings: {
|
|
112
|
+
"$global:Test/Header": {
|
|
113
|
+
inputs: {
|
|
114
|
+
title: {
|
|
115
|
+
id: "title",
|
|
116
|
+
type: "text",
|
|
117
|
+
static: "ACME Inc"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}));
|
|
123
|
+
expect(html).toContain("<header>ACME Inc</header>");
|
|
124
|
+
});
|
|
125
|
+
it("fills named content areas by name, and leaves the others empty", ()=>{
|
|
126
|
+
const html = render(createLayout({
|
|
127
|
+
elements: {},
|
|
128
|
+
bindings: {}
|
|
129
|
+
}), {
|
|
130
|
+
sidebar: /*#__PURE__*/ react.createElement("aside", null, "Related")
|
|
131
|
+
});
|
|
132
|
+
expect(html).toContain("<aside>Related</aside>");
|
|
133
|
+
expect(html.indexOf("<article>")).toBeLessThan(html.indexOf("<aside>"));
|
|
134
|
+
expect(html).not.toContain("promo");
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=LayoutRenderer.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/LayoutRenderer.test.js","sources":["../../src/components/LayoutRenderer.test.tsx"],"sourcesContent":["import React from \"react\";\nimport { renderToString } from \"react-dom/server\";\nimport { beforeAll, describe, expect, it } from \"vitest\";\nimport { contentSdk, createTextInput, type PublicLayout } from \"@webiny/website-builder-sdk\";\nimport { createComponent } from \"~/createComponent.js\";\nimport type { ComponentProps } from \"~/types.js\";\nimport { LayoutRenderer } from \"./LayoutRenderer.js\";\n\nconst Header = createComponent(\n ({ inputs }: ComponentProps<{ title: string }>) => <header>{inputs.title}</header>,\n {\n name: \"Test/Header\",\n global: true,\n inputs: [createTextInput({ name: \"title\", defaultValue: \"Welcome\" })]\n }\n);\n\nconst element = (id: string, name: string, parentId?: string) => ({\n type: \"Webiny/Element\" as const,\n id,\n component: { name },\n parent: parentId ? { id: parentId, slot: \"children\" } : undefined\n});\n\nconst createLayout = (globals: Pick<PublicLayout, \"elements\" | \"bindings\">): PublicLayout => ({\n ...globals,\n layout: {\n id: \"layout-1\",\n elements: {\n root: element(\"root\", \"Webiny/Root\"),\n header: element(\"header\", \"Test/Header\", \"root\"),\n main: element(\"main\", \"Webiny/LayoutContent\", \"root\"),\n sidebar: element(\"sidebar\", \"Webiny/NamedContent\", \"root\"),\n promo: element(\"promo\", \"Webiny/NamedContent\", \"root\")\n },\n bindings: {\n root: {\n inputs: {\n children: {\n id: \"children\",\n type: \"slot\",\n list: true,\n static: [\"header\", \"main\", \"sidebar\", \"promo\"]\n }\n }\n },\n sidebar: { inputs: { area: { id: \"sidebar-area\", type: \"text\", static: \"sidebar\" } } },\n promo: { inputs: { area: { id: \"promo-area\", type: \"text\", static: \"promo\" } } }\n }\n }\n});\n\nconst render = (layout: PublicLayout, areas?: Record<string, React.ReactNode>) => {\n return renderToString(\n <LayoutRenderer layout={layout} components={[Header]} areas={areas}>\n <article>The entry</article>\n </LayoutRenderer>\n );\n};\n\ndescribe(\"LayoutRenderer\", () => {\n beforeAll(() => {\n contentSdk.init({ apiKey: \"key\", apiHost: \"https://api.test\", apiTenant: \"root\" });\n });\n\n it(\"renders the children in Main content, inside the layout\", () => {\n const html = render(createLayout({ elements: {}, bindings: {} }));\n\n expect(html).toContain(\"<article>The entry</article>\");\n expect(html.indexOf(\"<header>\")).toBeLessThan(html.indexOf(\"<article>\"));\n });\n\n it(\"renders a global the layout places from its manifest defaults when it was never saved\", () => {\n const html = render(createLayout({ elements: {}, bindings: {} }));\n\n expect(html).toContain(\"<header>Welcome</header>\");\n });\n\n it(\"renders a global the layout places with its delivered values\", () => {\n const html = render(\n createLayout({\n elements: {\n \"$global:Test/Header\": element(\"$global:Test/Header\", \"Test/Header\")\n },\n bindings: {\n \"$global:Test/Header\": {\n inputs: { title: { id: \"title\", type: \"text\", static: \"ACME Inc\" } }\n }\n }\n })\n );\n\n expect(html).toContain(\"<header>ACME Inc</header>\");\n });\n\n it(\"fills named content areas by name, and leaves the others empty\", () => {\n const html = render(createLayout({ elements: {}, bindings: {} }), {\n sidebar: <aside>Related</aside>\n });\n\n expect(html).toContain(\"<aside>Related</aside>\");\n expect(html.indexOf(\"<article>\")).toBeLessThan(html.indexOf(\"<aside>\"));\n expect(html).not.toContain(\"promo\");\n });\n});\n"],"names":["Header","createComponent","inputs","createTextInput","element","id","name","parentId","undefined","createLayout","globals","render","layout","areas","renderToString","LayoutRenderer","describe","beforeAll","contentSdk","it","html","expect"],"mappings":";;;;;;AAQA,MAAMA,SAASC,gBACX,CAAC,EAAEC,MAAM,EAAqC,iBAAK,oBAAC,gBAAQA,OAAO,KAAK,GACxE;IACI,MAAM;IACN,QAAQ;IACR,QAAQ;QAACC,gBAAgB;YAAE,MAAM;YAAS,cAAc;QAAU;KAAG;AACzE;AAGJ,MAAMC,8BAAU,CAACC,IAAYC,MAAcC,WAAuB;QAC9D,MAAM;QACNF;QACA,WAAW;YAAEC;QAAK;QAClB,QAAQC,WAAW;YAAE,IAAIA;YAAU,MAAM;QAAW,IAAIC;IAC5D;AAEA,MAAMC,eAAe,CAACC,UAAwE;QAC1F,GAAGA,OAAO;QACV,QAAQ;YACJ,IAAI;YACJ,UAAU;gBACN,MAAMN,4BAAQ,QAAQ;gBACtB,QAAQA,4BAAQ,UAAU,eAAe;gBACzC,MAAMA,4BAAQ,QAAQ,wBAAwB;gBAC9C,SAASA,4BAAQ,WAAW,uBAAuB;gBACnD,OAAOA,4BAAQ,SAAS,uBAAuB;YACnD;YACA,UAAU;gBACN,MAAM;oBACF,QAAQ;wBACJ,UAAU;4BACN,IAAI;4BACJ,MAAM;4BACN,MAAM;4BACN,QAAQ;gCAAC;gCAAU;gCAAQ;gCAAW;6BAAQ;wBAClD;oBACJ;gBACJ;gBACA,SAAS;oBAAE,QAAQ;wBAAE,MAAM;4BAAE,IAAI;4BAAgB,MAAM;4BAAQ,QAAQ;wBAAU;oBAAE;gBAAE;gBACrF,OAAO;oBAAE,QAAQ;wBAAE,MAAM;4BAAE,IAAI;4BAAc,MAAM;4BAAQ,QAAQ;wBAAQ;oBAAE;gBAAE;YACnF;QACJ;IACJ;AAEA,MAAMO,SAAS,CAACC,QAAsBC,QAC3BC,eAAe,WAADA,GACjB,oBAACC,gBAAcA;QAAC,QAAQH;QAAQ,YAAY;YAACZ;SAAO;QAAE,OAAOa;qBACzD,oBAAC,iBAAQ;AAKrBG,SAAS,kBAAkB;IACvBC,UAAU;QACNC,WAAW,IAAI,CAAC;YAAE,QAAQ;YAAO,SAAS;YAAoB,WAAW;QAAO;IACpF;IAEAC,GAAG,2DAA2D;QAC1D,MAAMC,OAAOT,OAAOF,aAAa;YAAE,UAAU,CAAC;YAAG,UAAU,CAAC;QAAE;QAE9DY,OAAOD,MAAM,SAAS,CAAC;QACvBC,OAAOD,KAAK,OAAO,CAAC,aAAa,YAAY,CAACA,KAAK,OAAO,CAAC;IAC/D;IAEAD,GAAG,yFAAyF;QACxF,MAAMC,OAAOT,OAAOF,aAAa;YAAE,UAAU,CAAC;YAAG,UAAU,CAAC;QAAE;QAE9DY,OAAOD,MAAM,SAAS,CAAC;IAC3B;IAEAD,GAAG,gEAAgE;QAC/D,MAAMC,OAAOT,OACTF,aAAa;YACT,UAAU;gBACN,uBAAuBL,4BAAQ,uBAAuB;YAC1D;YACA,UAAU;gBACN,uBAAuB;oBACnB,QAAQ;wBAAE,OAAO;4BAAE,IAAI;4BAAS,MAAM;4BAAQ,QAAQ;wBAAW;oBAAE;gBACvE;YACJ;QACJ;QAGJiB,OAAOD,MAAM,SAAS,CAAC;IAC3B;IAEAD,GAAG,kEAAkE;QACjE,MAAMC,OAAOT,OAAOF,aAAa;YAAE,UAAU,CAAC;YAAG,UAAU,CAAC;QAAE,IAAI;YAC9D,SAAS,WAAT,GAAS,oBAAC,eAAM;QACpB;QAEAY,OAAOD,MAAM,SAAS,CAAC;QACvBC,OAAOD,KAAK,OAAO,CAAC,cAAc,YAAY,CAACA,KAAK,OAAO,CAAC;QAC5DC,OAAOD,MAAM,GAAG,CAAC,SAAS,CAAC;IAC/B;AACJ"}
|
|
@@ -4,7 +4,7 @@ interface LiveElementRendererProps {
|
|
|
4
4
|
element: DocumentElement;
|
|
5
5
|
bindings?: DocumentElementBindings;
|
|
6
6
|
}
|
|
7
|
-
export declare const LiveElementRenderer: (({ element }: LiveElementRendererProps) => React.JSX.Element | null) & {
|
|
8
|
-
|
|
7
|
+
export declare const LiveElementRenderer: (({ element }: LiveElementRendererProps) => React.JSX.Element | null) & React.NamedExoticComponent<LiveElementRendererProps> & {
|
|
8
|
+
readonly type: ({ element }: LiveElementRendererProps) => React.JSX.Element | null;
|
|
9
9
|
};
|
|
10
10
|
export {};
|
|
@@ -1,78 +1,69 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import React, { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import react, { useCallback, useEffect, useState } from "react";
|
|
4
3
|
import { observer } from "mobx-react-lite";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}, props));
|
|
68
|
-
if (!autoApplyStyles) {
|
|
69
|
-
return userElement;
|
|
70
|
-
}
|
|
71
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
72
|
-
key: index,
|
|
73
|
-
style: styles
|
|
74
|
-
}, userElement);
|
|
75
|
-
}));
|
|
4
|
+
import { ElementSlot } from "./ElementSlot.js";
|
|
5
|
+
import { useViewport } from "./useViewportInfo.js";
|
|
6
|
+
import { useBindingsForElement } from "./useBindingsForElement.js";
|
|
7
|
+
import { useDocumentState } from "./useDocumentState.js";
|
|
8
|
+
import { useDocumentStore } from "./DocumentStoreProvider.js";
|
|
9
|
+
import { useContentClient } from "./useContentClient.js";
|
|
10
|
+
const LiveElementRenderer = observer(({ element })=>{
|
|
11
|
+
const viewport = useViewport();
|
|
12
|
+
const client = useContentClient();
|
|
13
|
+
const [breakpoint, setBreakpoint] = useState("desktop");
|
|
14
|
+
useEffect(()=>{
|
|
15
|
+
if (viewport.breakpoint && viewport.breakpoint !== breakpoint) setBreakpoint(viewport.breakpoint);
|
|
16
|
+
}, [
|
|
17
|
+
viewport.breakpoint,
|
|
18
|
+
breakpoint
|
|
19
|
+
]);
|
|
20
|
+
const elementBindings = useBindingsForElement(element.id, breakpoint);
|
|
21
|
+
const state = useDocumentState();
|
|
22
|
+
const documentStore = useDocumentStore();
|
|
23
|
+
const document = documentStore.getDocument();
|
|
24
|
+
const onResolved = useCallback((value, input)=>{
|
|
25
|
+
if ("slot" === input.type) return /*#__PURE__*/ react.createElement(ElementSlot, {
|
|
26
|
+
key: element.id,
|
|
27
|
+
parentId: element.id,
|
|
28
|
+
slot: input.name,
|
|
29
|
+
elements: input.list ? value : [
|
|
30
|
+
value
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
return value;
|
|
34
|
+
}, [
|
|
35
|
+
element.id
|
|
36
|
+
]);
|
|
37
|
+
if (!element || !element.component) return null;
|
|
38
|
+
const instances = client.resolveElement({
|
|
39
|
+
element,
|
|
40
|
+
state,
|
|
41
|
+
elementBindings,
|
|
42
|
+
cache: document?.__cache,
|
|
43
|
+
onResolved
|
|
44
|
+
});
|
|
45
|
+
if (!instances) return null;
|
|
46
|
+
return /*#__PURE__*/ react.createElement(react.Fragment, null, instances.map((resolvedElement, index)=>{
|
|
47
|
+
const { component: Component, inputs, styles, manifest } = resolvedElement;
|
|
48
|
+
const props = {
|
|
49
|
+
inputs,
|
|
50
|
+
styles,
|
|
51
|
+
element,
|
|
52
|
+
breakpoint: viewport.breakpoint,
|
|
53
|
+
breakpoints: viewport.breakpoints.map((bp)=>bp.name)
|
|
54
|
+
};
|
|
55
|
+
const autoApplyStyles = false !== manifest.autoApplyStyles;
|
|
56
|
+
const userElement = /*#__PURE__*/ react.createElement(Component, {
|
|
57
|
+
key: element.id,
|
|
58
|
+
...props
|
|
59
|
+
});
|
|
60
|
+
if (!autoApplyStyles) return userElement;
|
|
61
|
+
return /*#__PURE__*/ react.createElement("div", {
|
|
62
|
+
key: index,
|
|
63
|
+
style: styles
|
|
64
|
+
}, userElement);
|
|
65
|
+
}));
|
|
76
66
|
});
|
|
67
|
+
export { LiveElementRenderer };
|
|
77
68
|
|
|
78
69
|
//# sourceMappingURL=LiveElementRenderer.js.map
|