loro-crdt 1.16.3 → 1.16.4

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.
@@ -322,6 +322,29 @@ interface LoroDoc {
322
322
  diff(from: OpId[], to: OpId[], for_json?: boolean): [ContainerID, JsonDiff|Diff][];
323
323
  }
324
324
 
325
+ /**
326
+ * Options for `LoroDoc.applyDiff`.
327
+ */
328
+ export interface ApplyDiffOptions {
329
+ /**
330
+ * Read the batch as the result of `doc.diff()`: a mergeable child that the batch makes
331
+ * visible again carries its full content, which is aligned with whatever hidden state the
332
+ * target document keeps for it (none, the same, or different).
333
+ *
334
+ * Only use it for `doc.diff()` results (also after a JSON round trip), or for events from
335
+ * `import`/`checkout`, which report a revived child with its full content.
336
+ *
337
+ * Never use it for events from local commits. A local re-activation (such as
338
+ * `ensureMergeableCounter` over a deleted key) reports only the parent map change plus the
339
+ * commit's own ops, because the child's content did not change. With `fullState`, a
340
+ * missing child entry means "empty" and an entry means the whole content, so the hidden
341
+ * child would be cleared or overwritten (e.g. a counter at 7 becomes 0). Leave it unset
342
+ * (the default) for such events: their entries are increments, which is right when the
343
+ * target shares the source's hidden state.
344
+ */
345
+ fullState?: boolean;
346
+ }
347
+
325
348
  /**
326
349
  * Represents a `Delta` type which is a union of different operations that can be performed.
327
350
  *
@@ -1949,8 +1972,25 @@ export class LoroDoc {
1949
1972
  * doc2.applyDiff(diff);
1950
1973
  * console.log(doc2.getText("text").toString()); // "Hello"
1951
1974
  * ```
1975
+ *
1976
+ * Pass `{ fullState: true }` when applying the result of `doc.diff()` to a document that may
1977
+ * keep hidden state for a mergeable child the diff makes visible again (e.g. applying
1978
+ * `doc.diff(afterDelete, beforeDelete)` to `doc` itself or to a copy of it). The child's
1979
+ * entry is then read as its full content and aligned with that hidden state. Without it
1980
+ * (the default), entries are applied as increments, which is right for events forwarded to
1981
+ * a document that shares the source's hidden state. Never pass it for events from local
1982
+ * commits; see `ApplyDiffOptions.fullState`.
1983
+ *
1984
+ * ```ts
1985
+ * const text = doc.getMap("m").ensureMergeableText("t");
1986
+ * text.insert(0, "hello");
1987
+ * const before = doc.frontiers();
1988
+ * doc.getMap("m").delete("t");
1989
+ * doc.applyDiff(doc.diff(doc.frontiers(), before), { fullState: true });
1990
+ * console.log(doc.getMap("m").get("t").toString()); // "hello"
1991
+ * ```
1952
1992
  */
1953
- applyDiff(diff: [ContainerID, Diff|JsonDiff][]): void;
1993
+ applyDiff(diff: [ContainerID, Diff|JsonDiff][], options?: ApplyDiffOptions | null): void;
1954
1994
  /**
1955
1995
  * Check if the doc contains the full history.
1956
1996
  */
