@lofcz/platejs-toc 52.0.11
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 +24 -0
- package/README.md +12 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/isHeading-CiQqjntU.js +22 -0
- package/dist/isHeading-CiQqjntU.js.map +1 -0
- package/dist/react/index.d.ts +129 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +489 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types-CqaZEV-V.d.ts +13 -0
- package/dist/types-CqaZEV-V.d.ts.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Ziad Beyens, Dylan Schiemann, Joe Anderson, Felix Feng
|
|
4
|
+
|
|
5
|
+
Unless otherwise specified in a LICENSE file within an individual package directory,
|
|
6
|
+
this license applies to all files in this repository outside of those package directories.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
|
16
|
+
all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as Heading } from "./types-CqaZEV-V";
|
|
2
|
+
import { InsertNodesOptions, PluginConfig, SlateEditor, TNode } from "platejs";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/BaseTocPlugin.d.ts
|
|
5
|
+
type TocConfig = PluginConfig<'toc', {
|
|
6
|
+
isScroll: boolean;
|
|
7
|
+
topOffset: number;
|
|
8
|
+
queryHeading?: (editor: SlateEditor) => Heading[];
|
|
9
|
+
}>;
|
|
10
|
+
declare const BaseTocPlugin: any;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/lib/transforms/insertToc.d.ts
|
|
13
|
+
declare const insertToc: (editor: SlateEditor, options?: InsertNodesOptions) => void;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/lib/utils/isHeading.d.ts
|
|
16
|
+
declare const isHeading: (node: TNode) => any;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { BaseTocPlugin, Heading, TocConfig, insertToc, isHeading };
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/lib/BaseTocPlugin.ts","../src/lib/transforms/insertToc.ts","../src/lib/utils/isHeading.ts"],"sourcesContent":[],"mappings":";;;;KASY,SAAA,GAAY;;EAAZ,SAAA,EAAA,MAAS;EAKO,YAAA,CAAA,EAAA,CAAA,MAAA,EAAA,WAAA,EAAA,GAAgB,OAAhB,EAAA;CAAgB,CAAA;AALpB,cASX,aATW,EAAA,GAAA;;;cCLX,oBACH,uBACE;;;cCJC,kBAAmB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { n as BaseTocPlugin, t as isHeading } from "./isHeading-CiQqjntU.js";
|
|
2
|
+
import { KEYS } from "platejs";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/transforms/insertToc.ts
|
|
5
|
+
const insertToc = (editor, options) => {
|
|
6
|
+
editor.tf.insertNodes({
|
|
7
|
+
children: [{ text: "" }],
|
|
8
|
+
type: editor.getType(KEYS.toc)
|
|
9
|
+
}, options);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { BaseTocPlugin, insertToc, isHeading };
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["InsertNodesOptions","SlateEditor","TElement","KEYS","insertToc","editor","options","tf","insertNodes","children","text","type","getType","toc"],"sources":["../src/lib/transforms/insertToc.ts"],"sourcesContent":["import type { InsertNodesOptions, SlateEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const insertToc = (\n editor: SlateEditor,\n options?: InsertNodesOptions\n) => {\n editor.tf.insertNodes<TElement>(\n {\n children: [{ text: '' }],\n type: editor.getType(KEYS.toc),\n },\n options as any\n );\n};\n"],"mappings":";;;;AAIA,MAAaI,aACXC,QACAC,YACG;AACHD,QAAOE,GAAGC,YACR;EACEC,UAAU,CAAC,EAAEC,MAAM,IAAI,CAAC;EACxBC,MAAMN,OAAOO,QAAQT,KAAKU,IAAG;EAC9B,EACDP,QACD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { KEYS, createTSlatePlugin } from "platejs";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/BaseTocPlugin.ts
|
|
4
|
+
const BaseTocPlugin = createTSlatePlugin({
|
|
5
|
+
key: KEYS.toc,
|
|
6
|
+
node: {
|
|
7
|
+
isElement: true,
|
|
8
|
+
isVoid: true
|
|
9
|
+
},
|
|
10
|
+
options: {
|
|
11
|
+
isScroll: true,
|
|
12
|
+
topOffset: 80
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/lib/utils/isHeading.ts
|
|
18
|
+
const isHeading = (node) => node.type && KEYS.heading.includes(node.type);
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { BaseTocPlugin as n, isHeading as t };
|
|
22
|
+
//# sourceMappingURL=isHeading-CiQqjntU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isHeading-CiQqjntU.js","names":["PluginConfig","SlateEditor","createTSlatePlugin","KEYS","Heading","TocConfig","isScroll","topOffset","queryHeading","editor","BaseTocPlugin","key","toc","node","isElement","isVoid","options","TNode","KEYS","isHeading","node","type","heading","includes"],"sources":["../src/lib/BaseTocPlugin.ts","../src/lib/utils/isHeading.ts"],"sourcesContent":["import {\n type PluginConfig,\n type SlateEditor,\n createTSlatePlugin,\n KEYS,\n} from 'platejs';\n\nimport type { Heading } from './types';\n\nexport type TocConfig = PluginConfig<\n 'toc',\n {\n isScroll: boolean;\n topOffset: number;\n queryHeading?: (editor: SlateEditor) => Heading[];\n }\n>;\n\nexport const BaseTocPlugin = createTSlatePlugin<TocConfig>({\n key: KEYS.toc,\n node: { isElement: true, isVoid: true },\n options: {\n isScroll: true,\n topOffset: 80,\n },\n});\n","import { type TNode, KEYS } from 'platejs';\n\nexport const isHeading = (node: TNode) =>\n node.type && KEYS.heading.includes(node.type as any);\n"],"mappings":";;;AAkBA,MAAaU,gBAAgBR,mBAA8B;CACzDS,KAAKR,KAAKS;CACVC,MAAM;EAAEC,WAAW;EAAMC,QAAQ;EAAM;CACvCC,SAAS;EACPV,UAAU;EACVC,WAAW;EACb;CACD,CAAC;;;;ACvBF,MAAaY,aAAaC,SACxBA,KAAKC,QAAQH,KAAKI,QAAQC,SAASH,KAAKC,KAAY"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { t as Heading } from "../types-CqaZEV-V";
|
|
2
|
+
import React$1 from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/react/TocPlugin.d.ts
|
|
5
|
+
declare const TocPlugin: any;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/react/types.d.ts
|
|
8
|
+
type TocSideBarProps = {
|
|
9
|
+
open?: boolean;
|
|
10
|
+
rootMargin?: string;
|
|
11
|
+
topOffset?: number;
|
|
12
|
+
};
|
|
13
|
+
type UseContentController = {
|
|
14
|
+
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
15
|
+
isObserve: boolean;
|
|
16
|
+
rootMargin: string;
|
|
17
|
+
topOffset: number;
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/react/hooks/useContentController.d.ts
|
|
21
|
+
declare const useContentController: ({
|
|
22
|
+
containerRef,
|
|
23
|
+
isObserve,
|
|
24
|
+
rootMargin,
|
|
25
|
+
topOffset
|
|
26
|
+
}: UseContentController) => {
|
|
27
|
+
activeContentId: string;
|
|
28
|
+
onContentScroll: ({
|
|
29
|
+
id,
|
|
30
|
+
behavior,
|
|
31
|
+
el
|
|
32
|
+
}: {
|
|
33
|
+
id: string;
|
|
34
|
+
el: HTMLElement;
|
|
35
|
+
behavior?: ScrollBehavior;
|
|
36
|
+
}) => void;
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/react/hooks/useContentObserver.d.ts
|
|
40
|
+
type UseContentObserver = {
|
|
41
|
+
editorContentRef: React$1.RefObject<HTMLElement | null>;
|
|
42
|
+
isObserve: boolean;
|
|
43
|
+
isScroll: boolean;
|
|
44
|
+
rootMargin: string;
|
|
45
|
+
status: number;
|
|
46
|
+
};
|
|
47
|
+
declare const useContentObserver: ({
|
|
48
|
+
editorContentRef,
|
|
49
|
+
isObserve,
|
|
50
|
+
isScroll,
|
|
51
|
+
rootMargin,
|
|
52
|
+
status
|
|
53
|
+
}: UseContentObserver) => {
|
|
54
|
+
activeId: string;
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/react/hooks/useTocController.d.ts
|
|
58
|
+
type UseTocController = {
|
|
59
|
+
activeId: string;
|
|
60
|
+
isObserve: boolean;
|
|
61
|
+
tocRef: React$1.RefObject<HTMLElement | null>;
|
|
62
|
+
};
|
|
63
|
+
declare const useTocController: ({
|
|
64
|
+
activeId,
|
|
65
|
+
isObserve,
|
|
66
|
+
tocRef
|
|
67
|
+
}: UseTocController) => void;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/react/hooks/useTocElement.d.ts
|
|
70
|
+
declare const useTocElementState: () => {
|
|
71
|
+
editor: any;
|
|
72
|
+
headingList: any;
|
|
73
|
+
onContentScroll: (el: HTMLElement, id: string, behavior?: ScrollBehavior) => void;
|
|
74
|
+
};
|
|
75
|
+
declare const useTocElement: ({
|
|
76
|
+
editor,
|
|
77
|
+
onContentScroll
|
|
78
|
+
}: ReturnType<typeof useTocElementState>) => {
|
|
79
|
+
props: {
|
|
80
|
+
onClick: (e: React$1.MouseEvent<HTMLElement, globalThis.MouseEvent>, item: Heading, behavior: ScrollBehavior) => void;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/react/hooks/useTocObserver.d.ts
|
|
85
|
+
type UseTocObserver = {
|
|
86
|
+
activeId: string;
|
|
87
|
+
isObserve: boolean;
|
|
88
|
+
tocRef: React$1.RefObject<HTMLElement | null>;
|
|
89
|
+
};
|
|
90
|
+
declare const useTocObserver: ({
|
|
91
|
+
activeId,
|
|
92
|
+
isObserve,
|
|
93
|
+
tocRef
|
|
94
|
+
}: UseTocObserver) => {
|
|
95
|
+
offset: number;
|
|
96
|
+
visible: boolean;
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/react/hooks/useTocSideBar.d.ts
|
|
100
|
+
declare const useTocSideBarState: ({
|
|
101
|
+
open,
|
|
102
|
+
rootMargin,
|
|
103
|
+
topOffset
|
|
104
|
+
}: TocSideBarProps) => any;
|
|
105
|
+
declare const useTocSideBar: ({
|
|
106
|
+
editor,
|
|
107
|
+
mouseInToc,
|
|
108
|
+
open,
|
|
109
|
+
setIsObserve,
|
|
110
|
+
setMouseInToc,
|
|
111
|
+
tocRef,
|
|
112
|
+
onContentScroll
|
|
113
|
+
}: ReturnType<typeof useTocSideBarState>) => {
|
|
114
|
+
navProps: {
|
|
115
|
+
ref: any;
|
|
116
|
+
onMouseEnter: () => void;
|
|
117
|
+
onMouseLeave: (e: React$1.MouseEvent<HTMLElement, globalThis.MouseEvent>) => void;
|
|
118
|
+
};
|
|
119
|
+
onContentClick: (e: React$1.MouseEvent<HTMLElement, globalThis.MouseEvent>, item: Heading, behavior?: ScrollBehavior) => void;
|
|
120
|
+
};
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/react/utils/checkIn.d.ts
|
|
123
|
+
declare function checkIn(e: React.MouseEvent<HTMLElement, globalThis.MouseEvent>): boolean;
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/react/utils/heightToTop.d.ts
|
|
126
|
+
declare const heightToTop: (ele: HTMLElement, editorContentRef?: React$1.RefObject<HTMLDivElement | null>) => number;
|
|
127
|
+
//#endregion
|
|
128
|
+
export { TocPlugin, TocSideBarProps, UseContentController, checkIn, heightToTop, useContentController, useContentObserver, useTocController, useTocElement, useTocElementState, useTocObserver, useTocSideBar, useTocSideBarState };
|
|
129
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/react/TocPlugin.tsx","../../src/react/types.ts","../../src/react/hooks/useContentController.ts","../../src/react/hooks/useContentObserver.ts","../../src/react/hooks/useTocController.ts","../../src/react/hooks/useTocElement.ts","../../src/react/hooks/useTocObserver.ts","../../src/react/hooks/useTocSide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AAA;;;;ICJzC,YAAA,EAAe,CAAA,CAAA,EMqGhB,OAAA,CAAM,UNrGU,CMqGC,WNrGD,EMqGc,UAAA,CAAW,UNrGzB,CAAA,EAAA,GAAA,IAAA;EAMf,CAAA;sBMmEH,OAAA,CAAM,WAAW,aAAa,UAAA,CAAW,mBACtC,oBACK;;;;iBC3ED,OAAA,IACX,KAAA,CAAM,WAAW,aAAa,UAAA,CAAW;;;cCCjC,mBACN,gCACc,OAAA,CAAM,UAAU"}
|
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import { n as BaseTocPlugin, t as isHeading } from "../isHeading-CiQqjntU.js";
|
|
2
|
+
import { KEYS, NodeApi } from "platejs";
|
|
3
|
+
import { toPlatePlugin, useEditorPlugin, useEditorRef, useEditorSelector, useScrollRef } from "platejs/react";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { c } from "react-compiler-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/react/TocPlugin.tsx
|
|
8
|
+
const TocPlugin = toPlatePlugin(BaseTocPlugin);
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/react/utils/checkIn.ts
|
|
12
|
+
function checkIn(e) {
|
|
13
|
+
const event = window.event;
|
|
14
|
+
const x = Number(event.clientX);
|
|
15
|
+
const y = Number(event.clientY);
|
|
16
|
+
const ele = e.target;
|
|
17
|
+
const div_x = Number(ele.getBoundingClientRect().left);
|
|
18
|
+
const div_x_width = Number(ele.getBoundingClientRect().left + ele.clientWidth);
|
|
19
|
+
const div_y = Number(ele.getBoundingClientRect().top);
|
|
20
|
+
const div_y_height = Number(ele.getBoundingClientRect().top + ele.clientHeight);
|
|
21
|
+
if (x > div_x && x < div_x_width && y > div_y && y < div_y_height) return true;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/react/utils/heightToTop.ts
|
|
27
|
+
const heightToTop = (ele, editorContentRef) => {
|
|
28
|
+
const root = editorContentRef ? editorContentRef.current : document.body;
|
|
29
|
+
if (!root || !ele) return 0;
|
|
30
|
+
const containerRect = root.getBoundingClientRect();
|
|
31
|
+
const elementRect = ele.getBoundingClientRect();
|
|
32
|
+
const scrollY = root.scrollTop;
|
|
33
|
+
return elementRect.top + scrollY - containerRect.top;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/internal/getHeadingList.ts
|
|
38
|
+
const headingDepth = {
|
|
39
|
+
h1: 1,
|
|
40
|
+
h2: 2,
|
|
41
|
+
h3: 3,
|
|
42
|
+
h4: 4,
|
|
43
|
+
h5: 5,
|
|
44
|
+
h6: 6
|
|
45
|
+
};
|
|
46
|
+
const getHeadingList = (editor) => {
|
|
47
|
+
const options = editor.getOptions(BaseTocPlugin);
|
|
48
|
+
if (options.queryHeading) return options.queryHeading(editor);
|
|
49
|
+
const headingList = [];
|
|
50
|
+
const values = editor.api.nodes({
|
|
51
|
+
at: [],
|
|
52
|
+
match: (n) => isHeading(n)
|
|
53
|
+
});
|
|
54
|
+
if (!values) return [];
|
|
55
|
+
for (const [node, path] of values) {
|
|
56
|
+
const { type } = node;
|
|
57
|
+
const title = NodeApi.string(node);
|
|
58
|
+
const depth = headingDepth[type];
|
|
59
|
+
const id = node.id;
|
|
60
|
+
if (title) headingList.push({
|
|
61
|
+
id,
|
|
62
|
+
depth,
|
|
63
|
+
path,
|
|
64
|
+
title,
|
|
65
|
+
type
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return headingList;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/react/hooks/useContentObserver.ts
|
|
73
|
+
const useContentObserver = (t0) => {
|
|
74
|
+
const $ = c(19);
|
|
75
|
+
const { editorContentRef, isObserve, isScroll, rootMargin, status } = t0;
|
|
76
|
+
let t1;
|
|
77
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
78
|
+
t1 = {};
|
|
79
|
+
$[0] = t1;
|
|
80
|
+
} else t1 = $[0];
|
|
81
|
+
const headingElementsRef = React.useRef(t1);
|
|
82
|
+
const editor = useEditorRef();
|
|
83
|
+
let t2;
|
|
84
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
85
|
+
t2 = [];
|
|
86
|
+
$[1] = t2;
|
|
87
|
+
} else t2 = $[1];
|
|
88
|
+
const headingList = useEditorSelector(getHeadingList, t2);
|
|
89
|
+
const [activeId, setActiveId] = React.useState("");
|
|
90
|
+
let t3;
|
|
91
|
+
if ($[2] !== editor || $[3] !== editorContentRef || $[4] !== headingList || $[5] !== isObserve || $[6] !== isScroll || $[7] !== rootMargin) {
|
|
92
|
+
t3 = () => {
|
|
93
|
+
const root = isScroll ? editorContentRef.current : void 0;
|
|
94
|
+
const callback = (headings) => {
|
|
95
|
+
if (!isObserve) return;
|
|
96
|
+
headingElementsRef.current = headings.reduce(_temp, headingElementsRef.current);
|
|
97
|
+
const visibleHeadings = [];
|
|
98
|
+
Object.keys(headingElementsRef.current).forEach((key) => {
|
|
99
|
+
if (headingElementsRef.current[key].isIntersecting) visibleHeadings.push(key);
|
|
100
|
+
});
|
|
101
|
+
const lastKey = Object.keys(headingElementsRef.current).pop();
|
|
102
|
+
if (visibleHeadings.length > 0) setActiveId(visibleHeadings[0] || lastKey);
|
|
103
|
+
headingElementsRef.current = {};
|
|
104
|
+
};
|
|
105
|
+
const observer = new IntersectionObserver(callback, {
|
|
106
|
+
root,
|
|
107
|
+
rootMargin
|
|
108
|
+
});
|
|
109
|
+
headingList.forEach((item) => {
|
|
110
|
+
const { path } = item;
|
|
111
|
+
const node = NodeApi.get(editor, path);
|
|
112
|
+
if (!node) return;
|
|
113
|
+
const element = editor.api.toDOMNode(node);
|
|
114
|
+
if (element) observer.observe(element);
|
|
115
|
+
});
|
|
116
|
+
return () => {
|
|
117
|
+
observer.disconnect();
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
$[2] = editor;
|
|
121
|
+
$[3] = editorContentRef;
|
|
122
|
+
$[4] = headingList;
|
|
123
|
+
$[5] = isObserve;
|
|
124
|
+
$[6] = isScroll;
|
|
125
|
+
$[7] = rootMargin;
|
|
126
|
+
$[8] = t3;
|
|
127
|
+
} else t3 = $[8];
|
|
128
|
+
let t4;
|
|
129
|
+
if ($[9] !== editor || $[10] !== editorContentRef || $[11] !== headingList || $[12] !== isObserve || $[13] !== isScroll || $[14] !== rootMargin || $[15] !== status) {
|
|
130
|
+
t4 = [
|
|
131
|
+
headingList,
|
|
132
|
+
isObserve,
|
|
133
|
+
editor,
|
|
134
|
+
editorContentRef,
|
|
135
|
+
isScroll,
|
|
136
|
+
rootMargin,
|
|
137
|
+
status
|
|
138
|
+
];
|
|
139
|
+
$[9] = editor;
|
|
140
|
+
$[10] = editorContentRef;
|
|
141
|
+
$[11] = headingList;
|
|
142
|
+
$[12] = isObserve;
|
|
143
|
+
$[13] = isScroll;
|
|
144
|
+
$[14] = rootMargin;
|
|
145
|
+
$[15] = status;
|
|
146
|
+
$[16] = t4;
|
|
147
|
+
} else t4 = $[16];
|
|
148
|
+
React.useEffect(t3, t4);
|
|
149
|
+
let t5;
|
|
150
|
+
if ($[17] !== activeId) {
|
|
151
|
+
t5 = { activeId };
|
|
152
|
+
$[17] = activeId;
|
|
153
|
+
$[18] = t5;
|
|
154
|
+
} else t5 = $[18];
|
|
155
|
+
return t5;
|
|
156
|
+
};
|
|
157
|
+
function _temp(map, headingElement) {
|
|
158
|
+
map[headingElement.target.id] = headingElement;
|
|
159
|
+
return map;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/react/hooks/useContentController.ts
|
|
164
|
+
const useContentController = ({ containerRef, isObserve, rootMargin, topOffset }) => {
|
|
165
|
+
const editor = useEditorRef();
|
|
166
|
+
const [editorContentRef, setEditorContentRef] = React.useState(containerRef);
|
|
167
|
+
const isScrollRef = React.useRef(false);
|
|
168
|
+
const isScroll = (editorContentRef.current?.scrollHeight || 0) > (editorContentRef.current?.clientHeight || 0);
|
|
169
|
+
isScrollRef.current = isScroll;
|
|
170
|
+
const scrollContainer = React.useMemo(() => {
|
|
171
|
+
if (typeof window !== "object") return;
|
|
172
|
+
return isScroll ? editorContentRef.current : window;
|
|
173
|
+
}, [isScroll]);
|
|
174
|
+
const [status, setStatus] = React.useState(0);
|
|
175
|
+
const { activeId } = useContentObserver({
|
|
176
|
+
editorContentRef,
|
|
177
|
+
isObserve,
|
|
178
|
+
isScroll,
|
|
179
|
+
rootMargin,
|
|
180
|
+
status
|
|
181
|
+
});
|
|
182
|
+
const [activeContentId, setActiveContentId] = React.useState(activeId);
|
|
183
|
+
const onContentScroll = ({ id, behavior = "instant", el }) => {
|
|
184
|
+
setActiveContentId(id);
|
|
185
|
+
if (isScrollRef.current) editorContentRef.current?.scrollTo({
|
|
186
|
+
behavior,
|
|
187
|
+
top: heightToTop(el, editorContentRef) - topOffset
|
|
188
|
+
});
|
|
189
|
+
else {
|
|
190
|
+
const top = heightToTop(el) - topOffset;
|
|
191
|
+
window.scrollTo({
|
|
192
|
+
behavior,
|
|
193
|
+
top
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
editor.getApi({ key: KEYS.blockSelection }).blockSelection?.addSelectedRow?.(id);
|
|
197
|
+
};
|
|
198
|
+
React.useEffect(() => {
|
|
199
|
+
setEditorContentRef(containerRef);
|
|
200
|
+
}, [containerRef]);
|
|
201
|
+
React.useEffect(() => {
|
|
202
|
+
setActiveContentId(activeId);
|
|
203
|
+
}, [activeId]);
|
|
204
|
+
React.useEffect(() => {
|
|
205
|
+
if (!scrollContainer) return;
|
|
206
|
+
const scroll = () => {
|
|
207
|
+
if (isObserve) setStatus(Date.now());
|
|
208
|
+
};
|
|
209
|
+
scrollContainer.addEventListener("scroll", scroll);
|
|
210
|
+
return () => {
|
|
211
|
+
scrollContainer.removeEventListener("scroll", scroll);
|
|
212
|
+
};
|
|
213
|
+
}, [isObserve, scrollContainer]);
|
|
214
|
+
return {
|
|
215
|
+
activeContentId,
|
|
216
|
+
onContentScroll
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/react/hooks/useTocObserver.ts
|
|
222
|
+
const useTocObserver = (t0) => {
|
|
223
|
+
const $ = c(10);
|
|
224
|
+
const { activeId, isObserve, tocRef } = t0;
|
|
225
|
+
const [visible, setVisible] = React.useState(true);
|
|
226
|
+
const [offset, setOffset] = React.useState(0);
|
|
227
|
+
let t1;
|
|
228
|
+
if ($[0] !== isObserve || $[1] !== tocRef) {
|
|
229
|
+
t1 = () => {
|
|
230
|
+
const root = tocRef.current;
|
|
231
|
+
const updateOffset = (entries) => {
|
|
232
|
+
if (!isObserve) return;
|
|
233
|
+
const [entry] = entries;
|
|
234
|
+
const { boundingClientRect, intersectionRatio, rootBounds } = entry;
|
|
235
|
+
if (!rootBounds) return;
|
|
236
|
+
const halfHeight = (root?.getBoundingClientRect().height || 0) / 2;
|
|
237
|
+
const isAbove = boundingClientRect.top < rootBounds.top;
|
|
238
|
+
const isBelow = boundingClientRect.bottom > rootBounds.bottom;
|
|
239
|
+
const isVisible = intersectionRatio === 1;
|
|
240
|
+
setVisible(isVisible);
|
|
241
|
+
if (!isVisible) setOffset(isAbove ? boundingClientRect.top - rootBounds.top - halfHeight : isBelow ? boundingClientRect.bottom - rootBounds.bottom + halfHeight : 0);
|
|
242
|
+
};
|
|
243
|
+
const observer = new IntersectionObserver(updateOffset, { root });
|
|
244
|
+
const element = root?.querySelectorAll("#toc_item_active")[0];
|
|
245
|
+
if (element) observer.observe(element);
|
|
246
|
+
return () => {
|
|
247
|
+
observer.disconnect();
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
$[0] = isObserve;
|
|
251
|
+
$[1] = tocRef;
|
|
252
|
+
$[2] = t1;
|
|
253
|
+
} else t1 = $[2];
|
|
254
|
+
let t2;
|
|
255
|
+
if ($[3] !== activeId || $[4] !== isObserve || $[5] !== tocRef) {
|
|
256
|
+
t2 = [
|
|
257
|
+
tocRef,
|
|
258
|
+
activeId,
|
|
259
|
+
isObserve
|
|
260
|
+
];
|
|
261
|
+
$[3] = activeId;
|
|
262
|
+
$[4] = isObserve;
|
|
263
|
+
$[5] = tocRef;
|
|
264
|
+
$[6] = t2;
|
|
265
|
+
} else t2 = $[6];
|
|
266
|
+
React.useEffect(t1, t2);
|
|
267
|
+
let t3;
|
|
268
|
+
if ($[7] !== offset || $[8] !== visible) {
|
|
269
|
+
t3 = {
|
|
270
|
+
offset,
|
|
271
|
+
visible
|
|
272
|
+
};
|
|
273
|
+
$[7] = offset;
|
|
274
|
+
$[8] = visible;
|
|
275
|
+
$[9] = t3;
|
|
276
|
+
} else t3 = $[9];
|
|
277
|
+
return t3;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/react/hooks/useTocController.ts
|
|
282
|
+
const useTocController = (t0) => {
|
|
283
|
+
const $ = c(12);
|
|
284
|
+
const { activeId, isObserve, tocRef } = t0;
|
|
285
|
+
const [activeTocId, setActiveTocId] = React.useState("");
|
|
286
|
+
let t1;
|
|
287
|
+
if ($[0] !== activeTocId || $[1] !== isObserve || $[2] !== tocRef) {
|
|
288
|
+
t1 = {
|
|
289
|
+
activeId: activeTocId,
|
|
290
|
+
isObserve,
|
|
291
|
+
tocRef
|
|
292
|
+
};
|
|
293
|
+
$[0] = activeTocId;
|
|
294
|
+
$[1] = isObserve;
|
|
295
|
+
$[2] = tocRef;
|
|
296
|
+
$[3] = t1;
|
|
297
|
+
} else t1 = $[3];
|
|
298
|
+
const { offset, visible } = useTocObserver(t1);
|
|
299
|
+
let t2;
|
|
300
|
+
let t3;
|
|
301
|
+
if ($[4] !== offset || $[5] !== tocRef || $[6] !== visible) {
|
|
302
|
+
t2 = () => {
|
|
303
|
+
if (!visible) {
|
|
304
|
+
const tocItemWrapper = tocRef.current?.querySelector("#toc_wrap");
|
|
305
|
+
const top = tocItemWrapper?.scrollTop + offset;
|
|
306
|
+
tocItemWrapper?.scrollTo({
|
|
307
|
+
behavior: "instant",
|
|
308
|
+
top
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
t3 = [
|
|
313
|
+
visible,
|
|
314
|
+
offset,
|
|
315
|
+
tocRef
|
|
316
|
+
];
|
|
317
|
+
$[4] = offset;
|
|
318
|
+
$[5] = tocRef;
|
|
319
|
+
$[6] = visible;
|
|
320
|
+
$[7] = t2;
|
|
321
|
+
$[8] = t3;
|
|
322
|
+
} else {
|
|
323
|
+
t2 = $[7];
|
|
324
|
+
t3 = $[8];
|
|
325
|
+
}
|
|
326
|
+
React.useEffect(t2, t3);
|
|
327
|
+
let t4;
|
|
328
|
+
let t5;
|
|
329
|
+
if ($[9] !== activeId) {
|
|
330
|
+
t4 = () => {
|
|
331
|
+
setActiveTocId(activeId);
|
|
332
|
+
};
|
|
333
|
+
t5 = [activeId];
|
|
334
|
+
$[9] = activeId;
|
|
335
|
+
$[10] = t4;
|
|
336
|
+
$[11] = t5;
|
|
337
|
+
} else {
|
|
338
|
+
t4 = $[10];
|
|
339
|
+
t5 = $[11];
|
|
340
|
+
}
|
|
341
|
+
React.useEffect(t4, t5);
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region src/react/hooks/useTocElement.ts
|
|
346
|
+
const useTocElementState = () => {
|
|
347
|
+
const { editor, getOptions } = useEditorPlugin(TocPlugin);
|
|
348
|
+
const { isScroll, topOffset } = getOptions();
|
|
349
|
+
const headingList = useEditorSelector(getHeadingList, []);
|
|
350
|
+
const containerRef = useScrollRef();
|
|
351
|
+
return {
|
|
352
|
+
editor,
|
|
353
|
+
headingList,
|
|
354
|
+
onContentScroll: React.useCallback((el, id, behavior = "instant") => {
|
|
355
|
+
if (!containerRef.current) return;
|
|
356
|
+
if (isScroll) containerRef.current?.scrollTo({
|
|
357
|
+
behavior,
|
|
358
|
+
top: heightToTop(el, containerRef) - topOffset
|
|
359
|
+
});
|
|
360
|
+
else {
|
|
361
|
+
const top = heightToTop(el) - topOffset;
|
|
362
|
+
window.scrollTo({
|
|
363
|
+
behavior,
|
|
364
|
+
top
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
setTimeout(() => {
|
|
368
|
+
editor.getApi({ key: KEYS.blockSelection }).blockSelection?.addSelectedRow?.(id);
|
|
369
|
+
}, 0);
|
|
370
|
+
}, [isScroll, topOffset])
|
|
371
|
+
};
|
|
372
|
+
};
|
|
373
|
+
const useTocElement = ({ editor, onContentScroll }) => ({ props: { onClick: (e, item, behavior) => {
|
|
374
|
+
e.preventDefault();
|
|
375
|
+
const { id, path } = item;
|
|
376
|
+
const node = NodeApi.get(editor, path);
|
|
377
|
+
if (!node) return;
|
|
378
|
+
const el = editor.api.toDOMNode(node);
|
|
379
|
+
if (!el) return;
|
|
380
|
+
onContentScroll(el, id, behavior);
|
|
381
|
+
} } });
|
|
382
|
+
|
|
383
|
+
//#endregion
|
|
384
|
+
//#region src/react/hooks/useTocSideBar.ts
|
|
385
|
+
const useTocSideBarState = (t0) => {
|
|
386
|
+
const $ = c(16);
|
|
387
|
+
const { open: t1, rootMargin: t2, topOffset: t3 } = t0;
|
|
388
|
+
const open = t1 === void 0 ? true : t1;
|
|
389
|
+
const rootMargin = t2 === void 0 ? "0px 0px 0px 0px" : t2;
|
|
390
|
+
const topOffset = t3 === void 0 ? 0 : t3;
|
|
391
|
+
const editor = useEditorRef();
|
|
392
|
+
let t4;
|
|
393
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
394
|
+
t4 = [];
|
|
395
|
+
$[0] = t4;
|
|
396
|
+
} else t4 = $[0];
|
|
397
|
+
const headingList = useEditorSelector(getHeadingList, t4);
|
|
398
|
+
const containerRef = useScrollRef();
|
|
399
|
+
const tocRef = React.useRef(null);
|
|
400
|
+
const [mouseInToc, setMouseInToc] = React.useState(false);
|
|
401
|
+
const [isObserve, setIsObserve] = React.useState(open);
|
|
402
|
+
let t5;
|
|
403
|
+
if ($[1] !== containerRef || $[2] !== isObserve || $[3] !== rootMargin || $[4] !== topOffset) {
|
|
404
|
+
t5 = {
|
|
405
|
+
containerRef,
|
|
406
|
+
isObserve,
|
|
407
|
+
rootMargin,
|
|
408
|
+
topOffset
|
|
409
|
+
};
|
|
410
|
+
$[1] = containerRef;
|
|
411
|
+
$[2] = isObserve;
|
|
412
|
+
$[3] = rootMargin;
|
|
413
|
+
$[4] = topOffset;
|
|
414
|
+
$[5] = t5;
|
|
415
|
+
} else t5 = $[5];
|
|
416
|
+
const { activeContentId, onContentScroll } = useContentController(t5);
|
|
417
|
+
let t6;
|
|
418
|
+
if ($[6] !== activeContentId || $[7] !== isObserve) {
|
|
419
|
+
t6 = {
|
|
420
|
+
activeId: activeContentId,
|
|
421
|
+
isObserve,
|
|
422
|
+
tocRef
|
|
423
|
+
};
|
|
424
|
+
$[6] = activeContentId;
|
|
425
|
+
$[7] = isObserve;
|
|
426
|
+
$[8] = t6;
|
|
427
|
+
} else t6 = $[8];
|
|
428
|
+
useTocController(t6);
|
|
429
|
+
let t7;
|
|
430
|
+
if ($[9] !== activeContentId || $[10] !== editor || $[11] !== headingList || $[12] !== mouseInToc || $[13] !== onContentScroll || $[14] !== open) {
|
|
431
|
+
t7 = {
|
|
432
|
+
activeContentId,
|
|
433
|
+
editor,
|
|
434
|
+
headingList,
|
|
435
|
+
mouseInToc,
|
|
436
|
+
open,
|
|
437
|
+
setIsObserve,
|
|
438
|
+
setMouseInToc,
|
|
439
|
+
tocRef,
|
|
440
|
+
onContentScroll
|
|
441
|
+
};
|
|
442
|
+
$[9] = activeContentId;
|
|
443
|
+
$[10] = editor;
|
|
444
|
+
$[11] = headingList;
|
|
445
|
+
$[12] = mouseInToc;
|
|
446
|
+
$[13] = onContentScroll;
|
|
447
|
+
$[14] = open;
|
|
448
|
+
$[15] = t7;
|
|
449
|
+
} else t7 = $[15];
|
|
450
|
+
return t7;
|
|
451
|
+
};
|
|
452
|
+
const useTocSideBar = ({ editor, mouseInToc, open, setIsObserve, setMouseInToc, tocRef, onContentScroll }) => {
|
|
453
|
+
React.useEffect(() => {
|
|
454
|
+
if (mouseInToc) setIsObserve(false);
|
|
455
|
+
else setIsObserve(true);
|
|
456
|
+
}, [mouseInToc]);
|
|
457
|
+
const onContentClick = React.useCallback((e, item, behavior) => {
|
|
458
|
+
e.preventDefault();
|
|
459
|
+
const { id, path } = item;
|
|
460
|
+
const node = NodeApi.get(editor, path);
|
|
461
|
+
if (!node) return;
|
|
462
|
+
const el = editor.api.toDOMNode(node);
|
|
463
|
+
if (!el) return;
|
|
464
|
+
onContentScroll({
|
|
465
|
+
id,
|
|
466
|
+
behavior,
|
|
467
|
+
el
|
|
468
|
+
});
|
|
469
|
+
}, [editor, onContentScroll]);
|
|
470
|
+
return {
|
|
471
|
+
navProps: {
|
|
472
|
+
ref: tocRef,
|
|
473
|
+
onMouseEnter: () => {
|
|
474
|
+
if (!mouseInToc && open) setMouseInToc(true);
|
|
475
|
+
},
|
|
476
|
+
onMouseLeave: (e) => {
|
|
477
|
+
if (open) {
|
|
478
|
+
const isIn = checkIn(e);
|
|
479
|
+
if (isIn !== mouseInToc) setMouseInToc(isIn);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
onContentClick
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
//#endregion
|
|
488
|
+
export { TocPlugin, checkIn, heightToTop, useContentController, useContentObserver, useTocController, useTocElement, useTocElementState, useTocObserver, useTocSideBar, useTocSideBarState };
|
|
489
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["toPlatePlugin","BaseTocPlugin","TocPlugin","checkIn","e","React","MouseEvent","HTMLElement","globalThis","event","window","x","Number","clientX","y","clientY","ele","target","div_x","getBoundingClientRect","left","div_x_width","clientWidth","div_y","top","div_y_height","clientHeight","React","heightToTop","ele","HTMLElement","editorContentRef","RefObject","HTMLDivElement","root","current","document","body","containerRect","getBoundingClientRect","elementRect","scrollY","scrollTop","absoluteElementTop","top","SlateEditor","TElement","NodeApi","Heading","BaseTocPlugin","isHeading","headingDepth","Record","h1","h2","h3","h4","h5","h6","getHeadingList","editor","options","getOptions","queryHeading","headingList","values","api","nodes","at","match","n","node","path","type","title","string","depth","id","push","React","NodeApi","useEditorRef","useEditorSelector","getHeadingList","UseContentObserver","editorContentRef","RefObject","HTMLElement","isObserve","isScroll","rootMargin","status","useContentObserver","t0","$","_c","t1","Symbol","for","headingElementsRef","useRef","editor","t2","headingList","activeId","setActiveId","useState","t3","root","current","undefined","callback","headings","reduce","_temp","visibleHeadings","Object","keys","forEach","key","headingElement_0","headingElement","isIntersecting","push","lastKey","pop","length","observer","IntersectionObserver","item","path","node","get","element","api","toDOMNode","observe","disconnect","t4","useEffect","t5","map","target","id","React","KEYS","useEditorRef","UseContentController","heightToTop","useContentObserver","useContentController","containerRef","isObserve","rootMargin","topOffset","editor","editorContentRef","setEditorContentRef","useState","isScrollRef","useRef","isScroll","current","scrollHeight","clientHeight","scrollContainer","useMemo","window","status","setStatus","activeId","activeContentId","setActiveContentId","onContentScroll","id","behavior","el","HTMLElement","ScrollBehavior","scrollTo","top","getApi","key","blockSelection","addSelectedRow","useEffect","scroll","Date","now","addEventListener","removeEventListener","React","UseTocObserver","activeId","isObserve","tocRef","RefObject","HTMLElement","useTocObserver","t0","$","_c","visible","setVisible","useState","offset","setOffset","t1","root","current","updateOffset","entries","entry","boundingClientRect","intersectionRatio","rootBounds","halfHeight","getBoundingClientRect","height","isAbove","top","isBelow","bottom","isVisible","offset_0","observer","IntersectionObserver","element","querySelectorAll","observe","disconnect","t2","useEffect","t3","React","useTocObserver","UseTocController","activeId","isObserve","tocRef","RefObject","HTMLElement","useTocController","t0","$","_c","activeTocId","setActiveTocId","useState","t1","offset","visible","t2","t3","tocItemWrapper","current","querySelector","top","scrollTop","scrollTo","behavior","useEffect","t4","t5","React","KEYS","NodeApi","useEditorPlugin","useEditorSelector","useScrollRef","Heading","getHeadingList","TocPlugin","heightToTop","useTocElementState","editor","getOptions","isScroll","topOffset","headingList","containerRef","onContentScroll","useCallback","el","HTMLElement","id","behavior","ScrollBehavior","current","scrollTo","top","window","setTimeout","getApi","key","blockSelection","addSelectedRow","useTocElement","ReturnType","props","onClick","e","MouseEvent","globalThis","item","preventDefault","path","node","get","api","toDOMNode","React","NodeApi","useEditorRef","useEditorSelector","useScrollRef","Heading","TocSideBarProps","useContentController","useTocController","getHeadingList","checkIn","useTocSideBarState","t0","$","_c","open","t1","rootMargin","t2","topOffset","t3","undefined","editor","t4","Symbol","for","headingList","containerRef","tocRef","useRef","mouseInToc","setMouseInToc","useState","isObserve","setIsObserve","t5","activeContentId","onContentScroll","t6","activeId","t7","useTocSideBar","ReturnType","useEffect","onContentClick","useCallback","e","MouseEvent","HTMLElement","globalThis","item","behavior","ScrollBehavior","preventDefault","id","path","node","get","el","api","toDOMNode","navProps","ref","onMouseEnter","onMouseLeave","isIn"],"sources":["../../src/react/TocPlugin.tsx","../../src/react/utils/checkIn.ts","../../src/react/utils/heightToTop.ts","../../src/internal/getHeadingList.ts","../../src/react/hooks/useContentObserver.ts","../../src/react/hooks/useContentController.ts","../../src/react/hooks/useTocObserver.ts","../../src/react/hooks/useTocController.ts","../../src/react/hooks/useTocElement.ts","../../src/react/hooks/useTocSideBar.ts"],"sourcesContent":["import { toPlatePlugin } from 'platejs/react';\n\nimport { BaseTocPlugin } from '../lib';\n\nexport const TocPlugin = toPlatePlugin(BaseTocPlugin);\n","export function checkIn(\n e: React.MouseEvent<HTMLElement, globalThis.MouseEvent>\n) {\n const event = window.event as unknown as React.MouseEvent<\n HTMLElement,\n globalThis.MouseEvent\n >;\n const x = Number(event.clientX); // 鼠标相对屏幕横坐标\n const y = Number(event.clientY); // 鼠标相对屏幕纵坐标\n\n const ele = e.target as HTMLElement;\n const div_x = Number(ele.getBoundingClientRect().left); // 相对屏幕的横坐标\n const div_x_width = Number(\n ele.getBoundingClientRect().left + ele.clientWidth\n ); // 相对屏幕的横坐标+width\n\n const div_y = Number(ele.getBoundingClientRect().top); // 相对屏幕的纵坐标\n const div_y_height = Number(\n ele.getBoundingClientRect().top + ele.clientHeight\n ); // 相对屏幕的纵坐标+height\n\n if (x > div_x && x < div_x_width && y > div_y && y < div_y_height) {\n return true;\n }\n\n return false;\n}\n","import type React from 'react';\n\nexport const heightToTop = (\n ele: HTMLElement,\n editorContentRef?: React.RefObject<HTMLDivElement | null>\n) => {\n const root = editorContentRef ? editorContentRef.current : document.body;\n\n if (!root || !ele) return 0;\n\n const containerRect = root.getBoundingClientRect();\n const elementRect = ele.getBoundingClientRect();\n\n const scrollY = root.scrollTop;\n const absoluteElementTop = elementRect.top + scrollY - containerRect.top;\n\n return absoluteElementTop;\n};\n","import { type SlateEditor, type TElement, NodeApi } from 'platejs';\n\nimport type { Heading } from '../lib/types';\n\nimport { BaseTocPlugin } from '../lib';\nimport { isHeading } from '../lib/utils/isHeading';\n\nconst headingDepth: Record<string, number> = {\n h1: 1,\n h2: 2,\n h3: 3,\n h4: 4,\n h5: 5,\n h6: 6,\n};\n\nexport const getHeadingList = (editor: SlateEditor) => {\n const options = editor.getOptions(BaseTocPlugin);\n\n if (options.queryHeading) {\n return options.queryHeading(editor);\n }\n\n const headingList: Heading[] = [];\n\n const values = editor.api.nodes<TElement>({\n at: [],\n match: (n) => isHeading(n),\n });\n\n if (!values) return [];\n\n for (const [node, path] of values) {\n const { type } = node;\n const title = NodeApi.string(node);\n const depth = headingDepth[type];\n const id = node.id as string;\n\n if (title) {\n headingList.push({ id, depth, path, title, type });\n }\n }\n\n return headingList;\n};\n","import React from 'react';\n\nimport { NodeApi } from 'platejs';\nimport { useEditorRef, useEditorSelector } from 'platejs/react';\n\nimport { getHeadingList } from '../../internal/getHeadingList';\n\ntype UseContentObserver = {\n editorContentRef: React.RefObject<HTMLElement | null>;\n isObserve: boolean;\n isScroll: boolean;\n rootMargin: string;\n status: number;\n};\n\nexport const useContentObserver = ({\n editorContentRef,\n isObserve,\n isScroll,\n rootMargin,\n status,\n}: UseContentObserver) => {\n const headingElementsRef = React.useRef<\n Record<string, IntersectionObserverEntry>\n >({});\n\n const editor = useEditorRef();\n const headingList = useEditorSelector(getHeadingList, []);\n\n const [activeId, setActiveId] = React.useState('');\n\n React.useEffect(() => {\n // ✅ Access ref inside effect, not during render\n const root = isScroll ? editorContentRef.current : undefined;\n\n const callback = (headings: IntersectionObserverEntry[]) => {\n if (!isObserve) return;\n\n headingElementsRef.current = headings.reduce((map, headingElement) => {\n map[headingElement.target.id] = headingElement;\n\n return map;\n }, headingElementsRef.current);\n\n const visibleHeadings: string[] = [];\n\n Object.keys(headingElementsRef.current).forEach((key) => {\n const headingElement = headingElementsRef.current[key];\n\n if (headingElement.isIntersecting) visibleHeadings.push(key);\n });\n const lastKey = Object.keys(headingElementsRef.current).pop()!;\n\n if (visibleHeadings.length > 0) {\n setActiveId(visibleHeadings[0] || lastKey);\n }\n headingElementsRef.current = {};\n };\n const observer = new IntersectionObserver(callback, {\n root,\n rootMargin,\n });\n\n headingList.forEach((item) => {\n const { path } = item;\n\n const node = NodeApi.get(editor, path);\n\n if (!node) return;\n\n const element = editor.api.toDOMNode(node);\n\n if (element) {\n observer.observe(element);\n }\n });\n\n return () => {\n observer.disconnect();\n };\n }, [\n headingList,\n isObserve,\n editor,\n editorContentRef,\n isScroll,\n rootMargin,\n status,\n ]);\n\n return { activeId };\n};\n","'use client';\n\nimport React from 'react';\n\nimport { KEYS } from 'platejs';\nimport { useEditorRef } from 'platejs/react';\n\nimport type { UseContentController } from '../types';\n\nimport { heightToTop } from '../utils';\nimport { useContentObserver } from './useContentObserver';\n\nexport const useContentController = ({\n containerRef,\n isObserve,\n rootMargin,\n topOffset,\n}: UseContentController) => {\n const editor = useEditorRef();\n const [editorContentRef, setEditorContentRef] = React.useState(containerRef);\n\n const isScrollRef = React.useRef(false);\n\n const isScroll =\n (editorContentRef.current?.scrollHeight || 0) >\n (editorContentRef.current?.clientHeight || 0);\n\n isScrollRef.current = isScroll;\n\n const scrollContainer = React.useMemo(() => {\n if (typeof window !== 'object') return;\n\n return isScroll ? editorContentRef.current : window;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isScroll]);\n\n const [status, setStatus] = React.useState(0);\n\n const { activeId } = useContentObserver({\n editorContentRef,\n isObserve,\n isScroll,\n rootMargin,\n status,\n });\n\n const [activeContentId, setActiveContentId] = React.useState(activeId);\n\n const onContentScroll = ({\n id,\n behavior = 'instant',\n el,\n }: {\n id: string;\n el: HTMLElement;\n behavior?: ScrollBehavior;\n }) => {\n setActiveContentId(id);\n\n if (isScrollRef.current) {\n editorContentRef.current?.scrollTo({\n behavior,\n top: heightToTop(el, editorContentRef) - topOffset,\n });\n } else {\n const top = heightToTop(el) - topOffset;\n // Note: if behavior === smooth,scrolling the toc then click the title immediately will scroll to the wrong position.It should be a chrome bug.\n window.scrollTo({ behavior, top });\n }\n\n editor\n .getApi({ key: KEYS.blockSelection })\n .blockSelection?.addSelectedRow?.(id);\n };\n\n React.useEffect(() => {\n setEditorContentRef(containerRef);\n }, [containerRef]);\n\n React.useEffect(() => {\n setActiveContentId(activeId);\n }, [activeId]);\n\n React.useEffect(() => {\n if (!scrollContainer) return;\n\n const scroll = () => {\n if (isObserve) {\n setStatus(Date.now());\n }\n };\n\n scrollContainer.addEventListener('scroll', scroll);\n\n return () => {\n scrollContainer.removeEventListener('scroll', scroll);\n };\n }, [isObserve, scrollContainer]);\n\n return { activeContentId, onContentScroll };\n};\n","import React from 'react';\n\ntype UseTocObserver = {\n activeId: string;\n isObserve: boolean;\n tocRef: React.RefObject<HTMLElement | null>;\n};\n\nexport const useTocObserver = ({\n activeId,\n isObserve,\n tocRef,\n}: UseTocObserver) => {\n const [visible, setVisible] = React.useState<boolean>(true);\n const [offset, setOffset] = React.useState<number>(0);\n\n React.useEffect(() => {\n // ✅ Access ref inside effect, not during render\n const root = tocRef.current;\n\n const updateOffset = (entries: IntersectionObserverEntry[]) => {\n if (!isObserve) return;\n\n const [entry] = entries;\n const { boundingClientRect, intersectionRatio, rootBounds } = entry;\n\n if (!rootBounds) return;\n\n const halfHeight = (root?.getBoundingClientRect().height || 0) / 2;\n const isAbove = boundingClientRect.top < rootBounds.top;\n const isBelow = boundingClientRect.bottom > rootBounds.bottom;\n const isVisible = intersectionRatio === 1;\n\n setVisible(isVisible);\n\n if (!isVisible) {\n const offset = isAbove\n ? boundingClientRect.top - rootBounds!.top! - halfHeight\n : isBelow\n ? boundingClientRect.bottom - rootBounds!.bottom! + halfHeight\n : 0;\n\n setOffset(offset);\n }\n };\n\n const observer = new IntersectionObserver(updateOffset, {\n root,\n });\n\n const element = root?.querySelectorAll('#toc_item_active')[0];\n\n if (element) observer.observe(element);\n\n return () => {\n observer.disconnect();\n };\n }, [tocRef, activeId, isObserve]);\n\n return { offset, visible };\n};\n","import React from 'react';\n\nimport { useTocObserver } from './useTocObserver';\n\ntype UseTocController = {\n activeId: string;\n isObserve: boolean;\n tocRef: React.RefObject<HTMLElement | null>;\n};\n\nexport const useTocController = ({\n activeId,\n isObserve,\n tocRef,\n}: UseTocController) => {\n const [activeTocId, setActiveTocId] = React.useState('');\n const { offset, visible } = useTocObserver({\n activeId: activeTocId,\n isObserve,\n tocRef,\n });\n\n React.useEffect(() => {\n if (!visible) {\n const tocItemWrapper = tocRef.current?.querySelector('#toc_wrap');\n const top = (tocItemWrapper?.scrollTop as any) + offset;\n\n tocItemWrapper?.scrollTo({ behavior: 'instant', top });\n }\n }, [visible, offset, tocRef]);\n\n React.useEffect(() => {\n setActiveTocId(activeId);\n }, [activeId]);\n};\n","import React from 'react';\n\nimport { KEYS, NodeApi } from 'platejs';\nimport {\n useEditorPlugin,\n useEditorSelector,\n useScrollRef,\n} from 'platejs/react';\n\nimport type { Heading } from '../../lib/types';\n\nimport { getHeadingList } from '../../internal/getHeadingList';\nimport { TocPlugin } from '../TocPlugin';\nimport { heightToTop } from '../utils';\n\nexport const useTocElementState = () => {\n const { editor, getOptions } = useEditorPlugin(TocPlugin);\n const { isScroll, topOffset } = getOptions();\n\n const headingList = useEditorSelector(getHeadingList, []);\n\n const containerRef = useScrollRef();\n\n const onContentScroll = React.useCallback(\n (el: HTMLElement, id: string, behavior: ScrollBehavior = 'instant') => {\n if (!containerRef.current) return;\n if (isScroll) {\n containerRef.current?.scrollTo({\n behavior,\n top: heightToTop(el, containerRef as any) - topOffset,\n });\n } else {\n const top = heightToTop(el) - topOffset;\n window.scrollTo({ behavior, top });\n }\n\n setTimeout(() => {\n editor\n .getApi({ key: KEYS.blockSelection })\n .blockSelection?.addSelectedRow?.(id);\n }, 0);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [isScroll, topOffset]\n );\n\n return { editor, headingList, onContentScroll };\n};\n\nexport const useTocElement = ({\n editor,\n onContentScroll,\n}: ReturnType<typeof useTocElementState>) => ({\n props: {\n onClick: (\n e: React.MouseEvent<HTMLElement, globalThis.MouseEvent>,\n item: Heading,\n behavior: ScrollBehavior\n ) => {\n e.preventDefault();\n const { id, path } = item;\n const node = NodeApi.get(editor, path);\n\n if (!node) return;\n\n const el = editor.api.toDOMNode(node);\n\n if (!el) return;\n\n onContentScroll(el, id, behavior);\n },\n },\n});\n","import React from 'react';\n\nimport { NodeApi } from 'platejs';\nimport { useEditorRef, useEditorSelector, useScrollRef } from 'platejs/react';\n\nimport type { Heading } from '../../lib/types';\nimport type { TocSideBarProps } from '../types';\n\nimport { useContentController, useTocController } from '.';\nimport { getHeadingList } from '../../internal/getHeadingList';\nimport { checkIn } from '../utils';\n\nexport const useTocSideBarState = ({\n open = true,\n rootMargin = '0px 0px 0px 0px',\n topOffset = 0,\n}: TocSideBarProps): any => {\n const editor = useEditorRef();\n const headingList = useEditorSelector(getHeadingList, []);\n const containerRef = useScrollRef();\n\n const tocRef = React.useRef<HTMLElement>(null);\n\n const [mouseInToc, setMouseInToc] = React.useState(false);\n\n const [isObserve, setIsObserve] = React.useState(open);\n\n const { activeContentId, onContentScroll } = useContentController({\n containerRef,\n isObserve,\n rootMargin,\n topOffset,\n });\n\n useTocController({\n activeId: activeContentId,\n isObserve,\n tocRef,\n });\n\n return {\n activeContentId,\n editor,\n headingList,\n mouseInToc,\n open,\n setIsObserve,\n setMouseInToc,\n tocRef,\n onContentScroll,\n };\n};\n\nexport const useTocSideBar = ({\n editor,\n mouseInToc,\n open,\n setIsObserve,\n setMouseInToc,\n tocRef,\n onContentScroll,\n}: ReturnType<typeof useTocSideBarState>) => {\n React.useEffect(() => {\n if (mouseInToc) {\n setIsObserve(false);\n } else {\n setIsObserve(true);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [mouseInToc]);\n\n const onContentClick = React.useCallback(\n (\n e: React.MouseEvent<HTMLElement, globalThis.MouseEvent>,\n item: Heading,\n behavior?: ScrollBehavior\n ) => {\n e.preventDefault();\n const { id, path } = item;\n const node = NodeApi.get(editor, path);\n\n if (!node) return;\n\n const el = editor.api.toDOMNode(node);\n\n if (!el) return;\n\n onContentScroll({ id, behavior, el });\n },\n [editor, onContentScroll]\n );\n\n return {\n navProps: {\n ref: tocRef,\n onMouseEnter: () => {\n if (!mouseInToc && open) {\n setMouseInToc(true);\n }\n },\n onMouseLeave: (\n e: React.MouseEvent<HTMLElement, globalThis.MouseEvent>\n ) => {\n if (open) {\n const isIn = checkIn(e);\n\n if (isIn !== mouseInToc) {\n setMouseInToc(isIn);\n }\n }\n },\n },\n onContentClick,\n };\n};\n"],"mappings":";;;;;;;AAIA,MAAaE,YAAYF,cAAcC,cAAc;;;;ACJrD,SAAgBE,QACdC,GACA;CACA,MAAMK,QAAQC,OAAOD;CAIrB,MAAME,IAAIC,OAAOH,MAAMI,QAAQ;CAC/B,MAAMC,IAAIF,OAAOH,MAAMM,QAAQ;CAE/B,MAAMC,MAAMZ,EAAEa;CACd,MAAMC,QAAQN,OAAOI,IAAIG,uBAAuB,CAACC,KA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K;AAErC,MAAI,CAACE,GAAI;AAETrB,kBAAgB;GAAEiB;GAAIH;GAAUO;GAAI,CAAC;IAEvC,CAACpC,QAAQe,gBACX,CAAC;AAED,QAAO;EACLwB,UAAU;GACRC,KAAKlC;GACLmC,oBAAoB;AAClB,QAAI,CAACjC,cAAcf,KACjBgB,eAAc,KAAK;;GAGvBiC,eACElB,MACG;AACH,QAAI/B,MAAM;KACR,MAAMkD,OAAOvD,QAAQoC,EAAE;AAEvB,SAAImB,SAASnC,WACXC,eAAckC,KAAK;;;GAI1B;EACDrB;EACD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Path } from "platejs";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/types.d.ts
|
|
4
|
+
type Heading = {
|
|
5
|
+
id: string;
|
|
6
|
+
depth: number;
|
|
7
|
+
path: Path;
|
|
8
|
+
title: string;
|
|
9
|
+
type: string;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { Heading as t };
|
|
13
|
+
//# sourceMappingURL=types-CqaZEV-V.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CqaZEV-V.d.ts","names":[],"sources":["../src/lib/types.ts"],"sourcesContent":[],"mappings":";;;KAEY,OAAA;;EAAA,KAAA,EAAA,MAAO;QAGX"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lofcz/platejs-toc",
|
|
3
|
+
"version": "52.0.11",
|
|
4
|
+
"description": "Table of Contents plugin for Plate",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"plate",
|
|
7
|
+
"plugin",
|
|
8
|
+
"slate"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://platejs.org",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/udecode/plate/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/lofcz/plate.git",
|
|
17
|
+
"directory": "packages/toc"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./dist/index.js",
|
|
23
|
+
"./react": "./dist/react/index.js",
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist/**/*"
|
|
30
|
+
],
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@plate/scripts": "1.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"platejs": ">=52.0.11",
|
|
36
|
+
"react": ">=18.0.0",
|
|
37
|
+
"react-dom": ">=18.0.0"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"type": "module",
|
|
43
|
+
"module": "./dist/index.js",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"react-compiler-runtime": "^1.0.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"brl": "plate-pkg p:brl",
|
|
49
|
+
"build": "plate-pkg p:build",
|
|
50
|
+
"build:watch": "plate-pkg p:build:watch",
|
|
51
|
+
"clean": "plate-pkg p:clean",
|
|
52
|
+
"lint": "plate-pkg p:lint",
|
|
53
|
+
"lint:fix": "plate-pkg p:lint:fix",
|
|
54
|
+
"test": "plate-pkg p:test",
|
|
55
|
+
"test:watch": "plate-pkg p:test:watch",
|
|
56
|
+
"typecheck": "plate-pkg p:typecheck"
|
|
57
|
+
}
|
|
58
|
+
}
|