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.
- package/CHANGELOG.md +16 -0
- package/base64/index.js +264 -15
- package/base64/loro_wasm.d.ts +208 -16
- package/base64/loro_wasm_bg-8056e30c.js +64 -0
- package/bundler/index.js +47 -0
- package/bundler/index.js.map +1 -1
- package/bundler/loro_wasm.d.ts +208 -16
- package/bundler/loro_wasm_bg.js +216 -14
- package/bundler/loro_wasm_bg.wasm +0 -0
- package/bundler/loro_wasm_bg.wasm.d.ts +8 -1
- package/nodejs/index.js +47 -0
- package/nodejs/index.js.map +1 -1
- package/nodejs/loro_wasm.d.ts +208 -16
- package/nodejs/loro_wasm.js +216 -14
- package/nodejs/loro_wasm_bg.wasm +0 -0
- package/nodejs/loro_wasm_bg.wasm.d.ts +8 -1
- package/package.json +1 -1
- package/web/index.js +47 -0
- package/web/index.js.map +1 -1
- package/web/loro_wasm.d.ts +216 -17
- package/web/loro_wasm.js +216 -14
- package/web/loro_wasm_bg.wasm +0 -0
- package/web/loro_wasm_bg.wasm.d.ts +8 -1
- package/base64/loro_wasm_bg-543a4cca.js +0 -64
package/base64/loro_wasm.d.ts
CHANGED
|
@@ -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.
|
|
1948
|
+
* doc2.importBatch([snapshot, updates]);
|
|
1881
1949
|
* ```
|
|
1882
|
-
* @param {
|
|
1950
|
+
* @param {Uint8Array[]} data
|
|
1883
1951
|
* @returns {ImportStatus}
|
|
1884
1952
|
*/
|
|
1885
|
-
|
|
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 {
|
|
1979
|
+
* @returns {Record<string, ContainerID>}
|
|
1904
1980
|
*/
|
|
1905
|
-
getShallowValue():
|
|
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
|
|
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 {
|
|
2690
|
+
* @param {(string) => boolean} callback
|
|
2546
2691
|
*/
|
|
2547
|
-
iter(callback:
|
|
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;
|