prosemirror-view 1.18.4 → 1.18.8
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 +36 -0
- package/dist/index.es.js +72 -33
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +72 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/domchange.js +1 -1
- package/src/domcoords.js +4 -1
- package/src/input.js +18 -10
- package/src/viewdesc.js +41 -14
package/dist/index.js
CHANGED
|
@@ -381,7 +381,10 @@ function posAtCoords(view, coords) {
|
|
|
381
381
|
if (!elt) { return null }
|
|
382
382
|
}
|
|
383
383
|
// Safari's caretRangeFromPoint returns nonsense when on a draggable element
|
|
384
|
-
if (result.safari
|
|
384
|
+
if (result.safari) {
|
|
385
|
+
for (var p = elt; node && p; p = parentNode(p))
|
|
386
|
+
{ if (p.draggable) { node = offset = null; } }
|
|
387
|
+
}
|
|
385
388
|
elt = targetKludge(elt, coords);
|
|
386
389
|
if (node) {
|
|
387
390
|
if (result.gecko && node.nodeType == 1) {
|
|
@@ -695,7 +698,7 @@ var prototypeAccessors = { beforePosition: { configurable: true },size: { config
|
|
|
695
698
|
ViewDesc.prototype.matchesWidget = function matchesWidget () { return false };
|
|
696
699
|
ViewDesc.prototype.matchesMark = function matchesMark () { return false };
|
|
697
700
|
ViewDesc.prototype.matchesNode = function matchesNode () { return false };
|
|
698
|
-
ViewDesc.prototype.matchesHack = function matchesHack () { return false };
|
|
701
|
+
ViewDesc.prototype.matchesHack = function matchesHack (_nodeName) { return false };
|
|
699
702
|
|
|
700
703
|
prototypeAccessors.beforePosition.get = function () { return false };
|
|
701
704
|
|
|
@@ -961,14 +964,28 @@ ViewDesc.prototype.setSelection = function setSelection (anchor, head, root, for
|
|
|
961
964
|
if (node.nodeType == 3) {
|
|
962
965
|
brKludge = offset$1 && node.nodeValue[offset$1 - 1] == "\n";
|
|
963
966
|
// Issue #1128
|
|
964
|
-
if (brKludge && offset$1 == node.nodeValue.length
|
|
965
|
-
|
|
966
|
-
|
|
967
|
+
if (brKludge && offset$1 == node.nodeValue.length) {
|
|
968
|
+
for (var scan = node, after = (void 0); scan; scan = scan.parentNode) {
|
|
969
|
+
if (after = scan.nextSibling) {
|
|
970
|
+
if (after.nodeName == "BR")
|
|
971
|
+
{ anchorDOM = headDOM = {node: after.parentNode, offset: domIndex(after) + 1}; }
|
|
972
|
+
break
|
|
973
|
+
}
|
|
974
|
+
var desc = scan.pmViewDesc;
|
|
975
|
+
if (desc && desc.node && desc.node.isBlock) { break }
|
|
976
|
+
}
|
|
977
|
+
}
|
|
967
978
|
} else {
|
|
968
979
|
var prev = node.childNodes[offset$1 - 1];
|
|
969
980
|
brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false");
|
|
970
981
|
}
|
|
971
982
|
}
|
|
983
|
+
// Firefox can act strangely when the selection is in front of an
|
|
984
|
+
// uneditable node. See #1163 and https://bugzilla.mozilla.org/show_bug.cgi?id=1709536
|
|
985
|
+
if (result.gecko && domSel.focusNode && domSel.focusNode != headDOM.node && domSel.focusNode.nodeType == 1) {
|
|
986
|
+
var after$1 = domSel.focusNode.childNodes[domSel.focusOffset];
|
|
987
|
+
if (after$1 && after$1.contentEditable == "false") { force = true; }
|
|
988
|
+
}
|
|
972
989
|
|
|
973
990
|
if (!(force || brKludge && result.safari) &&
|
|
974
991
|
isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset) &&
|
|
@@ -1477,6 +1494,12 @@ var TextViewDesc = /*@__PURE__*/(function (NodeViewDesc) {
|
|
|
1477
1494
|
return new TextViewDesc(this.parent, node, this.outerDeco, this.innerDeco, dom, dom, view)
|
|
1478
1495
|
};
|
|
1479
1496
|
|
|
1497
|
+
TextViewDesc.prototype.markDirty = function markDirty (from, to) {
|
|
1498
|
+
NodeViewDesc.prototype.markDirty.call(this, from, to);
|
|
1499
|
+
if (this.dom != this.nodeDOM && (from == 0 || to == this.nodeDOM.nodeValue.length))
|
|
1500
|
+
{ this.dirty = NODE_DIRTY; }
|
|
1501
|
+
};
|
|
1502
|
+
|
|
1480
1503
|
prototypeAccessors$4.domAtom.get = function () { return false };
|
|
1481
1504
|
|
|
1482
1505
|
Object.defineProperties( TextViewDesc.prototype, prototypeAccessors$4 );
|
|
@@ -1484,26 +1507,26 @@ var TextViewDesc = /*@__PURE__*/(function (NodeViewDesc) {
|
|
|
1484
1507
|
return TextViewDesc;
|
|
1485
1508
|
}(NodeViewDesc));
|
|
1486
1509
|
|
|
1487
|
-
// A dummy desc used to tag trailing BR or
|
|
1510
|
+
// A dummy desc used to tag trailing BR or IMG nodes created to work
|
|
1488
1511
|
// around contentEditable terribleness.
|
|
1489
|
-
var
|
|
1490
|
-
function
|
|
1512
|
+
var TrailingHackViewDesc = /*@__PURE__*/(function (ViewDesc) {
|
|
1513
|
+
function TrailingHackViewDesc () {
|
|
1491
1514
|
ViewDesc.apply(this, arguments);
|
|
1492
1515
|
}
|
|
1493
1516
|
|
|
1494
|
-
if ( ViewDesc )
|
|
1495
|
-
|
|
1496
|
-
|
|
1517
|
+
if ( ViewDesc ) TrailingHackViewDesc.__proto__ = ViewDesc;
|
|
1518
|
+
TrailingHackViewDesc.prototype = Object.create( ViewDesc && ViewDesc.prototype );
|
|
1519
|
+
TrailingHackViewDesc.prototype.constructor = TrailingHackViewDesc;
|
|
1497
1520
|
|
|
1498
1521
|
var prototypeAccessors$5 = { domAtom: { configurable: true } };
|
|
1499
1522
|
|
|
1500
|
-
|
|
1501
|
-
|
|
1523
|
+
TrailingHackViewDesc.prototype.parseRule = function parseRule () { return {ignore: true} };
|
|
1524
|
+
TrailingHackViewDesc.prototype.matchesHack = function matchesHack (nodeName) { return this.dirty == NOT_DIRTY && this.dom.nodeName == nodeName };
|
|
1502
1525
|
prototypeAccessors$5.domAtom.get = function () { return true };
|
|
1503
1526
|
|
|
1504
|
-
Object.defineProperties(
|
|
1527
|
+
Object.defineProperties( TrailingHackViewDesc.prototype, prototypeAccessors$5 );
|
|
1505
1528
|
|
|
1506
|
-
return
|
|
1529
|
+
return TrailingHackViewDesc;
|
|
1507
1530
|
}(ViewDesc));
|
|
1508
1531
|
|
|
1509
1532
|
// A separate subclass is used for customized node views, so that the
|
|
@@ -1842,13 +1865,20 @@ ViewTreeUpdater.prototype.addTextblockHacks = function addTextblockHacks () {
|
|
|
1842
1865
|
if (!lastChild || // Empty textblock
|
|
1843
1866
|
!(lastChild instanceof TextViewDesc) ||
|
|
1844
1867
|
/\n$/.test(lastChild.node.text)) {
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1868
|
+
// Avoid a bug in Safari's cursor drawing (#1165)
|
|
1869
|
+
if (result.safari && lastChild && lastChild.dom.contentEditable == "false")
|
|
1870
|
+
{ this.addHackNode("IMG"); }
|
|
1871
|
+
this.addHackNode("BR");
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
|
|
1875
|
+
ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
|
|
1876
|
+
if (this.index < this.top.children.length && this.top.children[this.index].matchesHack(nodeName)) {
|
|
1877
|
+
this.index++;
|
|
1878
|
+
} else {
|
|
1879
|
+
var dom = document.createElement(nodeName);
|
|
1880
|
+
this.top.children.splice(this.index++, 0, new TrailingHackViewDesc(this.top, nothing, dom, null));
|
|
1881
|
+
this.changed = true;
|
|
1852
1882
|
}
|
|
1853
1883
|
};
|
|
1854
1884
|
|
|
@@ -2717,7 +2747,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
2717
2747
|
// Edge just doesn't move the cursor forward when you start typing
|
|
2718
2748
|
// in an empty block or between br nodes.
|
|
2719
2749
|
if (sel$2 && !(result.chrome && result.android && view.composing && sel$2.empty &&
|
|
2720
|
-
(change.
|
|
2750
|
+
(change.start != change.endB || view.lastAndroidDelete < Date.now() - 100) &&
|
|
2721
2751
|
(sel$2.head == chFrom || sel$2.head == tr.mapping.map(chTo) - 1) ||
|
|
2722
2752
|
result.ie && sel$2.empty && sel$2.head == chFrom))
|
|
2723
2753
|
{ tr.setSelection(sel$2); }
|
|
@@ -3359,7 +3389,7 @@ function dispatchEvent(view, event) {
|
|
|
3359
3389
|
editHandlers.keydown = function (view, event) {
|
|
3360
3390
|
view.shiftKey = event.keyCode == 16 || event.shiftKey;
|
|
3361
3391
|
if (inOrNearComposition(view, event)) { return }
|
|
3362
|
-
view.domObserver.forceFlush();
|
|
3392
|
+
if (event.keyCode != 229) { view.domObserver.forceFlush(); }
|
|
3363
3393
|
view.lastKeyCode = event.keyCode;
|
|
3364
3394
|
view.lastKeyCodeTime = Date.now();
|
|
3365
3395
|
// On iOS, if we preventDefault enter key presses, the virtual
|
|
@@ -3485,10 +3515,11 @@ function handleDoubleClick(view, pos, inside, event) {
|
|
|
3485
3515
|
function handleTripleClick(view, pos, inside, event) {
|
|
3486
3516
|
return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) ||
|
|
3487
3517
|
view.someProp("handleTripleClick", function (f) { return f(view, pos, event); }) ||
|
|
3488
|
-
defaultTripleClick(view, inside)
|
|
3518
|
+
defaultTripleClick(view, inside, event)
|
|
3489
3519
|
}
|
|
3490
3520
|
|
|
3491
|
-
function defaultTripleClick(view, inside) {
|
|
3521
|
+
function defaultTripleClick(view, inside, event) {
|
|
3522
|
+
if (event.button != 0) { return false }
|
|
3492
3523
|
var doc = view.state.doc;
|
|
3493
3524
|
if (inside == -1) {
|
|
3494
3525
|
if (doc.inlineContent) {
|
|
@@ -3550,7 +3581,7 @@ var MouseDown = function MouseDown(view, pos, event, flushed) {
|
|
|
3550
3581
|
this.event = event;
|
|
3551
3582
|
this.flushed = flushed;
|
|
3552
3583
|
this.selectNode = event[selectNodeModifier];
|
|
3553
|
-
this.allowDefault = event.shiftKey;
|
|
3584
|
+
this.allowDefault = event.shiftKey || event.button != 0;
|
|
3554
3585
|
|
|
3555
3586
|
var targetNode, targetPos;
|
|
3556
3587
|
if (pos.inside > -1) {
|
|
@@ -3568,8 +3599,11 @@ var MouseDown = function MouseDown(view, pos, event, flushed) {
|
|
|
3568
3599
|
var targetDesc = target ? view.docView.nearestDesc(target, true) : null;
|
|
3569
3600
|
this.target = targetDesc ? targetDesc.dom : null;
|
|
3570
3601
|
|
|
3571
|
-
|
|
3572
|
-
|
|
3602
|
+
var ref = view.state;
|
|
3603
|
+
var selection = ref.selection;
|
|
3604
|
+
if (event.button == 0 &&
|
|
3605
|
+
targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false ||
|
|
3606
|
+
selection instanceof prosemirrorState.NodeSelection && selection.from <= targetPos && selection.to > targetPos)
|
|
3573
3607
|
{ this.mightDrag = {node: targetNode,
|
|
3574
3608
|
pos: targetPos,
|
|
3575
3609
|
addAttr: this.target && !this.target.draggable,
|
|
@@ -3626,7 +3660,8 @@ MouseDown.prototype.up = function up (event) {
|
|
|
3626
3660
|
// thus doesn't get a reaction from ProseMirror. This
|
|
3627
3661
|
// works around that.
|
|
3628
3662
|
(result.chrome && !(this.view.state.selection instanceof prosemirrorState.TextSelection) &&
|
|
3629
|
-
(pos.pos
|
|
3663
|
+
Math.min(Math.abs(pos.pos - this.view.state.selection.from),
|
|
3664
|
+
Math.abs(pos.pos - this.view.state.selection.to)) <= 2)) {
|
|
3630
3665
|
updateSelection(this.view, prosemirrorState.Selection.near(this.view.state.doc.resolve(pos.pos)), "pointer");
|
|
3631
3666
|
event.preventDefault();
|
|
3632
3667
|
} else {
|
|
@@ -3874,9 +3909,13 @@ editHandlers.drop = function (view, e) {
|
|
|
3874
3909
|
if (!eventPos) { return }
|
|
3875
3910
|
var $mouse = view.state.doc.resolve(eventPos.pos);
|
|
3876
3911
|
if (!$mouse) { return }
|
|
3877
|
-
var slice = dragging && dragging.slice
|
|
3878
|
-
|
|
3879
|
-
|
|
3912
|
+
var slice = dragging && dragging.slice;
|
|
3913
|
+
if (slice) {
|
|
3914
|
+
view.someProp("transformPasted", function (f) { slice = f(slice); });
|
|
3915
|
+
} else {
|
|
3916
|
+
slice = parseFromClipboard(view, e.dataTransfer.getData(brokenClipboardAPI ? "Text" : "text/plain"),
|
|
3917
|
+
brokenClipboardAPI ? null : e.dataTransfer.getData("text/html"), false, $mouse);
|
|
3918
|
+
}
|
|
3880
3919
|
var move = dragging && !e[dragCopyModifier];
|
|
3881
3920
|
if (view.someProp("handleDrop", function (f) { return f(view, e, slice || prosemirrorModel.Slice.empty, move); })) {
|
|
3882
3921
|
e.preventDefault();
|