prosemirror-view 1.18.7 → 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 CHANGED
@@ -1,3 +1,15 @@
1
+ ## 1.18.8 (2021-06-23)
2
+
3
+ ### Bug fixes
4
+
5
+ Work around a Safari bug where it draws the cursor at the start of the line when it is after an uneditable node at the end of the line.
6
+
7
+ Fix an issue where the DOM could get out of sync when editing decorated text.
8
+
9
+ Work around an issue where Firefox draws the cursor on the wrong line when after a newline.
10
+
11
+ Fix a bug where double-clicking with the left mouse button and then pressing another mouse button was treated as a triple click.
12
+
1
13
  ## 1.18.7 (2021-05-20)
2
14
 
3
15
  ### Bug fixes
package/dist/index.es.js CHANGED
@@ -694,7 +694,7 @@ var prototypeAccessors = { beforePosition: { configurable: true },size: { config
694
694
  ViewDesc.prototype.matchesWidget = function matchesWidget () { return false };
695
695
  ViewDesc.prototype.matchesMark = function matchesMark () { return false };
696
696
  ViewDesc.prototype.matchesNode = function matchesNode () { return false };
697
- ViewDesc.prototype.matchesHack = function matchesHack () { return false };
697
+ ViewDesc.prototype.matchesHack = function matchesHack (_nodeName) { return false };
698
698
 
699
699
  prototypeAccessors.beforePosition.get = function () { return false };
700
700
 
@@ -960,9 +960,17 @@ ViewDesc.prototype.setSelection = function setSelection (anchor, head, root, for
960
960
  if (node.nodeType == 3) {
961
961
  brKludge = offset$1 && node.nodeValue[offset$1 - 1] == "\n";
962
962
  // Issue #1128
963
- if (brKludge && offset$1 == node.nodeValue.length &&
964
- node.nextSibling && node.nextSibling.nodeName == "BR")
965
- { anchorDOM = headDOM = {node: node.parentNode, offset: domIndex(node) + 1}; }
963
+ if (brKludge && offset$1 == node.nodeValue.length) {
964
+ for (var scan = node, after = (void 0); scan; scan = scan.parentNode) {
965
+ if (after = scan.nextSibling) {
966
+ if (after.nodeName == "BR")
967
+ { anchorDOM = headDOM = {node: after.parentNode, offset: domIndex(after) + 1}; }
968
+ break
969
+ }
970
+ var desc = scan.pmViewDesc;
971
+ if (desc && desc.node && desc.node.isBlock) { break }
972
+ }
973
+ }
966
974
  } else {
967
975
  var prev = node.childNodes[offset$1 - 1];
968
976
  brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false");
@@ -971,8 +979,8 @@ ViewDesc.prototype.setSelection = function setSelection (anchor, head, root, for
971
979
  // Firefox can act strangely when the selection is in front of an
972
980
  // uneditable node. See #1163 and https://bugzilla.mozilla.org/show_bug.cgi?id=1709536
973
981
  if (result.gecko && domSel.focusNode && domSel.focusNode != headDOM.node && domSel.focusNode.nodeType == 1) {
974
- var after = domSel.focusNode.childNodes[domSel.focusOffset];
975
- if (after && after.contentEditable == "false") { force = true; }
982
+ var after$1 = domSel.focusNode.childNodes[domSel.focusOffset];
983
+ if (after$1 && after$1.contentEditable == "false") { force = true; }
976
984
  }
977
985
 
978
986
  if (!(force || brKludge && result.safari) &&
@@ -1482,6 +1490,12 @@ var TextViewDesc = /*@__PURE__*/(function (NodeViewDesc) {
1482
1490
  return new TextViewDesc(this.parent, node, this.outerDeco, this.innerDeco, dom, dom, view)
1483
1491
  };
1484
1492
 
1493
+ TextViewDesc.prototype.markDirty = function markDirty (from, to) {
1494
+ NodeViewDesc.prototype.markDirty.call(this, from, to);
1495
+ if (this.dom != this.nodeDOM && (from == 0 || to == this.nodeDOM.nodeValue.length))
1496
+ { this.dirty = NODE_DIRTY; }
1497
+ };
1498
+
1485
1499
  prototypeAccessors$4.domAtom.get = function () { return false };
1486
1500
 
1487
1501
  Object.defineProperties( TextViewDesc.prototype, prototypeAccessors$4 );
@@ -1503,7 +1517,7 @@ var TrailingHackViewDesc = /*@__PURE__*/(function (ViewDesc) {
1503
1517
  var prototypeAccessors$5 = { domAtom: { configurable: true } };
1504
1518
 
1505
1519
  TrailingHackViewDesc.prototype.parseRule = function parseRule () { return {ignore: true} };
1506
- TrailingHackViewDesc.prototype.matchesHack = function matchesHack () { return this.dirty == NOT_DIRTY };
1520
+ TrailingHackViewDesc.prototype.matchesHack = function matchesHack (nodeName) { return this.dirty == NOT_DIRTY && this.dom.nodeName == nodeName };
1507
1521
  prototypeAccessors$5.domAtom.get = function () { return true };
1508
1522
 
1509
1523
  Object.defineProperties( TrailingHackViewDesc.prototype, prototypeAccessors$5 );
@@ -1847,13 +1861,20 @@ ViewTreeUpdater.prototype.addTextblockHacks = function addTextblockHacks () {
1847
1861
  if (!lastChild || // Empty textblock
1848
1862
  !(lastChild instanceof TextViewDesc) ||
1849
1863
  /\n$/.test(lastChild.node.text)) {
1850
- if (this.index < this.top.children.length && this.top.children[this.index].matchesHack()) {
1851
- this.index++;
1852
- } else {
1853
- var dom = document.createElement("br");
1854
- this.top.children.splice(this.index++, 0, new TrailingHackViewDesc(this.top, nothing, dom, null));
1855
- this.changed = true;
1856
- }
1864
+ // Avoid a bug in Safari's cursor drawing (#1165)
1865
+ if (result.safari && lastChild && lastChild.dom.contentEditable == "false")
1866
+ { this.addHackNode("IMG"); }
1867
+ this.addHackNode("BR");
1868
+ }
1869
+ };
1870
+
1871
+ ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
1872
+ if (this.index < this.top.children.length && this.top.children[this.index].matchesHack(nodeName)) {
1873
+ this.index++;
1874
+ } else {
1875
+ var dom = document.createElement(nodeName);
1876
+ this.top.children.splice(this.index++, 0, new TrailingHackViewDesc(this.top, nothing, dom, null));
1877
+ this.changed = true;
1857
1878
  }
1858
1879
  };
1859
1880
 
@@ -3364,7 +3385,7 @@ function dispatchEvent(view, event) {
3364
3385
  editHandlers.keydown = function (view, event) {
3365
3386
  view.shiftKey = event.keyCode == 16 || event.shiftKey;
3366
3387
  if (inOrNearComposition(view, event)) { return }
3367
- view.domObserver.forceFlush();
3388
+ if (event.keyCode != 229) { view.domObserver.forceFlush(); }
3368
3389
  view.lastKeyCode = event.keyCode;
3369
3390
  view.lastKeyCodeTime = Date.now();
3370
3391
  // On iOS, if we preventDefault enter key presses, the virtual
@@ -3490,10 +3511,11 @@ function handleDoubleClick(view, pos, inside, event) {
3490
3511
  function handleTripleClick(view, pos, inside, event) {
3491
3512
  return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) ||
3492
3513
  view.someProp("handleTripleClick", function (f) { return f(view, pos, event); }) ||
3493
- defaultTripleClick(view, inside)
3514
+ defaultTripleClick(view, inside, event)
3494
3515
  }
3495
3516
 
3496
- function defaultTripleClick(view, inside) {
3517
+ function defaultTripleClick(view, inside, event) {
3518
+ if (event.button != 0) { return false }
3497
3519
  var doc = view.state.doc;
3498
3520
  if (inside == -1) {
3499
3521
  if (doc.inlineContent) {
@@ -3555,7 +3577,7 @@ var MouseDown = function MouseDown(view, pos, event, flushed) {
3555
3577
  this.event = event;
3556
3578
  this.flushed = flushed;
3557
3579
  this.selectNode = event[selectNodeModifier];
3558
- this.allowDefault = event.shiftKey;
3580
+ this.allowDefault = event.shiftKey || event.button != 0;
3559
3581
 
3560
3582
  var targetNode, targetPos;
3561
3583
  if (pos.inside > -1) {
@@ -3575,7 +3597,8 @@ var MouseDown = function MouseDown(view, pos, event, flushed) {
3575
3597
 
3576
3598
  var ref = view.state;
3577
3599
  var selection = ref.selection;
3578
- if (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false ||
3600
+ if (event.button == 0 &&
3601
+ targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false ||
3579
3602
  selection instanceof NodeSelection && selection.from <= targetPos && selection.to > targetPos)
3580
3603
  { this.mightDrag = {node: targetNode,
3581
3604
  pos: targetPos,