tldraw/components/canvas/defs.tsx

26 lines
699 B
TypeScript
Raw Normal View History

2021-05-28 16:25:43 +00:00
import { getShapeUtils } from 'lib/shape-utils'
import { useSelector } from 'state'
import { deepCompareArrays, getPage } from 'utils/utils'
2021-05-28 13:08:51 +00:00
export default function Defs() {
const currentPageShapeIds = useSelector(({ data }) => {
return Object.values(getPage(data).shapes)
.sort((a, b) => a.childIndex - b.childIndex)
.map((shape) => shape.id)
}, deepCompareArrays)
return (
<defs>
{currentPageShapeIds.map((id) => (
<Def key={id} id={id} />
))}
</defs>
)
}
export function Def({ id }: { id: string }) {
const shape = useSelector(({ data }) => getPage(data).shapes[id])
2021-05-28 16:25:43 +00:00
if (!shape) return null
2021-05-28 13:08:51 +00:00
return getShapeUtils(shape).render(shape)
}