loro-crdt 1.5.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,42 +1,28 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  /**
4
- * Get the version of Loro
5
- * @returns {string}
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
- * @param {Uint8Array} blob
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,2521 +1406,2248 @@ 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
- * @param {number | bigint | `${number}`} peer
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
- * @param {Array<any>} peers
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
- * @returns {Uint8Array}
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
- * @param {Uint8Array} encoded_peers_info
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
- * @returns {PeerID}
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
- * @param {number | bigint | `${number}`} peer
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
- * @returns {(PeerID)[]}
1476
- */
1477
- removeOutdated(): (PeerID)[];
1478
- /**
1479
- * Get the number of peers.
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
- * @returns {boolean}
1486
- */
1457
+ /**
1458
+ * If the state is empty.
1459
+ */
1487
1460
  isEmpty(): boolean;
1488
- /**
1489
- * Get all the peers
1490
- * @returns {(PeerID)[]}
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
- * @returns {ContainerID}
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
- * @returns {{ peer: PeerID, counter: number } | undefined}
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
- * @returns {Side}
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
- * @returns {Uint8Array}
1564
- */
1522
+ /**
1523
+ * Encode the cursor into a Uint8Array.
1524
+ */
1565
1525
  encode(): Uint8Array;
1566
- /**
1567
- * Decode the cursor from a Uint8Array.
1568
- * @param {Uint8Array} data
1569
- * @returns {Cursor}
1570
- */
1526
+ /**
1527
+ * Decode the cursor from a Uint8Array.
1528
+ */
1571
1529
  static decode(data: Uint8Array): Cursor;
1572
- /**
1573
- * "Cursor"
1574
- * @returns {any}
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
- * @param {number} timeout
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
- * @returns {boolean}
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
- * @returns {'Counter'}
1647
- */
1568
+ /**
1569
+ * "Counter"
1570
+ */
1648
1571
  kind(): 'Counter';
1649
- /**
1650
- * Increment the counter by the given value.
1651
- * @param {number} value
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
- * @param {number} value
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
- * @param {Function} f
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
- * @returns {Container | undefined}
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
- * @returns {boolean}
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
- * @returns {LoroTree | undefined}
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
- * @returns {number}
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
- * @param {boolean} enable
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
- * @returns {boolean}
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
- * @param {boolean} auto_record
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
- * @param {number} interval
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
- * @param {{[key: string]: { expand: 'before'|'after'|'none'|'both' }}} styles
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
- * @param {{ expand: 'before'|'after'|'none'|'both' } | undefined} style
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
- * @param {Uint8Array} snapshot
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
- * @returns {boolean}
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
- * @returns {LoroDoc}
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
- * @param {({ peer: PeerID, counter: number })[]} frontiers
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
- * @param {({ peer: PeerID, counter: number })[]} ids
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
- * @param {({ peer: PeerID, counter: number })[]} from
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
- * @param {({ peer: PeerID, counter: number })[]} frontiers
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
- * @param {number | bigint | `${number}`} peer_id
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
- * @param {{ origin?: string, timestamp?: number, message?: string } | undefined} [options]
2074
- */
2075
- commit(options?: { origin?: string, timestamp?: number, message?: string }): void;
2076
- /**
2077
- * Get the number of operations in the pending transaction.
2078
- *
2079
- * The pending transaction is the one that is not committed yet. It will be committed
2080
- * automatically after calling `doc.commit()`, `doc.export(mode)` or `doc.checkout(version)`.
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
- * @param {ContainerID | string} cid
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
- * @param {ContainerID | string} cid
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
- * @param {ContainerID} container_id
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
- * @param {string} msg
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
- * @param {string} origin
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
- * @param {number} timestamp
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
- * @param {{ origin?: string, timestamp?: number, message?: string }} options
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
- * @returns {any}
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
- * @param {ContainerID} id
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
- * @param {string} jsonpath
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
- * @returns {VersionVector}
2187
- */
2188
- 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
- * @returns {VersionVector}
2196
- */
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
+ */
2066
+ version(): VersionVector;
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
- * @returns {boolean}
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
- * @returns {{ peer: PeerID, counter: number }[]}
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
- * @returns {VersionVector}
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
- * @returns {{ peer: PeerID, counter: number }[]}
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
- * @returns {{ peer: PeerID, counter: number }[]}
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
- * @param {({ peer: PeerID, counter: number })[]} frontiers
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
- * @param {({ peer: PeerID, counter: number })[]} a
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
- * @returns {Uint8Array}
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
- * @param {ExportMode} mode
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
- * @param {string | JsonSchema} json
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
- * @param {Uint8Array} update_or_snapshot
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
- * @param {Uint8Array[]} data
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
- * @param {Uint8Array[]} data
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
- * @returns {Record<string, ContainerID>}
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
- * @returns {any}
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
- * @returns {number}
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
- * @returns {number}
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
- * @returns {Map<PeerID, Change[]>}
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
- * @param {{ peer: PeerID, counter: number }} id
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
- * @param {string} peer_id
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
- * @param {{ peer: PeerID, counter: number }} id
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
- * @param {({ peer: PeerID, counter: number })[]} frontiers
2520
- * @returns {VersionVector}
2521
- */
2522
- 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
- * @param {VersionVector} vv
2537
- * @returns {{ peer: PeerID, counter: number }[]}
2538
- */
2539
- 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
- * @param {string} path
2569
- * @returns {Value | Container | undefined}
2570
- */
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
+ */
2364
+ frontiersToVV(frontiers: ({ peer: PeerID, counter: number })[]): VersionVector;
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
+ */
2379
+ vvToFrontiers(vv: VersionVector): { peer: PeerID, counter: number }[];
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
- * @param {Cursor} cursor
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
- * @param {{ peer: PeerID, counter: number }} id
2608
- * @param {number} len
2609
- * @returns {(ContainerID)[]}
2610
- */
2611
- getChangedContainersIn(id: { peer: PeerID, counter: number }, len: number): (ContainerID)[];
2612
- /**
2613
- * Revert the document to the given frontiers.
2614
- *
2615
- * The doc will not become detached when using this method. Instead, it will generate a series
2616
- * of operations to revert the document to the given version.
2617
- *
2618
- * @example
2619
- * ```ts
2620
- * const doc = new LoroDoc();
2621
- * doc.setPeerId("1");
2622
- * const text = doc.getText("text");
2623
- * text.insert(0, "Hello");
2624
- * doc.commit();
2625
- * doc.revertTo([{ peer: "1", counter: 1 }]);
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
- * @param {[ContainerID, Diff|JsonDiff][]} diff
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
- * @returns {JsonSchema | undefined}
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
+ * Delete all content from a root container and hide it from the document.
2513
+ *
2514
+ * When a root container is empty and hidden:
2515
+ * - It won't show up in `get_deep_value()` results
2516
+ * - It won't be included in document snapshots
2517
+ *
2518
+ * Only works on root containers (containers without parents).
2519
+ */
2520
+ deleteRootContainer(cid: ContainerID): void;
2521
+ /**
2522
+ * Set whether to hide empty root containers.
2523
+ *
2524
+ * @example
2525
+ * ```ts
2526
+ * const doc = new LoroDoc();
2527
+ * const map = doc.getMap("map");
2528
+ * console.log(doc.toJSON()); // { map: {} }
2529
+ * doc.setHideEmptyRootContainers(true);
2530
+ * console.log(doc.toJSON()); // {}
2531
+ * ```
2532
+ */
2533
+ setHideEmptyRootContainers(hide: boolean): void;
2534
+ /**
2535
+ * Peer ID of the current writer.
2536
+ */
2684
2537
  readonly peerId: bigint;
2685
- /**
2686
- * Get peer id in decimal string.
2687
- */
2538
+ /**
2539
+ * Get peer id in decimal string.
2540
+ */
2688
2541
  readonly peerIdStr: PeerID;
2689
2542
  }
