@a200888213/gbdocx 0.0.0-stage → 0.3.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.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +205 -2
  3. package/index.html +24 -0
  4. package/package.json +47 -6
  5. package/serve.mjs +20 -0
  6. package/src/app/file-io.js +122 -0
  7. package/src/app/main.js +9 -0
  8. package/src/app/word/catalog.js +52 -0
  9. package/src/app/word/comments.js +112 -0
  10. package/src/app/word/doc.js +113 -0
  11. package/src/app/word/edit.js +72 -0
  12. package/src/app/word/file.js +162 -0
  13. package/src/app/word/hf.js +76 -0
  14. package/src/app/word/layout.js +152 -0
  15. package/src/app/word/menus.js +175 -0
  16. package/src/app/word/notes.js +110 -0
  17. package/src/app/word/shared.js +22 -0
  18. package/src/app/word/view.js +88 -0
  19. package/src/app/word-app.js +440 -0
  20. package/src/app/word-sheets.js +101 -0
  21. package/src/kernel/docx/catalog.js +41 -0
  22. package/src/kernel/docx/codec/blocks.js +123 -0
  23. package/src/kernel/docx/codec/carry.js +129 -0
  24. package/src/kernel/docx/codec/comments.js +25 -0
  25. package/src/kernel/docx/codec/docx.js +198 -0
  26. package/src/kernel/docx/codec/docxStyles.js +177 -0
  27. package/src/kernel/docx/codec/fonts.js +195 -0
  28. package/src/kernel/docx/codec/helpers.js +161 -0
  29. package/src/kernel/docx/codec/hfHtml.js +152 -0
  30. package/src/kernel/docx/codec/html.js +739 -0
  31. package/src/kernel/docx/codec/losses.js +420 -0
  32. package/src/kernel/docx/codec/markdown.js +170 -0
  33. package/src/kernel/docx/codec/parts.js +249 -0
  34. package/src/kernel/docx/codec/read.js +603 -0
  35. package/src/kernel/docx/codec/render.js +1156 -0
  36. package/src/kernel/docx/codec/roundtrip.js +236 -0
  37. package/src/kernel/docx/codec/write.js +833 -0
  38. package/src/kernel/docx/comments.js +14 -0
  39. package/src/kernel/docx/constants.js +63 -0
  40. package/src/kernel/docx/menus.js +211 -0
  41. package/src/kernel/docx/pageGeometry.js +121 -0
  42. package/src/kernel/docx/pagination.js +481 -0
  43. package/src/kernel/docx/watermark.js +45 -0
  44. package/src/kernel/docx/wordShortcuts.js +37 -0
  45. package/src/kernel/editor/constants.js +8 -0
  46. package/src/kernel/editor/engine/blocks.js +594 -0
  47. package/src/kernel/editor/engine/blocksEnter.js +109 -0
  48. package/src/kernel/editor/engine/blocksInsert.js +254 -0
  49. package/src/kernel/editor/engine/blocksStructure.js +208 -0
  50. package/src/kernel/editor/engine/commands.js +180 -0
  51. package/src/kernel/editor/engine/dom.js +622 -0
  52. package/src/kernel/editor/engine/editor.js +213 -0
  53. package/src/kernel/editor/engine/history.js +149 -0
  54. package/src/kernel/editor/engine/inline.js +656 -0
  55. package/src/kernel/editor/engine/input.js +554 -0
  56. package/src/kernel/editor/engine/interaction.js +137 -0
  57. package/src/kernel/editor/engine/pointer.js +39 -0
  58. package/src/kernel/editor/engine/revision.js +138 -0
  59. package/src/kernel/editor/engine/schema.js +417 -0
  60. package/src/kernel/editor/engine/search.js +113 -0
  61. package/src/kernel/editor/engine/selection.js +119 -0
  62. package/src/kernel/editor/engine/state.js +118 -0
  63. package/src/kernel/editor/engine/tableClip.js +154 -0
  64. package/src/kernel/editor/engine/tableGrid.js +55 -0
  65. package/src/kernel/editor/engine/tableInteraction.js +371 -0
  66. package/src/kernel/editor/engine/tableMenu.js +250 -0
  67. package/src/kernel/editor/engine/tableOps.js +178 -0
  68. package/src/kernel/editor/engine/tables.js +732 -0
  69. package/src/kernel/editor/overlayGeometry.js +20 -0
  70. package/src/kernel/editor/pasteClean.js +293 -0
  71. package/src/kernel/editor/utils.js +49 -0
  72. package/src/kernel/keyboard.js +114 -0
  73. package/src/kernel/notify.js +54 -0
  74. package/src/kernel/textStyles.js +84 -0
  75. package/src/kernel/util/clipboard.js +89 -0
  76. package/src/kernel/util/imageFile.js +91 -0
  77. package/src/kernel/util/safeValue.js +25 -0
  78. package/src/kernel/util/shortcutKey.js +33 -0
  79. package/src/surface/editor-surface.js +469 -0
  80. package/src/ui/color-panel.js +69 -0
  81. package/src/ui/context-menu.js +130 -0
  82. package/src/ui/dialogs.js +249 -0
  83. package/src/ui/find-bar.js +151 -0
  84. package/src/ui/icons.js +36 -0
  85. package/src/ui/menubar.js +28 -0
  86. package/src/ui/panels.js +115 -0
  87. package/src/ui/popup.js +79 -0
  88. package/src/ui/prompt.js +89 -0
  89. package/src/ui/special-chars.js +39 -0
  90. package/src/ui/statusbar.js +81 -0
  91. package/src/ui/toolbar.js +199 -0
  92. package/styles/app.css +944 -0
  93. package/styles/editor-content.css +440 -0
  94. package/styles/tokens.css +154 -0
  95. package/styles/word-panel.css +450 -0
