prosemirror-view 1.22.0 → 1.23.3

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
@@ -1751,7 +1751,7 @@ var ViewTreeUpdater = function ViewTreeUpdater(top, lockedNode) {
1751
1751
  // Tracks whether anything was changed
1752
1752
  this.changed = false;
1753
1753
 
1754
- this.preMatch = preMatch(top.node.content, top.children);
1754
+ this.preMatch = preMatch(top.node.content, top);
1755
1755
  };
1756
1756
 
1757
1757
  // Destroy and remove the children between the given indices in
@@ -1812,19 +1812,16 @@ ViewTreeUpdater.prototype.syncToMarks = function syncToMarks (marks, inline, vie
1812
1812
  // Try to find a node desc matching the given data. Skip over it and
1813
1813
  // return true when successful.
1814
1814
  ViewTreeUpdater.prototype.findNodeMatch = function findNodeMatch (node, outerDeco, innerDeco, index) {
1815
- var children = this.top.children, found = -1;
1816
- if (index >= this.preMatch.index) {
1817
- for (var i = this.index; i < children.length; i++) {
1818
- if (this.preMatch.matched.get(children[i]) == index) {
1819
- if (children[i].matchesNode(node, outerDeco, innerDeco)) { found = i; }
1820
- break
1821
- }
1822
- }
1815
+ var found = -1, targetDesc;
1816
+ if (index >= this.preMatch.index &&
1817
+ (targetDesc = this.preMatch.matches[index - this.preMatch.index]).parent == this.top &&
1818
+ targetDesc.matchesNode(node, outerDeco, innerDeco)) {
1819
+ found = this.top.children.indexOf(targetDesc, this.index);
1823
1820
  } else {
1824
- for (var i$1 = this.index, e = Math.min(children.length, i$1 + 1); i$1 < e; i$1++) {
1825
- var child = children[i$1];
1821
+ for (var i = this.index, e = Math.min(this.top.children.length, i + 5); i < e; i++) {
1822
+ var child = this.top.children[i];
1826
1823
  if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) {
1827
- found = i$1;
1824
+ found = i;
1828
1825
  break
1829
1826
  }
1830
1827
  }
@@ -1933,22 +1930,44 @@ ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
1933
1930
  }
1934
1931
  };
1935
1932
 
1936
- // : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>}
1933
+ // : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>, matches: ViewDesc[]}
1937
1934
  // Iterate from the end of the fragment and array of descs to find
1938
1935
  // directly matching ones, in order to avoid overeagerly reusing those
1939
1936
  // for other nodes. Returns the fragment index of the first node that
1940
1937
  // is part of the sequence of matched nodes at the end of the
1941
1938
  // fragment.
1942
- function preMatch(frag, descs) {
1943
- var fI = frag.childCount, dI = descs.length, matched = new Map;
1944
- for (; fI > 0 && dI > 0; dI--) {
1945
- var desc = descs[dI - 1], node = desc.node;
1939
+ function preMatch(frag, parentDesc) {
1940
+ var curDesc = parentDesc, descI = curDesc.children.length;
1941
+ var fI = frag.childCount, matched = new Map, matches = [];
1942
+ outer: while (fI > 0) {
1943
+ var desc = (void 0);
1944
+ for (;;) {
1945
+ if (descI) {
1946
+ var next = curDesc.children[descI - 1];
1947
+ if (next instanceof MarkViewDesc) {
1948
+ curDesc = next;
1949
+ descI = next.children.length;
1950
+ } else {
1951
+ desc = next;
1952
+ descI--;
1953
+ break
1954
+ }
1955
+ } else if (curDesc == parentDesc) {
1956
+ break outer
1957
+ } else {
1958
+ // FIXME
1959
+ descI = curDesc.parent.children.indexOf(curDesc);
1960
+ curDesc = curDesc.parent;
1961
+ }
1962
+ }
1963
+ var node = desc.node;
1946
1964
  if (!node) { continue }
1947
1965
  if (node != frag.child(fI - 1)) { break }
1948
1966
  --fI;
1949
1967
  matched.set(desc, fI);
1968
+ matches.push(desc);
1950
1969
  }
1951
- return {index: fI, matched: matched}
1970
+ return {index: fI, matched: matched, matches: matches.reverse()}
1952
1971
  }
1953
1972
 
1954
1973
  function compareSide(a, b) { return a.type.side - b.type.side }
@@ -2979,7 +2998,14 @@ function parseFromClipboard(view, text, html, plainText, $context) {
2979
2998
  var sliceData = contextNode && /^(\d+) (\d+) (.*)/.exec(contextNode.getAttribute("data-pm-slice"));
2980
2999
  if (!slice) {
2981
3000
  var parser = view.someProp("clipboardParser") || view.someProp("domParser") || prosemirrorModel.DOMParser.fromSchema(view.state.schema);
2982
- slice = parser.parseSlice(dom, {preserveWhitespace: !!(asText || sliceData), context: $context});
3001
+ slice = parser.parseSlice(dom, {
3002
+ preserveWhitespace: !!(asText || sliceData),
3003
+ context: $context,
3004
+ ruleFromNode: function ruleFromNode(dom) {
3005
+ if (dom.nodeName == "BR" && !dom.nextSibling &&
3006
+ dom.parentNode && !inlineParents.test(dom.parentNode.nodeName)) { return {ignore: true} }
3007
+ }
3008
+ });
2983
3009
  }
2984
3010
  if (sliceData) {
2985
3011
  slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[3]);
@@ -2999,6 +3025,8 @@ function parseFromClipboard(view, text, html, plainText, $context) {
2999
3025
  return slice
3000
3026
  }
3001
3027
 
3028
+ 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;
3029
+
3002
3030
  // Takes a slice parsed with parseSlice, which means there hasn't been
3003
3031
  // any content-expression checking done on the top nodes, tries to
3004
3032
  // find a parent node in the current context that might fit the nodes,
@@ -4265,7 +4293,7 @@ Decoration.prototype.map = function map (mapping, offset, oldOffset) {
4265
4293
  // key are interchangeable—if widgets differ in, for example,
4266
4294
  // the behavior of some event handler, they should get
4267
4295
  // different keys.
4268
- //
4296
+ //
4269
4297
  // destroy:: ?(node: dom.Node)
4270
4298
  // Called when the widget decoration is removed as a result of
4271
4299
  // mapping
@@ -4864,7 +4892,7 @@ var EditorView = function EditorView(place, props) {
4864
4892
  this.updatePluginViews();
4865
4893
  };
4866
4894
 
4867
- var prototypeAccessors$2 = { props: { configurable: true },root: { configurable: true } };
4895
+ var prototypeAccessors$2 = { props: { configurable: true },root: { configurable: true },isDestroyed: { configurable: true } };
4868
4896
 
4869
4897
  // composing:: boolean
4870
4898
  // Holds `true` when a
@@ -5174,6 +5202,14 @@ EditorView.prototype.destroy = function destroy () {
5174
5202
  this.docView = null;
5175
5203
  };
5176
5204
 
5205
+ // :: boolean
5206
+ // This is true when the view has been
5207
+ // [destroyed](#view.EditorView.destroy) (and thus should not be
5208
+ // used anymore).
5209
+ prototypeAccessors$2.isDestroyed.get = function () {
5210
+ return this.docView == null
5211
+ };
5212
+
5177
5213
  // Used for testing.
5178
5214
  EditorView.prototype.dispatchEvent = function dispatchEvent$1 (event) {
5179
5215
  return dispatchEvent(this, event)