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 699B

12345678910111213141516171819202122232425
  1. import { getShapeUtils } from 'lib/shape-utils'
  2. import { useSelector } from 'state'
  3. import { deepCompareArrays, getPage } from 'utils/utils'
  4. export default function Defs() {
  5. const currentPageShapeIds = useSelector(({ data }) => {
  6. return Object.values(getPage(data).shapes)
  7. .sort((a, b) => a.childIndex - b.childIndex)
  8. .map((shape) => shape.id)
  9. }, deepCompareArrays)
  10. return (
  11. <defs>
  12. {currentPageShapeIds.map((id) => (
  13. <Def key={id} id={id} />
  14. ))}
  15. </defs>
  16. )
  17. }
  18. export function Def({ id }: { id: string }) {
  19. const shape = useSelector(({ data }) => getPage(data).shapes[id])
  20. if (!shape) return null
  21. return getShapeUtils(shape).render(shape)
  22. }