@@ -0,0 +1,175 @@
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 inTable() { return app.editorState?.inTable; },
55
+ get hasSelection() { return app.editorState?.hasSelection; },
56
+ get columns() { return app.state.page.columns || 1; },
57
+ get pageNumbers() { return app.state.pageNumbers; },
58
+ get hfMode() { return app.state.hfMode; },
59
+ get catalog() { return app.flags.catalog; },
60
+ get commentsPanel() { return app.flags.commentsPanel; },
61
+ },
62
+ file: {
63
+ // 嵌入模式:文件动作全部交给宿主 io(打开新页签/写回存储/另存为弹窗),缺省才走包内自带的本地文件实现
64
+ newDoc: io.newDoc || (() => this.newDoc()),
65
+ open: io.open || (() => this.openFile()),
66
+ recentList: () => [],
67
+ openRecent: () => {},
68
+ save: io.save || (() => this.save()),
69
+ saveAs: io.saveAs || (() => this.saveAs()),
70
+ setAutosave: io.setAutosave || ((on) => { this.prefs.autosave = on; savePrefs(this.prefs); this.autosaveEl.checked = on; }),
71
+ pageSetup: () => this.openPageSetupDialog(),
72
+ importDoc: io.importDoc || (() => this.importInput.click()),
73
+ exportCopy: io.exportCopy || (() => this.exportDocx()),
74
+ exportMarkdown: io.exportMarkdown || (() => this.exportMarkdown()),
75
+ print: io.print || (() => this.print()),
76
+ },
77
+ edit: {
78
+ undo: () => this.run('undo'),
79
+ redo: () => this.run('redo'),
80
+ canUndo: () => Boolean(this.editorState.canUndo),
81
+ canRedo: () => Boolean(this.editorState.canRedo),
82
+ cut: () => { this.editor.focus(); document.execCommand('cut'); },
83
+ copy: () => { this.editor.focus(); document.execCommand('copy'); },
84
+ paste: () => notify.info('请用 Ctrl+V 粘贴(浏览器不允许脚本触发粘贴)'),
85
+ find: (replace) => this.findBar.open(!!replace),
86
+ selectAll: () => this.editor?.exec('selectAll'),
87
+ setSuggesting: (on) => {
88
+ this.setEditMode(on ? 'suggest' : 'edit');
89
+ notify.info(on ? '已开启「建议修改」:输入会成为插入建议,删除会成为删除建议' : '已关闭「建议修改」');
90
+ },
91
+ suggestionCount: () => this.suggestionCount,
92
+ acceptAll: () => {
93
+ const n = this.suggestionCount;
94
+ if (n && this.run('resolveRevisions', true)) notify.success(`已接受 ${n} 条建议`);
95
+ this.refreshStats();
96
+ },
97
+ rejectAll: () => {
98
+ const n = this.suggestionCount;
99
+ if (n && this.run('resolveRevisions', false)) notify.success(`已拒绝 ${n} 条建议`);
100
+ this.refreshStats();
101
+ },
102
+ },
103
+ insert: {
104
+ image: () => this.pickImage(),
105
+ table: (e) => this.openTableSpec(e),
106
+ link: () => this.insertLink(),
107
+ comment: () => this.insertComment(),
108
+ footnote: () => this.insertFootnote(),
109
+ toc: () => this.insertToc(),
110
+ refreshToc: () => this.refreshToc(),
111
+ setPageNumber: (align) => {
112
+ this.state.pageNumbers = { ...this.state.pageNumbers, enabled: true, align };
113
+ this.onDocUpdate();
114
+ },
115
+ pageNumberSetup: () => this.openPageSetupDialog(),
116
+ watermark: () => this.openPageSetupDialog(),
117
+ pageBreak: () => this.run('insertPageBreak'),
118
+ hr: () => this.run('setHorizontalRule'),
119
+ specialChars: () => { this.charsPop.hidden = !this.charsPop.hidden; },
120
+ },
121
+ table: {
122
+ action: (key, payload, op) => this.tableAction(key, payload, op),
123
+ model: () => tableMenuModel(this.editor?.tableContext() ?? null),
124
+ state: () => this.editor?.state() ?? null,
125
+ can: (key) => this.editor?.canTableAction(key) ?? false,
126
+ active: (key) => this.editor?.isTableActionActive(key) ?? false,
127
+ exec: (command, ...args) => this.run(command, ...args),
128
+ },
129
+ format: {
130
+ setLayout: (cols) => { this.state.page = { ...this.state.page, columns: cols }; this.onDocUpdate(); this.paginate(); },
131
+ paragraphStyle: (kind) => this.run('convertBlock', kind),
132
+ align: (v) => this.run('setBlockAlign', v),
133
+ setLineHeight: (v) => this.run('setBlockLineHeight', v),
134
+ firstLine: () => this.run('toggleFirstLineIndent'),
135
+ setHfMode: (mode) => { this.state.hfMode = mode; this.onDocUpdate(); },
136
+ list: (command) => this.run(command),
137
+ clearFormat: () => this.run('clearFormat'),
138
+ },
139
+ view: {
140
+ zoomIn: () => this.setZoom(this.zoom + 10),
141
+ zoomOut: () => this.setZoom(this.zoom - 10),
142
+ zoomReset: () => this.setZoom(100),
143
+ setView: (key, on) => this.setView(key, on),
144
+ },
145
+ };
146
+ // [设计] 只读档在这里统一短路写动作:菜单栏、右键菜单、快捷键共用这一份 ctx,
147
+ // 不必逐条给菜单项挂 disabled;查询函数(model/state/can…)必须留着,否则菜单结构会读不到数据。
148
+ if (app.readOnly) {
149
+ const allow = {
150
+ file: ['recentList', 'openRecent', 'exportCopy', 'exportMarkdown', 'print'],
151
+ edit: ['canUndo', 'canRedo', 'copy', 'find', 'selectAll', 'suggestionCount'],
152
+ insert: [],
153
+ table: ['model', 'state', 'can', 'active'],
154
+ format: [],
155
+ };
156
+ for (const [group, keys] of Object.entries(allow)) {
157
+ for (const [key, fn] of Object.entries(ctx[group])) {
158
+ if (typeof fn === 'function' && !keys.includes(key)) ctx[group][key] = () => false;
159
+ }
160
+ }
161
+ }
162
+ return ctx;
163
+ }
164
+
165
+ function shortcutCtx() {
166
+ const file = this.menuCtx().file;
167
+ return {
168
+ file,
169
+ insert: { pageBreak: () => this.run('insertPageBreak'), link: () => this.insertLink(), comment: () => this.insertComment(), list: (ordered) => this.run(ordered ? 'toggleOrderedList' : 'toggleBulletList') },
170
+ edit: { find: () => this.findBar.open(false), findReplace: () => this.findBar.open(true) },
171
+ view: { zoomIn: () => this.setZoom(this.zoom + 10), zoomOut: () => this.setZoom(this.zoom - 10), zoomReset: () => this.setZoom(100) },
172
+ };
173
+ }
174
+
175
+ export const menusMethods = { onContextMenu, tableAction, menuCtx, shortcutCtx };
@@ -0,0 +1,110 @@
1
+ // [文件] gbdocx·word·notes —— 脚注与尾注 —— 页码刷新、重新编号、插入与编辑
2
+
3
+ // [设计] 方法以独立函数导出,由 word-app.js 末尾 Object.assign 装配到 WordApp.prototype:
4
+ // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
+
6
+ import { genId } from 'guabiutils';
7
+ import { pageOfElement } from '../../kernel/docx/pagination.js';
8
+ import { DOC_CLASS, NOTE_ATTR } from '../../kernel/editor/engine/schema.js';
9
+ import { notify } from '../../kernel/notify.js';
10
+ function refreshFootnotePages() {
11
+ const root = this.editor?.root;
12
+ if (!root || this.state.footnotes.length === 0) {
13
+ this.footnotePages = new Map();
14
+ return;
15
+ }
16
+ const byPage = new Map();
17
+ for (const sup of root.querySelectorAll(`sup.${DOC_CLASS.FOOTNOTE}`)) {
18
+ const id = sup.getAttribute(NOTE_ATTR);
19
+ const item = this.state.footnotes.find((n) => n.id === id);
20
+ if (!item) continue;
21
+ const p = pageOfElement(root, sup);
22
+ if (!byPage.has(p)) byPage.set(p, []);
23
+ byPage.get(p).push({ id: item.id, text: item.text, ord: sup.textContent || '' });
24
+ }
25
+ this.footnotePages = byPage;
26
+ }
27
+
28
+ function renumberFootnotes() {
29
+ const sups = this.editor?.root?.querySelectorAll(`sup.${DOC_CLASS.FOOTNOTE}`);
30
+ if (!sups) return;
31
+ Array.from(sups).forEach((sup, i) => { sup.textContent = String(i + 1); });
32
+ }
33
+
34
+ function insertFootnote() {
35
+ const ed = this.editor;
36
+ if (!ed || this.editMode === 'readonly') return;
37
+ ed.focus();
38
+ const id = genId('fn');
39
+ const ord = String((ed.root?.querySelectorAll(`sup.${DOC_CLASS.FOOTNOTE}`).length || 0) + 1);
40
+ if (!this.run('insertNote', { id, ord })) return notify.warning('请先把光标放进正文');
41
+ this._pendingNoteId = id;
42
+ const anchor = ed.root?.querySelector(`sup.${DOC_CLASS.FOOTNOTE}[${NOTE_ATTR}="${id}"]`);
43
+ this.prompt.openAt(anchor, {
44
+ title: '脚注内容',
45
+ placeholder: '写下脚注…',
46
+ maxlength: 500,
47
+ submit: (text) => {
48
+ this._pendingNoteId = '';
49
+ if (text.trim() === '') {
50
+ this.run('removeNote', id);
51
+ this.renumberFootnotes();
52
+ return true;
53
+ }
54
+ this.state.footnotes = [...this.state.footnotes, { id, text }];
55
+ this.renumberFootnotes();
56
+ this.onDocUpdate();
57
+ return true;
58
+ },
59
+ });
60
+ }
61
+
62
+ function editFootnote(fn) {
63
+ const anchor = this.editor.root?.querySelector(`sup.${DOC_CLASS.FOOTNOTE}[${NOTE_ATTR}="${fn.id}"]`);
64
+ this.prompt.openAt(anchor, {
65
+ title: '脚注内容',
66
+ placeholder: '留空提交 = 删除该脚注',
67
+ maxlength: 500,
68
+ value: fn.text,
69
+ submit: (text) => {
70
+ if (text.trim() === '') {
71
+ this.state.footnotes = this.state.footnotes.filter((n) => n.id !== fn.id);
72
+ this.run('removeNote', fn.id);
73
+ this.renumberFootnotes();
74
+ } else {
75
+ this.state.footnotes = this.state.footnotes.map((n) => (n.id === fn.id ? { ...n, text } : n));
76
+ }
77
+ this.onDocUpdate();
78
+ return true;
79
+ },
80
+ });
81
+ }
82
+
83
+ function editEndnote(en) {
84
+ const anchor = this.editor.root?.querySelector(`sup.${DOC_CLASS.ENDNOTE}[${NOTE_ATTR}="${en.id}"]`);
85
+ this.prompt.openAt(anchor, {
86
+ title: '尾注内容',
87
+ placeholder: '留空提交 = 删除该尾注',
88
+ maxlength: 500,
89
+ value: en.text,
90
+ submit: (text) => {
91
+ if (text.trim() === '') {
92
+ this.state.endnotes = this.state.endnotes.filter((n) => n.id !== en.id);
93
+ this.run('removeNote', en.id);
94
+ } else {
95
+ this.state.endnotes = this.state.endnotes.map((n) => (n.id === en.id ? { ...n, text } : n));
96
+ }
97
+ this.onDocUpdate();
98
+ return true;
99
+ },
100
+ });
101
+ }
102
+
103
+ function rollbackPendingNote() {
104
+ if (!this._pendingNoteId) return;
105
+ const id = this._pendingNoteId;
106
+ this._pendingNoteId = '';
107
+ this.run('removeNote', id);
108
+ }
109
+
110
+ export const notesMethods = { refreshFootnotePages, renumberFootnotes, insertFootnote, editFootnote, editEndnote, rollbackPendingNote };
@@ -0,0 +1,22 @@
1
+ // [文件] gbdocx·word·shared —— 应用级常量与偏好读写(无 this,装配前后都是模块级函数)
2
+
3
+ export const MD_MIME = 'text/markdown;charset=utf-8';
4
+
5
+ /** 本机偏好存储键(缩放/自动保存/视图开关等,按环境共用一份) */
6
+ const LS_KEY = 'gbdocx-word-prefs';
7
+
8
+ export function loadPrefs() {
9
+ try {
10
+ return JSON.parse(localStorage.getItem(LS_KEY) || '{}') || {};
11
+ } catch {
12
+ return {};
13
+ }
14
+ }
15
+
16
+ export function savePrefs(prefs) {
17
+ try {
18
+ localStorage.setItem(LS_KEY, JSON.stringify(prefs));
19
+ } catch {
20
+ /* 忽略存储失败 */
21
+ }
22
+ }
@@ -0,0 +1,88 @@
1
+ // [文件] gbdocx·word·view —— 视图与对话框 —— 视图开关、面板、页面设置/页边距/分栏
2
+
3
+ // [设计] 方法以独立函数导出,由 word-app.js 末尾 Object.assign 装配到 WordApp.prototype:
4
+ // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
+
6
+ import { cleanHfHtml } from '../../kernel/docx/codec/helpers.js';
7
+ import { openColumnDialog as openColumnDialogUI, openMarginDialog as openMarginDialogUI, openPageSetupDialog as openPageSetupDialogUI } from '../../ui/dialogs.js';
8
+ import { savePrefs } from './shared.js';
9
+ function setView(key, on) {
10
+ const next = on === undefined ? !this.flags[key] : !!on;
11
+ this.flags = { ...this.flags, [key]: next };
12
+ this.prefs.flags = this.flags;
13
+ savePrefs(this.prefs);
14
+ this.applyView();
15
+ }
16
+
17
+ function applyView() {
18
+ const main = this.root.querySelector('.word-main');
19
+ const hasCatalog = this.flags.catalog;
20
+ const hasComments = this.flags.commentsPanel;
21
+ if (hasCatalog && !this.catalogPanel.el.isConnected) main.insertBefore(this.catalogPanel.el, this.editorWrap);
22
+ if (!hasCatalog && this.catalogPanel.el.isConnected) this.catalogPanel.el.remove();
23
+ if (hasComments && !this.commentsPanel.el.isConnected) main.appendChild(this.commentsPanel.el);
24
+ if (!hasComments && this.commentsPanel.el.isConnected) this.commentsPanel.el.remove();
25
+ if (hasCatalog) this.refreshCatalog();
26
+ this.renderPanels();
27
+ }
28
+
29
+ function renderPanels() {
30
+ if (this.flags.commentsPanel) {
31
+ this.commentsPanel.activeKey = this.activeCommentKey;
32
+ this.commentsPanel.setItems(this.comments);
33
+ }
34
+ }
35
+
36
+ function renderHead() {
37
+ this.titleEl.textContent = this.doc.name || '新建文档';
38
+ this.pathEl.textContent = this.doc.pathText || (this.doc.handle ? '(已关联文件)' : '(未关联文件,保存将另存为)');
39
+ this.dirtyEl.hidden = !this.dirty;
40
+ }
41
+
42
+ function openPageSetupDialog() {
43
+ openPageSetupDialogUI({
44
+ page: this.state.page,
45
+ pageNumbers: this.state.pageNumbers,
46
+ watermark: this.state.watermark,
47
+ hfMode: this.state.hfMode,
48
+ header: this.state.header,
49
+ footer: this.state.footer,
50
+ headerFirst: this.state.headerFirst,
51
+ footerFirst: this.state.footerFirst,
52
+ }, (out) => {
53
+ const prevHf = { header: this.state.header, footer: this.state.footer, headerFirst: this.state.headerFirst, footerFirst: this.state.footerFirst };
54
+ this.state.page = { ...this.state.page, ...out.page };
55
+ this.state.pageNumbers = out.pageNumbers;
56
+ this.state.watermark = out.watermark;
57
+ this.state.hfMode = out.hfMode;
58
+ this.state.header = cleanHfHtml(out.header);
59
+ this.state.footer = cleanHfHtml(out.footer);
60
+ this.state.headerFirst = cleanHfHtml(out.headerFirst);
61
+ this.state.footerFirst = cleanHfHtml(out.footerFirst);
62
+ // 只有「新写入的文字」才把「不显示」自动拉回显示;用户明确选「不显示」而文字没变时必须尊重选择
63
+ const changedToText = ['header', 'footer', 'headerFirst', 'footerFirst']
64
+ .some((key) => this.state[key] !== prevHf[key] && this.state[key].replace(/<[^>]*>/g, '').trim());
65
+ if (changedToText && this.state.hfMode === 'none') this.state.hfMode = 'all';
66
+ this.onDocUpdate();
67
+ this.applyEditorGeometry();
68
+ this.paginate();
69
+ });
70
+ }
71
+
72
+ function openMarginDialog() {
73
+ openMarginDialogUI(this.state.page.margins, (margins) => {
74
+ this.state.page = { ...this.state.page, margins };
75
+ this.onDocUpdate();
76
+ this.paginate();
77
+ });
78
+ }
79
+
80
+ function openColumnDialog() {
81
+ openColumnDialogUI(this.state.page, (patch) => {
82
+ this.state.page = { ...this.state.page, ...patch };
83
+ this.onDocUpdate();
84
+ this.paginate();
85
+ });
86
+ }
87
+
88
+ export const viewMethods = { setView, applyView, renderPanels, renderHead, openPageSetupDialog, openMarginDialog, openColumnDialog };