@sitecore-jss/sitecore-jss-nextjs 22.6.0-canary.10 → 22.6.0-canary.12
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.
|
@@ -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
|
-
|
|
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;
|
|
@@ -71,9 +71,21 @@ const RichText = (props) => {
|
|
|
71
71
|
internalLinks.forEach((link) => {
|
|
72
72
|
if (link.target === '_blank')
|
|
73
73
|
return;
|
|
74
|
-
|
|
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
|
});
|
|
@@ -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;
|
|
@@ -42,9 +42,21 @@ export const RichText = (props) => {
|
|
|
42
42
|
internalLinks.forEach((link) => {
|
|
43
43
|
if (link.target === '_blank')
|
|
44
44
|
return;
|
|
45
|
-
|
|
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
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "22.6.0-canary.
|
|
3
|
+
"version": "22.6.0-canary.12",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"react-dom": "^18.2.0"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@sitecore-jss/sitecore-jss": "
|
|
77
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "
|
|
78
|
-
"@sitecore-jss/sitecore-jss-react": "
|
|
76
|
+
"@sitecore-jss/sitecore-jss": "22.6.0-canary.12",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "22.6.0-canary.12",
|
|
78
|
+
"@sitecore-jss/sitecore-jss-react": "22.6.0-canary.12",
|
|
79
79
|
"@vercel/kv": "^0.2.1",
|
|
80
80
|
"prop-types": "^15.8.1",
|
|
81
81
|
"regex-parser": "^2.2.11",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"description": "",
|
|
85
85
|
"types": "types/index.d.ts",
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "01800dcb1d9b80d8605519daf0c4c8385df6fc2e",
|
|
87
87
|
"files": [
|
|
88
88
|
"dist",
|
|
89
89
|
"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;
|