@a200888213/gbdocx 0.3.0 → 0.5.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 +4 -3
- package/index.html +5 -0
- package/package.json +48 -47
- package/serve.mjs +3 -1
- package/src/app/word/edit.js +2 -2
- package/src/app/word/layout.js +5 -2
- package/src/app/word/menus.js +26 -0
- package/src/app/word/view.js +31 -1
- package/src/app/word-app.js +36 -21
- package/src/kernel/docx/menus.js +144 -7
- package/src/kernel/docx/pageGeometry.js +2 -0
- package/src/kernel/editor/engine/blocksStructure.js +19 -1
- package/src/kernel/editor/engine/commands.js +1 -0
- package/src/kernel/editor/engine/dom.js +42 -18
- package/src/kernel/editor/engine/tableInteraction.js +17 -0
- package/src/kernel/editor/engine/tableOps.js +1 -5
- package/src/surface/editor-surface.js +131 -0
- package/src/ui/context-menu.js +4 -1
- package/src/ui/icons.js +99 -2
- package/src/ui/ribbon.js +485 -0
- package/src/ui/toolbar.js +2 -169
- package/styles/app.css +139 -123
- package/styles/tokens.css +5 -5
- package/styles/word-panel.css +9 -49
|
@@ -133,6 +133,7 @@ export const COMMANDS = {
|
|
|
133
133
|
moveBlockUp: { run: (ed, el) => B.moveBlock(ed.root, el, -1) },
|
|
134
134
|
moveBlockDown: { run: (ed, el) => B.moveBlock(ed.root, el, 1) },
|
|
135
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) },
|
|
136
137
|
deleteRange: {
|
|
137
138
|
run: (ed, { block, from, to }) => {
|
|
138
139
|
if (!block?.isConnected) return false;
|
|
@@ -52,7 +52,7 @@ const ANCHOR_SELECTOR = '[data-attach],[data-ref-doc]';
|
|
|
52
52
|
* 占位/分隔元素整块删除;栏容器拆壳留内容;行级拆分块按家族标记并回首个块 */
|
|
53
53
|
export const RUNTIME_ELEMENT_SELECTOR = '.wd-page-gap, .wd-col-sep';
|
|
54
54
|
const RUNTIME_UNWRAP_SELECTOR = '.wd-col';
|
|
55
|
-
const RUNTIME_SPLIT_ATTR = 'data-wd-split';
|
|
55
|
+
export const RUNTIME_SPLIT_ATTR = 'data-wd-split';
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* 运行期布局产物判据(Word 分页的页间缝 / 栏分隔 / 跨页拆分的段落碎片):不是正文块。
|
|
@@ -62,6 +62,46 @@ const RUNTIME_SPLIT_ATTR = 'data-wd-split';
|
|
|
62
62
|
export const isRuntimeBlock = (el) =>
|
|
63
63
|
el?.nodeType === Node.ELEMENT_NODE && (el.matches(RUNTIME_ELEMENT_SELECTOR) || el.hasAttribute(RUNTIME_SPLIT_ATTR));
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* 拆分家族并回首块
|
|
67
|
+
* @param {HTMLElement} first 首块(文档序最先的碎片)
|
|
68
|
+
* @param {HTMLElement[]} rest 其余碎片
|
|
69
|
+
* @returns {HTMLElement} 首块
|
|
70
|
+
*/
|
|
71
|
+
function mergeSplitGroup(first, rest) {
|
|
72
|
+
rest.forEach((el) => {
|
|
73
|
+
// 表格家族:续表只有「重复表头 + 接续行」两块——表头是克隆(丢弃),接续行并回首表最后一个 tbody
|
|
74
|
+
if (first.tagName === 'TABLE') {
|
|
75
|
+
// [坑] 通用「appendChild 全部子节点」会把续表的 thead / tbody 直接挂到首表尾部(多出一个 tbody),
|
|
76
|
+
// 表格结构当场坏掉:行级分页只认 tBodies 里的行,行数由此少算,超高表被误判「装得下」而永不拆行
|
|
77
|
+
const host = first.tBodies[first.tBodies.length - 1] || first.appendChild(document.createElement('tbody'));
|
|
78
|
+
Array.from(el.tBodies).forEach((tb) => Array.from(tb.rows).forEach((row) => host.appendChild(row)));
|
|
79
|
+
el.remove();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
moveChildren(el, first);
|
|
83
|
+
el.remove();
|
|
84
|
+
});
|
|
85
|
+
first.removeAttribute(RUNTIME_SPLIT_ATTR);
|
|
86
|
+
return first;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 把 el 所在的跨页拆分家族并回首块(悬停/拖拽命中的可能是续表碎片)
|
|
91
|
+
* [设计] 只并本家族,不动其它分页产物:宿主拖表要在同一次历史提交里先并回再搬家,这一步不能等重排
|
|
92
|
+
* @param {HTMLElement} container 编辑面根(家族查找范围)
|
|
93
|
+
* @param {HTMLElement} el 家族任一成员
|
|
94
|
+
* @returns {HTMLElement} 首块(无拆分标记时原样返回)
|
|
95
|
+
*/
|
|
96
|
+
export function mergeSplitFamily(container, el) {
|
|
97
|
+
const id = el?.getAttribute?.(RUNTIME_SPLIT_ATTR);
|
|
98
|
+
if (!id || !container?.querySelectorAll || !container.contains?.(el)) return el;
|
|
99
|
+
const members = Array.from(container.querySelectorAll(`[${RUNTIME_SPLIT_ATTR}]`))
|
|
100
|
+
.filter((node) => node.getAttribute(RUNTIME_SPLIT_ATTR) === id);
|
|
101
|
+
if (!members.length) return el;
|
|
102
|
+
return mergeSplitGroup(members[0], members.slice(1));
|
|
103
|
+
}
|
|
104
|
+
|
|
65
105
|
/**
|
|
66
106
|
* 把运行期布局结构还原成单流正文(装载时防御性调用、序列化前必须调用):
|
|
67
107
|
* 拆分块并回、栏容器拆壳、占位元素删除——三者的顺序不可调换
|
|
@@ -75,23 +115,7 @@ export function restoreRuntimeStructures(container) {
|
|
|
75
115
|
if (!groups.has(id)) groups.set(id, []);
|
|
76
116
|
groups.get(id).push(el);
|
|
77
117
|
});
|
|
78
|
-
groups.forEach((els) =>
|
|
79
|
-
const first = els[0];
|
|
80
|
-
els.slice(1).forEach((el) => {
|
|
81
|
-
// 表格家族:续表只有「重复表头 + 接续行」两块——表头是克隆(丢弃),接续行并回首表最后一个 tbody
|
|
82
|
-
if (first.tagName === 'TABLE') {
|
|
83
|
-
// [坑] 通用「appendChild 全部子节点」会把续表的 thead / tbody 直接挂到首表尾部(多出一个 tbody),
|
|
84
|
-
// 表格结构当场坏掉:行级分页只认 tBodies 里的行,行数由此少算,超高表被误判「装得下」而永不拆行
|
|
85
|
-
const host = first.tBodies[first.tBodies.length - 1] || first.appendChild(document.createElement('tbody'));
|
|
86
|
-
Array.from(el.tBodies).forEach((tb) => Array.from(tb.rows).forEach((row) => host.appendChild(row)));
|
|
87
|
-
el.remove();
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
moveChildren(el, first);
|
|
91
|
-
el.remove();
|
|
92
|
-
});
|
|
93
|
-
first.removeAttribute(RUNTIME_SPLIT_ATTR);
|
|
94
|
-
});
|
|
118
|
+
groups.forEach((els) => mergeSplitGroup(els[0], els.slice(1)));
|
|
95
119
|
// 2) 栏容器拆壳:里面装的是正文本体,删了就丢内容
|
|
96
120
|
container.querySelectorAll(RUNTIME_UNWRAP_SELECTOR).forEach((el) => unwrapElement(el));
|
|
97
121
|
// 3) 占位/分隔元素整块删除
|
|
@@ -16,6 +16,23 @@ export const TABLE_INTERACTION_HANDLERS = ['onMouseDown', 'onHoverColumn', 'onLe
|
|
|
16
16
|
|
|
17
17
|
/** 表格框选与列宽方法(装配到 EditorCore.prototype;this 为内核实例) */
|
|
18
18
|
export const tableInteractionMethods = {
|
|
19
|
+
/**
|
|
20
|
+
* 整表转成单元格框选(移动手柄单击 / 菜单「选择整个表格」共用)
|
|
21
|
+
* @param {HTMLTableElement} table 目标表
|
|
22
|
+
* @returns {boolean} 是否落地
|
|
23
|
+
*/
|
|
24
|
+
selectTable(table) {
|
|
25
|
+
if (!table?.isConnected || !this.root.contains(table)) return false;
|
|
26
|
+
const grid = this.cachedGrid(table);
|
|
27
|
+
if (!grid.width || !grid.height) return false;
|
|
28
|
+
this.cellRect = { table, rect: { r1: 0, c1: 0, r2: grid.height - 1, c2: grid.width - 1 } };
|
|
29
|
+
// 紧接着的表格菜单动作按命中格取上下文:锚到左上格,整表操作才不会静默失效
|
|
30
|
+
this.contextCell = grid.matrix[0]?.[0]?.el || null;
|
|
31
|
+
this.notifyCellSelection();
|
|
32
|
+
this.syncState();
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
|
|
19
36
|
/**
|
|
20
37
|
* 拖列边设列宽:落点在「格右边界 ± COL_RESIZE_HIT/2」的命中带内即接管
|
|
21
38
|
* 中间列的右边界 = 与右邻列的共享线(两列守恒转移,表宽不变);最后一列的右边界 = 表右边界
|
|
@@ -81,11 +81,7 @@ export const tableOpsMethods = {
|
|
|
81
81
|
/** 全选表格单元格(菜单「选择整个表格」):转成框选态,后续合并/删除按整表走 */
|
|
82
82
|
selectAllCells() {
|
|
83
83
|
const ctx = this.tableContext();
|
|
84
|
-
|
|
85
|
-
const rect = { r1: 0, c1: 0, r2: ctx.grid.height - 1, c2: ctx.grid.width - 1 };
|
|
86
|
-
this.cellRect = { table: ctx.table, rect };
|
|
87
|
-
this.notifyCellSelection();
|
|
88
|
-
return true;
|
|
84
|
+
return ctx ? this.selectTable(ctx.table) : false;
|
|
89
85
|
},
|
|
90
86
|
|
|
91
87
|
/**
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// 说明:Vue 槽位改回调装配(backdrop 由宿主填充),其余行为与 guabi 版逐条对齐。
|
|
3
3
|
|
|
4
4
|
import { EditorCore } from '../kernel/editor/engine/editor.js';
|
|
5
|
+
import { isRuntimeBlock } from '../kernel/editor/engine/dom.js';
|
|
5
6
|
import { overlayOrigin, PROBE_WIDTH } from '../kernel/editor/overlayGeometry.js';
|
|
6
7
|
|
|
7
8
|
/** 内容上报防抖(ms):按键只置脏,序列化交给拖尾防抖;失焦与卸载立即落地 */
|
|
@@ -11,7 +12,16 @@ const MARQUEE_THRESHOLD = 4;
|
|
|
11
12
|
const MIN_IMAGE_WIDTH = 60;
|
|
12
13
|
const MIN_IMAGE_HEIGHT = 40;
|
|
13
14
|
const RESIZE_DIRECTIONS = ['top-left', 'top-right', 'bottom-left', 'bottom-right'];
|
|
15
|
+
/** 表格移动手柄尺寸(px)与距表左沿的间隙:落在纸的左边距里(Word 口径) */
|
|
16
|
+
const TABLE_MOVE_W = 14;
|
|
17
|
+
const TABLE_MOVE_H = 20;
|
|
18
|
+
const TABLE_MOVE_GAP = 6;
|
|
19
|
+
/** 拖表起手阈值(px):位移不足按单击处理(单击=选中整张表) */
|
|
20
|
+
const TABLE_MOVE_THRESHOLD = 4;
|
|
21
|
+
/** 分页运行期栏容器类名(与 pagination.js 同契约):落点要穿透到栏内正文块 */
|
|
22
|
+
const COL_CLASS = 'wd-col';
|
|
14
23
|
const ZOOM_ICON = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3M11 8v6M8 11h6"/></svg>';
|
|
24
|
+
const MOVE_ICON = '<svg viewBox="0 0 10 18" width="10" height="18" fill="currentColor" aria-hidden="true"><circle cx="2.6" cy="4" r="1.25"/><circle cx="7.4" cy="4" r="1.25"/><circle cx="2.6" cy="9" r="1.25"/><circle cx="7.4" cy="9" r="1.25"/><circle cx="2.6" cy="14" r="1.25"/><circle cx="7.4" cy="14" r="1.25"/></svg>';
|
|
15
25
|
|
|
16
26
|
export class EditorSurface {
|
|
17
27
|
/**
|
|
@@ -48,9 +58,11 @@ export class EditorSurface {
|
|
|
48
58
|
<div class="re-table-layer">
|
|
49
59
|
<span class="re-table-select" hidden></span>
|
|
50
60
|
<div class="re-table-handles" hidden>
|
|
61
|
+
<button type="button" class="re-table-move" aria-label="拖动表格" title="拖动表格">${MOVE_ICON}</button>
|
|
51
62
|
<button type="button" class="re-table-handle gbd-is-column" aria-label="在右侧插入一列">+</button>
|
|
52
63
|
<button type="button" class="re-table-handle gbd-is-row" aria-label="在下方插入一行">+</button>
|
|
53
64
|
</div>
|
|
65
|
+
<span class="re-drop-line" hidden></span>
|
|
54
66
|
<span class="re-col-line" hidden></span>
|
|
55
67
|
</div>
|
|
56
68
|
<div class="re-marquee" hidden></div>
|
|
@@ -71,6 +83,8 @@ export class EditorSurface {
|
|
|
71
83
|
this.tableLayer = root.querySelector('.re-table-layer');
|
|
72
84
|
this.selectBoxEl = root.querySelector('.re-table-select');
|
|
73
85
|
this.handlesEl = root.querySelector('.re-table-handles');
|
|
86
|
+
this.moveHandleEl = root.querySelector('.re-table-move');
|
|
87
|
+
this.dropLineEl = root.querySelector('.re-drop-line');
|
|
74
88
|
this.colLineEl = root.querySelector('.re-col-line');
|
|
75
89
|
this.marqueeEl = root.querySelector('.re-marquee');
|
|
76
90
|
this.resizeBoxEl = root.querySelector('.re-resize-box');
|
|
@@ -181,6 +195,7 @@ export class EditorSurface {
|
|
|
181
195
|
destroy() {
|
|
182
196
|
this.flushEmit();
|
|
183
197
|
this._resizeCleanup?.();
|
|
198
|
+
this._tableMoveCleanup?.();
|
|
184
199
|
this.editor?.destroy();
|
|
185
200
|
this.editor = null;
|
|
186
201
|
if (this.resizeRaf) cancelAnimationFrame(this.resizeRaf);
|
|
@@ -242,6 +257,12 @@ export class EditorSurface {
|
|
|
242
257
|
const row = this.handlesEl.querySelector('.gbd-is-row');
|
|
243
258
|
Object.assign(col.style, { left: `${Math.round(left + width)}px`, top: `${Math.round(top)}px`, height: `${Math.round(height)}px` });
|
|
244
259
|
Object.assign(row.style, { left: `${Math.round(left)}px`, top: `${Math.round(top + height)}px`, width: `${Math.round(width)}px` });
|
|
260
|
+
// 移动手柄:贴表左上角、纵向对齐首行中线(表恰在版心首行时手柄自然落进纸的左边距)
|
|
261
|
+
const rowH = (table.rows?.[0]?.getBoundingClientRect().height || 0) / base.z;
|
|
262
|
+
Object.assign(this.moveHandleEl.style, {
|
|
263
|
+
left: `${Math.round(left - TABLE_MOVE_W - TABLE_MOVE_GAP)}px`,
|
|
264
|
+
top: `${Math.round(top + Math.max(0, (rowH - TABLE_MOVE_H) / 2))}px`,
|
|
265
|
+
});
|
|
245
266
|
this.handlesEl.hidden = false;
|
|
246
267
|
}
|
|
247
268
|
|
|
@@ -301,11 +322,14 @@ export class EditorSurface {
|
|
|
301
322
|
});
|
|
302
323
|
this.handlesEl.querySelector('.gbd-is-column').addEventListener('mousedown', (e) => this.startEdgeGesture('column', e));
|
|
303
324
|
this.handlesEl.querySelector('.gbd-is-row').addEventListener('mousedown', (e) => this.startEdgeGesture('row', e));
|
|
325
|
+
this.moveHandleEl.addEventListener('mousedown', (e) => this.startTableMove(e));
|
|
304
326
|
this.viewerEl.addEventListener('click', () => this.closePreview());
|
|
305
327
|
}
|
|
306
328
|
|
|
307
329
|
onSurfaceMouseMove(event) {
|
|
308
330
|
if (!this.editable) return;
|
|
331
|
+
// 拖表手势期悬停目标已锁:再按指针重算会让手柄跟着别的表跳
|
|
332
|
+
if (this._tableMoveCleanup) return;
|
|
309
333
|
const target = event.target;
|
|
310
334
|
if (!(target instanceof Element)) return;
|
|
311
335
|
if (target.closest('.re-table-handles')) return;
|
|
@@ -327,6 +351,113 @@ export class EditorSurface {
|
|
|
327
351
|
ed.beginEdgeGesture(event, table, axis);
|
|
328
352
|
}
|
|
329
353
|
|
|
354
|
+
/**
|
|
355
|
+
* 表格移动手柄手势:单击选中整表,拖拽把表搬到落点块前/后
|
|
356
|
+
* [设计] 落点按正文块几何现算(不用 elementFromPoint):页间缝、栏容器、浮件都不是合法落点,
|
|
357
|
+
* 指针划过页缝时取最近的正文块,落点线不会闪断;跨页续表由内核先并回首块再搬
|
|
358
|
+
*/
|
|
359
|
+
startTableMove(event) {
|
|
360
|
+
const ed = this.editor;
|
|
361
|
+
const table = this.hoveredTable;
|
|
362
|
+
if (!ed || ed.destroyed || !table?.isConnected || !this.editable || event.button !== 0) return;
|
|
363
|
+
if (this._tableMoveCleanup) return;
|
|
364
|
+
event.preventDefault();
|
|
365
|
+
const startX = event.clientX;
|
|
366
|
+
const startY = event.clientY;
|
|
367
|
+
let dragging = false;
|
|
368
|
+
let slot = null;
|
|
369
|
+
const cleanup = () => {
|
|
370
|
+
this._tableMoveCleanup = null;
|
|
371
|
+
document.removeEventListener('mousemove', onMove);
|
|
372
|
+
document.removeEventListener('mouseup', onUp);
|
|
373
|
+
document.removeEventListener('keydown', onKey, true);
|
|
374
|
+
this.el.classList.remove('gbd-is-table-moving');
|
|
375
|
+
this.hideDropLine();
|
|
376
|
+
};
|
|
377
|
+
const onMove = (moveEvent) => {
|
|
378
|
+
if (!dragging) {
|
|
379
|
+
const moved = Math.abs(moveEvent.clientX - startX) + Math.abs(moveEvent.clientY - startY);
|
|
380
|
+
if (moved < TABLE_MOVE_THRESHOLD) return;
|
|
381
|
+
dragging = true;
|
|
382
|
+
this.el.classList.add('gbd-is-table-moving');
|
|
383
|
+
}
|
|
384
|
+
slot = this.dropSlot(moveEvent.clientY, table);
|
|
385
|
+
this.showDropLine(slot);
|
|
386
|
+
};
|
|
387
|
+
const onUp = () => {
|
|
388
|
+
cleanup();
|
|
389
|
+
// 拖到一半切只读 / 卸载:丢弃本次手势,不再落选区或改文档
|
|
390
|
+
if (ed.destroyed || !this.editable) return;
|
|
391
|
+
if (!dragging) {
|
|
392
|
+
ed.selectTable(table);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (slot) ed.exec('moveTableTo', table, slot.ref, slot.before);
|
|
396
|
+
// 换位后旧框选(可能落在续表碎片上)与几何对不上:拖完即清,避免覆盖层画到错位置
|
|
397
|
+
ed.clearCellSelection();
|
|
398
|
+
// 表已换位(或未落点):悬停几何随旧位置作废,等下次移入表格再浮出
|
|
399
|
+
this.hideTableHandles();
|
|
400
|
+
};
|
|
401
|
+
const onKey = (keyEvent) => {
|
|
402
|
+
if (keyEvent.key !== 'Escape') return;
|
|
403
|
+
keyEvent.preventDefault();
|
|
404
|
+
cleanup();
|
|
405
|
+
};
|
|
406
|
+
this._tableMoveCleanup = cleanup;
|
|
407
|
+
document.addEventListener('mousemove', onMove);
|
|
408
|
+
document.addEventListener('mouseup', onUp);
|
|
409
|
+
document.addEventListener('keydown', onKey, true);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* 拖表落点:指针纵坐标命中的正文块(拖动的表自身与它的祖先块不算)
|
|
414
|
+
* @param {number} y 指针视口纵坐标
|
|
415
|
+
* @param {HTMLElement} dragged 被拖的表
|
|
416
|
+
* @returns {{ref:HTMLElement,before:boolean,rect:DOMRect}|null} 无正文块可落时 null
|
|
417
|
+
*/
|
|
418
|
+
dropSlot(y, dragged) {
|
|
419
|
+
const blocks = this.logicalBlocks().filter((el) => el !== dragged && !dragged.contains(el) && !el.contains(dragged));
|
|
420
|
+
if (!blocks.length) return null;
|
|
421
|
+
let last = null;
|
|
422
|
+
for (const el of blocks) {
|
|
423
|
+
const rect = el.getBoundingClientRect();
|
|
424
|
+
last = { ref: el, rect };
|
|
425
|
+
if (y < rect.bottom) return { ref: el, before: y < rect.top + rect.height / 2, rect };
|
|
426
|
+
}
|
|
427
|
+
return { ref: last.ref, before: false, rect: last.rect };
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** 正文本体块(文档序;穿透分页栏容器,页间缝与续表碎片不算块) */
|
|
431
|
+
logicalBlocks() {
|
|
432
|
+
const out = [];
|
|
433
|
+
const walk = (parent) => {
|
|
434
|
+
for (const el of parent.children) {
|
|
435
|
+
if (isRuntimeBlock(el)) continue;
|
|
436
|
+
if (el.classList.contains(COL_CLASS)) {
|
|
437
|
+
walk(el);
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
out.push(el);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
walk(this.contentEl);
|
|
444
|
+
return out;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
showDropLine(slot) {
|
|
448
|
+
if (!slot) {
|
|
449
|
+
this.hideDropLine();
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const top = slot.before ? slot.rect.top : slot.rect.bottom;
|
|
453
|
+
Object.assign(this.dropLineEl.style, toLocalRect({ left: slot.rect.left, top, width: slot.rect.width, height: 2 }, this.probeEl));
|
|
454
|
+
this.dropLineEl.hidden = false;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
hideDropLine() {
|
|
458
|
+
this.dropLineEl.hidden = true;
|
|
459
|
+
}
|
|
460
|
+
|
|
330
461
|
onBlankMouseDown(event) {
|
|
331
462
|
const ed = this.editor;
|
|
332
463
|
const root = this.contentEl;
|
package/src/ui/context-menu.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// [文件] gbdocx·ContextMenu —— 右键/下拉菜单渲染(条目口径:label/disabled/checked/
|
|
1
|
+
// [文件] gbdocx·ContextMenu —— 右键/下拉菜单渲染(条目口径:label/icon/disabled/checked/colorDot/shortcut/divided/children/input/onClick)
|
|
2
2
|
import { openPopup } from './popup.js';
|
|
3
|
+
import { icon } from './icons.js';
|
|
3
4
|
|
|
4
5
|
const CHECK = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12l5 5L20 7"/></svg>';
|
|
5
6
|
const SUB = '<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 6l6 6-6 6"/></svg>';
|
|
@@ -58,6 +59,8 @@ function buildList(items) {
|
|
|
58
59
|
if (item.checked) lead.innerHTML = CHECK;
|
|
59
60
|
else if (item.colorDot) {
|
|
60
61
|
lead.innerHTML = `<i class="gbd-menu__dot" style="background:${item.colorDot}"></i>`;
|
|
62
|
+
} else if (item.icon) {
|
|
63
|
+
lead.innerHTML = icon(item.icon);
|
|
61
64
|
}
|
|
62
65
|
row.appendChild(lead);
|
|
63
66
|
|
package/src/ui/icons.js
CHANGED
|
@@ -7,8 +7,8 @@ export const ICONS = {
|
|
|
7
7
|
italic: S('<path d="M15 5h-5M14 19H9M14 5l-4 14"/>'),
|
|
8
8
|
underline: S('<path d="M7 5v7a5 5 0 0 0 10 0V5M5 20h14"/>'),
|
|
9
9
|
strike: S('<path d="M5 12h14M8 8a3 3 0 0 1 3-3h3a3 3 0 0 1 0 6M16 16a3 3 0 0 1-3 3h-3a3 3 0 0 1-2-1"/>'),
|
|
10
|
-
superscript: S('<path d="
|
|
11
|
-
subscript: S('<path d="
|
|
10
|
+
superscript: S('<path d="M4 19l4.5-11L13 19M5.5 15h5.5"/><path d="M16 8h3l-3 4h3"/>'),
|
|
11
|
+
subscript: S('<path d="M4 15l4.5-11L13 15M5.5 11h5.5"/><path d="M16 15h3l-3 4h3"/>'),
|
|
12
12
|
colorIcon: S('<path d="M6 18h12M8 14l4-9 4 9M7 14h10"/><path d="M4 21h16"/>'),
|
|
13
13
|
bgIcon: S('<path d="M4 20h16M6 14l4-9 4 9M7 14h10"/>'),
|
|
14
14
|
alignLeft: S('<path d="M4 6h16M4 12h10M4 18h14"/>'),
|
|
@@ -30,6 +30,103 @@ export const ICONS = {
|
|
|
30
30
|
redo: S('<path d="M15 7l5 5-5 5M20 12H9a5 5 0 0 0 0 10"/>'),
|
|
31
31
|
clear: S('<path d="M6 6l12 12M18 6L6 18"/>'),
|
|
32
32
|
chevronDown: S('<path d="M6 9l6 6 6-6"/>'),
|
|
33
|
+
// 选项卡面板专用(紧凑图标按钮,与上面同款 stroke 风格)
|
|
34
|
+
find: S('<circle cx="10.5" cy="10.5" r="6.5"/><path d="M15.5 15.5L21 21"/>'),
|
|
35
|
+
pageSetup: S('<path d="M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2M4 7h16v12a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1z"/><path d="M8 12h8M8 16h5"/>'),
|
|
36
|
+
columns: S('<rect x="3" y="4" width="18" height="16" rx="1"/><path d="M12 4v16"/>'),
|
|
37
|
+
headerFooter: S('<rect x="3" y="4" width="18" height="16" rx="1"/><path d="M3 9h18M3 15h18"/>'),
|
|
38
|
+
footnote: S('<path d="M5 5h14M5 12h9M5 19h6M17 11v8M15 19h4"/>'),
|
|
39
|
+
comment: S('<path d="M20 15a3 3 0 0 1-3 3H8l-4 3V6a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3z"/>'),
|
|
40
|
+
toc: S('<path d="M4 6h3M4 12h3M4 18h3M11 6h9M11 12h9M11 18h9"/>'),
|
|
41
|
+
watermark: S('<path d="M4 5h16v14H4z"/><path d="M9 15l2.5-6 2.5 6M9.8 13h3.4"/>'),
|
|
42
|
+
pageNumber: S('<rect x="6" y="3" width="12" height="18" rx="1.5"/><path d="M9 18h6"/>'),
|
|
43
|
+
suggest: S('<path d="M4 20h4L19 9a2 2 0 0 0-3-3L5 17z"/><path d="M14 7l3 3"/>'),
|
|
44
|
+
accept: S('<path d="M5 13l4 4L19 7"/>'),
|
|
45
|
+
reject: S('<path d="M6 6l12 12M18 6L6 18"/>'),
|
|
46
|
+
print: S('<path d="M6 9V4h12v5M6 18H4a1 1 0 0 1-1-1v-5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v5a1 1 0 0 1-1 1h-2"/><path d="M6 15h12v5H6z"/>'),
|
|
47
|
+
export: S('<path d="M12 3v12M8 11l4 4 4-4M4 17v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3"/>'),
|
|
48
|
+
zoomIn: S('<circle cx="10.5" cy="10.5" r="6.5"/><path d="M15.5 15.5L21 21M10.5 7v7M7 10.5h7"/>'),
|
|
49
|
+
zoomOut: S('<circle cx="10.5" cy="10.5" r="6.5"/><path d="M15.5 15.5L21 21M7 10.5h7"/>'),
|
|
50
|
+
specialChars: S('<path d="M12 4v16M5 8h14M5 8c0 6 14 6 14 0"/>'),
|
|
51
|
+
bookmark: S('<path d="M6 4h12v17l-6-4-6 4z"/>'),
|
|
52
|
+
panel: S('<rect x="3" y="4" width="18" height="16" rx="1"/><path d="M15 4v16"/>'),
|
|
53
|
+
eye: S('<path d="M2.5 12S6 5.5 12 5.5 21.5 12 21.5 12 18 18.5 12 18.5 2.5 12 2.5 12z"/><circle cx="12" cy="12" r="2.8"/>'),
|
|
54
|
+
margin: S('<rect x="3" y="3" width="18" height="18" rx="1"/><rect x="8" y="8" width="8" height="8" rx="0.5"/>'),
|
|
55
|
+
zoomReset: S('<circle cx="10.5" cy="10.5" r="6.5"/><path d="M15.5 15.5L21 21M7.5 10.5h6"/>'),
|
|
56
|
+
selectAll: S('<rect x="3" y="3" width="12" height="12" rx="1"/><path d="M9 21h10a2 2 0 0 0 2-2V9"/>'),
|
|
57
|
+
|
|
58
|
+
// ---- WPS 风格功能区专用图标 ----
|
|
59
|
+
// 剪贴板
|
|
60
|
+
paste: S('<rect x="5" y="4" width="14" height="17" rx="1.5"/><path d="M9 4V3h6v1M8 9h8M8 13h8M8 17h5"/>'),
|
|
61
|
+
cut: S('<circle cx="6" cy="17" r="2.5"/><circle cx="18" cy="17" r="2.5"/><path d="M8 15L19 4M16 4L5 15"/>'),
|
|
62
|
+
copy: S('<rect x="8" y="8" width="12" height="12" rx="1.5"/><path d="M16 8V5a1.5 1.5 0 0 0-1.5-1.5H5A1.5 1.5 0 0 0 3.5 5v9.5A1.5 1.5 0 0 0 5 16h3"/>'),
|
|
63
|
+
formatPainter: S('<path d="M14 4l6 6-8 8-6-6zM6 12l-2 6 6-2M9 9l6 6"/>'),
|
|
64
|
+
// 字体
|
|
65
|
+
growFont: S('<path d="M3 18l4.5-11L12 18M4.5 14h6M18 7v8M14 11h8"/>'),
|
|
66
|
+
shrinkFont: S('<path d="M3 18l4.5-11L12 18M4.5 14h6M14 11h8"/>'),
|
|
67
|
+
eraser: S('<path d="M4 15l8-8a2 2 0 0 1 3 0l4 4a2 2 0 0 1 0 3l-7 7H8zM12 19h9"/>'),
|
|
68
|
+
highlight: S('<path d="M4 20h16M14 4l6 6-8 8-6-6zM9 15l6 6"/>'),
|
|
69
|
+
pinyin: S('<path d="M4 6h16M12 6v13M7 12l3 3M17 12l-3 3M8 19h8"/>'),
|
|
70
|
+
circleChar: S('<circle cx="12" cy="12" r="9"/><path d="M9 15l3-7 3 7M10 13h4"/>'),
|
|
71
|
+
// 段落
|
|
72
|
+
multiLevel: S('<path d="M9 6h11M9 12h11M9 18h11M4 5h1v3M4 11h2l-2 3h2M4 17h2v3H4z"/>'),
|
|
73
|
+
outdent: S('<path d="M11 6h9M11 12h9M11 18h9M3 12h6M6 9l-3 3 3 3"/>'),
|
|
74
|
+
distribute: S('<path d="M4 6h16M7 12h10M4 18h16M4 3v18M20 3v18"/>'),
|
|
75
|
+
lineSpacing: S('<path d="M4 7h10M4 12h10M4 17h10M18 5v14M15 8l3-3 3 3M15 16l3 3 3-3"/>'),
|
|
76
|
+
shading: S('<path d="M4 4h16v16H4zM4 9h16M4 14h16M9 4v16M15 4v16"/>'),
|
|
77
|
+
borders: S('<rect x="3" y="3" width="18" height="18" rx="1"/><path d="M3 12h18M12 3v18"/>'),
|
|
78
|
+
newStyle: S('<path d="M5 19h14M8 15l7-9 3 3-7 9H8zM13 8l3 3"/>'),
|
|
79
|
+
// 插入
|
|
80
|
+
coverPage: S('<rect x="5" y="3" width="14" height="18" rx="1"/><path d="M5 8h14M8 12h8M8 15h8"/>'),
|
|
81
|
+
blankPage: S('<rect x="5" y="3" width="14" height="18" rx="1"/><path d="M9 9h6v6H9z"/>'),
|
|
82
|
+
chart: S('<path d="M4 20h16M6 20V10M11 20V5M16 20v-7M21 20v-4"/>'),
|
|
83
|
+
screenshot: S('<path d="M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3M4 12h16"/>'),
|
|
84
|
+
shape: S('<circle cx="8" cy="8" r="4"/><rect x="12" y="12" width="8" height="8" rx="1"/>'),
|
|
85
|
+
iconGallery: S('<path d="M12 3l2.2 5.6L20 9l-5 4 1.5 6L12 16l-4.5 3L9 13 4 9l5.8-.4z"/>'),
|
|
86
|
+
mindMap: S('<rect x="2" y="9" width="6" height="5" rx="1"/><rect x="16" y="3" width="6" height="5" rx="1"/><rect x="16" y="15" width="6" height="5" rx="1"/><path d="M8 11h4V6h4M12 11v7h4"/>'),
|
|
87
|
+
flowChart: S('<rect x="2" y="4" width="7" height="5" rx="1"/><rect x="15" y="15" width="7" height="5" rx="1"/><path d="M9 6h4v12h2M5 9v6h10"/>'),
|
|
88
|
+
textBox: S('<rect x="3" y="5" width="18" height="14" rx="1"/><path d="M7 9h10M12 9v9M9 18h6"/>'),
|
|
89
|
+
wordArt: S('<path d="M4 18l4-11 4 11M5 14h6M14 18V7h6M14 12h5"/>'),
|
|
90
|
+
equation: S('<path d="M8 4c-2 0-3 1-3 3 0 3 6 4 6 8a3 3 0 0 1-6 0M6 11h8M17 7l4 8M21 7l-4 8"/>'),
|
|
91
|
+
insertText: S('<path d="M4 6h10M9 3v6M4 18h16M14 14h6M17 11v6"/>'),
|
|
92
|
+
object: S('<path d="M12 3l9 5v8l-9 5-9-5V8zM3 8l9 5 9-5M12 13v8"/>'),
|
|
93
|
+
date: S('<rect x="3" y="5" width="18" height="16" rx="2"/><path d="M3 10h18M8 3v4M16 3v4M8 14h3M8 17h6"/>'),
|
|
94
|
+
attachment: S('<path d="M20 11l-8 8a5 5 0 0 1-7-7l9-9a3.5 3.5 0 0 1 5 5l-9 9a2 2 0 0 1-3-3l8-8"/>'),
|
|
95
|
+
fileLink: S('<path d="M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8M14 3l6 6h-6zM13 15a3 3 0 0 1 5-2M18 13a3 3 0 0 1 1 4l-2 2a3 3 0 0 1-4 0"/>'),
|
|
96
|
+
crossReference: S('<path d="M6 4h8l4 4v12H6zM14 4v4h4M9 13h6M9 17h4M4 8v12a2 2 0 0 0 2 2"/>'),
|
|
97
|
+
// 页面布局
|
|
98
|
+
theme: S('<circle cx="12" cy="12" r="9"/><path d="M12 3a9 9 0 0 0 0 18M8 8h.01M12 6h.01M16 9h.01"/>'),
|
|
99
|
+
colors: S('<circle cx="7" cy="8" r="3"/><circle cx="16" cy="7" r="3"/><circle cx="11" cy="16" r="3"/><path d="M7 11v2a2 2 0 0 0 2 2M16 10v3a3 3 0 0 1-3 3"/>'),
|
|
100
|
+
effects: S('<path d="M5 3l1.5 4L10 9l-3.5 2L5 15l-1.5-4L0 9l3.5-2zM17 12l1 3 3 1-3 1-1 3-1-3-3-1 3-1z"/>'),
|
|
101
|
+
fontCollection: S('<path d="M3 18l4-10 4 10M4 14h6M14 18l3-8 3 8M15 15h4"/>'),
|
|
102
|
+
orientation: S('<rect x="6" y="3" width="12" height="18" rx="1"/><path d="M6 8h12M9 12h6M9 15h6"/>'),
|
|
103
|
+
paperSize: S('<rect x="4" y="3" width="16" height="18" rx="1"/><path d="M4 17h16M16 17V3"/>'),
|
|
104
|
+
textDirection: S('<path d="M12 3v18M9 6l3-3 3 3M9 18l3 3 3-3M6 9h4M6 12h3"/>'),
|
|
105
|
+
separator: S('<path d="M3 12h5M16 12h5M9 6v12M12 6v12M15 6v12"/>'),
|
|
106
|
+
lineNumbers: S('<path d="M8 4h13M8 10h13M8 16h13M3 4h.01M3 10h.01M3 16h.01"/>'),
|
|
107
|
+
background: S('<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 14l4-4 4 4 3-3 4 4 3-3"/>'),
|
|
108
|
+
pageBorder: S('<rect x="4" y="3" width="16" height="18" rx="1"/><rect x="7" y="6" width="10" height="12" rx="0.5"/>'),
|
|
109
|
+
paperSettings: S('<rect x="4" y="3" width="16" height="18" rx="1"/><path d="M4 9h16M4 15h16M10 3v18M15 3v18"/>'),
|
|
110
|
+
wrap: S('<path d="M4 6h16M4 18h16M8 10h8a3 3 0 0 1 0 6H9M8 13l-2 3 2 3"/>'),
|
|
111
|
+
alignObjects: S('<path d="M4 3v18M9 7h11M9 14h8M6 4h.01M6 20h.01"/>'),
|
|
112
|
+
groupObjects: S('<rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/><path d="M10 10l4 4M14 6h4v4M10 18H6v-4"/>'),
|
|
113
|
+
rotate: S('<path d="M20 12a8 8 0 1 1-2.3-5.6M20 4v5h-5"/>'),
|
|
114
|
+
bringForward: S('<rect x="8" y="8" width="12" height="12" rx="1"/><path d="M4 16V4h12M12 14h4M14 12v4"/>'),
|
|
115
|
+
sendBackward: S('<rect x="4" y="4" width="12" height="12" rx="1"/><path d="M20 8v12H8M10 10h4M12 8v4"/>'),
|
|
116
|
+
// 引用
|
|
117
|
+
updateToc: S('<path d="M4 6h10M4 12h7M4 18h10M18 8a4 4 0 1 1-1 5M17 5v3h3"/>'),
|
|
118
|
+
tocLevel: S('<path d="M4 6h16M6 12h14M8 18h12M4 12h.01M4 18h.01"/>'),
|
|
119
|
+
prevFootnote: S('<path d="M15 18l-6-6 6-6M8 12h8M4 4h.01M4 20h.01"/>'),
|
|
120
|
+
nextFootnote: S('<path d="M9 6l6 6-6 6M8 12h8M20 4h.01M20 20h.01"/>'),
|
|
121
|
+
insertEndnote: S('<path d="M12 4v12M8 12l4 4 4-4M5 20h14"/>'),
|
|
122
|
+
prevEndnote: S('<path d="M15 18l-6-6 6-6M8 12h8M4 20h16"/>'),
|
|
123
|
+
nextEndnote: S('<path d="M9 6l6 6-6 6M8 12h8M4 20h16"/>'),
|
|
124
|
+
footnoteSep: S('<path d="M4 6h16M4 18h16M4 12h4M16 12h4M9 12h6"/>'),
|
|
125
|
+
caption: S('<path d="M4 5h16v11H4zM8 9h8M8 13h5M4 20h10"/>'),
|
|
126
|
+
markCitation: S('<path d="M8 6c-2 0-3 1-3 3s1 3 3 3c-1 2-2 3-4 4M16 6c-2 0-3 1-3 3s1 3 3 3c-1 2-2 3-4 4"/>'),
|
|
127
|
+
insertIndex: S('<path d="M4 5h16M4 11h16M4 17h10M17 15v6M14 18h6"/>'),
|
|
128
|
+
updateIndex: S('<path d="M4 5h16M4 11h16M4 17h10M18 14a3 3 0 1 1-1 4M17 12v2h2"/>'),
|
|
129
|
+
mail: S('<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 7l9 6 9-6"/>'),
|
|
33
130
|
};
|
|
34
131
|
|
|
35
132
|
/** 取图标 SVG 串(未登记返回空串) */
|