@a200888213/gbdocx 0.6.1 → 0.6.2
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/package.json +1 -1
- package/src/app/file-io.js +122 -122
- package/src/app/main.js +9 -9
- package/src/app/word/catalog.js +52 -52
- package/src/app/word/comments.js +112 -112
- package/src/app/word/doc.js +113 -113
- package/src/app/word/edit.js +72 -72
- package/src/app/word/hf.js +76 -76
- package/src/app/word/layout.js +155 -155
- package/src/app/word/notes.js +110 -110
- package/src/app/word/shared.js +22 -22
- package/src/app/word-sheets.js +101 -101
- package/src/kernel/docx/codec/blocks.js +123 -123
- package/src/kernel/docx/codec/carry.js +129 -129
- package/src/kernel/docx/codec/comments.js +25 -25
- package/src/kernel/docx/codec/docx.js +198 -198
- package/src/kernel/docx/codec/docxStyles.js +177 -177
- package/src/kernel/docx/codec/fonts.js +195 -195
- package/src/kernel/docx/codec/helpers.js +161 -161
- package/src/kernel/docx/codec/hfHtml.js +152 -152
- package/src/kernel/docx/codec/html.js +739 -739
- package/src/kernel/docx/codec/losses.js +420 -420
- package/src/kernel/docx/codec/markdown.js +170 -170
- package/src/kernel/docx/codec/parts.js +249 -249
- package/src/kernel/docx/codec/read.js +603 -603
- package/src/kernel/docx/codec/render.js +1156 -1156
- package/src/kernel/docx/codec/roundtrip.js +236 -236
- package/src/kernel/docx/codec/write.js +833 -833
- package/src/kernel/docx/comments.js +14 -14
- package/src/kernel/docx/pageGeometry.js +123 -123
- package/src/kernel/docx/pagination.js +481 -481
- package/src/kernel/docx/watermark.js +45 -45
- package/src/kernel/editor/constants.js +8 -8
- package/src/kernel/editor/engine/blocks.js +594 -594
- package/src/kernel/editor/engine/blocksEnter.js +109 -109
- package/src/kernel/editor/engine/blocksInsert.js +254 -254
- package/src/kernel/editor/engine/blocksStructure.js +226 -226
- package/src/kernel/editor/engine/commands.js +181 -181
- package/src/kernel/editor/engine/dom.js +646 -646
- package/src/kernel/editor/engine/history.js +149 -149
- package/src/kernel/editor/engine/inline.js +656 -656
- package/src/kernel/editor/engine/input.js +554 -554
- package/src/kernel/editor/engine/interaction.js +137 -137
- package/src/kernel/editor/engine/pointer.js +39 -39
- package/src/kernel/editor/engine/revision.js +138 -138
- package/src/kernel/editor/engine/schema.js +417 -417
- package/src/kernel/editor/engine/selection.js +119 -119
- package/src/kernel/editor/engine/state.js +118 -118
- package/src/kernel/editor/engine/tableClip.js +154 -154
- package/src/kernel/editor/engine/tableGrid.js +55 -55
- package/src/kernel/editor/engine/tableInteraction.js +388 -388
- package/src/kernel/editor/engine/tableMenu.js +250 -250
- package/src/kernel/editor/engine/tableOps.js +174 -174
- package/src/kernel/editor/engine/tables.js +732 -732
- package/src/kernel/editor/overlayGeometry.js +20 -20
- package/src/kernel/editor/utils.js +48 -48
- package/src/kernel/keyboard.js +114 -114
- package/src/kernel/textStyles.js +84 -84
- package/src/kernel/util/imageFile.js +91 -91
- package/src/kernel/util/shortcutKey.js +33 -33
- package/src/surface/editor-surface.js +600 -600
- package/src/ui/color-panel.js +69 -69
- package/src/ui/context-menu.js +133 -133
- package/src/ui/find-bar.js +151 -151
- package/src/ui/menubar.js +28 -28
- package/src/ui/panels.js +115 -115
- package/src/ui/prompt.js +89 -89
- package/src/ui/ribbon.js +485 -485
- package/src/ui/special-chars.js +39 -39
- package/src/ui/statusbar.js +81 -81
- package/src/ui/toolbar.js +32 -32
- package/styles/editor-content.css +440 -440
- package/styles/tokens.css +154 -154
- package/styles/word-panel.css +1 -1
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
// [文件] web·editor-kernel·engine·history —— 内核历史栈与编辑态:一次改写 = 一次历史提交 + 一次变更上报(混入 EditorCore.prototype)
|
|
2
|
-
// [设计] 历史以「整篇 innerHTML 快照」为记账单位,配合 typing 合并窗口把连续输入合成一条撤销记录。
|
|
3
|
-
import { normalizeBody } from './schema.js';
|
|
4
|
-
|
|
5
|
-
/** 历史栈深度上限 */
|
|
6
|
-
const HISTORY_LIMIT = 120;
|
|
7
|
-
|
|
8
|
-
/** 连续输入合入同一条历史记录的空闲窗口 */
|
|
9
|
-
const TYPING_MERGE_MS = 600;
|
|
10
|
-
|
|
11
|
-
/** 历史与编辑态方法(装配到 EditorCore.prototype;this 为内核实例) */
|
|
12
|
-
export const historyMethods = {
|
|
13
|
-
snapshot() {
|
|
14
|
-
return { html: this.root.innerHTML, sel: this.captureSelection() };
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
pushHistory() {
|
|
18
|
-
if (!this.baseline) return;
|
|
19
|
-
const last = this.undoStack[this.undoStack.length - 1];
|
|
20
|
-
// [坑] 同状态重复入栈会让「撤销」看起来没反应(弹出来的是改动后的快照)
|
|
21
|
-
if (last && last.html === this.baseline.html) return;
|
|
22
|
-
this.undoStack.push(this.baseline);
|
|
23
|
-
if (this.undoStack.length > HISTORY_LIMIT) this.undoStack.shift();
|
|
24
|
-
this.redoStack = [];
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 执行一次 DOM 改写:入历史 + 上报变更
|
|
29
|
-
* @param {Function} mutate 直接操作 DOM 的回调
|
|
30
|
-
* @param {{merge?:boolean, coalesce?:boolean}} options merge=true 合入当前输入会话(输入规则不另起一条撤销记录);
|
|
31
|
-
* coalesce=true 合入调用方自己开好的一步(拖列宽这类逐帧动作,整次手势只留一条撤销记录)
|
|
32
|
-
*/
|
|
33
|
-
run(mutate, options = {}) {
|
|
34
|
-
if (this.destroyed) return false;
|
|
35
|
-
if (!options.coalesce && !(options.merge && this.typing)) this.pushHistory();
|
|
36
|
-
const beforeSel = this.captureSelection();
|
|
37
|
-
this.applying = true;
|
|
38
|
-
this.typing = false;
|
|
39
|
-
clearTimeout(this.idleTimer);
|
|
40
|
-
try {
|
|
41
|
-
mutate();
|
|
42
|
-
} finally {
|
|
43
|
-
Promise.resolve().then(() => {
|
|
44
|
-
this.applying = false;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
this.keepSelection(beforeSel);
|
|
48
|
-
this.baseline = this.snapshot();
|
|
49
|
-
this.afterChange();
|
|
50
|
-
return true;
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 静默改写:运行期布局(Word 分页的占位 / 栏容器 / 拆块)专用——改写照跑,
|
|
55
|
-
* 但观察者记账窗口整个关掉:不入历史、不标脏、不上报 update
|
|
56
|
-
*/
|
|
57
|
-
quietly(mutate) {
|
|
58
|
-
if (this.destroyed) return;
|
|
59
|
-
this.applying = true;
|
|
60
|
-
try {
|
|
61
|
-
mutate();
|
|
62
|
-
} finally {
|
|
63
|
-
// [坑] 与 run() 同一口径:观察者回调是微任务,同步解锁会让分页产物被判成正文变更
|
|
64
|
-
Promise.resolve().then(() => {
|
|
65
|
-
this.applying = false;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
/** 建议修改模式开关(开启后键入/删除被拦成修订标记;Word 应用的状态栏与菜单驱动) */
|
|
71
|
-
setSuggesting(on) {
|
|
72
|
-
this.suggesting = Boolean(on);
|
|
73
|
-
this.syncState();
|
|
74
|
-
return true;
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
/** 当前是否可写(只读档由 setEditable(false) 落到 contenteditable;工具栏/浮层可用性统一问它) */
|
|
78
|
-
isEditable() {
|
|
79
|
-
return this.root.getAttribute('contenteditable') !== 'false';
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
/** 只读开关(切 contenteditable;按钮可用性由宿主按自身档位决定) */
|
|
83
|
-
setEditable(on) {
|
|
84
|
-
this.root.setAttribute('contenteditable', on ? 'true' : 'false');
|
|
85
|
-
this.syncState();
|
|
86
|
-
return true;
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
onDomMutated() {
|
|
90
|
-
if (this.applying || this.destroyed) return;
|
|
91
|
-
if (!this.typing) {
|
|
92
|
-
this.pushHistory();
|
|
93
|
-
this.typing = true;
|
|
94
|
-
}
|
|
95
|
-
clearTimeout(this.idleTimer);
|
|
96
|
-
this.idleTimer = setTimeout(() => {
|
|
97
|
-
this.typing = false;
|
|
98
|
-
this.baseline = this.snapshot();
|
|
99
|
-
this.afterChange();
|
|
100
|
-
}, TYPING_MERGE_MS);
|
|
101
|
-
this.emit('update');
|
|
102
|
-
this.syncState();
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
undo() {
|
|
106
|
-
if (!this.undoStack.length) return false;
|
|
107
|
-
if (this.typing) {
|
|
108
|
-
this.typing = false;
|
|
109
|
-
clearTimeout(this.idleTimer);
|
|
110
|
-
}
|
|
111
|
-
this.redoStack.push(this.snapshot());
|
|
112
|
-
this.restore(this.undoStack.pop());
|
|
113
|
-
return true;
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
redo() {
|
|
117
|
-
if (!this.redoStack.length) return false;
|
|
118
|
-
this.undoStack.push(this.snapshot());
|
|
119
|
-
this.restore(this.redoStack.pop());
|
|
120
|
-
return true;
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
restore(entry) {
|
|
124
|
-
this.applying = true;
|
|
125
|
-
this.root.innerHTML = entry.html;
|
|
126
|
-
normalizeBody(this.root, { editable: true });
|
|
127
|
-
setTimeout(() => {
|
|
128
|
-
this.applying = false;
|
|
129
|
-
}, 0);
|
|
130
|
-
this.baseline = { ...entry };
|
|
131
|
-
this.pending = null;
|
|
132
|
-
// [坑] 整篇换 DOM 后,表格框选与右键命中的旧元素引用全部脱离文档:不清掉的话,
|
|
133
|
-
// 撤销/重做之后紧接着的表格菜单动作会因取不到上下文而静默失效(又是「点了没反应」)
|
|
134
|
-
this.cellRect = null;
|
|
135
|
-
this.contextCell = null;
|
|
136
|
-
this.cellDragFrom = null;
|
|
137
|
-
this.selectedAtom = null;
|
|
138
|
-
this.afterChange();
|
|
139
|
-
const sel = entry.sel;
|
|
140
|
-
this.applyCaptured(sel);
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
afterChange() {
|
|
144
|
-
this.search.refresh();
|
|
145
|
-
this.emit('update');
|
|
146
|
-
this.emit('transaction');
|
|
147
|
-
this.syncState();
|
|
148
|
-
},
|
|
149
|
-
};
|
|
1
|
+
// [文件] web·editor-kernel·engine·history —— 内核历史栈与编辑态:一次改写 = 一次历史提交 + 一次变更上报(混入 EditorCore.prototype)
|
|
2
|
+
// [设计] 历史以「整篇 innerHTML 快照」为记账单位,配合 typing 合并窗口把连续输入合成一条撤销记录。
|
|
3
|
+
import { normalizeBody } from './schema.js';
|
|
4
|
+
|
|
5
|
+
/** 历史栈深度上限 */
|
|
6
|
+
const HISTORY_LIMIT = 120;
|
|
7
|
+
|
|
8
|
+
/** 连续输入合入同一条历史记录的空闲窗口 */
|
|
9
|
+
const TYPING_MERGE_MS = 600;
|
|
10
|
+
|
|
11
|
+
/** 历史与编辑态方法(装配到 EditorCore.prototype;this 为内核实例) */
|
|
12
|
+
export const historyMethods = {
|
|
13
|
+
snapshot() {
|
|
14
|
+
return { html: this.root.innerHTML, sel: this.captureSelection() };
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
pushHistory() {
|
|
18
|
+
if (!this.baseline) return;
|
|
19
|
+
const last = this.undoStack[this.undoStack.length - 1];
|
|
20
|
+
// [坑] 同状态重复入栈会让「撤销」看起来没反应(弹出来的是改动后的快照)
|
|
21
|
+
if (last && last.html === this.baseline.html) return;
|
|
22
|
+
this.undoStack.push(this.baseline);
|
|
23
|
+
if (this.undoStack.length > HISTORY_LIMIT) this.undoStack.shift();
|
|
24
|
+
this.redoStack = [];
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 执行一次 DOM 改写:入历史 + 上报变更
|
|
29
|
+
* @param {Function} mutate 直接操作 DOM 的回调
|
|
30
|
+
* @param {{merge?:boolean, coalesce?:boolean}} options merge=true 合入当前输入会话(输入规则不另起一条撤销记录);
|
|
31
|
+
* coalesce=true 合入调用方自己开好的一步(拖列宽这类逐帧动作,整次手势只留一条撤销记录)
|
|
32
|
+
*/
|
|
33
|
+
run(mutate, options = {}) {
|
|
34
|
+
if (this.destroyed) return false;
|
|
35
|
+
if (!options.coalesce && !(options.merge && this.typing)) this.pushHistory();
|
|
36
|
+
const beforeSel = this.captureSelection();
|
|
37
|
+
this.applying = true;
|
|
38
|
+
this.typing = false;
|
|
39
|
+
clearTimeout(this.idleTimer);
|
|
40
|
+
try {
|
|
41
|
+
mutate();
|
|
42
|
+
} finally {
|
|
43
|
+
Promise.resolve().then(() => {
|
|
44
|
+
this.applying = false;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
this.keepSelection(beforeSel);
|
|
48
|
+
this.baseline = this.snapshot();
|
|
49
|
+
this.afterChange();
|
|
50
|
+
return true;
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 静默改写:运行期布局(Word 分页的占位 / 栏容器 / 拆块)专用——改写照跑,
|
|
55
|
+
* 但观察者记账窗口整个关掉:不入历史、不标脏、不上报 update
|
|
56
|
+
*/
|
|
57
|
+
quietly(mutate) {
|
|
58
|
+
if (this.destroyed) return;
|
|
59
|
+
this.applying = true;
|
|
60
|
+
try {
|
|
61
|
+
mutate();
|
|
62
|
+
} finally {
|
|
63
|
+
// [坑] 与 run() 同一口径:观察者回调是微任务,同步解锁会让分页产物被判成正文变更
|
|
64
|
+
Promise.resolve().then(() => {
|
|
65
|
+
this.applying = false;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
/** 建议修改模式开关(开启后键入/删除被拦成修订标记;Word 应用的状态栏与菜单驱动) */
|
|
71
|
+
setSuggesting(on) {
|
|
72
|
+
this.suggesting = Boolean(on);
|
|
73
|
+
this.syncState();
|
|
74
|
+
return true;
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
/** 当前是否可写(只读档由 setEditable(false) 落到 contenteditable;工具栏/浮层可用性统一问它) */
|
|
78
|
+
isEditable() {
|
|
79
|
+
return this.root.getAttribute('contenteditable') !== 'false';
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
/** 只读开关(切 contenteditable;按钮可用性由宿主按自身档位决定) */
|
|
83
|
+
setEditable(on) {
|
|
84
|
+
this.root.setAttribute('contenteditable', on ? 'true' : 'false');
|
|
85
|
+
this.syncState();
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
onDomMutated() {
|
|
90
|
+
if (this.applying || this.destroyed) return;
|
|
91
|
+
if (!this.typing) {
|
|
92
|
+
this.pushHistory();
|
|
93
|
+
this.typing = true;
|
|
94
|
+
}
|
|
95
|
+
clearTimeout(this.idleTimer);
|
|
96
|
+
this.idleTimer = setTimeout(() => {
|
|
97
|
+
this.typing = false;
|
|
98
|
+
this.baseline = this.snapshot();
|
|
99
|
+
this.afterChange();
|
|
100
|
+
}, TYPING_MERGE_MS);
|
|
101
|
+
this.emit('update');
|
|
102
|
+
this.syncState();
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
undo() {
|
|
106
|
+
if (!this.undoStack.length) return false;
|
|
107
|
+
if (this.typing) {
|
|
108
|
+
this.typing = false;
|
|
109
|
+
clearTimeout(this.idleTimer);
|
|
110
|
+
}
|
|
111
|
+
this.redoStack.push(this.snapshot());
|
|
112
|
+
this.restore(this.undoStack.pop());
|
|
113
|
+
return true;
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
redo() {
|
|
117
|
+
if (!this.redoStack.length) return false;
|
|
118
|
+
this.undoStack.push(this.snapshot());
|
|
119
|
+
this.restore(this.redoStack.pop());
|
|
120
|
+
return true;
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
restore(entry) {
|
|
124
|
+
this.applying = true;
|
|
125
|
+
this.root.innerHTML = entry.html;
|
|
126
|
+
normalizeBody(this.root, { editable: true });
|
|
127
|
+
setTimeout(() => {
|
|
128
|
+
this.applying = false;
|
|
129
|
+
}, 0);
|
|
130
|
+
this.baseline = { ...entry };
|
|
131
|
+
this.pending = null;
|
|
132
|
+
// [坑] 整篇换 DOM 后,表格框选与右键命中的旧元素引用全部脱离文档:不清掉的话,
|
|
133
|
+
// 撤销/重做之后紧接着的表格菜单动作会因取不到上下文而静默失效(又是「点了没反应」)
|
|
134
|
+
this.cellRect = null;
|
|
135
|
+
this.contextCell = null;
|
|
136
|
+
this.cellDragFrom = null;
|
|
137
|
+
this.selectedAtom = null;
|
|
138
|
+
this.afterChange();
|
|
139
|
+
const sel = entry.sel;
|
|
140
|
+
this.applyCaptured(sel);
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
afterChange() {
|
|
144
|
+
this.search.refresh();
|
|
145
|
+
this.emit('update');
|
|
146
|
+
this.emit('transaction');
|
|
147
|
+
this.syncState();
|
|
148
|
+
},
|
|
149
|
+
};
|