import type { Dimensions, EdgeBase, NodeBase, XYPosition } from '../types'; export type NodeChange = | DimensionChange | PositionChange | SelectionChange | RemoveChange | AddChange | ReplaceChange | UpdateChange | DataChange; export type EdgeChange = | SelectionChange | RemoveChange | AddChange | ReplaceChange | UpdateChange | DataChange>; // Narrow down change type based on the element type (Node -> NodeChange, Edge -> EdgeChange) export type ElementChangeType = | NodeChange | EdgeChange; export type DimensionChange = { id: string; type: 'dimensions'; dimensions?: Dimensions; /* if this is true, the node is currently being resized via the NodeResizer */ resizing?: boolean; /* if this is true, we will set width and height of the node and not just the measured dimensions */ setAttributes?: boolean | 'width' | 'height'; }; export type PositionChange = { id: string; type: 'position'; position?: XYPosition; positionAbsolute?: XYPosition; dragging?: boolean; }; export type SelectionChange = { id: string; type: 'select'; selected: boolean; }; export type RemoveChange = { id: string; type: 'remove'; }; export type AddChange = { id: string; item: NodeOrEdge; type: 'add'; index?: number; }; export type ReplaceChange = { id: string; item: NodeOrEdge; type: 'replace'; }; export type UpdateChange = { id: string; item: Partial; type: 'update'; }; export type DataChange> = | { id: string; type: 'data'; /* the data gets merged into the existing data */ data: Partial; replace?: false; } | { id: string; type: 'data'; /* the data replaces the existing data, so it has to be complete */ data: Data; replace: true; };