@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.
Files changed (233) hide show
  1. package/README.md +11 -11
  2. package/dist/cjs/components/ClientEditingChromesUpdate.js +53 -52
  3. package/dist/cjs/components/Date.js +49 -45
  4. package/dist/cjs/components/DefaultEmptyFieldEditingComponents.js +32 -22
  5. package/dist/cjs/components/{DesignLibrary.js → DesignLibrary/DesignLibrary.js} +161 -202
  6. package/dist/cjs/components/DesignLibrary/DesignLibraryApp.js +31 -0
  7. package/dist/cjs/components/DesignLibrary/DesignLibraryClientEvents.js +123 -0
  8. package/dist/cjs/components/DesignLibrary/DesignLibraryErrorBoundary.js +65 -0
  9. package/dist/cjs/components/DesignLibrary/DesignLibraryServer.js +193 -0
  10. package/dist/cjs/components/DesignLibrary/index.js +7 -0
  11. package/dist/cjs/components/DesignLibrary/models.js +2 -0
  12. package/dist/cjs/components/EditingScripts.js +44 -43
  13. package/dist/cjs/components/ErrorBoundary.js +101 -92
  14. package/dist/cjs/components/FEaaS/BYOCServerWrapper.js +25 -28
  15. package/dist/cjs/components/FEaaS/BYOCWrapper.js +133 -122
  16. package/dist/cjs/components/FEaaS/FEaaSSeverWrapper.js +26 -34
  17. package/dist/cjs/components/FEaaS/FEaaSWrapper.js +84 -78
  18. package/dist/cjs/components/FEaaS/feaas-utils.js +130 -144
  19. package/dist/cjs/components/FEaaS/index.js +21 -21
  20. package/dist/cjs/components/FEaaS/models.js +7 -7
  21. package/dist/cjs/components/FieldMetadata.js +29 -29
  22. package/dist/cjs/components/File.js +43 -38
  23. package/dist/cjs/components/Form.js +100 -92
  24. package/dist/cjs/components/HiddenRendering.js +23 -23
  25. package/dist/cjs/components/Image.js +71 -66
  26. package/dist/cjs/components/Link.js +91 -86
  27. package/dist/cjs/components/MissingComponent.js +28 -28
  28. package/dist/cjs/components/Placeholder/AppPlaceholder.js +79 -76
  29. package/dist/cjs/components/Placeholder/ClientComponentWrapper.js +21 -21
  30. package/dist/cjs/components/Placeholder/Placeholder.js +144 -110
  31. package/dist/cjs/components/Placeholder/PlaceholderMetadata.js +68 -63
  32. package/dist/cjs/components/Placeholder/index.js +25 -25
  33. package/dist/cjs/components/Placeholder/models.js +18 -18
  34. package/dist/cjs/components/Placeholder/placeholder-utils.js +226 -226
  35. package/dist/cjs/components/RichText.js +75 -70
  36. package/dist/cjs/components/SitecoreProvider.js +62 -52
  37. package/dist/cjs/components/Text.js +69 -65
  38. package/dist/cjs/components/sharedTypes/components.js +7 -7
  39. package/dist/cjs/components/sharedTypes/index.js +18 -18
  40. package/dist/cjs/components/sharedTypes/props.js +2 -2
  41. package/dist/cjs/enhancers/withAppPlaceholder.js +21 -21
  42. package/dist/cjs/enhancers/withComponentMap.js +24 -24
  43. package/dist/cjs/enhancers/withDatasourceCheck.js +31 -30
  44. package/dist/cjs/enhancers/withEditorChromes.js +29 -24
  45. package/dist/cjs/enhancers/withEmptyFieldEditingComponent.js +71 -70
  46. package/dist/cjs/enhancers/withFieldMetadata.js +68 -67
  47. package/dist/cjs/enhancers/withLoadImportMap.js +53 -0
  48. package/dist/cjs/enhancers/withPlaceholder.js +64 -65
  49. package/dist/cjs/enhancers/withSitecore.js +47 -45
  50. package/dist/cjs/index.js +86 -85
  51. package/dist/cjs/rsc-utils/no-rsc.js +5 -5
  52. package/dist/cjs/rsc-utils/rsc.js +5 -5
  53. package/dist/cjs/search/index.js +7 -0
  54. package/dist/cjs/search/useInfiniteSearch.js +136 -0
  55. package/dist/cjs/search/useSearch.js +107 -0
  56. package/dist/cjs/search/utils.js +35 -0
  57. package/dist/cjs/server-actions/update-server-component-action.js +18 -0
  58. package/dist/cjs/utils.js +38 -38
  59. package/dist/esm/components/ClientEditingChromesUpdate.js +16 -15
  60. package/dist/esm/components/Date.js +43 -39
  61. package/dist/esm/components/DefaultEmptyFieldEditingComponents.js +24 -14
  62. package/dist/esm/components/{DesignLibrary.js → DesignLibrary/DesignLibrary.js} +124 -164
  63. package/dist/esm/components/DesignLibrary/DesignLibraryApp.js +24 -0
  64. package/dist/esm/components/DesignLibrary/DesignLibraryClientEvents.js +84 -0
  65. package/dist/esm/components/DesignLibrary/DesignLibraryErrorBoundary.js +28 -0
  66. package/dist/esm/components/DesignLibrary/DesignLibraryServer.js +150 -0
  67. package/dist/esm/components/DesignLibrary/index.js +2 -0
  68. package/dist/esm/components/DesignLibrary/models.js +1 -0
  69. package/dist/esm/components/EditingScripts.js +37 -36
  70. package/dist/esm/components/ErrorBoundary.js +64 -57
  71. package/dist/esm/components/FEaaS/BYOCServerWrapper.js +18 -21
  72. package/dist/esm/components/FEaaS/BYOCWrapper.js +91 -81
  73. package/dist/esm/components/FEaaS/FEaaSSeverWrapper.js +19 -27
  74. package/dist/esm/components/FEaaS/FEaaSWrapper.js +43 -37
  75. package/dist/esm/components/FEaaS/feaas-utils.js +91 -105
  76. package/dist/esm/components/FEaaS/index.js +6 -6
  77. package/dist/esm/components/FEaaS/models.js +4 -4
  78. package/dist/esm/components/FieldMetadata.js +22 -22
  79. package/dist/esm/components/File.js +36 -31
  80. package/dist/esm/components/Form.js +62 -54
  81. package/dist/esm/components/HiddenRendering.js +16 -16
  82. package/dist/esm/components/Image.js +65 -60
  83. package/dist/esm/components/Link.js +55 -50
  84. package/dist/esm/components/MissingComponent.js +21 -21
  85. package/dist/esm/components/Placeholder/AppPlaceholder.js +72 -69
  86. package/dist/esm/components/Placeholder/ClientComponentWrapper.js +14 -14
  87. package/dist/esm/components/Placeholder/Placeholder.js +104 -103
  88. package/dist/esm/components/Placeholder/PlaceholderMetadata.js +61 -56
  89. package/dist/esm/components/Placeholder/index.js +4 -4
  90. package/dist/esm/components/Placeholder/models.js +15 -15
  91. package/dist/esm/components/Placeholder/placeholder-utils.js +214 -214
  92. package/dist/esm/components/RichText.js +39 -34
  93. package/dist/esm/components/SitecoreProvider.js +55 -45
  94. package/dist/esm/components/Text.js +63 -59
  95. package/dist/esm/components/sharedTypes/components.js +4 -4
  96. package/dist/esm/components/sharedTypes/index.js +2 -2
  97. package/dist/esm/components/sharedTypes/props.js +1 -1
  98. package/dist/esm/enhancers/withAppPlaceholder.js +14 -14
  99. package/dist/esm/enhancers/withComponentMap.js +18 -18
  100. package/dist/esm/enhancers/withDatasourceCheck.js +23 -22
  101. package/dist/esm/enhancers/withEditorChromes.js +22 -17
  102. package/dist/esm/enhancers/withEmptyFieldEditingComponent.js +35 -34
  103. package/dist/esm/enhancers/withFieldMetadata.js +32 -31
  104. package/dist/esm/enhancers/withLoadImportMap.js +17 -0
  105. package/dist/esm/enhancers/withPlaceholder.js +58 -59
  106. package/dist/esm/enhancers/withSitecore.js +40 -38
  107. package/dist/esm/index.js +29 -29
  108. package/dist/esm/rsc-utils/no-rsc.js +2 -2
  109. package/dist/esm/rsc-utils/rsc.js +2 -2
  110. package/dist/esm/search/index.js +2 -0
  111. package/dist/esm/search/useInfiniteSearch.js +132 -0
  112. package/dist/esm/search/useSearch.js +103 -0
  113. package/dist/esm/search/utils.js +30 -0
  114. package/dist/esm/server-actions/update-server-component-action.js +15 -0
  115. package/dist/esm/utils.js +33 -33
  116. package/global.d.ts +17 -0
  117. package/package.json +27 -11
  118. package/search.d.ts +1 -0
  119. package/types/components/ClientEditingChromesUpdate.d.ts +8 -6
  120. package/types/components/ClientEditingChromesUpdate.d.ts.map +1 -0
  121. package/types/components/Date.d.ts +25 -16
  122. package/types/components/Date.d.ts.map +1 -0
  123. package/types/components/DefaultEmptyFieldEditingComponents.d.ts +20 -9
  124. package/types/components/DefaultEmptyFieldEditingComponents.d.ts.map +1 -0
  125. package/types/components/DesignLibrary/DesignLibrary.d.ts +20 -0
  126. package/types/components/DesignLibrary/DesignLibrary.d.ts.map +1 -0
  127. package/types/components/DesignLibrary/DesignLibraryApp.d.ts +14 -0
  128. package/types/components/DesignLibrary/DesignLibraryApp.d.ts.map +1 -0
  129. package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts +21 -0
  130. package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts.map +1 -0
  131. package/types/components/DesignLibrary/DesignLibraryErrorBoundary.d.ts +19 -0
  132. package/types/components/DesignLibrary/DesignLibraryErrorBoundary.d.ts.map +1 -0
  133. package/types/components/DesignLibrary/DesignLibraryServer.d.ts +38 -0
  134. package/types/components/DesignLibrary/DesignLibraryServer.d.ts.map +1 -0
  135. package/types/components/DesignLibrary/index.d.ts +3 -0
  136. package/types/components/DesignLibrary/index.d.ts.map +1 -0
  137. package/types/components/DesignLibrary/models.d.ts +67 -0
  138. package/types/components/DesignLibrary/models.d.ts.map +1 -0
  139. package/types/components/EditingScripts.d.ts +9 -7
  140. package/types/components/EditingScripts.d.ts.map +1 -0
  141. package/types/components/ErrorBoundary.d.ts +29 -17
  142. package/types/components/ErrorBoundary.d.ts.map +1 -0
  143. package/types/components/FEaaS/BYOCServerWrapper.d.ts +10 -3
  144. package/types/components/FEaaS/BYOCServerWrapper.d.ts.map +1 -0
  145. package/types/components/FEaaS/BYOCWrapper.d.ts +29 -25
  146. package/types/components/FEaaS/BYOCWrapper.d.ts.map +1 -0
  147. package/types/components/FEaaS/FEaaSSeverWrapper.d.ts +10 -8
  148. package/types/components/FEaaS/FEaaSSeverWrapper.d.ts.map +1 -0
  149. package/types/components/FEaaS/FEaaSWrapper.d.ts +14 -7
  150. package/types/components/FEaaS/FEaaSWrapper.d.ts.map +1 -0
  151. package/types/components/FEaaS/feaas-utils.d.ts +24 -21
  152. package/types/components/FEaaS/feaas-utils.d.ts.map +1 -0
  153. package/types/components/FEaaS/index.d.ts +7 -6
  154. package/types/components/FEaaS/index.d.ts.map +1 -0
  155. package/types/components/FEaaS/models.d.ts +136 -125
  156. package/types/components/FEaaS/models.d.ts.map +1 -0
  157. package/types/components/FieldMetadata.d.ts +18 -17
  158. package/types/components/FieldMetadata.d.ts.map +1 -0
  159. package/types/components/File.d.ts +28 -18
  160. package/types/components/File.d.ts.map +1 -0
  161. package/types/components/Form.d.ts +35 -29
  162. package/types/components/Form.d.ts.map +1 -0
  163. package/types/components/HiddenRendering.d.ts +3 -2
  164. package/types/components/HiddenRendering.d.ts.map +1 -0
  165. package/types/components/Image.d.ts +70 -48
  166. package/types/components/Image.d.ts.map +1 -0
  167. package/types/components/Link.d.ts +45 -27
  168. package/types/components/Link.d.ts.map +1 -0
  169. package/types/components/MissingComponent.d.ts +9 -8
  170. package/types/components/MissingComponent.d.ts.map +1 -0
  171. package/types/components/Placeholder/AppPlaceholder.d.ts +12 -10
  172. package/types/components/Placeholder/AppPlaceholder.d.ts.map +1 -0
  173. package/types/components/Placeholder/ClientComponentWrapper.d.ts +10 -9
  174. package/types/components/Placeholder/ClientComponentWrapper.d.ts.map +1 -0
  175. package/types/components/Placeholder/Placeholder.d.ts +33 -28
  176. package/types/components/Placeholder/Placeholder.d.ts.map +1 -0
  177. package/types/components/Placeholder/PlaceholderMetadata.d.ts +35 -28
  178. package/types/components/Placeholder/PlaceholderMetadata.d.ts.map +1 -0
  179. package/types/components/Placeholder/index.d.ts +6 -5
  180. package/types/components/Placeholder/index.d.ts.map +1 -0
  181. package/types/components/Placeholder/models.d.ts +149 -140
  182. package/types/components/Placeholder/models.d.ts.map +1 -0
  183. package/types/components/Placeholder/placeholder-utils.d.ts +52 -53
  184. package/types/components/Placeholder/placeholder-utils.d.ts.map +1 -0
  185. package/types/components/RichText.d.ts +31 -17
  186. package/types/components/RichText.d.ts.map +1 -0
  187. package/types/components/SitecoreProvider.d.ts +68 -48
  188. package/types/components/SitecoreProvider.d.ts.map +1 -0
  189. package/types/components/Text.d.ts +29 -20
  190. package/types/components/Text.d.ts.map +1 -0
  191. package/types/components/sharedTypes/components.d.ts +50 -38
  192. package/types/components/sharedTypes/components.d.ts.map +1 -0
  193. package/types/components/sharedTypes/index.d.ts +3 -2
  194. package/types/components/sharedTypes/index.d.ts.map +1 -0
  195. package/types/components/sharedTypes/props.d.ts +15 -14
  196. package/types/components/sharedTypes/props.d.ts.map +1 -0
  197. package/types/enhancers/withAppPlaceholder.d.ts +16 -15
  198. package/types/enhancers/withAppPlaceholder.d.ts.map +1 -0
  199. package/types/enhancers/withComponentMap.d.ts +13 -12
  200. package/types/enhancers/withComponentMap.d.ts.map +1 -0
  201. package/types/enhancers/withDatasourceCheck.d.ts +23 -21
  202. package/types/enhancers/withDatasourceCheck.d.ts.map +1 -0
  203. package/types/enhancers/withEditorChromes.d.ts +8 -2
  204. package/types/enhancers/withEditorChromes.d.ts.map +1 -0
  205. package/types/enhancers/withEmptyFieldEditingComponent.d.ts +29 -27
  206. package/types/enhancers/withEmptyFieldEditingComponent.d.ts.map +1 -0
  207. package/types/enhancers/withFieldMetadata.d.ts +18 -16
  208. package/types/enhancers/withFieldMetadata.d.ts.map +1 -0
  209. package/types/enhancers/withLoadImportMap.d.ts +22 -0
  210. package/types/enhancers/withLoadImportMap.d.ts.map +1 -0
  211. package/types/enhancers/withPlaceholder.d.ts +37 -35
  212. package/types/enhancers/withPlaceholder.d.ts.map +1 -0
  213. package/types/enhancers/withSitecore.d.ts +63 -48
  214. package/types/enhancers/withSitecore.d.ts.map +1 -0
  215. package/types/index.d.ts +31 -30
  216. package/types/index.d.ts.map +1 -0
  217. package/types/rsc-utils/no-rsc.d.ts +2 -1
  218. package/types/rsc-utils/no-rsc.d.ts.map +1 -0
  219. package/types/rsc-utils/rsc.d.ts +2 -1
  220. package/types/rsc-utils/rsc.d.ts.map +1 -0
  221. package/types/search/index.d.ts +4 -0
  222. package/types/search/index.d.ts.map +1 -0
  223. package/types/search/useInfiniteSearch.d.ts +116 -0
  224. package/types/search/useInfiniteSearch.d.ts.map +1 -0
  225. package/types/search/useSearch.d.ts +107 -0
  226. package/types/search/useSearch.d.ts.map +1 -0
  227. package/types/search/utils.d.ts +19 -0
  228. package/types/search/utils.d.ts.map +1 -0
  229. package/types/server-actions/update-server-component-action.d.ts +25 -0
  230. package/types/server-actions/update-server-component-action.d.ts.map +1 -0
  231. package/types/utils.d.ts +18 -17
  232. package/types/utils.d.ts.map +1 -0
  233. 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,2 @@