2690
2543
  /**
2691
- * The handler of a list container.
2692
- *
2693
- * Learn more at https://loro.dev/docs/tutorial/list
2694
- */
2544
+ * The handler of a list container.
2545
+ *
2546
+ * Learn more at https://loro.dev/docs/tutorial/list
2547
+ */
2695
2548
  export class LoroList {
2696
2549
  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
- */
2550
+ /**
2551
+ * Create a new detached LoroList (not attached to any LoroDoc).
2552
+ *
2553
+ * The edits on a detached container will not be persisted.
2554
+ * To attach the container to the document, please insert it into an attached container.
2555
+ */
2703
2556
  constructor();
2704
- /**
2705
- * "List"
2706
- * @returns {'List'}
2707
- */
2557
+ /**
2558
+ * "List"
2559
+ */
2708
2560
  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
- * @param {number} index
2723
- * @param {number} len
2724
- */
2561
+ /**
2562
+ * Delete elements from index to index + len.
2563
+ *
2564
+ * @example
2565
+ * ```ts
2566
+ * import { LoroDoc } from "loro-crdt";
2567
+ *
2568
+ * const doc = new LoroDoc();
2569
+ * const list = doc.getList("list");
2570
+ * list.insert(0, 100);
2571
+ * list.delete(0, 1);
2572
+ * console.log(list.value); // []
2573
+ * ```
2574
+ */
2725
2575
  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
- * @returns {any}
2742
- */
2576
+ /**
2577
+ * Get elements of the list. If the type of a element is a container, it will be
2578
+ * resolved recursively.
2579
+ *
2580
+ * @example
2581
+ * ```ts
2582
+ * import { LoroDoc, LoroText } from "loro-crdt";
2583
+ *
2584
+ * const doc = new LoroDoc();
2585
+ * const list = doc.getList("list");
2586
+ * list.insert(0, 100);
2587
+ * const text = list.insertContainer(1, new LoroText());
2588
+ * text.insert(0, "Hello");
2589
+ * console.log(list.toJSON()); // [100, "Hello"];
2590
+ * ```
2591
+ */
2743
2592
  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
- * @returns {Container | undefined}
2751
- */
2593
+ /**
2594
+ * Get the parent container.
2595
+ *
2596
+ * - The parent container of the root tree is `undefined`.
2597
+ * - The object returned is a new js object each time because it need to cross
2598
+ * the WASM boundary.
2599
+ */
2752
2600
  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
- * @returns {boolean}
2758
- */
2601
+ /**
2602
+ * Whether the container is attached to a document.
2603
+ *
2604
+ * If it's detached, the operations on the container will not be persisted.
2605
+ */
2759
2606
  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
- * @returns {LoroList | undefined}
2765
- */
2607
+ /**
2608
+ * Get the attached container associated with this.
2609
+ *
2610
+ * Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
2611
+ */
2766
2612
  getAttached(): LoroList | undefined;
2767
- /**
2768
- * Pop a value from the end of the list.
2769
- * @returns {Value | undefined}
2770
- */
2613
+ /**
2614
+ * Pop a value from the end of the list.
2615
+ */
2771
2616
  pop(): Value | undefined;
2772
- /**
2773
- * Delete all elements in the list.
2774
- */
2617
+ /**
2618
+ * Delete all elements in the list.
2619
+ */
2775
2620
  clear(): void;
2776
- /**
2777
- * @param {number} pos
2778
- * @returns {{ peer: PeerID, counter: number } | undefined}
2779
- */
2780
2621
  getIdAt(pos: number): { peer: PeerID, counter: number } | undefined;
2781
- /**
2782
- * Check if the container is deleted
2783
- * @returns {boolean}
2784
- */
2622
+ /**
2623
+ * Check if the container is deleted
2624
+ */
2785
2625
  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
- * @returns {Value[]}
2804
- */
2626
+ /**
2627
+ * Get the shallow value of the list.
2628
+ *
2629
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
2630
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
2631
+ *
2632
+ * ```js
2633
+ * const doc = new LoroDoc();
2634
+ * doc.setPeerId("1");
2635
+ * const list = doc.getList("list");
2636
+ * list.insert(0, 1);
2637
+ * list.insert(1, "two");
2638
+ * const subList = list.insertContainer(2, new LoroList());
2639
+ * subList.insert(0, "sub");
2640
+ * list.getShallowValue(); // [1, "two", "cid:2@1:List"]
2641
+ * list.toJSON(); // [1, "two", ["sub"]]
2642
+ * ```
2643
+ */
2805
2644
  getShallowValue(): Value[];
2806
- /**
2807
- * Get the id of this container.
2808
- */
2645
+ /**
2646
+ * Get the id of this container.
2647
+ */
2809
2648
  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
- */
2649
+ /**
2650
+ * Get the length of list.
2651
+ *
2652
+ * @example
2653
+ * ```ts
2654
+ * import { LoroDoc } from "loro-crdt";
2655
+ *
2656
+ * const doc = new LoroDoc();
2657
+ * const list = doc.getList("list");
2658
+ * list.insert(0, 100);
2659
+ * list.insert(1, "foo");
2660
+ * list.insert(2, true);
2661
+ * console.log(list.length); // 3
2662
+ * ```
2663
+ */
2825
2664
  readonly length: number;
2826
2665
  }
2827
2666
  /**
2828
- * The handler of a map container.
2829
- *
2830
- * Learn more at https://loro.dev/docs/tutorial/map
2831
- */
2667
+ * The handler of a map container.
2668
+ *
2669
+ * Learn more at https://loro.dev/docs/tutorial/map
2670
+ */
2832
2671
  export class LoroMap {
2833
2672
  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
- */
2673
+ /**
2674
+ * Create a new detached LoroMap (not attached to any LoroDoc).
2675
+ *
2676
+ * The edits on a detached container will not be persisted.
2677
+ * To attach the container to the document, please insert it into an attached container.
2678
+ */
2840
2679
  constructor();
2841
- /**
2842
- * "Map"
2843
- * @returns {'Map'}
2844
- */
2680
+ /**
2681
+ * "Map"
2682
+ */
2845
2683
  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
- * @param {string} key
2859
- */
2684
+ /**
2685
+ * Remove the key from the map.
2686
+ *
2687
+ * @example
2688
+ * ```ts
2689
+ * import { LoroDoc } from "loro-crdt";
2690
+ *
2691
+ * const doc = new LoroDoc();
2692
+ * const map = doc.getMap("map");
2693
+ * map.set("foo", "bar");
2694
+ * map.delete("foo");
2695
+ * ```
2696
+ */
2860
2697
  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
- * @returns {any[]}
2875
- */
2698
+ /**
2699
+ * Get the keys of the map.
2700
+ *
2701
+ * @example
2702
+ * ```ts
2703
+ * import { LoroDoc } from "loro-crdt";
2704
+ *
2705
+ * const doc = new LoroDoc();
2706
+ * const map = doc.getMap("map");
2707
+ * map.set("foo", "bar");
2708
+ * map.set("baz", "bar");
2709
+ * const keys = map.keys(); // ["foo", "baz"]
2710
+ * ```
2711
+ */
2876
2712
  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
- * @returns {any[]}
2892
- */
2713
+ /**
2714
+ * Get the values of the map. If the value is a child container, the corresponding
2715
+ * `Container` will be returned.
2716
+ *
2717
+ * @example
2718
+ * ```ts
2719
+ * import { LoroDoc } from "loro-crdt";
2720
+ *
2721
+ * const doc = new LoroDoc();
2722
+ * const map = doc.getMap("map");
2723
+ * map.set("foo", "bar");
2724
+ * map.set("baz", "bar");
2725
+ * const values = map.values(); // ["bar", "bar"]
2726
+ * ```
2727
+ */
2893
2728
  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
- * @returns {([string, Value | Container])[]}
2909
- */
2729
+ /**
2730
+ * Get the entries of the map. If the value is a child container, the corresponding
2731
+ * `Container` will be returned.
2732
+ *
2733
+ * @example
2734
+ * ```ts
2735
+ * import { LoroDoc } from "loro-crdt";
2736
+ *
2737
+ * const doc = new LoroDoc();
2738
+ * const map = doc.getMap("map");
2739
+ * map.set("foo", "bar");
2740
+ * map.set("baz", "bar");
2741
+ * const entries = map.entries(); // [["foo", "bar"], ["baz", "bar"]]
2742
+ * ```
2743
+ */
2910
2744
  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
- * @returns {any}
2927
- */
2745
+ /**
2746
+ * Get the keys and the values. If the type of value is a child container,
2747
+ * it will be resolved recursively.
2748
+ *
2749
+ * @example
2750
+ * ```ts
2751
+ * import { LoroDoc, LoroText } from "loro-crdt";
2752
+ *
2753
+ * const doc = new LoroDoc();
2754
+ * const map = doc.getMap("map");
2755
+ * map.set("foo", "bar");
2756
+ * const text = map.setContainer("text", new LoroText());
2757
+ * text.insert(0, "Hello");
2758
+ * console.log(map.toJSON()); // {"foo": "bar", "text": "Hello"}
2759
+ * ```
2760
+ */
2928
2761
  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
- * @returns {Container | undefined}
2936
- */
2762
+ /**
2763
+ * Get the parent container.
2764
+ *
2765
+ * - The parent container of the root tree is `undefined`.
2766
+ * - The object returned is a new js object each time because it need to cross
2767
+ * the WASM boundary.
2768
+ */
2937
2769
  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
- * @returns {boolean}
2943
- */
2770
+ /**
2771
+ * Whether the container is attached to a document.
2772
+ *
2773
+ * If it's detached, the operations on the container will not be persisted.
2774
+ */
2944
2775
  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
- * @returns {LoroMap | undefined}
2950
- */
2776
+ /**
2777
+ * Get the attached container associated with this.
2778
+ *
2779
+ * Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
2780
+ */
2951
2781
  getAttached(): LoroMap | undefined;
2952
- /**
2953
- * Delete all key-value pairs in the map.
2954
- */
2782
+ /**
2783
+ * Delete all key-value pairs in the map.
2784
+ */
2955
2785
  clear(): void;
2956
- /**
2957
- * Get the peer id of the last editor on the given entry
2958
- * @param {string} key
2959
- * @returns {PeerID | undefined}
2960
- */
2786
+ /**
2787
+ * Get the peer id of the last editor on the given entry
2788
+ */
2961
2789
  getLastEditor(key: string): PeerID | undefined;
2962
- /**
2963
- * Check if the container is deleted
2964
- * @returns {boolean}
2965
- */
2790
+ /**
2791
+ * Check if the container is deleted
2792
+ */
2966
2793
  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
- * @returns {Record<string, Value>}
2993
- */
2794
+ /**
2795
+ * Get the shallow value of the map.
2796
+ *
2797
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
2798
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
2799
+ *
2800
+ * @example
2801
+ * ```ts
2802
+ * import { LoroDoc, LoroText } from "loro-crdt";
2803
+ *
2804
+ * const doc = new LoroDoc();
2805
+ * doc.setPeerId("1");
2806
+ * const map = doc.getMap("map");
2807
+ * map.set("key", "value");
2808
+ * const subText = map.setContainer("text", new LoroText());
2809
+ * subText.insert(0, "Hello");
2810
+ *
2811
+ * // Get shallow value - nested containers are represented by their IDs
2812
+ * console.log(map.getShallowValue());
2813
+ * // Output: { key: "value", text: "cid:1@1:Text" }
2814
+ *
2815
+ * // Get full value with nested containers resolved by `toJSON()`
2816
+ * console.log(map.toJSON());
2817
+ * // Output: { key: "value", text: "Hello" }
2818
+ * ```
2819
+ */
2994
2820
  getShallowValue(): Record<string, Value>;
2995
- /**
2996
- * The container id of this handler.
2997
- */
2821
+ /**
2822
+ * The container id of this handler.
2823
+ */
2998
2824
  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
- */
2825
+ /**
2826
+ * Get the size of the map.
2827
+ *
2828
+ * @example
2829
+ * ```ts
2830
+ * import { LoroDoc } from "loro-crdt";
2831
+ *
2832
+ * const doc = new LoroDoc();
2833
+ * const map = doc.getMap("map");
2834
+ * map.set("foo", "bar");
2835
+ * console.log(map.size); // 1
2836
+ * ```
2837
+ */
3012
2838
  readonly size: number;
3013
2839
  }
