import type { TDShape, TldrawCommand, } from '@toeverything/components/board-types'; import type { TldrawApp } from '@toeverything/components/board-state'; export function setShapesProps( app: TldrawApp, ids: string[], partial: Partial ): TldrawCommand { const { currentPageId, selectedIds } = app; const initialShapes = ids .map(id => app.getShape(id)) .filter(shape => (partial['isLocked'] ? true : !shape.isLocked)); const before: Record> = {}; const after: Record> = {}; const keys = Object.keys(partial) as (keyof T)[]; initialShapes.forEach(shape => { before[shape.id] = Object.fromEntries( keys.map(key => [key, shape[key]]) ); after[shape.id] = partial; }); return { id: 'set_props', before: { document: { pages: { [currentPageId]: { shapes: before, }, }, pageStates: { [currentPageId]: { selectedIds, }, }, }, }, after: { document: { pages: { [currentPageId]: { shapes: after, }, }, pageStates: { [currentPageId]: { selectedIds, }, }, }, }, }; }