Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import styled from 'styles'
  2. import { ErrorBoundary } from 'react-error-boundary'
  3. import state, { useSelector } from 'state'
  4. import React, { useRef } from 'react'
  5. import useZoomEvents from 'hooks/useZoomEvents'
  6. import useCamera from 'hooks/useCamera'
  7. import Defs from './defs'
  8. import Page from './page'
  9. import Brush from './brush'
  10. import Bounds from './bounds/bounding-box'
  11. import BoundsBg from './bounds/bounds-bg'
  12. import Handles from './bounds/handles'
  13. import useCanvasEvents from 'hooks/useCanvasEvents'
  14. import ContextMenu from './context-menu/context-menu'
  15. export default function Canvas(): JSX.Element {
  16. const rCanvas = useRef<SVGSVGElement>(null)
  17. const rGroup = useRef<SVGGElement>(null)
  18. useCamera(rGroup)
  19. useZoomEvents()
  20. const events = useCanvasEvents(rCanvas)
  21. const isReady = useSelector((s) => s.isIn('ready'))
  22. return (
  23. <ContextMenu>
  24. <MainSVG ref={rCanvas} {...events}>
  25. <ErrorBoundary
  26. FallbackComponent={ErrorFallback}
  27. onReset={() => {
  28. // reset the state of your app so the error doesn't happen again
  29. }}
  30. >
  31. <Defs />
  32. {isReady && (
  33. <g ref={rGroup} id="shapes">
  34. <BoundsBg />
  35. <Page />
  36. <Bounds />
  37. <Handles />
  38. <Brush />
  39. </g>
  40. )}
  41. </ErrorBoundary>
  42. </MainSVG>
  43. </ContextMenu>
  44. )
  45. }
  46. const MainSVG = styled('svg', {
  47. position: 'fixed',
  48. overflow: 'hidden',
  49. top: 0,
  50. left: 0,
  51. width: '100%',
  52. height: '100%',
  53. touchAction: 'none',
  54. zIndex: 100,
  55. backgroundColor: '$canvas',
  56. pointerEvents: 'all',
  57. // cursor: 'none',
  58. '& *': {
  59. userSelect: 'none',
  60. },
  61. })
  62. function ErrorFallback({ error, resetErrorBoundary }) {
  63. React.useEffect(() => {
  64. console.error(error)
  65. const copy = 'Sorry, something went wrong. Clear canvas and continue?'
  66. if (window.confirm(copy)) {
  67. state.send('CLEARED_PAGE')
  68. resetErrorBoundary()
  69. }
  70. }, [])
  71. return (
  72. <g>
  73. <text>Oops</text>
  74. </g>
  75. )
  76. }