@webiny/website-builder-react 0.0.0-unstable.0156a4c312
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/LICENSE +21 -0
- package/README.md +11 -0
- package/components/ConnectToEditor.d.ts +10 -0
- package/components/ConnectToEditor.js +25 -0
- package/components/ConnectToEditor.js.map +1 -0
- 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 +13 -0
- package/components/DocumentFragment.js +9 -0
- package/components/DocumentFragment.js.map +1 -0
- package/components/DocumentRenderer.d.ts +14 -0
- package/components/DocumentRenderer.js +59 -0
- package/components/DocumentRenderer.js.map +1 -0
- package/components/DocumentStoreProvider.d.ts +16 -0
- package/components/DocumentStoreProvider.js +27 -0
- package/components/DocumentStoreProvider.js.map +1 -0
- package/components/EditingElementRenderer/EditingElementRenderer.d.ts +14 -0
- package/components/EditingElementRenderer/EditingElementRenderer.js +55 -0
- package/components/EditingElementRenderer/EditingElementRenderer.js.map +1 -0
- package/components/EditingElementRenderer/EditingElementRenderer.presenter.d.ts +15 -0
- package/components/EditingElementRenderer/EditingElementRenderer.presenter.js +38 -0
- package/components/EditingElementRenderer/EditingElementRenderer.presenter.js.map +1 -0
- package/components/EditingElementRenderer/index.d.ts +1 -0
- package/components/EditingElementRenderer/index.js +1 -0
- package/components/ElementIndexProvider.d.ts +8 -0
- package/components/ElementIndexProvider.js +13 -0
- package/components/ElementIndexProvider.js.map +1 -0
- package/components/ElementRenderer.d.ts +8 -0
- package/components/ElementRenderer.js +35 -0
- package/components/ElementRenderer.js.map +1 -0
- package/components/ElementSlot.d.ts +7 -0
- package/components/ElementSlot.js +16 -0
- package/components/ElementSlot.js.map +1 -0
- package/components/ElementSlotDepthProvider.d.ts +8 -0
- package/components/ElementSlotDepthProvider.js +13 -0
- package/components/ElementSlotDepthProvider.js.map +1 -0
- package/components/FragmentsProvider.d.ts +18 -0
- package/components/FragmentsProvider.js +38 -0
- package/components/FragmentsProvider.js.map +1 -0
- 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 +10 -0
- package/components/LiveElementRenderer.js +68 -0
- package/components/LiveElementRenderer.js.map +1 -0
- package/components/LiveElementSlot.d.ts +3 -0
- package/components/LiveElementSlot.js +19 -0
- package/components/LiveElementSlot.js.map +1 -0
- package/components/PageLayout.d.ts +40 -0
- package/components/PageLayout.js +71 -0
- package/components/PageLayout.js.map +1 -0
- package/components/PreviewElementSlot.d.ts +8 -0
- package/components/PreviewElementSlot.js +34 -0
- package/components/PreviewElementSlot.js.map +1 -0
- 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 +11 -0
- package/components/index.js +10 -0
- 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 +815 -0
- package/components/useBindingsForElement.js +21 -0
- package/components/useBindingsForElement.js.map +1 -0
- 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 -0
- package/components/useDocumentState.js +9 -0
- package/components/useDocumentState.js.map +1 -0
- 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 +8 -0
- package/components/useSelectFromState.js +33 -0
- package/components/useSelectFromState.js.map +1 -0
- package/components/useViewportInfo.d.ts +1 -0
- package/components/useViewportInfo.js +10 -0
- package/components/useViewportInfo.js.map +1 -0
- 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 -0
- package/createComponent.js +1 -0
- 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 +3 -0
- package/editorComponents/Box.js +5 -0
- package/editorComponents/Box.js.map +1 -0
- package/editorComponents/Box.manifest.d.ts +1 -0
- package/editorComponents/Box.manifest.js +22 -0
- package/editorComponents/Box.manifest.js.map +1 -0
- package/editorComponents/Fragment.d.ts +7 -0
- package/editorComponents/Fragment.js +30 -0
- package/editorComponents/Fragment.js.map +1 -0
- package/editorComponents/Fragment.manifest.d.ts +1 -0
- package/editorComponents/Fragment.manifest.js +22 -0
- package/editorComponents/Fragment.manifest.js.map +1 -0
- package/editorComponents/Grid.d.ts +19 -0
- package/editorComponents/Grid.js +37 -0
- package/editorComponents/Grid.js.map +1 -0
- package/editorComponents/Grid.manifest.d.ts +4 -0
- package/editorComponents/Grid.manifest.js +171 -0
- package/editorComponents/Grid.manifest.js.map +1 -0
- package/editorComponents/GridColumn.d.ts +5 -0
- package/editorComponents/GridColumn.js +5 -0
- package/editorComponents/GridColumn.js.map +1 -0
- package/editorComponents/GridColumn.manifest.d.ts +1 -0
- package/editorComponents/GridColumn.manifest.js +28 -0
- package/editorComponents/GridColumn.manifest.js.map +1 -0
- package/editorComponents/Image.d.ts +15 -0
- package/editorComponents/Image.js +106 -0
- package/editorComponents/Image.js.map +1 -0
- package/editorComponents/Image.manifest.d.ts +1 -0
- package/editorComponents/Image.manifest.js +42 -0
- package/editorComponents/Image.manifest.js.map +1 -0
- 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 +13 -0
- package/editorComponents/Lexical.js +18 -0
- package/editorComponents/Lexical.js.map +1 -0
- package/editorComponents/Lexical.manifest.d.ts +1 -0
- package/editorComponents/Lexical.manifest.js +25 -0
- package/editorComponents/Lexical.manifest.js.map +1 -0
- package/editorComponents/Root.d.ts +3 -0
- package/editorComponents/Root.js +5 -0
- package/editorComponents/Root.js.map +1 -0
- package/editorComponents/Root.manifest.d.ts +1 -0
- package/editorComponents/Root.manifest.js +13 -0
- package/editorComponents/Root.manifest.js.map +1 -0
- package/editorComponents/index.d.ts +1 -0
- package/editorComponents/index.js +22 -0
- package/editorComponents/index.js.map +1 -0
- 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 +5 -0
- package/index.js +3 -0
- package/package.json +40 -0
- package/types.d.ts +47 -0
- package/types.js +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webiny/website-builder-react
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type Component, type Document } from "@webiny/website-builder-sdk";
|
|
3
|
+
import type { DocumentLayout } from "../components/renderWithLayout.js";
|
|
4
|
+
interface ConnectToEditorProps {
|
|
5
|
+
document: Document | null;
|
|
6
|
+
components: Component[];
|
|
7
|
+
layout?: DocumentLayout;
|
|
8
|
+
}
|
|
9
|
+
export declare const ConnectToEditor: (props: ConnectToEditorProps) => React.JSX.Element | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import react, { useEffect, useState } from "react";
|
|
3
|
+
import { DocumentStoreProvider } from "./DocumentStoreProvider.js";
|
|
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
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
export { ConnectToEditor };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=ConnectToEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export type DocumentFragmentProps = {
|
|
3
|
+
name: string;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
component?: never;
|
|
6
|
+
inputs?: never;
|
|
7
|
+
} | {
|
|
8
|
+
component: string;
|
|
9
|
+
inputs?: Record<string, any>;
|
|
10
|
+
name?: never;
|
|
11
|
+
children?: never;
|
|
12
|
+
};
|
|
13
|
+
export declare function DocumentFragment(props: DocumentFragmentProps): React.JSX.Element | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
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;
|
|
6
|
+
}
|
|
7
|
+
export { DocumentFragment };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=DocumentFragment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type Component, type Document } from "@webiny/website-builder-sdk";
|
|
3
|
+
import type { DocumentLayout } from "./renderWithLayout.js";
|
|
4
|
+
export interface DocumentRendererProps {
|
|
5
|
+
document: Document | null;
|
|
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;
|
|
12
|
+
children?: React.ReactNode | React.ReactNode[];
|
|
13
|
+
}
|
|
14
|
+
export declare const DocumentRenderer: ({ document, components, layout, children }: DocumentRendererProps) => React.JSX.Element;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import react from "react";
|
|
2
|
+
import { withGlobalElementDefaults } from "@webiny/website-builder-sdk";
|
|
3
|
+
import { DocumentStoreProvider } from "./DocumentStoreProvider.js";
|
|
4
|
+
import { ConnectToEditor } from "./ConnectToEditor.js";
|
|
5
|
+
import { editorComponents } from "../editorComponents/index.js";
|
|
6
|
+
import { FragmentsProvider } from "./FragmentsProvider.js";
|
|
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"
|
|
41
|
+
}, children);
|
|
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
|
+
}))));
|
|
56
|
+
};
|
|
57
|
+
export { DocumentRenderer };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=DocumentRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { DocumentStore } from "@webiny/website-builder-sdk";
|
|
3
|
+
import { type Document } from "@webiny/website-builder-sdk";
|
|
4
|
+
export declare const DocumentStoreProvider: ({ id, document, children }: {
|
|
5
|
+
id: string;
|
|
6
|
+
document?: Document;
|
|
7
|
+
children: React.ReactNode;
|
|
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;
|
|
16
|
+
export declare const useDocumentStore: () => DocumentStore;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
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);
|
|
16
|
+
};
|
|
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;
|
|
24
|
+
};
|
|
25
|
+
export { DocumentStoreProvider, DocumentStoreScope, useDocumentStore };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=DocumentStoreProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type DocumentElement } from "@webiny/website-builder-sdk";
|
|
3
|
+
interface PreviewElementRendererProps {
|
|
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;
|
|
10
|
+
}
|
|
11
|
+
export declare const EditingElementRenderer: ((props: PreviewElementRendererProps) => React.JSX.Element | null) & React.NamedExoticComponent<PreviewElementRendererProps> & {
|
|
12
|
+
readonly type: (props: PreviewElementRendererProps) => React.JSX.Element | null;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import react, { useEffect, useMemo } from "react";
|
|
3
|
+
import { observer } from "mobx-react-lite";
|
|
4
|
+
import { EditingElementRendererPresenter } from "./EditingElementRenderer.presenter.js";
|
|
5
|
+
import { LiveElementRenderer } from "../LiveElementRenderer.js";
|
|
6
|
+
import { useElementSlotDepth } from "../ElementSlotDepthProvider.js";
|
|
7
|
+
import { useElementIndex } from "../ElementIndexProvider.js";
|
|
8
|
+
import { useDocumentStore } from "../DocumentStoreProvider.js";
|
|
9
|
+
import { useContentClient } from "../useContentClient.js";
|
|
10
|
+
const styles = {
|
|
11
|
+
display: "contents"
|
|
12
|
+
};
|
|
13
|
+
const EditingElementRenderer = observer((props)=>{
|
|
14
|
+
const documentStore = useDocumentStore();
|
|
15
|
+
const client = useContentClient();
|
|
16
|
+
const depth = useElementSlotDepth();
|
|
17
|
+
const index = useElementIndex();
|
|
18
|
+
const rendered = props.instance ?? props.element;
|
|
19
|
+
const presenter = useMemo(()=>{
|
|
20
|
+
const editingSdk = client.getEditingSdk();
|
|
21
|
+
return new EditingElementRendererPresenter(documentStore, editingSdk);
|
|
22
|
+
}, [
|
|
23
|
+
rendered?.id,
|
|
24
|
+
client,
|
|
25
|
+
documentStore
|
|
26
|
+
]);
|
|
27
|
+
useEffect(()=>{
|
|
28
|
+
if (!rendered) return;
|
|
29
|
+
presenter.init(rendered);
|
|
30
|
+
}, [
|
|
31
|
+
presenter,
|
|
32
|
+
rendered?.id
|
|
33
|
+
]);
|
|
34
|
+
useEffect(()=>()=>{
|
|
35
|
+
presenter.dispose();
|
|
36
|
+
}, [
|
|
37
|
+
presenter
|
|
38
|
+
]);
|
|
39
|
+
const renderedElement = presenter.vm.element;
|
|
40
|
+
const element = props.instance ? props.element : renderedElement;
|
|
41
|
+
if (!element || !element.id || !renderedElement?.id) return null;
|
|
42
|
+
return /*#__PURE__*/ react.createElement("div", {
|
|
43
|
+
style: styles,
|
|
44
|
+
"data-element-id": element.id,
|
|
45
|
+
"data-depth": depth,
|
|
46
|
+
"data-parent-index": index,
|
|
47
|
+
"data-parent-id": element.parent?.id,
|
|
48
|
+
"data-parent-slot": element.parent?.slot
|
|
49
|
+
}, /*#__PURE__*/ react.createElement(LiveElementRenderer, {
|
|
50
|
+
element: renderedElement
|
|
51
|
+
}));
|
|
52
|
+
});
|
|
53
|
+
export { EditingElementRenderer };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=EditingElementRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/EditingElementRenderer/EditingElementRenderer.js","sources":["../../../src/components/EditingElementRenderer/EditingElementRenderer.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useMemo } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { type DocumentElement } from \"@webiny/website-builder-sdk\";\nimport { EditingElementRendererPresenter } from \"./EditingElementRenderer.presenter.js\";\nimport { LiveElementRenderer } from \"../LiveElementRenderer.js\";\nimport { useElementSlotDepth } from \"../ElementSlotDepthProvider.js\";\nimport { useElementIndex } from \"../ElementIndexProvider.js\";\nimport { useDocumentStore } from \"../DocumentStoreProvider.js\";\nimport { useContentClient } from \"../useContentClient.js\";\n\ninterface PreviewElementRendererProps {\n element: DocumentElement;\n /**\n * For a placement of a global component: the global's instance. The placement is what's selected,\n * moved and deleted; the instance is what renders, with its values.\n */\n instance?: DocumentElement;\n}\n\nconst styles = { display: \"contents\" };\n\nexport const EditingElementRenderer = observer((props: PreviewElementRendererProps) => {\n const documentStore = useDocumentStore();\n const client = useContentClient();\n const depth = useElementSlotDepth();\n const index = useElementIndex();\n\n const rendered = props.instance ?? props.element;\n\n const presenter = useMemo(() => {\n const editingSdk = client.getEditingSdk();\n return new EditingElementRendererPresenter(documentStore, editingSdk);\n }, [rendered?.id, client, documentStore]);\n\n useEffect(() => {\n if (!rendered) {\n return;\n }\n presenter.init(rendered);\n }, [presenter, rendered?.id]);\n\n useEffect(() => {\n return () => {\n presenter.dispose();\n };\n }, [presenter]);\n\n const renderedElement = presenter.vm.element;\n const element = props.instance ? props.element : renderedElement;\n\n if (!element || !element.id || !renderedElement?.id) {\n return null;\n }\n\n return (\n <div\n style={styles}\n data-element-id={element.id}\n data-depth={depth}\n data-parent-index={index}\n data-parent-id={element.parent?.id}\n data-parent-slot={element.parent?.slot}\n >\n <LiveElementRenderer element={renderedElement} />\n </div>\n );\n});\n"],"names":["styles","EditingElementRenderer","observer","props","documentStore","useDocumentStore","client","useContentClient","depth","useElementSlotDepth","index","useElementIndex","rendered","presenter","useMemo","editingSdk","EditingElementRendererPresenter","useEffect","renderedElement","element","LiveElementRenderer"],"mappings":";;;;;;;;;AAoBA,MAAMA,SAAS;IAAE,SAAS;AAAW;AAE9B,MAAMC,yBAAyBC,SAAS,CAACC;IAC5C,MAAMC,gBAAgBC;IACtB,MAAMC,SAASC;IACf,MAAMC,QAAQC;IACd,MAAMC,QAAQC;IAEd,MAAMC,WAAWT,MAAM,QAAQ,IAAIA,MAAM,OAAO;IAEhD,MAAMU,YAAYC,QAAQ;QACtB,MAAMC,aAAaT,OAAO,aAAa;QACvC,OAAO,IAAIU,gCAAgCZ,eAAeW;IAC9D,GAAG;QAACH,UAAU;QAAIN;QAAQF;KAAc;IAExCa,UAAU;QACN,IAAI,CAACL,UACD;QAEJC,UAAU,IAAI,CAACD;IACnB,GAAG;QAACC;QAAWD,UAAU;KAAG;IAE5BK,UAAU,IACC;YACHJ,UAAU,OAAO;QACrB,GACD;QAACA;KAAU;IAEd,MAAMK,kBAAkBL,UAAU,EAAE,CAAC,OAAO;IAC5C,MAAMM,UAAUhB,MAAM,QAAQ,GAAGA,MAAM,OAAO,GAAGe;IAEjD,IAAI,CAACC,WAAW,CAACA,QAAQ,EAAE,IAAI,CAACD,iBAAiB,IAC7C,OAAO;IAGX,OAAO,WAAP,GACI,oBAAC;QACG,OAAOlB;QACP,mBAAiBmB,QAAQ,EAAE;QAC3B,cAAYX;QACZ,qBAAmBE;QACnB,kBAAgBS,QAAQ,MAAM,EAAE;QAChC,oBAAkBA,QAAQ,MAAM,EAAE;qBAElC,oBAACC,qBAAmBA;QAAC,SAASF;;AAG1C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DocumentStore } from "@webiny/website-builder-sdk";
|
|
2
|
+
import { type EditingSdk, type DocumentElement } from "@webiny/website-builder-sdk";
|
|
3
|
+
export declare class EditingElementRendererPresenter {
|
|
4
|
+
private element;
|
|
5
|
+
private listeners;
|
|
6
|
+
private documentStore;
|
|
7
|
+
private readonly editingSdk;
|
|
8
|
+
constructor(documentStore: DocumentStore, editingSdk: EditingSdk | undefined);
|
|
9
|
+
get vm(): {
|
|
10
|
+
element: DocumentElement;
|
|
11
|
+
};
|
|
12
|
+
init(element: DocumentElement): void;
|
|
13
|
+
dispose(): void;
|
|
14
|
+
private setupPreview;
|
|
15
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { makeAutoObservable, observable, toJS } from "mobx";
|
|
3
|
+
import { jsonPatch } from "@webiny/website-builder-sdk";
|
|
4
|
+
class EditingElementRendererPresenter {
|
|
5
|
+
constructor(documentStore, editingSdk){
|
|
6
|
+
this.listeners = [];
|
|
7
|
+
this.documentStore = documentStore;
|
|
8
|
+
this.element = observable({});
|
|
9
|
+
this.editingSdk = editingSdk;
|
|
10
|
+
makeAutoObservable(this);
|
|
11
|
+
}
|
|
12
|
+
get vm() {
|
|
13
|
+
return {
|
|
14
|
+
element: toJS(this.element)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
init(element) {
|
|
18
|
+
this.element = element;
|
|
19
|
+
this.setupPreview();
|
|
20
|
+
}
|
|
21
|
+
dispose() {
|
|
22
|
+
this.listeners.forEach((fn)=>fn());
|
|
23
|
+
}
|
|
24
|
+
setupPreview() {
|
|
25
|
+
const element = this.element;
|
|
26
|
+
if (!element) return;
|
|
27
|
+
const { id } = element;
|
|
28
|
+
if (this.editingSdk) this.listeners.push(this.editingSdk.messenger.on(`element.patch.${id}`, (patch)=>{
|
|
29
|
+
this.documentStore.updateDocument((document)=>{
|
|
30
|
+
document.bindings[id] ??= {};
|
|
31
|
+
jsonPatch.applyPatch(document.bindings[id], patch, false, true);
|
|
32
|
+
});
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export { EditingElementRendererPresenter };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=EditingElementRenderer.presenter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/EditingElementRenderer/EditingElementRenderer.presenter.js","sources":["../../../src/components/EditingElementRenderer/EditingElementRenderer.presenter.ts"],"sourcesContent":["\"use client\";\nimport { makeAutoObservable, observable, toJS } from \"mobx\";\nimport type { DocumentStore } from \"@webiny/website-builder-sdk\";\nimport { jsonPatch, type EditingSdk, type DocumentElement } from \"@webiny/website-builder-sdk\";\n\nexport class EditingElementRendererPresenter {\n private element: DocumentElement;\n private listeners: Array<() => void> = [];\n private documentStore: DocumentStore;\n private readonly editingSdk: EditingSdk | undefined;\n\n constructor(documentStore: DocumentStore, editingSdk: EditingSdk | undefined) {\n this.documentStore = documentStore;\n this.element = observable({}) as DocumentElement;\n this.editingSdk = editingSdk;\n makeAutoObservable(this);\n }\n\n get vm() {\n return {\n element: toJS(this.element)\n };\n }\n\n init(element: DocumentElement) {\n this.element = element;\n this.setupPreview();\n }\n\n dispose() {\n this.listeners.forEach(fn => fn());\n }\n\n private setupPreview() {\n const element = this.element;\n\n if (!element) {\n return;\n }\n\n const { id } = element;\n\n if (this.editingSdk) {\n this.listeners.push(\n this.editingSdk.messenger.on(`element.patch.${id}`, patch => {\n this.documentStore.updateDocument(document => {\n // An element can be stored without bindings (e.g., a layout's main content area).\n document.bindings[id] ??= {};\n jsonPatch.applyPatch(document.bindings[id], patch, false, true);\n });\n })\n );\n }\n }\n}\n"],"names":["EditingElementRendererPresenter","documentStore","editingSdk","observable","makeAutoObservable","toJS","element","fn","id","patch","document","jsonPatch"],"mappings":";;;AAKO,MAAMA;IAMT,YAAYC,aAA4B,EAAEC,UAAkC,CAAE;aAJtE,SAAS,GAAsB,EAAE;QAKrC,IAAI,CAAC,aAAa,GAAGD;QACrB,IAAI,CAAC,OAAO,GAAGE,WAAW,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAGD;QAClBE,mBAAmB,IAAI;IAC3B;IAEA,IAAI,KAAK;QACL,OAAO;YACH,SAASC,KAAK,IAAI,CAAC,OAAO;QAC9B;IACJ;IAEA,KAAKC,OAAwB,EAAE;QAC3B,IAAI,CAAC,OAAO,GAAGA;QACf,IAAI,CAAC,YAAY;IACrB;IAEA,UAAU;QACN,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC,CAAAA,KAAMA;IACjC;IAEQ,eAAe;QACnB,MAAMD,UAAU,IAAI,CAAC,OAAO;QAE5B,IAAI,CAACA,SACD;QAGJ,MAAM,EAAEE,EAAE,EAAE,GAAGF;QAEf,IAAI,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,SAAS,CAAC,IAAI,CACf,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,cAAc,EAAEE,IAAI,EAAEC,CAAAA;YAChD,IAAI,CAAC,aAAa,CAAC,cAAc,CAACC,CAAAA;gBAE9BA,SAAS,QAAQ,CAACF,GAAG,KAAK,CAAC;gBAC3BG,UAAU,UAAU,CAACD,SAAS,QAAQ,CAACF,GAAG,EAAEC,OAAO,OAAO;YAC9D;QACJ;IAGZ;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./EditingElementRenderer.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./EditingElementRenderer.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface ElementIndexProviderProps {
|
|
3
|
+
index: number;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare const ElementIndexProvider: ({ children, index }: ElementIndexProviderProps) => React.JSX.Element;
|
|
7
|
+
export declare const useElementIndex: () => number;
|
|
8
|
+
export {};
|