@sitecore-content-sdk/nextjs 1.3.0-canary.9 → 1.4.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/dist/cjs/client/index.js +10 -10
- package/dist/cjs/client/models.js +2 -2
- package/dist/cjs/client/sitecore-nextjs-client.js +160 -156
- package/dist/cjs/components/BYOCWrapper.js +31 -30
- package/dist/cjs/components/ComponentPropsContext.js +66 -59
- package/dist/cjs/components/FEaaSWrapper.js +33 -32
- package/dist/cjs/components/Link.js +117 -90
- package/dist/cjs/components/NextImage.js +66 -62
- package/dist/cjs/components/Placeholder.js +55 -50
- package/dist/cjs/components/RichText.js +133 -128
- package/dist/cjs/config/define-config.js +26 -25
- package/dist/cjs/config/index.js +5 -5
- package/dist/cjs/config-cli/define-cli-config.js +40 -39
- package/dist/cjs/config-cli/index.js +5 -5
- package/dist/cjs/editing/codegen/import-map.js +129 -118
- package/dist/cjs/editing/codegen/index.js +6 -6
- package/dist/cjs/editing/constants.js +10 -10
- package/dist/cjs/editing/editing-config-middleware.js +70 -69
- package/dist/cjs/editing/editing-render-middleware.js +145 -144
- package/dist/cjs/editing/feaas-render-middleware.js +102 -101
- package/dist/cjs/editing/index.js +19 -19
- package/dist/cjs/editing/render-middleware.js +46 -46
- package/dist/cjs/editing/utils.js +260 -257
- package/dist/cjs/index.js +132 -131
- package/dist/cjs/middleware/app-router-multisite-middleware.js +41 -20
- package/dist/cjs/middleware/index.js +30 -30
- package/dist/cjs/middleware/locale-middleware.js +85 -84
- package/dist/cjs/middleware/middleware.js +195 -192
- package/dist/cjs/middleware/multisite-middleware.js +141 -118
- package/dist/cjs/middleware/personalize-middleware.js +240 -236
- package/dist/cjs/middleware/redirects-middleware.js +323 -297
- package/dist/cjs/middleware/robots-middleware.js +45 -44
- package/dist/cjs/middleware/sitemap-middleware.js +50 -49
- package/dist/cjs/monitoring/healthcheck-middleware.js +31 -30
- package/dist/cjs/monitoring/index.js +5 -5
- package/dist/cjs/route-handler/editing-config-route-handler.js +110 -106
- package/dist/cjs/route-handler/editing-render-route-handler.js +270 -165
- package/dist/cjs/route-handler/index.js +11 -11
- package/dist/cjs/route-handler/robots-route-handler.js +69 -68
- package/dist/cjs/route-handler/sitemap-route-handler.js +66 -65
- package/dist/cjs/search/index.js +17 -0
- package/dist/cjs/services/component-props-service.js +142 -138
- package/dist/cjs/sharedTypes/component-props.js +2 -2
- package/dist/cjs/sharedTypes/sitecore-page-props.js +2 -2
- package/dist/cjs/site/index.js +5 -5
- package/dist/cjs/tools/codegen/import-map.js +15 -0
- package/dist/cjs/tools/component-props.loader.js +95 -95
- package/dist/cjs/tools/generate-map.js +317 -317
- package/dist/cjs/tools/index.js +14 -13
- package/dist/cjs/tools/templating/byoc-component.js +36 -36
- package/dist/cjs/tools/templating/constants.js +7 -7
- package/dist/cjs/tools/templating/default-component.js +35 -35
- package/dist/cjs/tools/templating/utils.js +200 -0
- package/dist/cjs/utils/index.js +14 -14
- package/dist/cjs/utils/utils.js +82 -73
- package/dist/esm/client/index.js +2 -2
- package/dist/esm/client/models.js +1 -1
- package/dist/esm/client/sitecore-nextjs-client.js +156 -152
- package/dist/esm/components/BYOCWrapper.js +27 -26
- package/dist/esm/components/ComponentPropsContext.js +28 -21
- package/dist/esm/components/FEaaSWrapper.js +29 -28
- package/dist/esm/components/Link.js +78 -51
- package/dist/esm/components/NextImage.js +60 -56
- package/dist/esm/components/Placeholder.js +18 -13
- package/dist/esm/components/RichText.js +96 -91
- package/dist/esm/config/define-config.js +21 -20
- package/dist/esm/config/index.js +1 -1
- package/dist/esm/config-cli/define-cli-config.js +36 -35
- package/dist/esm/config-cli/index.js +1 -1
- package/dist/esm/editing/codegen/import-map.js +92 -81
- package/dist/esm/editing/codegen/index.js +1 -1
- package/dist/esm/editing/constants.js +7 -7
- package/dist/esm/editing/editing-config-middleware.js +66 -65
- package/dist/esm/editing/editing-render-middleware.js +141 -140
- package/dist/esm/editing/feaas-render-middleware.js +98 -97
- package/dist/esm/editing/index.js +6 -6
- package/dist/esm/editing/render-middleware.js +42 -42
- package/dist/esm/editing/utils.js +246 -243
- package/dist/esm/index.js +25 -25
- package/dist/esm/middleware/app-router-multisite-middleware.js +37 -16
- package/dist/esm/middleware/index.js +11 -11
- package/dist/esm/middleware/locale-middleware.js +81 -80
- package/dist/esm/middleware/middleware.js +189 -186
- package/dist/esm/middleware/multisite-middleware.js +137 -114
- package/dist/esm/middleware/personalize-middleware.js +236 -232
- package/dist/esm/middleware/redirects-middleware.js +316 -290
- package/dist/esm/middleware/robots-middleware.js +41 -40
- package/dist/esm/middleware/sitemap-middleware.js +46 -45
- package/dist/esm/monitoring/healthcheck-middleware.js +27 -26
- package/dist/esm/monitoring/index.js +1 -1
- package/dist/esm/route-handler/editing-config-route-handler.js +106 -102
- package/dist/esm/route-handler/editing-render-route-handler.js +265 -160
- package/dist/esm/route-handler/index.js +4 -4
- package/dist/esm/route-handler/robots-route-handler.js +65 -64
- package/dist/esm/route-handler/sitemap-route-handler.js +63 -62
- package/dist/esm/search/index.js +1 -0
- package/dist/esm/services/component-props-service.js +135 -131
- package/dist/esm/sharedTypes/component-props.js +1 -1
- package/dist/esm/sharedTypes/sitecore-page-props.js +1 -1
- package/dist/esm/site/index.js +1 -1
- package/dist/esm/tools/codegen/import-map.js +11 -0
- package/dist/esm/tools/component-props.loader.js +59 -59
- package/dist/esm/tools/generate-map.js +279 -279
- package/dist/esm/tools/index.js +3 -2
- package/dist/esm/tools/templating/byoc-component.js +30 -30
- package/dist/esm/tools/templating/constants.js +4 -4
- package/dist/esm/tools/templating/default-component.js +29 -29
- package/dist/esm/tools/templating/utils.js +190 -0
- package/dist/esm/utils/index.js +3 -3
- package/dist/esm/utils/utils.js +74 -65
- package/package.json +87 -13
- package/search.d.ts +1 -0
- package/types/client/index.d.ts +3 -2
- package/types/client/index.d.ts.map +1 -0
- package/types/client/models.d.ts +9 -8
- package/types/client/models.d.ts.map +1 -0
- package/types/client/sitecore-nextjs-client.d.ts +68 -63
- package/types/client/sitecore-nextjs-client.d.ts.map +1 -0
- package/types/components/BYOCWrapper.d.ts +16 -14
- package/types/components/BYOCWrapper.d.ts.map +1 -0
- package/types/components/ComponentPropsContext.d.ts +30 -18
- package/types/components/ComponentPropsContext.d.ts.map +1 -0
- package/types/components/FEaaSWrapper.d.ts +17 -15
- package/types/components/FEaaSWrapper.d.ts.map +1 -0
- package/types/components/Link.d.ts +25 -15
- package/types/components/Link.d.ts.map +1 -0
- package/types/components/NextImage.d.ts +11 -6
- package/types/components/NextImage.d.ts.map +1 -0
- package/types/components/Placeholder.d.ts +14 -8
- package/types/components/Placeholder.d.ts.map +1 -0
- package/types/components/RichText.d.ts +35 -25
- package/types/components/RichText.d.ts.map +1 -0
- package/types/config/define-config.d.ts +42 -38
- package/types/config/define-config.d.ts.map +1 -0
- package/types/config/index.d.ts +2 -1
- package/types/config/index.d.ts.map +1 -0
- package/types/config-cli/define-cli-config.d.ts +10 -8
- package/types/config-cli/define-cli-config.d.ts.map +1 -0
- package/types/config-cli/index.d.ts +2 -1
- package/types/config-cli/index.d.ts.map +1 -0
- package/types/editing/codegen/import-map.d.ts +15 -3
- package/types/editing/codegen/import-map.d.ts.map +1 -0
- package/types/editing/codegen/index.d.ts +3 -2
- package/types/editing/codegen/index.d.ts.map +1 -0
- package/types/editing/constants.d.ts +8 -7
- package/types/editing/constants.d.ts.map +1 -0
- package/types/editing/editing-config-middleware.d.ts +37 -31
- package/types/editing/editing-config-middleware.d.ts.map +1 -0
- package/types/editing/editing-render-middleware.d.ts +47 -44
- package/types/editing/editing-render-middleware.d.ts.map +1 -0
- package/types/editing/feaas-render-middleware.d.ts +35 -32
- package/types/editing/feaas-render-middleware.d.ts.map +1 -0
- package/types/editing/index.d.ts +7 -6
- package/types/editing/index.d.ts.map +1 -0
- package/types/editing/render-middleware.d.ts +26 -25
- package/types/editing/render-middleware.d.ts.map +1 -0
- package/types/editing/utils.d.ts +110 -106
- package/types/editing/utils.d.ts.map +1 -0
- package/types/index.d.ts +25 -24
- package/types/index.d.ts.map +1 -0
- package/types/middleware/app-router-multisite-middleware.d.ts +28 -13
- package/types/middleware/app-router-multisite-middleware.d.ts.map +1 -0
- package/types/middleware/index.d.ts +12 -11
- package/types/middleware/index.d.ts.map +1 -0
- package/types/middleware/locale-middleware.d.ts +35 -32
- package/types/middleware/locale-middleware.d.ts.map +1 -0
- package/types/middleware/middleware.d.ts +135 -127
- package/types/middleware/middleware.d.ts.map +1 -0
- package/types/middleware/multisite-middleware.d.ts +54 -37
- package/types/middleware/multisite-middleware.d.ts.map +1 -0
- package/types/middleware/personalize-middleware.d.ts +81 -65
- package/types/middleware/personalize-middleware.d.ts.map +1 -0
- package/types/middleware/redirects-middleware.d.ts +68 -65
- package/types/middleware/redirects-middleware.d.ts.map +1 -0
- package/types/middleware/robots-middleware.d.ts +15 -13
- package/types/middleware/robots-middleware.d.ts.map +1 -0
- package/types/middleware/sitemap-middleware.d.ts +16 -14
- package/types/middleware/sitemap-middleware.d.ts.map +1 -0
- package/types/monitoring/healthcheck-middleware.d.ts +14 -12
- package/types/monitoring/healthcheck-middleware.d.ts.map +1 -0
- package/types/monitoring/index.d.ts +2 -1
- package/types/monitoring/index.d.ts.map +1 -0
- package/types/route-handler/editing-config-route-handler.d.ts +30 -24
- package/types/route-handler/editing-config-route-handler.d.ts.map +1 -0
- package/types/route-handler/editing-render-route-handler.d.ts +33 -25
- package/types/route-handler/editing-render-route-handler.d.ts.map +1 -0
- package/types/route-handler/index.d.ts +5 -4
- package/types/route-handler/index.d.ts.map +1 -0
- package/types/route-handler/robots-route-handler.d.ts +30 -28
- package/types/route-handler/robots-route-handler.d.ts.map +1 -0
- package/types/route-handler/sitemap-route-handler.d.ts +30 -28
- package/types/route-handler/sitemap-route-handler.d.ts.map +1 -0
- package/types/search/index.d.ts +2 -0
- package/types/search/index.d.ts.map +1 -0
- package/types/services/component-props-service.d.ts +62 -57
- package/types/services/component-props-service.d.ts.map +1 -0
- package/types/sharedTypes/component-props.d.ts +62 -47
- package/types/sharedTypes/component-props.d.ts.map +1 -0
- package/types/sharedTypes/sitecore-page-props.d.ts +14 -9
- package/types/sharedTypes/sitecore-page-props.d.ts.map +1 -0
- package/types/site/index.d.ts +2 -1
- package/types/site/index.d.ts.map +1 -0
- package/types/tools/codegen/import-map.d.ts +10 -0
- package/types/tools/codegen/import-map.d.ts.map +1 -0
- package/types/tools/component-props.loader.d.ts +8 -7
- package/types/tools/component-props.loader.d.ts.map +1 -0
- package/types/tools/generate-map.d.ts +26 -24
- package/types/tools/generate-map.d.ts.map +1 -0
- package/types/tools/index.d.ts +4 -2
- package/types/tools/index.d.ts.map +1 -0
- package/types/tools/templating/byoc-component.d.ts +3 -2
- package/types/tools/templating/byoc-component.d.ts.map +1 -0
- package/types/tools/templating/constants.d.ts +5 -4
- package/types/tools/templating/constants.d.ts.map +1 -0
- package/types/tools/templating/default-component.d.ts +3 -2
- package/types/tools/templating/default-component.d.ts.map +1 -0
- package/types/tools/templating/utils.d.ts +44 -0
- package/types/tools/templating/utils.d.ts.map +1 -0
- package/types/utils/index.d.ts +4 -3
- package/types/utils/index.d.ts.map +1 -0
- package/types/utils/utils.d.ts +34 -24
- package/types/utils/utils.d.ts.map +1 -0
- package/client.js +0 -1
- package/codegen.js +0 -1
- package/config-cli.js +0 -1
- package/config.js +0 -1
- package/editing.js +0 -1
- package/middleware.js +0 -1
- package/monitoring.js +0 -1
- package/route-handler.js +0 -1
- package/site.js +0 -1
- package/tools.js +0 -1
- package/utils.js +0 -1
|
@@ -1,152 +1,156 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { SitecoreClient, } from '@sitecore-content-sdk/core/client';
|
|
11
|
-
import { ComponentPropsService } from '../services/component-props-service';
|
|
12
|
-
import { getSiteRewriteData, normalizeSiteRewrite } from '@sitecore-content-sdk/core/site';
|
|
13
|
-
import { getPersonalizedRewriteData, normalizePersonalizedRewrite, } from '@sitecore-content-sdk/core/personalize';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
componentProps =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { SitecoreClient, } from '@sitecore-content-sdk/core/client';
|
|
11
|
+
import { ComponentPropsService } from '../services/component-props-service';
|
|
12
|
+
import { getSiteRewriteData, normalizeSiteRewrite } from '@sitecore-content-sdk/core/site';
|
|
13
|
+
import { getPersonalizedRewriteData, normalizePersonalizedRewrite, } from '@sitecore-content-sdk/core/personalize';
|
|
14
|
+
/**
|
|
15
|
+
* The SitecoreNextjsClient class extends the SitecoreClient class to provide additional functionality for Next.js.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export class SitecoreNextjsClient extends SitecoreClient {
|
|
19
|
+
constructor(initOptions) {
|
|
20
|
+
super(initOptions);
|
|
21
|
+
this.initOptions = initOptions;
|
|
22
|
+
this.componentPropsService = this.getComponentPropsService();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Gets site name based on the provided path
|
|
26
|
+
* @param {string | string[]} path path to get site name from
|
|
27
|
+
* @returns site name, or default site info if not found
|
|
28
|
+
*/
|
|
29
|
+
getSiteNameFromPath(path) {
|
|
30
|
+
const resolvedPath = super.parsePath(path);
|
|
31
|
+
// Get site name (from path rewritten in middleware)
|
|
32
|
+
const siteData = getSiteRewriteData(resolvedPath, this.initOptions.defaultSite);
|
|
33
|
+
return siteData.siteName;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Normalizes a nextjs path that could have been rewritten
|
|
37
|
+
* @param {string | string[]} path nextjs path
|
|
38
|
+
* @returns path string without nextjs prefixes
|
|
39
|
+
*/
|
|
40
|
+
parsePath(path) {
|
|
41
|
+
const basePath = super.parsePath(path);
|
|
42
|
+
return normalizeSiteRewrite(normalizePersonalizedRewrite(basePath));
|
|
43
|
+
}
|
|
44
|
+
getPage(path, pageOptions, options) {
|
|
45
|
+
const _super = Object.create(null, {
|
|
46
|
+
parsePath: { get: () => super.parsePath },
|
|
47
|
+
getPage: { get: () => super.getPage }
|
|
48
|
+
});
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const resolvedPath = this.parsePath(path);
|
|
51
|
+
// Get variant(s) for personalization (from path), must ensure path is of type string
|
|
52
|
+
const personalizeData = pageOptions.personalize || getPersonalizedRewriteData(_super.parsePath.call(this, path));
|
|
53
|
+
const site = pageOptions.site || this.getSiteNameFromPath(path);
|
|
54
|
+
const page = yield _super.getPage.call(this, resolvedPath, {
|
|
55
|
+
locale: pageOptions.locale,
|
|
56
|
+
site,
|
|
57
|
+
personalize: personalizeData,
|
|
58
|
+
}, options);
|
|
59
|
+
return page;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get design library page details for Design Library mode of your app
|
|
64
|
+
* @param {PreviewData} designLibData preview data set in 'library' mode of the app
|
|
65
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
66
|
+
* @returns {Page} preview page for Design Library
|
|
67
|
+
*/
|
|
68
|
+
getDesignLibraryData(designLibData, fetchOptions) {
|
|
69
|
+
const _super = Object.create(null, {
|
|
70
|
+
getDesignLibraryData: { get: () => super.getDesignLibraryData }
|
|
71
|
+
});
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return _super.getDesignLibraryData.call(this, designLibData, fetchOptions);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves preview page and layout details
|
|
78
|
+
* @param {PreviewData} previewData - The editing preview data for metadata mode.
|
|
79
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
|
|
80
|
+
*/
|
|
81
|
+
getPreview(previewData, fetchOptions) {
|
|
82
|
+
const _super = Object.create(null, {
|
|
83
|
+
getPreview: { get: () => super.getPreview }
|
|
84
|
+
});
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
return _super.getPreview.call(this, previewData, fetchOptions);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Generates static params for the Next.js App Router from Sitecore routes.
|
|
91
|
+
*
|
|
92
|
+
* Fetches routes for the specified `sites` and `languages`, then converts them into
|
|
93
|
+
* objects consumable by `generateStaticParams`. Internal multisite segments are removed.
|
|
94
|
+
* The `site` name is resolved from the path. If a route lacks a locale, the
|
|
95
|
+
* client's `defaultLanguage` is used.
|
|
96
|
+
*
|
|
97
|
+
* **NOTE**: App Router only. For the Pages Router, use `getPagePaths`.
|
|
98
|
+
* @param {string[]} sites - An array of site names to fetch routes for.
|
|
99
|
+
* @param {string[]} [languages] - Language codes to generate params for.
|
|
100
|
+
* @param {FetchOptions} [fetchOptions] - Additional fetch options.
|
|
101
|
+
* @returns {Promise<StaticParams[]>} Array of `{ site, locale, path }` entries for `generateStaticParams`.
|
|
102
|
+
*/
|
|
103
|
+
getAppRouterStaticParams(sites, languages, fetchOptions) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const staticPaths = yield this.getPagePaths(sites, languages, fetchOptions);
|
|
106
|
+
const params = new Array();
|
|
107
|
+
staticPaths.map((path) => {
|
|
108
|
+
var _a;
|
|
109
|
+
// remove _site_ segments
|
|
110
|
+
const normalizedPath = normalizeSiteRewrite(path.params.path.join('/')).split('/');
|
|
111
|
+
params.push({
|
|
112
|
+
locale: (_a = path.locale) !== null && _a !== void 0 ? _a : this.initOptions.defaultLanguage,
|
|
113
|
+
site: this.getSiteNameFromPath(path.params.path),
|
|
114
|
+
path: normalizedPath,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
return params;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Parses components from nextjs component map and layoutData, executes getServerProps/getStaticProps methods
|
|
122
|
+
* and returns resulting props from components
|
|
123
|
+
* @param {LayoutServiceData} layoutData layout data to parse compnents from
|
|
124
|
+
* @param {PreviewData} context Nextjs preview data
|
|
125
|
+
* @param {ComponentMap<NextjsContentSdkComponent>} components component map to get props for
|
|
126
|
+
* @returns {ComponentPropsCollection} component props
|
|
127
|
+
*/
|
|
128
|
+
getComponentData(layoutData, context, components) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
let componentProps = {};
|
|
131
|
+
if (!layoutData.sitecore.route)
|
|
132
|
+
return componentProps;
|
|
133
|
+
// Retrieve component props using side-effects defined on components level
|
|
134
|
+
componentProps = yield this.componentPropsService.fetchComponentProps({
|
|
135
|
+
layoutData: layoutData,
|
|
136
|
+
context,
|
|
137
|
+
components,
|
|
138
|
+
});
|
|
139
|
+
const errors = Object.keys(componentProps)
|
|
140
|
+
.map((id) => {
|
|
141
|
+
const component = componentProps[id];
|
|
142
|
+
return component.error
|
|
143
|
+
? `\nUnable to get component props for ${component.componentName} (${id}): ${component.error}`
|
|
144
|
+
: '';
|
|
145
|
+
})
|
|
146
|
+
.join('');
|
|
147
|
+
if (errors.length) {
|
|
148
|
+
throw new Error(errors);
|
|
149
|
+
}
|
|
150
|
+
return componentProps;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
getComponentPropsService() {
|
|
154
|
+
return new ComponentPropsService();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { BYOCWrapper, fetchBYOCComponentServerProps, } from '@sitecore-content-sdk/react';
|
|
11
|
-
/**
|
|
12
|
-
* TODO: remove when framework agnostic forms implemented
|
|
13
|
-
* This is a repackaged version of the React BYOCWrapper component with support for
|
|
14
|
-
* server rendering in Next.js (using component-level data-fetching feature of Content SDK).
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Will be called during SSG or SSR
|
|
18
|
-
* @param {ComponentRendering} rendering
|
|
19
|
-
* @returns {GetStaticPropsContext | GetStaticPropsContext} context with type depending on SSR or SSG mode
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { BYOCWrapper, fetchBYOCComponentServerProps, } from '@sitecore-content-sdk/react';
|
|
11
|
+
/**
|
|
12
|
+
* TODO: remove when framework agnostic forms implemented
|
|
13
|
+
* This is a repackaged version of the React BYOCWrapper component with support for
|
|
14
|
+
* server rendering in Next.js (using component-level data-fetching feature of Content SDK).
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Will be called during SSG or SSR
|
|
18
|
+
* @param {ComponentRendering} rendering
|
|
19
|
+
* @returns {GetStaticPropsContext | GetStaticPropsContext} context with type depending on SSR or SSG mode
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export const getComponentServerProps = (rendering) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const params = rendering.params || {};
|
|
24
|
+
const result = yield fetchBYOCComponentServerProps(params);
|
|
25
|
+
return result;
|
|
26
|
+
});
|
|
27
|
+
export default BYOCWrapper;
|
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import React, { createContext, useContext } from 'react';
|
|
3
|
-
/**
|
|
4
|
-
* Component props context which we are using in order to store data fetched on components level (getComponentServerProps)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { createContext, useContext } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Component props context which we are using in order to store data fetched on components level (getComponentServerProps)
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export const ComponentPropsReactContext = createContext({});
|
|
8
|
+
/**
|
|
9
|
+
* Hook in order to get access to props related to specific component. Data comes from ComponentPropsContext.
|
|
10
|
+
* @see ComponentPropsContext
|
|
11
|
+
* @param {string | undefined} componentUid component uId
|
|
12
|
+
* @returns {ComponentData | undefined} component props
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export function useComponentProps(componentUid) {
|
|
16
|
+
if (!componentUid) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
20
|
+
const data = useContext(ComponentPropsReactContext);
|
|
21
|
+
return data[componentUid];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The ComponentPropsContext component. Stores component props in a context.
|
|
25
|
+
* @param {ComponentPropsContextProps} props component props
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export const ComponentPropsContext = ({ children, value, }) => (React.createElement(ComponentPropsReactContext.Provider, { value: value }, children));
|
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { FEaaSWrapper, fetchFEaaSComponentServerProps, LayoutServicePageState, } from '@sitecore-content-sdk/react';
|
|
11
|
-
/**
|
|
12
|
-
* TODO: remove when framework agnostic forms implemented
|
|
13
|
-
* This is a repackaged version of the React FEaaSWrapper component with support for
|
|
14
|
-
* server rendering in Next.js (using component-level data-fetching feature of Content SDK).
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Will be called during SSG or SSR
|
|
18
|
-
* @param {ComponentRendering} rendering
|
|
19
|
-
* @param {LayoutServiceData} layoutData
|
|
20
|
-
* @returns {GetStaticPropsContext | GetServerSideProps} context
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { FEaaSWrapper, fetchFEaaSComponentServerProps, LayoutServicePageState, } from '@sitecore-content-sdk/react';
|
|
11
|
+
/**
|
|
12
|
+
* TODO: remove when framework agnostic forms implemented
|
|
13
|
+
* This is a repackaged version of the React FEaaSWrapper component with support for
|
|
14
|
+
* server rendering in Next.js (using component-level data-fetching feature of Content SDK).
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Will be called during SSG or SSR
|
|
18
|
+
* @param {ComponentRendering} rendering
|
|
19
|
+
* @param {LayoutServiceData} layoutData
|
|
20
|
+
* @returns {GetStaticPropsContext | GetServerSideProps} context
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export const getComponentServerProps = (rendering, layoutData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const params = rendering.params || {};
|
|
25
|
+
const isPageStateNormal = !layoutData.sitecore.context.pageState ||
|
|
26
|
+
layoutData.sitecore.context.pageState === LayoutServicePageState.Normal;
|
|
27
|
+
return yield fetchFEaaSComponentServerProps(params, isPageStateNormal);
|
|
28
|
+
});
|
|
29
|
+
export default FEaaSWrapper;
|
|
@@ -1,51 +1,78 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
import React, { forwardRef } from 'react';
|
|
14
|
-
import NextLink from 'next/link';
|
|
15
|
-
import { Link as ReactLink, } from '@sitecore-content-sdk/react';
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import React, { forwardRef } from 'react';
|
|
14
|
+
import NextLink from 'next/link';
|
|
15
|
+
import { Link as ReactLink, } from '@sitecore-content-sdk/react';
|
|
16
|
+
/**
|
|
17
|
+
* The list of NextLink props to be supported by the Link component.
|
|
18
|
+
*/
|
|
19
|
+
const supportedNextLinkProps = [
|
|
20
|
+
'as',
|
|
21
|
+
'onNavigate',
|
|
22
|
+
'passHref',
|
|
23
|
+
'prefetch',
|
|
24
|
+
'replace',
|
|
25
|
+
'scroll',
|
|
26
|
+
'shallow',
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Matches relative URLs that end with a file extension.
|
|
30
|
+
*/
|
|
31
|
+
const FILE_EXTENSION_MATCHER = /^\/.*\.\w+$/;
|
|
32
|
+
/**
|
|
33
|
+
* Next.js specific Link component implementation.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export const Link = forwardRef((props, ref) => {
|
|
37
|
+
const { field, editable = true, children, internalLinkMatcher = /^\//g, showLinkTextWithChildrenPresent } = props, rest = __rest(props, ["field", "editable", "children", "internalLinkMatcher", "showLinkTextWithChildrenPresent"]);
|
|
38
|
+
if (!field || (!field.value && !field.href && !field.metadata)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const value = (field.href ? field : field.value);
|
|
42
|
+
// fallback to {} if value is undefined; could happen if field is LinkFieldValue, href is empty in metadata mode
|
|
43
|
+
const { href, querystring, anchor } = value || {};
|
|
44
|
+
const isEditing = editable && field.metadata;
|
|
45
|
+
if (href && !isEditing) {
|
|
46
|
+
const text = showLinkTextWithChildrenPresent || !children ? value.text || value.href : null;
|
|
47
|
+
const isMatching = internalLinkMatcher.test(href);
|
|
48
|
+
const isFileUrl = FILE_EXTENSION_MATCHER.test(href);
|
|
49
|
+
// determine if a link is a route or not. File extensions are not routes and should not be pre-fetched.
|
|
50
|
+
if (isMatching && !isFileUrl) {
|
|
51
|
+
return (React.createElement(NextLink, Object.assign({ href: { pathname: href, query: querystring, hash: anchor }, key: "link", title: value.title, target: value.target, className: value.class }, rest, { locale: false, ref: ref }, (process.env.TEST
|
|
52
|
+
? {
|
|
53
|
+
'data-nextjs-link': true,
|
|
54
|
+
'data-nextjs-prefetch': props.prefetch,
|
|
55
|
+
}
|
|
56
|
+
: {})),
|
|
57
|
+
text,
|
|
58
|
+
children));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const reactLinkProps = sanitizeLinkProps(props);
|
|
62
|
+
return (React.createElement(ReactLink, Object.assign({}, reactLinkProps, { ref: ref }, (process.env.TEST ? { 'data-react-link': true } : {}))));
|
|
63
|
+
});
|
|
64
|
+
Link.displayName = 'NextLink';
|
|
65
|
+
/**
|
|
66
|
+
* Sanitize props for ReactLink by removing Next.js and internal props to prevent invalid DOM attributes.
|
|
67
|
+
* @param {LinkProps} props - The props the Link component received.
|
|
68
|
+
* @returns sanitized props for ReactLink.
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
function sanitizeLinkProps(props) {
|
|
72
|
+
const internalProps = ['internalLinkMatcher'];
|
|
73
|
+
const sanitizedProps = Object.assign({}, props);
|
|
74
|
+
for (const prop of [...supportedNextLinkProps, ...internalProps]) {
|
|
75
|
+
delete sanitizedProps[prop];
|
|
76
|
+
}
|
|
77
|
+
return sanitizedProps;
|
|
78
|
+
}
|