Skip to content

Commit 0684daf

Browse files
chore
1 parent 91f82f1 commit 0684daf

File tree

4 files changed

+68
-64
lines changed

4 files changed

+68
-64
lines changed

editor/grida-canvas/editor.i.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,65 @@ export namespace editor.a11y {
19141914
} as const;
19151915
}
19161916

1917+
export namespace editor.multiplayer {
1918+
export type AwarenessPayload = {
1919+
/**
1920+
* user-window-session unique cursor id
1921+
*
1922+
* one user can have multiple cursors (if multiple windows are open)
1923+
*/
1924+
cursor_id: string;
1925+
/**
1926+
* player profile information (rarely changes)
1927+
*/
1928+
profile: {
1929+
/**
1930+
* theme colors for this player within collaboration ui
1931+
*/
1932+
palette: editor.state.MultiplayerCursorColorPalette;
1933+
};
1934+
/**
1935+
* current focus state (changes when switching pages/selecting)
1936+
*/
1937+
focus: {
1938+
/**
1939+
* player's current scene (page)
1940+
*/
1941+
scene_id: string | undefined;
1942+
/**
1943+
* the selection (node ids) of this player
1944+
*/
1945+
selection: string[];
1946+
};
1947+
/**
1948+
* geometric state (changes frequently with mouse movement)
1949+
*/
1950+
geo: {
1951+
/**
1952+
* current transform (camera)
1953+
*/
1954+
transform: cmath.Transform;
1955+
/**
1956+
* current cursor position
1957+
*/
1958+
position: [number, number];
1959+
/**
1960+
* marquee start point
1961+
* the full marquee is a rect with marquee_a and position (current cursor position)
1962+
*/
1963+
marquee_a: [number, number] | null;
1964+
};
1965+
/**
1966+
* cursor chat is a ephemeral message that lives for a short time and disappears after few seconds (as configured)
1967+
* only the last message is kept
1968+
*/
1969+
cursor_chat: {
1970+
txt: string;
1971+
ts: number;
1972+
} | null;
1973+
};
1974+
}
1975+
19171976
export namespace editor.api {
19181977
export type SubscriptionCallbackFn<T = any> = (
19191978
editor: T,

editor/grida-canvas/editor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,8 +2106,8 @@ export class Editor
21062106
this.doc = new EditorDocumentStore(
21072107
grida.id.noop.generator, // test only
21082108
// // TODO: resolve from server
2109-
// new grida.id.i32.NodeIdGenerator({
2110-
// actor: grida.id.i32.k.OFFLINE_ACTOR_ID,
2109+
// new grida.id.u32.NodeIdGenerator({
2110+
// actor: grida.id.u32.k.OFFLINE_ACTOR_ID,
21112111
// }),
21122112
initialState,
21132113
backend,

editor/grida-canvas/plugins/sync-y.ts

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,11 @@ import { editor } from "..";
33
import { WebsocketProvider } from "y-websocket";
44
import type { Awareness } from "y-protocols/awareness";
55
import type { Editor, EditorDocumentStore } from "../editor";
6-
import type cmath from "@grida/cmath";
76
import type grida from "@grida/schema";
87
import type { Patch } from "immer";
98
import { YPatchBinder } from "./sync-y-patches";
109
import equal from "fast-deep-equal";
1110

12-
type AwarenessPayload = {
13-
/**
14-
* user-window-session unique cursor id
15-
*
16-
* one user can have multiple cursors (if multiple windows are open)
17-
*/
18-
cursor_id: string;
19-
/**
20-
* player profile information (rarely changes)
21-
*/
22-
profile: {
23-
/**
24-
* theme colors for this player within collaboration ui
25-
*/
26-
palette: editor.state.MultiplayerCursorColorPalette;
27-
};
28-
/**
29-
* current focus state (changes when switching pages/selecting)
30-
*/
31-
focus: {
32-
/**
33-
* player's current scene (page)
34-
*/
35-
scene_id: string | undefined;
36-
/**
37-
* the selection (node ids) of this player
38-
*/
39-
selection: string[];
40-
};
41-
/**
42-
* geometric state (changes frequently with mouse movement)
43-
*/
44-
geo: {
45-
/**
46-
* current transform (camera)
47-
*/
48-
transform: cmath.Transform;
49-
/**
50-
* current cursor position
51-
*/
52-
position: [number, number];
53-
/**
54-
* marquee start point
55-
* the full marquee is a rect with marquee_a and position (current cursor position)
56-
*/
57-
marquee_a: [number, number] | null;
58-
};
59-
/**
60-
* cursor chat is a ephemeral message that lives for a short time and disappears after few seconds (as configured)
61-
* only the last message is kept
62-
*/
63-
cursor_chat: {
64-
txt: string;
65-
ts: number;
66-
} | null;
67-
};
68-
6911
// Internal class for managing document synchronization
7012
class DocumentSyncManager {
7113
private __unsubscribe_document_change!: () => void;
@@ -301,7 +243,7 @@ class AwarenessSyncManager {
301243
private __unsubscribe_focus_change!: () => void;
302244

303245
private _currentState: Partial<
304-
Omit<AwarenessPayload, "cursor_id" | "profile">
246+
Omit<editor.multiplayer.AwarenessPayload, "cursor_id" | "profile">
305247
> = {};
306248

307249
private __unsubscribe_cursor_chat_change!: () => void;
@@ -326,7 +268,10 @@ class AwarenessSyncManager {
326268
return state && state.profile?.palette;
327269
})
328270
.map((_: any) => {
329-
const [id, state] = _ as [string, AwarenessPayload];
271+
const [id, state] = _ as [
272+
string,
273+
editor.multiplayer.AwarenessPayload,
274+
];
330275
const {
331276
cursor_id,
332277
profile: { palette },
@@ -453,7 +398,7 @@ class AwarenessSyncManager {
453398
marquee_a: null,
454399
},
455400
cursor_chat: this._currentState.cursor_chat || null,
456-
} satisfies AwarenessPayload);
401+
} satisfies editor.multiplayer.AwarenessPayload);
457402
}
458403

459404
public destroy() {

packages/grida-canvas-schema/grida.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export namespace grida {
5151
*
5252
* @see https://grida.co/docs/wg/feat-crdt/id
5353
*/
54-
export namespace i32 {
54+
export namespace u32 {
5555
//
5656

5757
export namespace k {

0 commit comments

Comments
 (0)