tldraw/components/canvas/page.tsx

37 lines
1,008 B
TypeScript
Raw Normal View History

2021-05-28 14:37:23 +00:00
import { useSelector } from 'state'
2021-06-04 16:08:43 +00:00
import { GroupShape } from 'types'
2021-05-28 14:37:23 +00:00
import { deepCompareArrays, getPage } from 'utils/utils'
import Shape from './shape'
2021-05-09 21:22:25 +00:00
/*
On each state change, compare node ids of all shapes
on the current page. Kind of expensive but only happens
here; and still cheaper than any other pattern I've found.
*/
2021-06-04 16:08:43 +00:00
const noOffset = [0, 0]
2021-05-09 21:22:25 +00:00
export default function Page() {
2021-05-23 13:46:04 +00:00
const currentPageShapeIds = useSelector(({ data }) => {
return Object.values(getPage(data).shapes)
2021-06-04 16:08:43 +00:00
.filter((shape) => shape.parentId === data.currentPageId)
2021-05-23 13:46:04 +00:00
.sort((a, b) => a.childIndex - b.childIndex)
.map((shape) => shape.id)
}, deepCompareArrays)
2021-05-09 21:22:25 +00:00
2021-05-28 14:37:23 +00:00
const isSelecting = useSelector((s) => s.isIn('selecting'))
2021-05-09 21:22:25 +00:00
return (
2021-05-30 13:20:25 +00:00
<g pointerEvents={isSelecting ? 'all' : 'none'}>
2021-05-09 21:22:25 +00:00
{currentPageShapeIds.map((shapeId) => (
2021-06-04 16:08:43 +00:00
<Shape
key={shapeId}
id={shapeId}
isSelecting={isSelecting}
parentPoint={noOffset}
/>
2021-05-09 21:22:25 +00:00
))}
2021-05-30 13:20:25 +00:00
</g>
2021-05-09 21:22:25 +00:00
)
}