@webiny/website-builder-react 0.0.0-unstable.df7a8bb475 → 0.0.0-unstable.e1999482d0
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 +35 -22
- package/components/DocumentStoreProvider.js.map +1 -1
- package/components/DocumentStoreProvider.test.d.ts +1 -0
- package/components/DocumentStoreProvider.test.js +66 -0
- package/components/DocumentStoreProvider.test.js.map +1 -0
- package/components/EditingElementRenderer/EditingElementRenderer.d.ts +7 -2
- package/components/EditingElementRenderer/EditingElementRenderer.js +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 +60 -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.d.ts +146 -49
- 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 +5 -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.d.ts +2 -1
- package/components/useSelectFromState.js +29 -35
- package/components/useSelectFromState.js.map +1 -1
- package/components/useSelectFromState.test.d.ts +1 -0
- package/components/useSelectFromState.test.js +67 -0
- package/components/useSelectFromState.test.js.map +1 -0
- package/components/useViewportInfo.js +5 -6
- package/components/useViewportInfo.js.map +1 -1
- package/contentEntry/useContentEntryList.d.ts +22 -0
- package/contentEntry/useContentEntryList.js +51 -0
- package/contentEntry/useContentEntryList.js.map +1 -0
- package/createComponent.d.ts +1 -3
- package/createComponent.js +1 -36
- package/createComponent.test.js +108 -119
- 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.d.ts +1 -1
- package/editorComponents/Grid.js +34 -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 +4 -3
- package/index.js +2 -4
- package/package.json +18 -15
- package/types.d.ts +39 -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
|
@@ -3,17 +3,19 @@ import { BindingsProcessor } from "@webiny/website-builder-sdk";
|
|
|
3
3
|
import { useViewport } from "./useViewportInfo.js";
|
|
4
4
|
import { useDocumentStore } from "./DocumentStoreProvider.js";
|
|
5
5
|
import { useSelectFromState } from "./useSelectFromState.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
const useBindingsForElement = (elementId, breakpoint)=>{
|
|
7
|
+
const documentStore = useDocumentStore();
|
|
8
|
+
const viewport = useViewport();
|
|
9
|
+
return useSelectFromState(()=>documentStore.getDocument(), (document)=>{
|
|
10
|
+
const bindings = toJS(document.bindings[elementId]) ?? {};
|
|
11
|
+
const breakpoints = viewport.breakpoints.map((bp)=>bp.name);
|
|
12
|
+
const bindingsProcessor = new BindingsProcessor(breakpoints);
|
|
13
|
+
return bindingsProcessor.getBindings(bindings, breakpoint);
|
|
14
|
+
}, [
|
|
15
|
+
elementId,
|
|
16
|
+
breakpoint
|
|
17
|
+
]);
|
|
17
18
|
};
|
|
19
|
+
export { useBindingsForElement };
|
|
18
20
|
|
|
19
21
|
//# sourceMappingURL=useBindingsForElement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"components/useBindingsForElement.js","sources":["../../src/components/useBindingsForElement.ts"],"sourcesContent":["import { toJS } from \"mobx\";\nimport { BindingsProcessor } from \"@webiny/website-builder-sdk\";\nimport { useViewport } from \"./useViewportInfo.js\";\nimport { useDocumentStore } from \"./DocumentStoreProvider.js\";\nimport { useSelectFromState } from \"./useSelectFromState.js\";\n\nexport const useBindingsForElement = (elementId: string, breakpoint: string) => {\n const documentStore = useDocumentStore();\n const viewport = useViewport();\n\n return useSelectFromState(\n () => documentStore.getDocument()!,\n document => {\n const bindings = toJS(document.bindings[elementId]) ?? {};\n const breakpoints = viewport.breakpoints.map(bp => bp.name);\n\n // Merge element bindings.\n const bindingsProcessor = new BindingsProcessor(breakpoints);\n\n return bindingsProcessor.getBindings(bindings, breakpoint);\n },\n [elementId, breakpoint]\n );\n};\n"],"names":["useBindingsForElement","elementId","breakpoint","documentStore","useDocumentStore","viewport","useViewport","useSelectFromState","document","bindings","toJS","breakpoints","bp","bindingsProcessor","BindingsProcessor"],"mappings":";;;;;AAMO,MAAMA,wBAAwB,CAACC,WAAmBC;IACrD,MAAMC,gBAAgBC;IACtB,MAAMC,WAAWC;IAEjB,OAAOC,mBACH,IAAMJ,cAAc,WAAW,IAC/BK,CAAAA;QACI,MAAMC,WAAWC,KAAKF,SAAS,QAAQ,CAACP,UAAU,KAAK,CAAC;QACxD,MAAMU,cAAcN,SAAS,WAAW,CAAC,GAAG,CAACO,CAAAA,KAAMA,GAAG,IAAI;QAG1D,MAAMC,oBAAoB,IAAIC,kBAAkBH;QAEhD,OAAOE,kBAAkB,WAAW,CAACJ,UAAUP;IACnD,GACA;QAACD;QAAWC;KAAW;AAE/B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { contentSdk } from "@webiny/website-builder-sdk";
|
|
4
|
+
import { ContentClientContext } from "./ContentClientContext.js";
|
|
5
|
+
const useContentClient = ()=>{
|
|
6
|
+
const client = useContext(ContentClientContext);
|
|
7
|
+
return client ?? contentSdk;
|
|
8
|
+
};
|
|
9
|
+
export { useContentClient };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=useContentClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/useContentClient.js","sources":["../../src/components/useContentClient.ts"],"sourcesContent":["\"use client\";\nimport { useContext } from \"react\";\nimport type { ContentClient } from \"@webiny/website-builder-sdk\";\nimport { contentSdk } from \"@webiny/website-builder-sdk\";\nimport { ContentClientContext } from \"./ContentClientContext.js\";\n\n/**\n * Returns the client from the nearest `ContentClientProvider`, or the `contentSdk` singleton\n * when there is none.\n */\nexport const useContentClient = (): ContentClient => {\n const client = useContext(ContentClientContext);\n return client ?? contentSdk;\n};\n"],"names":["useContentClient","client","useContext","ContentClientContext","contentSdk"],"mappings":";;;;AAUO,MAAMA,mBAAmB;IAC5B,MAAMC,SAASC,WAAWC;IAC1B,OAAOF,UAAUG;AACrB"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { toJS } from "mobx";
|
|
1
2
|
import { useDocumentStore } from "./DocumentStoreProvider.js";
|
|
2
3
|
import { useSelectFromState } from "./useSelectFromState.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const useDocumentState = ()=>{
|
|
5
|
+
const documentStore = useDocumentStore();
|
|
6
|
+
return useSelectFromState(()=>documentStore.getDocument(), (document)=>toJS(document.state) ?? {});
|
|
6
7
|
};
|
|
8
|
+
export { useDocumentState };
|
|
7
9
|
|
|
8
10
|
//# sourceMappingURL=useDocumentState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"components/useDocumentState.js","sources":["../../src/components/useDocumentState.ts"],"sourcesContent":["import { toJS } from \"mobx\";\nimport { useDocumentStore } from \"./DocumentStoreProvider.js\";\nimport { useSelectFromState } from \"./useSelectFromState.js\";\n\nexport const useDocumentState = () => {\n const documentStore = useDocumentStore();\n return useSelectFromState(\n () => documentStore.getDocument()!,\n // The state's values (`toJS` reads them all), not the observable object: the store changes\n // values in place, so the object itself stays the same when a value changes.\n document => toJS(document.state) ?? {}\n );\n};\n"],"names":["useDocumentState","documentStore","useDocumentStore","useSelectFromState","document","toJS"],"mappings":";;;AAIO,MAAMA,mBAAmB;IAC5B,MAAMC,gBAAgBC;IACtB,OAAOC,mBACH,IAAMF,cAAc,WAAW,IAG/BG,CAAAA,WAAYC,KAAKD,SAAS,KAAK,KAAK,CAAC;AAE7C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type DocumentElement } from "@webiny/website-builder-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Whether this component's element, or an element inside it, is selected in the editor.
|
|
4
|
+
* Use it to show content that is normally hidden, e.g. a dialog opens itself while it's selected,
|
|
5
|
+
* or an accordion expands while one of its items is selected.
|
|
6
|
+
* Always `false` outside the editor.
|
|
7
|
+
*/
|
|
8
|
+
export declare const useIsElementSelected: (element: Pick<DocumentElement, "id">) => boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { autorun } from "mobx";
|
|
4
|
+
import { useContentClient } from "./useContentClient.js";
|
|
5
|
+
const useIsElementSelected = (element)=>{
|
|
6
|
+
const client = useContentClient();
|
|
7
|
+
const [isSelected, setIsSelected] = useState(false);
|
|
8
|
+
useEffect(()=>{
|
|
9
|
+
const editingSdk = client.getEditingSdk();
|
|
10
|
+
if (!editingSdk) return;
|
|
11
|
+
return autorun(()=>{
|
|
12
|
+
setIsSelected(editingSdk.isElementSelected(element.id));
|
|
13
|
+
});
|
|
14
|
+
}, [
|
|
15
|
+
element.id,
|
|
16
|
+
client
|
|
17
|
+
]);
|
|
18
|
+
return isSelected;
|
|
19
|
+
};
|
|
20
|
+
export { useIsElementSelected };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=useIsElementSelected.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/useIsElementSelected.js","sources":["../../src/components/useIsElementSelected.tsx"],"sourcesContent":["\"use client\";\nimport { useEffect, useState } from \"react\";\nimport { autorun } from \"mobx\";\nimport { type DocumentElement } from \"@webiny/website-builder-sdk\";\nimport { useContentClient } from \"./useContentClient.js\";\n\n/**\n * Whether this component's element, or an element inside it, is selected in the editor.\n * Use it to show content that is normally hidden, e.g. a dialog opens itself while it's selected,\n * or an accordion expands while one of its items is selected.\n * Always `false` outside the editor.\n */\nexport const useIsElementSelected = (element: Pick<DocumentElement, \"id\">): boolean => {\n const client = useContentClient();\n const [isSelected, setIsSelected] = useState(false);\n\n useEffect(() => {\n const editingSdk = client.getEditingSdk();\n if (!editingSdk) {\n return;\n }\n\n return autorun(() => {\n setIsSelected(editingSdk.isElementSelected(element.id));\n });\n }, [element.id, client]);\n\n return isSelected;\n};\n"],"names":["useIsElementSelected","element","client","useContentClient","isSelected","setIsSelected","useState","useEffect","editingSdk","autorun"],"mappings":";;;;AAYO,MAAMA,uBAAuB,CAACC;IACjC,MAAMC,SAASC;IACf,MAAM,CAACC,YAAYC,cAAc,GAAGC,SAAS;IAE7CC,UAAU;QACN,MAAMC,aAAaN,OAAO,aAAa;QACvC,IAAI,CAACM,YACD;QAGJ,OAAOC,QAAQ;YACXJ,cAAcG,WAAW,iBAAiB,CAACP,QAAQ,EAAE;QACzD;IACJ,GAAG;QAACA,QAAQ,EAAE;QAAEC;KAAO;IAEvB,OAAOE;AACX"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Document, DocumentStore } from "@webiny/website-builder-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* A store of its own for a document rendered inside another one (a page's layout, the page previewed in the
|
|
4
|
+
* layout editor): never one shared by id across renders, or across requests on the server.
|
|
5
|
+
*
|
|
6
|
+
* It's seeded on creation, so the first render (and the server render) has the document. A changed document
|
|
7
|
+
* goes into the store after render: writing an observable store while rendering would update its observers
|
|
8
|
+
* during someone else's render.
|
|
9
|
+
*/
|
|
10
|
+
export declare const useSeededDocumentStore: (document: Document) => DocumentStore<Document>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { DocumentStore } from "@webiny/website-builder-sdk";
|
|
4
|
+
const useSeededDocumentStore = (document)=>{
|
|
5
|
+
const [store] = useState(()=>{
|
|
6
|
+
const store = new DocumentStore();
|
|
7
|
+
store.setDocument(document);
|
|
8
|
+
return store;
|
|
9
|
+
});
|
|
10
|
+
const appliedDocument = useRef(document);
|
|
11
|
+
useEffect(()=>{
|
|
12
|
+
if (appliedDocument.current === document) return;
|
|
13
|
+
appliedDocument.current = document;
|
|
14
|
+
store.setDocument(document);
|
|
15
|
+
}, [
|
|
16
|
+
document
|
|
17
|
+
]);
|
|
18
|
+
return store;
|
|
19
|
+
};
|
|
20
|
+
export { useSeededDocumentStore };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=useSeededDocumentStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/useSeededDocumentStore.js","sources":["../../src/components/useSeededDocumentStore.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { type Document, DocumentStore } from \"@webiny/website-builder-sdk\";\n\n/**\n * A store of its own for a document rendered inside another one (a page's layout, the page previewed in the\n * layout editor): never one shared by id across renders, or across requests on the server.\n *\n * It's seeded on creation, so the first render (and the server render) has the document. A changed document\n * goes into the store after render: writing an observable store while rendering would update its observers\n * during someone else's render.\n */\nexport const useSeededDocumentStore = (document: Document) => {\n const [store] = useState(() => {\n const store = new DocumentStore();\n store.setDocument(document);\n return store;\n });\n const appliedDocument = useRef(document);\n\n useEffect(() => {\n if (appliedDocument.current === document) {\n return;\n }\n appliedDocument.current = document;\n store.setDocument(document);\n }, [document]);\n\n return store;\n};\n"],"names":["useSeededDocumentStore","document","store","useState","DocumentStore","appliedDocument","useRef","useEffect"],"mappings":";;;AAYO,MAAMA,yBAAyB,CAACC;IACnC,MAAM,CAACC,MAAM,GAAGC,SAAS;QACrB,MAAMD,QAAQ,IAAIE;QAClBF,MAAM,WAAW,CAACD;QAClB,OAAOC;IACX;IACA,MAAMG,kBAAkBC,OAAOL;IAE/BM,UAAU;QACN,IAAIF,gBAAgB,OAAO,KAAKJ,UAC5B;QAEJI,gBAAgB,OAAO,GAAGJ;QAC1BC,MAAM,WAAW,CAACD;IACtB,GAAG;QAACA;KAAS;IAEb,OAAOC;AACX"}
|
|
@@ -2,7 +2,8 @@ type Equals<T> = (a: T, b: T) => boolean;
|
|
|
2
2
|
/**
|
|
3
3
|
* Subscribe to part of the document state.
|
|
4
4
|
* @param selector Pick the slice of state you care about.
|
|
5
|
-
* @param equals (optional) comparator, defaults to
|
|
5
|
+
* @param equals (optional) comparator, defaults to a strict structural compare
|
|
6
|
+
* (`lodash/isEqual`), cheap enough to run for every subscribed element
|
|
6
7
|
*/
|
|
7
8
|
export declare function useSelectFromState<TState, T>(getState: () => TState, selector: (doc: TState) => T, deps?: React.DependencyList, equals?: Equals<T>): T;
|
|
8
9
|
export {};
|
|
@@ -1,39 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import isEqual from "lodash/isEqual.js";
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { reaction } from "mobx";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
return () => {
|
|
32
|
-
// clean up when the component unmounts
|
|
33
|
-
disposer();
|
|
34
|
-
};
|
|
35
|
-
}, [getState, selector, equals, ...deps]);
|
|
36
|
-
return value;
|
|
4
|
+
function useSelectFromState(getState, selector, deps = [], equals = isEqual) {
|
|
5
|
+
const initialValue = useMemo(()=>selector(getState()), deps);
|
|
6
|
+
const [value, setValue] = useState(initialValue);
|
|
7
|
+
useEffect(()=>{
|
|
8
|
+
setValue(selector(getState()));
|
|
9
|
+
}, deps);
|
|
10
|
+
useEffect(()=>{
|
|
11
|
+
const disposer = reaction(()=>{
|
|
12
|
+
const state = getState();
|
|
13
|
+
return selector(state);
|
|
14
|
+
}, (newValue, oldValue)=>{
|
|
15
|
+
if (!equals(oldValue, newValue)) setValue(newValue);
|
|
16
|
+
}, {
|
|
17
|
+
equals,
|
|
18
|
+
fireImmediately: false
|
|
19
|
+
});
|
|
20
|
+
return ()=>{
|
|
21
|
+
disposer();
|
|
22
|
+
};
|
|
23
|
+
}, [
|
|
24
|
+
getState,
|
|
25
|
+
selector,
|
|
26
|
+
equals,
|
|
27
|
+
...deps
|
|
28
|
+
]);
|
|
29
|
+
return value;
|
|
37
30
|
}
|
|
31
|
+
export { useSelectFromState };
|
|
38
32
|
|
|
39
33
|
//# sourceMappingURL=useSelectFromState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"components/useSelectFromState.js","sources":["../../src/components/useSelectFromState.ts"],"sourcesContent":["import isEqual from \"lodash/isEqual.js\";\nimport { useState, useEffect, useMemo } from \"react\";\nimport type { IReactionDisposer } from \"mobx\";\nimport { reaction } from \"mobx\";\n\ntype Equals<T> = (a: T, b: T) => boolean;\n\n/**\n * Subscribe to part of the document state.\n * @param selector Pick the slice of state you care about.\n * @param equals (optional) comparator, defaults to a strict structural compare\n * (`lodash/isEqual`), cheap enough to run for every subscribed element\n */\nexport function useSelectFromState<TState, T>(\n getState: () => TState,\n selector: (doc: TState) => T,\n deps: React.DependencyList = [],\n equals: Equals<T> = isEqual\n): T {\n // Pull the initial slice synchronously\n const initialValue = useMemo(() => selector(getState()), deps);\n const [value, setValue] = useState<T>(initialValue);\n\n useEffect(() => {\n setValue(selector(getState())); // reset state on dep change\n }, deps);\n\n useEffect(() => {\n // reaction tracks selector(doc) and only fires when newVal !== oldVal\n const disposer: IReactionDisposer = reaction(\n () => {\n const state = getState();\n\n return selector(state);\n },\n (newValue, oldValue) => {\n if (!equals(oldValue, newValue)) {\n setValue(newValue);\n }\n },\n {\n // use your comparator to decide if newValue “really” changed\n equals,\n // we already set initial via useState\n fireImmediately: false\n }\n );\n\n return () => {\n // clean up when the component unmounts\n disposer();\n };\n }, [getState, selector, equals, ...deps]);\n\n return value;\n}\n"],"names":["useSelectFromState","getState","selector","deps","equals","isEqual","initialValue","useMemo","value","setValue","useState","useEffect","disposer","reaction","state","newValue","oldValue"],"mappings":";;;AAaO,SAASA,mBACZC,QAAsB,EACtBC,QAA4B,EAC5BC,OAA6B,EAAE,EAC/BC,SAAoBC,OAAO;IAG3B,MAAMC,eAAeC,QAAQ,IAAML,SAASD,aAAaE;IACzD,MAAM,CAACK,OAAOC,SAAS,GAAGC,SAAYJ;IAEtCK,UAAU;QACNF,SAASP,SAASD;IACtB,GAAGE;IAEHQ,UAAU;QAEN,MAAMC,WAA8BC,SAChC;YACI,MAAMC,QAAQb;YAEd,OAAOC,SAASY;QACpB,GACA,CAACC,UAAUC;YACP,IAAI,CAACZ,OAAOY,UAAUD,WAClBN,SAASM;QAEjB,GACA;YAEIX;YAEA,iBAAiB;QACrB;QAGJ,OAAO;YAEHQ;QACJ;IACJ,GAAG;QAACX;QAAUC;QAAUE;WAAWD;KAAK;IAExC,OAAOK;AACX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { act, renderHook } from "@testing-library/react";
|
|
3
|
+
import { observable, runInAction } from "mobx";
|
|
4
|
+
import { useSelectFromState } from "./useSelectFromState.js";
|
|
5
|
+
function subscribe(state, elementId) {
|
|
6
|
+
let renders = 0;
|
|
7
|
+
const hook = renderHook(()=>{
|
|
8
|
+
renders++;
|
|
9
|
+
return useSelectFromState(()=>state, (current)=>({
|
|
10
|
+
...current.bindings[elementId]
|
|
11
|
+
}), [
|
|
12
|
+
elementId
|
|
13
|
+
]);
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
hook,
|
|
17
|
+
renders: ()=>renders
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
describe("useSelectFromState", ()=>{
|
|
21
|
+
it("returns the new slice when its value changes", ()=>{
|
|
22
|
+
const state = observable({
|
|
23
|
+
bindings: {
|
|
24
|
+
a: {
|
|
25
|
+
value: "one"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const { hook } = subscribe(state, "a");
|
|
30
|
+
act(()=>runInAction(()=>state.bindings.a.value = "two"));
|
|
31
|
+
expect(hook.result.current).toEqual({
|
|
32
|
+
value: "two"
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
it("returns the new slice when only the value's type changes", ()=>{
|
|
36
|
+
const state = observable({
|
|
37
|
+
bindings: {
|
|
38
|
+
a: {
|
|
39
|
+
value: 1
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const { hook } = subscribe(state, "a");
|
|
44
|
+
act(()=>runInAction(()=>state.bindings.a.value = "1"));
|
|
45
|
+
expect(hook.result.current).toEqual({
|
|
46
|
+
value: "1"
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
it("doesn't re-render when another element's bindings change", ()=>{
|
|
50
|
+
const state = observable({
|
|
51
|
+
bindings: {
|
|
52
|
+
a: {
|
|
53
|
+
value: "one"
|
|
54
|
+
},
|
|
55
|
+
b: {
|
|
56
|
+
value: "x"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const { renders } = subscribe(state, "a");
|
|
61
|
+
const before = renders();
|
|
62
|
+
act(()=>runInAction(()=>state.bindings.b.value = "y"));
|
|
63
|
+
expect(renders()).toBe(before);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=useSelectFromState.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/useSelectFromState.test.js","sources":["../../src/components/useSelectFromState.test.ts"],"sourcesContent":["// @vitest-environment jsdom\nimport { describe, expect, it } from \"vitest\";\nimport { act, renderHook } from \"@testing-library/react\";\nimport { observable, runInAction } from \"mobx\";\nimport { useSelectFromState } from \"./useSelectFromState.js\";\n\ninterface TestState {\n bindings: Record<string, { value: unknown }>;\n}\n\nfunction subscribe(state: TestState, elementId: string) {\n let renders = 0;\n const hook = renderHook(() => {\n renders++;\n return useSelectFromState(\n () => state,\n current => ({ ...current.bindings[elementId] }),\n [elementId]\n );\n });\n return { hook, renders: () => renders };\n}\n\ndescribe(\"useSelectFromState\", () => {\n it(\"returns the new slice when its value changes\", () => {\n const state = observable<TestState>({ bindings: { a: { value: \"one\" } } });\n const { hook } = subscribe(state, \"a\");\n\n act(() => runInAction(() => (state.bindings.a.value = \"two\")));\n\n expect(hook.result.current).toEqual({ value: \"two\" });\n });\n\n // The default comparator is strict: a loose one (`deep-equal`'s default, `1 == \"1\"`) kept the\n // old value when only the type changed, e.g. a radio input's value from 1 to \"1\".\n it(\"returns the new slice when only the value's type changes\", () => {\n const state = observable<TestState>({ bindings: { a: { value: 1 } } });\n const { hook } = subscribe(state, \"a\");\n\n act(() => runInAction(() => (state.bindings.a.value = \"1\")));\n\n expect(hook.result.current).toEqual({ value: \"1\" });\n });\n\n it(\"doesn't re-render when another element's bindings change\", () => {\n const state = observable<TestState>({\n bindings: { a: { value: \"one\" }, b: { value: \"x\" } }\n });\n const { renders } = subscribe(state, \"a\");\n const before = renders();\n\n act(() => runInAction(() => (state.bindings.b.value = \"y\")));\n\n expect(renders()).toBe(before);\n });\n});\n"],"names":["subscribe","state","elementId","renders","hook","renderHook","useSelectFromState","current","describe","it","observable","act","runInAction","expect","before"],"mappings":";;;;AAUA,SAASA,UAAUC,KAAgB,EAAEC,SAAiB;IAClD,IAAIC,UAAU;IACd,MAAMC,OAAOC,WAAW;QACpBF;QACA,OAAOG,mBACH,IAAML,OACNM,CAAAA,UAAY;gBAAE,GAAGA,QAAQ,QAAQ,CAACL,UAAU;YAAC,IAC7C;YAACA;SAAU;IAEnB;IACA,OAAO;QAAEE;QAAM,SAAS,IAAMD;IAAQ;AAC1C;AAEAK,SAAS,sBAAsB;IAC3BC,GAAG,gDAAgD;QAC/C,MAAMR,QAAQS,WAAsB;YAAE,UAAU;gBAAE,GAAG;oBAAE,OAAO;gBAAM;YAAE;QAAE;QACxE,MAAM,EAAEN,IAAI,EAAE,GAAGJ,UAAUC,OAAO;QAElCU,IAAI,IAAMC,YAAY,IAAOX,MAAM,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG;QAEtDY,OAAOT,KAAK,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;YAAE,OAAO;QAAM;IACvD;IAIAK,GAAG,4DAA4D;QAC3D,MAAMR,QAAQS,WAAsB;YAAE,UAAU;gBAAE,GAAG;oBAAE,OAAO;gBAAE;YAAE;QAAE;QACpE,MAAM,EAAEN,IAAI,EAAE,GAAGJ,UAAUC,OAAO;QAElCU,IAAI,IAAMC,YAAY,IAAOX,MAAM,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG;QAEtDY,OAAOT,KAAK,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;YAAE,OAAO;QAAI;IACrD;IAEAK,GAAG,4DAA4D;QAC3D,MAAMR,QAAQS,WAAsB;YAChC,UAAU;gBAAE,GAAG;oBAAE,OAAO;gBAAM;gBAAG,GAAG;oBAAE,OAAO;gBAAI;YAAE;QACvD;QACA,MAAM,EAAEP,OAAO,EAAE,GAAGH,UAAUC,OAAO;QACrC,MAAMa,SAASX;QAEfQ,IAAI,IAAMC,YAAY,IAAOX,MAAM,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG;QAEtDY,OAAOV,WAAW,IAAI,CAACW;IAC3B;AACJ"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
import { viewportManager } from "@webiny/website-builder-sdk";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return
|
|
7
|
-
}, []);
|
|
8
|
-
return viewport;
|
|
3
|
+
const useViewport = ()=>{
|
|
4
|
+
const [viewport, setViewport] = useState(viewportManager.getViewport());
|
|
5
|
+
useEffect(()=>viewportManager.onViewportChangeEnd(setViewport), []);
|
|
6
|
+
return viewport;
|
|
9
7
|
};
|
|
8
|
+
export { useViewport };
|
|
10
9
|
|
|
11
10
|
//# sourceMappingURL=useViewportInfo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"components/useViewportInfo.js","sources":["../../src/components/useViewportInfo.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport { viewportManager } from \"@webiny/website-builder-sdk\";\n\nexport const useViewport = () => {\n const [viewport, setViewport] = useState(viewportManager.getViewport());\n\n useEffect(() => {\n return viewportManager.onViewportChangeEnd(setViewport);\n }, []);\n\n return viewport;\n};\n"],"names":["useViewport","viewport","setViewport","useState","viewportManager","useEffect"],"mappings":";;AAGO,MAAMA,cAAc;IACvB,MAAM,CAACC,UAAUC,YAAY,GAAGC,SAASC,gBAAgB,WAAW;IAEpEC,UAAU,IACCD,gBAAgB,mBAAmB,CAACF,cAC5C,EAAE;IAEL,OAAOD;AACX"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ResolvedContentEntryQuery } from "@webiny/website-builder-sdk";
|
|
2
|
+
export type { ResolvedContentEntryQuery, ContentEntryQuerySpec } from "@webiny/website-builder-sdk";
|
|
3
|
+
export interface ContentEntryList<T = unknown> {
|
|
4
|
+
/** The loaded entries (first page + any loaded via loadMore). */
|
|
5
|
+
items: T[];
|
|
6
|
+
/** Whether more pages are available (and pagination is enabled). */
|
|
7
|
+
hasMore: boolean;
|
|
8
|
+
/** True while a loadMore fetch is in flight. */
|
|
9
|
+
loading: boolean;
|
|
10
|
+
/** Fetch and append the next page. No-op when nothing more to load. */
|
|
11
|
+
loadMore: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Client hook for a query-mode `contentEntry` input. Seeds from the server-resolved
|
|
15
|
+
* first page (SSR-safe — no fetch on mount) and loads further pages on demand from
|
|
16
|
+
* the embedded query + cursor. Re-seeds when the underlying query changes (e.g. the
|
|
17
|
+
* editor tweaks sort/limit/search in preview).
|
|
18
|
+
*
|
|
19
|
+
* Pagination is active only when the input enables it (the resolved value then
|
|
20
|
+
* carries a `query`); otherwise `hasMore` is always false and `loadMore` is a no-op.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useContentEntryList<T = unknown>(value: ResolvedContentEntryQuery<T> | null | undefined): ContentEntryList<T>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
import { contentSdk } from "@webiny/cms-sdk";
|
|
4
|
+
function useContentEntryList(value) {
|
|
5
|
+
const query = value?.query;
|
|
6
|
+
const signature = JSON.stringify({
|
|
7
|
+
query,
|
|
8
|
+
cursor: value?.pageInfo?.cursor ?? null
|
|
9
|
+
});
|
|
10
|
+
const seed = ()=>({
|
|
11
|
+
signature,
|
|
12
|
+
items: value?.items ?? [],
|
|
13
|
+
cursor: value?.pageInfo?.cursor ?? null,
|
|
14
|
+
apiHasMore: value?.pageInfo?.hasMore ?? false
|
|
15
|
+
});
|
|
16
|
+
const [state, setState] = useState(seed);
|
|
17
|
+
const [loading, setLoading] = useState(false);
|
|
18
|
+
if (state.signature !== signature) setState(seed());
|
|
19
|
+
const loadMore = useCallback(()=>{
|
|
20
|
+
if (!query || loading || !state.apiHasMore || !state.cursor) return;
|
|
21
|
+
setLoading(true);
|
|
22
|
+
contentSdk.listEntries({
|
|
23
|
+
...query,
|
|
24
|
+
after: state.cursor
|
|
25
|
+
}).then((result)=>{
|
|
26
|
+
setState((prev)=>({
|
|
27
|
+
...prev,
|
|
28
|
+
items: [
|
|
29
|
+
...prev.items,
|
|
30
|
+
...result.data
|
|
31
|
+
],
|
|
32
|
+
cursor: result.meta.cursor,
|
|
33
|
+
apiHasMore: result.meta.hasMoreItems
|
|
34
|
+
}));
|
|
35
|
+
}).finally(()=>setLoading(false));
|
|
36
|
+
}, [
|
|
37
|
+
query,
|
|
38
|
+
loading,
|
|
39
|
+
state.apiHasMore,
|
|
40
|
+
state.cursor
|
|
41
|
+
]);
|
|
42
|
+
return {
|
|
43
|
+
items: state.items,
|
|
44
|
+
hasMore: Boolean(query) && state.apiHasMore,
|
|
45
|
+
loading,
|
|
46
|
+
loadMore
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export { useContentEntryList };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=useContentEntryList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentEntry/useContentEntryList.js","sources":["../../src/contentEntry/useContentEntryList.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useState } from \"react\";\nimport { contentSdk } from \"@webiny/cms-sdk\";\nimport type { ResolvedContentEntryQuery } from \"@webiny/website-builder-sdk\";\n\nexport type { ResolvedContentEntryQuery, ContentEntryQuerySpec } from \"@webiny/website-builder-sdk\";\n\nexport interface ContentEntryList<T = unknown> {\n /** The loaded entries (first page + any loaded via loadMore). */\n items: T[];\n /** Whether more pages are available (and pagination is enabled). */\n hasMore: boolean;\n /** True while a loadMore fetch is in flight. */\n loading: boolean;\n /** Fetch and append the next page. No-op when nothing more to load. */\n loadMore: () => void;\n}\n\ninterface PageState<T> {\n signature: string;\n items: T[];\n cursor: string | null;\n apiHasMore: boolean;\n}\n\n/**\n * Client hook for a query-mode `contentEntry` input. Seeds from the server-resolved\n * first page (SSR-safe — no fetch on mount) and loads further pages on demand from\n * the embedded query + cursor. Re-seeds when the underlying query changes (e.g. the\n * editor tweaks sort/limit/search in preview).\n *\n * Pagination is active only when the input enables it (the resolved value then\n * carries a `query`); otherwise `hasMore` is always false and `loadMore` is a no-op.\n */\nexport function useContentEntryList<T = unknown>(\n value: ResolvedContentEntryQuery<T> | null | undefined\n): ContentEntryList<T> {\n const query = value?.query;\n const signature = JSON.stringify({ query, cursor: value?.pageInfo?.cursor ?? null });\n\n const seed = (): PageState<T> => ({\n signature,\n items: value?.items ?? [],\n cursor: value?.pageInfo?.cursor ?? null,\n apiHasMore: value?.pageInfo?.hasMore ?? false\n });\n\n const [state, setState] = useState<PageState<T>>(seed);\n const [loading, setLoading] = useState(false);\n\n // Re-seed (on the client) when the resolved page changes — e.g. the editor edits\n // the query. The first/SSR render already has the right data via useState.\n if (state.signature !== signature) {\n setState(seed());\n }\n\n const loadMore = useCallback(() => {\n if (!query || loading || !state.apiHasMore || !state.cursor) {\n return;\n }\n setLoading(true);\n contentSdk\n .listEntries({ ...query, after: state.cursor })\n .then(result => {\n setState(prev => ({\n ...prev,\n items: [...prev.items, ...(result.data as T[])],\n cursor: result.meta.cursor,\n apiHasMore: result.meta.hasMoreItems\n }));\n })\n .finally(() => setLoading(false));\n }, [query, loading, state.apiHasMore, state.cursor]);\n\n return {\n items: state.items,\n hasMore: Boolean(query) && state.apiHasMore,\n loading,\n loadMore\n };\n}\n"],"names":["useContentEntryList","value","query","signature","JSON","seed","state","setState","useState","loading","setLoading","loadMore","useCallback","contentSdk","result","prev","Boolean"],"mappings":";;;AAkCO,SAASA,oBACZC,KAAsD;IAEtD,MAAMC,QAAQD,OAAO;IACrB,MAAME,YAAYC,KAAK,SAAS,CAAC;QAAEF;QAAO,QAAQD,OAAO,UAAU,UAAU;IAAK;IAElF,MAAMI,OAAO,IAAqB;YAC9BF;YACA,OAAOF,OAAO,SAAS,EAAE;YACzB,QAAQA,OAAO,UAAU,UAAU;YACnC,YAAYA,OAAO,UAAU,WAAW;QAC5C;IAEA,MAAM,CAACK,OAAOC,SAAS,GAAGC,SAAuBH;IACjD,MAAM,CAACI,SAASC,WAAW,GAAGF,SAAS;IAIvC,IAAIF,MAAM,SAAS,KAAKH,WACpBI,SAASF;IAGb,MAAMM,WAAWC,YAAY;QACzB,IAAI,CAACV,SAASO,WAAW,CAACH,MAAM,UAAU,IAAI,CAACA,MAAM,MAAM,EACvD;QAEJI,WAAW;QACXG,WAAAA,WACgB,CAAC;YAAE,GAAGX,KAAK;YAAE,OAAOI,MAAM,MAAM;QAAC,GAC5C,IAAI,CAACQ,CAAAA;YACFP,SAASQ,CAAAA,OAAS;oBACd,GAAGA,IAAI;oBACP,OAAO;2BAAIA,KAAK,KAAK;2BAAMD,OAAO,IAAI;qBAAS;oBAC/C,QAAQA,OAAO,IAAI,CAAC,MAAM;oBAC1B,YAAYA,OAAO,IAAI,CAAC,YAAY;gBACxC;QACJ,GACC,OAAO,CAAC,IAAMJ,WAAW;IAClC,GAAG;QAACR;QAAOO;QAASH,MAAM,UAAU;QAAEA,MAAM,MAAM;KAAC;IAEnD,OAAO;QACH,OAAOA,MAAM,KAAK;QAClB,SAASU,QAAQd,UAAUI,MAAM,UAAU;QAC3CG;QACAE;IACJ;AACJ"}
|
package/createComponent.d.ts
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { ExtractInputs } from "./types.js";
|
|
3
|
-
export declare function createComponent<TComponent extends (props: any) => any, TInputs extends ExtractInputs<Parameters<TComponent>[0]>>(component: TComponent, manifest: ComponentManifestInput<TInputs>): Component;
|
|
1
|
+
export { createComponent } from "@webiny/website-builder-sdk";
|
package/createComponent.js
CHANGED
|
@@ -1,36 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export function createComponent(component, manifest) {
|
|
3
|
-
const inputs = [];
|
|
4
|
-
|
|
5
|
-
// Normalize inputs to always be an array of objects.
|
|
6
|
-
|
|
7
|
-
if (Array.isArray(manifest.inputs)) {
|
|
8
|
-
inputs.push(...manifest.inputs);
|
|
9
|
-
} else {
|
|
10
|
-
const inputsObject = manifest.inputs ?? {};
|
|
11
|
-
Object.keys(inputsObject).forEach(name => {
|
|
12
|
-
inputs.push({
|
|
13
|
-
...inputsObject[name],
|
|
14
|
-
name
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const acceptsChildren = manifest.acceptsChildren;
|
|
19
|
-
if (acceptsChildren) {
|
|
20
|
-
const hasChildren = inputs.some(input => input.name === "children");
|
|
21
|
-
if (!hasChildren) {
|
|
22
|
-
inputs.push(createSlotInput({
|
|
23
|
-
name: "children"
|
|
24
|
-
}));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
component,
|
|
29
|
-
manifest: {
|
|
30
|
-
...manifest,
|
|
31
|
-
inputs
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
//# sourceMappingURL=createComponent.js.map
|
|
1
|
+
export { createComponent } from "@webiny/website-builder-sdk";
|