prosemirror-view 1.23.2 → 1.23.6

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/dist/index.js CHANGED
@@ -1055,7 +1055,8 @@ ViewDesc.prototype.markDirty = function markDirty (from, to) {
1055
1055
  else { child.markDirty(from - startInside, to - startInside); }
1056
1056
  return
1057
1057
  } else {
1058
- child.dirty = child.dom == child.contentDOM && child.dom.parentNode == this.contentDOM ? CONTENT_DIRTY : NODE_DIRTY;
1058
+ child.dirty = child.dom == child.contentDOM && child.dom.parentNode == this.contentDOM && !child.children.length
1059
+ ? CONTENT_DIRTY : NODE_DIRTY;
1059
1060
  }
1060
1061
  }
1061
1062
  offset = end;
@@ -1193,7 +1194,10 @@ var MarkViewDesc = /*@__PURE__*/(function (ViewDesc) {
1193
1194
  return new MarkViewDesc(parent, mark, spec.dom, spec.contentDOM || spec.dom)
1194
1195
  };
1195
1196
 
1196
- MarkViewDesc.prototype.parseRule = function parseRule () { return {mark: this.mark.type.name, attrs: this.mark.attrs, contentElement: this.contentDOM} };
1197
+ MarkViewDesc.prototype.parseRule = function parseRule () {
1198
+ if ((this.dirty & NODE_DIRTY) || this.mark.type.spec.reparseInView) { return null }
1199
+ return {mark: this.mark.type.name, attrs: this.mark.attrs, contentElement: this.contentDOM}
1200
+ };
1197
1201
 
1198
1202
  MarkViewDesc.prototype.matchesMark = function matchesMark (mark) { return this.dirty != NODE_DIRTY && this.mark.eq(mark) };
1199
1203
 
@@ -1294,7 +1298,7 @@ var NodeViewDesc = /*@__PURE__*/(function (ViewDesc) {
1294
1298
  // attrs in the dom, that won't be picked up. Not entirely sure
1295
1299
  // whether this is a problem
1296
1300
  var rule = {node: this.node.type.name, attrs: this.node.attrs};
1297
- if (this.node.type.spec.code) { rule.preserveWhitespace = "full"; }
1301
+ if (this.node.type.whitespace == "pre") { rule.preserveWhitespace = "full"; }
1298
1302
  if (this.contentDOM && !this.contentLost) { rule.contentElement = this.contentDOM; }
1299
1303
  else { rule.getContent = function () { return this$1.contentDOM ? prosemirrorModel.Fragment.empty : this$1.node.content; }; }
1300
1304
  return rule
@@ -2081,8 +2085,8 @@ function findTextInFragment(frag, text, from, to) {
2081
2085
  if (!next.isText) { break }
2082
2086
  str += next.text;
2083
2087
  }
2084
- if (pos >= from) {
2085
- var found = str.lastIndexOf(text, to - childStart);
2088
+ if (pos >= from && childStart < to) {
2089
+ var found = str.lastIndexOf(text, to - childStart - 1);
2086
2090
  if (found >= 0 && found + text.length + childStart >= from)
2087
2091
  { return childStart + found }
2088
2092
  }
@@ -2152,10 +2156,17 @@ function selectionToDOM(view, force) {
2152
2156
 
2153
2157
  if (!editorOwnsSelection(view)) { return }
2154
2158
 
2155
- if (!force && view.mouseDown && view.mouseDown.allowDefault) {
2156
- view.mouseDown.delayedSelectionSync = true;
2157
- view.domObserver.setCurSelection();
2158
- return
2159
+ // The delayed drag selection causes issues with Cell Selections
2160
+ // in Safari. And the drag selection delay is to workarond issues
2161
+ // which only present in Chrome.
2162
+ if (!force && view.mouseDown && view.mouseDown.allowDefault && result.chrome) {
2163
+ var domSel = view.root.getSelection(), curSel = view.domObserver.currentSelection;
2164
+ if (domSel.anchorNode && isEquivalentPosition(domSel.anchorNode, domSel.anchorOffset,
2165
+ curSel.anchorNode, curSel.anchorOffset)) {
2166
+ view.mouseDown.delayedSelectionSync = true;
2167
+ view.domObserver.setCurSelection();
2168
+ return
2169
+ }
2159
2170
  }
2160
2171
 
2161
2172
  view.domObserver.disconnectSelection();
@@ -2620,7 +2631,7 @@ function parseBetween(view, from_, to_) {
2620
2631
  topOpen: true,
2621
2632
  from: fromOffset,
2622
2633
  to: toOffset,
2623
- preserveWhitespace: $from.parent.type.spec.code ? "full" : true,
2634
+ preserveWhitespace: $from.parent.type.whitespace == "pre" ? "full" : true,
2624
2635
  editableContent: true,
2625
2636
  findPositions: find,
2626
2637
  ruleFromNode: ruleFromNode,
@@ -3002,7 +3013,8 @@ function parseFromClipboard(view, text, html, plainText, $context) {
3002
3013
  preserveWhitespace: !!(asText || sliceData),
3003
3014
  context: $context,
3004
3015
  ruleFromNode: function ruleFromNode(dom) {
3005
- if (dom.nodeName == "BR" && !dom.nextSibling) { return {ignore: true} }
3016
+ if (dom.nodeName == "BR" && !dom.nextSibling &&
3017
+ dom.parentNode && !inlineParents.test(dom.parentNode.nodeName)) { return {ignore: true} }
3006
3018
  }
3007
3019
  });
3008
3020
  }
@@ -3024,6 +3036,8 @@ function parseFromClipboard(view, text, html, plainText, $context) {
3024
3036
  return slice
3025
3037
  }
3026
3038
 
3039
+ var inlineParents = /^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;
3040
+
3027
3041
  // Takes a slice parsed with parseSlice, which means there hasn't been
3028
3042
  // any content-expression checking done on the top nodes, tries to
3029
3043
  // find a parent node in the current context that might fit the nodes,
@@ -3504,9 +3518,14 @@ function dispatchEvent(view, event) {
3504
3518
  editHandlers.keydown = function (view, event) {
3505
3519
  view.shiftKey = event.keyCode == 16 || event.shiftKey;
3506
3520
  if (inOrNearComposition(view, event)) { return }
3507
- if (event.keyCode != 229) { view.domObserver.forceFlush(); }
3508
3521
  view.lastKeyCode = event.keyCode;
3509
3522
  view.lastKeyCodeTime = Date.now();
3523
+ // Suppress enter key events on Chrome Android, because those tend
3524
+ // to be part of a confused sequence of composition events fired,
3525
+ // and handling them eagerly tends to corrupt the input.
3526
+ if (result.android && result.chrome && event.keyCode == 13) { return }
3527
+ if (event.keyCode != 229) { view.domObserver.forceFlush(); }
3528
+
3510
3529
  // On iOS, if we preventDefault enter key presses, the virtual
3511
3530
  // keyboard gets confused. So the hack here is to set a flag that
3512
3531
  // makes the DOM change code recognize that what just happens should
@@ -3891,6 +3910,7 @@ function timestampFromCustomEvent() {
3891
3910
  }
3892
3911
 
3893
3912
  function endComposition(view, forceUpdate) {
3913
+ if (result.android && view.domObserver.flushingSoon >= 0) { return }
3894
3914
  view.domObserver.forceFlush();
3895
3915
  clearComposition(view);
3896
3916
  if (forceUpdate || view.docView.dirty) {
@@ -3981,6 +4001,11 @@ function doPaste(view, text, html, e) {
3981
4001
  }
3982
4002
 
3983
4003
  editHandlers.paste = function (view, e) {
4004
+ // Handling paste from JavaScript during composition is very poorly
4005
+ // handled by browsers, so as a dodgy but preferable kludge, we just
4006
+ // let the browser do its native thing there, except on Android,
4007
+ // where the editor is almost always composing.
4008
+ if (view.composing && !result.android) { return }
3984
4009
  var data = brokenClipboardAPI ? null : e.clipboardData;
3985
4010
  if (data && doPaste(view, data.getData("text/plain"), data.getData("text/html"), e)) { e.preventDefault(); }
3986
4011
  else { capturePaste(view, e); }
@@ -4112,6 +4137,7 @@ handlers.beforeinput = function (view, event) {
4112
4137
  // Very specific hack to deal with backspace sometimes failing on
4113
4138
  // Chrome Android when after an uneditable node.
4114
4139
  if (result.chrome && result.android && event.inputType == "deleteContentBackward") {
4140
+ view.domObserver.flushSoon();
4115
4141
  var domChangeCount = view.domChangeCount;
4116
4142
  setTimeout(function () {
4117
4143
  if (view.domChangeCount != domChangeCount) { return } // Event already had some effect