prosemirror-transform 1.3.3 → 1.3.4

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,9 @@
1
+ ## 1.3.4 (2022-02-04)
2
+
3
+ ### Bug fixes
4
+
5
+ Make sure that constructing an empty `StepMap` returns `StepMap.empty`.
6
+
1
7
  ## 1.3.3 (2021-09-29)
2
8
 
3
9
  ### Bug fixes
package/dist/index.es.js CHANGED
@@ -57,6 +57,7 @@ var MapResult = function MapResult(pos, deleted, recover) {
57
57
  var StepMap = function StepMap(ranges, inverted) {
58
58
  if ( inverted === void 0 ) inverted = false;
59
59
 
60
+ if (!ranges.length && StepMap.empty) { return StepMap.empty }
60
61
  this.ranges = ranges;
61
62
  this.inverted = inverted;
62
63
  };
@@ -720,8 +721,14 @@ function findWrappingInside(range, type) {
720
721
  // probably be computed with [`findWrapping`](#transform.findWrapping).
721
722
  Transform.prototype.wrap = function(range, wrappers) {
722
723
  var content = Fragment.empty;
723
- for (var i = wrappers.length - 1; i >= 0; i--)
724
- { content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content)); }
724
+ for (var i = wrappers.length - 1; i >= 0; i--) {
725
+ if (content.size) {
726
+ var match = wrappers[i].type.contentMatch.matchFragment(content);
727
+ if (!match || !match.validEnd)
728
+ { throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper") }
729
+ }
730
+ content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
731
+ }
725
732
 
726
733
  var start = range.start, end = range.end;
727
734
  return this.step(new ReplaceAroundStep(start, end, start, end, new Slice(content, 0, 0), wrappers.length, true))