@pluv/crdt-yjs 0.19.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 +8 -8
- package/CHANGELOG.md +77 -0
- package/README.md +0 -64
- package/dist/index.d.mts +40 -119
- package/dist/index.d.ts +40 -119
- package/dist/index.js +142 -268
- package/dist/index.mjs +147 -273
- package/package.json +5 -5
- 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
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { InferCrdtStorageJson } from "@pluv/crdt";
|
|
2
|
-
import { AbstractCrdtType } from "@pluv/crdt";
|
|
3
|
-
import { Array as YArray } from "yjs";
|
|
4
|
-
import { toYjsValue } from "../shared";
|
|
5
|
-
import type { InferYjsJson, InferYjsType } from "../types";
|
|
6
|
-
|
|
7
|
-
export class CrdtYjsArray<T extends unknown> extends AbstractCrdtType<YArray<InferYjsType<T>>, InferYjsJson<T>[]> {
|
|
8
|
-
public readonly initialValue: InferYjsType<T>[] | readonly InferYjsType<T>[];
|
|
9
|
-
public value: YArray<InferYjsType<T>>;
|
|
10
|
-
|
|
11
|
-
constructor(value: T[] | readonly T[] = []) {
|
|
12
|
-
super();
|
|
13
|
-
|
|
14
|
-
const initialValue = value.map((item) => toYjsValue(item));
|
|
15
|
-
|
|
16
|
-
this.initialValue = initialValue;
|
|
17
|
-
this.value = new YArray<InferYjsType<T>>();
|
|
18
|
-
this.push(...value);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public get length(): number {
|
|
22
|
-
return this.value.length;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public delete(index: number, length: number = 1): this {
|
|
26
|
-
this.value.delete(index, length);
|
|
27
|
-
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public insert(index: number, ...items: T[]): this {
|
|
32
|
-
const converted = items.map((item) => toYjsValue(item));
|
|
33
|
-
|
|
34
|
-
this.value.insert(index, converted);
|
|
35
|
-
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public push(...items: T[]): this {
|
|
40
|
-
return this.insert(this.length, ...items);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public unshift(...items: T[]): this {
|
|
44
|
-
return this.insert(0, ...items);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public toJson(): InferCrdtStorageJson<InferYjsJson<T>>[] {
|
|
48
|
-
return this.value.toJSON();
|
|
49
|
-
}
|
|
50
|
-
}
|
package/src/map/CrdtYjsMap.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { InferCrdtStorageJson } from "@pluv/crdt";
|
|
2
|
-
import { AbstractCrdtType } from "@pluv/crdt";
|
|
3
|
-
import { Map as YMap } from "yjs";
|
|
4
|
-
import { toYjsValue } from "../shared";
|
|
5
|
-
import type { InferYjsJson, InferYjsType } from "../types";
|
|
6
|
-
|
|
7
|
-
export class CrdtYjsMap<T extends unknown> extends AbstractCrdtType<
|
|
8
|
-
YMap<InferYjsType<T>>,
|
|
9
|
-
Record<string, InferYjsJson<T>>
|
|
10
|
-
> {
|
|
11
|
-
public initialValue: readonly (readonly [key: string, value: InferYjsType<T>])[];
|
|
12
|
-
public value: YMap<InferYjsType<T>>;
|
|
13
|
-
|
|
14
|
-
constructor(value: readonly (readonly [key: string, value: T])[] = []) {
|
|
15
|
-
super();
|
|
16
|
-
|
|
17
|
-
this.initialValue = value.map(([k, v]) => [k, toYjsValue(v)]);
|
|
18
|
-
this.value = new YMap(this.initialValue);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public get size(): number {
|
|
22
|
-
return this.value.size;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public delete(prop: string): this {
|
|
26
|
-
this.value.delete(prop);
|
|
27
|
-
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public set(prop: string, value: T): this {
|
|
32
|
-
this.value.set(prop, toYjsValue(value));
|
|
33
|
-
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public toJson(): InferCrdtStorageJson<Record<string, InferYjsJson<T>>> {
|
|
38
|
-
return this.value.toJSON();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { InferCrdtStorageJson } from "@pluv/crdt";
|
|
2
|
-
import { AbstractCrdtType } from "@pluv/crdt";
|
|
3
|
-
import { Map as YMap } from "yjs";
|
|
4
|
-
import { toYjsValue } from "../shared";
|
|
5
|
-
import type { InferYjsJson, InferYjsType } from "../types";
|
|
6
|
-
|
|
7
|
-
export class CrdtYjsObject<T extends Record<string, any>> extends AbstractCrdtType<
|
|
8
|
-
YMap<InferYjsType<T[keyof T]>>,
|
|
9
|
-
InferYjsJson<T>
|
|
10
|
-
> {
|
|
11
|
-
public initialValue: readonly (readonly [key: string, value: T[keyof T]])[];
|
|
12
|
-
public value: YMap<InferYjsType<T[keyof T]>>;
|
|
13
|
-
|
|
14
|
-
constructor(value: T = {} as T) {
|
|
15
|
-
super();
|
|
16
|
-
|
|
17
|
-
this.initialValue = Object.entries(value).map(([k, v]) => [k, toYjsValue(v)]);
|
|
18
|
-
this.value = new YMap(this.initialValue);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public set<TProp extends keyof T>(prop: TProp, value: T[TProp]): this {
|
|
22
|
-
this.value.set(prop.toString(), toYjsValue(value));
|
|
23
|
-
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public toJson(): InferCrdtStorageJson<InferYjsJson<T>> {
|
|
28
|
-
return this.value.toJSON() as InferCrdtStorageJson<InferYjsJson<T>>;
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/shared/index.ts
DELETED
package/src/shared/isWrapper.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { CrdtYjsArray } from "../array/CrdtYjsArray";
|
|
2
|
-
import { CrdtYjsMap } from "../map/CrdtYjsMap";
|
|
3
|
-
import { CrdtYjsObject } from "../object/CrdtYjsObject";
|
|
4
|
-
import { CrdtYjsText } from "../text/CrdtYjsText";
|
|
5
|
-
import { CrdtYjsXmlElement } from "../xmlElement";
|
|
6
|
-
import { CrdtYjsXmlFragment } from "../xmlFragment";
|
|
7
|
-
import { CrdtYjsXmlText } from "../xmlText";
|
|
8
|
-
|
|
9
|
-
export const isWrapper = (
|
|
10
|
-
item: any,
|
|
11
|
-
): item is CrdtYjsArray<any> | CrdtYjsMap<any> | CrdtYjsObject<any> | CrdtYjsText => {
|
|
12
|
-
return (
|
|
13
|
-
item instanceof CrdtYjsArray ||
|
|
14
|
-
item instanceof CrdtYjsMap ||
|
|
15
|
-
item instanceof CrdtYjsObject ||
|
|
16
|
-
item instanceof CrdtYjsText ||
|
|
17
|
-
item instanceof CrdtYjsXmlElement ||
|
|
18
|
-
item instanceof CrdtYjsXmlFragment ||
|
|
19
|
-
item instanceof CrdtYjsXmlText
|
|
20
|
-
);
|
|
21
|
-
};
|
package/src/shared/toYjsValue.ts
DELETED
package/src/text/CrdtYjsText.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { AbstractCrdtType } from "@pluv/crdt";
|
|
2
|
-
import { Text as YText } from "yjs";
|
|
3
|
-
|
|
4
|
-
export class CrdtYjsText extends AbstractCrdtType<YText, string> {
|
|
5
|
-
public readonly initialValue: string;
|
|
6
|
-
public value: YText;
|
|
7
|
-
|
|
8
|
-
constructor(value: string = "") {
|
|
9
|
-
super();
|
|
10
|
-
|
|
11
|
-
this.initialValue = value;
|
|
12
|
-
this.value = new YText(value);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public get length(): number {
|
|
16
|
-
return this.value.length;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public delete(index: number, length: number = 1): this {
|
|
20
|
-
this.value.delete(index, length);
|
|
21
|
-
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public insert(index: number, text: string): this {
|
|
26
|
-
this.value.insert(index, text);
|
|
27
|
-
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public toJson(): string {
|
|
32
|
-
return this.value.toJSON();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { AbstractCrdtType } from "@pluv/crdt";
|
|
2
|
-
import type { XmlText as YXmlText } from "yjs";
|
|
3
|
-
import { XmlElement as YXmlElement } from "yjs";
|
|
4
|
-
import { toYjsValue } from "../shared";
|
|
5
|
-
import type { CrdtYjsXmlText } from "../xmlText/CrdtYjsXmlText";
|
|
6
|
-
|
|
7
|
-
export class CrdtYjsXmlElement extends AbstractCrdtType<YXmlElement, string> {
|
|
8
|
-
public readonly initialValue: readonly (YXmlElement | YXmlText)[];
|
|
9
|
-
public readonly name: string;
|
|
10
|
-
public value: YXmlElement;
|
|
11
|
-
|
|
12
|
-
constructor(name: string, children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]) {
|
|
13
|
-
super();
|
|
14
|
-
|
|
15
|
-
this.initialValue = children.map((item) => item.value);
|
|
16
|
-
this.name = name;
|
|
17
|
-
this.value = new YXmlElement(name);
|
|
18
|
-
this.push(...children);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public get length(): number {
|
|
22
|
-
return this.value.length;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public delete(index: number, length: number = 1): this {
|
|
26
|
-
this.value.delete(index, length);
|
|
27
|
-
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public insert(index: number, ...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
32
|
-
const converted = children.map((child) => toYjsValue(child));
|
|
33
|
-
|
|
34
|
-
this.value.insert(index, converted);
|
|
35
|
-
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public push(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
40
|
-
return this.insert(this.length, ...children);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public unshift(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
44
|
-
return this.insert(0, ...children);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public toJson(): string {
|
|
48
|
-
return this.value.toJSON();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { AbstractCrdtType } from "@pluv/crdt";
|
|
2
|
-
import type { XmlElement as YXmlElement, XmlText as YXmlText } from "yjs";
|
|
3
|
-
import { XmlFragment as YXmlFragment } from "yjs";
|
|
4
|
-
import { toYjsValue } from "../shared";
|
|
5
|
-
import type { CrdtYjsXmlElement } from "../xmlElement/CrdtYjsXmlElement";
|
|
6
|
-
import type { CrdtYjsXmlText } from "../xmlText/CrdtYjsXmlText";
|
|
7
|
-
|
|
8
|
-
export class CrdtYjsXmlFragment extends AbstractCrdtType<YXmlFragment, string> {
|
|
9
|
-
public readonly initialValue: readonly (YXmlElement | YXmlText)[];
|
|
10
|
-
public value: YXmlFragment;
|
|
11
|
-
|
|
12
|
-
constructor(children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]) {
|
|
13
|
-
super();
|
|
14
|
-
|
|
15
|
-
this.initialValue = children.map((item) => item.value);
|
|
16
|
-
this.value = new YXmlFragment();
|
|
17
|
-
this.push(...children);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public get length(): number {
|
|
21
|
-
return this.value.length;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public delete(index: number, length: number = 1): this {
|
|
25
|
-
this.value.delete(index, length);
|
|
26
|
-
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public insert(index: number, ...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
31
|
-
const converted = children.map((child) => toYjsValue(child));
|
|
32
|
-
|
|
33
|
-
this.value.insert(index, converted);
|
|
34
|
-
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public push(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
39
|
-
return this.insert(this.length, ...children);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public unshift(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
43
|
-
return this.insert(0, ...children);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public toJson(): string {
|
|
47
|
-
return this.value.toJSON();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { AbstractCrdtType } from "@pluv/crdt";
|
|
2
|
-
import { XmlText as YXmlText } from "yjs";
|
|
3
|
-
|
|
4
|
-
export class CrdtYjsXmlText extends AbstractCrdtType<YXmlText, string> {
|
|
5
|
-
public readonly initialValue: string;
|
|
6
|
-
public value: YXmlText;
|
|
7
|
-
|
|
8
|
-
constructor(value: string = "") {
|
|
9
|
-
super();
|
|
10
|
-
|
|
11
|
-
this.initialValue = value;
|
|
12
|
-
this.value = new YXmlText(value);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public get length(): number {
|
|
16
|
-
return this.value.length;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public delete(index: number, length: number = 1): this {
|
|
20
|
-
this.value.delete(index, length);
|
|
21
|
-
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public insert(index: number, text: string, attributes?: Record<string, string>): this {
|
|
26
|
-
this.value.insert(index, text, attributes);
|
|
27
|
-
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public toJson(): string {
|
|
32
|
-
return this.value.toJSON();
|
|
33
|
-
}
|
|
34
|
-
}
|