3014
2840
  /**
3015
- * The handler of a list container.
3016
- *
3017
- * Learn more at https://loro.dev/docs/tutorial/list
3018
- */
2841
+ * The handler of a list container.
2842
+ *
2843
+ * Learn more at https://loro.dev/docs/tutorial/list
2844
+ */
3019
2845
  export class LoroMovableList {
3020
2846
  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
- */
2847
+ /**
2848
+ * Create a new detached LoroMovableList (not attached to any LoroDoc).
2849
+ *
2850
+ * The edits on a detached container will not be persisted.
2851
+ * To attach the container to the document, please insert it into an attached container.
2852
+ */
3027
2853
  constructor();
3028
- /**
3029
- * "MovableList"
3030
- * @returns {'MovableList'}
3031
- */
2854
+ /**
2855
+ * "MovableList"
2856
+ */
3032
2857
  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
- * @param {number} index
3047
- * @param {number} len
3048
- */
2858
+ /**
2859
+ * Delete elements from index to index + len.
2860
+ *
2861
+ * @example
2862
+ * ```ts
2863
+ * import { LoroDoc } from "loro-crdt";
2864
+ *
2865
+ * const doc = new LoroDoc();
2866
+ * const list = doc.getList("list");
2867
+ * list.insert(0, 100);
2868
+ * list.delete(0, 1);
2869
+ * console.log(list.value); // []
2870
+ * ```
2871
+ */
3049
2872
  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
- * @returns {any}
3066
- */
2873
+ /**
2874
+ * Get elements of the list. If the type of a element is a container, it will be
2875
+ * resolved recursively.
2876
+ *
2877
+ * @example
2878
+ * ```ts
2879
+ * import { LoroDoc, LoroText } from "loro-crdt";
2880
+ *
2881
+ * const doc = new LoroDoc();
2882
+ * const list = doc.getList("list");
2883
+ * list.insert(0, 100);
2884
+ * const text = list.insertContainer(1, new LoroText());
2885
+ * text.insert(0, "Hello");
2886
+ * console.log(list.toJSON()); // [100, "Hello"];
2887
+ * ```
2888
+ */
3067
2889
  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
- * @returns {Container | undefined}
3075
- */
2890
+ /**
2891
+ * Get the parent container.
2892
+ *
2893
+ * - The parent container of the root tree is `undefined`.
2894
+ * - The object returned is a new js object each time because it need to cross
2895
+ * the WASM boundary.
2896
+ */
3076
2897
  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
- * @returns {boolean}
3082
- */
2898
+ /**
2899
+ * Whether the container is attached to a document.
2900
+ *
2901
+ * If it's detached, the operations on the container will not be persisted.
2902
+ */
3083
2903
  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
- * @returns {LoroList | undefined}
3089
- */
2904
+ /**
2905
+ * Get the attached container associated with this.
2906
+ *
2907
+ * Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
2908
+ */
3090
2909
  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
- * @param {number} from
3103
- * @param {number} to
3104
- */
2910
+ /**
2911
+ * Move the element from `from` to `to`.
2912
+ *
2913
+ * The new position of the element will be `to`.
2914
+ * Move the element from `from` to `to`.
2915
+ *
2916
+ * The new position of the element will be `to`. This method is optimized to prevent redundant
2917
+ * operations that might occur with a naive remove and insert approach. Specifically, it avoids
2918
+ * creating surplus values in the list, unlike a delete followed by an insert, which can lead to
2919
+ * additional values in cases of concurrent edits. This ensures more efficient and accurate
2920
+ * operations in a MovableList.
2921
+ */
3105
2922
  move(from: number, to: number): void;
3106
- /**
3107
- * Pop a value from the end of the list.
3108
- * @returns {Value | undefined}
3109
- */
2923
+ /**
2924
+ * Pop a value from the end of the list.
2925
+ */
3110
2926
  pop(): Value | undefined;
3111
- /**
3112
- * Delete all elements in the list.
3113
- */
2927
+ /**
2928
+ * Delete all elements in the list.
2929
+ */
3114
2930
  clear(): void;
3115
- /**
3116
- * Get the creator of the list item at the given position.
3117
- * @param {number} pos
3118
- * @returns {PeerID | undefined}
3119
- */
2931
+ /**
2932
+ * Get the creator of the list item at the given position.
2933
+ */
3120
2934
  getCreatorAt(pos: number): PeerID | undefined;
3121
- /**
3122
- * Get the last mover of the list item at the given position.
3123
- * @param {number} pos
3124
- * @returns {PeerID | undefined}
3125
- */
2935
+ /**
2936
+ * Get the last mover of the list item at the given position.
2937
+ */
3126
2938
  getLastMoverAt(pos: number): PeerID | undefined;
3127
- /**
3128
- * Get the last editor of the list item at the given position.
3129
- * @param {number} pos
3130
- * @returns {PeerID | undefined}
3131
- */
2939
+ /**
2940
+ * Get the last editor of the list item at the given position.
2941
+ */
3132
2942
  getLastEditorAt(pos: number): PeerID | undefined;
3133
- /**
3134
- * Check if the container is deleted
3135
- * @returns {boolean}
3136
- */
2943
+ /**
2944
+ * Check if the container is deleted
2945
+ */
3137
2946
  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
- * @returns {Value[]}
3156
- */
2947
+ /**
2948
+ * Get the shallow value of the movable list.
2949
+ *
2950
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
2951
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
2952
+ *
2953
+ * ```js
2954
+ * const doc = new LoroDoc();
2955
+ * doc.setPeerId("1");
2956
+ * const list = doc.getMovableList("list");
2957
+ * list.insert(0, 1);
2958
+ * list.insert(1, "two");
2959
+ * const subList = list.insertContainer(2, new LoroList());
2960
+ * subList.insert(0, "sub");
2961
+ * list.getShallowValue(); // [1, "two", "cid:2@1:List"]
2962
+ * list.toJSON(); // [1, "two", ["sub"]]
2963
+ * ```
2964
+ */
3157
2965
  getShallowValue(): Value[];
3158
- /**
3159
- * Get the id of this container.
3160
- */
2966
+ /**
2967
+ * Get the id of this container.
2968
+ */
3161
2969
  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
- */
2970
+ /**
2971
+ * Get the length of list.
2972
+ *
2973
+ * @example
2974
+ * ```ts
2975
+ * import { LoroDoc } from "loro-crdt";
2976
+ *
2977
+ * const doc = new LoroDoc();
2978
+ * const list = doc.getList("list");
2979
+ * list.insert(0, 100);
2980
+ * list.insert(1, "foo");
2981
+ * list.insert(2, true);
2982
+ * console.log(list.length); // 3
2983
+ * ```
2984
+ */
3177
2985
  readonly length: number;
3178
2986
  }
