prosemirror-changeset 2.3.0 → 2.3.1
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 +6 -0
- package/dist/index.cjs +8 -2
- package/dist/index.js +12 -4
- package/package.json +1 -1
- package/src/diff.ts +13 -5
- package/test/test-diff.ts +3 -0
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -12,6 +12,12 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
12
12
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
13
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
14
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
+
function typeID(type) {
|
|
16
|
+
var cache = type.schema.cached.changeSetIDs || (type.schema.cached.changeSetIDs = Object.create(null));
|
|
17
|
+
var id = cache[type.name];
|
|
18
|
+
if (id == null) cache[type.name] = id = Object.keys(type.schema.nodes).indexOf(type.name) + 1;
|
|
19
|
+
return id;
|
|
20
|
+
}
|
|
15
21
|
var DefaultEncoder = {
|
|
16
22
|
encodeCharacter: function encodeCharacter(_char) {
|
|
17
23
|
return _char;
|
|
@@ -19,8 +25,8 @@ var DefaultEncoder = {
|
|
|
19
25
|
encodeNodeStart: function encodeNodeStart(node) {
|
|
20
26
|
return node.type.name;
|
|
21
27
|
},
|
|
22
|
-
encodeNodeEnd: function encodeNodeEnd() {
|
|
23
|
-
return -
|
|
28
|
+
encodeNodeEnd: function encodeNodeEnd(node) {
|
|
29
|
+
return -typeID(node.type);
|
|
24
30
|
},
|
|
25
31
|
compareTokens: function compareTokens(a, b) {
|
|
26
32
|
return a === b;
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
function typeID(type) {
|
|
2
|
+
let cache = type.schema.cached.changeSetIDs || (type.schema.cached.changeSetIDs = Object.create(null));
|
|
3
|
+
let id = cache[type.name];
|
|
4
|
+
if (id == null)
|
|
5
|
+
cache[type.name] = id = Object.keys(type.schema.nodes).indexOf(type.name) + 1;
|
|
6
|
+
return id;
|
|
7
|
+
}
|
|
8
|
+
// The default token encoder, which encodes node open tokens are
|
|
9
|
+
// encoded as strings holding the node name, characters as their
|
|
10
|
+
// character code, and node close tokens as negative numbers.
|
|
1
11
|
const DefaultEncoder = {
|
|
2
12
|
encodeCharacter: char => char,
|
|
3
13
|
encodeNodeStart: node => node.type.name,
|
|
4
|
-
encodeNodeEnd:
|
|
14
|
+
encodeNodeEnd: node => -typeID(node.type),
|
|
5
15
|
compareTokens: (a, b) => a === b
|
|
6
16
|
};
|
|
7
|
-
// Convert the given range of a fragment to tokens
|
|
8
|
-
// tokens are encoded as strings holding the node name, characters as
|
|
9
|
-
// their character code, and node close tokens as -1.
|
|
17
|
+
// Convert the given range of a fragment to tokens.
|
|
10
18
|
function tokens(frag, encoder, start, end, target) {
|
|
11
19
|
for (let i = 0, off = 0; i < frag.childCount; i++) {
|
|
12
20
|
let child = frag.child(i), endOff = off + child.nodeSize;
|
package/package.json
CHANGED
package/src/diff.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Fragment, Node, Mark} from "prosemirror-model"
|
|
1
|
+
import {Fragment, Node, NodeType, Mark} from "prosemirror-model"
|
|
2
2
|
import {Change} from "./change"
|
|
3
3
|
|
|
4
4
|
/// A token encoder can be passed when creating a `ChangeSet` in order
|
|
@@ -23,16 +23,24 @@ export interface TokenEncoder<T> {
|
|
|
23
23
|
compareTokens(a: T, b: T): boolean
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function typeID(type: NodeType) {
|
|
27
|
+
let cache: Record<string, number> = type.schema.cached.changeSetIDs || (type.schema.cached.changeSetIDs = Object.create(null))
|
|
28
|
+
let id = cache[type.name]
|
|
29
|
+
if (id == null) cache[type.name] = id = Object.keys(type.schema.nodes).indexOf(type.name) + 1
|
|
30
|
+
return id
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The default token encoder, which encodes node open tokens are
|
|
34
|
+
// encoded as strings holding the node name, characters as their
|
|
35
|
+
// character code, and node close tokens as negative numbers.
|
|
26
36
|
export const DefaultEncoder: TokenEncoder<number | string> = {
|
|
27
37
|
encodeCharacter: char => char,
|
|
28
38
|
encodeNodeStart: node => node.type.name,
|
|
29
|
-
encodeNodeEnd:
|
|
39
|
+
encodeNodeEnd: node => -typeID(node.type),
|
|
30
40
|
compareTokens: (a, b) => a === b
|
|
31
41
|
}
|
|
32
42
|
|
|
33
|
-
// Convert the given range of a fragment to tokens
|
|
34
|
-
// tokens are encoded as strings holding the node name, characters as
|
|
35
|
-
// their character code, and node close tokens as -1.
|
|
43
|
+
// Convert the given range of a fragment to tokens.
|
|
36
44
|
function tokens<T>(frag: Fragment, encoder: TokenEncoder<T>, start: number, end: number, target: T[]) {
|
|
37
45
|
for (let i = 0, off = 0; i < frag.childCount; i++) {
|
|
38
46
|
let child = frag.child(i), endOff = off + child.nodeSize
|
package/test/test-diff.ts
CHANGED