@pluv/crdt-yjs 5.0.0 → 5.0.2

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 (43) hide show
  1. package/dist/index.d.mts +0 -1
  2. package/dist/index.d.mts.map +1 -1
  3. package/package.json +14 -11
  4. package/.turbo/turbo-build.log +0 -19
  5. package/CHANGELOG.md +0 -1623
  6. package/eslint.config.mjs +0 -4
  7. package/src/array/YjsArray.ts +0 -18
  8. package/src/array/array.ts +0 -9
  9. package/src/array/index.ts +0 -2
  10. package/src/awareness/PluvYjsAwareness.ts +0 -220
  11. package/src/awareness/awareness.ts +0 -15
  12. package/src/awareness/index.ts +0 -2
  13. package/src/constants.ts +0 -2
  14. package/src/doc/CrdtYjsDoc.ts +0 -241
  15. package/src/doc/CrdtYjsDocFactory.ts +0 -33
  16. package/src/doc/builder.ts +0 -71
  17. package/src/doc/doc.ts +0 -9
  18. package/src/doc/index.ts +0 -4
  19. package/src/index.ts +0 -5
  20. package/src/map/YjsMap.ts +0 -19
  21. package/src/map/index.ts +0 -2
  22. package/src/map/map.ts +0 -9
  23. package/src/provider/PluvYjsProvider.ts +0 -132
  24. package/src/provider/index.ts +0 -2
  25. package/src/provider/provider.ts +0 -15
  26. package/src/text/YjsText.ts +0 -16
  27. package/src/text/index.ts +0 -2
  28. package/src/text/text.ts +0 -7
  29. package/src/types.ts +0 -35
  30. package/src/utils/index.ts +0 -1
  31. package/src/utils/oneLine.ts +0 -7
  32. package/src/xmlElement/YjsXmlElement.ts +0 -25
  33. package/src/xmlElement/index.ts +0 -2
  34. package/src/xmlElement/xmlElement.ts +0 -9
  35. package/src/xmlFragment/YjsXmlFragment.ts +0 -19
  36. package/src/xmlFragment/index.ts +0 -2
  37. package/src/xmlFragment/xmlFragment.ts +0 -8
  38. package/src/xmlText/YjsXmlText.ts +0 -16
  39. package/src/xmlText/index.ts +0 -2
  40. package/src/xmlText/xmlText.ts +0 -7
  41. package/src/yjs.ts +0 -12
  42. package/tsconfig.json +0 -8
  43. package/tsdown.config.ts +0 -14
