@pluv/crdt-loro 3.1.4 → 3.1.6

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,5 @@
1
1
 
2
- > @pluv/crdt-loro@3.1.4 build /home/runner/work/pluv/pluv/packages/crdt-loro
2
+ > @pluv/crdt-loro@3.1.6 build /home/runner/work/pluv/pluv/packages/crdt-loro
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,11 +8,11 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- CJS dist/index.js 11.17 KB
12
- CJS ⚡️ Build success in 89ms
13
- ESM dist/index.mjs 10.11 KB
14
- ESM ⚡️ Build success in 90ms
11
+ ESM dist/index.mjs 10.39 KB
12
+ ESM ⚡️ Build success in 89ms
13
+ CJS dist/index.js 11.44 KB
14
+ CJS ⚡️ Build success in 92ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 4049ms
17
- DTS dist/index.d.mts 4.65 KB
18
- DTS dist/index.d.ts 4.65 KB
16
+ DTS ⚡️ Build success in 3970ms
17
+ DTS dist/index.d.mts 4.68 KB
18
+ DTS dist/index.d.ts 4.68 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @pluv/crdt-loro
2
2
 
3
+ ## 3.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - @pluv/crdt@3.1.6
8
+ - @pluv/types@3.1.6
9
+
10
+ ## 3.1.5
11
+
12
+ ### Patch Changes
13
+
14
+ - 6d43c08: Fixed CRDT docs being considered as `empty` even when there are properties (i.e. yjs shared types and loro container types) on the document when they have not been modified.
15
+ - @pluv/crdt@3.1.5
16
+ - @pluv/types@3.1.5
17
+
3
18
  ## 3.1.4
4
19
 
5
20
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -47,6 +47,7 @@ declare class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>> i
47
47
  */
48
48
  transact(fn: () => void): this;
49
49
  undo(): this;
50
+ private _setPluvId;
50
51
  private _warn;
51
52
  }
52
53
 
package/dist/index.d.ts CHANGED
@@ -47,6 +47,7 @@ declare class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>> i
47
47
  */
48
48
  transact(fn: () => void): this;
49
49
  undo(): this;
50
+ private _setPluvId;
50
51
  private _warn;
51
52
  }
52
53
 
