@sitecore-content-sdk/react 2.0.0-canary.9 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +202 -202
- package/dist/cjs/components/DesignLibrary/DesignLibrary.js +2 -2
- package/dist/cjs/components/DesignLibrary/DesignLibraryErrorBoundary.js +6 -0
- package/dist/cjs/components/DesignLibrary/index.js +3 -3
- package/dist/cjs/components/ErrorBoundary.js +1 -0
- package/dist/cjs/components/Form.js +4 -2
- package/dist/cjs/components/Placeholder/PlaceholderMetadata.js +1 -0
- package/dist/cjs/index.js +6 -3
- package/dist/esm/components/DesignLibrary/DesignLibrary.js +2 -2
- package/dist/esm/components/DesignLibrary/DesignLibraryErrorBoundary.js +6 -0
- package/dist/esm/components/DesignLibrary/index.js +1 -1
- package/dist/esm/components/ErrorBoundary.js +1 -0
- package/dist/esm/components/Form.js +4 -2
- package/dist/esm/components/Placeholder/PlaceholderMetadata.js +1 -0
- package/dist/esm/index.js +3 -2
- package/package.json +7 -6
- package/types/components/DesignLibrary/DesignLibraryErrorBoundary.d.ts +13 -0
- package/types/components/DesignLibrary/DesignLibraryErrorBoundary.d.ts.map +1 -1
- package/types/components/DesignLibrary/index.d.ts +2 -1
- package/types/components/DesignLibrary/index.d.ts.map +1 -1
- package/types/components/DesignLibrary/models.d.ts +13 -55
- package/types/components/DesignLibrary/models.d.ts.map +1 -1
- package/types/components/ErrorBoundary.d.ts +1 -0
- package/types/components/ErrorBoundary.d.ts.map +1 -1
- package/types/components/Form.d.ts.map +1 -1
- package/types/components/Placeholder/PlaceholderMetadata.d.ts +1 -0
- package/types/components/Placeholder/PlaceholderMetadata.d.ts.map +1 -1
- package/types/index.d.ts +3 -2
- package/types/index.d.ts.map +1 -1
- package/dist/cjs/components/DesignLibrary/DesignLibraryApp.js +0 -31
- package/dist/cjs/components/DesignLibrary/DesignLibraryClientEvents.js +0 -139
- package/dist/cjs/components/DesignLibrary/DesignLibraryServer.js +0 -212
- package/dist/cjs/server-actions/update-server-component-action.js +0 -51
- package/dist/esm/components/DesignLibrary/DesignLibraryApp.js +0 -24
- package/dist/esm/components/DesignLibrary/DesignLibraryClientEvents.js +0 -100
- package/dist/esm/components/DesignLibrary/DesignLibraryServer.js +0 -169
- package/dist/esm/server-actions/update-server-component-action.js +0 -47
- package/types/components/DesignLibrary/DesignLibraryApp.d.ts +0 -14
- package/types/components/DesignLibrary/DesignLibraryApp.d.ts.map +0 -1
- package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts +0 -21
- package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts.map +0 -1
- package/types/components/DesignLibrary/DesignLibraryServer.d.ts +0 -38
- package/types/components/DesignLibrary/DesignLibraryServer.d.ts.map +0 -1
- package/types/server-actions/update-server-component-action.d.ts +0 -58
- package/types/server-actions/update-server-component-action.d.ts.map +0 -1
|
@@ -1,212 +0,0 @@
|
|
|
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/content/layout");
|
|
43
|
-
const DesignLibraryClientEvents_1 = require("./DesignLibraryClientEvents");
|
|
44
|
-
const globalCache = __importStar(require("@sitecore-content-sdk/core/tools"));
|
|
45
|
-
const editing_1 = require("@sitecore-content-sdk/content/editing");
|
|
46
|
-
const codegen = __importStar(require("@sitecore-content-sdk/content/codegen"));
|
|
47
|
-
const Placeholder_1 = require("../Placeholder");
|
|
48
|
-
const DesignLibraryErrorBoundary_1 = require("./DesignLibraryErrorBoundary");
|
|
49
|
-
const ErrorBoundary_1 = require("../ErrorBoundary");
|
|
50
|
-
let { getCacheAndClean, hasCache } = globalCache;
|
|
51
|
-
let { createComponentInstance, getImportMapInfo } = codegen;
|
|
52
|
-
let updateComponent = editing_1.updateComponent;
|
|
53
|
-
const __mockDependencies = async (mocks) => {
|
|
54
|
-
getCacheAndClean = mocks.getCacheAndClean;
|
|
55
|
-
hasCache = mocks.hasCache;
|
|
56
|
-
createComponentInstance = mocks.createComponentInstance;
|
|
57
|
-
if (mocks.updateComponent) {
|
|
58
|
-
updateComponent = mocks.updateComponent;
|
|
59
|
-
}
|
|
60
|
-
if (mocks.getImportMapInfo) {
|
|
61
|
-
getImportMapInfo = mocks.getImportMapInfo;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
exports.__mockDependencies = __mockDependencies;
|
|
65
|
-
/**
|
|
66
|
-
* Design Library component for rendering server components in app router application.
|
|
67
|
-
*
|
|
68
|
-
* Renders the **real** Sitecore component for `library` / `library-metadata` modes and,
|
|
69
|
-
* when generation is enabled (`page.mode.designLibrary.isVariantGeneration === true`),
|
|
70
|
-
* wires the **variant generation** handshake so the parent (Design Library) can send
|
|
71
|
-
* generated code to preview and iterate on.
|
|
72
|
-
* Also renders the DesignLibraryClientEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
73
|
-
* @param {DesignLibraryServerProps} props The props. {@link DesignLibraryServerProps}
|
|
74
|
-
* @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
|
|
75
|
-
*/
|
|
76
|
-
const DesignLibraryServer = async ({ page, componentMap, rendering, loadServerImportMap, }) => {
|
|
77
|
-
var _a;
|
|
78
|
-
if (!page.mode.isDesignLibrary) {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
const isVariantGeneration = (_a = page.mode.designLibrary) === null || _a === void 0 ? void 0 : _a.isVariantGeneration;
|
|
82
|
-
if (isVariantGeneration) {
|
|
83
|
-
return (react_1.default.createElement(exports.DesignLibraryServerVariantGeneration, { page: page, rendering: rendering, loadServerImportMap: loadServerImportMap, componentMap: componentMap }));
|
|
84
|
-
}
|
|
85
|
-
return (react_1.default.createElement(exports.DesignLibraryServerPreview, { page: page, rendering: rendering, componentMap: componentMap }));
|
|
86
|
-
};
|
|
87
|
-
exports.DesignLibraryServer = DesignLibraryServer;
|
|
88
|
-
/**
|
|
89
|
-
* Design Library component for rendering server components in app router application in variant generation mode.
|
|
90
|
-
*
|
|
91
|
-
* Renders the **real** Sitecore component for `library` / `library-metadata` modes on first render and,
|
|
92
|
-
* wires the **variant generation** handshake so the parent (Design Library) can send
|
|
93
|
-
* generated code to preview and iterate on.
|
|
94
|
-
* Also renders the DesignLibraryVariantGenerationEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
95
|
-
* @param {DesignLibraryServerVariantGenerationProps} props The props. {@link DesignLibraryServerVariantGenerationProps}
|
|
96
|
-
* @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
|
|
97
|
-
*/
|
|
98
|
-
const DesignLibraryServerVariantGeneration = async ({ page, rendering, loadServerImportMap, componentMap, }) => {
|
|
99
|
-
var _a, _b;
|
|
100
|
-
let designLibraryStatus = editing_1.DesignLibraryStatus.READY;
|
|
101
|
-
let importMap;
|
|
102
|
-
let importMapInfo;
|
|
103
|
-
let Component;
|
|
104
|
-
let componentInitError;
|
|
105
|
-
let generatedComponentData;
|
|
106
|
-
// load importmap and importmap payload to pass to FE
|
|
107
|
-
// if not provided, or errors during load set error to pass to FE
|
|
108
|
-
if (!loadServerImportMap) {
|
|
109
|
-
componentInitError = 'No loadImportMap provided';
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
try {
|
|
113
|
-
const mod = await loadServerImportMap();
|
|
114
|
-
importMap = mod.default;
|
|
115
|
-
importMapInfo = getImportMapInfo(importMap);
|
|
116
|
-
}
|
|
117
|
-
catch (e) {
|
|
118
|
-
componentInitError = `Error loading import map: ${e}`;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
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}`;
|
|
128
|
-
const componentPreviewKey = `${editing_1.COMPONENT_PREVIEW_CACHE_KEY_PREFIX}${uid}`;
|
|
129
|
-
// check if we have an update for this component in the global cache
|
|
130
|
-
if (hasCache(componentUpdateKey)) {
|
|
131
|
-
// we have fields/params update, get it and clean the cache
|
|
132
|
-
designLibraryStatus = editing_1.DesignLibraryStatus.RENDERED;
|
|
133
|
-
const updateData = getCacheAndClean(componentUpdateKey);
|
|
134
|
-
// apply the updates to the component rendering
|
|
135
|
-
if (updateData === null || updateData === void 0 ? void 0 : updateData.rendering) {
|
|
136
|
-
updateComponent(componentToUpdate, updateData.rendering.fields, updateData.rendering.params);
|
|
137
|
-
}
|
|
138
|
-
// generate the component instance if we are dealing with an AI-generated component
|
|
139
|
-
if ((updateData === null || updateData === void 0 ? void 0 : updateData.generatedComponentData) && !componentInitError && importMap) {
|
|
140
|
-
generatedComponentData = updateData.generatedComponentData;
|
|
141
|
-
try {
|
|
142
|
-
// use provided code and import map to create the component instance
|
|
143
|
-
Component = createComponentInstance(importMap, updateData.generatedComponentData);
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
// error during component initialization - send error to client
|
|
147
|
-
componentInitError = error.toString();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
else if (hasCache(componentPreviewKey) && !componentInitError && importMap) {
|
|
152
|
-
// we have a preview update, get it and clean the cache
|
|
153
|
-
designLibraryStatus = editing_1.DesignLibraryStatus.RENDERED;
|
|
154
|
-
const previewData = getCacheAndClean(componentPreviewKey);
|
|
155
|
-
componentInitError = previewData === null || previewData === void 0 ? void 0 : previewData.error;
|
|
156
|
-
if (previewData === null || previewData === void 0 ? void 0 : previewData.generatedComponentData) {
|
|
157
|
-
generatedComponentData = previewData.generatedComponentData;
|
|
158
|
-
try {
|
|
159
|
-
// use provided code and import map to create the component instance
|
|
160
|
-
Component = createComponentInstance(importMap, previewData.generatedComponentData);
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
// error during component initialization - send error to client
|
|
164
|
-
componentInitError = error.toString();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
169
|
-
Component ? (react_1.default.createElement(DesignLibraryErrorBoundary_1.DesignLibraryErrorBoundary, { uid: componentToUpdate.uid },
|
|
170
|
-
react_1.default.createElement(Placeholder_1.PlaceholderMetadata, { rendering: componentToUpdate },
|
|
171
|
-
react_1.default.createElement(Component, { fields: componentToUpdate.fields, params: componentToUpdate.params, key: Date.now() })))) : (react_1.default.createElement(Placeholder_1.AppPlaceholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap, key: Date.now() })),
|
|
172
|
-
react_1.default.createElement(DesignLibraryClientEvents_1.DesignLibraryVariantGenerationEvents, { designLibraryStatus: designLibraryStatus, importMap: importMapInfo,
|
|
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), componentInitError: componentInitError, generatedComponentData: generatedComponentData })));
|
|
175
|
-
};
|
|
176
|
-
exports.DesignLibraryServerVariantGeneration = DesignLibraryServerVariantGeneration;
|
|
177
|
-
/**
|
|
178
|
-
* Design Library component for rendering server components in app router application when variant generation is not enabled.
|
|
179
|
-
*
|
|
180
|
-
* Renders the **real** Sitecore component for `library` / `library-metadata` modes and,
|
|
181
|
-
* wires the **component update** handshake so the parent (Design Library) can send
|
|
182
|
-
* updated component props.
|
|
183
|
-
* Also renders the DesignLibraryPreviewEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
184
|
-
* @param {DesignLibraryServerPreviewProps} props The props. {@link DesignLibraryServerPreviewProps}
|
|
185
|
-
* @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
|
|
186
|
-
*/
|
|
187
|
-
const DesignLibraryServerPreview = async ({ page, rendering, componentMap, }) => {
|
|
188
|
-
var _a, _b;
|
|
189
|
-
let designLibraryStatus = editing_1.DesignLibraryStatus.READY;
|
|
190
|
-
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];
|
|
191
|
-
if (!componentToUpdate)
|
|
192
|
-
return react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: "Rendering data is missing" });
|
|
193
|
-
if (!componentToUpdate.uid)
|
|
194
|
-
return react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
|
|
195
|
-
const componentUpdateKey = `${editing_1.COMPONENT_UPDATE_CACHE_KEY_PREFIX}${componentToUpdate.uid}`;
|
|
196
|
-
// check if we have an update for this component in the global cache
|
|
197
|
-
if (hasCache(componentUpdateKey)) {
|
|
198
|
-
// we have an update, get it and clean the cache
|
|
199
|
-
designLibraryStatus = editing_1.DesignLibraryStatus.RENDERED;
|
|
200
|
-
const updateData = getCacheAndClean(componentUpdateKey);
|
|
201
|
-
// apply the updates to the component rendering
|
|
202
|
-
if (updateData === null || updateData === void 0 ? void 0 : updateData.rendering) {
|
|
203
|
-
updateComponent(componentToUpdate, updateData.rendering.fields, updateData.rendering.params);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
207
|
-
react_1.default.createElement(Placeholder_1.AppPlaceholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap, key: Date.now() }),
|
|
208
|
-
react_1.default.createElement(DesignLibraryClientEvents_1.DesignLibraryPreviewEvents, { designLibraryStatus: designLibraryStatus,
|
|
209
|
-
// pass a new object since we have mutated the original which leads to old reference passed to the client
|
|
210
|
-
component: Object.assign({}, componentToUpdate) })));
|
|
211
|
-
};
|
|
212
|
-
exports.DesignLibraryServerPreview = DesignLibraryServerPreview;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
'use server';
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.updateComponentAction = updateComponentAction;
|
|
5
|
-
exports.previewComponentAction = previewComponentAction;
|
|
6
|
-
const content_1 = require("@sitecore-content-sdk/content");
|
|
7
|
-
const codegen_1 = require("@sitecore-content-sdk/content/codegen");
|
|
8
|
-
const tools_1 = require("@sitecore-content-sdk/core/tools");
|
|
9
|
-
const editing_1 = require("@sitecore-content-sdk/content/editing");
|
|
10
|
-
/**
|
|
11
|
-
* Server action to update global cache with the provided component updates received from Design Library.
|
|
12
|
-
* Stores the given {@link ComponentUpdateModel} in the global cache using a key based on the component UID.
|
|
13
|
-
* This enables rendering dynamic updates of server components inside Design Library
|
|
14
|
-
* @param {ComponentUpdateModel} updatedComponent - The component update model containing the UID and optional updated or preview component data.
|
|
15
|
-
* @returns A Promise that resolves when the cache has been updated.
|
|
16
|
-
*/
|
|
17
|
-
async function updateComponentAction(updatedComponent) {
|
|
18
|
-
content_1.debug.editing(`Updating server component cache for Update Component: ${updatedComponent.uid}`);
|
|
19
|
-
(0, tools_1.setCache)(`${editing_1.COMPONENT_UPDATE_CACHE_KEY_PREFIX}${updatedComponent.uid}`, updatedComponent);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Server action to update global cache with the generated component data in variant generation mode
|
|
23
|
-
* The generated component data is retrieved from a secured cache endpoint via the provided event arguments.
|
|
24
|
-
* This enables rendering dynamic updates of server components inside Design Library
|
|
25
|
-
* @param {PreviewEventModel} previewEvent - The preview event model containing the UID and the preview event arguments with cache information to fetch the generated component data.
|
|
26
|
-
* @param {string} [edgeUrl] - Optional Edge URL to fetch the generated component data.
|
|
27
|
-
* @returns A Promise that resolves when the cache has been updated.
|
|
28
|
-
*/
|
|
29
|
-
async function previewComponentAction(previewEvent, edgeUrl) {
|
|
30
|
-
content_1.debug.editing(`Updating server component cache for Preview Component: ${previewEvent.uid}`);
|
|
31
|
-
const updatedComponent = {
|
|
32
|
-
uid: previewEvent.uid,
|
|
33
|
-
generatedComponentData: undefined,
|
|
34
|
-
error: undefined,
|
|
35
|
-
};
|
|
36
|
-
if (previewEvent.args) {
|
|
37
|
-
// we've received a component preview event from the Design Library, so we need to fetch the generated component data from secured endpoint
|
|
38
|
-
try {
|
|
39
|
-
updatedComponent.generatedComponentData = await (0, codegen_1.fetchGeneratedComponentFromCache)(previewEvent.args.message.cache.id, previewEvent.args.message.cache.token, edgeUrl);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
content_1.debug.editing(`Error fetching generated component data from cache for Component: ${previewEvent.uid}`, error);
|
|
43
|
-
updatedComponent.error = error instanceof Error ? error.message : String(error);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
content_1.debug.editing(`No preview event arguments provided for Component: ${previewEvent.uid}`);
|
|
48
|
-
updatedComponent.error = 'No preview event arguments provided';
|
|
49
|
-
}
|
|
50
|
-
(0, tools_1.setCache)(`${editing_1.COMPONENT_PREVIEW_CACHE_KEY_PREFIX}${updatedComponent.uid}`, updatedComponent);
|
|
51
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { EDITING_COMPONENT_PLACEHOLDER } from '@sitecore-content-sdk/content/layout';
|
|
3
|
-
import { DesignLibraryServer } from './DesignLibraryServer';
|
|
4
|
-
import { DesignLibrary } from './DesignLibrary';
|
|
5
|
-
/**
|
|
6
|
-
* Design Library component intended to be used by the NextJs app router application
|
|
7
|
-
* This component serves as a router between client and server component rendering modes for the Design Library.
|
|
8
|
-
* It inspects the component type from the component map and
|
|
9
|
-
* delegates to the appropriate rendering implementation:
|
|
10
|
-
* - Client components are rendered using the `DesignLibrary` component
|
|
11
|
-
* - Server components are rendered using the `DesignLibraryServer` component
|
|
12
|
-
* @param {DesingLibraryAppProps} props - The properties for the Design Library App.
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
export const DesignLibraryApp = ({ page, componentMap, loadServerImportMap, }) => {
|
|
16
|
-
var _a;
|
|
17
|
-
const { route } = page.layout.sitecore;
|
|
18
|
-
if (!route)
|
|
19
|
-
return null;
|
|
20
|
-
const rendering = (_a = route === null || route === void 0 ? void 0 : route.placeholders[EDITING_COMPONENT_PLACEHOLDER]) === null || _a === void 0 ? void 0 : _a[0];
|
|
21
|
-
const component = componentMap.get((rendering === null || rendering === void 0 ? void 0 : rendering.componentName) || '');
|
|
22
|
-
const isClient = component && component.componentType === 'client';
|
|
23
|
-
return (React.createElement(React.Fragment, null, isClient ? (React.createElement(DesignLibrary, null)) : (React.createElement(DesignLibraryServer, { page: page, componentMap: componentMap, loadServerImportMap: loadServerImportMap, rendering: route }))));
|
|
24
|
-
};
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import React, { useEffect } from 'react';
|
|
3
|
-
import * as dlHelpers from '@sitecore-content-sdk/content/editing';
|
|
4
|
-
import * as codegen from '@sitecore-content-sdk/content/codegen';
|
|
5
|
-
import { updateComponentAction, previewComponentAction, } from '../../server-actions/update-server-component-action';
|
|
6
|
-
import { useSitecore } from '../SitecoreProvider';
|
|
7
|
-
let { getDesignLibraryComponentPropsEvent, addServerComponentPreviewHandler, getDesignLibraryImportMapEvent, addStyleElement, sendErrorEvent, } = codegen;
|
|
8
|
-
let { getDesignLibraryStatusEvent, addComponentUpdateHandler, postToDesignLibrary } = dlHelpers;
|
|
9
|
-
let _updateComponentAction = updateComponentAction;
|
|
10
|
-
let _previewComponentAction = previewComponentAction;
|
|
11
|
-
export const __mockDependencies = (mocks) => {
|
|
12
|
-
postToDesignLibrary = mocks.postToDesignLibrary;
|
|
13
|
-
addComponentUpdateHandler = mocks.addComponentUpdateHandler;
|
|
14
|
-
_updateComponentAction = mocks.updateComponentAction;
|
|
15
|
-
_previewComponentAction = mocks.previewComponentAction;
|
|
16
|
-
addServerComponentPreviewHandler = mocks.addServerComponentPreviewHandler;
|
|
17
|
-
getDesignLibraryImportMapEvent = mocks.getDesignLibraryImportMapEvent;
|
|
18
|
-
getDesignLibraryComponentPropsEvent = mocks.getDesignLibraryComponentPropsEvent;
|
|
19
|
-
addStyleElement = mocks.addStyleElement;
|
|
20
|
-
sendErrorEvent = mocks.sendErrorEvent;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Design Library component for rendering server components in app router application.
|
|
24
|
-
* DesignLibraryPreviewEvents component serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
25
|
-
* 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.
|
|
26
|
-
* @param {DesignLibraryPreviewEventsProps} props The props. {@link DesignLibraryPreviewEventsProps}
|
|
27
|
-
* @returns {JSX.Element} empty JSX element.
|
|
28
|
-
*/
|
|
29
|
-
export const DesignLibraryPreviewEvents = ({ designLibraryStatus, component, }) => {
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
if (!(component === null || component === void 0 ? void 0 : component.uid))
|
|
32
|
-
return;
|
|
33
|
-
postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid, true));
|
|
34
|
-
const unsubUpdate = addComponentUpdateHandler(component, (rendering) => {
|
|
35
|
-
_updateComponentAction({ uid: rendering.uid, rendering });
|
|
36
|
-
});
|
|
37
|
-
return () => {
|
|
38
|
-
unsubUpdate && unsubUpdate();
|
|
39
|
-
};
|
|
40
|
-
}, [component, designLibraryStatus]);
|
|
41
|
-
return React.createElement(React.Fragment, null);
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Design Library component for rendering server components in app router application.
|
|
45
|
-
* DesignLibraryVariantGenerationEvents component serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side in variant generation mode.
|
|
46
|
-
* 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.
|
|
47
|
-
* If the import map is not present then the import map error will be sent to Design Studio.
|
|
48
|
-
* @param {DesignLibraryVariantGenerationEventsProps} props The props. {@link DesignLibraryVariantGenerationEventsProps}
|
|
49
|
-
* @returns {JSX.Element} empty JSX element.
|
|
50
|
-
*/
|
|
51
|
-
export const DesignLibraryVariantGenerationEvents = ({ designLibraryStatus, component, importMap, componentInitError, generatedComponentData, }) => {
|
|
52
|
-
var _a;
|
|
53
|
-
const { api } = useSitecore();
|
|
54
|
-
const edgeUrl = (_a = api === null || api === void 0 ? void 0 : api.edge) === null || _a === void 0 ? void 0 : _a.edgeUrl;
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
var _a;
|
|
57
|
-
if (!(component === null || component === void 0 ? void 0 : component.uid))
|
|
58
|
-
return;
|
|
59
|
-
postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid, true));
|
|
60
|
-
const unsubUpdate = addComponentUpdateHandler(component, (rendering) => {
|
|
61
|
-
_updateComponentAction({
|
|
62
|
-
uid: rendering.uid,
|
|
63
|
-
rendering,
|
|
64
|
-
generatedComponentData,
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
const unsubPreview = addServerComponentPreviewHandler((eventArgs) => {
|
|
68
|
-
_previewComponentAction({
|
|
69
|
-
uid: component.uid,
|
|
70
|
-
args: eventArgs,
|
|
71
|
-
}, edgeUrl);
|
|
72
|
-
});
|
|
73
|
-
if (componentInitError) {
|
|
74
|
-
// an error occurred during initialization of the component on the server side
|
|
75
|
-
sendErrorEvent(component.uid, componentInitError, codegen.DesignLibraryPreviewError.RenderInit);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
const importMapEvent = getDesignLibraryImportMapEvent(component.uid, importMap);
|
|
79
|
-
postToDesignLibrary(importMapEvent);
|
|
80
|
-
const propsEvent = getDesignLibraryComponentPropsEvent(component.uid, component.fields, component.params);
|
|
81
|
-
postToDesignLibrary(propsEvent);
|
|
82
|
-
if ((_a = generatedComponentData === null || generatedComponentData === void 0 ? void 0 : generatedComponentData.styles) === null || _a === void 0 ? void 0 : _a.content) {
|
|
83
|
-
// the generated component has custom styles, so add the css in style element and add it to document head
|
|
84
|
-
addStyleElement(generatedComponentData.styles.content);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return () => {
|
|
88
|
-
unsubUpdate && unsubUpdate();
|
|
89
|
-
unsubPreview && unsubPreview();
|
|
90
|
-
};
|
|
91
|
-
}, [
|
|
92
|
-
component,
|
|
93
|
-
designLibraryStatus,
|
|
94
|
-
importMap,
|
|
95
|
-
componentInitError,
|
|
96
|
-
generatedComponentData,
|
|
97
|
-
edgeUrl,
|
|
98
|
-
]);
|
|
99
|
-
return React.createElement(React.Fragment, null);
|
|
100
|
-
};
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { EDITING_COMPONENT_PLACEHOLDER } from '@sitecore-content-sdk/content/layout';
|
|
4
|
-
import { DesignLibraryPreviewEvents, DesignLibraryVariantGenerationEvents, } from './DesignLibraryClientEvents';
|
|
5
|
-
import * as globalCache from '@sitecore-content-sdk/core/tools';
|
|
6
|
-
import { DesignLibraryStatus, COMPONENT_UPDATE_CACHE_KEY_PREFIX, COMPONENT_PREVIEW_CACHE_KEY_PREFIX, updateComponent as updateComponentOriginal, } from '@sitecore-content-sdk/content/editing';
|
|
7
|
-
import * as codegen from '@sitecore-content-sdk/content/codegen';
|
|
8
|
-
import { AppPlaceholder, PlaceholderMetadata } from '../Placeholder';
|
|
9
|
-
import { DesignLibraryErrorBoundary } from './DesignLibraryErrorBoundary';
|
|
10
|
-
import { ErrorComponent } from '../ErrorBoundary';
|
|
11
|
-
let { getCacheAndClean, hasCache } = globalCache;
|
|
12
|
-
let { createComponentInstance, getImportMapInfo } = codegen;
|
|
13
|
-
let updateComponent = updateComponentOriginal;
|
|
14
|
-
export const __mockDependencies = async (mocks) => {
|
|
15
|
-
getCacheAndClean = mocks.getCacheAndClean;
|
|
16
|
-
hasCache = mocks.hasCache;
|
|
17
|
-
createComponentInstance = mocks.createComponentInstance;
|
|
18
|
-
if (mocks.updateComponent) {
|
|
19
|
-
updateComponent = mocks.updateComponent;
|
|
20
|
-
}
|
|
21
|
-
if (mocks.getImportMapInfo) {
|
|
22
|
-
getImportMapInfo = mocks.getImportMapInfo;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Design Library component for rendering server components in app router application.
|
|
27
|
-
*
|
|
28
|
-
* Renders the **real** Sitecore component for `library` / `library-metadata` modes and,
|
|
29
|
-
* when generation is enabled (`page.mode.designLibrary.isVariantGeneration === true`),
|
|
30
|
-
* wires the **variant generation** handshake so the parent (Design Library) can send
|
|
31
|
-
* generated code to preview and iterate on.
|
|
32
|
-
* Also renders the DesignLibraryClientEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
33
|
-
* @param {DesignLibraryServerProps} props The props. {@link DesignLibraryServerProps}
|
|
34
|
-
* @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
|
|
35
|
-
*/
|
|
36
|
-
export const DesignLibraryServer = async ({ page, componentMap, rendering, loadServerImportMap, }) => {
|
|
37
|
-
var _a;
|
|
38
|
-
if (!page.mode.isDesignLibrary) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
const isVariantGeneration = (_a = page.mode.designLibrary) === null || _a === void 0 ? void 0 : _a.isVariantGeneration;
|
|
42
|
-
if (isVariantGeneration) {
|
|
43
|
-
return (React.createElement(DesignLibraryServerVariantGeneration, { page: page, rendering: rendering, loadServerImportMap: loadServerImportMap, componentMap: componentMap }));
|
|
44
|
-
}
|
|
45
|
-
return (React.createElement(DesignLibraryServerPreview, { page: page, rendering: rendering, componentMap: componentMap }));
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Design Library component for rendering server components in app router application in variant generation mode.
|
|
49
|
-
*
|
|
50
|
-
* Renders the **real** Sitecore component for `library` / `library-metadata` modes on first render and,
|
|
51
|
-
* wires the **variant generation** handshake so the parent (Design Library) can send
|
|
52
|
-
* generated code to preview and iterate on.
|
|
53
|
-
* Also renders the DesignLibraryVariantGenerationEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
54
|
-
* @param {DesignLibraryServerVariantGenerationProps} props The props. {@link DesignLibraryServerVariantGenerationProps}
|
|
55
|
-
* @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
|
|
56
|
-
*/
|
|
57
|
-
export const DesignLibraryServerVariantGeneration = async ({ page, rendering, loadServerImportMap, componentMap, }) => {
|
|
58
|
-
var _a, _b;
|
|
59
|
-
let designLibraryStatus = DesignLibraryStatus.READY;
|
|
60
|
-
let importMap;
|
|
61
|
-
let importMapInfo;
|
|
62
|
-
let Component;
|
|
63
|
-
let componentInitError;
|
|
64
|
-
let generatedComponentData;
|
|
65
|
-
// load importmap and importmap payload to pass to FE
|
|
66
|
-
// if not provided, or errors during load set error to pass to FE
|
|
67
|
-
if (!loadServerImportMap) {
|
|
68
|
-
componentInitError = 'No loadImportMap provided';
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
try {
|
|
72
|
-
const mod = await loadServerImportMap();
|
|
73
|
-
importMap = mod.default;
|
|
74
|
-
importMapInfo = getImportMapInfo(importMap);
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
componentInitError = `Error loading import map: ${e}`;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
let componentToUpdate = (_b = (_a = rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) === null || _a === void 0 ? void 0 : _a[EDITING_COMPONENT_PLACEHOLDER]) === null || _b === void 0 ? void 0 : _b[0];
|
|
81
|
-
if (!componentToUpdate)
|
|
82
|
-
return React.createElement(ErrorComponent, { message: "Rendering data is missing" });
|
|
83
|
-
if (!componentToUpdate.uid)
|
|
84
|
-
return React.createElement(ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
|
|
85
|
-
const uid = componentToUpdate.uid;
|
|
86
|
-
const componentUpdateKey = `${COMPONENT_UPDATE_CACHE_KEY_PREFIX}${uid}`;
|
|
87
|
-
const componentPreviewKey = `${COMPONENT_PREVIEW_CACHE_KEY_PREFIX}${uid}`;
|
|
88
|
-
// check if we have an update for this component in the global cache
|
|
89
|
-
if (hasCache(componentUpdateKey)) {
|
|
90
|
-
// we have fields/params update, get it and clean the cache
|
|
91
|
-
designLibraryStatus = DesignLibraryStatus.RENDERED;
|
|
92
|
-
const updateData = getCacheAndClean(componentUpdateKey);
|
|
93
|
-
// apply the updates to the component rendering
|
|
94
|
-
if (updateData === null || updateData === void 0 ? void 0 : updateData.rendering) {
|
|
95
|
-
updateComponent(componentToUpdate, updateData.rendering.fields, updateData.rendering.params);
|
|
96
|
-
}
|
|
97
|
-
// generate the component instance if we are dealing with an AI-generated component
|
|
98
|
-
if ((updateData === null || updateData === void 0 ? void 0 : updateData.generatedComponentData) && !componentInitError && importMap) {
|
|
99
|
-
generatedComponentData = updateData.generatedComponentData;
|
|
100
|
-
try {
|
|
101
|
-
// use provided code and import map to create the component instance
|
|
102
|
-
Component = createComponentInstance(importMap, updateData.generatedComponentData);
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
// error during component initialization - send error to client
|
|
106
|
-
componentInitError = error.toString();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else if (hasCache(componentPreviewKey) && !componentInitError && importMap) {
|
|
111
|
-
// we have a preview update, get it and clean the cache
|
|
112
|
-
designLibraryStatus = DesignLibraryStatus.RENDERED;
|
|
113
|
-
const previewData = getCacheAndClean(componentPreviewKey);
|
|
114
|
-
componentInitError = previewData === null || previewData === void 0 ? void 0 : previewData.error;
|
|
115
|
-
if (previewData === null || previewData === void 0 ? void 0 : previewData.generatedComponentData) {
|
|
116
|
-
generatedComponentData = previewData.generatedComponentData;
|
|
117
|
-
try {
|
|
118
|
-
// use provided code and import map to create the component instance
|
|
119
|
-
Component = createComponentInstance(importMap, previewData.generatedComponentData);
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
// error during component initialization - send error to client
|
|
123
|
-
componentInitError = error.toString();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return (React.createElement(React.Fragment, null,
|
|
128
|
-
Component ? (React.createElement(DesignLibraryErrorBoundary, { uid: componentToUpdate.uid },
|
|
129
|
-
React.createElement(PlaceholderMetadata, { rendering: componentToUpdate },
|
|
130
|
-
React.createElement(Component, { fields: componentToUpdate.fields, params: componentToUpdate.params, key: Date.now() })))) : (React.createElement(AppPlaceholder, { name: EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap, key: Date.now() })),
|
|
131
|
-
React.createElement(DesignLibraryVariantGenerationEvents, { designLibraryStatus: designLibraryStatus, importMap: importMapInfo,
|
|
132
|
-
// pass a new object since we have mutated the original which leads to old reference passed to the client
|
|
133
|
-
component: Object.assign({}, componentToUpdate), componentInitError: componentInitError, generatedComponentData: generatedComponentData })));
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* Design Library component for rendering server components in app router application when variant generation is not enabled.
|
|
137
|
-
*
|
|
138
|
-
* Renders the **real** Sitecore component for `library` / `library-metadata` modes and,
|
|
139
|
-
* wires the **component update** handshake so the parent (Design Library) can send
|
|
140
|
-
* updated component props.
|
|
141
|
-
* Also renders the DesignLibraryPreviewEvents component which serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
142
|
-
* @param {DesignLibraryServerPreviewProps} props The props. {@link DesignLibraryServerPreviewProps}
|
|
143
|
-
* @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
|
|
144
|
-
*/
|
|
145
|
-
export const DesignLibraryServerPreview = async ({ page, rendering, componentMap, }) => {
|
|
146
|
-
var _a, _b;
|
|
147
|
-
let designLibraryStatus = DesignLibraryStatus.READY;
|
|
148
|
-
let componentToUpdate = (_b = (_a = rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) === null || _a === void 0 ? void 0 : _a[EDITING_COMPONENT_PLACEHOLDER]) === null || _b === void 0 ? void 0 : _b[0];
|
|
149
|
-
if (!componentToUpdate)
|
|
150
|
-
return React.createElement(ErrorComponent, { message: "Rendering data is missing" });
|
|
151
|
-
if (!componentToUpdate.uid)
|
|
152
|
-
return React.createElement(ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
|
|
153
|
-
const componentUpdateKey = `${COMPONENT_UPDATE_CACHE_KEY_PREFIX}${componentToUpdate.uid}`;
|
|
154
|
-
// check if we have an update for this component in the global cache
|
|
155
|
-
if (hasCache(componentUpdateKey)) {
|
|
156
|
-
// we have an update, get it and clean the cache
|
|
157
|
-
designLibraryStatus = DesignLibraryStatus.RENDERED;
|
|
158
|
-
const updateData = getCacheAndClean(componentUpdateKey);
|
|
159
|
-
// apply the updates to the component rendering
|
|
160
|
-
if (updateData === null || updateData === void 0 ? void 0 : updateData.rendering) {
|
|
161
|
-
updateComponent(componentToUpdate, updateData.rendering.fields, updateData.rendering.params);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return (React.createElement(React.Fragment, null,
|
|
165
|
-
React.createElement(AppPlaceholder, { name: EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap, key: Date.now() }),
|
|
166
|
-
React.createElement(DesignLibraryPreviewEvents, { designLibraryStatus: designLibraryStatus,
|
|
167
|
-
// pass a new object since we have mutated the original which leads to old reference passed to the client
|
|
168
|
-
component: Object.assign({}, componentToUpdate) })));
|
|
169
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
import { debug } from '@sitecore-content-sdk/content';
|
|
3
|
-
import { fetchGeneratedComponentFromCache, } from '@sitecore-content-sdk/content/codegen';
|
|
4
|
-
import { setCache } from '@sitecore-content-sdk/core/tools';
|
|
5
|
-
import { COMPONENT_UPDATE_CACHE_KEY_PREFIX, COMPONENT_PREVIEW_CACHE_KEY_PREFIX, } from '@sitecore-content-sdk/content/editing';
|
|
6
|
-
/**
|
|
7
|
-
* Server action to update global cache with the provided component updates received from Design Library.
|
|
8
|
-
* Stores the given {@link ComponentUpdateModel} in the global cache using a key based on the component UID.
|
|
9
|
-
* This enables rendering dynamic updates of server components inside Design Library
|
|
10
|
-
* @param {ComponentUpdateModel} updatedComponent - The component update model containing the UID and optional updated or preview component data.
|
|
11
|
-
* @returns A Promise that resolves when the cache has been updated.
|
|
12
|
-
*/
|
|
13
|
-
export async function updateComponentAction(updatedComponent) {
|
|
14
|
-
debug.editing(`Updating server component cache for Update Component: ${updatedComponent.uid}`);
|
|
15
|
-
setCache(`${COMPONENT_UPDATE_CACHE_KEY_PREFIX}${updatedComponent.uid}`, updatedComponent);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Server action to update global cache with the generated component data in variant generation mode
|
|
19
|
-
* The generated component data is retrieved from a secured cache endpoint via the provided event arguments.
|
|
20
|
-
* This enables rendering dynamic updates of server components inside Design Library
|
|
21
|
-
* @param {PreviewEventModel} previewEvent - The preview event model containing the UID and the preview event arguments with cache information to fetch the generated component data.
|
|
22
|
-
* @param {string} [edgeUrl] - Optional Edge URL to fetch the generated component data.
|
|
23
|
-
* @returns A Promise that resolves when the cache has been updated.
|
|
24
|
-
*/
|
|
25
|
-
export async function previewComponentAction(previewEvent, edgeUrl) {
|
|
26
|
-
debug.editing(`Updating server component cache for Preview Component: ${previewEvent.uid}`);
|
|
27
|
-
const updatedComponent = {
|
|
28
|
-
uid: previewEvent.uid,
|
|
29
|
-
generatedComponentData: undefined,
|
|
30
|
-
error: undefined,
|
|
31
|
-
};
|
|
32
|
-
if (previewEvent.args) {
|
|
33
|
-
// we've received a component preview event from the Design Library, so we need to fetch the generated component data from secured endpoint
|
|
34
|
-
try {
|
|
35
|
-
updatedComponent.generatedComponentData = await fetchGeneratedComponentFromCache(previewEvent.args.message.cache.id, previewEvent.args.message.cache.token, edgeUrl);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
debug.editing(`Error fetching generated component data from cache for Component: ${previewEvent.uid}`, error);
|
|
39
|
-
updatedComponent.error = error instanceof Error ? error.message : String(error);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
debug.editing(`No preview event arguments provided for Component: ${previewEvent.uid}`);
|
|
44
|
-
updatedComponent.error = 'No preview event arguments provided';
|
|
45
|
-
}
|
|
46
|
-
setCache(`${COMPONENT_PREVIEW_CACHE_KEY_PREFIX}${updatedComponent.uid}`, updatedComponent);
|
|
47
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { DesingLibraryAppProps } from './models';
|
|
3
|
-
/**
|
|
4
|
-
* Design Library component intended to be used by the NextJs app router application
|
|
5
|
-
* This component serves as a router between client and server component rendering modes for the Design Library.
|
|
6
|
-
* It inspects the component type from the component map and
|
|
7
|
-
* delegates to the appropriate rendering implementation:
|
|
8
|
-
* - Client components are rendered using the `DesignLibrary` component
|
|
9
|
-
* - Server components are rendered using the `DesignLibraryServer` component
|
|
10
|
-
* @param {DesingLibraryAppProps} props - The properties for the Design Library App.
|
|
11
|
-
* @public
|
|
12
|
-
*/
|
|
13
|
-
export declare const DesignLibraryApp: ({ page, componentMap, loadServerImportMap, }: DesingLibraryAppProps) => React.JSX.Element | null;
|
|
14
|
-
//# sourceMappingURL=DesignLibraryApp.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DesignLibraryApp.d.ts","sourceRoot":"","sources":["../../../src/components/DesignLibrary/DesignLibraryApp.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAIjD;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,GAAI,8CAI9B,qBAAqB,6BAsBvB,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { DesignLibraryPreviewEventsProps, DesignLibraryVariantGenerationEventsProps } from './models';
|
|
3
|
-
export declare const __mockDependencies: (mocks: any) => void;
|
|
4
|
-
/**
|
|
5
|
-
* Design Library component for rendering server components in app router application.
|
|
6
|
-
* DesignLibraryPreviewEvents component serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side.
|
|
7
|
-
* 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.
|
|
8
|
-
* @param {DesignLibraryPreviewEventsProps} props The props. {@link DesignLibraryPreviewEventsProps}
|
|
9
|
-
* @returns {JSX.Element} empty JSX element.
|
|
10
|
-
*/
|
|
11
|
-
export declare const DesignLibraryPreviewEvents: ({ designLibraryStatus, component, }: DesignLibraryPreviewEventsProps) => React.JSX.Element;
|
|
12
|
-
/**
|
|
13
|
-
* Design Library component for rendering server components in app router application.
|
|
14
|
-
* DesignLibraryVariantGenerationEvents component serves as a communication bridge between DesignLibraryServer and the Design Studio on the client side in variant generation mode.
|
|
15
|
-
* 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.
|
|
16
|
-
* If the import map is not present then the import map error will be sent to Design Studio.
|
|
17
|
-
* @param {DesignLibraryVariantGenerationEventsProps} props The props. {@link DesignLibraryVariantGenerationEventsProps}
|
|
18
|
-
* @returns {JSX.Element} empty JSX element.
|
|
19
|
-
*/
|
|
20
|
-
export declare const DesignLibraryVariantGenerationEvents: ({ designLibraryStatus, component, importMap, componentInitError, generatedComponentData, }: DesignLibraryVariantGenerationEventsProps) => React.JSX.Element;
|
|
21
|
-
//# sourceMappingURL=DesignLibraryClientEvents.d.ts.map
|