@sitecore-content-sdk/nextjs 2.0.0-canary.8 → 2.0.0
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/cache/page-params.js +30 -0
- package/dist/cjs/client/sitecore-nextjs-client.js +57 -94
- package/dist/cjs/components/BYOCWrapper.js +3 -12
- package/dist/cjs/components/DesignLibrary/DesignLibraryApp.js +31 -0
- package/dist/cjs/components/DesignLibrary/DesignLibraryClientEvents.js +139 -0
- package/dist/cjs/components/DesignLibrary/DesignLibraryServer.js +221 -0
- package/dist/cjs/components/DesignLibrary/index.js +5 -0
- package/dist/cjs/components/DesignLibrary/models.js +2 -0
- package/dist/cjs/components/FEaaSWrapper.js +3 -12
- package/dist/cjs/editing/editing-config-middleware.js +2 -11
- package/dist/cjs/editing/editing-render-middleware.js +3 -12
- package/dist/cjs/editing/feaas-render-middleware.js +2 -11
- package/dist/cjs/editing/utils.js +3 -12
- package/dist/cjs/index.js +12 -2
- package/dist/cjs/initialization/proxy/analytics-adapter.js +71 -0
- package/dist/cjs/initialization/proxy/personalize-adapter.js +72 -0
- package/dist/cjs/middleware/robots-middleware.js +16 -25
- package/dist/cjs/middleware/sitemap-middleware.js +19 -28
- package/dist/cjs/monitoring/healthcheck-middleware.js +2 -11
- package/dist/cjs/proxy/locale-proxy.js +2 -11
- package/dist/cjs/proxy/multisite-proxy.js +2 -11
- package/dist/cjs/proxy/personalize-proxy.js +40 -36
- package/dist/cjs/proxy/proxy.js +3 -12
- package/dist/cjs/proxy/redirects-proxy.js +58 -69
- package/dist/cjs/route-handler/editing-config-route-handler.js +4 -13
- package/dist/cjs/route-handler/editing-render-route-handler.js +17 -28
- package/dist/cjs/route-handler/robots-route-handler.js +5 -14
- package/dist/cjs/route-handler/sitemap-route-handler.js +5 -14
- package/dist/cjs/server-actions/update-server-component-action.js +56 -0
- package/dist/cjs/services/component-props-service.js +63 -80
- package/dist/esm/cache/page-params.js +25 -0
- package/dist/esm/client/sitecore-nextjs-client.js +57 -94
- package/dist/esm/components/BYOCWrapper.js +3 -12
- package/dist/esm/components/DesignLibrary/DesignLibraryApp.js +24 -0
- package/dist/esm/components/DesignLibrary/DesignLibraryClientEvents.js +100 -0
- package/dist/esm/components/DesignLibrary/DesignLibraryServer.js +178 -0
- package/dist/esm/components/DesignLibrary/index.js +1 -0
- package/dist/esm/components/DesignLibrary/models.js +1 -0
- package/dist/esm/components/FEaaSWrapper.js +3 -12
- package/dist/esm/editing/editing-config-middleware.js +2 -11
- package/dist/esm/editing/editing-render-middleware.js +3 -12
- package/dist/esm/editing/feaas-render-middleware.js +2 -11
- package/dist/esm/editing/utils.js +3 -12
- package/dist/esm/index.js +6 -1
- package/dist/esm/initialization/proxy/analytics-adapter.js +66 -0
- package/dist/esm/initialization/proxy/personalize-adapter.js +69 -0
- package/dist/esm/middleware/robots-middleware.js +16 -25
- package/dist/esm/middleware/sitemap-middleware.js +19 -28
- package/dist/esm/monitoring/healthcheck-middleware.js +2 -11
- package/dist/esm/proxy/locale-proxy.js +2 -11
- package/dist/esm/proxy/multisite-proxy.js +2 -11
- package/dist/esm/proxy/personalize-proxy.js +40 -36
- package/dist/esm/proxy/proxy.js +3 -12
- package/dist/esm/proxy/redirects-proxy.js +58 -69
- package/dist/esm/route-handler/editing-config-route-handler.js +4 -13
- package/dist/esm/route-handler/editing-render-route-handler.js +17 -28
- package/dist/esm/route-handler/robots-route-handler.js +5 -14
- package/dist/esm/route-handler/sitemap-route-handler.js +5 -14
- package/dist/esm/server-actions/update-server-component-action.js +52 -0
- package/dist/esm/services/component-props-service.js +63 -80
- package/package.json +10 -10
- package/types/cache/page-params.d.ts +30 -0
- package/types/cache/page-params.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryApp.d.ts +14 -0
- package/types/components/DesignLibrary/DesignLibraryApp.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts +21 -0
- package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryServer.d.ts +38 -0
- package/types/components/DesignLibrary/DesignLibraryServer.d.ts.map +1 -0
- package/types/components/DesignLibrary/index.d.ts +2 -0
- package/types/components/DesignLibrary/index.d.ts.map +1 -0
- package/types/components/DesignLibrary/models.d.ts +60 -0
- package/types/components/DesignLibrary/models.d.ts.map +1 -0
- package/types/index.d.ts +9 -1
- package/types/index.d.ts.map +1 -1
- package/types/initialization/proxy/analytics-adapter.d.ts +30 -0
- package/types/initialization/proxy/analytics-adapter.d.ts.map +1 -0
- package/types/initialization/proxy/personalize-adapter.d.ts +23 -0
- package/types/initialization/proxy/personalize-adapter.d.ts.map +1 -0
- package/types/middleware/robots-middleware.d.ts.map +1 -1
- package/types/middleware/sitemap-middleware.d.ts.map +1 -1
- package/types/proxy/personalize-proxy.d.ts +2 -1
- package/types/proxy/personalize-proxy.d.ts.map +1 -1
- package/types/server-actions/update-server-component-action.d.ts +63 -0
- package/types/server-actions/update-server-component-action.d.ts.map +1 -0
|
@@ -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
|
};
|
|
@@ -19,18 +10,16 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
19
10
|
* @public
|
|
20
11
|
*/
|
|
21
12
|
class ComponentPropsService {
|
|
22
|
-
fetchComponentProps(params) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
context,
|
|
31
|
-
});
|
|
32
|
-
return yield this.execRequests(requests);
|
|
13
|
+
async fetchComponentProps(params) {
|
|
14
|
+
var _a;
|
|
15
|
+
const { layoutData, context, components } = params;
|
|
16
|
+
const requests = await this.collectRequests({
|
|
17
|
+
placeholders: (_a = layoutData.sitecore.route) === null || _a === void 0 ? void 0 : _a.placeholders,
|
|
18
|
+
components,
|
|
19
|
+
layoutData,
|
|
20
|
+
context,
|
|
33
21
|
});
|
|
22
|
+
return await this.execRequests(requests);
|
|
34
23
|
}
|
|
35
24
|
/**
|
|
36
25
|
* Go through layout service data, check all renderings using displayName, which should make some side effects.
|
|
@@ -43,67 +32,63 @@ class ComponentPropsService {
|
|
|
43
32
|
* @param {ComponentPropsRequest[]} params.requests
|
|
44
33
|
* @returns {ComponentPropsRequest[]} array of requests
|
|
45
34
|
*/
|
|
46
|
-
collectRequests(params) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
async collectRequests(params) {
|
|
36
|
+
const { placeholders = {}, components, layoutData, context } = params;
|
|
37
|
+
// Will be called on first round
|
|
38
|
+
if (!params.requests) {
|
|
39
|
+
params.requests = [];
|
|
40
|
+
}
|
|
41
|
+
const renderings = this.flatRenderings(placeholders);
|
|
42
|
+
const actions = renderings.map(async (r) => {
|
|
43
|
+
var _a;
|
|
44
|
+
const fetchFunc = (_a = (await this.getModule(components, r.componentName))) === null || _a === void 0 ? void 0 : _a.getComponentServerProps;
|
|
45
|
+
if (fetchFunc) {
|
|
46
|
+
params.requests &&
|
|
47
|
+
params.requests.push({
|
|
48
|
+
fetch: fetchFunc,
|
|
49
|
+
rendering: r,
|
|
50
|
+
layoutData: layoutData,
|
|
51
|
+
context,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// If placeholders exist in current rendering
|
|
55
|
+
if (r.placeholders) {
|
|
56
|
+
await this.collectRequests(Object.assign(Object.assign({}, params), { placeholders: r.placeholders }));
|
|
52
57
|
}
|
|
53
|
-
const renderings = this.flatRenderings(placeholders);
|
|
54
|
-
const actions = renderings.map((r) => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
var _a;
|
|
56
|
-
const fetchFunc = (_a = (yield this.getModule(components, r.componentName))) === null || _a === void 0 ? void 0 : _a.getComponentServerProps;
|
|
57
|
-
if (fetchFunc) {
|
|
58
|
-
params.requests &&
|
|
59
|
-
params.requests.push({
|
|
60
|
-
fetch: fetchFunc,
|
|
61
|
-
rendering: r,
|
|
62
|
-
layoutData: layoutData,
|
|
63
|
-
context,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
// If placeholders exist in current rendering
|
|
67
|
-
if (r.placeholders) {
|
|
68
|
-
yield this.collectRequests(Object.assign(Object.assign({}, params), { placeholders: r.placeholders }));
|
|
69
|
-
}
|
|
70
|
-
}));
|
|
71
|
-
yield Promise.all(actions);
|
|
72
|
-
return params.requests;
|
|
73
58
|
});
|
|
59
|
+
await Promise.all(actions);
|
|
60
|
+
return params.requests;
|
|
74
61
|
}
|
|
75
62
|
/**
|
|
76
63
|
* Execute request for component props
|
|
77
64
|
* @param {ComponentPropsRequest[]} requests requests
|
|
78
65
|
* @returns {Promise<ComponentPropsCollection>} requests result
|
|
79
66
|
*/
|
|
80
|
-
execRequests(requests) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
});
|
|
67
|
+
async execRequests(requests) {
|
|
68
|
+
const componentProps = {};
|
|
69
|
+
const promises = requests.map((req) => {
|
|
70
|
+
const { uid } = req.rendering;
|
|
71
|
+
if (!uid) {
|
|
72
|
+
console.log(`Component ${req.rendering.componentName} doesn't have uid, can't store data for this component`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
return req
|
|
76
|
+
.fetch(req.rendering, req.layoutData, req.context)
|
|
77
|
+
.then((result) => {
|
|
78
|
+
// Set component specific data in componentProps store
|
|
79
|
+
componentProps[uid] = result;
|
|
80
|
+
})
|
|
81
|
+
.catch((error) => {
|
|
82
|
+
const errLog = `Error during preload data for component ${req.rendering.componentName} (${uid}): ${error.message || error}`;
|
|
83
|
+
console.error(chalk_1.default.red(errLog));
|
|
84
|
+
componentProps[uid] = {
|
|
85
|
+
error: error.message || errLog,
|
|
86
|
+
componentName: req.rendering.componentName,
|
|
87
|
+
};
|
|
103
88
|
});
|
|
104
|
-
yield Promise.all(promises);
|
|
105
|
-
return componentProps;
|
|
106
89
|
});
|
|
90
|
+
await Promise.all(promises);
|
|
91
|
+
return componentProps;
|
|
107
92
|
}
|
|
108
93
|
/**
|
|
109
94
|
* Take renderings from all placeholders and returns a flat array of renderings.
|
|
@@ -128,15 +113,13 @@ class ComponentPropsService {
|
|
|
128
113
|
});
|
|
129
114
|
return allComponentRenderings;
|
|
130
115
|
}
|
|
131
|
-
getModule(components, componentName) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return module;
|
|
139
|
-
});
|
|
116
|
+
async getModule(components, componentName) {
|
|
117
|
+
var _a;
|
|
118
|
+
const component = components.get(componentName);
|
|
119
|
+
if (!component)
|
|
120
|
+
return null;
|
|
121
|
+
const module = component.dynamicModule ? await ((_a = component === null || component === void 0 ? void 0 : component.dynamicModule) === null || _a === void 0 ? void 0 : _a.call(component)) : component;
|
|
122
|
+
return module;
|
|
140
123
|
}
|
|
141
124
|
}
|
|
142
125
|
exports.ComponentPropsService = ComponentPropsService;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { cache } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Internal cache implementation for storing page params.
|
|
4
|
+
*
|
|
5
|
+
* This cache is used to store the locale and site information for the current page.
|
|
6
|
+
*
|
|
7
|
+
* It helps avoid the usage of functions that disable SSG such as `headers()`.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
const cacheImpl = cache(() => ({ locale: '', site: '' }));
|
|
11
|
+
/**
|
|
12
|
+
* Gets the cached page params, including locale and site.
|
|
13
|
+
* @returns An object containing the locale and site information for the current page.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export const getCachedPageParams = () => cacheImpl();
|
|
17
|
+
/**
|
|
18
|
+
* Sets the cached page params, including locale and site.
|
|
19
|
+
* @param {CachedPageParams} pageParams An object containing the locale and site information to be set for the current page cache.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export function setCachedPageParams(pageParams) {
|
|
23
|
+
cacheImpl().locale = pageParams.locale;
|
|
24
|
+
cacheImpl().site = pageParams.site;
|
|
25
|
+
}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { SitecoreClient, } from '@sitecore-content-sdk/content/client';
|
|
11
2
|
import { ComponentPropsService } from '../services/component-props-service';
|
|
12
3
|
import { getSiteRewriteData, normalizeSiteRewrite } from '@sitecore-content-sdk/content/site';
|
|
@@ -41,23 +32,17 @@ export class SitecoreNextjsClient extends SitecoreClient {
|
|
|
41
32
|
const basePath = super.parsePath(path);
|
|
42
33
|
return normalizeSiteRewrite(normalizePersonalizedRewrite(basePath));
|
|
43
34
|
}
|
|
44
|
-
getPage(path, pageOptions, options) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
locale: pageOptions.locale,
|
|
56
|
-
site,
|
|
57
|
-
personalize: personalizeData,
|
|
58
|
-
}, options);
|
|
59
|
-
return page;
|
|
60
|
-
});
|
|
35
|
+
async getPage(path, pageOptions, options) {
|
|
36
|
+
const resolvedPath = this.parsePath(path);
|
|
37
|
+
// Get variant(s) for personalization (from path), must ensure path is of type string
|
|
38
|
+
const personalizeData = pageOptions.personalize || getPersonalizedRewriteData(super.parsePath(path));
|
|
39
|
+
const site = pageOptions.site || this.getSiteNameFromPath(path);
|
|
40
|
+
const page = await super.getPage(resolvedPath, {
|
|
41
|
+
locale: pageOptions.locale,
|
|
42
|
+
site,
|
|
43
|
+
personalize: personalizeData,
|
|
44
|
+
}, options);
|
|
45
|
+
return page;
|
|
61
46
|
}
|
|
62
47
|
/**
|
|
63
48
|
* Get design library page details for Design Library mode of your app
|
|
@@ -65,26 +50,16 @@ export class SitecoreNextjsClient extends SitecoreClient {
|
|
|
65
50
|
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
66
51
|
* @returns {Page} preview page for Design Library
|
|
67
52
|
*/
|
|
68
|
-
getDesignLibraryData(designLibData, fetchOptions) {
|
|
69
|
-
|
|
70
|
-
getDesignLibraryData: { get: () => super.getDesignLibraryData }
|
|
71
|
-
});
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
return _super.getDesignLibraryData.call(this, designLibData, fetchOptions);
|
|
74
|
-
});
|
|
53
|
+
async getDesignLibraryData(designLibData, fetchOptions) {
|
|
54
|
+
return super.getDesignLibraryData(designLibData, fetchOptions);
|
|
75
55
|
}
|
|
76
56
|
/**
|
|
77
57
|
* Retrieves preview page and layout details
|
|
78
58
|
* @param {PreviewData} previewData - The editing preview data for metadata mode.
|
|
79
59
|
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
|
|
80
60
|
*/
|
|
81
|
-
getPreview(previewData, fetchOptions) {
|
|
82
|
-
|
|
83
|
-
getPreview: { get: () => super.getPreview }
|
|
84
|
-
});
|
|
85
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
return _super.getPreview.call(this, previewData, fetchOptions);
|
|
87
|
-
});
|
|
61
|
+
async getPreview(previewData, fetchOptions) {
|
|
62
|
+
return super.getPreview(previewData, fetchOptions);
|
|
88
63
|
}
|
|
89
64
|
/**
|
|
90
65
|
* Generates static params for the Next.js App Router from Sitecore routes.
|
|
@@ -100,25 +75,20 @@ export class SitecoreNextjsClient extends SitecoreClient {
|
|
|
100
75
|
* @param {FetchOptions} [fetchOptions] - Additional fetch options.
|
|
101
76
|
* @returns {Promise<StaticParams[]>} Array of `{ site, locale, path }` entries for `generateStaticParams`.
|
|
102
77
|
*/
|
|
103
|
-
getAppRouterStaticParams(sites, languages, fetchOptions) {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
params.push({
|
|
115
|
-
locale: (_a = path.locale) !== null && _a !== void 0 ? _a : this.initOptions.defaultLanguage,
|
|
116
|
-
site: this.getSiteNameFromPath(path.params.path),
|
|
117
|
-
path: normalizedPath,
|
|
118
|
-
});
|
|
78
|
+
async getAppRouterStaticParams(sites, languages, fetchOptions) {
|
|
79
|
+
const staticPaths = await super.getPagePaths(sites, languages, fetchOptions);
|
|
80
|
+
const params = new Array();
|
|
81
|
+
staticPaths.map((path) => {
|
|
82
|
+
var _a;
|
|
83
|
+
// remove _site_ segments
|
|
84
|
+
const normalizedPath = normalizeSiteRewrite(path.params.path.join('/')).split('/');
|
|
85
|
+
params.push({
|
|
86
|
+
locale: (_a = path.locale) !== null && _a !== void 0 ? _a : this.initOptions.defaultLanguage,
|
|
87
|
+
site: this.getSiteNameFromPath(path.params.path),
|
|
88
|
+
path: normalizedPath,
|
|
119
89
|
});
|
|
120
|
-
return params;
|
|
121
90
|
});
|
|
91
|
+
return params;
|
|
122
92
|
}
|
|
123
93
|
/**
|
|
124
94
|
* Retrieves the static paths for pages based on the given languages.
|
|
@@ -127,21 +97,16 @@ export class SitecoreNextjsClient extends SitecoreClient {
|
|
|
127
97
|
* @param {FetchOptions} [fetchOptions] - Additional fetch options.
|
|
128
98
|
* @returns {Promise<StaticPath[]>} A promise that resolves to an array of static paths.
|
|
129
99
|
*/
|
|
130
|
-
getPagePaths(sites, languages, fetchOptions) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
path.params.path = normalizeSiteRewrite(path.params.path.join('/')).split('/');
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
return staticPaths;
|
|
144
|
-
});
|
|
100
|
+
async getPagePaths(sites, languages, fetchOptions) {
|
|
101
|
+
var _a;
|
|
102
|
+
const staticPaths = await super.getPagePaths(sites, languages, fetchOptions);
|
|
103
|
+
if (!((_a = this.initOptions.multisite) === null || _a === void 0 ? void 0 : _a.enabled)) {
|
|
104
|
+
// remove _site_ segments when multisite is disabled
|
|
105
|
+
staticPaths.map((path) => {
|
|
106
|
+
path.params.path = normalizeSiteRewrite(path.params.path.join('/')).split('/');
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return staticPaths;
|
|
145
110
|
}
|
|
146
111
|
/**
|
|
147
112
|
* Parses components from nextjs component map and layoutData, executes getServerProps/getStaticProps methods
|
|
@@ -151,30 +116,28 @@ export class SitecoreNextjsClient extends SitecoreClient {
|
|
|
151
116
|
* @param {ComponentMap<NextjsContentSdkComponent>} components component map to get props for
|
|
152
117
|
* @returns {ComponentPropsCollection} component props
|
|
153
118
|
*/
|
|
154
|
-
getComponentData(layoutData, context, components) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (!layoutData.sitecore.route)
|
|
158
|
-
return componentProps;
|
|
159
|
-
// Retrieve component props using side-effects defined on components level
|
|
160
|
-
componentProps = yield this.componentPropsService.fetchComponentProps({
|
|
161
|
-
layoutData: layoutData,
|
|
162
|
-
context,
|
|
163
|
-
components,
|
|
164
|
-
});
|
|
165
|
-
const errors = Object.keys(componentProps)
|
|
166
|
-
.map((id) => {
|
|
167
|
-
const component = componentProps[id];
|
|
168
|
-
return component.error
|
|
169
|
-
? `\nUnable to get component props for ${component.componentName} (${id}): ${component.error}`
|
|
170
|
-
: '';
|
|
171
|
-
})
|
|
172
|
-
.join('');
|
|
173
|
-
if (errors.length) {
|
|
174
|
-
throw new Error(errors);
|
|
175
|
-
}
|
|
119
|
+
async getComponentData(layoutData, context, components) {
|
|
120
|
+
let componentProps = {};
|
|
121
|
+
if (!layoutData.sitecore.route)
|
|
176
122
|
return componentProps;
|
|
123
|
+
// Retrieve component props using side-effects defined on components level
|
|
124
|
+
componentProps = await this.componentPropsService.fetchComponentProps({
|
|
125
|
+
layoutData: layoutData,
|
|
126
|
+
context,
|
|
127
|
+
components,
|
|
177
128
|
});
|
|
129
|
+
const errors = Object.keys(componentProps)
|
|
130
|
+
.map((id) => {
|
|
131
|
+
const component = componentProps[id];
|
|
132
|
+
return component.error
|
|
133
|
+
? `\nUnable to get component props for ${component.componentName} (${id}): ${component.error}`
|
|
134
|
+
: '';
|
|
135
|
+
})
|
|
136
|
+
.join('');
|
|
137
|
+
if (errors.length) {
|
|
138
|
+
throw new Error(errors);
|
|
139
|
+
}
|
|
140
|
+
return componentProps;
|
|
178
141
|
}
|
|
179
142
|
getComponentPropsService() {
|
|
180
143
|
return new ComponentPropsService();
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { BYOCWrapper, fetchBYOCComponentServerProps, } from '@sitecore-content-sdk/react';
|
|
11
2
|
/**
|
|
12
3
|
* Will be called during SSG or SSR
|
|
@@ -14,9 +5,9 @@ import { BYOCWrapper, fetchBYOCComponentServerProps, } from '@sitecore-content-s
|
|
|
14
5
|
* @returns {GetStaticPropsContext | GetStaticPropsContext} context with type depending on SSR or SSG mode
|
|
15
6
|
* @internal
|
|
16
7
|
*/
|
|
17
|
-
export const getComponentServerProps = (rendering) =>
|
|
8
|
+
export const getComponentServerProps = async (rendering) => {
|
|
18
9
|
const params = rendering.params || {};
|
|
19
|
-
const result =
|
|
10
|
+
const result = await fetchBYOCComponentServerProps(params);
|
|
20
11
|
return result;
|
|
21
|
-
}
|
|
12
|
+
};
|
|
22
13
|
export default BYOCWrapper;
|
|
@@ -0,0 +1,24 @@
|
|
|
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 '@sitecore-content-sdk/react';
|
|
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
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
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 '@sitecore-content-sdk/react';
|
|
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(component, (rendering, eventArgs) => {
|
|
68
|
+
_previewComponentAction({
|
|
69
|
+
uid: component.uid,
|
|
70
|
+
args: eventArgs,
|
|
71
|
+
}, rendering, edgeUrl);
|
|
72
|
+
});
|
|
73
|
+
if (componentInitError) {
|
|
74
|
+
// an error occurred during initialization of the component on the server side
|
|
75
|
+
sendErrorEvent(component.uid, componentInitError.message, componentInitError.type);
|
|
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
|
+
};
|