@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/LICENSE +201 -44
- package/README.md +39 -0
- package/dist/ai/index.d.cts +1 -1
- package/dist/ai/index.d.ts +1 -1
- package/dist/{index-BTF6gajh.d.cts → index-BsIFJXPk.d.cts} +3 -35
- package/dist/{index-BTF6gajh.d.ts → index-BsIFJXPk.d.ts} +3 -35
- package/dist/index.cjs +978 -975
- package/dist/index.d.cts +151 -99
- package/dist/index.d.ts +151 -99
- package/dist/index.js +1108 -974
- package/package.json +2 -7
- package/dist/Collaboration-CGv9OZlB.d.cts +0 -109
- package/dist/Collaboration-CGv9OZlB.d.ts +0 -109
- package/dist/chunk-XJG72F7M.js +0 -140
- package/dist/collab/index.cjs +0 -286
- package/dist/collab/index.d.cts +0 -71
- package/dist/collab/index.d.ts +0 -71
- package/dist/collab/index.js +0 -116
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
PaginationPlus: () => PaginationPlus,
|
|
40
40
|
PerformanceMonitor: () => PerformanceMonitor,
|
|
41
41
|
SearchAndReplaceExtension: () => SearchAndReplaceExtension,
|
|
42
|
+
SubdocumentProvider: () => SubdocumentProvider,
|
|
42
43
|
buildAIPrompt: () => buildAIPrompt,
|
|
43
44
|
clearSearch: () => clearSearch,
|
|
44
45
|
collaborationExtensions: () => collaborationExtensions,
|
|
@@ -72,7 +73,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
72
73
|
|
|
73
74
|
// src/Editor.ts
|
|
74
75
|
var import_core6 = require("@tiptap/core");
|
|
75
|
-
var import_state5 = require("@tiptap/pm/state");
|
|
76
76
|
var import_starter_kit = __toESM(require("@tiptap/starter-kit"), 1);
|
|
77
77
|
var import_extension_text_style = __toESM(require("@tiptap/extension-text-style"), 1);
|
|
78
78
|
|
|
@@ -127,6 +127,9 @@ function createActionMap(editor, plugins) {
|
|
|
127
127
|
var import_extension_collaboration = require("@tiptap/extension-collaboration");
|
|
128
128
|
var import_extension_collaboration_cursor = require("@tiptap/extension-collaboration-cursor");
|
|
129
129
|
var import_awareness = require("y-protocols/awareness");
|
|
130
|
+
var import_y_indexeddb = require("y-indexeddb");
|
|
131
|
+
var import_y_webrtc = require("y-webrtc");
|
|
132
|
+
var import_y_websocket = require("y-websocket");
|
|
130
133
|
var Y = __toESM(require("yjs"), 1);
|
|
131
134
|
var LOCAL_SIGNALING = ["ws://localhost:4444"];
|
|
132
135
|
var warnedLocalSignaling = false;
|
|
@@ -157,28 +160,25 @@ function createAwarenessStates(awareness) {
|
|
|
157
160
|
});
|
|
158
161
|
return states;
|
|
159
162
|
}
|
|
160
|
-
|
|
163
|
+
function createCollaboration(options) {
|
|
161
164
|
const ydoc = new Y.Doc();
|
|
162
165
|
if (options.initialStorageState) {
|
|
163
166
|
Y.applyUpdate(ydoc, options.initialStorageState);
|
|
164
167
|
}
|
|
165
168
|
let persistence;
|
|
166
169
|
if (options.offline) {
|
|
167
|
-
|
|
168
|
-
persistence = new IndexeddbPersistence(`docflow-${options.room}`, ydoc);
|
|
170
|
+
persistence = new import_y_indexeddb.IndexeddbPersistence(`docflow-${options.room}`, ydoc);
|
|
169
171
|
}
|
|
170
172
|
let provider = null;
|
|
171
173
|
if (options.provider === "webrtc") {
|
|
172
|
-
|
|
173
|
-
provider = new WebrtcProvider(options.room, ydoc, {
|
|
174
|
+
provider = new import_y_webrtc.WebrtcProvider(options.room, ydoc, {
|
|
174
175
|
signaling: resolveSignalingUrls(options.signaling)
|
|
175
176
|
});
|
|
176
177
|
} else if (options.provider === "websocket") {
|
|
177
178
|
if (!options.websocketUrl) {
|
|
178
179
|
throw new Error('[Collaboration] websocketUrl is required when provider is "websocket"');
|
|
179
180
|
}
|
|
180
|
-
|
|
181
|
-
provider = new WebsocketProvider(options.websocketUrl, options.room, ydoc);
|
|
181
|
+
provider = new import_y_websocket.WebsocketProvider(options.websocketUrl, options.room, ydoc);
|
|
182
182
|
}
|
|
183
183
|
const awareness = provider?.awareness ?? new import_awareness.Awareness(ydoc);
|
|
184
184
|
awareness.setLocalStateField("user", options.user);
|
|
@@ -244,7 +244,8 @@ async function createCollaboration(options) {
|
|
|
244
244
|
};
|
|
245
245
|
return { ydoc, provider, awareness, persistence, whenReady, destroy, setLocalCursorEnabled };
|
|
246
246
|
}
|
|
247
|
-
function collaborationExtensions(
|
|
247
|
+
function collaborationExtensions(options) {
|
|
248
|
+
const setup = "ydoc" in options ? options : createCollaboration(options);
|
|
248
249
|
const extensions = [
|
|
249
250
|
import_extension_collaboration.Collaboration.configure({ document: setup.ydoc })
|
|
250
251
|
];
|
|
@@ -320,42 +321,6 @@ var BlockAttributesExtension = import_core.Extension.create({
|
|
|
320
321
|
}
|
|
321
322
|
});
|
|
322
323
|
|
|
323
|
-
// src/collab/seedEmptyFragment.ts
|
|
324
|
-
var Y2 = __toESM(require("yjs"), 1);
|
|
325
|
-
var PROVISIONAL_SEED_ORIGIN = "docflow:provisional-seed";
|
|
326
|
-
function isPristineEmptyParagraph(element) {
|
|
327
|
-
return element.length === 0 && Object.keys(element.getAttributes()).length === 0;
|
|
328
|
-
}
|
|
329
|
-
function seedEmptyFragment(doc, field = "default") {
|
|
330
|
-
const fragment = doc.getXmlFragment(field);
|
|
331
|
-
const paragraph = new Y2.XmlElement("paragraph");
|
|
332
|
-
const observer = (_events, transaction) => {
|
|
333
|
-
if (transaction.origin === PROVISIONAL_SEED_ORIGIN) return;
|
|
334
|
-
if (paragraph.parent !== fragment) return;
|
|
335
|
-
if (!isPristineEmptyParagraph(paragraph)) return;
|
|
336
|
-
if (fragment.length < 2) return;
|
|
337
|
-
const index = fragment.toArray().indexOf(paragraph);
|
|
338
|
-
if (index === -1) return;
|
|
339
|
-
doc.transact(() => {
|
|
340
|
-
fragment.delete(index);
|
|
341
|
-
}, PROVISIONAL_SEED_ORIGIN);
|
|
342
|
-
};
|
|
343
|
-
let disposed = false;
|
|
344
|
-
const dispose = () => {
|
|
345
|
-
if (disposed) return;
|
|
346
|
-
disposed = true;
|
|
347
|
-
fragment.unobserveDeep(observer);
|
|
348
|
-
};
|
|
349
|
-
if (fragment.length > 0) {
|
|
350
|
-
return { seeded: false, dispose };
|
|
351
|
-
}
|
|
352
|
-
fragment.observeDeep(observer);
|
|
353
|
-
doc.transact(() => {
|
|
354
|
-
fragment.insert(0, [paragraph]);
|
|
355
|
-
}, PROVISIONAL_SEED_ORIGIN);
|
|
356
|
-
return { seeded: true, dispose };
|
|
357
|
-
}
|
|
358
|
-
|
|
359
324
|
// src/EditorContext.ts
|
|
360
325
|
var import_core2 = require("@tiptap/core");
|
|
361
326
|
var EditorContextExtension = import_core2.Extension.create({
|
|
@@ -378,11 +343,336 @@ var EditorContextExtension = import_core2.Extension.create({
|
|
|
378
343
|
}
|
|
379
344
|
});
|
|
380
345
|
|
|
381
|
-
// src/
|
|
346
|
+
// src/ManualColumnResize.ts
|
|
382
347
|
var import_core3 = require("@tiptap/core");
|
|
383
348
|
var import_state2 = require("@tiptap/pm/state");
|
|
349
|
+
var ManualColumnResize = import_core3.Extension.create({
|
|
350
|
+
name: "manualColumnResize",
|
|
351
|
+
addProseMirrorPlugins() {
|
|
352
|
+
const key2 = new import_state2.PluginKey("manualColumnResize");
|
|
353
|
+
return [new import_state2.Plugin({
|
|
354
|
+
key: key2,
|
|
355
|
+
view(view) {
|
|
356
|
+
const observer = view;
|
|
357
|
+
function pauseObserver() {
|
|
358
|
+
try {
|
|
359
|
+
observer.domObserver?.stop?.();
|
|
360
|
+
} catch (_) {
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
function resumeObserver() {
|
|
364
|
+
try {
|
|
365
|
+
observer.domObserver?.start?.();
|
|
366
|
+
} catch (_) {
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function getMaxContainerWidth(tableEl) {
|
|
370
|
+
let curr = tableEl.parentElement;
|
|
371
|
+
while (curr) {
|
|
372
|
+
const style = window.getComputedStyle(curr);
|
|
373
|
+
const paddingLeft = parseFloat(style.paddingLeft) || 0;
|
|
374
|
+
const paddingRight = parseFloat(style.paddingRight) || 0;
|
|
375
|
+
const availWidth = curr.clientWidth - paddingLeft - paddingRight;
|
|
376
|
+
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"))) {
|
|
377
|
+
return availWidth;
|
|
378
|
+
}
|
|
379
|
+
curr = curr.parentElement;
|
|
380
|
+
}
|
|
381
|
+
return tableEl.parentElement?.clientWidth || 614;
|
|
382
|
+
}
|
|
383
|
+
const onMouseDown = function(event) {
|
|
384
|
+
if (event.button !== 0) return;
|
|
385
|
+
const td = event.target.closest("td, th");
|
|
386
|
+
if (!td) return;
|
|
387
|
+
const r = td.getBoundingClientRect();
|
|
388
|
+
const parent = td.parentElement;
|
|
389
|
+
if (!parent) return;
|
|
390
|
+
const cellColSpan = td.colSpan || 1;
|
|
391
|
+
let logicalStart = 0;
|
|
392
|
+
let foundCell = false;
|
|
393
|
+
for (const sibling of Array.from(parent.children)) {
|
|
394
|
+
if (sibling === td) {
|
|
395
|
+
foundCell = true;
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
logicalStart += sibling.colSpan || 1;
|
|
399
|
+
}
|
|
400
|
+
if (!foundCell) return;
|
|
401
|
+
const table = td.closest("table");
|
|
402
|
+
if (!table) return;
|
|
403
|
+
const distRight = Math.abs(event.clientX - r.right);
|
|
404
|
+
const distLeft = Math.abs(event.clientX - r.left);
|
|
405
|
+
let targetColIdx = -1;
|
|
406
|
+
if (distRight <= 16) {
|
|
407
|
+
targetColIdx = logicalStart + cellColSpan - 1;
|
|
408
|
+
} else if (distLeft <= 16 && logicalStart > 0) {
|
|
409
|
+
targetColIdx = logicalStart - 1;
|
|
410
|
+
} else {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const colsList = table.querySelectorAll("colgroup col");
|
|
414
|
+
const totalCols = colsList.length || table.querySelector("tr")?.children.length || 0;
|
|
415
|
+
const allColWidths = [];
|
|
416
|
+
for (let c = 0; c < totalCols; c++) {
|
|
417
|
+
const colEl = colsList[c];
|
|
418
|
+
const w = colEl ? parseFloat(colEl.style.width) : 0;
|
|
419
|
+
allColWidths[c] = w || initialWidth(table, c);
|
|
420
|
+
}
|
|
421
|
+
const isLastCol = targetColIdx === totalCols - 1;
|
|
422
|
+
const neighborIdx = targetColIdx + 1;
|
|
423
|
+
const startX = event.clientX;
|
|
424
|
+
const startW = allColWidths[targetColIdx] || initialWidth(table, targetColIdx);
|
|
425
|
+
const startNeighborW = !isLastCol ? allColWidths[neighborIdx] || initialWidth(table, neighborIdx) : 0;
|
|
426
|
+
const maxContainerW = getMaxContainerWidth(table);
|
|
427
|
+
let otherColsW = 0;
|
|
428
|
+
allColWidths.forEach((w, idx) => {
|
|
429
|
+
if (idx !== targetColIdx) otherColsW += w;
|
|
430
|
+
});
|
|
431
|
+
const maxNwLastCol = Math.max(20, maxContainerW - otherColsW);
|
|
432
|
+
function updateDOMWidths() {
|
|
433
|
+
let totalWidth = 0;
|
|
434
|
+
allColWidths.forEach((w, idx) => {
|
|
435
|
+
const col = table.querySelector(`colgroup col:nth-child(${idx + 1})`);
|
|
436
|
+
if (col) col.style.setProperty("width", w + "px", "important");
|
|
437
|
+
table.querySelectorAll("tr").forEach(function(row) {
|
|
438
|
+
const cell = row.children[idx];
|
|
439
|
+
if (cell) {
|
|
440
|
+
cell.style.setProperty("width", w + "px", "important");
|
|
441
|
+
cell.setAttribute("width", String(w));
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
totalWidth += w;
|
|
445
|
+
});
|
|
446
|
+
if (totalWidth > 0) {
|
|
447
|
+
table.style.setProperty("width", Math.min(totalWidth, maxContainerW) + "px", "important");
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
event.stopPropagation();
|
|
451
|
+
let lastNw = startW;
|
|
452
|
+
const onMove = function(e) {
|
|
453
|
+
if (!e.buttons) {
|
|
454
|
+
onUp(e);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const rawDiff = e.clientX - startX;
|
|
458
|
+
if (isLastCol) {
|
|
459
|
+
const nw = Math.min(maxNwLastCol, Math.max(20, startW + rawDiff));
|
|
460
|
+
allColWidths[targetColIdx] = nw;
|
|
461
|
+
lastNw = nw;
|
|
462
|
+
} else {
|
|
463
|
+
const delta = Math.max(20 - startW, Math.min(rawDiff, startNeighborW - 20));
|
|
464
|
+
allColWidths[targetColIdx] = startW + delta;
|
|
465
|
+
allColWidths[neighborIdx] = startNeighborW - delta;
|
|
466
|
+
lastNw = allColWidths[targetColIdx];
|
|
467
|
+
}
|
|
468
|
+
let borderPos = table.getBoundingClientRect().left;
|
|
469
|
+
for (let i = 0; i <= targetColIdx; i++) borderPos += allColWidths[i];
|
|
470
|
+
showLine(table, borderPos);
|
|
471
|
+
pauseObserver();
|
|
472
|
+
updateDOMWidths();
|
|
473
|
+
resumeObserver();
|
|
474
|
+
};
|
|
475
|
+
const onUp = function(upEvent) {
|
|
476
|
+
document.removeEventListener("mousemove", onMove);
|
|
477
|
+
document.removeEventListener("mouseup", onUp, true);
|
|
478
|
+
upEvent.stopPropagation();
|
|
479
|
+
hideLine();
|
|
480
|
+
if (lastNw === startW) return;
|
|
481
|
+
try {
|
|
482
|
+
const { state } = view;
|
|
483
|
+
const { doc } = state;
|
|
484
|
+
let tablePos = -1;
|
|
485
|
+
doc.descendants((node, pos) => {
|
|
486
|
+
if (tablePos >= 0) return false;
|
|
487
|
+
if (node.type.name === "table") {
|
|
488
|
+
try {
|
|
489
|
+
const dom = view.nodeDOM(pos);
|
|
490
|
+
if (dom === table || dom instanceof HTMLElement && dom.contains(table) || table.contains(dom)) {
|
|
491
|
+
tablePos = pos;
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
} catch (_) {
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return true;
|
|
498
|
+
});
|
|
499
|
+
if (tablePos >= 0) {
|
|
500
|
+
const tableNode = doc.nodeAt(tablePos);
|
|
501
|
+
if (tableNode) {
|
|
502
|
+
const tr = state.tr;
|
|
503
|
+
tableNode.forEach((row, rowOffset) => {
|
|
504
|
+
let cellColIdx = 0;
|
|
505
|
+
row.forEach((cell, cellOffset) => {
|
|
506
|
+
const colspan = cell.attrs.colspan || 1;
|
|
507
|
+
const cellPos = tablePos + 1 + rowOffset + 1 + cellOffset;
|
|
508
|
+
const cw = new Array(colspan);
|
|
509
|
+
for (let k = 0; k < colspan; k++) {
|
|
510
|
+
cw[k] = allColWidths[cellColIdx + k] || 100;
|
|
511
|
+
}
|
|
512
|
+
tr.setNodeMarkup(cellPos, null, { ...cell.attrs, colwidth: cw });
|
|
513
|
+
cellColIdx += colspan;
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
view.dispatch(tr);
|
|
517
|
+
pauseObserver();
|
|
518
|
+
updateDOMWidths();
|
|
519
|
+
resumeObserver();
|
|
520
|
+
}
|
|
521
|
+
} else {
|
|
522
|
+
console.warn("[Resize] could not find table position in doc");
|
|
523
|
+
}
|
|
524
|
+
} catch (err) {
|
|
525
|
+
console.warn("[Resize] transaction failed, falling back to DOM:", err);
|
|
526
|
+
pauseObserver();
|
|
527
|
+
updateDOMWidths();
|
|
528
|
+
resumeObserver();
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
document.addEventListener("mousemove", onMove);
|
|
532
|
+
document.addEventListener("mouseup", onUp, true);
|
|
533
|
+
};
|
|
534
|
+
function initialWidth(table, colIdx) {
|
|
535
|
+
const firstRow = table.querySelector("tr");
|
|
536
|
+
if (!firstRow) return 100;
|
|
537
|
+
const cell = firstRow.children[colIdx];
|
|
538
|
+
if (!cell) return 100;
|
|
539
|
+
return Math.round(cell.getBoundingClientRect().width) || cell.offsetWidth || 100;
|
|
540
|
+
}
|
|
541
|
+
let lineEl = null;
|
|
542
|
+
let isDragging = false;
|
|
543
|
+
function getOrCreateLine() {
|
|
544
|
+
if (!lineEl) {
|
|
545
|
+
lineEl = document.createElement("div");
|
|
546
|
+
lineEl.className = "docflow-active-border-line";
|
|
547
|
+
Object.assign(lineEl.style, {
|
|
548
|
+
position: "fixed",
|
|
549
|
+
width: "3px",
|
|
550
|
+
background: "#06b6d4",
|
|
551
|
+
boxShadow: "0 0 8px rgba(6, 182, 212, 0.9)",
|
|
552
|
+
pointerEvents: "none",
|
|
553
|
+
zIndex: "999999",
|
|
554
|
+
display: "none",
|
|
555
|
+
borderRadius: "1.5px"
|
|
556
|
+
});
|
|
557
|
+
const dotTop = document.createElement("div");
|
|
558
|
+
Object.assign(dotTop.style, {
|
|
559
|
+
position: "absolute",
|
|
560
|
+
top: "-4px",
|
|
561
|
+
left: "-3.5px",
|
|
562
|
+
width: "10px",
|
|
563
|
+
height: "10px",
|
|
564
|
+
borderRadius: "50%",
|
|
565
|
+
background: "#ffffff",
|
|
566
|
+
border: "2px solid #06b6d4"
|
|
567
|
+
});
|
|
568
|
+
const dotBottom = document.createElement("div");
|
|
569
|
+
Object.assign(dotBottom.style, {
|
|
570
|
+
position: "absolute",
|
|
571
|
+
bottom: "-4px",
|
|
572
|
+
left: "-3.5px",
|
|
573
|
+
width: "10px",
|
|
574
|
+
height: "10px",
|
|
575
|
+
borderRadius: "50%",
|
|
576
|
+
background: "#ffffff",
|
|
577
|
+
border: "2px solid #06b6d4"
|
|
578
|
+
});
|
|
579
|
+
lineEl.appendChild(dotTop);
|
|
580
|
+
lineEl.appendChild(dotBottom);
|
|
581
|
+
document.body.appendChild(lineEl);
|
|
582
|
+
}
|
|
583
|
+
return lineEl;
|
|
584
|
+
}
|
|
585
|
+
function showLine(table, borderX) {
|
|
586
|
+
const line = getOrCreateLine();
|
|
587
|
+
const tableRect = table.getBoundingClientRect();
|
|
588
|
+
line.style.left = `${borderX - 1.5}px`;
|
|
589
|
+
line.style.top = `${tableRect.top}px`;
|
|
590
|
+
line.style.height = `${tableRect.height}px`;
|
|
591
|
+
line.style.display = "block";
|
|
592
|
+
document.body.style.cursor = "col-resize";
|
|
593
|
+
view.dom.style.cursor = "col-resize";
|
|
594
|
+
}
|
|
595
|
+
function hideLine() {
|
|
596
|
+
if (lineEl) {
|
|
597
|
+
lineEl.style.display = "none";
|
|
598
|
+
}
|
|
599
|
+
document.body.style.cursor = "";
|
|
600
|
+
view.dom.style.cursor = "";
|
|
601
|
+
}
|
|
602
|
+
const onMouseMoveHover = function(event) {
|
|
603
|
+
if (isDragging) return;
|
|
604
|
+
const target = event.target;
|
|
605
|
+
const td = target.closest("td, th");
|
|
606
|
+
if (!td) {
|
|
607
|
+
hideLine();
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
const r = td.getBoundingClientRect();
|
|
611
|
+
const distRight = Math.abs(event.clientX - r.right);
|
|
612
|
+
const distLeft = Math.abs(event.clientX - r.left);
|
|
613
|
+
const parent = td.parentElement;
|
|
614
|
+
if (!parent) {
|
|
615
|
+
hideLine();
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const colIdx = Array.from(parent.children).indexOf(td);
|
|
619
|
+
let borderX = -1;
|
|
620
|
+
if (distRight <= 16) {
|
|
621
|
+
borderX = r.right;
|
|
622
|
+
} else if (distLeft <= 16 && colIdx > 0) {
|
|
623
|
+
borderX = r.left;
|
|
624
|
+
}
|
|
625
|
+
if (borderX >= 0) {
|
|
626
|
+
const table = td.closest("table");
|
|
627
|
+
if (table) {
|
|
628
|
+
showLine(table, borderX);
|
|
629
|
+
}
|
|
630
|
+
} else {
|
|
631
|
+
hideLine();
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
document.addEventListener("mousemove", onMouseMoveHover, true);
|
|
635
|
+
view.dom.addEventListener("mousedown", function handleMouseDown(event) {
|
|
636
|
+
onMouseDown(event);
|
|
637
|
+
const td = event.target.closest("td, th");
|
|
638
|
+
if (!td) return;
|
|
639
|
+
const r = td.getBoundingClientRect();
|
|
640
|
+
const distRight = Math.abs(event.clientX - r.right);
|
|
641
|
+
const distLeft = Math.abs(event.clientX - r.left);
|
|
642
|
+
const parent = td.parentElement;
|
|
643
|
+
if (!parent) return;
|
|
644
|
+
const colIdx = Array.from(parent.children).indexOf(td);
|
|
645
|
+
if (distRight <= 16 || distLeft <= 16 && colIdx > 0) {
|
|
646
|
+
isDragging = true;
|
|
647
|
+
hideLine();
|
|
648
|
+
const onDragEnd = function() {
|
|
649
|
+
isDragging = false;
|
|
650
|
+
hideLine();
|
|
651
|
+
document.removeEventListener("mouseup", onDragEnd, true);
|
|
652
|
+
};
|
|
653
|
+
document.addEventListener("mouseup", onDragEnd, true);
|
|
654
|
+
}
|
|
655
|
+
}, true);
|
|
656
|
+
return {
|
|
657
|
+
destroy: function() {
|
|
658
|
+
document.removeEventListener("mousemove", onMouseMoveHover, true);
|
|
659
|
+
if (lineEl && lineEl.parentElement) {
|
|
660
|
+
lineEl.parentElement.removeChild(lineEl);
|
|
661
|
+
}
|
|
662
|
+
lineEl = null;
|
|
663
|
+
hideLine();
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
})];
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
// src/SearchAndReplace.ts
|
|
672
|
+
var import_core4 = require("@tiptap/core");
|
|
673
|
+
var import_state3 = require("@tiptap/pm/state");
|
|
384
674
|
var import_view2 = require("@tiptap/pm/view");
|
|
385
|
-
var searchAndReplaceKey = new
|
|
675
|
+
var searchAndReplaceKey = new import_state3.PluginKey("searchAndReplace");
|
|
386
676
|
var EMPTY_STATE = { query: "", matches: [], activeIndex: 0 };
|
|
387
677
|
function findMatches(doc, query) {
|
|
388
678
|
const matches = [];
|
|
@@ -407,7 +697,7 @@ function computeState(doc, query, activeIndex = 0) {
|
|
|
407
697
|
const matches = findMatches(doc, query);
|
|
408
698
|
return { query, matches, activeIndex: clampIndex(activeIndex, matches) };
|
|
409
699
|
}
|
|
410
|
-
var searchPlugin = new
|
|
700
|
+
var searchPlugin = new import_state3.Plugin({
|
|
411
701
|
key: searchAndReplaceKey,
|
|
412
702
|
state: {
|
|
413
703
|
init: () => EMPTY_STATE,
|
|
@@ -439,7 +729,7 @@ var searchPlugin = new import_state2.Plugin({
|
|
|
439
729
|
}
|
|
440
730
|
}
|
|
441
731
|
});
|
|
442
|
-
var SearchAndReplaceExtension =
|
|
732
|
+
var SearchAndReplaceExtension = import_core4.Extension.create({
|
|
443
733
|
name: "searchAndReplace",
|
|
444
734
|
addProseMirrorPlugins() {
|
|
445
735
|
return [searchPlugin];
|
|
@@ -459,7 +749,7 @@ function activateMatch(editor, index) {
|
|
|
459
749
|
const match = s.matches[index];
|
|
460
750
|
const tr = editor.state.tr.setMeta(searchAndReplaceKey, { type: "setActive", index });
|
|
461
751
|
if (match) {
|
|
462
|
-
tr.setSelection(
|
|
752
|
+
tr.setSelection(import_state3.TextSelection.create(editor.state.doc, match.from, match.to));
|
|
463
753
|
tr.scrollIntoView();
|
|
464
754
|
}
|
|
465
755
|
editor.view.dispatch(tr);
|
|
@@ -496,13 +786,13 @@ function replaceAll(editor, replacement) {
|
|
|
496
786
|
return s.matches.length;
|
|
497
787
|
}
|
|
498
788
|
|
|
499
|
-
//
|
|
500
|
-
var
|
|
501
|
-
var
|
|
789
|
+
// ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js
|
|
790
|
+
var import_core5 = require("@tiptap/core");
|
|
791
|
+
var import_state4 = require("@tiptap/pm/state");
|
|
502
792
|
var import_transform = require("@tiptap/pm/transform");
|
|
503
793
|
var import_view3 = require("@tiptap/pm/view");
|
|
504
794
|
|
|
505
|
-
//
|
|
795
|
+
// ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/utils.js
|
|
506
796
|
var updateCssVariables = (targetNode, config) => {
|
|
507
797
|
const cssVariables = {
|
|
508
798
|
"rm-page-height": `${config.pageHeight}px`,
|
|
@@ -529,32 +819,75 @@ var getPageSize = (height, width, marginTop, marginBottom, marginLeft, marginRig
|
|
|
529
819
|
marginRight
|
|
530
820
|
};
|
|
531
821
|
};
|
|
532
|
-
var getHeaderHeightSelector = (pageNumber, type) => {
|
|
533
|
-
return type === "actual" ? `.rm-page-header-${pageNumber}` : `.rm-page-header-${pageNumber} .rm-page-header-content`;
|
|
534
|
-
};
|
|
535
822
|
var getHeaderHeight = (targetNode, pageNumbers, type) => {
|
|
536
823
|
const headerHeightMap = /* @__PURE__ */ new Map();
|
|
537
824
|
const clientHeader = targetNode.querySelector(getHeaderHeightSelector(0, type));
|
|
538
825
|
headerHeightMap.set(0, clientHeader ? clientHeader.clientHeight : 0);
|
|
539
826
|
pageNumbers.forEach((pageNumber) => {
|
|
540
|
-
const
|
|
541
|
-
|
|
827
|
+
const clientHeader2 = targetNode.querySelector(getHeaderHeightSelector(pageNumber, type));
|
|
828
|
+
const headerHeight = clientHeader2 ? clientHeader2.clientHeight : 0;
|
|
829
|
+
headerHeightMap.set(pageNumber, headerHeight);
|
|
542
830
|
});
|
|
543
831
|
return headerHeightMap;
|
|
544
832
|
};
|
|
545
|
-
var
|
|
546
|
-
return type === "actual" ? `.rm-page-
|
|
833
|
+
var getHeaderHeightSelector = (pageNumber, type) => {
|
|
834
|
+
return type === "actual" ? `.rm-page-header-${pageNumber}` : `.rm-page-header-${pageNumber} .rm-page-header-content`;
|
|
547
835
|
};
|
|
548
836
|
var getFooterHeight = (targetNode, pageNumbers, type) => {
|
|
549
837
|
const footerHeightMap = /* @__PURE__ */ new Map();
|
|
550
838
|
const clientFooter = targetNode.querySelector(getFooterHeightSelector(0, type));
|
|
551
839
|
footerHeightMap.set(0, clientFooter ? clientFooter.clientHeight : 0);
|
|
552
840
|
pageNumbers.forEach((pageNumber) => {
|
|
553
|
-
const
|
|
554
|
-
|
|
841
|
+
const clientFooter2 = targetNode.querySelector(getFooterHeightSelector(pageNumber, type));
|
|
842
|
+
const footerHeight = clientFooter2 ? clientFooter2.clientHeight : 0;
|
|
843
|
+
footerHeightMap.set(pageNumber, footerHeight);
|
|
555
844
|
});
|
|
556
845
|
return footerHeightMap;
|
|
557
846
|
};
|
|
847
|
+
var getFooterHeightSelector = (pageNumber, type) => {
|
|
848
|
+
return type === "actual" ? `.rm-page-footer-${pageNumber}` : `.rm-page-footer-${pageNumber} .rm-page-footer-content`;
|
|
849
|
+
};
|
|
850
|
+
function deepEqualIterative(a, b) {
|
|
851
|
+
if (a === b)
|
|
852
|
+
return true;
|
|
853
|
+
if (typeof a !== "object" || typeof b !== "object" || a == null || b == null) {
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
const stack = [{ x: a, y: b }];
|
|
857
|
+
while (stack.length) {
|
|
858
|
+
const _stackItem = stack.pop();
|
|
859
|
+
if (!_stackItem)
|
|
860
|
+
continue;
|
|
861
|
+
const { x, y } = _stackItem;
|
|
862
|
+
if (x === y)
|
|
863
|
+
continue;
|
|
864
|
+
if (typeof x !== typeof y)
|
|
865
|
+
return false;
|
|
866
|
+
if (typeof x !== "object")
|
|
867
|
+
return false;
|
|
868
|
+
if (x == null || y == null)
|
|
869
|
+
return false;
|
|
870
|
+
const xKeys = Object.keys(x);
|
|
871
|
+
const yKeys = Object.keys(y);
|
|
872
|
+
if (xKeys.length !== yKeys.length)
|
|
873
|
+
return false;
|
|
874
|
+
for (const key2 of xKeys) {
|
|
875
|
+
if (!(key2 in y))
|
|
876
|
+
return false;
|
|
877
|
+
const xVal = x[key2];
|
|
878
|
+
const yVal = y[key2];
|
|
879
|
+
if (xVal === yVal)
|
|
880
|
+
continue;
|
|
881
|
+
if (typeof xVal === "object" && typeof yVal === "object") {
|
|
882
|
+
stack.push({ x: xVal, y: yVal });
|
|
883
|
+
} else {
|
|
884
|
+
if (xVal !== yVal)
|
|
885
|
+
return false;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
return true;
|
|
890
|
+
}
|
|
558
891
|
function getCustomPages(customHeader, customFooter) {
|
|
559
892
|
return [...Object.keys(customHeader), ...Object.keys(customFooter)].map(Number);
|
|
560
893
|
}
|
|
@@ -569,8 +902,8 @@ function getFooter(footerRightContent, footerLeftContent, onFooterClick, pageNum
|
|
|
569
902
|
pageFooterContent.classList.add("rm-page-footer-content");
|
|
570
903
|
pageFooterContent.style.width = "100%";
|
|
571
904
|
pageFooterContent.style.overflow = "hidden";
|
|
572
|
-
const footerRight =
|
|
573
|
-
const footerLeft =
|
|
905
|
+
const footerRight = footerRightContent.replace("{page}", `<span class="rm-page-number"></span>`);
|
|
906
|
+
const footerLeft = footerLeftContent.replace("{page}", `<span class="rm-page-number"></span>`);
|
|
574
907
|
const pageFooterLeft = document.createElement("div");
|
|
575
908
|
pageFooterLeft.classList.add("rm-page-footer-left");
|
|
576
909
|
pageFooterLeft.innerHTML = footerLeft;
|
|
@@ -593,8 +926,8 @@ function getHeader(headerRightContent, headerLeftContent, onHeaderClick, pageNum
|
|
|
593
926
|
pageHeaderContent.classList.add("rm-page-header-content");
|
|
594
927
|
pageHeaderContent.style.width = "100%";
|
|
595
928
|
pageHeaderContent.style.overflow = "hidden";
|
|
596
|
-
const headerLeft =
|
|
597
|
-
const headerRight =
|
|
929
|
+
const headerLeft = headerLeftContent.replace("{page}", `<span class="rm-page-number-plus"></span>`);
|
|
930
|
+
const headerRight = headerRightContent.replace("{page}", `<span class="rm-page-number-plus"></span>`);
|
|
598
931
|
const pageHeaderLeft = document.createElement("div");
|
|
599
932
|
pageHeaderLeft.classList.add("rm-page-header-left");
|
|
600
933
|
pageHeaderLeft.innerHTML = headerLeft;
|
|
@@ -618,40 +951,24 @@ var getHeight = (pageOptions, _headerHeight, _footerHeight) => {
|
|
|
618
951
|
};
|
|
619
952
|
var headerClickEvent = (pageNumber, onHeaderClick) => {
|
|
620
953
|
return (event) => {
|
|
621
|
-
onHeaderClick
|
|
954
|
+
onHeaderClick === null || onHeaderClick === void 0 ? void 0 : onHeaderClick({
|
|
955
|
+
event,
|
|
956
|
+
pageNumber
|
|
957
|
+
});
|
|
622
958
|
};
|
|
623
959
|
};
|
|
624
960
|
var footerClickEvent = (pageNumber, onFooterClick) => {
|
|
625
961
|
return (event) => {
|
|
626
|
-
onFooterClick
|
|
962
|
+
onFooterClick === null || onFooterClick === void 0 ? void 0 : onFooterClick({
|
|
963
|
+
event,
|
|
964
|
+
pageNumber
|
|
965
|
+
});
|
|
627
966
|
};
|
|
628
967
|
};
|
|
629
968
|
|
|
630
|
-
//
|
|
631
|
-
var MAX_PAGES = 1e3;
|
|
632
|
-
function grownPageCount(input) {
|
|
633
|
-
const { currentPageCount, lastPageGap, pageContentAreaHeight, maxPagesByContent } = input;
|
|
634
|
-
if (!(lastPageGap > 0) || !(pageContentAreaHeight > 0)) {
|
|
635
|
-
return currentPageCount;
|
|
636
|
-
}
|
|
637
|
-
const addPage = Math.ceil(lastPageGap / pageContentAreaHeight);
|
|
638
|
-
if (!Number.isFinite(addPage) || addPage <= 0) {
|
|
639
|
-
return currentPageCount;
|
|
640
|
-
}
|
|
641
|
-
const contentCap = Math.max(currentPageCount, maxPagesByContent + 1);
|
|
642
|
-
const desired = currentPageCount + addPage;
|
|
643
|
-
if (desired > contentCap) {
|
|
644
|
-
return contentCap;
|
|
645
|
-
}
|
|
646
|
-
if (desired > MAX_PAGES) {
|
|
647
|
-
return currentPageCount;
|
|
648
|
-
}
|
|
649
|
-
return desired;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// src/pagination/PaginationPlus.ts
|
|
969
|
+
// ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js
|
|
653
970
|
var page_count_meta_key = "PAGE_COUNT_META_KEY";
|
|
654
|
-
var key = new
|
|
971
|
+
var key = new import_state4.PluginKey("brDecoration");
|
|
655
972
|
function buildDecorations(doc) {
|
|
656
973
|
const decorations = [];
|
|
657
974
|
doc.descendants((node, pos) => {
|
|
@@ -669,7 +986,7 @@ function buildDecorations(doc) {
|
|
|
669
986
|
}
|
|
670
987
|
var defaultPageConfig = {
|
|
671
988
|
enabled: true,
|
|
672
|
-
pageBreakBackground: "#
|
|
989
|
+
pageBreakBackground: "#ffffff",
|
|
673
990
|
pageHeight: 800,
|
|
674
991
|
pageWidth: 789,
|
|
675
992
|
marginTop: 20,
|
|
@@ -686,17 +1003,14 @@ var defaultPageConfig = {
|
|
|
686
1003
|
customHeader: {},
|
|
687
1004
|
customFooter: {}
|
|
688
1005
|
};
|
|
689
|
-
var defaultOptions = {
|
|
690
|
-
pageGapBorderSize: 1,
|
|
691
|
-
pageGapBorderColor: "#e5e5e5",
|
|
692
|
-
...defaultPageConfig
|
|
693
|
-
};
|
|
1006
|
+
var defaultOptions = Object.assign({ pageGapBorderSize: 1, pageGapBorderColor: "#e5e5e5" }, defaultPageConfig);
|
|
694
1007
|
var refreshPage = (targetNode, paginationEnabled = true) => {
|
|
1008
|
+
var _a;
|
|
695
1009
|
const paginationElement = targetNode.querySelector("[data-rm-pagination]");
|
|
696
1010
|
if (paginationEnabled) {
|
|
697
1011
|
targetNode.removeAttribute("rm-pagination-disabled");
|
|
698
1012
|
if (paginationElement) {
|
|
699
|
-
const lastPageBreak = paginationElement.lastElementChild
|
|
1013
|
+
const lastPageBreak = (_a = paginationElement.lastElementChild) === null || _a === void 0 ? void 0 : _a.querySelector(".breaker");
|
|
700
1014
|
if (lastPageBreak) {
|
|
701
1015
|
const minHeight = lastPageBreak.offsetTop + lastPageBreak.offsetHeight;
|
|
702
1016
|
targetNode.style.minHeight = `calc(${minHeight}px + 2px)`;
|
|
@@ -704,305 +1018,65 @@ var refreshPage = (targetNode, paginationEnabled = true) => {
|
|
|
704
1018
|
}
|
|
705
1019
|
} else {
|
|
706
1020
|
targetNode.setAttribute("rm-pagination-disabled", "");
|
|
707
|
-
targetNode.style.minHeight =
|
|
1021
|
+
targetNode.style.minHeight = `auto`;
|
|
708
1022
|
}
|
|
709
1023
|
};
|
|
710
1024
|
var getPageConfig = (_storage, _currentOptions) => {
|
|
1025
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
711
1026
|
const pageConfig = {
|
|
712
|
-
enabled: _storage.enabled
|
|
713
|
-
pageBreakBackground: _storage.pageBreakBackground
|
|
714
|
-
pageHeight: _storage.pageHeight
|
|
715
|
-
pageWidth: _storage.pageWidth
|
|
716
|
-
marginTop: _storage.marginTop
|
|
717
|
-
marginBottom: _storage.marginBottom
|
|
718
|
-
marginLeft: _storage.marginLeft
|
|
719
|
-
marginRight: _storage.marginRight
|
|
720
|
-
pageGap: _storage.pageGap
|
|
721
|
-
contentMarginTop: _storage.contentMarginTop
|
|
722
|
-
contentMarginBottom: _storage.contentMarginBottom
|
|
723
|
-
footerRight: _storage.footerRight
|
|
724
|
-
footerLeft: _storage.footerLeft
|
|
725
|
-
headerRight: _storage.headerRight
|
|
726
|
-
headerLeft: _storage.headerLeft
|
|
727
|
-
customHeader: _storage.customHeader
|
|
728
|
-
customFooter: _storage.customFooter
|
|
1027
|
+
enabled: (_a = _storage.enabled) !== null && _a !== void 0 ? _a : defaultOptions.enabled,
|
|
1028
|
+
pageBreakBackground: (_b = _storage.pageBreakBackground) !== null && _b !== void 0 ? _b : defaultOptions.pageBreakBackground,
|
|
1029
|
+
pageHeight: (_c = _storage.pageHeight) !== null && _c !== void 0 ? _c : defaultOptions.pageHeight,
|
|
1030
|
+
pageWidth: (_d = _storage.pageWidth) !== null && _d !== void 0 ? _d : defaultPageConfig.pageWidth,
|
|
1031
|
+
marginTop: (_e = _storage.marginTop) !== null && _e !== void 0 ? _e : defaultPageConfig.marginTop,
|
|
1032
|
+
marginBottom: (_f = _storage.marginBottom) !== null && _f !== void 0 ? _f : defaultPageConfig.marginBottom,
|
|
1033
|
+
marginLeft: (_g = _storage.marginLeft) !== null && _g !== void 0 ? _g : defaultPageConfig.marginLeft,
|
|
1034
|
+
marginRight: (_h = _storage.marginRight) !== null && _h !== void 0 ? _h : defaultPageConfig.marginRight,
|
|
1035
|
+
pageGap: (_j = _storage.pageGap) !== null && _j !== void 0 ? _j : defaultPageConfig.pageGap,
|
|
1036
|
+
contentMarginTop: (_k = _storage.contentMarginTop) !== null && _k !== void 0 ? _k : defaultPageConfig.contentMarginTop,
|
|
1037
|
+
contentMarginBottom: (_l = _storage.contentMarginBottom) !== null && _l !== void 0 ? _l : defaultPageConfig.contentMarginBottom,
|
|
1038
|
+
footerRight: (_m = _storage.footerRight) !== null && _m !== void 0 ? _m : defaultPageConfig.footerRight,
|
|
1039
|
+
footerLeft: (_o = _storage.footerLeft) !== null && _o !== void 0 ? _o : defaultPageConfig.footerLeft,
|
|
1040
|
+
headerRight: (_p = _storage.headerRight) !== null && _p !== void 0 ? _p : defaultPageConfig.headerRight,
|
|
1041
|
+
headerLeft: (_q = _storage.headerLeft) !== null && _q !== void 0 ? _q : defaultPageConfig.headerLeft,
|
|
1042
|
+
customHeader: (_r = _storage.customHeader) !== null && _r !== void 0 ? _r : defaultPageConfig.customHeader,
|
|
1043
|
+
customFooter: (_s = _storage.customFooter) !== null && _s !== void 0 ? _s : defaultPageConfig.customFooter
|
|
729
1044
|
};
|
|
730
1045
|
return {
|
|
731
1046
|
config: pageConfig,
|
|
732
|
-
options: {
|
|
1047
|
+
options: Object.assign(Object.assign({}, _currentOptions), pageConfig)
|
|
733
1048
|
};
|
|
734
1049
|
};
|
|
735
1050
|
var getPageConfigFromOptions = (_currentOptions) => {
|
|
1051
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
736
1052
|
return {
|
|
737
|
-
enabled: _currentOptions.enabled
|
|
738
|
-
pageBreakBackground: _currentOptions.pageBreakBackground
|
|
739
|
-
pageHeight: _currentOptions.pageHeight
|
|
740
|
-
pageWidth: _currentOptions.pageWidth
|
|
741
|
-
marginTop: _currentOptions.marginTop
|
|
742
|
-
marginBottom: _currentOptions.marginBottom
|
|
743
|
-
marginLeft: _currentOptions.marginLeft
|
|
744
|
-
marginRight: _currentOptions.marginRight
|
|
745
|
-
pageGap: _currentOptions.pageGap
|
|
746
|
-
contentMarginTop: _currentOptions.contentMarginTop
|
|
747
|
-
contentMarginBottom: _currentOptions.contentMarginBottom
|
|
748
|
-
footerRight: _currentOptions.footerRight
|
|
749
|
-
footerLeft: _currentOptions.footerLeft
|
|
750
|
-
headerRight: _currentOptions.headerRight
|
|
751
|
-
headerLeft: _currentOptions.headerLeft
|
|
752
|
-
customHeader: _currentOptions.customHeader
|
|
753
|
-
customFooter: _currentOptions.customFooter
|
|
1053
|
+
enabled: (_a = _currentOptions.enabled) !== null && _a !== void 0 ? _a : defaultOptions.enabled,
|
|
1054
|
+
pageBreakBackground: (_b = _currentOptions.pageBreakBackground) !== null && _b !== void 0 ? _b : defaultOptions.pageBreakBackground,
|
|
1055
|
+
pageHeight: (_c = _currentOptions.pageHeight) !== null && _c !== void 0 ? _c : defaultOptions.pageHeight,
|
|
1056
|
+
pageWidth: (_d = _currentOptions.pageWidth) !== null && _d !== void 0 ? _d : defaultPageConfig.pageWidth,
|
|
1057
|
+
marginTop: (_e = _currentOptions.marginTop) !== null && _e !== void 0 ? _e : defaultPageConfig.marginTop,
|
|
1058
|
+
marginBottom: (_f = _currentOptions.marginBottom) !== null && _f !== void 0 ? _f : defaultPageConfig.marginBottom,
|
|
1059
|
+
marginLeft: (_g = _currentOptions.marginLeft) !== null && _g !== void 0 ? _g : defaultPageConfig.marginLeft,
|
|
1060
|
+
marginRight: (_h = _currentOptions.marginRight) !== null && _h !== void 0 ? _h : defaultPageConfig.marginRight,
|
|
1061
|
+
pageGap: (_j = _currentOptions.pageGap) !== null && _j !== void 0 ? _j : defaultPageConfig.pageGap,
|
|
1062
|
+
contentMarginTop: (_k = _currentOptions.contentMarginTop) !== null && _k !== void 0 ? _k : defaultPageConfig.contentMarginTop,
|
|
1063
|
+
contentMarginBottom: (_l = _currentOptions.contentMarginBottom) !== null && _l !== void 0 ? _l : defaultPageConfig.contentMarginBottom,
|
|
1064
|
+
footerRight: (_m = _currentOptions.footerRight) !== null && _m !== void 0 ? _m : defaultPageConfig.footerRight,
|
|
1065
|
+
footerLeft: (_o = _currentOptions.footerLeft) !== null && _o !== void 0 ? _o : defaultPageConfig.footerLeft,
|
|
1066
|
+
headerRight: (_p = _currentOptions.headerRight) !== null && _p !== void 0 ? _p : defaultPageConfig.headerRight,
|
|
1067
|
+
headerLeft: (_q = _currentOptions.headerLeft) !== null && _q !== void 0 ? _q : defaultPageConfig.headerLeft,
|
|
1068
|
+
customHeader: (_r = _currentOptions.customHeader) !== null && _r !== void 0 ? _r : defaultPageConfig.customHeader,
|
|
1069
|
+
customFooter: (_s = _currentOptions.customFooter) !== null && _s !== void 0 ? _s : defaultPageConfig.customFooter
|
|
754
1070
|
};
|
|
755
1071
|
};
|
|
756
|
-
var paginationKey = new
|
|
757
|
-
var
|
|
758
|
-
const editorDom = view.dom;
|
|
759
|
-
const paginationElement = editorDom.querySelector("[data-rm-pagination]");
|
|
760
|
-
if (paginationElement) {
|
|
761
|
-
return paginationElement.children.length;
|
|
762
|
-
}
|
|
763
|
-
return 0;
|
|
764
|
-
};
|
|
765
|
-
var lastContentChild = (editorDom) => {
|
|
766
|
-
for (let i = editorDom.children.length - 1; i >= 0; i--) {
|
|
767
|
-
const child = editorDom.children[i];
|
|
768
|
-
if (!(child instanceof HTMLElement)) continue;
|
|
769
|
-
if (child.hasAttribute("data-rm-pagination")) continue;
|
|
770
|
-
if (child.classList.contains("rm-page-break")) continue;
|
|
771
|
-
return child;
|
|
772
|
-
}
|
|
773
|
-
return null;
|
|
774
|
-
};
|
|
775
|
-
var pageGapTracker = /* @__PURE__ */ new WeakMap();
|
|
776
|
-
var calculatePageCount = (view, pageOptions, headerHeight = 0, footerHeight = 0) => {
|
|
777
|
-
const editorDom = view.dom;
|
|
778
|
-
const _pageHeaderHeight = pageOptions.contentMarginTop + pageOptions.marginTop + headerHeight;
|
|
779
|
-
const _pageFooterHeight = pageOptions.contentMarginBottom + pageOptions.marginBottom + footerHeight;
|
|
780
|
-
const pageContentAreaHeight = pageOptions.pageHeight - _pageHeaderHeight - _pageFooterHeight;
|
|
781
|
-
const paginationElement = editorDom.querySelector("[data-rm-pagination]");
|
|
782
|
-
const currentPageCount = getExistingPageCount(view);
|
|
783
|
-
if (paginationElement) {
|
|
784
|
-
const lastElementOfEditor = lastContentChild(editorDom);
|
|
785
|
-
const lastPageBreak = paginationElement.lastElementChild?.querySelector(".breaker");
|
|
786
|
-
if (lastElementOfEditor && lastPageBreak) {
|
|
787
|
-
const lastElementRect = lastElementOfEditor.getBoundingClientRect();
|
|
788
|
-
const lastPageBreakRect = lastPageBreak.getBoundingClientRect();
|
|
789
|
-
const lastPageGap = lastElementRect.bottom - lastPageBreakRect.bottom;
|
|
790
|
-
if (lastPageGap > 0) {
|
|
791
|
-
const addPage = Math.ceil(lastPageGap / pageContentAreaHeight);
|
|
792
|
-
let totalEditorContentHeight = 0;
|
|
793
|
-
for (const child of Array.from(editorDom.children)) {
|
|
794
|
-
if (!(child instanceof HTMLElement)) continue;
|
|
795
|
-
if (child.hasAttribute("data-rm-pagination")) continue;
|
|
796
|
-
if (child.classList.contains("rm-page-break")) continue;
|
|
797
|
-
totalEditorContentHeight += child.getBoundingClientRect().height;
|
|
798
|
-
}
|
|
799
|
-
const maxPagesByContent = Math.ceil(totalEditorContentHeight / pageContentAreaHeight);
|
|
800
|
-
const prev = pageGapTracker.get(editorDom);
|
|
801
|
-
if (prev && prev.pages < currentPageCount && lastPageGap > prev.gap - 2 && currentPageCount >= maxPagesByContent) {
|
|
802
|
-
return currentPageCount;
|
|
803
|
-
}
|
|
804
|
-
const recent = prev?.recent ?? [];
|
|
805
|
-
let flapping = prev?.flapping ?? [];
|
|
806
|
-
if (recent.length >= 4 && recent.filter((p) => p === currentPageCount + addPage).length >= 2 && currentPageCount >= maxPagesByContent) {
|
|
807
|
-
flapping = [.../* @__PURE__ */ new Set([...flapping, currentPageCount + addPage, currentPageCount])];
|
|
808
|
-
pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount, recent, flapping });
|
|
809
|
-
return currentPageCount;
|
|
810
|
-
}
|
|
811
|
-
pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount, recent, flapping });
|
|
812
|
-
return grownPageCount({
|
|
813
|
-
currentPageCount,
|
|
814
|
-
lastPageGap,
|
|
815
|
-
pageContentAreaHeight,
|
|
816
|
-
maxPagesByContent
|
|
817
|
-
});
|
|
818
|
-
} else {
|
|
819
|
-
const allBreaksAfterLastElement = Array.from(paginationElement.querySelectorAll(".breaker"));
|
|
820
|
-
const allBreaksAfterLastElementRect = allBreaksAfterLastElement.filter(
|
|
821
|
-
(element) => element.getBoundingClientRect().top > lastElementRect.bottom
|
|
822
|
-
);
|
|
823
|
-
const removePage = allBreaksAfterLastElementRect.length;
|
|
824
|
-
if (removePage > 1) {
|
|
825
|
-
return currentPageCount - (removePage - 1);
|
|
826
|
-
} else {
|
|
827
|
-
return currentPageCount;
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
return 1;
|
|
832
|
-
} else {
|
|
833
|
-
const editorHeight = editorDom.scrollHeight;
|
|
834
|
-
let pageCount = Math.ceil(editorHeight / pageContentAreaHeight);
|
|
835
|
-
pageCount = pageCount <= 0 ? 1 : pageCount;
|
|
836
|
-
return pageCount;
|
|
837
|
-
}
|
|
838
|
-
};
|
|
839
|
-
var getNewPageCount = (view, pageOptions) => {
|
|
840
|
-
if (pageOptions.enabled) {
|
|
841
|
-
const pageCount = calculatePageCount(view, pageOptions);
|
|
842
|
-
return pageCount <= 1 ? 1 : pageCount;
|
|
843
|
-
} else return 0;
|
|
844
|
-
};
|
|
845
|
-
function createDecoration(pageOptions, headerHeightMap, footerHeightMap) {
|
|
846
|
-
if (!pageOptions.enabled) return [];
|
|
847
|
-
const commonHeaderOptions = {
|
|
848
|
-
headerLeft: pageOptions.headerLeft,
|
|
849
|
-
headerRight: pageOptions.headerRight
|
|
850
|
-
};
|
|
851
|
-
const commonFooterOptions = {
|
|
852
|
-
footerLeft: pageOptions.footerLeft,
|
|
853
|
-
footerRight: pageOptions.footerRight
|
|
854
|
-
};
|
|
855
|
-
return [
|
|
856
|
-
import_view3.Decoration.widget(
|
|
857
|
-
0,
|
|
858
|
-
(view) => {
|
|
859
|
-
const _pageGap = pageOptions.pageGap;
|
|
860
|
-
const _pageBreakBackground = pageOptions.pageBreakBackground;
|
|
861
|
-
const el = document.createElement("div");
|
|
862
|
-
el.dataset.rmPagination = "true";
|
|
863
|
-
const pageBreakDefinition = (firstPage, pageHeader, pageFooter, headerHeight, footerHeight, pageNumber) => {
|
|
864
|
-
const { _pageHeaderHeight, _pageHeight } = getHeight(pageOptions, headerHeight, footerHeight);
|
|
865
|
-
const pageContainer = document.createElement("div");
|
|
866
|
-
pageContainer.classList.add("rm-page-break");
|
|
867
|
-
const page = document.createElement("div");
|
|
868
|
-
page.classList.add("page");
|
|
869
|
-
page.style.position = "relative";
|
|
870
|
-
page.style.float = "left";
|
|
871
|
-
page.style.clear = "both";
|
|
872
|
-
const marginTop = firstPage ? `calc(${_pageHeaderHeight}px + ${_pageHeight}px)` : _pageHeight + "px";
|
|
873
|
-
if (pageNumber) {
|
|
874
|
-
page.style.marginTop = `var(--rm-page-content-${pageNumber}, ${marginTop})`;
|
|
875
|
-
} else {
|
|
876
|
-
page.style.marginTop = firstPage ? `var(--rm-page-content-first, ${marginTop})` : `var(--rm-page-content-general, ${marginTop})`;
|
|
877
|
-
}
|
|
878
|
-
const pageBreak = document.createElement("div");
|
|
879
|
-
pageBreak.classList.add("breaker");
|
|
880
|
-
pageBreak.style.width = `calc(100% + var(--rm-margin-left) + var(--rm-margin-right))`;
|
|
881
|
-
pageBreak.style.marginLeft = `calc(-1 * var(--rm-margin-left))`;
|
|
882
|
-
pageBreak.style.marginRight = `calc(-1 * var(--rm-margin-right))`;
|
|
883
|
-
pageBreak.style.position = "relative";
|
|
884
|
-
pageBreak.style.float = "left";
|
|
885
|
-
pageBreak.style.clear = "both";
|
|
886
|
-
pageBreak.style.left = "0px";
|
|
887
|
-
pageBreak.style.right = "0px";
|
|
888
|
-
pageBreak.style.zIndex = "2";
|
|
889
|
-
const pageSpace = document.createElement("div");
|
|
890
|
-
pageSpace.classList.add("rm-pagination-gap");
|
|
891
|
-
pageSpace.style.height = _pageGap + "px";
|
|
892
|
-
pageSpace.style.borderLeft = "1px solid";
|
|
893
|
-
pageSpace.style.borderRight = "1px solid";
|
|
894
|
-
pageSpace.style.position = "relative";
|
|
895
|
-
pageSpace.style.setProperty("width", "calc(100% + 2px)", "important");
|
|
896
|
-
pageSpace.style.left = "-1px";
|
|
897
|
-
pageSpace.style.backgroundColor = _pageBreakBackground;
|
|
898
|
-
pageSpace.style.borderLeftColor = _pageBreakBackground;
|
|
899
|
-
pageSpace.style.borderRightColor = _pageBreakBackground;
|
|
900
|
-
pageBreak.append(pageFooter, pageSpace, pageHeader);
|
|
901
|
-
pageContainer.append(page, pageBreak);
|
|
902
|
-
return pageContainer;
|
|
903
|
-
};
|
|
904
|
-
const _headerHeight = headerHeightMap.get(0) || 0;
|
|
905
|
-
const _footerHeight = footerHeightMap.get(0) || 0;
|
|
906
|
-
const fragment = document.createDocumentFragment();
|
|
907
|
-
const pageCount = getNewPageCount(view, pageOptions);
|
|
908
|
-
for (let i = 0; i < pageCount; i++) {
|
|
909
|
-
const pageNumber = i + 1;
|
|
910
|
-
const headerPageNumber = i + 2;
|
|
911
|
-
if (headerPageNumber in pageOptions.customHeader || pageNumber in pageOptions.customFooter || pageNumber in pageOptions.customHeader) {
|
|
912
|
-
let _headerOptions = commonHeaderOptions;
|
|
913
|
-
let _footerOptions = commonFooterOptions;
|
|
914
|
-
let _pageHeaderHeight = _headerHeight;
|
|
915
|
-
let _pageFooterHeight = _footerHeight;
|
|
916
|
-
if (headerPageNumber in pageOptions.customHeader) {
|
|
917
|
-
_headerOptions = pageOptions.customHeader[headerPageNumber] || commonHeaderOptions;
|
|
918
|
-
_pageHeaderHeight = headerHeightMap.get(headerPageNumber) || 0;
|
|
919
|
-
}
|
|
920
|
-
if (pageNumber in pageOptions.customFooter) {
|
|
921
|
-
_footerOptions = pageOptions.customFooter[pageNumber] || commonFooterOptions;
|
|
922
|
-
_pageFooterHeight = footerHeightMap.get(pageNumber) || 0;
|
|
923
|
-
}
|
|
924
|
-
const _pageHeader = getHeader(
|
|
925
|
-
_headerOptions.headerRight,
|
|
926
|
-
_headerOptions.headerLeft,
|
|
927
|
-
headerClickEvent(headerPageNumber, pageOptions.onHeaderClick),
|
|
928
|
-
headerPageNumber
|
|
929
|
-
);
|
|
930
|
-
const _pageFooter = getFooter(
|
|
931
|
-
_footerOptions.footerRight,
|
|
932
|
-
_footerOptions.footerLeft,
|
|
933
|
-
footerClickEvent(pageNumber, pageOptions.onFooterClick),
|
|
934
|
-
pageNumber
|
|
935
|
-
);
|
|
936
|
-
const pageBreak = pageBreakDefinition(
|
|
937
|
-
i === 0,
|
|
938
|
-
_pageHeader,
|
|
939
|
-
_pageFooter,
|
|
940
|
-
_pageHeaderHeight,
|
|
941
|
-
_pageFooterHeight,
|
|
942
|
-
pageNumber
|
|
943
|
-
);
|
|
944
|
-
fragment.appendChild(pageBreak);
|
|
945
|
-
} else {
|
|
946
|
-
const __pageHeader = getHeader(
|
|
947
|
-
commonHeaderOptions.headerRight,
|
|
948
|
-
commonHeaderOptions.headerLeft,
|
|
949
|
-
headerClickEvent(headerPageNumber, pageOptions.onHeaderClick)
|
|
950
|
-
);
|
|
951
|
-
const __pageFooter = getFooter(
|
|
952
|
-
commonFooterOptions.footerRight,
|
|
953
|
-
commonFooterOptions.footerLeft,
|
|
954
|
-
footerClickEvent(pageNumber, pageOptions.onFooterClick)
|
|
955
|
-
);
|
|
956
|
-
fragment.appendChild(pageBreakDefinition(i === 0, __pageHeader, __pageFooter, _headerHeight, _footerHeight));
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
el.append(fragment);
|
|
960
|
-
el.id = "pages";
|
|
961
|
-
el.classList.add("rm-pages-wrapper");
|
|
962
|
-
return el;
|
|
963
|
-
},
|
|
964
|
-
{ side: -1 }
|
|
965
|
-
),
|
|
966
|
-
import_view3.Decoration.widget(
|
|
967
|
-
0,
|
|
968
|
-
() => {
|
|
969
|
-
const pageNumber = 1;
|
|
970
|
-
let _headerOptions = commonHeaderOptions;
|
|
971
|
-
if (pageNumber in pageOptions.customHeader) {
|
|
972
|
-
_headerOptions = pageOptions.customHeader[pageNumber];
|
|
973
|
-
}
|
|
974
|
-
const el = getHeader(
|
|
975
|
-
_headerOptions.headerRight,
|
|
976
|
-
_headerOptions.headerLeft,
|
|
977
|
-
headerClickEvent(pageNumber, pageOptions.onHeaderClick)
|
|
978
|
-
);
|
|
979
|
-
el.classList.add("rm-first-page-header");
|
|
980
|
-
return el;
|
|
981
|
-
},
|
|
982
|
-
{ side: -1 }
|
|
983
|
-
)
|
|
984
|
-
];
|
|
985
|
-
}
|
|
986
|
-
var PAGE_SIZES = {
|
|
987
|
-
A4: getPageSize(1123, 794, 95, 95, 76, 76),
|
|
988
|
-
A3: getPageSize(1591, 1123, 95, 95, 76, 76),
|
|
989
|
-
A5: getPageSize(794, 419, 76, 76, 57, 57),
|
|
990
|
-
LETTER: getPageSize(1060, 818, 96, 96, 96, 96),
|
|
991
|
-
LEGAL: getPageSize(1404, 818, 96, 96, 96, 96),
|
|
992
|
-
TABLOID: getPageSize(1635, 1060, 96, 96, 96, 96)
|
|
993
|
-
};
|
|
994
|
-
var PaginationPlus = import_core4.Extension.create({
|
|
1072
|
+
var paginationKey = new import_state4.PluginKey("pagination");
|
|
1073
|
+
var PaginationPlus = import_core5.Extension.create({
|
|
995
1074
|
name: "PaginationPlus",
|
|
996
1075
|
addOptions() {
|
|
997
1076
|
return defaultOptions;
|
|
998
1077
|
},
|
|
999
1078
|
addStorage() {
|
|
1000
|
-
return {
|
|
1001
|
-
...defaultOptions,
|
|
1002
|
-
headerHeight: /* @__PURE__ */ new Map(),
|
|
1003
|
-
footerHeight: /* @__PURE__ */ new Map(),
|
|
1004
|
-
appliedConfig: defaultPageConfig
|
|
1005
|
-
};
|
|
1079
|
+
return Object.assign(Object.assign({}, defaultOptions), { headerHeight: /* @__PURE__ */ new Map(), footerHeight: /* @__PURE__ */ new Map(), appliedConfig: defaultPageConfig });
|
|
1006
1080
|
},
|
|
1007
1081
|
onCreate() {
|
|
1008
1082
|
const { options: _currentOptions } = getPageConfig(this.storage, this.options);
|
|
@@ -1010,180 +1084,210 @@ var PaginationPlus = import_core4.Extension.create({
|
|
|
1010
1084
|
const targetNode = this.editor.view.dom;
|
|
1011
1085
|
targetNode.classList.add("rm-with-pagination");
|
|
1012
1086
|
targetNode.style.border = `1px solid var(--rm-page-gap-border-color)`;
|
|
1013
|
-
targetNode.style.paddingLeft =
|
|
1014
|
-
targetNode.style.paddingRight =
|
|
1015
|
-
targetNode.style.width =
|
|
1016
|
-
updateCssVariables(targetNode, {
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1087
|
+
targetNode.style.paddingLeft = `var(--rm-margin-left)`;
|
|
1088
|
+
targetNode.style.paddingRight = `var(--rm-margin-right)`;
|
|
1089
|
+
targetNode.style.width = `var(--rm-page-width)`;
|
|
1090
|
+
updateCssVariables(targetNode, Object.assign(Object.assign({}, _currentOptions), pageConfig));
|
|
1091
|
+
const style = document.createElement("style");
|
|
1092
|
+
style.dataset.rmPaginationStyle = "";
|
|
1093
|
+
style.textContent = `
|
|
1094
|
+
.rm-pagination-gap{
|
|
1095
|
+
border-top: 1px solid;
|
|
1096
|
+
border-bottom: 1px solid;
|
|
1097
|
+
border-color: var(--rm-page-gap-border-color);
|
|
1098
|
+
}
|
|
1099
|
+
.rm-with-pagination,
|
|
1100
|
+
.rm-with-pagination .rm-first-page-header {
|
|
1101
|
+
counter-reset: page-number page-number-plus 1;
|
|
1102
|
+
}
|
|
1103
|
+
.rm-with-pagination .image-plus-wrapper,
|
|
1104
|
+
.rm-with-pagination .table-plus td,
|
|
1105
|
+
.rm-with-pagination .table-plus th {
|
|
1106
|
+
max-height: var(--rm-max-content-child-height);
|
|
1107
|
+
overflow-y: auto;
|
|
1108
|
+
}
|
|
1109
|
+
.rm-with-pagination .image-plus-wrapper {
|
|
1110
|
+
overflow-y: visible;
|
|
1111
|
+
}
|
|
1112
|
+
.rm-with-pagination .rm-page-break {
|
|
1113
|
+
counter-increment: page-number page-number-plus;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
.rm-with-pagination .rm-page-break:last-child .rm-pagination-gap {
|
|
1117
|
+
display: none;
|
|
1118
|
+
}
|
|
1119
|
+
.rm-with-pagination .rm-page-break:last-child .rm-page-header {
|
|
1120
|
+
display: none;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
.rm-with-pagination table tr td,
|
|
1124
|
+
.rm-with-pagination table tr th {
|
|
1125
|
+
word-break: break-all;
|
|
1126
|
+
}
|
|
1127
|
+
.rm-with-pagination table > tr {
|
|
1128
|
+
display: grid;
|
|
1129
|
+
min-width: 100%;
|
|
1130
|
+
}
|
|
1131
|
+
.rm-with-pagination table {
|
|
1132
|
+
border-collapse: collapse;
|
|
1133
|
+
width: 100%;
|
|
1134
|
+
display: contents;
|
|
1135
|
+
}
|
|
1136
|
+
.rm-with-pagination table tbody > tr{
|
|
1137
|
+
display: table-row !important;
|
|
1138
|
+
}
|
|
1139
|
+
.rm-with-pagination *:has(>br.ProseMirror-trailingBreak:only-child) {
|
|
1140
|
+
display: table;
|
|
1141
|
+
width: 100%;
|
|
1142
|
+
}
|
|
1143
|
+
.rm-with-pagination .rm-br-decoration {
|
|
1144
|
+
display: table;
|
|
1145
|
+
width: 100%;
|
|
1146
|
+
}
|
|
1147
|
+
.rm-with-pagination .table-row-group {
|
|
1148
|
+
max-height: var(--rm-max-content-child-height);
|
|
1149
|
+
overflow-y: auto;
|
|
1150
|
+
width: 100%;
|
|
1151
|
+
}
|
|
1152
|
+
.rm-with-pagination .rm-page-footer-left,
|
|
1153
|
+
.rm-with-pagination .rm-page-footer-right,
|
|
1154
|
+
.rm-with-pagination .rm-page-header-left,
|
|
1155
|
+
.rm-with-pagination .rm-page-header-right {
|
|
1156
|
+
display: inline-block;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
.rm-with-pagination .rm-page-header-left,
|
|
1160
|
+
.rm-with-pagination .rm-page-footer-left{
|
|
1161
|
+
float: left;
|
|
1162
|
+
margin-left: var(--rm-margin-left);
|
|
1163
|
+
}
|
|
1164
|
+
.rm-with-pagination .rm-page-header-right,
|
|
1165
|
+
.rm-with-pagination .rm-page-footer-right{
|
|
1166
|
+
float: right;
|
|
1167
|
+
margin-right: var(--rm-margin-right);
|
|
1168
|
+
}
|
|
1169
|
+
.rm-with-pagination .rm-first-page-header .rm-page-header-right{
|
|
1170
|
+
margin-right: 0px !important;
|
|
1171
|
+
}
|
|
1172
|
+
.rm-with-pagination .rm-first-page-header .rm-page-header-left{
|
|
1173
|
+
margin-left: 0px !important;
|
|
1174
|
+
}
|
|
1175
|
+
.rm-with-pagination .rm-page-number::before {
|
|
1176
|
+
content: counter(page-number);
|
|
1177
|
+
}
|
|
1178
|
+
.rm-with-pagination .rm-page-number-plus::before {
|
|
1179
|
+
content: counter(page-number-plus);
|
|
1180
|
+
}
|
|
1181
|
+
.rm-with-pagination .rm-page-header,
|
|
1182
|
+
.rm-with-pagination .rm-page-footer{
|
|
1183
|
+
width: 100%;
|
|
1184
|
+
}
|
|
1185
|
+
.rm-with-pagination .rm-page-header{
|
|
1186
|
+
padding-bottom: var(--rm-content-margin-top) !important;
|
|
1187
|
+
padding-top: var(--rm-margin-top) !important;
|
|
1188
|
+
display: inline-flex;
|
|
1189
|
+
justify-content: space-between;
|
|
1190
|
+
max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-margin-top) - var(--rm-content-margin-top));
|
|
1191
|
+
overflow-y: hidden;
|
|
1192
|
+
}
|
|
1193
|
+
.rm-with-pagination .rm-page-footer{
|
|
1194
|
+
padding-top: var(--rm-content-margin-bottom) !important;
|
|
1195
|
+
padding-bottom: var(--rm-margin-bottom) !important;
|
|
1196
|
+
display: inline-flex;
|
|
1197
|
+
justify-content: space-between;
|
|
1198
|
+
max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-content-margin-bottom) - var(--rm-margin-bottom));
|
|
1199
|
+
overflow-y: hidden;
|
|
1200
|
+
}
|
|
1201
|
+
.rm-with-pagination[rm-pagination-disabled] {
|
|
1202
|
+
padding-top: var(--rm-margin-top) !important;
|
|
1203
|
+
padding-bottom: var(--rm-margin-bottom) !important;
|
|
1204
|
+
}
|
|
1205
|
+
`;
|
|
1206
|
+
document.head.appendChild(style);
|
|
1132
1207
|
refreshPage(targetNode, _currentOptions.enabled);
|
|
1133
1208
|
},
|
|
1134
1209
|
addProseMirrorPlugins() {
|
|
1210
|
+
const editor = this.editor;
|
|
1135
1211
|
const storage = this.storage;
|
|
1136
|
-
const options = this.options;
|
|
1137
1212
|
return [
|
|
1138
|
-
new
|
|
1213
|
+
new import_state4.Plugin({
|
|
1139
1214
|
key: paginationKey,
|
|
1140
1215
|
state: {
|
|
1141
|
-
init: () =>
|
|
1142
|
-
|
|
1143
|
-
const
|
|
1144
|
-
|
|
1145
|
-
|
|
1216
|
+
init: (_, state) => {
|
|
1217
|
+
const _currentOptions = getPageConfigFromOptions(this.options);
|
|
1218
|
+
const pageConfig = getPageConfigFromOptions(this.options);
|
|
1219
|
+
const widgetList = createDecoration(Object.assign(Object.assign({}, this.options), _currentOptions), /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map());
|
|
1220
|
+
storage.pageBreakBackground = _currentOptions.pageBreakBackground;
|
|
1221
|
+
storage.pageHeight = _currentOptions.pageHeight;
|
|
1222
|
+
storage.pageWidth = _currentOptions.pageWidth;
|
|
1223
|
+
storage.marginTop = _currentOptions.marginTop;
|
|
1224
|
+
storage.marginBottom = _currentOptions.marginBottom;
|
|
1225
|
+
storage.marginLeft = _currentOptions.marginLeft;
|
|
1226
|
+
storage.marginRight = _currentOptions.marginRight;
|
|
1227
|
+
storage.pageGap = _currentOptions.pageGap;
|
|
1228
|
+
storage.contentMarginTop = _currentOptions.contentMarginTop;
|
|
1229
|
+
storage.contentMarginBottom = _currentOptions.contentMarginBottom;
|
|
1230
|
+
storage.footerRight = _currentOptions.footerRight;
|
|
1231
|
+
storage.footerLeft = _currentOptions.footerLeft;
|
|
1232
|
+
storage.headerRight = _currentOptions.headerRight;
|
|
1233
|
+
storage.headerLeft = _currentOptions.headerLeft;
|
|
1234
|
+
storage.customHeader = _currentOptions.customHeader;
|
|
1235
|
+
storage.customFooter = _currentOptions.customFooter;
|
|
1236
|
+
storage.headerHeight = /* @__PURE__ */ new Map();
|
|
1237
|
+
storage.footerHeight = /* @__PURE__ */ new Map();
|
|
1238
|
+
storage.appliedConfig = pageConfig;
|
|
1239
|
+
return {
|
|
1240
|
+
decorations: import_view3.DecorationSet.create(state.doc, widgetList)
|
|
1241
|
+
};
|
|
1242
|
+
},
|
|
1243
|
+
apply: (tr, oldDeco, oldState, newState) => {
|
|
1244
|
+
const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, this.options);
|
|
1245
|
+
if (storage.enabled === storage.appliedConfig.enabled && storage.enabled === false && storage.appliedConfig.enabled === false) {
|
|
1246
|
+
return oldDeco;
|
|
1146
1247
|
}
|
|
1147
|
-
const
|
|
1148
|
-
const
|
|
1149
|
-
const
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1248
|
+
const pageCount = getNewPageCount(editor.view, Object.assign(Object.assign({}, _currentOptions), pageConfig));
|
|
1249
|
+
const currentPageCount = getExistingPageCount(editor.view);
|
|
1250
|
+
const getNewDecoration = () => {
|
|
1251
|
+
const { options: _currentOptions2, config: pageConfig2 } = getPageConfig(storage, this.options);
|
|
1252
|
+
updateCssVariables(editor.view.dom, _currentOptions2);
|
|
1253
|
+
let headerHeight = "headerHeight" in this.storage ? this.storage.headerHeight : /* @__PURE__ */ new Map();
|
|
1254
|
+
let footerHeight = "footerHeight" in this.storage ? this.storage.footerHeight : /* @__PURE__ */ new Map();
|
|
1255
|
+
const widgetList = createDecoration(Object.assign(Object.assign({}, _currentOptions2), pageConfig2), headerHeight, footerHeight);
|
|
1256
|
+
storage.appliedConfig = pageConfig2;
|
|
1257
|
+
storage.headerHeight = headerHeight;
|
|
1258
|
+
storage.footerHeight = footerHeight;
|
|
1259
|
+
return {
|
|
1260
|
+
decorations: import_view3.DecorationSet.create(newState.doc, [...widgetList]),
|
|
1261
|
+
footerHeight
|
|
1262
|
+
};
|
|
1263
|
+
};
|
|
1264
|
+
if (
|
|
1265
|
+
// If pagination is enabled only then check for other changes
|
|
1266
|
+
(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)
|
|
1267
|
+
) {
|
|
1268
|
+
return getNewDecoration();
|
|
1159
1269
|
}
|
|
1160
|
-
return
|
|
1270
|
+
return oldDeco;
|
|
1161
1271
|
}
|
|
1162
1272
|
},
|
|
1163
1273
|
props: {
|
|
1164
1274
|
decorations(state) {
|
|
1165
|
-
|
|
1275
|
+
var _a;
|
|
1276
|
+
return (_a = this.getState(state)) === null || _a === void 0 ? void 0 : _a.decorations;
|
|
1166
1277
|
}
|
|
1167
1278
|
},
|
|
1168
|
-
view: () => {
|
|
1279
|
+
view: (editorView) => {
|
|
1169
1280
|
return {
|
|
1170
1281
|
update: (view) => {
|
|
1171
|
-
const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, options);
|
|
1282
|
+
const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, this.options);
|
|
1172
1283
|
if (!pageConfig.enabled && !view.dom.hasAttribute("rm-pagination-disabled")) {
|
|
1173
1284
|
refreshPage(view.dom, false);
|
|
1174
1285
|
return;
|
|
1175
1286
|
}
|
|
1176
|
-
const pageCount = getNewPageCount(view, {
|
|
1287
|
+
const pageCount = getNewPageCount(view, Object.assign(Object.assign({}, _currentOptions), pageConfig));
|
|
1177
1288
|
const currentPageCount = getExistingPageCount(view);
|
|
1178
1289
|
const triggerUpdate = (_footerHeight) => {
|
|
1179
1290
|
requestAnimationFrame(() => {
|
|
1180
|
-
const history = pageGapTracker.get(view.dom);
|
|
1181
|
-
if (history && history.flapping && history.flapping.includes(pageCount)) {
|
|
1182
|
-
return;
|
|
1183
|
-
}
|
|
1184
|
-
if (history && history.recent) {
|
|
1185
|
-
history.recent.push(pageCount);
|
|
1186
|
-
}
|
|
1187
1291
|
const tr = view.state.tr.setMeta(page_count_meta_key, { footerHeight: _footerHeight });
|
|
1188
1292
|
view.dispatch(tr);
|
|
1189
1293
|
});
|
|
@@ -1207,7 +1311,7 @@ var PaginationPlus = import_core4.Extension.create({
|
|
|
1207
1311
|
}
|
|
1208
1312
|
}
|
|
1209
1313
|
const pagesSetToCheck = /* @__PURE__ */ new Set([1, ...footerHeightForCurrentPages.keys(), ...headerHeightForCurrentPages.keys()]);
|
|
1210
|
-
let missingPageNumber;
|
|
1314
|
+
let missingPageNumber = void 0;
|
|
1211
1315
|
for (let i = 1; i <= pageCount; i++) {
|
|
1212
1316
|
if (!pagesSetToCheck.has(i)) {
|
|
1213
1317
|
missingPageNumber = i;
|
|
@@ -1218,18 +1322,18 @@ var PaginationPlus = import_core4.Extension.create({
|
|
|
1218
1322
|
pagesSetToCheck.add(missingPageNumber);
|
|
1219
1323
|
}
|
|
1220
1324
|
pagesSetToCheck.delete(0);
|
|
1221
|
-
|
|
1222
|
-
let maxContentHeight;
|
|
1325
|
+
let pageContentHeightVariable = {};
|
|
1326
|
+
let maxContentHeight = void 0;
|
|
1223
1327
|
for (const page of pagesSetToCheck) {
|
|
1224
|
-
const
|
|
1225
|
-
const
|
|
1226
|
-
const { _pageHeaderHeight, _pageHeight } = getHeight(_currentOptions,
|
|
1328
|
+
const headerHeight2 = headerHeightForCurrentPages.has(page) ? headerHeightForCurrentPages.get(page) || 0 : headerHeightForCurrentPages.get(0) || 0;
|
|
1329
|
+
const footerHeight2 = footerHeightForCurrentPages.has(page) ? footerHeightForCurrentPages.get(page) || 0 : footerHeightForCurrentPages.get(0) || 0;
|
|
1330
|
+
const { _pageHeaderHeight, _pageHeight } = getHeight(_currentOptions, headerHeight2, footerHeight2);
|
|
1227
1331
|
const contentHeight = page === 1 ? _pageHeight + _pageHeaderHeight : _pageHeight;
|
|
1228
1332
|
if (page === 1) {
|
|
1229
|
-
pageContentHeightVariable[
|
|
1333
|
+
pageContentHeightVariable[`rm-page-content-first`] = `${contentHeight}px`;
|
|
1230
1334
|
}
|
|
1231
1335
|
if (page === missingPageNumber) {
|
|
1232
|
-
pageContentHeightVariable[
|
|
1336
|
+
pageContentHeightVariable[`rm-page-content-general`] = `${contentHeight}px`;
|
|
1233
1337
|
} else {
|
|
1234
1338
|
pageContentHeightVariable[`rm-page-content-${page}`] = `${contentHeight}px`;
|
|
1235
1339
|
}
|
|
@@ -1238,28 +1342,25 @@ var PaginationPlus = import_core4.Extension.create({
|
|
|
1238
1342
|
}
|
|
1239
1343
|
}
|
|
1240
1344
|
if (maxContentHeight) {
|
|
1241
|
-
;
|
|
1242
|
-
view.dom.style.setProperty("--rm-max-content-child-height", `${maxContentHeight - 10}px`);
|
|
1345
|
+
view.dom.style.setProperty(`--rm-max-content-child-height`, `${maxContentHeight - 10}px`);
|
|
1243
1346
|
}
|
|
1244
|
-
Object.entries(pageContentHeightVariable).forEach(([
|
|
1245
|
-
;
|
|
1246
|
-
view.dom.style.setProperty(`--${k}`, value);
|
|
1347
|
+
Object.entries(pageContentHeightVariable).forEach(([key2, value]) => {
|
|
1348
|
+
view.dom.style.setProperty(`--${key2}`, value);
|
|
1247
1349
|
});
|
|
1248
1350
|
refreshPage(view.dom, _currentOptions.enabled);
|
|
1351
|
+
return;
|
|
1249
1352
|
}
|
|
1250
1353
|
};
|
|
1251
1354
|
}
|
|
1252
1355
|
}),
|
|
1253
|
-
new
|
|
1356
|
+
new import_state4.Plugin({
|
|
1254
1357
|
key,
|
|
1255
1358
|
state: {
|
|
1256
1359
|
init(_, state) {
|
|
1257
1360
|
return buildDecorations(state.doc);
|
|
1258
1361
|
},
|
|
1259
1362
|
apply(tr, old) {
|
|
1260
|
-
if (tr.docChanged || tr.steps.some(
|
|
1261
|
-
(step) => step instanceof import_transform.ReplaceStep || step instanceof import_transform.ReplaceAroundStep || step instanceof import_transform.AddMarkStep || step instanceof import_transform.RemoveMarkStep || step instanceof import_transform.RemoveNodeMarkStep || step instanceof import_transform.AttrStep
|
|
1262
|
-
)) {
|
|
1363
|
+
if (tr.docChanged || tr.steps.some((step) => step instanceof import_transform.ReplaceStep) || tr.steps.some((step) => step instanceof import_transform.ReplaceAroundStep) || tr.steps.some((step) => step instanceof import_transform.AddMarkStep) || tr.steps.some((step) => step instanceof import_transform.RemoveMarkStep) || tr.steps.some((step) => step instanceof import_transform.RemoveNodeMarkStep) || tr.steps.some((step) => step instanceof import_transform.AttrStep)) {
|
|
1263
1364
|
return buildDecorations(tr.doc);
|
|
1264
1365
|
}
|
|
1265
1366
|
return old;
|
|
@@ -1267,7 +1368,8 @@ var PaginationPlus = import_core4.Extension.create({
|
|
|
1267
1368
|
},
|
|
1268
1369
|
props: {
|
|
1269
1370
|
decorations(state) {
|
|
1270
|
-
|
|
1371
|
+
var _a;
|
|
1372
|
+
return (_a = key.getState(state)) !== null && _a !== void 0 ? _a : import_view3.DecorationSet.empty;
|
|
1271
1373
|
}
|
|
1272
1374
|
}
|
|
1273
1375
|
})
|
|
@@ -1307,14 +1409,31 @@ var PaginationPlus = import_core4.Extension.create({
|
|
|
1307
1409
|
this.storage.marginRight = margins.right;
|
|
1308
1410
|
return true;
|
|
1309
1411
|
},
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1412
|
+
updateContentMargins: (margins) => () => {
|
|
1413
|
+
this.storage.contentMarginTop = margins.top;
|
|
1414
|
+
this.storage.contentMarginBottom = margins.bottom;
|
|
1313
1415
|
return true;
|
|
1314
1416
|
},
|
|
1315
|
-
|
|
1316
|
-
if (
|
|
1317
|
-
|
|
1417
|
+
updateHeaderContent: (left, right, pageNumber) => () => {
|
|
1418
|
+
if (pageNumber) {
|
|
1419
|
+
this.storage.customHeader = Object.assign(Object.assign({}, this.storage.customHeader), { [pageNumber]: { headerLeft: left, headerRight: right } });
|
|
1420
|
+
} else {
|
|
1421
|
+
this.storage.headerLeft = left;
|
|
1422
|
+
this.storage.headerRight = right;
|
|
1423
|
+
}
|
|
1424
|
+
return true;
|
|
1425
|
+
},
|
|
1426
|
+
updateFooterContent: (left, right, pageNumber) => () => {
|
|
1427
|
+
if (pageNumber) {
|
|
1428
|
+
this.storage.customFooter = Object.assign(Object.assign({}, this.storage.customFooter), { [pageNumber]: { footerLeft: left, footerRight: right } });
|
|
1429
|
+
} else {
|
|
1430
|
+
this.storage.footerLeft = left;
|
|
1431
|
+
this.storage.footerRight = right;
|
|
1432
|
+
}
|
|
1433
|
+
return true;
|
|
1434
|
+
},
|
|
1435
|
+
togglePagination: () => () => {
|
|
1436
|
+
this.storage.enabled = !this.storage.enabled;
|
|
1318
1437
|
return true;
|
|
1319
1438
|
},
|
|
1320
1439
|
enablePagination: () => () => {
|
|
@@ -1328,94 +1447,203 @@ var PaginationPlus = import_core4.Extension.create({
|
|
|
1328
1447
|
};
|
|
1329
1448
|
}
|
|
1330
1449
|
});
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
var isPaginationActive = (view) => {
|
|
1339
|
-
const dom = view.dom;
|
|
1340
|
-
return dom.classList.contains(PAGINATION_CLASS) && dom.getAttribute(PAGINATION_DISABLED_ATTR) === null;
|
|
1450
|
+
var getExistingPageCount = (view) => {
|
|
1451
|
+
const editorDom = view.dom;
|
|
1452
|
+
const paginationElement = editorDom.querySelector("[data-rm-pagination]");
|
|
1453
|
+
if (paginationElement) {
|
|
1454
|
+
return paginationElement.children.length;
|
|
1455
|
+
}
|
|
1456
|
+
return 0;
|
|
1341
1457
|
};
|
|
1342
|
-
var
|
|
1343
|
-
var
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
const
|
|
1347
|
-
const
|
|
1348
|
-
const
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
if (
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
if (!drag) return;
|
|
1365
|
-
dragStates.delete(view);
|
|
1366
|
-
const doc = view.dom.ownerDocument;
|
|
1367
|
-
doc.removeEventListener("mousemove", drag.onMouseMove);
|
|
1368
|
-
doc.removeEventListener("mouseup", drag.onMouseUp);
|
|
1369
|
-
}
|
|
1370
|
-
function beginDrag(view, anchorPos) {
|
|
1371
|
-
stopDrag(view);
|
|
1372
|
-
const doc = view.dom.ownerDocument;
|
|
1373
|
-
const onMouseMove = (event) => {
|
|
1374
|
-
const drag = dragStates.get(view);
|
|
1375
|
-
if (!drag) return;
|
|
1376
|
-
const pos = resolvePosFromNativePoint(view, event.clientX, event.clientY);
|
|
1377
|
-
if (pos === null) return;
|
|
1378
|
-
const from = Math.min(drag.anchorPos, pos);
|
|
1379
|
-
const to = Math.max(drag.anchorPos, pos);
|
|
1380
|
-
view.dispatch(view.state.tr.setSelection(import_state4.TextSelection.create(view.state.doc, from, to)));
|
|
1381
|
-
};
|
|
1382
|
-
const onMouseUp = () => {
|
|
1383
|
-
stopDrag(view);
|
|
1384
|
-
};
|
|
1385
|
-
dragStates.set(view, { anchorPos, onMouseMove, onMouseUp });
|
|
1386
|
-
doc.addEventListener("mousemove", onMouseMove);
|
|
1387
|
-
doc.addEventListener("mouseup", onMouseUp);
|
|
1388
|
-
}
|
|
1389
|
-
function interceptPaginationMouseDown(view, event) {
|
|
1390
|
-
if (!isPaginationActive(view) || !isPlainSingleLeftClick(event) || !isEditable(view)) return false;
|
|
1391
|
-
const pos = resolvePosFromNativePoint(view, event.clientX, event.clientY);
|
|
1392
|
-
if (pos === null) return false;
|
|
1393
|
-
view.focus();
|
|
1394
|
-
view.dispatch(view.state.tr.setSelection(import_state4.TextSelection.create(view.state.doc, pos)));
|
|
1395
|
-
beginDrag(view, pos);
|
|
1396
|
-
return true;
|
|
1397
|
-
}
|
|
1398
|
-
var PaginationCaretFix = import_core5.Extension.create({
|
|
1399
|
-
name: "paginationCaretFix",
|
|
1400
|
-
addProseMirrorPlugins() {
|
|
1401
|
-
return [
|
|
1402
|
-
new import_state4.Plugin({
|
|
1403
|
-
key: new import_state4.PluginKey("paginationCaretFix"),
|
|
1404
|
-
props: {
|
|
1405
|
-
handleDOMEvents: {
|
|
1406
|
-
mousedown: (view, event) => {
|
|
1407
|
-
try {
|
|
1408
|
-
return interceptPaginationMouseDown(view, event);
|
|
1409
|
-
} catch {
|
|
1410
|
-
return false;
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1458
|
+
var pageGapTracker = /* @__PURE__ */ new WeakMap();
|
|
1459
|
+
var calculatePageCount = (view, pageOptions, headerHeight = 0, footerHeight = 0) => {
|
|
1460
|
+
var _a;
|
|
1461
|
+
const editorDom = view.dom;
|
|
1462
|
+
const _pageHeaderHeight = pageOptions.contentMarginTop + pageOptions.marginTop + headerHeight;
|
|
1463
|
+
const _pageFooterHeight = pageOptions.contentMarginBottom + pageOptions.marginBottom + footerHeight;
|
|
1464
|
+
const pageContentAreaHeight = pageOptions.pageHeight - _pageHeaderHeight - _pageFooterHeight;
|
|
1465
|
+
const paginationElement = editorDom.querySelector("[data-rm-pagination]");
|
|
1466
|
+
const currentPageCount = getExistingPageCount(view);
|
|
1467
|
+
if (paginationElement) {
|
|
1468
|
+
const lastElementOfEditor = editorDom.lastElementChild;
|
|
1469
|
+
const lastPageBreak = (_a = paginationElement.lastElementChild) === null || _a === void 0 ? void 0 : _a.querySelector(".breaker");
|
|
1470
|
+
if (lastElementOfEditor && lastPageBreak) {
|
|
1471
|
+
const lastElementRect = lastElementOfEditor.getBoundingClientRect();
|
|
1472
|
+
const lastPageBreakRect = lastPageBreak.getBoundingClientRect();
|
|
1473
|
+
const lastPageGap = lastElementRect.bottom - lastPageBreakRect.bottom;
|
|
1474
|
+
if (lastPageGap > 0) {
|
|
1475
|
+
const addPage = Math.ceil(lastPageGap / pageContentAreaHeight);
|
|
1476
|
+
if (lastElementRect.height > pageContentAreaHeight) {
|
|
1477
|
+
const isSplittableTable = (lastElementOfEditor === null || lastElementOfEditor === void 0 ? void 0 : lastElementOfEditor.tagName) === "TABLE" && lastElementOfEditor.hasAttribute("data-tps-splittable");
|
|
1478
|
+
if (!isSplittableTable) {
|
|
1479
|
+
return currentPageCount;
|
|
1413
1480
|
}
|
|
1414
1481
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1482
|
+
const prev = pageGapTracker.get(editorDom);
|
|
1483
|
+
if (prev && prev.pages < currentPageCount && lastPageGap > prev.gap - 2) {
|
|
1484
|
+
return currentPageCount;
|
|
1485
|
+
}
|
|
1486
|
+
pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount });
|
|
1487
|
+
let totalEditorContentHeight = 0;
|
|
1488
|
+
for (const child of editorDom.children) {
|
|
1489
|
+
if (!(child instanceof HTMLElement)) continue;
|
|
1490
|
+
if (child.hasAttribute("data-rm-pagination")) continue;
|
|
1491
|
+
if (child.classList.contains("rm-page-break")) continue;
|
|
1492
|
+
totalEditorContentHeight += child.getBoundingClientRect().height;
|
|
1493
|
+
}
|
|
1494
|
+
const maxPagesByContent = Math.ceil(totalEditorContentHeight / pageContentAreaHeight);
|
|
1495
|
+
const contentCap = Math.max(currentPageCount, maxPagesByContent + 1);
|
|
1496
|
+
if (currentPageCount + addPage > contentCap) {
|
|
1497
|
+
return contentCap;
|
|
1498
|
+
}
|
|
1499
|
+
const MAX_PAGES = 1e3;
|
|
1500
|
+
if (currentPageCount + addPage > MAX_PAGES) {
|
|
1501
|
+
return currentPageCount;
|
|
1502
|
+
}
|
|
1503
|
+
return currentPageCount + addPage;
|
|
1504
|
+
} else {
|
|
1505
|
+
pageGapTracker.delete(editorDom);
|
|
1506
|
+
const allBreaksAfterLastElement = Array.from(paginationElement.querySelectorAll(".breaker"));
|
|
1507
|
+
const allBreaksAfterLastElementRect = allBreaksAfterLastElement.filter((element) => element.getBoundingClientRect().top > lastElementRect.bottom);
|
|
1508
|
+
const removePage = allBreaksAfterLastElementRect.length;
|
|
1509
|
+
if (removePage > 1) {
|
|
1510
|
+
return currentPageCount - removePage;
|
|
1511
|
+
} else {
|
|
1512
|
+
return currentPageCount;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
return 1;
|
|
1517
|
+
} else {
|
|
1518
|
+
const editorHeight = editorDom.scrollHeight;
|
|
1519
|
+
let pageCount = Math.ceil(editorHeight / pageContentAreaHeight);
|
|
1520
|
+
pageCount = pageCount <= 0 ? 1 : pageCount;
|
|
1521
|
+
return pageCount;
|
|
1417
1522
|
}
|
|
1418
|
-
}
|
|
1523
|
+
};
|
|
1524
|
+
var getNewPageCount = (view, pageOptions) => {
|
|
1525
|
+
if (pageOptions.enabled) {
|
|
1526
|
+
const pageCount = calculatePageCount(view, pageOptions);
|
|
1527
|
+
return pageCount <= 1 ? 1 : pageCount;
|
|
1528
|
+
} else {
|
|
1529
|
+
return 0;
|
|
1530
|
+
}
|
|
1531
|
+
};
|
|
1532
|
+
function createDecoration(pageOptions, headerHeightMap, footerHeightMap) {
|
|
1533
|
+
if (!pageOptions.enabled) {
|
|
1534
|
+
return [];
|
|
1535
|
+
}
|
|
1536
|
+
const commonHeaderOptions = { headerLeft: pageOptions.headerLeft, headerRight: pageOptions.headerRight };
|
|
1537
|
+
const commonFooterOptions = { footerLeft: pageOptions.footerLeft, footerRight: pageOptions.footerRight };
|
|
1538
|
+
const pageWidget = import_view3.Decoration.widget(0, (view) => {
|
|
1539
|
+
const _pageGap = pageOptions.pageGap;
|
|
1540
|
+
const _pageBreakBackground = pageOptions.pageBreakBackground;
|
|
1541
|
+
const el = document.createElement("div");
|
|
1542
|
+
el.dataset.rmPagination = "true";
|
|
1543
|
+
const pageBreakDefinition = (firstPage, pageHeader, pageFooter, headerHeight, footerHeight, pageNumber) => {
|
|
1544
|
+
const { _pageHeaderHeight, _pageHeight } = getHeight(pageOptions, headerHeight, footerHeight);
|
|
1545
|
+
const pageContainer = document.createElement("div");
|
|
1546
|
+
pageContainer.classList.add("rm-page-break");
|
|
1547
|
+
const page = document.createElement("div");
|
|
1548
|
+
page.classList.add("page");
|
|
1549
|
+
page.style.position = "relative";
|
|
1550
|
+
page.style.float = "left";
|
|
1551
|
+
page.style.clear = "both";
|
|
1552
|
+
const marginTop = firstPage ? `calc(${_pageHeaderHeight}px + ${_pageHeight}px)` : _pageHeight + "px";
|
|
1553
|
+
if (pageNumber) {
|
|
1554
|
+
page.style.marginTop = `var(--rm-page-content-${pageNumber}, ${marginTop})`;
|
|
1555
|
+
} else {
|
|
1556
|
+
page.style.marginTop = firstPage ? `var(--rm-page-content-first, ${marginTop})` : `var(--rm-page-content-general, ${marginTop})`;
|
|
1557
|
+
}
|
|
1558
|
+
const pageBreak = document.createElement("div");
|
|
1559
|
+
pageBreak.classList.add("breaker");
|
|
1560
|
+
pageBreak.style.width = `calc(100% + var(--rm-margin-left) + var(--rm-margin-right))`;
|
|
1561
|
+
pageBreak.style.marginLeft = `calc(-1 * var(--rm-margin-left))`;
|
|
1562
|
+
pageBreak.style.marginRight = `calc(-1 * var(--rm-margin-right))`;
|
|
1563
|
+
pageBreak.style.position = "relative";
|
|
1564
|
+
pageBreak.style.float = "left";
|
|
1565
|
+
pageBreak.style.clear = "both";
|
|
1566
|
+
pageBreak.style.left = `0px`;
|
|
1567
|
+
pageBreak.style.right = `0px`;
|
|
1568
|
+
pageBreak.style.zIndex = "2";
|
|
1569
|
+
const pageSpace = document.createElement("div");
|
|
1570
|
+
pageSpace.classList.add("rm-pagination-gap");
|
|
1571
|
+
pageSpace.style.height = _pageGap + "px";
|
|
1572
|
+
pageSpace.style.borderLeft = "1px solid";
|
|
1573
|
+
pageSpace.style.borderRight = "1px solid";
|
|
1574
|
+
pageSpace.style.position = "relative";
|
|
1575
|
+
pageSpace.style.setProperty("width", "calc(100% + 2px)", "important");
|
|
1576
|
+
pageSpace.style.left = "-1px";
|
|
1577
|
+
pageSpace.style.backgroundColor = _pageBreakBackground;
|
|
1578
|
+
pageSpace.style.borderLeftColor = _pageBreakBackground;
|
|
1579
|
+
pageSpace.style.borderRightColor = _pageBreakBackground;
|
|
1580
|
+
pageBreak.append(pageFooter, pageSpace, pageHeader);
|
|
1581
|
+
pageContainer.append(page, pageBreak);
|
|
1582
|
+
return pageContainer;
|
|
1583
|
+
};
|
|
1584
|
+
const _headerHeight = headerHeightMap.get(0) || 0;
|
|
1585
|
+
const _footerHeight = footerHeightMap.get(0) || 0;
|
|
1586
|
+
const fragment = document.createDocumentFragment();
|
|
1587
|
+
const pageCount = getNewPageCount(view, pageOptions);
|
|
1588
|
+
for (let i = 0; i < pageCount; i++) {
|
|
1589
|
+
const pageNumber = i + 1;
|
|
1590
|
+
const headerPageNumber = i + 2;
|
|
1591
|
+
if (headerPageNumber in pageOptions.customHeader || pageNumber in pageOptions.customFooter || pageNumber in pageOptions.customHeader) {
|
|
1592
|
+
let _headerOptions = commonHeaderOptions;
|
|
1593
|
+
let _footerOptions = commonFooterOptions;
|
|
1594
|
+
let _pageHeaderHeight = _headerHeight;
|
|
1595
|
+
let _pageFooterHeight = _footerHeight;
|
|
1596
|
+
if (headerPageNumber in pageOptions.customHeader) {
|
|
1597
|
+
_headerOptions = pageOptions.customHeader[headerPageNumber] || commonHeaderOptions;
|
|
1598
|
+
_pageHeaderHeight = headerHeightMap.get(headerPageNumber) || 0;
|
|
1599
|
+
}
|
|
1600
|
+
if (pageNumber in pageOptions.customFooter) {
|
|
1601
|
+
_footerOptions = pageOptions.customFooter[pageNumber] || commonFooterOptions;
|
|
1602
|
+
_pageFooterHeight = footerHeightMap.get(pageNumber) || 0;
|
|
1603
|
+
}
|
|
1604
|
+
let _pageHeader = getHeader(_headerOptions.headerRight, _headerOptions.headerLeft, headerClickEvent(headerPageNumber, pageOptions.onHeaderClick), headerPageNumber);
|
|
1605
|
+
let _pageFooter = getFooter(_footerOptions.footerRight, _footerOptions.footerLeft, footerClickEvent(pageNumber, pageOptions.onFooterClick), pageNumber);
|
|
1606
|
+
let pageBreak = pageBreakDefinition(i === 0, _pageHeader, _pageFooter, _pageHeaderHeight, _pageFooterHeight, pageNumber);
|
|
1607
|
+
fragment.appendChild(pageBreak);
|
|
1608
|
+
} else {
|
|
1609
|
+
const __pageHeader = getHeader(commonHeaderOptions.headerRight, commonHeaderOptions.headerLeft, headerClickEvent(headerPageNumber, pageOptions.onHeaderClick));
|
|
1610
|
+
const __pageFooter = getFooter(commonFooterOptions.footerRight, commonFooterOptions.footerLeft, footerClickEvent(pageNumber, pageOptions.onFooterClick));
|
|
1611
|
+
fragment.appendChild(pageBreakDefinition(i === 0, __pageHeader, __pageFooter, _headerHeight, _footerHeight));
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
el.append(fragment);
|
|
1615
|
+
el.id = "pages";
|
|
1616
|
+
el.classList.add("rm-pages-wrapper");
|
|
1617
|
+
return el;
|
|
1618
|
+
}, { side: -1 });
|
|
1619
|
+
const firstHeaderWidget = import_view3.Decoration.widget(0, () => {
|
|
1620
|
+
const pageNumber = 1;
|
|
1621
|
+
let _headerOptions = commonHeaderOptions;
|
|
1622
|
+
if (pageNumber in pageOptions.customHeader) {
|
|
1623
|
+
_headerOptions = pageOptions.customHeader[pageNumber];
|
|
1624
|
+
}
|
|
1625
|
+
const el = getHeader(_headerOptions.headerRight, _headerOptions.headerLeft, headerClickEvent(pageNumber, pageOptions.onHeaderClick));
|
|
1626
|
+
el.classList.add("rm-first-page-header");
|
|
1627
|
+
return el;
|
|
1628
|
+
}, { side: -1 });
|
|
1629
|
+
return [pageWidget, firstHeaderWidget];
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
// ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/constants.js
|
|
1633
|
+
var A4_PAGE_SIZE = getPageSize(1123, 794, 95, 95, 76, 76);
|
|
1634
|
+
var A3_PAGE_SIZE = getPageSize(1591, 1123, 95, 95, 76, 76);
|
|
1635
|
+
var A5_PAGE_SIZE = getPageSize(794, 419, 76, 76, 57, 57);
|
|
1636
|
+
var LETTER_PAGE_SIZE = getPageSize(1060, 818, 96, 96, 96, 96);
|
|
1637
|
+
var LEGAL_PAGE_SIZE = getPageSize(1404, 818, 96, 96, 96, 96);
|
|
1638
|
+
var TABLOID_PAGE_SIZE = getPageSize(1635, 1060, 96, 96, 96, 96);
|
|
1639
|
+
var PAGE_SIZES = {
|
|
1640
|
+
A4: A4_PAGE_SIZE,
|
|
1641
|
+
A3: A3_PAGE_SIZE,
|
|
1642
|
+
A5: A5_PAGE_SIZE,
|
|
1643
|
+
LETTER: LETTER_PAGE_SIZE,
|
|
1644
|
+
LEGAL: LEGAL_PAGE_SIZE,
|
|
1645
|
+
TABLOID: TABLOID_PAGE_SIZE
|
|
1646
|
+
};
|
|
1419
1647
|
|
|
1420
1648
|
// src/PerformanceMonitor.ts
|
|
1421
1649
|
var TARGET_FRAME_MS = 1e3 / 60;
|
|
@@ -1784,7 +2012,7 @@ function createEditor(options = {}) {
|
|
|
1784
2012
|
content: options.content ? migrateContent(options.content) : options.content
|
|
1785
2013
|
};
|
|
1786
2014
|
const plugins = migratedOptions.plugins ?? [];
|
|
1787
|
-
const collaborationSetup = migratedOptions.collaboration;
|
|
2015
|
+
const collaborationSetup = !migratedOptions.collaboration ? void 0 : "ydoc" in migratedOptions.collaboration ? migratedOptions.collaboration : createCollaboration(migratedOptions.collaboration);
|
|
1788
2016
|
const performanceMonitor = migratedOptions.debug ? createPerformanceMonitor() : void 0;
|
|
1789
2017
|
let tiptapEditor = createTiptapEditor(migratedOptions, plugins, collaborationSetup);
|
|
1790
2018
|
let pluginActions = createActionMap(tiptapEditor, plugins);
|
|
@@ -1825,6 +2053,7 @@ function createEditor(options = {}) {
|
|
|
1825
2053
|
plugin.hooks?.onDestroy?.(tiptapEditor);
|
|
1826
2054
|
}
|
|
1827
2055
|
tiptapEditor.destroy();
|
|
2056
|
+
collaborationSetup?.destroy();
|
|
1828
2057
|
performanceMonitor?.destroy();
|
|
1829
2058
|
},
|
|
1830
2059
|
use: (plugin) => {
|
|
@@ -1844,336 +2073,12 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
|
|
|
1844
2073
|
const pluginExtensions = collectExtensions(plugins);
|
|
1845
2074
|
const blockAttrs = options.getPageMap ? BlockAttributesExtension.configure({ pageMap: options.getPageMap }) : BlockAttributesExtension;
|
|
1846
2075
|
const paginationExt = options.paginationOptions ? PaginationPlus.configure(options.paginationOptions) : PaginationPlus;
|
|
1847
|
-
const ManualColumnResize = import_core6.Extension.create({
|
|
1848
|
-
name: "manualColumnResize",
|
|
1849
|
-
addProseMirrorPlugins() {
|
|
1850
|
-
const key2 = new import_state5.PluginKey("manualColumnResize");
|
|
1851
|
-
return [new import_state5.Plugin({
|
|
1852
|
-
key: key2,
|
|
1853
|
-
view(view) {
|
|
1854
|
-
function pauseObserver() {
|
|
1855
|
-
try {
|
|
1856
|
-
view.domObserver?.stop?.();
|
|
1857
|
-
} catch (_) {
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
function resumeObserver() {
|
|
1861
|
-
try {
|
|
1862
|
-
view.domObserver?.start?.();
|
|
1863
|
-
} catch (_) {
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
function getMaxContainerWidth(tableEl) {
|
|
1867
|
-
let curr = tableEl.parentElement;
|
|
1868
|
-
while (curr) {
|
|
1869
|
-
const style = window.getComputedStyle(curr);
|
|
1870
|
-
const paddingLeft = parseFloat(style.paddingLeft) || 0;
|
|
1871
|
-
const paddingRight = parseFloat(style.paddingRight) || 0;
|
|
1872
|
-
const availWidth = curr.clientWidth - paddingLeft - paddingRight;
|
|
1873
|
-
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"))) {
|
|
1874
|
-
return availWidth;
|
|
1875
|
-
}
|
|
1876
|
-
curr = curr.parentElement;
|
|
1877
|
-
}
|
|
1878
|
-
return tableEl.parentElement?.clientWidth || 614;
|
|
1879
|
-
}
|
|
1880
|
-
const onMouseDown = function(event) {
|
|
1881
|
-
if (event.button !== 0) return;
|
|
1882
|
-
const td = event.target.closest("td, th");
|
|
1883
|
-
if (!td) return;
|
|
1884
|
-
const r = td.getBoundingClientRect();
|
|
1885
|
-
const parent = td.parentElement;
|
|
1886
|
-
if (!parent) return;
|
|
1887
|
-
const cellColSpan = td.colSpan || 1;
|
|
1888
|
-
let logicalStart = 0;
|
|
1889
|
-
let foundCell = false;
|
|
1890
|
-
for (const sibling of Array.from(parent.children)) {
|
|
1891
|
-
if (sibling === td) {
|
|
1892
|
-
foundCell = true;
|
|
1893
|
-
break;
|
|
1894
|
-
}
|
|
1895
|
-
logicalStart += sibling.colSpan || 1;
|
|
1896
|
-
}
|
|
1897
|
-
if (!foundCell) return;
|
|
1898
|
-
const table = td.closest("table");
|
|
1899
|
-
if (!table) return;
|
|
1900
|
-
const distRight = Math.abs(event.clientX - r.right);
|
|
1901
|
-
const distLeft = Math.abs(event.clientX - r.left);
|
|
1902
|
-
let targetColIdx = -1;
|
|
1903
|
-
if (distRight <= 16) {
|
|
1904
|
-
targetColIdx = logicalStart + cellColSpan - 1;
|
|
1905
|
-
} else if (distLeft <= 16 && logicalStart > 0) {
|
|
1906
|
-
targetColIdx = logicalStart - 1;
|
|
1907
|
-
} else {
|
|
1908
|
-
return;
|
|
1909
|
-
}
|
|
1910
|
-
const colsList = table.querySelectorAll("colgroup col");
|
|
1911
|
-
const totalCols = colsList.length || table.querySelector("tr")?.children.length || 0;
|
|
1912
|
-
const allColWidths = [];
|
|
1913
|
-
for (let c = 0; c < totalCols; c++) {
|
|
1914
|
-
const colEl = colsList[c];
|
|
1915
|
-
const w = colEl ? parseFloat(colEl.style.width) : 0;
|
|
1916
|
-
allColWidths[c] = w || initialWidth(table, c);
|
|
1917
|
-
}
|
|
1918
|
-
const isLastCol = targetColIdx === totalCols - 1;
|
|
1919
|
-
const neighborIdx = targetColIdx + 1;
|
|
1920
|
-
const startX = event.clientX;
|
|
1921
|
-
const startW = allColWidths[targetColIdx] || initialWidth(table, targetColIdx);
|
|
1922
|
-
const startNeighborW = !isLastCol ? allColWidths[neighborIdx] || initialWidth(table, neighborIdx) : 0;
|
|
1923
|
-
const maxContainerW = getMaxContainerWidth(table);
|
|
1924
|
-
let otherColsW = 0;
|
|
1925
|
-
allColWidths.forEach((w, idx) => {
|
|
1926
|
-
if (idx !== targetColIdx) otherColsW += w;
|
|
1927
|
-
});
|
|
1928
|
-
const maxNwLastCol = Math.max(20, maxContainerW - otherColsW);
|
|
1929
|
-
function updateDOMWidths() {
|
|
1930
|
-
let totalWidth = 0;
|
|
1931
|
-
allColWidths.forEach((w, idx) => {
|
|
1932
|
-
const col = table.querySelector(`colgroup col:nth-child(${idx + 1})`);
|
|
1933
|
-
if (col) col.style.setProperty("width", w + "px", "important");
|
|
1934
|
-
table.querySelectorAll("tr").forEach(function(row) {
|
|
1935
|
-
const cell = row.children[idx];
|
|
1936
|
-
if (cell) {
|
|
1937
|
-
cell.style.setProperty("width", w + "px", "important");
|
|
1938
|
-
cell.setAttribute("width", String(w));
|
|
1939
|
-
}
|
|
1940
|
-
});
|
|
1941
|
-
totalWidth += w;
|
|
1942
|
-
});
|
|
1943
|
-
if (totalWidth > 0) {
|
|
1944
|
-
table.style.setProperty("width", Math.min(totalWidth, maxContainerW) + "px", "important");
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
event.stopPropagation();
|
|
1948
|
-
let lastNw = startW;
|
|
1949
|
-
const onMove = function(e) {
|
|
1950
|
-
if (!e.buttons) {
|
|
1951
|
-
onUp(e);
|
|
1952
|
-
return;
|
|
1953
|
-
}
|
|
1954
|
-
const rawDiff = e.clientX - startX;
|
|
1955
|
-
if (isLastCol) {
|
|
1956
|
-
const nw = Math.min(maxNwLastCol, Math.max(20, startW + rawDiff));
|
|
1957
|
-
allColWidths[targetColIdx] = nw;
|
|
1958
|
-
lastNw = nw;
|
|
1959
|
-
} else {
|
|
1960
|
-
const delta = Math.max(20 - startW, Math.min(rawDiff, startNeighborW - 20));
|
|
1961
|
-
allColWidths[targetColIdx] = startW + delta;
|
|
1962
|
-
allColWidths[neighborIdx] = startNeighborW - delta;
|
|
1963
|
-
lastNw = allColWidths[targetColIdx];
|
|
1964
|
-
}
|
|
1965
|
-
let borderPos = table.getBoundingClientRect().left;
|
|
1966
|
-
for (let i = 0; i <= targetColIdx; i++) borderPos += allColWidths[i];
|
|
1967
|
-
showLine(table, borderPos);
|
|
1968
|
-
pauseObserver();
|
|
1969
|
-
updateDOMWidths();
|
|
1970
|
-
resumeObserver();
|
|
1971
|
-
};
|
|
1972
|
-
const onUp = function(upEvent) {
|
|
1973
|
-
document.removeEventListener("mousemove", onMove);
|
|
1974
|
-
document.removeEventListener("mouseup", onUp, true);
|
|
1975
|
-
upEvent.stopPropagation();
|
|
1976
|
-
hideLine();
|
|
1977
|
-
if (lastNw === startW) return;
|
|
1978
|
-
try {
|
|
1979
|
-
const { state } = view;
|
|
1980
|
-
const { doc } = state;
|
|
1981
|
-
let tablePos = -1;
|
|
1982
|
-
doc.descendants((node, pos) => {
|
|
1983
|
-
if (tablePos >= 0) return false;
|
|
1984
|
-
if (node.type.name === "table") {
|
|
1985
|
-
try {
|
|
1986
|
-
const dom = view.nodeDOM(pos);
|
|
1987
|
-
if (dom === table || dom instanceof HTMLElement && dom.contains(table) || table.contains(dom)) {
|
|
1988
|
-
tablePos = pos;
|
|
1989
|
-
return false;
|
|
1990
|
-
}
|
|
1991
|
-
} catch (_) {
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
|
-
return true;
|
|
1995
|
-
});
|
|
1996
|
-
if (tablePos >= 0) {
|
|
1997
|
-
const tableNode = doc.nodeAt(tablePos);
|
|
1998
|
-
if (tableNode) {
|
|
1999
|
-
const tr = state.tr;
|
|
2000
|
-
tableNode.forEach((row, rowOffset) => {
|
|
2001
|
-
let cellColIdx = 0;
|
|
2002
|
-
row.forEach((cell, cellOffset) => {
|
|
2003
|
-
const colspan = cell.attrs.colspan || 1;
|
|
2004
|
-
const cellPos = tablePos + 1 + rowOffset + 1 + cellOffset;
|
|
2005
|
-
const cw = new Array(colspan);
|
|
2006
|
-
for (let k = 0; k < colspan; k++) {
|
|
2007
|
-
cw[k] = allColWidths[cellColIdx + k] || 100;
|
|
2008
|
-
}
|
|
2009
|
-
tr.setNodeMarkup(cellPos, null, { ...cell.attrs, colwidth: cw });
|
|
2010
|
-
cellColIdx += colspan;
|
|
2011
|
-
});
|
|
2012
|
-
});
|
|
2013
|
-
view.dispatch(tr);
|
|
2014
|
-
pauseObserver();
|
|
2015
|
-
updateDOMWidths();
|
|
2016
|
-
resumeObserver();
|
|
2017
|
-
}
|
|
2018
|
-
} else {
|
|
2019
|
-
console.warn("[Resize] could not find table position in doc");
|
|
2020
|
-
}
|
|
2021
|
-
} catch (err) {
|
|
2022
|
-
console.warn("[Resize] transaction failed, falling back to DOM:", err);
|
|
2023
|
-
pauseObserver();
|
|
2024
|
-
updateDOMWidths();
|
|
2025
|
-
resumeObserver();
|
|
2026
|
-
}
|
|
2027
|
-
};
|
|
2028
|
-
document.addEventListener("mousemove", onMove);
|
|
2029
|
-
document.addEventListener("mouseup", onUp, true);
|
|
2030
|
-
};
|
|
2031
|
-
function initialWidth(table, colIdx) {
|
|
2032
|
-
const firstRow = table.querySelector("tr");
|
|
2033
|
-
if (!firstRow) return 100;
|
|
2034
|
-
const cell = firstRow.children[colIdx];
|
|
2035
|
-
if (!cell) return 100;
|
|
2036
|
-
return Math.round(cell.getBoundingClientRect().width) || cell.offsetWidth || 100;
|
|
2037
|
-
}
|
|
2038
|
-
let lineEl = null;
|
|
2039
|
-
let isDragging = false;
|
|
2040
|
-
function getOrCreateLine() {
|
|
2041
|
-
if (!lineEl) {
|
|
2042
|
-
lineEl = document.createElement("div");
|
|
2043
|
-
lineEl.className = "docflow-active-border-line";
|
|
2044
|
-
Object.assign(lineEl.style, {
|
|
2045
|
-
position: "fixed",
|
|
2046
|
-
width: "3px",
|
|
2047
|
-
background: "#06b6d4",
|
|
2048
|
-
boxShadow: "0 0 8px rgba(6, 182, 212, 0.9)",
|
|
2049
|
-
pointerEvents: "none",
|
|
2050
|
-
zIndex: "999999",
|
|
2051
|
-
display: "none",
|
|
2052
|
-
borderRadius: "1.5px"
|
|
2053
|
-
});
|
|
2054
|
-
const dotTop = document.createElement("div");
|
|
2055
|
-
Object.assign(dotTop.style, {
|
|
2056
|
-
position: "absolute",
|
|
2057
|
-
top: "-4px",
|
|
2058
|
-
left: "-3.5px",
|
|
2059
|
-
width: "10px",
|
|
2060
|
-
height: "10px",
|
|
2061
|
-
borderRadius: "50%",
|
|
2062
|
-
background: "#ffffff",
|
|
2063
|
-
border: "2px solid #06b6d4"
|
|
2064
|
-
});
|
|
2065
|
-
const dotBottom = document.createElement("div");
|
|
2066
|
-
Object.assign(dotBottom.style, {
|
|
2067
|
-
position: "absolute",
|
|
2068
|
-
bottom: "-4px",
|
|
2069
|
-
left: "-3.5px",
|
|
2070
|
-
width: "10px",
|
|
2071
|
-
height: "10px",
|
|
2072
|
-
borderRadius: "50%",
|
|
2073
|
-
background: "#ffffff",
|
|
2074
|
-
border: "2px solid #06b6d4"
|
|
2075
|
-
});
|
|
2076
|
-
lineEl.appendChild(dotTop);
|
|
2077
|
-
lineEl.appendChild(dotBottom);
|
|
2078
|
-
document.body.appendChild(lineEl);
|
|
2079
|
-
}
|
|
2080
|
-
return lineEl;
|
|
2081
|
-
}
|
|
2082
|
-
function showLine(table, borderX) {
|
|
2083
|
-
const line = getOrCreateLine();
|
|
2084
|
-
const tableRect = table.getBoundingClientRect();
|
|
2085
|
-
line.style.left = `${borderX - 1.5}px`;
|
|
2086
|
-
line.style.top = `${tableRect.top}px`;
|
|
2087
|
-
line.style.height = `${tableRect.height}px`;
|
|
2088
|
-
line.style.display = "block";
|
|
2089
|
-
document.body.style.cursor = "col-resize";
|
|
2090
|
-
view.dom.style.cursor = "col-resize";
|
|
2091
|
-
}
|
|
2092
|
-
function hideLine() {
|
|
2093
|
-
if (lineEl) {
|
|
2094
|
-
lineEl.style.display = "none";
|
|
2095
|
-
}
|
|
2096
|
-
document.body.style.cursor = "";
|
|
2097
|
-
view.dom.style.cursor = "";
|
|
2098
|
-
}
|
|
2099
|
-
const onMouseMoveHover = function(event) {
|
|
2100
|
-
if (isDragging) return;
|
|
2101
|
-
const target = event.target;
|
|
2102
|
-
const td = target.closest("td, th");
|
|
2103
|
-
if (!td) {
|
|
2104
|
-
hideLine();
|
|
2105
|
-
return;
|
|
2106
|
-
}
|
|
2107
|
-
const r = td.getBoundingClientRect();
|
|
2108
|
-
const distRight = Math.abs(event.clientX - r.right);
|
|
2109
|
-
const distLeft = Math.abs(event.clientX - r.left);
|
|
2110
|
-
const parent = td.parentElement;
|
|
2111
|
-
if (!parent) {
|
|
2112
|
-
hideLine();
|
|
2113
|
-
return;
|
|
2114
|
-
}
|
|
2115
|
-
const colIdx = Array.from(parent.children).indexOf(td);
|
|
2116
|
-
let borderX = -1;
|
|
2117
|
-
if (distRight <= 16) {
|
|
2118
|
-
borderX = r.right;
|
|
2119
|
-
} else if (distLeft <= 16 && colIdx > 0) {
|
|
2120
|
-
borderX = r.left;
|
|
2121
|
-
}
|
|
2122
|
-
if (borderX >= 0) {
|
|
2123
|
-
const table = td.closest("table");
|
|
2124
|
-
if (table) {
|
|
2125
|
-
showLine(table, borderX);
|
|
2126
|
-
}
|
|
2127
|
-
} else {
|
|
2128
|
-
hideLine();
|
|
2129
|
-
}
|
|
2130
|
-
};
|
|
2131
|
-
document.addEventListener("mousemove", onMouseMoveHover, true);
|
|
2132
|
-
view.dom.addEventListener("mousedown", function handleMouseDown(event) {
|
|
2133
|
-
onMouseDown(event);
|
|
2134
|
-
const td = event.target.closest("td, th");
|
|
2135
|
-
if (!td) return;
|
|
2136
|
-
const r = td.getBoundingClientRect();
|
|
2137
|
-
const distRight = Math.abs(event.clientX - r.right);
|
|
2138
|
-
const distLeft = Math.abs(event.clientX - r.left);
|
|
2139
|
-
const parent = td.parentElement;
|
|
2140
|
-
if (!parent) return;
|
|
2141
|
-
const colIdx = Array.from(parent.children).indexOf(td);
|
|
2142
|
-
if (distRight <= 16 || distLeft <= 16 && colIdx > 0) {
|
|
2143
|
-
isDragging = true;
|
|
2144
|
-
hideLine();
|
|
2145
|
-
const onDragEnd = function() {
|
|
2146
|
-
isDragging = false;
|
|
2147
|
-
hideLine();
|
|
2148
|
-
document.removeEventListener("mouseup", onDragEnd, true);
|
|
2149
|
-
};
|
|
2150
|
-
document.addEventListener("mouseup", onDragEnd, true);
|
|
2151
|
-
}
|
|
2152
|
-
}, true);
|
|
2153
|
-
return {
|
|
2154
|
-
destroy: function() {
|
|
2155
|
-
document.removeEventListener("mousemove", onMouseMoveHover, true);
|
|
2156
|
-
if (lineEl && lineEl.parentElement) {
|
|
2157
|
-
lineEl.parentElement.removeChild(lineEl);
|
|
2158
|
-
}
|
|
2159
|
-
lineEl = null;
|
|
2160
|
-
hideLine();
|
|
2161
|
-
}
|
|
2162
|
-
};
|
|
2163
|
-
}
|
|
2164
|
-
})];
|
|
2165
|
-
}
|
|
2166
|
-
});
|
|
2167
2076
|
let extensions = [
|
|
2168
2077
|
ManualColumnResize,
|
|
2169
2078
|
baseStarterKit,
|
|
2170
2079
|
import_extension_text_style.default,
|
|
2171
2080
|
blockAttrs,
|
|
2172
2081
|
paginationExt,
|
|
2173
|
-
// Always present — fixes caret-on-click misplacement caused by the
|
|
2174
|
-
// pagination DOM (header/footer/gap widgets breaking linear coordinates).
|
|
2175
|
-
// No-op (gated at runtime) when pagination is off or disabled.
|
|
2176
|
-
PaginationCaretFix,
|
|
2177
2082
|
// Always present — carries host-injected ports (onImageUpload, citation, …)
|
|
2178
2083
|
// in storage so plugin commands can reach them through the editor instance.
|
|
2179
2084
|
EditorContextExtension.configure({
|
|
@@ -2188,18 +2093,9 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
|
|
|
2188
2093
|
];
|
|
2189
2094
|
const content = options.collaboration ? void 0 : options.content;
|
|
2190
2095
|
if (options.collaboration && collaborationSetup) {
|
|
2191
|
-
const seed = seedEmptyFragment(collaborationSetup.ydoc);
|
|
2192
|
-
if (seed.seeded) {
|
|
2193
|
-
extensions.push(
|
|
2194
|
-
import_core6.Extension.create({
|
|
2195
|
-
name: "provisionalSeedCleanup",
|
|
2196
|
-
onDestroy: () => seed.dispose()
|
|
2197
|
-
})
|
|
2198
|
-
);
|
|
2199
|
-
}
|
|
2200
2096
|
extensions = [...extensions, ...collaborationExtensions(collaborationSetup)];
|
|
2201
2097
|
}
|
|
2202
|
-
|
|
2098
|
+
return new import_core6.Editor({
|
|
2203
2099
|
element: options.target,
|
|
2204
2100
|
content,
|
|
2205
2101
|
extensions,
|
|
@@ -2214,7 +2110,6 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
|
|
|
2214
2110
|
transformPastedHTML: sanitizePastedHTML
|
|
2215
2111
|
}
|
|
2216
2112
|
});
|
|
2217
|
-
return tiptapEditor;
|
|
2218
2113
|
}
|
|
2219
2114
|
|
|
2220
2115
|
// src/FontSize.ts
|
|
@@ -2327,6 +2222,113 @@ var FontSizeExtension = import_core7.Extension.create({
|
|
|
2327
2222
|
}
|
|
2328
2223
|
});
|
|
2329
2224
|
|
|
2225
|
+
// src/SubdocumentProvider.ts
|
|
2226
|
+
var import_awareness2 = require("y-protocols/awareness");
|
|
2227
|
+
var import_y_websocket2 = require("y-websocket");
|
|
2228
|
+
var Y2 = __toESM(require("yjs"), 1);
|
|
2229
|
+
var SubdocumentProvider = class {
|
|
2230
|
+
parentDoc;
|
|
2231
|
+
subdocs;
|
|
2232
|
+
awareness;
|
|
2233
|
+
options;
|
|
2234
|
+
states = /* @__PURE__ */ new Map();
|
|
2235
|
+
activeQueue = [];
|
|
2236
|
+
parentProvider = null;
|
|
2237
|
+
constructor(options) {
|
|
2238
|
+
this.options = {
|
|
2239
|
+
maxActive: options.maxActive ?? 5,
|
|
2240
|
+
onStateChange: options.onStateChange ?? (() => {
|
|
2241
|
+
}),
|
|
2242
|
+
...options
|
|
2243
|
+
};
|
|
2244
|
+
this.parentDoc = new Y2.Doc();
|
|
2245
|
+
this.subdocs = this.parentDoc.getMap("subdocs");
|
|
2246
|
+
this.awareness = new import_awareness2.Awareness(this.parentDoc);
|
|
2247
|
+
this.awareness.setLocalStateField("user", this.options.user);
|
|
2248
|
+
this.parentProvider = new import_y_websocket2.WebsocketProvider(
|
|
2249
|
+
this.options.websocketUrl,
|
|
2250
|
+
`${this.options.roomPrefix}/_parent`,
|
|
2251
|
+
this.parentDoc
|
|
2252
|
+
);
|
|
2253
|
+
}
|
|
2254
|
+
/** Create a new subdocument. Does NOT activate it. */
|
|
2255
|
+
createSubdoc(id, initialState) {
|
|
2256
|
+
if (this.states.has(id)) return this.states.get(id).doc;
|
|
2257
|
+
const doc = new Y2.Doc();
|
|
2258
|
+
if (initialState) Y2.applyUpdate(doc, initialState);
|
|
2259
|
+
doc.getXmlFragment("default");
|
|
2260
|
+
this.subdocs.set(id, doc);
|
|
2261
|
+
this.states.set(id, {
|
|
2262
|
+
id,
|
|
2263
|
+
doc,
|
|
2264
|
+
provider: null,
|
|
2265
|
+
active: false
|
|
2266
|
+
});
|
|
2267
|
+
this.options.onStateChange(this.getAllStates());
|
|
2268
|
+
return doc;
|
|
2269
|
+
}
|
|
2270
|
+
/** Activate a subdocument — connects it to the network for live sync. */
|
|
2271
|
+
activate(id) {
|
|
2272
|
+
const state = this.states.get(id);
|
|
2273
|
+
if (!state || state.active) return;
|
|
2274
|
+
if (this.activeQueue.length >= this.options.maxActive) {
|
|
2275
|
+
const oldest = this.activeQueue.shift();
|
|
2276
|
+
if (oldest) this.deactivate(oldest);
|
|
2277
|
+
}
|
|
2278
|
+
const doc = state.doc;
|
|
2279
|
+
const roomName = `${this.options.roomPrefix}/${id}`;
|
|
2280
|
+
const provider = new import_y_websocket2.WebsocketProvider(
|
|
2281
|
+
this.options.websocketUrl,
|
|
2282
|
+
roomName,
|
|
2283
|
+
doc
|
|
2284
|
+
);
|
|
2285
|
+
provider.awareness.setLocalStateField("user", this.options.user);
|
|
2286
|
+
state.provider = provider;
|
|
2287
|
+
state.active = true;
|
|
2288
|
+
this.activeQueue.push(id);
|
|
2289
|
+
this.options.onStateChange(this.getAllStates());
|
|
2290
|
+
}
|
|
2291
|
+
/** Deactivate a subdocument — disconnects it from the network. */
|
|
2292
|
+
deactivate(id) {
|
|
2293
|
+
const state = this.states.get(id);
|
|
2294
|
+
if (!state || !state.active) return;
|
|
2295
|
+
state.provider?.destroy();
|
|
2296
|
+
state.provider = null;
|
|
2297
|
+
state.active = false;
|
|
2298
|
+
const idx = this.activeQueue.indexOf(id);
|
|
2299
|
+
if (idx >= 0) this.activeQueue.splice(idx, 1);
|
|
2300
|
+
this.options.onStateChange(this.getAllStates());
|
|
2301
|
+
}
|
|
2302
|
+
/** Get the Y.XmlFragment for a subdocument. */
|
|
2303
|
+
getFragment(id) {
|
|
2304
|
+
const doc = this.states.get(id)?.doc ?? this.subdocs.get(id);
|
|
2305
|
+
if (!doc) return null;
|
|
2306
|
+
return doc.getXmlFragment("default");
|
|
2307
|
+
}
|
|
2308
|
+
/** Check if a subdocument is currently active (syncing). */
|
|
2309
|
+
isActive(id) {
|
|
2310
|
+
return this.states.get(id)?.active ?? false;
|
|
2311
|
+
}
|
|
2312
|
+
/** Get all subdocument states. */
|
|
2313
|
+
getAllStates() {
|
|
2314
|
+
return Array.from(this.states.values());
|
|
2315
|
+
}
|
|
2316
|
+
/** Get IDs of all active subdocuments. */
|
|
2317
|
+
getActiveIds() {
|
|
2318
|
+
return [...this.activeQueue];
|
|
2319
|
+
}
|
|
2320
|
+
/** Destroy all subdocuments and providers. */
|
|
2321
|
+
destroy() {
|
|
2322
|
+
for (const [id] of this.states) {
|
|
2323
|
+
this.deactivate(id);
|
|
2324
|
+
}
|
|
2325
|
+
this.parentProvider?.destroy();
|
|
2326
|
+
this.parentDoc.destroy();
|
|
2327
|
+
this.states.clear();
|
|
2328
|
+
this.activeQueue.length = 0;
|
|
2329
|
+
}
|
|
2330
|
+
};
|
|
2331
|
+
|
|
2330
2332
|
// src/ai/prompts.ts
|
|
2331
2333
|
var CONTEXT_CHAR_CAP = 1500;
|
|
2332
2334
|
var ONLY_RESULT = "Return ONLY the resulting text \u2014 no preamble, no explanation, no commentary, no markdown fences.";
|
|
@@ -2600,6 +2602,7 @@ function openaiCompatibleProvider(config) {
|
|
|
2600
2602
|
PaginationPlus,
|
|
2601
2603
|
PerformanceMonitor,
|
|
2602
2604
|
SearchAndReplaceExtension,
|
|
2605
|
+
SubdocumentProvider,
|
|
2603
2606
|
buildAIPrompt,
|
|
2604
2607
|
clearSearch,
|
|
2605
2608
|
collaborationExtensions,
|