Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

editor.tsx 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { TLDraw, TLDrawState, Data, useFileSystem } 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. const fileSystemEvents = useFileSystem()
  29. return (
  30. <div className="tldraw">
  31. <TLDraw
  32. id={id}
  33. onMount={handleMount}
  34. onChange={handleChange}
  35. autofocus
  36. {...fileSystemEvents}
  37. />
  38. </div>
  39. )
  40. }