slate-react 0.110.2 → 0.110.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"with-react.d.ts","sourceRoot":"","sources":["../../../../packages/slate-react/src/plugin/with-react.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EAUX,MAAM,OAAO,CAAA;AA0Bd,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAG5C;;;;;;;GAOG;AAEH,eAAO,MAAM,SAAS,mFAqUrB,CAAA"}
1
+ {"version":3,"file":"with-react.d.ts","sourceRoot":"","sources":["../../../../packages/slate-react/src/plugin/with-react.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EAUX,MAAM,OAAO,CAAA;AA2Bd,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAG5C;;;;;;;GAOG;AAEH,eAAO,MAAM,SAAS,mFA+UrB,CAAA"}
@@ -859,6 +859,7 @@
859
859
  * Two weak maps that allow us rebuild a path given a node. They are populated
860
860
  * at render time such that after a render occurs we can always backtrack.
861
861
  */
862
+ var IS_NODE_MAP_DIRTY = new WeakMap();
862
863
  var NODE_TO_INDEX = new WeakMap();
863
864
  var NODE_TO_PARENT = new WeakMap();
864
865
  /**
@@ -2473,6 +2474,9 @@
2473
2474
  clearTimeout(flushTimeoutId);
2474
2475
  flushTimeoutId = null;
2475
2476
  }
2477
+ if (IS_NODE_MAP_DIRTY.get(editor)) {
2478
+ return;
2479
+ }
2476
2480
  var type = event.inputType;
2477
2481
  var targetRange = null;
2478
2482
  var data = event.dataTransfer || event.data || undefined;
@@ -3974,6 +3978,7 @@
3974
3978
  selection = props.selection;
3975
3979
  var decorate = useDecorate();
3976
3980
  var editor = useSlateStatic();
3981
+ IS_NODE_MAP_DIRTY.set(editor, false);
3977
3982
  var path = ReactEditor.findPath(editor, node);
3978
3983
  var children = [];
3979
3984
  var isLeafBlock = slate.Element.isElement(node) && !editor.isInline(node) && slate.Editor.hasInlines(editor, node);
@@ -4737,6 +4742,10 @@
4737
4742
  // while a selection is being dragged.
4738
4743
  var onDOMSelectionChange = React.useMemo(function () {
4739
4744
  return throttle_1(function () {
4745
+ if (IS_NODE_MAP_DIRTY.get(editor)) {
4746
+ onDOMSelectionChange();
4747
+ return;
4748
+ }
4740
4749
  var el = ReactEditor.toDOMNode(editor, editor);
4741
4750
  var root = el.getRootNode();
4742
4751
  if (!processing.current && IS_WEBKIT && root instanceof ShadowRoot) {
@@ -4991,48 +5000,52 @@
4991
5000
  // When there is an inline element, e.g. a link, and you select
4992
5001
  // right after it (the start of the next node).
4993
5002
  selection.anchor.offset !== 0) {
4994
- var _node$parentElement, _window$getComputedSt;
4995
5003
  _native = true;
4996
5004
  // Skip native if there are marks, as
4997
5005
  // `insertText` will insert a node, not just text.
4998
5006
  if (editor.marks) {
4999
5007
  _native = false;
5000
5008
  }
5001
- // Chrome also has issues correctly editing the end of anchor elements: https://bugs.chromium.org/p/chromium/issues/detail?id=1259100
5002
- // Therefore we don't allow native events to insert text at the end of anchor nodes.
5003
- var anchor = selection.anchor;
5004
- var _ReactEditor$toDOMPoi = ReactEditor.toDOMPoint(editor, anchor),
5005
- _ReactEditor$toDOMPoi2 = _slicedToArray(_ReactEditor$toDOMPoi, 2),
5006
- node = _ReactEditor$toDOMPoi2[0],
5007
- offset = _ReactEditor$toDOMPoi2[1];
5008
- var anchorNode = (_node$parentElement = node.parentElement) === null || _node$parentElement === void 0 ? void 0 : _node$parentElement.closest('a');
5009
- var _window = ReactEditor.getWindow(editor);
5010
- if (_native && anchorNode && ReactEditor.hasDOMNode(editor, anchorNode)) {
5011
- var _lastText$textContent;
5012
- // Find the last text node inside the anchor.
5013
- var lastText = _window === null || _window === void 0 ? void 0 : _window.document.createTreeWalker(anchorNode, NodeFilter.SHOW_TEXT).lastChild();
5014
- if (lastText === node && ((_lastText$textContent = lastText.textContent) === null || _lastText$textContent === void 0 ? void 0 : _lastText$textContent.length) === offset) {
5015
- _native = false;
5009
+ // If the NODE_MAP is dirty, we can't trust the selection anchor (eg ReactEditor.toDOMPoint)
5010
+ if (!IS_NODE_MAP_DIRTY.get(editor)) {
5011
+ var _node$parentElement, _window$getComputedSt;
5012
+ // Chrome also has issues correctly editing the end of anchor elements: https://bugs.chromium.org/p/chromium/issues/detail?id=1259100
5013
+ // Therefore we don't allow native events to insert text at the end of anchor nodes.
5014
+ var anchor = selection.anchor;
5015
+ var _ReactEditor$toDOMPoi = ReactEditor.toDOMPoint(editor, anchor),
5016
+ _ReactEditor$toDOMPoi2 = _slicedToArray(_ReactEditor$toDOMPoi, 2),
5017
+ node = _ReactEditor$toDOMPoi2[0],
5018
+ offset = _ReactEditor$toDOMPoi2[1];
5019
+ var anchorNode = (_node$parentElement = node.parentElement) === null || _node$parentElement === void 0 ? void 0 : _node$parentElement.closest('a');
5020
+ var _window = ReactEditor.getWindow(editor);
5021
+ if (_native && anchorNode && ReactEditor.hasDOMNode(editor, anchorNode)) {
5022
+ var _lastText$textContent;
5023
+ // Find the last text node inside the anchor.
5024
+ var lastText = _window === null || _window === void 0 ? void 0 : _window.document.createTreeWalker(anchorNode, NodeFilter.SHOW_TEXT).lastChild();
5025
+ if (lastText === node && ((_lastText$textContent = lastText.textContent) === null || _lastText$textContent === void 0 ? void 0 : _lastText$textContent.length) === offset) {
5026
+ _native = false;
5027
+ }
5016
5028
  }
5017
- }
5018
- // Chrome has issues with the presence of tab characters inside elements with whiteSpace = 'pre'
5019
- // causing abnormal insert behavior: https://bugs.chromium.org/p/chromium/issues/detail?id=1219139
5020
- if (_native && node.parentElement && (_window === null || _window === void 0 || (_window$getComputedSt = _window.getComputedStyle(node.parentElement)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.whiteSpace) === 'pre') {
5021
- var block = slate.Editor.above(editor, {
5022
- at: anchor.path,
5023
- match: function match(n) {
5024
- return slate.Element.isElement(n) && slate.Editor.isBlock(editor, n);
5029
+ // Chrome has issues with the presence of tab characters inside elements with whiteSpace = 'pre'
5030
+ // causing abnormal insert behavior: https://bugs.chromium.org/p/chromium/issues/detail?id=1219139
5031
+ if (_native && node.parentElement && (_window === null || _window === void 0 || (_window$getComputedSt = _window.getComputedStyle(node.parentElement)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.whiteSpace) === 'pre') {
5032
+ var block = slate.Editor.above(editor, {
5033
+ at: anchor.path,
5034
+ match: function match(n) {
5035
+ return slate.Element.isElement(n) && slate.Editor.isBlock(editor, n);
5036
+ }
5037
+ });
5038
+ if (block && slate.Node.string(block[0]).includes('\t')) {
5039
+ _native = false;
5025
5040
  }
5026
- });
5027
- if (block && slate.Node.string(block[0]).includes('\t')) {
5028
- _native = false;
5029
5041
  }
5030
5042
  }
5031
5043
  }
5032
5044
  // COMPAT: For the deleting forward/backward input types we don't want
5033
5045
  // to change the selection because it is the range that will be deleted,
5034
5046
  // and those commands determine that for themselves.
5035
- if (!type.startsWith('delete') || type.startsWith('deleteBy')) {
5047
+ // If the NODE_MAP is dirty, we can't trust the selection anchor (eg ReactEditor.toDOMPoint via ReactEditor.toSlateRange)
5048
+ if ((!type.startsWith('delete') || type.startsWith('deleteBy')) && !IS_NODE_MAP_DIRTY.get(editor)) {
5036
5049
  var _event$getTargetRange = event.getTargetRanges(),
5037
5050
  _event$getTargetRange2 = _slicedToArray(_event$getTargetRange, 1),
5038
5051
  targetRange = _event$getTargetRange2[0];
@@ -36976,6 +36989,16 @@
36976
36989
  }
36977
36990
  }
36978
36991
  apply(op);
36992
+ switch (op.type) {
36993
+ case 'insert_node':
36994
+ case 'remove_node':
36995
+ case 'merge_node':
36996
+ case 'move_node':
36997
+ case 'split_node':
36998
+ {
36999
+ IS_NODE_MAP_DIRTY.set(e, true);
37000
+ }
37001
+ }
36979
37002
  for (var _i = 0, _matches = matches; _i < _matches.length; _i++) {
36980
37003
  var _matches$_i = _slicedToArray(_matches[_i], 2),
36981
37004
  path = _matches$_i[0],