@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.
Files changed (44) hide show
  1. package/.turbo/turbo-build.log +15 -15
  2. package/CHANGELOG.md +84 -0
  3. package/README.md +0 -64
  4. package/dist/index.d.mts +40 -119
  5. package/dist/index.d.ts +40 -119
  6. package/dist/index.js +145 -275
  7. package/dist/index.mjs +150 -280
  8. package/package.json +7 -7
  9. package/src/array/YjsArray.ts +18 -0
  10. package/src/array/array.ts +5 -3
  11. package/src/array/index.ts +1 -1
  12. package/src/doc/CrdtYjsDoc.ts +58 -69
  13. package/src/doc/CrdtYjsDocFactory.ts +30 -26
  14. package/src/doc/doc.ts +2 -2
  15. package/src/map/YjsMap.ts +16 -0
  16. package/src/map/index.ts +1 -1
  17. package/src/map/map.ts +7 -3
  18. package/src/object/YjsObject.ts +16 -0
  19. package/src/object/index.ts +1 -1
  20. package/src/object/object.ts +5 -3
  21. package/src/text/YjsText.ts +16 -0
  22. package/src/text/index.ts +1 -1
  23. package/src/text/text.ts +5 -3
  24. package/src/types.ts +5 -63
  25. package/src/xmlElement/YjsXmlElement.ts +22 -0
  26. package/src/xmlElement/index.ts +1 -1
  27. package/src/xmlElement/xmlElement.ts +6 -6
  28. package/src/xmlFragment/YjsXmlFragment.ts +19 -0
  29. package/src/xmlFragment/index.ts +1 -1
  30. package/src/xmlFragment/xmlFragment.ts +6 -5
  31. package/src/xmlText/YjsXmlText.ts +16 -0
  32. package/src/xmlText/index.ts +1 -1
  33. package/src/xmlText/xmlText.ts +5 -3
  34. package/src/yjs.ts +9 -9
  35. package/src/array/CrdtYjsArray.ts +0 -50
  36. package/src/map/CrdtYjsMap.ts +0 -40
  37. package/src/object/CrdtYjsObject.ts +0 -30
  38. package/src/shared/index.ts +0 -2
  39. package/src/shared/isWrapper.ts +0 -21
  40. package/src/shared/toYjsValue.ts +0 -5
  41. package/src/text/CrdtYjsText.ts +0 -34
  42. package/src/xmlElement/CrdtYjsXmlElement.ts +0 -50
  43. package/src/xmlFragment/CrdtYjsXmlFragment.ts +0 -49
  44. package/src/xmlText/CrdtYjsXmlText.ts +0 -34
