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.
@@ -26,12 +26,13 @@ export function setDebug(): void;
26
26
  * - endVersionVector
27
27
  * - startTimestamp
28
28
  * - endTimestamp
29
- * - isSnapshot
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
- isSnapshot: boolean;
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 {Function} f
1573
+ * @param {(change: ChangeMeta) => boolean} f
1536
1574
  */
1537
- travelChangeAncestors(ids: ({ peer: PeerID, counter: number })[], f: Function): void;
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) of the text.
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;
@@ -3212,12 +3291,13 @@ export interface InitOutput {
3212
3291
  readonly lorodoc_vvToFrontiers: (a: number, b: number, c: number) => void;
3213
3292
  readonly lorodoc_getByPath: (a: number, b: number, c: number) => number;
3214
3293
  readonly lorodoc_getCursorPos: (a: number, b: number, c: number) => void;
3294
+ readonly lorodoc_getChangedContainersIn: (a: number, b: number, c: number, d: number) => void;
3215
3295
  readonly __wbg_lorotext_free: (a: number) => void;
3216
3296
  readonly lorotext_new: () => number;
3217
3297
  readonly lorotext_kind: (a: number) => number;
3218
3298
  readonly lorotext_iter: (a: number, b: number) => void;
3219
- readonly lorotext_update: (a: number, b: number, c: number) => void;
3220
- readonly lorotext_updateByLine: (a: number, b: number, c: number) => void;
3299
+ readonly lorotext_update: (a: number, b: number, c: number, d: number, e: number) => void;
3300
+ readonly lorotext_updateByLine: (a: number, b: number, c: number, d: number, e: number) => void;
3221
3301
  readonly lorotext_insert: (a: number, b: number, c: number, d: number, e: number) => void;
3222
3302
  readonly lorotext_slice: (a: number, b: number, c: number, d: number) => void;
3223
3303
  readonly lorotext_charAt: (a: number, b: number, c: number) => void;
@@ -3237,6 +3317,7 @@ export interface InitOutput {
3237
3317
  readonly lorotext_getAttached: (a: number) => number;
3238
3318
  readonly lorotext_getCursor: (a: number, b: number, c: number) => number;
3239
3319
  readonly lorotext_push: (a: number, b: number, c: number, d: number) => void;
3320
+ readonly lorotext_getEditorOf: (a: number, b: number) => number;
3240
3321
  readonly __wbg_loromap_free: (a: number) => void;
3241
3322
  readonly loromap_new: () => number;
3242
3323
  readonly loromap_kind: (a: number) => number;
@@ -3255,6 +3336,7 @@ export interface InitOutput {
3255
3336
  readonly loromap_parent: (a: number) => number;
3256
3337
  readonly loromap_getAttached: (a: number) => number;
3257
3338
  readonly loromap_clear: (a: number, b: number) => void;
3339
+ readonly loromap_getLastEditor: (a: number, b: number, c: number) => number;
3258
3340
  readonly __wbg_lorolist_free: (a: number) => void;
3259
3341
  readonly lorolist_new: () => number;
3260
3342
  readonly lorolist_kind: (a: number) => number;
@@ -3275,6 +3357,7 @@ export interface InitOutput {
3275
3357
  readonly lorolist_push: (a: number, b: number, c: number) => void;
3276
3358
  readonly lorolist_pop: (a: number, b: number) => void;
3277
3359
  readonly lorolist_clear: (a: number, b: number) => void;
3360
+ readonly lorolist_getIdAt: (a: number, b: number) => number;
3278
3361
  readonly loromovablelist_new: () => number;
3279
3362
  readonly loromovablelist_kind: (a: number) => number;
3280
3363
  readonly loromovablelist_insert: (a: number, b: number, c: number, d: number) => void;
@@ -3295,6 +3378,9 @@ export interface InitOutput {
3295
3378
  readonly loromovablelist_push: (a: number, b: number, c: number) => void;
3296
3379
  readonly loromovablelist_pop: (a: number, b: number) => void;
3297
3380
  readonly loromovablelist_clear: (a: number, b: number) => void;
3381
+ readonly loromovablelist_getCreatorAt: (a: number, b: number) => number;
3382
+ readonly loromovablelist_getLastMoverAt: (a: number, b: number) => number;
3383
+ readonly loromovablelist_getLastEditorAt: (a: number, b: number) => number;
3298
3384
  readonly __wbg_lorotree_free: (a: number) => void;
3299
3385
  readonly lorotreenode___getClassname: (a: number, b: number) => void;
3300
3386
  readonly __wbg_lorotreenode_free: (a: number) => void;
@@ -3306,9 +3392,13 @@ export interface InitOutput {
3306
3392
  readonly lorotreenode_index: (a: number, b: number) => void;
3307
3393
  readonly lorotreenode_fractionalIndex: (a: number, b: number) => void;
3308
3394
  readonly lorotreenode_data: (a: number, b: number) => void;
3395
+ readonly lorotreenode_toJSON: (a: number, b: number) => void;
3309
3396
  readonly lorotreenode_parent: (a: number, b: number) => void;
3310
3397
  readonly lorotreenode_children: (a: number) => number;
3311
3398
  readonly lorotreenode_isDeleted: (a: number, b: number) => void;
3399
+ readonly lorotreenode_getLastMoveId: (a: number) => number;
3400
+ readonly lorotreenode_creationId: (a: number) => number;
3401
+ readonly lorotreenode_creator: (a: number) => number;
3312
3402
  readonly lorotree_new: () => number;
3313
3403
  readonly lorotree_kind: (a: number) => number;
3314
3404
  readonly lorotree_createNode: (a: number, b: number, c: number, d: number, e: number) => void;
@@ -3358,7 +3448,7 @@ export interface InitOutput {
3358
3448
  readonly versionvector_decode: (a: number, b: number, c: number) => void;
3359
3449
  readonly versionvector_get: (a: number, b: number, c: number) => void;
3360
3450
  readonly versionvector_compare: (a: number, b: number, c: number) => void;
3361
- readonly decodeImportBlobMeta: (a: number, b: number, c: number) => void;
3451
+ readonly decodeImportBlobMeta: (a: number, b: number, c: number, d: number) => void;
3362
3452
  readonly __wbg_loromovablelist_free: (a: number) => void;
3363
3453
  readonly loromovablelist_parent: (a: number) => number;
3364
3454
  readonly lorotext_isAttached: (a: number) => number;
package/web/loro_wasm.js CHANGED
@@ -360,17 +360,18 @@ function _assertClass(instance, klass) {
360
360
  * - endVersionVector
361
361
  * - startTimestamp
362
362
  * - endTimestamp
363
- * - isSnapshot
363
+ * - mode
364
364
  * - changeNum
365
365
  * @param {Uint8Array} blob
366
+ * @param {boolean} check_checksum
366
367
  * @returns {ImportBlobMetadata}
367
368
  */
368
- export function decodeImportBlobMeta(blob) {
369
+ export function decodeImportBlobMeta(blob, check_checksum) {
369
370
  try {
370
371
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
371
372
  const ptr0 = passArray8ToWasm0(blob, wasm.__wbindgen_export_0);
372
373
  const len0 = WASM_VECTOR_LEN;
373
- wasm.decodeImportBlobMeta(retptr, ptr0, len0);
374
+ wasm.decodeImportBlobMeta(retptr, ptr0, len0, check_checksum);
374
375
  var r0 = getInt32Memory0()[retptr / 4 + 0];
375
376
  var r1 = getInt32Memory0()[retptr / 4 + 1];
376
377
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -1202,7 +1203,7 @@ export class LoroDoc {
1202
1203
  * @param ids - the changes to visit
1203
1204
  * @param f - the callback function, return `true` to continue visiting, return `false` to stop
1204
1205
  * @param {({ peer: PeerID, counter: number })[]} ids
1205
- * @param {Function} f
1206
+ * @param {(change: ChangeMeta) => boolean} f
1206
1207
  */
1207
1208
  travelChangeAncestors(ids, f) {
1208
1209
  try {
@@ -2349,6 +2350,40 @@ export class LoroDoc {
2349
2350
  wasm.__wbindgen_add_to_stack_pointer(16);
2350
2351
  }
2351
2352
  }
2353
+ /**
2354
+ * Gets container IDs modified in the given ID range.
2355
+ *
2356
+ * **NOTE:** This method will implicitly commit.
2357
+ *
2358
+ * This method identifies which containers were affected by changes in a given range of operations.
2359
+ * It can be used together with `doc.travelChangeAncestors()` to analyze the history of changes
2360
+ * and determine which containers were modified by each change.
2361
+ *
2362
+ * @param id - The starting ID of the change range
2363
+ * @param len - The length of the change range to check
2364
+ * @returns An array of container IDs that were modified in the given range
2365
+ * @param {{ peer: PeerID, counter: number }} id
2366
+ * @param {number} len
2367
+ * @returns {(ContainerID)[]}
2368
+ */
2369
+ getChangedContainersIn(id, len) {
2370
+ try {
2371
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2372
+ wasm.lorodoc_getChangedContainersIn(retptr, this.__wbg_ptr, addHeapObject(id), len);
2373
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2374
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2375
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
2376
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
2377
+ if (r3) {
2378
+ throw takeObject(r2);
2379
+ }
2380
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
2381
+ wasm.__wbindgen_export_5(r0, r1 * 4, 4);
2382
+ return v1;
2383
+ } finally {
2384
+ wasm.__wbindgen_add_to_stack_pointer(16);
2385
+ }
2386
+ }
2352
2387
  }
2353
2388
 
2354
2389
  const LoroListFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -2749,6 +2784,14 @@ export class LoroList {
2749
2784
  wasm.__wbindgen_add_to_stack_pointer(16);
2750
2785
  }
2751
2786
  }
2787
+ /**
2788
+ * @param {number} pos
2789
+ * @returns {{ peer: PeerID, counter: number } | undefined}
2790
+ */
2791
+ getIdAt(pos) {
2792
+ const ret = wasm.lorolist_getIdAt(this.__wbg_ptr, pos);
2793
+ return takeObject(ret);
2794
+ }
2752
2795
  }
2753
2796
 
2754
2797
  const LoroMapFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -3180,6 +3223,17 @@ export class LoroMap {
3180
3223
  wasm.__wbindgen_add_to_stack_pointer(16);
3181
3224
  }
3182
3225
  }
3226
+ /**
3227
+ * Get the peer id of the last editor on the given entry
3228
+ * @param {string} key
3229
+ * @returns {PeerID | undefined}
3230
+ */
3231
+ getLastEditor(key) {
3232
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
3233
+ const len0 = WASM_VECTOR_LEN;
3234
+ const ret = wasm.loromap_getLastEditor(this.__wbg_ptr, ptr0, len0);
3235
+ return takeObject(ret);
3236
+ }
3183
3237
  }
3184
3238
 
3185
3239
  const LoroMovableListFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -3652,6 +3706,33 @@ export class LoroMovableList {
3652
3706
  wasm.__wbindgen_add_to_stack_pointer(16);
3653
3707
  }
3654
3708
  }
3709
+ /**
3710
+ * Get the creator of the list item at the given position.
3711
+ * @param {number} pos
3712
+ * @returns {PeerID | undefined}
3713
+ */
3714
+ getCreatorAt(pos) {
3715
+ const ret = wasm.loromovablelist_getCreatorAt(this.__wbg_ptr, pos);
3716
+ return takeObject(ret);
3717
+ }
3718
+ /**
3719
+ * Get the last mover of the list item at the given position.
3720
+ * @param {number} pos
3721
+ * @returns {PeerID | undefined}
3722
+ */
3723
+ getLastMoverAt(pos) {
3724
+ const ret = wasm.loromovablelist_getLastMoverAt(this.__wbg_ptr, pos);
3725
+ return takeObject(ret);
3726
+ }
3727
+ /**
3728
+ * Get the last editor of the list item at the given position.
3729
+ * @param {number} pos
3730
+ * @returns {PeerID | undefined}
3731
+ */
3732
+ getLastEditorAt(pos) {
3733
+ const ret = wasm.loromovablelist_getLastEditorAt(this.__wbg_ptr, pos);
3734
+ return takeObject(ret);
3735
+ }
3655
3736
  }
3656
3737
 
3657
3738
  const LoroTextFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -3703,11 +3784,14 @@ export class LoroText {
3703
3784
  return takeObject(ret);
3704
3785
  }
3705
3786
  /**
3706
- * Iterate each span(internal storage unit) of the text.
3787
+ * Iterate each text span(internal storage unit)
3707
3788
  *
3708
3789
  * The callback function will be called for each span in the text.
3709
3790
  * If the callback returns `false`, the iteration will stop.
3710
3791
  *
3792
+ * Limitation: you cannot access or alter the doc state when iterating (this is for performance consideration).
3793
+ * If you need to access or alter the doc state, please use `toString` instead.
3794
+ *
3711
3795
  * @example
3712
3796
  * ```ts
3713
3797
  * import { LoroDoc } from "loro-crdt";
@@ -3746,22 +3830,44 @@ export class LoroText {
3746
3830
  * console.log(text.toString()); // "Hello World"
3747
3831
  * ```
3748
3832
  * @param {string} text
3833
+ * @param {any} options
3749
3834
  */
3750
- update(text) {
3751
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
3752
- const len0 = WASM_VECTOR_LEN;
3753
- wasm.lorotext_update(this.__wbg_ptr, ptr0, len0);
3835
+ update(text, options) {
3836
+ try {
3837
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
3838
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
3839
+ const len0 = WASM_VECTOR_LEN;
3840
+ wasm.lorotext_update(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(options));
3841
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
3842
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
3843
+ if (r1) {
3844
+ throw takeObject(r0);
3845
+ }
3846
+ } finally {
3847
+ wasm.__wbindgen_add_to_stack_pointer(16);
3848
+ }
3754
3849
  }
3755
3850
  /**
3756
3851
  * Update the current text to the target text, the difference is calculated line by line.
3757
3852
  *
3758
3853
  * It uses Myers' diff algorithm to compute the optimal difference.
3759
3854
  * @param {string} text
3855
+ * @param {any} options
3760
3856
  */
3761
- updateByLine(text) {
3762
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
3763
- const len0 = WASM_VECTOR_LEN;
3764
- wasm.lorotext_updateByLine(this.__wbg_ptr, ptr0, len0);
3857
+ updateByLine(text, options) {
3858
+ try {
3859
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
3860
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
3861
+ const len0 = WASM_VECTOR_LEN;
3862
+ wasm.lorotext_updateByLine(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(options));
3863
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
3864
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
3865
+ if (r1) {
3866
+ throw takeObject(r0);
3867
+ }
3868
+ } finally {
3869
+ wasm.__wbindgen_add_to_stack_pointer(16);
3870
+ }
3765
3871
  }
3766
3872
  /**
3767
3873
  * Insert the string at the given index (utf-16 index).
@@ -4259,6 +4365,15 @@ export class LoroText {
4259
4365
  wasm.__wbindgen_add_to_stack_pointer(16);
4260
4366
  }
4261
4367
  }
4368
+ /**
4369
+ * Get the editor of the text at the given position.
4370
+ * @param {number} pos
4371
+ * @returns {PeerID | undefined}
4372
+ */
4373
+ getEditorOf(pos) {
4374
+ const ret = wasm.lorotext_getEditorOf(this.__wbg_ptr, pos);
4375
+ return takeObject(ret);
4376
+ }
4262
4377
  }
4263
4378
 
4264
4379
  const LoroTreeFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -4953,6 +5068,24 @@ export class LoroTreeNode {
4953
5068
  }
4954
5069
  }
4955
5070
  /**
5071
+ * @returns {any}
5072
+ */
5073
+ toJSON() {
5074
+ try {
5075
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
5076
+ wasm.lorotreenode_toJSON(retptr, this.__wbg_ptr);
5077
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
5078
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
5079
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
5080
+ if (r2) {
5081
+ throw takeObject(r1);
5082
+ }
5083
+ return takeObject(r0);
5084
+ } finally {
5085
+ wasm.__wbindgen_add_to_stack_pointer(16);
5086
+ }
5087
+ }
5088
+ /**
4956
5089
  * Get the parent node of this node.
4957
5090
  *
4958
5091
  * - The parent of the root node is `undefined`.
@@ -5005,6 +5138,30 @@ export class LoroTreeNode {
5005
5138
  wasm.__wbindgen_add_to_stack_pointer(16);
5006
5139
  }
5007
5140
  }
5141
+ /**
5142
+ * Get the last mover of this node.
5143
+ * @returns {{ peer: PeerID, counter: number } | undefined}
5144
+ */
5145
+ getLastMoveId() {
5146
+ const ret = wasm.lorotreenode_getLastMoveId(this.__wbg_ptr);
5147
+ return takeObject(ret);
5148
+ }
5149
+ /**
5150
+ * Get the creation id of this node.
5151
+ * @returns {{ peer: PeerID, counter: number }}
5152
+ */
5153
+ creationId() {
5154
+ const ret = wasm.lorotreenode_creationId(this.__wbg_ptr);
5155
+ return takeObject(ret);
5156
+ }
5157
+ /**
5158
+ * Get the creator of this node.
5159
+ * @returns {PeerID}
5160
+ */
5161
+ creator() {
5162
+ const ret = wasm.lorotreenode_creator(this.__wbg_ptr);
5163
+ return takeObject(ret);
5164
+ }
5008
5165
  }
5009
5166
 
5010
5167
  const UndoManagerFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -5416,6 +5573,10 @@ function __wbg_get_imports() {
5416
5573
  const ret = VersionVector.__wrap(arg0);
5417
5574
  return addHeapObject(ret);
5418
5575
  };
5576
+ imports.wbg.__wbindgen_is_function = function(arg0) {
5577
+ const ret = typeof(getObject(arg0)) === 'function';
5578
+ return ret;
5579
+ };
5419
5580
  imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
5420
5581
  const ret = getStringFromWasm0(arg0, arg1);
5421
5582
  return addHeapObject(ret);
@@ -5489,10 +5650,6 @@ function __wbg_get_imports() {
5489
5650
  const ret = +getObject(arg0);
5490
5651
  return ret;
5491
5652
  };
5492
- imports.wbg.__wbindgen_is_function = function(arg0) {
5493
- const ret = typeof(getObject(arg0)) === 'function';
5494
- return ret;
5495
- };
5496
5653
  imports.wbg.__wbindgen_is_string = function(arg0) {
5497
5654
  const ret = typeof(getObject(arg0)) === 'string';
5498
5655
  return ret;
@@ -5859,11 +6016,11 @@ function __wbg_get_imports() {
5859
6016
  const ret = wasm.memory;
5860
6017
  return addHeapObject(ret);
5861
6018
  };
5862
- imports.wbg.__wbindgen_closure_wrapper488 = function(arg0, arg1, arg2) {
6019
+ imports.wbg.__wbindgen_closure_wrapper491 = function(arg0, arg1, arg2) {
5863
6020
  const ret = makeMutClosure(arg0, arg1, 9, __wbg_adapter_58);
5864
6021
  return addHeapObject(ret);
5865
6022
  };
5866
- imports.wbg.__wbindgen_closure_wrapper491 = function(arg0, arg1, arg2) {
6023
+ imports.wbg.__wbindgen_closure_wrapper494 = function(arg0, arg1, arg2) {
5867
6024
  const ret = makeMutClosure(arg0, arg1, 11, __wbg_adapter_61);
5868
6025
  return addHeapObject(ret);
5869
6026
  };
Binary file