@portabletext/editor 8.1.6 → 8.1.7
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/lib/{behavior.types.action-BDNqhLEt.d.ts → behavior.types.action-Dg36r1rf.d.ts} +2 -2
- package/lib/{behavior.types.action-BDNqhLEt.d.ts.map → behavior.types.action-Dg36r1rf.d.ts.map} +1 -1
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/{get-container-CXdmRdiX.js → get-container-BNT2gY-T.js} +3 -3
- package/lib/{get-container-CXdmRdiX.js.map → get-container-BNT2gY-T.js.map} +1 -1
- package/lib/{get-parent-BLzi7eLr.js → get-parent-1LYvKkzm.js} +2 -2
- package/lib/{get-parent-BLzi7eLr.js.map → get-parent-1LYvKkzm.js.map} +1 -1
- package/lib/{get-path-sub-schema-DsN1qF_l.js → get-path-sub-schema-BQTgjrJ0.js} +2 -2
- package/lib/{get-path-sub-schema-DsN1qF_l.js.map → get-path-sub-schema-BQTgjrJ0.js.map} +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +30 -647
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +1 -1
- package/lib/{selector.is-selecting-entire-blocks-BHVYIXbI.js → selector.is-selecting-entire-blocks-CAUZpsBb.js} +6 -6
- package/lib/{selector.is-selecting-entire-blocks-BHVYIXbI.js.map → selector.is-selecting-entire-blocks-CAUZpsBb.js.map} +1 -1
- package/lib/selectors/index.d.ts +1 -1
- package/lib/selectors/index.js +4 -4
- package/lib/traversal/index.d.ts +1 -1
- package/lib/traversal/index.js +3 -3
- package/lib/{util.is-equal-selections-sCQib0IC.js → util.is-equal-selections-Ae0HO_72.js} +2 -2
- package/lib/{util.is-equal-selections-sCQib0IC.js.map → util.is-equal-selections-Ae0HO_72.js.map} +1 -1
- package/lib/{util.slice-blocks-B-iKFEG7.js → util.slice-blocks-By7qN-i2.js} +3 -3
- package/lib/{util.slice-blocks-B-iKFEG7.js.map → util.slice-blocks-By7qN-i2.js.map} +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +3 -3
- package/package.json +2 -5
package/lib/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as getChildren, d as nodeSegment, f as serializePath, i as resolveNode, n as parentPath, o as getNodeChildren, p as isKeyedSegment, r as getNode, t as getParent, u as hasUsableKey } from "./get-parent-
|
|
2
|
-
import { C as getAncestors, S as hasNode, _ as comparePoints, a as isInline, b as isEditableContainer, c as isSpanNode, d as resolveChildEntryIndex, f as isAncestorPath, g as isAfterPoint, h as isBackwardRange, i as getEnclosingBlock, l as getSibling, m as rangeEdges, n as getEnclosingContainer, o as getBlock, p as isTextBlockNode, s as isBlock, t as getPathSubSchema, u as getNodes, v as comparePaths, x as resolveContainerAt, y as isObject } from "./get-path-sub-schema-
|
|
3
|
-
import { _ as getAncestor, a as getTextBlock, c as pathContains, d as isRange, f as isPoint, g as isLeafObject, h as getLeaf, i as getFirstChild, l as getSpan, m as isPath, n as getUnionSchema, o as rangeIntersects, p as isObject$1, r as getLastChild, s as isBeforePoint, t as getContainer, u as getText } from "./get-container-
|
|
4
|
-
import { a as parseMarkDefs, c as getSelectionStartPoint, d as getBlockStartPoint, f as getBlockEndPoint, g as blockOffsetToSpanSelectionPoint, i as parseInlineObject, l as getSelectionEndPoint, m as isEqualSelectionPoints, n as parseAnnotation, o as parseSpan, p as getBlockKeyFromSelectionPoint, r as parseBlock, s as defaultKeyGenerator, u as isSelectionCollapsed, v as childAtTextOffset, y as textOffsetOfChild } from "./util.slice-blocks-
|
|
5
|
-
import { A as getSelectionEndPoint$1, B as getFocusTextBlock, C as getSelectedTextBlocks, D as getPreviousSpan, F as getSelectionStartBlock, H as getFocusSpan, I as getSelectionEndBlock, K as rangesOverlap, L as getFragment, M as isSelectionExpanded, N as isSelectionCollapsed$1, O as getSelectionStartPoint$1, P as isOverlappingSelection, R as getSelectedValue, S as getActiveDecorators, T as getMarkState, U as getFocusInlineObject, V as getFocusBlock, W as getFocusChild, a as isActiveListItem, b as getActiveAnnotations, c as getSelectionEndChild, d as getLastBlock, f as getFocusListBlock, i as isActiveStyle, j as isListBlock, k as getNextSpan, l as getPreviousBlock, m as getCaretWordSelection, n as isAtTheStartOfBlock, o as isActiveDecorator, p as getFocusBlockObject, r as isAtTheEndOfBlock, s as getSelectionStartChild, t as isSelectingEntireBlocks, u as getNextBlock, w as getActiveAnnotationsMarks, x as isActiveAnnotation, z as getRootAcceptedTypes } from "./selector.is-selecting-entire-blocks-
|
|
6
|
-
import { n as isEmptyTextBlock, r as getTextBlockText, t as isEqualSelections } from "./util.is-equal-selections-
|
|
1
|
+
import { a as getChildren, d as nodeSegment, f as serializePath, i as resolveNode, n as parentPath, o as getNodeChildren, p as isKeyedSegment, r as getNode, t as getParent, u as hasUsableKey } from "./get-parent-1LYvKkzm.js";
|
|
2
|
+
import { C as getAncestors, S as hasNode, _ as comparePoints, a as isInline, b as isEditableContainer, c as isSpanNode, d as resolveChildEntryIndex, f as isAncestorPath, g as isAfterPoint, h as isBackwardRange, i as getEnclosingBlock, l as getSibling, m as rangeEdges, n as getEnclosingContainer, o as getBlock, p as isTextBlockNode, s as isBlock, t as getPathSubSchema, u as getNodes, v as comparePaths, x as resolveContainerAt, y as isObject } from "./get-path-sub-schema-BQTgjrJ0.js";
|
|
3
|
+
import { _ as getAncestor, a as getTextBlock, c as pathContains, d as isRange, f as isPoint, g as isLeafObject, h as getLeaf, i as getFirstChild, l as getSpan, m as isPath, n as getUnionSchema, o as rangeIntersects, p as isObject$1, r as getLastChild, s as isBeforePoint, t as getContainer, u as getText } from "./get-container-BNT2gY-T.js";
|
|
4
|
+
import { a as parseMarkDefs, c as getSelectionStartPoint, d as getBlockStartPoint, f as getBlockEndPoint, g as blockOffsetToSpanSelectionPoint, i as parseInlineObject, l as getSelectionEndPoint, m as isEqualSelectionPoints, n as parseAnnotation, o as parseSpan, p as getBlockKeyFromSelectionPoint, r as parseBlock, s as defaultKeyGenerator, u as isSelectionCollapsed, v as childAtTextOffset, y as textOffsetOfChild } from "./util.slice-blocks-By7qN-i2.js";
|
|
5
|
+
import { A as getSelectionEndPoint$1, B as getFocusTextBlock, C as getSelectedTextBlocks, D as getPreviousSpan, F as getSelectionStartBlock, H as getFocusSpan, I as getSelectionEndBlock, K as rangesOverlap, L as getFragment, M as isSelectionExpanded, N as isSelectionCollapsed$1, O as getSelectionStartPoint$1, P as isOverlappingSelection, R as getSelectedValue, S as getActiveDecorators, T as getMarkState, U as getFocusInlineObject, V as getFocusBlock, W as getFocusChild, a as isActiveListItem, b as getActiveAnnotations, c as getSelectionEndChild, d as getLastBlock, f as getFocusListBlock, i as isActiveStyle, j as isListBlock, k as getNextSpan, l as getPreviousBlock, m as getCaretWordSelection, n as isAtTheStartOfBlock, o as isActiveDecorator, p as getFocusBlockObject, r as isAtTheEndOfBlock, s as getSelectionStartChild, t as isSelectingEntireBlocks, u as getNextBlock, w as getActiveAnnotationsMarks, x as isActiveAnnotation, z as getRootAcceptedTypes } from "./selector.is-selecting-entire-blocks-CAUZpsBb.js";
|
|
6
|
+
import { n as isEmptyTextBlock, r as getTextBlockText, t as isEqualSelections } from "./util.is-equal-selections-Ae0HO_72.js";
|
|
7
7
|
import { a as raise$1, i as forward, n as effect, t as defineBehavior } from "./behavior.types.behavior-BxSLb73I.js";
|
|
8
8
|
import { n as EditorContext$1, t as useEditor } from "./use-editor-CwNeVwVC.js";
|
|
9
9
|
import { c } from "react/compiler-runtime";
|
|
@@ -18,6 +18,7 @@ import { and, assertEvent, assign, createActor, emit, enqueueActions, fromCallba
|
|
|
18
18
|
import { htmlToPortableText } from "@portabletext/html";
|
|
19
19
|
import { toHTML } from "@portabletext/to-html";
|
|
20
20
|
import { applyAll, diffMatchPatch, insert, set, setIfMissing, unset } from "@portabletext/patches";
|
|
21
|
+
import { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, applyPatches, cleanupEfficiency, makeDiff, parsePatch } from "@sanity/diff-match-patch";
|
|
21
22
|
/**
|
|
22
23
|
* Resolve the DOM node corresponding to a keyed path.
|
|
23
24
|
*/
|
|
@@ -564,16 +565,16 @@ const getCharacterDistance = (str, isRTL = !1) => {
|
|
|
564
565
|
let end = str.length - 1;
|
|
565
566
|
for (let i = 0; i < str.length; i++) {
|
|
566
567
|
let char1 = str.charAt(end - i);
|
|
567
|
-
if (isLowSurrogate
|
|
568
|
+
if (isLowSurrogate(char1.charCodeAt(0))) {
|
|
568
569
|
let char2 = str.charAt(end - i - 1);
|
|
569
|
-
if (isHighSurrogate
|
|
570
|
+
if (isHighSurrogate(char2.charCodeAt(0))) {
|
|
570
571
|
yield char2 + char1, i++;
|
|
571
572
|
continue;
|
|
572
573
|
}
|
|
573
574
|
}
|
|
574
575
|
yield char1;
|
|
575
576
|
}
|
|
576
|
-
}, isHighSurrogate
|
|
577
|
+
}, isHighSurrogate = (charCode) => charCode >= 55296 && charCode <= 56319, isLowSurrogate = (charCode) => charCode >= 56320 && charCode <= 57343, CodepointType = {
|
|
577
578
|
None: 0,
|
|
578
579
|
Extend: 1,
|
|
579
580
|
ZWJ: 2,
|
|
@@ -4651,7 +4652,7 @@ function getSelectionState(snapshot, selection) {
|
|
|
4651
4652
|
function subscribeCoalesced(actor, observer) {
|
|
4652
4653
|
let scheduled = !1, active = !0, subscription = actor.subscribe({
|
|
4653
4654
|
next: observer.next ? () => {
|
|
4654
|
-
scheduled
|
|
4655
|
+
!scheduled && active && (scheduled = !0, queueMicrotask(() => {
|
|
4655
4656
|
scheduled = !1, active && observer.next?.();
|
|
4656
4657
|
}));
|
|
4657
4658
|
} : void 0,
|
|
@@ -5306,7 +5307,7 @@ function validateSelection(editorEngine, editorElement) {
|
|
|
5306
5307
|
} catch {}
|
|
5307
5308
|
if (!root || editorElement !== root.activeElement) return;
|
|
5308
5309
|
let domSelection = DOMEditor.getWindow(editorEngine).getSelection();
|
|
5309
|
-
if (
|
|
5310
|
+
if (domSelection && domSelection.rangeCount !== 0) try {
|
|
5310
5311
|
let domEditorSelection = DOMEditor.toEditorSelection(editorEngine, domSelection, {
|
|
5311
5312
|
exactMatch: !1,
|
|
5312
5313
|
suppressThrow: !0
|
|
@@ -5666,7 +5667,7 @@ const PortableTextEditable = forwardRef(function PortableTextEditable(props, for
|
|
|
5666
5667
|
}, $[105] = editorActor, $[106] = editorEngine, $[107] = onDragStart, $[108] = readOnly, $[109] = t28) : t28 = $[109];
|
|
5667
5668
|
let handleDragStart = t28, t29;
|
|
5668
5669
|
$[110] !== editorActor || $[111] !== editorEngine || $[112] !== onDrag ? (t29 = (event_9) => {
|
|
5669
|
-
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped()) && !
|
|
5670
|
+
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped()) && !editorActor.getSnapshot().matches({ setup: "setting up" }) && DOMEditor.hasTarget(editorEngine, event_9.target)) return editorActor.send({
|
|
5670
5671
|
type: "behavior event",
|
|
5671
5672
|
behaviorEvent: {
|
|
5672
5673
|
type: "drag.drag",
|
|
@@ -5750,7 +5751,7 @@ const PortableTextEditable = forwardRef(function PortableTextEditable(props, for
|
|
|
5750
5751
|
}, $[126] = editorActor, $[127] = editorEngine, $[128] = onDrop, $[129] = t33) : t33 = $[129];
|
|
5751
5752
|
let handleDrop = t33, t34;
|
|
5752
5753
|
$[130] !== editorActor || $[131] !== editorEngine || $[132] !== onDragLeave ? (t34 = (event_14) => {
|
|
5753
|
-
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped()) && !
|
|
5754
|
+
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped()) && !editorActor.getSnapshot().matches({ setup: "setting up" }) && DOMEditor.hasTarget(editorEngine, event_14.target)) return editorActor.send({
|
|
5754
5755
|
type: "behavior event",
|
|
5755
5756
|
behaviorEvent: {
|
|
5756
5757
|
type: "drag.dragleave",
|
|
@@ -6161,7 +6162,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
6161
6162
|
focusChild: () => {
|
|
6162
6163
|
if (!editor.snapshot.context.selection) return;
|
|
6163
6164
|
let leaf = getLeaf(editor.snapshot, editor.snapshot.context.selection.focus.path, { edge: "start" });
|
|
6164
|
-
if (
|
|
6165
|
+
if (leaf && !isBlock(editor.snapshot, leaf.path)) return leaf.node;
|
|
6165
6166
|
},
|
|
6166
6167
|
insertChild: (type, value) => (editorActor.send({
|
|
6167
6168
|
type: "behavior event",
|
|
@@ -7242,7 +7243,7 @@ function updateDirtyPaths(editor, newDirtyPaths) {
|
|
|
7242
7243
|
for (let path of newDirtyPaths) add(path);
|
|
7243
7244
|
editor.dirtyPaths = dirtyPaths, editor.dirtyPathKeys = dirtyPathKeys;
|
|
7244
7245
|
}
|
|
7245
|
-
const apply
|
|
7246
|
+
const apply = (editor, op) => {
|
|
7246
7247
|
let beforeListeners = editor.operationListeners.before, operationEvent = beforeListeners.length > 0 || editor.operationListeners.after.length > 0 ? createOperationEvent(editor, op) : void 0;
|
|
7247
7248
|
operationEvent && emitOperationEvent(beforeListeners, operationEvent);
|
|
7248
7249
|
for (let ref of editor.pathRefs) PathRef.transform(ref, op);
|
|
@@ -8256,7 +8257,7 @@ const shouldNormalize = (_editor, { iteration, initialDirtyPathsLength }) => {
|
|
|
8256
8257
|
pointRefs: /* @__PURE__ */ new Set(),
|
|
8257
8258
|
rangeRefs: /* @__PURE__ */ new Set(),
|
|
8258
8259
|
onChange: () => {},
|
|
8259
|
-
apply: (...args) => apply
|
|
8260
|
+
apply: (...args) => apply(e, ...args),
|
|
8260
8261
|
normalizeNode: (...args) => normalizeNode(e, ...args),
|
|
8261
8262
|
shouldNormalize: (...args) => shouldNormalize(e, ...args),
|
|
8262
8263
|
select: (...args) => select(e, ...args),
|
|
@@ -8355,624 +8356,6 @@ function pluginWithoutHistory(editor, fn) {
|
|
|
8355
8356
|
editor.withHistory = prev;
|
|
8356
8357
|
}
|
|
8357
8358
|
}
|
|
8358
|
-
function cloneDiff(diff2) {
|
|
8359
|
-
let [type, patch] = diff2;
|
|
8360
|
-
return [type, patch];
|
|
8361
|
-
}
|
|
8362
|
-
function getCommonOverlap(textA, textB) {
|
|
8363
|
-
let text1 = textA, text2 = textB, text1Length = text1.length, text2Length = text2.length;
|
|
8364
|
-
if (text1Length === 0 || text2Length === 0) return 0;
|
|
8365
|
-
text1Length > text2Length ? text1 = text1.substring(text1Length - text2Length) : text1Length < text2Length && (text2 = text2.substring(0, text1Length));
|
|
8366
|
-
let textLength = Math.min(text1Length, text2Length);
|
|
8367
|
-
if (text1 === text2) return textLength;
|
|
8368
|
-
let best = 0, length = 1;
|
|
8369
|
-
for (let found = 0; found !== -1;) {
|
|
8370
|
-
let pattern = text1.substring(textLength - length);
|
|
8371
|
-
if (found = text2.indexOf(pattern), found === -1) return best;
|
|
8372
|
-
length += found, (found === 0 || text1.substring(textLength - length) === text2.substring(0, length)) && (best = length, length++);
|
|
8373
|
-
}
|
|
8374
|
-
return best;
|
|
8375
|
-
}
|
|
8376
|
-
function getCommonPrefix(text1, text2) {
|
|
8377
|
-
if (!text1 || !text2 || text1[0] !== text2[0]) return 0;
|
|
8378
|
-
let pointerMin = 0, pointerMax = Math.min(text1.length, text2.length), pointerMid = pointerMax, pointerStart = 0;
|
|
8379
|
-
for (; pointerMin < pointerMid;) text1.substring(pointerStart, pointerMid) === text2.substring(pointerStart, pointerMid) ? (pointerMin = pointerMid, pointerStart = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
|
|
8380
|
-
return pointerMid;
|
|
8381
|
-
}
|
|
8382
|
-
function getCommonSuffix(text1, text2) {
|
|
8383
|
-
if (!text1 || !text2 || text1[text1.length - 1] !== text2[text2.length - 1]) return 0;
|
|
8384
|
-
let pointerMin = 0, pointerMax = Math.min(text1.length, text2.length), pointerMid = pointerMax, pointerEnd = 0;
|
|
8385
|
-
for (; pointerMin < pointerMid;) text1.substring(text1.length - pointerMid, text1.length - pointerEnd) === text2.substring(text2.length - pointerMid, text2.length - pointerEnd) ? (pointerMin = pointerMid, pointerEnd = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
|
|
8386
|
-
return pointerMid;
|
|
8387
|
-
}
|
|
8388
|
-
function isHighSurrogate(char) {
|
|
8389
|
-
let charCode = char.charCodeAt(0);
|
|
8390
|
-
return charCode >= 55296 && charCode <= 56319;
|
|
8391
|
-
}
|
|
8392
|
-
function isLowSurrogate(char) {
|
|
8393
|
-
let charCode = char.charCodeAt(0);
|
|
8394
|
-
return charCode >= 56320 && charCode <= 57343;
|
|
8395
|
-
}
|
|
8396
|
-
function bisect(text1, text2, deadline) {
|
|
8397
|
-
let text1Length = text1.length, text2Length = text2.length, maxD = Math.ceil((text1Length + text2Length) / 2), vOffset = maxD, vLength = 2 * maxD, v1 = Array(vLength), v2 = Array(vLength);
|
|
8398
|
-
for (let x = 0; x < vLength; x++) v1[x] = -1, v2[x] = -1;
|
|
8399
|
-
v1[vOffset + 1] = 0, v2[vOffset + 1] = 0;
|
|
8400
|
-
let delta = text1Length - text2Length, front = delta % 2 != 0, k1start = 0, k1end = 0, k2start = 0, k2end = 0;
|
|
8401
|
-
for (let d = 0; d < maxD && !(Date.now() > deadline); d++) {
|
|
8402
|
-
for (let k1 = -d + k1start; k1 <= d - k1end; k1 += 2) {
|
|
8403
|
-
let k1Offset = vOffset + k1, x1;
|
|
8404
|
-
x1 = k1 === -d || k1 !== d && v1[k1Offset - 1] < v1[k1Offset + 1] ? v1[k1Offset + 1] : v1[k1Offset - 1] + 1;
|
|
8405
|
-
let y1 = x1 - k1;
|
|
8406
|
-
for (; x1 < text1Length && y1 < text2Length && text1.charAt(x1) === text2.charAt(y1);) x1++, y1++;
|
|
8407
|
-
if (v1[k1Offset] = x1, x1 > text1Length) k1end += 2;
|
|
8408
|
-
else if (y1 > text2Length) k1start += 2;
|
|
8409
|
-
else if (front) {
|
|
8410
|
-
let k2Offset = vOffset + delta - k1;
|
|
8411
|
-
if (k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] !== -1) {
|
|
8412
|
-
let x2 = text1Length - v2[k2Offset];
|
|
8413
|
-
if (x1 >= x2) return bisectSplit(text1, text2, x1, y1, deadline);
|
|
8414
|
-
}
|
|
8415
|
-
}
|
|
8416
|
-
}
|
|
8417
|
-
for (let k2 = -d + k2start; k2 <= d - k2end; k2 += 2) {
|
|
8418
|
-
let k2Offset = vOffset + k2, x2;
|
|
8419
|
-
x2 = k2 === -d || k2 !== d && v2[k2Offset - 1] < v2[k2Offset + 1] ? v2[k2Offset + 1] : v2[k2Offset - 1] + 1;
|
|
8420
|
-
let y2 = x2 - k2;
|
|
8421
|
-
for (; x2 < text1Length && y2 < text2Length && text1.charAt(text1Length - x2 - 1) === text2.charAt(text2Length - y2 - 1);) x2++, y2++;
|
|
8422
|
-
if (v2[k2Offset] = x2, x2 > text1Length) k2end += 2;
|
|
8423
|
-
else if (y2 > text2Length) k2start += 2;
|
|
8424
|
-
else if (!front) {
|
|
8425
|
-
let k1Offset = vOffset + delta - k2;
|
|
8426
|
-
if (k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] !== -1) {
|
|
8427
|
-
let x1 = v1[k1Offset], y1 = vOffset + x1 - k1Offset;
|
|
8428
|
-
if (x2 = text1Length - x2, x1 >= x2) return bisectSplit(text1, text2, x1, y1, deadline);
|
|
8429
|
-
}
|
|
8430
|
-
}
|
|
8431
|
-
}
|
|
8432
|
-
}
|
|
8433
|
-
return [[-1, text1], [1, text2]];
|
|
8434
|
-
}
|
|
8435
|
-
function bisectSplit(text1, text2, x, y, deadline) {
|
|
8436
|
-
let text1a = text1.substring(0, x), text2a = text2.substring(0, y), text1b = text1.substring(x), text2b = text2.substring(y), diffs = doDiff(text1a, text2a, {
|
|
8437
|
-
checkLines: !1,
|
|
8438
|
-
deadline
|
|
8439
|
-
}), diffsb = doDiff(text1b, text2b, {
|
|
8440
|
-
checkLines: !1,
|
|
8441
|
-
deadline
|
|
8442
|
-
});
|
|
8443
|
-
return diffs.concat(diffsb);
|
|
8444
|
-
}
|
|
8445
|
-
function findHalfMatch(text1, text2, timeout = 1) {
|
|
8446
|
-
if (timeout <= 0) return null;
|
|
8447
|
-
let longText = text1.length > text2.length ? text1 : text2, shortText = text1.length > text2.length ? text2 : text1;
|
|
8448
|
-
if (longText.length < 4 || shortText.length * 2 < longText.length) return null;
|
|
8449
|
-
let halfMatch1 = halfMatchI(longText, shortText, Math.ceil(longText.length / 4)), halfMatch2 = halfMatchI(longText, shortText, Math.ceil(longText.length / 2)), halfMatch;
|
|
8450
|
-
if (halfMatch1 && halfMatch2) halfMatch = halfMatch1[4].length > halfMatch2[4].length ? halfMatch1 : halfMatch2;
|
|
8451
|
-
else {
|
|
8452
|
-
if (!halfMatch1 && !halfMatch2) return null;
|
|
8453
|
-
halfMatch2 ? halfMatch1 || (halfMatch = halfMatch2) : halfMatch = halfMatch1;
|
|
8454
|
-
}
|
|
8455
|
-
if (!halfMatch) throw Error("Unable to find a half match.");
|
|
8456
|
-
let text1A, text1B, text2A, text2B;
|
|
8457
|
-
text1.length > text2.length ? (text1A = halfMatch[0], text1B = halfMatch[1], text2A = halfMatch[2], text2B = halfMatch[3]) : (text2A = halfMatch[0], text2B = halfMatch[1], text1A = halfMatch[2], text1B = halfMatch[3]);
|
|
8458
|
-
let midCommon = halfMatch[4];
|
|
8459
|
-
return [
|
|
8460
|
-
text1A,
|
|
8461
|
-
text1B,
|
|
8462
|
-
text2A,
|
|
8463
|
-
text2B,
|
|
8464
|
-
midCommon
|
|
8465
|
-
];
|
|
8466
|
-
}
|
|
8467
|
-
function halfMatchI(longText, shortText, i) {
|
|
8468
|
-
let seed = longText.slice(i, i + Math.floor(longText.length / 4)), j = -1, bestCommon = "", bestLongTextA, bestLongTextB, bestShortTextA, bestShortTextB;
|
|
8469
|
-
for (; (j = shortText.indexOf(seed, j + 1)) !== -1;) {
|
|
8470
|
-
let prefixLength = getCommonPrefix(longText.slice(i), shortText.slice(j)), suffixLength = getCommonSuffix(longText.slice(0, i), shortText.slice(0, j));
|
|
8471
|
-
bestCommon.length < suffixLength + prefixLength && (bestCommon = shortText.slice(j - suffixLength, j) + shortText.slice(j, j + prefixLength), bestLongTextA = longText.slice(0, i - suffixLength), bestLongTextB = longText.slice(i + prefixLength), bestShortTextA = shortText.slice(0, j - suffixLength), bestShortTextB = shortText.slice(j + prefixLength));
|
|
8472
|
-
}
|
|
8473
|
-
return bestCommon.length * 2 >= longText.length ? [
|
|
8474
|
-
bestLongTextA || "",
|
|
8475
|
-
bestLongTextB || "",
|
|
8476
|
-
bestShortTextA || "",
|
|
8477
|
-
bestShortTextB || "",
|
|
8478
|
-
bestCommon || ""
|
|
8479
|
-
] : null;
|
|
8480
|
-
}
|
|
8481
|
-
function charsToLines(diffs, lineArray) {
|
|
8482
|
-
for (let x = 0; x < diffs.length; x++) {
|
|
8483
|
-
let chars = diffs[x][1], text = [];
|
|
8484
|
-
for (let y = 0; y < chars.length; y++) text[y] = lineArray[chars.charCodeAt(y)];
|
|
8485
|
-
diffs[x][1] = text.join("");
|
|
8486
|
-
}
|
|
8487
|
-
}
|
|
8488
|
-
function linesToChars(textA, textB) {
|
|
8489
|
-
let lineArray = [], lineHash = {};
|
|
8490
|
-
lineArray[0] = "";
|
|
8491
|
-
function diffLinesToMunge(text) {
|
|
8492
|
-
let chars = "", lineStart = 0, lineEnd = -1, lineArrayLength = lineArray.length;
|
|
8493
|
-
for (; lineEnd < text.length - 1;) {
|
|
8494
|
-
lineEnd = text.indexOf("\n", lineStart), lineEnd === -1 && (lineEnd = text.length - 1);
|
|
8495
|
-
let line = text.slice(lineStart, lineEnd + 1);
|
|
8496
|
-
(lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) : lineHash[line] !== void 0) ? chars += String.fromCharCode(lineHash[line]) : (lineArrayLength === maxLines && (line = text.slice(lineStart), lineEnd = text.length), chars += String.fromCharCode(lineArrayLength), lineHash[line] = lineArrayLength, lineArray[lineArrayLength++] = line), lineStart = lineEnd + 1;
|
|
8497
|
-
}
|
|
8498
|
-
return chars;
|
|
8499
|
-
}
|
|
8500
|
-
let maxLines = 4e4, chars1 = diffLinesToMunge(textA);
|
|
8501
|
-
return maxLines = 65535, {
|
|
8502
|
-
chars1,
|
|
8503
|
-
chars2: diffLinesToMunge(textB),
|
|
8504
|
-
lineArray
|
|
8505
|
-
};
|
|
8506
|
-
}
|
|
8507
|
-
function doLineModeDiff(textA, textB, opts) {
|
|
8508
|
-
let text1 = textA, text2 = textB, a = linesToChars(text1, text2);
|
|
8509
|
-
text1 = a.chars1, text2 = a.chars2;
|
|
8510
|
-
let linearray = a.lineArray, diffs = doDiff(text1, text2, {
|
|
8511
|
-
checkLines: !1,
|
|
8512
|
-
deadline: opts.deadline
|
|
8513
|
-
});
|
|
8514
|
-
charsToLines(diffs, linearray), diffs = cleanupSemantic(diffs), diffs.push([0, ""]);
|
|
8515
|
-
let pointer = 0, countDelete = 0, countInsert = 0, textDelete = "", textInsert = "";
|
|
8516
|
-
for (; pointer < diffs.length;) {
|
|
8517
|
-
switch (diffs[pointer][0]) {
|
|
8518
|
-
case 1:
|
|
8519
|
-
countInsert++, textInsert += diffs[pointer][1];
|
|
8520
|
-
break;
|
|
8521
|
-
case -1:
|
|
8522
|
-
countDelete++, textDelete += diffs[pointer][1];
|
|
8523
|
-
break;
|
|
8524
|
-
case 0:
|
|
8525
|
-
if (countDelete >= 1 && countInsert >= 1) {
|
|
8526
|
-
diffs.splice(pointer - countDelete - countInsert, countDelete + countInsert), pointer = pointer - countDelete - countInsert;
|
|
8527
|
-
let aa = doDiff(textDelete, textInsert, {
|
|
8528
|
-
checkLines: !1,
|
|
8529
|
-
deadline: opts.deadline
|
|
8530
|
-
});
|
|
8531
|
-
for (let j = aa.length - 1; j >= 0; j--) diffs.splice(pointer, 0, aa[j]);
|
|
8532
|
-
pointer += aa.length;
|
|
8533
|
-
}
|
|
8534
|
-
countInsert = 0, countDelete = 0, textDelete = "", textInsert = "";
|
|
8535
|
-
break;
|
|
8536
|
-
default: throw Error("Unknown diff operation.");
|
|
8537
|
-
}
|
|
8538
|
-
pointer++;
|
|
8539
|
-
}
|
|
8540
|
-
return diffs.pop(), diffs;
|
|
8541
|
-
}
|
|
8542
|
-
function computeDiff(text1, text2, opts) {
|
|
8543
|
-
let diffs;
|
|
8544
|
-
if (!text1) return [[1, text2]];
|
|
8545
|
-
if (!text2) return [[-1, text1]];
|
|
8546
|
-
let longtext = text1.length > text2.length ? text1 : text2, shorttext = text1.length > text2.length ? text2 : text1, i = longtext.indexOf(shorttext);
|
|
8547
|
-
if (i !== -1) return diffs = [
|
|
8548
|
-
[1, longtext.substring(0, i)],
|
|
8549
|
-
[0, shorttext],
|
|
8550
|
-
[1, longtext.substring(i + shorttext.length)]
|
|
8551
|
-
], text1.length > text2.length && (diffs[0][0] = -1, diffs[2][0] = -1), diffs;
|
|
8552
|
-
if (shorttext.length === 1) return [[-1, text1], [1, text2]];
|
|
8553
|
-
let halfMatch = findHalfMatch(text1, text2);
|
|
8554
|
-
if (halfMatch) {
|
|
8555
|
-
let text1A = halfMatch[0], text1B = halfMatch[1], text2A = halfMatch[2], text2B = halfMatch[3], midCommon = halfMatch[4], diffsA = doDiff(text1A, text2A, opts), diffsB = doDiff(text1B, text2B, opts);
|
|
8556
|
-
return diffsA.concat([[0, midCommon]], diffsB);
|
|
8557
|
-
}
|
|
8558
|
-
return opts.checkLines && text1.length > 100 && text2.length > 100 ? doLineModeDiff(text1, text2, opts) : bisect(text1, text2, opts.deadline);
|
|
8559
|
-
}
|
|
8560
|
-
var __defProp$2 = Object.defineProperty, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, {
|
|
8561
|
-
enumerable: !0,
|
|
8562
|
-
configurable: !0,
|
|
8563
|
-
writable: !0,
|
|
8564
|
-
value
|
|
8565
|
-
}) : obj[key] = value, __spreadValues$2 = (a, b) => {
|
|
8566
|
-
for (var prop in b ||= {}) __hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
8567
|
-
if (__getOwnPropSymbols$2) for (var prop of __getOwnPropSymbols$2(b)) __propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
8568
|
-
return a;
|
|
8569
|
-
};
|
|
8570
|
-
function diff(textA, textB, opts) {
|
|
8571
|
-
if (textA === null || textB === null) throw Error("Null input. (diff)");
|
|
8572
|
-
let diffs = doDiff(textA, textB, createInternalOpts(opts || {}));
|
|
8573
|
-
return adjustDiffForSurrogatePairs(diffs), diffs;
|
|
8574
|
-
}
|
|
8575
|
-
function doDiff(textA, textB, options) {
|
|
8576
|
-
let text1 = textA, text2 = textB;
|
|
8577
|
-
if (text1 === text2) return text1 ? [[0, text1]] : [];
|
|
8578
|
-
let commonlength = getCommonPrefix(text1, text2), commonprefix = text1.substring(0, commonlength);
|
|
8579
|
-
text1 = text1.substring(commonlength), text2 = text2.substring(commonlength), commonlength = getCommonSuffix(text1, text2);
|
|
8580
|
-
let commonsuffix = text1.substring(text1.length - commonlength);
|
|
8581
|
-
text1 = text1.substring(0, text1.length - commonlength), text2 = text2.substring(0, text2.length - commonlength);
|
|
8582
|
-
let diffs = computeDiff(text1, text2, options);
|
|
8583
|
-
return commonprefix && diffs.unshift([0, commonprefix]), commonsuffix && diffs.push([0, commonsuffix]), diffs = cleanupMerge(diffs), diffs;
|
|
8584
|
-
}
|
|
8585
|
-
function createDeadLine(timeout) {
|
|
8586
|
-
let t = 1;
|
|
8587
|
-
return typeof timeout < "u" && (t = timeout <= 0 ? Number.MAX_VALUE : timeout), Date.now() + t * 1e3;
|
|
8588
|
-
}
|
|
8589
|
-
function createInternalOpts(opts) {
|
|
8590
|
-
return __spreadValues$2({
|
|
8591
|
-
checkLines: !0,
|
|
8592
|
-
deadline: createDeadLine(opts.timeout || 1)
|
|
8593
|
-
}, opts);
|
|
8594
|
-
}
|
|
8595
|
-
function combineChar(data, char, dir) {
|
|
8596
|
-
return dir === 1 ? data + char : char + data;
|
|
8597
|
-
}
|
|
8598
|
-
function splitChar(data, dir) {
|
|
8599
|
-
return dir === 1 ? [data.substring(0, data.length - 1), data[data.length - 1]] : [data.substring(1), data[0]];
|
|
8600
|
-
}
|
|
8601
|
-
function hasSharedChar(diffs, i, j, dir) {
|
|
8602
|
-
return dir === 1 ? diffs[i][1][diffs[i][1].length - 1] === diffs[j][1][diffs[j][1].length - 1] : diffs[i][1][0] === diffs[j][1][0];
|
|
8603
|
-
}
|
|
8604
|
-
function deisolateChar(diffs, i, dir) {
|
|
8605
|
-
let inv = dir === 1 ? -1 : 1, insertIdx = null, deleteIdx = null, j = i + dir;
|
|
8606
|
-
for (; j >= 0 && j < diffs.length && (insertIdx === null || deleteIdx === null); j += dir) {
|
|
8607
|
-
let [op, text2] = diffs[j];
|
|
8608
|
-
if (text2.length !== 0) {
|
|
8609
|
-
if (op === 1) {
|
|
8610
|
-
insertIdx === null && (insertIdx = j);
|
|
8611
|
-
continue;
|
|
8612
|
-
}
|
|
8613
|
-
if (op === -1) {
|
|
8614
|
-
deleteIdx === null && (deleteIdx = j);
|
|
8615
|
-
continue;
|
|
8616
|
-
}
|
|
8617
|
-
if (op === 0) {
|
|
8618
|
-
if (insertIdx === null && deleteIdx === null) {
|
|
8619
|
-
let [rest, char2] = splitChar(diffs[i][1], dir);
|
|
8620
|
-
diffs[i][1] = rest, diffs[j][1] = combineChar(diffs[j][1], char2, inv);
|
|
8621
|
-
return;
|
|
8622
|
-
}
|
|
8623
|
-
break;
|
|
8624
|
-
}
|
|
8625
|
-
}
|
|
8626
|
-
}
|
|
8627
|
-
if (insertIdx !== null && deleteIdx !== null && hasSharedChar(diffs, insertIdx, deleteIdx, dir)) {
|
|
8628
|
-
let [insertText, insertChar] = splitChar(diffs[insertIdx][1], inv), [deleteText] = splitChar(diffs[deleteIdx][1], inv);
|
|
8629
|
-
diffs[insertIdx][1] = insertText, diffs[deleteIdx][1] = deleteText, diffs[i][1] = combineChar(diffs[i][1], insertChar, dir);
|
|
8630
|
-
return;
|
|
8631
|
-
}
|
|
8632
|
-
let [text, char] = splitChar(diffs[i][1], dir);
|
|
8633
|
-
diffs[i][1] = text, insertIdx === null ? (diffs.splice(j, 0, [1, char]), deleteIdx !== null && deleteIdx >= j && deleteIdx++) : diffs[insertIdx][1] = combineChar(diffs[insertIdx][1], char, inv), deleteIdx === null ? diffs.splice(j, 0, [-1, char]) : diffs[deleteIdx][1] = combineChar(diffs[deleteIdx][1], char, inv);
|
|
8634
|
-
}
|
|
8635
|
-
function adjustDiffForSurrogatePairs(diffs) {
|
|
8636
|
-
for (let i = 0; i < diffs.length; i++) {
|
|
8637
|
-
let [diffType, diffText] = diffs[i];
|
|
8638
|
-
if (diffText.length === 0) continue;
|
|
8639
|
-
let firstChar = diffText[0], lastChar = diffText[diffText.length - 1];
|
|
8640
|
-
isHighSurrogate(lastChar) && diffType === 0 && deisolateChar(diffs, i, 1), isLowSurrogate(firstChar) && diffType === 0 && deisolateChar(diffs, i, -1);
|
|
8641
|
-
}
|
|
8642
|
-
for (let i = 0; i < diffs.length; i++) diffs[i][1].length === 0 && diffs.splice(i, 1);
|
|
8643
|
-
}
|
|
8644
|
-
function cleanupSemantic(rawDiffs) {
|
|
8645
|
-
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2)), hasChanges = !1, equalities = [], equalitiesLength = 0, lastEquality = null, pointer = 0, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0;
|
|
8646
|
-
for (; pointer < diffs.length;) diffs[pointer][0] === 0 ? (equalities[equalitiesLength++] = pointer, lengthInsertions1 = lengthInsertions2, lengthDeletions1 = lengthDeletions2, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = diffs[pointer][1]) : (diffs[pointer][0] === 1 ? lengthInsertions2 += diffs[pointer][1].length : lengthDeletions2 += diffs[pointer][1].length, lastEquality && lastEquality.length <= Math.max(lengthInsertions1, lengthDeletions1) && lastEquality.length <= Math.max(lengthInsertions2, lengthDeletions2) && (diffs.splice(equalities[equalitiesLength - 1], 0, [-1, lastEquality]), diffs[equalities[equalitiesLength - 1] + 1][0] = 1, equalitiesLength--, equalitiesLength--, pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = null, hasChanges = !0)), pointer++;
|
|
8647
|
-
for (hasChanges && (diffs = cleanupMerge(diffs)), diffs = cleanupSemanticLossless(diffs), pointer = 1; pointer < diffs.length;) {
|
|
8648
|
-
if (diffs[pointer - 1][0] === -1 && diffs[pointer][0] === 1) {
|
|
8649
|
-
let deletion = diffs[pointer - 1][1], insertion = diffs[pointer][1], overlapLength1 = getCommonOverlap(deletion, insertion), overlapLength2 = getCommonOverlap(insertion, deletion);
|
|
8650
|
-
overlapLength1 >= overlapLength2 ? (overlapLength1 >= deletion.length / 2 || overlapLength1 >= insertion.length / 2) && (diffs.splice(pointer, 0, [0, insertion.substring(0, overlapLength1)]), diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlapLength1), diffs[pointer + 1][1] = insertion.substring(overlapLength1), pointer++) : (overlapLength2 >= deletion.length / 2 || overlapLength2 >= insertion.length / 2) && (diffs.splice(pointer, 0, [0, deletion.substring(0, overlapLength2)]), diffs[pointer - 1][0] = 1, diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlapLength2), diffs[pointer + 1][0] = -1, diffs[pointer + 1][1] = deletion.substring(overlapLength2), pointer++), pointer++;
|
|
8651
|
-
}
|
|
8652
|
-
pointer++;
|
|
8653
|
-
}
|
|
8654
|
-
return diffs;
|
|
8655
|
-
}
|
|
8656
|
-
const nonAlphaNumericRegex = /[^a-zA-Z0-9]/, whitespaceRegex = /\s/, linebreakRegex = /[\r\n]/, blanklineEndRegex = /\n\r?\n$/, blanklineStartRegex = /^\r?\n\r?\n/;
|
|
8657
|
-
function cleanupSemanticLossless(rawDiffs) {
|
|
8658
|
-
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
8659
|
-
function diffCleanupSemanticScore(one, two) {
|
|
8660
|
-
if (!one || !two) return 6;
|
|
8661
|
-
let char1 = one.charAt(one.length - 1), char2 = two.charAt(0), nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex), nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex), whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex), whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex), lineBreak1 = whitespace1 && char1.match(linebreakRegex), lineBreak2 = whitespace2 && char2.match(linebreakRegex), blankLine1 = lineBreak1 && one.match(blanklineEndRegex), blankLine2 = lineBreak2 && two.match(blanklineStartRegex);
|
|
8662
|
-
return blankLine1 || blankLine2 ? 5 : lineBreak1 || lineBreak2 ? 4 : nonAlphaNumeric1 && !whitespace1 && whitespace2 ? 3 : whitespace1 || whitespace2 ? 2 : nonAlphaNumeric1 || nonAlphaNumeric2 ? 1 : 0;
|
|
8663
|
-
}
|
|
8664
|
-
let pointer = 1;
|
|
8665
|
-
for (; pointer < diffs.length - 1;) {
|
|
8666
|
-
if (diffs[pointer - 1][0] === 0 && diffs[pointer + 1][0] === 0) {
|
|
8667
|
-
let equality1 = diffs[pointer - 1][1], edit = diffs[pointer][1], equality2 = diffs[pointer + 1][1], commonOffset = getCommonSuffix(equality1, edit);
|
|
8668
|
-
if (commonOffset) {
|
|
8669
|
-
let commonString = edit.substring(edit.length - commonOffset);
|
|
8670
|
-
equality1 = equality1.substring(0, equality1.length - commonOffset), edit = commonString + edit.substring(0, edit.length - commonOffset), equality2 = commonString + equality2;
|
|
8671
|
-
}
|
|
8672
|
-
let bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2, bestScore = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
8673
|
-
for (; edit.charAt(0) === equality2.charAt(0);) {
|
|
8674
|
-
equality1 += edit.charAt(0), edit = edit.substring(1) + equality2.charAt(0), equality2 = equality2.substring(1);
|
|
8675
|
-
let score = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
8676
|
-
score >= bestScore && (bestScore = score, bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2);
|
|
8677
|
-
}
|
|
8678
|
-
diffs[pointer - 1][1] !== bestEquality1 && (bestEquality1 ? diffs[pointer - 1][1] = bestEquality1 : (diffs.splice(pointer - 1, 1), pointer--), diffs[pointer][1] = bestEdit, bestEquality2 ? diffs[pointer + 1][1] = bestEquality2 : (diffs.splice(pointer + 1, 1), pointer--));
|
|
8679
|
-
}
|
|
8680
|
-
pointer++;
|
|
8681
|
-
}
|
|
8682
|
-
return diffs;
|
|
8683
|
-
}
|
|
8684
|
-
function cleanupMerge(rawDiffs) {
|
|
8685
|
-
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
8686
|
-
diffs.push([0, ""]);
|
|
8687
|
-
let pointer = 0, countDelete = 0, countInsert = 0, textDelete = "", textInsert = "", commonlength;
|
|
8688
|
-
for (; pointer < diffs.length;) switch (diffs[pointer][0]) {
|
|
8689
|
-
case 1:
|
|
8690
|
-
countInsert++, textInsert += diffs[pointer][1], pointer++;
|
|
8691
|
-
break;
|
|
8692
|
-
case -1:
|
|
8693
|
-
countDelete++, textDelete += diffs[pointer][1], pointer++;
|
|
8694
|
-
break;
|
|
8695
|
-
case 0:
|
|
8696
|
-
countDelete + countInsert > 1 ? (countDelete !== 0 && countInsert !== 0 && (commonlength = getCommonPrefix(textInsert, textDelete), commonlength !== 0 && (pointer - countDelete - countInsert > 0 && diffs[pointer - countDelete - countInsert - 1][0] === 0 ? diffs[pointer - countDelete - countInsert - 1][1] += textInsert.substring(0, commonlength) : (diffs.splice(0, 0, [0, textInsert.substring(0, commonlength)]), pointer++), textInsert = textInsert.substring(commonlength), textDelete = textDelete.substring(commonlength)), commonlength = getCommonSuffix(textInsert, textDelete), commonlength !== 0 && (diffs[pointer][1] = textInsert.substring(textInsert.length - commonlength) + diffs[pointer][1], textInsert = textInsert.substring(0, textInsert.length - commonlength), textDelete = textDelete.substring(0, textDelete.length - commonlength))), pointer -= countDelete + countInsert, diffs.splice(pointer, countDelete + countInsert), textDelete.length && (diffs.splice(pointer, 0, [-1, textDelete]), pointer++), textInsert.length && (diffs.splice(pointer, 0, [1, textInsert]), pointer++), pointer++) : pointer !== 0 && diffs[pointer - 1][0] === 0 ? (diffs[pointer - 1][1] += diffs[pointer][1], diffs.splice(pointer, 1)) : pointer++, countInsert = 0, countDelete = 0, textDelete = "", textInsert = "";
|
|
8697
|
-
break;
|
|
8698
|
-
default: throw Error("Unknown diff operation");
|
|
8699
|
-
}
|
|
8700
|
-
diffs[diffs.length - 1][1] === "" && diffs.pop();
|
|
8701
|
-
let hasChanges = !1;
|
|
8702
|
-
for (pointer = 1; pointer < diffs.length - 1;) diffs[pointer - 1][0] === 0 && diffs[pointer + 1][0] === 0 && (diffs[pointer][1].substring(diffs[pointer][1].length - diffs[pointer - 1][1].length) === diffs[pointer - 1][1] ? (diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length), diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1], diffs.splice(pointer - 1, 1), hasChanges = !0) : diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1] && (diffs[pointer - 1][1] += diffs[pointer + 1][1], diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1], diffs.splice(pointer + 1, 1), hasChanges = !0)), pointer++;
|
|
8703
|
-
return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
|
|
8704
|
-
}
|
|
8705
|
-
function trueCount(...args) {
|
|
8706
|
-
return args.reduce((n, bool) => n + +!!bool, 0);
|
|
8707
|
-
}
|
|
8708
|
-
function cleanupEfficiency(rawDiffs, editCost = 4) {
|
|
8709
|
-
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2)), hasChanges = !1, equalities = [], equalitiesLength = 0, lastEquality = null, pointer = 0, preIns = !1, preDel = !1, postIns = !1, postDel = !1;
|
|
8710
|
-
for (; pointer < diffs.length;) diffs[pointer][0] === 0 ? (diffs[pointer][1].length < editCost && (postIns || postDel) ? (equalities[equalitiesLength++] = pointer, preIns = postIns, preDel = postDel, lastEquality = diffs[pointer][1]) : (equalitiesLength = 0, lastEquality = null), postIns = !1, postDel = !1) : (diffs[pointer][0] === -1 ? postDel = !0 : postIns = !0, lastEquality && (preIns && preDel && postIns && postDel || lastEquality.length < editCost / 2 && trueCount(preIns, preDel, postIns, postDel) === 3) && (diffs.splice(equalities[equalitiesLength - 1], 0, [-1, lastEquality]), diffs[equalities[equalitiesLength - 1] + 1][0] = 1, equalitiesLength--, lastEquality = null, preIns && preDel ? (postIns = !0, postDel = !0, equalitiesLength = 0) : (equalitiesLength--, pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1, postIns = !1, postDel = !1), hasChanges = !0)), pointer++;
|
|
8711
|
-
return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
|
|
8712
|
-
}
|
|
8713
|
-
var __defProp$1 = Object.defineProperty, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
8714
|
-
enumerable: !0,
|
|
8715
|
-
configurable: !0,
|
|
8716
|
-
writable: !0,
|
|
8717
|
-
value
|
|
8718
|
-
}) : obj[key] = value, __spreadValues$1 = (a, b) => {
|
|
8719
|
-
for (var prop in b ||= {}) __hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
8720
|
-
if (__getOwnPropSymbols$1) for (var prop of __getOwnPropSymbols$1(b)) __propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
8721
|
-
return a;
|
|
8722
|
-
};
|
|
8723
|
-
const DEFAULT_OPTIONS = {
|
|
8724
|
-
/**
|
|
8725
|
-
* At what point is no match declared (0.0 = perfection, 1.0 = very loose).
|
|
8726
|
-
*/
|
|
8727
|
-
threshold: .5,
|
|
8728
|
-
/**
|
|
8729
|
-
* How far to search for a match (0 = exact location, 1000+ = broad match).
|
|
8730
|
-
* A match this many characters away from the expected location will add
|
|
8731
|
-
* 1.0 to the score (0.0 is a perfect match).
|
|
8732
|
-
*/
|
|
8733
|
-
distance: 1e3
|
|
8734
|
-
};
|
|
8735
|
-
function applyDefaults(options) {
|
|
8736
|
-
return __spreadValues$1(__spreadValues$1({}, DEFAULT_OPTIONS), options);
|
|
8737
|
-
}
|
|
8738
|
-
function bitap(text, pattern, loc, opts = {}) {
|
|
8739
|
-
if (pattern.length > 32) throw Error("Pattern too long for this browser.");
|
|
8740
|
-
let options = applyDefaults(opts), s = getAlphabetFromPattern(pattern);
|
|
8741
|
-
function getBitapScore(e, x) {
|
|
8742
|
-
let accuracy = e / pattern.length, proximity = Math.abs(loc - x);
|
|
8743
|
-
return options.distance ? accuracy + proximity / options.distance : proximity ? 1 : accuracy;
|
|
8744
|
-
}
|
|
8745
|
-
let scoreThreshold = options.threshold, bestLoc = text.indexOf(pattern, loc);
|
|
8746
|
-
bestLoc !== -1 && (scoreThreshold = Math.min(getBitapScore(0, bestLoc), scoreThreshold), bestLoc = text.lastIndexOf(pattern, loc + pattern.length), bestLoc !== -1 && (scoreThreshold = Math.min(getBitapScore(0, bestLoc), scoreThreshold)));
|
|
8747
|
-
let matchmask = 1 << pattern.length - 1;
|
|
8748
|
-
bestLoc = -1;
|
|
8749
|
-
let binMin, binMid, binMax = pattern.length + text.length, lastRd = [];
|
|
8750
|
-
for (let d = 0; d < pattern.length; d++) {
|
|
8751
|
-
for (binMin = 0, binMid = binMax; binMin < binMid;) getBitapScore(d, loc + binMid) <= scoreThreshold ? binMin = binMid : binMax = binMid, binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
8752
|
-
binMax = binMid;
|
|
8753
|
-
let start = Math.max(1, loc - binMid + 1), finish = Math.min(loc + binMid, text.length) + pattern.length, rd = Array(finish + 2);
|
|
8754
|
-
rd[finish + 1] = (1 << d) - 1;
|
|
8755
|
-
for (let j = finish; j >= start; j--) {
|
|
8756
|
-
let charMatch = s[text.charAt(j - 1)];
|
|
8757
|
-
if (d === 0 ? rd[j] = (rd[j + 1] << 1 | 1) & charMatch : rd[j] = (rd[j + 1] << 1 | 1) & charMatch | (lastRd[j + 1] | lastRd[j]) << 1 | 1 | lastRd[j + 1], rd[j] & matchmask) {
|
|
8758
|
-
let score = getBitapScore(d, j - 1);
|
|
8759
|
-
if (score <= scoreThreshold) {
|
|
8760
|
-
if (scoreThreshold = score, bestLoc = j - 1, bestLoc > loc) start = Math.max(1, 2 * loc - bestLoc);
|
|
8761
|
-
else break;
|
|
8762
|
-
}
|
|
8763
|
-
}
|
|
8764
|
-
}
|
|
8765
|
-
if (getBitapScore(d + 1, loc) > scoreThreshold) break;
|
|
8766
|
-
lastRd = rd;
|
|
8767
|
-
}
|
|
8768
|
-
return bestLoc;
|
|
8769
|
-
}
|
|
8770
|
-
function getAlphabetFromPattern(pattern) {
|
|
8771
|
-
let s = {};
|
|
8772
|
-
for (let i = 0; i < pattern.length; i++) s[pattern.charAt(i)] = 0;
|
|
8773
|
-
for (let i = 0; i < pattern.length; i++) s[pattern.charAt(i)] |= 1 << pattern.length - i - 1;
|
|
8774
|
-
return s;
|
|
8775
|
-
}
|
|
8776
|
-
function match(text, pattern, searchLocation, options = {}) {
|
|
8777
|
-
if (text === null || pattern === null || searchLocation === null) throw Error("Null input. (match())");
|
|
8778
|
-
let loc = Math.max(0, Math.min(searchLocation, text.length));
|
|
8779
|
-
if (text === pattern) return 0;
|
|
8780
|
-
if (text.length) {
|
|
8781
|
-
if (text.substring(loc, loc + pattern.length) === pattern) return loc;
|
|
8782
|
-
} else return -1;
|
|
8783
|
-
return bitap(text, pattern, loc, options);
|
|
8784
|
-
}
|
|
8785
|
-
function diffText1(diffs) {
|
|
8786
|
-
let text = [];
|
|
8787
|
-
for (let x = 0; x < diffs.length; x++) diffs[x][0] !== 1 && (text[x] = diffs[x][1]);
|
|
8788
|
-
return text.join("");
|
|
8789
|
-
}
|
|
8790
|
-
function diffText2(diffs) {
|
|
8791
|
-
let text = [];
|
|
8792
|
-
for (let x = 0; x < diffs.length; x++) diffs[x][0] !== -1 && (text[x] = diffs[x][1]);
|
|
8793
|
-
return text.join("");
|
|
8794
|
-
}
|
|
8795
|
-
function levenshtein(diffs) {
|
|
8796
|
-
let leven = 0, insertions = 0, deletions = 0;
|
|
8797
|
-
for (let x = 0; x < diffs.length; x++) {
|
|
8798
|
-
let op = diffs[x][0], data = diffs[x][1];
|
|
8799
|
-
switch (op) {
|
|
8800
|
-
case 1:
|
|
8801
|
-
insertions += data.length;
|
|
8802
|
-
break;
|
|
8803
|
-
case -1:
|
|
8804
|
-
deletions += data.length;
|
|
8805
|
-
break;
|
|
8806
|
-
case 0:
|
|
8807
|
-
leven += Math.max(insertions, deletions), insertions = 0, deletions = 0;
|
|
8808
|
-
break;
|
|
8809
|
-
default: throw Error("Unknown diff operation.");
|
|
8810
|
-
}
|
|
8811
|
-
}
|
|
8812
|
-
return leven += Math.max(insertions, deletions), leven;
|
|
8813
|
-
}
|
|
8814
|
-
function xIndex(diffs, location) {
|
|
8815
|
-
let chars1 = 0, chars2 = 0, lastChars1 = 0, lastChars2 = 0, x;
|
|
8816
|
-
for (x = 0; x < diffs.length && (diffs[x][0] !== 1 && (chars1 += diffs[x][1].length), diffs[x][0] !== -1 && (chars2 += diffs[x][1].length), !(chars1 > location)); x++) lastChars1 = chars1, lastChars2 = chars2;
|
|
8817
|
-
return diffs.length !== x && diffs[x][0] === -1 ? lastChars2 : lastChars2 + (location - lastChars1);
|
|
8818
|
-
}
|
|
8819
|
-
function countUtf8Bytes(str) {
|
|
8820
|
-
let bytes = 0;
|
|
8821
|
-
for (let i = 0; i < str.length; i++) {
|
|
8822
|
-
let codePoint = str.codePointAt(i);
|
|
8823
|
-
if (typeof codePoint > "u") throw Error("Failed to get codepoint");
|
|
8824
|
-
codePoint > 65535 && i++, bytes += utf8len(codePoint);
|
|
8825
|
-
}
|
|
8826
|
-
return bytes;
|
|
8827
|
-
}
|
|
8828
|
-
function adjustIndiciesToUcs2(patches, base, options = {}) {
|
|
8829
|
-
let byteOffset = 0, idx = 0;
|
|
8830
|
-
function advanceTo(target) {
|
|
8831
|
-
for (; byteOffset < target;) {
|
|
8832
|
-
let codePoint = base.codePointAt(idx);
|
|
8833
|
-
if (typeof codePoint > "u") return idx;
|
|
8834
|
-
byteOffset += utf8len(codePoint), idx += codePoint > 65535 ? 2 : 1;
|
|
8835
|
-
}
|
|
8836
|
-
if (!options.allowExceedingIndices && byteOffset !== target) throw Error("Failed to determine byte offset");
|
|
8837
|
-
return idx;
|
|
8838
|
-
}
|
|
8839
|
-
let adjusted = [];
|
|
8840
|
-
for (let patch of patches) adjusted.push({
|
|
8841
|
-
diffs: patch.diffs.map((diff2) => cloneDiff(diff2)),
|
|
8842
|
-
start1: advanceTo(patch.start1),
|
|
8843
|
-
start2: advanceTo(patch.start2),
|
|
8844
|
-
utf8Start1: patch.utf8Start1,
|
|
8845
|
-
utf8Start2: patch.utf8Start2,
|
|
8846
|
-
length1: patch.length1,
|
|
8847
|
-
length2: patch.length2,
|
|
8848
|
-
utf8Length1: patch.utf8Length1,
|
|
8849
|
-
utf8Length2: patch.utf8Length2
|
|
8850
|
-
});
|
|
8851
|
-
return adjusted;
|
|
8852
|
-
}
|
|
8853
|
-
function utf8len(codePoint) {
|
|
8854
|
-
return codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
|
|
8855
|
-
}
|
|
8856
|
-
function addPadding(patches, margin = 4) {
|
|
8857
|
-
let paddingLength = margin, nullPadding = "";
|
|
8858
|
-
for (let x = 1; x <= paddingLength; x++) nullPadding += String.fromCharCode(x);
|
|
8859
|
-
for (let p of patches) p.start1 += paddingLength, p.start2 += paddingLength, p.utf8Start1 += paddingLength, p.utf8Start2 += paddingLength;
|
|
8860
|
-
let patch = patches[0], diffs = patch.diffs;
|
|
8861
|
-
if (diffs.length === 0 || diffs[0][0] !== 0) diffs.unshift([0, nullPadding]), patch.start1 -= paddingLength, patch.start2 -= paddingLength, patch.utf8Start1 -= paddingLength, patch.utf8Start2 -= paddingLength, patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
|
|
8862
|
-
else if (paddingLength > diffs[0][1].length) {
|
|
8863
|
-
let firstDiffLength = diffs[0][1].length, extraLength = paddingLength - firstDiffLength;
|
|
8864
|
-
diffs[0][1] = nullPadding.substring(firstDiffLength) + diffs[0][1], patch.start1 -= extraLength, patch.start2 -= extraLength, patch.utf8Start1 -= extraLength, patch.utf8Start2 -= extraLength, patch.length1 += extraLength, patch.length2 += extraLength, patch.utf8Length1 += extraLength, patch.utf8Length2 += extraLength;
|
|
8865
|
-
}
|
|
8866
|
-
if (patch = patches[patches.length - 1], diffs = patch.diffs, diffs.length === 0 || diffs[diffs.length - 1][0] !== 0) diffs.push([0, nullPadding]), patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
|
|
8867
|
-
else if (paddingLength > diffs[diffs.length - 1][1].length) {
|
|
8868
|
-
let extraLength = paddingLength - diffs[diffs.length - 1][1].length;
|
|
8869
|
-
diffs[diffs.length - 1][1] += nullPadding.substring(0, extraLength), patch.length1 += extraLength, patch.length2 += extraLength, patch.utf8Length1 += extraLength, patch.utf8Length2 += extraLength;
|
|
8870
|
-
}
|
|
8871
|
-
return nullPadding;
|
|
8872
|
-
}
|
|
8873
|
-
function createPatchObject(start1, start2) {
|
|
8874
|
-
return {
|
|
8875
|
-
diffs: [],
|
|
8876
|
-
start1,
|
|
8877
|
-
start2,
|
|
8878
|
-
utf8Start1: start1,
|
|
8879
|
-
utf8Start2: start2,
|
|
8880
|
-
length1: 0,
|
|
8881
|
-
length2: 0,
|
|
8882
|
-
utf8Length1: 0,
|
|
8883
|
-
utf8Length2: 0
|
|
8884
|
-
};
|
|
8885
|
-
}
|
|
8886
|
-
function splitMax(patches, margin = 4) {
|
|
8887
|
-
for (let x = 0; x < patches.length; x++) {
|
|
8888
|
-
if (patches[x].length1 <= 32) continue;
|
|
8889
|
-
let bigpatch = patches[x];
|
|
8890
|
-
patches.splice(x--, 1);
|
|
8891
|
-
let start1 = bigpatch.start1, start2 = bigpatch.start2, preContext = "";
|
|
8892
|
-
for (; bigpatch.diffs.length !== 0;) {
|
|
8893
|
-
let patch = createPatchObject(start1 - preContext.length, start2 - preContext.length), empty = !0;
|
|
8894
|
-
if (preContext !== "") {
|
|
8895
|
-
let precontextByteCount = countUtf8Bytes(preContext);
|
|
8896
|
-
patch.length1 = preContext.length, patch.utf8Length1 = precontextByteCount, patch.length2 = preContext.length, patch.utf8Length2 = precontextByteCount, patch.diffs.push([0, preContext]);
|
|
8897
|
-
}
|
|
8898
|
-
for (; bigpatch.diffs.length !== 0 && patch.length1 < 32 - margin;) {
|
|
8899
|
-
let diffType = bigpatch.diffs[0][0], diffText = bigpatch.diffs[0][1], diffTextByteCount = countUtf8Bytes(diffText);
|
|
8900
|
-
if (diffType === 1) {
|
|
8901
|
-
patch.length2 += diffText.length, patch.utf8Length2 += diffTextByteCount, start2 += diffText.length;
|
|
8902
|
-
let diff2 = bigpatch.diffs.shift();
|
|
8903
|
-
diff2 && patch.diffs.push(diff2), empty = !1;
|
|
8904
|
-
} else diffType === -1 && patch.diffs.length === 1 && patch.diffs[0][0] === 0 && diffText.length > 64 ? (patch.length1 += diffText.length, patch.utf8Length1 += diffTextByteCount, start1 += diffText.length, empty = !1, patch.diffs.push([diffType, diffText]), bigpatch.diffs.shift()) : (diffText = diffText.substring(0, 32 - patch.length1 - margin), diffTextByteCount = countUtf8Bytes(diffText), patch.length1 += diffText.length, patch.utf8Length1 += diffTextByteCount, start1 += diffText.length, diffType === 0 ? (patch.length2 += diffText.length, patch.utf8Length2 += diffTextByteCount, start2 += diffText.length) : empty = !1, patch.diffs.push([diffType, diffText]), diffText === bigpatch.diffs[0][1] ? bigpatch.diffs.shift() : bigpatch.diffs[0][1] = bigpatch.diffs[0][1].substring(diffText.length));
|
|
8905
|
-
}
|
|
8906
|
-
preContext = diffText2(patch.diffs), preContext = preContext.substring(preContext.length - margin);
|
|
8907
|
-
let postContext = diffText1(bigpatch.diffs).substring(0, margin), postContextByteCount = countUtf8Bytes(postContext);
|
|
8908
|
-
postContext !== "" && (patch.length1 += postContext.length, patch.length2 += postContext.length, patch.utf8Length1 += postContextByteCount, patch.utf8Length2 += postContextByteCount, patch.diffs.length !== 0 && patch.diffs[patch.diffs.length - 1][0] === 0 ? patch.diffs[patch.diffs.length - 1][1] += postContext : patch.diffs.push([0, postContext])), empty || patches.splice(++x, 0, patch);
|
|
8909
|
-
}
|
|
8910
|
-
}
|
|
8911
|
-
}
|
|
8912
|
-
function apply(patches, originalText, opts = {}) {
|
|
8913
|
-
if (typeof patches == "string") throw Error("Patches must be an array - pass the patch to `parsePatch()` first");
|
|
8914
|
-
let text = originalText;
|
|
8915
|
-
if (patches.length === 0) return [text, []];
|
|
8916
|
-
let parsed = adjustIndiciesToUcs2(patches, text, { allowExceedingIndices: opts.allowExceedingIndices }), margin = opts.margin || 4, deleteThreshold = opts.deleteThreshold || .4, nullPadding = addPadding(parsed, margin);
|
|
8917
|
-
text = nullPadding + text + nullPadding, splitMax(parsed, margin);
|
|
8918
|
-
let delta = 0, results = [];
|
|
8919
|
-
for (let x = 0; x < parsed.length; x++) {
|
|
8920
|
-
let expectedLoc = parsed[x].start2 + delta, text1 = diffText1(parsed[x].diffs), startLoc, endLoc = -1;
|
|
8921
|
-
if (text1.length > 32 ? (startLoc = match(text, text1.substring(0, 32), expectedLoc), startLoc !== -1 && (endLoc = match(text, text1.substring(text1.length - 32), expectedLoc + text1.length - 32), (endLoc === -1 || startLoc >= endLoc) && (startLoc = -1))) : startLoc = match(text, text1, expectedLoc), startLoc === -1) results[x] = !1, delta -= parsed[x].length2 - parsed[x].length1;
|
|
8922
|
-
else {
|
|
8923
|
-
results[x] = !0, delta = startLoc - expectedLoc;
|
|
8924
|
-
let text2;
|
|
8925
|
-
if (text2 = endLoc === -1 ? text.substring(startLoc, startLoc + text1.length) : text.substring(startLoc, endLoc + 32), text1 === text2) text = text.substring(0, startLoc) + diffText2(parsed[x].diffs) + text.substring(startLoc + text1.length);
|
|
8926
|
-
else {
|
|
8927
|
-
let diffs = diff(text1, text2, { checkLines: !1 });
|
|
8928
|
-
if (text1.length > 32 && levenshtein(diffs) / text1.length > deleteThreshold) results[x] = !1;
|
|
8929
|
-
else {
|
|
8930
|
-
diffs = cleanupSemanticLossless(diffs);
|
|
8931
|
-
let index1 = 0, index2 = 0;
|
|
8932
|
-
for (let y = 0; y < parsed[x].diffs.length; y++) {
|
|
8933
|
-
let mod = parsed[x].diffs[y];
|
|
8934
|
-
mod[0] !== 0 && (index2 = xIndex(diffs, index1)), mod[0] === 1 ? text = text.substring(0, startLoc + index2) + mod[1] + text.substring(startLoc + index2) : mod[0] === -1 && (text = text.substring(0, startLoc + index2) + text.substring(startLoc + xIndex(diffs, index1 + mod[1].length))), mod[0] !== -1 && (index1 += mod[1].length);
|
|
8935
|
-
}
|
|
8936
|
-
}
|
|
8937
|
-
}
|
|
8938
|
-
}
|
|
8939
|
-
}
|
|
8940
|
-
return text = text.substring(nullPadding.length, text.length - nullPadding.length), [text, results];
|
|
8941
|
-
}
|
|
8942
|
-
const patchHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;
|
|
8943
|
-
function parse(textline) {
|
|
8944
|
-
if (!textline) return [];
|
|
8945
|
-
let patches = [], lines = textline.split("\n"), textPointer = 0;
|
|
8946
|
-
for (; textPointer < lines.length;) {
|
|
8947
|
-
let m = lines[textPointer].match(patchHeader);
|
|
8948
|
-
if (!m) throw Error(`Invalid patch string: ${lines[textPointer]}`);
|
|
8949
|
-
let patch = createPatchObject(toInt(m[1]), toInt(m[3]));
|
|
8950
|
-
for (patches.push(patch), m[2] === "" ? (patch.start1--, patch.utf8Start1--, patch.length1 = 1, patch.utf8Length1 = 1) : m[2] === "0" ? (patch.length1 = 0, patch.utf8Length1 = 0) : (patch.start1--, patch.utf8Start1--, patch.utf8Length1 = toInt(m[2]), patch.length1 = patch.utf8Length1), m[4] === "" ? (patch.start2--, patch.utf8Start2--, patch.length2 = 1, patch.utf8Length2 = 1) : m[4] === "0" ? (patch.length2 = 0, patch.utf8Length2 = 0) : (patch.start2--, patch.utf8Start2--, patch.utf8Length2 = toInt(m[4]), patch.length2 = patch.utf8Length2), textPointer++; textPointer < lines.length;) {
|
|
8951
|
-
let currentLine = lines[textPointer], sign = currentLine.charAt(0);
|
|
8952
|
-
if (sign === "@") break;
|
|
8953
|
-
if (sign === "") {
|
|
8954
|
-
textPointer++;
|
|
8955
|
-
continue;
|
|
8956
|
-
}
|
|
8957
|
-
let line;
|
|
8958
|
-
try {
|
|
8959
|
-
line = decodeURI(currentLine.slice(1));
|
|
8960
|
-
} catch {
|
|
8961
|
-
throw Error(`Illegal escape in parse: ${currentLine}`);
|
|
8962
|
-
}
|
|
8963
|
-
let utf8Diff = countUtf8Bytes(line) - line.length;
|
|
8964
|
-
if (sign === "-") patch.diffs.push([-1, line]), patch.length1 -= utf8Diff;
|
|
8965
|
-
else if (sign === "+") patch.diffs.push([1, line]), patch.length2 -= utf8Diff;
|
|
8966
|
-
else if (sign === " ") patch.diffs.push([0, line]), patch.length1 -= utf8Diff, patch.length2 -= utf8Diff;
|
|
8967
|
-
else throw Error(`Invalid patch mode "${sign}" in: ${line}`);
|
|
8968
|
-
textPointer++;
|
|
8969
|
-
}
|
|
8970
|
-
}
|
|
8971
|
-
return patches;
|
|
8972
|
-
}
|
|
8973
|
-
function toInt(num) {
|
|
8974
|
-
return parseInt(num, 10);
|
|
8975
|
-
}
|
|
8976
8359
|
function toEngineBlock(block, { schemaTypes }) {
|
|
8977
8360
|
let { _type, _key, ...rest } = block;
|
|
8978
8361
|
if (block && block._type === schemaTypes.block.name) {
|
|
@@ -9042,7 +8425,7 @@ function diffMatchPatch$1(editor, patch) {
|
|
|
9042
8425
|
if (patch.path.at(-1) !== "text") {
|
|
9043
8426
|
let currentValue = getValue(editor.snapshot.context.value, patch.path);
|
|
9044
8427
|
if (typeof currentValue != "string") return !1;
|
|
9045
|
-
let [newValue] =
|
|
8428
|
+
let [newValue] = applyPatches(parsePatch(patch.value), currentValue, { allowExceedingIndices: !0 });
|
|
9046
8429
|
return editor.apply({
|
|
9047
8430
|
type: "set",
|
|
9048
8431
|
path: patch.path,
|
|
@@ -9051,18 +8434,18 @@ function diffMatchPatch$1(editor, patch) {
|
|
|
9051
8434
|
}
|
|
9052
8435
|
let spanPath = patch.path.slice(0, -1), spanEntry = getNode(editor.snapshot, spanPath);
|
|
9053
8436
|
if (!spanEntry || !isSpan({ schema: editor.snapshot.context.schema }, spanEntry.node)) return !1;
|
|
9054
|
-
let
|
|
9055
|
-
for (let [op, text] of diff
|
|
8437
|
+
let patches = parsePatch(patch.value), [newValue] = applyPatches(patches, spanEntry.node.text, { allowExceedingIndices: !0 }), diff = cleanupEfficiency(makeDiff(spanEntry.node.text, newValue), 5), offset = 0;
|
|
8438
|
+
for (let [op, text] of diff) op === DIFF_INSERT ? (editor.apply({
|
|
9056
8439
|
type: "insert.text",
|
|
9057
8440
|
path: spanEntry.path,
|
|
9058
8441
|
offset,
|
|
9059
8442
|
text
|
|
9060
|
-
}), offset += text.length) : op ===
|
|
8443
|
+
}), offset += text.length) : op === DIFF_DELETE ? editor.apply({
|
|
9061
8444
|
type: "remove.text",
|
|
9062
8445
|
path: spanEntry.path,
|
|
9063
8446
|
offset,
|
|
9064
8447
|
text
|
|
9065
|
-
}) : op ===
|
|
8448
|
+
}) : op === DIFF_EQUAL && (offset += text.length);
|
|
9066
8449
|
return !0;
|
|
9067
8450
|
}
|
|
9068
8451
|
function insertPatch(context, editor, patch) {
|
|
@@ -9429,7 +8812,7 @@ function resolveSiblingContext(context, value, opPath) {
|
|
|
9429
8812
|
let resolvedParent = resolveIndexableNode(context, value, keyedParentPath);
|
|
9430
8813
|
if (!resolvedParent) return;
|
|
9431
8814
|
let childrenResult = getNodeChildren(context, resolvedParent.node, resolvedParent.containerOfParent);
|
|
9432
|
-
if (
|
|
8815
|
+
if (childrenResult && childrenResult.fieldName === fieldSegment) return {
|
|
9433
8816
|
children: childrenResult.children,
|
|
9434
8817
|
serializedPrefix: serializePath([...keyedParentPath, fieldSegment])
|
|
9435
8818
|
};
|
|
@@ -9445,7 +8828,7 @@ function resolveSiblingContext(context, value, opPath) {
|
|
|
9445
8828
|
function reindexSiblings(map, siblingContext, startIndex) {
|
|
9446
8829
|
for (let childIndex = Math.max(0, startIndex); childIndex < siblingContext.children.length; childIndex++) {
|
|
9447
8830
|
let child = siblingContext.children[childIndex];
|
|
9448
|
-
|
|
8831
|
+
child && child._key !== void 0 && map.set(`${siblingContext.serializedPrefix}[_key=="${child._key}"]`, childIndex);
|
|
9449
8832
|
}
|
|
9450
8833
|
}
|
|
9451
8834
|
/**
|
|
@@ -11691,7 +11074,7 @@ function planMergeKeyRenames(args) {
|
|
|
11691
11074
|
});
|
|
11692
11075
|
}
|
|
11693
11076
|
let childRenames = [], renamedChildren = mergingBlock.children.map((child) => {
|
|
11694
|
-
let currentMarks = isSpan(context, child) ? child.marks : void 0, remappedMarks = currentMarks?.map((mark) => markDefKeyMap.get(mark) ?? mark), marksChanged =
|
|
11077
|
+
let currentMarks = isSpan(context, child) ? child.marks : void 0, remappedMarks = currentMarks?.map((mark) => markDefKeyMap.get(mark) ?? mark), marksChanged = !(!remappedMarks || isEqualMarks(remappedMarks, currentMarks)), newKey = destinationChildKeys.has(child._key) ? context.keyGenerator() : child._key, props = {};
|
|
11695
11078
|
return newKey !== child._key && (props._key = newKey), marksChanged && (props.marks = remappedMarks), Object.keys(props).length > 0 && childRenames.push({
|
|
11696
11079
|
childKey: child._key,
|
|
11697
11080
|
props
|
|
@@ -12386,11 +11769,11 @@ function transformOperation(editor, patch, operation) {
|
|
|
12386
11769
|
if (patch.type === "unset" && patch.path.length === 0) return debug.history(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
12387
11770
|
if (patch.type === "diffMatchPatch") {
|
|
12388
11771
|
let operationTargetBlock = findOperationTargetBlock(snapshot, editor, transformedOperation), patchTargetBlock = getEnclosingBlock(snapshot, patch.path);
|
|
12389
|
-
return !operationTargetBlock || !patchTargetBlock || operationTargetBlock._key !== patchTargetBlock.node._key ||
|
|
11772
|
+
return !operationTargetBlock || !patchTargetBlock || operationTargetBlock._key !== patchTargetBlock.node._key || parsePatch(patch.value).forEach((diffPatch) => {
|
|
12390
11773
|
let adjustOffsetBy = 0, changedOffset = diffPatch.utf8Start1, { diffs } = diffPatch;
|
|
12391
11774
|
if (diffs.forEach((diff, index) => {
|
|
12392
11775
|
let [diffType, text] = diff;
|
|
12393
|
-
diffType ===
|
|
11776
|
+
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
|
|
12394
11777
|
}), transformedOperation.type === "insert.text" && changedOffset < transformedOperation.offset && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "remove.text" && changedOffset <= transformedOperation.offset - transformedOperation.text.length && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "set.selection") {
|
|
12395
11778
|
let currentFocus = transformedOperation.properties?.focus ? { ...transformedOperation.properties.focus } : void 0, currentAnchor = transformedOperation?.properties?.anchor ? { ...transformedOperation.properties.anchor } : void 0, newFocus = transformedOperation?.newProperties?.focus ? { ...transformedOperation.newProperties.focus } : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? { ...transformedOperation.newProperties.anchor } : void 0;
|
|
12396
11779
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([
|
|
@@ -14438,7 +13821,7 @@ const abstractInsertBehaviors = [
|
|
|
14438
13821
|
context: snapshot.context,
|
|
14439
13822
|
block: endBlock
|
|
14440
13823
|
});
|
|
14441
|
-
return
|
|
13824
|
+
return !(!isTextBlockNode(snapshot.context, startBlock.node) || !isTextBlockNode(snapshot.context, endBlock.node) || isEqualSelectionPoints(startPoint, startBlockStartPoint) || isEqualSelectionPoints(endPoint, endBlockEndPoint));
|
|
14442
13825
|
},
|
|
14443
13826
|
actions: [() => [raise$1({ type: "delete" }), raise$1({ type: "split" })]]
|
|
14444
13827
|
}),
|
|
@@ -14784,7 +14167,7 @@ function sortByPriority(items) {
|
|
|
14784
14167
|
ensureNode(id);
|
|
14785
14168
|
}
|
|
14786
14169
|
function addEdge(fromId, toId) {
|
|
14787
|
-
|
|
14170
|
+
graph.has(fromId) && graph.has(toId) && (graph.get(fromId)?.add(toId), inDegree.set(toId, (inDegree.get(toId) ?? 0) + 1));
|
|
14788
14171
|
}
|
|
14789
14172
|
for (let item of itemsWithPriority) {
|
|
14790
14173
|
let id = item.priority.id, visited = /* @__PURE__ */ new Set(), ref = item.priority.reference;
|
|
@@ -15021,7 +14404,7 @@ function isTypeAlreadyRegistered(maps, attempting, type) {
|
|
|
15021
14404
|
]) {
|
|
15022
14405
|
if (otherKind === attempting || attempting === "blockObject" && otherKind === "inlineObject" || attempting === "inlineObject" && otherKind === "blockObject") continue;
|
|
15023
14406
|
let attemptingIsExclusive = exclusiveKinds.includes(attempting), otherIsExclusive = exclusiveKinds.includes(otherKind);
|
|
15024
|
-
if (
|
|
14407
|
+
if ((attemptingIsExclusive || otherIsExclusive) && claimedAs(otherKind)) return console.warn(`registerNode: type "${type}" is already registered as a ${otherKind}. A type must be exactly one of: container, textBlock, span, or co-registered as blockObject+inlineObject.`), !0;
|
|
15025
14408
|
}
|
|
15026
14409
|
return !1;
|
|
15027
14410
|
}
|