loro-crdt 1.2.0 → 1.2.2

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.
@@ -155,6 +155,36 @@ interface LoroDoc {
155
155
  * ```
156
156
  */
157
157
  subscribeLocalUpdates(f: (bytes: Uint8Array) => void): () => void
158
+ /**
159
+ * Convert the document to a JSON value with a custom replacer function.
160
+ *
161
+ * This method works similarly to `JSON.stringify`'s replacer parameter.
162
+ * The replacer function is called for each value in the document and can transform
163
+ * how values are serialized to JSON.
164
+ *
165
+ * @param replacer - A function that takes a key and value, and returns how that value
166
+ * should be serialized. Similar to JSON.stringify's replacer.
167
+ * If return undefined, the value will be skipped.
168
+ * @returns The JSON representation of the document after applying the replacer function.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * const doc = new LoroDoc();
173
+ * const text = doc.getText("text");
174
+ * text.insert(0, "Hello");
175
+ * text.mark(0, 2, {bold: true});
176
+ *
177
+ * // Use delta to represent text
178
+ * const json = doc.toJsonWithReplacer((key, value) => {
179
+ * if (value instanceof LoroText) {
180
+ * return value.toDelta();
181
+ * }
182
+ *
183
+ * return value;
184
+ * });
185
+ * ```
186
+ */
187
+ toJsonWithReplacer(replacer: (key: string | index, value: Value | Container) => Value | Container | undefined): Value;
158
188
  }
159
189
 
160
190
  /**
@@ -231,7 +261,8 @@ export type Value =
231
261
  | null
232
262
  | { [key: string]: Value }
233
263
  | Uint8Array
234
- | Value[];
264
+ | Value[]
265
+ | undefined;
235
266
 
236
267
  export type UndoConfig = {
237
268
  mergeInterval?: number,
@@ -343,6 +374,15 @@ interface LoroList {
343
374
  getCursor(pos: number, side?: Side): Cursor | undefined;
344
375
  }
345
376
 
377
+ export type TreeNodeShallowValue = {
378
+ id: TreeID,
379
+ parent: TreeID | undefined,
380
+ index: number,
381
+ fractionalIndex: string,
382
+ meta: ContainerID,
383
+ children: TreeNodeShallowValue[],
384
+ }
385
+
346
386
  export type TreeNodeValue = {
347
387
  id: TreeID,
348
388
  parent: TreeID | undefined,
@@ -1320,6 +1360,11 @@ export class LoroCounter {
1320
1360
  getAttached(): LoroTree | undefined;
1321
1361
  /**
1322
1362
  * Get the value of the counter.
1363
+ * @returns {number}
1364
+ */
1365
+ getShallowValue(): number;
1366
+ /**
1367
+ * Get the value of the counter.
1323
1368
  */
1324
1369
  readonly value: number;
1325
1370
  }
