slate-react 0.76.0-20222247328 → 0.76.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.
package/dist/index.js CHANGED
@@ -796,21 +796,6 @@ var useSlateStatic = function useSlateStatic() {
796
796
  return editor;
797
797
  };
798
798
 
799
- /**
800
- * A React context for sharing the `decorate` prop of the editable.
801
- */
802
-
803
- var DecorateContext = /*#__PURE__*/React.createContext(function () {
804
- return [];
805
- });
806
- /**
807
- * Get the current `decorate` prop of the editable.
808
- */
809
-
810
- var useDecorate = function useDecorate() {
811
- return React.useContext(DecorateContext);
812
- };
813
-
814
799
  /**
815
800
  * A React context for sharing the `selected` state of an element.
816
801
  */
@@ -835,7 +820,6 @@ var useChildren = function useChildren(props) {
835
820
  renderPlaceholder = props.renderPlaceholder,
836
821
  renderLeaf = props.renderLeaf,
837
822
  selection = props.selection;
838
- useDecorate();
839
823
  var editor = useSlateStatic();
840
824
  var path = ReactEditor.findPath(editor, node);
841
825
  var children = [];
@@ -847,9 +831,11 @@ var useChildren = function useChildren(props) {
847
831
  var key = ReactEditor.findKey(editor, n);
848
832
  var range = slate.Editor.range(editor, p);
849
833
  var sel = selection && slate.Range.intersection(range, selection);
850
- var ds = decorations.filter(function (dec) {
851
- return slate.Range.intersection(dec, range);
852
- });
834
+ var ds = decorations.reduce(function (acc, dec) {
835
+ var intersection = slate.Range.intersection(dec, range);
836
+ if (intersection) acc.push(intersection);
837
+ return acc;
838
+ }, []);
853
839
 
854
840
  if (slate.Element.isElement(n)) {
855
841
  children.push( /*#__PURE__*/React__default['default'].createElement(SelectedContext.Provider, {
@@ -1014,6 +1000,14 @@ var useSlate = function useSlate() {
1014
1000
  return editor;
1015
1001
  };
1016
1002
 
1003
+ /**
1004
+ * A React context for sharing the `decorate` prop of the editable.
1005
+ */
1006
+
1007
+ var DecorateContext = /*#__PURE__*/React.createContext(function () {
1008
+ return [];
1009
+ });
1010
+
1017
1011
  /**
1018
1012
  * Returns the host window of a DOM node
1019
1013
  */
@@ -4504,7 +4498,9 @@ var withReact = function withReact(editor) {
4504
4498
  }
4505
4499
  }
4506
4500
  }
4507
- };
4501
+ }; // This attempts to reset the NODE_TO_KEY entry to the correct value
4502
+ // as apply() changes the object reference and hence invalidates the NODE_TO_KEY entry
4503
+
4508
4504
 
4509
4505
  e.apply = function (op) {
4510
4506
  var matches = [];
@@ -4513,82 +4509,30 @@ var withReact = function withReact(editor) {
4513
4509
  case 'insert_text':
4514
4510
  case 'remove_text':
4515
4511
  case 'set_node':
4512
+ case 'split_node':
4516
4513
  {
4517
- var _iterator = _createForOfIteratorHelper(slate.Editor.levels(e, {
4518
- at: op.path
4519
- })),
4520
- _step;
4521
-
4522
- try {
4523
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
4524
- var _step$value = _slicedToArray(_step.value, 2),
4525
- node = _step$value[0],
4526
- path = _step$value[1];
4527
-
4528
- var key = ReactEditor.findKey(e, node);
4529
- matches.push([path, key]);
4530
- }
4531
- } catch (err) {
4532
- _iterator.e(err);
4533
- } finally {
4534
- _iterator.f();
4535
- }
4536
-
4514
+ matches.push.apply(matches, _toConsumableArray(getMatches(e, op.path)));
4537
4515
  break;
4538
4516
  }
4539
4517
 
4540
4518
  case 'insert_node':
4541
4519
  case 'remove_node':
4542
- case 'merge_node':
4543
- case 'split_node':
4544
4520
  {
4545
- var _iterator2 = _createForOfIteratorHelper(slate.Editor.levels(e, {
4546
- at: slate.Path.parent(op.path)
4547
- })),
4548
- _step2;
4549
-
4550
- try {
4551
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
4552
- var _step2$value = _slicedToArray(_step2.value, 2),
4553
- _node = _step2$value[0],
4554
- _path = _step2$value[1];
4555
-
4556
- var _key = ReactEditor.findKey(e, _node);
4557
-
4558
- matches.push([_path, _key]);
4559
- }
4560
- } catch (err) {
4561
- _iterator2.e(err);
4562
- } finally {
4563
- _iterator2.f();
4564
- }
4521
+ matches.push.apply(matches, _toConsumableArray(getMatches(e, slate.Path.parent(op.path))));
4522
+ break;
4523
+ }
4565
4524
 
4525
+ case 'merge_node':
4526
+ {
4527
+ var prevPath = slate.Path.previous(op.path);
4528
+ matches.push.apply(matches, _toConsumableArray(getMatches(e, prevPath)));
4566
4529
  break;
4567
4530
  }
4568
4531
 
4569
4532
  case 'move_node':
4570
4533
  {
4571
- var _iterator3 = _createForOfIteratorHelper(slate.Editor.levels(e, {
4572
- at: slate.Path.common(slate.Path.parent(op.path), slate.Path.parent(op.newPath))
4573
- })),
4574
- _step3;
4575
-
4576
- try {
4577
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
4578
- var _step3$value = _slicedToArray(_step3.value, 2),
4579
- _node2 = _step3$value[0],
4580
- _path2 = _step3$value[1];
4581
-
4582
- var _key2 = ReactEditor.findKey(e, _node2);
4583
-
4584
- matches.push([_path2, _key2]);
4585
- }
4586
- } catch (err) {
4587
- _iterator3.e(err);
4588
- } finally {
4589
- _iterator3.f();
4590
- }
4591
-
4534
+ var commonPath = slate.Path.common(slate.Path.parent(op.path), slate.Path.parent(op.newPath));
4535
+ matches.push.apply(matches, _toConsumableArray(getMatches(e, commonPath)));
4592
4536
  break;
4593
4537
  }
4594
4538
  }
