fix: Don't share collab types with core (#3353)

* fix: Don't share collab types with core

* fix

* remove

* fix
This commit is contained in:
Aakansha Doshi 2021-03-28 19:26:03 +05:30 committed by GitHub
parent 3d047d57a7
commit 25fd275158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 27 additions and 18 deletions

View File

@ -4111,9 +4111,6 @@ declare global {
history: SceneHistory;
app: InstanceType<typeof App>;
library: typeof Library;
collab: InstanceType<
typeof import("../excalidraw-app/collab/CollabWrapper").default
>;
};
}
}

View File

@ -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<Props, CollabState> {
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<Props, CollabState> {
}
}
declare global {
interface Window {
collab: InstanceType<typeof CollabWrapper>;
}
}
if (
process.env.NODE_ENV === ENV.TEST ||
process.env.NODE_ENV === ENV.DEVELOPMENT
) {
window.collab = window.collab || ({} as Window["collab"]);
}
export default CollabWrapper;

View File

@ -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 {

View File

@ -1,5 +0,0 @@
export enum UserIdleState {
ACTIVE = "active",
AWAY = "away",
IDLE = "idle",
}

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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);
};

View File

@ -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<RoughPoint>;
@ -196,3 +195,9 @@ export type SceneData = {
collaborators?: Map<string, Collaborator>;
commitToHistory?: boolean;
};
export enum UserIdleState {
ACTIVE = "active",
AWAY = "away",
IDLE = "idle",
}