@pluv/crdt-yjs 3.2.0 → 3.2.1

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-yjs@3.2.0 build /home/runner/work/pluv/pluv/packages/crdt-yjs
2
+ > @pluv/crdt-yjs@3.2.1 build /home/runner/work/pluv/pluv/packages/crdt-yjs
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
- ESM dist/index.mjs 17.12 KB
12
- ESM ⚡️ Build success in 69ms
13
- CJS dist/index.js 18.03 KB
14
- CJS ⚡️ Build success in 94ms
11
+ CJS dist/index.js 19.19 KB
12
+ CJS ⚡️ Build success in 112ms
13
+ ESM dist/index.mjs 18.28 KB
14
+ ESM ⚡️ Build success in 112ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 4593ms
17
- DTS dist/index.d.mts 10.76 KB
18
- DTS dist/index.d.ts 10.76 KB
16
+ DTS ⚡️ Build success in 4903ms
17
+ DTS dist/index.d.mts 10.68 KB
18
+ DTS dist/index.d.ts 10.68 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @pluv/crdt-yjs
2
2
 
3
+ ## 3.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 1e0c886: Updated crdt internal private properties to use native [private elements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_elements).
8
+ - @pluv/crdt@3.2.1
9
+ - @pluv/types@3.2.1
10
+
3
11
  ## 3.2.0
4
12
 
5
13
  ### Patch Changes
@@ -238,7 +246,6 @@
238
246
  - 945c47d: Updated deprecation warnings to read that features will be removed in v3 instead of v2.
239
247
 
