prosemirror-transform 1.3.0 → 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,29 @@
1
+ ## 1.3.4 (2022-02-04)
2
+
3
+ ### Bug fixes
4
+
5
+ Make sure that constructing an empty `StepMap` returns `StepMap.empty`.
6
+
7
+ ## 1.3.3 (2021-09-29)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix an inconsistency in `deleteRange` where it would delete the parent node for ranges covering all textblocks in a given parent.
12
+
13
+ ## 1.3.2 (2021-04-06)
14
+
15
+ ### Bug fixes
16
+
17
+ Fix a regression in `dropPoint` that caused it to dereference undefined in some circumstances.
18
+
19
+ ## 1.3.1 (2021-04-01)
20
+
21
+ ### Bug fixes
22
+
23
+ Fix a crash in `Transform.replaceRange` when called with under specific circumstances.
24
+
25
+ Fix an issue where `dropPoint` could return an invalid drop point.
26
+
1
27
  ## 1.3.0 (2021-03-31)
2
28
 
3
29
  ### New features
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))
@@ -904,9 +911,14 @@ function dropPoint(doc, pos, slice) {
904
911
  for (var d = $pos.depth; d >= 0; d--) {
905
912
  var bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1;
906
913
  var insertPos = $pos.index(d) + (bias > 0 ? 1 : 0);
907
- if (pass == 1
908
- ? $pos.node(d).canReplace(insertPos, insertPos, content)
909
- : $pos.node(d).contentMatchAt(insertPos).findWrapping(content.firstChild.type))
914
+ var parent = $pos.node(d), fits = false;
915
+ if (pass == 1) {
916
+ fits = parent.canReplace(insertPos, insertPos, content);
917
+ } else {
918
+ var wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type);
919
+ fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]);
920
+ }
921
+ if (fits)
910
922
  { return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1) }
911
923
  }
912
924
  }
@@ -1606,7 +1618,7 @@ Transform.prototype.replaceRange = function(from, to, slice) {
1606
1618
  this.replace(from, to, slice);
1607
1619
  if (this.steps.length > startSteps) { break }
1608
1620
  var depth = targetDepths[i$2];
1609
- if (i$2 < 0) { continue }
1621
+ if (depth < 0) { continue }
1610
1622
  from = $from.before(depth); to = $to.after(depth);
1611
1623
  }
1612
1624
  return this
@@ -1672,7 +1684,10 @@ function coveredDepths($from, $to) {
1672
1684
  $to.end(d) > $to.pos + ($to.depth - d) ||
1673
1685
  $from.node(d).type.spec.isolating ||
1674
1686
  $to.node(d).type.spec.isolating) { break }
1675
- if (start == $to.start(d)) { result.push(d); }
1687
+ if (start == $to.start(d) ||
1688
+ (d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent &&
1689
+ d && $to.start(d - 1) == start - 1))
1690
+ { result.push(d); }
1676
1691
  }
1677
1692
  return result
1678
1693
  }