prosemirror-view 1.23.10 → 1.23.13

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,21 @@
1
+ ## 1.23.13 (2022-04-26)
2
+
3
+ ### Bug fixes
4
+
5
+ Work around a hidden cursor issue in Chrome when a textblock ends in an uneditable node wrapped in a mark.
6
+
7
+ ## 1.23.12 (2022-04-08)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix an issue where enter on Chrome Android could, in textblock nodes rendered with an inner content element, delete the text after the cursor.
12
+
13
+ ## 1.23.11 (2022-03-31)
14
+
15
+ ### Bug fixes
16
+
17
+ Fix an issue where a node view with a separate content wrapper node could sometimes lose its content on Chrome when backspacing out content due to unexpected DOM element recreation.
18
+
1
19
  ## 1.23.10 (2022-03-22)
2
20
 
3
21
  ### Bug fixes
package/dist/index.es.js CHANGED
@@ -1296,8 +1296,23 @@ var NodeViewDesc = /*@__PURE__*/(function (ViewDesc) {
1296
1296
  // whether this is a problem
1297
1297
  var rule = {node: this.node.type.name, attrs: this.node.attrs};
1298
1298
  if (this.node.type.whitespace == "pre") { rule.preserveWhitespace = "full"; }
1299
- if (this.contentDOM && !this.contentLost) { rule.contentElement = this.contentDOM; }
1300
- else { rule.getContent = function () { return this$1.contentDOM ? Fragment.empty : this$1.node.content; }; }
1299
+ if (!this.contentDOM) {
1300
+ rule.getContent = function () { return this$1.node.content; };
1301
+ } else if (!this.contentLost) {
1302
+ rule.contentElement = this.contentDOM;
1303
+ } else {
1304
+ // Chrome likes to randomly recreate parent nodes when
1305
+ // backspacing things. When that happens, this tries to find the
1306
+ // new parent.
1307
+ for (var i = this.children.length - 1; i >= 0; i--) {
1308
+ var child = this.children[i];
1309
+ if (this.dom.contains(child.dom.parentNode)) {
1310
+ rule.contentElement = child.dom.parentNode;
1311
+ break
1312
+ }
1313
+ }
1314
+ if (!rule.contentElement) { rule.getContent = function () { return Fragment.empty; }; }
1315
+ }
1301
1316
  return rule
1302
1317
  };
1303
1318
 
@@ -1906,21 +1921,24 @@ ViewTreeUpdater.prototype.placeWidget = function placeWidget (widget, view, pos)
1906
1921
  // Make sure a textblock looks and behaves correctly in
1907
1922
  // contentEditable.
1908
1923
  ViewTreeUpdater.prototype.addTextblockHacks = function addTextblockHacks () {
1909
- var lastChild = this.top.children[this.index - 1];
1910
- while (lastChild instanceof MarkViewDesc) { lastChild = lastChild.children[lastChild.children.length - 1]; }
1924
+ var lastChild = this.top.children[this.index - 1], parent = this.top;
1925
+ while (lastChild instanceof MarkViewDesc) {
1926
+ parent = lastChild;
1927
+ lastChild = parent.children[parent.children.length - 1];
1928
+ }
1911
1929
 
1912
1930
  if (!lastChild || // Empty textblock
1913
1931
  !(lastChild instanceof TextViewDesc) ||
1914
1932
  /\n$/.test(lastChild.node.text)) {
1915
1933
  // Avoid bugs in Safari's cursor drawing (#1165) and Chrome's mouse selection (#1152)
1916
1934
  if ((result.safari || result.chrome) && lastChild && lastChild.dom.contentEditable == "false")
1917
- { this.addHackNode("IMG"); }
1918
- this.addHackNode("BR");
1935
+ { this.addHackNode("IMG", parent); }
1936
+ this.addHackNode("BR", this.top);
1919
1937
  }
1920
1938
  };
1921
1939
 
1922
- ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
1923
- if (this.index < this.top.children.length && this.top.children[this.index].matchesHack(nodeName)) {
1940
+ ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName, parent) {
1941
+ if (parent == this.top && this.index < parent.children.length && parent.children[this.index].matchesHack(nodeName)) {
1924
1942
  this.index++;
1925
1943
  } else {
1926
1944
  var dom = document.createElement(nodeName);
@@ -1929,7 +1947,9 @@ ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
1929
1947
  dom.alt = "";
1930
1948
  }
1931
1949
  if (nodeName == "BR") { dom.className = "ProseMirror-trailingBreak"; }
1932
- this.top.children.splice(this.index++, 0, new TrailingHackViewDesc(this.top, nothing, dom, null));
1950
+ var hack = new TrailingHackViewDesc(this.top, nothing, dom, null);
1951
+ if (parent != this.top) { parent.children.push(hack); }
1952
+ else { parent.children.splice(this.index++, 0, hack); }
1933
1953
  this.changed = true;
1934
1954
  }
1935
1955
  };
