@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
@@ -1,27 +1,19 @@
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 { fetchFEaaSComponentServerProps } from './feaas-utils';
12
- import { FEaaSWrapper } from './FEaaSWrapper';
13
- import { nonSerializedPlaceholderProps } from '../Placeholder/models';
14
- /**
15
- * Server component for FEaaS. Retrieves server props and renders client FEaaSWrapper.
16
- * @param {FEaaSComponentProps} props incoming props
17
- * @returns {Promise<JSX.Element>} rendered FEaaSWrapper component
18
- */
19
- export const FEaaSServerWrapper = (props) => __awaiter(void 0, void 0, void 0, function* () {
20
- var _a, _b;
21
- const params = ((_a = props.rendering) === null || _a === void 0 ? void 0 : _a.params) || {};
22
- const isPageStateNormal = (_b = props.page) === null || _b === void 0 ? void 0 : _b.mode.isNormal;
23
- // only pass serializable props to the client FEaaS component
24
- const serializableProps = Object.fromEntries(Object.entries(props).filter(([key]) => !nonSerializedPlaceholderProps.includes(key)));
25
- const finalProps = Object.assign(Object.assign({}, (yield fetchFEaaSComponentServerProps(params, isPageStateNormal))), serializableProps);
26
- return React.createElement(FEaaSWrapper, Object.assign({}, finalProps));
27
- });
1
+ import React from 'react';
2
+ import { fetchFEaaSComponentServerProps } from './feaas-utils';
3
+ import { FEaaSWrapper } from './FEaaSWrapper';
4
+ import { nonSerializedPlaceholderProps } from '../Placeholder/models';
5
+ /**
6
+ * Server component for FEaaS. Retrieves server props and renders client FEaaSWrapper.
7
+ * @param {FEaaSComponentProps} props incoming props
8
+ * @returns rendered FEaaSWrapper component
9
+ * @public
10
+ */
11
+ export const FEaaSServerWrapper = async (props) => {
12
+ var _a, _b;
13
+ const params = ((_a = props.rendering) === null || _a === void 0 ? void 0 : _a.params) || {};
14
+ const isPageStateNormal = (_b = props.page) === null || _b === void 0 ? void 0 : _b.mode.isNormal;
15
+ // only pass serializable props to the client FEaaS component
16
+ const serializableProps = Object.fromEntries(Object.entries(props).filter(([key]) => !nonSerializedPlaceholderProps.includes(key)));
17
+ const finalProps = Object.assign(Object.assign({}, (await fetchFEaaSComponentServerProps(params, isPageStateNormal))), serializableProps);
18
+ return React.createElement(FEaaSWrapper, Object.assign({}, finalProps));
19
+ };
@@ -1,37 +1,43 @@
1
- 'use client';
2
- import React from 'react';
3
- import * as FEAAS from '@sitecore-feaas/clientside/react';
4
- import { getDataFromFields } from '../../utils';
5
- // FEaaSComponent remains for backward compatibility and testing purposes
6
- /**
7
- * @param {FEaaSComponentProps} props component props
8
- */
9
- export const FEaaSComponent = (props) => {
10
- var _a, _b, _c, _d, _e, _f, _g;
11
- const computedRevision = ((_a = props.params) === null || _a === void 0 ? void 0 : _a.ComponentRevision) || props.revisionFallback;
12
- if (!props.template &&
13
- (!props.params ||
14
- !props.params.LibraryId ||
15
- !props.params.ComponentId ||
16
- !props.params.ComponentVersion ||
17
- !props.params.ComponentHostName ||
18
- !computedRevision)) {
19
- // Missing FEaaS component required props
20
- return null;
21
- }
22
- // combine fetchedData from server with datasource data (if present)
23
- const data = Object.assign(Object.assign({}, props.fetchedData), { _: getDataFromFields((_b = props.fields) !== null && _b !== void 0 ? _b : {}) });
24
- // FEaaS control would still be hydrated by client
25
- // we pass all the props as a workaround to avoid hydration error, until we convert all Content SDK components to server side
26
- // this also allows component to fall back to full client-side rendering when template or src is empty
27
- // FEAAS should not fetch anything, since Content SDK does the fetching - so we pass empty array into fetch param
28
- return (React.createElement(FEAAS.Component, { data: data, template: props.template, cdn: (_c = props.params) === null || _c === void 0 ? void 0 : _c.ComponentHostName, library: (_d = props.params) === null || _d === void 0 ? void 0 : _d.LibraryId, version: (_e = props.params) === null || _e === void 0 ? void 0 : _e.ComponentVersion, component: (_f = props.params) === null || _f === void 0 ? void 0 : _f.ComponentId, instance: (_g = props.params) === null || _g === void 0 ? void 0 : _g.ComponentInstanceId, revision: computedRevision, fetch: [] }));
29
- };
30
- export const FEaaSWrapper = (props) => {
31
- var _a, _b;
32
- const styles = `component feaas ${(_a = props.params) === null || _a === void 0 ? void 0 : _a.styles}`.trimEnd();
33
- const id = (_b = props.params) === null || _b === void 0 ? void 0 : _b.RenderingIdentifier;
34
- return (React.createElement("div", { className: styles, id: id ? id : undefined },
35
- React.createElement("div", { className: "component-content" },
36
- React.createElement(FEaaSComponent, Object.assign({}, props)))));
37
- };
1
+ 'use client';
2
+ import React from 'react';
3
+ import * as FEAAS from '@sitecore-feaas/clientside/react';
4
+ import { getDataFromFields } from '../../utils';
5
+ // FEaaSComponent remains for backward compatibility and testing purposes
6
+ /**
7
+ * @param {FEaaSComponentProps} props component props
8
+ * @public
9
+ */
10
+ export const FEaaSComponent = (props) => {
11
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
12
+ const computedRevision = ((_a = props.params) === null || _a === void 0 ? void 0 : _a.ComponentRevision) || props.revisionFallback;
13
+ if (!props.template &&
14
+ (!props.params ||
15
+ !props.params.LibraryId ||
16
+ !props.params.ComponentId ||
17
+ !props.params.ComponentVersion ||
18
+ !props.params.ComponentHostName ||
19
+ !computedRevision)) {
20
+ // Missing FEaaS component required props
21
+ return null;
22
+ }
23
+ // combine fetchedData from server with datasource data (if present)
24
+ const data = Object.assign(Object.assign({}, props.fetchedData), { _: getDataFromFields((_b = props.fields) !== null && _b !== void 0 ? _b : {}) });
25
+ // FEaaS control would still be hydrated by client
26
+ // we pass all the props as a workaround to avoid hydration error, until we convert all Content SDK components to server side
27
+ // this also allows component to fall back to full client-side rendering when template or src is empty
28
+ // FEAAS should not fetch anything, since Content SDK does the fetching - so we pass empty array into fetch param
29
+ return (React.createElement(FEAAS.Component, { data: data, template: props.template, cdn: (_c = props.params) === null || _c === void 0 ? void 0 : _c.ComponentHostName, library: (_e = (_d = props.params) === null || _d === void 0 ? void 0 : _d.LibraryId) !== null && _e !== void 0 ? _e : '', version: (_f = props.params) === null || _f === void 0 ? void 0 : _f.ComponentVersion, component: (_h = (_g = props.params) === null || _g === void 0 ? void 0 : _g.ComponentId) !== null && _h !== void 0 ? _h : '', instance: (_j = props.params) === null || _j === void 0 ? void 0 : _j.ComponentInstanceId, revision: computedRevision, fetch: [] }));
30
+ };
31
+ /**
32
+ * The FEaaSWrapper component.
33
+ * @param {FEaaSComponentProps} props component props
34
+ * @public
35
+ */
36
+ export const FEaaSWrapper = (props) => {
37
+ var _a, _b;
38
+ const styles = `component feaas ${(_a = props.params) === null || _a === void 0 ? void 0 : _a.styles}`.trimEnd();
39
+ const id = (_b = props.params) === null || _b === void 0 ? void 0 : _b.RenderingIdentifier;
40
+ return (React.createElement("div", { className: styles, id: id ? id : undefined },
41
+ React.createElement("div", { className: "component-content" },
42
+ React.createElement(FEaaSComponent, Object.assign({}, props)))));
43
+ };
@@ -1,105 +1,91 @@
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 * as FEAAS from '@sitecore-feaas/clientside/react';
11
- /**
12
- * Fetches server component props required for server rendering, based on rendering params.
13
- * @param {BYOCComponentParams} params component params
14
- */
15
- export function fetchBYOCComponentServerProps(params) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const fetchDataOptions = params.ComponentDataOverride
18
- ? JSON.parse(params.ComponentDataOverride)
19
- : {};
20
- const fetchedData = yield FEAAS.DataSettings.fetch(fetchDataOptions || {});
21
- return {
22
- fetchedData,
23
- };
24
- });
25
- }
26
- /**
27
- * Fetches server component props required for server rendering, based on rendering params.
28
- * Component endpoint will either be retrieved from params or from endpointOverride
29
- * @param {FEaaSComponentParams} params component params
30
- * @param {boolean} [isPageStateNormal] whether page is in normal mode
31
- * @param {string} [endpointOverride] optional override for component endpoint
32
- */
33
- export function fetchFEaaSComponentServerProps(params, isPageStateNormal, endpointOverride) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const revisionFallback = isPageStateNormal ? 'published' : 'staged';
36
- const src = endpointOverride || composeComponentEndpoint(params, revisionFallback);
37
- let template = '';
38
- let fetchedData = {};
39
- const fetchDataOptions = params.ComponentDataOverride
40
- ? JSON.parse(params.ComponentDataOverride)
41
- : {};
42
- try {
43
- template = yield fetchComponentTemplate(src, params, revisionFallback);
44
- fetchedData = yield fetchData(fetchDataOptions);
45
- }
46
- catch (e) {
47
- console.error(e);
48
- }
49
- return {
50
- fetchedData,
51
- revisionFallback,
52
- template,
53
- };
54
- });
55
- }
56
- /**
57
- * @param {string} src component endpoint
58
- * @param {FEaaSComponentParams} params rendering parameters for FEAAS component
59
- * @param {RevisionType} revisionFallback fallback revision to fetch if revision is absent in params
60
- */
61
- function fetchComponentTemplate(src, params, revisionFallback) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- try {
64
- const { template } = yield FEAAS.fetchComponent(src);
65
- return template;
66
- }
67
- catch (error) {
68
- console.error(`Fetch FEAAS component from ${src} failed. Ensure the component revision "${params.ComponentRevision || revisionFallback}" is present`);
69
- throw error;
70
- }
71
- });
72
- }
73
- /**
74
- * Fetches component data based on the provided data options.
75
- * This function asynchronously fetches data using the FEAAS.DataSettings.fetch method.
76
- * @param {FEAAS.DataOptions} dataOptions - Options to customize data fetching.
77
- * @returns {Promise<FEAAS.DataScopes>} A promise that resolves with the fetched data,
78
- * or rejects with an error if data fetching encounters an issue.
79
- * @throws {Error} If an error occurs during data fetching, it is propagated as an error.
80
- */
81
- function fetchData(dataOptions) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- try {
84
- const fetchedData = yield FEAAS.DataSettings.fetch(dataOptions || {});
85
- return fetchedData;
86
- }
87
- catch (error) {
88
- console.error('Fetch FEAAS component data settings failed');
89
- throw error;
90
- }
91
- });
92
- }
93
- /**
94
- * Build component endpoint URL from component's params
95
- * @param {FEaaSComponentParams} params rendering parameters for FEAAS component
96
- * @param {RevisionType} revisionFallback fallback revision to fetch if revision is absent in params
97
- * @returns component endpoint URL
98
- */
99
- export const composeComponentEndpoint = (params, revisionFallback) => {
100
- const revision = params.ComponentRevision || revisionFallback;
101
- const hostname = params.ComponentHostName.startsWith('https://')
102
- ? params.ComponentHostName
103
- : `https://${params.ComponentHostName}`;
104
- return `${hostname}/components/${params.LibraryId}/${params.ComponentId}/${params.ComponentVersion}/${revision}`;
105
- };
1
+ import * as FEAAS from '@sitecore-feaas/clientside/react';
2
+ /**
3
+ * Fetches server component props required for server rendering, based on rendering params.
4
+ * @param {BYOCComponentParams} params component params
5
+ * @public
6
+ */
7
+ export async function fetchBYOCComponentServerProps(params) {
8
+ const fetchDataOptions = params.ComponentDataOverride
9
+ ? JSON.parse(params.ComponentDataOverride)
10
+ : {};
11
+ const fetchedData = await FEAAS.DataSettings.fetch(fetchDataOptions || {});
12
+ return {
13
+ fetchedData,
14
+ };
15
+ }
16
+ /**
17
+ * Fetches server component props required for server rendering, based on rendering params.
18
+ * Component endpoint will either be retrieved from params or from endpointOverride
19
+ * @param {FEaaSComponentParams} params component params
20
+ * @param {boolean} [isPageStateNormal] whether page is in normal mode
21
+ * @param {string} [endpointOverride] optional override for component endpoint
22
+ * @public
23
+ */
24
+ export async function fetchFEaaSComponentServerProps(params, isPageStateNormal, endpointOverride) {
25
+ const revisionFallback = isPageStateNormal ? 'published' : 'staged';
26
+ const src = endpointOverride || composeComponentEndpoint(params, revisionFallback);
27
+ let template = '';
28
+ let fetchedData = {};
29
+ const fetchDataOptions = params.ComponentDataOverride
30
+ ? JSON.parse(params.ComponentDataOverride)
31
+ : {};
32
+ try {
33
+ template = await fetchComponentTemplate(src, params, revisionFallback);
34
+ fetchedData = await fetchData(fetchDataOptions);
35
+ }
36
+ catch (e) {
37
+ console.error(e);
38
+ }
39
+ return {
40
+ fetchedData,
41
+ revisionFallback,
42
+ template,
43
+ };
44
+ }
45
+ /**
46
+ * @param {string} src component endpoint
47
+ * @param {FEaaSComponentParams} params rendering parameters for FEAAS component
48
+ * @param {RevisionType} revisionFallback fallback revision to fetch if revision is absent in params
49
+ */
50
+ async function fetchComponentTemplate(src, params, revisionFallback) {
51
+ try {
52
+ const { template } = await FEAAS.fetchComponent(src);
53
+ return template;
54
+ }
55
+ catch (error) {
56
+ console.error(`Fetch FEAAS component from ${src} failed. Ensure the component revision "${params.ComponentRevision || revisionFallback}" is present`);
57
+ throw error;
58
+ }
59
+ }
60
+ /**
61
+ * Fetches component data based on the provided data options.
62
+ * This function asynchronously fetches data using the FEAAS.DataSettings.fetch method.
63
+ * @param {FEAAS.DataOptions} dataOptions - Options to customize data fetching.
64
+ * @returns {Promise<FEAAS.DataScopes>} A promise that resolves with the fetched data,
65
+ * or rejects with an error if data fetching encounters an issue.
66
+ * @throws {Error} If an error occurs during data fetching, it is propagated as an error.
67
+ */
68
+ async function fetchData(dataOptions) {
69
+ try {
70
+ const fetchedData = await FEAAS.DataSettings.fetch(dataOptions || {});
71
+ return fetchedData;
72
+ }
73
+ catch (error) {
74
+ console.error('Fetch FEAAS component data settings failed');
75
+ throw error;
76
+ }
77
+ }
78
+ /**
79
+ * Build component endpoint URL from component's params
80
+ * @param {FEaaSComponentParams} params rendering parameters for FEAAS component
81
+ * @param {RevisionType} revisionFallback fallback revision to fetch if revision is absent in params
82
+ * @returns component endpoint URL
83
+ */
84
+ export const composeComponentEndpoint = (params, revisionFallback) => {
85
+ var _a;
86
+ const revision = params.ComponentRevision || revisionFallback;
87
+ const hostname = ((_a = params.ComponentHostName) === null || _a === void 0 ? void 0 : _a.startsWith('https://'))
88
+ ? params.ComponentHostName
89
+ : `https://${params.ComponentHostName}`;
90
+ return `${hostname}/components/${params.LibraryId}/${params.ComponentId}/${params.ComponentVersion}/${revision}`;
91
+ };
@@ -1,6 +1,6 @@
1
- export { FEaaSWrapper, FEaaSComponent } from './FEaaSWrapper';
2
- export { BYOCWrapper, BYOCComponent } from './BYOCWrapper';
3
- export { FEAAS_COMPONENT_RENDERING_NAME, BYOC_COMPONENT_RENDERING_NAME, FEAAS_WRAPPER_RENDERING_NAME, BYOC_WRAPPER_RENDERING_NAME, } from './models';
4
- export { FEaaSServerWrapper } from './FEaaSSeverWrapper';
5
- export { BYOCServerWrapper } from './BYOCServerWrapper';
6
- export { fetchFEaaSComponentServerProps, fetchBYOCComponentServerProps } from './feaas-utils';
1
+ export { FEaaSWrapper, FEaaSComponent } from './FEaaSWrapper';
2
+ export { BYOCWrapper, BYOCComponent } from './BYOCWrapper';
3
+ export { FEAAS_COMPONENT_RENDERING_NAME, BYOC_COMPONENT_RENDERING_NAME, FEAAS_WRAPPER_RENDERING_NAME, BYOC_WRAPPER_RENDERING_NAME, } from './models';
4
+ export { FEaaSServerWrapper } from './FEaaSSeverWrapper';
5
+ export { BYOCServerWrapper } from './BYOCServerWrapper';
6
+ export { fetchFEaaSComponentServerProps, fetchBYOCComponentServerProps } from './feaas-utils';
@@ -1,4 +1,4 @@
1
- export const FEAAS_WRAPPER_RENDERING_NAME = 'FEaaSWrapper';
2
- export const FEAAS_COMPONENT_RENDERING_NAME = 'FEaaSComponent';
3
- export const BYOC_WRAPPER_RENDERING_NAME = 'BYOCWrapper';
4
- export const BYOC_COMPONENT_RENDERING_NAME = 'BYOCComponent';
1
+ export const FEAAS_WRAPPER_RENDERING_NAME = 'FEaaSWrapper';
2
+ export const FEAAS_COMPONENT_RENDERING_NAME = 'FEaaSComponent';
3
+ export const BYOC_WRAPPER_RENDERING_NAME = 'BYOCWrapper';
4
+ export const BYOC_COMPONENT_RENDERING_NAME = 'BYOCComponent';
@@ -1,22 +1,22 @@
1
- import React from 'react';
2
- import { MetadataKind } from '@sitecore-content-sdk/core/editing';
3
- /**
4
- * The component which renders field metadata markup
5
- * @param {FieldMetadataProps} props the props of the component
6
- * @returns metadata markup wrapped around children
7
- */
8
- export const FieldMetadata = (props) => {
9
- const data = JSON.stringify(props.metadata);
10
- const attributes = {
11
- type: 'text/sitecore',
12
- chrometype: 'field',
13
- className: 'scpm',
14
- };
15
- const codeOpenAttributes = Object.assign(Object.assign({}, attributes), { kind: MetadataKind.Open });
16
- const codeCloseAttributes = Object.assign(Object.assign({}, attributes), { kind: MetadataKind.Close });
17
- return (React.createElement(React.Fragment, null,
18
- React.createElement("code", Object.assign({}, codeOpenAttributes), data),
19
- props.children,
20
- React.createElement("code", Object.assign({}, codeCloseAttributes))));
21
- };
22
- FieldMetadata.displayName = 'FieldMetadata';
1
+ import React from 'react';
2
+ import { MetadataKind } from '@sitecore-content-sdk/core/editing';
3
+ /**
4
+ * The component which renders field metadata markup
5
+ * @param {FieldMetadataProps} props the props of the component
6
+ * @returns metadata markup wrapped around children
7
+ */
8
+ export const FieldMetadata = (props) => {
9
+ const data = JSON.stringify(props.metadata);
10
+ const attributes = {
11
+ type: 'text/sitecore',
12
+ chrometype: 'field',
13
+ className: 'scpm',
14
+ };
15
+ const codeOpenAttributes = Object.assign(Object.assign({}, attributes), { kind: MetadataKind.Open });
16
+ const codeCloseAttributes = Object.assign(Object.assign({}, attributes), { kind: MetadataKind.Close });
17
+ return (React.createElement(React.Fragment, null,
18
+ React.createElement("code", Object.assign({}, codeOpenAttributes), data),
19
+ props.children,
20
+ React.createElement("code", Object.assign({}, codeCloseAttributes))));
21
+ };
22
+ FieldMetadata.displayName = 'FieldMetadata';
@@ -1,31 +1,36 @@
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 { isFieldValueEmpty } from '@sitecore-content-sdk/core/layout';
13
- import React from 'react';
14
- export const File = (_a) => {
15
- var { field, children } = _a, otherProps = __rest(_a, ["field", "children"]);
16
- const dynamicField = field;
17
- if (isFieldValueEmpty(dynamicField)) {
18
- return null;
19
- }
20
- // handle link directly on field for forgetful devs
21
- const file = (dynamicField.src ? field : dynamicField.value);
22
- if (!file) {
23
- return null;
24
- }
25
- const linkText = !children ? file.title || file.displayName : null;
26
- const anchorAttrs = {
27
- href: file.src,
28
- };
29
- return React.createElement('a', Object.assign(Object.assign({}, anchorAttrs), otherProps), linkText, children);
30
- };
31
- File.displayName = 'File';
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 { isFieldValueEmpty } from '@sitecore-content-sdk/core/layout';
13
+ import React from 'react';
14
+ /**
15
+ * The File component.
16
+ * @param {FileProps} props component props
17
+ * @public
18
+ */
19
+ export const File = (_a) => {
20
+ var { field, children } = _a, otherProps = __rest(_a, ["field", "children"]);
21
+ const dynamicField = field;
22
+ if (isFieldValueEmpty(dynamicField)) {
23
+ return null;
24
+ }
25
+ // handle link directly on field for forgetful devs
26
+ const file = (dynamicField.src ? field : dynamicField.value);
27
+ if (!file) {
28
+ return null;
29
+ }
30
+ const linkText = !children ? file.title || file.displayName : null;
31
+ const anchorAttrs = {
32
+ href: file.src,
33
+ };
34
+ return React.createElement('a', Object.assign(Object.assign({}, anchorAttrs), otherProps), linkText, children);
35
+ };
36
+ File.displayName = 'File';
@@ -1,54 +1,62 @@
1
- 'use client';
2
- import React, { useEffect, useRef, useState } from 'react';
3
- import { form } from '@sitecore-content-sdk/core';
4
- import { useSitecore } from '../enhancers/withSitecore';
5
- let { executeScriptElements, loadForm, subscribeToFormSubmitEvent } = form;
6
- /**
7
- * Mock function to replace the form module functions for `testing` purposes.
8
- * @param {any} formModule - The form module to mock
9
- */
10
- export const mockFormModule = (formModule) => {
11
- executeScriptElements = formModule.executeScriptElements;
12
- loadForm = formModule.loadForm;
13
- subscribeToFormSubmitEvent = formModule.subscribeToFormSubmitEvent;
14
- };
15
- export const Form = ({ params, rendering }) => {
16
- var _a;
17
- const id = params === null || params === void 0 ? void 0 : params.RenderingIdentifier;
18
- const [error, setError] = useState(false);
19
- const [content, setContent] = useState('');
20
- const context = useSitecore();
21
- const formRef = useRef(null);
22
- const isEditing = context.page.mode.isEditing;
23
- useEffect(() => {
24
- var _a, _b, _c, _d;
25
- if (!content) {
26
- // Forms must use clientContextId since they are rendered client-side
27
- const edgeId = (_b = (_a = context.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.clientContextId;
28
- if (!edgeId) {
29
- /* eslint-disable no-console */
30
- console.warn('Warning: clientContextId is missing – form cannot be loaded properly on the client');
31
- return;
32
- }
33
- loadForm(edgeId, params.FormId, (_d = (_c = context.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.edgeUrl)
34
- .then(setContent)
35
- .catch(() => {
36
- if (isEditing) {
37
- console.error(`Failed to load form with id ${params.FormId}. Check debug logs for content-sdk:form for more details.`);
38
- }
39
- setError(true);
40
- });
41
- }
42
- else {
43
- // If we are in editing mode, we don't want to send any events
44
- if (!isEditing) {
45
- subscribeToFormSubmitEvent(formRef.current, rendering.uid);
46
- }
47
- executeScriptElements(formRef.current);
48
- }
49
- }, [content]);
50
- if (isEditing && error) {
51
- return (React.createElement("div", { className: "sc-content-sdk-placeholder-error" }, "There was a problem loading this section"));
52
- }
53
- return (React.createElement("div", { ref: formRef, dangerouslySetInnerHTML: { __html: content }, className: (_a = params.styles) === null || _a === void 0 ? void 0 : _a.trimEnd(), id: id ? id : undefined }));
54
- };
1
+ 'use client';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ import { form } from '@sitecore-content-sdk/core';
4
+ import { useSitecore } from '../enhancers/withSitecore';
5
+ import { ErrorComponent } from './ErrorBoundary';
6
+ let { executeScriptElements, loadForm, subscribeToFormSubmitEvent } = form;
7
+ /**
8
+ * Mock function to replace the form module functions for `testing` purposes.
9
+ * @param {any} formModule - The form module to mock
10
+ */
11
+ export const mockFormModule = (formModule) => {
12
+ executeScriptElements = formModule.executeScriptElements;
13
+ loadForm = formModule.loadForm;
14
+ subscribeToFormSubmitEvent = formModule.subscribeToFormSubmitEvent;
15
+ };
16
+ /**
17
+ * The Form component.
18
+ * @param {FormProps} props incoming props
19
+ * @public
20
+ */
21
+ export const Form = ({ params, rendering }) => {
22
+ var _a;
23
+ const id = params === null || params === void 0 ? void 0 : params.RenderingIdentifier;
24
+ const [error, setError] = useState(false);
25
+ const [content, setContent] = useState('');
26
+ const context = useSitecore();
27
+ const formRef = useRef(null);
28
+ const isEditing = context.page.mode.isEditing;
29
+ useEffect(() => {
30
+ var _a, _b, _c, _d;
31
+ if (!content) {
32
+ // Forms must use clientContextId since they are rendered client-side
33
+ const edgeId = (_b = (_a = context.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.clientContextId;
34
+ if (!edgeId) {
35
+ /* eslint-disable no-console */
36
+ console.warn('Warning: clientContextId is missing – form cannot be loaded properly on the client');
37
+ return;
38
+ }
39
+ loadForm(edgeId, params.FormId, (_d = (_c = context.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.edgeUrl)
40
+ .then(setContent)
41
+ .catch(() => {
42
+ if (isEditing) {
43
+ console.error(`Failed to load form with id ${params.FormId}. Check debug logs for content-sdk:form for more details.`);
44
+ }
45
+ setError(true);
46
+ });
47
+ }
48
+ else {
49
+ if (!formRef.current)
50
+ return;
51
+ // If we are in editing mode, we don't want to send any events
52
+ if (!isEditing) {
53
+ subscribeToFormSubmitEvent(formRef.current, rendering.uid);
54
+ }
55
+ executeScriptElements(formRef.current);
56
+ }
57
+ }, [content]);
58
+ if (isEditing && error) {
59
+ return React.createElement(ErrorComponent, { message: "There was a problem loading this section" });
60
+ }
61
+ return (React.createElement("div", { ref: formRef, dangerouslySetInnerHTML: { __html: content }, className: (_a = params.styles) === null || _a === void 0 ? void 0 : _a.trimEnd(), id: id ? id : undefined }));
62
+ };