@webiny/website-builder-react 0.0.0-unstable.81ae05e56b → 0.0.0-unstable.9609e4e0c9
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/components/ConnectToEditor.d.ts +3 -1
- package/components/ConnectToEditor.js +20 -20
- 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.js +5 -7
- package/components/DocumentFragment.js.map +1 -1
- package/components/DocumentRenderer.d.ts +8 -3
- package/components/DocumentRenderer.js +51 -48
- package/components/DocumentRenderer.js.map +1 -1
- package/components/DocumentStoreProvider.d.ts +7 -0
- package/components/DocumentStoreProvider.js +22 -22
- package/components/DocumentStoreProvider.js.map +1 -1
- package/components/EditingElementRenderer/EditingElementRenderer.d.ts +7 -2
- package/components/EditingElementRenderer/EditingElementRenderer.js +43 -35
- 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 +9 -9
- package/components/ElementSlot.js.map +1 -1
- package/components/ElementSlotDepthProvider.js +9 -14
- package/components/ElementSlotDepthProvider.js.map +1 -1
- package/components/FragmentsProvider.js +32 -37
- 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 +59 -69
- package/components/LiveElementRenderer.js.map +1 -1
- package/components/LiveElementSlot.js +12 -14
- 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 +27 -23
- 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.js +13 -11
- 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.js +4 -3
- 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.js +29 -35
- package/components/useSelectFromState.js.map +1 -1
- 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 -3
- package/createComponent.js +1 -37
- package/createComponent.test.js +108 -122
- package/createComponent.test.js.map +1 -1
- package/editorComponents/Box.js +3 -6
- package/editorComponents/Box.js.map +1 -1
- package/editorComponents/Box.manifest.js +15 -14
- package/editorComponents/Box.manifest.js.map +1 -1
- package/editorComponents/Fragment.js +23 -32
- package/editorComponents/Fragment.js.map +1 -1
- package/editorComponents/Fragment.manifest.js +14 -11
- package/editorComponents/Fragment.manifest.js.map +1 -1
- package/editorComponents/Grid.js +33 -61
- package/editorComponents/Grid.js.map +1 -1
- package/editorComponents/Grid.manifest.js +163 -166
- package/editorComponents/Grid.manifest.js.map +1 -1
- package/editorComponents/GridColumn.js +3 -6
- package/editorComponents/GridColumn.js.map +1 -1
- package/editorComponents/GridColumn.manifest.js +20 -17
- package/editorComponents/GridColumn.manifest.js.map +1 -1
- package/editorComponents/Image.js +99 -119
- package/editorComponents/Image.js.map +1 -1
- package/editorComponents/Image.manifest.js +33 -32
- 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.js +13 -21
- package/editorComponents/Lexical.js.map +1 -1
- package/editorComponents/Lexical.manifest.js +17 -14
- package/editorComponents/Lexical.manifest.js.map +1 -1
- package/editorComponents/Root.js +3 -6
- package/editorComponents/Root.js.map +1 -1
- package/editorComponents/Root.manifest.js +7 -6
- package/editorComponents/Root.manifest.js.map +1 -1
- package/editorComponents/index.js +13 -1
- 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 +3 -2
- package/index.js +2 -4
- package/package.json +13 -12
- package/types.d.ts +2 -4
- 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,8 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { type Component, type Document } from "@webiny/website-builder-sdk";
|
|
3
|
+
import type { DocumentLayout } from "../components/renderWithLayout.js";
|
|
3
4
|
interface ConnectToEditorProps {
|
|
4
|
-
document: Document;
|
|
5
|
+
document: Document | null;
|
|
5
6
|
components: Component[];
|
|
7
|
+
layout?: DocumentLayout;
|
|
6
8
|
}
|
|
7
9
|
export declare const ConnectToEditor: (props: ConnectToEditorProps) => React.JSX.Element | null;
|
|
8
10
|
export {};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import React, { useEffect, useState } from "react";
|
|
4
|
-
import { contentSdk } from "@webiny/website-builder-sdk";
|
|
2
|
+
import react, { useEffect, useState } from "react";
|
|
5
3
|
import { DocumentStoreProvider } from "./DocumentStoreProvider.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
import { PageWithLayout } from "./PageLayout.js";
|
|
5
|
+
import { useContentClient } from "./useContentClient.js";
|
|
6
|
+
const ConnectToEditor = (props)=>{
|
|
7
|
+
const client = useContentClient();
|
|
8
|
+
const [data, setData] = useState(null);
|
|
9
|
+
useEffect(()=>{
|
|
10
|
+
const load = props.document ? client.getPage(props.document.properties.path) : client.getEditingSdk()?.getEditedDocument() ?? Promise.resolve(null);
|
|
11
|
+
load.then((document)=>{
|
|
12
|
+
setData(document);
|
|
13
|
+
});
|
|
14
|
+
}, []);
|
|
15
|
+
if (!data) return null;
|
|
16
|
+
return /*#__PURE__*/ react.createElement(DocumentStoreProvider, {
|
|
17
|
+
id: data.properties.id,
|
|
18
|
+
document: data
|
|
19
|
+
}, /*#__PURE__*/ react.createElement(PageWithLayout, {
|
|
20
|
+
layout: props.layout
|
|
21
|
+
}));
|
|
23
22
|
};
|
|
23
|
+
export { ConnectToEditor };
|
|
24
24
|
|
|
25
25
|
//# sourceMappingURL=ConnectToEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"components/ConnectToEditor.js","sources":["../../src/components/ConnectToEditor.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useState } from \"react\";\nimport { type Component, type Document } from \"@webiny/website-builder-sdk\";\nimport { DocumentStoreProvider } from \"~/components/DocumentStoreProvider.js\";\nimport type { DocumentLayout } from \"~/components/renderWithLayout.js\";\nimport { PageWithLayout } from \"~/components/PageLayout.js\";\nimport { useContentClient } from \"~/components/useContentClient.js\";\n\ninterface ConnectToEditorProps {\n // Without a document, render the document open in the editor, whatever its type (e.g., a layout).\n document: Document | null;\n components: Component[];\n layout?: DocumentLayout;\n}\n\nexport const ConnectToEditor = (props: ConnectToEditorProps) => {\n const client = useContentClient();\n const [data, setData] = useState<Document | null>(null);\n\n useEffect(() => {\n const load = props.document\n ? client.getPage(props.document.properties.path)\n : (client.getEditingSdk()?.getEditedDocument() ?? Promise.resolve(null));\n\n load.then(document => {\n setData(document);\n });\n }, []);\n\n if (!data) {\n return null;\n }\n\n return (\n <DocumentStoreProvider id={data.properties.id} document={data}>\n <PageWithLayout layout={props.layout} />\n </DocumentStoreProvider>\n );\n};\n"],"names":["ConnectToEditor","props","client","useContentClient","data","setData","useState","useEffect","load","Promise","document","DocumentStoreProvider","PageWithLayout"],"mappings":";;;;;AAeO,MAAMA,kBAAkB,CAACC;IAC5B,MAAMC,SAASC;IACf,MAAM,CAACC,MAAMC,QAAQ,GAAGC,SAA0B;IAElDC,UAAU;QACN,MAAMC,OAAOP,MAAM,QAAQ,GACrBC,OAAO,OAAO,CAACD,MAAM,QAAQ,CAAC,UAAU,CAAC,IAAI,IAC5CC,OAAO,aAAa,IAAI,uBAAuBO,QAAQ,OAAO,CAAC;QAEtED,KAAK,IAAI,CAACE,CAAAA;YACNL,QAAQK;QACZ;IACJ,GAAG,EAAE;IAEL,IAAI,CAACN,MACD,OAAO;IAGX,OAAO,WAAP,GACI,oBAACO,uBAAqBA;QAAC,IAAIP,KAAK,UAAU,CAAC,EAAE;QAAE,UAAUA;qBACrD,oBAACQ,gBAAcA;QAAC,QAAQX,MAAM,MAAM;;AAGhD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/ContentClientContext.js","sources":["../../src/components/ContentClientContext.ts"],"sourcesContent":["\"use client\";\nimport React from \"react\";\nimport type { ContentClient } from \"@webiny/website-builder-sdk\";\n\nexport const ContentClientContext = React.createContext<ContentClient | undefined>(undefined);\n"],"names":["ContentClientContext","React","undefined"],"mappings":";;AAIO,MAAMA,uBAAuBC,MAAAA,aAAmB,CAA4BC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ContentClient } from "@webiny/website-builder-sdk";
|
|
3
|
+
interface ContentClientProviderProps {
|
|
4
|
+
client: ContentClient;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Renders the documents below it with `client`: its component registry, content entry cache,
|
|
9
|
+
* document stores and data. Without this provider, renderers use the `contentSdk` singleton.
|
|
10
|
+
*/
|
|
11
|
+
export declare const ContentClientProvider: ({ client, children }: ContentClientProviderProps) => React.JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import react from "react";
|
|
3
|
+
import { ContentClientContext } from "./ContentClientContext.js";
|
|
4
|
+
const ContentClientProvider = ({ client, children })=>/*#__PURE__*/ react.createElement(ContentClientContext.Provider, {
|
|
5
|
+
value: client
|
|
6
|
+
}, children);
|
|
7
|
+
export { ContentClientProvider };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=ContentClientProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/ContentClientProvider.js","sources":["../../src/components/ContentClientProvider.tsx"],"sourcesContent":["\"use client\";\nimport React from \"react\";\nimport type { ContentClient } from \"@webiny/website-builder-sdk\";\nimport { ContentClientContext } from \"./ContentClientContext.js\";\n\ninterface ContentClientProviderProps {\n client: ContentClient;\n children: React.ReactNode;\n}\n\n/**\n * Renders the documents below it with `client`: its component registry, content entry cache,\n * document stores and data. Without this provider, renderers use the `contentSdk` singleton.\n */\nexport const ContentClientProvider = ({ client, children }: ContentClientProviderProps) => {\n return <ContentClientContext.Provider value={client}>{children}</ContentClientContext.Provider>;\n};\n"],"names":["ContentClientProvider","client","children","ContentClientContext"],"mappings":";;;AAcO,MAAMA,wBAAwB,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAA8B,GAC3E,WAAP,GAAO,oBAACC,qBAAqB,QAAQ;QAAC,OAAOF;OAASC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import react from "react";
|
|
2
|
+
import { renderToString } from "react-dom/server";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { componentRegistry, contentSdk, createContentClient } from "@webiny/website-builder-sdk";
|
|
5
|
+
import { ContentClientProvider } from "./ContentClientProvider.js";
|
|
6
|
+
import { DocumentRenderer } from "./DocumentRenderer.js";
|
|
7
|
+
const componentLabels = {
|
|
8
|
+
"tenant-a": "Hero from tenant A",
|
|
9
|
+
"tenant-b": "Hero from tenant B"
|
|
10
|
+
};
|
|
11
|
+
const createBlueprint = (name, label)=>{
|
|
12
|
+
const Hero = ()=>/*#__PURE__*/ react.createElement("span", null, label);
|
|
13
|
+
return {
|
|
14
|
+
component: Hero,
|
|
15
|
+
manifest: {
|
|
16
|
+
name,
|
|
17
|
+
inputs: [],
|
|
18
|
+
tags: []
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const createDocument = (componentName)=>({
|
|
23
|
+
id: "page-1",
|
|
24
|
+
version: 1,
|
|
25
|
+
state: {},
|
|
26
|
+
properties: {
|
|
27
|
+
id: "page-1",
|
|
28
|
+
path: "/"
|
|
29
|
+
},
|
|
30
|
+
extensions: {},
|
|
31
|
+
metadata: {},
|
|
32
|
+
bindings: {},
|
|
33
|
+
elements: {
|
|
34
|
+
root: {
|
|
35
|
+
type: "Webiny/Element",
|
|
36
|
+
id: "root",
|
|
37
|
+
component: {
|
|
38
|
+
name: componentName
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const tenantComponentLoader = ({ apiClient })=>({
|
|
44
|
+
async loadComponent (ref) {
|
|
45
|
+
const data = await apiClient.query({
|
|
46
|
+
query: "query LoadComponent($name: String!) { component(name: $name) { label } }",
|
|
47
|
+
variables: {
|
|
48
|
+
name: ref.name
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return createBlueprint(ref.name, data.component.label);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
describe("ContentClientProvider", ()=>{
|
|
55
|
+
beforeEach(()=>{
|
|
56
|
+
const fetchMock = vi.fn(async (_url, init)=>{
|
|
57
|
+
const headers = init.headers;
|
|
58
|
+
const tenant = headers["X-Tenant"];
|
|
59
|
+
const delay = "tenant-a" === tenant ? 20 : 0;
|
|
60
|
+
await new Promise((resolve)=>setTimeout(resolve, delay));
|
|
61
|
+
return {
|
|
62
|
+
json: async ()=>({
|
|
63
|
+
data: {
|
|
64
|
+
component: {
|
|
65
|
+
label: componentLabels[tenant]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
72
|
+
});
|
|
73
|
+
afterEach(()=>{
|
|
74
|
+
vi.unstubAllGlobals();
|
|
75
|
+
});
|
|
76
|
+
it("renders each tenant's same-name component through its own client, concurrently", async ()=>{
|
|
77
|
+
const document = createDocument("Acme/Hero");
|
|
78
|
+
const renderFor = async (tenant)=>{
|
|
79
|
+
const client = createContentClient({
|
|
80
|
+
apiHost: `https://${tenant}.example.com`,
|
|
81
|
+
apiKey: `key-${tenant}`,
|
|
82
|
+
apiTenant: tenant,
|
|
83
|
+
componentLoader: tenantComponentLoader
|
|
84
|
+
});
|
|
85
|
+
await client.loadDocumentComponents(document);
|
|
86
|
+
return renderToString(/*#__PURE__*/ react.createElement(ContentClientProvider, {
|
|
87
|
+
client: client
|
|
88
|
+
}, /*#__PURE__*/ react.createElement(DocumentRenderer, {
|
|
89
|
+
document: document,
|
|
90
|
+
components: []
|
|
91
|
+
})));
|
|
92
|
+
};
|
|
93
|
+
const [htmlA, htmlB] = await Promise.all([
|
|
94
|
+
renderFor("tenant-a"),
|
|
95
|
+
renderFor("tenant-b")
|
|
96
|
+
]);
|
|
97
|
+
expect(htmlA).toContain("Hero from tenant A");
|
|
98
|
+
expect(htmlA).not.toContain("Hero from tenant B");
|
|
99
|
+
expect(htmlB).toContain("Hero from tenant B");
|
|
100
|
+
expect(htmlB).not.toContain("Hero from tenant A");
|
|
101
|
+
expect(componentRegistry.get("Acme/Hero")).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
it("uses the contentSdk singleton without a provider, as before", ()=>{
|
|
104
|
+
contentSdk.init({
|
|
105
|
+
apiHost: "https://root.example.com",
|
|
106
|
+
apiKey: "key-root",
|
|
107
|
+
apiTenant: "root"
|
|
108
|
+
});
|
|
109
|
+
const document = createDocument("Acme/SingletonHero");
|
|
110
|
+
const html = renderToString(/*#__PURE__*/ react.createElement(DocumentRenderer, {
|
|
111
|
+
document: document,
|
|
112
|
+
components: [
|
|
113
|
+
createBlueprint("Acme/SingletonHero", "Singleton hero")
|
|
114
|
+
]
|
|
115
|
+
}));
|
|
116
|
+
expect(html).toContain("Singleton hero");
|
|
117
|
+
expect(componentRegistry.get("Acme/SingletonHero")).toBeDefined();
|
|
118
|
+
expect(contentSdk.getDocumentStoreManager().hasStore("page-1")).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
it("doesn't render the singleton's components inside a provider", ()=>{
|
|
121
|
+
contentSdk.init({
|
|
122
|
+
apiHost: "https://root.example.com",
|
|
123
|
+
apiKey: "key-root",
|
|
124
|
+
apiTenant: "root"
|
|
125
|
+
});
|
|
126
|
+
contentSdk.registerComponent(createBlueprint("Acme/SingletonHero", "Singleton hero"));
|
|
127
|
+
const client = createContentClient({
|
|
128
|
+
apiHost: "https://a.example.com",
|
|
129
|
+
apiKey: "key-a",
|
|
130
|
+
apiTenant: "tenant-a"
|
|
131
|
+
});
|
|
132
|
+
const document = createDocument("Acme/SingletonHero");
|
|
133
|
+
const html = renderToString(/*#__PURE__*/ react.createElement(ContentClientProvider, {
|
|
134
|
+
client: client
|
|
135
|
+
}, /*#__PURE__*/ react.createElement(DocumentRenderer, {
|
|
136
|
+
document: document,
|
|
137
|
+
components: []
|
|
138
|
+
})));
|
|
139
|
+
expect(html).not.toContain("Singleton hero");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
//# sourceMappingURL=ContentClientProvider.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/ContentClientProvider.test.js","sources":["../../src/components/ContentClientProvider.test.tsx"],"sourcesContent":["import React from \"react\";\nimport { renderToString } from \"react-dom/server\";\nimport { describe, it, expect, beforeEach, afterEach, vi } from \"vitest\";\nimport {\n componentRegistry,\n contentSdk,\n createContentClient,\n type Component,\n type ComponentLoaderFactory,\n type Document,\n type ElementComponent\n} from \"@webiny/website-builder-sdk\";\nimport { ContentClientProvider } from \"./ContentClientProvider.js\";\nimport { DocumentRenderer } from \"./DocumentRenderer.js\";\n\nconst componentLabels: Record<string, string> = {\n \"tenant-a\": \"Hero from tenant A\",\n \"tenant-b\": \"Hero from tenant B\"\n};\n\nconst createBlueprint = (name: string, label: string): Component => {\n const Hero = () => <span>{label}</span>;\n return { component: Hero, manifest: { name, inputs: [], tags: [] } };\n};\n\nconst createDocument = (componentName: string): Document => {\n return {\n id: \"page-1\",\n version: 1,\n state: {},\n properties: { id: \"page-1\", path: \"/\" },\n extensions: {},\n metadata: {} as Document[\"metadata\"],\n bindings: {},\n elements: {\n root: {\n type: \"Webiny/Element\",\n id: \"root\",\n component: { name: componentName }\n }\n }\n };\n};\n\n// Fetches the component through the client's own API client, so it reaches the client's tenant.\nconst tenantComponentLoader: ComponentLoaderFactory = ({ apiClient }) => {\n return {\n async loadComponent(ref: ElementComponent) {\n const data = await apiClient.query({\n query: \"query LoadComponent($name: String!) { component(name: $name) { label } }\",\n variables: { name: ref.name }\n });\n return createBlueprint(ref.name, data.component.label);\n }\n };\n};\n\ndescribe(\"ContentClientProvider\", () => {\n beforeEach(() => {\n const fetchMock = vi.fn(async (_url: string, init: RequestInit) => {\n const headers = init.headers as Record<string, string>;\n const tenant = headers[\"X-Tenant\"];\n\n // Tenant A answers last, so the two requests interleave.\n const delay = tenant === \"tenant-a\" ? 20 : 0;\n await new Promise(resolve => setTimeout(resolve, delay));\n\n return {\n json: async () => ({ data: { component: { label: componentLabels[tenant] } } })\n };\n });\n\n vi.stubGlobal(\"fetch\", fetchMock);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n });\n\n it(\"renders each tenant's same-name component through its own client, concurrently\", async () => {\n const document = createDocument(\"Acme/Hero\");\n\n const renderFor = async (tenant: string) => {\n const client = createContentClient({\n apiHost: `https://${tenant}.example.com`,\n apiKey: `key-${tenant}`,\n apiTenant: tenant,\n componentLoader: tenantComponentLoader\n });\n await client.loadDocumentComponents(document);\n\n return renderToString(\n <ContentClientProvider client={client}>\n <DocumentRenderer document={document} components={[]} />\n </ContentClientProvider>\n );\n };\n\n const [htmlA, htmlB] = await Promise.all([renderFor(\"tenant-a\"), renderFor(\"tenant-b\")]);\n\n expect(htmlA).toContain(\"Hero from tenant A\");\n expect(htmlA).not.toContain(\"Hero from tenant B\");\n expect(htmlB).toContain(\"Hero from tenant B\");\n expect(htmlB).not.toContain(\"Hero from tenant A\");\n expect(componentRegistry.get(\"Acme/Hero\")).toBeUndefined();\n });\n\n it(\"uses the contentSdk singleton without a provider, as before\", () => {\n contentSdk.init({\n apiHost: \"https://root.example.com\",\n apiKey: \"key-root\",\n apiTenant: \"root\"\n });\n const document = createDocument(\"Acme/SingletonHero\");\n\n const html = renderToString(\n <DocumentRenderer\n document={document}\n components={[createBlueprint(\"Acme/SingletonHero\", \"Singleton hero\")]}\n />\n );\n\n expect(html).toContain(\"Singleton hero\");\n expect(componentRegistry.get(\"Acme/SingletonHero\")).toBeDefined();\n expect(contentSdk.getDocumentStoreManager().hasStore(\"page-1\")).toBe(true);\n });\n\n it(\"doesn't render the singleton's components inside a provider\", () => {\n contentSdk.init({\n apiHost: \"https://root.example.com\",\n apiKey: \"key-root\",\n apiTenant: \"root\"\n });\n contentSdk.registerComponent(createBlueprint(\"Acme/SingletonHero\", \"Singleton hero\"));\n const client = createContentClient({\n apiHost: \"https://a.example.com\",\n apiKey: \"key-a\",\n apiTenant: \"tenant-a\"\n });\n const document = createDocument(\"Acme/SingletonHero\");\n\n const html = renderToString(\n <ContentClientProvider client={client}>\n <DocumentRenderer document={document} components={[]} />\n </ContentClientProvider>\n );\n\n expect(html).not.toContain(\"Singleton hero\");\n });\n});\n"],"names":["componentLabels","createBlueprint","name","label","Hero","createDocument","componentName","tenantComponentLoader","apiClient","ref","data","describe","beforeEach","fetchMock","vi","_url","init","headers","tenant","delay","Promise","resolve","setTimeout","afterEach","it","document","renderFor","client","createContentClient","renderToString","ContentClientProvider","DocumentRenderer","htmlA","htmlB","expect","componentRegistry","contentSdk","html"],"mappings":";;;;;;AAeA,MAAMA,kBAA0C;IAC5C,YAAY;IACZ,YAAY;AAChB;AAEA,MAAMC,kBAAkB,CAACC,MAAcC;IACnC,MAAMC,OAAO,kBAAM,oBAAC,cAAMD;IAC1B,OAAO;QAAE,WAAWC;QAAM,UAAU;YAAEF;YAAM,QAAQ,EAAE;YAAE,MAAM,EAAE;QAAC;IAAE;AACvE;AAEA,MAAMG,iBAAiB,CAACC,gBACb;QACH,IAAI;QACJ,SAAS;QACT,OAAO,CAAC;QACR,YAAY;YAAE,IAAI;YAAU,MAAM;QAAI;QACtC,YAAY,CAAC;QACb,UAAU,CAAC;QACX,UAAU,CAAC;QACX,UAAU;YACN,MAAM;gBACF,MAAM;gBACN,IAAI;gBACJ,WAAW;oBAAE,MAAMA;gBAAc;YACrC;QACJ;IACJ;AAIJ,MAAMC,wBAAgD,CAAC,EAAEC,SAAS,EAAE,GACzD;QACH,MAAM,eAAcC,GAAqB;YACrC,MAAMC,OAAO,MAAMF,UAAU,KAAK,CAAC;gBAC/B,OAAO;gBACP,WAAW;oBAAE,MAAMC,IAAI,IAAI;gBAAC;YAChC;YACA,OAAOR,gBAAgBQ,IAAI,IAAI,EAAEC,KAAK,SAAS,CAAC,KAAK;QACzD;IACJ;AAGJC,SAAS,yBAAyB;IAC9BC,WAAW;QACP,MAAMC,YAAYC,GAAG,EAAE,CAAC,OAAOC,MAAcC;YACzC,MAAMC,UAAUD,KAAK,OAAO;YAC5B,MAAME,SAASD,OAAO,CAAC,WAAW;YAGlC,MAAME,QAAQD,AAAW,eAAXA,SAAwB,KAAK;YAC3C,MAAM,IAAIE,QAAQC,CAAAA,UAAWC,WAAWD,SAASF;YAEjD,OAAO;gBACH,MAAM,UAAa;wBAAE,MAAM;4BAAE,WAAW;gCAAE,OAAOnB,eAAe,CAACkB,OAAO;4BAAC;wBAAE;oBAAE;YACjF;QACJ;QAEAJ,GAAG,UAAU,CAAC,SAASD;IAC3B;IAEAU,UAAU;QACNT,GAAG,gBAAgB;IACvB;IAEAU,GAAG,kFAAkF;QACjF,MAAMC,WAAWpB,eAAe;QAEhC,MAAMqB,YAAY,OAAOR;YACrB,MAAMS,SAASC,oBAAoB;gBAC/B,SAAS,CAAC,QAAQ,EAAEV,OAAO,YAAY,CAAC;gBACxC,QAAQ,CAAC,IAAI,EAAEA,QAAQ;gBACvB,WAAWA;gBACX,iBAAiBX;YACrB;YACA,MAAMoB,OAAO,sBAAsB,CAACF;YAEpC,OAAOI,eAAe,WAADA,GACjB,oBAACC,uBAAqBA;gBAAC,QAAQH;6BAC3B,oBAACI,kBAAgBA;gBAAC,UAAUN;gBAAU,YAAY,EAAE;;QAGhE;QAEA,MAAM,CAACO,OAAOC,MAAM,GAAG,MAAMb,QAAQ,GAAG,CAAC;YAACM,UAAU;YAAaA,UAAU;SAAY;QAEvFQ,OAAOF,OAAO,SAAS,CAAC;QACxBE,OAAOF,OAAO,GAAG,CAAC,SAAS,CAAC;QAC5BE,OAAOD,OAAO,SAAS,CAAC;QACxBC,OAAOD,OAAO,GAAG,CAAC,SAAS,CAAC;QAC5BC,OAAOC,kBAAkB,GAAG,CAAC,cAAc,aAAa;IAC5D;IAEAX,GAAG,+DAA+D;QAC9DY,WAAW,IAAI,CAAC;YACZ,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QACA,MAAMX,WAAWpB,eAAe;QAEhC,MAAMgC,OAAOR,eAAe,WAADA,GACvB,oBAACE,kBAAgBA;YACb,UAAUN;YACV,YAAY;gBAACxB,gBAAgB,sBAAsB;aAAkB;;QAI7EiC,OAAOG,MAAM,SAAS,CAAC;QACvBH,OAAOC,kBAAkB,GAAG,CAAC,uBAAuB,WAAW;QAC/DD,OAAOE,WAAW,uBAAuB,GAAG,QAAQ,CAAC,WAAW,IAAI,CAAC;IACzE;IAEAZ,GAAG,+DAA+D;QAC9DY,WAAW,IAAI,CAAC;YACZ,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QACAA,WAAW,iBAAiB,CAACnC,gBAAgB,sBAAsB;QACnE,MAAM0B,SAASC,oBAAoB;YAC/B,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QACA,MAAMH,WAAWpB,eAAe;QAEhC,MAAMgC,OAAOR,eAAe,WAADA,GACvB,oBAACC,uBAAqBA;YAAC,QAAQH;yBAC3B,oBAACI,kBAAgBA;YAAC,UAAUN;YAAU,YAAY,EAAE;;QAI5DS,OAAOG,MAAM,GAAG,CAAC,SAAS,CAAC;IAC/B;AACJ"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, props.children);
|
|
7
|
-
}
|
|
8
|
-
return null;
|
|
2
|
+
import react from "react";
|
|
3
|
+
function DocumentFragment(props) {
|
|
4
|
+
if (props.children) return /*#__PURE__*/ react.createElement(react.Fragment, null, props.children);
|
|
5
|
+
return null;
|
|
9
6
|
}
|
|
7
|
+
export { DocumentFragment };
|
|
10
8
|
|
|
11
9
|
//# sourceMappingURL=DocumentFragment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"components/DocumentFragment.js","sources":["../../src/components/DocumentFragment.tsx"],"sourcesContent":["\"use client\";\nimport React from \"react\";\n\nexport type DocumentFragmentProps =\n | {\n name: string;\n children: React.ReactNode;\n component?: never;\n inputs?: never;\n }\n | {\n component: string;\n inputs?: Record<string, any>;\n name?: never;\n children?: never;\n };\n\nexport function DocumentFragment(props: DocumentFragmentProps) {\n if (props.children) {\n return <>{props.children}</>;\n }\n\n return null;\n}\n"],"names":["DocumentFragment","props"],"mappings":";;AAiBO,SAASA,iBAAiBC,KAA4B;IACzD,IAAIA,MAAM,QAAQ,EACd,OAAO,WAAP,GAAO,0CAAGA,MAAM,QAAQ;IAG5B,OAAO;AACX"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { type Component, type Document } from "@webiny/website-builder-sdk";
|
|
3
|
-
|
|
3
|
+
import type { DocumentLayout } from "./renderWithLayout.js";
|
|
4
|
+
export interface DocumentRendererProps {
|
|
4
5
|
document: Document | null;
|
|
5
6
|
components: Component[];
|
|
7
|
+
/**
|
|
8
|
+
* Place the page `content` and global components (via <GlobalComponent>) around it.
|
|
9
|
+
* A page with a layout picked in its settings is rendered in that layout instead.
|
|
10
|
+
*/
|
|
11
|
+
layout?: DocumentLayout;
|
|
6
12
|
children?: React.ReactNode | React.ReactNode[];
|
|
7
13
|
}
|
|
8
|
-
export declare const DocumentRenderer: ({ document, components, children }: DocumentRendererProps) => React.JSX.Element;
|
|
9
|
-
export {};
|
|
14
|
+
export declare const DocumentRenderer: ({ document, components, layout, children }: DocumentRendererProps) => React.JSX.Element;
|
|
@@ -1,56 +1,59 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { ElementRenderer } from "./ElementRenderer.js";
|
|
1
|
+
import react from "react";
|
|
2
|
+
import { withGlobalElementDefaults } from "@webiny/website-builder-sdk";
|
|
4
3
|
import { DocumentStoreProvider } from "./DocumentStoreProvider.js";
|
|
5
4
|
import { ConnectToEditor } from "./ConnectToEditor.js";
|
|
6
5
|
import { editorComponents } from "../editorComponents/index.js";
|
|
7
6
|
import { FragmentsProvider } from "./FragmentsProvider.js";
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
7
|
+
import { PageWithLayout } from "./PageLayout.js";
|
|
8
|
+
import { useContentClient } from "./useContentClient.js";
|
|
9
|
+
const withGlobalComponentDefaults = (document, client)=>{
|
|
10
|
+
const withDefaults = withGlobalElementDefaults(document, client.getComponentManifests());
|
|
11
|
+
if (withDefaults === document) return document;
|
|
12
|
+
return {
|
|
13
|
+
...document,
|
|
14
|
+
elements: withDefaults.elements,
|
|
15
|
+
bindings: withDefaults.bindings
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const DocumentRenderer = ({ document, components, layout, children })=>{
|
|
19
|
+
const client = useContentClient();
|
|
20
|
+
const allComponents = [
|
|
21
|
+
...editorComponents,
|
|
22
|
+
...components
|
|
23
|
+
];
|
|
24
|
+
allComponents.forEach((blueprint)=>client.registerComponent(blueprint));
|
|
25
|
+
const fragments = [];
|
|
26
|
+
react.Children.toArray(children).filter((child)=>/*#__PURE__*/ react.isValidElement(child)).forEach((child)=>{
|
|
27
|
+
const props = child.props;
|
|
28
|
+
if (props.name && props.children) fragments.push({
|
|
29
|
+
type: "fixed",
|
|
30
|
+
name: props.name,
|
|
31
|
+
element: /*#__PURE__*/ react.createElement(react.Fragment, null, props.children)
|
|
32
|
+
});
|
|
33
|
+
if (props.component) fragments.push({
|
|
34
|
+
type: "component",
|
|
35
|
+
component: props.component,
|
|
36
|
+
inputs: props.inputs ?? {}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
if (!document && !client.isEditing()) return /*#__PURE__*/ react.createElement("div", {
|
|
40
|
+
"data-role": "document-renderer"
|
|
39
41
|
}, children);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
return /*#__PURE__*/ react.createElement("div", {
|
|
43
|
+
"data-role": "document-renderer"
|
|
44
|
+
}, /*#__PURE__*/ react.createElement(FragmentsProvider, {
|
|
45
|
+
fragments: fragments ?? {}
|
|
46
|
+
}, client.isEditing() ? /*#__PURE__*/ react.createElement(ConnectToEditor, {
|
|
47
|
+
document: document,
|
|
48
|
+
components: components,
|
|
49
|
+
layout: layout
|
|
50
|
+
}) : /*#__PURE__*/ react.createElement(DocumentStoreProvider, {
|
|
51
|
+
id: document.properties.id,
|
|
52
|
+
document: withGlobalComponentDefaults(document, client)
|
|
53
|
+
}, /*#__PURE__*/ react.createElement(PageWithLayout, {
|
|
54
|
+
layout: layout
|
|
55
|
+
}))));
|
|
54
56
|
};
|
|
57
|
+
export { DocumentRenderer };
|
|
55
58
|
|
|
56
59
|
//# sourceMappingURL=DocumentRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"components/DocumentRenderer.js","sources":["../../src/components/DocumentRenderer.tsx"],"sourcesContent":["import React from \"react\";\nimport {\n type Component,\n type ContentClient,\n type Document,\n withGlobalElementDefaults\n} from \"@webiny/website-builder-sdk\";\nimport { DocumentStoreProvider } from \"./DocumentStoreProvider.js\";\nimport { ConnectToEditor } from \"./ConnectToEditor.js\";\nimport { editorComponents } from \"../editorComponents/index.js\";\nimport type { DocumentFragments } from \"./FragmentsProvider.js\";\nimport { FragmentsProvider } from \"./FragmentsProvider.js\";\nimport type { DocumentFragmentProps } from \"~/components/DocumentFragment.js\";\nimport type { DocumentLayout } from \"./renderWithLayout.js\";\nimport { PageWithLayout } from \"./PageLayout.js\";\nimport { useContentClient } from \"./useContentClient.js\";\n\n/**\n * The page is delivered with its stored global components. A global that was never saved is rendered\n * from its manifest defaults, so a global defined in code shows up right away.\n */\nconst withGlobalComponentDefaults = (document: Document, client: ContentClient): Document => {\n const withDefaults = withGlobalElementDefaults(document, client.getComponentManifests());\n if (withDefaults === document) {\n return document;\n }\n\n return { ...document, elements: withDefaults.elements, bindings: withDefaults.bindings };\n};\n\nexport interface DocumentRendererProps {\n // In the editor's preview, `null` renders the document open in the editor (e.g., a layout).\n document: Document | null;\n components: Component[];\n /**\n * Place the page `content` and global components (via <GlobalComponent>) around it.\n * A page with a layout picked in its settings is rendered in that layout instead.\n */\n layout?: DocumentLayout;\n children?: React.ReactNode | React.ReactNode[];\n}\n\nexport const DocumentRenderer = ({\n document,\n components,\n layout,\n children\n}: DocumentRendererProps) => {\n const client = useContentClient();\n const allComponents = [...editorComponents, ...components];\n allComponents.forEach(blueprint => client.registerComponent(blueprint));\n const fragments: DocumentFragments = [];\n\n React.Children.toArray(children)\n .filter(child => React.isValidElement(child))\n .forEach(child => {\n const props = child.props as DocumentFragmentProps;\n // Case 1:\n if (props.name && props.children) {\n fragments.push({\n type: \"fixed\",\n name: props.name,\n element: <>{props.children}</>\n });\n }\n\n // Case 2:\n if (props.component) {\n fragments.push({\n type: \"component\",\n component: props.component,\n inputs: props.inputs ?? {}\n });\n }\n });\n\n if (!document && !client.isEditing()) {\n return <div data-role={\"document-renderer\"}>{children}</div>;\n }\n\n return (\n <div data-role={\"document-renderer\"}>\n <FragmentsProvider fragments={fragments ?? {}}>\n {client.isEditing() ? (\n <ConnectToEditor document={document} components={components} layout={layout} />\n ) : (\n <DocumentStoreProvider\n id={document!.properties.id}\n document={withGlobalComponentDefaults(document!, client)}\n >\n <PageWithLayout layout={layout} />\n </DocumentStoreProvider>\n )}\n </FragmentsProvider>\n </div>\n );\n};\n"],"names":["withGlobalComponentDefaults","document","client","withDefaults","withGlobalElementDefaults","DocumentRenderer","components","layout","children","useContentClient","allComponents","editorComponents","blueprint","fragments","React","child","props","FragmentsProvider","ConnectToEditor","DocumentStoreProvider","PageWithLayout"],"mappings":";;;;;;;;AAqBA,MAAMA,8BAA8B,CAACC,UAAoBC;IACrD,MAAMC,eAAeC,0BAA0BH,UAAUC,OAAO,qBAAqB;IACrF,IAAIC,iBAAiBF,UACjB,OAAOA;IAGX,OAAO;QAAE,GAAGA,QAAQ;QAAE,UAAUE,aAAa,QAAQ;QAAE,UAAUA,aAAa,QAAQ;IAAC;AAC3F;AAcO,MAAME,mBAAmB,CAAC,EAC7BJ,QAAQ,EACRK,UAAU,EACVC,MAAM,EACNC,QAAQ,EACY;IACpB,MAAMN,SAASO;IACf,MAAMC,gBAAgB;WAAIC;WAAqBL;KAAW;IAC1DI,cAAc,OAAO,CAACE,CAAAA,YAAaV,OAAO,iBAAiB,CAACU;IAC5D,MAAMC,YAA+B,EAAE;IAEvCC,MAAAA,QAAAA,CAAAA,OAAsB,CAACN,UAClB,MAAM,CAACO,CAAAA,QAAAA,WAAAA,GAASD,MAAAA,cAAoB,CAACC,QACrC,OAAO,CAACA,CAAAA;QACL,MAAMC,QAAQD,MAAM,KAAK;QAEzB,IAAIC,MAAM,IAAI,IAAIA,MAAM,QAAQ,EAC5BH,UAAU,IAAI,CAAC;YACX,MAAM;YACN,MAAMG,MAAM,IAAI;YAChB,SAAS,WAAT,GAAS,0CAAGA,MAAM,QAAQ;QAC9B;QAIJ,IAAIA,MAAM,SAAS,EACfH,UAAU,IAAI,CAAC;YACX,MAAM;YACN,WAAWG,MAAM,SAAS;YAC1B,QAAQA,MAAM,MAAM,IAAI,CAAC;QAC7B;IAER;IAEJ,IAAI,CAACf,YAAY,CAACC,OAAO,SAAS,IAC9B,OAAO,WAAP,GAAO,oBAAC;QAAI,aAAW;OAAsBM;IAGjD,OAAO,WAAP,GACI,oBAAC;QAAI,aAAW;qBACZ,oBAACS,mBAAiBA;QAAC,WAAWJ,aAAa,CAAC;OACvCX,OAAO,SAAS,KAAK,WAAL,GACb,oBAACgB,iBAAeA;QAAC,UAAUjB;QAAU,YAAYK;QAAY,QAAQC;uBAErE,oBAACY,uBAAqBA;QAClB,IAAIlB,SAAU,UAAU,CAAC,EAAE;QAC3B,UAAUD,4BAA4BC,UAAWC;qBAEjD,oBAACkB,gBAAcA;QAAC,QAAQb;;AAMhD"}
|
|
@@ -6,4 +6,11 @@ export declare const DocumentStoreProvider: ({ id, document, children }: {
|
|
|
6
6
|
document?: Document;
|
|
7
7
|
children: React.ReactNode;
|
|
8
8
|
}) => React.JSX.Element;
|
|
9
|
+
/**
|
|
10
|
+
* Render children from an existing store, e.g. to switch from a layout back to the page it's rendered around.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DocumentStoreScope: ({ store, children }: {
|
|
13
|
+
store: DocumentStore;
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}) => React.JSX.Element;
|
|
9
16
|
export declare const useDocumentStore: () => DocumentStore;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
value: store
|
|
17
|
-
}, children);
|
|
2
|
+
import react, { useContext, useMemo } from "react";
|
|
3
|
+
import { useContentClient } from "./useContentClient.js";
|
|
4
|
+
const DocumentStoreContext = /*#__PURE__*/ react.createContext(void 0);
|
|
5
|
+
const DocumentStoreProvider = ({ id, document, children })=>{
|
|
6
|
+
const client = useContentClient();
|
|
7
|
+
const stores = client.getDocumentStoreManager();
|
|
8
|
+
const store = useMemo(()=>stores.getStore(id), [
|
|
9
|
+
stores,
|
|
10
|
+
id
|
|
11
|
+
]);
|
|
12
|
+
if (document) store.setDocument(document);
|
|
13
|
+
return /*#__PURE__*/ react.createElement(DocumentStoreContext.Provider, {
|
|
14
|
+
value: store
|
|
15
|
+
}, children);
|
|
18
16
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
const DocumentStoreScope = ({ store, children })=>/*#__PURE__*/ react.createElement(DocumentStoreContext.Provider, {
|
|
18
|
+
value: store
|
|
19
|
+
}, children);
|
|
20
|
+
const useDocumentStore = ()=>{
|
|
21
|
+
const store = useContext(DocumentStoreContext);
|
|
22
|
+
if (!store) throw new Error("useDocumentStore must be used within a DocumentStoreProvider");
|
|
23
|
+
return store;
|
|
25
24
|
};
|
|
25
|
+
export { DocumentStoreProvider, DocumentStoreScope, useDocumentStore };
|
|
26
26
|
|
|
27
27
|
//# sourceMappingURL=DocumentStoreProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"components/DocumentStoreProvider.js","sources":["../../src/components/DocumentStoreProvider.tsx"],"sourcesContent":["\"use client\";\nimport React, { useContext, useMemo } from \"react\";\nimport type { DocumentStore } from \"@webiny/website-builder-sdk\";\nimport { type Document } from \"@webiny/website-builder-sdk\";\nimport { useContentClient } from \"./useContentClient.js\";\n\nconst DocumentStoreContext = React.createContext<DocumentStore | undefined>(undefined);\n\nexport const DocumentStoreProvider = ({\n id,\n document,\n children\n}: {\n id: string;\n document?: Document;\n children: React.ReactNode;\n}) => {\n const client = useContentClient();\n const stores = client.getDocumentStoreManager();\n const store = useMemo(() => stores.getStore(id), [stores, id]);\n\n if (document) {\n store.setDocument(document);\n }\n\n return <DocumentStoreContext.Provider value={store}>{children}</DocumentStoreContext.Provider>;\n};\n\n/**\n * Render children from an existing store, e.g. to switch from a layout back to the page it's rendered around.\n */\nexport const DocumentStoreScope = ({\n store,\n children\n}: {\n store: DocumentStore;\n children: React.ReactNode;\n}) => {\n return <DocumentStoreContext.Provider value={store}>{children}</DocumentStoreContext.Provider>;\n};\n\nexport const useDocumentStore = (): DocumentStore => {\n const store = useContext(DocumentStoreContext);\n if (!store) {\n throw new Error(\"useDocumentStore must be used within a DocumentStoreProvider\");\n }\n return store;\n};\n"],"names":["DocumentStoreContext","React","undefined","DocumentStoreProvider","id","document","children","client","useContentClient","stores","store","useMemo","DocumentStoreScope","useDocumentStore","useContext","Error"],"mappings":";;;AAMA,MAAMA,uBAAuB,WAAHA,GAAGC,MAAAA,aAAmB,CAA4BC;AAErE,MAAMC,wBAAwB,CAAC,EAClCC,EAAE,EACFC,QAAQ,EACRC,QAAQ,EAKX;IACG,MAAMC,SAASC;IACf,MAAMC,SAASF,OAAO,uBAAuB;IAC7C,MAAMG,QAAQC,QAAQ,IAAMF,OAAO,QAAQ,CAACL,KAAK;QAACK;QAAQL;KAAG;IAE7D,IAAIC,UACAK,MAAM,WAAW,CAACL;IAGtB,OAAO,WAAP,GAAO,oBAACL,qBAAqB,QAAQ;QAAC,OAAOU;OAAQJ;AACzD;AAKO,MAAMM,qBAAqB,CAAC,EAC/BF,KAAK,EACLJ,QAAQ,EAIX,GACU,WAAP,GAAO,oBAACN,qBAAqB,QAAQ;QAAC,OAAOU;OAAQJ;AAGlD,MAAMO,mBAAmB;IAC5B,MAAMH,QAAQI,WAAWd;IACzB,IAAI,CAACU,OACD,MAAM,IAAIK,MAAM;IAEpB,OAAOL;AACX"}
|
|
@@ -2,8 +2,13 @@ import React from "react";
|
|
|
2
2
|
import { type DocumentElement } from "@webiny/website-builder-sdk";
|
|
3
3
|
interface PreviewElementRendererProps {
|
|
4
4
|
element: DocumentElement;
|
|
5
|
+
/**
|
|
6
|
+
* For a placement of a global component: the global's instance. The placement is what's selected,
|
|
7
|
+
* moved and deleted; the instance is what renders, with its values.
|
|
8
|
+
*/
|
|
9
|
+
instance?: DocumentElement;
|
|
5
10
|
}
|
|
6
|
-
export declare const EditingElementRenderer: ((props: PreviewElementRendererProps) => React.JSX.Element | null) & {
|
|
7
|
-
|
|
11
|
+
export declare const EditingElementRenderer: ((props: PreviewElementRendererProps) => React.JSX.Element | null) & React.NamedExoticComponent<PreviewElementRendererProps> & {
|
|
12
|
+
readonly type: (props: PreviewElementRendererProps) => React.JSX.Element | null;
|
|
8
13
|
};
|
|
9
14
|
export {};
|