From 25fd27515866b5704066d9301dd641c481f6c38c Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Sun, 28 Mar 2021 19:26:03 +0530 Subject: [PATCH] fix: Don't share collab types with core (#3353) * fix: Don't share collab types with core * fix * remove * fix --- src/components/App.tsx | 3 --- src/excalidraw-app/collab/CollabWrapper.tsx | 19 ++++++++++++++++--- src/excalidraw-app/collab/Portal.tsx | 2 +- src/excalidraw-app/collab/types.ts | 5 ----- src/excalidraw-app/data/index.ts | 3 +-- src/renderer/renderScene.ts | 2 +- src/tests/collab.test.tsx | 2 +- src/tests/test-utils.ts | 2 +- src/types.ts | 7 ++++++- 9 files changed, 27 insertions(+), 18 deletions(-) delete mode 100644 src/excalidraw-app/collab/types.ts diff --git a/src/components/App.tsx b/src/components/App.tsx index f179aa98b1..bc47f5701b 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -4111,9 +4111,6 @@ declare global { history: SceneHistory; app: InstanceType; library: typeof Library; - collab: InstanceType< - typeof import("../excalidraw-app/collab/CollabWrapper").default - >; }; } } diff --git a/src/excalidraw-app/collab/CollabWrapper.tsx b/src/excalidraw-app/collab/CollabWrapper.tsx index 9b353eb68b..de87184cce 100644 --- a/src/excalidraw-app/collab/CollabWrapper.tsx +++ b/src/excalidraw-app/collab/CollabWrapper.tsx @@ -38,7 +38,7 @@ import Portal from "./Portal"; import RoomDialog from "./RoomDialog"; import { createInverseContext } from "../../createInverseContext"; import { t } from "../../i18n"; -import { UserIdleState } from "./types"; +import { UserIdleState } from "../../types"; import { IDLE_THRESHOLD, ACTIVE_THRESHOLD } from "../../constants"; import { trackEvent } from "../../analytics"; @@ -113,8 +113,8 @@ class CollabWrapper extends PureComponent { process.env.NODE_ENV === ENV.TEST || process.env.NODE_ENV === ENV.DEVELOPMENT ) { - window.h = window.h || ({} as Window["h"]); - Object.defineProperties(window.h, { + window.collab = window.collab || ({} as Window["collab"]); + Object.defineProperties(window, { collab: { configurable: true, value: this, @@ -658,4 +658,17 @@ class CollabWrapper extends PureComponent { } } +declare global { + interface Window { + collab: InstanceType; + } +} + +if ( + process.env.NODE_ENV === ENV.TEST || + process.env.NODE_ENV === ENV.DEVELOPMENT +) { + window.collab = window.collab || ({} as Window["collab"]); +} + export default CollabWrapper; diff --git a/src/excalidraw-app/collab/Portal.tsx b/src/excalidraw-app/collab/Portal.tsx index b79f20ef93..b58cc2b928 100644 --- a/src/excalidraw-app/collab/Portal.tsx +++ b/src/excalidraw-app/collab/Portal.tsx @@ -9,7 +9,7 @@ import CollabWrapper from "./CollabWrapper"; import { getSyncableElements } from "../../packages/excalidraw/index"; import { ExcalidrawElement } from "../../element/types"; import { BROADCAST, SCENE } from "../app_constants"; -import { UserIdleState } from "./types"; +import { UserIdleState } from "../../types"; import { trackEvent } from "../../analytics"; class Portal { diff --git a/src/excalidraw-app/collab/types.ts b/src/excalidraw-app/collab/types.ts deleted file mode 100644 index f2b8882656..0000000000 --- a/src/excalidraw-app/collab/types.ts +++ /dev/null @@ -1,5 +0,0 @@ -export enum UserIdleState { - ACTIVE = "active", - AWAY = "away", - IDLE = "idle", -} diff --git a/src/excalidraw-app/data/index.ts b/src/excalidraw-app/data/index.ts index 7d4c6eb35a..5769d780ef 100644 --- a/src/excalidraw-app/data/index.ts +++ b/src/excalidraw-app/data/index.ts @@ -3,8 +3,7 @@ import { restore } from "../../data/restore"; import { ImportedDataState } from "../../data/types"; import { ExcalidrawElement } from "../../element/types"; import { t } from "../../i18n"; -import { AppState } from "../../types"; -import { UserIdleState } from "../collab/types"; +import { AppState, UserIdleState } from "../../types"; const byteToHex = (byte: number): string => `0${byte.toString(16)}`.slice(-2); diff --git a/src/renderer/renderScene.ts b/src/renderer/renderScene.ts index ae6a54335a..d96bedc9f5 100644 --- a/src/renderer/renderScene.ts +++ b/src/renderer/renderScene.ts @@ -48,7 +48,7 @@ import { TransformHandleType, } from "../element/transformHandles"; import { viewportCoordsToSceneCoords, supportsEmoji } from "../utils"; -import { UserIdleState } from "../excalidraw-app/collab/types"; +import { UserIdleState } from "../types"; import { THEME_FILTER } from "../constants"; const hasEmojiSupport = supportsEmoji(); diff --git a/src/tests/collab.test.tsx b/src/tests/collab.test.tsx index ad76d29527..9065abbf85 100644 --- a/src/tests/collab.test.tsx +++ b/src/tests/collab.test.tsx @@ -60,7 +60,7 @@ describe("collaboration", () => { ]); expect(API.getStateHistory().length).toBe(1); }); - h.collab.openPortal(); + window.collab.openPortal(); await waitFor(() => { expect(h.elements).toEqual([expect.objectContaining({ id: "A" })]); expect(API.getStateHistory().length).toBe(1); diff --git a/src/tests/test-utils.ts b/src/tests/test-utils.ts index f78295be6f..c722fa9a92 100644 --- a/src/tests/test-utils.ts +++ b/src/tests/test-utils.ts @@ -100,5 +100,5 @@ const initLocalStorage = (data: ImportedDataState) => { }; export const updateSceneData = (data: SceneData) => { - (window.h.collab as any).excalidrawAPI.updateScene(data); + (window.collab as any).excalidrawAPI.updateScene(data); }; diff --git a/src/types.ts b/src/types.ts index 956f8f5181..2defeed496 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,7 +20,6 @@ import { ExcalidrawImperativeAPI } from "./components/App"; import type { ResolvablePromise } from "./utils"; import { Spreadsheet } from "./charts"; import { Language } from "./i18n"; -import { UserIdleState } from "./excalidraw-app/collab/types"; export type Point = Readonly; @@ -196,3 +195,9 @@ export type SceneData = { collaborators?: Map; commitToHistory?: boolean; }; + +export enum UserIdleState { + ACTIVE = "active", + AWAY = "away", + IDLE = "idle", +}