3179
2987
  /**
3180
- * The handler of a text container. It supports rich text CRDT.
3181
- *
3182
- * Learn more at https://loro.dev/docs/tutorial/text
3183
- */
2988
+ * The handler of a text container. It supports rich text CRDT.
2989
+ *
2990
+ * Learn more at https://loro.dev/docs/tutorial/text
2991
+ */
3184
2992
  export class LoroText {
3185
2993
  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
- */
2994
+ /**
2995
+ * Create a new detached LoroText (not attached to any LoroDoc).
2996
+ *
2997
+ * The edits on a detached container will not be persisted.
2998
+ * To attach the container to the document, please insert it into an attached container.
2999
+ */
3192
3000
  constructor();
3193
- /**
3194
- * "Text"
3195
- * @returns {'Text'}
3196
- */
3001
+ /**
3002
+ * "Text"
3003
+ */
3197
3004
  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
- * @param {(string) => boolean} callback
3217
- */
3218
- 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
- * @param {number} index
3231
- * @param {string} content
3232
- */
3005
+ /**
3006
+ * Iterate each text span(internal storage unit)
3007
+ *
3008
+ * The callback function will be called for each span in the text.
3009
+ * If the callback returns `false`, the iteration will stop.
3010
+ *
3011
+ * Limitation: you cannot access or alter the doc state when iterating (this is for performance consideration).
3012
+ * If you need to access or alter the doc state, please use `toString` instead.
3013
+ *
3014
+ * @example
3015
+ * ```ts
3016
+ * import { LoroDoc } from "loro-crdt";
3017
+ *
3018
+ * const doc = new LoroDoc();
3019
+ * const text = doc.getText("text");
3020
+ * text.insert(0, "Hello");
3021
+ * text.iter((str) => (console.log(str), true));
3022
+ * ```
3023
+ */
3024
+ iter(callback: (string) => boolean): void;
3025
+ /**
3026
+ * Insert the string at the given index (utf-16 index).
3027
+ *
3028
+ * @example
3029
+ * ```ts
3030
+ * import { LoroDoc } from "loro-crdt";
3031
+ *
3032
+ * const doc = new LoroDoc();
3033
+ * const text = doc.getText("text");
3034
+ * text.insert(0, "Hello");
3035
+ * ```
3036
+ */
3233
3037
  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
- * @param {number} start_index
3247
- * @param {number} end_index
3248
- * @returns {string}
3249
- */
3038
+ /**
3039
+ * Get a string slice (utf-16 index).
3040
+ *
3041
+ * @example
3042
+ * ```ts
3043
+ * import { LoroDoc } from "loro-crdt";
3044
+ *
3045
+ * const doc = new LoroDoc();
3046
+ * const text = doc.getText("text");
3047
+ * text.insert(0, "Hello");
3048
+ * text.slice(0, 2); // "He"
3049
+ * ```
3050
+ */
3250
3051
  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
- * @param {number} pos
3264
- * @returns {string}
3265
- */
3052
+ /**
3053
+ * Get the character at the given position (utf-16 index).
3054
+ *
3055
+ * @example
3056
+ * ```ts
3057
+ * import { LoroDoc } from "loro-crdt";
3058
+ *
3059
+ * const doc = new LoroDoc();
3060
+ * const text = doc.getText("text");
3061
+ * text.insert(0, "Hello");
3062
+ * text.charAt(0); // "H"
3063
+ * ```
3064
+ */
3266
3065
  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
- * @param {number} pos
3280
- * @param {number} len
3281
- * @param {string} s
3282
- * @returns {string}
3283
- */
3066
+ /**
3067
+ * Delete and return the string at the given range and insert a string at the same position (utf-16 index).
3068
+ *
3069
+ * @example
3070
+ * ```ts
3071
+ * import { LoroDoc } from "loro-crdt";
3072
+ *
3073
+ * const doc = new LoroDoc();
3074
+ * const text = doc.getText("text");
3075
+ * text.insert(0, "Hello");
3076
+ * text.splice(2, 3, "llo"); // "llo"
3077
+ * ```
3078
+ */
3284
3079
  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
- * @param {number} index
3297
- * @param {string} content
3298
- */
3080
+ /**
3081
+ * Insert some string at utf-8 index.
3082
+ *
3083
+ * @example
3084
+ * ```ts
3085
+ * import { LoroDoc } from "loro-crdt";
3086
+ *
3087
+ * const doc = new LoroDoc();
3088
+ * const text = doc.getText("text");
3089
+ * text.insertUtf8(0, "Hello");
3090
+ * ```
3091
+ */
3299
3092
  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
- * @param {number} index
3315
- * @param {number} len
3316
- */
3093
+ /**
3094
+ * Delete elements from index to index + len (utf-16 index).
3095
+ *
3096
+ * @example
3097
+ * ```ts
3098
+ * import { LoroDoc } from "loro-crdt";
3099
+ *
3100
+ * const doc = new LoroDoc();
3101
+ * const text = doc.getText("text");
3102
+ * text.insert(0, "Hello");
3103
+ * text.delete(1, 3);
3104
+ * const s = text.toString();
3105
+ * console.log(s); // "Ho"
3106
+ * ```
3107
+ */
3317
3108
  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
- * @param {number} index
3333
- * @param {number} len
3334
- */
3109
+ /**
3110
+ * Delete elements from index to utf-8 index + len
3111
+ *
3112
+ * @example
3113
+ * ```ts
3114
+ * import { LoroDoc } from "loro-crdt";
3115
+ *
3116
+ * const doc = new LoroDoc();
3117
+ * const text = doc.getText("text");
3118
+ * text.insertUtf8(0, "Hello");
3119
+ * text.deleteUtf8(1, 3);
3120
+ * const s = text.toString();
3121
+ * console.log(s); // "Ho"
3122
+ * ```
3123
+ */
3335
3124
  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
- * @param {{ start: number, end: number }} range
3354
- * @param {string} key
3355
- * @param {any} value
3356
- */
3125
+ /**
3126
+ * Mark a range of text with a key and a value (utf-16 index).
3127
+ *
3128
+ * > You should call `configTextStyle` before using `mark` and `unmark`.
3129
+ *
3130
+ * You can use it to create a highlight, make a range of text bold, or add a link to a range of text.
3131
+ *
3132
+ * @example
3133
+ * ```ts
3134
+ * import { LoroDoc } from "loro-crdt";
3135
+ *
3136
+ * const doc = new LoroDoc();
3137
+ * doc.configTextStyle({bold: {expand: "after"}});
3138
+ * const text = doc.getText("text");
3139
+ * text.insert(0, "Hello World!");
3140
+ * text.mark({ start: 0, end: 5 }, "bold", true);
3141
+ * ```
3142
+ */
3357
3143
  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
- * @param {{ start: number, end: number }} range
3377
- * @param {string} key
3378
- */
3144
+ /**
3145
+ * Unmark a range of text with a key and a value (utf-16 index).
3146
+ *
3147
+ * > You should call `configTextStyle` before using `mark` and `unmark`.
3148
+ *
3149
+ * You can use it to remove highlights, bolds or links
3150
+ *
3151
+ * @example
3152
+ * ```ts
3153
+ * import { LoroDoc } from "loro-crdt";
3154
+ *
3155
+ * const doc = new LoroDoc();
3156
+ * doc.configTextStyle({bold: {expand: "after"}});
3157
+ * const text = doc.getText("text");
3158
+ * text.insert(0, "Hello World!");
3159
+ * text.mark({ start: 0, end: 5 }, "bold", true);
3160
+ * text.unmark({ start: 0, end: 5 }, "bold");
3161
+ * ```
3162
+ */
3379
3163
  unmark(range: { start: number, end: number }, key: string): void;
3380
- /**
3381
- * Convert the text to a string
3382
- * @returns {string}
3383
- */
3164
+ /**
3165
+ * Convert the text to a string
3166
+ */
3384
3167
  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
- * @returns {Delta<string>[]}
3402
- */
3168
+ /**
3169
+ * Get the text in [Delta](https://quilljs.com/docs/delta/) format.
3170
+ *
3171
+ * The returned value will include the rich text information.
3172
+ *
3173
+ * @example
3174
+ * ```ts
3175
+ * import { LoroDoc } from "loro-crdt";
3176
+ *
3177
+ * const doc = new LoroDoc();
3178
+ * const text = doc.getText("text");
3179
+ * doc.configTextStyle({bold: {expand: "after"}});
3180
+ * text.insert(0, "Hello World!");
3181
+ * text.mark({ start: 0, end: 5 }, "bold", true);
3182
+ * console.log(text.toDelta()); // [ { insert: 'Hello', attributes: { bold: true } } ]
3183
+ * ```
3184
+ */
3403
3185
  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
- * @param {Delta<string>[]} delta
3430
- */
3186
+ /**
3187
+ * Change the state of this text by delta.
3188
+ *
3189
+ * If a delta item is `insert`, it should include all the attributes of the inserted text.
3190
+ * Loro's rich text CRDT may make the inserted text inherit some styles when you use
3191
+ * `insert` method directly. However, when you use `applyDelta` if some attributes are
3192
+ * inherited from CRDT but not included in the delta, they will be removed.
3193
+ *
3194
+ * Another special property of `applyDelta` is if you format an attribute for ranges out of
3195
+ * the text length, Loro will insert new lines to fill the gap first. It's useful when you
3196
+ * build the binding between Loro and rich text editors like Quill, which might assume there
3197
+ * is always a newline at the end of the text implicitly.
3198
+ *
3199
+ * @example
3200
+ * ```ts
3201
+ * const doc = new LoroDoc();
3202
+ * const text = doc.getText("text");
3203
+ * doc.configTextStyle({bold: {expand: "after"}});
3204
+ * text.insert(0, "Hello World!");
3205
+ * text.mark({ start: 0, end: 5 }, "bold", true);
3206
+ * const delta = text.toDelta();
3207
+ * const text2 = doc.getText("text2");
3208
+ * text2.applyDelta(delta);
3209
+ * expect(text2.toDelta()).toStrictEqual(delta);
3210
+ * ```
3211
+ */
3431
3212
  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
- * @returns {Container | undefined}
3439
- */
3213
+ /**
3214
+ * Get the parent container.
3215
+ *
3216
+ * - The parent of the root is `undefined`.
3217
+ * - The object returned is a new js object each time because it need to cross
3218
+ * the WASM boundary.
3219
+ */
3440
3220
  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
- * @returns {boolean}
3446
- */
3221
+ /**
3222
+ * Whether the container is attached to a LoroDoc.
3223
+ *
3224
+ * If it's detached, the operations on the container will not be persisted.
3225
+ */
3447
3226
  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
- * @returns {LoroText | undefined}
3453
- */
3227
+ /**
3228
+ * Get the attached container associated with this.
3229
+ *
3230
+ * Returns an attached `Container` that is equal to this or created by this; otherwise, it returns `undefined`.
3231
+ */
3454
3232
  getAttached(): LoroText | undefined;
3455
- /**
3456
- * Push a string to the end of the text.
3457
- * @param {string} s
3458
- */
3233
+ /**
3234
+ * Push a string to the end of the text.
3235
+ */
3459
3236
  push(s: string): void;
3460
- /**
3461
- * Get the editor of the text at the given position.
3462
- * @param {number} pos
3463
- * @returns {PeerID | undefined}
3464
- */
3237
+ /**
3238
+ * Get the editor of the text at the given position.
3239
+ */
3465
3240
  getEditorOf(pos: number): PeerID | undefined;
3466
- /**
3467
- * Check if the container is deleted
3468
- * @returns {boolean}
3469
- */
3241
+ /**
3242
+ * Check if the container is deleted
3243
+ */
3470
3244
  isDeleted(): boolean;
3471
- /**
3472
- * Get the shallow value of the text. This equals to `text.toString()`.
3473
- * @returns {string}
3474
- */
3245
+ /**
3246
+ * Get the shallow value of the text. This equals to `text.toString()`.
3247
+ */
3475
3248
  getShallowValue(): string;
3476
- /**
3477
- * Get the JSON representation of the text.
3478
- * @returns {any}
3479
- */
3249
+ /**
3250
+ * Get the JSON representation of the text.
3251
+ */
3480
3252
  toJSON(): any;
3481
- /**
3482
- * Get the container id of the text.
3483
- */
3253
+ /**
3254
+ * Get the container id of the text.
3255
+ */
3484
3256
  readonly id: ContainerID;
3485
- /**
3486
- * Get the length of text (utf-16 length).
3487
- */
3257
+ /**
3258
+ * Get the length of text (utf-16 length).
3259
+ */
3488
3260
  readonly length: number;
3489
3261
  }
