2021-06-21 21:35:28 +00:00
|
|
|
import { getShapeStyle } from 'state/shape-styles'
|
|
|
|
import { getShapeUtils } from 'state/shape-utils'
|
2021-06-20 22:01:40 +00:00
|
|
|
import React, { memo } from 'react'
|
2021-05-28 16:25:43 +00:00
|
|
|
import { useSelector } from 'state'
|
2021-06-27 09:07:20 +00:00
|
|
|
import { getCurrentCamera } from 'utils'
|
2021-06-05 06:36:39 +00:00
|
|
|
import { DotCircle, Handle } from './misc'
|
2021-06-26 11:52:36 +00:00
|
|
|
import useShapeDef from 'hooks/useShape'
|
2021-06-27 09:07:20 +00:00
|
|
|
import useShapesToRender from 'hooks/useShapesToRender'
|
2021-05-28 13:08:51 +00:00
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
export default function Defs(): JSX.Element {
|
2021-06-27 09:07:20 +00:00
|
|
|
const shapeIdsToRender = useShapesToRender()
|
2021-05-28 13:08:51 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<defs>
|
2021-06-27 09:07:20 +00:00
|
|
|
{shapeIdsToRender.map((id) => (
|
2021-05-28 13:08:51 +00:00
|
|
|
<Def key={id} id={id} />
|
|
|
|
))}
|
2021-06-05 06:36:39 +00:00
|
|
|
<DotCircle id="dot" r={4} />
|
|
|
|
<Handle id="handle" r={4} />
|
2021-06-27 09:07:20 +00:00
|
|
|
<ExpandDef />
|
2021-05-28 13:08:51 +00:00
|
|
|
</defs>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-03 21:23:16 +00:00
|
|
|
const Def = memo(function Def({ id }: { id: string }) {
|
2021-06-26 11:52:36 +00:00
|
|
|
const shape = useShapeDef(id)
|
2021-06-15 11:58:51 +00:00
|
|
|
|
2021-05-28 16:25:43 +00:00
|
|
|
if (!shape) return null
|
2021-06-20 22:01:40 +00:00
|
|
|
|
|
|
|
const style = getShapeStyle(shape.style)
|
|
|
|
|
|
|
|
return React.cloneElement(
|
|
|
|
getShapeUtils(shape).render(shape, { isEditing: false }),
|
2021-06-23 14:39:14 +00:00
|
|
|
{ id, ...style }
|
2021-06-20 22:01:40 +00:00
|
|
|
)
|
2021-06-02 11:50:34 +00:00
|
|
|
})
|
2021-06-27 09:07:20 +00:00
|
|
|
|
|
|
|
function ExpandDef() {
|
|
|
|
const zoom = useSelector((s) => getCurrentCamera(s.data).zoom)
|
|
|
|
return (
|
|
|
|
<filter id="expand">
|
|
|
|
<feMorphology operator="dilate" radius={2 / zoom} />
|
|
|
|
</filter>
|
|
|
|
)
|
|
|
|
}
|