@a200888213/gbdocx 0.6.2 → 0.6.3

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.
@@ -1,41 +1,41 @@
1
- // [文件] web·office·docx·目录 —— 正文标题树抽取与点击定位(列表项带元素引用,缩进由 level 表达,面板只消费这份扁平列表)
2
- import { DOC_CLASS } from '../editor/engine/schema.js';
3
- import { CATALOG_HIT } from '../editor/engine/dom.js';
4
-
5
- /**
6
- * 抽目录:正文根内的标题按文档顺序扁平化
7
- * @param {HTMLElement} root 编辑面根
8
- * @returns {Array<{key:string, text:string, level:number, el:HTMLElement}>}
9
- */
10
- export const collectCatalog = (root) => {
11
- if (!root) return [];
12
- const out = [];
13
- for (const el of Array.from(root.querySelectorAll('h1,h2,h3,h4,h5,h6'))) {
14
- const text = (el.textContent || '').trim();
15
- if (!text) continue;
16
- const level = el.classList.contains(DOC_CLASS.TITLE) ? 1 : Number(el.tagName[1]);
17
- out.push({ key: `t${out.length + 1}`, text, level, el });
18
- }
19
- return out;
20
- };
21
-
22
- /** 目录项定位:滚进视口并闪一下(与批注锚点定位同口径,禁各自写一套滚动) */
23
- const scrollToCatalogItem = (el) => {
24
- if (!el) return;
25
- el.scrollIntoView({ block: 'center', behavior: 'smooth' });
26
- el.classList.add(CATALOG_HIT);
27
- setTimeout(() => el.classList.remove(CATALOG_HIT), 1200);
28
- };
29
-
30
- /** 目录接线:重建目录(原位替换,Vue 才能追踪) */
31
- export const bindCatalog = (list, root) => {
32
- list.value = collectCatalog(root);
33
- };
34
-
35
- /** 定位某一项,返回命中的键(未命中返回 null) */
36
- export const gotoCatalogItem = (list, key) => {
37
- const item = (list.value || []).find((c) => c.key === key);
38
- if (!item) return null;
39
- scrollToCatalogItem(item.el);
40
- return key;
41
- };
1
+ // [文件] web·office·docx·目录 —— 正文标题树抽取与点击定位(列表项带元素引用,缩进由 level 表达,面板只消费这份扁平列表)
2
+ import { DOC_CLASS } from '../editor/engine/schema.js';
3
+ import { CATALOG_HIT } from '../editor/engine/dom.js';
4
+
5
+ /**
6
+ * 抽目录:正文根内的标题按文档顺序扁平化
7
+ * @param {HTMLElement} root 编辑面根
8
+ * @returns {Array<{key:string, text:string, level:number, el:HTMLElement}>}
9
+ */
10
+ export const collectCatalog = (root) => {
11
+ if (!root) return [];
12
+ const out = [];
13
+ for (const el of Array.from(root.querySelectorAll('h1,h2,h3,h4,h5,h6'))) {
14
+ const text = (el.textContent || '').trim();
15
+ if (!text) continue;
16
+ const level = el.classList.contains(DOC_CLASS.TITLE) ? 1 : Number(el.tagName[1]);
17
+ out.push({ key: `t${out.length + 1}`, text, level, el });
18
+ }
19
+ return out;
20
+ };
21
+
22
+ /** 目录项定位:滚进视口并闪一下(与批注锚点定位同口径,禁各自写一套滚动) */
23
+ const scrollToCatalogItem = (el) => {
24
+ if (!el) return;
25
+ el.scrollIntoView({ block: 'center', behavior: 'smooth' });
26
+ el.classList.add(CATALOG_HIT);
27
+ setTimeout(() => el.classList.remove(CATALOG_HIT), 1200);
28
+ };
29
+
30
+ /** 目录接线:重建目录(原位替换,Vue 才能追踪) */
31
+ export const bindCatalog = (list, root) => {
32
+ list.value = collectCatalog(root);
33
+ };
34
+
35
+ /** 定位某一项,返回命中的键(未命中返回 null) */
36
+ export const gotoCatalogItem = (list, key) => {
37
+ const item = (list.value || []).find((c) => c.key === key);
38
+ if (!item) return null;
39
+ scrollToCatalogItem(item.el);
40
+ return key;
41
+ };