loro-crdt 1.5.0 → 1.5.1
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 +8 -0
- package/base64/index.js +3668 -3702
- package/base64/loro_wasm.d.ts +1966 -2276
- package/base64/loro_wasm_bg-c5907423.js +64 -0
- package/bundler/loro_wasm.d.ts +1966 -2276
- package/bundler/loro_wasm_bg.js +3611 -3644
- package/bundler/loro_wasm_bg.wasm +0 -0
- package/bundler/loro_wasm_bg.wasm.d.ts +312 -312
- package/nodejs/loro_wasm.d.ts +1966 -2276
- package/nodejs/loro_wasm.js +3612 -3644
- package/nodejs/loro_wasm_bg.wasm +0 -0
- package/nodejs/loro_wasm_bg.wasm.d.ts +312 -312
- package/package.json +1 -1
- package/web/loro_wasm.d.ts +1999 -2309
- package/web/loro_wasm.js +3624 -3641
- package/web/loro_wasm_bg.wasm +0 -0
- package/web/loro_wasm_bg.wasm.d.ts +312 -312
- package/base64/loro_wasm_bg-536e230f.js +0 -64
package/nodejs/loro_wasm.d.ts
CHANGED
|
@@ -1,42 +1,28 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/**
|
|
4
|
-
* Get the version of Loro
|
|
5
|
-
|
|
6
|
-
*/
|
|
4
|
+
* Get the version of Loro
|
|
5
|
+
*/
|
|
7
6
|
export function LORO_VERSION(): string;
|
|
8
|
-
/**
|
|
9
|
-
*/
|
|
10
7
|
export function run(): void;
|
|
11
|
-
/**
|
|
12
|
-
* @param {({ peer: PeerID, counter: number })[]} frontiers
|
|
13
|
-
* @returns {Uint8Array}
|
|
14
|
-
*/
|
|
15
8
|
export function encodeFrontiers(frontiers: ({ peer: PeerID, counter: number })[]): Uint8Array;
|
|
16
|
-
/**
|
|
17
|
-
* @param {Uint8Array} bytes
|
|
18
|
-
* @returns {{ peer: PeerID, counter: number }[]}
|
|
19
|
-
*/
|
|
20
9
|
export function decodeFrontiers(bytes: Uint8Array): { peer: PeerID, counter: number }[];
|
|
21
10
|
/**
|
|
22
|
-
* Enable debug info of Loro
|
|
23
|
-
*/
|
|
11
|
+
* Enable debug info of Loro
|
|
12
|
+
*/
|
|
24
13
|
export function setDebug(): void;
|
|
25
14
|
/**
|
|
26
|
-
* Decode the metadata of the import blob.
|
|
27
|
-
*
|
|
28
|
-
* This method is useful to get the following metadata of the import blob:
|
|
29
|
-
*
|
|
30
|
-
* - startVersionVector
|
|
31
|
-
* - endVersionVector
|
|
32
|
-
* - startTimestamp
|
|
33
|
-
* - endTimestamp
|
|
34
|
-
* - mode
|
|
35
|
-
* - changeNum
|
|
36
|
-
|
|
37
|
-
* @param {boolean} check_checksum
|
|
38
|
-
* @returns {ImportBlobMetadata}
|
|
39
|
-
*/
|
|
15
|
+
* Decode the metadata of the import blob.
|
|
16
|
+
*
|
|
17
|
+
* This method is useful to get the following metadata of the import blob:
|
|
18
|
+
*
|
|
19
|
+
* - startVersionVector
|
|
20
|
+
* - endVersionVector
|
|
21
|
+
* - startTimestamp
|
|
22
|
+
* - endTimestamp
|
|
23
|
+
* - mode
|
|
24
|
+
* - changeNum
|
|
25
|
+
*/
|
|
40
26
|
export function decodeImportBlobMeta(blob: Uint8Array, check_checksum: boolean): ImportBlobMetadata;
|
|
41
27
|
|
|
42
28
|
/**
|
|
@@ -1420,2520 +1406,2224 @@ interface EphemeralStoreEvent {
|
|
|
1420
1406
|
|
|
1421
1407
|
|
|
1422
1408
|
/**
|
|
1423
|
-
* `Awareness` is a structure that tracks the ephemeral state of peers.
|
|
1424
|
-
*
|
|
1425
|
-
* It can be used to synchronize cursor positions, selections, and the names of the peers.
|
|
1426
|
-
*
|
|
1427
|
-
* The state of a specific peer is expected to be removed after a specified timeout. Use
|
|
1428
|
-
* `remove_outdated` to eliminate outdated states.
|
|
1429
|
-
*/
|
|
1409
|
+
* `Awareness` is a structure that tracks the ephemeral state of peers.
|
|
1410
|
+
*
|
|
1411
|
+
* It can be used to synchronize cursor positions, selections, and the names of the peers.
|
|
1412
|
+
*
|
|
1413
|
+
* The state of a specific peer is expected to be removed after a specified timeout. Use
|
|
1414
|
+
* `remove_outdated` to eliminate outdated states.
|
|
1415
|
+
*/
|
|
1430
1416
|
export class AwarenessWasm {
|
|
1431
1417
|
free(): void;
|
|
1432
|
-
/**
|
|
1433
|
-
* Creates a new `Awareness` instance.
|
|
1434
|
-
*
|
|
1435
|
-
* The `timeout` parameter specifies the duration in milliseconds.
|
|
1436
|
-
* A state of a peer is considered outdated, if the last update of the state of the peer
|
|
1437
|
-
* is older than the `timeout`.
|
|
1438
|
-
|
|
1439
|
-
* @param {number} timeout
|
|
1440
|
-
*/
|
|
1418
|
+
/**
|
|
1419
|
+
* Creates a new `Awareness` instance.
|
|
1420
|
+
*
|
|
1421
|
+
* The `timeout` parameter specifies the duration in milliseconds.
|
|
1422
|
+
* A state of a peer is considered outdated, if the last update of the state of the peer
|
|
1423
|
+
* is older than the `timeout`.
|
|
1424
|
+
*/
|
|
1441
1425
|
constructor(peer: number | bigint | `${number}`, timeout: number);
|
|
1442
|
-
/**
|
|
1443
|
-
* Encodes the state of the given peers.
|
|
1444
|
-
|
|
1445
|
-
* @returns {Uint8Array}
|
|
1446
|
-
*/
|
|
1426
|
+
/**
|
|
1427
|
+
* Encodes the state of the given peers.
|
|
1428
|
+
*/
|
|
1447
1429
|
encode(peers: Array<any>): Uint8Array;
|
|
1448
|
-
/**
|
|
1449
|
-
* Encodes the state of all peers.
|
|
1450
|
-
|
|
1451
|
-
*/
|
|
1430
|
+
/**
|
|
1431
|
+
* Encodes the state of all peers.
|
|
1432
|
+
*/
|
|
1452
1433
|
encodeAll(): Uint8Array;
|
|
1453
|
-
/**
|
|
1454
|
-
* Applies the encoded state of peers.
|
|
1455
|
-
*
|
|
1456
|
-
* Each peer's deletion countdown will be reset upon update, requiring them to pass through the `timeout`
|
|
1457
|
-
* interval again before being eligible for deletion.
|
|
1458
|
-
|
|
1459
|
-
* @returns {{ updated: PeerID[], added: PeerID[] }}
|
|
1460
|
-
*/
|
|
1434
|
+
/**
|
|
1435
|
+
* Applies the encoded state of peers.
|
|
1436
|
+
*
|
|
1437
|
+
* Each peer's deletion countdown will be reset upon update, requiring them to pass through the `timeout`
|
|
1438
|
+
* interval again before being eligible for deletion.
|
|
1439
|
+
*/
|
|
1461
1440
|
apply(encoded_peers_info: Uint8Array): { updated: PeerID[], added: PeerID[] };
|
|
1462
|
-
/**
|
|
1463
|
-
* Get the PeerID of the local peer.
|
|
1464
|
-
|
|
1465
|
-
*/
|
|
1441
|
+
/**
|
|
1442
|
+
* Get the PeerID of the local peer.
|
|
1443
|
+
*/
|
|
1466
1444
|
peer(): PeerID;
|
|
1467
|
-
/**
|
|
1468
|
-
* Get the timestamp of the state of a given peer.
|
|
1469
|
-
|
|
1470
|
-
* @returns {number | undefined}
|
|
1471
|
-
*/
|
|
1445
|
+
/**
|
|
1446
|
+
* Get the timestamp of the state of a given peer.
|
|
1447
|
+
*/
|
|
1472
1448
|
getTimestamp(peer: number | bigint | `${number}`): number | undefined;
|
|
1473
|
-
/**
|
|
1474
|
-
* Remove the states of outdated peers.
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
* @returns {number}
|
|
1481
|
-
*/
|
|
1449
|
+
/**
|
|
1450
|
+
* Remove the states of outdated peers.
|
|
1451
|
+
*/
|
|
1452
|
+
removeOutdated(): PeerID[];
|
|
1453
|
+
/**
|
|
1454
|
+
* Get the number of peers.
|
|
1455
|
+
*/
|
|
1482
1456
|
length(): number;
|
|
1483
|
-
/**
|
|
1484
|
-
* If the state is empty.
|
|
1485
|
-
|
|
1486
|
-
*/
|
|
1457
|
+
/**
|
|
1458
|
+
* If the state is empty.
|
|
1459
|
+
*/
|
|
1487
1460
|
isEmpty(): boolean;
|
|
1488
|
-
/**
|
|
1489
|
-
* Get all the peers
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
peers(): (PeerID)[];
|
|
1461
|
+
/**
|
|
1462
|
+
* Get all the peers
|
|
1463
|
+
*/
|
|
1464
|
+
peers(): PeerID[];
|
|
1493
1465
|
}
|
|
1494
|
-
/**
|
|
1495
|
-
*/
|
|
1496
1466
|
export class ChangeModifier {
|
|
1467
|
+
private constructor();
|
|
1497
1468
|
free(): void;
|
|
1498
|
-
/**
|
|
1499
|
-
* @param {string} message
|
|
1500
|
-
* @returns {ChangeModifier}
|
|
1501
|
-
*/
|
|
1502
1469
|
setMessage(message: string): ChangeModifier;
|
|
1503
|
-
/**
|
|
1504
|
-
* @param {number} timestamp
|
|
1505
|
-
* @returns {ChangeModifier}
|
|
1506
|
-
*/
|
|
1507
1470
|
setTimestamp(timestamp: number): ChangeModifier;
|
|
1508
1471
|
}
|
|
1509
1472
|
/**
|
|
1510
|
-
* Cursor is a stable position representation in the doc.
|
|
1511
|
-
* When expressing the position of a cursor, using "index" can be unstable
|
|
1512
|
-
* because the cursor's position may change due to other deletions and insertions,
|
|
1513
|
-
* requiring updates with each edit. To stably represent a position or range within
|
|
1514
|
-
* a list structure, we can utilize the ID of each item/character on List CRDT or
|
|
1515
|
-
* Text CRDT for expression.
|
|
1516
|
-
*
|
|
1517
|
-
* Loro optimizes State metadata by not storing the IDs of deleted elements. This
|
|
1518
|
-
* approach complicates tracking cursors since they rely on these IDs. The solution
|
|
1519
|
-
* recalculates position by replaying relevant history to update cursors
|
|
1520
|
-
* accurately. To minimize the performance impact of history replay, the system
|
|
1521
|
-
* updates cursor info to reference only the IDs of currently present elements,
|
|
1522
|
-
* thereby reducing the need for replay.
|
|
1523
|
-
*
|
|
1524
|
-
* @example
|
|
1525
|
-
* ```ts
|
|
1526
|
-
*
|
|
1527
|
-
* const doc = new LoroDoc();
|
|
1528
|
-
* const text = doc.getText("text");
|
|
1529
|
-
* text.insert(0, "123");
|
|
1530
|
-
* const pos0 = text.getCursor(0, 0);
|
|
1531
|
-
* {
|
|
1532
|
-
* const ans = doc.getCursorPos(pos0!);
|
|
1533
|
-
* expect(ans.offset).toBe(0);
|
|
1534
|
-
* }
|
|
1535
|
-
* text.insert(0, "1");
|
|
1536
|
-
* {
|
|
1537
|
-
* const ans = doc.getCursorPos(pos0!);
|
|
1538
|
-
* expect(ans.offset).toBe(1);
|
|
1539
|
-
* }
|
|
1540
|
-
* ```
|
|
1541
|
-
*/
|
|
1473
|
+
* Cursor is a stable position representation in the doc.
|
|
1474
|
+
* When expressing the position of a cursor, using "index" can be unstable
|
|
1475
|
+
* because the cursor's position may change due to other deletions and insertions,
|
|
1476
|
+
* requiring updates with each edit. To stably represent a position or range within
|
|
1477
|
+
* a list structure, we can utilize the ID of each item/character on List CRDT or
|
|
1478
|
+
* Text CRDT for expression.
|
|
1479
|
+
*
|
|
1480
|
+
* Loro optimizes State metadata by not storing the IDs of deleted elements. This
|
|
1481
|
+
* approach complicates tracking cursors since they rely on these IDs. The solution
|
|
1482
|
+
* recalculates position by replaying relevant history to update cursors
|
|
1483
|
+
* accurately. To minimize the performance impact of history replay, the system
|
|
1484
|
+
* updates cursor info to reference only the IDs of currently present elements,
|
|
1485
|
+
* thereby reducing the need for replay.
|
|
1486
|
+
*
|
|
1487
|
+
* @example
|
|
1488
|
+
* ```ts
|
|
1489
|
+
*
|
|
1490
|
+
* const doc = new LoroDoc();
|
|
1491
|
+
* const text = doc.getText("text");
|
|
1492
|
+
* text.insert(0, "123");
|
|
1493
|
+
* const pos0 = text.getCursor(0, 0);
|
|
1494
|
+
* {
|
|
1495
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
1496
|
+
* expect(ans.offset).toBe(0);
|
|
1497
|
+
* }
|
|
1498
|
+
* text.insert(0, "1");
|
|
1499
|
+
* {
|
|
1500
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
1501
|
+
* expect(ans.offset).toBe(1);
|
|
1502
|
+
* }
|
|
1503
|
+
* ```
|
|
1504
|
+
*/
|
|
1542
1505
|
export class Cursor {
|
|
1506
|
+
private constructor();
|
|
1543
1507
|
free(): void;
|
|
1544
|
-
/**
|
|
1545
|
-
* Get the id of the given container.
|
|
1546
|
-
|
|
1547
|
-
*/
|
|
1508
|
+
/**
|
|
1509
|
+
* Get the id of the given container.
|
|
1510
|
+
*/
|
|
1548
1511
|
containerId(): ContainerID;
|
|
1549
|
-
/**
|
|
1550
|
-
* Get the ID that represents the position.
|
|
1551
|
-
*
|
|
1552
|
-
* It can be undefined if it's not bind into a specific ID.
|
|
1553
|
-
|
|
1554
|
-
*/
|
|
1512
|
+
/**
|
|
1513
|
+
* Get the ID that represents the position.
|
|
1514
|
+
*
|
|
1515
|
+
* It can be undefined if it's not bind into a specific ID.
|
|
1516
|
+
*/
|
|
1555
1517
|
pos(): { peer: PeerID, counter: number } | undefined;
|
|
1556
|
-
/**
|
|
1557
|
-
* Get which side of the character/list item the cursor is on.
|
|
1558
|
-
|
|
1559
|
-
*/
|
|
1518
|
+
/**
|
|
1519
|
+
* Get which side of the character/list item the cursor is on.
|
|
1520
|
+
*/
|
|
1560
1521
|
side(): Side;
|
|
1561
|
-
/**
|
|
1562
|
-
* Encode the cursor into a Uint8Array.
|
|
1563
|
-
|
|
1564
|
-
*/
|
|
1522
|
+
/**
|
|
1523
|
+
* Encode the cursor into a Uint8Array.
|
|
1524
|
+
*/
|
|
1565
1525
|
encode(): Uint8Array;
|
|
1566
|
-
/**
|
|
1567
|
-
* Decode the cursor from a Uint8Array.
|
|
1568
|
-
|
|
1569
|
-
* @returns {Cursor}
|
|
1570
|
-
*/
|
|
1526
|
+
/**
|
|
1527
|
+
* Decode the cursor from a Uint8Array.
|
|
1528
|
+
*/
|
|
1571
1529
|
static decode(data: Uint8Array): Cursor;
|
|
1572
|
-
/**
|
|
1573
|
-
* "Cursor"
|
|
1574
|
-
|
|
1575
|
-
*/
|
|
1530
|
+
/**
|
|
1531
|
+
* "Cursor"
|
|
1532
|
+
*/
|
|
1576
1533
|
kind(): any;
|
|
1577
1534
|
}
|
|
1578
|
-
/**
|
|
1579
|
-
*/
|
|
1580
1535
|
export class EphemeralStoreWasm {
|
|
1581
1536
|
free(): void;
|
|
1582
|
-
/**
|
|
1583
|
-
* Creates a new `EphemeralStore` instance.
|
|
1584
|
-
*
|
|
1585
|
-
* The `timeout` parameter specifies the duration in milliseconds.
|
|
1586
|
-
* A state of a peer is considered outdated, if the last update of the state of the peer
|
|
1587
|
-
* is older than the `timeout`.
|
|
1588
|
-
|
|
1589
|
-
*/
|
|
1537
|
+
/**
|
|
1538
|
+
* Creates a new `EphemeralStore` instance.
|
|
1539
|
+
*
|
|
1540
|
+
* The `timeout` parameter specifies the duration in milliseconds.
|
|
1541
|
+
* A state of a peer is considered outdated, if the last update of the state of the peer
|
|
1542
|
+
* is older than the `timeout`.
|
|
1543
|
+
*/
|
|
1590
1544
|
constructor(timeout: number);
|
|
1591
|
-
/**
|
|
1592
|
-
* @param {string} key
|
|
1593
|
-
* @param {any} value
|
|
1594
|
-
*/
|
|
1595
1545
|
set(key: string, value: any): void;
|
|
1596
|
-
/**
|
|
1597
|
-
* @param {string} key
|
|
1598
|
-
*/
|
|
1599
1546
|
delete(key: string): void;
|
|
1600
|
-
/**
|
|
1601
|
-
* @param {string} key
|
|
1602
|
-
* @returns {any}
|
|
1603
|
-
*/
|
|
1604
1547
|
get(key: string): any;
|
|
1605
|
-
/**
|
|
1606
|
-
* @returns {any}
|
|
1607
|
-
*/
|
|
1608
1548
|
getAllStates(): any;
|
|
1609
|
-
/**
|
|
1610
|
-
* @param {string} key
|
|
1611
|
-
* @returns {Uint8Array}
|
|
1612
|
-
*/
|
|
1613
1549
|
encode(key: string): Uint8Array;
|
|
1614
|
-
/**
|
|
1615
|
-
* @returns {Uint8Array}
|
|
1616
|
-
*/
|
|
1617
1550
|
encodeAll(): Uint8Array;
|
|
1618
|
-
/**
|
|
1619
|
-
* @param {Uint8Array} data
|
|
1620
|
-
*/
|
|
1621
1551
|
apply(data: Uint8Array): void;
|
|
1622
|
-
/**
|
|
1623
|
-
*/
|
|
1624
1552
|
removeOutdated(): void;
|
|
1625
|
-
/**
|
|
1626
|
-
* If the state is empty.
|
|
1627
|
-
|
|
1628
|
-
*/
|
|
1553
|
+
/**
|
|
1554
|
+
* If the state is empty.
|
|
1555
|
+
*/
|
|
1629
1556
|
isEmpty(): boolean;
|
|
1630
|
-
|
|
1631
|
-
* @returns {(string)[]}
|
|
1632
|
-
*/
|
|
1633
|
-
keys(): (string)[];
|
|
1557
|
+
keys(): string[];
|
|
1634
1558
|
}
|
|
1635
1559
|
/**
|
|
1636
|
-
* The handler of a counter container.
|
|
1637
|
-
*/
|
|
1560
|
+
* The handler of a counter container.
|
|
1561
|
+
*/
|
|
1638
1562
|
export class LoroCounter {
|
|
1639
1563
|
free(): void;
|
|
1640
|
-
/**
|
|
1641
|
-
* Create a new LoroCounter.
|
|
1642
|
-
*/
|
|
1564
|
+
/**
|
|
1565
|
+
* Create a new LoroCounter.
|
|
1566
|
+
*/
|
|
1643
1567
|
constructor();
|
|
1644
|
-
/**
|
|
1645
|
-
* "Counter"
|
|
1646
|
-
|
|
1647
|
-
*/
|
|
1568
|
+
/**
|
|
1569
|
+
* "Counter"
|
|
1570
|
+
*/
|
|
1648
1571
|
kind(): 'Counter';
|
|
1649
|
-
/**
|
|
1650
|
-
* Increment the counter by the given value.
|
|
1651
|
-
|
|
1652
|
-
*/
|
|
1572
|
+
/**
|
|
1573
|
+
* Increment the counter by the given value.
|
|
1574
|
+
*/
|
|
1653
1575
|
increment(value: number): void;
|
|
1654
|
-
/**
|
|
1655
|
-
* Decrement the counter by the given value.
|
|
1656
|
-
|
|
1657
|
-
*/
|
|
1576
|
+
/**
|
|
1577
|
+
* Decrement the counter by the given value.
|
|
1578
|
+
*/
|
|
1658
1579
|
decrement(value: number): void;
|
|
1659
|
-
/**
|
|
1660
|
-
* Subscribe to the changes of the counter.
|
|
1661
|
-
|
|
1662
|
-
* @returns {any}
|
|
1663
|
-
*/
|
|
1580
|
+
/**
|
|
1581
|
+
* Subscribe to the changes of the counter.
|
|
1582
|
+
*/
|
|
1664
1583
|
subscribe(f: Function): any;
|
|
1665
|
-
/**
|
|
1666
|
-
* Get the parent container of the counter container.
|
|
1667
|
-
*
|
|
1668
|
-
* - The parent container of the root counter is `undefined`.
|
|
1669
|
-
* - The object returned is a new js object each time because it need to cross
|
|
1670
|
-
* the WASM boundary.
|
|
1671
|
-
|
|
1672
|
-
*/
|
|
1584
|
+
/**
|
|
1585
|
+
* Get the parent container of the counter container.
|
|
1586
|
+
*
|
|
1587
|
+
* - The parent container of the root counter is `undefined`.
|
|
1588
|
+
* - The object returned is a new js object each time because it need to cross
|
|
1589
|
+
* the WASM boundary.
|
|
1590
|
+
*/
|
|
1673
1591
|
parent(): Container | undefined;
|
|
1674
|
-
/**
|
|
1675
|
-
* Whether the container is attached to a docuemnt.
|
|
1676
|
-
*
|
|
1677
|
-
* If it's detached, the operations on the container will not be persisted.
|
|
1678
|
-
|
|
1679
|
-
*/
|
|
1592
|
+
/**
|
|
1593
|
+
* Whether the container is attached to a docuemnt.
|
|
1594
|
+
*
|
|
1595
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
1596
|
+
*/
|
|
1680
1597
|
isAttached(): boolean;
|
|
1681
|
-
/**
|
|
1682
|
-
* Get the attached container associated with this.
|
|
1683
|
-
*
|
|
1684
|
-
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
1685
|
-
|
|
1686
|
-
*/
|
|
1598
|
+
/**
|
|
1599
|
+
* Get the attached container associated with this.
|
|
1600
|
+
*
|
|
1601
|
+
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
1602
|
+
*/
|
|
1687
1603
|
getAttached(): LoroTree | undefined;
|
|
1688
|
-
/**
|
|
1689
|
-
* Get the value of the counter.
|
|
1690
|
-
|
|
1691
|
-
*/
|
|
1604
|
+
/**
|
|
1605
|
+
* Get the value of the counter.
|
|
1606
|
+
*/
|
|
1692
1607
|
getShallowValue(): number;
|
|
1693
|
-
/**
|
|
1694
|
-
* The container id of this handler.
|
|
1695
|
-
*/
|
|
1608
|
+
/**
|
|
1609
|
+
* The container id of this handler.
|
|
1610
|
+
*/
|
|
1696
1611
|
readonly id: ContainerID;
|
|
1697
|
-
/**
|
|
1698
|
-
* Get the value of the counter.
|
|
1699
|
-
*/
|
|
1612
|
+
/**
|
|
1613
|
+
* Get the value of the counter.
|
|
1614
|
+
*/
|
|
1700
1615
|
readonly value: number;
|
|
1701
1616
|
}
|
|
1702
1617
|
/**
|
|
1703
|
-
* The CRDTs document. Loro supports different CRDTs include [**List**](LoroList),
|
|
1704
|
-
* [**RichText**](LoroText), [**Map**](LoroMap) and [**Movable Tree**](LoroTree),
|
|
1705
|
-
* you could build all kind of applications by these.
|
|
1706
|
-
*
|
|
1707
|
-
* **Important:** Loro is a pure library and does not handle network protocols.
|
|
1708
|
-
* It is the responsibility of the user to manage the storage, loading, and synchronization
|
|
1709
|
-
* of the bytes exported by Loro in a manner suitable for their specific environment.
|
|
1710
|
-
*
|
|
1711
|
-
* @example
|
|
1712
|
-
* ```ts
|
|
1713
|
-
* import { LoroDoc } from "loro-crdt"
|
|
1714
|
-
*
|
|
1715
|
-
* const loro = new LoroDoc();
|
|
1716
|
-
* const text = loro.getText("text");
|
|
1717
|
-
* const list = loro.getList("list");
|
|
1718
|
-
* const map = loro.getMap("Map");
|
|
1719
|
-
* const tree = loro.getTree("tree");
|
|
1720
|
-
* ```
|
|
1721
|
-
*/
|
|
1618
|
+
* The CRDTs document. Loro supports different CRDTs include [**List**](LoroList),
|
|
1619
|
+
* [**RichText**](LoroText), [**Map**](LoroMap) and [**Movable Tree**](LoroTree),
|
|
1620
|
+
* you could build all kind of applications by these.
|
|
1621
|
+
*
|
|
1622
|
+
* **Important:** Loro is a pure library and does not handle network protocols.
|
|
1623
|
+
* It is the responsibility of the user to manage the storage, loading, and synchronization
|
|
1624
|
+
* of the bytes exported by Loro in a manner suitable for their specific environment.
|
|
1625
|
+
*
|
|
1626
|
+
* @example
|
|
1627
|
+
* ```ts
|
|
1628
|
+
* import { LoroDoc } from "loro-crdt"
|
|
1629
|
+
*
|
|
1630
|
+
* const loro = new LoroDoc();
|
|
1631
|
+
* const text = loro.getText("text");
|
|
1632
|
+
* const list = loro.getList("list");
|
|
1633
|
+
* const map = loro.getMap("Map");
|
|
1634
|
+
* const tree = loro.getTree("tree");
|
|
1635
|
+
* ```
|
|
1636
|
+
*/
|
|
1722
1637
|
export class LoroDoc {
|
|
1723
1638
|
free(): void;
|
|
1724
|
-
/**
|
|
1725
|
-
* Create a new loro document.
|
|
1726
|
-
*
|
|
1727
|
-
* New document will have a random peer id.
|
|
1728
|
-
*/
|
|
1639
|
+
/**
|
|
1640
|
+
* Create a new loro document.
|
|
1641
|
+
*
|
|
1642
|
+
* New document will have a random peer id.
|
|
1643
|
+
*/
|
|
1729
1644
|
constructor();
|
|
1730
|
-
/**
|
|
1731
|
-
* Enables editing in detached mode, which is disabled by default.
|
|
1732
|
-
*
|
|
1733
|
-
* The doc enter detached mode after calling `detach` or checking out a non-latest version.
|
|
1734
|
-
*
|
|
1735
|
-
* # Important Notes:
|
|
1736
|
-
*
|
|
1737
|
-
* - This mode uses a different PeerID for each checkout.
|
|
1738
|
-
* - Ensure no concurrent operations share the same PeerID if set manually.
|
|
1739
|
-
* - Importing does not affect the document's state or version; changes are
|
|
1740
|
-
* recorded in the [OpLog] only. Call `checkout` to apply changes.
|
|
1741
|
-
|
|
1742
|
-
*/
|
|
1645
|
+
/**
|
|
1646
|
+
* Enables editing in detached mode, which is disabled by default.
|
|
1647
|
+
*
|
|
1648
|
+
* The doc enter detached mode after calling `detach` or checking out a non-latest version.
|
|
1649
|
+
*
|
|
1650
|
+
* # Important Notes:
|
|
1651
|
+
*
|
|
1652
|
+
* - This mode uses a different PeerID for each checkout.
|
|
1653
|
+
* - Ensure no concurrent operations share the same PeerID if set manually.
|
|
1654
|
+
* - Importing does not affect the document's state or version; changes are
|
|
1655
|
+
* recorded in the [OpLog] only. Call `checkout` to apply changes.
|
|
1656
|
+
*/
|
|
1743
1657
|
setDetachedEditing(enable: boolean): void;
|
|
1744
|
-
/**
|
|
1745
|
-
* Whether the editing is enabled in detached mode.
|
|
1746
|
-
*
|
|
1747
|
-
* The doc enter detached mode after calling `detach` or checking out a non-latest version.
|
|
1748
|
-
*
|
|
1749
|
-
* # Important Notes:
|
|
1750
|
-
*
|
|
1751
|
-
* - This mode uses a different PeerID for each checkout.
|
|
1752
|
-
* - Ensure no concurrent operations share the same PeerID if set manually.
|
|
1753
|
-
* - Importing does not affect the document's state or version; changes are
|
|
1754
|
-
* recorded in the [OpLog] only. Call `checkout` to apply changes.
|
|
1755
|
-
|
|
1756
|
-
*/
|
|
1658
|
+
/**
|
|
1659
|
+
* Whether the editing is enabled in detached mode.
|
|
1660
|
+
*
|
|
1661
|
+
* The doc enter detached mode after calling `detach` or checking out a non-latest version.
|
|
1662
|
+
*
|
|
1663
|
+
* # Important Notes:
|
|
1664
|
+
*
|
|
1665
|
+
* - This mode uses a different PeerID for each checkout.
|
|
1666
|
+
* - Ensure no concurrent operations share the same PeerID if set manually.
|
|
1667
|
+
* - Importing does not affect the document's state or version; changes are
|
|
1668
|
+
* recorded in the [OpLog] only. Call `checkout` to apply changes.
|
|
1669
|
+
*/
|
|
1757
1670
|
isDetachedEditingEnabled(): boolean;
|
|
1758
|
-
/**
|
|
1759
|
-
* Set whether to record the timestamp of each change. Default is `false`.
|
|
1760
|
-
*
|
|
1761
|
-
* If enabled, the Unix timestamp (in seconds) will be recorded for each change automatically.
|
|
1762
|
-
*
|
|
1763
|
-
* You can also set each timestamp manually when you commit a change.
|
|
1764
|
-
* The timestamp manually set will override the automatic one.
|
|
1765
|
-
*
|
|
1766
|
-
* NOTE: Timestamps are forced to be in ascending order in the OpLog's history.
|
|
1767
|
-
* If you commit a new change with a timestamp that is less than the existing one,
|
|
1768
|
-
* the largest existing timestamp will be used instead.
|
|
1769
|
-
|
|
1770
|
-
*/
|
|
1671
|
+
/**
|
|
1672
|
+
* Set whether to record the timestamp of each change. Default is `false`.
|
|
1673
|
+
*
|
|
1674
|
+
* If enabled, the Unix timestamp (in seconds) will be recorded for each change automatically.
|
|
1675
|
+
*
|
|
1676
|
+
* You can also set each timestamp manually when you commit a change.
|
|
1677
|
+
* The timestamp manually set will override the automatic one.
|
|
1678
|
+
*
|
|
1679
|
+
* NOTE: Timestamps are forced to be in ascending order in the OpLog's history.
|
|
1680
|
+
* If you commit a new change with a timestamp that is less than the existing one,
|
|
1681
|
+
* the largest existing timestamp will be used instead.
|
|
1682
|
+
*/
|
|
1771
1683
|
setRecordTimestamp(auto_record: boolean): void;
|
|
1772
|
-
/**
|
|
1773
|
-
* If two continuous local changes are within (<=) the interval(**in seconds**), they will be merged into one change.
|
|
1774
|
-
*
|
|
1775
|
-
* The default value is 1_000 seconds.
|
|
1776
|
-
*
|
|
1777
|
-
* By default, we record timestamps in seconds for each change. So if the merge interval is 1, and changes A and B
|
|
1778
|
-
* have timestamps of 3 and 4 respectively, then they will be merged into one change
|
|
1779
|
-
|
|
1780
|
-
*/
|
|
1684
|
+
/**
|
|
1685
|
+
* If two continuous local changes are within (<=) the interval(**in seconds**), they will be merged into one change.
|
|
1686
|
+
*
|
|
1687
|
+
* The default value is 1_000 seconds.
|
|
1688
|
+
*
|
|
1689
|
+
* By default, we record timestamps in seconds for each change. So if the merge interval is 1, and changes A and B
|
|
1690
|
+
* have timestamps of 3 and 4 respectively, then they will be merged into one change
|
|
1691
|
+
*/
|
|
1781
1692
|
setChangeMergeInterval(interval: number): void;
|
|
1782
|
-
/**
|
|
1783
|
-
* Set the rich text format configuration of the document.
|
|
1784
|
-
*
|
|
1785
|
-
* You need to config it if you use rich text `mark` method.
|
|
1786
|
-
* Specifically, you need to config the `expand` property of each style.
|
|
1787
|
-
*
|
|
1788
|
-
* Expand is used to specify the behavior of expanding when new text is inserted at the
|
|
1789
|
-
* beginning or end of the style.
|
|
1790
|
-
*
|
|
1791
|
-
* You can specify the `expand` option to set the behavior when inserting text at the boundary of the range.
|
|
1792
|
-
*
|
|
1793
|
-
* - `after`(default): when inserting text right after the given range, the mark will be expanded to include the inserted text
|
|
1794
|
-
* - `before`: when inserting text right before the given range, the mark will be expanded to include the inserted text
|
|
1795
|
-
* - `none`: the mark will not be expanded to include the inserted text at the boundaries
|
|
1796
|
-
* - `both`: when inserting text either right before or right after the given range, the mark will be expanded to include the inserted text
|
|
1797
|
-
*
|
|
1798
|
-
* @example
|
|
1799
|
-
* ```ts
|
|
1800
|
-
* const doc = new LoroDoc();
|
|
1801
|
-
* doc.configTextStyle({
|
|
1802
|
-
* bold: { expand: "after" },
|
|
1803
|
-
* link: { expand: "before" }
|
|
1804
|
-
* });
|
|
1805
|
-
* const text = doc.getText("text");
|
|
1806
|
-
* text.insert(0, "Hello World!");
|
|
1807
|
-
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
1808
|
-
* expect(text.toDelta()).toStrictEqual([
|
|
1809
|
-
* {
|
|
1810
|
-
* insert: "Hello",
|
|
1811
|
-
* attributes: {
|
|
1812
|
-
* bold: true,
|
|
1813
|
-
* },
|
|
1814
|
-
* },
|
|
1815
|
-
* {
|
|
1816
|
-
* insert: " World!",
|
|
1817
|
-
* },
|
|
1818
|
-
* ] as Delta<string>[]);
|
|
1819
|
-
* ```
|
|
1820
|
-
|
|
1821
|
-
*/
|
|
1693
|
+
/**
|
|
1694
|
+
* Set the rich text format configuration of the document.
|
|
1695
|
+
*
|
|
1696
|
+
* You need to config it if you use rich text `mark` method.
|
|
1697
|
+
* Specifically, you need to config the `expand` property of each style.
|
|
1698
|
+
*
|
|
1699
|
+
* Expand is used to specify the behavior of expanding when new text is inserted at the
|
|
1700
|
+
* beginning or end of the style.
|
|
1701
|
+
*
|
|
1702
|
+
* You can specify the `expand` option to set the behavior when inserting text at the boundary of the range.
|
|
1703
|
+
*
|
|
1704
|
+
* - `after`(default): when inserting text right after the given range, the mark will be expanded to include the inserted text
|
|
1705
|
+
* - `before`: when inserting text right before the given range, the mark will be expanded to include the inserted text
|
|
1706
|
+
* - `none`: the mark will not be expanded to include the inserted text at the boundaries
|
|
1707
|
+
* - `both`: when inserting text either right before or right after the given range, the mark will be expanded to include the inserted text
|
|
1708
|
+
*
|
|
1709
|
+
* @example
|
|
1710
|
+
* ```ts
|
|
1711
|
+
* const doc = new LoroDoc();
|
|
1712
|
+
* doc.configTextStyle({
|
|
1713
|
+
* bold: { expand: "after" },
|
|
1714
|
+
* link: { expand: "before" }
|
|
1715
|
+
* });
|
|
1716
|
+
* const text = doc.getText("text");
|
|
1717
|
+
* text.insert(0, "Hello World!");
|
|
1718
|
+
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
1719
|
+
* expect(text.toDelta()).toStrictEqual([
|
|
1720
|
+
* {
|
|
1721
|
+
* insert: "Hello",
|
|
1722
|
+
* attributes: {
|
|
1723
|
+
* bold: true,
|
|
1724
|
+
* },
|
|
1725
|
+
* },
|
|
1726
|
+
* {
|
|
1727
|
+
* insert: " World!",
|
|
1728
|
+
* },
|
|
1729
|
+
* ] as Delta<string>[]);
|
|
1730
|
+
* ```
|
|
1731
|
+
*/
|
|
1822
1732
|
configTextStyle(styles: {[key: string]: { expand: 'before'|'after'|'none'|'both' }}): void;
|
|
1823
|
-
/**
|
|
1824
|
-
* Configures the default text style for the document.
|
|
1825
|
-
*
|
|
1826
|
-
* This method sets the default text style configuration for the document when using LoroText.
|
|
1827
|
-
* If `None` is provided, the default style is reset.
|
|
1828
|
-
|
|
1829
|
-
*/
|
|
1733
|
+
/**
|
|
1734
|
+
* Configures the default text style for the document.
|
|
1735
|
+
*
|
|
1736
|
+
* This method sets the default text style configuration for the document when using LoroText.
|
|
1737
|
+
* If `None` is provided, the default style is reset.
|
|
1738
|
+
*/
|
|
1830
1739
|
configDefaultTextStyle(style: { expand: 'before'|'after'|'none'|'both' } | undefined): void;
|
|
1831
|
-
/**
|
|
1832
|
-
* Create a loro document from the snapshot.
|
|
1833
|
-
*
|
|
1834
|
-
* @see You can learn more [here](https://loro.dev/docs/tutorial/encoding).
|
|
1835
|
-
*
|
|
1836
|
-
* @example
|
|
1837
|
-
* ```ts
|
|
1838
|
-
* import { LoroDoc } from "loro-crdt"
|
|
1839
|
-
*
|
|
1840
|
-
* const doc = new LoroDoc();
|
|
1841
|
-
* // ...
|
|
1842
|
-
* const bytes = doc.export({ mode: "snapshot" });
|
|
1843
|
-
* const loro = LoroDoc.fromSnapshot(bytes);
|
|
1844
|
-
* ```
|
|
1845
|
-
|
|
1846
|
-
* @returns {LoroDoc}
|
|
1847
|
-
*/
|
|
1740
|
+
/**
|
|
1741
|
+
* Create a loro document from the snapshot.
|
|
1742
|
+
*
|
|
1743
|
+
* @see You can learn more [here](https://loro.dev/docs/tutorial/encoding).
|
|
1744
|
+
*
|
|
1745
|
+
* @example
|
|
1746
|
+
* ```ts
|
|
1747
|
+
* import { LoroDoc } from "loro-crdt"
|
|
1748
|
+
*
|
|
1749
|
+
* const doc = new LoroDoc();
|
|
1750
|
+
* // ...
|
|
1751
|
+
* const bytes = doc.export({ mode: "snapshot" });
|
|
1752
|
+
* const loro = LoroDoc.fromSnapshot(bytes);
|
|
1753
|
+
* ```
|
|
1754
|
+
*/
|
|
1848
1755
|
static fromSnapshot(snapshot: Uint8Array): LoroDoc;
|
|
1849
|
-
/**
|
|
1850
|
-
* Attach the document state to the latest known version.
|
|
1851
|
-
*
|
|
1852
|
-
* > The document becomes detached during a `checkout` operation.
|
|
1853
|
-
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
1854
|
-
* > In a detached state, the document is not editable, and any `import` operations will be
|
|
1855
|
-
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
1856
|
-
*
|
|
1857
|
-
* This method has the same effect as invoking `checkoutToLatest`.
|
|
1858
|
-
*
|
|
1859
|
-
* @example
|
|
1860
|
-
* ```ts
|
|
1861
|
-
* import { LoroDoc } from "loro-crdt";
|
|
1862
|
-
*
|
|
1863
|
-
* const doc = new LoroDoc();
|
|
1864
|
-
* const text = doc.getText("text");
|
|
1865
|
-
* const frontiers = doc.frontiers();
|
|
1866
|
-
* text.insert(0, "Hello World!");
|
|
1867
|
-
* doc.checkout(frontiers);
|
|
1868
|
-
* // you need call `attach()` or `checkoutToLatest()` before changing the doc.
|
|
1869
|
-
* doc.attach();
|
|
1870
|
-
* text.insert(0, "Hi");
|
|
1871
|
-
* ```
|
|
1872
|
-
*/
|
|
1756
|
+
/**
|
|
1757
|
+
* Attach the document state to the latest known version.
|
|
1758
|
+
*
|
|
1759
|
+
* > The document becomes detached during a `checkout` operation.
|
|
1760
|
+
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
1761
|
+
* > In a detached state, the document is not editable, and any `import` operations will be
|
|
1762
|
+
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
1763
|
+
*
|
|
1764
|
+
* This method has the same effect as invoking `checkoutToLatest`.
|
|
1765
|
+
*
|
|
1766
|
+
* @example
|
|
1767
|
+
* ```ts
|
|
1768
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1769
|
+
*
|
|
1770
|
+
* const doc = new LoroDoc();
|
|
1771
|
+
* const text = doc.getText("text");
|
|
1772
|
+
* const frontiers = doc.frontiers();
|
|
1773
|
+
* text.insert(0, "Hello World!");
|
|
1774
|
+
* doc.checkout(frontiers);
|
|
1775
|
+
* // you need call `attach()` or `checkoutToLatest()` before changing the doc.
|
|
1776
|
+
* doc.attach();
|
|
1777
|
+
* text.insert(0, "Hi");
|
|
1778
|
+
* ```
|
|
1779
|
+
*/
|
|
1873
1780
|
attach(): void;
|
|
1874
|
-
/**
|
|
1875
|
-
* `detached` indicates that the `DocState` is not synchronized with the latest version of `OpLog`.
|
|
1876
|
-
*
|
|
1877
|
-
* > The document becomes detached during a `checkout` operation.
|
|
1878
|
-
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
1879
|
-
* > In a detached state, the document is not editable by default, and any `import` operations will be
|
|
1880
|
-
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
1881
|
-
*
|
|
1882
|
-
* @example
|
|
1883
|
-
* ```ts
|
|
1884
|
-
* import { LoroDoc } from "loro-crdt";
|
|
1885
|
-
*
|
|
1886
|
-
* const doc = new LoroDoc();
|
|
1887
|
-
* const text = doc.getText("text");
|
|
1888
|
-
* const frontiers = doc.frontiers();
|
|
1889
|
-
* text.insert(0, "Hello World!");
|
|
1890
|
-
* console.log(doc.isDetached()); // false
|
|
1891
|
-
* doc.checkout(frontiers);
|
|
1892
|
-
* console.log(doc.isDetached()); // true
|
|
1893
|
-
* doc.attach();
|
|
1894
|
-
* console.log(doc.isDetached()); // false
|
|
1895
|
-
* ```
|
|
1896
|
-
|
|
1897
|
-
*/
|
|
1781
|
+
/**
|
|
1782
|
+
* `detached` indicates that the `DocState` is not synchronized with the latest version of `OpLog`.
|
|
1783
|
+
*
|
|
1784
|
+
* > The document becomes detached during a `checkout` operation.
|
|
1785
|
+
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
1786
|
+
* > In a detached state, the document is not editable by default, and any `import` operations will be
|
|
1787
|
+
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
1788
|
+
*
|
|
1789
|
+
* @example
|
|
1790
|
+
* ```ts
|
|
1791
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1792
|
+
*
|
|
1793
|
+
* const doc = new LoroDoc();
|
|
1794
|
+
* const text = doc.getText("text");
|
|
1795
|
+
* const frontiers = doc.frontiers();
|
|
1796
|
+
* text.insert(0, "Hello World!");
|
|
1797
|
+
* console.log(doc.isDetached()); // false
|
|
1798
|
+
* doc.checkout(frontiers);
|
|
1799
|
+
* console.log(doc.isDetached()); // true
|
|
1800
|
+
* doc.attach();
|
|
1801
|
+
* console.log(doc.isDetached()); // false
|
|
1802
|
+
* ```
|
|
1803
|
+
*/
|
|
1898
1804
|
isDetached(): boolean;
|
|
1899
|
-
/**
|
|
1900
|
-
* Detach the document state from the latest known version.
|
|
1901
|
-
*
|
|
1902
|
-
* After detaching, all import operations will be recorded in the `OpLog` without being applied to the `DocState`.
|
|
1903
|
-
* When `detached`, the document is not editable.
|
|
1904
|
-
*
|
|
1905
|
-
* @example
|
|
1906
|
-
* ```ts
|
|
1907
|
-
* import { LoroDoc } from "loro-crdt";
|
|
1908
|
-
*
|
|
1909
|
-
* const doc = new LoroDoc();
|
|
1910
|
-
* doc.detach();
|
|
1911
|
-
* console.log(doc.isDetached()); // true
|
|
1912
|
-
* ```
|
|
1913
|
-
*/
|
|
1805
|
+
/**
|
|
1806
|
+
* Detach the document state from the latest known version.
|
|
1807
|
+
*
|
|
1808
|
+
* After detaching, all import operations will be recorded in the `OpLog` without being applied to the `DocState`.
|
|
1809
|
+
* When `detached`, the document is not editable.
|
|
1810
|
+
*
|
|
1811
|
+
* @example
|
|
1812
|
+
* ```ts
|
|
1813
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1814
|
+
*
|
|
1815
|
+
* const doc = new LoroDoc();
|
|
1816
|
+
* doc.detach();
|
|
1817
|
+
* console.log(doc.isDetached()); // true
|
|
1818
|
+
* ```
|
|
1819
|
+
*/
|
|
1914
1820
|
detach(): void;
|
|
1915
|
-
/**
|
|
1916
|
-
* Duplicate the document with a different PeerID
|
|
1917
|
-
*
|
|
1918
|
-
* The time complexity and space complexity of this operation are both O(n),
|
|
1919
|
-
*
|
|
1920
|
-
* When called in detached mode, it will fork at the current state frontiers.
|
|
1921
|
-
* It will have the same effect as `forkAt(&self.frontiers())`.
|
|
1922
|
-
|
|
1923
|
-
*/
|
|
1821
|
+
/**
|
|
1822
|
+
* Duplicate the document with a different PeerID
|
|
1823
|
+
*
|
|
1824
|
+
* The time complexity and space complexity of this operation are both O(n),
|
|
1825
|
+
*
|
|
1826
|
+
* When called in detached mode, it will fork at the current state frontiers.
|
|
1827
|
+
* It will have the same effect as `forkAt(&self.frontiers())`.
|
|
1828
|
+
*/
|
|
1924
1829
|
fork(): LoroDoc;
|
|
1925
|
-
/**
|
|
1926
|
-
* Creates a new LoroDoc at a specified version (Frontiers)
|
|
1927
|
-
*
|
|
1928
|
-
* The created doc will only contain the history before the specified frontiers.
|
|
1929
|
-
|
|
1930
|
-
* @returns {LoroDoc}
|
|
1931
|
-
*/
|
|
1830
|
+
/**
|
|
1831
|
+
* Creates a new LoroDoc at a specified version (Frontiers)
|
|
1832
|
+
*
|
|
1833
|
+
* The created doc will only contain the history before the specified frontiers.
|
|
1834
|
+
*/
|
|
1932
1835
|
forkAt(frontiers: ({ peer: PeerID, counter: number })[]): LoroDoc;
|
|
1933
|
-
/**
|
|
1934
|
-
* Checkout the `DocState` to the latest version of `OpLog`.
|
|
1935
|
-
*
|
|
1936
|
-
* > The document becomes detached during a `checkout` operation.
|
|
1937
|
-
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
1938
|
-
* > In a detached state, the document is not editable by default, and any `import` operations will be
|
|
1939
|
-
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
1940
|
-
*
|
|
1941
|
-
* This has the same effect as `attach`.
|
|
1942
|
-
*
|
|
1943
|
-
* @example
|
|
1944
|
-
* ```ts
|
|
1945
|
-
* import { LoroDoc } from "loro-crdt";
|
|
1946
|
-
*
|
|
1947
|
-
* const doc = new LoroDoc();
|
|
1948
|
-
* const text = doc.getText("text");
|
|
1949
|
-
* const frontiers = doc.frontiers();
|
|
1950
|
-
* text.insert(0, "Hello World!");
|
|
1951
|
-
* doc.checkout(frontiers);
|
|
1952
|
-
* // you need call `checkoutToLatest()` or `attach()` before changing the doc.
|
|
1953
|
-
* doc.checkoutToLatest();
|
|
1954
|
-
* text.insert(0, "Hi");
|
|
1955
|
-
* ```
|
|
1956
|
-
*/
|
|
1836
|
+
/**
|
|
1837
|
+
* Checkout the `DocState` to the latest version of `OpLog`.
|
|
1838
|
+
*
|
|
1839
|
+
* > The document becomes detached during a `checkout` operation.
|
|
1840
|
+
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
1841
|
+
* > In a detached state, the document is not editable by default, and any `import` operations will be
|
|
1842
|
+
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
1843
|
+
*
|
|
1844
|
+
* This has the same effect as `attach`.
|
|
1845
|
+
*
|
|
1846
|
+
* @example
|
|
1847
|
+
* ```ts
|
|
1848
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1849
|
+
*
|
|
1850
|
+
* const doc = new LoroDoc();
|
|
1851
|
+
* const text = doc.getText("text");
|
|
1852
|
+
* const frontiers = doc.frontiers();
|
|
1853
|
+
* text.insert(0, "Hello World!");
|
|
1854
|
+
* doc.checkout(frontiers);
|
|
1855
|
+
* // you need call `checkoutToLatest()` or `attach()` before changing the doc.
|
|
1856
|
+
* doc.checkoutToLatest();
|
|
1857
|
+
* text.insert(0, "Hi");
|
|
1858
|
+
* ```
|
|
1859
|
+
*/
|
|
1957
1860
|
checkoutToLatest(): void;
|
|
1958
|
-
/**
|
|
1959
|
-
* Visit all the ancestors of the changes in causal order.
|
|
1960
|
-
*
|
|
1961
|
-
* @param ids - the changes to visit
|
|
1962
|
-
* @param f - the callback function, return `true` to continue visiting, return `false` to stop
|
|
1963
|
-
|
|
1964
|
-
* @param {(change: Change) => boolean} f
|
|
1965
|
-
*/
|
|
1861
|
+
/**
|
|
1862
|
+
* Visit all the ancestors of the changes in causal order.
|
|
1863
|
+
*
|
|
1864
|
+
* @param ids - the changes to visit
|
|
1865
|
+
* @param f - the callback function, return `true` to continue visiting, return `false` to stop
|
|
1866
|
+
*/
|
|
1966
1867
|
travelChangeAncestors(ids: ({ peer: PeerID, counter: number })[], f: (change: Change) => boolean): void;
|
|
1967
|
-
/**
|
|
1968
|
-
* Find the op id spans that between the `from` version and the `to` version.
|
|
1969
|
-
*
|
|
1970
|
-
* You can combine it with `exportJsonInIdSpan` to get the changes between two versions.
|
|
1971
|
-
*
|
|
1972
|
-
* You can use it to travel all the changes from `from` to `to`. `from` and `to` are frontiers,
|
|
1973
|
-
* and they can be concurrent to each other. You can use it to find all the changes related to an event:
|
|
1974
|
-
*
|
|
1975
|
-
* @example
|
|
1976
|
-
* ```ts
|
|
1977
|
-
* import { LoroDoc } from "loro-crdt";
|
|
1978
|
-
*
|
|
1979
|
-
* const docA = new LoroDoc();
|
|
1980
|
-
* docA.setPeerId("1");
|
|
1981
|
-
* const docB = new LoroDoc();
|
|
1982
|
-
*
|
|
1983
|
-
* docA.getText("text").update("Hello");
|
|
1984
|
-
* docA.commit();
|
|
1985
|
-
* const snapshot = docA.export({ mode: "snapshot" });
|
|
1986
|
-
* let done = false;
|
|
1987
|
-
* docB.subscribe(e => {
|
|
1988
|
-
* const spans = docB.findIdSpansBetween(e.from, e.to);
|
|
1989
|
-
* const changes = docB.exportJsonInIdSpan(spans.forward[0]);
|
|
1990
|
-
* console.log(changes);
|
|
1991
|
-
* // [{
|
|
1992
|
-
* // id: "0@1",
|
|
1993
|
-
* // timestamp: expect.any(Number),
|
|
1994
|
-
* // deps: [],
|
|
1995
|
-
* // lamport: 0,
|
|
1996
|
-
* // msg: undefined,
|
|
1997
|
-
* // ops: [{
|
|
1998
|
-
* // container: "cid:root-text:Text",
|
|
1999
|
-
* // counter: 0,
|
|
2000
|
-
* // content: {
|
|
2001
|
-
* // type: "insert",
|
|
2002
|
-
* // pos: 0,
|
|
2003
|
-
* // text: "Hello"
|
|
2004
|
-
* // }
|
|
2005
|
-
* // }]
|
|
2006
|
-
* // }]
|
|
2007
|
-
* });
|
|
2008
|
-
* docB.import(snapshot);
|
|
2009
|
-
* ```
|
|
2010
|
-
|
|
2011
|
-
* @param {({ peer: PeerID, counter: number })[]} to
|
|
2012
|
-
* @returns {VersionVectorDiff}
|
|
2013
|
-
*/
|
|
1868
|
+
/**
|
|
1869
|
+
* Find the op id spans that between the `from` version and the `to` version.
|
|
1870
|
+
*
|
|
1871
|
+
* You can combine it with `exportJsonInIdSpan` to get the changes between two versions.
|
|
1872
|
+
*
|
|
1873
|
+
* You can use it to travel all the changes from `from` to `to`. `from` and `to` are frontiers,
|
|
1874
|
+
* and they can be concurrent to each other. You can use it to find all the changes related to an event:
|
|
1875
|
+
*
|
|
1876
|
+
* @example
|
|
1877
|
+
* ```ts
|
|
1878
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1879
|
+
*
|
|
1880
|
+
* const docA = new LoroDoc();
|
|
1881
|
+
* docA.setPeerId("1");
|
|
1882
|
+
* const docB = new LoroDoc();
|
|
1883
|
+
*
|
|
1884
|
+
* docA.getText("text").update("Hello");
|
|
1885
|
+
* docA.commit();
|
|
1886
|
+
* const snapshot = docA.export({ mode: "snapshot" });
|
|
1887
|
+
* let done = false;
|
|
1888
|
+
* docB.subscribe(e => {
|
|
1889
|
+
* const spans = docB.findIdSpansBetween(e.from, e.to);
|
|
1890
|
+
* const changes = docB.exportJsonInIdSpan(spans.forward[0]);
|
|
1891
|
+
* console.log(changes);
|
|
1892
|
+
* // [{
|
|
1893
|
+
* // id: "0@1",
|
|
1894
|
+
* // timestamp: expect.any(Number),
|
|
1895
|
+
* // deps: [],
|
|
1896
|
+
* // lamport: 0,
|
|
1897
|
+
* // msg: undefined,
|
|
1898
|
+
* // ops: [{
|
|
1899
|
+
* // container: "cid:root-text:Text",
|
|
1900
|
+
* // counter: 0,
|
|
1901
|
+
* // content: {
|
|
1902
|
+
* // type: "insert",
|
|
1903
|
+
* // pos: 0,
|
|
1904
|
+
* // text: "Hello"
|
|
1905
|
+
* // }
|
|
1906
|
+
* // }]
|
|
1907
|
+
* // }]
|
|
1908
|
+
* });
|
|
1909
|
+
* docB.import(snapshot);
|
|
1910
|
+
* ```
|
|
1911
|
+
*/
|
|
2014
1912
|
findIdSpansBetween(from: ({ peer: PeerID, counter: number })[], to: ({ peer: PeerID, counter: number })[]): VersionVectorDiff;
|
|
2015
|
-
/**
|
|
2016
|
-
* Checkout the `DocState` to a specific version.
|
|
2017
|
-
*
|
|
2018
|
-
* > The document becomes detached during a `checkout` operation.
|
|
2019
|
-
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
2020
|
-
* > In a detached state, the document is not editable, and any `import` operations will be
|
|
2021
|
-
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
2022
|
-
*
|
|
2023
|
-
* You should call `attach` to attach the `DocState` to the latest version of `OpLog`.
|
|
2024
|
-
*
|
|
2025
|
-
* @param frontiers - the specific frontiers
|
|
2026
|
-
*
|
|
2027
|
-
* @example
|
|
2028
|
-
* ```ts
|
|
2029
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2030
|
-
*
|
|
2031
|
-
* const doc = new LoroDoc();
|
|
2032
|
-
* const text = doc.getText("text");
|
|
2033
|
-
* const frontiers = doc.frontiers();
|
|
2034
|
-
* text.insert(0, "Hello World!");
|
|
2035
|
-
* doc.checkout(frontiers);
|
|
2036
|
-
* console.log(doc.toJSON()); // {"text": ""}
|
|
2037
|
-
* ```
|
|
2038
|
-
|
|
2039
|
-
*/
|
|
1913
|
+
/**
|
|
1914
|
+
* Checkout the `DocState` to a specific version.
|
|
1915
|
+
*
|
|
1916
|
+
* > The document becomes detached during a `checkout` operation.
|
|
1917
|
+
* > Being `detached` implies that the `DocState` is not synchronized with the latest version of the `OpLog`.
|
|
1918
|
+
* > In a detached state, the document is not editable, and any `import` operations will be
|
|
1919
|
+
* > recorded in the `OpLog` without being applied to the `DocState`.
|
|
1920
|
+
*
|
|
1921
|
+
* You should call `attach` to attach the `DocState` to the latest version of `OpLog`.
|
|
1922
|
+
*
|
|
1923
|
+
* @param frontiers - the specific frontiers
|
|
1924
|
+
*
|
|
1925
|
+
* @example
|
|
1926
|
+
* ```ts
|
|
1927
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1928
|
+
*
|
|
1929
|
+
* const doc = new LoroDoc();
|
|
1930
|
+
* const text = doc.getText("text");
|
|
1931
|
+
* const frontiers = doc.frontiers();
|
|
1932
|
+
* text.insert(0, "Hello World!");
|
|
1933
|
+
* doc.checkout(frontiers);
|
|
1934
|
+
* console.log(doc.toJSON()); // {"text": ""}
|
|
1935
|
+
* ```
|
|
1936
|
+
*/
|
|
2040
1937
|
checkout(frontiers: ({ peer: PeerID, counter: number })[]): void;
|
|
2041
|
-
/**
|
|
2042
|
-
* Set the peer ID of the current writer.
|
|
2043
|
-
*
|
|
2044
|
-
* It must be a number, a BigInt, or a decimal string that can be parsed to a unsigned 64-bit integer.
|
|
2045
|
-
*
|
|
2046
|
-
* Note: use it with caution. You need to make sure there is not chance that two peers
|
|
2047
|
-
* have the same peer ID. Otherwise, we cannot ensure the consistency of the document.
|
|
2048
|
-
|
|
2049
|
-
*/
|
|
1938
|
+
/**
|
|
1939
|
+
* Set the peer ID of the current writer.
|
|
1940
|
+
*
|
|
1941
|
+
* It must be a number, a BigInt, or a decimal string that can be parsed to a unsigned 64-bit integer.
|
|
1942
|
+
*
|
|
1943
|
+
* Note: use it with caution. You need to make sure there is not chance that two peers
|
|
1944
|
+
* have the same peer ID. Otherwise, we cannot ensure the consistency of the document.
|
|
1945
|
+
*/
|
|
2050
1946
|
setPeerId(peer_id: number | bigint | `${number}`): void;
|
|
2051
|
-
/**
|
|
2052
|
-
* Commit the cumulative auto-committed transaction.
|
|
2053
|
-
*
|
|
2054
|
-
* You can specify the `origin`, `timestamp`, and `message` of the commit.
|
|
2055
|
-
*
|
|
2056
|
-
* - The `origin` is used to mark the event
|
|
2057
|
-
* - The `message` works like a git commit message, which will be recorded and synced to peers
|
|
2058
|
-
* - The `timestamp` is the number of seconds that have elapsed since 00:00:00 UTC on January 1, 1970.
|
|
2059
|
-
* It defaults to `Date.now() / 1000` when timestamp recording is enabled
|
|
2060
|
-
*
|
|
2061
|
-
* The events will be emitted after a transaction is committed. A transaction is committed when:
|
|
2062
|
-
*
|
|
2063
|
-
* - `doc.commit()` is called.
|
|
2064
|
-
* - `doc.export(mode)` is called.
|
|
2065
|
-
* - `doc.import(data)` is called.
|
|
2066
|
-
* - `doc.checkout(version)` is called.
|
|
2067
|
-
*
|
|
2068
|
-
* NOTE: Timestamps are forced to be in ascending order.
|
|
2069
|
-
* If you commit a new change with a timestamp that is less than the existing one,
|
|
2070
|
-
* the largest existing timestamp will be used instead.
|
|
2071
|
-
*
|
|
2072
|
-
* NOTE: The `origin` will not be persisted, but the `message` will.
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
*
|
|
2078
|
-
*
|
|
2079
|
-
*
|
|
2080
|
-
|
|
2081
|
-
* @returns {number}
|
|
2082
|
-
*/
|
|
1947
|
+
/**
|
|
1948
|
+
* Commit the cumulative auto-committed transaction.
|
|
1949
|
+
*
|
|
1950
|
+
* You can specify the `origin`, `timestamp`, and `message` of the commit.
|
|
1951
|
+
*
|
|
1952
|
+
* - The `origin` is used to mark the event
|
|
1953
|
+
* - The `message` works like a git commit message, which will be recorded and synced to peers
|
|
1954
|
+
* - The `timestamp` is the number of seconds that have elapsed since 00:00:00 UTC on January 1, 1970.
|
|
1955
|
+
* It defaults to `Date.now() / 1000` when timestamp recording is enabled
|
|
1956
|
+
*
|
|
1957
|
+
* The events will be emitted after a transaction is committed. A transaction is committed when:
|
|
1958
|
+
*
|
|
1959
|
+
* - `doc.commit()` is called.
|
|
1960
|
+
* - `doc.export(mode)` is called.
|
|
1961
|
+
* - `doc.import(data)` is called.
|
|
1962
|
+
* - `doc.checkout(version)` is called.
|
|
1963
|
+
*
|
|
1964
|
+
* NOTE: Timestamps are forced to be in ascending order.
|
|
1965
|
+
* If you commit a new change with a timestamp that is less than the existing one,
|
|
1966
|
+
* the largest existing timestamp will be used instead.
|
|
1967
|
+
*
|
|
1968
|
+
* NOTE: The `origin` will not be persisted, but the `message` will.
|
|
1969
|
+
*/
|
|
1970
|
+
commit(options?: { origin?: string, timestamp?: number, message?: string } | null): void;
|
|
1971
|
+
/**
|
|
1972
|
+
* Get the number of operations in the pending transaction.
|
|
1973
|
+
*
|
|
1974
|
+
* The pending transaction is the one that is not committed yet. It will be committed
|
|
1975
|
+
* automatically after calling `doc.commit()`, `doc.export(mode)` or `doc.checkout(version)`.
|
|
1976
|
+
*/
|
|
2083
1977
|
getPendingTxnLength(): number;
|
|
2084
|
-
/**
|
|
2085
|
-
* Get a LoroText by container id.
|
|
2086
|
-
*
|
|
2087
|
-
* The object returned is a new js object each time because it need to cross
|
|
2088
|
-
* the WASM boundary.
|
|
2089
|
-
*
|
|
2090
|
-
* If the container does not exist, an error will be thrown.
|
|
2091
|
-
*
|
|
2092
|
-
* @example
|
|
2093
|
-
* ```ts
|
|
2094
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2095
|
-
*
|
|
2096
|
-
* const doc = new LoroDoc();
|
|
2097
|
-
* const text = doc.getText("text");
|
|
2098
|
-
* ```
|
|
2099
|
-
|
|
2100
|
-
* @returns {LoroText}
|
|
2101
|
-
*/
|
|
1978
|
+
/**
|
|
1979
|
+
* Get a LoroText by container id.
|
|
1980
|
+
*
|
|
1981
|
+
* The object returned is a new js object each time because it need to cross
|
|
1982
|
+
* the WASM boundary.
|
|
1983
|
+
*
|
|
1984
|
+
* If the container does not exist, an error will be thrown.
|
|
1985
|
+
*
|
|
1986
|
+
* @example
|
|
1987
|
+
* ```ts
|
|
1988
|
+
* import { LoroDoc } from "loro-crdt";
|
|
1989
|
+
*
|
|
1990
|
+
* const doc = new LoroDoc();
|
|
1991
|
+
* const text = doc.getText("text");
|
|
1992
|
+
* ```
|
|
1993
|
+
*/
|
|
2102
1994
|
getText(cid: ContainerID | string): LoroText;
|
|
2103
|
-
/**
|
|
2104
|
-
* Get a LoroCounter by container id
|
|
2105
|
-
*
|
|
2106
|
-
* If the container does not exist, an error will be thrown.
|
|
2107
|
-
|
|
2108
|
-
* @returns {LoroCounter}
|
|
2109
|
-
*/
|
|
1995
|
+
/**
|
|
1996
|
+
* Get a LoroCounter by container id
|
|
1997
|
+
*
|
|
1998
|
+
* If the container does not exist, an error will be thrown.
|
|
1999
|
+
*/
|
|
2110
2000
|
getCounter(cid: ContainerID | string): LoroCounter;
|
|
2111
|
-
/**
|
|
2112
|
-
* Check if the doc contains the target container.
|
|
2113
|
-
*
|
|
2114
|
-
* A root container always exists, while a normal container exists
|
|
2115
|
-
* if it has ever been created on the doc.
|
|
2116
|
-
*
|
|
2117
|
-
* @example
|
|
2118
|
-
* ```ts
|
|
2119
|
-
* import { LoroDoc, LoroMap, LoroText, LoroList } from "loro-crdt";
|
|
2120
|
-
*
|
|
2121
|
-
* const doc = new LoroDoc();
|
|
2122
|
-
* doc.setPeerId("1");
|
|
2123
|
-
* const text = doc.getMap("map").setContainer("text", new LoroText());
|
|
2124
|
-
* const list = doc.getMap("map").setContainer("list", new LoroList());
|
|
2125
|
-
* expect(doc.isContainerExists("cid:root-map:Map")).toBe(true);
|
|
2126
|
-
* expect(doc.isContainerExists("cid:0@1:Text")).toBe(true);
|
|
2127
|
-
* expect(doc.isContainerExists("cid:1@1:List")).toBe(true);
|
|
2128
|
-
*
|
|
2129
|
-
* const doc2 = new LoroDoc();
|
|
2130
|
-
* // Containers exist, as long as the history or the doc state include it
|
|
2131
|
-
* doc.detach();
|
|
2132
|
-
* doc2.import(doc.export({ mode: "update" }));
|
|
2133
|
-
* expect(doc2.isContainerExists("cid:root-map:Map")).toBe(true);
|
|
2134
|
-
* expect(doc2.isContainerExists("cid:0@1:Text")).toBe(true);
|
|
2135
|
-
* expect(doc2.isContainerExists("cid:1@1:List")).toBe(true);
|
|
2136
|
-
* ```
|
|
2137
|
-
|
|
2138
|
-
* @returns {boolean}
|
|
2139
|
-
*/
|
|
2001
|
+
/**
|
|
2002
|
+
* Check if the doc contains the target container.
|
|
2003
|
+
*
|
|
2004
|
+
* A root container always exists, while a normal container exists
|
|
2005
|
+
* if it has ever been created on the doc.
|
|
2006
|
+
*
|
|
2007
|
+
* @example
|
|
2008
|
+
* ```ts
|
|
2009
|
+
* import { LoroDoc, LoroMap, LoroText, LoroList } from "loro-crdt";
|
|
2010
|
+
*
|
|
2011
|
+
* const doc = new LoroDoc();
|
|
2012
|
+
* doc.setPeerId("1");
|
|
2013
|
+
* const text = doc.getMap("map").setContainer("text", new LoroText());
|
|
2014
|
+
* const list = doc.getMap("map").setContainer("list", new LoroList());
|
|
2015
|
+
* expect(doc.isContainerExists("cid:root-map:Map")).toBe(true);
|
|
2016
|
+
* expect(doc.isContainerExists("cid:0@1:Text")).toBe(true);
|
|
2017
|
+
* expect(doc.isContainerExists("cid:1@1:List")).toBe(true);
|
|
2018
|
+
*
|
|
2019
|
+
* const doc2 = new LoroDoc();
|
|
2020
|
+
* // Containers exist, as long as the history or the doc state include it
|
|
2021
|
+
* doc.detach();
|
|
2022
|
+
* doc2.import(doc.export({ mode: "update" }));
|
|
2023
|
+
* expect(doc2.isContainerExists("cid:root-map:Map")).toBe(true);
|
|
2024
|
+
* expect(doc2.isContainerExists("cid:0@1:Text")).toBe(true);
|
|
2025
|
+
* expect(doc2.isContainerExists("cid:1@1:List")).toBe(true);
|
|
2026
|
+
* ```
|
|
2027
|
+
*/
|
|
2140
2028
|
hasContainer(container_id: ContainerID): boolean;
|
|
2141
|
-
/**
|
|
2142
|
-
* Set the commit message of the next commit
|
|
2143
|
-
|
|
2144
|
-
*/
|
|
2029
|
+
/**
|
|
2030
|
+
* Set the commit message of the next commit
|
|
2031
|
+
*/
|
|
2145
2032
|
setNextCommitMessage(msg: string): void;
|
|
2146
|
-
/**
|
|
2147
|
-
* Set the origin of the next commit
|
|
2148
|
-
|
|
2149
|
-
*/
|
|
2033
|
+
/**
|
|
2034
|
+
* Set the origin of the next commit
|
|
2035
|
+
*/
|
|
2150
2036
|
setNextCommitOrigin(origin: string): void;
|
|
2151
|
-
/**
|
|
2152
|
-
* Set the timestamp of the next commit
|
|
2153
|
-
|
|
2154
|
-
*/
|
|
2037
|
+
/**
|
|
2038
|
+
* Set the timestamp of the next commit
|
|
2039
|
+
*/
|
|
2155
2040
|
setNextCommitTimestamp(timestamp: number): void;
|
|
2156
|
-
/**
|
|
2157
|
-
* Set the options of the next commit
|
|
2158
|
-
|
|
2159
|
-
*/
|
|
2041
|
+
/**
|
|
2042
|
+
* Set the options of the next commit
|
|
2043
|
+
*/
|
|
2160
2044
|
setNextCommitOptions(options: { origin?: string, timestamp?: number, message?: string }): void;
|
|
2161
|
-
/**
|
|
2162
|
-
* Clear the options of the next commit
|
|
2163
|
-
*/
|
|
2045
|
+
/**
|
|
2046
|
+
* Clear the options of the next commit
|
|
2047
|
+
*/
|
|
2164
2048
|
clearNextCommitOptions(): void;
|
|
2165
|
-
/**
|
|
2166
|
-
* Get deep value of the document with container id
|
|
2167
|
-
|
|
2168
|
-
*/
|
|
2049
|
+
/**
|
|
2050
|
+
* Get deep value of the document with container id
|
|
2051
|
+
*/
|
|
2169
2052
|
getDeepValueWithID(): any;
|
|
2170
|
-
/**
|
|
2171
|
-
* Get the path from the root to the container
|
|
2172
|
-
|
|
2173
|
-
* @returns {(string|number)[] | undefined}
|
|
2174
|
-
*/
|
|
2053
|
+
/**
|
|
2054
|
+
* Get the path from the root to the container
|
|
2055
|
+
*/
|
|
2175
2056
|
getPathToContainer(id: ContainerID): (string|number)[] | undefined;
|
|
2176
|
-
/**
|
|
2177
|
-
* Evaluate JSONPath against a LoroDoc
|
|
2178
|
-
|
|
2179
|
-
* @returns {Array<any>}
|
|
2180
|
-
*/
|
|
2057
|
+
/**
|
|
2058
|
+
* Evaluate JSONPath against a LoroDoc
|
|
2059
|
+
*/
|
|
2181
2060
|
JSONPath(jsonpath: string): Array<any>;
|
|
2182
|
-
/**
|
|
2183
|
-
* Get the version vector of the current document state.
|
|
2184
|
-
*
|
|
2185
|
-
* If you checkout to a specific version, the version vector will change.
|
|
2186
|
-
|
|
2187
|
-
*/
|
|
2061
|
+
/**
|
|
2062
|
+
* Get the version vector of the current document state.
|
|
2063
|
+
*
|
|
2064
|
+
* If you checkout to a specific version, the version vector will change.
|
|
2065
|
+
*/
|
|
2188
2066
|
version(): VersionVector;
|
|
2189
|
-
/**
|
|
2190
|
-
* The doc only contains the history since this version
|
|
2191
|
-
*
|
|
2192
|
-
* This is empty if the doc is not shallow.
|
|
2193
|
-
*
|
|
2194
|
-
* The ops included by the shallow history start version vector are not in the doc.
|
|
2195
|
-
|
|
2196
|
-
*/
|
|
2067
|
+
/**
|
|
2068
|
+
* The doc only contains the history since this version
|
|
2069
|
+
*
|
|
2070
|
+
* This is empty if the doc is not shallow.
|
|
2071
|
+
*
|
|
2072
|
+
* The ops included by the shallow history start version vector are not in the doc.
|
|
2073
|
+
*/
|
|
2197
2074
|
shallowSinceVV(): VersionVector;
|
|
2198
|
-
/**
|
|
2199
|
-
* Check if the doc contains the full history.
|
|
2200
|
-
|
|
2201
|
-
*/
|
|
2075
|
+
/**
|
|
2076
|
+
* Check if the doc contains the full history.
|
|
2077
|
+
*/
|
|
2202
2078
|
isShallow(): boolean;
|
|
2203
|
-
/**
|
|
2204
|
-
* The doc only contains the history since this version
|
|
2205
|
-
*
|
|
2206
|
-
* This is empty if the doc is not shallow.
|
|
2207
|
-
*
|
|
2208
|
-
* The ops included by the shallow history start frontiers are not in the doc.
|
|
2209
|
-
|
|
2210
|
-
*/
|
|
2079
|
+
/**
|
|
2080
|
+
* The doc only contains the history since this version
|
|
2081
|
+
*
|
|
2082
|
+
* This is empty if the doc is not shallow.
|
|
2083
|
+
*
|
|
2084
|
+
* The ops included by the shallow history start frontiers are not in the doc.
|
|
2085
|
+
*/
|
|
2211
2086
|
shallowSinceFrontiers(): { peer: PeerID, counter: number }[];
|
|
2212
|
-
/**
|
|
2213
|
-
* Get the version vector of the latest known version in OpLog.
|
|
2214
|
-
*
|
|
2215
|
-
* If you checkout to a specific version, this version vector will not change.
|
|
2216
|
-
|
|
2217
|
-
*/
|
|
2087
|
+
/**
|
|
2088
|
+
* Get the version vector of the latest known version in OpLog.
|
|
2089
|
+
*
|
|
2090
|
+
* If you checkout to a specific version, this version vector will not change.
|
|
2091
|
+
*/
|
|
2218
2092
|
oplogVersion(): VersionVector;
|
|
2219
|
-
/**
|
|
2220
|
-
* Get the [frontiers](https://loro.dev/docs/advanced/version_deep_dive) of the current document state.
|
|
2221
|
-
*
|
|
2222
|
-
* If you checkout to a specific version, this value will change.
|
|
2223
|
-
|
|
2224
|
-
*/
|
|
2093
|
+
/**
|
|
2094
|
+
* Get the [frontiers](https://loro.dev/docs/advanced/version_deep_dive) of the current document state.
|
|
2095
|
+
*
|
|
2096
|
+
* If you checkout to a specific version, this value will change.
|
|
2097
|
+
*/
|
|
2225
2098
|
frontiers(): { peer: PeerID, counter: number }[];
|
|
2226
|
-
/**
|
|
2227
|
-
* Get the [frontiers](https://loro.dev/docs/advanced/version_deep_dive) of the latest version in OpLog.
|
|
2228
|
-
*
|
|
2229
|
-
* If you checkout to a specific version, this value will not change.
|
|
2230
|
-
|
|
2231
|
-
*/
|
|
2099
|
+
/**
|
|
2100
|
+
* Get the [frontiers](https://loro.dev/docs/advanced/version_deep_dive) of the latest version in OpLog.
|
|
2101
|
+
*
|
|
2102
|
+
* If you checkout to a specific version, this value will not change.
|
|
2103
|
+
*/
|
|
2232
2104
|
oplogFrontiers(): { peer: PeerID, counter: number }[];
|
|
2233
|
-
/**
|
|
2234
|
-
* Compare the version of the OpLog with the specified frontiers.
|
|
2235
|
-
*
|
|
2236
|
-
* This method is useful to compare the version by only a small amount of data.
|
|
2237
|
-
*
|
|
2238
|
-
* This method returns an integer indicating the relationship between the version of the OpLog (referred to as 'self')
|
|
2239
|
-
* and the provided 'frontiers' parameter:
|
|
2240
|
-
*
|
|
2241
|
-
* - -1: The version of 'self' is either less than 'frontiers' or is non-comparable (parallel) to 'frontiers',
|
|
2242
|
-
* indicating that it is not definitively less than 'frontiers'.
|
|
2243
|
-
* - 0: The version of 'self' is equal to 'frontiers'.
|
|
2244
|
-
* - 1: The version of 'self' is greater than 'frontiers'.
|
|
2245
|
-
*
|
|
2246
|
-
* # Internal
|
|
2247
|
-
*
|
|
2248
|
-
* Frontiers cannot be compared without the history of the OpLog.
|
|
2249
|
-
|
|
2250
|
-
* @returns {number}
|
|
2251
|
-
*/
|
|
2105
|
+
/**
|
|
2106
|
+
* Compare the version of the OpLog with the specified frontiers.
|
|
2107
|
+
*
|
|
2108
|
+
* This method is useful to compare the version by only a small amount of data.
|
|
2109
|
+
*
|
|
2110
|
+
* This method returns an integer indicating the relationship between the version of the OpLog (referred to as 'self')
|
|
2111
|
+
* and the provided 'frontiers' parameter:
|
|
2112
|
+
*
|
|
2113
|
+
* - -1: The version of 'self' is either less than 'frontiers' or is non-comparable (parallel) to 'frontiers',
|
|
2114
|
+
* indicating that it is not definitively less than 'frontiers'.
|
|
2115
|
+
* - 0: The version of 'self' is equal to 'frontiers'.
|
|
2116
|
+
* - 1: The version of 'self' is greater than 'frontiers'.
|
|
2117
|
+
*
|
|
2118
|
+
* # Internal
|
|
2119
|
+
*
|
|
2120
|
+
* Frontiers cannot be compared without the history of the OpLog.
|
|
2121
|
+
*/
|
|
2252
2122
|
cmpWithFrontiers(frontiers: ({ peer: PeerID, counter: number })[]): number;
|
|
2253
|
-
/**
|
|
2254
|
-
* Compare the ordering of two Frontiers.
|
|
2255
|
-
*
|
|
2256
|
-
* It's assumed that both Frontiers are included by the doc. Otherwise, an error will be thrown.
|
|
2257
|
-
*
|
|
2258
|
-
* Return value:
|
|
2259
|
-
*
|
|
2260
|
-
* - -1: a < b
|
|
2261
|
-
* - 0: a == b
|
|
2262
|
-
* - 1: a > b
|
|
2263
|
-
* - undefined: a ∥ b: a and b are concurrent
|
|
2264
|
-
|
|
2265
|
-
* @param {({ peer: PeerID, counter: number })[]} b
|
|
2266
|
-
* @returns {-1 | 1 | 0 | undefined}
|
|
2267
|
-
*/
|
|
2123
|
+
/**
|
|
2124
|
+
* Compare the ordering of two Frontiers.
|
|
2125
|
+
*
|
|
2126
|
+
* It's assumed that both Frontiers are included by the doc. Otherwise, an error will be thrown.
|
|
2127
|
+
*
|
|
2128
|
+
* Return value:
|
|
2129
|
+
*
|
|
2130
|
+
* - -1: a < b
|
|
2131
|
+
* - 0: a == b
|
|
2132
|
+
* - 1: a > b
|
|
2133
|
+
* - undefined: a ∥ b: a and b are concurrent
|
|
2134
|
+
*/
|
|
2268
2135
|
cmpFrontiers(a: ({ peer: PeerID, counter: number })[], b: ({ peer: PeerID, counter: number })[]): -1 | 1 | 0 | undefined;
|
|
2269
|
-
/**
|
|
2270
|
-
* Export the snapshot of current version.
|
|
2271
|
-
* It includes all the history and the document state
|
|
2272
|
-
*
|
|
2273
|
-
* @deprecated Use `export({mode: "snapshot"})` instead
|
|
2274
|
-
|
|
2275
|
-
*/
|
|
2136
|
+
/**
|
|
2137
|
+
* Export the snapshot of current version.
|
|
2138
|
+
* It includes all the history and the document state
|
|
2139
|
+
*
|
|
2140
|
+
* @deprecated Use `export({mode: "snapshot"})` instead
|
|
2141
|
+
*/
|
|
2276
2142
|
exportSnapshot(): Uint8Array;
|
|
2277
|
-
/**
|
|
2278
|
-
* Export the document based on the specified ExportMode.
|
|
2279
|
-
*
|
|
2280
|
-
* @param mode - The export mode to use. Can be one of:
|
|
2281
|
-
* - `{ mode: "snapshot" }`: Export a full snapshot of the document.
|
|
2282
|
-
* - `{ mode: "update", from?: VersionVector }`: Export updates from the given version vector.
|
|
2283
|
-
* - `{ mode: "updates-in-range", spans: { id: ID, len: number }[] }`: Export updates within the specified ID spans.
|
|
2284
|
-
* - `{ mode: "shallow-snapshot", frontiers: Frontiers }`: Export a garbage-collected snapshot up to the given frontiers.
|
|
2285
|
-
*
|
|
2286
|
-
* @returns A byte array containing the exported data.
|
|
2287
|
-
*
|
|
2288
|
-
* @example
|
|
2289
|
-
* ```ts
|
|
2290
|
-
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2291
|
-
*
|
|
2292
|
-
* const doc = new LoroDoc();
|
|
2293
|
-
* doc.setPeerId("1");
|
|
2294
|
-
* doc.getText("text").update("Hello World");
|
|
2295
|
-
*
|
|
2296
|
-
* // Export a full snapshot
|
|
2297
|
-
* const snapshotBytes = doc.export({ mode: "snapshot" });
|
|
2298
|
-
*
|
|
2299
|
-
* // Export updates from a specific version
|
|
2300
|
-
* const vv = doc.oplogVersion();
|
|
2301
|
-
* doc.getText("text").update("Hello Loro");
|
|
2302
|
-
* const updateBytes = doc.export({ mode: "update", from: vv });
|
|
2303
|
-
*
|
|
2304
|
-
* // Export a shallow snapshot that only includes the history since the frontiers
|
|
2305
|
-
* const shallowBytes = doc.export({ mode: "shallow-snapshot", frontiers: doc.oplogFrontiers() });
|
|
2306
|
-
*
|
|
2307
|
-
* // Export updates within specific ID spans
|
|
2308
|
-
* const spanBytes = doc.export({
|
|
2309
|
-
* mode: "updates-in-range",
|
|
2310
|
-
* spans: [{ id: { peer: "1", counter: 0 }, len: 10 }]
|
|
2311
|
-
* });
|
|
2312
|
-
* ```
|
|
2313
|
-
|
|
2314
|
-
* @returns {Uint8Array}
|
|
2315
|
-
*/
|
|
2143
|
+
/**
|
|
2144
|
+
* Export the document based on the specified ExportMode.
|
|
2145
|
+
*
|
|
2146
|
+
* @param mode - The export mode to use. Can be one of:
|
|
2147
|
+
* - `{ mode: "snapshot" }`: Export a full snapshot of the document.
|
|
2148
|
+
* - `{ mode: "update", from?: VersionVector }`: Export updates from the given version vector.
|
|
2149
|
+
* - `{ mode: "updates-in-range", spans: { id: ID, len: number }[] }`: Export updates within the specified ID spans.
|
|
2150
|
+
* - `{ mode: "shallow-snapshot", frontiers: Frontiers }`: Export a garbage-collected snapshot up to the given frontiers.
|
|
2151
|
+
*
|
|
2152
|
+
* @returns A byte array containing the exported data.
|
|
2153
|
+
*
|
|
2154
|
+
* @example
|
|
2155
|
+
* ```ts
|
|
2156
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2157
|
+
*
|
|
2158
|
+
* const doc = new LoroDoc();
|
|
2159
|
+
* doc.setPeerId("1");
|
|
2160
|
+
* doc.getText("text").update("Hello World");
|
|
2161
|
+
*
|
|
2162
|
+
* // Export a full snapshot
|
|
2163
|
+
* const snapshotBytes = doc.export({ mode: "snapshot" });
|
|
2164
|
+
*
|
|
2165
|
+
* // Export updates from a specific version
|
|
2166
|
+
* const vv = doc.oplogVersion();
|
|
2167
|
+
* doc.getText("text").update("Hello Loro");
|
|
2168
|
+
* const updateBytes = doc.export({ mode: "update", from: vv });
|
|
2169
|
+
*
|
|
2170
|
+
* // Export a shallow snapshot that only includes the history since the frontiers
|
|
2171
|
+
* const shallowBytes = doc.export({ mode: "shallow-snapshot", frontiers: doc.oplogFrontiers() });
|
|
2172
|
+
*
|
|
2173
|
+
* // Export updates within specific ID spans
|
|
2174
|
+
* const spanBytes = doc.export({
|
|
2175
|
+
* mode: "updates-in-range",
|
|
2176
|
+
* spans: [{ id: { peer: "1", counter: 0 }, len: 10 }]
|
|
2177
|
+
* });
|
|
2178
|
+
* ```
|
|
2179
|
+
*/
|
|
2316
2180
|
export(mode: ExportMode): Uint8Array;
|
|
2317
|
-
/**
|
|
2318
|
-
* Import updates from the JSON format.
|
|
2319
|
-
*
|
|
2320
|
-
* only supports backward compatibility but not forward compatibility.
|
|
2321
|
-
|
|
2322
|
-
* @returns {ImportStatus}
|
|
2323
|
-
*/
|
|
2181
|
+
/**
|
|
2182
|
+
* Import updates from the JSON format.
|
|
2183
|
+
*
|
|
2184
|
+
* only supports backward compatibility but not forward compatibility.
|
|
2185
|
+
*/
|
|
2324
2186
|
importJsonUpdates(json: string | JsonSchema): ImportStatus;
|
|
2325
|
-
/**
|
|
2326
|
-
* Import snapshot or updates into current doc.
|
|
2327
|
-
*
|
|
2328
|
-
* Note:
|
|
2329
|
-
* - Updates within the current version will be ignored
|
|
2330
|
-
* - Updates with missing dependencies will be pending until the dependencies are received
|
|
2331
|
-
*
|
|
2332
|
-
* @example
|
|
2333
|
-
* ```ts
|
|
2334
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2335
|
-
*
|
|
2336
|
-
* const doc = new LoroDoc();
|
|
2337
|
-
* const text = doc.getText("text");
|
|
2338
|
-
* text.insert(0, "Hello");
|
|
2339
|
-
* // get all updates of the doc
|
|
2340
|
-
* const updates = doc.export({ mode: "update" });
|
|
2341
|
-
* const snapshot = doc.export({ mode: "snapshot" });
|
|
2342
|
-
* const doc2 = new LoroDoc();
|
|
2343
|
-
* // import snapshot
|
|
2344
|
-
* doc2.import(snapshot);
|
|
2345
|
-
* // or import updates
|
|
2346
|
-
* doc2.import(updates);
|
|
2347
|
-
* ```
|
|
2348
|
-
|
|
2349
|
-
* @returns {ImportStatus}
|
|
2350
|
-
*/
|
|
2187
|
+
/**
|
|
2188
|
+
* Import snapshot or updates into current doc.
|
|
2189
|
+
*
|
|
2190
|
+
* Note:
|
|
2191
|
+
* - Updates within the current version will be ignored
|
|
2192
|
+
* - Updates with missing dependencies will be pending until the dependencies are received
|
|
2193
|
+
*
|
|
2194
|
+
* @example
|
|
2195
|
+
* ```ts
|
|
2196
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2197
|
+
*
|
|
2198
|
+
* const doc = new LoroDoc();
|
|
2199
|
+
* const text = doc.getText("text");
|
|
2200
|
+
* text.insert(0, "Hello");
|
|
2201
|
+
* // get all updates of the doc
|
|
2202
|
+
* const updates = doc.export({ mode: "update" });
|
|
2203
|
+
* const snapshot = doc.export({ mode: "snapshot" });
|
|
2204
|
+
* const doc2 = new LoroDoc();
|
|
2205
|
+
* // import snapshot
|
|
2206
|
+
* doc2.import(snapshot);
|
|
2207
|
+
* // or import updates
|
|
2208
|
+
* doc2.import(updates);
|
|
2209
|
+
* ```
|
|
2210
|
+
*/
|
|
2351
2211
|
import(update_or_snapshot: Uint8Array): ImportStatus;
|
|
2352
|
-
/**
|
|
2353
|
-
* Import a batch of updates and snapshots.
|
|
2354
|
-
*
|
|
2355
|
-
* It's more efficient than importing updates one by one.
|
|
2356
|
-
*
|
|
2357
|
-
* @deprecated Use `importBatch` instead.
|
|
2358
|
-
*
|
|
2359
|
-
* @example
|
|
2360
|
-
* ```ts
|
|
2361
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2362
|
-
*
|
|
2363
|
-
* const doc = new LoroDoc();
|
|
2364
|
-
* const text = doc.getText("text");
|
|
2365
|
-
* text.insert(0, "Hello");
|
|
2366
|
-
* const updates = doc.export({ mode: "update" });
|
|
2367
|
-
* const snapshot = doc.export({ mode: "snapshot" });
|
|
2368
|
-
* const doc2 = new LoroDoc();
|
|
2369
|
-
* doc2.importBatch([snapshot, updates]);
|
|
2370
|
-
* ```
|
|
2371
|
-
|
|
2372
|
-
* @returns {ImportStatus}
|
|
2373
|
-
*/
|
|
2212
|
+
/**
|
|
2213
|
+
* Import a batch of updates and snapshots.
|
|
2214
|
+
*
|
|
2215
|
+
* It's more efficient than importing updates one by one.
|
|
2216
|
+
*
|
|
2217
|
+
* @deprecated Use `importBatch` instead.
|
|
2218
|
+
*
|
|
2219
|
+
* @example
|
|
2220
|
+
* ```ts
|
|
2221
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2222
|
+
*
|
|
2223
|
+
* const doc = new LoroDoc();
|
|
2224
|
+
* const text = doc.getText("text");
|
|
2225
|
+
* text.insert(0, "Hello");
|
|
2226
|
+
* const updates = doc.export({ mode: "update" });
|
|
2227
|
+
* const snapshot = doc.export({ mode: "snapshot" });
|
|
2228
|
+
* const doc2 = new LoroDoc();
|
|
2229
|
+
* doc2.importBatch([snapshot, updates]);
|
|
2230
|
+
* ```
|
|
2231
|
+
*/
|
|
2374
2232
|
importUpdateBatch(data: Uint8Array[]): ImportStatus;
|
|
2375
|
-
/**
|
|
2376
|
-
* Import a batch of updates or snapshots.
|
|
2377
|
-
*
|
|
2378
|
-
* It's more efficient than importing updates one by one.
|
|
2379
|
-
*
|
|
2380
|
-
* @example
|
|
2381
|
-
* ```ts
|
|
2382
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2383
|
-
*
|
|
2384
|
-
* const doc = new LoroDoc();
|
|
2385
|
-
* const text = doc.getText("text");
|
|
2386
|
-
* text.insert(0, "Hello");
|
|
2387
|
-
* const updates = doc.export({ mode: "update" });
|
|
2388
|
-
* const snapshot = doc.export({ mode: "snapshot" });
|
|
2389
|
-
* const doc2 = new LoroDoc();
|
|
2390
|
-
* doc2.importBatch([snapshot, updates]);
|
|
2391
|
-
* ```
|
|
2392
|
-
|
|
2393
|
-
* @returns {ImportStatus}
|
|
2394
|
-
*/
|
|
2233
|
+
/**
|
|
2234
|
+
* Import a batch of updates or snapshots.
|
|
2235
|
+
*
|
|
2236
|
+
* It's more efficient than importing updates one by one.
|
|
2237
|
+
*
|
|
2238
|
+
* @example
|
|
2239
|
+
* ```ts
|
|
2240
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2241
|
+
*
|
|
2242
|
+
* const doc = new LoroDoc();
|
|
2243
|
+
* const text = doc.getText("text");
|
|
2244
|
+
* text.insert(0, "Hello");
|
|
2245
|
+
* const updates = doc.export({ mode: "update" });
|
|
2246
|
+
* const snapshot = doc.export({ mode: "snapshot" });
|
|
2247
|
+
* const doc2 = new LoroDoc();
|
|
2248
|
+
* doc2.importBatch([snapshot, updates]);
|
|
2249
|
+
* ```
|
|
2250
|
+
*/
|
|
2395
2251
|
importBatch(data: Uint8Array[]): ImportStatus;
|
|
2396
|
-
/**
|
|
2397
|
-
* Get the shallow json format of the document state.
|
|
2398
|
-
*
|
|
2399
|
-
* Unlike `toJSON()` which recursively resolves all containers to their values,
|
|
2400
|
-
* `getShallowValue()` returns container IDs as strings for any nested containers.
|
|
2401
|
-
*
|
|
2402
|
-
* @example
|
|
2403
|
-
* ```ts
|
|
2404
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2405
|
-
*
|
|
2406
|
-
* const doc = new LoroDoc();
|
|
2407
|
-
* const list = doc.getList("list");
|
|
2408
|
-
* const tree = doc.getTree("tree");
|
|
2409
|
-
* const map = doc.getMap("map");
|
|
2410
|
-
* const shallowValue = doc.getShallowValue();
|
|
2411
|
-
* console.log(shallowValue);
|
|
2412
|
-
* // {
|
|
2413
|
-
* // list: 'cid:root-list:List',
|
|
2414
|
-
* // tree: 'cid:root-tree:Tree',
|
|
2415
|
-
* // map: 'cid:root-map:Map'
|
|
2416
|
-
* // }
|
|
2417
|
-
*
|
|
2418
|
-
* // It points to the same container as `list`
|
|
2419
|
-
* const listB = doc.getContainerById(shallowValue.list);
|
|
2420
|
-
* ```
|
|
2421
|
-
|
|
2422
|
-
*/
|
|
2252
|
+
/**
|
|
2253
|
+
* Get the shallow json format of the document state.
|
|
2254
|
+
*
|
|
2255
|
+
* Unlike `toJSON()` which recursively resolves all containers to their values,
|
|
2256
|
+
* `getShallowValue()` returns container IDs as strings for any nested containers.
|
|
2257
|
+
*
|
|
2258
|
+
* @example
|
|
2259
|
+
* ```ts
|
|
2260
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2261
|
+
*
|
|
2262
|
+
* const doc = new LoroDoc();
|
|
2263
|
+
* const list = doc.getList("list");
|
|
2264
|
+
* const tree = doc.getTree("tree");
|
|
2265
|
+
* const map = doc.getMap("map");
|
|
2266
|
+
* const shallowValue = doc.getShallowValue();
|
|
2267
|
+
* console.log(shallowValue);
|
|
2268
|
+
* // {
|
|
2269
|
+
* // list: 'cid:root-list:List',
|
|
2270
|
+
* // tree: 'cid:root-tree:Tree',
|
|
2271
|
+
* // map: 'cid:root-map:Map'
|
|
2272
|
+
* // }
|
|
2273
|
+
*
|
|
2274
|
+
* // It points to the same container as `list`
|
|
2275
|
+
* const listB = doc.getContainerById(shallowValue.list);
|
|
2276
|
+
* ```
|
|
2277
|
+
*/
|
|
2423
2278
|
getShallowValue(): Record<string, ContainerID>;
|
|
2424
|
-
/**
|
|
2425
|
-
* Get the json format of the entire document state.
|
|
2426
|
-
*
|
|
2427
|
-
* Unlike `getShallowValue()` which returns container IDs as strings,
|
|
2428
|
-
* `toJSON()` recursively resolves all containers to their actual values.
|
|
2429
|
-
*
|
|
2430
|
-
* @example
|
|
2431
|
-
* ```ts
|
|
2432
|
-
* import { LoroDoc, LoroText, LoroMap } from "loro-crdt";
|
|
2433
|
-
*
|
|
2434
|
-
* const doc = new LoroDoc();
|
|
2435
|
-
* const list = doc.getList("list");
|
|
2436
|
-
* list.insert(0, "Hello");
|
|
2437
|
-
* const text = list.insertContainer(0, new LoroText());
|
|
2438
|
-
* text.insert(0, "Hello");
|
|
2439
|
-
* const map = list.insertContainer(1, new LoroMap());
|
|
2440
|
-
* map.set("foo", "bar");
|
|
2441
|
-
* console.log(doc.toJSON());
|
|
2442
|
-
* // {"list": ["Hello", {"foo": "bar"}]}
|
|
2443
|
-
* ```
|
|
2444
|
-
|
|
2445
|
-
*/
|
|
2279
|
+
/**
|
|
2280
|
+
* Get the json format of the entire document state.
|
|
2281
|
+
*
|
|
2282
|
+
* Unlike `getShallowValue()` which returns container IDs as strings,
|
|
2283
|
+
* `toJSON()` recursively resolves all containers to their actual values.
|
|
2284
|
+
*
|
|
2285
|
+
* @example
|
|
2286
|
+
* ```ts
|
|
2287
|
+
* import { LoroDoc, LoroText, LoroMap } from "loro-crdt";
|
|
2288
|
+
*
|
|
2289
|
+
* const doc = new LoroDoc();
|
|
2290
|
+
* const list = doc.getList("list");
|
|
2291
|
+
* list.insert(0, "Hello");
|
|
2292
|
+
* const text = list.insertContainer(0, new LoroText());
|
|
2293
|
+
* text.insert(0, "Hello");
|
|
2294
|
+
* const map = list.insertContainer(1, new LoroMap());
|
|
2295
|
+
* map.set("foo", "bar");
|
|
2296
|
+
* console.log(doc.toJSON());
|
|
2297
|
+
* // {"list": ["Hello", {"foo": "bar"}]}
|
|
2298
|
+
* ```
|
|
2299
|
+
*/
|
|
2446
2300
|
toJSON(): any;
|
|
2447
|
-
/**
|
|
2448
|
-
* Debug the size of the history
|
|
2449
|
-
*/
|
|
2301
|
+
/**
|
|
2302
|
+
* Debug the size of the history
|
|
2303
|
+
*/
|
|
2450
2304
|
debugHistory(): void;
|
|
2451
|
-
/**
|
|
2452
|
-
* Get the number of changes in the oplog.
|
|
2453
|
-
|
|
2454
|
-
*/
|
|
2305
|
+
/**
|
|
2306
|
+
* Get the number of changes in the oplog.
|
|
2307
|
+
*/
|
|
2455
2308
|
changeCount(): number;
|
|
2456
|
-
/**
|
|
2457
|
-
* Get the number of ops in the oplog.
|
|
2458
|
-
|
|
2459
|
-
*/
|
|
2309
|
+
/**
|
|
2310
|
+
* Get the number of ops in the oplog.
|
|
2311
|
+
*/
|
|
2460
2312
|
opCount(): number;
|
|
2461
|
-
/**
|
|
2462
|
-
* Get all of changes in the oplog.
|
|
2463
|
-
*
|
|
2464
|
-
* Note: this method is expensive when the oplog is large. O(n)
|
|
2465
|
-
*
|
|
2466
|
-
* @example
|
|
2467
|
-
* ```ts
|
|
2468
|
-
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2469
|
-
*
|
|
2470
|
-
* const doc = new LoroDoc();
|
|
2471
|
-
* const text = doc.getText("text");
|
|
2472
|
-
* text.insert(0, "Hello");
|
|
2473
|
-
* const changes = doc.getAllChanges();
|
|
2474
|
-
*
|
|
2475
|
-
* for (let [peer, c] of changes.entries()){
|
|
2476
|
-
* console.log("peer: ", peer);
|
|
2477
|
-
* for (let change of c){
|
|
2478
|
-
* console.log("change: ", change);
|
|
2479
|
-
* }
|
|
2480
|
-
* }
|
|
2481
|
-
* ```
|
|
2482
|
-
|
|
2483
|
-
*/
|
|
2313
|
+
/**
|
|
2314
|
+
* Get all of changes in the oplog.
|
|
2315
|
+
*
|
|
2316
|
+
* Note: this method is expensive when the oplog is large. O(n)
|
|
2317
|
+
*
|
|
2318
|
+
* @example
|
|
2319
|
+
* ```ts
|
|
2320
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2321
|
+
*
|
|
2322
|
+
* const doc = new LoroDoc();
|
|
2323
|
+
* const text = doc.getText("text");
|
|
2324
|
+
* text.insert(0, "Hello");
|
|
2325
|
+
* const changes = doc.getAllChanges();
|
|
2326
|
+
*
|
|
2327
|
+
* for (let [peer, c] of changes.entries()){
|
|
2328
|
+
* console.log("peer: ", peer);
|
|
2329
|
+
* for (let change of c){
|
|
2330
|
+
* console.log("change: ", change);
|
|
2331
|
+
* }
|
|
2332
|
+
* }
|
|
2333
|
+
* ```
|
|
2334
|
+
*/
|
|
2484
2335
|
getAllChanges(): Map<PeerID, Change[]>;
|
|
2485
|
-
/**
|
|
2486
|
-
* Get the change that contains the specific ID
|
|
2487
|
-
|
|
2488
|
-
* @returns {Change}
|
|
2489
|
-
*/
|
|
2336
|
+
/**
|
|
2337
|
+
* Get the change that contains the specific ID
|
|
2338
|
+
*/
|
|
2490
2339
|
getChangeAt(id: { peer: PeerID, counter: number }): Change;
|
|
2491
|
-
/**
|
|
2492
|
-
* Get the change of with specific peer_id and lamport <= given lamport
|
|
2493
|
-
|
|
2494
|
-
* @param {number} lamport
|
|
2495
|
-
* @returns {Change | undefined}
|
|
2496
|
-
*/
|
|
2340
|
+
/**
|
|
2341
|
+
* Get the change of with specific peer_id and lamport <= given lamport
|
|
2342
|
+
*/
|
|
2497
2343
|
getChangeAtLamport(peer_id: string, lamport: number): Change | undefined;
|
|
2498
|
-
/**
|
|
2499
|
-
* Get all ops of the change that contains the specific ID
|
|
2500
|
-
|
|
2501
|
-
* @returns {any[]}
|
|
2502
|
-
*/
|
|
2344
|
+
/**
|
|
2345
|
+
* Get all ops of the change that contains the specific ID
|
|
2346
|
+
*/
|
|
2503
2347
|
getOpsInChange(id: { peer: PeerID, counter: number }): any[];
|
|
2504
|
-
/**
|
|
2505
|
-
* Convert frontiers to a version vector
|
|
2506
|
-
*
|
|
2507
|
-
* Learn more about frontiers and version vector [here](https://loro.dev/docs/advanced/version_deep_dive)
|
|
2508
|
-
*
|
|
2509
|
-
* @example
|
|
2510
|
-
* ```ts
|
|
2511
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2512
|
-
*
|
|
2513
|
-
* const doc = new LoroDoc();
|
|
2514
|
-
* const text = doc.getText("text");
|
|
2515
|
-
* text.insert(0, "Hello");
|
|
2516
|
-
* const frontiers = doc.frontiers();
|
|
2517
|
-
* const version = doc.frontiersToVV(frontiers);
|
|
2518
|
-
* ```
|
|
2519
|
-
|
|
2520
|
-
* @returns {VersionVector}
|
|
2521
|
-
*/
|
|
2348
|
+
/**
|
|
2349
|
+
* Convert frontiers to a version vector
|
|
2350
|
+
*
|
|
2351
|
+
* Learn more about frontiers and version vector [here](https://loro.dev/docs/advanced/version_deep_dive)
|
|
2352
|
+
*
|
|
2353
|
+
* @example
|
|
2354
|
+
* ```ts
|
|
2355
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2356
|
+
*
|
|
2357
|
+
* const doc = new LoroDoc();
|
|
2358
|
+
* const text = doc.getText("text");
|
|
2359
|
+
* text.insert(0, "Hello");
|
|
2360
|
+
* const frontiers = doc.frontiers();
|
|
2361
|
+
* const version = doc.frontiersToVV(frontiers);
|
|
2362
|
+
* ```
|
|
2363
|
+
*/
|
|
2522
2364
|
frontiersToVV(frontiers: ({ peer: PeerID, counter: number })[]): VersionVector;
|
|
2523
|
-
/**
|
|
2524
|
-
* Convert a version vector to frontiers
|
|
2525
|
-
*
|
|
2526
|
-
* @example
|
|
2527
|
-
* ```ts
|
|
2528
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2529
|
-
*
|
|
2530
|
-
* const doc = new LoroDoc();
|
|
2531
|
-
* const text = doc.getText("text");
|
|
2532
|
-
* text.insert(0, "Hello");
|
|
2533
|
-
* const version = doc.version();
|
|
2534
|
-
* const frontiers = doc.vvToFrontiers(version);
|
|
2535
|
-
* ```
|
|
2536
|
-
|
|
2537
|
-
* @returns {{ peer: PeerID, counter: number }[]}
|
|
2538
|
-
*/
|
|
2365
|
+
/**
|
|
2366
|
+
* Convert a version vector to frontiers
|
|
2367
|
+
*
|
|
2368
|
+
* @example
|
|
2369
|
+
* ```ts
|
|
2370
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2371
|
+
*
|
|
2372
|
+
* const doc = new LoroDoc();
|
|
2373
|
+
* const text = doc.getText("text");
|
|
2374
|
+
* text.insert(0, "Hello");
|
|
2375
|
+
* const version = doc.version();
|
|
2376
|
+
* const frontiers = doc.vvToFrontiers(version);
|
|
2377
|
+
* ```
|
|
2378
|
+
*/
|
|
2539
2379
|
vvToFrontiers(vv: VersionVector): { peer: PeerID, counter: number }[];
|
|
2540
|
-
/**
|
|
2541
|
-
* Get the value or container at the given path
|
|
2542
|
-
*
|
|
2543
|
-
* The path can be specified in different ways depending on the container type:
|
|
2544
|
-
*
|
|
2545
|
-
* For Tree:
|
|
2546
|
-
* 1. Using node IDs: `tree/{node_id}/property`
|
|
2547
|
-
* 2. Using indices: `tree/0/1/property`
|
|
2548
|
-
*
|
|
2549
|
-
* For List and MovableList:
|
|
2550
|
-
* - Using indices: `list/0` or `list/1/property`
|
|
2551
|
-
*
|
|
2552
|
-
* For Map:
|
|
2553
|
-
* - Using keys: `map/key` or `map/nested/property`
|
|
2554
|
-
*
|
|
2555
|
-
* For tree structures, index-based paths follow depth-first traversal order.
|
|
2556
|
-
* The indices start from 0 and represent the position of a node among its siblings.
|
|
2557
|
-
*
|
|
2558
|
-
* @example
|
|
2559
|
-
* ```ts
|
|
2560
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2561
|
-
*
|
|
2562
|
-
* const doc = new LoroDoc();
|
|
2563
|
-
* const map = doc.getMap("map");
|
|
2564
|
-
* map.set("key", 1);
|
|
2565
|
-
* console.log(doc.getByPath("map/key")); // 1
|
|
2566
|
-
* console.log(doc.getByPath("map")); // LoroMap
|
|
2567
|
-
* ```
|
|
2568
|
-
|
|
2569
|
-
* @returns {Value | Container | undefined}
|
|
2570
|
-
*/
|
|
2380
|
+
/**
|
|
2381
|
+
* Get the value or container at the given path
|
|
2382
|
+
*
|
|
2383
|
+
* The path can be specified in different ways depending on the container type:
|
|
2384
|
+
*
|
|
2385
|
+
* For Tree:
|
|
2386
|
+
* 1. Using node IDs: `tree/{node_id}/property`
|
|
2387
|
+
* 2. Using indices: `tree/0/1/property`
|
|
2388
|
+
*
|
|
2389
|
+
* For List and MovableList:
|
|
2390
|
+
* - Using indices: `list/0` or `list/1/property`
|
|
2391
|
+
*
|
|
2392
|
+
* For Map:
|
|
2393
|
+
* - Using keys: `map/key` or `map/nested/property`
|
|
2394
|
+
*
|
|
2395
|
+
* For tree structures, index-based paths follow depth-first traversal order.
|
|
2396
|
+
* The indices start from 0 and represent the position of a node among its siblings.
|
|
2397
|
+
*
|
|
2398
|
+
* @example
|
|
2399
|
+
* ```ts
|
|
2400
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2401
|
+
*
|
|
2402
|
+
* const doc = new LoroDoc();
|
|
2403
|
+
* const map = doc.getMap("map");
|
|
2404
|
+
* map.set("key", 1);
|
|
2405
|
+
* console.log(doc.getByPath("map/key")); // 1
|
|
2406
|
+
* console.log(doc.getByPath("map")); // LoroMap
|
|
2407
|
+
* ```
|
|
2408
|
+
*/
|
|
2571
2409
|
getByPath(path: string): Value | Container | undefined;
|
|
2572
|
-
/**
|
|
2573
|
-
* Get the absolute position of the given Cursor
|
|
2574
|
-
*
|
|
2575
|
-
* @example
|
|
2576
|
-
* ```ts
|
|
2577
|
-
* const doc = new LoroDoc();
|
|
2578
|
-
* const text = doc.getText("text");
|
|
2579
|
-
* text.insert(0, "123");
|
|
2580
|
-
* const pos0 = text.getCursor(0, 0);
|
|
2581
|
-
* {
|
|
2582
|
-
* const ans = doc.getCursorPos(pos0!);
|
|
2583
|
-
* expect(ans.offset).toBe(0);
|
|
2584
|
-
* }
|
|
2585
|
-
* text.insert(0, "1");
|
|
2586
|
-
* {
|
|
2587
|
-
* const ans = doc.getCursorPos(pos0!);
|
|
2588
|
-
* expect(ans.offset).toBe(1);
|
|
2589
|
-
* }
|
|
2590
|
-
* ```
|
|
2591
|
-
|
|
2592
|
-
* @returns {{ update?: Cursor, offset: number, side: Side }}
|
|
2593
|
-
*/
|
|
2410
|
+
/**
|
|
2411
|
+
* Get the absolute position of the given Cursor
|
|
2412
|
+
*
|
|
2413
|
+
* @example
|
|
2414
|
+
* ```ts
|
|
2415
|
+
* const doc = new LoroDoc();
|
|
2416
|
+
* const text = doc.getText("text");
|
|
2417
|
+
* text.insert(0, "123");
|
|
2418
|
+
* const pos0 = text.getCursor(0, 0);
|
|
2419
|
+
* {
|
|
2420
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
2421
|
+
* expect(ans.offset).toBe(0);
|
|
2422
|
+
* }
|
|
2423
|
+
* text.insert(0, "1");
|
|
2424
|
+
* {
|
|
2425
|
+
* const ans = doc.getCursorPos(pos0!);
|
|
2426
|
+
* expect(ans.offset).toBe(1);
|
|
2427
|
+
* }
|
|
2428
|
+
* ```
|
|
2429
|
+
*/
|
|
2594
2430
|
getCursorPos(cursor: Cursor): { update?: Cursor, offset: number, side: Side };
|
|
2595
|
-
/**
|
|
2596
|
-
* Gets container IDs modified in the given ID range.
|
|
2597
|
-
*
|
|
2598
|
-
* **NOTE:** This method will implicitly commit.
|
|
2599
|
-
*
|
|
2600
|
-
* This method identifies which containers were affected by changes in a given range of operations.
|
|
2601
|
-
* It can be used together with `doc.travelChangeAncestors()` to analyze the history of changes
|
|
2602
|
-
* and determine which containers were modified by each change.
|
|
2603
|
-
*
|
|
2604
|
-
* @param id - The starting ID of the change range
|
|
2605
|
-
* @param len - The length of the change range to check
|
|
2606
|
-
* @returns An array of container IDs that were modified in the given range
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
*
|
|
2614
|
-
*
|
|
2615
|
-
*
|
|
2616
|
-
*
|
|
2617
|
-
*
|
|
2618
|
-
*
|
|
2619
|
-
*
|
|
2620
|
-
*
|
|
2621
|
-
* doc.
|
|
2622
|
-
*
|
|
2623
|
-
* text.
|
|
2624
|
-
*
|
|
2625
|
-
|
|
2626
|
-
* expect(doc.getText("text").toString()).toBe("He");
|
|
2627
|
-
* ```
|
|
2628
|
-
* @param {({ peer: PeerID, counter: number })[]} frontiers
|
|
2629
|
-
*/
|
|
2431
|
+
/**
|
|
2432
|
+
* Gets container IDs modified in the given ID range.
|
|
2433
|
+
*
|
|
2434
|
+
* **NOTE:** This method will implicitly commit.
|
|
2435
|
+
*
|
|
2436
|
+
* This method identifies which containers were affected by changes in a given range of operations.
|
|
2437
|
+
* It can be used together with `doc.travelChangeAncestors()` to analyze the history of changes
|
|
2438
|
+
* and determine which containers were modified by each change.
|
|
2439
|
+
*
|
|
2440
|
+
* @param id - The starting ID of the change range
|
|
2441
|
+
* @param len - The length of the change range to check
|
|
2442
|
+
* @returns An array of container IDs that were modified in the given range
|
|
2443
|
+
*/
|
|
2444
|
+
getChangedContainersIn(id: { peer: PeerID, counter: number }, len: number): ContainerID[];
|
|
2445
|
+
/**
|
|
2446
|
+
* Revert the document to the given frontiers.
|
|
2447
|
+
*
|
|
2448
|
+
* The doc will not become detached when using this method. Instead, it will generate a series
|
|
2449
|
+
* of operations to revert the document to the given version.
|
|
2450
|
+
*
|
|
2451
|
+
* @example
|
|
2452
|
+
* ```ts
|
|
2453
|
+
* const doc = new LoroDoc();
|
|
2454
|
+
* doc.setPeerId("1");
|
|
2455
|
+
* const text = doc.getText("text");
|
|
2456
|
+
* text.insert(0, "Hello");
|
|
2457
|
+
* doc.commit();
|
|
2458
|
+
* doc.revertTo([{ peer: "1", counter: 1 }]);
|
|
2459
|
+
* expect(doc.getText("text").toString()).toBe("He");
|
|
2460
|
+
* ```
|
|
2461
|
+
*/
|
|
2630
2462
|
revertTo(frontiers: ({ peer: PeerID, counter: number })[]): void;
|
|
2631
|
-
/**
|
|
2632
|
-
* Apply a batch of diff to the document
|
|
2633
|
-
*
|
|
2634
|
-
* A diff batch represents a set of changes between two versions of the document.
|
|
2635
|
-
* You can calculate a diff batch using `doc.diff()`.
|
|
2636
|
-
*
|
|
2637
|
-
* Changes are associated with container IDs. During diff application, if new containers were created in the source
|
|
2638
|
-
* document, they will be assigned fresh IDs in the target document. Loro automatically handles remapping these
|
|
2639
|
-
* container IDs from their original IDs to the new IDs as the diff is applied.
|
|
2640
|
-
*
|
|
2641
|
-
* @example
|
|
2642
|
-
* ```ts
|
|
2643
|
-
* const doc1 = new LoroDoc();
|
|
2644
|
-
* const doc2 = new LoroDoc();
|
|
2645
|
-
*
|
|
2646
|
-
* // Make some changes to doc1
|
|
2647
|
-
* const text = doc1.getText("text");
|
|
2648
|
-
* text.insert(0, "Hello");
|
|
2649
|
-
*
|
|
2650
|
-
* // Calculate diff between empty and current state
|
|
2651
|
-
* const diff = doc1.diff([], doc1.frontiers());
|
|
2652
|
-
*
|
|
2653
|
-
* // Apply changes to doc2
|
|
2654
|
-
* doc2.applyDiff(diff);
|
|
2655
|
-
* console.log(doc2.getText("text").toString()); // "Hello"
|
|
2656
|
-
* ```
|
|
2657
|
-
|
|
2658
|
-
*/
|
|
2463
|
+
/**
|
|
2464
|
+
* Apply a batch of diff to the document
|
|
2465
|
+
*
|
|
2466
|
+
* A diff batch represents a set of changes between two versions of the document.
|
|
2467
|
+
* You can calculate a diff batch using `doc.diff()`.
|
|
2468
|
+
*
|
|
2469
|
+
* Changes are associated with container IDs. During diff application, if new containers were created in the source
|
|
2470
|
+
* document, they will be assigned fresh IDs in the target document. Loro automatically handles remapping these
|
|
2471
|
+
* container IDs from their original IDs to the new IDs as the diff is applied.
|
|
2472
|
+
*
|
|
2473
|
+
* @example
|
|
2474
|
+
* ```ts
|
|
2475
|
+
* const doc1 = new LoroDoc();
|
|
2476
|
+
* const doc2 = new LoroDoc();
|
|
2477
|
+
*
|
|
2478
|
+
* // Make some changes to doc1
|
|
2479
|
+
* const text = doc1.getText("text");
|
|
2480
|
+
* text.insert(0, "Hello");
|
|
2481
|
+
*
|
|
2482
|
+
* // Calculate diff between empty and current state
|
|
2483
|
+
* const diff = doc1.diff([], doc1.frontiers());
|
|
2484
|
+
*
|
|
2485
|
+
* // Apply changes to doc2
|
|
2486
|
+
* doc2.applyDiff(diff);
|
|
2487
|
+
* console.log(doc2.getText("text").toString()); // "Hello"
|
|
2488
|
+
* ```
|
|
2489
|
+
*/
|
|
2659
2490
|
applyDiff(diff: [ContainerID, Diff|JsonDiff][]): void;
|
|
2660
|
-
/**
|
|
2661
|
-
* Get the pending operations from the current transaction in JSON format
|
|
2662
|
-
*
|
|
2663
|
-
* This method returns a JSON representation of operations that have been applied
|
|
2664
|
-
* but not yet committed in the current transaction.
|
|
2665
|
-
*
|
|
2666
|
-
* It will use the same data format as `doc.exportJsonUpdates()`
|
|
2667
|
-
*
|
|
2668
|
-
* @example
|
|
2669
|
-
* ```ts
|
|
2670
|
-
* const doc = new LoroDoc();
|
|
2671
|
-
* const text = doc.getText("text");
|
|
2672
|
-
* text.insert(0, "Hello");
|
|
2673
|
-
* // Get pending ops before commit
|
|
2674
|
-
* const pendingOps = doc.getPendingOpsFromCurrentTxnAsJson();
|
|
2675
|
-
* doc.commit();
|
|
2676
|
-
* const emptyOps = doc.getPendingOpsFromCurrentTxnAsJson(); // this is undefined
|
|
2677
|
-
* ```
|
|
2678
|
-
|
|
2679
|
-
*/
|
|
2491
|
+
/**
|
|
2492
|
+
* Get the pending operations from the current transaction in JSON format
|
|
2493
|
+
*
|
|
2494
|
+
* This method returns a JSON representation of operations that have been applied
|
|
2495
|
+
* but not yet committed in the current transaction.
|
|
2496
|
+
*
|
|
2497
|
+
* It will use the same data format as `doc.exportJsonUpdates()`
|
|
2498
|
+
*
|
|
2499
|
+
* @example
|
|
2500
|
+
* ```ts
|
|
2501
|
+
* const doc = new LoroDoc();
|
|
2502
|
+
* const text = doc.getText("text");
|
|
2503
|
+
* text.insert(0, "Hello");
|
|
2504
|
+
* // Get pending ops before commit
|
|
2505
|
+
* const pendingOps = doc.getPendingOpsFromCurrentTxnAsJson();
|
|
2506
|
+
* doc.commit();
|
|
2507
|
+
* const emptyOps = doc.getPendingOpsFromCurrentTxnAsJson(); // this is undefined
|
|
2508
|
+
* ```
|
|
2509
|
+
*/
|
|
2680
2510
|
getUncommittedOpsAsJson(): JsonSchema | undefined;
|
|
2681
|
-
/**
|
|
2682
|
-
* Peer ID of the current writer.
|
|
2683
|
-
*/
|
|
2511
|
+
/**
|
|
2512
|
+
* Peer ID of the current writer.
|
|
2513
|
+
*/
|
|
2684
2514
|
readonly peerId: bigint;
|
|
2685
|
-
/**
|
|
2686
|
-
* Get peer id in decimal string.
|
|
2687
|
-
*/
|
|
2515
|
+
/**
|
|
2516
|
+
* Get peer id in decimal string.
|
|
2517
|
+
*/
|
|
2688
2518
|
readonly peerIdStr: PeerID;
|
|
2689
2519
|
}
|
|
2690
2520
|
/**
|
|
2691
|
-
* The handler of a list container.
|
|
2692
|
-
*
|
|
2693
|
-
* Learn more at https://loro.dev/docs/tutorial/list
|
|
2694
|
-
*/
|
|
2521
|
+
* The handler of a list container.
|
|
2522
|
+
*
|
|
2523
|
+
* Learn more at https://loro.dev/docs/tutorial/list
|
|
2524
|
+
*/
|
|
2695
2525
|
export class LoroList {
|
|
2696
2526
|
free(): void;
|
|
2697
|
-
/**
|
|
2698
|
-
* Create a new detached LoroList (not attached to any LoroDoc).
|
|
2699
|
-
*
|
|
2700
|
-
* The edits on a detached container will not be persisted.
|
|
2701
|
-
* To attach the container to the document, please insert it into an attached container.
|
|
2702
|
-
*/
|
|
2527
|
+
/**
|
|
2528
|
+
* Create a new detached LoroList (not attached to any LoroDoc).
|
|
2529
|
+
*
|
|
2530
|
+
* The edits on a detached container will not be persisted.
|
|
2531
|
+
* To attach the container to the document, please insert it into an attached container.
|
|
2532
|
+
*/
|
|
2703
2533
|
constructor();
|
|
2704
|
-
/**
|
|
2705
|
-
* "List"
|
|
2706
|
-
|
|
2707
|
-
*/
|
|
2534
|
+
/**
|
|
2535
|
+
* "List"
|
|
2536
|
+
*/
|
|
2708
2537
|
kind(): 'List';
|
|
2709
|
-
/**
|
|
2710
|
-
* Delete elements from index to index + len.
|
|
2711
|
-
*
|
|
2712
|
-
* @example
|
|
2713
|
-
* ```ts
|
|
2714
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2715
|
-
*
|
|
2716
|
-
* const doc = new LoroDoc();
|
|
2717
|
-
* const list = doc.getList("list");
|
|
2718
|
-
* list.insert(0, 100);
|
|
2719
|
-
* list.delete(0, 1);
|
|
2720
|
-
* console.log(list.value); // []
|
|
2721
|
-
* ```
|
|
2722
|
-
|
|
2723
|
-
* @param {number} len
|
|
2724
|
-
*/
|
|
2538
|
+
/**
|
|
2539
|
+
* Delete elements from index to index + len.
|
|
2540
|
+
*
|
|
2541
|
+
* @example
|
|
2542
|
+
* ```ts
|
|
2543
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2544
|
+
*
|
|
2545
|
+
* const doc = new LoroDoc();
|
|
2546
|
+
* const list = doc.getList("list");
|
|
2547
|
+
* list.insert(0, 100);
|
|
2548
|
+
* list.delete(0, 1);
|
|
2549
|
+
* console.log(list.value); // []
|
|
2550
|
+
* ```
|
|
2551
|
+
*/
|
|
2725
2552
|
delete(index: number, len: number): void;
|
|
2726
|
-
/**
|
|
2727
|
-
* Get elements of the list. If the type of a element is a container, it will be
|
|
2728
|
-
* resolved recursively.
|
|
2729
|
-
*
|
|
2730
|
-
* @example
|
|
2731
|
-
* ```ts
|
|
2732
|
-
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2733
|
-
*
|
|
2734
|
-
* const doc = new LoroDoc();
|
|
2735
|
-
* const list = doc.getList("list");
|
|
2736
|
-
* list.insert(0, 100);
|
|
2737
|
-
* const text = list.insertContainer(1, new LoroText());
|
|
2738
|
-
* text.insert(0, "Hello");
|
|
2739
|
-
* console.log(list.toJSON()); // [100, "Hello"];
|
|
2740
|
-
* ```
|
|
2741
|
-
|
|
2742
|
-
*/
|
|
2553
|
+
/**
|
|
2554
|
+
* Get elements of the list. If the type of a element is a container, it will be
|
|
2555
|
+
* resolved recursively.
|
|
2556
|
+
*
|
|
2557
|
+
* @example
|
|
2558
|
+
* ```ts
|
|
2559
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2560
|
+
*
|
|
2561
|
+
* const doc = new LoroDoc();
|
|
2562
|
+
* const list = doc.getList("list");
|
|
2563
|
+
* list.insert(0, 100);
|
|
2564
|
+
* const text = list.insertContainer(1, new LoroText());
|
|
2565
|
+
* text.insert(0, "Hello");
|
|
2566
|
+
* console.log(list.toJSON()); // [100, "Hello"];
|
|
2567
|
+
* ```
|
|
2568
|
+
*/
|
|
2743
2569
|
toJSON(): any;
|
|
2744
|
-
/**
|
|
2745
|
-
* Get the parent container.
|
|
2746
|
-
*
|
|
2747
|
-
* - The parent container of the root tree is `undefined`.
|
|
2748
|
-
* - The object returned is a new js object each time because it need to cross
|
|
2749
|
-
* the WASM boundary.
|
|
2750
|
-
|
|
2751
|
-
*/
|
|
2570
|
+
/**
|
|
2571
|
+
* Get the parent container.
|
|
2572
|
+
*
|
|
2573
|
+
* - The parent container of the root tree is `undefined`.
|
|
2574
|
+
* - The object returned is a new js object each time because it need to cross
|
|
2575
|
+
* the WASM boundary.
|
|
2576
|
+
*/
|
|
2752
2577
|
parent(): Container | undefined;
|
|
2753
|
-
/**
|
|
2754
|
-
* Whether the container is attached to a document.
|
|
2755
|
-
*
|
|
2756
|
-
* If it's detached, the operations on the container will not be persisted.
|
|
2757
|
-
|
|
2758
|
-
*/
|
|
2578
|
+
/**
|
|
2579
|
+
* Whether the container is attached to a document.
|
|
2580
|
+
*
|
|
2581
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
2582
|
+
*/
|
|
2759
2583
|
isAttached(): boolean;
|
|
2760
|
-
/**
|
|
2761
|
-
* Get the attached container associated with this.
|
|
2762
|
-
*
|
|
2763
|
-
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
2764
|
-
|
|
2765
|
-
*/
|
|
2584
|
+
/**
|
|
2585
|
+
* Get the attached container associated with this.
|
|
2586
|
+
*
|
|
2587
|
+
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
2588
|
+
*/
|
|
2766
2589
|
getAttached(): LoroList | undefined;
|
|
2767
|
-
/**
|
|
2768
|
-
* Pop a value from the end of the list.
|
|
2769
|
-
|
|
2770
|
-
*/
|
|
2590
|
+
/**
|
|
2591
|
+
* Pop a value from the end of the list.
|
|
2592
|
+
*/
|
|
2771
2593
|
pop(): Value | undefined;
|
|
2772
|
-
/**
|
|
2773
|
-
* Delete all elements in the list.
|
|
2774
|
-
*/
|
|
2594
|
+
/**
|
|
2595
|
+
* Delete all elements in the list.
|
|
2596
|
+
*/
|
|
2775
2597
|
clear(): void;
|
|
2776
|
-
/**
|
|
2777
|
-
* @param {number} pos
|
|
2778
|
-
* @returns {{ peer: PeerID, counter: number } | undefined}
|
|
2779
|
-
*/
|
|
2780
2598
|
getIdAt(pos: number): { peer: PeerID, counter: number } | undefined;
|
|
2781
|
-
/**
|
|
2782
|
-
* Check if the container is deleted
|
|
2783
|
-
|
|
2784
|
-
*/
|
|
2599
|
+
/**
|
|
2600
|
+
* Check if the container is deleted
|
|
2601
|
+
*/
|
|
2785
2602
|
isDeleted(): boolean;
|
|
2786
|
-
/**
|
|
2787
|
-
* Get the shallow value of the list.
|
|
2788
|
-
*
|
|
2789
|
-
* Unlike `toJSON()` which recursively resolves all containers to their values,
|
|
2790
|
-
* `getShallowValue()` returns container IDs as strings for any nested containers.
|
|
2791
|
-
*
|
|
2792
|
-
* ```js
|
|
2793
|
-
* const doc = new LoroDoc();
|
|
2794
|
-
* doc.setPeerId("1");
|
|
2795
|
-
* const list = doc.getList("list");
|
|
2796
|
-
* list.insert(0, 1);
|
|
2797
|
-
* list.insert(1, "two");
|
|
2798
|
-
* const subList = list.insertContainer(2, new LoroList());
|
|
2799
|
-
* subList.insert(0, "sub");
|
|
2800
|
-
* list.getShallowValue(); // [1, "two", "cid:2@1:List"]
|
|
2801
|
-
* list.toJSON(); // [1, "two", ["sub"]]
|
|
2802
|
-
* ```
|
|
2803
|
-
|
|
2804
|
-
*/
|
|
2603
|
+
/**
|
|
2604
|
+
* Get the shallow value of the list.
|
|
2605
|
+
*
|
|
2606
|
+
* Unlike `toJSON()` which recursively resolves all containers to their values,
|
|
2607
|
+
* `getShallowValue()` returns container IDs as strings for any nested containers.
|
|
2608
|
+
*
|
|
2609
|
+
* ```js
|
|
2610
|
+
* const doc = new LoroDoc();
|
|
2611
|
+
* doc.setPeerId("1");
|
|
2612
|
+
* const list = doc.getList("list");
|
|
2613
|
+
* list.insert(0, 1);
|
|
2614
|
+
* list.insert(1, "two");
|
|
2615
|
+
* const subList = list.insertContainer(2, new LoroList());
|
|
2616
|
+
* subList.insert(0, "sub");
|
|
2617
|
+
* list.getShallowValue(); // [1, "two", "cid:2@1:List"]
|
|
2618
|
+
* list.toJSON(); // [1, "two", ["sub"]]
|
|
2619
|
+
* ```
|
|
2620
|
+
*/
|
|
2805
2621
|
getShallowValue(): Value[];
|
|
2806
|
-
/**
|
|
2807
|
-
* Get the id of this container.
|
|
2808
|
-
*/
|
|
2622
|
+
/**
|
|
2623
|
+
* Get the id of this container.
|
|
2624
|
+
*/
|
|
2809
2625
|
readonly id: ContainerID;
|
|
2810
|
-
/**
|
|
2811
|
-
* Get the length of list.
|
|
2812
|
-
*
|
|
2813
|
-
* @example
|
|
2814
|
-
* ```ts
|
|
2815
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2816
|
-
*
|
|
2817
|
-
* const doc = new LoroDoc();
|
|
2818
|
-
* const list = doc.getList("list");
|
|
2819
|
-
* list.insert(0, 100);
|
|
2820
|
-
* list.insert(1, "foo");
|
|
2821
|
-
* list.insert(2, true);
|
|
2822
|
-
* console.log(list.length); // 3
|
|
2823
|
-
* ```
|
|
2824
|
-
*/
|
|
2626
|
+
/**
|
|
2627
|
+
* Get the length of list.
|
|
2628
|
+
*
|
|
2629
|
+
* @example
|
|
2630
|
+
* ```ts
|
|
2631
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2632
|
+
*
|
|
2633
|
+
* const doc = new LoroDoc();
|
|
2634
|
+
* const list = doc.getList("list");
|
|
2635
|
+
* list.insert(0, 100);
|
|
2636
|
+
* list.insert(1, "foo");
|
|
2637
|
+
* list.insert(2, true);
|
|
2638
|
+
* console.log(list.length); // 3
|
|
2639
|
+
* ```
|
|
2640
|
+
*/
|
|
2825
2641
|
readonly length: number;
|
|
2826
2642
|
}
|
|
2827
2643
|
/**
|
|
2828
|
-
* The handler of a map container.
|
|
2829
|
-
*
|
|
2830
|
-
* Learn more at https://loro.dev/docs/tutorial/map
|
|
2831
|
-
*/
|
|
2644
|
+
* The handler of a map container.
|
|
2645
|
+
*
|
|
2646
|
+
* Learn more at https://loro.dev/docs/tutorial/map
|
|
2647
|
+
*/
|
|
2832
2648
|
export class LoroMap {
|
|
2833
2649
|
free(): void;
|
|
2834
|
-
/**
|
|
2835
|
-
* Create a new detached LoroMap (not attached to any LoroDoc).
|
|
2836
|
-
*
|
|
2837
|
-
* The edits on a detached container will not be persisted.
|
|
2838
|
-
* To attach the container to the document, please insert it into an attached container.
|
|
2839
|
-
*/
|
|
2650
|
+
/**
|
|
2651
|
+
* Create a new detached LoroMap (not attached to any LoroDoc).
|
|
2652
|
+
*
|
|
2653
|
+
* The edits on a detached container will not be persisted.
|
|
2654
|
+
* To attach the container to the document, please insert it into an attached container.
|
|
2655
|
+
*/
|
|
2840
2656
|
constructor();
|
|
2841
|
-
/**
|
|
2842
|
-
* "Map"
|
|
2843
|
-
|
|
2844
|
-
*/
|
|
2657
|
+
/**
|
|
2658
|
+
* "Map"
|
|
2659
|
+
*/
|
|
2845
2660
|
kind(): 'Map';
|
|
2846
|
-
/**
|
|
2847
|
-
* Remove the key from the map.
|
|
2848
|
-
*
|
|
2849
|
-
* @example
|
|
2850
|
-
* ```ts
|
|
2851
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2852
|
-
*
|
|
2853
|
-
* const doc = new LoroDoc();
|
|
2854
|
-
* const map = doc.getMap("map");
|
|
2855
|
-
* map.set("foo", "bar");
|
|
2856
|
-
* map.delete("foo");
|
|
2857
|
-
* ```
|
|
2858
|
-
|
|
2859
|
-
*/
|
|
2661
|
+
/**
|
|
2662
|
+
* Remove the key from the map.
|
|
2663
|
+
*
|
|
2664
|
+
* @example
|
|
2665
|
+
* ```ts
|
|
2666
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2667
|
+
*
|
|
2668
|
+
* const doc = new LoroDoc();
|
|
2669
|
+
* const map = doc.getMap("map");
|
|
2670
|
+
* map.set("foo", "bar");
|
|
2671
|
+
* map.delete("foo");
|
|
2672
|
+
* ```
|
|
2673
|
+
*/
|
|
2860
2674
|
delete(key: string): void;
|
|
2861
|
-
/**
|
|
2862
|
-
* Get the keys of the map.
|
|
2863
|
-
*
|
|
2864
|
-
* @example
|
|
2865
|
-
* ```ts
|
|
2866
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2867
|
-
*
|
|
2868
|
-
* const doc = new LoroDoc();
|
|
2869
|
-
* const map = doc.getMap("map");
|
|
2870
|
-
* map.set("foo", "bar");
|
|
2871
|
-
* map.set("baz", "bar");
|
|
2872
|
-
* const keys = map.keys(); // ["foo", "baz"]
|
|
2873
|
-
* ```
|
|
2874
|
-
|
|
2875
|
-
*/
|
|
2675
|
+
/**
|
|
2676
|
+
* Get the keys of the map.
|
|
2677
|
+
*
|
|
2678
|
+
* @example
|
|
2679
|
+
* ```ts
|
|
2680
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2681
|
+
*
|
|
2682
|
+
* const doc = new LoroDoc();
|
|
2683
|
+
* const map = doc.getMap("map");
|
|
2684
|
+
* map.set("foo", "bar");
|
|
2685
|
+
* map.set("baz", "bar");
|
|
2686
|
+
* const keys = map.keys(); // ["foo", "baz"]
|
|
2687
|
+
* ```
|
|
2688
|
+
*/
|
|
2876
2689
|
keys(): any[];
|
|
2877
|
-
/**
|
|
2878
|
-
* Get the values of the map. If the value is a child container, the corresponding
|
|
2879
|
-
* `Container` will be returned.
|
|
2880
|
-
*
|
|
2881
|
-
* @example
|
|
2882
|
-
* ```ts
|
|
2883
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2884
|
-
*
|
|
2885
|
-
* const doc = new LoroDoc();
|
|
2886
|
-
* const map = doc.getMap("map");
|
|
2887
|
-
* map.set("foo", "bar");
|
|
2888
|
-
* map.set("baz", "bar");
|
|
2889
|
-
* const values = map.values(); // ["bar", "bar"]
|
|
2890
|
-
* ```
|
|
2891
|
-
|
|
2892
|
-
*/
|
|
2690
|
+
/**
|
|
2691
|
+
* Get the values of the map. If the value is a child container, the corresponding
|
|
2692
|
+
* `Container` will be returned.
|
|
2693
|
+
*
|
|
2694
|
+
* @example
|
|
2695
|
+
* ```ts
|
|
2696
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2697
|
+
*
|
|
2698
|
+
* const doc = new LoroDoc();
|
|
2699
|
+
* const map = doc.getMap("map");
|
|
2700
|
+
* map.set("foo", "bar");
|
|
2701
|
+
* map.set("baz", "bar");
|
|
2702
|
+
* const values = map.values(); // ["bar", "bar"]
|
|
2703
|
+
* ```
|
|
2704
|
+
*/
|
|
2893
2705
|
values(): any[];
|
|
2894
|
-
/**
|
|
2895
|
-
* Get the entries of the map. If the value is a child container, the corresponding
|
|
2896
|
-
* `Container` will be returned.
|
|
2897
|
-
*
|
|
2898
|
-
* @example
|
|
2899
|
-
* ```ts
|
|
2900
|
-
* import { LoroDoc } from "loro-crdt";
|
|
2901
|
-
*
|
|
2902
|
-
* const doc = new LoroDoc();
|
|
2903
|
-
* const map = doc.getMap("map");
|
|
2904
|
-
* map.set("foo", "bar");
|
|
2905
|
-
* map.set("baz", "bar");
|
|
2906
|
-
* const entries = map.entries(); // [["foo", "bar"], ["baz", "bar"]]
|
|
2907
|
-
* ```
|
|
2908
|
-
|
|
2909
|
-
*/
|
|
2706
|
+
/**
|
|
2707
|
+
* Get the entries of the map. If the value is a child container, the corresponding
|
|
2708
|
+
* `Container` will be returned.
|
|
2709
|
+
*
|
|
2710
|
+
* @example
|
|
2711
|
+
* ```ts
|
|
2712
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2713
|
+
*
|
|
2714
|
+
* const doc = new LoroDoc();
|
|
2715
|
+
* const map = doc.getMap("map");
|
|
2716
|
+
* map.set("foo", "bar");
|
|
2717
|
+
* map.set("baz", "bar");
|
|
2718
|
+
* const entries = map.entries(); // [["foo", "bar"], ["baz", "bar"]]
|
|
2719
|
+
* ```
|
|
2720
|
+
*/
|
|
2910
2721
|
entries(): ([string, Value | Container])[];
|
|
2911
|
-
/**
|
|
2912
|
-
* Get the keys and the values. If the type of value is a child container,
|
|
2913
|
-
* it will be resolved recursively.
|
|
2914
|
-
*
|
|
2915
|
-
* @example
|
|
2916
|
-
* ```ts
|
|
2917
|
-
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2918
|
-
*
|
|
2919
|
-
* const doc = new LoroDoc();
|
|
2920
|
-
* const map = doc.getMap("map");
|
|
2921
|
-
* map.set("foo", "bar");
|
|
2922
|
-
* const text = map.setContainer("text", new LoroText());
|
|
2923
|
-
* text.insert(0, "Hello");
|
|
2924
|
-
* console.log(map.toJSON()); // {"foo": "bar", "text": "Hello"}
|
|
2925
|
-
* ```
|
|
2926
|
-
|
|
2927
|
-
*/
|
|
2722
|
+
/**
|
|
2723
|
+
* Get the keys and the values. If the type of value is a child container,
|
|
2724
|
+
* it will be resolved recursively.
|
|
2725
|
+
*
|
|
2726
|
+
* @example
|
|
2727
|
+
* ```ts
|
|
2728
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2729
|
+
*
|
|
2730
|
+
* const doc = new LoroDoc();
|
|
2731
|
+
* const map = doc.getMap("map");
|
|
2732
|
+
* map.set("foo", "bar");
|
|
2733
|
+
* const text = map.setContainer("text", new LoroText());
|
|
2734
|
+
* text.insert(0, "Hello");
|
|
2735
|
+
* console.log(map.toJSON()); // {"foo": "bar", "text": "Hello"}
|
|
2736
|
+
* ```
|
|
2737
|
+
*/
|
|
2928
2738
|
toJSON(): any;
|
|
2929
|
-
/**
|
|
2930
|
-
* Get the parent container.
|
|
2931
|
-
*
|
|
2932
|
-
* - The parent container of the root tree is `undefined`.
|
|
2933
|
-
* - The object returned is a new js object each time because it need to cross
|
|
2934
|
-
* the WASM boundary.
|
|
2935
|
-
|
|
2936
|
-
*/
|
|
2739
|
+
/**
|
|
2740
|
+
* Get the parent container.
|
|
2741
|
+
*
|
|
2742
|
+
* - The parent container of the root tree is `undefined`.
|
|
2743
|
+
* - The object returned is a new js object each time because it need to cross
|
|
2744
|
+
* the WASM boundary.
|
|
2745
|
+
*/
|
|
2937
2746
|
parent(): Container | undefined;
|
|
2938
|
-
/**
|
|
2939
|
-
* Whether the container is attached to a document.
|
|
2940
|
-
*
|
|
2941
|
-
* If it's detached, the operations on the container will not be persisted.
|
|
2942
|
-
|
|
2943
|
-
*/
|
|
2747
|
+
/**
|
|
2748
|
+
* Whether the container is attached to a document.
|
|
2749
|
+
*
|
|
2750
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
2751
|
+
*/
|
|
2944
2752
|
isAttached(): boolean;
|
|
2945
|
-
/**
|
|
2946
|
-
* Get the attached container associated with this.
|
|
2947
|
-
*
|
|
2948
|
-
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
2949
|
-
|
|
2950
|
-
*/
|
|
2753
|
+
/**
|
|
2754
|
+
* Get the attached container associated with this.
|
|
2755
|
+
*
|
|
2756
|
+
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
2757
|
+
*/
|
|
2951
2758
|
getAttached(): LoroMap | undefined;
|
|
2952
|
-
/**
|
|
2953
|
-
* Delete all key-value pairs in the map.
|
|
2954
|
-
*/
|
|
2759
|
+
/**
|
|
2760
|
+
* Delete all key-value pairs in the map.
|
|
2761
|
+
*/
|
|
2955
2762
|
clear(): void;
|
|
2956
|
-
/**
|
|
2957
|
-
* Get the peer id of the last editor on the given entry
|
|
2958
|
-
|
|
2959
|
-
* @returns {PeerID | undefined}
|
|
2960
|
-
*/
|
|
2763
|
+
/**
|
|
2764
|
+
* Get the peer id of the last editor on the given entry
|
|
2765
|
+
*/
|
|
2961
2766
|
getLastEditor(key: string): PeerID | undefined;
|
|
2962
|
-
/**
|
|
2963
|
-
* Check if the container is deleted
|
|
2964
|
-
|
|
2965
|
-
*/
|
|
2767
|
+
/**
|
|
2768
|
+
* Check if the container is deleted
|
|
2769
|
+
*/
|
|
2966
2770
|
isDeleted(): boolean;
|
|
2967
|
-
/**
|
|
2968
|
-
* Get the shallow value of the map.
|
|
2969
|
-
*
|
|
2970
|
-
* Unlike `toJSON()` which recursively resolves all containers to their values,
|
|
2971
|
-
* `getShallowValue()` returns container IDs as strings for any nested containers.
|
|
2972
|
-
*
|
|
2973
|
-
* @example
|
|
2974
|
-
* ```ts
|
|
2975
|
-
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2976
|
-
*
|
|
2977
|
-
* const doc = new LoroDoc();
|
|
2978
|
-
* doc.setPeerId("1");
|
|
2979
|
-
* const map = doc.getMap("map");
|
|
2980
|
-
* map.set("key", "value");
|
|
2981
|
-
* const subText = map.setContainer("text", new LoroText());
|
|
2982
|
-
* subText.insert(0, "Hello");
|
|
2983
|
-
*
|
|
2984
|
-
* // Get shallow value - nested containers are represented by their IDs
|
|
2985
|
-
* console.log(map.getShallowValue());
|
|
2986
|
-
* // Output: { key: "value", text: "cid:1@1:Text" }
|
|
2987
|
-
*
|
|
2988
|
-
* // Get full value with nested containers resolved by `toJSON()`
|
|
2989
|
-
* console.log(map.toJSON());
|
|
2990
|
-
* // Output: { key: "value", text: "Hello" }
|
|
2991
|
-
* ```
|
|
2992
|
-
|
|
2993
|
-
*/
|
|
2771
|
+
/**
|
|
2772
|
+
* Get the shallow value of the map.
|
|
2773
|
+
*
|
|
2774
|
+
* Unlike `toJSON()` which recursively resolves all containers to their values,
|
|
2775
|
+
* `getShallowValue()` returns container IDs as strings for any nested containers.
|
|
2776
|
+
*
|
|
2777
|
+
* @example
|
|
2778
|
+
* ```ts
|
|
2779
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2780
|
+
*
|
|
2781
|
+
* const doc = new LoroDoc();
|
|
2782
|
+
* doc.setPeerId("1");
|
|
2783
|
+
* const map = doc.getMap("map");
|
|
2784
|
+
* map.set("key", "value");
|
|
2785
|
+
* const subText = map.setContainer("text", new LoroText());
|
|
2786
|
+
* subText.insert(0, "Hello");
|
|
2787
|
+
*
|
|
2788
|
+
* // Get shallow value - nested containers are represented by their IDs
|
|
2789
|
+
* console.log(map.getShallowValue());
|
|
2790
|
+
* // Output: { key: "value", text: "cid:1@1:Text" }
|
|
2791
|
+
*
|
|
2792
|
+
* // Get full value with nested containers resolved by `toJSON()`
|
|
2793
|
+
* console.log(map.toJSON());
|
|
2794
|
+
* // Output: { key: "value", text: "Hello" }
|
|
2795
|
+
* ```
|
|
2796
|
+
*/
|
|
2994
2797
|
getShallowValue(): Record<string, Value>;
|
|
2995
|
-
/**
|
|
2996
|
-
* The container id of this handler.
|
|
2997
|
-
*/
|
|
2798
|
+
/**
|
|
2799
|
+
* The container id of this handler.
|
|
2800
|
+
*/
|
|
2998
2801
|
readonly id: ContainerID;
|
|
2999
|
-
/**
|
|
3000
|
-
* Get the size of the map.
|
|
3001
|
-
*
|
|
3002
|
-
* @example
|
|
3003
|
-
* ```ts
|
|
3004
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3005
|
-
*
|
|
3006
|
-
* const doc = new LoroDoc();
|
|
3007
|
-
* const map = doc.getMap("map");
|
|
3008
|
-
* map.set("foo", "bar");
|
|
3009
|
-
* console.log(map.size); // 1
|
|
3010
|
-
* ```
|
|
3011
|
-
*/
|
|
2802
|
+
/**
|
|
2803
|
+
* Get the size of the map.
|
|
2804
|
+
*
|
|
2805
|
+
* @example
|
|
2806
|
+
* ```ts
|
|
2807
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2808
|
+
*
|
|
2809
|
+
* const doc = new LoroDoc();
|
|
2810
|
+
* const map = doc.getMap("map");
|
|
2811
|
+
* map.set("foo", "bar");
|
|
2812
|
+
* console.log(map.size); // 1
|
|
2813
|
+
* ```
|
|
2814
|
+
*/
|
|
3012
2815
|
readonly size: number;
|
|
3013
2816
|
}
|
|
3014
2817
|
/**
|
|
3015
|
-
* The handler of a list container.
|
|
3016
|
-
*
|
|
3017
|
-
* Learn more at https://loro.dev/docs/tutorial/list
|
|
3018
|
-
*/
|
|
2818
|
+
* The handler of a list container.
|
|
2819
|
+
*
|
|
2820
|
+
* Learn more at https://loro.dev/docs/tutorial/list
|
|
2821
|
+
*/
|
|
3019
2822
|
export class LoroMovableList {
|
|
3020
2823
|
free(): void;
|
|
3021
|
-
/**
|
|
3022
|
-
* Create a new detached LoroMovableList (not attached to any LoroDoc).
|
|
3023
|
-
*
|
|
3024
|
-
* The edits on a detached container will not be persisted.
|
|
3025
|
-
* To attach the container to the document, please insert it into an attached container.
|
|
3026
|
-
*/
|
|
2824
|
+
/**
|
|
2825
|
+
* Create a new detached LoroMovableList (not attached to any LoroDoc).
|
|
2826
|
+
*
|
|
2827
|
+
* The edits on a detached container will not be persisted.
|
|
2828
|
+
* To attach the container to the document, please insert it into an attached container.
|
|
2829
|
+
*/
|
|
3027
2830
|
constructor();
|
|
3028
|
-
/**
|
|
3029
|
-
* "MovableList"
|
|
3030
|
-
|
|
3031
|
-
*/
|
|
2831
|
+
/**
|
|
2832
|
+
* "MovableList"
|
|
2833
|
+
*/
|
|
3032
2834
|
kind(): 'MovableList';
|
|
3033
|
-
/**
|
|
3034
|
-
* Delete elements from index to index + len.
|
|
3035
|
-
*
|
|
3036
|
-
* @example
|
|
3037
|
-
* ```ts
|
|
3038
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3039
|
-
*
|
|
3040
|
-
* const doc = new LoroDoc();
|
|
3041
|
-
* const list = doc.getList("list");
|
|
3042
|
-
* list.insert(0, 100);
|
|
3043
|
-
* list.delete(0, 1);
|
|
3044
|
-
* console.log(list.value); // []
|
|
3045
|
-
* ```
|
|
3046
|
-
|
|
3047
|
-
* @param {number} len
|
|
3048
|
-
*/
|
|
2835
|
+
/**
|
|
2836
|
+
* Delete elements from index to index + len.
|
|
2837
|
+
*
|
|
2838
|
+
* @example
|
|
2839
|
+
* ```ts
|
|
2840
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2841
|
+
*
|
|
2842
|
+
* const doc = new LoroDoc();
|
|
2843
|
+
* const list = doc.getList("list");
|
|
2844
|
+
* list.insert(0, 100);
|
|
2845
|
+
* list.delete(0, 1);
|
|
2846
|
+
* console.log(list.value); // []
|
|
2847
|
+
* ```
|
|
2848
|
+
*/
|
|
3049
2849
|
delete(index: number, len: number): void;
|
|
3050
|
-
/**
|
|
3051
|
-
* Get elements of the list. If the type of a element is a container, it will be
|
|
3052
|
-
* resolved recursively.
|
|
3053
|
-
*
|
|
3054
|
-
* @example
|
|
3055
|
-
* ```ts
|
|
3056
|
-
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
3057
|
-
*
|
|
3058
|
-
* const doc = new LoroDoc();
|
|
3059
|
-
* const list = doc.getList("list");
|
|
3060
|
-
* list.insert(0, 100);
|
|
3061
|
-
* const text = list.insertContainer(1, new LoroText());
|
|
3062
|
-
* text.insert(0, "Hello");
|
|
3063
|
-
* console.log(list.toJSON()); // [100, "Hello"];
|
|
3064
|
-
* ```
|
|
3065
|
-
|
|
3066
|
-
*/
|
|
2850
|
+
/**
|
|
2851
|
+
* Get elements of the list. If the type of a element is a container, it will be
|
|
2852
|
+
* resolved recursively.
|
|
2853
|
+
*
|
|
2854
|
+
* @example
|
|
2855
|
+
* ```ts
|
|
2856
|
+
* import { LoroDoc, LoroText } from "loro-crdt";
|
|
2857
|
+
*
|
|
2858
|
+
* const doc = new LoroDoc();
|
|
2859
|
+
* const list = doc.getList("list");
|
|
2860
|
+
* list.insert(0, 100);
|
|
2861
|
+
* const text = list.insertContainer(1, new LoroText());
|
|
2862
|
+
* text.insert(0, "Hello");
|
|
2863
|
+
* console.log(list.toJSON()); // [100, "Hello"];
|
|
2864
|
+
* ```
|
|
2865
|
+
*/
|
|
3067
2866
|
toJSON(): any;
|
|
3068
|
-
/**
|
|
3069
|
-
* Get the parent container.
|
|
3070
|
-
*
|
|
3071
|
-
* - The parent container of the root tree is `undefined`.
|
|
3072
|
-
* - The object returned is a new js object each time because it need to cross
|
|
3073
|
-
* the WASM boundary.
|
|
3074
|
-
|
|
3075
|
-
*/
|
|
2867
|
+
/**
|
|
2868
|
+
* Get the parent container.
|
|
2869
|
+
*
|
|
2870
|
+
* - The parent container of the root tree is `undefined`.
|
|
2871
|
+
* - The object returned is a new js object each time because it need to cross
|
|
2872
|
+
* the WASM boundary.
|
|
2873
|
+
*/
|
|
3076
2874
|
parent(): Container | undefined;
|
|
3077
|
-
/**
|
|
3078
|
-
* Whether the container is attached to a document.
|
|
3079
|
-
*
|
|
3080
|
-
* If it's detached, the operations on the container will not be persisted.
|
|
3081
|
-
|
|
3082
|
-
*/
|
|
2875
|
+
/**
|
|
2876
|
+
* Whether the container is attached to a document.
|
|
2877
|
+
*
|
|
2878
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
2879
|
+
*/
|
|
3083
2880
|
isAttached(): boolean;
|
|
3084
|
-
/**
|
|
3085
|
-
* Get the attached container associated with this.
|
|
3086
|
-
*
|
|
3087
|
-
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
3088
|
-
|
|
3089
|
-
*/
|
|
2881
|
+
/**
|
|
2882
|
+
* Get the attached container associated with this.
|
|
2883
|
+
*
|
|
2884
|
+
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
2885
|
+
*/
|
|
3090
2886
|
getAttached(): LoroList | undefined;
|
|
3091
|
-
/**
|
|
3092
|
-
* Move the element from `from` to `to`.
|
|
3093
|
-
*
|
|
3094
|
-
* The new position of the element will be `to`.
|
|
3095
|
-
* Move the element from `from` to `to`.
|
|
3096
|
-
*
|
|
3097
|
-
* The new position of the element will be `to`. This method is optimized to prevent redundant
|
|
3098
|
-
* operations that might occur with a naive remove and insert approach. Specifically, it avoids
|
|
3099
|
-
* creating surplus values in the list, unlike a delete followed by an insert, which can lead to
|
|
3100
|
-
* additional values in cases of concurrent edits. This ensures more efficient and accurate
|
|
3101
|
-
* operations in a MovableList.
|
|
3102
|
-
|
|
3103
|
-
* @param {number} to
|
|
3104
|
-
*/
|
|
2887
|
+
/**
|
|
2888
|
+
* Move the element from `from` to `to`.
|
|
2889
|
+
*
|
|
2890
|
+
* The new position of the element will be `to`.
|
|
2891
|
+
* Move the element from `from` to `to`.
|
|
2892
|
+
*
|
|
2893
|
+
* The new position of the element will be `to`. This method is optimized to prevent redundant
|
|
2894
|
+
* operations that might occur with a naive remove and insert approach. Specifically, it avoids
|
|
2895
|
+
* creating surplus values in the list, unlike a delete followed by an insert, which can lead to
|
|
2896
|
+
* additional values in cases of concurrent edits. This ensures more efficient and accurate
|
|
2897
|
+
* operations in a MovableList.
|
|
2898
|
+
*/
|
|
3105
2899
|
move(from: number, to: number): void;
|
|
3106
|
-
/**
|
|
3107
|
-
* Pop a value from the end of the list.
|
|
3108
|
-
|
|
3109
|
-
*/
|
|
2900
|
+
/**
|
|
2901
|
+
* Pop a value from the end of the list.
|
|
2902
|
+
*/
|
|
3110
2903
|
pop(): Value | undefined;
|
|
3111
|
-
/**
|
|
3112
|
-
* Delete all elements in the list.
|
|
3113
|
-
*/
|
|
2904
|
+
/**
|
|
2905
|
+
* Delete all elements in the list.
|
|
2906
|
+
*/
|
|
3114
2907
|
clear(): void;
|
|
3115
|
-
/**
|
|
3116
|
-
* Get the creator of the list item at the given position.
|
|
3117
|
-
|
|
3118
|
-
* @returns {PeerID | undefined}
|
|
3119
|
-
*/
|
|
2908
|
+
/**
|
|
2909
|
+
* Get the creator of the list item at the given position.
|
|
2910
|
+
*/
|
|
3120
2911
|
getCreatorAt(pos: number): PeerID | undefined;
|
|
3121
|
-
/**
|
|
3122
|
-
* Get the last mover of the list item at the given position.
|
|
3123
|
-
|
|
3124
|
-
* @returns {PeerID | undefined}
|
|
3125
|
-
*/
|
|
2912
|
+
/**
|
|
2913
|
+
* Get the last mover of the list item at the given position.
|
|
2914
|
+
*/
|
|
3126
2915
|
getLastMoverAt(pos: number): PeerID | undefined;
|
|
3127
|
-
/**
|
|
3128
|
-
* Get the last editor of the list item at the given position.
|
|
3129
|
-
|
|
3130
|
-
* @returns {PeerID | undefined}
|
|
3131
|
-
*/
|
|
2916
|
+
/**
|
|
2917
|
+
* Get the last editor of the list item at the given position.
|
|
2918
|
+
*/
|
|
3132
2919
|
getLastEditorAt(pos: number): PeerID | undefined;
|
|
3133
|
-
/**
|
|
3134
|
-
* Check if the container is deleted
|
|
3135
|
-
|
|
3136
|
-
*/
|
|
2920
|
+
/**
|
|
2921
|
+
* Check if the container is deleted
|
|
2922
|
+
*/
|
|
3137
2923
|
isDeleted(): boolean;
|
|
3138
|
-
/**
|
|
3139
|
-
* Get the shallow value of the movable list.
|
|
3140
|
-
*
|
|
3141
|
-
* Unlike `toJSON()` which recursively resolves all containers to their values,
|
|
3142
|
-
* `getShallowValue()` returns container IDs as strings for any nested containers.
|
|
3143
|
-
*
|
|
3144
|
-
* ```js
|
|
3145
|
-
* const doc = new LoroDoc();
|
|
3146
|
-
* doc.setPeerId("1");
|
|
3147
|
-
* const list = doc.getMovableList("list");
|
|
3148
|
-
* list.insert(0, 1);
|
|
3149
|
-
* list.insert(1, "two");
|
|
3150
|
-
* const subList = list.insertContainer(2, new LoroList());
|
|
3151
|
-
* subList.insert(0, "sub");
|
|
3152
|
-
* list.getShallowValue(); // [1, "two", "cid:2@1:List"]
|
|
3153
|
-
* list.toJSON(); // [1, "two", ["sub"]]
|
|
3154
|
-
* ```
|
|
3155
|
-
|
|
3156
|
-
*/
|
|
2924
|
+
/**
|
|
2925
|
+
* Get the shallow value of the movable list.
|
|
2926
|
+
*
|
|
2927
|
+
* Unlike `toJSON()` which recursively resolves all containers to their values,
|
|
2928
|
+
* `getShallowValue()` returns container IDs as strings for any nested containers.
|
|
2929
|
+
*
|
|
2930
|
+
* ```js
|
|
2931
|
+
* const doc = new LoroDoc();
|
|
2932
|
+
* doc.setPeerId("1");
|
|
2933
|
+
* const list = doc.getMovableList("list");
|
|
2934
|
+
* list.insert(0, 1);
|
|
2935
|
+
* list.insert(1, "two");
|
|
2936
|
+
* const subList = list.insertContainer(2, new LoroList());
|
|
2937
|
+
* subList.insert(0, "sub");
|
|
2938
|
+
* list.getShallowValue(); // [1, "two", "cid:2@1:List"]
|
|
2939
|
+
* list.toJSON(); // [1, "two", ["sub"]]
|
|
2940
|
+
* ```
|
|
2941
|
+
*/
|
|
3157
2942
|
getShallowValue(): Value[];
|
|
3158
|
-
/**
|
|
3159
|
-
* Get the id of this container.
|
|
3160
|
-
*/
|
|
2943
|
+
/**
|
|
2944
|
+
* Get the id of this container.
|
|
2945
|
+
*/
|
|
3161
2946
|
readonly id: ContainerID;
|
|
3162
|
-
/**
|
|
3163
|
-
* Get the length of list.
|
|
3164
|
-
*
|
|
3165
|
-
* @example
|
|
3166
|
-
* ```ts
|
|
3167
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3168
|
-
*
|
|
3169
|
-
* const doc = new LoroDoc();
|
|
3170
|
-
* const list = doc.getList("list");
|
|
3171
|
-
* list.insert(0, 100);
|
|
3172
|
-
* list.insert(1, "foo");
|
|
3173
|
-
* list.insert(2, true);
|
|
3174
|
-
* console.log(list.length); // 3
|
|
3175
|
-
* ```
|
|
3176
|
-
*/
|
|
2947
|
+
/**
|
|
2948
|
+
* Get the length of list.
|
|
2949
|
+
*
|
|
2950
|
+
* @example
|
|
2951
|
+
* ```ts
|
|
2952
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2953
|
+
*
|
|
2954
|
+
* const doc = new LoroDoc();
|
|
2955
|
+
* const list = doc.getList("list");
|
|
2956
|
+
* list.insert(0, 100);
|
|
2957
|
+
* list.insert(1, "foo");
|
|
2958
|
+
* list.insert(2, true);
|
|
2959
|
+
* console.log(list.length); // 3
|
|
2960
|
+
* ```
|
|
2961
|
+
*/
|
|
3177
2962
|
readonly length: number;
|
|
3178
2963
|
}
|
|
3179
2964
|
/**
|
|
3180
|
-
* The handler of a text container. It supports rich text CRDT.
|
|
3181
|
-
*
|
|
3182
|
-
* Learn more at https://loro.dev/docs/tutorial/text
|
|
3183
|
-
*/
|
|
2965
|
+
* The handler of a text container. It supports rich text CRDT.
|
|
2966
|
+
*
|
|
2967
|
+
* Learn more at https://loro.dev/docs/tutorial/text
|
|
2968
|
+
*/
|
|
3184
2969
|
export class LoroText {
|
|
3185
2970
|
free(): void;
|
|
3186
|
-
/**
|
|
3187
|
-
* Create a new detached LoroText (not attached to any LoroDoc).
|
|
3188
|
-
*
|
|
3189
|
-
* The edits on a detached container will not be persisted.
|
|
3190
|
-
* To attach the container to the document, please insert it into an attached container.
|
|
3191
|
-
*/
|
|
2971
|
+
/**
|
|
2972
|
+
* Create a new detached LoroText (not attached to any LoroDoc).
|
|
2973
|
+
*
|
|
2974
|
+
* The edits on a detached container will not be persisted.
|
|
2975
|
+
* To attach the container to the document, please insert it into an attached container.
|
|
2976
|
+
*/
|
|
3192
2977
|
constructor();
|
|
3193
|
-
/**
|
|
3194
|
-
* "Text"
|
|
3195
|
-
|
|
3196
|
-
*/
|
|
2978
|
+
/**
|
|
2979
|
+
* "Text"
|
|
2980
|
+
*/
|
|
3197
2981
|
kind(): 'Text';
|
|
3198
|
-
/**
|
|
3199
|
-
* Iterate each text span(internal storage unit)
|
|
3200
|
-
*
|
|
3201
|
-
* The callback function will be called for each span in the text.
|
|
3202
|
-
* If the callback returns `false`, the iteration will stop.
|
|
3203
|
-
*
|
|
3204
|
-
* Limitation: you cannot access or alter the doc state when iterating (this is for performance consideration).
|
|
3205
|
-
* If you need to access or alter the doc state, please use `toString` instead.
|
|
3206
|
-
*
|
|
3207
|
-
* @example
|
|
3208
|
-
* ```ts
|
|
3209
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3210
|
-
*
|
|
3211
|
-
* const doc = new LoroDoc();
|
|
3212
|
-
* const text = doc.getText("text");
|
|
3213
|
-
* text.insert(0, "Hello");
|
|
3214
|
-
* text.iter((str) => (console.log(str), true));
|
|
3215
|
-
* ```
|
|
3216
|
-
|
|
3217
|
-
*/
|
|
2982
|
+
/**
|
|
2983
|
+
* Iterate each text span(internal storage unit)
|
|
2984
|
+
*
|
|
2985
|
+
* The callback function will be called for each span in the text.
|
|
2986
|
+
* If the callback returns `false`, the iteration will stop.
|
|
2987
|
+
*
|
|
2988
|
+
* Limitation: you cannot access or alter the doc state when iterating (this is for performance consideration).
|
|
2989
|
+
* If you need to access or alter the doc state, please use `toString` instead.
|
|
2990
|
+
*
|
|
2991
|
+
* @example
|
|
2992
|
+
* ```ts
|
|
2993
|
+
* import { LoroDoc } from "loro-crdt";
|
|
2994
|
+
*
|
|
2995
|
+
* const doc = new LoroDoc();
|
|
2996
|
+
* const text = doc.getText("text");
|
|
2997
|
+
* text.insert(0, "Hello");
|
|
2998
|
+
* text.iter((str) => (console.log(str), true));
|
|
2999
|
+
* ```
|
|
3000
|
+
*/
|
|
3218
3001
|
iter(callback: (string) => boolean): void;
|
|
3219
|
-
/**
|
|
3220
|
-
* Insert the string at the given index (utf-16 index).
|
|
3221
|
-
*
|
|
3222
|
-
* @example
|
|
3223
|
-
* ```ts
|
|
3224
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3225
|
-
*
|
|
3226
|
-
* const doc = new LoroDoc();
|
|
3227
|
-
* const text = doc.getText("text");
|
|
3228
|
-
* text.insert(0, "Hello");
|
|
3229
|
-
* ```
|
|
3230
|
-
|
|
3231
|
-
* @param {string} content
|
|
3232
|
-
*/
|
|
3002
|
+
/**
|
|
3003
|
+
* Insert the string at the given index (utf-16 index).
|
|
3004
|
+
*
|
|
3005
|
+
* @example
|
|
3006
|
+
* ```ts
|
|
3007
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3008
|
+
*
|
|
3009
|
+
* const doc = new LoroDoc();
|
|
3010
|
+
* const text = doc.getText("text");
|
|
3011
|
+
* text.insert(0, "Hello");
|
|
3012
|
+
* ```
|
|
3013
|
+
*/
|
|
3233
3014
|
insert(index: number, content: string): void;
|
|
3234
|
-
/**
|
|
3235
|
-
* Get a string slice (utf-16 index).
|
|
3236
|
-
*
|
|
3237
|
-
* @example
|
|
3238
|
-
* ```ts
|
|
3239
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3240
|
-
*
|
|
3241
|
-
* const doc = new LoroDoc();
|
|
3242
|
-
* const text = doc.getText("text");
|
|
3243
|
-
* text.insert(0, "Hello");
|
|
3244
|
-
* text.slice(0, 2); // "He"
|
|
3245
|
-
* ```
|
|
3246
|
-
|
|
3247
|
-
* @param {number} end_index
|
|
3248
|
-
* @returns {string}
|
|
3249
|
-
*/
|
|
3015
|
+
/**
|
|
3016
|
+
* Get a string slice (utf-16 index).
|
|
3017
|
+
*
|
|
3018
|
+
* @example
|
|
3019
|
+
* ```ts
|
|
3020
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3021
|
+
*
|
|
3022
|
+
* const doc = new LoroDoc();
|
|
3023
|
+
* const text = doc.getText("text");
|
|
3024
|
+
* text.insert(0, "Hello");
|
|
3025
|
+
* text.slice(0, 2); // "He"
|
|
3026
|
+
* ```
|
|
3027
|
+
*/
|
|
3250
3028
|
slice(start_index: number, end_index: number): string;
|
|
3251
|
-
/**
|
|
3252
|
-
* Get the character at the given position (utf-16 index).
|
|
3253
|
-
*
|
|
3254
|
-
* @example
|
|
3255
|
-
* ```ts
|
|
3256
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3257
|
-
*
|
|
3258
|
-
* const doc = new LoroDoc();
|
|
3259
|
-
* const text = doc.getText("text");
|
|
3260
|
-
* text.insert(0, "Hello");
|
|
3261
|
-
* text.charAt(0); // "H"
|
|
3262
|
-
* ```
|
|
3263
|
-
|
|
3264
|
-
* @returns {string}
|
|
3265
|
-
*/
|
|
3029
|
+
/**
|
|
3030
|
+
* Get the character at the given position (utf-16 index).
|
|
3031
|
+
*
|
|
3032
|
+
* @example
|
|
3033
|
+
* ```ts
|
|
3034
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3035
|
+
*
|
|
3036
|
+
* const doc = new LoroDoc();
|
|
3037
|
+
* const text = doc.getText("text");
|
|
3038
|
+
* text.insert(0, "Hello");
|
|
3039
|
+
* text.charAt(0); // "H"
|
|
3040
|
+
* ```
|
|
3041
|
+
*/
|
|
3266
3042
|
charAt(pos: number): string;
|
|
3267
|
-
/**
|
|
3268
|
-
* Delete and return the string at the given range and insert a string at the same position (utf-16 index).
|
|
3269
|
-
*
|
|
3270
|
-
* @example
|
|
3271
|
-
* ```ts
|
|
3272
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3273
|
-
*
|
|
3274
|
-
* const doc = new LoroDoc();
|
|
3275
|
-
* const text = doc.getText("text");
|
|
3276
|
-
* text.insert(0, "Hello");
|
|
3277
|
-
* text.splice(2, 3, "llo"); // "llo"
|
|
3278
|
-
* ```
|
|
3279
|
-
|
|
3280
|
-
* @param {number} len
|
|
3281
|
-
* @param {string} s
|
|
3282
|
-
* @returns {string}
|
|
3283
|
-
*/
|
|
3043
|
+
/**
|
|
3044
|
+
* Delete and return the string at the given range and insert a string at the same position (utf-16 index).
|
|
3045
|
+
*
|
|
3046
|
+
* @example
|
|
3047
|
+
* ```ts
|
|
3048
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3049
|
+
*
|
|
3050
|
+
* const doc = new LoroDoc();
|
|
3051
|
+
* const text = doc.getText("text");
|
|
3052
|
+
* text.insert(0, "Hello");
|
|
3053
|
+
* text.splice(2, 3, "llo"); // "llo"
|
|
3054
|
+
* ```
|
|
3055
|
+
*/
|
|
3284
3056
|
splice(pos: number, len: number, s: string): string;
|
|
3285
|
-
/**
|
|
3286
|
-
* Insert some string at utf-8 index.
|
|
3287
|
-
*
|
|
3288
|
-
* @example
|
|
3289
|
-
* ```ts
|
|
3290
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3291
|
-
*
|
|
3292
|
-
* const doc = new LoroDoc();
|
|
3293
|
-
* const text = doc.getText("text");
|
|
3294
|
-
* text.insertUtf8(0, "Hello");
|
|
3295
|
-
* ```
|
|
3296
|
-
|
|
3297
|
-
* @param {string} content
|
|
3298
|
-
*/
|
|
3057
|
+
/**
|
|
3058
|
+
* Insert some string at utf-8 index.
|
|
3059
|
+
*
|
|
3060
|
+
* @example
|
|
3061
|
+
* ```ts
|
|
3062
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3063
|
+
*
|
|
3064
|
+
* const doc = new LoroDoc();
|
|
3065
|
+
* const text = doc.getText("text");
|
|
3066
|
+
* text.insertUtf8(0, "Hello");
|
|
3067
|
+
* ```
|
|
3068
|
+
*/
|
|
3299
3069
|
insertUtf8(index: number, content: string): void;
|
|
3300
|
-
/**
|
|
3301
|
-
* Delete elements from index to index + len (utf-16 index).
|
|
3302
|
-
*
|
|
3303
|
-
* @example
|
|
3304
|
-
* ```ts
|
|
3305
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3306
|
-
*
|
|
3307
|
-
* const doc = new LoroDoc();
|
|
3308
|
-
* const text = doc.getText("text");
|
|
3309
|
-
* text.insert(0, "Hello");
|
|
3310
|
-
* text.delete(1, 3);
|
|
3311
|
-
* const s = text.toString();
|
|
3312
|
-
* console.log(s); // "Ho"
|
|
3313
|
-
* ```
|
|
3314
|
-
|
|
3315
|
-
* @param {number} len
|
|
3316
|
-
*/
|
|
3070
|
+
/**
|
|
3071
|
+
* Delete elements from index to index + len (utf-16 index).
|
|
3072
|
+
*
|
|
3073
|
+
* @example
|
|
3074
|
+
* ```ts
|
|
3075
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3076
|
+
*
|
|
3077
|
+
* const doc = new LoroDoc();
|
|
3078
|
+
* const text = doc.getText("text");
|
|
3079
|
+
* text.insert(0, "Hello");
|
|
3080
|
+
* text.delete(1, 3);
|
|
3081
|
+
* const s = text.toString();
|
|
3082
|
+
* console.log(s); // "Ho"
|
|
3083
|
+
* ```
|
|
3084
|
+
*/
|
|
3317
3085
|
delete(index: number, len: number): void;
|
|
3318
|
-
/**
|
|
3319
|
-
* Delete elements from index to utf-8 index + len
|
|
3320
|
-
*
|
|
3321
|
-
* @example
|
|
3322
|
-
* ```ts
|
|
3323
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3324
|
-
*
|
|
3325
|
-
* const doc = new LoroDoc();
|
|
3326
|
-
* const text = doc.getText("text");
|
|
3327
|
-
* text.insertUtf8(0, "Hello");
|
|
3328
|
-
* text.deleteUtf8(1, 3);
|
|
3329
|
-
* const s = text.toString();
|
|
3330
|
-
* console.log(s); // "Ho"
|
|
3331
|
-
* ```
|
|
3332
|
-
|
|
3333
|
-
* @param {number} len
|
|
3334
|
-
*/
|
|
3086
|
+
/**
|
|
3087
|
+
* Delete elements from index to utf-8 index + len
|
|
3088
|
+
*
|
|
3089
|
+
* @example
|
|
3090
|
+
* ```ts
|
|
3091
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3092
|
+
*
|
|
3093
|
+
* const doc = new LoroDoc();
|
|
3094
|
+
* const text = doc.getText("text");
|
|
3095
|
+
* text.insertUtf8(0, "Hello");
|
|
3096
|
+
* text.deleteUtf8(1, 3);
|
|
3097
|
+
* const s = text.toString();
|
|
3098
|
+
* console.log(s); // "Ho"
|
|
3099
|
+
* ```
|
|
3100
|
+
*/
|
|
3335
3101
|
deleteUtf8(index: number, len: number): void;
|
|
3336
|
-
/**
|
|
3337
|
-
* Mark a range of text with a key and a value (utf-16 index).
|
|
3338
|
-
*
|
|
3339
|
-
* > You should call `configTextStyle` before using `mark` and `unmark`.
|
|
3340
|
-
*
|
|
3341
|
-
* You can use it to create a highlight, make a range of text bold, or add a link to a range of text.
|
|
3342
|
-
*
|
|
3343
|
-
* @example
|
|
3344
|
-
* ```ts
|
|
3345
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3346
|
-
*
|
|
3347
|
-
* const doc = new LoroDoc();
|
|
3348
|
-
* doc.configTextStyle({bold: {expand: "after"}});
|
|
3349
|
-
* const text = doc.getText("text");
|
|
3350
|
-
* text.insert(0, "Hello World!");
|
|
3351
|
-
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
3352
|
-
* ```
|
|
3353
|
-
|
|
3354
|
-
* @param {string} key
|
|
3355
|
-
* @param {any} value
|
|
3356
|
-
*/
|
|
3102
|
+
/**
|
|
3103
|
+
* Mark a range of text with a key and a value (utf-16 index).
|
|
3104
|
+
*
|
|
3105
|
+
* > You should call `configTextStyle` before using `mark` and `unmark`.
|
|
3106
|
+
*
|
|
3107
|
+
* You can use it to create a highlight, make a range of text bold, or add a link to a range of text.
|
|
3108
|
+
*
|
|
3109
|
+
* @example
|
|
3110
|
+
* ```ts
|
|
3111
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3112
|
+
*
|
|
3113
|
+
* const doc = new LoroDoc();
|
|
3114
|
+
* doc.configTextStyle({bold: {expand: "after"}});
|
|
3115
|
+
* const text = doc.getText("text");
|
|
3116
|
+
* text.insert(0, "Hello World!");
|
|
3117
|
+
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
3118
|
+
* ```
|
|
3119
|
+
*/
|
|
3357
3120
|
mark(range: { start: number, end: number }, key: string, value: any): void;
|
|
3358
|
-
/**
|
|
3359
|
-
* Unmark a range of text with a key and a value (utf-16 index).
|
|
3360
|
-
*
|
|
3361
|
-
* > You should call `configTextStyle` before using `mark` and `unmark`.
|
|
3362
|
-
*
|
|
3363
|
-
* You can use it to remove highlights, bolds or links
|
|
3364
|
-
*
|
|
3365
|
-
* @example
|
|
3366
|
-
* ```ts
|
|
3367
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3368
|
-
*
|
|
3369
|
-
* const doc = new LoroDoc();
|
|
3370
|
-
* doc.configTextStyle({bold: {expand: "after"}});
|
|
3371
|
-
* const text = doc.getText("text");
|
|
3372
|
-
* text.insert(0, "Hello World!");
|
|
3373
|
-
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
3374
|
-
* text.unmark({ start: 0, end: 5 }, "bold");
|
|
3375
|
-
* ```
|
|
3376
|
-
|
|
3377
|
-
* @param {string} key
|
|
3378
|
-
*/
|
|
3121
|
+
/**
|
|
3122
|
+
* Unmark a range of text with a key and a value (utf-16 index).
|
|
3123
|
+
*
|
|
3124
|
+
* > You should call `configTextStyle` before using `mark` and `unmark`.
|
|
3125
|
+
*
|
|
3126
|
+
* You can use it to remove highlights, bolds or links
|
|
3127
|
+
*
|
|
3128
|
+
* @example
|
|
3129
|
+
* ```ts
|
|
3130
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3131
|
+
*
|
|
3132
|
+
* const doc = new LoroDoc();
|
|
3133
|
+
* doc.configTextStyle({bold: {expand: "after"}});
|
|
3134
|
+
* const text = doc.getText("text");
|
|
3135
|
+
* text.insert(0, "Hello World!");
|
|
3136
|
+
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
3137
|
+
* text.unmark({ start: 0, end: 5 }, "bold");
|
|
3138
|
+
* ```
|
|
3139
|
+
*/
|
|
3379
3140
|
unmark(range: { start: number, end: number }, key: string): void;
|
|
3380
|
-
/**
|
|
3381
|
-
* Convert the text to a string
|
|
3382
|
-
|
|
3383
|
-
*/
|
|
3141
|
+
/**
|
|
3142
|
+
* Convert the text to a string
|
|
3143
|
+
*/
|
|
3384
3144
|
toString(): string;
|
|
3385
|
-
/**
|
|
3386
|
-
* Get the text in [Delta](https://quilljs.com/docs/delta/) format.
|
|
3387
|
-
*
|
|
3388
|
-
* The returned value will include the rich text information.
|
|
3389
|
-
*
|
|
3390
|
-
* @example
|
|
3391
|
-
* ```ts
|
|
3392
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3393
|
-
*
|
|
3394
|
-
* const doc = new LoroDoc();
|
|
3395
|
-
* const text = doc.getText("text");
|
|
3396
|
-
* doc.configTextStyle({bold: {expand: "after"}});
|
|
3397
|
-
* text.insert(0, "Hello World!");
|
|
3398
|
-
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
3399
|
-
* console.log(text.toDelta()); // [ { insert: 'Hello', attributes: { bold: true } } ]
|
|
3400
|
-
* ```
|
|
3401
|
-
|
|
3402
|
-
*/
|
|
3145
|
+
/**
|
|
3146
|
+
* Get the text in [Delta](https://quilljs.com/docs/delta/) format.
|
|
3147
|
+
*
|
|
3148
|
+
* The returned value will include the rich text information.
|
|
3149
|
+
*
|
|
3150
|
+
* @example
|
|
3151
|
+
* ```ts
|
|
3152
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3153
|
+
*
|
|
3154
|
+
* const doc = new LoroDoc();
|
|
3155
|
+
* const text = doc.getText("text");
|
|
3156
|
+
* doc.configTextStyle({bold: {expand: "after"}});
|
|
3157
|
+
* text.insert(0, "Hello World!");
|
|
3158
|
+
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
3159
|
+
* console.log(text.toDelta()); // [ { insert: 'Hello', attributes: { bold: true } } ]
|
|
3160
|
+
* ```
|
|
3161
|
+
*/
|
|
3403
3162
|
toDelta(): Delta<string>[];
|
|
3404
|
-
/**
|
|
3405
|
-
* Change the state of this text by delta.
|
|
3406
|
-
*
|
|
3407
|
-
* If a delta item is `insert`, it should include all the attributes of the inserted text.
|
|
3408
|
-
* Loro's rich text CRDT may make the inserted text inherit some styles when you use
|
|
3409
|
-
* `insert` method directly. However, when you use `applyDelta` if some attributes are
|
|
3410
|
-
* inherited from CRDT but not included in the delta, they will be removed.
|
|
3411
|
-
*
|
|
3412
|
-
* Another special property of `applyDelta` is if you format an attribute for ranges out of
|
|
3413
|
-
* the text length, Loro will insert new lines to fill the gap first. It's useful when you
|
|
3414
|
-
* build the binding between Loro and rich text editors like Quill, which might assume there
|
|
3415
|
-
* is always a newline at the end of the text implicitly.
|
|
3416
|
-
*
|
|
3417
|
-
* @example
|
|
3418
|
-
* ```ts
|
|
3419
|
-
* const doc = new LoroDoc();
|
|
3420
|
-
* const text = doc.getText("text");
|
|
3421
|
-
* doc.configTextStyle({bold: {expand: "after"}});
|
|
3422
|
-
* text.insert(0, "Hello World!");
|
|
3423
|
-
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
3424
|
-
* const delta = text.toDelta();
|
|
3425
|
-
* const text2 = doc.getText("text2");
|
|
3426
|
-
* text2.applyDelta(delta);
|
|
3427
|
-
* expect(text2.toDelta()).toStrictEqual(delta);
|
|
3428
|
-
* ```
|
|
3429
|
-
|
|
3430
|
-
*/
|
|
3163
|
+
/**
|
|
3164
|
+
* Change the state of this text by delta.
|
|
3165
|
+
*
|
|
3166
|
+
* If a delta item is `insert`, it should include all the attributes of the inserted text.
|
|
3167
|
+
* Loro's rich text CRDT may make the inserted text inherit some styles when you use
|
|
3168
|
+
* `insert` method directly. However, when you use `applyDelta` if some attributes are
|
|
3169
|
+
* inherited from CRDT but not included in the delta, they will be removed.
|
|
3170
|
+
*
|
|
3171
|
+
* Another special property of `applyDelta` is if you format an attribute for ranges out of
|
|
3172
|
+
* the text length, Loro will insert new lines to fill the gap first. It's useful when you
|
|
3173
|
+
* build the binding between Loro and rich text editors like Quill, which might assume there
|
|
3174
|
+
* is always a newline at the end of the text implicitly.
|
|
3175
|
+
*
|
|
3176
|
+
* @example
|
|
3177
|
+
* ```ts
|
|
3178
|
+
* const doc = new LoroDoc();
|
|
3179
|
+
* const text = doc.getText("text");
|
|
3180
|
+
* doc.configTextStyle({bold: {expand: "after"}});
|
|
3181
|
+
* text.insert(0, "Hello World!");
|
|
3182
|
+
* text.mark({ start: 0, end: 5 }, "bold", true);
|
|
3183
|
+
* const delta = text.toDelta();
|
|
3184
|
+
* const text2 = doc.getText("text2");
|
|
3185
|
+
* text2.applyDelta(delta);
|
|
3186
|
+
* expect(text2.toDelta()).toStrictEqual(delta);
|
|
3187
|
+
* ```
|
|
3188
|
+
*/
|
|
3431
3189
|
applyDelta(delta: Delta<string>[]): void;
|
|
3432
|
-
/**
|
|
3433
|
-
* Get the parent container.
|
|
3434
|
-
*
|
|
3435
|
-
* - The parent of the root is `undefined`.
|
|
3436
|
-
* - The object returned is a new js object each time because it need to cross
|
|
3437
|
-
* the WASM boundary.
|
|
3438
|
-
|
|
3439
|
-
*/
|
|
3190
|
+
/**
|
|
3191
|
+
* Get the parent container.
|
|
3192
|
+
*
|
|
3193
|
+
* - The parent of the root is `undefined`.
|
|
3194
|
+
* - The object returned is a new js object each time because it need to cross
|
|
3195
|
+
* the WASM boundary.
|
|
3196
|
+
*/
|
|
3440
3197
|
parent(): Container | undefined;
|
|
3441
|
-
/**
|
|
3442
|
-
* Whether the container is attached to a LoroDoc.
|
|
3443
|
-
*
|
|
3444
|
-
* If it's detached, the operations on the container will not be persisted.
|
|
3445
|
-
|
|
3446
|
-
*/
|
|
3198
|
+
/**
|
|
3199
|
+
* Whether the container is attached to a LoroDoc.
|
|
3200
|
+
*
|
|
3201
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
3202
|
+
*/
|
|
3447
3203
|
isAttached(): boolean;
|
|
3448
|
-
/**
|
|
3449
|
-
* Get the attached container associated with this.
|
|
3450
|
-
*
|
|
3451
|
-
* Returns an attached `Container` that is equal to this or created by this; otherwise, it returns `undefined`.
|
|
3452
|
-
|
|
3453
|
-
*/
|
|
3204
|
+
/**
|
|
3205
|
+
* Get the attached container associated with this.
|
|
3206
|
+
*
|
|
3207
|
+
* Returns an attached `Container` that is equal to this or created by this; otherwise, it returns `undefined`.
|
|
3208
|
+
*/
|
|
3454
3209
|
getAttached(): LoroText | undefined;
|
|
3455
|
-
/**
|
|
3456
|
-
* Push a string to the end of the text.
|
|
3457
|
-
|
|
3458
|
-
*/
|
|
3210
|
+
/**
|
|
3211
|
+
* Push a string to the end of the text.
|
|
3212
|
+
*/
|
|
3459
3213
|
push(s: string): void;
|
|
3460
|
-
/**
|
|
3461
|
-
* Get the editor of the text at the given position.
|
|
3462
|
-
|
|
3463
|
-
* @returns {PeerID | undefined}
|
|
3464
|
-
*/
|
|
3214
|
+
/**
|
|
3215
|
+
* Get the editor of the text at the given position.
|
|
3216
|
+
*/
|
|
3465
3217
|
getEditorOf(pos: number): PeerID | undefined;
|
|
3466
|
-
/**
|
|
3467
|
-
* Check if the container is deleted
|
|
3468
|
-
|
|
3469
|
-
*/
|
|
3218
|
+
/**
|
|
3219
|
+
* Check if the container is deleted
|
|
3220
|
+
*/
|
|
3470
3221
|
isDeleted(): boolean;
|
|
3471
|
-
/**
|
|
3472
|
-
* Get the shallow value of the text. This equals to `text.toString()`.
|
|
3473
|
-
|
|
3474
|
-
*/
|
|
3222
|
+
/**
|
|
3223
|
+
* Get the shallow value of the text. This equals to `text.toString()`.
|
|
3224
|
+
*/
|
|
3475
3225
|
getShallowValue(): string;
|
|
3476
|
-
/**
|
|
3477
|
-
* Get the JSON representation of the text.
|
|
3478
|
-
|
|
3479
|
-
*/
|
|
3226
|
+
/**
|
|
3227
|
+
* Get the JSON representation of the text.
|
|
3228
|
+
*/
|
|
3480
3229
|
toJSON(): any;
|
|
3481
|
-
/**
|
|
3482
|
-
* Get the container id of the text.
|
|
3483
|
-
*/
|
|
3230
|
+
/**
|
|
3231
|
+
* Get the container id of the text.
|
|
3232
|
+
*/
|
|
3484
3233
|
readonly id: ContainerID;
|
|
3485
|
-
/**
|
|
3486
|
-
* Get the length of text (utf-16 length).
|
|
3487
|
-
*/
|
|
3234
|
+
/**
|
|
3235
|
+
* Get the length of text (utf-16 length).
|
|
3236
|
+
*/
|
|
3488
3237
|
readonly length: number;
|
|
3489
3238
|
}
|
|
3490
3239
|
/**
|
|
3491
|
-
* The handler of a tree(forest) container.
|
|
3492
|
-
*
|
|
3493
|
-
* Learn more at https://loro.dev/docs/tutorial/tree
|
|
3494
|
-
*/
|
|
3240
|
+
* The handler of a tree(forest) container.
|
|
3241
|
+
*
|
|
3242
|
+
* Learn more at https://loro.dev/docs/tutorial/tree
|
|
3243
|
+
*/
|
|
3495
3244
|
export class LoroTree {
|
|
3496
3245
|
free(): void;
|
|
3497
|
-
/**
|
|
3498
|
-
* Create a new detached LoroTree (not attached to any LoroDoc).
|
|
3499
|
-
*
|
|
3500
|
-
* The edits on a detached container will not be persisted.
|
|
3501
|
-
* To attach the container to the document, please insert it into an attached container.
|
|
3502
|
-
*/
|
|
3246
|
+
/**
|
|
3247
|
+
* Create a new detached LoroTree (not attached to any LoroDoc).
|
|
3248
|
+
*
|
|
3249
|
+
* The edits on a detached container will not be persisted.
|
|
3250
|
+
* To attach the container to the document, please insert it into an attached container.
|
|
3251
|
+
*/
|
|
3503
3252
|
constructor();
|
|
3504
|
-
/**
|
|
3505
|
-
* "Tree"
|
|
3506
|
-
|
|
3507
|
-
*/
|
|
3253
|
+
/**
|
|
3254
|
+
* "Tree"
|
|
3255
|
+
*/
|
|
3508
3256
|
kind(): 'Tree';
|
|
3509
|
-
/**
|
|
3510
|
-
* Move the target tree node to be a child of the parent.
|
|
3511
|
-
* It's not allowed that the target is an ancestor of the parent
|
|
3512
|
-
* or the target and the parent are the same node.
|
|
3513
|
-
*
|
|
3514
|
-
* @example
|
|
3515
|
-
* ```ts
|
|
3516
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3517
|
-
*
|
|
3518
|
-
* const doc = new LoroDoc();
|
|
3519
|
-
* const tree = doc.getTree("tree");
|
|
3520
|
-
* const root = tree.createNode();
|
|
3521
|
-
* const node = root.createNode();
|
|
3522
|
-
* const node2 = node.createNode();
|
|
3523
|
-
* tree.move(node2.id, root.id);
|
|
3524
|
-
* // Error will be thrown if move operation creates a cycle
|
|
3525
|
-
* // tree.move(root.id, node.id);
|
|
3526
|
-
* ```
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
*
|
|
3534
|
-
*
|
|
3535
|
-
*
|
|
3536
|
-
*
|
|
3537
|
-
*
|
|
3538
|
-
*
|
|
3539
|
-
* const
|
|
3540
|
-
*
|
|
3541
|
-
*
|
|
3542
|
-
|
|
3543
|
-
* tree.delete(node.id);
|
|
3544
|
-
* ```
|
|
3545
|
-
* @param {TreeID} target
|
|
3546
|
-
*/
|
|
3257
|
+
/**
|
|
3258
|
+
* Move the target tree node to be a child of the parent.
|
|
3259
|
+
* It's not allowed that the target is an ancestor of the parent
|
|
3260
|
+
* or the target and the parent are the same node.
|
|
3261
|
+
*
|
|
3262
|
+
* @example
|
|
3263
|
+
* ```ts
|
|
3264
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3265
|
+
*
|
|
3266
|
+
* const doc = new LoroDoc();
|
|
3267
|
+
* const tree = doc.getTree("tree");
|
|
3268
|
+
* const root = tree.createNode();
|
|
3269
|
+
* const node = root.createNode();
|
|
3270
|
+
* const node2 = node.createNode();
|
|
3271
|
+
* tree.move(node2.id, root.id);
|
|
3272
|
+
* // Error will be thrown if move operation creates a cycle
|
|
3273
|
+
* // tree.move(root.id, node.id);
|
|
3274
|
+
* ```
|
|
3275
|
+
*/
|
|
3276
|
+
move(target: TreeID, parent: TreeID | undefined, index?: number | null): void;
|
|
3277
|
+
/**
|
|
3278
|
+
* Delete a tree node from the forest.
|
|
3279
|
+
*
|
|
3280
|
+
* @example
|
|
3281
|
+
* ```ts
|
|
3282
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3283
|
+
*
|
|
3284
|
+
* const doc = new LoroDoc();
|
|
3285
|
+
* const tree = doc.getTree("tree");
|
|
3286
|
+
* const root = tree.createNode();
|
|
3287
|
+
* const node = root.createNode();
|
|
3288
|
+
* tree.delete(node.id);
|
|
3289
|
+
* ```
|
|
3290
|
+
*/
|
|
3547
3291
|
delete(target: TreeID): void;
|
|
3548
|
-
/**
|
|
3549
|
-
* Return `true` if the tree contains the TreeID, include deleted node.
|
|
3550
|
-
|
|
3551
|
-
* @returns {boolean}
|
|
3552
|
-
*/
|
|
3292
|
+
/**
|
|
3293
|
+
* Return `true` if the tree contains the TreeID, include deleted node.
|
|
3294
|
+
*/
|
|
3553
3295
|
has(target: TreeID): boolean;
|
|
3554
|
-
/**
|
|
3555
|
-
* Return `None` if the node is not exist, otherwise return `Some(true)` if the node is deleted.
|
|
3556
|
-
|
|
3557
|
-
* @returns {boolean}
|
|
3558
|
-
*/
|
|
3296
|
+
/**
|
|
3297
|
+
* Return `None` if the node is not exist, otherwise return `Some(true)` if the node is deleted.
|
|
3298
|
+
*/
|
|
3559
3299
|
isNodeDeleted(target: TreeID): boolean;
|
|
3560
|
-
/**
|
|
3561
|
-
* Get the hierarchy array with metadata of the forest.
|
|
3562
|
-
*
|
|
3563
|
-
* @example
|
|
3564
|
-
* ```ts
|
|
3565
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3566
|
-
*
|
|
3567
|
-
* const doc = new LoroDoc();
|
|
3568
|
-
* const tree = doc.getTree("tree");
|
|
3569
|
-
* const root = tree.createNode();
|
|
3570
|
-
* root.data.set("color", "red");
|
|
3571
|
-
* // [ { id: '0@F2462C4159C4C8D1', parent: null, meta: { color: 'red' }, children: [] } ]
|
|
3572
|
-
* console.log(tree.toJSON());
|
|
3573
|
-
* ```
|
|
3574
|
-
|
|
3575
|
-
*/
|
|
3300
|
+
/**
|
|
3301
|
+
* Get the hierarchy array with metadata of the forest.
|
|
3302
|
+
*
|
|
3303
|
+
* @example
|
|
3304
|
+
* ```ts
|
|
3305
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3306
|
+
*
|
|
3307
|
+
* const doc = new LoroDoc();
|
|
3308
|
+
* const tree = doc.getTree("tree");
|
|
3309
|
+
* const root = tree.createNode();
|
|
3310
|
+
* root.data.set("color", "red");
|
|
3311
|
+
* // [ { id: '0@F2462C4159C4C8D1', parent: null, meta: { color: 'red' }, children: [] } ]
|
|
3312
|
+
* console.log(tree.toJSON());
|
|
3313
|
+
* ```
|
|
3314
|
+
*/
|
|
3576
3315
|
toJSON(): any;
|
|
3577
|
-
/**
|
|
3578
|
-
* Get all tree nodes of the forest, including deleted nodes.
|
|
3579
|
-
*
|
|
3580
|
-
* @example
|
|
3581
|
-
* ```ts
|
|
3582
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3583
|
-
*
|
|
3584
|
-
* const doc = new LoroDoc();
|
|
3585
|
-
* const tree = doc.getTree("tree");
|
|
3586
|
-
* const root = tree.createNode();
|
|
3587
|
-
* const node = root.createNode();
|
|
3588
|
-
* const node2 = node.createNode();
|
|
3589
|
-
* console.log(tree.nodes());
|
|
3590
|
-
* ```
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
*
|
|
3601
|
-
*
|
|
3602
|
-
*
|
|
3603
|
-
|
|
3604
|
-
* the WASM boundary.
|
|
3605
|
-
* @returns {Container | undefined}
|
|
3606
|
-
*/
|
|
3316
|
+
/**
|
|
3317
|
+
* Get all tree nodes of the forest, including deleted nodes.
|
|
3318
|
+
*
|
|
3319
|
+
* @example
|
|
3320
|
+
* ```ts
|
|
3321
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3322
|
+
*
|
|
3323
|
+
* const doc = new LoroDoc();
|
|
3324
|
+
* const tree = doc.getTree("tree");
|
|
3325
|
+
* const root = tree.createNode();
|
|
3326
|
+
* const node = root.createNode();
|
|
3327
|
+
* const node2 = node.createNode();
|
|
3328
|
+
* console.log(tree.nodes());
|
|
3329
|
+
* ```
|
|
3330
|
+
*/
|
|
3331
|
+
nodes(): LoroTreeNode[];
|
|
3332
|
+
/**
|
|
3333
|
+
* Get the root nodes of the forest.
|
|
3334
|
+
*/
|
|
3335
|
+
roots(): LoroTreeNode[];
|
|
3336
|
+
/**
|
|
3337
|
+
* Get the parent container of the tree container.
|
|
3338
|
+
*
|
|
3339
|
+
* - The parent container of the root tree is `undefined`.
|
|
3340
|
+
* - The object returned is a new js object each time because it need to cross
|
|
3341
|
+
* the WASM boundary.
|
|
3342
|
+
*/
|
|
3607
3343
|
parent(): Container | undefined;
|
|
3608
|
-
/**
|
|
3609
|
-
* Whether the container is attached to a document.
|
|
3610
|
-
*
|
|
3611
|
-
* If it's detached, the operations on the container will not be persisted.
|
|
3612
|
-
|
|
3613
|
-
*/
|
|
3344
|
+
/**
|
|
3345
|
+
* Whether the container is attached to a document.
|
|
3346
|
+
*
|
|
3347
|
+
* If it's detached, the operations on the container will not be persisted.
|
|
3348
|
+
*/
|
|
3614
3349
|
isAttached(): boolean;
|
|
3615
|
-
/**
|
|
3616
|
-
* Get the attached container associated with this.
|
|
3617
|
-
*
|
|
3618
|
-
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
3619
|
-
|
|
3620
|
-
*/
|
|
3350
|
+
/**
|
|
3351
|
+
* Get the attached container associated with this.
|
|
3352
|
+
*
|
|
3353
|
+
* Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
|
|
3354
|
+
*/
|
|
3621
3355
|
getAttached(): LoroTree | undefined;
|
|
3622
|
-
/**
|
|
3623
|
-
* Set whether to generate a fractional index for moving and creating.
|
|
3624
|
-
*
|
|
3625
|
-
* A fractional index can be used to determine the position of tree nodes among their siblings.
|
|
3626
|
-
*
|
|
3627
|
-
* The jitter is used to avoid conflicts when multiple users are creating a node at the same position.
|
|
3628
|
-
* A value of 0 is the default, which means no jitter; any value larger than 0 will enable jitter.
|
|
3629
|
-
*
|
|
3630
|
-
* Generally speaking, higher jitter value will increase the size of the operation
|
|
3631
|
-
* [Read more about it](https://www.loro.dev/blog/movable-tree#implementation-and-encoding-size)
|
|
3632
|
-
|
|
3633
|
-
*/
|
|
3356
|
+
/**
|
|
3357
|
+
* Set whether to generate a fractional index for moving and creating.
|
|
3358
|
+
*
|
|
3359
|
+
* A fractional index can be used to determine the position of tree nodes among their siblings.
|
|
3360
|
+
*
|
|
3361
|
+
* The jitter is used to avoid conflicts when multiple users are creating a node at the same position.
|
|
3362
|
+
* A value of 0 is the default, which means no jitter; any value larger than 0 will enable jitter.
|
|
3363
|
+
*
|
|
3364
|
+
* Generally speaking, higher jitter value will increase the size of the operation
|
|
3365
|
+
* [Read more about it](https://www.loro.dev/blog/movable-tree#implementation-and-encoding-size)
|
|
3366
|
+
*/
|
|
3634
3367
|
enableFractionalIndex(jitter: number): void;
|
|
3635
|
-
/**
|
|
3636
|
-
* Disable the fractional index generation when you don't need the Tree's siblings to be sorted.
|
|
3637
|
-
* The fractional index will always be set to the same default value 0.
|
|
3638
|
-
*
|
|
3639
|
-
* After calling this, you cannot use `tree.moveTo()`, `tree.moveBefore()`, `tree.moveAfter()`,
|
|
3640
|
-
* and `tree.createAt()`.
|
|
3641
|
-
*/
|
|
3368
|
+
/**
|
|
3369
|
+
* Disable the fractional index generation when you don't need the Tree's siblings to be sorted.
|
|
3370
|
+
* The fractional index will always be set to the same default value 0.
|
|
3371
|
+
*
|
|
3372
|
+
* After calling this, you cannot use `tree.moveTo()`, `tree.moveBefore()`, `tree.moveAfter()`,
|
|
3373
|
+
* and `tree.createAt()`.
|
|
3374
|
+
*/
|
|
3642
3375
|
disableFractionalIndex(): void;
|
|
3643
|
-
/**
|
|
3644
|
-
* Whether the tree enables the fractional index generation.
|
|
3645
|
-
|
|
3646
|
-
*/
|
|
3376
|
+
/**
|
|
3377
|
+
* Whether the tree enables the fractional index generation.
|
|
3378
|
+
*/
|
|
3647
3379
|
isFractionalIndexEnabled(): boolean;
|
|
3648
|
-
/**
|
|
3649
|
-
* Check if the container is deleted
|
|
3650
|
-
|
|
3651
|
-
*/
|
|
3380
|
+
/**
|
|
3381
|
+
* Check if the container is deleted
|
|
3382
|
+
*/
|
|
3652
3383
|
isDeleted(): boolean;
|
|
3653
|
-
/**
|
|
3654
|
-
* Get the shallow value of the tree.
|
|
3655
|
-
*
|
|
3656
|
-
* Unlike `toJSON()` which recursively resolves nested containers to their values,
|
|
3657
|
-
* `getShallowValue()` returns container IDs as strings for any nested containers.
|
|
3658
|
-
*
|
|
3659
|
-
* @example
|
|
3660
|
-
* ```ts
|
|
3661
|
-
* const doc = new LoroDoc();
|
|
3662
|
-
* doc.setPeerId("1");
|
|
3663
|
-
* const tree = doc.getTree("tree");
|
|
3664
|
-
* const root = tree.createNode();
|
|
3665
|
-
* root.data.set("name", "root");
|
|
3666
|
-
* const text = root.data.setContainer("content", new LoroText());
|
|
3667
|
-
* text.insert(0, "Hello");
|
|
3668
|
-
*
|
|
3669
|
-
* console.log(tree.getShallowValue());
|
|
3670
|
-
* // [{
|
|
3671
|
-
* // id: "0@1",
|
|
3672
|
-
* // parent: null,
|
|
3673
|
-
* // index: 0,
|
|
3674
|
-
* // fractional_index: "80",
|
|
3675
|
-
* // meta: "cid:0@1:Map",
|
|
3676
|
-
* // children: []
|
|
3677
|
-
* // }]
|
|
3678
|
-
*
|
|
3679
|
-
* console.log(tree.toJSON());
|
|
3680
|
-
* // [{
|
|
3681
|
-
* // id: "0@1",
|
|
3682
|
-
* // parent: null,
|
|
3683
|
-
* // index: 0,
|
|
3684
|
-
* // fractional_index: "80",
|
|
3685
|
-
* // meta: {
|
|
3686
|
-
* // name: "root",
|
|
3687
|
-
* // content: "Hello"
|
|
3688
|
-
* // },
|
|
3689
|
-
* // children: []
|
|
3690
|
-
* // }]
|
|
3691
|
-
* ```
|
|
3692
|
-
|
|
3693
|
-
*/
|
|
3384
|
+
/**
|
|
3385
|
+
* Get the shallow value of the tree.
|
|
3386
|
+
*
|
|
3387
|
+
* Unlike `toJSON()` which recursively resolves nested containers to their values,
|
|
3388
|
+
* `getShallowValue()` returns container IDs as strings for any nested containers.
|
|
3389
|
+
*
|
|
3390
|
+
* @example
|
|
3391
|
+
* ```ts
|
|
3392
|
+
* const doc = new LoroDoc();
|
|
3393
|
+
* doc.setPeerId("1");
|
|
3394
|
+
* const tree = doc.getTree("tree");
|
|
3395
|
+
* const root = tree.createNode();
|
|
3396
|
+
* root.data.set("name", "root");
|
|
3397
|
+
* const text = root.data.setContainer("content", new LoroText());
|
|
3398
|
+
* text.insert(0, "Hello");
|
|
3399
|
+
*
|
|
3400
|
+
* console.log(tree.getShallowValue());
|
|
3401
|
+
* // [{
|
|
3402
|
+
* // id: "0@1",
|
|
3403
|
+
* // parent: null,
|
|
3404
|
+
* // index: 0,
|
|
3405
|
+
* // fractional_index: "80",
|
|
3406
|
+
* // meta: "cid:0@1:Map",
|
|
3407
|
+
* // children: []
|
|
3408
|
+
* // }]
|
|
3409
|
+
*
|
|
3410
|
+
* console.log(tree.toJSON());
|
|
3411
|
+
* // [{
|
|
3412
|
+
* // id: "0@1",
|
|
3413
|
+
* // parent: null,
|
|
3414
|
+
* // index: 0,
|
|
3415
|
+
* // fractional_index: "80",
|
|
3416
|
+
* // meta: {
|
|
3417
|
+
* // name: "root",
|
|
3418
|
+
* // content: "Hello"
|
|
3419
|
+
* // },
|
|
3420
|
+
* // children: []
|
|
3421
|
+
* // }]
|
|
3422
|
+
* ```
|
|
3423
|
+
*/
|
|
3694
3424
|
getShallowValue(): TreeNodeShallowValue[];
|
|
3695
|
-
/**
|
|
3696
|
-
* Get the id of the container.
|
|
3697
|
-
*/
|
|
3425
|
+
/**
|
|
3426
|
+
* Get the id of the container.
|
|
3427
|
+
*/
|
|
3698
3428
|
readonly id: ContainerID;
|
|
3699
3429
|
}
|
|
3700
3430
|
/**
|
|
3701
|
-
* The handler of a tree node.
|
|
3702
|
-
*/
|
|
3431
|
+
* The handler of a tree node.
|
|
3432
|
+
*/
|
|
3703
3433
|
export class LoroTreeNode {
|
|
3434
|
+
private constructor();
|
|
3704
3435
|
free(): void;
|
|
3705
|
-
/**
|
|
3706
|
-
* @returns {string}
|
|
3707
|
-
*/
|
|
3708
3436
|
__getClassname(): string;
|
|
3709
|
-
/**
|
|
3710
|
-
* Move the tree node to be after the target node.
|
|
3711
|
-
*
|
|
3712
|
-
* @example
|
|
3713
|
-
* ```ts
|
|
3714
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3715
|
-
*
|
|
3716
|
-
* const doc = new LoroDoc();
|
|
3717
|
-
* const tree = doc.getTree("tree");
|
|
3718
|
-
* const root = tree.createNode();
|
|
3719
|
-
* const node = root.createNode();
|
|
3720
|
-
* const node2 = root.createNode();
|
|
3721
|
-
* node2.moveAfter(node);
|
|
3722
|
-
* // root
|
|
3723
|
-
* // / \
|
|
3724
|
-
* // node node2
|
|
3725
|
-
* ```
|
|
3726
|
-
|
|
3727
|
-
*/
|
|
3437
|
+
/**
|
|
3438
|
+
* Move the tree node to be after the target node.
|
|
3439
|
+
*
|
|
3440
|
+
* @example
|
|
3441
|
+
* ```ts
|
|
3442
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3443
|
+
*
|
|
3444
|
+
* const doc = new LoroDoc();
|
|
3445
|
+
* const tree = doc.getTree("tree");
|
|
3446
|
+
* const root = tree.createNode();
|
|
3447
|
+
* const node = root.createNode();
|
|
3448
|
+
* const node2 = root.createNode();
|
|
3449
|
+
* node2.moveAfter(node);
|
|
3450
|
+
* // root
|
|
3451
|
+
* // / \
|
|
3452
|
+
* // node node2
|
|
3453
|
+
* ```
|
|
3454
|
+
*/
|
|
3728
3455
|
moveAfter(target: LoroTreeNode): void;
|
|
3729
|
-
/**
|
|
3730
|
-
* Move the tree node to be before the target node.
|
|
3731
|
-
*
|
|
3732
|
-
* @example
|
|
3733
|
-
* ```ts
|
|
3734
|
-
* import { LoroDoc } from "loro-crdt";
|
|
3735
|
-
*
|
|
3736
|
-
* const doc = new LoroDoc();
|
|
3737
|
-
* const tree = doc.getTree("tree");
|
|
3738
|
-
* const root = tree.createNode();
|
|
3739
|
-
* const node = root.createNode();
|
|
3740
|
-
* const node2 = root.createNode();
|
|
3741
|
-
* node2.moveBefore(node);
|
|
3742
|
-
* // root
|
|
3743
|
-
* // / \
|
|
3744
|
-
* // node2 node
|
|
3745
|
-
* ```
|
|
3746
|
-
|
|
3747
|
-
*/
|
|
3456
|
+
/**
|
|
3457
|
+
* Move the tree node to be before the target node.
|
|
3458
|
+
*
|
|
3459
|
+
* @example
|
|
3460
|
+
* ```ts
|
|
3461
|
+
* import { LoroDoc } from "loro-crdt";
|
|
3462
|
+
*
|
|
3463
|
+
* const doc = new LoroDoc();
|
|
3464
|
+
* const tree = doc.getTree("tree");
|
|
3465
|
+
* const root = tree.createNode();
|
|
3466
|
+
* const node = root.createNode();
|
|
3467
|
+
* const node2 = root.createNode();
|
|
3468
|
+
* node2.moveBefore(node);
|
|
3469
|
+
* // root
|
|
3470
|
+
* // / \
|
|
3471
|
+
* // node2 node
|
|
3472
|
+
* ```
|
|
3473
|
+
*/
|
|
3748
3474
|
moveBefore(target: LoroTreeNode): void;
|
|
3749
|
-
/**
|
|
3750
|
-
* Get the index of the node in the parent's children.
|
|
3751
|
-
|
|
3752
|
-
*/
|
|
3475
|
+
/**
|
|
3476
|
+
* Get the index of the node in the parent's children.
|
|
3477
|
+
*/
|
|
3753
3478
|
index(): number | undefined;
|
|
3754
|
-
/**
|
|
3755
|
-
* Get the `Fractional Index` of the node.
|
|
3756
|
-
*
|
|
3757
|
-
* Note: the tree container must be attached to the document.
|
|
3758
|
-
|
|
3759
|
-
*/
|
|
3479
|
+
/**
|
|
3480
|
+
* Get the `Fractional Index` of the node.
|
|
3481
|
+
*
|
|
3482
|
+
* Note: the tree container must be attached to the document.
|
|
3483
|
+
*/
|
|
3760
3484
|
fractionalIndex(): string | undefined;
|
|
3761
|
-
/**
|
|
3762
|
-
* Check if the node is deleted.
|
|
3763
|
-
|
|
3764
|
-
*/
|
|
3485
|
+
/**
|
|
3486
|
+
* Check if the node is deleted.
|
|
3487
|
+
*/
|
|
3765
3488
|
isDeleted(): boolean;
|
|
3766
|
-
/**
|
|
3767
|
-
* Get the last mover of this node.
|
|
3768
|
-
|
|
3769
|
-
*/
|
|
3489
|
+
/**
|
|
3490
|
+
* Get the last mover of this node.
|
|
3491
|
+
*/
|
|
3770
3492
|
getLastMoveId(): { peer: PeerID, counter: number } | undefined;
|
|
3771
|
-
/**
|
|
3772
|
-
* Get the creation id of this node.
|
|
3773
|
-
|
|
3774
|
-
*/
|
|
3493
|
+
/**
|
|
3494
|
+
* Get the creation id of this node.
|
|
3495
|
+
*/
|
|
3775
3496
|
creationId(): { peer: PeerID, counter: number };
|
|
3776
|
-
/**
|
|
3777
|
-
* Get the creator of this node.
|
|
3778
|
-
|
|
3779
|
-
*/
|
|
3497
|
+
/**
|
|
3498
|
+
* Get the creator of this node.
|
|
3499
|
+
*/
|
|
3780
3500
|
creator(): PeerID;
|
|
3781
|
-
/**
|
|
3782
|
-
* The TreeID of the node.
|
|
3783
|
-
*/
|
|
3501
|
+
/**
|
|
3502
|
+
* The TreeID of the node.
|
|
3503
|
+
*/
|
|
3784
3504
|
readonly id: TreeID;
|
|
3785
3505
|
}
|
|
3786
3506
|
/**
|
|
3787
|
-
* `UndoManager` is responsible for handling undo and redo operations.
|
|
3788
|
-
*
|
|
3789
|
-
* By default, the maxUndoSteps is set to 100, mergeInterval is set to 1000 ms.
|
|
3790
|
-
*
|
|
3791
|
-
* Each commit made by the current peer is recorded as an undo step in the `UndoManager`.
|
|
3792
|
-
* Undo steps can be merged if they occur within a specified merge interval.
|
|
3793
|
-
*
|
|
3794
|
-
* Note that undo operations are local and cannot revert changes made by other peers.
|
|
3795
|
-
* To undo changes made by other peers, consider using the time travel feature.
|
|
3796
|
-
*
|
|
3797
|
-
* Once the `peerId` is bound to the `UndoManager` in the document, it cannot be changed.
|
|
3798
|
-
* Otherwise, the `UndoManager` may not function correctly.
|
|
3799
|
-
*/
|
|
3507
|
+
* `UndoManager` is responsible for handling undo and redo operations.
|
|
3508
|
+
*
|
|
3509
|
+
* By default, the maxUndoSteps is set to 100, mergeInterval is set to 1000 ms.
|
|
3510
|
+
*
|
|
3511
|
+
* Each commit made by the current peer is recorded as an undo step in the `UndoManager`.
|
|
3512
|
+
* Undo steps can be merged if they occur within a specified merge interval.
|
|
3513
|
+
*
|
|
3514
|
+
* Note that undo operations are local and cannot revert changes made by other peers.
|
|
3515
|
+
* To undo changes made by other peers, consider using the time travel feature.
|
|
3516
|
+
*
|
|
3517
|
+
* Once the `peerId` is bound to the `UndoManager` in the document, it cannot be changed.
|
|
3518
|
+
* Otherwise, the `UndoManager` may not function correctly.
|
|
3519
|
+
*/
|
|
3800
3520
|
export class UndoManager {
|
|
3801
3521
|
free(): void;
|
|
3802
|
-
/**
|
|
3803
|
-
* `UndoManager` is responsible for handling undo and redo operations.
|
|
3804
|
-
*
|
|
3805
|
-
* PeerID cannot be changed during the lifetime of the UndoManager.
|
|
3806
|
-
*
|
|
3807
|
-
* Note that undo operations are local and cannot revert changes made by other peers.
|
|
3808
|
-
* To undo changes made by other peers, consider using the time travel feature.
|
|
3809
|
-
*
|
|
3810
|
-
* Each commit made by the current peer is recorded as an undo step in the `UndoManager`.
|
|
3811
|
-
* Undo steps can be merged if they occur within a specified merge interval.
|
|
3812
|
-
*
|
|
3813
|
-
* ## Config
|
|
3814
|
-
*
|
|
3815
|
-
* - `mergeInterval`: Optional. The interval in milliseconds within which undo steps can be merged. Default is 1000 ms.
|
|
3816
|
-
* - `maxUndoSteps`: Optional. The maximum number of undo steps to retain. Default is 100.
|
|
3817
|
-
* - `excludeOriginPrefixes`: Optional. An array of string prefixes. Events with origins matching these prefixes will be excluded from undo steps.
|
|
3818
|
-
* - `onPush`: Optional. A callback function that is called when an undo/redo step is pushed.
|
|
3819
|
-
* The function can return a meta data value that will be attached to the given stack item.
|
|
3820
|
-
* - `onPop`: Optional. A callback function that is called when an undo/redo step is popped.
|
|
3821
|
-
* The function will have a meta data value that was attached to the given stack item when
|
|
3822
|
-
* `onPush` was called.
|
|
3823
|
-
|
|
3824
|
-
* @param {UndoConfig} config
|
|
3825
|
-
*/
|
|
3522
|
+
/**
|
|
3523
|
+
* `UndoManager` is responsible for handling undo and redo operations.
|
|
3524
|
+
*
|
|
3525
|
+
* PeerID cannot be changed during the lifetime of the UndoManager.
|
|
3526
|
+
*
|
|
3527
|
+
* Note that undo operations are local and cannot revert changes made by other peers.
|
|
3528
|
+
* To undo changes made by other peers, consider using the time travel feature.
|
|
3529
|
+
*
|
|
3530
|
+
* Each commit made by the current peer is recorded as an undo step in the `UndoManager`.
|
|
3531
|
+
* Undo steps can be merged if they occur within a specified merge interval.
|
|
3532
|
+
*
|
|
3533
|
+
* ## Config
|
|
3534
|
+
*
|
|
3535
|
+
* - `mergeInterval`: Optional. The interval in milliseconds within which undo steps can be merged. Default is 1000 ms.
|
|
3536
|
+
* - `maxUndoSteps`: Optional. The maximum number of undo steps to retain. Default is 100.
|
|
3537
|
+
* - `excludeOriginPrefixes`: Optional. An array of string prefixes. Events with origins matching these prefixes will be excluded from undo steps.
|
|
3538
|
+
* - `onPush`: Optional. A callback function that is called when an undo/redo step is pushed.
|
|
3539
|
+
* The function can return a meta data value that will be attached to the given stack item.
|
|
3540
|
+
* - `onPop`: Optional. A callback function that is called when an undo/redo step is popped.
|
|
3541
|
+
* The function will have a meta data value that was attached to the given stack item when
|
|
3542
|
+
* `onPush` was called.
|
|
3543
|
+
*/
|
|
3826
3544
|
constructor(doc: LoroDoc, config: UndoConfig);
|
|
3827
|
-
/**
|
|
3828
|
-
* Undo the last operation.
|
|
3829
|
-
|
|
3830
|
-
*/
|
|
3545
|
+
/**
|
|
3546
|
+
* Undo the last operation.
|
|
3547
|
+
*/
|
|
3831
3548
|
undo(): boolean;
|
|
3832
|
-
/**
|
|
3833
|
-
* Redo the last undone operation.
|
|
3834
|
-
|
|
3835
|
-
*/
|
|
3549
|
+
/**
|
|
3550
|
+
* Redo the last undone operation.
|
|
3551
|
+
*/
|
|
3836
3552
|
redo(): boolean;
|
|
3837
|
-
/**
|
|
3838
|
-
* Can undo the last operation.
|
|
3839
|
-
|
|
3840
|
-
*/
|
|
3553
|
+
/**
|
|
3554
|
+
* Can undo the last operation.
|
|
3555
|
+
*/
|
|
3841
3556
|
canUndo(): boolean;
|
|
3842
|
-
/**
|
|
3843
|
-
* Can redo the last operation.
|
|
3844
|
-
|
|
3845
|
-
*/
|
|
3557
|
+
/**
|
|
3558
|
+
* Can redo the last operation.
|
|
3559
|
+
*/
|
|
3846
3560
|
canRedo(): boolean;
|
|
3847
|
-
/**
|
|
3848
|
-
* The number of max undo steps.
|
|
3849
|
-
* If the number of undo steps exceeds this number, the oldest undo step will be removed.
|
|
3850
|
-
|
|
3851
|
-
*/
|
|
3561
|
+
/**
|
|
3562
|
+
* The number of max undo steps.
|
|
3563
|
+
* If the number of undo steps exceeds this number, the oldest undo step will be removed.
|
|
3564
|
+
*/
|
|
3852
3565
|
setMaxUndoSteps(steps: number): void;
|
|
3853
|
-
/**
|
|
3854
|
-
* Set the merge interval (in ms).
|
|
3855
|
-
*
|
|
3856
|
-
* If the interval is set to 0, the undo steps will not be merged.
|
|
3857
|
-
* Otherwise, the undo steps will be merged if the interval between the two steps is less than the given interval.
|
|
3858
|
-
|
|
3859
|
-
*/
|
|
3566
|
+
/**
|
|
3567
|
+
* Set the merge interval (in ms).
|
|
3568
|
+
*
|
|
3569
|
+
* If the interval is set to 0, the undo steps will not be merged.
|
|
3570
|
+
* Otherwise, the undo steps will be merged if the interval between the two steps is less than the given interval.
|
|
3571
|
+
*/
|
|
3860
3572
|
setMergeInterval(interval: number): void;
|
|
3861
|
-
/**
|
|
3862
|
-
* If a local event's origin matches the given prefix, it will not be recorded in the
|
|
3863
|
-
* undo stack.
|
|
3864
|
-
|
|
3865
|
-
*/
|
|
3573
|
+
/**
|
|
3574
|
+
* If a local event's origin matches the given prefix, it will not be recorded in the
|
|
3575
|
+
* undo stack.
|
|
3576
|
+
*/
|
|
3866
3577
|
addExcludeOriginPrefix(prefix: string): void;
|
|
3867
|
-
/**
|
|
3868
|
-
*/
|
|
3869
3578
|
clear(): void;
|
|
3870
3579
|
}
|
|
3871
3580
|
/**
|
|
3872
|
-
* [VersionVector](https://en.wikipedia.org/wiki/Version_vector)
|
|
3873
|
-
* is a map from [PeerID] to [Counter]. Its a right-open interval.
|
|
3874
|
-
*
|
|
3875
|
-
* i.e. a [VersionVector] of `{A: 1, B: 2}` means that A has 1 atomic op and B has 2 atomic ops,
|
|
3876
|
-
* thus ID of `{client: A, counter: 1}` is out of the range.
|
|
3877
|
-
*/
|
|
3581
|
+
* [VersionVector](https://en.wikipedia.org/wiki/Version_vector)
|
|
3582
|
+
* is a map from [PeerID] to [Counter]. Its a right-open interval.
|
|
3583
|
+
*
|
|
3584
|
+
* i.e. a [VersionVector] of `{A: 1, B: 2}` means that A has 1 atomic op and B has 2 atomic ops,
|
|
3585
|
+
* thus ID of `{client: A, counter: 1}` is out of the range.
|
|
3586
|
+
*/
|
|
3878
3587
|
export class VersionVector {
|
|
3879
3588
|
free(): void;
|
|
3880
|
-
/**
|
|
3881
|
-
* Create a new version vector.
|
|
3882
|
-
|
|
3883
|
-
*/
|
|
3589
|
+
/**
|
|
3590
|
+
* Create a new version vector.
|
|
3591
|
+
*/
|
|
3884
3592
|
constructor(value: Map<PeerID, number> | Uint8Array | VersionVector | undefined | null);
|
|
3885
|
-
/**
|
|
3886
|
-
* Create a new version vector from a Map.
|
|
3887
|
-
|
|
3888
|
-
* @returns {VersionVector}
|
|
3889
|
-
*/
|
|
3593
|
+
/**
|
|
3594
|
+
* Create a new version vector from a Map.
|
|
3595
|
+
*/
|
|
3890
3596
|
static parseJSON(version: Map<PeerID, number>): VersionVector;
|
|
3891
|
-
/**
|
|
3892
|
-
* Convert the version vector to a Map
|
|
3893
|
-
|
|
3894
|
-
*/
|
|
3597
|
+
/**
|
|
3598
|
+
* Convert the version vector to a Map
|
|
3599
|
+
*/
|
|
3895
3600
|
toJSON(): Map<PeerID, number>;
|
|
3896
|
-
/**
|
|
3897
|
-
* Encode the version vector into a Uint8Array.
|
|
3898
|
-
|
|
3899
|
-
*/
|
|
3601
|
+
/**
|
|
3602
|
+
* Encode the version vector into a Uint8Array.
|
|
3603
|
+
*/
|
|
3900
3604
|
encode(): Uint8Array;
|
|
3901
|
-
/**
|
|
3902
|
-
* Decode the version vector from a Uint8Array.
|
|
3903
|
-
|
|
3904
|
-
* @returns {VersionVector}
|
|
3905
|
-
*/
|
|
3605
|
+
/**
|
|
3606
|
+
* Decode the version vector from a Uint8Array.
|
|
3607
|
+
*/
|
|
3906
3608
|
static decode(bytes: Uint8Array): VersionVector;
|
|
3907
|
-
/**
|
|
3908
|
-
* Get the counter of a peer.
|
|
3909
|
-
|
|
3910
|
-
* @returns {number | undefined}
|
|
3911
|
-
*/
|
|
3609
|
+
/**
|
|
3610
|
+
* Get the counter of a peer.
|
|
3611
|
+
*/
|
|
3912
3612
|
get(peer_id: number | bigint | `${number}`): number | undefined;
|
|
3913
|
-
/**
|
|
3914
|
-
* Compare the version vector with another version vector.
|
|
3915
|
-
*
|
|
3916
|
-
* If they are concurrent, return undefined.
|
|
3917
|
-
|
|
3918
|
-
* @returns {number | undefined}
|
|
3919
|
-
*/
|
|
3613
|
+
/**
|
|
3614
|
+
* Compare the version vector with another version vector.
|
|
3615
|
+
*
|
|
3616
|
+
* If they are concurrent, return undefined.
|
|
3617
|
+
*/
|
|
3920
3618
|
compare(other: VersionVector): number | undefined;
|
|
3921
|
-
/**
|
|
3922
|
-
* set the exclusive ending point. target id will NOT be included by self
|
|
3923
|
-
|
|
3924
|
-
*/
|
|
3619
|
+
/**
|
|
3620
|
+
* set the exclusive ending point. target id will NOT be included by self
|
|
3621
|
+
*/
|
|
3925
3622
|
setEnd(id: { peer: PeerID, counter: number }): void;
|
|
3926
|
-
/**
|
|
3927
|
-
* set the inclusive ending point. target id will be included
|
|
3928
|
-
|
|
3929
|
-
*/
|
|
3623
|
+
/**
|
|
3624
|
+
* set the inclusive ending point. target id will be included
|
|
3625
|
+
*/
|
|
3930
3626
|
setLast(id: { peer: PeerID, counter: number }): void;
|
|
3931
|
-
/**
|
|
3932
|
-
* @param {PeerID} peer
|
|
3933
|
-
*/
|
|
3934
3627
|
remove(peer: PeerID): void;
|
|
3935
|
-
/**
|
|
3936
|
-
* @returns {number}
|
|
3937
|
-
*/
|
|
3938
3628
|
length(): number;
|
|
3939
3629
|
}
|