@@ -1863,7 +1908,30 @@ export class LoroDoc {
1863
1908
  */
1864
1909
  import(update_or_snapshot: Uint8Array): ImportStatus;
1865
1910
  /**
1866
- * Import a batch of updates.
1911
+ * Import a batch of updates and snapshots.
1912
+ *
1913
+ * It's more efficient than importing updates one by one.
1914
+ *
1915
+ * @deprecated Use `importBatch` instead.
1916
+ *
1917
+ * @example
1918
+ * ```ts
1919
+ * import { LoroDoc } from "loro-crdt";
1920
+ *
1921
+ * const doc = new LoroDoc();
1922
+ * const text = doc.getText("text");
1923
+ * text.insert(0, "Hello");
1924
+ * const updates = doc.export({ mode: "update" });
1925
+ * const snapshot = doc.export({ mode: "snapshot" });
1926
+ * const doc2 = new LoroDoc();
1927
+ * doc2.importBatch([snapshot, updates]);
1928
+ * ```
1929
+ * @param {Uint8Array[]} data
1930
+ * @returns {ImportStatus}
1931
+ */
1932
+ importUpdateBatch(data: Uint8Array[]): ImportStatus;
1933
+ /**
1934
+ * Import a batch of updates or snapshots.
1867
1935
  *
1868
1936
  * It's more efficient than importing updates one by one.
1869
1937
  *
@@ -1877,15 +1945,18 @@ export class LoroDoc {
1877
1945
  * const updates = doc.export({ mode: "update" });
1878
1946
  * const snapshot = doc.export({ mode: "snapshot" });
1879
1947
  * const doc2 = new LoroDoc();
1880
- * doc2.importUpdateBatch([snapshot, updates]);
1948
+ * doc2.importBatch([snapshot, updates]);
1881
1949
  * ```
1882
- * @param {Array<any>} data
1950
+ * @param {Uint8Array[]} data
1883
1951
  * @returns {ImportStatus}
1884
1952
  */
1885
- importUpdateBatch(data: Array<any>): ImportStatus;
1953
+ importBatch(data: Uint8Array[]): ImportStatus;
1886
1954
  /**
1887
1955
  * Get the shallow json format of the document state.
1888
1956
  *
1957
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
1958
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
1959
+ *
1889
1960
  * @example
1890
1961
  * ```ts
1891
1962
  * import { LoroDoc } from "loro-crdt";
@@ -1895,20 +1966,28 @@ export class LoroDoc {
1895
1966
  * const tree = doc.getTree("tree");
1896
1967
  * const map = doc.getMap("map");
1897
1968
  * const shallowValue = doc.getShallowValue();
1898
- * /*
1899
- * {"list": ..., "tree": ..., "map": ...}
1900
- * *\/
1901
1969
  * console.log(shallowValue);
1970
+ * // {
1971
+ * // list: 'cid:root-list:List',
1972
+ * // tree: 'cid:root-tree:Tree',
1973
+ * // map: 'cid:root-map:Map'
1974
+ * // }
1975
+ *
1976
+ * // It points to the same container as `list`
1977
+ * const listB = doc.getContainerById(shallowValue.list);
1902
1978
  * ```
1903
- * @returns {any}
1979
+ * @returns {Record<string, ContainerID>}
1904
1980
  */
1905
- getShallowValue(): any;
1981
+ getShallowValue(): Record<string, ContainerID>;
1906
1982
  /**
1907
1983
  * Get the json format of the entire document state.
1908
1984
  *
1985
+ * Unlike `getShallowValue()` which returns container IDs as strings,
1986
+ * `toJSON()` recursively resolves all containers to their actual values.
1987
+ *
1909
1988
  * @example
1910
1989
  * ```ts
1911
- * import { LoroDoc, LoroText, LoroMap } from "loro-crdt";
1990
+ * import { LoroDoc, LoroText } from "loro-crdt";
1912
1991
  *
1913
1992
  * const doc = new LoroDoc();
1914
1993
  * const list = doc.getList("list");
@@ -1917,10 +1996,8 @@ export class LoroDoc {
1917
1996
  * text.insert(0, "Hello");
1918
1997
  * const map = list.insertContainer(1, new LoroMap());
1919
1998
  * map.set("foo", "bar");
1920
- * /*
1921
- * {"list": ["Hello", {"foo": "bar"}]}
1922
- * *\/
1923
1999
  * console.log(doc.toJSON());
2000
+ * // {"list": ["Hello", {"foo": "bar"}]}
1924
2001
  * ```
1925
2002
  * @returns {any}
1926
2003
  */
@@ -2181,6 +2258,26 @@ export class LoroList {
2181
2258
  */
2182
2259
  isDeleted(): boolean;
2183
2260
  /**
2261
+ * Get the shallow value of the list.
2262
+ *
2263
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
2264
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
2265
+ *
2266
+ * ```js
2267
+ * const doc = new LoroDoc();
2268
+ * doc.setPeerId("1");
2269
+ * const list = doc.getList("list");
2270
+ * list.insert(0, 1);
2271
+ * list.insert(1, "two");
2272
+ * const subList = list.insertContainer(2, new LoroList());
2273
+ * subList.insert(0, "sub");
2274
+ * list.getShallowValue(); // [1, "two", "cid:2@1:List"]
2275
+ * list.toJSON(); // [1, "two", ["sub"]]
2276
+ * ```
2277
+ * @returns {Value[]}
2278
+ */
2279
+ getShallowValue(): Value[];
2280
+ /**
2184
2281
  * Get the id of this container.
2185
2282
  */
2186
2283
  readonly id: ContainerID;
@@ -2342,6 +2439,34 @@ export class LoroMap {
2342
2439
  */
2343
2440
  isDeleted(): boolean;
2344
2441
  /**
2442
+ * Get the shallow value of the map.
2443
+ *
2444
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
2445
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
2446
+ *
2447
+ * @example
2448
+ * ```ts
2449
+ * import { LoroDoc } from "loro-crdt";
2450
+ *
2451
+ * const doc = new LoroDoc();
2452
+ * doc.setPeerId("1");
2453
+ * const map = doc.getMap("map");
2454
+ * map.set("key", "value");
2455
+ * const subText = map.setContainer("text", new LoroText());
2456
+ * subText.insert(0, "Hello");
2457
+ *
2458
+ * // Get shallow value - nested containers are represented by their IDs
2459
+ * console.log(map.getShallowValue());
2460
+ * // Output: { key: "value", text: "cid:1@1:Text" }
2461
+ *
2462
+ * // Get full value with nested containers resolved by `toJSON()`
2463
+ * console.log(map.toJSON());
2464
+ * // Output: { key: "value", text: "Hello" }
2465
+ * ```
2466
+ * @returns {Record<string, Value>}
2467
+ */
2468
+ getShallowValue(): Record<string, Value>;
2469
+ /**
2345
2470
  * The container id of this handler.
2346
2471
  */
2347
2472
  readonly id: ContainerID;
@@ -2485,6 +2610,26 @@ export class LoroMovableList {
2485
2610
  */
2486
2611
  isDeleted(): boolean;
2487
2612
  /**
2613
+ * Get the shallow value of the movable list.
2614
+ *
2615
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
2616
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
2617
+ *
2618
+ * ```js
2619
+ * const doc = new LoroDoc();
2620
+ * doc.setPeerId("1");
2621
+ * const list = doc.getMovableList("list");
2622
+ * list.insert(0, 1);
2623
+ * list.insert(1, "two");
2624
+ * const subList = list.insertContainer(2, new LoroList());
2625
+ * subList.insert(0, "sub");
2626
+ * list.getShallowValue(); // [1, "two", "cid:2@1:List"]
2627
+ * list.toJSON(); // [1, "two", ["sub"]]
2628
+ * ```
2629
+ * @returns {Value[]}
2630
+ */
2631
+ getShallowValue(): Value[];
2632
+ /**
2488
2633
  * Get the id of this container.
2489
2634
  */
2490
2635
  readonly id: ContainerID;
@@ -2542,9 +2687,9 @@ export class LoroText {
2542
2687
  * text.insert(0, "Hello");
2543
2688
  * text.iter((str) => (console.log(str), true));
2544
2689
  * ```
2545
- * @param {Function} callback
2690
+ * @param {(string) => boolean} callback
2546
2691
  */
2547
- iter(callback: Function): void;
2692
+ iter(callback: (string) => boolean): void;
2548
2693
  /**
2549
2694
  * Insert the string at the given index (utf-16 index).
2550
2695
  *
@@ -2800,6 +2945,11 @@ export class LoroText {
2800
2945
  */
2801
2946
  isDeleted(): boolean;
2802
2947
  /**
2948
+ * Get the shallow value of the text. This equals to `text.toString()`.
2949
+ * @returns {string}
2950
+ */
2951
+ getShallowValue(): string;
2952
+ /**
2803
2953
  * Get the container id of the text.
2804
2954
  */
2805
2955
  readonly id: ContainerID;
@@ -2972,6 +3122,48 @@ export class LoroTree {
2972
3122
  */
2973
3123
  isDeleted(): boolean;
2974
3124
  /**
3125
+ * Get the shallow value of the tree.
3126
+ *
3127
+ * Unlike `toJSON()` which recursively resolves nested containers to their values,
3128
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
3129
+ *
3130
+ * @example
3131
+ * ```ts
3132
+ * const doc = new LoroDoc();
3133
+ * doc.setPeerId("1");
3134
+ * const tree = doc.getTree("tree");
3135
+ * const root = tree.createNode();
3136
+ * root.data.set("name", "root");
3137
+ * const text = root.data.setContainer("content", new LoroText());
3138
+ * text.insert(0, "Hello");
3139
+ *
3140
+ * console.log(tree.getShallowValue());
3141
+ * // [{
3142
+ * // id: "0@1",
3143
+ * // parent: null,
3144
+ * // index: 0,
3145
+ * // fractional_index: "80",
3146
+ * // meta: "cid:0@1:Map",
3147
+ * // children: []
3148
+ * // }]
3149
+ *
3150
+ * console.log(tree.toJSON());
3151
+ * // [{
3152
+ * // id: "0@1",
3153
+ * // parent: null,
3154
+ * // index: 0,
3155
+ * // fractional_index: "80",
3156
+ * // meta: {
3157
+ * // name: "root",
3158
+ * // content: "Hello"
3159
+ * // },
3160
+ * // children: []
3161
+ * // }]
3162
+ * ```
3163
+ * @returns {TreeNodeShallowValue[]}
3164
+ */
3165
+ getShallowValue(): TreeNodeShallowValue[];
3166
+ /**
2975
3167
  * Get the id of the container.
2976
3168
  */
2977
3169
  readonly id: ContainerID;
@@ -858,6 +858,14 @@ class LoroCounter {
858
858
  const ret = wasm.lorocounter_getAttached(this.__wbg_ptr);
859
859
  return takeObject(ret);
860
860
  }
861
+ /**
862
+ * Get the value of the counter.
863
+ * @returns {number}
864
+ */
865
+ getShallowValue() {
866
+ const ret = wasm.lorocounter_getShallowValue(this.__wbg_ptr);
867
+ return ret;
868
+ }
861
869
  }
862
870
  module.exports.LoroCounter = LoroCounter;
863
871
 
@@ -1985,10 +1993,12 @@ class LoroDoc {
1985
1993
  }
1986
1994
  }
1987
1995
  /**
1988
- * Import a batch of updates.
1996
+ * Import a batch of updates and snapshots.
1989
1997
  *
1990
1998
  * It's more efficient than importing updates one by one.
1991
1999
  *
2000
+ * @deprecated Use `importBatch` instead.
2001
+ *
1992
2002
  * @example
1993
2003
  * ```ts
1994
2004
  * import { LoroDoc } from "loro-crdt";
@@ -1999,9 +2009,9 @@ class LoroDoc {
1999
2009
  * const updates = doc.export({ mode: "update" });
2000
2010
  * const snapshot = doc.export({ mode: "snapshot" });
2001
2011
  * const doc2 = new LoroDoc();
2002
- * doc2.importUpdateBatch([snapshot, updates]);
2012
+ * doc2.importBatch([snapshot, updates]);
2003
2013
  * ```
2004
- * @param {Array<any>} data
2014
+ * @param {Uint8Array[]} data
2005
2015
  * @returns {ImportStatus}
2006
2016
  */
2007
2017
  importUpdateBatch(data) {
@@ -2020,8 +2030,46 @@ class LoroDoc {
2020
2030
  }
2021
2031
  }
2022
2032
  /**
2033
+ * Import a batch of updates or snapshots.
2034
+ *
2035
+ * It's more efficient than importing updates one by one.
2036
+ *
2037
+ * @example
2038
+ * ```ts
2039
+ * import { LoroDoc } from "loro-crdt";
2040
+ *
2041
+ * const doc = new LoroDoc();
2042
+ * const text = doc.getText("text");
2043
+ * text.insert(0, "Hello");
2044
+ * const updates = doc.export({ mode: "update" });
2045
+ * const snapshot = doc.export({ mode: "snapshot" });
2046
+ * const doc2 = new LoroDoc();
2047
+ * doc2.importBatch([snapshot, updates]);
2048
+ * ```
2049
+ * @param {Uint8Array[]} data
2050
+ * @returns {ImportStatus}
2051
+ */
2052
+ importBatch(data) {
2053
+ try {
2054
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2055
+ wasm.lorodoc_importBatch(retptr, this.__wbg_ptr, addHeapObject(data));
2056
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2057
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2058
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
2059
+ if (r2) {
2060
+ throw takeObject(r1);
2061
+ }
2062
+ return takeObject(r0);
2063
+ } finally {
2064
+ wasm.__wbindgen_add_to_stack_pointer(16);
2065
+ }
2066
+ }
2067
+ /**
2023
2068
  * Get the shallow json format of the document state.
2024
2069
  *
2070
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
2071
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
2072
+ *
2025
2073
  * @example
2026
2074
  * ```ts
2027
2075
  * import { LoroDoc } from "loro-crdt";
@@ -2031,12 +2079,17 @@ class LoroDoc {
2031
2079
  * const tree = doc.getTree("tree");
2032
2080
  * const map = doc.getMap("map");
2033
2081
  * const shallowValue = doc.getShallowValue();
2034
- * /*
2035
- * {"list": ..., "tree": ..., "map": ...}
2036
- * *\/
2037
2082
  * console.log(shallowValue);
2083
+ * // {
2084
+ * // list: 'cid:root-list:List',
2085
+ * // tree: 'cid:root-tree:Tree',
2086
+ * // map: 'cid:root-map:Map'
2087
+ * // }
2088
+ *
2089
+ * // It points to the same container as `list`
2090
+ * const listB = doc.getContainerById(shallowValue.list);
2038
2091
  * ```
2039
- * @returns {any}
2092
+ * @returns {Record<string, ContainerID>}
2040
2093
  */
2041
2094
  getShallowValue() {
2042
2095
  try {
@@ -2056,9 +2109,12 @@ class LoroDoc {
2056
2109
  /**
2057
2110
  * Get the json format of the entire document state.
2058
2111
  *
2112
+ * Unlike `getShallowValue()` which returns container IDs as strings,
2113
+ * `toJSON()` recursively resolves all containers to their actual values.
2114
+ *
2059
2115
  * @example
2060
2116
  * ```ts
2061
- * import { LoroDoc, LoroText, LoroMap } from "loro-crdt";
2117
+ * import { LoroDoc, LoroText } from "loro-crdt";
2062
2118
  *
2063
2119
  * const doc = new LoroDoc();
2064
2120
  * const list = doc.getList("list");
@@ -2067,10 +2123,8 @@ class LoroDoc {
2067
2123
  * text.insert(0, "Hello");
2068
2124
  * const map = list.insertContainer(1, new LoroMap());
2069
2125
  * map.set("foo", "bar");
2070
- * /*
2071
- * {"list": ["Hello", {"foo": "bar"}]}
2072
- * *\/
2073
2126
  * console.log(doc.toJSON());
2127
+ * // {"list": ["Hello", {"foo": "bar"}]}
2074
2128
  * ```
2075
2129
  * @returns {any}
2076
2130
  */
@@ -2826,6 +2880,29 @@ class LoroList {
2826
2880
  const ret = wasm.lorolist_isDeleted(this.__wbg_ptr);
2827
2881
  return ret !== 0;
2828
2882
  }
2883
+ /**
2884
+ * Get the shallow value of the list.
2885
+ *
2886
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
2887
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
2888
+ *
2889
+ * ```js
2890
+ * const doc = new LoroDoc();
2891
+ * doc.setPeerId("1");
2892
+ * const list = doc.getList("list");
2893
+ * list.insert(0, 1);
2894
+ * list.insert(1, "two");
2895
+ * const subList = list.insertContainer(2, new LoroList());
2896
+ * subList.insert(0, "sub");
2897
+ * list.getShallowValue(); // [1, "two", "cid:2@1:List"]
2898
+ * list.toJSON(); // [1, "two", ["sub"]]
2899
+ * ```
2900
+ * @returns {Value[]}
2901
+ */
2902
+ getShallowValue() {
2903
+ const ret = wasm.lorolist_getShallowValue(this.__wbg_ptr);
2904
+ return takeObject(ret);
2905
+ }
2829
2906
  }
2830
2907
  module.exports.LoroList = LoroList;
2831
2908
 
@@ -3277,6 +3354,37 @@ class LoroMap {
3277
3354
  const ret = wasm.loromap_isDeleted(this.__wbg_ptr);
3278
3355
  return ret !== 0;
3279
3356
  }
3357
+ /**
3358
+ * Get the shallow value of the map.
3359
+ *
3360
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
3361
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
3362
+ *
3363
+ * @example
3364
+ * ```ts
3365
+ * import { LoroDoc } from "loro-crdt";
3366
+ *
3367
+ * const doc = new LoroDoc();
3368
+ * doc.setPeerId("1");
3369
+ * const map = doc.getMap("map");
3370
+ * map.set("key", "value");
3371
+ * const subText = map.setContainer("text", new LoroText());
3372
+ * subText.insert(0, "Hello");
3373
+ *
3374
+ * // Get shallow value - nested containers are represented by their IDs
3375
+ * console.log(map.getShallowValue());
3376
+ * // Output: { key: "value", text: "cid:1@1:Text" }
3377
+ *
3378
+ * // Get full value with nested containers resolved by `toJSON()`
3379
+ * console.log(map.toJSON());
3380
+ * // Output: { key: "value", text: "Hello" }
3381
+ * ```
3382
+ * @returns {Record<string, Value>}
3383
+ */
3384
+ getShallowValue() {
3385
+ const ret = wasm.loromap_getShallowValue(this.__wbg_ptr);
3386
+ return takeObject(ret);
3387
+ }
3280
3388
  }
3281
3389
  module.exports.LoroMap = LoroMap;
3282
3390
 
@@ -3785,6 +3893,29 @@ class LoroMovableList {
3785
3893
  const ret = wasm.loromovablelist_isDeleted(this.__wbg_ptr);
3786
3894
  return ret !== 0;
3787
3895
  }
3896
+ /**
3897
+ * Get the shallow value of the movable list.
3898
+ *
3899
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
3900
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
3901
+ *
3902
+ * ```js
3903
+ * const doc = new LoroDoc();
3904
+ * doc.setPeerId("1");
3905
+ * const list = doc.getMovableList("list");
3906
+ * list.insert(0, 1);
3907
+ * list.insert(1, "two");
3908
+ * const subList = list.insertContainer(2, new LoroList());
3909
+ * subList.insert(0, "sub");
3910
+ * list.getShallowValue(); // [1, "two", "cid:2@1:List"]
3911
+ * list.toJSON(); // [1, "two", ["sub"]]
3912
+ * ```
3913
+ * @returns {Value[]}
3914
+ */
3915
+ getShallowValue() {
3916
+ const ret = wasm.loromovablelist_getShallowValue(this.__wbg_ptr);
3917
+ return takeObject(ret);
3918
+ }
3788
3919
  }
3789
3920
  module.exports.LoroMovableList = LoroMovableList;
3790
3921
 
@@ -3854,13 +3985,19 @@ class LoroText {
3854
3985
  * text.insert(0, "Hello");
3855
3986
  * text.iter((str) => (console.log(str), true));
3856
3987
  * ```
3857
- * @param {Function} callback
3988
+ * @param {(string) => boolean} callback
3858
3989
  */
3859
3990
  iter(callback) {
3860
3991
  try {
3861
- wasm.lorotext_iter(this.__wbg_ptr, addBorrowedObject(callback));
3992
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
3993
+ wasm.lorotext_iter(retptr, this.__wbg_ptr, addHeapObject(callback));
3994
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
3995
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
3996
+ if (r1) {
3997
+ throw takeObject(r0);
3998
+ }
3862
3999
  } finally {
3863
- heap[stack_pointer++] = undefined;
4000
+ wasm.__wbindgen_add_to_stack_pointer(16);
3864
4001
  }
3865
4002
  }
3866
4003
  /**
@@ -4435,6 +4572,26 @@ class LoroText {
4435
4572
  const ret = wasm.lorotext_isDeleted(this.__wbg_ptr);
4436
4573
  return ret !== 0;
4437
4574
  }
4575
+ /**
4576
+ * Get the shallow value of the text. This equals to `text.toString()`.
4577
+ * @returns {string}
4578
+ */
4579
+ getShallowValue() {
4580
+ let deferred1_0;
4581
+ let deferred1_1;
4582
+ try {
4583
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
4584
+ wasm.lorotext_getShallowValue(retptr, this.__wbg_ptr);
4585
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
4586
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
4587
+ deferred1_0 = r0;
4588
+ deferred1_1 = r1;
4589
+ return getStringFromWasm0(r0, r1);
4590
+ } finally {
4591
+ wasm.__wbindgen_add_to_stack_pointer(16);
4592
+ wasm.__wbindgen_export_5(deferred1_0, deferred1_1, 1);
4593
+ }
4594
+ }
4438
4595
  }
4439
4596
  module.exports.LoroText = LoroText;
4440
4597
 
@@ -4883,6 +5040,51 @@ class LoroTree {
4883
5040
  const ret = wasm.lorotree_isDeleted(this.__wbg_ptr);
4884
5041
  return ret !== 0;
4885
5042
  }
5043
+ /**
5044
+ * Get the shallow value of the tree.
5045
+ *
5046
+ * Unlike `toJSON()` which recursively resolves nested containers to their values,
5047
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
5048
+ *
5049
+ * @example
5050
+ * ```ts
5051
+ * const doc = new LoroDoc();
5052
+ * doc.setPeerId("1");
5053
+ * const tree = doc.getTree("tree");
5054
+ * const root = tree.createNode();
5055
+ * root.data.set("name", "root");
5056
+ * const text = root.data.setContainer("content", new LoroText());
5057
+ * text.insert(0, "Hello");
5058
+ *
5059
+ * console.log(tree.getShallowValue());
5060
+ * // [{
5061
+ * // id: "0@1",
5062
+ * // parent: null,
5063
+ * // index: 0,
5064
+ * // fractional_index: "80",
5065
+ * // meta: "cid:0@1:Map",
5066
+ * // children: []
5067
+ * // }]
5068
+ *
5069
+ * console.log(tree.toJSON());
5070
+ * // [{
5071
+ * // id: "0@1",
5072
+ * // parent: null,
5073
+ * // index: 0,
5074
+ * // fractional_index: "80",
5075
+ * // meta: {
5076
+ * // name: "root",
5077
+ * // content: "Hello"
5078
+ * // },
5079
+ * // children: []
5080
+ * // }]
5081
+ * ```
5082
+ * @returns {TreeNodeShallowValue[]}
5083
+ */
5084
+ getShallowValue() {
5085
+ const ret = wasm.lorotree_getShallowValue(this.__wbg_ptr);
5086
+ return takeObject(ret);
5087
+ }
4886
5088
  }
4887
5089
  module.exports.LoroTree = LoroTree;
4888
5090
 
Binary file