@stll/folio-vue 0.32.0 → 0.32.1

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