@slate-yjs/core 0.2.8 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -913,6 +913,9 @@ var SlateYjsCore = (() => {
913
913
  insertBreak(editor) {
914
914
  editor.insertBreak();
915
915
  },
916
+ insertSoftBreak(editor) {
917
+ editor.insertSoftBreak();
918
+ },
916
919
  insertFragment(editor, fragment) {
917
920
  editor.insertFragment(fragment);
918
921
  },
@@ -926,13 +929,14 @@ var SlateYjsCore = (() => {
926
929
  return Element.isElement(value) && !editor.isInline(value);
927
930
  },
928
931
  isEditor(value) {
929
- if (!isPlainObject(value))
930
- return false;
931
932
  var cachedIsEditor = IS_EDITOR_CACHE.get(value);
932
933
  if (cachedIsEditor !== void 0) {
933
934
  return cachedIsEditor;
934
935
  }
935
- var isEditor = typeof value.addMark === "function" && typeof value.apply === "function" && typeof value.deleteBackward === "function" && typeof value.deleteForward === "function" && typeof value.deleteFragment === "function" && typeof value.insertBreak === "function" && typeof value.insertFragment === "function" && typeof value.insertNode === "function" && typeof value.insertText === "function" && typeof value.isInline === "function" && typeof value.isVoid === "function" && typeof value.normalizeNode === "function" && typeof value.onChange === "function" && typeof value.removeMark === "function" && (value.marks === null || isPlainObject(value.marks)) && (value.selection === null || Range.isRange(value.selection)) && Node.isNodeList(value.children) && Operation.isOperationList(value.operations);
936
+ if (!isPlainObject(value)) {
937
+ return false;
938
+ }
939
+ var isEditor = typeof value.addMark === "function" && typeof value.apply === "function" && typeof value.deleteBackward === "function" && typeof value.deleteForward === "function" && typeof value.deleteFragment === "function" && typeof value.insertBreak === "function" && typeof value.insertSoftBreak === "function" && typeof value.insertFragment === "function" && typeof value.insertNode === "function" && typeof value.insertText === "function" && typeof value.isInline === "function" && typeof value.isVoid === "function" && typeof value.normalizeNode === "function" && typeof value.onChange === "function" && typeof value.removeMark === "function" && typeof value.getDirtyPaths === "function" && (value.marks === null || isPlainObject(value.marks)) && (value.selection === null || Range.isRange(value.selection)) && Node.isNodeList(value.children) && Operation.isOperationList(value.operations);
936
940
  IS_EDITOR_CACHE.set(value, isEditor);
937
941
  return isEditor;
938
942
  },
@@ -1654,7 +1658,7 @@ var SlateYjsCore = (() => {
1654
1658
  ancestor(root, path) {
1655
1659
  var node = Node.get(root, path);
1656
1660
  if (Text.isText(node)) {
1657
- throw new Error("Cannot get the ancestor node at path [".concat(path, "] because it refers to a text node instead: ").concat(node));
1661
+ throw new Error("Cannot get the ancestor node at path [".concat(path, "] because it refers to a text node instead: ").concat(Scrubber.stringify(node)));
1658
1662
  }
1659
1663
  return node;
1660
1664
  },
@@ -1668,11 +1672,11 @@ var SlateYjsCore = (() => {
1668
1672
  },
1669
1673
  child(root, index) {
1670
1674
  if (Text.isText(root)) {
1671
- throw new Error("Cannot get the child of a text node: ".concat(JSON.stringify(root)));
1675
+ throw new Error("Cannot get the child of a text node: ".concat(Scrubber.stringify(root)));
1672
1676
  }
1673
1677
  var c2 = root.children[index];
1674
1678
  if (c2 == null) {
1675
- throw new Error("Cannot get child at index `".concat(index, "` in node: ").concat(JSON.stringify(root)));
1679
+ throw new Error("Cannot get child at index `".concat(index, "` in node: ").concat(Scrubber.stringify(root)));
1676
1680
  }
1677
1681
  return c2;
1678
1682
  },
@@ -1701,7 +1705,7 @@ var SlateYjsCore = (() => {
1701
1705
  descendant(root, path) {
1702
1706
  var node = Node.get(root, path);
1703
1707
  if (Editor.isEditor(node)) {
1704
- throw new Error("Cannot get the descendant node at path [".concat(path, "] because it refers to the root editor node instead: ").concat(node));
1708
+ throw new Error("Cannot get the descendant node at path [".concat(path, "] because it refers to the root editor node instead: ").concat(Scrubber.stringify(node)));
1705
1709
  }
1706
1710
  return node;
1707
1711
  },
@@ -1745,7 +1749,7 @@ var SlateYjsCore = (() => {
1745
1749
  },
1746
1750
  fragment(root, range) {
1747
1751
  if (Text.isText(root)) {
1748
- throw new Error("Cannot get a fragment starting from a root text node: ".concat(JSON.stringify(root)));
1752
+ throw new Error("Cannot get a fragment starting from a root text node: ".concat(Scrubber.stringify(root)));
1749
1753
  }
1750
1754
  var newRoot = fn({
1751
1755
  children: root.children
@@ -1784,7 +1788,7 @@ var SlateYjsCore = (() => {
1784
1788
  for (var i2 = 0; i2 < path.length; i2++) {
1785
1789
  var p2 = path[i2];
1786
1790
  if (Text.isText(node) || !node.children[p2]) {
1787
- throw new Error("Cannot find a descendant at path [".concat(path, "] in node: ").concat(JSON.stringify(root)));
1791
+ throw new Error("Cannot find a descendant at path [".concat(path, "] in node: ").concat(Scrubber.stringify(root)));
1788
1792
  }
1789
1793
  node = node.children[p2];
1790
1794
  }
@@ -1833,7 +1837,7 @@ var SlateYjsCore = (() => {
1833
1837
  leaf(root, path) {
1834
1838
  var node = Node.get(root, path);
1835
1839
  if (!Text.isText(node)) {
1836
- throw new Error("Cannot get the leaf node at path [".concat(path, "] because it refers to a non-leaf node: ").concat(node));
1840
+ throw new Error("Cannot get the leaf node at path [".concat(path, "] because it refers to a non-leaf node: ").concat(Scrubber.stringify(node)));
1837
1841
  }
1838
1842
  return node;
1839
1843
  },
@@ -2621,6 +2625,15 @@ var SlateYjsCore = (() => {
2621
2625
  });
2622
2626
  }
2623
2627
  };
2628
+ var _scrubber = void 0;
2629
+ var Scrubber = {
2630
+ setScrubber(scrubber) {
2631
+ _scrubber = scrubber;
2632
+ },
2633
+ stringify(value) {
2634
+ return JSON.stringify(value, _scrubber);
2635
+ }
2636
+ };
2624
2637
  var isDeepEqual = (node, another) => {
2625
2638
  for (var key in node) {
2626
2639
  var a2 = node[key];
@@ -2716,27 +2729,29 @@ var SlateYjsCore = (() => {
2716
2729
  var rest = _objectWithoutProperties(dec, _excluded2$1);
2717
2730
  var [start, end] = Range.edges(dec);
2718
2731
  var next = [];
2719
- var o2 = 0;
2732
+ var leafEnd = 0;
2733
+ var decorationStart = start.offset;
2734
+ var decorationEnd = end.offset;
2720
2735
  for (var leaf of leaves) {
2721
2736
  var {
2722
2737
  length: length3
2723
2738
  } = leaf.text;
2724
- var offset = o2;
2725
- o2 += length3;
2726
- if (start.offset <= offset && end.offset >= o2) {
2739
+ var leafStart = leafEnd;
2740
+ leafEnd += length3;
2741
+ if (decorationStart <= leafStart && leafEnd <= decorationEnd) {
2727
2742
  Object.assign(leaf, rest);
2728
2743
  next.push(leaf);
2729
2744
  continue;
2730
2745
  }
2731
- if (start.offset !== end.offset && (start.offset === o2 || end.offset === offset) || start.offset > o2 || end.offset < offset || end.offset === offset && offset !== 0) {
2746
+ if (decorationStart !== decorationEnd && (decorationStart === leafEnd || decorationEnd === leafStart) || decorationStart > leafEnd || decorationEnd < leafStart || decorationEnd === leafStart && leafStart !== 0) {
2732
2747
  next.push(leaf);
2733
2748
  continue;
2734
2749
  }
2735
2750
  var middle = leaf;
2736
2751
  var before = void 0;
2737
2752
  var after = void 0;
2738
- if (end.offset < o2) {
2739
- var off = end.offset - offset;
2753
+ if (decorationEnd < leafEnd) {
2754
+ var off = decorationEnd - leafStart;
2740
2755
  after = _objectSpread$4(_objectSpread$4({}, middle), {}, {
2741
2756
  text: middle.text.slice(off)
2742
2757
  });
@@ -2744,8 +2759,8 @@ var SlateYjsCore = (() => {
2744
2759
  text: middle.text.slice(0, off)
2745
2760
  });
2746
2761
  }
2747
- if (start.offset > offset) {
2748
- var _off = start.offset - offset;
2762
+ if (decorationStart > leafStart) {
2763
+ var _off = decorationStart - leafStart;
2749
2764
  before = _objectSpread$4(_objectSpread$4({}, middle), {}, {
2750
2765
  text: middle.text.slice(0, _off)
2751
2766
  });
@@ -2850,7 +2865,7 @@ var SlateYjsCore = (() => {
2850
2865
  } else if (!Text.isText(_node2) && !Text.isText(prev)) {
2851
2866
  prev.children.push(..._node2.children);
2852
2867
  } else {
2853
- throw new Error('Cannot apply a "merge_node" operation at path ['.concat(_path2, "] to nodes of different interfaces: ").concat(_node2, " ").concat(prev));
2868
+ throw new Error('Cannot apply a "merge_node" operation at path ['.concat(_path2, "] to nodes of different interfaces: ").concat(Scrubber.stringify(_node2), " ").concat(Scrubber.stringify(prev)));
2854
2869
  }
2855
2870
  _parent.children.splice(_index, 1);
2856
2871
  if (selection) {
@@ -2984,7 +2999,7 @@ var SlateYjsCore = (() => {
2984
2999
  } else {
2985
3000
  if (selection == null) {
2986
3001
  if (!Range.isRange(_newProperties)) {
2987
- throw new Error('Cannot apply an incomplete "set_selection" operation properties '.concat(JSON.stringify(_newProperties), " when there is no current selection."));
3002
+ throw new Error('Cannot apply an incomplete "set_selection" operation properties '.concat(Scrubber.stringify(_newProperties), " when there is no current selection."));
2988
3003
  }
2989
3004
  selection = _objectSpread$3({}, _newProperties);
2990
3005
  }
@@ -3361,7 +3376,7 @@ var SlateYjsCore = (() => {
3361
3376
  position = prevNode.children.length;
3362
3377
  properties = rest;
3363
3378
  } else {
3364
- throw new Error("Cannot merge the node at path [".concat(path, "] with the previous sibling because it is not the same kind: ").concat(JSON.stringify(node), " ").concat(JSON.stringify(prevNode)));
3379
+ throw new Error("Cannot merge the node at path [".concat(path, "] with the previous sibling because it is not the same kind: ").concat(Scrubber.stringify(node), " ").concat(Scrubber.stringify(prevNode)));
3365
3380
  }
3366
3381
  if (!isPreviousSibling) {
3367
3382
  Transforms.moveNodes(editor, {
@@ -3489,7 +3504,8 @@ var SlateYjsCore = (() => {
3489
3504
  var {
3490
3505
  match,
3491
3506
  at = editor.selection,
3492
- compare
3507
+ compare,
3508
+ merge
3493
3509
  } = options;
3494
3510
  var {
3495
3511
  hanging = false,
@@ -3559,8 +3575,13 @@ var SlateYjsCore = (() => {
3559
3575
  hasChanges = true;
3560
3576
  if (node.hasOwnProperty(k2))
3561
3577
  properties[k2] = node[k2];
3562
- if (props[k2] != null)
3563
- newProperties[k2] = props[k2];
3578
+ if (merge) {
3579
+ if (props[k2] != null)
3580
+ newProperties[k2] = merge(node[k2], props[k2]);
3581
+ } else {
3582
+ if (props[k2] != null)
3583
+ newProperties[k2] = props[k2];
3584
+ }
3564
3585
  }
3565
3586
  }
3566
3587
  if (hasChanges) {
@@ -3608,76 +3629,81 @@ var SlateYjsCore = (() => {
3608
3629
  var beforeRef = Editor.pointRef(editor, at, {
3609
3630
  affinity: "backward"
3610
3631
  });
3611
- var [highest] = Editor.nodes(editor, {
3612
- at,
3613
- match,
3614
- mode,
3615
- voids
3616
- });
3617
- if (!highest) {
3618
- return;
3619
- }
3620
- var voidMatch = Editor.void(editor, {
3621
- at,
3622
- mode: "highest"
3623
- });
3624
- var nudge = 0;
3625
- if (!voids && voidMatch) {
3626
- var [voidNode, voidPath] = voidMatch;
3627
- if (Element.isElement(voidNode) && editor.isInline(voidNode)) {
3628
- var after = Editor.after(editor, voidPath);
3629
- if (!after) {
3630
- var text2 = {
3631
- text: ""
3632
- };
3633
- var afterPath = Path.next(voidPath);
3634
- Transforms.insertNodes(editor, text2, {
3635
- at: afterPath,
3636
- voids
3637
- });
3638
- after = Editor.point(editor, afterPath);
3632
+ var afterRef;
3633
+ try {
3634
+ var [highest] = Editor.nodes(editor, {
3635
+ at,
3636
+ match,
3637
+ mode,
3638
+ voids
3639
+ });
3640
+ if (!highest) {
3641
+ return;
3642
+ }
3643
+ var voidMatch = Editor.void(editor, {
3644
+ at,
3645
+ mode: "highest"
3646
+ });
3647
+ var nudge = 0;
3648
+ if (!voids && voidMatch) {
3649
+ var [voidNode, voidPath] = voidMatch;
3650
+ if (Element.isElement(voidNode) && editor.isInline(voidNode)) {
3651
+ var after = Editor.after(editor, voidPath);
3652
+ if (!after) {
3653
+ var text2 = {
3654
+ text: ""
3655
+ };
3656
+ var afterPath = Path.next(voidPath);
3657
+ Transforms.insertNodes(editor, text2, {
3658
+ at: afterPath,
3659
+ voids
3660
+ });
3661
+ after = Editor.point(editor, afterPath);
3662
+ }
3663
+ at = after;
3664
+ always = true;
3639
3665
  }
3640
- at = after;
3666
+ var siblingHeight = at.path.length - voidPath.length;
3667
+ height = siblingHeight + 1;
3641
3668
  always = true;
3642
3669
  }
3643
- var siblingHeight = at.path.length - voidPath.length;
3644
- height = siblingHeight + 1;
3645
- always = true;
3646
- }
3647
- var afterRef = Editor.pointRef(editor, at);
3648
- var depth = at.path.length - height;
3649
- var [, highestPath] = highest;
3650
- var lowestPath = at.path.slice(0, depth);
3651
- var position = height === 0 ? at.offset : at.path[depth] + nudge;
3652
- for (var [node, _path2] of Editor.levels(editor, {
3653
- at: lowestPath,
3654
- reverse: true,
3655
- voids
3656
- })) {
3657
- var split = false;
3658
- if (_path2.length < highestPath.length || _path2.length === 0 || !voids && Editor.isVoid(editor, node)) {
3659
- break;
3670
+ afterRef = Editor.pointRef(editor, at);
3671
+ var depth = at.path.length - height;
3672
+ var [, highestPath] = highest;
3673
+ var lowestPath = at.path.slice(0, depth);
3674
+ var position = height === 0 ? at.offset : at.path[depth] + nudge;
3675
+ for (var [node, _path2] of Editor.levels(editor, {
3676
+ at: lowestPath,
3677
+ reverse: true,
3678
+ voids
3679
+ })) {
3680
+ var split = false;
3681
+ if (_path2.length < highestPath.length || _path2.length === 0 || !voids && Editor.isVoid(editor, node)) {
3682
+ break;
3683
+ }
3684
+ var _point = beforeRef.current;
3685
+ var isEnd = Editor.isEnd(editor, _point, _path2);
3686
+ if (always || !beforeRef || !Editor.isEdge(editor, _point, _path2)) {
3687
+ split = true;
3688
+ var properties = Node.extractProps(node);
3689
+ editor.apply({
3690
+ type: "split_node",
3691
+ path: _path2,
3692
+ position,
3693
+ properties
3694
+ });
3695
+ }
3696
+ position = _path2[_path2.length - 1] + (split || isEnd ? 1 : 0);
3660
3697
  }
3661
- var _point = beforeRef.current;
3662
- var isEnd = Editor.isEnd(editor, _point, _path2);
3663
- if (always || !beforeRef || !Editor.isEdge(editor, _point, _path2)) {
3664
- split = true;
3665
- var properties = Node.extractProps(node);
3666
- editor.apply({
3667
- type: "split_node",
3668
- path: _path2,
3669
- position,
3670
- properties
3671
- });
3698
+ if (options.at == null) {
3699
+ var _point2 = afterRef.current || Editor.end(editor, []);
3700
+ Transforms.select(editor, _point2);
3672
3701
  }
3673
- position = _path2[_path2.length - 1] + (split || isEnd ? 1 : 0);
3674
- }
3675
- if (options.at == null) {
3676
- var _point2 = afterRef.current || Editor.end(editor, []);
3677
- Transforms.select(editor, _point2);
3702
+ } finally {
3703
+ var _afterRef;
3704
+ beforeRef.unref();
3705
+ (_afterRef = afterRef) === null || _afterRef === void 0 ? void 0 : _afterRef.unref();
3678
3706
  }
3679
- beforeRef.unref();
3680
- afterRef.unref();
3681
3707
  });
3682
3708
  },
3683
3709
  unsetNodes(editor, props) {
@@ -3993,7 +4019,7 @@ var SlateYjsCore = (() => {
3993
4019
  return;
3994
4020
  }
3995
4021
  if (!Range.isRange(target)) {
3996
- throw new Error("When setting the selection and the current selection is `null` you must provide at least an `anchor` and `focus`, but you passed: ".concat(JSON.stringify(target)));
4022
+ throw new Error("When setting the selection and the current selection is `null` you must provide at least an `anchor` and `focus`, but you passed: ".concat(Scrubber.stringify(target)));
3997
4023
  }
3998
4024
  editor.apply({
3999
4025
  type: "set_selection",
@@ -4068,7 +4094,9 @@ var SlateYjsCore = (() => {
4068
4094
  if (!at) {
4069
4095
  return;
4070
4096
  }
4097
+ var isCollapsed = false;
4071
4098
  if (Range.isRange(at) && Range.isCollapsed(at)) {
4099
+ isCollapsed = true;
4072
4100
  at = at.anchor;
4073
4101
  }
4074
4102
  if (Point.isPoint(at)) {
@@ -4165,6 +4193,7 @@ var SlateYjsCore = (() => {
4165
4193
  });
4166
4194
  var startRef = Editor.pointRef(editor, start);
4167
4195
  var endRef = Editor.pointRef(editor, end);
4196
+ var removedText = "";
4168
4197
  if (!isSingleText && !startVoid) {
4169
4198
  var _point = startRef.current;
4170
4199
  var [_node] = Editor.leaf(editor, _point);
@@ -4175,13 +4204,15 @@ var SlateYjsCore = (() => {
4175
4204
  offset
4176
4205
  } = start;
4177
4206
  var text2 = _node.text.slice(offset);
4178
- if (text2.length > 0)
4207
+ if (text2.length > 0) {
4179
4208
  editor.apply({
4180
4209
  type: "remove_text",
4181
4210
  path: _path,
4182
4211
  offset,
4183
4212
  text: text2
4184
4213
  });
4214
+ removedText = text2;
4215
+ }
4185
4216
  }
4186
4217
  for (var pathRef of pathRefs) {
4187
4218
  var _path2 = pathRef.unref();
@@ -4198,13 +4229,15 @@ var SlateYjsCore = (() => {
4198
4229
  } = _point2;
4199
4230
  var _offset = isSingleText ? start.offset : 0;
4200
4231
  var _text = _node2.text.slice(_offset, end.offset);
4201
- if (_text.length > 0)
4232
+ if (_text.length > 0) {
4202
4233
  editor.apply({
4203
4234
  type: "remove_text",
4204
4235
  path: _path3,
4205
4236
  offset: _offset,
4206
4237
  text: _text
4207
4238
  });
4239
+ removedText = _text;
4240
+ }
4208
4241
  }
4209
4242
  if (!isSingleText && isAcrossBlocks && endRef.current && startRef.current) {
4210
4243
  Transforms.mergeNodes(editor, {
@@ -4213,7 +4246,12 @@ var SlateYjsCore = (() => {
4213
4246
  voids
4214
4247
  });
4215
4248
  }
4216
- var point = reverse ? startRef.unref() || endRef.unref() : endRef.unref() || startRef.unref();
4249
+ if (isCollapsed && reverse && unit === "character" && removedText.length > 1 && removedText.match(/[\u0E00-\u0E7F]+/)) {
4250
+ Transforms.insertText(editor, removedText.slice(0, removedText.length - distance));
4251
+ }
4252
+ var startUnref = startRef.unref();
4253
+ var endUnref = endRef.unref();
4254
+ var point = reverse ? startUnref || endUnref : endUnref || startUnref;
4217
4255
  if (options.at == null && point) {
4218
4256
  Transforms.select(editor, point);
4219
4257
  }
@@ -4346,13 +4384,13 @@ var SlateYjsCore = (() => {
4346
4384
  var [, inlinePath] = inlineMatch;
4347
4385
  var isInlineStart = Editor.isStart(editor, at, inlinePath);
4348
4386
  var isInlineEnd = Editor.isEnd(editor, at, inlinePath);
4349
- var middleRef = Editor.pathRef(editor, isBlockEnd ? Path.next(blockPath) : blockPath);
4387
+ var middleRef = Editor.pathRef(editor, isBlockEnd && !ends.length ? Path.next(blockPath) : blockPath);
4350
4388
  var endRef = Editor.pathRef(editor, isInlineEnd ? Path.next(inlinePath) : inlinePath);
4351
- var blockPathRef = Editor.pathRef(editor, blockPath);
4352
4389
  Transforms.splitNodes(editor, {
4353
4390
  at,
4354
4391
  match: (n2) => hasBlocks ? Editor.isBlock(editor, n2) : Text.isText(n2) || Editor.isInline(editor, n2),
4355
4392
  mode: hasBlocks ? "lowest" : "highest",
4393
+ always: hasBlocks && (!isBlockStart || starts.length > 0) && (!isBlockEnd || ends.length > 0),
4356
4394
  voids
4357
4395
  });
4358
4396
  var startRef = Editor.pathRef(editor, !isInlineStart || isInlineStart && isInlineEnd ? Path.next(inlinePath) : inlinePath);
@@ -4362,9 +4400,9 @@ var SlateYjsCore = (() => {
4362
4400
  mode: "highest",
4363
4401
  voids
4364
4402
  });
4365
- if (isBlockEmpty && middles.length) {
4403
+ if (isBlockEmpty && !starts.length && middles.length && !ends.length) {
4366
4404
  Transforms.delete(editor, {
4367
- at: blockPathRef.unref(),
4405
+ at: blockPath,
4368
4406
  voids
4369
4407
  });
4370
4408
  }
@@ -4382,15 +4420,17 @@ var SlateYjsCore = (() => {
4382
4420
  });
4383
4421
  if (!options.at) {
4384
4422
  var path;
4385
- if (ends.length > 0) {
4423
+ if (ends.length > 0 && endRef.current) {
4386
4424
  path = Path.previous(endRef.current);
4387
- } else if (middles.length > 0) {
4425
+ } else if (middles.length > 0 && middleRef.current) {
4388
4426
  path = Path.previous(middleRef.current);
4389
- } else {
4427
+ } else if (startRef.current) {
4390
4428
  path = Path.previous(startRef.current);
4391
4429
  }
4392
- var _end2 = Editor.end(editor, path);
4393
- Transforms.select(editor, _end2);
4430
+ if (path) {
4431
+ var _end2 = Editor.end(editor, path);
4432
+ Transforms.select(editor, _end2);
4433
+ }
4394
4434
  }
4395
4435
  startRef.unref();
4396
4436
  middleRef.unref();
@@ -4422,12 +4462,16 @@ var SlateYjsCore = (() => {
4422
4462
  })) {
4423
4463
  return;
4424
4464
  }
4425
- var pointRef = Editor.pointRef(editor, end);
4465
+ var start = Range.start(at);
4466
+ var startRef = Editor.pointRef(editor, start);
4467
+ var endRef = Editor.pointRef(editor, end);
4426
4468
  Transforms.delete(editor, {
4427
4469
  at,
4428
4470
  voids
4429
4471
  });
4430
- at = pointRef.unref();
4472
+ var startPoint = startRef.unref();
4473
+ var endPoint = endRef.unref();
4474
+ at = startPoint || endPoint;
4431
4475
  Transforms.setSelection(editor, {
4432
4476
  anchor: at,
4433
4477
  focus: at
@@ -5104,79 +5148,6 @@ var SlateYjsCore = (() => {
5104
5148
  }
5105
5149
  }
5106
5150
  };
5107
- var equalityStrict = (a2, b2) => a2 === b2;
5108
- var equalityDeep = (a2, b2) => {
5109
- if (a2 == null || b2 == null) {
5110
- return equalityStrict(a2, b2);
5111
- }
5112
- if (a2.constructor !== b2.constructor) {
5113
- return false;
5114
- }
5115
- if (a2 === b2) {
5116
- return true;
5117
- }
5118
- switch (a2.constructor) {
5119
- case ArrayBuffer:
5120
- a2 = new Uint8Array(a2);
5121
- b2 = new Uint8Array(b2);
5122
- case Uint8Array: {
5123
- if (a2.byteLength !== b2.byteLength) {
5124
- return false;
5125
- }
5126
- for (let i2 = 0; i2 < a2.length; i2++) {
5127
- if (a2[i2] !== b2[i2]) {
5128
- return false;
5129
- }
5130
- }
5131
- break;
5132
- }
5133
- case Set: {
5134
- if (a2.size !== b2.size) {
5135
- return false;
5136
- }
5137
- for (const value of a2) {
5138
- if (!b2.has(value)) {
5139
- return false;
5140
- }
5141
- }
5142
- break;
5143
- }
5144
- case Map: {
5145
- if (a2.size !== b2.size) {
5146
- return false;
5147
- }
5148
- for (const key of a2.keys()) {
5149
- if (!b2.has(key) || !equalityDeep(a2.get(key), b2.get(key))) {
5150
- return false;
5151
- }
5152
- }
5153
- break;
5154
- }
5155
- case Object:
5156
- if (length2(a2) !== length2(b2)) {
5157
- return false;
5158
- }
5159
- for (const key in a2) {
5160
- if (!hasProperty(a2, key) || !equalityDeep(a2[key], b2[key])) {
5161
- return false;
5162
- }
5163
- }
5164
- break;
5165
- case Array:
5166
- if (a2.length !== b2.length) {
5167
- return false;
5168
- }
5169
- for (let i2 = 0; i2 < a2.length; i2++) {
5170
- if (!equalityDeep(a2[i2], b2[i2])) {
5171
- return false;
5172
- }
5173
- }
5174
- break;
5175
- default:
5176
- return false;
5177
- }
5178
- return true;
5179
- };
5180
5151
 
5181
5152
  // ../../node_modules/lib0/symbol.js
5182
5153
  var create5 = Symbol;
@@ -10009,7 +9980,10 @@ var SlateYjsCore = (() => {
10009
9980
  const content = yTextToSlateElement(e.sharedRoot);
10010
9981
  e.children = content.children;
10011
9982
  CONNECTED.add(e);
10012
- e.onChange();
9983
+ Editor.normalize(editor, { force: true });
9984
+ if (!editor.operations.length) {
9985
+ editor.onChange();
9986
+ }
10013
9987
  };
10014
9988
  e.disconnect = () => {
10015
9989
  if (autoConnectTimeoutId) {
@@ -10162,118 +10136,11 @@ var SlateYjsCore = (() => {
10162
10136
  return e;
10163
10137
  }
10164
10138
 
10165
- // ../../node_modules/y-protocols/awareness.js
10166
- var outdatedTimeout = 3e4;
10167
- var Awareness = class extends Observable {
10168
- constructor(doc2) {
10169
- super();
10170
- this.doc = doc2;
10171
- this.clientID = doc2.clientID;
10172
- this.states = /* @__PURE__ */ new Map();
10173
- this.meta = /* @__PURE__ */ new Map();
10174
- this._checkInterval = setInterval(() => {
10175
- const now = getUnixTime();
10176
- if (this.getLocalState() !== null && outdatedTimeout / 2 <= now - this.meta.get(this.clientID).lastUpdated) {
10177
- this.setLocalState(this.getLocalState());
10178
- }
10179
- const remove = [];
10180
- this.meta.forEach((meta, clientid) => {
10181
- if (clientid !== this.clientID && outdatedTimeout <= now - meta.lastUpdated && this.states.has(clientid)) {
10182
- remove.push(clientid);
10183
- }
10184
- });
10185
- if (remove.length > 0) {
10186
- removeAwarenessStates(this, remove, "timeout");
10187
- }
10188
- }, floor(outdatedTimeout / 10));
10189
- doc2.on("destroy", () => {
10190
- this.destroy();
10191
- });
10192
- this.setLocalState({});
10193
- }
10194
- destroy() {
10195
- this.emit("destroy", [this]);
10196
- this.setLocalState(null);
10197
- super.destroy();
10198
- clearInterval(this._checkInterval);
10199
- }
10200
- getLocalState() {
10201
- return this.states.get(this.clientID) || null;
10202
- }
10203
- setLocalState(state) {
10204
- const clientID = this.clientID;
10205
- const currLocalMeta = this.meta.get(clientID);
10206
- const clock = currLocalMeta === void 0 ? 0 : currLocalMeta.clock + 1;
10207
- const prevState = this.states.get(clientID);
10208
- if (state === null) {
10209
- this.states.delete(clientID);
10210
- } else {
10211
- this.states.set(clientID, state);
10212
- }
10213
- this.meta.set(clientID, {
10214
- clock,
10215
- lastUpdated: getUnixTime()
10216
- });
10217
- const added = [];
10218
- const updated = [];
10219
- const filteredUpdated = [];
10220
- const removed = [];
10221
- if (state === null) {
10222
- removed.push(clientID);
10223
- } else if (prevState == null) {
10224
- if (state != null) {
10225
- added.push(clientID);
10226
- }
10227
- } else {
10228
- updated.push(clientID);
10229
- if (!equalityDeep(prevState, state)) {
10230
- filteredUpdated.push(clientID);
10231
- }
10232
- }
10233
- if (added.length > 0 || filteredUpdated.length > 0 || removed.length > 0) {
10234
- this.emit("change", [{ added, updated: filteredUpdated, removed }, "local"]);
10235
- }
10236
- this.emit("update", [{ added, updated, removed }, "local"]);
10237
- }
10238
- setLocalStateField(field, value) {
10239
- const state = this.getLocalState();
10240
- if (state !== null) {
10241
- this.setLocalState(__spreadProps(__spreadValues({}, state), {
10242
- [field]: value
10243
- }));
10244
- }
10245
- }
10246
- getStates() {
10247
- return this.states;
10248
- }
10249
- };
10250
- var removeAwarenessStates = (awareness, clients, origin) => {
10251
- const removed = [];
10252
- for (let i2 = 0; i2 < clients.length; i2++) {
10253
- const clientID = clients[i2];
10254
- if (awareness.states.has(clientID)) {
10255
- awareness.states.delete(clientID);
10256
- if (clientID === awareness.clientID) {
10257
- const curMeta = awareness.meta.get(clientID);
10258
- awareness.meta.set(clientID, {
10259
- clock: curMeta.clock + 1,
10260
- lastUpdated: getUnixTime()
10261
- });
10262
- }
10263
- removed.push(clientID);
10264
- }
10265
- }
10266
- if (removed.length > 0) {
10267
- awareness.emit("change", [{ added: [], updated: [], removed }, origin]);
10268
- awareness.emit("update", [{ added: [], updated: [], removed }, origin]);
10269
- }
10270
- };
10271
-
10272
10139
  // src/plugins/withCursors.ts
10273
10140
  var CURSOR_CHANGE_EVENT_LISTENERS = /* @__PURE__ */ new WeakMap();
10274
10141
  var CursorEditor = {
10275
10142
  isCursorEditor(value) {
10276
- return YjsEditor.isYjsEditor(value) && value.awareness instanceof Awareness && typeof value.cursorDataField === "string" && typeof value.selectionStateField === "string" && typeof value.sendCursorPosition === "function" && typeof value.sendCursorData === "function";
10143
+ return YjsEditor.isYjsEditor(value) && value.awareness && typeof value.cursorDataField === "string" && typeof value.selectionStateField === "string" && typeof value.sendCursorPosition === "function" && typeof value.sendCursorData === "function";
10277
10144
  },
10278
10145
  sendCursorPosition(editor, range = editor.selection) {
10279
10146
  editor.sendCursorPosition(range);