@sitecore-content-sdk/react 1.3.0-canary.20 → 1.3.0-canary.21

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 (54) hide show
  1. package/dist/cjs/components/{DesignLibrary.js → DesignLibrary/DesignLibrary.js} +16 -70
  2. package/dist/cjs/components/DesignLibrary/DesignLibraryApp.js +31 -0
  3. package/dist/cjs/components/DesignLibrary/DesignLibraryClientEvents.js +118 -0
  4. package/dist/cjs/components/DesignLibrary/DesignLibraryErrorBoundary.js +65 -0
  5. package/dist/cjs/components/DesignLibrary/DesignLibraryServer.js +176 -0
  6. package/dist/cjs/components/DesignLibrary/index.js +7 -0
  7. package/dist/cjs/components/DesignLibrary/models.js +2 -0
  8. package/dist/cjs/components/FEaaS/BYOCServerWrapper.js +3 -12
  9. package/dist/cjs/components/FEaaS/FEaaSSeverWrapper.js +3 -12
  10. package/dist/cjs/components/FEaaS/feaas-utils.js +46 -63
  11. package/dist/cjs/components/SitecoreProvider.js +5 -3
  12. package/dist/cjs/enhancers/withLoadImportMap.js +52 -0
  13. package/dist/cjs/index.js +3 -2
  14. package/dist/cjs/server-actions/update-server-component-action.js +18 -0
  15. package/dist/esm/components/{DesignLibrary.js → DesignLibrary/DesignLibrary.js} +16 -69
  16. package/dist/esm/components/DesignLibrary/DesignLibraryApp.js +24 -0
  17. package/dist/esm/components/DesignLibrary/DesignLibraryClientEvents.js +79 -0
  18. package/dist/esm/components/DesignLibrary/DesignLibraryErrorBoundary.js +28 -0
  19. package/dist/esm/components/DesignLibrary/DesignLibraryServer.js +133 -0
  20. package/dist/esm/components/DesignLibrary/index.js +2 -0
  21. package/dist/esm/components/DesignLibrary/models.js +1 -0
  22. package/dist/esm/components/FEaaS/BYOCServerWrapper.js +3 -12
  23. package/dist/esm/components/FEaaS/FEaaSSeverWrapper.js +3 -12
  24. package/dist/esm/components/FEaaS/feaas-utils.js +46 -63
  25. package/dist/esm/components/SitecoreProvider.js +4 -2
  26. package/dist/esm/enhancers/withLoadImportMap.js +16 -0
  27. package/dist/esm/index.js +1 -1
  28. package/dist/esm/server-actions/update-server-component-action.js +15 -0
  29. package/package.json +3 -3
  30. package/types/components/{DesignLibrary.d.ts → DesignLibrary/DesignLibrary.d.ts} +5 -13
  31. package/types/components/DesignLibrary/DesignLibrary.d.ts.map +1 -0
  32. package/types/components/DesignLibrary/DesignLibraryApp.d.ts +14 -0
  33. package/types/components/DesignLibrary/DesignLibraryApp.d.ts.map +1 -0
  34. package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts +20 -0
  35. package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts.map +1 -0
  36. package/types/components/DesignLibrary/DesignLibraryErrorBoundary.d.ts +19 -0
  37. package/types/components/DesignLibrary/DesignLibraryErrorBoundary.d.ts.map +1 -0
  38. package/types/components/DesignLibrary/DesignLibraryServer.d.ts +38 -0
  39. package/types/components/DesignLibrary/DesignLibraryServer.d.ts.map +1 -0
  40. package/types/components/DesignLibrary/index.d.ts +3 -0
  41. package/types/components/DesignLibrary/index.d.ts.map +1 -0
  42. package/types/components/DesignLibrary/models.d.ts +68 -0
  43. package/types/components/DesignLibrary/models.d.ts.map +1 -0
  44. package/types/components/SitecoreProvider.d.ts +7 -0
  45. package/types/components/SitecoreProvider.d.ts.map +1 -1
  46. package/types/components/sharedTypes/components.d.ts +3 -1
  47. package/types/components/sharedTypes/components.d.ts.map +1 -1
  48. package/types/enhancers/withLoadImportMap.d.ts +22 -0
  49. package/types/enhancers/withLoadImportMap.d.ts.map +1 -0
  50. package/types/index.d.ts +1 -1
  51. package/types/index.d.ts.map +1 -1
  52. package/types/server-actions/update-server-component-action.d.ts +25 -0
  53. package/types/server-actions/update-server-component-action.d.ts.map +1 -0
  54. package/types/components/DesignLibrary.d.ts.map +0 -1
