@eigenpal/docx-editor-vue 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,577 @@
1
+ import { computed as e, onBeforeUnmount as t, onMounted as n, ref as r, shallowRef as i, unref as a, watch as o } from "vue";
2
+ import { EditorState as s } from "prosemirror-state";
3
+ import { buildFootnoteContentMap as c, buildFootnoteRenderItems as l, collectFootnoteRefs as u, convertHeaderFooterPmDocToContent as d, convertHeaderFooterToContent as f, getMargins as p, getPageSize as m, measureTableBlock as h, resolveHeaderFooter as ee, stabilizeFootnoteLayout as te } from "@eigenpal/docx-editor-core/layout-bridge";
4
+ import { createEmptyDoc as ne, headerFooterToProseDoc as g, proseDocToBlocks as _, toProseDoc as re } from "@eigenpal/docx-editor-core/prosemirror/conversion";
5
+ import { schema as v } from "@eigenpal/docx-editor-core/prosemirror";
6
+ import { EditorView as y } from "prosemirror-view";
7
+ import { parseDocx as b } from "@eigenpal/docx-editor-core/docx/parser";
8
+ import { fromProseDoc as x } from "@eigenpal/docx-editor-core/prosemirror/conversion/fromProseDoc";
9
+ import { singletonManager as S } from "@eigenpal/docx-editor-core/prosemirror/schema";
10
+ import { createSuggestionModePlugin as C, setSuggestionMode as w } from "@eigenpal/docx-editor-core/prosemirror/plugins";
11
+ import { ExtensionManager as T, createStarterKit as E } from "@eigenpal/docx-editor-core/prosemirror/extensions";
12
+ import { toFlowBlocks as ie } from "@eigenpal/docx-editor-core/layout-bridge/toFlowBlocks";
13
+ import { measureBlocksWithFloats as D, measureParagraph as O } from "@eigenpal/docx-editor-core/layout-bridge/measuring";
14
+ import { DEFAULT_TEXTBOX_MARGINS as k, DEFAULT_TEXTBOX_WIDTH as A, assertExhaustiveFlowBlock as j, layoutDocument as ae } from "@eigenpal/docx-editor-core/layout-engine";
15
+ import { renderPages as oe } from "@eigenpal/docx-editor-core/layout-painter/renderPage";
16
+ import "prosemirror-view/style/prosemirror.css";
17
+ import "@eigenpal/docx-editor-core/prosemirror/editor.css";
18
+ //#region src/composables/useDocxEditor.ts
19
+ var M = 24;
20
+ function N(e, t, n, r) {
21
+ switch (e.kind) {
22
+ case "paragraph": return O(e, t, {
23
+ floatingZones: n,
24
+ paragraphYOffset: r ?? 0
25
+ });
26
+ case "table": return h(e, t, N);
27
+ case "image": {
28
+ let t = e;
29
+ return {
30
+ kind: "image",
31
+ width: t.width ?? 100,
32
+ height: t.height ?? 100
33
+ };
34
+ }
35
+ case "textBox": {
36
+ let t = e, n = t.margins ?? k, r = (t.width ?? A) - n.left - n.right, i = t.content.map((e) => O(e, r)), a = i.reduce((e, t) => e + t.totalHeight, 0), o = t.height ?? a + n.top + n.bottom;
37
+ return {
38
+ kind: "textBox",
39
+ width: t.width ?? A,
40
+ height: o,
41
+ innerMeasures: i
42
+ };
43
+ }
44
+ case "pageBreak": return { kind: "pageBreak" };
45
+ case "columnBreak": return { kind: "columnBreak" };
46
+ case "sectionBreak": return { kind: "sectionBreak" };
47
+ default: j(e, "vue useDocxEditor measureBlock");
48
+ }
49
+ }
50
+ function P(e, t) {
51
+ return D(e, t, N);
52
+ }
53
+ function F(e) {
54
+ let { hiddenContainer: n, pagesContainer: h, readOnly: D = !1, pageGap: O = M, onChange: k, onError: A, onSelectionUpdate: j, externalPlugins: N = [], syncCoordinator: F, editorMode: I, author: L } = e, R = i(null), z = i(null), B = i(null), V = r(!1), H = r(null), U = i(null), W = S;
55
+ function G(e) {
56
+ let t = h.value;
57
+ if (!t || !R.value) return;
58
+ let n = F?.getStateSeq() ?? 0;
59
+ F?.onLayoutStart();
60
+ let r = R.value.package?.document, i = r?.sections?.[0]?.properties ?? r?.finalSectionProperties ?? null, a = r?.finalSectionProperties ?? i, o = m(i), s = p(i), ne = m(a), g = p(a), _ = o.w - s.left - s.right, re = o.h - s.top - s.bottom, v = R.value.package?.theme ?? null, y = R.value.package?.styles ?? null;
61
+ try {
62
+ let n = ie(e.doc, {
63
+ theme: v,
64
+ pageContentHeight: re
65
+ }), r = P(n, _), { header: a, footer: p, firstHeader: m, firstFooter: h } = ee(R.value, i), b = {
66
+ section: "header",
67
+ pageSize: o,
68
+ margins: s
69
+ }, x = {
70
+ section: "footer",
71
+ pageSize: o,
72
+ margins: s
73
+ }, S = e.doc.attrs?.defaultTabStopTwips, C = {
74
+ styles: y,
75
+ theme: v,
76
+ measureBlocks: P,
77
+ defaultTabStopTwips: S
78
+ }, w = (e, t) => {
79
+ if (!e) return;
80
+ let n = ce(e);
81
+ return n ? d(n.state.doc, _, t, C) : f(e, _, t, C);
82
+ }, T = w(a, b), E = w(p, x), D = i?.titlePg === !0, k = D ? w(m, b) : void 0, A = D ? w(h, x) : void 0, j = s.header ?? 48, M = s.footer ?? 48, N = s.top - j, F = s.bottom - M, I = (e) => e ? e.visualBottom ?? e.height : 0, L = (e) => e ? Math.max((e.visualBottom ?? e.height) - (e.visualTop ?? 0), e.height) : 0, z = Math.max(I(T), I(k)), B = Math.max(L(E), L(A)), V = z > N, H = B > F;
83
+ if (V || H) {
84
+ let e = (e) => {
85
+ let t = { ...e };
86
+ return V && (t.top = Math.max(e.top, j + z)), H && (t.bottom = Math.max(e.bottom, M + B)), t;
87
+ };
88
+ s = e(s), g = e(g);
89
+ for (let t of n) {
90
+ if (t.kind !== "sectionBreak") continue;
91
+ let n = t;
92
+ n.margins &&= e(n.margins);
93
+ }
94
+ }
95
+ let W = {
96
+ pageSize: o,
97
+ margins: s,
98
+ finalPageSize: ne,
99
+ finalMargins: g,
100
+ pageGap: O
101
+ }, G = u(n), K = G.length > 0 && !!R.value.package?.footnotes, q = ae(n, r, W), J = /* @__PURE__ */ new Map(), Y = /* @__PURE__ */ new Map();
102
+ if (K) {
103
+ Y = c(R.value.package.footnotes, G, _, {
104
+ styles: y,
105
+ theme: v,
106
+ measureBlocks: P,
107
+ defaultTabStopTwips: S
108
+ });
109
+ let e = te({
110
+ blocks: n,
111
+ measures: r,
112
+ layoutOpts: W,
113
+ footnoteRefs: G,
114
+ footnoteContentMap: Y,
115
+ initialLayout: q
116
+ });
117
+ q = e.layout, J = e.pageFootnoteMap;
118
+ }
119
+ U.value = q;
120
+ let X = /* @__PURE__ */ new Map();
121
+ for (let e = 0; e < n.length; e++) {
122
+ let t = n[e], i = r[e];
123
+ t && i && X.set(String(t.id), {
124
+ block: t,
125
+ measure: i
126
+ });
127
+ }
128
+ let Z = K ? l(J, Y, R.value) : void 0;
129
+ oe(q.pages, t, {
130
+ pageGap: O,
131
+ showShadow: !0,
132
+ pageBackground: "#fff",
133
+ blockLookup: X,
134
+ theme: v,
135
+ headerContent: T,
136
+ footerContent: E,
137
+ firstPageHeaderContent: k,
138
+ firstPageFooterContent: A,
139
+ titlePage: D,
140
+ footnotesByPage: Z
141
+ }), t.style.overflowY = "auto", t.style.minHeight = "0";
142
+ for (let e of Array.from(t.children)) e.style.flexShrink = "0";
143
+ } catch (e) {
144
+ console.error("[useDocxEditor] Layout pipeline error:", e), A?.(e instanceof Error ? e : Error(String(e)));
145
+ } finally {
146
+ F?.onLayoutComplete(n);
147
+ }
148
+ }
149
+ function K() {
150
+ let e = n.value;
151
+ if (!e) return;
152
+ let t = R.value ? re(R.value, { styles: R.value.package?.styles ?? void 0 }) : ne(), r = [
153
+ C(!1),
154
+ ...N,
155
+ ...W.getPlugins() ?? []
156
+ ], i = s.create({
157
+ doc: t,
158
+ schema: W.getSchema(),
159
+ plugins: r
160
+ });
161
+ B.value = i;
162
+ let o = new y(e, {
163
+ state: i,
164
+ editable: () => !a(D),
165
+ dispatchTransaction(e) {
166
+ if (!o) return;
167
+ let t = o.state.apply(e);
168
+ if (o.updateState(t), B.value = t, e.docChanged) {
169
+ F?.incrementStateSeq(), G(t);
170
+ try {
171
+ if (R.value) {
172
+ let e = x(t.doc, R.value);
173
+ R.value = e, k?.(e);
174
+ }
175
+ } catch (e) {
176
+ console.error("[useDocxEditor] fromProseDoc error:", e);
177
+ }
178
+ }
179
+ F?.requestRender(), j?.();
180
+ }
181
+ });
182
+ z.value = o, V.value = !0, G(i), F?.requestRender();
183
+ }
184
+ o([
185
+ () => a(I),
186
+ () => a(L),
187
+ z
188
+ ], ([e, t, n]) => {
189
+ n && w(e === "suggesting", n.state, n.dispatch, t);
190
+ }, { immediate: !0 });
191
+ function q() {
192
+ z.value &&= (z.value.destroy(), null), B.value = null, V.value = !1;
193
+ }
194
+ let J = { current: null }, Y = /* @__PURE__ */ new Map(), X = /* @__PURE__ */ new Map();
195
+ function Z() {
196
+ if (J.current && J.current.isConnected) return J.current;
197
+ let e = window.document.createElement("div");
198
+ return e.dataset.hfHost = "true", e.style.cssText = "position: fixed; left: -9999px; top: 0; opacity: 0; z-index: -1; pointer-events: none;", window.document.body.appendChild(e), J.current = e, e;
199
+ }
200
+ function se(e) {
201
+ let t = R.value?.package;
202
+ if (!t) return null;
203
+ if (t.headers) {
204
+ for (let [n, r] of t.headers) if (r === e) return n;
205
+ }
206
+ if (t.footers) {
207
+ for (let [n, r] of t.footers) if (r === e) return n;
208
+ }
209
+ return null;
210
+ }
211
+ function ce(e) {
212
+ let t = se(e);
213
+ return t ? Y.get(t) ?? null : null;
214
+ }
215
+ function Q() {
216
+ let e = R.value?.package, t = Z(), n = /* @__PURE__ */ new Set();
217
+ if (e?.headers) for (let t of e.headers.keys()) n.add(t);
218
+ if (e?.footers) for (let t of e.footers.keys()) n.add(t);
219
+ for (let [e, t] of Y) n.has(e) || (t.destroy(), t.dom.parentElement?.remove(), X.get(e)?.destroy(), X.delete(e), Y.delete(e));
220
+ if (!e) return;
221
+ let r = e.styles ?? null, i = e.theme ?? null, a = e.settings?.defaultTabStop ?? null;
222
+ for (let o of n) {
223
+ if (Y.has(o)) continue;
224
+ let n = e.headers?.get(o) ?? e.footers?.get(o);
225
+ if (!n) continue;
226
+ let c = e.headers?.has(o) ? "header" : "footer", l = new T(E());
227
+ l.buildSchema(), l.initializeRuntime(), X.set(o, l);
228
+ let u = window.document.createElement("div");
229
+ u.dataset.hfRId = o, u.dataset.hfKind = c, t.appendChild(u);
230
+ let d = g(n.content, {
231
+ styles: r ?? void 0,
232
+ theme: i,
233
+ defaultTabStopTwips: a
234
+ }), f = s.create({
235
+ doc: d,
236
+ schema: v,
237
+ plugins: l.getPlugins()
238
+ }), p = c, m = new y(u, {
239
+ state: f,
240
+ dispatchTransaction(e) {
241
+ let t = m.state.apply(e);
242
+ if (m.updateState(t), e.docChanged) {
243
+ let e = R.value?.package, n = (p === "header" ? e?.headers : e?.footers)?.get(o);
244
+ n && (n.content = _(t.doc));
245
+ }
246
+ e.docChanged && B.value && G(B.value), le.value?.(o, m, e.docChanged);
247
+ }
248
+ });
249
+ Y.set(o, m);
250
+ }
251
+ }
252
+ function $() {
253
+ for (let e of Y.values()) e.destroy(), e.dom.parentElement?.remove();
254
+ Y.clear();
255
+ for (let e of X.values()) e.destroy();
256
+ X.clear(), J.current &&= (J.current.remove(), null);
257
+ }
258
+ let le = { value: null };
259
+ function ue(e) {
260
+ le.value = e;
261
+ }
262
+ async function de(e) {
263
+ H.value = null, V.value = !1;
264
+ try {
265
+ let t;
266
+ t = e instanceof Blob || e instanceof File ? await e.arrayBuffer() : e instanceof Uint8Array ? e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength) : e, R.value = await b(t), q(), $(), K(), Q();
267
+ } catch (e) {
268
+ let t = e instanceof Error ? e : Error(String(e));
269
+ H.value = t.message, A?.(t);
270
+ }
271
+ }
272
+ function fe(e) {
273
+ H.value = null, R.value = e, q(), $(), K(), Q();
274
+ }
275
+ async function pe() {
276
+ if (!z.value || !R.value) return null;
277
+ let { repackDocx: e, createDocx: t } = await import("@eigenpal/docx-editor-core/docx/rezip"), { injectReplyRangeMarkers: n, injectTCReplyRangeMarkers: r } = await import("@eigenpal/docx-editor-core/docx"), i = x(z.value.state.doc, R.value), a = i.package.document?.comments ?? [];
278
+ i.package.document?.content && a.length > 0 && (n(i.package.document.content, a), r(i.package.document.content, a));
279
+ let o;
280
+ return o = i.originalBuffer ? await e(i) : await t(i), new Blob([o], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
281
+ }
282
+ function me() {
283
+ z.value?.focus();
284
+ }
285
+ function he() {
286
+ q(), $(), R.value = null;
287
+ }
288
+ function ge() {
289
+ return R.value;
290
+ }
291
+ t(() => {
292
+ he();
293
+ });
294
+ function _e() {
295
+ return W.getCommands();
296
+ }
297
+ return {
298
+ editorView: z,
299
+ editorState: B,
300
+ isReady: V,
301
+ parseError: H,
302
+ layout: U,
303
+ loadBuffer: de,
304
+ loadDocument: fe,
305
+ save: pe,
306
+ focus: me,
307
+ destroy: he,
308
+ getDocument: ge,
309
+ getCommands: _e,
310
+ reLayout() {
311
+ z.value && G(z.value.state);
312
+ },
313
+ getHfPmView: ce,
314
+ syncHfPMs: Q,
315
+ setHfTransactionListener: ue,
316
+ setDocument(e) {
317
+ R.value = e;
318
+ }
319
+ };
320
+ }
321
+ //#endregion
322
+ //#region src/composables/useZoom.ts
323
+ var I = .25, L = 4, R = .1, z = [
324
+ .25,
325
+ .5,
326
+ .75,
327
+ 1,
328
+ 1.25,
329
+ 1.5,
330
+ 2,
331
+ 3,
332
+ 4
333
+ ];
334
+ function B(i = 1) {
335
+ let a = r(Math.max(I, Math.min(L, i))), o = e(() => Math.round(a.value * 100)), s = e(() => a.value <= I), c = e(() => a.value >= L);
336
+ function l(e) {
337
+ a.value = Math.max(I, Math.min(L, Math.round(e * 100) / 100));
338
+ }
339
+ function u() {
340
+ l(a.value + R);
341
+ }
342
+ function d() {
343
+ l(a.value - R);
344
+ }
345
+ function f() {
346
+ l(1);
347
+ }
348
+ function p(e) {
349
+ (e.ctrlKey || e.metaKey) && (e.preventDefault(), e.deltaY < 0 ? u() : d());
350
+ }
351
+ function m(e) {
352
+ (e.ctrlKey || e.metaKey) && (e.shiftKey || e.altKey || (e.key === "=" || e.key === "+" ? (e.preventDefault(), u()) : e.key === "-" ? (e.preventDefault(), d()) : e.key === "0" && (e.preventDefault(), f())));
353
+ }
354
+ function h() {
355
+ n(() => document.addEventListener("keydown", m)), t(() => document.removeEventListener("keydown", m));
356
+ }
357
+ return {
358
+ zoom: a,
359
+ zoomPercent: o,
360
+ isMinZoom: s,
361
+ isMaxZoom: c,
362
+ setZoom: l,
363
+ zoomIn: u,
364
+ zoomOut: d,
365
+ resetZoom: f,
366
+ handleWheel: p,
367
+ handleKeyDown: m,
368
+ installShortcuts: h,
369
+ ZOOM_PRESETS: z
370
+ };
371
+ }
372
+ //#endregion
373
+ //#region src/composables/useTableResize.ts
374
+ var V = 15, H = 300, U = 200, W = 15;
375
+ function G() {
376
+ let e = {
377
+ active: !1,
378
+ startX: 0,
379
+ handle: null,
380
+ columnIndex: 0,
381
+ tablePmStart: 0,
382
+ origWidths: {
383
+ left: 0,
384
+ right: 0
385
+ }
386
+ }, t = {
387
+ active: !1,
388
+ startY: 0,
389
+ handle: null,
390
+ rowIndex: 0,
391
+ isEdge: !1,
392
+ tablePmStart: 0,
393
+ origHeight: 0
394
+ }, n = {
395
+ active: !1,
396
+ startX: 0,
397
+ handle: null,
398
+ columnIndex: 0,
399
+ tablePmStart: 0,
400
+ origWidth: 0
401
+ }, r = null;
402
+ function i() {
403
+ return e.active || t.active || n.active;
404
+ }
405
+ function a(i, a) {
406
+ let o = i.target;
407
+ return o?.classList ? o.classList.contains("layout-table-resize-handle") ? (i.preventDefault(), i.stopPropagation(), r = a, e.active = !0, e.startX = i.clientX, e.handle = o, o.classList.add("dragging"), e.columnIndex = parseInt(o.dataset.columnIndex ?? "0", 10), e.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), K(a, e), !0) : o.classList.contains("layout-table-row-resize-handle") || o.classList.contains("layout-table-edge-handle-bottom") ? (i.preventDefault(), i.stopPropagation(), r = a, t.active = !0, t.startY = i.clientY, t.handle = o, t.isEdge = o.dataset.isEdge === "bottom", o.classList.add("dragging"), t.rowIndex = parseInt(o.dataset.rowIndex ?? "0", 10), t.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), q(a, t, o), !0) : o.classList.contains("layout-table-edge-handle-right") ? (i.preventDefault(), i.stopPropagation(), r = a, n.active = !0, n.startX = i.clientX, n.handle = o, o.classList.add("dragging"), n.columnIndex = parseInt(o.dataset.columnIndex ?? "0", 10), n.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), J(a, n), !0) : !1 : !1;
408
+ }
409
+ function o(r) {
410
+ if (e.active && e.handle) {
411
+ r.preventDefault();
412
+ let t = r.clientX - e.startX, n = parseFloat(e.handle.style.left);
413
+ e.handle.style.left = `${n + t}px`, e.startX = r.clientX;
414
+ let i = Math.round(t * V), a = e.origWidths.left + i, o = e.origWidths.right - i;
415
+ a >= H && o >= H && (e.origWidths = {
416
+ left: a,
417
+ right: o
418
+ });
419
+ return;
420
+ }
421
+ if (t.active && t.handle) {
422
+ r.preventDefault();
423
+ let e = r.clientY - t.startY, n = parseFloat(t.handle.style.top);
424
+ t.handle.style.top = `${n + e}px`, t.startY = r.clientY;
425
+ let i = Math.round(e * V), a = t.origHeight + i;
426
+ a >= U && (t.origHeight = a);
427
+ return;
428
+ }
429
+ if (n.active && n.handle) {
430
+ r.preventDefault();
431
+ let e = r.clientX - n.startX, t = parseFloat(n.handle.style.left);
432
+ n.handle.style.left = `${t + e}px`, n.startX = r.clientX;
433
+ let i = Math.round(e * V), a = n.origWidth + i;
434
+ a >= H && (n.origWidth = a);
435
+ }
436
+ }
437
+ function s(i) {
438
+ if (e.active) {
439
+ e.active = !1, e.handle?.classList.remove("dragging"), r && Y(r, e), e.handle = null;
440
+ return;
441
+ }
442
+ if (t.active) {
443
+ t.active = !1, t.handle?.classList.remove("dragging"), r && X(r, t), t.handle = null;
444
+ return;
445
+ }
446
+ n.active && (n.active = !1, n.handle?.classList.remove("dragging"), r && Z(r, n), n.handle = null);
447
+ }
448
+ function c() {
449
+ return document.addEventListener("mousemove", o), document.addEventListener("mouseup", s), () => {
450
+ document.removeEventListener("mousemove", o), document.removeEventListener("mouseup", s);
451
+ };
452
+ }
453
+ return {
454
+ tryStartResize: a,
455
+ install: c,
456
+ isResizing: i
457
+ };
458
+ }
459
+ function K(e, t) {
460
+ let n = e.state.doc.resolve(t.tablePmStart + 1);
461
+ for (let e = n.depth; e >= 0; e--) {
462
+ let r = n.node(e);
463
+ if (r.type.name === "table") {
464
+ let e = r.attrs.columnWidths;
465
+ e && e[t.columnIndex] !== void 0 && e[t.columnIndex + 1] !== void 0 && (t.origWidths = {
466
+ left: e[t.columnIndex],
467
+ right: e[t.columnIndex + 1]
468
+ });
469
+ return;
470
+ }
471
+ }
472
+ }
473
+ function q(e, t, n) {
474
+ let r = e.state.doc.resolve(t.tablePmStart + 1);
475
+ for (let e = r.depth; e >= 0; e--) {
476
+ let i = r.node(e);
477
+ if (i.type.name === "table") {
478
+ let e = null, r = 0;
479
+ if (i.forEach((n) => {
480
+ r === t.rowIndex && (e = n), r++;
481
+ }), e) {
482
+ let r = e.attrs.height;
483
+ if (r) t.origHeight = r;
484
+ else {
485
+ let e = n.closest(".layout-table")?.querySelector(`[data-row-index="${t.rowIndex}"]`), r = e ? e.getBoundingClientRect().height : 30;
486
+ t.origHeight = Math.round(r * W);
487
+ }
488
+ }
489
+ return;
490
+ }
491
+ }
492
+ }
493
+ function J(e, t) {
494
+ let n = e.state.doc.resolve(t.tablePmStart + 1);
495
+ for (let e = n.depth; e >= 0; e--) {
496
+ let r = n.node(e);
497
+ if (r.type.name === "table") {
498
+ let e = r.attrs.columnWidths;
499
+ e && e[t.columnIndex] !== void 0 && (t.origWidth = e[t.columnIndex]);
500
+ return;
501
+ }
502
+ }
503
+ }
504
+ function Y(e, t) {
505
+ let n = e.state.doc.resolve(t.tablePmStart + 1);
506
+ for (let r = n.depth; r >= 0; r--) {
507
+ let i = n.node(r);
508
+ if (i.type.name !== "table") continue;
509
+ let a = n.before(r), o = e.state.tr, s = [...i.attrs.columnWidths || []];
510
+ s[t.columnIndex] = t.origWidths.left, s[t.columnIndex + 1] = t.origWidths.right, o.setNodeMarkup(a, void 0, {
511
+ ...i.attrs,
512
+ columnWidths: s
513
+ });
514
+ let c = a + 1;
515
+ i.forEach((e) => {
516
+ let n = c + 1, r = 0;
517
+ e.forEach((e) => {
518
+ let i = e.attrs.colspan || 1;
519
+ if (r === t.columnIndex || r === t.columnIndex + 1) {
520
+ let i = r === t.columnIndex ? t.origWidths.left : t.origWidths.right;
521
+ o.setNodeMarkup(o.mapping.map(n), void 0, {
522
+ ...e.attrs,
523
+ width: i,
524
+ widthType: "dxa",
525
+ colwidth: null
526
+ });
527
+ }
528
+ n += e.nodeSize, r += i;
529
+ }), c += e.nodeSize;
530
+ }), e.dispatch(o);
531
+ return;
532
+ }
533
+ }
534
+ function X(e, t) {
535
+ let n = e.state.doc.resolve(t.tablePmStart + 1);
536
+ for (let r = n.depth; r >= 0; r--) {
537
+ let i = n.node(r);
538
+ if (i.type.name !== "table") continue;
539
+ let a = n.before(r), o = e.state.tr, s = a + 1, c = 0;
540
+ i.forEach((e) => {
541
+ c === t.rowIndex && o.setNodeMarkup(o.mapping.map(s), void 0, {
542
+ ...e.attrs,
543
+ height: t.origHeight,
544
+ heightRule: "atLeast"
545
+ }), s += e.nodeSize, c++;
546
+ }), e.dispatch(o);
547
+ return;
548
+ }
549
+ }
550
+ function Z(e, t) {
551
+ let n = e.state.doc.resolve(t.tablePmStart + 1);
552
+ for (let r = n.depth; r >= 0; r--) {
553
+ let i = n.node(r);
554
+ if (i.type.name !== "table") continue;
555
+ let a = n.before(r), o = e.state.tr, s = [...i.attrs.columnWidths || []];
556
+ s[t.columnIndex] = t.origWidth, o.setNodeMarkup(a, void 0, {
557
+ ...i.attrs,
558
+ columnWidths: s
559
+ });
560
+ let c = a + 1;
561
+ i.forEach((e) => {
562
+ let n = c + 1, r = 0;
563
+ e.forEach((e) => {
564
+ let i = e.attrs.colspan || 1;
565
+ r === t.columnIndex && o.setNodeMarkup(o.mapping.map(n), void 0, {
566
+ ...e.attrs,
567
+ width: t.origWidth,
568
+ widthType: "dxa",
569
+ colwidth: null
570
+ }), n += e.nodeSize, r += i;
571
+ }), c += e.nodeSize;
572
+ }), e.dispatch(o);
573
+ return;
574
+ }
575
+ }
576
+ //#endregion
577
+ export { B as n, F as r, G as t };
@@ -0,0 +1 @@
1
+ let e=require(`vue`),t=require(`prosemirror-state`),n=require(`@eigenpal/docx-editor-core/layout-bridge`),r=require(`@eigenpal/docx-editor-core/prosemirror/conversion`),i=require(`@eigenpal/docx-editor-core/prosemirror`),a=require(`prosemirror-view`),o=require(`@eigenpal/docx-editor-core/docx/parser`),s=require(`@eigenpal/docx-editor-core/prosemirror/conversion/fromProseDoc`),c=require(`@eigenpal/docx-editor-core/prosemirror/schema`),l=require(`@eigenpal/docx-editor-core/prosemirror/plugins`),u=require(`@eigenpal/docx-editor-core/prosemirror/extensions`),d=require(`@eigenpal/docx-editor-core/layout-bridge/toFlowBlocks`),f=require(`@eigenpal/docx-editor-core/layout-bridge/measuring`),p=require(`@eigenpal/docx-editor-core/layout-engine`),m=require(`@eigenpal/docx-editor-core/layout-painter/renderPage`);require(`prosemirror-view/style/prosemirror.css`),require(`@eigenpal/docx-editor-core/prosemirror/editor.css`);var h=24;function g(e,t,r,i){switch(e.kind){case`paragraph`:return(0,f.measureParagraph)(e,t,{floatingZones:r,paragraphYOffset:i??0});case`table`:return(0,n.measureTableBlock)(e,t,g);case`image`:{let t=e;return{kind:`image`,width:t.width??100,height:t.height??100}}case`textBox`:{let t=e,n=t.margins??p.DEFAULT_TEXTBOX_MARGINS,r=(t.width??p.DEFAULT_TEXTBOX_WIDTH)-n.left-n.right,i=t.content.map(e=>(0,f.measureParagraph)(e,r)),a=i.reduce((e,t)=>e+t.totalHeight,0),o=t.height??a+n.top+n.bottom;return{kind:`textBox`,width:t.width??p.DEFAULT_TEXTBOX_WIDTH,height:o,innerMeasures:i}}case`pageBreak`:return{kind:`pageBreak`};case`columnBreak`:return{kind:`columnBreak`};case`sectionBreak`:return{kind:`sectionBreak`};default:(0,p.assertExhaustiveFlowBlock)(e,`vue useDocxEditor measureBlock`)}}function _(e,t){return(0,f.measureBlocksWithFloats)(e,t,g)}function v(f){let{hiddenContainer:g,pagesContainer:v,readOnly:y=!1,pageGap:b=h,onChange:x,onError:S,onSelectionUpdate:C,externalPlugins:w=[],syncCoordinator:T,editorMode:E,author:D}=f,O=(0,e.shallowRef)(null),k=(0,e.shallowRef)(null),A=(0,e.shallowRef)(null),j=(0,e.ref)(!1),M=(0,e.ref)(null),N=(0,e.shallowRef)(null),P=c.singletonManager;function F(e){let t=v.value;if(!t||!O.value)return;let r=T?.getStateSeq()??0;T?.onLayoutStart();let i=O.value.package?.document,a=i?.sections?.[0]?.properties??i?.finalSectionProperties??null,o=i?.finalSectionProperties??a,s=(0,n.getPageSize)(a),c=(0,n.getMargins)(a),l=(0,n.getPageSize)(o),u=(0,n.getMargins)(o),f=s.w-c.left-c.right,h=s.h-c.top-c.bottom,g=O.value.package?.theme??null,y=O.value.package?.styles??null;try{let r=(0,d.toFlowBlocks)(e.doc,{theme:g,pageContentHeight:h}),i=_(r,f),{header:o,footer:v,firstHeader:x,firstFooter:S}=(0,n.resolveHeaderFooter)(O.value,a),C={section:`header`,pageSize:s,margins:c},w={section:`footer`,pageSize:s,margins:c},T=e.doc.attrs?.defaultTabStopTwips,E={styles:y,theme:g,measureBlocks:_,defaultTabStopTwips:T},D=(e,t)=>{if(!e)return;let r=U(e);return r?(0,n.convertHeaderFooterPmDocToContent)(r.state.doc,f,t,E):(0,n.convertHeaderFooterToContent)(e,f,t,E)},k=D(o,C),A=D(v,w),j=a?.titlePg===!0,M=j?D(x,C):void 0,P=j?D(S,w):void 0,F=c.header??48,I=c.footer??48,L=c.top-F,R=c.bottom-I,z=e=>e?e.visualBottom??e.height:0,B=e=>e?Math.max((e.visualBottom??e.height)-(e.visualTop??0),e.height):0,V=Math.max(z(k),z(M)),H=Math.max(B(A),B(P)),W=V>L,G=H>R;if(W||G){let e=e=>{let t={...e};return W&&(t.top=Math.max(e.top,F+V)),G&&(t.bottom=Math.max(e.bottom,I+H)),t};c=e(c),u=e(u);for(let t of r){if(t.kind!==`sectionBreak`)continue;let n=t;n.margins&&=e(n.margins)}}let K={pageSize:s,margins:c,finalPageSize:l,finalMargins:u,pageGap:b},q=(0,n.collectFootnoteRefs)(r),J=q.length>0&&!!O.value.package?.footnotes,Y=(0,p.layoutDocument)(r,i,K),X=new Map,Z=new Map;if(J){Z=(0,n.buildFootnoteContentMap)(O.value.package.footnotes,q,f,{styles:y,theme:g,measureBlocks:_,defaultTabStopTwips:T});let e=(0,n.stabilizeFootnoteLayout)({blocks:r,measures:i,layoutOpts:K,footnoteRefs:q,footnoteContentMap:Z,initialLayout:Y});Y=e.layout,X=e.pageFootnoteMap}N.value=Y;let Q=new Map;for(let e=0;e<r.length;e++){let t=r[e],n=i[e];t&&n&&Q.set(String(t.id),{block:t,measure:n})}let $=J?(0,n.buildFootnoteRenderItems)(X,Z,O.value):void 0;(0,m.renderPages)(Y.pages,t,{pageGap:b,showShadow:!0,pageBackground:`#fff`,blockLookup:Q,theme:g,headerContent:k,footerContent:A,firstPageHeaderContent:M,firstPageFooterContent:P,titlePage:j,footnotesByPage:$}),t.style.overflowY=`auto`,t.style.minHeight=`0`;for(let e of Array.from(t.children))e.style.flexShrink=`0`}catch(e){console.error(`[useDocxEditor] Layout pipeline error:`,e),S?.(e instanceof Error?e:Error(String(e)))}finally{T?.onLayoutComplete(r)}}function I(){let n=g.value;if(!n)return;let i=O.value?(0,r.toProseDoc)(O.value,{styles:O.value.package?.styles??void 0}):(0,r.createEmptyDoc)(),o=[(0,l.createSuggestionModePlugin)(!1),...w,...P.getPlugins()??[]],c=t.EditorState.create({doc:i,schema:P.getSchema(),plugins:o});A.value=c;let u=new a.EditorView(n,{state:c,editable:()=>!(0,e.unref)(y),dispatchTransaction(e){if(!u)return;let t=u.state.apply(e);if(u.updateState(t),A.value=t,e.docChanged){T?.incrementStateSeq(),F(t);try{if(O.value){let e=(0,s.fromProseDoc)(t.doc,O.value);O.value=e,x?.(e)}}catch(e){console.error(`[useDocxEditor] fromProseDoc error:`,e)}}T?.requestRender(),C?.()}});k.value=u,j.value=!0,F(c),T?.requestRender()}(0,e.watch)([()=>(0,e.unref)(E),()=>(0,e.unref)(D),k],([e,t,n])=>{n&&(0,l.setSuggestionMode)(e===`suggesting`,n.state,n.dispatch,t)},{immediate:!0});function L(){k.value&&=(k.value.destroy(),null),A.value=null,j.value=!1}let R={current:null},z=new Map,B=new Map;function V(){if(R.current&&R.current.isConnected)return R.current;let e=window.document.createElement(`div`);return e.dataset.hfHost=`true`,e.style.cssText=`position: fixed; left: -9999px; top: 0; opacity: 0; z-index: -1; pointer-events: none;`,window.document.body.appendChild(e),R.current=e,e}function H(e){let t=O.value?.package;if(!t)return null;if(t.headers){for(let[n,r]of t.headers)if(r===e)return n}if(t.footers){for(let[n,r]of t.footers)if(r===e)return n}return null}function U(e){let t=H(e);return t?z.get(t)??null:null}function W(){let e=O.value?.package,n=V(),o=new Set;if(e?.headers)for(let t of e.headers.keys())o.add(t);if(e?.footers)for(let t of e.footers.keys())o.add(t);for(let[e,t]of z)o.has(e)||(t.destroy(),t.dom.parentElement?.remove(),B.get(e)?.destroy(),B.delete(e),z.delete(e));if(!e)return;let s=e.styles??null,c=e.theme??null,l=e.settings?.defaultTabStop??null;for(let d of o){if(z.has(d))continue;let o=e.headers?.get(d)??e.footers?.get(d);if(!o)continue;let f=e.headers?.has(d)?`header`:`footer`,p=new u.ExtensionManager((0,u.createStarterKit)());p.buildSchema(),p.initializeRuntime(),B.set(d,p);let m=window.document.createElement(`div`);m.dataset.hfRId=d,m.dataset.hfKind=f,n.appendChild(m);let h=(0,r.headerFooterToProseDoc)(o.content,{styles:s??void 0,theme:c,defaultTabStopTwips:l}),g=t.EditorState.create({doc:h,schema:i.schema,plugins:p.getPlugins()}),_=f,v=new a.EditorView(m,{state:g,dispatchTransaction(e){let t=v.state.apply(e);if(v.updateState(t),e.docChanged){let e=O.value?.package,n=(_===`header`?e?.headers:e?.footers)?.get(d);n&&(n.content=(0,r.proseDocToBlocks)(t.doc))}e.docChanged&&A.value&&F(A.value),K.value?.(d,v,e.docChanged)}});z.set(d,v)}}function G(){for(let e of z.values())e.destroy(),e.dom.parentElement?.remove();z.clear();for(let e of B.values())e.destroy();B.clear(),R.current&&=(R.current.remove(),null)}let K={value:null};function q(e){K.value=e}async function J(e){M.value=null,j.value=!1;try{let t;t=e instanceof Blob||e instanceof File?await e.arrayBuffer():e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,O.value=await(0,o.parseDocx)(t),L(),G(),I(),W()}catch(e){let t=e instanceof Error?e:Error(String(e));M.value=t.message,S?.(t)}}function Y(e){M.value=null,O.value=e,L(),G(),I(),W()}async function X(){if(!k.value||!O.value)return null;let{repackDocx:e,createDocx:t}=await import(`@eigenpal/docx-editor-core/docx/rezip`),{injectReplyRangeMarkers:n,injectTCReplyRangeMarkers:r}=await import(`@eigenpal/docx-editor-core/docx`),i=(0,s.fromProseDoc)(k.value.state.doc,O.value),a=i.package.document?.comments??[];i.package.document?.content&&a.length>0&&(n(i.package.document.content,a),r(i.package.document.content,a));let o;return o=i.originalBuffer?await e(i):await t(i),new Blob([o],{type:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`})}function Z(){k.value?.focus()}function Q(){L(),G(),O.value=null}function $(){return O.value}(0,e.onBeforeUnmount)(()=>{Q()});function ee(){return P.getCommands()}return{editorView:k,editorState:A,isReady:j,parseError:M,layout:N,loadBuffer:J,loadDocument:Y,save:X,focus:Z,destroy:Q,getDocument:$,getCommands:ee,reLayout(){k.value&&F(k.value.state)},getHfPmView:U,syncHfPMs:W,setHfTransactionListener:q,setDocument(e){O.value=e}}}var y=.25,b=4,x=.1,S=[.25,.5,.75,1,1.25,1.5,2,3,4];function C(t=1){let n=(0,e.ref)(Math.max(y,Math.min(b,t))),r=(0,e.computed)(()=>Math.round(n.value*100)),i=(0,e.computed)(()=>n.value<=y),a=(0,e.computed)(()=>n.value>=b);function o(e){n.value=Math.max(y,Math.min(b,Math.round(e*100)/100))}function s(){o(n.value+x)}function c(){o(n.value-x)}function l(){o(1)}function u(e){(e.ctrlKey||e.metaKey)&&(e.preventDefault(),e.deltaY<0?s():c())}function d(e){(e.ctrlKey||e.metaKey)&&(e.shiftKey||e.altKey||(e.key===`=`||e.key===`+`?(e.preventDefault(),s()):e.key===`-`?(e.preventDefault(),c()):e.key===`0`&&(e.preventDefault(),l())))}function f(){(0,e.onMounted)(()=>document.addEventListener(`keydown`,d)),(0,e.onBeforeUnmount)(()=>document.removeEventListener(`keydown`,d))}return{zoom:n,zoomPercent:r,isMinZoom:i,isMaxZoom:a,setZoom:o,zoomIn:s,zoomOut:c,resetZoom:l,handleWheel:u,handleKeyDown:d,installShortcuts:f,ZOOM_PRESETS:S}}var w=15,T=300,E=200,D=15;function O(){let e={active:!1,startX:0,handle:null,columnIndex:0,tablePmStart:0,origWidths:{left:0,right:0}},t={active:!1,startY:0,handle:null,rowIndex:0,isEdge:!1,tablePmStart:0,origHeight:0},n={active:!1,startX:0,handle:null,columnIndex:0,tablePmStart:0,origWidth:0},r=null;function i(){return e.active||t.active||n.active}function a(i,a){let o=i.target;return o?.classList?o.classList.contains(`layout-table-resize-handle`)?(i.preventDefault(),i.stopPropagation(),r=a,e.active=!0,e.startX=i.clientX,e.handle=o,o.classList.add(`dragging`),e.columnIndex=parseInt(o.dataset.columnIndex??`0`,10),e.tablePmStart=parseInt(o.dataset.tablePmStart??`0`,10),k(a,e),!0):o.classList.contains(`layout-table-row-resize-handle`)||o.classList.contains(`layout-table-edge-handle-bottom`)?(i.preventDefault(),i.stopPropagation(),r=a,t.active=!0,t.startY=i.clientY,t.handle=o,t.isEdge=o.dataset.isEdge===`bottom`,o.classList.add(`dragging`),t.rowIndex=parseInt(o.dataset.rowIndex??`0`,10),t.tablePmStart=parseInt(o.dataset.tablePmStart??`0`,10),A(a,t,o),!0):o.classList.contains(`layout-table-edge-handle-right`)?(i.preventDefault(),i.stopPropagation(),r=a,n.active=!0,n.startX=i.clientX,n.handle=o,o.classList.add(`dragging`),n.columnIndex=parseInt(o.dataset.columnIndex??`0`,10),n.tablePmStart=parseInt(o.dataset.tablePmStart??`0`,10),j(a,n),!0):!1:!1}function o(r){if(e.active&&e.handle){r.preventDefault();let t=r.clientX-e.startX,n=parseFloat(e.handle.style.left);e.handle.style.left=`${n+t}px`,e.startX=r.clientX;let i=Math.round(t*w),a=e.origWidths.left+i,o=e.origWidths.right-i;a>=T&&o>=T&&(e.origWidths={left:a,right:o});return}if(t.active&&t.handle){r.preventDefault();let e=r.clientY-t.startY,n=parseFloat(t.handle.style.top);t.handle.style.top=`${n+e}px`,t.startY=r.clientY;let i=Math.round(e*w),a=t.origHeight+i;a>=E&&(t.origHeight=a);return}if(n.active&&n.handle){r.preventDefault();let e=r.clientX-n.startX,t=parseFloat(n.handle.style.left);n.handle.style.left=`${t+e}px`,n.startX=r.clientX;let i=Math.round(e*w),a=n.origWidth+i;a>=T&&(n.origWidth=a)}}function s(i){if(e.active){e.active=!1,e.handle?.classList.remove(`dragging`),r&&M(r,e),e.handle=null;return}if(t.active){t.active=!1,t.handle?.classList.remove(`dragging`),r&&N(r,t),t.handle=null;return}n.active&&(n.active=!1,n.handle?.classList.remove(`dragging`),r&&P(r,n),n.handle=null)}function c(){return document.addEventListener(`mousemove`,o),document.addEventListener(`mouseup`,s),()=>{document.removeEventListener(`mousemove`,o),document.removeEventListener(`mouseup`,s)}}return{tryStartResize:a,install:c,isResizing:i}}function k(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let e=n.depth;e>=0;e--){let r=n.node(e);if(r.type.name===`table`){let e=r.attrs.columnWidths;e&&e[t.columnIndex]!==void 0&&e[t.columnIndex+1]!==void 0&&(t.origWidths={left:e[t.columnIndex],right:e[t.columnIndex+1]});return}}}function A(e,t,n){let r=e.state.doc.resolve(t.tablePmStart+1);for(let e=r.depth;e>=0;e--){let i=r.node(e);if(i.type.name===`table`){let e=null,r=0;if(i.forEach(n=>{r===t.rowIndex&&(e=n),r++}),e){let r=e.attrs.height;if(r)t.origHeight=r;else{let e=n.closest(`.layout-table`)?.querySelector(`[data-row-index="${t.rowIndex}"]`),r=e?e.getBoundingClientRect().height:30;t.origHeight=Math.round(r*D)}}return}}}function j(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let e=n.depth;e>=0;e--){let r=n.node(e);if(r.type.name===`table`){let e=r.attrs.columnWidths;e&&e[t.columnIndex]!==void 0&&(t.origWidth=e[t.columnIndex]);return}}}function M(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=[...i.attrs.columnWidths||[]];s[t.columnIndex]=t.origWidths.left,s[t.columnIndex+1]=t.origWidths.right,o.setNodeMarkup(a,void 0,{...i.attrs,columnWidths:s});let c=a+1;i.forEach(e=>{let n=c+1,r=0;e.forEach(e=>{let i=e.attrs.colspan||1;if(r===t.columnIndex||r===t.columnIndex+1){let i=r===t.columnIndex?t.origWidths.left:t.origWidths.right;o.setNodeMarkup(o.mapping.map(n),void 0,{...e.attrs,width:i,widthType:`dxa`,colwidth:null})}n+=e.nodeSize,r+=i}),c+=e.nodeSize}),e.dispatch(o);return}}function N(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=a+1,c=0;i.forEach(e=>{c===t.rowIndex&&o.setNodeMarkup(o.mapping.map(s),void 0,{...e.attrs,height:t.origHeight,heightRule:`atLeast`}),s+=e.nodeSize,c++}),e.dispatch(o);return}}function P(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=[...i.attrs.columnWidths||[]];s[t.columnIndex]=t.origWidth,o.setNodeMarkup(a,void 0,{...i.attrs,columnWidths:s});let c=a+1;i.forEach(e=>{let n=c+1,r=0;e.forEach(e=>{let i=e.attrs.colspan||1;r===t.columnIndex&&o.setNodeMarkup(o.mapping.map(n),void 0,{...e.attrs,width:t.origWidth,widthType:`dxa`,colwidth:null}),n+=e.nodeSize,r+=i}),c+=e.nodeSize}),e.dispatch(o);return}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return O}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eigenpal/docx-editor-vue",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "Vue 3 DOCX editor adapter for @eigenpal/docx-editor-core.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -83,9 +83,9 @@
83
83
  "vue": "^3.3.0"
84
84
  },
85
85
  "dependencies": {
86
- "@eigenpal/docx-editor-agents": "^1.0.3",
87
- "@eigenpal/docx-editor-core": "^1.0.3",
88
- "@eigenpal/docx-editor-i18n": "^1.0.3"
86
+ "@eigenpal/docx-editor-agents": "^1.1.0",
87
+ "@eigenpal/docx-editor-core": "^1.1.0",
88
+ "@eigenpal/docx-editor-i18n": "^1.1.0"
89
89
  },
90
90
  "keywords": [
91
91
  "docx",