@portabletext/editor 1.17.0 → 1.18.0

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.
Files changed (56) hide show
  1. package/README.md +228 -261
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  4. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +1 -1
  5. package/lib/_chunks-es/behavior.core.js.map +1 -1
  6. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  7. package/lib/_chunks-es/selector.is-selection-collapsed.js.map +1 -1
  8. package/lib/behaviors/index.cjs +40 -38
  9. package/lib/behaviors/index.cjs.map +1 -1
  10. package/lib/behaviors/index.d.cts +23 -23
  11. package/lib/behaviors/index.d.ts +23 -23
  12. package/lib/behaviors/index.js +40 -38
  13. package/lib/behaviors/index.js.map +1 -1
  14. package/lib/index.cjs +301 -351
  15. package/lib/index.cjs.map +1 -1
  16. package/lib/index.d.cts +123 -753
  17. package/lib/index.d.ts +123 -753
  18. package/lib/index.js +301 -351
  19. package/lib/index.js.map +1 -1
  20. package/lib/selectors/index.cjs.map +1 -1
  21. package/lib/selectors/index.d.cts +30 -30
  22. package/lib/selectors/index.d.ts +30 -30
  23. package/lib/selectors/index.js.map +1 -1
  24. package/package.json +10 -10
  25. package/src/behaviors/behavior.code-editor.ts +2 -2
  26. package/src/behaviors/behavior.core.ts +2 -2
  27. package/src/behaviors/behavior.emoji-picker.ts +52 -41
  28. package/src/behaviors/behavior.links.ts +2 -2
  29. package/src/behaviors/behavior.markdown.ts +2 -2
  30. package/src/behaviors/behavior.types.ts +10 -10
  31. package/src/editor/PortableTextEditor.tsx +2 -0
  32. package/src/editor/__tests__/self-solving.test.tsx +14 -0
  33. package/src/editor/components/Synchronizer.tsx +6 -1
  34. package/src/editor/create-editor.ts +14 -3
  35. package/src/editor/define-schema.ts +4 -4
  36. package/src/editor/editor-event-listener.tsx +1 -1
  37. package/src/editor/editor-machine.ts +42 -52
  38. package/src/editor/editor-provider.tsx +3 -3
  39. package/src/editor/editor-selector.ts +31 -14
  40. package/src/editor/editor-snapshot.ts +2 -2
  41. package/src/editor/get-value.ts +12 -5
  42. package/src/editor/hooks/usePortableTextEditor.ts +1 -0
  43. package/src/editor/hooks/usePortableTextEditorSelection.tsx +1 -0
  44. package/src/selectors/selector.get-active-list-item.ts +1 -1
  45. package/src/selectors/selector.get-active-style.ts +1 -1
  46. package/src/selectors/selector.get-selected-spans.ts +1 -1
  47. package/src/selectors/selector.get-selection-text.ts +1 -1
  48. package/src/selectors/selector.get-text-before.ts +1 -1
  49. package/src/selectors/selector.is-active-annotation.ts +1 -1
  50. package/src/selectors/selector.is-active-decorator.ts +1 -1
  51. package/src/selectors/selector.is-active-list-item.ts +1 -1
  52. package/src/selectors/selector.is-active-style.ts +1 -1
  53. package/src/selectors/selector.is-selection-collapsed.ts +1 -1
  54. package/src/selectors/selector.is-selection-expanded.ts +1 -1
  55. package/src/selectors/selectors.ts +13 -13
  56. package/src/types/editor.ts +2 -2
