diff --git a/src/types/index.ts b/src/types/index.ts index 5866b050..9fab312e 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,9 +2,9 @@ import { CSSProperties, MouseEvent as ReactMouseEvent } from 'react'; export type ElementId = string; -export type FlowElement = Node | Edge; +export type FlowElement = Node | Edge; -export type Elements = Array; +export type Elements = Array>; export type Transform = [number, number, number]; @@ -34,12 +34,12 @@ export interface Box extends XYPosition { export type SnapGrid = [number, number]; -export interface Node { +export interface Node { id: ElementId; position: XYPosition; type?: string; __rf?: any; - data?: any; + data?: T; style?: CSSProperties; className?: string; targetPosition?: Position; @@ -55,7 +55,7 @@ export enum ArrowHeadType { ArrowClosed = 'arrowclosed', } -export interface Edge { +export interface Edge { id: ElementId; type?: string; source: ElementId; @@ -72,7 +72,7 @@ export interface Edge { animated?: boolean; arrowHeadType?: ArrowHeadType; isHidden?: boolean; - data?: any; + data?: T; className?: string; } @@ -93,11 +93,11 @@ export interface SelectionRect extends Rect { draw: boolean; } -export interface WrapEdgeProps { +export interface WrapEdgeProps { id: ElementId; className?: string; type: string; - data?: any; + data?: T; onClick?: (event: React.MouseEvent, edge: Edge) => void; selected: boolean; animated?: boolean; @@ -126,7 +126,7 @@ export interface WrapEdgeProps { onConnectEdge: OnConnectFunc; } -export interface EdgeProps { +export interface EdgeProps { id: ElementId; source: ElementId; target: ElementId; @@ -147,9 +147,9 @@ export interface EdgeProps { style?: CSSProperties; arrowHeadType?: ArrowHeadType; markerEndId?: string; - data?: any; + data?: T; } -export interface EdgeSmoothStepProps extends EdgeProps { +export interface EdgeSmoothStepProps extends EdgeProps { borderRadius?: number; } @@ -164,10 +164,10 @@ export interface EdgeTextProps { labelBgBorderRadius?: number; } -export interface NodeProps { +export interface NodeProps { id: ElementId; type: string; - data: any; + data: T; selected: boolean; isConnectable: boolean; xPos?: number; @@ -177,10 +177,10 @@ export interface NodeProps { isDragging?: boolean; } -export interface NodeComponentProps { +export interface NodeComponentProps { id: ElementId; type: string; - data: any; + data: T; selected?: boolean; isConnectable: boolean; transform?: Transform; @@ -199,10 +199,10 @@ export interface NodeComponentProps { isDragging?: boolean; } -export interface WrapNodeProps { +export interface WrapNodeProps { id: ElementId; type: string; - data: any; + data: T; selected: boolean; scale: number; xPos: number; @@ -234,28 +234,28 @@ export type FitViewParams = { padding: number; }; -export type FlowExportObject = { - elements: Elements; +export type FlowExportObject = { + elements: Elements; position: [number, number]; zoom: number; }; export type FitViewFunc = (fitViewOptions?: FitViewParams) => void; export type ProjectFunc = (position: XYPosition) => XYPosition; -export type ToObjectFunc = () => FlowExportObject; +export type ToObjectFunc = () => FlowExportObject; -export type OnLoadParams = { +export type OnLoadParams = { zoomIn: () => void; zoomOut: () => void; zoomTo: (zoomLevel: number) => void; fitView: FitViewFunc; project: ProjectFunc; - getElements: () => Elements; + getElements: () => Elements; setTransform: (transform: FlowTransform) => void; - toObject: ToObjectFunc; + toObject: ToObjectFunc; }; -export type OnLoadFunc = (params: OnLoadParams) => void; +export type OnLoadFunc = (params: OnLoadParams) => void; export interface Connection { source: ElementId | null; @@ -359,4 +359,4 @@ export interface ZoomPanHelperFunctions { initialized: boolean; } -export type OnEdgeUpdateFunc = (oldEdge: Edge, newConnection: Connection) => void; +export type OnEdgeUpdateFunc = (oldEdge: Edge, newConnection: Connection) => void;