loro-crdt 1.1.1 → 1.1.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 +7 -0
- package/base64/index.d.ts +72 -0
- package/base64/index.js +6406 -0
- package/base64/loro_wasm.d.ts +3253 -0
- package/base64/loro_wasm_bg-4a32f96e.js +64 -0
- package/bundler/loro_wasm.d.ts +10 -0
- package/bundler/loro_wasm_bg.js +18 -2
- package/bundler/loro_wasm_bg.wasm +0 -0
- package/bundler/loro_wasm_bg.wasm.d.ts +2 -0
- package/nodejs/loro_wasm.d.ts +10 -0
- package/nodejs/loro_wasm.js +18 -2
- package/nodejs/loro_wasm_bg.wasm +0 -0
- package/nodejs/loro_wasm_bg.wasm.d.ts +2 -0
- package/package.json +9 -7
- package/web/loro_wasm.d.ts +12 -0
- package/web/loro_wasm.js +18 -2
- package/web/loro_wasm_bg.wasm +0 -0
- package/web/loro_wasm_bg.wasm.d.ts +2 -0
- package/bundler/vite.config.d.ts +0 -2
- package/nodejs/vite.config.d.ts +0 -2
- package/web/vite.config.d.ts +0 -2
|
@@ -0,0 +1,3253 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
*/
|
|
5
|
+
export function run(): void;
|
|
6
|
+
/**
|
|
7
|
+
* @param {({ peer: PeerID, counter: number })[]} frontiers
|
|
8
|
+
* @returns {Uint8Array}
|
|
9
|
+
*/
|
|
10
|
+
export function encodeFrontiers(frontiers: ({ peer: PeerID, counter: number })[]): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* @param {Uint8Array} bytes
|
|
13
|
+
* @returns {{ peer: PeerID, counter: number }[]}
|
|
14
|
+
*/
|
|
15
|
+
export function decodeFrontiers(bytes: Uint8Array): { peer: PeerID, counter: number }[];
|
|
16
|
+
/**
|
|
17
|
+
* Enable debug info of Loro
|
|
18
|
+
*/
|
|
19
|
+
export function setDebug(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Decode the metadata of the import blob.
|
|
22
|
+
*
|
|
23
|
+
* This method is useful to get the following metadata of the import blob:
|
|
24
|
+
*
|
|
25
|
+
* - startVersionVector
|
|
26
|
+
* - endVersionVector
|
|
27
|
+
* - startTimestamp
|
|
28
|
+
* - endTimestamp
|
|
29
|
+
* - mode
|
|
30
|
+
* - changeNum
|
|
31
|
+
* @param {Uint8Array} blob
|
|
32
|
+
* @param {boolean} check_checksum
|
|
33
|
+
* @returns {ImportBlobMetadata}
|
|
34
|
+
*/
|
|
35
|
+
export function decodeImportBlobMeta(blob: Uint8Array, check_checksum: boolean): ImportBlobMetadata;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Container types supported by loro.
|
|
39
|
+
*
|
|
40
|
+
* It is most commonly used to specify the type of sub-container to be created.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
44
|
+
*
|
|
45
|
+
* const doc = new LoroDoc();
|
|
46
|
+
* const list = doc.getList("list");
|
|
47
|
+
* list.insert(0, 100);
|
|
48
|
+
* const text = list.insertContainer(1, new LoroText());
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export type ContainerType = "Text" | "Map" | "List"| "Tree" | "MovableList";
|
|
52
|
+
|
|
53
|
+
export type PeerID = `${number}`;
|
|
54
|
+
/**
|
|
55
|
+
* The unique id of each container.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { LoroDoc } from "loro-crdt";
|
|
60
|
+
*
|
|
61
|
+
* const doc = new LoroDoc();
|
|
62
|
+
* const list = doc.getList("list");
|
|
63
|
+
* const containerId = list.id;
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export type ContainerID =
|
|
67
|
+
| `cid:root-${string}:${ContainerType}`
|
|
68
|
+
| `cid:${number}@${PeerID}:${ContainerType}`;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The unique id of each tree node.
|
|
72
|
+
*/
|
|
73
|
+
export type TreeID = `${number}@${PeerID}`;
|
|
74
|
+
|
|
75
|
+
interface LoroDoc {
|
|
76
|
+
/**
|
|
77
|
+
* Export updates from the specific version to the current version
|
|
78
|
+
*
|
|
79
|
+
* @deprecated Use `export({mode: "update", from: version})` instead
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { LoroDoc } from "loro-crdt";
|
|
84
|
+
*
|
|
85
|
+
* const doc = new LoroDoc();
|
|
86
|
+
* const text = doc.getText("text");
|
|
87
|
+
* text.insert(0, "Hello");
|
|
88
|
+
* // get all updates of the doc
|
|
89
|
+
* const updates = doc.exportFrom();
|
|
90
|
+
* const version = doc.oplogVersion();
|
|
91
|
+
* text.insert(5, " World");
|
|
92
|
+
* // get updates from specific version to the latest version
|
|
93
|
+
* const updates2 = doc.exportFrom(version);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
exportFrom(version?: VersionVector): Uint8Array;
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* Get the container corresponding to the container id
|
|
100
|
+
*
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { LoroDoc } from "loro-crdt";
|
|
105
|
+
*
|
|
106
|
+
* const doc = new LoroDoc();
|
|
107
|
+
* let text = doc.getText("text");
|
|
108
|
+
* const textId = text.id;
|
|
109
|
+
* text = doc.getContainerById(textId);
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
getContainerById(id: ContainerID): Container;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Subscribe to updates from local edits.
|
|
116
|
+
*
|
|
117
|
+
* This method allows you to listen for local changes made to the document.
|
|
118
|
+
* It's useful for syncing changes with other instances or saving updates.
|
|
119
|
+
*
|
|
120
|
+
* @param f - A callback function that receives a Uint8Array containing the update data.
|
|
121
|
+
* @returns A function to unsubscribe from the updates.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* const loro = new Loro();
|
|
126
|
+
* const text = loro.getText("text");
|
|
127
|
+
*
|
|
128
|
+
* const unsubscribe = loro.subscribeLocalUpdates((update) => {
|
|
129
|
+
* console.log("Local update received:", update);
|
|
130
|
+
* // You can send this update to other Loro instances
|
|
131
|
+
* });
|
|
132
|
+
*
|
|
133
|
+
* text.insert(0, "Hello");
|
|
134
|
+
* loro.commit();
|
|
135
|
+
*
|
|
136
|
+
* // Later, when you want to stop listening:
|
|
137
|
+
* unsubscribe();
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const loro1 = new Loro();
|
|
143
|
+
* const loro2 = new Loro();
|
|
144
|
+
*
|
|
145
|
+
* // Set up two-way sync
|
|
146
|
+
* loro1.subscribeLocalUpdates((updates) => {
|
|
147
|
+
* loro2.import(updates);
|
|
148
|
+
* });
|
|
149
|
+
*
|
|
150
|
+
* loro2.subscribeLocalUpdates((updates) => {
|
|
151
|
+
* loro1.import(updates);
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* // Now changes in loro1 will be reflected in loro2 and vice versa
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
subscribeLocalUpdates(f: (bytes: Uint8Array) => void): () => void
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Represents a `Delta` type which is a union of different operations that can be performed.
|
|
162
|
+
*
|
|
163
|
+
* @typeparam T - The data type for the `insert` operation.
|
|
164
|
+
*
|
|
165
|
+
* The `Delta` type can be one of three distinct shapes:
|
|
166
|
+
*
|
|
167
|
+
* 1. Insert Operation:
|
|
168
|
+
* - `insert`: The item to be inserted, of type T.
|
|
169
|
+
* - `attributes`: (Optional) A dictionary of attributes, describing styles in richtext
|
|
170
|
+
*
|
|
171
|
+
* 2. Delete Operation:
|
|
172
|
+
* - `delete`: The number of elements to delete.
|
|
173
|
+
*
|
|
174
|
+
* 3. Retain Operation:
|
|
175
|
+
* - `retain`: The number of elements to retain.
|
|
176
|
+
* - `attributes`: (Optional) A dictionary of attributes, describing styles in richtext
|
|
177
|
+
*/
|
|
178
|
+
export type Delta<T> =
|
|
179
|
+
| {
|
|
180
|
+
insert: T;
|
|
181
|
+
attributes?: { [key in string]: {} };
|
|
182
|
+
retain?: undefined;
|
|
183
|
+
delete?: undefined;
|
|
184
|
+
}
|
|
185
|
+
| {
|
|
186
|
+
delete: number;
|
|
187
|
+
attributes?: undefined;
|
|
188
|
+
retain?: undefined;
|
|
189
|
+
insert?: undefined;
|
|
190
|
+
}
|
|
191
|
+
| {
|
|
192
|
+
retain: number;
|
|
193
|
+
attributes?: { [key in string]: {} };
|
|
194
|
+
delete?: undefined;
|
|
195
|
+
insert?: undefined;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The unique id of each operation.
|
|
200
|
+
*/
|
|
201
|
+
export type OpId = { peer: PeerID, counter: number };
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Change is a group of continuous operations
|
|
205
|
+
*/
|
|
206
|
+
export interface Change {
|
|
207
|
+
peer: PeerID,
|
|
208
|
+
counter: number,
|
|
209
|
+
lamport: number,
|
|
210
|
+
length: number,
|
|
211
|
+
/**
|
|
212
|
+
* The timestamp in seconds.
|
|
213
|
+
*
|
|
214
|
+
* [Unix time](https://en.wikipedia.org/wiki/Unix_time)
|
|
215
|
+
* It is the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970.
|
|
216
|
+
*/
|
|
217
|
+
timestamp: number,
|
|
218
|
+
deps: OpId[],
|
|
219
|
+
message: string | undefined,
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Data types supported by loro
|
|
225
|
+
*/
|
|
226
|
+
export type Value =
|
|
227
|
+
| ContainerID
|
|
228
|
+
| string
|
|
229
|
+
| number
|
|
230
|
+
| boolean
|
|
231
|
+
| null
|
|
232
|
+
| { [key: string]: Value }
|
|
233
|
+
| Uint8Array
|
|
234
|
+
| Value[];
|
|
235
|
+
|
|
236
|
+
export type UndoConfig = {
|
|
237
|
+
mergeInterval?: number,
|
|
238
|
+
maxUndoSteps?: number,
|
|
239
|
+
excludeOriginPrefixes?: string[],
|
|
240
|
+
onPush?: (isUndo: boolean, counterRange: { start: number, end: number }) => { value: Value, cursors: Cursor[] },
|
|
241
|
+
onPop?: (isUndo: boolean, value: { value: Value, cursors: Cursor[] }, counterRange: { start: number, end: number }) => void
|
|
242
|
+
};
|
|
243
|
+
export type Container = LoroList | LoroMap | LoroText | LoroTree | LoroMovableList;
|
|
244
|
+
|
|
245
|
+
export interface ImportBlobMetadata {
|
|
246
|
+
/**
|
|
247
|
+
* The version vector of the start of the import.
|
|
248
|
+
*
|
|
249
|
+
* Import blob includes all the ops from `partial_start_vv` to `partial_end_vv`.
|
|
250
|
+
* However, it does not constitute a complete version vector, as it only contains counters
|
|
251
|
+
* from peers included within the import blob.
|
|
252
|
+
*/
|
|
253
|
+
partialStartVersionVector: VersionVector;
|
|
254
|
+
/**
|
|
255
|
+
* The version vector of the end of the import.
|
|
256
|
+
*
|
|
257
|
+
* Import blob includes all the ops from `partial_start_vv` to `partial_end_vv`.
|
|
258
|
+
* However, it does not constitute a complete version vector, as it only contains counters
|
|
259
|
+
* from peers included within the import blob.
|
|
260
|
+
*/
|
|
261
|
+
partialEndVersionVector: VersionVector;
|
|
262
|
+
|
|
263
|
+
startFrontiers: OpId[],
|
|
264
|
+
startTimestamp: number;
|
|
265
|
+
endTimestamp: number;
|
|
266
|
+
mode: "outdated-snapshot" | "outdated-update" | "snapshot" | "shallow-snapshot" | "update";
|
|
267
|
+
changeNum: number;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
interface LoroText {
|
|
271
|
+
/**
|
|
272
|
+
* Get the cursor position at the given pos.
|
|
273
|
+
*
|
|
274
|
+
* When expressing the position of a cursor, using "index" can be unstable
|
|
275
|
+
* because the cursor's position may change due to other deletions and insertions,
|
|
276
|
+
* requiring updates with each edit. To stably represent a position or range within
|
|
277
|
+
* a list structure, we can utilize the ID of each item/character on List CRDT or
|
|
278
|
+
* Text CRDT for expression.
|
|
279
|
+
*
|
|
280
|
+
* Loro optimizes State metadata by not storing the IDs of deleted elements. This
|
|
281
|
+
* approach complicates tracking cursors since they rely on these IDs. The solution
|
|
282
|
+
* recalculates position by replaying relevant history to update cursors
|
|
283
|
+
* accurately. To minimize the performance impact of history replay, the system
|
|
284
|
+
* updates cursor info to reference only the IDs of currently present elements,
|
|
285
|
+
* thereby reducing the need for replay.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
*
|
|
290
|
+
* const doc = new LoroDoc();
|
|
291
|
+
* const text = doc.getText("text");
|
|
292
|
+
* text.insert(0, "123");
|
|
293
|
+
* const pos0 = text.getCursor(0, 0);
|
|
294
|
+
* {
|
|
295
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
296
|
+
* expect(ans.offset).toBe(0);
|
|
297
|
+
* }
|
|
298
|
+
* text.insert(0, "1");
|
|
299
|
+
* {
|
|
300
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
301
|
+
* expect(ans.offset).toBe(1);
|
|
302
|
+
* }
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
getCursor(pos: number, side?: Side): Cursor | undefined;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
interface LoroList {
|
|
309
|
+
/**
|
|
310
|
+
* Get the cursor position at the given pos.
|
|
311
|
+
*
|
|
312
|
+
* When expressing the position of a cursor, using "index" can be unstable
|
|
313
|
+
* because the cursor's position may change due to other deletions and insertions,
|
|
314
|
+
* requiring updates with each edit. To stably represent a position or range within
|
|
315
|
+
* a list structure, we can utilize the ID of each item/character on List CRDT or
|
|
316
|
+
* Text CRDT for expression.
|
|
317
|
+
*
|
|
318
|
+
* Loro optimizes State metadata by not storing the IDs of deleted elements. This
|
|
319
|
+
* approach complicates tracking cursors since they rely on these IDs. The solution
|
|
320
|
+
* recalculates position by replaying relevant history to update cursors
|
|
321
|
+
* accurately. To minimize the performance impact of history replay, the system
|
|
322
|
+
* updates cursor info to reference only the IDs of currently present elements,
|
|
323
|
+
* thereby reducing the need for replay.
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```ts
|
|
327
|
+
*
|
|
328
|
+
* const doc = new LoroDoc();
|
|
329
|
+
* const text = doc.getList("list");
|
|
330
|
+
* text.insert(0, "1");
|
|
331
|
+
* const pos0 = text.getCursor(0, 0);
|
|
332
|
+
* {
|
|
333
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
334
|
+
* expect(ans.offset).toBe(0);
|
|
335
|
+
* }
|
|
336
|
+
* text.insert(0, "1");
|
|
337
|
+
* {
|
|
338
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
339
|
+
* expect(ans.offset).toBe(1);
|
|
340
|
+
* }
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
getCursor(pos: number, side?: Side): Cursor | undefined;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export type TreeNodeValue = {
|
|
347
|
+
id: TreeID,
|
|
348
|
+
parent: TreeID | undefined,
|
|
349
|
+
index: number,
|
|
350
|
+
fractionalIndex: string,
|
|
351
|
+
meta: LoroMap,
|
|
352
|
+
children: TreeNodeValue[],
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export type TreeNodeJSON<T> = Omit<TreeNodeValue, 'meta' | 'children'> & {
|
|
356
|
+
meta: T,
|
|
357
|
+
children: TreeNodeJSON<T>[],
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
interface LoroTree{
|
|
361
|
+
toArray(): TreeNodeValue[];
|
|
362
|
+
getNodes(options?: { withDeleted: boolean = false }): LoroTreeNode[];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
interface LoroMovableList {
|
|
366
|
+
/**
|
|
367
|
+
* Get the cursor position at the given pos.
|
|
368
|
+
*
|
|
369
|
+
* When expressing the position of a cursor, using "index" can be unstable
|
|
370
|
+
* because the cursor's position may change due to other deletions and insertions,
|
|
371
|
+
* requiring updates with each edit. To stably represent a position or range within
|
|
372
|
+
* a list structure, we can utilize the ID of each item/character on List CRDT or
|
|
373
|
+
* Text CRDT for expression.
|
|
374
|
+
*
|
|
375
|
+
* Loro optimizes State metadata by not storing the IDs of deleted elements. This
|
|
376
|
+
* approach complicates tracking cursors since they rely on these IDs. The solution
|
|
377
|
+
* recalculates position by replaying relevant history to update cursors
|
|
378
|
+
* accurately. To minimize the performance impact of history replay, the system
|
|
379
|
+
* updates cursor info to reference only the IDs of currently present elements,
|
|
380
|
+
* thereby reducing the need for replay.
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
*
|
|
385
|
+
* const doc = new LoroDoc();
|
|
386
|
+
* const text = doc.getMovableList("text");
|
|
387
|
+
* text.insert(0, "1");
|
|
388
|
+
* const pos0 = text.getCursor(0, 0);
|
|
389
|
+
* {
|
|
390
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
391
|
+
* expect(ans.offset).toBe(0);
|
|
392
|
+
* }
|
|
393
|
+
* text.insert(0, "1");
|
|
394
|
+
* {
|
|
395
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
396
|
+
* expect(ans.offset).toBe(1);
|
|
397
|
+
* }
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
getCursor(pos: number, side?: Side): Cursor | undefined;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export type Side = -1 | 0 | 1;
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
export type JsonOpID = `${number}@${PeerID}`;
|
|
408
|
+
export type JsonContainerID = `🦜:${ContainerID}` ;
|
|
409
|
+
export type JsonValue =
|
|
410
|
+
| JsonContainerID
|
|
411
|
+
| string
|
|
412
|
+
| number
|
|
413
|
+
| boolean
|
|
414
|
+
| null
|
|
415
|
+
| { [key: string]: JsonValue }
|
|
416
|
+
| Uint8Array
|
|
417
|
+
| JsonValue[];
|
|
418
|
+
|
|
419
|
+
export type JsonSchema = {
|
|
420
|
+
schema_version: number;
|
|
421
|
+
start_version: Map<string, number>,
|
|
422
|
+
peers: PeerID[],
|
|
423
|
+
changes: JsonChange[]
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
export type JsonChange = {
|
|
427
|
+
id: JsonOpID
|
|
428
|
+
/**
|
|
429
|
+
* The timestamp in seconds.
|
|
430
|
+
*
|
|
431
|
+
* [Unix time](https://en.wikipedia.org/wiki/Unix_time)
|
|
432
|
+
* It is the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970.
|
|
433
|
+
*/
|
|
434
|
+
timestamp: number,
|
|
435
|
+
deps: JsonOpID[],
|
|
436
|
+
lamport: number,
|
|
437
|
+
msg: string | null,
|
|
438
|
+
ops: JsonOp[]
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export interface TextUpdateOptions {
|
|
442
|
+
timeoutMs?: number,
|
|
443
|
+
useRefinedDiff?: boolean,
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export type ExportMode = {
|
|
447
|
+
mode: "update",
|
|
448
|
+
from?: VersionVector,
|
|
449
|
+
} | {
|
|
450
|
+
mode: "snapshot",
|
|
451
|
+
} | {
|
|
452
|
+
mode: "shallow-snapshot",
|
|
453
|
+
frontiers: Frontiers,
|
|
454
|
+
} | {
|
|
455
|
+
mode: "updates-in-range",
|
|
456
|
+
spans: {
|
|
457
|
+
id: ID,
|
|
458
|
+
len: number,
|
|
459
|
+
}[],
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
export type JsonOp = {
|
|
463
|
+
container: ContainerID,
|
|
464
|
+
counter: number,
|
|
465
|
+
content: ListOp | TextOp | MapOp | TreeOp | MovableListOp | UnknownOp
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export type ListOp = {
|
|
469
|
+
type: "insert",
|
|
470
|
+
pos: number,
|
|
471
|
+
value: JsonValue
|
|
472
|
+
} | {
|
|
473
|
+
type: "delete",
|
|
474
|
+
pos: number,
|
|
475
|
+
len: number,
|
|
476
|
+
start_id: JsonOpID,
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
export type MovableListOp = {
|
|
480
|
+
type: "insert",
|
|
481
|
+
pos: number,
|
|
482
|
+
value: JsonValue
|
|
483
|
+
} | {
|
|
484
|
+
type: "delete",
|
|
485
|
+
pos: number,
|
|
486
|
+
len: number,
|
|
487
|
+
start_id: JsonOpID,
|
|
488
|
+
}| {
|
|
489
|
+
type: "move",
|
|
490
|
+
from: number,
|
|
491
|
+
to: number,
|
|
492
|
+
elem_id: JsonOpID,
|
|
493
|
+
}|{
|
|
494
|
+
type: "set",
|
|
495
|
+
elem_id: JsonOpID,
|
|
496
|
+
value: JsonValue
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export type TextOp = {
|
|
500
|
+
type: "insert",
|
|
501
|
+
pos: number,
|
|
502
|
+
text: string
|
|
503
|
+
} | {
|
|
504
|
+
type: "delete",
|
|
505
|
+
pos: number,
|
|
506
|
+
len: number,
|
|
507
|
+
start_id: JsonOpID,
|
|
508
|
+
} | {
|
|
509
|
+
type: "mark",
|
|
510
|
+
start: number,
|
|
511
|
+
end: number,
|
|
512
|
+
style_key: string,
|
|
513
|
+
style_value: JsonValue,
|
|
514
|
+
info: number
|
|
515
|
+
}|{
|
|
516
|
+
type: "mark_end"
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
export type MapOp = {
|
|
520
|
+
type: "insert",
|
|
521
|
+
key: string,
|
|
522
|
+
value: JsonValue
|
|
523
|
+
} | {
|
|
524
|
+
type: "delete",
|
|
525
|
+
key: string,
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
export type TreeOp = {
|
|
529
|
+
type: "create",
|
|
530
|
+
target: TreeID,
|
|
531
|
+
parent: TreeID | undefined,
|
|
532
|
+
fractional_index: string
|
|
533
|
+
}|{
|
|
534
|
+
type: "move",
|
|
535
|
+
target: TreeID,
|
|
536
|
+
parent: TreeID | undefined,
|
|
537
|
+
fractional_index: string
|
|
538
|
+
}|{
|
|
539
|
+
type: "delete",
|
|
540
|
+
target: TreeID
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
export type UnknownOp = {
|
|
544
|
+
type: "unknown"
|
|
545
|
+
prop: number,
|
|
546
|
+
value_type: "unknown",
|
|
547
|
+
value: {
|
|
548
|
+
kind: number,
|
|
549
|
+
data: Uint8Array
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
export type CounterSpan = { start: number, end: number };
|
|
554
|
+
|
|
555
|
+
export type ImportStatus = {
|
|
556
|
+
success: Map<PeerID, CounterSpan>,
|
|
557
|
+
pending: Map<PeerID, CounterSpan> | null
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export type Frontiers = OpId[];
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Represents a path to identify the exact location of an event's target.
|
|
564
|
+
* The path is composed of numbers (e.g., indices of a list container) strings
|
|
565
|
+
* (e.g., keys of a map container) and TreeID (the node of a tree container),
|
|
566
|
+
* indicating the absolute position of the event's source within a loro document.
|
|
567
|
+
*/
|
|
568
|
+
export type Path = (number | string | TreeID)[];
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* A batch of events that created by a single `import`/`transaction`/`checkout`.
|
|
572
|
+
*
|
|
573
|
+
* @prop by - How the event is triggered.
|
|
574
|
+
* @prop origin - (Optional) Provides information about the origin of the event.
|
|
575
|
+
* @prop diff - Contains the differential information related to the event.
|
|
576
|
+
* @prop target - Identifies the container ID of the event's target.
|
|
577
|
+
* @prop path - Specifies the absolute path of the event's emitter, which can be an index of a list container or a key of a map container.
|
|
578
|
+
*/
|
|
579
|
+
export interface LoroEventBatch {
|
|
580
|
+
/**
|
|
581
|
+
* How the event is triggered.
|
|
582
|
+
*
|
|
583
|
+
* - `local`: The event is triggered by a local transaction.
|
|
584
|
+
* - `import`: The event is triggered by an import operation.
|
|
585
|
+
* - `checkout`: The event is triggered by a checkout operation.
|
|
586
|
+
*/
|
|
587
|
+
by: "local" | "import" | "checkout";
|
|
588
|
+
origin?: string;
|
|
589
|
+
/**
|
|
590
|
+
* The container ID of the current event receiver.
|
|
591
|
+
* It's undefined if the subscriber is on the root document.
|
|
592
|
+
*/
|
|
593
|
+
currentTarget?: ContainerID;
|
|
594
|
+
events: LoroEvent[];
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* The concrete event of Loro.
|
|
599
|
+
*/
|
|
600
|
+
export interface LoroEvent {
|
|
601
|
+
/**
|
|
602
|
+
* The container ID of the event's target.
|
|
603
|
+
*/
|
|
604
|
+
target: ContainerID;
|
|
605
|
+
diff: Diff;
|
|
606
|
+
/**
|
|
607
|
+
* The absolute path of the event's emitter, which can be an index of a list container or a key of a map container.
|
|
608
|
+
*/
|
|
609
|
+
path: Path;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
export type ListDiff = {
|
|
613
|
+
type: "list";
|
|
614
|
+
diff: Delta<(Value | Container)[]>[];
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
export type TextDiff = {
|
|
618
|
+
type: "text";
|
|
619
|
+
diff: Delta<string>[];
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
export type MapDiff = {
|
|
623
|
+
type: "map";
|
|
624
|
+
updated: Record<string, Value | Container | undefined>;
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
export type TreeDiffItem =
|
|
628
|
+
| {
|
|
629
|
+
target: TreeID;
|
|
630
|
+
action: "create";
|
|
631
|
+
parent: TreeID | undefined;
|
|
632
|
+
index: number;
|
|
633
|
+
fractionalIndex: string;
|
|
634
|
+
}
|
|
635
|
+
| {
|
|
636
|
+
target: TreeID;
|
|
637
|
+
action: "delete";
|
|
638
|
+
oldParent: TreeID | undefined;
|
|
639
|
+
oldIndex: number;
|
|
640
|
+
}
|
|
641
|
+
| {
|
|
642
|
+
target: TreeID;
|
|
643
|
+
action: "move";
|
|
644
|
+
parent: TreeID | undefined;
|
|
645
|
+
index: number;
|
|
646
|
+
fractionalIndex: string;
|
|
647
|
+
oldParent: TreeID | undefined;
|
|
648
|
+
oldIndex: number;
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
export type TreeDiff = {
|
|
652
|
+
type: "tree";
|
|
653
|
+
diff: TreeDiffItem[];
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
export type CounterDiff = {
|
|
657
|
+
type: "counter";
|
|
658
|
+
increment: number;
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
export type Diff = ListDiff | TextDiff | MapDiff | TreeDiff | CounterDiff;
|
|
662
|
+
export type Subscription = () => void;
|
|
663
|
+
type NonNullableType<T> = Exclude<T, null | undefined>;
|
|
664
|
+
export type AwarenessListener = (
|
|
665
|
+
arg: { updated: PeerID[]; added: PeerID[]; removed: PeerID[] },
|
|
666
|
+
origin: "local" | "timeout" | "remote" | string,
|
|
667
|
+
) => void;
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
interface Listener {
|
|
671
|
+
(event: LoroEventBatch): void;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
interface LoroDoc {
|
|
675
|
+
subscribe(listener: Listener): Subscription;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
interface UndoManager {
|
|
679
|
+
/**
|
|
680
|
+
* Set the callback function that is called when an undo/redo step is pushed.
|
|
681
|
+
* The function can return a meta data value that will be attached to the given stack item.
|
|
682
|
+
*
|
|
683
|
+
* @param listener - The callback function.
|
|
684
|
+
*/
|
|
685
|
+
setOnPush(listener?: UndoConfig["onPush"]): void;
|
|
686
|
+
/**
|
|
687
|
+
* Set the callback function that is called when an undo/redo step is popped.
|
|
688
|
+
* The function will have a meta data value that was attached to the given stack item when `onPush` was called.
|
|
689
|
+
*
|
|
690
|
+
* @param listener - The callback function.
|
|
691
|
+
*/
|
|
692
|
+
setOnPop(listener?: UndoConfig["onPop"]): void;
|
|
693
|
+
}
|
|
694
|
+
interface LoroDoc<T extends Record<string, Container> = Record<string, Container>> {
|
|
695
|
+
/**
|
|
696
|
+
* Get a LoroMap by container id
|
|
697
|
+
*
|
|
698
|
+
* The object returned is a new js object each time because it need to cross
|
|
699
|
+
* the WASM boundary.
|
|
700
|
+
*
|
|
701
|
+
* @example
|
|
702
|
+
* ```ts
|
|
703
|
+
* import { LoroDoc } from "loro-crdt";
|
|
704
|
+
*
|
|
705
|
+
* const doc = new LoroDoc();
|
|
706
|
+
* const map = doc.getMap("map");
|
|
707
|
+
* ```
|
|
708
|
+
*/
|
|
709
|
+
getMap<Key extends keyof T | ContainerID>(name: Key): T[Key] extends LoroMap ? T[Key] : LoroMap;
|
|
710
|
+
/**
|
|
711
|
+
* Get a LoroList by container id
|
|
712
|
+
*
|
|
713
|
+
* The object returned is a new js object each time because it need to cross
|
|
714
|
+
* the WASM boundary.
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* ```ts
|
|
718
|
+
* import { LoroDoc } from "loro-crdt";
|
|
719
|
+
*
|
|
720
|
+
* const doc = new LoroDoc();
|
|
721
|
+
* const list = doc.getList("list");
|
|
722
|
+
* ```
|
|
723
|
+
*/
|
|
724
|
+
getList<Key extends keyof T | ContainerID>(name: Key): T[Key] extends LoroList ? T[Key] : LoroList;
|
|
725
|
+
/**
|
|
726
|
+
* Get a LoroMovableList by container id
|
|
727
|
+
*
|
|
728
|
+
* The object returned is a new js object each time because it need to cross
|
|
729
|
+
* the WASM boundary.
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* ```ts
|
|
733
|
+
* import { LoroDoc } from "loro-crdt";
|
|
734
|
+
*
|
|
735
|
+
* const doc = new LoroDoc();
|
|
736
|
+
* const list = doc.getList("list");
|
|
737
|
+
* ```
|
|
738
|
+
*/
|
|
739
|
+
getMovableList<Key extends keyof T | ContainerID>(name: Key): T[Key] extends LoroMovableList ? T[Key] : LoroMovableList;
|
|
740
|
+
/**
|
|
741
|
+
* Get a LoroTree by container id
|
|
742
|
+
*
|
|
743
|
+
* The object returned is a new js object each time because it need to cross
|
|
744
|
+
* the WASM boundary.
|
|
745
|
+
*
|
|
746
|
+
* @example
|
|
747
|
+
* ```ts
|
|
748
|
+
* import { LoroDoc } from "loro-crdt";
|
|
749
|
+
*
|
|
750
|
+
* const doc = new LoroDoc();
|
|
751
|
+
* const tree = doc.getTree("tree");
|
|
752
|
+
* ```
|
|
753
|
+
*/
|
|
754
|
+
getTree<Key extends keyof T | ContainerID>(name: Key): T[Key] extends LoroTree ? T[Key] : LoroTree;
|
|
755
|
+
getText(key: string | ContainerID): LoroText;
|
|
756
|
+
}
|
|
757
|
+
interface LoroList<T = unknown> {
|
|
758
|
+
new(): LoroList<T>;
|
|
759
|
+
/**
|
|
760
|
+
* Get elements of the list. If the value is a child container, the corresponding
|
|
761
|
+
* `Container` will be returned.
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* ```ts
|
|
765
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
766
|
+
*
|
|
767
|
+
* const doc = new LoroDoc();
|
|
768
|
+
* const list = doc.getList("list");
|
|
769
|
+
* list.insert(0, 100);
|
|
770
|
+
* list.insert(1, "foo");
|
|
771
|
+
* list.insert(2, true);
|
|
772
|
+
* list.insertContainer(3, new LoroText());
|
|
773
|
+
* console.log(list.value); // [100, "foo", true, LoroText];
|
|
774
|
+
* ```
|
|
775
|
+
*/
|
|
776
|
+
toArray(): T[];
|
|
777
|
+
/**
|
|
778
|
+
* Insert a container at the index.
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* ```ts
|
|
782
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
783
|
+
*
|
|
784
|
+
* const doc = new LoroDoc();
|
|
785
|
+
* const list = doc.getList("list");
|
|
786
|
+
* list.insert(0, 100);
|
|
787
|
+
* const text = list.insertContainer(1, new LoroText());
|
|
788
|
+
* text.insert(0, "Hello");
|
|
789
|
+
* console.log(list.toJSON()); // [100, "Hello"];
|
|
790
|
+
* ```
|
|
791
|
+
*/
|
|
792
|
+
insertContainer<C extends Container>(pos: number, child: C): T extends C ? T : C;
|
|
793
|
+
/**
|
|
794
|
+
* Push a container to the end of the list.
|
|
795
|
+
*/
|
|
796
|
+
pushContainer<C extends Container>(child: C): T extends C ? T : C;
|
|
797
|
+
/**
|
|
798
|
+
* Get the value at the index. If the value is a container, the corresponding handler will be returned.
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* ```ts
|
|
802
|
+
* import { LoroDoc } from "loro-crdt";
|
|
803
|
+
*
|
|
804
|
+
* const doc = new LoroDoc();
|
|
805
|
+
* const list = doc.getList("list");
|
|
806
|
+
* list.insert(0, 100);
|
|
807
|
+
* console.log(list.get(0)); // 100
|
|
808
|
+
* console.log(list.get(1)); // undefined
|
|
809
|
+
* ```
|
|
810
|
+
*/
|
|
811
|
+
get(index: number): T;
|
|
812
|
+
/**
|
|
813
|
+
* Insert a value at index.
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* ```ts
|
|
817
|
+
* import { LoroDoc } from "loro-crdt";
|
|
818
|
+
*
|
|
819
|
+
* const doc = new LoroDoc();
|
|
820
|
+
* const list = doc.getList("list");
|
|
821
|
+
* list.insert(0, 100);
|
|
822
|
+
* list.insert(1, "foo");
|
|
823
|
+
* list.insert(2, true);
|
|
824
|
+
* console.log(list.value); // [100, "foo", true];
|
|
825
|
+
* ```
|
|
826
|
+
*/
|
|
827
|
+
insert<V extends T>(pos: number, value: Exclude<V, Container>): void;
|
|
828
|
+
delete(pos: number, len: number): void;
|
|
829
|
+
push<V extends T>(value: Exclude<V, Container>): void;
|
|
830
|
+
subscribe(listener: Listener): Subscription;
|
|
831
|
+
getAttached(): undefined | LoroList<T>;
|
|
832
|
+
}
|
|
833
|
+
interface LoroMovableList<T = unknown> {
|
|
834
|
+
new(): LoroMovableList<T>;
|
|
835
|
+
/**
|
|
836
|
+
* Get elements of the list. If the value is a child container, the corresponding
|
|
837
|
+
* `Container` will be returned.
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```ts
|
|
841
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
842
|
+
*
|
|
843
|
+
* const doc = new LoroDoc();
|
|
844
|
+
* const list = doc.getMovableList("list");
|
|
845
|
+
* list.insert(0, 100);
|
|
846
|
+
* list.insert(1, "foo");
|
|
847
|
+
* list.insert(2, true);
|
|
848
|
+
* list.insertContainer(3, new LoroText());
|
|
849
|
+
* console.log(list.value); // [100, "foo", true, LoroText];
|
|
850
|
+
* ```
|
|
851
|
+
*/
|
|
852
|
+
toArray(): T[];
|
|
853
|
+
/**
|
|
854
|
+
* Insert a container at the index.
|
|
855
|
+
*
|
|
856
|
+
* @example
|
|
857
|
+
* ```ts
|
|
858
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
859
|
+
*
|
|
860
|
+
* const doc = new LoroDoc();
|
|
861
|
+
* const list = doc.getMovableList("list");
|
|
862
|
+
* list.insert(0, 100);
|
|
863
|
+
* const text = list.insertContainer(1, new LoroText());
|
|
864
|
+
* text.insert(0, "Hello");
|
|
865
|
+
* console.log(list.toJSON()); // [100, "Hello"];
|
|
866
|
+
* ```
|
|
867
|
+
*/
|
|
868
|
+
insertContainer<C extends Container>(pos: number, child: C): T extends C ? T : C;
|
|
869
|
+
/**
|
|
870
|
+
* Push a container to the end of the list.
|
|
871
|
+
*/
|
|
872
|
+
pushContainer<C extends Container>(child: C): T extends C ? T : C;
|
|
873
|
+
/**
|
|
874
|
+
* Get the value at the index. If the value is a container, the corresponding handler will be returned.
|
|
875
|
+
*
|
|
876
|
+
* @example
|
|
877
|
+
* ```ts
|
|
878
|
+
* import { LoroDoc } from "loro-crdt";
|
|
879
|
+
*
|
|
880
|
+
* const doc = new LoroDoc();
|
|
881
|
+
* const list = doc.getMovableList("list");
|
|
882
|
+
* list.insert(0, 100);
|
|
883
|
+
* console.log(list.get(0)); // 100
|
|
884
|
+
* console.log(list.get(1)); // undefined
|
|
885
|
+
* ```
|
|
886
|
+
*/
|
|
887
|
+
get(index: number): T;
|
|
888
|
+
/**
|
|
889
|
+
* Insert a value at index.
|
|
890
|
+
*
|
|
891
|
+
* @example
|
|
892
|
+
* ```ts
|
|
893
|
+
* import { LoroDoc } from "loro-crdt";
|
|
894
|
+
*
|
|
895
|
+
* const doc = new LoroDoc();
|
|
896
|
+
* const list = doc.getMovableList("list");
|
|
897
|
+
* list.insert(0, 100);
|
|
898
|
+
* list.insert(1, "foo");
|
|
899
|
+
* list.insert(2, true);
|
|
900
|
+
* console.log(list.value); // [100, "foo", true];
|
|
901
|
+
* ```
|
|
902
|
+
*/
|
|
903
|
+
insert<V extends T>(pos: number, value: Exclude<V, Container>): void;
|
|
904
|
+
delete(pos: number, len: number): void;
|
|
905
|
+
push<V extends T>(value: Exclude<V, Container>): void;
|
|
906
|
+
subscribe(listener: Listener): Subscription;
|
|
907
|
+
getAttached(): undefined | LoroMovableList<T>;
|
|
908
|
+
/**
|
|
909
|
+
* Set the value at the given position.
|
|
910
|
+
*
|
|
911
|
+
* It's different from `delete` + `insert` that it will replace the value at the position.
|
|
912
|
+
*
|
|
913
|
+
* For example, if you have a list `[1, 2, 3]`, and you call `set(1, 100)`, the list will be `[1, 100, 3]`.
|
|
914
|
+
* If concurrently someone call `set(1, 200)`, the list will be `[1, 200, 3]` or `[1, 100, 3]`.
|
|
915
|
+
*
|
|
916
|
+
* But if you use `delete` + `insert` to simulate the set operation, they may create redundant operations
|
|
917
|
+
* and the final result will be `[1, 100, 200, 3]` or `[1, 200, 100, 3]`.
|
|
918
|
+
*
|
|
919
|
+
* @example
|
|
920
|
+
* ```ts
|
|
921
|
+
* import { LoroDoc } from "loro-crdt";
|
|
922
|
+
*
|
|
923
|
+
* const doc = new LoroDoc();
|
|
924
|
+
* const list = doc.getMovableList("list");
|
|
925
|
+
* list.insert(0, 100);
|
|
926
|
+
* list.insert(1, "foo");
|
|
927
|
+
* list.insert(2, true);
|
|
928
|
+
* list.set(1, "bar");
|
|
929
|
+
* console.log(list.value); // [100, "bar", true];
|
|
930
|
+
* ```
|
|
931
|
+
*/
|
|
932
|
+
set<V extends T>(pos: number, value: Exclude<V, Container>): void;
|
|
933
|
+
/**
|
|
934
|
+
* Set a container at the index.
|
|
935
|
+
*
|
|
936
|
+
* @example
|
|
937
|
+
* ```ts
|
|
938
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
939
|
+
*
|
|
940
|
+
* const doc = new LoroDoc();
|
|
941
|
+
* const list = doc.getMovableList("list");
|
|
942
|
+
* list.insert(0, 100);
|
|
943
|
+
* const text = list.setContainer(0, new LoroText());
|
|
944
|
+
* text.insert(0, "Hello");
|
|
945
|
+
* console.log(list.toJSON()); // ["Hello"];
|
|
946
|
+
* ```
|
|
947
|
+
*/
|
|
948
|
+
setContainer<C extends Container>(pos: number, child: C): T extends C ? T : C;
|
|
949
|
+
}
|
|
950
|
+
interface LoroMap<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
951
|
+
new(): LoroMap<T>;
|
|
952
|
+
/**
|
|
953
|
+
* Get the value of the key. If the value is a child container, the corresponding
|
|
954
|
+
* `Container` will be returned.
|
|
955
|
+
*
|
|
956
|
+
* The object returned is a new js object each time because it need to cross
|
|
957
|
+
*
|
|
958
|
+
* @example
|
|
959
|
+
* ```ts
|
|
960
|
+
* import { LoroDoc } from "loro-crdt";
|
|
961
|
+
*
|
|
962
|
+
* const doc = new LoroDoc();
|
|
963
|
+
* const map = doc.getMap("map");
|
|
964
|
+
* map.set("foo", "bar");
|
|
965
|
+
* const bar = map.get("foo");
|
|
966
|
+
* ```
|
|
967
|
+
*/
|
|
968
|
+
getOrCreateContainer<C extends Container>(key: string, child: C): C;
|
|
969
|
+
/**
|
|
970
|
+
* Set the key with a container.
|
|
971
|
+
*
|
|
972
|
+
* @example
|
|
973
|
+
* ```ts
|
|
974
|
+
* import { LoroDoc, LoroText, LoroList } from "loro-crdt";
|
|
975
|
+
*
|
|
976
|
+
* const doc = new LoroDoc();
|
|
977
|
+
* const map = doc.getMap("map");
|
|
978
|
+
* map.set("foo", "bar");
|
|
979
|
+
* const text = map.setContainer("text", new LoroText());
|
|
980
|
+
* const list = map.setContainer("list", new LoroList());
|
|
981
|
+
* ```
|
|
982
|
+
*/
|
|
983
|
+
setContainer<C extends Container, Key extends keyof T>(key: Key, child: C): NonNullableType<T[Key]> extends C ? NonNullableType<T[Key]> : C;
|
|
984
|
+
/**
|
|
985
|
+
* Get the value of the key. If the value is a child container, the corresponding
|
|
986
|
+
* `Container` will be returned.
|
|
987
|
+
*
|
|
988
|
+
* The object/value returned is a new js object/value each time because it need to cross
|
|
989
|
+
* the WASM boundary.
|
|
990
|
+
*
|
|
991
|
+
* @example
|
|
992
|
+
* ```ts
|
|
993
|
+
* import { LoroDoc } from "loro-crdt";
|
|
994
|
+
*
|
|
995
|
+
* const doc = new LoroDoc();
|
|
996
|
+
* const map = doc.getMap("map");
|
|
997
|
+
* map.set("foo", "bar");
|
|
998
|
+
* const bar = map.get("foo");
|
|
999
|
+
* ```
|
|
1000
|
+
*/
|
|
1001
|
+
get<Key extends keyof T>(key: Key): T[Key];
|
|
1002
|
+
/**
|
|
1003
|
+
* Set the key with the value.
|
|
1004
|
+
*
|
|
1005
|
+
* If the value of the key is exist, the old value will be updated.
|
|
1006
|
+
*
|
|
1007
|
+
* @example
|
|
1008
|
+
* ```ts
|
|
1009
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1010
|
+
*
|
|
1011
|
+
* const doc = new LoroDoc();
|
|
1012
|
+
* const map = doc.getMap("map");
|
|
1013
|
+
* map.set("foo", "bar");
|
|
1014
|
+
* map.set("foo", "baz");
|
|
1015
|
+
* ```
|
|
1016
|
+
*/
|
|
1017
|
+
set<Key extends keyof T, V extends T[Key]>(key: Key, value: Exclude<V, Container>): void;
|
|
1018
|
+
delete(key: string): void;
|
|
1019
|
+
subscribe(listener: Listener): Subscription;
|
|
1020
|
+
}
|
|
1021
|
+
interface LoroText {
|
|
1022
|
+
new(): LoroText;
|
|
1023
|
+
insert(pos: number, text: string): void;
|
|
1024
|
+
delete(pos: number, len: number): void;
|
|
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;
|
|
1052
|
+
}
|
|
1053
|
+
interface LoroTree<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
1054
|
+
new(): LoroTree<T>;
|
|
1055
|
+
/**
|
|
1056
|
+
* Create a new tree node as the child of parent and return a `LoroTreeNode` instance.
|
|
1057
|
+
* If the parent is undefined, the tree node will be a root node.
|
|
1058
|
+
*
|
|
1059
|
+
* If the index is not provided, the new node will be appended to the end.
|
|
1060
|
+
*
|
|
1061
|
+
* @example
|
|
1062
|
+
* ```ts
|
|
1063
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1064
|
+
*
|
|
1065
|
+
* const doc = new LoroDoc();
|
|
1066
|
+
* const tree = doc.getTree("tree");
|
|
1067
|
+
* const root = tree.createNode();
|
|
1068
|
+
* const node = tree.createNode(undefined, 0);
|
|
1069
|
+
*
|
|
1070
|
+
* // undefined
|
|
1071
|
+
* // / \
|
|
1072
|
+
* // node root
|
|
1073
|
+
* ```
|
|
1074
|
+
*/
|
|
1075
|
+
createNode(parent?: TreeID, index?: number): LoroTreeNode<T>;
|
|
1076
|
+
move(target: TreeID, parent?: TreeID, index?: number): void;
|
|
1077
|
+
delete(target: TreeID): void;
|
|
1078
|
+
has(target: TreeID): boolean;
|
|
1079
|
+
/**
|
|
1080
|
+
* Get LoroTreeNode by the TreeID.
|
|
1081
|
+
*/
|
|
1082
|
+
getNodeByID(target: TreeID): LoroTreeNode<T>;
|
|
1083
|
+
subscribe(listener: Listener): Subscription;
|
|
1084
|
+
}
|
|
1085
|
+
interface LoroTreeNode<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
1086
|
+
/**
|
|
1087
|
+
* Get the associated metadata map container of a tree node.
|
|
1088
|
+
*/
|
|
1089
|
+
readonly data: LoroMap<T>;
|
|
1090
|
+
/**
|
|
1091
|
+
* Create a new node as the child of the current node and
|
|
1092
|
+
* return an instance of `LoroTreeNode`.
|
|
1093
|
+
*
|
|
1094
|
+
* If the index is not provided, the new node will be appended to the end.
|
|
1095
|
+
*
|
|
1096
|
+
* @example
|
|
1097
|
+
* ```typescript
|
|
1098
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1099
|
+
*
|
|
1100
|
+
* let doc = new LoroDoc();
|
|
1101
|
+
* let tree = doc.getTree("tree");
|
|
1102
|
+
* let root = tree.createNode();
|
|
1103
|
+
* let node = root.createNode();
|
|
1104
|
+
* let node2 = root.createNode(0);
|
|
1105
|
+
* // root
|
|
1106
|
+
* // / \
|
|
1107
|
+
* // node2 node
|
|
1108
|
+
* ```
|
|
1109
|
+
*/
|
|
1110
|
+
createNode(index?: number): LoroTreeNode<T>;
|
|
1111
|
+
move(parent?: LoroTreeNode<T>, index?: number): void;
|
|
1112
|
+
parent(): LoroTreeNode<T> | undefined;
|
|
1113
|
+
/**
|
|
1114
|
+
* Get the children of this node.
|
|
1115
|
+
*
|
|
1116
|
+
* The objects returned are new js objects each time because they need to cross
|
|
1117
|
+
* the WASM boundary.
|
|
1118
|
+
*/
|
|
1119
|
+
children(): Array<LoroTreeNode<T>> | undefined;
|
|
1120
|
+
toJSON(): TreeNodeJSON<T>;
|
|
1121
|
+
}
|
|
1122
|
+
interface AwarenessWasm<T extends Value = Value> {
|
|
1123
|
+
getState(peer: PeerID): T | undefined;
|
|
1124
|
+
getTimestamp(peer: PeerID): number | undefined;
|
|
1125
|
+
getAllStates(): Record<PeerID, T>;
|
|
1126
|
+
setLocalState(value: T): void;
|
|
1127
|
+
removeOutdated(): PeerID[];
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* `Awareness` is a structure that tracks the ephemeral state of peers.
|
|
1134
|
+
*
|
|
1135
|
+
* It can be used to synchronize cursor positions, selections, and the names of the peers.
|
|
1136
|
+
*
|
|
1137
|
+
* The state of a specific peer is expected to be removed after a specified timeout. Use
|
|
1138
|
+
* `remove_outdated` to eliminate outdated states.
|
|
1139
|
+
*/
|
|
1140
|
+
export class AwarenessWasm {
|
|
1141
|
+
free(): void;
|
|
1142
|
+
/**
|
|
1143
|
+
* Creates a new `Awareness` instance.
|
|
1144
|
+
*
|
|
1145
|
+
* The `timeout` parameter specifies the duration in milliseconds.
|
|
1146
|
+
* A state of a peer is considered outdated, if the last update of the state of the peer
|
|
1147
|
+
* is older than the `timeout`.
|
|
1148
|
+
* @param {number | bigint | `${number}`} peer
|
|
1149
|
+
* @param {number} timeout
|
|
1150
|
+
*/
|
|
1151
|
+
constructor(peer: number | bigint | `${number}`, timeout: number);
|
|
1152
|
+
/**
|
|
1153
|
+
* Encodes the state of the given peers.
|
|
1154
|
+
* @param {Array<any>} peers
|
|
1155
|
+
* @returns {Uint8Array}
|
|
1156
|
+
*/
|
|
1157
|
+
encode(peers: Array<any>): Uint8Array;
|
|
1158
|
+
/**
|
|
1159
|
+
* Encodes the state of all peers.
|
|
1160
|
+
* @returns {Uint8Array}
|
|
1161
|
+
*/
|
|
1162
|
+
encodeAll(): Uint8Array;
|
|
1163
|
+
/**
|
|
1164
|
+
* Applies the encoded state of peers.
|
|
1165
|
+
*
|
|
1166
|
+
* Each peer's deletion countdown will be reset upon update, requiring them to pass through the `timeout`
|
|
1167
|
+
* interval again before being eligible for deletion.
|
|
1168
|
+
* @param {Uint8Array} encoded_peers_info
|
|
1169
|
+
* @returns {{ updated: PeerID[], added: PeerID[] }}
|
|
1170
|
+
*/
|
|
1171
|
+
apply(encoded_peers_info: Uint8Array): { updated: PeerID[], added: PeerID[] };
|
|
1172
|
+
/**
|
|
1173
|
+
* Get the PeerID of the local peer.
|
|
1174
|
+
* @returns {PeerID}
|
|
1175
|
+
*/
|
|
1176
|
+
peer(): PeerID;
|
|
1177
|
+
/**
|
|
1178
|
+
* Get the timestamp of the state of a given peer.
|
|
1179
|
+
* @param {number | bigint | `${number}`} peer
|
|
1180
|
+
* @returns {number | undefined}
|
|
1181
|
+
*/
|
|
1182
|
+
getTimestamp(peer: number | bigint | `${number}`): number | undefined;
|
|
1183
|
+
/**
|
|
1184
|
+
* Remove the states of outdated peers.
|
|
1185
|
+
* @returns {(PeerID)[]}
|
|
1186
|
+
*/
|
|
1187
|
+
removeOutdated(): (PeerID)[];
|
|
1188
|
+
/**
|
|
1189
|
+
* Get the number of peers.
|
|
1190
|
+
* @returns {number}
|
|
1191
|
+
*/
|
|
1192
|
+
length(): number;
|
|
1193
|
+
/**
|
|
1194
|
+
* If the state is empty.
|
|
1195
|
+
* @returns {boolean}
|
|
1196
|
+
*/
|
|
1197
|
+
isEmpty(): boolean;
|
|
1198
|
+
/**
|
|
1199
|
+
* Get all the peers
|
|
1200
|
+
* @returns {(PeerID)[]}
|
|
1201
|
+
*/
|
|
1202
|
+
peers(): (PeerID)[];
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Cursor is a stable position representation in the doc.
|
|
1206
|
+
* When expressing the position of a cursor, using "index" can be unstable
|
|
1207
|
+
* because the cursor's position may change due to other deletions and insertions,
|
|
1208
|
+
* requiring updates with each edit. To stably represent a position or range within
|
|
1209
|
+
* a list structure, we can utilize the ID of each item/character on List CRDT or
|
|
1210
|
+
* Text CRDT for expression.
|
|
1211
|
+
*
|
|
1212
|
+
* Loro optimizes State metadata by not storing the IDs of deleted elements. This
|
|
1213
|
+
* approach complicates tracking cursors since they rely on these IDs. The solution
|
|
1214
|
+
* recalculates position by replaying relevant history to update cursors
|
|
1215
|
+
* accurately. To minimize the performance impact of history replay, the system
|
|
1216
|
+
* updates cursor info to reference only the IDs of currently present elements,
|
|
1217
|
+
* thereby reducing the need for replay.
|
|
1218
|
+
*
|
|
1219
|
+
* @example
|
|
1220
|
+
* ```ts
|
|
1221
|
+
*
|
|
1222
|
+
* const doc = new LoroDoc();
|
|
1223
|
+
* const text = doc.getText("text");
|
|
1224
|
+
* text.insert(0, "123");
|
|
1225
|
+
* const pos0 = text.getCursor(0, 0);
|
|
1226
|
+
* {
|
|
1227
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
1228
|
+
* expect(ans.offset).toBe(0);
|
|
1229
|
+
* }
|
|
1230
|
+
* text.insert(0, "1");
|
|
1231
|
+
* {
|
|
1232
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
1233
|
+
* expect(ans.offset).toBe(1);
|
|
1234
|
+
* }
|
|
1235
|
+
* ```
|
|
1236
|
+
*/
|
|
1237
|
+
export class Cursor {
|
|
1238
|
+
free(): void;
|
|
1239
|
+
/**
|
|
1240
|
+
* Get the id of the given container.
|
|
1241
|
+
* @returns {ContainerID}
|
|
1242
|
+
*/
|
|
1243
|
+
containerId(): ContainerID;
|
|
1244
|
+
/**
|
|
1245
|
+
* Get the ID that represents the position.
|
|
1246
|
+
*
|
|
1247
|
+
* It can be undefined if it's not bind into a specific ID.
|
|
1248
|
+
* @returns {{ peer: PeerID, counter: number } | undefined}
|
|
1249
|
+
*/
|
|
1250
|
+
pos(): { peer: PeerID, counter: number } | undefined;
|
|
1251
|
+
/**
|
|
1252
|
+
* Get which side of the character/list item the cursor is on.
|
|
1253
|
+
* @returns {Side}
|
|
1254
|
+
*/
|
|
1255
|
+
side(): Side;
|
|
1256
|
+
/**
|
|
1257
|
+
* Encode the cursor into a Uint8Array.
|
|
1258
|
+
* @returns {Uint8Array}
|
|
1259
|
+
*/
|
|
1260
|
+
encode(): Uint8Array;
|
|
1261
|
+
/**
|
|
1262
|
+
* Decode the cursor from a Uint8Array.
|
|
1263
|
+
* @param {Uint8Array} data
|
|
1264
|
+
* @returns {Cursor}
|
|
1265
|
+
*/
|
|
1266
|
+
static decode(data: Uint8Array): Cursor;
|
|
1267
|
+
/**
|
|
1268
|
+
* "Cursor"
|
|
1269
|
+
* @returns {any}
|
|
1270
|
+
*/
|
|
1271
|
+
kind(): any;
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* The handler of a tree(forest) container.
|
|
1275
|
+
*/
|
|
1276
|
+
export class LoroCounter {
|
|
1277
|
+
free(): void;
|
|
1278
|
+
/**
|
|
1279
|
+
* Create a new LoroCounter.
|
|
1280
|
+
*/
|
|
1281
|
+
constructor();
|
|
1282
|
+
/**
|
|
1283
|
+
* Increment the counter by the given value.
|
|
1284
|
+
* @param {number} value
|
|
1285
|
+
*/
|
|
1286
|
+
increment(value: number): void;
|
|
1287
|
+
/**
|
|
1288
|
+
* Decrement the counter by the given value.
|
|
1289
|
+
* @param {number} value
|
|
1290
|
+
*/
|
|
1291
|
+
decrement(value: number): void;
|
|
1292
|
+
/**
|
|
1293
|
+
* Subscribe to the changes of the counter.
|
|
1294
|
+
* @param {Function} f
|
|
1295
|
+
* @returns {any}
|
|
1296
|
+
*/
|
|
1297
|
+
subscribe(f: Function): any;
|
|
1298
|
+
/**
|
|
1299
|
+
* Get the parent container of the counter container.
|
|
1300
|
+
*
|
|
1301
|
+
* - The parent container of the root counter is `undefined`.
|
|
1302
|
+
* - The object returned is a new js object each time because it need to cross
|
|
1303
|
+
* the WASM boundary.
|
|
1304
|
+
* @returns {Container | undefined}
|
|
1305
|
+
*/
|
|
1306
|
+
parent(): Container | undefined;
|
|
1307
|
+
/**
|
|
1308
|
+
* Whether the container is attached to a docuemnt.
|
|
1309
|
+
*
|
|
1310
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
1311
|
+
* @returns {boolean}
|
|
1312
|
+
*/
|
|
1313
|
+
isAttached(): boolean;
|
|
1314
|
+
/**
|
|
1315
|
+
* Get the attached container associated with this.
|
|
1316
|
+
*
|
|
1317
|
+
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
1318
|
+
* @returns {LoroTree | undefined}
|
|
1319
|
+
*/
|
|
1320
|
+
getAttached(): LoroTree | undefined;
|
|
1321
|
+
/**
|
|
1322
|
+
* Get the value of the counter.
|
|
1323
|
+
*/
|
|
1324
|
+
readonly value: number;
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* The CRDTs document. Loro supports different CRDTs include [**List**](LoroList),
|
|
1328
|
+
* [**RichText**](LoroText), [**Map**](LoroMap) and [**Movable Tree**](LoroTree),
|
|
1329
|
+
* you could build all kind of applications by these.
|
|
1330
|
+
*
|
|
1331
|
+
* @example
|
|
1332
|
+
* ```ts
|
|
1333
|
+
* import { LoroDoc } from "loro-crdt"
|
|
1334
|
+
*
|
|
1335
|
+
* const loro = new LoroDoc();
|
|
1336
|
+
* const text = loro.getText("text");
|
|
1337
|
+
* const list = loro.getList("list");
|
|
1338
|
+
* const map = loro.getMap("Map");
|
|
1339
|
+
* const tree = loro.getTree("tree");
|
|
1340
|
+
* ```
|
|
1341
|
+
*/
|
|
1342
|
+
export class LoroDoc {
|
|
1343
|
+
free(): void;
|
|
1344
|
+
/**
|
|
1345
|
+
* Create a new loro document.
|
|
1346
|
+
*
|
|
1347
|
+
* New document will have a random peer id.
|
|
1348
|
+
*/
|
|
1349
|
+
constructor();
|
|
1350
|
+
/**
|
|
1351
|
+
* Enables editing in detached mode, which is disabled by default.
|
|
1352
|
+
*
|
|
1353
|
+
* The doc enter detached mode after calling `detach` or checking out a non-latest version.
|
|
1354
|
+
*
|
|
1355
|
+
* # Important Notes:
|
|
1356
|
+
*
|
|
1357
|
+
* - This mode uses a different PeerID for each checkout.
|
|
1358
|
+
* - Ensure no concurrent operations share the same PeerID if set manually.
|
|
1359
|
+
* - Importing does not affect the document's state or version; changes are
|
|
1360
|
+
* recorded in the [OpLog] only. Call `checkout` to apply changes.
|
|
1361
|
+
* @param {boolean} enable
|
|
1362
|
+
*/
|
|
1363
|
+
setDetachedEditing(enable: boolean): void;
|
|
1364
|
+
/**
|
|
1365
|
+
* Whether the editing is enabled in detached mode.
|
|
1366
|
+
*
|
|
1367
|
+
* The doc enter detached mode after calling `detach` or checking out a non-latest version.
|
|
1368
|
+
*
|
|
1369
|
+
* # Important Notes:
|
|
1370
|
+
*
|
|
1371
|
+
* - This mode uses a different PeerID for each checkout.
|
|
1372
|
+
* - Ensure no concurrent operations share the same PeerID if set manually.
|
|
1373
|
+
* - Importing does not affect the document's state or version; changes are
|
|
1374
|
+
* recorded in the [OpLog] only. Call `checkout` to apply changes.
|
|
1375
|
+
* @returns {boolean}
|
|
1376
|
+
*/
|
|
1377
|
+
isDetachedEditingEnabled(): boolean;
|
|
1378
|
+
/**
|
|
1379
|
+
* Set whether to record the timestamp of each change. Default is `false`.
|
|
1380
|
+
*
|
|
1381
|
+
* If enabled, the Unix timestamp (in seconds) will be recorded for each change automatically.
|
|
1382
|
+
*
|
|
1383
|
+
* You can also set each timestamp manually when you commit a change.
|
|
1384
|
+
* The timestamp manually set will override the automatic one.
|
|
1385
|
+
*
|
|
1386
|
+
* NOTE: Timestamps are forced to be in ascending order in the OpLog's history.
|
|
1387
|
+
* If you commit a new change with a timestamp that is less than the existing one,
|
|
1388
|
+
* the largest existing timestamp will be used instead.
|
|
1389
|
+
* @param {boolean} auto_record
|
|
1390
|
+
*/
|
|
1391
|
+
setRecordTimestamp(auto_record: boolean): void;
|
|
1392
|
+
/**
|
|
1393
|
+
* If two continuous local changes are within the interval, they will be merged into one change.
|
|
1394
|
+
*
|
|
1395
|
+
* The default value is 1_000_000, the default unit is seconds.
|
|
1396
|
+
* @param {number} interval
|
|
1397
|
+
*/
|
|
1398
|
+
setChangeMergeInterval(interval: number): void;
|
|
1399
|
+
/**
|
|
1400
|
+
* Set the rich text format configuration of the document.
|
|
1401
|
+
*
|
|
1402
|
+
* You need to config it if you use rich text `mark` method.
|
|
1403
|
+
* Specifically, you need to config the `expand` property of each style.
|
|
1404
|
+
*
|
|
1405
|
+
* Expand is used to specify the behavior of expanding when new text is inserted at the
|
|
1406
|
+
* beginning or end of the style.
|
|
1407
|
+
*
|
|
1408
|
+
* You can specify the `expand` option to set the behavior when inserting text at the boundary of the range.
|
|
1409
|
+
*
|
|
1410
|
+
* - `after`(default): when inserting text right after the given range, the mark will be expanded to include the inserted text
|
|
1411
|
+
* - `before`: when inserting text right before the given range, the mark will be expanded to include the inserted text
|
|
1412
|
+
* - `none`: the mark will not be expanded to include the inserted text at the boundaries
|
|
1413
|
+
* - `both`: when inserting text either right before or right after the given range, the mark will be expanded to include the inserted text
|
|
1414
|
+
*
|
|
1415
|
+
* @example
|
|
1416
|
+
* ```ts
|
|
1417
|
+
* const doc = new LoroDoc();
|
|
1418
|
+
* doc.configTextStyle({
|
|
1419
|
+
* bold: { expand: "after" },
|
|
1420
|
+
* link: { expand: "before" }
|
|
1421
|
+
* });
|
|
1422
|
+
* const text = doc.getText("text");
|
|
1423
|
+
* text.insert(0, "Hello World!");
|
|
1424
|
+
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
1425
|
+
* expect(text.toDelta()).toStrictEqual([
|
|
1426
|
+
* {
|
|
1427
|
+
* insert: "Hello",
|
|
1428
|
+
* attributes: {
|
|
1429
|
+
* bold: true,
|
|
1430
|
+
* },
|
|
1431
|
+
* },
|
|
1432
|
+
* {
|
|
1433
|
+
* insert: " World!",
|
|
1434
|
+
* },
|
|
1435
|
+
* ] as Delta<string>[]);
|
|
1436
|
+
* ```
|
|
1437
|
+
* @param {{[key: string]: { expand: 'before'|'after'|'none'|'both' }}} styles
|
|
1438
|
+
*/
|
|
1439
|
+
configTextStyle(styles: {[key: string]: { expand: 'before'|'after'|'none'|'both' }}): void;
|
|
1440
|
+
/**
|
|
1441
|
+
* Create a loro document from the snapshot.
|
|
1442
|
+
*
|
|
1443
|
+
* @see You can learn more [here](https://loro.dev/docs/tutorial/encoding).
|
|
1444
|
+
*
|
|
1445
|
+
* @example
|
|
1446
|
+
* ```ts
|
|
1447
|
+
* import { LoroDoc } from "loro-crdt"
|
|
1448
|
+
*
|
|
1449
|
+
* const doc = new LoroDoc();
|
|
1450
|
+
* // ...
|
|
1451
|
+
* const bytes = doc.export({ mode: "snapshot" });
|
|
1452
|
+
* const loro = LoroDoc.fromSnapshot(bytes);
|
|
1453
|
+
* ```
|
|
1454
|
+
* @param {Uint8Array} snapshot
|
|
1455
|
+
* @returns {LoroDoc}
|
|
1456
|
+
*/
|
|
1457
|
+
static fromSnapshot(snapshot: Uint8Array): LoroDoc;
|
|
1458
|
+
/**
|
|
1459
|
+
* Attach the document state to the latest known version.
|
|
1460
|
+
*
|
|
1461
|
+
* > The document becomes detached during a `checkout` operation.
|
|
1462
|
+
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
1463
|
+
* > In a detached state, the document is not editable, and any `import` operations will be
|
|
1464
|
+
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
1465
|
+
*
|
|
1466
|
+
* This method has the same effect as invoking `checkoutToLatest`.
|
|
1467
|
+
*
|
|
1468
|
+
* @example
|
|
1469
|
+
* ```ts
|
|
1470
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1471
|
+
*
|
|
1472
|
+
* const doc = new LoroDoc();
|
|
1473
|
+
* const text = doc.getText("text");
|
|
1474
|
+
* const frontiers = doc.frontiers();
|
|
1475
|
+
* text.insert(0, "Hello World!");
|
|
1476
|
+
* doc.checkout(frontiers);
|
|
1477
|
+
* // you need call `attach()` or `checkoutToLatest()` before changing the doc.
|
|
1478
|
+
* doc.attach();
|
|
1479
|
+
* text.insert(0, "Hi");
|
|
1480
|
+
* ```
|
|
1481
|
+
*/
|
|
1482
|
+
attach(): void;
|
|
1483
|
+
/**
|
|
1484
|
+
* `detached` indicates that the `DocState` is not synchronized with the latest version of `OpLog`.
|
|
1485
|
+
*
|
|
1486
|
+
* > The document becomes detached during a `checkout` operation.
|
|
1487
|
+
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
1488
|
+
* > In a detached state, the document is not editable by default, and any `import` operations will be
|
|
1489
|
+
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
1490
|
+
*
|
|
1491
|
+
* @example
|
|
1492
|
+
* ```ts
|
|
1493
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1494
|
+
*
|
|
1495
|
+
* const doc = new LoroDoc();
|
|
1496
|
+
* const text = doc.getText("text");
|
|
1497
|
+
* const frontiers = doc.frontiers();
|
|
1498
|
+
* text.insert(0, "Hello World!");
|
|
1499
|
+
* console.log(doc.isDetached()); // false
|
|
1500
|
+
* doc.checkout(frontiers);
|
|
1501
|
+
* console.log(doc.isDetached()); // true
|
|
1502
|
+
* doc.attach();
|
|
1503
|
+
* console.log(doc.isDetached()); // false
|
|
1504
|
+
* ```
|
|
1505
|
+
* @returns {boolean}
|
|
1506
|
+
*/
|
|
1507
|
+
isDetached(): boolean;
|
|
1508
|
+
/**
|
|
1509
|
+
* Detach the document state from the latest known version.
|
|
1510
|
+
*
|
|
1511
|
+
* After detaching, all import operations will be recorded in the `OpLog` without being applied to the `DocState`.
|
|
1512
|
+
* When `detached`, the document is not editable.
|
|
1513
|
+
*
|
|
1514
|
+
* @example
|
|
1515
|
+
* ```ts
|
|
1516
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1517
|
+
*
|
|
1518
|
+
* const doc = new LoroDoc();
|
|
1519
|
+
* doc.detach();
|
|
1520
|
+
* console.log(doc.isDetached()); // true
|
|
1521
|
+
* ```
|
|
1522
|
+
*/
|
|
1523
|
+
detach(): void;
|
|
1524
|
+
/**
|
|
1525
|
+
* Duplicate the document with a different PeerID
|
|
1526
|
+
*
|
|
1527
|
+
* The time complexity and space complexity of this operation are both O(n),
|
|
1528
|
+
*
|
|
1529
|
+
* When called in detached mode, it will fork at the current state frontiers.
|
|
1530
|
+
* It will have the same effect as `forkAt(&self.frontiers())`.
|
|
1531
|
+
* @returns {LoroDoc}
|
|
1532
|
+
*/
|
|
1533
|
+
fork(): LoroDoc;
|
|
1534
|
+
/**
|
|
1535
|
+
* Creates a new LoroDoc at a specified version (Frontiers)
|
|
1536
|
+
*
|
|
1537
|
+
* The created doc will only contain the history before the specified frontiers.
|
|
1538
|
+
* @param {({ peer: PeerID, counter: number })[]} frontiers
|
|
1539
|
+
* @returns {LoroDoc}
|
|
1540
|
+
*/
|
|
1541
|
+
forkAt(frontiers: ({ peer: PeerID, counter: number })[]): LoroDoc;
|
|
1542
|
+
/**
|
|
1543
|
+
* Checkout the `DocState` to the latest version of `OpLog`.
|
|
1544
|
+
*
|
|
1545
|
+
* > The document becomes detached during a `checkout` operation.
|
|
1546
|
+
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
1547
|
+
* > In a detached state, the document is not editable by default, and any `import` operations will be
|
|
1548
|
+
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
1549
|
+
*
|
|
1550
|
+
* This has the same effect as `attach`.
|
|
1551
|
+
*
|
|
1552
|
+
* @example
|
|
1553
|
+
* ```ts
|
|
1554
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1555
|
+
*
|
|
1556
|
+
* const doc = new LoroDoc();
|
|
1557
|
+
* const text = doc.getText("text");
|
|
1558
|
+
* const frontiers = doc.frontiers();
|
|
1559
|
+
* text.insert(0, "Hello World!");
|
|
1560
|
+
* doc.checkout(frontiers);
|
|
1561
|
+
* // you need call `checkoutToLatest()` or `attach()` before changing the doc.
|
|
1562
|
+
* doc.checkoutToLatest();
|
|
1563
|
+
* text.insert(0, "Hi");
|
|
1564
|
+
* ```
|
|
1565
|
+
*/
|
|
1566
|
+
checkoutToLatest(): void;
|
|
1567
|
+
/**
|
|
1568
|
+
* Visit all the ancestors of the changes in causal order.
|
|
1569
|
+
*
|
|
1570
|
+
* @param ids - the changes to visit
|
|
1571
|
+
* @param f - the callback function, return `true` to continue visiting, return `false` to stop
|
|
1572
|
+
* @param {({ peer: PeerID, counter: number })[]} ids
|
|
1573
|
+
* @param {(change: ChangeMeta) => boolean} f
|
|
1574
|
+
*/
|
|
1575
|
+
travelChangeAncestors(ids: ({ peer: PeerID, counter: number })[], f: (change: ChangeMeta) => boolean): void;
|
|
1576
|
+
/**
|
|
1577
|
+
* Checkout the `DocState` to a specific version.
|
|
1578
|
+
*
|
|
1579
|
+
* > The document becomes detached during a `checkout` operation.
|
|
1580
|
+
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
1581
|
+
* > In a detached state, the document is not editable, and any `import` operations will be
|
|
1582
|
+
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
1583
|
+
*
|
|
1584
|
+
* You should call `attach` to attach the `DocState` to the latest version of `OpLog`.
|
|
1585
|
+
*
|
|
1586
|
+
* @param frontiers - the specific frontiers
|
|
1587
|
+
*
|
|
1588
|
+
* @example
|
|
1589
|
+
* ```ts
|
|
1590
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1591
|
+
*
|
|
1592
|
+
* const doc = new LoroDoc();
|
|
1593
|
+
* const text = doc.getText("text");
|
|
1594
|
+
* const frontiers = doc.frontiers();
|
|
1595
|
+
* text.insert(0, "Hello World!");
|
|
1596
|
+
* doc.checkout(frontiers);
|
|
1597
|
+
* console.log(doc.toJSON()); // {"text": ""}
|
|
1598
|
+
* ```
|
|
1599
|
+
* @param {({ peer: PeerID, counter: number })[]} frontiers
|
|
1600
|
+
*/
|
|
1601
|
+
checkout(frontiers: ({ peer: PeerID, counter: number })[]): void;
|
|
1602
|
+
/**
|
|
1603
|
+
* Set the peer ID of the current writer.
|
|
1604
|
+
*
|
|
1605
|
+
* It must be a number, a BigInt, or a decimal string that can be parsed to a unsigned 64-bit integer.
|
|
1606
|
+
*
|
|
1607
|
+
* Note: use it with caution. You need to make sure there is not chance that two peers
|
|
1608
|
+
* have the same peer ID. Otherwise, we cannot ensure the consistency of the document.
|
|
1609
|
+
* @param {number | bigint | `${number}`} peer_id
|
|
1610
|
+
*/
|
|
1611
|
+
setPeerId(peer_id: number | bigint | `${number}`): void;
|
|
1612
|
+
/**
|
|
1613
|
+
* Commit the cumulative auto committed transaction.
|
|
1614
|
+
*
|
|
1615
|
+
* You can specify the `origin`, `timestamp`, and `message` of the commit.
|
|
1616
|
+
*
|
|
1617
|
+
* - The `origin` is used to mark the event
|
|
1618
|
+
* - The `message` works like a git commit message, which will be recorded and synced to peers
|
|
1619
|
+
*
|
|
1620
|
+
* The events will be emitted after a transaction is committed. A transaction is committed when:
|
|
1621
|
+
*
|
|
1622
|
+
* - `doc.commit()` is called.
|
|
1623
|
+
* - `doc.export(mode)` is called.
|
|
1624
|
+
* - `doc.import(data)` is called.
|
|
1625
|
+
* - `doc.checkout(version)` is called.
|
|
1626
|
+
*
|
|
1627
|
+
* NOTE: Timestamps are forced to be in ascending order.
|
|
1628
|
+
* If you commit a new change with a timestamp that is less than the existing one,
|
|
1629
|
+
* the largest existing timestamp will be used instead.
|
|
1630
|
+
*
|
|
1631
|
+
* NOTE: The `origin` will not be persisted, but the `message` will.
|
|
1632
|
+
* @param {{ origin?: string, timestamp?: number, message?: string } | undefined} [options]
|
|
1633
|
+
*/
|
|
1634
|
+
commit(options?: { origin?: string, timestamp?: number, message?: string }): void;
|
|
1635
|
+
/**
|
|
1636
|
+
* Get the number of operations in the pending transaction.
|
|
1637
|
+
*
|
|
1638
|
+
* The pending transaction is the one that is not committed yet. It will be committed
|
|
1639
|
+
* automatically after calling `doc.commit()`, `doc.export(mode)` or `doc.checkout(version)`.
|
|
1640
|
+
* @returns {number}
|
|
1641
|
+
*/
|
|
1642
|
+
getPendingTxnLength(): number;
|
|
1643
|
+
/**
|
|
1644
|
+
* Get a LoroText by container id.
|
|
1645
|
+
*
|
|
1646
|
+
* The object returned is a new js object each time because it need to cross
|
|
1647
|
+
* the WASM boundary.
|
|
1648
|
+
*
|
|
1649
|
+
* @example
|
|
1650
|
+
* ```ts
|
|
1651
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1652
|
+
*
|
|
1653
|
+
* const doc = new LoroDoc();
|
|
1654
|
+
* const text = doc.getText("text");
|
|
1655
|
+
* ```
|
|
1656
|
+
* @param {ContainerID | string} cid
|
|
1657
|
+
* @returns {LoroText}
|
|
1658
|
+
*/
|
|
1659
|
+
getText(cid: ContainerID | string): LoroText;
|
|
1660
|
+
/**
|
|
1661
|
+
* Get a LoroCounter by container id
|
|
1662
|
+
* @param {ContainerID | string} cid
|
|
1663
|
+
* @returns {LoroCounter}
|
|
1664
|
+
*/
|
|
1665
|
+
getCounter(cid: ContainerID | string): LoroCounter;
|
|
1666
|
+
/**
|
|
1667
|
+
* Set the commit message of the next commit
|
|
1668
|
+
* @param {string} msg
|
|
1669
|
+
*/
|
|
1670
|
+
setNextCommitMessage(msg: string): void;
|
|
1671
|
+
/**
|
|
1672
|
+
* Get deep value of the document with container id
|
|
1673
|
+
* @returns {any}
|
|
1674
|
+
*/
|
|
1675
|
+
getDeepValueWithID(): any;
|
|
1676
|
+
/**
|
|
1677
|
+
* Get the path from the root to the container
|
|
1678
|
+
* @param {ContainerID} id
|
|
1679
|
+
* @returns {(string|number)[] | undefined}
|
|
1680
|
+
*/
|
|
1681
|
+
getPathToContainer(id: ContainerID): (string|number)[] | undefined;
|
|
1682
|
+
/**
|
|
1683
|
+
* Evaluate JSONPath against a LoroDoc
|
|
1684
|
+
* @param {string} jsonpath
|
|
1685
|
+
* @returns {Array<any>}
|
|
1686
|
+
*/
|
|
1687
|
+
JSONPath(jsonpath: string): Array<any>;
|
|
1688
|
+
/**
|
|
1689
|
+
* Get the version vector of the current document state.
|
|
1690
|
+
*
|
|
1691
|
+
* If you checkout to a specific version, the version vector will change.
|
|
1692
|
+
* @returns {VersionVector}
|
|
1693
|
+
*/
|
|
1694
|
+
version(): VersionVector;
|
|
1695
|
+
/**
|
|
1696
|
+
* The doc only contains the history since this version
|
|
1697
|
+
*
|
|
1698
|
+
* This is empty if the doc is not shallow.
|
|
1699
|
+
*
|
|
1700
|
+
* The ops included by the shallow history start version vector are not in the doc.
|
|
1701
|
+
* @returns {VersionVector}
|
|
1702
|
+
*/
|
|
1703
|
+
shallowSinceVV(): VersionVector;
|
|
1704
|
+
/**
|
|
1705
|
+
* Check if the doc contains the full history.
|
|
1706
|
+
* @returns {boolean}
|
|
1707
|
+
*/
|
|
1708
|
+
isShallow(): boolean;
|
|
1709
|
+
/**
|
|
1710
|
+
* The doc only contains the history since this version
|
|
1711
|
+
*
|
|
1712
|
+
* This is empty if the doc is not shallow.
|
|
1713
|
+
*
|
|
1714
|
+
* The ops included by the shallow history start frontiers are not in the doc.
|
|
1715
|
+
* @returns {{ peer: PeerID, counter: number }[]}
|
|
1716
|
+
*/
|
|
1717
|
+
shallowSinceFrontiers(): { peer: PeerID, counter: number }[];
|
|
1718
|
+
/**
|
|
1719
|
+
* Get the version vector of the latest known version in OpLog.
|
|
1720
|
+
*
|
|
1721
|
+
* If you checkout to a specific version, this version vector will not change.
|
|
1722
|
+
* @returns {VersionVector}
|
|
1723
|
+
*/
|
|
1724
|
+
oplogVersion(): VersionVector;
|
|
1725
|
+
/**
|
|
1726
|
+
* Get the [frontiers](https://loro.dev/docs/advanced/version_deep_dive) of the current document state.
|
|
1727
|
+
*
|
|
1728
|
+
* If you checkout to a specific version, this value will change.
|
|
1729
|
+
* @returns {{ peer: PeerID, counter: number }[]}
|
|
1730
|
+
*/
|
|
1731
|
+
frontiers(): { peer: PeerID, counter: number }[];
|
|
1732
|
+
/**
|
|
1733
|
+
* Get the [frontiers](https://loro.dev/docs/advanced/version_deep_dive) of the latest version in OpLog.
|
|
1734
|
+
*
|
|
1735
|
+
* If you checkout to a specific version, this value will not change.
|
|
1736
|
+
* @returns {{ peer: PeerID, counter: number }[]}
|
|
1737
|
+
*/
|
|
1738
|
+
oplogFrontiers(): { peer: PeerID, counter: number }[];
|
|
1739
|
+
/**
|
|
1740
|
+
* Compare the version of the OpLog with the specified frontiers.
|
|
1741
|
+
*
|
|
1742
|
+
* This method is useful to compare the version by only a small amount of data.
|
|
1743
|
+
*
|
|
1744
|
+
* This method returns an integer indicating the relationship between the version of the OpLog (referred to as 'self')
|
|
1745
|
+
* and the provided 'frontiers' parameter:
|
|
1746
|
+
*
|
|
1747
|
+
* - -1: The version of 'self' is either less than 'frontiers' or is non-comparable (parallel) to 'frontiers',
|
|
1748
|
+
* indicating that it is not definitively less than 'frontiers'.
|
|
1749
|
+
* - 0: The version of 'self' is equal to 'frontiers'.
|
|
1750
|
+
* - 1: The version of 'self' is greater than 'frontiers'.
|
|
1751
|
+
*
|
|
1752
|
+
* # Internal
|
|
1753
|
+
*
|
|
1754
|
+
* Frontiers cannot be compared without the history of the OpLog.
|
|
1755
|
+
* @param {({ peer: PeerID, counter: number })[]} frontiers
|
|
1756
|
+
* @returns {number}
|
|
1757
|
+
*/
|
|
1758
|
+
cmpWithFrontiers(frontiers: ({ peer: PeerID, counter: number })[]): number;
|
|
1759
|
+
/**
|
|
1760
|
+
* Compare the ordering of two Frontiers.
|
|
1761
|
+
*
|
|
1762
|
+
* It's assumed that both Frontiers are included by the doc. Otherwise, an error will be thrown.
|
|
1763
|
+
*
|
|
1764
|
+
* Return value:
|
|
1765
|
+
*
|
|
1766
|
+
* - -1: a < b
|
|
1767
|
+
* - 0: a == b
|
|
1768
|
+
* - 1: a > b
|
|
1769
|
+
* - undefined: a ∥ b: a and b are concurrent
|
|
1770
|
+
* @param {({ peer: PeerID, counter: number })[]} a
|
|
1771
|
+
* @param {({ peer: PeerID, counter: number })[]} b
|
|
1772
|
+
* @returns {-1 | 1 | 0 | undefined}
|
|
1773
|
+
*/
|
|
1774
|
+
cmpFrontiers(a: ({ peer: PeerID, counter: number })[], b: ({ peer: PeerID, counter: number })[]): -1 | 1 | 0 | undefined;
|
|
1775
|
+
/**
|
|
1776
|
+
* Export the snapshot of current version.
|
|
1777
|
+
* It includes all the history and the document state
|
|
1778
|
+
*
|
|
1779
|
+
* @deprecated Use `export({mode: "snapshot"})` instead
|
|
1780
|
+
* @returns {Uint8Array}
|
|
1781
|
+
*/
|
|
1782
|
+
exportSnapshot(): Uint8Array;
|
|
1783
|
+
/**
|
|
1784
|
+
* Export the document based on the specified ExportMode.
|
|
1785
|
+
*
|
|
1786
|
+
* @param mode - The export mode to use. Can be one of:
|
|
1787
|
+
* - `{ mode: "snapshot" }`: Export a full snapshot of the document.
|
|
1788
|
+
* - `{ mode: "update", from?: VersionVector }`: Export updates from the given version vector.
|
|
1789
|
+
* - `{ mode: "updates-in-range", spans: { id: ID, len: number }[] }`: Export updates within the specified ID spans.
|
|
1790
|
+
* - `{ mode: "shallow-snapshot", frontiers: Frontiers }`: Export a garbage-collected snapshot up to the given frontiers.
|
|
1791
|
+
*
|
|
1792
|
+
* @returns A byte array containing the exported data.
|
|
1793
|
+
*
|
|
1794
|
+
* @example
|
|
1795
|
+
* ```ts
|
|
1796
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
1797
|
+
*
|
|
1798
|
+
* const doc = new LoroDoc();
|
|
1799
|
+
* doc.setPeerId("1");
|
|
1800
|
+
* doc.getText("text").update("Hello World");
|
|
1801
|
+
*
|
|
1802
|
+
* // Export a full snapshot
|
|
1803
|
+
* const snapshotBytes = doc.export({ mode: "snapshot" });
|
|
1804
|
+
*
|
|
1805
|
+
* // Export updates from a specific version
|
|
1806
|
+
* const vv = doc.oplogVersion();
|
|
1807
|
+
* doc.getText("text").update("Hello Loro");
|
|
1808
|
+
* const updateBytes = doc.export({ mode: "update", from: vv });
|
|
1809
|
+
*
|
|
1810
|
+
* // Export a shallow snapshot that only includes the history since the frontiers
|
|
1811
|
+
* const shallowBytes = doc.export({ mode: "shallow-snapshot", frontiers: doc.oplogFrontiers() });
|
|
1812
|
+
*
|
|
1813
|
+
* // Export updates within specific ID spans
|
|
1814
|
+
* const spanBytes = doc.export({
|
|
1815
|
+
* mode: "updates-in-range",
|
|
1816
|
+
* spans: [{ id: { peer: "1", counter: 0 }, len: 10 }]
|
|
1817
|
+
* });
|
|
1818
|
+
* ```
|
|
1819
|
+
* @param {ExportMode} mode
|
|
1820
|
+
* @returns {Uint8Array}
|
|
1821
|
+
*/
|
|
1822
|
+
export(mode: ExportMode): Uint8Array;
|
|
1823
|
+
/**
|
|
1824
|
+
* Export updates in the given range in JSON format.
|
|
1825
|
+
* @param {VersionVector | undefined} [start_vv]
|
|
1826
|
+
* @param {VersionVector | undefined} [end_vv]
|
|
1827
|
+
* @returns {JsonSchema}
|
|
1828
|
+
*/
|
|
1829
|
+
exportJsonUpdates(start_vv?: VersionVector, end_vv?: VersionVector): JsonSchema;
|
|
1830
|
+
/**
|
|
1831
|
+
* Import updates from the JSON format.
|
|
1832
|
+
*
|
|
1833
|
+
* only supports backward compatibility but not forward compatibility.
|
|
1834
|
+
* @param {string | JsonSchema} json
|
|
1835
|
+
* @returns {ImportStatus}
|
|
1836
|
+
*/
|
|
1837
|
+
importJsonUpdates(json: string | JsonSchema): ImportStatus;
|
|
1838
|
+
/**
|
|
1839
|
+
* Import snapshot or updates into current doc.
|
|
1840
|
+
*
|
|
1841
|
+
* Note:
|
|
1842
|
+
* - Updates within the current version will be ignored
|
|
1843
|
+
* - Updates with missing dependencies will be pending until the dependencies are received
|
|
1844
|
+
*
|
|
1845
|
+
* @example
|
|
1846
|
+
* ```ts
|
|
1847
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1848
|
+
*
|
|
1849
|
+
* const doc = new LoroDoc();
|
|
1850
|
+
* const text = doc.getText("text");
|
|
1851
|
+
* text.insert(0, "Hello");
|
|
1852
|
+
* // get all updates of the doc
|
|
1853
|
+
* const updates = doc.export({ mode: "update" });
|
|
1854
|
+
* const snapshot = doc.export({ mode: "snapshot" });
|
|
1855
|
+
* const doc2 = new LoroDoc();
|
|
1856
|
+
* // import snapshot
|
|
1857
|
+
* doc2.import(snapshot);
|
|
1858
|
+
* // or import updates
|
|
1859
|
+
* doc2.import(updates);
|
|
1860
|
+
* ```
|
|
1861
|
+
* @param {Uint8Array} update_or_snapshot
|
|
1862
|
+
* @returns {ImportStatus}
|
|
1863
|
+
*/
|
|
1864
|
+
import(update_or_snapshot: Uint8Array): ImportStatus;
|
|
1865
|
+
/**
|
|
1866
|
+
* Import a batch of updates.
|
|
1867
|
+
*
|
|
1868
|
+
* It's more efficient than importing updates one by one.
|
|
1869
|
+
*
|
|
1870
|
+
* @example
|
|
1871
|
+
* ```ts
|
|
1872
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1873
|
+
*
|
|
1874
|
+
* const doc = new LoroDoc();
|
|
1875
|
+
* const text = doc.getText("text");
|
|
1876
|
+
* text.insert(0, "Hello");
|
|
1877
|
+
* const updates = doc.export({ mode: "update" });
|
|
1878
|
+
* const snapshot = doc.export({ mode: "snapshot" });
|
|
1879
|
+
* const doc2 = new LoroDoc();
|
|
1880
|
+
* doc2.importUpdateBatch([snapshot, updates]);
|
|
1881
|
+
* ```
|
|
1882
|
+
* @param {Array<any>} data
|
|
1883
|
+
*/
|
|
1884
|
+
importUpdateBatch(data: Array<any>): void;
|
|
1885
|
+
/**
|
|
1886
|
+
* Get the shallow json format of the document state.
|
|
1887
|
+
*
|
|
1888
|
+
* @example
|
|
1889
|
+
* ```ts
|
|
1890
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1891
|
+
*
|
|
1892
|
+
* const doc = new LoroDoc();
|
|
1893
|
+
* const list = doc.getList("list");
|
|
1894
|
+
* const tree = doc.getTree("tree");
|
|
1895
|
+
* const map = doc.getMap("map");
|
|
1896
|
+
* const shallowValue = doc.getShallowValue();
|
|
1897
|
+
* /*
|
|
1898
|
+
* {"list": ..., "tree": ..., "map": ...}
|
|
1899
|
+
* *\/
|
|
1900
|
+
* console.log(shallowValue);
|
|
1901
|
+
* ```
|
|
1902
|
+
* @returns {any}
|
|
1903
|
+
*/
|
|
1904
|
+
getShallowValue(): any;
|
|
1905
|
+
/**
|
|
1906
|
+
* Get the json format of the entire document state.
|
|
1907
|
+
*
|
|
1908
|
+
* @example
|
|
1909
|
+
* ```ts
|
|
1910
|
+
* import { LoroDoc, LoroText, LoroMap } from "loro-crdt";
|
|
1911
|
+
*
|
|
1912
|
+
* const doc = new LoroDoc();
|
|
1913
|
+
* const list = doc.getList("list");
|
|
1914
|
+
* list.insert(0, "Hello");
|
|
1915
|
+
* const text = list.insertContainer(0, new LoroText());
|
|
1916
|
+
* text.insert(0, "Hello");
|
|
1917
|
+
* const map = list.insertContainer(1, new LoroMap());
|
|
1918
|
+
* map.set("foo", "bar");
|
|
1919
|
+
* /*
|
|
1920
|
+
* {"list": ["Hello", {"foo": "bar"}]}
|
|
1921
|
+
* *\/
|
|
1922
|
+
* console.log(doc.toJSON());
|
|
1923
|
+
* ```
|
|
1924
|
+
* @returns {any}
|
|
1925
|
+
*/
|
|
1926
|
+
toJSON(): any;
|
|
1927
|
+
/**
|
|
1928
|
+
* Debug the size of the history
|
|
1929
|
+
*/
|
|
1930
|
+
debugHistory(): void;
|
|
1931
|
+
/**
|
|
1932
|
+
* Get the number of changes in the oplog.
|
|
1933
|
+
* @returns {number}
|
|
1934
|
+
*/
|
|
1935
|
+
changeCount(): number;
|
|
1936
|
+
/**
|
|
1937
|
+
* Get the number of ops in the oplog.
|
|
1938
|
+
* @returns {number}
|
|
1939
|
+
*/
|
|
1940
|
+
opCount(): number;
|
|
1941
|
+
/**
|
|
1942
|
+
* Get all of changes in the oplog.
|
|
1943
|
+
*
|
|
1944
|
+
* Note: this method is expensive when the oplog is large. O(n)
|
|
1945
|
+
*
|
|
1946
|
+
* @example
|
|
1947
|
+
* ```ts
|
|
1948
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
1949
|
+
*
|
|
1950
|
+
* const doc = new LoroDoc();
|
|
1951
|
+
* const text = doc.getText("text");
|
|
1952
|
+
* text.insert(0, "Hello");
|
|
1953
|
+
* const changes = doc.getAllChanges();
|
|
1954
|
+
*
|
|
1955
|
+
* for (let [peer, c] of changes.entries()){
|
|
1956
|
+
* console.log("peer: ", peer);
|
|
1957
|
+
* for (let change of c){
|
|
1958
|
+
* console.log("change: ", change);
|
|
1959
|
+
* }
|
|
1960
|
+
* }
|
|
1961
|
+
* ```
|
|
1962
|
+
* @returns {Map<PeerID, Change[]>}
|
|
1963
|
+
*/
|
|
1964
|
+
getAllChanges(): Map<PeerID, Change[]>;
|
|
1965
|
+
/**
|
|
1966
|
+
* Get the change that contains the specific ID
|
|
1967
|
+
* @param {{ peer: PeerID, counter: number }} id
|
|
1968
|
+
* @returns {Change}
|
|
1969
|
+
*/
|
|
1970
|
+
getChangeAt(id: { peer: PeerID, counter: number }): Change;
|
|
1971
|
+
/**
|
|
1972
|
+
* Get the change of with specific peer_id and lamport <= given lamport
|
|
1973
|
+
* @param {string} peer_id
|
|
1974
|
+
* @param {number} lamport
|
|
1975
|
+
* @returns {Change | undefined}
|
|
1976
|
+
*/
|
|
1977
|
+
getChangeAtLamport(peer_id: string, lamport: number): Change | undefined;
|
|
1978
|
+
/**
|
|
1979
|
+
* Get all ops of the change that contains the specific ID
|
|
1980
|
+
* @param {{ peer: PeerID, counter: number }} id
|
|
1981
|
+
* @returns {any[]}
|
|
1982
|
+
*/
|
|
1983
|
+
getOpsInChange(id: { peer: PeerID, counter: number }): any[];
|
|
1984
|
+
/**
|
|
1985
|
+
* Convert frontiers to a version vector
|
|
1986
|
+
*
|
|
1987
|
+
* Learn more about frontiers and version vector [here](https://loro.dev/docs/advanced/version_deep_dive)
|
|
1988
|
+
*
|
|
1989
|
+
* @example
|
|
1990
|
+
* ```ts
|
|
1991
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1992
|
+
*
|
|
1993
|
+
* const doc = new LoroDoc();
|
|
1994
|
+
* const text = doc.getText("text");
|
|
1995
|
+
* text.insert(0, "Hello");
|
|
1996
|
+
* const frontiers = doc.frontiers();
|
|
1997
|
+
* const version = doc.frontiersToVV(frontiers);
|
|
1998
|
+
* ```
|
|
1999
|
+
* @param {({ peer: PeerID, counter: number })[]} frontiers
|
|
2000
|
+
* @returns {VersionVector}
|
|
2001
|
+
*/
|
|
2002
|
+
frontiersToVV(frontiers: ({ peer: PeerID, counter: number })[]): VersionVector;
|
|
2003
|
+
/**
|
|
2004
|
+
* Convert a version vector to frontiers
|
|
2005
|
+
*
|
|
2006
|
+
* @example
|
|
2007
|
+
* ```ts
|
|
2008
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2009
|
+
*
|
|
2010
|
+
* const doc = new LoroDoc();
|
|
2011
|
+
* const text = doc.getText("text");
|
|
2012
|
+
* text.insert(0, "Hello");
|
|
2013
|
+
* const version = doc.version();
|
|
2014
|
+
* const frontiers = doc.vvToFrontiers(version);
|
|
2015
|
+
* ```
|
|
2016
|
+
* @param {VersionVector} vv
|
|
2017
|
+
* @returns {{ peer: PeerID, counter: number }[]}
|
|
2018
|
+
*/
|
|
2019
|
+
vvToFrontiers(vv: VersionVector): { peer: PeerID, counter: number }[];
|
|
2020
|
+
/**
|
|
2021
|
+
* Get the value or container at the given path
|
|
2022
|
+
*
|
|
2023
|
+
* @example
|
|
2024
|
+
* ```ts
|
|
2025
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2026
|
+
*
|
|
2027
|
+
* const doc = new LoroDoc();
|
|
2028
|
+
* const map = doc.getMap("map");
|
|
2029
|
+
* map.set("key", 1);
|
|
2030
|
+
* console.log(doc.getByPath("map/key")); // 1
|
|
2031
|
+
* console.log(doc.getByPath("map")); // LoroMap
|
|
2032
|
+
* ```
|
|
2033
|
+
* @param {string} path
|
|
2034
|
+
* @returns {Value | Container | undefined}
|
|
2035
|
+
*/
|
|
2036
|
+
getByPath(path: string): Value | Container | undefined;
|
|
2037
|
+
/**
|
|
2038
|
+
* Get the absolute position of the given Cursor
|
|
2039
|
+
*
|
|
2040
|
+
* @example
|
|
2041
|
+
* ```ts
|
|
2042
|
+
* const doc = new LoroDoc();
|
|
2043
|
+
* const text = doc.getText("text");
|
|
2044
|
+
* text.insert(0, "123");
|
|
2045
|
+
* const pos0 = text.getCursor(0, 0);
|
|
2046
|
+
* {
|
|
2047
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
2048
|
+
* expect(ans.offset).toBe(0);
|
|
2049
|
+
* }
|
|
2050
|
+
* text.insert(0, "1");
|
|
2051
|
+
* {
|
|
2052
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
2053
|
+
* expect(ans.offset).toBe(1);
|
|
2054
|
+
* }
|
|
2055
|
+
* ```
|
|
2056
|
+
* @param {Cursor} cursor
|
|
2057
|
+
* @returns {{ update?: Cursor, offset: number, side: Side }}
|
|
2058
|
+
*/
|
|
2059
|
+
getCursorPos(cursor: Cursor): { update?: Cursor, offset: number, side: Side };
|
|
2060
|
+
/**
|
|
2061
|
+
* Gets container IDs modified in the given ID range.
|
|
2062
|
+
*
|
|
2063
|
+
* **NOTE:** This method will implicitly commit.
|
|
2064
|
+
*
|
|
2065
|
+
* This method identifies which containers were affected by changes in a given range of operations.
|
|
2066
|
+
* It can be used together with `doc.travelChangeAncestors()` to analyze the history of changes
|
|
2067
|
+
* and determine which containers were modified by each change.
|
|
2068
|
+
*
|
|
2069
|
+
* @param id - The starting ID of the change range
|
|
2070
|
+
* @param len - The length of the change range to check
|
|
2071
|
+
* @returns An array of container IDs that were modified in the given range
|
|
2072
|
+
* @param {{ peer: PeerID, counter: number }} id
|
|
2073
|
+
* @param {number} len
|
|
2074
|
+
* @returns {(ContainerID)[]}
|
|
2075
|
+
*/
|
|
2076
|
+
getChangedContainersIn(id: { peer: PeerID, counter: number }, len: number): (ContainerID)[];
|
|
2077
|
+
/**
|
|
2078
|
+
* Peer ID of the current writer.
|
|
2079
|
+
*/
|
|
2080
|
+
readonly peerId: bigint;
|
|
2081
|
+
/**
|
|
2082
|
+
* Get peer id in decimal string.
|
|
2083
|
+
*/
|
|
2084
|
+
readonly peerIdStr: PeerID;
|
|
2085
|
+
}
|
|
2086
|
+
/**
|
|
2087
|
+
* The handler of a list container.
|
|
2088
|
+
*
|
|
2089
|
+
* Learn more at https://loro.dev/docs/tutorial/list
|
|
2090
|
+
*/
|
|
2091
|
+
export class LoroList {
|
|
2092
|
+
free(): void;
|
|
2093
|
+
/**
|
|
2094
|
+
* Create a new detached LoroList (not attached to any LoroDoc).
|
|
2095
|
+
*
|
|
2096
|
+
* The edits on a detached container will not be persisted.
|
|
2097
|
+
* To attach the container to the document, please insert it into an attached container.
|
|
2098
|
+
*/
|
|
2099
|
+
constructor();
|
|
2100
|
+
/**
|
|
2101
|
+
* "List"
|
|
2102
|
+
* @returns {'List'}
|
|
2103
|
+
*/
|
|
2104
|
+
kind(): 'List';
|
|
2105
|
+
/**
|
|
2106
|
+
* Delete elements from index to index + len.
|
|
2107
|
+
*
|
|
2108
|
+
* @example
|
|
2109
|
+
* ```ts
|
|
2110
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2111
|
+
*
|
|
2112
|
+
* const doc = new LoroDoc();
|
|
2113
|
+
* const list = doc.getList("list");
|
|
2114
|
+
* list.insert(0, 100);
|
|
2115
|
+
* list.delete(0, 1);
|
|
2116
|
+
* console.log(list.value); // []
|
|
2117
|
+
* ```
|
|
2118
|
+
* @param {number} index
|
|
2119
|
+
* @param {number} len
|
|
2120
|
+
*/
|
|
2121
|
+
delete(index: number, len: number): void;
|
|
2122
|
+
/**
|
|
2123
|
+
* Get elements of the list. If the type of a element is a container, it will be
|
|
2124
|
+
* resolved recursively.
|
|
2125
|
+
*
|
|
2126
|
+
* @example
|
|
2127
|
+
* ```ts
|
|
2128
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2129
|
+
*
|
|
2130
|
+
* const doc = new LoroDoc();
|
|
2131
|
+
* const list = doc.getList("list");
|
|
2132
|
+
* list.insert(0, 100);
|
|
2133
|
+
* const text = list.insertContainer(1, new LoroText());
|
|
2134
|
+
* text.insert(0, "Hello");
|
|
2135
|
+
* console.log(list.toJSON()); // [100, "Hello"];
|
|
2136
|
+
* ```
|
|
2137
|
+
* @returns {any}
|
|
2138
|
+
*/
|
|
2139
|
+
toJSON(): any;
|
|
2140
|
+
/**
|
|
2141
|
+
* Get the parent container.
|
|
2142
|
+
*
|
|
2143
|
+
* - The parent container of the root tree is `undefined`.
|
|
2144
|
+
* - The object returned is a new js object each time because it need to cross
|
|
2145
|
+
* the WASM boundary.
|
|
2146
|
+
* @returns {Container | undefined}
|
|
2147
|
+
*/
|
|
2148
|
+
parent(): Container | undefined;
|
|
2149
|
+
/**
|
|
2150
|
+
* Whether the container is attached to a document.
|
|
2151
|
+
*
|
|
2152
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
2153
|
+
* @returns {boolean}
|
|
2154
|
+
*/
|
|
2155
|
+
isAttached(): boolean;
|
|
2156
|
+
/**
|
|
2157
|
+
* Get the attached container associated with this.
|
|
2158
|
+
*
|
|
2159
|
+
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
2160
|
+
* @returns {LoroList | undefined}
|
|
2161
|
+
*/
|
|
2162
|
+
getAttached(): LoroList | undefined;
|
|
2163
|
+
/**
|
|
2164
|
+
* Pop a value from the end of the list.
|
|
2165
|
+
* @returns {Value | undefined}
|
|
2166
|
+
*/
|
|
2167
|
+
pop(): Value | undefined;
|
|
2168
|
+
/**
|
|
2169
|
+
* Delete all elements in the list.
|
|
2170
|
+
*/
|
|
2171
|
+
clear(): void;
|
|
2172
|
+
/**
|
|
2173
|
+
* @param {number} pos
|
|
2174
|
+
* @returns {{ peer: PeerID, counter: number } | undefined}
|
|
2175
|
+
*/
|
|
2176
|
+
getIdAt(pos: number): { peer: PeerID, counter: number } | undefined;
|
|
2177
|
+
/**
|
|
2178
|
+
* Check if the container is deleted
|
|
2179
|
+
* @returns {boolean}
|
|
2180
|
+
*/
|
|
2181
|
+
isDeleted(): boolean;
|
|
2182
|
+
/**
|
|
2183
|
+
* Get the id of this container.
|
|
2184
|
+
*/
|
|
2185
|
+
readonly id: ContainerID;
|
|
2186
|
+
/**
|
|
2187
|
+
* Get the length of list.
|
|
2188
|
+
*
|
|
2189
|
+
* @example
|
|
2190
|
+
* ```ts
|
|
2191
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2192
|
+
*
|
|
2193
|
+
* const doc = new LoroDoc();
|
|
2194
|
+
* const list = doc.getList("list");
|
|
2195
|
+
* list.insert(0, 100);
|
|
2196
|
+
* list.insert(1, "foo");
|
|
2197
|
+
* list.insert(2, true);
|
|
2198
|
+
* console.log(list.length); // 3
|
|
2199
|
+
* ```
|
|
2200
|
+
*/
|
|
2201
|
+
readonly length: number;
|
|
2202
|
+
}
|
|
2203
|
+
/**
|
|
2204
|
+
* The handler of a map container.
|
|
2205
|
+
*
|
|
2206
|
+
* Learn more at https://loro.dev/docs/tutorial/map
|
|
2207
|
+
*/
|
|
2208
|
+
export class LoroMap {
|
|
2209
|
+
free(): void;
|
|
2210
|
+
/**
|
|
2211
|
+
* Create a new detached LoroMap (not attached to any LoroDoc).
|
|
2212
|
+
*
|
|
2213
|
+
* The edits on a detached container will not be persisted.
|
|
2214
|
+
* To attach the container to the document, please insert it into an attached container.
|
|
2215
|
+
*/
|
|
2216
|
+
constructor();
|
|
2217
|
+
/**
|
|
2218
|
+
* "Map"
|
|
2219
|
+
* @returns {'Map'}
|
|
2220
|
+
*/
|
|
2221
|
+
kind(): 'Map';
|
|
2222
|
+
/**
|
|
2223
|
+
* Remove the key from the map.
|
|
2224
|
+
*
|
|
2225
|
+
* @example
|
|
2226
|
+
* ```ts
|
|
2227
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2228
|
+
*
|
|
2229
|
+
* const doc = new LoroDoc();
|
|
2230
|
+
* const map = doc.getMap("map");
|
|
2231
|
+
* map.set("foo", "bar");
|
|
2232
|
+
* map.delete("foo");
|
|
2233
|
+
* ```
|
|
2234
|
+
* @param {string} key
|
|
2235
|
+
*/
|
|
2236
|
+
delete(key: string): void;
|
|
2237
|
+
/**
|
|
2238
|
+
* Get the keys of the map.
|
|
2239
|
+
*
|
|
2240
|
+
* @example
|
|
2241
|
+
* ```ts
|
|
2242
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2243
|
+
*
|
|
2244
|
+
* const doc = new LoroDoc();
|
|
2245
|
+
* const map = doc.getMap("map");
|
|
2246
|
+
* map.set("foo", "bar");
|
|
2247
|
+
* map.set("baz", "bar");
|
|
2248
|
+
* const keys = map.keys(); // ["foo", "baz"]
|
|
2249
|
+
* ```
|
|
2250
|
+
* @returns {any[]}
|
|
2251
|
+
*/
|
|
2252
|
+
keys(): any[];
|
|
2253
|
+
/**
|
|
2254
|
+
* Get the values of the map. If the value is a child container, the corresponding
|
|
2255
|
+
* `Container` will be returned.
|
|
2256
|
+
*
|
|
2257
|
+
* @example
|
|
2258
|
+
* ```ts
|
|
2259
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2260
|
+
*
|
|
2261
|
+
* const doc = new LoroDoc();
|
|
2262
|
+
* const map = doc.getMap("map");
|
|
2263
|
+
* map.set("foo", "bar");
|
|
2264
|
+
* map.set("baz", "bar");
|
|
2265
|
+
* const values = map.values(); // ["bar", "bar"]
|
|
2266
|
+
* ```
|
|
2267
|
+
* @returns {any[]}
|
|
2268
|
+
*/
|
|
2269
|
+
values(): any[];
|
|
2270
|
+
/**
|
|
2271
|
+
* Get the entries of the map. If the value is a child container, the corresponding
|
|
2272
|
+
* `Container` will be returned.
|
|
2273
|
+
*
|
|
2274
|
+
* @example
|
|
2275
|
+
* ```ts
|
|
2276
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2277
|
+
*
|
|
2278
|
+
* const doc = new LoroDoc();
|
|
2279
|
+
* const map = doc.getMap("map");
|
|
2280
|
+
* map.set("foo", "bar");
|
|
2281
|
+
* map.set("baz", "bar");
|
|
2282
|
+
* const entries = map.entries(); // [["foo", "bar"], ["baz", "bar"]]
|
|
2283
|
+
* ```
|
|
2284
|
+
* @returns {([string, Value | Container])[]}
|
|
2285
|
+
*/
|
|
2286
|
+
entries(): ([string, Value | Container])[];
|
|
2287
|
+
/**
|
|
2288
|
+
* Get the keys and the values. If the type of value is a child container,
|
|
2289
|
+
* it will be resolved recursively.
|
|
2290
|
+
*
|
|
2291
|
+
* @example
|
|
2292
|
+
* ```ts
|
|
2293
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2294
|
+
*
|
|
2295
|
+
* const doc = new LoroDoc();
|
|
2296
|
+
* const map = doc.getMap("map");
|
|
2297
|
+
* map.set("foo", "bar");
|
|
2298
|
+
* const text = map.setContainer("text", new LoroText());
|
|
2299
|
+
* text.insert(0, "Hello");
|
|
2300
|
+
* console.log(map.toJSON()); // {"foo": "bar", "text": "Hello"}
|
|
2301
|
+
* ```
|
|
2302
|
+
* @returns {any}
|
|
2303
|
+
*/
|
|
2304
|
+
toJSON(): any;
|
|
2305
|
+
/**
|
|
2306
|
+
* Get the parent container.
|
|
2307
|
+
*
|
|
2308
|
+
* - The parent container of the root tree is `undefined`.
|
|
2309
|
+
* - The object returned is a new js object each time because it need to cross
|
|
2310
|
+
* the WASM boundary.
|
|
2311
|
+
* @returns {Container | undefined}
|
|
2312
|
+
*/
|
|
2313
|
+
parent(): Container | undefined;
|
|
2314
|
+
/**
|
|
2315
|
+
* Whether the container is attached to a document.
|
|
2316
|
+
*
|
|
2317
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
2318
|
+
* @returns {boolean}
|
|
2319
|
+
*/
|
|
2320
|
+
isAttached(): boolean;
|
|
2321
|
+
/**
|
|
2322
|
+
* Get the attached container associated with this.
|
|
2323
|
+
*
|
|
2324
|
+
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
2325
|
+
* @returns {LoroMap | undefined}
|
|
2326
|
+
*/
|
|
2327
|
+
getAttached(): LoroMap | undefined;
|
|
2328
|
+
/**
|
|
2329
|
+
* Delete all key-value pairs in the map.
|
|
2330
|
+
*/
|
|
2331
|
+
clear(): void;
|
|
2332
|
+
/**
|
|
2333
|
+
* Get the peer id of the last editor on the given entry
|
|
2334
|
+
* @param {string} key
|
|
2335
|
+
* @returns {PeerID | undefined}
|
|
2336
|
+
*/
|
|
2337
|
+
getLastEditor(key: string): PeerID | undefined;
|
|
2338
|
+
/**
|
|
2339
|
+
* Check if the container is deleted
|
|
2340
|
+
* @returns {boolean}
|
|
2341
|
+
*/
|
|
2342
|
+
isDeleted(): boolean;
|
|
2343
|
+
/**
|
|
2344
|
+
* The container id of this handler.
|
|
2345
|
+
*/
|
|
2346
|
+
readonly id: ContainerID;
|
|
2347
|
+
/**
|
|
2348
|
+
* Get the size of the map.
|
|
2349
|
+
*
|
|
2350
|
+
* @example
|
|
2351
|
+
* ```ts
|
|
2352
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2353
|
+
*
|
|
2354
|
+
* const doc = new LoroDoc();
|
|
2355
|
+
* const map = doc.getMap("map");
|
|
2356
|
+
* map.set("foo", "bar");
|
|
2357
|
+
* console.log(map.size); // 1
|
|
2358
|
+
* ```
|
|
2359
|
+
*/
|
|
2360
|
+
readonly size: number;
|
|
2361
|
+
}
|
|
2362
|
+
/**
|
|
2363
|
+
* The handler of a list container.
|
|
2364
|
+
*
|
|
2365
|
+
* Learn more at https://loro.dev/docs/tutorial/list
|
|
2366
|
+
*/
|
|
2367
|
+
export class LoroMovableList {
|
|
2368
|
+
free(): void;
|
|
2369
|
+
/**
|
|
2370
|
+
* Create a new detached LoroMovableList (not attached to any LoroDoc).
|
|
2371
|
+
*
|
|
2372
|
+
* The edits on a detached container will not be persisted.
|
|
2373
|
+
* To attach the container to the document, please insert it into an attached container.
|
|
2374
|
+
*/
|
|
2375
|
+
constructor();
|
|
2376
|
+
/**
|
|
2377
|
+
* "MovableList"
|
|
2378
|
+
* @returns {'MovableList'}
|
|
2379
|
+
*/
|
|
2380
|
+
kind(): 'MovableList';
|
|
2381
|
+
/**
|
|
2382
|
+
* Delete elements from index to index + len.
|
|
2383
|
+
*
|
|
2384
|
+
* @example
|
|
2385
|
+
* ```ts
|
|
2386
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2387
|
+
*
|
|
2388
|
+
* const doc = new LoroDoc();
|
|
2389
|
+
* const list = doc.getList("list");
|
|
2390
|
+
* list.insert(0, 100);
|
|
2391
|
+
* list.delete(0, 1);
|
|
2392
|
+
* console.log(list.value); // []
|
|
2393
|
+
* ```
|
|
2394
|
+
* @param {number} index
|
|
2395
|
+
* @param {number} len
|
|
2396
|
+
*/
|
|
2397
|
+
delete(index: number, len: number): void;
|
|
2398
|
+
/**
|
|
2399
|
+
* Get elements of the list. If the type of a element is a container, it will be
|
|
2400
|
+
* resolved recursively.
|
|
2401
|
+
*
|
|
2402
|
+
* @example
|
|
2403
|
+
* ```ts
|
|
2404
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2405
|
+
*
|
|
2406
|
+
* const doc = new LoroDoc();
|
|
2407
|
+
* const list = doc.getList("list");
|
|
2408
|
+
* list.insert(0, 100);
|
|
2409
|
+
* const text = list.insertContainer(1, new LoroText());
|
|
2410
|
+
* text.insert(0, "Hello");
|
|
2411
|
+
* console.log(list.toJSON()); // [100, "Hello"];
|
|
2412
|
+
* ```
|
|
2413
|
+
* @returns {any}
|
|
2414
|
+
*/
|
|
2415
|
+
toJSON(): any;
|
|
2416
|
+
/**
|
|
2417
|
+
* Get the parent container.
|
|
2418
|
+
*
|
|
2419
|
+
* - The parent container of the root tree is `undefined`.
|
|
2420
|
+
* - The object returned is a new js object each time because it need to cross
|
|
2421
|
+
* the WASM boundary.
|
|
2422
|
+
* @returns {Container | undefined}
|
|
2423
|
+
*/
|
|
2424
|
+
parent(): Container | undefined;
|
|
2425
|
+
/**
|
|
2426
|
+
* Whether the container is attached to a document.
|
|
2427
|
+
*
|
|
2428
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
2429
|
+
* @returns {boolean}
|
|
2430
|
+
*/
|
|
2431
|
+
isAttached(): boolean;
|
|
2432
|
+
/**
|
|
2433
|
+
* Get the attached container associated with this.
|
|
2434
|
+
*
|
|
2435
|
+
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
2436
|
+
* @returns {LoroList | undefined}
|
|
2437
|
+
*/
|
|
2438
|
+
getAttached(): LoroList | undefined;
|
|
2439
|
+
/**
|
|
2440
|
+
* Move the element from `from` to `to`.
|
|
2441
|
+
*
|
|
2442
|
+
* The new position of the element will be `to`.
|
|
2443
|
+
* Move the element from `from` to `to`.
|
|
2444
|
+
*
|
|
2445
|
+
* The new position of the element will be `to`. This method is optimized to prevent redundant
|
|
2446
|
+
* operations that might occur with a naive remove and insert approach. Specifically, it avoids
|
|
2447
|
+
* creating surplus values in the list, unlike a delete followed by an insert, which can lead to
|
|
2448
|
+
* additional values in cases of concurrent edits. This ensures more efficient and accurate
|
|
2449
|
+
* operations in a MovableList.
|
|
2450
|
+
* @param {number} from
|
|
2451
|
+
* @param {number} to
|
|
2452
|
+
*/
|
|
2453
|
+
move(from: number, to: number): void;
|
|
2454
|
+
/**
|
|
2455
|
+
* Pop a value from the end of the list.
|
|
2456
|
+
* @returns {Value | undefined}
|
|
2457
|
+
*/
|
|
2458
|
+
pop(): Value | undefined;
|
|
2459
|
+
/**
|
|
2460
|
+
* Delete all elements in the list.
|
|
2461
|
+
*/
|
|
2462
|
+
clear(): void;
|
|
2463
|
+
/**
|
|
2464
|
+
* Get the creator of the list item at the given position.
|
|
2465
|
+
* @param {number} pos
|
|
2466
|
+
* @returns {PeerID | undefined}
|
|
2467
|
+
*/
|
|
2468
|
+
getCreatorAt(pos: number): PeerID | undefined;
|
|
2469
|
+
/**
|
|
2470
|
+
* Get the last mover of the list item at the given position.
|
|
2471
|
+
* @param {number} pos
|
|
2472
|
+
* @returns {PeerID | undefined}
|
|
2473
|
+
*/
|
|
2474
|
+
getLastMoverAt(pos: number): PeerID | undefined;
|
|
2475
|
+
/**
|
|
2476
|
+
* Get the last editor of the list item at the given position.
|
|
2477
|
+
* @param {number} pos
|
|
2478
|
+
* @returns {PeerID | undefined}
|
|
2479
|
+
*/
|
|
2480
|
+
getLastEditorAt(pos: number): PeerID | undefined;
|
|
2481
|
+
/**
|
|
2482
|
+
* Check if the container is deleted
|
|
2483
|
+
* @returns {boolean}
|
|
2484
|
+
*/
|
|
2485
|
+
isDeleted(): boolean;
|
|
2486
|
+
/**
|
|
2487
|
+
* Get the id of this container.
|
|
2488
|
+
*/
|
|
2489
|
+
readonly id: ContainerID;
|
|
2490
|
+
/**
|
|
2491
|
+
* Get the length of list.
|
|
2492
|
+
*
|
|
2493
|
+
* @example
|
|
2494
|
+
* ```ts
|
|
2495
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2496
|
+
*
|
|
2497
|
+
* const doc = new LoroDoc();
|
|
2498
|
+
* const list = doc.getList("list");
|
|
2499
|
+
* list.insert(0, 100);
|
|
2500
|
+
* list.insert(1, "foo");
|
|
2501
|
+
* list.insert(2, true);
|
|
2502
|
+
* console.log(list.length); // 3
|
|
2503
|
+
* ```
|
|
2504
|
+
*/
|
|
2505
|
+
readonly length: number;
|
|
2506
|
+
}
|
|
2507
|
+
/**
|
|
2508
|
+
* The handler of a text container. It supports rich text CRDT.
|
|
2509
|
+
*
|
|
2510
|
+
* Learn more at https://loro.dev/docs/tutorial/text
|
|
2511
|
+
*/
|
|
2512
|
+
export class LoroText {
|
|
2513
|
+
free(): void;
|
|
2514
|
+
/**
|
|
2515
|
+
* Create a new detached LoroText (not attached to any LoroDoc).
|
|
2516
|
+
*
|
|
2517
|
+
* The edits on a detached container will not be persisted.
|
|
2518
|
+
* To attach the container to the document, please insert it into an attached container.
|
|
2519
|
+
*/
|
|
2520
|
+
constructor();
|
|
2521
|
+
/**
|
|
2522
|
+
* "Text"
|
|
2523
|
+
* @returns {'Text'}
|
|
2524
|
+
*/
|
|
2525
|
+
kind(): 'Text';
|
|
2526
|
+
/**
|
|
2527
|
+
* Iterate each text span(internal storage unit)
|
|
2528
|
+
*
|
|
2529
|
+
* The callback function will be called for each span in the text.
|
|
2530
|
+
* If the callback returns `false`, the iteration will stop.
|
|
2531
|
+
*
|
|
2532
|
+
* Limitation: you cannot access or alter the doc state when iterating (this is for performance consideration).
|
|
2533
|
+
* If you need to access or alter the doc state, please use `toString` instead.
|
|
2534
|
+
*
|
|
2535
|
+
* @example
|
|
2536
|
+
* ```ts
|
|
2537
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2538
|
+
*
|
|
2539
|
+
* const doc = new LoroDoc();
|
|
2540
|
+
* const text = doc.getText("text");
|
|
2541
|
+
* text.insert(0, "Hello");
|
|
2542
|
+
* text.iter((str) => (console.log(str), true));
|
|
2543
|
+
* ```
|
|
2544
|
+
* @param {Function} callback
|
|
2545
|
+
*/
|
|
2546
|
+
iter(callback: Function): void;
|
|
2547
|
+
/**
|
|
2548
|
+
* Insert the string at the given index (utf-16 index).
|
|
2549
|
+
*
|
|
2550
|
+
* @example
|
|
2551
|
+
* ```ts
|
|
2552
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2553
|
+
*
|
|
2554
|
+
* const doc = new LoroDoc();
|
|
2555
|
+
* const text = doc.getText("text");
|
|
2556
|
+
* text.insert(0, "Hello");
|
|
2557
|
+
* ```
|
|
2558
|
+
* @param {number} index
|
|
2559
|
+
* @param {string} content
|
|
2560
|
+
*/
|
|
2561
|
+
insert(index: number, content: string): void;
|
|
2562
|
+
/**
|
|
2563
|
+
* Get a string slice (utf-16 index).
|
|
2564
|
+
*
|
|
2565
|
+
* @example
|
|
2566
|
+
* ```ts
|
|
2567
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2568
|
+
*
|
|
2569
|
+
* const doc = new LoroDoc();
|
|
2570
|
+
* const text = doc.getText("text");
|
|
2571
|
+
* text.insert(0, "Hello");
|
|
2572
|
+
* text.slice(0, 2); // "He"
|
|
2573
|
+
* ```
|
|
2574
|
+
* @param {number} start_index
|
|
2575
|
+
* @param {number} end_index
|
|
2576
|
+
* @returns {string}
|
|
2577
|
+
*/
|
|
2578
|
+
slice(start_index: number, end_index: number): string;
|
|
2579
|
+
/**
|
|
2580
|
+
* Get the character at the given position (utf-16 index).
|
|
2581
|
+
*
|
|
2582
|
+
* @example
|
|
2583
|
+
* ```ts
|
|
2584
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2585
|
+
*
|
|
2586
|
+
* const doc = new LoroDoc();
|
|
2587
|
+
* const text = doc.getText("text");
|
|
2588
|
+
* text.insert(0, "Hello");
|
|
2589
|
+
* text.charAt(0); // "H"
|
|
2590
|
+
* ```
|
|
2591
|
+
* @param {number} pos
|
|
2592
|
+
* @returns {string}
|
|
2593
|
+
*/
|
|
2594
|
+
charAt(pos: number): string;
|
|
2595
|
+
/**
|
|
2596
|
+
* Delete and return the string at the given range and insert a string at the same position (utf-16 index).
|
|
2597
|
+
*
|
|
2598
|
+
* @example
|
|
2599
|
+
* ```ts
|
|
2600
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2601
|
+
*
|
|
2602
|
+
* const doc = new LoroDoc();
|
|
2603
|
+
* const text = doc.getText("text");
|
|
2604
|
+
* text.insert(0, "Hello");
|
|
2605
|
+
* text.splice(2, 3, "llo"); // "llo"
|
|
2606
|
+
* ```
|
|
2607
|
+
* @param {number} pos
|
|
2608
|
+
* @param {number} len
|
|
2609
|
+
* @param {string} s
|
|
2610
|
+
* @returns {string}
|
|
2611
|
+
*/
|
|
2612
|
+
splice(pos: number, len: number, s: string): string;
|
|
2613
|
+
/**
|
|
2614
|
+
* Insert some string at utf-8 index.
|
|
2615
|
+
*
|
|
2616
|
+
* @example
|
|
2617
|
+
* ```ts
|
|
2618
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2619
|
+
*
|
|
2620
|
+
* const doc = new LoroDoc();
|
|
2621
|
+
* const text = doc.getText("text");
|
|
2622
|
+
* text.insertUtf8(0, "Hello");
|
|
2623
|
+
* ```
|
|
2624
|
+
* @param {number} index
|
|
2625
|
+
* @param {string} content
|
|
2626
|
+
*/
|
|
2627
|
+
insertUtf8(index: number, content: string): void;
|
|
2628
|
+
/**
|
|
2629
|
+
* Delete elements from index to index + len (utf-16 index).
|
|
2630
|
+
*
|
|
2631
|
+
* @example
|
|
2632
|
+
* ```ts
|
|
2633
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2634
|
+
*
|
|
2635
|
+
* const doc = new LoroDoc();
|
|
2636
|
+
* const text = doc.getText("text");
|
|
2637
|
+
* text.insert(0, "Hello");
|
|
2638
|
+
* text.delete(1, 3);
|
|
2639
|
+
* const s = text.toString();
|
|
2640
|
+
* console.log(s); // "Ho"
|
|
2641
|
+
* ```
|
|
2642
|
+
* @param {number} index
|
|
2643
|
+
* @param {number} len
|
|
2644
|
+
*/
|
|
2645
|
+
delete(index: number, len: number): void;
|
|
2646
|
+
/**
|
|
2647
|
+
* Delete elements from index to utf-8 index + len
|
|
2648
|
+
*
|
|
2649
|
+
* @example
|
|
2650
|
+
* ```ts
|
|
2651
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2652
|
+
*
|
|
2653
|
+
* const doc = new LoroDoc();
|
|
2654
|
+
* const text = doc.getText("text");
|
|
2655
|
+
* text.insertUtf8(0, "Hello");
|
|
2656
|
+
* text.deleteUtf8(1, 3);
|
|
2657
|
+
* const s = text.toString();
|
|
2658
|
+
* console.log(s); // "Ho"
|
|
2659
|
+
* ```
|
|
2660
|
+
* @param {number} index
|
|
2661
|
+
* @param {number} len
|
|
2662
|
+
*/
|
|
2663
|
+
deleteUtf8(index: number, len: number): void;
|
|
2664
|
+
/**
|
|
2665
|
+
* Mark a range of text with a key and a value (utf-16 index).
|
|
2666
|
+
*
|
|
2667
|
+
* > You should call `configTextStyle` before using `mark` and `unmark`.
|
|
2668
|
+
*
|
|
2669
|
+
* You can use it to create a highlight, make a range of text bold, or add a link to a range of text.
|
|
2670
|
+
*
|
|
2671
|
+
* Note: this is not suitable for unmergeable annotations like comments.
|
|
2672
|
+
*
|
|
2673
|
+
* @example
|
|
2674
|
+
* ```ts
|
|
2675
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2676
|
+
*
|
|
2677
|
+
* const doc = new LoroDoc();
|
|
2678
|
+
* doc.configTextStyle({bold: {expand: "after"}});
|
|
2679
|
+
* const text = doc.getText("text");
|
|
2680
|
+
* text.insert(0, "Hello World!");
|
|
2681
|
+
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
2682
|
+
* ```
|
|
2683
|
+
* @param {{ start: number, end: number }} range
|
|
2684
|
+
* @param {string} key
|
|
2685
|
+
* @param {any} value
|
|
2686
|
+
*/
|
|
2687
|
+
mark(range: { start: number, end: number }, key: string, value: any): void;
|
|
2688
|
+
/**
|
|
2689
|
+
* Unmark a range of text with a key and a value (utf-16 index).
|
|
2690
|
+
*
|
|
2691
|
+
* > You should call `configTextStyle` before using `mark` and `unmark`.
|
|
2692
|
+
*
|
|
2693
|
+
* You can use it to remove highlights, bolds or links
|
|
2694
|
+
*
|
|
2695
|
+
* @example
|
|
2696
|
+
* ```ts
|
|
2697
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2698
|
+
*
|
|
2699
|
+
* const doc = new LoroDoc();
|
|
2700
|
+
* doc.configTextStyle({bold: {expand: "after"}});
|
|
2701
|
+
* const text = doc.getText("text");
|
|
2702
|
+
* text.insert(0, "Hello World!");
|
|
2703
|
+
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
2704
|
+
* text.unmark({ start: 0, end: 5 }, "bold");
|
|
2705
|
+
* ```
|
|
2706
|
+
* @param {{ start: number, end: number }} range
|
|
2707
|
+
* @param {string} key
|
|
2708
|
+
*/
|
|
2709
|
+
unmark(range: { start: number, end: number }, key: string): void;
|
|
2710
|
+
/**
|
|
2711
|
+
* Convert the text to a string
|
|
2712
|
+
* @returns {string}
|
|
2713
|
+
*/
|
|
2714
|
+
toString(): string;
|
|
2715
|
+
/**
|
|
2716
|
+
* Get the text in [Delta](https://quilljs.com/docs/delta/) format.
|
|
2717
|
+
*
|
|
2718
|
+
* The returned value will include the rich text information.
|
|
2719
|
+
*
|
|
2720
|
+
* @example
|
|
2721
|
+
* ```ts
|
|
2722
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2723
|
+
*
|
|
2724
|
+
* const doc = new LoroDoc();
|
|
2725
|
+
* const text = doc.getText("text");
|
|
2726
|
+
* doc.configTextStyle({bold: {expand: "after"}});
|
|
2727
|
+
* text.insert(0, "Hello World!");
|
|
2728
|
+
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
2729
|
+
* console.log(text.toDelta()); // [ { insert: 'Hello', attributes: { bold: true } } ]
|
|
2730
|
+
* ```
|
|
2731
|
+
* @returns {Delta<string>[]}
|
|
2732
|
+
*/
|
|
2733
|
+
toDelta(): Delta<string>[];
|
|
2734
|
+
/**
|
|
2735
|
+
* Change the state of this text by delta.
|
|
2736
|
+
*
|
|
2737
|
+
* If a delta item is `insert`, it should include all the attributes of the inserted text.
|
|
2738
|
+
* Loro's rich text CRDT may make the inserted text inherit some styles when you use
|
|
2739
|
+
* `insert` method directly. However, when you use `applyDelta` if some attributes are
|
|
2740
|
+
* inherited from CRDT but not included in the delta, they will be removed.
|
|
2741
|
+
*
|
|
2742
|
+
* Another special property of `applyDelta` is if you format an attribute for ranges out of
|
|
2743
|
+
* the text length, Loro will insert new lines to fill the gap first. It's useful when you
|
|
2744
|
+
* build the binding between Loro and rich text editors like Quill, which might assume there
|
|
2745
|
+
* is always a newline at the end of the text implicitly.
|
|
2746
|
+
*
|
|
2747
|
+
* @example
|
|
2748
|
+
* ```ts
|
|
2749
|
+
* const doc = new LoroDoc();
|
|
2750
|
+
* const text = doc.getText("text");
|
|
2751
|
+
* doc.configTextStyle({bold: {expand: "after"}});
|
|
2752
|
+
* text.insert(0, "Hello World!");
|
|
2753
|
+
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
2754
|
+
* const delta = text.toDelta();
|
|
2755
|
+
* const text2 = doc.getText("text2");
|
|
2756
|
+
* text2.applyDelta(delta);
|
|
2757
|
+
* expect(text2.toDelta()).toStrictEqual(delta);
|
|
2758
|
+
* ```
|
|
2759
|
+
* @param {Delta<string>[]} delta
|
|
2760
|
+
*/
|
|
2761
|
+
applyDelta(delta: Delta<string>[]): void;
|
|
2762
|
+
/**
|
|
2763
|
+
* Get the parent container.
|
|
2764
|
+
*
|
|
2765
|
+
* - The parent of the root is `undefined`.
|
|
2766
|
+
* - The object returned is a new js object each time because it need to cross
|
|
2767
|
+
* the WASM boundary.
|
|
2768
|
+
* @returns {Container | undefined}
|
|
2769
|
+
*/
|
|
2770
|
+
parent(): Container | undefined;
|
|
2771
|
+
/**
|
|
2772
|
+
* Whether the container is attached to a LoroDoc.
|
|
2773
|
+
*
|
|
2774
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
2775
|
+
* @returns {boolean}
|
|
2776
|
+
*/
|
|
2777
|
+
isAttached(): boolean;
|
|
2778
|
+
/**
|
|
2779
|
+
* Get the attached container associated with this.
|
|
2780
|
+
*
|
|
2781
|
+
* Returns an attached `Container` that is equal to this or created by this; otherwise, it returns `undefined`.
|
|
2782
|
+
* @returns {LoroText | undefined}
|
|
2783
|
+
*/
|
|
2784
|
+
getAttached(): LoroText | undefined;
|
|
2785
|
+
/**
|
|
2786
|
+
* Push a string to the end of the text.
|
|
2787
|
+
* @param {string} s
|
|
2788
|
+
*/
|
|
2789
|
+
push(s: string): void;
|
|
2790
|
+
/**
|
|
2791
|
+
* Get the editor of the text at the given position.
|
|
2792
|
+
* @param {number} pos
|
|
2793
|
+
* @returns {PeerID | undefined}
|
|
2794
|
+
*/
|
|
2795
|
+
getEditorOf(pos: number): PeerID | undefined;
|
|
2796
|
+
/**
|
|
2797
|
+
* Check if the container is deleted
|
|
2798
|
+
* @returns {boolean}
|
|
2799
|
+
*/
|
|
2800
|
+
isDeleted(): boolean;
|
|
2801
|
+
/**
|
|
2802
|
+
* Get the container id of the text.
|
|
2803
|
+
*/
|
|
2804
|
+
readonly id: ContainerID;
|
|
2805
|
+
/**
|
|
2806
|
+
* Get the length of text (utf-16 length).
|
|
2807
|
+
*/
|
|
2808
|
+
readonly length: number;
|
|
2809
|
+
}
|
|
2810
|
+
/**
|
|
2811
|
+
* The handler of a tree(forest) container.
|
|
2812
|
+
*
|
|
2813
|
+
* Learn more at https://loro.dev/docs/tutorial/tree
|
|
2814
|
+
*/
|
|
2815
|
+
export class LoroTree {
|
|
2816
|
+
free(): void;
|
|
2817
|
+
/**
|
|
2818
|
+
* Create a new detached LoroTree (not attached to any LoroDoc).
|
|
2819
|
+
*
|
|
2820
|
+
* The edits on a detached container will not be persisted.
|
|
2821
|
+
* To attach the container to the document, please insert it into an attached container.
|
|
2822
|
+
*/
|
|
2823
|
+
constructor();
|
|
2824
|
+
/**
|
|
2825
|
+
* "Tree"
|
|
2826
|
+
* @returns {'Tree'}
|
|
2827
|
+
*/
|
|
2828
|
+
kind(): 'Tree';
|
|
2829
|
+
/**
|
|
2830
|
+
* Move the target tree node to be a child of the parent.
|
|
2831
|
+
* It's not allowed that the target is an ancestor of the parent
|
|
2832
|
+
* or the target and the parent are the same node.
|
|
2833
|
+
*
|
|
2834
|
+
* @example
|
|
2835
|
+
* ```ts
|
|
2836
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2837
|
+
*
|
|
2838
|
+
* const doc = new LoroDoc();
|
|
2839
|
+
* const tree = doc.getTree("tree");
|
|
2840
|
+
* const root = tree.createNode();
|
|
2841
|
+
* const node = root.createNode();
|
|
2842
|
+
* const node2 = node.createNode();
|
|
2843
|
+
* tree.move(node2.id, root.id);
|
|
2844
|
+
* // Error will be thrown if move operation creates a cycle
|
|
2845
|
+
* // tree.move(root.id, node.id);
|
|
2846
|
+
* ```
|
|
2847
|
+
* @param {TreeID} target
|
|
2848
|
+
* @param {TreeID | undefined} parent
|
|
2849
|
+
* @param {number | undefined} [index]
|
|
2850
|
+
*/
|
|
2851
|
+
move(target: TreeID, parent: TreeID | undefined, index?: number): void;
|
|
2852
|
+
/**
|
|
2853
|
+
* Delete a tree node from the forest.
|
|
2854
|
+
*
|
|
2855
|
+
* @example
|
|
2856
|
+
* ```ts
|
|
2857
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2858
|
+
*
|
|
2859
|
+
* const doc = new LoroDoc();
|
|
2860
|
+
* const tree = doc.getTree("tree");
|
|
2861
|
+
* const root = tree.createNode();
|
|
2862
|
+
* const node = root.createNode();
|
|
2863
|
+
* tree.delete(node.id);
|
|
2864
|
+
* ```
|
|
2865
|
+
* @param {TreeID} target
|
|
2866
|
+
*/
|
|
2867
|
+
delete(target: TreeID): void;
|
|
2868
|
+
/**
|
|
2869
|
+
* Return `true` if the tree contains the TreeID, include deleted node.
|
|
2870
|
+
* @param {TreeID} target
|
|
2871
|
+
* @returns {boolean}
|
|
2872
|
+
*/
|
|
2873
|
+
has(target: TreeID): boolean;
|
|
2874
|
+
/**
|
|
2875
|
+
* Return `None` if the node is not exist, otherwise return `Some(true)` if the node is deleted.
|
|
2876
|
+
* @param {TreeID} target
|
|
2877
|
+
* @returns {boolean}
|
|
2878
|
+
*/
|
|
2879
|
+
isNodeDeleted(target: TreeID): boolean;
|
|
2880
|
+
/**
|
|
2881
|
+
* Get the hierarchy array with metadata of the forest.
|
|
2882
|
+
*
|
|
2883
|
+
* @example
|
|
2884
|
+
* ```ts
|
|
2885
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2886
|
+
*
|
|
2887
|
+
* const doc = new LoroDoc();
|
|
2888
|
+
* const tree = doc.getTree("tree");
|
|
2889
|
+
* const root = tree.createNode();
|
|
2890
|
+
* root.data.set("color", "red");
|
|
2891
|
+
* // [ { id: '0@F2462C4159C4C8D1', parent: null, meta: { color: 'red' }, children: [] } ]
|
|
2892
|
+
* console.log(tree.toJSON());
|
|
2893
|
+
* ```
|
|
2894
|
+
* @returns {any}
|
|
2895
|
+
*/
|
|
2896
|
+
toJSON(): any;
|
|
2897
|
+
/**
|
|
2898
|
+
* Get all tree nodes of the forest, including deleted nodes.
|
|
2899
|
+
*
|
|
2900
|
+
* @example
|
|
2901
|
+
* ```ts
|
|
2902
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2903
|
+
*
|
|
2904
|
+
* const doc = new LoroDoc();
|
|
2905
|
+
* const tree = doc.getTree("tree");
|
|
2906
|
+
* const root = tree.createNode();
|
|
2907
|
+
* const node = root.createNode();
|
|
2908
|
+
* const node2 = node.createNode();
|
|
2909
|
+
* console.log(tree.nodes());
|
|
2910
|
+
* ```
|
|
2911
|
+
* @returns {(LoroTreeNode)[]}
|
|
2912
|
+
*/
|
|
2913
|
+
nodes(): (LoroTreeNode)[];
|
|
2914
|
+
/**
|
|
2915
|
+
* Get the root nodes of the forest.
|
|
2916
|
+
* @returns {(LoroTreeNode)[]}
|
|
2917
|
+
*/
|
|
2918
|
+
roots(): (LoroTreeNode)[];
|
|
2919
|
+
/**
|
|
2920
|
+
* Get the parent container of the tree container.
|
|
2921
|
+
*
|
|
2922
|
+
* - The parent container of the root tree is `undefined`.
|
|
2923
|
+
* - The object returned is a new js object each time because it need to cross
|
|
2924
|
+
* the WASM boundary.
|
|
2925
|
+
* @returns {Container | undefined}
|
|
2926
|
+
*/
|
|
2927
|
+
parent(): Container | undefined;
|
|
2928
|
+
/**
|
|
2929
|
+
* Whether the container is attached to a document.
|
|
2930
|
+
*
|
|
2931
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
2932
|
+
* @returns {boolean}
|
|
2933
|
+
*/
|
|
2934
|
+
isAttached(): boolean;
|
|
2935
|
+
/**
|
|
2936
|
+
* Get the attached container associated with this.
|
|
2937
|
+
*
|
|
2938
|
+
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
2939
|
+
* @returns {LoroTree | undefined}
|
|
2940
|
+
*/
|
|
2941
|
+
getAttached(): LoroTree | undefined;
|
|
2942
|
+
/**
|
|
2943
|
+
* Set whether to generate a fractional index for moving and creating.
|
|
2944
|
+
*
|
|
2945
|
+
* A fractional index can be used to determine the position of tree nodes among their siblings.
|
|
2946
|
+
*
|
|
2947
|
+
* The jitter is used to avoid conflicts when multiple users are creating a node at the same position.
|
|
2948
|
+
* A value of 0 is the default, which means no jitter; any value larger than 0 will enable jitter.
|
|
2949
|
+
*
|
|
2950
|
+
* Generally speaking, higher jitter value will increase the size of the operation
|
|
2951
|
+
* [Read more about it](https://www.loro.dev/blog/movable-tree#implementation-and-encoding-size)
|
|
2952
|
+
* @param {number} jitter
|
|
2953
|
+
*/
|
|
2954
|
+
enableFractionalIndex(jitter: number): void;
|
|
2955
|
+
/**
|
|
2956
|
+
* Disable the fractional index generation for Tree Position when
|
|
2957
|
+
* you don't need the Tree's siblings to be sorted. The fractional index will always be set to default.
|
|
2958
|
+
*/
|
|
2959
|
+
disableFractionalIndex(): void;
|
|
2960
|
+
/**
|
|
2961
|
+
* Whether the tree enables the fractional index generation.
|
|
2962
|
+
* @returns {boolean}
|
|
2963
|
+
*/
|
|
2964
|
+
isFractionalIndexEnabled(): boolean;
|
|
2965
|
+
/**
|
|
2966
|
+
* Check if the container is deleted
|
|
2967
|
+
* @returns {boolean}
|
|
2968
|
+
*/
|
|
2969
|
+
isDeleted(): boolean;
|
|
2970
|
+
/**
|
|
2971
|
+
* Get the id of the container.
|
|
2972
|
+
*/
|
|
2973
|
+
readonly id: ContainerID;
|
|
2974
|
+
}
|
|
2975
|
+
/**
|
|
2976
|
+
* The handler of a tree node.
|
|
2977
|
+
*/
|
|
2978
|
+
export class LoroTreeNode {
|
|
2979
|
+
free(): void;
|
|
2980
|
+
/**
|
|
2981
|
+
* @returns {string}
|
|
2982
|
+
*/
|
|
2983
|
+
__getClassname(): string;
|
|
2984
|
+
/**
|
|
2985
|
+
* Move this tree node to be a child of the parent.
|
|
2986
|
+
* If the parent is undefined, this node will be a root node.
|
|
2987
|
+
*
|
|
2988
|
+
* If the index is not provided, the node will be appended to the end.
|
|
2989
|
+
*
|
|
2990
|
+
* It's not allowed that the target is an ancestor of the parent.
|
|
2991
|
+
*
|
|
2992
|
+
* @example
|
|
2993
|
+
* ```ts
|
|
2994
|
+
* const doc = new LoroDoc();
|
|
2995
|
+
* const tree = doc.getTree("tree");
|
|
2996
|
+
* const root = tree.createNode();
|
|
2997
|
+
* const node = root.createNode();
|
|
2998
|
+
* const node2 = node.createNode();
|
|
2999
|
+
* node2.move(undefined, 0);
|
|
3000
|
+
* // node2 root
|
|
3001
|
+
* // |
|
|
3002
|
+
* // node
|
|
3003
|
+
*
|
|
3004
|
+
* ```
|
|
3005
|
+
* @param {LoroTreeNode | undefined} parent
|
|
3006
|
+
* @param {number | undefined} [index]
|
|
3007
|
+
*/
|
|
3008
|
+
move(parent: LoroTreeNode | undefined, index?: number): void;
|
|
3009
|
+
/**
|
|
3010
|
+
* Move the tree node to be after the target node.
|
|
3011
|
+
*
|
|
3012
|
+
* @example
|
|
3013
|
+
* ```ts
|
|
3014
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3015
|
+
*
|
|
3016
|
+
* const doc = new LoroDoc();
|
|
3017
|
+
* const tree = doc.getTree("tree");
|
|
3018
|
+
* const root = tree.createNode();
|
|
3019
|
+
* const node = root.createNode();
|
|
3020
|
+
* const node2 = root.createNode();
|
|
3021
|
+
* node2.moveAfter(node);
|
|
3022
|
+
* // root
|
|
3023
|
+
* // / \
|
|
3024
|
+
* // node node2
|
|
3025
|
+
* ```
|
|
3026
|
+
* @param {LoroTreeNode} target
|
|
3027
|
+
*/
|
|
3028
|
+
moveAfter(target: LoroTreeNode): void;
|
|
3029
|
+
/**
|
|
3030
|
+
* Move the tree node to be before the target node.
|
|
3031
|
+
*
|
|
3032
|
+
* @example
|
|
3033
|
+
* ```ts
|
|
3034
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3035
|
+
*
|
|
3036
|
+
* const doc = new LoroDoc();
|
|
3037
|
+
* const tree = doc.getTree("tree");
|
|
3038
|
+
* const root = tree.createNode();
|
|
3039
|
+
* const node = root.createNode();
|
|
3040
|
+
* const node2 = root.createNode();
|
|
3041
|
+
* node2.moveBefore(node);
|
|
3042
|
+
* // root
|
|
3043
|
+
* // / \
|
|
3044
|
+
* // node2 node
|
|
3045
|
+
* ```
|
|
3046
|
+
* @param {LoroTreeNode} target
|
|
3047
|
+
*/
|
|
3048
|
+
moveBefore(target: LoroTreeNode): void;
|
|
3049
|
+
/**
|
|
3050
|
+
* Get the index of the node in the parent's children.
|
|
3051
|
+
* @returns {number | undefined}
|
|
3052
|
+
*/
|
|
3053
|
+
index(): number | undefined;
|
|
3054
|
+
/**
|
|
3055
|
+
* Get the `Fractional Index` of the node.
|
|
3056
|
+
*
|
|
3057
|
+
* Note: the tree container must be attached to the document.
|
|
3058
|
+
* @returns {string | undefined}
|
|
3059
|
+
*/
|
|
3060
|
+
fractionalIndex(): string | undefined;
|
|
3061
|
+
/**
|
|
3062
|
+
* Get the parent node of this node.
|
|
3063
|
+
*
|
|
3064
|
+
* - The parent of the root node is `undefined`.
|
|
3065
|
+
* - The object returned is a new js object each time because it need to cross
|
|
3066
|
+
* the WASM boundary.
|
|
3067
|
+
* @returns {LoroTreeNode | undefined}
|
|
3068
|
+
*/
|
|
3069
|
+
parent(): LoroTreeNode | undefined;
|
|
3070
|
+
/**
|
|
3071
|
+
* Check if the node is deleted.
|
|
3072
|
+
* @returns {boolean}
|
|
3073
|
+
*/
|
|
3074
|
+
isDeleted(): boolean;
|
|
3075
|
+
/**
|
|
3076
|
+
* Get the last mover of this node.
|
|
3077
|
+
* @returns {{ peer: PeerID, counter: number } | undefined}
|
|
3078
|
+
*/
|
|
3079
|
+
getLastMoveId(): { peer: PeerID, counter: number } | undefined;
|
|
3080
|
+
/**
|
|
3081
|
+
* Get the creation id of this node.
|
|
3082
|
+
* @returns {{ peer: PeerID, counter: number }}
|
|
3083
|
+
*/
|
|
3084
|
+
creationId(): { peer: PeerID, counter: number };
|
|
3085
|
+
/**
|
|
3086
|
+
* Get the creator of this node.
|
|
3087
|
+
* @returns {PeerID}
|
|
3088
|
+
*/
|
|
3089
|
+
creator(): PeerID;
|
|
3090
|
+
/**
|
|
3091
|
+
* The TreeID of the node.
|
|
3092
|
+
*/
|
|
3093
|
+
readonly id: TreeID;
|
|
3094
|
+
}
|
|
3095
|
+
/**
|
|
3096
|
+
* `UndoManager` is responsible for handling undo and redo operations.
|
|
3097
|
+
*
|
|
3098
|
+
* By default, the maxUndoSteps is set to 100, mergeInterval is set to 1000 ms.
|
|
3099
|
+
*
|
|
3100
|
+
* Each commit made by the current peer is recorded as an undo step in the `UndoManager`.
|
|
3101
|
+
* Undo steps can be merged if they occur within a specified merge interval.
|
|
3102
|
+
*
|
|
3103
|
+
* Note that undo operations are local and cannot revert changes made by other peers.
|
|
3104
|
+
* To undo changes made by other peers, consider using the time travel feature.
|
|
3105
|
+
*
|
|
3106
|
+
* Once the `peerId` is bound to the `UndoManager` in the document, it cannot be changed.
|
|
3107
|
+
* Otherwise, the `UndoManager` may not function correctly.
|
|
3108
|
+
*/
|
|
3109
|
+
export class UndoManager {
|
|
3110
|
+
free(): void;
|
|
3111
|
+
/**
|
|
3112
|
+
* `UndoManager` is responsible for handling undo and redo operations.
|
|
3113
|
+
*
|
|
3114
|
+
* PeerID cannot be changed during the lifetime of the UndoManager.
|
|
3115
|
+
*
|
|
3116
|
+
* Note that undo operations are local and cannot revert changes made by other peers.
|
|
3117
|
+
* To undo changes made by other peers, consider using the time travel feature.
|
|
3118
|
+
*
|
|
3119
|
+
* Each commit made by the current peer is recorded as an undo step in the `UndoManager`.
|
|
3120
|
+
* Undo steps can be merged if they occur within a specified merge interval.
|
|
3121
|
+
*
|
|
3122
|
+
* ## Config
|
|
3123
|
+
*
|
|
3124
|
+
* - `mergeInterval`: Optional. The interval in milliseconds within which undo steps can be merged. Default is 1000 ms.
|
|
3125
|
+
* - `maxUndoSteps`: Optional. The maximum number of undo steps to retain. Default is 100.
|
|
3126
|
+
* - `excludeOriginPrefixes`: Optional. An array of string prefixes. Events with origins matching these prefixes will be excluded from undo steps.
|
|
3127
|
+
* - `onPush`: Optional. A callback function that is called when an undo/redo step is pushed.
|
|
3128
|
+
* The function can return a meta data value that will be attached to the given stack item.
|
|
3129
|
+
* - `onPop`: Optional. A callback function that is called when an undo/redo step is popped.
|
|
3130
|
+
* The function will have a meta data value that was attached to the given stack item when
|
|
3131
|
+
* `onPush` was called.
|
|
3132
|
+
* @param {LoroDoc} doc
|
|
3133
|
+
* @param {UndoConfig} config
|
|
3134
|
+
*/
|
|
3135
|
+
constructor(doc: LoroDoc, config: UndoConfig);
|
|
3136
|
+
/**
|
|
3137
|
+
* Undo the last operation.
|
|
3138
|
+
* @returns {boolean}
|
|
3139
|
+
*/
|
|
3140
|
+
undo(): boolean;
|
|
3141
|
+
/**
|
|
3142
|
+
* Redo the last undone operation.
|
|
3143
|
+
* @returns {boolean}
|
|
3144
|
+
*/
|
|
3145
|
+
redo(): boolean;
|
|
3146
|
+
/**
|
|
3147
|
+
* Can undo the last operation.
|
|
3148
|
+
* @returns {boolean}
|
|
3149
|
+
*/
|
|
3150
|
+
canUndo(): boolean;
|
|
3151
|
+
/**
|
|
3152
|
+
* Can redo the last operation.
|
|
3153
|
+
* @returns {boolean}
|
|
3154
|
+
*/
|
|
3155
|
+
canRedo(): boolean;
|
|
3156
|
+
/**
|
|
3157
|
+
* The number of max undo steps.
|
|
3158
|
+
* If the number of undo steps exceeds this number, the oldest undo step will be removed.
|
|
3159
|
+
* @param {number} steps
|
|
3160
|
+
*/
|
|
3161
|
+
setMaxUndoSteps(steps: number): void;
|
|
3162
|
+
/**
|
|
3163
|
+
* Set the merge interval (in ms).
|
|
3164
|
+
* If the interval is set to 0, the undo steps will not be merged.
|
|
3165
|
+
* Otherwise, the undo steps will be merged if the interval between the two steps is less than the given interval.
|
|
3166
|
+
* @param {number} interval
|
|
3167
|
+
*/
|
|
3168
|
+
setMergeInterval(interval: number): void;
|
|
3169
|
+
/**
|
|
3170
|
+
* If a local event's origin matches the given prefix, it will not be recorded in the
|
|
3171
|
+
* undo stack.
|
|
3172
|
+
* @param {string} prefix
|
|
3173
|
+
*/
|
|
3174
|
+
addExcludeOriginPrefix(prefix: string): void;
|
|
3175
|
+
/**
|
|
3176
|
+
* Check if the undo manager is bound to the given document.
|
|
3177
|
+
* @param {LoroDoc} doc
|
|
3178
|
+
* @returns {boolean}
|
|
3179
|
+
*/
|
|
3180
|
+
checkBinding(doc: LoroDoc): boolean;
|
|
3181
|
+
/**
|
|
3182
|
+
*/
|
|
3183
|
+
clear(): void;
|
|
3184
|
+
}
|
|
3185
|
+
/**
|
|
3186
|
+
* [VersionVector](https://en.wikipedia.org/wiki/Version_vector)
|
|
3187
|
+
* is a map from [PeerID] to [Counter]. Its a right-open interval.
|
|
3188
|
+
*
|
|
3189
|
+
* i.e. a [VersionVector] of `{A: 1, B: 2}` means that A has 1 atomic op and B has 2 atomic ops,
|
|
3190
|
+
* thus ID of `{client: A, counter: 1}` is out of the range.
|
|
3191
|
+
*/
|
|
3192
|
+
export class VersionVector {
|
|
3193
|
+
free(): void;
|
|
3194
|
+
/**
|
|
3195
|
+
* Create a new version vector.
|
|
3196
|
+
* @param {Map<PeerID, number> | Uint8Array | VersionVector | undefined | null} value
|
|
3197
|
+
*/
|
|
3198
|
+
constructor(value: Map<PeerID, number> | Uint8Array | VersionVector | undefined | null);
|
|
3199
|
+
/**
|
|
3200
|
+
* Create a new version vector from a Map.
|
|
3201
|
+
* @param {Map<PeerID, number>} version
|
|
3202
|
+
* @returns {VersionVector}
|
|
3203
|
+
*/
|
|
3204
|
+
static parseJSON(version: Map<PeerID, number>): VersionVector;
|
|
3205
|
+
/**
|
|
3206
|
+
* Convert the version vector to a Map
|
|
3207
|
+
* @returns {Map<PeerID, number>}
|
|
3208
|
+
*/
|
|
3209
|
+
toJSON(): Map<PeerID, number>;
|
|
3210
|
+
/**
|
|
3211
|
+
* Encode the version vector into a Uint8Array.
|
|
3212
|
+
* @returns {Uint8Array}
|
|
3213
|
+
*/
|
|
3214
|
+
encode(): Uint8Array;
|
|
3215
|
+
/**
|
|
3216
|
+
* Decode the version vector from a Uint8Array.
|
|
3217
|
+
* @param {Uint8Array} bytes
|
|
3218
|
+
* @returns {VersionVector}
|
|
3219
|
+
*/
|
|
3220
|
+
static decode(bytes: Uint8Array): VersionVector;
|
|
3221
|
+
/**
|
|
3222
|
+
* Get the counter of a peer.
|
|
3223
|
+
* @param {number | bigint | `${number}`} peer_id
|
|
3224
|
+
* @returns {number | undefined}
|
|
3225
|
+
*/
|
|
3226
|
+
get(peer_id: number | bigint | `${number}`): number | undefined;
|
|
3227
|
+
/**
|
|
3228
|
+
* Compare the version vector with another version vector.
|
|
3229
|
+
*
|
|
3230
|
+
* If they are concurrent, return undefined.
|
|
3231
|
+
* @param {VersionVector} other
|
|
3232
|
+
* @returns {number | undefined}
|
|
3233
|
+
*/
|
|
3234
|
+
compare(other: VersionVector): number | undefined;
|
|
3235
|
+
/**
|
|
3236
|
+
* set the exclusive ending point. target id will NOT be included by self
|
|
3237
|
+
* @param {{ peer: PeerID, counter: number }} id
|
|
3238
|
+
*/
|
|
3239
|
+
setEnd(id: { peer: PeerID, counter: number }): void;
|
|
3240
|
+
/**
|
|
3241
|
+
* set the inclusive ending point. target id will be included
|
|
3242
|
+
* @param {{ peer: PeerID, counter: number }} id
|
|
3243
|
+
*/
|
|
3244
|
+
setLast(id: { peer: PeerID, counter: number }): void;
|
|
3245
|
+
/**
|
|
3246
|
+
* @param {PeerID} peer
|
|
3247
|
+
*/
|
|
3248
|
+
remove(peer: PeerID): void;
|
|
3249
|
+
/**
|
|
3250
|
+
* @returns {number}
|
|
3251
|
+
*/
|
|
3252
|
+
length(): number;
|
|
3253
|
+
}
|