package/lib/index.cjs CHANGED
@@ -1236,14 +1236,6 @@ function withoutPatching(editor, fn) {
1236
1236
  function isPatching(editor) {
1237
1237
  return PATCHING.get(editor);
1238
1238
  }
1239
- function isHighSurrogate(char) {
1240
- const charCode = char.charCodeAt(0);
1241
- return charCode >= 55296 && charCode <= 56319;
1242
- }
1243
- function isLowSurrogate(char) {
1244
- const charCode = char.charCodeAt(0);
1245
- return charCode >= 56320 && charCode <= 57343;
1246
- }
1247
1239
  function cloneDiff(diff2) {
1248
1240
  const [type, patch] = diff2;
1249
1241
  return [type, patch];
@@ -1251,123 +1243,41 @@ function cloneDiff(diff2) {
1251
1243
  function getCommonOverlap(textA, textB) {
1252
1244
  let text1 = textA, text2 = textB;
1253
1245
  const text1Length = text1.length, text2Length = text2.length;
1254
- if (text1Length === 0 || text2Length === 0)
1255
- return 0;
1246
+ if (text1Length === 0 || text2Length === 0) return 0;
1256
1247
  text1Length > text2Length ? text1 = text1.substring(text1Length - text2Length) : text1Length < text2Length && (text2 = text2.substring(0, text1Length));
1257
1248
  const textLength = Math.min(text1Length, text2Length);
1258
- if (text1 === text2)
1259
- return textLength;
1249
+ if (text1 === text2) return textLength;
1260
1250
  let best = 0, length = 1;
1261
1251
  for (let found = 0; found !== -1; ) {
1262
1252
  const pattern = text1.substring(textLength - length);
1263
- if (found = text2.indexOf(pattern), found === -1)
1264
- return best;
1253
+ if (found = text2.indexOf(pattern), found === -1) return best;
1265
1254
  length += found, (found === 0 || text1.substring(textLength - length) === text2.substring(0, length)) && (best = length, length++);
1266
1255
  }
1267
1256
  return best;
1268
1257
  }
1269
1258
  function getCommonPrefix(text1, text2) {
1270
- if (!text1 || !text2 || text1[0] !== text2[0])
1271
- return 0;
1259
+ if (!text1 || !text2 || text1[0] !== text2[0]) return 0;
1272
1260
  let pointerMin = 0, pointerMax = Math.min(text1.length, text2.length), pointerMid = pointerMax, pointerStart = 0;
1273
- for (; pointerMin < pointerMid; )
1274
- text1.substring(pointerStart, pointerMid) === text2.substring(pointerStart, pointerMid) ? (pointerMin = pointerMid, pointerStart = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
1261
+ for (; pointerMin < pointerMid; ) text1.substring(pointerStart, pointerMid) === text2.substring(pointerStart, pointerMid) ? (pointerMin = pointerMid, pointerStart = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
1275
1262
  return pointerMid;
1276
1263
  }
1277
1264
  function getCommonSuffix(text1, text2) {
1278
- if (!text1 || !text2 || text1[text1.length - 1] !== text2[text2.length - 1])
1279
- return 0;
1265
+ if (!text1 || !text2 || text1[text1.length - 1] !== text2[text2.length - 1]) return 0;
1280
1266
  let pointerMin = 0, pointerMax = Math.min(text1.length, text2.length), pointerMid = pointerMax, pointerEnd = 0;
1281
- for (; pointerMin < pointerMid; )
1282
- 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);
1267
+ 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);
1283
1268
  return pointerMid;
1284
1269
  }
1285
- function cleanupSemantic(rawDiffs) {
1286
- let diffs = rawDiffs.map((diff2) => cloneDiff(diff2)), hasChanges = !1;
1287
- const equalities = [];
1288
- let equalitiesLength = 0, lastEquality = null, pointer = 0, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0;
1289
- for (; pointer < diffs.length; )
1290
- diffs[pointer][0] === DIFF_EQUAL ? (equalities[equalitiesLength++] = pointer, lengthInsertions1 = lengthInsertions2, lengthDeletions1 = lengthDeletions2, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = diffs[pointer][1]) : (diffs[pointer][0] === DIFF_INSERT ? 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, [DIFF_DELETE, lastEquality]), diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT, equalitiesLength--, equalitiesLength--, pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = null, hasChanges = !0)), pointer++;
1291
- for (hasChanges && (diffs = cleanupMerge(diffs)), diffs = cleanupSemanticLossless(diffs), pointer = 1; pointer < diffs.length; ) {
1292
- if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
1293
- const deletion = diffs[pointer - 1][1], insertion = diffs[pointer][1], overlapLength1 = getCommonOverlap(deletion, insertion), overlapLength2 = getCommonOverlap(insertion, deletion);
1294
- overlapLength1 >= overlapLength2 ? (overlapLength1 >= deletion.length / 2 || overlapLength1 >= insertion.length / 2) && (diffs.splice(pointer, 0, [DIFF_EQUAL, 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, [DIFF_EQUAL, deletion.substring(0, overlapLength2)]), diffs[pointer - 1][0] = DIFF_INSERT, diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlapLength2), diffs[pointer + 1][0] = DIFF_DELETE, diffs[pointer + 1][1] = deletion.substring(overlapLength2), pointer++), pointer++;
1295
- }
1296
- pointer++;
1297
- }
1298
- return diffs;
1299
- }
1300
- const nonAlphaNumericRegex = /[^a-zA-Z0-9]/, whitespaceRegex = /\s/, linebreakRegex = /[\r\n]/, blanklineEndRegex = /\n\r?\n$/, blanklineStartRegex = /^\r?\n\r?\n/;
1301
- function cleanupSemanticLossless(rawDiffs) {
1302
- const diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
1303
- function diffCleanupSemanticScore(one, two) {
1304
- if (!one || !two)
1305
- return 6;
1306
- const 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);
1307
- return blankLine1 || blankLine2 ? 5 : lineBreak1 || lineBreak2 ? 4 : nonAlphaNumeric1 && !whitespace1 && whitespace2 ? 3 : whitespace1 || whitespace2 ? 2 : nonAlphaNumeric1 || nonAlphaNumeric2 ? 1 : 0;
1308
- }
1309
- let pointer = 1;
1310
- for (; pointer < diffs.length - 1; ) {
1311
- if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
1312
- let equality1 = diffs[pointer - 1][1], edit = diffs[pointer][1], equality2 = diffs[pointer + 1][1];
1313
- const commonOffset = getCommonSuffix(equality1, edit);
1314
- if (commonOffset) {
1315
- const commonString = edit.substring(edit.length - commonOffset);
1316
- equality1 = equality1.substring(0, equality1.length - commonOffset), edit = commonString + edit.substring(0, edit.length - commonOffset), equality2 = commonString + equality2;
1317
- }
1318
- let bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2, bestScore = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
1319
- for (; edit.charAt(0) === equality2.charAt(0); ) {
1320
- equality1 += edit.charAt(0), edit = edit.substring(1) + equality2.charAt(0), equality2 = equality2.substring(1);
1321
- const score = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
1322
- score >= bestScore && (bestScore = score, bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2);
1323
- }
1324
- 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--));
1325
- }
1326
- pointer++;
1327
- }
1328
- return diffs;
1329
- }
1330
- function cleanupMerge(rawDiffs) {
1331
- let diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
1332
- diffs.push([DIFF_EQUAL, ""]);
1333
- let pointer = 0, countDelete = 0, countInsert = 0, textDelete = "", textInsert = "", commonlength;
1334
- for (; pointer < diffs.length; )
1335
- switch (diffs[pointer][0]) {
1336
- case DIFF_INSERT:
1337
- countInsert++, textInsert += diffs[pointer][1], pointer++;
1338
- break;
1339
- case DIFF_DELETE:
1340
- countDelete++, textDelete += diffs[pointer][1], pointer++;
1341
- break;
1342
- case DIFF_EQUAL:
1343
- countDelete + countInsert > 1 ? (countDelete !== 0 && countInsert !== 0 && (commonlength = getCommonPrefix(textInsert, textDelete), commonlength !== 0 && (pointer - countDelete - countInsert > 0 && diffs[pointer - countDelete - countInsert - 1][0] === DIFF_EQUAL ? diffs[pointer - countDelete - countInsert - 1][1] += textInsert.substring(0, commonlength) : (diffs.splice(0, 0, [DIFF_EQUAL, 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, [DIFF_DELETE, textDelete]), pointer++), textInsert.length && (diffs.splice(pointer, 0, [DIFF_INSERT, textInsert]), pointer++), pointer++) : pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL ? (diffs[pointer - 1][1] += diffs[pointer][1], diffs.splice(pointer, 1)) : pointer++, countInsert = 0, countDelete = 0, textDelete = "", textInsert = "";
1344
- break;
1345
- default:
1346
- throw new Error("Unknown diff operation");
1347
- }
1348
- diffs[diffs.length - 1][1] === "" && diffs.pop();
1349
- let hasChanges = !1;
1350
- for (pointer = 1; pointer < diffs.length - 1; )
1351
- diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL && (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++;
1352
- return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
1353
- }
1354
- function trueCount() {
1355
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++)
1356
- args[_key] = arguments[_key];
1357
- return args.reduce((n, bool) => n + (bool ? 1 : 0), 0);
1270
+ function isHighSurrogate(char) {
1271
+ const charCode = char.charCodeAt(0);
1272
+ return charCode >= 55296 && charCode <= 56319;
1358
1273
  }
1359
- function cleanupEfficiency(rawDiffs) {
1360
- let editCost = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 4, diffs = rawDiffs.map((diff2) => cloneDiff(diff2)), hasChanges = !1;
1361
- const equalities = [];
1362
- let equalitiesLength = 0, lastEquality = null, pointer = 0, preIns = !1, preDel = !1, postIns = !1, postDel = !1;
1363
- for (; pointer < diffs.length; )
1364
- diffs[pointer][0] === DIFF_EQUAL ? (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] === DIFF_DELETE ? 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, [DIFF_DELETE, lastEquality]), diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT, 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++;
1365
- return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
1274
+ function isLowSurrogate(char) {
1275
+ const charCode = char.charCodeAt(0);
1276
+ return charCode >= 56320 && charCode <= 57343;
1366
1277
  }
1367
1278
  function bisect(text1, text2, deadline) {
1368
1279
  const text1Length = text1.length, text2Length = text2.length, maxD = Math.ceil((text1Length + text2Length) / 2), vOffset = maxD, vLength = 2 * maxD, v1 = new Array(vLength), v2 = new Array(vLength);
1369
- for (let x = 0; x < vLength; x++)
1370
- v1[x] = -1, v2[x] = -1;
1280
+ for (let x = 0; x < vLength; x++) v1[x] = -1, v2[x] = -1;
1371
1281
  v1[vOffset + 1] = 0, v2[vOffset + 1] = 0;
1372
1282
  const delta = text1Length - text2Length, front = delta % 2 !== 0;
1373
1283
  let k1start = 0, k1end = 0, k2start = 0, k2end = 0;
@@ -1377,18 +1287,14 @@ function bisect(text1, text2, deadline) {
1377
1287
  let x1;
1378
1288
  k1 === -d || k1 !== d && v1[k1Offset - 1] < v1[k1Offset + 1] ? x1 = v1[k1Offset + 1] : x1 = v1[k1Offset - 1] + 1;
1379
1289
  let y1 = x1 - k1;
1380
- for (; x1 < text1Length && y1 < text2Length && text1.charAt(x1) === text2.charAt(y1); )
1381
- x1++, y1++;
1382
- if (v1[k1Offset] = x1, x1 > text1Length)
1383
- k1end += 2;
1384
- else if (y1 > text2Length)
1385
- k1start += 2;
1290
+ for (; x1 < text1Length && y1 < text2Length && text1.charAt(x1) === text2.charAt(y1); ) x1++, y1++;
1291
+ if (v1[k1Offset] = x1, x1 > text1Length) k1end += 2;
1292
+ else if (y1 > text2Length) k1start += 2;
1386
1293
  else if (front) {
1387
1294
  const k2Offset = vOffset + delta - k1;
1388
1295
  if (k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] !== -1) {
1389
1296
  const x2 = text1Length - v2[k2Offset];
1390
- if (x1 >= x2)
1391
- return bisectSplit(text1, text2, x1, y1, deadline);
1297
+ if (x1 >= x2) return bisectSplit(text1, text2, x1, y1, deadline);
1392
1298
  }
1393
1299
  }
1394
1300
  }
@@ -1397,18 +1303,14 @@ function bisect(text1, text2, deadline) {
1397
1303
  let x2;
1398
1304
  k2 === -d || k2 !== d && v2[k2Offset - 1] < v2[k2Offset + 1] ? x2 = v2[k2Offset + 1] : x2 = v2[k2Offset - 1] + 1;
1399
1305
  let y2 = x2 - k2;
1400
- for (; x2 < text1Length && y2 < text2Length && text1.charAt(text1Length - x2 - 1) === text2.charAt(text2Length - y2 - 1); )
1401
- x2++, y2++;
1402
- if (v2[k2Offset] = x2, x2 > text1Length)
1403
- k2end += 2;
1404
- else if (y2 > text2Length)
1405
- k2start += 2;
1306
+ for (; x2 < text1Length && y2 < text2Length && text1.charAt(text1Length - x2 - 1) === text2.charAt(text2Length - y2 - 1); ) x2++, y2++;
1307
+ if (v2[k2Offset] = x2, x2 > text1Length) k2end += 2;
1308
+ else if (y2 > text2Length) k2start += 2;
1406
1309
  else if (!front) {
1407
1310
  const k1Offset = vOffset + delta - k2;
1408
1311
  if (k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] !== -1) {
1409
1312
  const x1 = v1[k1Offset], y1 = vOffset + x1 - k1Offset;
1410
- if (x2 = text1Length - x2, x1 >= x2)
1411
- return bisectSplit(text1, text2, x1, y1, deadline);
1313
+ if (x2 = text1Length - x2, x1 >= x2) return bisectSplit(text1, text2, x1, y1, deadline);
1412
1314
  }
1413
1315
  }
1414
1316
  }
@@ -1425,23 +1327,18 @@ function bisectSplit(text1, text2, x, y, deadline) {
1425
1327
  });
1426
1328
  return diffs.concat(diffsb);
1427
1329
  }
1428
- function findHalfMatch(text1, text2) {
1429
- if ((arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1) <= 0)
1430
- return null;
1330
+ function findHalfMatch(text1, text2, timeout = 1) {
1331
+ if (timeout <= 0) return null;
1431
1332
  const longText = text1.length > text2.length ? text1 : text2, shortText = text1.length > text2.length ? text2 : text1;
1432
- if (longText.length < 4 || shortText.length * 2 < longText.length)
1433
- return null;
1333
+ if (longText.length < 4 || shortText.length * 2 < longText.length) return null;
1434
1334
  const halfMatch1 = halfMatchI(longText, shortText, Math.ceil(longText.length / 4)), halfMatch2 = halfMatchI(longText, shortText, Math.ceil(longText.length / 2));
1435
1335
  let halfMatch;
1436
- if (halfMatch1 && halfMatch2)
1437
- halfMatch = halfMatch1[4].length > halfMatch2[4].length ? halfMatch1 : halfMatch2;
1336
+ if (halfMatch1 && halfMatch2) halfMatch = halfMatch1[4].length > halfMatch2[4].length ? halfMatch1 : halfMatch2;
1438
1337
  else {
1439
- if (!halfMatch1 && !halfMatch2)
1440
- return null;
1338
+ if (!halfMatch1 && !halfMatch2) return null;
1441
1339
  halfMatch2 ? halfMatch1 || (halfMatch = halfMatch2) : halfMatch = halfMatch1;
1442
1340
  }
1443
- if (!halfMatch)
1444
- throw new Error("Unable to find a half match.");
1341
+ if (!halfMatch) throw new Error("Unable to find a half match.");
1445
1342
  let text1A, text1B, text2A, text2B;
1446
1343
  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]);
1447
1344
  const midCommon = halfMatch[4];
@@ -1459,8 +1356,7 @@ function halfMatchI(longText, shortText, i) {
1459
1356
  function charsToLines(diffs, lineArray) {
1460
1357
  for (let x = 0; x < diffs.length; x++) {
1461
1358
  const chars = diffs[x][1], text = [];
1462
- for (let y = 0; y < chars.length; y++)
1463
- text[y] = lineArray[chars.charCodeAt(y)];
1359
+ for (let y = 0; y < chars.length; y++) text[y] = lineArray[chars.charCodeAt(y)];
1464
1360
  diffs[x][1] = text.join("");
1465
1361
  }
1466
1362
  }
@@ -1513,8 +1409,7 @@ function doLineModeDiff(textA, textB, opts) {
1513
1409
  checkLines: !1,
1514
1410
  deadline: opts.deadline
1515
1411
  });
1516
- for (let j = aa.length - 1; j >= 0; j--)
1517
- diffs.splice(pointer, 0, aa[j]);
1412
+ for (let j = aa.length - 1; j >= 0; j--) diffs.splice(pointer, 0, aa[j]);
1518
1413
  pointer += aa.length;
1519
1414
  }
