import { Edge, EdgeProps, Node, NodeProps } from '@xyflow/react'; import { OptionalKeysOf, SetRequired, Simplify } from 'type-fest'; import { Base } from './Base'; export type BaseNodeData = { /** * Whether the cursor is hovering over the node */ hovered?: boolean; /** * Whether the node is dimmed * 'immediate' means that the node is dimmed without delay */ dimmed?: Base.Dimmed; }; export type BaseEdgeData = { /** * Whether the cursor is hovering over the edge */ hovered?: boolean; /** * Whether the edge is active (animated and highlighted) */ active?: boolean; /** * Whether the edge is dimmed * 'immediate' means that the edge is dimmed without delay */ dimmed?: Base.Dimmed; }; export type BaseNode = Record, NodeType extends string = string> = SetRequired, 'type' | 'initialWidth' | 'initialHeight'>; export interface BaseEdge = Record, EdgeType extends string = string> extends SetRequired, 'type' | 'data'> { } /** * ReactFlow Base Node properties with BaseNodeData at least */ export interface BaseNodeProps extends NodeProps { } export type BaseNodePropsWithData> = BaseNodeProps>; /** * ReactFlow Base Edge properties with BaseEdgeData at least */ export interface BaseEdgeProps extends EdgeProps { } export type BaseEdgePropsWithData> = BaseEdgeProps>; /** * To cooperate with `exactOptionalPropertyTypes` in `tsconfig.json` * * @example * interface User { * name: string; * surname?: string; * luckyNumber?: number; * } * * type NonOptionalUser = NonOptional * // NonOptionalUser = { * // name: string * // surname: string | undefined * // luckyNumber: number | undefined * // } */ export type NonOptional = OptionalKeysOf> = Simplify<{ [P in Exclude]: T[P]; } & { [P in Keys]-?: T[P] | undefined; }>;