@pluv/crdt-yjs 0.1.3 → 0.3.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.1.3 build /home/runner/work/pluv/pluv/packages/crdt-yjs
2
+ > @pluv/crdt-yjs@0.3.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.5.0
7
+ CLI tsup v6.6.3
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 2.88 KB
12
- ESM ⚡️ Build success in 70ms
13
- CJS dist/index.js 4.01 KB
14
- CJS ⚡️ Build success in 71ms
11
+ CJS dist/index.js 4.69 KB
12
+ CJS ⚡️ Build success in 54ms
13
+ ESM dist/index.mjs 3.50 KB
14
+ ESM ⚡️ Build success in 55ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 1340ms
17
- DTS dist/index.d.ts 2.61 KB
16
+ DTS ⚡️ Build success in 1551ms
17
+ DTS dist/index.d.ts 3.09 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @pluv/crdt-yjs
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 327a6ef: renamed y.unstable\_\_object to y.object
8
+
9
+ ### Patch Changes
10
+
11
+ - 8bf62cb: bumped dependencies
12
+ - 7e52685: Bumped dependencies
13
+ - b1cb325: Updated dependencies
14
+ - 8e97fb2: Updated dependencies
15
+ - Updated dependencies [8bf62cb]
16
+ - Updated dependencies [7e52685]
17
+ - Updated dependencies [8e97fb2]
18
+ - @pluv/types@0.1.3
19
+
20
+ ## 0.2.0
21
+
22
+ ### Minor Changes
23
+
24
+ - 6858682: Added support for yjs xml types including XmlElement, XmlFragment and XmlText
25
+
26
+ ### Patch Changes
27
+
28
+ - @pluv/types@0.1.2
29
+
3
30
  ## 0.1.3
4
31
 
5
32
  ### Patch Changes
package/README.md CHANGED
@@ -26,7 +26,9 @@
26
26
  <img src="https://img.shields.io/badge/docs-coming%20soon!-blue" alt="Docs coming soon!" />
27
27
  </p>
28
28
 
29
- <img src="https://github.com/pluv-io/pluv/blob/master/assets/demo-events.gif?raw=true" alt="Demo" />
29
+ <p align="center">
30
+ <img src="https://github.com/pluv-io/pluv/blob/master/assets/demo-events.gif?raw=true" alt="Demo" />
31
+ </p>
30
32
 
31
33
  ## `@pluv/crdt-yjs`
32
34
 
@@ -52,6 +54,11 @@ pnpm add @pluv/crdt-yjs yjs
52
54
 
