@kedataindo/docflow-core 0.0.82 → 0.0.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -10,14 +10,9 @@ import {
10
10
  trimContextAfter,
11
11
  trimContextBefore
12
12
  } from "./chunk-HMOWKFPE.js";
13
- import {
14
- collaborationExtensions,
15
- createCollaboration
16
- } from "./chunk-XJG72F7M.js";
17
13
 
18
14
  // src/Editor.ts
19
- import { Extension as Extension6, Editor as TiptapEditor } from "@tiptap/core";
20
- import { Plugin as Plugin5, PluginKey as PluginKey5 } from "@tiptap/pm/state";
15
+ import { Editor as TiptapEditor } from "@tiptap/core";
21
16
  import StarterKit from "@tiptap/starter-kit";
22
17
  import TextStyle from "@tiptap/extension-text-style";
23
18
 
@@ -68,6 +63,143 @@ function createActionMap(editor, plugins) {
68
63
  return map;
69
64
  }
70
65
 
66
+ // src/Collaboration.ts
67
+ import { Collaboration } from "@tiptap/extension-collaboration";
68
+ import { CollaborationCursor } from "@tiptap/extension-collaboration-cursor";
69
+ import { Awareness } from "y-protocols/awareness";
70
+ import { IndexeddbPersistence } from "y-indexeddb";
71
+ import { WebrtcProvider } from "y-webrtc";
72
+ import { WebsocketProvider } from "y-websocket";
73
+ import * as Y from "yjs";
74
+ var LOCAL_SIGNALING = ["ws://localhost:4444"];
75
+ var warnedLocalSignaling = false;
76
+ function resolveSignalingUrls(signaling) {
77
+ if (signaling && signaling.length > 0) return signaling;
78
+ if (!warnedLocalSignaling) {
79
+ warnedLocalSignaling = true;
80
+ console.warn(
81
+ '[docflow] webrtc provider has no `signaling` configured \u2014 falling back to localhost-only sync (ws://localhost:4444 + same-browser tabs). For production self-host, run your own signaling server and pass `signaling`, or use `provider: "websocket"` with your own websocketUrl.'
82
+ );
83
+ }
84
+ return LOCAL_SIGNALING;
85
+ }
86
+ var LOCAL_PRESENT_DEFAULT = true;
87
+ function createAwarenessStates(awareness) {
88
+ const states = [];
89
+ awareness.getStates().forEach((state, clientId) => {
90
+ const raw = state;
91
+ states.push({
92
+ clientId,
93
+ user: raw.user ?? { name: "", color: "" },
94
+ cursor: raw.cursor ?? null,
95
+ // `present` defaults to true for backwards compat (legacy states
96
+ // don't set it) and for the local user (always considered present
97
+ // until PR2 toggles it off).
98
+ present: raw.present ?? LOCAL_PRESENT_DEFAULT
99
+ });
100
+ });
101
+ return states;
102
+ }
103
+ function createCollaboration(options) {
104
+ const ydoc = new Y.Doc();
105
+ if (options.initialStorageState) {
106
+ Y.applyUpdate(ydoc, options.initialStorageState);
107
+ }
108
+ let persistence;
109
+ if (options.offline) {
110
+ persistence = new IndexeddbPersistence(`docflow-${options.room}`, ydoc);
111
+ }
112
+ let provider = null;
113
+ if (options.provider === "webrtc") {
114
+ provider = new WebrtcProvider(options.room, ydoc, {
115
+ signaling: resolveSignalingUrls(options.signaling)
116
+ });
117
+ } else if (options.provider === "websocket") {
118
+ if (!options.websocketUrl) {
119
+ throw new Error('[Collaboration] websocketUrl is required when provider is "websocket"');
120
+ }
121
+ provider = new WebsocketProvider(options.websocketUrl, options.room, ydoc);
122
+ }
123
+ const awareness = provider?.awareness ?? new Awareness(ydoc);
124
+ awareness.setLocalStateField("user", options.user);
125
+ let emitCursor = options.emitCursor ?? true;
126
+ const setLocalCursorEnabled = (enabled) => {
127
+ if (emitCursor === enabled) return;
128
+ emitCursor = enabled;
129
+ if (!enabled) {
130
+ awareness.setLocalStateField("cursor", null);
131
+ }
132
+ awareness.setLocalStateField("emitCursor", enabled);
133
+ };
134
+ awareness.setLocalStateField("present", true);
135
+ awareness.setLocalStateField("emitCursor", emitCursor);
136
+ let awarenessHandler;
137
+ if (options.onAwarenessChange) {
138
+ const notify = () => {
139
+ options.onAwarenessChange?.(createAwarenessStates(awareness));
140
+ };
141
+ awarenessHandler = notify;
142
+ awareness.on("change", notify);
143
+ notify();
144
+ }
145
+ const readyParts = [];
146
+ if (persistence) {
147
+ readyParts.push(
148
+ persistence.whenSynced.then(
149
+ () => void 0,
150
+ () => void 0
151
+ )
152
+ );
153
+ }
154
+ if (provider && options.provider === "websocket") {
155
+ const ws = provider;
156
+ readyParts.push(
157
+ new Promise((resolve) => {
158
+ let settled = false;
159
+ const done = () => {
160
+ if (settled) return;
161
+ settled = true;
162
+ resolve();
163
+ };
164
+ if (ws.synced) {
165
+ done();
166
+ return;
167
+ }
168
+ ws.once("sync", done);
169
+ ws.once("synced", done);
170
+ setTimeout(done, 5e3);
171
+ })
172
+ );
173
+ }
174
+ const whenReady = readyParts.length === 0 ? Promise.resolve() : Promise.all(readyParts).then(() => void 0);
175
+ const destroy = () => {
176
+ if (awarenessHandler) {
177
+ awareness.off("change", awarenessHandler);
178
+ }
179
+ awareness.setLocalState(null);
180
+ provider?.destroy?.();
181
+ awareness.destroy?.();
182
+ void persistence?.destroy();
183
+ ydoc.destroy();
184
+ };
185
+ return { ydoc, provider, awareness, persistence, whenReady, destroy, setLocalCursorEnabled };
186
+ }
187
+ function collaborationExtensions(options) {
188
+ const setup = "ydoc" in options ? options : createCollaboration(options);
189
+ const extensions = [
190
+ Collaboration.configure({ document: setup.ydoc })
191
+ ];
192
+ if (setup.provider) {
193
+ extensions.push(
194
+ CollaborationCursor.configure({
195
+ provider: setup.provider,
196
+ user: setup.awareness.getLocalState()?.user ?? { name: "", color: "" }
197
+ })
198
+ );
199
+ }
200
+ return extensions;
201
+ }
202
+
71
203
  // src/BlockAttributes.ts
72
204
  import { Extension } from "@tiptap/core";
73
205
  import { Plugin, PluginKey } from "@tiptap/pm/state";
@@ -129,42 +261,6 @@ var BlockAttributesExtension = Extension.create({
129
261
  }
130
262
  });
131
263
 
132
- // src/collab/seedEmptyFragment.ts
133
- import * as Y from "yjs";
134
- var PROVISIONAL_SEED_ORIGIN = "docflow:provisional-seed";
135
- function isPristineEmptyParagraph(element) {
136
- return element.length === 0 && Object.keys(element.getAttributes()).length === 0;
137
- }
138
- function seedEmptyFragment(doc, field = "default") {
139
- const fragment = doc.getXmlFragment(field);
140
- const paragraph = new Y.XmlElement("paragraph");
141
- const observer = (_events, transaction) => {
142
- if (transaction.origin === PROVISIONAL_SEED_ORIGIN) return;
143
- if (paragraph.parent !== fragment) return;
144
- if (!isPristineEmptyParagraph(paragraph)) return;
145
- if (fragment.length < 2) return;
146
- const index = fragment.toArray().indexOf(paragraph);
147
- if (index === -1) return;
148
- doc.transact(() => {
149
- fragment.delete(index);
150
- }, PROVISIONAL_SEED_ORIGIN);
151
- };
152
- let disposed = false;
153
- const dispose = () => {
154
- if (disposed) return;
155
- disposed = true;
156
- fragment.unobserveDeep(observer);
157
- };
158
- if (fragment.length > 0) {
159
- return { seeded: false, dispose };
160
- }
161
- fragment.observeDeep(observer);
162
- doc.transact(() => {
163
- fragment.insert(0, [paragraph]);
164
- }, PROVISIONAL_SEED_ORIGIN);
165
- return { seeded: true, dispose };
166
- }
167
-
168
264
  // src/EditorContext.ts
169
265
  import { Extension as Extension2 } from "@tiptap/core";
