prosemirror-view 1.21.0 → 1.22.0

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.22.0",
4
4
  "description": "ProseMirror's view component",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
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
@@ -642,7 +642,7 @@ function checkStateComponent(plugin) {
642
642
  // view](#state.PluginSpec.view) and
643
643
  // [props](#state.PluginSpec.props). Passing plugins with a state
644
644
  // component (a [state field](#state.PluginSpec.state) field or a
645
- // [transaction)[#state.PluginSpec.filterTransaction] filter or
645
+ // [transaction](#state.PluginSpec.filterTransaction) filter or
646
646
  // appender) will result in an error, since such plugins must be
647
647
  // present in the state to work.
648
648
  //
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) {
@@ -1147,9 +1154,11 @@ class ViewTreeUpdater {
1147
1154
  findNodeMatch(node, outerDeco, innerDeco, index) {
1148
1155
  let children = this.top.children, found = -1
1149
1156
  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
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
+ }
1153
1162
  }
1154
1163
  } else {
1155
1164
  for (let i = this.index, e = Math.min(children.length, i + 1); i < e; i++) {