From ae531da193278560bc6a33c4e8c6ce9c9f7d22e6 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Thu, 29 Feb 2024 15:42:36 +0000 Subject: [PATCH] Don't add editor / app to window. (#2995) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR removes code that would add a reference to the editor to the window. This is a feature that we added very early on during testing, but which we should have moved out of the library earlier. Adding it here as one of our last PRs before release. If you've relied on this, you'll need to update your use of the library to do it manually: ```ts { ;(window as any).app = editor ;(window as any).editor = editor }}/> ``` ### Change Type - [x] `major` — Breaking change ### Release Notes - Remove `window.editor` and `window.app` references to editor. --- apps/dotcom/src/components/LocalEditor.tsx | 2 ++ apps/dotcom/src/components/MultiplayerEditor.tsx | 2 ++ apps/dotcom/src/components/SnapshotsEditor.tsx | 2 ++ apps/examples/src/misc/develop.tsx | 8 +++++++- apps/examples/src/misc/end-to-end.tsx | 3 +++ packages/editor/src/lib/TldrawEditor.tsx | 2 -- 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/dotcom/src/components/LocalEditor.tsx b/apps/dotcom/src/components/LocalEditor.tsx index d814b6216..828a48277 100644 --- a/apps/dotcom/src/components/LocalEditor.tsx +++ b/apps/dotcom/src/components/LocalEditor.tsx @@ -91,6 +91,8 @@ export function LocalEditor() { const fileSystemUiOverrides = useFileSystem({ isMultiplayer: false }) const handleMount = useCallback((editor: Editor) => { + ;(window as any).app = editor + ;(window as any).editor = editor editor.registerExternalAssetHandler('url', createAssetFromUrl) }, []) diff --git a/apps/dotcom/src/components/MultiplayerEditor.tsx b/apps/dotcom/src/components/MultiplayerEditor.tsx index f7cfbf574..c42643cfd 100644 --- a/apps/dotcom/src/components/MultiplayerEditor.tsx +++ b/apps/dotcom/src/components/MultiplayerEditor.tsx @@ -142,6 +142,8 @@ export function MultiplayerEditor({ const handleMount = useCallback( (editor: Editor) => { + ;(window as any).app = editor + ;(window as any).editor = editor editor.updateInstanceState({ isReadonly: isReadOnly }) editor.registerExternalAssetHandler('file', createAssetFromFile) editor.registerExternalAssetHandler('url', createAssetFromUrl) diff --git a/apps/dotcom/src/components/SnapshotsEditor.tsx b/apps/dotcom/src/components/SnapshotsEditor.tsx index 704b50333..6719f88e3 100644 --- a/apps/dotcom/src/components/SnapshotsEditor.tsx +++ b/apps/dotcom/src/components/SnapshotsEditor.tsx @@ -83,6 +83,8 @@ export function SnapshotsEditor(props: SnapshotEditorProps) { overrides={[sharingUiOverrides, fileSystemUiOverrides]} onUiEvent={handleUiEvent} onMount={(editor) => { + ;(window as any).app = editor + ;(window as any).editor = editor editor.updateInstanceState({ isReadonly: true }) }} components={components} diff --git a/apps/examples/src/misc/develop.tsx b/apps/examples/src/misc/develop.tsx index fdc0466e4..34e1db0fa 100644 --- a/apps/examples/src/misc/develop.tsx +++ b/apps/examples/src/misc/develop.tsx @@ -4,7 +4,13 @@ import '@tldraw/tldraw/tldraw.css' export default function Develop() { return (
- + { + ;(window as any).app = editor + ;(window as any).editor = editor + }} + />
) } diff --git a/apps/examples/src/misc/end-to-end.tsx b/apps/examples/src/misc/end-to-end.tsx index 22ad0d465..8442f7160 100644 --- a/apps/examples/src/misc/end-to-end.tsx +++ b/apps/examples/src/misc/end-to-end.tsx @@ -9,6 +9,9 @@ export default function EndToEnd() {
{ + ;(window as any).app = editor + ;(window as any).editor = editor + editor.on('event', (info) => { ;(window as any).__tldraw_editor_events.push(info) }) diff --git a/packages/editor/src/lib/TldrawEditor.tsx b/packages/editor/src/lib/TldrawEditor.tsx index 13097665c..4e9dc559b 100644 --- a/packages/editor/src/lib/TldrawEditor.tsx +++ b/packages/editor/src/lib/TldrawEditor.tsx @@ -285,8 +285,6 @@ function TldrawEditorWithReadyStore({ initialState, inferDarkMode, }) - ;(window as any).app = editor - ;(window as any).editor = editor setEditor(editor) return () => {