loro-crdt 1.0.9 → 1.1.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 +16 -0
- package/bundler/loro_wasm.d.ts +114 -35
- package/bundler/loro_wasm_bg.js +177 -20
- package/bundler/loro_wasm_bg.wasm +0 -0
- package/bundler/loro_wasm_bg.wasm.d.ts +14 -3
- package/nodejs/loro_wasm.d.ts +114 -35
- package/nodejs/loro_wasm.js +177 -20
- package/nodejs/loro_wasm_bg.wasm +0 -0
- package/nodejs/loro_wasm_bg.wasm.d.ts +14 -3
- package/package.json +1 -1
- package/web/loro_wasm.d.ts +128 -38
- package/web/loro_wasm.js +176 -19
- package/web/loro_wasm_bg.wasm +0 -0
- package/web/loro_wasm_bg.wasm.d.ts +14 -3
package/nodejs/loro_wasm.d.ts
CHANGED
|
@@ -26,12 +26,13 @@ export function setDebug(): void;
|
|
|
26
26
|
* - endVersionVector
|
|
27
27
|
* - startTimestamp
|
|
28
28
|
* - endTimestamp
|
|
29
|
-
* -
|
|
29
|
+
* - mode
|
|
30
30
|
* - changeNum
|
|
31
31
|
* @param {Uint8Array} blob
|
|
32
|
+
* @param {boolean} check_checksum
|
|
32
33
|
* @returns {ImportBlobMetadata}
|
|
33
34
|
*/
|
|
34
|
-
export function decodeImportBlobMeta(blob: Uint8Array): ImportBlobMetadata;
|
|
35
|
+
export function decodeImportBlobMeta(blob: Uint8Array, check_checksum: boolean): ImportBlobMetadata;
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Container types supported by loro.
|
|
@@ -262,7 +263,7 @@ export interface ImportBlobMetadata {
|
|
|
262
263
|
startFrontiers: OpId[],
|
|
263
264
|
startTimestamp: number;
|
|
264
265
|
endTimestamp: number;
|
|
265
|
-
|
|
266
|
+
mode: "outdated-snapshot" | "outdated-update" | "snapshot" | "shallow-snapshot" | "update";
|
|
266
267
|
changeNum: number;
|
|
267
268
|
}
|
|
268
269
|
|
|
@@ -351,6 +352,11 @@ export type TreeNodeValue = {
|
|
|
351
352
|
children: TreeNodeValue[],
|
|
352
353
|
}
|
|
353
354
|
|
|
355
|
+
export type TreeNodeJSON<T> = Omit<TreeNodeValue, 'meta' | 'children'> & {
|
|
356
|
+
meta: T,
|
|
357
|
+
children: TreeNodeJSON<T>[],
|
|
358
|
+
}
|
|
359
|
+
|
|
354
360
|
interface LoroTree{
|
|
355
361
|
toArray(): TreeNodeValue[];
|
|
356
362
|
getNodes(options?: { withDeleted: boolean = false }): LoroTreeNode[];
|
|
@@ -432,6 +438,11 @@ export type JsonChange = {
|
|
|
432
438
|
ops: JsonOp[]
|
|
433
439
|
}
|
|
434
440
|
|
|
441
|
+
export interface TextUpdateOptions {
|
|
442
|
+
timeoutMs?: number,
|
|
443
|
+
useRefinedDiff?: boolean,
|
|
444
|
+
}
|
|
445
|
+
|
|
435
446
|
export type ExportMode = {
|
|
436
447
|
mode: "update",
|
|
437
448
|
from?: VersionVector,
|
|
@@ -1012,6 +1023,32 @@ interface LoroText {
|
|
|
1012
1023
|
insert(pos: number, text: string): void;
|
|
1013
1024
|
delete(pos: number, len: number): void;
|
|
1014
1025
|
subscribe(listener: Listener): Subscription;
|
|
1026
|
+
/**
|
|
1027
|
+
* Update the current text to the target text.
|
|
1028
|
+
*
|
|
1029
|
+
* It will calculate the minimal difference and apply it to the current text.
|
|
1030
|
+
* It uses Myers' diff algorithm to compute the optimal difference.
|
|
1031
|
+
*
|
|
1032
|
+
* This could take a long time for large texts (e.g. > 50_000 characters).
|
|
1033
|
+
* In that case, you should use `updateByLine` instead.
|
|
1034
|
+
*
|
|
1035
|
+
* @example
|
|
1036
|
+
* ```ts
|
|
1037
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1038
|
+
*
|
|
1039
|
+
* const doc = new LoroDoc();
|
|
1040
|
+
* const text = doc.getText("text");
|
|
1041
|
+
* text.insert(0, "Hello");
|
|
1042
|
+
* text.update("Hello World");
|
|
1043
|
+
* console.log(text.toString()); // "Hello World"
|
|
1044
|
+
* ```
|
|
1045
|
+
*/
|
|
1046
|
+
update(text: string, options?: TextUpdateOptions): void;
|
|
1047
|
+
/**
|
|
1048
|
+
* Update the current text based on the provided text.
|
|
1049
|
+
* This update calculation is line-based, which will be more efficient but less precise.
|
|
1050
|
+
*/
|
|
1051
|
+
updateByLine(text: string, options?: TextUpdateOptions): void;
|
|
1015
1052
|
}
|
|
1016
1053
|
interface LoroTree<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
1017
1054
|
new(): LoroTree<T>;
|
|
@@ -1080,6 +1117,7 @@ interface LoroTreeNode<T extends Record<string, unknown> = Record<string, unknow
|
|
|
1080
1117
|
* the WASM boundary.
|
|
1081
1118
|
*/
|
|
1082
1119
|
children(): Array<LoroTreeNode<T>> | undefined;
|
|
1120
|
+
toJSON(): TreeNodeJSON<T>;
|
|
1083
1121
|
}
|
|
1084
1122
|
interface AwarenessWasm<T extends Value = Value> {
|
|
1085
1123
|
getState(peer: PeerID): T | undefined;
|
|
@@ -1532,9 +1570,9 @@ export class LoroDoc {
|
|
|
1532
1570
|
* @param ids - the changes to visit
|
|
1533
1571
|
* @param f - the callback function, return `true` to continue visiting, return `false` to stop
|
|
1534
1572
|
* @param {({ peer: PeerID, counter: number })[]} ids
|
|
1535
|
-
* @param {
|
|
1573
|
+
* @param {(change: ChangeMeta) => boolean} f
|
|
1536
1574
|
*/
|
|
1537
|
-
travelChangeAncestors(ids: ({ peer: PeerID, counter: number })[], f:
|
|
1575
|
+
travelChangeAncestors(ids: ({ peer: PeerID, counter: number })[], f: (change: ChangeMeta) => boolean): void;
|
|
1538
1576
|
/**
|
|
1539
1577
|
* Checkout the `DocState` to a specific version.
|
|
1540
1578
|
*
|
|
@@ -2010,6 +2048,23 @@ export class LoroDoc {
|
|
|
2010
2048
|
*/
|
|
2011
2049
|
getCursorPos(cursor: Cursor): { update?: Cursor, offset: number, side: Side };
|
|
2012
2050
|
/**
|
|
2051
|
+
* Gets container IDs modified in the given ID range.
|
|
2052
|
+
*
|
|
2053
|
+
* **NOTE:** This method will implicitly commit.
|
|
2054
|
+
*
|
|
2055
|
+
* This method identifies which containers were affected by changes in a given range of operations.
|
|
2056
|
+
* It can be used together with `doc.travelChangeAncestors()` to analyze the history of changes
|
|
2057
|
+
* and determine which containers were modified by each change.
|
|
2058
|
+
*
|
|
2059
|
+
* @param id - The starting ID of the change range
|
|
2060
|
+
* @param len - The length of the change range to check
|
|
2061
|
+
* @returns An array of container IDs that were modified in the given range
|
|
2062
|
+
* @param {{ peer: PeerID, counter: number }} id
|
|
2063
|
+
* @param {number} len
|
|
2064
|
+
* @returns {(ContainerID)[]}
|
|
2065
|
+
*/
|
|
2066
|
+
getChangedContainersIn(id: { peer: PeerID, counter: number }, len: number): (ContainerID)[];
|
|
2067
|
+
/**
|
|
2013
2068
|
* Peer ID of the current writer.
|
|
2014
2069
|
*/
|
|
2015
2070
|
readonly peerId: bigint;
|
|
@@ -2105,6 +2160,11 @@ export class LoroList {
|
|
|
2105
2160
|
*/
|
|
2106
2161
|
clear(): void;
|
|
2107
2162
|
/**
|
|
2163
|
+
* @param {number} pos
|
|
2164
|
+
* @returns {{ peer: PeerID, counter: number } | undefined}
|
|
2165
|
+
*/
|
|
2166
|
+
getIdAt(pos: number): { peer: PeerID, counter: number } | undefined;
|
|
2167
|
+
/**
|
|
2108
2168
|
* Get the id of this container.
|
|
2109
2169
|
*/
|
|
2110
2170
|
readonly id: ContainerID;
|
|
@@ -2255,6 +2315,12 @@ export class LoroMap {
|
|
|
2255
2315
|
*/
|
|
2256
2316
|
clear(): void;
|
|
2257
2317
|
/**
|
|
2318
|
+
* Get the peer id of the last editor on the given entry
|
|
2319
|
+
* @param {string} key
|
|
2320
|
+
* @returns {PeerID | undefined}
|
|
2321
|
+
*/
|
|
2322
|
+
getLastEditor(key: string): PeerID | undefined;
|
|
2323
|
+
/**
|
|
2258
2324
|
* The container id of this handler.
|
|
2259
2325
|
*/
|
|
2260
2326
|
readonly id: ContainerID;
|
|
@@ -2375,6 +2441,24 @@ export class LoroMovableList {
|
|
|
2375
2441
|
*/
|
|
2376
2442
|
clear(): void;
|
|
2377
2443
|
/**
|
|
2444
|
+
* Get the creator of the list item at the given position.
|
|
2445
|
+
* @param {number} pos
|
|
2446
|
+
* @returns {PeerID | undefined}
|
|
2447
|
+
*/
|
|
2448
|
+
getCreatorAt(pos: number): PeerID | undefined;
|
|
2449
|
+
/**
|
|
2450
|
+
* Get the last mover of the list item at the given position.
|
|
2451
|
+
* @param {number} pos
|
|
2452
|
+
* @returns {PeerID | undefined}
|
|
2453
|
+
*/
|
|
2454
|
+
getLastMoverAt(pos: number): PeerID | undefined;
|
|
2455
|
+
/**
|
|
2456
|
+
* Get the last editor of the list item at the given position.
|
|
2457
|
+
* @param {number} pos
|
|
2458
|
+
* @returns {PeerID | undefined}
|
|
2459
|
+
*/
|
|
2460
|
+
getLastEditorAt(pos: number): PeerID | undefined;
|
|
2461
|
+
/**
|
|
2378
2462
|
* Get the id of this container.
|
|
2379
2463
|
*/
|
|
2380
2464
|
readonly id: ContainerID;
|
|
@@ -2415,11 +2499,14 @@ export class LoroText {
|
|
|
2415
2499
|
*/
|
|
2416
2500
|
kind(): 'Text';
|
|
2417
2501
|
/**
|
|
2418
|
-
* Iterate each span(internal storage unit)
|
|
2502
|
+
* Iterate each text span(internal storage unit)
|
|
2419
2503
|
*
|
|
2420
2504
|
* The callback function will be called for each span in the text.
|
|
2421
2505
|
* If the callback returns `false`, the iteration will stop.
|
|
2422
2506
|
*
|
|
2507
|
+
* Limitation: you cannot access or alter the doc state when iterating (this is for performance consideration).
|
|
2508
|
+
* If you need to access or alter the doc state, please use `toString` instead.
|
|
2509
|
+
*
|
|
2423
2510
|
* @example
|
|
2424
2511
|
* ```ts
|
|
2425
2512
|
* import { LoroDoc } from "loro-crdt";
|
|
@@ -2433,35 +2520,6 @@ export class LoroText {
|
|
|
2433
2520
|
*/
|
|
2434
2521
|
iter(callback: Function): void;
|
|
2435
2522
|
/**
|
|
2436
|
-
* Update the current text to the target text.
|
|
2437
|
-
*
|
|
2438
|
-
* It will calculate the minimal difference and apply it to the current text.
|
|
2439
|
-
* It uses Myers' diff algorithm to compute the optimal difference.
|
|
2440
|
-
*
|
|
2441
|
-
* This could take a long time for large texts (e.g. > 50_000 characters).
|
|
2442
|
-
* In that case, you should use `updateByLine` instead.
|
|
2443
|
-
*
|
|
2444
|
-
* @example
|
|
2445
|
-
* ```ts
|
|
2446
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2447
|
-
*
|
|
2448
|
-
* const doc = new LoroDoc();
|
|
2449
|
-
* const text = doc.getText("text");
|
|
2450
|
-
* text.insert(0, "Hello");
|
|
2451
|
-
* text.update("Hello World");
|
|
2452
|
-
* console.log(text.toString()); // "Hello World"
|
|
2453
|
-
* ```
|
|
2454
|
-
* @param {string} text
|
|
2455
|
-
*/
|
|
2456
|
-
update(text: string): void;
|
|
2457
|
-
/**
|
|
2458
|
-
* Update the current text to the target text, the difference is calculated line by line.
|
|
2459
|
-
*
|
|
2460
|
-
* It uses Myers' diff algorithm to compute the optimal difference.
|
|
2461
|
-
* @param {string} text
|
|
2462
|
-
*/
|
|
2463
|
-
updateByLine(text: string): void;
|
|
2464
|
-
/**
|
|
2465
2523
|
* Insert the string at the given index (utf-16 index).
|
|
2466
2524
|
*
|
|
2467
2525
|
* @example
|
|
@@ -2705,6 +2763,12 @@ export class LoroText {
|
|
|
2705
2763
|
*/
|
|
2706
2764
|
push(s: string): void;
|
|
2707
2765
|
/**
|
|
2766
|
+
* Get the editor of the text at the given position.
|
|
2767
|
+
* @param {number} pos
|
|
2768
|
+
* @returns {PeerID | undefined}
|
|
2769
|
+
*/
|
|
2770
|
+
getEditorOf(pos: number): PeerID | undefined;
|
|
2771
|
+
/**
|
|
2708
2772
|
* Get the container id of the text.
|
|
2709
2773
|
*/
|
|
2710
2774
|
readonly id: ContainerID;
|
|
@@ -2974,6 +3038,21 @@ export class LoroTreeNode {
|
|
|
2974
3038
|
*/
|
|
2975
3039
|
isDeleted(): boolean;
|
|
2976
3040
|
/**
|
|
3041
|
+
* Get the last mover of this node.
|
|
3042
|
+
* @returns {{ peer: PeerID, counter: number } | undefined}
|
|
3043
|
+
*/
|
|
3044
|
+
getLastMoveId(): { peer: PeerID, counter: number } | undefined;
|
|
3045
|
+
/**
|
|
3046
|
+
* Get the creation id of this node.
|
|
3047
|
+
* @returns {{ peer: PeerID, counter: number }}
|
|
3048
|
+
*/
|
|
3049
|
+
creationId(): { peer: PeerID, counter: number };
|
|
3050
|
+
/**
|
|
3051
|
+
* Get the creator of this node.
|
|
3052
|
+
* @returns {PeerID}
|
|
3053
|
+
*/
|
|
3054
|
+
creator(): PeerID;
|
|
3055
|
+
/**
|
|
2977
3056
|
* The TreeID of the node.
|
|
2978
3057
|
*/
|
|
2979
3058
|
readonly id: TreeID;
|
package/nodejs/loro_wasm.js
CHANGED
|
@@ -363,17 +363,18 @@ function _assertClass(instance, klass) {
|
|
|
363
363
|
* - endVersionVector
|
|
364
364
|
* - startTimestamp
|
|
365
365
|
* - endTimestamp
|
|
366
|
-
* -
|
|
366
|
+
* - mode
|
|
367
367
|
* - changeNum
|
|
368
368
|
* @param {Uint8Array} blob
|
|
369
|
+
* @param {boolean} check_checksum
|
|
369
370
|
* @returns {ImportBlobMetadata}
|
|
370
371
|
*/
|
|
371
|
-
module.exports.decodeImportBlobMeta = function(blob) {
|
|
372
|
+
module.exports.decodeImportBlobMeta = function(blob, check_checksum) {
|
|
372
373
|
try {
|
|
373
374
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
374
375
|
const ptr0 = passArray8ToWasm0(blob, wasm.__wbindgen_export_0);
|
|
375
376
|
const len0 = WASM_VECTOR_LEN;
|
|
376
|
-
wasm.decodeImportBlobMeta(retptr, ptr0, len0);
|
|
377
|
+
wasm.decodeImportBlobMeta(retptr, ptr0, len0, check_checksum);
|
|
377
378
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
378
379
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
379
380
|
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
@@ -1208,7 +1209,7 @@ class LoroDoc {
|
|
|
1208
1209
|
* @param ids - the changes to visit
|
|
1209
1210
|
* @param f - the callback function, return `true` to continue visiting, return `false` to stop
|
|
1210
1211
|
* @param {({ peer: PeerID, counter: number })[]} ids
|
|
1211
|
-
* @param {
|
|
1212
|
+
* @param {(change: ChangeMeta) => boolean} f
|
|
1212
1213
|
*/
|
|
1213
1214
|
travelChangeAncestors(ids, f) {
|
|
1214
1215
|
try {
|
|
@@ -2355,6 +2356,40 @@ class LoroDoc {
|
|
|
2355
2356
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2356
2357
|
}
|
|
2357
2358
|
}
|
|
2359
|
+
/**
|
|
2360
|
+
* Gets container IDs modified in the given ID range.
|
|
2361
|
+
*
|
|
2362
|
+
* **NOTE:** This method will implicitly commit.
|
|
2363
|
+
*
|
|
2364
|
+
* This method identifies which containers were affected by changes in a given range of operations.
|
|
2365
|
+
* It can be used together with `doc.travelChangeAncestors()` to analyze the history of changes
|
|
2366
|
+
* and determine which containers were modified by each change.
|
|
2367
|
+
*
|
|
2368
|
+
* @param id - The starting ID of the change range
|
|
2369
|
+
* @param len - The length of the change range to check
|
|
2370
|
+
* @returns An array of container IDs that were modified in the given range
|
|
2371
|
+
* @param {{ peer: PeerID, counter: number }} id
|
|
2372
|
+
* @param {number} len
|
|
2373
|
+
* @returns {(ContainerID)[]}
|
|
2374
|
+
*/
|
|
2375
|
+
getChangedContainersIn(id, len) {
|
|
2376
|
+
try {
|
|
2377
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
2378
|
+
wasm.lorodoc_getChangedContainersIn(retptr, this.__wbg_ptr, addHeapObject(id), len);
|
|
2379
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
2380
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
2381
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
2382
|
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
2383
|
+
if (r3) {
|
|
2384
|
+
throw takeObject(r2);
|
|
2385
|
+
}
|
|
2386
|
+
var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
2387
|
+
wasm.__wbindgen_export_5(r0, r1 * 4, 4);
|
|
2388
|
+
return v1;
|
|
2389
|
+
} finally {
|
|
2390
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2358
2393
|
}
|
|
2359
2394
|
module.exports.LoroDoc = LoroDoc;
|
|
2360
2395
|
|
|
@@ -2756,6 +2791,14 @@ class LoroList {
|
|
|
2756
2791
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2757
2792
|
}
|
|
2758
2793
|
}
|
|
2794
|
+
/**
|
|
2795
|
+
* @param {number} pos
|
|
2796
|
+
* @returns {{ peer: PeerID, counter: number } | undefined}
|
|
2797
|
+
*/
|
|
2798
|
+
getIdAt(pos) {
|
|
2799
|
+
const ret = wasm.lorolist_getIdAt(this.__wbg_ptr, pos);
|
|
2800
|
+
return takeObject(ret);
|
|
2801
|
+
}
|
|
2759
2802
|
}
|
|
2760
2803
|
module.exports.LoroList = LoroList;
|
|
2761
2804
|
|
|
@@ -3188,6 +3231,17 @@ class LoroMap {
|
|
|
3188
3231
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
3189
3232
|
}
|
|
3190
3233
|
}
|
|
3234
|
+
/**
|
|
3235
|
+
* Get the peer id of the last editor on the given entry
|
|
3236
|
+
* @param {string} key
|
|
3237
|
+
* @returns {PeerID | undefined}
|
|
3238
|
+
*/
|
|
3239
|
+
getLastEditor(key) {
|
|
3240
|
+
const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
|
3241
|
+
const len0 = WASM_VECTOR_LEN;
|
|
3242
|
+
const ret = wasm.loromap_getLastEditor(this.__wbg_ptr, ptr0, len0);
|
|
3243
|
+
return takeObject(ret);
|
|
3244
|
+
}
|
|
3191
3245
|
}
|
|
3192
3246
|
module.exports.LoroMap = LoroMap;
|
|
3193
3247
|
|
|
@@ -3661,6 +3715,33 @@ class LoroMovableList {
|
|
|
3661
3715
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
3662
3716
|
}
|
|
3663
3717
|
}
|
|
3718
|
+
/**
|
|
3719
|
+
* Get the creator of the list item at the given position.
|
|
3720
|
+
* @param {number} pos
|
|
3721
|
+
* @returns {PeerID | undefined}
|
|
3722
|
+
*/
|
|
3723
|
+
getCreatorAt(pos) {
|
|
3724
|
+
const ret = wasm.loromovablelist_getCreatorAt(this.__wbg_ptr, pos);
|
|
3725
|
+
return takeObject(ret);
|
|
3726
|
+
}
|
|
3727
|
+
/**
|
|
3728
|
+
* Get the last mover of the list item at the given position.
|
|
3729
|
+
* @param {number} pos
|
|
3730
|
+
* @returns {PeerID | undefined}
|
|
3731
|
+
*/
|
|
3732
|
+
getLastMoverAt(pos) {
|
|
3733
|
+
const ret = wasm.loromovablelist_getLastMoverAt(this.__wbg_ptr, pos);
|
|
3734
|
+
return takeObject(ret);
|
|
3735
|
+
}
|
|
3736
|
+
/**
|
|
3737
|
+
* Get the last editor of the list item at the given position.
|
|
3738
|
+
* @param {number} pos
|
|
3739
|
+
* @returns {PeerID | undefined}
|
|
3740
|
+
*/
|
|
3741
|
+
getLastEditorAt(pos) {
|
|
3742
|
+
const ret = wasm.loromovablelist_getLastEditorAt(this.__wbg_ptr, pos);
|
|
3743
|
+
return takeObject(ret);
|
|
3744
|
+
}
|
|
3664
3745
|
}
|
|
3665
3746
|
module.exports.LoroMovableList = LoroMovableList;
|
|
3666
3747
|
|
|
@@ -3713,11 +3794,14 @@ class LoroText {
|
|
|
3713
3794
|
return takeObject(ret);
|
|
3714
3795
|
}
|
|
3715
3796
|
/**
|
|
3716
|
-
* Iterate each span(internal storage unit)
|
|
3797
|
+
* Iterate each text span(internal storage unit)
|
|
3717
3798
|
*
|
|
3718
3799
|
* The callback function will be called for each span in the text.
|
|
3719
3800
|
* If the callback returns `false`, the iteration will stop.
|
|
3720
3801
|
*
|
|
3802
|
+
* Limitation: you cannot access or alter the doc state when iterating (this is for performance consideration).
|
|
3803
|
+
* If you need to access or alter the doc state, please use `toString` instead.
|
|
3804
|
+
*
|
|
3721
3805
|
* @example
|
|
3722
3806
|
* ```ts
|
|
3723
3807
|
* import { LoroDoc } from "loro-crdt";
|
|
@@ -3756,22 +3840,44 @@ class LoroText {
|
|
|
3756
3840
|
* console.log(text.toString()); // "Hello World"
|
|
3757
3841
|
* ```
|
|
3758
3842
|
* @param {string} text
|
|
3843
|
+
* @param {any} options
|
|
3759
3844
|
*/
|
|
3760
|
-
update(text) {
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3845
|
+
update(text, options) {
|
|
3846
|
+
try {
|
|
3847
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
3848
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
|
3849
|
+
const len0 = WASM_VECTOR_LEN;
|
|
3850
|
+
wasm.lorotext_update(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(options));
|
|
3851
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
3852
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
3853
|
+
if (r1) {
|
|
3854
|
+
throw takeObject(r0);
|
|
3855
|
+
}
|
|
3856
|
+
} finally {
|
|
3857
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
3858
|
+
}
|
|
3764
3859
|
}
|
|
3765
3860
|
/**
|
|
3766
3861
|
* Update the current text to the target text, the difference is calculated line by line.
|
|
3767
3862
|
*
|
|
3768
3863
|
* It uses Myers' diff algorithm to compute the optimal difference.
|
|
3769
3864
|
* @param {string} text
|
|
3865
|
+
* @param {any} options
|
|
3770
3866
|
*/
|
|
3771
|
-
updateByLine(text) {
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3867
|
+
updateByLine(text, options) {
|
|
3868
|
+
try {
|
|
3869
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
3870
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
|
3871
|
+
const len0 = WASM_VECTOR_LEN;
|
|
3872
|
+
wasm.lorotext_updateByLine(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(options));
|
|
3873
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
3874
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
3875
|
+
if (r1) {
|
|
3876
|
+
throw takeObject(r0);
|
|
3877
|
+
}
|
|
3878
|
+
} finally {
|
|
3879
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
3880
|
+
}
|
|
3775
3881
|
}
|
|
3776
3882
|
/**
|
|
3777
3883
|
* Insert the string at the given index (utf-16 index).
|
|
@@ -4269,6 +4375,15 @@ class LoroText {
|
|
|
4269
4375
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
4270
4376
|
}
|
|
4271
4377
|
}
|
|
4378
|
+
/**
|
|
4379
|
+
* Get the editor of the text at the given position.
|
|
4380
|
+
* @param {number} pos
|
|
4381
|
+
* @returns {PeerID | undefined}
|
|
4382
|
+
*/
|
|
4383
|
+
getEditorOf(pos) {
|
|
4384
|
+
const ret = wasm.lorotext_getEditorOf(this.__wbg_ptr, pos);
|
|
4385
|
+
return takeObject(ret);
|
|
4386
|
+
}
|
|
4272
4387
|
}
|
|
4273
4388
|
module.exports.LoroText = LoroText;
|
|
4274
4389
|
|
|
@@ -4965,6 +5080,24 @@ class LoroTreeNode {
|
|
|
4965
5080
|
}
|
|
4966
5081
|
}
|
|
4967
5082
|
/**
|
|
5083
|
+
* @returns {any}
|
|
5084
|
+
*/
|
|
5085
|
+
toJSON() {
|
|
5086
|
+
try {
|
|
5087
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
5088
|
+
wasm.lorotreenode_toJSON(retptr, this.__wbg_ptr);
|
|
5089
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
5090
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
5091
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
5092
|
+
if (r2) {
|
|
5093
|
+
throw takeObject(r1);
|
|
5094
|
+
}
|
|
5095
|
+
return takeObject(r0);
|
|
5096
|
+
} finally {
|
|
5097
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
5098
|
+
}
|
|
5099
|
+
}
|
|
5100
|
+
/**
|
|
4968
5101
|
* Get the parent node of this node.
|
|
4969
5102
|
*
|
|
4970
5103
|
* - The parent of the root node is `undefined`.
|
|
@@ -5017,6 +5150,30 @@ class LoroTreeNode {
|
|
|
5017
5150
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
5018
5151
|
}
|
|
5019
5152
|
}
|
|
5153
|
+
/**
|
|
5154
|
+
* Get the last mover of this node.
|
|
5155
|
+
* @returns {{ peer: PeerID, counter: number } | undefined}
|
|
5156
|
+
*/
|
|
5157
|
+
getLastMoveId() {
|
|
5158
|
+
const ret = wasm.lorotreenode_getLastMoveId(this.__wbg_ptr);
|
|
5159
|
+
return takeObject(ret);
|
|
5160
|
+
}
|
|
5161
|
+
/**
|
|
5162
|
+
* Get the creation id of this node.
|
|
5163
|
+
* @returns {{ peer: PeerID, counter: number }}
|
|
5164
|
+
*/
|
|
5165
|
+
creationId() {
|
|
5166
|
+
const ret = wasm.lorotreenode_creationId(this.__wbg_ptr);
|
|
5167
|
+
return takeObject(ret);
|
|
5168
|
+
}
|
|
5169
|
+
/**
|
|
5170
|
+
* Get the creator of this node.
|
|
5171
|
+
* @returns {PeerID}
|
|
5172
|
+
*/
|
|
5173
|
+
creator() {
|
|
5174
|
+
const ret = wasm.lorotreenode_creator(this.__wbg_ptr);
|
|
5175
|
+
return takeObject(ret);
|
|
5176
|
+
}
|
|
5020
5177
|
}
|
|
5021
5178
|
module.exports.LoroTreeNode = LoroTreeNode;
|
|
5022
5179
|
|
|
@@ -5407,6 +5564,11 @@ module.exports.__wbg_versionvector_new = function(arg0) {
|
|
|
5407
5564
|
return addHeapObject(ret);
|
|
5408
5565
|
};
|
|
5409
5566
|
|
|
5567
|
+
module.exports.__wbindgen_is_function = function(arg0) {
|
|
5568
|
+
const ret = typeof(getObject(arg0)) === 'function';
|
|
5569
|
+
return ret;
|
|
5570
|
+
};
|
|
5571
|
+
|
|
5410
5572
|
module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
5411
5573
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
5412
5574
|
return addHeapObject(ret);
|
|
@@ -5495,11 +5657,6 @@ module.exports.__wbindgen_as_number = function(arg0) {
|
|
|
5495
5657
|
return ret;
|
|
5496
5658
|
};
|
|
5497
5659
|
|
|
5498
|
-
module.exports.__wbindgen_is_function = function(arg0) {
|
|
5499
|
-
const ret = typeof(getObject(arg0)) === 'function';
|
|
5500
|
-
return ret;
|
|
5501
|
-
};
|
|
5502
|
-
|
|
5503
5660
|
module.exports.__wbindgen_is_string = function(arg0) {
|
|
5504
5661
|
const ret = typeof(getObject(arg0)) === 'string';
|
|
5505
5662
|
return ret;
|
|
@@ -5944,12 +6101,12 @@ module.exports.__wbindgen_memory = function() {
|
|
|
5944
6101
|
return addHeapObject(ret);
|
|
5945
6102
|
};
|
|
5946
6103
|
|
|
5947
|
-
module.exports.
|
|
6104
|
+
module.exports.__wbindgen_closure_wrapper491 = function(arg0, arg1, arg2) {
|
|
5948
6105
|
const ret = makeMutClosure(arg0, arg1, 9, __wbg_adapter_58);
|
|
5949
6106
|
return addHeapObject(ret);
|
|
5950
6107
|
};
|
|
5951
6108
|
|
|
5952
|
-
module.exports.
|
|
6109
|
+
module.exports.__wbindgen_closure_wrapper494 = function(arg0, arg1, arg2) {
|
|
5953
6110
|
const ret = makeMutClosure(arg0, arg1, 11, __wbg_adapter_61);
|
|
5954
6111
|
return addHeapObject(ret);
|
|
5955
6112
|
};
|
package/nodejs/loro_wasm_bg.wasm
CHANGED
|
Binary file
|
|
@@ -89,12 +89,13 @@ export function lorodoc_frontiersToVV(a: number, b: number, c: number, d: number
|
|
|
89
89
|
export function lorodoc_vvToFrontiers(a: number, b: number, c: number): void;
|
|
90
90
|
export function lorodoc_getByPath(a: number, b: number, c: number): number;
|
|
91
91
|
export function lorodoc_getCursorPos(a: number, b: number, c: number): void;
|
|
92
|
+
export function lorodoc_getChangedContainersIn(a: number, b: number, c: number, d: number): void;
|
|
92
93
|
export function __wbg_lorotext_free(a: number): void;
|
|
93
94
|
export function lorotext_new(): number;
|
|
94
95
|
export function lorotext_kind(a: number): number;
|
|
95
96
|
export function lorotext_iter(a: number, b: number): void;
|
|
96
|
-
export function lorotext_update(a: number, b: number, c: number): void;
|
|
97
|
-
export function lorotext_updateByLine(a: number, b: number, c: number): void;
|
|
97
|
+
export function lorotext_update(a: number, b: number, c: number, d: number, e: number): void;
|
|
98
|
+
export function lorotext_updateByLine(a: number, b: number, c: number, d: number, e: number): void;
|
|
98
99
|
export function lorotext_insert(a: number, b: number, c: number, d: number, e: number): void;
|
|
99
100
|
export function lorotext_slice(a: number, b: number, c: number, d: number): void;
|
|
100
101
|
export function lorotext_charAt(a: number, b: number, c: number): void;
|
|
@@ -114,6 +115,7 @@ export function lorotext_parent(a: number): number;
|
|
|
114
115
|
export function lorotext_getAttached(a: number): number;
|
|
115
116
|
export function lorotext_getCursor(a: number, b: number, c: number): number;
|
|
116
117
|
export function lorotext_push(a: number, b: number, c: number, d: number): void;
|
|
118
|
+
export function lorotext_getEditorOf(a: number, b: number): number;
|
|
117
119
|
export function __wbg_loromap_free(a: number): void;
|
|
118
120
|
export function loromap_new(): number;
|
|
119
121
|
export function loromap_kind(a: number): number;
|
|
@@ -132,6 +134,7 @@ export function loromap_size(a: number): number;
|
|
|
132
134
|
export function loromap_parent(a: number): number;
|
|
133
135
|
export function loromap_getAttached(a: number): number;
|
|
134
136
|
export function loromap_clear(a: number, b: number): void;
|
|
137
|
+
export function loromap_getLastEditor(a: number, b: number, c: number): number;
|
|
135
138
|
export function __wbg_lorolist_free(a: number): void;
|
|
136
139
|
export function lorolist_new(): number;
|
|
137
140
|
export function lorolist_kind(a: number): number;
|
|
@@ -152,6 +155,7 @@ export function lorolist_getCursor(a: number, b: number, c: number): number;
|
|
|
152
155
|
export function lorolist_push(a: number, b: number, c: number): void;
|
|
153
156
|
export function lorolist_pop(a: number, b: number): void;
|
|
154
157
|
export function lorolist_clear(a: number, b: number): void;
|
|
158
|
+
export function lorolist_getIdAt(a: number, b: number): number;
|
|
155
159
|
export function loromovablelist_new(): number;
|
|
156
160
|
export function loromovablelist_kind(a: number): number;
|
|
157
161
|
export function loromovablelist_insert(a: number, b: number, c: number, d: number): void;
|
|
@@ -172,6 +176,9 @@ export function loromovablelist_setContainer(a: number, b: number, c: number, d:
|
|
|
172
176
|
export function loromovablelist_push(a: number, b: number, c: number): void;
|
|
173
177
|
export function loromovablelist_pop(a: number, b: number): void;
|
|
174
178
|
export function loromovablelist_clear(a: number, b: number): void;
|
|
179
|
+
export function loromovablelist_getCreatorAt(a: number, b: number): number;
|
|
180
|
+
export function loromovablelist_getLastMoverAt(a: number, b: number): number;
|
|
181
|
+
export function loromovablelist_getLastEditorAt(a: number, b: number): number;
|
|
175
182
|
export function __wbg_lorotree_free(a: number): void;
|
|
176
183
|
export function lorotreenode___getClassname(a: number, b: number): void;
|
|
177
184
|
export function __wbg_lorotreenode_free(a: number): void;
|
|
@@ -183,9 +190,13 @@ export function lorotreenode_moveBefore(a: number, b: number, c: number): void;
|
|
|
183
190
|
export function lorotreenode_index(a: number, b: number): void;
|
|
184
191
|
export function lorotreenode_fractionalIndex(a: number, b: number): void;
|
|
185
192
|
export function lorotreenode_data(a: number, b: number): void;
|
|
193
|
+
export function lorotreenode_toJSON(a: number, b: number): void;
|
|
186
194
|
export function lorotreenode_parent(a: number, b: number): void;
|
|
187
195
|
export function lorotreenode_children(a: number): number;
|
|
188
196
|
export function lorotreenode_isDeleted(a: number, b: number): void;
|
|
197
|
+
export function lorotreenode_getLastMoveId(a: number): number;
|
|
198
|
+
export function lorotreenode_creationId(a: number): number;
|
|
199
|
+
export function lorotreenode_creator(a: number): number;
|
|
189
200
|
export function lorotree_new(): number;
|
|
190
201
|
export function lorotree_kind(a: number): number;
|
|
191
202
|
export function lorotree_createNode(a: number, b: number, c: number, d: number, e: number): void;
|
|
@@ -235,7 +246,7 @@ export function versionvector_encode(a: number, b: number): void;
|
|
|
235
246
|
export function versionvector_decode(a: number, b: number, c: number): void;
|
|
236
247
|
export function versionvector_get(a: number, b: number, c: number): void;
|
|
237
248
|
export function versionvector_compare(a: number, b: number, c: number): void;
|
|
238
|
-
export function decodeImportBlobMeta(a: number, b: number, c: number): void;
|
|
249
|
+
export function decodeImportBlobMeta(a: number, b: number, c: number, d: number): void;
|
|
239
250
|
export function __wbg_loromovablelist_free(a: number): void;
|
|
240
251
|
export function loromovablelist_parent(a: number): number;
|
|
241
252
|
export function lorotext_isAttached(a: number): number;
|
package/package.json
CHANGED