1520
1415
  countInsert = 0, countDelete = 0, textDelete = "", textInsert = "";
@@ -1528,15 +1423,11 @@ function doLineModeDiff(textA, textB, opts) {
1528
1423
  }
1529
1424
  function computeDiff(text1, text2, opts) {
1530
1425
  let diffs;
1531
- if (!text1)
1532
- return [[DIFF_INSERT, text2]];
1533
- if (!text2)
1534
- return [[DIFF_DELETE, text1]];
1426
+ if (!text1) return [[DIFF_INSERT, text2]];
1427
+ if (!text2) return [[DIFF_DELETE, text1]];
1535
1428
  const longtext = text1.length > text2.length ? text1 : text2, shorttext = text1.length > text2.length ? text2 : text1, i = longtext.indexOf(shorttext);
1536
- if (i !== -1)
1537
- return diffs = [[DIFF_INSERT, longtext.substring(0, i)], [DIFF_EQUAL, shorttext], [DIFF_INSERT, longtext.substring(i + shorttext.length)]], text1.length > text2.length && (diffs[0][0] = DIFF_DELETE, diffs[2][0] = DIFF_DELETE), diffs;
1538
- if (shorttext.length === 1)
1539
- return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
1429
+ if (i !== -1) return diffs = [[DIFF_INSERT, longtext.substring(0, i)], [DIFF_EQUAL, shorttext], [DIFF_INSERT, longtext.substring(i + shorttext.length)]], text1.length > text2.length && (diffs[0][0] = DIFF_DELETE, diffs[2][0] = DIFF_DELETE), diffs;
1430
+ if (shorttext.length === 1) return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
1540
1431
  const halfMatch = findHalfMatch(text1, text2);
1541
1432
  if (halfMatch) {
1542
1433
  const 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);
@@ -1544,17 +1435,25 @@ function computeDiff(text1, text2, opts) {
1544
1435
  }
1545
1436
  return opts.checkLines && text1.length > 100 && text2.length > 100 ? doLineModeDiff(text1, text2, opts) : bisect(text1, text2, opts.deadline);
1546
1437
  }
1438
+ 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, {
1439
+ enumerable: !0,
1440
+ configurable: !0,
1441
+ writable: !0,
1442
+ value
1443
+ }) : obj[key] = value, __spreadValues$2 = (a, b) => {
1444
+ for (var prop in b || (b = {})) __hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
1445
+ if (__getOwnPropSymbols$2) for (var prop of __getOwnPropSymbols$2(b)) __propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
1446
+ return a;
1447
+ };
1547
1448
  const DIFF_DELETE = -1, DIFF_INSERT = 1, DIFF_EQUAL = 0;