@@ -1,132 +0,0 @@
1
- import type { CrdtType, IOLike, PluvRouterEventConfig, RoomLike } from "@pluv/types";
2
- import { StorageState } from "@pluv/types";
3
- import { ObservableV2 } from "lib0/observable";
4
- import type { Doc as YDoc } from "yjs";
5
- import type { PluvYjsAwareness } from "../awareness";
6
- import { awareness } from "../awareness";
7
- import type { YjsProviderStatus } from "../types";
8
-
9
- export interface PluvYjsProviderParams<
10
- TIO extends IOLike<any, any, any>,
11
- TPresence extends Record<string, any>,
12
- TStorage extends Record<string, CrdtType<any, any>>,
13
- TEvents extends PluvRouterEventConfig,
14
- TField extends keyof TPresence | null = null,
15
- > {
16
- presenceField?: TField;
17
- room: RoomLike<TIO, YDoc, TPresence, TStorage, TEvents>;
18
- }
19
-
20
- /**
21
- * !HACK
22
- * @description This doesn't really do anything but emit states in a Yjs.Provider compatible way.
23
- * Connections and document syncing are handled by the PluvRoom already.
24
- * @date May 13, 2025
25
- */
26
- export class PluvYjsProvider<
27
- TIO extends IOLike<any, any, any>,
28
- TPresence extends Record<string, any>,
29
- TStorage extends Record<string, CrdtType<any, any>>,
30
- TEvents extends PluvRouterEventConfig,
31
- TField extends keyof TPresence | null = null,
32
- > extends ObservableV2<{
33
- "connection-close": (
34
- event: CloseEvent | null,
35
- provider: PluvYjsProvider<TIO, TPresence, TStorage, TEvents, TField>,
36
- ) => void;
37
- "connection-error": (
38
- event: Event,
39
- provider: PluvYjsProvider<TIO, TPresence, TStorage, TEvents, TField>,
40
- ) => void;
41
- status: (event: { status: YjsProviderStatus }) => void;
42
- sync: (state: boolean) => void;
43
- synced: (state: boolean) => void;
44
- }> {
45
- public readonly awareness: PluvYjsAwareness<TIO, TPresence, TStorage, TEvents, TField>;
46
- public readonly doc: YDoc;
47
-
48
- private readonly _room: RoomLike<TIO, YDoc, TPresence, TStorage, TEvents>;
49
- private readonly _unsubscribe: () => void;
50
-
51
- private _synced: boolean = false;
52
-
53
- constructor(params: PluvYjsProviderParams<TIO, TPresence, TStorage, TEvents, TField>) {
54
- super();
55
-
56
- const { presenceField, room } = params;
57
-
58
- this.awareness = awareness({ presenceField, room });
59
- this.doc = room.getDoc().value;
60
-
61
- this._room = room;
62
-
63
- const subscriptions = [
64
- this._room.subscribe.connection(({ storage }) => {
65
- const status = this._toProviderStatus(storage.state);
66
-
67
- if (!status) return;
68
-
69
- this.emit("status", [{ status }]);
70
- }),
71
- this._room.addEventListener("close", (event) => {
72
- this.emit("connection-close", [event, this]);
73
- }),
74
- this._room.addEventListener("error", (event) => {
75
- this.emit("connection-error", [event, this]);
76
- }),
77
- ];
78
-
79
- this._unsubscribe = subscriptions.reduce(
80
- (fn, unsubscribe) => () => {
81
- fn();
82
- unsubscribe();
83
- },
84
- () => undefined,
85
- );
86
- }
87
-
88
- public get synced(): boolean {
89
- return this._synced;
90
- }
91
-
92
- public set synced(state: boolean) {
93
- if (this._synced === state) return;
94
-
95
- this._synced = state;
96
- this.emit("sync", [state]);
97
- this.emit("synced", [state]);
98
- }
99
-
100
- public destroy(): void {
101
- this.awareness.destroy();
102
- this._unsubscribe();
103
- super.destroy();
104
- }
105
-
106
- private _toProviderStatus(state: StorageState): YjsProviderStatus | null {
107
- switch (state) {
108
- case StorageState.Loading: {
109
- return "connecting";
110
- }
111
- case StorageState.Unavailable: {
112
- return "disconnected";
113
- }
114
- case StorageState.Offline:
115
- case StorageState.Synced: {
116
- return "connected";
117
- }
118
- default:
119
- return null;
120
- }
121
- }
122
-
123
- /**
124
- * !HACK
125
- * @description We dgaf about these, since the room manages these already. We're just mirroring
126
- * the fields that exist in the og provider to make sure everything aligns.
127
- * @see https://github.com/yjs/y-websocket/blob/master/src/y-websocket.js
128
- * @date May 13, 2025
129
- */
130
- public connect(): void {}
131
- public disconnect(): void {}
132
- }
@@ -1,2 +0,0 @@
1
- export type { PluvYjsProvider } from "./PluvYjsProvider";
2
- export { provider } from "./provider";
@@ -1,15 +0,0 @@
1
- import type { CrdtType, IOLike, PluvRouterEventConfig } from "@pluv/types";
2
- import type { PluvYjsProviderParams } from "./PluvYjsProvider";
3
- import { PluvYjsProvider } from "./PluvYjsProvider";
4
-
5
- export const provider = <
6
- TIO extends IOLike<any, any, any>,
7
- TPresence extends Record<string, any>,
8
- TStorage extends Record<string, CrdtType<any, any>>,
9
- TEvents extends PluvRouterEventConfig,
10
- TField extends keyof TPresence | null = null,
11
- >(
12
- params: PluvYjsProviderParams<TIO, TPresence, TStorage, TEvents, TField>,
13
- ) => {
14
- return new PluvYjsProvider(params);
15
- };
@@ -1,16 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- export { text } from "./text";
2
- export type { YjsText } from "./YjsText";
package/src/text/text.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { Text as YText } from "yjs";
2
- import type { YjsType } from "../types";
3
- import { YjsText } from "./YjsText";
4
-
5
- export const text = (value: string = ""): YjsType<YText, string> => {
6
- return new YjsText(value);
7
- };
package/src/types.ts DELETED
@@ -1,35 +0,0 @@
1
- import type { CrdtType } from "@pluv/crdt";
2
-
3
- export type YjsType<TValue extends unknown, TJson extends unknown = any> = CrdtType<
4
- TValue,
5
- TJson
6
- > & {
7
- initialValue?: any;
8
- toJSON: () => any;
9
- };
10
-
11
- /**
12
- * @description Type internally defined by Yjs.Awareness
13
- * @see https://github.com/yjs/y-protocols/blob/master/awareness.js
14
- */
15
- export interface YjsAwarenessUpdate {
16
- added: number[];
17
- updated: number[];
18
- removed: number[];
19
- }
20
-
21
- export type YjsProviderStatus = "connecting" | "connected" | "disconnected";
22
-
23
- /**
24
- * @description Type internally defined by Yjs.Awareness
25
- * @see https://github.com/yjs/y-protocols/blob/master/awareness.js
26
- */
27
- export interface MetaClientState {
28
- clock: number;
29
- lastUpdated: number;
30
- }
31
-
32
- export type AwarenessPresence<
33
- TPresence extends Record<string, any>,
34
- TField extends keyof TPresence | null,
35
- > = TField extends null ? TPresence : TField extends keyof TPresence ? TPresence[TField] : never;
@@ -1 +0,0 @@
1
- export { oneLine } from "./oneLine";
@@ -1,7 +0,0 @@
1
- export const oneLine = (strings: TemplateStringsArray, ...values: unknown[]): string => {
2
- return strings
3
- .map((str) => str.replace(/\s+/g, " "))
4
- .reduce((acc, str, i) => acc + str + (i < values.length ? values[i] : ""), "")
5
- .replace(/\s+/g, " ")
6
- .trim();
7
- };
@@ -1,25 +0,0 @@
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(
12
- name: string,
13
- value: (YXmlElement | YXmlText)[] | readonly (YXmlElement | YXmlText)[],
14
- ) {
15
- super(name);
16
-
17
- if (!!value.length) this.insert(0, value as (YXmlElement | YXmlText)[]);
18
-
19
- this.initialValue = value;
20
- }
21
-
22
- public __pluvType() {
23
- return {} as unknown as any;
24
- }
25
- }
@@ -1,2 +0,0 @@
1
- export { xmlElement } from "./xmlElement";
2
- export type { YjsXmlElement } from "./YjsXmlElement";
@@ -1,9 +0,0 @@
1
- import type { XmlText as YXmlText, XmlElement as YXmlElement } from "yjs";
2
- import { YjsXmlElement } from "./YjsXmlElement";
3
-
4
- export const xmlElement = <T extends Record<string, any> = Record<string, any>>(
5
- name: string,
6
- children: (YXmlElement | YXmlText)[] | readonly (YXmlElement | YXmlText)[],
7
- ): YjsXmlElement<T> => {
8
- return new YjsXmlElement<T>(name, children);
9
- };
@@ -1,19 +0,0 @@
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
- if (!!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 +0,0 @@
1
- export { xmlFragment } from "./xmlFragment";
2
- export type { YjsXmlFragment } from "./YjsXmlFragment";
@@ -1,8 +0,0 @@
1
- import type { XmlElement as YXmlElement, XmlText as YXmlText } from "yjs";
2
- import { YjsXmlFragment } from "./YjsXmlFragment";
3
-
4
- export const xmlFragment = (
5
- children: (YXmlElement | YXmlText)[] | readonly (YXmlElement | YXmlText)[],
6
- ): YjsXmlFragment => {
7
- return new YjsXmlFragment(children);
8
- };
@@ -1,16 +0,0 @@
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 +0,0 @@
1
- export { xmlText } from "./xmlText";
2
- export type { YjsXmlText } from "./YjsXmlText";
@@ -1,7 +0,0 @@
1
- import type { XmlText as YXmlText } from "yjs";
2
- import { YjsType } from "../types";
3
- import { YjsXmlText } from "./YjsXmlText";
4
-
5
- export const xmlText = (): YjsType<YXmlText, string> => {
6
- return new YjsXmlText();
7
- };
package/src/yjs.ts DELETED
@@ -1,12 +0,0 @@
1
- export { array } from "./array";
2
- export { awareness } from "./awareness";
3
- export { doc } from "./doc";
4
- export type { YjsBuilder } from "./doc";
5
- export { map } from "./map";
6
- export { provider } from "./provider";
7
- export { text } from "./text";
8
- export type { YjsType } from "./types";
9
- export { xmlElement } from "./xmlElement";
10
- export { xmlFragment } from "./xmlFragment";
11
- export { xmlText } from "./xmlText";
12
- export const kind = "yjs" as const;
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "@pluv/tsconfig/library.json",
3
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
4
- "exclude": ["node_modules"],
5
- "compilerOptions": {
6
- "lib": ["dom", "esnext"]
7
- }
8
- }
package/tsdown.config.ts DELETED
@@ -1,14 +0,0 @@
1
- import { defineConfig } from "tsdown";
2
-
3
- export default defineConfig({
4
- format: ["esm"],
5
- dts: true,
6
- outDir: "dist",
7
- entry: "src/index.ts",
8
- target: "esnext",
9
- sourcemap: true,
10
- clean: true,
11
- exports: {
12
- all: true,
13
- },
14
- });