1
+ export { DesignLibrary } from './DesignLibrary';
2
+ export { DesignLibraryApp } from './DesignLibraryApp';
@@ -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
- export const EditingScripts = () => {
12
- var _a;
13
- const { page: { mode, layout }, api, } = useSitecore();
14
- const { clientData, clientScripts } = layout.sitecore.context;
15
- // Don't render anything if not in editing mode and rendering type is not component
16
- if (mode.isNormal || mode.isPreview) {
17
- return React.createElement(React.Fragment, null);
18
- }
19
- // In case of Design Library - render only the script for Design Library
20
- if (mode.isDesignLibrary) {
21
- // Add cache buster to the script URL (format hh-dd-mm-yyyy, UTC)
22
- const now = new Date();
23
- const hour = String(now.getUTCHours()).padStart(2, '0');
24
- const day = String(now.getUTCDate()).padStart(2, '0');
25
- const month = String(now.getUTCMonth() + 1).padStart(2, '0');
26
- const year = String(now.getUTCFullYear());
27
- const cacheTimestamp = `${hour}-${day}-${month}-${year}`;
28
- const scriptUrl = `${getDesignLibraryScriptLink((_a = api === null || api === void 0 ? void 0 : api.edge) === null || _a === void 0 ? void 0 : _a.edgeUrl)}?cb=${cacheTimestamp}`;
29
- return (React.createElement(React.Fragment, null,
30
- React.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
31
- }
32
- const contentSdkClientData = Object.assign(Object.assign({}, clientData), getContentSdkPagesClientData());
33
- return (React.createElement(React.Fragment, null, clientScripts === null || clientScripts === void 0 ? void 0 :
34
- clientScripts.map((src, index) => (React.createElement("script", { src: src, key: index }))),
35
- Object.keys(contentSdkClientData).map((id) => (React.createElement("script", { key: id, id: id, type: "application/json", dangerouslySetInnerHTML: { __html: JSON.stringify(contentSdkClientData[id]) } })))));
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
- class ErrorBoundary extends React.Component {
5
- constructor(props) {
6
- super(props);
7
- this.defaultErrorMessage = 'There was a problem loading this section.';
8
- this.defaultLoadingMessage = 'Loading component...';
9
- this.state = { error: null };
10
- }
11
- static getDerivedStateFromError(error) {
12
- return { error: error };
13
- }
14
- componentDidCatch(error, errorInfo) {
15
- var _a, _b;
16
- if (this.showErrorDetails()) {
17
- 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}): `);
18
- }
19
- console.error({ error, errorInfo });
20
- }
21
- isInDevMode() {
22
- return process.env.NODE_ENV === 'development';
23
- }
24
- showErrorDetails() {
25
- return this.isInDevMode() || this.props.page.mode.isEditing || this.props.page.mode.isPreview;
26
- }
27
- render() {
28
- var _a;
29
- if (this.state.error) {
30
- if (this.props.errorComponent) {
31
- return React.createElement(this.props.errorComponent, { error: this.state.error });
32
- }
33
- else {
34
- if (this.showErrorDetails()) {
35
- return (React.createElement("div", null,
36
- React.createElement("div", { className: "sc-content-sdk-placeholder-error" },
37
- "A rendering error occurred in component",
38
- ' ',
39
- React.createElement("em", null, (_a = this.props.rendering) === null || _a === void 0 ? void 0 : _a.componentName),
40
- React.createElement("br", null),
41
- "Error: ",
42
- React.createElement("em", null, this.state.error.message || JSON.stringify(this.state.error)))));
43
- }
44
- else {
45
- return (React.createElement("div", null,
46
- React.createElement("div", { className: "sc-content-sdk-placeholder-error" }, this.defaultErrorMessage)));
47
- }
48
- }
49
- }
50
- // do not apply suspense when suspense is disabled or when on already dynamic components
51
- if (this.props.disableSuspense || this.props.isDynamic) {
52
- return this.props.children;
53
- }
54
- return (React.createElement(Suspense, { fallback: React.createElement("h4", null, this.props.componentLoadingMessage || this.defaultLoadingMessage) }, this.props.children));
55
- }
56
- }
57
- export default withSitecore()(ErrorBoundary);
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import React from 'react';
11
- import { fetchBYOCComponentServerProps } from './feaas-utils';
12
- import { BYOCWrapper } from './BYOCWrapper';
13
- import { nonSerializedPlaceholderProps } from '../Placeholder/models';
14
- export const BYOCServerWrapper = (props) => __awaiter(void 0, void 0, void 0, function* () {
15
- var _a;
16
- const params = ((_a = props.rendering) === null || _a === void 0 ? void 0 : _a.params) || {};
17
- // only pass serializable props to the client BYOC component
18
- const serializableProps = Object.fromEntries(Object.entries(props).filter(([key]) => !nonSerializedPlaceholderProps.includes(key)));
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
- const DefaultErrorComponent = (props) => {
7
- var _a;
8
- return (React.createElement("div", null,
9
- "A rendering error occurred: ", (_a = props.error) === null || _a === void 0 ? void 0 :
10
- _a.message,
11
- "."));
12
- };
13
- // BYOCComponent remains for backward compatibility and testing purposes
14
- /**
15
- * BYOCComponent facilitate the rendering of external components. It manages potential errors,
16
- * missing components, and customization of error messages or alternative rendering components.
17
- * @param {ByocComponentProps} props component props
18
- * @returns dynamically rendered component or Missing Component error frame
19
- */
20
- export class BYOCComponent extends React.Component {
21
- constructor(props) {
22
- super(props);
23
- this.state = {};
24
- }
25
- static getDerivedStateFromError(error) {
26
- // Update state so the next render will show the fallback UI.
27
- return { error: error };
28
- }
29
- componentDidCatch(error) {
30
- this.setState({ error });
31
- }
32
- render() {
33
- var _a, _b, _c;
34
- const props = this.props;
35
- if (this.state.error) {
36
- return this.props.errorComponent ? (React.createElement(this.props.errorComponent, { error: this.state.error })) : (React.createElement(DefaultErrorComponent, { error: this.state.error }));
37
- }
38
- const { ComponentName: componentName } = props.params || {};
39
- if (!componentName) {
40
- const noNameProps = {
41
- errorOverride: 'BYOC: The ComponentName for this rendering is missing',
42
- };
43
- return props.missingComponentComponent ? (React.createElement(this.props.missingComponentComponent, Object.assign({}, noNameProps))) : (React.createElement(MissingComponent, Object.assign({}, noNameProps)));
44
- }
45
- const unRegisteredComponentProps = {
46
- rendering: {
47
- componentName: componentName,
48
- },
49
- errorOverride: 'BYOC: This component was not registered.',
50
- };
51
- const fallbackComponent = this.props.missingComponentComponent ? (React.createElement(this.props.missingComponentComponent, Object.assign({}, unRegisteredComponentProps))) : (React.createElement(MissingComponent, Object.assign({}, unRegisteredComponentProps)));
52
- const ErrorComponent = this.props.errorComponent;
53
- let componentProps = {};
54
- if ((_a = props.params) === null || _a === void 0 ? void 0 : _a.ComponentProps) {
55
- try {
56
- componentProps = (_b = JSON.parse(props.params.ComponentProps)) !== null && _b !== void 0 ? _b : {};
57
- }
58
- catch (e) {
59
- console.error(`Parsing props for ${componentName} component from rendering params failed. Error: ${e}`);
60
- return ErrorComponent ? (React.createElement(ErrorComponent, { error: e })) : (React.createElement(DefaultErrorComponent, { error: e }));
61
- }
62
- }
63
- // apply props from item datasource
64
- const dataSourcesData = Object.assign(Object.assign({}, props.fetchedData), { _: getDataFromFields((_c = props.fields) !== null && _c !== void 0 ? _c : {}) });
65
- // we render fallback on client to avoid problems with client-only components
66
- return (React.createElement(FEAAS.ExternalComponent, Object.assign({}, props.rendering, { componentName: componentName, clientFallback: fallbackComponent, datasources: dataSourcesData }, componentProps)));
67
- }
68
- }
69
- /**
70
- * SXA wrapper for BYOC components
71
- * @param {BYOCComponentProps} props component props
72
- * @returns wrapped BYOC component
73
- */
74
- export const BYOCWrapper = (props) => {
75
- var _a, _b, _c;
76
- const styles = (_b = (_a = props.params) === null || _a === void 0 ? void 0 : _a.styles) === null || _b === void 0 ? void 0 : _b.trimEnd();
77
- const id = (_c = props.params) === null || _c === void 0 ? void 0 : _c.RenderingIdentifier;
78
- return (React.createElement("div", { className: styles ? styles : undefined, id: id ? id : undefined },
79
- React.createElement("div", { className: "component-content" },
80
- React.createElement(BYOCComponent, Object.assign({}, props)))));
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
+ };