prosemirror-transform 1.12.4 → 1.12.5

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.12.5 (2026-11-04)
2
+
3
+ ### Bug fixes
4
+
5
+ Make sure `ReplaceAroundStep`s are dropped when mapped through another change that deletes their gap range.
6
+
7
+ Fix a crash in replace step fitting when an open slice is partially fitted.
8
+
9
+ Fix a crash in replace fitting that could occur when inserting nodes open at both ends.
10
+
1
11
  ## 1.12.4 (2026-10-22)
2
12
 
3
13
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -819,7 +819,7 @@ var ReplaceAroundStep = function (_Step7) {
819
819
  to = mapping.mapResult(this.to, -1);
820
820
  var gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);
821
821
  var gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
822
- if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos) return null;
822
+ if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos || gapFrom > gapTo) return null;
823
823
  return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
824
824
  }
825
825
  }, {
@@ -1423,15 +1423,14 @@ var Fitter = function () {
1423
1423
  this.placed = addToFragment(this.placed, frontierDepth, prosemirrorModel.Fragment.from(add));
1424
1424
  this.frontier[frontierDepth].match = match;
1425
1425
  if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1) this.closeFrontierNode();
1426
- for (var _i4 = 0, cur = fragment; _i4 < openEndCount; _i4++) {
1427
- var node = cur.lastChild;
1426
+ for (var _i4 = 0, cur = add[add.length - 1]; cur && _i4 < openEndCount; _i4++) {
1428
1427
  this.frontier.push({
1429
- type: node.type,
1430
- match: node.contentMatchAt(node.childCount)
1428
+ type: cur.type,
1429
+ match: cur.contentMatchAt(cur.childCount)
1431
1430
  });
1432
- cur = node.content;
1431
+ cur = cur.lastChild;
1433
1432
  }
1434
- this.unplaced = !toEnd ? new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd) : sliceDepth == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);
1433
+ this.unplaced = !toEnd ? new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth, taken), sliceDepth, slice.openEnd) : sliceDepth == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);
1435
1434
  }
1436
1435
  }, {
1437
1436
  key: "mustMoveInline",
package/dist/index.js CHANGED
@@ -902,7 +902,7 @@ class ReplaceAroundStep extends Step {
902
902
  let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
903
903
  let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);
904
904
  let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
905
- if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos)
905
+ if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos || gapFrom > gapTo)
906
906
  return null;
907
907
  return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
908
908
  }
@@ -1588,15 +1588,14 @@ class Fitter {
1588
1588
  if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1)
1589
1589
  this.closeFrontierNode();
1590
1590
  // Add new frontier nodes for any open nodes at the end.
1591
- for (let i = 0, cur = fragment; i < openEndCount; i++) {
1592
- let node = cur.lastChild;
1593
- this.frontier.push({ type: node.type, match: node.contentMatchAt(node.childCount) });
1594
- cur = node.content;
1591
+ for (let i = 0, cur = add[add.length - 1]; cur && i < openEndCount; i++) {
1592
+ this.frontier.push({ type: cur.type, match: cur.contentMatchAt(cur.childCount) });
1593
+ cur = cur.lastChild;
1595
1594
  }
1596
1595
  // Update `this.unplaced`. Drop the entire node from which we
1597
1596
  // placed it we got to its end, otherwise just drop the placed
1598
1597
  // nodes.
1599
- this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd)
1598
+ this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), sliceDepth, slice.openEnd)
1600
1599
  : sliceDepth == 0 ? Slice.empty
1601
1600
  : new Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);
1602
1601
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-transform",
3
- "version": "1.12.4",
3
+ "version": "1.12.5",
4
4
  "description": "ProseMirror document transformations",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/replace.ts CHANGED
@@ -216,16 +216,15 @@ class Fitter {
216
216
  this.closeFrontierNode()
217
217
 
218
218
  // Add new frontier nodes for any open nodes at the end.
219
- for (let i = 0, cur = fragment; i < openEndCount; i++) {
220
- let node = cur.lastChild!
221
- this.frontier.push({type: node.type, match: node.contentMatchAt(node.childCount)})
222
- cur = node.content
219
+ for (let i = 0, cur: Node | null = add[add.length - 1]; cur && i < openEndCount; i++) {
220
+ this.frontier.push({type: cur.type, match: cur.contentMatchAt(cur.childCount)})
221
+ cur = cur.lastChild
223
222
  }
224
223
 
225
224
  // Update `this.unplaced`. Drop the entire node from which we
226
225
  // placed it we got to its end, otherwise just drop the placed
227
226
  // nodes.
228
- this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd)
227
+ this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), sliceDepth, slice.openEnd)
229
228
  : sliceDepth == 0 ? Slice.empty
230
229
  : new Slice(dropFromFragment(slice.content, sliceDepth - 1, 1),
231
230
  sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1)
@@ -145,7 +145,7 @@ export class ReplaceAroundStep extends Step {
145
145
  let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1)
146
146
  let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1)
147
147
  let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1)
148
- if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos) return null
148
+ if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos || gapFrom > gapTo) return null
149
149
  return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure)
150
150
  }
151
151