@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.
- package/LICENSE +21 -21
- package/README.md +215 -215
- package/index.html +31 -30
- package/package.json +49 -48
- package/serve.mjs +27 -23
- package/src/app/word/file.js +191 -191
- package/src/app/word/menus.js +201 -201
- package/src/app/word/view.js +159 -159
- package/src/app/word-app.js +487 -487
- package/src/kernel/docx/catalog.js +41 -41
- package/src/kernel/docx/menus.js +348 -348
- package/src/kernel/docx/wordShortcuts.js +37 -37
- package/src/kernel/editor/engine/editor.js +213 -213
- package/src/kernel/editor/engine/search.js +113 -113
- package/src/kernel/editor/pasteClean.js +293 -293
- package/src/kernel/notify.js +54 -54
- package/src/kernel/util/clipboard.js +89 -89
- package/src/kernel/util/safeValue.js +25 -25
- package/src/surface/editor-surface.js +5 -2
- package/src/ui/context-menu.js +4 -2
- package/src/ui/dialogs.js +249 -249
- package/src/ui/icons.js +245 -137
- package/src/ui/popup.js +79 -79
- package/styles/app.css +970 -970
- package/styles/word-panel.css +410 -410
package/src/app/word/menus.js
CHANGED
|
@@ -1,201 +1,201 @@
|
|
|
1
|
-
// [文件] gbdocx·word·menus —— 右键菜单与快捷键上下文
|
|
2
|
-
|
|
3
|
-
// [设计] 方法以独立函数导出,由 word-app.js 末尾 Object.assign 装配到 WordApp.prototype:
|
|
4
|
-
// 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
|
|
5
|
-
|
|
6
|
-
import { textMenuItems, tableMenuItems, revisionMenuItems } from '../../kernel/docx/menus.js';
|
|
7
|
-
import { DOC_CLASS } from '../../kernel/editor/engine/schema.js';
|
|
8
|
-
import { tableMenuModel } from '../../kernel/editor/engine/tableMenu.js';
|
|
9
|
-
import { notify } from '../../kernel/notify.js';
|
|
10
|
-
import { openMenu } from '../../ui/context-menu.js';
|
|
11
|
-
|
|
12
|
-
import { savePrefs } from './shared.js';
|
|
13
|
-
function onContextMenu(e) {
|
|
14
|
-
if (!e.target.closest?.('.rich-text-content')) return;
|
|
15
|
-
e.preventDefault();
|
|
16
|
-
const ed = this.editor;
|
|
17
|
-
const cell = ed.cellAt(e.clientX, e.clientY);
|
|
18
|
-
const rev = e.target.closest?.(`.${DOC_CLASS.INS}, .${DOC_CLASS.DEL}`);
|
|
19
|
-
const items = rev
|
|
20
|
-
? revisionMenuItems(rev, (el, accept) => { if (this.run('resolveRevisionAt', el, accept)) this.onDocUpdate(); })
|
|
21
|
-
: cell
|
|
22
|
-
? tableMenuItems({ inTable: true }, {
|
|
23
|
-
model: () => tableMenuModel(ed.tableContext() ?? null),
|
|
24
|
-
state: () => ed.state() ?? null,
|
|
25
|
-
can: (key) => ed.canTableAction(key) ?? false,
|
|
26
|
-
active: (key) => ed.isTableActionActive(key) ?? false,
|
|
27
|
-
exec: (command, ...args) => this.run(command, ...args),
|
|
28
|
-
action: (key, payload, op) => this.tableAction(key, payload, op),
|
|
29
|
-
})
|
|
30
|
-
: textMenuItems(this.menuCtx());
|
|
31
|
-
openMenu({ anchor: { left: e.clientX, top: e.clientY, right: e.clientX, bottom: e.clientY }, items, placement: 'bottom-start' });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function tableAction(action, payload, op = 'table') {
|
|
35
|
-
if (op === 'clip') return this.editor?.runTableOp('clip', action, payload);
|
|
36
|
-
return this.run('tableAction', action, payload);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function menuCtx() {
|
|
40
|
-
const app = this;
|
|
41
|
-
const io = this.io || {};
|
|
42
|
-
// [坑] state 必须是活值:菜单结构只在启动时构建一次,普通快照会让勾选态/可用性永远停在首帧。
|
|
43
|
-
// 这里用 getter 按打开那一刻的编辑器状态现读(readonly 属性在菜单求值时才访问)
|
|
44
|
-
const ctx = {
|
|
45
|
-
state: {
|
|
46
|
-
get autosave() {
|
|
47
|
-
return app.embed && typeof io.autosave === 'function' ? io.autosave() : !!app.prefs.autosave;
|
|
48
|
-
},
|
|
49
|
-
get suggesting() { return app.editMode === 'suggest'; },
|
|
50
|
-
get blockType() { return app.editorState?.blockType; },
|
|
51
|
-
get align() { return app.editorState?.textAlign; },
|
|
52
|
-
get lineHeight() { return app.editorState?.lineHeight; },
|
|
53
|
-
get firstLineIndent() { return app.editorState?.firstLineIndent; },
|
|
54
|
-
get bold() { return app.editorState?.bold; },
|
|
55
|
-
get italic() { return app.editorState?.italic; },
|
|
56
|
-
get underline() { return app.editorState?.underline; },
|
|
57
|
-
get strike() { return app.editorState?.strike; },
|
|
58
|
-
get superscript() { return app.editorState?.superscript; },
|
|
59
|
-
get subscript() { return app.editorState?.subscript; },
|
|
60
|
-
get fontSize() { return app.editorState?.fontSize; },
|
|
61
|
-
get fontFamily() { return app.editorState?.fontFamily; },
|
|
62
|
-
get color() { return app.editorState?.color; },
|
|
63
|
-
get backgroundColor() { return app.editorState?.backgroundColor; },
|
|
64
|
-
get bulletList() { return app.editorState?.bulletList; },
|
|
65
|
-
get orderedList() { return app.editorState?.orderedList; },
|
|
66
|
-
get taskList() { return app.editorState?.taskList; },
|
|
67
|
-
get inTable() { return app.editorState?.inTable; },
|
|
68
|
-
get hasSelection() { return app.editorState?.hasSelection; },
|
|
69
|
-
get columns() { return app.state.page.columns || 1; },
|
|
70
|
-
get pageNumbers() { return app.state.pageNumbers; },
|
|
71
|
-
get hfMode() { return app.state.hfMode; },
|
|
72
|
-
get catalog() { return app.flags.catalog; },
|
|
73
|
-
get commentsPanel() { return app.flags.commentsPanel; },
|
|
74
|
-
},
|
|
75
|
-
file: {
|
|
76
|
-
// 嵌入模式:文件动作全部交给宿主 io(打开新页签/写回存储/另存为弹窗),缺省才走包内自带的本地文件实现
|
|
77
|
-
newDoc: io.newDoc || (() => this.newDoc()),
|
|
78
|
-
open: io.open || (() => this.openFile()),
|
|
79
|
-
recentList: () => [],
|
|
80
|
-
openRecent: () => {},
|
|
81
|
-
save: io.save || (() => this.save()),
|
|
82
|
-
saveAs: io.saveAs || (() => this.saveAs()),
|
|
83
|
-
setAutosave: io.setAutosave || ((on) => { this.prefs.autosave = on; savePrefs(this.prefs); this.autosaveEl.checked = on; }),
|
|
84
|
-
pageSetup: () => this.openPageSetupDialog(),
|
|
85
|
-
importDoc: io.importDoc || (() => this.importInput.click()),
|
|
86
|
-
exportCopy: io.exportCopy || (() => this.exportDocx()),
|
|
87
|
-
exportMarkdown: io.exportMarkdown || (() => this.exportMarkdown()),
|
|
88
|
-
print: io.print || (() => this.print()),
|
|
89
|
-
},
|
|
90
|
-
edit: {
|
|
91
|
-
undo: () => this.run('undo'),
|
|
92
|
-
redo: () => this.run('redo'),
|
|
93
|
-
canUndo: () => Boolean(this.editorState.canUndo),
|
|
94
|
-
canRedo: () => Boolean(this.editorState.canRedo),
|
|
95
|
-
cut: () => { this.editor.focus(); document.execCommand('cut'); },
|
|
96
|
-
copy: () => { this.editor.focus(); document.execCommand('copy'); },
|
|
97
|
-
paste: () => notify.info('请用 Ctrl+V 粘贴(浏览器不允许脚本触发粘贴)'),
|
|
98
|
-
find: (replace) => this.findBar.open(!!replace),
|
|
99
|
-
selectAll: () => this.editor?.exec('selectAll'),
|
|
100
|
-
setSuggesting: (on) => {
|
|
101
|
-
this.setEditMode(on ? 'suggest' : 'edit');
|
|
102
|
-
notify.info(on ? '已开启「建议修改」:输入会成为插入建议,删除会成为删除建议' : '已关闭「建议修改」');
|
|
103
|
-
},
|
|
104
|
-
suggestionCount: () => this.suggestionCount,
|
|
105
|
-
acceptAll: () => {
|
|
106
|
-
const n = this.suggestionCount;
|
|
107
|
-
if (n && this.run('resolveRevisions', true)) notify.success(`已接受 ${n} 条建议`);
|
|
108
|
-
this.refreshStats();
|
|
109
|
-
},
|
|
110
|
-
rejectAll: () => {
|
|
111
|
-
const n = this.suggestionCount;
|
|
112
|
-
if (n && this.run('resolveRevisions', false)) notify.success(`已拒绝 ${n} 条建议`);
|
|
113
|
-
this.refreshStats();
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
insert: {
|
|
117
|
-
image: () => this.pickImage(),
|
|
118
|
-
table: (e) => this.openTableSpec(e),
|
|
119
|
-
link: () => this.insertLink(),
|
|
120
|
-
comment: () => this.insertComment(),
|
|
121
|
-
footnote: () => this.insertFootnote(),
|
|
122
|
-
toc: () => this.insertToc(),
|
|
123
|
-
refreshToc: () => this.refreshToc(),
|
|
124
|
-
setPageNumber: (align) => {
|
|
125
|
-
this.state.pageNumbers = { ...this.state.pageNumbers, enabled: true, align };
|
|
126
|
-
this.onDocUpdate();
|
|
127
|
-
},
|
|
128
|
-
pageNumberSetup: () => this.openPageSetupDialog(),
|
|
129
|
-
watermark: () => this.openPageSetupDialog(),
|
|
130
|
-
pageBreak: () => this.run('insertPageBreak'),
|
|
131
|
-
hr: () => this.run('setHorizontalRule'),
|
|
132
|
-
specialChars: () => { this.charsPop.hidden = !this.charsPop.hidden; },
|
|
133
|
-
},
|
|
134
|
-
table: {
|
|
135
|
-
action: (key, payload, op) => this.tableAction(key, payload, op),
|
|
136
|
-
model: () => tableMenuModel(this.editor?.tableContext() ?? null),
|
|
137
|
-
state: () => this.editor?.state() ?? null,
|
|
138
|
-
can: (key) => this.editor?.canTableAction(key) ?? false,
|
|
139
|
-
active: (key) => this.editor?.isTableActionActive(key) ?? false,
|
|
140
|
-
exec: (command, ...args) => this.run(command, ...args),
|
|
141
|
-
},
|
|
142
|
-
format: {
|
|
143
|
-
setLayout: (cols) => { this.state.page = { ...this.state.page, columns: cols }; this.onDocUpdate(); this.paginate(); },
|
|
144
|
-
paragraphStyle: (kind) => this.run('convertBlock', kind),
|
|
145
|
-
align: (v) => this.run('setBlockAlign', v),
|
|
146
|
-
setLineHeight: (v) => this.run('setBlockLineHeight', v),
|
|
147
|
-
firstLine: () => this.run('toggleFirstLineIndent'),
|
|
148
|
-
bold: () => this.run('toggleBold'),
|
|
149
|
-
italic: () => this.run('toggleItalic'),
|
|
150
|
-
underline: () => this.run('toggleUnderline'),
|
|
151
|
-
strike: () => this.run('toggleStrike'),
|
|
152
|
-
superscript: () => this.run('toggleSuperscript'),
|
|
153
|
-
subscript: () => this.run('toggleSubscript'),
|
|
154
|
-
setFontFamily: (v) => this.run('setFontFamily', v),
|
|
155
|
-
setFontSize: (v) => this.run('setFontSize', v),
|
|
156
|
-
setColor: (v) => this.run('setColor', v),
|
|
157
|
-
unsetColor: () => this.run('unsetColor'),
|
|
158
|
-
setHighlight: (v) => this.run('setBackgroundColor', v),
|
|
159
|
-
unsetHighlight: () => this.run('unsetBackgroundColor'),
|
|
160
|
-
indent: (command) => this.run(command),
|
|
161
|
-
setHfMode: (mode) => { this.state.hfMode = mode; this.onDocUpdate(); },
|
|
162
|
-
list: (command) => this.run(command),
|
|
163
|
-
clearFormat: () => this.run('clearFormat'),
|
|
164
|
-
},
|
|
165
|
-
view: {
|
|
166
|
-
zoomIn: () => this.setZoom(this.zoom + 10),
|
|
167
|
-
zoomOut: () => this.setZoom(this.zoom - 10),
|
|
168
|
-
zoomReset: () => this.setZoom(100),
|
|
169
|
-
setView: (key, on) => this.setView(key, on),
|
|
170
|
-
},
|
|
171
|
-
};
|
|
172
|
-
// [设计] 只读档在这里统一短路写动作:菜单栏、右键菜单、快捷键共用这一份 ctx,
|
|
173
|
-
// 不必逐条给菜单项挂 disabled;查询函数(model/state/can…)必须留着,否则菜单结构会读不到数据。
|
|
174
|
-
if (app.readOnly) {
|
|
175
|
-
const allow = {
|
|
176
|
-
file: ['recentList', 'openRecent', 'exportCopy', 'exportMarkdown', 'print'],
|
|
177
|
-
edit: ['canUndo', 'canRedo', 'copy', 'find', 'selectAll', 'suggestionCount'],
|
|
178
|
-
insert: [],
|
|
179
|
-
table: ['model', 'state', 'can', 'active'],
|
|
180
|
-
format: [],
|
|
181
|
-
};
|
|
182
|
-
for (const [group, keys] of Object.entries(allow)) {
|
|
183
|
-
for (const [key, fn] of Object.entries(ctx[group])) {
|
|
184
|
-
if (typeof fn === 'function' && !keys.includes(key)) ctx[group][key] = () => false;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return ctx;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function shortcutCtx() {
|
|
192
|
-
const file = this.menuCtx().file;
|
|
193
|
-
return {
|
|
194
|
-
file,
|
|
195
|
-
insert: { pageBreak: () => this.run('insertPageBreak'), link: () => this.insertLink(), comment: () => this.insertComment(), list: (ordered) => this.run(ordered ? 'toggleOrderedList' : 'toggleBulletList') },
|
|
196
|
-
edit: { find: () => this.findBar.open(false), findReplace: () => this.findBar.open(true) },
|
|
197
|
-
view: { zoomIn: () => this.setZoom(this.zoom + 10), zoomOut: () => this.setZoom(this.zoom - 10), zoomReset: () => this.setZoom(100) },
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export const menusMethods = { onContextMenu, tableAction, menuCtx, shortcutCtx };
|
|
1
|
+
// [文件] gbdocx·word·menus —— 右键菜单与快捷键上下文
|
|
2
|
+
|
|
3
|
+
// [设计] 方法以独立函数导出,由 word-app.js 末尾 Object.assign 装配到 WordApp.prototype:
|
|
4
|
+
// 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
|
|
5
|
+
|
|
6
|
+
import { textMenuItems, tableMenuItems, revisionMenuItems } from '../../kernel/docx/menus.js';
|
|
7
|
+
import { DOC_CLASS } from '../../kernel/editor/engine/schema.js';
|
|
8
|
+
import { tableMenuModel } from '../../kernel/editor/engine/tableMenu.js';
|
|
9
|
+
import { notify } from '../../kernel/notify.js';
|
|
10
|
+
import { openMenu } from '../../ui/context-menu.js';
|
|
11
|
+
|
|
12
|
+
import { savePrefs } from './shared.js';
|
|
13
|
+
function onContextMenu(e) {
|
|
14
|
+
if (!e.target.closest?.('.rich-text-content')) return;
|
|
15
|
+
e.preventDefault();
|
|
16
|
+
const ed = this.editor;
|
|
17
|
+
const cell = ed.cellAt(e.clientX, e.clientY);
|
|
18
|
+
const rev = e.target.closest?.(`.${DOC_CLASS.INS}, .${DOC_CLASS.DEL}`);
|
|
19
|
+
const items = rev
|
|
20
|
+
? revisionMenuItems(rev, (el, accept) => { if (this.run('resolveRevisionAt', el, accept)) this.onDocUpdate(); })
|
|
21
|
+
: cell
|
|
22
|
+
? tableMenuItems({ inTable: true }, {
|
|
23
|
+
model: () => tableMenuModel(ed.tableContext() ?? null),
|
|
24
|
+
state: () => ed.state() ?? null,
|
|
25
|
+
can: (key) => ed.canTableAction(key) ?? false,
|
|
26
|
+
active: (key) => ed.isTableActionActive(key) ?? false,
|
|
27
|
+
exec: (command, ...args) => this.run(command, ...args),
|
|
28
|
+
action: (key, payload, op) => this.tableAction(key, payload, op),
|
|
29
|
+
})
|
|
30
|
+
: textMenuItems(this.menuCtx());
|
|
31
|
+
openMenu({ anchor: { left: e.clientX, top: e.clientY, right: e.clientX, bottom: e.clientY }, items, placement: 'bottom-start' });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function tableAction(action, payload, op = 'table') {
|
|
35
|
+
if (op === 'clip') return this.editor?.runTableOp('clip', action, payload);
|
|
36
|
+
return this.run('tableAction', action, payload);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function menuCtx() {
|
|
40
|
+
const app = this;
|
|
41
|
+
const io = this.io || {};
|
|
42
|
+
// [坑] state 必须是活值:菜单结构只在启动时构建一次,普通快照会让勾选态/可用性永远停在首帧。
|
|
43
|
+
// 这里用 getter 按打开那一刻的编辑器状态现读(readonly 属性在菜单求值时才访问)
|
|
44
|
+
const ctx = {
|
|
45
|
+
state: {
|
|
46
|
+
get autosave() {
|
|
47
|
+
return app.embed && typeof io.autosave === 'function' ? io.autosave() : !!app.prefs.autosave;
|
|
48
|
+
},
|
|
49
|
+
get suggesting() { return app.editMode === 'suggest'; },
|
|
50
|
+
get blockType() { return app.editorState?.blockType; },
|
|
51
|
+
get align() { return app.editorState?.textAlign; },
|
|
52
|
+
get lineHeight() { return app.editorState?.lineHeight; },
|
|
53
|
+
get firstLineIndent() { return app.editorState?.firstLineIndent; },
|
|
54
|
+
get bold() { return app.editorState?.bold; },
|
|
55
|
+
get italic() { return app.editorState?.italic; },
|
|
56
|
+
get underline() { return app.editorState?.underline; },
|
|
57
|
+
get strike() { return app.editorState?.strike; },
|
|
58
|
+
get superscript() { return app.editorState?.superscript; },
|
|
59
|
+
get subscript() { return app.editorState?.subscript; },
|
|
60
|
+
get fontSize() { return app.editorState?.fontSize; },
|
|
61
|
+
get fontFamily() { return app.editorState?.fontFamily; },
|
|
62
|
+
get color() { return app.editorState?.color; },
|
|
63
|
+
get backgroundColor() { return app.editorState?.backgroundColor; },
|
|
64
|
+
get bulletList() { return app.editorState?.bulletList; },
|
|
65
|
+
get orderedList() { return app.editorState?.orderedList; },
|
|
66
|
+
get taskList() { return app.editorState?.taskList; },
|
|
67
|
+
get inTable() { return app.editorState?.inTable; },
|
|
68
|
+
get hasSelection() { return app.editorState?.hasSelection; },
|
|
69
|
+
get columns() { return app.state.page.columns || 1; },
|
|
70
|
+
get pageNumbers() { return app.state.pageNumbers; },
|
|
71
|
+
get hfMode() { return app.state.hfMode; },
|
|
72
|
+
get catalog() { return app.flags.catalog; },
|
|
73
|
+
get commentsPanel() { return app.flags.commentsPanel; },
|
|
74
|
+
},
|
|
75
|
+
file: {
|
|
76
|
+
// 嵌入模式:文件动作全部交给宿主 io(打开新页签/写回存储/另存为弹窗),缺省才走包内自带的本地文件实现
|
|
77
|
+
newDoc: io.newDoc || (() => this.newDoc()),
|
|
78
|
+
open: io.open || (() => this.openFile()),
|
|
79
|
+
recentList: () => [],
|
|
80
|
+
openRecent: () => {},
|
|
81
|
+
save: io.save || (() => this.save()),
|
|
82
|
+
saveAs: io.saveAs || (() => this.saveAs()),
|
|
83
|
+
setAutosave: io.setAutosave || ((on) => { this.prefs.autosave = on; savePrefs(this.prefs); this.autosaveEl.checked = on; }),
|
|
84
|
+
pageSetup: () => this.openPageSetupDialog(),
|
|
85
|
+
importDoc: io.importDoc || (() => this.importInput.click()),
|
|
86
|
+
exportCopy: io.exportCopy || (() => this.exportDocx()),
|
|
87
|
+
exportMarkdown: io.exportMarkdown || (() => this.exportMarkdown()),
|
|
88
|
+
print: io.print || (() => this.print()),
|
|
89
|
+
},
|
|
90
|
+
edit: {
|
|
91
|
+
undo: () => this.run('undo'),
|
|
92
|
+
redo: () => this.run('redo'),
|
|
93
|
+
canUndo: () => Boolean(this.editorState.canUndo),
|
|
94
|
+
canRedo: () => Boolean(this.editorState.canRedo),
|
|
95
|
+
cut: () => { this.editor.focus(); document.execCommand('cut'); },
|
|
96
|
+
copy: () => { this.editor.focus(); document.execCommand('copy'); },
|
|
97
|
+
paste: () => notify.info('请用 Ctrl+V 粘贴(浏览器不允许脚本触发粘贴)'),
|
|
98
|
+
find: (replace) => this.findBar.open(!!replace),
|
|
99
|
+
selectAll: () => this.editor?.exec('selectAll'),
|
|
100
|
+
setSuggesting: (on) => {
|
|
101
|
+
this.setEditMode(on ? 'suggest' : 'edit');
|
|
102
|
+
notify.info(on ? '已开启「建议修改」:输入会成为插入建议,删除会成为删除建议' : '已关闭「建议修改」');
|
|
103
|
+
},
|
|
104
|
+
suggestionCount: () => this.suggestionCount,
|
|
105
|
+
acceptAll: () => {
|
|
106
|
+
const n = this.suggestionCount;
|
|
107
|
+
if (n && this.run('resolveRevisions', true)) notify.success(`已接受 ${n} 条建议`);
|
|
108
|
+
this.refreshStats();
|
|
109
|
+
},
|
|
110
|
+
rejectAll: () => {
|
|
111
|
+
const n = this.suggestionCount;
|
|
112
|
+
if (n && this.run('resolveRevisions', false)) notify.success(`已拒绝 ${n} 条建议`);
|
|
113
|
+
this.refreshStats();
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
insert: {
|
|
117
|
+
image: () => this.pickImage(),
|
|
118
|
+
table: (e) => this.openTableSpec(e),
|
|
119
|
+
link: () => this.insertLink(),
|
|
120
|
+
comment: () => this.insertComment(),
|
|
121
|
+
footnote: () => this.insertFootnote(),
|
|
122
|
+
toc: () => this.insertToc(),
|
|
123
|
+
refreshToc: () => this.refreshToc(),
|
|
124
|
+
setPageNumber: (align) => {
|
|
125
|
+
this.state.pageNumbers = { ...this.state.pageNumbers, enabled: true, align };
|
|
126
|
+
this.onDocUpdate();
|
|
127
|
+
},
|
|
128
|
+
pageNumberSetup: () => this.openPageSetupDialog(),
|
|
129
|
+
watermark: () => this.openPageSetupDialog(),
|
|
130
|
+
pageBreak: () => this.run('insertPageBreak'),
|
|
131
|
+
hr: () => this.run('setHorizontalRule'),
|
|
132
|
+
specialChars: () => { this.charsPop.hidden = !this.charsPop.hidden; },
|
|
133
|
+
},
|
|
134
|
+
table: {
|
|
135
|
+
action: (key, payload, op) => this.tableAction(key, payload, op),
|
|
136
|
+
model: () => tableMenuModel(this.editor?.tableContext() ?? null),
|
|
137
|
+
state: () => this.editor?.state() ?? null,
|
|
138
|
+
can: (key) => this.editor?.canTableAction(key) ?? false,
|
|
139
|
+
active: (key) => this.editor?.isTableActionActive(key) ?? false,
|
|
140
|
+
exec: (command, ...args) => this.run(command, ...args),
|
|
141
|
+
},
|
|
142
|
+
format: {
|
|
143
|
+
setLayout: (cols) => { this.state.page = { ...this.state.page, columns: cols }; this.onDocUpdate(); this.paginate(); },
|
|
144
|
+
paragraphStyle: (kind) => this.run('convertBlock', kind),
|
|
145
|
+
align: (v) => this.run('setBlockAlign', v),
|
|
146
|
+
setLineHeight: (v) => this.run('setBlockLineHeight', v),
|
|
147
|
+
firstLine: () => this.run('toggleFirstLineIndent'),
|
|
148
|
+
bold: () => this.run('toggleBold'),
|
|
149
|
+
italic: () => this.run('toggleItalic'),
|
|
150
|
+
underline: () => this.run('toggleUnderline'),
|
|
151
|
+
strike: () => this.run('toggleStrike'),
|
|
152
|
+
superscript: () => this.run('toggleSuperscript'),
|
|
153
|
+
subscript: () => this.run('toggleSubscript'),
|
|
154
|
+
setFontFamily: (v) => this.run('setFontFamily', v),
|
|
155
|
+
setFontSize: (v) => this.run('setFontSize', v),
|
|
156
|
+
setColor: (v) => this.run('setColor', v),
|
|
157
|
+
unsetColor: () => this.run('unsetColor'),
|
|
158
|
+
setHighlight: (v) => this.run('setBackgroundColor', v),
|
|
159
|
+
unsetHighlight: () => this.run('unsetBackgroundColor'),
|
|
160
|
+
indent: (command) => this.run(command),
|
|
161
|
+
setHfMode: (mode) => { this.state.hfMode = mode; this.onDocUpdate(); },
|
|
162
|
+
list: (command) => this.run(command),
|
|
163
|
+
clearFormat: () => this.run('clearFormat'),
|
|
164
|
+
},
|
|
165
|
+
view: {
|
|
166
|
+
zoomIn: () => this.setZoom(this.zoom + 10),
|
|
167
|
+
zoomOut: () => this.setZoom(this.zoom - 10),
|
|
168
|
+
zoomReset: () => this.setZoom(100),
|
|
169
|
+
setView: (key, on) => this.setView(key, on),
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
// [设计] 只读档在这里统一短路写动作:菜单栏、右键菜单、快捷键共用这一份 ctx,
|
|
173
|
+
// 不必逐条给菜单项挂 disabled;查询函数(model/state/can…)必须留着,否则菜单结构会读不到数据。
|
|
174
|
+
if (app.readOnly) {
|
|
175
|
+
const allow = {
|
|
176
|
+
file: ['recentList', 'openRecent', 'exportCopy', 'exportMarkdown', 'print'],
|
|
177
|
+
edit: ['canUndo', 'canRedo', 'copy', 'find', 'selectAll', 'suggestionCount'],
|
|
178
|
+
insert: [],
|
|
179
|
+
table: ['model', 'state', 'can', 'active'],
|
|
180
|
+
format: [],
|
|
181
|
+
};
|
|
182
|
+
for (const [group, keys] of Object.entries(allow)) {
|
|
183
|
+
for (const [key, fn] of Object.entries(ctx[group])) {
|
|
184
|
+
if (typeof fn === 'function' && !keys.includes(key)) ctx[group][key] = () => false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return ctx;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function shortcutCtx() {
|
|
192
|
+
const file = this.menuCtx().file;
|
|
193
|
+
return {
|
|
194
|
+
file,
|
|
195
|
+
insert: { pageBreak: () => this.run('insertPageBreak'), link: () => this.insertLink(), comment: () => this.insertComment(), list: (ordered) => this.run(ordered ? 'toggleOrderedList' : 'toggleBulletList') },
|
|
196
|
+
edit: { find: () => this.findBar.open(false), findReplace: () => this.findBar.open(true) },
|
|
197
|
+
view: { zoomIn: () => this.setZoom(this.zoom + 10), zoomOut: () => this.setZoom(this.zoom - 10), zoomReset: () => this.setZoom(100) },
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export const menusMethods = { onContextMenu, tableAction, menuCtx, shortcutCtx };
|