2021-07-07 14:42:17 +00:00
|
|
|
import * as Sentry from '@sentry/node'
|
2021-06-24 22:09:36 +00:00
|
|
|
import { ErrorBoundary } from 'react-error-boundary'
|
2021-05-28 14:37:23 +00:00
|
|
|
import Bounds from './bounds/bounding-box'
|
|
|
|
import BoundsBg from './bounds/bounds-bg'
|
2021-06-30 20:31:29 +00:00
|
|
|
import Brush from './brush'
|
|
|
|
import ContextMenu from './context-menu/context-menu'
|
|
|
|
import Coop from './coop/coop'
|
|
|
|
import Defs from './defs'
|
2021-05-31 19:13:43 +00:00
|
|
|
import Handles from './bounds/handles'
|
2021-06-30 20:31:29 +00:00
|
|
|
import Page from './page'
|
|
|
|
import React, { useRef } from 'react'
|
|
|
|
import state, { useSelector } from 'state'
|
|
|
|
import styled from 'styles'
|
|
|
|
import useCamera from 'hooks/useCamera'
|
2021-06-06 10:50:01 +00:00
|
|
|
import useCanvasEvents from 'hooks/useCanvasEvents'
|
2021-06-30 20:31:29 +00:00
|
|
|
import useZoomEvents from 'hooks/useZoomEvents'
|
2021-05-09 13:04:42 +00:00
|
|
|
|
2021-06-28 12:13:34 +00:00
|
|
|
function resetError() {
|
|
|
|
null
|
|
|
|
}
|
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
export default function Canvas(): JSX.Element {
|
2021-05-09 13:04:42 +00:00
|
|
|
const rCanvas = useRef<SVGSVGElement>(null)
|
|
|
|
const rGroup = useRef<SVGGElement>(null)
|
|
|
|
|
2021-05-09 21:22:25 +00:00
|
|
|
useCamera(rGroup)
|
2021-05-28 16:25:43 +00:00
|
|
|
|
2021-06-06 10:50:01 +00:00
|
|
|
useZoomEvents()
|
2021-05-30 13:14:35 +00:00
|
|
|
|
2021-06-06 10:50:01 +00:00
|
|
|
const events = useCanvasEvents(rCanvas)
|
2021-05-10 12:16:57 +00:00
|
|
|
|
2021-06-06 10:50:01 +00:00
|
|
|
const isReady = useSelector((s) => s.isIn('ready'))
|
2021-05-10 12:16:57 +00:00
|
|
|
|
2021-05-09 13:04:42 +00:00
|
|
|
return (
|
2021-06-10 09:49:16 +00:00
|
|
|
<ContextMenu>
|
|
|
|
<MainSVG ref={rCanvas} {...events}>
|
2021-06-28 12:13:34 +00:00
|
|
|
<ErrorBoundary FallbackComponent={ErrorFallback} onReset={resetError}>
|
2021-06-24 22:09:36 +00:00
|
|
|
<Defs />
|
|
|
|
{isReady && (
|
|
|
|
<g ref={rGroup} id="shapes">
|
|
|
|
<BoundsBg />
|
|
|
|
<Page />
|
2021-06-30 20:31:29 +00:00
|
|
|
<Coop />
|
2021-06-24 22:09:36 +00:00
|
|
|
<Bounds />
|
|
|
|
<Handles />
|
|
|
|
<Brush />
|
|
|
|
</g>
|
|
|
|
)}
|
|
|
|
</ErrorBoundary>
|
2021-06-10 09:49:16 +00:00
|
|
|
</MainSVG>
|
|
|
|
</ContextMenu>
|
2021-05-09 13:04:42 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-05-28 14:37:23 +00:00
|
|
|
const MainSVG = styled('svg', {
|
|
|
|
position: 'fixed',
|
2021-06-18 14:39:07 +00:00
|
|
|
overflow: 'hidden',
|
2021-05-09 13:04:42 +00:00
|
|
|
top: 0,
|
|
|
|
left: 0,
|
2021-05-28 14:37:23 +00:00
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
touchAction: 'none',
|
2021-05-09 13:04:42 +00:00
|
|
|
zIndex: 100,
|
2021-05-30 13:49:33 +00:00
|
|
|
backgroundColor: '$canvas',
|
2021-06-03 16:13:23 +00:00
|
|
|
pointerEvents: 'all',
|
2021-06-07 21:12:14 +00:00
|
|
|
// cursor: 'none',
|
2021-05-23 13:46:04 +00:00
|
|
|
|
2021-05-28 14:37:23 +00:00
|
|
|
'& *': {
|
|
|
|
userSelect: 'none',
|
2021-05-23 13:46:04 +00:00
|
|
|
},
|
2021-05-09 13:04:42 +00:00
|
|
|
})
|
2021-06-24 22:09:36 +00:00
|
|
|
|
|
|
|
function ErrorFallback({ error, resetErrorBoundary }) {
|
|
|
|
React.useEffect(() => {
|
2021-07-07 14:42:17 +00:00
|
|
|
const copy =
|
|
|
|
'Sorry, something went wrong. Press Ok to reset the document, or press cancel to continue and see if it resolves itself.'
|
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
console.error(error)
|
2021-07-07 14:42:17 +00:00
|
|
|
|
|
|
|
Sentry.captureException(error)
|
|
|
|
|
2021-06-24 22:09:36 +00:00
|
|
|
if (window.confirm(copy)) {
|
2021-07-07 14:42:17 +00:00
|
|
|
state.send('RESET_DOCUMENT_STATE')
|
2021-06-24 22:09:36 +00:00
|
|
|
resetErrorBoundary()
|
|
|
|
}
|
|
|
|
}, [])
|
|
|
|
|
2021-07-07 14:42:17 +00:00
|
|
|
return <g />
|
2021-06-24 22:09:36 +00:00
|
|
|
}
|