superdoc 0.35.3 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{PdfViewer-C2woiqSD.es.js → PdfViewer-0ljQHJ46.es.js} +2 -2
- package/dist/chunks/{PdfViewer-cKeULrJD.cjs → PdfViewer-S16P3o_7.cjs} +2 -2
- package/dist/chunks/{eventemitter3-DmHNHvFX.cjs → eventemitter3-Cq0SNNyY.cjs} +1 -1
- package/dist/chunks/{eventemitter3-hYlnBzSA.es.js → eventemitter3-Dggxln8t.es.js} +1 -1
- package/dist/chunks/{index-CUb1VdVb-BOiRrEoQ.es.js → index-CzkLnJsZ-BTVdUMdV.es.js} +1 -1
- package/dist/chunks/{index-CUb1VdVb-Dn-WH3X_.cjs → index-CzkLnJsZ-BgswlBSf.cjs} +1 -1
- package/dist/chunks/{index-BLV0gVBb.cjs → index-D3qTp4tj.cjs} +32 -17
- package/dist/chunks/{index-qCXNfgIE.es.js → index-DzR1O6RL.es.js} +32 -17
- package/dist/chunks/{jszip-jKrsZoMS.es.js → jszip-CY0q2Bnp.es.js} +1 -1
- package/dist/chunks/{jszip-BP2FTbpi.cjs → jszip-F-dEByfH.cjs} +1 -1
- package/dist/chunks/{super-editor.es-FtM9y9Xi.cjs → super-editor.es-DVKZ65HN.cjs} +2240 -1699
- package/dist/chunks/{super-editor.es-C-FCfUaM.es.js → super-editor.es-D_ayGwNx.es.js} +2193 -1652
- package/dist/chunks/{vue-Cwv-wUpm.cjs → vue-dM1GiXsI.cjs} +2488 -2423
- package/dist/chunks/{vue-CKmzTNVs.es.js → vue-siHYWVb6.es.js} +2488 -2423
- package/dist/chunks/xml-js-DY0nfayl.cjs +3 -0
- package/dist/chunks/xml-js-lhjyYB16.es.js +2 -0
- package/dist/packages/superdoc/src/core/SuperDoc.d.ts +5 -2
- package/dist/packages/superdoc/src/core/SuperDoc.d.ts.map +1 -1
- package/dist/packages/superdoc/src/core/types/index.d.ts +37 -2
- package/dist/packages/superdoc/src/core/types/index.d.ts.map +1 -1
- package/dist/style.css +37 -33
- package/dist/super-editor/ai-writer.es.js +2 -2
- package/dist/super-editor/chunks/{converter-DCcuo33v.js → converter-C_m22GDt.js} +311 -292
- package/dist/super-editor/chunks/{docx-zipper-BmJ2rJSz.js → docx-zipper-BMFQCW01.js} +1 -1
- package/dist/super-editor/chunks/{editor-CyldDVIe.js → editor-DOp2dsXA.js} +1496 -968
- package/dist/super-editor/chunks/{index-CUb1VdVb.js → index-CzkLnJsZ.js} +1 -1
- package/dist/super-editor/chunks/{toolbar-CO92tGD-.js → toolbar-VEU6sWSR.js} +2 -2
- package/dist/super-editor/converter.es.js +1 -1
- package/dist/super-editor/docx-zipper.es.js +2 -2
- package/dist/super-editor/editor.es.js +3 -3
- package/dist/super-editor/file-zipper.es.js +1 -1
- package/dist/super-editor/style.css +10 -6
- package/dist/super-editor/super-editor/src/core/Editor.d.ts +29 -4
- package/dist/super-editor/super-editor/src/core/Editor.d.ts.map +1 -1
- package/dist/super-editor/super-editor/src/extensions/track-changes/permission-helpers.d.ts +5 -2
- package/dist/super-editor/super-editor/src/extensions/track-changes/permission-helpers.d.ts.map +1 -1
- package/dist/super-editor/super-editor.es.js +32 -28
- package/dist/super-editor/toolbar.es.js +2 -2
- package/dist/super-editor.cjs +2 -2
- package/dist/super-editor.es.js +2 -2
- package/dist/superdoc.cjs +2 -2
- package/dist/superdoc.es.js +2 -2
- package/dist/superdoc.umd.js +2691 -2077
- package/dist/superdoc.umd.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/xml-js-BSDu25I7.cjs +0 -3
- package/dist/chunks/xml-js-CBrRls0f.es.js +0 -2
|
@@ -9,11 +9,11 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
9
9
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10
10
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
11
11
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
12
|
-
var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _editor, _stateValidators, _xmlValidators, _requiredNodeTypes, _requiredMarkTypes, _SuperValidator_instances, initializeValidators_fn, collectValidatorRequirements_fn, analyzeDocument_fn, _commandService, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, registerCopyHandler_fn, insertNewFileData_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, checkFonts_fn, determineUnsupportedFonts_fn, createSchema_fn, generatePmData_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, validateDocumentInit_fn, validateDocumentExport_fn, initDevTools_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ListItemNodeView_instances, init_fn3, applyIndentStyling_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn;
|
|
12
|
+
var _a, _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _editor, _stateValidators, _xmlValidators, _requiredNodeTypes, _requiredMarkTypes, _SuperValidator_instances, initializeValidators_fn, collectValidatorRequirements_fn, analyzeDocument_fn, _commandService, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, validateLayoutMargins_fn, isResponsiveMode_fn, registerCopyHandler_fn, insertNewFileData_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, checkFonts_fn, determineUnsupportedFonts_fn, createSchema_fn, generatePmData_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, validateDocumentInit_fn, validateDocumentExport_fn, initDevTools_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ListItemNodeView_instances, init_fn3, applyIndentStyling_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn;
|
|
13
13
|
import * as Y from "yjs";
|
|
14
14
|
import { UndoManager, Item as Item$1, ContentType, Text as Text$1, XmlElement, encodeStateAsUpdate } from "yjs";
|
|
15
|
-
import { P as PluginKey, a as Plugin, M as Mapping, N as NodeSelection, S as Selection, T as TextSelection, b as Slice, D as DOMSerializer, F as Fragment, c as DOMParser$1, d as Mark$1, e as dropPoint, A as AllSelection, p as process$1, B as Buffer2, f as callOrGet, g as getExtensionConfigField, h as getMarkType, i as getMarksFromSelection, j as getNodeType, k as getSchemaTypeNameByName, l as Schema$
|
|
16
|
-
import { D as DocxZipper } from "./docx-zipper-
|
|
15
|
+
import { P as PluginKey, a as Plugin, M as Mapping, N as NodeSelection, S as Selection, T as TextSelection, b as Slice, D as DOMSerializer, F as Fragment, c as DOMParser$1, d as Mark$1, e as dropPoint, A as AllSelection, p as process$1, B as Buffer2, f as callOrGet, g as getExtensionConfigField, h as getMarkType, i as getMarksFromSelection, j as getNodeType, k as getSchemaTypeNameByName, l as Schema$2, m as cleanSchemaItem, n as canSplit, o as defaultBlockAt$1, q as liftTarget, r as canJoin, s as joinPoint, t as replaceStep$1, R as ReplaceAroundStep$1, u as isTextSelection, v as getMarkRange, w as isMarkActive, x as isNodeActive, y as deleteProps, z as processContent, C as ReplaceStep, E as NodeRange, G as findWrapping, L as ListHelpers, H as findParentNode, I as isMacOS, J as isIOS, K as getSchemaTypeByName, O as inputRulesPlugin, Q as TrackDeleteMarkName, U as TrackInsertMarkName, V as v4, W as TrackFormatMarkName, X as comments_module_events, Y as findMark, Z as objectIncludes, _ as AddMarkStep, $ as RemoveMarkStep, a0 as twipsToLines, a1 as pixelsToTwips, a2 as helpers, a3 as posToDOMRect, a4 as CommandService, a5 as SuperConverter, a6 as createDocument, a7 as createDocFromMarkdown, a8 as createDocFromHTML, a9 as EditorState, aa as hasSomeParentWithClass, ab as isActive, ac as unflattenListsInHtml, ad as parseSizeUnit, ae as minMax, af as getLineHeightValueString, ag as updateDOMAttributes, ah as findChildren$5, ai as htmlHandler, aj as generateRandomSigned32BitIntStrId, ak as InputRule, al as kebabCase, am as findParentNodeClosestToPos, an as getListItemStyleDefinitions, ao as docxNumberingHelpers, ap as parseIndentElement, aq as combineIndents, ar as twipsToPixels, as as PIXELS_PER_INCH$1, at as SelectionRange, au as Transform, av as isInTable$1, aw as generateDocxRandomId, ax as insertNewRelationship, ay as inchesToPixels } from "./converter-C_m22GDt.js";
|
|
16
|
+
import { D as DocxZipper } from "./docx-zipper-BMFQCW01.js";
|
|
17
17
|
import { ref, computed, createElementBlock, openBlock, withModifiers, Fragment as Fragment$1, renderList, normalizeClass, createCommentVNode, toDisplayString, createElementVNode, createApp } from "vue";
|
|
18
18
|
var GOOD_LEAF_SIZE = 200;
|
|
19
19
|
var RopeSequence = function RopeSequence2() {
|
|
@@ -577,7 +577,7 @@ const isEquivalentPosition = function(node, off, targetNode, targetOff) {
|
|
|
577
577
|
};
|
|
578
578
|
const atomElements = /^(img|br|input|textarea|hr)$/i;
|
|
579
579
|
function scanFor(node, off, targetNode, targetOff, dir) {
|
|
580
|
-
var
|
|
580
|
+
var _a2;
|
|
581
581
|
for (; ; ) {
|
|
582
582
|
if (node == targetNode && off == targetOff)
|
|
583
583
|
return true;
|
|
@@ -590,7 +590,7 @@ function scanFor(node, off, targetNode, targetOff, dir) {
|
|
|
590
590
|
} else if (node.nodeType == 1) {
|
|
591
591
|
let child = node.childNodes[off + (dir < 0 ? -1 : 0)];
|
|
592
592
|
if (child.nodeType == 1 && child.contentEditable == "false") {
|
|
593
|
-
if ((
|
|
593
|
+
if ((_a2 = child.pmViewDesc) === null || _a2 === void 0 ? void 0 : _a2.ignoreForSelection)
|
|
594
594
|
off += dir;
|
|
595
595
|
else
|
|
596
596
|
return false;
|
|
@@ -887,17 +887,20 @@ function findOffsetInNode(node, coords) {
|
|
|
887
887
|
}
|
|
888
888
|
function findOffsetInText(node, coords) {
|
|
889
889
|
let len = node.nodeValue.length;
|
|
890
|
-
let range = document.createRange();
|
|
890
|
+
let range = document.createRange(), result;
|
|
891
891
|
for (let i = 0; i < len; i++) {
|
|
892
892
|
range.setEnd(node, i + 1);
|
|
893
893
|
range.setStart(node, i);
|
|
894
894
|
let rect = singleRect(range, 1);
|
|
895
895
|
if (rect.top == rect.bottom)
|
|
896
896
|
continue;
|
|
897
|
-
if (inRect(coords, rect))
|
|
898
|
-
|
|
897
|
+
if (inRect(coords, rect)) {
|
|
898
|
+
result = { node, offset: i + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0) };
|
|
899
|
+
break;
|
|
900
|
+
}
|
|
899
901
|
}
|
|
900
|
-
|
|
902
|
+
range.detach();
|
|
903
|
+
return result || { node, offset: 0 };
|
|
901
904
|
}
|
|
902
905
|
function inRect(coords, rect) {
|
|
903
906
|
return coords.left >= rect.left - 1 && coords.left <= rect.right + 1 && coords.top >= rect.top - 1 && coords.top <= rect.bottom + 1;
|
|
@@ -1214,10 +1217,10 @@ class ViewDesc {
|
|
|
1214
1217
|
}
|
|
1215
1218
|
// The size of the content represented by this desc.
|
|
1216
1219
|
get size() {
|
|
1217
|
-
let
|
|
1220
|
+
let size2 = 0;
|
|
1218
1221
|
for (let i = 0; i < this.children.length; i++)
|
|
1219
|
-
|
|
1220
|
-
return
|
|
1222
|
+
size2 += this.children[i].size;
|
|
1223
|
+
return size2;
|
|
1221
1224
|
}
|
|
1222
1225
|
// For block nodes, this represents the space taken up by their
|
|
1223
1226
|
// start/end tokens.
|
|
@@ -1669,9 +1672,9 @@ class MarkViewDesc extends ViewDesc {
|
|
|
1669
1672
|
}
|
|
1670
1673
|
slice(from2, to, view) {
|
|
1671
1674
|
let copy = MarkViewDesc.create(this.parent, this.mark, true, view);
|
|
1672
|
-
let nodes = this.children,
|
|
1673
|
-
if (to <
|
|
1674
|
-
nodes = replaceNodes(nodes, to,
|
|
1675
|
+
let nodes = this.children, size2 = this.size;
|
|
1676
|
+
if (to < size2)
|
|
1677
|
+
nodes = replaceNodes(nodes, to, size2, view);
|
|
1675
1678
|
if (from2 > 0)
|
|
1676
1679
|
nodes = replaceNodes(nodes, 0, from2, view);
|
|
1677
1680
|
for (let i = 0; i < nodes.length; i++)
|
|
@@ -3144,12 +3147,12 @@ function normalizeSiblings(fragment, $context) {
|
|
|
3144
3147
|
return fragment;
|
|
3145
3148
|
for (let d2 = $context.depth; d2 >= 0; d2--) {
|
|
3146
3149
|
let parent = $context.node(d2);
|
|
3147
|
-
let
|
|
3150
|
+
let match2 = parent.contentMatchAt($context.index(d2));
|
|
3148
3151
|
let lastWrap, result = [];
|
|
3149
3152
|
fragment.forEach((node) => {
|
|
3150
3153
|
if (!result)
|
|
3151
3154
|
return;
|
|
3152
|
-
let wrap =
|
|
3155
|
+
let wrap = match2.findWrapping(node.type), inLast;
|
|
3153
3156
|
if (!wrap)
|
|
3154
3157
|
return result = null;
|
|
3155
3158
|
if (inLast = result.length && lastWrap.length && addToSibling(wrap, lastWrap, node, result[result.length - 1], 0)) {
|
|
@@ -3159,7 +3162,7 @@ function normalizeSiblings(fragment, $context) {
|
|
|
3159
3162
|
result[result.length - 1] = closeRight(result[result.length - 1], lastWrap.length);
|
|
3160
3163
|
let wrapped = withWrappers(node, wrap);
|
|
3161
3164
|
result.push(wrapped);
|
|
3162
|
-
|
|
3165
|
+
match2 = match2.matchType(wrapped.type);
|
|
3163
3166
|
lastWrap = wrap;
|
|
3164
3167
|
}
|
|
3165
3168
|
});
|
|
@@ -3178,8 +3181,8 @@ function addToSibling(wrap, lastWrap, node, sibling, depth) {
|
|
|
3178
3181
|
let inner = addToSibling(wrap, lastWrap, node, sibling.lastChild, depth + 1);
|
|
3179
3182
|
if (inner)
|
|
3180
3183
|
return sibling.copy(sibling.content.replaceChild(sibling.childCount - 1, inner));
|
|
3181
|
-
let
|
|
3182
|
-
if (
|
|
3184
|
+
let match2 = sibling.contentMatchAt(sibling.childCount);
|
|
3185
|
+
if (match2.matchType(depth == wrap.length - 1 ? node.type : wrap[depth + 1]))
|
|
3183
3186
|
return sibling.copy(sibling.content.append(Fragment.from(withWrappers(node, wrap, depth + 1))));
|
|
3184
3187
|
}
|
|
3185
3188
|
}
|
|
@@ -3644,7 +3647,7 @@ editHandlers.compositionstart = editHandlers.compositionupdate = (view) => {
|
|
|
3644
3647
|
if (!view.composing) {
|
|
3645
3648
|
view.domObserver.flush();
|
|
3646
3649
|
let { state } = view, $pos = state.selection.$to;
|
|
3647
|
-
if (state.selection instanceof TextSelection && (state.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some((m) => m.type.spec.inclusive === false))) {
|
|
3650
|
+
if (state.selection instanceof TextSelection && (state.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some((m) => m.type.spec.inclusive === false) || chrome && windows$1 && selectionBeforeUneditable(view))) {
|
|
3648
3651
|
view.markCursor = view.state.storedMarks || $pos.marks();
|
|
3649
3652
|
endComposition(view, true);
|
|
3650
3653
|
view.markCursor = null;
|
|
@@ -3672,6 +3675,13 @@ editHandlers.compositionstart = editHandlers.compositionupdate = (view) => {
|
|
|
3672
3675
|
}
|
|
3673
3676
|
scheduleComposeEnd(view, timeoutComposition);
|
|
3674
3677
|
};
|
|
3678
|
+
function selectionBeforeUneditable(view) {
|
|
3679
|
+
let { focusNode, focusOffset } = view.domSelectionRange();
|
|
3680
|
+
if (!focusNode || focusNode.nodeType != 1 || focusOffset >= focusNode.childNodes.length)
|
|
3681
|
+
return false;
|
|
3682
|
+
let next = focusNode.childNodes[focusOffset];
|
|
3683
|
+
return next.nodeType == 1 && next.contentEditable == "false";
|
|
3684
|
+
}
|
|
3675
3685
|
editHandlers.compositionend = (view, event) => {
|
|
3676
3686
|
if (view.composing) {
|
|
3677
3687
|
view.input.composing = false;
|
|
@@ -3875,10 +3885,14 @@ handlers.dragend = (view) => {
|
|
|
3875
3885
|
}, 50);
|
|
3876
3886
|
};
|
|
3877
3887
|
editHandlers.dragover = editHandlers.dragenter = (_, e) => e.preventDefault();
|
|
3878
|
-
editHandlers.drop = (view,
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3888
|
+
editHandlers.drop = (view, event) => {
|
|
3889
|
+
try {
|
|
3890
|
+
handleDrop(view, event, view.dragging);
|
|
3891
|
+
} finally {
|
|
3892
|
+
view.dragging = null;
|
|
3893
|
+
}
|
|
3894
|
+
};
|
|
3895
|
+
function handleDrop(view, event, dragging) {
|
|
3882
3896
|
if (!event.dataTransfer)
|
|
3883
3897
|
return;
|
|
3884
3898
|
let eventPos = view.posAtCoords(eventCoords(event));
|
|
@@ -3931,7 +3945,7 @@ editHandlers.drop = (view, _event) => {
|
|
|
3931
3945
|
}
|
|
3932
3946
|
view.focus();
|
|
3933
3947
|
view.dispatch(tr.setMeta("uiEvent", "drop"));
|
|
3934
|
-
}
|
|
3948
|
+
}
|
|
3935
3949
|
handlers.focus = (view) => {
|
|
3936
3950
|
view.input.lastFocus = Date.now();
|
|
3937
3951
|
if (!view.focused) {
|
|
@@ -4781,6 +4795,13 @@ class DOMObserver {
|
|
|
4781
4795
|
br.remove();
|
|
4782
4796
|
}
|
|
4783
4797
|
}
|
|
4798
|
+
} else if ((chrome || safari) && added.some((n) => n.nodeName == "BR") && (view.input.lastKeyCode == 8 || view.input.lastKeyCode == 46)) {
|
|
4799
|
+
for (let node of added)
|
|
4800
|
+
if (node.nodeName == "BR" && node.parentNode) {
|
|
4801
|
+
let after = node.nextSibling;
|
|
4802
|
+
if (after && after.nodeType == 1 && after.contentEditable == "false")
|
|
4803
|
+
node.parentNode.removeChild(node);
|
|
4804
|
+
}
|
|
4784
4805
|
}
|
|
4785
4806
|
let readSel = null;
|
|
4786
4807
|
if (from2 < 0 && newSel && view.input.lastFocus > Date.now() - 200 && Math.max(view.input.lastTouch, view.input.lastClick.time) < Date.now() - 300 && selectionCollapsed(sel) && (readSel = selectionFromDOM(view)) && readSel.eq(Selection.near(view.state.doc.resolve(0), 1))) {
|
|
@@ -5298,7 +5319,7 @@ class EditorView {
|
|
|
5298
5319
|
this.updateStateInner(state, this._props);
|
|
5299
5320
|
}
|
|
5300
5321
|
updateStateInner(state, prevProps) {
|
|
5301
|
-
var
|
|
5322
|
+
var _a2;
|
|
5302
5323
|
let prev = this.state, redraw = false, updateSel = false;
|
|
5303
5324
|
if (state.storedMarks && this.composing) {
|
|
5304
5325
|
clearComposition(this);
|
|
@@ -5348,7 +5369,7 @@ class EditorView {
|
|
|
5348
5369
|
this.domObserver.start();
|
|
5349
5370
|
}
|
|
5350
5371
|
this.updatePluginViews(prev);
|
|
5351
|
-
if (((
|
|
5372
|
+
if (((_a2 = this.dragging) === null || _a2 === void 0 ? void 0 : _a2.node) && !prev.doc.eq(state.doc))
|
|
5352
5373
|
this.updateDraggedNode(this.dragging, prev);
|
|
5353
5374
|
if (scroll == "reset") {
|
|
5354
5375
|
this.dom.scrollTop = 0;
|
|
@@ -5718,15 +5739,40 @@ const BIT30 = 1 << 29;
|
|
|
5718
5739
|
const BITS6 = 63;
|
|
5719
5740
|
const BITS7 = 127;
|
|
5720
5741
|
const BITS31 = 2147483647;
|
|
5742
|
+
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
5743
|
+
const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER;
|
|
5721
5744
|
const isInteger = Number.isInteger || ((num) => typeof num === "number" && isFinite(num) && floor$1(num) === num);
|
|
5722
5745
|
const create$2 = () => /* @__PURE__ */ new Set();
|
|
5746
|
+
const every$1 = (arr, f2) => {
|
|
5747
|
+
for (let i = 0; i < arr.length; i++) {
|
|
5748
|
+
if (!f2(arr[i], i, arr)) {
|
|
5749
|
+
return false;
|
|
5750
|
+
}
|
|
5751
|
+
}
|
|
5752
|
+
return true;
|
|
5753
|
+
};
|
|
5754
|
+
const some = (arr, f2) => {
|
|
5755
|
+
for (let i = 0; i < arr.length; i++) {
|
|
5756
|
+
if (f2(arr[i], i, arr)) {
|
|
5757
|
+
return true;
|
|
5758
|
+
}
|
|
5759
|
+
}
|
|
5760
|
+
return false;
|
|
5761
|
+
};
|
|
5762
|
+
const unfold = (len, f2) => {
|
|
5763
|
+
const array = new Array(len);
|
|
5764
|
+
for (let i = 0; i < len; i++) {
|
|
5765
|
+
array[i] = f2(i, array);
|
|
5766
|
+
}
|
|
5767
|
+
return array;
|
|
5768
|
+
};
|
|
5723
5769
|
const isArray = Array.isArray;
|
|
5724
5770
|
const fromCharCode = String.fromCharCode;
|
|
5725
5771
|
const toLowerCase = (s2) => s2.toLowerCase();
|
|
5726
5772
|
const trimLeftRegex = /^\s*/g;
|
|
5727
5773
|
const trimLeft = (s2) => s2.replace(trimLeftRegex, "");
|
|
5728
5774
|
const fromCamelCaseRegex = /([A-Z])/g;
|
|
5729
|
-
const fromCamelCase = (s2, separator) => trimLeft(s2.replace(fromCamelCaseRegex, (
|
|
5775
|
+
const fromCamelCase = (s2, separator) => trimLeft(s2.replace(fromCamelCaseRegex, (match2) => `${separator}${toLowerCase(match2)}`));
|
|
5730
5776
|
const _encodeUtf8Polyfill = (str) => {
|
|
5731
5777
|
const encodedString = unescape(encodeURIComponent(str));
|
|
5732
5778
|
const len = encodedString.length;
|
|
@@ -5747,6 +5793,7 @@ let utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecode
|
|
|
5747
5793
|
if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {
|
|
5748
5794
|
utf8TextDecoder = null;
|
|
5749
5795
|
}
|
|
5796
|
+
const repeat = (source, n) => unfold(n, () => source).join("");
|
|
5750
5797
|
class Encoder {
|
|
5751
5798
|
constructor() {
|
|
5752
5799
|
this.cpos = 0;
|
|
@@ -5943,7 +5990,11 @@ const setIfUndefined = (map2, key2, createT) => {
|
|
|
5943
5990
|
}
|
|
5944
5991
|
return set;
|
|
5945
5992
|
};
|
|
5993
|
+
const EqualityTraitSymbol = Symbol("Equality");
|
|
5994
|
+
const equals = (a, b) => a === b || a[EqualityTraitSymbol]?.(b) || false;
|
|
5995
|
+
const isObject$1 = (o) => typeof o === "object";
|
|
5946
5996
|
const keys = Object.keys;
|
|
5997
|
+
const size = (obj) => keys(obj).length;
|
|
5947
5998
|
const every = (obj, f2) => {
|
|
5948
5999
|
for (const key2 in obj) {
|
|
5949
6000
|
if (!f2(obj[key2], key2)) {
|
|
@@ -5952,6 +6003,81 @@ const every = (obj, f2) => {
|
|
|
5952
6003
|
}
|
|
5953
6004
|
return true;
|
|
5954
6005
|
};
|
|
6006
|
+
const hasProperty = (obj, key2) => Object.prototype.hasOwnProperty.call(obj, key2);
|
|
6007
|
+
const equalityDeep = (a, b) => {
|
|
6008
|
+
if (a === b) {
|
|
6009
|
+
return true;
|
|
6010
|
+
}
|
|
6011
|
+
if (a == null || b == null || a.constructor !== b.constructor && (a.constructor || Object) !== (b.constructor || Object)) {
|
|
6012
|
+
return false;
|
|
6013
|
+
}
|
|
6014
|
+
if (a[EqualityTraitSymbol] != null) {
|
|
6015
|
+
return a[EqualityTraitSymbol](b);
|
|
6016
|
+
}
|
|
6017
|
+
switch (a.constructor) {
|
|
6018
|
+
case ArrayBuffer:
|
|
6019
|
+
a = new Uint8Array(a);
|
|
6020
|
+
b = new Uint8Array(b);
|
|
6021
|
+
// eslint-disable-next-line no-fallthrough
|
|
6022
|
+
case Uint8Array: {
|
|
6023
|
+
if (a.byteLength !== b.byteLength) {
|
|
6024
|
+
return false;
|
|
6025
|
+
}
|
|
6026
|
+
for (let i = 0; i < a.length; i++) {
|
|
6027
|
+
if (a[i] !== b[i]) {
|
|
6028
|
+
return false;
|
|
6029
|
+
}
|
|
6030
|
+
}
|
|
6031
|
+
break;
|
|
6032
|
+
}
|
|
6033
|
+
case Set: {
|
|
6034
|
+
if (a.size !== b.size) {
|
|
6035
|
+
return false;
|
|
6036
|
+
}
|
|
6037
|
+
for (const value of a) {
|
|
6038
|
+
if (!b.has(value)) {
|
|
6039
|
+
return false;
|
|
6040
|
+
}
|
|
6041
|
+
}
|
|
6042
|
+
break;
|
|
6043
|
+
}
|
|
6044
|
+
case Map: {
|
|
6045
|
+
if (a.size !== b.size) {
|
|
6046
|
+
return false;
|
|
6047
|
+
}
|
|
6048
|
+
for (const key2 of a.keys()) {
|
|
6049
|
+
if (!b.has(key2) || !equalityDeep(a.get(key2), b.get(key2))) {
|
|
6050
|
+
return false;
|
|
6051
|
+
}
|
|
6052
|
+
}
|
|
6053
|
+
break;
|
|
6054
|
+
}
|
|
6055
|
+
case void 0:
|
|
6056
|
+
case Object:
|
|
6057
|
+
if (size(a) !== size(b)) {
|
|
6058
|
+
return false;
|
|
6059
|
+
}
|
|
6060
|
+
for (const key2 in a) {
|
|
6061
|
+
if (!hasProperty(a, key2) || !equalityDeep(a[key2], b[key2])) {
|
|
6062
|
+
return false;
|
|
6063
|
+
}
|
|
6064
|
+
}
|
|
6065
|
+
break;
|
|
6066
|
+
case Array:
|
|
6067
|
+
if (a.length !== b.length) {
|
|
6068
|
+
return false;
|
|
6069
|
+
}
|
|
6070
|
+
for (let i = 0; i < a.length; i++) {
|
|
6071
|
+
if (!equalityDeep(a[i], b[i])) {
|
|
6072
|
+
return false;
|
|
6073
|
+
}
|
|
6074
|
+
}
|
|
6075
|
+
break;
|
|
6076
|
+
default:
|
|
6077
|
+
return false;
|
|
6078
|
+
}
|
|
6079
|
+
return true;
|
|
6080
|
+
};
|
|
5955
6081
|
const isOneOf = (value, options) => options.includes(value);
|
|
5956
6082
|
const createMutex = () => {
|
|
5957
6083
|
let token = true;
|
|
@@ -5992,7 +6118,7 @@ const ySyncPluginKey = new PluginKey("y-sync");
|
|
|
5992
6118
|
const yUndoPluginKey = new PluginKey("y-undo");
|
|
5993
6119
|
const yCursorPluginKey = new PluginKey("yjs-cursor");
|
|
5994
6120
|
const rand = Math.random;
|
|
5995
|
-
const oneOf = (arr) => arr[floor$1(rand() * arr.length)];
|
|
6121
|
+
const oneOf$1 = (arr) => arr[floor$1(rand() * arr.length)];
|
|
5996
6122
|
const undefinedToNull = (v) => v === void 0 ? null : v;
|
|
5997
6123
|
class VarStoragePolyfill {
|
|
5998
6124
|
constructor() {
|
|
@@ -6066,15 +6192,771 @@ const computeParams = () => {
|
|
|
6066
6192
|
const hasParam = (name) => computeParams().has(name);
|
|
6067
6193
|
const getVariable = (name) => isNode$1 ? undefinedToNull(process$1.env[name.toUpperCase().replaceAll("-", "_")]) : undefinedToNull(varStorage.getItem(name));
|
|
6068
6194
|
const hasConf = (name) => hasParam("--" + name) || getVariable(name) !== null;
|
|
6069
|
-
hasConf("production");
|
|
6195
|
+
const production = hasConf("production");
|
|
6070
6196
|
const forceColor = isNode$1 && isOneOf(process$1.env.FORCE_COLOR, ["true", "1", "2"]);
|
|
6071
6197
|
forceColor || !hasParam("--no-colors") && // @todo deprecate --no-colors
|
|
6072
6198
|
!hasConf("no-color") && (!isNode$1 || process$1.stdout.isTTY) && (!isNode$1 || hasParam("--color") || getVariable("COLORTERM") !== null || (getVariable("TERM") || "").includes("color"));
|
|
6199
|
+
const toBase64Browser = (bytes) => {
|
|
6200
|
+
let s2 = "";
|
|
6201
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
6202
|
+
s2 += fromCharCode(bytes[i]);
|
|
6203
|
+
}
|
|
6204
|
+
return btoa(s2);
|
|
6205
|
+
};
|
|
6206
|
+
const toBase64Node = (bytes) => Buffer2.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
6207
|
+
const toBase64 = isBrowser$1 ? toBase64Browser : toBase64Node;
|
|
6208
|
+
const encodeAny = (data) => encode((encoder) => writeAny(encoder, data));
|
|
6209
|
+
const bool = (gen) => gen.next() >= 0.5;
|
|
6210
|
+
const int53 = (gen, min2, max2) => floor$1(gen.next() * (max2 + 1 - min2) + min2);
|
|
6211
|
+
const int32 = (gen, min2, max2) => floor$1(gen.next() * (max2 + 1 - min2) + min2);
|
|
6212
|
+
const int31 = (gen, min2, max2) => int32(gen, min2, max2);
|
|
6213
|
+
const letter = (gen) => fromCharCode(int31(gen, 97, 122));
|
|
6214
|
+
const word = (gen, minLen = 0, maxLen = 20) => {
|
|
6215
|
+
const len = int31(gen, minLen, maxLen);
|
|
6216
|
+
let str = "";
|
|
6217
|
+
for (let i = 0; i < len; i++) {
|
|
6218
|
+
str += letter(gen);
|
|
6219
|
+
}
|
|
6220
|
+
return str;
|
|
6221
|
+
};
|
|
6222
|
+
const oneOf = (gen, array) => array[int31(gen, 0, array.length - 1)];
|
|
6223
|
+
const schemaSymbol = Symbol("0schema");
|
|
6224
|
+
class ValidationError {
|
|
6225
|
+
constructor() {
|
|
6226
|
+
this._rerrs = [];
|
|
6227
|
+
}
|
|
6228
|
+
/**
|
|
6229
|
+
* @param {string?} path
|
|
6230
|
+
* @param {string} expected
|
|
6231
|
+
* @param {string} has
|
|
6232
|
+
* @param {string?} message
|
|
6233
|
+
*/
|
|
6234
|
+
extend(path, expected, has, message = null) {
|
|
6235
|
+
this._rerrs.push({ path, expected, has, message });
|
|
6236
|
+
}
|
|
6237
|
+
toString() {
|
|
6238
|
+
const s2 = [];
|
|
6239
|
+
for (let i = this._rerrs.length - 1; i > 0; i--) {
|
|
6240
|
+
const r2 = this._rerrs[i];
|
|
6241
|
+
s2.push(repeat(" ", (this._rerrs.length - i) * 2) + `${r2.path != null ? `[${r2.path}] ` : ""}${r2.has} doesn't match ${r2.expected}. ${r2.message}`);
|
|
6242
|
+
}
|
|
6243
|
+
return s2.join("\n");
|
|
6244
|
+
}
|
|
6245
|
+
}
|
|
6246
|
+
const shapeExtends = (a, b) => {
|
|
6247
|
+
if (a === b) return true;
|
|
6248
|
+
if (a == null || b == null || a.constructor !== b.constructor) return false;
|
|
6249
|
+
if (a[EqualityTraitSymbol]) return equals(a, b);
|
|
6250
|
+
if (isArray(a)) {
|
|
6251
|
+
return every$1(
|
|
6252
|
+
a,
|
|
6253
|
+
(aitem) => some(b, (bitem) => shapeExtends(aitem, bitem))
|
|
6254
|
+
);
|
|
6255
|
+
} else if (isObject$1(a)) {
|
|
6256
|
+
return every(
|
|
6257
|
+
a,
|
|
6258
|
+
(aitem, akey) => shapeExtends(aitem, b[akey])
|
|
6259
|
+
);
|
|
6260
|
+
}
|
|
6261
|
+
return false;
|
|
6262
|
+
};
|
|
6263
|
+
let Schema$1 = (_a = class {
|
|
6264
|
+
/**
|
|
6265
|
+
* @param {Schema<any>} other
|
|
6266
|
+
*/
|
|
6267
|
+
extends(other) {
|
|
6268
|
+
let [a, b] = [
|
|
6269
|
+
/** @type {any} */
|
|
6270
|
+
this.shape,
|
|
6271
|
+
/** @type {any} */
|
|
6272
|
+
other.shape
|
|
6273
|
+
];
|
|
6274
|
+
if (
|
|
6275
|
+
/** @type {typeof Schema<any>} */
|
|
6276
|
+
this.constructor._dilutes
|
|
6277
|
+
) [b, a] = [a, b];
|
|
6278
|
+
return shapeExtends(a, b);
|
|
6279
|
+
}
|
|
6280
|
+
/**
|
|
6281
|
+
* Overwrite this when necessary. By default, we only check the `shape` property which every shape
|
|
6282
|
+
* should have.
|
|
6283
|
+
* @param {Schema<any>} other
|
|
6284
|
+
*/
|
|
6285
|
+
equals(other) {
|
|
6286
|
+
return this.constructor === other.constructor && equalityDeep(this.shape, other.shape);
|
|
6287
|
+
}
|
|
6288
|
+
[schemaSymbol]() {
|
|
6289
|
+
return true;
|
|
6290
|
+
}
|
|
6291
|
+
/**
|
|
6292
|
+
* @param {object} other
|
|
6293
|
+
*/
|
|
6294
|
+
[EqualityTraitSymbol](other) {
|
|
6295
|
+
return this.equals(
|
|
6296
|
+
/** @type {any} */
|
|
6297
|
+
other
|
|
6298
|
+
);
|
|
6299
|
+
}
|
|
6300
|
+
/**
|
|
6301
|
+
* Use `schema.validate(obj)` with a typed parameter that is already of typed to be an instance of
|
|
6302
|
+
* Schema. Validate will check the structure of the parameter and return true iff the instance
|
|
6303
|
+
* really is an instance of Schema.
|
|
6304
|
+
*
|
|
6305
|
+
* @param {T} o
|
|
6306
|
+
* @return {boolean}
|
|
6307
|
+
*/
|
|
6308
|
+
validate(o) {
|
|
6309
|
+
return this.check(o);
|
|
6310
|
+
}
|
|
6311
|
+
/* c8 ignore start */
|
|
6312
|
+
/**
|
|
6313
|
+
* Similar to validate, but this method accepts untyped parameters.
|
|
6314
|
+
*
|
|
6315
|
+
* @param {any} _o
|
|
6316
|
+
* @param {ValidationError} [_err]
|
|
6317
|
+
* @return {_o is T}
|
|
6318
|
+
*/
|
|
6319
|
+
check(_o, _err) {
|
|
6320
|
+
methodUnimplemented();
|
|
6321
|
+
}
|
|
6322
|
+
/* c8 ignore stop */
|
|
6323
|
+
/**
|
|
6324
|
+
* @type {Schema<T?>}
|
|
6325
|
+
*/
|
|
6326
|
+
get nullable() {
|
|
6327
|
+
return $union(this, $null);
|
|
6328
|
+
}
|
|
6329
|
+
/**
|
|
6330
|
+
* @type {$Optional<Schema<T>>}
|
|
6331
|
+
*/
|
|
6332
|
+
get optional() {
|
|
6333
|
+
return new $Optional(
|
|
6334
|
+
/** @type {Schema<T>} */
|
|
6335
|
+
this
|
|
6336
|
+
);
|
|
6337
|
+
}
|
|
6338
|
+
/**
|
|
6339
|
+
* Cast a variable to a specific type. Returns the casted value, or throws an exception otherwise.
|
|
6340
|
+
* Use this if you know that the type is of a specific type and you just want to convince the type
|
|
6341
|
+
* system.
|
|
6342
|
+
*
|
|
6343
|
+
* **Do not rely on these error messages!**
|
|
6344
|
+
* Performs an assertion check only if not in a production environment.
|
|
6345
|
+
*
|
|
6346
|
+
* @template OO
|
|
6347
|
+
* @param {OO} o
|
|
6348
|
+
* @return {Extract<OO, T> extends never ? T : (OO extends Array<never> ? T : Extract<OO,T>)}
|
|
6349
|
+
*/
|
|
6350
|
+
cast(o) {
|
|
6351
|
+
assert(o, this);
|
|
6352
|
+
return (
|
|
6353
|
+
/** @type {any} */
|
|
6354
|
+
o
|
|
6355
|
+
);
|
|
6356
|
+
}
|
|
6357
|
+
/**
|
|
6358
|
+
* EXPECTO PATRONUM!! 🪄
|
|
6359
|
+
* This function protects against type errors. Though it may not work in the real world.
|
|
6360
|
+
*
|
|
6361
|
+
* "After all this time?"
|
|
6362
|
+
* "Always." - Snape, talking about type safety
|
|
6363
|
+
*
|
|
6364
|
+
* Ensures that a variable is a a specific type. Returns the value, or throws an exception if the assertion check failed.
|
|
6365
|
+
* Use this if you know that the type is of a specific type and you just want to convince the type
|
|
6366
|
+
* system.
|
|
6367
|
+
*
|
|
6368
|
+
* Can be useful when defining lambdas: `s.lambda(s.$number, s.$void).expect((n) => n + 1)`
|
|
6369
|
+
*
|
|
6370
|
+
* **Do not rely on these error messages!**
|
|
6371
|
+
* Performs an assertion check if not in a production environment.
|
|
6372
|
+
*
|
|
6373
|
+
* @param {T} o
|
|
6374
|
+
* @return {o extends T ? T : never}
|
|
6375
|
+
*/
|
|
6376
|
+
expect(o) {
|
|
6377
|
+
assert(o, this);
|
|
6378
|
+
return o;
|
|
6379
|
+
}
|
|
6380
|
+
}, // this.shape must not be defined on Schema. Otherwise typecheck on metatypes (e.g. $$object) won't work as expected anymore
|
|
6381
|
+
/**
|
|
6382
|
+
* If true, the more things are added to the shape the more objects this schema will accept (e.g.
|
|
6383
|
+
* union). By default, the more objects are added, the the fewer objects this schema will accept.
|
|
6384
|
+
* @protected
|
|
6385
|
+
*/
|
|
6386
|
+
__publicField(_a, "_dilutes", false), _a);
|
|
6387
|
+
class $ConstructedBy extends Schema$1 {
|
|
6388
|
+
/**
|
|
6389
|
+
* @param {C} c
|
|
6390
|
+
* @param {((o:Instance<C>)=>boolean)|null} check
|
|
6391
|
+
*/
|
|
6392
|
+
constructor(c, check) {
|
|
6393
|
+
super();
|
|
6394
|
+
this.shape = c;
|
|
6395
|
+
this._c = check;
|
|
6396
|
+
}
|
|
6397
|
+
/**
|
|
6398
|
+
* @param {any} o
|
|
6399
|
+
* @param {ValidationError} [err]
|
|
6400
|
+
* @return {o is C extends ((...args:any[]) => infer T) ? T : (C extends (new (...args:any[]) => any) ? InstanceType<C> : never)} o
|
|
6401
|
+
*/
|
|
6402
|
+
check(o, err = void 0) {
|
|
6403
|
+
const c = o?.constructor === this.shape && (this._c == null || this._c(o));
|
|
6404
|
+
!c && err?.extend(null, this.shape.name, o?.constructor.name, o?.constructor !== this.shape ? "Constructor match failed" : "Check failed");
|
|
6405
|
+
return c;
|
|
6406
|
+
}
|
|
6407
|
+
}
|
|
6408
|
+
const $constructedBy = (c, check = null) => new $ConstructedBy(c, check);
|
|
6409
|
+
$constructedBy($ConstructedBy);
|
|
6410
|
+
class $Custom extends Schema$1 {
|
|
6411
|
+
/**
|
|
6412
|
+
* @param {(o:any) => boolean} check
|
|
6413
|
+
*/
|
|
6414
|
+
constructor(check) {
|
|
6415
|
+
super();
|
|
6416
|
+
this.shape = check;
|
|
6417
|
+
}
|
|
6418
|
+
/**
|
|
6419
|
+
* @param {any} o
|
|
6420
|
+
* @param {ValidationError} err
|
|
6421
|
+
* @return {o is any}
|
|
6422
|
+
*/
|
|
6423
|
+
check(o, err) {
|
|
6424
|
+
const c = this.shape(o);
|
|
6425
|
+
!c && err?.extend(null, "custom prop", o?.constructor.name, "failed to check custom prop");
|
|
6426
|
+
return c;
|
|
6427
|
+
}
|
|
6428
|
+
}
|
|
6429
|
+
const $custom = (check) => new $Custom(check);
|
|
6430
|
+
$constructedBy($Custom);
|
|
6431
|
+
class $Literal extends Schema$1 {
|
|
6432
|
+
/**
|
|
6433
|
+
* @param {Array<T>} literals
|
|
6434
|
+
*/
|
|
6435
|
+
constructor(literals) {
|
|
6436
|
+
super();
|
|
6437
|
+
this.shape = literals;
|
|
6438
|
+
}
|
|
6439
|
+
/**
|
|
6440
|
+
*
|
|
6441
|
+
* @param {any} o
|
|
6442
|
+
* @param {ValidationError} [err]
|
|
6443
|
+
* @return {o is T}
|
|
6444
|
+
*/
|
|
6445
|
+
check(o, err) {
|
|
6446
|
+
const c = this.shape.some((a) => a === o);
|
|
6447
|
+
!c && err?.extend(null, this.shape.join(" | "), o.toString());
|
|
6448
|
+
return c;
|
|
6449
|
+
}
|
|
6450
|
+
}
|
|
6451
|
+
const $literal = (...literals) => new $Literal(literals);
|
|
6452
|
+
const $$literal = $constructedBy($Literal);
|
|
6453
|
+
const _regexEscape = (
|
|
6454
|
+
/** @type {any} */
|
|
6455
|
+
RegExp.escape || /** @type {(str:string) => string} */
|
|
6456
|
+
((str) => str.replace(/[().|&,$^[\]]/g, (s2) => "\\" + s2))
|
|
6457
|
+
);
|
|
6458
|
+
const _schemaStringTemplateToRegex = (s2) => {
|
|
6459
|
+
if ($string.check(s2)) {
|
|
6460
|
+
return [_regexEscape(s2)];
|
|
6461
|
+
}
|
|
6462
|
+
if ($$literal.check(s2)) {
|
|
6463
|
+
return (
|
|
6464
|
+
/** @type {Array<string|number>} */
|
|
6465
|
+
s2.shape.map((v) => v + "")
|
|
6466
|
+
);
|
|
6467
|
+
}
|
|
6468
|
+
if ($$number.check(s2)) {
|
|
6469
|
+
return ["[+-]?\\d+.?\\d*"];
|
|
6470
|
+
}
|
|
6471
|
+
if ($$string.check(s2)) {
|
|
6472
|
+
return [".*"];
|
|
6473
|
+
}
|
|
6474
|
+
if ($$union.check(s2)) {
|
|
6475
|
+
return s2.shape.map(_schemaStringTemplateToRegex).flat(1);
|
|
6476
|
+
}
|
|
6477
|
+
unexpectedCase();
|
|
6478
|
+
};
|
|
6479
|
+
class $StringTemplate extends Schema$1 {
|
|
6480
|
+
/**
|
|
6481
|
+
* @param {T} shape
|
|
6482
|
+
*/
|
|
6483
|
+
constructor(shape) {
|
|
6484
|
+
super();
|
|
6485
|
+
this.shape = shape;
|
|
6486
|
+
this._r = new RegExp("^" + shape.map(_schemaStringTemplateToRegex).map((opts) => `(${opts.join("|")})`).join("") + "$");
|
|
6487
|
+
}
|
|
6488
|
+
/**
|
|
6489
|
+
* @param {any} o
|
|
6490
|
+
* @param {ValidationError} [err]
|
|
6491
|
+
* @return {o is CastStringTemplateArgsToTemplate<T>}
|
|
6492
|
+
*/
|
|
6493
|
+
check(o, err) {
|
|
6494
|
+
const c = this._r.exec(o) != null;
|
|
6495
|
+
!c && err?.extend(null, this._r.toString(), o.toString(), "String doesn't match string template.");
|
|
6496
|
+
return c;
|
|
6497
|
+
}
|
|
6498
|
+
}
|
|
6499
|
+
$constructedBy($StringTemplate);
|
|
6500
|
+
const isOptionalSymbol = Symbol("optional");
|
|
6501
|
+
class $Optional extends Schema$1 {
|
|
6502
|
+
/**
|
|
6503
|
+
* @param {S} shape
|
|
6504
|
+
*/
|
|
6505
|
+
constructor(shape) {
|
|
6506
|
+
super();
|
|
6507
|
+
this.shape = shape;
|
|
6508
|
+
}
|
|
6509
|
+
/**
|
|
6510
|
+
* @param {any} o
|
|
6511
|
+
* @param {ValidationError} [err]
|
|
6512
|
+
* @return {o is (Unwrap<S>|undefined)}
|
|
6513
|
+
*/
|
|
6514
|
+
check(o, err) {
|
|
6515
|
+
const c = o === void 0 || this.shape.check(o);
|
|
6516
|
+
!c && err?.extend(null, "undefined (optional)", "()");
|
|
6517
|
+
return c;
|
|
6518
|
+
}
|
|
6519
|
+
get [isOptionalSymbol]() {
|
|
6520
|
+
return true;
|
|
6521
|
+
}
|
|
6522
|
+
}
|
|
6523
|
+
const $$optional = $constructedBy($Optional);
|
|
6524
|
+
class $Never extends Schema$1 {
|
|
6525
|
+
/**
|
|
6526
|
+
* @param {any} _o
|
|
6527
|
+
* @param {ValidationError} [err]
|
|
6528
|
+
* @return {_o is never}
|
|
6529
|
+
*/
|
|
6530
|
+
check(_o, err) {
|
|
6531
|
+
err?.extend(null, "never", typeof _o);
|
|
6532
|
+
return false;
|
|
6533
|
+
}
|
|
6534
|
+
}
|
|
6535
|
+
$constructedBy($Never);
|
|
6536
|
+
const _$Object = class _$Object extends Schema$1 {
|
|
6537
|
+
/**
|
|
6538
|
+
* @param {S} shape
|
|
6539
|
+
* @param {boolean} partial
|
|
6540
|
+
*/
|
|
6541
|
+
constructor(shape, partial = false) {
|
|
6542
|
+
super();
|
|
6543
|
+
this.shape = shape;
|
|
6544
|
+
this._isPartial = partial;
|
|
6545
|
+
}
|
|
6546
|
+
/**
|
|
6547
|
+
* @type {Schema<Partial<$ObjectToType<S>>>}
|
|
6548
|
+
*/
|
|
6549
|
+
get partial() {
|
|
6550
|
+
return new _$Object(this.shape, true);
|
|
6551
|
+
}
|
|
6552
|
+
/**
|
|
6553
|
+
* @param {any} o
|
|
6554
|
+
* @param {ValidationError} err
|
|
6555
|
+
* @return {o is $ObjectToType<S>}
|
|
6556
|
+
*/
|
|
6557
|
+
check(o, err) {
|
|
6558
|
+
if (o == null) {
|
|
6559
|
+
err?.extend(null, "object", "null");
|
|
6560
|
+
return false;
|
|
6561
|
+
}
|
|
6562
|
+
return every(this.shape, (vv, vk) => {
|
|
6563
|
+
const c = this._isPartial && !hasProperty(o, vk) || vv.check(o[vk], err);
|
|
6564
|
+
!c && err?.extend(vk.toString(), vv.toString(), typeof o[vk], "Object property does not match");
|
|
6565
|
+
return c;
|
|
6566
|
+
});
|
|
6567
|
+
}
|
|
6568
|
+
};
|
|
6569
|
+
__publicField(_$Object, "_dilutes", true);
|
|
6570
|
+
let $Object = _$Object;
|
|
6571
|
+
const $object = (def) => (
|
|
6572
|
+
/** @type {any} */
|
|
6573
|
+
new $Object(def)
|
|
6574
|
+
);
|
|
6575
|
+
const $$object = $constructedBy($Object);
|
|
6576
|
+
const $objectAny = $custom((o) => o != null && (o.constructor === Object || o.constructor == null));
|
|
6577
|
+
class $Record extends Schema$1 {
|
|
6578
|
+
/**
|
|
6579
|
+
* @param {Keys} keys
|
|
6580
|
+
* @param {Values} values
|
|
6581
|
+
*/
|
|
6582
|
+
constructor(keys2, values) {
|
|
6583
|
+
super();
|
|
6584
|
+
this.shape = {
|
|
6585
|
+
keys: keys2,
|
|
6586
|
+
values
|
|
6587
|
+
};
|
|
6588
|
+
}
|
|
6589
|
+
/**
|
|
6590
|
+
* @param {any} o
|
|
6591
|
+
* @param {ValidationError} err
|
|
6592
|
+
* @return {o is { [key in Unwrap<Keys>]: Unwrap<Values> }}
|
|
6593
|
+
*/
|
|
6594
|
+
check(o, err) {
|
|
6595
|
+
return o != null && every(o, (vv, vk) => {
|
|
6596
|
+
const ck = this.shape.keys.check(vk, err);
|
|
6597
|
+
!ck && err?.extend(vk + "", "Record", typeof o, ck ? "Key doesn't match schema" : "Value doesn't match value");
|
|
6598
|
+
return ck && this.shape.values.check(vv, err);
|
|
6599
|
+
});
|
|
6600
|
+
}
|
|
6601
|
+
}
|
|
6602
|
+
const $record = (keys2, values) => new $Record(keys2, values);
|
|
6603
|
+
const $$record = $constructedBy($Record);
|
|
6604
|
+
class $Tuple extends Schema$1 {
|
|
6605
|
+
/**
|
|
6606
|
+
* @param {S} shape
|
|
6607
|
+
*/
|
|
6608
|
+
constructor(shape) {
|
|
6609
|
+
super();
|
|
6610
|
+
this.shape = shape;
|
|
6611
|
+
}
|
|
6612
|
+
/**
|
|
6613
|
+
* @param {any} o
|
|
6614
|
+
* @param {ValidationError} err
|
|
6615
|
+
* @return {o is { [K in keyof S]: S[K] extends Schema<infer Type> ? Type : never }}
|
|
6616
|
+
*/
|
|
6617
|
+
check(o, err) {
|
|
6618
|
+
return o != null && every(this.shape, (vv, vk) => {
|
|
6619
|
+
const c = (
|
|
6620
|
+
/** @type {Schema<any>} */
|
|
6621
|
+
vv.check(o[vk], err)
|
|
6622
|
+
);
|
|
6623
|
+
!c && err?.extend(vk.toString(), "Tuple", typeof vv);
|
|
6624
|
+
return c;
|
|
6625
|
+
});
|
|
6626
|
+
}
|
|
6627
|
+
}
|
|
6628
|
+
const $tuple = (...def) => new $Tuple(def);
|
|
6629
|
+
$constructedBy($Tuple);
|
|
6630
|
+
class $Array extends Schema$1 {
|
|
6631
|
+
/**
|
|
6632
|
+
* @param {Array<S>} v
|
|
6633
|
+
*/
|
|
6634
|
+
constructor(v) {
|
|
6635
|
+
super();
|
|
6636
|
+
this.shape = v.length === 1 ? v[0] : new $Union(v);
|
|
6637
|
+
}
|
|
6638
|
+
/**
|
|
6639
|
+
* @param {any} o
|
|
6640
|
+
* @param {ValidationError} [err]
|
|
6641
|
+
* @return {o is Array<S extends Schema<infer T> ? T : never>} o
|
|
6642
|
+
*/
|
|
6643
|
+
check(o, err) {
|
|
6644
|
+
const c = isArray(o) && every$1(o, (oi) => this.shape.check(oi));
|
|
6645
|
+
!c && err?.extend(null, "Array", "");
|
|
6646
|
+
return c;
|
|
6647
|
+
}
|
|
6648
|
+
}
|
|
6649
|
+
const $array = (...def) => new $Array(def);
|
|
6650
|
+
const $$array = $constructedBy($Array);
|
|
6651
|
+
const $arrayAny = $custom((o) => isArray(o));
|
|
6652
|
+
class $InstanceOf extends Schema$1 {
|
|
6653
|
+
/**
|
|
6654
|
+
* @param {new (...args:any) => T} constructor
|
|
6655
|
+
* @param {((o:T) => boolean)|null} check
|
|
6656
|
+
*/
|
|
6657
|
+
constructor(constructor, check) {
|
|
6658
|
+
super();
|
|
6659
|
+
this.shape = constructor;
|
|
6660
|
+
this._c = check;
|
|
6661
|
+
}
|
|
6662
|
+
/**
|
|
6663
|
+
* @param {any} o
|
|
6664
|
+
* @param {ValidationError} err
|
|
6665
|
+
* @return {o is T}
|
|
6666
|
+
*/
|
|
6667
|
+
check(o, err) {
|
|
6668
|
+
const c = o instanceof this.shape && (this._c == null || this._c(o));
|
|
6669
|
+
!c && err?.extend(null, this.shape.name, o?.constructor.name);
|
|
6670
|
+
return c;
|
|
6671
|
+
}
|
|
6672
|
+
}
|
|
6673
|
+
const $instanceOf = (c, check = null) => new $InstanceOf(c, check);
|
|
6674
|
+
$constructedBy($InstanceOf);
|
|
6675
|
+
const $$schema = $instanceOf(Schema$1);
|
|
6676
|
+
class $Lambda extends Schema$1 {
|
|
6677
|
+
/**
|
|
6678
|
+
* @param {Args} args
|
|
6679
|
+
*/
|
|
6680
|
+
constructor(args) {
|
|
6681
|
+
super();
|
|
6682
|
+
this.len = args.length - 1;
|
|
6683
|
+
this.args = $tuple(...args.slice(-1));
|
|
6684
|
+
this.res = args[this.len];
|
|
6685
|
+
}
|
|
6686
|
+
/**
|
|
6687
|
+
* @param {any} f
|
|
6688
|
+
* @param {ValidationError} err
|
|
6689
|
+
* @return {f is _LArgsToLambdaDef<Args>}
|
|
6690
|
+
*/
|
|
6691
|
+
check(f2, err) {
|
|
6692
|
+
const c = f2.constructor === Function && f2.length <= this.len;
|
|
6693
|
+
!c && err?.extend(null, "function", typeof f2);
|
|
6694
|
+
return c;
|
|
6695
|
+
}
|
|
6696
|
+
}
|
|
6697
|
+
const $$lambda = $constructedBy($Lambda);
|
|
6698
|
+
const $function = $custom((o) => typeof o === "function");
|
|
6699
|
+
class $Intersection extends Schema$1 {
|
|
6700
|
+
/**
|
|
6701
|
+
* @param {T} v
|
|
6702
|
+
*/
|
|
6703
|
+
constructor(v) {
|
|
6704
|
+
super();
|
|
6705
|
+
this.shape = v;
|
|
6706
|
+
}
|
|
6707
|
+
/**
|
|
6708
|
+
* @param {any} o
|
|
6709
|
+
* @param {ValidationError} [err]
|
|
6710
|
+
* @return {o is Intersect<UnwrapArray<T>>}
|
|
6711
|
+
*/
|
|
6712
|
+
check(o, err) {
|
|
6713
|
+
const c = every$1(this.shape, (check) => check.check(o, err));
|
|
6714
|
+
!c && err?.extend(null, "Intersectinon", typeof o);
|
|
6715
|
+
return c;
|
|
6716
|
+
}
|
|
6717
|
+
}
|
|
6718
|
+
$constructedBy($Intersection, (o) => o.shape.length > 0);
|
|
6719
|
+
class $Union extends Schema$1 {
|
|
6720
|
+
/**
|
|
6721
|
+
* @param {Array<Schema<S>>} v
|
|
6722
|
+
*/
|
|
6723
|
+
constructor(v) {
|
|
6724
|
+
super();
|
|
6725
|
+
this.shape = v;
|
|
6726
|
+
}
|
|
6727
|
+
/**
|
|
6728
|
+
* @param {any} o
|
|
6729
|
+
* @param {ValidationError} [err]
|
|
6730
|
+
* @return {o is S}
|
|
6731
|
+
*/
|
|
6732
|
+
check(o, err) {
|
|
6733
|
+
const c = some(this.shape, (vv) => vv.check(o, err));
|
|
6734
|
+
err?.extend(null, "Union", typeof o);
|
|
6735
|
+
return c;
|
|
6736
|
+
}
|
|
6737
|
+
}
|
|
6738
|
+
__publicField($Union, "_dilutes", true);
|
|
6739
|
+
const $union = (...schemas) => schemas.findIndex(($s) => $$union.check($s)) >= 0 ? $union(...schemas.map(($s) => $($s)).map(($s) => $$union.check($s) ? $s.shape : [$s]).flat(1)) : schemas.length === 1 ? schemas[0] : new $Union(schemas);
|
|
6740
|
+
const $$union = (
|
|
6741
|
+
/** @type {Schema<$Union<any>>} */
|
|
6742
|
+
$constructedBy($Union)
|
|
6743
|
+
);
|
|
6744
|
+
const _t = () => true;
|
|
6745
|
+
const $any = $custom(_t);
|
|
6746
|
+
const $$any = (
|
|
6747
|
+
/** @type {Schema<Schema<any>>} */
|
|
6748
|
+
$constructedBy($Custom, (o) => o.shape === _t)
|
|
6749
|
+
);
|
|
6750
|
+
const $bigint = $custom((o) => typeof o === "bigint");
|
|
6751
|
+
const $$bigint = (
|
|
6752
|
+
/** @type {Schema<Schema<BigInt>>} */
|
|
6753
|
+
$custom((o) => o === $bigint)
|
|
6754
|
+
);
|
|
6755
|
+
const $symbol = $custom((o) => typeof o === "symbol");
|
|
6756
|
+
$custom((o) => o === $symbol);
|
|
6757
|
+
const $number = $custom((o) => typeof o === "number");
|
|
6758
|
+
const $$number = (
|
|
6759
|
+
/** @type {Schema<Schema<number>>} */
|
|
6760
|
+
$custom((o) => o === $number)
|
|
6761
|
+
);
|
|
6762
|
+
const $string = $custom((o) => typeof o === "string");
|
|
6763
|
+
const $$string = (
|
|
6764
|
+
/** @type {Schema<Schema<string>>} */
|
|
6765
|
+
$custom((o) => o === $string)
|
|
6766
|
+
);
|
|
6767
|
+
const $boolean = $custom((o) => typeof o === "boolean");
|
|
6768
|
+
const $$boolean = (
|
|
6769
|
+
/** @type {Schema<Schema<Boolean>>} */
|
|
6770
|
+
$custom((o) => o === $boolean)
|
|
6771
|
+
);
|
|
6772
|
+
const $undefined = $literal(void 0);
|
|
6773
|
+
$constructedBy($Literal, (o) => o.shape.length === 1 && o.shape[0] === void 0);
|
|
6774
|
+
$literal(void 0);
|
|
6775
|
+
const $null = $literal(null);
|
|
6776
|
+
const $$null = (
|
|
6777
|
+
/** @type {Schema<Schema<null>>} */
|
|
6778
|
+
$constructedBy($Literal, (o) => o.shape.length === 1 && o.shape[0] === null)
|
|
6779
|
+
);
|
|
6780
|
+
$constructedBy(Uint8Array);
|
|
6781
|
+
$constructedBy($ConstructedBy, (o) => o.shape === Uint8Array);
|
|
6782
|
+
const $primitive = $union($number, $string, $null, $undefined, $bigint, $boolean, $symbol);
|
|
6783
|
+
(() => {
|
|
6784
|
+
const $jsonArr = (
|
|
6785
|
+
/** @type {$Array<$any>} */
|
|
6786
|
+
$array($any)
|
|
6787
|
+
);
|
|
6788
|
+
const $jsonRecord = (
|
|
6789
|
+
/** @type {$Record<$string,$any>} */
|
|
6790
|
+
$record($string, $any)
|
|
6791
|
+
);
|
|
6792
|
+
const $json = $union($number, $string, $null, $boolean, $jsonArr, $jsonRecord);
|
|
6793
|
+
$jsonArr.shape = $json;
|
|
6794
|
+
$jsonRecord.shape.values = $json;
|
|
6795
|
+
return $json;
|
|
6796
|
+
})();
|
|
6797
|
+
const $ = (o) => {
|
|
6798
|
+
if ($$schema.check(o)) {
|
|
6799
|
+
return (
|
|
6800
|
+
/** @type {any} */
|
|
6801
|
+
o
|
|
6802
|
+
);
|
|
6803
|
+
} else if ($objectAny.check(o)) {
|
|
6804
|
+
const o2 = {};
|
|
6805
|
+
for (const k2 in o) {
|
|
6806
|
+
o2[k2] = $(o[k2]);
|
|
6807
|
+
}
|
|
6808
|
+
return (
|
|
6809
|
+
/** @type {any} */
|
|
6810
|
+
$object(o2)
|
|
6811
|
+
);
|
|
6812
|
+
} else if ($arrayAny.check(o)) {
|
|
6813
|
+
return (
|
|
6814
|
+
/** @type {any} */
|
|
6815
|
+
$union(...o.map($))
|
|
6816
|
+
);
|
|
6817
|
+
} else if ($primitive.check(o)) {
|
|
6818
|
+
return (
|
|
6819
|
+
/** @type {any} */
|
|
6820
|
+
$literal(o)
|
|
6821
|
+
);
|
|
6822
|
+
} else if ($function.check(o)) {
|
|
6823
|
+
return (
|
|
6824
|
+
/** @type {any} */
|
|
6825
|
+
$constructedBy(
|
|
6826
|
+
/** @type {any} */
|
|
6827
|
+
o
|
|
6828
|
+
)
|
|
6829
|
+
);
|
|
6830
|
+
}
|
|
6831
|
+
unexpectedCase();
|
|
6832
|
+
};
|
|
6833
|
+
const assert = production ? () => {
|
|
6834
|
+
} : (o, schema) => {
|
|
6835
|
+
const err = new ValidationError();
|
|
6836
|
+
if (!schema.check(o, err)) {
|
|
6837
|
+
throw create$1(`Expected value to be of type ${schema.constructor.name}.
|
|
6838
|
+
${err.toString()}`);
|
|
6839
|
+
}
|
|
6840
|
+
};
|
|
6841
|
+
class PatternMatcher {
|
|
6842
|
+
/**
|
|
6843
|
+
* @param {Schema<State>} [$state]
|
|
6844
|
+
*/
|
|
6845
|
+
constructor($state) {
|
|
6846
|
+
this.patterns = [];
|
|
6847
|
+
this.$state = $state;
|
|
6848
|
+
}
|
|
6849
|
+
/**
|
|
6850
|
+
* @template P
|
|
6851
|
+
* @template R
|
|
6852
|
+
* @param {P} pattern
|
|
6853
|
+
* @param {(o:NoInfer<Unwrap<ReadSchema<P>>>,s:State)=>R} handler
|
|
6854
|
+
* @return {PatternMatcher<State,Patterns|Pattern<Unwrap<ReadSchema<P>>,R>>}
|
|
6855
|
+
*/
|
|
6856
|
+
if(pattern, handler) {
|
|
6857
|
+
this.patterns.push({ if: $(pattern), h: handler });
|
|
6858
|
+
return this;
|
|
6859
|
+
}
|
|
6860
|
+
/**
|
|
6861
|
+
* @template R
|
|
6862
|
+
* @param {(o:any,s:State)=>R} h
|
|
6863
|
+
*/
|
|
6864
|
+
else(h) {
|
|
6865
|
+
return this.if($any, h);
|
|
6866
|
+
}
|
|
6867
|
+
/**
|
|
6868
|
+
* @return {State extends undefined
|
|
6869
|
+
* ? <In extends Unwrap<Patterns['if']>>(o:In,state?:undefined)=>PatternMatchResult<Patterns,In>
|
|
6870
|
+
* : <In extends Unwrap<Patterns['if']>>(o:In,state:State)=>PatternMatchResult<Patterns,In>}
|
|
6871
|
+
*/
|
|
6872
|
+
done() {
|
|
6873
|
+
return (
|
|
6874
|
+
/** @type {any} */
|
|
6875
|
+
(o, s2) => {
|
|
6876
|
+
for (let i = 0; i < this.patterns.length; i++) {
|
|
6877
|
+
const p = this.patterns[i];
|
|
6878
|
+
if (p.if.check(o)) {
|
|
6879
|
+
return p.h(o, s2);
|
|
6880
|
+
}
|
|
6881
|
+
}
|
|
6882
|
+
throw create$1("Unhandled pattern");
|
|
6883
|
+
}
|
|
6884
|
+
);
|
|
6885
|
+
}
|
|
6886
|
+
}
|
|
6887
|
+
const match = (state) => new PatternMatcher(
|
|
6888
|
+
/** @type {any} */
|
|
6889
|
+
state
|
|
6890
|
+
);
|
|
6891
|
+
const _random = (
|
|
6892
|
+
/** @type {any} */
|
|
6893
|
+
match(
|
|
6894
|
+
/** @type {Schema<prng.PRNG>} */
|
|
6895
|
+
$any
|
|
6896
|
+
).if($$number, (_o, gen) => int53(gen, MIN_SAFE_INTEGER, MAX_SAFE_INTEGER)).if($$string, (_o, gen) => word(gen)).if($$boolean, (_o, gen) => bool(gen)).if($$bigint, (_o, gen) => BigInt(int53(gen, MIN_SAFE_INTEGER, MAX_SAFE_INTEGER))).if($$union, (o, gen) => random(gen, oneOf(gen, o.shape))).if($$object, (o, gen) => {
|
|
6897
|
+
const res = {};
|
|
6898
|
+
for (const k2 in o.shape) {
|
|
6899
|
+
let prop = o.shape[k2];
|
|
6900
|
+
if ($$optional.check(prop)) {
|
|
6901
|
+
if (bool(gen)) {
|
|
6902
|
+
continue;
|
|
6903
|
+
}
|
|
6904
|
+
prop = prop.shape;
|
|
6905
|
+
}
|
|
6906
|
+
res[k2] = _random(prop, gen);
|
|
6907
|
+
}
|
|
6908
|
+
return res;
|
|
6909
|
+
}).if($$array, (o, gen) => {
|
|
6910
|
+
const arr = [];
|
|
6911
|
+
const n = int32(gen, 0, 42);
|
|
6912
|
+
for (let i = 0; i < n; i++) {
|
|
6913
|
+
arr.push(random(gen, o.shape));
|
|
6914
|
+
}
|
|
6915
|
+
return arr;
|
|
6916
|
+
}).if($$literal, (o, gen) => {
|
|
6917
|
+
return oneOf(gen, o.shape);
|
|
6918
|
+
}).if($$null, (o, gen) => {
|
|
6919
|
+
return null;
|
|
6920
|
+
}).if($$lambda, (o, gen) => {
|
|
6921
|
+
const res = random(gen, o.res);
|
|
6922
|
+
return () => res;
|
|
6923
|
+
}).if($$any, (o, gen) => random(gen, oneOf(gen, [
|
|
6924
|
+
$number,
|
|
6925
|
+
$string,
|
|
6926
|
+
$null,
|
|
6927
|
+
$undefined,
|
|
6928
|
+
$bigint,
|
|
6929
|
+
$boolean,
|
|
6930
|
+
$array($number),
|
|
6931
|
+
$record($union("a", "b", "c"), $number)
|
|
6932
|
+
]))).if($$record, (o, gen) => {
|
|
6933
|
+
const res = {};
|
|
6934
|
+
const keysN = int53(gen, 0, 3);
|
|
6935
|
+
for (let i = 0; i < keysN; i++) {
|
|
6936
|
+
const key2 = random(gen, o.shape.keys);
|
|
6937
|
+
const val = random(gen, o.shape.values);
|
|
6938
|
+
res[key2] = val;
|
|
6939
|
+
}
|
|
6940
|
+
return res;
|
|
6941
|
+
}).done()
|
|
6942
|
+
);
|
|
6943
|
+
const random = (gen, schema) => (
|
|
6944
|
+
/** @type {any} */
|
|
6945
|
+
_random($(schema), gen)
|
|
6946
|
+
);
|
|
6073
6947
|
const doc = (
|
|
6074
6948
|
/** @type {Document} */
|
|
6075
6949
|
typeof document !== "undefined" ? document : {}
|
|
6076
6950
|
);
|
|
6951
|
+
$custom((el) => el.nodeType === DOCUMENT_FRAGMENT_NODE);
|
|
6077
6952
|
typeof DOMParser !== "undefined" ? new DOMParser() : null;
|
|
6953
|
+
$custom((el) => el.nodeType === ELEMENT_NODE);
|
|
6954
|
+
$custom((el) => el.nodeType === TEXT_NODE);
|
|
6955
|
+
const ELEMENT_NODE = doc.ELEMENT_NODE;
|
|
6956
|
+
const TEXT_NODE = doc.TEXT_NODE;
|
|
6957
|
+
const DOCUMENT_NODE = doc.DOCUMENT_NODE;
|
|
6958
|
+
const DOCUMENT_FRAGMENT_NODE = doc.DOCUMENT_FRAGMENT_NODE;
|
|
6959
|
+
$custom((el) => el.nodeType === DOCUMENT_NODE);
|
|
6078
6960
|
const createTimeoutClass = (clearFunction) => class TT {
|
|
6079
6961
|
/**
|
|
6080
6962
|
* @param {number} timeoutId
|
|
@@ -6257,16 +7139,6 @@ class Hasher {
|
|
|
6257
7139
|
}
|
|
6258
7140
|
}
|
|
6259
7141
|
const digest = (data) => new Hasher().digest(data);
|
|
6260
|
-
const toBase64Browser = (bytes) => {
|
|
6261
|
-
let s2 = "";
|
|
6262
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
6263
|
-
s2 += fromCharCode(bytes[i]);
|
|
6264
|
-
}
|
|
6265
|
-
return btoa(s2);
|
|
6266
|
-
};
|
|
6267
|
-
const toBase64Node = (bytes) => Buffer2.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
6268
|
-
const toBase64 = isBrowser$1 ? toBase64Browser : toBase64Node;
|
|
6269
|
-
const encodeAny = (data) => encode((encoder) => writeAny(encoder, data));
|
|
6270
7142
|
const _convolute = (digest2) => {
|
|
6271
7143
|
const N = 6;
|
|
6272
7144
|
for (let i = N; i < digest2.length; i++) {
|
|
@@ -6289,7 +7161,7 @@ const getUserColor = (colorMapping, colors, user) => {
|
|
|
6289
7161
|
colorMapping.forEach((color) => usedColors.add(color));
|
|
6290
7162
|
colors = colors.filter((color) => !usedColors.has(color));
|
|
6291
7163
|
}
|
|
6292
|
-
colorMapping.set(user, oneOf(colors));
|
|
7164
|
+
colorMapping.set(user, oneOf$1(colors));
|
|
6293
7165
|
}
|
|
6294
7166
|
return (
|
|
6295
7167
|
/** @type {ColorDef} */
|
|
@@ -8077,14 +8949,14 @@ const _Schema = class _Schema {
|
|
|
8077
8949
|
* @returns PM schema
|
|
8078
8950
|
*/
|
|
8079
8951
|
static createSchemaByExtensions(extensions, editor) {
|
|
8080
|
-
var
|
|
8952
|
+
var _a2, _b;
|
|
8081
8953
|
const nodeExtensions = extensions.filter((e) => e.type === "node");
|
|
8082
8954
|
const markExtensions = extensions.filter((e) => e.type === "mark");
|
|
8083
8955
|
const topNode = nodeExtensions.find((e) => getExtensionConfigField(e, "topNode"))?.name;
|
|
8084
8956
|
const attributes = Attribute.getAttributesFromExtensions(extensions);
|
|
8085
|
-
const nodes = __privateMethod(
|
|
8957
|
+
const nodes = __privateMethod(_a2 = _Schema, _Schema_static, createNodesSchema_fn).call(_a2, nodeExtensions, attributes, editor);
|
|
8086
8958
|
const marks = __privateMethod(_b = _Schema, _Schema_static, createMarksSchema_fn).call(_b, markExtensions, attributes, editor);
|
|
8087
|
-
return new Schema$
|
|
8959
|
+
return new Schema$2({ topNode, nodes, marks });
|
|
8088
8960
|
}
|
|
8089
8961
|
};
|
|
8090
8962
|
_Schema_static = new WeakSet();
|
|
@@ -8481,9 +9353,9 @@ const newlineInCode$1 = (state, dispatch) => {
|
|
|
8481
9353
|
dispatch(state.tr.insertText("\n").scrollIntoView());
|
|
8482
9354
|
return true;
|
|
8483
9355
|
};
|
|
8484
|
-
function defaultBlockAt(
|
|
8485
|
-
for (let i = 0; i <
|
|
8486
|
-
let { type } =
|
|
9356
|
+
function defaultBlockAt(match2) {
|
|
9357
|
+
for (let i = 0; i < match2.edgeCount; i++) {
|
|
9358
|
+
let { type } = match2.edge(i);
|
|
8487
9359
|
if (type.isTextblock && !type.hasRequiredAttrs())
|
|
8488
9360
|
return type;
|
|
8489
9361
|
}
|
|
@@ -8610,12 +9482,12 @@ function joinMaybeClear(state, $pos, dispatch) {
|
|
|
8610
9482
|
return true;
|
|
8611
9483
|
}
|
|
8612
9484
|
function deleteBarrier(state, $cut, dispatch, dir) {
|
|
8613
|
-
let before = $cut.nodeBefore, after = $cut.nodeAfter, conn,
|
|
9485
|
+
let before = $cut.nodeBefore, after = $cut.nodeAfter, conn, match2;
|
|
8614
9486
|
let isolated = before.type.spec.isolating || after.type.spec.isolating;
|
|
8615
9487
|
if (!isolated && joinMaybeClear(state, $cut, dispatch))
|
|
8616
9488
|
return true;
|
|
8617
9489
|
let canDelAfter = !isolated && $cut.parent.canReplace($cut.index(), $cut.index() + 1);
|
|
8618
|
-
if (canDelAfter && (conn = (
|
|
9490
|
+
if (canDelAfter && (conn = (match2 = before.contentMatchAt(before.childCount)).findWrapping(after.type)) && match2.matchType(conn[0] || after.type).validEnd) {
|
|
8619
9491
|
if (dispatch) {
|
|
8620
9492
|
let end2 = $cut.pos + after.nodeSize, wrap = Fragment.empty;
|
|
8621
9493
|
for (let i = conn.length - 1; i >= 0; i--)
|
|
@@ -9192,7 +10064,7 @@ function createNodeFromContent(content, schema, options) {
|
|
|
9192
10064
|
if (options.errorOnInvalidContent) {
|
|
9193
10065
|
let hasInvalidContent = false;
|
|
9194
10066
|
let invalidContent = "";
|
|
9195
|
-
const contentCheckSchema = new Schema$
|
|
10067
|
+
const contentCheckSchema = new Schema$2({
|
|
9196
10068
|
topNode: schema.spec.topNode,
|
|
9197
10069
|
marks: schema.spec.marks,
|
|
9198
10070
|
// Prosemirror's schemas are executed such that: the last to execute, matches last
|
|
@@ -9826,8 +10698,8 @@ const collectTargetListItemPositions = (state, fallbackPos) => {
|
|
|
9826
10698
|
const { from: from2, to } = state.selection;
|
|
9827
10699
|
doc2.nodesBetween(from2, to, (node, pos) => {
|
|
9828
10700
|
if (node.type === listItemType) {
|
|
9829
|
-
const
|
|
9830
|
-
candidates.push({ node, pos, end: pos +
|
|
10701
|
+
const size2 = typeof node.nodeSize === "number" ? node.nodeSize : 0;
|
|
10702
|
+
candidates.push({ node, pos, end: pos + size2 });
|
|
9831
10703
|
}
|
|
9832
10704
|
});
|
|
9833
10705
|
if (!candidates.length && typeof fallbackPos === "number") {
|
|
@@ -10093,8 +10965,8 @@ const deleteListItem = () => (props) => {
|
|
|
10093
10965
|
}
|
|
10094
10966
|
});
|
|
10095
10967
|
if (fullySelectedBlocks.length) {
|
|
10096
|
-
fullySelectedBlocks.sort((a, b) => b.pos - a.pos).forEach(({ pos, size }) => {
|
|
10097
|
-
tr.delete(pos, pos +
|
|
10968
|
+
fullySelectedBlocks.sort((a, b) => b.pos - a.pos).forEach(({ pos, size: size2 }) => {
|
|
10969
|
+
tr.delete(pos, pos + size2);
|
|
10098
10970
|
});
|
|
10099
10971
|
const $new = tr.doc.resolve(from2);
|
|
10100
10972
|
tr.setSelection(TextSelection.near($new));
|
|
@@ -13352,9 +14224,9 @@ const findWordBounds = (doc2, pos) => {
|
|
|
13352
14224
|
};
|
|
13353
14225
|
const setWordSelection = (view, pos) => {
|
|
13354
14226
|
const { state, dispatch } = view;
|
|
13355
|
-
const
|
|
13356
|
-
if (!
|
|
13357
|
-
const tr = state.tr.setSelection(TextSelection.create(state.doc,
|
|
14227
|
+
const word2 = findWordBounds(state.doc, pos);
|
|
14228
|
+
if (!word2) return;
|
|
14229
|
+
const tr = state.tr.setSelection(TextSelection.create(state.doc, word2.from, word2.to));
|
|
13358
14230
|
dispatch(tr);
|
|
13359
14231
|
};
|
|
13360
14232
|
const setImageNodeSelection = (view, pos) => {
|
|
@@ -14494,6 +15366,9 @@ function buildSchemaSummary(schema, schemaVersion) {
|
|
|
14494
15366
|
marks
|
|
14495
15367
|
};
|
|
14496
15368
|
}
|
|
15369
|
+
const PIXELS_PER_INCH = 96;
|
|
15370
|
+
const MAX_HEIGHT_BUFFER_PX = 50;
|
|
15371
|
+
const MAX_WIDTH_BUFFER_PX = 20;
|
|
14497
15372
|
const _Editor = class _Editor extends EventEmitter {
|
|
14498
15373
|
/**
|
|
14499
15374
|
* Create a new Editor instance
|
|
@@ -14575,6 +15450,8 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
14575
15450
|
lastSelection: null,
|
|
14576
15451
|
suppressDefaultDocxStyles: false,
|
|
14577
15452
|
jsonOverride: null,
|
|
15453
|
+
layoutMode: "paginated",
|
|
15454
|
+
layoutMargins: null,
|
|
14578
15455
|
onBeforeCreate: () => null,
|
|
14579
15456
|
onCreate: () => null,
|
|
14580
15457
|
onUpdate: () => null,
|
|
@@ -14613,6 +15490,7 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
14613
15490
|
});
|
|
14614
15491
|
__privateMethod(this, _Editor_instances, initContainerElement_fn).call(this, options);
|
|
14615
15492
|
__privateMethod(this, _Editor_instances, checkHeadless_fn).call(this, options);
|
|
15493
|
+
__privateMethod(this, _Editor_instances, validateLayoutMargins_fn).call(this, options);
|
|
14616
15494
|
this.setOptions(options);
|
|
14617
15495
|
let modes = {
|
|
14618
15496
|
docx: () => __privateMethod(this, _Editor_instances, init_fn).call(this),
|
|
@@ -14991,17 +15869,28 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
14991
15869
|
});
|
|
14992
15870
|
}
|
|
14993
15871
|
/**
|
|
14994
|
-
* Get the maximum content size
|
|
14995
|
-
* @returns {
|
|
15872
|
+
* Get the maximum content size based on page dimensions and margins
|
|
15873
|
+
* @returns {{width: number, height: number} | {}} Size object with width and height in pixels, or empty object if no page size
|
|
14996
15874
|
*/
|
|
14997
15875
|
getMaxContentSize() {
|
|
14998
15876
|
if (!this.converter) return {};
|
|
14999
15877
|
const { pageSize = {}, pageMargins = {} } = this.converter.pageStyles ?? {};
|
|
15878
|
+
const { layoutMargins } = this.options;
|
|
15000
15879
|
const { width, height } = pageSize;
|
|
15001
|
-
const
|
|
15880
|
+
const isResponsive = __privateMethod(this, _Editor_instances, isResponsiveMode_fn).call(this);
|
|
15881
|
+
const getMarginPx = (side) => {
|
|
15882
|
+
if (isResponsive) {
|
|
15883
|
+
return layoutMargins?.[side] ?? PIXELS_PER_INCH;
|
|
15884
|
+
}
|
|
15885
|
+
return (pageMargins?.[side] ?? 0) * PIXELS_PER_INCH;
|
|
15886
|
+
};
|
|
15887
|
+
const topPx = getMarginPx("top");
|
|
15888
|
+
const bottomPx = getMarginPx("bottom");
|
|
15889
|
+
const leftPx = getMarginPx("left");
|
|
15890
|
+
const rightPx = getMarginPx("right");
|
|
15002
15891
|
if (!width || !height) return {};
|
|
15003
|
-
const maxHeight = height *
|
|
15004
|
-
const maxWidth = width *
|
|
15892
|
+
const maxHeight = height * PIXELS_PER_INCH - topPx - bottomPx - MAX_HEIGHT_BUFFER_PX;
|
|
15893
|
+
const maxWidth = width * PIXELS_PER_INCH - leftPx - rightPx - MAX_WIDTH_BUFFER_PX;
|
|
15005
15894
|
return {
|
|
15006
15895
|
width: maxWidth,
|
|
15007
15896
|
height: maxHeight
|
|
@@ -15009,9 +15898,15 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
15009
15898
|
}
|
|
15010
15899
|
/**
|
|
15011
15900
|
* Attach styles and attributes to the editor element
|
|
15901
|
+
* @param {HTMLElement} element - The editor container element
|
|
15902
|
+
* @param {HTMLElement} proseMirror - The ProseMirror element
|
|
15903
|
+
* @param {boolean} [hasPaginationEnabled=true] - Whether pagination is enabled
|
|
15904
|
+
* @returns {void}
|
|
15012
15905
|
*/
|
|
15013
15906
|
updateEditorStyles(element, proseMirror, hasPaginationEnabled = true) {
|
|
15014
15907
|
const { pageSize, pageMargins } = this.converter.pageStyles ?? {};
|
|
15908
|
+
const { layoutMargins, pagination } = this.options;
|
|
15909
|
+
const isResponsive = __privateMethod(this, _Editor_instances, isResponsiveMode_fn).call(this);
|
|
15015
15910
|
if (!proseMirror || !element) {
|
|
15016
15911
|
return;
|
|
15017
15912
|
}
|
|
@@ -15020,12 +15915,17 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
15020
15915
|
proseMirror.setAttribute("aria-label", "Main content area, start typing to enter text.");
|
|
15021
15916
|
proseMirror.setAttribute("aria-description", "");
|
|
15022
15917
|
proseMirror.classList.remove("view-mode");
|
|
15023
|
-
if (pageSize) {
|
|
15024
|
-
element.style.width = pageSize.width
|
|
15025
|
-
element.style.minWidth = pageSize.width
|
|
15026
|
-
element.style.minHeight = pageSize.height + "in";
|
|
15918
|
+
if (pageSize?.width != null) {
|
|
15919
|
+
element.style.width = isResponsive ? "100%" : `${pageSize.width}in`;
|
|
15920
|
+
element.style.minWidth = isResponsive ? "" : `${pageSize.width}in`;
|
|
15027
15921
|
}
|
|
15028
|
-
if (
|
|
15922
|
+
if (pageSize?.height != null) {
|
|
15923
|
+
element.style.minHeight = isResponsive ? "" : `${pageSize.height}in`;
|
|
15924
|
+
}
|
|
15925
|
+
if (isResponsive) {
|
|
15926
|
+
element.style.paddingLeft = (layoutMargins?.left ?? PIXELS_PER_INCH) + "px";
|
|
15927
|
+
element.style.paddingRight = (layoutMargins?.right ?? PIXELS_PER_INCH) + "px";
|
|
15928
|
+
} else if (pageMargins) {
|
|
15029
15929
|
element.style.paddingLeft = pageMargins.left + "in";
|
|
15030
15930
|
element.style.paddingRight = pageMargins.right + "in";
|
|
15031
15931
|
}
|
|
@@ -15048,7 +15948,10 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
15048
15948
|
element.style.webkitOverflowScrolling = "touch";
|
|
15049
15949
|
const defaultLineHeight = 1.2;
|
|
15050
15950
|
proseMirror.style.lineHeight = defaultLineHeight;
|
|
15051
|
-
if (
|
|
15951
|
+
if (isResponsive) {
|
|
15952
|
+
proseMirror.style.paddingTop = (layoutMargins?.top ?? PIXELS_PER_INCH) + "px";
|
|
15953
|
+
proseMirror.style.paddingBottom = (layoutMargins?.bottom ?? PIXELS_PER_INCH) + "px";
|
|
15954
|
+
} else if (!pagination) {
|
|
15052
15955
|
proseMirror.style.paddingTop = "1in";
|
|
15053
15956
|
proseMirror.style.paddingBottom = "1in";
|
|
15054
15957
|
} else {
|
|
@@ -15073,6 +15976,7 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
15073
15976
|
/**
|
|
15074
15977
|
* Initializes responsive styles for mobile devices.
|
|
15075
15978
|
* Sets up scaling based on viewport width and handles orientation changes.
|
|
15979
|
+
* Note: Scaling is skipped in responsive layout mode since content reflows naturally.
|
|
15076
15980
|
*
|
|
15077
15981
|
* @param {HTMLElement|void} element - The DOM element to apply mobile styles to
|
|
15078
15982
|
* @returns {void}
|
|
@@ -15081,6 +15985,9 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
15081
15985
|
if (!element) {
|
|
15082
15986
|
return;
|
|
15083
15987
|
}
|
|
15988
|
+
if (__privateMethod(this, _Editor_instances, isResponsiveMode_fn).call(this)) {
|
|
15989
|
+
return;
|
|
15990
|
+
}
|
|
15084
15991
|
const initialWidth = element.offsetWidth;
|
|
15085
15992
|
const updateScale = () => {
|
|
15086
15993
|
const minPageSideMargin = 10;
|
|
@@ -15229,7 +16136,7 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
15229
16136
|
{ default: remarkStringify },
|
|
15230
16137
|
{ default: remarkGfm }
|
|
15231
16138
|
] = await Promise.all([
|
|
15232
|
-
import("./index-
|
|
16139
|
+
import("./index-CzkLnJsZ.js"),
|
|
15233
16140
|
import("./index-DRCvimau.js"),
|
|
15234
16141
|
import("./index-C_x_N6Uh.js"),
|
|
15235
16142
|
import("./index-D_sWOSiG.js"),
|
|
@@ -15447,7 +16354,7 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
15447
16354
|
* @returns {Object | void} Migration results
|
|
15448
16355
|
*/
|
|
15449
16356
|
processCollaborationMigrations() {
|
|
15450
|
-
console.debug("[checkVersionMigrations] Current editor version", "0.
|
|
16357
|
+
console.debug("[checkVersionMigrations] Current editor version", "0.36.1");
|
|
15451
16358
|
if (!this.options.ydoc) return;
|
|
15452
16359
|
const metaMap = this.options.ydoc.getMap("meta");
|
|
15453
16360
|
let docVersion = metaMap.get("version");
|
|
@@ -15761,6 +16668,39 @@ checkHeadless_fn = function(options) {
|
|
|
15761
16668
|
global.window = options.mockWindow;
|
|
15762
16669
|
}
|
|
15763
16670
|
};
|
|
16671
|
+
/**
|
|
16672
|
+
* Validate layoutMargins option values
|
|
16673
|
+
* @param {EditorOptions} options - Editor options
|
|
16674
|
+
* @returns {void}
|
|
16675
|
+
*/
|
|
16676
|
+
validateLayoutMargins_fn = function(options) {
|
|
16677
|
+
if (!options.layoutMargins) return;
|
|
16678
|
+
const margins = options.layoutMargins;
|
|
16679
|
+
const validatedMargins = {};
|
|
16680
|
+
let hasValidValues = false;
|
|
16681
|
+
for (const key2 of ["top", "bottom", "left", "right"]) {
|
|
16682
|
+
if (margins[key2] !== void 0 && margins[key2] !== null) {
|
|
16683
|
+
const value = margins[key2];
|
|
16684
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
|
|
16685
|
+
validatedMargins[key2] = value;
|
|
16686
|
+
hasValidValues = true;
|
|
16687
|
+
} else {
|
|
16688
|
+
console.warn(
|
|
16689
|
+
`[SuperDoc] Invalid layoutMargins.${key2}: ${value}. Value must be a positive finite number. Ignoring this property.`
|
|
16690
|
+
);
|
|
16691
|
+
}
|
|
16692
|
+
}
|
|
16693
|
+
}
|
|
16694
|
+
options.layoutMargins = hasValidValues ? validatedMargins : null;
|
|
16695
|
+
};
|
|
16696
|
+
/**
|
|
16697
|
+
* Check if responsive layout mode is enabled
|
|
16698
|
+
* @returns {boolean} True if layoutMode is 'responsive'
|
|
16699
|
+
* @private
|
|
16700
|
+
*/
|
|
16701
|
+
isResponsiveMode_fn = function() {
|
|
16702
|
+
return this.options.layoutMode === "responsive";
|
|
16703
|
+
};
|
|
15764
16704
|
registerCopyHandler_fn = function() {
|
|
15765
16705
|
this.view.dom.addEventListener("copy", (event) => {
|
|
15766
16706
|
const clipboardData = event.clipboardData;
|
|
@@ -16043,6 +16983,9 @@ initPagination_fn = async function() {
|
|
|
16043
16983
|
if (this.options.isHeadless || !this.extensionService || this.options.isHeaderOrFooter) {
|
|
16044
16984
|
return;
|
|
16045
16985
|
}
|
|
16986
|
+
if (__privateMethod(this, _Editor_instances, isResponsiveMode_fn).call(this)) {
|
|
16987
|
+
return;
|
|
16988
|
+
}
|
|
16046
16989
|
const pagination = this.options.extensions.find((e) => e.name === "pagination");
|
|
16047
16990
|
if (pagination && this.options.pagination) {
|
|
16048
16991
|
const sectionData = await initPaginationData(this);
|
|
@@ -16766,12 +17709,12 @@ function dropCursor(options = {}) {
|
|
|
16766
17709
|
}
|
|
16767
17710
|
class DropCursorView {
|
|
16768
17711
|
constructor(editorView, options) {
|
|
16769
|
-
var
|
|
17712
|
+
var _a2;
|
|
16770
17713
|
this.editorView = editorView;
|
|
16771
17714
|
this.cursorPos = null;
|
|
16772
17715
|
this.element = null;
|
|
16773
17716
|
this.timeout = -1;
|
|
16774
|
-
this.width = (
|
|
17717
|
+
this.width = (_a2 = options.width) !== null && _a2 !== void 0 ? _a2 : 1;
|
|
16775
17718
|
this.color = options.color === false ? void 0 : options.color || "black";
|
|
16776
17719
|
this.class = options.class;
|
|
16777
17720
|
this.handlers = ["dragover", "dragend", "drop", "dragleave"].map((name) => {
|
|
@@ -18919,7 +19862,7 @@ const Document = Node$1.create({
|
|
|
18919
19862
|
*/
|
|
18920
19863
|
getDocumentStats: () => ({ editor }) => {
|
|
18921
19864
|
const text = editor.getText();
|
|
18922
|
-
const words = text.split(/\s+/).filter((
|
|
19865
|
+
const words = text.split(/\s+/).filter((word2) => word2.length > 0).length;
|
|
18923
19866
|
const characters = text.length;
|
|
18924
19867
|
const paragraphs = editor.state.doc.content.childCount;
|
|
18925
19868
|
return {
|
|
@@ -19326,9 +20269,9 @@ const ordinalFormatter = (level) => {
|
|
|
19326
20269
|
};
|
|
19327
20270
|
const generateFromCustom = (path, lvlText, customFormat) => {
|
|
19328
20271
|
if (customFormat !== "001, 002, 003, ...") return generateNumbering(path, lvlText, String);
|
|
19329
|
-
const
|
|
19330
|
-
if (!
|
|
19331
|
-
const sample =
|
|
20272
|
+
const match2 = customFormat.match(/(\d+)/);
|
|
20273
|
+
if (!match2) throw new Error("Invalid format string: no numeric pattern found");
|
|
20274
|
+
const sample = match2[1];
|
|
19332
20275
|
const digitCount = sample.length;
|
|
19333
20276
|
const index2 = path.pop();
|
|
19334
20277
|
return String(index2).padStart(digitCount, "0");
|
|
@@ -21697,9 +22640,9 @@ function calculateIndentFallback(indentAttrs = {}) {
|
|
|
21697
22640
|
} else if (hanging) {
|
|
21698
22641
|
textIndent = -hanging;
|
|
21699
22642
|
} else if (typeof indentAttrs.textIndent === "string") {
|
|
21700
|
-
const
|
|
21701
|
-
if (
|
|
21702
|
-
textIndent = Number(
|
|
22643
|
+
const match2 = indentAttrs.textIndent.match(/(-?\d*\.?\d+)in$/);
|
|
22644
|
+
if (match2) {
|
|
22645
|
+
textIndent = Number(match2[1]) * 96;
|
|
21703
22646
|
}
|
|
21704
22647
|
}
|
|
21705
22648
|
if (textIndent) return left2 + textIndent;
|
|
@@ -22057,7 +23000,7 @@ function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrid
|
|
|
22057
23000
|
const pageWidth = toNumber(pageStyles.pageSize.width);
|
|
22058
23001
|
const marginLeft = toNumber(pageStyles.pageMargins?.left);
|
|
22059
23002
|
const marginRight = toNumber(pageStyles.pageMargins?.right);
|
|
22060
|
-
const pageAvailableWidthPx = Math.max((pageWidth - marginLeft - marginRight) * PIXELS_PER_INCH, 0);
|
|
23003
|
+
const pageAvailableWidthPx = Math.max((pageWidth - marginLeft - marginRight) * PIXELS_PER_INCH$1, 0);
|
|
22061
23004
|
if (pageAvailableWidthPx > 0) {
|
|
22062
23005
|
availableWidth = availableWidth ? Math.min(availableWidth, pageAvailableWidthPx) : pageAvailableWidthPx;
|
|
22063
23006
|
}
|
|
@@ -22176,14 +23119,14 @@ const createCell = (cellType, cellContent = null) => {
|
|
|
22176
23119
|
}
|
|
22177
23120
|
return cellType.createAndFill();
|
|
22178
23121
|
};
|
|
22179
|
-
const createTableBorders = ({ size = 0.66665, color = "#000000" } = {}) => {
|
|
23122
|
+
const createTableBorders = ({ size: size2 = 0.66665, color = "#000000" } = {}) => {
|
|
22180
23123
|
return {
|
|
22181
|
-
top: { size, color },
|
|
22182
|
-
left: { size, color },
|
|
22183
|
-
bottom: { size, color },
|
|
22184
|
-
right: { size, color },
|
|
22185
|
-
insideH: { size, color },
|
|
22186
|
-
insideV: { size, color }
|
|
23124
|
+
top: { size: size2, color },
|
|
23125
|
+
left: { size: size2, color },
|
|
23126
|
+
bottom: { size: size2, color },
|
|
23127
|
+
right: { size: size2, color },
|
|
23128
|
+
insideH: { size: size2, color },
|
|
23129
|
+
insideV: { size: size2, color }
|
|
22187
23130
|
};
|
|
22188
23131
|
};
|
|
22189
23132
|
const createTable = (schema, rowsCount, colsCount, withHeaderRow, cellContent = null) => {
|
|
@@ -22281,8 +23224,8 @@ const createColGroup = (node, cellMinWidth, overrideCol, overrideValue) => {
|
|
|
22281
23224
|
colgroupValues
|
|
22282
23225
|
};
|
|
22283
23226
|
};
|
|
22284
|
-
|
|
22285
|
-
|
|
23227
|
+
let readFromCache;
|
|
23228
|
+
let addToCache;
|
|
22286
23229
|
if (typeof WeakMap != "undefined") {
|
|
22287
23230
|
let cache = /* @__PURE__ */ new WeakMap();
|
|
22288
23231
|
readFromCache = (key2) => cache.get(key2);
|
|
@@ -22295,8 +23238,7 @@ if (typeof WeakMap != "undefined") {
|
|
|
22295
23238
|
const cacheSize = 10;
|
|
22296
23239
|
let cachePos = 0;
|
|
22297
23240
|
readFromCache = (key2) => {
|
|
22298
|
-
for (let i = 0; i < cache.length; i += 2)
|
|
22299
|
-
if (cache[i] == key2) return cache[i + 1];
|
|
23241
|
+
for (let i = 0; i < cache.length; i += 2) if (cache[i] == key2) return cache[i + 1];
|
|
22300
23242
|
};
|
|
22301
23243
|
addToCache = (key2, value) => {
|
|
22302
23244
|
if (cachePos == cacheSize) cachePos = 0;
|
|
@@ -22311,7 +23253,6 @@ var TableMap = class {
|
|
|
22311
23253
|
this.map = map2;
|
|
22312
23254
|
this.problems = problems;
|
|
22313
23255
|
}
|
|
22314
|
-
// Find the dimensions of the cell at the given position.
|
|
22315
23256
|
findCell(pos) {
|
|
22316
23257
|
for (let i = 0; i < this.map.length; i++) {
|
|
22317
23258
|
const curPos = this.map[i];
|
|
@@ -22320,27 +23261,21 @@ var TableMap = class {
|
|
|
22320
23261
|
const top2 = i / this.width | 0;
|
|
22321
23262
|
let right2 = left2 + 1;
|
|
22322
23263
|
let bottom2 = top2 + 1;
|
|
22323
|
-
for (let j = 1; right2 < this.width && this.map[i + j] == curPos; j++)
|
|
22324
|
-
|
|
22325
|
-
|
|
22326
|
-
|
|
22327
|
-
|
|
22328
|
-
|
|
22329
|
-
|
|
23264
|
+
for (let j = 1; right2 < this.width && this.map[i + j] == curPos; j++) right2++;
|
|
23265
|
+
for (let j = 1; bottom2 < this.height && this.map[i + this.width * j] == curPos; j++) bottom2++;
|
|
23266
|
+
return {
|
|
23267
|
+
left: left2,
|
|
23268
|
+
top: top2,
|
|
23269
|
+
right: right2,
|
|
23270
|
+
bottom: bottom2
|
|
23271
|
+
};
|
|
22330
23272
|
}
|
|
22331
23273
|
throw new RangeError(`No cell with offset ${pos} found`);
|
|
22332
23274
|
}
|
|
22333
|
-
// Find the left side of the cell at the given position.
|
|
22334
23275
|
colCount(pos) {
|
|
22335
|
-
for (let i = 0; i < this.map.length; i++)
|
|
22336
|
-
if (this.map[i] == pos) {
|
|
22337
|
-
return i % this.width;
|
|
22338
|
-
}
|
|
22339
|
-
}
|
|
23276
|
+
for (let i = 0; i < this.map.length; i++) if (this.map[i] == pos) return i % this.width;
|
|
22340
23277
|
throw new RangeError(`No cell with offset ${pos} found`);
|
|
22341
23278
|
}
|
|
22342
|
-
// Find the next cell in the given direction, starting from the cell
|
|
22343
|
-
// at `pos`, if any.
|
|
22344
23279
|
nextCell(pos, axis, dir) {
|
|
22345
23280
|
const { left: left2, right: right2, top: top2, bottom: bottom2 } = this.findCell(pos);
|
|
22346
23281
|
if (axis == "horiz") {
|
|
@@ -22351,20 +23286,9 @@ var TableMap = class {
|
|
|
22351
23286
|
return this.map[left2 + this.width * (dir < 0 ? top2 - 1 : bottom2)];
|
|
22352
23287
|
}
|
|
22353
23288
|
}
|
|
22354
|
-
// Get the rectangle spanning the two given cells.
|
|
22355
23289
|
rectBetween(a, b) {
|
|
22356
|
-
const {
|
|
22357
|
-
|
|
22358
|
-
right: rightA,
|
|
22359
|
-
top: topA,
|
|
22360
|
-
bottom: bottomA
|
|
22361
|
-
} = this.findCell(a);
|
|
22362
|
-
const {
|
|
22363
|
-
left: leftB,
|
|
22364
|
-
right: rightB,
|
|
22365
|
-
top: topB,
|
|
22366
|
-
bottom: bottomB
|
|
22367
|
-
} = this.findCell(b);
|
|
23290
|
+
const { left: leftA, right: rightA, top: topA, bottom: bottomA } = this.findCell(a);
|
|
23291
|
+
const { left: leftB, right: rightB, top: topB, bottom: bottomB } = this.findCell(b);
|
|
22368
23292
|
return {
|
|
22369
23293
|
left: Math.min(leftA, leftB),
|
|
22370
23294
|
top: Math.min(topA, topB),
|
|
@@ -22372,27 +23296,19 @@ var TableMap = class {
|
|
|
22372
23296
|
bottom: Math.max(bottomA, bottomB)
|
|
22373
23297
|
};
|
|
22374
23298
|
}
|
|
22375
|
-
// Return the position of all cells that have the top left corner in
|
|
22376
|
-
// the given rectangle.
|
|
22377
23299
|
cellsInRect(rect) {
|
|
22378
23300
|
const result = [];
|
|
22379
23301
|
const seen = {};
|
|
22380
|
-
for (let row = rect.top; row < rect.bottom; row++) {
|
|
22381
|
-
|
|
22382
|
-
|
|
22383
|
-
|
|
22384
|
-
|
|
22385
|
-
|
|
22386
|
-
|
|
22387
|
-
continue;
|
|
22388
|
-
}
|
|
22389
|
-
result.push(pos);
|
|
22390
|
-
}
|
|
23302
|
+
for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {
|
|
23303
|
+
const index2 = row * this.width + col;
|
|
23304
|
+
const pos = this.map[index2];
|
|
23305
|
+
if (seen[pos]) continue;
|
|
23306
|
+
seen[pos] = true;
|
|
23307
|
+
if (col == rect.left && col && this.map[index2 - 1] == pos || row == rect.top && row && this.map[index2 - this.width] == pos) continue;
|
|
23308
|
+
result.push(pos);
|
|
22391
23309
|
}
|
|
22392
23310
|
return result;
|
|
22393
23311
|
}
|
|
22394
|
-
// Return the position at which the cell at the given row and column
|
|
22395
|
-
// starts, or would start, if a cell started there.
|
|
22396
23312
|
positionAt(row, col, table) {
|
|
22397
23313
|
for (let i = 0, rowStart = 0; ; i++) {
|
|
22398
23314
|
const rowEnd = rowStart + table.child(i).nodeSize;
|
|
@@ -22405,14 +23321,12 @@ var TableMap = class {
|
|
|
22405
23321
|
rowStart = rowEnd;
|
|
22406
23322
|
}
|
|
22407
23323
|
}
|
|
22408
|
-
// Find the table map for the given table node.
|
|
22409
23324
|
static get(table) {
|
|
22410
23325
|
return readFromCache(table) || addToCache(table, computeMap(table));
|
|
22411
23326
|
}
|
|
22412
23327
|
};
|
|
22413
23328
|
function computeMap(table) {
|
|
22414
|
-
if (table.type.spec.tableRole != "table")
|
|
22415
|
-
throw new RangeError("Not a table node: " + table.type.name);
|
|
23329
|
+
if (table.type.spec.tableRole != "table") throw new RangeError("Not a table node: " + table.type.name);
|
|
22416
23330
|
const width = findWidth(table), height = table.childCount;
|
|
22417
23331
|
const map2 = [];
|
|
22418
23332
|
let mapPos = 0;
|
|
@@ -22439,22 +23353,19 @@ function computeMap(table) {
|
|
|
22439
23353
|
const start2 = mapPos + h * width;
|
|
22440
23354
|
for (let w = 0; w < colspan; w++) {
|
|
22441
23355
|
if (map2[start2 + w] == 0) map2[start2 + w] = pos;
|
|
22442
|
-
else
|
|
22443
|
-
|
|
22444
|
-
|
|
22445
|
-
|
|
22446
|
-
|
|
22447
|
-
|
|
22448
|
-
});
|
|
23356
|
+
else (problems || (problems = [])).push({
|
|
23357
|
+
type: "collision",
|
|
23358
|
+
row,
|
|
23359
|
+
pos,
|
|
23360
|
+
n: colspan - w
|
|
23361
|
+
});
|
|
22449
23362
|
const colW = colwidth && colwidth[w];
|
|
22450
23363
|
if (colW) {
|
|
22451
23364
|
const widthIndex = (start2 + w) % width * 2, prev = colWidths[widthIndex];
|
|
22452
23365
|
if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
|
|
22453
23366
|
colWidths[widthIndex] = colW;
|
|
22454
23367
|
colWidths[widthIndex + 1] = 1;
|
|
22455
|
-
} else if (prev == colW)
|
|
22456
|
-
colWidths[widthIndex + 1]++;
|
|
22457
|
-
}
|
|
23368
|
+
} else if (prev == colW) colWidths[widthIndex + 1]++;
|
|
22458
23369
|
}
|
|
22459
23370
|
}
|
|
22460
23371
|
}
|
|
@@ -22464,16 +23375,17 @@ function computeMap(table) {
|
|
|
22464
23375
|
const expectedPos = (row + 1) * width;
|
|
22465
23376
|
let missing = 0;
|
|
22466
23377
|
while (mapPos < expectedPos) if (map2[mapPos++] == 0) missing++;
|
|
22467
|
-
if (missing)
|
|
22468
|
-
|
|
23378
|
+
if (missing) (problems || (problems = [])).push({
|
|
23379
|
+
type: "missing",
|
|
23380
|
+
row,
|
|
23381
|
+
n: missing
|
|
23382
|
+
});
|
|
22469
23383
|
pos++;
|
|
22470
23384
|
}
|
|
22471
|
-
if (width === 0 || height === 0)
|
|
22472
|
-
(problems || (problems = [])).push({ type: "zero_sized" });
|
|
23385
|
+
if (width === 0 || height === 0) (problems || (problems = [])).push({ type: "zero_sized" });
|
|
22473
23386
|
const tableMap = new TableMap(width, height, map2, problems);
|
|
22474
23387
|
let badWidths = false;
|
|
22475
|
-
for (let i = 0; !badWidths && i < colWidths.length; i += 2)
|
|
22476
|
-
if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
|
|
23388
|
+
for (let i = 0; !badWidths && i < colWidths.length; i += 2) if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
|
|
22477
23389
|
if (badWidths) findBadColWidths(tableMap, colWidths, table);
|
|
22478
23390
|
return tableMap;
|
|
22479
23391
|
}
|
|
@@ -22483,14 +23395,13 @@ function findWidth(table) {
|
|
|
22483
23395
|
for (let row = 0; row < table.childCount; row++) {
|
|
22484
23396
|
const rowNode = table.child(row);
|
|
22485
23397
|
let rowWidth = 0;
|
|
22486
|
-
if (hasRowSpan)
|
|
22487
|
-
|
|
22488
|
-
|
|
22489
|
-
|
|
22490
|
-
|
|
22491
|
-
if (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
|
|
22492
|
-
}
|
|
23398
|
+
if (hasRowSpan) for (let j = 0; j < row; j++) {
|
|
23399
|
+
const prevRow = table.child(j);
|
|
23400
|
+
for (let i = 0; i < prevRow.childCount; i++) {
|
|
23401
|
+
const cell = prevRow.child(i);
|
|
23402
|
+
if (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
|
|
22493
23403
|
}
|
|
23404
|
+
}
|
|
22494
23405
|
for (let i = 0; i < rowNode.childCount; i++) {
|
|
22495
23406
|
const cell = rowNode.child(i);
|
|
22496
23407
|
rowWidth += cell.attrs.colspan;
|
|
@@ -22509,23 +23420,18 @@ function findBadColWidths(map2, colWidths, table) {
|
|
|
22509
23420
|
if (seen[pos]) continue;
|
|
22510
23421
|
seen[pos] = true;
|
|
22511
23422
|
const node = table.nodeAt(pos);
|
|
22512
|
-
if (!node) {
|
|
22513
|
-
throw new RangeError(`No cell with offset ${pos} found`);
|
|
22514
|
-
}
|
|
23423
|
+
if (!node) throw new RangeError(`No cell with offset ${pos} found`);
|
|
22515
23424
|
let updated = null;
|
|
22516
23425
|
const attrs = node.attrs;
|
|
22517
23426
|
for (let j = 0; j < attrs.colspan; j++) {
|
|
22518
|
-
const
|
|
22519
|
-
|
|
22520
|
-
|
|
22521
|
-
|
|
22522
|
-
|
|
22523
|
-
|
|
22524
|
-
|
|
22525
|
-
|
|
22526
|
-
pos,
|
|
22527
|
-
colwidth: updated
|
|
22528
|
-
});
|
|
23427
|
+
const colWidth = colWidths[(i + j) % map2.width * 2];
|
|
23428
|
+
if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth)) (updated || (updated = freshColWidth(attrs)))[j] = colWidth;
|
|
23429
|
+
}
|
|
23430
|
+
if (updated) map2.problems.unshift({
|
|
23431
|
+
type: "colwidth mismatch",
|
|
23432
|
+
pos,
|
|
23433
|
+
colwidth: updated
|
|
23434
|
+
});
|
|
22529
23435
|
}
|
|
22530
23436
|
}
|
|
22531
23437
|
function freshColWidth(attrs) {
|
|
@@ -22545,11 +23451,9 @@ function tableNodeTypes(schema) {
|
|
|
22545
23451
|
}
|
|
22546
23452
|
return result;
|
|
22547
23453
|
}
|
|
22548
|
-
|
|
23454
|
+
const tableEditingKey = new PluginKey("selectingCells");
|
|
22549
23455
|
function cellAround$1($pos) {
|
|
22550
|
-
for (let d2 = $pos.depth - 1; d2 > 0; d2--)
|
|
22551
|
-
if ($pos.node(d2).type.spec.tableRole == "row")
|
|
22552
|
-
return $pos.node(0).resolve($pos.before(d2 + 1));
|
|
23456
|
+
for (let d2 = $pos.depth - 1; d2 > 0; d2--) if ($pos.node(d2).type.spec.tableRole == "row") return $pos.node(0).resolve($pos.before(d2 + 1));
|
|
22553
23457
|
return null;
|
|
22554
23458
|
}
|
|
22555
23459
|
function cellWrapping$1($pos) {
|
|
@@ -22561,21 +23465,15 @@ function cellWrapping$1($pos) {
|
|
|
22561
23465
|
}
|
|
22562
23466
|
function isInTable(state) {
|
|
22563
23467
|
const $head = state.selection.$head;
|
|
22564
|
-
for (let d2 = $head.depth; d2 > 0; d2--)
|
|
22565
|
-
if ($head.node(d2).type.spec.tableRole == "row") return true;
|
|
23468
|
+
for (let d2 = $head.depth; d2 > 0; d2--) if ($head.node(d2).type.spec.tableRole == "row") return true;
|
|
22566
23469
|
return false;
|
|
22567
23470
|
}
|
|
22568
23471
|
function selectionCell(state) {
|
|
22569
23472
|
const sel = state.selection;
|
|
22570
|
-
if ("$anchorCell" in sel && sel.$anchorCell)
|
|
22571
|
-
|
|
22572
|
-
} else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
|
|
22573
|
-
return sel.$anchor;
|
|
22574
|
-
}
|
|
23473
|
+
if ("$anchorCell" in sel && sel.$anchorCell) return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
|
|
23474
|
+
else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") return sel.$anchor;
|
|
22575
23475
|
const $cell = cellAround$1(sel.$head) || cellNear(sel.$head);
|
|
22576
|
-
if ($cell)
|
|
22577
|
-
return $cell;
|
|
22578
|
-
}
|
|
23476
|
+
if ($cell) return $cell;
|
|
22579
23477
|
throw new RangeError(`No cell found around position ${sel.head}`);
|
|
22580
23478
|
}
|
|
22581
23479
|
function cellNear($pos) {
|
|
@@ -22585,8 +23483,7 @@ function cellNear($pos) {
|
|
|
22585
23483
|
}
|
|
22586
23484
|
for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
|
|
22587
23485
|
const role = before.type.spec.tableRole;
|
|
22588
|
-
if (role == "cell" || role == "header_cell")
|
|
22589
|
-
return $pos.doc.resolve(pos - before.nodeSize);
|
|
23486
|
+
if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos - before.nodeSize);
|
|
22590
23487
|
}
|
|
22591
23488
|
}
|
|
22592
23489
|
function pointsAtCell($pos) {
|
|
@@ -22606,7 +23503,10 @@ function nextCell($pos, axis, dir) {
|
|
|
22606
23503
|
return moved == null ? null : $pos.node(0).resolve(tableStart + moved);
|
|
22607
23504
|
}
|
|
22608
23505
|
function removeColSpan(attrs, pos, n = 1) {
|
|
22609
|
-
const result = {
|
|
23506
|
+
const result = {
|
|
23507
|
+
...attrs,
|
|
23508
|
+
colspan: attrs.colspan - n
|
|
23509
|
+
};
|
|
22610
23510
|
if (result.colwidth) {
|
|
22611
23511
|
result.colwidth = result.colwidth.slice();
|
|
22612
23512
|
result.colwidth.splice(pos, n);
|
|
@@ -22615,7 +23515,10 @@ function removeColSpan(attrs, pos, n = 1) {
|
|
|
22615
23515
|
return result;
|
|
22616
23516
|
}
|
|
22617
23517
|
function addColSpan(attrs, pos, n = 1) {
|
|
22618
|
-
const result = {
|
|
23518
|
+
const result = {
|
|
23519
|
+
...attrs,
|
|
23520
|
+
colspan: attrs.colspan + n
|
|
23521
|
+
};
|
|
22619
23522
|
if (result.colwidth) {
|
|
22620
23523
|
result.colwidth = result.colwidth.slice();
|
|
22621
23524
|
for (let i = 0; i < n; i++) result.colwidth.splice(pos, 0, 0);
|
|
@@ -22624,37 +23527,23 @@ function addColSpan(attrs, pos, n = 1) {
|
|
|
22624
23527
|
}
|
|
22625
23528
|
function columnIsHeader(map2, table, col) {
|
|
22626
23529
|
const headerCell = tableNodeTypes(table.type.schema).header_cell;
|
|
22627
|
-
for (let row = 0; row < map2.height; row++)
|
|
22628
|
-
if (table.nodeAt(map2.map[col + row * map2.width]).type != headerCell)
|
|
22629
|
-
return false;
|
|
23530
|
+
for (let row = 0; row < map2.height; row++) if (table.nodeAt(map2.map[col + row * map2.width]).type != headerCell) return false;
|
|
22630
23531
|
return true;
|
|
22631
23532
|
}
|
|
22632
|
-
var CellSelection = class
|
|
22633
|
-
// A table selection is identified by its anchor and head cells. The
|
|
22634
|
-
// positions given to this constructor should point _before_ two
|
|
22635
|
-
// cells in the same table. They may be the same, to select a single
|
|
22636
|
-
// cell.
|
|
23533
|
+
var CellSelection = class CellSelection2 extends Selection {
|
|
22637
23534
|
constructor($anchorCell, $headCell = $anchorCell) {
|
|
22638
23535
|
const table = $anchorCell.node(-1);
|
|
22639
23536
|
const map2 = TableMap.get(table);
|
|
22640
23537
|
const tableStart = $anchorCell.start(-1);
|
|
22641
|
-
const rect = map2.rectBetween(
|
|
22642
|
-
$anchorCell.pos - tableStart,
|
|
22643
|
-
$headCell.pos - tableStart
|
|
22644
|
-
);
|
|
23538
|
+
const rect = map2.rectBetween($anchorCell.pos - tableStart, $headCell.pos - tableStart);
|
|
22645
23539
|
const doc2 = $anchorCell.node(0);
|
|
22646
23540
|
const cells = map2.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);
|
|
22647
23541
|
cells.unshift($headCell.pos - tableStart);
|
|
22648
23542
|
const ranges = cells.map((pos) => {
|
|
22649
23543
|
const cell = table.nodeAt(pos);
|
|
22650
|
-
if (!cell) {
|
|
22651
|
-
throw RangeError(`No cell with offset ${pos} found`);
|
|
22652
|
-
}
|
|
23544
|
+
if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
|
|
22653
23545
|
const from2 = tableStart + pos + 1;
|
|
22654
|
-
return new SelectionRange(
|
|
22655
|
-
doc2.resolve(from2),
|
|
22656
|
-
doc2.resolve(from2 + cell.content.size)
|
|
22657
|
-
);
|
|
23546
|
+
return new SelectionRange(doc2.resolve(from2), doc2.resolve(from2 + cell.content.size));
|
|
22658
23547
|
});
|
|
22659
23548
|
super(ranges[0].$from, ranges[0].$to, ranges);
|
|
22660
23549
|
this.$anchorCell = $anchorCell;
|
|
@@ -22665,24 +23554,17 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22665
23554
|
const $headCell = doc2.resolve(mapping.map(this.$headCell.pos));
|
|
22666
23555
|
if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
|
|
22667
23556
|
const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
|
|
22668
|
-
if (tableChanged && this.isRowSelection())
|
|
22669
|
-
|
|
22670
|
-
else
|
|
22671
|
-
return _CellSelection.colSelection($anchorCell, $headCell);
|
|
22672
|
-
else return new _CellSelection($anchorCell, $headCell);
|
|
23557
|
+
if (tableChanged && this.isRowSelection()) return CellSelection2.rowSelection($anchorCell, $headCell);
|
|
23558
|
+
else if (tableChanged && this.isColSelection()) return CellSelection2.colSelection($anchorCell, $headCell);
|
|
23559
|
+
else return new CellSelection2($anchorCell, $headCell);
|
|
22673
23560
|
}
|
|
22674
23561
|
return TextSelection.between($anchorCell, $headCell);
|
|
22675
23562
|
}
|
|
22676
|
-
// Returns a rectangular slice of table rows containing the selected
|
|
22677
|
-
// cells.
|
|
22678
23563
|
content() {
|
|
22679
23564
|
const table = this.$anchorCell.node(-1);
|
|
22680
23565
|
const map2 = TableMap.get(table);
|
|
22681
23566
|
const tableStart = this.$anchorCell.start(-1);
|
|
22682
|
-
const rect = map2.rectBetween(
|
|
22683
|
-
this.$anchorCell.pos - tableStart,
|
|
22684
|
-
this.$headCell.pos - tableStart
|
|
22685
|
-
);
|
|
23567
|
+
const rect = map2.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart);
|
|
22686
23568
|
const seen = {};
|
|
22687
23569
|
const rows = [];
|
|
22688
23570
|
for (let row = rect.top; row < rect.bottom; row++) {
|
|
@@ -22693,44 +23575,25 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22693
23575
|
seen[pos] = true;
|
|
22694
23576
|
const cellRect = map2.findCell(pos);
|
|
22695
23577
|
let cell = table.nodeAt(pos);
|
|
22696
|
-
if (!cell) {
|
|
22697
|
-
throw RangeError(`No cell with offset ${pos} found`);
|
|
22698
|
-
}
|
|
23578
|
+
if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
|
|
22699
23579
|
const extraLeft = rect.left - cellRect.left;
|
|
22700
23580
|
const extraRight = cellRect.right - rect.right;
|
|
22701
23581
|
if (extraLeft > 0 || extraRight > 0) {
|
|
22702
23582
|
let attrs = cell.attrs;
|
|
22703
|
-
if (extraLeft > 0)
|
|
22704
|
-
|
|
22705
|
-
}
|
|
22706
|
-
if (extraRight > 0) {
|
|
22707
|
-
attrs = removeColSpan(
|
|
22708
|
-
attrs,
|
|
22709
|
-
attrs.colspan - extraRight,
|
|
22710
|
-
extraRight
|
|
22711
|
-
);
|
|
22712
|
-
}
|
|
23583
|
+
if (extraLeft > 0) attrs = removeColSpan(attrs, 0, extraLeft);
|
|
23584
|
+
if (extraRight > 0) attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
|
|
22713
23585
|
if (cellRect.left < rect.left) {
|
|
22714
23586
|
cell = cell.type.createAndFill(attrs);
|
|
22715
|
-
if (!cell) {
|
|
22716
|
-
|
|
22717
|
-
`Could not create cell with attrs ${JSON.stringify(attrs)}`
|
|
22718
|
-
);
|
|
22719
|
-
}
|
|
22720
|
-
} else {
|
|
22721
|
-
cell = cell.type.create(attrs, cell.content);
|
|
22722
|
-
}
|
|
23587
|
+
if (!cell) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(attrs)}`);
|
|
23588
|
+
} else cell = cell.type.create(attrs, cell.content);
|
|
22723
23589
|
}
|
|
22724
23590
|
if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
|
|
22725
23591
|
const attrs = {
|
|
22726
23592
|
...cell.attrs,
|
|
22727
23593
|
rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
|
|
22728
23594
|
};
|
|
22729
|
-
if (cellRect.top < rect.top)
|
|
22730
|
-
|
|
22731
|
-
} else {
|
|
22732
|
-
cell = cell.type.create(attrs, cell.content);
|
|
22733
|
-
}
|
|
23595
|
+
if (cellRect.top < rect.top) cell = cell.type.createAndFill(attrs);
|
|
23596
|
+
else cell = cell.type.create(attrs, cell.content);
|
|
22734
23597
|
}
|
|
22735
23598
|
rowContent.push(cell);
|
|
22736
23599
|
}
|
|
@@ -22743,16 +23606,9 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22743
23606
|
const mapFrom = tr.steps.length, ranges = this.ranges;
|
|
22744
23607
|
for (let i = 0; i < ranges.length; i++) {
|
|
22745
23608
|
const { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
|
|
22746
|
-
tr.replace(
|
|
22747
|
-
mapping.map($from.pos),
|
|
22748
|
-
mapping.map($to.pos),
|
|
22749
|
-
i ? Slice.empty : content
|
|
22750
|
-
);
|
|
23609
|
+
tr.replace(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
|
|
22751
23610
|
}
|
|
22752
|
-
const sel = Selection.findFrom(
|
|
22753
|
-
tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)),
|
|
22754
|
-
-1
|
|
22755
|
-
);
|
|
23611
|
+
const sel = Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1);
|
|
22756
23612
|
if (sel) tr.setSelection(sel);
|
|
22757
23613
|
}
|
|
22758
23614
|
replaceWith(tr, node) {
|
|
@@ -22762,18 +23618,9 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22762
23618
|
const table = this.$anchorCell.node(-1);
|
|
22763
23619
|
const map2 = TableMap.get(table);
|
|
22764
23620
|
const tableStart = this.$anchorCell.start(-1);
|
|
22765
|
-
const cells = map2.cellsInRect(
|
|
22766
|
-
|
|
22767
|
-
this.$anchorCell.pos - tableStart,
|
|
22768
|
-
this.$headCell.pos - tableStart
|
|
22769
|
-
)
|
|
22770
|
-
);
|
|
22771
|
-
for (let i = 0; i < cells.length; i++) {
|
|
22772
|
-
f2(table.nodeAt(cells[i]), tableStart + cells[i]);
|
|
22773
|
-
}
|
|
23621
|
+
const cells = map2.cellsInRect(map2.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart));
|
|
23622
|
+
for (let i = 0; i < cells.length; i++) f2(table.nodeAt(cells[i]), tableStart + cells[i]);
|
|
22774
23623
|
}
|
|
22775
|
-
// True if this selection goes all the way from the top to the
|
|
22776
|
-
// bottom of the table.
|
|
22777
23624
|
isColSelection() {
|
|
22778
23625
|
const anchorTop = this.$anchorCell.index(-1);
|
|
22779
23626
|
const headTop = this.$headCell.index(-1);
|
|
@@ -22782,8 +23629,6 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22782
23629
|
const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
|
|
22783
23630
|
return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
|
|
22784
23631
|
}
|
|
22785
|
-
// Returns the smallest column selection that covers the given anchor
|
|
22786
|
-
// and head cell.
|
|
22787
23632
|
static colSelection($anchorCell, $headCell = $anchorCell) {
|
|
22788
23633
|
const table = $anchorCell.node(-1);
|
|
22789
23634
|
const map2 = TableMap.get(table);
|
|
@@ -22792,24 +23637,14 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22792
23637
|
const headRect = map2.findCell($headCell.pos - tableStart);
|
|
22793
23638
|
const doc2 = $anchorCell.node(0);
|
|
22794
23639
|
if (anchorRect.top <= headRect.top) {
|
|
22795
|
-
if (anchorRect.top > 0)
|
|
22796
|
-
|
|
22797
|
-
if (headRect.bottom < map2.height)
|
|
22798
|
-
$headCell = doc2.resolve(
|
|
22799
|
-
tableStart + map2.map[map2.width * (map2.height - 1) + headRect.right - 1]
|
|
22800
|
-
);
|
|
23640
|
+
if (anchorRect.top > 0) $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.left]);
|
|
23641
|
+
if (headRect.bottom < map2.height) $headCell = doc2.resolve(tableStart + map2.map[map2.width * (map2.height - 1) + headRect.right - 1]);
|
|
22801
23642
|
} else {
|
|
22802
|
-
if (headRect.top > 0)
|
|
22803
|
-
|
|
22804
|
-
if (anchorRect.bottom < map2.height)
|
|
22805
|
-
$anchorCell = doc2.resolve(
|
|
22806
|
-
tableStart + map2.map[map2.width * (map2.height - 1) + anchorRect.right - 1]
|
|
22807
|
-
);
|
|
23643
|
+
if (headRect.top > 0) $headCell = doc2.resolve(tableStart + map2.map[headRect.left]);
|
|
23644
|
+
if (anchorRect.bottom < map2.height) $anchorCell = doc2.resolve(tableStart + map2.map[map2.width * (map2.height - 1) + anchorRect.right - 1]);
|
|
22808
23645
|
}
|
|
22809
|
-
return new
|
|
23646
|
+
return new CellSelection2($anchorCell, $headCell);
|
|
22810
23647
|
}
|
|
22811
|
-
// True if this selection goes all the way from the left to the
|
|
22812
|
-
// right of the table.
|
|
22813
23648
|
isRowSelection() {
|
|
22814
23649
|
const table = this.$anchorCell.node(-1);
|
|
22815
23650
|
const map2 = TableMap.get(table);
|
|
@@ -22822,10 +23657,8 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22822
23657
|
return Math.max(anchorRight, headRight) == map2.width;
|
|
22823
23658
|
}
|
|
22824
23659
|
eq(other) {
|
|
22825
|
-
return other instanceof
|
|
23660
|
+
return other instanceof CellSelection2 && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
|
|
22826
23661
|
}
|
|
22827
|
-
// Returns the smallest row selection that covers the given anchor
|
|
22828
|
-
// and head cell.
|
|
22829
23662
|
static rowSelection($anchorCell, $headCell = $anchorCell) {
|
|
22830
23663
|
const table = $anchorCell.node(-1);
|
|
22831
23664
|
const map2 = TableMap.get(table);
|
|
@@ -22834,23 +23667,13 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22834
23667
|
const headRect = map2.findCell($headCell.pos - tableStart);
|
|
22835
23668
|
const doc2 = $anchorCell.node(0);
|
|
22836
23669
|
if (anchorRect.left <= headRect.left) {
|
|
22837
|
-
if (anchorRect.left > 0)
|
|
22838
|
-
|
|
22839
|
-
tableStart + map2.map[anchorRect.top * map2.width]
|
|
22840
|
-
);
|
|
22841
|
-
if (headRect.right < map2.width)
|
|
22842
|
-
$headCell = doc2.resolve(
|
|
22843
|
-
tableStart + map2.map[map2.width * (headRect.top + 1) - 1]
|
|
22844
|
-
);
|
|
23670
|
+
if (anchorRect.left > 0) $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.top * map2.width]);
|
|
23671
|
+
if (headRect.right < map2.width) $headCell = doc2.resolve(tableStart + map2.map[map2.width * (headRect.top + 1) - 1]);
|
|
22845
23672
|
} else {
|
|
22846
|
-
if (headRect.left > 0)
|
|
22847
|
-
|
|
22848
|
-
if (anchorRect.right < map2.width)
|
|
22849
|
-
$anchorCell = doc2.resolve(
|
|
22850
|
-
tableStart + map2.map[map2.width * (anchorRect.top + 1) - 1]
|
|
22851
|
-
);
|
|
23673
|
+
if (headRect.left > 0) $headCell = doc2.resolve(tableStart + map2.map[headRect.top * map2.width]);
|
|
23674
|
+
if (anchorRect.right < map2.width) $anchorCell = doc2.resolve(tableStart + map2.map[map2.width * (anchorRect.top + 1) - 1]);
|
|
22852
23675
|
}
|
|
22853
|
-
return new
|
|
23676
|
+
return new CellSelection2($anchorCell, $headCell);
|
|
22854
23677
|
}
|
|
22855
23678
|
toJSON() {
|
|
22856
23679
|
return {
|
|
@@ -22860,10 +23683,10 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22860
23683
|
};
|
|
22861
23684
|
}
|
|
22862
23685
|
static fromJSON(doc2, json) {
|
|
22863
|
-
return new
|
|
23686
|
+
return new CellSelection2(doc2.resolve(json.anchor), doc2.resolve(json.head));
|
|
22864
23687
|
}
|
|
22865
23688
|
static create(doc2, anchorCell, headCell = anchorCell) {
|
|
22866
|
-
return new
|
|
23689
|
+
return new CellSelection2(doc2.resolve(anchorCell), doc2.resolve(headCell));
|
|
22867
23690
|
}
|
|
22868
23691
|
getBookmark() {
|
|
22869
23692
|
return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
|
|
@@ -22871,18 +23694,17 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22871
23694
|
};
|
|
22872
23695
|
CellSelection.prototype.visible = false;
|
|
22873
23696
|
Selection.jsonID("cell", CellSelection);
|
|
22874
|
-
var CellBookmark = class
|
|
23697
|
+
var CellBookmark = class CellBookmark2 {
|
|
22875
23698
|
constructor(anchor, head) {
|
|
22876
23699
|
this.anchor = anchor;
|
|
22877
23700
|
this.head = head;
|
|
22878
23701
|
}
|
|
22879
23702
|
map(mapping) {
|
|
22880
|
-
return new
|
|
23703
|
+
return new CellBookmark2(mapping.map(this.anchor), mapping.map(this.head));
|
|
22881
23704
|
}
|
|
22882
23705
|
resolve(doc2) {
|
|
22883
23706
|
const $anchorCell = doc2.resolve(this.anchor), $headCell = doc2.resolve(this.head);
|
|
22884
|
-
if ($anchorCell.parent.type.spec.tableRole == "row" && $headCell.parent.type.spec.tableRole == "row" && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell))
|
|
22885
|
-
return new CellSelection($anchorCell, $headCell);
|
|
23707
|
+
if ($anchorCell.parent.type.spec.tableRole == "row" && $headCell.parent.type.spec.tableRole == "row" && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell)) return new CellSelection($anchorCell, $headCell);
|
|
22886
23708
|
else return Selection.near($headCell, 1);
|
|
22887
23709
|
}
|
|
22888
23710
|
};
|
|
@@ -22890,9 +23712,7 @@ function drawCellSelection(state) {
|
|
|
22890
23712
|
if (!(state.selection instanceof CellSelection)) return null;
|
|
22891
23713
|
const cells = [];
|
|
22892
23714
|
state.selection.forEachCell((node, pos) => {
|
|
22893
|
-
cells.push(
|
|
22894
|
-
Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" })
|
|
22895
|
-
);
|
|
23715
|
+
cells.push(Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" }));
|
|
22896
23716
|
});
|
|
22897
23717
|
return DecorationSet.create(state.doc, cells);
|
|
22898
23718
|
}
|
|
@@ -22901,10 +23721,8 @@ function isCellBoundarySelection({ $from, $to }) {
|
|
|
22901
23721
|
let afterFrom = $from.pos;
|
|
22902
23722
|
let beforeTo = $to.pos;
|
|
22903
23723
|
let depth = $from.depth;
|
|
22904
|
-
for (; depth >= 0; depth--, afterFrom++)
|
|
22905
|
-
|
|
22906
|
-
for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--)
|
|
22907
|
-
if ($to.before(d2 + 1) > $to.start(d2)) break;
|
|
23724
|
+
for (; depth >= 0; depth--, afterFrom++) if ($from.after(depth + 1) < $from.end(depth)) break;
|
|
23725
|
+
for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--) if ($to.before(d2 + 1) > $to.start(d2)) break;
|
|
22908
23726
|
return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
|
|
22909
23727
|
}
|
|
22910
23728
|
function isTextSelectionAcrossCells({ $from, $to }) {
|
|
@@ -22932,9 +23750,8 @@ function normalizeSelection(state, tr, allowTableNodeSelection) {
|
|
|
22932
23750
|
let normalize2;
|
|
22933
23751
|
let role;
|
|
22934
23752
|
if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
|
|
22935
|
-
if (role == "cell" || role == "header_cell")
|
|
22936
|
-
|
|
22937
|
-
} else if (role == "row") {
|
|
23753
|
+
if (role == "cell" || role == "header_cell") normalize2 = CellSelection.create(doc2, sel.from);
|
|
23754
|
+
else if (role == "row") {
|
|
22938
23755
|
const $cell = doc2.resolve(sel.from + 1);
|
|
22939
23756
|
normalize2 = CellSelection.rowSelection($cell, $cell);
|
|
22940
23757
|
} else if (!allowTableNodeSelection) {
|
|
@@ -22943,29 +23760,23 @@ function normalizeSelection(state, tr, allowTableNodeSelection) {
|
|
|
22943
23760
|
const lastCell = start2 + map2.map[map2.width * map2.height - 1];
|
|
22944
23761
|
normalize2 = CellSelection.create(doc2, start2 + 1, lastCell);
|
|
22945
23762
|
}
|
|
22946
|
-
} else if (sel instanceof TextSelection && isCellBoundarySelection(sel))
|
|
22947
|
-
|
|
22948
|
-
} else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {
|
|
22949
|
-
normalize2 = TextSelection.create(doc2, sel.$from.start(), sel.$from.end());
|
|
22950
|
-
}
|
|
23763
|
+
} else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) normalize2 = TextSelection.create(doc2, sel.from);
|
|
23764
|
+
else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) normalize2 = TextSelection.create(doc2, sel.$from.start(), sel.$from.end());
|
|
22951
23765
|
if (normalize2) (tr || (tr = state.tr)).setSelection(normalize2);
|
|
22952
23766
|
return tr;
|
|
22953
23767
|
}
|
|
22954
|
-
|
|
23768
|
+
const fixTablesKey = new PluginKey("fix-tables");
|
|
22955
23769
|
function changedDescendants(old, cur, offset2, f2) {
|
|
22956
23770
|
const oldSize = old.childCount, curSize = cur.childCount;
|
|
22957
23771
|
outer: for (let i = 0, j = 0; i < curSize; i++) {
|
|
22958
23772
|
const child = cur.child(i);
|
|
22959
|
-
for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {
|
|
22960
|
-
|
|
22961
|
-
|
|
22962
|
-
|
|
22963
|
-
continue outer;
|
|
22964
|
-
}
|
|
23773
|
+
for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) if (old.child(scan) == child) {
|
|
23774
|
+
j = scan + 1;
|
|
23775
|
+
offset2 += child.nodeSize;
|
|
23776
|
+
continue outer;
|
|
22965
23777
|
}
|
|
22966
23778
|
f2(child, offset2);
|
|
22967
|
-
if (j < oldSize && old.child(j).sameMarkup(child))
|
|
22968
|
-
changedDescendants(old.child(j), child, offset2 + 1, f2);
|
|
23779
|
+
if (j < oldSize && old.child(j).sameMarkup(child)) changedDescendants(old.child(j), child, offset2 + 1, f2);
|
|
22969
23780
|
else child.nodesBetween(0, child.content.size, f2, offset2 + 1);
|
|
22970
23781
|
offset2 += child.nodeSize;
|
|
22971
23782
|
}
|
|
@@ -22973,12 +23784,10 @@ function changedDescendants(old, cur, offset2, f2) {
|
|
|
22973
23784
|
function fixTables(state, oldState) {
|
|
22974
23785
|
let tr;
|
|
22975
23786
|
const check = (node, pos) => {
|
|
22976
|
-
if (node.type.spec.tableRole == "table")
|
|
22977
|
-
tr = fixTable(state, node, pos, tr);
|
|
23787
|
+
if (node.type.spec.tableRole == "table") tr = fixTable(state, node, pos, tr);
|
|
22978
23788
|
};
|
|
22979
23789
|
if (!oldState) state.doc.descendants(check);
|
|
22980
|
-
else if (oldState.doc != state.doc)
|
|
22981
|
-
changedDescendants(oldState.doc, state.doc, 0, check);
|
|
23790
|
+
else if (oldState.doc != state.doc) changedDescendants(oldState.doc, state.doc, 0, check);
|
|
22982
23791
|
return tr;
|
|
22983
23792
|
}
|
|
22984
23793
|
function fixTable(state, table, tablePos, tr) {
|
|
@@ -22994,14 +23803,9 @@ function fixTable(state, table, tablePos, tr) {
|
|
|
22994
23803
|
if (!cell) continue;
|
|
22995
23804
|
const attrs = cell.attrs;
|
|
22996
23805
|
for (let j = 0; j < attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n;
|
|
22997
|
-
tr.setNodeMarkup(
|
|
22998
|
-
|
|
22999
|
-
|
|
23000
|
-
removeColSpan(attrs, attrs.colspan - prob.n, prob.n)
|
|
23001
|
-
);
|
|
23002
|
-
} else if (prob.type == "missing") {
|
|
23003
|
-
mustAdd[prob.row] += prob.n;
|
|
23004
|
-
} else if (prob.type == "overlong_rowspan") {
|
|
23806
|
+
tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, removeColSpan(attrs, attrs.colspan - prob.n, prob.n));
|
|
23807
|
+
} else if (prob.type == "missing") mustAdd[prob.row] += prob.n;
|
|
23808
|
+
else if (prob.type == "overlong_rowspan") {
|
|
23005
23809
|
const cell = table.nodeAt(prob.pos);
|
|
23006
23810
|
if (!cell) continue;
|
|
23007
23811
|
tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
|
|
@@ -23021,20 +23825,17 @@ function fixTable(state, table, tablePos, tr) {
|
|
|
23021
23825
|
}
|
|
23022
23826
|
}
|
|
23023
23827
|
let first2, last;
|
|
23024
|
-
for (let i = 0; i < mustAdd.length; i++)
|
|
23025
|
-
if (
|
|
23026
|
-
|
|
23027
|
-
|
|
23028
|
-
}
|
|
23828
|
+
for (let i = 0; i < mustAdd.length; i++) if (mustAdd[i]) {
|
|
23829
|
+
if (first2 == null) first2 = i;
|
|
23830
|
+
last = i;
|
|
23831
|
+
}
|
|
23029
23832
|
for (let i = 0, pos = tablePos + 1; i < map2.height; i++) {
|
|
23030
23833
|
const row = table.child(i);
|
|
23031
23834
|
const end2 = pos + row.nodeSize;
|
|
23032
23835
|
const add = mustAdd[i];
|
|
23033
23836
|
if (add > 0) {
|
|
23034
23837
|
let role = "cell";
|
|
23035
|
-
if (row.firstChild)
|
|
23036
|
-
role = row.firstChild.type.spec.tableRole;
|
|
23037
|
-
}
|
|
23838
|
+
if (row.firstChild) role = row.firstChild.type.spec.tableRole;
|
|
23038
23839
|
const nodes = [];
|
|
23039
23840
|
for (let j = 0; j < add; j++) {
|
|
23040
23841
|
const node = tableNodeTypes(state.schema)[role].createAndFill();
|
|
@@ -23053,27 +23854,22 @@ function selectedRect(state) {
|
|
|
23053
23854
|
const table = $pos.node(-1);
|
|
23054
23855
|
const tableStart = $pos.start(-1);
|
|
23055
23856
|
const map2 = TableMap.get(table);
|
|
23056
|
-
|
|
23057
|
-
sel.$anchorCell.pos - tableStart,
|
|
23058
|
-
|
|
23059
|
-
|
|
23060
|
-
|
|
23857
|
+
return {
|
|
23858
|
+
...sel instanceof CellSelection ? map2.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart) : map2.findCell($pos.pos - tableStart),
|
|
23859
|
+
tableStart,
|
|
23860
|
+
map: map2,
|
|
23861
|
+
table
|
|
23862
|
+
};
|
|
23061
23863
|
}
|
|
23062
23864
|
function addColumn(tr, { map: map2, tableStart, table }, col) {
|
|
23063
23865
|
let refColumn = col > 0 ? -1 : 0;
|
|
23064
|
-
if (columnIsHeader(map2, table, col + refColumn))
|
|
23065
|
-
refColumn = col == 0 || col == map2.width ? null : 0;
|
|
23066
|
-
}
|
|
23866
|
+
if (columnIsHeader(map2, table, col + refColumn)) refColumn = col == 0 || col == map2.width ? null : 0;
|
|
23067
23867
|
for (let row = 0; row < map2.height; row++) {
|
|
23068
23868
|
const index2 = row * map2.width + col;
|
|
23069
23869
|
if (col > 0 && col < map2.width && map2.map[index2 - 1] == map2.map[index2]) {
|
|
23070
23870
|
const pos = map2.map[index2];
|
|
23071
23871
|
const cell = table.nodeAt(pos);
|
|
23072
|
-
tr.setNodeMarkup(
|
|
23073
|
-
tr.mapping.map(tableStart + pos),
|
|
23074
|
-
null,
|
|
23075
|
-
addColSpan(cell.attrs, col - map2.colCount(pos))
|
|
23076
|
-
);
|
|
23872
|
+
tr.setNodeMarkup(tr.mapping.map(tableStart + pos), null, addColSpan(cell.attrs, col - map2.colCount(pos)));
|
|
23077
23873
|
row += cell.attrs.rowspan - 1;
|
|
23078
23874
|
} else {
|
|
23079
23875
|
const type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map2.map[index2 + refColumn]).type;
|
|
@@ -23106,13 +23902,8 @@ function removeColumn(tr, { map: map2, table, tableStart }, col) {
|
|
|
23106
23902
|
const pos = map2.map[index2];
|
|
23107
23903
|
const cell = table.nodeAt(pos);
|
|
23108
23904
|
const attrs = cell.attrs;
|
|
23109
|
-
if (col > 0 && map2.map[index2 - 1] == pos || col < map2.width - 1 && map2.map[index2 + 1] == pos)
|
|
23110
|
-
|
|
23111
|
-
tr.mapping.slice(mapStart).map(tableStart + pos),
|
|
23112
|
-
null,
|
|
23113
|
-
removeColSpan(attrs, col - map2.colCount(pos))
|
|
23114
|
-
);
|
|
23115
|
-
} else {
|
|
23905
|
+
if (col > 0 && map2.map[index2 - 1] == pos || col < map2.width - 1 && map2.map[index2 + 1] == pos) tr.setNodeMarkup(tr.mapping.slice(mapStart).map(tableStart + pos), null, removeColSpan(attrs, col - map2.colCount(pos)));
|
|
23906
|
+
else {
|
|
23116
23907
|
const start2 = tr.mapping.slice(mapStart).map(tableStart + pos);
|
|
23117
23908
|
tr.delete(start2, start2 + cell.nodeSize);
|
|
23118
23909
|
}
|
|
@@ -23129,9 +23920,7 @@ function deleteColumn(state, dispatch) {
|
|
|
23129
23920
|
removeColumn(tr, rect, i);
|
|
23130
23921
|
if (i == rect.left) break;
|
|
23131
23922
|
const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
|
|
23132
|
-
if (!table)
|
|
23133
|
-
throw RangeError("No table found");
|
|
23134
|
-
}
|
|
23923
|
+
if (!table) throw new RangeError("No table found");
|
|
23135
23924
|
rect.table = table;
|
|
23136
23925
|
rect.map = TableMap.get(table);
|
|
23137
23926
|
}
|
|
@@ -23140,35 +23929,30 @@ function deleteColumn(state, dispatch) {
|
|
|
23140
23929
|
return true;
|
|
23141
23930
|
}
|
|
23142
23931
|
function rowIsHeader(map2, table, row) {
|
|
23143
|
-
var
|
|
23932
|
+
var _table$nodeAt;
|
|
23144
23933
|
const headerCell = tableNodeTypes(table.type.schema).header_cell;
|
|
23145
|
-
for (let col = 0; col < map2.width; col++)
|
|
23146
|
-
if (((_a = table.nodeAt(map2.map[col + row * map2.width])) == null ? void 0 : _a.type) != headerCell)
|
|
23147
|
-
return false;
|
|
23934
|
+
for (let col = 0; col < map2.width; col++) if (((_table$nodeAt = table.nodeAt(map2.map[col + row * map2.width])) === null || _table$nodeAt === void 0 ? void 0 : _table$nodeAt.type) != headerCell) return false;
|
|
23148
23935
|
return true;
|
|
23149
23936
|
}
|
|
23150
23937
|
function addRow(tr, { map: map2, tableStart, table }, row) {
|
|
23151
|
-
var _a;
|
|
23152
23938
|
let rowPos = tableStart;
|
|
23153
23939
|
for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;
|
|
23154
23940
|
const cells = [];
|
|
23155
23941
|
let refRow = row > 0 ? -1 : 0;
|
|
23156
|
-
if (rowIsHeader(map2, table, row + refRow))
|
|
23157
|
-
|
|
23158
|
-
|
|
23159
|
-
|
|
23160
|
-
|
|
23161
|
-
|
|
23162
|
-
|
|
23163
|
-
|
|
23164
|
-
|
|
23165
|
-
|
|
23166
|
-
|
|
23167
|
-
|
|
23168
|
-
|
|
23169
|
-
|
|
23170
|
-
if (node) cells.push(node);
|
|
23171
|
-
}
|
|
23942
|
+
if (rowIsHeader(map2, table, row + refRow)) refRow = row == 0 || row == map2.height ? null : 0;
|
|
23943
|
+
for (let col = 0, index2 = map2.width * row; col < map2.width; col++, index2++) if (row > 0 && row < map2.height && map2.map[index2] == map2.map[index2 - map2.width]) {
|
|
23944
|
+
const pos = map2.map[index2];
|
|
23945
|
+
const attrs = table.nodeAt(pos).attrs;
|
|
23946
|
+
tr.setNodeMarkup(tableStart + pos, null, {
|
|
23947
|
+
...attrs,
|
|
23948
|
+
rowspan: attrs.rowspan + 1
|
|
23949
|
+
});
|
|
23950
|
+
col += attrs.colspan - 1;
|
|
23951
|
+
} else {
|
|
23952
|
+
var _table$nodeAt2;
|
|
23953
|
+
const type = refRow == null ? tableNodeTypes(table.type.schema).cell : (_table$nodeAt2 = table.nodeAt(map2.map[index2 + refRow * map2.width])) === null || _table$nodeAt2 === void 0 ? void 0 : _table$nodeAt2.type;
|
|
23954
|
+
const node = type === null || type === void 0 ? void 0 : type.createAndFill();
|
|
23955
|
+
if (node) cells.push(node);
|
|
23172
23956
|
}
|
|
23173
23957
|
tr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells));
|
|
23174
23958
|
return tr;
|
|
@@ -23210,10 +23994,10 @@ function removeRow(tr, { map: map2, table, tableStart }, row) {
|
|
|
23210
23994
|
} else if (row < map2.height && pos == map2.map[index2 + map2.width]) {
|
|
23211
23995
|
const cell = table.nodeAt(pos);
|
|
23212
23996
|
const attrs = cell.attrs;
|
|
23213
|
-
const copy = cell.type.create(
|
|
23214
|
-
|
|
23215
|
-
cell.
|
|
23216
|
-
);
|
|
23997
|
+
const copy = cell.type.create({
|
|
23998
|
+
...attrs,
|
|
23999
|
+
rowspan: cell.attrs.rowspan - 1
|
|
24000
|
+
}, cell.content);
|
|
23217
24001
|
const newPos = map2.positionAt(row + 1, col, table);
|
|
23218
24002
|
tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy);
|
|
23219
24003
|
col += attrs.colspan - 1;
|
|
@@ -23229,9 +24013,7 @@ function deleteRow(state, dispatch) {
|
|
|
23229
24013
|
removeRow(tr, rect, i);
|
|
23230
24014
|
if (i == rect.top) break;
|
|
23231
24015
|
const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
|
|
23232
|
-
if (!table)
|
|
23233
|
-
throw RangeError("No table found");
|
|
23234
|
-
}
|
|
24016
|
+
if (!table) throw new RangeError("No table found");
|
|
23235
24017
|
rect.table = table;
|
|
23236
24018
|
rect.map = TableMap.get(rect.table);
|
|
23237
24019
|
}
|
|
@@ -23247,14 +24029,12 @@ function cellsOverlapRectangle({ width, height, map: map2 }, rect) {
|
|
|
23247
24029
|
let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
|
|
23248
24030
|
let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
|
|
23249
24031
|
for (let i = rect.top; i < rect.bottom; i++) {
|
|
23250
|
-
if (rect.left > 0 && map2[indexLeft] == map2[indexLeft - 1] || rect.right < width && map2[indexRight] == map2[indexRight + 1])
|
|
23251
|
-
return true;
|
|
24032
|
+
if (rect.left > 0 && map2[indexLeft] == map2[indexLeft - 1] || rect.right < width && map2[indexRight] == map2[indexRight + 1]) return true;
|
|
23252
24033
|
indexLeft += width;
|
|
23253
24034
|
indexRight += width;
|
|
23254
24035
|
}
|
|
23255
24036
|
for (let i = rect.left; i < rect.right; i++) {
|
|
23256
|
-
if (rect.top > 0 && map2[indexTop] == map2[indexTop - width] || rect.bottom < height && map2[indexBottom] == map2[indexBottom + width])
|
|
23257
|
-
return true;
|
|
24037
|
+
if (rect.top > 0 && map2[indexTop] == map2[indexTop - width] || rect.bottom < height && map2[indexBottom] == map2[indexBottom + width]) return true;
|
|
23258
24038
|
indexTop++;
|
|
23259
24039
|
indexBottom++;
|
|
23260
24040
|
}
|
|
@@ -23262,8 +24042,7 @@ function cellsOverlapRectangle({ width, height, map: map2 }, rect) {
|
|
|
23262
24042
|
}
|
|
23263
24043
|
function mergeCells(state, dispatch) {
|
|
23264
24044
|
const sel = state.selection;
|
|
23265
|
-
if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos)
|
|
23266
|
-
return false;
|
|
24045
|
+
if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos) return false;
|
|
23267
24046
|
const rect = selectedRect(state), { map: map2 } = rect;
|
|
23268
24047
|
if (cellsOverlapRectangle(map2, rect)) return false;
|
|
23269
24048
|
if (dispatch) {
|
|
@@ -23272,41 +24051,31 @@ function mergeCells(state, dispatch) {
|
|
|
23272
24051
|
let content = Fragment.empty;
|
|
23273
24052
|
let mergedPos;
|
|
23274
24053
|
let mergedCell;
|
|
23275
|
-
for (let row = rect.top; row < rect.bottom; row++) {
|
|
23276
|
-
|
|
23277
|
-
|
|
23278
|
-
|
|
23279
|
-
|
|
23280
|
-
|
|
23281
|
-
|
|
23282
|
-
|
|
23283
|
-
|
|
23284
|
-
|
|
23285
|
-
|
|
23286
|
-
|
|
23287
|
-
tr.delete(mapped, mapped + cell.nodeSize);
|
|
23288
|
-
}
|
|
24054
|
+
for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {
|
|
24055
|
+
const cellPos = map2.map[row * map2.width + col];
|
|
24056
|
+
const cell = rect.table.nodeAt(cellPos);
|
|
24057
|
+
if (seen[cellPos] || !cell) continue;
|
|
24058
|
+
seen[cellPos] = true;
|
|
24059
|
+
if (mergedPos == null) {
|
|
24060
|
+
mergedPos = cellPos;
|
|
24061
|
+
mergedCell = cell;
|
|
24062
|
+
} else {
|
|
24063
|
+
if (!isEmpty(cell)) content = content.append(cell.content);
|
|
24064
|
+
const mapped = tr.mapping.map(cellPos + rect.tableStart);
|
|
24065
|
+
tr.delete(mapped, mapped + cell.nodeSize);
|
|
23289
24066
|
}
|
|
23290
24067
|
}
|
|
23291
|
-
if (mergedPos == null || mergedCell == null)
|
|
23292
|
-
return true;
|
|
23293
|
-
}
|
|
24068
|
+
if (mergedPos == null || mergedCell == null) return true;
|
|
23294
24069
|
tr.setNodeMarkup(mergedPos + rect.tableStart, null, {
|
|
23295
|
-
...addColSpan(
|
|
23296
|
-
mergedCell.attrs,
|
|
23297
|
-
mergedCell.attrs.colspan,
|
|
23298
|
-
rect.right - rect.left - mergedCell.attrs.colspan
|
|
23299
|
-
),
|
|
24070
|
+
...addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan),
|
|
23300
24071
|
rowspan: rect.bottom - rect.top
|
|
23301
24072
|
});
|
|
23302
|
-
if (content.size) {
|
|
24073
|
+
if (content.size > 0) {
|
|
23303
24074
|
const end2 = mergedPos + 1 + mergedCell.content.size;
|
|
23304
24075
|
const start2 = isEmpty(mergedCell) ? mergedPos + 1 : end2;
|
|
23305
24076
|
tr.replaceWith(start2 + rect.tableStart, end2 + rect.tableStart, content);
|
|
23306
24077
|
}
|
|
23307
|
-
tr.setSelection(
|
|
23308
|
-
new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart))
|
|
23309
|
-
);
|
|
24078
|
+
tr.setSelection(new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));
|
|
23310
24079
|
dispatch(tr);
|
|
23311
24080
|
}
|
|
23312
24081
|
return true;
|
|
@@ -23319,63 +24088,57 @@ function splitCell(state, dispatch) {
|
|
|
23319
24088
|
}
|
|
23320
24089
|
function splitCellWithType(getCellType2) {
|
|
23321
24090
|
return (state, dispatch) => {
|
|
23322
|
-
var _a;
|
|
23323
24091
|
const sel = state.selection;
|
|
23324
24092
|
let cellNode;
|
|
23325
24093
|
let cellPos;
|
|
23326
24094
|
if (!(sel instanceof CellSelection)) {
|
|
24095
|
+
var _cellAround;
|
|
23327
24096
|
cellNode = cellWrapping$1(sel.$from);
|
|
23328
24097
|
if (!cellNode) return false;
|
|
23329
|
-
cellPos = (
|
|
24098
|
+
cellPos = (_cellAround = cellAround$1(sel.$from)) === null || _cellAround === void 0 ? void 0 : _cellAround.pos;
|
|
23330
24099
|
} else {
|
|
23331
24100
|
if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
|
|
23332
24101
|
cellNode = sel.$anchorCell.nodeAfter;
|
|
23333
24102
|
cellPos = sel.$anchorCell.pos;
|
|
23334
24103
|
}
|
|
23335
|
-
if (cellNode == null || cellPos == null)
|
|
23336
|
-
|
|
23337
|
-
}
|
|
23338
|
-
if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {
|
|
23339
|
-
return false;
|
|
23340
|
-
}
|
|
24104
|
+
if (cellNode == null || cellPos == null) return false;
|
|
24105
|
+
if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) return false;
|
|
23341
24106
|
if (dispatch) {
|
|
23342
24107
|
let baseAttrs = cellNode.attrs;
|
|
23343
24108
|
const attrs = [];
|
|
23344
24109
|
const colwidth = baseAttrs.colwidth;
|
|
23345
|
-
if (baseAttrs.rowspan > 1) baseAttrs = {
|
|
23346
|
-
|
|
24110
|
+
if (baseAttrs.rowspan > 1) baseAttrs = {
|
|
24111
|
+
...baseAttrs,
|
|
24112
|
+
rowspan: 1
|
|
24113
|
+
};
|
|
24114
|
+
if (baseAttrs.colspan > 1) baseAttrs = {
|
|
24115
|
+
...baseAttrs,
|
|
24116
|
+
colspan: 1
|
|
24117
|
+
};
|
|
23347
24118
|
const rect = selectedRect(state), tr = state.tr;
|
|
23348
|
-
for (let i = 0; i < rect.right - rect.left; i++)
|
|
23349
|
-
|
|
23350
|
-
|
|
23351
|
-
|
|
23352
|
-
colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
|
|
23353
|
-
} : baseAttrs
|
|
23354
|
-
);
|
|
24119
|
+
for (let i = 0; i < rect.right - rect.left; i++) attrs.push(colwidth ? {
|
|
24120
|
+
...baseAttrs,
|
|
24121
|
+
colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
|
|
24122
|
+
} : baseAttrs);
|
|
23355
24123
|
let lastCell;
|
|
23356
24124
|
for (let row = rect.top; row < rect.bottom; row++) {
|
|
23357
24125
|
let pos = rect.map.positionAt(row, rect.left, rect.table);
|
|
23358
24126
|
if (row == rect.top) pos += cellNode.nodeSize;
|
|
23359
24127
|
for (let col = rect.left, i = 0; col < rect.right; col++, i++) {
|
|
23360
24128
|
if (col == rect.left && row == rect.top) continue;
|
|
23361
|
-
tr.insert(
|
|
23362
|
-
|
|
23363
|
-
|
|
23364
|
-
|
|
23365
|
-
|
|
23366
|
-
|
|
23367
|
-
|
|
23368
|
-
|
|
23369
|
-
|
|
23370
|
-
|
|
23371
|
-
|
|
23372
|
-
|
|
23373
|
-
|
|
23374
|
-
new CellSelection(
|
|
23375
|
-
tr.doc.resolve(sel.$anchorCell.pos),
|
|
23376
|
-
lastCell ? tr.doc.resolve(lastCell) : void 0
|
|
23377
|
-
)
|
|
23378
|
-
);
|
|
24129
|
+
tr.insert(lastCell = tr.mapping.map(pos + rect.tableStart, 1), getCellType2({
|
|
24130
|
+
node: cellNode,
|
|
24131
|
+
row,
|
|
24132
|
+
col
|
|
24133
|
+
}).createAndFill(attrs[i]));
|
|
24134
|
+
}
|
|
24135
|
+
}
|
|
24136
|
+
tr.setNodeMarkup(cellPos, getCellType2({
|
|
24137
|
+
node: cellNode,
|
|
24138
|
+
row: rect.top,
|
|
24139
|
+
col: rect.left
|
|
24140
|
+
}), attrs[0]);
|
|
24141
|
+
if (sel instanceof CellSelection) tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), lastCell ? tr.doc.resolve(lastCell) : void 0));
|
|
23379
24142
|
dispatch(tr);
|
|
23380
24143
|
}
|
|
23381
24144
|
return true;
|
|
@@ -23388,19 +24151,16 @@ function setCellAttr(name, value) {
|
|
|
23388
24151
|
if ($cell.nodeAfter.attrs[name] === value) return false;
|
|
23389
24152
|
if (dispatch) {
|
|
23390
24153
|
const tr = state.tr;
|
|
23391
|
-
if (state.selection instanceof CellSelection)
|
|
23392
|
-
|
|
23393
|
-
|
|
23394
|
-
tr.setNodeMarkup(pos, null, {
|
|
23395
|
-
...node.attrs,
|
|
23396
|
-
[name]: value
|
|
23397
|
-
});
|
|
23398
|
-
});
|
|
23399
|
-
else
|
|
23400
|
-
tr.setNodeMarkup($cell.pos, null, {
|
|
23401
|
-
...$cell.nodeAfter.attrs,
|
|
24154
|
+
if (state.selection instanceof CellSelection) state.selection.forEachCell((node, pos) => {
|
|
24155
|
+
if (node.attrs[name] !== value) tr.setNodeMarkup(pos, null, {
|
|
24156
|
+
...node.attrs,
|
|
23402
24157
|
[name]: value
|
|
23403
24158
|
});
|
|
24159
|
+
});
|
|
24160
|
+
else tr.setNodeMarkup($cell.pos, null, {
|
|
24161
|
+
...$cell.nodeAfter.attrs,
|
|
24162
|
+
[name]: value
|
|
24163
|
+
});
|
|
23404
24164
|
dispatch(tr);
|
|
23405
24165
|
}
|
|
23406
24166
|
return true;
|
|
@@ -23412,34 +24172,20 @@ function deprecated_toggleHeader(type) {
|
|
|
23412
24172
|
if (dispatch) {
|
|
23413
24173
|
const types = tableNodeTypes(state.schema);
|
|
23414
24174
|
const rect = selectedRect(state), tr = state.tr;
|
|
23415
|
-
const cells = rect.map.cellsInRect(
|
|
23416
|
-
|
|
23417
|
-
|
|
23418
|
-
|
|
23419
|
-
|
|
23420
|
-
|
|
23421
|
-
|
|
23422
|
-
|
|
23423
|
-
|
|
23424
|
-
|
|
23425
|
-
|
|
23426
|
-
} : rect
|
|
23427
|
-
);
|
|
24175
|
+
const cells = rect.map.cellsInRect(type == "column" ? {
|
|
24176
|
+
left: rect.left,
|
|
24177
|
+
top: 0,
|
|
24178
|
+
right: rect.right,
|
|
24179
|
+
bottom: rect.map.height
|
|
24180
|
+
} : type == "row" ? {
|
|
24181
|
+
left: 0,
|
|
24182
|
+
top: rect.top,
|
|
24183
|
+
right: rect.map.width,
|
|
24184
|
+
bottom: rect.bottom
|
|
24185
|
+
} : rect);
|
|
23428
24186
|
const nodes = cells.map((pos) => rect.table.nodeAt(pos));
|
|
23429
|
-
for (let i = 0; i < cells.length; i++)
|
|
23430
|
-
|
|
23431
|
-
tr.setNodeMarkup(
|
|
23432
|
-
rect.tableStart + cells[i],
|
|
23433
|
-
types.cell,
|
|
23434
|
-
nodes[i].attrs
|
|
23435
|
-
);
|
|
23436
|
-
if (tr.steps.length == 0)
|
|
23437
|
-
for (let i = 0; i < cells.length; i++)
|
|
23438
|
-
tr.setNodeMarkup(
|
|
23439
|
-
rect.tableStart + cells[i],
|
|
23440
|
-
types.header_cell,
|
|
23441
|
-
nodes[i].attrs
|
|
23442
|
-
);
|
|
24187
|
+
for (let i = 0; i < cells.length; i++) if (nodes[i].type == types.header_cell) tr.setNodeMarkup(rect.tableStart + cells[i], types.cell, nodes[i].attrs);
|
|
24188
|
+
if (tr.steps.length === 0) for (let i = 0; i < cells.length; i++) tr.setNodeMarkup(rect.tableStart + cells[i], types.header_cell, nodes[i].attrs);
|
|
23443
24189
|
dispatch(tr);
|
|
23444
24190
|
}
|
|
23445
24191
|
return true;
|
|
@@ -23454,9 +24200,7 @@ function isHeaderEnabledByType(type, rect, types) {
|
|
|
23454
24200
|
});
|
|
23455
24201
|
for (let i = 0; i < cellPositions.length; i++) {
|
|
23456
24202
|
const cell = rect.table.nodeAt(cellPositions[i]);
|
|
23457
|
-
if (cell && cell.type !== types.header_cell)
|
|
23458
|
-
return false;
|
|
23459
|
-
}
|
|
24203
|
+
if (cell && cell.type !== types.header_cell) return false;
|
|
23460
24204
|
}
|
|
23461
24205
|
return true;
|
|
23462
24206
|
}
|
|
@@ -23469,13 +24213,8 @@ function toggleHeader(type, options) {
|
|
|
23469
24213
|
const types = tableNodeTypes(state.schema);
|
|
23470
24214
|
const rect = selectedRect(state), tr = state.tr;
|
|
23471
24215
|
const isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types);
|
|
23472
|
-
const isHeaderColumnEnabled = isHeaderEnabledByType(
|
|
23473
|
-
|
|
23474
|
-
rect,
|
|
23475
|
-
types
|
|
23476
|
-
);
|
|
23477
|
-
const isHeaderEnabled = type === "column" ? isHeaderRowEnabled : type === "row" ? isHeaderColumnEnabled : false;
|
|
23478
|
-
const selectionStartsAt = isHeaderEnabled ? 1 : 0;
|
|
24216
|
+
const isHeaderColumnEnabled = isHeaderEnabledByType("column", rect, types);
|
|
24217
|
+
const selectionStartsAt = (type === "column" ? isHeaderRowEnabled : type === "row" ? isHeaderColumnEnabled : false) ? 1 : 0;
|
|
23479
24218
|
const cellsRect = type == "column" ? {
|
|
23480
24219
|
left: 0,
|
|
23481
24220
|
top: selectionStartsAt,
|
|
@@ -23491,24 +24230,16 @@ function toggleHeader(type, options) {
|
|
|
23491
24230
|
rect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => {
|
|
23492
24231
|
const cellPos = relativeCellPos + rect.tableStart;
|
|
23493
24232
|
const cell = tr.doc.nodeAt(cellPos);
|
|
23494
|
-
if (cell)
|
|
23495
|
-
tr.setNodeMarkup(cellPos, newType, cell.attrs);
|
|
23496
|
-
}
|
|
24233
|
+
if (cell) tr.setNodeMarkup(cellPos, newType, cell.attrs);
|
|
23497
24234
|
});
|
|
23498
24235
|
dispatch(tr);
|
|
23499
24236
|
}
|
|
23500
24237
|
return true;
|
|
23501
24238
|
};
|
|
23502
24239
|
}
|
|
23503
|
-
toggleHeader("row", {
|
|
23504
|
-
|
|
23505
|
-
});
|
|
23506
|
-
toggleHeader("column", {
|
|
23507
|
-
useDeprecatedLogic: true
|
|
23508
|
-
});
|
|
23509
|
-
var toggleHeaderCell = toggleHeader("cell", {
|
|
23510
|
-
useDeprecatedLogic: true
|
|
23511
|
-
});
|
|
24240
|
+
toggleHeader("row", { useDeprecatedLogic: true });
|
|
24241
|
+
toggleHeader("column", { useDeprecatedLogic: true });
|
|
24242
|
+
const toggleHeaderCell = toggleHeader("cell", { useDeprecatedLogic: true });
|
|
23512
24243
|
function findNextCell($cell, dir) {
|
|
23513
24244
|
if (dir < 0) {
|
|
23514
24245
|
const before = $cell.nodeBefore;
|
|
@@ -23516,15 +24247,11 @@ function findNextCell($cell, dir) {
|
|
|
23516
24247
|
for (let row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) {
|
|
23517
24248
|
const rowNode = $cell.node(-1).child(row);
|
|
23518
24249
|
const lastChild = rowNode.lastChild;
|
|
23519
|
-
if (lastChild)
|
|
23520
|
-
return rowEnd - 1 - lastChild.nodeSize;
|
|
23521
|
-
}
|
|
24250
|
+
if (lastChild) return rowEnd - 1 - lastChild.nodeSize;
|
|
23522
24251
|
rowEnd -= rowNode.nodeSize;
|
|
23523
24252
|
}
|
|
23524
24253
|
} else {
|
|
23525
|
-
if ($cell.index() < $cell.parent.childCount - 1)
|
|
23526
|
-
return $cell.pos + $cell.nodeAfter.nodeSize;
|
|
23527
|
-
}
|
|
24254
|
+
if ($cell.index() < $cell.parent.childCount - 1) return $cell.pos + $cell.nodeAfter.nodeSize;
|
|
23528
24255
|
const table = $cell.node(-1);
|
|
23529
24256
|
for (let row = $cell.indexAfter(-1), rowStart = $cell.after(); row < table.childCount; row++) {
|
|
23530
24257
|
const rowNode = table.child(row);
|
|
@@ -23541,24 +24268,16 @@ function goToNextCell(direction) {
|
|
|
23541
24268
|
if (cell == null) return false;
|
|
23542
24269
|
if (dispatch) {
|
|
23543
24270
|
const $cell = state.doc.resolve(cell);
|
|
23544
|
-
dispatch(
|
|
23545
|
-
state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView()
|
|
23546
|
-
);
|
|
24271
|
+
dispatch(state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView());
|
|
23547
24272
|
}
|
|
23548
24273
|
return true;
|
|
23549
24274
|
};
|
|
23550
24275
|
}
|
|
23551
24276
|
function deleteTable(state, dispatch) {
|
|
23552
24277
|
const $pos = state.selection.$anchor;
|
|
23553
|
-
for (let d2 = $pos.depth; d2 > 0; d2--) {
|
|
23554
|
-
|
|
23555
|
-
|
|
23556
|
-
if (dispatch)
|
|
23557
|
-
dispatch(
|
|
23558
|
-
state.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView()
|
|
23559
|
-
);
|
|
23560
|
-
return true;
|
|
23561
|
-
}
|
|
24278
|
+
for (let d2 = $pos.depth; d2 > 0; d2--) if ($pos.node(d2).type.spec.tableRole == "table") {
|
|
24279
|
+
if (dispatch) dispatch(state.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView());
|
|
24280
|
+
return true;
|
|
23562
24281
|
}
|
|
23563
24282
|
return false;
|
|
23564
24283
|
}
|
|
@@ -23569,19 +24288,14 @@ function deleteCellSelection(state, dispatch) {
|
|
|
23569
24288
|
const tr = state.tr;
|
|
23570
24289
|
const baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
|
|
23571
24290
|
sel.forEachCell((cell, pos) => {
|
|
23572
|
-
if (!cell.content.eq(baseContent))
|
|
23573
|
-
tr.replace(
|
|
23574
|
-
tr.mapping.map(pos + 1),
|
|
23575
|
-
tr.mapping.map(pos + cell.nodeSize - 1),
|
|
23576
|
-
new Slice(baseContent, 0, 0)
|
|
23577
|
-
);
|
|
24291
|
+
if (!cell.content.eq(baseContent)) tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell.nodeSize - 1), new Slice(baseContent, 0, 0));
|
|
23578
24292
|
});
|
|
23579
24293
|
if (tr.docChanged) dispatch(tr);
|
|
23580
24294
|
}
|
|
23581
24295
|
return true;
|
|
23582
24296
|
}
|
|
23583
24297
|
function pastedCells(slice2) {
|
|
23584
|
-
if (
|
|
24298
|
+
if (slice2.size === 0) return null;
|
|
23585
24299
|
let { content, openStart, openEnd } = slice2;
|
|
23586
24300
|
while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) {
|
|
23587
24301
|
openStart--;
|
|
@@ -23591,28 +24305,15 @@ function pastedCells(slice2) {
|
|
|
23591
24305
|
const first2 = content.child(0);
|
|
23592
24306
|
const role = first2.type.spec.tableRole;
|
|
23593
24307
|
const schema = first2.type.schema, rows = [];
|
|
23594
|
-
if (role == "row") {
|
|
23595
|
-
|
|
23596
|
-
|
|
23597
|
-
|
|
23598
|
-
|
|
23599
|
-
|
|
23600
|
-
|
|
23601
|
-
|
|
23602
|
-
|
|
23603
|
-
).content;
|
|
23604
|
-
rows.push(cells);
|
|
23605
|
-
}
|
|
23606
|
-
} else if (role == "cell" || role == "header_cell") {
|
|
23607
|
-
rows.push(
|
|
23608
|
-
openStart || openEnd ? fitSlice(
|
|
23609
|
-
tableNodeTypes(schema).row,
|
|
23610
|
-
new Slice(content, openStart, openEnd)
|
|
23611
|
-
).content : content
|
|
23612
|
-
);
|
|
23613
|
-
} else {
|
|
23614
|
-
return null;
|
|
23615
|
-
}
|
|
24308
|
+
if (role == "row") for (let i = 0; i < content.childCount; i++) {
|
|
24309
|
+
let cells = content.child(i).content;
|
|
24310
|
+
const left2 = i ? 0 : Math.max(0, openStart - 1);
|
|
24311
|
+
const right2 = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
|
|
24312
|
+
if (left2 || right2) cells = fitSlice(tableNodeTypes(schema).row, new Slice(cells, left2, right2)).content;
|
|
24313
|
+
rows.push(cells);
|
|
24314
|
+
}
|
|
24315
|
+
else if (role == "cell" || role == "header_cell") rows.push(openStart || openEnd ? fitSlice(tableNodeTypes(schema).row, new Slice(content, openStart, openEnd)).content : content);
|
|
24316
|
+
else return null;
|
|
23616
24317
|
return ensureRectangular(schema, rows);
|
|
23617
24318
|
}
|
|
23618
24319
|
function ensureRectangular(schema, rows) {
|
|
@@ -23621,8 +24322,7 @@ function ensureRectangular(schema, rows) {
|
|
|
23621
24322
|
const row = rows[i];
|
|
23622
24323
|
for (let j = row.childCount - 1; j >= 0; j--) {
|
|
23623
24324
|
const { rowspan, colspan } = row.child(j).attrs;
|
|
23624
|
-
for (let r2 = i; r2 < i + rowspan; r2++)
|
|
23625
|
-
widths[r2] = (widths[r2] || 0) + colspan;
|
|
24325
|
+
for (let r2 = i; r2 < i + rowspan; r2++) widths[r2] = (widths[r2] || 0) + colspan;
|
|
23626
24326
|
}
|
|
23627
24327
|
}
|
|
23628
24328
|
let width = 0;
|
|
@@ -23632,18 +24332,19 @@ function ensureRectangular(schema, rows) {
|
|
|
23632
24332
|
if (widths[r2] < width) {
|
|
23633
24333
|
const empty2 = tableNodeTypes(schema).cell.createAndFill();
|
|
23634
24334
|
const cells = [];
|
|
23635
|
-
for (let i = widths[r2]; i < width; i++)
|
|
23636
|
-
cells.push(empty2);
|
|
23637
|
-
}
|
|
24335
|
+
for (let i = widths[r2]; i < width; i++) cells.push(empty2);
|
|
23638
24336
|
rows[r2] = rows[r2].append(Fragment.from(cells));
|
|
23639
24337
|
}
|
|
23640
24338
|
}
|
|
23641
|
-
return {
|
|
24339
|
+
return {
|
|
24340
|
+
height: rows.length,
|
|
24341
|
+
width,
|
|
24342
|
+
rows
|
|
24343
|
+
};
|
|
23642
24344
|
}
|
|
23643
24345
|
function fitSlice(nodeType, slice2) {
|
|
23644
24346
|
const node = nodeType.createAndFill();
|
|
23645
|
-
|
|
23646
|
-
return tr.doc;
|
|
24347
|
+
return new Transform(node).replace(0, node.content.size, slice2).doc;
|
|
23647
24348
|
}
|
|
23648
24349
|
function clipCells({ width, height, rows }, newWidth, newHeight) {
|
|
23649
24350
|
if (width != newWidth) {
|
|
@@ -23653,19 +24354,10 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
|
|
|
23653
24354
|
const frag = rows[row], cells = [];
|
|
23654
24355
|
for (let col = added[row] || 0, i = 0; col < newWidth; i++) {
|
|
23655
24356
|
let cell = frag.child(i % frag.childCount);
|
|
23656
|
-
if (col + cell.attrs.colspan > newWidth)
|
|
23657
|
-
cell = cell.type.createChecked(
|
|
23658
|
-
removeColSpan(
|
|
23659
|
-
cell.attrs,
|
|
23660
|
-
cell.attrs.colspan,
|
|
23661
|
-
col + cell.attrs.colspan - newWidth
|
|
23662
|
-
),
|
|
23663
|
-
cell.content
|
|
23664
|
-
);
|
|
24357
|
+
if (col + cell.attrs.colspan > newWidth) cell = cell.type.createChecked(removeColSpan(cell.attrs, cell.attrs.colspan, col + cell.attrs.colspan - newWidth), cell.content);
|
|
23665
24358
|
cells.push(cell);
|
|
23666
24359
|
col += cell.attrs.colspan;
|
|
23667
|
-
for (let j = 1; j < cell.attrs.rowspan; j++)
|
|
23668
|
-
added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;
|
|
24360
|
+
for (let j = 1; j < cell.attrs.rowspan; j++) added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;
|
|
23669
24361
|
}
|
|
23670
24362
|
newRows.push(Fragment.from(cells));
|
|
23671
24363
|
}
|
|
@@ -23678,14 +24370,10 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
|
|
|
23678
24370
|
const cells = [], source = rows[i % height];
|
|
23679
24371
|
for (let j = 0; j < source.childCount; j++) {
|
|
23680
24372
|
let cell = source.child(j);
|
|
23681
|
-
if (row + cell.attrs.rowspan > newHeight)
|
|
23682
|
-
cell
|
|
23683
|
-
|
|
23684
|
-
|
|
23685
|
-
rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
|
|
23686
|
-
},
|
|
23687
|
-
cell.content
|
|
23688
|
-
);
|
|
24373
|
+
if (row + cell.attrs.rowspan > newHeight) cell = cell.type.create({
|
|
24374
|
+
...cell.attrs,
|
|
24375
|
+
rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
|
|
24376
|
+
}, cell.content);
|
|
23689
24377
|
cells.push(cell);
|
|
23690
24378
|
}
|
|
23691
24379
|
newRows.push(Fragment.from(cells));
|
|
@@ -23693,33 +24381,32 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
|
|
|
23693
24381
|
rows = newRows;
|
|
23694
24382
|
height = newHeight;
|
|
23695
24383
|
}
|
|
23696
|
-
return {
|
|
24384
|
+
return {
|
|
24385
|
+
width,
|
|
24386
|
+
height,
|
|
24387
|
+
rows
|
|
24388
|
+
};
|
|
23697
24389
|
}
|
|
23698
24390
|
function growTable(tr, map2, table, start2, width, height, mapFrom) {
|
|
23699
24391
|
const schema = tr.doc.type.schema;
|
|
23700
24392
|
const types = tableNodeTypes(schema);
|
|
23701
24393
|
let empty2;
|
|
23702
24394
|
let emptyHead;
|
|
23703
|
-
if (width > map2.width) {
|
|
23704
|
-
|
|
23705
|
-
|
|
23706
|
-
|
|
23707
|
-
|
|
23708
|
-
|
|
23709
|
-
|
|
23710
|
-
|
|
23711
|
-
|
|
23712
|
-
for (let i = map2.width; i < width; i++) cells.push(add);
|
|
23713
|
-
tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start2), cells);
|
|
23714
|
-
}
|
|
24395
|
+
if (width > map2.width) for (let row = 0, rowEnd = 0; row < map2.height; row++) {
|
|
24396
|
+
const rowNode = table.child(row);
|
|
24397
|
+
rowEnd += rowNode.nodeSize;
|
|
24398
|
+
const cells = [];
|
|
24399
|
+
let add;
|
|
24400
|
+
if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell) add = empty2 || (empty2 = types.cell.createAndFill());
|
|
24401
|
+
else add = emptyHead || (emptyHead = types.header_cell.createAndFill());
|
|
24402
|
+
for (let i = map2.width; i < width; i++) cells.push(add);
|
|
24403
|
+
tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start2), cells);
|
|
23715
24404
|
}
|
|
23716
24405
|
if (height > map2.height) {
|
|
23717
24406
|
const cells = [];
|
|
23718
|
-
for (let i = 0,
|
|
23719
|
-
const header = i >= map2.width ? false : table.nodeAt(map2.map[
|
|
23720
|
-
cells.push(
|
|
23721
|
-
header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty2 || (empty2 = types.cell.createAndFill())
|
|
23722
|
-
);
|
|
24407
|
+
for (let i = 0, start$1 = (map2.height - 1) * map2.width; i < Math.max(map2.width, width); i++) {
|
|
24408
|
+
const header = i >= map2.width ? false : table.nodeAt(map2.map[start$1 + i]).type == types.header_cell;
|
|
24409
|
+
cells.push(header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty2 || (empty2 = types.cell.createAndFill()));
|
|
23723
24410
|
}
|
|
23724
24411
|
const emptyRow = types.row.create(null, Fragment.from(cells)), rows = [];
|
|
23725
24412
|
for (let i = map2.height; i < height; i++) rows.push(emptyRow);
|
|
@@ -23740,13 +24427,10 @@ function isolateHorizontal(tr, map2, table, start2, left2, right2, top2, mapFrom
|
|
|
23740
24427
|
...cell.attrs,
|
|
23741
24428
|
rowspan: top2 - cellTop
|
|
23742
24429
|
});
|
|
23743
|
-
tr.insert(
|
|
23744
|
-
|
|
23745
|
-
cell.
|
|
23746
|
-
|
|
23747
|
-
rowspan: cellTop + cell.attrs.rowspan - top2
|
|
23748
|
-
})
|
|
23749
|
-
);
|
|
24430
|
+
tr.insert(tr.mapping.slice(mapFrom).map(map2.positionAt(top2, cellLeft, table)), cell.type.createAndFill({
|
|
24431
|
+
...cell.attrs,
|
|
24432
|
+
rowspan: cellTop + cell.attrs.rowspan - top2
|
|
24433
|
+
}));
|
|
23750
24434
|
col += cell.attrs.colspan - 1;
|
|
23751
24435
|
}
|
|
23752
24436
|
}
|
|
@@ -23762,21 +24446,8 @@ function isolateVertical(tr, map2, table, start2, top2, bottom2, left2, mapFrom)
|
|
|
23762
24446
|
const cell = table.nodeAt(pos);
|
|
23763
24447
|
const cellLeft = map2.colCount(pos);
|
|
23764
24448
|
const updatePos = tr.mapping.slice(mapFrom).map(pos + start2);
|
|
23765
|
-
tr.setNodeMarkup(
|
|
23766
|
-
|
|
23767
|
-
null,
|
|
23768
|
-
removeColSpan(
|
|
23769
|
-
cell.attrs,
|
|
23770
|
-
left2 - cellLeft,
|
|
23771
|
-
cell.attrs.colspan - (left2 - cellLeft)
|
|
23772
|
-
)
|
|
23773
|
-
);
|
|
23774
|
-
tr.insert(
|
|
23775
|
-
updatePos + cell.nodeSize,
|
|
23776
|
-
cell.type.createAndFill(
|
|
23777
|
-
removeColSpan(cell.attrs, 0, left2 - cellLeft)
|
|
23778
|
-
)
|
|
23779
|
-
);
|
|
24449
|
+
tr.setNodeMarkup(updatePos, null, removeColSpan(cell.attrs, left2 - cellLeft, cell.attrs.colspan - (left2 - cellLeft)));
|
|
24450
|
+
tr.insert(updatePos + cell.nodeSize, cell.type.createAndFill(removeColSpan(cell.attrs, 0, left2 - cellLeft)));
|
|
23780
24451
|
row += cell.attrs.rowspan - 1;
|
|
23781
24452
|
}
|
|
23782
24453
|
}
|
|
@@ -23784,9 +24455,7 @@ function isolateVertical(tr, map2, table, start2, top2, bottom2, left2, mapFrom)
|
|
|
23784
24455
|
}
|
|
23785
24456
|
function insertCells(state, dispatch, tableStart, rect, cells) {
|
|
23786
24457
|
let table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc;
|
|
23787
|
-
if (!table)
|
|
23788
|
-
throw new Error("No table found");
|
|
23789
|
-
}
|
|
24458
|
+
if (!table) throw new Error("No table found");
|
|
23790
24459
|
let map2 = TableMap.get(table);
|
|
23791
24460
|
const { top: top2, left: left2 } = rect;
|
|
23792
24461
|
const right2 = left2 + cells.width, bottom2 = top2 + cells.height;
|
|
@@ -23794,39 +24463,24 @@ function insertCells(state, dispatch, tableStart, rect, cells) {
|
|
|
23794
24463
|
let mapFrom = 0;
|
|
23795
24464
|
function recomp() {
|
|
23796
24465
|
table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
|
|
23797
|
-
if (!table)
|
|
23798
|
-
throw new Error("No table found");
|
|
23799
|
-
}
|
|
24466
|
+
if (!table) throw new Error("No table found");
|
|
23800
24467
|
map2 = TableMap.get(table);
|
|
23801
24468
|
mapFrom = tr.mapping.maps.length;
|
|
23802
24469
|
}
|
|
23803
24470
|
if (growTable(tr, map2, table, tableStart, right2, bottom2, mapFrom)) recomp();
|
|
23804
|
-
if (isolateHorizontal(tr, map2, table, tableStart, left2, right2, top2, mapFrom))
|
|
23805
|
-
|
|
23806
|
-
if (
|
|
23807
|
-
|
|
23808
|
-
if (isolateVertical(tr, map2, table, tableStart, top2, bottom2, left2, mapFrom))
|
|
23809
|
-
recomp();
|
|
23810
|
-
if (isolateVertical(tr, map2, table, tableStart, top2, bottom2, right2, mapFrom))
|
|
23811
|
-
recomp();
|
|
24471
|
+
if (isolateHorizontal(tr, map2, table, tableStart, left2, right2, top2, mapFrom)) recomp();
|
|
24472
|
+
if (isolateHorizontal(tr, map2, table, tableStart, left2, right2, bottom2, mapFrom)) recomp();
|
|
24473
|
+
if (isolateVertical(tr, map2, table, tableStart, top2, bottom2, left2, mapFrom)) recomp();
|
|
24474
|
+
if (isolateVertical(tr, map2, table, tableStart, top2, bottom2, right2, mapFrom)) recomp();
|
|
23812
24475
|
for (let row = top2; row < bottom2; row++) {
|
|
23813
24476
|
const from2 = map2.positionAt(row, left2, table), to = map2.positionAt(row, right2, table);
|
|
23814
|
-
tr.replace(
|
|
23815
|
-
tr.mapping.slice(mapFrom).map(from2 + tableStart),
|
|
23816
|
-
tr.mapping.slice(mapFrom).map(to + tableStart),
|
|
23817
|
-
new Slice(cells.rows[row - top2], 0, 0)
|
|
23818
|
-
);
|
|
24477
|
+
tr.replace(tr.mapping.slice(mapFrom).map(from2 + tableStart), tr.mapping.slice(mapFrom).map(to + tableStart), new Slice(cells.rows[row - top2], 0, 0));
|
|
23819
24478
|
}
|
|
23820
24479
|
recomp();
|
|
23821
|
-
tr.setSelection(
|
|
23822
|
-
new CellSelection(
|
|
23823
|
-
tr.doc.resolve(tableStart + map2.positionAt(top2, left2, table)),
|
|
23824
|
-
tr.doc.resolve(tableStart + map2.positionAt(bottom2 - 1, right2 - 1, table))
|
|
23825
|
-
)
|
|
23826
|
-
);
|
|
24480
|
+
tr.setSelection(new CellSelection(tr.doc.resolve(tableStart + map2.positionAt(top2, left2, table)), tr.doc.resolve(tableStart + map2.positionAt(bottom2 - 1, right2 - 1, table))));
|
|
23827
24481
|
dispatch(tr);
|
|
23828
24482
|
}
|
|
23829
|
-
|
|
24483
|
+
const handleKeyDown = keydownHandler({
|
|
23830
24484
|
ArrowLeft: arrow$2("horiz", -1),
|
|
23831
24485
|
ArrowRight: arrow$2("horiz", 1),
|
|
23832
24486
|
ArrowUp: arrow$2("vert", -1),
|
|
@@ -23849,29 +24503,17 @@ function arrow$2(axis, dir) {
|
|
|
23849
24503
|
return (state, dispatch, view) => {
|
|
23850
24504
|
if (!view) return false;
|
|
23851
24505
|
const sel = state.selection;
|
|
23852
|
-
if (sel instanceof CellSelection)
|
|
23853
|
-
return maybeSetSelection(
|
|
23854
|
-
state,
|
|
23855
|
-
dispatch,
|
|
23856
|
-
Selection.near(sel.$headCell, dir)
|
|
23857
|
-
);
|
|
23858
|
-
}
|
|
24506
|
+
if (sel instanceof CellSelection) return maybeSetSelection(state, dispatch, Selection.near(sel.$headCell, dir));
|
|
23859
24507
|
if (axis != "horiz" && !sel.empty) return false;
|
|
23860
24508
|
const end2 = atEndOfCell(view, axis, dir);
|
|
23861
24509
|
if (end2 == null) return false;
|
|
23862
|
-
if (axis == "horiz")
|
|
23863
|
-
|
|
23864
|
-
state,
|
|
23865
|
-
dispatch,
|
|
23866
|
-
Selection.near(state.doc.resolve(sel.head + dir), dir)
|
|
23867
|
-
);
|
|
23868
|
-
} else {
|
|
24510
|
+
if (axis == "horiz") return maybeSetSelection(state, dispatch, Selection.near(state.doc.resolve(sel.head + dir), dir));
|
|
24511
|
+
else {
|
|
23869
24512
|
const $cell = state.doc.resolve(end2);
|
|
23870
24513
|
const $next = nextCell($cell, axis, dir);
|
|
23871
24514
|
let newSel;
|
|
23872
24515
|
if ($next) newSel = Selection.near($next, 1);
|
|
23873
|
-
else if (dir < 0)
|
|
23874
|
-
newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1);
|
|
24516
|
+
else if (dir < 0) newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1);
|
|
23875
24517
|
else newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1);
|
|
23876
24518
|
return maybeSetSelection(state, dispatch, newSel);
|
|
23877
24519
|
}
|
|
@@ -23882,20 +24524,15 @@ function shiftArrow(axis, dir) {
|
|
|
23882
24524
|
if (!view) return false;
|
|
23883
24525
|
const sel = state.selection;
|
|
23884
24526
|
let cellSel;
|
|
23885
|
-
if (sel instanceof CellSelection)
|
|
23886
|
-
|
|
23887
|
-
} else {
|
|
24527
|
+
if (sel instanceof CellSelection) cellSel = sel;
|
|
24528
|
+
else {
|
|
23888
24529
|
const end2 = atEndOfCell(view, axis, dir);
|
|
23889
24530
|
if (end2 == null) return false;
|
|
23890
24531
|
cellSel = new CellSelection(state.doc.resolve(end2));
|
|
23891
24532
|
}
|
|
23892
24533
|
const $head = nextCell(cellSel.$headCell, axis, dir);
|
|
23893
24534
|
if (!$head) return false;
|
|
23894
|
-
return maybeSetSelection(
|
|
23895
|
-
state,
|
|
23896
|
-
dispatch,
|
|
23897
|
-
new CellSelection(cellSel.$anchorCell, $head)
|
|
23898
|
-
);
|
|
24535
|
+
return maybeSetSelection(state, dispatch, new CellSelection(cellSel.$anchorCell, $head));
|
|
23899
24536
|
};
|
|
23900
24537
|
}
|
|
23901
24538
|
function handleTripleClick(view, pos) {
|
|
@@ -23909,65 +24546,45 @@ function handlePaste(view, _, slice2) {
|
|
|
23909
24546
|
let cells = pastedCells(slice2);
|
|
23910
24547
|
const sel = view.state.selection;
|
|
23911
24548
|
if (sel instanceof CellSelection) {
|
|
23912
|
-
if (!cells)
|
|
23913
|
-
|
|
23914
|
-
|
|
23915
|
-
|
|
23916
|
-
|
|
23917
|
-
Fragment.from(
|
|
23918
|
-
fitSlice(tableNodeTypes(view.state.schema).cell, slice2)
|
|
23919
|
-
)
|
|
23920
|
-
]
|
|
23921
|
-
};
|
|
24549
|
+
if (!cells) cells = {
|
|
24550
|
+
width: 1,
|
|
24551
|
+
height: 1,
|
|
24552
|
+
rows: [Fragment.from(fitSlice(tableNodeTypes(view.state.schema).cell, slice2))]
|
|
24553
|
+
};
|
|
23922
24554
|
const table = sel.$anchorCell.node(-1);
|
|
23923
24555
|
const start2 = sel.$anchorCell.start(-1);
|
|
23924
|
-
const rect = TableMap.get(table).rectBetween(
|
|
23925
|
-
sel.$anchorCell.pos - start2,
|
|
23926
|
-
sel.$headCell.pos - start2
|
|
23927
|
-
);
|
|
24556
|
+
const rect = TableMap.get(table).rectBetween(sel.$anchorCell.pos - start2, sel.$headCell.pos - start2);
|
|
23928
24557
|
cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
|
|
23929
24558
|
insertCells(view.state, view.dispatch, start2, rect, cells);
|
|
23930
24559
|
return true;
|
|
23931
24560
|
} else if (cells) {
|
|
23932
24561
|
const $cell = selectionCell(view.state);
|
|
23933
24562
|
const start2 = $cell.start(-1);
|
|
23934
|
-
insertCells(
|
|
23935
|
-
view.state,
|
|
23936
|
-
view.dispatch,
|
|
23937
|
-
start2,
|
|
23938
|
-
TableMap.get($cell.node(-1)).findCell($cell.pos - start2),
|
|
23939
|
-
cells
|
|
23940
|
-
);
|
|
24563
|
+
insertCells(view.state, view.dispatch, start2, TableMap.get($cell.node(-1)).findCell($cell.pos - start2), cells);
|
|
23941
24564
|
return true;
|
|
23942
|
-
} else
|
|
23943
|
-
return false;
|
|
23944
|
-
}
|
|
24565
|
+
} else return false;
|
|
23945
24566
|
}
|
|
23946
24567
|
function handleMouseDown(view, startEvent) {
|
|
23947
|
-
var
|
|
24568
|
+
var _cellUnderMouse;
|
|
23948
24569
|
if (startEvent.ctrlKey || startEvent.metaKey) return;
|
|
23949
24570
|
const startDOMCell = domInCell(view, startEvent.target);
|
|
23950
24571
|
let $anchor;
|
|
23951
24572
|
if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
|
|
23952
24573
|
setCellSelection(view.state.selection.$anchorCell, startEvent);
|
|
23953
24574
|
startEvent.preventDefault();
|
|
23954
|
-
} else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround$1(view.state.selection.$anchor)) != null && ((
|
|
24575
|
+
} else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround$1(view.state.selection.$anchor)) != null && ((_cellUnderMouse = cellUnderMouse(view, startEvent)) === null || _cellUnderMouse === void 0 ? void 0 : _cellUnderMouse.pos) != $anchor.pos) {
|
|
23955
24576
|
setCellSelection($anchor, startEvent);
|
|
23956
24577
|
startEvent.preventDefault();
|
|
23957
|
-
} else if (!startDOMCell)
|
|
23958
|
-
|
|
23959
|
-
}
|
|
23960
|
-
function setCellSelection($anchor2, event) {
|
|
24578
|
+
} else if (!startDOMCell) return;
|
|
24579
|
+
function setCellSelection($anchor$1, event) {
|
|
23961
24580
|
let $head = cellUnderMouse(view, event);
|
|
23962
24581
|
const starting = tableEditingKey.getState(view.state) == null;
|
|
23963
|
-
if (!$head || !inSameTable($
|
|
23964
|
-
|
|
23965
|
-
|
|
23966
|
-
}
|
|
23967
|
-
const selection = new CellSelection($anchor2, $head);
|
|
24582
|
+
if (!$head || !inSameTable($anchor$1, $head)) if (starting) $head = $anchor$1;
|
|
24583
|
+
else return;
|
|
24584
|
+
const selection = new CellSelection($anchor$1, $head);
|
|
23968
24585
|
if (starting || !view.state.selection.eq(selection)) {
|
|
23969
24586
|
const tr = view.state.tr.setSelection(selection);
|
|
23970
|
-
if (starting) tr.setMeta(tableEditingKey, $
|
|
24587
|
+
if (starting) tr.setMeta(tableEditingKey, $anchor$1.pos);
|
|
23971
24588
|
view.dispatch(tr);
|
|
23972
24589
|
}
|
|
23973
24590
|
}
|
|
@@ -23975,20 +24592,18 @@ function handleMouseDown(view, startEvent) {
|
|
|
23975
24592
|
view.root.removeEventListener("mouseup", stop);
|
|
23976
24593
|
view.root.removeEventListener("dragstart", stop);
|
|
23977
24594
|
view.root.removeEventListener("mousemove", move);
|
|
23978
|
-
if (tableEditingKey.getState(view.state) != null)
|
|
23979
|
-
view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
|
|
24595
|
+
if (tableEditingKey.getState(view.state) != null) view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
|
|
23980
24596
|
}
|
|
23981
24597
|
function move(_event) {
|
|
23982
24598
|
const event = _event;
|
|
23983
24599
|
const anchor = tableEditingKey.getState(view.state);
|
|
23984
|
-
let $
|
|
23985
|
-
if (anchor != null)
|
|
23986
|
-
|
|
23987
|
-
|
|
23988
|
-
$
|
|
23989
|
-
if (!$anchor2) return stop();
|
|
24600
|
+
let $anchor$1;
|
|
24601
|
+
if (anchor != null) $anchor$1 = view.state.doc.resolve(anchor);
|
|
24602
|
+
else if (domInCell(view, event.target) != startDOMCell) {
|
|
24603
|
+
$anchor$1 = cellUnderMouse(view, startEvent);
|
|
24604
|
+
if (!$anchor$1) return stop();
|
|
23990
24605
|
}
|
|
23991
|
-
if ($
|
|
24606
|
+
if ($anchor$1) setCellSelection($anchor$1, event);
|
|
23992
24607
|
}
|
|
23993
24608
|
view.root.addEventListener("mouseup", stop);
|
|
23994
24609
|
view.root.addEventListener("dragstart", stop);
|
|
@@ -23998,8 +24613,8 @@ function atEndOfCell(view, axis, dir) {
|
|
|
23998
24613
|
if (!(view.state.selection instanceof TextSelection)) return null;
|
|
23999
24614
|
const { $head } = view.state.selection;
|
|
24000
24615
|
for (let d2 = $head.depth - 1; d2 >= 0; d2--) {
|
|
24001
|
-
const parent = $head.node(d2)
|
|
24002
|
-
if (
|
|
24616
|
+
const parent = $head.node(d2);
|
|
24617
|
+
if ((dir < 0 ? $head.index(d2) : $head.indexAfter(d2)) != (dir < 0 ? 0 : parent.childCount)) return null;
|
|
24003
24618
|
if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
|
|
24004
24619
|
const cellPos = $head.before(d2);
|
|
24005
24620
|
const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
|
|
@@ -24009,11 +24624,7 @@ function atEndOfCell(view, axis, dir) {
|
|
|
24009
24624
|
return null;
|
|
24010
24625
|
}
|
|
24011
24626
|
function domInCell(view, dom) {
|
|
24012
|
-
for (; dom && dom != view.dom; dom = dom.parentNode)
|
|
24013
|
-
if (dom.nodeName == "TD" || dom.nodeName == "TH") {
|
|
24014
|
-
return dom;
|
|
24015
|
-
}
|
|
24016
|
-
}
|
|
24627
|
+
for (; dom && dom != view.dom; dom = dom.parentNode) if (dom.nodeName == "TD" || dom.nodeName == "TH") return dom;
|
|
24017
24628
|
return null;
|
|
24018
24629
|
}
|
|
24019
24630
|
function cellUnderMouse(view, event) {
|
|
@@ -24022,7 +24633,8 @@ function cellUnderMouse(view, event) {
|
|
|
24022
24633
|
top: event.clientY
|
|
24023
24634
|
});
|
|
24024
24635
|
if (!mousePos) return null;
|
|
24025
|
-
|
|
24636
|
+
const pos = mousePos.inside >= 0 ? mousePos.inside : mousePos.pos;
|
|
24637
|
+
return cellAround$1(view.state.doc.resolve(pos));
|
|
24026
24638
|
}
|
|
24027
24639
|
var TableView = class {
|
|
24028
24640
|
constructor(node, defaultCellMinWidth) {
|
|
@@ -24031,10 +24643,7 @@ var TableView = class {
|
|
|
24031
24643
|
this.dom = document.createElement("div");
|
|
24032
24644
|
this.dom.className = "tableWrapper";
|
|
24033
24645
|
this.table = this.dom.appendChild(document.createElement("table"));
|
|
24034
|
-
this.table.style.setProperty(
|
|
24035
|
-
"--default-cell-min-width",
|
|
24036
|
-
`${defaultCellMinWidth}px`
|
|
24037
|
-
);
|
|
24646
|
+
this.table.style.setProperty("--default-cell-min-width", `${defaultCellMinWidth}px`);
|
|
24038
24647
|
this.colgroup = this.table.appendChild(document.createElement("colgroup"));
|
|
24039
24648
|
updateColumnsOnResize(node, this.colgroup, this.table, defaultCellMinWidth);
|
|
24040
24649
|
this.contentDOM = this.table.appendChild(document.createElement("tbody"));
|
|
@@ -24042,12 +24651,7 @@ var TableView = class {
|
|
|
24042
24651
|
update(node) {
|
|
24043
24652
|
if (node.type != this.node.type) return false;
|
|
24044
24653
|
this.node = node;
|
|
24045
|
-
updateColumnsOnResize(
|
|
24046
|
-
node,
|
|
24047
|
-
this.colgroup,
|
|
24048
|
-
this.table,
|
|
24049
|
-
this.defaultCellMinWidth
|
|
24050
|
-
);
|
|
24654
|
+
updateColumnsOnResize(node, this.colgroup, this.table, this.defaultCellMinWidth);
|
|
24051
24655
|
return true;
|
|
24052
24656
|
}
|
|
24053
24657
|
ignoreMutation(record) {
|
|
@@ -24055,7 +24659,6 @@ var TableView = class {
|
|
|
24055
24659
|
}
|
|
24056
24660
|
};
|
|
24057
24661
|
function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overrideCol, overrideValue) {
|
|
24058
|
-
var _a;
|
|
24059
24662
|
let totalWidth = 0;
|
|
24060
24663
|
let fixedWidth = true;
|
|
24061
24664
|
let nextDOM = colgroup.firstChild;
|
|
@@ -24069,20 +24672,19 @@ function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overr
|
|
|
24069
24672
|
totalWidth += hasWidth || defaultCellMinWidth;
|
|
24070
24673
|
if (!hasWidth) fixedWidth = false;
|
|
24071
24674
|
if (!nextDOM) {
|
|
24072
|
-
const
|
|
24073
|
-
|
|
24074
|
-
colgroup.appendChild(
|
|
24675
|
+
const col$1 = document.createElement("col");
|
|
24676
|
+
col$1.style.width = cssWidth;
|
|
24677
|
+
colgroup.appendChild(col$1);
|
|
24075
24678
|
} else {
|
|
24076
|
-
if (nextDOM.style.width != cssWidth)
|
|
24077
|
-
nextDOM.style.width = cssWidth;
|
|
24078
|
-
}
|
|
24679
|
+
if (nextDOM.style.width != cssWidth) nextDOM.style.width = cssWidth;
|
|
24079
24680
|
nextDOM = nextDOM.nextSibling;
|
|
24080
24681
|
}
|
|
24081
24682
|
}
|
|
24082
24683
|
}
|
|
24083
24684
|
while (nextDOM) {
|
|
24685
|
+
var _nextDOM$parentNode;
|
|
24084
24686
|
const after = nextDOM.nextSibling;
|
|
24085
|
-
(
|
|
24687
|
+
(_nextDOM$parentNode = nextDOM.parentNode) === null || _nextDOM$parentNode === void 0 || _nextDOM$parentNode.removeChild(nextDOM);
|
|
24086
24688
|
nextDOM = after;
|
|
24087
24689
|
}
|
|
24088
24690
|
if (fixedWidth) {
|
|
@@ -24093,28 +24695,18 @@ function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overr
|
|
|
24093
24695
|
table.style.minWidth = totalWidth + "px";
|
|
24094
24696
|
}
|
|
24095
24697
|
}
|
|
24096
|
-
|
|
24097
|
-
|
|
24098
|
-
);
|
|
24099
|
-
function columnResizing({
|
|
24100
|
-
handleWidth = 5,
|
|
24101
|
-
cellMinWidth = 25,
|
|
24102
|
-
defaultCellMinWidth = 100,
|
|
24103
|
-
View = TableView,
|
|
24104
|
-
lastColumnResizable = true
|
|
24105
|
-
} = {}) {
|
|
24698
|
+
const columnResizingPluginKey = new PluginKey("tableColumnResizing");
|
|
24699
|
+
function columnResizing({ handleWidth = 5, cellMinWidth = 25, defaultCellMinWidth = 100, View = TableView, lastColumnResizable = true } = {}) {
|
|
24106
24700
|
const plugin = new Plugin({
|
|
24107
24701
|
key: columnResizingPluginKey,
|
|
24108
24702
|
state: {
|
|
24109
24703
|
init(_, state) {
|
|
24110
|
-
var
|
|
24111
|
-
const nodeViews = (
|
|
24704
|
+
var _plugin$spec;
|
|
24705
|
+
const nodeViews = (_plugin$spec = plugin.spec) === null || _plugin$spec === void 0 || (_plugin$spec = _plugin$spec.props) === null || _plugin$spec === void 0 ? void 0 : _plugin$spec.nodeViews;
|
|
24112
24706
|
const tableName = tableNodeTypes(state.schema).table.name;
|
|
24113
|
-
if (View && nodeViews) {
|
|
24114
|
-
|
|
24115
|
-
|
|
24116
|
-
};
|
|
24117
|
-
}
|
|
24707
|
+
if (View && nodeViews) nodeViews[tableName] = (node, view) => {
|
|
24708
|
+
return new View(node, defaultCellMinWidth, view);
|
|
24709
|
+
};
|
|
24118
24710
|
return new ResizeState(-1, false);
|
|
24119
24711
|
},
|
|
24120
24712
|
apply(tr, prev) {
|
|
@@ -24134,21 +24726,19 @@ function columnResizing({
|
|
|
24134
24726
|
handleMouseLeave(view);
|
|
24135
24727
|
},
|
|
24136
24728
|
mousedown: (view, event) => {
|
|
24137
|
-
|
|
24729
|
+
handleMouseDown$1(view, event, cellMinWidth, defaultCellMinWidth);
|
|
24138
24730
|
}
|
|
24139
24731
|
},
|
|
24140
24732
|
decorations: (state) => {
|
|
24141
24733
|
const pluginState = columnResizingPluginKey.getState(state);
|
|
24142
|
-
if (pluginState && pluginState.activeHandle > -1)
|
|
24143
|
-
return handleDecorations(state, pluginState.activeHandle);
|
|
24144
|
-
}
|
|
24734
|
+
if (pluginState && pluginState.activeHandle > -1) return handleDecorations(state, pluginState.activeHandle);
|
|
24145
24735
|
},
|
|
24146
24736
|
nodeViews: {}
|
|
24147
24737
|
}
|
|
24148
24738
|
});
|
|
24149
24739
|
return plugin;
|
|
24150
24740
|
}
|
|
24151
|
-
var ResizeState = class
|
|
24741
|
+
var ResizeState = class ResizeState2 {
|
|
24152
24742
|
constructor(activeHandle, dragging) {
|
|
24153
24743
|
this.activeHandle = activeHandle;
|
|
24154
24744
|
this.dragging = dragging;
|
|
@@ -24156,16 +24746,12 @@ var ResizeState = class _ResizeState {
|
|
|
24156
24746
|
apply(tr) {
|
|
24157
24747
|
const state = this;
|
|
24158
24748
|
const action = tr.getMeta(columnResizingPluginKey);
|
|
24159
|
-
if (action && action.setHandle != null)
|
|
24160
|
-
|
|
24161
|
-
if (action && action.setDragging !== void 0)
|
|
24162
|
-
return new _ResizeState(state.activeHandle, action.setDragging);
|
|
24749
|
+
if (action && action.setHandle != null) return new ResizeState2(action.setHandle, false);
|
|
24750
|
+
if (action && action.setDragging !== void 0) return new ResizeState2(state.activeHandle, action.setDragging);
|
|
24163
24751
|
if (state.activeHandle > -1 && tr.docChanged) {
|
|
24164
24752
|
let handle = tr.mapping.map(state.activeHandle, -1);
|
|
24165
|
-
if (!pointsAtCell(tr.doc.resolve(handle)))
|
|
24166
|
-
|
|
24167
|
-
}
|
|
24168
|
-
return new _ResizeState(handle, state.dragging);
|
|
24753
|
+
if (!pointsAtCell(tr.doc.resolve(handle))) handle = -1;
|
|
24754
|
+
return new ResizeState2(handle, state.dragging);
|
|
24169
24755
|
}
|
|
24170
24756
|
return state;
|
|
24171
24757
|
}
|
|
@@ -24179,10 +24765,8 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
|
|
|
24179
24765
|
let cell = -1;
|
|
24180
24766
|
if (target) {
|
|
24181
24767
|
const { left: left2, right: right2 } = target.getBoundingClientRect();
|
|
24182
|
-
if (event.clientX - left2 <= handleWidth)
|
|
24183
|
-
|
|
24184
|
-
else if (right2 - event.clientX <= handleWidth)
|
|
24185
|
-
cell = edgeCell(view, event, "right", handleWidth);
|
|
24768
|
+
if (event.clientX - left2 <= handleWidth) cell = edgeCell(view, event, "left", handleWidth);
|
|
24769
|
+
else if (right2 - event.clientX <= handleWidth) cell = edgeCell(view, event, "right", handleWidth);
|
|
24186
24770
|
}
|
|
24187
24771
|
if (cell != pluginState.activeHandle) {
|
|
24188
24772
|
if (!lastColumnResizable && cell !== -1) {
|
|
@@ -24190,10 +24774,7 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
|
|
|
24190
24774
|
const table = $cell.node(-1);
|
|
24191
24775
|
const map2 = TableMap.get(table);
|
|
24192
24776
|
const tableStart = $cell.start(-1);
|
|
24193
|
-
|
|
24194
|
-
if (col == map2.width - 1) {
|
|
24195
|
-
return;
|
|
24196
|
-
}
|
|
24777
|
+
if (map2.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1 == map2.width - 1) return;
|
|
24197
24778
|
}
|
|
24198
24779
|
updateHandle(view, cell);
|
|
24199
24780
|
}
|
|
@@ -24202,58 +24783,39 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
|
|
|
24202
24783
|
function handleMouseLeave(view) {
|
|
24203
24784
|
if (!view.editable) return;
|
|
24204
24785
|
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
24205
|
-
if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging)
|
|
24206
|
-
updateHandle(view, -1);
|
|
24786
|
+
if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging) updateHandle(view, -1);
|
|
24207
24787
|
}
|
|
24208
|
-
function
|
|
24209
|
-
var
|
|
24788
|
+
function handleMouseDown$1(view, event, cellMinWidth, defaultCellMinWidth) {
|
|
24789
|
+
var _view$dom$ownerDocume;
|
|
24210
24790
|
if (!view.editable) return false;
|
|
24211
|
-
const win = (
|
|
24791
|
+
const win = (_view$dom$ownerDocume = view.dom.ownerDocument.defaultView) !== null && _view$dom$ownerDocume !== void 0 ? _view$dom$ownerDocume : window;
|
|
24212
24792
|
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
24213
|
-
if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging)
|
|
24214
|
-
return false;
|
|
24793
|
+
if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging) return false;
|
|
24215
24794
|
const cell = view.state.doc.nodeAt(pluginState.activeHandle);
|
|
24216
24795
|
const width = currentColWidth(view, pluginState.activeHandle, cell.attrs);
|
|
24217
|
-
view.dispatch(
|
|
24218
|
-
|
|
24219
|
-
|
|
24220
|
-
|
|
24221
|
-
)
|
|
24222
|
-
function finish(event2) {
|
|
24796
|
+
view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: {
|
|
24797
|
+
startX: event.clientX,
|
|
24798
|
+
startWidth: width
|
|
24799
|
+
} }));
|
|
24800
|
+
function finish(event$1) {
|
|
24223
24801
|
win.removeEventListener("mouseup", finish);
|
|
24224
24802
|
win.removeEventListener("mousemove", move);
|
|
24225
|
-
const
|
|
24226
|
-
if (
|
|
24227
|
-
updateColumnWidth(
|
|
24228
|
-
|
|
24229
|
-
pluginState2.activeHandle,
|
|
24230
|
-
draggedWidth(pluginState2.dragging, event2, cellMinWidth)
|
|
24231
|
-
);
|
|
24232
|
-
view.dispatch(
|
|
24233
|
-
view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null })
|
|
24234
|
-
);
|
|
24803
|
+
const pluginState$1 = columnResizingPluginKey.getState(view.state);
|
|
24804
|
+
if (pluginState$1 === null || pluginState$1 === void 0 ? void 0 : pluginState$1.dragging) {
|
|
24805
|
+
updateColumnWidth(view, pluginState$1.activeHandle, draggedWidth(pluginState$1.dragging, event$1, cellMinWidth));
|
|
24806
|
+
view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null }));
|
|
24235
24807
|
}
|
|
24236
24808
|
}
|
|
24237
|
-
function move(
|
|
24238
|
-
if (!
|
|
24239
|
-
const
|
|
24240
|
-
if (!
|
|
24241
|
-
if (
|
|
24242
|
-
const dragged = draggedWidth(
|
|
24243
|
-
displayColumnWidth(
|
|
24244
|
-
view,
|
|
24245
|
-
pluginState2.activeHandle,
|
|
24246
|
-
dragged,
|
|
24247
|
-
defaultCellMinWidth
|
|
24248
|
-
);
|
|
24809
|
+
function move(event$1) {
|
|
24810
|
+
if (!event$1.which) return finish(event$1);
|
|
24811
|
+
const pluginState$1 = columnResizingPluginKey.getState(view.state);
|
|
24812
|
+
if (!pluginState$1) return;
|
|
24813
|
+
if (pluginState$1.dragging) {
|
|
24814
|
+
const dragged = draggedWidth(pluginState$1.dragging, event$1, cellMinWidth);
|
|
24815
|
+
displayColumnWidth(view, pluginState$1.activeHandle, dragged, defaultCellMinWidth);
|
|
24249
24816
|
}
|
|
24250
24817
|
}
|
|
24251
|
-
displayColumnWidth(
|
|
24252
|
-
view,
|
|
24253
|
-
pluginState.activeHandle,
|
|
24254
|
-
width,
|
|
24255
|
-
defaultCellMinWidth
|
|
24256
|
-
);
|
|
24818
|
+
displayColumnWidth(view, pluginState.activeHandle, width, defaultCellMinWidth);
|
|
24257
24819
|
win.addEventListener("mouseup", finish);
|
|
24258
24820
|
win.addEventListener("mousemove", move);
|
|
24259
24821
|
event.preventDefault();
|
|
@@ -24263,20 +24825,17 @@ function currentColWidth(view, cellPos, { colspan, colwidth }) {
|
|
|
24263
24825
|
const width = colwidth && colwidth[colwidth.length - 1];
|
|
24264
24826
|
if (width) return width;
|
|
24265
24827
|
const dom = view.domAtPos(cellPos);
|
|
24266
|
-
|
|
24267
|
-
let domWidth = node.offsetWidth, parts = colspan;
|
|
24828
|
+
let domWidth = dom.node.childNodes[dom.offset].offsetWidth, parts = colspan;
|
|
24268
24829
|
if (colwidth) {
|
|
24269
|
-
for (let i = 0; i < colspan; i++)
|
|
24270
|
-
|
|
24271
|
-
|
|
24272
|
-
|
|
24273
|
-
}
|
|
24830
|
+
for (let i = 0; i < colspan; i++) if (colwidth[i]) {
|
|
24831
|
+
domWidth -= colwidth[i];
|
|
24832
|
+
parts--;
|
|
24833
|
+
}
|
|
24274
24834
|
}
|
|
24275
24835
|
return domWidth / parts;
|
|
24276
24836
|
}
|
|
24277
24837
|
function domCellAround(target) {
|
|
24278
|
-
while (target && target.nodeName != "TD" && target.nodeName != "TH")
|
|
24279
|
-
target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
|
|
24838
|
+
while (target && target.nodeName != "TD" && target.nodeName != "TH") target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
|
|
24280
24839
|
return target;
|
|
24281
24840
|
}
|
|
24282
24841
|
function edgeCell(view, event, side, handleWidth) {
|
|
@@ -24299,9 +24858,7 @@ function draggedWidth(dragging, event, resizeMinWidth) {
|
|
|
24299
24858
|
return Math.max(resizeMinWidth, dragging.startWidth + offset2);
|
|
24300
24859
|
}
|
|
24301
24860
|
function updateHandle(view, value) {
|
|
24302
|
-
view.dispatch(
|
|
24303
|
-
view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value })
|
|
24304
|
-
);
|
|
24861
|
+
view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value }));
|
|
24305
24862
|
}
|
|
24306
24863
|
function updateColumnWidth(view, cell, width) {
|
|
24307
24864
|
const $cell = view.state.doc.resolve(cell);
|
|
@@ -24317,7 +24874,10 @@ function updateColumnWidth(view, cell, width) {
|
|
|
24317
24874
|
if (attrs.colwidth && attrs.colwidth[index2] == width) continue;
|
|
24318
24875
|
const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan);
|
|
24319
24876
|
colwidth[index2] = width;
|
|
24320
|
-
tr.setNodeMarkup(start2 + pos, null, {
|
|
24877
|
+
tr.setNodeMarkup(start2 + pos, null, {
|
|
24878
|
+
...attrs,
|
|
24879
|
+
colwidth
|
|
24880
|
+
});
|
|
24321
24881
|
}
|
|
24322
24882
|
if (tr.docChanged) view.dispatch(tr);
|
|
24323
24883
|
}
|
|
@@ -24326,64 +24886,38 @@ function displayColumnWidth(view, cell, width, defaultCellMinWidth) {
|
|
|
24326
24886
|
const table = $cell.node(-1), start2 = $cell.start(-1);
|
|
24327
24887
|
const col = TableMap.get(table).colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
|
|
24328
24888
|
let dom = view.domAtPos($cell.start(-1)).node;
|
|
24329
|
-
while (dom && dom.nodeName != "TABLE")
|
|
24330
|
-
dom = dom.parentNode;
|
|
24331
|
-
}
|
|
24889
|
+
while (dom && dom.nodeName != "TABLE") dom = dom.parentNode;
|
|
24332
24890
|
if (!dom) return;
|
|
24333
|
-
updateColumnsOnResize(
|
|
24334
|
-
table,
|
|
24335
|
-
dom.firstChild,
|
|
24336
|
-
dom,
|
|
24337
|
-
defaultCellMinWidth,
|
|
24338
|
-
col,
|
|
24339
|
-
width
|
|
24340
|
-
);
|
|
24891
|
+
updateColumnsOnResize(table, dom.firstChild, dom, defaultCellMinWidth, col, width);
|
|
24341
24892
|
}
|
|
24342
24893
|
function zeroes(n) {
|
|
24343
24894
|
return Array(n).fill(0);
|
|
24344
24895
|
}
|
|
24345
24896
|
function handleDecorations(state, cell) {
|
|
24346
|
-
var _a;
|
|
24347
24897
|
const decorations = [];
|
|
24348
24898
|
const $cell = state.doc.resolve(cell);
|
|
24349
24899
|
const table = $cell.node(-1);
|
|
24350
|
-
if (!table)
|
|
24351
|
-
return DecorationSet.empty;
|
|
24352
|
-
}
|
|
24900
|
+
if (!table) return DecorationSet.empty;
|
|
24353
24901
|
const map2 = TableMap.get(table);
|
|
24354
24902
|
const start2 = $cell.start(-1);
|
|
24355
24903
|
const col = map2.colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
|
|
24356
24904
|
for (let row = 0; row < map2.height; row++) {
|
|
24357
24905
|
const index2 = col + row * map2.width;
|
|
24358
24906
|
if ((col == map2.width - 1 || map2.map[index2] != map2.map[index2 + 1]) && (row == 0 || map2.map[index2] != map2.map[index2 - map2.width])) {
|
|
24907
|
+
var _columnResizingPlugin;
|
|
24359
24908
|
const cellPos = map2.map[index2];
|
|
24360
24909
|
const pos = start2 + cellPos + table.nodeAt(cellPos).nodeSize - 1;
|
|
24361
24910
|
const dom = document.createElement("div");
|
|
24362
24911
|
dom.className = "column-resize-handle";
|
|
24363
|
-
if ((
|
|
24364
|
-
decorations.push(
|
|
24365
|
-
Decoration.node(
|
|
24366
|
-
start2 + cellPos,
|
|
24367
|
-
start2 + cellPos + table.nodeAt(cellPos).nodeSize,
|
|
24368
|
-
{
|
|
24369
|
-
class: "column-resize-dragging"
|
|
24370
|
-
}
|
|
24371
|
-
)
|
|
24372
|
-
);
|
|
24373
|
-
}
|
|
24912
|
+
if ((_columnResizingPlugin = columnResizingPluginKey.getState(state)) === null || _columnResizingPlugin === void 0 ? void 0 : _columnResizingPlugin.dragging) decorations.push(Decoration.node(start2 + cellPos, start2 + cellPos + table.nodeAt(cellPos).nodeSize, { class: "column-resize-dragging" }));
|
|
24374
24913
|
decorations.push(Decoration.widget(pos, dom));
|
|
24375
24914
|
}
|
|
24376
24915
|
}
|
|
24377
24916
|
return DecorationSet.create(state.doc, decorations);
|
|
24378
24917
|
}
|
|
24379
|
-
function tableEditing({
|
|
24380
|
-
allowTableNodeSelection = false
|
|
24381
|
-
} = {}) {
|
|
24918
|
+
function tableEditing({ allowTableNodeSelection = false } = {}) {
|
|
24382
24919
|
return new Plugin({
|
|
24383
24920
|
key: tableEditingKey,
|
|
24384
|
-
// This piece of state is used to remember when a mouse-drag
|
|
24385
|
-
// cell-selection is happening, so that it can continue even as
|
|
24386
|
-
// transactions (which might move its anchor cell) come in.
|
|
24387
24921
|
state: {
|
|
24388
24922
|
init() {
|
|
24389
24923
|
return null;
|
|
@@ -24398,9 +24932,7 @@ function tableEditing({
|
|
|
24398
24932
|
},
|
|
24399
24933
|
props: {
|
|
24400
24934
|
decorations: drawCellSelection,
|
|
24401
|
-
handleDOMEvents: {
|
|
24402
|
-
mousedown: handleMouseDown
|
|
24403
|
-
},
|
|
24935
|
+
handleDOMEvents: { mousedown: handleMouseDown },
|
|
24404
24936
|
createSelectionBetween(view) {
|
|
24405
24937
|
return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
|
|
24406
24938
|
},
|
|
@@ -24409,11 +24941,7 @@ function tableEditing({
|
|
|
24409
24941
|
handlePaste
|
|
24410
24942
|
},
|
|
24411
24943
|
appendTransaction(_, oldState, state) {
|
|
24412
|
-
return normalizeSelection(
|
|
24413
|
-
state,
|
|
24414
|
-
fixTables(state, oldState),
|
|
24415
|
-
allowTableNodeSelection
|
|
24416
|
-
);
|
|
24944
|
+
return normalizeSelection(state, fixTables(state, oldState), allowTableNodeSelection);
|
|
24417
24945
|
}
|
|
24418
24946
|
});
|
|
24419
24947
|
}
|
|
@@ -24438,12 +24966,12 @@ const deleteTableWhenSelected = ({ editor }) => {
|
|
|
24438
24966
|
editor.commands.deleteTable();
|
|
24439
24967
|
return true;
|
|
24440
24968
|
};
|
|
24441
|
-
const createCellBorders = ({ size = 0.66665, color = "#000000" } = {}) => {
|
|
24969
|
+
const createCellBorders = ({ size: size2 = 0.66665, color = "#000000" } = {}) => {
|
|
24442
24970
|
return {
|
|
24443
|
-
top: { size, color },
|
|
24444
|
-
left: { size, color },
|
|
24445
|
-
bottom: { size, color },
|
|
24446
|
-
right: { size, color }
|
|
24971
|
+
top: { size: size2, color },
|
|
24972
|
+
left: { size: size2, color },
|
|
24973
|
+
bottom: { size: size2, color },
|
|
24974
|
+
right: { size: size2, color }
|
|
24447
24975
|
};
|
|
24448
24976
|
};
|
|
24449
24977
|
function cellAround($pos) {
|
|
@@ -24624,8 +25152,8 @@ const Table = Node$1.create({
|
|
|
24624
25152
|
default: {},
|
|
24625
25153
|
renderDOM({ borders }) {
|
|
24626
25154
|
if (!borders) return {};
|
|
24627
|
-
const style = Object.entries(borders).reduce((acc, [key2, { size, color }]) => {
|
|
24628
|
-
return `${acc}border-${key2}: ${Math.ceil(
|
|
25155
|
+
const style = Object.entries(borders).reduce((acc, [key2, { size: size2, color }]) => {
|
|
25156
|
+
return `${acc}border-${key2}: ${Math.ceil(size2)}px solid ${color || "black"};`;
|
|
24629
25157
|
}, "");
|
|
24630
25158
|
return {
|
|
24631
25159
|
style
|
|
@@ -24747,8 +25275,8 @@ const Table = Node$1.create({
|
|
|
24747
25275
|
let resolvedTablePos = tablePos;
|
|
24748
25276
|
if (typeof resolvedTablePos !== "number" && workingTable) {
|
|
24749
25277
|
const tables = editor.getNodesOfType("table");
|
|
24750
|
-
const
|
|
24751
|
-
resolvedTablePos =
|
|
25278
|
+
const match2 = workingTable ? tables.find((t) => t.node.eq(workingTable)) : tables[0];
|
|
25279
|
+
resolvedTablePos = match2?.pos ?? null;
|
|
24752
25280
|
}
|
|
24753
25281
|
if (typeof resolvedTablePos !== "number") {
|
|
24754
25282
|
return false;
|
|
@@ -26404,9 +26932,9 @@ const FieldAnnotation = Node$1.create({
|
|
|
26404
26932
|
},
|
|
26405
26933
|
size: {
|
|
26406
26934
|
default: null,
|
|
26407
|
-
renderDOM: ({ size }) => {
|
|
26408
|
-
if (!
|
|
26409
|
-
const style = `width: ${
|
|
26935
|
+
renderDOM: ({ size: size2 }) => {
|
|
26936
|
+
if (!size2 || !size2.width) return {};
|
|
26937
|
+
const style = `width: ${size2.width}px; height: ${size2.height}px; overflow: hidden;`;
|
|
26410
26938
|
return { style };
|
|
26411
26939
|
}
|
|
26412
26940
|
},
|
|
@@ -27526,7 +28054,7 @@ const generateUniqueDocPrId = (editor) => {
|
|
|
27526
28054
|
} while (!candidate || existingIds.has(candidate));
|
|
27527
28055
|
return candidate;
|
|
27528
28056
|
};
|
|
27529
|
-
async function uploadAndInsertImage({ editor, view, file, size, id }) {
|
|
28057
|
+
async function uploadAndInsertImage({ editor, view, file, size: size2, id }) {
|
|
27530
28058
|
const imageUploadHandler = typeof editor.options.handleImageUpload === "function" ? editor.options.handleImageUpload : handleImageUpload;
|
|
27531
28059
|
const placeholderId = id;
|
|
27532
28060
|
try {
|
|
@@ -27551,7 +28079,7 @@ async function uploadAndInsertImage({ editor, view, file, size, id }) {
|
|
|
27551
28079
|
}
|
|
27552
28080
|
let imageNode = view.state.schema.nodes.image.create({
|
|
27553
28081
|
src: mediaPath,
|
|
27554
|
-
size,
|
|
28082
|
+
size: size2,
|
|
27555
28083
|
id: docPrId,
|
|
27556
28084
|
rId
|
|
27557
28085
|
});
|
|
@@ -27842,7 +28370,7 @@ const getImagePositionDecorations = (state, view) => {
|
|
|
27842
28370
|
let style = "";
|
|
27843
28371
|
let className = "";
|
|
27844
28372
|
const { vRelativeFrom, alignH } = node.attrs.anchorData;
|
|
27845
|
-
const { size, padding } = node.attrs;
|
|
28373
|
+
const { size: size2, padding } = node.attrs;
|
|
27846
28374
|
const pageBreak = findPreviousDomNodeWithClass(view, pos, "pagination-break-wrapper");
|
|
27847
28375
|
if (pageBreak && vRelativeFrom === "margin" && alignH) {
|
|
27848
28376
|
let pageBreakPos = pageBreakPositionCache.get(pageBreak);
|
|
@@ -27862,7 +28390,7 @@ const getImagePositionDecorations = (state, view) => {
|
|
|
27862
28390
|
const $pos = view.state.doc.resolve(pos);
|
|
27863
28391
|
decorations.push(
|
|
27864
28392
|
Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
|
|
27865
|
-
style: `height: ${
|
|
28393
|
+
style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
|
|
27866
28394
|
})
|
|
27867
28395
|
);
|
|
27868
28396
|
}
|
|
@@ -27875,8 +28403,8 @@ const getImagePositionDecorations = (state, view) => {
|
|
|
27875
28403
|
} else {
|
|
27876
28404
|
paddingHorizontal = parseInt(padding[alignH]) || 0;
|
|
27877
28405
|
}
|
|
27878
|
-
imageBlock.style.width =
|
|
27879
|
-
imageBlock.style.height =
|
|
28406
|
+
imageBlock.style.width = size2.width + paddingHorizontal + "px";
|
|
28407
|
+
imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
|
|
27880
28408
|
decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
|
|
27881
28409
|
decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style, class: className }));
|
|
27882
28410
|
}
|
|
@@ -28080,9 +28608,9 @@ const Image = Node$1.create({
|
|
|
28080
28608
|
extension: { rendered: false },
|
|
28081
28609
|
size: {
|
|
28082
28610
|
default: {},
|
|
28083
|
-
renderDOM: ({ size, extension }) => {
|
|
28611
|
+
renderDOM: ({ size: size2, extension }) => {
|
|
28084
28612
|
let style = "";
|
|
28085
|
-
let { width, height } =
|
|
28613
|
+
let { width, height } = size2 ?? {};
|
|
28086
28614
|
if (width) style += `width: ${width}px;`;
|
|
28087
28615
|
if (height && ["emf", "wmf"].includes(extension))
|
|
28088
28616
|
style += `height: ${height}px; border: 1px solid black; position: absolute;`;
|
|
@@ -28119,7 +28647,7 @@ const Image = Node$1.create({
|
|
|
28119
28647
|
},
|
|
28120
28648
|
renderDOM({ node, htmlAttributes }) {
|
|
28121
28649
|
const { wrap, marginOffset } = getNormalizedImageAttrs(node.attrs);
|
|
28122
|
-
const { anchorData, padding, transformData = {}, size = { width: 0, height: 0 } } = node.attrs;
|
|
28650
|
+
const { anchorData, padding, transformData = {}, size: size2 = { width: 0, height: 0 } } = node.attrs;
|
|
28123
28651
|
const margin = {
|
|
28124
28652
|
left: 0,
|
|
28125
28653
|
right: 0,
|
|
@@ -28137,7 +28665,7 @@ const Image = Node$1.create({
|
|
|
28137
28665
|
if (padding.bottom) margin.bottom += padding.bottom;
|
|
28138
28666
|
}
|
|
28139
28667
|
const { rotation } = transformData;
|
|
28140
|
-
const { height, width } =
|
|
28668
|
+
const { height, width } = size2;
|
|
28141
28669
|
if (rotation && height && width) {
|
|
28142
28670
|
const { horizontal, vertical } = getRotationMargins(width, height, rotation);
|
|
28143
28671
|
margin.left += horizontal;
|
|
@@ -28167,7 +28695,7 @@ const Image = Node$1.create({
|
|
|
28167
28695
|
const pageStylesData = getDataFromPageStyles({
|
|
28168
28696
|
editor: this.editor,
|
|
28169
28697
|
marginOffset,
|
|
28170
|
-
size,
|
|
28698
|
+
size: size2,
|
|
28171
28699
|
attrs
|
|
28172
28700
|
});
|
|
28173
28701
|
style += pageStylesData.style;
|
|
@@ -28185,7 +28713,7 @@ const Image = Node$1.create({
|
|
|
28185
28713
|
const pageStylesData = getDataFromPageStyles({
|
|
28186
28714
|
editor: this.editor,
|
|
28187
28715
|
marginOffset,
|
|
28188
|
-
size,
|
|
28716
|
+
size: size2,
|
|
28189
28717
|
attrs
|
|
28190
28718
|
});
|
|
28191
28719
|
style += pageStylesData.style;
|
|
@@ -28210,8 +28738,8 @@ const Image = Node$1.create({
|
|
|
28210
28738
|
});
|
|
28211
28739
|
const originalWidth = maxX - minX;
|
|
28212
28740
|
const originalHeight = maxY - minY;
|
|
28213
|
-
const scaleWidth = Math.min(1,
|
|
28214
|
-
const scaleHeight = Math.min(1,
|
|
28741
|
+
const scaleWidth = Math.min(1, size2.width / originalWidth);
|
|
28742
|
+
const scaleHeight = Math.min(1, size2.height / originalHeight);
|
|
28215
28743
|
const verticalOffset = Math.max(0, marginOffset.top);
|
|
28216
28744
|
const points = attrs.polygon.map(([x, y]) => `${horizontalOffset + x * scaleWidth}px ${verticalOffset + y * scaleHeight}px`).join(", ");
|
|
28217
28745
|
style += `shape-outside: polygon(${points});`;
|
|
@@ -28267,7 +28795,7 @@ const Image = Node$1.create({
|
|
|
28267
28795
|
let rotationHorizontal = 0;
|
|
28268
28796
|
let rotationTop = 0;
|
|
28269
28797
|
const { rotation: rotation2 } = transformData ?? {};
|
|
28270
|
-
const { height: height2, width: width2 } =
|
|
28798
|
+
const { height: height2, width: width2 } = size2 ?? {};
|
|
28271
28799
|
if (rotation2 && height2 && width2) {
|
|
28272
28800
|
const { horizontal: horizontal2, vertical } = getRotationMargins(width2, height2, rotation2);
|
|
28273
28801
|
rotationHorizontal = horizontal2;
|
|
@@ -28408,17 +28936,17 @@ const Image = Node$1.create({
|
|
|
28408
28936
|
return [ImageRegistrationPlugin({ editor: this.editor }), ImagePositionPlugin({ editor: this.editor })];
|
|
28409
28937
|
}
|
|
28410
28938
|
});
|
|
28411
|
-
const getDataFromPageStyles = ({ editor, marginOffset, size, attrs }) => {
|
|
28939
|
+
const getDataFromPageStyles = ({ editor, marginOffset, size: size2, attrs }) => {
|
|
28412
28940
|
let style = "";
|
|
28413
28941
|
let floatRight = false;
|
|
28414
28942
|
let baseHorizontal = marginOffset?.horizontal || 0;
|
|
28415
28943
|
const pageStyles = editor?.converter?.pageStyles || editor?.options.parentEditor?.converter?.pageStyles;
|
|
28416
|
-
if (pageStyles?.pageSize && pageStyles?.pageMargins &&
|
|
28944
|
+
if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
|
|
28417
28945
|
const pageWidth = inchesToPixels(pageStyles.pageSize.width);
|
|
28418
28946
|
const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
|
|
28419
28947
|
const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
|
|
28420
28948
|
const contentWidth = pageWidth - leftMargin - rightMargin;
|
|
28421
|
-
const imageWidth =
|
|
28949
|
+
const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
|
|
28422
28950
|
const leftSpace = marginOffset.horizontal;
|
|
28423
28951
|
const rightSpace = contentWidth - leftSpace - imageWidth;
|
|
28424
28952
|
if (rightSpace < 0) {
|
|
@@ -29112,14 +29640,14 @@ const ContentBlock = Node$1.create({
|
|
|
29112
29640
|
},
|
|
29113
29641
|
size: {
|
|
29114
29642
|
default: null,
|
|
29115
|
-
renderDOM: ({ size }) => {
|
|
29116
|
-
if (!
|
|
29643
|
+
renderDOM: ({ size: size2 }) => {
|
|
29644
|
+
if (!size2) return {};
|
|
29117
29645
|
let style = "";
|
|
29118
|
-
if (
|
|
29119
|
-
if (
|
|
29120
|
-
if (
|
|
29121
|
-
if (
|
|
29122
|
-
style += `height: ${
|
|
29646
|
+
if (size2.top) style += `top: ${size2.top}px; `;
|
|
29647
|
+
if (size2.left) style += `left: ${size2.left}px; `;
|
|
29648
|
+
if (size2.width) style += `width: ${size2.width.toString().endsWith("%") ? size2.width : `${size2.width}px`}; `;
|
|
29649
|
+
if (size2.height)
|
|
29650
|
+
style += `height: ${size2.height.toString().endsWith("%") ? size2.height : `${size2.height}px`}; `;
|
|
29123
29651
|
return { style };
|
|
29124
29652
|
}
|
|
29125
29653
|
},
|
|
@@ -31834,12 +32362,12 @@ class ShapeGroupView {
|
|
|
31834
32362
|
}
|
|
31835
32363
|
createElement() {
|
|
31836
32364
|
const attrs = this.node.attrs;
|
|
31837
|
-
const { groupTransform, shapes, size } = attrs;
|
|
32365
|
+
const { groupTransform, shapes, size: size2 } = attrs;
|
|
31838
32366
|
const container = document.createElement("div");
|
|
31839
32367
|
container.classList.add("sd-shape-group");
|
|
31840
32368
|
container.setAttribute("data-shape-group", "");
|
|
31841
|
-
const width =
|
|
31842
|
-
const height =
|
|
32369
|
+
const width = size2?.width || groupTransform?.width || 300;
|
|
32370
|
+
const height = size2?.height || groupTransform?.height || 200;
|
|
31843
32371
|
container.style.width = `${width}px`;
|
|
31844
32372
|
container.style.height = `${height}px`;
|
|
31845
32373
|
container.style.position = "relative";
|
|
@@ -36303,8 +36831,8 @@ class Popover {
|
|
|
36303
36831
|
if (from2 < 1) return false;
|
|
36304
36832
|
const textBefore = this.getMentionText(from2);
|
|
36305
36833
|
const mentionPattern = /(?:^|\s)@[\w]*$/;
|
|
36306
|
-
const
|
|
36307
|
-
return
|
|
36834
|
+
const match2 = textBefore.match(mentionPattern);
|
|
36835
|
+
return match2 && this.state.selection.empty;
|
|
36308
36836
|
}
|
|
36309
36837
|
destroy() {
|
|
36310
36838
|
this.tippyInstance.destroy();
|
|
@@ -36812,10 +37340,10 @@ function getScale(element) {
|
|
|
36812
37340
|
const {
|
|
36813
37341
|
width,
|
|
36814
37342
|
height,
|
|
36815
|
-
$
|
|
37343
|
+
$: $2
|
|
36816
37344
|
} = getCssDimensions(domElement);
|
|
36817
|
-
let x = ($ ? round(rect.width) : rect.width) / width;
|
|
36818
|
-
let y = ($ ? round(rect.height) : rect.height) / height;
|
|
37345
|
+
let x = ($2 ? round(rect.width) : rect.width) / width;
|
|
37346
|
+
let y = ($2 ? round(rect.height) : rect.height) / height;
|
|
36819
37347
|
if (!x || !Number.isFinite(x)) {
|
|
36820
37348
|
x = 1;
|
|
36821
37349
|
}
|
|
@@ -38156,8 +38684,8 @@ class SearchQuery {
|
|
|
38156
38684
|
let $from = state.doc.resolve(result.from);
|
|
38157
38685
|
let marks = $from.marksAcross(state.doc.resolve(result.to));
|
|
38158
38686
|
let ranges = [];
|
|
38159
|
-
let frag = Fragment.empty, pos = result.from, { match } = result;
|
|
38160
|
-
let groups =
|
|
38687
|
+
let frag = Fragment.empty, pos = result.from, { match: match2 } = result;
|
|
38688
|
+
let groups = match2 ? getGroupIndices(match2) : [[0, result.to - result.from]];
|
|
38161
38689
|
let replParts = parseReplacement(this.unquote(this.replace));
|
|
38162
38690
|
for (let part of replParts) {
|
|
38163
38691
|
if (typeof part == "string") {
|
|
@@ -38235,39 +38763,39 @@ class RegExpQuery {
|
|
|
38235
38763
|
return scanTextblocks(state.doc, from2, to, (node, start2) => {
|
|
38236
38764
|
let content = textContent(node).slice(0, Math.min(node.content.size, to - start2));
|
|
38237
38765
|
this.regexp.lastIndex = from2 - start2;
|
|
38238
|
-
let
|
|
38239
|
-
if (!
|
|
38240
|
-
const absoluteIndex =
|
|
38766
|
+
let match2 = this.regexp.exec(content);
|
|
38767
|
+
if (!match2) return null;
|
|
38768
|
+
const absoluteIndex = match2.index;
|
|
38241
38769
|
const fromPos = mapIndexToDocPos(node, start2, absoluteIndex);
|
|
38242
|
-
const toPos = mapIndexToDocPos(node, start2, absoluteIndex +
|
|
38243
|
-
return { from: fromPos, to: toPos, match, matchStart: start2 };
|
|
38770
|
+
const toPos = mapIndexToDocPos(node, start2, absoluteIndex + match2[0].length);
|
|
38771
|
+
return { from: fromPos, to: toPos, match: match2, matchStart: start2 };
|
|
38244
38772
|
});
|
|
38245
38773
|
}
|
|
38246
38774
|
findPrev(state, from2, to) {
|
|
38247
38775
|
return scanTextblocks(state.doc, from2, to, (node, start2) => {
|
|
38248
38776
|
let content = textContent(node).slice(0, Math.min(node.content.size, from2 - start2));
|
|
38249
|
-
let
|
|
38777
|
+
let match2;
|
|
38250
38778
|
for (let off = 0; ; ) {
|
|
38251
38779
|
this.regexp.lastIndex = off;
|
|
38252
38780
|
let next = this.regexp.exec(content);
|
|
38253
38781
|
if (!next) break;
|
|
38254
|
-
|
|
38782
|
+
match2 = next;
|
|
38255
38783
|
off = next.index + 1;
|
|
38256
38784
|
}
|
|
38257
|
-
if (!
|
|
38258
|
-
const absoluteIndex =
|
|
38785
|
+
if (!match2) return null;
|
|
38786
|
+
const absoluteIndex = match2.index;
|
|
38259
38787
|
const fromPos = mapIndexToDocPos(node, start2, absoluteIndex);
|
|
38260
|
-
const toPos = mapIndexToDocPos(node, start2, absoluteIndex +
|
|
38261
|
-
return { from: fromPos, to: toPos, match, matchStart: start2 };
|
|
38788
|
+
const toPos = mapIndexToDocPos(node, start2, absoluteIndex + match2[0].length);
|
|
38789
|
+
return { from: fromPos, to: toPos, match: match2, matchStart: start2 };
|
|
38262
38790
|
});
|
|
38263
38791
|
}
|
|
38264
38792
|
}
|
|
38265
|
-
function getGroupIndices(
|
|
38266
|
-
if (
|
|
38267
|
-
let result = [[0,
|
|
38268
|
-
for (let i = 1, pos = 0; i <
|
|
38269
|
-
let found =
|
|
38270
|
-
result.push(found < 0 ? void 0 : [found, pos = found +
|
|
38793
|
+
function getGroupIndices(match2) {
|
|
38794
|
+
if (match2.indices) return match2.indices;
|
|
38795
|
+
let result = [[0, match2[0].length]];
|
|
38796
|
+
for (let i = 1, pos = 0; i < match2.length; i++) {
|
|
38797
|
+
let found = match2[i] ? match2[0].indexOf(match2[i], pos) : -1;
|
|
38798
|
+
result.push(found < 0 ? void 0 : [found, pos = found + match2[i].length]);
|
|
38271
38799
|
}
|
|
38272
38800
|
return result;
|
|
38273
38801
|
}
|
|
@@ -38508,8 +39036,8 @@ const Search = Extension.create({
|
|
|
38508
39036
|
const matches = storage?.searchResults;
|
|
38509
39037
|
if (!matches?.length) return null;
|
|
38510
39038
|
const decorations = matches.map(
|
|
38511
|
-
(
|
|
38512
|
-
id: `search-match-${
|
|
39039
|
+
(match2) => Decoration.inline(match2.from, match2.to, {
|
|
39040
|
+
id: `search-match-${match2.id}`
|
|
38513
39041
|
})
|
|
38514
39042
|
);
|
|
38515
39043
|
return DecorationSet.create(state.doc, decorations);
|
|
@@ -38613,10 +39141,10 @@ const Search = Extension.create({
|
|
|
38613
39141
|
* editor.commands.goToSearchResult(searchResults[3])
|
|
38614
39142
|
* @note Scrolls to match and selects it
|
|
38615
39143
|
*/
|
|
38616
|
-
goToSearchResult: (
|
|
39144
|
+
goToSearchResult: (match2) => (
|
|
38617
39145
|
/** @returns {boolean} */
|
|
38618
39146
|
({ state, dispatch, editor }) => {
|
|
38619
|
-
const { from: from2, to } =
|
|
39147
|
+
const { from: from2, to } = match2;
|
|
38620
39148
|
editor.view.focus();
|
|
38621
39149
|
const tr = state.tr.setSelection(TextSelection.create(state.doc, from2, to)).scrollIntoView();
|
|
38622
39150
|
dispatch(tr);
|