You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

editor.tsx 960B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { TLDraw, TLDrawState, Data } from '@tldraw/tldraw'
  2. import * as gtag from '-utils/gtag'
  3. import React from 'react'
  4. interface EditorProps {
  5. id?: string
  6. }
  7. export default function Editor({ id = 'home' }: EditorProps) {
  8. // Put the tlstate into the window, for debugging.
  9. const handleMount = React.useCallback((tlstate: TLDrawState) => {
  10. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  11. // @ts-ignore
  12. window.tlstate = tlstate
  13. }, [])
  14. // Send events to gtag as actions.
  15. const handleChange = React.useCallback(
  16. (_tlstate: TLDrawState, _state: Data, reason: string) => {
  17. if (reason.startsWith('command')) {
  18. gtag.event({
  19. action: reason,
  20. category: 'editor',
  21. label: `page:${id}`,
  22. value: 0,
  23. })
  24. }
  25. },
  26. [id]
  27. )
  28. return (
  29. <div className="tldraw">
  30. <TLDraw id={id} onMount={handleMount} onChange={handleChange} autofocus />
  31. </div>
  32. )
  33. }