@@ -33,76 +33,23 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  return result;
34
34
  };
35
35
  })();
36
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
- return new (P || (P = Promise))(function (resolve, reject) {
39
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- };
45
36
  Object.defineProperty(exports, "__esModule", { value: true });
46
37
  exports.DesignLibrary = exports.__mockDependencies = void 0;
47
38
  /* eslint-disable jsdoc/require-param */
48
39
  /* eslint-disable prefer-const */
49
40
  const react_1 = __importStar(require("react"));
50
- const Placeholder_1 = require("./Placeholder");
51
41
  const layout_1 = require("@sitecore-content-sdk/core/layout");
52
42
  const editing_1 = require("@sitecore-content-sdk/core/editing");
53
43
  const codegen = __importStar(require("@sitecore-content-sdk/core/codegen"));
54
- const withSitecore_1 = require("../enhancers/withSitecore");
55
- const Placeholder_2 = require("./Placeholder");
56
- let { getDesignLibraryImportMapEvent, getDesignLibraryComponentPropsEvent, addComponentPreviewHandler, } = codegen;
44
+ const withSitecore_1 = require("../../enhancers/withSitecore");
45
+ const Placeholder_1 = require("../Placeholder");
46
+ const DesignLibraryErrorBoundary_1 = require("./DesignLibraryErrorBoundary");
47
+ const withLoadImportMap_1 = require("../../enhancers/withLoadImportMap");
48
+ let { getDesignLibraryImportMapEvent, getDesignLibraryComponentPropsEvent, addComponentPreviewHandler, sendErrorEvent, } = codegen;
57
49
  const __mockDependencies = (mocks) => {
58
50
  addComponentPreviewHandler = mocks.addComponentPreviewHandler;
59
51
  };
60
52
  exports.__mockDependencies = __mockDependencies;
61
- const sendErrorEvent = (uid, error, type) => {
62
- const errorEvent = codegen.getDesignLibraryComponentPreviewErrorEvent(uid, error, type);
63
- console.error('Component Library: sending error event', errorEvent);
64
- if (typeof window !== 'undefined') {
65
- const target = window.parent && window.parent !== window ? window.parent : window;
66
- target.postMessage(errorEvent, '*');
67
- }
68
- };
69
- const postToDL = (evt) => {
70
- if (typeof window === 'undefined')
71
- return;
72
- const target = window.parent && window.parent !== window ? window.parent : window;
73
- try {
74
- console.log('Component Library: sending event', evt === null || evt === void 0 ? void 0 : evt.name, evt);
75
- target.postMessage(evt, '*');
76
- }
77
- catch (err) {
78
- console.error('Component Library: postMessage failed', err, evt);
79
- }
80
- };
81
- class ErrorBoundary extends react_1.default.Component {
82
- constructor() {
83
- super(...arguments);
84
- this.state = {
85
- hasError: false,
86
- };
87
- }
88
- static getDerivedStateFromError() {
89
- return { hasError: true };
90
- }
91
- componentDidUpdate(prevProps) {
92
- if (prevProps.renderKey !== this.props.renderKey) {
93
- this.setState({ hasError: false });
94
- }
95
- }
96
- componentDidCatch(error) {
97
- sendErrorEvent(this.props.uid, error, codegen.DesignLibraryPreviewError.Render);
98
- }
99
- render() {
100
- if (this.state.hasError) {
101
- return react_1.default.createElement("div", null, "Error during component rendering");
102
- }
103
- return this.props.children;
104
- }
105
- }
106
53
  /**
107
54
  * Design Library component.
108
55
  *
@@ -115,7 +62,7 @@ class ErrorBoundary extends react_1.default.Component {
115
62
  * @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
116
63
  * @public
117
64
  */
118
- const DesignLibrary = ({ loadImportMap }) => {
65
+ exports.DesignLibrary = (0, withLoadImportMap_1.withLoadImportMap)(({ loadImportMap }) => {
119
66
  var _a, _b;
120
67
  const { page } = (0, withSitecore_1.useSitecore)();
121
68
  const route = page.layout.sitecore.route;
@@ -133,7 +80,7 @@ const DesignLibrary = ({ loadImportMap }) => {
133
80
  return null;
134
81
  // eslint-disable-next-line react-hooks/rules-of-hooks
135
82
  (0, react_1.useEffect)(() => {
136
- postToDL((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.READY, rendering.uid));
83
+ (0, editing_1.postToDesignLibrary)((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.READY, rendering.uid));
137
84
  if (!isVariantGeneration) {
138
85
  requestAnimationFrame(() => {
139
86
  setRenderKey((k) => (k === 0 ? k + 1 : k));
@@ -151,7 +98,7 @@ const DesignLibrary = ({ loadImportMap }) => {
151
98
  // Send a rendered event only as effect of a component update command
152
99
  if (renderKey === 0)
153
100
  return;
154
- postToDL((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.RENDERED, rendering.uid));
101
+ (0, editing_1.postToDesignLibrary)((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.RENDERED, rendering.uid));
155
102
  }, [renderKey, rendering]);
156
103
  // eslint-disable-next-line react-hooks/rules-of-hooks
157
104
  (0, react_1.useEffect)(() => {
@@ -161,14 +108,14 @@ const DesignLibrary = ({ loadImportMap }) => {
161
108
  // since import map is loaded lazily, we only need to add preview event handler once the import map is loaded
162
109
  // unsubscribe function for useEffect cleanup will also be returned once importMap promise has been resolved or rejected
163
110
  let unsubscribe;
164
- (() => __awaiter(void 0, void 0, void 0, function* () {
111
+ (async () => {
165
112
  if (!loadImportMap) {
166
113
  sendErrorEvent(rendering.uid, 'No loadImportMap provided', codegen.DesignLibraryPreviewError.RenderInit);
167
114
  return;
168
115
  }
169
116
  let importMap;
170
117
  try {
171
- const mod = yield loadImportMap();
118
+ const mod = await loadImportMap();
172
119
  importMap = mod.default;
173
120
  }
174
121
  catch (e) {
@@ -186,18 +133,17 @@ const DesignLibrary = ({ loadImportMap }) => {
186
133
  setRenderKey((k) => k + 1);
187
134
  });
188
135
  const importMapEvent = getDesignLibraryImportMapEvent(rendering.uid, importMap);
189
- postToDL(importMapEvent);
136
+ (0, editing_1.postToDesignLibrary)(importMapEvent);
190
137
  const propsEvent = getDesignLibraryComponentPropsEvent(rendering.uid, propsState.fields, propsState.params);
191
- postToDL(propsEvent);
192
- }))();
138
+ (0, editing_1.postToDesignLibrary)(propsEvent);
139
+ })();
193
140
  // return function that calls unsubscribe - if the component was mounted correctly
194
141
  return () => {
195
142
  cancelled = true;
196
143
  unsubscribe && unsubscribe();
197
144
  };
198
145
  }, [isVariantGeneration, rendering]);
199
- return (react_1.default.createElement("main", null, isGeneratedComponentActive ? (react_1.default.createElement(ErrorBoundary, { uid: rendering.uid, renderKey: renderKey },
200
- react_1.default.createElement(Placeholder_2.PlaceholderMetadata, { rendering: rendering },
146
+ return (react_1.default.createElement("main", null, isGeneratedComponentActive ? (react_1.default.createElement(DesignLibraryErrorBoundary_1.DesignLibraryErrorBoundary, { uid: rendering.uid, renderKey: renderKey },
147
+ react_1.default.createElement(Placeholder_1.PlaceholderMetadata, { rendering: rendering },
201
148
  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 }))))));
202
- };
203
- exports.DesignLibrary = DesignLibrary;
149
+ });
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DesignLibraryApp = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const layout_1 = require("@sitecore-content-sdk/core/layout");
9
+ const DesignLibraryServer_1 = require("./DesignLibraryServer");
10
+ const DesignLibrary_1 = require("./DesignLibrary");
11
+ /**
12
+ * Design Library component intended to be used by the NextJs app router application
13
+ * This component serves as a router between client and server component rendering modes for the Design Library.
14
+ * It inspects the component type from the component map and
15
+ * delegates to the appropriate rendering implementation:
16
+ * - Client components are rendered using the `DesignLibrary` component
17
+ * - Server components are rendered using the `DesignLibraryServer` component
18
+ * @param {DesingLibraryAppProps} props - The properties for the Design Library App.
19
+ * @public
20
+ */
21
+ const DesignLibraryApp = ({ page, componentMap, loadServerImportMap, }) => {
22
+ var _a;
23
+ const { route } = page.layout.sitecore;
24
+ if (!route)
25
+ return null;
26
+ 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];
27
+ const component = componentMap.get((rendering === null || rendering === void 0 ? void 0 : rendering.componentName) || '');
28
+ const isClient = component && component.componentType === 'client';
29
+ return (react_1.default.createElement(react_1.default.Fragment, null, isClient ? (react_1.default.createElement(DesignLibrary_1.DesignLibrary, null)) : (react_1.default.createElement(DesignLibraryServer_1.DesignLibraryServer, { page: page, componentMap: componentMap, loadServerImportMap: loadServerImportMap, rendering: route }))));
30
+ };
31
+ exports.DesignLibraryApp = DesignLibraryApp;
@@ -0,0 +1,118 @@
1
+ "use strict";
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
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.DesignLibraryVariantGenerationEvents = exports.DesignLibraryPreviewEvents = exports.__mockDependencies = void 0;
38
+ const react_1 = __importStar(require("react"));
39
+ const dlHelpers = __importStar(require("@sitecore-content-sdk/core/editing"));
40
+ const codegen = __importStar(require("@sitecore-content-sdk/core/codegen"));
41
+ const update_server_component_action_1 = require("../../server-actions/update-server-component-action");
42
+ let { getDesignLibraryComponentPropsEvent, addServerComponentPreviewHandler, getDesignLibraryImportMapEvent, addStyleElement, sendErrorEvent, } = codegen;
43
+ let { getDesignLibraryStatusEvent, addComponentUpdateHandler, postToDesignLibrary } = dlHelpers;
44
+ let _updateServerComponentAction = update_server_component_action_1.updateServerComponentAction;
45
+ const __mockDependencies = (mocks) => {
46
+ postToDesignLibrary = mocks.postToDesignLibrary;
47
+ addComponentUpdateHandler = mocks.addComponentUpdateHandler;
48
+ _updateServerComponentAction = mocks.updateServerComponentAction;
49
+ addServerComponentPreviewHandler = mocks.addServerComponentPreviewHandler;
50
+ getDesignLibraryImportMapEvent = mocks.getDesignLibraryImportMapEvent;
51
+ getDesignLibraryComponentPropsEvent = mocks.getDesignLibraryComponentPropsEvent;
52
+ addStyleElement = mocks.addStyleElement;
53
+ sendErrorEvent = mocks.sendErrorEvent;
54
+ };
55
+ exports.__mockDependencies = __mockDependencies;
56
+ /**
57
+ * Design Library component for rendering server components in app router application.
58
+ * DesignLibraryPreviewEvents component serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
59
+ * 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.
60
+ * @param {DesignLibraryPreviewEventsProps} props The props. {@link DesignLibraryPreviewEventsProps}
61
+ * @returns {JSX.Element} empty JSX element.
62
+ */
63
+ const DesignLibraryPreviewEvents = ({ designLibraryStatus, component, }) => {
64
+ (0, react_1.useEffect)(() => {
65
+ postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
66
+ const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
67
+ _updateServerComponentAction({ uid: updated.uid, updatedComponent: updated });
68
+ });
69
+ return () => {
70
+ unsubUpdate && unsubUpdate();
71
+ };
72
+ }, [component, designLibraryStatus]);
73
+ return react_1.default.createElement(react_1.default.Fragment, null);
74
+ };
75
+ exports.DesignLibraryPreviewEvents = DesignLibraryPreviewEvents;
76
+ /**
77
+ * Design Library component for rendering server components in app router application.
78
+ * DesignLibraryVariantGenerationEvents component serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side in variant generation mode.
79
+ * 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.
80
+ * @param {DesignLibraryVariantGenerationEventsProps} props The props. {@link DesignLibraryVariantGenerationEventsProps}
81
+ * @returns {JSX.Element} empty JSX element.
82
+ */
83
+ const DesignLibraryVariantGenerationEvents = ({ designLibraryStatus, component, importMap, importMapError, previewComponentData, }) => {
84
+ (0, react_1.useEffect)(() => {
85
+ var _a, _b;
86
+ postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
87
+ const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
88
+ _updateServerComponentAction({
89
+ uid: updated.uid,
90
+ updatedComponent: updated,
91
+ previewComponent: previewComponentData,
92
+ });
93
+ });
94
+ const unsubPreview = addServerComponentPreviewHandler((eventArgs) => {
95
+ _updateServerComponentAction({ uid: component.uid, previewComponent: eventArgs });
96
+ });
97
+ if (importMapError) {
98
+ // an import map error occurred on the server side in DesignLibraryServer, post error event to Design Studio
99
+ sendErrorEvent(component.uid, importMapError, codegen.DesignLibraryPreviewError.RenderInit);
100
+ }
101
+ else {
102
+ const importMapEvent = getDesignLibraryImportMapEvent(component.uid, importMap);
103
+ postToDesignLibrary(importMapEvent);
104
+ const propsEvent = getDesignLibraryComponentPropsEvent(component.uid, component.fields, component.params);
105
+ postToDesignLibrary(propsEvent);
106
+ if ((_b = (_a = previewComponentData === null || previewComponentData === void 0 ? void 0 : previewComponentData.message) === null || _a === void 0 ? void 0 : _a.styles) === null || _b === void 0 ? void 0 : _b.content) {
107
+ // the generated component has custom styles, so add the css in style element and add it to document head
108
+ addStyleElement(previewComponentData.message.styles.content);
109
+ }
110
+ }
111
+ return () => {
112
+ unsubUpdate && unsubUpdate();
113
+ unsubPreview && unsubPreview();
114
+ };
115
+ }, [component, designLibraryStatus, importMap, importMapError, previewComponentData]);
116
+ return react_1.default.createElement(react_1.default.Fragment, null);
117
+ };
118
+ exports.DesignLibraryVariantGenerationEvents = DesignLibraryVariantGenerationEvents;
@@ -0,0 +1,65 @@
1
+ "use strict";
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
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.DesignLibraryErrorBoundary = void 0;
38
+ const react_1 = __importStar(require("react"));
39
+ const codegen_1 = require("@sitecore-content-sdk/core/codegen");
40
+ class DesignLibraryErrorBoundary extends react_1.default.Component {
41
+ constructor() {
42
+ super(...arguments);
43
+ this.state = {
44
+ hasError: false,
45
+ };
46
+ }
47
+ static getDerivedStateFromError() {
48
+ return { hasError: true };
49
+ }
50
+ componentDidUpdate(prevProps) {
51
+ if (prevProps.renderKey !== this.props.renderKey) {
52
+ this.setState({ hasError: false });
53
+ }
54
+ }
55
+ componentDidCatch(error) {
56
+ (0, codegen_1.sendErrorEvent)(this.props.uid, error, codegen_1.DesignLibraryPreviewError.Render);
57
+ }
58
+ render() {
59
+ if (this.state.hasError) {
60
+ return react_1.default.createElement("div", null, "Error during component rendering");
61
+ }
62
+ return react_1.default.createElement(react_1.Suspense, null, this.props.children);
63
+ }
64
+ }
65
+ exports.DesignLibraryErrorBoundary = DesignLibraryErrorBoundary;
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ 'use server';
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
+ })();
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.DesignLibraryServerPreview = exports.DesignLibraryServerVariantGeneration = exports.DesignLibraryServer = exports.__mockDependencies = void 0;
41
+ const react_1 = __importDefault(require("react"));
42
+ const layout_1 = require("@sitecore-content-sdk/core/layout");
43
+ const DesignLibraryClientEvents_1 = require("./DesignLibraryClientEvents");
44
+ const globalCache = __importStar(require("@sitecore-content-sdk/core/utils"));
45
+ const editing_1 = require("@sitecore-content-sdk/core/editing");
46
+ const codegen = __importStar(require("@sitecore-content-sdk/core/codegen"));
47
+ const Placeholder_1 = require("../Placeholder");
48
+ const DesignLibraryErrorBoundary_1 = require("./DesignLibraryErrorBoundary");
49
+ let { getCacheAndClean, hasCache } = globalCache;
50
+ let { createComponentInstance } = codegen;
51
+ const __mockDependencies = async (mocks) => {
52
+ getCacheAndClean = mocks.getCacheAndClean;
53
+ hasCache = mocks.hasCache;
54
+ createComponentInstance = mocks.createComponentInstance;
55
+ };
56
+ exports.__mockDependencies = __mockDependencies;
57
+ /**
58
+ * Design Library component for rendering server components in app router application.
59
+ *
60
+ * Renders the **real** Sitecore component for `library` / `library-metadata` modes and,
61
+ * when generation is enabled (`page.mode.designLibrary.isVariantGeneration === true`),
62
+ * wires the **variant generation** handshake so the parent (Design Library) can send
63
+ * generated code to preview and iterate on.
64
+ * Also renders the DesignLibraryClientEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
65
+ * @param {DesignLibraryServerProps} props The props. {@link DesignLibraryServerProps}
66
+ * @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
67
+ */
68
+ const DesignLibraryServer = async ({ page, componentMap, rendering, loadServerImportMap, }) => {
69
+ var _a;
70
+ if (!page.mode.isDesignLibrary) {
71
+ return null;
72
+ }
73
+ const isVariantGeneration = (_a = page.mode.designLibrary) === null || _a === void 0 ? void 0 : _a.isVariantGeneration;
74
+ if (isVariantGeneration) {
75
+ return (react_1.default.createElement(exports.DesignLibraryServerVariantGeneration, { page: page, rendering: rendering, loadServerImportMap: loadServerImportMap, componentMap: componentMap }));
76
+ }
77
+ return (react_1.default.createElement(exports.DesignLibraryServerPreview, { page: page, rendering: rendering, componentMap: componentMap }));
78
+ };
79
+ exports.DesignLibraryServer = DesignLibraryServer;
80
+ /**
81
+ * Design Library component for rendering server components in app router application in variant generation mode.
82
+ *
83
+ * Renders the **real** Sitecore component for `library` / `library-metadata` modes on first render and,
84
+ * wires the **variant generation** handshake so the parent (Design Library) can send
85
+ * generated code to preview and iterate on.
86
+ * Also renders the DesignLibraryVariantGenerationEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
87
+ * @param {DesignLibraryServerVariantGenerationProps} props The props. {@link DesignLibraryServerVariantGenerationProps}
88
+ * @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
89
+ */
90
+ const DesignLibraryServerVariantGeneration = async ({ page, rendering, loadServerImportMap, componentMap, }) => {
91
+ var _a;
92
+ let designLibraryStatus = editing_1.DesignLibraryStatus.READY;
93
+ let importMap;
94
+ let importMapInfo;
95
+ let Component;
96
+ let importMapError;
97
+ let previewComponentData;
98
+ // load importmap and importmap payload to pass to FE
99
+ // if not provided, or errors during load set error to pass to FE
100
+ if (!loadServerImportMap) {
101
+ importMapError = 'No loadImportMap provided';
102
+ }
103
+ else {
104
+ try {
105
+ const mod = await loadServerImportMap();
106
+ importMap = mod.default;
107
+ importMapInfo = codegen.getImportMapInfo(importMap);
108
+ }
109
+ catch (e) {
110
+ importMapError = `Error loading import map: ${e}`;
111
+ }
112
+ }
113
+ 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];
114
+ const componentUpdateKey = `${editing_1.COMPONENT_UPDATE_CACHE_KEY_PREFIX}${componentToUpdate.uid}`;
115
+ // check if we have an update for this component in the global cache
116
+ if (hasCache(componentUpdateKey)) {
117
+ // we have an update, get it and clean the cache
118
+ designLibraryStatus = editing_1.DesignLibraryStatus.RENDERED;
119
+ const updateData = getCacheAndClean(componentUpdateKey);
120
+ // apply the updates to the component rendering
121
+ if (updateData.updatedComponent) {
122
+ (0, editing_1.updateComponent)(componentToUpdate, updateData.updatedComponent.fields, updateData.updatedComponent.params);
123
+ }
124
+ if (updateData.previewComponent && !importMapError) {
125
+ previewComponentData = updateData.previewComponent;
126
+ try {
127
+ // use provided code and import map to create the component instance
128
+ Component = createComponentInstance(importMap, updateData.previewComponent);
129
+ }
130
+ catch (error) {
131
+ // error during component initialization - send error to client
132
+ importMapError = error.toString();
133
+ }
134
+ }
135
+ }
136
+ return (react_1.default.createElement(react_1.default.Fragment, null,
137
+ Component ? (react_1.default.createElement(DesignLibraryErrorBoundary_1.DesignLibraryErrorBoundary, { uid: componentToUpdate.uid },
138
+ react_1.default.createElement(Placeholder_1.PlaceholderMetadata, { rendering: componentToUpdate },
139
+ react_1.default.createElement(Component, { fields: componentToUpdate.fields, params: componentToUpdate.params })))) : (react_1.default.createElement(Placeholder_1.AppPlaceholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap })),
140
+ react_1.default.createElement(DesignLibraryClientEvents_1.DesignLibraryVariantGenerationEvents, { designLibraryStatus: designLibraryStatus, importMap: importMapInfo,
141
+ // pass a new object since we have mutated the original which leads to old reference passed to the client
142
+ component: Object.assign({}, componentToUpdate), importMapError: importMapError, previewComponentData: previewComponentData })));
143
+ };
144
+ exports.DesignLibraryServerVariantGeneration = DesignLibraryServerVariantGeneration;
145
+ /**
146
+ * Design Library component for rendering server components in app router application when variant generation is not enabled.
147
+ *
148
+ * Renders the **real** Sitecore component for `library` / `library-metadata` modes and,
149
+ * wires the **component update** handshake so the parent (Design Library) can send
150
+ * updated component props.
151
+ * Also renders the DesignLibraryPreviewEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
152
+ * @param {DesignLibraryServerPreviewProps} props The props. {@link DesignLibraryServerPreviewProps}
153
+ * @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
154
+ */
155
+ const DesignLibraryServerPreview = async ({ page, rendering, componentMap, }) => {
156
+ var _a;
157
+ let designLibraryStatus = editing_1.DesignLibraryStatus.READY;
158
+ 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];
159
+ const componentUpdateKey = `${editing_1.COMPONENT_UPDATE_CACHE_KEY_PREFIX}${componentToUpdate.uid}`;
160
+ // check if we have an update for this component in the global cache
161
+ if (hasCache(componentUpdateKey)) {
162
+ // we have an update, get it and clean the cache
163
+ designLibraryStatus = editing_1.DesignLibraryStatus.RENDERED;
164
+ const updateData = getCacheAndClean(componentUpdateKey);
165
+ // apply the updates to the component rendering
166
+ if (updateData.updatedComponent) {
167
+ (0, editing_1.updateComponent)(componentToUpdate, updateData.updatedComponent.fields, updateData.updatedComponent.params);
168
+ }
169
+ }
170
+ return (react_1.default.createElement(react_1.default.Fragment, null,
171
+ react_1.default.createElement(Placeholder_1.AppPlaceholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap }),
172
+ react_1.default.createElement(DesignLibraryClientEvents_1.DesignLibraryPreviewEvents, { designLibraryStatus: designLibraryStatus,
173
+ // pass a new object since we have mutated the original which leads to old reference passed to the client
174
+ component: Object.assign({}, componentToUpdate) })));
175
+ };
176
+ exports.DesignLibraryServerPreview = DesignLibraryServerPreview;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DesignLibraryApp = exports.DesignLibrary = void 0;
4
+ var DesignLibrary_1 = require("./DesignLibrary");
5
+ Object.defineProperty(exports, "DesignLibrary", { enumerable: true, get: function () { return DesignLibrary_1.DesignLibrary; } });
6
+ var DesignLibraryApp_1 = require("./DesignLibraryApp");
7
+ Object.defineProperty(exports, "DesignLibraryApp", { enumerable: true, get: function () { return DesignLibraryApp_1.DesignLibraryApp; } });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -23,12 +14,12 @@ const models_1 = require("../Placeholder/models");
23
14
  * @returns rendered BYOCWrapper component
