import type { Dimensions, XYPosition } from '../types'; import type { AddChange, DataChange, DimensionChange, PositionChange, RemoveChange, ReplaceChange, SelectionChange, UpdateChange, } from './types'; export function selectionChange(id: string, selected: boolean): SelectionChange { return { id, type: 'select', selected, }; } export function positionChange(id: string, position: XYPosition): PositionChange { return { id, type: 'position', position, }; } export function dimensionChange(id: string, dimensions: Dimensions): DimensionChange { return { id, type: 'dimensions', dimensions, }; } export function removeChange(id: string): RemoveChange { return { id, type: 'remove', }; } export function addChange(item: T): AddChange { return { id: item.id, item: item, type: 'add', }; } export function replaceChange(item: T): ReplaceChange { return { id: item.id, item: item, type: 'replace', }; } export function updateChange(id: string, item: Partial): UpdateChange { return { id, item, type: 'update', }; } export function dataChange>(id: string, data: Data, replace: true): DataChange; export function dataChange>( id: string, data: Partial, replace?: false ): DataChange; export function dataChange>( id: string, data: Partial, replace?: boolean ): DataChange { return (replace ? { id, type: 'data', data, replace } : { id, type: 'data', data }) as DataChange; }