@sitecore-content-sdk/react 1.3.0-canary.36 → 1.3.0-canary.38

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 (61) hide show
  1. package/dist/cjs/components/DesignLibrary/DesignLibrary.js +15 -11
  2. package/dist/cjs/components/DesignLibrary/DesignLibraryClientEvents.js +5 -0
  3. package/dist/cjs/components/DesignLibrary/DesignLibraryServer.js +18 -8
  4. package/dist/cjs/components/ErrorBoundary.js +11 -2
  5. package/dist/cjs/components/FEaaS/BYOCWrapper.js +2 -1
  6. package/dist/cjs/components/FEaaS/FEaaSWrapper.js +2 -2
  7. package/dist/cjs/components/FEaaS/feaas-utils.js +2 -1
  8. package/dist/cjs/components/Form.js +4 -1
  9. package/dist/cjs/components/Placeholder/Placeholder.js +35 -5
  10. package/dist/cjs/components/Placeholder/PlaceholderMetadata.js +6 -6
  11. package/dist/cjs/components/Placeholder/placeholder-utils.js +7 -7
  12. package/dist/cjs/enhancers/withAppPlaceholder.js +1 -1
  13. package/dist/cjs/enhancers/withPlaceholder.js +2 -4
  14. package/dist/esm/components/DesignLibrary/DesignLibrary.js +15 -11
  15. package/dist/esm/components/DesignLibrary/DesignLibraryClientEvents.js +5 -0
  16. package/dist/esm/components/DesignLibrary/DesignLibraryServer.js +18 -8
  17. package/dist/esm/components/ErrorBoundary.js +9 -2
  18. package/dist/esm/components/FEaaS/BYOCWrapper.js +2 -1
  19. package/dist/esm/components/FEaaS/FEaaSWrapper.js +2 -2
  20. package/dist/esm/components/FEaaS/feaas-utils.js +2 -1
  21. package/dist/esm/components/Form.js +4 -1
  22. package/dist/esm/components/Placeholder/Placeholder.js +2 -5
  23. package/dist/esm/components/Placeholder/PlaceholderMetadata.js +6 -6
  24. package/dist/esm/components/Placeholder/placeholder-utils.js +7 -7
  25. package/dist/esm/enhancers/withAppPlaceholder.js +1 -1
  26. package/dist/esm/enhancers/withPlaceholder.js +2 -4
  27. package/package.json +4 -4
  28. package/types/components/DesignLibrary/DesignLibrary.d.ts.map +1 -1
  29. package/types/components/DesignLibrary/DesignLibraryApp.d.ts +1 -1
  30. package/types/components/DesignLibrary/DesignLibraryApp.d.ts.map +1 -1
  31. package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts +1 -0
  32. package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts.map +1 -1
  33. package/types/components/DesignLibrary/DesignLibraryServer.d.ts +1 -1
  34. package/types/components/DesignLibrary/DesignLibraryServer.d.ts.map +1 -1
  35. package/types/components/DesignLibrary/models.d.ts +3 -3
  36. package/types/components/DesignLibrary/models.d.ts.map +1 -1
  37. package/types/components/ErrorBoundary.d.ts +11 -0
  38. package/types/components/ErrorBoundary.d.ts.map +1 -1
  39. package/types/components/FEaaS/BYOCWrapper.d.ts.map +1 -1
  40. package/types/components/FEaaS/FEaaSWrapper.d.ts +1 -1
  41. package/types/components/FEaaS/FEaaSWrapper.d.ts.map +1 -1
  42. package/types/components/FEaaS/feaas-utils.d.ts +1 -1
  43. package/types/components/FEaaS/feaas-utils.d.ts.map +1 -1
  44. package/types/components/Form.d.ts.map +1 -1
  45. package/types/components/Placeholder/AppPlaceholder.d.ts +1 -1
  46. package/types/components/Placeholder/AppPlaceholder.d.ts.map +1 -1
  47. package/types/components/Placeholder/Placeholder.d.ts +1 -1
  48. package/types/components/Placeholder/Placeholder.d.ts.map +1 -1
  49. package/types/components/Placeholder/PlaceholderMetadata.d.ts.map +1 -1
  50. package/types/components/Placeholder/models.d.ts +1 -1
  51. package/types/components/Placeholder/models.d.ts.map +1 -1
  52. package/types/components/Placeholder/placeholder-utils.d.ts +1 -3
  53. package/types/components/Placeholder/placeholder-utils.d.ts.map +1 -1
  54. package/types/components/SitecoreProvider.d.ts +1 -1
  55. package/types/components/SitecoreProvider.d.ts.map +1 -1
  56. package/types/enhancers/withAppPlaceholder.d.ts.map +1 -1
  57. package/types/enhancers/withDatasourceCheck.d.ts +1 -1
  58. package/types/enhancers/withDatasourceCheck.d.ts.map +1 -1
  59. package/types/enhancers/withPlaceholder.d.ts.map +1 -1
  60. package/types/search/utils.d.ts +1 -1
  61. package/types/search/utils.d.ts.map +1 -1