@@ -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 { CrdtYjsArray } from "../array/CrdtYjsArray";
23
- import { CrdtYjsMap } from "../map/CrdtYjsMap";
24
- import { CrdtYjsObject } from "../object/CrdtYjsObject";
25
- import { CrdtYjsText } from "../text/CrdtYjsText";
26
- import { CrdtYjsXmlElement } from "../xmlElement/CrdtYjsXmlElement";
27
- import { CrdtYjsXmlFragment } from "../xmlFragment/CrdtYjsXmlFragment";
28
- import { CrdtYjsXmlText } from "../xmlText/CrdtYjsXmlText";
29
-
30
- export class CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, any>>> extends AbstractCrdtDoc<TStorage> {
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 CrdtYjsArray) {
41
- const yArray = this.value.get(key, YArray) as YArray<any>;
42
- yArray.insert(0, node.initialValue.slice(0));
35
+ if (node instanceof YjsArray) {
36
+ const yArray = this.value.getArray(key);
43
37
 
44
- node.value = yArray;
38
+ !!node.initialValue?.length && yArray.insert(0, node.initialValue?.slice(0));
45
39
 
46
- return { ...acc, [key]: node };
40
+ return { ...acc, [key]: yArray };
47
41
  }
48
42
 
49
- if (node instanceof CrdtYjsMap || node instanceof CrdtYjsObject) {
50
- const yMap = this.value.get(key, YMap) as YMap<any>;
51
- node.initialValue.forEach(([k, v]) => {
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
- node.value = yMap;
56
-
57
- return { ...acc, [key]: node };
50
+ return { ...acc, [key]: yMap };
58
51
  }
59
52
 
60
- if (node instanceof CrdtYjsObject) {
61
- const yMap = this.value.get(key, YMap) as YMap<any>;
62
- node.initialValue.forEach(([k, v]) => {
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
- node.value = yMap;
67
-
68
- return { ...acc, [key]: node };
60
+ return { ...acc, [key]: yMap };
69
61
  }
70
62
 
71
- if (node instanceof CrdtYjsText) {
72
- const yText = this.value.get(key, YText) as YText;
73
- yText.insert(0, node.initialValue);
63
+ if (node instanceof YjsText) {
64
+ const yText = this.value.getText(key);
74
65
 
75
- node.value = yText;
66
+ typeof node.initialValue === "string" && yText.insert(0, node.initialValue);
76
67
 
77
- return { ...acc, [key]: node };
68
+ return { ...acc, [key]: yText };
78
69
  }
79
70
 
80
- if (node instanceof CrdtYjsXmlElement) {
81
- const yXmlElement = this.value.get(key, YXmlElement) as YXmlElement;
82
- yXmlElement.insert(0, node.initialValue.slice(0));
71
+ if (node instanceof YjsXmlElement) {
72
+ const yXmlElement = this.value.getXmlElement(key);
83
73
 
84
- node.value = yXmlElement;
74
+ !!node.initialValue?.length && yXmlElement.insert(0, node.initialValue?.slice(0));
85
75
 
86
- return { ...acc, [key]: node };
76
+ return { ...acc, [key]: yXmlElement };
87
77
  }
88
78
 
89
- if (node instanceof CrdtYjsXmlFragment) {
90
- const yXmlFragment = this.value.get(key, YXmlFragment) as YXmlFragment;
91
- yXmlFragment.insert(0, node.initialValue.slice(0));
79
+ if (node instanceof YXmlFragment) {
80
+ const yXmlFragment = this.value.getXmlFragment(key);
92
81
 
93
- node.value = yXmlFragment;
82
+ !!node.initialValue?.length && yXmlFragment.insert(0, node.initialValue?.slice(0));
94
83
 
95
- return { ...acc, [key]: node };
84
+ return { ...acc, [key]: yXmlFragment };
96
85
  }
97
86
 
98
- if (node instanceof CrdtYjsXmlText) {
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]: node };
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>(key: TKey): TStorage[TKey];
160
- public get<TKey extends keyof TStorage>(key?: TKey): TStorage | TStorage[TKey] {
161
- if (typeof key === "undefined") return this._storage;
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[key as TKey];
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<YAbstractType<any>[]>((acc, type) => {
186
+ const sharedTypes = Object.values(this._storage).reduce<YjsType<AbstractType<any>, any>[]>((acc, type) => {
201
187
  if (
202
- type instanceof CrdtYjsArray ||
203
- type instanceof CrdtYjsMap ||
204
- type instanceof CrdtYjsObject ||
205
- type instanceof CrdtYjsText ||
206
- type instanceof CrdtYjsXmlElement ||
207
- type instanceof CrdtYjsXmlFragment ||
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.value);
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(): InferCrdtStorageJson<TStorage> {
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.toJson() }),
237
- {} as InferCrdtStorageJson<TStorage>,
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 { CrdtYjsArray } from "../array";
4
- import { CrdtYjsMap } from "../map";
5
- import { CrdtYjsObject } from "../object";
6
- import { CrdtYjsText } from "../text";
7
- import { CrdtYjsXmlElement } from "../xmlElement";
8
- import { CrdtYjsXmlFragment } from "../xmlFragment";
9
- import { CrdtYjsXmlText } from "../xmlText";
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, AbstractCrdtType<any, any>>,
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 CrdtYjsArray) {
37
- return { ...acc, [key]: new CrdtYjsArray([]) };
43
+ if (node instanceof YjsArray) {
44
+ return { ...acc, [key]: array() };
38
45
  }
39
46
 
40
- if (node instanceof CrdtYjsMap) {
41
- return { ...acc, [key]: new CrdtYjsMap([]) };
47
+ if (node instanceof YjsMap) {
48
+ return { ...acc, [key]: map() };
42
49
  }
43
50
 
44
- if (node instanceof CrdtYjsObject) {
45
- return { ...acc, [key]: new CrdtYjsObject({}) };
51
+ if (node instanceof YjsObject) {
52
+ return { ...acc, [key]: object() };
46
53
  }
47
54
 
48
- if (node instanceof CrdtYjsText) {
49
- return { ...acc, [key]: new CrdtYjsText("") };
55
+ if (node instanceof YjsText) {
56
+ return { ...acc, [key]: text() };
50
57
  }
51
58
 
52
- if (node instanceof CrdtYjsXmlElement) {
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 CrdtYjsXmlFragment) {
60
- return { ...acc, [key]: new CrdtYjsXmlFragment([]) };
63
+ if (node instanceof YXmlFragment) {
64
+ return { ...acc, [key]: xmlFragment([]) };
61
65
  }
62
66
 
63
- if (node instanceof CrdtYjsXmlText) {
64
- return { ...acc, [key]: new CrdtYjsXmlText("") };
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 { AbstractCrdtType } from "@pluv/crdt";
1
+ import type { YjsType } from "../types";
2
2
  import { CrdtYjsDocFactory } from "./CrdtYjsDocFactory";
3
3
 
4
- export const doc = <TStorage extends Record<string, AbstractCrdtType<any, any>>>(
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
@@ -1,2 +1,2 @@
1
- export { CrdtYjsMap } from "./CrdtYjsMap";
2
1
  export { map } from "./map";
2
+ export type { YjsMap } from "./YjsMap";
package/src/map/map.ts CHANGED
@@ -1,5 +1,9 @@
1
- import { CrdtYjsMap } from "./CrdtYjsMap";
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>(value: readonly (readonly [key: string, value: T])[] = []): CrdtYjsMap<T> => {
4
- return new CrdtYjsMap<T>(value);
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
+ }
@@ -1,2 +1,2 @@
1
- export { CrdtYjsObject } from "./CrdtYjsObject";
2
1
  export { object } from "./object";
2
+ export type { YjsObject } from "./YjsObject";
@@ -1,5 +1,7 @@
1
- import { CrdtYjsObject } from "./CrdtYjsObject";
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): CrdtYjsObject<T> => {
4
- return new CrdtYjsObject(value);
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
@@ -1,2 +1,2 @@
1
- export { CrdtYjsText } from "./CrdtYjsText";
2
1
  export { text } from "./text";
2
+ export type { YjsText } from "./YjsText";
package/src/text/text.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { CrdtYjsText } from "./CrdtYjsText";
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 = ""): CrdtYjsText => {
4
- return new CrdtYjsText(value);
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 { Json } from "@pluv/types";
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 InferYjsType<T extends unknown> =
19
- T extends CrdtYjsArray<infer IType>
20
- ? YArray<IType>
21
- : T extends CrdtYjsMap<infer IType>
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
+ }
@@ -1,2 +1,2 @@
1
- export { CrdtYjsXmlElement } from "./CrdtYjsXmlElement";
2
1
  export { xmlElement } from "./xmlElement";
2
+ export type { YjsXmlElement } from "./YjsXmlElement";
@@ -1,9 +1,9 @@
1
- import type { CrdtYjsXmlText } from "../xmlText";
2
- import { CrdtYjsXmlElement } from "./CrdtYjsXmlElement";
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 (CrdtYjsXmlElement | CrdtYjsXmlText)[],
7
- ): CrdtYjsXmlElement => {
8
- return new CrdtYjsXmlElement(name, children);
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
+ }
@@ -1,2 +1,2 @@
1
- export { CrdtYjsXmlFragment } from "./CrdtYjsXmlFragment";
2
1
  export { xmlFragment } from "./xmlFragment";
2
+ export type { YjsXmlFragment } from "./YjsXmlFragment";
@@ -1,7 +1,8 @@
1
- import type { CrdtYjsXmlElement } from "../xmlElement";
2
- import type { CrdtYjsXmlText } from "../xmlText";
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 = (children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): CrdtYjsXmlFragment => {
6
- return new CrdtYjsXmlFragment(children);
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
+ }
@@ -1,2 +1,2 @@
1
- export { CrdtYjsXmlText } from "./CrdtYjsXmlText";
2
1
  export { xmlText } from "./xmlText";
2
+ export type { YjsXmlText } from "./YjsXmlText";
@@ -1,5 +1,7 @@
1
- import { CrdtYjsXmlText } from "./CrdtYjsXmlText";
1
+ import type { XmlText as YXmlText } from "yjs";
2
+ import { YjsType } from "../types";
3
+ import { YjsXmlText } from "./YjsXmlText";
2
4
 
3
- export const xmlText = (value: string = ""): CrdtYjsXmlText => {
4
- return new CrdtYjsXmlText(value);
5
+ export const xmlText = (): YjsType<YXmlText, string> => {
6
+ return new YjsXmlText();
5
7
  };
package/src/yjs.ts CHANGED
@@ -1,9 +1,9 @@
1
- export { CrdtYjsArray, array } from "./array";
2
- export { CrdtYjsDoc, doc } from "./doc";
3
- export { CrdtYjsMap, map } from "./map";
4
- export { CrdtYjsObject, object } from "./object";
5
- export { CrdtYjsText } from "./text";
6
- export type { InferYjsJson, InferYjsType } from "./types";
7
- export { CrdtYjsXmlElement, xmlElement } from "./xmlElement";
8
- export { CrdtYjsXmlFragment, xmlFragment } from "./xmlFragment";
9
- export { CrdtYjsXmlText, xmlText } from "./xmlText";
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";