tiptap-rusty-parser 0.1.3 → 0.1.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/README.md
CHANGED
|
@@ -52,6 +52,7 @@ boundary. `path` arguments are plain `number[]` index paths (root = `[]`).
|
|
|
52
52
|
| Mutate (by path) | `setAttr`, `removeAttr`, `setText`, `addMark`, `removeMark`, `pushChild`, `insertChild`, `removeChild` |
|
|
53
53
|
| Text | `textContent()`, `charCount()`, `wordCount()` |
|
|
54
54
|
| Validate | `validate(schema)`, `isValid(schema)` |
|
|
55
|
+
| Diff | `diff(other)` → `Change[]`; `applyChanges(changes)`; `invert(changes)` → reverse `Change[]` (undo) |
|
|
55
56
|
|
|
56
57
|
Methods throw on malformed input or a missing path target.
|
|
57
58
|
|
package/package.json
CHANGED
|
@@ -14,6 +14,10 @@ export class TiptapDoc {
|
|
|
14
14
|
* returns whether it was newly added.
|
|
15
15
|
*/
|
|
16
16
|
addMark(path: any, mark_type: string, attrs: any): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Apply a change array (as produced by [`diff`](Self::diff)) in place.
|
|
19
|
+
*/
|
|
20
|
+
applyChanges(changes: any): void;
|
|
17
21
|
/**
|
|
18
22
|
* All nodes whose attribute `key` equals `value`.
|
|
19
23
|
*/
|
|
@@ -34,6 +38,11 @@ export class TiptapDoc {
|
|
|
34
38
|
* Child count of the node at `path`, or `undefined` if no such node.
|
|
35
39
|
*/
|
|
36
40
|
childCount(path: any): number | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Structural diff from this document to `other`; returns an array of
|
|
43
|
+
* change objects (each tagged with an `op`).
|
|
44
|
+
*/
|
|
45
|
+
diff(other: TiptapDoc): any;
|
|
37
46
|
/**
|
|
38
47
|
* The first node of `node_type`, or `undefined`.
|
|
39
48
|
*/
|
|
@@ -50,6 +59,11 @@ export class TiptapDoc {
|
|
|
50
59
|
* Insert `child` at `index` under the node at `path` (index clamped).
|
|
51
60
|
*/
|
|
52
61
|
insertChild(path: any, index: number, child: any): void;
|
|
62
|
+
/**
|
|
63
|
+
* Invert a change array relative to this document (the pre-image); returns
|
|
64
|
+
* the reverse change array for undo. See `applyChanges`.
|
|
65
|
+
*/
|
|
66
|
+
invert(changes: any): any;
|
|
53
67
|
/**
|
|
54
68
|
* True if the document has no schema violations.
|
|
55
69
|
*/
|
|
@@ -36,6 +36,16 @@ export class TiptapDoc {
|
|
|
36
36
|
}
|
|
37
37
|
return ret[0] !== 0;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Apply a change array (as produced by [`diff`](Self::diff)) in place.
|
|
41
|
+
* @param {any} changes
|
|
42
|
+
*/
|
|
43
|
+
applyChanges(changes) {
|
|
44
|
+
const ret = wasm.tiptapdoc_applyChanges(this.__wbg_ptr, changes);
|
|
45
|
+
if (ret[1]) {
|
|
46
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
39
49
|
/**
|
|
40
50
|
* All nodes whose attribute `key` equals `value`.
|
|
41
51
|
* @param {string} key
|
|
@@ -99,6 +109,20 @@ export class TiptapDoc {
|
|
|
99
109
|
}
|
|
100
110
|
return ret[0] === Number.MAX_SAFE_INTEGER ? undefined : ret[0];
|
|
101
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Structural diff from this document to `other`; returns an array of
|
|
114
|
+
* change objects (each tagged with an `op`).
|
|
115
|
+
* @param {TiptapDoc} other
|
|
116
|
+
* @returns {any}
|
|
117
|
+
*/
|
|
118
|
+
diff(other) {
|
|
119
|
+
_assertClass(other, TiptapDoc);
|
|
120
|
+
const ret = wasm.tiptapdoc_diff(this.__wbg_ptr, other.__wbg_ptr);
|
|
121
|
+
if (ret[2]) {
|
|
122
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
123
|
+
}
|
|
124
|
+
return takeFromExternrefTable0(ret[0]);
|
|
125
|
+
}
|
|
102
126
|
/**
|
|
103
127
|
* The first node of `node_type`, or `undefined`.
|
|
104
128
|
* @param {string} node_type
|
|
@@ -151,6 +175,19 @@ export class TiptapDoc {
|
|
|
151
175
|
throw takeFromExternrefTable0(ret[0]);
|
|
152
176
|
}
|
|
153
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Invert a change array relative to this document (the pre-image); returns
|
|
180
|
+
* the reverse change array for undo. See `applyChanges`.
|
|
181
|
+
* @param {any} changes
|
|
182
|
+
* @returns {any}
|
|
183
|
+
*/
|
|
184
|
+
invert(changes) {
|
|
185
|
+
const ret = wasm.tiptapdoc_invert(this.__wbg_ptr, changes);
|
|
186
|
+
if (ret[2]) {
|
|
187
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
188
|
+
}
|
|
189
|
+
return takeFromExternrefTable0(ret[0]);
|
|
190
|
+
}
|
|
154
191
|
/**
|
|
155
192
|
* True if the document has no schema violations.
|
|
156
193
|
* @param {any} schema
|
|
@@ -616,6 +653,12 @@ function addToExternrefTable0(obj) {
|
|
|
616
653
|
return idx;
|
|
617
654
|
}
|
|
618
655
|
|
|
656
|
+
function _assertClass(instance, klass) {
|
|
657
|
+
if (!(instance instanceof klass)) {
|
|
658
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
619
662
|
function debugString(val) {
|
|
620
663
|
// primitive types
|
|
621
664
|
const type = typeof val;
|
|
Binary file
|