prosemirror-changeset 2.2.0 → 2.3.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.3.0 (2025-05-05)
2
+
3
+ ### New features
4
+
5
+ Change sets can now be passed a custom token encoder that controls the way changed content is diffed.
6
+
7
+ ## 2.2.1 (2023-05-17)
8
+
9
+ ### Bug fixes
10
+
11
+ Include CommonJS type declarations in the package to please new TypeScript resolution settings.
12
+
1
13
  ## 2.2.0 (2022-05-30)
2
14
 
3
15
  ### New features
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2017 by Marijn Haverbeke <marijnh@gmail.com> and others
1
+ Copyright (C) 2017 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -41,7 +41,7 @@ A replaced range with metadata associated with it.
41
41
 
42
42
  * **`inserted`**`: readonly Span[]`\
43
43
  Data associated with the inserted content. Length adds up to
44
- `this.toB - this.toA`.
44
+ `this.toB - this.fromB`.
45
45
 
46
46
  * `static `**`merge`**`<Data>(x: readonly Change[], y: readonly Change[], combine: fn(dataA: Data, dataB: Data) → Data) → readonly Change[]`\
47
47
  This merges two changesets (the end document of x should be the
@@ -96,12 +96,18 @@ partially undo themselves by comparing their content.
96
96
  make sure the method is called on the old set and passed the new
97
97
  set. The returned positions will be in new document coordinates.
98
98
 
99
- * `static `**`create`**`<Data = any>(doc: Node, combine?: fn(dataA: Data, dataB: Data) → Data = (a, b) => a === b ? a : null as any) → ChangeSet`\
99
+ * `static `**`create`**`<Data = any>(doc: Node, combine?: fn(dataA: Data, dataB: Data) → Data = (a, b) => a === b ? a : null as any, tokenEncoder?: TokenEncoder = DefaultEncoder) → ChangeSet`\
100
100
  Create a changeset with the given base object and configuration.
101
+
101
102
  The `combine` function is used to compare and combine metadata—it
102
103
  should return null when metadata isn't compatible, and a combined
103
104
  version for a merged range when it is.
104
105
 
106
+ When given, a token encoder determines how document tokens are
107
+ serialized and compared when diffing the content produced by
108
+ changes. The default is to just compare nodes by name and text
109
+ by character, ignoring marks and attributes.
110
+
105
111
 
106
112
  * **`simplifyChanges`**`(changes: readonly Change[], doc: Node) → Change[]`\
107
113
  Simplifies a set of changes for presentation. This makes the
@@ -111,3 +117,30 @@ partially undo themselves by comparing their content.
111
117
  words (in the new document) they touch. An exception is made for
112
118
  single-character replacements.
113
119
 
120
+
121
+ ### interface TokenEncoder`<T>`
122
+
123
+ A token encoder can be passed when creating a `ChangeSet` in order
124
+ to influence the way the library runs its diffing algorithm. The
125
+ encoder determines how document tokens (such as nodes and
126
+ characters) are encoded and compared.
127
+
128
+ Note that both the encoding and the comparison may run a lot, and
129
+ doing non-trivial work in these functions could impact
130
+ performance.
131
+
132
+ * **`encodeCharacter`**`(char: number, marks: readonly Mark[]) → T`\
133
+ Encode a given character, with the given marks applied.
134
+
135
+ * **`encodeNodeStart`**`(node: Node) → T`\
136
+ Encode the start of a node or, if this is a leaf node, the
137
+ entire node.
138
+
139
+ * **`encodeNodeEnd`**`(node: Node) → T`\
140
+ Encode the end token for the given node. It is valid to encode
141
+ every end token in the same way.
142
+
143
+ * **`compareTokens`**`(a: T, b: T) → boolean`\
144
+ Compare the given tokens. Should return true when they count as
145
+ equal.
146
+