loro-crdt 1.10.0 → 1.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ export function callPendingEvents(): void;
3
4
  /**
4
5
  * Get the version of Loro
5
6
  */
@@ -8,8 +9,9 @@ export function LORO_VERSION(): string;
8
9
  * Enable debug info of Loro
9
10
  */
10
11
  export function setDebug(): void;
11
- export function run(): void;
12
+ export function encodeFrontiers(frontiers: ({ peer: PeerID, counter: number })[]): Uint8Array;
12
13
  export function decodeFrontiers(bytes: Uint8Array): { peer: PeerID, counter: number }[];
14
+ export function run(): void;
13
15
  /**
14
16
  * Redacts sensitive content in JSON updates within the specified version range.
15
17
  *
@@ -43,8 +45,6 @@ export function redactJsonUpdates(json_updates: string | JsonSchema, version_ran
43
45
  * - changeNum
44
46
  */
45
47
  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.
@@ -63,6 +63,7 @@ export function callPendingEvents(): void;
63
63
  export type ContainerType = "Text" | "Map" | "List"| "Tree" | "MovableList" | "Counter";
64
64
 
65
65
  export type PeerID = `${number}`;
66
+ export type TextPosType = "unicode" | "utf16" | "utf8";
66
67
  /**
67
68
  * The unique id of each container.
68
69
  *
@@ -338,7 +339,7 @@ interface LoroDoc {
338
339
  export type Delta<T> =
339
340
  | {
340
341
  insert: T;
341
- attributes?: { [key in string]: {} };
342
+ attributes?: { [key in string]: Value };
342
343
  retain?: undefined;
343
344
  delete?: undefined;
344
345
  }
@@ -350,7 +351,7 @@ export type Delta<T> =
350
351
  }
351
352
  | {
352
353
  retain: number;
353
- attributes?: { [key in string]: {} };
354
+ attributes?: { [key in string]: Value };
354
355
  delete?: undefined;
355
356
  insert?: undefined;
356
357
  };
@@ -450,6 +451,11 @@ export interface ImportBlobMetadata {
450
451
  }
451
452
 
452
453
  interface LoroText {
454
+ /**
455
+ * Convert a position between coordinate systems.
456
+ */
457
+ convertPos(index: number, from: TextPosType, to: TextPosType): number | undefined;
458
+
453
459
  /**
454
460
  * Get the cursor position at the given pos.
455
461
  *
@@ -1264,6 +1270,10 @@ interface LoroText {
1264
1270
  insert(pos: number, text: string): void;
1265
1271
  delete(pos: number, len: number): void;
1266
1272
  subscribe(listener: Listener): Subscription;
1273
+ /**
1274
+ * Convert a position between coordinate systems.
1275
+ */
1276
+ convertPos(index: number, from: TextPosType, to: TextPosType): number | undefined;
1267
1277
  /**
1268
1278
  * Update the current text to the target text.
1269
1279
  *
@@ -3035,6 +3045,14 @@ export class LoroText {
3035
3045
  * ```
3036
3046
  */
3037
3047
  applyDelta(delta: Delta<string>[]): void;
