@sitecore-jss/sitecore-jss-nextjs 22.6.0-canary.8 → 22.6.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 CHANGED
@@ -1,202 +1,202 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright [yyyy] [name of copyright owner]
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
- # Sitecore JavaScript Rendering SDK for Next.js
2
-
3
- This module is provided as a part of Sitecore JavaScript Rendering SDK. It contains Next.js components and integration for JSS.
4
-
5
- <!---
6
- @TODO: Update to next version docs before release
7
- -->
8
- [Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
9
-
10
- [Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
11
-
1
+ # Sitecore JavaScript Rendering SDK for Next.js
2
+
3
+ This module is provided as a part of Sitecore JavaScript Rendering SDK. It contains Next.js components and integration for JSS.
4
+
5
+ <!---
6
+ @TODO: Update to next version docs before release
7
+ -->
8
+ [Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
9
+
10
+ [Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
11
+
12
12
  [API reference documentation](/ref-docs/sitecore-jss-nextjs/)
@@ -67,6 +67,7 @@ exports.Link = (0, react_1.forwardRef)((props, ref) => {
67
67
  const isFileUrl = FILE_EXTENSION_MATCHER.test(href);
68
68
  // determine if a link is a route or not. File extensions are not routes and should not be pre-fetched.
69
69
  if (isMatching && !isFileUrl) {
70
+ delete htmlLinkProps.emptyFieldEditingComponent;
70
71
  return (react_1.default.createElement(link_1.default, Object.assign({ href: { pathname: href, query: querystring, hash: anchor }, key: "link", locale: false, title: value.title, target: value.target, className: value.class, prefetch: props.prefetch }, htmlLinkProps, { ref: ref }),
71
72
  text,
72
73
  children));
@@ -37,12 +37,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.RichText = void 0;
40
+ exports.RichText = exports.prefetched = void 0;
41
41
  const react_1 = __importStar(require("react"));
42
42
  const prop_types_1 = __importDefault(require("prop-types"));
43
43
  const router_1 = require("next/router");
44
44
  const sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
45
- const prefetched = {};
45
+ exports.prefetched = {};
46
46
  const RichText = (props) => {
47
47
  const { internalLinksSelector = 'a[href^="/"]', prefetchLinks = true, editable = true } = props, rest = __rest(props, ["internalLinksSelector", "prefetchLinks", "editable"]);
48
48
  const hasText = props.field && props.field.value;
@@ -50,7 +50,7 @@ const RichText = (props) => {
50
50
  const router = (0, router_1.useRouter)();
51
51
  const richTextRef = (0, react_1.useRef)(null);
52
52
  (0, react_1.useEffect)(() => {
53
- // NOT IN EXPERIENCE EDITOR
53
+ // NOT IN EDIT MODE
54
54
  if (hasText && !isEditing) {
55
55
  initializeLinks();
56
56
  }
@@ -71,9 +71,21 @@ const RichText = (props) => {
71
71
  internalLinks.forEach((link) => {
72
72
  if (link.target === '_blank')
73
73
  return;
74
- if (prefetchLinks && !prefetched[link.pathname]) {
74
+ const prefetch = () => {
75
75
  router.prefetch(link.pathname, undefined, { locale: false });
76
- prefetched[link.pathname] = true;
76
+ exports.prefetched[link.pathname] = true;
77
+ };
78
+ if (!exports.prefetched[link.pathname] && prefetchLinks !== false) {
79
+ if (prefetchLinks === true) {
80
+ prefetch();
81
+ }
82
+ if (prefetchLinks === 'hover') {
83
+ const mouseOverHandler = () => {
84
+ prefetch();
85
+ link.removeEventListener('mouseover', mouseOverHandler);
86
+ };
87
+ link.addEventListener('mouseover', mouseOverHandler, false);
88
+ }
77
89
  }
78
90
  link.addEventListener('click', routeHandler, false);
79
91
  });
@@ -108,7 +108,13 @@ class ServerlessEditingDataService {
108
108
  params,
109
109
  };
110
110
  sitecore_jss_1.debug.editing('storing editing data for %o: %o', previewData, data);
111
- return this.dataFetcher.put(url, data).then(() => {
111
+ return this.dataFetcher
112
+ .put(url, data, {
113
+ headers: {
114
+ 'Content-Type': 'application/json',
115
+ },
116
+ })
117
+ .then(() => {
112
118
  return previewData;
113
119
  });
114
120
  });
package/dist/cjs/index.js CHANGED
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.fetchFEaaSComponentServerProps = exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.ComponentBuilder = exports.BYOCWrapper = exports.FEaaSWrapper = exports.NextImage = exports.Placeholder = exports.RichText = exports.Link = exports.useComponentProps = exports.ComponentPropsContext = exports.ComponentPropsReactContext = exports.normalizeSiteRewrite = exports.getSiteRewriteData = exports.getSiteRewrite = exports.GraphQLSiteInfoService = exports.SiteResolver = exports.GraphQLRobotsService = exports.GraphQLErrorPagesService = exports.GraphQLSitemapXmlService = exports.MultisiteGraphQLSitemapService = exports.GraphQLSitemapService = exports.DisconnectedSitemapService = exports.ComponentPropsService = exports.CdpHelper = exports.normalizePersonalizedRewrite = exports.getGroomedVariantIds = exports.getPersonalizedRewriteData = exports.getPersonalizedRewrite = exports.personalizeLayout = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.mediaApi = exports.EditMode = exports.getContentStylesheetLink = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.MemoryCacheClient = exports.debug = exports.enableDebug = exports.NativeDataFetcher = exports.constants = void 0;
27
- exports.EditingScripts = exports.withEmptyFieldEditingComponent = exports.withFieldMetadata = exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.DefaultEmptyFieldEditingComponentText = exports.DefaultEmptyFieldEditingComponentImage = exports.File = exports.getComponentLibraryStylesheetLinks = exports.BYOCComponent = void 0;
26
+ exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.Form = exports.ComponentBuilder = exports.BYOCWrapper = exports.FEaaSWrapper = exports.NextImage = exports.Placeholder = exports.RichText = exports.Link = exports.useComponentProps = exports.ComponentPropsContext = exports.ComponentPropsReactContext = exports.normalizeSiteRewrite = exports.getSiteRewriteData = exports.getSiteRewrite = exports.GraphQLSiteInfoService = exports.SiteResolver = exports.GraphQLRobotsService = exports.GraphQLErrorPagesService = exports.GraphQLSitemapXmlService = exports.MultisiteGraphQLSitemapService = exports.GraphQLSitemapService = exports.DisconnectedSitemapService = exports.ComponentPropsService = exports.CdpHelper = exports.normalizePersonalizedRewrite = exports.getGroomedVariantIds = exports.getPersonalizedRewriteData = exports.getPersonalizedRewrite = exports.personalizeLayout = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.mediaApi = exports.EditMode = exports.getContentStylesheetLink = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.MemoryCacheClient = exports.debug = exports.enableDebug = exports.NativeDataFetcher = exports.constants = void 0;
27
+ exports.EditingScripts = exports.withEmptyFieldEditingComponent = exports.withFieldMetadata = exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.DefaultEmptyFieldEditingComponentText = exports.DefaultEmptyFieldEditingComponentImage = exports.File = exports.getComponentLibraryStylesheetLinks = exports.BYOCComponent = exports.fetchFEaaSComponentServerProps = void 0;
28
28
  var sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
29
29
  Object.defineProperty(exports, "constants", { enumerable: true, get: function () { return sitecore_jss_1.constants; } });
30
30
  Object.defineProperty(exports, "NativeDataFetcher", { enumerable: true, get: function () { return sitecore_jss_1.NativeDataFetcher; } });
@@ -89,6 +89,7 @@ exports.BYOCWrapper = BYOCWrapper;
89
89
  var ComponentBuilder_1 = require("./ComponentBuilder");
90
90
  Object.defineProperty(exports, "ComponentBuilder", { enumerable: true, get: function () { return ComponentBuilder_1.ComponentBuilder; } });
91
91
  var sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
92
+ Object.defineProperty(exports, "Form", { enumerable: true, get: function () { return sitecore_jss_react_1.Form; } });
92
93
  Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return sitecore_jss_react_1.Image; } });
93
94
  Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return sitecore_jss_react_1.Text; } });
94
95
  Object.defineProperty(exports, "DateField", { enumerable: true, get: function () { return sitecore_jss_react_1.DateField; } });
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MiddlewareBase = void 0;
3
+ exports.MiddlewareBase = exports.REWRITE_HEADER_NAME = void 0;
4
4
  const server_1 = require("next/server");
5
+ exports.REWRITE_HEADER_NAME = 'x-sc-rewrite';
5
6
  class MiddlewareBase {
6
7
  constructor(config) {
7
8
  this.config = config;
8
9
  this.SITE_SYMBOL = 'sc_site';
9
- this.REWRITE_HEADER_NAME = 'x-sc-rewrite';
10
10
  this.defaultHostname = config.defaultHostname || 'localhost';
11
11
  }
12
12
  /**
@@ -84,14 +84,17 @@ class MiddlewareBase {
84
84
  * @param {string} rewritePath the destionation path
85
85
  * @param {NextRequest} req the current request
86
86
  * @param {NextResponse} res the current response
87
+ * @param {boolean} [skipHeader] don't write 'x-sc-rewrite' header
87
88
  */
88
- rewrite(rewritePath, req, res) {
89
+ rewrite(rewritePath, req, res, skipHeader) {
89
90
  // Note an absolute URL is required: https://nextjs.org/docs/messages/middleware-relative-urls
90
91
  const rewriteUrl = req.nextUrl.clone();
91
92
  rewriteUrl.pathname = rewritePath;
92
93
  const response = server_1.NextResponse.rewrite(rewriteUrl, res);
93
94
  // Share rewrite path with following executed middlewares
94
- response.headers.set(this.REWRITE_HEADER_NAME, rewritePath);
95
+ if (!skipHeader) {
96
+ response.headers.set(exports.REWRITE_HEADER_NAME, rewritePath);
97
+ }
95
98
  return response;
96
99
  }
97
100
  }
@@ -102,7 +102,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
102
102
  return response;
103
103
  }
104
104
  // Path can be rewritten by previously executed middleware
105
- const basePath = (res === null || res === void 0 ? void 0 : res.headers.get('x-sc-rewrite')) || pathname;
105
+ const basePath = (res === null || res === void 0 ? void 0 : res.headers.get(middleware_1.REWRITE_HEADER_NAME)) || pathname;
106
106
  // Rewrite to persononalized path
107
107
  const rewritePath = (0, personalize_1.getPersonalizedRewrite)(basePath, identifiedVariantIds);
108
108
  response = this.rewrite(rewritePath, req, response);
@@ -32,9 +32,6 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
32
32
  constructor(config) {
33
33
  super(config);
34
34
  this.config = config;
35
- this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
36
- return this.processRedirectRequest(req, res);
37
- });
38
35
  // NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
39
36
  // (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
40
37
  this.redirectsService = new site_1.GraphQLRedirectsService(Object.assign(Object.assign({}, config), { fetch: fetch }));
@@ -47,7 +44,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
47
44
  getHandler() {
48
45
  return (req, res) => __awaiter(this, void 0, void 0, function* () {
49
46
  try {
50
- return yield this.handler(req, res);
47
+ return this.processRedirectRequest(req, res);
51
48
  }
52
49
  catch (error) {
53
50
  console.log('Redirect middleware failed:');
@@ -65,23 +62,35 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
65
62
  */
66
63
  getExistsRedirect(req, siteName) {
67
64
  return __awaiter(this, void 0, void 0, function* () {
68
- const { pathname: targetURL, search: targetQS = '', locale } = this.normalizeUrl(req.nextUrl.clone());
69
- const normalizedPath = targetURL.replace(/\/*$/gi, '');
65
+ const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
66
+ const locale = this.getLanguage(req);
67
+ const normalizedPath = incomingURL.replace(/\/*$/gi, '');
70
68
  const redirects = yield this.redirectsService.fetchRedirects(siteName);
71
69
  const language = this.getLanguage(req);
72
70
  const modifyRedirects = structuredClone(redirects);
73
71
  let matchedQueryString;
72
+ const localePath = `/${locale.toLowerCase()}${normalizedPath}`;
74
73
  return modifyRedirects.length
75
74
  ? modifyRedirects.find((redirect) => {
76
- var _a;
75
+ // process static URL (non-regex) rules
77
76
  if ((0, utils_1.isRegexOrUrl)(redirect.pattern) === 'url') {
78
- const parseUrlPattern = redirect.pattern.endsWith('/')
77
+ const urlArray = redirect.pattern.endsWith('/')
79
78
  ? redirect.pattern.slice(0, -1).split('?')
80
79
  : redirect.pattern.split('?');
81
- return ((parseUrlPattern[0] === normalizedPath ||
82
- parseUrlPattern[0] === `/${locale}${normalizedPath}`) &&
83
- (0, utils_1.areURLSearchParamsEqual)(new URLSearchParams((_a = parseUrlPattern[1]) !== null && _a !== void 0 ? _a : ''), new URLSearchParams(targetQS)));
80
+ const patternQS = urlArray[1];
81
+ let patternPath = urlArray[0];
82
+ // nextjs routes are case-sensitive, but locales should be compared case-insensitively
83
+ const patternParts = patternPath.split('/');
84
+ const maybeLocale = patternParts[1].toLowerCase();
85
+ // case insensitive lookup of locales
86
+ if (new RegExp(this.locales.join('|'), 'i').test(maybeLocale)) {
87
+ patternPath = patternPath.replace(`/${patternParts[1]}`, `/${maybeLocale}`);
88
+ }
89
+ return ((patternPath === localePath || patternPath === normalizedPath) &&
90
+ (!patternQS ||
91
+ (0, utils_1.areURLSearchParamsEqual)(new URLSearchParams(patternQS), new URLSearchParams(incomingQS))));
84
92
  }
93
+ // process regex rules
85
94
  // Modify the redirect pattern to ignore the language prefix in the path
86
95
  // And escapes non-special "?" characters in a string or regex.
87
96
  redirect.pattern = (0, utils_1.escapeNonSpecialQuestionMarks)(redirect.pattern.replace(new RegExp(`^[^]?/${language}/`, 'gi'), ''));
@@ -91,16 +100,17 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
91
100
  .replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
92
101
  .replace(/^\^|\$$/g, '') // Further cleans up anchors
93
102
  .replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
103
+ // Redirect pattern matches the full incoming URL with query string present
94
104
  matchedQueryString = [
95
- (0, regex_parser_1.default)(redirect.pattern).test(`${normalizedPath}${targetQS}`),
96
- (0, regex_parser_1.default)(redirect.pattern).test(`/${locale}${normalizedPath}${targetQS}`),
105
+ (0, regex_parser_1.default)(redirect.pattern).test(`${localePath}${incomingQS}`),
106
+ (0, regex_parser_1.default)(redirect.pattern).test(`${normalizedPath}${incomingQS}`),
97
107
  ].some(Boolean)
98
- ? targetQS
108
+ ? incomingQS
99
109
  : undefined;
100
110
  // Save the matched query string (if found) into the redirect object
101
111
  redirect.matchedQueryString = matchedQueryString || '';
102
- return (!!((0, regex_parser_1.default)(redirect.pattern).test(targetURL) ||
103
- (0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
112
+ return (!!((0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${incomingURL}`) ||
113
+ (0, regex_parser_1.default)(redirect.pattern).test(incomingURL) ||
104
114
  matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
105
115
  })
106
116
  : undefined;
@@ -148,6 +158,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
148
158
  sitecore_jss_1.debug.redirects('skipped (redirect does not exist)');
149
159
  return response;
150
160
  }
161
+ sitecore_jss_1.debug.redirects('Matched redirect rule: %o', { existsRedirect });
151
162
  // Find context site language and replace token
152
163
  if (REGEXP_CONTEXT_SITE_LANG.test(existsRedirect.target) &&
153
164
  !(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
@@ -194,7 +205,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
194
205
  return this.createRedirectResponse(url, response, 302, 'Found');
195
206
  }
196
207
  case site_1.REDIRECT_TYPE_SERVER_TRANSFER: {
197
- return this.rewrite(url.href, req, response);
208
+ return this.rewrite(url.href, req, response, true);
198
209
  }
199
210
  default:
200
211
  return response;
@@ -244,9 +255,9 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
244
255
  return false;
245
256
  })
246
257
  .join('&');
247
- const newUrl = new URL(`${url.pathname}?${newQueryString}`, url.origin);
258
+ const newUrl = new URL(`${url.pathname.toLowerCase()}?${newQueryString}`, url.origin);
248
259
  url.search = newUrl.search;
249
- url.pathname = newUrl.pathname;
260
+ url.pathname = newUrl.pathname.toLowerCase();
250
261
  url.href = newUrl.href;
251
262
  return url;
252
263
  }
@@ -267,6 +278,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
267
278
  if (res === null || res === void 0 ? void 0 : res.headers) {
268
279
  redirect.headers.delete('x-middleware-next');
269
280
  redirect.headers.delete('x-middleware-rewrite');
281
+ redirect.headers.delete(middleware_1.REWRITE_HEADER_NAME);
270
282
  }
271
283
  return redirect;
272
284
  }
@@ -38,6 +38,7 @@ export const Link = forwardRef((props, ref) => {
38
38
  const isFileUrl = FILE_EXTENSION_MATCHER.test(href);
39
39
  // determine if a link is a route or not. File extensions are not routes and should not be pre-fetched.
40
40
  if (isMatching && !isFileUrl) {
41
+ delete htmlLinkProps.emptyFieldEditingComponent;
41
42
  return (React.createElement(NextLink, Object.assign({ href: { pathname: href, query: querystring, hash: anchor }, key: "link", locale: false, title: value.title, target: value.target, className: value.class, prefetch: props.prefetch }, htmlLinkProps, { ref: ref }),
42
43
  text,
43
44
  children));
@@ -13,7 +13,7 @@ import React, { useEffect, useRef } from 'react';
13
13
  import PropTypes from 'prop-types';
14
14
  import { useRouter } from 'next/router';
15
15
  import { RichText as ReactRichText, RichTextPropTypes, } from '@sitecore-jss/sitecore-jss-react';
16
- const prefetched = {};
16
+ export const prefetched = {};
17
17
  export const RichText = (props) => {
18
18
  const { internalLinksSelector = 'a[href^="/"]', prefetchLinks = true, editable = true } = props, rest = __rest(props, ["internalLinksSelector", "prefetchLinks", "editable"]);
19
19
  const hasText = props.field && props.field.value;
@@ -21,7 +21,7 @@ export const RichText = (props) => {
21
21
  const router = useRouter();
22
22
  const richTextRef = useRef(null);
23
23
  useEffect(() => {
24
- // NOT IN EXPERIENCE EDITOR
24
+ // NOT IN EDIT MODE
25
25
  if (hasText && !isEditing) {
26
26
  initializeLinks();
27
27
  }
@@ -42,9 +42,21 @@ export const RichText = (props) => {
42
42
  internalLinks.forEach((link) => {
43
43
  if (link.target === '_blank')
44
44
  return;
45
- if (prefetchLinks && !prefetched[link.pathname]) {
45
+ const prefetch = () => {
46
46
  router.prefetch(link.pathname, undefined, { locale: false });
47
47
  prefetched[link.pathname] = true;
48
+ };
49
+ if (!prefetched[link.pathname] && prefetchLinks !== false) {
50
+ if (prefetchLinks === true) {
51
+ prefetch();
52
+ }
53
+ if (prefetchLinks === 'hover') {
54
+ const mouseOverHandler = () => {
55
+ prefetch();
56
+ link.removeEventListener('mouseover', mouseOverHandler);
57
+ };
58
+ link.addEventListener('mouseover', mouseOverHandler, false);
59
+ }
48
60
  }
49
61
  link.addEventListener('click', routeHandler, false);
50
62
  });
@@ -103,7 +103,13 @@ export class ServerlessEditingDataService {
103
103
  params,
104
104
  };
105
105
  debug.editing('storing editing data for %o: %o', previewData, data);
106
- return this.dataFetcher.put(url, data).then(() => {
106
+ return this.dataFetcher
107
+ .put(url, data, {
108
+ headers: {
109
+ 'Content-Type': 'application/json',
110
+ },
111
+ })
112
+ .then(() => {
107
113
  return previewData;
108
114
  });
109
115
  });
package/dist/esm/index.js CHANGED
@@ -19,4 +19,4 @@ import * as BYOCWrapper from './components/BYOCWrapper';
19
19
  export { FEaaSWrapper };
20
20
  export { BYOCWrapper };
21
21
  export { ComponentBuilder } from './ComponentBuilder';
22
- export { Image, Text, DateField, EditFrame, FEaaSComponent, fetchFEaaSComponentServerProps, BYOCComponent, getComponentLibraryStylesheetLinks, File, DefaultEmptyFieldEditingComponentImage, DefaultEmptyFieldEditingComponentText, VisitorIdentification, SitecoreContext, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, withFieldMetadata, withEmptyFieldEditingComponent, EditingScripts, } from '@sitecore-jss/sitecore-jss-react';
22
+ export { Form, Image, Text, DateField, EditFrame, FEaaSComponent, fetchFEaaSComponentServerProps, BYOCComponent, getComponentLibraryStylesheetLinks, File, DefaultEmptyFieldEditingComponentImage, DefaultEmptyFieldEditingComponentText, VisitorIdentification, SitecoreContext, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, withFieldMetadata, withEmptyFieldEditingComponent, EditingScripts, } from '@sitecore-jss/sitecore-jss-react';
@@ -1,9 +1,9 @@
1
1
  import { NextResponse } from 'next/server';
2
+ export const REWRITE_HEADER_NAME = 'x-sc-rewrite';
2
3
  export class MiddlewareBase {
3
4
  constructor(config) {
4
5
  this.config = config;
5
6
  this.SITE_SYMBOL = 'sc_site';
6
- this.REWRITE_HEADER_NAME = 'x-sc-rewrite';
7
7
  this.defaultHostname = config.defaultHostname || 'localhost';
8
8
  }
9
9
  /**
@@ -81,14 +81,17 @@ export class MiddlewareBase {
81
81
  * @param {string} rewritePath the destionation path
82
82
  * @param {NextRequest} req the current request
83
83
  * @param {NextResponse} res the current response
84
+ * @param {boolean} [skipHeader] don't write 'x-sc-rewrite' header
84
85
  */
85
- rewrite(rewritePath, req, res) {
86
+ rewrite(rewritePath, req, res, skipHeader) {
86
87
  // Note an absolute URL is required: https://nextjs.org/docs/messages/middleware-relative-urls
87
88
  const rewriteUrl = req.nextUrl.clone();
88
89
  rewriteUrl.pathname = rewritePath;
89
90
  const response = NextResponse.rewrite(rewriteUrl, res);
90
91
  // Share rewrite path with following executed middlewares
91
- response.headers.set(this.REWRITE_HEADER_NAME, rewritePath);
92
+ if (!skipHeader) {
93
+ response.headers.set(REWRITE_HEADER_NAME, rewritePath);
94
+ }
92
95
  return response;
93
96
  }
94
97
  }
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { NextResponse } from 'next/server';
11
11
  import { GraphQLPersonalizeService, getPersonalizedRewrite, CdpHelper, DEFAULT_VARIANT, } from '@sitecore-jss/sitecore-jss/personalize';
12
12
  import { debug } from '@sitecore-jss/sitecore-jss';
13
- import { MiddlewareBase } from './middleware';
13
+ import { MiddlewareBase, REWRITE_HEADER_NAME } from './middleware';
14
14
  import { CloudSDK } from '@sitecore-cloudsdk/core/server';
15
15
  import { personalize } from '@sitecore-cloudsdk/personalize/server';
16
16
  /**
@@ -99,7 +99,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
99
99
  return response;
100
100
  }
101
101
  // Path can be rewritten by previously executed middleware
102
- const basePath = (res === null || res === void 0 ? void 0 : res.headers.get('x-sc-rewrite')) || pathname;
102
+ const basePath = (res === null || res === void 0 ? void 0 : res.headers.get(REWRITE_HEADER_NAME)) || pathname;
103
103
  // Rewrite to persononalized path
104
104
  const rewritePath = getPersonalizedRewrite(basePath, identifiedVariantIds);
105
105
  response = this.rewrite(rewritePath, req, response);
@@ -12,7 +12,7 @@ import { GraphQLRedirectsService, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT
12
12
  import { areURLSearchParamsEqual, escapeNonSpecialQuestionMarks, isRegexOrUrl, mergeURLSearchParams, } from '@sitecore-jss/sitecore-jss/utils';
13
13
  import { NextResponse } from 'next/server';
14
14
  import regexParser from 'regex-parser';
15
- import { MiddlewareBase } from './middleware';
15
+ import { MiddlewareBase, REWRITE_HEADER_NAME } from './middleware';
16
16
  const REGEXP_CONTEXT_SITE_LANG = new RegExp(/\$siteLang/, 'i');
17
17
  const REGEXP_ABSOLUTE_URL = new RegExp('^(?:[a-z]+:)?//', 'i');
18
18
  /**
@@ -26,9 +26,6 @@ export class RedirectsMiddleware extends MiddlewareBase {
26
26
  constructor(config) {
27
27
  super(config);
28
28
  this.config = config;
29
- this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
30
- return this.processRedirectRequest(req, res);
31
- });
32
29
  // NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
33
30
  // (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
34
31
  this.redirectsService = new GraphQLRedirectsService(Object.assign(Object.assign({}, config), { fetch: fetch }));
@@ -41,7 +38,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
41
38
  getHandler() {
42
39
  return (req, res) => __awaiter(this, void 0, void 0, function* () {
43
40
  try {
44
- return yield this.handler(req, res);
41
+ return this.processRedirectRequest(req, res);
45
42
  }
46
43
  catch (error) {
47
44
  console.log('Redirect middleware failed:');
@@ -59,23 +56,35 @@ export class RedirectsMiddleware extends MiddlewareBase {
59
56
  */
60
57
  getExistsRedirect(req, siteName) {
61
58
  return __awaiter(this, void 0, void 0, function* () {
62
- const { pathname: targetURL, search: targetQS = '', locale } = this.normalizeUrl(req.nextUrl.clone());
63
- const normalizedPath = targetURL.replace(/\/*$/gi, '');
59
+ const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
60
+ const locale = this.getLanguage(req);
61
+ const normalizedPath = incomingURL.replace(/\/*$/gi, '');
64
62
  const redirects = yield this.redirectsService.fetchRedirects(siteName);
65
63
  const language = this.getLanguage(req);
66
64
  const modifyRedirects = structuredClone(redirects);
67
65
  let matchedQueryString;
66
+ const localePath = `/${locale.toLowerCase()}${normalizedPath}`;
68
67
  return modifyRedirects.length
69
68
  ? modifyRedirects.find((redirect) => {
70
- var _a;
69
+ // process static URL (non-regex) rules
71
70
  if (isRegexOrUrl(redirect.pattern) === 'url') {
72
- const parseUrlPattern = redirect.pattern.endsWith('/')
71
+ const urlArray = redirect.pattern.endsWith('/')
73
72
  ? redirect.pattern.slice(0, -1).split('?')
74
73
  : redirect.pattern.split('?');
75
- return ((parseUrlPattern[0] === normalizedPath ||
76
- parseUrlPattern[0] === `/${locale}${normalizedPath}`) &&
77
- areURLSearchParamsEqual(new URLSearchParams((_a = parseUrlPattern[1]) !== null && _a !== void 0 ? _a : ''), new URLSearchParams(targetQS)));
74
+ const patternQS = urlArray[1];
75
+ let patternPath = urlArray[0];
76
+ // nextjs routes are case-sensitive, but locales should be compared case-insensitively
77
+ const patternParts = patternPath.split('/');
78
+ const maybeLocale = patternParts[1].toLowerCase();
79
+ // case insensitive lookup of locales
80
+ if (new RegExp(this.locales.join('|'), 'i').test(maybeLocale)) {
81
+ patternPath = patternPath.replace(`/${patternParts[1]}`, `/${maybeLocale}`);
82
+ }
83
+ return ((patternPath === localePath || patternPath === normalizedPath) &&
84
+ (!patternQS ||
85
+ areURLSearchParamsEqual(new URLSearchParams(patternQS), new URLSearchParams(incomingQS))));
78
86
  }
87
+ // process regex rules
79
88
  // Modify the redirect pattern to ignore the language prefix in the path
80
89
  // And escapes non-special "?" characters in a string or regex.
81
90
  redirect.pattern = escapeNonSpecialQuestionMarks(redirect.pattern.replace(new RegExp(`^[^]?/${language}/`, 'gi'), ''));
@@ -85,16 +94,17 @@ export class RedirectsMiddleware extends MiddlewareBase {
85
94
  .replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
86
95
  .replace(/^\^|\$$/g, '') // Further cleans up anchors
87
96
  .replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
97
+ // Redirect pattern matches the full incoming URL with query string present
88
98
  matchedQueryString = [
89
- regexParser(redirect.pattern).test(`${normalizedPath}${targetQS}`),
90
- regexParser(redirect.pattern).test(`/${locale}${normalizedPath}${targetQS}`),
99
+ regexParser(redirect.pattern).test(`${localePath}${incomingQS}`),
100
+ regexParser(redirect.pattern).test(`${normalizedPath}${incomingQS}`),
91
101
  ].some(Boolean)
92
- ? targetQS
102
+ ? incomingQS
93
103
  : undefined;
94
104
  // Save the matched query string (if found) into the redirect object
95
105
  redirect.matchedQueryString = matchedQueryString || '';
96
- return (!!(regexParser(redirect.pattern).test(targetURL) ||
97
- regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
106
+ return (!!(regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${incomingURL}`) ||
107
+ regexParser(redirect.pattern).test(incomingURL) ||
98
108
  matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
99
109
  })
100
110
  : undefined;
@@ -142,6 +152,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
142
152
  debug.redirects('skipped (redirect does not exist)');
143
153
  return response;
144
154
  }
155
+ debug.redirects('Matched redirect rule: %o', { existsRedirect });
145
156
  // Find context site language and replace token
146
157
  if (REGEXP_CONTEXT_SITE_LANG.test(existsRedirect.target) &&
147
158
  !(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
@@ -188,7 +199,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
188
199
  return this.createRedirectResponse(url, response, 302, 'Found');
189
200
  }
190
201
  case REDIRECT_TYPE_SERVER_TRANSFER: {
191
- return this.rewrite(url.href, req, response);
202
+ return this.rewrite(url.href, req, response, true);
192
203
  }
193
204
  default:
194
205
  return response;
@@ -238,9 +249,9 @@ export class RedirectsMiddleware extends MiddlewareBase {
238
249
  return false;
239
250
  })
240
251
  .join('&');
241
- const newUrl = new URL(`${url.pathname}?${newQueryString}`, url.origin);
252
+ const newUrl = new URL(`${url.pathname.toLowerCase()}?${newQueryString}`, url.origin);
242
253
  url.search = newUrl.search;
243
- url.pathname = newUrl.pathname;
254
+ url.pathname = newUrl.pathname.toLowerCase();
244
255
  url.href = newUrl.href;
245
256
  return url;
246
257
  }
@@ -261,6 +272,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
261
272
  if (res === null || res === void 0 ? void 0 : res.headers) {
262
273
  redirect.headers.delete('x-middleware-next');
263
274
  redirect.headers.delete('x-middleware-rewrite');
275
+ redirect.headers.delete(REWRITE_HEADER_NAME);
264
276
  }
265
277
  return redirect;
266
278
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-nextjs",
3
- "version": "22.6.0-canary.8",
3
+ "version": "22.6.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -67,15 +67,16 @@
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@sitecore-cloudsdk/core": "^0.4.2",
70
+ "@sitecore-cloudsdk/events": "^0.4.2",
70
71
  "@sitecore-cloudsdk/personalize": "^0.4.2",
71
72
  "next": "^14.2.18",
72
73
  "react": "^18.2.0",
73
74
  "react-dom": "^18.2.0"
74
75
  },
75
76
  "dependencies": {
76
- "@sitecore-jss/sitecore-jss": "^22.6.0-canary.8",
77
- "@sitecore-jss/sitecore-jss-dev-tools": "^22.6.0-canary.8",
78
- "@sitecore-jss/sitecore-jss-react": "^22.6.0-canary.8",
77
+ "@sitecore-jss/sitecore-jss": "22.6.0",
78
+ "@sitecore-jss/sitecore-jss-dev-tools": "22.6.0",
79
+ "@sitecore-jss/sitecore-jss-react": "22.6.0",
79
80
  "@vercel/kv": "^0.2.1",
80
81
  "prop-types": "^15.8.1",
81
82
  "regex-parser": "^2.2.11",
@@ -83,7 +84,7 @@
83
84
  },
84
85
  "description": "",
85
86
  "types": "types/index.d.ts",
86
- "gitHead": "207de802c73d93a7691a625d14cf097ee8861c70",
87
+ "gitHead": "e75a84e27a017ba303b4e9b3a8e65d4dac4c8a59",
87
88
  "files": [
88
89
  "dist",
89
90
  "types",
@@ -11,9 +11,15 @@ export type RichTextProps = ReactRichTextProps & {
11
11
  /**
12
12
  * Controls the prefetch of internal links. This can be beneficial if you have RichText fields
13
13
  * with large numbers of internal links in them.
14
+ * - `true` (default): The full route & its data will be prefetched.
15
+ * - `hover`: Prefetching will happen on hover.
16
+ * - `false`: Prefetching will not happen.
14
17
  * @default true
15
18
  */
16
- prefetchLinks?: boolean;
19
+ prefetchLinks?: boolean | 'hover';
20
+ };
21
+ export declare const prefetched: {
22
+ [cacheKey: string]: boolean;
17
23
  };
18
24
  export declare const RichText: {
19
25
  (props: RichTextProps): JSX.Element;
package/types/index.d.ts CHANGED
@@ -22,4 +22,4 @@ import * as BYOCWrapper from './components/BYOCWrapper';
22
22
  export { FEaaSWrapper };
23
23
  export { BYOCWrapper };
24
24
  export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
25
- export { ComponentFactory, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, EditFrame, FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, BYOCComponentParams, BYOCComponent, BYOCComponentProps, getComponentLibraryStylesheetLinks, File, FileField, RichTextField, DefaultEmptyFieldEditingComponentImage, DefaultEmptyFieldEditingComponentText, VisitorIdentification, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, WithSitecoreContextOptions, WithSitecoreContextProps, WithSitecoreContextHocProps, withFieldMetadata, withEmptyFieldEditingComponent, EditingScripts, } from '@sitecore-jss/sitecore-jss-react';
25
+ export { ComponentFactory, Form, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, EditFrame, FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, BYOCComponentParams, BYOCComponent, BYOCComponentProps, getComponentLibraryStylesheetLinks, File, FileField, RichTextField, DefaultEmptyFieldEditingComponentImage, DefaultEmptyFieldEditingComponentText, VisitorIdentification, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, WithSitecoreContextOptions, WithSitecoreContextProps, WithSitecoreContextHocProps, withFieldMetadata, withEmptyFieldEditingComponent, EditingScripts, } from '@sitecore-jss/sitecore-jss-react';
@@ -1,5 +1,6 @@
1
1
  import { SiteInfo, SiteResolver } from '@sitecore-jss/sitecore-jss/site';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
+ export declare const REWRITE_HEADER_NAME = "x-sc-rewrite";
3
4
  export type MiddlewareBaseConfig = {
4
5
  /**
5
6
  * function, determines if middleware should be turned off, based on cookie, header, or other considerations
@@ -28,7 +29,6 @@ export type MiddlewareBaseConfig = {
28
29
  export declare abstract class MiddlewareBase {
29
30
  protected config: MiddlewareBaseConfig;
30
31
  protected SITE_SYMBOL: string;
31
- protected REWRITE_HEADER_NAME: string;
32
32
  protected defaultHostname: string;
33
33
  constructor(config: MiddlewareBaseConfig);
34
34
  /**
@@ -77,6 +77,7 @@ export declare abstract class MiddlewareBase {
77
77
  * @param {string} rewritePath the destionation path
78
78
  * @param {NextRequest} req the current request
79
79
  * @param {NextResponse} res the current response
80
+ * @param {boolean} [skipHeader] don't write 'x-sc-rewrite' header
80
81
  */
81
- protected rewrite(rewritePath: string, req: NextRequest, res: NextResponse): NextResponse;
82
+ protected rewrite(rewritePath: string, req: NextRequest, res: NextResponse, skipHeader?: boolean): NextResponse;
82
83
  }
@@ -45,7 +45,6 @@ export declare class RedirectsMiddleware extends MiddlewareBase {
45
45
  * @returns {Promise<NextResponse>} The redirect response.
46
46
  */
47
47
  protected processRedirectRequest(req: NextRequest, res?: NextResponse): Promise<NextResponse>;
48
- private handler;
49
48
  /**
50
49
  * When a user clicks on a link generated by the Link component from next/link,
51
50
  * Next.js adds special parameters in the route called path.