53
55
  ```ts
54
56
  import { createClient, y } from "@pluv/client";
57
+ import type {
58
+ Array as YArray,
59
+ Map as YMap,
60
+ XmlFragment as YXmlFragment,
61
+ } from "yjs";
55
62
  import { z } from "zod";
56
63
  // Import the PluvIO instance as a type from your server file
57
64
  import { type io } from "./server";
@@ -61,13 +68,21 @@ const client = createClient<typeof io>({ /* client config here */ });
61
68
  type Presence = {};
62
69
 
63
70
  interface Storage {
64
- groceryList: { [food: string]: number };
65
- messages: readonly { name: string; message: string }[]
71
+ editor: YXmlFragment;
72
+ groceryList: YMap<string, number>;
73
+ messages: YArray<{ name: string; message: string }>;
66
74
  }
67
75
 
68
76
  // Create a room to join
69
77
  const room = client.createRoom<Presence, Storage>("my-room", {
70
78
  initialStorage: () => ({
79
+ editor: y.xmlFragment({
80
+ children: [
81
+ y.xmlElement("paragraph", {
82
+ children: [y.xmlText("Hello World!")],
83
+ }),
84
+ ]
85
+ }),
71
86
  groceryList: y.map([
72
87
  ["apricots", 2],
73
88
  ["bread", 3],
package/dist/index.d.ts CHANGED
@@ -1,9 +1,25 @@
1
- import { Array, AbstractType, Doc, Transaction, Map, Text } from 'yjs';
1
+ import { Array, Map, AbstractType, Text, XmlElement, XmlFragment, XmlText, Doc, Transaction } from 'yjs';
2
2
  export { AbstractType, Array, Map, Text } from 'yjs';
3
- import { JsonObject, JsonPrimitive } from '@pluv/types';
3
+ import { JsonPrimitive } from '@pluv/types';
4
4
 
5
5
  declare const array: <T extends unknown>(value?: readonly T[]) => Array<T>;
6
6
 
7
+ type unstable__YObjectValue = Record<string, NonNullable<JsonPrimitive> | AbstractType<any>>;
8
+ type unstable__YObject<T extends unstable__YObjectValue> = Map<T[keyof T]> & {
9
+ __$type: T;
10
+ };
11
+ declare const object: <T extends unstable__YObjectValue = {}>(value: T) => unstable__YObject<T>;
12
+
13
+ type InferYjsDocJson<TDoc extends YjsDoc<any>> = TDoc extends YjsDoc<infer ITypes> ? {
14
+ [P in keyof ITypes]: InferYjsSharedTypeJson<ITypes[P]>;
15
+ } : never;
16
+ type InferYjsDocSharedType<TDoc extends YjsDoc<any>, TKey extends keyof InferYjsDocSharedTypes<TDoc> = keyof InferYjsDocSharedTypes<TDoc>> = InferYjsDocSharedTypes<TDoc>[TKey];
17
+ type InferYjsDocSharedTypeJson<TDoc extends YjsDoc<any>, TKey extends keyof InferYjsDocSharedTypes<TDoc> = keyof InferYjsDocSharedTypes<TDoc>> = InferYjsSharedTypeJson<InferYjsDocSharedTypes<TDoc>[TKey]>;
18
+ type InferYjsDocSharedTypes<TDoc extends YjsDoc<any>> = TDoc extends YjsDoc<infer ITypes> ? ITypes : never;
19
+ type InferYjsSharedTypeJson<TShared extends unknown> = TShared extends AbstractType<any> ? TShared extends Array<infer IItem> ? readonly InferYjsSharedTypeJson<IItem>[] : TShared extends unstable__YObject<infer IObject> ? {
20
+ [P in keyof IObject]: InferYjsSharedTypeJson<IObject[P]>;
21
+ } : TShared extends Map<infer IItem> ? Record<string, InferYjsSharedTypeJson<IItem>> : TShared extends Text | XmlElement | XmlFragment | XmlText ? string : never : TShared;
22
+
7
23
  declare class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
8
24
  value: Doc;
9
25
  private get _storage();
@@ -14,7 +30,7 @@ declare class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
14
30
  get<TKey extends keyof T>(key: TKey): T[TKey];
15
31
  getSharedTypes(): T;
16
32
  subscribe(fn: (update: string, origin: string, doc: Doc, transaction: Transaction) => void): () => void;
17
- toJSON(): JsonObject;
33
+ toJSON(): InferYjsDocJson<this>;
18
34
  static fromUint8Array(u8a: Uint8Array): string;
19
35
  static toUint8Array(str: string): Uint8Array;
20
36
  }
@@ -22,22 +38,18 @@ declare const doc: <T extends Record<string, AbstractType<any>> = {}>(value?: T
22
38
 
23
39
  declare const map: <T extends unknown>(value?: readonly (readonly [key: string, value: T])[]) => Map<T>;
24
40
 
25
- type unstable__YObjectValue = Record<string, NonNullable<JsonPrimitive> | AbstractType<any>>;
26
- type unstable__YObject<T extends unstable__YObjectValue> = Map<T[keyof T]> & {
27
- __$type: T;
28
- };
29
- declare const unstable__object: <T extends unstable__YObjectValue = {}>(value: T) => unstable__YObject<T>;
30
-
31
41
  declare const text: (value?: string) => Text;
32
42
 
33
- type InferYjsDocJson<TDoc extends YjsDoc<any>> = TDoc extends YjsDoc<infer ITypes> ? {
34
- [P in keyof ITypes]: InferYjsSharedTypeJson<ITypes[P]>;
35
- } : never;
36
- type InferYjsDocSharedType<TDoc extends YjsDoc<any>, TKey extends keyof InferYjsDocSharedTypes<TDoc> = keyof InferYjsDocSharedTypes<TDoc>> = InferYjsDocSharedTypes<TDoc>[TKey];
37
- type InferYjsDocSharedTypeJson<TDoc extends YjsDoc<any>, TKey extends keyof InferYjsDocSharedTypes<TDoc> = keyof InferYjsDocSharedTypes<TDoc>> = InferYjsSharedTypeJson<InferYjsDocSharedTypes<TDoc>[TKey]>;
38
- type InferYjsDocSharedTypes<TDoc extends YjsDoc<any>> = TDoc extends YjsDoc<infer ITypes> ? ITypes : never;
39
- type InferYjsSharedTypeJson<TShared extends unknown> = TShared extends AbstractType<any> ? TShared extends Array<infer IItem> ? readonly InferYjsSharedTypeJson<IItem>[] : TShared extends unstable__YObject<infer IObject> ? {
40
- [P in keyof IObject]: InferYjsSharedTypeJson<IObject[P]>;
41
- } : TShared extends Map<infer IItem> ? Record<string, InferYjsSharedTypeJson<IItem>> : TShared extends Text ? string : never : TShared;
43
+ interface XmlElementParams {
44
+ children?: readonly (XmlElement | XmlText)[];
45
+ }
46
+ declare const xmlElement: (name: string, params?: XmlElementParams) => XmlElement;
47
+
48
+ interface XmlFragmentParams {
49
+ children?: readonly (XmlElement | XmlText)[];
50
+ }
51
+ declare const xmlFragment: (params?: XmlFragmentParams) => XmlFragment;
52
+
53
+ declare const xmlText: (value?: string) => XmlText;
42
54
 
43
- export { InferYjsDocJson, InferYjsDocSharedType, InferYjsDocSharedTypeJson, InferYjsDocSharedTypes, InferYjsSharedTypeJson, YjsDoc, array, doc, map, text, unstable__YObject, unstable__object };
55
+ export { InferYjsDocJson, InferYjsDocSharedType, InferYjsDocSharedTypeJson, InferYjsDocSharedTypes, InferYjsSharedTypeJson, XmlElementParams, XmlFragmentParams, YjsDoc, array, doc, map, object, text, unstable__YObject, xmlElement, xmlFragment, xmlText };
package/dist/index.js CHANGED
@@ -41,8 +41,11 @@ __export(src_exports, {
41
41
  array: () => array,
42
42
  doc: () => doc,
43
43
  map: () => map,
44
+ object: () => object,
44
45
  text: () => text,
45
- unstable__object: () => unstable__object
46
+ xmlElement: () => xmlElement,
47
+ xmlFragment: () => xmlFragment,
48
+ xmlText: () => xmlText
46
49
  });
47
50
  module.exports = __toCommonJS(src_exports);
48
51
 
@@ -119,7 +122,7 @@ var map = (value = []) => {
119
122
 
120
123
  // src/object.ts
121
124
  var import_yjs4 = require("yjs");
122
- var unstable__object = (value) => {
125
+ var object = (value) => {
123
126
  return new import_yjs4.Map(Object.entries(value));
124
127
  };
125
128
 
@@ -128,12 +131,39 @@ var import_yjs5 = require("yjs");
128
131
  var text = (value = "") => {
129
132
  return new import_yjs5.Text(value);
130
133
  };
134
+
135
+ // src/xmlElement.ts
136
+ var import_yjs6 = require("yjs");
137
+ var xmlElement = (name, params = {}) => {
138
+ const { children = [] } = params;
139
+ const element = new import_yjs6.XmlElement(name);
140
+ element.push(children.slice());
141
+ return element;
142
+ };
143
+
144
+ // src/xmlFragment.ts
145
+ var import_yjs7 = require("yjs");
146
+ var xmlFragment = (params = {}) => {
147
+ const { children = [] } = params;
148
+ const fragment = new import_yjs7.XmlFragment();
149
+ fragment.push(children.slice());
150
+ return fragment;
151
+ };
152
+
153
+ // src/xmlText.ts
154
+ var import_yjs8 = require("yjs");
155
+ var xmlText = (value = "") => {
156
+ return new import_yjs8.XmlText(value);
157
+ };
131
158
  // Annotate the CommonJS export names for ESM import in node:
132
159
  0 && (module.exports = {
133
160
  YjsDoc,
134
161
  array,
135
162
  doc,
136
163
  map,
164
+ object,
137
165
  text,
138
- unstable__object
166
+ xmlElement,
167
+ xmlFragment,
168
+ xmlText
139
169
  });
package/dist/index.mjs CHANGED
@@ -91,7 +91,7 @@ var map = (value = []) => {
91
91
 
92
92
  // src/object.ts
93
93
  import { Map as YMap2 } from "yjs";
94
- var unstable__object = (value) => {
94
+ var object = (value) => {
95
95
  return new YMap2(Object.entries(value));
96
96
  };
97
97
 
@@ -100,11 +100,38 @@ import { Text as YText } from "yjs";
100
100
  var text = (value = "") => {
101
101
  return new YText(value);
102
102
  };
103
+
104
+ // src/xmlElement.ts
105
+ import { XmlElement as YXmlElement } from "yjs";
106
+ var xmlElement = (name, params = {}) => {
107
+ const { children = [] } = params;
108
+ const element = new YXmlElement(name);
109
+ element.push(children.slice());
110
+ return element;
111
+ };
112
+
113
+ // src/xmlFragment.ts
114
+ import { XmlFragment as YXmlFragment } from "yjs";
115
+ var xmlFragment = (params = {}) => {
116
+ const { children = [] } = params;
117
+ const fragment = new YXmlFragment();
118
+ fragment.push(children.slice());
119
+ return fragment;
120
+ };
121
+
122
+ // src/xmlText.ts
123
+ import { XmlText as YXmlText } from "yjs";
124
+ var xmlText = (value = "") => {
125
+ return new YXmlText(value);
126
+ };
103
127
  export {
104
128
  YjsDoc,
105
129
  array,
106
130
  doc,
107
131
  map,
132
+ object,
108
133
  text,
109
- unstable__object
134
+ xmlElement,
135
+ xmlFragment,
136
+ xmlText
110
137
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/crdt-yjs",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "yjs for @pluv/io",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -17,18 +17,18 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "js-base64": "^3.7.4",
21
- "@pluv/types": "^0.1.2"
20
+ "js-base64": "^3.7.5",
21
+ "@pluv/types": "^0.1.3"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "yjs": "^13.0.0"
25
25
  },
26
26
  "devDependencies": {
27
- "tsup": "^6.5.0",
28
- "typescript": "^4.9.4",
29
- "yjs": "^13.5.44",
30
- "@pluv/tsconfig": "^0.1.2",
31
- "eslint-config-pluv": "^0.1.2"
27
+ "tsup": "^6.6.3",
28
+ "typescript": "^4.9.5",
29
+ "yjs": "^13.5.49",
30
+ "@pluv/tsconfig": "^0.1.3",
31
+ "eslint-config-pluv": "^0.1.4"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsup src/index.ts --format esm,cjs --dts",
package/src/doc.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { JsonObject } from "@pluv/types";
2
1
  import { fromUint8Array, toUint8Array } from "js-base64";
3
2
  import type { AbstractType, Map as YMap, Transaction } from "yjs";
4
3
  import { applyUpdate, Doc as YDoc, encodeStateAsUpdate } from "yjs";
4
+ import type { InferYjsDocJson } from "./types";
5
5
 
6
6
  export class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
7
7
  public value: YDoc = new YDoc();
@@ -70,8 +70,8 @@ export class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
70
70
  };
71
71
  }
72
72
 
73
- public toJSON(): JsonObject {
74
- return this._storage.toJSON();
73
+ public toJSON(): InferYjsDocJson<this> {
74
+ return this._storage.toJSON() as InferYjsDocJson<this>;
75
75
  }
76
76
 
77
77
  public static fromUint8Array(u8a: Uint8Array): string {
package/src/index.ts CHANGED
@@ -3,8 +3,13 @@ export { array } from "./array";
3
3
  export { doc, YjsDoc } from "./doc";
4
4
  export { map } from "./map";
5
5
  export type { unstable__YObject } from "./object";
6
- export { unstable__object } from "./object";
6
+ export { object } from "./object";
7
7
  export { text } from "./text";
8
+ export type { XmlElementParams } from "./xmlElement";
9
+ export { xmlElement } from "./xmlElement";
10
+ export type { XmlFragmentParams } from "./xmlFragment";
11
+ export { xmlFragment } from "./xmlFragment";
12
+ export { xmlText } from "./xmlText";
8
13
  export type {
9
14
  InferYjsDocJson,
10
15
  InferYjsDocSharedType,
package/src/object.ts CHANGED
@@ -11,7 +11,7 @@ export type unstable__YObject<T extends unstable__YObjectValue> = YMap<
11
11
  T[keyof T]
12
12
  > & { __$type: T };
13
13
 
14
- export const unstable__object = <T extends unstable__YObjectValue = {}>(
14
+ export const object = <T extends unstable__YObjectValue = {}>(
15
15
  value: T
16
16
  ): unstable__YObject<T> => {
17
17
  return new YMap(Object.entries(value)) as unstable__YObject<T>;
package/src/types.ts CHANGED
@@ -3,6 +3,9 @@ import type {
3
3
  Array as YArray,
4
4
  Map as YMap,
5
5
  Text as YText,
6
+ XmlElement as YXmlElement,
7
+ XmlFragment as YXmlFragment,
8
+ XmlText as YXmlText,
6
9
  } from "yjs";
7
10
  import type { YjsDoc } from "./doc";
8
11
  import type { unstable__YObject } from "./object";
@@ -34,7 +37,7 @@ export type InferYjsSharedTypeJson<TShared extends unknown> =
34
37
  ? { [P in keyof IObject]: InferYjsSharedTypeJson<IObject[P]> }
35
38
  : TShared extends YMap<infer IItem>
36
39
  ? Record<string, InferYjsSharedTypeJson<IItem>>
37
- : TShared extends YText
40
+ : TShared extends YText | YXmlElement | YXmlFragment | YXmlText
38
41
  ? string
39
42
  : never
40
43
  : TShared;
@@ -0,0 +1,19 @@
1
+ import type { XmlText as YXmlText } from "yjs";
2
+ import { XmlElement as YXmlElement } from "yjs";
3
+
4
+ export interface XmlElementParams {
5
+ children?: readonly (YXmlElement | YXmlText)[];
6
+ }
7
+
8
+ export const xmlElement = (
9
+ name: string,
10
+ params: XmlElementParams = {}
11
+ ): YXmlElement => {
12
+ const { children = [] } = params;
13
+
14
+ const element = new YXmlElement(name);
15
+
16
+ element.push(children.slice());
17
+
18
+ return element;
19
+ };
@@ -0,0 +1,16 @@
1
+ import type { XmlElement as YXmlElement, XmlText as YXmlText } from "yjs";
2
+ import { XmlFragment as YXmlFragment } from "yjs";
3
+
4
+ export interface XmlFragmentParams {
5
+ children?: readonly (YXmlElement | YXmlText)[];
6
+ }
7
+
8
+ export const xmlFragment = (params: XmlFragmentParams = {}): YXmlFragment => {
9
+ const { children = [] } = params;
10
+
11
+ const fragment = new YXmlFragment();
12
+
13
+ fragment.push(children.slice());
14
+
15
+ return fragment;
16
+ };
package/src/xmlText.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { XmlText as YXmlText } from "yjs";
2
+
3
+ export const xmlText = (value: string = ""): YXmlText => {
4
+ return new YXmlText(value);
5
+ };