3048
+ /**
3049
+ * Convert a position between coordinate systems.
3050
+ *
3051
+ * Supported values: `"unicode"`, `"utf16"`, `"utf8"`.
3052
+ *
3053
+ * Returns `undefined` when out of bounds or unsupported.
3054
+ */
3055
+ convertPos(index: number, from: string, to: string): any;
3038
3056
  /**
3039
3057
  * Delete elements from index to utf-8 index + len
3040
3058
  *
@@ -3905,6 +3923,7 @@ export interface InitOutput {
3905
3923
  readonly loromovablelist_toJSON: (a: number) => any;
3906
3924
  readonly lorotext_applyDelta: (a: number, b: any) => [number, number];
3907
3925
  readonly lorotext_charAt: (a: number, b: number) => [number, number, number];
3926
+ readonly lorotext_convertPos: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
3908
3927
  readonly lorotext_delete: (a: number, b: number, c: number) => [number, number];
3909
3928
  readonly lorotext_deleteUtf8: (a: number, b: number, c: number) => [number, number];
3910
3929
  readonly lorotext_getAttached: (a: number) => any;
@@ -4017,7 +4036,7 @@ export interface InitOutput {
4017
4036
  readonly __externref_table_dealloc: (a: number) => void;
4018
4037
  readonly __externref_drop_slice: (a: number, b: number) => void;
4019
4038
  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;
4039
+ readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha7d67e25add7f151: (a: number, b: number) => void;
4021
4040
  readonly __wbindgen_start: () => void;
4022
4041
  }
4023
4042
 
package/web/loro_wasm.js CHANGED
@@ -232,6 +232,11 @@ function getArrayJsValueFromWasm0(ptr, len) {
232
232
  wasm.__externref_drop_slice(ptr, len);
233
233
  return result;
234
234
  }
235
+
236
+ export function callPendingEvents() {
237
+ wasm.callPendingEvents();
238
+ }
239
+
235
240
  /**
236
241
  * Get the version of Loro
237
242
  * @returns {string}
@@ -256,8 +261,29 @@ export function setDebug() {
256
261
  wasm.setDebug();
257
262
  }
258
263
 
259
- export function run() {
260
- wasm.run();
264
+ function passArrayJsValueToWasm0(array, malloc) {
265
+ const ptr = malloc(array.length * 4, 4) >>> 0;
266
+ for (let i = 0; i < array.length; i++) {
267
+ const add = addToExternrefTable0(array[i]);
268
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
269
+ }
270
+ WASM_VECTOR_LEN = array.length;
271
+ return ptr;
272
+ }
273
+ /**
274
+ * @param {({ peer: PeerID, counter: number })[]} frontiers
275
+ * @returns {Uint8Array}
276
+ */
277
+ export function encodeFrontiers(frontiers) {
278
+ const ptr0 = passArrayJsValueToWasm0(frontiers, wasm.__wbindgen_malloc);
279
+ const len0 = WASM_VECTOR_LEN;
280
+ const ret = wasm.encodeFrontiers(ptr0, len0);
281
+ if (ret[3]) {
282
+ throw takeFromExternrefTable0(ret[2]);
283
+ }
284
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
285
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
286
+ return v2;
261
287
  }
262
288
 
263
289
  /**
@@ -274,6 +300,10 @@ export function decodeFrontiers(bytes) {
274
300
  return takeFromExternrefTable0(ret[0]);
275
301
  }
276
302
 
303
+ export function run() {
304
+ wasm.run();
305
+ }
306
+
277
307
  /**
278
308
  * Redacts sensitive content in JSON updates within the specified version range.
279
309
  *
@@ -329,41 +359,12 @@ export function decodeImportBlobMeta(blob, check_checksum) {
329
359
  return takeFromExternrefTable0(ret[0]);
330
360
  }
331
361
 
332
- function passArrayJsValueToWasm0(array, malloc) {
333
- const ptr = malloc(array.length * 4, 4) >>> 0;
334
- for (let i = 0; i < array.length; i++) {
335
- const add = addToExternrefTable0(array[i]);
336
- getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
337
- }
338
- WASM_VECTOR_LEN = array.length;
339
- return ptr;
340
- }
341
- /**
342
- * @param {({ peer: PeerID, counter: number })[]} frontiers
343
- * @returns {Uint8Array}
344
- */
345
- export function encodeFrontiers(frontiers) {
346
- const ptr0 = passArrayJsValueToWasm0(frontiers, wasm.__wbindgen_malloc);
347
- const len0 = WASM_VECTOR_LEN;
348
- const ret = wasm.encodeFrontiers(ptr0, len0);
349
- if (ret[3]) {
350
- throw takeFromExternrefTable0(ret[2]);
351
- }
352
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
353
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
354
- return v2;
355
- }
356
-
357
- export function callPendingEvents() {
358
- wasm.callPendingEvents();
359
- }
360
-
361
362
  function __wbg_adapter_62(arg0, arg1, arg2) {
362
363
  wasm.closure11_externref_shim(arg0, arg1, arg2);
363
364
  }
364
365
 
365
366
  function __wbg_adapter_65(arg0, arg1) {
366
- wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h87f1268ec3b8423e(arg0, arg1);
367
+ wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha7d67e25add7f151(arg0, arg1);
367
368
  }
368
369
 
369
370
  const AwarenessWasmFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -3895,6 +3896,25 @@ export class LoroText {
3895
3896
  throw takeFromExternrefTable0(ret[0]);
3896
3897
  }
3897
3898
  }
