prosemirror-changeset 2.1.1 → 2.2.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,15 @@
1
+ ## 2.2.0 (2022-05-30)
2
+
3
+ ### New features
4
+
5
+ Include TypeScript type declarations.
6
+
7
+ ## 2.1.2 (2019-11-20)
8
+
9
+ ### Bug fixes
10
+
11
+ Rename ES module files to use a .js extension, since Webpack gets confused by .mjs
12
+
1
13
  ## 2.1.1 (2019-11-19)
2
14
 
3
15
  ### Bug fixes
package/README.md CHANGED
@@ -19,13 +19,12 @@ It is possible to associate arbitrary data values with such spans, for
19
19
  example to track the user that made the change, the timestamp at which
20
20
  it was made, or the step data necessary to invert it again.
21
21
 
22
- ### class Change
22
+ ### class Change`<Data = any>`
23
23
 
24
24
  A replaced range with metadata associated with it.
25
25
 
26
26
  * **`fromA`**`: number`\
27
- The start of the range deleted/replaced in the old
28
- document.
27
+ The start of the range deleted/replaced in the old document.
29
28
 
30
29
  * **`toA`**`: number`\
31
30
  The end of the range in the old document.
@@ -36,35 +35,42 @@ A replaced range with metadata associated with it.
36
35
  * **`toB`**`: number`\
37
36
  The end of the range in the new document.
38
37
 
39
- * **`deleted`**`: [Span]`\
40
- Data associated with the deleted content. The length
41
- of these spans adds up to `this.toA - this.fromA`.
38
+ * **`deleted`**`: readonly Span[]`\
39
+ Data associated with the deleted content. The length of these
40
+ spans adds up to `this.toA - this.fromA`.
42
41
 
43
- * **`inserted`**`: [Span]`\
44
- Data associated with the inserted content. Length
45
- adds up to `this.toB - this.toA`.
42
+ * **`inserted`**`: readonly Span[]`\
43
+ Data associated with the inserted content. Length adds up to
44
+ `this.toB - this.toA`.
46
45
 
46
+ * `static `**`merge`**`<Data>(x: readonly Change[], y: readonly Change[], combine: fn(dataA: Data, dataB: Data) → Data) → readonly Change[]`\
47
+ This merges two changesets (the end document of x should be the
48
+ start document of y) into a single one spanning the start of x to
49
+ the end of y.
47
50
 
48
- ### class Span
51
+
52
+ ### class Span`<Data = any>`
49
53
 
50
54
  Stores metadata for a part of a change.
51
55
 
52
- * **`length`**`: number`
56
+ * **`length`**`: number`\
57
+ The length of this span.
53
58
 
54
- * **`data`**`: any`
59
+ * **`data`**`: Data`\
60
+ The data associated with this span.
55
61
 
56
62
 
57
- ### class ChangeSet
63
+ ### class ChangeSet`<Data = any>`
58
64
 
59
- A change set tracks the changes to a document from a given
60
- point in the past. It condenses a number of step maps down to a
61
- flat sequence of replacements, and simplifies replacments that
65
+ A change set tracks the changes to a document from a given point
66
+ in the past. It condenses a number of step maps down to a flat
67
+ sequence of replacements, and simplifies replacments that
62
68
  partially undo themselves by comparing their content.
63
69
 
64
- * **`changes`**`: [Change]`\
70
+ * **`changes`**`: readonly Change[]`\
65
71
  Replaced regions.
66
72
 
67
- * **`addSteps`**`(newDoc: Node, maps: [StepMap], data: [any] | any) → ChangeSet`\
73
+ * **`addSteps`**`(newDoc: Node, maps: readonly StepMap[], data: Data | readonly Data[]) → ChangeSet`\
68
74
  Computes a new changeset by adding the given step maps and
69
75
  metadata (either as an array, per-map, or as a single value to be
70
76
  associated with all maps) to the current set. Will not mutate the
@@ -79,25 +85,25 @@ partially undo themselves by comparing their content.
79
85
  * **`startDoc`**`: Node`\
80
86
  The starting document of the change set.
81
87
 
82
- * **`map`**`(f: fn(range: Change) → any) → ChangeSet`\
88
+ * **`map`**`(f: fn(range: Span) → Data) → ChangeSet`\
83
89
  Map the span's data values in the given set through a function
84
90
  and construct a new set with the resulting data.
85
91
 
86
- * **`changedRange`**`(b: ChangeSet, maps: ?[StepMap]) → ?{from: number, to: number}`\
92
+ * **`changedRange`**`(b: ChangeSet, maps?: readonly StepMap[]) → {from: number, to: number}`\
87
93
  Compare two changesets and return the range in which they are
88
94
  changed, if any. If the document changed between the maps, pass
89
95
  the maps for the steps that changed it as second argument, and
90
96
  make sure the method is called on the old set and passed the new
91
97
  set. The returned positions will be in new document coordinates.
92
98
 
93
- * `static `**`create`**`(doc: Node, combine: ?fn(a: any, b: any) → any) → ChangeSet`\
99
+ * `static `**`create`**`<Data = any>(doc: Node, combine?: fn(dataA: Data, dataB: Data) → Data = (a, b) => a === b ? a : null as any) → ChangeSet`\
94
100
  Create a changeset with the given base object and configuration.
95
101
  The `combine` function is used to compare and combine metadata—it
96
102
  should return null when metadata isn't compatible, and a combined
97
103
  version for a merged range when it is.
98
104
 
99
105
 
100
- * **`simplifyChanges`**`(changes: [Change], doc: Node) → [Change]`\
106
+ * **`simplifyChanges`**`(changes: readonly Change[], doc: Node) → Change[]`\
101
107
  Simplifies a set of changes for presentation. This makes the
102
108
  assumption that having both insertions and deletions within a word
103
109
  is confusing, and, when such changes occur without a word boundary