prosemirror-transform 1.10.5 → 1.11.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,9 @@
1
+ ## 1.11.0 (2026-01-21)
2
+
3
+ ### New features
4
+
5
+ The new `Tranform.changedRange` method gives you a document range that includes all changes made by the transform/transaction.
6
+
1
7
  ## 1.10.5 (2025-11-11)
2
8
 
3
9
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1691,6 +1691,27 @@ var Transform = function () {
1691
1691
  get: function get() {
1692
1692
  return this.steps.length > 0;
1693
1693
  }
1694
+ }, {
1695
+ key: "changedRange",
1696
+ value: function changedRange() {
1697
+ var from = 1e9,
1698
+ to = -1e9;
1699
+ for (var i = 0; i < this.mapping.maps.length; i++) {
1700
+ var map = this.mapping.maps[i];
1701
+ if (i) {
1702
+ from = map.map(from, 1);
1703
+ to = map.map(to, -1);
1704
+ }
1705
+ map.forEach(function (_f, _t, fromB, toB) {
1706
+ from = Math.min(from, fromB);
1707
+ to = Math.max(to, toB);
1708
+ });
1709
+ }
1710
+ return from == 1e9 ? null : {
1711
+ from: from,
1712
+ to: to
1713
+ };
1714
+ }
1694
1715
  }, {
1695
1716
  key: "addStep",
1696
1717
  value: function addStep(step, doc) {
package/dist/index.d.cts CHANGED
@@ -326,6 +326,16 @@ declare class Transform {
326
326
  */
327
327
  get docChanged(): boolean;
328
328
  /**
329
+ Return a single range, in post-transform document positions,
330
+ that covers all content changed by this transform. Returns null
331
+ if no replacements are made. Note that this will ignore changes
332
+ that add/remove marks without replacing the underlying content.
333
+ */
334
+ changedRange(): {
335
+ from: number;
336
+ to: number;
337
+ } | null;
338
+ /**
329
339
  Replace the part of the document between `from` and `to` with the
330
340
  given `slice`.
331
341
  */
package/dist/index.d.ts CHANGED
@@ -326,6 +326,16 @@ declare class Transform {
326
326
  */
327
327
  get docChanged(): boolean;
328
328
  /**
329
+ Return a single range, in post-transform document positions,
330
+ that covers all content changed by this transform. Returns null
331
+ if no replacements are made. Note that this will ignore changes
332
+ that add/remove marks without replacing the underlying content.
333
+ */
334
+ changedRange(): {
335
+ from: number;
336
+ to: number;
337
+ } | null;
338
+ /**
329
339
  Replace the part of the document between `from` and `to` with the
330
340
  given `slice`.
331
341
  */
package/dist/index.js CHANGED
@@ -1946,6 +1946,27 @@ class Transform {
1946
1946
  return this.steps.length > 0;
1947
1947
  }
1948
1948
  /**
1949
+ Return a single range, in post-transform document positions,
1950
+ that covers all content changed by this transform. Returns null
1951
+ if no replacements are made. Note that this will ignore changes
1952
+ that add/remove marks without replacing the underlying content.
1953
+ */
1954
+ changedRange() {
1955
+ let from = 1e9, to = -1e9;
1956
+ for (let i = 0; i < this.mapping.maps.length; i++) {
1957
+ let map = this.mapping.maps[i];
1958
+ if (i) {
1959
+ from = map.map(from, 1);
1960
+ to = map.map(to, -1);
1961
+ }
1962
+ map.forEach((_f, _t, fromB, toB) => {
1963
+ from = Math.min(from, fromB);
1964
+ to = Math.max(to, toB);
1965
+ });
1966
+ }
1967
+ return from == 1e9 ? null : { from, to };
1968
+ }
1969
+ /**
1949
1970
  @internal
1950
1971
  */
1951
1972
  addStep(step, doc) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-transform",
3
- "version": "1.10.5",
3
+ "version": "1.11.0",
4
4
  "description": "ProseMirror document transformations",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/transform.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import {Node, NodeType, Mark, MarkType, ContentMatch, Slice, Fragment, NodeRange, Attrs} from "prosemirror-model"
2
-
3
2
  import {Mapping} from "./map"
4
3
  import {Step} from "./step"
5
4
  import {addMark, removeMark, clearIncompatible} from "./mark"
@@ -66,6 +65,26 @@ export class Transform {
66
65
  return this.steps.length > 0
67
66
  }
68
67
 
68
+ /// Return a single range, in post-transform document positions,
69
+ /// that covers all content changed by this transform. Returns null
70
+ /// if no replacements are made. Note that this will ignore changes
71
+ /// that add/remove marks without replacing the underlying content.
72
+ changedRange() {
73
+ let from = 1e9, to = -1e9
74
+ for (let i = 0; i < this.mapping.maps.length; i++) {
75
+ let map = this.mapping.maps[i]
76
+ if (i) {
77
+ from = map.map(from, 1)
78
+ to = map.map(to, -1)
79
+ }
80
+ map.forEach((_f, _t, fromB, toB) => {
81
+ from = Math.min(from, fromB)
82
+ to = Math.max(to, toB)
83
+ })
84
+ }
85
+ return from == 1e9 ? null : {from, to}
86
+ }
87
+
69
88
  /// @internal
70
89
  addStep(step: Step, doc: Node) {
71
90
  this.docs.push(this.doc)
@@ -206,7 +225,7 @@ export class Transform {
206
225
  if (mark instanceof Mark) {
207
226
  if (mark.isInSet(node.marks)) this.step(new RemoveNodeMarkStep(pos, mark))
208
227
  } else {
209
- let set = node.marks, found, steps: Step[] = []
228
+ let set = node.marks, found: Mark | undefined, steps: Step[] = []
210
229
  while (found = mark.isInSet(set)) {
211
230
  steps.push(new RemoveNodeMarkStep(pos, found))
212
231
  set = found.removeFromSet(set)