3490
3262
  /**
3491
- * The handler of a tree(forest) container.
3492
- *
3493
- * Learn more at https://loro.dev/docs/tutorial/tree
3494
- */
3263
+ * The handler of a tree(forest) container.
3264
+ *
3265
+ * Learn more at https://loro.dev/docs/tutorial/tree
3266
+ */
3495
3267
  export class LoroTree {
3496
3268
  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
- */
3269
+ /**
3270
+ * Create a new detached LoroTree (not attached to any LoroDoc).
3271
+ *
3272
+ * The edits on a detached container will not be persisted.
3273
+ * To attach the container to the document, please insert it into an attached container.
3274
+ */
3503
3275
  constructor();
3504
- /**
3505
- * "Tree"
3506
- * @returns {'Tree'}
3507
- */
3276
+ /**
3277
+ * "Tree"
3278
+ */
3508
3279
  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
- * @param {TreeID} target
3528
- * @param {TreeID | undefined} parent
3529
- * @param {number | undefined} [index]
3530
- */
3531
- move(target: TreeID, parent: TreeID | undefined, index?: number): void;
3532
- /**
3533
- * Delete a tree node from the forest.
3534
- *
3535
- * @example
3536
- * ```ts
3537
- * import { LoroDoc } from "loro-crdt";
3538
- *
3539
- * const doc = new LoroDoc();
3540
- * const tree = doc.getTree("tree");
3541
- * const root = tree.createNode();
3542
- * const node = root.createNode();
3543
- * tree.delete(node.id);
3544
- * ```
3545
- * @param {TreeID} target
3546
- */
3280
+ /**
3281
+ * Move the target tree node to be a child of the parent.
3282
+ * It's not allowed that the target is an ancestor of the parent
3283
+ * or the target and the parent are the same node.
3284
+ *
3285
+ * @example
3286
+ * ```ts
3287
+ * import { LoroDoc } from "loro-crdt";
3288
+ *
3289
+ * const doc = new LoroDoc();
3290
+ * const tree = doc.getTree("tree");
3291
+ * const root = tree.createNode();
3292
+ * const node = root.createNode();
3293
+ * const node2 = node.createNode();
3294
+ * tree.move(node2.id, root.id);
3295
+ * // Error will be thrown if move operation creates a cycle
3296
+ * // tree.move(root.id, node.id);
3297
+ * ```
3298
+ */
3299
+ move(target: TreeID, parent: TreeID | undefined, index?: number | null): void;
3300
+ /**
3301
+ * Delete a tree node from 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
+ * const node = root.createNode();
3311
+ * tree.delete(node.id);
3312
+ * ```
3313
+ */
3547
3314
  delete(target: TreeID): void;
3548
- /**
3549
- * Return `true` if the tree contains the TreeID, include deleted node.
3550
- * @param {TreeID} target
3551
- * @returns {boolean}
3552
- */
3315
+ /**
3316
+ * Return `true` if the tree contains the TreeID, include deleted node.
3317
+ */
3553
3318
  has(target: TreeID): boolean;
3554
- /**
3555
- * Return `None` if the node is not exist, otherwise return `Some(true)` if the node is deleted.
3556
- * @param {TreeID} target
3557
- * @returns {boolean}
3558
- */
3559
- 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
- * @returns {any}
3575
- */
3319
+ /**
3320
+ * Return `None` if the node is not exist, otherwise return `Some(true)` if the node is deleted.
3321
+ */
3322
+ isNodeDeleted(target: TreeID): boolean;
3323
+ /**
3324
+ * Get the hierarchy array with metadata of the forest.
3325
+ *
3326
+ * @example
3327
+ * ```ts
3328
+ * import { LoroDoc } from "loro-crdt";
3329
+ *
3330
+ * const doc = new LoroDoc();
3331
+ * const tree = doc.getTree("tree");
3332
+ * const root = tree.createNode();
3333
+ * root.data.set("color", "red");
3334
+ * // [ { id: '0@F2462C4159C4C8D1', parent: null, meta: { color: 'red' }, children: [] } ]
3335
+ * console.log(tree.toJSON());
3336
+ * ```
3337
+ */
3576
3338
  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
- * @returns {(LoroTreeNode)[]}
3592
- */
3593
- nodes(): (LoroTreeNode)[];
3594
- /**
3595
- * Get the root nodes of the forest.
3596
- * @returns {(LoroTreeNode)[]}
3597
- */
3598
- roots(): (LoroTreeNode)[];
3599
- /**
3600
- * Get the parent container of the tree container.
3601
- *
3602
- * - The parent container of the root tree is `undefined`.
3603
- * - The object returned is a new js object each time because it need to cross
3604
- * the WASM boundary.
3605
- * @returns {Container | undefined}
3606
- */
3339
+ /**
3340
+ * Get all tree nodes of the forest, including deleted nodes.
3341
+ *
3342
+ * @example
3343
+ * ```ts
3344
+ * import { LoroDoc } from "loro-crdt";
3345
+ *
3346
+ * const doc = new LoroDoc();
3347
+ * const tree = doc.getTree("tree");
3348
+ * const root = tree.createNode();
3349
+ * const node = root.createNode();
3350
+ * const node2 = node.createNode();
3351
+ * console.log(tree.nodes());
3352
+ * ```
3353
+ */
3354
+ nodes(): LoroTreeNode[];
3355
+ /**
3356
+ * Get the root nodes of the forest.
3357
+ */
3358
+ roots(): LoroTreeNode[];
3359
+ /**
3360
+ * Get the parent container of the tree container.
3361
+ *
3362
+ * - The parent container of the root tree is `undefined`.
3363
+ * - The object returned is a new js object each time because it need to cross
3364
+ * the WASM boundary.
3365
+ */
3607
3366
  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
- * @returns {boolean}
3613
- */
3367
+ /**
3368
+ * Whether the container is attached to a document.
3369
+ *
3370
+ * If it's detached, the operations on the container will not be persisted.
3371
+ */
3614
3372
  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
- * @returns {LoroTree | undefined}
3620
- */
3373
+ /**
3374
+ * Get the attached container associated with this.
3375
+ *
3376
+ * Returns an attached `Container` that equals to this or created by this, otherwise `undefined`.
3377
+ */
3621
3378
  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
- * @param {number} jitter
3633
- */
3379
+ /**
3380
+ * Set whether to generate a fractional index for moving and creating.
3381
+ *
3382
+ * A fractional index can be used to determine the position of tree nodes among their siblings.
3383
+ *
3384
+ * The jitter is used to avoid conflicts when multiple users are creating a node at the same position.
3385
+ * A value of 0 is the default, which means no jitter; any value larger than 0 will enable jitter.
3386
+ *
3387
+ * Generally speaking, higher jitter value will increase the size of the operation
3388
+ * [Read more about it](https://www.loro.dev/blog/movable-tree#implementation-and-encoding-size)
3389
+ */
3634
3390
  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
- */
3391
+ /**
3392
+ * Disable the fractional index generation when you don't need the Tree's siblings to be sorted.
3393
+ * The fractional index will always be set to the same default value 0.
3394
+ *
3395
+ * After calling this, you cannot use `tree.moveTo()`, `tree.moveBefore()`, `tree.moveAfter()`,
3396
+ * and `tree.createAt()`.
3397
+ */
3642
3398
  disableFractionalIndex(): void;
3643
- /**
3644
- * Whether the tree enables the fractional index generation.
3645
- * @returns {boolean}
3646
- */
3399
+ /**
3400
+ * Whether the tree enables the fractional index generation.
3401
+ */
3647
3402
  isFractionalIndexEnabled(): boolean;
3648
- /**
3649
- * Check if the container is deleted
3650
- * @returns {boolean}
3651
- */
3403
+ /**
3404
+ * Check if the container is deleted
3405
+ */
3652
3406
  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
- * @returns {TreeNodeShallowValue[]}
3693
- */
3407
+ /**
3408
+ * Get the shallow value of the tree.
3409
+ *
3410
+ * Unlike `toJSON()` which recursively resolves nested containers to their values,
3411
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
3412
+ *
3413
+ * @example
3414
+ * ```ts
3415
+ * const doc = new LoroDoc();
3416
+ * doc.setPeerId("1");
3417
+ * const tree = doc.getTree("tree");
3418
+ * const root = tree.createNode();
3419
+ * root.data.set("name", "root");
3420
+ * const text = root.data.setContainer("content", new LoroText());
3421
+ * text.insert(0, "Hello");
3422
+ *
3423
+ * console.log(tree.getShallowValue());
3424
+ * // [{
3425
+ * // id: "0@1",
3426
+ * // parent: null,
3427
+ * // index: 0,
3428
+ * // fractional_index: "80",
3429
+ * // meta: "cid:0@1:Map",
3430
+ * // children: []
3431
+ * // }]
3432
+ *
3433
+ * console.log(tree.toJSON());
3434
+ * // [{
3435
+ * // id: "0@1",
3436
+ * // parent: null,
3437
+ * // index: 0,
3438
+ * // fractional_index: "80",
3439
+ * // meta: {
3440
+ * // name: "root",
3441
+ * // content: "Hello"
3442
+ * // },
3443
+ * // children: []
3444
+ * // }]
3445
+ * ```
3446
+ */
3694
3447
  getShallowValue(): TreeNodeShallowValue[];
3695
- /**
3696
- * Get the id of the container.
3697
- */
3448
+ /**
3449
+ * Get the id of the container.
3450
+ */
3698
3451
  readonly id: ContainerID;
3699
3452
  }
