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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-view",
3
- "version": "1.22.0",
3
+ "version": "1.23.3",
4
4
  "description": "ProseMirror's view component",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
package/src/clipboard.js CHANGED
@@ -69,7 +69,14 @@ export function parseFromClipboard(view, text, html, plainText, $context) {
69
69
  let sliceData = contextNode && /^(\d+) (\d+) (.*)/.exec(contextNode.getAttribute("data-pm-slice"))
70
70
  if (!slice) {
71
71
  let parser = view.someProp("clipboardParser") || view.someProp("domParser") || DOMParser.fromSchema(view.state.schema)
72
- slice = parser.parseSlice(dom, {preserveWhitespace: !!(asText || sliceData), context: $context})
72
+ slice = parser.parseSlice(dom, {
73
+ preserveWhitespace: !!(asText || sliceData),
74
+ context: $context,
75
+ ruleFromNode(dom) {
76
+ if (dom.nodeName == "BR" && !dom.nextSibling &&
77
+ dom.parentNode && !inlineParents.test(dom.parentNode.nodeName)) return {ignore: true}
78
+ }
79
+ })
73
80
  }
74
81
  if (sliceData) {
75
82
  slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[3])
@@ -89,6 +96,8 @@ export function parseFromClipboard(view, text, html, plainText, $context) {
89
96
  return slice
90
97
  }
91
98
 
99
+ const 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
100
+
92
101
  // Takes a slice parsed with parseSlice, which means there hasn't been
93
102
  // any content-expression checking done on the top nodes, tries to
94
103
  // find a parent node in the current context that might fit the nodes,
package/src/decoration.js CHANGED
@@ -156,7 +156,7 @@ export class Decoration {
156
156
  // key are interchangeable—if widgets differ in, for example,
157
157
  // the behavior of some event handler, they should get
158
158
  // different keys.
159
- //
159
+ //
160
160
  // destroy:: ?(node: dom.Node)
161
161
  // Called when the widget decoration is removed as a result of
162
162
  // mapping
package/src/index.js CHANGED
@@ -373,6 +373,14 @@ export class EditorView {
373
373
  this.docView = null
374
374
  }
375
375
 
376
+ // :: boolean
377
+ // This is true when the view has been
378
+ // [destroyed](#view.EditorView.destroy) (and thus should not be
379
+ // used anymore).
380
+ get isDestroyed() {
381
+ return this.docView == null
382
+ }
383
+
376
384
  // Used for testing.
377
385
  dispatchEvent(event) {
378
386
  return dispatchEvent(this, event)
package/src/viewdesc.js CHANGED
@@ -1091,7 +1091,7 @@ class ViewTreeUpdater {
1091
1091
  // Tracks whether anything was changed
1092
1092
  this.changed = false
1093
1093
 
1094
- this.preMatch = preMatch(top.node.content, top.children)
1094
+ this.preMatch = preMatch(top.node.content, top)
1095
1095
  }
1096
1096
 
1097
1097
  // Destroy and remove the children between the given indices in
@@ -1152,17 +1152,14 @@ class ViewTreeUpdater {
1152
1152
  // Try to find a node desc matching the given data. Skip over it and
1153
1153
  // return true when successful.
1154
1154
  findNodeMatch(node, outerDeco, innerDeco, index) {
1155
- let children = this.top.children, found = -1
1156
- if (index >= this.preMatch.index) {
1157
- for (let i = this.index; i < children.length; i++) {
1158
- if (this.preMatch.matched.get(children[i]) == index) {
1159
- if (children[i].matchesNode(node, outerDeco, innerDeco)) found = i
1160
- break
1161
- }
1162
- }
1155
+ let found = -1, targetDesc
1156
+ if (index >= this.preMatch.index &&
1157
+ (targetDesc = this.preMatch.matches[index - this.preMatch.index]).parent == this.top &&
1158
+ targetDesc.matchesNode(node, outerDeco, innerDeco)) {
1159
+ found = this.top.children.indexOf(targetDesc, this.index)
1163
1160
  } else {
1164
- for (let i = this.index, e = Math.min(children.length, i + 1); i < e; i++) {
1165
- let child = children[i]
1161
+ for (let i = this.index, e = Math.min(this.top.children.length, i + 5); i < e; i++) {
1162
+ let child = this.top.children[i]
1166
1163
  if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) {
1167
1164
  found = i
1168
1165
  break
@@ -1274,22 +1271,44 @@ class ViewTreeUpdater {
1274
1271
  }
1275
1272
  }
1276
1273
 
1277
- // : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>}
1274
+ // : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>, matches: ViewDesc[]}
1278
1275
  // Iterate from the end of the fragment and array of descs to find
1279
1276
  // directly matching ones, in order to avoid overeagerly reusing those
1280
1277
  // for other nodes. Returns the fragment index of the first node that
1281
1278
  // is part of the sequence of matched nodes at the end of the
1282
1279
  // fragment.
1283
- function preMatch(frag, descs) {
1284
- let fI = frag.childCount, dI = descs.length, matched = new Map
1285
- for (; fI > 0 && dI > 0; dI--) {
1286
- let desc = descs[dI - 1], node = desc.node
1280
+ function preMatch(frag, parentDesc) {
1281
+ let curDesc = parentDesc, descI = curDesc.children.length
1282
+ let fI = frag.childCount, matched = new Map, matches = []
1283
+ outer: while (fI > 0) {
1284
+ let desc
1285
+ for (;;) {
1286
+ if (descI) {
1287
+ let next = curDesc.children[descI - 1]
1288
+ if (next instanceof MarkViewDesc) {
1289
+ curDesc = next
1290
+ descI = next.children.length
1291
+ } else {
1292
+ desc = next
1293
+ descI--
1294
+ break
1295
+ }
1296
+ } else if (curDesc == parentDesc) {
1297
+ break outer
1298
+ } else {
1299
+ // FIXME
1300
+ descI = curDesc.parent.children.indexOf(curDesc)
1301
+ curDesc = curDesc.parent
1302
+ }
1303
+ }
1304
+ let node = desc.node
1287
1305
  if (!node) continue
1288
1306
  if (node != frag.child(fI - 1)) break
1289
1307
  --fI
1290
1308
  matched.set(desc, fI)
1309
+ matches.push(desc)
1291
1310
  }
1292
- return {index: fI, matched}
1311
+ return {index: fI, matched, matches: matches.reverse()}
1293
1312
  }
1294
1313
 
1295
1314
  function compareSide(a, b) { return a.type.side - b.type.side }