tldraw/apps/electron/src/renderer/app.tsx
Gwenaël Gallon e0e1373468
Chore: clean up sort imports with prettier (#870)
* Update prettier to latest

* Add format command

* Create .prettierignore

* Add prettier plugin sort imports

* Update prettier config

* Update prettier config

* Update .prettierignore

* Fix @babel/parser conflict

https://github.com/trivago/prettier-plugin-sort-imports/issues/156

* Revert "Update .prettierignore"

This reverts commit 282e5b838376f16b3df7f4c1f99f1106baaffea4.

* Revert change for apps/www/pages/v/[id].tsx

* Sort imports

Moves the third party imports to the top, "~" imports in middle, and "./" at last

* Sorting of the specifiers

in an import declarations

* [www] use path vs  "../"

* [core] use path "~" vs "../"

* [tldraw] use path "~" vs "../.../"

* [tldraw] use path "~" vs "../"

* [tldraw] Cleanup

* Update prettier config

* Last use path "~" vs "../.../"

* [www] Fix order of the third party imports

* Clean prettier config
2022-08-02 14:56:12 +01:00

86 lines
1.8 KiB
TypeScript

import { Tldraw, TldrawApp } from '@tldraw/tldraw'
import * as React from 'react'
import type { Message, TldrawBridgeApi } from 'src/types'
declare const window: Window & { TldrawBridgeApi: TldrawBridgeApi }
export default function App() {
const rTldrawApp = React.useRef<TldrawApp>()
// When the editor mounts, save the state instance in a ref.
const handleMount = React.useCallback((tldr: TldrawApp) => {
rTldrawApp.current = tldr
}, [])
React.useEffect(() => {
function handleEvent(message: Message) {
const app = rTldrawApp.current
if (!app) return
switch (message.type) {
case 'resetZoom': {
app.resetZoom()
break
}
case 'zoomIn': {
app.zoomIn()
break
}
case 'zoomOut': {
app.zoomOut()
break
}
case 'zoomToFit': {
app.zoomToFit()
break
}
case 'zoomToSelection': {
app.zoomToSelection()
break
}
case 'undo': {
app.undo()
break
}
case 'redo': {
app.redo()
break
}
case 'cut': {
app.cut()
break
}
case 'copy': {
app.copy()
break
}
case 'paste': {
app.paste()
break
}
case 'delete': {
app.delete()
break
}
case 'selectAll': {
app.selectAll()
break
}
case 'selectNone': {
app.selectNone()
break
}
}
}
const { on } = window.TldrawBridgeApi
on('projectMsg', handleEvent)
})
return (
<div className="tldraw">
<Tldraw id="electron" onMount={handleMount} autofocus showMenu={false} />
</div>
)
}