@@ -2710,15 +2730,17 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
2710
2730
  view.lastKeyCode = null;
2711
2731
 
2712
2732
  var change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
2733
+ if ((result.ios && view.lastIOSEnter > Date.now() - 225 || result.android) &&
2734
+ addedNodes.some(function (n) { return n.nodeName == "DIV" || n.nodeName == "P"; }) &&
2735
+ (!change || change.endA >= change.endB) &&
2736
+ view.someProp("handleKeyDown", function (f) { return f(view, keyEvent(13, "Enter")); })) {
2737
+ view.lastIOSEnter = 0;
2738
+ return
2739
+ }
2713
2740
  if (!change) {
2714
2741
  if (typeOver && sel instanceof TextSelection && !sel.empty && sel.$head.sameParent(sel.$anchor) &&
2715
2742
  !view.composing && !(parse.sel && parse.sel.anchor != parse.sel.head)) {
2716
2743
  change = {start: sel.from, endA: sel.to, endB: sel.to};
2717
- } else if ((result.ios && view.lastIOSEnter > Date.now() - 225 || result.android) &&
2718
- addedNodes.some(function (n) { return n.nodeName == "DIV" || n.nodeName == "P"; }) &&
2719
- view.someProp("handleKeyDown", function (f) { return f(view, keyEvent(13, "Enter")); })) {
2720
- view.lastIOSEnter = 0;
2721
- return
2722
2744
  } else {
2723
2745
  if (parse.sel) {
2724
2746
  var sel$1 = resolveSelection(view, view.state.doc, parse.sel);
@@ -3338,7 +3360,7 @@ DOMObserver.prototype.flush = function flush () {
3338
3360
  }
3339
3361
 
3340
3362
  var sel = this.view.root.getSelection();
3341
- var newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasSelection(this.view) && !this.ignoreSelectionChange(sel);
3363
+ var newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(this.view) && !this.ignoreSelectionChange(sel);
3342
3364
 
3343
3365
  var from = -1, to = -1, typeOver = false, added = [];
3344
3366
  if (this.view.editable) {
@@ -4931,7 +4953,7 @@ var prototypeAccessors$2 = { props: { configurable: true },root: { configurable:
4931
4953
 
4932
4954
  // composing:: boolean
4933
4955
  // Holds `true` when a
4934
- // [composition](https://developer.mozilla.org/en-US/docs/Mozilla/IME_handling_guide)
4956
+ // [composition](https://w3c.github.io/uievents/#events-compositionevents)
4935
4957
  // is active.
4936
4958
 
4937
4959
  // :: DirectEditorProps
@@ -5508,7 +5530,7 @@ function checkStateComponent(plugin) {
5508
5530
 
5509
5531
  // DirectEditorProps:: interface extends EditorProps
5510
5532
  //
5511
- // The props object given directly to the editor view supports two
5533
+ // The props object given directly to the editor view supports some
5512
5534
  // fields that can't be used in plugins:
5513
5535
  //
5514
5536
  // state:: EditorState