@a200888213/gbdocx 0.3.0 → 0.4.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 +3 -2
- package/index.html +2 -1
- package/package.json +2 -1
- 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/view.js +30 -1
- package/src/app/word-app.js +30 -11
- 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/icons.js +100 -2
- package/src/ui/ribbon.js +485 -0
- package/src/ui/toolbar.js +2 -169
- package/styles/app.css +116 -116
- package/styles/tokens.css +5 -5
- package/styles/word-panel.css +9 -49
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,104 @@ 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
|
+
showMarks: S('<path d="M8 4v13a3 3 0 1 1-3-3M4 14h4M12 6h9M12 12h7M12 18h9"/>'),
|
|
75
|
+
distribute: S('<path d="M4 6h16M7 12h10M4 18h16M4 3v18M20 3v18"/>'),
|
|
76
|
+
lineSpacing: S('<path d="M4 7h10M4 12h10M4 17h10M18 5v14M15 8l3-3 3 3M15 16l3 3 3-3"/>'),
|
|
77
|
+
shading: S('<path d="M4 4h16v16H4zM4 9h16M4 14h16M9 4v16M15 4v16"/>'),
|
|
78
|
+
borders: S('<rect x="3" y="3" width="18" height="18" rx="1"/><path d="M3 12h18M12 3v18"/>'),
|
|
79
|
+
newStyle: S('<path d="M5 19h14M8 15l7-9 3 3-7 9H8zM13 8l3 3"/>'),
|
|
80
|
+
// 插入
|
|
81
|
+
coverPage: S('<rect x="5" y="3" width="14" height="18" rx="1"/><path d="M5 8h14M8 12h8M8 15h8"/>'),
|
|
82
|
+
blankPage: S('<rect x="5" y="3" width="14" height="18" rx="1"/><path d="M9 9h6v6H9z"/>'),
|
|
83
|
+
chart: S('<path d="M4 20h16M6 20V10M11 20V5M16 20v-7M21 20v-4"/>'),
|
|
84
|
+
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"/>'),
|
|
85
|
+
shape: S('<circle cx="8" cy="8" r="4"/><rect x="12" y="12" width="8" height="8" rx="1"/>'),
|
|
86
|
+
iconGallery: S('<path d="M12 3l2.2 5.6L20 9l-5 4 1.5 6L12 16l-4.5 3L9 13 4 9l5.8-.4z"/>'),
|
|
87
|
+
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"/>'),
|
|
88
|
+
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"/>'),
|
|
89
|
+
textBox: S('<rect x="3" y="5" width="18" height="14" rx="1"/><path d="M7 9h10M12 9v9M9 18h6"/>'),
|
|
90
|
+
wordArt: S('<path d="M4 18l4-11 4 11M5 14h6M14 18V7h6M14 12h5"/>'),
|
|
91
|
+
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"/>'),
|
|
92
|
+
insertText: S('<path d="M4 6h10M9 3v6M4 18h16M14 14h6M17 11v6"/>'),
|
|
93
|
+
object: S('<path d="M12 3l9 5v8l-9 5-9-5V8zM3 8l9 5 9-5M12 13v8"/>'),
|
|
94
|
+
date: S('<rect x="3" y="5" width="18" height="16" rx="2"/><path d="M3 10h18M8 3v4M16 3v4M8 14h3M8 17h6"/>'),
|
|
95
|
+
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"/>'),
|
|
96
|
+
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"/>'),
|
|
97
|
+
crossReference: S('<path d="M6 4h8l4 4v12H6zM14 4v4h4M9 13h6M9 17h4M4 8v12a2 2 0 0 0 2 2"/>'),
|
|
98
|
+
// 页面布局
|
|
99
|
+
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"/>'),
|
|
100
|
+
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"/>'),
|
|
101
|
+
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"/>'),
|
|
102
|
+
fontCollection: S('<path d="M3 18l4-10 4 10M4 14h6M14 18l3-8 3 8M15 15h4"/>'),
|
|
103
|
+
orientation: S('<rect x="6" y="3" width="12" height="18" rx="1"/><path d="M6 8h12M9 12h6M9 15h6"/>'),
|
|
104
|
+
paperSize: S('<rect x="4" y="3" width="16" height="18" rx="1"/><path d="M4 17h16M16 17V3"/>'),
|
|
105
|
+
textDirection: S('<path d="M12 3v18M9 6l3-3 3 3M9 18l3 3 3-3M6 9h4M6 12h3"/>'),
|
|
106
|
+
separator: S('<path d="M3 12h5M16 12h5M9 6v12M12 6v12M15 6v12"/>'),
|
|
107
|
+
lineNumbers: S('<path d="M8 4h13M8 10h13M8 16h13M3 4h.01M3 10h.01M3 16h.01"/>'),
|
|
108
|
+
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"/>'),
|
|
109
|
+
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"/>'),
|
|
110
|
+
paperSettings: S('<rect x="4" y="3" width="16" height="18" rx="1"/><path d="M4 9h16M4 15h16M10 3v18M15 3v18"/>'),
|
|
111
|
+
wrap: S('<path d="M4 6h16M4 18h16M8 10h8a3 3 0 0 1 0 6H9M8 13l-2 3 2 3"/>'),
|
|
112
|
+
alignObjects: S('<path d="M4 3v18M9 7h11M9 14h8M6 4h.01M6 20h.01"/>'),
|
|
113
|
+
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"/>'),
|
|
114
|
+
rotate: S('<path d="M20 12a8 8 0 1 1-2.3-5.6M20 4v5h-5"/>'),
|
|
115
|
+
bringForward: S('<rect x="8" y="8" width="12" height="12" rx="1"/><path d="M4 16V4h12M12 14h4M14 12v4"/>'),
|
|
116
|
+
sendBackward: S('<rect x="4" y="4" width="12" height="12" rx="1"/><path d="M20 8v12H8M10 10h4M12 8v4"/>'),
|
|
117
|
+
// 引用
|
|
118
|
+
updateToc: S('<path d="M4 6h10M4 12h7M4 18h10M18 8a4 4 0 1 1-1 5M17 5v3h3"/>'),
|
|
119
|
+
tocLevel: S('<path d="M4 6h16M6 12h14M8 18h12M4 12h.01M4 18h.01"/>'),
|
|
120
|
+
prevFootnote: S('<path d="M15 18l-6-6 6-6M8 12h8M4 4h.01M4 20h.01"/>'),
|
|
121
|
+
nextFootnote: S('<path d="M9 6l6 6-6 6M8 12h8M20 4h.01M20 20h.01"/>'),
|
|
122
|
+
insertEndnote: S('<path d="M12 4v12M8 12l4 4 4-4M5 20h14"/>'),
|
|
123
|
+
prevEndnote: S('<path d="M15 18l-6-6 6-6M8 12h8M4 20h16"/>'),
|
|
124
|
+
nextEndnote: S('<path d="M9 6l6 6-6 6M8 12h8M4 20h16"/>'),
|
|
125
|
+
footnoteSep: S('<path d="M4 6h16M4 18h16M4 12h4M16 12h4M9 12h6"/>'),
|
|
126
|
+
caption: S('<path d="M4 5h16v11H4zM8 9h8M8 13h5M4 20h10"/>'),
|
|
127
|
+
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"/>'),
|
|
128
|
+
insertIndex: S('<path d="M4 5h16M4 11h16M4 17h10M17 15v6M14 18h6"/>'),
|
|
129
|
+
updateIndex: S('<path d="M4 5h16M4 11h16M4 17h10M18 14a3 3 0 1 1-1 4M17 12v2h2"/>'),
|
|
130
|
+
mail: S('<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 7l9 6 9-6"/>'),
|
|
33
131
|
};
|
|
34
132
|
|
|
35
133
|
/** 取图标 SVG 串(未登记返回空串) */
|
package/src/ui/ribbon.js
ADDED
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
// [文件] gbdocx·Ribbon —— WPS 风格选项卡栏(开始/插入/页面布局/引用/审阅/视图/章节/开发工具/特色功能/查找)
|
|
2
|
+
//
|
|
3
|
+
// [设计] 只装配功能区(选项卡 + 分组按钮),菜单栏/文件头/状态栏的结构与行为不动;
|
|
4
|
+
// 视觉密度、分组节奏与按钮尺寸统一由 app.css 的 ribbon 段控制。
|
|
5
|
+
// 「开始」页的分类与按钮顺序照 WPS 还原(剪贴板/字体/段落/样式);其余页同理解构。
|
|
6
|
+
// 本模块是纯装配:按钮只声明「调哪个命令/哪个 ctx 动作」,不含编辑逻辑。
|
|
7
|
+
// 编辑器命令走 io.run(内部挡只读);应用动作走 menuCtx(只读档已短路写操作)。
|
|
8
|
+
// 没接入的能力不摆按钮:占位按钮点了只会提示「暂未接入」,等于假入口。
|
|
9
|
+
import { icon } from './icons.js';
|
|
10
|
+
import { openMenu } from './context-menu.js';
|
|
11
|
+
import { makeSelect } from './toolbar.js';
|
|
12
|
+
import { HF_MODES, PAGE_NUMBER_ALIGNS } from '../kernel/docx/constants.js';
|
|
13
|
+
import { FONT_FAMILIES, FONT_SIZES, TEXT_COLORS, BG_COLORS } from '../kernel/textStyles.js';
|
|
14
|
+
|
|
15
|
+
/** 选项卡顺序即 WPS 截图顺序 */
|
|
16
|
+
const TABS = [
|
|
17
|
+
{ key: 'home', label: '开始' },
|
|
18
|
+
{ key: 'insert', label: '插入' },
|
|
19
|
+
{ key: 'layout', label: '页面布局' },
|
|
20
|
+
{ key: 'reference', label: '引用' },
|
|
21
|
+
{ key: 'review', label: '审阅' },
|
|
22
|
+
{ key: 'view', label: '视图' },
|
|
23
|
+
{ key: 'chapter', label: '章节' },
|
|
24
|
+
{ key: 'developer', label: '开发工具' },
|
|
25
|
+
{ key: 'feature', label: '特色功能' },
|
|
26
|
+
{ key: 'find', label: '查找', icon: 'find' },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/* ============ 描述符构造(纯数据,供渲染器消费) ============ */
|
|
30
|
+
|
|
31
|
+
/** 大按钮:图标在上、文字在下,WPS 功能区主按钮 */
|
|
32
|
+
const big = (iconName, title, onClick, opts = {}) => ({ kind: 'big', iconName, title, onClick, ...opts });
|
|
33
|
+
/** 小按钮:单行图标+文字(如 B/I/U、对齐、项目符号) */
|
|
34
|
+
const small = (iconName, title, onClick, opts = {}) => ({ kind: 'small', iconName, title, onClick, ...opts });
|
|
35
|
+
/** 下拉按钮:点击弹 menu;items 每次打开现求值 */
|
|
36
|
+
const menu = (iconName, title, items, opts = {}) => ({ kind: 'menu', iconName, title, items, ...opts });
|
|
37
|
+
/** 分组:带底部组名(剪贴板/字体/段落/样式…) */
|
|
38
|
+
const group = (title, ...items) => ({ kind: 'group', title, items });
|
|
39
|
+
/** 横向一排按钮(字体组内 B I U 一行) */
|
|
40
|
+
const row = (...items) => ({ kind: 'row', items });
|
|
41
|
+
/** 竖向堆叠若干行(一个分组里多行) */
|
|
42
|
+
const stack = (...rows) => ({ kind: 'stack', items: rows });
|
|
43
|
+
/** 样式卡片(样式名按自身字号预览,如 WPS 样式库);blockType 用于点亮当前段落样式 */
|
|
44
|
+
const styleCard = (preview, name, onClick, previewClass, blockType) => ({
|
|
45
|
+
kind: 'style', preview, name, onClick, previewClass,
|
|
46
|
+
active: blockType ? (s) => s.blockType === blockType : null,
|
|
47
|
+
});
|
|
48
|
+
/** 下拉选择框 */
|
|
49
|
+
const select = (spec) => ({ kind: 'select', spec });
|
|
50
|
+
|
|
51
|
+
/* ============ 渲染 ============ */
|
|
52
|
+
|
|
53
|
+
/** 收集按钮激活态求值器,refresh 时按现取状态统一点亮 */
|
|
54
|
+
class PanelContext {
|
|
55
|
+
constructor(io) {
|
|
56
|
+
this.io = io;
|
|
57
|
+
this.states = [];
|
|
58
|
+
this.swatches = [];
|
|
59
|
+
this.selects = [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 登记按钮的激活/禁用求值器,refresh 时统一结算 */
|
|
63
|
+
trackState(button, active, disabled) {
|
|
64
|
+
if (!active && !disabled) return;
|
|
65
|
+
this.states.push({ button, active, disabled });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
button(desc) {
|
|
69
|
+
const b = document.createElement('button');
|
|
70
|
+
b.type = 'button';
|
|
71
|
+
// iconOnly 的菜单按钮(字体颜色/突出显示/行距)按小按钮渲染,不能沿用大按钮的 54px 高度
|
|
72
|
+
b.className = desc.kind === 'small' || desc.iconOnly ? 'gbd-rbtn--small' : 'gbd-rbtn';
|
|
73
|
+
b.title = desc.title;
|
|
74
|
+
const iconHtml = desc.iconName ? `<span class="gbd-rbtn__ico">${icon(desc.iconName)}</span>` : '';
|
|
75
|
+
const isMenu = desc.kind === 'menu';
|
|
76
|
+
const caret = isMenu ? '<span class="gbd-rbtn__caret">▾</span>' : '';
|
|
77
|
+
// iconOnly:只显示图标(B/I/U 等),文字留在 title 做提示
|
|
78
|
+
const labelHtml = desc.iconOnly ? '' : `<span class="gbd-rbtn__label">${desc.title}</span>`;
|
|
79
|
+
const swatchHtml = desc.swatch ? '<span class="gbd-rbtn__swatch"></span>' : '';
|
|
80
|
+
b.innerHTML = iconHtml + labelHtml + caret + swatchHtml;
|
|
81
|
+
if (desc.iconOnly) b.classList.add('gbd-rbtn--icon');
|
|
82
|
+
if (desc.swatch) b.classList.add('gbd-rbtn--swatch');
|
|
83
|
+
if (desc.swatch) this.swatches.push([b.querySelector('.gbd-rbtn__swatch'), desc.swatch]);
|
|
84
|
+
const io = this.io;
|
|
85
|
+
b.addEventListener('mousedown', (e) => e.preventDefault());
|
|
86
|
+
b.addEventListener('click', (e) => {
|
|
87
|
+
if (isMenu) {
|
|
88
|
+
openMenu({ anchor: e.currentTarget, items: desc.items(), placement: 'bottom-start' });
|
|
89
|
+
} else {
|
|
90
|
+
desc.onClick?.(e);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
this.trackState(b, desc.active, desc.disabled);
|
|
94
|
+
return b;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
node(item) {
|
|
98
|
+
switch (item.kind) {
|
|
99
|
+
case 'big':
|
|
100
|
+
case 'small':
|
|
101
|
+
case 'menu':
|
|
102
|
+
return this.button(item);
|
|
103
|
+
case 'style': {
|
|
104
|
+
const b = document.createElement('button');
|
|
105
|
+
b.type = 'button';
|
|
106
|
+
b.className = 'gbd-rstyle';
|
|
107
|
+
b.title = item.name;
|
|
108
|
+
b.innerHTML = `<span class="gbd-rstyle__preview ${item.previewClass || ''}">${item.preview}</span>`;
|
|
109
|
+
b.addEventListener('mousedown', (e) => e.preventDefault());
|
|
110
|
+
b.addEventListener('click', item.onClick);
|
|
111
|
+
this.trackState(b, item.active, null);
|
|
112
|
+
return b;
|
|
113
|
+
}
|
|
114
|
+
case 'row': {
|
|
115
|
+
const el = document.createElement('div');
|
|
116
|
+
el.className = 'gbd-rgroup__row';
|
|
117
|
+
for (const it of item.items) el.appendChild(this.node(it));
|
|
118
|
+
return el;
|
|
119
|
+
}
|
|
120
|
+
case 'stack': {
|
|
121
|
+
const el = document.createElement('div');
|
|
122
|
+
el.className = 'gbd-rgroup__col';
|
|
123
|
+
for (const it of item.items) el.appendChild(this.node(it));
|
|
124
|
+
return el;
|
|
125
|
+
}
|
|
126
|
+
case 'select': {
|
|
127
|
+
const s = makeSelect({ ...item.spec, get: item.spec.get });
|
|
128
|
+
this.selects.push(s.refresh);
|
|
129
|
+
return s.el;
|
|
130
|
+
}
|
|
131
|
+
case 'group': {
|
|
132
|
+
const el = document.createElement('div');
|
|
133
|
+
el.className = 'gbd-rgroup';
|
|
134
|
+
const body = document.createElement('div');
|
|
135
|
+
body.className = 'gbd-rgroup__body';
|
|
136
|
+
for (const it of item.items) body.appendChild(this.node(it));
|
|
137
|
+
const name = document.createElement('div');
|
|
138
|
+
name.className = 'gbd-rgroup__name';
|
|
139
|
+
name.textContent = item.title;
|
|
140
|
+
el.append(body, name);
|
|
141
|
+
return el;
|
|
142
|
+
}
|
|
143
|
+
default:
|
|
144
|
+
return document.createComment('unknown ribbon item');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
render(panel, items) {
|
|
149
|
+
for (const item of items) panel.appendChild(this.node(item));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
refresh() {
|
|
153
|
+
const state = this.io.getState();
|
|
154
|
+
for (const { button, active, disabled } of this.states) {
|
|
155
|
+
if (active) button.classList.toggle('gbd-is-active', Boolean(active(state)));
|
|
156
|
+
if (disabled) button.disabled = Boolean(disabled(state));
|
|
157
|
+
}
|
|
158
|
+
for (const [el, evaluate] of this.swatches) el.style.background = evaluate(state) || 'transparent';
|
|
159
|
+
for (const r of this.selects) r();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* ============ 各选项卡面板(构建函数返回描述符数组) ============ */
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @param {object} io 见 buildRibbon 的 JSDoc;各构建函数通过闭包读取
|
|
167
|
+
* @returns {Record<string, (io) => Array>} key -> 描述符数组构建函数
|
|
168
|
+
*/
|
|
169
|
+
function panelDefs(io) {
|
|
170
|
+
const ctx = () => io.getCtx();
|
|
171
|
+
const state = () => io.getState();
|
|
172
|
+
const run = (name, ...args) => io.run(name, ...args);
|
|
173
|
+
|
|
174
|
+
/** 字体名下拉 */
|
|
175
|
+
const fontSelect = () => select({
|
|
176
|
+
title: '字体', width: 120,
|
|
177
|
+
options: [{ value: '', label: '默认字体' }, ...FONT_FAMILIES.map((f) => ({ value: f.value, label: f.label, style: { fontFamily: f.value } }))],
|
|
178
|
+
get: () => state().fontFamily || '',
|
|
179
|
+
onChange: (v) => (v ? run('setFontFamily', v) : run('unsetFontFamily')),
|
|
180
|
+
});
|
|
181
|
+
/** 字号下拉 */
|
|
182
|
+
const sizeSelect = () => select({
|
|
183
|
+
title: '字号', width: 48,
|
|
184
|
+
options: [{ value: '', label: '默认' }, ...FONT_SIZES.map((s) => ({ value: s, label: String(s) }))],
|
|
185
|
+
get: () => Number.parseFloat(state().fontSize) || '',
|
|
186
|
+
onChange: (v) => (v ? run('setFontSize', `${v}px`) : run('unsetFontSize')),
|
|
187
|
+
});
|
|
188
|
+
/** 字体色下拉(取色板现成值,点击即应用) */
|
|
189
|
+
const colorMenu = () => TEXT_COLORS.slice(0, 20).map((c) => ({
|
|
190
|
+
label: c,
|
|
191
|
+
onClick: () => run('setColor', c),
|
|
192
|
+
}));
|
|
193
|
+
const bgMenu = () => BG_COLORS.slice(0, 18).map((c) => ({
|
|
194
|
+
label: c,
|
|
195
|
+
onClick: () => run('setBackgroundColor', c),
|
|
196
|
+
}));
|
|
197
|
+
const pageNumberMenu = () => PAGE_NUMBER_ALIGNS.map((a) => ({
|
|
198
|
+
label: a.label,
|
|
199
|
+
checked: state().pageNumbers.enabled && state().pageNumbers.align === a.value,
|
|
200
|
+
onClick: () => ctx().insert.setPageNumber(a.value),
|
|
201
|
+
}));
|
|
202
|
+
const hfMenu = () => HF_MODES.map((m) => ({
|
|
203
|
+
label: m.label,
|
|
204
|
+
checked: state().hfMode === m.value,
|
|
205
|
+
onClick: () => ctx().format.setHfMode(m.value),
|
|
206
|
+
}));
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
// ---------- 开始 ----------
|
|
210
|
+
home: () => [
|
|
211
|
+
group('剪贴板',
|
|
212
|
+
big('paste', '粘贴', () => ctx().edit.paste()),
|
|
213
|
+
row(
|
|
214
|
+
small('cut', '剪切', () => ctx().edit.cut()),
|
|
215
|
+
small('copy', '复制', () => ctx().edit.copy())
|
|
216
|
+
)
|
|
217
|
+
),
|
|
218
|
+
group('字体',
|
|
219
|
+
stack(
|
|
220
|
+
row(fontSelect(), sizeSelect(),
|
|
221
|
+
small('growFont', '增大', () => run('setFontSize', `${Math.min(72, (Number.parseFloat(state().fontSize) || 14) + 2)}px`), { iconOnly: true }),
|
|
222
|
+
small('shrinkFont', '减小', () => run('setFontSize', `${Math.max(8, (Number.parseFloat(state().fontSize) || 14) - 2)}px`), { iconOnly: true }),
|
|
223
|
+
small('eraser', '清除格式', () => run('clearFormat'), { iconOnly: true })
|
|
224
|
+
),
|
|
225
|
+
row(
|
|
226
|
+
small('bold', '加粗', () => run('toggleBold'), { iconOnly: true, active: (s) => s.bold }),
|
|
227
|
+
small('italic', '斜体', () => run('toggleItalic'), { iconOnly: true, active: (s) => s.italic }),
|
|
228
|
+
small('underline', '下划线', () => run('toggleUnderline'), { iconOnly: true, active: (s) => s.underline }),
|
|
229
|
+
small('strike', '删除线', () => run('toggleStrike'), { iconOnly: true, active: (s) => s.strike }),
|
|
230
|
+
small('superscript', '上标', () => run('toggleSuperscript'), { iconOnly: true, active: (s) => s.superscript }),
|
|
231
|
+
small('subscript', '下标', () => run('toggleSubscript'), { iconOnly: true, active: (s) => s.subscript }),
|
|
232
|
+
menu('highlight', '突出显示', bgMenu, { iconOnly: true, swatch: (s) => s.backgroundColor || BG_COLORS[15] }),
|
|
233
|
+
menu('colorIcon', '字体颜色', colorMenu, { iconOnly: true, swatch: (s) => s.color || TEXT_COLORS[0] })
|
|
234
|
+
)
|
|
235
|
+
)
|
|
236
|
+
),
|
|
237
|
+
group('段落',
|
|
238
|
+
stack(
|
|
239
|
+
row(
|
|
240
|
+
small('bullet', '项目符号', () => run('toggleBulletList'), { iconOnly: true, active: (s) => s.bulletList }),
|
|
241
|
+
small('ordered', '编号', () => run('toggleOrderedList'), { iconOnly: true, active: (s) => s.orderedList }),
|
|
242
|
+
small('outdent', '减少缩进', () => run('decreaseBlockIndent'), { iconOnly: true }),
|
|
243
|
+
small('indentAdd', '增加缩进', () => run('increaseBlockIndent'), { iconOnly: true })
|
|
244
|
+
),
|
|
245
|
+
row(
|
|
246
|
+
small('alignLeft', '左对齐', () => run('setBlockAlign', 'left'), { iconOnly: true, active: (s) => s.textAlign === 'left' }),
|
|
247
|
+
small('alignCenter', '居中', () => run('setBlockAlign', 'center'), { iconOnly: true, active: (s) => s.textAlign === 'center' }),
|
|
248
|
+
small('alignRight', '右对齐', () => run('setBlockAlign', 'right'), { iconOnly: true, active: (s) => s.textAlign === 'right' }),
|
|
249
|
+
small('alignJustify', '两端对齐', () => run('setBlockAlign', 'justify'), { iconOnly: true, active: (s) => s.textAlign === 'justify' }),
|
|
250
|
+
menu('lineSpacing', '行距', () => ['1', '1.15', '1.5', '2', '2.5', '3'].map((v) => ({
|
|
251
|
+
label: v, checked: state().lineHeight === v, onClick: () => run('setBlockLineHeight', v),
|
|
252
|
+
})), { iconOnly: true })
|
|
253
|
+
)
|
|
254
|
+
)
|
|
255
|
+
),
|
|
256
|
+
group('样式',
|
|
257
|
+
row(
|
|
258
|
+
styleCard('正文', '正文', () => run('convertBlock', 'paragraph'), '', 'paragraph'),
|
|
259
|
+
styleCard('标题1', '标题 1', () => run('convertBlock', 'heading1'), 'gbd-rstyle__preview--h1', 'heading1'),
|
|
260
|
+
styleCard('标题2', '标题 2', () => run('convertBlock', 'heading2'), 'gbd-rstyle__preview--h2', 'heading2'),
|
|
261
|
+
styleCard('标题3', '标题 3', () => run('convertBlock', 'heading3'), 'gbd-rstyle__preview--h3', 'heading3')
|
|
262
|
+
)
|
|
263
|
+
),
|
|
264
|
+
group('编辑',
|
|
265
|
+
stack(
|
|
266
|
+
row(
|
|
267
|
+
small('undo', '撤销', () => run('undo'), { disabled: (s) => !s.canUndo }),
|
|
268
|
+
small('redo', '重做', () => run('redo'), { disabled: (s) => !s.canRedo })
|
|
269
|
+
),
|
|
270
|
+
row(small('find', '查找', () => io.find(false)))
|
|
271
|
+
),
|
|
272
|
+
big('comment', '批注', () => ctx().insert.comment())
|
|
273
|
+
),
|
|
274
|
+
],
|
|
275
|
+
|
|
276
|
+
// ---------- 插入 ----------
|
|
277
|
+
insert: () => [
|
|
278
|
+
group('分页',
|
|
279
|
+
big('pageBreak', '分页符', () => run('insertPageBreak'))
|
|
280
|
+
),
|
|
281
|
+
group('表格', big('table', '表格', (e) => io.actions.insertTable(e))),
|
|
282
|
+
group('插图',
|
|
283
|
+
big('image', '图片', () => io.actions.insertImage())
|
|
284
|
+
),
|
|
285
|
+
group('符号',
|
|
286
|
+
big('specialChars', '符号', () => ctx().insert.specialChars())
|
|
287
|
+
),
|
|
288
|
+
group('页眉页脚',
|
|
289
|
+
big('headerFooter', '页眉页脚', () => ctx().file.pageSetup()),
|
|
290
|
+
big('pageNumber', '页码', (e) => openMenu({ anchor: e.currentTarget, items: pageNumberMenu(), placement: 'bottom-start' })),
|
|
291
|
+
big('watermark', '水印', () => ctx().insert.watermark())
|
|
292
|
+
),
|
|
293
|
+
group('链接',
|
|
294
|
+
big('linkIcon', '超级链接', () => io.actions.insertLink())
|
|
295
|
+
),
|
|
296
|
+
group('脚注与批注',
|
|
297
|
+
big('footnote', '脚注', () => ctx().insert.footnote()),
|
|
298
|
+
big('comment', '批注', () => ctx().insert.comment())
|
|
299
|
+
),
|
|
300
|
+
],
|
|
301
|
+
|
|
302
|
+
// ---------- 页面布局 ----------
|
|
303
|
+
layout: () => [
|
|
304
|
+
group('页面设置',
|
|
305
|
+
big('margin', '页边距', () => io.openMargin()),
|
|
306
|
+
big('orientation', '纸张方向', () => ctx().file.pageSetup()),
|
|
307
|
+
big('paperSize', '纸张大小', () => ctx().file.pageSetup()),
|
|
308
|
+
big('columns', '分栏', (e) => openMenu({ anchor: e.currentTarget, items: [1, 2, 3].map((n) => ({
|
|
309
|
+
label: n === 1 ? '单栏' : `${n} 栏`, checked: state().columns === n, onClick: () => ctx().format.setLayout(n),
|
|
310
|
+
})), placement: 'bottom-start' }))
|
|
311
|
+
),
|
|
312
|
+
],
|
|
313
|
+
|
|
314
|
+
// ---------- 引用 ----------
|
|
315
|
+
reference: () => [
|
|
316
|
+
group('目录',
|
|
317
|
+
big('toc', '目录', (e) => openMenu({ anchor: e.currentTarget, items: [
|
|
318
|
+
{ label: '插入目录', onClick: () => ctx().insert.toc() },
|
|
319
|
+
{ label: '刷新目录', onClick: () => ctx().insert.refreshToc() },
|
|
320
|
+
], placement: 'bottom-start' })),
|
|
321
|
+
big('updateToc', '更新目录', () => ctx().insert.refreshToc())
|
|
322
|
+
),
|
|
323
|
+
group('脚注',
|
|
324
|
+
big('footnote', '插入脚注', () => ctx().insert.footnote())
|
|
325
|
+
),
|
|
326
|
+
],
|
|
327
|
+
|
|
328
|
+
// ---------- 审阅 ----------
|
|
329
|
+
review: () => [
|
|
330
|
+
group('修订',
|
|
331
|
+
big('suggest', '修订', () => ctx().edit.setSuggesting(!state().suggesting), { active: (s) => s.suggesting }),
|
|
332
|
+
big('accept', '接受', () => ctx().edit.acceptAll()),
|
|
333
|
+
big('reject', '拒绝', () => ctx().edit.rejectAll())
|
|
334
|
+
),
|
|
335
|
+
group('批注',
|
|
336
|
+
big('comment', '插入批注', () => ctx().insert.comment()),
|
|
337
|
+
big('panel', '批注面板', () => ctx().view.setView('commentsPanel', !state().commentsPanel), { active: (s) => s.commentsPanel })
|
|
338
|
+
),
|
|
339
|
+
group('查找',
|
|
340
|
+
big('find', '查找', () => io.find(false)),
|
|
341
|
+
big('find', '替换', () => io.find(true))
|
|
342
|
+
),
|
|
343
|
+
],
|
|
344
|
+
|
|
345
|
+
// ---------- 视图 ----------
|
|
346
|
+
view: () => [
|
|
347
|
+
group('缩放',
|
|
348
|
+
big('zoomIn', '放大', () => ctx().view.zoomIn()),
|
|
349
|
+
big('zoomOut', '缩小', () => ctx().view.zoomOut()),
|
|
350
|
+
big('zoomReset', '100%', () => ctx().view.zoomReset())
|
|
351
|
+
),
|
|
352
|
+
group('显示',
|
|
353
|
+
big('bookmark', '目录导航', () => ctx().view.setView('catalog', !state().catalog), { active: (s) => s.catalog }),
|
|
354
|
+
big('panel', '批注面板', () => ctx().view.setView('commentsPanel', !state().commentsPanel), { active: (s) => s.commentsPanel })
|
|
355
|
+
),
|
|
356
|
+
],
|
|
357
|
+
|
|
358
|
+
// ---------- 章节 ----------
|
|
359
|
+
chapter: () => [
|
|
360
|
+
group('章节',
|
|
361
|
+
big('toc', '插入目录', () => ctx().insert.toc()),
|
|
362
|
+
big('updateToc', '刷新目录', () => ctx().insert.refreshToc())
|
|
363
|
+
),
|
|
364
|
+
group('分页',
|
|
365
|
+
big('pageBreak', '分页符', () => run('insertPageBreak')),
|
|
366
|
+
big('pageNumber', '页码', (e) => openMenu({ anchor: e.currentTarget, items: pageNumberMenu(), placement: 'bottom-start' }))
|
|
367
|
+
),
|
|
368
|
+
group('页眉页脚',
|
|
369
|
+
big('headerFooter', '页眉页脚', (e) => openMenu({ anchor: e.currentTarget, items: hfMenu(), placement: 'bottom-start' })),
|
|
370
|
+
big('watermark', '水印', () => ctx().insert.watermark())
|
|
371
|
+
),
|
|
372
|
+
],
|
|
373
|
+
|
|
374
|
+
// ---------- 开发工具 ----------
|
|
375
|
+
developer: () => [
|
|
376
|
+
group('内容块',
|
|
377
|
+
big('code', '代码块', () => run('toggleCodeBlock'), { active: (s) => s.codeBlock }),
|
|
378
|
+
big('quote', '引用块', () => run('toggleBlockquote'), { active: (s) => s.blockquote }),
|
|
379
|
+
big('ordered', '待办列表', () => run('toggleTaskList'), { active: (s) => s.taskList })
|
|
380
|
+
),
|
|
381
|
+
group('编辑',
|
|
382
|
+
big('clear', '清除格式', () => run('clearFormat')),
|
|
383
|
+
big('suggest', '修订', () => ctx().edit.setSuggesting(!state().suggesting), { active: (s) => s.suggesting }),
|
|
384
|
+
big('specialChars', '特殊符号', () => ctx().insert.specialChars())
|
|
385
|
+
),
|
|
386
|
+
],
|
|
387
|
+
|
|
388
|
+
// ---------- 特色功能 ----------
|
|
389
|
+
feature: () => [
|
|
390
|
+
group('文档增强',
|
|
391
|
+
big('watermark', '水印', () => ctx().insert.watermark()),
|
|
392
|
+
big('toc', '目录', () => ctx().insert.toc()),
|
|
393
|
+
big('pageBreak', '分页符', () => run('insertPageBreak'))
|
|
394
|
+
),
|
|
395
|
+
group('输出',
|
|
396
|
+
big('print', '打印 / PDF', () => ctx().file.print()),
|
|
397
|
+
big('export', '导出 Word', () => ctx().file.exportCopy()),
|
|
398
|
+
big('export', '导出 Markdown', () => ctx().file.exportMarkdown())
|
|
399
|
+
),
|
|
400
|
+
],
|
|
401
|
+
|
|
402
|
+
// ---------- 查找 ----------
|
|
403
|
+
find: () => [
|
|
404
|
+
group('查找',
|
|
405
|
+
big('find', '查找', () => io.find(false)),
|
|
406
|
+
big('find', '查找替换', () => io.find(true)),
|
|
407
|
+
big('selectAll', '全选', () => run('selectAll'))
|
|
408
|
+
),
|
|
409
|
+
],
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* 构建选项卡栏。
|
|
415
|
+
* @param {object} io
|
|
416
|
+
* @param {() => object} io.getState 现取合并状态
|
|
417
|
+
* @param {() => object} io.getCtx 现取 menuCtx(只读短路已内含)
|
|
418
|
+
* @param {() => boolean} io.isDisabled 是否只读
|
|
419
|
+
* @param {(name:string, ...args:any[]) => any} io.run 执行编辑器命令
|
|
420
|
+
* @param {object} io.actions {insertTable, insertImage, insertLink}
|
|
421
|
+
* @param {(replace:boolean) => void} io.find 打开查找栏
|
|
422
|
+
* @param {() => void} io.openMargin 页边距对话框
|
|
423
|
+
*/
|
|
424
|
+
export function buildRibbon(io) {
|
|
425
|
+
const root = document.createElement('div');
|
|
426
|
+
root.className = 'gbd-ribbon';
|
|
427
|
+
const tabsEl = document.createElement('div');
|
|
428
|
+
tabsEl.className = 'gbd-ribbon__tabs';
|
|
429
|
+
tabsEl.setAttribute('role', 'tablist');
|
|
430
|
+
const panelsEl = document.createElement('div');
|
|
431
|
+
panelsEl.className = 'gbd-ribbon__panels';
|
|
432
|
+
root.append(tabsEl, panelsEl);
|
|
433
|
+
|
|
434
|
+
const defs = panelDefs(io);
|
|
435
|
+
const entries = [];
|
|
436
|
+
let activeKey = TABS[0].key;
|
|
437
|
+
|
|
438
|
+
for (const { key, label, icon: tabIcon } of TABS) {
|
|
439
|
+
const tab = document.createElement('button');
|
|
440
|
+
tab.type = 'button';
|
|
441
|
+
tab.className = 'gbd-ribbon__tab';
|
|
442
|
+
tab.dataset.tab = key;
|
|
443
|
+
tab.setAttribute('role', 'tab');
|
|
444
|
+
tab.innerHTML = (tabIcon ? `<span class="gbd-ribbon__tabicon">${icon(tabIcon)}</span>` : '') + `<span>${label}</span>`;
|
|
445
|
+
|
|
446
|
+
const panel = document.createElement('div');
|
|
447
|
+
panel.className = 'gbd-ribbon__panel';
|
|
448
|
+
panel.dataset.panel = key;
|
|
449
|
+
panel.setAttribute('role', 'tabpanel');
|
|
450
|
+
const pctx = new PanelContext(io);
|
|
451
|
+
pctx.render(panel, defs[key]());
|
|
452
|
+
pctx.refresh(); // 首帧即按现态点亮(激活样式/色条/撤销可用性),不等第一次 state 事件
|
|
453
|
+
entries.push({ key, tab, panel, refresh: () => pctx.refresh() });
|
|
454
|
+
tab.addEventListener('click', () => select(key));
|
|
455
|
+
tabsEl.appendChild(tab);
|
|
456
|
+
panelsEl.appendChild(panel);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function select(key) {
|
|
460
|
+
if (activeKey === key) return;
|
|
461
|
+
activeKey = key;
|
|
462
|
+
for (const entry of entries) {
|
|
463
|
+
const on = entry.key === key;
|
|
464
|
+
entry.panel.hidden = !on;
|
|
465
|
+
entry.tab.classList.toggle('gbd-is-active', on);
|
|
466
|
+
entry.tab.setAttribute('aria-selected', String(on));
|
|
467
|
+
if (on) entry.refresh();
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
for (const entry of entries) {
|
|
472
|
+
const on = entry.key === activeKey;
|
|
473
|
+
entry.panel.hidden = !on;
|
|
474
|
+
entry.tab.classList.toggle('gbd-is-active', on);
|
|
475
|
+
entry.tab.setAttribute('aria-selected', String(on));
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
root.refresh = () => { for (const entry of entries) entry.refresh(); };
|
|
479
|
+
root.getActiveTab = () => activeKey;
|
|
480
|
+
root.selectTab = select;
|
|
481
|
+
return root;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** 供测试断言:选项卡定义(顺序 + key/label) */
|
|
485
|
+
export const RIBBON_TABS = TABS.map(({ key, label }) => ({ key, label }));
|