2021-06-21 21:35:28 +00:00
|
|
|
import { getShapeStyle } from 'state/shape-styles'
|
|
|
|
import { getShapeUtils } from 'state/shape-utils'
|
2021-06-28 12:13:34 +00:00
|
|
|
import React 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-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-06-28 12:13:34 +00:00
|
|
|
{shapeIdsToRender.map((id) => (
|
|
|
|
<Def key={id} id={id} />
|
|
|
|
))}
|
2021-05-28 13:08:51 +00:00
|
|
|
</defs>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-28 12:13:34 +00:00
|
|
|
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)
|
|
|
|
|
2021-06-28 12:13:34 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{React.cloneElement(
|
|
|
|
getShapeUtils(shape).render(shape, { isEditing: false }),
|
|
|
|
{ id, ...style, strokeWidth: undefined }
|
|
|
|
)}
|
|
|
|
</>
|
2021-06-20 22:01:40 +00:00
|
|
|
)
|
2021-06-28 12:13: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>
|
|
|
|
)
|
|
|
|
}
|