@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
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { EDITING_COMPONENT_PLACEHOLDER } from '@sitecore-content-sdk/core/layout';
|
|
4
|
+
import { DesignLibraryPreviewEvents, DesignLibraryVariantGenerationEvents, } from './DesignLibraryClientEvents';
|
|
5
|
+
import * as globalCache from '@sitecore-content-sdk/core/utils';
|
|
6
|
+
import { DesignLibraryStatus, COMPONENT_UPDATE_CACHE_KEY_PREFIX, updateComponent as updateComponentOriginal, } from '@sitecore-content-sdk/core/editing';
|
|
7
|
+
import * as codegen from '@sitecore-content-sdk/core/codegen';
|
|
8
|
+
import { AppPlaceholder, PlaceholderMetadata } from '../Placeholder';
|
|
9
|
+
import { DesignLibraryErrorBoundary } from './DesignLibraryErrorBoundary';
|
|
10
|
+
import { ErrorComponent } from '../ErrorBoundary';
|
|
11
|
+
let { getCacheAndClean, hasCache } = globalCache;
|
|
12
|
+
let { createComponentInstance, getImportMapInfo } = codegen;
|
|
13
|
+
let updateComponent = updateComponentOriginal;
|
|
14
|
+
export const __mockDependencies = async (mocks) => {
|
|
15
|
+
getCacheAndClean = mocks.getCacheAndClean;
|
|
16
|
+
hasCache = mocks.hasCache;
|
|
17
|
+
createComponentInstance = mocks.createComponentInstance;
|
|
18
|
+
if (mocks.updateComponent) {
|
|
19
|
+
updateComponent = mocks.updateComponent;
|
|
20
|
+
}
|
|
21
|
+
if (mocks.getImportMapInfo) {
|
|
22
|
+
getImportMapInfo = mocks.getImportMapInfo;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Design Library component for rendering server components in app router application.
|
|
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 (Design Library) can send
|
|
31
|
+
* generated code to preview and iterate on.
|
|
32
|
+
* Also renders the DesignLibraryClientEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
33
|
+
* @param {DesignLibraryServerProps} props The props. {@link DesignLibraryServerProps}
|
|
34
|
+
* @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
|
|
35
|
+
*/
|
|
36
|
+
export const DesignLibraryServer = async ({ page, componentMap, rendering, loadServerImportMap, }) => {
|
|
37
|
+
var _a;
|
|
38
|
+
if (!page.mode.isDesignLibrary) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const isVariantGeneration = (_a = page.mode.designLibrary) === null || _a === void 0 ? void 0 : _a.isVariantGeneration;
|
|
42
|
+
if (isVariantGeneration) {
|
|
43
|
+
return (React.createElement(DesignLibraryServerVariantGeneration, { page: page, rendering: rendering, loadServerImportMap: loadServerImportMap, componentMap: componentMap }));
|
|
44
|
+
}
|
|
45
|
+
return (React.createElement(DesignLibraryServerPreview, { page: page, rendering: rendering, componentMap: componentMap }));
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Design Library component for rendering server components in app router application in variant generation mode.
|
|
49
|
+
*
|
|
50
|
+
* Renders the **real** Sitecore component for `library` / `library-metadata` modes on first render and,
|
|
51
|
+
* wires the **variant generation** handshake so the parent (Design Library) can send
|
|
52
|
+
* generated code to preview and iterate on.
|
|
53
|
+
* Also renders the DesignLibraryVariantGenerationEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
54
|
+
* @param {DesignLibraryServerVariantGenerationProps} props The props. {@link DesignLibraryServerVariantGenerationProps}
|
|
55
|
+
* @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
|
|
56
|
+
*/
|
|
57
|
+
export const DesignLibraryServerVariantGeneration = async ({ page, rendering, loadServerImportMap, componentMap, }) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
let designLibraryStatus = DesignLibraryStatus.READY;
|
|
60
|
+
let importMap;
|
|
61
|
+
let importMapInfo;
|
|
62
|
+
let Component;
|
|
63
|
+
let importMapError;
|
|
64
|
+
let previewComponentData;
|
|
65
|
+
// load importmap and importmap payload to pass to FE
|
|
66
|
+
// if not provided, or errors during load set error to pass to FE
|
|
67
|
+
if (!loadServerImportMap) {
|
|
68
|
+
importMapError = 'No loadImportMap provided';
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
try {
|
|
72
|
+
const mod = await loadServerImportMap();
|
|
73
|
+
importMap = mod.default;
|
|
74
|
+
importMapInfo = getImportMapInfo(importMap);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
importMapError = `Error loading import map: ${e}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let componentToUpdate = (_b = (_a = rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) === null || _a === void 0 ? void 0 : _a[EDITING_COMPONENT_PLACEHOLDER]) === null || _b === void 0 ? void 0 : _b[0];
|
|
81
|
+
if (!componentToUpdate)
|
|
82
|
+
return React.createElement(ErrorComponent, { message: "Rendering data is missing" });
|
|
83
|
+
if (!componentToUpdate.uid)
|
|
84
|
+
return React.createElement(ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
|
|
85
|
+
const uid = componentToUpdate.uid;
|
|
86
|
+
const componentUpdateKey = `${COMPONENT_UPDATE_CACHE_KEY_PREFIX}${uid}`;
|
|
87
|
+
// check if we have an update for this component in the global cache
|
|
88
|
+
if (hasCache(componentUpdateKey)) {
|
|
89
|
+
// we have an update, get it and clean the cache
|
|
90
|
+
designLibraryStatus = DesignLibraryStatus.RENDERED;
|
|
91
|
+
const updateData = getCacheAndClean(componentUpdateKey);
|
|
92
|
+
// apply the updates to the component rendering
|
|
93
|
+
if (updateData === null || updateData === void 0 ? void 0 : updateData.updatedComponent) {
|
|
94
|
+
updateComponent(componentToUpdate, updateData.updatedComponent.fields, updateData.updatedComponent.params);
|
|
95
|
+
}
|
|
96
|
+
if ((updateData === null || updateData === void 0 ? void 0 : updateData.previewComponent) && !importMapError && importMap) {
|
|
97
|
+
previewComponentData = updateData.previewComponent;
|
|
98
|
+
try {
|
|
99
|
+
// use provided code and import map to create the component instance
|
|
100
|
+
Component = createComponentInstance(importMap, updateData.previewComponent);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
// error during component initialization - send error to client
|
|
104
|
+
importMapError = error.toString();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return (React.createElement(React.Fragment, null,
|
|
109
|
+
Component ? (React.createElement(DesignLibraryErrorBoundary, { uid: componentToUpdate.uid },
|
|
110
|
+
React.createElement(PlaceholderMetadata, { rendering: componentToUpdate },
|
|
111
|
+
React.createElement(Component, { fields: componentToUpdate.fields, params: componentToUpdate.params, key: Date.now() })))) : (React.createElement(AppPlaceholder, { name: EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap, key: Date.now() })),
|
|
112
|
+
React.createElement(DesignLibraryVariantGenerationEvents, { designLibraryStatus: designLibraryStatus, importMap: importMapInfo,
|
|
113
|
+
// pass a new object since we have mutated the original which leads to old reference passed to the client
|
|
114
|
+
component: Object.assign({}, componentToUpdate), importMapError: importMapError, previewComponentData: previewComponentData })));
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Design Library component for rendering server components in app router application when variant generation is not enabled.
|
|
118
|
+
*
|
|
119
|
+
* Renders the **real** Sitecore component for `library` / `library-metadata` modes and,
|
|
120
|
+
* wires the **component update** handshake so the parent (Design Library) can send
|
|
121
|
+
* updated component props.
|
|
122
|
+
* Also renders the DesignLibraryPreviewEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
123
|
+
* @param {DesignLibraryServerPreviewProps} props The props. {@link DesignLibraryServerPreviewProps}
|
|
124
|
+
* @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
|
|
125
|
+
*/
|
|
126
|
+
export const DesignLibraryServerPreview = async ({ page, rendering, componentMap, }) => {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
let designLibraryStatus = DesignLibraryStatus.READY;
|
|
129
|
+
let componentToUpdate = (_b = (_a = rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) === null || _a === void 0 ? void 0 : _a[EDITING_COMPONENT_PLACEHOLDER]) === null || _b === void 0 ? void 0 : _b[0];
|
|
130
|
+
if (!componentToUpdate)
|
|
131
|
+
return React.createElement(ErrorComponent, { message: "Rendering data is missing" });
|
|
132
|
+
if (!componentToUpdate.uid)
|
|
133
|
+
return React.createElement(ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
|
|
134
|
+
const componentUpdateKey = `${COMPONENT_UPDATE_CACHE_KEY_PREFIX}${componentToUpdate.uid}`;
|
|
135
|
+
// check if we have an update for this component in the global cache
|
|
136
|
+
if (hasCache(componentUpdateKey)) {
|
|
137
|
+
// we have an update, get it and clean the cache
|
|
138
|
+
designLibraryStatus = DesignLibraryStatus.RENDERED;
|
|
139
|
+
const updateData = getCacheAndClean(componentUpdateKey);
|
|
140
|
+
// apply the updates to the component rendering
|
|
141
|
+
if (updateData === null || updateData === void 0 ? void 0 : updateData.updatedComponent) {
|
|
142
|
+
updateComponent(componentToUpdate, updateData.updatedComponent.fields, updateData.updatedComponent.params);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return (React.createElement(React.Fragment, null,
|
|
146
|
+
React.createElement(AppPlaceholder, { name: EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap }),
|
|
147
|
+
React.createElement(DesignLibraryPreviewEvents, { designLibraryStatus: designLibraryStatus,
|
|
148
|
+
// pass a new object since we have mutated the original which leads to old reference passed to the client
|
|
149
|
+
component: Object.assign({}, componentToUpdate) })));
|
|
150
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { useSitecore } from '../enhancers/withSitecore';
|
|
4
|
-
import { getContentSdkPagesClientData } from '@sitecore-content-sdk/core/editing';
|
|
5
|
-
import { getDesignLibraryScriptLink } from '@sitecore-content-sdk/core/editing';
|
|
6
|
-
/**
|
|
7
|
-
* Renders client scripts and data for editing/preview mode for Pages.
|
|
8
|
-
* Renders script required for the Design Library (when mode.isDesignLibrary is true).
|
|
9
|
-
* @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
if
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
1
|
+
'use client';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useSitecore } from '../enhancers/withSitecore';
|
|
4
|
+
import { getContentSdkPagesClientData } from '@sitecore-content-sdk/core/editing';
|
|
5
|
+
import { getDesignLibraryScriptLink } from '@sitecore-content-sdk/core/editing';
|
|
6
|
+
/**
|
|
7
|
+
* Renders client scripts and data for editing/preview mode for Pages.
|
|
8
|
+
* Renders script required for the Design Library (when mode.isDesignLibrary is true).
|
|
9
|
+
* @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export const EditingScripts = () => {
|
|
13
|
+
var _a;
|
|
14
|
+
const { page: { mode, layout }, api, } = useSitecore();
|
|
15
|
+
const { clientData, clientScripts } = layout.sitecore.context;
|
|
16
|
+
// Don't render anything if not in editing mode and rendering type is not component
|
|
17
|
+
if (mode.isNormal || mode.isPreview) {
|
|
18
|
+
return React.createElement(React.Fragment, null);
|
|
19
|
+
}
|
|
20
|
+
// In case of Design Library - render only the script for Design Library
|
|
21
|
+
if (mode.isDesignLibrary) {
|
|
22
|
+
// Add cache buster to the script URL (format hh-dd-mm-yyyy, UTC)
|
|
23
|
+
const now = new Date();
|
|
24
|
+
const hour = String(now.getUTCHours()).padStart(2, '0');
|
|
25
|
+
const day = String(now.getUTCDate()).padStart(2, '0');
|
|
26
|
+
const month = String(now.getUTCMonth() + 1).padStart(2, '0');
|
|
27
|
+
const year = String(now.getUTCFullYear());
|
|
28
|
+
const cacheTimestamp = `${hour}-${day}-${month}-${year}`;
|
|
29
|
+
const scriptUrl = `${getDesignLibraryScriptLink((_a = api === null || api === void 0 ? void 0 : api.edge) === null || _a === void 0 ? void 0 : _a.edgeUrl)}?cb=${cacheTimestamp}`;
|
|
30
|
+
return (React.createElement(React.Fragment, null,
|
|
31
|
+
React.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
|
|
32
|
+
}
|
|
33
|
+
const contentSdkClientData = Object.assign(Object.assign({}, clientData), getContentSdkPagesClientData());
|
|
34
|
+
return (React.createElement(React.Fragment, null, clientScripts === null || clientScripts === void 0 ? void 0 :
|
|
35
|
+
clientScripts.map((src, index) => (React.createElement("script", { src: src, key: index }))),
|
|
36
|
+
Object.keys(contentSdkClientData).map((id) => (React.createElement("script", { key: id, id: id, type: "application/json", dangerouslySetInnerHTML: { __html: JSON.stringify(contentSdkClientData[id]) } })))));
|
|
37
|
+
};
|
|
@@ -1,57 +1,64 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import React, { Suspense } from 'react';
|
|
3
|
-
import { withSitecore } from '../enhancers/withSitecore';
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { Suspense } from 'react';
|
|
3
|
+
import { withSitecore } from '../enhancers/withSitecore';
|
|
4
|
+
/**
|
|
5
|
+
* Simple error component applying basic error styling.
|
|
6
|
+
* @param {object} props - Either with `message` (string) or with `children` (ReactNode), but not both.
|
|
7
|
+
*/
|
|
8
|
+
export const ErrorComponent = (props) => {
|
|
9
|
+
return (React.createElement("div", { className: "sc-content-sdk-placeholder-error" }, props.message ? props.message : props.children));
|
|
10
|
+
};
|
|
11
|
+
class ErrorBoundary extends React.Component {
|
|
12
|
+
constructor(props) {
|
|
13
|
+
super(props);
|
|
14
|
+
this.defaultErrorMessage = 'There was a problem loading this section.';
|
|
15
|
+
this.defaultLoadingMessage = 'Loading component...';
|
|
16
|
+
this.state = { error: null };
|
|
17
|
+
}
|
|
18
|
+
static getDerivedStateFromError(error) {
|
|
19
|
+
return { error: error };
|
|
20
|
+
}
|
|
21
|
+
componentDidCatch(error, errorInfo) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
if (this.showErrorDetails()) {
|
|
24
|
+
console.error(`An error occurred in component ${(_a = this.props.rendering) === null || _a === void 0 ? void 0 : _a.componentName} (${(_b = this.props.rendering) === null || _b === void 0 ? void 0 : _b.uid}): `);
|
|
25
|
+
}
|
|
26
|
+
console.error({ error, errorInfo });
|
|
27
|
+
}
|
|
28
|
+
isInDevMode() {
|
|
29
|
+
return process.env.NODE_ENV === 'development';
|
|
30
|
+
}
|
|
31
|
+
showErrorDetails() {
|
|
32
|
+
return this.isInDevMode() || this.props.page.mode.isEditing || this.props.page.mode.isPreview;
|
|
33
|
+
}
|
|
34
|
+
render() {
|
|
35
|
+
var _a;
|
|
36
|
+
if (this.state.error) {
|
|
37
|
+
if (this.props.errorComponent) {
|
|
38
|
+
return React.createElement(this.props.errorComponent, { error: this.state.error });
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (this.showErrorDetails()) {
|
|
42
|
+
return (React.createElement("div", null,
|
|
43
|
+
React.createElement(ErrorComponent, null,
|
|
44
|
+
"A rendering error occurred in component",
|
|
45
|
+
' ',
|
|
46
|
+
React.createElement("em", null, (_a = this.props.rendering) === null || _a === void 0 ? void 0 : _a.componentName),
|
|
47
|
+
React.createElement("br", null),
|
|
48
|
+
"Error: ",
|
|
49
|
+
React.createElement("em", null, this.state.error.message || JSON.stringify(this.state.error)))));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return (React.createElement("div", null,
|
|
53
|
+
React.createElement(ErrorComponent, { message: this.defaultErrorMessage })));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// do not apply suspense when suspense is disabled or when on already dynamic components
|
|
58
|
+
if (this.props.disableSuspense || this.props.isDynamic) {
|
|
59
|
+
return this.props.children;
|
|
60
|
+
}
|
|
61
|
+
return (React.createElement(Suspense, { fallback: React.createElement("h4", null, this.props.componentLoadingMessage || this.defaultLoadingMessage) }, this.props.children));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export default withSitecore()(ErrorBoundary);
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const finalProps = Object.assign(Object.assign({}, (yield fetchBYOCComponentServerProps(params))), serializableProps);
|
|
20
|
-
return React.createElement(BYOCWrapper, Object.assign({}, finalProps));
|
|
21
|
-
});
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fetchBYOCComponentServerProps } from './feaas-utils';
|
|
3
|
+
import { BYOCWrapper } from './BYOCWrapper';
|
|
4
|
+
import { nonSerializedPlaceholderProps } from '../Placeholder/models';
|
|
5
|
+
/**
|
|
6
|
+
* Server component for BYOC. Retrieves server props and renders client BYOCWrapper.
|
|
7
|
+
* @param {BYOCServerWrapperProps} props incoming props
|
|
8
|
+
* @returns rendered BYOCWrapper component
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export const BYOCServerWrapper = async (props) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const params = ((_a = props.rendering) === null || _a === void 0 ? void 0 : _a.params) || {};
|
|
14
|
+
// only pass serializable props to the client BYOC component
|
|
15
|
+
const serializableProps = Object.fromEntries(Object.entries(props).filter(([key]) => !nonSerializedPlaceholderProps.includes(key)));
|
|
16
|
+
const finalProps = Object.assign(Object.assign({}, (await fetchBYOCComponentServerProps(params))), serializableProps);
|
|
17
|
+
return React.createElement(BYOCWrapper, Object.assign({}, finalProps));
|
|
18
|
+
};
|
|
@@ -1,81 +1,91 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import * as FEAAS from '@sitecore-feaas/clientside/react';
|
|
4
|
-
import { getDataFromFields } from '../../utils';
|
|
5
|
-
import { MissingComponent } from '../MissingComponent';
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import * as FEAAS from '@sitecore-feaas/clientside/react';
|
|
4
|
+
import { getDataFromFields } from '../../utils';
|
|
5
|
+
import { MissingComponent } from '../MissingComponent';
|
|
6
|
+
// Allow mocking of FEAAS.ExternalComponent for testing
|
|
7
|
+
let { ExternalComponent } = FEAAS;
|
|
8
|
+
export const __mockDependencies = (mocks) => {
|
|
9
|
+
if (mocks.ExternalComponent) {
|
|
10
|
+
ExternalComponent = mocks.ExternalComponent;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const DefaultErrorComponent = (props) => {
|
|
14
|
+
var _a;
|
|
15
|
+
return (React.createElement("div", null,
|
|
16
|
+
"A rendering error occurred: ", (_a = props.error) === null || _a === void 0 ? void 0 :
|
|
17
|
+
_a.message,
|
|
18
|
+
"."));
|
|
19
|
+
};
|
|
20
|
+
// BYOCComponent remains for backward compatibility and testing purposes
|
|
21
|
+
/**
|
|
22
|
+
* BYOCComponent facilitate the rendering of external components. It manages potential errors,
|
|
23
|
+
* missing components, and customization of error messages or alternative rendering components.
|
|
24
|
+
* @param {ByocComponentProps} props component props
|
|
25
|
+
* @returns dynamically rendered component or Missing Component error frame
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export class BYOCComponent extends React.Component {
|
|
29
|
+
constructor(props) {
|
|
30
|
+
super(props);
|
|
31
|
+
this.state = {};
|
|
32
|
+
}
|
|
33
|
+
static getDerivedStateFromError(error) {
|
|
34
|
+
// Update state so the next render will show the fallback UI.
|
|
35
|
+
return { error: error };
|
|
36
|
+
}
|
|
37
|
+
componentDidCatch(error) {
|
|
38
|
+
this.setState({ error });
|
|
39
|
+
}
|
|
40
|
+
render() {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
const props = this.props;
|
|
43
|
+
if (this.state.error) {
|
|
44
|
+
return this.props.errorComponent ? (React.createElement(this.props.errorComponent, { error: this.state.error })) : (React.createElement(DefaultErrorComponent, { error: this.state.error }));
|
|
45
|
+
}
|
|
46
|
+
const { ComponentName: componentName } = props.params || {};
|
|
47
|
+
if (!componentName) {
|
|
48
|
+
const noNameProps = {
|
|
49
|
+
errorOverride: 'BYOC: The ComponentName for this rendering is missing',
|
|
50
|
+
};
|
|
51
|
+
const MissingComp = this.props.missingComponentComponent;
|
|
52
|
+
return MissingComp ? React.createElement(MissingComp, Object.assign({}, noNameProps)) : React.createElement(MissingComponent, Object.assign({}, noNameProps));
|
|
53
|
+
}
|
|
54
|
+
const unRegisteredComponentProps = {
|
|
55
|
+
rendering: {
|
|
56
|
+
componentName: componentName,
|
|
57
|
+
},
|
|
58
|
+
errorOverride: 'BYOC: This component was not registered.',
|
|
59
|
+
};
|
|
60
|
+
const fallbackComponent = this.props.missingComponentComponent ? (React.createElement(this.props.missingComponentComponent, Object.assign({}, unRegisteredComponentProps))) : (React.createElement(MissingComponent, Object.assign({}, unRegisteredComponentProps)));
|
|
61
|
+
const ErrorComponent = this.props.errorComponent;
|
|
62
|
+
let componentProps = {};
|
|
63
|
+
if ((_a = props.params) === null || _a === void 0 ? void 0 : _a.ComponentProps) {
|
|
64
|
+
try {
|
|
65
|
+
componentProps = (_b = JSON.parse(props.params.ComponentProps)) !== null && _b !== void 0 ? _b : {};
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
console.error(`Parsing props for ${componentName} component from rendering params failed. Error: ${e}`);
|
|
69
|
+
return ErrorComponent ? (React.createElement(ErrorComponent, { error: e })) : (React.createElement(DefaultErrorComponent, { error: e }));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// apply props from item datasource
|
|
73
|
+
const dataSourcesData = Object.assign(Object.assign({}, props.fetchedData), { _: getDataFromFields((_c = props.fields) !== null && _c !== void 0 ? _c : {}) });
|
|
74
|
+
// we render fallback on client to avoid problems with client-only components
|
|
75
|
+
return (React.createElement(ExternalComponent, Object.assign({}, props.rendering, { componentName: componentName, clientFallback: fallbackComponent, datasources: dataSourcesData }, componentProps)));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* SXA wrapper for BYOC components
|
|
80
|
+
* @param {BYOCComponentProps} props component props
|
|
81
|
+
* @returns wrapped BYOC component
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export const BYOCWrapper = (props) => {
|
|
85
|
+
var _a, _b, _c;
|
|
86
|
+
const styles = (_b = (_a = props.params) === null || _a === void 0 ? void 0 : _a.styles) === null || _b === void 0 ? void 0 : _b.trimEnd();
|
|
87
|
+
const id = (_c = props.params) === null || _c === void 0 ? void 0 : _c.RenderingIdentifier;
|
|
88
|
+
return (React.createElement("div", { className: styles ? styles : undefined, id: id ? id : undefined },
|
|
89
|
+
React.createElement("div", { className: "component-content" },
|
|
90
|
+
React.createElement(BYOCComponent, Object.assign({}, props)))));
|
|
91
|
+
};
|