@@ -4597,14 +4541,14 @@ var withReact = function withReact(editor) {
4597
4541
 
4598
4542
  for (var _i = 0, _matches = matches; _i < _matches.length; _i++) {
4599
4543
  var _matches$_i = _slicedToArray(_matches[_i], 2),
4600
- _path3 = _matches$_i[0],
4601
- _key3 = _matches$_i[1];
4544
+ path = _matches$_i[0],
4545
+ key = _matches$_i[1];
4602
4546
 
4603
- var _Editor$node = slate.Editor.node(e, _path3),
4547
+ var _Editor$node = slate.Editor.node(e, path),
4604
4548
  _Editor$node2 = _slicedToArray(_Editor$node, 1),
4605
- _node3 = _Editor$node2[0];
4549
+ node = _Editor$node2[0];
4606
4550
 
4607
- NODE_TO_KEY.set(_node3, _key3);
4551
+ NODE_TO_KEY.set(node, key);
4608
4552
  }
4609
4553
  };
4610
4554
 
@@ -4727,12 +4671,12 @@ var withReact = function withReact(editor) {
4727
4671
  var lines = text.split(/\r\n|\r|\n/);
4728
4672
  var split = false;
4729
4673
 
4730
- var _iterator4 = _createForOfIteratorHelper(lines),
4731
- _step4;
4674
+ var _iterator = _createForOfIteratorHelper(lines),
4675
+ _step;
4732
4676
 
4733
4677
  try {
4734
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
4735
- var line = _step4.value;
4678
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
4679
+ var line = _step.value;
4736
4680
 
4737
4681
  if (split) {
4738
4682
  slate.Transforms.splitNodes(e, {
@@ -4744,9 +4688,9 @@ var withReact = function withReact(editor) {
4744
4688
  split = true;
4745
4689
  }
4746
4690
  } catch (err) {
4747
- _iterator4.e(err);
4691
+ _iterator.e(err);
4748
4692
  } finally {
4749
- _iterator4.f();
4693
+ _iterator.f();
4750
4694
  }
4751
4695
 
4752
4696
  return true;
@@ -4774,6 +4718,32 @@ var withReact = function withReact(editor) {
4774
4718
  return e;
4775
4719
  };
4776
4720
 
4721
+ var getMatches = function getMatches(e, path) {
4722
+ var matches = [];
4723
+
4724
+ var _iterator2 = _createForOfIteratorHelper(slate.Editor.levels(e, {
4725
+ at: path
4726
+ })),
4727
+ _step2;
4728
+
4729
+ try {
4730
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
4731
+ var _step2$value = _slicedToArray(_step2.value, 2),
4732
+ n = _step2$value[0],
4733
+ p = _step2$value[1];
4734
+
4735
+ var key = ReactEditor.findKey(e, n);
4736
+ matches.push([p, key]);
4737
+ }
4738
+ } catch (err) {
4739
+ _iterator2.e(err);
4740
+ } finally {
4741
+ _iterator2.f();
4742
+ }
4743
+
4744
+ return matches;
4745
+ };
4746
+
4777
4747
  // Components
4778
4748
  var Editable = IS_ANDROID ? AndroidEditable : Editable$1;
4779
4749