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/dist/index.js CHANGED
@@ -61,6 +61,7 @@ var MapResult = function MapResult(pos, deleted, recover) {
61
61
  var StepMap = function StepMap(ranges, inverted) {
62
62
  if ( inverted === void 0 ) inverted = false;
63
63
 
64
+ if (!ranges.length && StepMap.empty) { return StepMap.empty }
64
65
  this.ranges = ranges;
65
66
  this.inverted = inverted;
66
67
  };
@@ -724,8 +725,14 @@ function findWrappingInside(range, type) {
724
725
  // probably be computed with [`findWrapping`](#transform.findWrapping).
725
726
  Transform.prototype.wrap = function(range, wrappers) {
726
727
  var content = prosemirrorModel.Fragment.empty;
727
- for (var i = wrappers.length - 1; i >= 0; i--)
728
- { content = prosemirrorModel.Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content)); }
728
+ for (var i = wrappers.length - 1; i >= 0; i--) {
729
+ if (content.size) {
730
+ var match = wrappers[i].type.contentMatch.matchFragment(content);
731
+ if (!match || !match.validEnd)
732
+ { throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper") }
733
+ }
734
+ content = prosemirrorModel.Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
735
+ }
729
736
 
730
737
  var start = range.start, end = range.end;
731
738
  return this.step(new ReplaceAroundStep(start, end, start, end, new prosemirrorModel.Slice(content, 0, 0), wrappers.length, true))