diff --git a/excalidraw-app/App.tsx b/excalidraw-app/App.tsx index 5ce79caf03..61dcf0369f 100644 --- a/excalidraw-app/App.tsx +++ b/excalidraw-app/App.tsx @@ -856,7 +856,7 @@ const ExcalidrawWrapper = () => { excalidrawAPI?.updateScene({ appState: { ...excalidrawAPI?.getAppState(), - viewModeEnabled: value !== acknowledgedIncrements.length, + viewModeEnabled: value !== -1, }, elements: Array.from(elements.values()), storeAction: StoreAction.UPDATE, @@ -865,7 +865,7 @@ const ExcalidrawWrapper = () => { currentVersion.current = value; }, 0); - const latestVersion = acknowledgedIncrements.length - 1; + const latestVersion = acknowledgedIncrements.length; return (
{ step={1} min={0} max={latestVersion} - value={ - nextVersion === -1 || nextVersion === latestVersion - ? latestVersion - : nextVersion - } + value={nextVersion === -1 ? latestVersion : nextVersion} onChange={(value) => { + let nextValue: number; + // CFDO: should be disabled when offline! (later we could have speculative changes in the versioning log as well) // CFDO: in safari the whole canvas gets selected when dragging if (value !== acknowledgedIncrements.length) { // don't listen to updates in the detached mode syncAPI?.disconnect(); + nextValue = value as number; } else { // reconnect once we're back to the latest version syncAPI?.connect(); + nextValue = -1; } - setNextVersion(value as number); - debouncedTimeTravel(value as number); + setNextVersion(nextValue); + debouncedTimeTravel(nextValue); }} /> { + console.debug(`Connection to the room "${this.roomId}" opened.`); this.isOffline = false; this.handlers.onOpen(event); }; + + private onClose = (event: CloseEvent) => { + console.debug(`Connection to the room "${this.roomId}" closed.`, event); + }; + + private onError = (event: Event) => { + console.debug( + `Connection to the room "${this.roomId}" returned an error.`, + event, + ); + }; } interface AcknowledgedIncrement { @@ -258,9 +260,12 @@ export class SyncClient { repository: IncrementsRepository & MetadataRepository, ) { const queue = await SyncQueue.create(repository); + // CFDO: temporary for custom roomId (though E+ will be similar) + const roomId = window.location.pathname.split("/").at(-1); + return new SyncClient(api, repository, queue, { host: SyncClient.HOST_URL, - roomId: SyncClient.ROOM_ID, + roomId: roomId ?? SyncClient.ROOM_ID, // CFDO: temporary, so that all increments are loaded and applied on init lastAcknowledgedVersion: 0, }); diff --git a/packages/excalidraw/tests/history.test.tsx b/packages/excalidraw/tests/history.test.tsx index f8957766c6..a58a45d903 100644 --- a/packages/excalidraw/tests/history.test.tsx +++ b/packages/excalidraw/tests/history.test.tsx @@ -64,6 +64,12 @@ const checkpoint = (name: string) => { ...strippedAppState } = h.state; expect(strippedAppState).toMatchSnapshot(`[${name}] appState`); + expect(h.elements.length).toMatchSnapshot(`[${name}] number of elements`); + h.elements + .map(({ seed, versionNonce, ...strippedElement }) => strippedElement) + .forEach((element, i) => + expect(element).toMatchSnapshot(`[${name}] element ${i}`), + ); const stripSeed = (deltas: Record) => Object.entries(deltas).reduce((acc, curr) => { @@ -92,6 +98,7 @@ const checkpoint = (name: string) => { }, })), ).toMatchSnapshot(`[${name}] undo stack`); + expect( h.history.redoStack.map((x) => ({ ...x, @@ -103,12 +110,6 @@ const checkpoint = (name: string) => { }, })), ).toMatchSnapshot(`[${name}] redo stack`); - expect(h.elements.length).toMatchSnapshot(`[${name}] number of elements`); - h.elements - .map(({ seed, versionNonce, ...strippedElement }) => strippedElement) - .forEach((element, i) => - expect(element).toMatchSnapshot(`[${name}] element ${i}`), - ); }; const renderStaticScene = vi.spyOn(StaticScene, "renderStaticScene");