@pluv/crdt-yjs 0.3.8 → 0.4.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.
@@ -1,17 +1,17 @@
1
1
 
2
- > @pluv/crdt-yjs@0.3.8 build /home/runner/work/pluv/pluv/packages/crdt-yjs
2
+ > @pluv/crdt-yjs@0.4.0 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
6
6
  CLI Using tsconfig: tsconfig.json
7
- CLI tsup v6.7.0
7
+ CLI tsup v7.0.0
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 3.57 KB
12
- ESM ⚡️ Build success in 77ms
13
- CJS dist/index.js 4.77 KB
14
- CJS ⚡️ Build success in 79ms
11
+ ESM dist/index.mjs 3.68 KB
12
+ ESM ⚡️ Build success in 95ms
13
+ CJS dist/index.js 4.87 KB
14
+ CJS ⚡️ Build success in 96ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 1561ms
17
- DTS dist/index.d.ts 3.10 KB
16
+ DTS ⚡️ Build success in 2333ms
17
+ DTS dist/index.d.ts 3.17 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # @pluv/crdt-yjs
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 829d31b: Added support for defining persistant frontend storage for rooms via a new `addons` option on rooms.
8
+
9
+ This also introduces the first new addon `@pluv/addon-indexeddb`, which is more-or-less the equivalent to `y-indexeddb` which you can install like so:
10
+
11
+ ```
12
+ npm install @pluv/addon-indexeddb
13
+ ```
14
+
15
+ To use this new addon, simply pass it to options when creating a room:
16
+
17
+ ```ts
18
+ import { addonIndexedDB } from "@pluv/addon-indexeddb";
19
+ import { createClient } from "@pluv/client";
20
+
21
+ const client = createClient({
22
+ // ...
23
+ });
24
+
25
+ const room = client.createRoom("my-new-room", {
26
+ addons: [
27
+ // Define your addons in an array like so
28
+ addonIndexedDB(),
29
+ ],
30
+ });
31
+ ```
32
+
33
+ Or when using `@pluv/react`:
34
+
35
+ ```ts
36
+ const PluvRoom = createRoomBundle({
37
+ // ...
38
+ addons: [
39
+ // Define your addons in an array like so
40
+ addonIndexedDB(),
41
+ ],
42
+ });
43
+ ```
44
+
45
+ ### Patch Changes
46
+
47
+ - 8d11672: bumped dependencies to latest
48
+ - Updated dependencies [8d11672]
49
+ - @pluv/types@0.2.1
50
+
3
51
  ## 0.3.8
4
52
 
5
53
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -29,8 +29,9 @@ declare class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
29
29
  encodeStateAsUpdate(): string;
30
30
  get<TKey extends keyof T>(key: TKey): T[TKey];
31
31
  getSharedTypes(): T;
32
- subscribe(fn: (update: string, origin: string, doc: Doc, transaction: Transaction) => void): () => void;
32
+ subscribe(fn: (update: string, origin: any, doc: Doc, transaction: Transaction) => void): () => void;
33
33
  toJSON(): InferYjsDocJson<this>;
34
+ transact(fn: (transaction: Transaction) => void, origin?: any): void;
34
35
  static fromUint8Array(u8a: Uint8Array): string;
35
36
  static toUint8Array(str: string): Uint8Array;
36
37
  }
