@stll/folio-vue 0.27.0 → 0.28.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.
@@ -1,991 +0,0 @@
1
- import { computed as e, inject as t, onBeforeUnmount as n, onMounted as r, onScopeDispose as i, provide as a, reactive as o, ref as s, shallowRef as c, toValue as l, watch as u, watchEffect as d } from "vue";
2
- import { CanonicalSessionRefusalError as f, collectRemoteSelections as p, createHiddenEditorManager as m, createHiddenEditorState as h } from "@stll/folio-core/controller/hiddenEditorManager";
3
- import { cloneDocumentWithParagraphPropertySources as g } from "@stll/folio-core/docx/document-clone";
4
- import { getEditorReadOnlyReason as ee } from "@stll/folio-core/managers/EditorModeManager";
5
- import { getEditorScrollRoot as _, scrollEditorBy as v } from "@stll/folio-core/paged-layout/editorScrollRoot";
6
- import { getMargins as te, getPageSize as y, twipsToPixels as b } from "@stll/folio-core/paged-layout/sectionGeometry";
7
- import { CANONICAL_GAP as x, canonicalRefusalMessage as ne, usesCanonicalSession as re } from "@stll/folio-core/types/canonicalCapabilities";
8
- import { createSuggestionModePlugin as ie, setSuggestionMode as S } from "@stll/folio-core/prosemirror/plugins/suggestionMode";
9
- import { loadCollaborationModules as ae } from "@stll/folio-core/controller/collaborationModules";
10
- import { FOLIO_DOCX_SERIALIZATION_MODE as C, createFolioEditor as oe } from "@stll/folio-core/controller/folioEditor";
11
- import { createFolioEditorEmitter as se } from "@stll/folio-core/controller/folioEditorEvents";
12
- import { readFontSetSignature as ce, waitForInitialLayoutFonts as w, watchLayoutFontLoads as le } from "@stll/folio-core/controller/fontReadiness";
13
- import { createHeaderFooterEditorManager as ue } from "@stll/folio-core/controller/headerFooterEditorManager";
14
- import { createHyphenationReadiness as de } from "@stll/folio-core/controller/hyphenationReadiness";
15
- import { runLayoutPipeline as fe } from "@stll/folio-core/controller/layoutPipeline";
16
- import { TRANSACTION_LAYOUT_TIMING as T, browserClock as pe, createLayoutScheduler as me } from "@stll/folio-core/controller/layoutScheduler";
17
- import { createLayoutSession as he } from "@stll/folio-core/controller/layoutSession";
18
- import { createNoteEditorManager as ge } from "@stll/folio-core/controller/noteEditorManager";
19
- import { CanonicalSaveDiagnosticError as _e, serializeCanonicalSave as ve } from "@stll/folio-core/docx/canonicalSave";
20
- import { prepareCanonicalDocxInput as ye } from "@stll/folio-core/docx/canonicalSessionInput";
21
- import { parseDocx as be } from "@stll/folio-core/docx/parser";
22
- import { getFootnoteText as xe } from "@stll/folio-core/docx/storyPlainText";
23
- import { convertHeaderFooterPmDocToContent as Se, convertHeaderFooterToContent as Ce } from "@stll/folio-core/layout-bridge/convert/headerFooterLayout";
24
- import { resolveSectionHeaderFooterRefs as we } from "@stll/folio-core/layout-engine";
25
- import { LayoutPainter as Te, releaseDisplayPageResources as Ee } from "@stll/folio-core/layout-painter";
26
- import { LayoutSelectionGate as De } from "@stll/folio-core/paged-layout/LayoutSelectionGate";
27
- import { fromProseDoc as Oe } from "@stll/folio-core/prosemirror/conversion/fromProseDoc";
28
- import { ExtensionManager as ke } from "@stll/folio-core/prosemirror/extensions/ExtensionManager";
29
- import { getChangedParagraphIds as Ae, hasStructuralChanges as je, hasUntrackedChanges as Me, repackWithEditorSectionRemovals as Ne } from "@stll/folio-core/prosemirror/extensions/features/ParagraphChangeTrackerExtension";
30
- import { createStarterKit as Pe } from "@stll/folio-core/prosemirror/extensions/StarterKit";
31
- import { createNoteReferenceFollower as Fe, withoutUnreferencedNotes as Ie } from "@stll/folio-core/prosemirror/noteReferenceReview";
32
- import { createAnonymizationDecorationsPlugin as Le } from "@stll/folio-core/prosemirror/plugins/anonymizationDecorations";
33
- import { autocompleteSuggestionPlugin as Re } from "@stll/folio-core/prosemirror/plugins/autocompleteSuggestion";
34
- import { createTemplateDirectivesPlugin as ze } from "@stll/folio-core/prosemirror/plugins/templateDirectives";
35
- import { createTemplatePreviewValuesPlugin as Be } from "@stll/folio-core/prosemirror/plugins/templatePreviewValues";
36
- import { templateSlashMenuPlugin as Ve } from "@stll/folio-core/prosemirror/plugins/templateSlashMenu";
37
- import { resolveHeaderFooterContent as He } from "@stll/folio-core/utils/headerFooter";
38
- import { FindReplaceManager as Ue } from "@stll/folio-core/managers/FindReplaceManager";
39
- import { findInDisplayedDocument as We, resolveFindMatchRange as Ge } from "@stll/folio-core/prosemirror/findReplaceSelection";
40
- import { createFindMatchView as Ke, getRenderedSearchStories as qe } from "@stll/folio-core/utils/findMatchView";
41
- import { createDefaultFindOptions as E, replaceEligibility as Je } from "@stll/folio-core/utils/findReplace";
42
- import { createFindSearchKey as Ye, sameFindSearchKey as Xe } from "@stll/folio-core/utils/findSearchKey";
43
- import { MIN_CELL_WIDTH_TWIPS as Ze, MIN_ROW_HEIGHT_TWIPS as Qe, TWIPS_PER_PIXEL as D, clampRowResizeDelta as $e, commitColumnResize as et, commitRightEdgeResize as tt, commitRowResize as nt, readColumnWidthAt as rt, readColumnWidths as it, readRowHeight as at } from "@stll/folio-core/prosemirror/tableResize";
44
- import { extractTrackedChanges as ot } from "@stll/folio-core/prosemirror/utils/extractTrackedChanges";
45
- import { ZOOM_MAX as st, ZOOM_MIN as ct, ZOOM_STEP as O } from "@stll/folio-core/utils/zoom";
46
- // src/utils/colorMode.ts
47
- var k = "(prefers-color-scheme: dark)";
48
- function lt() {
49
- return typeof window < "u" && typeof window.matchMedia == "function";
50
- }
51
- function A(e, t) {
52
- return e === "dark" || e === "system" && t;
53
- }
54
- function j(e) {
55
- if (!lt()) return () => {};
56
- let t = window.matchMedia(k);
57
- e(t.matches);
58
- let n = (t) => e(t.matches);
59
- return t.addEventListener("change", n), () => t.removeEventListener("change", n);
60
- }
61
- // src/composables/useColorMode.ts
62
- var M = "light", N = Symbol("folioColorMode"), P = (t = M) => {
63
- a(N, e(() => l(t)));
64
- }, F = { install(t, n = M) {
65
- t.provide(N, e(() => l(n)));
66
- } };
67
- function ut() {
68
- let n = t(N, e(() => M)), i = s(!1), a = s(!1);
69
- return r(() => {
70
- i.value = !0;
71
- }), d((e) => {
72
- i.value && n.value === "system" && e(j((e) => {
73
- a.value = e;
74
- }));
75
- }), e(() => A(n.value, i.value && a.value));
76
- }
77
- // src/composables/useDocxEditor.ts
78
- var dt = 24, ft = "User", pt = 250, mt = [], ht = [];
79
- function gt(e) {
80
- let t = e?.columnCount ?? 1;
81
- if (t <= 1) return;
82
- let n = {
83
- count: t,
84
- gap: b(e?.columnSpace ?? 720),
85
- equalWidth: e?.equalWidth ?? !0
86
- };
87
- return e?.separator !== void 0 && (n.separator = e.separator), n;
88
- }
89
- function _t(e, t, n, r, i, a) {
90
- if (!e) return;
91
- let o = t ? {
92
- ...a,
93
- rId: t
94
- } : a, s = t ? n?.getView(t) : null;
95
- return s ? Se(s.state.doc, r, i, o) : Ce(e, r, i, o);
96
- }
97
- function vt(e, t, n, r, i) {
98
- if (!e || e.size === 0) return;
99
- let a = /* @__PURE__ */ new Map();
100
- for (let [o, s] of e) {
101
- let e = _t(s, o, t, n, r, i);
102
- e && a.set(o, e);
103
- }
104
- return a.size > 0 ? a : void 0;
105
- }
106
- function yt(e, t, n) {
107
- let r = /* @__PURE__ */ new Map();
108
- if (!n || !n.package.footnotes) return r;
109
- let i = /* @__PURE__ */ new Map();
110
- for (let e of n.package.footnotes) e.noteType && e.noteType !== "normal" || i.set(e.id, e);
111
- for (let [n, a] of e) {
112
- let e = [];
113
- for (let n of a) {
114
- let r = i.get(n);
115
- if (!r) continue;
116
- let a = t.get(n), o = a?.displayNumber ?? 0;
117
- e.push({
118
- displayNumber: String(o),
119
- noteId: n,
120
- text: xe(r),
121
- ...a ? { content: {
122
- blocks: a.blocks,
123
- measures: a.measures,
124
- height: a.height
125
- } } : {}
126
- });
127
- }
128
- e.length > 0 && r.set(n, e);
129
- }
130
- return r;
131
- }
132
- var I = /* @__PURE__ */ new Set([
133
- "black",
134
- "blue",
135
- "cyan",
136
- "darkBlue",
137
- "darkCyan",
138
- "darkGray",
139
- "darkGreen",
140
- "darkMagenta",
141
- "darkRed",
142
- "darkYellow",
143
- "green",
144
- "lightGray",
145
- "magenta",
146
- "none",
147
- "red",
148
- "white",
149
- "yellow"
150
- ]);
151
- function bt(e) {
152
- let t = [], n = (e, r) => {
153
- for (let [n, i] of e.marks.entries()) i.type.name === "highlight" && !I.has(String(i.attrs.color)) && t.push(`${r}.marks[${n}]=${JSON.stringify(i.attrs)}`);
154
- e.forEach((e, t, i) => {
155
- n(e, `${r}.content[${i}]`);
156
- });
157
- };
158
- return n(e, "doc"), t.join("; ");
159
- }
160
- function L(e) {
161
- let { hiddenContainer: t, hiddenHeaderFooterContainer: n, noteEditorContainer: r, pagesContainer: a, readOnly: o = !1, experimentalSession: d, pageGap: ee = dt, pageRenderer: _, markupView: v = "all-markup", showCommentHighlights: b = !0, altChunkMarkerText: xe, showMarginGuides: Se, marginGuideColor: Ce, password: Ue, editorMode: We, author: Ge, externalPlugins: Ke = [], historyShortcuts: qe = "editor", collaboration: E, onAnonymizationMatchesChange: Je, showTemplateDirectives: Ye, onSlashMenuChange: Xe, onSlashMenuKeyAction: Ze, onChange: Qe, onError: D, onSelectionUpdate: $e, onEditorViewReady: et, onCopy: tt, onCut: nt, onPaste: rt, onReadOnlyEditAttempt: it, featureFlags: at, onSelectiveSaveTripwire: ot } = e, st = n ?? t, ct = () => l(Ge) ?? ft, O = c(null), k = 0, lt = !1, A = 0, j = !1, M = c(null), N = c(null), P = c(null), F = c([]), ut = c(null), I = c(null), L = c(null), xt = c([]), St = c([]), R = s(!1), z = s(null), B = s(!1), V = () => re(l(d), x.authorityRouting), H = (e) => V() ? g(e) : e, Ct = (e, t) => {
162
- if (!V()) return !1;
163
- let n = new f({
164
- gap: e,
165
- message: ne(e, t)
166
- });
167
- return D?.(n), !0;
168
- }, U = new ke(Pe({ historyShortcuts: qe }));
169
- U.buildSchema(), U.initializeRuntime();
170
- let wt = ie(!1), Tt = [wt], Et = Re({ keymap: !0 }), Dt = Le({ onMatchesChange: (e) => Je?.(e) }), Ot = ze(), kt = Ve({
171
- onChange: (e) => Xe?.(e),
172
- onKeyAction: (e) => Ze?.(e) ?? !1
173
- }), At = Be(), jt = () => l(Ye) === !0;
174
- function Mt() {
175
- return [
176
- Et,
177
- wt,
178
- ...Ke,
179
- ...l(E)?.plugins ?? [],
180
- Dt,
181
- ...jt() ? [Ot, kt] : [],
182
- At
183
- ];
184
- }
185
- let W = se(), G = new De(), K = he(), Nt = de({
186
- relayout: () => {
187
- let e = M.value?.state ?? K.lastEditorState;
188
- e && X(e, { reason: "hyphenation-ready" });
189
- },
190
- onError: (e) => D?.(e)
191
- });
192
- i(Nt.cancel), i(le({
193
- measuredFontSet: () => K.lastMeasureInputs?.fontSet ?? null,
194
- relayout: () => {
195
- if (j) return;
196
- let e = M.value?.state ?? K.lastEditorState;
197
- e && X(e, { reason: "font-ready" });
198
- }
199
- }));
200
- let Pt = new Te({
201
- pageGap: ee,
202
- showShadow: !0
203
- }), q = ue({
204
- getHost: () => st.value,
205
- getReadOnly: () => l(o),
206
- getDocument: () => $.api.getCanonicalDocument() ?? O.value,
207
- getCanonicalApi: () => $.api,
208
- getExperimentalSession: () => l(d),
209
- onSessionRefusal: (e, t, n) => {
210
- z.value = e, D?.(n ?? new f({
211
- gap: t,
212
- message: e
213
- }));
214
- },
215
- getStyles: () => O.value?.package.styles ?? null,
216
- getTheme: () => O.value?.package.theme ?? null,
217
- onTransaction: ({ rId: e, kind: t, view: n, docChanged: r, selectionChanged: i }) => {
218
- if (r && (B.value = !0, Z.schedule()), r || i) {
219
- let { from: r, to: i } = n.state.selection;
220
- ut.value = {
221
- from: r,
222
- kind: t,
223
- rId: e,
224
- to: i
225
- }, $e?.(n.state), W.emit("selectionChange", {
226
- from: r,
227
- to: i
228
- });
229
- }
230
- G.requestRender();
231
- }
232
- }), Ft = { current: null }, J = ge({
233
- getHost: () => r?.value ?? null,
234
- getPlugins: () => Tt,
235
- getDocument: () => $.api.getCanonicalDocument() ?? O.value,
236
- getCanonicalApi: () => $.api,
237
- getExperimentalSession: () => l(d),
238
- onSessionRefusal: (e, t, n) => {
239
- z.value = e, D?.(n ?? new f({
240
- gap: t,
241
- message: e
242
- }));
243
- },
244
- getStyles: () => O.value?.package.styles ?? null,
245
- getTheme: () => O.value?.package.theme ?? null,
246
- onTransaction: ({ docChanged: e, selectionChanged: t, view: n }) => {
247
- if (e) {
248
- B.value = !0;
249
- let e = O.value;
250
- if (e) {
251
- let t = $.api.getCanonicalDocument() ?? Ft.current?.snapshotDocument(e) ?? e;
252
- O.value = t, Qe?.(H(t)), W.emit("docChange", H(t));
253
- }
254
- Z.schedule();
255
- }
256
- if (e || t) {
257
- $e?.(n.state);
258
- let { from: e, to: t } = n.state.selection;
259
- W.emit("selectionChange", {
260
- from: e,
261
- to: t
262
- });
263
- }
264
- }
265
- });
266
- Ft.current = J;
267
- let Y = () => {
268
- q.sync(), J.sync();
269
- };
270
- u(() => l(d), Y);
271
- function It(e) {
272
- e.layout && (L.value = e.layout), e.blocks && (xt.value = e.blocks), e.measures && (St.value = e.measures), e.blockLookup && Pt.setBlockLookup(e.blockLookup), e.layout && W.emit("layoutComplete", e.layout);
273
- }
274
- function X(e, t = {}) {
275
- if (j) return;
276
- let n = a.value, r = n instanceof HTMLDivElement ? n : null, i = O.value, o = i?.package.document, s = o?.sections?.[0]?.properties ?? o?.finalSectionProperties ?? null, c = y(s), u = te(s), d = gt(s), f = c.w - u.left - u.right, p = i?.package.styles ?? null, m = i?.package.theme ?? null, h = i?.package.settings?.defaultTabStop, g = i?.package.settings?.mirrorMargins === !0, x = He(i?.package);
277
- try {
278
- It(fe({
279
- contentWidth: f,
280
- columns: d,
281
- pageSize: c,
282
- margins: u,
283
- pageGap: ee,
284
- showMarginGuides: l(Se) === !0,
285
- marginGuideColor: l(Ce),
286
- ...(() => {
287
- let e = l(_);
288
- return e === void 0 ? {} : { pageRenderer: e };
289
- })(),
290
- syncCoordinator: G,
291
- headerContent: x.headerContent,
292
- footerContent: x.footerContent,
293
- firstPageHeaderContent: x.firstPageHeaderContent,
294
- firstPageFooterContent: x.firstPageFooterContent,
295
- headerContentRId: x.activeHeaderRId,
296
- footerContentRId: x.activeFooterRId,
297
- firstPageHeaderContentRId: x.activeFirstHeaderRId,
298
- firstPageFooterContentRId: x.activeFirstFooterRId,
299
- sectionHeaderFooterRefs: we(i),
300
- theme: m,
301
- sectionProperties: s,
302
- document: i,
303
- defaultTabStop: h,
304
- mirrorMargins: g,
305
- styles: p,
306
- layout: L.value,
307
- hfPMs: q,
308
- painter: Pt,
309
- pagesContainer: r,
310
- session: K,
311
- renderHfFromContentOrPm: _t,
312
- renderHeaderFooterContentByRId: vt,
313
- readFontSetSignature: ce,
314
- buildFootnoteRenderItems: yt,
315
- describeInvalidHighlightMarks: bt,
316
- emptyTemplatePreviewEntries: mt,
317
- emptyTemplatePreviewHidden: ht,
318
- hyphenationReadiness: Nt,
319
- markupView: l(v),
320
- showCommentHighlights: l(b),
321
- ...xe === void 0 ? {} : { altChunkMarkerText: l(xe) }
322
- }, e, t));
323
- } catch (e) {
324
- let t = e instanceof Error ? e : Error(String(e));
325
- D?.(t);
326
- }
327
- }
328
- let Z = me({
329
- readState: () => M.value?.state ?? null,
330
- runLayout: (e, t) => X(e, t),
331
- ...T,
332
- clock: pe
333
- }), Q = null, Lt = Fe();
334
- function Rt() {
335
- Q !== null && (window.clearTimeout(Q), Q = null);
336
- let e = M.value, t = O.value;
337
- if (e && t) try {
338
- let n = $.api.getCanonicalDocument();
339
- if (!n && V()) return;
340
- let r = n ?? Lt.reconcile(Oe(e.state.doc, t, { stylesheetSource: { type: "package" } }), e.state.doc);
341
- O.value = r, Y(), Qe?.(H(r)), W.emit("docChange", H(r));
342
- } catch (e) {
343
- D?.(e instanceof Error ? e : Error(String(e)));
344
- }
345
- }
346
- function zt() {
347
- Q !== null && window.clearTimeout(Q), Q = window.setTimeout(() => {
348
- Q = null, Rt();
349
- }, pt);
350
- }
351
- let $ = m({
352
- getHost: () => t.value,
353
- getDocument: () => O.value,
354
- getStyles: () => O.value?.package.styles ?? null,
355
- getExtensionManager: () => U,
356
- getExternalPlugins: Mt,
357
- getCollaboration: () => l(E),
358
- getCollaborationModules: () => P.value,
359
- getPrecomputedInitialState: () => null,
360
- getReadOnly: () => l(o),
361
- getExperimentalSession: () => l(d),
362
- getEditingMode: () => l(We) ?? "editing",
363
- getSuggestionAuthor: ct,
364
- onSessionRefusal: (e, t, n) => {
365
- D?.(n ?? new f({
366
- gap: t,
367
- message: e
368
- }));
369
- },
370
- getDocumentIdentity: () => String(k),
371
- getDocumentContext: () => O.value,
372
- onTransaction: Vt,
373
- onCanonicalCompositionEnd: () => Z.schedule(),
374
- onSelectionChange: (e) => {
375
- N.value = e, $e?.(e), W.emit("selectionChange", {
376
- from: e.selection.from,
377
- to: e.selection.to
378
- });
379
- },
380
- onKeyDown: () => !1,
381
- onCopy: () => tt?.(),
382
- onCut: () => nt?.(),
383
- onPaste: () => rt?.(),
384
- onReadOnlyEditAttempt: () => it?.(),
385
- onEditorViewReady: Ht,
386
- onEditorViewDestroy: () => {
387
- M.value = null, R.value = !1, et?.(null);
388
- },
389
- onRemoteSelectionsChange: (e) => {
390
- F.value = e;
391
- }
392
- }), Bt = () => {
393
- let e = l(E)?.awareness, t = P.value, n = $.getView();
394
- F.value = e && t && n ? p(n.state, e, t) : [];
395
- };
396
- u(() => l(E), (e, t, n) => {
397
- if (F.value = [], !e) {
398
- P.value = null, $.retryViewCreation(), $.syncExternalDocument();
399
- return;
400
- }
401
- let r = !1;
402
- n(() => {
403
- r = !0;
404
- }), P.value = null, ae().then((e) => {
405
- r || (P.value = e, $.retryViewCreation(), $.syncExternalDocument(), Bt());
406
- }, (e) => {
407
- r || (P.value = null, D?.(e instanceof Error ? e : Error(String(e))));
408
- });
409
- }, { immediate: !0 }), u(() => ({
410
- awareness: l(E)?.awareness,
411
- modules: P.value,
412
- view: M.value
413
- }), ({ awareness: e, modules: t, view: n }, r, i) => {
414
- !e || !t || !n ? F.value = [] : (e.on("change", Bt), Bt(), i(() => {
415
- e.off("change", Bt), F.value = [];
416
- }));
417
- }, { flush: "post" });
418
- function Vt({ newState: e, docChanged: t, transactions: n }) {
419
- N.value = e;
420
- let r = n[0]?.before;
421
- if (t && r && Lt.noteBase(r), t) {
422
- let e = $.api.getCanonicalDocument();
423
- e && (O.value = e, Y()), B.value = !0, G.incrementStateSeq(), Z.schedule(), zt();
424
- }
425
- G.requestRender();
426
- }
427
- function Ht(e) {
428
- M.value = e, N.value = e.state, R.value = !0;
429
- let t = O.value, n = k, r = ++A;
430
- j = !0;
431
- let i = () => {
432
- A === r && (j = !1, !(lt || k !== n || $.getView() !== e) && (X(e.state, { reason: "initial" }), G.requestRender()));
433
- };
434
- w(t, e.state.doc).then(i, i), Gt(e), et?.(e), l(o) || requestAnimationFrame(() => {
435
- M.value === e && e.focus();
436
- });
437
- }
438
- let Ut = {
439
- getDocx: async (e) => (await Qt(e))?.buffer ?? null,
440
- loadDocument: Zt,
441
- loadDocx: Xt
442
- }, Wt = oe({
443
- getEditorApi: () => $.api,
444
- getLayout: () => L.value,
445
- runLayout: (e, t) => X(e, t),
446
- getDocumentIO: () => Ut,
447
- emitter: W
448
- });
449
- function Gt(e) {
450
- let t = l(We) === "suggesting";
451
- S(t, e.state, e.dispatch, ct());
452
- }
453
- u([() => l(We), ct], () => {
454
- Wt.setCanonicalMode(l(We) === "suggesting" ? {
455
- type: "suggesting",
456
- author: ct()
457
- } : { type: "editing" });
458
- let e = M.value;
459
- e && Gt(e);
460
- for (let e of J.listStories()) {
461
- let t = J.getView(e);
462
- t && Gt(t);
463
- }
464
- }), u(() => l(o), (e) => {
465
- $.syncEditable(), e && on(), q.sync();
466
- });
467
- function Kt(e) {
468
- let t = jt();
469
- if (t === e.state.plugins.includes(Ot)) return;
470
- let n = e.state.plugins.filter((e) => e !== Ot && e !== kt);
471
- if (t) {
472
- let e = n.indexOf(At), t = e === -1 ? n.length : e;
473
- n.splice(t, 0, Ot, kt);
474
- }
475
- e.updateState(e.state.reconfigure({ plugins: n }));
476
- }
477
- u(() => jt(), () => {
478
- let e = M.value;
479
- e && Kt(e);
480
- });
481
- function qt() {
482
- $.ensureView();
483
- }
484
- function Jt() {
485
- k += 1, B.value = !1, ut.value = null, I.value = null, J.activate(null), Z.dispose(), $.destroyView(), V() && $.ensureView(), Y(), $.ensureView(), $.getView() || Yt();
486
- }
487
- function Yt() {
488
- let e = O.value;
489
- if (e && !l(E)) try {
490
- let t = h({
491
- document: e,
492
- styles: e.package.styles ?? null,
493
- manager: U,
494
- externalPlugins: Mt(),
495
- collaborationModules: null,
496
- reason: "mount"
497
- });
498
- N.value = t;
499
- let n = k, r = ++A;
500
- j = !0;
501
- let i = () => {
502
- A === r && (j = !1, !(lt || k !== n || O.value !== e || $.getView()) && X(t, { reason: "initial" }));
503
- };
504
- w(e, t.doc).then(i, i);
505
- } catch (e) {
506
- D?.(e instanceof Error ? e : Error(String(e)));
507
- }
508
- }
509
- u([
510
- t,
511
- a,
512
- st,
513
- ...r ? [r] : []
514
- ], () => {
515
- t.value && O.value && !$.getView() && qt(), Y();
516
- }, { flush: "post" });
517
- async function Xt(e) {
518
- z.value = null, R.value = !1;
519
- try {
520
- let t = e;
521
- if (V()) {
522
- let n = await ye(e);
523
- if (n.isErr()) throw n.error;
524
- t = n.value;
525
- }
526
- let n = await be(t, { password: l(Ue) });
527
- O.value = n, Jt();
528
- } catch (e) {
529
- let t = e instanceof Error ? e : Error(String(e));
530
- z.value = t.message, D?.(t);
531
- }
532
- }
533
- function Zt(e) {
534
- z.value = null, O.value = e, Lt.reset(), Jt();
535
- }
536
- async function Qt(e) {
537
- let t = M.value, n = O.value;
538
- if (!t || !n) return null;
539
- try {
540
- let t = $.api.captureCanonicalSave();
541
- if (t) {
542
- let n = await ve({
543
- snapshot: t,
544
- options: e,
545
- featureFlags: l(at)
546
- });
547
- for (let t of n.diagnostics) e?.onDiagnostic || D?.(new _e({
548
- gap: x.save,
549
- diagnostic: t,
550
- message: `Canonical save used a fidelity fallback: ${t.type} (${t.part}).`
551
- }));
552
- return n.tripwireResult && ot?.(n.tripwireResult), n;
553
- }
554
- } catch (e) {
555
- return D?.(e instanceof Error ? e : Error(String(e))), null;
556
- }
557
- if (V()) return null;
558
- Q !== null && Rt();
559
- let r = J.snapshotDocument(q.snapshotDocument(n)), i = t.state, a = Ie(Oe(i.doc, r, { stylesheetSource: { type: "package" } })), { resolveSelectiveSaveFlags: o } = await import("@stll/folio-core/docx/selectiveSaveFlags"), s = o(l(at)), c = a.originalBuffer ?? null, u = s.selectiveSave && e?.mode !== C.full, d = u || s.selectiveSaveTripwire, { repackDocx: f, createDocx: p } = await import("@stll/folio-core/docx/rezip"), m = null;
560
- if (d && c) {
561
- let { attemptSelectiveSave: e } = await import("@stll/folio-core/docx/selectiveSave");
562
- m = await e(a, c, {
563
- changedParaIds: Ae(i),
564
- structuralChange: je(i),
565
- hasUntrackedChanges: Me(i),
566
- maxBytes: s.selectiveSaveMaxBytes
567
- });
568
- }
569
- let h = u ? m : null, g = null, ee = () => Ne({
570
- state: i,
571
- document: a,
572
- repack: () => f(a)
573
- });
574
- if (!h) g = c ? await ee() : await p(a), h = g;
575
- else if (s.selectiveSaveTripwire) try {
576
- g = await ee();
577
- } catch {}
578
- if (s.selectiveSaveTripwire && g && ot) try {
579
- let { compareSelectiveVsFull: e } = await import("@stll/folio-core/docx/selectiveSaveTripwire");
580
- ot(await e(m, g));
581
- } catch {}
582
- return {
583
- buffer: h,
584
- document: a
585
- };
586
- }
587
- async function $t(e) {
588
- let t = M.value, n = t?.state, r = await Qt({ mode: e?.selective === !1 ? C.full : C.preferSelective });
589
- return r ? (M.value === t && t?.state.doc === n?.doc && (r.version === void 0 || $.api.isCanonicalSaveCurrent(r.version)) && (O.value = r.document, Y(), B.value = !1), new Blob([r.buffer], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" })) : null;
590
- }
591
- function en() {
592
- let e = $.api.getCanonicalDocument();
593
- if (e) return e;
594
- if (V()) return null;
595
- let t = O.value;
596
- if (!t) return null;
597
- let n = $.api.getDocument() ?? t;
598
- return H(J.snapshotDocument(q.snapshotDocument(n)));
599
- }
600
- function tn(e) {
601
- Ct(x.modelEdits, "Direct document model changes are unavailable in this session.") || (O.value = e, Y(), I.value && !J.getView(I.value) && (I.value = null));
602
- }
603
- function nn(e) {
604
- return q.getView(e);
605
- }
606
- function rn() {
607
- Y();
608
- }
609
- function an(e) {
610
- let t = J.activate(e);
611
- t && (Gt(t), I.value = e, requestAnimationFrame(() => t.focus()));
612
- }
613
- function on() {
614
- J.activate(null), I.value = null;
615
- }
616
- function sn() {
617
- let e = I.value;
618
- return e ? J.getView(e) : null;
619
- }
620
- function cn() {
621
- return U.getCommands();
622
- }
623
- function ln() {
624
- let e = sn();
625
- e ? e.focus() : M.value?.focus();
626
- }
627
- function un() {
628
- let e = M.value;
629
- e && X(e.state, { reason: "manual" });
630
- }
631
- u([
632
- () => l(Se),
633
- () => l(Ce),
634
- () => l(_),
635
- () => l(v),
636
- () => l(b),
637
- () => l(xe)
638
- ], () => un());
639
- function dn() {
640
- lt = !0, a.value && Ee(a.value), A += 1, j = !1, Z.dispose(), Q !== null && (window.clearTimeout(Q), Q = null), $.destroyView(), F.value = [], q.destroy(), J.destroy(), U.destroy(), N.value = null, L.value = null, O.value = null, R.value = !1;
641
- }
642
- return i(dn), {
643
- setEmbeddedFontFamilies: (e) => {
644
- e ? K.embeddedFontFamilyMap = new Map(e) : delete K.embeddedFontFamilyMap;
645
- },
646
- editor: Wt,
647
- editorView: M,
648
- editorState: N,
649
- remoteSelections: F,
650
- headerFooterSelection: ut,
651
- activeNoteStory: I,
652
- isReady: R,
653
- isDirty: B,
654
- parseError: z,
655
- layout: L,
656
- blocks: xt,
657
- measures: St,
658
- syncCoordinator: G,
659
- loadBuffer: Xt,
660
- loadDocument: Zt,
661
- save: $t,
662
- getDocument: en,
663
- setDocument: tn,
664
- getHeaderFooterView: nn,
665
- syncHeaderFooterViews: rn,
666
- openNoteStory: an,
667
- closeNoteStory: on,
668
- getActiveNoteView: sn,
669
- getCommands: cn,
670
- focus: ln,
671
- reLayout: un,
672
- destroy: dn
673
- };
674
- }
675
- // src/composables/useFindReplace.ts
676
- function xt({ editorView: t, pagesRef: n, getDocument: r, layout: a, commentRoot: l, revealComment: d, displayMode: f, readOnly: p, onReadonlyEditAttempt: m, onResultChange: h }) {
677
- let g = new Ue(), _ = s(""), v = s(""), te = o(E()), y = c([]), b = s(-1), x = e(() => y.value.at(b.value) ?? null), ne = () => ee({
678
- editingMode: t.value?.editable === !1 ? "viewing" : "editing",
679
- readOnlyProp: p.value,
680
- displayMode: f.value
681
- }), re = e(ne), ie = e(() => {
682
- let e = x.value;
683
- return ne() === null && !!t.value && !!e && se() && Je(e).status === "allowed";
684
- }), S = null, ae, C = null, oe = (e) => {
685
- let n = t.value?.state.doc;
686
- return {
687
- query: _.value,
688
- options: {
689
- ...te,
690
- displayMode: f.value,
691
- includeComments: !!l
692
- },
693
- document: e,
694
- ...n ? { bodyVersion: n } : {},
695
- context: { renderedStories: qe(a.value) }
696
- };
697
- }, se = () => {
698
- let e = r();
699
- return !!e && Xe(C, Ye(oe(e)));
700
- }, ce = () => g.getResult(), w = () => h(ce()), le = () => {
701
- clearTimeout(ae), ae = void 0;
702
- }, ue = () => {
703
- le(), g.clear(), S?.destroy(), S = null, y.value = [], C = null, b.value = -1;
704
- }, de = () => {
705
- ue(), _.value = "", w();
706
- }, fe = (e) => (b.value = e, S?.navigate(e, d), w(), !0), T = (e = "query") => {
707
- le();
708
- let i = r(), o = n.value, s = t.value?.state.doc;
709
- if (!i || !_.value.trim()) return de(), [];
710
- let c = oe(i), u = We({
711
- document: c.document,
712
- state: t.value?.state ?? null,
713
- searchText: c.query,
714
- options: c.options,
715
- context: c.context
716
- });
717
- if (u === null) return ue(), w(), [];
718
- let d = Ye(c), f = e === "refresh" && C?.query === d.query, p = g.setMatches(u, f ? g.getResult()?.currentIndex ?? 0 : 0);
719
- return C = d, y.value = u, b.value = u.length > 0 ? p.currentIndex : -1, S?.destroy(), S = o ? Ke({
720
- container: o,
721
- document: i,
722
- bodyDoc: s,
723
- matches: u,
724
- commentRoot: l?.value ?? void 0,
725
- layout: a.value
726
- }) : null, S?.paint(b.value), u.at(0) && !f ? fe(0) : w(), u;
727
- }, pe = () => {
728
- le(), ae = setTimeout(() => T("refresh"), 120);
729
- }, me = (e, t) => (_.value = e, Object.assign(te, E(), t), T(), ce()), he = (e) => {
730
- let t = g.goTo(e);
731
- return t ? fe(t.index) : !1;
732
- }, ge = (e) => {
733
- let t = g.navigate(e);
734
- return t ? (fe(t.index), t.match) : null;
735
- }, _e = () => !se() && (T("refresh"), !0), ve = () => {
736
- let e = ne();
737
- return e !== null && (m?.(e), !0);
738
- };
739
- return u(f, () => {
740
- _.value.trim() && T();
741
- }), i(() => {
742
- le(), S?.destroy();
743
- }), {
744
- searchText: _,
745
- replaceText: v,
746
- options: te,
747
- matches: y,
748
- currentIndex: b,
749
- currentMatch: x,
750
- canReplaceCurrent: ie,
751
- replacementRefusal: re,
752
- performSearch: T,
753
- scheduleSearch: pe,
754
- find: me,
755
- getFindResult: ce,
756
- goToMatch: he,
757
- findNext: () => ge("next"),
758
- findPrevious: () => ge("previous"),
759
- replaceCurrent: () => {
760
- let e = t.value;
761
- if (!e || ve() || _e()) return !1;
762
- let n = x.value;
763
- if (!ie.value || !e || !n) return !1;
764
- if (n.text === v.value) return !0;
765
- let r = Ge(e.state.doc, n);
766
- return r ? (e.dispatch(e.state.tr.insertText(v.value, r.from, r.to)), T("refresh"), !0) : !1;
767
- },
768
- replaceAll: () => {
769
- let e = t.value, n = y.value.length;
770
- if (!e || ve() || _e()) return {
771
- replacedCount: 0,
772
- skippedCount: n
773
- };
774
- let r = y.value.filter((e) => Je(e).status === "allowed"), i = r.filter((e) => e.text === v.value).length, a = r.filter((e) => e.text !== v.value).flatMap((t) => {
775
- let n = Ge(e.state.doc, t);
776
- return n ? [n] : [];
777
- }).toSorted((e, t) => t.from - e.from), o = a.length + i, s = {
778
- replacedCount: o,
779
- skippedCount: n - o
780
- };
781
- if (!a.length) return s;
782
- let c = e.state.tr;
783
- for (let e of a) c = c.insertText(v.value, e.from, e.to);
784
- return e.dispatch(c), T(), s;
785
- },
786
- clear: de
787
- };
788
- }
789
- function St(e, t) {
790
- if (t < e.top + 40) {
791
- let n = Math.max(0, e.top + 40 - t);
792
- return -Math.min(12, n / 40 * 12);
793
- }
794
- if (t > e.bottom - 40) {
795
- let n = Math.max(0, t - (e.bottom - 40));
796
- return Math.min(12, n / 40 * 12);
797
- }
798
- return 0;
799
- }
800
- // src/composables/useDragAutoScroll.ts
801
- function R({ pagesContainer: e, onScrollExtendSelection: t }) {
802
- let n = null, r = 0, a = 0, o = !1;
803
- function s() {
804
- return _(e.value);
805
- }
806
- function c() {
807
- o = !1, n !== null && (cancelAnimationFrame(n), n = null);
808
- }
809
- function l() {
810
- if (!o) return;
811
- let e = s();
812
- if (!e) return;
813
- let i = St(e.getBoundingClientRect(), a);
814
- i !== 0 && (v(e, i), t(r, a)), n = requestAnimationFrame(l);
815
- }
816
- function u() {
817
- o || (o = !0, n = requestAnimationFrame(l));
818
- }
819
- function d(e, t) {
820
- if (r = e, a = t, !o) {
821
- let e = s();
822
- if (!e) return;
823
- let n = e.getBoundingClientRect();
824
- (t < n.top + 40 || t > n.bottom - 40) && u();
825
- }
826
- }
827
- return i(() => c()), {
828
- updateMousePosition: d,
829
- stopAutoScroll: c
830
- };
831
- }
832
- // src/composables/useTableResize.ts
833
- function z() {
834
- let e = {
835
- active: !1,
836
- startX: 0,
837
- handle: null,
838
- columnIndex: 0,
839
- tablePmStart: 0,
840
- origWidths: {
841
- left: 0,
842
- right: 0
843
- }
844
- }, t = {
845
- active: !1,
846
- startY: 0,
847
- handle: null,
848
- rowIndex: 0,
849
- isEdge: !1,
850
- tablePmStart: 0,
851
- origHeight: 0,
852
- minimumHeight: Qe
853
- }, n = {
854
- active: !1,
855
- startX: 0,
856
- handle: null,
857
- columnIndex: 0,
858
- tablePmStart: 0,
859
- origWidth: 0
860
- }, r = null;
861
- function i() {
862
- return e.active || t.active || n.active;
863
- }
864
- function a(i, a) {
865
- let o = i.target;
866
- return o instanceof HTMLElement ? 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), B(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), V(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), H(a, n), !0) : !1 : !1;
867
- }
868
- function o(r) {
869
- if (e.active && e.handle) {
870
- r.preventDefault();
871
- let t = r.clientX - e.startX, n = parseFloat(e.handle.style.left);
872
- e.handle.style.left = `${n + t}px`, e.startX = r.clientX;
873
- let i = Math.round(t * D), a = e.origWidths.left + i, o = e.origWidths.right - i;
874
- a >= Ze && o >= Ze && (e.origWidths = {
875
- left: a,
876
- right: o
877
- });
878
- } else if (t.active && t.handle) {
879
- r.preventDefault();
880
- let e = r.clientY - t.startY, n = parseFloat(t.handle.style.top);
881
- t.startY = r.clientY;
882
- let i = Math.round(e * D), a = $e({
883
- currentHeight: t.origHeight,
884
- delta: i,
885
- minimumHeight: t.minimumHeight
886
- });
887
- t.handle.style.top = `${n + a / D}px`, t.origHeight += a;
888
- } else if (n.active && n.handle) {
889
- r.preventDefault();
890
- let e = r.clientX - n.startX, t = parseFloat(n.handle.style.left);
891
- n.handle.style.left = `${t + e}px`, n.startX = r.clientX;
892
- let i = Math.round(e * D), a = n.origWidth + i;
893
- a >= Ze && (n.origWidth = a);
894
- }
895
- }
896
- function s(i) {
897
- e.active ? (e.active = !1, e.handle?.classList.remove("dragging"), r && et(r, {
898
- pmStart: e.tablePmStart,
899
- colIdx: e.columnIndex,
900
- newLeft: e.origWidths.left,
901
- newRight: e.origWidths.right
902
- }), e.handle = null) : t.active ? (t.active = !1, t.handle?.classList.remove("dragging"), r && nt(r, {
903
- pmStart: t.tablePmStart,
904
- rowIdx: t.rowIndex,
905
- newHeight: t.origHeight
906
- }), t.handle = null) : n.active && (n.active = !1, n.handle?.classList.remove("dragging"), r && tt(r, {
907
- pmStart: n.tablePmStart,
908
- colIdx: n.columnIndex,
909
- newWidth: n.origWidth
910
- }), n.handle = null);
911
- }
912
- function c() {
913
- return document.addEventListener("mousemove", o), document.addEventListener("mouseup", s), () => {
914
- document.removeEventListener("mousemove", o), document.removeEventListener("mouseup", s);
915
- };
916
- }
917
- return {
918
- tryStartResize: a,
919
- install: c,
920
- isResizing: i
921
- };
922
- }
923
- function B(e, t) {
924
- let n = it(e, t.tablePmStart, t.columnIndex);
925
- n && (t.origWidths = n);
926
- }
927
- function V(e, t, n) {
928
- let r = at(e, t.tablePmStart, t.rowIndex);
929
- if (r != null) t.origHeight = r;
930
- else {
931
- let e = n.closest(".layout-table")?.querySelector(`[data-row-index="${t.rowIndex}"]`), r = e ? e.getBoundingClientRect().height : 30;
932
- t.origHeight = Math.round(r * D);
933
- }
934
- t.minimumHeight = Math.min(Qe, t.origHeight);
935
- }
936
- function H(e, t) {
937
- let n = rt(e, t.tablePmStart, t.columnIndex);
938
- n != null && (t.origWidth = n);
939
- }
940
- // src/composables/useTrackedChanges.ts
941
- function Ct(t, n) {
942
- return e(() => (n.value, ot(t.value?.state ?? null)));
943
- }
944
- // src/composables/useZoom.ts
945
- var U = ct, wt = st, Tt = [
946
- .5,
947
- .75,
948
- 1,
949
- 1.25,
950
- 1.5,
951
- 2
952
- ];
953
- function Et(t = 1) {
954
- let i = s(Math.max(U, Math.min(wt, t))), a = e(() => Math.round(i.value * 100)), o = e(() => i.value <= U), c = e(() => i.value >= wt);
955
- function l(e) {
956
- i.value = Math.max(U, Math.min(wt, Math.round(e * 100) / 100));
957
- }
958
- function u() {
959
- l(i.value + O);
960
- }
961
- function d() {
962
- l(i.value - O);
963
- }
964
- function f() {
965
- l(1);
966
- }
967
- function p(e) {
968
- (e.ctrlKey || e.metaKey) && (e.preventDefault(), e.deltaY < 0 ? u() : d());
969
- }
970
- function m(e) {
971
- (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())));
972
- }
973
- function h() {
974
- r(() => document.addEventListener("keydown", m)), n(() => document.removeEventListener("keydown", m));
975
- }
976
- return {
977
- zoom: i,
978
- zoomPercent: a,
979
- isMinZoom: o,
980
- isMaxZoom: c,
981
- setZoom: l,
982
- zoomIn: u,
983
- zoomOut: d,
984
- resetZoom: f,
985
- handleWheel: p,
986
- handleKeyDown: m,
987
- installShortcuts: h,
988
- ZOOM_PRESETS: Tt
989
- };
990
- }
991
- export { R as a, F as c, ut as d, z as i, M as l, ot as n, xt as o, Ct as r, L as s, Et as t, P as u };