@a200888213/gbdocx 0.5.2 → 0.6.0
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/README.md +215 -207
- package/index.html +3 -2
- package/package.json +48 -48
- package/serve.mjs +3 -2
- 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/file.js +30 -1
- 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/view.js +6 -2
- package/src/app/word-app.js +486 -469
- 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/icons.js +137 -135
- 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
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
// [文件] web·editor-kernel·engine·commands —— 命令注册表(UI 只传命令名与参数;串多个内置命令的复合动作在宿主 actions)
|
|
2
|
-
import { normalizeHex } from 'guabiutils';
|
|
3
|
-
import * as D from './dom.js';
|
|
4
|
-
import * as I from './inline.js';
|
|
5
|
-
import * as B from './blocks.js';
|
|
6
|
-
import * as T from './tables.js';
|
|
7
|
-
import * as R from './revision.js';
|
|
8
|
-
import { ATTACH_ATTR, parseFragment } from './schema.js';
|
|
9
|
-
import { insertFragment } from './input.js';
|
|
10
|
-
|
|
11
|
-
/** 命令注册表:UI 只传命令名与参数,串多个内置命令的复合动作在 actions.js */
|
|
12
|
-
export const COMMANDS = {
|
|
13
|
-
// [坑] 撤销/重做自带历史栈,不能再被 exec 的 run() 包一层入栈(否则 undo 会弹到自己刚推进去的那条)
|
|
14
|
-
undo: { raw: true, run: (ed) => ed.undo(), can: (ed) => ed.undoStack.length > 0 },
|
|
15
|
-
redo: { raw: true, run: (ed) => ed.redo(), can: (ed) => ed.redoStack.length > 0 },
|
|
16
|
-
// 全选只动选区不动正文:raw 跳过历史,避免 Ctrl+A 也塞一条撤销记录
|
|
17
|
-
selectAll: {
|
|
18
|
-
raw: true,
|
|
19
|
-
run: (ed) => {
|
|
20
|
-
ed.focus();
|
|
21
|
-
ed.clearCellSelection?.();
|
|
22
|
-
ed.clearAtom?.();
|
|
23
|
-
const range = document.createRange();
|
|
24
|
-
range.selectNodeContents(ed.root);
|
|
25
|
-
const sel = window.getSelection();
|
|
26
|
-
if (!sel) return false;
|
|
27
|
-
sel.removeAllRanges();
|
|
28
|
-
sel.addRange(range);
|
|
29
|
-
return true;
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
toggleBold: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'bold') },
|
|
34
|
-
toggleItalic: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'italic') },
|
|
35
|
-
toggleUnderline: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'underline') },
|
|
36
|
-
toggleStrike: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'strike') },
|
|
37
|
-
toggleCode: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'code') },
|
|
38
|
-
toggleSuperscript: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'superscript') },
|
|
39
|
-
toggleSubscript: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'subscript') },
|
|
40
|
-
|
|
41
|
-
setColor: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'color', normalizeHex(value)) },
|
|
42
|
-
unsetColor: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'color', '') },
|
|
43
|
-
setBackgroundColor: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'backgroundColor', normalizeHex(value)) },
|
|
44
|
-
unsetBackgroundColor: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'backgroundColor', '') },
|
|
45
|
-
setFontSize: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'fontSize', value) },
|
|
46
|
-
unsetFontSize: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'fontSize', '') },
|
|
47
|
-
setFontFamily: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'fontFamily', value) },
|
|
48
|
-
unsetFontFamily: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'fontFamily', '') },
|
|
49
|
-
// 字体效果:空心(-webkit-text-stroke)/ 阴影(text-shadow),值形如 '0.2px currentColor' / '1px 1px var(...)'
|
|
50
|
-
setTextStroke: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'textStroke', value) },
|
|
51
|
-
unsetTextStroke: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'textStroke', '') },
|
|
52
|
-
setTextShadow: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'textShadow', value) },
|
|
53
|
-
unsetTextShadow: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'textShadow', '') },
|
|
54
|
-
// 组合色(前景 + 背景一体):一次落两个标记(拆两次会因块 DOM 重建丢选区,见 setStyleMarks 的 [坑])
|
|
55
|
-
setComboStyle: {
|
|
56
|
-
run: (ed, color, backgroundColor) =>
|
|
57
|
-
I.setStyleMarks(inlineCtx(ed), { color: normalizeHex(color), backgroundColor: normalizeHex(backgroundColor) }),
|
|
58
|
-
},
|
|
59
|
-
setLink: { run: (ed, href) => I.setLinkMark(inlineCtx(ed), href) },
|
|
60
|
-
unsetLink: { run: (ed) => I.setLinkMark(inlineCtx(ed), '') },
|
|
61
|
-
clearFormat: {
|
|
62
|
-
run: (ed) => {
|
|
63
|
-
const ctx = inlineCtx(ed);
|
|
64
|
-
const inline = I.clearInlineMarks(ctx);
|
|
65
|
-
const block = B.resetBlockStyle(ed.root, ctx.ranges);
|
|
66
|
-
return inline || block;
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
setParagraph: { run: (ed) => B.setBlockKind(ed.root, 'paragraph') },
|
|
71
|
-
setHeading: { run: (ed, level) => B.setBlockKind(ed.root, `heading${Number(level) || 1}`) },
|
|
72
|
-
toggleBlockquote: { run: (ed) => B.setBlockKind(ed.root, 'blockquote') },
|
|
73
|
-
toggleCodeBlock: { run: (ed) => B.setBlockKind(ed.root, 'codeBlock') },
|
|
74
|
-
toggleBulletList: { run: (ed) => B.setBlockKind(ed.root, 'bulletList') },
|
|
75
|
-
toggleOrderedList: { run: (ed) => B.setBlockKind(ed.root, 'orderedList') },
|
|
76
|
-
toggleTaskList: { run: (ed) => B.setBlockKind(ed.root, 'taskList') },
|
|
77
|
-
setHorizontalRule: { run: (ed) => B.insertDivider(ed.root) },
|
|
78
|
-
insertPageBreak: { run: (ed) => B.insertPageBreak(ed.root) },
|
|
79
|
-
insertCallout: { run: (ed, variant) => B.insertCallout(ed.root, variant) },
|
|
80
|
-
insertSuperBlock: { run: (ed, cols) => B.insertSuperBlock(ed.root, cols) },
|
|
81
|
-
// 超级块列增删(el 可为超级块或其内的列;笔记域块菜单消费)
|
|
82
|
-
addColumn: { run: (ed, el) => B.addColumn(ed.root, el) },
|
|
83
|
-
removeColumn: { run: (ed, el) => B.removeColumn(ed.root, el) },
|
|
84
|
-
// 拖块并排:把拖拽块与目标块合成 2 列超级块(块标拖拽到目标左/右边缘放下)
|
|
85
|
-
wrapInSuper: { run: (ed, dragged, target, side) => B.wrapInSuper(ed.root, dragged, target, side) },
|
|
86
|
-
insertImage: { run: (ed, spec) => B.insertImageInline(ed.root, spec) },
|
|
87
|
-
// 笔记资产图片(<img data-gbBlk-asset> + 直链 src;与 .gbRtx 的 insertImage 各归各)
|
|
88
|
-
insertAssetImage: { run: (ed, spec) => B.insertAssetImage(ed.root, spec) },
|
|
89
|
-
insertText: { run: (ed, text) => B.insertTextAtSelection(ed.root, text) },
|
|
90
|
-
// 受控 HTML 片段插入(宿主生成的复杂块,如 docx 目录块)
|
|
91
|
-
// [约束] 只允许应用代码生成的受控 HTML:不走粘贴清洗(它面向外来内容,会剥 class 等编解码标记)
|
|
92
|
-
insertHtml: {
|
|
93
|
-
run: (ed, html) => {
|
|
94
|
-
const frag = parseFragment(String(html || ''));
|
|
95
|
-
if (!frag.childNodes.length) return false;
|
|
96
|
-
insertFragment(ed, frag);
|
|
97
|
-
return true;
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
// 批注锚点(span.doc-comment):选区打键 / 按宿主数据删除某键的全部锚点
|
|
102
|
-
setComment: { run: (ed, key) => I.setCommentMark(inlineCtx(ed), key) },
|
|
103
|
-
removeComment: { run: (ed, key) => I.removeCommentRange(ed.root, key) > 0 },
|
|
104
|
-
|
|
105
|
-
// 脚注/尾注锚点(sup.doc-footnote/endnote[data-fn];Word 应用消费)
|
|
106
|
-
insertNote: { run: (ed, spec) => I.insertNoteAnchor(ed.root, spec) },
|
|
107
|
-
removeNote: { run: (ed, id) => I.removeNoteAnchor(ed.root, id) },
|
|
108
|
-
|
|
109
|
-
// 笔记行内锚(span.doc-attach 附件引用 / span.doc-ref 块·文档引用;笔记域专用,.gbRtx 侧不产生)
|
|
110
|
-
insertAttach: { run: (ed, spec) => I.insertAnchorAtCursor(ed.root, 'attach', spec) },
|
|
111
|
-
removeAttach: { run: (ed, id) => I.removeAnchorsByAttr(ed.root, ATTACH_ATTR, id) },
|
|
112
|
-
insertRef: { run: (ed, spec) => I.insertAnchorAtCursor(ed.root, 'ref', spec) },
|
|
113
|
-
|
|
114
|
-
// 笔记引用节点转换(宿主右键菜单入口):行内引用 ↔ 嵌入块 / 锚文本类型 / 删除
|
|
115
|
-
convertRefToEmbed: { run: (ed, el, html) => I.convertRefToEmbed(ed.root, el, html) },
|
|
116
|
-
convertEmbedToRef: { run: (ed, el) => I.convertEmbedToRef(el) },
|
|
117
|
-
setRefSub: { run: (ed, el, sub) => I.setRefSub(el, sub) },
|
|
118
|
-
removeAnchor: { run: (ed, el) => I.removeAnchorNode(el) },
|
|
119
|
-
|
|
120
|
-
// 修订接受/拒绝(Word 应用;普通富文本不暴露入口)
|
|
121
|
-
resolveRevisions: { run: (ed, accept) => R.resolveRevisions(ed.root, accept) > 0 },
|
|
122
|
-
resolveRevisionAt: { run: (ed, el, accept) => R.resolveRevisionAt(el, accept) },
|
|
123
|
-
|
|
124
|
-
increaseBlockIndent: { run: (ed) => B.changeBlockIndent(ed.root, 1), can: (ed) => ed.state().canIndent },
|
|
125
|
-
decreaseBlockIndent: { run: (ed) => B.changeBlockIndent(ed.root, -1), can: (ed) => ed.state().canOutdent },
|
|
126
|
-
toggleFirstLineIndent: { run: (ed) => B.toggleFirstLineIndent(ed.root) },
|
|
127
|
-
setBlockLineHeight: { run: (ed, value) => B.setLineHeight(ed.root, value) },
|
|
128
|
-
setBlockAlign: { run: (ed, value) => B.setBlockAlign(ed.root, value) },
|
|
129
|
-
|
|
130
|
-
duplicateBlock: { run: (ed, el) => B.duplicateBlock(ed.root, el) },
|
|
131
|
-
deleteBlock: { run: (ed, el) => B.deleteBlock(ed.root, el) },
|
|
132
|
-
insertBlockNear: { run: (ed, el, position) => B.insertBlockNear(ed.root, position, el) },
|
|
133
|
-
moveBlockUp: { run: (ed, el) => B.moveBlock(ed.root, el, -1) },
|
|
134
|
-
moveBlockDown: { run: (ed, el) => B.moveBlock(ed.root, el, 1) },
|
|
135
|
-
moveBlockTo: { run: (ed, el, ref, before) => B.moveBlockTo(el, ref, before) },
|
|
136
|
-
moveTableTo: { run: (ed, table, ref, before) => B.moveTableTo(ed.root, table, ref, before) },
|
|
137
|
-
deleteRange: {
|
|
138
|
-
run: (ed, { block, from, to }) => {
|
|
139
|
-
if (!block?.isConnected) return false;
|
|
140
|
-
const range = D.rangeInBlock(block, from, to);
|
|
141
|
-
range.deleteContents();
|
|
142
|
-
D.selectRange(ed.root, { block, offset: from }, { block, offset: from });
|
|
143
|
-
return true;
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
insertTable: {
|
|
148
|
-
run: (ed, { rows = 2, cols = 2, withHeaderRow = true } = {}) => {
|
|
149
|
-
const ranges = ed.selectionRanges();
|
|
150
|
-
const block = ranges[0]?.block;
|
|
151
|
-
const anchor = block ? D.structureTarget(block, ed.root) : ed.root.lastElementChild;
|
|
152
|
-
return Boolean(T.insertTable(ed.root, { rows, cols, headerRow: withHeaderRow }, anchor));
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
tableAction: { run: (ed, action, counts) => ed.runTableAction(action, counts) },
|
|
156
|
-
convertBlock: { run: (ed, kind, el) => B.setBlockKind(ed.root, kind, el ? [el] : null) },
|
|
157
|
-
// 块自定义属性(data-battrs JSON;el 缺省=光标所在最外层结构块)。笔记域块属性弹层消费,.gbRtx 侧不产生。
|
|
158
|
-
// [坑] 显式给了 el 就必须写它:元素已失效(不在编辑面内)时返回 false,禁退回「光标所在块」——
|
|
159
|
-
// 否则「给这个块加属性」会静默写到另一个块上,用户看到的是属性跑到了别处
|
|
160
|
-
setBlockAttrs: { run: (ed, map, el = null) => {
|
|
161
|
-
const target = el ? B.liveTarget(ed.root, el) : B.currentStructureBlock(ed.root);
|
|
162
|
-
return target ? B.writeBlockAttrs(target, map) : false;
|
|
163
|
-
} },
|
|
164
|
-
focusBlock: {
|
|
165
|
-
run: (ed, el) => {
|
|
166
|
-
const target = D.firstTextBlockIn(el, ed.root) || (D.isTextBlock(el, ed.root) ? el : null);
|
|
167
|
-
if (!target) return false;
|
|
168
|
-
D.setCaret(target, 0);
|
|
169
|
-
return true;
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
function inlineCtx(ed) {
|
|
175
|
-
const ranges = ed.selectionRanges();
|
|
176
|
-
const marks = I.inlineState(ed.root, ranges).marks;
|
|
177
|
-
// [坑] 待定标记原先只由 selectionchange 装载:程序化落光标(点工具栏后复原选区、focusAt 定位)时它仍是 null,
|
|
178
|
-
// 折叠光标按加粗就落到 patchSelection 的空选区分支——表现又是「点了没反应」。这里按当前选区现推一次。
|
|
179
|
-
const collapsed = ranges.length > 0 && ranges.every((item) => item.end <= item.start);
|
|
180
|
-
return { root: ed.root, ranges, marks, pending: collapsed ? (ed.pending ||= { ...marks }) : null };
|
|
181
|
-
}
|
|
1
|
+
// [文件] web·editor-kernel·engine·commands —— 命令注册表(UI 只传命令名与参数;串多个内置命令的复合动作在宿主 actions)
|
|
2
|
+
import { normalizeHex } from 'guabiutils';
|
|
3
|
+
import * as D from './dom.js';
|
|
4
|
+
import * as I from './inline.js';
|
|
5
|
+
import * as B from './blocks.js';
|
|
6
|
+
import * as T from './tables.js';
|
|
7
|
+
import * as R from './revision.js';
|
|
8
|
+
import { ATTACH_ATTR, parseFragment } from './schema.js';
|
|
9
|
+
import { insertFragment } from './input.js';
|
|
10
|
+
|
|
11
|
+
/** 命令注册表:UI 只传命令名与参数,串多个内置命令的复合动作在 actions.js */
|
|
12
|
+
export const COMMANDS = {
|
|
13
|
+
// [坑] 撤销/重做自带历史栈,不能再被 exec 的 run() 包一层入栈(否则 undo 会弹到自己刚推进去的那条)
|
|
14
|
+
undo: { raw: true, run: (ed) => ed.undo(), can: (ed) => ed.undoStack.length > 0 },
|
|
15
|
+
redo: { raw: true, run: (ed) => ed.redo(), can: (ed) => ed.redoStack.length > 0 },
|
|
16
|
+
// 全选只动选区不动正文:raw 跳过历史,避免 Ctrl+A 也塞一条撤销记录
|
|
17
|
+
selectAll: {
|
|
18
|
+
raw: true,
|
|
19
|
+
run: (ed) => {
|
|
20
|
+
ed.focus();
|
|
21
|
+
ed.clearCellSelection?.();
|
|
22
|
+
ed.clearAtom?.();
|
|
23
|
+
const range = document.createRange();
|
|
24
|
+
range.selectNodeContents(ed.root);
|
|
25
|
+
const sel = window.getSelection();
|
|
26
|
+
if (!sel) return false;
|
|
27
|
+
sel.removeAllRanges();
|
|
28
|
+
sel.addRange(range);
|
|
29
|
+
return true;
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
toggleBold: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'bold') },
|
|
34
|
+
toggleItalic: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'italic') },
|
|
35
|
+
toggleUnderline: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'underline') },
|
|
36
|
+
toggleStrike: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'strike') },
|
|
37
|
+
toggleCode: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'code') },
|
|
38
|
+
toggleSuperscript: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'superscript') },
|
|
39
|
+
toggleSubscript: { run: (ed) => I.toggleTagMark(inlineCtx(ed), 'subscript') },
|
|
40
|
+
|
|
41
|
+
setColor: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'color', normalizeHex(value)) },
|
|
42
|
+
unsetColor: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'color', '') },
|
|
43
|
+
setBackgroundColor: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'backgroundColor', normalizeHex(value)) },
|
|
44
|
+
unsetBackgroundColor: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'backgroundColor', '') },
|
|
45
|
+
setFontSize: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'fontSize', value) },
|
|
46
|
+
unsetFontSize: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'fontSize', '') },
|
|
47
|
+
setFontFamily: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'fontFamily', value) },
|
|
48
|
+
unsetFontFamily: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'fontFamily', '') },
|
|
49
|
+
// 字体效果:空心(-webkit-text-stroke)/ 阴影(text-shadow),值形如 '0.2px currentColor' / '1px 1px var(...)'
|
|
50
|
+
setTextStroke: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'textStroke', value) },
|
|
51
|
+
unsetTextStroke: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'textStroke', '') },
|
|
52
|
+
setTextShadow: { run: (ed, value) => I.setStyleMark(inlineCtx(ed), 'textShadow', value) },
|
|
53
|
+
unsetTextShadow: { run: (ed) => I.setStyleMark(inlineCtx(ed), 'textShadow', '') },
|
|
54
|
+
// 组合色(前景 + 背景一体):一次落两个标记(拆两次会因块 DOM 重建丢选区,见 setStyleMarks 的 [坑])
|
|
55
|
+
setComboStyle: {
|
|
56
|
+
run: (ed, color, backgroundColor) =>
|
|
57
|
+
I.setStyleMarks(inlineCtx(ed), { color: normalizeHex(color), backgroundColor: normalizeHex(backgroundColor) }),
|
|
58
|
+
},
|
|
59
|
+
setLink: { run: (ed, href) => I.setLinkMark(inlineCtx(ed), href) },
|
|
60
|
+
unsetLink: { run: (ed) => I.setLinkMark(inlineCtx(ed), '') },
|
|
61
|
+
clearFormat: {
|
|
62
|
+
run: (ed) => {
|
|
63
|
+
const ctx = inlineCtx(ed);
|
|
64
|
+
const inline = I.clearInlineMarks(ctx);
|
|
65
|
+
const block = B.resetBlockStyle(ed.root, ctx.ranges);
|
|
66
|
+
return inline || block;
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
setParagraph: { run: (ed) => B.setBlockKind(ed.root, 'paragraph') },
|
|
71
|
+
setHeading: { run: (ed, level) => B.setBlockKind(ed.root, `heading${Number(level) || 1}`) },
|
|
72
|
+
toggleBlockquote: { run: (ed) => B.setBlockKind(ed.root, 'blockquote') },
|
|
73
|
+
toggleCodeBlock: { run: (ed) => B.setBlockKind(ed.root, 'codeBlock') },
|
|
74
|
+
toggleBulletList: { run: (ed) => B.setBlockKind(ed.root, 'bulletList') },
|
|
75
|
+
toggleOrderedList: { run: (ed) => B.setBlockKind(ed.root, 'orderedList') },
|
|
76
|
+
toggleTaskList: { run: (ed) => B.setBlockKind(ed.root, 'taskList') },
|
|
77
|
+
setHorizontalRule: { run: (ed) => B.insertDivider(ed.root) },
|
|
78
|
+
insertPageBreak: { run: (ed) => B.insertPageBreak(ed.root) },
|
|
79
|
+
insertCallout: { run: (ed, variant) => B.insertCallout(ed.root, variant) },
|
|
80
|
+
insertSuperBlock: { run: (ed, cols) => B.insertSuperBlock(ed.root, cols) },
|
|
81
|
+
// 超级块列增删(el 可为超级块或其内的列;笔记域块菜单消费)
|
|
82
|
+
addColumn: { run: (ed, el) => B.addColumn(ed.root, el) },
|
|
83
|
+
removeColumn: { run: (ed, el) => B.removeColumn(ed.root, el) },
|
|
84
|
+
// 拖块并排:把拖拽块与目标块合成 2 列超级块(块标拖拽到目标左/右边缘放下)
|
|
85
|
+
wrapInSuper: { run: (ed, dragged, target, side) => B.wrapInSuper(ed.root, dragged, target, side) },
|
|
86
|
+
insertImage: { run: (ed, spec) => B.insertImageInline(ed.root, spec) },
|
|
87
|
+
// 笔记资产图片(<img data-gbBlk-asset> + 直链 src;与 .gbRtx 的 insertImage 各归各)
|
|
88
|
+
insertAssetImage: { run: (ed, spec) => B.insertAssetImage(ed.root, spec) },
|
|
89
|
+
insertText: { run: (ed, text) => B.insertTextAtSelection(ed.root, text) },
|
|
90
|
+
// 受控 HTML 片段插入(宿主生成的复杂块,如 docx 目录块)
|
|
91
|
+
// [约束] 只允许应用代码生成的受控 HTML:不走粘贴清洗(它面向外来内容,会剥 class 等编解码标记)
|
|
92
|
+
insertHtml: {
|
|
93
|
+
run: (ed, html) => {
|
|
94
|
+
const frag = parseFragment(String(html || ''));
|
|
95
|
+
if (!frag.childNodes.length) return false;
|
|
96
|
+
insertFragment(ed, frag);
|
|
97
|
+
return true;
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
// 批注锚点(span.doc-comment):选区打键 / 按宿主数据删除某键的全部锚点
|
|
102
|
+
setComment: { run: (ed, key) => I.setCommentMark(inlineCtx(ed), key) },
|
|
103
|
+
removeComment: { run: (ed, key) => I.removeCommentRange(ed.root, key) > 0 },
|
|
104
|
+
|
|
105
|
+
// 脚注/尾注锚点(sup.doc-footnote/endnote[data-fn];Word 应用消费)
|
|
106
|
+
insertNote: { run: (ed, spec) => I.insertNoteAnchor(ed.root, spec) },
|
|
107
|
+
removeNote: { run: (ed, id) => I.removeNoteAnchor(ed.root, id) },
|
|
108
|
+
|
|
109
|
+
// 笔记行内锚(span.doc-attach 附件引用 / span.doc-ref 块·文档引用;笔记域专用,.gbRtx 侧不产生)
|
|
110
|
+
insertAttach: { run: (ed, spec) => I.insertAnchorAtCursor(ed.root, 'attach', spec) },
|
|
111
|
+
removeAttach: { run: (ed, id) => I.removeAnchorsByAttr(ed.root, ATTACH_ATTR, id) },
|
|
112
|
+
insertRef: { run: (ed, spec) => I.insertAnchorAtCursor(ed.root, 'ref', spec) },
|
|
113
|
+
|
|
114
|
+
// 笔记引用节点转换(宿主右键菜单入口):行内引用 ↔ 嵌入块 / 锚文本类型 / 删除
|
|
115
|
+
convertRefToEmbed: { run: (ed, el, html) => I.convertRefToEmbed(ed.root, el, html) },
|
|
116
|
+
convertEmbedToRef: { run: (ed, el) => I.convertEmbedToRef(el) },
|
|
117
|
+
setRefSub: { run: (ed, el, sub) => I.setRefSub(el, sub) },
|
|
118
|
+
removeAnchor: { run: (ed, el) => I.removeAnchorNode(el) },
|
|
119
|
+
|
|
120
|
+
// 修订接受/拒绝(Word 应用;普通富文本不暴露入口)
|
|
121
|
+
resolveRevisions: { run: (ed, accept) => R.resolveRevisions(ed.root, accept) > 0 },
|
|
122
|
+
resolveRevisionAt: { run: (ed, el, accept) => R.resolveRevisionAt(el, accept) },
|
|
123
|
+
|
|
124
|
+
increaseBlockIndent: { run: (ed) => B.changeBlockIndent(ed.root, 1), can: (ed) => ed.state().canIndent },
|
|
125
|
+
decreaseBlockIndent: { run: (ed) => B.changeBlockIndent(ed.root, -1), can: (ed) => ed.state().canOutdent },
|
|
126
|
+
toggleFirstLineIndent: { run: (ed) => B.toggleFirstLineIndent(ed.root) },
|
|
127
|
+
setBlockLineHeight: { run: (ed, value) => B.setLineHeight(ed.root, value) },
|
|
128
|
+
setBlockAlign: { run: (ed, value) => B.setBlockAlign(ed.root, value) },
|
|
129
|
+
|
|
130
|
+
duplicateBlock: { run: (ed, el) => B.duplicateBlock(ed.root, el) },
|
|
131
|
+
deleteBlock: { run: (ed, el) => B.deleteBlock(ed.root, el) },
|
|
132
|
+
insertBlockNear: { run: (ed, el, position) => B.insertBlockNear(ed.root, position, el) },
|
|
133
|
+
moveBlockUp: { run: (ed, el) => B.moveBlock(ed.root, el, -1) },
|
|
134
|
+
moveBlockDown: { run: (ed, el) => B.moveBlock(ed.root, el, 1) },
|
|
135
|
+
moveBlockTo: { run: (ed, el, ref, before) => B.moveBlockTo(el, ref, before) },
|
|
136
|
+
moveTableTo: { run: (ed, table, ref, before) => B.moveTableTo(ed.root, table, ref, before) },
|
|
137
|
+
deleteRange: {
|
|
138
|
+
run: (ed, { block, from, to }) => {
|
|
139
|
+
if (!block?.isConnected) return false;
|
|
140
|
+
const range = D.rangeInBlock(block, from, to);
|
|
141
|
+
range.deleteContents();
|
|
142
|
+
D.selectRange(ed.root, { block, offset: from }, { block, offset: from });
|
|
143
|
+
return true;
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
insertTable: {
|
|
148
|
+
run: (ed, { rows = 2, cols = 2, withHeaderRow = true } = {}) => {
|
|
149
|
+
const ranges = ed.selectionRanges();
|
|
150
|
+
const block = ranges[0]?.block;
|
|
151
|
+
const anchor = block ? D.structureTarget(block, ed.root) : ed.root.lastElementChild;
|
|
152
|
+
return Boolean(T.insertTable(ed.root, { rows, cols, headerRow: withHeaderRow }, anchor));
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
tableAction: { run: (ed, action, counts) => ed.runTableAction(action, counts) },
|
|
156
|
+
convertBlock: { run: (ed, kind, el) => B.setBlockKind(ed.root, kind, el ? [el] : null) },
|
|
157
|
+
// 块自定义属性(data-battrs JSON;el 缺省=光标所在最外层结构块)。笔记域块属性弹层消费,.gbRtx 侧不产生。
|
|
158
|
+
// [坑] 显式给了 el 就必须写它:元素已失效(不在编辑面内)时返回 false,禁退回「光标所在块」——
|
|
159
|
+
// 否则「给这个块加属性」会静默写到另一个块上,用户看到的是属性跑到了别处
|
|
160
|
+
setBlockAttrs: { run: (ed, map, el = null) => {
|
|
161
|
+
const target = el ? B.liveTarget(ed.root, el) : B.currentStructureBlock(ed.root);
|
|
162
|
+
return target ? B.writeBlockAttrs(target, map) : false;
|
|
163
|
+
} },
|
|
164
|
+
focusBlock: {
|
|
165
|
+
run: (ed, el) => {
|
|
166
|
+
const target = D.firstTextBlockIn(el, ed.root) || (D.isTextBlock(el, ed.root) ? el : null);
|
|
167
|
+
if (!target) return false;
|
|
168
|
+
D.setCaret(target, 0);
|
|
169
|
+
return true;
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
function inlineCtx(ed) {
|
|
175
|
+
const ranges = ed.selectionRanges();
|
|
176
|
+
const marks = I.inlineState(ed.root, ranges).marks;
|
|
177
|
+
// [坑] 待定标记原先只由 selectionchange 装载:程序化落光标(点工具栏后复原选区、focusAt 定位)时它仍是 null,
|
|
178
|
+
// 折叠光标按加粗就落到 patchSelection 的空选区分支——表现又是「点了没反应」。这里按当前选区现推一次。
|
|
179
|
+
const collapsed = ranges.length > 0 && ranges.every((item) => item.end <= item.start);
|
|
180
|
+
return { root: ed.root, ranges, marks, pending: collapsed ? (ed.pending ||= { ...marks }) : null };
|
|
181
|
+
}
|