package/dist/index.js CHANGED
@@ -112,6 +112,7 @@ var builder = (doc2) => {
112
112
  // src/doc/CrdtLoroDoc.ts
113
113
  var MAX_UNDO_STEPS = 100;
114
114
  var MERGE_INTERVAL_MS = 1e3;
115
+ var PLUV_ID_FIELD = "__$pluv";
115
116
  var CrdtLoroDoc = class {
116
117
  constructor(params = () => ({})) {
117
118
  this.value = new import_loro_crdt3.LoroDoc();
@@ -125,6 +126,7 @@ var CrdtLoroDoc = class {
125
126
  (acc, [key, node]) => keys.has(key) ? __spreadProps(__spreadValues({}, acc), { [key]: node }) : acc,
126
127
  {}
127
128
  );
129
+ if (!!Object.keys(storage).length) this._setPluvId();
128
130
  this.value.commit();
129
131
  }
130
132
  applyEncodedState(params) {
@@ -264,6 +266,11 @@ var CrdtLoroDoc = class {
264
266
  (_a = this._undoManager) == null ? void 0 : _a.undo();
265
267
  return this;
266
268
  }
269
+ _setPluvId() {
270
+ const text2 = this.value.getText(PLUV_ID_FIELD);
271
+ const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
272
+ text2.insert(0, id);
273
+ }
267
274
  _warn(...data) {
268
275
  var _a;
269
276
  if (typeof process === "undefined") return;
package/dist/index.mjs CHANGED
@@ -102,6 +102,7 @@ var builder = (doc2) => {
102
102
  // src/doc/CrdtLoroDoc.ts
103
103
  var MAX_UNDO_STEPS = 100;
104
104
  var MERGE_INTERVAL_MS = 1e3;
105
+ var PLUV_ID_FIELD = "__$pluv";
105
106
  var CrdtLoroDoc = class {
106
107
  constructor(params = () => ({})) {
107
108
  this.value = new LoroDoc();
@@ -115,6 +116,7 @@ var CrdtLoroDoc = class {
115
116
  (acc, [key, node]) => keys.has(key) ? __spreadProps(__spreadValues({}, acc), { [key]: node }) : acc,
116
117
  {}
117
118
  );
119
+ if (!!Object.keys(storage).length) this._setPluvId();
118
120
  this.value.commit();
119
121
  }
120
122
  applyEncodedState(params) {
@@ -254,6 +256,11 @@ var CrdtLoroDoc = class {
254
256
  (_a = this._undoManager) == null ? void 0 : _a.undo();
255
257
  return this;
256
258
  }
259
+ _setPluvId() {
260
+ const text2 = this.value.getText(PLUV_ID_FIELD);
261
+ const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
262
+ text2.insert(0, id);
263
+ }
257
264
  _warn(...data) {
258
265
  var _a;
259
266
  if (typeof process === "undefined") return;
@@ -286,44 +293,44 @@ var doc = (value = () => ({})) => {
286
293
  };
287
294
 
288
295
  // src/list.ts
289
- import { LoroList as LoroList2, isContainer as isContainer3 } from "loro-crdt";
296
+ import { LoroList as LoroList2, isContainer as isContainer2 } from "loro-crdt";
290
297
  var list = (value = []) => {
291
298
  const container = new LoroList2();
292
299
  value.forEach((item, i) => {
293
- if (isContainer3(item)) container.insertContainer(i, item);
300
+ if (isContainer2(item)) container.insertContainer(i, item);
294
301
  else container.insert(i, item);
295
302
  });
296
303
  return container;
297
304
  };
298
305
 
299
306
  // src/map.ts
300
- import { LoroMap as LoroMap2, isContainer as isContainer4 } from "loro-crdt";
307
+ import { LoroMap as LoroMap2, isContainer as isContainer3 } from "loro-crdt";
301
308
  var map = (value = []) => {
302
309
  const container = new LoroMap2();
303
310
  value.forEach(([key, item]) => {
304
- if (isContainer4(item)) container.setContainer(key, item);
311
+ if (isContainer3(item)) container.setContainer(key, item);
305
312
  else container.set(key, item);
306
313
  });
307
314
  return container;
308
315
  };
309
316
 
310
317
  // src/movableList.ts
311
- import { isContainer as isContainer5, LoroMovableList as LoroMovableList2 } from "loro-crdt";
318
+ import { isContainer as isContainer4, LoroMovableList as LoroMovableList2 } from "loro-crdt";
312
319
  var movableList = (value = []) => {
313
320
  const container = new LoroMovableList2();
314
321
  value.forEach((item, i) => {
315
- if (isContainer5(item)) container.insertContainer(i, item);
322
+ if (isContainer4(item)) container.insertContainer(i, item);
316
323
  else container.insert(i, item);
317
324
  });
318
325
  return container;
319
326
  };
320
327
 
321
328
  // src/object.ts
322
- import { LoroMap as LoroMap3, isContainer as isContainer6 } from "loro-crdt";
329
+ import { LoroMap as LoroMap3, isContainer as isContainer5 } from "loro-crdt";
323
330
  var object = (value) => {
324
331
  const container = new LoroMap3();
325
332
  Object.entries(value).forEach(([key, item]) => {
326
- if (isContainer6(item)) container.setContainer(key, item);
333
+ if (isContainer5(item)) container.setContainer(key, item);
327
334
  else container.set(key, item);
328
335
  });
329
336
  return container;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/crdt-loro",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "description": "loro for @pluv/io",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -19,8 +19,8 @@
19
19
  "dependencies": {
20
20
  "@types/node": "^22.15.21",
21
21
  "js-base64": "^3.7.7",
22
- "@pluv/crdt": "^3.1.4",
23
- "@pluv/types": "^3.1.4"
22
+ "@pluv/crdt": "^3.1.6",
23
+ "@pluv/types": "^3.1.6"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "loro-crdt": "^1.0.0"
@@ -30,8 +30,8 @@
30
30
  "loro-crdt": "^1.5.6",
31
31
  "tsup": "^8.5.0",
32
32
  "typescript": "^5.8.3",
33
- "@pluv/tsconfig": "^3.1.4",
34
- "eslint-config-pluv": "^3.1.4"
33
+ "@pluv/tsconfig": "^3.1.6",
34
+ "eslint-config-pluv": "^3.1.6"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -17,15 +17,14 @@ import {
17
17
  LoroText,
18
18
  LoroTree,
19
19
  UndoManager,
20
- isContainer,
21
20
  } from "loro-crdt";
22
21
  import type { LoroType } from "../types";
23
- import { oneLine } from "../utils";
24
22
  import type { LoroBuilder } from "./builder";
25
23
  import { builder } from "./builder";
26
24
 
27
25
  const MAX_UNDO_STEPS = 100;
28
26
  const MERGE_INTERVAL_MS = 1_000;
27
+ const PLUV_ID_FIELD = "__$pluv";
29
28
 
30
29
  export type CrdtLoroDocParams<TStorage extends Record<string, LoroType<any, any>>> = (
31
30
  builder: LoroBuilder,
@@ -51,6 +50,7 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
51
50
  (acc, [key, node]) => (keys.has(key) ? { ...acc, [key]: node } : acc),
52
51
  {} as TStorage,
53
52
  );
53
+ if (!!Object.keys(storage).length) this._setPluvId();
54
54
 
55
55
  this.value.commit();
56
56
  }
@@ -250,6 +250,13 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
250
250
  return this;
251
251
  }
252
252
 
253
+ private _setPluvId() {
254
+ const text = this.value.getText(PLUV_ID_FIELD);
255
+ const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
256
+
257
+ text.insert(0, id);
258
+ }
259
+
253
260
  private _warn(...data: any[]) {
254
261
  if (typeof process === "undefined") return;
255
262
  if (process.env?.NODE_ENV === "production") return;