loro-crdt 1.8.9 → 1.10.0

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