@@ -46,6 +46,7 @@ const withSitecore_1 = require("../../enhancers/withSitecore");
46
46
  const Placeholder_1 = require("../Placeholder");
47
47
  const DesignLibraryErrorBoundary_1 = require("./DesignLibraryErrorBoundary");
48
48
  const withLoadImportMap_1 = require("../../enhancers/withLoadImportMap");
49
+ const ErrorBoundary_1 = require("../ErrorBoundary");
49
50
  let { getDesignLibraryImportMapEvent, getDesignLibraryComponentPropsEvent, addComponentPreviewHandler, sendErrorEvent, } = codegen;
50
51
  let { postToDesignLibrary } = editing;
51
52
  const __mockDependencies = (mocks) => {
@@ -75,6 +76,7 @@ exports.DesignLibrary = (0, withLoadImportMap_1.withLoadImportMap)(({ loadImport
75
76
  const { page } = (0, withSitecore_1.useSitecore)();
76
77
  const route = page.layout.sitecore.route;
77
78
  const rendering = (_a = route === null || route === void 0 ? void 0 : route.placeholders[layout_1.EDITING_COMPONENT_PLACEHOLDER]) === null || _a === void 0 ? void 0 : _a[0];
79
+ const uid = rendering === null || rendering === void 0 ? void 0 : rendering.uid;
78
80
  const { isDesignLibrary } = page.mode;
79
81
  const isVariantGeneration = (_b = page.mode.designLibrary) === null || _b === void 0 ? void 0 : _b.isVariantGeneration;
80
82
  const [propsState, setPropsState] = (0, react_1.useState)({
@@ -86,9 +88,11 @@ exports.DesignLibrary = (0, withLoadImportMap_1.withLoadImportMap)(({ loadImport
86
88
  const isGeneratedComponentActive = !!Component;
87
89
  if (!isDesignLibrary)
88
90
  return null;
91
+ if (!uid)
92
+ return react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
89
93
  // eslint-disable-next-line react-hooks/rules-of-hooks
90
94
  (0, react_1.useEffect)(() => {
91
- postToDesignLibrary((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.READY, rendering.uid));
95
+ postToDesignLibrary((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.READY, uid));
92
96
  if (!isVariantGeneration) {
93
97
  requestAnimationFrame(() => {
94
98
  setRenderKey((k) => (k === 0 ? k + 1 : k));
@@ -100,25 +104,25 @@ exports.DesignLibrary = (0, withLoadImportMap_1.withLoadImportMap)(({ loadImport
100
104
  });
101
105
  // useEffect will cleanup event handler on re-render
102
106
  return () => unsubUpdate && unsubUpdate();
103
- }, [isVariantGeneration, rendering]);
107
+ }, [isVariantGeneration, rendering, uid]);
104
108
  // eslint-disable-next-line react-hooks/rules-of-hooks
105
109
  (0, react_1.useEffect)(() => {
106
110
  // Send a rendered event only as effect of a component update command
107
111
  if (renderKey === 0)
108
112
  return;
109
- postToDesignLibrary((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.RENDERED, rendering.uid));
110
- }, [renderKey, rendering]);
113
+ postToDesignLibrary((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.RENDERED, uid));
114
+ }, [renderKey, uid]);
111
115
  // eslint-disable-next-line react-hooks/rules-of-hooks
112
116
  (0, react_1.useEffect)(() => {
113
117
  if (!isDesignLibrary || !isVariantGeneration)
114
- return undefined;
118
+ return;
115
119
  let cancelled = false;
116
120
  // since import map is loaded lazily, we only need to add preview event handler once the import map is loaded
117
121
  // unsubscribe function for useEffect cleanup will also be returned once importMap promise has been resolved or rejected
118
122
  let unsubscribe;
119
123
  (async () => {
120
124
  if (!loadImportMap) {
121
- sendErrorEvent(rendering.uid, 'No loadImportMap provided', codegen.DesignLibraryPreviewError.RenderInit);
125
+ sendErrorEvent(uid, 'No loadImportMap provided', codegen.DesignLibraryPreviewError.RenderInit);
122
126
  return;
123
127
  }
124
128
  let importMap;
@@ -127,7 +131,7 @@ exports.DesignLibrary = (0, withLoadImportMap_1.withLoadImportMap)(({ loadImport
127
131
  importMap = mod.default;
128
132
  }
129
133
  catch (e) {
130
- sendErrorEvent(rendering.uid, `Error loading import map: ${e}`, codegen.DesignLibraryPreviewError.RenderInit);
134
+ sendErrorEvent(uid, `Error loading import map: ${e}`, codegen.DesignLibraryPreviewError.RenderInit);
131
135
  return;
132
136
  }
133
137
  // account for component being unmounted while resolving async import map
@@ -140,9 +144,9 @@ exports.DesignLibrary = (0, withLoadImportMap_1.withLoadImportMap)(({ loadImport
140
144
  setComponent(() => Component);
141
145
  setRenderKey((k) => k + 1);
142
146
  });
143
- const importMapEvent = getDesignLibraryImportMapEvent(rendering.uid, importMap);
147
+ const importMapEvent = getDesignLibraryImportMapEvent(uid, importMap);
144
148
  postToDesignLibrary(importMapEvent);
145
- const propsEvent = getDesignLibraryComponentPropsEvent(rendering.uid, propsState.fields, propsState.params);
149
+ const propsEvent = getDesignLibraryComponentPropsEvent(uid, propsState.fields, propsState.params);
146
150
  postToDesignLibrary(propsEvent);
147
151
  })();
148
152
  // return function that calls unsubscribe - if the component was mounted correctly
@@ -150,8 +154,8 @@ exports.DesignLibrary = (0, withLoadImportMap_1.withLoadImportMap)(({ loadImport
150
154
  cancelled = true;
151
155
  unsubscribe && unsubscribe();
152
156
  };
153
- }, [isVariantGeneration, rendering]);
154
- return (react_1.default.createElement("main", null, isGeneratedComponentActive ? (react_1.default.createElement(DesignLibraryErrorBoundary_1.DesignLibraryErrorBoundary, { uid: rendering.uid, renderKey: renderKey },
157
+ }, [isVariantGeneration, uid]);
158
+ return (react_1.default.createElement("main", null, isGeneratedComponentActive ? (react_1.default.createElement(DesignLibraryErrorBoundary_1.DesignLibraryErrorBoundary, { uid: uid, renderKey: renderKey },
155
159
  react_1.default.createElement(Placeholder_1.PlaceholderMetadata, { rendering: rendering },
156
160
  react_1.default.createElement(Component, { fields: propsState.fields, params: propsState.params, key: renderKey })))) : (react_1.default.createElement("div", { id: layout_1.EDITING_COMPONENT_ID }, route && (react_1.default.createElement(Placeholder_1.Placeholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, rendering: route, key: renderKey }))))));
157
161
  });
@@ -62,6 +62,8 @@ exports.__mockDependencies = __mockDependencies;
62
62
  */
63
63
  const DesignLibraryPreviewEvents = ({ designLibraryStatus, component, }) => {
64
64
  (0, react_1.useEffect)(() => {
65
+ if (!(component === null || component === void 0 ? void 0 : component.uid))
66
+ return;
65
67
  postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
66
68
  const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
67
69
  _updateServerComponentAction({ uid: updated.uid, updatedComponent: updated });
@@ -77,12 +79,15 @@ exports.DesignLibraryPreviewEvents = DesignLibraryPreviewEvents;
77
79
  * Design Library component for rendering server components in app router application.
78
80
  * DesignLibraryVariantGenerationEvents component serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side in variant generation mode.
79
81
  * It posts messages to Design Library Studio and sets up handlers to receive updates and previews which are then passed to the server component via server function updateServerComponentAction.
82
+ * If the import map is not present then the import map error will be sent to Design Studio.
80
83
  * @param {DesignLibraryVariantGenerationEventsProps} props The props. {@link DesignLibraryVariantGenerationEventsProps}
81
84
  * @returns {JSX.Element} empty JSX element.
82
85
  */
83
86
  const DesignLibraryVariantGenerationEvents = ({ designLibraryStatus, component, importMap, importMapError, previewComponentData, }) => {
84
87
  (0, react_1.useEffect)(() => {
85
88
  var _a, _b;
89
+ if (!(component === null || component === void 0 ? void 0 : component.uid))
90
+ return;
86
91
  postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
87
92
  const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
88
93
  _updateServerComponentAction({
@@ -46,6 +46,7 @@ const editing_1 = require("@sitecore-content-sdk/core/editing");
46
46
  const codegen = __importStar(require("@sitecore-content-sdk/core/codegen"));
47
47
  const Placeholder_1 = require("../Placeholder");
48
48
  const DesignLibraryErrorBoundary_1 = require("./DesignLibraryErrorBoundary");
49
+ const ErrorBoundary_1 = require("../ErrorBoundary");
49
50
  let { getCacheAndClean, hasCache } = globalCache;
50
51
  let { createComponentInstance, getImportMapInfo } = codegen;
51
52
  let updateComponent = editing_1.updateComponent;
@@ -95,7 +96,7 @@ exports.DesignLibraryServer = DesignLibraryServer;
95
96
  * @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
96
97
  */
97
98
  const DesignLibraryServerVariantGeneration = async ({ page, rendering, loadServerImportMap, componentMap, }) => {
98
- var _a;
99
+ var _a, _b;
99
100
  let designLibraryStatus = editing_1.DesignLibraryStatus.READY;
100
101
  let importMap;
101
102
  let importMapInfo;
@@ -117,18 +118,23 @@ const DesignLibraryServerVariantGeneration = async ({ page, rendering, loadServe
117
118
  importMapError = `Error loading import map: ${e}`;
118
119
  }
119
120
  }
120
- let componentToUpdate = (_a = rendering === null || rendering === void 0 ? void 0 : rendering.placeholders[layout_1.EDITING_COMPONENT_PLACEHOLDER]) === null || _a === void 0 ? void 0 : _a[0];
121
- const componentUpdateKey = `${editing_1.COMPONENT_UPDATE_CACHE_KEY_PREFIX}${componentToUpdate.uid}`;
121
+ let componentToUpdate = (_b = (_a = rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) === null || _a === void 0 ? void 0 : _a[layout_1.EDITING_COMPONENT_PLACEHOLDER]) === null || _b === void 0 ? void 0 : _b[0];
122
+ if (!componentToUpdate)
123
+ return react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: "Rendering data is missing" });
124
+ if (!componentToUpdate.uid)
125
+ return react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
126
+ const uid = componentToUpdate.uid;
127
+ const componentUpdateKey = `${editing_1.COMPONENT_UPDATE_CACHE_KEY_PREFIX}${uid}`;
122
128
  // check if we have an update for this component in the global cache
123
129
  if (hasCache(componentUpdateKey)) {
124
130
  // we have an update, get it and clean the cache
125
131
  designLibraryStatus = editing_1.DesignLibraryStatus.RENDERED;
126
132
  const updateData = getCacheAndClean(componentUpdateKey);
127
133
  // apply the updates to the component rendering
128
- if (updateData.updatedComponent) {
134
+ if (updateData === null || updateData === void 0 ? void 0 : updateData.updatedComponent) {
129
135
  updateComponent(componentToUpdate, updateData.updatedComponent.fields, updateData.updatedComponent.params);
130
136
  }
131
- if (updateData.previewComponent && !importMapError) {
137
+ if ((updateData === null || updateData === void 0 ? void 0 : updateData.previewComponent) && !importMapError && importMap) {
132
138
  previewComponentData = updateData.previewComponent;
133
139
  try {
134
140
  // use provided code and import map to create the component instance
@@ -160,9 +166,13 @@ exports.DesignLibraryServerVariantGeneration = DesignLibraryServerVariantGenerat
160
166
  * @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
161
167
  */
162
168
  const DesignLibraryServerPreview = async ({ page, rendering, componentMap, }) => {
163
- var _a;
169
+ var _a, _b;
164
170
  let designLibraryStatus = editing_1.DesignLibraryStatus.READY;
165
- let componentToUpdate = (_a = rendering === null || rendering === void 0 ? void 0 : rendering.placeholders[layout_1.EDITING_COMPONENT_PLACEHOLDER]) === null || _a === void 0 ? void 0 : _a[0];
171
+ let componentToUpdate = (_b = (_a = rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) === null || _a === void 0 ? void 0 : _a[layout_1.EDITING_COMPONENT_PLACEHOLDER]) === null || _b === void 0 ? void 0 : _b[0];
172
+ if (!componentToUpdate)
173
+ return react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: "Rendering data is missing" });
174
+ if (!componentToUpdate.uid)
175
+ return react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
166
176
  const componentUpdateKey = `${editing_1.COMPONENT_UPDATE_CACHE_KEY_PREFIX}${componentToUpdate.uid}`;
167
177
  // check if we have an update for this component in the global cache
168
178
  if (hasCache(componentUpdateKey)) {
@@ -170,7 +180,7 @@ const DesignLibraryServerPreview = async ({ page, rendering, componentMap, }) =>
170
180
  designLibraryStatus = editing_1.DesignLibraryStatus.RENDERED;
171
181
  const updateData = getCacheAndClean(componentUpdateKey);
172
182
  // apply the updates to the component rendering
173
- if (updateData.updatedComponent) {
183
+ if (updateData === null || updateData === void 0 ? void 0 : updateData.updatedComponent) {
174
184
  updateComponent(componentToUpdate, updateData.updatedComponent.fields, updateData.updatedComponent.params);
175
185
  }
176
186
  }
@@ -34,8 +34,17 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  };
35
35
  })();
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.ErrorComponent = void 0;
37
38
  const react_1 = __importStar(require("react"));
38
39
  const withSitecore_1 = require("../enhancers/withSitecore");
40
+ /**
41
+ * Simple error component applying basic error styling.
42
+ * @param {object} props - Either with `message` (string) or with `children` (ReactNode), but not both.
43
+ */
44
+ const ErrorComponent = (props) => {
45
+ return (react_1.default.createElement("div", { className: "sc-content-sdk-placeholder-error" }, props.message ? props.message : props.children));
46
+ };
47
+ exports.ErrorComponent = ErrorComponent;
39
48
  class ErrorBoundary extends react_1.default.Component {
40
49
  constructor(props) {
41
50
  super(props);
@@ -68,7 +77,7 @@ class ErrorBoundary extends react_1.default.Component {
68
77
  else {
69
78
  if (this.showErrorDetails()) {
70
79
  return (react_1.default.createElement("div", null,
71
- react_1.default.createElement("div", { className: "sc-content-sdk-placeholder-error" },
80
+ react_1.default.createElement(exports.ErrorComponent, null,
72
81
  "A rendering error occurred in component",
73
82
  ' ',
74
83
  react_1.default.createElement("em", null, (_a = this.props.rendering) === null || _a === void 0 ? void 0 : _a.componentName),
@@ -78,7 +87,7 @@ class ErrorBoundary extends react_1.default.Component {
78
87
  }
79
88
  else {
80
89
  return (react_1.default.createElement("div", null,
81
- react_1.default.createElement("div", { className: "sc-content-sdk-placeholder-error" }, this.defaultErrorMessage)));
90
+ react_1.default.createElement(exports.ErrorComponent, { message: this.defaultErrorMessage })));
82
91
  }
83
92
  }
84
93
  }
@@ -88,7 +88,8 @@ class BYOCComponent extends react_1.default.Component {
88
88
  const noNameProps = {
89
89
  errorOverride: 'BYOC: The ComponentName for this rendering is missing',
90
90
  };
91
- return props.missingComponentComponent ? (react_1.default.createElement(this.props.missingComponentComponent, Object.assign({}, noNameProps))) : (react_1.default.createElement(MissingComponent_1.MissingComponent, Object.assign({}, noNameProps)));
91
+ const MissingComp = this.props.missingComponentComponent;
92
+ return MissingComp ? react_1.default.createElement(MissingComp, Object.assign({}, noNameProps)) : react_1.default.createElement(MissingComponent_1.MissingComponent, Object.assign({}, noNameProps));
92
93
  }
93
94
  const unRegisteredComponentProps = {
94
95
  rendering: {
@@ -47,7 +47,7 @@ const utils_1 = require("../../utils");
47
47
  * @public
48
48
  */
49
49
  const FEaaSComponent = (props) => {
50
- var _a, _b, _c, _d, _e, _f, _g;
50
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
51
51
  const computedRevision = ((_a = props.params) === null || _a === void 0 ? void 0 : _a.ComponentRevision) || props.revisionFallback;
52
52
  if (!props.template &&
53
53
  (!props.params ||
@@ -65,7 +65,7 @@ const FEaaSComponent = (props) => {
65
65
  // we pass all the props as a workaround to avoid hydration error, until we convert all Content SDK components to server side
66
66
  // this also allows component to fall back to full client-side rendering when template or src is empty
67
67
  // FEAAS should not fetch anything, since Content SDK does the fetching - so we pass empty array into fetch param
68
- return (react_1.default.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: [] }));
68
+ return (react_1.default.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: [] }));
69
69
  };
70
70
  exports.FEaaSComponent = FEaaSComponent;
71
71
  /**
@@ -120,8 +120,9 @@ async function fetchData(dataOptions) {
120
120
  * @returns component endpoint URL
121
121
  */
122
122
  const composeComponentEndpoint = (params, revisionFallback) => {
123
+ var _a;
123
124
  const revision = params.ComponentRevision || revisionFallback;
124
- const hostname = params.ComponentHostName.startsWith('https://')
125
+ const hostname = ((_a = params.ComponentHostName) === null || _a === void 0 ? void 0 : _a.startsWith('https://'))
125
126
  ? params.ComponentHostName
126
127
  : `https://${params.ComponentHostName}`;
127
128
  return `${hostname}/components/${params.LibraryId}/${params.ComponentId}/${params.ComponentVersion}/${revision}`;
@@ -38,6 +38,7 @@ exports.Form = exports.mockFormModule = void 0;
38
38
  const react_1 = __importStar(require("react"));
39
39
  const core_1 = require("@sitecore-content-sdk/core");
40
40
  const withSitecore_1 = require("../enhancers/withSitecore");
41
+ const ErrorBoundary_1 = require("./ErrorBoundary");
41
42
  let { executeScriptElements, loadForm, subscribeToFormSubmitEvent } = core_1.form;
42
43
  /**
43
44
  * Mock function to replace the form module functions for `testing` purposes.
@@ -82,6 +83,8 @@ const Form = ({ params, rendering }) => {
82
83
  });
83
84
  }
84
85
  else {
86
+ if (!formRef.current)
87
+ return;
85
88
  // If we are in editing mode, we don't want to send any events
86
89
  if (!isEditing) {
87
90
  subscribeToFormSubmitEvent(formRef.current, rendering.uid);
@@ -90,7 +93,7 @@ const Form = ({ params, rendering }) => {
90
93
  }
91
94
  }, [content]);
92
95
  if (isEditing && error) {
93
- return (react_1.default.createElement("div", { className: "sc-content-sdk-placeholder-error" }, "There was a problem loading this section"));
96
+ return react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: "There was a problem loading this section" });
94
97
  }
95
98
  return (react_1.default.createElement("div", { ref: formRef, dangerouslySetInnerHTML: { __html: content }, className: (_a = params.styles) === null || _a === void 0 ? void 0 : _a.trimEnd(), id: id ? id : undefined }));
96
99
  };
@@ -1,5 +1,38 @@
1
1
  "use strict";
2
2
  'use client';
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
3
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
38
  };
@@ -11,7 +44,7 @@ const editing_1 = require("@sitecore-content-sdk/core/editing");
11
44
  const withSitecore_1 = require("../../enhancers/withSitecore");
12
45
  const placeholder_utils_1 = require("./placeholder-utils");
13
46
  const PlaceholderMetadata_1 = require("./PlaceholderMetadata");
14
- const ErrorBoundary_1 = __importDefault(require("../ErrorBoundary"));
47
+ const ErrorBoundary_1 = __importStar(require("../ErrorBoundary"));
15
48
  class PlaceholderComponent extends react_1.default.Component {
16
49
  constructor(props) {
17
50
  super(props);
@@ -42,10 +75,7 @@ class PlaceholderComponent extends react_1.default.Component {
42
75
  if (childProps.errorComponent) {
43
76
  return react_1.default.createElement(childProps.errorComponent, { error: this.state.error });
44
77
  }
45
- return (react_1.default.createElement("div", { className: "sc-content-sdk-placeholder-error" },
46
- "A rendering error occurred: ",
47
- this.state.error.message,
48
- "."));
78
+ return (react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: `A rendering error occurred: ${this.state.error.message}.` }));
49
79
  }
50
80
  const renderingData = childProps.rendering;
51
81
  const placeholderRenderings = (0, placeholder_utils_1.getPlaceholderRenderings)(renderingData, this.props.name, this.props.page.mode.isEditing);
@@ -19,7 +19,8 @@ const editing_1 = require("@sitecore-content-sdk/core/editing");
19
19
  * @returns {JSX.Element} A React fragment containing open and close code blocks surrounding the children elements.
20
20
  */
21
21
  const PlaceholderMetadata = ({ rendering, placeholderName, children, componentRuntime, }) => {
22
- const getCodeBlockAttributes = (kind, id, placeholderName) => {
22
+ const getCodeBlockAttributes = ({ kind, id, placeholderName, }) => {
23
+ var _a;
23
24
  const chrometype = placeholderName ? 'placeholder' : 'rendering';
24
25
  const attributes = {
25
26
  type: 'text/sitecore',
@@ -30,7 +31,7 @@ const PlaceholderMetadata = ({ rendering, placeholderName, children, componentRu
30
31
  if (kind === editing_1.MetadataKind.Open) {
31
32
  if (chrometype === 'placeholder' && placeholderName) {
32
33
  let phId = '';
33
- for (const placeholder of Object.keys(rendering.placeholders)) {
34
+ for (const placeholder of Object.keys((_a = rendering.placeholders) !== null && _a !== void 0 ? _a : {})) {
34
35
  if (placeholderName === placeholder) {
35
36
  phId = id
36
37
  ? `${placeholderName}_${id}`
@@ -59,10 +60,9 @@ const PlaceholderMetadata = ({ rendering, placeholderName, children, componentRu
59
60
  }
60
61
  return attributes;
61
62
  };
62
- const renderComponent = (uid, placeholderName) => (react_1.default.createElement(react_1.default.Fragment, null,
63
- react_1.default.createElement("code", Object.assign({}, getCodeBlockAttributes(editing_1.MetadataKind.Open, uid, placeholderName))),
63
+ return (react_1.default.createElement(react_1.default.Fragment, null,
64
+ react_1.default.createElement("code", Object.assign({}, getCodeBlockAttributes({ kind: editing_1.MetadataKind.Open, id: rendering.uid, placeholderName }))),
64
65
  children,
65
- react_1.default.createElement("code", Object.assign({}, getCodeBlockAttributes(editing_1.MetadataKind.Close, uid, placeholderName)))));
66
- return react_1.default.createElement(react_1.default.Fragment, null, renderComponent(rendering.uid, placeholderName));
66
+ react_1.default.createElement("code", Object.assign({}, getCodeBlockAttributes({ kind: editing_1.MetadataKind.Close, placeholderName })))));
67
67
  };
68
68
  exports.PlaceholderMetadata = PlaceholderMetadata;
@@ -39,17 +39,17 @@ const getPlaceholderRenderings = (rendering, name, isEditing) => {
39
39
  * For Metadata EditMode, we need to keep the raw placeholder name in place.
40
40
  */
41
41
  if (rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) {
42
- Object.keys(rendering.placeholders).forEach((placeholder) => {
43
- const patternPlaceholder = (0, layout_1.isDynamicPlaceholder)(placeholder)
44
- ? (0, layout_1.getDynamicPlaceholderPattern)(placeholder)
42
+ Object.entries(rendering.placeholders).forEach(([key, value]) => {
43
+ const patternPlaceholder = (0, layout_1.isDynamicPlaceholder)(key)
44
+ ? (0, layout_1.getDynamicPlaceholderPattern)(key)
45
45
  : null;
46
46
  if (patternPlaceholder && patternPlaceholder.test(phName)) {
47
47
  if (isEditing) {
48
- phName = placeholder;
48
+ phName = key;
49
49
  }
50
50
  else {
51
- rendering.placeholders[phName] = rendering.placeholders[placeholder];
52
- delete rendering.placeholders[placeholder];
51
+ rendering.placeholders[phName] = value;
52
+ delete rendering.placeholders[key];
53
53
  }
54
54
  }
55
55
  });
@@ -74,7 +74,7 @@ exports.getPlaceholderRenderings = getPlaceholderRenderings;
74
74
  */
75
75
  const getSXAParams = (rendering) => {
76
76
  if (!rendering.params)
77
- return {};
77
+ return { styles: '' };
78
78
  const { GridParameters, Styles } = rendering.params;
79
79
  return ((GridParameters || Styles) && {
80
80
  styles: `${GridParameters || ''} ${Styles || ''}`,
@@ -8,7 +8,7 @@ const react_1 = __importDefault(require("react"));
8
8
  const AppPlaceholder_1 = require("../components/Placeholder/AppPlaceholder");
9
9
  const withAppPlaceholder = (Component) => {
10
10
  return (props) => {
11
- const placeholders = props.rendering.placeholders;
11
+ const placeholders = props.rendering.placeholders || {};
12
12
  const phProps = {};
13
13
  for (const placeholder of Object.keys(placeholders)) {
14
14
  phProps[placeholder] = (react_1.default.createElement(AppPlaceholder_1.AppPlaceholder, { name: placeholder, rendering: props.rendering, componentMap: props.componentMap, page: props.page }));
@@ -8,6 +8,7 @@ const react_1 = __importDefault(require("react"));
8
8
  const withComponentMap_1 = require("./withComponentMap");
9
9
  const withSitecore_1 = require("./withSitecore");
10
10
  const Placeholder_1 = require("../components/Placeholder");
11
+ const ErrorBoundary_1 = require("../components/ErrorBoundary");
11
12
  /**
12
13
  * HOC to provide client-side placeholder functionality to a component.
13
14
  * @param {WithPlaceholderSpec} placeholders
@@ -30,10 +31,7 @@ function withPlaceholder(placeholders, options) {
30
31
  if (childProps.errorComponent) {
31
32
  return react_1.default.createElement(childProps.errorComponent, { error: this.state.error });
32
33
  }
33
- return (react_1.default.createElement("div", { className: "sc-content-sdk-placeholder-error" },
34
- "A rendering error occurred: ",
35
- this.state.error.message,
36
- "."));
34
+ return (react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: `A rendering error occurred: ${this.state.error.message}.` }));
37
35
  }
38
36
  const renderingData = options && options.resolvePlaceholderDataFromProps
39
37
  ? options.resolvePlaceholderDataFromProps(childProps)
@@ -10,6 +10,7 @@ import { useSitecore } from '../../enhancers/withSitecore';
10
10
  import { Placeholder, PlaceholderMetadata } from '../Placeholder';
11
11
  import { DesignLibraryErrorBoundary } from './DesignLibraryErrorBoundary';
12
12
  import { withLoadImportMap } from '../../enhancers/withLoadImportMap';
13
+ import { ErrorComponent } from '../ErrorBoundary';
13
14
  let { getDesignLibraryImportMapEvent, getDesignLibraryComponentPropsEvent, addComponentPreviewHandler, sendErrorEvent, } = codegen;
14
15
  let { postToDesignLibrary } = editing;
15
16
  export const __mockDependencies = (mocks) => {
@@ -38,6 +39,7 @@ export const DesignLibrary = withLoadImportMap(({ loadImportMap }) => {
38
39
  const { page } = useSitecore();
39
40
  const route = page.layout.sitecore.route;
40
41
  const rendering = (_a = route === null || route === void 0 ? void 0 : route.placeholders[EDITING_COMPONENT_PLACEHOLDER]) === null || _a === void 0 ? void 0 : _a[0];
42
+ const uid = rendering === null || rendering === void 0 ? void 0 : rendering.uid;
41
43
  const { isDesignLibrary } = page.mode;
42
44
  const isVariantGeneration = (_b = page.mode.designLibrary) === null || _b === void 0 ? void 0 : _b.isVariantGeneration;
43
45
  const [propsState, setPropsState] = useState({
@@ -49,9 +51,11 @@ export const DesignLibrary = withLoadImportMap(({ loadImportMap }) => {
49
51
  const isGeneratedComponentActive = !!Component;
50
52
  if (!isDesignLibrary)
51
53
  return null;
54
+ if (!uid)
55
+ return React.createElement(ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
52
56
  // eslint-disable-next-line react-hooks/rules-of-hooks
53
57
  useEffect(() => {
54
- postToDesignLibrary(getDesignLibraryStatusEvent(DesignLibraryStatus.READY, rendering.uid));
58
+ postToDesignLibrary(getDesignLibraryStatusEvent(DesignLibraryStatus.READY, uid));
55
59
  if (!isVariantGeneration) {
56
60
  requestAnimationFrame(() => {
57
61
  setRenderKey((k) => (k === 0 ? k + 1 : k));
@@ -63,25 +67,25 @@ export const DesignLibrary = withLoadImportMap(({ loadImportMap }) => {
63
67
  });
64
68
  // useEffect will cleanup event handler on re-render
65
69
  return () => unsubUpdate && unsubUpdate();
66
- }, [isVariantGeneration, rendering]);
70
+ }, [isVariantGeneration, rendering, uid]);
67
71
  // eslint-disable-next-line react-hooks/rules-of-hooks
68
72
  useEffect(() => {
69
73
  // Send a rendered event only as effect of a component update command
70
74
  if (renderKey === 0)
71
75
  return;
72
- postToDesignLibrary(getDesignLibraryStatusEvent(DesignLibraryStatus.RENDERED, rendering.uid));
73
- }, [renderKey, rendering]);
76
+ postToDesignLibrary(getDesignLibraryStatusEvent(DesignLibraryStatus.RENDERED, uid));
77
+ }, [renderKey, uid]);
74
78
  // eslint-disable-next-line react-hooks/rules-of-hooks
75
79
  useEffect(() => {
76
80
  if (!isDesignLibrary || !isVariantGeneration)
77
- return undefined;
81
+ return;
78
82
  let cancelled = false;
79
83
  // since import map is loaded lazily, we only need to add preview event handler once the import map is loaded
80
84
  // unsubscribe function for useEffect cleanup will also be returned once importMap promise has been resolved or rejected
81
85
  let unsubscribe;
82
86
  (async () => {
83
87
  if (!loadImportMap) {
84
- sendErrorEvent(rendering.uid, 'No loadImportMap provided', codegen.DesignLibraryPreviewError.RenderInit);
88
+ sendErrorEvent(uid, 'No loadImportMap provided', codegen.DesignLibraryPreviewError.RenderInit);
85
89
  return;
86
90
  }
87
91
  let importMap;
@@ -90,7 +94,7 @@ export const DesignLibrary = withLoadImportMap(({ loadImportMap }) => {
90
94
  importMap = mod.default;
91
95
  }
92
96
  catch (e) {
93
- sendErrorEvent(rendering.uid, `Error loading import map: ${e}`, codegen.DesignLibraryPreviewError.RenderInit);
97
+ sendErrorEvent(uid, `Error loading import map: ${e}`, codegen.DesignLibraryPreviewError.RenderInit);
94
98
  return;
95
99
  }
96
100
  // account for component being unmounted while resolving async import map
@@ -103,9 +107,9 @@ export const DesignLibrary = withLoadImportMap(({ loadImportMap }) => {
103
107
  setComponent(() => Component);
104
108
  setRenderKey((k) => k + 1);
105
109
  });
106
- const importMapEvent = getDesignLibraryImportMapEvent(rendering.uid, importMap);
110
+ const importMapEvent = getDesignLibraryImportMapEvent(uid, importMap);
107
111
  postToDesignLibrary(importMapEvent);
108
- const propsEvent = getDesignLibraryComponentPropsEvent(rendering.uid, propsState.fields, propsState.params);
112
+ const propsEvent = getDesignLibraryComponentPropsEvent(uid, propsState.fields, propsState.params);
109
113
  postToDesignLibrary(propsEvent);
110
114
  })();
111
115
  // return function that calls unsubscribe - if the component was mounted correctly
@@ -113,8 +117,8 @@ export const DesignLibrary = withLoadImportMap(({ loadImportMap }) => {
113
117
  cancelled = true;
114
118
  unsubscribe && unsubscribe();
115
119
  };
116
- }, [isVariantGeneration, rendering]);
117
- return (React.createElement("main", null, isGeneratedComponentActive ? (React.createElement(DesignLibraryErrorBoundary, { uid: rendering.uid, renderKey: renderKey },
120
+ }, [isVariantGeneration, uid]);
121
+ return (React.createElement("main", null, isGeneratedComponentActive ? (React.createElement(DesignLibraryErrorBoundary, { uid: uid, renderKey: renderKey },
118
122
  React.createElement(PlaceholderMetadata, { rendering: rendering },
119
123
  React.createElement(Component, { fields: propsState.fields, params: propsState.params, key: renderKey })))) : (React.createElement("div", { id: EDITING_COMPONENT_ID }, route && (React.createElement(Placeholder, { name: EDITING_COMPONENT_PLACEHOLDER, rendering: route, key: renderKey }))))));
120
124
  });
@@ -25,6 +25,8 @@ export const __mockDependencies = (mocks) => {
25
25
  */
26
26
  export const DesignLibraryPreviewEvents = ({ designLibraryStatus, component, }) => {
27
27
  useEffect(() => {
28
+ if (!(component === null || component === void 0 ? void 0 : component.uid))
29
+ return;
28
30
  postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
29
31
  const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
30
32
  _updateServerComponentAction({ uid: updated.uid, updatedComponent: updated });
@@ -39,12 +41,15 @@ export const DesignLibraryPreviewEvents = ({ designLibraryStatus, component, })
39
41
  * Design Library component for rendering server components in app router application.
40
42
  * DesignLibraryVariantGenerationEvents component serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side in variant generation mode.
41
43
  * It posts messages to Design Library Studio and sets up handlers to receive updates and previews which are then passed to the server component via server function updateServerComponentAction.
44
+ * If the import map is not present then the import map error will be sent to Design Studio.
42
45
  * @param {DesignLibraryVariantGenerationEventsProps} props The props. {@link DesignLibraryVariantGenerationEventsProps}
43
46
  * @returns {JSX.Element} empty JSX element.
44
47
  */
45
48
  export const DesignLibraryVariantGenerationEvents = ({ designLibraryStatus, component, importMap, importMapError, previewComponentData, }) => {
46
49
  useEffect(() => {
47
50
  var _a, _b;
51
+ if (!(component === null || component === void 0 ? void 0 : component.uid))
52
+ return;
48
53
  postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
49
54
  const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
50
55
  _updateServerComponentAction({