react-datocms 7.2.5-0 → 7.2.5
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/dist/cjs/ContentLink/index.js +4 -2
- package/dist/cjs/ContentLink/index.js.map +1 -1
- package/dist/cjs/useContentLink/index.js +16 -4
- package/dist/cjs/useContentLink/index.js.map +1 -1
- package/dist/esm/ContentLink/index.js +4 -2
- package/dist/esm/ContentLink/index.js.map +1 -1
- package/dist/esm/useContentLink/index.js +16 -4
- package/dist/esm/useContentLink/index.js.map +1 -1
- package/dist/types/ContentLink/index.d.ts +1 -1
- package/dist/types/useContentLink/index.d.ts +18 -3
- package/package.json +2 -2
- package/src/ContentLink/index.tsx +7 -5
- package/src/useContentLink/index.ts +35 -7
|
@@ -81,14 +81,16 @@ const index_js_1 = require("../useContentLink/index.js");
|
|
|
81
81
|
*/
|
|
82
82
|
function ContentLink(props) {
|
|
83
83
|
const { currentPath, enableClickToEdit: enableClickToEditOptions } = props, useContentLinkOptions = __rest(props, ["currentPath", "enableClickToEdit"]);
|
|
84
|
-
const { enableClickToEdit, setCurrentPath } = (0, index_js_1.useContentLink)(useContentLinkOptions)
|
|
84
|
+
const { enableClickToEdit, setCurrentPath } = (0, index_js_1.useContentLink)(Object.assign(Object.assign({}, useContentLinkOptions), {
|
|
85
|
+
// Always strip stega encoding in the component for clean DOM
|
|
86
|
+
enabled: { stripStega: true } }));
|
|
85
87
|
// Sync current path when it changes
|
|
86
88
|
(0, react_1.useEffect)(() => {
|
|
87
89
|
if (currentPath !== undefined) {
|
|
88
90
|
setCurrentPath(currentPath);
|
|
89
91
|
}
|
|
90
92
|
}, [currentPath, setCurrentPath]);
|
|
91
|
-
//
|
|
93
|
+
// Enable click-to-edit on mount if requested
|
|
92
94
|
(0, react_1.useEffect)(() => {
|
|
93
95
|
if (enableClickToEditOptions !== undefined) {
|
|
94
96
|
enableClickToEdit(enableClickToEditOptions === true ? undefined : enableClickToEditOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContentLink/index.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;AAEb,iCAAkC;AAClC,yDAGoC;AASpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,SAAgB,WAAW,CAAC,KAAuB;IACjD,MAAM,EACJ,WAAW,EACX,iBAAiB,EAAE,wBAAwB,KAEzC,KAAK,EADJ,qBAAqB,UACtB,KAAK,EAJH,oCAIL,CAAQ,CAAC;IAEV,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,GAAG,IAAA,yBAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContentLink/index.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;AAEb,iCAAkC;AAClC,yDAGoC;AASpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,SAAgB,WAAW,CAAC,KAAuB;IACjD,MAAM,EACJ,WAAW,EACX,iBAAiB,EAAE,wBAAwB,KAEzC,KAAK,EADJ,qBAAqB,UACtB,KAAK,EAJH,oCAIL,CAAQ,CAAC;IAEV,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,GAAG,IAAA,yBAAc,kCACvD,qBAAqB;QACxB,6DAA6D;QAC7D,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,IAC7B,CAAC;IAEH,oCAAoC;IACpC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,cAAc,CAAC,WAAW,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC;IAElC,6CAA6C;IAC7C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,wBAAwB,KAAK,SAAS,EAAE,CAAC;YAC3C,iBAAiB,CACf,wBAAwB,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,wBAAwB,CACzE,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAElD,OAAO,IAAI,CAAC;AACd,CAAC;AA9BD,kCA8BC"}
|
|
@@ -37,25 +37,37 @@ Object.defineProperty(exports, "stripStega", { enumerable: true, get: function (
|
|
|
37
37
|
function useContentLink(options = {}) {
|
|
38
38
|
const { enabled = true, onNavigateTo, root } = options;
|
|
39
39
|
const controllerRef = (0, react_1.useRef)(null);
|
|
40
|
-
//
|
|
40
|
+
// Store the callback in a ref to avoid recreating the controller when it changes
|
|
41
|
+
const onNavigateToRef = (0, react_1.useRef)(onNavigateTo);
|
|
42
|
+
// Keep the callback ref up to date
|
|
41
43
|
(0, react_1.useEffect)(() => {
|
|
42
|
-
|
|
44
|
+
onNavigateToRef.current = onNavigateTo;
|
|
45
|
+
}, [onNavigateTo]);
|
|
46
|
+
// Create/dispose controller based on enabled flag and root only
|
|
47
|
+
// The onNavigateTo callback is accessed via ref, so changes don't trigger recreation
|
|
48
|
+
(0, react_1.useEffect)(() => {
|
|
49
|
+
// Check if controller is disabled
|
|
50
|
+
const isEnabled = enabled === true || (typeof enabled === 'object' && enabled !== null);
|
|
51
|
+
if (!isEnabled) {
|
|
43
52
|
if (controllerRef.current) {
|
|
44
53
|
controllerRef.current.dispose();
|
|
45
54
|
controllerRef.current = null;
|
|
46
55
|
}
|
|
47
56
|
return;
|
|
48
57
|
}
|
|
58
|
+
// Extract stripStega option if enabled is an object
|
|
59
|
+
const stripStega = typeof enabled === 'object' ? enabled.stripStega : false;
|
|
49
60
|
const controller = (0, content_link_1.createController)({
|
|
50
|
-
onNavigateTo,
|
|
61
|
+
onNavigateTo: (path) => { var _a; return (_a = onNavigateToRef.current) === null || _a === void 0 ? void 0 : _a.call(onNavigateToRef, path); },
|
|
51
62
|
root: (root === null || root === void 0 ? void 0 : root.current) || undefined,
|
|
63
|
+
stripStega,
|
|
52
64
|
});
|
|
53
65
|
controllerRef.current = controller;
|
|
54
66
|
return () => {
|
|
55
67
|
controller.dispose();
|
|
56
68
|
controllerRef.current = null;
|
|
57
69
|
};
|
|
58
|
-
}, [enabled,
|
|
70
|
+
}, [enabled, root]);
|
|
59
71
|
// Stable method references that call through to the controller
|
|
60
72
|
const enableClickToEdit = (0, react_1.useCallback)((opts) => {
|
|
61
73
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/useContentLink/index.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AAEb,wDAA0E;AAC1E,iCAAuD;AAIvD,sDAAgE;AAAvD,2GAAA,WAAW,OAAA;AAAE,0GAAA,UAAU,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/useContentLink/index.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AAEb,wDAA0E;AAC1E,iCAAuD;AAIvD,sDAAgE;AAAvD,2GAAA,WAAW,OAAA;AAAE,0GAAA,UAAU,OAAA;AAuChC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,cAAc,CAC5B,UAAiC,EAAE;IAEnC,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAEvD,MAAM,aAAa,GAAG,IAAA,cAAM,EAAoB,IAAI,CAAC,CAAC;IACtD,iFAAiF;IACjF,MAAM,eAAe,GAAG,IAAA,cAAM,EAAC,YAAY,CAAC,CAAC;IAE7C,mCAAmC;IACnC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,eAAe,CAAC,OAAO,GAAG,YAAY,CAAC;IACzC,CAAC,EAAE,CAAC,YAAY,CAAC,CA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AAM,kBAAkB,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;;QAC1C,MAAA,aAAa,CAAC,OAAO,0CAAE,kBAAkB,EAAE,CAAC;IAC9C,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,oBAAoB,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;;QAC5C,OAAO,MAAA,MAAA,aAAa,CAAC,OAAO,0CAAE,oBAAoB,EAAE,mCAAI,KAAK,CAAC;IAChE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAAC,CAAC,qBAA+B,EAAE,EAAE;;QAC/D,MAAA,aAAa,CAAC,OAAO,0CAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IACzD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,cAAc,GAAG,IAAA,mBAAW,EAAC,CAAC,IAAY,EAAE,EAAE;;QAClD,MAAA,aAAa,CAAC,OAAO,0CAAE,cAAc,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,UAAU,EAAE,aAAa,CAAC,OAAO;QACjC,iBAAiB;QACjB,kBAAkB;QAClB,oBAAoB;QACpB,QAAQ;QACR,cAAc;KACf,CAAC;AACJ,CAAC;AA7ED,wCA6EC"}
|
|
@@ -78,14 +78,16 @@ import { useContentLink, } from '../useContentLink/index.js';
|
|
|
78
78
|
*/
|
|
79
79
|
export function ContentLink(props) {
|
|
80
80
|
const { currentPath, enableClickToEdit: enableClickToEditOptions } = props, useContentLinkOptions = __rest(props, ["currentPath", "enableClickToEdit"]);
|
|
81
|
-
const { enableClickToEdit, setCurrentPath } = useContentLink(useContentLinkOptions)
|
|
81
|
+
const { enableClickToEdit, setCurrentPath } = useContentLink(Object.assign(Object.assign({}, useContentLinkOptions), {
|
|
82
|
+
// Always strip stega encoding in the component for clean DOM
|
|
83
|
+
enabled: { stripStega: true } }));
|
|
82
84
|
// Sync current path when it changes
|
|
83
85
|
useEffect(() => {
|
|
84
86
|
if (currentPath !== undefined) {
|
|
85
87
|
setCurrentPath(currentPath);
|
|
86
88
|
}
|
|
87
89
|
}, [currentPath, setCurrentPath]);
|
|
88
|
-
//
|
|
90
|
+
// Enable click-to-edit on mount if requested
|
|
89
91
|
useEffect(() => {
|
|
90
92
|
if (enableClickToEditOptions !== undefined) {
|
|
91
93
|
enableClickToEdit(enableClickToEditOptions === true ? undefined : enableClickToEditOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContentLink/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAEL,cAAc,GACf,MAAM,4BAA4B,CAAC;AASpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,MAAM,UAAU,WAAW,CAAC,KAAuB;IACjD,MAAM,EACJ,WAAW,EACX,iBAAiB,EAAE,wBAAwB,KAEzC,KAAK,EADJ,qBAAqB,UACtB,KAAK,EAJH,oCAIL,CAAQ,CAAC;IAEV,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContentLink/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAEL,cAAc,GACf,MAAM,4BAA4B,CAAC;AASpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,MAAM,UAAU,WAAW,CAAC,KAAuB;IACjD,MAAM,EACJ,WAAW,EACX,iBAAiB,EAAE,wBAAwB,KAEzC,KAAK,EADJ,qBAAqB,UACtB,KAAK,EAJH,oCAIL,CAAQ,CAAC;IAEV,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,GAAG,cAAc,iCACvD,qBAAqB;QACxB,6DAA6D;QAC7D,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,IAC7B,CAAC;IAEH,oCAAoC;IACpC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,cAAc,CAAC,WAAW,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC;IAElC,6CAA6C;IAC7C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,wBAAwB,KAAK,SAAS,EAAE,CAAC;YAC3C,iBAAiB,CACf,wBAAwB,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,wBAAwB,CACzE,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAElD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -32,25 +32,37 @@ export { decodeStega, stripStega } from '@datocms/content-link';
|
|
|
32
32
|
export function useContentLink(options = {}) {
|
|
33
33
|
const { enabled = true, onNavigateTo, root } = options;
|
|
34
34
|
const controllerRef = useRef(null);
|
|
35
|
-
//
|
|
35
|
+
// Store the callback in a ref to avoid recreating the controller when it changes
|
|
36
|
+
const onNavigateToRef = useRef(onNavigateTo);
|
|
37
|
+
// Keep the callback ref up to date
|
|
36
38
|
useEffect(() => {
|
|
37
|
-
|
|
39
|
+
onNavigateToRef.current = onNavigateTo;
|
|
40
|
+
}, [onNavigateTo]);
|
|
41
|
+
// Create/dispose controller based on enabled flag and root only
|
|
42
|
+
// The onNavigateTo callback is accessed via ref, so changes don't trigger recreation
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
// Check if controller is disabled
|
|
45
|
+
const isEnabled = enabled === true || (typeof enabled === 'object' && enabled !== null);
|
|
46
|
+
if (!isEnabled) {
|
|
38
47
|
if (controllerRef.current) {
|
|
39
48
|
controllerRef.current.dispose();
|
|
40
49
|
controllerRef.current = null;
|
|
41
50
|
}
|
|
42
51
|
return;
|
|
43
52
|
}
|
|
53
|
+
// Extract stripStega option if enabled is an object
|
|
54
|
+
const stripStega = typeof enabled === 'object' ? enabled.stripStega : false;
|
|
44
55
|
const controller = createController({
|
|
45
|
-
onNavigateTo,
|
|
56
|
+
onNavigateTo: (path) => { var _a; return (_a = onNavigateToRef.current) === null || _a === void 0 ? void 0 : _a.call(onNavigateToRef, path); },
|
|
46
57
|
root: (root === null || root === void 0 ? void 0 : root.current) || undefined,
|
|
58
|
+
stripStega,
|
|
47
59
|
});
|
|
48
60
|
controllerRef.current = controller;
|
|
49
61
|
return () => {
|
|
50
62
|
controller.dispose();
|
|
51
63
|
controllerRef.current = null;
|
|
52
64
|
};
|
|
53
|
-
}, [enabled,
|
|
65
|
+
}, [enabled, root]);
|
|
54
66
|
// Stable method references that call through to the controller
|
|
55
67
|
const enableClickToEdit = useCallback((opts) => {
|
|
56
68
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/useContentLink/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAmB,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAIvD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/useContentLink/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAmB,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAA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oB;QACpB,QAAQ;QACR,cAAc;KACf,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type UseContentLinkOptions } from '../useContentLink/index.js';
|
|
2
|
-
export type ContentLinkProps = UseContentLinkOptions & {
|
|
2
|
+
export type ContentLinkProps = Omit<UseContentLinkOptions, 'enabled'> & {
|
|
3
3
|
/** Current pathname to sync with Web Previews plugin */
|
|
4
4
|
currentPath?: string;
|
|
5
5
|
/** Enable click-to-edit on mount. Pass true for default behavior or an object with scrollToNearestTarget. If undefined, click-to-edit is disabled. */
|
|
@@ -3,12 +3,27 @@ import { type Controller } from '@datocms/content-link';
|
|
|
3
3
|
export type { Controller } from '@datocms/content-link';
|
|
4
4
|
export { decodeStega, stripStega } from '@datocms/content-link';
|
|
5
5
|
export type UseContentLinkOptions = {
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Whether the controller is enabled, or an options object.
|
|
8
|
+
* - Pass `true` (default): Enables the controller with stega encoding preserved (allows controller recreation)
|
|
9
|
+
* - Pass `false`: Disables the controller completely
|
|
10
|
+
* - Pass `{ stripStega: true }`: Enables the controller and strips stega encoding after stamping
|
|
11
|
+
*
|
|
12
|
+
* When stripStega is false (default): Stega encoding remains in the DOM, allowing controllers
|
|
13
|
+
* to be disposed and recreated on the same page. The invisible characters don't affect display
|
|
14
|
+
* but preserve the source of truth.
|
|
15
|
+
*
|
|
16
|
+
* When stripStega is true: Stega encoding is permanently removed from text nodes, providing
|
|
17
|
+
* clean textContent for programmatic access. However, recreating a controller on the same page
|
|
18
|
+
* won't detect elements since the encoding is lost.
|
|
19
|
+
*/
|
|
20
|
+
enabled?: boolean | {
|
|
21
|
+
stripStega: boolean;
|
|
22
|
+
};
|
|
8
23
|
/** Callback when Web Previews plugin requests navigation */
|
|
9
24
|
onNavigateTo?: (path: string) => void;
|
|
10
25
|
/** Ref to limit scanning to this root instead of document */
|
|
11
|
-
root?: React.RefObject<
|
|
26
|
+
root?: React.RefObject<HTMLElement>;
|
|
12
27
|
};
|
|
13
28
|
export type UseContentLinkResult = {
|
|
14
29
|
/** The controller instance, or null if disabled */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-datocms",
|
|
3
|
-
"version": "7.2.5
|
|
3
|
+
"version": "7.2.5",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=8.0.0"
|
|
6
6
|
},
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"react": ">= 16.12.0 || ^19.0.0-rc"
|
|
150
150
|
},
|
|
151
151
|
"dependencies": {
|
|
152
|
-
"@datocms/content-link": "^0.3.
|
|
152
|
+
"@datocms/content-link": "^0.3.7",
|
|
153
153
|
"@mux/mux-player-react": "*",
|
|
154
154
|
"datocms-listen": "^0.1.9",
|
|
155
155
|
"datocms-structured-text-generic-html-renderer": "^5.0.0",
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
useContentLink,
|
|
7
7
|
} from '../useContentLink/index.js';
|
|
8
8
|
|
|
9
|
-
export type ContentLinkProps = UseContentLinkOptions & {
|
|
9
|
+
export type ContentLinkProps = Omit<UseContentLinkOptions, 'enabled'> & {
|
|
10
10
|
/** Current pathname to sync with Web Previews plugin */
|
|
11
11
|
currentPath?: string;
|
|
12
12
|
/** Enable click-to-edit on mount. Pass true for default behavior or an object with scrollToNearestTarget. If undefined, click-to-edit is disabled. */
|
|
@@ -84,9 +84,11 @@ export function ContentLink(props: ContentLinkProps): null {
|
|
|
84
84
|
...useContentLinkOptions
|
|
85
85
|
} = props;
|
|
86
86
|
|
|
87
|
-
const { enableClickToEdit, setCurrentPath } = useContentLink(
|
|
88
|
-
useContentLinkOptions,
|
|
89
|
-
|
|
87
|
+
const { enableClickToEdit, setCurrentPath } = useContentLink({
|
|
88
|
+
...useContentLinkOptions,
|
|
89
|
+
// Always strip stega encoding in the component for clean DOM
|
|
90
|
+
enabled: { stripStega: true },
|
|
91
|
+
});
|
|
90
92
|
|
|
91
93
|
// Sync current path when it changes
|
|
92
94
|
useEffect(() => {
|
|
@@ -95,7 +97,7 @@ export function ContentLink(props: ContentLinkProps): null {
|
|
|
95
97
|
}
|
|
96
98
|
}, [currentPath, setCurrentPath]);
|
|
97
99
|
|
|
98
|
-
//
|
|
100
|
+
// Enable click-to-edit on mount if requested
|
|
99
101
|
useEffect(() => {
|
|
100
102
|
if (enableClickToEditOptions !== undefined) {
|
|
101
103
|
enableClickToEdit(
|
|
@@ -8,12 +8,25 @@ export type { Controller } from '@datocms/content-link';
|
|
|
8
8
|
export { decodeStega, stripStega } from '@datocms/content-link';
|
|
9
9
|
|
|
10
10
|
export type UseContentLinkOptions = {
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Whether the controller is enabled, or an options object.
|
|
13
|
+
* - Pass `true` (default): Enables the controller with stega encoding preserved (allows controller recreation)
|
|
14
|
+
* - Pass `false`: Disables the controller completely
|
|
15
|
+
* - Pass `{ stripStega: true }`: Enables the controller and strips stega encoding after stamping
|
|
16
|
+
*
|
|
17
|
+
* When stripStega is false (default): Stega encoding remains in the DOM, allowing controllers
|
|
18
|
+
* to be disposed and recreated on the same page. The invisible characters don't affect display
|
|
19
|
+
* but preserve the source of truth.
|
|
20
|
+
*
|
|
21
|
+
* When stripStega is true: Stega encoding is permanently removed from text nodes, providing
|
|
22
|
+
* clean textContent for programmatic access. However, recreating a controller on the same page
|
|
23
|
+
* won't detect elements since the encoding is lost.
|
|
24
|
+
*/
|
|
25
|
+
enabled?: boolean | { stripStega: boolean };
|
|
13
26
|
/** Callback when Web Previews plugin requests navigation */
|
|
14
27
|
onNavigateTo?: (path: string) => void;
|
|
15
28
|
/** Ref to limit scanning to this root instead of document */
|
|
16
|
-
root?: React.RefObject<
|
|
29
|
+
root?: React.RefObject<HTMLElement>;
|
|
17
30
|
};
|
|
18
31
|
|
|
19
32
|
export type UseContentLinkResult = {
|
|
@@ -64,10 +77,21 @@ export function useContentLink(
|
|
|
64
77
|
const { enabled = true, onNavigateTo, root } = options;
|
|
65
78
|
|
|
66
79
|
const controllerRef = useRef<Controller | null>(null);
|
|
80
|
+
// Store the callback in a ref to avoid recreating the controller when it changes
|
|
81
|
+
const onNavigateToRef = useRef(onNavigateTo);
|
|
67
82
|
|
|
68
|
-
//
|
|
83
|
+
// Keep the callback ref up to date
|
|
69
84
|
useEffect(() => {
|
|
70
|
-
|
|
85
|
+
onNavigateToRef.current = onNavigateTo;
|
|
86
|
+
}, [onNavigateTo]);
|
|
87
|
+
|
|
88
|
+
// Create/dispose controller based on enabled flag and root only
|
|
89
|
+
// The onNavigateTo callback is accessed via ref, so changes don't trigger recreation
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
// Check if controller is disabled
|
|
92
|
+
const isEnabled = enabled === true || (typeof enabled === 'object' && enabled !== null);
|
|
93
|
+
|
|
94
|
+
if (!isEnabled) {
|
|
71
95
|
if (controllerRef.current) {
|
|
72
96
|
controllerRef.current.dispose();
|
|
73
97
|
controllerRef.current = null;
|
|
@@ -75,9 +99,13 @@ export function useContentLink(
|
|
|
75
99
|
return;
|
|
76
100
|
}
|
|
77
101
|
|
|
102
|
+
// Extract stripStega option if enabled is an object
|
|
103
|
+
const stripStega = typeof enabled === 'object' ? enabled.stripStega : false;
|
|
104
|
+
|
|
78
105
|
const controller = createController({
|
|
79
|
-
onNavigateTo,
|
|
106
|
+
onNavigateTo: (path: string) => onNavigateToRef.current?.(path),
|
|
80
107
|
root: root?.current || undefined,
|
|
108
|
+
stripStega,
|
|
81
109
|
});
|
|
82
110
|
|
|
83
111
|
controllerRef.current = controller;
|
|
@@ -86,7 +114,7 @@ export function useContentLink(
|
|
|
86
114
|
controller.dispose();
|
|
87
115
|
controllerRef.current = null;
|
|
88
116
|
};
|
|
89
|
-
}, [enabled,
|
|
117
|
+
}, [enabled, root]);
|
|
90
118
|
|
|
91
119
|
// Stable method references that call through to the controller
|
|
92
120
|
const enableClickToEdit = useCallback(
|