slate-react 0.66.4 → 0.66.7-2021911122111

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # slate-react
2
2
 
3
+ ## 0.66.7-2021911122111
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4588](https://github.com/ianstormtaylor/slate/pull/4588) [`ae65ae5f`](https://github.com/ianstormtaylor/slate/commit/ae65ae5f717c877eee0e3f839b76fc18d8b44999) Thanks [@jaked](https://github.com/jaked)! - revert #4455 / #4512; fix triple-click by unhanging range with void
8
+
9
+ ## 0.66.6
10
+
11
+ ### Patch Changes
12
+
13
+ - [#4556](https://github.com/ianstormtaylor/slate/pull/4556) [`b1084918`](https://github.com/ianstormtaylor/slate/commit/b10849182086699d4bb18209a37ea6247f712bd0) Thanks [@jaked](https://github.com/jaked)! - fix forced update in TextString in case of double render
14
+
3
15
  ## 0.66.4
4
16
 
5
17
  ### Patch Changes
package/dist/index.es.js CHANGED
@@ -117,10 +117,10 @@ var TextString = props => {
117
117
  isTrailing = false
118
118
  } = props;
119
119
  var ref = useRef(null);
120
- var forceUpdateFlag = useRef(false);
120
+ var forceUpdateCount = useRef(0);
121
121
 
122
122
  if (ref.current && ref.current.textContent !== text) {
123
- forceUpdateFlag.current = !forceUpdateFlag.current;
123
+ forceUpdateCount.current += 1;
124
124
  } // This component may have skipped rendering due to native operations being
125
125
  // applied. If an undo is performed React will see the old and new shadow DOM
126
126
  // match and not apply an update. Forces each render to actually reconcile.
@@ -129,7 +129,7 @@ var TextString = props => {
129
129
  return /*#__PURE__*/React.createElement("span", {
130
130
  "data-slate-string": true,
131
131
  ref: ref,
132
- key: forceUpdateFlag.current ? 'A' : 'B'
132
+ key: forceUpdateCount.current
133
133
  }, text, isTrailing ? '\n' : null);
134
134
  };
135
135
  /**
@@ -2551,7 +2551,7 @@ var ReactEditor = {
2551
2551
  }
2552
2552
  }
2553
2553
 
2554
- if (domNode && offset === domNode.textContent.length && (parentNode.hasAttribute('data-slate-zero-width') || IS_FIREFOX && (_domNode$textContent = domNode.textContent) !== null && _domNode$textContent !== void 0 && _domNode$textContent.endsWith('\n'))) {
2554
+ if (domNode && offset === domNode.textContent.length && (parentNode.hasAttribute('data-slate-zero-width') || IS_FIREFOX && (_domNode$textContent = domNode.textContent) !== null && _domNode$textContent !== void 0 && _domNode$textContent.endsWith('\n\n'))) {
2555
2555
  offset--;
2556
2556
  }
2557
2557
  }
@@ -2594,61 +2594,11 @@ var ReactEditor = {
2594
2594
  anchorNode = domRange.anchorNode;
2595
2595
  anchorOffset = domRange.anchorOffset;
2596
2596
  focusNode = domRange.focusNode;
2597
- focusOffset = domRange.focusOffset; // When triple clicking a block, Chrome will return a selection object whose
2598
- // focus node is the next element sibling and focusOffset is 0.
2599
- // This will highlight the corresponding toolbar button for the sibling
2600
- // block even though users just want to target the previous block.
2601
- // (2021/08/24)
2602
- // Signs of a triple click in Chrome
2603
- // - anchor node will be a text node but focus node won't
2604
- // - both anchorOffset and focusOffset are 0
2605
- // - focusNode value will be null since Chrome tries to extend to just the
2606
- // beginning of the next block
2607
-
2608
- if (IS_CHROME && anchorNode && focusNode && anchorNode.nodeType !== focusNode.nodeType && domRange.anchorOffset === 0 && domRange.focusOffset === 0 && focusNode.nodeValue == null) {
2609
- // If an anchorNode is an element node when triple clicked, then the focusNode
2610
- // should also be the same as anchorNode when triple clicked.
2611
- // Otherwise, anchorNode is a text node and we need to
2612
- // - climb up the DOM tree to get the farthest element node that receives
2613
- // triple click. It should have atribute 'data-slate-node' = "element"
2614
- // - get the last child of that element node
2615
- // - climb down the DOM tree to get the text node of the last child
2616
- // - this is also the end of the selection aka the focusNode
2617
- var anchorElement = anchorNode.parentNode;
2618
- var selectedBlock = anchorElement.closest('[data-slate-node="element"]');
2619
-
2620
- if (selectedBlock) {
2621
- // The Slate Text nodes are leaf-level and contains document's text.
2622
- // However, when represented in the DOM, they are actually Element nodes
2623
- // and different from the DOM's Text nodes
2624
- var {
2625
- childElementCount: slateTextNodeCount
2626
- } = selectedBlock;
2627
-
2628
- if (slateTextNodeCount === 1) {
2629
- focusNode = anchorNode;
2630
- focusOffset = focusNode.length;
2631
- } else if (slateTextNodeCount > 1) {
2632
- // A element with attribute data-slate-node="element" can have multiple
2633
- // children with attribute data-slate-node="text". But these children only have
2634
- // one child at each level.
2635
- // <span data-slate-node="text">
2636
- // <span data-slate-leaf="">
2637
- // <span data-slate-string=""></span>
2638
- // </span>
2639
- // </span>
2640
- var focusElement = selectedBlock.lastElementChild;
2641
- var nodeIterator = document.createNodeIterator(focusElement, NodeFilter.SHOW_TEXT);
2642
- focusNode = nodeIterator.nextNode();
2643
- focusOffset = focusNode.length;
2644
- }
2645
- }
2646
- } // COMPAT: There's a bug in chrome that always returns `true` for
2597
+ focusOffset = domRange.focusOffset; // COMPAT: There's a bug in chrome that always returns `true` for
2647
2598
  // `isCollapsed` for a Selection that comes from a ShadowRoot.
2648
2599
  // (2020/08/08)
2649
2600
  // https://bugs.chromium.org/p/chromium/issues/detail?id=447523
2650
2601
 
2651
-
2652
2602
  if (IS_CHROME && hasShadowRoot()) {
2653
2603
  isCollapsed = domRange.anchorNode === domRange.focusNode && domRange.anchorOffset === domRange.focusOffset;
2654
2604
  } else {
@@ -2679,10 +2629,24 @@ var ReactEditor = {
2679
2629
  return null;
2680
2630
  }
2681
2631
 
2682
- return {
2683
- anchor,
2684
- focus
2685
- };
2632
+ var range = {
2633
+ anchor: anchor,
2634
+ focus: focus
2635
+ }; // if the selection is a hanging range that ends in a void
2636
+ // and the DOM focus is an Element
2637
+ // (meaning that the selection ends before the element)
2638
+ // unhang the range to avoid mistakenly including the void
2639
+
2640
+ if (Range.isExpanded(range) && Range.isForward(range) && isDOMElement(focusNode) && Editor.void(editor, {
2641
+ at: range.focus,
2642
+ mode: 'highest'
2643
+ })) {
2644
+ range = Editor.unhangRange(editor, range, {
2645
+ voids: true
2646
+ });
2647
+ }
2648
+
2649
+ return range;
2686
2650
  },
2687
2651
 
2688
2652
  hasRange(editor, range) {