170
266
  var EditorContextExtension = Extension2.create({
@@ -187,11 +283,336 @@ var EditorContextExtension = Extension2.create({
187
283
  }
188
284
  });
189
285
 
190
- // src/SearchAndReplace.ts
286
+ // src/ManualColumnResize.ts
191
287
  import { Extension as Extension3 } from "@tiptap/core";
192
- import { Plugin as Plugin2, PluginKey as PluginKey2, TextSelection } from "@tiptap/pm/state";
288
+ import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
289
+ var ManualColumnResize = Extension3.create({
290
+ name: "manualColumnResize",
291
+ addProseMirrorPlugins() {
292
+ const key2 = new PluginKey2("manualColumnResize");
293
+ return [new Plugin2({
294
+ key: key2,
295
+ view(view) {
296
+ const observer = view;
297
+ function pauseObserver() {
298
+ try {
299
+ observer.domObserver?.stop?.();
300
+ } catch (_) {
301
+ }
302
+ }
303
+ function resumeObserver() {
304
+ try {
305
+ observer.domObserver?.start?.();
306
+ } catch (_) {
307
+ }
308
+ }
309
+ function getMaxContainerWidth(tableEl) {
310
+ let curr = tableEl.parentElement;
311
+ while (curr) {
312
+ const style = window.getComputedStyle(curr);
313
+ const paddingLeft = parseFloat(style.paddingLeft) || 0;
314
+ const paddingRight = parseFloat(style.paddingRight) || 0;
315
+ const availWidth = curr.clientWidth - paddingLeft - paddingRight;
316
+ if (availWidth > 100 && (curr.classList.contains("docs-editor__paper") || curr.classList.contains("docs-editor-page") || curr.classList.contains("ProseMirror") || curr.classList.contains("rm-with-pagination"))) {
317
+ return availWidth;
318
+ }
319
+ curr = curr.parentElement;
320
+ }
321
+ return tableEl.parentElement?.clientWidth || 614;
322
+ }
323
+ const onMouseDown = function(event) {
324
+ if (event.button !== 0) return;
325
+ const td = event.target.closest("td, th");
326
+ if (!td) return;
327
+ const r = td.getBoundingClientRect();
328
+ const parent = td.parentElement;
329
+ if (!parent) return;
330
+ const cellColSpan = td.colSpan || 1;
331
+ let logicalStart = 0;
332
+ let foundCell = false;
333
+ for (const sibling of Array.from(parent.children)) {
334
+ if (sibling === td) {
335
+ foundCell = true;
336
+ break;
337
+ }
338
+ logicalStart += sibling.colSpan || 1;
339
+ }
340
+ if (!foundCell) return;
341
+ const table = td.closest("table");
342
+ if (!table) return;
343
+ const distRight = Math.abs(event.clientX - r.right);
344
+ const distLeft = Math.abs(event.clientX - r.left);
345
+ let targetColIdx = -1;
346
+ if (distRight <= 16) {
347
+ targetColIdx = logicalStart + cellColSpan - 1;
348
+ } else if (distLeft <= 16 && logicalStart > 0) {
349
+ targetColIdx = logicalStart - 1;
350
+ } else {
351
+ return;
352
+ }
353
+ const colsList = table.querySelectorAll("colgroup col");
354
+ const totalCols = colsList.length || table.querySelector("tr")?.children.length || 0;
355
+ const allColWidths = [];
356
+ for (let c = 0; c < totalCols; c++) {
357
+ const colEl = colsList[c];
358
+ const w = colEl ? parseFloat(colEl.style.width) : 0;
359
+ allColWidths[c] = w || initialWidth(table, c);
360
+ }
361
+ const isLastCol = targetColIdx === totalCols - 1;
362
+ const neighborIdx = targetColIdx + 1;
363
+ const startX = event.clientX;
364
+ const startW = allColWidths[targetColIdx] || initialWidth(table, targetColIdx);
365
+ const startNeighborW = !isLastCol ? allColWidths[neighborIdx] || initialWidth(table, neighborIdx) : 0;
366
+ const maxContainerW = getMaxContainerWidth(table);
367
+ let otherColsW = 0;
368
+ allColWidths.forEach((w, idx) => {
369
+ if (idx !== targetColIdx) otherColsW += w;
370
+ });
371
+ const maxNwLastCol = Math.max(20, maxContainerW - otherColsW);
372
+ function updateDOMWidths() {
373
+ let totalWidth = 0;
374
+ allColWidths.forEach((w, idx) => {
375
+ const col = table.querySelector(`colgroup col:nth-child(${idx + 1})`);
376
+ if (col) col.style.setProperty("width", w + "px", "important");
377
+ table.querySelectorAll("tr").forEach(function(row) {
378
+ const cell = row.children[idx];
379
+ if (cell) {
380
+ cell.style.setProperty("width", w + "px", "important");
381
+ cell.setAttribute("width", String(w));
382
+ }
383
+ });
384
+ totalWidth += w;
385
+ });
386
+ if (totalWidth > 0) {
387
+ table.style.setProperty("width", Math.min(totalWidth, maxContainerW) + "px", "important");
388
+ }
389
+ }
390
+ event.stopPropagation();
391
+ let lastNw = startW;
392
+ const onMove = function(e) {
393
+ if (!e.buttons) {
394
+ onUp(e);
395
+ return;
396
+ }
397
+ const rawDiff = e.clientX - startX;
398
+ if (isLastCol) {
399
+ const nw = Math.min(maxNwLastCol, Math.max(20, startW + rawDiff));
400
+ allColWidths[targetColIdx] = nw;
401
+ lastNw = nw;
402
+ } else {
403
+ const delta = Math.max(20 - startW, Math.min(rawDiff, startNeighborW - 20));
404
+ allColWidths[targetColIdx] = startW + delta;
405
+ allColWidths[neighborIdx] = startNeighborW - delta;
406
+ lastNw = allColWidths[targetColIdx];
407
+ }
408
+ let borderPos = table.getBoundingClientRect().left;
409
+ for (let i = 0; i <= targetColIdx; i++) borderPos += allColWidths[i];
410
+ showLine(table, borderPos);
411
+ pauseObserver();
412
+ updateDOMWidths();
413
+ resumeObserver();
414
+ };
415
+ const onUp = function(upEvent) {
416
+ document.removeEventListener("mousemove", onMove);
417
+ document.removeEventListener("mouseup", onUp, true);
418
+ upEvent.stopPropagation();
419
+ hideLine();
420
+ if (lastNw === startW) return;
421
+ try {
422
+ const { state } = view;
423
+ const { doc } = state;
424
+ let tablePos = -1;
425
+ doc.descendants((node, pos) => {
426
+ if (tablePos >= 0) return false;
427
+ if (node.type.name === "table") {
428
+ try {
429
+ const dom = view.nodeDOM(pos);
430
+ if (dom === table || dom instanceof HTMLElement && dom.contains(table) || table.contains(dom)) {
431
+ tablePos = pos;
432
+ return false;
433
+ }
434
+ } catch (_) {
435
+ }
436
+ }
437
+ return true;
438
+ });
439
+ if (tablePos >= 0) {
440
+ const tableNode = doc.nodeAt(tablePos);
441
+ if (tableNode) {
442
+ const tr = state.tr;
443
+ tableNode.forEach((row, rowOffset) => {
444
+ let cellColIdx = 0;
445
+ row.forEach((cell, cellOffset) => {
446
+ const colspan = cell.attrs.colspan || 1;
447
+ const cellPos = tablePos + 1 + rowOffset + 1 + cellOffset;
448
+ const cw = new Array(colspan);
449
+ for (let k = 0; k < colspan; k++) {
450
+ cw[k] = allColWidths[cellColIdx + k] || 100;
451
+ }
452
+ tr.setNodeMarkup(cellPos, null, { ...cell.attrs, colwidth: cw });
453
+ cellColIdx += colspan;
454
+ });
455
+ });
456
+ view.dispatch(tr);
457
+ pauseObserver();
458
+ updateDOMWidths();
459
+ resumeObserver();
460
+ }
461
+ } else {
462
+ console.warn("[Resize] could not find table position in doc");
463
+ }
464
+ } catch (err) {
465
+ console.warn("[Resize] transaction failed, falling back to DOM:", err);
466
+ pauseObserver();
467
+ updateDOMWidths();
468
+ resumeObserver();
469
+ }
470
+ };
471
+ document.addEventListener("mousemove", onMove);
472
+ document.addEventListener("mouseup", onUp, true);
473
+ };
474
+ function initialWidth(table, colIdx) {
475
+ const firstRow = table.querySelector("tr");
476
+ if (!firstRow) return 100;
477
+ const cell = firstRow.children[colIdx];
478
+ if (!cell) return 100;
479
+ return Math.round(cell.getBoundingClientRect().width) || cell.offsetWidth || 100;
480
+ }
481
+ let lineEl = null;
482
+ let isDragging = false;
483
+ function getOrCreateLine() {
484
+ if (!lineEl) {
485
+ lineEl = document.createElement("div");
486
+ lineEl.className = "docflow-active-border-line";
487
+ Object.assign(lineEl.style, {
488
+ position: "fixed",
489
+ width: "3px",
490
+ background: "#06b6d4",
491
+ boxShadow: "0 0 8px rgba(6, 182, 212, 0.9)",
492
+ pointerEvents: "none",
493
+ zIndex: "999999",
494
+ display: "none",
495
+ borderRadius: "1.5px"
496
+ });
497
+ const dotTop = document.createElement("div");
498
+ Object.assign(dotTop.style, {
499
+ position: "absolute",
500
+ top: "-4px",
501
+ left: "-3.5px",
502
+ width: "10px",
503
+ height: "10px",
504
+ borderRadius: "50%",
505
+ background: "#ffffff",
506
+ border: "2px solid #06b6d4"
507
+ });
508
+ const dotBottom = document.createElement("div");
509
+ Object.assign(dotBottom.style, {
510
+ position: "absolute",
511
+ bottom: "-4px",
512
+ left: "-3.5px",
513
+ width: "10px",
514
+ height: "10px",
515
+ borderRadius: "50%",
516
+ background: "#ffffff",
517
+ border: "2px solid #06b6d4"
518
+ });
519
+ lineEl.appendChild(dotTop);
520
+ lineEl.appendChild(dotBottom);
521
+ document.body.appendChild(lineEl);
522
+ }
523
+ return lineEl;
524
+ }
525
+ function showLine(table, borderX) {
526
+ const line = getOrCreateLine();
527
+ const tableRect = table.getBoundingClientRect();
528
+ line.style.left = `${borderX - 1.5}px`;
529
+ line.style.top = `${tableRect.top}px`;
530
+ line.style.height = `${tableRect.height}px`;
531
+ line.style.display = "block";
532
+ document.body.style.cursor = "col-resize";
533
+ view.dom.style.cursor = "col-resize";
534
+ }
535
+ function hideLine() {
536
+ if (lineEl) {
537
+ lineEl.style.display = "none";
538
+ }
539
+ document.body.style.cursor = "";
540
+ view.dom.style.cursor = "";
541
+ }
542
+ const onMouseMoveHover = function(event) {
543
+ if (isDragging) return;
544
+ const target = event.target;
545
+ const td = target.closest("td, th");
546
+ if (!td) {
547
+ hideLine();
548
+ return;
549
+ }
550
+ const r = td.getBoundingClientRect();
551
+ const distRight = Math.abs(event.clientX - r.right);
552
+ const distLeft = Math.abs(event.clientX - r.left);
553
+ const parent = td.parentElement;
554
+ if (!parent) {
555
+ hideLine();
556
+ return;
557
+ }
558
+ const colIdx = Array.from(parent.children).indexOf(td);
559
+ let borderX = -1;
560
+ if (distRight <= 16) {
561
+ borderX = r.right;
562
+ } else if (distLeft <= 16 && colIdx > 0) {
563
+ borderX = r.left;
564
+ }
565
+ if (borderX >= 0) {
566
+ const table = td.closest("table");
567
+ if (table) {
568
+ showLine(table, borderX);
569
+ }
570
+ } else {
571
+ hideLine();
572
+ }
573
+ };
574
+ document.addEventListener("mousemove", onMouseMoveHover, true);
575
+ view.dom.addEventListener("mousedown", function handleMouseDown(event) {
576
+ onMouseDown(event);
577
+ const td = event.target.closest("td, th");
578
+ if (!td) return;
579
+ const r = td.getBoundingClientRect();
580
+ const distRight = Math.abs(event.clientX - r.right);
581
+ const distLeft = Math.abs(event.clientX - r.left);
582
+ const parent = td.parentElement;
583
+ if (!parent) return;
584
+ const colIdx = Array.from(parent.children).indexOf(td);
585
+ if (distRight <= 16 || distLeft <= 16 && colIdx > 0) {
586
+ isDragging = true;
587
+ hideLine();
588
+ const onDragEnd = function() {
589
+ isDragging = false;
590
+ hideLine();
591
+ document.removeEventListener("mouseup", onDragEnd, true);
592
+ };
593
+ document.addEventListener("mouseup", onDragEnd, true);
594
+ }
595
+ }, true);
596
+ return {
597
+ destroy: function() {
598
+ document.removeEventListener("mousemove", onMouseMoveHover, true);
599
+ if (lineEl && lineEl.parentElement) {
600
+ lineEl.parentElement.removeChild(lineEl);
601
+ }
602
+ lineEl = null;
603
+ hideLine();
604
+ }
605
+ };
606
+ }
607
+ })];
608
+ }
609
+ });
610
+
611
+ // src/SearchAndReplace.ts
612
+ import { Extension as Extension4 } from "@tiptap/core";
613
+ import { Plugin as Plugin3, PluginKey as PluginKey3, TextSelection } from "@tiptap/pm/state";
193
614
  import { Decoration as Decoration2, DecorationSet as DecorationSet2 } from "@tiptap/pm/view";
194
- var searchAndReplaceKey = new PluginKey2("searchAndReplace");
615
+ var searchAndReplaceKey = new PluginKey3("searchAndReplace");
195
616
  var EMPTY_STATE = { query: "", matches: [], activeIndex: 0 };
196
617
  function findMatches(doc, query) {
197
618
  const matches = [];
@@ -216,7 +637,7 @@ function computeState(doc, query, activeIndex = 0) {
216
637
  const matches = findMatches(doc, query);
217
638
  return { query, matches, activeIndex: clampIndex(activeIndex, matches) };
218
639
  }
219
- var searchPlugin = new Plugin2({
640
+ var searchPlugin = new Plugin3({
220
641
  key: searchAndReplaceKey,
221
642
  state: {
222
643
  init: () => EMPTY_STATE,
@@ -248,7 +669,7 @@ var searchPlugin = new Plugin2({
248
669
  }
249
670
  }
250
671
  });
251
- var SearchAndReplaceExtension = Extension3.create({
672
+ var SearchAndReplaceExtension = Extension4.create({
252
673
  name: "searchAndReplace",
253
674
  addProseMirrorPlugins() {
254
675
  return [searchPlugin];
@@ -305,13 +726,13 @@ function replaceAll(editor, replacement) {
305
726
  return s.matches.length;
306
727
  }
307
728
 
308
- // src/pagination/PaginationPlus.ts
309
- import { Extension as Extension4 } from "@tiptap/core";
310
- import { Plugin as Plugin3, PluginKey as PluginKey3 } from "@tiptap/pm/state";
729
+ // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js
730
+ import { Extension as Extension5 } from "@tiptap/core";
731
+ import { Plugin as Plugin4, PluginKey as PluginKey4 } from "@tiptap/pm/state";
311
732
  import { ReplaceStep, ReplaceAroundStep, AddMarkStep, RemoveMarkStep, RemoveNodeMarkStep, AttrStep } from "@tiptap/pm/transform";
312
733
  import { Decoration as Decoration3, DecorationSet as DecorationSet3 } from "@tiptap/pm/view";
313
734
 
314
- // src/pagination/utils.ts
735
+ // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/utils.js
315
736
  var updateCssVariables = (targetNode, config) => {
316
737
  const cssVariables = {
317
738
  "rm-page-height": `${config.pageHeight}px`,
@@ -338,32 +759,75 @@ var getPageSize = (height, width, marginTop, marginBottom, marginLeft, marginRig
338
759
  marginRight
339
760
  };
340
761
  };
341
- var getHeaderHeightSelector = (pageNumber, type) => {
342
- return type === "actual" ? `.rm-page-header-${pageNumber}` : `.rm-page-header-${pageNumber} .rm-page-header-content`;
343
- };
344
762
  var getHeaderHeight = (targetNode, pageNumbers, type) => {
345
763
  const headerHeightMap = /* @__PURE__ */ new Map();
346
764
  const clientHeader = targetNode.querySelector(getHeaderHeightSelector(0, type));
347
765
  headerHeightMap.set(0, clientHeader ? clientHeader.clientHeight : 0);
348
766
  pageNumbers.forEach((pageNumber) => {
349
- const ch = targetNode.querySelector(getHeaderHeightSelector(pageNumber, type));
350
- headerHeightMap.set(pageNumber, ch ? ch.clientHeight : 0);
767
+ const clientHeader2 = targetNode.querySelector(getHeaderHeightSelector(pageNumber, type));
768
+ const headerHeight = clientHeader2 ? clientHeader2.clientHeight : 0;
769
+ headerHeightMap.set(pageNumber, headerHeight);
351
770
  });
352
771
  return headerHeightMap;
353
772
  };
354
- var getFooterHeightSelector = (pageNumber, type) => {
355
- return type === "actual" ? `.rm-page-footer-${pageNumber}` : `.rm-page-footer-${pageNumber} .rm-page-footer-content`;
773
+ var getHeaderHeightSelector = (pageNumber, type) => {
774
+ return type === "actual" ? `.rm-page-header-${pageNumber}` : `.rm-page-header-${pageNumber} .rm-page-header-content`;
356
775
  };
357
776
  var getFooterHeight = (targetNode, pageNumbers, type) => {
358
777
  const footerHeightMap = /* @__PURE__ */ new Map();
359
778
  const clientFooter = targetNode.querySelector(getFooterHeightSelector(0, type));
360
779
  footerHeightMap.set(0, clientFooter ? clientFooter.clientHeight : 0);
361
780
  pageNumbers.forEach((pageNumber) => {
362
- const cf = targetNode.querySelector(getFooterHeightSelector(pageNumber, type));
363
- footerHeightMap.set(pageNumber, cf ? cf.clientHeight : 0);
781
+ const clientFooter2 = targetNode.querySelector(getFooterHeightSelector(pageNumber, type));
782
+ const footerHeight = clientFooter2 ? clientFooter2.clientHeight : 0;
783
+ footerHeightMap.set(pageNumber, footerHeight);
364
784
  });
365
785
  return footerHeightMap;
366
786
  };
787
+ var getFooterHeightSelector = (pageNumber, type) => {
788
+ return type === "actual" ? `.rm-page-footer-${pageNumber}` : `.rm-page-footer-${pageNumber} .rm-page-footer-content`;
789
+ };
790
+ function deepEqualIterative(a, b) {
791
+ if (a === b)
792
+ return true;
793
+ if (typeof a !== "object" || typeof b !== "object" || a == null || b == null) {
794
+ return false;
795
+ }
796
+ const stack = [{ x: a, y: b }];
797
+ while (stack.length) {
798
+ const _stackItem = stack.pop();
799
+ if (!_stackItem)
800
+ continue;
801
+ const { x, y } = _stackItem;
802
+ if (x === y)
803
+ continue;
804
+ if (typeof x !== typeof y)
805
+ return false;
806
+ if (typeof x !== "object")
807
+ return false;
808
+ if (x == null || y == null)
809
+ return false;
810
+ const xKeys = Object.keys(x);
811
+ const yKeys = Object.keys(y);
812
+ if (xKeys.length !== yKeys.length)
813
+ return false;
814
+ for (const key2 of xKeys) {
815
+ if (!(key2 in y))
816
+ return false;
817
+ const xVal = x[key2];
818
+ const yVal = y[key2];
819
+ if (xVal === yVal)
820
+ continue;
821
+ if (typeof xVal === "object" && typeof yVal === "object") {
822
+ stack.push({ x: xVal, y: yVal });
823
+ } else {
824
+ if (xVal !== yVal)
825
+ return false;
826
+ }
827
+ }
828
+ }
829
+ return true;
830
+ }
367
831
  function getCustomPages(customHeader, customFooter) {
368
832
  return [...Object.keys(customHeader), ...Object.keys(customFooter)].map(Number);
369
833
  }
@@ -378,8 +842,8 @@ function getFooter(footerRightContent, footerLeftContent, onFooterClick, pageNum
378
842
  pageFooterContent.classList.add("rm-page-footer-content");
379
843
  pageFooterContent.style.width = "100%";
380
844
  pageFooterContent.style.overflow = "hidden";
381
- const footerRight = (footerRightContent || "").replace("{page}", `<span class="rm-page-number"></span>`);
382
- const footerLeft = (footerLeftContent || "").replace("{page}", `<span class="rm-page-number"></span>`);
845
+ const footerRight = footerRightContent.replace("{page}", `<span class="rm-page-number"></span>`);
846
+ const footerLeft = footerLeftContent.replace("{page}", `<span class="rm-page-number"></span>`);
383
847
  const pageFooterLeft = document.createElement("div");
384
848
  pageFooterLeft.classList.add("rm-page-footer-left");
385
849
  pageFooterLeft.innerHTML = footerLeft;
@@ -402,8 +866,8 @@ function getHeader(headerRightContent, headerLeftContent, onHeaderClick, pageNum
402
866
  pageHeaderContent.classList.add("rm-page-header-content");
403
867
  pageHeaderContent.style.width = "100%";
404
868
  pageHeaderContent.style.overflow = "hidden";
405
- const headerLeft = (headerLeftContent || "").replace("{page}", `<span class="rm-page-number-plus"></span>`);
406
- const headerRight = (headerRightContent || "").replace("{page}", `<span class="rm-page-number-plus"></span>`);
869
+ const headerLeft = headerLeftContent.replace("{page}", `<span class="rm-page-number-plus"></span>`);
870
+ const headerRight = headerRightContent.replace("{page}", `<span class="rm-page-number-plus"></span>`);
407
871
  const pageHeaderLeft = document.createElement("div");
408
872
  pageHeaderLeft.classList.add("rm-page-header-left");
409
873
  pageHeaderLeft.innerHTML = headerLeft;
@@ -427,40 +891,24 @@ var getHeight = (pageOptions, _headerHeight, _footerHeight) => {
427
891
  };
428
892
  var headerClickEvent = (pageNumber, onHeaderClick) => {
429
893
  return (event) => {
430
- onHeaderClick?.({ event, pageNumber });
894
+ onHeaderClick === null || onHeaderClick === void 0 ? void 0 : onHeaderClick({
895
+ event,
896
+ pageNumber
897
+ });
431
898
  };
432
899
  };
433
900
  var footerClickEvent = (pageNumber, onFooterClick) => {
434
901
  return (event) => {
435
- onFooterClick?.({ event, pageNumber });
902
+ onFooterClick === null || onFooterClick === void 0 ? void 0 : onFooterClick({
903
+ event,
904
+ pageNumber
905
+ });
436
906
  };
437
907
  };
438
908
 
439
- // src/pagination/pageCount.ts
440
- var MAX_PAGES = 1e3;
441
- function grownPageCount(input) {
442
- const { currentPageCount, lastPageGap, pageContentAreaHeight, maxPagesByContent } = input;
443
- if (!(lastPageGap > 0) || !(pageContentAreaHeight > 0)) {
444
- return currentPageCount;
445
- }
446
- const addPage = Math.ceil(lastPageGap / pageContentAreaHeight);
447
- if (!Number.isFinite(addPage) || addPage <= 0) {
448
- return currentPageCount;
449
- }
450
- const contentCap = Math.max(currentPageCount, maxPagesByContent + 1);
451
- const desired = currentPageCount + addPage;
452
- if (desired > contentCap) {
453
- return contentCap;
454
- }
455
- if (desired > MAX_PAGES) {
456
- return currentPageCount;
457
- }
458
- return desired;
459
- }
460
-
461
- // src/pagination/PaginationPlus.ts
909
+ // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js
462
910
  var page_count_meta_key = "PAGE_COUNT_META_KEY";
463
- var key = new PluginKey3("brDecoration");
911
+ var key = new PluginKey4("brDecoration");
464
912
  function buildDecorations(doc) {
465
913
  const decorations = [];
466
914
  doc.descendants((node, pos) => {
@@ -478,7 +926,7 @@ function buildDecorations(doc) {
478
926
  }
479
927
  var defaultPageConfig = {
480
928
  enabled: true,
481
- pageBreakBackground: "#f1f5f9",
929
+ pageBreakBackground: "#ffffff",
482
930
  pageHeight: 800,
483
931
  pageWidth: 789,
484
932
  marginTop: 20,
@@ -495,17 +943,14 @@ var defaultPageConfig = {
495
943
  customHeader: {},
496
944
  customFooter: {}
497
945
  };
498
- var defaultOptions = {
499
- pageGapBorderSize: 1,
500
- pageGapBorderColor: "#e5e5e5",
501
- ...defaultPageConfig
502
- };
946
+ var defaultOptions = Object.assign({ pageGapBorderSize: 1, pageGapBorderColor: "#e5e5e5" }, defaultPageConfig);
503
947
  var refreshPage = (targetNode, paginationEnabled = true) => {
948
+ var _a;
504
949
  const paginationElement = targetNode.querySelector("[data-rm-pagination]");
505
950
  if (paginationEnabled) {
506
951
  targetNode.removeAttribute("rm-pagination-disabled");
507
952
  if (paginationElement) {
508
- const lastPageBreak = paginationElement.lastElementChild?.querySelector(".breaker");
953
+ const lastPageBreak = (_a = paginationElement.lastElementChild) === null || _a === void 0 ? void 0 : _a.querySelector(".breaker");
509
954
  if (lastPageBreak) {
510
955
  const minHeight = lastPageBreak.offsetTop + lastPageBreak.offsetHeight;
511
956
  targetNode.style.minHeight = `calc(${minHeight}px + 2px)`;
@@ -513,305 +958,65 @@ var refreshPage = (targetNode, paginationEnabled = true) => {
513
958
  }
514
959
  } else {
515
960
  targetNode.setAttribute("rm-pagination-disabled", "");
516
- targetNode.style.minHeight = "auto";
961
+ targetNode.style.minHeight = `auto`;
517
962
  }
518
963
  };
519
964
  var getPageConfig = (_storage, _currentOptions) => {
965
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
520
966
  const pageConfig = {
521
- enabled: _storage.enabled ?? defaultOptions.enabled,
522
- pageBreakBackground: _storage.pageBreakBackground ?? defaultOptions.pageBreakBackground,
523
- pageHeight: _storage.pageHeight ?? defaultOptions.pageHeight,
524
- pageWidth: _storage.pageWidth ?? defaultPageConfig.pageWidth,
525
- marginTop: _storage.marginTop ?? defaultPageConfig.marginTop,
526
- marginBottom: _storage.marginBottom ?? defaultPageConfig.marginBottom,
527
- marginLeft: _storage.marginLeft ?? defaultPageConfig.marginLeft,
528
- marginRight: _storage.marginRight ?? defaultPageConfig.marginRight,
529
- pageGap: _storage.pageGap ?? defaultPageConfig.pageGap,
530
- contentMarginTop: _storage.contentMarginTop ?? defaultPageConfig.contentMarginTop,
531
- contentMarginBottom: _storage.contentMarginBottom ?? defaultPageConfig.contentMarginBottom,
532
- footerRight: _storage.footerRight ?? defaultPageConfig.footerRight,
533
- footerLeft: _storage.footerLeft ?? defaultPageConfig.footerLeft,
534
- headerRight: _storage.headerRight ?? defaultPageConfig.headerRight,
535
- headerLeft: _storage.headerLeft ?? defaultPageConfig.headerLeft,
536
- customHeader: _storage.customHeader ?? defaultPageConfig.customHeader,
537
- customFooter: _storage.customFooter ?? defaultPageConfig.customFooter
967
+ enabled: (_a = _storage.enabled) !== null && _a !== void 0 ? _a : defaultOptions.enabled,
968
+ pageBreakBackground: (_b = _storage.pageBreakBackground) !== null && _b !== void 0 ? _b : defaultOptions.pageBreakBackground,
969
+ pageHeight: (_c = _storage.pageHeight) !== null && _c !== void 0 ? _c : defaultOptions.pageHeight,
970
+ pageWidth: (_d = _storage.pageWidth) !== null && _d !== void 0 ? _d : defaultPageConfig.pageWidth,
971
+ marginTop: (_e = _storage.marginTop) !== null && _e !== void 0 ? _e : defaultPageConfig.marginTop,
972
+ marginBottom: (_f = _storage.marginBottom) !== null && _f !== void 0 ? _f : defaultPageConfig.marginBottom,
973
+ marginLeft: (_g = _storage.marginLeft) !== null && _g !== void 0 ? _g : defaultPageConfig.marginLeft,
974
+ marginRight: (_h = _storage.marginRight) !== null && _h !== void 0 ? _h : defaultPageConfig.marginRight,
975
+ pageGap: (_j = _storage.pageGap) !== null && _j !== void 0 ? _j : defaultPageConfig.pageGap,
976
+ contentMarginTop: (_k = _storage.contentMarginTop) !== null && _k !== void 0 ? _k : defaultPageConfig.contentMarginTop,
977
+ contentMarginBottom: (_l = _storage.contentMarginBottom) !== null && _l !== void 0 ? _l : defaultPageConfig.contentMarginBottom,
978
+ footerRight: (_m = _storage.footerRight) !== null && _m !== void 0 ? _m : defaultPageConfig.footerRight,
979
+ footerLeft: (_o = _storage.footerLeft) !== null && _o !== void 0 ? _o : defaultPageConfig.footerLeft,
980
+ headerRight: (_p = _storage.headerRight) !== null && _p !== void 0 ? _p : defaultPageConfig.headerRight,
981
+ headerLeft: (_q = _storage.headerLeft) !== null && _q !== void 0 ? _q : defaultPageConfig.headerLeft,
982
+ customHeader: (_r = _storage.customHeader) !== null && _r !== void 0 ? _r : defaultPageConfig.customHeader,
983
+ customFooter: (_s = _storage.customFooter) !== null && _s !== void 0 ? _s : defaultPageConfig.customFooter
538
984
  };
539
985
  return {
540
986
  config: pageConfig,
541
- options: { ..._currentOptions, ...pageConfig }
987
+ options: Object.assign(Object.assign({}, _currentOptions), pageConfig)
542
988
  };
543
989
  };
544
990
  var getPageConfigFromOptions = (_currentOptions) => {
991
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
545
992
  return {
546
- enabled: _currentOptions.enabled ?? defaultOptions.enabled,
547
- pageBreakBackground: _currentOptions.pageBreakBackground ?? defaultOptions.pageBreakBackground,
548
- pageHeight: _currentOptions.pageHeight ?? defaultOptions.pageHeight,
549
- pageWidth: _currentOptions.pageWidth ?? defaultPageConfig.pageWidth,
550
- marginTop: _currentOptions.marginTop ?? defaultPageConfig.marginTop,
551
- marginBottom: _currentOptions.marginBottom ?? defaultPageConfig.marginBottom,
552
- marginLeft: _currentOptions.marginLeft ?? defaultPageConfig.marginLeft,
553
- marginRight: _currentOptions.marginRight ?? defaultPageConfig.marginRight,
554
- pageGap: _currentOptions.pageGap ?? defaultPageConfig.pageGap,
555
- contentMarginTop: _currentOptions.contentMarginTop ?? defaultPageConfig.contentMarginTop,
556
- contentMarginBottom: _currentOptions.contentMarginBottom ?? defaultPageConfig.contentMarginBottom,
557
- footerRight: _currentOptions.footerRight ?? defaultPageConfig.footerRight,
558
- footerLeft: _currentOptions.footerLeft ?? defaultPageConfig.footerLeft,
559
- headerRight: _currentOptions.headerRight ?? defaultPageConfig.headerRight,
560
- headerLeft: _currentOptions.headerLeft ?? defaultPageConfig.headerLeft,
561
- customHeader: _currentOptions.customHeader ?? defaultPageConfig.customHeader,
562
- customFooter: _currentOptions.customFooter ?? defaultPageConfig.customFooter
993
+ enabled: (_a = _currentOptions.enabled) !== null && _a !== void 0 ? _a : defaultOptions.enabled,
994
+ pageBreakBackground: (_b = _currentOptions.pageBreakBackground) !== null && _b !== void 0 ? _b : defaultOptions.pageBreakBackground,
995
+ pageHeight: (_c = _currentOptions.pageHeight) !== null && _c !== void 0 ? _c : defaultOptions.pageHeight,
996
+ pageWidth: (_d = _currentOptions.pageWidth) !== null && _d !== void 0 ? _d : defaultPageConfig.pageWidth,
997
+ marginTop: (_e = _currentOptions.marginTop) !== null && _e !== void 0 ? _e : defaultPageConfig.marginTop,
998
+ marginBottom: (_f = _currentOptions.marginBottom) !== null && _f !== void 0 ? _f : defaultPageConfig.marginBottom,
999
+ marginLeft: (_g = _currentOptions.marginLeft) !== null && _g !== void 0 ? _g : defaultPageConfig.marginLeft,
1000
+ marginRight: (_h = _currentOptions.marginRight) !== null && _h !== void 0 ? _h : defaultPageConfig.marginRight,
1001
+ pageGap: (_j = _currentOptions.pageGap) !== null && _j !== void 0 ? _j : defaultPageConfig.pageGap,
1002
+ contentMarginTop: (_k = _currentOptions.contentMarginTop) !== null && _k !== void 0 ? _k : defaultPageConfig.contentMarginTop,
1003
+ contentMarginBottom: (_l = _currentOptions.contentMarginBottom) !== null && _l !== void 0 ? _l : defaultPageConfig.contentMarginBottom,
1004
+ footerRight: (_m = _currentOptions.footerRight) !== null && _m !== void 0 ? _m : defaultPageConfig.footerRight,
1005
+ footerLeft: (_o = _currentOptions.footerLeft) !== null && _o !== void 0 ? _o : defaultPageConfig.footerLeft,
1006
+ headerRight: (_p = _currentOptions.headerRight) !== null && _p !== void 0 ? _p : defaultPageConfig.headerRight,
1007
+ headerLeft: (_q = _currentOptions.headerLeft) !== null && _q !== void 0 ? _q : defaultPageConfig.headerLeft,
1008
+ customHeader: (_r = _currentOptions.customHeader) !== null && _r !== void 0 ? _r : defaultPageConfig.customHeader,
1009
+ customFooter: (_s = _currentOptions.customFooter) !== null && _s !== void 0 ? _s : defaultPageConfig.customFooter
563
1010
  };
564
1011
  };
565
- var paginationKey = new PluginKey3("pagination");
566
- var getExistingPageCount = (view) => {
567
- const editorDom = view.dom;
568
- const paginationElement = editorDom.querySelector("[data-rm-pagination]");
569
- if (paginationElement) {
570
- return paginationElement.children.length;
571
- }
572
- return 0;
573
- };
574
- var lastContentChild = (editorDom) => {
575
- for (let i = editorDom.children.length - 1; i >= 0; i--) {
576
- const child = editorDom.children[i];
577
- if (!(child instanceof HTMLElement)) continue;
578
- if (child.hasAttribute("data-rm-pagination")) continue;
579
- if (child.classList.contains("rm-page-break")) continue;
580
- return child;
581
- }
582
- return null;
583
- };
584
- var pageGapTracker = /* @__PURE__ */ new WeakMap();
585
- var calculatePageCount = (view, pageOptions, headerHeight = 0, footerHeight = 0) => {
586
- const editorDom = view.dom;
587
- const _pageHeaderHeight = pageOptions.contentMarginTop + pageOptions.marginTop + headerHeight;
588
- const _pageFooterHeight = pageOptions.contentMarginBottom + pageOptions.marginBottom + footerHeight;
589
- const pageContentAreaHeight = pageOptions.pageHeight - _pageHeaderHeight - _pageFooterHeight;
590
- const paginationElement = editorDom.querySelector("[data-rm-pagination]");
591
- const currentPageCount = getExistingPageCount(view);
592
- if (paginationElement) {
593
- const lastElementOfEditor = lastContentChild(editorDom);
594
- const lastPageBreak = paginationElement.lastElementChild?.querySelector(".breaker");
595
- if (lastElementOfEditor && lastPageBreak) {
596
- const lastElementRect = lastElementOfEditor.getBoundingClientRect();
597
- const lastPageBreakRect = lastPageBreak.getBoundingClientRect();
598
- const lastPageGap = lastElementRect.bottom - lastPageBreakRect.bottom;
599
- if (lastPageGap > 0) {
600
- const addPage = Math.ceil(lastPageGap / pageContentAreaHeight);
601
- let totalEditorContentHeight = 0;
602
- for (const child of Array.from(editorDom.children)) {
603
- if (!(child instanceof HTMLElement)) continue;
604
- if (child.hasAttribute("data-rm-pagination")) continue;
605
- if (child.classList.contains("rm-page-break")) continue;
606
- totalEditorContentHeight += child.getBoundingClientRect().height;
607
- }
608
- const maxPagesByContent = Math.ceil(totalEditorContentHeight / pageContentAreaHeight);
609
- const prev = pageGapTracker.get(editorDom);
610
- if (prev && prev.pages < currentPageCount && lastPageGap > prev.gap - 2 && currentPageCount >= maxPagesByContent) {
611
- return currentPageCount;
612
- }
613
- const recent = prev?.recent ?? [];
614
- let flapping = prev?.flapping ?? [];
615
- if (recent.length >= 4 && recent.filter((p) => p === currentPageCount + addPage).length >= 2 && currentPageCount >= maxPagesByContent) {
616
- flapping = [.../* @__PURE__ */ new Set([...flapping, currentPageCount + addPage, currentPageCount])];
617
- pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount, recent, flapping });
618
- return currentPageCount;
619
- }
620
- pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount, recent, flapping });
621
- return grownPageCount({
622
- currentPageCount,
623
- lastPageGap,
624
- pageContentAreaHeight,
625
- maxPagesByContent
626
- });
627
- } else {
628
- const allBreaksAfterLastElement = Array.from(paginationElement.querySelectorAll(".breaker"));
629
- const allBreaksAfterLastElementRect = allBreaksAfterLastElement.filter(
630
- (element) => element.getBoundingClientRect().top > lastElementRect.bottom
631
- );
632
- const removePage = allBreaksAfterLastElementRect.length;
633
- if (removePage > 1) {
634
- return currentPageCount - (removePage - 1);
635
- } else {
636
- return currentPageCount;
637
- }
638
- }
639
- }
640
- return 1;
641
- } else {
642
- const editorHeight = editorDom.scrollHeight;
643
- let pageCount = Math.ceil(editorHeight / pageContentAreaHeight);
644
- pageCount = pageCount <= 0 ? 1 : pageCount;
645
- return pageCount;
646
- }
647
- };
648
- var getNewPageCount = (view, pageOptions) => {
649
- if (pageOptions.enabled) {
650
- const pageCount = calculatePageCount(view, pageOptions);
651
- return pageCount <= 1 ? 1 : pageCount;
652
- } else return 0;
653
- };
654
- function createDecoration(pageOptions, headerHeightMap, footerHeightMap) {
655
- if (!pageOptions.enabled) return [];
656
- const commonHeaderOptions = {
657
- headerLeft: pageOptions.headerLeft,
658
- headerRight: pageOptions.headerRight
659
- };
660
- const commonFooterOptions = {
661
- footerLeft: pageOptions.footerLeft,
662
- footerRight: pageOptions.footerRight
663
- };
664
- return [
665
- Decoration3.widget(
666
- 0,
667
- (view) => {
668
- const _pageGap = pageOptions.pageGap;
669
- const _pageBreakBackground = pageOptions.pageBreakBackground;
670
- const el = document.createElement("div");
671
- el.dataset.rmPagination = "true";
672
- const pageBreakDefinition = (firstPage, pageHeader, pageFooter, headerHeight, footerHeight, pageNumber) => {
673
- const { _pageHeaderHeight, _pageHeight } = getHeight(pageOptions, headerHeight, footerHeight);
674
- const pageContainer = document.createElement("div");
675
- pageContainer.classList.add("rm-page-break");
676
- const page = document.createElement("div");
677
- page.classList.add("page");
678
- page.style.position = "relative";
679
- page.style.float = "left";
680
- page.style.clear = "both";
681
- const marginTop = firstPage ? `calc(${_pageHeaderHeight}px + ${_pageHeight}px)` : _pageHeight + "px";
682
- if (pageNumber) {
683
- page.style.marginTop = `var(--rm-page-content-${pageNumber}, ${marginTop})`;
684
- } else {
685
- page.style.marginTop = firstPage ? `var(--rm-page-content-first, ${marginTop})` : `var(--rm-page-content-general, ${marginTop})`;
686
- }
687
- const pageBreak = document.createElement("div");
688
- pageBreak.classList.add("breaker");
689
- pageBreak.style.width = `calc(100% + var(--rm-margin-left) + var(--rm-margin-right))`;
690
- pageBreak.style.marginLeft = `calc(-1 * var(--rm-margin-left))`;
691
- pageBreak.style.marginRight = `calc(-1 * var(--rm-margin-right))`;
692
- pageBreak.style.position = "relative";
693
- pageBreak.style.float = "left";
694
- pageBreak.style.clear = "both";
695
- pageBreak.style.left = "0px";
696
- pageBreak.style.right = "0px";
697
- pageBreak.style.zIndex = "2";
698
- const pageSpace = document.createElement("div");
699
- pageSpace.classList.add("rm-pagination-gap");
700
- pageSpace.style.height = _pageGap + "px";
701
- pageSpace.style.borderLeft = "1px solid";
702
- pageSpace.style.borderRight = "1px solid";
703
- pageSpace.style.position = "relative";
704
- pageSpace.style.setProperty("width", "calc(100% + 2px)", "important");
705
- pageSpace.style.left = "-1px";
706
- pageSpace.style.backgroundColor = _pageBreakBackground;
707
- pageSpace.style.borderLeftColor = _pageBreakBackground;
708
- pageSpace.style.borderRightColor = _pageBreakBackground;
709
- pageBreak.append(pageFooter, pageSpace, pageHeader);
710
- pageContainer.append(page, pageBreak);
711
- return pageContainer;
712
- };
713
- const _headerHeight = headerHeightMap.get(0) || 0;
714
- const _footerHeight = footerHeightMap.get(0) || 0;
715
- const fragment = document.createDocumentFragment();
716
- const pageCount = getNewPageCount(view, pageOptions);
717
- for (let i = 0; i < pageCount; i++) {
718
- const pageNumber = i + 1;
719
- const headerPageNumber = i + 2;
720
- if (headerPageNumber in pageOptions.customHeader || pageNumber in pageOptions.customFooter || pageNumber in pageOptions.customHeader) {
721
- let _headerOptions = commonHeaderOptions;
722
- let _footerOptions = commonFooterOptions;
723
- let _pageHeaderHeight = _headerHeight;
724
- let _pageFooterHeight = _footerHeight;
725
- if (headerPageNumber in pageOptions.customHeader) {
726
- _headerOptions = pageOptions.customHeader[headerPageNumber] || commonHeaderOptions;
727
- _pageHeaderHeight = headerHeightMap.get(headerPageNumber) || 0;
728
- }
729
- if (pageNumber in pageOptions.customFooter) {
730
- _footerOptions = pageOptions.customFooter[pageNumber] || commonFooterOptions;
731
- _pageFooterHeight = footerHeightMap.get(pageNumber) || 0;
732
- }
733
- const _pageHeader = getHeader(
734
- _headerOptions.headerRight,
735
- _headerOptions.headerLeft,
736
- headerClickEvent(headerPageNumber, pageOptions.onHeaderClick),
737
- headerPageNumber
738
- );
739
- const _pageFooter = getFooter(
740
- _footerOptions.footerRight,
741
- _footerOptions.footerLeft,
742
- footerClickEvent(pageNumber, pageOptions.onFooterClick),
743
- pageNumber
744
- );
745
- const pageBreak = pageBreakDefinition(
746
- i === 0,
747
- _pageHeader,
748
- _pageFooter,
749
- _pageHeaderHeight,
750
- _pageFooterHeight,
751
- pageNumber
752
- );
753
- fragment.appendChild(pageBreak);
754
- } else {
755
- const __pageHeader = getHeader(
756
- commonHeaderOptions.headerRight,
757
- commonHeaderOptions.headerLeft,
758
- headerClickEvent(headerPageNumber, pageOptions.onHeaderClick)
759
- );
760
- const __pageFooter = getFooter(
761
- commonFooterOptions.footerRight,
762
- commonFooterOptions.footerLeft,
763
- footerClickEvent(pageNumber, pageOptions.onFooterClick)
764
- );
765
- fragment.appendChild(pageBreakDefinition(i === 0, __pageHeader, __pageFooter, _headerHeight, _footerHeight));
766
- }
767
- }
768
- el.append(fragment);
769
- el.id = "pages";
770
- el.classList.add("rm-pages-wrapper");
771
- return el;
772
- },
773
- { side: -1 }
774
- ),
775
- Decoration3.widget(
776
- 0,
777
- () => {
778
- const pageNumber = 1;
779
- let _headerOptions = commonHeaderOptions;
780
- if (pageNumber in pageOptions.customHeader) {
781
- _headerOptions = pageOptions.customHeader[pageNumber];
782
- }
783
- const el = getHeader(
784
- _headerOptions.headerRight,
785
- _headerOptions.headerLeft,
786
- headerClickEvent(pageNumber, pageOptions.onHeaderClick)
787
- );
788
- el.classList.add("rm-first-page-header");
789
- return el;
790
- },
791
- { side: -1 }
792
- )
793
- ];
794
- }
795
- var PAGE_SIZES = {
796
- A4: getPageSize(1123, 794, 95, 95, 76, 76),
797
- A3: getPageSize(1591, 1123, 95, 95, 76, 76),
798
- A5: getPageSize(794, 419, 76, 76, 57, 57),
799
- LETTER: getPageSize(1060, 818, 96, 96, 96, 96),
800
- LEGAL: getPageSize(1404, 818, 96, 96, 96, 96),
801
- TABLOID: getPageSize(1635, 1060, 96, 96, 96, 96)
802
- };
803
- var PaginationPlus = Extension4.create({
1012
+ var paginationKey = new PluginKey4("pagination");
1013
+ var PaginationPlus = Extension5.create({
804
1014
  name: "PaginationPlus",
805
1015
  addOptions() {
806
1016
  return defaultOptions;
807
1017
  },
808
1018
  addStorage() {
809
- return {
810
- ...defaultOptions,
811
- headerHeight: /* @__PURE__ */ new Map(),
812
- footerHeight: /* @__PURE__ */ new Map(),
813
- appliedConfig: defaultPageConfig
814
- };
1019
+ return Object.assign(Object.assign({}, defaultOptions), { headerHeight: /* @__PURE__ */ new Map(), footerHeight: /* @__PURE__ */ new Map(), appliedConfig: defaultPageConfig });
815
1020
  },
816
1021
  onCreate() {
817
1022
  const { options: _currentOptions } = getPageConfig(this.storage, this.options);
@@ -819,180 +1024,210 @@ var PaginationPlus = Extension4.create({
819
1024
  const targetNode = this.editor.view.dom;
820
1025
  targetNode.classList.add("rm-with-pagination");
821
1026
  targetNode.style.border = `1px solid var(--rm-page-gap-border-color)`;
822
- targetNode.style.paddingLeft = "var(--rm-margin-left)";
823
- targetNode.style.paddingRight = "var(--rm-margin-right)";
824
- targetNode.style.width = "var(--rm-page-width)";
825
- updateCssVariables(targetNode, { ..._currentOptions, ...pageConfig });
826
- if (!document.querySelector("style[data-rm-pagination-style]")) {
827
- const style = document.createElement("style");
828
- style.dataset.rmPaginationStyle = "";
829
- style.textContent = `
830
- .rm-pagination-gap{
831
- border-top: 1px solid;
832
- border-bottom: 1px solid;
833
- border-color: var(--rm-page-gap-border-color);
834
- }
835
- .rm-with-pagination,
836
- .rm-with-pagination .rm-first-page-header {
837
- counter-reset: page-number page-number-plus 1;
838
- }
839
- .rm-with-pagination .image-plus-wrapper,
840
- .rm-with-pagination .table-plus td,
841
- .rm-with-pagination .table-plus th {
842
- max-height: var(--rm-max-content-child-height);
843
- overflow-y: auto;
844
- }
845
- .rm-with-pagination .image-plus-wrapper {
846
- overflow-y: visible;
847
- }
848
- .rm-with-pagination .rm-page-break {
849
- counter-increment: page-number page-number-plus;
850
- }
851
- .rm-with-pagination .rm-page-break:last-child .rm-pagination-gap {
852
- display: none;
853
- }
854
- .rm-with-pagination .rm-page-break:last-child .rm-page-header {
855
- display: none;
856
- }
857
- .rm-with-pagination table tr td,
858
- .rm-with-pagination table tr th {
859
- word-break: break-all;
860
- }
861
- .rm-with-pagination table > tr {
862
- display: grid;
863
- min-width: 100%;
864
- }
865
- .rm-with-pagination table {
866
- border-collapse: collapse;
867
- width: 100%;
868
- display: contents;
869
- }
870
- .rm-with-pagination table tbody > tr{
871
- display: table-row !important;
872
- }
873
- .rm-with-pagination *:has(>br.ProseMirror-trailingBreak:only-child) {
874
- display: table;
875
- width: 100%;
876
- }
877
- .rm-with-pagination .rm-br-decoration {
878
- display: table;
879
- width: 100%;
880
- }
881
- .rm-with-pagination .table-row-group {
882
- max-height: var(--rm-max-content-child-height);
883
- overflow-y: auto;
884
- width: 100%;
885
- }
886
- .rm-with-pagination .rm-page-footer-left,
887
- .rm-with-pagination .rm-page-footer-right,
888
- .rm-with-pagination .rm-page-header-left,
889
- .rm-with-pagination .rm-page-header-right {
890
- display: inline-block;
891
- }
892
- .rm-with-pagination .rm-page-header-left,
893
- .rm-with-pagination .rm-page-footer-left{
894
- float: left;
895
- margin-left: var(--rm-margin-left);
896
- }
897
- .rm-with-pagination .rm-page-header-right,
898
- .rm-with-pagination .rm-page-footer-right{
899
- float: right;
900
- margin-right: var(--rm-margin-right);
901
- }
902
- .rm-with-pagination .rm-first-page-header .rm-page-header-right{
903
- margin-right: 0px !important;
904
- }
905
- .rm-with-pagination .rm-first-page-header .rm-page-header-left{
906
- margin-left: 0px !important;
907
- }
908
- .rm-with-pagination .rm-page-number::before {
909
- content: counter(page-number);
910
- }
911
- .rm-with-pagination .rm-page-number-plus::before {
912
- content: counter(page-number-plus);
913
- }
914
- .rm-with-pagination .rm-page-header,
915
- .rm-with-pagination .rm-page-footer{
916
- width: 100%;
917
- }
918
- .rm-with-pagination .rm-page-header{
919
- padding-bottom: var(--rm-content-margin-top) !important;
920
- padding-top: var(--rm-margin-top) !important;
921
- display: inline-flex;
922
- justify-content: space-between;
923
- max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-margin-top) - var(--rm-content-margin-top));
924
- overflow-y: hidden;
925
- }
926
- .rm-with-pagination .rm-page-footer{
927
- padding-top: var(--rm-content-margin-bottom) !important;
928
- padding-bottom: var(--rm-margin-bottom) !important;
929
- display: inline-flex;
930
- justify-content: space-between;
931
- max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-content-margin-bottom) - var(--rm-margin-bottom));
932
- overflow-y: hidden;
933
- }
934
- .rm-with-pagination[rm-pagination-disabled] {
935
- padding-top: var(--rm-margin-top) !important;
936
- padding-bottom: var(--rm-margin-bottom) !important;
937
- }
938
- `;
939
- document.head.appendChild(style);
940
- }
1027
+ targetNode.style.paddingLeft = `var(--rm-margin-left)`;
1028
+ targetNode.style.paddingRight = `var(--rm-margin-right)`;
1029
+ targetNode.style.width = `var(--rm-page-width)`;
1030
+ updateCssVariables(targetNode, Object.assign(Object.assign({}, _currentOptions), pageConfig));
1031
+ const style = document.createElement("style");
1032
+ style.dataset.rmPaginationStyle = "";
1033
+ style.textContent = `
1034
+ .rm-pagination-gap{
1035
+ border-top: 1px solid;
1036
+ border-bottom: 1px solid;
1037
+ border-color: var(--rm-page-gap-border-color);
1038
+ }
1039
+ .rm-with-pagination,
1040
+ .rm-with-pagination .rm-first-page-header {
1041
+ counter-reset: page-number page-number-plus 1;
1042
+ }
1043
+ .rm-with-pagination .image-plus-wrapper,
1044
+ .rm-with-pagination .table-plus td,
1045
+ .rm-with-pagination .table-plus th {
1046
+ max-height: var(--rm-max-content-child-height);
1047
+ overflow-y: auto;
1048
+ }
1049
+ .rm-with-pagination .image-plus-wrapper {
1050
+ overflow-y: visible;
1051
+ }
1052
+ .rm-with-pagination .rm-page-break {
1053
+ counter-increment: page-number page-number-plus;
1054
+ }
1055
+
1056
+ .rm-with-pagination .rm-page-break:last-child .rm-pagination-gap {
1057
+ display: none;
1058
+ }
1059
+ .rm-with-pagination .rm-page-break:last-child .rm-page-header {
1060
+ display: none;
1061
+ }
1062
+
1063
+ .rm-with-pagination table tr td,
1064
+ .rm-with-pagination table tr th {
1065
+ word-break: break-all;
1066
+ }
1067
+ .rm-with-pagination table > tr {
1068
+ display: grid;
1069
+ min-width: 100%;
1070
+ }
1071
+ .rm-with-pagination table {
1072
+ border-collapse: collapse;
1073
+ width: 100%;
1074
+ display: contents;
1075
+ }
1076
+ .rm-with-pagination table tbody > tr{
1077
+ display: table-row !important;
1078
+ }
1079
+ .rm-with-pagination *:has(>br.ProseMirror-trailingBreak:only-child) {
1080
+ display: table;
1081
+ width: 100%;
1082
+ }
1083
+ .rm-with-pagination .rm-br-decoration {
1084
+ display: table;
1085
+ width: 100%;
1086
+ }
1087
+ .rm-with-pagination .table-row-group {
1088
+ max-height: var(--rm-max-content-child-height);
1089
+ overflow-y: auto;
1090
+ width: 100%;
1091
+ }
1092
+ .rm-with-pagination .rm-page-footer-left,
1093
+ .rm-with-pagination .rm-page-footer-right,
1094
+ .rm-with-pagination .rm-page-header-left,
1095
+ .rm-with-pagination .rm-page-header-right {
1096
+ display: inline-block;
1097
+ }
1098
+
1099
+ .rm-with-pagination .rm-page-header-left,
1100
+ .rm-with-pagination .rm-page-footer-left{
1101
+ float: left;
1102
+ margin-left: var(--rm-margin-left);
1103
+ }
1104
+ .rm-with-pagination .rm-page-header-right,
1105
+ .rm-with-pagination .rm-page-footer-right{
1106
+ float: right;
1107
+ margin-right: var(--rm-margin-right);
1108
+ }
1109
+ .rm-with-pagination .rm-first-page-header .rm-page-header-right{
1110
+ margin-right: 0px !important;
1111
+ }
1112
+ .rm-with-pagination .rm-first-page-header .rm-page-header-left{
1113
+ margin-left: 0px !important;
1114
+ }
1115
+ .rm-with-pagination .rm-page-number::before {
1116
+ content: counter(page-number);
1117
+ }
1118
+ .rm-with-pagination .rm-page-number-plus::before {
1119
+ content: counter(page-number-plus);
1120
+ }
1121
+ .rm-with-pagination .rm-page-header,
1122
+ .rm-with-pagination .rm-page-footer{
1123
+ width: 100%;
1124
+ }
1125
+ .rm-with-pagination .rm-page-header{
1126
+ padding-bottom: var(--rm-content-margin-top) !important;
1127
+ padding-top: var(--rm-margin-top) !important;
1128
+ display: inline-flex;
1129
+ justify-content: space-between;
1130
+ max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-margin-top) - var(--rm-content-margin-top));
1131
+ overflow-y: hidden;
1132
+ }
1133
+ .rm-with-pagination .rm-page-footer{
1134
+ padding-top: var(--rm-content-margin-bottom) !important;
1135
+ padding-bottom: var(--rm-margin-bottom) !important;
1136
+ display: inline-flex;
1137
+ justify-content: space-between;
1138
+ max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-content-margin-bottom) - var(--rm-margin-bottom));
1139
+ overflow-y: hidden;
1140
+ }
1141
+ .rm-with-pagination[rm-pagination-disabled] {
1142
+ padding-top: var(--rm-margin-top) !important;
1143
+ padding-bottom: var(--rm-margin-bottom) !important;
1144
+ }
1145
+ `;
1146
+ document.head.appendChild(style);
941
1147
  refreshPage(targetNode, _currentOptions.enabled);
942
1148
  },
943
1149
  addProseMirrorPlugins() {
1150
+ const editor = this.editor;
944
1151
  const storage = this.storage;
945
- const options = this.options;
946
1152
  return [
947
- new Plugin3({
1153
+ new Plugin4({
948
1154
  key: paginationKey,
949
1155
  state: {
950
- init: () => DecorationSet3.empty,
951
- apply: (tr, old) => {
952
- const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, options);
953
- if (!pageConfig.enabled) {
954
- return DecorationSet3.empty;
1156
+ init: (_, state) => {
1157
+ const _currentOptions = getPageConfigFromOptions(this.options);
1158
+ const pageConfig = getPageConfigFromOptions(this.options);
1159
+ const widgetList = createDecoration(Object.assign(Object.assign({}, this.options), _currentOptions), /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map());
1160
+ storage.pageBreakBackground = _currentOptions.pageBreakBackground;
1161
+ storage.pageHeight = _currentOptions.pageHeight;
1162
+ storage.pageWidth = _currentOptions.pageWidth;
1163
+ storage.marginTop = _currentOptions.marginTop;
1164
+ storage.marginBottom = _currentOptions.marginBottom;
1165
+ storage.marginLeft = _currentOptions.marginLeft;
1166
+ storage.marginRight = _currentOptions.marginRight;
1167
+ storage.pageGap = _currentOptions.pageGap;
1168
+ storage.contentMarginTop = _currentOptions.contentMarginTop;
1169
+ storage.contentMarginBottom = _currentOptions.contentMarginBottom;
1170
+ storage.footerRight = _currentOptions.footerRight;
1171
+ storage.footerLeft = _currentOptions.footerLeft;
1172
+ storage.headerRight = _currentOptions.headerRight;
1173
+ storage.headerLeft = _currentOptions.headerLeft;
1174
+ storage.customHeader = _currentOptions.customHeader;
1175
+ storage.customFooter = _currentOptions.customFooter;
1176
+ storage.headerHeight = /* @__PURE__ */ new Map();
1177
+ storage.footerHeight = /* @__PURE__ */ new Map();
1178
+ storage.appliedConfig = pageConfig;
1179
+ return {
1180
+ decorations: DecorationSet3.create(state.doc, widgetList)
1181
+ };
1182
+ },
1183
+ apply: (tr, oldDeco, oldState, newState) => {
1184
+ const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, this.options);
1185
+ if (storage.enabled === storage.appliedConfig.enabled && storage.enabled === false && storage.appliedConfig.enabled === false) {
1186
+ return oldDeco;
955
1187
  }
956
- const footerHeight = storage.footerHeight;
957
- const headerHeight = storage.headerHeight;
958
- const isPageCountChanged = tr.getMeta(page_count_meta_key);
959
- if (isPageCountChanged || tr.docChanged) {
960
- return DecorationSet3.create(
961
- tr.doc,
962
- createDecoration(
963
- { ..._currentOptions, ...pageConfig },
964
- headerHeight ?? /* @__PURE__ */ new Map(),
965
- footerHeight ?? /* @__PURE__ */ new Map()
966
- )
967
- );
1188
+ const pageCount = getNewPageCount(editor.view, Object.assign(Object.assign({}, _currentOptions), pageConfig));
1189
+ const currentPageCount = getExistingPageCount(editor.view);
1190
+ const getNewDecoration = () => {
1191
+ const { options: _currentOptions2, config: pageConfig2 } = getPageConfig(storage, this.options);
1192
+ updateCssVariables(editor.view.dom, _currentOptions2);
1193
+ let headerHeight = "headerHeight" in this.storage ? this.storage.headerHeight : /* @__PURE__ */ new Map();
1194
+ let footerHeight = "footerHeight" in this.storage ? this.storage.footerHeight : /* @__PURE__ */ new Map();
1195
+ const widgetList = createDecoration(Object.assign(Object.assign({}, _currentOptions2), pageConfig2), headerHeight, footerHeight);
1196
+ storage.appliedConfig = pageConfig2;
1197
+ storage.headerHeight = headerHeight;
1198
+ storage.footerHeight = footerHeight;
1199
+ return {
1200
+ decorations: DecorationSet3.create(newState.doc, [...widgetList]),
1201
+ footerHeight
1202
+ };
1203
+ };
1204
+ if (
1205
+ // If pagination is enabled only then check for other changes
1206
+ (pageCount > 1 ? pageCount : 1) !== currentPageCount || storage.enabled !== storage.appliedConfig.enabled || storage.pageBreakBackground !== storage.appliedConfig.pageBreakBackground || storage.pageHeight !== storage.appliedConfig.pageHeight || storage.pageWidth !== storage.appliedConfig.pageWidth || storage.marginTop !== storage.appliedConfig.marginTop || storage.marginBottom !== storage.appliedConfig.marginBottom || storage.marginLeft !== storage.appliedConfig.marginLeft || storage.marginRight !== storage.appliedConfig.marginRight || storage.pageGap !== storage.appliedConfig.pageGap || storage.contentMarginTop !== storage.appliedConfig.contentMarginTop || storage.contentMarginBottom !== storage.appliedConfig.contentMarginBottom || storage.headerLeft !== storage.appliedConfig.headerLeft || storage.headerRight !== storage.appliedConfig.headerRight || storage.footerLeft !== storage.appliedConfig.footerLeft || storage.footerRight !== storage.appliedConfig.footerRight || !deepEqualIterative(storage.appliedConfig.customHeader, storage.customHeader) || !deepEqualIterative(storage.appliedConfig.customFooter, storage.customFooter)
1207
+ ) {
1208
+ return getNewDecoration();
968
1209
  }
969
- return old;
1210
+ return oldDeco;
970
1211
  }
971
1212
  },
972
1213
  props: {
973
1214
  decorations(state) {
974
- return paginationKey.getState(state) ?? DecorationSet3.empty;
1215
+ var _a;
1216
+ return (_a = this.getState(state)) === null || _a === void 0 ? void 0 : _a.decorations;
975
1217
  }
976
1218
  },
977
- view: () => {
1219
+ view: (editorView) => {
978
1220
  return {
979
1221
  update: (view) => {
980
- const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, options);
1222
+ const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, this.options);
981
1223
  if (!pageConfig.enabled && !view.dom.hasAttribute("rm-pagination-disabled")) {
982
1224
  refreshPage(view.dom, false);
983
1225
  return;
984
1226
  }
985
- const pageCount = getNewPageCount(view, { ..._currentOptions, ...pageConfig });
1227
+ const pageCount = getNewPageCount(view, Object.assign(Object.assign({}, _currentOptions), pageConfig));
986
1228
  const currentPageCount = getExistingPageCount(view);
987
1229
  const triggerUpdate = (_footerHeight) => {
988
1230
  requestAnimationFrame(() => {
989
- const history = pageGapTracker.get(view.dom);
990
- if (history && history.flapping && history.flapping.includes(pageCount)) {
991
- return;
992
- }
993
- if (history && history.recent) {
994
- history.recent.push(pageCount);
995
- }
996
1231
  const tr = view.state.tr.setMeta(page_count_meta_key, { footerHeight: _footerHeight });
997
1232
  view.dispatch(tr);
998
1233
  });
@@ -1016,7 +1251,7 @@ var PaginationPlus = Extension4.create({
1016
1251
  }
1017
1252
  }
1018
1253
  const pagesSetToCheck = /* @__PURE__ */ new Set([1, ...footerHeightForCurrentPages.keys(), ...headerHeightForCurrentPages.keys()]);
1019
- let missingPageNumber;
1254
+ let missingPageNumber = void 0;
1020
1255
  for (let i = 1; i <= pageCount; i++) {
1021
1256
  if (!pagesSetToCheck.has(i)) {
1022
1257
  missingPageNumber = i;
@@ -1027,18 +1262,18 @@ var PaginationPlus = Extension4.create({
1027
1262
  pagesSetToCheck.add(missingPageNumber);
1028
1263
  }
1029
1264
  pagesSetToCheck.delete(0);
1030
- const pageContentHeightVariable = {};
1031
- let maxContentHeight;
1265
+ let pageContentHeightVariable = {};
1266
+ let maxContentHeight = void 0;
1032
1267
  for (const page of pagesSetToCheck) {
1033
- const hHeight = headerHeightForCurrentPages.has(page) ? headerHeightForCurrentPages.get(page) || 0 : headerHeightForCurrentPages.get(0) || 0;
1034
- const fHeight = footerHeightForCurrentPages.has(page) ? footerHeightForCurrentPages.get(page) || 0 : footerHeightForCurrentPages.get(0) || 0;
1035
- const { _pageHeaderHeight, _pageHeight } = getHeight(_currentOptions, hHeight, fHeight);
1268
+ const headerHeight2 = headerHeightForCurrentPages.has(page) ? headerHeightForCurrentPages.get(page) || 0 : headerHeightForCurrentPages.get(0) || 0;
1269
+ const footerHeight2 = footerHeightForCurrentPages.has(page) ? footerHeightForCurrentPages.get(page) || 0 : footerHeightForCurrentPages.get(0) || 0;
1270
+ const { _pageHeaderHeight, _pageHeight } = getHeight(_currentOptions, headerHeight2, footerHeight2);
1036
1271
  const contentHeight = page === 1 ? _pageHeight + _pageHeaderHeight : _pageHeight;
1037
1272
  if (page === 1) {
1038
- pageContentHeightVariable["rm-page-content-first"] = `${contentHeight}px`;
1273
+ pageContentHeightVariable[`rm-page-content-first`] = `${contentHeight}px`;
1039
1274
  }
1040
1275
  if (page === missingPageNumber) {
1041
- pageContentHeightVariable["rm-page-content-general"] = `${contentHeight}px`;
1276
+ pageContentHeightVariable[`rm-page-content-general`] = `${contentHeight}px`;
1042
1277
  } else {
1043
1278
  pageContentHeightVariable[`rm-page-content-${page}`] = `${contentHeight}px`;
1044
1279
  }
@@ -1047,28 +1282,25 @@ var PaginationPlus = Extension4.create({
1047
1282
  }
1048
1283
  }
1049
1284
  if (maxContentHeight) {
1050
- ;
1051
- view.dom.style.setProperty("--rm-max-content-child-height", `${maxContentHeight - 10}px`);
1285
+ view.dom.style.setProperty(`--rm-max-content-child-height`, `${maxContentHeight - 10}px`);
1052
1286
  }
1053
- Object.entries(pageContentHeightVariable).forEach(([k, value]) => {
1054
- ;
1055
- view.dom.style.setProperty(`--${k}`, value);
1287
+ Object.entries(pageContentHeightVariable).forEach(([key2, value]) => {
1288
+ view.dom.style.setProperty(`--${key2}`, value);
1056
1289
  });
1057
1290
  refreshPage(view.dom, _currentOptions.enabled);
1291
+ return;
1058
1292
  }
1059
1293
  };
1060
1294
  }
1061
1295
  }),
1062
- new Plugin3({
1296
+ new Plugin4({
1063
1297
  key,
1064
1298
  state: {
1065
1299
  init(_, state) {
1066
1300
  return buildDecorations(state.doc);
1067
1301
  },
1068
1302
  apply(tr, old) {
1069
- if (tr.docChanged || tr.steps.some(
1070
- (step) => step instanceof ReplaceStep || step instanceof ReplaceAroundStep || step instanceof AddMarkStep || step instanceof RemoveMarkStep || step instanceof RemoveNodeMarkStep || step instanceof AttrStep
1071
- )) {
1303
+ if (tr.docChanged || tr.steps.some((step) => step instanceof ReplaceStep) || tr.steps.some((step) => step instanceof ReplaceAroundStep) || tr.steps.some((step) => step instanceof AddMarkStep) || tr.steps.some((step) => step instanceof RemoveMarkStep) || tr.steps.some((step) => step instanceof RemoveNodeMarkStep) || tr.steps.some((step) => step instanceof AttrStep)) {
1072
1304
  return buildDecorations(tr.doc);
1073
1305
  }
1074
1306
  return old;
@@ -1076,7 +1308,8 @@ var PaginationPlus = Extension4.create({
1076
1308
  },
1077
1309
  props: {
1078
1310
  decorations(state) {
1079
- return key.getState(state) ?? DecorationSet3.empty;
1311
+ var _a;
1312
+ return (_a = key.getState(state)) !== null && _a !== void 0 ? _a : DecorationSet3.empty;
1080
1313
  }
1081
1314
  }
1082
1315
  })
@@ -1116,14 +1349,31 @@ var PaginationPlus = Extension4.create({
1116
1349
  this.storage.marginRight = margins.right;
1117
1350
  return true;
1118
1351
  },
1119
- updateHeaderContent: (left, right) => () => {
1120
- if (left !== void 0) this.storage.headerLeft = left;
1121
- if (right !== void 0) this.storage.headerRight = right;
1352
+ updateContentMargins: (margins) => () => {
1353
+ this.storage.contentMarginTop = margins.top;
1354
+ this.storage.contentMarginBottom = margins.bottom;
1122
1355
  return true;
1123
1356
  },
1124
- updateFooterContent: (left, right) => () => {
1125
- if (left !== void 0) this.storage.footerLeft = left;
1126
- if (right !== void 0) this.storage.footerRight = right;
1357
+ updateHeaderContent: (left, right, pageNumber) => () => {
1358
+ if (pageNumber) {
1359
+ this.storage.customHeader = Object.assign(Object.assign({}, this.storage.customHeader), { [pageNumber]: { headerLeft: left, headerRight: right } });
1360
+ } else {
1361
+ this.storage.headerLeft = left;
1362
+ this.storage.headerRight = right;
1363
+ }
1364
+ return true;
1365
+ },
1366
+ updateFooterContent: (left, right, pageNumber) => () => {
1367
+ if (pageNumber) {
1368
+ this.storage.customFooter = Object.assign(Object.assign({}, this.storage.customFooter), { [pageNumber]: { footerLeft: left, footerRight: right } });
1369
+ } else {
1370
+ this.storage.footerLeft = left;
1371
+ this.storage.footerRight = right;
1372
+ }
1373
+ return true;
1374
+ },
1375
+ togglePagination: () => () => {
1376
+ this.storage.enabled = !this.storage.enabled;
1127
1377
  return true;
1128
1378
  },
1129
1379
  enablePagination: () => () => {
@@ -1137,94 +1387,203 @@ var PaginationPlus = Extension4.create({
1137
1387
  };
1138
1388
  }
1139
1389
  });
1140
-
1141
- // src/pagination/PaginationCaretFix.ts
1142
- import { Extension as Extension5 } from "@tiptap/core";
1143
- import { Plugin as Plugin4, PluginKey as PluginKey4, TextSelection as TextSelection2 } from "@tiptap/pm/state";
1144
- var PAGINATION_CLASS = "rm-with-pagination";
1145
- var PAGINATION_DISABLED_ATTR = "rm-pagination-disabled";
1146
- var dragStates = /* @__PURE__ */ new WeakMap();
1147
- var isPaginationActive = (view) => {
1148
- const dom = view.dom;
1149
- return dom.classList.contains(PAGINATION_CLASS) && dom.getAttribute(PAGINATION_DISABLED_ATTR) === null;
1390
+ var getExistingPageCount = (view) => {
1391
+ const editorDom = view.dom;
1392
+ const paginationElement = editorDom.querySelector("[data-rm-pagination]");
1393
+ if (paginationElement) {
1394
+ return paginationElement.children.length;
1395
+ }
1396
+ return 0;
1150
1397
  };
1151
- var isEditable = (view) => view.dom.getAttribute("contenteditable") !== "false";
1152
- var isPlainSingleLeftClick = (event) => event.button === 0 && event.detail === 1 && !event.shiftKey && !event.altKey && !event.ctrlKey && !event.metaKey;
1153
- function posFromTextOffset(view, textNode, offset) {
1154
- if (textNode.nodeType !== Node.TEXT_NODE || !view.dom.contains(textNode)) return null;
1155
- const text = textNode;
1156
- const clamped = Math.min(Math.max(0, offset), text.length);
1157
- const parent = text.parentElement;
1158
- if (parent?.closest?.('[contenteditable="false"]')) return null;
1159
- let pos = view.posAtDOM(text, clamped, -1);
1160
- if (pos < 0) pos = view.posAtDOM(text, clamped, 1);
1161
- if (pos < 0) return null;
1162
- return view.state.doc.resolve(pos).parent.isTextblock ? pos : null;
1163
- }
1164
- function resolvePosFromNativePoint(view, clientX, clientY) {
1165
- const doc = view.dom.ownerDocument;
1166
- if (typeof doc.caretRangeFromPoint !== "function") return null;
1167
- const range = doc.caretRangeFromPoint(clientX, clientY);
1168
- if (!range) return null;
1169
- return posFromTextOffset(view, range.startContainer, range.startOffset);
1170
- }
1171
- function stopDrag(view) {
1172
- const drag = dragStates.get(view);
1173
- if (!drag) return;
1174
- dragStates.delete(view);
1175
- const doc = view.dom.ownerDocument;
1176
- doc.removeEventListener("mousemove", drag.onMouseMove);
1177
- doc.removeEventListener("mouseup", drag.onMouseUp);
1178
- }
1179
- function beginDrag(view, anchorPos) {
1180
- stopDrag(view);
1181
- const doc = view.dom.ownerDocument;
1182
- const onMouseMove = (event) => {
1183
- const drag = dragStates.get(view);
1184
- if (!drag) return;
1185
- const pos = resolvePosFromNativePoint(view, event.clientX, event.clientY);
1186
- if (pos === null) return;
1187
- const from = Math.min(drag.anchorPos, pos);
1188
- const to = Math.max(drag.anchorPos, pos);
1189
- view.dispatch(view.state.tr.setSelection(TextSelection2.create(view.state.doc, from, to)));
1190
- };
1191
- const onMouseUp = () => {
1192
- stopDrag(view);
1193
- };
1194
- dragStates.set(view, { anchorPos, onMouseMove, onMouseUp });
1195
- doc.addEventListener("mousemove", onMouseMove);
1196
- doc.addEventListener("mouseup", onMouseUp);
1197
- }
1198
- function interceptPaginationMouseDown(view, event) {
1199
- if (!isPaginationActive(view) || !isPlainSingleLeftClick(event) || !isEditable(view)) return false;
1200
- const pos = resolvePosFromNativePoint(view, event.clientX, event.clientY);
1201
- if (pos === null) return false;
1202
- view.focus();
1203
- view.dispatch(view.state.tr.setSelection(TextSelection2.create(view.state.doc, pos)));
1204
- beginDrag(view, pos);
1205
- return true;
1206
- }
1207
- var PaginationCaretFix = Extension5.create({
1208
- name: "paginationCaretFix",
1209
- addProseMirrorPlugins() {
1210
- return [
1211
- new Plugin4({
1212
- key: new PluginKey4("paginationCaretFix"),
1213
- props: {
1214
- handleDOMEvents: {
1215
- mousedown: (view, event) => {
1216
- try {
1217
- return interceptPaginationMouseDown(view, event);
1218
- } catch {
1219
- return false;
1220
- }
1221
- }
1398
+ var pageGapTracker = /* @__PURE__ */ new WeakMap();
1399
+ var calculatePageCount = (view, pageOptions, headerHeight = 0, footerHeight = 0) => {
1400
+ var _a;
1401
+ const editorDom = view.dom;
1402
+ const _pageHeaderHeight = pageOptions.contentMarginTop + pageOptions.marginTop + headerHeight;
1403
+ const _pageFooterHeight = pageOptions.contentMarginBottom + pageOptions.marginBottom + footerHeight;
1404
+ const pageContentAreaHeight = pageOptions.pageHeight - _pageHeaderHeight - _pageFooterHeight;
1405
+ const paginationElement = editorDom.querySelector("[data-rm-pagination]");
1406
+ const currentPageCount = getExistingPageCount(view);
1407
+ if (paginationElement) {
1408
+ const lastElementOfEditor = editorDom.lastElementChild;
1409
+ const lastPageBreak = (_a = paginationElement.lastElementChild) === null || _a === void 0 ? void 0 : _a.querySelector(".breaker");
1410
+ if (lastElementOfEditor && lastPageBreak) {
1411
+ const lastElementRect = lastElementOfEditor.getBoundingClientRect();
1412
+ const lastPageBreakRect = lastPageBreak.getBoundingClientRect();
1413
+ const lastPageGap = lastElementRect.bottom - lastPageBreakRect.bottom;
1414
+ if (lastPageGap > 0) {
1415
+ const addPage = Math.ceil(lastPageGap / pageContentAreaHeight);
1416
+ if (lastElementRect.height > pageContentAreaHeight) {
1417
+ const isSplittableTable = (lastElementOfEditor === null || lastElementOfEditor === void 0 ? void 0 : lastElementOfEditor.tagName) === "TABLE" && lastElementOfEditor.hasAttribute("data-tps-splittable");
1418
+ if (!isSplittableTable) {
1419
+ return currentPageCount;
1222
1420
  }
1223
1421
  }
1224
- })
1225
- ];
1422
+ const prev = pageGapTracker.get(editorDom);
1423
+ if (prev && prev.pages < currentPageCount && lastPageGap > prev.gap - 2) {
1424
+ return currentPageCount;
1425
+ }
1426
+ pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount });
1427
+ let totalEditorContentHeight = 0;
1428
+ for (const child of editorDom.children) {
1429
+ if (!(child instanceof HTMLElement)) continue;
1430
+ if (child.hasAttribute("data-rm-pagination")) continue;
1431
+ if (child.classList.contains("rm-page-break")) continue;
1432
+ totalEditorContentHeight += child.getBoundingClientRect().height;
1433
+ }
1434
+ const maxPagesByContent = Math.ceil(totalEditorContentHeight / pageContentAreaHeight);
1435
+ const contentCap = Math.max(currentPageCount, maxPagesByContent + 1);
1436
+ if (currentPageCount + addPage > contentCap) {
1437
+ return contentCap;
1438
+ }
1439
+ const MAX_PAGES = 1e3;
1440
+ if (currentPageCount + addPage > MAX_PAGES) {
1441
+ return currentPageCount;
1442
+ }
1443
+ return currentPageCount + addPage;
1444
+ } else {
1445
+ pageGapTracker.delete(editorDom);
1446
+ const allBreaksAfterLastElement = Array.from(paginationElement.querySelectorAll(".breaker"));
1447
+ const allBreaksAfterLastElementRect = allBreaksAfterLastElement.filter((element) => element.getBoundingClientRect().top > lastElementRect.bottom);
1448
+ const removePage = allBreaksAfterLastElementRect.length;
1449
+ if (removePage > 1) {
1450
+ return currentPageCount - removePage;
1451
+ } else {
1452
+ return currentPageCount;
1453
+ }
1454
+ }
1455
+ }
1456
+ return 1;
1457
+ } else {
1458
+ const editorHeight = editorDom.scrollHeight;
1459
+ let pageCount = Math.ceil(editorHeight / pageContentAreaHeight);
1460
+ pageCount = pageCount <= 0 ? 1 : pageCount;
1461
+ return pageCount;
1226
1462
  }
1227
- });
1463
+ };
1464
+ var getNewPageCount = (view, pageOptions) => {
1465
+ if (pageOptions.enabled) {
1466
+ const pageCount = calculatePageCount(view, pageOptions);
1467
+ return pageCount <= 1 ? 1 : pageCount;
1468
+ } else {
1469
+ return 0;
1470
+ }
1471
+ };
1472
+ function createDecoration(pageOptions, headerHeightMap, footerHeightMap) {
1473
+ if (!pageOptions.enabled) {
1474
+ return [];
1475
+ }
1476
+ const commonHeaderOptions = { headerLeft: pageOptions.headerLeft, headerRight: pageOptions.headerRight };
1477
+ const commonFooterOptions = { footerLeft: pageOptions.footerLeft, footerRight: pageOptions.footerRight };
1478
+ const pageWidget = Decoration3.widget(0, (view) => {
1479
+ const _pageGap = pageOptions.pageGap;
1480
+ const _pageBreakBackground = pageOptions.pageBreakBackground;
1481
+ const el = document.createElement("div");
1482
+ el.dataset.rmPagination = "true";
1483
+ const pageBreakDefinition = (firstPage, pageHeader, pageFooter, headerHeight, footerHeight, pageNumber) => {
1484
+ const { _pageHeaderHeight, _pageHeight } = getHeight(pageOptions, headerHeight, footerHeight);
1485
+ const pageContainer = document.createElement("div");
1486
+ pageContainer.classList.add("rm-page-break");
1487
+ const page = document.createElement("div");
1488
+ page.classList.add("page");
1489
+ page.style.position = "relative";
1490
+ page.style.float = "left";
1491
+ page.style.clear = "both";
1492
+ const marginTop = firstPage ? `calc(${_pageHeaderHeight}px + ${_pageHeight}px)` : _pageHeight + "px";
1493
+ if (pageNumber) {
1494
+ page.style.marginTop = `var(--rm-page-content-${pageNumber}, ${marginTop})`;
1495
+ } else {
1496
+ page.style.marginTop = firstPage ? `var(--rm-page-content-first, ${marginTop})` : `var(--rm-page-content-general, ${marginTop})`;
1497
+ }
1498
+ const pageBreak = document.createElement("div");
1499
+ pageBreak.classList.add("breaker");
1500
+ pageBreak.style.width = `calc(100% + var(--rm-margin-left) + var(--rm-margin-right))`;
1501
+ pageBreak.style.marginLeft = `calc(-1 * var(--rm-margin-left))`;
1502
+ pageBreak.style.marginRight = `calc(-1 * var(--rm-margin-right))`;
1503
+ pageBreak.style.position = "relative";
1504
+ pageBreak.style.float = "left";
1505
+ pageBreak.style.clear = "both";
1506
+ pageBreak.style.left = `0px`;
1507
+ pageBreak.style.right = `0px`;
1508
+ pageBreak.style.zIndex = "2";
1509
+ const pageSpace = document.createElement("div");
1510
+ pageSpace.classList.add("rm-pagination-gap");
1511
+ pageSpace.style.height = _pageGap + "px";
1512
+ pageSpace.style.borderLeft = "1px solid";
1513
+ pageSpace.style.borderRight = "1px solid";
1514
+ pageSpace.style.position = "relative";
1515
+ pageSpace.style.setProperty("width", "calc(100% + 2px)", "important");
1516
+ pageSpace.style.left = "-1px";
1517
+ pageSpace.style.backgroundColor = _pageBreakBackground;
1518
+ pageSpace.style.borderLeftColor = _pageBreakBackground;
1519
+ pageSpace.style.borderRightColor = _pageBreakBackground;
1520
+ pageBreak.append(pageFooter, pageSpace, pageHeader);
1521
+ pageContainer.append(page, pageBreak);
1522
+ return pageContainer;
1523
+ };
1524
+ const _headerHeight = headerHeightMap.get(0) || 0;
1525
+ const _footerHeight = footerHeightMap.get(0) || 0;
1526
+ const fragment = document.createDocumentFragment();
1527
+ const pageCount = getNewPageCount(view, pageOptions);
1528
+ for (let i = 0; i < pageCount; i++) {
1529
+ const pageNumber = i + 1;
1530
+ const headerPageNumber = i + 2;
1531
+ if (headerPageNumber in pageOptions.customHeader || pageNumber in pageOptions.customFooter || pageNumber in pageOptions.customHeader) {
1532
+ let _headerOptions = commonHeaderOptions;
1533
+ let _footerOptions = commonFooterOptions;
1534
+ let _pageHeaderHeight = _headerHeight;
1535
+ let _pageFooterHeight = _footerHeight;
1536
+ if (headerPageNumber in pageOptions.customHeader) {
1537
+ _headerOptions = pageOptions.customHeader[headerPageNumber] || commonHeaderOptions;
1538
+ _pageHeaderHeight = headerHeightMap.get(headerPageNumber) || 0;
1539
+ }
1540
+ if (pageNumber in pageOptions.customFooter) {
1541
+ _footerOptions = pageOptions.customFooter[pageNumber] || commonFooterOptions;
1542
+ _pageFooterHeight = footerHeightMap.get(pageNumber) || 0;
1543
+ }
1544
+ let _pageHeader = getHeader(_headerOptions.headerRight, _headerOptions.headerLeft, headerClickEvent(headerPageNumber, pageOptions.onHeaderClick), headerPageNumber);
1545
+ let _pageFooter = getFooter(_footerOptions.footerRight, _footerOptions.footerLeft, footerClickEvent(pageNumber, pageOptions.onFooterClick), pageNumber);
1546
+ let pageBreak = pageBreakDefinition(i === 0, _pageHeader, _pageFooter, _pageHeaderHeight, _pageFooterHeight, pageNumber);
1547
+ fragment.appendChild(pageBreak);
1548
+ } else {
1549
+ const __pageHeader = getHeader(commonHeaderOptions.headerRight, commonHeaderOptions.headerLeft, headerClickEvent(headerPageNumber, pageOptions.onHeaderClick));
1550
+ const __pageFooter = getFooter(commonFooterOptions.footerRight, commonFooterOptions.footerLeft, footerClickEvent(pageNumber, pageOptions.onFooterClick));
1551
+ fragment.appendChild(pageBreakDefinition(i === 0, __pageHeader, __pageFooter, _headerHeight, _footerHeight));
1552
+ }
1553
+ }
1554
+ el.append(fragment);
1555
+ el.id = "pages";
1556
+ el.classList.add("rm-pages-wrapper");
1557
+ return el;
1558
+ }, { side: -1 });
1559
+ const firstHeaderWidget = Decoration3.widget(0, () => {
1560
+ const pageNumber = 1;
1561
+ let _headerOptions = commonHeaderOptions;
1562
+ if (pageNumber in pageOptions.customHeader) {
1563
+ _headerOptions = pageOptions.customHeader[pageNumber];
1564
+ }
1565
+ const el = getHeader(_headerOptions.headerRight, _headerOptions.headerLeft, headerClickEvent(pageNumber, pageOptions.onHeaderClick));
1566
+ el.classList.add("rm-first-page-header");
1567
+ return el;
1568
+ }, { side: -1 });
1569
+ return [pageWidget, firstHeaderWidget];
1570
+ }
1571
+
1572
+ // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/constants.js
1573
+ var A4_PAGE_SIZE = getPageSize(1123, 794, 95, 95, 76, 76);
1574
+ var A3_PAGE_SIZE = getPageSize(1591, 1123, 95, 95, 76, 76);
1575
+ var A5_PAGE_SIZE = getPageSize(794, 419, 76, 76, 57, 57);
1576
+ var LETTER_PAGE_SIZE = getPageSize(1060, 818, 96, 96, 96, 96);
1577
+ var LEGAL_PAGE_SIZE = getPageSize(1404, 818, 96, 96, 96, 96);
1578
+ var TABLOID_PAGE_SIZE = getPageSize(1635, 1060, 96, 96, 96, 96);
1579
+ var PAGE_SIZES = {
1580
+ A4: A4_PAGE_SIZE,
1581
+ A3: A3_PAGE_SIZE,
1582
+ A5: A5_PAGE_SIZE,
1583
+ LETTER: LETTER_PAGE_SIZE,
1584
+ LEGAL: LEGAL_PAGE_SIZE,
1585
+ TABLOID: TABLOID_PAGE_SIZE
1586
+ };
1228
1587
 
1229
1588
  // src/PerformanceMonitor.ts
1230
1589
  var TARGET_FRAME_MS = 1e3 / 60;
@@ -1593,7 +1952,7 @@ function createEditor(options = {}) {
1593
1952
  content: options.content ? migrateContent(options.content) : options.content
1594
1953
  };
1595
1954
  const plugins = migratedOptions.plugins ?? [];
1596
- const collaborationSetup = migratedOptions.collaboration;
1955
+ const collaborationSetup = !migratedOptions.collaboration ? void 0 : "ydoc" in migratedOptions.collaboration ? migratedOptions.collaboration : createCollaboration(migratedOptions.collaboration);
1597
1956
  const performanceMonitor = migratedOptions.debug ? createPerformanceMonitor() : void 0;
1598
1957
  let tiptapEditor = createTiptapEditor(migratedOptions, plugins, collaborationSetup);
1599
1958
  let pluginActions = createActionMap(tiptapEditor, plugins);
@@ -1634,6 +1993,7 @@ function createEditor(options = {}) {
1634
1993
  plugin.hooks?.onDestroy?.(tiptapEditor);
1635
1994
  }
1636
1995
  tiptapEditor.destroy();
1996
+ collaborationSetup?.destroy();
1637
1997
  performanceMonitor?.destroy();
1638
1998
  },
1639
1999
  use: (plugin) => {
@@ -1653,336 +2013,12 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1653
2013
  const pluginExtensions = collectExtensions(plugins);
1654
2014
  const blockAttrs = options.getPageMap ? BlockAttributesExtension.configure({ pageMap: options.getPageMap }) : BlockAttributesExtension;
1655
2015
  const paginationExt = options.paginationOptions ? PaginationPlus.configure(options.paginationOptions) : PaginationPlus;
1656
- const ManualColumnResize = Extension6.create({
1657
- name: "manualColumnResize",
1658
- addProseMirrorPlugins() {
1659
- const key2 = new PluginKey5("manualColumnResize");
1660
- return [new Plugin5({
1661
- key: key2,
1662
- view(view) {
1663
- function pauseObserver() {
1664
- try {
1665
- view.domObserver?.stop?.();
1666
- } catch (_) {
1667
- }
1668
- }
1669
- function resumeObserver() {
1670
- try {
1671
- view.domObserver?.start?.();
1672
- } catch (_) {
1673
- }
1674
- }
1675
- function getMaxContainerWidth(tableEl) {
1676
- let curr = tableEl.parentElement;
1677
- while (curr) {
1678
- const style = window.getComputedStyle(curr);
1679
- const paddingLeft = parseFloat(style.paddingLeft) || 0;
1680
- const paddingRight = parseFloat(style.paddingRight) || 0;
1681
- const availWidth = curr.clientWidth - paddingLeft - paddingRight;
1682
- if (availWidth > 100 && (curr.classList.contains("docs-editor__paper") || curr.classList.contains("docs-editor-page") || curr.classList.contains("ProseMirror") || curr.classList.contains("rm-with-pagination"))) {
1683
- return availWidth;
1684
- }
1685
- curr = curr.parentElement;
1686
- }
1687
- return tableEl.parentElement?.clientWidth || 614;
1688
- }
1689
- const onMouseDown = function(event) {
1690
- if (event.button !== 0) return;
1691
- const td = event.target.closest("td, th");
1692
- if (!td) return;
1693
- const r = td.getBoundingClientRect();
1694
- const parent = td.parentElement;
1695
- if (!parent) return;
1696
- const cellColSpan = td.colSpan || 1;
1697
- let logicalStart = 0;
1698
- let foundCell = false;
1699
- for (const sibling of Array.from(parent.children)) {
1700
- if (sibling === td) {
1701
- foundCell = true;
1702
- break;
1703
- }
1704
- logicalStart += sibling.colSpan || 1;
1705
- }
1706
- if (!foundCell) return;
1707
- const table = td.closest("table");
1708
- if (!table) return;
1709
- const distRight = Math.abs(event.clientX - r.right);
1710
- const distLeft = Math.abs(event.clientX - r.left);
1711
- let targetColIdx = -1;
1712
- if (distRight <= 16) {
1713
- targetColIdx = logicalStart + cellColSpan - 1;
1714
- } else if (distLeft <= 16 && logicalStart > 0) {
1715
- targetColIdx = logicalStart - 1;
1716
- } else {
1717
- return;
1718
- }
1719
- const colsList = table.querySelectorAll("colgroup col");
1720
- const totalCols = colsList.length || table.querySelector("tr")?.children.length || 0;
1721
- const allColWidths = [];
1722
- for (let c = 0; c < totalCols; c++) {
1723
- const colEl = colsList[c];
1724
- const w = colEl ? parseFloat(colEl.style.width) : 0;
1725
- allColWidths[c] = w || initialWidth(table, c);
1726
- }
1727
- const isLastCol = targetColIdx === totalCols - 1;
1728
- const neighborIdx = targetColIdx + 1;
1729
- const startX = event.clientX;
1730
- const startW = allColWidths[targetColIdx] || initialWidth(table, targetColIdx);
1731
- const startNeighborW = !isLastCol ? allColWidths[neighborIdx] || initialWidth(table, neighborIdx) : 0;
1732
- const maxContainerW = getMaxContainerWidth(table);
1733
- let otherColsW = 0;
1734
- allColWidths.forEach((w, idx) => {
1735
- if (idx !== targetColIdx) otherColsW += w;
1736
- });
1737
- const maxNwLastCol = Math.max(20, maxContainerW - otherColsW);
1738
- function updateDOMWidths() {
1739
- let totalWidth = 0;
1740
- allColWidths.forEach((w, idx) => {
1741
- const col = table.querySelector(`colgroup col:nth-child(${idx + 1})`);
1742
- if (col) col.style.setProperty("width", w + "px", "important");
1743
- table.querySelectorAll("tr").forEach(function(row) {
1744
- const cell = row.children[idx];
1745
- if (cell) {
1746
- cell.style.setProperty("width", w + "px", "important");
1747
- cell.setAttribute("width", String(w));
1748
- }
1749
- });
1750
- totalWidth += w;
1751
- });
1752
- if (totalWidth > 0) {
1753
- table.style.setProperty("width", Math.min(totalWidth, maxContainerW) + "px", "important");
1754
- }
1755
- }
1756
- event.stopPropagation();
1757
- let lastNw = startW;
1758
- const onMove = function(e) {
1759
- if (!e.buttons) {
1760
- onUp(e);
1761
- return;
1762
- }
1763
- const rawDiff = e.clientX - startX;
1764
- if (isLastCol) {
1765
- const nw = Math.min(maxNwLastCol, Math.max(20, startW + rawDiff));
1766
- allColWidths[targetColIdx] = nw;
1767
- lastNw = nw;
1768
- } else {
1769
- const delta = Math.max(20 - startW, Math.min(rawDiff, startNeighborW - 20));
1770
- allColWidths[targetColIdx] = startW + delta;
1771
- allColWidths[neighborIdx] = startNeighborW - delta;
1772
- lastNw = allColWidths[targetColIdx];
1773
- }
1774
- let borderPos = table.getBoundingClientRect().left;
1775
- for (let i = 0; i <= targetColIdx; i++) borderPos += allColWidths[i];
1776
- showLine(table, borderPos);
1777
- pauseObserver();
1778
- updateDOMWidths();
1779
- resumeObserver();
1780
- };
1781
- const onUp = function(upEvent) {
1782
- document.removeEventListener("mousemove", onMove);
1783
- document.removeEventListener("mouseup", onUp, true);
1784
- upEvent.stopPropagation();
1785
- hideLine();
1786
- if (lastNw === startW) return;
1787
- try {
1788
- const { state } = view;
1789
- const { doc } = state;
1790
- let tablePos = -1;
1791
- doc.descendants((node, pos) => {
1792
- if (tablePos >= 0) return false;
1793
- if (node.type.name === "table") {
1794
- try {
1795
- const dom = view.nodeDOM(pos);
1796
- if (dom === table || dom instanceof HTMLElement && dom.contains(table) || table.contains(dom)) {
1797
- tablePos = pos;
1798
- return false;
1799
- }
1800
- } catch (_) {
1801
- }
1802
- }
1803
- return true;
1804
- });
1805
- if (tablePos >= 0) {
1806
- const tableNode = doc.nodeAt(tablePos);
1807
- if (tableNode) {
1808
- const tr = state.tr;
1809
- tableNode.forEach((row, rowOffset) => {
1810
- let cellColIdx = 0;
1811
- row.forEach((cell, cellOffset) => {
1812
- const colspan = cell.attrs.colspan || 1;
1813
- const cellPos = tablePos + 1 + rowOffset + 1 + cellOffset;
1814
- const cw = new Array(colspan);
1815
- for (let k = 0; k < colspan; k++) {
1816
- cw[k] = allColWidths[cellColIdx + k] || 100;
1817
- }
1818
- tr.setNodeMarkup(cellPos, null, { ...cell.attrs, colwidth: cw });
1819
- cellColIdx += colspan;
1820
- });
1821
- });
1822
- view.dispatch(tr);
1823
- pauseObserver();
1824
- updateDOMWidths();
1825
- resumeObserver();
1826
- }
1827
- } else {
1828
- console.warn("[Resize] could not find table position in doc");
1829
- }
1830
- } catch (err) {
1831
- console.warn("[Resize] transaction failed, falling back to DOM:", err);
1832
- pauseObserver();
1833
- updateDOMWidths();
1834
- resumeObserver();
1835
- }
1836
- };
1837
- document.addEventListener("mousemove", onMove);
1838
- document.addEventListener("mouseup", onUp, true);
1839
- };
1840
- function initialWidth(table, colIdx) {
1841
- const firstRow = table.querySelector("tr");
1842
- if (!firstRow) return 100;
1843
- const cell = firstRow.children[colIdx];
1844
- if (!cell) return 100;
1845
- return Math.round(cell.getBoundingClientRect().width) || cell.offsetWidth || 100;
1846
- }
1847
- let lineEl = null;
1848
- let isDragging = false;
1849
- function getOrCreateLine() {
1850
- if (!lineEl) {
1851
- lineEl = document.createElement("div");
1852
- lineEl.className = "docflow-active-border-line";
1853
- Object.assign(lineEl.style, {
1854
- position: "fixed",
1855
- width: "3px",
1856
- background: "#06b6d4",
1857
- boxShadow: "0 0 8px rgba(6, 182, 212, 0.9)",
1858
- pointerEvents: "none",
1859
- zIndex: "999999",
1860
- display: "none",
1861
- borderRadius: "1.5px"
1862
- });
1863
- const dotTop = document.createElement("div");
1864
- Object.assign(dotTop.style, {
1865
- position: "absolute",
1866
- top: "-4px",
1867
- left: "-3.5px",
1868
- width: "10px",
1869
- height: "10px",
1870
- borderRadius: "50%",
1871
- background: "#ffffff",
1872
- border: "2px solid #06b6d4"
1873
- });
1874
- const dotBottom = document.createElement("div");
1875
- Object.assign(dotBottom.style, {
1876
- position: "absolute",
1877
- bottom: "-4px",
1878
- left: "-3.5px",
1879
- width: "10px",
1880
- height: "10px",
1881
- borderRadius: "50%",
1882
- background: "#ffffff",
1883
- border: "2px solid #06b6d4"
1884
- });
1885
- lineEl.appendChild(dotTop);
1886
- lineEl.appendChild(dotBottom);
1887
- document.body.appendChild(lineEl);
1888
- }
1889
- return lineEl;
1890
- }
1891
- function showLine(table, borderX) {
1892
- const line = getOrCreateLine();
1893
- const tableRect = table.getBoundingClientRect();
1894
- line.style.left = `${borderX - 1.5}px`;
1895
- line.style.top = `${tableRect.top}px`;
1896
- line.style.height = `${tableRect.height}px`;
1897
- line.style.display = "block";
1898
- document.body.style.cursor = "col-resize";
1899
- view.dom.style.cursor = "col-resize";
1900
- }
1901
- function hideLine() {
1902
- if (lineEl) {
1903
- lineEl.style.display = "none";
1904
- }
1905
- document.body.style.cursor = "";
1906
- view.dom.style.cursor = "";
1907
- }
1908
- const onMouseMoveHover = function(event) {
1909
- if (isDragging) return;
1910
- const target = event.target;
1911
- const td = target.closest("td, th");
1912
- if (!td) {
1913
- hideLine();
1914
- return;
1915
- }
1916
- const r = td.getBoundingClientRect();
1917
- const distRight = Math.abs(event.clientX - r.right);
1918
- const distLeft = Math.abs(event.clientX - r.left);
1919
- const parent = td.parentElement;
1920
- if (!parent) {
1921
- hideLine();
1922
- return;
1923
- }
1924
- const colIdx = Array.from(parent.children).indexOf(td);
1925
- let borderX = -1;
1926
- if (distRight <= 16) {
1927
- borderX = r.right;
1928
- } else if (distLeft <= 16 && colIdx > 0) {
1929
- borderX = r.left;
1930
- }
1931
- if (borderX >= 0) {
1932
- const table = td.closest("table");
1933
- if (table) {
1934
- showLine(table, borderX);
1935
- }
1936
- } else {
1937
- hideLine();
1938
- }
1939
- };
1940
- document.addEventListener("mousemove", onMouseMoveHover, true);
1941
- view.dom.addEventListener("mousedown", function handleMouseDown(event) {
1942
- onMouseDown(event);
1943
- const td = event.target.closest("td, th");
1944
- if (!td) return;
1945
- const r = td.getBoundingClientRect();
1946
- const distRight = Math.abs(event.clientX - r.right);
1947
- const distLeft = Math.abs(event.clientX - r.left);
1948
- const parent = td.parentElement;
1949
- if (!parent) return;
1950
- const colIdx = Array.from(parent.children).indexOf(td);
1951
- if (distRight <= 16 || distLeft <= 16 && colIdx > 0) {
1952
- isDragging = true;
1953
- hideLine();
1954
- const onDragEnd = function() {
1955
- isDragging = false;
1956
- hideLine();
1957
- document.removeEventListener("mouseup", onDragEnd, true);
1958
- };
1959
- document.addEventListener("mouseup", onDragEnd, true);
1960
- }
1961
- }, true);
1962
- return {
1963
- destroy: function() {
1964
- document.removeEventListener("mousemove", onMouseMoveHover, true);
1965
- if (lineEl && lineEl.parentElement) {
1966
- lineEl.parentElement.removeChild(lineEl);
1967
- }
1968
- lineEl = null;
1969
- hideLine();
1970
- }
1971
- };
1972
- }
1973
- })];
1974
- }
1975
- });
1976
2016
  let extensions = [
1977
2017
  ManualColumnResize,
1978
2018
  baseStarterKit,
1979
2019
  TextStyle,
1980
2020
  blockAttrs,
1981
2021
  paginationExt,
1982
- // Always present — fixes caret-on-click misplacement caused by the
1983
- // pagination DOM (header/footer/gap widgets breaking linear coordinates).
1984
- // No-op (gated at runtime) when pagination is off or disabled.
1985
- PaginationCaretFix,
1986
2022
  // Always present — carries host-injected ports (onImageUpload, citation, …)
1987
2023
  // in storage so plugin commands can reach them through the editor instance.
1988
2024
  EditorContextExtension.configure({
@@ -1997,18 +2033,9 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1997
2033
  ];
1998
2034
  const content = options.collaboration ? void 0 : options.content;
1999
2035
  if (options.collaboration && collaborationSetup) {
2000
- const seed = seedEmptyFragment(collaborationSetup.ydoc);
2001
- if (seed.seeded) {
2002
- extensions.push(
2003
- Extension6.create({
2004
- name: "provisionalSeedCleanup",
2005
- onDestroy: () => seed.dispose()
2006
- })
2007
- );
2008
- }
2009
2036
  extensions = [...extensions, ...collaborationExtensions(collaborationSetup)];
2010
2037
  }
2011
- const tiptapEditor = new TiptapEditor({
2038
+ return new TiptapEditor({
2012
2039
  element: options.target,
2013
2040
  content,
2014
2041
  extensions,
@@ -2023,11 +2050,10 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
2023
2050
  transformPastedHTML: sanitizePastedHTML
2024
2051
  }
2025
2052
  });
2026
- return tiptapEditor;
2027
2053
  }
2028
2054
 
2029
2055
  // src/FontSize.ts
2030
- import { Extension as Extension7 } from "@tiptap/core";
2056
+ import { Extension as Extension6 } from "@tiptap/core";
2031
2057
  function mergeFontSize(textStyleType, existing, fontSize) {
2032
2058
  if (fontSize === null) {
2033
2059
  const { fontSize: _removed, ...rest } = existing?.attrs ?? {};
@@ -2038,7 +2064,7 @@ function mergeFontSize(textStyleType, existing, fontSize) {
2038
2064
  function hasAttrs(mark) {
2039
2065
  return Object.values(mark.attrs).some((v) => v != null);
2040
2066
  }
2041
- var FontSizeExtension = Extension7.create({
2067
+ var FontSizeExtension = Extension6.create({
2042
2068
  name: "fontSize",
2043
2069
  addGlobalAttributes() {
2044
2070
  return [
@@ -2135,6 +2161,113 @@ var FontSizeExtension = Extension7.create({
2135
2161
  };
2136
2162
  }
2137
2163
  });
2164
+
2165
+ // src/SubdocumentProvider.ts
2166
+ import { Awareness as AwarenessClass } from "y-protocols/awareness";
2167
+ import { WebsocketProvider as WebsocketProvider2 } from "y-websocket";
2168
+ import * as Y2 from "yjs";
2169
+ var SubdocumentProvider = class {
2170
+ parentDoc;
2171
+ subdocs;
2172
+ awareness;
2173
+ options;
2174
+ states = /* @__PURE__ */ new Map();
2175
+ activeQueue = [];
2176
+ parentProvider = null;
2177
+ constructor(options) {
2178
+ this.options = {
2179
+ maxActive: options.maxActive ?? 5,
2180
+ onStateChange: options.onStateChange ?? (() => {
2181
+ }),
2182
+ ...options
2183
+ };
2184
+ this.parentDoc = new Y2.Doc();
2185
+ this.subdocs = this.parentDoc.getMap("subdocs");
2186
+ this.awareness = new AwarenessClass(this.parentDoc);
2187
+ this.awareness.setLocalStateField("user", this.options.user);
2188
+ this.parentProvider = new WebsocketProvider2(
2189
+ this.options.websocketUrl,
2190
+ `${this.options.roomPrefix}/_parent`,
2191
+ this.parentDoc
2192
+ );
2193
+ }
2194
+ /** Create a new subdocument. Does NOT activate it. */
2195
+ createSubdoc(id, initialState) {
2196
+ if (this.states.has(id)) return this.states.get(id).doc;
2197
+ const doc = new Y2.Doc();
2198
+ if (initialState) Y2.applyUpdate(doc, initialState);
2199
+ doc.getXmlFragment("default");
2200
+ this.subdocs.set(id, doc);
2201
+ this.states.set(id, {
2202
+ id,
2203
+ doc,
2204
+ provider: null,
2205
+ active: false
2206
+ });
2207
+ this.options.onStateChange(this.getAllStates());
2208
+ return doc;
2209
+ }
2210
+ /** Activate a subdocument — connects it to the network for live sync. */
2211
+ activate(id) {
2212
+ const state = this.states.get(id);
2213
+ if (!state || state.active) return;
2214
+ if (this.activeQueue.length >= this.options.maxActive) {
2215
+ const oldest = this.activeQueue.shift();
2216
+ if (oldest) this.deactivate(oldest);
2217
+ }
2218
+ const doc = state.doc;
2219
+ const roomName = `${this.options.roomPrefix}/${id}`;
2220
+ const provider = new WebsocketProvider2(
2221
+ this.options.websocketUrl,
2222
+ roomName,
2223
+ doc
2224
+ );
2225
+ provider.awareness.setLocalStateField("user", this.options.user);
2226
+ state.provider = provider;
2227
+ state.active = true;
2228
+ this.activeQueue.push(id);
2229
+ this.options.onStateChange(this.getAllStates());
2230
+ }
2231
+ /** Deactivate a subdocument — disconnects it from the network. */
2232
+ deactivate(id) {
2233
+ const state = this.states.get(id);
2234
+ if (!state || !state.active) return;
2235
+ state.provider?.destroy();
2236
+ state.provider = null;
2237
+ state.active = false;
2238
+ const idx = this.activeQueue.indexOf(id);
2239
+ if (idx >= 0) this.activeQueue.splice(idx, 1);
2240
+ this.options.onStateChange(this.getAllStates());
2241
+ }
2242
+ /** Get the Y.XmlFragment for a subdocument. */
2243
+ getFragment(id) {
2244
+ const doc = this.states.get(id)?.doc ?? this.subdocs.get(id);
2245
+ if (!doc) return null;
2246
+ return doc.getXmlFragment("default");
2247
+ }
2248
+ /** Check if a subdocument is currently active (syncing). */
2249
+ isActive(id) {
2250
+ return this.states.get(id)?.active ?? false;
2251
+ }
2252
+ /** Get all subdocument states. */
2253
+ getAllStates() {
2254
+ return Array.from(this.states.values());
2255
+ }
2256
+ /** Get IDs of all active subdocuments. */
2257
+ getActiveIds() {
2258
+ return [...this.activeQueue];
2259
+ }
2260
+ /** Destroy all subdocuments and providers. */
2261
+ destroy() {
2262
+ for (const [id] of this.states) {
2263
+ this.deactivate(id);
2264
+ }
2265
+ this.parentProvider?.destroy();
2266
+ this.parentDoc.destroy();
2267
+ this.states.clear();
2268
+ this.activeQueue.length = 0;
2269
+ }
2270
+ };
2138
2271
  export {
2139
2272
  BlockAttributesExtension,
2140
2273
  CONTEXT_CHAR_CAP,
@@ -2145,6 +2278,7 @@ export {
2145
2278
  PaginationPlus,
2146
2279
  PerformanceMonitor,
2147
2280
  SearchAndReplaceExtension,
2281
+ SubdocumentProvider,
2148
2282
  buildAIPrompt,
2149
2283
  clearSearch,
2150
2284
  collaborationExtensions,