loro-crdt 1.2.1 → 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 +10 -0
- package/base64/index.js +255 -12
- package/base64/loro_wasm.d.ts +206 -14
- 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 +206 -14
- package/bundler/loro_wasm_bg.js +207 -11
- package/bundler/loro_wasm_bg.wasm +0 -0
- package/bundler/loro_wasm_bg.wasm.d.ts +7 -0
- package/nodejs/index.js +47 -0
- package/nodejs/index.js.map +1 -1
- package/nodejs/loro_wasm.d.ts +206 -14
- package/nodejs/loro_wasm.js +207 -11
- package/nodejs/loro_wasm_bg.wasm +0 -0
- package/nodejs/loro_wasm_bg.wasm.d.ts +7 -0
- package/package.json +1 -1
- package/web/index.js +47 -0
- package/web/index.js.map +1 -1
- package/web/loro_wasm.d.ts +213 -14
- package/web/loro_wasm.js +207 -11
- package/web/loro_wasm_bg.wasm +0 -0
- package/web/loro_wasm_bg.wasm.d.ts +7 -0
- package/base64/loro_wasm_bg-101e42d1.js +0 -64
package/web/index.js
CHANGED
|
@@ -152,6 +152,53 @@ class Awareness {
|
|
|
152
152
|
}, this.timeout / 2);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
+
LoroDoc.prototype.toJsonWithReplacer = function (replacer) {
|
|
156
|
+
const doc = this;
|
|
157
|
+
const m = (key, value) => {
|
|
158
|
+
if (typeof value === "string") {
|
|
159
|
+
if (isContainerId(value)) {
|
|
160
|
+
const container = doc.getContainerById(value);
|
|
161
|
+
if (container == null) {
|
|
162
|
+
throw new Error(`ContainerID not found: ${value}`);
|
|
163
|
+
}
|
|
164
|
+
const ans = replacer(key, container);
|
|
165
|
+
if (ans === container) {
|
|
166
|
+
const ans = container.getShallowValue();
|
|
167
|
+
if (typeof ans === "object") {
|
|
168
|
+
return run(ans);
|
|
169
|
+
}
|
|
170
|
+
return ans;
|
|
171
|
+
}
|
|
172
|
+
if (isContainer(ans)) {
|
|
173
|
+
throw new Error("Using new container is not allowed in toJsonWithReplacer");
|
|
174
|
+
}
|
|
175
|
+
return ans;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const ans = replacer(key, value);
|
|
179
|
+
if (isContainer(ans)) {
|
|
180
|
+
throw new Error("Using new container is not allowed in toJsonWithReplacer");
|
|
181
|
+
}
|
|
182
|
+
return ans;
|
|
183
|
+
};
|
|
184
|
+
const run = (layer) => {
|
|
185
|
+
if (Array.isArray(layer)) {
|
|
186
|
+
return layer.map((item, index) => {
|
|
187
|
+
return m(index, item);
|
|
188
|
+
}).filter((item) => item !== undefined);
|
|
189
|
+
}
|
|
190
|
+
const result = {};
|
|
191
|
+
for (const [key, value] of Object.entries(layer)) {
|
|
192
|
+
const ans = m(key, value);
|
|
193
|
+
if (ans !== undefined) {
|
|
194
|
+
result[key] = ans;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
};
|
|
199
|
+
const layer = this.getShallowValue();
|
|
200
|
+
return run(layer);
|
|
201
|
+
};
|
|
155
202
|
|
|
156
203
|
export { Awareness, Loro, getType, isContainer, isContainerId, newContainerID, newRootContainerID };
|
|
157
204
|
//# sourceMappingURL=index.js.map
|
package/web/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAmBA;;AAEG;AACG,MAAO,IAAK,SAAQ,OAAO,CAAA;AAAI,CAAA;AAErC,MAAM,eAAe,GAAG;IACpB,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,aAAa;IACb,SAAS;CACZ,CAAC;AAEI,SAAU,aAAa,CAAC,CAAS,EAAA;AACnC,IAAA,OAAO,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED;;;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AE;YACtB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,KAAI;AAC7B,gBAAA,OAAO,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAC1B,aAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,KAAuC,IAAI,KAAK,SAAS,CAAC,CAAC;SAC7E;QAED,MAAM,MAAM,GAA0B,EAAE,CAAC;AACzC,QAAA,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC9C,MAAM,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAC1B,YAAA,IAAI,GAAG,KAAK,SAAS,EAAE;AACnB,gBAAA,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;aACrB;SACJ;AAED,QAAA,OAAO,MAAM,CAAC;AAClB,KAAC,CAAA;AAED,IAAA,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;AACrC,IAAA,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;;;;"}
|
package/web/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;
|
|
@@ -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;
|
|
@@ -3269,6 +3461,7 @@ export interface InitOutput {
|
|
|
3269
3461
|
readonly lorocounter_parent: (a: number) => number;
|
|
3270
3462
|
readonly lorocounter_isAttached: (a: number) => number;
|
|
3271
3463
|
readonly lorocounter_getAttached: (a: number) => number;
|
|
3464
|
+
readonly lorocounter_getShallowValue: (a: number) => number;
|
|
3272
3465
|
readonly __wbg_awarenesswasm_free: (a: number) => void;
|
|
3273
3466
|
readonly awarenesswasm_new: (a: number, b: number) => number;
|
|
3274
3467
|
readonly awarenesswasm_encode: (a: number, b: number, c: number) => void;
|
|
@@ -3335,6 +3528,7 @@ export interface InitOutput {
|
|
|
3335
3528
|
readonly lorodoc_importJsonUpdates: (a: number, b: number, c: number) => void;
|
|
3336
3529
|
readonly lorodoc_import: (a: number, b: number, c: number, d: number) => void;
|
|
3337
3530
|
readonly lorodoc_importUpdateBatch: (a: number, b: number, c: number) => void;
|
|
3531
|
+
readonly lorodoc_importBatch: (a: number, b: number, c: number) => void;
|
|
3338
3532
|
readonly lorodoc_getShallowValue: (a: number, b: number) => void;
|
|
3339
3533
|
readonly lorodoc_toJSON: (a: number, b: number) => void;
|
|
3340
3534
|
readonly lorodoc_subscribe: (a: number, b: number) => number;
|
|
@@ -3378,6 +3572,7 @@ export interface InitOutput {
|
|
|
3378
3572
|
readonly lorotext_push: (a: number, b: number, c: number, d: number) => void;
|
|
3379
3573
|
readonly lorotext_getEditorOf: (a: number, b: number) => number;
|
|
3380
3574
|
readonly lorotext_isDeleted: (a: number) => number;
|
|
3575
|
+
readonly lorotext_getShallowValue: (a: number, b: number) => void;
|
|
3381
3576
|
readonly __wbg_loromap_free: (a: number) => void;
|
|
3382
3577
|
readonly loromap_new: () => number;
|
|
3383
3578
|
readonly loromap_kind: (a: number) => number;
|
|
@@ -3398,6 +3593,7 @@ export interface InitOutput {
|
|
|
3398
3593
|
readonly loromap_clear: (a: number, b: number) => void;
|
|
3399
3594
|
readonly loromap_getLastEditor: (a: number, b: number, c: number) => number;
|
|
3400
3595
|
readonly loromap_isDeleted: (a: number) => number;
|
|
3596
|
+
readonly loromap_getShallowValue: (a: number) => number;
|
|
3401
3597
|
readonly __wbg_lorolist_free: (a: number) => void;
|
|
3402
3598
|
readonly lorolist_new: () => number;
|
|
3403
3599
|
readonly lorolist_kind: (a: number) => number;
|
|
@@ -3420,6 +3616,7 @@ export interface InitOutput {
|
|
|
3420
3616
|
readonly lorolist_clear: (a: number, b: number) => void;
|
|
3421
3617
|
readonly lorolist_getIdAt: (a: number, b: number) => number;
|
|
3422
3618
|
readonly lorolist_isDeleted: (a: number) => number;
|
|
3619
|
+
readonly lorolist_getShallowValue: (a: number) => number;
|
|
3423
3620
|
readonly loromovablelist_new: () => number;
|
|
3424
3621
|
readonly loromovablelist_kind: (a: number) => number;
|
|
3425
3622
|
readonly loromovablelist_insert: (a: number, b: number, c: number, d: number) => void;
|
|
@@ -3444,6 +3641,7 @@ export interface InitOutput {
|
|
|
3444
3641
|
readonly loromovablelist_getLastMoverAt: (a: number, b: number) => number;
|
|
3445
3642
|
readonly loromovablelist_getLastEditorAt: (a: number, b: number) => number;
|
|
3446
3643
|
readonly loromovablelist_isDeleted: (a: number) => number;
|
|
3644
|
+
readonly loromovablelist_getShallowValue: (a: number) => number;
|
|
3447
3645
|
readonly __wbg_lorotree_free: (a: number) => void;
|
|
3448
3646
|
readonly lorotreenode___getClassname: (a: number, b: number) => void;
|
|
3449
3647
|
readonly __wbg_lorotreenode_free: (a: number) => void;
|
|
@@ -3484,6 +3682,7 @@ export interface InitOutput {
|
|
|
3484
3682
|
readonly lorotree_disableFractionalIndex: (a: number) => void;
|
|
3485
3683
|
readonly lorotree_isFractionalIndexEnabled: (a: number) => number;
|
|
3486
3684
|
readonly lorotree_isDeleted: (a: number) => number;
|
|
3685
|
+
readonly lorotree_getShallowValue: (a: number) => number;
|
|
3487
3686
|
readonly __wbg_cursor_free: (a: number) => void;
|
|
3488
3687
|
readonly cursor_containerId: (a: number) => number;
|
|
3489
3688
|
readonly cursor_pos: (a: number) => number;
|