@pluv/crdt-yjs 0.19.0 → 0.21.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 +142 -268
- package/dist/index.mjs +147 -273
- 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/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/crdt-yjs@0.
|
|
2
|
+
> @pluv/crdt-yjs@0.21.0 build /home/runner/work/pluv/pluv/packages/crdt-yjs
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.2.4
|
|
8
|
+
[34mCLI[39m Target: es6
|
|
9
|
+
[34mESM[39m Build start
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m11.65 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 82ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m10.87 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 87ms
|
|
15
|
+
[34mDTS[39m Build start
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 2317ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.87 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.87 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,89 @@
|
|
|
1
1
|
# @pluv/crdt-yjs
|
|
2
2
|
|
|
3
|
+
## 0.21.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @pluv/crdt@0.21.0
|
|
8
|
+
- @pluv/types@0.21.0
|
|
9
|
+
|
|
10
|
+
## 0.20.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 9492085: **BREAKING**: `@pluv/crdt-yjs` and `@pluv/crdt-loro` have been updated so that the utilities to create shared-types/containers no-longer return a wrapper around the underlying shared-types and containers, but rather return the shared-types/containers directly.
|
|
15
|
+
|
|
16
|
+
This means that for methods such as `getStorage` from `@pluv/client` and `useStorage` from `@pluv/react`, the shared-types/containers are also returned instead of the wrapper types.
|
|
17
|
+
|
|
18
|
+
The motivation for these changes are so that pluv.io is supplementary to `yjs` and `loro-crdt`, instead of having these libraries be an internal implementation of pluv.io.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// Before
|
|
22
|
+
|
|
23
|
+
import { yjs } from "@pluv/crdt-yjs";
|
|
24
|
+
|
|
25
|
+
yjs.array([]); // Returns CrdtYjsArray
|
|
26
|
+
yjs.object([]); // Returns CrdtYjsObject
|
|
27
|
+
|
|
28
|
+
const room: PluvRoom = /* ... */;
|
|
29
|
+
|
|
30
|
+
room.getStorage("messages"); // Returns AbstractCrdtType
|
|
31
|
+
|
|
32
|
+
const [, sharedType] = useStorage("messages"); // sharedType is an AbstractCrdtType
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
// Now
|
|
37
|
+
|
|
38
|
+
import { yjs } from "@pluv/crdt-yjs";
|
|
39
|
+
|
|
40
|
+
yjs.array([]); // Returns yjs.Array
|
|
41
|
+
yjs.object([]); // Returns yjs.Map
|
|
42
|
+
|
|
43
|
+
const room: PluvRoom = /* ... */;
|
|
44
|
+
|
|
45
|
+
room.getStorage("messages"); // Returns yjs.AbstractType
|
|
46
|
+
|
|
47
|
+
const [, sharedType] = useStorage("messages"); // sharedType is a yjs.AbstractType
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
For `@pluv/crdt-loro` specifically, `@pluv/client` relies on [loro events and subscriptions](https://www.loro.dev/docs/tutorial/get_started#event) to detect changes. The `AbstractLoroCrdt` types previously called `Loro.commit` after each change as an abstraction, but now this no-longer happens. To ensure that changes to loro containers are properly handled in `@pluv/react`, make sure to commit your changes whenever possible:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// Before
|
|
54
|
+
|
|
55
|
+
const [data, container] = useStorage("messages");
|
|
56
|
+
|
|
57
|
+
// This automatically called Loro.commit under the hood and rerendered the page with updated data.
|
|
58
|
+
container.push(loro.object({ name: "John Doe", age: 35 }));
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
// Now
|
|
63
|
+
|
|
64
|
+
const [data, container] = useStorage("messages");
|
|
65
|
+
|
|
66
|
+
const doc = useDoc();
|
|
67
|
+
const transact = useTransact();
|
|
68
|
+
|
|
69
|
+
// Updates need to be committed back to the doc whenever the changes need to be emitted to other users
|
|
70
|
+
// The returned data also will not update until the changes are commited
|
|
71
|
+
|
|
72
|
+
// The two operations below are functionally equivalent
|
|
73
|
+
transact(() => {
|
|
74
|
+
container.push(loro.object({ name: "John Doe", age: 35 }));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
container.push(loro.object({ name: "John Doe", age: 35 }));
|
|
78
|
+
doc.value.commit();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- Updated dependencies [9492085]
|
|
84
|
+
- @pluv/crdt@0.20.0
|
|
85
|
+
- @pluv/types@0.20.0
|
|
86
|
+
|
|
3
87
|
## 0.19.0
|
|
4
88
|
|
|
5
89
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
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
|
-
|
|
4
|
-
<h1 align="center">
|
|
5
|
-
<br />
|
|
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" />
|
|
7
|
-
<br />
|
|
8
|
-
<a href="https://pluv.io/docs/introduction">Pluv.IO (preview)</a>
|
|
9
|
-
<br />
|
|
10
|
-
</h1>
|
|
11
|
-
|
|
12
|
-
<h3 align="center">Multi-platform, E2E type-safe realtime packages</h3>
|
|
13
|
-
<h4 align="center">💕 Inspired by <a href="https://trpc.io">trpc</a> 💕 <a href="https://docs.yjs.dev/">yjs</a> 💕 and <a href="https://developers.cloudflare.com/">Cloudflare</a> 💕 </h4>
|
|
14
|
-
|
|
15
|
-
<p align="center">
|
|
16
|
-
<a href="https://www.npmjs.com/package/@pluv/crdt-yjs">
|
|
17
|
-
<img src="https://img.shields.io/npm/v/@pluv/crdt-yjs" alt="npm @pluv/crdt-yjs" />
|
|
18
|
-
</a>
|
|
19
|
-
<a href="https://github.com/pluv-io/pluv/blob/master/LICENSE">
|
|
20
|
-
<img alt="GitHub" src="https://img.shields.io/github/license/pluv-io/pluv" alt="License MIT" />
|
|
21
|
-
</a>
|
|
22
|
-
<a href="https://commitizen.github.io/cz-cli/">
|
|
23
|
-
<img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen friendly" />
|
|
24
|
-
</a>
|
|
25
|
-
<img src="https://badgen.net/badge/-/TypeScript?icon=typescript&label&labelColor=blue&color=555555" alt="TypeScript" />
|
|
26
|
-
</p>
|
|
27
|
-
|
|
28
1
|
## `@pluv/crdt-yjs`
|
|
29
2
|
|
|
30
3
|
> Yjs adapter for [@pluv/client](https://www.npmjs.com/package/@pluv/client) and [@pluv/io](https://www.npmjs.com/package/@pluv/io).
|
|
@@ -46,40 +19,3 @@ yarn add @pluv/crdt-yjs yjs
|
|
|
46
19
|
# pnpm
|
|
47
20
|
pnpm add @pluv/crdt-yjs yjs
|
|
48
21
|
```
|
|
49
|
-
|
|
50
|
-
## Basic Example
|
|
51
|
-
|
|
52
|
-
```ts
|
|
53
|
-
import { createClient } from "@pluv/client";
|
|
54
|
-
import { yjs } from "@pluv/crdt-yjs";
|
|
55
|
-
import { z } from "zod";
|
|
56
|
-
// Import the PluvIO instance as a type from your server file
|
|
57
|
-
import { type io } from "./server";
|
|
58
|
-
|
|
59
|
-
const client = createClient<typeof io>({ /* client config here */ });
|
|
60
|
-
|
|
61
|
-
// Create a room to join
|
|
62
|
-
const room = client.createRoom("my-room", {
|
|
63
|
-
initialStorage: yjs.doc(() => ({
|
|
64
|
-
editor: yjs.xmlFragment({
|
|
65
|
-
children: [
|
|
66
|
-
yjs.xmlElement("paragraph", {
|
|
67
|
-
children: [yjs.xmlText("Hello World!")],
|
|
68
|
-
}),
|
|
69
|
-
]
|
|
70
|
-
}),
|
|
71
|
-
groceryList: yjs.map([
|
|
72
|
-
["apricots", 2],
|
|
73
|
-
["bread", 3],
|
|
74
|
-
["cheese", 5],
|
|
75
|
-
]),
|
|
76
|
-
messages: yjs.array([]),
|
|
77
|
-
})),
|
|
78
|
-
presence: z.object({}),
|
|
79
|
-
});
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Reference
|
|
83
|
-
|
|
84
|
-
Check us out on [GitHub](https://github.com/pluv-io/pluv) for more information on how to use `@pluv/io`.
|
|
85
|
-
|
package/dist/index.d.mts
CHANGED
|
@@ -1,102 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Json } from '@pluv/types';
|
|
1
|
+
import { Array, Doc, Map, Text, XmlElement, XmlText, XmlFragment } from 'yjs';
|
|
2
|
+
import { CrdtType, AbstractCrdtDoc, DocApplyEncodedStateParams, DocSubscribeCallbackParams, InferCrdtJson, AbstractCrdtDocFactory } from '@pluv/crdt';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
initialValue
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
get size(): number;
|
|
10
|
-
delete(prop: string): this;
|
|
11
|
-
set(prop: string, value: T): this;
|
|
12
|
-
toJson(): InferCrdtStorageJson<Record<string, InferYjsJson<T>>>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare const map: <T extends unknown>(value?: readonly (readonly [key: string, value: T])[]) => CrdtYjsMap<T>;
|
|
16
|
-
|
|
17
|
-
declare class CrdtYjsObject<T extends Record<string, any>> extends AbstractCrdtType<Map<InferYjsType<T[keyof T]>>, InferYjsJson<T>> {
|
|
18
|
-
initialValue: readonly (readonly [key: string, value: T[keyof T]])[];
|
|
19
|
-
value: Map<InferYjsType<T[keyof T]>>;
|
|
20
|
-
constructor(value?: T);
|
|
21
|
-
set<TProp extends keyof T>(prop: TProp, value: T[TProp]): this;
|
|
22
|
-
toJson(): InferCrdtStorageJson<InferYjsJson<T>>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
declare const object: <T extends Record<string, any>>(value: T) => CrdtYjsObject<T>;
|
|
26
|
-
|
|
27
|
-
declare class CrdtYjsText extends AbstractCrdtType<Text, string> {
|
|
28
|
-
readonly initialValue: string;
|
|
29
|
-
value: Text;
|
|
30
|
-
constructor(value?: string);
|
|
31
|
-
get length(): number;
|
|
32
|
-
delete(index: number, length?: number): this;
|
|
33
|
-
insert(index: number, text: string): this;
|
|
34
|
-
toJson(): string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
declare class CrdtYjsXmlText extends AbstractCrdtType<XmlText, string> {
|
|
38
|
-
readonly initialValue: string;
|
|
39
|
-
value: XmlText;
|
|
40
|
-
constructor(value?: string);
|
|
41
|
-
get length(): number;
|
|
42
|
-
delete(index: number, length?: number): this;
|
|
43
|
-
insert(index: number, text: string, attributes?: Record<string, string>): this;
|
|
44
|
-
toJson(): string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
declare class CrdtYjsXmlElement extends AbstractCrdtType<XmlElement, string> {
|
|
48
|
-
readonly initialValue: readonly (XmlElement | XmlText)[];
|
|
49
|
-
readonly name: string;
|
|
50
|
-
value: XmlElement;
|
|
51
|
-
constructor(name: string, children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]);
|
|
52
|
-
get length(): number;
|
|
53
|
-
delete(index: number, length?: number): this;
|
|
54
|
-
insert(index: number, ...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
55
|
-
push(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
56
|
-
unshift(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
57
|
-
toJson(): string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
declare const xmlText: (value?: string) => CrdtYjsXmlText;
|
|
61
|
-
|
|
62
|
-
declare const xmlElement: (name: string, children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]) => CrdtYjsXmlElement;
|
|
63
|
-
|
|
64
|
-
declare class CrdtYjsXmlFragment extends AbstractCrdtType<XmlFragment, string> {
|
|
65
|
-
readonly initialValue: readonly (XmlElement | XmlText)[];
|
|
66
|
-
value: XmlFragment;
|
|
67
|
-
constructor(children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]);
|
|
68
|
-
get length(): number;
|
|
69
|
-
delete(index: number, length?: number): this;
|
|
70
|
-
insert(index: number, ...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
71
|
-
push(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
72
|
-
unshift(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
73
|
-
toJson(): string;
|
|
74
|
-
}
|
|
4
|
+
type YjsType<TValue extends unknown, TJson extends unknown = any> = CrdtType<TValue, TJson> & {
|
|
5
|
+
initialValue?: any;
|
|
6
|
+
toJSON: () => any;
|
|
7
|
+
};
|
|
75
8
|
|
|
76
|
-
declare const
|
|
9
|
+
declare const array: <T extends unknown>(value?: T[] | readonly T[]) => YjsType<Array<T>, T[]>;
|
|
77
10
|
|
|
78
|
-
|
|
79
|
-
type InferYjsJson<T extends unknown> = T extends CrdtYjsArray<infer IType> ? InferYjsJson<IType>[] : T extends CrdtYjsMap<infer IType> ? Record<string, InferYjsJson<IType>> : T extends CrdtYjsObject<infer IType> ? {
|
|
80
|
-
[P in keyof IType]: InferYjsJson<IType[P]>;
|
|
81
|
-
} : T extends CrdtYjsText | CrdtYjsXmlElement | CrdtYjsXmlFragment | CrdtYjsXmlText | Text | XmlElement | XmlFragment | XmlText ? string : T extends Array<infer IType> ? InferYjsJson<IType>[] : T extends Map<infer IType> ? Record<string, InferYjsJson<IType>> : T extends (infer IType)[] ? InferYjsJson<IType>[] : T extends Record<any, any> ? {
|
|
82
|
-
[P in keyof T]: InferYjsJson<T[P]>;
|
|
83
|
-
} : T extends Json ? T : never;
|
|
84
|
-
|
|
85
|
-
declare class CrdtYjsArray<T extends unknown> extends AbstractCrdtType<Array<InferYjsType<T>>, InferYjsJson<T>[]> {
|
|
86
|
-
readonly initialValue: InferYjsType<T>[] | readonly InferYjsType<T>[];
|
|
87
|
-
value: Array<InferYjsType<T>>;
|
|
88
|
-
constructor(value?: T[] | readonly T[]);
|
|
89
|
-
get length(): number;
|
|
90
|
-
delete(index: number, length?: number): this;
|
|
91
|
-
insert(index: number, ...items: T[]): this;
|
|
92
|
-
push(...items: T[]): this;
|
|
93
|
-
unshift(...items: T[]): this;
|
|
94
|
-
toJson(): InferCrdtStorageJson<InferYjsJson<T>>[];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
declare const array: <T extends unknown>(value?: T[] | readonly T[]) => CrdtYjsArray<T>;
|
|
98
|
-
|
|
99
|
-
declare class CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, any>>> extends AbstractCrdtDoc<TStorage> {
|
|
11
|
+
declare class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> extends AbstractCrdtDoc<TStorage> {
|
|
100
12
|
value: Doc;
|
|
101
13
|
private _storage;
|
|
102
14
|
private _undoManager;
|
|
@@ -107,18 +19,19 @@ declare class CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, a
|
|
|
107
19
|
canUndo(): boolean;
|
|
108
20
|
destroy(): void;
|
|
109
21
|
get(key?: undefined): TStorage;
|
|
110
|
-
get<TKey extends keyof TStorage>(
|
|
22
|
+
get<TKey extends keyof TStorage>(type: TKey): TStorage[TKey];
|
|
111
23
|
getEncodedState(): string;
|
|
112
24
|
isEmpty(): boolean;
|
|
113
25
|
redo(): this;
|
|
114
26
|
subscribe(listener: (params: DocSubscribeCallbackParams<TStorage>) => void): () => void;
|
|
115
27
|
track(): this;
|
|
116
28
|
transact(fn: () => void): this;
|
|
117
|
-
toJson():
|
|
29
|
+
toJson(): InferCrdtJson<TStorage>;
|
|
30
|
+
toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
|
|
118
31
|
undo(): this;
|
|
119
32
|
}
|
|
120
33
|
|
|
121
|
-
declare class CrdtYjsDocFactory<TStorage extends Record<string,
|
|
34
|
+
declare class CrdtYjsDocFactory<TStorage extends Record<string, YjsType<any, any>>> extends AbstractCrdtDocFactory<TStorage> {
|
|
122
35
|
private _initialStorage;
|
|
123
36
|
constructor(initialStorage?: () => TStorage);
|
|
124
37
|
getEmpty(): CrdtYjsDoc<TStorage>;
|
|
@@ -127,35 +40,43 @@ declare class CrdtYjsDocFactory<TStorage extends Record<string, AbstractCrdtType
|
|
|
127
40
|
getInitialized(initialStorage?: () => TStorage): CrdtYjsDoc<TStorage>;
|
|
128
41
|
}
|
|
129
42
|
|
|
130
|
-
declare const doc: <TStorage extends Record<string,
|
|
43
|
+
declare const doc: <TStorage extends Record<string, YjsType<any, any>>>(value?: () => TStorage) => CrdtYjsDocFactory<TStorage>;
|
|
44
|
+
|
|
45
|
+
declare const map: <T extends unknown>(value?: readonly (readonly [key: string, value: T])[]) => YjsType<Map<T>, Record<string, T>>;
|
|
46
|
+
|
|
47
|
+
declare const object: <T extends Record<string, any>>(value?: T) => YjsType<Map<T[keyof T]>, T>;
|
|
48
|
+
|
|
49
|
+
declare const text: (value?: string) => YjsType<Text, string>;
|
|
50
|
+
|
|
51
|
+
declare class YjsXmlElement<T extends Record<string, any> = Record<string, any>> extends XmlElement<T> implements YjsType<XmlElement, string> {
|
|
52
|
+
initialValue?: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[];
|
|
53
|
+
constructor(name: string, value: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[]);
|
|
54
|
+
__pluvType(): any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare const xmlElement: <T extends Record<string, any> = Record<string, any>>(name: string, children: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[]) => YjsXmlElement<T>;
|
|
58
|
+
|
|
59
|
+
declare class YjsXmlFragment extends XmlFragment implements YjsType<XmlFragment, string> {
|
|
60
|
+
initialValue?: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[];
|
|
61
|
+
constructor(value: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[]);
|
|
62
|
+
__pluvType(): any;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare const xmlFragment: (children: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[]) => YjsXmlFragment;
|
|
66
|
+
|
|
67
|
+
declare const xmlText: () => YjsType<XmlText, string>;
|
|
131
68
|
|
|
132
|
-
type
|
|
133
|
-
declare const yjs_CrdtYjsArray: typeof CrdtYjsArray;
|
|
134
|
-
type yjs_CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, any>>> = CrdtYjsDoc<TStorage>;
|
|
135
|
-
declare const yjs_CrdtYjsDoc: typeof CrdtYjsDoc;
|
|
136
|
-
type yjs_CrdtYjsMap<T extends unknown> = CrdtYjsMap<T>;
|
|
137
|
-
declare const yjs_CrdtYjsMap: typeof CrdtYjsMap;
|
|
138
|
-
type yjs_CrdtYjsObject<T extends Record<string, any>> = CrdtYjsObject<T>;
|
|
139
|
-
declare const yjs_CrdtYjsObject: typeof CrdtYjsObject;
|
|
140
|
-
type yjs_CrdtYjsText = CrdtYjsText;
|
|
141
|
-
declare const yjs_CrdtYjsText: typeof CrdtYjsText;
|
|
142
|
-
type yjs_CrdtYjsXmlElement = CrdtYjsXmlElement;
|
|
143
|
-
declare const yjs_CrdtYjsXmlElement: typeof CrdtYjsXmlElement;
|
|
144
|
-
type yjs_CrdtYjsXmlFragment = CrdtYjsXmlFragment;
|
|
145
|
-
declare const yjs_CrdtYjsXmlFragment: typeof CrdtYjsXmlFragment;
|
|
146
|
-
type yjs_CrdtYjsXmlText = CrdtYjsXmlText;
|
|
147
|
-
declare const yjs_CrdtYjsXmlText: typeof CrdtYjsXmlText;
|
|
148
|
-
type yjs_InferYjsJson<T extends unknown> = InferYjsJson<T>;
|
|
149
|
-
type yjs_InferYjsType<T extends unknown> = InferYjsType<T>;
|
|
69
|
+
type yjs_YjsType<TValue extends unknown, TJson extends unknown = any> = YjsType<TValue, TJson>;
|
|
150
70
|
declare const yjs_array: typeof array;
|
|
151
71
|
declare const yjs_doc: typeof doc;
|
|
152
72
|
declare const yjs_map: typeof map;
|
|
153
73
|
declare const yjs_object: typeof object;
|
|
74
|
+
declare const yjs_text: typeof text;
|
|
154
75
|
declare const yjs_xmlElement: typeof xmlElement;
|
|
155
76
|
declare const yjs_xmlFragment: typeof xmlFragment;
|
|
156
77
|
declare const yjs_xmlText: typeof xmlText;
|
|
157
78
|
declare namespace yjs {
|
|
158
|
-
export {
|
|
79
|
+
export { type yjs_YjsType as YjsType, yjs_array as array, yjs_doc as doc, yjs_map as map, yjs_object as object, yjs_text as text, yjs_xmlElement as xmlElement, yjs_xmlFragment as xmlFragment, yjs_xmlText as xmlText };
|
|
159
80
|
}
|
|
160
81
|
|
|
161
82
|
export { yjs };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,102 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Json } from '@pluv/types';
|
|
1
|
+
import { Array, Doc, Map, Text, XmlElement, XmlText, XmlFragment } from 'yjs';
|
|
2
|
+
import { CrdtType, AbstractCrdtDoc, DocApplyEncodedStateParams, DocSubscribeCallbackParams, InferCrdtJson, AbstractCrdtDocFactory } from '@pluv/crdt';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
initialValue
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
get size(): number;
|
|
10
|
-
delete(prop: string): this;
|
|
11
|
-
set(prop: string, value: T): this;
|
|
12
|
-
toJson(): InferCrdtStorageJson<Record<string, InferYjsJson<T>>>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare const map: <T extends unknown>(value?: readonly (readonly [key: string, value: T])[]) => CrdtYjsMap<T>;
|
|
16
|
-
|
|
17
|
-
declare class CrdtYjsObject<T extends Record<string, any>> extends AbstractCrdtType<Map<InferYjsType<T[keyof T]>>, InferYjsJson<T>> {
|
|
18
|
-
initialValue: readonly (readonly [key: string, value: T[keyof T]])[];
|
|
19
|
-
value: Map<InferYjsType<T[keyof T]>>;
|
|
20
|
-
constructor(value?: T);
|
|
21
|
-
set<TProp extends keyof T>(prop: TProp, value: T[TProp]): this;
|
|
22
|
-
toJson(): InferCrdtStorageJson<InferYjsJson<T>>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
declare const object: <T extends Record<string, any>>(value: T) => CrdtYjsObject<T>;
|
|
26
|
-
|
|
27
|
-
declare class CrdtYjsText extends AbstractCrdtType<Text, string> {
|
|
28
|
-
readonly initialValue: string;
|
|
29
|
-
value: Text;
|
|
30
|
-
constructor(value?: string);
|
|
31
|
-
get length(): number;
|
|
32
|
-
delete(index: number, length?: number): this;
|
|
33
|
-
insert(index: number, text: string): this;
|
|
34
|
-
toJson(): string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
declare class CrdtYjsXmlText extends AbstractCrdtType<XmlText, string> {
|
|
38
|
-
readonly initialValue: string;
|
|
39
|
-
value: XmlText;
|
|
40
|
-
constructor(value?: string);
|
|
41
|
-
get length(): number;
|
|
42
|
-
delete(index: number, length?: number): this;
|
|
43
|
-
insert(index: number, text: string, attributes?: Record<string, string>): this;
|
|
44
|
-
toJson(): string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
declare class CrdtYjsXmlElement extends AbstractCrdtType<XmlElement, string> {
|
|
48
|
-
readonly initialValue: readonly (XmlElement | XmlText)[];
|
|
49
|
-
readonly name: string;
|
|
50
|
-
value: XmlElement;
|
|
51
|
-
constructor(name: string, children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]);
|
|
52
|
-
get length(): number;
|
|
53
|
-
delete(index: number, length?: number): this;
|
|
54
|
-
insert(index: number, ...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
55
|
-
push(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
56
|
-
unshift(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
57
|
-
toJson(): string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
declare const xmlText: (value?: string) => CrdtYjsXmlText;
|
|
61
|
-
|
|
62
|
-
declare const xmlElement: (name: string, children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]) => CrdtYjsXmlElement;
|
|
63
|
-
|
|
64
|
-
declare class CrdtYjsXmlFragment extends AbstractCrdtType<XmlFragment, string> {
|
|
65
|
-
readonly initialValue: readonly (XmlElement | XmlText)[];
|
|
66
|
-
value: XmlFragment;
|
|
67
|
-
constructor(children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]);
|
|
68
|
-
get length(): number;
|
|
69
|
-
delete(index: number, length?: number): this;
|
|
70
|
-
insert(index: number, ...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
71
|
-
push(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
72
|
-
unshift(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this;
|
|
73
|
-
toJson(): string;
|
|
74
|
-
}
|
|
4
|
+
type YjsType<TValue extends unknown, TJson extends unknown = any> = CrdtType<TValue, TJson> & {
|
|
5
|
+
initialValue?: any;
|
|
6
|
+
toJSON: () => any;
|
|
7
|
+
};
|
|
75
8
|
|
|
76
|
-
declare const
|
|
9
|
+
declare const array: <T extends unknown>(value?: T[] | readonly T[]) => YjsType<Array<T>, T[]>;
|
|
77
10
|
|
|
78
|
-
|
|
79
|
-
type InferYjsJson<T extends unknown> = T extends CrdtYjsArray<infer IType> ? InferYjsJson<IType>[] : T extends CrdtYjsMap<infer IType> ? Record<string, InferYjsJson<IType>> : T extends CrdtYjsObject<infer IType> ? {
|
|
80
|
-
[P in keyof IType]: InferYjsJson<IType[P]>;
|
|
81
|
-
} : T extends CrdtYjsText | CrdtYjsXmlElement | CrdtYjsXmlFragment | CrdtYjsXmlText | Text | XmlElement | XmlFragment | XmlText ? string : T extends Array<infer IType> ? InferYjsJson<IType>[] : T extends Map<infer IType> ? Record<string, InferYjsJson<IType>> : T extends (infer IType)[] ? InferYjsJson<IType>[] : T extends Record<any, any> ? {
|
|
82
|
-
[P in keyof T]: InferYjsJson<T[P]>;
|
|
83
|
-
} : T extends Json ? T : never;
|
|
84
|
-
|
|
85
|
-
declare class CrdtYjsArray<T extends unknown> extends AbstractCrdtType<Array<InferYjsType<T>>, InferYjsJson<T>[]> {
|
|
86
|
-
readonly initialValue: InferYjsType<T>[] | readonly InferYjsType<T>[];
|
|
87
|
-
value: Array<InferYjsType<T>>;
|
|
88
|
-
constructor(value?: T[] | readonly T[]);
|
|
89
|
-
get length(): number;
|
|
90
|
-
delete(index: number, length?: number): this;
|
|
91
|
-
insert(index: number, ...items: T[]): this;
|
|
92
|
-
push(...items: T[]): this;
|
|
93
|
-
unshift(...items: T[]): this;
|
|
94
|
-
toJson(): InferCrdtStorageJson<InferYjsJson<T>>[];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
declare const array: <T extends unknown>(value?: T[] | readonly T[]) => CrdtYjsArray<T>;
|
|
98
|
-
|
|
99
|
-
declare class CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, any>>> extends AbstractCrdtDoc<TStorage> {
|
|
11
|
+
declare class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> extends AbstractCrdtDoc<TStorage> {
|
|
100
12
|
value: Doc;
|
|
101
13
|
private _storage;
|
|
102
14
|
private _undoManager;
|
|
@@ -107,18 +19,19 @@ declare class CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, a
|
|
|
107
19
|
canUndo(): boolean;
|
|
108
20
|
destroy(): void;
|
|
109
21
|
get(key?: undefined): TStorage;
|
|
110
|
-
get<TKey extends keyof TStorage>(
|
|
22
|
+
get<TKey extends keyof TStorage>(type: TKey): TStorage[TKey];
|
|
111
23
|
getEncodedState(): string;
|
|
112
24
|
isEmpty(): boolean;
|
|
113
25
|
redo(): this;
|
|
114
26
|
subscribe(listener: (params: DocSubscribeCallbackParams<TStorage>) => void): () => void;
|
|
115
27
|
track(): this;
|
|
116
28
|
transact(fn: () => void): this;
|
|
117
|
-
toJson():
|
|
29
|
+
toJson(): InferCrdtJson<TStorage>;
|
|
30
|
+
toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
|
|
118
31
|
undo(): this;
|
|
119
32
|
}
|
|
120
33
|
|
|
121
|
-
declare class CrdtYjsDocFactory<TStorage extends Record<string,
|
|
34
|
+
declare class CrdtYjsDocFactory<TStorage extends Record<string, YjsType<any, any>>> extends AbstractCrdtDocFactory<TStorage> {
|
|
122
35
|
private _initialStorage;
|
|
123
36
|
constructor(initialStorage?: () => TStorage);
|
|
124
37
|
getEmpty(): CrdtYjsDoc<TStorage>;
|
|
@@ -127,35 +40,43 @@ declare class CrdtYjsDocFactory<TStorage extends Record<string, AbstractCrdtType
|
|
|
127
40
|
getInitialized(initialStorage?: () => TStorage): CrdtYjsDoc<TStorage>;
|
|
128
41
|
}
|
|
129
42
|
|
|
130
|
-
declare const doc: <TStorage extends Record<string,
|
|
43
|
+
declare const doc: <TStorage extends Record<string, YjsType<any, any>>>(value?: () => TStorage) => CrdtYjsDocFactory<TStorage>;
|
|
44
|
+
|
|
45
|
+
declare const map: <T extends unknown>(value?: readonly (readonly [key: string, value: T])[]) => YjsType<Map<T>, Record<string, T>>;
|
|
46
|
+
|
|
47
|
+
declare const object: <T extends Record<string, any>>(value?: T) => YjsType<Map<T[keyof T]>, T>;
|
|
48
|
+
|
|
49
|
+
declare const text: (value?: string) => YjsType<Text, string>;
|
|
50
|
+
|
|
51
|
+
declare class YjsXmlElement<T extends Record<string, any> = Record<string, any>> extends XmlElement<T> implements YjsType<XmlElement, string> {
|
|
52
|
+
initialValue?: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[];
|
|
53
|
+
constructor(name: string, value: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[]);
|
|
54
|
+
__pluvType(): any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare const xmlElement: <T extends Record<string, any> = Record<string, any>>(name: string, children: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[]) => YjsXmlElement<T>;
|
|
58
|
+
|
|
59
|
+
declare class YjsXmlFragment extends XmlFragment implements YjsType<XmlFragment, string> {
|
|
60
|
+
initialValue?: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[];
|
|
61
|
+
constructor(value: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[]);
|
|
62
|
+
__pluvType(): any;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare const xmlFragment: (children: (XmlElement | XmlText)[] | readonly (XmlElement | XmlText)[]) => YjsXmlFragment;
|
|
66
|
+
|
|
67
|
+
declare const xmlText: () => YjsType<XmlText, string>;
|
|
131
68
|
|
|
132
|
-
type
|
|
133
|
-
declare const yjs_CrdtYjsArray: typeof CrdtYjsArray;
|
|
134
|
-
type yjs_CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, any>>> = CrdtYjsDoc<TStorage>;
|
|
135
|
-
declare const yjs_CrdtYjsDoc: typeof CrdtYjsDoc;
|
|
136
|
-
type yjs_CrdtYjsMap<T extends unknown> = CrdtYjsMap<T>;
|
|
137
|
-
declare const yjs_CrdtYjsMap: typeof CrdtYjsMap;
|
|
138
|
-
type yjs_CrdtYjsObject<T extends Record<string, any>> = CrdtYjsObject<T>;
|
|
139
|
-
declare const yjs_CrdtYjsObject: typeof CrdtYjsObject;
|
|
140
|
-
type yjs_CrdtYjsText = CrdtYjsText;
|
|
141
|
-
declare const yjs_CrdtYjsText: typeof CrdtYjsText;
|
|
142
|
-
type yjs_CrdtYjsXmlElement = CrdtYjsXmlElement;
|
|
143
|
-
declare const yjs_CrdtYjsXmlElement: typeof CrdtYjsXmlElement;
|
|
144
|
-
type yjs_CrdtYjsXmlFragment = CrdtYjsXmlFragment;
|
|
145
|
-
declare const yjs_CrdtYjsXmlFragment: typeof CrdtYjsXmlFragment;
|
|
146
|
-
type yjs_CrdtYjsXmlText = CrdtYjsXmlText;
|
|
147
|
-
declare const yjs_CrdtYjsXmlText: typeof CrdtYjsXmlText;
|
|
148
|
-
type yjs_InferYjsJson<T extends unknown> = InferYjsJson<T>;
|
|
149
|
-
type yjs_InferYjsType<T extends unknown> = InferYjsType<T>;
|
|
69
|
+
type yjs_YjsType<TValue extends unknown, TJson extends unknown = any> = YjsType<TValue, TJson>;
|
|
150
70
|
declare const yjs_array: typeof array;
|
|
151
71
|
declare const yjs_doc: typeof doc;
|
|
152
72
|
declare const yjs_map: typeof map;
|
|
153
73
|
declare const yjs_object: typeof object;
|
|
74
|
+
declare const yjs_text: typeof text;
|
|
154
75
|
declare const yjs_xmlElement: typeof xmlElement;
|
|
155
76
|
declare const yjs_xmlFragment: typeof xmlFragment;
|
|
156
77
|
declare const yjs_xmlText: typeof xmlText;
|
|
157
78
|
declare namespace yjs {
|
|
158
|
-
export {
|
|
79
|
+
export { type yjs_YjsType as YjsType, yjs_array as array, yjs_doc as doc, yjs_map as map, yjs_object as object, yjs_text as text, yjs_xmlElement as xmlElement, yjs_xmlFragment as xmlFragment, yjs_xmlText as xmlText };
|
|
159
80
|
}
|
|
160
81
|
|
|
161
82
|
export { yjs };
|