2021-05-28 14:37:23 +00:00
|
|
|
import styled from 'styles'
|
2021-05-28 16:25:43 +00:00
|
|
|
import state, { useSelector } from 'state'
|
2021-06-17 10:43:55 +00:00
|
|
|
import React, { useEffect, useRef } from 'react'
|
2021-05-28 14:37:23 +00:00
|
|
|
import useZoomEvents from 'hooks/useZoomEvents'
|
|
|
|
import useCamera from 'hooks/useCamera'
|
|
|
|
import Defs from './defs'
|
|
|
|
import Page from './page'
|
|
|
|
import Brush from './brush'
|
|
|
|
import Bounds from './bounds/bounding-box'
|
|
|
|
import BoundsBg from './bounds/bounds-bg'
|
2021-05-28 16:25:43 +00:00
|
|
|
import Selected from './selected'
|
2021-05-31 19:13:43 +00:00
|
|
|
import Handles from './bounds/handles'
|
2021-06-06 10:50:01 +00:00
|
|
|
import useCanvasEvents from 'hooks/useCanvasEvents'
|
2021-06-17 12:03:08 +00:00
|
|
|
import ContextMenu from './context-menu/context-menu'
|
2021-05-09 13:04:42 +00:00
|
|
|
|
|
|
|
export default function Canvas() {
|
|
|
|
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}>
|
|
|
|
<Defs />
|
|
|
|
{isReady && (
|
|
|
|
<g ref={rGroup}>
|
|
|
|
<BoundsBg />
|
|
|
|
<Page />
|
2021-06-17 21:50:04 +00:00
|
|
|
{/* <Selected /> */}
|
2021-06-10 09:49:16 +00:00
|
|
|
<Bounds />
|
|
|
|
<Handles />
|
|
|
|
<Brush />
|
|
|
|
</g>
|
|
|
|
)}
|
|
|
|
</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
|
|
|
})
|