3700
3453
  /**
3701
- * The handler of a tree node.
3702
- */
3454
+ * The handler of a tree node.
3455
+ */
3703
3456
  export class LoroTreeNode {
3457
+ private constructor();
3704
3458
  free(): void;
3705
- /**
3706
- * @returns {string}
3707
- */
3708
3459
  __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
- * @param {LoroTreeNode} target
3727
- */
3460
+ /**
3461
+ * Move the tree node to be after the target node.
3462
+ *
3463
+ * @example
3464
+ * ```ts
3465
+ * import { LoroDoc } from "loro-crdt";
3466
+ *
3467
+ * const doc = new LoroDoc();
3468
+ * const tree = doc.getTree("tree");
3469
+ * const root = tree.createNode();
3470
+ * const node = root.createNode();
3471
+ * const node2 = root.createNode();
3472
+ * node2.moveAfter(node);
3473
+ * // root
3474
+ * // / \
3475
+ * // node node2
3476
+ * ```
3477
+ */
3728
3478
  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
- * @param {LoroTreeNode} target
3747
- */
3479
+ /**
3480
+ * Move the tree node to be before the target node.
3481
+ *
3482
+ * @example
3483
+ * ```ts
3484
+ * import { LoroDoc } from "loro-crdt";
3485
+ *
3486
+ * const doc = new LoroDoc();
3487
+ * const tree = doc.getTree("tree");
3488
+ * const root = tree.createNode();
3489
+ * const node = root.createNode();
3490
+ * const node2 = root.createNode();
3491
+ * node2.moveBefore(node);
3492
+ * // root
3493
+ * // / \
3494
+ * // node2 node
3495
+ * ```
3496
+ */
3748
3497
  moveBefore(target: LoroTreeNode): void;
3749
- /**
3750
- * Get the index of the node in the parent's children.
3751
- * @returns {number | undefined}
3752
- */
3498
+ /**
3499
+ * Get the index of the node in the parent's children.
3500
+ */
3753
3501
  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
- * @returns {string | undefined}
3759
- */
3502
+ /**
3503
+ * Get the `Fractional Index` of the node.
3504
+ *
3505
+ * Note: the tree container must be attached to the document.
3506
+ */
3760
3507
  fractionalIndex(): string | undefined;
3761
- /**
3762
- * Check if the node is deleted.
3763
- * @returns {boolean}
3764
- */
3508
+ /**
3509
+ * Check if the node is deleted.
3510
+ */
3765
3511
  isDeleted(): boolean;
3766
- /**
3767
- * Get the last mover of this node.
3768
- * @returns {{ peer: PeerID, counter: number } | undefined}
3769
- */
3512
+ /**
3513
+ * Get the last mover of this node.
3514
+ */
3770
3515
  getLastMoveId(): { peer: PeerID, counter: number } | undefined;
3771
- /**
3772
- * Get the creation id of this node.
3773
- * @returns {{ peer: PeerID, counter: number }}
3774
- */
3516
+ /**
3517
+ * Get the creation id of this node.
3518
+ */
3775
3519
  creationId(): { peer: PeerID, counter: number };
3776
- /**
3777
- * Get the creator of this node.
3778
- * @returns {PeerID}
3779
- */
3520
+ /**
3521
+ * Get the creator of this node.
3522
+ */
3780
3523
  creator(): PeerID;
3781
- /**
3782
- * The TreeID of the node.
3783
- */
3524
+ /**
3525
+ * The TreeID of the node.
3526
+ */
3784
3527
  readonly id: TreeID;
3785
3528
  }
3786
3529
  /**
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
- */
3530
+ * `UndoManager` is responsible for handling undo and redo operations.
3531
+ *
3532
+ * By default, the maxUndoSteps is set to 100, mergeInterval is set to 1000 ms.
3533
+ *
3534
+ * Each commit made by the current peer is recorded as an undo step in the `UndoManager`.
3535
+ * Undo steps can be merged if they occur within a specified merge interval.
3536
+ *
3537
+ * Note that undo operations are local and cannot revert changes made by other peers.
3538
+ * To undo changes made by other peers, consider using the time travel feature.
3539
+ *
3540
+ * Once the `peerId` is bound to the `UndoManager` in the document, it cannot be changed.
3541
+ * Otherwise, the `UndoManager` may not function correctly.
3542
+ */
3800
3543
  export class UndoManager {
3801
3544
  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
- * @param {LoroDoc} doc
3824
- * @param {UndoConfig} config
3825
- */
3545
+ /**
3546
+ * `UndoManager` is responsible for handling undo and redo operations.
3547
+ *
3548
+ * PeerID cannot be changed during the lifetime of the UndoManager.
3549
+ *
3550
+ * Note that undo operations are local and cannot revert changes made by other peers.
3551
+ * To undo changes made by other peers, consider using the time travel feature.
3552
+ *
3553
+ * Each commit made by the current peer is recorded as an undo step in the `UndoManager`.
3554
+ * Undo steps can be merged if they occur within a specified merge interval.
3555
+ *
3556
+ * ## Config
3557
+ *
3558
+ * - `mergeInterval`: Optional. The interval in milliseconds within which undo steps can be merged. Default is 1000 ms.
3559
+ * - `maxUndoSteps`: Optional. The maximum number of undo steps to retain. Default is 100.
3560
+ * - `excludeOriginPrefixes`: Optional. An array of string prefixes. Events with origins matching these prefixes will be excluded from undo steps.
3561
+ * - `onPush`: Optional. A callback function that is called when an undo/redo step is pushed.
3562
+ * The function can return a meta data value that will be attached to the given stack item.
3563
+ * - `onPop`: Optional. A callback function that is called when an undo/redo step is popped.
3564
+ * The function will have a meta data value that was attached to the given stack item when
3565
+ * `onPush` was called.
3566
+ */
3826
3567
  constructor(doc: LoroDoc, config: UndoConfig);
3827
- /**
3828
- * Undo the last operation.
3829
- * @returns {boolean}
3830
- */
3568
+ /**
3569
+ * Undo the last operation.
3570
+ */
3831
3571
  undo(): boolean;
3832
- /**
3833
- * Redo the last undone operation.
3834
- * @returns {boolean}
3835
- */
3572
+ /**
3573
+ * Redo the last undone operation.
3574
+ */
3836
3575
  redo(): boolean;
3837
- /**
3838
- * Can undo the last operation.
3839
- * @returns {boolean}
3840
- */
3576
+ /**
3577
+ * Can undo the last operation.
3578
+ */
3841
3579
  canUndo(): boolean;
3842
- /**
3843
- * Can redo the last operation.
3844
- * @returns {boolean}
3845
- */
3580
+ /**
3581
+ * Can redo the last operation.
3582
+ */
3846
3583
  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
- * @param {number} steps
3851
- */
3584
+ /**
3585
+ * The number of max undo steps.
3586
+ * If the number of undo steps exceeds this number, the oldest undo step will be removed.
3587
+ */
3852
3588
  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
- * @param {number} interval
3859
- */
3589
+ /**
3590
+ * Set the merge interval (in ms).
3591
+ *
3592
+ * If the interval is set to 0, the undo steps will not be merged.
3593
+ * Otherwise, the undo steps will be merged if the interval between the two steps is less than the given interval.
3594
+ */
3860
3595
  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
- * @param {string} prefix
3865
- */
3596
+ /**
3597
+ * If a local event's origin matches the given prefix, it will not be recorded in the
3598
+ * undo stack.
3599
+ */
3866
3600
  addExcludeOriginPrefix(prefix: string): void;
3867
- /**
3868
- */
3869
3601
  clear(): void;
3870
3602
  }