3899
+ /**
3900
+ * Convert a position between coordinate systems.
3901
+ *
3902
+ * Supported values: `"unicode"`, `"utf16"`, `"utf8"`.
3903
+ *
3904
+ * Returns `undefined` when out of bounds or unsupported.
3905
+ * @param {number} index
3906
+ * @param {string} from
3907
+ * @param {string} to
3908
+ * @returns {any}
3909
+ */
3910
+ convertPos(index, from, to) {
3911
+ const ptr0 = passStringToWasm0(from, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
3912
+ const len0 = WASM_VECTOR_LEN;
3913
+ const ptr1 = passStringToWasm0(to, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
3914
+ const len1 = WASM_VECTOR_LEN;
3915
+ const ret = wasm.lorotext_convertPos(this.__wbg_ptr, index, ptr0, len0, ptr1, len1);
3916
+ return ret;
3917
+ }
3898
3918
  /**
3899
3919
  * Delete elements from index to utf-8 index + len
3900
3920
  *
@@ -5521,6 +5541,9 @@ function __wbg_get_imports() {
5521
5541
  const ret = arg0.entries();
5522
5542
  return ret;
5523
5543
  };
5544
+ imports.wbg.__wbg_error_4ac2b4fe53215e85 = function(arg0, arg1) {
5545
+ console.error(getStringFromWasm0(arg0, arg1));
5546
+ };
5524
5547
  imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
5525
5548
  let deferred0_0;
5526
5549
  let deferred0_1;
@@ -5532,9 +5555,6 @@ function __wbg_get_imports() {
5532
5555
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
5533
5556
  }
5534
5557
  };
5535
- imports.wbg.__wbg_error_d3c8fa5665ed2ac9 = function(arg0, arg1) {
5536
- console.error(getStringFromWasm0(arg0, arg1));
5537
- };
5538
5558
  imports.wbg.__wbg_from_2a5d3e218e67aa85 = function(arg0) {
5539
5559
  const ret = Array.from(arg0);
5540
5560
  return ret;
@@ -5633,7 +5653,7 @@ function __wbg_get_imports() {
5633
5653
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
5634
5654
  }
5635
5655
  };
5636
- imports.wbg.__wbg_log_5f802740a68181b2 = function(arg0, arg1) {
5656
+ imports.wbg.__wbg_log_bd9aa71b996755d3 = function(arg0, arg1) {
5637
5657
  console.log(getStringFromWasm0(arg0, arg1));
5638
5658
  };
5639
5659
  imports.wbg.__wbg_log_cb9e190acc5753fb = function(arg0, arg1) {
@@ -5836,7 +5856,7 @@ function __wbg_get_imports() {
5836
5856
  const ret = VersionVector.__wrap(arg0);
5837
5857
  return ret;
5838
5858
  };
5839
- imports.wbg.__wbg_warn_13f0ef2de338c601 = function(arg0, arg1) {
5859
+ imports.wbg.__wbg_warn_ba32d63a72098111 = function(arg0, arg1) {
5840
5860
  console.warn(getStringFromWasm0(arg0, arg1));
5841
5861
  };
5842
5862
  imports.wbg.__wbindgen_as_number = function(arg0) {
@@ -5875,7 +5895,7 @@ function __wbg_get_imports() {
5875
5895
  const ret = makeMutClosure(arg0, arg1, 10, __wbg_adapter_62);
5876
5896
  return ret;
5877
5897
  };
5878
- imports.wbg.__wbindgen_closure_wrapper720 = function(arg0, arg1, arg2) {
5898
+ imports.wbg.__wbindgen_closure_wrapper721 = function(arg0, arg1, arg2) {
5879
5899
  const ret = makeMutClosure(arg0, arg1, 10, __wbg_adapter_65);
5880
5900
  return ret;
5881
5901
  };
Binary file
@@ -212,6 +212,7 @@ export const loromovablelist_toArray: (a: number) => [number, number];
212
212
  export const loromovablelist_toJSON: (a: number) => any;
213
213
  export const lorotext_applyDelta: (a: number, b: any) => [number, number];
214
214
  export const lorotext_charAt: (a: number, b: number) => [number, number, number];
215
+ export const lorotext_convertPos: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
215
216
  export const lorotext_delete: (a: number, b: number, c: number) => [number, number];
216
217
  export const lorotext_deleteUtf8: (a: number, b: number, c: number) => [number, number];
217
218
  export const lorotext_getAttached: (a: number) => any;
@@ -324,5 +325,5 @@ export const __wbindgen_export_6: WebAssembly.Table;
324
325
  export const __externref_table_dealloc: (a: number) => void;
325
326
  export const __externref_drop_slice: (a: number, b: number) => void;
326
327
  export const closure11_externref_shim: (a: number, b: number, c: any) => void;
327
- export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h87f1268ec3b8423e: (a: number, b: number) => void;
328
+ export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha7d67e25add7f151: (a: number, b: number) => void;
328
329
  export const __wbindgen_start: () => void;