@bireturn/word-editor 1.0.4 → 1.0.5
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/lib/components/Editor/useDocRenderer.d.ts +15 -0
- package/lib/components/VirtualTable/index.d.ts +19 -0
- package/lib/components/VirtualTable/src/context-menu.d.ts +16 -0
- package/lib/components/VirtualTable/src/tool.d.ts +15 -0
- package/lib/composables/useDocumentData.d.ts +10 -0
- package/lib/composables/useEditor.d.ts +5 -0
- package/lib/core/command/CommandManager.d.ts +16 -0
- package/lib/core/command/commands/DeleteCommand.d.ts +14 -0
- package/lib/core/command/commands/FormatCommand.d.ts +30 -0
- package/lib/core/command/commands/InsertParagraphCommand.d.ts +12 -0
- package/lib/core/command/commands/InsertTextCommand.d.ts +18 -0
- package/lib/core/editor/Editor.d.ts +46 -0
- package/lib/core/editor/EditorOptions.d.ts +1 -0
- package/lib/core/history/HistoryManager.d.ts +15 -0
- package/lib/core/input/InputHandler.d.ts +20 -0
- package/lib/core/model/DocumentModel.d.ts +38 -0
- package/lib/core/selection/SelectionManager.d.ts +26 -0
- package/lib/index.d.ts +10 -0
- package/lib/types/command.d.ts +57 -0
- package/lib/types/document.d.ts +111 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/plugin.d.ts +12 -0
- package/lib/types/selection.d.ts +17 -0
- package/lib/utils/catalog.d.ts +29 -0
- package/lib/utils/nanoid.d.ts +1 -0
- package/lib/utils/titleIndex.d.ts +11 -0
- package/lib/word-editor.css +1 -0
- package/lib/word-editor.es.js +2930 -0
- package/lib/word-editor.umd.js +2 -0
- package/package.json +2 -1
|
@@ -0,0 +1,2930 @@
|
|
|
1
|
+
var yn = Object.defineProperty;
|
|
2
|
+
var bn = (t, e, n) => e in t ? yn(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var D = (t, e, n) => bn(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
import { computed as ae, ref as te, onMounted as ft, onUnmounted as lt, openBlock as u, createElementBlock as v, normalizeStyle as N, createElementVNode as ee, Fragment as U, renderList as Z, normalizeClass as Ie, createBlock as ke, resolveDynamicComponent as nt, toDisplayString as J, unref as z, createCommentVNode as ue, render as Vt, h as _n, defineComponent as xn, getCurrentInstance as kn, watch as Ve, nextTick as be, createVNode as q, createTextVNode as He, isVNode as wn, renderSlot as Cn, resolveComponent as Mn, inject as jt, withCtx as Ke, provide as Kt, createSlots as In, reactive as qt } from "vue";
|
|
5
|
+
import { DynamicScroller as En, DynamicScrollerItem as Sn } from "vue-virtual-scroller";
|
|
6
|
+
import { ChevronRight as Ut, MoreHorizontal as kt, Download as st, Upload as Tn, Save as Fn, RotateCcw as An, History as Pn, Settings as $n, Info as Ln, Globe as Rn, Lock as Hn, Share as On, ShieldCheck as Bn, Search as Dn, Filter as Nn, SortDesc as zn, SortAsc as Vn, Minus as jn, Plus as wt, Eye as Ct, FileText as rt, Grid as Kn, Type as Mt, FileDown as It, Layers as Et, Edit as qn, Move as Un, Copy as Wn, Trash2 as St, Clipboard as Tt, PlusCircle as Ft, ArrowDown as At, Navigation as Pt, ChevronDown as Gn, PanelLeftOpen as Jn, ListTree as Xn, PanelLeftClose as Yn } from "lucide-vue-next";
|
|
7
|
+
const Zn = { class: "we-vt-context-menu--option-wrapper modern-menu-wrapper" }, Qn = ["onMouseenter", "onMouseleave"], ei = ["onClick"], ti = { class: "we-vt-context-menu--link-content menu-label" }, ni = {
|
|
8
|
+
key: 0,
|
|
9
|
+
class: "we-vt-context-menu--submenu modern-submenu"
|
|
10
|
+
}, ii = ["onClick"], li = { class: "we-vt-context-menu--link-content submenu-label" }, oi = {
|
|
11
|
+
__name: "ContextMenu",
|
|
12
|
+
props: {
|
|
13
|
+
// 事件
|
|
14
|
+
e: {
|
|
15
|
+
type: Object,
|
|
16
|
+
default: () => ({})
|
|
17
|
+
},
|
|
18
|
+
// 右键点击行数据
|
|
19
|
+
row: {
|
|
20
|
+
type: Object,
|
|
21
|
+
default: () => ({})
|
|
22
|
+
},
|
|
23
|
+
// 右键菜单配置
|
|
24
|
+
menuConfig: {
|
|
25
|
+
type: Object,
|
|
26
|
+
default: () => ({
|
|
27
|
+
body: {}
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
emits: ["close", "menuClick"],
|
|
32
|
+
setup(t, { emit: e }) {
|
|
33
|
+
const n = e, l = t, o = ae(() => {
|
|
34
|
+
var R, T;
|
|
35
|
+
return {
|
|
36
|
+
left: `${(R = l.e) == null ? void 0 : R.pageX}px`,
|
|
37
|
+
top: `${(T = l.e) == null ? void 0 : T.pageY}px`
|
|
38
|
+
};
|
|
39
|
+
}), r = te([]), y = te(null);
|
|
40
|
+
let s = null;
|
|
41
|
+
const m = te(), h = (R, T, f) => {
|
|
42
|
+
if (R.children && R.children.length > 0) {
|
|
43
|
+
T && T.preventDefault() && T.stopPropagation();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
R.disabled || (f ? n("menuClick", { ...R, parent: f.code }, l.row) : n("menuClick", R, l.row)), T && T.preventDefault() && T.stopPropagation();
|
|
47
|
+
}, I = (R) => {
|
|
48
|
+
let T = R.target;
|
|
49
|
+
for (; T && T != m.value; )
|
|
50
|
+
T = T.parentNode;
|
|
51
|
+
T != m.value && n("close");
|
|
52
|
+
}, S = (R, T) => {
|
|
53
|
+
R.currentTarget.classList.add("link--active"), s && (clearTimeout(s), s = null), T.children && T.children.length > 0 ? y.value = T.code : s = setTimeout(() => {
|
|
54
|
+
y.value = null;
|
|
55
|
+
}, 100);
|
|
56
|
+
}, L = (R, T) => {
|
|
57
|
+
R.currentTarget.classList.remove("link--active"), T.children && T.children.length > 0 && (s = setTimeout(() => {
|
|
58
|
+
y.value === T.code && (y.value = null);
|
|
59
|
+
}, 300));
|
|
60
|
+
}, x = (R) => {
|
|
61
|
+
s && (clearTimeout(s), s = null), R.currentTarget.classList.add("link--active");
|
|
62
|
+
}, K = (R) => {
|
|
63
|
+
R.currentTarget.classList.remove("link--active");
|
|
64
|
+
}, ne = (R) => {
|
|
65
|
+
const T = R.code || "", f = (R.name || "").toLowerCase(), E = {
|
|
66
|
+
// 添加操作 - 根据具体类型使用不同图标
|
|
67
|
+
"add-current": Pt,
|
|
68
|
+
// 添加(当前位置)
|
|
69
|
+
"add-next": At,
|
|
70
|
+
// 添加(下一行)
|
|
71
|
+
"add-child": Ft,
|
|
72
|
+
// 添加(子节点)
|
|
73
|
+
// 基本操作
|
|
74
|
+
paste: Tt,
|
|
75
|
+
// 粘贴
|
|
76
|
+
delete: St,
|
|
77
|
+
// 删除
|
|
78
|
+
copy: Wn,
|
|
79
|
+
// 复制
|
|
80
|
+
cut: Un,
|
|
81
|
+
// 剪切
|
|
82
|
+
edit: qn,
|
|
83
|
+
// 编辑
|
|
84
|
+
// 导出操作 - 根据范围使用不同图标
|
|
85
|
+
export_part_section: Et,
|
|
86
|
+
// 导出此节点所在节
|
|
87
|
+
export_part_chapter: It,
|
|
88
|
+
// 导出此节点所在章
|
|
89
|
+
export_full: st,
|
|
90
|
+
// 完整导出
|
|
91
|
+
// 文件格式
|
|
92
|
+
pdf: rt,
|
|
93
|
+
// PDF格式
|
|
94
|
+
word: Mt,
|
|
95
|
+
// WORD格式
|
|
96
|
+
excel: Kn,
|
|
97
|
+
// Excel格式
|
|
98
|
+
txt: rt,
|
|
99
|
+
// 文本格式
|
|
100
|
+
// 视图操作
|
|
101
|
+
view: Ct,
|
|
102
|
+
// 查看
|
|
103
|
+
preview: Ct,
|
|
104
|
+
// 预览
|
|
105
|
+
expand: wt,
|
|
106
|
+
// 展开
|
|
107
|
+
collapse: jn,
|
|
108
|
+
// 折叠
|
|
109
|
+
// 排序和过滤
|
|
110
|
+
"sort-asc": Vn,
|
|
111
|
+
// 升序
|
|
112
|
+
"sort-desc": zn,
|
|
113
|
+
// 降序
|
|
114
|
+
filter: Nn,
|
|
115
|
+
// 过滤
|
|
116
|
+
search: Dn,
|
|
117
|
+
// 搜索
|
|
118
|
+
// 权限操作
|
|
119
|
+
permission: Bn,
|
|
120
|
+
// 权限设置
|
|
121
|
+
share: On,
|
|
122
|
+
// 分享
|
|
123
|
+
lock: Hn,
|
|
124
|
+
// 锁定
|
|
125
|
+
unlock: Rn,
|
|
126
|
+
// 解锁
|
|
127
|
+
// 其他操作
|
|
128
|
+
info: Ln,
|
|
129
|
+
// 信息
|
|
130
|
+
settings: $n,
|
|
131
|
+
// 设置
|
|
132
|
+
history: Pn,
|
|
133
|
+
// 历史
|
|
134
|
+
refresh: An,
|
|
135
|
+
// 刷新
|
|
136
|
+
save: Fn,
|
|
137
|
+
// 保存
|
|
138
|
+
upload: Tn,
|
|
139
|
+
// 上传
|
|
140
|
+
download: st,
|
|
141
|
+
// 下载
|
|
142
|
+
more: kt
|
|
143
|
+
// 更多
|
|
144
|
+
};
|
|
145
|
+
return E[T] ? E[T] : f.includes("添加") || f.includes("add") ? f.includes("当前") || f.includes("current") ? Pt : f.includes("下") || f.includes("next") ? At : f.includes("子") || f.includes("child") ? Ft : wt : f.includes("导出") || f.includes("export") ? f.includes("节") || f.includes("section") ? Et : f.includes("章") || f.includes("chapter") ? It : st : f.includes("粘贴") || f.includes("paste") ? Tt : f.includes("删除") || f.includes("delete") ? St : f.includes("pdf") ? rt : f.includes("word") ? Mt : kt;
|
|
146
|
+
};
|
|
147
|
+
return ft(() => {
|
|
148
|
+
var R, T, f, E, B, A, P;
|
|
149
|
+
(R = l.menuConfig) != null && R.visibleMethod && typeof ((T = l.menuConfig) == null ? void 0 : T.visibleMethod) == "function" && ((B = l.menuConfig) == null || B.visibleMethod({
|
|
150
|
+
options: (E = (f = l.menuConfig) == null ? void 0 : f.body) == null ? void 0 : E.options,
|
|
151
|
+
row: l.row
|
|
152
|
+
})), r.value = (((P = (A = l.menuConfig) == null ? void 0 : A.body) == null ? void 0 : P.options) || []).flat(), document.addEventListener("click", I, !0);
|
|
153
|
+
}), lt(() => {
|
|
154
|
+
document.removeEventListener("click", I, !0);
|
|
155
|
+
}), (R, T) => (u(), v("div", {
|
|
156
|
+
class: "we-vt-table--context-menu-wrapper virtual-table-menu modern-virtual-menu",
|
|
157
|
+
ref_key: "contextMenuRef",
|
|
158
|
+
ref: m,
|
|
159
|
+
style: N([{ display: "inline-block" }, o.value])
|
|
160
|
+
}, [
|
|
161
|
+
ee("ul", Zn, [
|
|
162
|
+
(u(!0), v(U, null, Z(r.value, (f) => (u(), v("li", {
|
|
163
|
+
class: Ie({
|
|
164
|
+
"link--disabled": f.disabled,
|
|
165
|
+
"has-children": f.children && f.children.length > 0,
|
|
166
|
+
"modern-menu-item": !0
|
|
167
|
+
}),
|
|
168
|
+
key: f.code,
|
|
169
|
+
onMouseenter: (E) => S(E, f),
|
|
170
|
+
onMouseleave: (E) => L(E, f)
|
|
171
|
+
}, [
|
|
172
|
+
ee("a", {
|
|
173
|
+
class: "we-vt-context-menu--link modern-menu-link",
|
|
174
|
+
onClick: (E) => h(f, E)
|
|
175
|
+
}, [
|
|
176
|
+
(u(), ke(nt(ne(f)), {
|
|
177
|
+
size: 16,
|
|
178
|
+
class: "menu-icon"
|
|
179
|
+
})),
|
|
180
|
+
ee("span", ti, J(f.name), 1),
|
|
181
|
+
f.children && f.children.length > 0 ? (u(), ke(z(Ut), {
|
|
182
|
+
key: 0,
|
|
183
|
+
size: 14,
|
|
184
|
+
class: "submenu-arrow"
|
|
185
|
+
})) : ue("", !0)
|
|
186
|
+
], 8, ei),
|
|
187
|
+
f.children && f.children.length > 0 && y.value === f.code ? (u(), v("ul", ni, [
|
|
188
|
+
(u(!0), v(U, null, Z(f.children, (E) => (u(), v("li", {
|
|
189
|
+
key: E.code,
|
|
190
|
+
class: Ie({
|
|
191
|
+
"link--disabled": E.disabled,
|
|
192
|
+
"modern-submenu-item": !0
|
|
193
|
+
}),
|
|
194
|
+
onMouseenter: x,
|
|
195
|
+
onMouseleave: K
|
|
196
|
+
}, [
|
|
197
|
+
ee("a", {
|
|
198
|
+
class: "we-vt-context-menu--link modern-submenu-link",
|
|
199
|
+
onClick: (B) => h(E, B, f)
|
|
200
|
+
}, [
|
|
201
|
+
(u(), ke(nt(ne(E)), {
|
|
202
|
+
size: 14,
|
|
203
|
+
class: "submenu-icon"
|
|
204
|
+
})),
|
|
205
|
+
ee("span", li, J(E.name), 1)
|
|
206
|
+
], 8, ii)
|
|
207
|
+
], 34))), 128))
|
|
208
|
+
])) : ue("", !0)
|
|
209
|
+
], 42, Qn))), 128))
|
|
210
|
+
])
|
|
211
|
+
], 4));
|
|
212
|
+
}
|
|
213
|
+
}, Wt = Symbol("component_container");
|
|
214
|
+
function ai(t, e, n) {
|
|
215
|
+
const l = _n(t, { ...e }, n), o = document.createElement("div");
|
|
216
|
+
return document.body.appendChild(o), l[Wt] = o, Vt(l, o), l.component;
|
|
217
|
+
}
|
|
218
|
+
function si(t) {
|
|
219
|
+
var n;
|
|
220
|
+
const e = t.vnode[Wt];
|
|
221
|
+
Vt(null, e), e != null && e.checkVisibility && (e != null && e.checkVisibility()) && ((n = document.body) == null || n.removeChild(e));
|
|
222
|
+
}
|
|
223
|
+
let Gt;
|
|
224
|
+
const ri = (t) => {
|
|
225
|
+
Gt = ai(oi, t, null);
|
|
226
|
+
}, ci = function(t) {
|
|
227
|
+
const e = t.onClose;
|
|
228
|
+
return t.onClose = () => {
|
|
229
|
+
e && e.call(), si(Gt);
|
|
230
|
+
}, ri(t), t;
|
|
231
|
+
};
|
|
232
|
+
function di(t, e, n) {
|
|
233
|
+
const l = (n == null ? void 0 : n.keyField) || (n == null ? void 0 : n.rowField) || "node_id", o = (n == null ? void 0 : n.parentField) || "parent_id", r = (n == null ? void 0 : n.parentField) || "order";
|
|
234
|
+
if (!(t != null && t.length))
|
|
235
|
+
return t;
|
|
236
|
+
const y = {};
|
|
237
|
+
t.forEach((I) => {
|
|
238
|
+
const S = I[o];
|
|
239
|
+
y[S] || (y[S] = []), y[S].push(I);
|
|
240
|
+
});
|
|
241
|
+
function s(I) {
|
|
242
|
+
const S = y[I] || [];
|
|
243
|
+
S.sort(
|
|
244
|
+
(x, K) => x[r] && K[r] ? x[r] - K[r] : 0
|
|
245
|
+
);
|
|
246
|
+
const L = [];
|
|
247
|
+
return S.forEach((x) => {
|
|
248
|
+
L.push(x), L.push(...s(x[l]));
|
|
249
|
+
}), L;
|
|
250
|
+
}
|
|
251
|
+
let m = [];
|
|
252
|
+
if (Array.isArray(e))
|
|
253
|
+
m = e;
|
|
254
|
+
else {
|
|
255
|
+
const I = new Set(t.map((x) => x[l])), S = t.filter((x) => !I.has(x[o]));
|
|
256
|
+
if (S.length === 0)
|
|
257
|
+
throw new Error("无法确定根节点:可能存在循环引用或数据不完整");
|
|
258
|
+
const L = {};
|
|
259
|
+
S.forEach((x) => {
|
|
260
|
+
const K = x[o];
|
|
261
|
+
L[K] = (L[K] || 0) + 1;
|
|
262
|
+
}), m = Object.entries(L).map(([x]) => x);
|
|
263
|
+
}
|
|
264
|
+
let h = [];
|
|
265
|
+
return m.forEach((I) => {
|
|
266
|
+
h = h.concat(s(I));
|
|
267
|
+
}), h;
|
|
268
|
+
}
|
|
269
|
+
function $t(t, e, n) {
|
|
270
|
+
let l;
|
|
271
|
+
for (; t && t.nodeType && t !== document; ) {
|
|
272
|
+
if (t.className && t.className.split && t.className.split(" ").indexOf(e) > -1)
|
|
273
|
+
return l = t, l;
|
|
274
|
+
if (t === n)
|
|
275
|
+
return null;
|
|
276
|
+
t = t.parentNode;
|
|
277
|
+
}
|
|
278
|
+
return l;
|
|
279
|
+
}
|
|
280
|
+
function ui(t) {
|
|
281
|
+
return typeof t == "function" || Object.prototype.toString.call(t) === "[object Object]" && !wn(t);
|
|
282
|
+
}
|
|
283
|
+
const hi = /* @__PURE__ */ xn({
|
|
284
|
+
name: "VirtualTable",
|
|
285
|
+
props: {
|
|
286
|
+
data: {
|
|
287
|
+
type: Array,
|
|
288
|
+
required: !0,
|
|
289
|
+
default: () => []
|
|
290
|
+
},
|
|
291
|
+
rowConfig: {
|
|
292
|
+
type: Object,
|
|
293
|
+
default: () => ({
|
|
294
|
+
keyField: "node_id"
|
|
295
|
+
})
|
|
296
|
+
},
|
|
297
|
+
// 配置editConfig后才可双击编辑
|
|
298
|
+
editConfig: {
|
|
299
|
+
type: Object,
|
|
300
|
+
default: null
|
|
301
|
+
},
|
|
302
|
+
// 配置treeConfig后才可会做树排序
|
|
303
|
+
treeConfig: {
|
|
304
|
+
type: Object,
|
|
305
|
+
default: null
|
|
306
|
+
},
|
|
307
|
+
menuConfig: {
|
|
308
|
+
type: Object,
|
|
309
|
+
default: () => ({
|
|
310
|
+
body: {}
|
|
311
|
+
})
|
|
312
|
+
},
|
|
313
|
+
showHeader: {
|
|
314
|
+
type: Boolean,
|
|
315
|
+
default: !0
|
|
316
|
+
},
|
|
317
|
+
rowClassName: {
|
|
318
|
+
type: Function,
|
|
319
|
+
default: null
|
|
320
|
+
},
|
|
321
|
+
// A4页面配置
|
|
322
|
+
pageConfig: {
|
|
323
|
+
type: Object,
|
|
324
|
+
default: () => ({
|
|
325
|
+
enabled: !1,
|
|
326
|
+
// 是否启用A4页面模式
|
|
327
|
+
pageHeight: 842,
|
|
328
|
+
// A4页面高度 (297mm * 3.78px/mm)
|
|
329
|
+
pageWidth: 595,
|
|
330
|
+
// A4页面宽度 (210mm * 3.78px/mm)
|
|
331
|
+
margin: 40,
|
|
332
|
+
// 页面边距
|
|
333
|
+
gap: 10,
|
|
334
|
+
// 页面间隔
|
|
335
|
+
showPageHeader: !0,
|
|
336
|
+
// 是否显示页眉
|
|
337
|
+
showPageBorder: !1,
|
|
338
|
+
// 是否显示内容区边框
|
|
339
|
+
pageBorderPadding: 5,
|
|
340
|
+
// 内容区边框内边距(px)
|
|
341
|
+
pageBorderStyle: "1px solid #000",
|
|
342
|
+
// 内容区边框样式
|
|
343
|
+
headerHeight: 0,
|
|
344
|
+
// 页眉占用高度(px),从内容区高度中扣除
|
|
345
|
+
footerHeight: 0,
|
|
346
|
+
// 页脚占用高度(px),从内容区高度中扣除
|
|
347
|
+
showPageNumber: !0
|
|
348
|
+
// 是否显示默认页码
|
|
349
|
+
})
|
|
350
|
+
},
|
|
351
|
+
// 页面数据映射 - key是页码,value是node_id数组,用于和pdf分页对应
|
|
352
|
+
pageData: {
|
|
353
|
+
type: Object,
|
|
354
|
+
default: null
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
emits: ["current-change", "menu-click", "edit-activated", "edit-closed", "scroll-end", "selection-change"],
|
|
358
|
+
setup(t, {
|
|
359
|
+
emit: e,
|
|
360
|
+
slots: n,
|
|
361
|
+
expose: l
|
|
362
|
+
}) {
|
|
363
|
+
var xt;
|
|
364
|
+
const o = kn(), r = te(), y = te(!1), s = te(null), m = te(null), h = te([]);
|
|
365
|
+
let I = /* @__PURE__ */ new Map();
|
|
366
|
+
const S = /* @__PURE__ */ new Map();
|
|
367
|
+
te(0);
|
|
368
|
+
const L = te([]);
|
|
369
|
+
te([]);
|
|
370
|
+
const x = te(/* @__PURE__ */ new Set()), K = te(/* @__PURE__ */ new Set()), ne = te(null), R = 2, T = /* @__PURE__ */ new WeakMap(), f = te(null), E = te(""), B = /* @__PURE__ */ new Set(), A = ae(() => {
|
|
371
|
+
try {
|
|
372
|
+
return Array.isArray(h.value) ? h.value : [];
|
|
373
|
+
} catch {
|
|
374
|
+
return [];
|
|
375
|
+
}
|
|
376
|
+
}), P = (i) => {
|
|
377
|
+
var p, d, g;
|
|
378
|
+
if (!i) return 30;
|
|
379
|
+
if (i.height) return i.height;
|
|
380
|
+
const a = `${i.content_type}_${((p = i.content) == null ? void 0 : p.length) || 0}_${((d = i.title) == null ? void 0 : d.length) || 0}_${i._editing ? 1 : 0}`;
|
|
381
|
+
if (T.has(i)) {
|
|
382
|
+
const w = T.get(i);
|
|
383
|
+
if (w.key === a)
|
|
384
|
+
return w.height;
|
|
385
|
+
}
|
|
386
|
+
let c = 30;
|
|
387
|
+
switch (i.content_type) {
|
|
388
|
+
case "image":
|
|
389
|
+
c = 150;
|
|
390
|
+
break;
|
|
391
|
+
case "table-row":
|
|
392
|
+
c = i.rowHeight || 35;
|
|
393
|
+
break;
|
|
394
|
+
case "table":
|
|
395
|
+
const k = ((i.content || "").match(/<tr/g) || []).length;
|
|
396
|
+
c = Math.max(100, k * 35 + 30);
|
|
397
|
+
break;
|
|
398
|
+
case "flowchart":
|
|
399
|
+
c = 200;
|
|
400
|
+
break;
|
|
401
|
+
default: {
|
|
402
|
+
const b = (i.content || "").length, _ = (i.title || "").length, C = b + _, F = ((g = (i.content || "").match(/[\u4e00-\u9fa5]/g)) == null ? void 0 : g.length) || 0, O = C - F, M = F * 12 + O * 6, $ = Math.max(1, Math.ceil(M / 760));
|
|
403
|
+
c = Math.max(20, $ * 18), i._editing && (c += 20);
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return T.set(i, {
|
|
408
|
+
key: a,
|
|
409
|
+
height: c
|
|
410
|
+
}), c;
|
|
411
|
+
}, Q = ae(() => {
|
|
412
|
+
if (A.value.length === 0) return 30;
|
|
413
|
+
const i = A.value.slice(0, Math.min(100, A.value.length));
|
|
414
|
+
if (i.length === 0) return 30;
|
|
415
|
+
const a = i.reduce((p, d) => p + P(d), 0) / i.length, c = Math.max(20, Math.floor(a * 0.6));
|
|
416
|
+
return Math.min(c, 60);
|
|
417
|
+
});
|
|
418
|
+
let le;
|
|
419
|
+
const ot = (i, a) => {
|
|
420
|
+
e("menu-click", {
|
|
421
|
+
menu: i,
|
|
422
|
+
row: a
|
|
423
|
+
}), le == null || le.onClose(), le = null;
|
|
424
|
+
}, W = (i) => {
|
|
425
|
+
var c, p, d, g, w;
|
|
426
|
+
if (!((d = (p = (c = t.menuConfig) == null ? void 0 : c.body) == null ? void 0 : p.options) != null && d.length)) return;
|
|
427
|
+
le == null || le.onClose(), le = null;
|
|
428
|
+
let a = i.target;
|
|
429
|
+
for (; a && (a != null && a.getAttribute) && !(a != null && a.getAttribute("data-id")) && a !== ((g = r.value) == null ? void 0 : g.$el); )
|
|
430
|
+
a = a.parentNode;
|
|
431
|
+
if ((w = a == null ? void 0 : a.getAttribute) != null && w.call(a, "data-id")) {
|
|
432
|
+
const k = a.getAttribute("data-id"), b = Me(k);
|
|
433
|
+
b && (le = ci({
|
|
434
|
+
e: i,
|
|
435
|
+
row: b,
|
|
436
|
+
menuConfig: t.menuConfig,
|
|
437
|
+
onMenuClick: ot
|
|
438
|
+
}), i.preventDefault(), i.stopPropagation());
|
|
439
|
+
}
|
|
440
|
+
}, pe = (i) => {
|
|
441
|
+
var c, p, d;
|
|
442
|
+
if (!s.value)
|
|
443
|
+
return;
|
|
444
|
+
let a = i.target;
|
|
445
|
+
for (; a && (a != null && a.getAttribute) && !(a != null && a.getAttribute("data-id")) && a !== ((c = r.value) == null ? void 0 : c.$el); )
|
|
446
|
+
if (a = a.parentNode, a != null && a.classList && ["el-popper", "ck-body-wrapper"].some((g) => a.classList.contains(g)))
|
|
447
|
+
return;
|
|
448
|
+
((p = a == null ? void 0 : a.getAttribute) == null ? void 0 : p.call(a, "data-id")) != ((d = s.value) == null ? void 0 : d.node_id) && (s.value._editing = !1, e("edit-closed", {
|
|
449
|
+
row: s.value,
|
|
450
|
+
column: {},
|
|
451
|
+
$table: o == null ? void 0 : o.exposed
|
|
452
|
+
}), s.value = null);
|
|
453
|
+
};
|
|
454
|
+
((xt = t.editConfig) == null ? void 0 : xt.trigger) === "dblclick" && Ve(() => s.value, (i) => {
|
|
455
|
+
document.removeEventListener("click", pe, !0), i && setTimeout(() => {
|
|
456
|
+
document.addEventListener("click", pe, !0);
|
|
457
|
+
}, 200);
|
|
458
|
+
});
|
|
459
|
+
const ye = (i) => JSON.stringify(i.map((a) => {
|
|
460
|
+
var c;
|
|
461
|
+
return {
|
|
462
|
+
id: a[t.rowConfig.keyField],
|
|
463
|
+
content: ((c = a.content) == null ? void 0 : c.length) || 0,
|
|
464
|
+
type: a.content_type,
|
|
465
|
+
editing: a._editing
|
|
466
|
+
};
|
|
467
|
+
})), _e = () => {
|
|
468
|
+
if (!t.pageConfig.enabled) {
|
|
469
|
+
L.value = [{
|
|
470
|
+
items: h.value,
|
|
471
|
+
startIndex: 0,
|
|
472
|
+
endIndex: h.value.length
|
|
473
|
+
}];
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (t.pageData && Object.keys(t.pageData).length) {
|
|
477
|
+
const i = [], a = t.rowConfig.keyField || "node_id", c = /* @__PURE__ */ new Map();
|
|
478
|
+
h.value.forEach((d) => {
|
|
479
|
+
c.set(String(d[a]), d);
|
|
480
|
+
}), Object.keys(t.pageData).sort((d, g) => parseInt(d) - parseInt(g)).forEach((d) => {
|
|
481
|
+
const g = t.pageData[d], w = [];
|
|
482
|
+
g.forEach((k) => {
|
|
483
|
+
const b = c.get(String(k));
|
|
484
|
+
b && w.push(b);
|
|
485
|
+
}), w.length > 0 && i.push({
|
|
486
|
+
items: w,
|
|
487
|
+
pageNumber: parseInt(d),
|
|
488
|
+
height: w.reduce((k, b) => k + P(b), 0)
|
|
489
|
+
});
|
|
490
|
+
}), L.value = i;
|
|
491
|
+
} else {
|
|
492
|
+
const {
|
|
493
|
+
pageHeight: i,
|
|
494
|
+
margin: a,
|
|
495
|
+
headerHeight: c = 0,
|
|
496
|
+
footerHeight: p = 0
|
|
497
|
+
} = t.pageConfig, g = Math.max(100, i - a * 2 - c - p - 20), w = [];
|
|
498
|
+
let k = [], b = 0, _ = 0, C = 1;
|
|
499
|
+
h.value.forEach((F, O) => {
|
|
500
|
+
const M = P(F);
|
|
501
|
+
(F.layer || 0) <= 2 && k.length > 0 ? (w.push({
|
|
502
|
+
items: [...k],
|
|
503
|
+
startIndex: _,
|
|
504
|
+
endIndex: O,
|
|
505
|
+
height: b,
|
|
506
|
+
pageNumber: C++
|
|
507
|
+
}), k = [F], b = M, _ = O) : b + M > g && k.length > 0 ? (w.push({
|
|
508
|
+
items: [...k],
|
|
509
|
+
startIndex: _,
|
|
510
|
+
endIndex: O,
|
|
511
|
+
height: b,
|
|
512
|
+
pageNumber: C++
|
|
513
|
+
}), k = [F], b = Math.min(M, g), _ = O) : (k.push(F), b += M);
|
|
514
|
+
}), k.length > 0 && w.push({
|
|
515
|
+
items: k,
|
|
516
|
+
startIndex: _,
|
|
517
|
+
endIndex: h.value.length,
|
|
518
|
+
height: b,
|
|
519
|
+
pageNumber: C
|
|
520
|
+
}), L.value = w;
|
|
521
|
+
}
|
|
522
|
+
}, De = () => {
|
|
523
|
+
try {
|
|
524
|
+
const i = Array.isArray(t.data) ? t.data : [], a = ye(i);
|
|
525
|
+
if (!(a !== E.value) && h.value.length > 0)
|
|
526
|
+
return;
|
|
527
|
+
E.value = a;
|
|
528
|
+
const p = (t.treeConfig ? di(i, void 0, t.treeConfig) : i).map((g, w) => {
|
|
529
|
+
const k = g[t.rowConfig.keyField], b = S.get(k);
|
|
530
|
+
if (!b || b.content !== g.content || b.content_type !== g.content_type) {
|
|
531
|
+
B.add(k);
|
|
532
|
+
const _ = {
|
|
533
|
+
...g,
|
|
534
|
+
index: w,
|
|
535
|
+
_editing: g._editing || !1,
|
|
536
|
+
_original: (b == null ? void 0 : b._original) || {
|
|
537
|
+
...g
|
|
538
|
+
}
|
|
539
|
+
// 保留原始数据,避免重复深拷贝
|
|
540
|
+
};
|
|
541
|
+
return S.set(k, _), _;
|
|
542
|
+
}
|
|
543
|
+
return b.index = w, b;
|
|
544
|
+
});
|
|
545
|
+
h.value = p, _e();
|
|
546
|
+
const d = new Set(p.map((g) => g[t.rowConfig.keyField]));
|
|
547
|
+
for (const [g] of S)
|
|
548
|
+
d.has(g) || (S.delete(g), B.delete(g));
|
|
549
|
+
} catch {
|
|
550
|
+
h.value = [], L.value = [], S.clear(), B.clear();
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
Ve(() => t.data, (i, a) => {
|
|
554
|
+
try {
|
|
555
|
+
if (!Array.isArray(i))
|
|
556
|
+
return;
|
|
557
|
+
be(() => {
|
|
558
|
+
if (De(), t.pageConfig.enabled) {
|
|
559
|
+
K.value.clear(), x.value.clear();
|
|
560
|
+
for (let c = 0; c < Math.min(3, L.value.length); c++)
|
|
561
|
+
K.value.add(c);
|
|
562
|
+
be(() => {
|
|
563
|
+
re();
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
} catch {
|
|
568
|
+
}
|
|
569
|
+
}, {
|
|
570
|
+
deep: !1,
|
|
571
|
+
immediate: !1
|
|
572
|
+
}), Ve(() => t.pageData, () => {
|
|
573
|
+
if (t.pageConfig.enabled) {
|
|
574
|
+
_e(), K.value.clear(), x.value.clear();
|
|
575
|
+
for (let i = 0; i < Math.min(3, L.value.length); i++)
|
|
576
|
+
K.value.add(i);
|
|
577
|
+
be(() => {
|
|
578
|
+
re();
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
}, {
|
|
582
|
+
deep: !0
|
|
583
|
+
}), Ve(() => t.pageConfig, () => {
|
|
584
|
+
if (t.pageConfig.enabled) {
|
|
585
|
+
_e(), K.value.clear(), x.value.clear();
|
|
586
|
+
for (let i = 0; i < Math.min(3, L.value.length); i++)
|
|
587
|
+
K.value.add(i);
|
|
588
|
+
be(() => {
|
|
589
|
+
re();
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
}, {
|
|
593
|
+
deep: !0
|
|
594
|
+
}), Ve(m, () => e("current-change", {
|
|
595
|
+
row: m.value
|
|
596
|
+
}));
|
|
597
|
+
let Ee = null;
|
|
598
|
+
const se = () => {
|
|
599
|
+
window.ResizeObserver && (Ee = new ResizeObserver((i) => {
|
|
600
|
+
var a, c;
|
|
601
|
+
for (const p of i) {
|
|
602
|
+
const d = (a = p.target.dataset) == null ? void 0 : a.id;
|
|
603
|
+
if (!d) continue;
|
|
604
|
+
const g = Me(d);
|
|
605
|
+
if (!g) continue;
|
|
606
|
+
const w = p.contentRect.height, k = ((c = T.get(g)) == null ? void 0 : c.height) || 0;
|
|
607
|
+
if (Math.abs(k - w) > 5) {
|
|
608
|
+
const b = T.get(g) || {};
|
|
609
|
+
T.set(g, {
|
|
610
|
+
...b,
|
|
611
|
+
height: w
|
|
612
|
+
}), requestAnimationFrame(() => {
|
|
613
|
+
var C;
|
|
614
|
+
const _ = p.target.__vueParentComponent;
|
|
615
|
+
(C = _ == null ? void 0 : _.proxy) != null && C.updateSize && _.proxy.updateSize();
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}), be(() => {
|
|
620
|
+
var c;
|
|
621
|
+
const i = (c = r.value) == null ? void 0 : c.$el;
|
|
622
|
+
if (!i) return;
|
|
623
|
+
i.querySelectorAll("[data-id]").forEach((p) => {
|
|
624
|
+
p.dataset.id && Ee.observe(p);
|
|
625
|
+
});
|
|
626
|
+
}));
|
|
627
|
+
}, fe = () => {
|
|
628
|
+
f.value && (f.value.disconnect(), f.value = null), Ee && (Ee.disconnect(), Ee = null);
|
|
629
|
+
}, re = () => {
|
|
630
|
+
t.pageConfig.enabled && (ne.value && ne.value.disconnect(), ne.value = new IntersectionObserver((i) => {
|
|
631
|
+
i.forEach((a) => {
|
|
632
|
+
const c = parseInt(a.target.dataset.pageIndex);
|
|
633
|
+
if (a.isIntersecting) {
|
|
634
|
+
x.value.add(c);
|
|
635
|
+
for (let p = Math.max(0, c - R); p <= Math.min(L.value.length - 1, c + R); p++)
|
|
636
|
+
K.value.add(p);
|
|
637
|
+
} else
|
|
638
|
+
x.value.delete(c), setTimeout(() => {
|
|
639
|
+
x.value.has(c) || Array.from(x.value).some((d) => Math.abs(d - c) <= R * 2) || K.value.delete(c);
|
|
640
|
+
}, 3e3);
|
|
641
|
+
});
|
|
642
|
+
}, {
|
|
643
|
+
root: null,
|
|
644
|
+
rootMargin: "100px",
|
|
645
|
+
threshold: 0.01
|
|
646
|
+
}), be(() => {
|
|
647
|
+
const i = document.querySelector(".a4-pages-container");
|
|
648
|
+
i && i.querySelectorAll(".a4-page-placeholder").forEach((c) => {
|
|
649
|
+
ne.value.observe(c);
|
|
650
|
+
});
|
|
651
|
+
}));
|
|
652
|
+
};
|
|
653
|
+
ft(() => {
|
|
654
|
+
De(), be(() => {
|
|
655
|
+
var i;
|
|
656
|
+
if (se(), we.setup(), re(), ((i = t.editConfig) == null ? void 0 : i.trigger) === "contenteditable" && (document.addEventListener("selectionchange", pt), document.addEventListener("mouseup", vt)), t.pageConfig.enabled)
|
|
657
|
+
for (let a = 0; a < Math.min(3, L.value.length); a++)
|
|
658
|
+
K.value.add(a);
|
|
659
|
+
}), y.value = !0;
|
|
660
|
+
}), lt(() => {
|
|
661
|
+
var i;
|
|
662
|
+
fe(), we.cleanup(), ne.value && (ne.value.disconnect(), ne.value = null), ((i = t.editConfig) == null ? void 0 : i.trigger) === "contenteditable" && (document.removeEventListener("selectionchange", pt), document.removeEventListener("mouseup", vt)), Se && clearTimeout(Se), I = /* @__PURE__ */ new Map(), S.clear(), K.value.clear(), x.value.clear();
|
|
663
|
+
});
|
|
664
|
+
const we = {
|
|
665
|
+
handlers: /* @__PURE__ */ new Map(),
|
|
666
|
+
setup() {
|
|
667
|
+
be(() => {
|
|
668
|
+
var a;
|
|
669
|
+
const i = (a = r.value) == null ? void 0 : a.$el;
|
|
670
|
+
i && (i.addEventListener("click", this.handleClick.bind(this), {
|
|
671
|
+
passive: !0
|
|
672
|
+
}), i.addEventListener("dblclick", this.handleDblClick.bind(this), {
|
|
673
|
+
passive: !0
|
|
674
|
+
}));
|
|
675
|
+
});
|
|
676
|
+
},
|
|
677
|
+
handleClick(i) {
|
|
678
|
+
const a = i.target.closest("[data-id]");
|
|
679
|
+
if (!a) return;
|
|
680
|
+
const c = a.dataset.id, p = Me(c);
|
|
681
|
+
p && Je(p);
|
|
682
|
+
},
|
|
683
|
+
handleDblClick(i) {
|
|
684
|
+
var d;
|
|
685
|
+
if (!((d = t.editConfig) != null && d.trigger) === "dblclick") return;
|
|
686
|
+
const a = i.target.closest("[data-id]");
|
|
687
|
+
if (!a) return;
|
|
688
|
+
const c = a.dataset.id, p = Me(c);
|
|
689
|
+
p && Ne(p);
|
|
690
|
+
},
|
|
691
|
+
cleanup() {
|
|
692
|
+
var a, c;
|
|
693
|
+
const i = (c = (a = r.value) == null ? void 0 : a.$el) == null ? void 0 : c.querySelector(".virtual-table-wrapper");
|
|
694
|
+
i && (i.removeEventListener("click", this.handleClick), i.removeEventListener("dblclick", this.handleDblClick));
|
|
695
|
+
}
|
|
696
|
+
}, de = (i) => {
|
|
697
|
+
Je(i);
|
|
698
|
+
}, X = (i) => Ne(i);
|
|
699
|
+
let Ce = null, Fe;
|
|
700
|
+
const me = ({
|
|
701
|
+
row: i,
|
|
702
|
+
column: a
|
|
703
|
+
}, c, p) => {
|
|
704
|
+
var w, k;
|
|
705
|
+
const d = p || c.target, g = $t(d, "virtual-table-cell", (w = r.value) == null ? void 0 : w.$el);
|
|
706
|
+
Ce === g && Fe && (clearTimeout(Fe), Ce = null), ((k = s.value) == null ? void 0 : k[t.rowConfig.keyField]) != (i == null ? void 0 : i[t.rowConfig.keyField]) && setTimeout(() => {
|
|
707
|
+
var _, C;
|
|
708
|
+
s.value = i;
|
|
709
|
+
let b = (_ = d == null ? void 0 : d.getAttribute) == null ? void 0 : _.call(d, "field");
|
|
710
|
+
if (!b) {
|
|
711
|
+
try {
|
|
712
|
+
const F = document.getSelection();
|
|
713
|
+
let O = F == null ? void 0 : F.anchorNode;
|
|
714
|
+
O && O.nodeType === 3 && (O = O.parentElement);
|
|
715
|
+
const M = (C = O == null ? void 0 : O.closest) == null ? void 0 : C.call(O, "[field]");
|
|
716
|
+
M && (b = M.getAttribute("field"));
|
|
717
|
+
} catch {
|
|
718
|
+
}
|
|
719
|
+
if (!b && (c != null && c.composedPath)) {
|
|
720
|
+
for (const F of c.composedPath())
|
|
721
|
+
if (F != null && F.getAttribute && F.getAttribute("field")) {
|
|
722
|
+
b = F.getAttribute("field");
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
e("edit-activated", {
|
|
728
|
+
row: i,
|
|
729
|
+
column: {
|
|
730
|
+
...a,
|
|
731
|
+
field: b
|
|
732
|
+
},
|
|
733
|
+
$table: o == null ? void 0 : o.exposed
|
|
734
|
+
});
|
|
735
|
+
}, 200);
|
|
736
|
+
}, xe = ({
|
|
737
|
+
row: i,
|
|
738
|
+
column: a
|
|
739
|
+
}, c, p) => {
|
|
740
|
+
var g;
|
|
741
|
+
const d = p || c.target;
|
|
742
|
+
Ce = $t(d, "virtual-table-cell", (g = r.value) == null ? void 0 : g.$el), Fe && clearTimeout(Fe), Fe = setTimeout(() => {
|
|
743
|
+
var b, _, C, F, O;
|
|
744
|
+
const w = i.content_type;
|
|
745
|
+
let k = (b = d == null ? void 0 : d.getAttribute) == null ? void 0 : b.call(d, "field");
|
|
746
|
+
if (!k) {
|
|
747
|
+
try {
|
|
748
|
+
const M = document.getSelection();
|
|
749
|
+
let $ = M == null ? void 0 : M.anchorNode;
|
|
750
|
+
$ && $.nodeType === 3 && ($ = $.parentElement);
|
|
751
|
+
const Y = (_ = $ == null ? void 0 : $.closest) == null ? void 0 : _.call($, "[field]");
|
|
752
|
+
Y && (k = Y.getAttribute("field"));
|
|
753
|
+
} catch {
|
|
754
|
+
}
|
|
755
|
+
if (!k && (c != null && c.composedPath)) {
|
|
756
|
+
for (const M of c.composedPath())
|
|
757
|
+
if (M != null && M.getAttribute && M.getAttribute("field")) {
|
|
758
|
+
k = M.getAttribute("field");
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
if (w !== "table") {
|
|
764
|
+
if (w === "text") {
|
|
765
|
+
let M = null, $ = null;
|
|
766
|
+
if ((C = d == null ? void 0 : d.getAttribute) != null && C.call(d, "field") ? M = d : (F = d == null ? void 0 : d.closest) != null && F.call(d, "[field]") && (M = d.closest("[field]")), M && ($ = M.textContent), k && $ !== void 0 && $ !== null) {
|
|
767
|
+
$ = $.trim();
|
|
768
|
+
const Y = ((O = i[k]) == null ? void 0 : O.trim()) || "";
|
|
769
|
+
$ !== Y && (i[k] = $);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
e("edit-closed", {
|
|
774
|
+
row: i,
|
|
775
|
+
column: {
|
|
776
|
+
...a,
|
|
777
|
+
field: k
|
|
778
|
+
},
|
|
779
|
+
$table: o == null ? void 0 : o.exposed
|
|
780
|
+
});
|
|
781
|
+
}, 50);
|
|
782
|
+
};
|
|
783
|
+
let H = null, Se = null;
|
|
784
|
+
const Pe = (i) => {
|
|
785
|
+
var a;
|
|
786
|
+
((a = t.editConfig) == null ? void 0 : a.trigger) === "contenteditable" && gt("focusin", i);
|
|
787
|
+
}, We = (i) => {
|
|
788
|
+
var a, c, p, d, g;
|
|
789
|
+
if (((a = t.editConfig) == null ? void 0 : a.trigger) === "contenteditable")
|
|
790
|
+
if (H != null && H.cellEl) {
|
|
791
|
+
let w = H.fieldEl;
|
|
792
|
+
!w && H.field && (w = (p = (c = H.cellEl) == null ? void 0 : c.querySelector) == null ? void 0 : p.call(c, `[field="${H.field}"]`)), w || (w = ((g = (d = H.cellEl).querySelector) == null ? void 0 : g.call(d, "[field]")) || H.cellEl), xe(H, {
|
|
793
|
+
target: w
|
|
794
|
+
}, w), H = null;
|
|
795
|
+
} else
|
|
796
|
+
gt("focusout", i);
|
|
797
|
+
}, gt = (i, a) => {
|
|
798
|
+
var c, p, d, g, w, k;
|
|
799
|
+
try {
|
|
800
|
+
const b = document.getSelection();
|
|
801
|
+
let _ = b == null ? void 0 : b.anchorNode;
|
|
802
|
+
_ && _.nodeType === 3 && (_ = _.parentElement);
|
|
803
|
+
const C = (c = _ == null ? void 0 : _.closest) == null ? void 0 : c.call(_, ".virtual-table-cell"), F = (p = _ == null ? void 0 : _.closest) == null ? void 0 : p.call(_, ".virtual-table-row");
|
|
804
|
+
if (!C || !F) return;
|
|
805
|
+
const O = F.getAttribute("data-id"), M = C.getAttribute("data-prop"), $ = Me(O), Y = $e.value.find((oe) => `${oe.prop}` == `${M}`) || {}, j = ((d = _ == null ? void 0 : _.closest) == null ? void 0 : d.call(_, "[field]")) || null, V = ((g = j == null ? void 0 : j.getAttribute) == null ? void 0 : g.call(j, "field")) || void 0;
|
|
806
|
+
i === "focusin" ? (H = {
|
|
807
|
+
row: $,
|
|
808
|
+
column: Y,
|
|
809
|
+
cellEl: C,
|
|
810
|
+
rowEl: F,
|
|
811
|
+
fieldEl: j,
|
|
812
|
+
field: V
|
|
813
|
+
}, me({
|
|
814
|
+
row: $,
|
|
815
|
+
column: Y
|
|
816
|
+
}, a, j || ((w = _ == null ? void 0 : _.closest) == null ? void 0 : w.call(_, "[field]")))) : xe({
|
|
817
|
+
row: $,
|
|
818
|
+
column: Y
|
|
819
|
+
}, a, j || ((k = _ == null ? void 0 : _.closest) == null ? void 0 : k.call(_, "[field]")));
|
|
820
|
+
} catch {
|
|
821
|
+
}
|
|
822
|
+
}, pt = () => {
|
|
823
|
+
var i;
|
|
824
|
+
((i = t.editConfig) == null ? void 0 : i.trigger) === "contenteditable" && (Se && clearTimeout(Se), Se = setTimeout(() => {
|
|
825
|
+
var a, c, p, d, g, w, k, b, _, C, F, O, M, $;
|
|
826
|
+
try {
|
|
827
|
+
const Y = document.getSelection();
|
|
828
|
+
if (Y.rangeCount === 0) return;
|
|
829
|
+
const j = Y.getRangeAt(0);
|
|
830
|
+
let V = j.startContainer;
|
|
831
|
+
V.nodeType === 3 && (V = V.parentElement);
|
|
832
|
+
const oe = (a = V == null ? void 0 : V.closest) == null ? void 0 : a.call(V, ".virtual-table-cell"), ie = (c = V == null ? void 0 : V.closest) == null ? void 0 : c.call(V, ".virtual-table-row");
|
|
833
|
+
if (!oe || !ie) return;
|
|
834
|
+
const Le = ie.getAttribute("data-id"), Re = oe.getAttribute("data-prop"), ge = Me(Le), ce = $e.value.find((G) => `${G.prop}` == `${Re}`) || {};
|
|
835
|
+
if (!H || ((p = H.row) == null ? void 0 : p[t.rowConfig.keyField]) !== (ge == null ? void 0 : ge[t.rowConfig.keyField]) || ((d = H.column) == null ? void 0 : d.prop) !== (ce == null ? void 0 : ce.prop)) {
|
|
836
|
+
if (H) {
|
|
837
|
+
let G = H.fieldEl;
|
|
838
|
+
!G && H.field && (G = (w = (g = H.cellEl) == null ? void 0 : g.querySelector) == null ? void 0 : w.call(g, `[field="${H.field}"]`)), G || (G = ((b = (k = H.cellEl) == null ? void 0 : k.querySelector) == null ? void 0 : b.call(k, "[field]")) || H.cellEl), xe(H, {
|
|
839
|
+
target: G
|
|
840
|
+
}, G);
|
|
841
|
+
}
|
|
842
|
+
H = {
|
|
843
|
+
row: ge,
|
|
844
|
+
column: ce,
|
|
845
|
+
cellEl: oe,
|
|
846
|
+
rowEl: ie,
|
|
847
|
+
fieldEl: ((_ = V == null ? void 0 : V.closest) == null ? void 0 : _.call(V, "[field]")) || null,
|
|
848
|
+
field: ((O = (F = ((C = V == null ? void 0 : V.closest) == null ? void 0 : C.call(V, "[field]")) || null) == null ? void 0 : F.getAttribute) == null ? void 0 : O.call(F, "field")) || void 0
|
|
849
|
+
}, me({
|
|
850
|
+
row: ge,
|
|
851
|
+
column: ce
|
|
852
|
+
}, {
|
|
853
|
+
target: oe
|
|
854
|
+
}, oe);
|
|
855
|
+
}
|
|
856
|
+
if (Y.toString()) {
|
|
857
|
+
const G = j.endContainer.nodeType === 3 ? j.endContainer.parentElement : j.endContainer, Ae = (M = G == null ? void 0 : G.closest) == null ? void 0 : M.call(G, ".virtual-table-cell"), Qe = ($ = G == null ? void 0 : G.closest) == null ? void 0 : $.call(G, ".virtual-table-row");
|
|
858
|
+
}
|
|
859
|
+
} catch {
|
|
860
|
+
}
|
|
861
|
+
}, 50));
|
|
862
|
+
}, vt = () => {
|
|
863
|
+
var i;
|
|
864
|
+
((i = t.editConfig) == null ? void 0 : i.trigger) === "contenteditable" && setTimeout(() => {
|
|
865
|
+
var p, d, g, w;
|
|
866
|
+
const a = document.getSelection();
|
|
867
|
+
if (!a) return;
|
|
868
|
+
const c = a.toString();
|
|
869
|
+
if (c) {
|
|
870
|
+
const k = a.rangeCount > 0 ? a.getRangeAt(0) : null;
|
|
871
|
+
let b = null, _ = null;
|
|
872
|
+
try {
|
|
873
|
+
if (k) {
|
|
874
|
+
let C = k.startContainer;
|
|
875
|
+
(C == null ? void 0 : C.nodeType) === 3 && (C = C.parentElement);
|
|
876
|
+
const F = (p = C == null ? void 0 : C.closest) == null ? void 0 : p.call(C, ".virtual-table-cell"), O = (d = C == null ? void 0 : C.closest) == null ? void 0 : d.call(C, ".virtual-table-row");
|
|
877
|
+
b = F && O ? {
|
|
878
|
+
rowId: O.getAttribute("data-id"),
|
|
879
|
+
prop: F.getAttribute("data-prop")
|
|
880
|
+
} : null;
|
|
881
|
+
let M = k.endContainer;
|
|
882
|
+
(M == null ? void 0 : M.nodeType) === 3 && (M = M.parentElement);
|
|
883
|
+
const $ = (g = M == null ? void 0 : M.closest) == null ? void 0 : g.call(M, ".virtual-table-cell"), Y = (w = M == null ? void 0 : M.closest) == null ? void 0 : w.call(M, ".virtual-table-row");
|
|
884
|
+
_ = $ && Y ? {
|
|
885
|
+
rowId: Y.getAttribute("data-id"),
|
|
886
|
+
prop: $.getAttribute("data-prop")
|
|
887
|
+
} : null;
|
|
888
|
+
}
|
|
889
|
+
} catch {
|
|
890
|
+
}
|
|
891
|
+
e("selection-change", {
|
|
892
|
+
text: c,
|
|
893
|
+
selection: a,
|
|
894
|
+
range: k,
|
|
895
|
+
start: b,
|
|
896
|
+
end: _
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
}, 10);
|
|
900
|
+
}, Zt = (i) => (i == null ? void 0 : i._editing) === !0, Qt = (i) => i != null && i.parent_id ? I.get(i.parent_id) : null, en = (i) => {
|
|
901
|
+
var c;
|
|
902
|
+
const a = h.value.findIndex((p) => p[t.rowConfig.keyField] == i[t.rowConfig.keyField]);
|
|
903
|
+
return a < 1 ? null : ((c = h.value[a - 1]) == null ? void 0 : c.layer) === i.layer ? h.value[a - 1] : null;
|
|
904
|
+
}, tn = (i) => {
|
|
905
|
+
const a = h.value.findIndex((c) => c[t.rowConfig.keyField] == i[t.rowConfig.keyField]);
|
|
906
|
+
return a >= h.value.length - 1 ? null : h.value[a + 1];
|
|
907
|
+
}, Me = (i) => {
|
|
908
|
+
if (!i) return null;
|
|
909
|
+
let a = S.get(i);
|
|
910
|
+
return a || (typeof i == "number" ? S.get(`${i}`) : typeof i == "string" && /^\d+$/.test(i) ? S.get(Number(i)) : null);
|
|
911
|
+
};
|
|
912
|
+
let Ge = null;
|
|
913
|
+
const nn = (i) => {
|
|
914
|
+
Ge && cancelAnimationFrame(Ge), Ge = requestAnimationFrame(() => {
|
|
915
|
+
var p;
|
|
916
|
+
const a = t.rowConfig.keyField, c = i[a];
|
|
917
|
+
if (t.pageConfig.enabled) {
|
|
918
|
+
let d = -1;
|
|
919
|
+
for (let g = 0; g < L.value.length; g++)
|
|
920
|
+
if (L.value[g].items.some((b) => b[a] === c)) {
|
|
921
|
+
d = g;
|
|
922
|
+
break;
|
|
923
|
+
}
|
|
924
|
+
if (d !== -1) {
|
|
925
|
+
for (let g = Math.max(0, d - 1); g <= Math.min(L.value.length - 1, d + 1); g++)
|
|
926
|
+
K.value.has(g) || K.value.add(g);
|
|
927
|
+
be(() => {
|
|
928
|
+
const g = document.querySelector(".a4-pages-container");
|
|
929
|
+
if (!g) return;
|
|
930
|
+
const w = (k = 0) => {
|
|
931
|
+
const b = g.querySelector(`[data-id="${c}"]`);
|
|
932
|
+
if (b) {
|
|
933
|
+
let _ = 0, C = b;
|
|
934
|
+
for (; C && C !== g; )
|
|
935
|
+
_ += C.offsetTop, C = C.offsetParent;
|
|
936
|
+
const F = g.clientHeight;
|
|
937
|
+
let O = _ - F * 0.3;
|
|
938
|
+
O = Math.max(0, O);
|
|
939
|
+
const M = g.scrollTop, $ = Math.abs(O - M), Y = (j) => {
|
|
940
|
+
const V = g.scrollTop, oe = j - V, ie = Math.min(800, Math.max(300, $ * 0.5)), Le = performance.now(), Re = (ce) => ce < 0.5 ? 4 * ce * ce * ce : 1 - Math.pow(-2 * ce + 2, 3) / 2, ge = (ce) => {
|
|
941
|
+
const ze = ce - Le, G = Math.min(ze / ie, 1), Ae = Re(G), Qe = V + oe * Ae;
|
|
942
|
+
g.scrollTop = Qe, G < 1 ? requestAnimationFrame(ge) : setTimeout(() => {
|
|
943
|
+
g.scrollTop = j;
|
|
944
|
+
}, 50);
|
|
945
|
+
};
|
|
946
|
+
requestAnimationFrame(ge);
|
|
947
|
+
};
|
|
948
|
+
$ > 3e3 ? g.scrollTo({
|
|
949
|
+
top: O,
|
|
950
|
+
behavior: "instant"
|
|
951
|
+
}) : Y(O), b.classList.add("row--highlight"), setTimeout(() => {
|
|
952
|
+
b.classList.remove("row--highlight");
|
|
953
|
+
}, 1500);
|
|
954
|
+
} else k < 10 && setTimeout(() => w(k + 1), 150);
|
|
955
|
+
};
|
|
956
|
+
setTimeout(w, 200);
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
} else {
|
|
960
|
+
const d = h.value.findIndex((g) => g[a] === c);
|
|
961
|
+
d !== -1 && ((p = r.value) != null && p.scrollToItem) && r.value.scrollToItem(d);
|
|
962
|
+
}
|
|
963
|
+
Ge = null;
|
|
964
|
+
});
|
|
965
|
+
}, Je = (i) => {
|
|
966
|
+
if (i) {
|
|
967
|
+
if (!y.value) {
|
|
968
|
+
setTimeout(() => Je(i), 200);
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
971
|
+
m.value = i, m.value !== s.value && s.value && (s.value._editing = !1, setTimeout(() => {
|
|
972
|
+
s.value = null;
|
|
973
|
+
}, 200));
|
|
974
|
+
}
|
|
975
|
+
}, Ne = (i, a) => new Promise((c) => {
|
|
976
|
+
var p, d;
|
|
977
|
+
if (!((p = t == null ? void 0 : t.editConfig) != null && p.beforeEditMethod && typeof ((d = t == null ? void 0 : t.editConfig) == null ? void 0 : d.beforeEditMethod) == "function" && !t.editConfig.beforeEditMethod({
|
|
978
|
+
row: i
|
|
979
|
+
}))) {
|
|
980
|
+
if (!i || !y.value) {
|
|
981
|
+
setTimeout(() => Ne(i), 200);
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
984
|
+
i !== s.value && (h.value.forEach((g) => {
|
|
985
|
+
g._editing && e("edit-closed", {
|
|
986
|
+
row: g,
|
|
987
|
+
column: {
|
|
988
|
+
field: a
|
|
989
|
+
},
|
|
990
|
+
$table: o == null ? void 0 : o.exposed
|
|
991
|
+
}), g._editing = !1;
|
|
992
|
+
}), i._editing = !0, setTimeout(() => {
|
|
993
|
+
s.value = i, e("edit-activated", {
|
|
994
|
+
row: i,
|
|
995
|
+
column: {
|
|
996
|
+
field: a
|
|
997
|
+
},
|
|
998
|
+
$table: o == null ? void 0 : o.exposed
|
|
999
|
+
}), c(!0);
|
|
1000
|
+
}));
|
|
1001
|
+
}
|
|
1002
|
+
}), ln = (i) => Ne(i), at = () => {
|
|
1003
|
+
if (_e(), t.pageConfig.enabled) {
|
|
1004
|
+
const i = Array.from(x.value);
|
|
1005
|
+
if (i.length > 0) {
|
|
1006
|
+
const a = Math.min(...i);
|
|
1007
|
+
for (let c = Math.max(0, a - 1); c <= Math.min(L.value.length - 1, a + 2); c++)
|
|
1008
|
+
K.value.add(c);
|
|
1009
|
+
} else
|
|
1010
|
+
for (let a = 0; a < Math.min(3, L.value.length); a++)
|
|
1011
|
+
K.value.add(a);
|
|
1012
|
+
be(() => {
|
|
1013
|
+
re();
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
be(() => {
|
|
1017
|
+
!t.pageConfig.enabled && r.value && r.value.$forceUpdate && r.value.$forceUpdate();
|
|
1018
|
+
});
|
|
1019
|
+
}, on = (i, a) => new Promise((c) => {
|
|
1020
|
+
let p = -1;
|
|
1021
|
+
if (a == -1) {
|
|
1022
|
+
const d = Me(i.parent_id);
|
|
1023
|
+
for (p = h.value.findIndex((g) => g[t.rowConfig.keyField] == d[t.rowConfig.keyField]) + 1; h.value[p].parent_id == d[t.rowConfig.keyField]; )
|
|
1024
|
+
p += 1;
|
|
1025
|
+
} else
|
|
1026
|
+
p = h.value.findIndex((d) => d[t.rowConfig.keyField] == a[t.rowConfig.keyField]);
|
|
1027
|
+
I.set(i.node_id, i), S.set(i[t.rowConfig.keyField], i), h.value.splice(p, 0, i), at(), c({
|
|
1028
|
+
row: i
|
|
1029
|
+
});
|
|
1030
|
+
}), an = (i, a) => new Promise((c) => {
|
|
1031
|
+
const p = h.value.findIndex((d) => d[t.rowConfig.keyField] == a[t.rowConfig.keyField]) + 1;
|
|
1032
|
+
I.set(i.node_id, i), S.set(i[t.rowConfig.keyField], i), h.value.splice(p, 0, i), at(), c({
|
|
1033
|
+
row: i
|
|
1034
|
+
});
|
|
1035
|
+
}), mt = (i) => {
|
|
1036
|
+
const a = h.value.findIndex((c) => c[t.rowConfig.keyField] == i[t.rowConfig.keyField] || c === i);
|
|
1037
|
+
if (a > -1) {
|
|
1038
|
+
const c = i[t.rowConfig.keyField];
|
|
1039
|
+
I.delete(i.node_id), S.delete(c), h.value.splice(a, 1), at();
|
|
1040
|
+
}
|
|
1041
|
+
}, sn = (i, a) => {
|
|
1042
|
+
if (!i || !i[t.rowConfig.keyField]) return !1;
|
|
1043
|
+
const c = i._original;
|
|
1044
|
+
return c ? a ? i[a] !== c[a] : Object.keys(c).some((p) => c[p] !== i[p]) : !1;
|
|
1045
|
+
}, rn = (i) => i && i[t.rowConfig.keyField] && !i._original, cn = (i, a) => {
|
|
1046
|
+
i && i[t.rowConfig.keyField] && (a && Object.assign(i, a), i._original = {
|
|
1047
|
+
...i,
|
|
1048
|
+
_editing: void 0,
|
|
1049
|
+
_X_ROW_CHILD: void 0,
|
|
1050
|
+
_original: void 0
|
|
1051
|
+
});
|
|
1052
|
+
}, dn = (i) => {
|
|
1053
|
+
if (i && i[t.rowConfig.keyField]) {
|
|
1054
|
+
const a = Me(i[t.rowConfig.keyField]);
|
|
1055
|
+
a._original ? Object.assign(a, a._original) : mt(a);
|
|
1056
|
+
}
|
|
1057
|
+
}, un = () => {
|
|
1058
|
+
}, hn = () => {
|
|
1059
|
+
m.value = {};
|
|
1060
|
+
}, yt = (i) => {
|
|
1061
|
+
var c, p, d;
|
|
1062
|
+
let a = h.value.findIndex((g) => g[t.rowConfig.keyField] == i[t.rowConfig.keyField]);
|
|
1063
|
+
if (a > -1 && t.treeConfig) {
|
|
1064
|
+
const g = ((c = t.treeConfig) == null ? void 0 : c.keyField) || ((p = t.treeConfig) == null ? void 0 : p.rowField) || "node_id", w = ((d = t.treeConfig) == null ? void 0 : d.parentField) || "parent_id", k = [], b = /* @__PURE__ */ new Map();
|
|
1065
|
+
b.set(i[g], !0);
|
|
1066
|
+
for (let _ = a + 1; _ < h.value.length; _++) {
|
|
1067
|
+
const C = h.value[_];
|
|
1068
|
+
if (C && b.has(C[w]))
|
|
1069
|
+
k.push(C), b.set(C[g]);
|
|
1070
|
+
else
|
|
1071
|
+
break;
|
|
1072
|
+
}
|
|
1073
|
+
return k;
|
|
1074
|
+
}
|
|
1075
|
+
return [];
|
|
1076
|
+
};
|
|
1077
|
+
l({
|
|
1078
|
+
isEditByRow: Zt,
|
|
1079
|
+
getParentRow: Qt,
|
|
1080
|
+
getSiblingRow: en,
|
|
1081
|
+
getNextRow: tn,
|
|
1082
|
+
getRowById: Me,
|
|
1083
|
+
scrollToRow: nn,
|
|
1084
|
+
setCurrentRow: Je,
|
|
1085
|
+
setEditRow: Ne,
|
|
1086
|
+
setEditCell: ln,
|
|
1087
|
+
insertAt: on,
|
|
1088
|
+
insertNextAt: an,
|
|
1089
|
+
isUpdateByRow: sn,
|
|
1090
|
+
isInsertByRow: rn,
|
|
1091
|
+
reloadRow: cn,
|
|
1092
|
+
revertData: dn,
|
|
1093
|
+
remove: mt,
|
|
1094
|
+
setAllTreeExpand: un,
|
|
1095
|
+
clearCurrentRow: hn,
|
|
1096
|
+
getAllChilds: yt
|
|
1097
|
+
});
|
|
1098
|
+
const $e = ae(() => n.default().filter((i) => {
|
|
1099
|
+
var a;
|
|
1100
|
+
return ((a = i.type) == null ? void 0 : a.name) === "VirtualTableColumn";
|
|
1101
|
+
}).map((i) => {
|
|
1102
|
+
var a, c, p;
|
|
1103
|
+
return {
|
|
1104
|
+
prop: (a = i.props) == null ? void 0 : a.prop,
|
|
1105
|
+
title: (c = i.props) == null ? void 0 : c.title,
|
|
1106
|
+
width: (p = i.props) == null ? void 0 : p.width,
|
|
1107
|
+
slots: i.children
|
|
1108
|
+
};
|
|
1109
|
+
})), Xe = (i) => {
|
|
1110
|
+
try {
|
|
1111
|
+
return i === 0 ? {
|
|
1112
|
+
width: "0px"
|
|
1113
|
+
} : i ? {
|
|
1114
|
+
flex: /^\d+$/.test(i) ? `0 0 ${i}px` : `0 0 ${i}`
|
|
1115
|
+
} : {
|
|
1116
|
+
flex: "1 1 100%"
|
|
1117
|
+
};
|
|
1118
|
+
} catch (a) {
|
|
1119
|
+
return console.warn("[VirtualTable] computeColumnWidth error:", a), {
|
|
1120
|
+
flex: "1 1 100%"
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
}, bt = ae(() => {
|
|
1124
|
+
var i;
|
|
1125
|
+
return (i = t.treeConfig) != null && i.childCurrent && m.value ? yt(m.value).map((a) => a[t.rowConfig.keyField]) : [];
|
|
1126
|
+
}), _t = te({
|
|
1127
|
+
viewStartIndex: 0,
|
|
1128
|
+
viewEndIndex: 0,
|
|
1129
|
+
visibleStartIndex: 0,
|
|
1130
|
+
visibleEndIndex: 0
|
|
1131
|
+
});
|
|
1132
|
+
let Ye = null, Ze = null;
|
|
1133
|
+
const fn = (i, a) => {
|
|
1134
|
+
Ye && cancelAnimationFrame(Ye), Ye = requestAnimationFrame(() => {
|
|
1135
|
+
e("scroll-end", {
|
|
1136
|
+
..._t.value
|
|
1137
|
+
}), Ye = null;
|
|
1138
|
+
});
|
|
1139
|
+
}, gn = (i, a, c, p) => {
|
|
1140
|
+
Ze && cancelAnimationFrame(Ze), Ze = requestAnimationFrame(() => {
|
|
1141
|
+
_t.value = {
|
|
1142
|
+
viewStartIndex: i,
|
|
1143
|
+
viewEndIndex: a,
|
|
1144
|
+
visibleStartIndex: c,
|
|
1145
|
+
visibleEndIndex: p
|
|
1146
|
+
}, Ze = null;
|
|
1147
|
+
});
|
|
1148
|
+
}, pn = (i, a) => {
|
|
1149
|
+
var $, Y;
|
|
1150
|
+
const {
|
|
1151
|
+
pageHeight: c,
|
|
1152
|
+
margin: p,
|
|
1153
|
+
showPageBorder: d,
|
|
1154
|
+
pageBorderPadding: g,
|
|
1155
|
+
pageBorderStyle: w,
|
|
1156
|
+
showPageHeader: k,
|
|
1157
|
+
headerHeight: b = 0,
|
|
1158
|
+
footerHeight: _ = 0,
|
|
1159
|
+
showPageNumber: C
|
|
1160
|
+
} = t.pageConfig, F = i.pageNumber || a + 1, M = Math.max(100, c - p * 2 - b - _ - 20);
|
|
1161
|
+
return K.value.has(a) ? q(U, null, [k !== !1 && (n["page-header"] || b > 0) ? q("div", {
|
|
1162
|
+
class: "a4-page-header",
|
|
1163
|
+
style: {
|
|
1164
|
+
minHeight: `${Math.max(b, 1)}px`
|
|
1165
|
+
}
|
|
1166
|
+
}, [($ = n["page-header"]) == null ? void 0 : $.call(n, {
|
|
1167
|
+
pageNumber: F,
|
|
1168
|
+
pageIndex: a,
|
|
1169
|
+
totalPages: L.value.length
|
|
1170
|
+
})]) : null, a === 0 && t.showHeader ? q("div", {
|
|
1171
|
+
class: "a4-table-header"
|
|
1172
|
+
}, [q("div", {
|
|
1173
|
+
class: "virtual-table-header we-vt-table--header we-vt-table--header-wrapper"
|
|
1174
|
+
}, [$e.value.map((j) => {
|
|
1175
|
+
var V, oe, ie;
|
|
1176
|
+
return q("div", {
|
|
1177
|
+
class: "we-vt-header--column",
|
|
1178
|
+
key: j.prop,
|
|
1179
|
+
style: Xe(j.width)
|
|
1180
|
+
}, [q("div", {
|
|
1181
|
+
class: "we-vt-cell"
|
|
1182
|
+
}, [(V = j.slots) != null && V.header ? (ie = (oe = j.slots) == null ? void 0 : oe.header) == null ? void 0 : ie.call(oe, {
|
|
1183
|
+
column: j
|
|
1184
|
+
}) : j.title])]);
|
|
1185
|
+
})])]) : null, q("div", {
|
|
1186
|
+
class: "a4-page-content",
|
|
1187
|
+
style: {
|
|
1188
|
+
minHeight: `${M}px`,
|
|
1189
|
+
...d ? {
|
|
1190
|
+
border: w,
|
|
1191
|
+
padding: `${g}px`
|
|
1192
|
+
} : {}
|
|
1193
|
+
}
|
|
1194
|
+
}, [i.items.map((j) => {
|
|
1195
|
+
var V, oe;
|
|
1196
|
+
return q("div", {
|
|
1197
|
+
key: j[t.rowConfig.keyField],
|
|
1198
|
+
"data-id": j[t.rowConfig.keyField],
|
|
1199
|
+
class: {
|
|
1200
|
+
"virtual-table-row": !0,
|
|
1201
|
+
"we-vt-body--row": !0,
|
|
1202
|
+
"row--current": j[t.rowConfig.keyField] === ((V = m.value) == null ? void 0 : V[t.rowConfig.keyField]) || ((oe = t.treeConfig) == null ? void 0 : oe.childCurrent) && bt.value.includes(j[t.rowConfig.keyField])
|
|
1203
|
+
},
|
|
1204
|
+
style: {
|
|
1205
|
+
width: "100%"
|
|
1206
|
+
},
|
|
1207
|
+
onClick: () => de(j),
|
|
1208
|
+
onDblclick: () => X(j)
|
|
1209
|
+
}, [$e.value.map((ie) => {
|
|
1210
|
+
var Le, Re, ge, ce, ze, G, Ae;
|
|
1211
|
+
return q("div", {
|
|
1212
|
+
key: ie.prop,
|
|
1213
|
+
class: "virtual-table-cell we-vt-cell",
|
|
1214
|
+
style: Xe(ie.width),
|
|
1215
|
+
"data-prop": ie.prop
|
|
1216
|
+
}, [j._editing && ((Le = t.editConfig) == null ? void 0 : Le.trigger) === "dblclick" ? ((Re = ie.slots) == null ? void 0 : Re.edit) && ((ce = (ge = ie.slots) == null ? void 0 : ge.edit) == null ? void 0 : ce.call(ge, {
|
|
1217
|
+
row: j,
|
|
1218
|
+
column: ie
|
|
1219
|
+
})) : ((ze = ie.slots) == null ? void 0 : ze.default) && ((Ae = (G = ie.slots) == null ? void 0 : G.default) == null ? void 0 : Ae.call(G, {
|
|
1220
|
+
row: j,
|
|
1221
|
+
column: ie
|
|
1222
|
+
}))]);
|
|
1223
|
+
})]);
|
|
1224
|
+
})]), n["page-footer"] ? (Y = n["page-footer"]) == null ? void 0 : Y.call(n, {
|
|
1225
|
+
pageNumber: F,
|
|
1226
|
+
pageIndex: a,
|
|
1227
|
+
totalPages: L.value.length
|
|
1228
|
+
}) : q("div", {
|
|
1229
|
+
class: "a4-page-footer",
|
|
1230
|
+
contenteditable: "false",
|
|
1231
|
+
style: {
|
|
1232
|
+
height: `${Math.max(_ || 0, 20)}px`
|
|
1233
|
+
}
|
|
1234
|
+
}, [C !== !1 ? q("span", {
|
|
1235
|
+
class: "page-number",
|
|
1236
|
+
contenteditable: "false"
|
|
1237
|
+
}, [F, He(" / "), L.value.length]) : null])]) : q("div", {
|
|
1238
|
+
class: "a4-page-loading"
|
|
1239
|
+
}, [q("div", {
|
|
1240
|
+
class: "loading-spinner"
|
|
1241
|
+
}, null), q("div", {
|
|
1242
|
+
class: "loading-text"
|
|
1243
|
+
}, [He("加载中...")])]);
|
|
1244
|
+
}, vn = () => {
|
|
1245
|
+
var w;
|
|
1246
|
+
const {
|
|
1247
|
+
pageHeight: i,
|
|
1248
|
+
pageWidth: a,
|
|
1249
|
+
margin: c,
|
|
1250
|
+
gap: p,
|
|
1251
|
+
showPageBorder: d,
|
|
1252
|
+
pageBorderPadding: g
|
|
1253
|
+
} = t.pageConfig;
|
|
1254
|
+
return q("div", {
|
|
1255
|
+
class: "virtual-table we-vt-table we-vt-table--render-default border--none"
|
|
1256
|
+
}, [q("div", {
|
|
1257
|
+
class: "a4-pages-container",
|
|
1258
|
+
contenteditable: ((w = t.editConfig) == null ? void 0 : w.trigger) === "contenteditable" ? "true" : void 0,
|
|
1259
|
+
onContextmenu: W,
|
|
1260
|
+
onFocusin: Pe,
|
|
1261
|
+
onFocusout: We
|
|
1262
|
+
}, [L.value.map((k, b) => {
|
|
1263
|
+
const _ = K.value.has(b);
|
|
1264
|
+
return q("div", {
|
|
1265
|
+
key: `page-${b}`,
|
|
1266
|
+
class: _ ? "a4-page" : "a4-page-placeholder",
|
|
1267
|
+
"data-page-index": b,
|
|
1268
|
+
style: {
|
|
1269
|
+
width: `${a}px`,
|
|
1270
|
+
minHeight: `${i}px`,
|
|
1271
|
+
marginBottom: `${p}px`,
|
|
1272
|
+
padding: _ ? `${d ? c - g : c}px` : "0",
|
|
1273
|
+
boxSizing: "border-box",
|
|
1274
|
+
position: "relative"
|
|
1275
|
+
}
|
|
1276
|
+
}, [pn(k, b)]);
|
|
1277
|
+
})])]);
|
|
1278
|
+
}, mn = () => {
|
|
1279
|
+
var i;
|
|
1280
|
+
return q("div", {
|
|
1281
|
+
class: "virtual-table we-vt-table we-vt-table--render-default border--none"
|
|
1282
|
+
}, [t.showHeader ? q("div", {
|
|
1283
|
+
class: "virtual-table-header we-vt-table--header we-vt-table--header-wrapper"
|
|
1284
|
+
}, [$e.value.map((a) => {
|
|
1285
|
+
var c, p, d;
|
|
1286
|
+
return q("div", {
|
|
1287
|
+
class: "we-vt-header--column",
|
|
1288
|
+
key: a.prop,
|
|
1289
|
+
style: Xe(a.width)
|
|
1290
|
+
}, [q("div", {
|
|
1291
|
+
class: "we-vt-cell"
|
|
1292
|
+
}, [(c = a.slots) != null && c.header ? (d = (p = a.slots) == null ? void 0 : p.header) == null ? void 0 : d.call(p, {
|
|
1293
|
+
column: a
|
|
1294
|
+
}) : a.title]), q("div", {
|
|
1295
|
+
class: "we-vt-resizable is--line"
|
|
1296
|
+
}, null)]);
|
|
1297
|
+
})]) : void 0, q(En, {
|
|
1298
|
+
ref: r,
|
|
1299
|
+
items: A.value,
|
|
1300
|
+
minItemSize: Q.value,
|
|
1301
|
+
keyField: t.rowConfig.keyField,
|
|
1302
|
+
emitUpdate: !1,
|
|
1303
|
+
buffer: 300,
|
|
1304
|
+
class: "virtual-table-wrapper",
|
|
1305
|
+
contenteditable: ((i = t.editConfig) == null ? void 0 : i.trigger) === "contenteditable" ? "true" : void 0,
|
|
1306
|
+
onContextmenu: W,
|
|
1307
|
+
onScrollend: fn,
|
|
1308
|
+
onUpdate: gn,
|
|
1309
|
+
onFocusin: Pe,
|
|
1310
|
+
onFocusout: We
|
|
1311
|
+
}, {
|
|
1312
|
+
default: ({
|
|
1313
|
+
item: a,
|
|
1314
|
+
index: c,
|
|
1315
|
+
active: p
|
|
1316
|
+
}) => {
|
|
1317
|
+
var g, w, k;
|
|
1318
|
+
let d;
|
|
1319
|
+
return q(Sn, {
|
|
1320
|
+
key: a[t.rowConfig.keyField],
|
|
1321
|
+
item: a,
|
|
1322
|
+
active: p,
|
|
1323
|
+
sizeDependencies: [(g = a.content) == null ? void 0 : g.length, a._editing, a.content_type],
|
|
1324
|
+
"data-id": a[t.rowConfig.keyField],
|
|
1325
|
+
"data-index": c,
|
|
1326
|
+
"data-active": p,
|
|
1327
|
+
class: {
|
|
1328
|
+
"virtual-table-row": !0,
|
|
1329
|
+
"we-vt-body--row": !0,
|
|
1330
|
+
"row--current": a[t.rowConfig.keyField] === ((w = m.value) == null ? void 0 : w[t.rowConfig.keyField]) || // 如果是树,并且配置了childCurrent高亮子节点
|
|
1331
|
+
((k = t.treeConfig) == null ? void 0 : k.childCurrent) && bt.value.includes(a[t.rowConfig.keyField])
|
|
1332
|
+
}
|
|
1333
|
+
}, ui(d = $e.value.map((b) => {
|
|
1334
|
+
var _, C, F, O, M, $, Y;
|
|
1335
|
+
return q("div", {
|
|
1336
|
+
key: b.prop,
|
|
1337
|
+
class: "virtual-table-cell we-vt-cell",
|
|
1338
|
+
style: Xe(b.width),
|
|
1339
|
+
"data-prop": b.prop
|
|
1340
|
+
}, [a._editing && ((_ = t.editConfig) == null ? void 0 : _.trigger) === "dblclick" ? ((C = b.slots) == null ? void 0 : C.edit) && ((O = (F = b.slots) == null ? void 0 : F.edit) == null ? void 0 : O.call(F, {
|
|
1341
|
+
row: a,
|
|
1342
|
+
column: b
|
|
1343
|
+
})) : ((M = b.slots) == null ? void 0 : M.default) && ((Y = ($ = b.slots) == null ? void 0 : $.default) == null ? void 0 : Y.call($, {
|
|
1344
|
+
row: a,
|
|
1345
|
+
column: b
|
|
1346
|
+
}))]);
|
|
1347
|
+
})) ? d : {
|
|
1348
|
+
default: () => [d]
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
})]);
|
|
1352
|
+
};
|
|
1353
|
+
return () => t.pageConfig.enabled ? vn() : mn();
|
|
1354
|
+
}
|
|
1355
|
+
}), Be = (t, e) => {
|
|
1356
|
+
const n = t.__vccOpts || t;
|
|
1357
|
+
for (const [l, o] of e)
|
|
1358
|
+
n[l] = o;
|
|
1359
|
+
return n;
|
|
1360
|
+
}, fi = /* @__PURE__ */ Be(hi, [["__scopeId", "data-v-3756d9b0"]]), gi = {
|
|
1361
|
+
name: "VirtualTableColumn",
|
|
1362
|
+
props: {
|
|
1363
|
+
prop: String,
|
|
1364
|
+
label: String,
|
|
1365
|
+
width: [String, Number]
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
function pi(t, e, n, l, o, r) {
|
|
1369
|
+
return Cn(t.$slots, "default");
|
|
1370
|
+
}
|
|
1371
|
+
const vi = /* @__PURE__ */ Be(gi, [["render", pi]]), mi = { class: "catalog-node" }, yi = ["title"], bi = { class: "catalog-node__text" }, _i = {
|
|
1372
|
+
key: 0,
|
|
1373
|
+
class: "catalog-node__children"
|
|
1374
|
+
}, xi = {
|
|
1375
|
+
__name: "CatalogNode",
|
|
1376
|
+
props: {
|
|
1377
|
+
item: { type: Object, required: !0 },
|
|
1378
|
+
depth: { type: Number, default: 0 },
|
|
1379
|
+
activeId: { type: String, default: "" }
|
|
1380
|
+
},
|
|
1381
|
+
emits: ["navigate"],
|
|
1382
|
+
setup(t, { emit: e }) {
|
|
1383
|
+
const n = t, l = e, o = te(!0), r = ae(() => n.item.children && n.item.children.length > 0);
|
|
1384
|
+
function y(s) {
|
|
1385
|
+
s.stopPropagation(), o.value = !o.value;
|
|
1386
|
+
}
|
|
1387
|
+
return (s, m) => {
|
|
1388
|
+
const h = Mn("CatalogNode", !0);
|
|
1389
|
+
return u(), v("div", mi, [
|
|
1390
|
+
ee("div", {
|
|
1391
|
+
class: Ie(["catalog-node__label", { "is-active": t.activeId === t.item.nodeId }]),
|
|
1392
|
+
style: N({ paddingLeft: 10 + t.depth * 14 + "px" }),
|
|
1393
|
+
title: t.item.name,
|
|
1394
|
+
onClick: m[0] || (m[0] = (I) => l("navigate", t.item))
|
|
1395
|
+
}, [
|
|
1396
|
+
ee("span", {
|
|
1397
|
+
class: "catalog-node__toggle",
|
|
1398
|
+
onClick: y
|
|
1399
|
+
}, [
|
|
1400
|
+
r.value ? (u(), ke(nt(o.value ? z(Gn) : z(Ut)), {
|
|
1401
|
+
key: 0,
|
|
1402
|
+
size: 14
|
|
1403
|
+
})) : ue("", !0)
|
|
1404
|
+
]),
|
|
1405
|
+
ee("span", bi, J(t.item.name || "(无标题)"), 1)
|
|
1406
|
+
], 14, yi),
|
|
1407
|
+
r.value && o.value ? (u(), v("div", _i, [
|
|
1408
|
+
(u(!0), v(U, null, Z(t.item.children, (I) => (u(), ke(h, {
|
|
1409
|
+
key: I.nodeId,
|
|
1410
|
+
item: I,
|
|
1411
|
+
depth: t.depth + 1,
|
|
1412
|
+
"active-id": t.activeId,
|
|
1413
|
+
onNavigate: m[1] || (m[1] = (S) => l("navigate", S))
|
|
1414
|
+
}, null, 8, ["item", "depth", "active-id"]))), 128))
|
|
1415
|
+
])) : ue("", !0)
|
|
1416
|
+
]);
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
}, ki = /* @__PURE__ */ Be(xi, [["__scopeId", "data-v-ac882917"]]), wi = {
|
|
1420
|
+
key: 0,
|
|
1421
|
+
class: "catalog catalog--collapsed"
|
|
1422
|
+
}, Ci = {
|
|
1423
|
+
key: 1,
|
|
1424
|
+
class: "catalog"
|
|
1425
|
+
}, Mi = { class: "catalog__header" }, Ii = { class: "catalog__title" }, Ei = { class: "catalog__body" }, Si = {
|
|
1426
|
+
key: 0,
|
|
1427
|
+
class: "catalog__empty"
|
|
1428
|
+
}, Ti = {
|
|
1429
|
+
__name: "index",
|
|
1430
|
+
props: {
|
|
1431
|
+
items: { type: Array, default: () => [] }
|
|
1432
|
+
},
|
|
1433
|
+
emits: ["navigate"],
|
|
1434
|
+
setup(t, { emit: e }) {
|
|
1435
|
+
const n = e, l = te(!1), o = te("");
|
|
1436
|
+
function r(y) {
|
|
1437
|
+
o.value = y.nodeId, n("navigate", y);
|
|
1438
|
+
}
|
|
1439
|
+
return (y, s) => l.value ? (u(), v("div", wi, [
|
|
1440
|
+
ee("button", {
|
|
1441
|
+
class: "catalog__icon-btn",
|
|
1442
|
+
title: "展开目录",
|
|
1443
|
+
onClick: s[0] || (s[0] = (m) => l.value = !1)
|
|
1444
|
+
}, [
|
|
1445
|
+
q(z(Jn), { size: 18 })
|
|
1446
|
+
])
|
|
1447
|
+
])) : (u(), v("div", Ci, [
|
|
1448
|
+
ee("div", Mi, [
|
|
1449
|
+
ee("span", Ii, [
|
|
1450
|
+
q(z(Xn), { size: 16 }),
|
|
1451
|
+
s[2] || (s[2] = He(" 目录 ", -1))
|
|
1452
|
+
]),
|
|
1453
|
+
ee("button", {
|
|
1454
|
+
class: "catalog__icon-btn",
|
|
1455
|
+
title: "收起目录",
|
|
1456
|
+
onClick: s[1] || (s[1] = (m) => l.value = !0)
|
|
1457
|
+
}, [
|
|
1458
|
+
q(z(Yn), { size: 18 })
|
|
1459
|
+
])
|
|
1460
|
+
]),
|
|
1461
|
+
ee("div", Ei, [
|
|
1462
|
+
(u(!0), v(U, null, Z(t.items, (m) => (u(), ke(ki, {
|
|
1463
|
+
key: m.nodeId,
|
|
1464
|
+
item: m,
|
|
1465
|
+
"active-id": o.value,
|
|
1466
|
+
onNavigate: r
|
|
1467
|
+
}, null, 8, ["item", "active-id"]))), 128)),
|
|
1468
|
+
t.items.length ? ue("", !0) : (u(), v("div", Si, " 暂无目录 "))
|
|
1469
|
+
])
|
|
1470
|
+
]));
|
|
1471
|
+
}
|
|
1472
|
+
}, Fi = /* @__PURE__ */ Be(Ti, [["__scopeId", "data-v-8becafa1"]]), Ai = {
|
|
1473
|
+
first: 1,
|
|
1474
|
+
second: 2,
|
|
1475
|
+
third: 3,
|
|
1476
|
+
fourth: 4,
|
|
1477
|
+
fifth: 5,
|
|
1478
|
+
sixth: 6
|
|
1479
|
+
};
|
|
1480
|
+
function Pi(t) {
|
|
1481
|
+
return t.blockType !== "title" || !t.level ? 0 : Ai[t.level] || 1;
|
|
1482
|
+
}
|
|
1483
|
+
function $i(t) {
|
|
1484
|
+
const e = [];
|
|
1485
|
+
for (const o of t || []) {
|
|
1486
|
+
const r = Pi(o);
|
|
1487
|
+
r && e.push({
|
|
1488
|
+
id: o.node_id,
|
|
1489
|
+
nodeId: o.node_id,
|
|
1490
|
+
name: (o.content || "").trim(),
|
|
1491
|
+
level: r,
|
|
1492
|
+
children: []
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
if (!e.length) return [];
|
|
1496
|
+
const n = (o, r) => {
|
|
1497
|
+
const y = r.children[r.children.length - 1];
|
|
1498
|
+
y && o.level > y.level ? n(o, y) : r.children.push(o);
|
|
1499
|
+
}, l = [];
|
|
1500
|
+
for (const o of e) {
|
|
1501
|
+
const r = l[l.length - 1];
|
|
1502
|
+
r && o.level > r.level ? n(o, r) : l.push(o);
|
|
1503
|
+
}
|
|
1504
|
+
return l;
|
|
1505
|
+
}
|
|
1506
|
+
const Li = {
|
|
1507
|
+
first: 0,
|
|
1508
|
+
second: 1,
|
|
1509
|
+
third: 2,
|
|
1510
|
+
fourth: 3,
|
|
1511
|
+
fifth: 4,
|
|
1512
|
+
sixth: 5,
|
|
1513
|
+
seventh: 6,
|
|
1514
|
+
eighth: 7
|
|
1515
|
+
};
|
|
1516
|
+
function et(t, e) {
|
|
1517
|
+
let n = "", l = t;
|
|
1518
|
+
const o = e ? 65 : 97;
|
|
1519
|
+
for (; l > 0; ) {
|
|
1520
|
+
const r = (l - 1) % 26;
|
|
1521
|
+
n = String.fromCharCode(o + r) + n, l = Math.floor((l - 1) / 26);
|
|
1522
|
+
}
|
|
1523
|
+
return n;
|
|
1524
|
+
}
|
|
1525
|
+
const Lt = [
|
|
1526
|
+
(t) => t.toString(),
|
|
1527
|
+
// first:数字
|
|
1528
|
+
(t) => et(t, !0),
|
|
1529
|
+
// second:大写字母
|
|
1530
|
+
(t) => `(${t})`,
|
|
1531
|
+
// third:括号数字
|
|
1532
|
+
(t) => `(${et(t, !1)})`,
|
|
1533
|
+
// fourth:括号小写字母
|
|
1534
|
+
(t) => `${t})`,
|
|
1535
|
+
// fifth:数字+右括号
|
|
1536
|
+
(t) => `${et(t, !1)})`,
|
|
1537
|
+
// sixth:小写字母+右括号
|
|
1538
|
+
(t) => `<${t}>`,
|
|
1539
|
+
// seventh:数字+尖括号
|
|
1540
|
+
(t) => `<${et(t, !1)}>`
|
|
1541
|
+
// eighth:小写字母+尖括号
|
|
1542
|
+
];
|
|
1543
|
+
function Ri() {
|
|
1544
|
+
const t = new Array(8).fill(0);
|
|
1545
|
+
return {
|
|
1546
|
+
next(e, n) {
|
|
1547
|
+
const l = Li[e];
|
|
1548
|
+
if (l == null) return "";
|
|
1549
|
+
t[l]++;
|
|
1550
|
+
for (let r = l + 1; r < t.length; r++) t[r] = 0;
|
|
1551
|
+
if (n != null && n !== "")
|
|
1552
|
+
return `${n} `;
|
|
1553
|
+
const o = Lt[Math.min(l, Lt.length - 1)];
|
|
1554
|
+
return `${o(t[l])}. `;
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
const qe = 14, Jt = 760, Rt = 756, Hi = {
|
|
1559
|
+
left: "left",
|
|
1560
|
+
center: "center",
|
|
1561
|
+
right: "right",
|
|
1562
|
+
alignment: "justify",
|
|
1563
|
+
justify: "justify"
|
|
1564
|
+
};
|
|
1565
|
+
function Xt(t) {
|
|
1566
|
+
const e = [];
|
|
1567
|
+
let n = !1;
|
|
1568
|
+
const l = (o) => {
|
|
1569
|
+
if (n) {
|
|
1570
|
+
if (o && o.value != null && /^[\n200B]+$/.test(o.value)) {
|
|
1571
|
+
e.push(o);
|
|
1572
|
+
return;
|
|
1573
|
+
}
|
|
1574
|
+
n = !1, e.push({ ...o, _coverBreakBefore: !0 });
|
|
1575
|
+
} else
|
|
1576
|
+
e.push(o);
|
|
1577
|
+
};
|
|
1578
|
+
for (const o of t || []) {
|
|
1579
|
+
if (o && o.type === "pageBreak") {
|
|
1580
|
+
n = !0;
|
|
1581
|
+
continue;
|
|
1582
|
+
}
|
|
1583
|
+
if (o && o.type === "area") {
|
|
1584
|
+
const r = Xt(o.valueList || []), y = (o.areaId || "").includes("cover");
|
|
1585
|
+
for (const s of r) l(s);
|
|
1586
|
+
y && (n = !0);
|
|
1587
|
+
} else
|
|
1588
|
+
l(o);
|
|
1589
|
+
}
|
|
1590
|
+
return e;
|
|
1591
|
+
}
|
|
1592
|
+
function Ue(t) {
|
|
1593
|
+
const e = Xt(t), n = [];
|
|
1594
|
+
let l = [], o = 0, r = null;
|
|
1595
|
+
const y = (m) => {
|
|
1596
|
+
l.length && (n.push({ type: "paragraph", elements: [...l], rowFlex: m }), l = []);
|
|
1597
|
+
}, s = () => {
|
|
1598
|
+
if (o === 0) return;
|
|
1599
|
+
const m = r;
|
|
1600
|
+
y(m);
|
|
1601
|
+
for (let h = 1; h < o; h++)
|
|
1602
|
+
n.push({ type: "paragraph", elements: [], rowFlex: m });
|
|
1603
|
+
o = 0, r = null;
|
|
1604
|
+
};
|
|
1605
|
+
for (const m of e || [])
|
|
1606
|
+
if (m.type === "table")
|
|
1607
|
+
s(), y(), n.push({ type: "table", el: m });
|
|
1608
|
+
else if (m.type === "title")
|
|
1609
|
+
s(), y(), n.push({ type: "title", el: m });
|
|
1610
|
+
else if (m.type === "list") {
|
|
1611
|
+
s(), y();
|
|
1612
|
+
const h = [];
|
|
1613
|
+
let I = [];
|
|
1614
|
+
for (const S of m.valueList || [])
|
|
1615
|
+
S.value === `
|
|
1616
|
+
` || S.value === "" ? (h.push([...I]), I = []) : I.push(S);
|
|
1617
|
+
(I.length || h.length === 0) && h.push([...I]), n.push({ type: "list", listType: m.listType || "ul", listStyle: m.listStyle || "disc", items: h });
|
|
1618
|
+
} else if (m.listId) {
|
|
1619
|
+
s(), y();
|
|
1620
|
+
const h = m.value === "" || m.value === "" ? [] : [m];
|
|
1621
|
+
n.push({ type: "list", listType: m.listType || "ul", listStyle: m.listStyle || "disc", items: [h] });
|
|
1622
|
+
} else m.value != null && /^[\n200B]+$/.test(m.value) ? (o += m.value.length, m.rowFlex && (r = m.rowFlex)) : (s(), l.push(m));
|
|
1623
|
+
return s(), y(), n;
|
|
1624
|
+
}
|
|
1625
|
+
function Oe(t) {
|
|
1626
|
+
const e = t.filter((h) => h.type === "image").reduce((h, I) => h + (I.height || I.width || 0), 0), n = t.filter((h) => h.type !== "image").map((h) => h.value || "").join("");
|
|
1627
|
+
if (!n) return e || 20;
|
|
1628
|
+
const l = t.reduce((h, I) => Math.max(h, I.size || 0), 0) || 14, o = l + 6, r = (n.match(/[一-龥]/g) || []).length, y = n.length - r, s = r * l + y * (l * 0.5), m = Math.max(1, Math.ceil(s / Jt));
|
|
1629
|
+
return e + Math.max(o, m * o);
|
|
1630
|
+
}
|
|
1631
|
+
function Oi(t) {
|
|
1632
|
+
if (!t || !t.length) return [[]];
|
|
1633
|
+
const e = [];
|
|
1634
|
+
let n = [];
|
|
1635
|
+
for (const l of t)
|
|
1636
|
+
l.type === "image" && (l.width || 0) >= Jt ? (n.length && (e.push(n), n = []), e.push([l])) : n.push(l);
|
|
1637
|
+
return n.length && e.push(n), e.length ? e : [[]];
|
|
1638
|
+
}
|
|
1639
|
+
function Ht(t) {
|
|
1640
|
+
if (t.length === 0) return [];
|
|
1641
|
+
const e = new Array(t.length).fill(0);
|
|
1642
|
+
t.forEach((r, y) => {
|
|
1643
|
+
(r.tdList || []).forEach((s) => {
|
|
1644
|
+
const m = s.rowspan || 1;
|
|
1645
|
+
if (m > 1) {
|
|
1646
|
+
const h = Math.min(y + m - 1, t.length - 1);
|
|
1647
|
+
e[y] = Math.max(e[y], h);
|
|
1648
|
+
for (let I = 1; I < m && y + I < t.length; I++)
|
|
1649
|
+
e[y + I] = Math.max(e[y + I], h);
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
});
|
|
1653
|
+
const n = [];
|
|
1654
|
+
let l = 0, o = 0;
|
|
1655
|
+
for (let r = 0; r < t.length; r++)
|
|
1656
|
+
o = Math.max(o, e[r]), o <= r && (n.push(t.slice(l, r + 1)), l = r + 1, o = 0);
|
|
1657
|
+
return l < t.length && n.push(t.slice(l)), n;
|
|
1658
|
+
}
|
|
1659
|
+
function ct(t) {
|
|
1660
|
+
const e = (t == null ? void 0 : t.width) || 0;
|
|
1661
|
+
return !e || e <= Rt ? 1 : Rt / e;
|
|
1662
|
+
}
|
|
1663
|
+
function Ot(t) {
|
|
1664
|
+
var r, y;
|
|
1665
|
+
const e = t.elements || [], n = ((r = e.find((s) => s.rowFlex)) == null ? void 0 : r.rowFlex) || t.rowFlex, l = { textAlign: Hi[n] || "left" }, o = (y = e.find((s) => s.rowMargin)) == null ? void 0 : y.rowMargin;
|
|
1666
|
+
return o && (l.lineHeight = o), l;
|
|
1667
|
+
}
|
|
1668
|
+
function Bi(t) {
|
|
1669
|
+
var r;
|
|
1670
|
+
const e = Ue(t.value);
|
|
1671
|
+
let n = 0, l = 0, o = !1;
|
|
1672
|
+
for (const y of e)
|
|
1673
|
+
if (y.type === "paragraph") {
|
|
1674
|
+
if (!y.elements.length) continue;
|
|
1675
|
+
n++;
|
|
1676
|
+
for (const s of y.elements)
|
|
1677
|
+
(s.type === "image" || s.type === "table") && (o = !0), l += (s.value || "").length;
|
|
1678
|
+
} else y.type === "list" ? (n += ((r = y.items) == null ? void 0 : r.length) || 1, o = !0) : (n++, o = !0);
|
|
1679
|
+
return n > 1 || l > 30 || o ? "top" : t.verticalAlign || "middle";
|
|
1680
|
+
}
|
|
1681
|
+
function he(t) {
|
|
1682
|
+
const e = {};
|
|
1683
|
+
t.font && (e.fontFamily = t.font), e.fontSize = (t.size || qe) + "px", t.bold != null && (e.fontWeight = t.bold ? "bold" : "normal"), t.italic != null && (e.fontStyle = t.italic ? "italic" : "normal"), t.color && (e.color = t.color), t.highlight && t.highlight !== "rgb(255, 255, 255)" && t.highlight !== "#ffffff" && (e.backgroundColor = t.highlight);
|
|
1684
|
+
const n = [t.underline && "underline", t.strikeout && "line-through"].filter(Boolean).join(" ");
|
|
1685
|
+
return n && (e.textDecoration = n), t.letterSpacing && (e.letterSpacing = t.letterSpacing + "px"), e;
|
|
1686
|
+
}
|
|
1687
|
+
const Di = 5;
|
|
1688
|
+
function Bt(t, e = !1) {
|
|
1689
|
+
var l, o;
|
|
1690
|
+
let n = 0;
|
|
1691
|
+
for (const r of t)
|
|
1692
|
+
if (r.type === "table") {
|
|
1693
|
+
const y = ((l = r.el) == null ? void 0 : l.trList) || [];
|
|
1694
|
+
n += y.reduce((s, m) => s + (m.height || m.minHeight || 35), 0);
|
|
1695
|
+
} else if (r.type === "title")
|
|
1696
|
+
n += Oe(r.titleValueList || ((o = r.el) == null ? void 0 : o.valueList) || []);
|
|
1697
|
+
else if (r.type === "paragraph")
|
|
1698
|
+
n += Oe(r.elements || []);
|
|
1699
|
+
else if (r.type === "list") {
|
|
1700
|
+
const y = Math.round(18), s = (r.items || []).reduce(
|
|
1701
|
+
(m, h) => m + (h.length ? Oe(h) : y),
|
|
1702
|
+
0
|
|
1703
|
+
);
|
|
1704
|
+
n += Math.max(s, y);
|
|
1705
|
+
}
|
|
1706
|
+
return n + (e && n > 0 ? Di : 0);
|
|
1707
|
+
}
|
|
1708
|
+
const Ni = {
|
|
1709
|
+
key: 0,
|
|
1710
|
+
class: "empty-line"
|
|
1711
|
+
}, zi = ["href"], Vi = ["src"], ji = ["checked"], Ki = ["checked"], qi = {
|
|
1712
|
+
key: 4,
|
|
1713
|
+
class: "ctrl-input"
|
|
1714
|
+
}, Ui = ["checked"], Wi = ["checked"], Gi = { key: 0 }, Ji = ["colspan", "rowspan"], Xi = { key: 0 }, Yi = ["src"], Zi = ["href"], Qi = ["checked"], el = ["checked"], tl = ["checked"], nl = {
|
|
1715
|
+
__name: "DocBlock",
|
|
1716
|
+
props: {
|
|
1717
|
+
block: {
|
|
1718
|
+
type: Object,
|
|
1719
|
+
required: !0
|
|
1720
|
+
},
|
|
1721
|
+
isHeaderFooter: {
|
|
1722
|
+
type: Boolean,
|
|
1723
|
+
default: !1
|
|
1724
|
+
}
|
|
1725
|
+
},
|
|
1726
|
+
setup(t) {
|
|
1727
|
+
const e = t, n = jt("bindTableObserver", null), l = ae(() => e.isHeaderFooter ? 0 : e.block.indentPx ?? 0);
|
|
1728
|
+
return (o, r) => {
|
|
1729
|
+
var y;
|
|
1730
|
+
return t.block.blockType === "title" ? (u(), v("p", {
|
|
1731
|
+
key: 0,
|
|
1732
|
+
class: Ie(["doc-title", `doc-title--${t.block.level}`]),
|
|
1733
|
+
style: N({ paddingLeft: l.value ? l.value + "px" : void 0 })
|
|
1734
|
+
}, [
|
|
1735
|
+
(u(!0), v(U, null, Z(t.block.titleValueList || [], (s, m) => (u(), v("span", {
|
|
1736
|
+
key: m,
|
|
1737
|
+
style: N(z(he)(s))
|
|
1738
|
+
}, J(s.value), 5))), 128))
|
|
1739
|
+
], 6)) : t.block.blockType === "paragraph" ? (u(), v("p", {
|
|
1740
|
+
key: 1,
|
|
1741
|
+
class: "doc-para",
|
|
1742
|
+
style: N({ ...z(Ot)(t.block), paddingLeft: l.value ? l.value + "px" : void 0 })
|
|
1743
|
+
}, [
|
|
1744
|
+
t.block.elements.length ? ue("", !0) : (u(), v("span", Ni, " ")),
|
|
1745
|
+
(u(!0), v(U, null, Z(t.block.elements, (s, m) => {
|
|
1746
|
+
var h, I, S, L, x, K, ne, R, T, f, E, B, A;
|
|
1747
|
+
return u(), v(U, { key: m }, [
|
|
1748
|
+
!s.type || s.type === "text" ? (u(), v("span", {
|
|
1749
|
+
key: 0,
|
|
1750
|
+
style: N(z(he)(s))
|
|
1751
|
+
}, J(s.value), 5)) : s.type === "hyperlink" ? (u(), v("a", {
|
|
1752
|
+
key: 1,
|
|
1753
|
+
href: s.url,
|
|
1754
|
+
class: "doc-link",
|
|
1755
|
+
target: "_blank",
|
|
1756
|
+
rel: "noopener"
|
|
1757
|
+
}, [
|
|
1758
|
+
(u(!0), v(U, null, Z(s.valueList || [], (P, Q) => (u(), v("span", {
|
|
1759
|
+
key: Q,
|
|
1760
|
+
style: N(z(he)(P))
|
|
1761
|
+
}, J(P.value), 5))), 128))
|
|
1762
|
+
], 8, zi)) : s.type === "image" ? (u(), v("img", {
|
|
1763
|
+
key: 2,
|
|
1764
|
+
src: s.value,
|
|
1765
|
+
class: "doc-image",
|
|
1766
|
+
style: N({
|
|
1767
|
+
width: s.width ? s.width + "px" : "auto",
|
|
1768
|
+
height: s.height ? s.height + "px" : "auto"
|
|
1769
|
+
})
|
|
1770
|
+
}, null, 12, Vi)) : s.type === "control" ? (u(), v(U, { key: 3 }, [
|
|
1771
|
+
((h = s.control) == null ? void 0 : h.type) === "text" ? (u(), v("span", {
|
|
1772
|
+
key: 0,
|
|
1773
|
+
style: N({ fontSize: (s.control.size || 12) + "px" })
|
|
1774
|
+
}, [
|
|
1775
|
+
(u(!0), v(U, null, Z(s.control.value || [], (P, Q) => (u(), v("span", {
|
|
1776
|
+
key: Q,
|
|
1777
|
+
style: N(z(he)(P))
|
|
1778
|
+
}, J(P.value), 5))), 128))
|
|
1779
|
+
], 4)) : ((I = s.control) == null ? void 0 : I.type) === "input" ? (u(), v("span", {
|
|
1780
|
+
key: 1,
|
|
1781
|
+
class: "ctrl-input",
|
|
1782
|
+
style: N({
|
|
1783
|
+
minWidth: (s.control.minWidth || 60) + "px",
|
|
1784
|
+
fontSize: (s.control.size || 12) + "px"
|
|
1785
|
+
})
|
|
1786
|
+
}, [
|
|
1787
|
+
(u(!0), v(U, null, Z(s.control.value || [], (P, Q) => (u(), v("span", { key: Q }, J(P.value), 1))), 128))
|
|
1788
|
+
], 4)) : ((S = s.control) == null ? void 0 : S.type) === "radio" ? (u(), v("span", {
|
|
1789
|
+
key: 2,
|
|
1790
|
+
class: Ie(["ctrl-options", { "ctrl-options--vertical": ((x = (L = s.control.extension) == null ? void 0 : L.elementAttributes) == null ? void 0 : x.layout) === "vertical" }]),
|
|
1791
|
+
style: N({ fontSize: (s.control.size || z(qe)) + "px" })
|
|
1792
|
+
}, [
|
|
1793
|
+
(u(!0), v(U, null, Z(s.control.valueSets || [], (P, Q) => (u(), v("label", {
|
|
1794
|
+
key: Q,
|
|
1795
|
+
class: "ctrl-option"
|
|
1796
|
+
}, [
|
|
1797
|
+
ee("input", {
|
|
1798
|
+
type: "radio",
|
|
1799
|
+
disabled: "",
|
|
1800
|
+
checked: s.control.code === P.code
|
|
1801
|
+
}, null, 8, ji),
|
|
1802
|
+
He(" " + J(P.value), 1)
|
|
1803
|
+
]))), 128))
|
|
1804
|
+
], 6)) : ((K = s.control) == null ? void 0 : K.type) === "checkbox" ? (u(), v("span", {
|
|
1805
|
+
key: 3,
|
|
1806
|
+
class: Ie(["ctrl-options", { "ctrl-options--vertical": ((R = (ne = s.control.extension) == null ? void 0 : ne.elementAttributes) == null ? void 0 : R.layout) === "vertical" }]),
|
|
1807
|
+
style: N({ fontSize: (s.control.size || z(qe)) + "px" })
|
|
1808
|
+
}, [
|
|
1809
|
+
(u(!0), v(U, null, Z(s.control.valueSets || [], (P, Q) => (u(), v("label", {
|
|
1810
|
+
key: Q,
|
|
1811
|
+
class: "ctrl-option"
|
|
1812
|
+
}, [
|
|
1813
|
+
ee("input", {
|
|
1814
|
+
type: "checkbox",
|
|
1815
|
+
disabled: "",
|
|
1816
|
+
checked: (s.control.code || "").split(",").includes(P.code)
|
|
1817
|
+
}, null, 8, Ki),
|
|
1818
|
+
He(" " + J(P.value), 1)
|
|
1819
|
+
]))), 128))
|
|
1820
|
+
], 6)) : ((T = s.control) == null ? void 0 : T.type) === "select" ? (u(), v("span", qi, J(((E = (f = s.control.value) == null ? void 0 : f[0]) == null ? void 0 : E.value) || s.control.placeholder || ""), 1)) : ue("", !0)
|
|
1821
|
+
], 64)) : s.type === "checkbox" ? (u(), v("input", {
|
|
1822
|
+
key: 4,
|
|
1823
|
+
type: "checkbox",
|
|
1824
|
+
checked: !!((B = s.checkbox) != null && B.value),
|
|
1825
|
+
disabled: "",
|
|
1826
|
+
class: "el-check"
|
|
1827
|
+
}, null, 8, Ui)) : s.type === "radio" ? (u(), v("input", {
|
|
1828
|
+
key: 5,
|
|
1829
|
+
type: "radio",
|
|
1830
|
+
checked: !!((A = s.radio) != null && A.value),
|
|
1831
|
+
disabled: "",
|
|
1832
|
+
class: "el-check"
|
|
1833
|
+
}, null, 8, Wi)) : s.type === "superscript" ? (u(), v("sup", {
|
|
1834
|
+
key: 6,
|
|
1835
|
+
style: N(z(he)(s))
|
|
1836
|
+
}, J(s.value), 5)) : s.type === "subscript" ? (u(), v("sub", {
|
|
1837
|
+
key: 7,
|
|
1838
|
+
style: N(z(he)(s))
|
|
1839
|
+
}, J(s.value), 5)) : s.type === "tab" ? (u(), v("span", {
|
|
1840
|
+
key: 8,
|
|
1841
|
+
class: "doc-tab",
|
|
1842
|
+
style: N({ width: (s.size || z(qe)) + "px" })
|
|
1843
|
+
}, null, 4)) : ue("", !0)
|
|
1844
|
+
], 64);
|
|
1845
|
+
}), 128))
|
|
1846
|
+
], 4)) : t.block.blockType === "list" ? (u(), ke(nt(t.block.listType === "ol" ? "ol" : "ul"), {
|
|
1847
|
+
key: 2,
|
|
1848
|
+
class: "doc-list",
|
|
1849
|
+
style: N({ listStyleType: t.block.listStyle === "decimal" ? "decimal" : t.block.listStyle === "lower-alpha" ? "lower-alpha" : "disc", paddingLeft: l.value ? l.value + 24 + "px" : void 0 })
|
|
1850
|
+
}, {
|
|
1851
|
+
default: Ke(() => [
|
|
1852
|
+
(u(!0), v(U, null, Z(t.block.items, (s, m) => (u(), v("li", {
|
|
1853
|
+
key: m,
|
|
1854
|
+
class: "doc-list-item"
|
|
1855
|
+
}, [
|
|
1856
|
+
(u(!0), v(U, null, Z(s, (h, I) => (u(), v(U, { key: I }, [
|
|
1857
|
+
!h.type || h.type === "text" ? (u(), v("span", {
|
|
1858
|
+
key: 0,
|
|
1859
|
+
style: N(z(he)(h))
|
|
1860
|
+
}, J(h.value), 5)) : h.type === "superscript" ? (u(), v("sup", {
|
|
1861
|
+
key: 1,
|
|
1862
|
+
style: N(z(he)(h))
|
|
1863
|
+
}, J(h.value), 5)) : h.type === "subscript" ? (u(), v("sub", {
|
|
1864
|
+
key: 2,
|
|
1865
|
+
style: N(z(he)(h))
|
|
1866
|
+
}, J(h.value), 5)) : ue("", !0)
|
|
1867
|
+
], 64))), 128))
|
|
1868
|
+
]))), 128))
|
|
1869
|
+
]),
|
|
1870
|
+
_: 1
|
|
1871
|
+
}, 8, ["style"])) : t.block.blockType === "table-row-group" ? (u(), v("div", {
|
|
1872
|
+
key: 3,
|
|
1873
|
+
class: Ie(["doc-table-row-wrap", { "is-first": t.block.isFirst, "is-last": t.block.isLast, "is-page-break": t.block.isPageBreak }]),
|
|
1874
|
+
style: N({
|
|
1875
|
+
display: t.block.tableRowFlex ? "flex" : void 0,
|
|
1876
|
+
justifyContent: t.block.tableRowFlex === "right" ? "flex-end" : t.block.tableRowFlex === "center" ? "center" : t.block.tableRowFlex === "left" ? "flex-start" : void 0,
|
|
1877
|
+
paddingLeft: l.value ? l.value + "px" : void 0
|
|
1878
|
+
})
|
|
1879
|
+
}, [
|
|
1880
|
+
ee("div", {
|
|
1881
|
+
style: N({
|
|
1882
|
+
overflow: t.block.sliceHeight != null ? "hidden" : void 0,
|
|
1883
|
+
height: t.block.sliceHeight != null ? (t.block.isLast ? t.block.sliceHeight + 1 : t.block.sliceHeight) + "px" : void 0,
|
|
1884
|
+
width: t.block.tableEl.width ? "max-content" : "100%"
|
|
1885
|
+
})
|
|
1886
|
+
}, [
|
|
1887
|
+
ee("table", {
|
|
1888
|
+
ref: t.block._baseKey && z(n) ? (s) => z(n)(s, t.block._baseKey) : void 0,
|
|
1889
|
+
class: Ie(["doc-table", { "doc-table--no-border": t.block.tableEl.borderType === "empty" }]),
|
|
1890
|
+
style: N({
|
|
1891
|
+
width: t.block.tableEl.width ? t.block.tableEl.width * z(ct)(t.block.tableEl) + "px" : "100%",
|
|
1892
|
+
transform: t.block.sliceOffset ? `translateY(-${t.block.sliceOffset}px)` : void 0
|
|
1893
|
+
})
|
|
1894
|
+
}, [
|
|
1895
|
+
(y = t.block.tableEl.colgroup) != null && y.length ? (u(), v("colgroup", Gi, [
|
|
1896
|
+
(u(!0), v(U, null, Z(t.block.tableEl.colgroup, (s, m) => (u(), v("col", {
|
|
1897
|
+
key: m,
|
|
1898
|
+
style: N({ width: s.width * z(ct)(t.block.tableEl) + "px" })
|
|
1899
|
+
}, null, 4))), 128))
|
|
1900
|
+
])) : ue("", !0),
|
|
1901
|
+
ee("tbody", null, [
|
|
1902
|
+
(u(!0), v(U, null, Z(t.block.trGroup, (s, m) => (u(), v("tr", {
|
|
1903
|
+
key: m,
|
|
1904
|
+
style: N({ height: (s.height || s.minHeight || 30) + "px" })
|
|
1905
|
+
}, [
|
|
1906
|
+
(u(!0), v(U, null, Z(s.tdList || [], (h, I) => (u(), v("td", {
|
|
1907
|
+
key: I,
|
|
1908
|
+
colspan: h.colspan || 1,
|
|
1909
|
+
rowspan: h.rowspan || 1,
|
|
1910
|
+
style: N({
|
|
1911
|
+
backgroundColor: h.backgroundColor || void 0,
|
|
1912
|
+
verticalAlign: z(Bi)(h),
|
|
1913
|
+
width: h.width ? h.width * z(ct)(t.block.tableEl) + "px" : void 0,
|
|
1914
|
+
height: h.height ? h.height + "px" : void 0
|
|
1915
|
+
})
|
|
1916
|
+
}, [
|
|
1917
|
+
(u(!0), v(U, null, Z(z(Ue)(h.value), (S, L) => (u(), v(U, { key: L }, [
|
|
1918
|
+
S.type === "paragraph" ? (u(), v("p", {
|
|
1919
|
+
key: 0,
|
|
1920
|
+
class: "cell-para",
|
|
1921
|
+
style: N(z(Ot)(S))
|
|
1922
|
+
}, [
|
|
1923
|
+
S.elements.length ? ue("", !0) : (u(), v("span", Xi, " ")),
|
|
1924
|
+
(u(!0), v(U, null, Z(S.elements, (x, K) => {
|
|
1925
|
+
var ne, R, T, f, E, B, A;
|
|
1926
|
+
return u(), v(U, { key: K }, [
|
|
1927
|
+
!x.type || x.type === "text" ? (u(), v("span", {
|
|
1928
|
+
key: 0,
|
|
1929
|
+
style: N(z(he)(x))
|
|
1930
|
+
}, J(x.value), 5)) : x.type === "image" ? (u(), v("img", {
|
|
1931
|
+
key: 1,
|
|
1932
|
+
src: x.value,
|
|
1933
|
+
class: "doc-image",
|
|
1934
|
+
style: N({
|
|
1935
|
+
width: x.width ? x.width + "px" : "auto",
|
|
1936
|
+
height: x.height ? x.height + "px" : "auto"
|
|
1937
|
+
})
|
|
1938
|
+
}, null, 12, Yi)) : x.type === "hyperlink" ? (u(), v("a", {
|
|
1939
|
+
key: 2,
|
|
1940
|
+
href: x.url,
|
|
1941
|
+
class: "doc-link",
|
|
1942
|
+
target: "_blank"
|
|
1943
|
+
}, [
|
|
1944
|
+
(u(!0), v(U, null, Z(x.valueList || [], (P, Q) => (u(), v("span", {
|
|
1945
|
+
key: Q,
|
|
1946
|
+
style: N(z(he)(P))
|
|
1947
|
+
}, J(P.value), 5))), 128))
|
|
1948
|
+
], 8, Zi)) : x.type === "control" ? (u(), v(U, { key: 3 }, [
|
|
1949
|
+
((ne = x.control) == null ? void 0 : ne.type) === "text" ? (u(), v("span", {
|
|
1950
|
+
key: 0,
|
|
1951
|
+
style: N({ fontSize: (x.control.size || 12) + "px" })
|
|
1952
|
+
}, [
|
|
1953
|
+
(u(!0), v(U, null, Z(x.control.value || [], (P, Q) => (u(), v("span", {
|
|
1954
|
+
key: Q,
|
|
1955
|
+
style: N(z(he)(P))
|
|
1956
|
+
}, J(P.value), 5))), 128))
|
|
1957
|
+
], 4)) : ((R = x.control) == null ? void 0 : R.type) === "input" ? (u(), v("span", {
|
|
1958
|
+
key: 1,
|
|
1959
|
+
class: "ctrl-input",
|
|
1960
|
+
style: N({ fontSize: (x.control.size || 12) + "px" })
|
|
1961
|
+
}, [
|
|
1962
|
+
(u(!0), v(U, null, Z(x.control.value || [], (P, Q) => (u(), v("span", { key: Q }, J(P.value), 1))), 128))
|
|
1963
|
+
], 4)) : ((T = x.control) == null ? void 0 : T.type) === "radio" ? (u(), v("span", {
|
|
1964
|
+
key: 2,
|
|
1965
|
+
class: Ie(["ctrl-options", { "ctrl-options--vertical": ((E = (f = x.control.extension) == null ? void 0 : f.elementAttributes) == null ? void 0 : E.layout) === "vertical" }])
|
|
1966
|
+
}, [
|
|
1967
|
+
(u(!0), v(U, null, Z(x.control.valueSets || [], (P, Q) => (u(), v("label", {
|
|
1968
|
+
key: Q,
|
|
1969
|
+
class: "ctrl-option"
|
|
1970
|
+
}, [
|
|
1971
|
+
ee("input", {
|
|
1972
|
+
type: "radio",
|
|
1973
|
+
disabled: "",
|
|
1974
|
+
checked: x.control.code === P.code
|
|
1975
|
+
}, null, 8, Qi),
|
|
1976
|
+
He(J(P.value), 1)
|
|
1977
|
+
]))), 128))
|
|
1978
|
+
], 2)) : ue("", !0)
|
|
1979
|
+
], 64)) : x.type === "checkbox" ? (u(), v("input", {
|
|
1980
|
+
key: 4,
|
|
1981
|
+
type: "checkbox",
|
|
1982
|
+
checked: !!((B = x.checkbox) != null && B.value),
|
|
1983
|
+
disabled: "",
|
|
1984
|
+
class: "el-check"
|
|
1985
|
+
}, null, 8, el)) : x.type === "radio" ? (u(), v("input", {
|
|
1986
|
+
key: 5,
|
|
1987
|
+
type: "radio",
|
|
1988
|
+
checked: !!((A = x.radio) != null && A.value),
|
|
1989
|
+
disabled: "",
|
|
1990
|
+
class: "el-check"
|
|
1991
|
+
}, null, 8, tl)) : x.type === "superscript" ? (u(), v("sup", {
|
|
1992
|
+
key: 6,
|
|
1993
|
+
style: N(z(he)(x))
|
|
1994
|
+
}, J(x.value), 5)) : x.type === "subscript" ? (u(), v("sub", {
|
|
1995
|
+
key: 7,
|
|
1996
|
+
style: N(z(he)(x))
|
|
1997
|
+
}, J(x.value), 5)) : x.type === "tab" ? (u(), v("span", {
|
|
1998
|
+
key: 8,
|
|
1999
|
+
class: "doc-tab",
|
|
2000
|
+
style: N({ width: (x.size || z(qe)) + "px" })
|
|
2001
|
+
}, null, 4)) : ue("", !0)
|
|
2002
|
+
], 64);
|
|
2003
|
+
}), 128))
|
|
2004
|
+
], 4)) : ue("", !0)
|
|
2005
|
+
], 64))), 128))
|
|
2006
|
+
], 12, Ji))), 128))
|
|
2007
|
+
], 4))), 128))
|
|
2008
|
+
])
|
|
2009
|
+
], 6)
|
|
2010
|
+
], 4)
|
|
2011
|
+
], 6)) : ue("", !0);
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
}, dt = /* @__PURE__ */ Be(nl, [["__scopeId", "data-v-27e51e18"]]), il = { class: "editor-layout word-editor-scope" }, ll = { class: "editor-container" }, ol = {
|
|
2015
|
+
key: 0,
|
|
2016
|
+
class: "editor-loading"
|
|
2017
|
+
}, al = { class: "doc-header" }, sl = { class: "doc-footer" }, rl = { class: "doc-page-number" }, cl = 1123, dl = 50, ul = 20, hl = {
|
|
2018
|
+
__name: "index",
|
|
2019
|
+
props: {
|
|
2020
|
+
// 文档结构数据(IElement[]),来源由使用方决定
|
|
2021
|
+
data: {
|
|
2022
|
+
type: Array,
|
|
2023
|
+
default: () => []
|
|
2024
|
+
},
|
|
2025
|
+
// 外部数据加载态,用于展示加载占位
|
|
2026
|
+
loading: {
|
|
2027
|
+
type: Boolean,
|
|
2028
|
+
default: !1
|
|
2029
|
+
}
|
|
2030
|
+
},
|
|
2031
|
+
setup(t) {
|
|
2032
|
+
const e = t, n = ae(() => {
|
|
2033
|
+
const f = e.data;
|
|
2034
|
+
return f ? !Array.isArray(f) && f.main ? f.main : Array.isArray(f) ? f : [] : [];
|
|
2035
|
+
}), l = te(null), o = te({});
|
|
2036
|
+
let r = null;
|
|
2037
|
+
ft(() => {
|
|
2038
|
+
r = new ResizeObserver((f) => {
|
|
2039
|
+
const E = {};
|
|
2040
|
+
for (const B of f) {
|
|
2041
|
+
const A = B.target._rowKey;
|
|
2042
|
+
if (!A) continue;
|
|
2043
|
+
const P = Math.round(B.contentRect.height);
|
|
2044
|
+
P > (o.value[A] || 0) && (E[A] = P);
|
|
2045
|
+
}
|
|
2046
|
+
Object.keys(E).length && (o.value = { ...o.value, ...E });
|
|
2047
|
+
});
|
|
2048
|
+
}), lt(() => {
|
|
2049
|
+
r == null || r.disconnect(), r = null;
|
|
2050
|
+
});
|
|
2051
|
+
function y(f, E) {
|
|
2052
|
+
!f || !r || (f._rowKey = E, r.observe(f));
|
|
2053
|
+
}
|
|
2054
|
+
Kt("bindTableObserver", y);
|
|
2055
|
+
const s = ae(
|
|
2056
|
+
() => Math.max(100, cl - dl * 2 - S.value - L.value - ul)
|
|
2057
|
+
), m = ae(() => {
|
|
2058
|
+
const f = Ue(n.value), E = [], B = s.value;
|
|
2059
|
+
let A = 0;
|
|
2060
|
+
const P = Ri(), Q = { first: 0, second: 1, third: 2, fourth: 3, fifth: 4, sixth: 5, seventh: 6, eighth: 7 };
|
|
2061
|
+
let le = -1;
|
|
2062
|
+
const ot = (W) => {
|
|
2063
|
+
var pe, ye, _e;
|
|
2064
|
+
return !!((pe = W.el) != null && pe._coverBreakBefore || (_e = (ye = W.elements) == null ? void 0 : ye[0]) != null && _e._coverBreakBefore);
|
|
2065
|
+
};
|
|
2066
|
+
return f.forEach((W, pe) => {
|
|
2067
|
+
var _e, De, Ee;
|
|
2068
|
+
const ye = ot(W);
|
|
2069
|
+
if (ye && (A = 0), W.type === "title") {
|
|
2070
|
+
const ve = W.el.valueList || [], se = P.next(W.el.level, (_e = W.el.extension) == null ? void 0 : _e.startIndex), fe = ve.some((X) => {
|
|
2071
|
+
var Ce;
|
|
2072
|
+
return (Ce = X.extension) == null ? void 0 : Ce.isIndex;
|
|
2073
|
+
});
|
|
2074
|
+
let re = ve;
|
|
2075
|
+
if (!fe && se) {
|
|
2076
|
+
const X = ve[0] || {};
|
|
2077
|
+
re = [
|
|
2078
|
+
{
|
|
2079
|
+
value: se,
|
|
2080
|
+
size: X.size,
|
|
2081
|
+
bold: X.bold,
|
|
2082
|
+
italic: X.italic,
|
|
2083
|
+
color: X.color,
|
|
2084
|
+
font: X.font,
|
|
2085
|
+
extension: { isIndex: !0 }
|
|
2086
|
+
},
|
|
2087
|
+
...ve
|
|
2088
|
+
];
|
|
2089
|
+
}
|
|
2090
|
+
const we = re.map((X) => X.value || "").join(""), de = Oe(re);
|
|
2091
|
+
A = A + de > B && A > 0 ? de : A + de, le = Q[W.el.level] ?? 0, E.push({
|
|
2092
|
+
node_id: `blk_${pe}_0`,
|
|
2093
|
+
layer: ye ? 1 : 100,
|
|
2094
|
+
blockType: "title",
|
|
2095
|
+
level: W.el.level,
|
|
2096
|
+
titleEl: W.el,
|
|
2097
|
+
titleValueList: re,
|
|
2098
|
+
content_type: "text",
|
|
2099
|
+
content: we,
|
|
2100
|
+
height: de,
|
|
2101
|
+
indentPx: le * 20
|
|
2102
|
+
});
|
|
2103
|
+
} else if (W.type === "paragraph") {
|
|
2104
|
+
const ve = Oi(W.elements), se = le >= 0 ? (le + 1) * 20 : 0;
|
|
2105
|
+
ve.forEach((fe, re) => {
|
|
2106
|
+
const we = fe.map((X) => X.value || "").join(""), de = Oe(fe);
|
|
2107
|
+
A = A + de > B && A > 0 ? de : A + de, E.push({
|
|
2108
|
+
node_id: `blk_${pe}_${re}`,
|
|
2109
|
+
layer: ye && re === 0 ? 1 : 100,
|
|
2110
|
+
blockType: "paragraph",
|
|
2111
|
+
elements: fe,
|
|
2112
|
+
rowFlex: W.rowFlex,
|
|
2113
|
+
content_type: "text",
|
|
2114
|
+
content: we,
|
|
2115
|
+
height: de,
|
|
2116
|
+
indentPx: se
|
|
2117
|
+
});
|
|
2118
|
+
});
|
|
2119
|
+
} else if (W.type === "table") {
|
|
2120
|
+
const ve = !!((De = W.el.extension) != null && De.isTitleTable), se = ((Ee = W.el.extension) == null ? void 0 : Ee.elementType) === "signOff", fe = ve || se ? 0 : le >= 0 ? (le + 1) * 20 : 0, re = Ht(W.el.trList || []), we = re.length;
|
|
2121
|
+
re.forEach((de, X) => {
|
|
2122
|
+
const Ce = `blk_${pe}_${X}`, Fe = de.reduce(
|
|
2123
|
+
(xe, H) => xe + (H.height || H.minHeight || 35),
|
|
2124
|
+
0
|
|
2125
|
+
), me = Math.max(Fe, o.value[Ce] || 0);
|
|
2126
|
+
if (me > B) {
|
|
2127
|
+
const xe = Math.ceil(me / B);
|
|
2128
|
+
for (let H = 0; H < xe; H++) {
|
|
2129
|
+
const Se = H * B, Pe = Math.min(B, me - Se), We = H > 0 || A > 0;
|
|
2130
|
+
A = Pe, E.push({
|
|
2131
|
+
node_id: `blk_${pe}_${X}_s${H}`,
|
|
2132
|
+
layer: ye && X === 0 && H === 0 ? 1 : 100,
|
|
2133
|
+
blockType: "table-row-group",
|
|
2134
|
+
content_type: "table-row",
|
|
2135
|
+
rowHeight: me,
|
|
2136
|
+
trGroup: de,
|
|
2137
|
+
tableEl: W.el,
|
|
2138
|
+
tableRowFlex: W.el.rowFlex || null,
|
|
2139
|
+
isFirst: X === 0 && H === 0,
|
|
2140
|
+
isLast: X === we - 1 && H === xe - 1,
|
|
2141
|
+
isPageBreak: We,
|
|
2142
|
+
sliceOffset: Se,
|
|
2143
|
+
sliceHeight: Pe,
|
|
2144
|
+
_baseKey: H === 0 ? Ce : void 0,
|
|
2145
|
+
height: Pe,
|
|
2146
|
+
indentPx: fe
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
} else {
|
|
2150
|
+
const xe = X > 0 && A + me > B;
|
|
2151
|
+
A = A + me > B ? me : A + me, E.push({
|
|
2152
|
+
node_id: `blk_${pe}_${X}`,
|
|
2153
|
+
layer: ye && X === 0 ? 1 : 100,
|
|
2154
|
+
blockType: "table-row-group",
|
|
2155
|
+
content_type: "table-row",
|
|
2156
|
+
rowHeight: me,
|
|
2157
|
+
trGroup: de,
|
|
2158
|
+
tableEl: W.el,
|
|
2159
|
+
tableRowFlex: W.el.rowFlex || null,
|
|
2160
|
+
isFirst: X === 0,
|
|
2161
|
+
isLast: X === we - 1,
|
|
2162
|
+
isPageBreak: xe,
|
|
2163
|
+
indentPx: fe
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2166
|
+
});
|
|
2167
|
+
} else if (W.type === "list") {
|
|
2168
|
+
const ve = Math.round(18);
|
|
2169
|
+
let se = 0;
|
|
2170
|
+
for (const fe of W.items)
|
|
2171
|
+
se += fe.length ? Oe(fe) : ve;
|
|
2172
|
+
se = Math.max(se, ve), A = A + se > B && A > 0 ? se : A + se, E.push({
|
|
2173
|
+
node_id: `blk_${pe}_0`,
|
|
2174
|
+
layer: ye ? 1 : 100,
|
|
2175
|
+
blockType: "list",
|
|
2176
|
+
listType: W.listType,
|
|
2177
|
+
listStyle: W.listStyle,
|
|
2178
|
+
items: W.items,
|
|
2179
|
+
height: se,
|
|
2180
|
+
indentPx: le >= 0 ? (le + 1) * 20 : 0
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
}), E;
|
|
2184
|
+
}), h = ae(() => {
|
|
2185
|
+
var E;
|
|
2186
|
+
const f = (E = e.data) == null ? void 0 : E.header;
|
|
2187
|
+
return f != null && f.length ? Ue(f) : [];
|
|
2188
|
+
}), I = ae(() => {
|
|
2189
|
+
var E;
|
|
2190
|
+
const f = (E = e.data) == null ? void 0 : E.footer;
|
|
2191
|
+
return f != null && f.length ? Ue(f) : [];
|
|
2192
|
+
}), S = ae(() => Bt(h.value, !0)), L = ae(() => Bt(I.value, !0)), x = ae(() => h.value.length > 0), K = ae(() => I.value.length > 0);
|
|
2193
|
+
function ne(f) {
|
|
2194
|
+
var E, B, A, P;
|
|
2195
|
+
return {
|
|
2196
|
+
blockType: f.type,
|
|
2197
|
+
elements: f.elements,
|
|
2198
|
+
rowFlex: f.rowFlex,
|
|
2199
|
+
level: (E = f.el) == null ? void 0 : E.level,
|
|
2200
|
+
titleValueList: ((B = f.el) == null ? void 0 : B.titleValueList) || f.titleValueList || ((A = f.el) == null ? void 0 : A.valueList),
|
|
2201
|
+
listType: f.listType,
|
|
2202
|
+
listStyle: f.listStyle,
|
|
2203
|
+
items: f.items,
|
|
2204
|
+
indentPx: 0,
|
|
2205
|
+
trGroup: (P = f.el) != null && P.trList ? Ht(f.el.trList).flat() : void 0,
|
|
2206
|
+
tableEl: f.el,
|
|
2207
|
+
isFirst: !0,
|
|
2208
|
+
isLast: !0
|
|
2209
|
+
};
|
|
2210
|
+
}
|
|
2211
|
+
const R = ae(() => $i(m.value));
|
|
2212
|
+
function T(f) {
|
|
2213
|
+
var E;
|
|
2214
|
+
(E = l.value) == null || E.scrollToRow({ node_id: f.nodeId });
|
|
2215
|
+
}
|
|
2216
|
+
return (f, E) => (u(), v("div", il, [
|
|
2217
|
+
q(Fi, {
|
|
2218
|
+
items: R.value,
|
|
2219
|
+
onNavigate: T
|
|
2220
|
+
}, null, 8, ["items"]),
|
|
2221
|
+
ee("div", ll, [
|
|
2222
|
+
t.loading ? (u(), v("div", ol, " 加载中… ")) : (u(), ke(z(fi), {
|
|
2223
|
+
key: 1,
|
|
2224
|
+
ref_key: "virtualTableRef",
|
|
2225
|
+
ref: l,
|
|
2226
|
+
"show-header": !1,
|
|
2227
|
+
"row-config": { keyField: "node_id" },
|
|
2228
|
+
"page-config": {
|
|
2229
|
+
enabled: !0,
|
|
2230
|
+
pageHeight: 1123,
|
|
2231
|
+
pageWidth: 860,
|
|
2232
|
+
margin: 50,
|
|
2233
|
+
gap: 16,
|
|
2234
|
+
showPageHeader: x.value,
|
|
2235
|
+
showPageBorder: !0,
|
|
2236
|
+
pageBorderPadding: 5,
|
|
2237
|
+
pageBorderStyle: "1px solid #333",
|
|
2238
|
+
headerHeight: S.value,
|
|
2239
|
+
footerHeight: L.value,
|
|
2240
|
+
showPageNumber: !0
|
|
2241
|
+
},
|
|
2242
|
+
data: m.value
|
|
2243
|
+
}, In({
|
|
2244
|
+
default: Ke(() => [
|
|
2245
|
+
q(z(vi), null, {
|
|
2246
|
+
default: Ke(({ row: B }) => [
|
|
2247
|
+
q(dt, { block: B }, null, 8, ["block"])
|
|
2248
|
+
]),
|
|
2249
|
+
_: 1
|
|
2250
|
+
})
|
|
2251
|
+
]),
|
|
2252
|
+
_: 2
|
|
2253
|
+
}, [
|
|
2254
|
+
x.value ? {
|
|
2255
|
+
name: "page-header",
|
|
2256
|
+
fn: Ke(() => [
|
|
2257
|
+
ee("div", al, [
|
|
2258
|
+
(u(!0), v(U, null, Z(h.value, (B, A) => (u(), ke(dt, {
|
|
2259
|
+
key: A,
|
|
2260
|
+
block: ne(B),
|
|
2261
|
+
"is-header-footer": !0
|
|
2262
|
+
}, null, 8, ["block"]))), 128))
|
|
2263
|
+
])
|
|
2264
|
+
]),
|
|
2265
|
+
key: "0"
|
|
2266
|
+
} : void 0,
|
|
2267
|
+
K.value ? {
|
|
2268
|
+
name: "page-footer",
|
|
2269
|
+
fn: Ke(({ pageNumber: B, totalPages: A }) => [
|
|
2270
|
+
ee("div", sl, [
|
|
2271
|
+
(u(!0), v(U, null, Z(I.value, (P, Q) => (u(), ke(dt, {
|
|
2272
|
+
key: Q,
|
|
2273
|
+
block: ne(P),
|
|
2274
|
+
"is-header-footer": !0
|
|
2275
|
+
}, null, 8, ["block"]))), 128)),
|
|
2276
|
+
ee("div", rl, J(B) + " / " + J(A), 1)
|
|
2277
|
+
])
|
|
2278
|
+
]),
|
|
2279
|
+
key: "1"
|
|
2280
|
+
} : void 0
|
|
2281
|
+
]), 1032, ["page-config", "data"]))
|
|
2282
|
+
])
|
|
2283
|
+
]));
|
|
2284
|
+
}
|
|
2285
|
+
}, fl = /* @__PURE__ */ Be(hl, [["__scopeId", "data-v-f3f51b5c"]]), Dt = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
2286
|
+
function tt(t = 10) {
|
|
2287
|
+
const e = crypto.getRandomValues(new Uint8Array(t));
|
|
2288
|
+
return Array.from(e).map((n) => Dt[n % Dt.length]).join("");
|
|
2289
|
+
}
|
|
2290
|
+
class it {
|
|
2291
|
+
constructor(e) {
|
|
2292
|
+
D(this, "data");
|
|
2293
|
+
this.data = qt({
|
|
2294
|
+
id: tt(),
|
|
2295
|
+
version: 1,
|
|
2296
|
+
sections: [this.createEmptySection()],
|
|
2297
|
+
pageWidth: 595,
|
|
2298
|
+
pageHeight: 842,
|
|
2299
|
+
marginTop: 72,
|
|
2300
|
+
marginBottom: 72,
|
|
2301
|
+
marginLeft: 90,
|
|
2302
|
+
marginRight: 90,
|
|
2303
|
+
...e
|
|
2304
|
+
});
|
|
2305
|
+
}
|
|
2306
|
+
// ─── 工厂方法 ─────────────────────────────────────────────────────────────
|
|
2307
|
+
createEmptySection() {
|
|
2308
|
+
return {
|
|
2309
|
+
id: tt(),
|
|
2310
|
+
paragraphs: [this.createEmptyParagraph()]
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
createEmptyParagraph(e) {
|
|
2314
|
+
return {
|
|
2315
|
+
id: tt(),
|
|
2316
|
+
type: "paragraph",
|
|
2317
|
+
format: e ?? {},
|
|
2318
|
+
children: []
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
createTextElement(e, n) {
|
|
2322
|
+
return {
|
|
2323
|
+
id: tt(),
|
|
2324
|
+
type: "text",
|
|
2325
|
+
value: e,
|
|
2326
|
+
format: n ?? {}
|
|
2327
|
+
};
|
|
2328
|
+
}
|
|
2329
|
+
// ─── 查询方法 ─────────────────────────────────────────────────────────────
|
|
2330
|
+
getSectionCount() {
|
|
2331
|
+
return this.data.sections.length;
|
|
2332
|
+
}
|
|
2333
|
+
getParagraphCount(e = 0) {
|
|
2334
|
+
var n;
|
|
2335
|
+
return ((n = this.data.sections[e]) == null ? void 0 : n.paragraphs.length) ?? 0;
|
|
2336
|
+
}
|
|
2337
|
+
/** 获取所有段落(展开所有 section) */
|
|
2338
|
+
getAllParagraphs() {
|
|
2339
|
+
const e = [];
|
|
2340
|
+
return this.data.sections.forEach((n, l) => {
|
|
2341
|
+
n.paragraphs.forEach((o, r) => {
|
|
2342
|
+
e.push({ paragraph: o, sectionIndex: l, paragraphIndex: r });
|
|
2343
|
+
});
|
|
2344
|
+
}), e;
|
|
2345
|
+
}
|
|
2346
|
+
getParagraphAt(e, n) {
|
|
2347
|
+
var l;
|
|
2348
|
+
return ((l = this.data.sections[e]) == null ? void 0 : l.paragraphs[n]) ?? null;
|
|
2349
|
+
}
|
|
2350
|
+
getElementAt(e) {
|
|
2351
|
+
const n = this.getParagraphAt(e.sectionIndex, e.paragraphIndex);
|
|
2352
|
+
return (n == null ? void 0 : n.children[e.elementIndex]) ?? null;
|
|
2353
|
+
}
|
|
2354
|
+
// ─── 原子修改方法(由 Command 调用)─────────────────────────────────────
|
|
2355
|
+
/** 在指定位置插入文本(拆分/合并 text element) */
|
|
2356
|
+
insertText(e, n, l) {
|
|
2357
|
+
const o = this.getParagraphAt(e.sectionIndex, e.paragraphIndex);
|
|
2358
|
+
if (!o) return;
|
|
2359
|
+
const r = o.children[e.elementIndex];
|
|
2360
|
+
if (r && r.type === "text")
|
|
2361
|
+
r.value = r.value.slice(0, e.offset) + n + r.value.slice(e.offset);
|
|
2362
|
+
else {
|
|
2363
|
+
const y = this.createTextElement(n, l);
|
|
2364
|
+
o.children.splice(e.elementIndex, 0, y);
|
|
2365
|
+
}
|
|
2366
|
+
this.bumpVersion();
|
|
2367
|
+
}
|
|
2368
|
+
/** 删除指定范围内容 */
|
|
2369
|
+
deleteAt(e, n) {
|
|
2370
|
+
const l = this.getParagraphAt(e.sectionIndex, e.paragraphIndex);
|
|
2371
|
+
if (!l) return;
|
|
2372
|
+
const o = l.children[e.elementIndex];
|
|
2373
|
+
!o || o.type !== "text" || (o.value = o.value.slice(0, e.offset) + o.value.slice(e.offset + n), o.value === "" && l.children.splice(e.elementIndex, 1), this.bumpVersion());
|
|
2374
|
+
}
|
|
2375
|
+
/** 在段落后插入新段落 */
|
|
2376
|
+
insertParagraph(e, n, l) {
|
|
2377
|
+
const o = this.data.sections[e];
|
|
2378
|
+
if (!o) throw new Error(`Section ${e} not found`);
|
|
2379
|
+
const r = this.createEmptyParagraph(l);
|
|
2380
|
+
return o.paragraphs.splice(n + 1, 0, r), this.bumpVersion(), r;
|
|
2381
|
+
}
|
|
2382
|
+
/** 合并两个相邻段落 */
|
|
2383
|
+
mergeParagraphs(e, n) {
|
|
2384
|
+
const l = this.data.sections[e];
|
|
2385
|
+
if (!l) return;
|
|
2386
|
+
const o = l.paragraphs[n], r = l.paragraphs[n + 1];
|
|
2387
|
+
!o || !r || (o.children.push(...r.children), l.paragraphs.splice(n + 1, 1), this.bumpVersion());
|
|
2388
|
+
}
|
|
2389
|
+
/** 更新段落格式 */
|
|
2390
|
+
updateParagraphFormat(e, n, l) {
|
|
2391
|
+
const o = this.getParagraphAt(e, n);
|
|
2392
|
+
o && (o.format = { ...o.format, ...l }, this.bumpVersion());
|
|
2393
|
+
}
|
|
2394
|
+
/** 更新元素格式 */
|
|
2395
|
+
updateElementFormat(e, n) {
|
|
2396
|
+
const l = this.getElementAt(e);
|
|
2397
|
+
l && (l.format = { ...l.format, ...n }, this.bumpVersion());
|
|
2398
|
+
}
|
|
2399
|
+
/** 批量更新选区内元素格式 */
|
|
2400
|
+
updateRangeFormat(e, n, l) {
|
|
2401
|
+
const o = this.getAllParagraphs();
|
|
2402
|
+
let r = !1;
|
|
2403
|
+
for (const { paragraph: y, sectionIndex: s, paragraphIndex: m } of o) {
|
|
2404
|
+
const h = s === e.sectionIndex && m === e.paragraphIndex, I = s === n.sectionIndex && m === n.paragraphIndex;
|
|
2405
|
+
if (h && (r = !0), r)
|
|
2406
|
+
for (let S = 0; S < y.children.length; S++) {
|
|
2407
|
+
const L = y.children[S];
|
|
2408
|
+
if (!(h && S < e.elementIndex)) {
|
|
2409
|
+
if (I && S > n.elementIndex) break;
|
|
2410
|
+
L.format = { ...L.format, ...l };
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
if (I) break;
|
|
2414
|
+
}
|
|
2415
|
+
this.bumpVersion();
|
|
2416
|
+
}
|
|
2417
|
+
bumpVersion() {
|
|
2418
|
+
this.data.version++;
|
|
2419
|
+
}
|
|
2420
|
+
/** 序列化为 JSON */
|
|
2421
|
+
toJSON() {
|
|
2422
|
+
return JSON.stringify(this.data, null, 2);
|
|
2423
|
+
}
|
|
2424
|
+
/** 从 JSON 恢复 */
|
|
2425
|
+
static fromJSON(e) {
|
|
2426
|
+
const n = JSON.parse(e), l = new it();
|
|
2427
|
+
return Object.assign(l.data, n), l;
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
function Te(t = 0, e = 0, n = 0, l = 0) {
|
|
2431
|
+
return { sectionIndex: t, paragraphIndex: e, elementIndex: n, offset: l };
|
|
2432
|
+
}
|
|
2433
|
+
function Nt(t, e) {
|
|
2434
|
+
return t.sectionIndex === e.sectionIndex && t.paragraphIndex === e.paragraphIndex && t.elementIndex === e.elementIndex && t.offset === e.offset;
|
|
2435
|
+
}
|
|
2436
|
+
class ht {
|
|
2437
|
+
constructor(e) {
|
|
2438
|
+
D(this, "_selection", qt({
|
|
2439
|
+
anchor: Te(),
|
|
2440
|
+
focus: Te(),
|
|
2441
|
+
isCollapsed: !0
|
|
2442
|
+
}));
|
|
2443
|
+
D(this, "_docModel");
|
|
2444
|
+
/** 是否有选区(非光标) */
|
|
2445
|
+
D(this, "hasSelection", ae(() => !this._selection.isCollapsed));
|
|
2446
|
+
this._docModel = e;
|
|
2447
|
+
}
|
|
2448
|
+
get selection() {
|
|
2449
|
+
return this._selection;
|
|
2450
|
+
}
|
|
2451
|
+
// ─── 设置选区 ─────────────────────────────────────────────────────────────
|
|
2452
|
+
setCursor(e) {
|
|
2453
|
+
this._selection.anchor = { ...e }, this._selection.focus = { ...e }, this._selection.isCollapsed = !0;
|
|
2454
|
+
}
|
|
2455
|
+
setSelection(e, n) {
|
|
2456
|
+
this._selection.anchor = { ...e }, this._selection.focus = { ...n }, this._selection.isCollapsed = Nt(e, n);
|
|
2457
|
+
}
|
|
2458
|
+
collapse(e = !0) {
|
|
2459
|
+
e ? this._selection.anchor = { ...this._selection.focus } : this._selection.focus = { ...this._selection.anchor }, this._selection.isCollapsed = !0;
|
|
2460
|
+
}
|
|
2461
|
+
selectAll() {
|
|
2462
|
+
const e = this._docModel.data.sections, n = e[e.length - 1], l = n == null ? void 0 : n.paragraphs[n.paragraphs.length - 1], o = l == null ? void 0 : l.children[l.children.length - 1], r = (o == null ? void 0 : o.type) === "text" ? o.value.length : 0;
|
|
2463
|
+
this._selection.anchor = Te(0, 0, 0, 0), this._selection.focus = Te(
|
|
2464
|
+
e.length - 1,
|
|
2465
|
+
((n == null ? void 0 : n.paragraphs.length) ?? 1) - 1,
|
|
2466
|
+
((l == null ? void 0 : l.children.length) ?? 0) === 0 ? 0 : ((l == null ? void 0 : l.children.length) ?? 1) - 1,
|
|
2467
|
+
r
|
|
2468
|
+
), this._selection.isCollapsed = !1;
|
|
2469
|
+
}
|
|
2470
|
+
// ─── 移动光标 ─────────────────────────────────────────────────────────────
|
|
2471
|
+
/** 光标向前移动一个字符 */
|
|
2472
|
+
moveForward(e = !1) {
|
|
2473
|
+
const n = this._selection.focus, l = this._docModel.getParagraphAt(n.sectionIndex, n.paragraphIndex);
|
|
2474
|
+
if (!l) return;
|
|
2475
|
+
const o = l.children[n.elementIndex];
|
|
2476
|
+
if ((o == null ? void 0 : o.type) === "text" && n.offset < o.value.length) {
|
|
2477
|
+
const y = { ...n, offset: n.offset + 1 };
|
|
2478
|
+
this._applyMove(y, e);
|
|
2479
|
+
return;
|
|
2480
|
+
}
|
|
2481
|
+
if (n.elementIndex < l.children.length - 1) {
|
|
2482
|
+
const y = { ...n, elementIndex: n.elementIndex + 1, offset: 0 };
|
|
2483
|
+
this._applyMove(y, e);
|
|
2484
|
+
return;
|
|
2485
|
+
}
|
|
2486
|
+
const r = this._getNextParagraphPoint(n);
|
|
2487
|
+
r && this._applyMove(r, e);
|
|
2488
|
+
}
|
|
2489
|
+
/** 光标向后移动一个字符 */
|
|
2490
|
+
moveBackward(e = !1) {
|
|
2491
|
+
const n = this._selection.focus;
|
|
2492
|
+
if (n.offset > 0) {
|
|
2493
|
+
const o = { ...n, offset: n.offset - 1 };
|
|
2494
|
+
this._applyMove(o, e);
|
|
2495
|
+
return;
|
|
2496
|
+
}
|
|
2497
|
+
if (n.elementIndex > 0) {
|
|
2498
|
+
const o = this._docModel.getParagraphAt(n.sectionIndex, n.paragraphIndex), r = o == null ? void 0 : o.children[n.elementIndex - 1], y = (r == null ? void 0 : r.type) === "text" ? r.value.length : 0, s = { ...n, elementIndex: n.elementIndex - 1, offset: y };
|
|
2499
|
+
this._applyMove(s, e);
|
|
2500
|
+
return;
|
|
2501
|
+
}
|
|
2502
|
+
const l = this._getPrevParagraphPoint(n);
|
|
2503
|
+
l && this._applyMove(l, e);
|
|
2504
|
+
}
|
|
2505
|
+
_applyMove(e, n) {
|
|
2506
|
+
n ? (this._selection.focus = e, this._selection.isCollapsed = Nt(this._selection.anchor, e)) : (this._selection.anchor = { ...e }, this._selection.focus = { ...e }, this._selection.isCollapsed = !0);
|
|
2507
|
+
}
|
|
2508
|
+
_getNextParagraphPoint(e) {
|
|
2509
|
+
const n = this._docModel.data.sections[e.sectionIndex];
|
|
2510
|
+
return n ? e.paragraphIndex < n.paragraphs.length - 1 ? Te(e.sectionIndex, e.paragraphIndex + 1, 0, 0) : e.sectionIndex < this._docModel.data.sections.length - 1 ? Te(e.sectionIndex + 1, 0, 0, 0) : null : null;
|
|
2511
|
+
}
|
|
2512
|
+
_getPrevParagraphPoint(e) {
|
|
2513
|
+
if (e.paragraphIndex > 0) {
|
|
2514
|
+
const n = this._docModel.getParagraphAt(e.sectionIndex, e.paragraphIndex - 1);
|
|
2515
|
+
if (!n) return null;
|
|
2516
|
+
const l = n.children.length - 1, o = n.children[l], r = (o == null ? void 0 : o.type) === "text" ? o.value.length : 0;
|
|
2517
|
+
return Te(e.sectionIndex, e.paragraphIndex - 1, Math.max(l, 0), r);
|
|
2518
|
+
}
|
|
2519
|
+
if (e.sectionIndex > 0) {
|
|
2520
|
+
const n = this._docModel.data.sections[e.sectionIndex - 1];
|
|
2521
|
+
if (!n) return null;
|
|
2522
|
+
const l = n.paragraphs.length - 1, o = n.paragraphs[l], r = ((o == null ? void 0 : o.children.length) ?? 0) - 1, y = o == null ? void 0 : o.children[r], s = (y == null ? void 0 : y.type) === "text" ? y.value.length : 0;
|
|
2523
|
+
return Te(e.sectionIndex - 1, l, Math.max(r, 0), s);
|
|
2524
|
+
}
|
|
2525
|
+
return null;
|
|
2526
|
+
}
|
|
2527
|
+
// ─── DOM 坐标 <-> 模型坐标转换 ───────────────────────────────────────────
|
|
2528
|
+
/**
|
|
2529
|
+
* 从 DOM element 的 data-* 属性解析模型坐标
|
|
2530
|
+
* 渲染时每个元素需附带 data-si/data-pi/data-ei 属性
|
|
2531
|
+
*/
|
|
2532
|
+
static domToModelPoint(e, n) {
|
|
2533
|
+
let l = e instanceof Element ? e : e.parentElement;
|
|
2534
|
+
for (; l; ) {
|
|
2535
|
+
const o = l.getAttribute("data-si"), r = l.getAttribute("data-pi"), y = l.getAttribute("data-ei");
|
|
2536
|
+
if (o !== null && r !== null && y !== null)
|
|
2537
|
+
return {
|
|
2538
|
+
sectionIndex: parseInt(o),
|
|
2539
|
+
paragraphIndex: parseInt(r),
|
|
2540
|
+
elementIndex: parseInt(y),
|
|
2541
|
+
offset: n
|
|
2542
|
+
};
|
|
2543
|
+
l = l.parentElement;
|
|
2544
|
+
}
|
|
2545
|
+
return null;
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
const gl = 200;
|
|
2549
|
+
class pl {
|
|
2550
|
+
constructor() {
|
|
2551
|
+
D(this, "_undoStack", []);
|
|
2552
|
+
D(this, "_redoStack", []);
|
|
2553
|
+
}
|
|
2554
|
+
get canUndo() {
|
|
2555
|
+
return this._undoStack.length > 0;
|
|
2556
|
+
}
|
|
2557
|
+
get canRedo() {
|
|
2558
|
+
return this._redoStack.length > 0;
|
|
2559
|
+
}
|
|
2560
|
+
/**
|
|
2561
|
+
* 推入命令(执行后调用)
|
|
2562
|
+
* 支持合并连续同类命令(如连续输入文字)
|
|
2563
|
+
*/
|
|
2564
|
+
push(e) {
|
|
2565
|
+
var l, o;
|
|
2566
|
+
this._redoStack = [];
|
|
2567
|
+
const n = this._undoStack[this._undoStack.length - 1];
|
|
2568
|
+
if (n && ((l = e.canMergeWith) != null && l.call(e, n))) {
|
|
2569
|
+
(o = n.merge) == null || o.call(n, e);
|
|
2570
|
+
return;
|
|
2571
|
+
}
|
|
2572
|
+
this._undoStack.push(e), this._undoStack.length > gl && this._undoStack.shift();
|
|
2573
|
+
}
|
|
2574
|
+
undo() {
|
|
2575
|
+
const e = this._undoStack.pop();
|
|
2576
|
+
return e ? (e.undo(), this._redoStack.push(e), !0) : !1;
|
|
2577
|
+
}
|
|
2578
|
+
redo() {
|
|
2579
|
+
const e = this._redoStack.pop();
|
|
2580
|
+
return e ? (e.execute(), this._undoStack.push(e), !0) : !1;
|
|
2581
|
+
}
|
|
2582
|
+
clear() {
|
|
2583
|
+
this._undoStack = [], this._redoStack = [];
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
class vl {
|
|
2587
|
+
constructor(e, n, l, o, r) {
|
|
2588
|
+
D(this, "name", "insertText");
|
|
2589
|
+
D(this, "_point");
|
|
2590
|
+
D(this, "_text");
|
|
2591
|
+
D(this, "_format");
|
|
2592
|
+
this.docModel = e, this.selectionManager = n, this._point = { ...l }, this._text = o, this._format = r;
|
|
2593
|
+
}
|
|
2594
|
+
execute() {
|
|
2595
|
+
this.docModel.insertText(this._point, this._text, this._format), this.selectionManager.setCursor({
|
|
2596
|
+
...this._point,
|
|
2597
|
+
offset: this._point.offset + this._text.length
|
|
2598
|
+
});
|
|
2599
|
+
}
|
|
2600
|
+
undo() {
|
|
2601
|
+
this.docModel.deleteAt(this._point, this._text.length), this.selectionManager.setCursor(this._point);
|
|
2602
|
+
}
|
|
2603
|
+
canMergeWith(e) {
|
|
2604
|
+
if (e.name !== "insertText") return !1;
|
|
2605
|
+
const n = e;
|
|
2606
|
+
return n._point.sectionIndex === this._point.sectionIndex && n._point.paragraphIndex === this._point.paragraphIndex && n._point.elementIndex === this._point.elementIndex && n._point.offset === this._point.offset + this._text.length;
|
|
2607
|
+
}
|
|
2608
|
+
merge(e) {
|
|
2609
|
+
const n = e;
|
|
2610
|
+
this._text += n._text;
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
class ml {
|
|
2614
|
+
constructor(e, n) {
|
|
2615
|
+
D(this, "name", "insertParagraph");
|
|
2616
|
+
D(this, "_insertedParagraphId", null);
|
|
2617
|
+
this.docModel = e, this.selectionManager = n;
|
|
2618
|
+
}
|
|
2619
|
+
execute() {
|
|
2620
|
+
var m, h;
|
|
2621
|
+
const { focus: e } = this.selectionManager.selection, { sectionIndex: n, paragraphIndex: l } = e, o = this.docModel.getParagraphAt(n, l);
|
|
2622
|
+
if (!o) return;
|
|
2623
|
+
const r = e.elementIndex, y = o.children.splice(r), s = this.docModel.createEmptyParagraph(o.format);
|
|
2624
|
+
s.children.push(...y), this._insertedParagraphId = s.id, this.docModel.data.sections[n].paragraphs.splice(l + 1, 0, s), (h = (m = this.docModel).bumpVersion) == null || h.call(m), this.selectionManager.setCursor({
|
|
2625
|
+
sectionIndex: n,
|
|
2626
|
+
paragraphIndex: l + 1,
|
|
2627
|
+
elementIndex: 0,
|
|
2628
|
+
offset: 0
|
|
2629
|
+
});
|
|
2630
|
+
}
|
|
2631
|
+
undo() {
|
|
2632
|
+
const { focus: e } = this.selectionManager.selection, { sectionIndex: n, paragraphIndex: l } = e;
|
|
2633
|
+
l !== 0 && (this.docModel.mergeParagraphs(n, l - 1), this.selectionManager.setCursor({
|
|
2634
|
+
sectionIndex: n,
|
|
2635
|
+
paragraphIndex: l - 1,
|
|
2636
|
+
elementIndex: 0,
|
|
2637
|
+
offset: 0
|
|
2638
|
+
}));
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
class zt {
|
|
2642
|
+
constructor(e, n, l) {
|
|
2643
|
+
D(this, "name");
|
|
2644
|
+
D(this, "_deletedText", "");
|
|
2645
|
+
this.docModel = e, this.selectionManager = n, this.name = l === "backward" ? "deleteBackward" : "deleteForward";
|
|
2646
|
+
}
|
|
2647
|
+
execute() {
|
|
2648
|
+
const { focus: e, isCollapsed: n } = this.selectionManager.selection;
|
|
2649
|
+
if (n)
|
|
2650
|
+
if (this.name === "deleteBackward")
|
|
2651
|
+
if (e.offset > 0) {
|
|
2652
|
+
const l = { ...e, offset: e.offset - 1 }, o = this.docModel.getElementAt(e);
|
|
2653
|
+
(o == null ? void 0 : o.type) === "text" && (this._deletedText = o.value[e.offset - 1] ?? ""), this.docModel.deleteAt(l, 1), this.selectionManager.setCursor(l);
|
|
2654
|
+
} else (e.paragraphIndex > 0 || e.elementIndex > 0) && (this.docModel.mergeParagraphs(e.sectionIndex, e.paragraphIndex - 1), this.selectionManager.setCursor({
|
|
2655
|
+
...e,
|
|
2656
|
+
paragraphIndex: e.paragraphIndex - 1
|
|
2657
|
+
}));
|
|
2658
|
+
else {
|
|
2659
|
+
const l = this.docModel.getElementAt(e);
|
|
2660
|
+
if ((l == null ? void 0 : l.type) === "text" && e.offset < l.value.length)
|
|
2661
|
+
this._deletedText = l.value[e.offset], this.docModel.deleteAt(e, 1);
|
|
2662
|
+
else {
|
|
2663
|
+
const o = this.docModel.data.sections[e.sectionIndex];
|
|
2664
|
+
o && e.paragraphIndex < o.paragraphs.length - 1 && this.docModel.mergeParagraphs(e.sectionIndex, e.paragraphIndex);
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
undo() {
|
|
2669
|
+
if (this._deletedText) {
|
|
2670
|
+
const { focus: e } = this.selectionManager.selection;
|
|
2671
|
+
this.docModel.insertText(e, this._deletedText);
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
class je {
|
|
2676
|
+
constructor(e, n, l, o) {
|
|
2677
|
+
D(this, "name");
|
|
2678
|
+
D(this, "_prevFormat", {});
|
|
2679
|
+
this.docModel = e, this.selectionManager = n, this._value = o, this.name = l;
|
|
2680
|
+
}
|
|
2681
|
+
execute() {
|
|
2682
|
+
const { anchor: e, focus: n } = this.selectionManager.selection, l = this._getFormatKey();
|
|
2683
|
+
if (!l) return;
|
|
2684
|
+
const o = {};
|
|
2685
|
+
if (this._isToggle()) {
|
|
2686
|
+
const r = this._getCurrentValue(l);
|
|
2687
|
+
o[l] = !r;
|
|
2688
|
+
} else
|
|
2689
|
+
o[l] = this._value;
|
|
2690
|
+
this.docModel.updateRangeFormat(e, n, o);
|
|
2691
|
+
}
|
|
2692
|
+
undo() {
|
|
2693
|
+
const { anchor: e, focus: n } = this.selectionManager.selection;
|
|
2694
|
+
this.docModel.updateRangeFormat(e, n, this._prevFormat);
|
|
2695
|
+
}
|
|
2696
|
+
_isToggle() {
|
|
2697
|
+
return ["bold", "italic", "underline", "strikethrough", "superscript", "subscript"].includes(this.name);
|
|
2698
|
+
}
|
|
2699
|
+
_getFormatKey() {
|
|
2700
|
+
return {
|
|
2701
|
+
bold: "bold",
|
|
2702
|
+
italic: "italic",
|
|
2703
|
+
underline: "underline",
|
|
2704
|
+
strikethrough: "strikethrough",
|
|
2705
|
+
fontSize: "fontSize",
|
|
2706
|
+
fontFamily: "fontFamily",
|
|
2707
|
+
color: "color",
|
|
2708
|
+
backgroundColor: "backgroundColor"
|
|
2709
|
+
}[this.name] ?? null;
|
|
2710
|
+
}
|
|
2711
|
+
_getCurrentValue(e) {
|
|
2712
|
+
var o;
|
|
2713
|
+
const { focus: n } = this.selectionManager.selection, l = this.docModel.getElementAt(n);
|
|
2714
|
+
return (o = l == null ? void 0 : l.format) == null ? void 0 : o[e];
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
class ut {
|
|
2718
|
+
constructor(e, n, l, o) {
|
|
2719
|
+
D(this, "name", "textAlign");
|
|
2720
|
+
this.docModel = e, this.selectionManager = n, this._formatKey = l, this._value = o;
|
|
2721
|
+
}
|
|
2722
|
+
execute() {
|
|
2723
|
+
const { focus: e } = this.selectionManager.selection, n = {};
|
|
2724
|
+
n[this._formatKey] = this._value, this.docModel.updateParagraphFormat(e.sectionIndex, e.paragraphIndex, n);
|
|
2725
|
+
}
|
|
2726
|
+
undo() {
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
class yl {
|
|
2730
|
+
constructor(e, n, l) {
|
|
2731
|
+
D(this, "_factories", /* @__PURE__ */ new Map());
|
|
2732
|
+
this.docModel = e, this.selectionManager = n, this.historyManager = l, this._registerBuiltinCommands();
|
|
2733
|
+
}
|
|
2734
|
+
// ─── 注册内置命令 ─────────────────────────────────────────────────────────
|
|
2735
|
+
_registerBuiltinCommands() {
|
|
2736
|
+
this.register("insertText", (n) => {
|
|
2737
|
+
const { focus: l } = this.selectionManager.selection;
|
|
2738
|
+
return new vl(this.docModel, this.selectionManager, l, n);
|
|
2739
|
+
}), this.register("insertParagraph", () => new ml(this.docModel, this.selectionManager)), this.register("deleteBackward", () => new zt(this.docModel, this.selectionManager, "backward")), this.register("deleteForward", () => new zt(this.docModel, this.selectionManager, "forward")), this.register("undo", () => null), this.register("redo", () => null), ["bold", "italic", "underline", "strikethrough", "superscript", "subscript"].forEach((n) => {
|
|
2740
|
+
this.register(n, () => new je(this.docModel, this.selectionManager, n));
|
|
2741
|
+
}), this.register("fontSize", (n) => new je(this.docModel, this.selectionManager, "fontSize", n)), this.register("fontFamily", (n) => new je(this.docModel, this.selectionManager, "fontFamily", n)), this.register("color", (n) => new je(this.docModel, this.selectionManager, "color", n)), this.register("backgroundColor", (n) => new je(this.docModel, this.selectionManager, "backgroundColor", n)), this.register("textAlign", (n) => new ut(this.docModel, this.selectionManager, "textAlign", n)), this.register("lineHeight", (n) => new ut(this.docModel, this.selectionManager, "lineHeight", n)), this.register("heading", (n) => new ut(this.docModel, this.selectionManager, "heading", n)), this.register("selectAll", () => (this.selectionManager.selectAll(), null)), this.register("setSelection", (n) => {
|
|
2742
|
+
if (n) {
|
|
2743
|
+
const l = n;
|
|
2744
|
+
this.selectionManager.setSelection(l.anchor, l.focus);
|
|
2745
|
+
}
|
|
2746
|
+
return null;
|
|
2747
|
+
});
|
|
2748
|
+
}
|
|
2749
|
+
// ─── 公共 API ─────────────────────────────────────────────────────────────
|
|
2750
|
+
register(e, n) {
|
|
2751
|
+
this._factories.set(e, n);
|
|
2752
|
+
}
|
|
2753
|
+
exec(e, n) {
|
|
2754
|
+
if (e === "undo") {
|
|
2755
|
+
this.historyManager.undo();
|
|
2756
|
+
return;
|
|
2757
|
+
}
|
|
2758
|
+
if (e === "redo") {
|
|
2759
|
+
this.historyManager.redo();
|
|
2760
|
+
return;
|
|
2761
|
+
}
|
|
2762
|
+
const l = this._factories.get(e);
|
|
2763
|
+
if (!l) {
|
|
2764
|
+
console.warn(`[CommandManager] 未注册命令: ${e}`);
|
|
2765
|
+
return;
|
|
2766
|
+
}
|
|
2767
|
+
const o = l(n);
|
|
2768
|
+
o && (o.execute(), this.historyManager.push(o));
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
class bl {
|
|
2772
|
+
constructor(e, n) {
|
|
2773
|
+
D(this, "_el", null);
|
|
2774
|
+
D(this, "_commandManager");
|
|
2775
|
+
D(this, "_selectionManager");
|
|
2776
|
+
D(this, "_composing", !1);
|
|
2777
|
+
// 正在 IME 输入中
|
|
2778
|
+
D(this, "_boundKeydown");
|
|
2779
|
+
D(this, "_boundBeforeInput");
|
|
2780
|
+
D(this, "_boundCompositionStart");
|
|
2781
|
+
D(this, "_boundCompositionEnd");
|
|
2782
|
+
D(this, "_boundSelectionChange");
|
|
2783
|
+
this._commandManager = e, this._selectionManager = n, this._boundKeydown = this._onKeydown.bind(this), this._boundBeforeInput = this._onBeforeInput.bind(this), this._boundCompositionStart = () => {
|
|
2784
|
+
this._composing = !0;
|
|
2785
|
+
}, this._boundCompositionEnd = this._onCompositionEnd.bind(this), this._boundSelectionChange = this._onSelectionChange.bind(this);
|
|
2786
|
+
}
|
|
2787
|
+
attach(e) {
|
|
2788
|
+
this._el = e, e.addEventListener("keydown", this._boundKeydown), e.addEventListener("beforeinput", this._boundBeforeInput), e.addEventListener("compositionstart", this._boundCompositionStart), e.addEventListener("compositionend", this._boundCompositionEnd), document.addEventListener("selectionchange", this._boundSelectionChange);
|
|
2789
|
+
}
|
|
2790
|
+
detach() {
|
|
2791
|
+
this._el && (this._el.removeEventListener("keydown", this._boundKeydown), this._el.removeEventListener("beforeinput", this._boundBeforeInput), this._el.removeEventListener("compositionstart", this._boundCompositionStart), this._el.removeEventListener("compositionend", this._boundCompositionEnd), document.removeEventListener("selectionchange", this._boundSelectionChange), this._el = null);
|
|
2792
|
+
}
|
|
2793
|
+
// ─── 事件处理 ─────────────────────────────────────────────────────────────
|
|
2794
|
+
_onKeydown(e) {
|
|
2795
|
+
const n = e.key, l = e.ctrlKey || e.metaKey, o = e.shiftKey;
|
|
2796
|
+
if (l)
|
|
2797
|
+
switch (n) {
|
|
2798
|
+
case "z":
|
|
2799
|
+
e.preventDefault(), o ? this._commandManager.exec("redo") : this._commandManager.exec("undo");
|
|
2800
|
+
return;
|
|
2801
|
+
case "b":
|
|
2802
|
+
e.preventDefault(), this._commandManager.exec("bold");
|
|
2803
|
+
return;
|
|
2804
|
+
case "i":
|
|
2805
|
+
e.preventDefault(), this._commandManager.exec("italic");
|
|
2806
|
+
return;
|
|
2807
|
+
case "u":
|
|
2808
|
+
e.preventDefault(), this._commandManager.exec("underline");
|
|
2809
|
+
return;
|
|
2810
|
+
case "a":
|
|
2811
|
+
e.preventDefault(), this._commandManager.exec("selectAll");
|
|
2812
|
+
return;
|
|
2813
|
+
}
|
|
2814
|
+
switch (n) {
|
|
2815
|
+
case "Enter":
|
|
2816
|
+
e.preventDefault(), this._composing || this._commandManager.exec("insertParagraph");
|
|
2817
|
+
break;
|
|
2818
|
+
case "Backspace":
|
|
2819
|
+
e.preventDefault(), this._composing || this._commandManager.exec("deleteBackward");
|
|
2820
|
+
break;
|
|
2821
|
+
case "Delete":
|
|
2822
|
+
e.preventDefault(), this._composing || this._commandManager.exec("deleteForward");
|
|
2823
|
+
break;
|
|
2824
|
+
case "ArrowLeft":
|
|
2825
|
+
e.preventDefault(), this._selectionManager.moveBackward(o);
|
|
2826
|
+
break;
|
|
2827
|
+
case "ArrowRight":
|
|
2828
|
+
e.preventDefault(), this._selectionManager.moveForward(o);
|
|
2829
|
+
break;
|
|
2830
|
+
case "Tab":
|
|
2831
|
+
e.preventDefault(), this._commandManager.exec("insertText", " ");
|
|
2832
|
+
break;
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
_onBeforeInput(e) {
|
|
2836
|
+
e.preventDefault(), !this._composing && e.data && this._commandManager.exec("insertText", e.data);
|
|
2837
|
+
}
|
|
2838
|
+
_onCompositionEnd(e) {
|
|
2839
|
+
this._composing = !1, e.data && this._commandManager.exec("insertText", e.data);
|
|
2840
|
+
}
|
|
2841
|
+
_onSelectionChange() {
|
|
2842
|
+
const e = window.getSelection();
|
|
2843
|
+
if (!e || !this._el) return;
|
|
2844
|
+
const n = e.anchorNode, l = e.focusNode;
|
|
2845
|
+
if (!n || !l || !this._el.contains(n) && !this._el.contains(l)) return;
|
|
2846
|
+
const o = ht.domToModelPoint(n, e.anchorOffset), r = ht.domToModelPoint(l, e.focusOffset);
|
|
2847
|
+
o && r && this._selectionManager.setSelection(o, r);
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
class _l {
|
|
2851
|
+
constructor(e = {}) {
|
|
2852
|
+
D(this, "docModel");
|
|
2853
|
+
D(this, "selection");
|
|
2854
|
+
D(this, "history");
|
|
2855
|
+
D(this, "commands");
|
|
2856
|
+
D(this, "input");
|
|
2857
|
+
D(this, "_readonly");
|
|
2858
|
+
D(this, "_plugins", []);
|
|
2859
|
+
D(this, "_inputEl", null);
|
|
2860
|
+
var n;
|
|
2861
|
+
this._readonly = e.readonly ?? !1, this.docModel = new it(e.initialDocument), this.selection = new ht(this.docModel), this.history = new pl(), this.commands = new yl(this.docModel, this.selection, this.history), this.input = new bl(this.commands, this.selection), (n = e.plugins) == null || n.forEach((l) => this.use(l));
|
|
2862
|
+
}
|
|
2863
|
+
// ─── 公共 API ─────────────────────────────────────────────────────────────
|
|
2864
|
+
/**
|
|
2865
|
+
* 执行命令(外部调用入口)
|
|
2866
|
+
* @example editor.exec('bold')
|
|
2867
|
+
* @example editor.exec('fontSize', 18)
|
|
2868
|
+
* @example editor.exec('insertText', 'hello')
|
|
2869
|
+
*/
|
|
2870
|
+
exec(e, n) {
|
|
2871
|
+
if (this._readonly && !this._isReadCommand(e)) {
|
|
2872
|
+
console.warn("[Editor] 只读模式,忽略写操作");
|
|
2873
|
+
return;
|
|
2874
|
+
}
|
|
2875
|
+
this.commands.exec(e, n);
|
|
2876
|
+
}
|
|
2877
|
+
/** 挂载输入层到指定 DOM 元素 */
|
|
2878
|
+
mount(e) {
|
|
2879
|
+
this._inputEl = e, this._readonly || this.input.attach(e);
|
|
2880
|
+
}
|
|
2881
|
+
/** 卸载输入层 */
|
|
2882
|
+
unmount() {
|
|
2883
|
+
this.input.detach(), this._inputEl = null;
|
|
2884
|
+
}
|
|
2885
|
+
/** 安装插件 */
|
|
2886
|
+
use(e) {
|
|
2887
|
+
return this._plugins.find((n) => n.name === e.name) ? (console.warn(`[Editor] 插件 ${e.name} 已安装`), this) : (e.install(this), this._plugins.push(e), this);
|
|
2888
|
+
}
|
|
2889
|
+
/** 获取序列化后的文档 JSON */
|
|
2890
|
+
getJSON() {
|
|
2891
|
+
return this.docModel.toJSON();
|
|
2892
|
+
}
|
|
2893
|
+
/** 从 JSON 加载文档(清空历史) */
|
|
2894
|
+
loadJSON(e) {
|
|
2895
|
+
const n = it.fromJSON(e);
|
|
2896
|
+
Object.assign(this.docModel.data, n.data), this.history.clear();
|
|
2897
|
+
}
|
|
2898
|
+
get isReadonly() {
|
|
2899
|
+
return this._readonly;
|
|
2900
|
+
}
|
|
2901
|
+
_isReadCommand(e) {
|
|
2902
|
+
return ["undo", "redo", "selectAll", "setSelection"].includes(e);
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
const Yt = Symbol("editor");
|
|
2906
|
+
function Il(t) {
|
|
2907
|
+
const e = new _l(t);
|
|
2908
|
+
return Kt(Yt, e), lt(() => {
|
|
2909
|
+
e.unmount();
|
|
2910
|
+
}), e;
|
|
2911
|
+
}
|
|
2912
|
+
function El() {
|
|
2913
|
+
const t = jt(Yt);
|
|
2914
|
+
if (!t)
|
|
2915
|
+
throw new Error("[useEditor] 必须在 EditorContainer 组件内使用");
|
|
2916
|
+
return t;
|
|
2917
|
+
}
|
|
2918
|
+
const xl = fl, Sl = {
|
|
2919
|
+
install(t) {
|
|
2920
|
+
t.component("EditorContainer", xl);
|
|
2921
|
+
}
|
|
2922
|
+
};
|
|
2923
|
+
export {
|
|
2924
|
+
_l as Editor,
|
|
2925
|
+
xl as EditorContainer,
|
|
2926
|
+
Yt as EditorKey,
|
|
2927
|
+
Il as createEditor,
|
|
2928
|
+
Sl as default,
|
|
2929
|
+
El as useEditor
|
|
2930
|
+
};
|