@webiny/website-builder-react 0.0.0-unstable.81ae05e56b → 0.0.0-unstable.9609e4e0c9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ConnectToEditor.d.ts +3 -1
- package/components/ConnectToEditor.js +20 -20
- package/components/ConnectToEditor.js.map +1 -1
- package/components/ContentClientContext.d.ts +3 -0
- package/components/ContentClientContext.js +6 -0
- package/components/ContentClientContext.js.map +1 -0
- package/components/ContentClientProvider.d.ts +12 -0
- package/components/ContentClientProvider.js +9 -0
- package/components/ContentClientProvider.js.map +1 -0
- package/components/ContentClientProvider.test.d.ts +1 -0
- package/components/ContentClientProvider.test.js +143 -0
- package/components/ContentClientProvider.test.js.map +1 -0
- package/components/DocumentFragment.js +5 -7
- package/components/DocumentFragment.js.map +1 -1
- package/components/DocumentRenderer.d.ts +8 -3
- package/components/DocumentRenderer.js +51 -48
- package/components/DocumentRenderer.js.map +1 -1
- package/components/DocumentStoreProvider.d.ts +7 -0
- package/components/DocumentStoreProvider.js +22 -22
- package/components/DocumentStoreProvider.js.map +1 -1
- package/components/EditingElementRenderer/EditingElementRenderer.d.ts +7 -2
- package/components/EditingElementRenderer/EditingElementRenderer.js +43 -35
- package/components/EditingElementRenderer/EditingElementRenderer.js.map +1 -1
- package/components/EditingElementRenderer/EditingElementRenderer.presenter.d.ts +2 -2
- package/components/EditingElementRenderer/EditingElementRenderer.presenter.js +31 -36
- package/components/EditingElementRenderer/EditingElementRenderer.presenter.js.map +1 -1
- package/components/EditingElementRenderer/index.js +0 -2
- package/components/ElementIndexProvider.js +9 -14
- package/components/ElementIndexProvider.js.map +1 -1
- package/components/ElementRenderer.d.ts +2 -2
- package/components/ElementRenderer.js +25 -17
- package/components/ElementRenderer.js.map +1 -1
- package/components/ElementSlot.js +9 -9
- package/components/ElementSlot.js.map +1 -1
- package/components/ElementSlotDepthProvider.js +9 -14
- package/components/ElementSlotDepthProvider.js.map +1 -1
- package/components/FragmentsProvider.js +32 -37
- package/components/FragmentsProvider.js.map +1 -1
- package/components/GlobalComponent.d.ts +10 -0
- package/components/GlobalComponent.js +17 -0
- package/components/GlobalComponent.js.map +1 -0
- package/components/GlobalPlacement.d.ts +11 -0
- package/components/GlobalPlacement.js +27 -0
- package/components/GlobalPlacement.js.map +1 -0
- package/components/LayoutAreas.d.ts +19 -0
- package/components/LayoutAreas.js +15 -0
- package/components/LayoutAreas.js.map +1 -0
- package/components/LayoutRenderer.d.ts +14 -0
- package/components/LayoutRenderer.js +60 -0
- package/components/LayoutRenderer.js.map +1 -0
- package/components/LayoutRenderer.test.d.ts +1 -0
- package/components/LayoutRenderer.test.js +138 -0
- package/components/LayoutRenderer.test.js.map +1 -0
- package/components/LiveElementRenderer.d.ts +2 -2
- package/components/LiveElementRenderer.js +59 -69
- package/components/LiveElementRenderer.js.map +1 -1
- package/components/LiveElementSlot.js +12 -14
- package/components/LiveElementSlot.js.map +1 -1
- package/components/PageLayout.d.ts +40 -0
- package/components/PageLayout.js +71 -0
- package/components/PageLayout.js.map +1 -0
- package/components/PreviewElementSlot.js +27 -23
- package/components/PreviewElementSlot.js.map +1 -1
- package/components/SlotLabel.d.ts +15 -0
- package/components/SlotLabel.js +13 -0
- package/components/SlotLabel.js.map +1 -0
- package/components/index.d.ts +7 -0
- package/components/index.js +6 -2
- package/components/renderWithLayout.d.ts +5 -0
- package/components/renderWithLayout.js +7 -0
- package/components/renderWithLayout.js.map +1 -0
- package/components/useBindingsForElement.js +13 -11
- package/components/useBindingsForElement.js.map +1 -1
- package/components/useContentClient.d.ts +6 -0
- package/components/useContentClient.js +11 -0
- package/components/useContentClient.js.map +1 -0
- package/components/useDocumentState.js +4 -3
- package/components/useDocumentState.js.map +1 -1
- package/components/useIsElementSelected.d.ts +8 -0
- package/components/useIsElementSelected.js +22 -0
- package/components/useIsElementSelected.js.map +1 -0
- package/components/useSeededDocumentStore.d.ts +10 -0
- package/components/useSeededDocumentStore.js +22 -0
- package/components/useSeededDocumentStore.js.map +1 -0
- package/components/useSelectFromState.js +29 -35
- package/components/useSelectFromState.js.map +1 -1
- package/components/useViewportInfo.js +5 -6
- package/components/useViewportInfo.js.map +1 -1
- package/contentEntry/useContentEntryList.d.ts +22 -0
- package/contentEntry/useContentEntryList.js +51 -0
- package/contentEntry/useContentEntryList.js.map +1 -0
- package/createComponent.d.ts +1 -3
- package/createComponent.js +1 -37
- package/createComponent.test.js +108 -122
- package/createComponent.test.js.map +1 -1
- package/editorComponents/Box.js +3 -6
- package/editorComponents/Box.js.map +1 -1
- package/editorComponents/Box.manifest.js +15 -14
- package/editorComponents/Box.manifest.js.map +1 -1
- package/editorComponents/Fragment.js +23 -32
- package/editorComponents/Fragment.js.map +1 -1
- package/editorComponents/Fragment.manifest.js +14 -11
- package/editorComponents/Fragment.manifest.js.map +1 -1
- package/editorComponents/Grid.js +33 -61
- package/editorComponents/Grid.js.map +1 -1
- package/editorComponents/Grid.manifest.js +163 -166
- package/editorComponents/Grid.manifest.js.map +1 -1
- package/editorComponents/GridColumn.js +3 -6
- package/editorComponents/GridColumn.js.map +1 -1
- package/editorComponents/GridColumn.manifest.js +20 -17
- package/editorComponents/GridColumn.manifest.js.map +1 -1
- package/editorComponents/Image.js +99 -119
- package/editorComponents/Image.js.map +1 -1
- package/editorComponents/Image.manifest.js +33 -32
- package/editorComponents/Image.manifest.js.map +1 -1
- package/editorComponents/LayoutContent.d.ts +6 -0
- package/editorComponents/LayoutContent.js +121 -0
- package/editorComponents/LayoutContent.js.map +1 -0
- package/editorComponents/LayoutContent.manifest.d.ts +10 -0
- package/editorComponents/LayoutContent.manifest.js +32 -0
- package/editorComponents/LayoutContent.manifest.js.map +1 -0
- package/editorComponents/LayoutContentLabel.d.ts +2 -0
- package/editorComponents/LayoutContentLabel.js +7 -0
- package/editorComponents/LayoutContentLabel.js.map +1 -0
- package/editorComponents/LayoutContentLabel.test.d.ts +1 -0
- package/editorComponents/LayoutContentLabel.test.js +23 -0
- package/editorComponents/LayoutContentLabel.test.js.map +1 -0
- package/editorComponents/Lexical.js +13 -21
- package/editorComponents/Lexical.js.map +1 -1
- package/editorComponents/Lexical.manifest.js +17 -14
- package/editorComponents/Lexical.manifest.js.map +1 -1
- package/editorComponents/Root.js +3 -6
- package/editorComponents/Root.js.map +1 -1
- package/editorComponents/Root.manifest.js +7 -6
- package/editorComponents/Root.manifest.js.map +1 -1
- package/editorComponents/index.js +13 -1
- package/editorComponents/index.js.map +1 -1
- package/image/BackgroundImage.d.ts +33 -0
- package/image/BackgroundImage.js +61 -0
- package/image/BackgroundImage.js.map +1 -0
- package/image/Image.d.ts +29 -0
- package/image/Image.js +43 -0
- package/image/Image.js.map +1 -0
- package/image/getImageProps.d.ts +42 -0
- package/image/getImageProps.js +18 -0
- package/image/getImageProps.js.map +1 -0
- package/image/getImageProps.test.d.ts +1 -0
- package/image/getImageProps.test.js +70 -0
- package/image/getImageProps.test.js.map +1 -0
- package/image/index.d.ts +3 -0
- package/image/index.js +3 -0
- package/index.d.ts +3 -2
- package/index.js +2 -4
- package/package.json +13 -12
- package/types.d.ts +2 -4
- package/types.js +0 -3
- package/components/EditingElementRenderer/index.js.map +0 -1
- package/components/index.js.map +0 -1
- package/createComponent.js.map +0 -1
- package/index.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,126 +1,106 @@
|
|
|
1
|
-
import
|
|
1
|
+
import react, { useCallback, useEffect, useState } from "react";
|
|
2
2
|
import { contentSdk } from "@webiny/website-builder-sdk";
|
|
3
|
-
const SUPPORTED_IMAGE_RESIZE_WIDTHS = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
const SUPPORTED_IMAGE_RESIZE_WIDTHS = [
|
|
4
|
+
100,
|
|
5
|
+
300,
|
|
6
|
+
500,
|
|
7
|
+
750,
|
|
8
|
+
1000,
|
|
9
|
+
1500,
|
|
10
|
+
2500
|
|
11
|
+
];
|
|
12
|
+
const ImageComponent = (props)=>{
|
|
13
|
+
const image = useImage(props);
|
|
14
|
+
if (!image.src) return /*#__PURE__*/ react.createElement(ImagePlaceholder, {
|
|
15
|
+
style: props.styles
|
|
9
16
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
title: image.title,
|
|
15
|
-
data: image.src
|
|
17
|
+
if ("object" === image.tag) return /*#__PURE__*/ react.createElement("object", {
|
|
18
|
+
style: image.styles,
|
|
19
|
+
title: image.title,
|
|
20
|
+
data: image.src
|
|
16
21
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}));
|
|
22
|
+
return /*#__PURE__*/ react.createElement(react.Fragment, null, !image.isLoaded && /*#__PURE__*/ react.createElement(ImagePlaceholder, {
|
|
23
|
+
style: image.styles
|
|
24
|
+
}), /*#__PURE__*/ react.createElement("img", {
|
|
25
|
+
alt: image.altText,
|
|
26
|
+
onLoad: image.onLoad,
|
|
27
|
+
title: image.title,
|
|
28
|
+
src: image.src,
|
|
29
|
+
srcSet: image.srcSet,
|
|
30
|
+
style: image.styles
|
|
31
|
+
}));
|
|
28
32
|
};
|
|
29
|
-
const ImagePlaceholder = ({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const imageStyles = {
|
|
100
|
-
maxWidth: "100%",
|
|
101
|
-
opacity: isLoaded ? 1 : 0,
|
|
102
|
-
transition: "opacity 0.3s ease",
|
|
103
|
-
...styles
|
|
104
|
-
};
|
|
105
|
-
const onLoad = useCallback(() => {
|
|
106
|
-
if (contentSdk.isEditing()) {
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
setIsLoaded(true);
|
|
109
|
-
}, 100);
|
|
110
|
-
} else {
|
|
111
|
-
setIsLoaded(true);
|
|
112
|
-
}
|
|
113
|
-
}, []);
|
|
114
|
-
return {
|
|
115
|
-
altText,
|
|
116
|
-
isLoaded,
|
|
117
|
-
onLoad,
|
|
118
|
-
src: inputs.image?.src,
|
|
119
|
-
srcSet,
|
|
120
|
-
styles: imageStyles,
|
|
121
|
-
tag,
|
|
122
|
-
title
|
|
123
|
-
};
|
|
33
|
+
const ImagePlaceholder = ({ style })=>/*#__PURE__*/ react.createElement("div", {
|
|
34
|
+
style: {
|
|
35
|
+
display: "flex",
|
|
36
|
+
height: "200px",
|
|
37
|
+
backgroundColor: "#f4f4f4",
|
|
38
|
+
justifyContent: "center",
|
|
39
|
+
alignItems: "center",
|
|
40
|
+
fill: "#ffffff",
|
|
41
|
+
...style
|
|
42
|
+
}
|
|
43
|
+
}, /*#__PURE__*/ react.createElement("svg", {
|
|
44
|
+
style: {
|
|
45
|
+
width: "70px",
|
|
46
|
+
height: "70px",
|
|
47
|
+
filter: "drop-shadow(rgba(0, 0, 0, 0.16) 0px 1px 0px)"
|
|
48
|
+
},
|
|
49
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
50
|
+
height: "24px",
|
|
51
|
+
viewBox: "0 -960 960 960",
|
|
52
|
+
width: "24px"
|
|
53
|
+
}, /*#__PURE__*/ react.createElement("path", {
|
|
54
|
+
d: "M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm40-80h480L570-480 450-320l-90-120-120 160Zm-40 80v-560 560Z"
|
|
55
|
+
})));
|
|
56
|
+
const getSrcSet = (src, srcSetWidths)=>srcSetWidths.map((item)=>`${src}?width=${item} ${item}w`).join(", ");
|
|
57
|
+
const useImage = ({ inputs, styles })=>{
|
|
58
|
+
const [isLoaded, setIsLoaded] = useState(!contentSdk.isEditing());
|
|
59
|
+
const { title = "", altText, image } = inputs;
|
|
60
|
+
const src = image?.src;
|
|
61
|
+
const tag = src && src.endsWith(".svg") ? "object" : "img";
|
|
62
|
+
useEffect(()=>{
|
|
63
|
+
if (!src) setIsLoaded(false);
|
|
64
|
+
}, [
|
|
65
|
+
src
|
|
66
|
+
]);
|
|
67
|
+
let srcSetWidths = [];
|
|
68
|
+
const width = styles.width?.toString();
|
|
69
|
+
if (width && width.endsWith("px")) {
|
|
70
|
+
const imageWidthInt = parseInt(width);
|
|
71
|
+
for(let i = 0; i < SUPPORTED_IMAGE_RESIZE_WIDTHS.length; i++){
|
|
72
|
+
const supportedResizeWidth = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];
|
|
73
|
+
if (imageWidthInt > supportedResizeWidth) srcSetWidths.push(supportedResizeWidth);
|
|
74
|
+
else {
|
|
75
|
+
srcSetWidths.push(supportedResizeWidth);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} else srcSetWidths = SUPPORTED_IMAGE_RESIZE_WIDTHS;
|
|
80
|
+
const srcSet = src ? getSrcSet(src, srcSetWidths) : "";
|
|
81
|
+
const imageStyles = {
|
|
82
|
+
maxWidth: "100%",
|
|
83
|
+
opacity: isLoaded ? 1 : 0,
|
|
84
|
+
transition: "opacity 0.3s ease",
|
|
85
|
+
...styles
|
|
86
|
+
};
|
|
87
|
+
const onLoad = useCallback(()=>{
|
|
88
|
+
if (contentSdk.isEditing()) setTimeout(()=>{
|
|
89
|
+
setIsLoaded(true);
|
|
90
|
+
}, 100);
|
|
91
|
+
else setIsLoaded(true);
|
|
92
|
+
}, []);
|
|
93
|
+
return {
|
|
94
|
+
altText,
|
|
95
|
+
isLoaded,
|
|
96
|
+
onLoad,
|
|
97
|
+
src: inputs.image?.src,
|
|
98
|
+
srcSet,
|
|
99
|
+
styles: imageStyles,
|
|
100
|
+
tag,
|
|
101
|
+
title
|
|
102
|
+
};
|
|
124
103
|
};
|
|
104
|
+
export { ImageComponent };
|
|
125
105
|
|
|
126
106
|
//# sourceMappingURL=Image.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"editorComponents/Image.js","sources":["../../src/editorComponents/Image.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport type { CssProperties } from \"@webiny/website-builder-sdk\";\nimport { contentSdk } from \"@webiny/website-builder-sdk\";\nimport type { ComponentProps } from \"~/types.js\";\n\nconst SUPPORTED_IMAGE_RESIZE_WIDTHS = [100, 300, 500, 750, 1000, 1500, 2500];\n\ntype ImageProps = ComponentProps<{\n title: string;\n altText: string;\n image: {\n id: string;\n name: string;\n size: number;\n mimeType: string;\n src: string;\n };\n}>;\n\nexport const ImageComponent = (props: ImageProps) => {\n const image = useImage(props);\n\n if (!image.src) {\n return <ImagePlaceholder style={props.styles} />;\n }\n\n if (image.tag === \"object\") {\n return <object style={image.styles} title={image.title} data={image.src} />;\n }\n\n return (\n <>\n {!image.isLoaded && <ImagePlaceholder style={image.styles} />}\n <img\n alt={image.altText}\n onLoad={image.onLoad}\n title={image.title}\n src={image.src}\n srcSet={image.srcSet}\n style={image.styles}\n />\n </>\n );\n};\n\nconst ImagePlaceholder = ({ style }: { style: CssProperties }) => {\n return (\n <div\n style={{\n display: \"flex\",\n height: \"200px\",\n backgroundColor: \"#f4f4f4\",\n justifyContent: \"center\",\n alignItems: \"center\",\n fill: \"#ffffff\",\n ...style\n }}\n >\n <svg\n style={{\n width: \"70px\",\n height: \"70px\",\n filter: \"drop-shadow(rgba(0, 0, 0, 0.16) 0px 1px 0px)\"\n }}\n xmlns=\"http://www.w3.org/2000/svg\"\n height=\"24px\"\n viewBox=\"0 -960 960 960\"\n width=\"24px\"\n >\n <path d=\"M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm40-80h480L570-480 450-320l-90-120-120 160Zm-40 80v-560 560Z\" />\n </svg>\n </div>\n );\n};\n\nconst getSrcSet = (src: string, srcSetWidths: number[]) => {\n return srcSetWidths.map(item => `${src}?width=${item} ${item}w`).join(\", \");\n};\n\nconst useImage = ({ inputs, styles }: ImageProps) => {\n const [isLoaded, setIsLoaded] = useState(contentSdk.isEditing() ? false : true);\n const { title = \"\", altText, image } = inputs;\n const src = image?.src;\n\n const tag = src && src.endsWith(\".svg\") ? \"object\" : \"img\";\n\n useEffect(() => {\n if (!src) {\n setIsLoaded(false);\n }\n }, [src]);\n\n // If a fixed image width in pixels was set, let's filter out unneeded\n // image resize widths. For example, if 155px was set as the fixed image\n // width, then we want the `srcset` attribute to only contain 100w and 300w.\n let srcSetWidths: number[] = [];\n\n const width = styles.width?.toString();\n\n if (width && width.endsWith(\"px\")) {\n const imageWidthInt = parseInt(width);\n for (let i = 0; i < SUPPORTED_IMAGE_RESIZE_WIDTHS.length; i++) {\n const supportedResizeWidth = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];\n if (imageWidthInt > supportedResizeWidth) {\n srcSetWidths.push(supportedResizeWidth);\n } else {\n srcSetWidths.push(supportedResizeWidth);\n break;\n }\n }\n } else {\n // If a fixed image width was not provided, we\n // rely on all the supported image resize widths.\n srcSetWidths = SUPPORTED_IMAGE_RESIZE_WIDTHS;\n }\n\n const srcSet = src ? getSrcSet(src, srcSetWidths) : \"\";\n\n const imageStyles = {\n maxWidth: \"100%\",\n opacity: isLoaded ? 1 : 0,\n transition: \"opacity 0.3s ease\",\n ...styles\n };\n\n const onLoad = useCallback(() => {\n if (contentSdk.isEditing()) {\n setTimeout(() => {\n setIsLoaded(true);\n }, 100);\n } else {\n setIsLoaded(true);\n }\n }, []);\n\n return {\n altText,\n isLoaded,\n onLoad,\n src: inputs.image?.src,\n srcSet,\n styles: imageStyles,\n tag,\n title\n };\n};\n"],"names":["SUPPORTED_IMAGE_RESIZE_WIDTHS","ImageComponent","props","image","useImage","ImagePlaceholder","style","getSrcSet","src","srcSetWidths","item","inputs","styles","isLoaded","setIsLoaded","useState","contentSdk","title","altText","tag","useEffect","width","imageWidthInt","parseInt","i","supportedResizeWidth","srcSet","imageStyles","onLoad","useCallback","setTimeout"],"mappings":";;AAKA,MAAMA,gCAAgC;IAAC;IAAK;IAAK;IAAK;IAAK;IAAM;IAAM;CAAK;AAcrE,MAAMC,iBAAiB,CAACC;IAC3B,MAAMC,QAAQC,SAASF;IAEvB,IAAI,CAACC,MAAM,GAAG,EACV,OAAO,WAAP,GAAO,oBAACE,kBAAgBA;QAAC,OAAOH,MAAM,MAAM;;IAGhD,IAAIC,AAAc,aAAdA,MAAM,GAAG,EACT,OAAO,WAAP,GAAO,oBAAC;QAAO,OAAOA,MAAM,MAAM;QAAE,OAAOA,MAAM,KAAK;QAAE,MAAMA,MAAM,GAAG;;IAG3E,OAAO,WAAP,GACI,0CACK,CAACA,MAAM,QA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,IAAIxB,8BAA8B,MAAM,EAAEwB,IAAK;YAC3D,MAAMC,uBAAuBzB,6BAA6B,CAACwB,EAAE;YAC7D,IAAIF,gBAAgBG,sBAChBhB,aAAa,IAAI,CAACgB;iBACf;gBACHhB,aAAa,IAAI,CAACgB;gBAClB;YACJ;QACJ;IACJ,OAGIhB,eAAeT;IAGnB,MAAM0B,SAASlB,MAAMD,UAAUC,KAAKC,gBAAgB;IAEpD,MAAMkB,cAAc;QAChB,UAAU;QACV,SAASd,WAAW,IAAI;QACxB,YAAY;QACZ,GAAGD,MAAM;IACb;IAEA,MAAMgB,SAASC,YAAY;QACvB,IAAIb,WAAW,SAAS,IACpBc,WAAW;YACPhB,YAAY;QAChB,GAAG;aAEHA,YAAY;IAEpB,GAAG,EAAE;IAEL,OAAO;QACHI;QACAL;QACAe;QACA,KAAKjB,OAAO,KAAK,EAAE;QACnBe;QACA,QAAQC;QACRR;QACAF;IACJ;AACJ"}
|
|
@@ -1,41 +1,42 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
2
|
import { createFileInput, createTextInput } from "@webiny/website-builder-sdk";
|
|
4
3
|
import { createComponent } from "../createComponent.js";
|
|
5
4
|
import { ImageComponent } from "./Image.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
5
|
+
const Image = createComponent(ImageComponent, {
|
|
6
|
+
name: "Webiny/Image",
|
|
7
|
+
label: "Image",
|
|
8
|
+
aiContext: "Displays an image from the file manager with configurable title and alt text.",
|
|
9
|
+
group: "basic",
|
|
10
|
+
image: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-4.86 8.86-3 3.87L9 13.14 6 17h12l-3.86-5.14z"/></svg>',
|
|
11
|
+
autoApplyStyles: false,
|
|
12
|
+
inputs: {
|
|
13
|
+
image: createFileInput({
|
|
14
|
+
label: "Image",
|
|
15
|
+
allowedFileTypes: [
|
|
16
|
+
"image/*"
|
|
17
|
+
],
|
|
18
|
+
onChange: ({ inputs })=>{
|
|
19
|
+
if (inputs.image) {
|
|
20
|
+
inputs.title = inputs.image.name;
|
|
21
|
+
inputs.altText = inputs.image.name;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
title: createTextInput({
|
|
26
|
+
label: "Title",
|
|
27
|
+
description: "Title of the image"
|
|
28
|
+
}),
|
|
29
|
+
altText: createTextInput({
|
|
30
|
+
label: "Alternate Text",
|
|
31
|
+
description: "Shown when the user has disabled images"
|
|
32
|
+
})
|
|
33
|
+
},
|
|
34
|
+
defaults: {
|
|
35
|
+
styles: {
|
|
36
|
+
width: "100%"
|
|
22
37
|
}
|
|
23
|
-
}
|
|
24
|
-
}),
|
|
25
|
-
title: createTextInput({
|
|
26
|
-
label: "Title",
|
|
27
|
-
description: "Title of the image"
|
|
28
|
-
}),
|
|
29
|
-
altText: createTextInput({
|
|
30
|
-
label: "Alternate Text",
|
|
31
|
-
description: "Shown when the user has disabled images"
|
|
32
|
-
})
|
|
33
|
-
},
|
|
34
|
-
defaults: {
|
|
35
|
-
styles: {
|
|
36
|
-
width: "100%"
|
|
37
38
|
}
|
|
38
|
-
}
|
|
39
39
|
});
|
|
40
|
+
export { Image };
|
|
40
41
|
|
|
41
42
|
//# sourceMappingURL=Image.manifest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"editorComponents/Image.manifest.js","sources":["../../src/editorComponents/Image.manifest.ts"],"sourcesContent":["\"use client\";\nimport { createFileInput, createTextInput } from \"@webiny/website-builder-sdk\";\nimport { createComponent } from \"~/createComponent.js\";\nimport { ImageComponent } from \"./Image.js\";\n\nexport const Image = createComponent(ImageComponent, {\n name: \"Webiny/Image\",\n label: \"Image\",\n aiContext: \"Displays an image from the file manager with configurable title and alt text.\",\n group: \"basic\",\n image: `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-4.86 8.86-3 3.87L9 13.14 6 17h12l-3.86-5.14z\"/></svg>`,\n autoApplyStyles: false,\n inputs: {\n image: createFileInput({\n label: \"Image\",\n allowedFileTypes: [\"image/*\"],\n onChange: ({ inputs }) => {\n if (inputs.image) {\n inputs.title = inputs.image.name;\n inputs.altText = inputs.image.name;\n }\n }\n }),\n title: createTextInput({\n label: \"Title\",\n description: \"Title of the image\"\n }),\n altText: createTextInput({\n label: \"Alternate Text\",\n description: \"Shown when the user has disabled images\"\n })\n },\n defaults: {\n styles: {\n width: \"100%\"\n }\n }\n});\n"],"names":["Image","createComponent","ImageComponent","createFileInput","inputs","createTextInput"],"mappings":";;;;AAKO,MAAMA,QAAQC,gBAAgBC,gBAAgB;IACjD,MAAM;IACN,OAAO;IACP,WAAW;IACX,OAAO;IACP,OAAO;IACP,iBAAiB;IACjB,QAAQ;QACJ,OAAOC,gBAAgB;YACnB,OAAO;YACP,kBAAkB;gBAAC;aAAU;YAC7B,UAAU,CAAC,EAAEC,MAAM,EAAE;gBACjB,IAAIA,OAAO,KAAK,EAAE;oBACdA,OAAO,KAAK,GAAGA,OAAO,KAAK,CAAC,IAAI;oBAChCA,OAAO,OAAO,GAAGA,OAAO,KAAK,CAAC,IAAI;gBACtC;YACJ;QACJ;QACA,OAAOC,gBAAgB;YACnB,OAAO;YACP,aAAa;QACjB;QACA,SAASA,gBAAgB;YACrB,OAAO;YACP,aAAa;QACjB;IACJ;IACA,UAAU;QACN,QAAQ;YACJ,OAAO;QACX;IACJ;AACJ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ComponentProps } from "../types.js";
|
|
3
|
+
export declare const MainContentComponent: ({ element }: ComponentProps) => React.JSX.Element;
|
|
4
|
+
export declare const NamedContentComponent: ({ inputs, element }: ComponentProps<{
|
|
5
|
+
area?: string;
|
|
6
|
+
}>) => React.JSX.Element;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import react, { useMemo } from "react";
|
|
2
|
+
import { observer } from "mobx-react-lite";
|
|
3
|
+
import { toJS } from "mobx";
|
|
4
|
+
import { LayoutContentArea, withGlobalElementDefaults } from "@webiny/website-builder-sdk";
|
|
5
|
+
import { ElementRenderer } from "../components/ElementRenderer.js";
|
|
6
|
+
import { ElementSlot } from "../components/ElementSlot.js";
|
|
7
|
+
import { DocumentStoreScope, useDocumentStore } from "../components/DocumentStoreProvider.js";
|
|
8
|
+
import { useSeededDocumentStore } from "../components/useSeededDocumentStore.js";
|
|
9
|
+
import { PageScope, ReadOnlyScope, usePageLayout } from "../components/PageLayout.js";
|
|
10
|
+
import { SlotLabel } from "../components/SlotLabel.js";
|
|
11
|
+
import { LayoutAreasProvider, getLayoutAreaContent, useLayoutAreas } from "../components/LayoutAreas.js";
|
|
12
|
+
import { getContentAreaLabel } from "./LayoutContentLabel.js";
|
|
13
|
+
import { useContentClient } from "../components/useContentClient.js";
|
|
14
|
+
const toPreviewDocument = (page, client)=>{
|
|
15
|
+
const document = {
|
|
16
|
+
id: page.id,
|
|
17
|
+
version: 1,
|
|
18
|
+
state: {},
|
|
19
|
+
extensions: {},
|
|
20
|
+
metadata: {},
|
|
21
|
+
properties: page.properties ?? {
|
|
22
|
+
id: page.id
|
|
23
|
+
},
|
|
24
|
+
elements: page.elements ?? {},
|
|
25
|
+
bindings: page.bindings ?? {}
|
|
26
|
+
};
|
|
27
|
+
const withDefaults = withGlobalElementDefaults(document, client.getComponentManifests());
|
|
28
|
+
return {
|
|
29
|
+
...document,
|
|
30
|
+
elements: withDefaults.elements,
|
|
31
|
+
bindings: withDefaults.bindings
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const PageArea = observer(({ area })=>{
|
|
35
|
+
const documentStore = useDocumentStore();
|
|
36
|
+
const slot = area.slot();
|
|
37
|
+
if (area.isMain()) return /*#__PURE__*/ react.createElement(SlotLabel, {
|
|
38
|
+
parentId: "root",
|
|
39
|
+
slot: slot,
|
|
40
|
+
label: getContentAreaLabel(area)
|
|
41
|
+
}, /*#__PURE__*/ react.createElement(ElementRenderer, {
|
|
42
|
+
id: "root"
|
|
43
|
+
}));
|
|
44
|
+
const ids = documentStore.getDocument()?.bindings.root?.inputs?.[slot]?.static;
|
|
45
|
+
return /*#__PURE__*/ react.createElement(SlotLabel, {
|
|
46
|
+
parentId: "root",
|
|
47
|
+
slot: slot,
|
|
48
|
+
label: getContentAreaLabel(area)
|
|
49
|
+
}, /*#__PURE__*/ react.createElement(ElementSlot, {
|
|
50
|
+
parentId: "root",
|
|
51
|
+
slot: slot,
|
|
52
|
+
elements: Array.isArray(ids) ? [
|
|
53
|
+
...ids
|
|
54
|
+
] : []
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
57
|
+
const PreviewPageScope = ({ document, children })=>{
|
|
58
|
+
const store = useSeededDocumentStore(document);
|
|
59
|
+
return /*#__PURE__*/ react.createElement(DocumentStoreScope, {
|
|
60
|
+
store: store
|
|
61
|
+
}, children);
|
|
62
|
+
};
|
|
63
|
+
const PreviewPageContent = ({ pageJson, area })=>{
|
|
64
|
+
const client = useContentClient();
|
|
65
|
+
const document = useMemo(()=>toPreviewDocument(JSON.parse(pageJson), client), [
|
|
66
|
+
pageJson,
|
|
67
|
+
client
|
|
68
|
+
]);
|
|
69
|
+
return /*#__PURE__*/ react.createElement(ReadOnlyScope, null, /*#__PURE__*/ react.createElement(PreviewPageScope, {
|
|
70
|
+
key: document.id,
|
|
71
|
+
document: document
|
|
72
|
+
}, /*#__PURE__*/ react.createElement(PageArea, {
|
|
73
|
+
area: area
|
|
74
|
+
})));
|
|
75
|
+
};
|
|
76
|
+
const Placeholder = ({ area })=>/*#__PURE__*/ react.createElement("div", {
|
|
77
|
+
style: {
|
|
78
|
+
display: "flex",
|
|
79
|
+
minHeight: "200px",
|
|
80
|
+
backgroundColor: "#f4f4f4",
|
|
81
|
+
border: "2px dashed #d0d0d0",
|
|
82
|
+
justifyContent: "center",
|
|
83
|
+
alignItems: "center",
|
|
84
|
+
color: "#6b6b6b"
|
|
85
|
+
}
|
|
86
|
+
}, getContentAreaLabel(area));
|
|
87
|
+
const LayoutEditorContent = observer(({ area })=>{
|
|
88
|
+
const documentStore = useDocumentStore();
|
|
89
|
+
const previewPage = documentStore.getDocument()?.previewPage;
|
|
90
|
+
if (previewPage) return /*#__PURE__*/ react.createElement(PreviewPageContent, {
|
|
91
|
+
pageJson: JSON.stringify(toJS(previewPage)),
|
|
92
|
+
area: area
|
|
93
|
+
});
|
|
94
|
+
return /*#__PURE__*/ react.createElement(Placeholder, {
|
|
95
|
+
area: area
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
const ContentArea = ({ area })=>{
|
|
99
|
+
const client = useContentClient();
|
|
100
|
+
const pageLayout = usePageLayout();
|
|
101
|
+
const layoutAreas = useLayoutAreas();
|
|
102
|
+
if (layoutAreas) return /*#__PURE__*/ react.createElement(PageScope, null, /*#__PURE__*/ react.createElement(LayoutAreasProvider, {
|
|
103
|
+
value: void 0
|
|
104
|
+
}, getLayoutAreaContent(layoutAreas, area)));
|
|
105
|
+
if (pageLayout) return /*#__PURE__*/ react.createElement(PageScope, null, /*#__PURE__*/ react.createElement(PageArea, {
|
|
106
|
+
area: area
|
|
107
|
+
}));
|
|
108
|
+
if (!client.isEditing()) return null;
|
|
109
|
+
return /*#__PURE__*/ react.createElement(LayoutEditorContent, {
|
|
110
|
+
area: area
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
const MainContentComponent = ({ element })=>/*#__PURE__*/ react.createElement(ContentArea, {
|
|
114
|
+
area: LayoutContentArea.fromElement(element)
|
|
115
|
+
});
|
|
116
|
+
const NamedContentComponent = ({ inputs, element })=>/*#__PURE__*/ react.createElement(ContentArea, {
|
|
117
|
+
area: LayoutContentArea.fromElement(element, inputs?.area)
|
|
118
|
+
});
|
|
119
|
+
export { MainContentComponent, NamedContentComponent };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=LayoutContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editorComponents/LayoutContent.js","sources":["../../src/editorComponents/LayoutContent.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { toJS } from \"mobx\";\nimport {\n type ContentClient,\n type Document,\n LayoutContentArea,\n type PreviewPage,\n withGlobalElementDefaults\n} from \"@webiny/website-builder-sdk\";\nimport { ElementRenderer } from \"~/components/ElementRenderer.js\";\nimport { ElementSlot } from \"~/components/ElementSlot.js\";\nimport type { ComponentProps } from \"~/types.js\";\nimport { DocumentStoreScope, useDocumentStore } from \"~/components/DocumentStoreProvider.js\";\nimport { useSeededDocumentStore } from \"~/components/useSeededDocumentStore.js\";\nimport { PageScope, ReadOnlyScope, usePageLayout } from \"~/components/PageLayout.js\";\nimport { SlotLabel } from \"~/components/SlotLabel.js\";\nimport {\n getLayoutAreaContent,\n LayoutAreasProvider,\n useLayoutAreas\n} from \"~/components/LayoutAreas.js\";\nimport { getContentAreaLabel } from \"./LayoutContentLabel.js\";\nimport { useContentClient } from \"~/components/useContentClient.js\";\n\nconst toPreviewDocument = (page: PreviewPage, client: ContentClient): Document => {\n const document: Document = {\n id: page.id,\n version: 1,\n state: {},\n extensions: {},\n metadata: {},\n properties: page.properties ?? { id: page.id },\n elements: page.elements ?? {},\n bindings: page.bindings ?? {}\n };\n\n // Globals the page has no stored instance of render from their manifest defaults, as on the live site.\n const withDefaults = withGlobalElementDefaults(document, client.getComponentManifests());\n return { ...document, elements: withDefaults.elements, bindings: withDefaults.bindings };\n};\n\n/**\n * The page's content of one area. The main area is the page root, as on a page without a layout; the\n * others are slots of the page root. In the page editor, each is a place to drop content.\n */\nconst PageArea = observer(({ area }: { area: LayoutContentArea }) => {\n const documentStore = useDocumentStore();\n const slot = area.slot();\n\n // While an area is empty, its drop area in the page editor says which one it is.\n if (area.isMain()) {\n return (\n <SlotLabel parentId={\"root\"} slot={slot} label={getContentAreaLabel(area)}>\n <ElementRenderer id={\"root\"} />\n </SlotLabel>\n );\n }\n\n const ids = documentStore.getDocument()?.bindings.root?.inputs?.[slot]?.static;\n\n return (\n <SlotLabel parentId={\"root\"} slot={slot} label={getContentAreaLabel(area)}>\n <ElementSlot\n parentId={\"root\"}\n slot={slot}\n elements={Array.isArray(ids) ? [...ids] : []}\n />\n </SlotLabel>\n );\n});\n\nconst PreviewPageScope = ({\n document,\n children\n}: {\n document: Document;\n children: React.ReactNode;\n}) => {\n const store = useSeededDocumentStore(document);\n\n return <DocumentStoreScope store={store}>{children}</DocumentStoreScope>;\n};\n\n/**\n * In the layout editor, the page picked to preview the layout with: shown in place of the page content,\n * as on the live site. It can't be selected; it belongs to the page, not to the layout.\n */\nconst PreviewPageContent = ({ pageJson, area }: { pageJson: string; area: LayoutContentArea }) => {\n const client = useContentClient();\n const document = useMemo(\n () => toPreviewDocument(JSON.parse(pageJson), client),\n [pageJson, client]\n );\n\n // Keyed by page: picking another page renders it from scratch. Its elements share ids with the previous\n // page's (\"root\"), so they would otherwise keep what they had read from the previous page.\n return (\n <ReadOnlyScope>\n <PreviewPageScope key={document.id} document={document}>\n <PageArea area={area} />\n </PreviewPageScope>\n </ReadOnlyScope>\n );\n};\n\nconst Placeholder = ({ area }: { area: LayoutContentArea }) => {\n return (\n <div\n style={{\n display: \"flex\",\n minHeight: \"200px\",\n backgroundColor: \"#f4f4f4\",\n border: \"2px dashed #d0d0d0\",\n justifyContent: \"center\",\n alignItems: \"center\",\n color: \"#6b6b6b\"\n }}\n >\n {getContentAreaLabel(area)}\n </div>\n );\n};\n\nconst LayoutEditorContent = observer(({ area }: { area: LayoutContentArea }) => {\n const documentStore = useDocumentStore();\n const previewPage = documentStore.getDocument()?.previewPage;\n\n if (previewPage) {\n return <PreviewPageContent pageJson={JSON.stringify(toJS(previewPage))} area={area} />;\n }\n\n return <Placeholder area={area} />;\n});\n\n/**\n * A page content area: where a page renders its own content of that area inside a layout. In the layout\n * editor, there is no page: it shows a placeholder, or the page picked to preview the layout with.\n */\nconst ContentArea = ({ area }: { area: LayoutContentArea }) => {\n const client = useContentClient();\n const pageLayout = usePageLayout();\n const layoutAreas = useLayoutAreas();\n\n // Content from code rendered in the layout (see <LayoutRenderer>). It's not part of the layout, so\n // nothing of the layout is around it any more.\n if (layoutAreas) {\n return (\n <PageScope>\n <LayoutAreasProvider value={undefined}>\n {getLayoutAreaContent(layoutAreas, area)}\n </LayoutAreasProvider>\n </PageScope>\n );\n }\n\n if (pageLayout) {\n return (\n <PageScope>\n <PageArea area={area} />\n </PageScope>\n );\n }\n\n if (!client.isEditing()) {\n return null;\n }\n\n return <LayoutEditorContent area={area} />;\n};\n\nexport const MainContentComponent = ({ element }: ComponentProps) => {\n return <ContentArea area={LayoutContentArea.fromElement(element)} />;\n};\n\nexport const NamedContentComponent = ({ inputs, element }: ComponentProps<{ area?: string }>) => {\n return <ContentArea area={LayoutContentArea.fromElement(element, inputs?.area)} />;\n};\n"],"names":["toPreviewDocument","page","client","document","withDefaults","withGlobalElementDefaults","PageArea","observer","area","documentStore","useDocumentStore","slot","SlotLabel","getContentAreaLabel","ElementRenderer","ids","ElementSlot","Array","PreviewPageScope","children","store","useSeededDocumentStore","DocumentStoreScope","PreviewPageContent","pageJson","useContentClient","useMemo","JSON","ReadOnlyScope","Placeholder","LayoutEditorContent","previewPage","toJS","ContentArea","pageLayout","usePageLayout","layoutAreas","useLayoutAreas","PageScope","LayoutAreasProvider","undefined","getLayo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;AACtC;AAEO,MAAMkC,uBAAuB,CAAC,EAAEC,OAAO,EAAkB,GACrD,WAAP,GAAO,oBAACV,aAAWA;QAAC,MAAMW,kBAAkB,WAAW,CAACD;;AAGrD,MAAME,wBAAwB,CAAC,EAAEC,MAAM,EAAEH,OAAO,EAAqC,GACjF,WAAP,GAAO,oBAACV,aAAWA;QAAC,MAAMW,kBAAkB,WAAW,CAACD,SAASG,QAAQ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The main page content area of a layout. Every layout starts with it, and keeps it: it can be moved and
|
|
3
|
+
* styled, but not deleted, renamed or inserted again.
|
|
4
|
+
*/
|
|
5
|
+
export declare const LayoutContent: import("@webiny/website-builder-sdk").Component;
|
|
6
|
+
/**
|
|
7
|
+
* A named page content area, inserted in the layout editor (only there). Pages fill each named area in
|
|
8
|
+
* the page editor.
|
|
9
|
+
*/
|
|
10
|
+
export declare const NamedContent: import("@webiny/website-builder-sdk").Component;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { LayoutContentArea, createTextInput } from "@webiny/website-builder-sdk";
|
|
3
|
+
import { createComponent } from "../createComponent.js";
|
|
4
|
+
import { MainContentComponent, NamedContentComponent } from "./LayoutContent.js";
|
|
5
|
+
const LayoutContent_manifest_image = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M3 5v14h18V5H3zm16 12H5V7h14v10zM7 9h10v2H7V9zm0 4h7v2H7v-2z"/></svg>';
|
|
6
|
+
const LayoutContent = createComponent(MainContentComponent, {
|
|
7
|
+
name: LayoutContentArea.MAIN_COMPONENT,
|
|
8
|
+
label: "Main content",
|
|
9
|
+
group: "basic",
|
|
10
|
+
hideFromToolbar: true,
|
|
11
|
+
useInAiContentGeneration: false,
|
|
12
|
+
inputs: [],
|
|
13
|
+
image: LayoutContent_manifest_image
|
|
14
|
+
});
|
|
15
|
+
const NamedContent = createComponent(NamedContentComponent, {
|
|
16
|
+
name: LayoutContentArea.NAMED_COMPONENT,
|
|
17
|
+
label: "Named content",
|
|
18
|
+
group: "basic",
|
|
19
|
+
useInAiContentGeneration: false,
|
|
20
|
+
inputs: [
|
|
21
|
+
createTextInput({
|
|
22
|
+
name: LayoutContentArea.NAME_INPUT,
|
|
23
|
+
label: "Area name",
|
|
24
|
+
translatable: false,
|
|
25
|
+
description: "Shown in the page editor so authors can tell the areas apart. Renaming an area keeps the content pages added to it."
|
|
26
|
+
})
|
|
27
|
+
],
|
|
28
|
+
image: LayoutContent_manifest_image
|
|
29
|
+
});
|
|
30
|
+
export { LayoutContent, NamedContent };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=LayoutContent.manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editorComponents/LayoutContent.manifest.js","sources":["../../src/editorComponents/LayoutContent.manifest.ts"],"sourcesContent":["\"use client\";\nimport { createTextInput, LayoutContentArea } from \"@webiny/website-builder-sdk\";\nimport { createComponent } from \"~/createComponent.js\";\nimport { MainContentComponent, NamedContentComponent } from \"./LayoutContent.js\";\n\nconst image = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M3 5v14h18V5H3zm16 12H5V7h14v10zM7 9h10v2H7V9zm0 4h7v2H7v-2z\"/></svg>`;\n\n/**\n * The main page content area of a layout. Every layout starts with it, and keeps it: it can be moved and\n * styled, but not deleted, renamed or inserted again.\n */\nexport const LayoutContent = createComponent(MainContentComponent, {\n name: LayoutContentArea.MAIN_COMPONENT,\n label: \"Main content\",\n group: \"basic\",\n hideFromToolbar: true,\n useInAiContentGeneration: false,\n inputs: [],\n image\n});\n\n/**\n * A named page content area, inserted in the layout editor (only there). Pages fill each named area in\n * the page editor.\n */\nexport const NamedContent = createComponent(NamedContentComponent, {\n name: LayoutContentArea.NAMED_COMPONENT,\n label: \"Named content\",\n group: \"basic\",\n useInAiContentGeneration: false,\n inputs: [\n createTextInput({\n name: LayoutContentArea.NAME_INPUT,\n label: \"Area name\",\n // A label for people: pages' content of the area is stored by the area element's id.\n translatable: false,\n description:\n \"Shown in the page editor so authors can tell the areas apart. Renaming an area keeps the content pages added to it.\"\n })\n ],\n image\n});\n"],"names":["image","LayoutContent","createComponent","MainContentComponent","LayoutContentArea","NamedContent","NamedContentComponent","createTextInput"],"mappings":";;;;AAKA,MAAMA,+BAAQ;AAMP,MAAMC,gBAAgBC,gBAAgBC,sBAAsB;IAC/D,MAAMC,kBAAkB,cAAc;IACtC,OAAO;IACP,OAAO;IACP,iBAAiB;IACjB,0BAA0B;IAC1B,QAAQ,EAAE;IACVJ,OAAAA;AACJ;AAMO,MAAMK,eAAeH,gBAAgBI,uBAAuB;IAC/D,MAAMF,kBAAkB,eAAe;IACvC,OAAO;IACP,OAAO;IACP,0BAA0B;IAC1B,QAAQ;QACJG,gBAAgB;YACZ,MAAMH,kBAAkB,UAAU;YAClC,OAAO;YAEP,cAAc;YACd,aACI;QACR;KACH;IACDJ,OAAAA;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editorComponents/LayoutContentLabel.js","sources":["../../src/editorComponents/LayoutContentLabel.ts"],"sourcesContent":["import type { LayoutContentArea } from \"@webiny/website-builder-sdk\";\n\n// What a content area is called on the canvas. Its name is only a label: content is stored by its slot.\nexport const getContentAreaLabel = (area: LayoutContentArea) => {\n if (area.isMain()) {\n return \"Main content\";\n }\n return area.name() ?? \"Named content\";\n};\n"],"names":["getContentAreaLabel","area"],"mappings":"AAGO,MAAMA,sBAAsB,CAACC;IAChC,IAAIA,KAAK,MAAM,IACX,OAAO;IAEX,OAAOA,KAAK,IAAI,MAAM;AAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { LayoutContentArea } from "@webiny/website-builder-sdk";
|
|
3
|
+
import { getContentAreaLabel } from "./LayoutContentLabel.js";
|
|
4
|
+
const LayoutContentLabel_test_element = (id, name)=>({
|
|
5
|
+
id,
|
|
6
|
+
component: {
|
|
7
|
+
name
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
describe("getContentAreaLabel", ()=>{
|
|
11
|
+
it('labels the main content area "Main content", and a named one by its own name, with no "Named content ·" prefix', ()=>{
|
|
12
|
+
const main = LayoutContentArea.fromElement(LayoutContentLabel_test_element("content", "Webiny/LayoutContent"));
|
|
13
|
+
const named = LayoutContentArea.fromElement(LayoutContentLabel_test_element("sidebar", "Webiny/NamedContent"), "sidebar");
|
|
14
|
+
expect(getContentAreaLabel(main)).toBe("Main content");
|
|
15
|
+
expect(getContentAreaLabel(named)).toBe("sidebar");
|
|
16
|
+
});
|
|
17
|
+
it('labels a named content area without a name "Named content"', ()=>{
|
|
18
|
+
const area = LayoutContentArea.fromElement(LayoutContentLabel_test_element("area", "Webiny/NamedContent"), " ");
|
|
19
|
+
expect(getContentAreaLabel(area)).toBe("Named content");
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=LayoutContentLabel.test.js.map
|