您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

defs.tsx 1.0KB

12345678910111213141516171819202122232425262728293031323334
  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. .sort((a, b) => a.childIndex - b.childIndex)
  11. .map((shape) => shape.id)
  12. }, deepCompareArrays)
  13. return (
  14. <defs>
  15. {currentPageShapeIds.map((id) => (
  16. <Def key={id} id={id} />
  17. ))}
  18. <DotCircle id="dot" r={4} />
  19. <Handle id="handle" r={4} />
  20. <filter id="expand">
  21. <feMorphology operator="dilate" radius={2 / zoom} />
  22. </filter>
  23. </defs>
  24. )
  25. }
  26. const Def = memo(function Def({ id }: { id: string }) {
  27. const shape = useSelector((s) => getPage(s.data).shapes[id])
  28. if (!shape) return null
  29. return getShapeUtils(shape).render(shape)
  30. })