Don't add editor / app to window. (#2995)

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
<Tldraw onMount={(editor) => {
  ;(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.
This commit is contained in:
Steve Ruiz 2024-02-29 15:42:36 +00:00 committed by GitHub
parent 86519d60cd
commit ae531da193
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 16 additions and 3 deletions

View file

@ -91,6 +91,8 @@ export function LocalEditor() {
const fileSystemUiOverrides = useFileSystem({ isMultiplayer: false }) const fileSystemUiOverrides = useFileSystem({ isMultiplayer: false })
const handleMount = useCallback((editor: Editor) => { const handleMount = useCallback((editor: Editor) => {
;(window as any).app = editor
;(window as any).editor = editor
editor.registerExternalAssetHandler('url', createAssetFromUrl) editor.registerExternalAssetHandler('url', createAssetFromUrl)
}, []) }, [])

View file

@ -142,6 +142,8 @@ export function MultiplayerEditor({
const handleMount = useCallback( const handleMount = useCallback(
(editor: Editor) => { (editor: Editor) => {
;(window as any).app = editor
;(window as any).editor = editor
editor.updateInstanceState({ isReadonly: isReadOnly }) editor.updateInstanceState({ isReadonly: isReadOnly })
editor.registerExternalAssetHandler('file', createAssetFromFile) editor.registerExternalAssetHandler('file', createAssetFromFile)
editor.registerExternalAssetHandler('url', createAssetFromUrl) editor.registerExternalAssetHandler('url', createAssetFromUrl)

View file

@ -83,6 +83,8 @@ export function SnapshotsEditor(props: SnapshotEditorProps) {
overrides={[sharingUiOverrides, fileSystemUiOverrides]} overrides={[sharingUiOverrides, fileSystemUiOverrides]}
onUiEvent={handleUiEvent} onUiEvent={handleUiEvent}
onMount={(editor) => { onMount={(editor) => {
;(window as any).app = editor
;(window as any).editor = editor
editor.updateInstanceState({ isReadonly: true }) editor.updateInstanceState({ isReadonly: true })
}} }}
components={components} components={components}

View file

@ -4,7 +4,13 @@ import '@tldraw/tldraw/tldraw.css'
export default function Develop() { export default function Develop() {
return ( return (
<div className="tldraw__editor"> <div className="tldraw__editor">
<Tldraw persistenceKey="tldraw_example" /> <Tldraw
persistenceKey="tldraw_example"
onMount={(editor) => {
;(window as any).app = editor
;(window as any).editor = editor
}}
/>
</div> </div>
) )
} }

View file

@ -9,6 +9,9 @@ export default function EndToEnd() {
<div className="tldraw__editor"> <div className="tldraw__editor">
<Tldraw <Tldraw
onMount={(editor) => { onMount={(editor) => {
;(window as any).app = editor
;(window as any).editor = editor
editor.on('event', (info) => { editor.on('event', (info) => {
;(window as any).__tldraw_editor_events.push(info) ;(window as any).__tldraw_editor_events.push(info)
}) })

View file

@ -285,8 +285,6 @@ function TldrawEditorWithReadyStore({
initialState, initialState,
inferDarkMode, inferDarkMode,
}) })
;(window as any).app = editor
;(window as any).editor = editor
setEditor(editor) setEditor(editor)
return () => { return () => {