prosemirror-view 1.28.2 → 1.29.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 +20 -2
- package/README.md +1 -1
- package/dist/index.cjs +151 -77
- package/dist/index.d.ts +6 -6
- package/dist/index.js +128 -78
- package/package.json +1 -1
- package/src/capturekeys.ts +9 -8
- package/src/clipboard.ts +12 -8
- package/src/dom.ts +14 -8
- package/src/domchange.ts +2 -2
- package/src/domcoords.ts +8 -5
- package/src/domobserver.ts +47 -11
- package/src/index.ts +18 -11
- package/src/input.ts +4 -4
- package/src/selection.ts +6 -6
- package/src/viewdesc.ts +6 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## 1.29.0 (2022-10-12)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix an issue where HTML comments added to the clipboard by the OS throw off the clipboard parser.
|
|
6
|
+
|
|
7
|
+
Make sure Chrome Android's native behavior on pressing Enter in an empty nested list item is replaced by the result of the editor's Enter key handler.
|
|
8
|
+
|
|
9
|
+
### New features
|
|
10
|
+
|
|
11
|
+
The `transformPastedHTML`, `transformPastedText`, `transformPasted`, `transformCopied`, and `clipboardTextSerializer` props are now passed the view instance as last argument.
|
|
12
|
+
|
|
13
|
+
## 1.28.3 (2022-10-05)
|
|
14
|
+
|
|
15
|
+
### Bug fixes
|
|
16
|
+
|
|
17
|
+
Work around the five-year-old Safari bug where it won't accurately report the selection inside shadow roots, which would break ProseMirror when put in shadow DOM.
|
|
18
|
+
|
|
1
19
|
## 1.28.2 (2022-09-24)
|
|
2
20
|
|
|
3
21
|
### Bug fixes
|
|
@@ -14,11 +32,11 @@ Fix an issue where the editor would reset its scroll position to the top of the
|
|
|
14
32
|
|
|
15
33
|
### Bug fixes
|
|
16
34
|
|
|
17
|
-
Fix an issue where the editor wouldn't realize it was focused on IE when IE's resize controls are on an element inside the content.
|
|
35
|
+
Fix an issue where the editor wouldn't realize it was focused on IE when IE's resize controls are on an element inside the content.
|
|
18
36
|
|
|
19
37
|
### New features
|
|
20
38
|
|
|
21
|
-
The new `transformCopied` prop can be used to transform a copied/cut slice before it is serialized to the clipboard.
|
|
39
|
+
The new `transformCopied` prop can be used to transform a copied/cut slice before it is serialized to the clipboard.
|
|
22
40
|
|
|
23
41
|
## 1.27.2 (2022-08-19)
|
|
24
42
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# prosemirror-view
|
|
2
2
|
|
|
3
|
-
[ [**WEBSITE**](https://prosemirror.net) | [**ISSUES**](https://github.com/prosemirror/prosemirror/issues) | [**FORUM**](https://discuss.prosemirror.net) | [**
|
|
3
|
+
[ [**WEBSITE**](https://prosemirror.net) | [**ISSUES**](https://github.com/prosemirror/prosemirror/issues) | [**FORUM**](https://discuss.prosemirror.net) | [**CHANGELOG**](https://github.com/ProseMirror/prosemirror-view/blob/master/CHANGELOG.md) ]
|
|
4
4
|
|
|
5
5
|
This is a [core module](https://prosemirror.net/docs/ref/#view) of [ProseMirror](https://prosemirror.net).
|
|
6
6
|
ProseMirror is a well-behaved rich semantic content editor based on
|
package/dist/index.cjs
CHANGED
|
@@ -36,28 +36,6 @@ var prosemirrorModel = require('prosemirror-model');
|
|
|
36
36
|
|
|
37
37
|
var prosemirrorTransform = require('prosemirror-transform');
|
|
38
38
|
|
|
39
|
-
var nav = typeof navigator != "undefined" ? navigator : null;
|
|
40
|
-
var doc = typeof document != "undefined" ? document : null;
|
|
41
|
-
var agent = nav && nav.userAgent || "";
|
|
42
|
-
var ie_edge = /Edge\/(\d+)/.exec(agent);
|
|
43
|
-
var ie_upto10 = /MSIE \d/.exec(agent);
|
|
44
|
-
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent);
|
|
45
|
-
var ie = !!(ie_upto10 || ie_11up || ie_edge);
|
|
46
|
-
var ie_version = ie_upto10 ? document.documentMode : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0;
|
|
47
|
-
var gecko = !ie && /gecko\/(\d+)/i.test(agent);
|
|
48
|
-
gecko && +(/Firefox\/(\d+)/.exec(agent) || [0, 0])[1];
|
|
49
|
-
|
|
50
|
-
var _chrome = !ie && /Chrome\/(\d+)/.exec(agent);
|
|
51
|
-
|
|
52
|
-
var chrome = !!_chrome;
|
|
53
|
-
var chrome_version = _chrome ? +_chrome[1] : 0;
|
|
54
|
-
var safari = !ie && !!nav && /Apple Computer/.test(nav.vendor);
|
|
55
|
-
var ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2);
|
|
56
|
-
var mac = ios || (nav ? /Mac/.test(nav.platform) : false);
|
|
57
|
-
var android = /Android \d/.test(agent);
|
|
58
|
-
var webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style;
|
|
59
|
-
var webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0;
|
|
60
|
-
|
|
61
39
|
var domIndex = function domIndex(node) {
|
|
62
40
|
for (var index = 0;; index++) {
|
|
63
41
|
node = node.previousSibling;
|
|
@@ -130,9 +108,7 @@ function hasBlockDesc(dom) {
|
|
|
130
108
|
}
|
|
131
109
|
|
|
132
110
|
var selectionCollapsed = function selectionCollapsed(domSel) {
|
|
133
|
-
|
|
134
|
-
if (collapsed && chrome && domSel.rangeCount && !domSel.getRangeAt(0).collapsed) collapsed = false;
|
|
135
|
-
return collapsed;
|
|
111
|
+
return domSel.focusNode && isEquivalentPosition(domSel.focusNode, domSel.focusOffset, domSel.anchorNode, domSel.anchorOffset);
|
|
136
112
|
};
|
|
137
113
|
|
|
138
114
|
function keyEvent(keyCode, key) {
|
|
@@ -143,6 +119,38 @@ function keyEvent(keyCode, key) {
|
|
|
143
119
|
return event;
|
|
144
120
|
}
|
|
145
121
|
|
|
122
|
+
function deepActiveElement(doc) {
|
|
123
|
+
var elt = doc.activeElement;
|
|
124
|
+
|
|
125
|
+
while (elt && elt.shadowRoot) {
|
|
126
|
+
elt = elt.shadowRoot.activeElement;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return elt;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
var nav = typeof navigator != "undefined" ? navigator : null;
|
|
133
|
+
var doc = typeof document != "undefined" ? document : null;
|
|
134
|
+
var agent = nav && nav.userAgent || "";
|
|
135
|
+
var ie_edge = /Edge\/(\d+)/.exec(agent);
|
|
136
|
+
var ie_upto10 = /MSIE \d/.exec(agent);
|
|
137
|
+
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent);
|
|
138
|
+
var ie = !!(ie_upto10 || ie_11up || ie_edge);
|
|
139
|
+
var ie_version = ie_upto10 ? document.documentMode : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0;
|
|
140
|
+
var gecko = !ie && /gecko\/(\d+)/i.test(agent);
|
|
141
|
+
gecko && +(/Firefox\/(\d+)/.exec(agent) || [0, 0])[1];
|
|
142
|
+
|
|
143
|
+
var _chrome = !ie && /Chrome\/(\d+)/.exec(agent);
|
|
144
|
+
|
|
145
|
+
var chrome = !!_chrome;
|
|
146
|
+
var chrome_version = _chrome ? +_chrome[1] : 0;
|
|
147
|
+
var safari = !ie && !!nav && /Apple Computer/.test(nav.vendor);
|
|
148
|
+
var ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2);
|
|
149
|
+
var mac = ios || (nav ? /Mac/.test(nav.platform) : false);
|
|
150
|
+
var android = /Android \d/.test(agent);
|
|
151
|
+
var webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style;
|
|
152
|
+
var webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0;
|
|
153
|
+
|
|
146
154
|
function windowRect(doc) {
|
|
147
155
|
return {
|
|
148
156
|
left: 0,
|
|
@@ -654,15 +662,27 @@ function endOfTextblockHorizontal(view, state, dir) {
|
|
|
654
662
|
var sel = view.domSelection();
|
|
655
663
|
if (!maybeRTL.test($head.parent.textContent) || !sel.modify) return dir == "left" || dir == "backward" ? atStart : atEnd;
|
|
656
664
|
return withFlushedState(view, state, function () {
|
|
657
|
-
var
|
|
658
|
-
oldNode =
|
|
659
|
-
oldOff =
|
|
665
|
+
var _view$domSelectionRan = view.domSelectionRange(),
|
|
666
|
+
oldNode = _view$domSelectionRan.focusNode,
|
|
667
|
+
oldOff = _view$domSelectionRan.focusOffset,
|
|
668
|
+
anchorNode = _view$domSelectionRan.anchorNode,
|
|
669
|
+
anchorOffset = _view$domSelectionRan.anchorOffset;
|
|
670
|
+
|
|
660
671
|
var oldBidiLevel = sel.caretBidiLevel;
|
|
661
672
|
sel.modify("move", dir, "character");
|
|
662
673
|
var parentDOM = $head.depth ? view.docView.domAfterPos($head.before()) : view.dom;
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
674
|
+
|
|
675
|
+
var _view$domSelectionRan2 = view.domSelectionRange(),
|
|
676
|
+
newNode = _view$domSelectionRan2.focusNode,
|
|
677
|
+
newOff = _view$domSelectionRan2.focusOffset;
|
|
678
|
+
|
|
679
|
+
var result = newNode && !parentDOM.contains(newNode.nodeType == 1 ? newNode : newNode.parentNode) || oldNode == newNode && oldOff == newOff;
|
|
680
|
+
|
|
681
|
+
try {
|
|
682
|
+
sel.collapse(anchorNode, anchorOffset);
|
|
683
|
+
if (oldNode && (oldNode != anchorNode || oldOff != anchorOffset) && sel.extend) sel.extend(oldNode, oldOff);
|
|
684
|
+
} catch (_) {}
|
|
685
|
+
|
|
666
686
|
if (oldBidiLevel != null) sel.caretBidiLevel = oldBidiLevel;
|
|
667
687
|
return result;
|
|
668
688
|
});
|
|
@@ -1102,16 +1122,9 @@ var ViewDesc = function () {
|
|
|
1102
1122
|
domSel.collapse(anchorDOM.node, anchorDOM.offset);
|
|
1103
1123
|
|
|
1104
1124
|
try {
|
|
1105
|
-
if (anchor != head)
|
|
1106
|
-
try {
|
|
1107
|
-
domSel.extend(headDOM.node, headDOM.offset);
|
|
1108
|
-
} catch (_) {}
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1125
|
+
if (anchor != head) domSel.extend(headDOM.node, headDOM.offset);
|
|
1111
1126
|
domSelExtended = true;
|
|
1112
|
-
} catch (
|
|
1113
|
-
if (!(err instanceof DOMException)) throw err;
|
|
1114
|
-
}
|
|
1127
|
+
} catch (_) {}
|
|
1115
1128
|
}
|
|
1116
1129
|
|
|
1117
1130
|
if (!domSelExtended) {
|
|
@@ -1496,7 +1509,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1496
1509
|
from = _view$state$selection.from,
|
|
1497
1510
|
to = _view$state$selection.to;
|
|
1498
1511
|
if (!(view.state.selection instanceof prosemirrorState.TextSelection) || from < pos || to > pos + this.node.content.size) return null;
|
|
1499
|
-
var sel = view.
|
|
1512
|
+
var sel = view.domSelectionRange();
|
|
1500
1513
|
var textNode = nearbyTextNode(sel.focusNode, sel.focusOffset);
|
|
1501
1514
|
if (!textNode || !this.dom.contains(textNode.parentNode)) return null;
|
|
1502
1515
|
|
|
@@ -2406,7 +2419,7 @@ function replaceNodes(nodes, from, to, view, replacement) {
|
|
|
2406
2419
|
|
|
2407
2420
|
function selectionFromDOM(view) {
|
|
2408
2421
|
var origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
2409
|
-
var domSel = view.
|
|
2422
|
+
var domSel = view.domSelectionRange(),
|
|
2410
2423
|
doc = view.state.doc;
|
|
2411
2424
|
if (!domSel.focusNode) return null;
|
|
2412
2425
|
var nearestDesc = view.docView.nearestDesc(domSel.focusNode),
|
|
@@ -2455,7 +2468,7 @@ function selectionToDOM(view) {
|
|
|
2455
2468
|
if (!editorOwnsSelection(view)) return;
|
|
2456
2469
|
|
|
2457
2470
|
if (!force && view.input.mouseDown && view.input.mouseDown.allowDefault && chrome) {
|
|
2458
|
-
var domSel = view.
|
|
2471
|
+
var domSel = view.domSelectionRange(),
|
|
2459
2472
|
curSel = view.domObserver.currentSelection;
|
|
2460
2473
|
|
|
2461
2474
|
if (domSel.anchorNode && curSel.anchorNode && isEquivalentPosition(domSel.anchorNode, domSel.anchorOffset, curSel.anchorNode, curSel.anchorOffset)) {
|
|
@@ -2538,7 +2551,7 @@ function resetEditable(element) {
|
|
|
2538
2551
|
function removeClassOnSelectionChange(view) {
|
|
2539
2552
|
var doc = view.dom.ownerDocument;
|
|
2540
2553
|
doc.removeEventListener("selectionchange", view.input.hideSelectionGuard);
|
|
2541
|
-
var domSel = view.
|
|
2554
|
+
var domSel = view.domSelectionRange();
|
|
2542
2555
|
var node = domSel.anchorNode,
|
|
2543
2556
|
offset = domSel.anchorOffset;
|
|
2544
2557
|
doc.addEventListener("selectionchange", view.input.hideSelectionGuard = function () {
|
|
@@ -2600,7 +2613,7 @@ function hasFocusAndSelection(view) {
|
|
|
2600
2613
|
}
|
|
2601
2614
|
|
|
2602
2615
|
function hasSelection(view) {
|
|
2603
|
-
var sel = view.
|
|
2616
|
+
var sel = view.domSelectionRange();
|
|
2604
2617
|
if (!sel.anchorNode) return false;
|
|
2605
2618
|
|
|
2606
2619
|
try {
|
|
@@ -2612,7 +2625,7 @@ function hasSelection(view) {
|
|
|
2612
2625
|
|
|
2613
2626
|
function anchorInRightPlace(view) {
|
|
2614
2627
|
var anchorDOM = view.docView.domFromPos(view.state.selection.anchor, 0);
|
|
2615
|
-
var domSel = view.
|
|
2628
|
+
var domSel = view.domSelectionRange();
|
|
2616
2629
|
return isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset);
|
|
2617
2630
|
}
|
|
2618
2631
|
|
|
@@ -2676,7 +2689,7 @@ function isIgnorable(dom) {
|
|
|
2676
2689
|
}
|
|
2677
2690
|
|
|
2678
2691
|
function skipIgnoredNodesLeft(view) {
|
|
2679
|
-
var sel = view.
|
|
2692
|
+
var sel = view.domSelectionRange();
|
|
2680
2693
|
var node = sel.focusNode,
|
|
2681
2694
|
offset = sel.focusOffset;
|
|
2682
2695
|
if (!node) return;
|
|
@@ -2722,11 +2735,11 @@ function skipIgnoredNodesLeft(view) {
|
|
|
2722
2735
|
}
|
|
2723
2736
|
}
|
|
2724
2737
|
|
|
2725
|
-
if (force) setSelFocus(view,
|
|
2738
|
+
if (force) setSelFocus(view, node, offset);else if (moveNode) setSelFocus(view, moveNode, moveOffset);
|
|
2726
2739
|
}
|
|
2727
2740
|
|
|
2728
2741
|
function skipIgnoredNodesRight(view) {
|
|
2729
|
-
var sel = view.
|
|
2742
|
+
var sel = view.domSelectionRange();
|
|
2730
2743
|
var node = sel.focusNode,
|
|
2731
2744
|
offset = sel.focusOffset;
|
|
2732
2745
|
if (!node) return;
|
|
@@ -2765,7 +2778,7 @@ function skipIgnoredNodesRight(view) {
|
|
|
2765
2778
|
}
|
|
2766
2779
|
}
|
|
2767
2780
|
|
|
2768
|
-
if (moveNode) setSelFocus(view,
|
|
2781
|
+
if (moveNode) setSelFocus(view, moveNode, moveOffset);
|
|
2769
2782
|
}
|
|
2770
2783
|
|
|
2771
2784
|
function isBlockNode(dom) {
|
|
@@ -2773,7 +2786,9 @@ function isBlockNode(dom) {
|
|
|
2773
2786
|
return desc && desc.node && desc.node.isBlock;
|
|
2774
2787
|
}
|
|
2775
2788
|
|
|
2776
|
-
function setSelFocus(view,
|
|
2789
|
+
function setSelFocus(view, node, offset) {
|
|
2790
|
+
var sel = view.domSelection();
|
|
2791
|
+
|
|
2777
2792
|
if (selectionCollapsed(sel)) {
|
|
2778
2793
|
var range = document.createRange();
|
|
2779
2794
|
range.setEnd(node, offset);
|
|
@@ -2842,9 +2857,9 @@ function switchEditable(view, node, state) {
|
|
|
2842
2857
|
function safariDownArrowBug(view) {
|
|
2843
2858
|
if (!safari || view.state.selection.$head.parentOffset > 0) return false;
|
|
2844
2859
|
|
|
2845
|
-
var _view$
|
|
2846
|
-
focusNode = _view$
|
|
2847
|
-
focusOffset = _view$
|
|
2860
|
+
var _view$domSelectionRan3 = view.domSelectionRange(),
|
|
2861
|
+
focusNode = _view$domSelectionRan3.focusNode,
|
|
2862
|
+
focusOffset = _view$domSelectionRan3.focusOffset;
|
|
2848
2863
|
|
|
2849
2864
|
if (focusNode && focusNode.nodeType == 1 && focusOffset == 0 && focusNode.firstChild && focusNode.firstChild.contentEditable == "false") {
|
|
2850
2865
|
var child = focusNode.firstChild;
|
|
@@ -2893,7 +2908,7 @@ function captureKeyDown(view, event) {
|
|
|
2893
2908
|
|
|
2894
2909
|
function serializeForClipboard(view, slice) {
|
|
2895
2910
|
view.someProp("transformCopied", function (f) {
|
|
2896
|
-
slice = f(slice);
|
|
2911
|
+
slice = f(slice, view);
|
|
2897
2912
|
});
|
|
2898
2913
|
var context = [],
|
|
2899
2914
|
_slice = slice,
|
|
@@ -2936,7 +2951,7 @@ function serializeForClipboard(view, slice) {
|
|
|
2936
2951
|
|
|
2937
2952
|
if (firstChild && firstChild.nodeType == 1) firstChild.setAttribute("data-pm-slice", "".concat(openStart, " ").concat(openEnd).concat(wrappers ? " -".concat(wrappers) : "", " ").concat(JSON.stringify(context)));
|
|
2938
2953
|
var text = view.someProp("clipboardTextSerializer", function (f) {
|
|
2939
|
-
return f(slice);
|
|
2954
|
+
return f(slice, view);
|
|
2940
2955
|
}) || slice.content.textBetween(0, slice.content.size, "\n\n");
|
|
2941
2956
|
return {
|
|
2942
2957
|
dom: wrap,
|
|
@@ -2952,11 +2967,11 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2952
2967
|
|
|
2953
2968
|
if (asText) {
|
|
2954
2969
|
view.someProp("transformPastedText", function (f) {
|
|
2955
|
-
text = f(text, inCode || plainText);
|
|
2970
|
+
text = f(text, inCode || plainText, view);
|
|
2956
2971
|
});
|
|
2957
2972
|
if (inCode) return text ? new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0) : prosemirrorModel.Slice.empty;
|
|
2958
2973
|
var parsed = view.someProp("clipboardTextParser", function (f) {
|
|
2959
|
-
return f(text, $context, plainText);
|
|
2974
|
+
return f(text, $context, plainText, view);
|
|
2960
2975
|
});
|
|
2961
2976
|
|
|
2962
2977
|
if (parsed) {
|
|
@@ -2973,7 +2988,7 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2973
2988
|
}
|
|
2974
2989
|
} else {
|
|
2975
2990
|
view.someProp("transformPastedHTML", function (f) {
|
|
2976
|
-
html = f(html);
|
|
2991
|
+
html = f(html, view);
|
|
2977
2992
|
});
|
|
2978
2993
|
dom = readHTML(html);
|
|
2979
2994
|
if (webkit) restoreReplacedSpaces(dom);
|
|
@@ -2981,8 +2996,15 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2981
2996
|
|
|
2982
2997
|
var contextNode = dom && dom.querySelector("[data-pm-slice]");
|
|
2983
2998
|
var sliceData = contextNode && /^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(contextNode.getAttribute("data-pm-slice") || "");
|
|
2984
|
-
if (sliceData && sliceData[3]) for (var i = +sliceData[3]; i > 0
|
|
2985
|
-
|
|
2999
|
+
if (sliceData && sliceData[3]) for (var i = +sliceData[3]; i > 0; i--) {
|
|
3000
|
+
var child = dom.firstChild;
|
|
3001
|
+
|
|
3002
|
+
while (child && child.nodeType != 1) {
|
|
3003
|
+
child = child.nextSibling;
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
if (!child) break;
|
|
3007
|
+
dom = child;
|
|
2986
3008
|
}
|
|
2987
3009
|
|
|
2988
3010
|
if (!slice) {
|
|
@@ -3017,7 +3039,7 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
3017
3039
|
}
|
|
3018
3040
|
|
|
3019
3041
|
view.someProp("transformPasted", function (f) {
|
|
3020
|
-
slice = f(slice);
|
|
3042
|
+
slice = f(slice, view);
|
|
3021
3043
|
});
|
|
3022
3044
|
return slice;
|
|
3023
3045
|
}
|
|
@@ -3639,14 +3661,14 @@ editHandlers.compositionstart = editHandlers.compositionupdate = function (view)
|
|
|
3639
3661
|
endComposition(view);
|
|
3640
3662
|
|
|
3641
3663
|
if (gecko && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) {
|
|
3642
|
-
var sel = view.
|
|
3664
|
+
var sel = view.domSelectionRange();
|
|
3643
3665
|
|
|
3644
3666
|
for (var node = sel.focusNode, offset = sel.focusOffset; node && node.nodeType == 1 && offset != 0;) {
|
|
3645
3667
|
var before = offset < 0 ? node.lastChild : node.childNodes[offset - 1];
|
|
3646
3668
|
if (!before) break;
|
|
3647
3669
|
|
|
3648
3670
|
if (before.nodeType == 3) {
|
|
3649
|
-
|
|
3671
|
+
view.domSelection().collapse(before, before.nodeValue.length);
|
|
3650
3672
|
break;
|
|
3651
3673
|
} else {
|
|
3652
3674
|
node = before;
|
|
@@ -3847,7 +3869,7 @@ editHandlers.drop = function (view, _event) {
|
|
|
3847
3869
|
|
|
3848
3870
|
if (slice) {
|
|
3849
3871
|
view.someProp("transformPasted", function (f) {
|
|
3850
|
-
slice = f(slice);
|
|
3872
|
+
slice = f(slice, view);
|
|
3851
3873
|
});
|
|
3852
3874
|
} else {
|
|
3853
3875
|
slice = parseFromClipboard(view, event.dataTransfer.getData(brokenClipboardAPI ? "Text" : "text/plain"), brokenClipboardAPI ? null : event.dataTransfer.getData("text/html"), false, $mouse);
|
|
@@ -3898,7 +3920,7 @@ handlers.focus = function (view) {
|
|
|
3898
3920
|
view.domObserver.start();
|
|
3899
3921
|
view.focused = true;
|
|
3900
3922
|
setTimeout(function () {
|
|
3901
|
-
if (view.docView && view.hasFocus() && !view.domObserver.currentSelection.eq(view.
|
|
3923
|
+
if (view.docView && view.hasFocus() && !view.domObserver.currentSelection.eq(view.domSelectionRange())) selectionToDOM(view);
|
|
3902
3924
|
}, 20);
|
|
3903
3925
|
}
|
|
3904
3926
|
};
|
|
@@ -4826,7 +4848,7 @@ var DOMObserver = function () {
|
|
|
4826
4848
|
if (this.suppressingSelectionUpdates) return selectionToDOM(this.view);
|
|
4827
4849
|
|
|
4828
4850
|
if (ie && ie_version <= 11 && !this.view.state.selection.empty) {
|
|
4829
|
-
var sel = this.view.
|
|
4851
|
+
var sel = this.view.domSelectionRange();
|
|
4830
4852
|
if (sel.focusNode && isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset)) return this.flushSoon();
|
|
4831
4853
|
}
|
|
4832
4854
|
|
|
@@ -4835,14 +4857,27 @@ var DOMObserver = function () {
|
|
|
4835
4857
|
}, {
|
|
4836
4858
|
key: "setCurSelection",
|
|
4837
4859
|
value: function setCurSelection() {
|
|
4838
|
-
this.currentSelection.set(this.view.
|
|
4860
|
+
this.currentSelection.set(this.view.domSelectionRange());
|
|
4839
4861
|
}
|
|
4840
4862
|
}, {
|
|
4841
4863
|
key: "ignoreSelectionChange",
|
|
4842
4864
|
value: function ignoreSelectionChange(sel) {
|
|
4843
|
-
if (sel.
|
|
4844
|
-
var
|
|
4845
|
-
|
|
4865
|
+
if (!sel.focusNode) return true;
|
|
4866
|
+
var ancestors = new Set(),
|
|
4867
|
+
container;
|
|
4868
|
+
|
|
4869
|
+
for (var scan = sel.focusNode; scan; scan = parentNode(scan)) {
|
|
4870
|
+
ancestors.add(scan);
|
|
4871
|
+
}
|
|
4872
|
+
|
|
4873
|
+
for (var _scan = sel.anchorNode; _scan; _scan = parentNode(_scan)) {
|
|
4874
|
+
if (ancestors.has(_scan)) {
|
|
4875
|
+
container = _scan;
|
|
4876
|
+
break;
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
|
|
4880
|
+
var desc = container && this.view.docView.nearestDesc(container);
|
|
4846
4881
|
|
|
4847
4882
|
if (desc && desc.ignoreMutation({
|
|
4848
4883
|
type: "selection",
|
|
@@ -4864,7 +4899,7 @@ var DOMObserver = function () {
|
|
|
4864
4899
|
this.queue.length = 0;
|
|
4865
4900
|
}
|
|
4866
4901
|
|
|
4867
|
-
var sel = view.
|
|
4902
|
+
var sel = view.domSelectionRange();
|
|
4868
4903
|
var newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(view) && !this.ignoreSelectionChange(sel);
|
|
4869
4904
|
var from = -1,
|
|
4870
4905
|
to = -1,
|
|
@@ -4984,6 +5019,40 @@ function checkCSS(view) {
|
|
|
4984
5019
|
}
|
|
4985
5020
|
}
|
|
4986
5021
|
|
|
5022
|
+
function safariShadowSelectionRange(view) {
|
|
5023
|
+
var found;
|
|
5024
|
+
|
|
5025
|
+
function read(event) {
|
|
5026
|
+
event.preventDefault();
|
|
5027
|
+
event.stopImmediatePropagation();
|
|
5028
|
+
found = event.getTargetRanges()[0];
|
|
5029
|
+
}
|
|
5030
|
+
|
|
5031
|
+
view.dom.addEventListener("beforeinput", read, true);
|
|
5032
|
+
document.execCommand("indent");
|
|
5033
|
+
view.dom.removeEventListener("beforeinput", read, true);
|
|
5034
|
+
var anchorNode = found.startContainer,
|
|
5035
|
+
anchorOffset = found.startOffset;
|
|
5036
|
+
var focusNode = found.endContainer,
|
|
5037
|
+
focusOffset = found.endOffset;
|
|
5038
|
+
var currentAnchor = view.domAtPos(view.state.selection.anchor);
|
|
5039
|
+
|
|
5040
|
+
if (isEquivalentPosition(currentAnchor.node, currentAnchor.offset, focusNode, focusOffset)) {
|
|
5041
|
+
var _ref3 = [focusNode, focusOffset, anchorNode, anchorOffset];
|
|
5042
|
+
anchorNode = _ref3[0];
|
|
5043
|
+
anchorOffset = _ref3[1];
|
|
5044
|
+
focusNode = _ref3[2];
|
|
5045
|
+
focusOffset = _ref3[3];
|
|
5046
|
+
}
|
|
5047
|
+
|
|
5048
|
+
return {
|
|
5049
|
+
anchorNode: anchorNode,
|
|
5050
|
+
anchorOffset: anchorOffset,
|
|
5051
|
+
focusNode: focusNode,
|
|
5052
|
+
focusOffset: focusOffset
|
|
5053
|
+
};
|
|
5054
|
+
}
|
|
5055
|
+
|
|
4987
5056
|
function parseBetween(view, from_, to_) {
|
|
4988
5057
|
var _view$docView$parseRa = view.docView.parseRange(from_, to_),
|
|
4989
5058
|
parent = _view$docView$parseRa.node,
|
|
@@ -4992,7 +5061,7 @@ function parseBetween(view, from_, to_) {
|
|
|
4992
5061
|
from = _view$docView$parseRa.from,
|
|
4993
5062
|
to = _view$docView$parseRa.to;
|
|
4994
5063
|
|
|
4995
|
-
var domSel = view.
|
|
5064
|
+
var domSel = view.domSelectionRange();
|
|
4996
5065
|
var find;
|
|
4997
5066
|
var anchor = domSel.anchorNode;
|
|
4998
5067
|
|
|
@@ -5118,7 +5187,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
5118
5187
|
var change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
|
|
5119
5188
|
|
|
5120
5189
|
if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some(function (n) {
|
|
5121
|
-
return n.nodeName == "DIV" || n.nodeName == "P";
|
|
5190
|
+
return n.nodeName == "DIV" || n.nodeName == "P" || n.nodeName == "LI";
|
|
5122
5191
|
}) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", function (f) {
|
|
5123
5192
|
return f(view, keyEvent(13, "Enter"));
|
|
5124
5193
|
})) {
|
|
@@ -5502,7 +5571,7 @@ var EditorView = function () {
|
|
|
5502
5571
|
var forceSelUpdate = updateDoc && (ie || chrome) && !this.composing && !prev.selection.empty && !state.selection.empty && selectionContextChanged(prev.selection, state.selection);
|
|
5503
5572
|
|
|
5504
5573
|
if (updateDoc) {
|
|
5505
|
-
var chromeKludge = chrome ? this.trackWrites = this.
|
|
5574
|
+
var chromeKludge = chrome ? this.trackWrites = this.domSelectionRange().focusNode : null;
|
|
5506
5575
|
|
|
5507
5576
|
if (redraw || !this.docView.update(state.doc, outerDeco, innerDeco, this)) {
|
|
5508
5577
|
this.docView.updateOuterDeco([]);
|
|
@@ -5513,7 +5582,7 @@ var EditorView = function () {
|
|
|
5513
5582
|
if (chromeKludge && !this.trackWrites) forceSelUpdate = true;
|
|
5514
5583
|
}
|
|
5515
5584
|
|
|
5516
|
-
if (forceSelUpdate || !(this.input.mouseDown && this.domObserver.currentSelection.eq(this.
|
|
5585
|
+
if (forceSelUpdate || !(this.input.mouseDown && this.domObserver.currentSelection.eq(this.domSelectionRange()) && anchorInRightPlace(this))) {
|
|
5517
5586
|
selectionToDOM(this, forceSelUpdate);
|
|
5518
5587
|
} else {
|
|
5519
5588
|
syncNodeSelection(this, state.selection);
|
|
@@ -5538,7 +5607,7 @@ var EditorView = function () {
|
|
|
5538
5607
|
value: function scrollToSelection() {
|
|
5539
5608
|
var _this16 = this;
|
|
5540
5609
|
|
|
5541
|
-
var startDOM = this.
|
|
5610
|
+
var startDOM = this.domSelectionRange().focusNode;
|
|
5542
5611
|
if (this.someProp("handleScrollToSelection", function (f) {
|
|
5543
5612
|
return f(_this16);
|
|
5544
5613
|
})) ;else if (this.state.selection instanceof prosemirrorState.NodeSelection) {
|
|
@@ -5721,6 +5790,11 @@ var EditorView = function () {
|
|
|
5721
5790
|
var dispatchTransaction = this._props.dispatchTransaction;
|
|
5722
5791
|
if (dispatchTransaction) dispatchTransaction.call(this, tr);else this.updateState(this.state.apply(tr));
|
|
5723
5792
|
}
|
|
5793
|
+
}, {
|
|
5794
|
+
key: "domSelectionRange",
|
|
5795
|
+
value: function domSelectionRange() {
|
|
5796
|
+
return safari && this.root.nodeType === 11 && deepActiveElement(this.dom.ownerDocument) == this.dom ? safariShadowSelectionRange(this) : this.domSelection();
|
|
5797
|
+
}
|
|
5724
5798
|
}, {
|
|
5725
5799
|
key: "domSelection",
|
|
5726
5800
|
value: function domSelection() {
|
package/dist/index.d.ts
CHANGED
|
@@ -673,7 +673,7 @@ interface EditorProps<P = any> {
|
|
|
673
673
|
Can be used to transform pasted HTML text, _before_ it is parsed,
|
|
674
674
|
for example to clean it up.
|
|
675
675
|
*/
|
|
676
|
-
transformPastedHTML?: (this: P, html: string) => string;
|
|
676
|
+
transformPastedHTML?: (this: P, html: string, view: EditorView) => string;
|
|
677
677
|
/**
|
|
678
678
|
The [parser](https://prosemirror.net/docs/ref/#model.DOMParser) to use when reading content from
|
|
679
679
|
the clipboard. When not given, the value of the
|
|
@@ -684,7 +684,7 @@ interface EditorProps<P = any> {
|
|
|
684
684
|
Transform pasted plain text. The `plain` flag will be true when
|
|
685
685
|
the text is pasted as plain text.
|
|
686
686
|
*/
|
|
687
|
-
transformPastedText?: (this: P, text: string, plain: boolean) => string;
|
|
687
|
+
transformPastedText?: (this: P, text: string, plain: boolean, view: EditorView) => string;
|
|
688
688
|
/**
|
|
689
689
|
A function to parse text from the clipboard into a document
|
|
690
690
|
slice. Called after
|
|
@@ -694,17 +694,17 @@ interface EditorProps<P = any> {
|
|
|
694
694
|
[`clipboardParser`](https://prosemirror.net/docs/ref/#view.EditorProps.clipboardParser) on it.
|
|
695
695
|
The `plain` flag will be true when the text is pasted as plain text.
|
|
696
696
|
*/
|
|
697
|
-
clipboardTextParser?: (this: P, text: string, $context: ResolvedPos, plain: boolean) => Slice;
|
|
697
|
+
clipboardTextParser?: (this: P, text: string, $context: ResolvedPos, plain: boolean, view: EditorView) => Slice;
|
|
698
698
|
/**
|
|
699
699
|
Can be used to transform pasted or dragged-and-dropped content
|
|
700
700
|
before it is applied to the document.
|
|
701
701
|
*/
|
|
702
|
-
transformPasted?: (this: P, slice: Slice) => Slice;
|
|
702
|
+
transformPasted?: (this: P, slice: Slice, view: EditorView) => Slice;
|
|
703
703
|
/**
|
|
704
704
|
Can be used to transform copied or cut content before it is
|
|
705
705
|
serialized to the clipboard.
|
|
706
706
|
*/
|
|
707
|
-
transformCopied?: (this: P, slice: Slice) => Slice;
|
|
707
|
+
transformCopied?: (this: P, slice: Slice, view: EditorView) => Slice;
|
|
708
708
|
/**
|
|
709
709
|
Allows you to pass custom rendering and behavior logic for
|
|
710
710
|
nodes. Should map node names to constructor functions that
|
|
@@ -759,7 +759,7 @@ interface EditorProps<P = any> {
|
|
|
759
759
|
editor will use [`textBetween`](https://prosemirror.net/docs/ref/#model.Node.textBetween) on the
|
|
760
760
|
selected range.
|
|
761
761
|
*/
|
|
762
|
-
clipboardTextSerializer?: (this: P, content: Slice) => string;
|
|
762
|
+
clipboardTextSerializer?: (this: P, content: Slice, view: EditorView) => string;
|
|
763
763
|
/**
|
|
764
764
|
A set of [document decorations](https://prosemirror.net/docs/ref/#view.Decoration) to show in the
|
|
765
765
|
view.
|