@codemirror/view 6.2.4 → 6.2.5

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,3 +1,11 @@
1
+ ## 6.2.5 (2022-09-24)
2
+
3
+ ### Bug fixes
4
+
5
+ Don't override double/triple tap behavior on touch screen devices, so that the mobile selection menu pops up properly.
6
+
7
+ Fix an issue where updating the selection could crash on Safari when the editor was hidden.
8
+
1
9
  ## 6.2.4 (2022-09-16)
2
10
 
3
11
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -100,7 +100,7 @@ function windowRect(win) {
100
100
  top: 0, bottom: win.innerHeight };
101
101
  }
102
102
  function scrollRectIntoView(dom, rect, side, x, y, xMargin, yMargin, ltr) {
103
- let doc = dom.ownerDocument, win = doc.defaultView;
103
+ let doc = dom.ownerDocument, win = doc.defaultView || window;
104
104
  for (let cur = dom; cur;) {
105
105
  if (cur.nodeType == 1) { // Element
106
106
  let bounding, top = cur == doc.body;
@@ -350,7 +350,7 @@ class ContentView {
350
350
  if (child.dirty) {
351
351
  if (!child.dom && (next = prev ? prev.nextSibling : parent.firstChild)) {
352
352
  let contentView = ContentView.get(next);
353
- if (!contentView || !contentView.parent && contentView.constructor == child.constructor)
353
+ if (!contentView || !contentView.parent && contentView.canReuseDOM(child))
354
354
  child.reuseDOM(next);
355
355
  }
356
356
  child.sync(track);
@@ -508,6 +508,7 @@ class ContentView {
508
508
  return false;
509
509
  }
510
510
  become(other) { return false; }
511
+ canReuseDOM(other) { return other.constructor == this.constructor; }
511
512
  // When this is a zero-length view with a side, this should return a
512
513
  // number <= 0 to indicate it is before its position, or a
513
514
  // number > 0 when after its position.
@@ -911,6 +912,7 @@ class CompositionView extends WidgetView {
911
912
  (_a = this.widget.topView) === null || _a === void 0 ? void 0 : _a.destroy();
912
913
  }
913
914
  get isEditable() { return true; }
915
+ canReuseDOM() { return true; }
914
916
  }
915
917
  // Uses the old structure of a chunk of content view frozen for
916
918
  // composition to try and find a reasonable DOM location for the given
@@ -2639,7 +2641,13 @@ class DocView extends ContentView {
2639
2641
  // (one where the focus is before the anchor), but not all
2640
2642
  // browsers support it yet.
2641
2643
  rawSel.collapse(anchor.node, anchor.offset);
2642
- rawSel.extend(head.node, head.offset);
2644
+ // Safari will ignore the call above when the editor is
2645
+ // hidden, and then raise an error on the call to extend
2646
+ // (#940).
2647
+ try {
2648
+ rawSel.extend(head.node, head.offset);
2649
+ }
2650
+ catch (_) { }
2643
2651
  }
2644
2652
  else {
2645
2653
  // Primitive (IE) way
@@ -3692,7 +3700,7 @@ handlers.touchmove = view => {
3692
3700
  handlerOptions.touchstart = handlerOptions.touchmove = { passive: true };
3693
3701
  handlers.mousedown = (view, event) => {
3694
3702
  view.observer.flush();
3695
- if (view.inputState.lastTouchTime > Date.now() - 2000 && getClickType(event) == 1)
3703
+ if (view.inputState.lastTouchTime > Date.now() - 2000)
3696
3704
  return; // Ignore touch interaction
3697
3705
  let style = null;
3698
3706
  for (let makeStyle of view.state.facet(mouseSelectionStyle)) {
@@ -4663,7 +4671,7 @@ class DecorationComparator {
4663
4671
 
4664
4672
  function visiblePixelRange(dom, paddingTop) {
4665
4673
  let rect = dom.getBoundingClientRect();
4666
- let doc = dom.ownerDocument, win = doc.defaultView;
4674
+ let doc = dom.ownerDocument, win = doc.defaultView || window;
4667
4675
  let left = Math.max(0, rect.left), right = Math.min(win.innerWidth, rect.right);
4668
4676
  let top = Math.max(0, rect.top), bottom = Math.min(win.innerHeight, rect.bottom);
4669
4677
  for (let parent = dom.parentNode; parent && parent != doc.body;) {
@@ -6738,7 +6746,7 @@ class EditorView {
6738
6746
  setRoot(root) {
6739
6747
  if (this._root != root) {
6740
6748
  this._root = root;
6741
- this.observer.setWindow((root.nodeType == 9 ? root : root.ownerDocument).defaultView);
6749
+ this.observer.setWindow((root.nodeType == 9 ? root : root.ownerDocument).defaultView || window);
6742
6750
  this.mountStyles();
6743
6751
  }
6744
6752
  }
package/dist/index.js CHANGED
@@ -96,7 +96,7 @@ function windowRect(win) {
96
96
  top: 0, bottom: win.innerHeight };
97
97
  }
98
98
  function scrollRectIntoView(dom, rect, side, x, y, xMargin, yMargin, ltr) {
99
- let doc = dom.ownerDocument, win = doc.defaultView;
99
+ let doc = dom.ownerDocument, win = doc.defaultView || window;
100
100
  for (let cur = dom; cur;) {
101
101
  if (cur.nodeType == 1) { // Element
102
102
  let bounding, top = cur == doc.body;
@@ -346,7 +346,7 @@ class ContentView {
346
346
  if (child.dirty) {
347
347
  if (!child.dom && (next = prev ? prev.nextSibling : parent.firstChild)) {
348
348
  let contentView = ContentView.get(next);
349
- if (!contentView || !contentView.parent && contentView.constructor == child.constructor)
349
+ if (!contentView || !contentView.parent && contentView.canReuseDOM(child))
350
350
  child.reuseDOM(next);
351
351
  }
352
352
  child.sync(track);
@@ -504,6 +504,7 @@ class ContentView {
504
504
  return false;
505
505
  }
506
506
  become(other) { return false; }
507
+ canReuseDOM(other) { return other.constructor == this.constructor; }
507
508
  // When this is a zero-length view with a side, this should return a
508
509
  // number <= 0 to indicate it is before its position, or a
509
510
  // number > 0 when after its position.
@@ -907,6 +908,7 @@ class CompositionView extends WidgetView {
907
908
  (_a = this.widget.topView) === null || _a === void 0 ? void 0 : _a.destroy();
908
909
  }
909
910
  get isEditable() { return true; }
911
+ canReuseDOM() { return true; }
910
912
  }
911
913
  // Uses the old structure of a chunk of content view frozen for
912
914
  // composition to try and find a reasonable DOM location for the given
@@ -2633,7 +2635,13 @@ class DocView extends ContentView {
2633
2635
  // (one where the focus is before the anchor), but not all
2634
2636
  // browsers support it yet.
2635
2637
  rawSel.collapse(anchor.node, anchor.offset);
2636
- rawSel.extend(head.node, head.offset);
2638
+ // Safari will ignore the call above when the editor is
2639
+ // hidden, and then raise an error on the call to extend
2640
+ // (#940).
2641
+ try {
2642
+ rawSel.extend(head.node, head.offset);
2643
+ }
2644
+ catch (_) { }
2637
2645
  }
2638
2646
  else {
2639
2647
  // Primitive (IE) way
@@ -3686,7 +3694,7 @@ handlers.touchmove = view => {
3686
3694
  handlerOptions.touchstart = handlerOptions.touchmove = { passive: true };
3687
3695
  handlers.mousedown = (view, event) => {
3688
3696
  view.observer.flush();
3689
- if (view.inputState.lastTouchTime > Date.now() - 2000 && getClickType(event) == 1)
3697
+ if (view.inputState.lastTouchTime > Date.now() - 2000)
3690
3698
  return; // Ignore touch interaction
3691
3699
  let style = null;
3692
3700
  for (let makeStyle of view.state.facet(mouseSelectionStyle)) {
@@ -4656,7 +4664,7 @@ class DecorationComparator {
4656
4664
 
4657
4665
  function visiblePixelRange(dom, paddingTop) {
4658
4666
  let rect = dom.getBoundingClientRect();
4659
- let doc = dom.ownerDocument, win = doc.defaultView;
4667
+ let doc = dom.ownerDocument, win = doc.defaultView || window;
4660
4668
  let left = Math.max(0, rect.left), right = Math.min(win.innerWidth, rect.right);
4661
4669
  let top = Math.max(0, rect.top), bottom = Math.min(win.innerHeight, rect.bottom);
4662
4670
  for (let parent = dom.parentNode; parent && parent != doc.body;) {
@@ -6731,7 +6739,7 @@ class EditorView {
6731
6739
  setRoot(root) {
6732
6740
  if (this._root != root) {
6733
6741
  this._root = root;
6734
- this.observer.setWindow((root.nodeType == 9 ? root : root.ownerDocument).defaultView);
6742
+ this.observer.setWindow((root.nodeType == 9 ? root : root.ownerDocument).defaultView || window);
6735
6743
  this.mountStyles();
6736
6744
  }
6737
6745
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.2.4",
3
+ "version": "6.2.5",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",