24
15
  * @public
25
16
  */
26
- const BYOCServerWrapper = (props) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const BYOCServerWrapper = async (props) => {
27
18
  var _a;
28
19
  const params = ((_a = props.rendering) === null || _a === void 0 ? void 0 : _a.params) || {};
29
20
  // only pass serializable props to the client BYOC component
30
21
  const serializableProps = Object.fromEntries(Object.entries(props).filter(([key]) => !models_1.nonSerializedPlaceholderProps.includes(key)));
31
- const finalProps = Object.assign(Object.assign({}, (yield (0, feaas_utils_1.fetchBYOCComponentServerProps)(params))), serializableProps);
22
+ const finalProps = Object.assign(Object.assign({}, (await (0, feaas_utils_1.fetchBYOCComponentServerProps)(params))), serializableProps);
32
23
  return react_1.default.createElement(BYOCWrapper_1.BYOCWrapper, Object.assign({}, finalProps));
33
- });
24
+ };
34
25
  exports.BYOCServerWrapper = BYOCServerWrapper;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -23,13 +14,13 @@ const models_1 = require("../Placeholder/models");
23
14
  * @returns rendered FEaaSWrapper component
24
15
  * @public
25
16
  */
26
- const FEaaSServerWrapper = (props) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const FEaaSServerWrapper = async (props) => {
27
18
  var _a, _b;
28
19
  const params = ((_a = props.rendering) === null || _a === void 0 ? void 0 : _a.params) || {};
29
20
  const isPageStateNormal = (_b = props.page) === null || _b === void 0 ? void 0 : _b.mode.isNormal;
30
21
  // only pass serializable props to the client FEaaS component
31
22
  const serializableProps = Object.fromEntries(Object.entries(props).filter(([key]) => !models_1.nonSerializedPlaceholderProps.includes(key)));
32
- const finalProps = Object.assign(Object.assign({}, (yield (0, feaas_utils_1.fetchFEaaSComponentServerProps)(params, isPageStateNormal))), serializableProps);
23
+ const finalProps = Object.assign(Object.assign({}, (await (0, feaas_utils_1.fetchFEaaSComponentServerProps)(params, isPageStateNormal))), serializableProps);
33
24
  return react_1.default.createElement(FEaaSWrapper_1.FEaaSWrapper, Object.assign({}, finalProps));
34
- });
25
+ };
35
26
  exports.FEaaSServerWrapper = FEaaSServerWrapper;