prosemirror-view 1.21.0 → 1.23.2

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.21.0",
3
+ "version": "1.23.2",
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,13 @@ 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) return {ignore: true}
77
+ }
78
+ })
73
79
  }
74
80
  if (sliceData) {
75
81
  slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[3])
package/src/decoration.js CHANGED
@@ -25,6 +25,10 @@ class WidgetType {
25
25
  (this.spec.key && this.spec.key == other.spec.key ||
26
26
  this.toDOM == other.toDOM && compareObjs(this.spec, other.spec)))
27
27
  }
28
+
29
+ destroy(node) {
30
+ if (this.spec.destroy) this.spec.destroy(node)
31
+ }
28
32
  }
29
33
 
30
34
  class InlineType {
@@ -152,6 +156,10 @@ export class Decoration {
152
156
  // key are interchangeable—if widgets differ in, for example,
153
157
  // the behavior of some event handler, they should get
154
158
  // different keys.
159
+ //
160
+ // destroy:: ?(node: dom.Node)
161
+ // Called when the widget decoration is removed as a result of
162
+ // mapping
155
163
  static widget(pos, toDOM, spec) {
156
164
  return new Decoration(pos, pos, new WidgetType(toDOM, spec))
157
165
  }
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)
@@ -642,7 +650,7 @@ function checkStateComponent(plugin) {
642
650
  // view](#state.PluginSpec.view) and
643
651
  // [props](#state.PluginSpec.props). Passing plugins with a state
644
652
  // component (a [state field](#state.PluginSpec.state) field or a
645
- // [transaction)[#state.PluginSpec.filterTransaction] filter or
653
+ // [transaction](#state.PluginSpec.filterTransaction) filter or
646
654
  // appender) will result in an error, since such plugins must be
647
655
  // present in the state to work.
648
656
  //
package/src/viewdesc.js CHANGED
@@ -526,6 +526,11 @@ class WidgetViewDesc extends ViewDesc {
526
526
  return mutation.type != "selection" || this.widget.spec.ignoreSelection
527
527
  }
528
528
 
529
+ destroy() {
530
+ this.widget.type.destroy(this.dom)
531
+ super.destroy()
532
+ }
533
+
529
534
  get domAtom() { return true }
530
535
  }
531
536
 
@@ -1038,6 +1043,8 @@ function patchAttributes(dom, prev, cur) {
1038
1043
  dom.classList.remove(prevList[i])
1039
1044
  for (let i = 0; i < curList.length; i++) if (prevList.indexOf(curList[i]) == -1)
1040
1045
  dom.classList.add(curList[i])
1046
+ if (dom.classList.length == 0)
1047
+ dom.removeAttribute("class")
1041
1048
  }
1042
1049
  if (prev.style != cur.style) {
1043
1050
  if (prev.style) {
@@ -1084,7 +1091,7 @@ class ViewTreeUpdater {
1084
1091
  // Tracks whether anything was changed
1085
1092
  this.changed = false
1086
1093
 
1087
- this.preMatch = preMatch(top.node.content, top.children)
1094
+ this.preMatch = preMatch(top.node.content, top)
1088
1095
  }
1089
1096
 
1090
1097
  // Destroy and remove the children between the given indices in
@@ -1145,15 +1152,14 @@ class ViewTreeUpdater {
1145
1152
  // Try to find a node desc matching the given data. Skip over it and
1146
1153
  // return true when successful.
1147
1154
  findNodeMatch(node, outerDeco, innerDeco, index) {
1148
- let children = this.top.children, found = -1
1149
- if (index >= this.preMatch.index) {
1150
- for (let i = this.index; i < children.length; i++) if (children[i].matchesNode(node, outerDeco, innerDeco)) {
1151
- found = i
1152
- break
1153
- }
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)
1154
1160
  } else {
1155
- for (let i = this.index, e = Math.min(children.length, i + 1); i < e; i++) {
1156
- 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]
1157
1163
  if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) {
1158
1164
  found = i
1159
1165
  break
@@ -1265,22 +1271,44 @@ class ViewTreeUpdater {
1265
1271
  }
1266
1272
  }
1267
1273
 
1268
- // : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>}
1274
+ // : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>, matches: ViewDesc[]}
1269
1275
  // Iterate from the end of the fragment and array of descs to find
1270
1276
  // directly matching ones, in order to avoid overeagerly reusing those
1271
1277
  // for other nodes. Returns the fragment index of the first node that
1272
1278
  // is part of the sequence of matched nodes at the end of the
1273
1279
  // fragment.
1274
- function preMatch(frag, descs) {
1275
- let fI = frag.childCount, dI = descs.length, matched = new Map
1276
- for (; fI > 0 && dI > 0; dI--) {
1277
- 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
1278
1305
  if (!node) continue
1279
1306
  if (node != frag.child(fI - 1)) break
1280
1307
  --fI
1281
1308
  matched.set(desc, fI)
1309
+ matches.push(desc)
1282
1310
  }
1283
- return {index: fI, matched}
1311
+ return {index: fI, matched, matches: matches.reverse()}
1284
1312
  }
1285
1313
 
1286
1314
  function compareSide(a, b) { return a.type.side - b.type.side }