From 9325109836595276cdb97003eeff11086dfbfc52 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Thu, 10 Jun 2021 02:46:56 +0530 Subject: [PATCH] fix: use excal id so every element has unique id (#3696) * fix: use excal id so every element has unique id * fix * fix * fix * add docs * fix --- src/components/App.tsx | 25 ++++++++++++++----- src/components/Dialog.tsx | 5 ++-- src/components/ErrorDialog.tsx | 2 +- src/components/LockIcon.tsx | 2 -- src/components/Modal.tsx | 2 +- src/components/ProjectName.tsx | 6 +++-- src/components/Section.tsx | 6 +++-- src/components/ToolButton.tsx | 4 ++- src/css/styles.scss | 5 ++-- src/packages/excalidraw/CHANGELOG.md | 4 +++ src/setupTests.ts | 5 ++++ .../__snapshots__/excalidraw.test.tsx.snap | 8 +++--- src/tests/packages/excalidraw.test.tsx | 6 ++--- 13 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 13386e6f..f97a0a8c 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -197,9 +197,10 @@ import { actionToggleViewMode } from "../actions/actionToggleViewMode"; const IsMobileContext = React.createContext(false); export const useIsMobile = () => useContext(IsMobileContext); -const ExcalidrawContainerContext = React.createContext( - null, -); +const ExcalidrawContainerContext = React.createContext<{ + container: HTMLDivElement | null; + id: string | null; +}>({ container: null, id: null }); export const useExcalidrawContainer = () => useContext(ExcalidrawContainerContext); @@ -244,6 +245,10 @@ class App extends React.Component { public libraryItemsFromStorage: LibraryItems | undefined; private id: string; private history: History; + private excalidrawContainerValue: { + container: HTMLDivElement | null; + id: string; + }; constructor(props: AppProps) { super(props); @@ -300,6 +305,12 @@ class App extends React.Component { } readyPromise.resolve(api); } + + this.excalidrawContainerValue = { + container: this.excalidrawContainerRef.current, + id: this.id, + }; + this.scene = new Scene(); this.library = new Library(this); this.history = new History(); @@ -327,7 +338,7 @@ class App extends React.Component { if (viewModeEnabled) { return ( { } return ( { } > { }; public async componentDidMount() { + this.excalidrawContainerValue.container = this.excalidrawContainerRef.current; + if ( process.env.NODE_ENV === ENV.TEST || process.env.NODE_ENV === ENV.DEVELOPMENT diff --git a/src/components/Dialog.tsx b/src/components/Dialog.tsx index ada1bb5a..79cebf7e 100644 --- a/src/components/Dialog.tsx +++ b/src/components/Dialog.tsx @@ -2,7 +2,7 @@ import clsx from "clsx"; import React, { useEffect, useState } from "react"; import { useCallbackRefState } from "../hooks/useCallbackRefState"; import { t } from "../i18n"; -import { useIsMobile } from "../components/App"; +import { useExcalidrawContainer, useIsMobile } from "../components/App"; import { KEYS } from "../keys"; import "./Dialog.scss"; import { back, close } from "./icons"; @@ -21,6 +21,7 @@ export const Dialog = (props: { }) => { const [islandNode, setIslandNode] = useCallbackRefState(); const [lastActiveElement] = useState(document.activeElement); + const { id } = useExcalidrawContainer(); useEffect(() => { if (!islandNode) { @@ -82,7 +83,7 @@ export const Dialog = (props: { theme={props.theme} > -

+

{props.title}