@a200888213/gbdocx 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/app/file-io.js +122 -122
- package/src/app/main.js +9 -9
- package/src/app/word/catalog.js +52 -52
- package/src/app/word/comments.js +112 -112
- package/src/app/word/doc.js +113 -113
- package/src/app/word/edit.js +72 -72
- package/src/app/word/hf.js +76 -76
- package/src/app/word/layout.js +155 -155
- package/src/app/word/notes.js +110 -110
- package/src/app/word/shared.js +22 -22
- package/src/app/word/view.js +3 -0
- package/src/app/word-app.js +1 -0
- package/src/app/word-sheets.js +101 -101
- package/src/kernel/docx/codec/blocks.js +123 -123
- package/src/kernel/docx/codec/carry.js +129 -129
- package/src/kernel/docx/codec/comments.js +25 -25
- package/src/kernel/docx/codec/docx.js +198 -198
- package/src/kernel/docx/codec/docxStyles.js +177 -177
- package/src/kernel/docx/codec/fonts.js +195 -195
- package/src/kernel/docx/codec/helpers.js +161 -161
- package/src/kernel/docx/codec/hfHtml.js +152 -152
- package/src/kernel/docx/codec/html.js +739 -739
- package/src/kernel/docx/codec/losses.js +420 -420
- package/src/kernel/docx/codec/markdown.js +170 -170
- package/src/kernel/docx/codec/parts.js +249 -249
- package/src/kernel/docx/codec/read.js +603 -603
- package/src/kernel/docx/codec/render.js +1156 -1156
- package/src/kernel/docx/codec/roundtrip.js +236 -236
- package/src/kernel/docx/codec/write.js +833 -833
- package/src/kernel/docx/comments.js +14 -14
- package/src/kernel/docx/pageGeometry.js +123 -123
- package/src/kernel/docx/pagination.js +481 -481
- package/src/kernel/docx/watermark.js +45 -45
- package/src/kernel/editor/constants.js +8 -8
- package/src/kernel/editor/engine/blocks.js +594 -594
- package/src/kernel/editor/engine/blocksEnter.js +109 -109
- package/src/kernel/editor/engine/blocksInsert.js +254 -254
- package/src/kernel/editor/engine/blocksStructure.js +226 -226
- package/src/kernel/editor/engine/commands.js +181 -181
- package/src/kernel/editor/engine/dom.js +646 -646
- package/src/kernel/editor/engine/history.js +149 -149
- package/src/kernel/editor/engine/inline.js +656 -656
- package/src/kernel/editor/engine/input.js +554 -554
- package/src/kernel/editor/engine/interaction.js +137 -137
- package/src/kernel/editor/engine/pointer.js +39 -39
- package/src/kernel/editor/engine/revision.js +138 -138
- package/src/kernel/editor/engine/schema.js +417 -417
- package/src/kernel/editor/engine/selection.js +119 -119
- package/src/kernel/editor/engine/state.js +118 -118
- package/src/kernel/editor/engine/tableClip.js +154 -154
- package/src/kernel/editor/engine/tableGrid.js +55 -55
- package/src/kernel/editor/engine/tableInteraction.js +388 -388
- package/src/kernel/editor/engine/tableMenu.js +250 -250
- package/src/kernel/editor/engine/tableOps.js +174 -174
- package/src/kernel/editor/engine/tables.js +732 -732
- package/src/kernel/editor/overlayGeometry.js +20 -20
- package/src/kernel/editor/utils.js +48 -48
- package/src/kernel/keyboard.js +114 -114
- package/src/kernel/textStyles.js +84 -84
- package/src/kernel/util/imageFile.js +91 -91
- package/src/kernel/util/shortcutKey.js +33 -33
- package/src/surface/editor-surface.js +600 -600
- package/src/ui/color-panel.js +69 -69
- package/src/ui/context-menu.js +133 -133
- package/src/ui/find-bar.js +151 -151
- package/src/ui/menubar.js +28 -28
- package/src/ui/panels.js +115 -115
- package/src/ui/prompt.js +89 -89
- package/src/ui/ribbon.js +485 -485
- package/src/ui/special-chars.js +39 -39
- package/src/ui/statusbar.js +81 -81
- package/src/ui/toolbar.js +32 -32
- package/styles/editor-content.css +440 -440
- package/styles/tokens.css +154 -154
- package/styles/word-panel.css +1 -1
package/src/ui/color-panel.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
// [文件] gbdocx·ColorPanel —— 文字颜色/底色色板(预设格里 + 系统色轮 + Hex + 清除)
|
|
2
|
-
import { openPopup } from './popup.js';
|
|
3
|
-
|
|
4
|
-
/** 打开色板;onPick(color) 回调(清除传空串) */
|
|
5
|
-
export function openColorPanel({ anchor, colors, value, title, columns = 10, onPick }) {
|
|
6
|
-
const box = document.createElement('div');
|
|
7
|
-
box.className = 'gbd-color';
|
|
8
|
-
const head = document.createElement('div');
|
|
9
|
-
head.className = 'gbd-color__title';
|
|
10
|
-
head.textContent = title || '颜色';
|
|
11
|
-
box.appendChild(head);
|
|
12
|
-
|
|
13
|
-
const grid = document.createElement('div');
|
|
14
|
-
grid.className = 'gbd-color__grid';
|
|
15
|
-
grid.style.gridTemplateColumns = `repeat(${columns}, 18px)`;
|
|
16
|
-
for (const color of colors) {
|
|
17
|
-
const sw = document.createElement('button');
|
|
18
|
-
sw.type = 'button';
|
|
19
|
-
sw.className = 'gbd-color__swatch';
|
|
20
|
-
sw.style.background = color;
|
|
21
|
-
if (value && value.toLowerCase() === color.toLowerCase()) sw.classList.add('gbd-is-active');
|
|
22
|
-
sw.title = color;
|
|
23
|
-
sw.addEventListener('click', () => {
|
|
24
|
-
handle.close();
|
|
25
|
-
onPick(color);
|
|
26
|
-
});
|
|
27
|
-
grid.appendChild(sw);
|
|
28
|
-
}
|
|
29
|
-
box.appendChild(grid);
|
|
30
|
-
|
|
31
|
-
const custom = document.createElement('div');
|
|
32
|
-
custom.className = 'gbd-color__custom';
|
|
33
|
-
const wheel = document.createElement('input');
|
|
34
|
-
wheel.type = 'color';
|
|
35
|
-
wheel.value = /^#[0-9a-f]{6}$/i.test(value || '') ? value : '#000000';
|
|
36
|
-
const hex = document.createElement('input');
|
|
37
|
-
hex.type = 'text';
|
|
38
|
-
hex.className = 'gbd-color__hex';
|
|
39
|
-
hex.value = value || '';
|
|
40
|
-
hex.placeholder = '#rrggbb';
|
|
41
|
-
wheel.addEventListener('input', () => { hex.value = wheel.value; });
|
|
42
|
-
custom.append(wheel, hex);
|
|
43
|
-
box.appendChild(custom);
|
|
44
|
-
|
|
45
|
-
const actions = document.createElement('div');
|
|
46
|
-
actions.className = 'gbd-color__actions';
|
|
47
|
-
const apply = document.createElement('button');
|
|
48
|
-
apply.type = 'button';
|
|
49
|
-
apply.className = 'gbd-btn gbd-btn--primary';
|
|
50
|
-
apply.textContent = '应用';
|
|
51
|
-
const clear = document.createElement('button');
|
|
52
|
-
clear.type = 'button';
|
|
53
|
-
clear.className = 'gbd-btn';
|
|
54
|
-
clear.textContent = '清除';
|
|
55
|
-
apply.addEventListener('click', () => {
|
|
56
|
-
const v = (hex.value || '').trim();
|
|
57
|
-
handle.close();
|
|
58
|
-
onPick(/^#?[0-9a-f]{6}$/i.test(v) ? (v.startsWith('#') ? v : `#${v}`) : '');
|
|
59
|
-
});
|
|
60
|
-
clear.addEventListener('click', () => {
|
|
61
|
-
handle.close();
|
|
62
|
-
onPick('');
|
|
63
|
-
});
|
|
64
|
-
actions.append(apply, clear);
|
|
65
|
-
box.appendChild(actions);
|
|
66
|
-
|
|
67
|
-
const handle = openPopup({ anchor, content: box, placement: 'bottom-start', className: 'gbd-popup--color' });
|
|
68
|
-
return handle;
|
|
69
|
-
}
|
|
1
|
+
// [文件] gbdocx·ColorPanel —— 文字颜色/底色色板(预设格里 + 系统色轮 + Hex + 清除)
|
|
2
|
+
import { openPopup } from './popup.js';
|
|
3
|
+
|
|
4
|
+
/** 打开色板;onPick(color) 回调(清除传空串) */
|
|
5
|
+
export function openColorPanel({ anchor, colors, value, title, columns = 10, onPick }) {
|
|
6
|
+
const box = document.createElement('div');
|
|
7
|
+
box.className = 'gbd-color';
|
|
8
|
+
const head = document.createElement('div');
|
|
9
|
+
head.className = 'gbd-color__title';
|
|
10
|
+
head.textContent = title || '颜色';
|
|
11
|
+
box.appendChild(head);
|
|
12
|
+
|
|
13
|
+
const grid = document.createElement('div');
|
|
14
|
+
grid.className = 'gbd-color__grid';
|
|
15
|
+
grid.style.gridTemplateColumns = `repeat(${columns}, 18px)`;
|
|
16
|
+
for (const color of colors) {
|
|
17
|
+
const sw = document.createElement('button');
|
|
18
|
+
sw.type = 'button';
|
|
19
|
+
sw.className = 'gbd-color__swatch';
|
|
20
|
+
sw.style.background = color;
|
|
21
|
+
if (value && value.toLowerCase() === color.toLowerCase()) sw.classList.add('gbd-is-active');
|
|
22
|
+
sw.title = color;
|
|
23
|
+
sw.addEventListener('click', () => {
|
|
24
|
+
handle.close();
|
|
25
|
+
onPick(color);
|
|
26
|
+
});
|
|
27
|
+
grid.appendChild(sw);
|
|
28
|
+
}
|
|
29
|
+
box.appendChild(grid);
|
|
30
|
+
|
|
31
|
+
const custom = document.createElement('div');
|
|
32
|
+
custom.className = 'gbd-color__custom';
|
|
33
|
+
const wheel = document.createElement('input');
|
|
34
|
+
wheel.type = 'color';
|
|
35
|
+
wheel.value = /^#[0-9a-f]{6}$/i.test(value || '') ? value : '#000000';
|
|
36
|
+
const hex = document.createElement('input');
|
|
37
|
+
hex.type = 'text';
|
|
38
|
+
hex.className = 'gbd-color__hex';
|
|
39
|
+
hex.value = value || '';
|
|
40
|
+
hex.placeholder = '#rrggbb';
|
|
41
|
+
wheel.addEventListener('input', () => { hex.value = wheel.value; });
|
|
42
|
+
custom.append(wheel, hex);
|
|
43
|
+
box.appendChild(custom);
|
|
44
|
+
|
|
45
|
+
const actions = document.createElement('div');
|
|
46
|
+
actions.className = 'gbd-color__actions';
|
|
47
|
+
const apply = document.createElement('button');
|
|
48
|
+
apply.type = 'button';
|
|
49
|
+
apply.className = 'gbd-btn gbd-btn--primary';
|
|
50
|
+
apply.textContent = '应用';
|
|
51
|
+
const clear = document.createElement('button');
|
|
52
|
+
clear.type = 'button';
|
|
53
|
+
clear.className = 'gbd-btn';
|
|
54
|
+
clear.textContent = '清除';
|
|
55
|
+
apply.addEventListener('click', () => {
|
|
56
|
+
const v = (hex.value || '').trim();
|
|
57
|
+
handle.close();
|
|
58
|
+
onPick(/^#?[0-9a-f]{6}$/i.test(v) ? (v.startsWith('#') ? v : `#${v}`) : '');
|
|
59
|
+
});
|
|
60
|
+
clear.addEventListener('click', () => {
|
|
61
|
+
handle.close();
|
|
62
|
+
onPick('');
|
|
63
|
+
});
|
|
64
|
+
actions.append(apply, clear);
|
|
65
|
+
box.appendChild(actions);
|
|
66
|
+
|
|
67
|
+
const handle = openPopup({ anchor, content: box, placement: 'bottom-start', className: 'gbd-popup--color' });
|
|
68
|
+
return handle;
|
|
69
|
+
}
|
package/src/ui/context-menu.js
CHANGED
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
// [文件] gbdocx·ContextMenu —— 右键/下拉菜单渲染(条目口径:label/icon/disabled/checked/colorDot/shortcut/divided/children/input/onClick)
|
|
2
|
-
import { openPopup } from './popup.js';
|
|
3
|
-
import { icon } from './icons.js';
|
|
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>';
|
|
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>';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 打开菜单
|
|
10
|
-
* @param {object} opts
|
|
11
|
-
* @param {HTMLElement|DOMRect} opts.anchor
|
|
12
|
-
* @param {Array<object>} opts.items 条目表
|
|
13
|
-
* @param {string} [opts.placement]
|
|
14
|
-
* @param {() => void} [opts.onClose] 关闭回调(父菜单据此同步按钮态)
|
|
15
|
-
*/
|
|
16
|
-
export function openMenu({ anchor, items, placement = 'bottom-start', onClose }) {
|
|
17
|
-
const body = buildList(items);
|
|
18
|
-
return openPopup({
|
|
19
|
-
anchor,
|
|
20
|
-
content: body,
|
|
21
|
-
placement,
|
|
22
|
-
className: 'gbd-menu',
|
|
23
|
-
// 子菜单是独立浮层:既不能算作「点在外面」把父菜单关掉,父菜单关闭时也要把它一起收
|
|
24
|
-
isInside: (target) => Boolean(target?.closest?.('.gbd-menu--sub')),
|
|
25
|
-
onClose: () => {
|
|
26
|
-
body.__closeSub?.();
|
|
27
|
-
onClose?.();
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** 构建条目列表 DOM(子菜单在 hover 时另开浮层) */
|
|
33
|
-
function buildList(items) {
|
|
34
|
-
const ul = document.createElement('div');
|
|
35
|
-
ul.className = 'gbd-menu__list';
|
|
36
|
-
let subHandle = null;
|
|
37
|
-
const closeSub = () => {
|
|
38
|
-
subHandle?.close();
|
|
39
|
-
subHandle = null;
|
|
40
|
-
};
|
|
41
|
-
// 父级浮层关闭时由 openMenu 回调这里,把子菜单一起收走
|
|
42
|
-
ul.__closeSub = closeSub;
|
|
43
|
-
for (const item of items || []) {
|
|
44
|
-
// divided 有两种用法:裸分隔标记(只有 divided)与「本项之前画分隔线」(真实条目带 label)。
|
|
45
|
-
// 后者不能 continue,否则每个分组的首项(如表格菜单的「全选 / 删除表格」)都会被吞成一条分隔线。
|
|
46
|
-
if (item.divided) {
|
|
47
|
-
const sep = document.createElement('div');
|
|
48
|
-
sep.className = 'gbd-menu__sep';
|
|
49
|
-
ul.appendChild(sep);
|
|
50
|
-
if (!item.label) continue;
|
|
51
|
-
}
|
|
52
|
-
const row = document.createElement('div');
|
|
53
|
-
row.className = 'gbd-menu__item';
|
|
54
|
-
if (item.disabled) row.classList.add('gbd-is-disabled');
|
|
55
|
-
if (item.danger) row.classList.add('gbd-is-danger');
|
|
56
|
-
|
|
57
|
-
const lead = document.createElement('span');
|
|
58
|
-
lead.className = 'gbd-menu__lead';
|
|
59
|
-
if (item.checked) lead.innerHTML = CHECK;
|
|
60
|
-
else if (item.colorDot) {
|
|
61
|
-
lead.innerHTML = `<i class="gbd-menu__dot" style="background:${item.colorDot}"></i>`;
|
|
62
|
-
} else if (item.icon) {
|
|
63
|
-
lead.innerHTML = icon(item.icon);
|
|
64
|
-
}
|
|
65
|
-
row.appendChild(lead);
|
|
66
|
-
|
|
67
|
-
const label = document.createElement('span');
|
|
68
|
-
label.className = 'gbd-menu__label';
|
|
69
|
-
label.textContent = item.label;
|
|
70
|
-
row.appendChild(label);
|
|
71
|
-
|
|
72
|
-
let inputEl = null;
|
|
73
|
-
if (item.input && !item.disabled) {
|
|
74
|
-
const box = document.createElement('span');
|
|
75
|
-
box.className = 'gbd-menu__input';
|
|
76
|
-
inputEl = document.createElement('input');
|
|
77
|
-
inputEl.type = 'number';
|
|
78
|
-
inputEl.min = item.input.min;
|
|
79
|
-
inputEl.max = item.input.max;
|
|
80
|
-
inputEl.value = item.input.defaultValue;
|
|
81
|
-
inputEl.addEventListener('mousedown', (e) => e.stopPropagation());
|
|
82
|
-
box.appendChild(inputEl);
|
|
83
|
-
if (item.input.unit) {
|
|
84
|
-
const unit = document.createElement('span');
|
|
85
|
-
unit.className = 'gbd-menu__unit';
|
|
86
|
-
unit.textContent = item.input.unit;
|
|
87
|
-
box.appendChild(unit);
|
|
88
|
-
}
|
|
89
|
-
row.appendChild(box);
|
|
90
|
-
} else if (item.shortcut) {
|
|
91
|
-
const sc = document.createElement('span');
|
|
92
|
-
sc.className = 'gbd-menu__shortcut';
|
|
93
|
-
sc.textContent = item.shortcut;
|
|
94
|
-
row.appendChild(sc);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (item.children) {
|
|
98
|
-
const arrow = document.createElement('span');
|
|
99
|
-
arrow.className = 'gbd-menu__arrow';
|
|
100
|
-
arrow.innerHTML = SUB;
|
|
101
|
-
row.appendChild(arrow);
|
|
102
|
-
let openTimer = 0;
|
|
103
|
-
row.addEventListener('mouseenter', () => {
|
|
104
|
-
clearTimeout(openTimer);
|
|
105
|
-
openTimer = setTimeout(() => {
|
|
106
|
-
closeSub();
|
|
107
|
-
if (item.disabled) return;
|
|
108
|
-
const subBody = buildList(item.children);
|
|
109
|
-
subHandle = openPopup({
|
|
110
|
-
anchor: row.getBoundingClientRect(),
|
|
111
|
-
content: subBody,
|
|
112
|
-
placement: 'right-start',
|
|
113
|
-
className: 'gbd-menu gbd-menu--sub',
|
|
114
|
-
// 子级浮层:不能走 closeAll 把父菜单一起关掉
|
|
115
|
-
nested: true,
|
|
116
|
-
onClose: () => subBody.__closeSub?.(),
|
|
117
|
-
});
|
|
118
|
-
}, 60);
|
|
119
|
-
});
|
|
120
|
-
row.addEventListener('mouseleave', () => clearTimeout(openTimer));
|
|
121
|
-
} else {
|
|
122
|
-
row.addEventListener('click', (e) => {
|
|
123
|
-
if (item.disabled) return;
|
|
124
|
-
const value = inputEl ? Number(inputEl.value) : undefined;
|
|
125
|
-
item.onClick?.(e, value);
|
|
126
|
-
// 关闭整串菜单(含父级)
|
|
127
|
-
document.dispatchEvent(new CustomEvent('gbdocx-menu-close'));
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
ul.appendChild(row);
|
|
131
|
-
}
|
|
132
|
-
return ul;
|
|
133
|
-
}
|
|
1
|
+
// [文件] gbdocx·ContextMenu —— 右键/下拉菜单渲染(条目口径:label/icon/disabled/checked/colorDot/shortcut/divided/children/input/onClick)
|
|
2
|
+
import { openPopup } from './popup.js';
|
|
3
|
+
import { icon } from './icons.js';
|
|
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>';
|
|
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>';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 打开菜单
|
|
10
|
+
* @param {object} opts
|
|
11
|
+
* @param {HTMLElement|DOMRect} opts.anchor
|
|
12
|
+
* @param {Array<object>} opts.items 条目表
|
|
13
|
+
* @param {string} [opts.placement]
|
|
14
|
+
* @param {() => void} [opts.onClose] 关闭回调(父菜单据此同步按钮态)
|
|
15
|
+
*/
|
|
16
|
+
export function openMenu({ anchor, items, placement = 'bottom-start', onClose }) {
|
|
17
|
+
const body = buildList(items);
|
|
18
|
+
return openPopup({
|
|
19
|
+
anchor,
|
|
20
|
+
content: body,
|
|
21
|
+
placement,
|
|
22
|
+
className: 'gbd-menu',
|
|
23
|
+
// 子菜单是独立浮层:既不能算作「点在外面」把父菜单关掉,父菜单关闭时也要把它一起收
|
|
24
|
+
isInside: (target) => Boolean(target?.closest?.('.gbd-menu--sub')),
|
|
25
|
+
onClose: () => {
|
|
26
|
+
body.__closeSub?.();
|
|
27
|
+
onClose?.();
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 构建条目列表 DOM(子菜单在 hover 时另开浮层) */
|
|
33
|
+
function buildList(items) {
|
|
34
|
+
const ul = document.createElement('div');
|
|
35
|
+
ul.className = 'gbd-menu__list';
|
|
36
|
+
let subHandle = null;
|
|
37
|
+
const closeSub = () => {
|
|
38
|
+
subHandle?.close();
|
|
39
|
+
subHandle = null;
|
|
40
|
+
};
|
|
41
|
+
// 父级浮层关闭时由 openMenu 回调这里,把子菜单一起收走
|
|
42
|
+
ul.__closeSub = closeSub;
|
|
43
|
+
for (const item of items || []) {
|
|
44
|
+
// divided 有两种用法:裸分隔标记(只有 divided)与「本项之前画分隔线」(真实条目带 label)。
|
|
45
|
+
// 后者不能 continue,否则每个分组的首项(如表格菜单的「全选 / 删除表格」)都会被吞成一条分隔线。
|
|
46
|
+
if (item.divided) {
|
|
47
|
+
const sep = document.createElement('div');
|
|
48
|
+
sep.className = 'gbd-menu__sep';
|
|
49
|
+
ul.appendChild(sep);
|
|
50
|
+
if (!item.label) continue;
|
|
51
|
+
}
|
|
52
|
+
const row = document.createElement('div');
|
|
53
|
+
row.className = 'gbd-menu__item';
|
|
54
|
+
if (item.disabled) row.classList.add('gbd-is-disabled');
|
|
55
|
+
if (item.danger) row.classList.add('gbd-is-danger');
|
|
56
|
+
|
|
57
|
+
const lead = document.createElement('span');
|
|
58
|
+
lead.className = 'gbd-menu__lead';
|
|
59
|
+
if (item.checked) lead.innerHTML = CHECK;
|
|
60
|
+
else if (item.colorDot) {
|
|
61
|
+
lead.innerHTML = `<i class="gbd-menu__dot" style="background:${item.colorDot}"></i>`;
|
|
62
|
+
} else if (item.icon) {
|
|
63
|
+
lead.innerHTML = icon(item.icon);
|
|
64
|
+
}
|
|
65
|
+
row.appendChild(lead);
|
|
66
|
+
|
|
67
|
+
const label = document.createElement('span');
|
|
68
|
+
label.className = 'gbd-menu__label';
|
|
69
|
+
label.textContent = item.label;
|
|
70
|
+
row.appendChild(label);
|
|
71
|
+
|
|
72
|
+
let inputEl = null;
|
|
73
|
+
if (item.input && !item.disabled) {
|
|
74
|
+
const box = document.createElement('span');
|
|
75
|
+
box.className = 'gbd-menu__input';
|
|
76
|
+
inputEl = document.createElement('input');
|
|
77
|
+
inputEl.type = 'number';
|
|
78
|
+
inputEl.min = item.input.min;
|
|
79
|
+
inputEl.max = item.input.max;
|
|
80
|
+
inputEl.value = item.input.defaultValue;
|
|
81
|
+
inputEl.addEventListener('mousedown', (e) => e.stopPropagation());
|
|
82
|
+
box.appendChild(inputEl);
|
|
83
|
+
if (item.input.unit) {
|
|
84
|
+
const unit = document.createElement('span');
|
|
85
|
+
unit.className = 'gbd-menu__unit';
|
|
86
|
+
unit.textContent = item.input.unit;
|
|
87
|
+
box.appendChild(unit);
|
|
88
|
+
}
|
|
89
|
+
row.appendChild(box);
|
|
90
|
+
} else if (item.shortcut) {
|
|
91
|
+
const sc = document.createElement('span');
|
|
92
|
+
sc.className = 'gbd-menu__shortcut';
|
|
93
|
+
sc.textContent = item.shortcut;
|
|
94
|
+
row.appendChild(sc);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (item.children) {
|
|
98
|
+
const arrow = document.createElement('span');
|
|
99
|
+
arrow.className = 'gbd-menu__arrow';
|
|
100
|
+
arrow.innerHTML = SUB;
|
|
101
|
+
row.appendChild(arrow);
|
|
102
|
+
let openTimer = 0;
|
|
103
|
+
row.addEventListener('mouseenter', () => {
|
|
104
|
+
clearTimeout(openTimer);
|
|
105
|
+
openTimer = setTimeout(() => {
|
|
106
|
+
closeSub();
|
|
107
|
+
if (item.disabled) return;
|
|
108
|
+
const subBody = buildList(item.children);
|
|
109
|
+
subHandle = openPopup({
|
|
110
|
+
anchor: row.getBoundingClientRect(),
|
|
111
|
+
content: subBody,
|
|
112
|
+
placement: 'right-start',
|
|
113
|
+
className: 'gbd-menu gbd-menu--sub',
|
|
114
|
+
// 子级浮层:不能走 closeAll 把父菜单一起关掉
|
|
115
|
+
nested: true,
|
|
116
|
+
onClose: () => subBody.__closeSub?.(),
|
|
117
|
+
});
|
|
118
|
+
}, 60);
|
|
119
|
+
});
|
|
120
|
+
row.addEventListener('mouseleave', () => clearTimeout(openTimer));
|
|
121
|
+
} else {
|
|
122
|
+
row.addEventListener('click', (e) => {
|
|
123
|
+
if (item.disabled) return;
|
|
124
|
+
const value = inputEl ? Number(inputEl.value) : undefined;
|
|
125
|
+
item.onClick?.(e, value);
|
|
126
|
+
// 关闭整串菜单(含父级)
|
|
127
|
+
document.dispatchEvent(new CustomEvent('gbdocx-menu-close'));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
ul.appendChild(row);
|
|
131
|
+
}
|
|
132
|
+
return ul;
|
|
133
|
+
}
|