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:
parent
86519d60cd
commit
ae531da193
6 changed files with 16 additions and 3 deletions
|
@ -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)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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}
|
||||||
|
|
|
@ -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>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
})
|
})
|
||||||
|
|
|
@ -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 () => {
|
||||||
|
|
Loading…
Reference in a new issue