@@ -3979,10 +4019,19 @@ export class UndoManager {
3979
4019
  peer(): PeerID;
3980
4020
  /**
3981
4021
  * Redo the last undone operation.
4022
+ *
4023
+ * Throws like `undo` on steps that would recreate a container of an
4024
+ * unknown type.
3982
4025
  */
3983
4026
  redo(): boolean;
3984
4027
  /**
3985
4028
  * Undo the last operation.
4029
+ *
4030
+ * Throws without changing the doc if the step would have to recreate a
4031
+ * container of a type unknown to this version (created by a newer
4032
+ * loro-crdt). That step, with every edit merged into it, is dropped and its
4033
+ * edits stay; the next call undoes the step before it, rebased over the
4034
+ * dropped step's edits like over a remote peer's.
3986
4035
  */
3987
4036
  undo(): boolean;
3988
4037
  clear(): void;
@@ -1,4 +1,4 @@
1
- import { stateBinary, stateCid, stateContainer, stateIndex, stateOptions, stateRootCid, stateSet, stateSlice, stateValue } from './snippets/loro-wasm-c600d14705866f8f/inline0.js';
1
+ import { stateBinary, stateCid, stateContainer, stateIndex, stateOptions, stateRootCid, stateSet, stateSlice, stateValue } from './snippets/loro-wasm-704a44faa43c032c/inline0.js';
2
2
 
3
3
  let wasm;
4
4
  export function __wbg_set_wasm(val) {
@@ -1360,12 +1360,30 @@ export class LoroDoc {
1360
1360
  * doc2.applyDiff(diff);
1361
1361
  * console.log(doc2.getText("text").toString()); // "Hello"
1362
1362
  * ```
1363
+ *
1364
+ * Pass `{ fullState: true }` when applying the result of `doc.diff()` to a document that may
1365
+ * keep hidden state for a mergeable child the diff makes visible again (e.g. applying
1366
+ * `doc.diff(afterDelete, beforeDelete)` to `doc` itself or to a copy of it). The child's
1367
+ * entry is then read as its full content and aligned with that hidden state. Without it
1368
+ * (the default), entries are applied as increments, which is right for events forwarded to
1369
+ * a document that shares the source's hidden state. Never pass it for events from local
1370
+ * commits; see `ApplyDiffOptions.fullState`.
1371
+ *
1372
+ * ```ts
1373
+ * const text = doc.getMap("m").ensureMergeableText("t");
1374
+ * text.insert(0, "hello");
1375
+ * const before = doc.frontiers();
1376
+ * doc.getMap("m").delete("t");
1377
+ * doc.applyDiff(doc.diff(doc.frontiers(), before), { fullState: true });
1378
+ * console.log(doc.getMap("m").get("t").toString()); // "hello"
1379
+ * ```
1363
1380
  * @param {[ContainerID, Diff|JsonDiff][]} diff
1381
+ * @param {ApplyDiffOptions | null} [options]
1364
1382
  */
1365
- applyDiff(diff) {
1383
+ applyDiff(diff, options) {
1366
1384
  try {
1367
1385
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1368
- wasm.lorodoc_applyDiff(retptr, this.__wbg_ptr, addHeapObject(diff));
1386
+ wasm.lorodoc_applyDiff(retptr, this.__wbg_ptr, addHeapObject(diff), isLikeNone(options) ? 0 : addHeapObject(options));
1369
1387
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1370
1388
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1371
1389
  if (r1) {
@@ -7421,6 +7439,9 @@ export class UndoManager {
7421
7439
  }
7422
7440
  /**
7423
7441
  * Redo the last undone operation.
7442
+ *
7443
+ * Throws like `undo` on steps that would recreate a container of an
7444
+ * unknown type.
7424
7445
  * @returns {boolean}
7425
7446
  */
7426
7447
  redo() {
@@ -7440,6 +7461,12 @@ export class UndoManager {
7440
7461
  }
7441
7462
  /**
7442
7463
  * Undo the last operation.
7464
+ *
7465
+ * Throws without changing the doc if the step would have to recreate a
7466
+ * container of a type unknown to this version (created by a newer
7467
+ * loro-crdt). That step, with every edit merged into it, is dropped and its
7468
+ * edits stay; the next call undoes the step before it, rebased over the
7469
+ * dropped step's edits like over a remote peer's.
7443
7470
  * @returns {boolean}
7444
7471
  */
7445
7472
  undo() {
@@ -7828,7 +7855,7 @@ export function __wbg_entries_c8a90a7ed73e84ce(arg0) {
7828
7855
  return addHeapObject(ret);
7829
7856
  };
7830
7857
 
7831
- export function __wbg_error_10d6926de361eb2b(arg0, arg1) {
7858
+ export function __wbg_error_1d6f2b3f2c5a33ec(arg0, arg1) {
7832
7859
  console.error(getStringFromWasm0(arg0, arg1));
7833
7860
  };
7834
7861
 
@@ -7959,7 +7986,7 @@ export function __wbg_log_cb9e190acc5753fb(arg0, arg1) {
7959
7986
  }
7960
7987
  };
7961
7988
 
7962
- export function __wbg_log_d5951556f2f10ec9(arg0, arg1) {
7989
+ export function __wbg_log_f665cabe523a97df(arg0, arg1) {
7963
7990
  console.log(getStringFromWasm0(arg0, arg1));
7964
7991
  };
7965
7992
 
@@ -8144,45 +8171,45 @@ export function __wbg_setindex_dcd71eabf405bde1(arg0, arg1, arg2) {
8144
8171
  getObject(arg0)[arg1 >>> 0] = arg2;
8145
8172
  };
8146
8173
 
8147
- export function __wbg_stateBinary_64e9eb9b37720ab6(arg0, arg1) {
8174
+ export function __wbg_stateBinary_9e1da8a4daa74bc6(arg0, arg1) {
8148
8175
  const ret = stateBinary(getArrayU8FromWasm0(arg0, arg1));
8149
8176
  return addHeapObject(ret);
8150
8177
  };
8151
8178
 
8152
- export function __wbg_stateCid_760e963fd4c95f01(arg0, arg1, arg2) {
8179
+ export function __wbg_stateCid_c43ea762fb462319(arg0, arg1, arg2) {
8153
8180
  const ret = stateCid(getObject(arg0), arg1, arg2);
8154
8181
  return addHeapObject(ret);
8155
8182
  };
8156
8183
 
8157
- export function __wbg_stateContainer_71de82dd2efd60eb(arg0, arg1, arg2) {
8184
+ export function __wbg_stateContainer_cd983f42c6fe987d(arg0, arg1, arg2) {
8158
8185
  const ret = stateContainer(arg0, getObject(arg1), takeObject(arg2));
8159
8186
  return addHeapObject(ret);
8160
8187
  };
8161
8188
 
8162
- export function __wbg_stateIndex_acd88b869f874497() { return handleError(function (arg0, arg1, arg2) {
8189
+ export function __wbg_stateIndex_1fbac6394e58cff9() { return handleError(function (arg0, arg1, arg2) {
8163
8190
  stateIndex(getObject(arg0), arg1 >>> 0, getObject(arg2));
8164
8191
  }, arguments) };
8165
8192
 
8166
- export function __wbg_stateOptions_8486fef4478d16b3() { return handleError(function (arg0, arg1) {
8193
+ export function __wbg_stateOptions_dcb483514d1b925d() { return handleError(function (arg0, arg1) {
8167
8194
  const ret = stateOptions(takeObject(arg0), arg1 !== 0);
8168
8195
  return addHeapObject(ret);
8169
8196
  }, arguments) };
8170
8197
 
8171
- export function __wbg_stateRootCid_964d9fbc9bfbcea3(arg0, arg1, arg2) {
8198
+ export function __wbg_stateRootCid_9198769cdd9f37d5(arg0, arg1, arg2) {
8172
8199
  const ret = stateRootCid(getStringFromWasm0(arg0, arg1), arg2);
8173
8200
  return addHeapObject(ret);
8174
8201
  };
8175
8202
 
8176
- export function __wbg_stateSet_6cd1dd82536a3182() { return handleError(function (arg0, arg1, arg2) {
8203
+ export function __wbg_stateSet_a3e74b27d3d26f9d() { return handleError(function (arg0, arg1, arg2) {
8177
8204
  stateSet(getObject(arg0), getObject(arg1), getObject(arg2));
8178
8205
  }, arguments) };
8179
8206
 
8180
- export function __wbg_stateSlice_8d4107ebb0dfc484(arg0, arg1, arg2) {
8207
+ export function __wbg_stateSlice_aafffe8ecba122b8(arg0, arg1, arg2) {
8181
8208
  const ret = stateSlice(takeObject(arg0), arg1 >>> 0, arg2 >>> 0);
8182
8209
  return addHeapObject(ret);
8183
8210
  };
8184
8211
 
8185
- export function __wbg_stateValue_0727099e81830513(arg0) {
8212
+ export function __wbg_stateValue_8ed644fcdb61558c(arg0) {
8186
8213
  const ret = stateValue(takeObject(arg0));
8187
8214
  return addHeapObject(ret);
8188
8215
  };
@@ -8232,7 +8259,7 @@ export function __wbg_versionvector_new(arg0) {
8232
8259
  return addHeapObject(ret);
8233
8260
  };
8234
8261
 
8235
- export function __wbg_warn_576423aac512a858(arg0, arg1) {
8262
+ export function __wbg_warn_52b319b1b6be3d2f(arg0, arg1) {
8236
8263
  console.warn(getStringFromWasm0(arg0, arg1));
8237
8264
  };
8238
8265
 
@@ -8274,12 +8301,12 @@ export function __wbindgen_cb_drop(arg0) {
8274
8301
  return ret;
8275
8302
  };
8276
8303
 
8277
- export function __wbindgen_closure_wrapper283(arg0, arg1, arg2) {
8304
+ export function __wbindgen_closure_wrapper285(arg0, arg1, arg2) {
8278
8305
  const ret = makeMutClosure(arg0, arg1, 15, __wbg_adapter_58);
8279
8306
  return addHeapObject(ret);
8280
8307
  };
8281
8308
 
8282
- export function __wbindgen_closure_wrapper542(arg0, arg1, arg2) {
8309
+ export function __wbindgen_closure_wrapper544(arg0, arg1, arg2) {
8283
8310
  const ret = makeMutClosure(arg0, arg1, 15, __wbg_adapter_61);
8284
8311
  return addHeapObject(ret);
8285
8312
  };
Binary file
@@ -66,7 +66,7 @@ export const lorocounter_parent: (a: number, b: number) => void;
66
66
  export const lorocounter_subscribe: (a: number, b: number, c: number) => void;
67
67
  export const lorocounter_toContainerTree: (a: number, b: number, c: number) => void;
68
68
  export const lorodoc_JSONPath: (a: number, b: number, c: number, d: number) => void;
69
- export const lorodoc_applyDiff: (a: number, b: number, c: number) => void;
69
+ export const lorodoc_applyDiff: (a: number, b: number, c: number, d: number) => void;
70
70
  export const lorodoc_attach: (a: number) => void;
71
71
  export const lorodoc_changeCount: (a: number) => number;
72
72
  export const lorodoc_checkout: (a: number, b: number, c: number, d: number) => void;
@@ -322,6 +322,29 @@ interface LoroDoc {
322
322
  diff(from: OpId[], to: OpId[], for_json?: boolean): [ContainerID, JsonDiff|Diff][];
323
323
  }
324
324
 
325
+ /**
326
+ * Options for `LoroDoc.applyDiff`.
327
+ */
328
+ export interface ApplyDiffOptions {
329
+ /**
330
+ * Read the batch as the result of `doc.diff()`: a mergeable child that the batch makes
331
+ * visible again carries its full content, which is aligned with whatever hidden state the
332
+ * target document keeps for it (none, the same, or different).
333
+ *
334
+ * Only use it for `doc.diff()` results (also after a JSON round trip), or for events from
335
+ * `import`/`checkout`, which report a revived child with its full content.
336
+ *
337
+ * Never use it for events from local commits. A local re-activation (such as
338
+ * `ensureMergeableCounter` over a deleted key) reports only the parent map change plus the
339
+ * commit's own ops, because the child's content did not change. With `fullState`, a
340
+ * missing child entry means "empty" and an entry means the whole content, so the hidden
341
+ * child would be cleared or overwritten (e.g. a counter at 7 becomes 0). Leave it unset
342
+ * (the default) for such events: their entries are increments, which is right when the
343
+ * target shares the source's hidden state.
344
+ */
345
+ fullState?: boolean;
346
+ }
347
+
325
348
  /**
326
349
  * Represents a `Delta` type which is a union of different operations that can be performed.
327
350
  *
@@ -1949,8 +1972,25 @@ export class LoroDoc {
1949
1972
  * doc2.applyDiff(diff);
1950
1973
  * console.log(doc2.getText("text").toString()); // "Hello"
1951
1974
  * ```
1975
+ *
1976
+ * Pass `{ fullState: true }` when applying the result of `doc.diff()` to a document that may
1977
+ * keep hidden state for a mergeable child the diff makes visible again (e.g. applying
1978
+ * `doc.diff(afterDelete, beforeDelete)` to `doc` itself or to a copy of it). The child's
1979
+ * entry is then read as its full content and aligned with that hidden state. Without it
1980
+ * (the default), entries are applied as increments, which is right for events forwarded to
1981
+ * a document that shares the source's hidden state. Never pass it for events from local
1982
+ * commits; see `ApplyDiffOptions.fullState`.
1983
+ *
1984
+ * ```ts
1985
+ * const text = doc.getMap("m").ensureMergeableText("t");
1986
+ * text.insert(0, "hello");
1987
+ * const before = doc.frontiers();
1988
+ * doc.getMap("m").delete("t");
1989
+ * doc.applyDiff(doc.diff(doc.frontiers(), before), { fullState: true });
1990
+ * console.log(doc.getMap("m").get("t").toString()); // "hello"
1991
+ * ```
1952
1992
  */
1953
- applyDiff(diff: [ContainerID, Diff|JsonDiff][]): void;
1993
+ applyDiff(diff: [ContainerID, Diff|JsonDiff][], options?: ApplyDiffOptions | null): void;
1954
1994
  /**
1955
1995
  * Check if the doc contains the full history.
1956
1996
  */
@@ -3979,10 +4019,19 @@ export class UndoManager {
3979
4019
  peer(): PeerID;
3980
4020
  /**
3981
4021
  * Redo the last undone operation.
4022
+ *
4023
+ * Throws like `undo` on steps that would recreate a container of an
4024
+ * unknown type.
3982
4025
  */
3983
4026
  redo(): boolean;
3984
4027
  /**
3985
4028
  * Undo the last operation.
4029
+ *
4030
+ * Throws without changing the doc if the step would have to recreate a
4031
+ * container of a type unknown to this version (created by a newer
4032
+ * loro-crdt). That step, with every edit merged into it, is dropped and its
4033
+ * edits stay; the next call undoes the step before it, rebased over the
4034
+ * dropped step's edits like over a remote peer's.
3986
4035
  */
3987
4036
  undo(): boolean;
3988
4037
  clear(): void;
@@ -2,7 +2,7 @@
2
2
  let imports = {};
3
3
  imports['__wbindgen_placeholder__'] = module.exports;
4
4
  let wasm;
5
- const { stateBinary, stateCid, stateContainer, stateIndex, stateOptions, stateRootCid, stateSet, stateSlice, stateValue } = require(String.raw`./snippets/loro-wasm-c600d14705866f8f/inline0.js`);
5
+ const { stateBinary, stateCid, stateContainer, stateIndex, stateOptions, stateRootCid, stateSet, stateSlice, stateValue } = require(String.raw`./snippets/loro-wasm-704a44faa43c032c/inline0.js`);
6
6
  const { TextEncoder, TextDecoder } = require(`util`);
7
7
 
8
8
  const heap = new Array(128).fill(undefined);
@@ -1360,12 +1360,30 @@ class LoroDoc {
1360
1360
  * doc2.applyDiff(diff);
1361
1361
  * console.log(doc2.getText("text").toString()); // "Hello"
1362
1362
  * ```
1363
+ *
1364
+ * Pass `{ fullState: true }` when applying the result of `doc.diff()` to a document that may
1365
+ * keep hidden state for a mergeable child the diff makes visible again (e.g. applying
1366
+ * `doc.diff(afterDelete, beforeDelete)` to `doc` itself or to a copy of it). The child's
1367
+ * entry is then read as its full content and aligned with that hidden state. Without it
1368
+ * (the default), entries are applied as increments, which is right for events forwarded to
1369
+ * a document that shares the source's hidden state. Never pass it for events from local
1370
+ * commits; see `ApplyDiffOptions.fullState`.
1371
+ *
1372
+ * ```ts
1373
+ * const text = doc.getMap("m").ensureMergeableText("t");
1374
+ * text.insert(0, "hello");
1375
+ * const before = doc.frontiers();
1376
+ * doc.getMap("m").delete("t");
1377
+ * doc.applyDiff(doc.diff(doc.frontiers(), before), { fullState: true });
1378
+ * console.log(doc.getMap("m").get("t").toString()); // "hello"
1379
+ * ```
1363
1380
  * @param {[ContainerID, Diff|JsonDiff][]} diff
1381
+ * @param {ApplyDiffOptions | null} [options]
1364
1382
  */
1365
- applyDiff(diff) {
1383
+ applyDiff(diff, options) {
1366
1384
  try {
1367
1385
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1368
- wasm.lorodoc_applyDiff(retptr, this.__wbg_ptr, addHeapObject(diff));
1386
+ wasm.lorodoc_applyDiff(retptr, this.__wbg_ptr, addHeapObject(diff), isLikeNone(options) ? 0 : addHeapObject(options));
1369
1387
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1370
1388
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1371
1389
  if (r1) {
@@ -7428,6 +7446,9 @@ class UndoManager {
7428
7446
  }
7429
7447
  /**
7430
7448
  * Redo the last undone operation.
7449
+ *
7450
+ * Throws like `undo` on steps that would recreate a container of an
7451
+ * unknown type.
7431
7452
  * @returns {boolean}
7432
7453
  */
7433
7454
  redo() {
@@ -7447,6 +7468,12 @@ class UndoManager {
7447
7468
  }
7448
7469
  /**
7449
7470
  * Undo the last operation.
7471
+ *
7472
+ * Throws without changing the doc if the step would have to recreate a
7473
+ * container of a type unknown to this version (created by a newer
7474
+ * loro-crdt). That step, with every edit merged into it, is dropped and its
7475
+ * edits stay; the next call undoes the step before it, rebased over the
7476
+ * dropped step's edits like over a remote peer's.
7450
7477
  * @returns {boolean}
7451
7478
  */
7452
7479
  undo() {
@@ -7837,7 +7864,7 @@ module.exports.__wbg_entries_c8a90a7ed73e84ce = function(arg0) {
7837
7864
  return addHeapObject(ret);
7838
7865
  };
7839
7866
 
7840
- module.exports.__wbg_error_10d6926de361eb2b = function(arg0, arg1) {
7867
+ module.exports.__wbg_error_1d6f2b3f2c5a33ec = function(arg0, arg1) {
7841
7868
  console.error(getStringFromWasm0(arg0, arg1));
7842
7869
  };
7843
7870
 
@@ -7968,7 +7995,7 @@ module.exports.__wbg_log_cb9e190acc5753fb = function(arg0, arg1) {
7968
7995
  }
7969
7996
  };
7970
7997
 
7971
- module.exports.__wbg_log_d5951556f2f10ec9 = function(arg0, arg1) {
7998
+ module.exports.__wbg_log_f665cabe523a97df = function(arg0, arg1) {
7972
7999
  console.log(getStringFromWasm0(arg0, arg1));
7973
8000
  };
7974
8001
 
@@ -8153,45 +8180,45 @@ module.exports.__wbg_setindex_dcd71eabf405bde1 = function(arg0, arg1, arg2) {
8153
8180
  getObject(arg0)[arg1 >>> 0] = arg2;
8154
8181
  };
8155
8182
 
8156
- module.exports.__wbg_stateBinary_64e9eb9b37720ab6 = function(arg0, arg1) {
8183
+ module.exports.__wbg_stateBinary_9e1da8a4daa74bc6 = function(arg0, arg1) {
8157
8184
  const ret = stateBinary(getArrayU8FromWasm0(arg0, arg1));
8158
8185
  return addHeapObject(ret);
8159
8186
  };
8160
8187
 
8161
- module.exports.__wbg_stateCid_760e963fd4c95f01 = function(arg0, arg1, arg2) {
8188
+ module.exports.__wbg_stateCid_c43ea762fb462319 = function(arg0, arg1, arg2) {
8162
8189
  const ret = stateCid(getObject(arg0), arg1, arg2);
8163
8190
  return addHeapObject(ret);
8164
8191
  };
8165
8192
 
8166
- module.exports.__wbg_stateContainer_71de82dd2efd60eb = function(arg0, arg1, arg2) {
8193
+ module.exports.__wbg_stateContainer_cd983f42c6fe987d = function(arg0, arg1, arg2) {
8167
8194
  const ret = stateContainer(arg0, getObject(arg1), takeObject(arg2));
8168
8195
  return addHeapObject(ret);
8169
8196
  };
8170
8197
 
8171
- module.exports.__wbg_stateIndex_acd88b869f874497 = function() { return handleError(function (arg0, arg1, arg2) {
8198
+ module.exports.__wbg_stateIndex_1fbac6394e58cff9 = function() { return handleError(function (arg0, arg1, arg2) {
8172
8199
  stateIndex(getObject(arg0), arg1 >>> 0, getObject(arg2));
8173
8200
  }, arguments) };
8174
8201
 
8175
- module.exports.__wbg_stateOptions_8486fef4478d16b3 = function() { return handleError(function (arg0, arg1) {
8202
+ module.exports.__wbg_stateOptions_dcb483514d1b925d = function() { return handleError(function (arg0, arg1) {
8176
8203
  const ret = stateOptions(takeObject(arg0), arg1 !== 0);
8177
8204
  return addHeapObject(ret);
8178
8205
  }, arguments) };
8179
8206
 
8180
- module.exports.__wbg_stateRootCid_964d9fbc9bfbcea3 = function(arg0, arg1, arg2) {
8207
+ module.exports.__wbg_stateRootCid_9198769cdd9f37d5 = function(arg0, arg1, arg2) {
8181
8208
  const ret = stateRootCid(getStringFromWasm0(arg0, arg1), arg2);
8182
8209
  return addHeapObject(ret);
8183
8210
  };
8184
8211
 
8185
- module.exports.__wbg_stateSet_6cd1dd82536a3182 = function() { return handleError(function (arg0, arg1, arg2) {
8212
+ module.exports.__wbg_stateSet_a3e74b27d3d26f9d = function() { return handleError(function (arg0, arg1, arg2) {
8186
8213
  stateSet(getObject(arg0), getObject(arg1), getObject(arg2));
8187
8214
  }, arguments) };
8188
8215
 
8189
- module.exports.__wbg_stateSlice_8d4107ebb0dfc484 = function(arg0, arg1, arg2) {
8216
+ module.exports.__wbg_stateSlice_aafffe8ecba122b8 = function(arg0, arg1, arg2) {
8190
8217
  const ret = stateSlice(takeObject(arg0), arg1 >>> 0, arg2 >>> 0);
8191
8218
  return addHeapObject(ret);
8192
8219
  };
8193
8220
 
8194
- module.exports.__wbg_stateValue_0727099e81830513 = function(arg0) {
8221
+ module.exports.__wbg_stateValue_8ed644fcdb61558c = function(arg0) {
8195
8222
  const ret = stateValue(takeObject(arg0));
8196
8223
  return addHeapObject(ret);
8197
8224
  };
@@ -8241,7 +8268,7 @@ module.exports.__wbg_versionvector_new = function(arg0) {
8241
8268
  return addHeapObject(ret);
8242
8269
  };
8243
8270
 
8244
- module.exports.__wbg_warn_576423aac512a858 = function(arg0, arg1) {
8271
+ module.exports.__wbg_warn_52b319b1b6be3d2f = function(arg0, arg1) {
8245
8272
  console.warn(getStringFromWasm0(arg0, arg1));
8246
8273
  };
8247
8274
 
@@ -8283,12 +8310,12 @@ module.exports.__wbindgen_cb_drop = function(arg0) {
8283
8310
  return ret;
8284
8311
  };
8285
8312
 
8286
- module.exports.__wbindgen_closure_wrapper283 = function(arg0, arg1, arg2) {
8313
+ module.exports.__wbindgen_closure_wrapper285 = function(arg0, arg1, arg2) {
8287
8314
  const ret = makeMutClosure(arg0, arg1, 15, __wbg_adapter_58);
8288
8315
  return addHeapObject(ret);
8289
8316
  };
8290
8317
 
8291
- module.exports.__wbindgen_closure_wrapper542 = function(arg0, arg1, arg2) {
8318
+ module.exports.__wbindgen_closure_wrapper544 = function(arg0, arg1, arg2) {
8292
8319
  const ret = makeMutClosure(arg0, arg1, 15, __wbg_adapter_61);
8293
8320
  return addHeapObject(ret);
8294
8321
  };
Binary file
@@ -66,7 +66,7 @@ export const lorocounter_parent: (a: number, b: number) => void;
66
66
  export const lorocounter_subscribe: (a: number, b: number, c: number) => void;
67
67
  export const lorocounter_toContainerTree: (a: number, b: number, c: number) => void;
68
68
  export const lorodoc_JSONPath: (a: number, b: number, c: number, d: number) => void;
69
- export const lorodoc_applyDiff: (a: number, b: number, c: number) => void;
69
+ export const lorodoc_applyDiff: (a: number, b: number, c: number, d: number) => void;
70
70
  export const lorodoc_attach: (a: number) => void;
71
71
  export const lorodoc_changeCount: (a: number) => number;
72
72
  export const lorodoc_checkout: (a: number, b: number, c: number, d: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loro-crdt",
3
- "version": "1.16.3",
3
+ "version": "1.16.4",
4
4
  "description": "Loro CRDTs is a high-performance CRDT framework that makes your app state synchronized, collaborative and maintainable effortlessly.",
5
5
  "keywords": [
6
6
  "crdt",
@@ -322,6 +322,29 @@ interface LoroDoc {
322
322
  diff(from: OpId[], to: OpId[], for_json?: boolean): [ContainerID, JsonDiff|Diff][];
323
323
  }
324
324
 
325
+ /**
326
+ * Options for `LoroDoc.applyDiff`.
327
+ */
328
+ export interface ApplyDiffOptions {
329
+ /**
330
+ * Read the batch as the result of `doc.diff()`: a mergeable child that the batch makes
331
+ * visible again carries its full content, which is aligned with whatever hidden state the
332
+ * target document keeps for it (none, the same, or different).
333
+ *
334
+ * Only use it for `doc.diff()` results (also after a JSON round trip), or for events from
335
+ * `import`/`checkout`, which report a revived child with its full content.
336
+ *
337
+ * Never use it for events from local commits. A local re-activation (such as
338
+ * `ensureMergeableCounter` over a deleted key) reports only the parent map change plus the
339
+ * commit's own ops, because the child's content did not change. With `fullState`, a
340
+ * missing child entry means "empty" and an entry means the whole content, so the hidden
341
+ * child would be cleared or overwritten (e.g. a counter at 7 becomes 0). Leave it unset
342
+ * (the default) for such events: their entries are increments, which is right when the
343
+ * target shares the source's hidden state.
344
+ */
345
+ fullState?: boolean;
346
+ }
347
+
325
348
  /**
326
349
  * Represents a `Delta` type which is a union of different operations that can be performed.
327
350
  *
@@ -1949,8 +1972,25 @@ export class LoroDoc {
1949
1972
  * doc2.applyDiff(diff);
1950
1973
  * console.log(doc2.getText("text").toString()); // "Hello"
1951
1974
  * ```
1975
+ *
1976
+ * Pass `{ fullState: true }` when applying the result of `doc.diff()` to a document that may
1977
+ * keep hidden state for a mergeable child the diff makes visible again (e.g. applying
1978
+ * `doc.diff(afterDelete, beforeDelete)` to `doc` itself or to a copy of it). The child's
1979
+ * entry is then read as its full content and aligned with that hidden state. Without it
1980
+ * (the default), entries are applied as increments, which is right for events forwarded to
1981
+ * a document that shares the source's hidden state. Never pass it for events from local
1982
+ * commits; see `ApplyDiffOptions.fullState`.
1983
+ *
1984
+ * ```ts
1985
+ * const text = doc.getMap("m").ensureMergeableText("t");
1986
+ * text.insert(0, "hello");
1987
+ * const before = doc.frontiers();
1988
+ * doc.getMap("m").delete("t");
1989
+ * doc.applyDiff(doc.diff(doc.frontiers(), before), { fullState: true });
1990
+ * console.log(doc.getMap("m").get("t").toString()); // "hello"
1991
+ * ```
1952
1992
  */
1953
- applyDiff(diff: [ContainerID, Diff|JsonDiff][]): void;
1993
+ applyDiff(diff: [ContainerID, Diff|JsonDiff][], options?: ApplyDiffOptions | null): void;
1954
1994
  /**
1955
1995
  * Check if the doc contains the full history.
1956
1996
  */
@@ -3979,10 +4019,19 @@ export class UndoManager {
3979
4019
  peer(): PeerID;
3980
4020
  /**
3981
4021
  * Redo the last undone operation.
4022
+ *
4023
+ * Throws like `undo` on steps that would recreate a container of an
4024
+ * unknown type.
3982
4025
  */
3983
4026
  redo(): boolean;
3984
4027
  /**
3985
4028
  * Undo the last operation.
4029
+ *
4030
+ * Throws without changing the doc if the step would have to recreate a
4031
+ * container of a type unknown to this version (created by a newer
4032
+ * loro-crdt). That step, with every edit merged into it, is dropped and its
4033
+ * edits stay; the next call undoes the step before it, rebased over the
4034
+ * dropped step's edits like over a remote peer's.
3986
4035
  */
3987
4036
  undo(): boolean;
3988
4037
  clear(): void;
@@ -4149,7 +4198,7 @@ export interface InitOutput {
4149
4198
  readonly lorocounter_subscribe: (a: number, b: number, c: number) => void;
4150
4199
  readonly lorocounter_toContainerTree: (a: number, b: number, c: number) => void;
4151
4200
  readonly lorodoc_JSONPath: (a: number, b: number, c: number, d: number) => void;
4152
- readonly lorodoc_applyDiff: (a: number, b: number, c: number) => void;
4201
+ readonly lorodoc_applyDiff: (a: number, b: number, c: number, d: number) => void;
4153
4202
  readonly lorodoc_attach: (a: number) => void;
4154
4203
  readonly lorodoc_changeCount: (a: number) => number;
4155
4204
  readonly lorodoc_checkout: (a: number, b: number, c: number, d: number) => void;