@sitecore-content-sdk/react 1.3.0-canary.9 → 1.4.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/dist/cjs/components/ClientEditingChromesUpdate.js +53 -52
- package/dist/cjs/components/Date.js +49 -45
- package/dist/cjs/components/DefaultEmptyFieldEditingComponents.js +32 -22
- package/dist/cjs/components/{DesignLibrary.js → DesignLibrary/DesignLibrary.js} +161 -202
- package/dist/cjs/components/DesignLibrary/DesignLibraryApp.js +31 -0
- package/dist/cjs/components/DesignLibrary/DesignLibraryClientEvents.js +123 -0
- package/dist/cjs/components/DesignLibrary/DesignLibraryErrorBoundary.js +65 -0
- package/dist/cjs/components/DesignLibrary/DesignLibraryServer.js +193 -0
- package/dist/cjs/components/DesignLibrary/index.js +7 -0
- package/dist/cjs/components/DesignLibrary/models.js +2 -0
- package/dist/cjs/components/EditingScripts.js +44 -43
- package/dist/cjs/components/ErrorBoundary.js +101 -92
- package/dist/cjs/components/FEaaS/BYOCServerWrapper.js +25 -28
- package/dist/cjs/components/FEaaS/BYOCWrapper.js +133 -122
- package/dist/cjs/components/FEaaS/FEaaSSeverWrapper.js +26 -34
- package/dist/cjs/components/FEaaS/FEaaSWrapper.js +84 -78
- package/dist/cjs/components/FEaaS/feaas-utils.js +130 -144
- package/dist/cjs/components/FEaaS/index.js +21 -21
- package/dist/cjs/components/FEaaS/models.js +7 -7
- package/dist/cjs/components/FieldMetadata.js +29 -29
- package/dist/cjs/components/File.js +43 -38
- package/dist/cjs/components/Form.js +100 -92
- package/dist/cjs/components/HiddenRendering.js +23 -23
- package/dist/cjs/components/Image.js +71 -66
- package/dist/cjs/components/Link.js +91 -86
- package/dist/cjs/components/MissingComponent.js +28 -28
- package/dist/cjs/components/Placeholder/AppPlaceholder.js +79 -76
- package/dist/cjs/components/Placeholder/ClientComponentWrapper.js +21 -21
- package/dist/cjs/components/Placeholder/Placeholder.js +144 -110
- package/dist/cjs/components/Placeholder/PlaceholderMetadata.js +68 -63
- package/dist/cjs/components/Placeholder/index.js +25 -25
- package/dist/cjs/components/Placeholder/models.js +18 -18
- package/dist/cjs/components/Placeholder/placeholder-utils.js +226 -226
- package/dist/cjs/components/RichText.js +75 -70
- package/dist/cjs/components/SitecoreProvider.js +62 -52
- package/dist/cjs/components/Text.js +69 -65
- package/dist/cjs/components/sharedTypes/components.js +7 -7
- package/dist/cjs/components/sharedTypes/index.js +18 -18
- package/dist/cjs/components/sharedTypes/props.js +2 -2
- package/dist/cjs/enhancers/withAppPlaceholder.js +21 -21
- package/dist/cjs/enhancers/withComponentMap.js +24 -24
- package/dist/cjs/enhancers/withDatasourceCheck.js +31 -30
- package/dist/cjs/enhancers/withEditorChromes.js +29 -24
- package/dist/cjs/enhancers/withEmptyFieldEditingComponent.js +71 -70
- package/dist/cjs/enhancers/withFieldMetadata.js +68 -67
- package/dist/cjs/enhancers/withLoadImportMap.js +53 -0
- package/dist/cjs/enhancers/withPlaceholder.js +64 -65
- package/dist/cjs/enhancers/withSitecore.js +47 -45
- package/dist/cjs/index.js +86 -85
- package/dist/cjs/rsc-utils/no-rsc.js +5 -5
- package/dist/cjs/rsc-utils/rsc.js +5 -5
- package/dist/cjs/search/index.js +7 -0
- package/dist/cjs/search/useInfiniteSearch.js +136 -0
- package/dist/cjs/search/useSearch.js +107 -0
- package/dist/cjs/search/utils.js +35 -0
- package/dist/cjs/server-actions/update-server-component-action.js +18 -0
- package/dist/cjs/utils.js +38 -38
- package/dist/esm/components/ClientEditingChromesUpdate.js +16 -15
- package/dist/esm/components/Date.js +43 -39
- package/dist/esm/components/DefaultEmptyFieldEditingComponents.js +24 -14
- package/dist/esm/components/{DesignLibrary.js → DesignLibrary/DesignLibrary.js} +124 -164
- package/dist/esm/components/DesignLibrary/DesignLibraryApp.js +24 -0
- package/dist/esm/components/DesignLibrary/DesignLibraryClientEvents.js +84 -0
- package/dist/esm/components/DesignLibrary/DesignLibraryErrorBoundary.js +28 -0
- package/dist/esm/components/DesignLibrary/DesignLibraryServer.js +150 -0
- package/dist/esm/components/DesignLibrary/index.js +2 -0
- package/dist/esm/components/DesignLibrary/models.js +1 -0
- package/dist/esm/components/EditingScripts.js +37 -36
- package/dist/esm/components/ErrorBoundary.js +64 -57
- package/dist/esm/components/FEaaS/BYOCServerWrapper.js +18 -21
- package/dist/esm/components/FEaaS/BYOCWrapper.js +91 -81
- package/dist/esm/components/FEaaS/FEaaSSeverWrapper.js +19 -27
- package/dist/esm/components/FEaaS/FEaaSWrapper.js +43 -37
- package/dist/esm/components/FEaaS/feaas-utils.js +91 -105
- package/dist/esm/components/FEaaS/index.js +6 -6
- package/dist/esm/components/FEaaS/models.js +4 -4
- package/dist/esm/components/FieldMetadata.js +22 -22
- package/dist/esm/components/File.js +36 -31
- package/dist/esm/components/Form.js +62 -54
- package/dist/esm/components/HiddenRendering.js +16 -16
- package/dist/esm/components/Image.js +65 -60
- package/dist/esm/components/Link.js +55 -50
- package/dist/esm/components/MissingComponent.js +21 -21
- package/dist/esm/components/Placeholder/AppPlaceholder.js +72 -69
- package/dist/esm/components/Placeholder/ClientComponentWrapper.js +14 -14
- package/dist/esm/components/Placeholder/Placeholder.js +104 -103
- package/dist/esm/components/Placeholder/PlaceholderMetadata.js +61 -56
- package/dist/esm/components/Placeholder/index.js +4 -4
- package/dist/esm/components/Placeholder/models.js +15 -15
- package/dist/esm/components/Placeholder/placeholder-utils.js +214 -214
- package/dist/esm/components/RichText.js +39 -34
- package/dist/esm/components/SitecoreProvider.js +55 -45
- package/dist/esm/components/Text.js +63 -59
- package/dist/esm/components/sharedTypes/components.js +4 -4
- package/dist/esm/components/sharedTypes/index.js +2 -2
- package/dist/esm/components/sharedTypes/props.js +1 -1
- package/dist/esm/enhancers/withAppPlaceholder.js +14 -14
- package/dist/esm/enhancers/withComponentMap.js +18 -18
- package/dist/esm/enhancers/withDatasourceCheck.js +23 -22
- package/dist/esm/enhancers/withEditorChromes.js +22 -17
- package/dist/esm/enhancers/withEmptyFieldEditingComponent.js +35 -34
- package/dist/esm/enhancers/withFieldMetadata.js +32 -31
- package/dist/esm/enhancers/withLoadImportMap.js +17 -0
- package/dist/esm/enhancers/withPlaceholder.js +58 -59
- package/dist/esm/enhancers/withSitecore.js +40 -38
- package/dist/esm/index.js +29 -29
- package/dist/esm/rsc-utils/no-rsc.js +2 -2
- package/dist/esm/rsc-utils/rsc.js +2 -2
- package/dist/esm/search/index.js +2 -0
- package/dist/esm/search/useInfiniteSearch.js +132 -0
- package/dist/esm/search/useSearch.js +103 -0
- package/dist/esm/search/utils.js +30 -0
- package/dist/esm/server-actions/update-server-component-action.js +15 -0
- package/dist/esm/utils.js +33 -33
- package/global.d.ts +17 -0
- package/package.json +27 -11
- package/search.d.ts +1 -0
- package/types/components/ClientEditingChromesUpdate.d.ts +8 -6
- package/types/components/ClientEditingChromesUpdate.d.ts.map +1 -0
- package/types/components/Date.d.ts +25 -16
- package/types/components/Date.d.ts.map +1 -0
- package/types/components/DefaultEmptyFieldEditingComponents.d.ts +20 -9
- package/types/components/DefaultEmptyFieldEditingComponents.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibrary.d.ts +20 -0
- package/types/components/DesignLibrary/DesignLibrary.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryApp.d.ts +14 -0
- package/types/components/DesignLibrary/DesignLibraryApp.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts +21 -0
- package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryErrorBoundary.d.ts +19 -0
- package/types/components/DesignLibrary/DesignLibraryErrorBoundary.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryServer.d.ts +38 -0
- package/types/components/DesignLibrary/DesignLibraryServer.d.ts.map +1 -0
- package/types/components/DesignLibrary/index.d.ts +3 -0
- package/types/components/DesignLibrary/index.d.ts.map +1 -0
- package/types/components/DesignLibrary/models.d.ts +67 -0
- package/types/components/DesignLibrary/models.d.ts.map +1 -0
- package/types/components/EditingScripts.d.ts +9 -7
- package/types/components/EditingScripts.d.ts.map +1 -0
- package/types/components/ErrorBoundary.d.ts +29 -17
- package/types/components/ErrorBoundary.d.ts.map +1 -0
- package/types/components/FEaaS/BYOCServerWrapper.d.ts +10 -3
- package/types/components/FEaaS/BYOCServerWrapper.d.ts.map +1 -0
- package/types/components/FEaaS/BYOCWrapper.d.ts +29 -25
- package/types/components/FEaaS/BYOCWrapper.d.ts.map +1 -0
- package/types/components/FEaaS/FEaaSSeverWrapper.d.ts +10 -8
- package/types/components/FEaaS/FEaaSSeverWrapper.d.ts.map +1 -0
- package/types/components/FEaaS/FEaaSWrapper.d.ts +14 -7
- package/types/components/FEaaS/FEaaSWrapper.d.ts.map +1 -0
- package/types/components/FEaaS/feaas-utils.d.ts +24 -21
- package/types/components/FEaaS/feaas-utils.d.ts.map +1 -0
- package/types/components/FEaaS/index.d.ts +7 -6
- package/types/components/FEaaS/index.d.ts.map +1 -0
- package/types/components/FEaaS/models.d.ts +136 -125
- package/types/components/FEaaS/models.d.ts.map +1 -0
- package/types/components/FieldMetadata.d.ts +18 -17
- package/types/components/FieldMetadata.d.ts.map +1 -0
- package/types/components/File.d.ts +28 -18
- package/types/components/File.d.ts.map +1 -0
- package/types/components/Form.d.ts +35 -29
- package/types/components/Form.d.ts.map +1 -0
- package/types/components/HiddenRendering.d.ts +3 -2
- package/types/components/HiddenRendering.d.ts.map +1 -0
- package/types/components/Image.d.ts +70 -48
- package/types/components/Image.d.ts.map +1 -0
- package/types/components/Link.d.ts +45 -27
- package/types/components/Link.d.ts.map +1 -0
- package/types/components/MissingComponent.d.ts +9 -8
- package/types/components/MissingComponent.d.ts.map +1 -0
- package/types/components/Placeholder/AppPlaceholder.d.ts +12 -10
- package/types/components/Placeholder/AppPlaceholder.d.ts.map +1 -0
- package/types/components/Placeholder/ClientComponentWrapper.d.ts +10 -9
- package/types/components/Placeholder/ClientComponentWrapper.d.ts.map +1 -0
- package/types/components/Placeholder/Placeholder.d.ts +33 -28
- package/types/components/Placeholder/Placeholder.d.ts.map +1 -0
- package/types/components/Placeholder/PlaceholderMetadata.d.ts +35 -28
- package/types/components/Placeholder/PlaceholderMetadata.d.ts.map +1 -0
- package/types/components/Placeholder/index.d.ts +6 -5
- package/types/components/Placeholder/index.d.ts.map +1 -0
- package/types/components/Placeholder/models.d.ts +149 -140
- package/types/components/Placeholder/models.d.ts.map +1 -0
- package/types/components/Placeholder/placeholder-utils.d.ts +52 -53
- package/types/components/Placeholder/placeholder-utils.d.ts.map +1 -0
- package/types/components/RichText.d.ts +31 -17
- package/types/components/RichText.d.ts.map +1 -0
- package/types/components/SitecoreProvider.d.ts +68 -48
- package/types/components/SitecoreProvider.d.ts.map +1 -0
- package/types/components/Text.d.ts +29 -20
- package/types/components/Text.d.ts.map +1 -0
- package/types/components/sharedTypes/components.d.ts +50 -38
- package/types/components/sharedTypes/components.d.ts.map +1 -0
- package/types/components/sharedTypes/index.d.ts +3 -2
- package/types/components/sharedTypes/index.d.ts.map +1 -0
- package/types/components/sharedTypes/props.d.ts +15 -14
- package/types/components/sharedTypes/props.d.ts.map +1 -0
- package/types/enhancers/withAppPlaceholder.d.ts +16 -15
- package/types/enhancers/withAppPlaceholder.d.ts.map +1 -0
- package/types/enhancers/withComponentMap.d.ts +13 -12
- package/types/enhancers/withComponentMap.d.ts.map +1 -0
- package/types/enhancers/withDatasourceCheck.d.ts +23 -21
- package/types/enhancers/withDatasourceCheck.d.ts.map +1 -0
- package/types/enhancers/withEditorChromes.d.ts +8 -2
- package/types/enhancers/withEditorChromes.d.ts.map +1 -0
- package/types/enhancers/withEmptyFieldEditingComponent.d.ts +29 -27
- package/types/enhancers/withEmptyFieldEditingComponent.d.ts.map +1 -0
- package/types/enhancers/withFieldMetadata.d.ts +18 -16
- package/types/enhancers/withFieldMetadata.d.ts.map +1 -0
- package/types/enhancers/withLoadImportMap.d.ts +22 -0
- package/types/enhancers/withLoadImportMap.d.ts.map +1 -0
- package/types/enhancers/withPlaceholder.d.ts +37 -35
- package/types/enhancers/withPlaceholder.d.ts.map +1 -0
- package/types/enhancers/withSitecore.d.ts +63 -48
- package/types/enhancers/withSitecore.d.ts.map +1 -0
- package/types/index.d.ts +31 -30
- package/types/index.d.ts.map +1 -0
- package/types/rsc-utils/no-rsc.d.ts +2 -1
- package/types/rsc-utils/no-rsc.d.ts.map +1 -0
- package/types/rsc-utils/rsc.d.ts +2 -1
- package/types/rsc-utils/rsc.d.ts.map +1 -0
- package/types/search/index.d.ts +4 -0
- package/types/search/index.d.ts.map +1 -0
- package/types/search/useInfiniteSearch.d.ts +116 -0
- package/types/search/useInfiniteSearch.d.ts.map +1 -0
- package/types/search/useSearch.d.ts +107 -0
- package/types/search/useSearch.d.ts.map +1 -0
- package/types/search/utils.d.ts +19 -0
- package/types/search/utils.d.ts.map +1 -0
- package/types/server-actions/update-server-component-action.d.ts +25 -0
- package/types/server-actions/update-server-component-action.d.ts.map +1 -0
- package/types/utils.d.ts +18 -17
- package/types/utils.d.ts.map +1 -0
- package/types/components/DesignLibrary.d.ts +0 -26
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import React from 'react';
|
|
13
|
-
import { withFieldMetadata } from '../enhancers/withFieldMetadata';
|
|
14
|
-
import { withEmptyFieldEditingComponent } from '../enhancers/withEmptyFieldEditingComponent';
|
|
15
|
-
import { DefaultEmptyFieldEditingComponentText } from './DefaultEmptyFieldEditingComponents';
|
|
16
|
-
import { isFieldValueEmpty } from '@sitecore-content-sdk/core/layout';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { withFieldMetadata } from '../enhancers/withFieldMetadata';
|
|
14
|
+
import { withEmptyFieldEditingComponent } from '../enhancers/withEmptyFieldEditingComponent';
|
|
15
|
+
import { DefaultEmptyFieldEditingComponentText } from './DefaultEmptyFieldEditingComponents';
|
|
16
|
+
import { isFieldValueEmpty } from '@sitecore-content-sdk/core/layout';
|
|
17
|
+
/**
|
|
18
|
+
* The DateField component.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export const DateField = withFieldMetadata(withEmptyFieldEditingComponent(
|
|
22
|
+
// eslint-disable-next-line no-unused-vars
|
|
23
|
+
(_a) => {
|
|
24
|
+
var { field, tag, editable = true, render } = _a, otherProps = __rest(_a, ["field", "tag", "editable", "render"]);
|
|
25
|
+
if (isFieldValueEmpty(field)) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
let children;
|
|
29
|
+
const htmlProps = Object.assign({}, otherProps);
|
|
30
|
+
if (render) {
|
|
31
|
+
children = render(field.value ? new Date(field.value) : null);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
children = field.value;
|
|
35
|
+
}
|
|
36
|
+
if (tag) {
|
|
37
|
+
return React.createElement(tag || 'span', htmlProps, children);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return React.createElement(React.Fragment, null, children);
|
|
41
|
+
}
|
|
42
|
+
}, { defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText }));
|
|
43
|
+
DateField.displayName = 'Date';
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The DefaultEmptyFieldEditingComponentText component.
|
|
4
|
+
* @param {object} props - The props for the component.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export const DefaultEmptyFieldEditingComponentText = (props) => {
|
|
8
|
+
return React.createElement(props.tag || 'span', props, '[No text in field]');
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The DefaultEmptyFieldEditingComponentImage component.
|
|
12
|
+
* @param {object} props - The props for the component.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export const DefaultEmptyFieldEditingComponentImage = (props) => {
|
|
16
|
+
const inlineStyles = {
|
|
17
|
+
minWidth: '48px',
|
|
18
|
+
minHeight: '48px',
|
|
19
|
+
maxWidth: '400px',
|
|
20
|
+
maxHeight: '400px',
|
|
21
|
+
cursor: 'pointer',
|
|
22
|
+
};
|
|
23
|
+
return (React.createElement("img", Object.assign({}, props, { alt: "", src: 'data:image/svg+xml,%3Csvg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 240 240" style="enable-background:new 0 0 240 240;" xml:space="preserve"%3E%3Cstyle type="text/css"%3E .st0%7Bfill:none;%7D .st1%7Bfill:%23969696;%7D .st2%7Bfill:%23FFFFFF;%7D .st3%7Bfill:%23FFFFFF;stroke:%23FFFFFF;stroke-width:0.75;stroke-miterlimit:10;%7D%0A%3C/style%3E%3Cg%3E%3Crect class="st0" width="240" height="240"/%3E%3Cg%3E%3Cg%3E%3Crect x="20" y="20" class="st1" width="200" height="200"/%3E%3C/g%3E%3Cg%3E%3Ccircle class="st2" cx="174" cy="67" r="14"/%3E%3Cpath class="st2" d="M174,54c7.17,0,13,5.83,13,13s-5.83,13-13,13s-13-5.83-13-13S166.83,54,174,54 M174,52 c-8.28,0-15,6.72-15,15s6.72,15,15,15s15-6.72,15-15S182.28,52,174,52L174,52z"/%3E%3C/g%3E%3Cpolyline class="st3" points="29.5,179.25 81.32,122.25 95.41,137.75 137.23,91.75 209.5,179.75 "/%3E%3C/g%3E%3C/g%3E%3C/svg%3E', className: `scEmptyImage ${props.className || ''}`, style: inlineStyles })));
|
|
24
|
+
};
|
|
@@ -1,164 +1,124 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
let unsubscribe;
|
|
126
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
-
if (!loadImportMap) {
|
|
128
|
-
sendErrorEvent(rendering.uid, 'No loadImportMap provided', codegen.DesignLibraryPreviewError.RenderInit);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
let importMap;
|
|
132
|
-
try {
|
|
133
|
-
const mod = yield loadImportMap();
|
|
134
|
-
importMap = mod.default;
|
|
135
|
-
}
|
|
136
|
-
catch (e) {
|
|
137
|
-
sendErrorEvent(rendering.uid, `Error loading import map: ${e}`, codegen.DesignLibraryPreviewError.RenderInit);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
// account for component being unmounted while resolving async import map
|
|
141
|
-
if (cancelled)
|
|
142
|
-
return;
|
|
143
|
-
unsubscribe = addComponentPreviewHandler(importMap, (error, Component) => {
|
|
144
|
-
// Error event is already sent in the addComponentPreviewHandler
|
|
145
|
-
if (error)
|
|
146
|
-
return;
|
|
147
|
-
setComponent(() => Component);
|
|
148
|
-
setRenderKey((k) => k + 1);
|
|
149
|
-
});
|
|
150
|
-
const importMapEvent = getDesignLibraryImportMapEvent(rendering.uid, importMap);
|
|
151
|
-
postToDL(importMapEvent);
|
|
152
|
-
const propsEvent = getDesignLibraryComponentPropsEvent(rendering.uid, propsState.fields, propsState.params);
|
|
153
|
-
postToDL(propsEvent);
|
|
154
|
-
}))();
|
|
155
|
-
// return function that calls unsubscribe - if the component was mounted correctly
|
|
156
|
-
return () => {
|
|
157
|
-
cancelled = true;
|
|
158
|
-
unsubscribe && unsubscribe();
|
|
159
|
-
};
|
|
160
|
-
}, [isVariantGeneration, rendering]);
|
|
161
|
-
return (React.createElement("main", null, isGeneratedComponentActive ? (React.createElement(ErrorBoundary, { uid: rendering.uid, renderKey: renderKey },
|
|
162
|
-
React.createElement(PlaceholderMetadata, { rendering: rendering },
|
|
163
|
-
React.createElement(Component, { fields: propsState.fields, params: propsState.params, key: renderKey })))) : (React.createElement("div", { id: EDITING_COMPONENT_ID }, route && (React.createElement(Placeholder, { name: EDITING_COMPONENT_PLACEHOLDER, rendering: route, key: renderKey }))))));
|
|
164
|
-
};
|
|
1
|
+
'use client';
|
|
2
|
+
/* eslint-disable jsdoc/require-param */
|
|
3
|
+
/* eslint-disable prefer-const */
|
|
4
|
+
import React, { useEffect, useState } from 'react';
|
|
5
|
+
import { EDITING_COMPONENT_ID, EDITING_COMPONENT_PLACEHOLDER, } from '@sitecore-content-sdk/core/layout';
|
|
6
|
+
import { DesignLibraryStatus, getDesignLibraryStatusEvent, addComponentUpdateHandler, } from '@sitecore-content-sdk/core/editing';
|
|
7
|
+
import * as codegen from '@sitecore-content-sdk/core/codegen';
|
|
8
|
+
import * as editing from '@sitecore-content-sdk/core/editing';
|
|
9
|
+
import { useSitecore } from '../../enhancers/withSitecore';
|
|
10
|
+
import { Placeholder, PlaceholderMetadata } from '../Placeholder';
|
|
11
|
+
import { DesignLibraryErrorBoundary } from './DesignLibraryErrorBoundary';
|
|
12
|
+
import { withLoadImportMap } from '../../enhancers/withLoadImportMap';
|
|
13
|
+
import { ErrorComponent } from '../ErrorBoundary';
|
|
14
|
+
let { getDesignLibraryImportMapEvent, getDesignLibraryComponentPropsEvent, addComponentPreviewHandler, sendErrorEvent, } = codegen;
|
|
15
|
+
let { postToDesignLibrary } = editing;
|
|
16
|
+
export const __mockDependencies = (mocks) => {
|
|
17
|
+
addComponentPreviewHandler = mocks.addComponentPreviewHandler;
|
|
18
|
+
if (mocks.postToDesignLibrary) {
|
|
19
|
+
postToDesignLibrary = mocks.postToDesignLibrary;
|
|
20
|
+
}
|
|
21
|
+
if (mocks.sendErrorEvent) {
|
|
22
|
+
sendErrorEvent = mocks.sendErrorEvent;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Design Library component.
|
|
27
|
+
*
|
|
28
|
+
* Renders the **real** Sitecore component for `library` / `library-metadata` modes and,
|
|
29
|
+
* when generation is enabled (`page.mode.designLibrary.isVariantGeneration === true`),
|
|
30
|
+
* wires the **variant generation** handshake so the parent (DL Studio) can send
|
|
31
|
+
* generated code to preview and iterate on.
|
|
32
|
+
* @param {DesignLibraryProps} props
|
|
33
|
+
* @param {() => Promise} [props.loadImportMap] Optional async loader that resolves to the import-map used to resolve the generated component’s imports. Required when `isVariantGeneration` is true.
|
|
34
|
+
* @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export const DesignLibrary = withLoadImportMap(({ loadImportMap }) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const { page } = useSitecore();
|
|
40
|
+
const route = page.layout.sitecore.route;
|
|
41
|
+
const rendering = (_a = route === null || route === void 0 ? void 0 : route.placeholders[EDITING_COMPONENT_PLACEHOLDER]) === null || _a === void 0 ? void 0 : _a[0];
|
|
42
|
+
const uid = rendering === null || rendering === void 0 ? void 0 : rendering.uid;
|
|
43
|
+
const { isDesignLibrary } = page.mode;
|
|
44
|
+
const isVariantGeneration = (_b = page.mode.designLibrary) === null || _b === void 0 ? void 0 : _b.isVariantGeneration;
|
|
45
|
+
const [propsState, setPropsState] = useState({
|
|
46
|
+
fields: rendering === null || rendering === void 0 ? void 0 : rendering.fields,
|
|
47
|
+
params: rendering === null || rendering === void 0 ? void 0 : rendering.params,
|
|
48
|
+
});
|
|
49
|
+
const [renderKey, setRenderKey] = useState(0);
|
|
50
|
+
const [Component, setComponent] = useState(null);
|
|
51
|
+
const isGeneratedComponentActive = !!Component;
|
|
52
|
+
if (!isDesignLibrary)
|
|
53
|
+
return null;
|
|
54
|
+
if (!uid)
|
|
55
|
+
return React.createElement(ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
|
|
56
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
postToDesignLibrary(getDesignLibraryStatusEvent(DesignLibraryStatus.READY, uid));
|
|
59
|
+
if (!isVariantGeneration) {
|
|
60
|
+
requestAnimationFrame(() => {
|
|
61
|
+
setRenderKey((k) => (k === 0 ? k + 1 : k));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const unsubUpdate = addComponentUpdateHandler(rendering, (updated) => {
|
|
65
|
+
setPropsState({ fields: updated.fields, params: updated.params });
|
|
66
|
+
setRenderKey((k) => k + 1);
|
|
67
|
+
});
|
|
68
|
+
// useEffect will cleanup event handler on re-render
|
|
69
|
+
return () => unsubUpdate && unsubUpdate();
|
|
70
|
+
}, [isVariantGeneration, rendering, uid]);
|
|
71
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
// Send a rendered event only as effect of a component update command
|
|
74
|
+
if (renderKey === 0)
|
|
75
|
+
return;
|
|
76
|
+
postToDesignLibrary(getDesignLibraryStatusEvent(DesignLibraryStatus.RENDERED, uid));
|
|
77
|
+
}, [renderKey, uid]);
|
|
78
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!isDesignLibrary || !isVariantGeneration)
|
|
81
|
+
return;
|
|
82
|
+
let cancelled = false;
|
|
83
|
+
// since import map is loaded lazily, we only need to add preview event handler once the import map is loaded
|
|
84
|
+
// unsubscribe function for useEffect cleanup will also be returned once importMap promise has been resolved or rejected
|
|
85
|
+
let unsubscribe;
|
|
86
|
+
(async () => {
|
|
87
|
+
if (!loadImportMap) {
|
|
88
|
+
sendErrorEvent(uid, 'No loadImportMap provided', codegen.DesignLibraryPreviewError.RenderInit);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
let importMap;
|
|
92
|
+
try {
|
|
93
|
+
const mod = await loadImportMap();
|
|
94
|
+
importMap = mod.default;
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
sendErrorEvent(uid, `Error loading import map: ${e}`, codegen.DesignLibraryPreviewError.RenderInit);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
// account for component being unmounted while resolving async import map
|
|
101
|
+
if (cancelled)
|
|
102
|
+
return;
|
|
103
|
+
unsubscribe = addComponentPreviewHandler(importMap, (error, Component) => {
|
|
104
|
+
// Error event is already sent in the addComponentPreviewHandler
|
|
105
|
+
if (error)
|
|
106
|
+
return;
|
|
107
|
+
setComponent(() => Component);
|
|
108
|
+
setRenderKey((k) => k + 1);
|
|
109
|
+
});
|
|
110
|
+
const importMapEvent = getDesignLibraryImportMapEvent(uid, importMap);
|
|
111
|
+
postToDesignLibrary(importMapEvent);
|
|
112
|
+
const propsEvent = getDesignLibraryComponentPropsEvent(uid, propsState.fields, propsState.params);
|
|
113
|
+
postToDesignLibrary(propsEvent);
|
|
114
|
+
})();
|
|
115
|
+
// return function that calls unsubscribe - if the component was mounted correctly
|
|
116
|
+
return () => {
|
|
117
|
+
cancelled = true;
|
|
118
|
+
unsubscribe && unsubscribe();
|
|
119
|
+
};
|
|
120
|
+
}, [isVariantGeneration, uid]);
|
|
121
|
+
return (React.createElement("main", null, isGeneratedComponentActive ? (React.createElement(DesignLibraryErrorBoundary, { uid: uid, renderKey: renderKey },
|
|
122
|
+
React.createElement(PlaceholderMetadata, { rendering: rendering },
|
|
123
|
+
React.createElement(Component, { fields: propsState.fields, params: propsState.params, key: renderKey })))) : (React.createElement("div", { id: EDITING_COMPONENT_ID }, route && (React.createElement(Placeholder, { name: EDITING_COMPONENT_PLACEHOLDER, rendering: route, key: renderKey }))))));
|
|
124
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { EDITING_COMPONENT_PLACEHOLDER } from '@sitecore-content-sdk/core/layout';
|
|
3
|
+
import { DesignLibraryServer } from './DesignLibraryServer';
|
|
4
|
+
import { DesignLibrary } from './DesignLibrary';
|
|
5
|
+
/**
|
|
6
|
+
* Design Library component intended to be used by the NextJs app router application
|
|
7
|
+
* This component serves as a router between client and server component rendering modes for the Design Library.
|
|
8
|
+
* It inspects the component type from the component map and
|
|
9
|
+
* delegates to the appropriate rendering implementation:
|
|
10
|
+
* - Client components are rendered using the `DesignLibrary` component
|
|
11
|
+
* - Server components are rendered using the `DesignLibraryServer` component
|
|
12
|
+
* @param {DesingLibraryAppProps} props - The properties for the Design Library App.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export const DesignLibraryApp = ({ page, componentMap, loadServerImportMap, }) => {
|
|
16
|
+
var _a;
|
|
17
|
+
const { route } = page.layout.sitecore;
|
|
18
|
+
if (!route)
|
|
19
|
+
return null;
|
|
20
|
+
const rendering = (_a = route === null || route === void 0 ? void 0 : route.placeholders[EDITING_COMPONENT_PLACEHOLDER]) === null || _a === void 0 ? void 0 : _a[0];
|
|
21
|
+
const component = componentMap.get((rendering === null || rendering === void 0 ? void 0 : rendering.componentName) || '');
|
|
22
|
+
const isClient = component && component.componentType === 'client';
|
|
23
|
+
return (React.createElement(React.Fragment, null, isClient ? (React.createElement(DesignLibrary, null)) : (React.createElement(DesignLibraryServer, { page: page, componentMap: componentMap, loadServerImportMap: loadServerImportMap, rendering: route }))));
|
|
24
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
import * as dlHelpers from '@sitecore-content-sdk/core/editing';
|
|
4
|
+
import * as codegen from '@sitecore-content-sdk/core/codegen';
|
|
5
|
+
import { updateServerComponentAction } from '../../server-actions/update-server-component-action';
|
|
6
|
+
let { getDesignLibraryComponentPropsEvent, addServerComponentPreviewHandler, getDesignLibraryImportMapEvent, addStyleElement, sendErrorEvent, } = codegen;
|
|
7
|
+
let { getDesignLibraryStatusEvent, addComponentUpdateHandler, postToDesignLibrary } = dlHelpers;
|
|
8
|
+
let _updateServerComponentAction = updateServerComponentAction;
|
|
9
|
+
export const __mockDependencies = (mocks) => {
|
|
10
|
+
postToDesignLibrary = mocks.postToDesignLibrary;
|
|
11
|
+
addComponentUpdateHandler = mocks.addComponentUpdateHandler;
|
|
12
|
+
_updateServerComponentAction = mocks.updateServerComponentAction;
|
|
13
|
+
addServerComponentPreviewHandler = mocks.addServerComponentPreviewHandler;
|
|
14
|
+
getDesignLibraryImportMapEvent = mocks.getDesignLibraryImportMapEvent;
|
|
15
|
+
getDesignLibraryComponentPropsEvent = mocks.getDesignLibraryComponentPropsEvent;
|
|
16
|
+
addStyleElement = mocks.addStyleElement;
|
|
17
|
+
sendErrorEvent = mocks.sendErrorEvent;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Design Library component for rendering server components in app router application.
|
|
21
|
+
* DesignLibraryPreviewEvents component serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
22
|
+
* It posts messages to Design Library Studio and sets up handlers to receive updates and previews which are then passed to the server component via server function updateServerComponentAction.
|
|
23
|
+
* @param {DesignLibraryPreviewEventsProps} props The props. {@link DesignLibraryPreviewEventsProps}
|
|
24
|
+
* @returns {JSX.Element} empty JSX element.
|
|
25
|
+
*/
|
|
26
|
+
export const DesignLibraryPreviewEvents = ({ designLibraryStatus, component, }) => {
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!(component === null || component === void 0 ? void 0 : component.uid))
|
|
29
|
+
return;
|
|
30
|
+
postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
|
|
31
|
+
const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
|
|
32
|
+
_updateServerComponentAction({ uid: updated.uid, updatedComponent: updated });
|
|
33
|
+
});
|
|
34
|
+
return () => {
|
|
35
|
+
unsubUpdate && unsubUpdate();
|
|
36
|
+
};
|
|
37
|
+
}, [component, designLibraryStatus]);
|
|
38
|
+
return React.createElement(React.Fragment, null);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Design Library component for rendering server components in app router application.
|
|
42
|
+
* DesignLibraryVariantGenerationEvents component serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side in variant generation mode.
|
|
43
|
+
* It posts messages to Design Library Studio and sets up handlers to receive updates and previews which are then passed to the server component via server function updateServerComponentAction.
|
|
44
|
+
* If the import map is not present then the import map error will be sent to Design Studio.
|
|
45
|
+
* @param {DesignLibraryVariantGenerationEventsProps} props The props. {@link DesignLibraryVariantGenerationEventsProps}
|
|
46
|
+
* @returns {JSX.Element} empty JSX element.
|
|
47
|
+
*/
|
|
48
|
+
export const DesignLibraryVariantGenerationEvents = ({ designLibraryStatus, component, importMap, importMapError, previewComponentData, }) => {
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
if (!(component === null || component === void 0 ? void 0 : component.uid))
|
|
52
|
+
return;
|
|
53
|
+
postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
|
|
54
|
+
const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
|
|
55
|
+
_updateServerComponentAction({
|
|
56
|
+
uid: updated.uid,
|
|
57
|
+
updatedComponent: updated,
|
|
58
|
+
previewComponent: previewComponentData,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
const unsubPreview = addServerComponentPreviewHandler((eventArgs) => {
|
|
62
|
+
_updateServerComponentAction({ uid: component.uid, previewComponent: eventArgs });
|
|
63
|
+
});
|
|
64
|
+
if (importMapError) {
|
|
65
|
+
// an import map error occurred on the server side in DesignLibraryServer, post error event to Design Studio
|
|
66
|
+
sendErrorEvent(component.uid, importMapError, codegen.DesignLibraryPreviewError.RenderInit);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const importMapEvent = getDesignLibraryImportMapEvent(component.uid, importMap);
|
|
70
|
+
postToDesignLibrary(importMapEvent);
|
|
71
|
+
const propsEvent = getDesignLibraryComponentPropsEvent(component.uid, component.fields, component.params);
|
|
72
|
+
postToDesignLibrary(propsEvent);
|
|
73
|
+
if ((_b = (_a = previewComponentData === null || previewComponentData === void 0 ? void 0 : previewComponentData.message) === null || _a === void 0 ? void 0 : _a.styles) === null || _b === void 0 ? void 0 : _b.content) {
|
|
74
|
+
// the generated component has custom styles, so add the css in style element and add it to document head
|
|
75
|
+
addStyleElement(previewComponentData.message.styles.content);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return () => {
|
|
79
|
+
unsubUpdate && unsubUpdate();
|
|
80
|
+
unsubPreview && unsubPreview();
|
|
81
|
+
};
|
|
82
|
+
}, [component, designLibraryStatus, importMap, importMapError, previewComponentData]);
|
|
83
|
+
return React.createElement(React.Fragment, null);
|
|
84
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { Suspense } from 'react';
|
|
3
|
+
import { DesignLibraryPreviewError, sendErrorEvent } from '@sitecore-content-sdk/core/codegen';
|
|
4
|
+
export class DesignLibraryErrorBoundary extends React.Component {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.state = {
|
|
8
|
+
hasError: false,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
static getDerivedStateFromError() {
|
|
12
|
+
return { hasError: true };
|
|
13
|
+
}
|
|
14
|
+
componentDidUpdate(prevProps) {
|
|
15
|
+
if (prevProps.renderKey !== this.props.renderKey) {
|
|
16
|
+
this.setState({ hasError: false });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
componentDidCatch(error) {
|
|
20
|
+
sendErrorEvent(this.props.uid, error, DesignLibraryPreviewError.Render);
|
|
21
|
+
}
|
|
22
|
+
render() {
|
|
23
|
+
if (this.state.hasError) {
|
|
24
|
+
return React.createElement("div", null, "Error during component rendering");
|
|
25
|
+
}
|
|
26
|
+
return React.createElement(Suspense, null, this.props.children);
|
|
27
|
+
}
|
|
28
|
+
}
|