@pluv/crdt-yjs 0.18.0 → 0.20.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 +15 -15
- package/CHANGELOG.md +84 -0
- package/README.md +0 -64
- package/dist/index.d.mts +40 -119
- package/dist/index.d.ts +40 -119
- package/dist/index.js +145 -275
- package/dist/index.mjs +150 -280
- package/package.json +7 -7
- package/src/array/YjsArray.ts +18 -0
- package/src/array/array.ts +5 -3
- package/src/array/index.ts +1 -1
- package/src/doc/CrdtYjsDoc.ts +58 -69
- package/src/doc/CrdtYjsDocFactory.ts +30 -26
- package/src/doc/doc.ts +2 -2
- package/src/map/YjsMap.ts +16 -0
- package/src/map/index.ts +1 -1
- package/src/map/map.ts +7 -3
- package/src/object/YjsObject.ts +16 -0
- package/src/object/index.ts +1 -1
- package/src/object/object.ts +5 -3
- package/src/text/YjsText.ts +16 -0
- package/src/text/index.ts +1 -1
- package/src/text/text.ts +5 -3
- package/src/types.ts +5 -63
- package/src/xmlElement/YjsXmlElement.ts +22 -0
- package/src/xmlElement/index.ts +1 -1
- package/src/xmlElement/xmlElement.ts +6 -6
- package/src/xmlFragment/YjsXmlFragment.ts +19 -0
- package/src/xmlFragment/index.ts +1 -1
- package/src/xmlFragment/xmlFragment.ts +6 -5
- package/src/xmlText/YjsXmlText.ts +16 -0
- package/src/xmlText/index.ts +1 -1
- package/src/xmlText/xmlText.ts +5 -3
- package/src/yjs.ts +9 -9
- package/src/array/CrdtYjsArray.ts +0 -50
- package/src/map/CrdtYjsMap.ts +0 -40
- package/src/object/CrdtYjsObject.ts +0 -30
- package/src/shared/index.ts +0 -2
- package/src/shared/isWrapper.ts +0 -21
- package/src/shared/toYjsValue.ts +0 -5
- package/src/text/CrdtYjsText.ts +0 -34
- package/src/xmlElement/CrdtYjsXmlElement.ts +0 -50
- package/src/xmlFragment/CrdtYjsXmlFragment.ts +0 -49
- package/src/xmlText/CrdtYjsXmlText.ts +0 -34
package/src/doc/CrdtYjsDoc.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AbstractCrdtType,
|
|
3
|
-
DocApplyEncodedStateParams,
|
|
4
|
-
DocSubscribeCallbackParams,
|
|
5
|
-
InferCrdtStorageJson,
|
|
6
|
-
} from "@pluv/crdt";
|
|
1
|
+
import type { DocApplyEncodedStateParams, DocSubscribeCallbackParams, InferCrdtJson } from "@pluv/crdt";
|
|
7
2
|
import { AbstractCrdtDoc } from "@pluv/crdt";
|
|
8
3
|
import { fromUint8Array, toUint8Array } from "js-base64";
|
|
9
4
|
import {
|
|
5
|
+
AbstractType,
|
|
10
6
|
UndoManager,
|
|
11
|
-
AbstractType as YAbstractType,
|
|
12
7
|
Array as YArray,
|
|
13
8
|
Doc as YDoc,
|
|
14
9
|
Map as YMap,
|
|
@@ -19,15 +14,15 @@ import {
|
|
|
19
14
|
applyUpdate,
|
|
20
15
|
encodeStateAsUpdate,
|
|
21
16
|
} from "yjs";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
export class CrdtYjsDoc<TStorage extends Record<string,
|
|
17
|
+
import { YjsArray } from "../array/YjsArray";
|
|
18
|
+
import { YjsMap } from "../map/YjsMap";
|
|
19
|
+
import { YjsObject } from "../object/YjsObject";
|
|
20
|
+
import { YjsText } from "../text/YjsText";
|
|
21
|
+
import type { YjsType } from "../types";
|
|
22
|
+
import { YjsXmlElement } from "../xmlElement/YjsXmlElement";
|
|
23
|
+
import { YjsXmlText } from "../xmlText/YjsXmlText";
|
|
24
|
+
|
|
25
|
+
export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> extends AbstractCrdtDoc<TStorage> {
|
|
31
26
|
public value: YDoc = new YDoc();
|
|
32
27
|
|
|
33
28
|
private _storage: TStorage;
|
|
@@ -37,71 +32,62 @@ export class CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, an
|
|
|
37
32
|
super();
|
|
38
33
|
|
|
39
34
|
this._storage = Object.entries(value).reduce((acc, [key, node]) => {
|
|
40
|
-
if (node instanceof
|
|
41
|
-
const yArray = this.value.
|
|
42
|
-
yArray.insert(0, node.initialValue.slice(0));
|
|
35
|
+
if (node instanceof YjsArray) {
|
|
36
|
+
const yArray = this.value.getArray(key);
|
|
43
37
|
|
|
44
|
-
node.
|
|
38
|
+
!!node.initialValue?.length && yArray.insert(0, node.initialValue?.slice(0));
|
|
45
39
|
|
|
46
|
-
return { ...acc, [key]:
|
|
40
|
+
return { ...acc, [key]: yArray };
|
|
47
41
|
}
|
|
48
42
|
|
|
49
|
-
if (node instanceof
|
|
50
|
-
const yMap = this.value.
|
|
51
|
-
|
|
43
|
+
if (node instanceof YjsMap) {
|
|
44
|
+
const yMap = this.value.getMap(key);
|
|
45
|
+
|
|
46
|
+
(node.initialValue ?? []).forEach(([k, v]) => {
|
|
52
47
|
yMap.set(k.toString(), v);
|
|
53
48
|
});
|
|
54
49
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return { ...acc, [key]: node };
|
|
50
|
+
return { ...acc, [key]: yMap };
|
|
58
51
|
}
|
|
59
52
|
|
|
60
|
-
if (node instanceof
|
|
61
|
-
const yMap = this.value.
|
|
62
|
-
|
|
53
|
+
if (node instanceof YjsObject) {
|
|
54
|
+
const yMap = this.value.getMap(key);
|
|
55
|
+
|
|
56
|
+
Object.entries(node.initialValue ?? {}).forEach(([k, v]) => {
|
|
63
57
|
yMap.set(k.toString(), v);
|
|
64
58
|
});
|
|
65
59
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return { ...acc, [key]: node };
|
|
60
|
+
return { ...acc, [key]: yMap };
|
|
69
61
|
}
|
|
70
62
|
|
|
71
|
-
if (node instanceof
|
|
72
|
-
const yText = this.value.
|
|
73
|
-
yText.insert(0, node.initialValue);
|
|
63
|
+
if (node instanceof YjsText) {
|
|
64
|
+
const yText = this.value.getText(key);
|
|
74
65
|
|
|
75
|
-
node.
|
|
66
|
+
typeof node.initialValue === "string" && yText.insert(0, node.initialValue);
|
|
76
67
|
|
|
77
|
-
return { ...acc, [key]:
|
|
68
|
+
return { ...acc, [key]: yText };
|
|
78
69
|
}
|
|
79
70
|
|
|
80
|
-
if (node instanceof
|
|
81
|
-
const yXmlElement = this.value.
|
|
82
|
-
yXmlElement.insert(0, node.initialValue.slice(0));
|
|
71
|
+
if (node instanceof YjsXmlElement) {
|
|
72
|
+
const yXmlElement = this.value.getXmlElement(key);
|
|
83
73
|
|
|
84
|
-
node.
|
|
74
|
+
!!node.initialValue?.length && yXmlElement.insert(0, node.initialValue?.slice(0));
|
|
85
75
|
|
|
86
|
-
return { ...acc, [key]:
|
|
76
|
+
return { ...acc, [key]: yXmlElement };
|
|
87
77
|
}
|
|
88
78
|
|
|
89
|
-
if (node instanceof
|
|
90
|
-
const yXmlFragment = this.value.
|
|
91
|
-
yXmlFragment.insert(0, node.initialValue.slice(0));
|
|
79
|
+
if (node instanceof YXmlFragment) {
|
|
80
|
+
const yXmlFragment = this.value.getXmlFragment(key);
|
|
92
81
|
|
|
93
|
-
node.
|
|
82
|
+
!!node.initialValue?.length && yXmlFragment.insert(0, node.initialValue?.slice(0));
|
|
94
83
|
|
|
95
|
-
return { ...acc, [key]:
|
|
84
|
+
return { ...acc, [key]: yXmlFragment };
|
|
96
85
|
}
|
|
97
86
|
|
|
98
|
-
if (node instanceof
|
|
87
|
+
if (node instanceof YjsXmlText) {
|
|
99
88
|
const yXmlText = this.value.get(key, YXmlText) as YXmlText;
|
|
100
|
-
yXmlText.insert(0, node.initialValue);
|
|
101
|
-
|
|
102
|
-
node.value = yXmlText;
|
|
103
89
|
|
|
104
|
-
return { ...acc, [key]:
|
|
90
|
+
return { ...acc, [key]: yXmlText };
|
|
105
91
|
}
|
|
106
92
|
|
|
107
93
|
return acc;
|
|
@@ -156,11 +142,11 @@ export class CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, an
|
|
|
156
142
|
}
|
|
157
143
|
|
|
158
144
|
public get(key?: undefined): TStorage;
|
|
159
|
-
public get<TKey extends keyof TStorage>(
|
|
160
|
-
public get<TKey extends keyof TStorage>(
|
|
161
|
-
if (typeof
|
|
145
|
+
public get<TKey extends keyof TStorage>(type: TKey): TStorage[TKey];
|
|
146
|
+
public get<TKey extends keyof TStorage>(type?: TKey): TStorage | TStorage[TKey] {
|
|
147
|
+
if (typeof type === "undefined") return this._storage;
|
|
162
148
|
|
|
163
|
-
return this._storage[
|
|
149
|
+
return this._storage[type as TKey];
|
|
164
150
|
}
|
|
165
151
|
|
|
166
152
|
public getEncodedState(): string {
|
|
@@ -197,17 +183,16 @@ export class CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, an
|
|
|
197
183
|
public track(): this {
|
|
198
184
|
if (this._undoManager) this._undoManager.destroy();
|
|
199
185
|
|
|
200
|
-
const sharedTypes = Object.values(this._storage).reduce<
|
|
186
|
+
const sharedTypes = Object.values(this._storage).reduce<YjsType<AbstractType<any>, any>[]>((acc, type) => {
|
|
201
187
|
if (
|
|
202
|
-
type instanceof
|
|
203
|
-
type instanceof
|
|
204
|
-
type instanceof
|
|
205
|
-
type instanceof
|
|
206
|
-
type instanceof
|
|
207
|
-
type instanceof
|
|
208
|
-
type instanceof CrdtYjsXmlText
|
|
188
|
+
type instanceof YArray ||
|
|
189
|
+
type instanceof YMap ||
|
|
190
|
+
type instanceof YText ||
|
|
191
|
+
type instanceof YXmlElement ||
|
|
192
|
+
type instanceof YXmlFragment ||
|
|
193
|
+
type instanceof YXmlText
|
|
209
194
|
) {
|
|
210
|
-
acc.push(type
|
|
195
|
+
acc.push(type);
|
|
211
196
|
}
|
|
212
197
|
|
|
213
198
|
return acc;
|
|
@@ -231,10 +216,14 @@ export class CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, an
|
|
|
231
216
|
return this;
|
|
232
217
|
}
|
|
233
218
|
|
|
234
|
-
public toJson():
|
|
219
|
+
public toJson(): InferCrdtJson<TStorage>;
|
|
220
|
+
public toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
|
|
221
|
+
public toJson<TKey extends keyof TStorage>(type?: TKey) {
|
|
222
|
+
if (typeof type === "string") return this._storage[type].toJSON();
|
|
223
|
+
|
|
235
224
|
return Object.entries(this._storage).reduce(
|
|
236
|
-
(acc, [key, value]) => ({ ...acc, [key]: value.
|
|
237
|
-
{} as
|
|
225
|
+
(acc, [key, value]) => ({ ...(acc as any), [key]: value.toJSON() }),
|
|
226
|
+
{} as InferCrdtJson<TStorage>,
|
|
238
227
|
);
|
|
239
228
|
}
|
|
240
229
|
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
import type { AbstractCrdtType } from "@pluv/crdt";
|
|
2
1
|
import { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
2
|
+
import { XmlFragment as YXmlFragment } from "yjs";
|
|
3
|
+
import { array } from "../array";
|
|
4
|
+
import { YjsArray } from "../array/YjsArray";
|
|
5
|
+
import { map } from "../map";
|
|
6
|
+
import { YjsMap } from "../map/YjsMap";
|
|
7
|
+
import { object } from "../object";
|
|
8
|
+
import { YjsObject } from "../object/YjsObject";
|
|
9
|
+
import { text } from "../text";
|
|
10
|
+
import { YjsText } from "../text/YjsText";
|
|
11
|
+
import type { YjsType } from "../types";
|
|
12
|
+
import { xmlElement } from "../xmlElement";
|
|
13
|
+
import { YjsXmlElement } from "../xmlElement/YjsXmlElement";
|
|
14
|
+
import { xmlFragment } from "../xmlFragment";
|
|
15
|
+
import { xmlText } from "../xmlText";
|
|
16
|
+
import { YjsXmlText } from "../xmlText/YjsXmlText";
|
|
10
17
|
import { CrdtYjsDoc } from "./CrdtYjsDoc";
|
|
11
18
|
|
|
12
19
|
export class CrdtYjsDocFactory<
|
|
13
|
-
TStorage extends Record<string,
|
|
20
|
+
TStorage extends Record<string, YjsType<any, any>>,
|
|
14
21
|
> extends AbstractCrdtDocFactory<TStorage> {
|
|
15
22
|
private _initialStorage: () => TStorage;
|
|
16
23
|
|
|
@@ -33,35 +40,32 @@ export class CrdtYjsDocFactory<
|
|
|
33
40
|
|
|
34
41
|
return new CrdtYjsDoc<TStorage>(
|
|
35
42
|
Object.entries(storage).reduce((acc, [key, node]) => {
|
|
36
|
-
if (node instanceof
|
|
37
|
-
return { ...acc, [key]:
|
|
43
|
+
if (node instanceof YjsArray) {
|
|
44
|
+
return { ...acc, [key]: array() };
|
|
38
45
|
}
|
|
39
46
|
|
|
40
|
-
if (node instanceof
|
|
41
|
-
return { ...acc, [key]:
|
|
47
|
+
if (node instanceof YjsMap) {
|
|
48
|
+
return { ...acc, [key]: map() };
|
|
42
49
|
}
|
|
43
50
|
|
|
44
|
-
if (node instanceof
|
|
45
|
-
return { ...acc, [key]:
|
|
51
|
+
if (node instanceof YjsObject) {
|
|
52
|
+
return { ...acc, [key]: object() };
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
if (node instanceof
|
|
49
|
-
return { ...acc, [key]:
|
|
55
|
+
if (node instanceof YjsText) {
|
|
56
|
+
return { ...acc, [key]: text() };
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
if (node instanceof
|
|
53
|
-
return {
|
|
54
|
-
...acc,
|
|
55
|
-
[key]: new CrdtYjsXmlElement(node.name, []),
|
|
56
|
-
};
|
|
59
|
+
if (node instanceof YjsXmlElement) {
|
|
60
|
+
return { ...acc, [key]: xmlElement(node.nodeName, []) };
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
if (node instanceof
|
|
60
|
-
return { ...acc, [key]:
|
|
63
|
+
if (node instanceof YXmlFragment) {
|
|
64
|
+
return { ...acc, [key]: xmlFragment([]) };
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
if (node instanceof
|
|
64
|
-
return { ...acc, [key]:
|
|
67
|
+
if (node instanceof YjsXmlText) {
|
|
68
|
+
return { ...acc, [key]: xmlText() };
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
return acc;
|
package/src/doc/doc.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { YjsType } from "../types";
|
|
2
2
|
import { CrdtYjsDocFactory } from "./CrdtYjsDocFactory";
|
|
3
3
|
|
|
4
|
-
export const doc = <TStorage extends Record<string,
|
|
4
|
+
export const doc = <TStorage extends Record<string, YjsType<any, any>>>(
|
|
5
5
|
value: () => TStorage = () => ({}) as TStorage,
|
|
6
6
|
): CrdtYjsDocFactory<TStorage> => {
|
|
7
7
|
return new CrdtYjsDocFactory<TStorage>(value);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Map as YMap } from "yjs";
|
|
2
|
+
import type { YjsType } from "../types";
|
|
3
|
+
|
|
4
|
+
export class YjsMap<T extends unknown> extends YMap<T> implements YjsType<YMap<T>, Record<string, T>> {
|
|
5
|
+
public initialValue?: readonly (readonly [key: string, value: T])[];
|
|
6
|
+
|
|
7
|
+
constructor(value: readonly (readonly [key: string, value: T])[] = []) {
|
|
8
|
+
super(value);
|
|
9
|
+
|
|
10
|
+
this.initialValue = value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public __pluvType(): any {
|
|
14
|
+
return {} as any;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/map/index.ts
CHANGED
package/src/map/map.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Map as YMap } from "yjs";
|
|
2
|
+
import type { YjsType } from "../types";
|
|
3
|
+
import { YjsMap } from "./YjsMap";
|
|
2
4
|
|
|
3
|
-
export const map = <T extends unknown>(
|
|
4
|
-
|
|
5
|
+
export const map = <T extends unknown>(
|
|
6
|
+
value: readonly (readonly [key: string, value: T])[] = [],
|
|
7
|
+
): YjsType<YMap<T>, Record<string, T>> => {
|
|
8
|
+
return new YjsMap<T>(value) as YjsType<YMap<T>, Record<string, T>>;
|
|
5
9
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Map as YMap } from "yjs";
|
|
2
|
+
import type { YjsType } from "../types";
|
|
3
|
+
|
|
4
|
+
export class YjsObject<T extends Record<string, any>> extends YMap<T[keyof T]> implements YjsType<YMap<T[keyof T]>, T> {
|
|
5
|
+
public initialValue?: T;
|
|
6
|
+
|
|
7
|
+
constructor(value: T) {
|
|
8
|
+
super(Object.entries(value));
|
|
9
|
+
|
|
10
|
+
this.initialValue = value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public __pluvType() {
|
|
14
|
+
return {} as unknown as any;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/object/index.ts
CHANGED
package/src/object/object.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Map as YMap } from "yjs";
|
|
2
|
+
import type { YjsType } from "../types";
|
|
3
|
+
import { YjsObject } from "./YjsObject";
|
|
2
4
|
|
|
3
|
-
export const object = <T extends Record<string, any>>(value: T):
|
|
4
|
-
return new
|
|
5
|
+
export const object = <T extends Record<string, any>>(value: T = {} as T): YjsType<YMap<T[keyof T]>, T> => {
|
|
6
|
+
return new YjsObject<T>(value);
|
|
5
7
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Text as YText } from "yjs";
|
|
2
|
+
import type { YjsType } from "../types";
|
|
3
|
+
|
|
4
|
+
export class YjsText extends YText implements YjsType<YText, string> {
|
|
5
|
+
public initialValue?: string;
|
|
6
|
+
|
|
7
|
+
constructor(value: string = "") {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.initialValue = value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public __pluvType() {
|
|
14
|
+
return {} as unknown as any;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/text/index.ts
CHANGED
package/src/text/text.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Text as YText } from "yjs";
|
|
2
|
+
import type { YjsType } from "../types";
|
|
3
|
+
import { YjsText } from "./YjsText";
|
|
2
4
|
|
|
3
|
-
export const text = (value: string = ""):
|
|
4
|
-
return new
|
|
5
|
+
export const text = (value: string = ""): YjsType<YText, string> => {
|
|
6
|
+
return new YjsText(value);
|
|
5
7
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,64 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
Array as YArray,
|
|
4
|
-
Map as YMap,
|
|
5
|
-
Text as YText,
|
|
6
|
-
XmlElement as YXmlElement,
|
|
7
|
-
XmlFragment as YXmlFragment,
|
|
8
|
-
XmlText as YXmlText,
|
|
9
|
-
} from "yjs";
|
|
10
|
-
import type { CrdtYjsArray } from "./array";
|
|
11
|
-
import type { CrdtYjsMap } from "./map";
|
|
12
|
-
import type { CrdtYjsObject } from "./object";
|
|
13
|
-
import type { CrdtYjsText } from "./text";
|
|
14
|
-
import type { CrdtYjsXmlElement } from "./xmlElement";
|
|
15
|
-
import type { CrdtYjsXmlFragment } from "./xmlFragment";
|
|
16
|
-
import type { CrdtYjsXmlText } from "./xmlText";
|
|
1
|
+
import type { CrdtType } from "@pluv/crdt";
|
|
17
2
|
|
|
18
|
-
export type
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
? YMap<IType>
|
|
23
|
-
: T extends CrdtYjsObject<infer IType>
|
|
24
|
-
? YMap<IType[keyof IType]>
|
|
25
|
-
: T extends CrdtYjsText
|
|
26
|
-
? YText
|
|
27
|
-
: T extends CrdtYjsXmlElement
|
|
28
|
-
? YXmlElement
|
|
29
|
-
: T extends CrdtYjsXmlFragment
|
|
30
|
-
? YXmlFragment
|
|
31
|
-
: T extends CrdtYjsXmlText
|
|
32
|
-
? YXmlText
|
|
33
|
-
: T extends Json
|
|
34
|
-
? T
|
|
35
|
-
: never;
|
|
36
|
-
|
|
37
|
-
export type InferYjsJson<T extends unknown> =
|
|
38
|
-
T extends CrdtYjsArray<infer IType>
|
|
39
|
-
? InferYjsJson<IType>[]
|
|
40
|
-
: T extends CrdtYjsMap<infer IType>
|
|
41
|
-
? Record<string, InferYjsJson<IType>>
|
|
42
|
-
: T extends CrdtYjsObject<infer IType>
|
|
43
|
-
? { [P in keyof IType]: InferYjsJson<IType[P]> }
|
|
44
|
-
: T extends
|
|
45
|
-
| CrdtYjsText
|
|
46
|
-
| CrdtYjsXmlElement
|
|
47
|
-
| CrdtYjsXmlFragment
|
|
48
|
-
| CrdtYjsXmlText
|
|
49
|
-
| YText
|
|
50
|
-
| YXmlElement
|
|
51
|
-
| YXmlFragment
|
|
52
|
-
| YXmlText
|
|
53
|
-
? string
|
|
54
|
-
: T extends YArray<infer IType>
|
|
55
|
-
? InferYjsJson<IType>[]
|
|
56
|
-
: T extends YMap<infer IType>
|
|
57
|
-
? Record<string, InferYjsJson<IType>>
|
|
58
|
-
: T extends (infer IType)[]
|
|
59
|
-
? InferYjsJson<IType>[]
|
|
60
|
-
: T extends Record<any, any>
|
|
61
|
-
? { [P in keyof T]: InferYjsJson<T[P]> }
|
|
62
|
-
: T extends Json
|
|
63
|
-
? T
|
|
64
|
-
: never;
|
|
3
|
+
export type YjsType<TValue extends unknown, TJson extends unknown = any> = CrdtType<TValue, TJson> & {
|
|
4
|
+
initialValue?: any;
|
|
5
|
+
toJSON: () => any;
|
|
6
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { XmlText as YXmlText } from "yjs";
|
|
2
|
+
import { XmlElement as YXmlElement } from "yjs";
|
|
3
|
+
import type { YjsType } from "../types";
|
|
4
|
+
|
|
5
|
+
export class YjsXmlElement<T extends Record<string, any> = Record<string, any>>
|
|
6
|
+
extends YXmlElement<T>
|
|
7
|
+
implements YjsType<YXmlElement, string>
|
|
8
|
+
{
|
|
9
|
+
public initialValue?: (YXmlElement | YXmlText)[] | readonly (YXmlElement | YXmlText)[];
|
|
10
|
+
|
|
11
|
+
constructor(name: string, value: (YXmlElement | YXmlText)[] | readonly (YXmlElement | YXmlText)[]) {
|
|
12
|
+
super(name);
|
|
13
|
+
|
|
14
|
+
!!value.length && this.insert(0, value as (YXmlElement | YXmlText)[]);
|
|
15
|
+
|
|
16
|
+
this.initialValue = value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public __pluvType() {
|
|
20
|
+
return {} as unknown as any;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/xmlElement/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { XmlText as YXmlText, XmlElement as YXmlElement } from "yjs";
|
|
2
|
+
import { YjsXmlElement } from "./YjsXmlElement";
|
|
3
3
|
|
|
4
|
-
export const xmlElement = (
|
|
4
|
+
export const xmlElement = <T extends Record<string, any> = Record<string, any>>(
|
|
5
5
|
name: string,
|
|
6
|
-
children: readonly (
|
|
7
|
-
):
|
|
8
|
-
return new
|
|
6
|
+
children: (YXmlElement | YXmlText)[] | readonly (YXmlElement | YXmlText)[],
|
|
7
|
+
): YjsXmlElement<T> => {
|
|
8
|
+
return new YjsXmlElement<T>(name, children);
|
|
9
9
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { XmlText as YXmlText, XmlElement as YXmlElement } from "yjs";
|
|
2
|
+
import { XmlFragment as YXmlFragment } from "yjs";
|
|
3
|
+
import type { YjsType } from "../types";
|
|
4
|
+
|
|
5
|
+
export class YjsXmlFragment extends YXmlFragment implements YjsType<YXmlFragment, string> {
|
|
6
|
+
public initialValue?: (YXmlElement | YXmlText)[] | readonly (YXmlElement | YXmlText)[];
|
|
7
|
+
|
|
8
|
+
constructor(value: (YXmlElement | YXmlText)[] | readonly (YXmlElement | YXmlText)[]) {
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
!!value.length && this.insert(0, value as (YXmlElement | YXmlText)[]);
|
|
12
|
+
|
|
13
|
+
this.initialValue = value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public __pluvType() {
|
|
17
|
+
return {} as unknown as any;
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/xmlFragment/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import { CrdtYjsXmlFragment } from "./CrdtYjsXmlFragment";
|
|
1
|
+
import type { XmlElement as YXmlElement, XmlText as YXmlText } from "yjs";
|
|
2
|
+
import { YjsXmlFragment } from "./YjsXmlFragment";
|
|
4
3
|
|
|
5
|
-
export const xmlFragment = (
|
|
6
|
-
|
|
4
|
+
export const xmlFragment = (
|
|
5
|
+
children: (YXmlElement | YXmlText)[] | readonly (YXmlElement | YXmlText)[],
|
|
6
|
+
): YjsXmlFragment => {
|
|
7
|
+
return new YjsXmlFragment(children);
|
|
7
8
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { XmlText as YXmlText } from "yjs";
|
|
2
|
+
import type { YjsType } from "../types";
|
|
3
|
+
|
|
4
|
+
export class YjsXmlText extends YXmlText implements YjsType<YXmlText, string> {
|
|
5
|
+
public initialValue?: string;
|
|
6
|
+
|
|
7
|
+
constructor(value: string = "") {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.initialValue = value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public __pluvType() {
|
|
14
|
+
return {} as unknown as any;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/xmlText/index.ts
CHANGED
package/src/xmlText/xmlText.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { XmlText as YXmlText } from "yjs";
|
|
2
|
+
import { YjsType } from "../types";
|
|
3
|
+
import { YjsXmlText } from "./YjsXmlText";
|
|
2
4
|
|
|
3
|
-
export const xmlText = (
|
|
4
|
-
return new
|
|
5
|
+
export const xmlText = (): YjsType<YXmlText, string> => {
|
|
6
|
+
return new YjsXmlText();
|
|
5
7
|
};
|
package/src/yjs.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
1
|
+
export { array } from "./array";
|
|
2
|
+
export { doc } from "./doc";
|
|
3
|
+
export { map } from "./map";
|
|
4
|
+
export { object } from "./object";
|
|
5
|
+
export { text } from "./text";
|
|
6
|
+
export type { YjsType } from "./types";
|
|
7
|
+
export { xmlElement } from "./xmlElement";
|
|
8
|
+
export { xmlFragment } from "./xmlFragment";
|
|
9
|
+
export { xmlText } from "./xmlText";
|