123456789101112131415161718192021222324252627282930313233343536373839 |
- import type { TLDrawShape, Data, TLDrawCommand } from '~types'
- import { TLDR } from '~state/tldr'
-
- export function toggle(data: Data, ids: string[], prop: keyof TLDrawShape): TLDrawCommand {
- const { currentPageId } = data.appState
- const initialShapes = ids.map((id) => TLDR.getShape(data, id, currentPageId))
- const isAllToggled = initialShapes.every((shape) => shape[prop])
-
- const { before, after } = TLDR.mutateShapes(
- data,
- TLDR.getSelectedIds(data, currentPageId),
- () => ({
- [prop]: !isAllToggled,
- }),
- currentPageId
- )
-
- return {
- id: 'toggle_shapes',
- before: {
- document: {
- pages: {
- [currentPageId]: {
- shapes: before,
- },
- },
- },
- },
- after: {
- document: {
- pages: {
- [currentPageId]: {
- shapes: after,
- },
- },
- },
- },
- }
- }
|