@pluv/crdt-yjs 0.1.2 → 0.2.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.
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +18 -0
- package/README.md +21 -3
- package/dist/index.d.ts +31 -19
- package/dist/index.js +32 -2
- package/dist/index.mjs +28 -1
- package/package.json +6 -6
- package/src/doc.ts +3 -3
- package/src/index.ts +5 -0
- package/src/types.ts +4 -1
- package/src/xmlElement.ts +19 -0
- package/src/xmlFragment.ts +16 -0
- package/src/xmlText.ts +5 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/crdt-yjs@0.
|
|
2
|
+
> @pluv/crdt-yjs@0.2.0 build /home/runner/work/pluv/pluv/packages/crdt-yjs
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m3.52 KB[39m
|
|
12
12
|
[32mESM[39m ⚡️ Build success in 65ms
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[32m4.
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m4.73 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 76ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 1515ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.11 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @pluv/crdt-yjs
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6858682: Added support for yjs xml types including XmlElement, XmlFragment and XmlText
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- @pluv/types@0.1.2
|
|
12
|
+
|
|
13
|
+
## 0.1.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- fe80d7b: added preview disclaimer about breaking changes in the readme
|
|
18
|
+
- Updated dependencies [fe80d7b]
|
|
19
|
+
- @pluv/types@0.1.2
|
|
20
|
+
|
|
3
21
|
## 0.1.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
> **Disclaimer:**
|
|
2
|
+
> This package is currently in preview and may have breaking changes between versions. Please wait for a `v1.0.0` stable release before using this in production.
|
|
3
|
+
|
|
1
4
|
<h1 align="center">
|
|
2
5
|
<br>
|
|
3
6
|
<img src="https://github.com/pluv-io/pluv/blob/master/assets/pluv-icon-192x192.png?raw=true" alt="Pluv.IO" width="180" style="border-radius:16px">
|
|
@@ -23,7 +26,9 @@
|
|
|
23
26
|
<img src="https://img.shields.io/badge/docs-coming%20soon!-blue" alt="Docs coming soon!" />
|
|
24
27
|
</p>
|
|
25
28
|
|
|
26
|
-
<
|
|
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>
|
|
27
32
|
|
|
28
33
|
## `@pluv/crdt-yjs`
|
|
29
34
|
|
|
@@ -49,6 +54,11 @@ pnpm add @pluv/crdt-yjs yjs
|
|
|
49
54
|
|
|
50
55
|
```ts
|
|
51
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";
|
|
52
62
|
import { z } from "zod";
|
|
53
63
|
// Import the PluvIO instance as a type from your server file
|
|
54
64
|
import { type io } from "./server";
|
|
@@ -58,13 +68,21 @@ const client = createClient<typeof io>({ /* client config here */ });
|
|
|
58
68
|
type Presence = {};
|
|
59
69
|
|
|
60
70
|
interface Storage {
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
editor: YXmlFragment;
|
|
72
|
+
groceryList: YMap<string, number>;
|
|
73
|
+
messages: YArray<{ name: string; message: string }>;
|
|
63
74
|
}
|
|
64
75
|
|
|
65
76
|
// Create a room to join
|
|
66
77
|
const room = client.createRoom<Presence, Storage>("my-room", {
|
|
67
78
|
initialStorage: () => ({
|
|
79
|
+
editor: y.xmlFragment({
|
|
80
|
+
children: [
|
|
81
|
+
y.xmlElement("paragraph", {
|
|
82
|
+
children: [y.xmlText("Hello World!")],
|
|
83
|
+
}),
|
|
84
|
+
]
|
|
85
|
+
}),
|
|
68
86
|
groceryList: y.map([
|
|
69
87
|
["apricots", 2],
|
|
70
88
|
["bread", 3],
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
import { Array, AbstractType,
|
|
1
|
+
import { Array, Map, AbstractType, Text, XmlElement, XmlFragment, XmlText, Doc, Transaction } from 'yjs';
|
|
2
2
|
export { AbstractType, Array, Map, Text } from 'yjs';
|
|
3
|
-
import {
|
|
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 unstable__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():
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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, text, unstable__YObject, unstable__object, xmlElement, xmlFragment, xmlText };
|
package/dist/index.js
CHANGED
|
@@ -42,7 +42,10 @@ __export(src_exports, {
|
|
|
42
42
|
doc: () => doc,
|
|
43
43
|
map: () => map,
|
|
44
44
|
text: () => text,
|
|
45
|
-
unstable__object: () => unstable__object
|
|
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
|
|
|
@@ -128,6 +131,30 @@ 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,
|
|
@@ -135,5 +162,8 @@ var text = (value = "") => {
|
|
|
135
162
|
doc,
|
|
136
163
|
map,
|
|
137
164
|
text,
|
|
138
|
-
unstable__object
|
|
165
|
+
unstable__object,
|
|
166
|
+
xmlElement,
|
|
167
|
+
xmlFragment,
|
|
168
|
+
xmlText
|
|
139
169
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -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,
|
|
108
132
|
text,
|
|
109
|
-
unstable__object
|
|
133
|
+
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.
|
|
3
|
+
"version": "0.2.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
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"js-base64": "^3.7.4",
|
|
21
|
+
"@pluv/types": "^0.1.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"yjs": "^13.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@pluv/tsconfig": "^0.1.1",
|
|
28
|
-
"eslint-config-pluv": "^0.1.1",
|
|
29
27
|
"tsup": "^6.5.0",
|
|
30
28
|
"typescript": "^4.9.4",
|
|
31
|
-
"yjs": "^13.5.44"
|
|
29
|
+
"yjs": "^13.5.44",
|
|
30
|
+
"@pluv/tsconfig": "^0.1.2",
|
|
31
|
+
"eslint-config-pluv": "^0.1.3"
|
|
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():
|
|
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
|
@@ -5,6 +5,11 @@ export { map } from "./map";
|
|
|
5
5
|
export type { unstable__YObject } from "./object";
|
|
6
6
|
export { unstable__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/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
|
+
};
|