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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 1.22.0 (2021-11-08)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where some types of node decoration changes could cause an unnecessary cascade of node redraws.
6
+
7
+ ### New features
8
+
9
+ Widget decorations now accept a `destroy` option, which will be called when the widget is removed from the view.
10
+
1
11
  ## 1.21.0 (2021-10-29)
2
12
 
3
13
  ### Bug fixes
package/dist/index.es.js CHANGED
@@ -1121,6 +1121,11 @@ var WidgetViewDesc = /*@__PURE__*/(function (ViewDesc) {
1121
1121
  return mutation.type != "selection" || this.widget.spec.ignoreSelection
1122
1122
  };
1123
1123
 
1124
+ WidgetViewDesc.prototype.destroy = function destroy () {
1125
+ this.widget.type.destroy(this.dom);
1126
+ ViewDesc.prototype.destroy.call(this);
1127
+ };
1128
+
1124
1129
  prototypeAccessors$1.domAtom.get = function () { return true };
1125
1130
 
1126
1131
  Object.defineProperties( WidgetViewDesc.prototype, prototypeAccessors$1 );
@@ -1696,6 +1701,8 @@ function patchAttributes(dom, prev, cur) {
1696
1701
  { dom.classList.remove(prevList[i]); } }
1697
1702
  for (var i$1 = 0; i$1 < curList.length; i$1++) { if (prevList.indexOf(curList[i$1]) == -1)
1698
1703
  { dom.classList.add(curList[i$1]); } }
1704
+ if (dom.classList.length == 0)
1705
+ { dom.removeAttribute("class"); }
1699
1706
  }
1700
1707
  if (prev.style != cur.style) {
1701
1708
  if (prev.style) {
@@ -1803,10 +1810,12 @@ ViewTreeUpdater.prototype.syncToMarks = function syncToMarks (marks, inline, vie
1803
1810
  ViewTreeUpdater.prototype.findNodeMatch = function findNodeMatch (node, outerDeco, innerDeco, index) {
1804
1811
  var children = this.top.children, found = -1;
1805
1812
  if (index >= this.preMatch.index) {
1806
- for (var i = this.index; i < children.length; i++) { if (children[i].matchesNode(node, outerDeco, innerDeco)) {
1807
- found = i;
1808
- break
1809
- } }
1813
+ for (var i = this.index; i < children.length; i++) {
1814
+ if (this.preMatch.matched.get(children[i]) == index) {
1815
+ if (children[i].matchesNode(node, outerDeco, innerDeco)) { found = i; }
1816
+ break
1817
+ }
1818
+ }
1810
1819
  } else {
1811
1820
  for (var i$1 = this.index, e = Math.min(children.length, i$1 + 1); i$1 < e; i$1++) {
1812
1821
  var child = children[i$1];
@@ -4121,6 +4130,10 @@ WidgetType.prototype.eq = function eq (other) {
4121
4130
  this.toDOM == other.toDOM && compareObjs(this.spec, other.spec)))
4122
4131
  };
4123
4132
 
4133
+ WidgetType.prototype.destroy = function destroy (node) {
4134
+ if (this.spec.destroy) { this.spec.destroy(node); }
4135
+ };
4136
+
4124
4137
  var InlineType = function InlineType(attrs, spec) {
4125
4138
  this.spec = spec || noSpec;
4126
4139
  this.attrs = attrs;
@@ -4248,6 +4261,10 @@ Decoration.prototype.map = function map (mapping, offset, oldOffset) {
4248
4261
  // key are interchangeable—if widgets differ in, for example,
4249
4262
  // the behavior of some event handler, they should get
4250
4263
  // different keys.
4264
+ //
4265
+ // destroy:: ?(node: dom.Node)
4266
+ // Called when the widget decoration is removed as a result of
4267
+ // mapping
4251
4268
  Decoration.widget = function widget (pos, toDOM, spec) {
4252
4269
  return new Decoration(pos, pos, new WidgetType(toDOM, spec))
4253
4270
  };
@@ -5423,7 +5440,7 @@ function checkStateComponent(plugin) {
5423
5440
  // view](#state.PluginSpec.view) and
5424
5441
  // [props](#state.PluginSpec.props). Passing plugins with a state
5425
5442
  // component (a [state field](#state.PluginSpec.state) field or a
5426
- // [transaction)[#state.PluginSpec.filterTransaction] filter or
5443
+ // [transaction](#state.PluginSpec.filterTransaction) filter or
5427
5444
  // appender) will result in an error, since such plugins must be
5428
5445
  // present in the state to work.
5429
5446
  //