-
Notifications
You must be signed in to change notification settings - Fork 0
feat(canvas): add frontend structural document replica and op queue #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ import { useCanvasShortcutContainer } from "./shortcuts/useCanvasShortcutContain | |
| import type { NodeDragVisual } from "./dragVisuals"; | ||
| import { useCanvasDocument } from "./model/useCanvasDocument"; | ||
| import { createCursorPresenceStore } from "./presence/cursorPresenceStore"; | ||
| import { createCanvasDocumentStore } from "./document/canvasDocumentStore"; | ||
| import { createCanvasOperationQueueStore } from "./ops/canvasOperationQueueStore"; | ||
|
|
||
| interface CanvasProps { | ||
| canvasId: string; | ||
|
|
@@ -41,6 +43,10 @@ export function Canvas({ canvasId, userId, displayName }: CanvasProps) { | |
| const viewportRef = useRef<HTMLDivElement>(null); | ||
| const sendRef = useRef<((event: CanvasOutboundEvent) => void) | null>(null); | ||
| const cursorStore = useMemo(() => createCursorPresenceStore(), []); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| const documentStore = useMemo(() => createCanvasDocumentStore(), [canvasId]); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| const operationQueueStore = useMemo(() => createCanvasOperationQueueStore(), [canvasId]); | ||
|
Comment on lines
+46
to
+49
|
||
| const [remoteSelections, setRemoteSelections] = useState< | ||
| Map<string, Set<string>> | ||
| >(new Map()); | ||
|
|
@@ -76,6 +82,8 @@ export function Canvas({ canvasId, userId, displayName }: CanvasProps) { | |
| viewportRef, | ||
| transformRef, | ||
| sendRef, | ||
| documentStore, | ||
| operationQueueStore, | ||
| }); | ||
|
|
||
| const [tool, setTool] = useState<CanvasTool>("select"); | ||
|
|
@@ -85,15 +93,8 @@ export function Canvas({ canvasId, userId, displayName }: CanvasProps) { | |
|
|
||
| const collabHandlers = useMemo( | ||
| () => ({ | ||
| onNodeCreate: remote.applyNodeCreate, | ||
| onNodeMove: ( | ||
| remoteUserId: string, | ||
| nodeId: string, | ||
| x: number, | ||
| y: number, | ||
| ) => { | ||
| onNodeMove: (remoteUserId: string, nodeId: string, x: number, y: number) => { | ||
| const previousNode = getNodeById(nodeId); | ||
| remote.applyNodeMove(remoteUserId, nodeId, x, y); | ||
| if (!previousNode) return; | ||
|
|
||
| setRemoteDragStates((prev) => { | ||
|
|
@@ -130,10 +131,6 @@ export function Canvas({ canvasId, userId, displayName }: CanvasProps) { | |
| return next; | ||
| }); | ||
| }, | ||
| onNodeUpdate: remote.applyNodeUpdate, | ||
| onNodeDelete: remote.applyNodeDelete, | ||
| onEdgeCreate: remote.applyEdgeCreate, | ||
| onEdgeDelete: remote.applyEdgeDelete, | ||
| onNodeSelect: (remoteUserId: string, nodeIds: string[]) => { | ||
| setRemoteSelections((prev) => { | ||
| const next = new Map(prev); | ||
|
|
@@ -168,15 +165,17 @@ export function Canvas({ canvasId, userId, displayName }: CanvasProps) { | |
| remoteStrokes, | ||
| send, | ||
| onPointerMove: collabPointerMove, | ||
| } = useCanvasCollab( | ||
| } = useCanvasCollab({ | ||
| canvasId, | ||
| userId, | ||
| displayName, | ||
| viewportRef, | ||
| transformRef, | ||
| cursorStore, | ||
| collabHandlers, | ||
| ); | ||
| documentStore, | ||
| operationQueueStore, | ||
| handlers: collabHandlers, | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| sendRef.current = send; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doc now mentions the sender receiving the committed structural event as an ack, but the contract examples below still list structural outbound events without the required
clientOperationIdfield (and imply the old relay-style payloads). Please update the “Event Types (Client -> Server)” section (and any examples) to reflect the new structural message shape withclientOperationIdmetadata.