package/dist/index.js CHANGED
@@ -60,7 +60,7 @@ var array = (value = []) => {
60
60
  // src/doc.ts
61
61
  var import_js_base64 = require("js-base64");
62
62
  var import_yjs2 = require("yjs");
63
- var YjsDoc = class {
63
+ var YjsDoc = class _YjsDoc {
64
64
  constructor(value) {
65
65
  this.value = new import_yjs2.Doc();
66
66
  if (!value)
@@ -96,7 +96,7 @@ var YjsDoc = class {
96
96
  );
97
97
  }
98
98
  subscribe(fn) {
99
- const _fn = (update, origin, doc2, transaction) => fn(YjsDoc.fromUint8Array(update), origin, doc2, transaction);
99
+ const _fn = (update, origin, doc2, transaction) => fn(_YjsDoc.fromUint8Array(update), origin, doc2, transaction);
100
100
  this.value.on("update", _fn);
101
101
  return () => {
102
102
  this.value.off("update", _fn);
@@ -105,6 +105,11 @@ var YjsDoc = class {
105
105
  toJSON() {
106
106
  return this._storage.toJSON();
107
107
  }
108
+ transact(fn, origin) {
109
+ this.value.transact((tx) => {
110
+ fn(tx);
111
+ }, origin);
112
+ }
108
113
  static fromUint8Array(u8a) {
109
114
  return (0, import_js_base64.fromUint8Array)(u8a);
110
115
  }
package/dist/index.mjs CHANGED
@@ -28,8 +28,12 @@ var array = (value = []) => {
28
28
 
29
29
  // src/doc.ts
30
30
  import { fromUint8Array, toUint8Array } from "js-base64";
31
- import { applyUpdate, Doc as YDoc, encodeStateAsUpdate } from "yjs";
32
- var YjsDoc = class {
31
+ import {
32
+ Doc as YDoc,
33
+ applyUpdate,
34
+ encodeStateAsUpdate
35
+ } from "yjs";
36
+ var YjsDoc = class _YjsDoc {
33
37
  constructor(value) {
34
38
  this.value = new YDoc();
35
39
  if (!value)
@@ -65,7 +69,7 @@ var YjsDoc = class {
65
69
  );
66
70
  }
67
71
  subscribe(fn) {
68
- const _fn = (update, origin, doc2, transaction) => fn(YjsDoc.fromUint8Array(update), origin, doc2, transaction);
72
+ const _fn = (update, origin, doc2, transaction) => fn(_YjsDoc.fromUint8Array(update), origin, doc2, transaction);
69
73
  this.value.on("update", _fn);
70
74
  return () => {
71
75
  this.value.off("update", _fn);
@@ -74,6 +78,11 @@ var YjsDoc = class {
74
78
  toJSON() {
75
79
  return this._storage.toJSON();
76
80
  }
81
+ transact(fn, origin) {
82
+ this.value.transact((tx) => {
83
+ fn(tx);
84
+ }, origin);
85
+ }
77
86
  static fromUint8Array(u8a) {
78
87
  return fromUint8Array(u8a);
79
88
  }
@@ -86,15 +95,15 @@ var doc = (value) => {
86
95
  };
87
96
 
88
97
  // src/map.ts
89
- import { Map as YMap } from "yjs";
98
+ import { Map as YMap2 } from "yjs";
90
99
  var map = (value = []) => {
91
- return new YMap(value);
100
+ return new YMap2(value);
92
101
  };
93
102
 
94
103
  // src/object.ts
95
- import { Map as YMap2 } from "yjs";
104
+ import { Map as YMap3 } from "yjs";
96
105
  var object = (value) => {
97
- return new YMap2(Object.entries(value));
106
+ return new YMap3(Object.entries(value));
98
107
  };
99
108
 
100
109
  // src/text.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/crdt-yjs",
3
- "version": "0.3.8",
3
+ "version": "0.4.0",
4
4
  "description": "yjs for @pluv/io",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -17,18 +17,20 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
+ "@playwright/test": "^1.35.1",
21
+ "@types/react": "^18.2.13",
20
22
  "js-base64": "^3.7.5",
21
- "@pluv/types": "^0.2.0"
23
+ "@pluv/types": "^0.2.1"
22
24
  },
23
25
  "peerDependencies": {
24
26
  "yjs": "^13.0.0"
25
27
  },
26
28
  "devDependencies": {
27
- "tsup": "^6.7.0",
28
- "typescript": "^5.0.4",
29
- "yjs": "^13.6.1",
30
- "@pluv/tsconfig": "^0.1.6",
31
- "eslint-config-pluv": "^0.1.12"
29
+ "tsup": "^7.0.0",
30
+ "typescript": "^5.1.3",
31
+ "yjs": "^13.6.4",
32
+ "@pluv/tsconfig": "^0.1.7",
33
+ "eslint-config-pluv": "^0.1.13"
32
34
  },
33
35
  "scripts": {
34
36
  "build": "tsup src/index.ts --format esm,cjs --dts",
package/src/doc.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { fromUint8Array, toUint8Array } from "js-base64";
2
- import type { AbstractType, Map as YMap, Transaction } from "yjs";
3
- import { applyUpdate, Doc as YDoc, encodeStateAsUpdate } from "yjs";
2
+ import {
3
+ AbstractType,
4
+ Transaction,
5
+ Doc as YDoc,
6
+ Map as YMap,
7
+ applyUpdate,
8
+ encodeStateAsUpdate,
9
+ } from "yjs";
4
10
  import type { InferYjsDocJson } from "./types";
5
11
 
6
12
  export class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
@@ -56,14 +62,14 @@ export class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
56
62
  public subscribe(
57
63
  fn: (
58
64
  update: string,
59
- origin: string,
65
+ origin: any,
60
66
  doc: YDoc,
61
67
  transaction: Transaction
62
68
  ) => void
63
69
  ): () => void {
64
70
  const _fn = (
65
71
  update: Uint8Array,
66
- origin: string,
72
+ origin: any,
67
73
  doc: YDoc,
68
74
  transaction: Transaction
69
75
  ) => fn(YjsDoc.fromUint8Array(update), origin, doc, transaction);
@@ -79,6 +85,15 @@ export class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
79
85
  return this._storage.toJSON() as InferYjsDocJson<this>;
80
86
  }
81
87
 
88
+ public transact(
89
+ fn: (transaction: Transaction) => void,
90
+ origin?: any
91
+ ): void {
92
+ this.value.transact((tx) => {
93
+ fn(tx);
94
+ }, origin);
95
+ }
96
+
82
97
  public static fromUint8Array(u8a: Uint8Array): string {
83
98
  return fromUint8Array(u8a);
84
99
  }