@codemirror/view 6.1.4 → 6.2.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/CHANGELOG.md +10 -0
- package/dist/index.cjs +54 -18
- package/dist/index.d.ts +10 -3
- package/dist/index.js +54 -18
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 6.2.0 (2022-08-05)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix a bug where `posAtCoords` would return the wrong results for positions to the right of wrapped lines.
|
|
6
|
+
|
|
7
|
+
### New features
|
|
8
|
+
|
|
9
|
+
The new `EditorView.setRoot` method can be used when an editor view is moved to a new document or shadow root.
|
|
10
|
+
|
|
1
11
|
## 6.1.4 (2022-08-04)
|
|
2
12
|
|
|
3
13
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -2483,7 +2483,6 @@ class DocView extends ContentView {
|
|
|
2483
2483
|
this.updateDeco();
|
|
2484
2484
|
this.updateInner([new ChangedRange(0, 0, 0, view.state.doc.length)], 0);
|
|
2485
2485
|
}
|
|
2486
|
-
get root() { return this.view.root; }
|
|
2487
2486
|
get editorView() { return this.view; }
|
|
2488
2487
|
get length() { return this.view.state.doc.length; }
|
|
2489
2488
|
// Update the document view to a given state. scrollIntoView can be
|
|
@@ -2606,7 +2605,7 @@ class DocView extends ContentView {
|
|
|
2606
2605
|
this.dom.blur();
|
|
2607
2606
|
this.dom.focus({ preventScroll: true });
|
|
2608
2607
|
}
|
|
2609
|
-
let rawSel = getSelection(this.root);
|
|
2608
|
+
let rawSel = getSelection(this.view.root);
|
|
2610
2609
|
if (!rawSel) ;
|
|
2611
2610
|
else if (main.empty) {
|
|
2612
2611
|
// Work around https://bugzilla.mozilla.org/show_bug.cgi?id=1612076
|
|
@@ -2649,7 +2648,7 @@ class DocView extends ContentView {
|
|
|
2649
2648
|
if (this.compositionDeco.size)
|
|
2650
2649
|
return;
|
|
2651
2650
|
let cursor = this.view.state.selection.main;
|
|
2652
|
-
let sel = getSelection(this.root);
|
|
2651
|
+
let sel = getSelection(this.view.root);
|
|
2653
2652
|
if (!sel || !cursor.empty || !cursor.assoc || !sel.modify)
|
|
2654
2653
|
return;
|
|
2655
2654
|
let line = LineView.find(this, cursor.head);
|
|
@@ -2666,7 +2665,7 @@ class DocView extends ContentView {
|
|
|
2666
2665
|
sel.modify("move", cursor.assoc < 0 ? "forward" : "backward", "lineboundary");
|
|
2667
2666
|
}
|
|
2668
2667
|
mayControlSelection() {
|
|
2669
|
-
let active = this.root.activeElement;
|
|
2668
|
+
let active = this.view.root.activeElement;
|
|
2670
2669
|
return active == this.dom ||
|
|
2671
2670
|
hasSelection(this.dom, this.view.observer.selectionRange) && !(active && this.dom.contains(active));
|
|
2672
2671
|
}
|
|
@@ -3019,7 +3018,7 @@ function upBot(rect, bottom) {
|
|
|
3019
3018
|
return bottom > rect.bottom ? { top: rect.top, left: rect.left, right: rect.right, bottom } : rect;
|
|
3020
3019
|
}
|
|
3021
3020
|
function domPosAtCoords(parent, x, y) {
|
|
3022
|
-
let closest, closestRect, closestX, closestY;
|
|
3021
|
+
let closest, closestRect, closestX, closestY, closestOverlap = false;
|
|
3023
3022
|
let above, below, aboveRect, belowRect;
|
|
3024
3023
|
for (let child = parent.firstChild; child; child = child.nextSibling) {
|
|
3025
3024
|
let rects = clientRectsFor(child);
|
|
@@ -3035,6 +3034,7 @@ function domPosAtCoords(parent, x, y) {
|
|
|
3035
3034
|
closestRect = rect;
|
|
3036
3035
|
closestX = dx;
|
|
3037
3036
|
closestY = dy;
|
|
3037
|
+
closestOverlap = !dx || (dx > 0 ? i < rects.length - 1 : i > 0);
|
|
3038
3038
|
}
|
|
3039
3039
|
if (dx == 0) {
|
|
3040
3040
|
if (y > rect.bottom && (!aboveRect || aboveRect.bottom < rect.bottom)) {
|
|
@@ -3067,7 +3067,7 @@ function domPosAtCoords(parent, x, y) {
|
|
|
3067
3067
|
let clipX = Math.max(closestRect.left, Math.min(closestRect.right, x));
|
|
3068
3068
|
if (closest.nodeType == 3)
|
|
3069
3069
|
return domPosInText(closest, clipX, y);
|
|
3070
|
-
if (
|
|
3070
|
+
if (closestOverlap && closest.contentEditable != "false")
|
|
3071
3071
|
return domPosAtCoords(closest, clipX, y);
|
|
3072
3072
|
let offset = Array.prototype.indexOf.call(parent.childNodes, closest) +
|
|
3073
3073
|
(x >= (closestRect.left + closestRect.right) / 2 ? 1 : 0);
|
|
@@ -3164,7 +3164,8 @@ function posAtCoords(view, { x, y }, precise, bias = -1) {
|
|
|
3164
3164
|
let range = doc.caretRangeFromPoint(x, y);
|
|
3165
3165
|
if (range) {
|
|
3166
3166
|
({ startContainer: node, startOffset: offset } = range);
|
|
3167
|
-
if (
|
|
3167
|
+
if (!view.contentDOM.contains(node) ||
|
|
3168
|
+
browser.safari && isSuspiciousSafariCaretResult(node, offset, x) ||
|
|
3168
3169
|
browser.chrome && isSuspiciousChromeCaretResult(node, offset, x))
|
|
3169
3170
|
node = undefined;
|
|
3170
3171
|
}
|
|
@@ -5378,6 +5379,7 @@ const baseTheme$1 = buildTheme("." + baseThemeID, {
|
|
|
5378
5379
|
".cm-widgetBuffer": {
|
|
5379
5380
|
verticalAlign: "text-top",
|
|
5380
5381
|
height: "1em",
|
|
5382
|
+
width: 0,
|
|
5381
5383
|
display: "inline"
|
|
5382
5384
|
},
|
|
5383
5385
|
".cm-placeholder": {
|
|
@@ -5487,7 +5489,9 @@ class DOMObserver {
|
|
|
5487
5489
|
this.flushSoon();
|
|
5488
5490
|
};
|
|
5489
5491
|
this.onSelectionChange = this.onSelectionChange.bind(this);
|
|
5490
|
-
|
|
5492
|
+
this.onResize = this.onResize.bind(this);
|
|
5493
|
+
this.onPrint = this.onPrint.bind(this);
|
|
5494
|
+
this.onScroll = this.onScroll.bind(this);
|
|
5491
5495
|
if (typeof ResizeObserver == "function") {
|
|
5492
5496
|
this.resize = new ResizeObserver(() => {
|
|
5493
5497
|
if (this.view.docView.lastUpdate < Date.now() - 75)
|
|
@@ -5495,9 +5499,9 @@ class DOMObserver {
|
|
|
5495
5499
|
});
|
|
5496
5500
|
this.resize.observe(view.scrollDOM);
|
|
5497
5501
|
}
|
|
5498
|
-
|
|
5502
|
+
this.win = view.dom.ownerDocument.defaultView;
|
|
5503
|
+
this.addWindowListeners(this.win);
|
|
5499
5504
|
this.start();
|
|
5500
|
-
window.addEventListener("scroll", this.onScroll = this.onScroll.bind(this));
|
|
5501
5505
|
if (typeof IntersectionObserver == "function") {
|
|
5502
5506
|
this.intersection = new IntersectionObserver(entries => {
|
|
5503
5507
|
if (this.parentCheck < 0)
|
|
@@ -5516,7 +5520,6 @@ class DOMObserver {
|
|
|
5516
5520
|
}
|
|
5517
5521
|
this.listenForScroll();
|
|
5518
5522
|
this.readSelectionRange();
|
|
5519
|
-
this.dom.ownerDocument.addEventListener("selectionchange", this.onSelectionChange);
|
|
5520
5523
|
}
|
|
5521
5524
|
onScroll(e) {
|
|
5522
5525
|
if (this.intersecting)
|
|
@@ -5731,6 +5734,7 @@ class DOMObserver {
|
|
|
5731
5734
|
let newSel = this.selectionChanged && hasSelection(this.dom, this.selectionRange);
|
|
5732
5735
|
if (from < 0 && !newSel)
|
|
5733
5736
|
return;
|
|
5737
|
+
this.view.inputState.lastFocusTime = 0;
|
|
5734
5738
|
this.selectionChanged = false;
|
|
5735
5739
|
let startState = this.view.state;
|
|
5736
5740
|
let handled = this.onChange(from, to, typeOver);
|
|
@@ -5759,6 +5763,25 @@ class DOMObserver {
|
|
|
5759
5763
|
return null;
|
|
5760
5764
|
}
|
|
5761
5765
|
}
|
|
5766
|
+
setWindow(win) {
|
|
5767
|
+
if (win != this.win) {
|
|
5768
|
+
this.removeWindowListeners(this.win);
|
|
5769
|
+
this.win = win;
|
|
5770
|
+
this.addWindowListeners(this.win);
|
|
5771
|
+
}
|
|
5772
|
+
}
|
|
5773
|
+
addWindowListeners(win) {
|
|
5774
|
+
win.addEventListener("resize", this.onResize);
|
|
5775
|
+
win.addEventListener("beforeprint", this.onPrint);
|
|
5776
|
+
win.addEventListener("scroll", this.onScroll);
|
|
5777
|
+
win.document.addEventListener("selectionchange", this.onSelectionChange);
|
|
5778
|
+
}
|
|
5779
|
+
removeWindowListeners(win) {
|
|
5780
|
+
win.removeEventListener("scroll", this.onScroll);
|
|
5781
|
+
win.removeEventListener("resize", this.onResize);
|
|
5782
|
+
win.removeEventListener("beforeprint", this.onPrint);
|
|
5783
|
+
win.document.removeEventListener("selectionchange", this.onSelectionChange);
|
|
5784
|
+
}
|
|
5762
5785
|
destroy() {
|
|
5763
5786
|
var _a, _b, _c;
|
|
5764
5787
|
this.stop();
|
|
@@ -5767,10 +5790,7 @@ class DOMObserver {
|
|
|
5767
5790
|
(_c = this.resize) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
5768
5791
|
for (let dom of this.scrollTargets)
|
|
5769
5792
|
dom.removeEventListener("scroll", this.onScroll);
|
|
5770
|
-
|
|
5771
|
-
window.removeEventListener("resize", this.onResize);
|
|
5772
|
-
window.removeEventListener("beforeprint", this.onPrint);
|
|
5773
|
-
this.dom.ownerDocument.removeEventListener("selectionchange", this.onSelectionChange);
|
|
5793
|
+
this.removeWindowListeners(this.win);
|
|
5774
5794
|
clearTimeout(this.parentCheck);
|
|
5775
5795
|
clearTimeout(this.resizeTimeout);
|
|
5776
5796
|
}
|
|
@@ -6078,7 +6098,7 @@ class EditorView {
|
|
|
6078
6098
|
this.dom.appendChild(this.scrollDOM);
|
|
6079
6099
|
this._dispatch = config.dispatch || ((tr) => this.update([tr]));
|
|
6080
6100
|
this.dispatch = this.dispatch.bind(this);
|
|
6081
|
-
this.
|
|
6101
|
+
this._root = (config.root || getRoot(config.parent) || document);
|
|
6082
6102
|
this.viewState = new ViewState(config.state || state.EditorState.create(config));
|
|
6083
6103
|
this.plugins = this.state.facet(viewPlugin).map(spec => new PluginInstance(spec));
|
|
6084
6104
|
for (let plugin of this.plugins)
|
|
@@ -6139,6 +6159,10 @@ class EditorView {
|
|
|
6139
6159
|
composition there.
|
|
6140
6160
|
*/
|
|
6141
6161
|
get compositionStarted() { return this.inputState.composing >= 0; }
|
|
6162
|
+
/**
|
|
6163
|
+
The document or shadow root that the view lives in.
|
|
6164
|
+
*/
|
|
6165
|
+
get root() { return this._root; }
|
|
6142
6166
|
dispatch(...input) {
|
|
6143
6167
|
this._dispatch(input.length == 1 && input[0] instanceof state.Transaction ? input[0]
|
|
6144
6168
|
: this.state.update(...input));
|
|
@@ -6474,7 +6498,7 @@ class EditorView {
|
|
|
6474
6498
|
/**
|
|
6475
6499
|
Find the text line or block widget at the given vertical
|
|
6476
6500
|
position (which is interpreted as relative to the [top of the
|
|
6477
|
-
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop)
|
|
6501
|
+
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop)).
|
|
6478
6502
|
*/
|
|
6479
6503
|
elementAtHeight(height) {
|
|
6480
6504
|
this.readMeasured();
|
|
@@ -6483,7 +6507,8 @@ class EditorView {
|
|
|
6483
6507
|
/**
|
|
6484
6508
|
Find the line block (see
|
|
6485
6509
|
[`lineBlockAt`](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt) at the given
|
|
6486
|
-
height
|
|
6510
|
+
height, again interpreted relative to the [top of the
|
|
6511
|
+
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop).
|
|
6487
6512
|
*/
|
|
6488
6513
|
lineBlockAtHeight(height) {
|
|
6489
6514
|
this.readMeasured();
|
|
@@ -6690,6 +6715,17 @@ class EditorView {
|
|
|
6690
6715
|
});
|
|
6691
6716
|
}
|
|
6692
6717
|
/**
|
|
6718
|
+
Update the [root](https://codemirror.net/6/docs/ref/##view.EditorViewConfig.root) in which the editor lives. This is only
|
|
6719
|
+
necessary when moving the editor's existing DOM to a new window or shadow root.
|
|
6720
|
+
*/
|
|
6721
|
+
setRoot(root) {
|
|
6722
|
+
if (this._root != root) {
|
|
6723
|
+
this._root = root;
|
|
6724
|
+
this.observer.setWindow((root.nodeType == 9 ? root : root.ownerDocument).defaultView);
|
|
6725
|
+
this.mountStyles();
|
|
6726
|
+
}
|
|
6727
|
+
}
|
|
6728
|
+
/**
|
|
6693
6729
|
Clean up this editor view, removing its element from the
|
|
6694
6730
|
document, unregistering event handlers, and notifying
|
|
6695
6731
|
plugins. The view instance can no longer be used after
|
package/dist/index.d.ts
CHANGED
|
@@ -647,10 +647,11 @@ declare class EditorView {
|
|
|
647
647
|
*/
|
|
648
648
|
get compositionStarted(): boolean;
|
|
649
649
|
private _dispatch;
|
|
650
|
+
private _root;
|
|
650
651
|
/**
|
|
651
652
|
The document or shadow root that the view lives in.
|
|
652
653
|
*/
|
|
653
|
-
|
|
654
|
+
get root(): DocumentOrShadowRoot;
|
|
654
655
|
/**
|
|
655
656
|
The DOM element that wraps the entire editor view.
|
|
656
657
|
*/
|
|
@@ -752,13 +753,14 @@ declare class EditorView {
|
|
|
752
753
|
/**
|
|
753
754
|
Find the text line or block widget at the given vertical
|
|
754
755
|
position (which is interpreted as relative to the [top of the
|
|
755
|
-
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop)
|
|
756
|
+
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop)).
|
|
756
757
|
*/
|
|
757
758
|
elementAtHeight(height: number): BlockInfo;
|
|
758
759
|
/**
|
|
759
760
|
Find the line block (see
|
|
760
761
|
[`lineBlockAt`](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt) at the given
|
|
761
|
-
height
|
|
762
|
+
height, again interpreted relative to the [top of the
|
|
763
|
+
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop).
|
|
762
764
|
*/
|
|
763
765
|
lineBlockAtHeight(height: number): BlockInfo;
|
|
764
766
|
/**
|
|
@@ -921,6 +923,11 @@ declare class EditorView {
|
|
|
921
923
|
*/
|
|
922
924
|
focus(): void;
|
|
923
925
|
/**
|
|
926
|
+
Update the [root](https://codemirror.net/6/docs/ref/##view.EditorViewConfig.root) in which the editor lives. This is only
|
|
927
|
+
necessary when moving the editor's existing DOM to a new window or shadow root.
|
|
928
|
+
*/
|
|
929
|
+
setRoot(root: Document | ShadowRoot): void;
|
|
930
|
+
/**
|
|
924
931
|
Clean up this editor view, removing its element from the
|
|
925
932
|
document, unregistering event handlers, and notifying
|
|
926
933
|
plugins. The view instance can no longer be used after
|
package/dist/index.js
CHANGED
|
@@ -2477,7 +2477,6 @@ class DocView extends ContentView {
|
|
|
2477
2477
|
this.updateDeco();
|
|
2478
2478
|
this.updateInner([new ChangedRange(0, 0, 0, view.state.doc.length)], 0);
|
|
2479
2479
|
}
|
|
2480
|
-
get root() { return this.view.root; }
|
|
2481
2480
|
get editorView() { return this.view; }
|
|
2482
2481
|
get length() { return this.view.state.doc.length; }
|
|
2483
2482
|
// Update the document view to a given state. scrollIntoView can be
|
|
@@ -2600,7 +2599,7 @@ class DocView extends ContentView {
|
|
|
2600
2599
|
this.dom.blur();
|
|
2601
2600
|
this.dom.focus({ preventScroll: true });
|
|
2602
2601
|
}
|
|
2603
|
-
let rawSel = getSelection(this.root);
|
|
2602
|
+
let rawSel = getSelection(this.view.root);
|
|
2604
2603
|
if (!rawSel) ;
|
|
2605
2604
|
else if (main.empty) {
|
|
2606
2605
|
// Work around https://bugzilla.mozilla.org/show_bug.cgi?id=1612076
|
|
@@ -2643,7 +2642,7 @@ class DocView extends ContentView {
|
|
|
2643
2642
|
if (this.compositionDeco.size)
|
|
2644
2643
|
return;
|
|
2645
2644
|
let cursor = this.view.state.selection.main;
|
|
2646
|
-
let sel = getSelection(this.root);
|
|
2645
|
+
let sel = getSelection(this.view.root);
|
|
2647
2646
|
if (!sel || !cursor.empty || !cursor.assoc || !sel.modify)
|
|
2648
2647
|
return;
|
|
2649
2648
|
let line = LineView.find(this, cursor.head);
|
|
@@ -2660,7 +2659,7 @@ class DocView extends ContentView {
|
|
|
2660
2659
|
sel.modify("move", cursor.assoc < 0 ? "forward" : "backward", "lineboundary");
|
|
2661
2660
|
}
|
|
2662
2661
|
mayControlSelection() {
|
|
2663
|
-
let active = this.root.activeElement;
|
|
2662
|
+
let active = this.view.root.activeElement;
|
|
2664
2663
|
return active == this.dom ||
|
|
2665
2664
|
hasSelection(this.dom, this.view.observer.selectionRange) && !(active && this.dom.contains(active));
|
|
2666
2665
|
}
|
|
@@ -3013,7 +3012,7 @@ function upBot(rect, bottom) {
|
|
|
3013
3012
|
return bottom > rect.bottom ? { top: rect.top, left: rect.left, right: rect.right, bottom } : rect;
|
|
3014
3013
|
}
|
|
3015
3014
|
function domPosAtCoords(parent, x, y) {
|
|
3016
|
-
let closest, closestRect, closestX, closestY;
|
|
3015
|
+
let closest, closestRect, closestX, closestY, closestOverlap = false;
|
|
3017
3016
|
let above, below, aboveRect, belowRect;
|
|
3018
3017
|
for (let child = parent.firstChild; child; child = child.nextSibling) {
|
|
3019
3018
|
let rects = clientRectsFor(child);
|
|
@@ -3029,6 +3028,7 @@ function domPosAtCoords(parent, x, y) {
|
|
|
3029
3028
|
closestRect = rect;
|
|
3030
3029
|
closestX = dx;
|
|
3031
3030
|
closestY = dy;
|
|
3031
|
+
closestOverlap = !dx || (dx > 0 ? i < rects.length - 1 : i > 0);
|
|
3032
3032
|
}
|
|
3033
3033
|
if (dx == 0) {
|
|
3034
3034
|
if (y > rect.bottom && (!aboveRect || aboveRect.bottom < rect.bottom)) {
|
|
@@ -3061,7 +3061,7 @@ function domPosAtCoords(parent, x, y) {
|
|
|
3061
3061
|
let clipX = Math.max(closestRect.left, Math.min(closestRect.right, x));
|
|
3062
3062
|
if (closest.nodeType == 3)
|
|
3063
3063
|
return domPosInText(closest, clipX, y);
|
|
3064
|
-
if (
|
|
3064
|
+
if (closestOverlap && closest.contentEditable != "false")
|
|
3065
3065
|
return domPosAtCoords(closest, clipX, y);
|
|
3066
3066
|
let offset = Array.prototype.indexOf.call(parent.childNodes, closest) +
|
|
3067
3067
|
(x >= (closestRect.left + closestRect.right) / 2 ? 1 : 0);
|
|
@@ -3158,7 +3158,8 @@ function posAtCoords(view, { x, y }, precise, bias = -1) {
|
|
|
3158
3158
|
let range = doc.caretRangeFromPoint(x, y);
|
|
3159
3159
|
if (range) {
|
|
3160
3160
|
({ startContainer: node, startOffset: offset } = range);
|
|
3161
|
-
if (
|
|
3161
|
+
if (!view.contentDOM.contains(node) ||
|
|
3162
|
+
browser.safari && isSuspiciousSafariCaretResult(node, offset, x) ||
|
|
3162
3163
|
browser.chrome && isSuspiciousChromeCaretResult(node, offset, x))
|
|
3163
3164
|
node = undefined;
|
|
3164
3165
|
}
|
|
@@ -5371,6 +5372,7 @@ const baseTheme$1 = /*@__PURE__*/buildTheme("." + baseThemeID, {
|
|
|
5371
5372
|
".cm-widgetBuffer": {
|
|
5372
5373
|
verticalAlign: "text-top",
|
|
5373
5374
|
height: "1em",
|
|
5375
|
+
width: 0,
|
|
5374
5376
|
display: "inline"
|
|
5375
5377
|
},
|
|
5376
5378
|
".cm-placeholder": {
|
|
@@ -5480,7 +5482,9 @@ class DOMObserver {
|
|
|
5480
5482
|
this.flushSoon();
|
|
5481
5483
|
};
|
|
5482
5484
|
this.onSelectionChange = this.onSelectionChange.bind(this);
|
|
5483
|
-
|
|
5485
|
+
this.onResize = this.onResize.bind(this);
|
|
5486
|
+
this.onPrint = this.onPrint.bind(this);
|
|
5487
|
+
this.onScroll = this.onScroll.bind(this);
|
|
5484
5488
|
if (typeof ResizeObserver == "function") {
|
|
5485
5489
|
this.resize = new ResizeObserver(() => {
|
|
5486
5490
|
if (this.view.docView.lastUpdate < Date.now() - 75)
|
|
@@ -5488,9 +5492,9 @@ class DOMObserver {
|
|
|
5488
5492
|
});
|
|
5489
5493
|
this.resize.observe(view.scrollDOM);
|
|
5490
5494
|
}
|
|
5491
|
-
|
|
5495
|
+
this.win = view.dom.ownerDocument.defaultView;
|
|
5496
|
+
this.addWindowListeners(this.win);
|
|
5492
5497
|
this.start();
|
|
5493
|
-
window.addEventListener("scroll", this.onScroll = this.onScroll.bind(this));
|
|
5494
5498
|
if (typeof IntersectionObserver == "function") {
|
|
5495
5499
|
this.intersection = new IntersectionObserver(entries => {
|
|
5496
5500
|
if (this.parentCheck < 0)
|
|
@@ -5509,7 +5513,6 @@ class DOMObserver {
|
|
|
5509
5513
|
}
|
|
5510
5514
|
this.listenForScroll();
|
|
5511
5515
|
this.readSelectionRange();
|
|
5512
|
-
this.dom.ownerDocument.addEventListener("selectionchange", this.onSelectionChange);
|
|
5513
5516
|
}
|
|
5514
5517
|
onScroll(e) {
|
|
5515
5518
|
if (this.intersecting)
|
|
@@ -5724,6 +5727,7 @@ class DOMObserver {
|
|
|
5724
5727
|
let newSel = this.selectionChanged && hasSelection(this.dom, this.selectionRange);
|
|
5725
5728
|
if (from < 0 && !newSel)
|
|
5726
5729
|
return;
|
|
5730
|
+
this.view.inputState.lastFocusTime = 0;
|
|
5727
5731
|
this.selectionChanged = false;
|
|
5728
5732
|
let startState = this.view.state;
|
|
5729
5733
|
let handled = this.onChange(from, to, typeOver);
|
|
@@ -5752,6 +5756,25 @@ class DOMObserver {
|
|
|
5752
5756
|
return null;
|
|
5753
5757
|
}
|
|
5754
5758
|
}
|
|
5759
|
+
setWindow(win) {
|
|
5760
|
+
if (win != this.win) {
|
|
5761
|
+
this.removeWindowListeners(this.win);
|
|
5762
|
+
this.win = win;
|
|
5763
|
+
this.addWindowListeners(this.win);
|
|
5764
|
+
}
|
|
5765
|
+
}
|
|
5766
|
+
addWindowListeners(win) {
|
|
5767
|
+
win.addEventListener("resize", this.onResize);
|
|
5768
|
+
win.addEventListener("beforeprint", this.onPrint);
|
|
5769
|
+
win.addEventListener("scroll", this.onScroll);
|
|
5770
|
+
win.document.addEventListener("selectionchange", this.onSelectionChange);
|
|
5771
|
+
}
|
|
5772
|
+
removeWindowListeners(win) {
|
|
5773
|
+
win.removeEventListener("scroll", this.onScroll);
|
|
5774
|
+
win.removeEventListener("resize", this.onResize);
|
|
5775
|
+
win.removeEventListener("beforeprint", this.onPrint);
|
|
5776
|
+
win.document.removeEventListener("selectionchange", this.onSelectionChange);
|
|
5777
|
+
}
|
|
5755
5778
|
destroy() {
|
|
5756
5779
|
var _a, _b, _c;
|
|
5757
5780
|
this.stop();
|
|
@@ -5760,10 +5783,7 @@ class DOMObserver {
|
|
|
5760
5783
|
(_c = this.resize) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
5761
5784
|
for (let dom of this.scrollTargets)
|
|
5762
5785
|
dom.removeEventListener("scroll", this.onScroll);
|
|
5763
|
-
|
|
5764
|
-
window.removeEventListener("resize", this.onResize);
|
|
5765
|
-
window.removeEventListener("beforeprint", this.onPrint);
|
|
5766
|
-
this.dom.ownerDocument.removeEventListener("selectionchange", this.onSelectionChange);
|
|
5786
|
+
this.removeWindowListeners(this.win);
|
|
5767
5787
|
clearTimeout(this.parentCheck);
|
|
5768
5788
|
clearTimeout(this.resizeTimeout);
|
|
5769
5789
|
}
|
|
@@ -6071,7 +6091,7 @@ class EditorView {
|
|
|
6071
6091
|
this.dom.appendChild(this.scrollDOM);
|
|
6072
6092
|
this._dispatch = config.dispatch || ((tr) => this.update([tr]));
|
|
6073
6093
|
this.dispatch = this.dispatch.bind(this);
|
|
6074
|
-
this.
|
|
6094
|
+
this._root = (config.root || getRoot(config.parent) || document);
|
|
6075
6095
|
this.viewState = new ViewState(config.state || EditorState.create(config));
|
|
6076
6096
|
this.plugins = this.state.facet(viewPlugin).map(spec => new PluginInstance(spec));
|
|
6077
6097
|
for (let plugin of this.plugins)
|
|
@@ -6132,6 +6152,10 @@ class EditorView {
|
|
|
6132
6152
|
composition there.
|
|
6133
6153
|
*/
|
|
6134
6154
|
get compositionStarted() { return this.inputState.composing >= 0; }
|
|
6155
|
+
/**
|
|
6156
|
+
The document or shadow root that the view lives in.
|
|
6157
|
+
*/
|
|
6158
|
+
get root() { return this._root; }
|
|
6135
6159
|
dispatch(...input) {
|
|
6136
6160
|
this._dispatch(input.length == 1 && input[0] instanceof Transaction ? input[0]
|
|
6137
6161
|
: this.state.update(...input));
|
|
@@ -6467,7 +6491,7 @@ class EditorView {
|
|
|
6467
6491
|
/**
|
|
6468
6492
|
Find the text line or block widget at the given vertical
|
|
6469
6493
|
position (which is interpreted as relative to the [top of the
|
|
6470
|
-
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop)
|
|
6494
|
+
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop)).
|
|
6471
6495
|
*/
|
|
6472
6496
|
elementAtHeight(height) {
|
|
6473
6497
|
this.readMeasured();
|
|
@@ -6476,7 +6500,8 @@ class EditorView {
|
|
|
6476
6500
|
/**
|
|
6477
6501
|
Find the line block (see
|
|
6478
6502
|
[`lineBlockAt`](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt) at the given
|
|
6479
|
-
height
|
|
6503
|
+
height, again interpreted relative to the [top of the
|
|
6504
|
+
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop).
|
|
6480
6505
|
*/
|
|
6481
6506
|
lineBlockAtHeight(height) {
|
|
6482
6507
|
this.readMeasured();
|
|
@@ -6683,6 +6708,17 @@ class EditorView {
|
|
|
6683
6708
|
});
|
|
6684
6709
|
}
|
|
6685
6710
|
/**
|
|
6711
|
+
Update the [root](https://codemirror.net/6/docs/ref/##view.EditorViewConfig.root) in which the editor lives. This is only
|
|
6712
|
+
necessary when moving the editor's existing DOM to a new window or shadow root.
|
|
6713
|
+
*/
|
|
6714
|
+
setRoot(root) {
|
|
6715
|
+
if (this._root != root) {
|
|
6716
|
+
this._root = root;
|
|
6717
|
+
this.observer.setWindow((root.nodeType == 9 ? root : root.ownerDocument).defaultView);
|
|
6718
|
+
this.mountStyles();
|
|
6719
|
+
}
|
|
6720
|
+
}
|
|
6721
|
+
/**
|
|
6686
6722
|
Clean up this editor view, removing its element from the
|
|
6687
6723
|
document, unregistering event handlers, and notifying
|
|
6688
6724
|
plugins. The view instance can no longer be used after
|