1548
1449
  function diff(textA, textB, opts) {
1549
- if (textA === null || textB === null)
1550
- throw new Error("Null input. (diff)");
1450
+ if (textA === null || textB === null) throw new Error("Null input. (diff)");
1551
1451
  const diffs = doDiff(textA, textB, createInternalOpts(opts || {}));
1552
1452
  return adjustDiffForSurrogatePairs(diffs), diffs;
1553
1453
  }
1554
1454
  function doDiff(textA, textB, options) {
1555
1455
  let text1 = textA, text2 = textB;
1556
- if (text1 === text2)
1557
- return text1 ? [[DIFF_EQUAL, text1]] : [];
1456
+ if (text1 === text2) return text1 ? [[DIFF_EQUAL, text1]] : [];
1558
1457
  let commonlength = getCommonPrefix(text1, text2);
1559
1458
  const commonprefix = text1.substring(0, commonlength);
1560
1459
  text1 = text1.substring(commonlength), text2 = text2.substring(commonlength), commonlength = getCommonSuffix(text1, text2);
@@ -1568,11 +1467,10 @@ function createDeadLine(timeout) {
1568
1467
  return typeof timeout < "u" && (t = timeout <= 0 ? Number.MAX_VALUE : timeout), Date.now() + t * 1e3;
1569
1468
  }
1570
1469
  function createInternalOpts(opts) {
1571
- return {
1470
+ return __spreadValues$2({
1572
1471
  checkLines: !0,
1573
- deadline: createDeadLine(opts.timeout || 1),
1574
- ...opts
1575
- };
1472
+ deadline: createDeadLine(opts.timeout || 1)
1473
+ }, opts);
1576
1474
  }
1577
1475
  function combineChar(data, char, dir) {
1578
1476
  return dir === 1 ? data + char : char + data;
@@ -1620,9 +1518,93 @@ function adjustDiffForSurrogatePairs(diffs) {
1620
1518
  const firstChar = diffText[0], lastChar = diffText[diffText.length - 1];
1621
1519
  isHighSurrogate(lastChar) && diffType === DIFF_EQUAL && deisolateChar(diffs, i, 1), isLowSurrogate(firstChar) && diffType === DIFF_EQUAL && deisolateChar(diffs, i, -1);
1622
1520
  }
1623
- for (let i = 0; i < diffs.length; i++)
1624
- diffs[i][1].length === 0 && diffs.splice(i, 1);
1521
+ for (let i = 0; i < diffs.length; i++) diffs[i][1].length === 0 && diffs.splice(i, 1);
1522
+ }
1523
+ function cleanupSemantic(rawDiffs) {
1524
+ let diffs = rawDiffs.map((diff2) => cloneDiff(diff2)), hasChanges = !1;
1525
+ const equalities = [];
1526
+ let equalitiesLength = 0, lastEquality = null, pointer = 0, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0;
1527
+ for (; pointer < diffs.length; ) diffs[pointer][0] === DIFF_EQUAL ? (equalities[equalitiesLength++] = pointer, lengthInsertions1 = lengthInsertions2, lengthDeletions1 = lengthDeletions2, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = diffs[pointer][1]) : (diffs[pointer][0] === DIFF_INSERT ? 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, [DIFF_DELETE, lastEquality]), diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT, equalitiesLength--, equalitiesLength--, pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = null, hasChanges = !0)), pointer++;
1528
+ for (hasChanges && (diffs = cleanupMerge(diffs)), diffs = cleanupSemanticLossless(diffs), pointer = 1; pointer < diffs.length; ) {
1529
+ if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
1530
+ const deletion = diffs[pointer - 1][1], insertion = diffs[pointer][1], overlapLength1 = getCommonOverlap(deletion, insertion), overlapLength2 = getCommonOverlap(insertion, deletion);
1531
+ overlapLength1 >= overlapLength2 ? (overlapLength1 >= deletion.length / 2 || overlapLength1 >= insertion.length / 2) && (diffs.splice(pointer, 0, [DIFF_EQUAL, 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, [DIFF_EQUAL, deletion.substring(0, overlapLength2)]), diffs[pointer - 1][0] = DIFF_INSERT, diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlapLength2), diffs[pointer + 1][0] = DIFF_DELETE, diffs[pointer + 1][1] = deletion.substring(overlapLength2), pointer++), pointer++;
1532
+ }
1533
+ pointer++;
1534
+ }
1535
+ return diffs;
1536
+ }
1537
+ const nonAlphaNumericRegex = /[^a-zA-Z0-9]/, whitespaceRegex = /\s/, linebreakRegex = /[\r\n]/, blanklineEndRegex = /\n\r?\n$/, blanklineStartRegex = /^\r?\n\r?\n/;
1538
+ function cleanupSemanticLossless(rawDiffs) {
1539
+ const diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
1540
+ function diffCleanupSemanticScore(one, two) {
1541
+ if (!one || !two) return 6;
1542
+ const 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);
1543
+ return blankLine1 || blankLine2 ? 5 : lineBreak1 || lineBreak2 ? 4 : nonAlphaNumeric1 && !whitespace1 && whitespace2 ? 3 : whitespace1 || whitespace2 ? 2 : nonAlphaNumeric1 || nonAlphaNumeric2 ? 1 : 0;
1544
+ }
1545
+ let pointer = 1;
1546
+ for (; pointer < diffs.length - 1; ) {
1547
+ if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
1548
+ let equality1 = diffs[pointer - 1][1], edit = diffs[pointer][1], equality2 = diffs[pointer + 1][1];
1549
+ const commonOffset = getCommonSuffix(equality1, edit);
1550
+ if (commonOffset) {
1551
+ const commonString = edit.substring(edit.length - commonOffset);
1552
+ equality1 = equality1.substring(0, equality1.length - commonOffset), edit = commonString + edit.substring(0, edit.length - commonOffset), equality2 = commonString + equality2;
1553
+ }
1554
+ let bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2, bestScore = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
1555
+ for (; edit.charAt(0) === equality2.charAt(0); ) {
1556
+ equality1 += edit.charAt(0), edit = edit.substring(1) + equality2.charAt(0), equality2 = equality2.substring(1);
1557
+ const score = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
1558
+ score >= bestScore && (bestScore = score, bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2);
1559
+ }
1560
+ 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--));
1561
+ }
1562
+ pointer++;
1563
+ }
1564
+ return diffs;
1565
+ }
1566
+ function cleanupMerge(rawDiffs) {
1567
+ let diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
1568
+ diffs.push([DIFF_EQUAL, ""]);
1569
+ let pointer = 0, countDelete = 0, countInsert = 0, textDelete = "", textInsert = "", commonlength;
1570
+ for (; pointer < diffs.length; ) switch (diffs[pointer][0]) {
1571
+ case DIFF_INSERT:
1572
+ countInsert++, textInsert += diffs[pointer][1], pointer++;
1573
+ break;
1574
+ case DIFF_DELETE:
1575
+ countDelete++, textDelete += diffs[pointer][1], pointer++;
1576
+ break;
1577
+ case DIFF_EQUAL:
1578
+ countDelete + countInsert > 1 ? (countDelete !== 0 && countInsert !== 0 && (commonlength = getCommonPrefix(textInsert, textDelete), commonlength !== 0 && (pointer - countDelete - countInsert > 0 && diffs[pointer - countDelete - countInsert - 1][0] === DIFF_EQUAL ? diffs[pointer - countDelete - countInsert - 1][1] += textInsert.substring(0, commonlength) : (diffs.splice(0, 0, [DIFF_EQUAL, 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, [DIFF_DELETE, textDelete]), pointer++), textInsert.length && (diffs.splice(pointer, 0, [DIFF_INSERT, textInsert]), pointer++), pointer++) : pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL ? (diffs[pointer - 1][1] += diffs[pointer][1], diffs.splice(pointer, 1)) : pointer++, countInsert = 0, countDelete = 0, textDelete = "", textInsert = "";
1579
+ break;
1580
+ default:
1581
+ throw new Error("Unknown diff operation");
1582
+ }
1583
+ diffs[diffs.length - 1][1] === "" && diffs.pop();
1584
+ let hasChanges = !1;
1585
+ for (pointer = 1; pointer < diffs.length - 1; ) diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL && (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++;
1586
+ return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
1587
+ }
1588
+ function trueCount(...args) {
1589
+ return args.reduce((n, bool) => n + (bool ? 1 : 0), 0);
1590
+ }
1591
+ function cleanupEfficiency(rawDiffs, editCost = 4) {
1592
+ let diffs = rawDiffs.map((diff2) => cloneDiff(diff2)), hasChanges = !1;
1593
+ const equalities = [];
1594
+ let equalitiesLength = 0, lastEquality = null, pointer = 0, preIns = !1, preDel = !1, postIns = !1, postDel = !1;
1595
+ for (; pointer < diffs.length; ) diffs[pointer][0] === DIFF_EQUAL ? (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] === DIFF_DELETE ? 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, [DIFF_DELETE, lastEquality]), diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT, 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++;
1596
+ return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
1625
1597
  }
1598
+ 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, {
1599
+ enumerable: !0,
1600
+ configurable: !0,
1601
+ writable: !0,
1602
+ value
1603
+ }) : obj[key] = value, __spreadValues$1 = (a, b) => {
1604
+ for (var prop in b || (b = {})) __hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
1605
+ if (__getOwnPropSymbols$1) for (var prop of __getOwnPropSymbols$1(b)) __propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
1606
+ return a;
1607
+ };
1626
1608
  const DEFAULT_OPTIONS = {
1627
1609
  /**
1628
1610
  * At what point is no match declared (0.0 = perfection, 1.0 = very loose).
@@ -1636,16 +1618,11 @@ const DEFAULT_OPTIONS = {
1636
1618
  distance: 1e3
1637
1619
  };
1638
1620
  function applyDefaults(options) {
1639
- return {
1640
- ...DEFAULT_OPTIONS,
1641
- ...options
1642
- };
1621
+ return __spreadValues$1(__spreadValues$1({}, DEFAULT_OPTIONS), options);
1643
1622
  }
1644
1623
  const MAX_BITS$1 = 32;
1645
- function bitap(text, pattern, loc) {
1646
- let opts = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
1647
- if (pattern.length > MAX_BITS$1)
1648
- throw new Error("Pattern too long for this browser.");
1624
+ function bitap(text, pattern, loc, opts = {}) {
1625
+ if (pattern.length > MAX_BITS$1) throw new Error("Pattern too long for this browser.");
1649
1626
  const options = applyDefaults(opts), s = getAlphabetFromPattern(pattern);
1650
1627
  function getBitapScore(e, x) {
1651
1628
  const accuracy = e / pattern.length, proximity = Math.abs(loc - x);
@@ -1657,8 +1634,7 @@ function bitap(text, pattern, loc) {
1657
1634
  bestLoc = -1;
1658
1635
  let binMin, binMid, binMax = pattern.length + text.length, lastRd = [];
1659
1636
  for (let d = 0; d < pattern.length; d++) {
1660
- for (binMin = 0, binMid = binMax; binMin < binMid; )
1661
- getBitapScore(d, loc + binMid) <= scoreThreshold ? binMin = binMid : binMax = binMid, binMid = Math.floor((binMax - binMin) / 2 + binMin);
1637
+ for (binMin = 0, binMid = binMax; binMin < binMid; ) getBitapScore(d, loc + binMid) <= scoreThreshold ? binMin = binMid : binMax = binMid, binMid = Math.floor((binMax - binMin) / 2 + binMin);
1662
1638
  binMax = binMid;
1663
1639
  let start = Math.max(1, loc - binMid + 1);
1664
1640
  const finish = Math.min(loc + binMid, text.length) + pattern.length, rd = new Array(finish + 2);
@@ -1667,106 +1643,40 @@ function bitap(text, pattern, loc) {
1667
1643
  const charMatch = s[text.charAt(j - 1)];
1668
1644
  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) {
1669
1645
  const score = getBitapScore(d, j - 1);
1670
- if (score <= scoreThreshold)
1671
- if (scoreThreshold = score, bestLoc = j - 1, bestLoc > loc)
1672
- start = Math.max(1, 2 * loc - bestLoc);
1673
- else
1674
- break;
1646
+ if (score <= scoreThreshold) if (scoreThreshold = score, bestLoc = j - 1, bestLoc > loc) start = Math.max(1, 2 * loc - bestLoc);
1647
+ else break;
1675
1648
  }
1676
1649
  }
1677
- if (getBitapScore(d + 1, loc) > scoreThreshold)
1678
- break;
1650
+ if (getBitapScore(d + 1, loc) > scoreThreshold) break;
1679
1651
  lastRd = rd;
1680
1652
  }
1681
1653
  return bestLoc;
1682
1654
  }
1683
1655
  function getAlphabetFromPattern(pattern) {
1684
1656
  const s = {};
1685
- for (let i = 0; i < pattern.length; i++)
1686
- s[pattern.charAt(i)] = 0;
1687
- for (let i = 0; i < pattern.length; i++)
1688
- s[pattern.charAt(i)] |= 1 << pattern.length - i - 1;
1657
+ for (let i = 0; i < pattern.length; i++) s[pattern.charAt(i)] = 0;
1658
+ for (let i = 0; i < pattern.length; i++) s[pattern.charAt(i)] |= 1 << pattern.length - i - 1;
1689
1659
  return s;
1690
1660
  }
1691
1661
  function match(text, pattern, searchLocation) {
1692
- if (text === null || pattern === null || searchLocation === null)
1693
- throw new Error("Null input. (match())");
1662
+ if (text === null || pattern === null || searchLocation === null) throw new Error("Null input. (match())");
1694
1663
  const loc = Math.max(0, Math.min(searchLocation, text.length));
1695
- if (text === pattern)
1696
- return 0;
1664
+ if (text === pattern) return 0;
1697
1665
  if (text.length) {
1698
- if (text.substring(loc, loc + pattern.length) === pattern)
1699
- return loc;
1666
+ if (text.substring(loc, loc + pattern.length) === pattern) return loc;
1700
1667
  } else return -1;
1701
1668
  return bitap(text, pattern, loc);
1702
1669
  }
1703
- function createPatchObject(start1, start2) {
1704
- return {
1705
- diffs: [],
1706
- start1,
1707
- start2,
1708
- utf8Start1: start1,
1709
- utf8Start2: start2,
1710
- length1: 0,
1711
- length2: 0,
1712
- utf8Length1: 0,
1713
- utf8Length2: 0
1714
- };
1715
- }
1716
1670
  function diffText1(diffs) {
1717
1671
  const text = [];
1718
- for (let x = 0; x < diffs.length; x++)
1719
- diffs[x][0] !== DIFF_INSERT && (text[x] = diffs[x][1]);
1672
+ for (let x = 0; x < diffs.length; x++) diffs[x][0] !== DIFF_INSERT && (text[x] = diffs[x][1]);
1720
1673
  return text.join("");
1721
1674
  }
1722
1675
  function diffText2(diffs) {
1723
1676
  const text = [];
1724
- for (let x = 0; x < diffs.length; x++)
1725
- diffs[x][0] !== DIFF_DELETE && (text[x] = diffs[x][1]);
1677
+ for (let x = 0; x < diffs.length; x++) diffs[x][0] !== DIFF_DELETE && (text[x] = diffs[x][1]);
1726
1678
  return text.join("");
1727
1679
  }
1728
- function countUtf8Bytes(str) {
1729
- let bytes = 0;
1730
- for (let i = 0; i < str.length; i++) {
1731
- const codePoint = str.codePointAt(i);
1732
- if (typeof codePoint > "u")
1733
- throw new Error("Failed to get codepoint");
1734
- bytes += utf8len(codePoint);
1735
- }
1736
- return bytes;
1737
- }
1738
- function adjustIndiciesToUcs2(patches2, base) {
1739
- let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, byteOffset = 0, idx = 0;
1740
- function advanceTo(target) {
1741
- for (; byteOffset < target; ) {
1742
- const codePoint = base.codePointAt(idx);
1743
- if (typeof codePoint > "u")
1744
- return idx;
1745
- byteOffset += utf8len(codePoint), codePoint > 65535 ? idx += 2 : idx += 1;
1746
- }
1747
- if (!options.allowExceedingIndices && byteOffset !== target)
1748
- throw new Error("Failed to determine byte offset");
1749
- return idx;
1750
- }
1751
- const adjusted = [];
1752
- for (const patch of patches2)
1753
- adjusted.push({
1754
- diffs: patch.diffs.map((diff2) => cloneDiff(diff2)),
1755
- start1: advanceTo(patch.start1),
1756
- start2: advanceTo(patch.start2),
1757
- utf8Start1: patch.utf8Start1,
1758
- utf8Start2: patch.utf8Start2,
1759
- length1: patch.length1,
1760
- length2: patch.length2,
1761
- utf8Length1: patch.utf8Length1,
1762
- utf8Length2: patch.utf8Length2
1763
- });
1764
- return adjusted;
1765
- }
1766
- function utf8len(codePoint) {
1767
- return codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
1768
- }
1769
- const MAX_BITS = 32, DEFAULT_MARGIN = 4;
1770
1680
  function levenshtein(diffs) {
1771
1681
  let leven = 0, insertions = 0, deletions = 0;
1772
1682
  for (let x = 0; x < diffs.length; x++) {
@@ -1789,38 +1699,82 @@ function levenshtein(diffs) {
1789
1699
  }
1790
1700
  function xIndex(diffs, loc) {
1791
1701
  let chars1 = 0, chars2 = 0, lastChars1 = 0, lastChars2 = 0, x;
1792
- for (x = 0; x < diffs.length && (diffs[x][0] !== DIFF_INSERT && (chars1 += diffs[x][1].length), diffs[x][0] !== DIFF_DELETE && (chars2 += diffs[x][1].length), !(chars1 > loc)); x++)
1793
- lastChars1 = chars1, lastChars2 = chars2;
1702
+ for (x = 0; x < diffs.length && (diffs[x][0] !== DIFF_INSERT && (chars1 += diffs[x][1].length), diffs[x][0] !== DIFF_DELETE && (chars2 += diffs[x][1].length), !(chars1 > loc)); x++) lastChars1 = chars1, lastChars2 = chars2;
1794
1703
  return diffs.length !== x && diffs[x][0] === DIFF_DELETE ? lastChars2 : lastChars2 + (loc - lastChars1);
1795
1704
  }
1796
- function addPadding(patches2) {
1797
- const paddingLength = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : DEFAULT_MARGIN;
1705
+ function countUtf8Bytes(str) {
1706
+ let bytes = 0;
1707
+ for (let i = 0; i < str.length; i++) {
1708
+ const codePoint = str.codePointAt(i);
1709
+ if (typeof codePoint > "u") throw new Error("Failed to get codepoint");
1710
+ bytes += utf8len(codePoint);
1711
+ }
1712
+ return bytes;
1713
+ }
1714
+ function adjustIndiciesToUcs2(patches2, base, options = {}) {
1715
+ let byteOffset = 0, idx = 0;
1716
+ function advanceTo(target) {
1717
+ for (; byteOffset < target; ) {
1718
+ const codePoint = base.codePointAt(idx);
1719
+ if (typeof codePoint > "u") return idx;
1720
+ byteOffset += utf8len(codePoint), codePoint > 65535 ? idx += 2 : idx += 1;
1721
+ }
1722
+ if (!options.allowExceedingIndices && byteOffset !== target) throw new Error("Failed to determine byte offset");
1723
+ return idx;
1724
+ }
1725
+ const adjusted = [];
1726
+ for (const patch of patches2) adjusted.push({
1727
+ diffs: patch.diffs.map((diff2) => cloneDiff(diff2)),
1728
+ start1: advanceTo(patch.start1),
1729
+ start2: advanceTo(patch.start2),
1730
+ utf8Start1: patch.utf8Start1,
1731
+ utf8Start2: patch.utf8Start2,
1732
+ length1: patch.length1,
1733
+ length2: patch.length2,
1734
+ utf8Length1: patch.utf8Length1,
1735
+ utf8Length2: patch.utf8Length2
1736
+ });
1737
+ return adjusted;
1738
+ }
1739
+ function utf8len(codePoint) {
1740
+ return codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
1741
+ }
1742
+ const MAX_BITS = 32, DEFAULT_MARGIN = 4;
1743
+ function addPadding(patches2, margin = DEFAULT_MARGIN) {
1744
+ const paddingLength = margin;
1798
1745
  let nullPadding = "";
1799
- for (let x = 1; x <= paddingLength; x++)
1800
- nullPadding += String.fromCharCode(x);
1801
- for (const p of patches2)
1802
- p.start1 += paddingLength, p.start2 += paddingLength, p.utf8Start1 += paddingLength, p.utf8Start2 += paddingLength;
1746
+ for (let x = 1; x <= paddingLength; x++) nullPadding += String.fromCharCode(x);
1747
+ for (const p of patches2) p.start1 += paddingLength, p.start2 += paddingLength, p.utf8Start1 += paddingLength, p.utf8Start2 += paddingLength;
1803
1748
  let patch = patches2[0], diffs = patch.diffs;
1804
- if (diffs.length === 0 || diffs[0][0] !== DIFF_EQUAL)
1805
- diffs.unshift([DIFF_EQUAL, 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;
1749
+ if (diffs.length === 0 || diffs[0][0] !== DIFF_EQUAL) diffs.unshift([DIFF_EQUAL, 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;
1806
1750
  else if (paddingLength > diffs[0][1].length) {
1807
1751
  const firstDiffLength = diffs[0][1].length, extraLength = paddingLength - firstDiffLength;
1808
1752
  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;
1809
1753
  }
1810
- if (patch = patches2[patches2.length - 1], diffs = patch.diffs, diffs.length === 0 || diffs[diffs.length - 1][0] !== DIFF_EQUAL)
1811
- diffs.push([DIFF_EQUAL, nullPadding]), patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
1754
+ if (patch = patches2[patches2.length - 1], diffs = patch.diffs, diffs.length === 0 || diffs[diffs.length - 1][0] !== DIFF_EQUAL) diffs.push([DIFF_EQUAL, nullPadding]), patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
1812
1755
  else if (paddingLength > diffs[diffs.length - 1][1].length) {
1813
1756
  const extraLength = paddingLength - diffs[diffs.length - 1][1].length;
1814
1757
  diffs[diffs.length - 1][1] += nullPadding.substring(0, extraLength), patch.length1 += extraLength, patch.length2 += extraLength, patch.utf8Length1 += extraLength, patch.utf8Length2 += extraLength;
1815
1758
  }
1816
1759
  return nullPadding;
1817
1760
  }
1818
- function splitMax(patches2) {
1819
- let margin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : DEFAULT_MARGIN;
1761
+ function createPatchObject(start1, start2) {
1762
+ return {
1763
+ diffs: [],
1764
+ start1,
1765
+ start2,
1766
+ utf8Start1: start1,
1767
+ utf8Start2: start2,
1768
+ length1: 0,
1769
+ length2: 0,
1770
+ utf8Length1: 0,
1771
+ utf8Length2: 0
1772
+ };
1773
+ }
1774
+ function splitMax(patches2, margin = DEFAULT_MARGIN) {
1820
1775
  const patchSize = MAX_BITS;
1821
1776
  for (let x = 0; x < patches2.length; x++) {
1822
- if (patches2[x].length1 <= patchSize)
1823
- continue;
1777
+ if (patches2[x].length1 <= patchSize) continue;
1824
1778
  const bigpatch = patches2[x];
1825
1779
  patches2.splice(x--, 1);
1826
1780
  let start1 = bigpatch.start1, start2 = bigpatch.start2, preContext = "";
@@ -1846,13 +1800,10 @@ function splitMax(patches2) {
1846
1800
  }
1847
1801
  }
1848
1802
  }
1849
- function apply(patches2, originalText) {
1850
- let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1851
- if (typeof patches2 == "string")
1852
- throw new Error("Patches must be an array - pass the patch to `parsePatch()` first");
1803
+ function apply(patches2, originalText, opts = {}) {
1804
+ if (typeof patches2 == "string") throw new Error("Patches must be an array - pass the patch to `parsePatch()` first");
1853
1805
  let text = originalText;
1854
- if (patches2.length === 0)
1855
- return [text, []];
1806
+ if (patches2.length === 0) return [text, []];
1856
1807
  const parsed = adjustIndiciesToUcs2(patches2, text, {
1857
1808
  allowExceedingIndices: opts.allowExceedingIndices
1858
1809
  }), margin = opts.margin || DEFAULT_MARGIN, deleteThreshold = opts.deleteThreshold || 0.4, nullPadding = addPadding(parsed, margin);
@@ -1862,19 +1813,16 @@ function apply(patches2, originalText) {
1862
1813
  for (let x = 0; x < parsed.length; x++) {
1863
1814
  const expectedLoc = parsed[x].start2 + delta, text1 = diffText1(parsed[x].diffs);
1864
1815
  let startLoc, endLoc = -1;
1865
- if (text1.length > MAX_BITS ? (startLoc = match(text, text1.substring(0, MAX_BITS), expectedLoc), startLoc !== -1 && (endLoc = match(text, text1.substring(text1.length - MAX_BITS), expectedLoc + text1.length - MAX_BITS), (endLoc === -1 || startLoc >= endLoc) && (startLoc = -1))) : startLoc = match(text, text1, expectedLoc), startLoc === -1)
1866
- results[x] = !1, delta -= parsed[x].length2 - parsed[x].length1;
1816
+ if (text1.length > MAX_BITS ? (startLoc = match(text, text1.substring(0, MAX_BITS), expectedLoc), startLoc !== -1 && (endLoc = match(text, text1.substring(text1.length - MAX_BITS), expectedLoc + text1.length - MAX_BITS), (endLoc === -1 || startLoc >= endLoc) && (startLoc = -1))) : startLoc = match(text, text1, expectedLoc), startLoc === -1) results[x] = !1, delta -= parsed[x].length2 - parsed[x].length1;
1867
1817
  else {
1868
1818
  results[x] = !0, delta = startLoc - expectedLoc;
1869
1819
  let text2;
1870
- if (endLoc === -1 ? text2 = text.substring(startLoc, startLoc + text1.length) : text2 = text.substring(startLoc, endLoc + MAX_BITS), text1 === text2)
1871
- text = text.substring(0, startLoc) + diffText2(parsed[x].diffs) + text.substring(startLoc + text1.length);
1820
+ if (endLoc === -1 ? text2 = text.substring(startLoc, startLoc + text1.length) : text2 = text.substring(startLoc, endLoc + MAX_BITS), text1 === text2) text = text.substring(0, startLoc) + diffText2(parsed[x].diffs) + text.substring(startLoc + text1.length);
1872
1821
  else {
1873
1822
  let diffs = diff(text1, text2, {
1874
1823
  checkLines: !1
1875
1824
  });
1876
- if (text1.length > MAX_BITS && levenshtein(diffs) / text1.length > deleteThreshold)
1877
- results[x] = !1;
1825
+ if (text1.length > MAX_BITS && levenshtein(diffs) / text1.length > deleteThreshold) results[x] = !1;
1878
1826
  else {
1879
1827
  diffs = cleanupSemanticLossless(diffs);
1880
1828
  let index1 = 0, index2 = 0;
@@ -1890,20 +1838,17 @@ function apply(patches2, originalText) {
1890
1838
  }
1891
1839
  const patchHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;
1892
1840
  function parse(textline) {
1893
- if (!textline)
1894
- return [];
1841
+ if (!textline) return [];
1895
1842
  const patches2 = [], lines = textline.split(`
1896
1843
  `);
1897
1844
  let textPointer = 0;
1898
1845
  for (; textPointer < lines.length; ) {
1899
1846
  const m = lines[textPointer].match(patchHeader);
1900
- if (!m)
1901
- throw new Error("Invalid patch string: ".concat(lines[textPointer]));
1847
+ if (!m) throw new Error(`Invalid patch string: ${lines[textPointer]}`);
1902
1848
  const patch = createPatchObject(toInt(m[1]), toInt(m[3]));
1903
1849
  for (patches2.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; ) {
1904
1850
  const currentLine = lines[textPointer], sign = currentLine.charAt(0);
1905
- if (sign === "@")
1906
- break;
1851
+ if (sign === "@") break;
1907
1852
  if (sign === "") {
1908
1853
  textPointer++;
1909
1854
  continue;
@@ -1912,17 +1857,13 @@ function parse(textline) {
1912
1857
  try {
1913
1858
  line = decodeURI(currentLine.slice(1));
1914
1859
  } catch {
1915
- throw new Error("Illegal escape in parse: ".concat(currentLine));
1860
+ throw new Error(`Illegal escape in parse: ${currentLine}`);
1916
1861
  }
1917
1862
  const utf8Diff = countUtf8Bytes(line) - line.length;
1918
- if (sign === "-")
1919
- patch.diffs.push([DIFF_DELETE, line]), patch.length1 -= utf8Diff;
1920
- else if (sign === "+")
1921
- patch.diffs.push([DIFF_INSERT, line]), patch.length2 -= utf8Diff;
1922
- else if (sign === " ")
1923
- patch.diffs.push([DIFF_EQUAL, line]), patch.length1 -= utf8Diff, patch.length2 -= utf8Diff;
1924
- else
1925
- throw new Error('Invalid patch mode "'.concat(sign, '" in: ').concat(line));
1863
+ if (sign === "-") patch.diffs.push([DIFF_DELETE, line]), patch.length1 -= utf8Diff;
1864
+ else if (sign === "+") patch.diffs.push([DIFF_INSERT, line]), patch.length2 -= utf8Diff;
1865
+ else if (sign === " ") patch.diffs.push([DIFF_EQUAL, line]), patch.length1 -= utf8Diff, patch.length2 -= utf8Diff;
1866
+ else throw new Error(`Invalid patch mode "${sign}" in: ${line}`);
1926
1867
  textPointer++;
1927
1868
  }
1928
1869
  }
@@ -2665,7 +2606,12 @@ function Synchronizer(props) {
2665
2606
  type: "has pending patches"
2666
2607
  }), event.type === "mutation" && (syncActorRef.send({
2667
2608
  type: "mutation"
2668
- }), editorActor.send(event));
2609
+ }), editorActor.send({
2610
+ type: "mutation",
2611
+ patches: event.patches,
2612
+ snapshot: event.snapshot,
2613
+ value: event.snapshot
2614
+ }));
2669
2615
  });
2670
2616
  return () => {
2671
2617
  subscription.unsubscribe();
@@ -5809,11 +5755,12 @@ const editorMachine = xstate.setup({
5809
5755
  if (eventBehaviors.length === 0) {
5810
5756
  if (!defaultAction)
5811
5757
  return;
5812
- enqueue.raise({
5813
- type: "behavior action intends",
5814
- editor: event.editor,
5815
- actionIntends: [defaultAction]
5816
- });
5758
+ slate.Editor.withoutNormalizing(event.editor, () => {
5759
+ performAction({
5760
+ context,
5761
+ action: defaultAction
5762
+ });
5763
+ }), event.editor.onChange();
5817
5764
  return;
5818
5765
  }
5819
5766
  const value = fromSlateValue(event.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(event.editor)), selection = toPortableTextRange(value, event.editor.selection, context.schema), editorContext = {
@@ -5839,10 +5786,20 @@ const editorMachine = xstate.setup({
5839
5786
  event: event.behaviorEvent
5840
5787
  }, shouldRun));
5841
5788
  for (const actionIntends of actionIntendSets)
5842
- behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), enqueue.raise({
5843
- type: "behavior action intends",
5844
- editor: event.editor,
5845
- actionIntends
5789
+ behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), slate.Editor.withoutNormalizing(event.editor, () => {
5790
+ for (const actionIntend of actionIntends) {
5791
+ const action = {
5792
+ ...actionIntend,
5793
+ editor: event.editor
5794
+ };
5795
+ performAction({
5796
+ context,
5797
+ action
5798
+ });
5799
+ }
5800
+ }), event.editor.onChange(), actionIntends.some((actionIntend) => actionIntend.type === "reselect") && enqueue.raise({
5801
+ type: "selection",
5802
+ selection: toPortableTextRange(event.editor.children, event.editor.selection, context.schema)
5846
5803
  });
5847
5804
  if (behaviorOverwritten) {
5848
5805
  event.nativeEvent?.preventDefault();
@@ -5852,11 +5809,12 @@ const editorMachine = xstate.setup({
5852
5809
  if (!behaviorOverwritten) {
5853
5810
  if (!defaultAction)
5854
5811
  return;
5855
- enqueue.raise({
5856
- type: "behavior action intends",
5857
- editor: event.editor,
5858
- actionIntends: [defaultAction]
5859
- });
5812
+ slate.Editor.withoutNormalizing(event.editor, () => {
5813
+ performAction({
5814
+ context,
5815
+ action: defaultAction
5816
+ });
5817
+ }), event.editor.onChange();
5860
5818
  }
5861
5819
  })
5862
5820
  }
@@ -5948,34 +5906,6 @@ const editorMachine = xstate.setup({
5948
5906
  event
5949
5907
  }) => event.maxBlocks
5950
5908
  })
5951
- },
5952
- "behavior action intends": {
5953
- actions: [({
5954
- context,
5955
- event
5956
- }) => {
5957
- slate.Editor.withoutNormalizing(event.editor, () => {
5958
- for (const actionIntend of event.actionIntends) {
5959
- const action = {
5960
- ...actionIntend,
5961
- editor: event.editor
5962
- };
5963
- performAction({
5964
- context,
5965
- action
5966
- });
5967
- }
5968
- }), event.editor.onChange();
5969
- }, xstate.enqueueActions(({
5970
- context,
5971
- event,
5972
- enqueue
5973
- }) => {
5974
- event.actionIntends.some((actionIntend) => actionIntend.type === "reselect") && enqueue.raise({
5975
- type: "selection",
5976
- selection: toPortableTextRange(event.editor.children, event.editor.selection, context.schema)
5977
- });
5978
- })]
5979
5909
  }
5980
5910
  },
5981
5911
  type: "parallel",
@@ -6136,7 +6066,48 @@ const editorMachine = xstate.setup({
6136
6066
  }
6137
6067
  }
6138
6068
  }
6139
- }), defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__ */ (() => {
6069
+ });
6070
+ function getValue({
6071
+ editorActorSnapshot,
6072
+ slateEditorInstance
6073
+ }) {
6074
+ return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
6075
+ }
6076
+ function defaultCompare(a, b) {
6077
+ return a === b;
6078
+ }
6079
+ function useEditorSelector(editor, selector, t0) {
6080
+ const $ = reactCompilerRuntime.c(3), compare = t0 === void 0 ? defaultCompare : t0;
6081
+ let t1;
6082
+ return $[0] !== editor._internal.slateEditor.instance || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
6083
+ const snapshot = getEditorSnapshot({
6084
+ editorActorSnapshot,
6085
+ slateEditorInstance: editor._internal.slateEditor.instance
6086
+ });
6087
+ return selector(snapshot);
6088
+ }, $[0] = editor._internal.slateEditor.instance, $[1] = selector, $[2] = t1) : t1 = $[2], react.useSelector(editor._internal.editorActor, t1, compare);
6089
+ }
6090
+ function getEditorSnapshot({
6091
+ editorActorSnapshot,
6092
+ slateEditorInstance
6093
+ }) {
6094
+ return {
6095
+ context: {
6096
+ activeDecorators: getActiveDecorators({
6097
+ schema: editorActorSnapshot.context.schema,
6098
+ slateEditorInstance
6099
+ }),
6100
+ keyGenerator: editorActorSnapshot.context.keyGenerator,
6101
+ schema: editorActorSnapshot.context.schema,
6102
+ selection: editorActorSnapshot.context.selection,
6103
+ value: getValue({
6104
+ editorActorSnapshot,
6105
+ slateEditorInstance
6106
+ })
6107
+ }
6108
+ };
6109
+ }
6110
+ const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__ */ (() => {
6140
6111
  let table;
6141
6112
  return () => {
6142
6113
  if (table)
@@ -6188,6 +6159,10 @@ function createEditorFromActor(editorActor) {
6188
6159
  editorActor
6189
6160
  }), editable = createEditableAPI(slateEditor.instance, editorActor);
6190
6161
  return {
6162
+ getSnapshot: () => getEditorSnapshot({
6163
+ editorActorSnapshot: editorActor.getSnapshot(),
6164
+ slateEditorInstance: slateEditor.instance
6165
+ }),
6191
6166
  send: (event) => {
6192
6167
  editorActor.send(event);
6193
6168
  },
@@ -7184,31 +7159,6 @@ function EditorEventListener(props) {
7184
7159
  };
7185
7160
  }, t1 = [editor, on], $[0] = editor, $[1] = on, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), React.useEffect(t0, t1), null;
7186
7161
  }
7187
- function getValue(editor) {
7188
- return fromSlateValue(editor._internal.slateEditor.instance.children, editor._internal.editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor._internal.slateEditor.instance));
7189
- }
7190
- function defaultCompare(a, b) {
7191
- return a === b;
7192
- }
7193
- function useEditorSelector(editor, selector, t0) {
7194
- const $ = reactCompilerRuntime.c(3), compare = t0 === void 0 ? defaultCompare : t0;
7195
- let t1;
7196
- return $[0] !== editor || $[1] !== selector ? (t1 = (snapshot) => {
7197
- const context = {
7198
- activeDecorators: getActiveDecorators({
7199
- schema: snapshot.context.schema,
7200
- slateEditorInstance: editor._internal.slateEditor.instance
7201
- }),
7202
- keyGenerator: snapshot.context.keyGenerator,
7203
- schema: snapshot.context.schema,
7204
- selection: snapshot.context.selection,
7205
- value: getValue(editor)
7206
- };
7207
- return selector({
7208
- context
7209
- });
7210
- }, $[0] = editor, $[1] = selector, $[2] = t1) : t1 = $[2], react.useSelector(editor._internal.editorActor, t1, compare);
7211
- }
7212
7162
  exports.EditorEventListener = EditorEventListener;
7213
7163
  exports.EditorProvider = EditorProvider;
7214
7164
  exports.PortableTextEditable = PortableTextEditable;