You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

defs.tsx 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { getShapeUtils } from 'lib/shape-utils'
  2. import { memo } from 'react'
  3. import { useSelector } from 'state'
  4. import { deepCompareArrays, getCurrentCamera, getPage } from 'utils/utils'
  5. import { DotCircle, Handle } from './misc'
  6. export default function Defs() {
  7. const zoom = useSelector((s) => getCurrentCamera(s.data).zoom)
  8. const currentPageShapeIds = useSelector(({ data }) => {
  9. return Object.values(getPage(data).shapes)
  10. .filter(Boolean)
  11. .filter((shape) => !getShapeUtils(shape).isForeignObject)
  12. .sort((a, b) => a.childIndex - b.childIndex)
  13. .map((shape) => shape.id)
  14. }, deepCompareArrays)
  15. return (
  16. <defs>
  17. {currentPageShapeIds.map((id) => (
  18. <Def key={id} id={id} />
  19. ))}
  20. <DotCircle id="dot" r={4} />
  21. <Handle id="handle" r={4} />
  22. <filter id="expand">
  23. <feMorphology operator="dilate" radius={2 / zoom} />
  24. </filter>
  25. </defs>
  26. )
  27. }
  28. const Def = memo(function Def({ id }: { id: string }) {
  29. const shape = useSelector((s) => getPage(s.data).shapes[id])
  30. if (!shape) return null
  31. return getShapeUtils(shape).render(shape, { isEditing: false })
  32. })