e0e1373468
* 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
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { Tldraw, TldrawApp, TldrawProps, useFileSystem } from '@tldraw/tldraw'
|
|
import * as React from 'react'
|
|
import { useUploadAssets } from '~hooks/useUploadAssets'
|
|
import * as gtag from '~utils/gtag'
|
|
|
|
declare const window: Window & { app: TldrawApp }
|
|
|
|
interface EditorProps {
|
|
id?: string
|
|
}
|
|
|
|
const Editor = ({ id = 'home', ...rest }: EditorProps & Partial<TldrawProps>) => {
|
|
const handleMount = React.useCallback((app: TldrawApp) => {
|
|
window.app = app
|
|
}, [])
|
|
|
|
// Send events to gtag as actions.
|
|
const handlePersist = React.useCallback((_app: TldrawApp, reason?: string) => {
|
|
gtag.event({
|
|
action: reason ?? '',
|
|
category: 'editor',
|
|
label: reason ?? 'persist',
|
|
value: 0,
|
|
})
|
|
}, [])
|
|
|
|
const fileSystemEvents = useFileSystem()
|
|
|
|
const { onAssetUpload } = useUploadAssets()
|
|
|
|
return (
|
|
<div className="tldraw">
|
|
<Tldraw
|
|
id={id}
|
|
autofocus
|
|
onMount={handleMount}
|
|
onPersist={handlePersist}
|
|
onAssetUpload={onAssetUpload}
|
|
{...fileSystemEvents}
|
|
{...rest}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Editor
|