3871
3603
  /**
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
- */
3604
+ * [VersionVector](https://en.wikipedia.org/wiki/Version_vector)
3605
+ * is a map from [PeerID] to [Counter]. Its a right-open interval.
3606
+ *
3607
+ * i.e. a [VersionVector] of `{A: 1, B: 2}` means that A has 1 atomic op and B has 2 atomic ops,
3608
+ * thus ID of `{client: A, counter: 1}` is out of the range.
3609
+ */
3878
3610
  export class VersionVector {
3879
3611
  free(): void;
3880
- /**
3881
- * Create a new version vector.
3882
- * @param {Map<PeerID, number> | Uint8Array | VersionVector | undefined | null} value
3883
- */
3612
+ /**
3613
+ * Create a new version vector.
3614
+ */
3884
3615
  constructor(value: Map<PeerID, number> | Uint8Array | VersionVector | undefined | null);
3885
- /**
3886
- * Create a new version vector from a Map.
3887
- * @param {Map<PeerID, number>} version
3888
- * @returns {VersionVector}
3889
- */
3616
+ /**
3617
+ * Create a new version vector from a Map.
3618
+ */
3890
3619
  static parseJSON(version: Map<PeerID, number>): VersionVector;
3891
- /**
3892
- * Convert the version vector to a Map
3893
- * @returns {Map<PeerID, number>}
3894
- */
3620
+ /**
3621
+ * Convert the version vector to a Map
3622
+ */
3895
3623
  toJSON(): Map<PeerID, number>;
3896
- /**
3897
- * Encode the version vector into a Uint8Array.
3898
- * @returns {Uint8Array}
3899
- */
3624
+ /**
3625
+ * Encode the version vector into a Uint8Array.
3626
+ */
3900
3627
  encode(): Uint8Array;
3901
- /**
3902
- * Decode the version vector from a Uint8Array.
3903
- * @param {Uint8Array} bytes
3904
- * @returns {VersionVector}
3905
- */
3628
+ /**
3629
+ * Decode the version vector from a Uint8Array.
3630
+ */
3906
3631
  static decode(bytes: Uint8Array): VersionVector;
3907
- /**
3908
- * Get the counter of a peer.
3909
- * @param {number | bigint | `${number}`} peer_id
3910
- * @returns {number | undefined}
3911
- */
3632
+ /**
3633
+ * Get the counter of a peer.
3634
+ */
3912
3635
  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
- * @param {VersionVector} other
3918
- * @returns {number | undefined}
3919
- */
3636
+ /**
3637
+ * Compare the version vector with another version vector.
3638
+ *
3639
+ * If they are concurrent, return undefined.
3640
+ */
3920
3641
  compare(other: VersionVector): number | undefined;
3921
- /**
3922
- * set the exclusive ending point. target id will NOT be included by self
3923
- * @param {{ peer: PeerID, counter: number }} id
3924
- */
3642
+ /**
3643
+ * set the exclusive ending point. target id will NOT be included by self
3644
+ */
3925
3645
  setEnd(id: { peer: PeerID, counter: number }): void;
3926
- /**
3927
- * set the inclusive ending point. target id will be included
3928
- * @param {{ peer: PeerID, counter: number }} id
3929
- */
3646
+ /**
3647
+ * set the inclusive ending point. target id will be included
3648
+ */
3930
3649
  setLast(id: { peer: PeerID, counter: number }): void;
3931
- /**
3932
- * @param {PeerID} peer
3933
- */
3934
3650
  remove(peer: PeerID): void;
3935
- /**
3936
- * @returns {number}
3937
- */
3938
3651
  length(): number;
3939
3652
  }
3940
3653
 
@@ -3942,7 +3655,7 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
3942
3655
 
3943
3656
  export interface InitOutput {
3944
3657
  readonly memory: WebAssembly.Memory;
3945
- readonly __wbg_lorocounter_free: (a: number) => void;
3658
+ readonly __wbg_lorocounter_free: (a: number, b: number) => void;
3946
3659
  readonly lorocounter_new: () => number;
3947
3660
  readonly lorocounter_kind: (a: number) => number;
3948
3661
  readonly lorocounter_id: (a: number) => number;
@@ -3954,7 +3667,7 @@ export interface InitOutput {
3954
3667
  readonly lorocounter_isAttached: (a: number) => number;
3955
3668
  readonly lorocounter_getAttached: (a: number) => number;
3956
3669
  readonly lorocounter_getShallowValue: (a: number) => number;
3957
- readonly __wbg_awarenesswasm_free: (a: number) => void;
3670
+ readonly __wbg_awarenesswasm_free: (a: number, b: number) => void;
3958
3671
  readonly awarenesswasm_new: (a: number, b: number) => number;
3959
3672
  readonly awarenesswasm_encode: (a: number, b: number, c: number) => void;
3960
3673
  readonly awarenesswasm_encodeAll: (a: number, b: number) => void;
@@ -3968,7 +3681,7 @@ export interface InitOutput {
3968
3681
  readonly awarenesswasm_length: (a: number) => number;
3969
3682
  readonly awarenesswasm_isEmpty: (a: number) => number;
3970
3683
  readonly awarenesswasm_peers: (a: number, b: number) => void;
3971
- readonly __wbg_ephemeralstorewasm_free: (a: number) => void;
3684
+ readonly __wbg_ephemeralstorewasm_free: (a: number, b: number) => void;
3972
3685
  readonly ephemeralstorewasm_new: (a: number) => number;
3973
3686
  readonly ephemeralstorewasm_set: (a: number, b: number, c: number, d: number) => void;
3974
3687
  readonly ephemeralstorewasm_delete: (a: number, b: number, c: number) => void;
@@ -3987,7 +3700,7 @@ export interface InitOutput {
3987
3700
  readonly encodeFrontiers: (a: number, b: number, c: number) => void;
3988
3701
  readonly decodeFrontiers: (a: number, b: number, c: number) => void;
3989
3702
  readonly setDebug: () => void;
3990
- readonly __wbg_lorodoc_free: (a: number) => void;
3703
+ readonly __wbg_lorodoc_free: (a: number, b: number) => void;
3991
3704
  readonly lorodoc_new: () => number;
3992
3705
  readonly lorodoc_setDetachedEditing: (a: number, b: number) => void;
3993
3706
  readonly lorodoc_isDetachedEditingEnabled: (a: number) => number;
@@ -4005,7 +3718,7 @@ export interface InitOutput {
4005
3718
  readonly lorodoc_travelChangeAncestors: (a: number, b: number, c: number, d: number, e: number) => void;
4006
3719
  readonly lorodoc_findIdSpansBetween: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
4007
3720
  readonly lorodoc_checkout: (a: number, b: number, c: number, d: number) => void;
4008
- readonly lorodoc_peerId: (a: number) => number;
3721
+ readonly lorodoc_peerId: (a: number) => bigint;
4009
3722
  readonly lorodoc_peerIdStr: (a: number) => number;
4010
3723
  readonly lorodoc_setPeerId: (a: number, b: number, c: number) => void;
4011
3724
  readonly lorodoc_commit: (a: number, b: number, c: number) => void;
@@ -4065,7 +3778,9 @@ export interface InitOutput {
4065
3778
  readonly lorodoc_getUncommittedOpsAsJson: (a: number, b: number) => void;
4066
3779
  readonly lorodoc_subscribeFirstCommitFromPeer: (a: number, b: number) => number;
4067
3780
  readonly lorodoc_subscribePreCommit: (a: number, b: number) => number;
4068
- readonly __wbg_lorotext_free: (a: number) => void;
3781
+ readonly lorodoc_deleteRootContainer: (a: number, b: number, c: number) => void;
3782
+ readonly lorodoc_setHideEmptyRootContainers: (a: number, b: number, c: number) => void;
3783
+ readonly __wbg_lorotext_free: (a: number, b: number) => void;
4069
3784
  readonly lorotext_new: () => number;
4070
3785
  readonly lorotext_kind: (a: number) => number;
4071
3786
  readonly lorotext_iter: (a: number, b: number, c: number) => void;
@@ -4087,6 +3802,7 @@ export interface InitOutput {
4087
3802
  readonly lorotext_subscribe: (a: number, b: number, c: number) => void;
4088
3803
  readonly lorotext_applyDelta: (a: number, b: number, c: number) => void;
4089
3804
  readonly lorotext_parent: (a: number) => number;
3805
+ readonly lorotext_isAttached: (a: number) => number;
4090
3806
  readonly lorotext_getAttached: (a: number) => number;
4091
3807
  readonly lorotext_getCursor: (a: number, b: number, c: number) => number;
4092
3808
  readonly lorotext_push: (a: number, b: number, c: number, d: number) => void;
@@ -4094,7 +3810,7 @@ export interface InitOutput {
4094
3810
  readonly lorotext_isDeleted: (a: number) => number;
4095
3811
  readonly lorotext_getShallowValue: (a: number, b: number) => void;
4096
3812
  readonly lorotext_toJSON: (a: number) => number;
4097
- readonly __wbg_loromap_free: (a: number) => void;
3813
+ readonly __wbg_loromap_free: (a: number, b: number) => void;
4098
3814
  readonly loromap_new: () => number;
4099
3815
  readonly loromap_kind: (a: number) => number;
4100
3816
  readonly loromap_set: (a: number, b: number, c: number, d: number, e: number) => void;
@@ -4110,12 +3826,13 @@ export interface InitOutput {
4110
3826
  readonly loromap_subscribe: (a: number, b: number, c: number) => void;
4111
3827
  readonly loromap_size: (a: number) => number;
4112
3828
  readonly loromap_parent: (a: number) => number;
3829
+ readonly loromap_isAttached: (a: number) => number;
4113
3830
  readonly loromap_getAttached: (a: number) => number;
4114
3831
  readonly loromap_clear: (a: number, b: number) => void;
4115
3832
  readonly loromap_getLastEditor: (a: number, b: number, c: number) => number;
4116
3833
  readonly loromap_isDeleted: (a: number) => number;
4117
3834
  readonly loromap_getShallowValue: (a: number) => number;
4118
- readonly __wbg_lorolist_free: (a: number) => void;
3835
+ readonly __wbg_lorolist_free: (a: number, b: number) => void;
4119
3836
  readonly lorolist_new: () => number;
4120
3837
  readonly lorolist_kind: (a: number) => number;
4121
3838
  readonly lorolist_insert: (a: number, b: number, c: number, d: number) => void;
@@ -4150,6 +3867,8 @@ export interface InitOutput {
4150
3867
  readonly loromovablelist_pushContainer: (a: number, b: number, c: number) => void;
4151
3868
  readonly loromovablelist_subscribe: (a: number, b: number, c: number) => void;
4152
3869
  readonly loromovablelist_length: (a: number) => number;
3870
+ readonly loromovablelist_parent: (a: number) => number;
3871
+ readonly loromovablelist_isAttached: (a: number) => number;
4153
3872
  readonly loromovablelist_getAttached: (a: number) => number;
4154
3873
  readonly loromovablelist_getCursor: (a: number, b: number, c: number) => number;
4155
3874
  readonly loromovablelist_move: (a: number, b: number, c: number, d: number) => void;
@@ -4163,12 +3882,12 @@ export interface InitOutput {
4163
3882
  readonly loromovablelist_getLastEditorAt: (a: number, b: number) => number;
4164
3883
  readonly loromovablelist_isDeleted: (a: number) => number;
4165
3884
  readonly loromovablelist_getShallowValue: (a: number) => number;
4166
- readonly __wbg_lorotree_free: (a: number) => void;
3885
+ readonly __wbg_lorotree_free: (a: number, b: number) => void;
4167
3886
  readonly lorotreenode___getClassname: (a: number, b: number) => void;
4168
- readonly __wbg_lorotreenode_free: (a: number) => void;
3887
+ readonly __wbg_lorotreenode_free: (a: number, b: number) => void;
4169
3888
  readonly lorotreenode_id: (a: number) => number;
4170
- readonly lorotreenode_createNode: (a: number, b: number, c: number, d: number) => void;
4171
- readonly lorotreenode_move: (a: number, b: number, c: number, d: number, e: number) => void;
3889
+ readonly lorotreenode_createNode: (a: number, b: number, c: number) => void;
3890
+ readonly lorotreenode_move: (a: number, b: number, c: number, d: number) => void;
4172
3891
  readonly lorotreenode_moveAfter: (a: number, b: number, c: number) => void;
4173
3892
  readonly lorotreenode_moveBefore: (a: number, b: number, c: number) => void;
4174
3893
  readonly lorotreenode_index: (a: number, b: number) => void;
@@ -4183,8 +3902,8 @@ export interface InitOutput {
4183
3902
  readonly lorotreenode_creator: (a: number) => number;
4184
3903
  readonly lorotree_new: () => number;
4185
3904
  readonly lorotree_kind: (a: number) => number;
4186
- readonly lorotree_createNode: (a: number, b: number, c: number, d: number, e: number) => void;
4187
- readonly lorotree_move: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
3905
+ readonly lorotree_createNode: (a: number, b: number, c: number, d: number) => void;
3906
+ readonly lorotree_move: (a: number, b: number, c: number, d: number, e: number) => void;
4188
3907
  readonly lorotree_delete: (a: number, b: number, c: number) => void;
4189
3908
  readonly lorotree_getNodeByID: (a: number, b: number) => number;
4190
3909
  readonly lorotree_id: (a: number) => number;
@@ -4204,14 +3923,14 @@ export interface InitOutput {
4204
3923
  readonly lorotree_isFractionalIndexEnabled: (a: number) => number;
4205
3924
  readonly lorotree_isDeleted: (a: number) => number;
4206
3925
  readonly lorotree_getShallowValue: (a: number) => number;
4207
- readonly __wbg_cursor_free: (a: number) => void;
3926
+ readonly __wbg_cursor_free: (a: number, b: number) => void;
4208
3927
  readonly cursor_containerId: (a: number) => number;
4209
3928
  readonly cursor_pos: (a: number) => number;
4210
3929
  readonly cursor_side: (a: number) => number;
4211
3930
  readonly cursor_encode: (a: number, b: number) => void;
4212
3931
  readonly cursor_decode: (a: number, b: number, c: number) => void;
4213
3932
  readonly cursor_kind: (a: number) => number;
4214
- readonly __wbg_undomanager_free: (a: number) => void;
3933
+ readonly __wbg_undomanager_free: (a: number, b: number) => void;
4215
3934
  readonly undomanager_new: (a: number, b: number) => number;
4216
3935
  readonly undomanager_undo: (a: number, b: number) => void;
4217
3936
  readonly undomanager_redo: (a: number, b: number) => void;
@@ -4223,36 +3942,32 @@ export interface InitOutput {
4223
3942
  readonly undomanager_setOnPush: (a: number, b: number) => void;
4224
3943
  readonly undomanager_setOnPop: (a: number, b: number) => void;
4225
3944
  readonly undomanager_clear: (a: number) => void;
4226
- readonly __wbg_versionvector_free: (a: number) => void;
3945
+ readonly __wbg_versionvector_free: (a: number, b: number) => void;
4227
3946
  readonly versionvector_new: (a: number, b: number) => void;
4228
3947
  readonly versionvector_parseJSON: (a: number, b: number) => void;
4229
3948
  readonly versionvector_toJSON: (a: number) => number;
4230
3949
  readonly versionvector_encode: (a: number, b: number) => void;
4231
3950
  readonly versionvector_decode: (a: number, b: number, c: number) => void;
4232
3951
  readonly versionvector_get: (a: number, b: number, c: number) => void;
4233
- readonly versionvector_compare: (a: number, b: number, c: number) => void;
3952
+ readonly versionvector_compare: (a: number, b: number) => number;
4234
3953
  readonly versionvector_setEnd: (a: number, b: number, c: number) => void;
4235
3954
  readonly versionvector_setLast: (a: number, b: number, c: number) => void;
4236
3955
  readonly versionvector_remove: (a: number, b: number, c: number) => void;
4237
3956
  readonly versionvector_length: (a: number) => number;
4238
3957
  readonly decodeImportBlobMeta: (a: number, b: number, c: number, d: number) => void;
4239
- readonly __wbg_changemodifier_free: (a: number) => void;
3958
+ readonly __wbg_changemodifier_free: (a: number, b: number) => void;
4240
3959
  readonly changemodifier_setMessage: (a: number, b: number, c: number) => number;
4241
3960
  readonly changemodifier_setTimestamp: (a: number, b: number) => number;
4242
- readonly __wbg_loromovablelist_free: (a: number) => void;
4243
3961
  readonly lorodoc_importUpdateBatch: (a: number, b: number, c: number) => void;
4244
- readonly loromovablelist_parent: (a: number) => number;
4245
- readonly lorotext_isAttached: (a: number) => number;
4246
- readonly loromap_isAttached: (a: number) => number;
4247
- readonly loromovablelist_isAttached: (a: number) => number;
3962
+ readonly __wbg_loromovablelist_free: (a: number, b: number) => void;
4248
3963
  readonly __wbindgen_export_0: (a: number, b: number) => number;
4249
3964
  readonly __wbindgen_export_1: (a: number, b: number, c: number, d: number) => number;
4250
- readonly __wbindgen_export_2: WebAssembly.Table;
3965
+ readonly __wbindgen_export_2: (a: number) => void;
4251
3966
  readonly __wbindgen_export_3: (a: number, b: number, c: number) => void;
4252
- readonly __wbindgen_export_4: (a: number, b: number) => void;
3967
+ readonly __wbindgen_export_4: WebAssembly.Table;
4253
3968
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
4254
3969
  readonly __wbindgen_export_5: (a: number, b: number, c: number) => void;
4255
- readonly __wbindgen_export_6: (a: number) => void;
3970
+ readonly __wbindgen_export_6: (a: number, b: number) => void;
4256
3971
  readonly __wbindgen_start: () => void;
4257
3972
  }
4258
3973
 
@@ -4261,18 +3976,18 @@ export type SyncInitInput = BufferSource | WebAssembly.Module;
4261
3976
  * Instantiates the given `module`, which can either be bytes or
4262
3977
  * a precompiled `WebAssembly.Module`.
4263
3978
  *
4264
- * @param {SyncInitInput} module
3979
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
4265
3980
  *
4266
3981
  * @returns {InitOutput}
4267
3982
  */
4268
- export function initSync(module: SyncInitInput): InitOutput;
3983
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
4269
3984
 
4270
3985
  /**
4271
3986
  * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
4272
3987
  * for everything else, calls `WebAssembly.instantiate` directly.
4273
3988
  *
4274
- * @param {InitInput | Promise<InitInput>} module_or_path
3989
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
4275
3990
  *
4276
3991
  * @returns {Promise<InitOutput>}
4277
3992
  */
4278
- export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
3993
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;