superdoc 0.36.0 → 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-Cw6hrjmI.es.js → PdfViewer-0ljQHJ46.es.js} +2 -2
- package/dist/chunks/{PdfViewer-BVjCijQM.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-C6pGFRDv-NmZ85_ZC.es.js → index-CzkLnJsZ-BTVdUMdV.es.js} +1 -1
- package/dist/chunks/{index-C6pGFRDv-DPPxKqzz.cjs → index-CzkLnJsZ-BgswlBSf.cjs} +1 -1
- package/dist/chunks/{index-C2I7v8Mz.cjs → index-D3qTp4tj.cjs} +20 -15
- package/dist/chunks/{index-DxVLb2GI.es.js → index-DzR1O6RL.es.js} +20 -15
- 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-DU7fPHu1.cjs → super-editor.es-DVKZ65HN.cjs} +2129 -1653
- package/dist/chunks/{super-editor.es-wvWKJiSQ.es.js → super-editor.es-D_ayGwNx.es.js} +2082 -1606
- 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.map +1 -1
- package/dist/packages/superdoc/src/core/types/index.d.ts.map +1 -1
- package/dist/super-editor/ai-writer.es.js +2 -2
- package/dist/super-editor/chunks/{converter-B_MV8Ifd.js → converter-C_m22GDt.js} +311 -292
- package/dist/super-editor/chunks/{docx-zipper-BErVQPhm.js → docx-zipper-BMFQCW01.js} +1 -1
- package/dist/super-editor/chunks/{editor-DJdDJYe1.js → editor-DOp2dsXA.js} +1413 -956
- package/dist/super-editor/chunks/{index-C6pGFRDv.js → index-CzkLnJsZ.js} +1 -1
- package/dist/super-editor/chunks/{toolbar-C3z7Pv8Z.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/super-editor/src/extensions/track-changes/permission-helpers.d.ts.map +1 -1
- package/dist/super-editor/super-editor.es.js +6 -6
- 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 +2574 -2035
- 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, 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;
|
|
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) => {
|
|
@@ -15264,7 +16136,7 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
15264
16136
|
{ default: remarkStringify },
|
|
15265
16137
|
{ default: remarkGfm }
|
|
15266
16138
|
] = await Promise.all([
|
|
15267
|
-
import("./index-
|
|
16139
|
+
import("./index-CzkLnJsZ.js"),
|
|
15268
16140
|
import("./index-DRCvimau.js"),
|
|
15269
16141
|
import("./index-C_x_N6Uh.js"),
|
|
15270
16142
|
import("./index-D_sWOSiG.js"),
|
|
@@ -15482,7 +16354,7 @@ const _Editor = class _Editor extends EventEmitter {
|
|
|
15482
16354
|
* @returns {Object | void} Migration results
|
|
15483
16355
|
*/
|
|
15484
16356
|
processCollaborationMigrations() {
|
|
15485
|
-
console.debug("[checkVersionMigrations] Current editor version", "0.36.
|
|
16357
|
+
console.debug("[checkVersionMigrations] Current editor version", "0.36.1");
|
|
15486
16358
|
if (!this.options.ydoc) return;
|
|
15487
16359
|
const metaMap = this.options.ydoc.getMap("meta");
|
|
15488
16360
|
let docVersion = metaMap.get("version");
|
|
@@ -16837,12 +17709,12 @@ function dropCursor(options = {}) {
|
|
|
16837
17709
|
}
|
|
16838
17710
|
class DropCursorView {
|
|
16839
17711
|
constructor(editorView, options) {
|
|
16840
|
-
var
|
|
17712
|
+
var _a2;
|
|
16841
17713
|
this.editorView = editorView;
|
|
16842
17714
|
this.cursorPos = null;
|
|
16843
17715
|
this.element = null;
|
|
16844
17716
|
this.timeout = -1;
|
|
16845
|
-
this.width = (
|
|
17717
|
+
this.width = (_a2 = options.width) !== null && _a2 !== void 0 ? _a2 : 1;
|
|
16846
17718
|
this.color = options.color === false ? void 0 : options.color || "black";
|
|
16847
17719
|
this.class = options.class;
|
|
16848
17720
|
this.handlers = ["dragover", "dragend", "drop", "dragleave"].map((name) => {
|
|
@@ -18990,7 +19862,7 @@ const Document = Node$1.create({
|
|
|
18990
19862
|
*/
|
|
18991
19863
|
getDocumentStats: () => ({ editor }) => {
|
|
18992
19864
|
const text = editor.getText();
|
|
18993
|
-
const words = text.split(/\s+/).filter((
|
|
19865
|
+
const words = text.split(/\s+/).filter((word2) => word2.length > 0).length;
|
|
18994
19866
|
const characters = text.length;
|
|
18995
19867
|
const paragraphs = editor.state.doc.content.childCount;
|
|
18996
19868
|
return {
|
|
@@ -19397,9 +20269,9 @@ const ordinalFormatter = (level) => {
|
|
|
19397
20269
|
};
|
|
19398
20270
|
const generateFromCustom = (path, lvlText, customFormat) => {
|
|
19399
20271
|
if (customFormat !== "001, 002, 003, ...") return generateNumbering(path, lvlText, String);
|
|
19400
|
-
const
|
|
19401
|
-
if (!
|
|
19402
|
-
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];
|
|
19403
20275
|
const digitCount = sample.length;
|
|
19404
20276
|
const index2 = path.pop();
|
|
19405
20277
|
return String(index2).padStart(digitCount, "0");
|
|
@@ -21768,9 +22640,9 @@ function calculateIndentFallback(indentAttrs = {}) {
|
|
|
21768
22640
|
} else if (hanging) {
|
|
21769
22641
|
textIndent = -hanging;
|
|
21770
22642
|
} else if (typeof indentAttrs.textIndent === "string") {
|
|
21771
|
-
const
|
|
21772
|
-
if (
|
|
21773
|
-
textIndent = Number(
|
|
22643
|
+
const match2 = indentAttrs.textIndent.match(/(-?\d*\.?\d+)in$/);
|
|
22644
|
+
if (match2) {
|
|
22645
|
+
textIndent = Number(match2[1]) * 96;
|
|
21774
22646
|
}
|
|
21775
22647
|
}
|
|
21776
22648
|
if (textIndent) return left2 + textIndent;
|
|
@@ -22247,14 +23119,14 @@ const createCell = (cellType, cellContent = null) => {
|
|
|
22247
23119
|
}
|
|
22248
23120
|
return cellType.createAndFill();
|
|
22249
23121
|
};
|
|
22250
|
-
const createTableBorders = ({ size = 0.66665, color = "#000000" } = {}) => {
|
|
23122
|
+
const createTableBorders = ({ size: size2 = 0.66665, color = "#000000" } = {}) => {
|
|
22251
23123
|
return {
|
|
22252
|
-
top: { size, color },
|
|
22253
|
-
left: { size, color },
|
|
22254
|
-
bottom: { size, color },
|
|
22255
|
-
right: { size, color },
|
|
22256
|
-
insideH: { size, color },
|
|
22257
|
-
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 }
|
|
22258
23130
|
};
|
|
22259
23131
|
};
|
|
22260
23132
|
const createTable = (schema, rowsCount, colsCount, withHeaderRow, cellContent = null) => {
|
|
@@ -22352,8 +23224,8 @@ const createColGroup = (node, cellMinWidth, overrideCol, overrideValue) => {
|
|
|
22352
23224
|
colgroupValues
|
|
22353
23225
|
};
|
|
22354
23226
|
};
|
|
22355
|
-
|
|
22356
|
-
|
|
23227
|
+
let readFromCache;
|
|
23228
|
+
let addToCache;
|
|
22357
23229
|
if (typeof WeakMap != "undefined") {
|
|
22358
23230
|
let cache = /* @__PURE__ */ new WeakMap();
|
|
22359
23231
|
readFromCache = (key2) => cache.get(key2);
|
|
@@ -22366,8 +23238,7 @@ if (typeof WeakMap != "undefined") {
|
|
|
22366
23238
|
const cacheSize = 10;
|
|
22367
23239
|
let cachePos = 0;
|
|
22368
23240
|
readFromCache = (key2) => {
|
|
22369
|
-
for (let i = 0; i < cache.length; i += 2)
|
|
22370
|
-
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];
|
|
22371
23242
|
};
|
|
22372
23243
|
addToCache = (key2, value) => {
|
|
22373
23244
|
if (cachePos == cacheSize) cachePos = 0;
|
|
@@ -22382,7 +23253,6 @@ var TableMap = class {
|
|
|
22382
23253
|
this.map = map2;
|
|
22383
23254
|
this.problems = problems;
|
|
22384
23255
|
}
|
|
22385
|
-
// Find the dimensions of the cell at the given position.
|
|
22386
23256
|
findCell(pos) {
|
|
22387
23257
|
for (let i = 0; i < this.map.length; i++) {
|
|
22388
23258
|
const curPos = this.map[i];
|
|
@@ -22391,27 +23261,21 @@ var TableMap = class {
|
|
|
22391
23261
|
const top2 = i / this.width | 0;
|
|
22392
23262
|
let right2 = left2 + 1;
|
|
22393
23263
|
let bottom2 = top2 + 1;
|
|
22394
|
-
for (let j = 1; right2 < this.width && this.map[i + j] == curPos; j++)
|
|
22395
|
-
|
|
22396
|
-
|
|
22397
|
-
|
|
22398
|
-
|
|
22399
|
-
|
|
22400
|
-
|
|
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
|
+
};
|
|
22401
23272
|
}
|
|
22402
23273
|
throw new RangeError(`No cell with offset ${pos} found`);
|
|
22403
23274
|
}
|
|
22404
|
-
// Find the left side of the cell at the given position.
|
|
22405
23275
|
colCount(pos) {
|
|
22406
|
-
for (let i = 0; i < this.map.length; i++)
|
|
22407
|
-
if (this.map[i] == pos) {
|
|
22408
|
-
return i % this.width;
|
|
22409
|
-
}
|
|
22410
|
-
}
|
|
23276
|
+
for (let i = 0; i < this.map.length; i++) if (this.map[i] == pos) return i % this.width;
|
|
22411
23277
|
throw new RangeError(`No cell with offset ${pos} found`);
|
|
22412
23278
|
}
|
|
22413
|
-
// Find the next cell in the given direction, starting from the cell
|
|
22414
|
-
// at `pos`, if any.
|
|
22415
23279
|
nextCell(pos, axis, dir) {
|
|
22416
23280
|
const { left: left2, right: right2, top: top2, bottom: bottom2 } = this.findCell(pos);
|
|
22417
23281
|
if (axis == "horiz") {
|
|
@@ -22422,20 +23286,9 @@ var TableMap = class {
|
|
|
22422
23286
|
return this.map[left2 + this.width * (dir < 0 ? top2 - 1 : bottom2)];
|
|
22423
23287
|
}
|
|
22424
23288
|
}
|
|
22425
|
-
// Get the rectangle spanning the two given cells.
|
|
22426
23289
|
rectBetween(a, b) {
|
|
22427
|
-
const {
|
|
22428
|
-
|
|
22429
|
-
right: rightA,
|
|
22430
|
-
top: topA,
|
|
22431
|
-
bottom: bottomA
|
|
22432
|
-
} = this.findCell(a);
|
|
22433
|
-
const {
|
|
22434
|
-
left: leftB,
|
|
22435
|
-
right: rightB,
|
|
22436
|
-
top: topB,
|
|
22437
|
-
bottom: bottomB
|
|
22438
|
-
} = 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);
|
|
22439
23292
|
return {
|
|
22440
23293
|
left: Math.min(leftA, leftB),
|
|
22441
23294
|
top: Math.min(topA, topB),
|
|
@@ -22443,27 +23296,19 @@ var TableMap = class {
|
|
|
22443
23296
|
bottom: Math.max(bottomA, bottomB)
|
|
22444
23297
|
};
|
|
22445
23298
|
}
|
|
22446
|
-
// Return the position of all cells that have the top left corner in
|
|
22447
|
-
// the given rectangle.
|
|
22448
23299
|
cellsInRect(rect) {
|
|
22449
23300
|
const result = [];
|
|
22450
23301
|
const seen = {};
|
|
22451
|
-
for (let row = rect.top; row < rect.bottom; row++) {
|
|
22452
|
-
|
|
22453
|
-
|
|
22454
|
-
|
|
22455
|
-
|
|
22456
|
-
|
|
22457
|
-
|
|
22458
|
-
continue;
|
|
22459
|
-
}
|
|
22460
|
-
result.push(pos);
|
|
22461
|
-
}
|
|
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);
|
|
22462
23309
|
}
|
|
22463
23310
|
return result;
|
|
22464
23311
|
}
|
|
22465
|
-
// Return the position at which the cell at the given row and column
|
|
22466
|
-
// starts, or would start, if a cell started there.
|
|
22467
23312
|
positionAt(row, col, table) {
|
|
22468
23313
|
for (let i = 0, rowStart = 0; ; i++) {
|
|
22469
23314
|
const rowEnd = rowStart + table.child(i).nodeSize;
|
|
@@ -22476,14 +23321,12 @@ var TableMap = class {
|
|
|
22476
23321
|
rowStart = rowEnd;
|
|
22477
23322
|
}
|
|
22478
23323
|
}
|
|
22479
|
-
// Find the table map for the given table node.
|
|
22480
23324
|
static get(table) {
|
|
22481
23325
|
return readFromCache(table) || addToCache(table, computeMap(table));
|
|
22482
23326
|
}
|
|
22483
23327
|
};
|
|
22484
23328
|
function computeMap(table) {
|
|
22485
|
-
if (table.type.spec.tableRole != "table")
|
|
22486
|
-
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);
|
|
22487
23330
|
const width = findWidth(table), height = table.childCount;
|
|
22488
23331
|
const map2 = [];
|
|
22489
23332
|
let mapPos = 0;
|
|
@@ -22510,22 +23353,19 @@ function computeMap(table) {
|
|
|
22510
23353
|
const start2 = mapPos + h * width;
|
|
22511
23354
|
for (let w = 0; w < colspan; w++) {
|
|
22512
23355
|
if (map2[start2 + w] == 0) map2[start2 + w] = pos;
|
|
22513
|
-
else
|
|
22514
|
-
|
|
22515
|
-
|
|
22516
|
-
|
|
22517
|
-
|
|
22518
|
-
|
|
22519
|
-
});
|
|
23356
|
+
else (problems || (problems = [])).push({
|
|
23357
|
+
type: "collision",
|
|
23358
|
+
row,
|
|
23359
|
+
pos,
|
|
23360
|
+
n: colspan - w
|
|
23361
|
+
});
|
|
22520
23362
|
const colW = colwidth && colwidth[w];
|
|
22521
23363
|
if (colW) {
|
|
22522
23364
|
const widthIndex = (start2 + w) % width * 2, prev = colWidths[widthIndex];
|
|
22523
23365
|
if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
|
|
22524
23366
|
colWidths[widthIndex] = colW;
|
|
22525
23367
|
colWidths[widthIndex + 1] = 1;
|
|
22526
|
-
} else if (prev == colW)
|
|
22527
|
-
colWidths[widthIndex + 1]++;
|
|
22528
|
-
}
|
|
23368
|
+
} else if (prev == colW) colWidths[widthIndex + 1]++;
|
|
22529
23369
|
}
|
|
22530
23370
|
}
|
|
22531
23371
|
}
|
|
@@ -22535,16 +23375,17 @@ function computeMap(table) {
|
|
|
22535
23375
|
const expectedPos = (row + 1) * width;
|
|
22536
23376
|
let missing = 0;
|
|
22537
23377
|
while (mapPos < expectedPos) if (map2[mapPos++] == 0) missing++;
|
|
22538
|
-
if (missing)
|
|
22539
|
-
|
|
23378
|
+
if (missing) (problems || (problems = [])).push({
|
|
23379
|
+
type: "missing",
|
|
23380
|
+
row,
|
|
23381
|
+
n: missing
|
|
23382
|
+
});
|
|
22540
23383
|
pos++;
|
|
22541
23384
|
}
|
|
22542
|
-
if (width === 0 || height === 0)
|
|
22543
|
-
(problems || (problems = [])).push({ type: "zero_sized" });
|
|
23385
|
+
if (width === 0 || height === 0) (problems || (problems = [])).push({ type: "zero_sized" });
|
|
22544
23386
|
const tableMap = new TableMap(width, height, map2, problems);
|
|
22545
23387
|
let badWidths = false;
|
|
22546
|
-
for (let i = 0; !badWidths && i < colWidths.length; i += 2)
|
|
22547
|
-
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;
|
|
22548
23389
|
if (badWidths) findBadColWidths(tableMap, colWidths, table);
|
|
22549
23390
|
return tableMap;
|
|
22550
23391
|
}
|
|
@@ -22554,14 +23395,13 @@ function findWidth(table) {
|
|
|
22554
23395
|
for (let row = 0; row < table.childCount; row++) {
|
|
22555
23396
|
const rowNode = table.child(row);
|
|
22556
23397
|
let rowWidth = 0;
|
|
22557
|
-
if (hasRowSpan)
|
|
22558
|
-
|
|
22559
|
-
|
|
22560
|
-
|
|
22561
|
-
|
|
22562
|
-
if (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
|
|
22563
|
-
}
|
|
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;
|
|
22564
23403
|
}
|
|
23404
|
+
}
|
|
22565
23405
|
for (let i = 0; i < rowNode.childCount; i++) {
|
|
22566
23406
|
const cell = rowNode.child(i);
|
|
22567
23407
|
rowWidth += cell.attrs.colspan;
|
|
@@ -22580,23 +23420,18 @@ function findBadColWidths(map2, colWidths, table) {
|
|
|
22580
23420
|
if (seen[pos]) continue;
|
|
22581
23421
|
seen[pos] = true;
|
|
22582
23422
|
const node = table.nodeAt(pos);
|
|
22583
|
-
if (!node) {
|
|
22584
|
-
throw new RangeError(`No cell with offset ${pos} found`);
|
|
22585
|
-
}
|
|
23423
|
+
if (!node) throw new RangeError(`No cell with offset ${pos} found`);
|
|
22586
23424
|
let updated = null;
|
|
22587
23425
|
const attrs = node.attrs;
|
|
22588
23426
|
for (let j = 0; j < attrs.colspan; j++) {
|
|
22589
|
-
const
|
|
22590
|
-
|
|
22591
|
-
|
|
22592
|
-
|
|
22593
|
-
|
|
22594
|
-
|
|
22595
|
-
|
|
22596
|
-
|
|
22597
|
-
pos,
|
|
22598
|
-
colwidth: updated
|
|
22599
|
-
});
|
|
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
|
+
});
|
|
22600
23435
|
}
|
|
22601
23436
|
}
|
|
22602
23437
|
function freshColWidth(attrs) {
|
|
@@ -22616,11 +23451,9 @@ function tableNodeTypes(schema) {
|
|
|
22616
23451
|
}
|
|
22617
23452
|
return result;
|
|
22618
23453
|
}
|
|
22619
|
-
|
|
23454
|
+
const tableEditingKey = new PluginKey("selectingCells");
|
|
22620
23455
|
function cellAround$1($pos) {
|
|
22621
|
-
for (let d2 = $pos.depth - 1; d2 > 0; d2--)
|
|
22622
|
-
if ($pos.node(d2).type.spec.tableRole == "row")
|
|
22623
|
-
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));
|
|
22624
23457
|
return null;
|
|
22625
23458
|
}
|
|
22626
23459
|
function cellWrapping$1($pos) {
|
|
@@ -22632,21 +23465,15 @@ function cellWrapping$1($pos) {
|
|
|
22632
23465
|
}
|
|
22633
23466
|
function isInTable(state) {
|
|
22634
23467
|
const $head = state.selection.$head;
|
|
22635
|
-
for (let d2 = $head.depth; d2 > 0; d2--)
|
|
22636
|
-
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;
|
|
22637
23469
|
return false;
|
|
22638
23470
|
}
|
|
22639
23471
|
function selectionCell(state) {
|
|
22640
23472
|
const sel = state.selection;
|
|
22641
|
-
if ("$anchorCell" in sel && sel.$anchorCell)
|
|
22642
|
-
|
|
22643
|
-
} else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
|
|
22644
|
-
return sel.$anchor;
|
|
22645
|
-
}
|
|
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;
|
|
22646
23475
|
const $cell = cellAround$1(sel.$head) || cellNear(sel.$head);
|
|
22647
|
-
if ($cell)
|
|
22648
|
-
return $cell;
|
|
22649
|
-
}
|
|
23476
|
+
if ($cell) return $cell;
|
|
22650
23477
|
throw new RangeError(`No cell found around position ${sel.head}`);
|
|
22651
23478
|
}
|
|
22652
23479
|
function cellNear($pos) {
|
|
@@ -22656,8 +23483,7 @@ function cellNear($pos) {
|
|
|
22656
23483
|
}
|
|
22657
23484
|
for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
|
|
22658
23485
|
const role = before.type.spec.tableRole;
|
|
22659
|
-
if (role == "cell" || role == "header_cell")
|
|
22660
|
-
return $pos.doc.resolve(pos - before.nodeSize);
|
|
23486
|
+
if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos - before.nodeSize);
|
|
22661
23487
|
}
|
|
22662
23488
|
}
|
|
22663
23489
|
function pointsAtCell($pos) {
|
|
@@ -22677,7 +23503,10 @@ function nextCell($pos, axis, dir) {
|
|
|
22677
23503
|
return moved == null ? null : $pos.node(0).resolve(tableStart + moved);
|
|
22678
23504
|
}
|
|
22679
23505
|
function removeColSpan(attrs, pos, n = 1) {
|
|
22680
|
-
const result = {
|
|
23506
|
+
const result = {
|
|
23507
|
+
...attrs,
|
|
23508
|
+
colspan: attrs.colspan - n
|
|
23509
|
+
};
|
|
22681
23510
|
if (result.colwidth) {
|
|
22682
23511
|
result.colwidth = result.colwidth.slice();
|
|
22683
23512
|
result.colwidth.splice(pos, n);
|
|
@@ -22686,7 +23515,10 @@ function removeColSpan(attrs, pos, n = 1) {
|
|
|
22686
23515
|
return result;
|
|
22687
23516
|
}
|
|
22688
23517
|
function addColSpan(attrs, pos, n = 1) {
|
|
22689
|
-
const result = {
|
|
23518
|
+
const result = {
|
|
23519
|
+
...attrs,
|
|
23520
|
+
colspan: attrs.colspan + n
|
|
23521
|
+
};
|
|
22690
23522
|
if (result.colwidth) {
|
|
22691
23523
|
result.colwidth = result.colwidth.slice();
|
|
22692
23524
|
for (let i = 0; i < n; i++) result.colwidth.splice(pos, 0, 0);
|
|
@@ -22695,37 +23527,23 @@ function addColSpan(attrs, pos, n = 1) {
|
|
|
22695
23527
|
}
|
|
22696
23528
|
function columnIsHeader(map2, table, col) {
|
|
22697
23529
|
const headerCell = tableNodeTypes(table.type.schema).header_cell;
|
|
22698
|
-
for (let row = 0; row < map2.height; row++)
|
|
22699
|
-
if (table.nodeAt(map2.map[col + row * map2.width]).type != headerCell)
|
|
22700
|
-
return false;
|
|
23530
|
+
for (let row = 0; row < map2.height; row++) if (table.nodeAt(map2.map[col + row * map2.width]).type != headerCell) return false;
|
|
22701
23531
|
return true;
|
|
22702
23532
|
}
|
|
22703
|
-
var CellSelection = class
|
|
22704
|
-
// A table selection is identified by its anchor and head cells. The
|
|
22705
|
-
// positions given to this constructor should point _before_ two
|
|
22706
|
-
// cells in the same table. They may be the same, to select a single
|
|
22707
|
-
// cell.
|
|
23533
|
+
var CellSelection = class CellSelection2 extends Selection {
|
|
22708
23534
|
constructor($anchorCell, $headCell = $anchorCell) {
|
|
22709
23535
|
const table = $anchorCell.node(-1);
|
|
22710
23536
|
const map2 = TableMap.get(table);
|
|
22711
23537
|
const tableStart = $anchorCell.start(-1);
|
|
22712
|
-
const rect = map2.rectBetween(
|
|
22713
|
-
$anchorCell.pos - tableStart,
|
|
22714
|
-
$headCell.pos - tableStart
|
|
22715
|
-
);
|
|
23538
|
+
const rect = map2.rectBetween($anchorCell.pos - tableStart, $headCell.pos - tableStart);
|
|
22716
23539
|
const doc2 = $anchorCell.node(0);
|
|
22717
23540
|
const cells = map2.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);
|
|
22718
23541
|
cells.unshift($headCell.pos - tableStart);
|
|
22719
23542
|
const ranges = cells.map((pos) => {
|
|
22720
23543
|
const cell = table.nodeAt(pos);
|
|
22721
|
-
if (!cell) {
|
|
22722
|
-
throw RangeError(`No cell with offset ${pos} found`);
|
|
22723
|
-
}
|
|
23544
|
+
if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
|
|
22724
23545
|
const from2 = tableStart + pos + 1;
|
|
22725
|
-
return new SelectionRange(
|
|
22726
|
-
doc2.resolve(from2),
|
|
22727
|
-
doc2.resolve(from2 + cell.content.size)
|
|
22728
|
-
);
|
|
23546
|
+
return new SelectionRange(doc2.resolve(from2), doc2.resolve(from2 + cell.content.size));
|
|
22729
23547
|
});
|
|
22730
23548
|
super(ranges[0].$from, ranges[0].$to, ranges);
|
|
22731
23549
|
this.$anchorCell = $anchorCell;
|
|
@@ -22736,24 +23554,17 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22736
23554
|
const $headCell = doc2.resolve(mapping.map(this.$headCell.pos));
|
|
22737
23555
|
if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
|
|
22738
23556
|
const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
|
|
22739
|
-
if (tableChanged && this.isRowSelection())
|
|
22740
|
-
|
|
22741
|
-
else
|
|
22742
|
-
return _CellSelection.colSelection($anchorCell, $headCell);
|
|
22743
|
-
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);
|
|
22744
23560
|
}
|
|
22745
23561
|
return TextSelection.between($anchorCell, $headCell);
|
|
22746
23562
|
}
|
|
22747
|
-
// Returns a rectangular slice of table rows containing the selected
|
|
22748
|
-
// cells.
|
|
22749
23563
|
content() {
|
|
22750
23564
|
const table = this.$anchorCell.node(-1);
|
|
22751
23565
|
const map2 = TableMap.get(table);
|
|
22752
23566
|
const tableStart = this.$anchorCell.start(-1);
|
|
22753
|
-
const rect = map2.rectBetween(
|
|
22754
|
-
this.$anchorCell.pos - tableStart,
|
|
22755
|
-
this.$headCell.pos - tableStart
|
|
22756
|
-
);
|
|
23567
|
+
const rect = map2.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart);
|
|
22757
23568
|
const seen = {};
|
|
22758
23569
|
const rows = [];
|
|
22759
23570
|
for (let row = rect.top; row < rect.bottom; row++) {
|
|
@@ -22764,44 +23575,25 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22764
23575
|
seen[pos] = true;
|
|
22765
23576
|
const cellRect = map2.findCell(pos);
|
|
22766
23577
|
let cell = table.nodeAt(pos);
|
|
22767
|
-
if (!cell) {
|
|
22768
|
-
throw RangeError(`No cell with offset ${pos} found`);
|
|
22769
|
-
}
|
|
23578
|
+
if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
|
|
22770
23579
|
const extraLeft = rect.left - cellRect.left;
|
|
22771
23580
|
const extraRight = cellRect.right - rect.right;
|
|
22772
23581
|
if (extraLeft > 0 || extraRight > 0) {
|
|
22773
23582
|
let attrs = cell.attrs;
|
|
22774
|
-
if (extraLeft > 0)
|
|
22775
|
-
|
|
22776
|
-
}
|
|
22777
|
-
if (extraRight > 0) {
|
|
22778
|
-
attrs = removeColSpan(
|
|
22779
|
-
attrs,
|
|
22780
|
-
attrs.colspan - extraRight,
|
|
22781
|
-
extraRight
|
|
22782
|
-
);
|
|
22783
|
-
}
|
|
23583
|
+
if (extraLeft > 0) attrs = removeColSpan(attrs, 0, extraLeft);
|
|
23584
|
+
if (extraRight > 0) attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
|
|
22784
23585
|
if (cellRect.left < rect.left) {
|
|
22785
23586
|
cell = cell.type.createAndFill(attrs);
|
|
22786
|
-
if (!cell) {
|
|
22787
|
-
|
|
22788
|
-
`Could not create cell with attrs ${JSON.stringify(attrs)}`
|
|
22789
|
-
);
|
|
22790
|
-
}
|
|
22791
|
-
} else {
|
|
22792
|
-
cell = cell.type.create(attrs, cell.content);
|
|
22793
|
-
}
|
|
23587
|
+
if (!cell) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(attrs)}`);
|
|
23588
|
+
} else cell = cell.type.create(attrs, cell.content);
|
|
22794
23589
|
}
|
|
22795
23590
|
if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
|
|
22796
23591
|
const attrs = {
|
|
22797
23592
|
...cell.attrs,
|
|
22798
23593
|
rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
|
|
22799
23594
|
};
|
|
22800
|
-
if (cellRect.top < rect.top)
|
|
22801
|
-
|
|
22802
|
-
} else {
|
|
22803
|
-
cell = cell.type.create(attrs, cell.content);
|
|
22804
|
-
}
|
|
23595
|
+
if (cellRect.top < rect.top) cell = cell.type.createAndFill(attrs);
|
|
23596
|
+
else cell = cell.type.create(attrs, cell.content);
|
|
22805
23597
|
}
|
|
22806
23598
|
rowContent.push(cell);
|
|
22807
23599
|
}
|
|
@@ -22814,16 +23606,9 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22814
23606
|
const mapFrom = tr.steps.length, ranges = this.ranges;
|
|
22815
23607
|
for (let i = 0; i < ranges.length; i++) {
|
|
22816
23608
|
const { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
|
|
22817
|
-
tr.replace(
|
|
22818
|
-
mapping.map($from.pos),
|
|
22819
|
-
mapping.map($to.pos),
|
|
22820
|
-
i ? Slice.empty : content
|
|
22821
|
-
);
|
|
23609
|
+
tr.replace(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
|
|
22822
23610
|
}
|
|
22823
|
-
const sel = Selection.findFrom(
|
|
22824
|
-
tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)),
|
|
22825
|
-
-1
|
|
22826
|
-
);
|
|
23611
|
+
const sel = Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1);
|
|
22827
23612
|
if (sel) tr.setSelection(sel);
|
|
22828
23613
|
}
|
|
22829
23614
|
replaceWith(tr, node) {
|
|
@@ -22833,18 +23618,9 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22833
23618
|
const table = this.$anchorCell.node(-1);
|
|
22834
23619
|
const map2 = TableMap.get(table);
|
|
22835
23620
|
const tableStart = this.$anchorCell.start(-1);
|
|
22836
|
-
const cells = map2.cellsInRect(
|
|
22837
|
-
|
|
22838
|
-
this.$anchorCell.pos - tableStart,
|
|
22839
|
-
this.$headCell.pos - tableStart
|
|
22840
|
-
)
|
|
22841
|
-
);
|
|
22842
|
-
for (let i = 0; i < cells.length; i++) {
|
|
22843
|
-
f2(table.nodeAt(cells[i]), tableStart + cells[i]);
|
|
22844
|
-
}
|
|
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]);
|
|
22845
23623
|
}
|
|
22846
|
-
// True if this selection goes all the way from the top to the
|
|
22847
|
-
// bottom of the table.
|
|
22848
23624
|
isColSelection() {
|
|
22849
23625
|
const anchorTop = this.$anchorCell.index(-1);
|
|
22850
23626
|
const headTop = this.$headCell.index(-1);
|
|
@@ -22853,8 +23629,6 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22853
23629
|
const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
|
|
22854
23630
|
return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
|
|
22855
23631
|
}
|
|
22856
|
-
// Returns the smallest column selection that covers the given anchor
|
|
22857
|
-
// and head cell.
|
|
22858
23632
|
static colSelection($anchorCell, $headCell = $anchorCell) {
|
|
22859
23633
|
const table = $anchorCell.node(-1);
|
|
22860
23634
|
const map2 = TableMap.get(table);
|
|
@@ -22863,24 +23637,14 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22863
23637
|
const headRect = map2.findCell($headCell.pos - tableStart);
|
|
22864
23638
|
const doc2 = $anchorCell.node(0);
|
|
22865
23639
|
if (anchorRect.top <= headRect.top) {
|
|
22866
|
-
if (anchorRect.top > 0)
|
|
22867
|
-
|
|
22868
|
-
if (headRect.bottom < map2.height)
|
|
22869
|
-
$headCell = doc2.resolve(
|
|
22870
|
-
tableStart + map2.map[map2.width * (map2.height - 1) + headRect.right - 1]
|
|
22871
|
-
);
|
|
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]);
|
|
22872
23642
|
} else {
|
|
22873
|
-
if (headRect.top > 0)
|
|
22874
|
-
|
|
22875
|
-
if (anchorRect.bottom < map2.height)
|
|
22876
|
-
$anchorCell = doc2.resolve(
|
|
22877
|
-
tableStart + map2.map[map2.width * (map2.height - 1) + anchorRect.right - 1]
|
|
22878
|
-
);
|
|
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]);
|
|
22879
23645
|
}
|
|
22880
|
-
return new
|
|
23646
|
+
return new CellSelection2($anchorCell, $headCell);
|
|
22881
23647
|
}
|
|
22882
|
-
// True if this selection goes all the way from the left to the
|
|
22883
|
-
// right of the table.
|
|
22884
23648
|
isRowSelection() {
|
|
22885
23649
|
const table = this.$anchorCell.node(-1);
|
|
22886
23650
|
const map2 = TableMap.get(table);
|
|
@@ -22893,10 +23657,8 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22893
23657
|
return Math.max(anchorRight, headRight) == map2.width;
|
|
22894
23658
|
}
|
|
22895
23659
|
eq(other) {
|
|
22896
|
-
return other instanceof
|
|
23660
|
+
return other instanceof CellSelection2 && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
|
|
22897
23661
|
}
|
|
22898
|
-
// Returns the smallest row selection that covers the given anchor
|
|
22899
|
-
// and head cell.
|
|
22900
23662
|
static rowSelection($anchorCell, $headCell = $anchorCell) {
|
|
22901
23663
|
const table = $anchorCell.node(-1);
|
|
22902
23664
|
const map2 = TableMap.get(table);
|
|
@@ -22905,23 +23667,13 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22905
23667
|
const headRect = map2.findCell($headCell.pos - tableStart);
|
|
22906
23668
|
const doc2 = $anchorCell.node(0);
|
|
22907
23669
|
if (anchorRect.left <= headRect.left) {
|
|
22908
|
-
if (anchorRect.left > 0)
|
|
22909
|
-
|
|
22910
|
-
tableStart + map2.map[anchorRect.top * map2.width]
|
|
22911
|
-
);
|
|
22912
|
-
if (headRect.right < map2.width)
|
|
22913
|
-
$headCell = doc2.resolve(
|
|
22914
|
-
tableStart + map2.map[map2.width * (headRect.top + 1) - 1]
|
|
22915
|
-
);
|
|
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]);
|
|
22916
23672
|
} else {
|
|
22917
|
-
if (headRect.left > 0)
|
|
22918
|
-
|
|
22919
|
-
if (anchorRect.right < map2.width)
|
|
22920
|
-
$anchorCell = doc2.resolve(
|
|
22921
|
-
tableStart + map2.map[map2.width * (anchorRect.top + 1) - 1]
|
|
22922
|
-
);
|
|
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]);
|
|
22923
23675
|
}
|
|
22924
|
-
return new
|
|
23676
|
+
return new CellSelection2($anchorCell, $headCell);
|
|
22925
23677
|
}
|
|
22926
23678
|
toJSON() {
|
|
22927
23679
|
return {
|
|
@@ -22931,10 +23683,10 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22931
23683
|
};
|
|
22932
23684
|
}
|
|
22933
23685
|
static fromJSON(doc2, json) {
|
|
22934
|
-
return new
|
|
23686
|
+
return new CellSelection2(doc2.resolve(json.anchor), doc2.resolve(json.head));
|
|
22935
23687
|
}
|
|
22936
23688
|
static create(doc2, anchorCell, headCell = anchorCell) {
|
|
22937
|
-
return new
|
|
23689
|
+
return new CellSelection2(doc2.resolve(anchorCell), doc2.resolve(headCell));
|
|
22938
23690
|
}
|
|
22939
23691
|
getBookmark() {
|
|
22940
23692
|
return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
|
|
@@ -22942,18 +23694,17 @@ var CellSelection = class _CellSelection extends Selection {
|
|
|
22942
23694
|
};
|
|
22943
23695
|
CellSelection.prototype.visible = false;
|
|
22944
23696
|
Selection.jsonID("cell", CellSelection);
|
|
22945
|
-
var CellBookmark = class
|
|
23697
|
+
var CellBookmark = class CellBookmark2 {
|
|
22946
23698
|
constructor(anchor, head) {
|
|
22947
23699
|
this.anchor = anchor;
|
|
22948
23700
|
this.head = head;
|
|
22949
23701
|
}
|
|
22950
23702
|
map(mapping) {
|
|
22951
|
-
return new
|
|
23703
|
+
return new CellBookmark2(mapping.map(this.anchor), mapping.map(this.head));
|
|
22952
23704
|
}
|
|
22953
23705
|
resolve(doc2) {
|
|
22954
23706
|
const $anchorCell = doc2.resolve(this.anchor), $headCell = doc2.resolve(this.head);
|
|
22955
|
-
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))
|
|
22956
|
-
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);
|
|
22957
23708
|
else return Selection.near($headCell, 1);
|
|
22958
23709
|
}
|
|
22959
23710
|
};
|
|
@@ -22961,9 +23712,7 @@ function drawCellSelection(state) {
|
|
|
22961
23712
|
if (!(state.selection instanceof CellSelection)) return null;
|
|
22962
23713
|
const cells = [];
|
|
22963
23714
|
state.selection.forEachCell((node, pos) => {
|
|
22964
|
-
cells.push(
|
|
22965
|
-
Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" })
|
|
22966
|
-
);
|
|
23715
|
+
cells.push(Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" }));
|
|
22967
23716
|
});
|
|
22968
23717
|
return DecorationSet.create(state.doc, cells);
|
|
22969
23718
|
}
|
|
@@ -22972,10 +23721,8 @@ function isCellBoundarySelection({ $from, $to }) {
|
|
|
22972
23721
|
let afterFrom = $from.pos;
|
|
22973
23722
|
let beforeTo = $to.pos;
|
|
22974
23723
|
let depth = $from.depth;
|
|
22975
|
-
for (; depth >= 0; depth--, afterFrom++)
|
|
22976
|
-
|
|
22977
|
-
for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--)
|
|
22978
|
-
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;
|
|
22979
23726
|
return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
|
|
22980
23727
|
}
|
|
22981
23728
|
function isTextSelectionAcrossCells({ $from, $to }) {
|
|
@@ -23003,9 +23750,8 @@ function normalizeSelection(state, tr, allowTableNodeSelection) {
|
|
|
23003
23750
|
let normalize2;
|
|
23004
23751
|
let role;
|
|
23005
23752
|
if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
|
|
23006
|
-
if (role == "cell" || role == "header_cell")
|
|
23007
|
-
|
|
23008
|
-
} else if (role == "row") {
|
|
23753
|
+
if (role == "cell" || role == "header_cell") normalize2 = CellSelection.create(doc2, sel.from);
|
|
23754
|
+
else if (role == "row") {
|
|
23009
23755
|
const $cell = doc2.resolve(sel.from + 1);
|
|
23010
23756
|
normalize2 = CellSelection.rowSelection($cell, $cell);
|
|
23011
23757
|
} else if (!allowTableNodeSelection) {
|
|
@@ -23014,29 +23760,23 @@ function normalizeSelection(state, tr, allowTableNodeSelection) {
|
|
|
23014
23760
|
const lastCell = start2 + map2.map[map2.width * map2.height - 1];
|
|
23015
23761
|
normalize2 = CellSelection.create(doc2, start2 + 1, lastCell);
|
|
23016
23762
|
}
|
|
23017
|
-
} else if (sel instanceof TextSelection && isCellBoundarySelection(sel))
|
|
23018
|
-
|
|
23019
|
-
} else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {
|
|
23020
|
-
normalize2 = TextSelection.create(doc2, sel.$from.start(), sel.$from.end());
|
|
23021
|
-
}
|
|
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());
|
|
23022
23765
|
if (normalize2) (tr || (tr = state.tr)).setSelection(normalize2);
|
|
23023
23766
|
return tr;
|
|
23024
23767
|
}
|
|
23025
|
-
|
|
23768
|
+
const fixTablesKey = new PluginKey("fix-tables");
|
|
23026
23769
|
function changedDescendants(old, cur, offset2, f2) {
|
|
23027
23770
|
const oldSize = old.childCount, curSize = cur.childCount;
|
|
23028
23771
|
outer: for (let i = 0, j = 0; i < curSize; i++) {
|
|
23029
23772
|
const child = cur.child(i);
|
|
23030
|
-
for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {
|
|
23031
|
-
|
|
23032
|
-
|
|
23033
|
-
|
|
23034
|
-
continue outer;
|
|
23035
|
-
}
|
|
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;
|
|
23036
23777
|
}
|
|
23037
23778
|
f2(child, offset2);
|
|
23038
|
-
if (j < oldSize && old.child(j).sameMarkup(child))
|
|
23039
|
-
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);
|
|
23040
23780
|
else child.nodesBetween(0, child.content.size, f2, offset2 + 1);
|
|
23041
23781
|
offset2 += child.nodeSize;
|
|
23042
23782
|
}
|
|
@@ -23044,12 +23784,10 @@ function changedDescendants(old, cur, offset2, f2) {
|
|
|
23044
23784
|
function fixTables(state, oldState) {
|
|
23045
23785
|
let tr;
|
|
23046
23786
|
const check = (node, pos) => {
|
|
23047
|
-
if (node.type.spec.tableRole == "table")
|
|
23048
|
-
tr = fixTable(state, node, pos, tr);
|
|
23787
|
+
if (node.type.spec.tableRole == "table") tr = fixTable(state, node, pos, tr);
|
|
23049
23788
|
};
|
|
23050
23789
|
if (!oldState) state.doc.descendants(check);
|
|
23051
|
-
else if (oldState.doc != state.doc)
|
|
23052
|
-
changedDescendants(oldState.doc, state.doc, 0, check);
|
|
23790
|
+
else if (oldState.doc != state.doc) changedDescendants(oldState.doc, state.doc, 0, check);
|
|
23053
23791
|
return tr;
|
|
23054
23792
|
}
|
|
23055
23793
|
function fixTable(state, table, tablePos, tr) {
|
|
@@ -23065,14 +23803,9 @@ function fixTable(state, table, tablePos, tr) {
|
|
|
23065
23803
|
if (!cell) continue;
|
|
23066
23804
|
const attrs = cell.attrs;
|
|
23067
23805
|
for (let j = 0; j < attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n;
|
|
23068
|
-
tr.setNodeMarkup(
|
|
23069
|
-
|
|
23070
|
-
|
|
23071
|
-
removeColSpan(attrs, attrs.colspan - prob.n, prob.n)
|
|
23072
|
-
);
|
|
23073
|
-
} else if (prob.type == "missing") {
|
|
23074
|
-
mustAdd[prob.row] += prob.n;
|
|
23075
|
-
} 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") {
|
|
23076
23809
|
const cell = table.nodeAt(prob.pos);
|
|
23077
23810
|
if (!cell) continue;
|
|
23078
23811
|
tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
|
|
@@ -23092,20 +23825,17 @@ function fixTable(state, table, tablePos, tr) {
|
|
|
23092
23825
|
}
|
|
23093
23826
|
}
|
|
23094
23827
|
let first2, last;
|
|
23095
|
-
for (let i = 0; i < mustAdd.length; i++)
|
|
23096
|
-
if (
|
|
23097
|
-
|
|
23098
|
-
|
|
23099
|
-
}
|
|
23828
|
+
for (let i = 0; i < mustAdd.length; i++) if (mustAdd[i]) {
|
|
23829
|
+
if (first2 == null) first2 = i;
|
|
23830
|
+
last = i;
|
|
23831
|
+
}
|
|
23100
23832
|
for (let i = 0, pos = tablePos + 1; i < map2.height; i++) {
|
|
23101
23833
|
const row = table.child(i);
|
|
23102
23834
|
const end2 = pos + row.nodeSize;
|
|
23103
23835
|
const add = mustAdd[i];
|
|
23104
23836
|
if (add > 0) {
|
|
23105
23837
|
let role = "cell";
|
|
23106
|
-
if (row.firstChild)
|
|
23107
|
-
role = row.firstChild.type.spec.tableRole;
|
|
23108
|
-
}
|
|
23838
|
+
if (row.firstChild) role = row.firstChild.type.spec.tableRole;
|
|
23109
23839
|
const nodes = [];
|
|
23110
23840
|
for (let j = 0; j < add; j++) {
|
|
23111
23841
|
const node = tableNodeTypes(state.schema)[role].createAndFill();
|
|
@@ -23124,27 +23854,22 @@ function selectedRect(state) {
|
|
|
23124
23854
|
const table = $pos.node(-1);
|
|
23125
23855
|
const tableStart = $pos.start(-1);
|
|
23126
23856
|
const map2 = TableMap.get(table);
|
|
23127
|
-
|
|
23128
|
-
sel.$anchorCell.pos - tableStart,
|
|
23129
|
-
|
|
23130
|
-
|
|
23131
|
-
|
|
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
|
+
};
|
|
23132
23863
|
}
|
|
23133
23864
|
function addColumn(tr, { map: map2, tableStart, table }, col) {
|
|
23134
23865
|
let refColumn = col > 0 ? -1 : 0;
|
|
23135
|
-
if (columnIsHeader(map2, table, col + refColumn))
|
|
23136
|
-
refColumn = col == 0 || col == map2.width ? null : 0;
|
|
23137
|
-
}
|
|
23866
|
+
if (columnIsHeader(map2, table, col + refColumn)) refColumn = col == 0 || col == map2.width ? null : 0;
|
|
23138
23867
|
for (let row = 0; row < map2.height; row++) {
|
|
23139
23868
|
const index2 = row * map2.width + col;
|
|
23140
23869
|
if (col > 0 && col < map2.width && map2.map[index2 - 1] == map2.map[index2]) {
|
|
23141
23870
|
const pos = map2.map[index2];
|
|
23142
23871
|
const cell = table.nodeAt(pos);
|
|
23143
|
-
tr.setNodeMarkup(
|
|
23144
|
-
tr.mapping.map(tableStart + pos),
|
|
23145
|
-
null,
|
|
23146
|
-
addColSpan(cell.attrs, col - map2.colCount(pos))
|
|
23147
|
-
);
|
|
23872
|
+
tr.setNodeMarkup(tr.mapping.map(tableStart + pos), null, addColSpan(cell.attrs, col - map2.colCount(pos)));
|
|
23148
23873
|
row += cell.attrs.rowspan - 1;
|
|
23149
23874
|
} else {
|
|
23150
23875
|
const type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map2.map[index2 + refColumn]).type;
|
|
@@ -23177,13 +23902,8 @@ function removeColumn(tr, { map: map2, table, tableStart }, col) {
|
|
|
23177
23902
|
const pos = map2.map[index2];
|
|
23178
23903
|
const cell = table.nodeAt(pos);
|
|
23179
23904
|
const attrs = cell.attrs;
|
|
23180
|
-
if (col > 0 && map2.map[index2 - 1] == pos || col < map2.width - 1 && map2.map[index2 + 1] == pos)
|
|
23181
|
-
|
|
23182
|
-
tr.mapping.slice(mapStart).map(tableStart + pos),
|
|
23183
|
-
null,
|
|
23184
|
-
removeColSpan(attrs, col - map2.colCount(pos))
|
|
23185
|
-
);
|
|
23186
|
-
} 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 {
|
|
23187
23907
|
const start2 = tr.mapping.slice(mapStart).map(tableStart + pos);
|
|
23188
23908
|
tr.delete(start2, start2 + cell.nodeSize);
|
|
23189
23909
|
}
|
|
@@ -23200,9 +23920,7 @@ function deleteColumn(state, dispatch) {
|
|
|
23200
23920
|
removeColumn(tr, rect, i);
|
|
23201
23921
|
if (i == rect.left) break;
|
|
23202
23922
|
const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
|
|
23203
|
-
if (!table)
|
|
23204
|
-
throw RangeError("No table found");
|
|
23205
|
-
}
|
|
23923
|
+
if (!table) throw new RangeError("No table found");
|
|
23206
23924
|
rect.table = table;
|
|
23207
23925
|
rect.map = TableMap.get(table);
|
|
23208
23926
|
}
|
|
@@ -23211,35 +23929,30 @@ function deleteColumn(state, dispatch) {
|
|
|
23211
23929
|
return true;
|
|
23212
23930
|
}
|
|
23213
23931
|
function rowIsHeader(map2, table, row) {
|
|
23214
|
-
var
|
|
23932
|
+
var _table$nodeAt;
|
|
23215
23933
|
const headerCell = tableNodeTypes(table.type.schema).header_cell;
|
|
23216
|
-
for (let col = 0; col < map2.width; col++)
|
|
23217
|
-
if (((_a = table.nodeAt(map2.map[col + row * map2.width])) == null ? void 0 : _a.type) != headerCell)
|
|
23218
|
-
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;
|
|
23219
23935
|
return true;
|
|
23220
23936
|
}
|
|
23221
23937
|
function addRow(tr, { map: map2, tableStart, table }, row) {
|
|
23222
|
-
var _a;
|
|
23223
23938
|
let rowPos = tableStart;
|
|
23224
23939
|
for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;
|
|
23225
23940
|
const cells = [];
|
|
23226
23941
|
let refRow = row > 0 ? -1 : 0;
|
|
23227
|
-
if (rowIsHeader(map2, table, row + refRow))
|
|
23228
|
-
|
|
23229
|
-
|
|
23230
|
-
|
|
23231
|
-
|
|
23232
|
-
|
|
23233
|
-
|
|
23234
|
-
|
|
23235
|
-
|
|
23236
|
-
|
|
23237
|
-
|
|
23238
|
-
|
|
23239
|
-
|
|
23240
|
-
|
|
23241
|
-
if (node) cells.push(node);
|
|
23242
|
-
}
|
|
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);
|
|
23243
23956
|
}
|
|
23244
23957
|
tr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells));
|
|
23245
23958
|
return tr;
|
|
@@ -23281,10 +23994,10 @@ function removeRow(tr, { map: map2, table, tableStart }, row) {
|
|
|
23281
23994
|
} else if (row < map2.height && pos == map2.map[index2 + map2.width]) {
|
|
23282
23995
|
const cell = table.nodeAt(pos);
|
|
23283
23996
|
const attrs = cell.attrs;
|
|
23284
|
-
const copy = cell.type.create(
|
|
23285
|
-
|
|
23286
|
-
cell.
|
|
23287
|
-
);
|
|
23997
|
+
const copy = cell.type.create({
|
|
23998
|
+
...attrs,
|
|
23999
|
+
rowspan: cell.attrs.rowspan - 1
|
|
24000
|
+
}, cell.content);
|
|
23288
24001
|
const newPos = map2.positionAt(row + 1, col, table);
|
|
23289
24002
|
tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy);
|
|
23290
24003
|
col += attrs.colspan - 1;
|
|
@@ -23300,9 +24013,7 @@ function deleteRow(state, dispatch) {
|
|
|
23300
24013
|
removeRow(tr, rect, i);
|
|
23301
24014
|
if (i == rect.top) break;
|
|
23302
24015
|
const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
|
|
23303
|
-
if (!table)
|
|
23304
|
-
throw RangeError("No table found");
|
|
23305
|
-
}
|
|
24016
|
+
if (!table) throw new RangeError("No table found");
|
|
23306
24017
|
rect.table = table;
|
|
23307
24018
|
rect.map = TableMap.get(rect.table);
|
|
23308
24019
|
}
|
|
@@ -23318,14 +24029,12 @@ function cellsOverlapRectangle({ width, height, map: map2 }, rect) {
|
|
|
23318
24029
|
let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
|
|
23319
24030
|
let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
|
|
23320
24031
|
for (let i = rect.top; i < rect.bottom; i++) {
|
|
23321
|
-
if (rect.left > 0 && map2[indexLeft] == map2[indexLeft - 1] || rect.right < width && map2[indexRight] == map2[indexRight + 1])
|
|
23322
|
-
return true;
|
|
24032
|
+
if (rect.left > 0 && map2[indexLeft] == map2[indexLeft - 1] || rect.right < width && map2[indexRight] == map2[indexRight + 1]) return true;
|
|
23323
24033
|
indexLeft += width;
|
|
23324
24034
|
indexRight += width;
|
|
23325
24035
|
}
|
|
23326
24036
|
for (let i = rect.left; i < rect.right; i++) {
|
|
23327
|
-
if (rect.top > 0 && map2[indexTop] == map2[indexTop - width] || rect.bottom < height && map2[indexBottom] == map2[indexBottom + width])
|
|
23328
|
-
return true;
|
|
24037
|
+
if (rect.top > 0 && map2[indexTop] == map2[indexTop - width] || rect.bottom < height && map2[indexBottom] == map2[indexBottom + width]) return true;
|
|
23329
24038
|
indexTop++;
|
|
23330
24039
|
indexBottom++;
|
|
23331
24040
|
}
|
|
@@ -23333,8 +24042,7 @@ function cellsOverlapRectangle({ width, height, map: map2 }, rect) {
|
|
|
23333
24042
|
}
|
|
23334
24043
|
function mergeCells(state, dispatch) {
|
|
23335
24044
|
const sel = state.selection;
|
|
23336
|
-
if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos)
|
|
23337
|
-
return false;
|
|
24045
|
+
if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos) return false;
|
|
23338
24046
|
const rect = selectedRect(state), { map: map2 } = rect;
|
|
23339
24047
|
if (cellsOverlapRectangle(map2, rect)) return false;
|
|
23340
24048
|
if (dispatch) {
|
|
@@ -23343,41 +24051,31 @@ function mergeCells(state, dispatch) {
|
|
|
23343
24051
|
let content = Fragment.empty;
|
|
23344
24052
|
let mergedPos;
|
|
23345
24053
|
let mergedCell;
|
|
23346
|
-
for (let row = rect.top; row < rect.bottom; row++) {
|
|
23347
|
-
|
|
23348
|
-
|
|
23349
|
-
|
|
23350
|
-
|
|
23351
|
-
|
|
23352
|
-
|
|
23353
|
-
|
|
23354
|
-
|
|
23355
|
-
|
|
23356
|
-
|
|
23357
|
-
|
|
23358
|
-
tr.delete(mapped, mapped + cell.nodeSize);
|
|
23359
|
-
}
|
|
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);
|
|
23360
24066
|
}
|
|
23361
24067
|
}
|
|
23362
|
-
if (mergedPos == null || mergedCell == null)
|
|
23363
|
-
return true;
|
|
23364
|
-
}
|
|
24068
|
+
if (mergedPos == null || mergedCell == null) return true;
|
|
23365
24069
|
tr.setNodeMarkup(mergedPos + rect.tableStart, null, {
|
|
23366
|
-
...addColSpan(
|
|
23367
|
-
mergedCell.attrs,
|
|
23368
|
-
mergedCell.attrs.colspan,
|
|
23369
|
-
rect.right - rect.left - mergedCell.attrs.colspan
|
|
23370
|
-
),
|
|
24070
|
+
...addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan),
|
|
23371
24071
|
rowspan: rect.bottom - rect.top
|
|
23372
24072
|
});
|
|
23373
|
-
if (content.size) {
|
|
24073
|
+
if (content.size > 0) {
|
|
23374
24074
|
const end2 = mergedPos + 1 + mergedCell.content.size;
|
|
23375
24075
|
const start2 = isEmpty(mergedCell) ? mergedPos + 1 : end2;
|
|
23376
24076
|
tr.replaceWith(start2 + rect.tableStart, end2 + rect.tableStart, content);
|
|
23377
24077
|
}
|
|
23378
|
-
tr.setSelection(
|
|
23379
|
-
new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart))
|
|
23380
|
-
);
|
|
24078
|
+
tr.setSelection(new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));
|
|
23381
24079
|
dispatch(tr);
|
|
23382
24080
|
}
|
|
23383
24081
|
return true;
|
|
@@ -23390,63 +24088,57 @@ function splitCell(state, dispatch) {
|
|
|
23390
24088
|
}
|
|
23391
24089
|
function splitCellWithType(getCellType2) {
|
|
23392
24090
|
return (state, dispatch) => {
|
|
23393
|
-
var _a;
|
|
23394
24091
|
const sel = state.selection;
|
|
23395
24092
|
let cellNode;
|
|
23396
24093
|
let cellPos;
|
|
23397
24094
|
if (!(sel instanceof CellSelection)) {
|
|
24095
|
+
var _cellAround;
|
|
23398
24096
|
cellNode = cellWrapping$1(sel.$from);
|
|
23399
24097
|
if (!cellNode) return false;
|
|
23400
|
-
cellPos = (
|
|
24098
|
+
cellPos = (_cellAround = cellAround$1(sel.$from)) === null || _cellAround === void 0 ? void 0 : _cellAround.pos;
|
|
23401
24099
|
} else {
|
|
23402
24100
|
if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
|
|
23403
24101
|
cellNode = sel.$anchorCell.nodeAfter;
|
|
23404
24102
|
cellPos = sel.$anchorCell.pos;
|
|
23405
24103
|
}
|
|
23406
|
-
if (cellNode == null || cellPos == null)
|
|
23407
|
-
|
|
23408
|
-
}
|
|
23409
|
-
if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {
|
|
23410
|
-
return false;
|
|
23411
|
-
}
|
|
24104
|
+
if (cellNode == null || cellPos == null) return false;
|
|
24105
|
+
if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) return false;
|
|
23412
24106
|
if (dispatch) {
|
|
23413
24107
|
let baseAttrs = cellNode.attrs;
|
|
23414
24108
|
const attrs = [];
|
|
23415
24109
|
const colwidth = baseAttrs.colwidth;
|
|
23416
|
-
if (baseAttrs.rowspan > 1) baseAttrs = {
|
|
23417
|
-
|
|
24110
|
+
if (baseAttrs.rowspan > 1) baseAttrs = {
|
|
24111
|
+
...baseAttrs,
|
|
24112
|
+
rowspan: 1
|
|
24113
|
+
};
|
|
24114
|
+
if (baseAttrs.colspan > 1) baseAttrs = {
|
|
24115
|
+
...baseAttrs,
|
|
24116
|
+
colspan: 1
|
|
24117
|
+
};
|
|
23418
24118
|
const rect = selectedRect(state), tr = state.tr;
|
|
23419
|
-
for (let i = 0; i < rect.right - rect.left; i++)
|
|
23420
|
-
|
|
23421
|
-
|
|
23422
|
-
|
|
23423
|
-
colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
|
|
23424
|
-
} : baseAttrs
|
|
23425
|
-
);
|
|
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);
|
|
23426
24123
|
let lastCell;
|
|
23427
24124
|
for (let row = rect.top; row < rect.bottom; row++) {
|
|
23428
24125
|
let pos = rect.map.positionAt(row, rect.left, rect.table);
|
|
23429
24126
|
if (row == rect.top) pos += cellNode.nodeSize;
|
|
23430
24127
|
for (let col = rect.left, i = 0; col < rect.right; col++, i++) {
|
|
23431
24128
|
if (col == rect.left && row == rect.top) continue;
|
|
23432
|
-
tr.insert(
|
|
23433
|
-
|
|
23434
|
-
|
|
23435
|
-
|
|
23436
|
-
|
|
23437
|
-
|
|
23438
|
-
|
|
23439
|
-
|
|
23440
|
-
|
|
23441
|
-
|
|
23442
|
-
|
|
23443
|
-
|
|
23444
|
-
|
|
23445
|
-
new CellSelection(
|
|
23446
|
-
tr.doc.resolve(sel.$anchorCell.pos),
|
|
23447
|
-
lastCell ? tr.doc.resolve(lastCell) : void 0
|
|
23448
|
-
)
|
|
23449
|
-
);
|
|
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));
|
|
23450
24142
|
dispatch(tr);
|
|
23451
24143
|
}
|
|
23452
24144
|
return true;
|
|
@@ -23459,19 +24151,16 @@ function setCellAttr(name, value) {
|
|
|
23459
24151
|
if ($cell.nodeAfter.attrs[name] === value) return false;
|
|
23460
24152
|
if (dispatch) {
|
|
23461
24153
|
const tr = state.tr;
|
|
23462
|
-
if (state.selection instanceof CellSelection)
|
|
23463
|
-
|
|
23464
|
-
|
|
23465
|
-
tr.setNodeMarkup(pos, null, {
|
|
23466
|
-
...node.attrs,
|
|
23467
|
-
[name]: value
|
|
23468
|
-
});
|
|
23469
|
-
});
|
|
23470
|
-
else
|
|
23471
|
-
tr.setNodeMarkup($cell.pos, null, {
|
|
23472
|
-
...$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,
|
|
23473
24157
|
[name]: value
|
|
23474
24158
|
});
|
|
24159
|
+
});
|
|
24160
|
+
else tr.setNodeMarkup($cell.pos, null, {
|
|
24161
|
+
...$cell.nodeAfter.attrs,
|
|
24162
|
+
[name]: value
|
|
24163
|
+
});
|
|
23475
24164
|
dispatch(tr);
|
|
23476
24165
|
}
|
|
23477
24166
|
return true;
|
|
@@ -23483,34 +24172,20 @@ function deprecated_toggleHeader(type) {
|
|
|
23483
24172
|
if (dispatch) {
|
|
23484
24173
|
const types = tableNodeTypes(state.schema);
|
|
23485
24174
|
const rect = selectedRect(state), tr = state.tr;
|
|
23486
|
-
const cells = rect.map.cellsInRect(
|
|
23487
|
-
|
|
23488
|
-
|
|
23489
|
-
|
|
23490
|
-
|
|
23491
|
-
|
|
23492
|
-
|
|
23493
|
-
|
|
23494
|
-
|
|
23495
|
-
|
|
23496
|
-
|
|
23497
|
-
} : rect
|
|
23498
|
-
);
|
|
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);
|
|
23499
24186
|
const nodes = cells.map((pos) => rect.table.nodeAt(pos));
|
|
23500
|
-
for (let i = 0; i < cells.length; i++)
|
|
23501
|
-
|
|
23502
|
-
tr.setNodeMarkup(
|
|
23503
|
-
rect.tableStart + cells[i],
|
|
23504
|
-
types.cell,
|
|
23505
|
-
nodes[i].attrs
|
|
23506
|
-
);
|
|
23507
|
-
if (tr.steps.length == 0)
|
|
23508
|
-
for (let i = 0; i < cells.length; i++)
|
|
23509
|
-
tr.setNodeMarkup(
|
|
23510
|
-
rect.tableStart + cells[i],
|
|
23511
|
-
types.header_cell,
|
|
23512
|
-
nodes[i].attrs
|
|
23513
|
-
);
|
|
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);
|
|
23514
24189
|
dispatch(tr);
|
|
23515
24190
|
}
|
|
23516
24191
|
return true;
|
|
@@ -23525,9 +24200,7 @@ function isHeaderEnabledByType(type, rect, types) {
|
|
|
23525
24200
|
});
|
|
23526
24201
|
for (let i = 0; i < cellPositions.length; i++) {
|
|
23527
24202
|
const cell = rect.table.nodeAt(cellPositions[i]);
|
|
23528
|
-
if (cell && cell.type !== types.header_cell)
|
|
23529
|
-
return false;
|
|
23530
|
-
}
|
|
24203
|
+
if (cell && cell.type !== types.header_cell) return false;
|
|
23531
24204
|
}
|
|
23532
24205
|
return true;
|
|
23533
24206
|
}
|
|
@@ -23540,13 +24213,8 @@ function toggleHeader(type, options) {
|
|
|
23540
24213
|
const types = tableNodeTypes(state.schema);
|
|
23541
24214
|
const rect = selectedRect(state), tr = state.tr;
|
|
23542
24215
|
const isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types);
|
|
23543
|
-
const isHeaderColumnEnabled = isHeaderEnabledByType(
|
|
23544
|
-
|
|
23545
|
-
rect,
|
|
23546
|
-
types
|
|
23547
|
-
);
|
|
23548
|
-
const isHeaderEnabled = type === "column" ? isHeaderRowEnabled : type === "row" ? isHeaderColumnEnabled : false;
|
|
23549
|
-
const selectionStartsAt = isHeaderEnabled ? 1 : 0;
|
|
24216
|
+
const isHeaderColumnEnabled = isHeaderEnabledByType("column", rect, types);
|
|
24217
|
+
const selectionStartsAt = (type === "column" ? isHeaderRowEnabled : type === "row" ? isHeaderColumnEnabled : false) ? 1 : 0;
|
|
23550
24218
|
const cellsRect = type == "column" ? {
|
|
23551
24219
|
left: 0,
|
|
23552
24220
|
top: selectionStartsAt,
|
|
@@ -23562,24 +24230,16 @@ function toggleHeader(type, options) {
|
|
|
23562
24230
|
rect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => {
|
|
23563
24231
|
const cellPos = relativeCellPos + rect.tableStart;
|
|
23564
24232
|
const cell = tr.doc.nodeAt(cellPos);
|
|
23565
|
-
if (cell)
|
|
23566
|
-
tr.setNodeMarkup(cellPos, newType, cell.attrs);
|
|
23567
|
-
}
|
|
24233
|
+
if (cell) tr.setNodeMarkup(cellPos, newType, cell.attrs);
|
|
23568
24234
|
});
|
|
23569
24235
|
dispatch(tr);
|
|
23570
24236
|
}
|
|
23571
24237
|
return true;
|
|
23572
24238
|
};
|
|
23573
24239
|
}
|
|
23574
|
-
toggleHeader("row", {
|
|
23575
|
-
|
|
23576
|
-
});
|
|
23577
|
-
toggleHeader("column", {
|
|
23578
|
-
useDeprecatedLogic: true
|
|
23579
|
-
});
|
|
23580
|
-
var toggleHeaderCell = toggleHeader("cell", {
|
|
23581
|
-
useDeprecatedLogic: true
|
|
23582
|
-
});
|
|
24240
|
+
toggleHeader("row", { useDeprecatedLogic: true });
|
|
24241
|
+
toggleHeader("column", { useDeprecatedLogic: true });
|
|
24242
|
+
const toggleHeaderCell = toggleHeader("cell", { useDeprecatedLogic: true });
|
|
23583
24243
|
function findNextCell($cell, dir) {
|
|
23584
24244
|
if (dir < 0) {
|
|
23585
24245
|
const before = $cell.nodeBefore;
|
|
@@ -23587,15 +24247,11 @@ function findNextCell($cell, dir) {
|
|
|
23587
24247
|
for (let row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) {
|
|
23588
24248
|
const rowNode = $cell.node(-1).child(row);
|
|
23589
24249
|
const lastChild = rowNode.lastChild;
|
|
23590
|
-
if (lastChild)
|
|
23591
|
-
return rowEnd - 1 - lastChild.nodeSize;
|
|
23592
|
-
}
|
|
24250
|
+
if (lastChild) return rowEnd - 1 - lastChild.nodeSize;
|
|
23593
24251
|
rowEnd -= rowNode.nodeSize;
|
|
23594
24252
|
}
|
|
23595
24253
|
} else {
|
|
23596
|
-
if ($cell.index() < $cell.parent.childCount - 1)
|
|
23597
|
-
return $cell.pos + $cell.nodeAfter.nodeSize;
|
|
23598
|
-
}
|
|
24254
|
+
if ($cell.index() < $cell.parent.childCount - 1) return $cell.pos + $cell.nodeAfter.nodeSize;
|
|
23599
24255
|
const table = $cell.node(-1);
|
|
23600
24256
|
for (let row = $cell.indexAfter(-1), rowStart = $cell.after(); row < table.childCount; row++) {
|
|
23601
24257
|
const rowNode = table.child(row);
|
|
@@ -23612,24 +24268,16 @@ function goToNextCell(direction) {
|
|
|
23612
24268
|
if (cell == null) return false;
|
|
23613
24269
|
if (dispatch) {
|
|
23614
24270
|
const $cell = state.doc.resolve(cell);
|
|
23615
|
-
dispatch(
|
|
23616
|
-
state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView()
|
|
23617
|
-
);
|
|
24271
|
+
dispatch(state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView());
|
|
23618
24272
|
}
|
|
23619
24273
|
return true;
|
|
23620
24274
|
};
|
|
23621
24275
|
}
|
|
23622
24276
|
function deleteTable(state, dispatch) {
|
|
23623
24277
|
const $pos = state.selection.$anchor;
|
|
23624
|
-
for (let d2 = $pos.depth; d2 > 0; d2--) {
|
|
23625
|
-
|
|
23626
|
-
|
|
23627
|
-
if (dispatch)
|
|
23628
|
-
dispatch(
|
|
23629
|
-
state.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView()
|
|
23630
|
-
);
|
|
23631
|
-
return true;
|
|
23632
|
-
}
|
|
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;
|
|
23633
24281
|
}
|
|
23634
24282
|
return false;
|
|
23635
24283
|
}
|
|
@@ -23640,19 +24288,14 @@ function deleteCellSelection(state, dispatch) {
|
|
|
23640
24288
|
const tr = state.tr;
|
|
23641
24289
|
const baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
|
|
23642
24290
|
sel.forEachCell((cell, pos) => {
|
|
23643
|
-
if (!cell.content.eq(baseContent))
|
|
23644
|
-
tr.replace(
|
|
23645
|
-
tr.mapping.map(pos + 1),
|
|
23646
|
-
tr.mapping.map(pos + cell.nodeSize - 1),
|
|
23647
|
-
new Slice(baseContent, 0, 0)
|
|
23648
|
-
);
|
|
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));
|
|
23649
24292
|
});
|
|
23650
24293
|
if (tr.docChanged) dispatch(tr);
|
|
23651
24294
|
}
|
|
23652
24295
|
return true;
|
|
23653
24296
|
}
|
|
23654
24297
|
function pastedCells(slice2) {
|
|
23655
|
-
if (
|
|
24298
|
+
if (slice2.size === 0) return null;
|
|
23656
24299
|
let { content, openStart, openEnd } = slice2;
|
|
23657
24300
|
while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) {
|
|
23658
24301
|
openStart--;
|
|
@@ -23662,28 +24305,15 @@ function pastedCells(slice2) {
|
|
|
23662
24305
|
const first2 = content.child(0);
|
|
23663
24306
|
const role = first2.type.spec.tableRole;
|
|
23664
24307
|
const schema = first2.type.schema, rows = [];
|
|
23665
|
-
if (role == "row") {
|
|
23666
|
-
|
|
23667
|
-
|
|
23668
|
-
|
|
23669
|
-
|
|
23670
|
-
|
|
23671
|
-
|
|
23672
|
-
|
|
23673
|
-
|
|
23674
|
-
).content;
|
|
23675
|
-
rows.push(cells);
|
|
23676
|
-
}
|
|
23677
|
-
} else if (role == "cell" || role == "header_cell") {
|
|
23678
|
-
rows.push(
|
|
23679
|
-
openStart || openEnd ? fitSlice(
|
|
23680
|
-
tableNodeTypes(schema).row,
|
|
23681
|
-
new Slice(content, openStart, openEnd)
|
|
23682
|
-
).content : content
|
|
23683
|
-
);
|
|
23684
|
-
} else {
|
|
23685
|
-
return null;
|
|
23686
|
-
}
|
|
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;
|
|
23687
24317
|
return ensureRectangular(schema, rows);
|
|
23688
24318
|
}
|
|
23689
24319
|
function ensureRectangular(schema, rows) {
|
|
@@ -23692,8 +24322,7 @@ function ensureRectangular(schema, rows) {
|
|
|
23692
24322
|
const row = rows[i];
|
|
23693
24323
|
for (let j = row.childCount - 1; j >= 0; j--) {
|
|
23694
24324
|
const { rowspan, colspan } = row.child(j).attrs;
|
|
23695
|
-
for (let r2 = i; r2 < i + rowspan; r2++)
|
|
23696
|
-
widths[r2] = (widths[r2] || 0) + colspan;
|
|
24325
|
+
for (let r2 = i; r2 < i + rowspan; r2++) widths[r2] = (widths[r2] || 0) + colspan;
|
|
23697
24326
|
}
|
|
23698
24327
|
}
|
|
23699
24328
|
let width = 0;
|
|
@@ -23703,18 +24332,19 @@ function ensureRectangular(schema, rows) {
|
|
|
23703
24332
|
if (widths[r2] < width) {
|
|
23704
24333
|
const empty2 = tableNodeTypes(schema).cell.createAndFill();
|
|
23705
24334
|
const cells = [];
|
|
23706
|
-
for (let i = widths[r2]; i < width; i++)
|
|
23707
|
-
cells.push(empty2);
|
|
23708
|
-
}
|
|
24335
|
+
for (let i = widths[r2]; i < width; i++) cells.push(empty2);
|
|
23709
24336
|
rows[r2] = rows[r2].append(Fragment.from(cells));
|
|
23710
24337
|
}
|
|
23711
24338
|
}
|
|
23712
|
-
return {
|
|
24339
|
+
return {
|
|
24340
|
+
height: rows.length,
|
|
24341
|
+
width,
|
|
24342
|
+
rows
|
|
24343
|
+
};
|
|
23713
24344
|
}
|
|
23714
24345
|
function fitSlice(nodeType, slice2) {
|
|
23715
24346
|
const node = nodeType.createAndFill();
|
|
23716
|
-
|
|
23717
|
-
return tr.doc;
|
|
24347
|
+
return new Transform(node).replace(0, node.content.size, slice2).doc;
|
|
23718
24348
|
}
|
|
23719
24349
|
function clipCells({ width, height, rows }, newWidth, newHeight) {
|
|
23720
24350
|
if (width != newWidth) {
|
|
@@ -23724,19 +24354,10 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
|
|
|
23724
24354
|
const frag = rows[row], cells = [];
|
|
23725
24355
|
for (let col = added[row] || 0, i = 0; col < newWidth; i++) {
|
|
23726
24356
|
let cell = frag.child(i % frag.childCount);
|
|
23727
|
-
if (col + cell.attrs.colspan > newWidth)
|
|
23728
|
-
cell = cell.type.createChecked(
|
|
23729
|
-
removeColSpan(
|
|
23730
|
-
cell.attrs,
|
|
23731
|
-
cell.attrs.colspan,
|
|
23732
|
-
col + cell.attrs.colspan - newWidth
|
|
23733
|
-
),
|
|
23734
|
-
cell.content
|
|
23735
|
-
);
|
|
24357
|
+
if (col + cell.attrs.colspan > newWidth) cell = cell.type.createChecked(removeColSpan(cell.attrs, cell.attrs.colspan, col + cell.attrs.colspan - newWidth), cell.content);
|
|
23736
24358
|
cells.push(cell);
|
|
23737
24359
|
col += cell.attrs.colspan;
|
|
23738
|
-
for (let j = 1; j < cell.attrs.rowspan; j++)
|
|
23739
|
-
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;
|
|
23740
24361
|
}
|
|
23741
24362
|
newRows.push(Fragment.from(cells));
|
|
23742
24363
|
}
|
|
@@ -23749,14 +24370,10 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
|
|
|
23749
24370
|
const cells = [], source = rows[i % height];
|
|
23750
24371
|
for (let j = 0; j < source.childCount; j++) {
|
|
23751
24372
|
let cell = source.child(j);
|
|
23752
|
-
if (row + cell.attrs.rowspan > newHeight)
|
|
23753
|
-
cell
|
|
23754
|
-
|
|
23755
|
-
|
|
23756
|
-
rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
|
|
23757
|
-
},
|
|
23758
|
-
cell.content
|
|
23759
|
-
);
|
|
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);
|
|
23760
24377
|
cells.push(cell);
|
|
23761
24378
|
}
|
|
23762
24379
|
newRows.push(Fragment.from(cells));
|
|
@@ -23764,33 +24381,32 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
|
|
|
23764
24381
|
rows = newRows;
|
|
23765
24382
|
height = newHeight;
|
|
23766
24383
|
}
|
|
23767
|
-
return {
|
|
24384
|
+
return {
|
|
24385
|
+
width,
|
|
24386
|
+
height,
|
|
24387
|
+
rows
|
|
24388
|
+
};
|
|
23768
24389
|
}
|
|
23769
24390
|
function growTable(tr, map2, table, start2, width, height, mapFrom) {
|
|
23770
24391
|
const schema = tr.doc.type.schema;
|
|
23771
24392
|
const types = tableNodeTypes(schema);
|
|
23772
24393
|
let empty2;
|
|
23773
24394
|
let emptyHead;
|
|
23774
|
-
if (width > map2.width) {
|
|
23775
|
-
|
|
23776
|
-
|
|
23777
|
-
|
|
23778
|
-
|
|
23779
|
-
|
|
23780
|
-
|
|
23781
|
-
|
|
23782
|
-
|
|
23783
|
-
for (let i = map2.width; i < width; i++) cells.push(add);
|
|
23784
|
-
tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start2), cells);
|
|
23785
|
-
}
|
|
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);
|
|
23786
24404
|
}
|
|
23787
24405
|
if (height > map2.height) {
|
|
23788
24406
|
const cells = [];
|
|
23789
|
-
for (let i = 0,
|
|
23790
|
-
const header = i >= map2.width ? false : table.nodeAt(map2.map[
|
|
23791
|
-
cells.push(
|
|
23792
|
-
header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty2 || (empty2 = types.cell.createAndFill())
|
|
23793
|
-
);
|
|
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()));
|
|
23794
24410
|
}
|
|
23795
24411
|
const emptyRow = types.row.create(null, Fragment.from(cells)), rows = [];
|
|
23796
24412
|
for (let i = map2.height; i < height; i++) rows.push(emptyRow);
|
|
@@ -23811,13 +24427,10 @@ function isolateHorizontal(tr, map2, table, start2, left2, right2, top2, mapFrom
|
|
|
23811
24427
|
...cell.attrs,
|
|
23812
24428
|
rowspan: top2 - cellTop
|
|
23813
24429
|
});
|
|
23814
|
-
tr.insert(
|
|
23815
|
-
|
|
23816
|
-
cell.
|
|
23817
|
-
|
|
23818
|
-
rowspan: cellTop + cell.attrs.rowspan - top2
|
|
23819
|
-
})
|
|
23820
|
-
);
|
|
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
|
+
}));
|
|
23821
24434
|
col += cell.attrs.colspan - 1;
|
|
23822
24435
|
}
|
|
23823
24436
|
}
|
|
@@ -23833,21 +24446,8 @@ function isolateVertical(tr, map2, table, start2, top2, bottom2, left2, mapFrom)
|
|
|
23833
24446
|
const cell = table.nodeAt(pos);
|
|
23834
24447
|
const cellLeft = map2.colCount(pos);
|
|
23835
24448
|
const updatePos = tr.mapping.slice(mapFrom).map(pos + start2);
|
|
23836
|
-
tr.setNodeMarkup(
|
|
23837
|
-
|
|
23838
|
-
null,
|
|
23839
|
-
removeColSpan(
|
|
23840
|
-
cell.attrs,
|
|
23841
|
-
left2 - cellLeft,
|
|
23842
|
-
cell.attrs.colspan - (left2 - cellLeft)
|
|
23843
|
-
)
|
|
23844
|
-
);
|
|
23845
|
-
tr.insert(
|
|
23846
|
-
updatePos + cell.nodeSize,
|
|
23847
|
-
cell.type.createAndFill(
|
|
23848
|
-
removeColSpan(cell.attrs, 0, left2 - cellLeft)
|
|
23849
|
-
)
|
|
23850
|
-
);
|
|
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)));
|
|
23851
24451
|
row += cell.attrs.rowspan - 1;
|
|
23852
24452
|
}
|
|
23853
24453
|
}
|
|
@@ -23855,9 +24455,7 @@ function isolateVertical(tr, map2, table, start2, top2, bottom2, left2, mapFrom)
|
|
|
23855
24455
|
}
|
|
23856
24456
|
function insertCells(state, dispatch, tableStart, rect, cells) {
|
|
23857
24457
|
let table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc;
|
|
23858
|
-
if (!table)
|
|
23859
|
-
throw new Error("No table found");
|
|
23860
|
-
}
|
|
24458
|
+
if (!table) throw new Error("No table found");
|
|
23861
24459
|
let map2 = TableMap.get(table);
|
|
23862
24460
|
const { top: top2, left: left2 } = rect;
|
|
23863
24461
|
const right2 = left2 + cells.width, bottom2 = top2 + cells.height;
|
|
@@ -23865,39 +24463,24 @@ function insertCells(state, dispatch, tableStart, rect, cells) {
|
|
|
23865
24463
|
let mapFrom = 0;
|
|
23866
24464
|
function recomp() {
|
|
23867
24465
|
table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
|
|
23868
|
-
if (!table)
|
|
23869
|
-
throw new Error("No table found");
|
|
23870
|
-
}
|
|
24466
|
+
if (!table) throw new Error("No table found");
|
|
23871
24467
|
map2 = TableMap.get(table);
|
|
23872
24468
|
mapFrom = tr.mapping.maps.length;
|
|
23873
24469
|
}
|
|
23874
24470
|
if (growTable(tr, map2, table, tableStart, right2, bottom2, mapFrom)) recomp();
|
|
23875
|
-
if (isolateHorizontal(tr, map2, table, tableStart, left2, right2, top2, mapFrom))
|
|
23876
|
-
|
|
23877
|
-
if (
|
|
23878
|
-
|
|
23879
|
-
if (isolateVertical(tr, map2, table, tableStart, top2, bottom2, left2, mapFrom))
|
|
23880
|
-
recomp();
|
|
23881
|
-
if (isolateVertical(tr, map2, table, tableStart, top2, bottom2, right2, mapFrom))
|
|
23882
|
-
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();
|
|
23883
24475
|
for (let row = top2; row < bottom2; row++) {
|
|
23884
24476
|
const from2 = map2.positionAt(row, left2, table), to = map2.positionAt(row, right2, table);
|
|
23885
|
-
tr.replace(
|
|
23886
|
-
tr.mapping.slice(mapFrom).map(from2 + tableStart),
|
|
23887
|
-
tr.mapping.slice(mapFrom).map(to + tableStart),
|
|
23888
|
-
new Slice(cells.rows[row - top2], 0, 0)
|
|
23889
|
-
);
|
|
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));
|
|
23890
24478
|
}
|
|
23891
24479
|
recomp();
|
|
23892
|
-
tr.setSelection(
|
|
23893
|
-
new CellSelection(
|
|
23894
|
-
tr.doc.resolve(tableStart + map2.positionAt(top2, left2, table)),
|
|
23895
|
-
tr.doc.resolve(tableStart + map2.positionAt(bottom2 - 1, right2 - 1, table))
|
|
23896
|
-
)
|
|
23897
|
-
);
|
|
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))));
|
|
23898
24481
|
dispatch(tr);
|
|
23899
24482
|
}
|
|
23900
|
-
|
|
24483
|
+
const handleKeyDown = keydownHandler({
|
|
23901
24484
|
ArrowLeft: arrow$2("horiz", -1),
|
|
23902
24485
|
ArrowRight: arrow$2("horiz", 1),
|
|
23903
24486
|
ArrowUp: arrow$2("vert", -1),
|
|
@@ -23920,29 +24503,17 @@ function arrow$2(axis, dir) {
|
|
|
23920
24503
|
return (state, dispatch, view) => {
|
|
23921
24504
|
if (!view) return false;
|
|
23922
24505
|
const sel = state.selection;
|
|
23923
|
-
if (sel instanceof CellSelection)
|
|
23924
|
-
return maybeSetSelection(
|
|
23925
|
-
state,
|
|
23926
|
-
dispatch,
|
|
23927
|
-
Selection.near(sel.$headCell, dir)
|
|
23928
|
-
);
|
|
23929
|
-
}
|
|
24506
|
+
if (sel instanceof CellSelection) return maybeSetSelection(state, dispatch, Selection.near(sel.$headCell, dir));
|
|
23930
24507
|
if (axis != "horiz" && !sel.empty) return false;
|
|
23931
24508
|
const end2 = atEndOfCell(view, axis, dir);
|
|
23932
24509
|
if (end2 == null) return false;
|
|
23933
|
-
if (axis == "horiz")
|
|
23934
|
-
|
|
23935
|
-
state,
|
|
23936
|
-
dispatch,
|
|
23937
|
-
Selection.near(state.doc.resolve(sel.head + dir), dir)
|
|
23938
|
-
);
|
|
23939
|
-
} else {
|
|
24510
|
+
if (axis == "horiz") return maybeSetSelection(state, dispatch, Selection.near(state.doc.resolve(sel.head + dir), dir));
|
|
24511
|
+
else {
|
|
23940
24512
|
const $cell = state.doc.resolve(end2);
|
|
23941
24513
|
const $next = nextCell($cell, axis, dir);
|
|
23942
24514
|
let newSel;
|
|
23943
24515
|
if ($next) newSel = Selection.near($next, 1);
|
|
23944
|
-
else if (dir < 0)
|
|
23945
|
-
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);
|
|
23946
24517
|
else newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1);
|
|
23947
24518
|
return maybeSetSelection(state, dispatch, newSel);
|
|
23948
24519
|
}
|
|
@@ -23953,20 +24524,15 @@ function shiftArrow(axis, dir) {
|
|
|
23953
24524
|
if (!view) return false;
|
|
23954
24525
|
const sel = state.selection;
|
|
23955
24526
|
let cellSel;
|
|
23956
|
-
if (sel instanceof CellSelection)
|
|
23957
|
-
|
|
23958
|
-
} else {
|
|
24527
|
+
if (sel instanceof CellSelection) cellSel = sel;
|
|
24528
|
+
else {
|
|
23959
24529
|
const end2 = atEndOfCell(view, axis, dir);
|
|
23960
24530
|
if (end2 == null) return false;
|
|
23961
24531
|
cellSel = new CellSelection(state.doc.resolve(end2));
|
|
23962
24532
|
}
|
|
23963
24533
|
const $head = nextCell(cellSel.$headCell, axis, dir);
|
|
23964
24534
|
if (!$head) return false;
|
|
23965
|
-
return maybeSetSelection(
|
|
23966
|
-
state,
|
|
23967
|
-
dispatch,
|
|
23968
|
-
new CellSelection(cellSel.$anchorCell, $head)
|
|
23969
|
-
);
|
|
24535
|
+
return maybeSetSelection(state, dispatch, new CellSelection(cellSel.$anchorCell, $head));
|
|
23970
24536
|
};
|
|
23971
24537
|
}
|
|
23972
24538
|
function handleTripleClick(view, pos) {
|
|
@@ -23980,65 +24546,45 @@ function handlePaste(view, _, slice2) {
|
|
|
23980
24546
|
let cells = pastedCells(slice2);
|
|
23981
24547
|
const sel = view.state.selection;
|
|
23982
24548
|
if (sel instanceof CellSelection) {
|
|
23983
|
-
if (!cells)
|
|
23984
|
-
|
|
23985
|
-
|
|
23986
|
-
|
|
23987
|
-
|
|
23988
|
-
Fragment.from(
|
|
23989
|
-
fitSlice(tableNodeTypes(view.state.schema).cell, slice2)
|
|
23990
|
-
)
|
|
23991
|
-
]
|
|
23992
|
-
};
|
|
24549
|
+
if (!cells) cells = {
|
|
24550
|
+
width: 1,
|
|
24551
|
+
height: 1,
|
|
24552
|
+
rows: [Fragment.from(fitSlice(tableNodeTypes(view.state.schema).cell, slice2))]
|
|
24553
|
+
};
|
|
23993
24554
|
const table = sel.$anchorCell.node(-1);
|
|
23994
24555
|
const start2 = sel.$anchorCell.start(-1);
|
|
23995
|
-
const rect = TableMap.get(table).rectBetween(
|
|
23996
|
-
sel.$anchorCell.pos - start2,
|
|
23997
|
-
sel.$headCell.pos - start2
|
|
23998
|
-
);
|
|
24556
|
+
const rect = TableMap.get(table).rectBetween(sel.$anchorCell.pos - start2, sel.$headCell.pos - start2);
|
|
23999
24557
|
cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
|
|
24000
24558
|
insertCells(view.state, view.dispatch, start2, rect, cells);
|
|
24001
24559
|
return true;
|
|
24002
24560
|
} else if (cells) {
|
|
24003
24561
|
const $cell = selectionCell(view.state);
|
|
24004
24562
|
const start2 = $cell.start(-1);
|
|
24005
|
-
insertCells(
|
|
24006
|
-
view.state,
|
|
24007
|
-
view.dispatch,
|
|
24008
|
-
start2,
|
|
24009
|
-
TableMap.get($cell.node(-1)).findCell($cell.pos - start2),
|
|
24010
|
-
cells
|
|
24011
|
-
);
|
|
24563
|
+
insertCells(view.state, view.dispatch, start2, TableMap.get($cell.node(-1)).findCell($cell.pos - start2), cells);
|
|
24012
24564
|
return true;
|
|
24013
|
-
} else
|
|
24014
|
-
return false;
|
|
24015
|
-
}
|
|
24565
|
+
} else return false;
|
|
24016
24566
|
}
|
|
24017
24567
|
function handleMouseDown(view, startEvent) {
|
|
24018
|
-
var
|
|
24568
|
+
var _cellUnderMouse;
|
|
24019
24569
|
if (startEvent.ctrlKey || startEvent.metaKey) return;
|
|
24020
24570
|
const startDOMCell = domInCell(view, startEvent.target);
|
|
24021
24571
|
let $anchor;
|
|
24022
24572
|
if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
|
|
24023
24573
|
setCellSelection(view.state.selection.$anchorCell, startEvent);
|
|
24024
24574
|
startEvent.preventDefault();
|
|
24025
|
-
} 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) {
|
|
24026
24576
|
setCellSelection($anchor, startEvent);
|
|
24027
24577
|
startEvent.preventDefault();
|
|
24028
|
-
} else if (!startDOMCell)
|
|
24029
|
-
|
|
24030
|
-
}
|
|
24031
|
-
function setCellSelection($anchor2, event) {
|
|
24578
|
+
} else if (!startDOMCell) return;
|
|
24579
|
+
function setCellSelection($anchor$1, event) {
|
|
24032
24580
|
let $head = cellUnderMouse(view, event);
|
|
24033
24581
|
const starting = tableEditingKey.getState(view.state) == null;
|
|
24034
|
-
if (!$head || !inSameTable($
|
|
24035
|
-
|
|
24036
|
-
|
|
24037
|
-
}
|
|
24038
|
-
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);
|
|
24039
24585
|
if (starting || !view.state.selection.eq(selection)) {
|
|
24040
24586
|
const tr = view.state.tr.setSelection(selection);
|
|
24041
|
-
if (starting) tr.setMeta(tableEditingKey, $
|
|
24587
|
+
if (starting) tr.setMeta(tableEditingKey, $anchor$1.pos);
|
|
24042
24588
|
view.dispatch(tr);
|
|
24043
24589
|
}
|
|
24044
24590
|
}
|
|
@@ -24046,20 +24592,18 @@ function handleMouseDown(view, startEvent) {
|
|
|
24046
24592
|
view.root.removeEventListener("mouseup", stop);
|
|
24047
24593
|
view.root.removeEventListener("dragstart", stop);
|
|
24048
24594
|
view.root.removeEventListener("mousemove", move);
|
|
24049
|
-
if (tableEditingKey.getState(view.state) != null)
|
|
24050
|
-
view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
|
|
24595
|
+
if (tableEditingKey.getState(view.state) != null) view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
|
|
24051
24596
|
}
|
|
24052
24597
|
function move(_event) {
|
|
24053
24598
|
const event = _event;
|
|
24054
24599
|
const anchor = tableEditingKey.getState(view.state);
|
|
24055
|
-
let $
|
|
24056
|
-
if (anchor != null)
|
|
24057
|
-
|
|
24058
|
-
|
|
24059
|
-
$
|
|
24060
|
-
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();
|
|
24061
24605
|
}
|
|
24062
|
-
if ($
|
|
24606
|
+
if ($anchor$1) setCellSelection($anchor$1, event);
|
|
24063
24607
|
}
|
|
24064
24608
|
view.root.addEventListener("mouseup", stop);
|
|
24065
24609
|
view.root.addEventListener("dragstart", stop);
|
|
@@ -24069,8 +24613,8 @@ function atEndOfCell(view, axis, dir) {
|
|
|
24069
24613
|
if (!(view.state.selection instanceof TextSelection)) return null;
|
|
24070
24614
|
const { $head } = view.state.selection;
|
|
24071
24615
|
for (let d2 = $head.depth - 1; d2 >= 0; d2--) {
|
|
24072
|
-
const parent = $head.node(d2)
|
|
24073
|
-
if (
|
|
24616
|
+
const parent = $head.node(d2);
|
|
24617
|
+
if ((dir < 0 ? $head.index(d2) : $head.indexAfter(d2)) != (dir < 0 ? 0 : parent.childCount)) return null;
|
|
24074
24618
|
if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
|
|
24075
24619
|
const cellPos = $head.before(d2);
|
|
24076
24620
|
const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
|
|
@@ -24080,11 +24624,7 @@ function atEndOfCell(view, axis, dir) {
|
|
|
24080
24624
|
return null;
|
|
24081
24625
|
}
|
|
24082
24626
|
function domInCell(view, dom) {
|
|
24083
|
-
for (; dom && dom != view.dom; dom = dom.parentNode)
|
|
24084
|
-
if (dom.nodeName == "TD" || dom.nodeName == "TH") {
|
|
24085
|
-
return dom;
|
|
24086
|
-
}
|
|
24087
|
-
}
|
|
24627
|
+
for (; dom && dom != view.dom; dom = dom.parentNode) if (dom.nodeName == "TD" || dom.nodeName == "TH") return dom;
|
|
24088
24628
|
return null;
|
|
24089
24629
|
}
|
|
24090
24630
|
function cellUnderMouse(view, event) {
|
|
@@ -24093,7 +24633,8 @@ function cellUnderMouse(view, event) {
|
|
|
24093
24633
|
top: event.clientY
|
|
24094
24634
|
});
|
|
24095
24635
|
if (!mousePos) return null;
|
|
24096
|
-
|
|
24636
|
+
const pos = mousePos.inside >= 0 ? mousePos.inside : mousePos.pos;
|
|
24637
|
+
return cellAround$1(view.state.doc.resolve(pos));
|
|
24097
24638
|
}
|
|
24098
24639
|
var TableView = class {
|
|
24099
24640
|
constructor(node, defaultCellMinWidth) {
|
|
@@ -24102,10 +24643,7 @@ var TableView = class {
|
|
|
24102
24643
|
this.dom = document.createElement("div");
|
|
24103
24644
|
this.dom.className = "tableWrapper";
|
|
24104
24645
|
this.table = this.dom.appendChild(document.createElement("table"));
|
|
24105
|
-
this.table.style.setProperty(
|
|
24106
|
-
"--default-cell-min-width",
|
|
24107
|
-
`${defaultCellMinWidth}px`
|
|
24108
|
-
);
|
|
24646
|
+
this.table.style.setProperty("--default-cell-min-width", `${defaultCellMinWidth}px`);
|
|
24109
24647
|
this.colgroup = this.table.appendChild(document.createElement("colgroup"));
|
|
24110
24648
|
updateColumnsOnResize(node, this.colgroup, this.table, defaultCellMinWidth);
|
|
24111
24649
|
this.contentDOM = this.table.appendChild(document.createElement("tbody"));
|
|
@@ -24113,12 +24651,7 @@ var TableView = class {
|
|
|
24113
24651
|
update(node) {
|
|
24114
24652
|
if (node.type != this.node.type) return false;
|
|
24115
24653
|
this.node = node;
|
|
24116
|
-
updateColumnsOnResize(
|
|
24117
|
-
node,
|
|
24118
|
-
this.colgroup,
|
|
24119
|
-
this.table,
|
|
24120
|
-
this.defaultCellMinWidth
|
|
24121
|
-
);
|
|
24654
|
+
updateColumnsOnResize(node, this.colgroup, this.table, this.defaultCellMinWidth);
|
|
24122
24655
|
return true;
|
|
24123
24656
|
}
|
|
24124
24657
|
ignoreMutation(record) {
|
|
@@ -24126,7 +24659,6 @@ var TableView = class {
|
|
|
24126
24659
|
}
|
|
24127
24660
|
};
|
|
24128
24661
|
function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overrideCol, overrideValue) {
|
|
24129
|
-
var _a;
|
|
24130
24662
|
let totalWidth = 0;
|
|
24131
24663
|
let fixedWidth = true;
|
|
24132
24664
|
let nextDOM = colgroup.firstChild;
|
|
@@ -24140,20 +24672,19 @@ function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overr
|
|
|
24140
24672
|
totalWidth += hasWidth || defaultCellMinWidth;
|
|
24141
24673
|
if (!hasWidth) fixedWidth = false;
|
|
24142
24674
|
if (!nextDOM) {
|
|
24143
|
-
const
|
|
24144
|
-
|
|
24145
|
-
colgroup.appendChild(
|
|
24675
|
+
const col$1 = document.createElement("col");
|
|
24676
|
+
col$1.style.width = cssWidth;
|
|
24677
|
+
colgroup.appendChild(col$1);
|
|
24146
24678
|
} else {
|
|
24147
|
-
if (nextDOM.style.width != cssWidth)
|
|
24148
|
-
nextDOM.style.width = cssWidth;
|
|
24149
|
-
}
|
|
24679
|
+
if (nextDOM.style.width != cssWidth) nextDOM.style.width = cssWidth;
|
|
24150
24680
|
nextDOM = nextDOM.nextSibling;
|
|
24151
24681
|
}
|
|
24152
24682
|
}
|
|
24153
24683
|
}
|
|
24154
24684
|
while (nextDOM) {
|
|
24685
|
+
var _nextDOM$parentNode;
|
|
24155
24686
|
const after = nextDOM.nextSibling;
|
|
24156
|
-
(
|
|
24687
|
+
(_nextDOM$parentNode = nextDOM.parentNode) === null || _nextDOM$parentNode === void 0 || _nextDOM$parentNode.removeChild(nextDOM);
|
|
24157
24688
|
nextDOM = after;
|
|
24158
24689
|
}
|
|
24159
24690
|
if (fixedWidth) {
|
|
@@ -24164,28 +24695,18 @@ function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overr
|
|
|
24164
24695
|
table.style.minWidth = totalWidth + "px";
|
|
24165
24696
|
}
|
|
24166
24697
|
}
|
|
24167
|
-
|
|
24168
|
-
|
|
24169
|
-
);
|
|
24170
|
-
function columnResizing({
|
|
24171
|
-
handleWidth = 5,
|
|
24172
|
-
cellMinWidth = 25,
|
|
24173
|
-
defaultCellMinWidth = 100,
|
|
24174
|
-
View = TableView,
|
|
24175
|
-
lastColumnResizable = true
|
|
24176
|
-
} = {}) {
|
|
24698
|
+
const columnResizingPluginKey = new PluginKey("tableColumnResizing");
|
|
24699
|
+
function columnResizing({ handleWidth = 5, cellMinWidth = 25, defaultCellMinWidth = 100, View = TableView, lastColumnResizable = true } = {}) {
|
|
24177
24700
|
const plugin = new Plugin({
|
|
24178
24701
|
key: columnResizingPluginKey,
|
|
24179
24702
|
state: {
|
|
24180
24703
|
init(_, state) {
|
|
24181
|
-
var
|
|
24182
|
-
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;
|
|
24183
24706
|
const tableName = tableNodeTypes(state.schema).table.name;
|
|
24184
|
-
if (View && nodeViews) {
|
|
24185
|
-
|
|
24186
|
-
|
|
24187
|
-
};
|
|
24188
|
-
}
|
|
24707
|
+
if (View && nodeViews) nodeViews[tableName] = (node, view) => {
|
|
24708
|
+
return new View(node, defaultCellMinWidth, view);
|
|
24709
|
+
};
|
|
24189
24710
|
return new ResizeState(-1, false);
|
|
24190
24711
|
},
|
|
24191
24712
|
apply(tr, prev) {
|
|
@@ -24205,21 +24726,19 @@ function columnResizing({
|
|
|
24205
24726
|
handleMouseLeave(view);
|
|
24206
24727
|
},
|
|
24207
24728
|
mousedown: (view, event) => {
|
|
24208
|
-
|
|
24729
|
+
handleMouseDown$1(view, event, cellMinWidth, defaultCellMinWidth);
|
|
24209
24730
|
}
|
|
24210
24731
|
},
|
|
24211
24732
|
decorations: (state) => {
|
|
24212
24733
|
const pluginState = columnResizingPluginKey.getState(state);
|
|
24213
|
-
if (pluginState && pluginState.activeHandle > -1)
|
|
24214
|
-
return handleDecorations(state, pluginState.activeHandle);
|
|
24215
|
-
}
|
|
24734
|
+
if (pluginState && pluginState.activeHandle > -1) return handleDecorations(state, pluginState.activeHandle);
|
|
24216
24735
|
},
|
|
24217
24736
|
nodeViews: {}
|
|
24218
24737
|
}
|
|
24219
24738
|
});
|
|
24220
24739
|
return plugin;
|
|
24221
24740
|
}
|
|
24222
|
-
var ResizeState = class
|
|
24741
|
+
var ResizeState = class ResizeState2 {
|
|
24223
24742
|
constructor(activeHandle, dragging) {
|
|
24224
24743
|
this.activeHandle = activeHandle;
|
|
24225
24744
|
this.dragging = dragging;
|
|
@@ -24227,16 +24746,12 @@ var ResizeState = class _ResizeState {
|
|
|
24227
24746
|
apply(tr) {
|
|
24228
24747
|
const state = this;
|
|
24229
24748
|
const action = tr.getMeta(columnResizingPluginKey);
|
|
24230
|
-
if (action && action.setHandle != null)
|
|
24231
|
-
|
|
24232
|
-
if (action && action.setDragging !== void 0)
|
|
24233
|
-
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);
|
|
24234
24751
|
if (state.activeHandle > -1 && tr.docChanged) {
|
|
24235
24752
|
let handle = tr.mapping.map(state.activeHandle, -1);
|
|
24236
|
-
if (!pointsAtCell(tr.doc.resolve(handle)))
|
|
24237
|
-
|
|
24238
|
-
}
|
|
24239
|
-
return new _ResizeState(handle, state.dragging);
|
|
24753
|
+
if (!pointsAtCell(tr.doc.resolve(handle))) handle = -1;
|
|
24754
|
+
return new ResizeState2(handle, state.dragging);
|
|
24240
24755
|
}
|
|
24241
24756
|
return state;
|
|
24242
24757
|
}
|
|
@@ -24250,10 +24765,8 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
|
|
|
24250
24765
|
let cell = -1;
|
|
24251
24766
|
if (target) {
|
|
24252
24767
|
const { left: left2, right: right2 } = target.getBoundingClientRect();
|
|
24253
|
-
if (event.clientX - left2 <= handleWidth)
|
|
24254
|
-
|
|
24255
|
-
else if (right2 - event.clientX <= handleWidth)
|
|
24256
|
-
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);
|
|
24257
24770
|
}
|
|
24258
24771
|
if (cell != pluginState.activeHandle) {
|
|
24259
24772
|
if (!lastColumnResizable && cell !== -1) {
|
|
@@ -24261,10 +24774,7 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
|
|
|
24261
24774
|
const table = $cell.node(-1);
|
|
24262
24775
|
const map2 = TableMap.get(table);
|
|
24263
24776
|
const tableStart = $cell.start(-1);
|
|
24264
|
-
|
|
24265
|
-
if (col == map2.width - 1) {
|
|
24266
|
-
return;
|
|
24267
|
-
}
|
|
24777
|
+
if (map2.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1 == map2.width - 1) return;
|
|
24268
24778
|
}
|
|
24269
24779
|
updateHandle(view, cell);
|
|
24270
24780
|
}
|
|
@@ -24273,58 +24783,39 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
|
|
|
24273
24783
|
function handleMouseLeave(view) {
|
|
24274
24784
|
if (!view.editable) return;
|
|
24275
24785
|
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
24276
|
-
if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging)
|
|
24277
|
-
updateHandle(view, -1);
|
|
24786
|
+
if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging) updateHandle(view, -1);
|
|
24278
24787
|
}
|
|
24279
|
-
function
|
|
24280
|
-
var
|
|
24788
|
+
function handleMouseDown$1(view, event, cellMinWidth, defaultCellMinWidth) {
|
|
24789
|
+
var _view$dom$ownerDocume;
|
|
24281
24790
|
if (!view.editable) return false;
|
|
24282
|
-
const win = (
|
|
24791
|
+
const win = (_view$dom$ownerDocume = view.dom.ownerDocument.defaultView) !== null && _view$dom$ownerDocume !== void 0 ? _view$dom$ownerDocume : window;
|
|
24283
24792
|
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
24284
|
-
if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging)
|
|
24285
|
-
return false;
|
|
24793
|
+
if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging) return false;
|
|
24286
24794
|
const cell = view.state.doc.nodeAt(pluginState.activeHandle);
|
|
24287
24795
|
const width = currentColWidth(view, pluginState.activeHandle, cell.attrs);
|
|
24288
|
-
view.dispatch(
|
|
24289
|
-
|
|
24290
|
-
|
|
24291
|
-
|
|
24292
|
-
)
|
|
24293
|
-
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) {
|
|
24294
24801
|
win.removeEventListener("mouseup", finish);
|
|
24295
24802
|
win.removeEventListener("mousemove", move);
|
|
24296
|
-
const
|
|
24297
|
-
if (
|
|
24298
|
-
updateColumnWidth(
|
|
24299
|
-
|
|
24300
|
-
pluginState2.activeHandle,
|
|
24301
|
-
draggedWidth(pluginState2.dragging, event2, cellMinWidth)
|
|
24302
|
-
);
|
|
24303
|
-
view.dispatch(
|
|
24304
|
-
view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null })
|
|
24305
|
-
);
|
|
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 }));
|
|
24306
24807
|
}
|
|
24307
24808
|
}
|
|
24308
|
-
function move(
|
|
24309
|
-
if (!
|
|
24310
|
-
const
|
|
24311
|
-
if (!
|
|
24312
|
-
if (
|
|
24313
|
-
const dragged = draggedWidth(
|
|
24314
|
-
displayColumnWidth(
|
|
24315
|
-
view,
|
|
24316
|
-
pluginState2.activeHandle,
|
|
24317
|
-
dragged,
|
|
24318
|
-
defaultCellMinWidth
|
|
24319
|
-
);
|
|
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);
|
|
24320
24816
|
}
|
|
24321
24817
|
}
|
|
24322
|
-
displayColumnWidth(
|
|
24323
|
-
view,
|
|
24324
|
-
pluginState.activeHandle,
|
|
24325
|
-
width,
|
|
24326
|
-
defaultCellMinWidth
|
|
24327
|
-
);
|
|
24818
|
+
displayColumnWidth(view, pluginState.activeHandle, width, defaultCellMinWidth);
|
|
24328
24819
|
win.addEventListener("mouseup", finish);
|
|
24329
24820
|
win.addEventListener("mousemove", move);
|
|
24330
24821
|
event.preventDefault();
|
|
@@ -24334,20 +24825,17 @@ function currentColWidth(view, cellPos, { colspan, colwidth }) {
|
|
|
24334
24825
|
const width = colwidth && colwidth[colwidth.length - 1];
|
|
24335
24826
|
if (width) return width;
|
|
24336
24827
|
const dom = view.domAtPos(cellPos);
|
|
24337
|
-
|
|
24338
|
-
let domWidth = node.offsetWidth, parts = colspan;
|
|
24828
|
+
let domWidth = dom.node.childNodes[dom.offset].offsetWidth, parts = colspan;
|
|
24339
24829
|
if (colwidth) {
|
|
24340
|
-
for (let i = 0; i < colspan; i++)
|
|
24341
|
-
|
|
24342
|
-
|
|
24343
|
-
|
|
24344
|
-
}
|
|
24830
|
+
for (let i = 0; i < colspan; i++) if (colwidth[i]) {
|
|
24831
|
+
domWidth -= colwidth[i];
|
|
24832
|
+
parts--;
|
|
24833
|
+
}
|
|
24345
24834
|
}
|
|
24346
24835
|
return domWidth / parts;
|
|
24347
24836
|
}
|
|
24348
24837
|
function domCellAround(target) {
|
|
24349
|
-
while (target && target.nodeName != "TD" && target.nodeName != "TH")
|
|
24350
|
-
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;
|
|
24351
24839
|
return target;
|
|
24352
24840
|
}
|
|
24353
24841
|
function edgeCell(view, event, side, handleWidth) {
|
|
@@ -24370,9 +24858,7 @@ function draggedWidth(dragging, event, resizeMinWidth) {
|
|
|
24370
24858
|
return Math.max(resizeMinWidth, dragging.startWidth + offset2);
|
|
24371
24859
|
}
|
|
24372
24860
|
function updateHandle(view, value) {
|
|
24373
|
-
view.dispatch(
|
|
24374
|
-
view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value })
|
|
24375
|
-
);
|
|
24861
|
+
view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value }));
|
|
24376
24862
|
}
|
|
24377
24863
|
function updateColumnWidth(view, cell, width) {
|
|
24378
24864
|
const $cell = view.state.doc.resolve(cell);
|
|
@@ -24388,7 +24874,10 @@ function updateColumnWidth(view, cell, width) {
|
|
|
24388
24874
|
if (attrs.colwidth && attrs.colwidth[index2] == width) continue;
|
|
24389
24875
|
const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan);
|
|
24390
24876
|
colwidth[index2] = width;
|
|
24391
|
-
tr.setNodeMarkup(start2 + pos, null, {
|
|
24877
|
+
tr.setNodeMarkup(start2 + pos, null, {
|
|
24878
|
+
...attrs,
|
|
24879
|
+
colwidth
|
|
24880
|
+
});
|
|
24392
24881
|
}
|
|
24393
24882
|
if (tr.docChanged) view.dispatch(tr);
|
|
24394
24883
|
}
|
|
@@ -24397,64 +24886,38 @@ function displayColumnWidth(view, cell, width, defaultCellMinWidth) {
|
|
|
24397
24886
|
const table = $cell.node(-1), start2 = $cell.start(-1);
|
|
24398
24887
|
const col = TableMap.get(table).colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
|
|
24399
24888
|
let dom = view.domAtPos($cell.start(-1)).node;
|
|
24400
|
-
while (dom && dom.nodeName != "TABLE")
|
|
24401
|
-
dom = dom.parentNode;
|
|
24402
|
-
}
|
|
24889
|
+
while (dom && dom.nodeName != "TABLE") dom = dom.parentNode;
|
|
24403
24890
|
if (!dom) return;
|
|
24404
|
-
updateColumnsOnResize(
|
|
24405
|
-
table,
|
|
24406
|
-
dom.firstChild,
|
|
24407
|
-
dom,
|
|
24408
|
-
defaultCellMinWidth,
|
|
24409
|
-
col,
|
|
24410
|
-
width
|
|
24411
|
-
);
|
|
24891
|
+
updateColumnsOnResize(table, dom.firstChild, dom, defaultCellMinWidth, col, width);
|
|
24412
24892
|
}
|
|
24413
24893
|
function zeroes(n) {
|
|
24414
24894
|
return Array(n).fill(0);
|
|
24415
24895
|
}
|
|
24416
24896
|
function handleDecorations(state, cell) {
|
|
24417
|
-
var _a;
|
|
24418
24897
|
const decorations = [];
|
|
24419
24898
|
const $cell = state.doc.resolve(cell);
|
|
24420
24899
|
const table = $cell.node(-1);
|
|
24421
|
-
if (!table)
|
|
24422
|
-
return DecorationSet.empty;
|
|
24423
|
-
}
|
|
24900
|
+
if (!table) return DecorationSet.empty;
|
|
24424
24901
|
const map2 = TableMap.get(table);
|
|
24425
24902
|
const start2 = $cell.start(-1);
|
|
24426
24903
|
const col = map2.colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
|
|
24427
24904
|
for (let row = 0; row < map2.height; row++) {
|
|
24428
24905
|
const index2 = col + row * map2.width;
|
|
24429
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;
|
|
24430
24908
|
const cellPos = map2.map[index2];
|
|
24431
24909
|
const pos = start2 + cellPos + table.nodeAt(cellPos).nodeSize - 1;
|
|
24432
24910
|
const dom = document.createElement("div");
|
|
24433
24911
|
dom.className = "column-resize-handle";
|
|
24434
|
-
if ((
|
|
24435
|
-
decorations.push(
|
|
24436
|
-
Decoration.node(
|
|
24437
|
-
start2 + cellPos,
|
|
24438
|
-
start2 + cellPos + table.nodeAt(cellPos).nodeSize,
|
|
24439
|
-
{
|
|
24440
|
-
class: "column-resize-dragging"
|
|
24441
|
-
}
|
|
24442
|
-
)
|
|
24443
|
-
);
|
|
24444
|
-
}
|
|
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" }));
|
|
24445
24913
|
decorations.push(Decoration.widget(pos, dom));
|
|
24446
24914
|
}
|
|
24447
24915
|
}
|
|
24448
24916
|
return DecorationSet.create(state.doc, decorations);
|
|
24449
24917
|
}
|
|
24450
|
-
function tableEditing({
|
|
24451
|
-
allowTableNodeSelection = false
|
|
24452
|
-
} = {}) {
|
|
24918
|
+
function tableEditing({ allowTableNodeSelection = false } = {}) {
|
|
24453
24919
|
return new Plugin({
|
|
24454
24920
|
key: tableEditingKey,
|
|
24455
|
-
// This piece of state is used to remember when a mouse-drag
|
|
24456
|
-
// cell-selection is happening, so that it can continue even as
|
|
24457
|
-
// transactions (which might move its anchor cell) come in.
|
|
24458
24921
|
state: {
|
|
24459
24922
|
init() {
|
|
24460
24923
|
return null;
|
|
@@ -24469,9 +24932,7 @@ function tableEditing({
|
|
|
24469
24932
|
},
|
|
24470
24933
|
props: {
|
|
24471
24934
|
decorations: drawCellSelection,
|
|
24472
|
-
handleDOMEvents: {
|
|
24473
|
-
mousedown: handleMouseDown
|
|
24474
|
-
},
|
|
24935
|
+
handleDOMEvents: { mousedown: handleMouseDown },
|
|
24475
24936
|
createSelectionBetween(view) {
|
|
24476
24937
|
return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
|
|
24477
24938
|
},
|
|
@@ -24480,11 +24941,7 @@ function tableEditing({
|
|
|
24480
24941
|
handlePaste
|
|
24481
24942
|
},
|
|
24482
24943
|
appendTransaction(_, oldState, state) {
|
|
24483
|
-
return normalizeSelection(
|
|
24484
|
-
state,
|
|
24485
|
-
fixTables(state, oldState),
|
|
24486
|
-
allowTableNodeSelection
|
|
24487
|
-
);
|
|
24944
|
+
return normalizeSelection(state, fixTables(state, oldState), allowTableNodeSelection);
|
|
24488
24945
|
}
|
|
24489
24946
|
});
|
|
24490
24947
|
}
|
|
@@ -24509,12 +24966,12 @@ const deleteTableWhenSelected = ({ editor }) => {
|
|
|
24509
24966
|
editor.commands.deleteTable();
|
|
24510
24967
|
return true;
|
|
24511
24968
|
};
|
|
24512
|
-
const createCellBorders = ({ size = 0.66665, color = "#000000" } = {}) => {
|
|
24969
|
+
const createCellBorders = ({ size: size2 = 0.66665, color = "#000000" } = {}) => {
|
|
24513
24970
|
return {
|
|
24514
|
-
top: { size, color },
|
|
24515
|
-
left: { size, color },
|
|
24516
|
-
bottom: { size, color },
|
|
24517
|
-
right: { size, color }
|
|
24971
|
+
top: { size: size2, color },
|
|
24972
|
+
left: { size: size2, color },
|
|
24973
|
+
bottom: { size: size2, color },
|
|
24974
|
+
right: { size: size2, color }
|
|
24518
24975
|
};
|
|
24519
24976
|
};
|
|
24520
24977
|
function cellAround($pos) {
|
|
@@ -24695,8 +25152,8 @@ const Table = Node$1.create({
|
|
|
24695
25152
|
default: {},
|
|
24696
25153
|
renderDOM({ borders }) {
|
|
24697
25154
|
if (!borders) return {};
|
|
24698
|
-
const style = Object.entries(borders).reduce((acc, [key2, { size, color }]) => {
|
|
24699
|
-
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"};`;
|
|
24700
25157
|
}, "");
|
|
24701
25158
|
return {
|
|
24702
25159
|
style
|
|
@@ -24818,8 +25275,8 @@ const Table = Node$1.create({
|
|
|
24818
25275
|
let resolvedTablePos = tablePos;
|
|
24819
25276
|
if (typeof resolvedTablePos !== "number" && workingTable) {
|
|
24820
25277
|
const tables = editor.getNodesOfType("table");
|
|
24821
|
-
const
|
|
24822
|
-
resolvedTablePos =
|
|
25278
|
+
const match2 = workingTable ? tables.find((t) => t.node.eq(workingTable)) : tables[0];
|
|
25279
|
+
resolvedTablePos = match2?.pos ?? null;
|
|
24823
25280
|
}
|
|
24824
25281
|
if (typeof resolvedTablePos !== "number") {
|
|
24825
25282
|
return false;
|
|
@@ -26475,9 +26932,9 @@ const FieldAnnotation = Node$1.create({
|
|
|
26475
26932
|
},
|
|
26476
26933
|
size: {
|
|
26477
26934
|
default: null,
|
|
26478
|
-
renderDOM: ({ size }) => {
|
|
26479
|
-
if (!
|
|
26480
|
-
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;`;
|
|
26481
26938
|
return { style };
|
|
26482
26939
|
}
|
|
26483
26940
|
},
|
|
@@ -27597,7 +28054,7 @@ const generateUniqueDocPrId = (editor) => {
|
|
|
27597
28054
|
} while (!candidate || existingIds.has(candidate));
|
|
27598
28055
|
return candidate;
|
|
27599
28056
|
};
|
|
27600
|
-
async function uploadAndInsertImage({ editor, view, file, size, id }) {
|
|
28057
|
+
async function uploadAndInsertImage({ editor, view, file, size: size2, id }) {
|
|
27601
28058
|
const imageUploadHandler = typeof editor.options.handleImageUpload === "function" ? editor.options.handleImageUpload : handleImageUpload;
|
|
27602
28059
|
const placeholderId = id;
|
|
27603
28060
|
try {
|
|
@@ -27622,7 +28079,7 @@ async function uploadAndInsertImage({ editor, view, file, size, id }) {
|
|
|
27622
28079
|
}
|
|
27623
28080
|
let imageNode = view.state.schema.nodes.image.create({
|
|
27624
28081
|
src: mediaPath,
|
|
27625
|
-
size,
|
|
28082
|
+
size: size2,
|
|
27626
28083
|
id: docPrId,
|
|
27627
28084
|
rId
|
|
27628
28085
|
});
|
|
@@ -27913,7 +28370,7 @@ const getImagePositionDecorations = (state, view) => {
|
|
|
27913
28370
|
let style = "";
|
|
27914
28371
|
let className = "";
|
|
27915
28372
|
const { vRelativeFrom, alignH } = node.attrs.anchorData;
|
|
27916
|
-
const { size, padding } = node.attrs;
|
|
28373
|
+
const { size: size2, padding } = node.attrs;
|
|
27917
28374
|
const pageBreak = findPreviousDomNodeWithClass(view, pos, "pagination-break-wrapper");
|
|
27918
28375
|
if (pageBreak && vRelativeFrom === "margin" && alignH) {
|
|
27919
28376
|
let pageBreakPos = pageBreakPositionCache.get(pageBreak);
|
|
@@ -27933,7 +28390,7 @@ const getImagePositionDecorations = (state, view) => {
|
|
|
27933
28390
|
const $pos = view.state.doc.resolve(pos);
|
|
27934
28391
|
decorations.push(
|
|
27935
28392
|
Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
|
|
27936
|
-
style: `height: ${
|
|
28393
|
+
style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
|
|
27937
28394
|
})
|
|
27938
28395
|
);
|
|
27939
28396
|
}
|
|
@@ -27946,8 +28403,8 @@ const getImagePositionDecorations = (state, view) => {
|
|
|
27946
28403
|
} else {
|
|
27947
28404
|
paddingHorizontal = parseInt(padding[alignH]) || 0;
|
|
27948
28405
|
}
|
|
27949
|
-
imageBlock.style.width =
|
|
27950
|
-
imageBlock.style.height =
|
|
28406
|
+
imageBlock.style.width = size2.width + paddingHorizontal + "px";
|
|
28407
|
+
imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
|
|
27951
28408
|
decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
|
|
27952
28409
|
decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style, class: className }));
|
|
27953
28410
|
}
|
|
@@ -28151,9 +28608,9 @@ const Image = Node$1.create({
|
|
|
28151
28608
|
extension: { rendered: false },
|
|
28152
28609
|
size: {
|
|
28153
28610
|
default: {},
|
|
28154
|
-
renderDOM: ({ size, extension }) => {
|
|
28611
|
+
renderDOM: ({ size: size2, extension }) => {
|
|
28155
28612
|
let style = "";
|
|
28156
|
-
let { width, height } =
|
|
28613
|
+
let { width, height } = size2 ?? {};
|
|
28157
28614
|
if (width) style += `width: ${width}px;`;
|
|
28158
28615
|
if (height && ["emf", "wmf"].includes(extension))
|
|
28159
28616
|
style += `height: ${height}px; border: 1px solid black; position: absolute;`;
|
|
@@ -28190,7 +28647,7 @@ const Image = Node$1.create({
|
|
|
28190
28647
|
},
|
|
28191
28648
|
renderDOM({ node, htmlAttributes }) {
|
|
28192
28649
|
const { wrap, marginOffset } = getNormalizedImageAttrs(node.attrs);
|
|
28193
|
-
const { anchorData, padding, transformData = {}, size = { width: 0, height: 0 } } = node.attrs;
|
|
28650
|
+
const { anchorData, padding, transformData = {}, size: size2 = { width: 0, height: 0 } } = node.attrs;
|
|
28194
28651
|
const margin = {
|
|
28195
28652
|
left: 0,
|
|
28196
28653
|
right: 0,
|
|
@@ -28208,7 +28665,7 @@ const Image = Node$1.create({
|
|
|
28208
28665
|
if (padding.bottom) margin.bottom += padding.bottom;
|
|
28209
28666
|
}
|
|
28210
28667
|
const { rotation } = transformData;
|
|
28211
|
-
const { height, width } =
|
|
28668
|
+
const { height, width } = size2;
|
|
28212
28669
|
if (rotation && height && width) {
|
|
28213
28670
|
const { horizontal, vertical } = getRotationMargins(width, height, rotation);
|
|
28214
28671
|
margin.left += horizontal;
|
|
@@ -28238,7 +28695,7 @@ const Image = Node$1.create({
|
|
|
28238
28695
|
const pageStylesData = getDataFromPageStyles({
|
|
28239
28696
|
editor: this.editor,
|
|
28240
28697
|
marginOffset,
|
|
28241
|
-
size,
|
|
28698
|
+
size: size2,
|
|
28242
28699
|
attrs
|
|
28243
28700
|
});
|
|
28244
28701
|
style += pageStylesData.style;
|
|
@@ -28256,7 +28713,7 @@ const Image = Node$1.create({
|
|
|
28256
28713
|
const pageStylesData = getDataFromPageStyles({
|
|
28257
28714
|
editor: this.editor,
|
|
28258
28715
|
marginOffset,
|
|
28259
|
-
size,
|
|
28716
|
+
size: size2,
|
|
28260
28717
|
attrs
|
|
28261
28718
|
});
|
|
28262
28719
|
style += pageStylesData.style;
|
|
@@ -28281,8 +28738,8 @@ const Image = Node$1.create({
|
|
|
28281
28738
|
});
|
|
28282
28739
|
const originalWidth = maxX - minX;
|
|
28283
28740
|
const originalHeight = maxY - minY;
|
|
28284
|
-
const scaleWidth = Math.min(1,
|
|
28285
|
-
const scaleHeight = Math.min(1,
|
|
28741
|
+
const scaleWidth = Math.min(1, size2.width / originalWidth);
|
|
28742
|
+
const scaleHeight = Math.min(1, size2.height / originalHeight);
|
|
28286
28743
|
const verticalOffset = Math.max(0, marginOffset.top);
|
|
28287
28744
|
const points = attrs.polygon.map(([x, y]) => `${horizontalOffset + x * scaleWidth}px ${verticalOffset + y * scaleHeight}px`).join(", ");
|
|
28288
28745
|
style += `shape-outside: polygon(${points});`;
|
|
@@ -28338,7 +28795,7 @@ const Image = Node$1.create({
|
|
|
28338
28795
|
let rotationHorizontal = 0;
|
|
28339
28796
|
let rotationTop = 0;
|
|
28340
28797
|
const { rotation: rotation2 } = transformData ?? {};
|
|
28341
|
-
const { height: height2, width: width2 } =
|
|
28798
|
+
const { height: height2, width: width2 } = size2 ?? {};
|
|
28342
28799
|
if (rotation2 && height2 && width2) {
|
|
28343
28800
|
const { horizontal: horizontal2, vertical } = getRotationMargins(width2, height2, rotation2);
|
|
28344
28801
|
rotationHorizontal = horizontal2;
|
|
@@ -28479,17 +28936,17 @@ const Image = Node$1.create({
|
|
|
28479
28936
|
return [ImageRegistrationPlugin({ editor: this.editor }), ImagePositionPlugin({ editor: this.editor })];
|
|
28480
28937
|
}
|
|
28481
28938
|
});
|
|
28482
|
-
const getDataFromPageStyles = ({ editor, marginOffset, size, attrs }) => {
|
|
28939
|
+
const getDataFromPageStyles = ({ editor, marginOffset, size: size2, attrs }) => {
|
|
28483
28940
|
let style = "";
|
|
28484
28941
|
let floatRight = false;
|
|
28485
28942
|
let baseHorizontal = marginOffset?.horizontal || 0;
|
|
28486
28943
|
const pageStyles = editor?.converter?.pageStyles || editor?.options.parentEditor?.converter?.pageStyles;
|
|
28487
|
-
if (pageStyles?.pageSize && pageStyles?.pageMargins &&
|
|
28944
|
+
if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
|
|
28488
28945
|
const pageWidth = inchesToPixels(pageStyles.pageSize.width);
|
|
28489
28946
|
const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
|
|
28490
28947
|
const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
|
|
28491
28948
|
const contentWidth = pageWidth - leftMargin - rightMargin;
|
|
28492
|
-
const imageWidth =
|
|
28949
|
+
const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
|
|
28493
28950
|
const leftSpace = marginOffset.horizontal;
|
|
28494
28951
|
const rightSpace = contentWidth - leftSpace - imageWidth;
|
|
28495
28952
|
if (rightSpace < 0) {
|
|
@@ -29183,14 +29640,14 @@ const ContentBlock = Node$1.create({
|
|
|
29183
29640
|
},
|
|
29184
29641
|
size: {
|
|
29185
29642
|
default: null,
|
|
29186
|
-
renderDOM: ({ size }) => {
|
|
29187
|
-
if (!
|
|
29643
|
+
renderDOM: ({ size: size2 }) => {
|
|
29644
|
+
if (!size2) return {};
|
|
29188
29645
|
let style = "";
|
|
29189
|
-
if (
|
|
29190
|
-
if (
|
|
29191
|
-
if (
|
|
29192
|
-
if (
|
|
29193
|
-
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`}; `;
|
|
29194
29651
|
return { style };
|
|
29195
29652
|
}
|
|
29196
29653
|
},
|
|
@@ -31905,12 +32362,12 @@ class ShapeGroupView {
|
|
|
31905
32362
|
}
|
|
31906
32363
|
createElement() {
|
|
31907
32364
|
const attrs = this.node.attrs;
|
|
31908
|
-
const { groupTransform, shapes, size } = attrs;
|
|
32365
|
+
const { groupTransform, shapes, size: size2 } = attrs;
|
|
31909
32366
|
const container = document.createElement("div");
|
|
31910
32367
|
container.classList.add("sd-shape-group");
|
|
31911
32368
|
container.setAttribute("data-shape-group", "");
|
|
31912
|
-
const width =
|
|
31913
|
-
const height =
|
|
32369
|
+
const width = size2?.width || groupTransform?.width || 300;
|
|
32370
|
+
const height = size2?.height || groupTransform?.height || 200;
|
|
31914
32371
|
container.style.width = `${width}px`;
|
|
31915
32372
|
container.style.height = `${height}px`;
|
|
31916
32373
|
container.style.position = "relative";
|
|
@@ -36374,8 +36831,8 @@ class Popover {
|
|
|
36374
36831
|
if (from2 < 1) return false;
|
|
36375
36832
|
const textBefore = this.getMentionText(from2);
|
|
36376
36833
|
const mentionPattern = /(?:^|\s)@[\w]*$/;
|
|
36377
|
-
const
|
|
36378
|
-
return
|
|
36834
|
+
const match2 = textBefore.match(mentionPattern);
|
|
36835
|
+
return match2 && this.state.selection.empty;
|
|
36379
36836
|
}
|
|
36380
36837
|
destroy() {
|
|
36381
36838
|
this.tippyInstance.destroy();
|
|
@@ -36883,10 +37340,10 @@ function getScale(element) {
|
|
|
36883
37340
|
const {
|
|
36884
37341
|
width,
|
|
36885
37342
|
height,
|
|
36886
|
-
$
|
|
37343
|
+
$: $2
|
|
36887
37344
|
} = getCssDimensions(domElement);
|
|
36888
|
-
let x = ($ ? round(rect.width) : rect.width) / width;
|
|
36889
|
-
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;
|
|
36890
37347
|
if (!x || !Number.isFinite(x)) {
|
|
36891
37348
|
x = 1;
|
|
36892
37349
|
}
|
|
@@ -38227,8 +38684,8 @@ class SearchQuery {
|
|
|
38227
38684
|
let $from = state.doc.resolve(result.from);
|
|
38228
38685
|
let marks = $from.marksAcross(state.doc.resolve(result.to));
|
|
38229
38686
|
let ranges = [];
|
|
38230
|
-
let frag = Fragment.empty, pos = result.from, { match } = result;
|
|
38231
|
-
let groups =
|
|
38687
|
+
let frag = Fragment.empty, pos = result.from, { match: match2 } = result;
|
|
38688
|
+
let groups = match2 ? getGroupIndices(match2) : [[0, result.to - result.from]];
|
|
38232
38689
|
let replParts = parseReplacement(this.unquote(this.replace));
|
|
38233
38690
|
for (let part of replParts) {
|
|
38234
38691
|
if (typeof part == "string") {
|
|
@@ -38306,39 +38763,39 @@ class RegExpQuery {
|
|
|
38306
38763
|
return scanTextblocks(state.doc, from2, to, (node, start2) => {
|
|
38307
38764
|
let content = textContent(node).slice(0, Math.min(node.content.size, to - start2));
|
|
38308
38765
|
this.regexp.lastIndex = from2 - start2;
|
|
38309
|
-
let
|
|
38310
|
-
if (!
|
|
38311
|
-
const absoluteIndex =
|
|
38766
|
+
let match2 = this.regexp.exec(content);
|
|
38767
|
+
if (!match2) return null;
|
|
38768
|
+
const absoluteIndex = match2.index;
|
|
38312
38769
|
const fromPos = mapIndexToDocPos(node, start2, absoluteIndex);
|
|
38313
|
-
const toPos = mapIndexToDocPos(node, start2, absoluteIndex +
|
|
38314
|
-
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 };
|
|
38315
38772
|
});
|
|
38316
38773
|
}
|
|
38317
38774
|
findPrev(state, from2, to) {
|
|
38318
38775
|
return scanTextblocks(state.doc, from2, to, (node, start2) => {
|
|
38319
38776
|
let content = textContent(node).slice(0, Math.min(node.content.size, from2 - start2));
|
|
38320
|
-
let
|
|
38777
|
+
let match2;
|
|
38321
38778
|
for (let off = 0; ; ) {
|
|
38322
38779
|
this.regexp.lastIndex = off;
|
|
38323
38780
|
let next = this.regexp.exec(content);
|
|
38324
38781
|
if (!next) break;
|
|
38325
|
-
|
|
38782
|
+
match2 = next;
|
|
38326
38783
|
off = next.index + 1;
|
|
38327
38784
|
}
|
|
38328
|
-
if (!
|
|
38329
|
-
const absoluteIndex =
|
|
38785
|
+
if (!match2) return null;
|
|
38786
|
+
const absoluteIndex = match2.index;
|
|
38330
38787
|
const fromPos = mapIndexToDocPos(node, start2, absoluteIndex);
|
|
38331
|
-
const toPos = mapIndexToDocPos(node, start2, absoluteIndex +
|
|
38332
|
-
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 };
|
|
38333
38790
|
});
|
|
38334
38791
|
}
|
|
38335
38792
|
}
|
|
38336
|
-
function getGroupIndices(
|
|
38337
|
-
if (
|
|
38338
|
-
let result = [[0,
|
|
38339
|
-
for (let i = 1, pos = 0; i <
|
|
38340
|
-
let found =
|
|
38341
|
-
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]);
|
|
38342
38799
|
}
|
|
38343
38800
|
return result;
|
|
38344
38801
|
}
|
|
@@ -38579,8 +39036,8 @@ const Search = Extension.create({
|
|
|
38579
39036
|
const matches = storage?.searchResults;
|
|
38580
39037
|
if (!matches?.length) return null;
|
|
38581
39038
|
const decorations = matches.map(
|
|
38582
|
-
(
|
|
38583
|
-
id: `search-match-${
|
|
39039
|
+
(match2) => Decoration.inline(match2.from, match2.to, {
|
|
39040
|
+
id: `search-match-${match2.id}`
|
|
38584
39041
|
})
|
|
38585
39042
|
);
|
|
38586
39043
|
return DecorationSet.create(state.doc, decorations);
|
|
@@ -38684,10 +39141,10 @@ const Search = Extension.create({
|
|
|
38684
39141
|
* editor.commands.goToSearchResult(searchResults[3])
|
|
38685
39142
|
* @note Scrolls to match and selects it
|
|
38686
39143
|
*/
|
|
38687
|
-
goToSearchResult: (
|
|
39144
|
+
goToSearchResult: (match2) => (
|
|
38688
39145
|
/** @returns {boolean} */
|
|
38689
39146
|
({ state, dispatch, editor }) => {
|
|
38690
|
-
const { from: from2, to } =
|
|
39147
|
+
const { from: from2, to } = match2;
|
|
38691
39148
|
editor.view.focus();
|
|
38692
39149
|
const tr = state.tr.setSelection(TextSelection.create(state.doc, from2, to)).scrollIntoView();
|
|
38693
39150
|
dispatch(tr);
|