240
248
  Due to an [extremely unfortunate bug in changesets](https://github.com/changesets/changesets/issues/1011), minor and patch changes will create major releases. This caused an unintended v2 release that had no breaking changes. To avoid backtracking and deleting deprecated functionalities right away, the deprecation warnings have been updated so that those APIs will be removed in v3 instead of v2.
241
-
242
249
  - @pluv/crdt@2.0.2
243
250
  - @pluv/types@2.0.2
244
251
 
@@ -1359,7 +1366,6 @@
1359
1366
  ### Patch Changes
1360
1367
 
1361
1368
  - f4317ba: \* Renamed type `unstable_YObjectValue` to `YObjectValue`;
1362
-
1363
1369
  - Renamed type `unstable_YObject` to `YObject`.
1364
1370
  - Re-exported `xmlElement`, `xmlFragment` and `xmlText` from `@pluv/client`.
1365
1371
 
package/dist/index.d.mts CHANGED
@@ -86,9 +86,8 @@ declare const builder: (doc: Doc) => {
86
86
 
87
87
  type CrdtYjsDocParams<TStorage extends Record<string, YjsType<any, any>>> = (builder: YjsBuilder) => TStorage;
88
88
  declare class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> implements CrdtDocLike<Doc, TStorage> {
89
+ #private;
89
90
  value: Doc;
90
- private _storage;
91
- private _undoManager;
92
91
  constructor(params?: CrdtYjsDocParams<TStorage>);
93
92
  applyEncodedState(params: DocApplyEncodedStateParams): this;
94
93
  batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
@@ -107,8 +106,6 @@ declare class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> imp
107
106
  toJson(): InferCrdtJson<TStorage>;
108
107
  toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
109
108
  undo(): this;
110
- private _setPluvId;
111
- private _warn;
112
109
  }
113
110
 
114
111
  declare class CrdtYjsDocFactory<TStorage extends Record<string, YjsType<any, any>> = {}> extends AbstractCrdtDocFactory<Doc, TStorage> {
package/dist/index.d.ts CHANGED
@@ -86,9 +86,8 @@ declare const builder: (doc: Doc) => {
86
86
 
87
87
  type CrdtYjsDocParams<TStorage extends Record<string, YjsType<any, any>>> = (builder: YjsBuilder) => TStorage;
88
88
  declare class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> implements CrdtDocLike<Doc, TStorage> {
89
+ #private;
89
90
  value: Doc;
90
- private _storage;
91
- private _undoManager;
92
91
  constructor(params?: CrdtYjsDocParams<TStorage>);
93
92
  applyEncodedState(params: DocApplyEncodedStateParams): this;
94
93
  batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
@@ -107,8 +106,6 @@ declare class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> imp
107
106
  toJson(): InferCrdtJson<TStorage>;
108
107
  toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
109
108
  undo(): this;
110
- private _setPluvId;
111
- private _warn;
112
109
  }
113
110
 
114
111
  declare class CrdtYjsDocFactory<TStorage extends Record<string, YjsType<any, any>> = {}> extends AbstractCrdtDocFactory<Doc, TStorage> {
package/dist/index.js CHANGED
@@ -7,6 +7,9 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __typeError = (msg) => {
11
+ throw TypeError(msg);
12
+ };
10
13
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
14
  var __spreadValues = (a, b) => {
12
15
  for (var prop in b || (b = {}))
@@ -33,6 +36,11 @@ var __copyProps = (to, from, except, desc) => {
33
36
  return to;
34
37
  };
35
38
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
40
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
41
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
42
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
43
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
36
44
 
37
45
  // src/index.ts
38
46
  var index_exports = {};
@@ -260,17 +268,20 @@ var builder = (doc2) => {
260
268
  // src/doc/CrdtYjsDoc.ts
261
269
  var MERGE_INTERVAL_MS = 1e3;
262
270
  var PLUV_ID_FIELD = "__$pluv";
271
+ var __storage, __undoManager, _CrdtYjsDoc_instances, _setPluvId_fn;
263
272
  var CrdtYjsDoc = class {
264
273
  constructor(params = () => ({})) {
274
+ __privateAdd(this, _CrdtYjsDoc_instances);
265
275
  this.value = new import_yjs3.Doc();
266
- this._undoManager = null;
276
+ __privateAdd(this, __storage);
277
+ __privateAdd(this, __undoManager, null);
267
278
  const storage = params(builder(this.value));
268
279
  const keys = this.value.share.keys().reduce((set, key) => set.add(key), /* @__PURE__ */ new Set());
269
- this._storage = Object.entries(storage).reduce(
280
+ __privateSet(this, __storage, Object.entries(storage).reduce(
270
281
  (acc, [key, node]) => keys.has(key) ? __spreadProps(__spreadValues({}, acc), { [key]: node }) : acc,
271
282
  {}
272
- );
273
- if (!!Object.keys(storage).length) this._setPluvId();
283
+ ));
284
+ if (!!Object.keys(storage).length) __privateMethod(this, _CrdtYjsDoc_instances, _setPluvId_fn).call(this);
274
285
  }
275
286
  applyEncodedState(params) {
276
287
  const { origin, update } = params;
@@ -301,20 +312,20 @@ var CrdtYjsDoc = class {
301
312
  }
302
313
  canRedo() {
303
314
  var _a;
304
- return !!((_a = this._undoManager) == null ? void 0 : _a.canRedo());
315
+ return !!((_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.canRedo());
305
316
  }
306
317
  canUndo() {
307
318
  var _a;
308
- return !!((_a = this._undoManager) == null ? void 0 : _a.canUndo());
319
+ return !!((_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.canUndo());
309
320
  }
310
321
  destroy() {
311
322
  var _a;
312
- (_a = this._undoManager) == null ? void 0 : _a.destroy();
323
+ (_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.destroy();
313
324
  this.value.destroy();
314
325
  }
315
326
  get(type) {
316
- if (typeof type === "undefined") return this._storage;
317
- return this._storage[type];
327
+ if (typeof type === "undefined") return __privateGet(this, __storage);
328
+ return __privateGet(this, __storage)[type];
318
329
  }
319
330
  getEncodedState() {
320
331
  return (0, import_js_base64.fromUint8Array)((0, import_yjs3.encodeStateAsUpdate)(this.value));
@@ -323,12 +334,12 @@ var CrdtYjsDoc = class {
323
334
  return !this.value.share.size;
324
335
  }
325
336
  rebuildStorage(reference) {
326
- const isBuilt = !!Object.keys(this._storage).length;
337
+ const isBuilt = !!Object.keys(__privateGet(this, __storage)).length;
327
338
  if (isBuilt) {
328
339
  console.warn("Attempted to rebuild storage multiple times");
329
340
  return this;
330
341
  }
331
- this._storage = Object.entries(reference).reduce((acc, [key, node]) => {
342
+ __privateSet(this, __storage, Object.entries(reference).reduce((acc, [key, node]) => {
332
343
  if (node instanceof import_yjs3.XmlElement) {
333
344
  return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getXmlElement(key) });
334
345
  }
@@ -340,12 +351,12 @@ var CrdtYjsDoc = class {
340
351
  if (node instanceof import_yjs3.Map) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getMap(key) });
341
352
  if (node instanceof import_yjs3.Text) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getText(key) });
342
353
  return acc;
343
- }, {});
354
+ }, {}));
344
355
  return this.track();
345
356
  }
346
357
  redo() {
347
358
  var _a;
348
- (_a = this._undoManager) == null ? void 0 : _a.redo();
359
+ (_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.redo();
349
360
  return this;
350
361
  }
351
362
  subscribe(listener) {
@@ -364,8 +375,8 @@ var CrdtYjsDoc = class {
364
375
  }
365
376
  track() {
366
377
  var _a;
367
- if (this._undoManager) this._undoManager.destroy();
368
- const sharedTypes = Object.values(this._storage).reduce(
378
+ if (__privateGet(this, __undoManager)) __privateGet(this, __undoManager).destroy();
379
+ const sharedTypes = Object.values(__privateGet(this, __storage)).reduce(
369
380
  (acc, type) => {
370
381
  if (type instanceof import_yjs3.Array || type instanceof import_yjs3.Map || type instanceof import_yjs3.Text || type instanceof import_yjs3.XmlElement || type instanceof import_yjs3.XmlFragment || type instanceof import_yjs3.XmlText) {
371
382
  acc.push(type);
@@ -375,11 +386,11 @@ var CrdtYjsDoc = class {
375
386
  []
376
387
  );
377
388
  if (!sharedTypes.length) {
378
- (_a = this._undoManager) == null ? void 0 : _a.destroy();
379
- this._undoManager = null;
389
+ (_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.destroy();
390
+ __privateSet(this, __undoManager, null);
380
391
  return this;
381
392
  }
382
- this._undoManager = new import_yjs3.UndoManager(sharedTypes, { captureTimeout: MERGE_INTERVAL_MS });
393
+ __privateSet(this, __undoManager, new import_yjs3.UndoManager(sharedTypes, { captureTimeout: MERGE_INTERVAL_MS }));
383
394
  return this;
384
395
  }
385
396
  transact(fn) {
@@ -387,28 +398,25 @@ var CrdtYjsDoc = class {
387
398
  return this;
388
399
  }
389
400
  toJson(type) {
390
- if (typeof type === "string") return this._storage[type].toJSON();
391
- return Object.entries(this._storage).reduce(
401
+ if (typeof type === "string") return __privateGet(this, __storage)[type].toJSON();
402
+ return Object.entries(__privateGet(this, __storage)).reduce(
392
403
  (acc, [key, value]) => __spreadProps(__spreadValues({}, acc), { [key]: value.toJSON() }),
393
404
  {}
394
405
  );
395
406
  }
396
407
  undo() {
397
408
  var _a;
398
- (_a = this._undoManager) == null ? void 0 : _a.undo();
409
+ (_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.undo();
399
410
  return this;
400
411
  }
401
- _setPluvId() {
402
- const text2 = this.value.getText(PLUV_ID_FIELD);
403
- const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
404
- text2.insert(0, id);
405
- }
406
- _warn(...data) {
407
- var _a;
408
- if (typeof process === "undefined") return;
409
- if (((_a = process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
410
- console.log(...data);
411
- }
412
+ };
413
+ __storage = new WeakMap();
414
+ __undoManager = new WeakMap();
415
+ _CrdtYjsDoc_instances = new WeakSet();
416
+ _setPluvId_fn = function() {
417
+ const text2 = this.value.getText(PLUV_ID_FIELD);
418
+ const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
419
+ text2.insert(0, id);
412
420
  };
413
421
 
414
422
  // src/doc/CrdtYjsDocFactory.ts
package/dist/index.mjs CHANGED
@@ -4,6 +4,9 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __typeError = (msg) => {
8
+ throw TypeError(msg);
9
+ };
7
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
11
  var __spreadValues = (a, b) => {
9
12
  for (var prop in b || (b = {}))
@@ -21,6 +24,11 @@ var __export = (target, all) => {
21
24
  for (var name in all)
22
25
  __defProp(target, name, { get: all[name], enumerable: true });
23
26
  };
27
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
28
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
29
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
30
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
31
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
24
32
 
25
33
  // src/yjs.ts
26
34
  var yjs_exports = {};
@@ -255,17 +263,20 @@ var builder = (doc2) => {
255
263
  // src/doc/CrdtYjsDoc.ts
256
264
  var MERGE_INTERVAL_MS = 1e3;
257
265
  var PLUV_ID_FIELD = "__$pluv";
266
+ var __storage, __undoManager, _CrdtYjsDoc_instances, _setPluvId_fn;
258
267
  var CrdtYjsDoc = class {
259
268
  constructor(params = () => ({})) {
269
+ __privateAdd(this, _CrdtYjsDoc_instances);
260
270
  this.value = new YDoc2();
261
- this._undoManager = null;
271
+ __privateAdd(this, __storage);
272
+ __privateAdd(this, __undoManager, null);
262
273
  const storage = params(builder(this.value));
263
274
  const keys = this.value.share.keys().reduce((set, key) => set.add(key), /* @__PURE__ */ new Set());
264
- this._storage = Object.entries(storage).reduce(
275
+ __privateSet(this, __storage, Object.entries(storage).reduce(
265
276
  (acc, [key, node]) => keys.has(key) ? __spreadProps(__spreadValues({}, acc), { [key]: node }) : acc,
266
277
  {}
267
- );
268
- if (!!Object.keys(storage).length) this._setPluvId();
278
+ ));
279
+ if (!!Object.keys(storage).length) __privateMethod(this, _CrdtYjsDoc_instances, _setPluvId_fn).call(this);
269
280
  }
270
281
  applyEncodedState(params) {
271
282
  const { origin, update } = params;
@@ -296,20 +307,20 @@ var CrdtYjsDoc = class {
296
307
  }
297
308
  canRedo() {
298
309
  var _a;
299
- return !!((_a = this._undoManager) == null ? void 0 : _a.canRedo());
310
+ return !!((_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.canRedo());
300
311
  }
301
312
  canUndo() {
302
313
  var _a;
303
- return !!((_a = this._undoManager) == null ? void 0 : _a.canUndo());
314
+ return !!((_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.canUndo());
304
315
  }
305
316
  destroy() {
306
317
  var _a;
307
- (_a = this._undoManager) == null ? void 0 : _a.destroy();
318
+ (_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.destroy();
308
319
  this.value.destroy();
309
320
  }
310
321
  get(type) {
311
- if (typeof type === "undefined") return this._storage;
312
- return this._storage[type];
322
+ if (typeof type === "undefined") return __privateGet(this, __storage);
323
+ return __privateGet(this, __storage)[type];
313
324
  }
314
325
  getEncodedState() {
315
326
  return fromUint8Array(encodeStateAsUpdate(this.value));
@@ -318,12 +329,12 @@ var CrdtYjsDoc = class {
318
329
  return !this.value.share.size;
319
330
  }
320
331
  rebuildStorage(reference) {
321
- const isBuilt = !!Object.keys(this._storage).length;
332
+ const isBuilt = !!Object.keys(__privateGet(this, __storage)).length;
322
333
  if (isBuilt) {
323
334
  console.warn("Attempted to rebuild storage multiple times");
324
335
  return this;
325
336
  }
326
- this._storage = Object.entries(reference).reduce((acc, [key, node]) => {
337
+ __privateSet(this, __storage, Object.entries(reference).reduce((acc, [key, node]) => {
327
338
  if (node instanceof YXmlElement2) {
328
339
  return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getXmlElement(key) });
329
340
  }
@@ -335,12 +346,12 @@ var CrdtYjsDoc = class {
335
346
  if (node instanceof YMap2) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getMap(key) });
336
347
  if (node instanceof YText2) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getText(key) });
337
348
  return acc;
338
- }, {});
349
+ }, {}));
339
350
  return this.track();
340
351
  }
341
352
  redo() {
342
353
  var _a;
343
- (_a = this._undoManager) == null ? void 0 : _a.redo();
354
+ (_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.redo();
344
355
  return this;
345
356
  }
346
357
  subscribe(listener) {
@@ -359,8 +370,8 @@ var CrdtYjsDoc = class {
359
370
  }
360
371
  track() {
361
372
  var _a;
362
- if (this._undoManager) this._undoManager.destroy();
363
- const sharedTypes = Object.values(this._storage).reduce(
373
+ if (__privateGet(this, __undoManager)) __privateGet(this, __undoManager).destroy();
374
+ const sharedTypes = Object.values(__privateGet(this, __storage)).reduce(
364
375
  (acc, type) => {
365
376
  if (type instanceof YArray3 || type instanceof YMap2 || type instanceof YText2 || type instanceof YXmlElement2 || type instanceof YXmlFragment2 || type instanceof YXmlText2) {
366
377
  acc.push(type);
@@ -370,11 +381,11 @@ var CrdtYjsDoc = class {
370
381
  []
371
382
  );
372
383
  if (!sharedTypes.length) {
373
- (_a = this._undoManager) == null ? void 0 : _a.destroy();
374
- this._undoManager = null;
384
+ (_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.destroy();
385
+ __privateSet(this, __undoManager, null);
375
386
  return this;
376
387
  }
377
- this._undoManager = new UndoManager(sharedTypes, { captureTimeout: MERGE_INTERVAL_MS });
388
+ __privateSet(this, __undoManager, new UndoManager(sharedTypes, { captureTimeout: MERGE_INTERVAL_MS }));
378
389
  return this;
379
390
  }
380
391
  transact(fn) {
@@ -382,28 +393,25 @@ var CrdtYjsDoc = class {
382
393
  return this;
383
394
  }
384
395
  toJson(type) {
385
- if (typeof type === "string") return this._storage[type].toJSON();
386
- return Object.entries(this._storage).reduce(
396
+ if (typeof type === "string") return __privateGet(this, __storage)[type].toJSON();
397
+ return Object.entries(__privateGet(this, __storage)).reduce(
387
398
  (acc, [key, value]) => __spreadProps(__spreadValues({}, acc), { [key]: value.toJSON() }),
388
399
  {}
389
400
  );
390
401
  }
391
402
  undo() {
392
403
  var _a;
393
- (_a = this._undoManager) == null ? void 0 : _a.undo();
404
+ (_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.undo();
394
405
  return this;
395
406
  }
396
- _setPluvId() {
397
- const text2 = this.value.getText(PLUV_ID_FIELD);
398
- const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
399
- text2.insert(0, id);
400
- }
401
- _warn(...data) {
402
- var _a;
403
- if (typeof process === "undefined") return;
404
- if (((_a = process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
405
- console.log(...data);
406
- }
407
+ };
408
+ __storage = new WeakMap();
409
+ __undoManager = new WeakMap();
410
+ _CrdtYjsDoc_instances = new WeakSet();
411
+ _setPluvId_fn = function() {
412
+ const text2 = this.value.getText(PLUV_ID_FIELD);
413
+ const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
414
+ text2.insert(0, id);
407
415
  };
408
416
 
409
417
  // src/doc/CrdtYjsDocFactory.ts
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@pluv/crdt-yjs",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "yjs for @pluv/io",
5
- "author": "leedavidcs",
5
+ "author": {
6
+ "email": "david@pluv.io",
7
+ "name": "i3dly",
8
+ "url": "https://github.com/i3dly"
9
+ },
6
10
  "license": "MIT",
7
11
  "homepage": "https://github.com/pluv-io/pluv",
8
12
  "repository": {
@@ -17,22 +21,22 @@
17
21
  "access": "public"
18
22
  },
19
23
  "dependencies": {
20
- "@types/node": "^22.15.30",
24
+ "@types/node": "^24.0.14",
21
25
  "js-base64": "^3.7.7",
22
- "lib0": "^0.2.108",
23
- "@pluv/crdt": "^3.2.0",
24
- "@pluv/types": "^3.2.0"
26
+ "lib0": "^0.2.114",
27
+ "@pluv/crdt": "^3.2.1",
28
+ "@pluv/types": "^3.2.1"
25
29
  },
26
30
  "peerDependencies": {
27
31
  "yjs": "^13.0.0"
28
32
  },
29
33
  "devDependencies": {
30
- "eslint": "^9.28.0",
34
+ "eslint": "^9.31.0",
31
35
  "tsup": "^8.5.0",
32
36
  "typescript": "^5.8.3",
33
37
  "yjs": "^13.6.27",
34
- "@pluv/tsconfig": "^3.2.0",
35
- "eslint-config-pluv": "^3.2.0"
38
+ "@pluv/tsconfig": "^3.2.1",
39
+ "eslint-config-pluv": "^3.2.1"
36
40
  },
37
41
  "scripts": {
38
42
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -36,18 +36,18 @@ export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>>
36
36
  {
37
37
  public value: YDoc = new YDoc();
38
38
 
39
- private _storage: TStorage;
40
- private _undoManager: UndoManager | null = null;
39
+ #_storage: TStorage;
40
+ #_undoManager: UndoManager | null = null;
41
41
 
42
42
  constructor(params: CrdtYjsDocParams<TStorage> = () => ({}) as TStorage) {
43
43
  const storage = params(builder(this.value));
44
44
  const keys = this.value.share.keys().reduce((set, key) => set.add(key), new Set<string>());
45
45
 
46
- this._storage = Object.entries(storage).reduce(
46
+ this.#_storage = Object.entries(storage).reduce(
47
47
  (acc, [key, node]) => (keys.has(key) ? { ...acc, [key]: node } : acc),
48
48
  {} as TStorage,
49
49
  );
50
- if (!!Object.keys(storage).length) this._setPluvId();
50
+ if (!!Object.keys(storage).length) this.#_setPluvId();
51
51
  }
52
52
 
53
53
  public applyEncodedState(params: DocApplyEncodedStateParams): this {
@@ -90,24 +90,24 @@ export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>>
90
90
  }
91
91
 
92
92
  public canRedo(): boolean {
93
- return !!this._undoManager?.canRedo();
93
+ return !!this.#_undoManager?.canRedo();
94
94
  }
95
95
 
96
96
  public canUndo(): boolean {
97
- return !!this._undoManager?.canUndo();
97
+ return !!this.#_undoManager?.canUndo();
98
98
  }
99
99
 
100
100
  public destroy(): void {
101
- this._undoManager?.destroy();
101
+ this.#_undoManager?.destroy();
102
102
  this.value.destroy();
103
103
  }
104
104
 
105
105
  public get(key?: undefined): TStorage;
106
106
  public get<TKey extends keyof TStorage>(type: TKey): TStorage[TKey];
107
107
  public get<TKey extends keyof TStorage>(type?: TKey): TStorage | TStorage[TKey] {
108
- if (typeof type === "undefined") return this._storage;
108
+ if (typeof type === "undefined") return this.#_storage;
109
109
 
110
- return this._storage[type as TKey];
110
+ return this.#_storage[type as TKey];
111
111
  }
112
112
 
113
113
  public getEncodedState(): string {
@@ -119,14 +119,14 @@ export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>>
119
119
  }
120
120
 
121
121
  public rebuildStorage(reference: TStorage): this {
122
- const isBuilt = !!Object.keys(this._storage).length;
122
+ const isBuilt = !!Object.keys(this.#_storage).length;
123
123
 
124
124
  if (isBuilt) {
125
125
  console.warn("Attempted to rebuild storage multiple times");
126
126
  return this;
127
127
  }
128
128
 
129
- this._storage = Object.entries(reference).reduce((acc, [key, node]) => {
129
+ this.#_storage = Object.entries(reference).reduce((acc, [key, node]) => {
130
130
  /**
131
131
  * @description It is important that the XML shared-types be checked before the others
132
132
  * because they extend off the non-xml types (thereby you can mistakenly identify the
@@ -151,7 +151,7 @@ export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>>
151
151
  }
152
152
 
153
153
  public redo(): this {
154
- this._undoManager?.redo();
154
+ this.#_undoManager?.redo();
155
155
 
156
156
  return this;
157
157
  }
@@ -176,9 +176,9 @@ export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>>
176
176
  }
177
177
 
178
178
  public track(): this {
179
- if (this._undoManager) this._undoManager.destroy();
179
+ if (this.#_undoManager) this.#_undoManager.destroy();
180
180
 
181
- const sharedTypes = Object.values(this._storage).reduce<YjsType<AbstractType<any>, any>[]>(
181
+ const sharedTypes = Object.values(this.#_storage).reduce<YjsType<AbstractType<any>, any>[]>(
182
182
  (acc, type) => {
183
183
  if (
184
184
  type instanceof YArray ||
@@ -197,13 +197,13 @@ export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>>
197
197
  );
198
198
 
199
199
  if (!sharedTypes.length) {
200
- this._undoManager?.destroy();
201
- this._undoManager = null;
200
+ this.#_undoManager?.destroy();
201
+ this.#_undoManager = null;
202
202
 
203
203
  return this;
204
204
  }
205
205
 
206
- this._undoManager = new UndoManager(sharedTypes, { captureTimeout: MERGE_INTERVAL_MS });
206
+ this.#_undoManager = new UndoManager(sharedTypes, { captureTimeout: MERGE_INTERVAL_MS });
207
207
 
208
208
  return this;
209
209
  }
@@ -217,30 +217,24 @@ export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>>
217
217
  public toJson(): InferCrdtJson<TStorage>;
218
218
  public toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
219
219
  public toJson<TKey extends keyof TStorage>(type?: TKey) {
220
- if (typeof type === "string") return this._storage[type].toJSON();
220
+ if (typeof type === "string") return this.#_storage[type].toJSON();
221
221
 
222
- return Object.entries(this._storage).reduce(
222
+ return Object.entries(this.#_storage).reduce(
223
223
  (acc, [key, value]) => ({ ...(acc as any), [key]: value.toJSON() }),
224
224
  {} as InferCrdtJson<TStorage>,
225
225
  );
226
226
  }
227
227
 
228
228
  public undo(): this {
229
- this._undoManager?.undo();
229
+ this.#_undoManager?.undo();
230
230
 
231
231
  return this;
232
232
  }
233
233
 
234
- private _setPluvId() {
234
+ #_setPluvId() {
235
235
  const text = this.value.getText(PLUV_ID_FIELD);
236
236
  const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
237
237
 
238
238
  text.insert(0, id);
239
239
  }
240
-
241
- private _warn(...data: any[]) {
242
- if (typeof process === "undefined") return;
243
- if (process.env?.NODE_ENV === "production") return;
244
- console.log(...data);
245
- }
246
240
  }