prosemirror-view
Advanced tools
Comparing version 1.18.1 to 1.18.2
@@ -0,1 +1,9 @@ | ||
## 1.18.2 (2021-03-25) | ||
### Bug fixes | ||
Properly handle CSS class name strings with extra spaces in decorations. | ||
Fix a performance bug when updating nodes with thousands of children. | ||
## 1.18.1 (2021-03-15) | ||
@@ -2,0 +10,0 @@ |
{ | ||
"name": "prosemirror-view", | ||
"version": "1.18.1", | ||
"version": "1.18.2", | ||
"description": "ProseMirror's view component", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -995,4 +995,4 @@ import {DOMSerializer, Fragment, Mark} from "prosemirror-model" | ||
if (prev.class != cur.class) { | ||
let prevList = prev.class ? prev.class.split(" ") : nothing | ||
let curList = cur.class ? cur.class.split(" ") : nothing | ||
let prevList = prev.class ? prev.class.split(" ").filter(Boolean) : nothing | ||
let curList = cur.class ? cur.class.split(" ").filter(Boolean) : nothing | ||
for (let i = 0; i < prevList.length; i++) if (curList.indexOf(prevList[i]) == -1) | ||
@@ -1048,11 +1048,5 @@ dom.classList.remove(prevList[i]) | ||
let pre = preMatch(top.node.content, top.children) | ||
this.preMatched = pre.nodes | ||
this.preMatchOffset = pre.offset | ||
this.preMatch = preMatch(top.node.content, top.children) | ||
} | ||
getPreMatch(index) { | ||
return index >= this.preMatchOffset ? this.preMatched[index - this.preMatchOffset] : null | ||
} | ||
// Destroy and remove the children between the given indices in | ||
@@ -1116,9 +1110,12 @@ // `this.top`. | ||
findNodeMatch(node, outerDeco, innerDeco, index) { | ||
let found = -1, preMatch = index < 0 ? undefined : this.getPreMatch(index), children = this.top.children | ||
if (preMatch && preMatch.matchesNode(node, outerDeco, innerDeco)) { | ||
found = children.indexOf(preMatch) | ||
let children = this.top.children, found = -1 | ||
if (index >= this.preMatch.index) { | ||
for (let i = this.index; i < children.length; i++) if (children[i].matchesNode(node, outerDeco, innerDeco)) { | ||
found = i | ||
break | ||
} | ||
} else { | ||
for (let i = this.index, e = Math.min(children.length, i + 5); i < e; i++) { | ||
for (let i = this.index, e = Math.min(children.length, i + 1); i < e; i++) { | ||
let child = children[i] | ||
if (child.matchesNode(node, outerDeco, innerDeco) && this.preMatched.indexOf(child) < 0) { | ||
if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) { | ||
found = i | ||
@@ -1142,4 +1139,4 @@ break | ||
if (next instanceof NodeViewDesc) { | ||
let preMatch = this.preMatched.indexOf(next) | ||
if (preMatch > -1 && preMatch + this.preMatchOffset != index) return false | ||
let preMatch = this.preMatch.matched.get(next) | ||
if (preMatch != null && preMatch != index) return false | ||
let nextDOM = next.dom | ||
@@ -1203,18 +1200,18 @@ | ||
// : (Fragment, [ViewDesc]) → [ViewDesc] | ||
// : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>} | ||
// Iterate from the end of the fragment and array of descs to find | ||
// directly matching ones, in order to avoid overeagerly reusing | ||
// those for other nodes. Returns an array whose positions correspond | ||
// to node positions in the fragment, and whose elements are either | ||
// descs matched to the child at that index, or empty. | ||
// directly matching ones, in order to avoid overeagerly reusing those | ||
// for other nodes. Returns the fragment index of the first node that | ||
// is part of the sequence of matched nodes at the end of the | ||
// fragment. | ||
function preMatch(frag, descs) { | ||
let result = [], end = frag.childCount | ||
for (let i = descs.length - 1; end > 0 && i >= 0; i--) { | ||
let desc = descs[i], node = desc.node | ||
let fI = frag.childCount, dI = descs.length, matched = new Map | ||
for (; fI > 0 && dI > 0; dI--) { | ||
let desc = descs[dI - 1], node = desc.node | ||
if (!node) continue | ||
if (node != frag.child(end - 1)) break | ||
result.push(desc) | ||
--end | ||
if (node != frag.child(fI - 1)) break | ||
--fI | ||
matched.set(desc, fI) | ||
} | ||
return {nodes: result.reverse(), offset: end} | ||
return {index: fI, matched} | ||
} | ||
@@ -1221,0 +1218,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1512287
14104