refactor(types): cleanup edge types
This commit is contained in:
@@ -20,6 +20,7 @@ import type {
|
||||
OnError,
|
||||
IsValidConnection,
|
||||
ColorMode,
|
||||
SnapGrid,
|
||||
} from '@xyflow/system';
|
||||
|
||||
import type {
|
||||
@@ -110,7 +111,7 @@ export type ReactFlowProps = Omit<HTMLAttributes<HTMLDivElement>, 'onError'> & {
|
||||
multiSelectionKeyCode?: KeyCode | null;
|
||||
zoomActivationKeyCode?: KeyCode | null;
|
||||
snapToGrid?: boolean;
|
||||
snapGrid?: [number, number];
|
||||
snapGrid?: SnapGrid;
|
||||
onlyRenderVisibleElements?: boolean;
|
||||
nodesDraggable?: boolean;
|
||||
nodesConnectable?: boolean;
|
||||
|
||||
@@ -13,7 +13,6 @@ import type {
|
||||
HandleElement,
|
||||
ConnectionStatus,
|
||||
EdgePosition,
|
||||
Optional,
|
||||
StepPathOptions,
|
||||
} from '@xyflow/system';
|
||||
|
||||
@@ -30,13 +29,13 @@ export type EdgeLabelOptions = {
|
||||
|
||||
export type EdgeUpdatable = boolean | HandleType;
|
||||
|
||||
export type DefaultEdge<EdgeData = any> = EdgeBase<EdgeData> & {
|
||||
style?: CSSProperties;
|
||||
className?: string;
|
||||
sourceNode?: Node;
|
||||
targetNode?: Node;
|
||||
updatable?: EdgeUpdatable;
|
||||
} & EdgeLabelOptions;
|
||||
export type DefaultEdge<EdgeData = any> = EdgeBase<EdgeData> &
|
||||
EdgeLabelOptions & {
|
||||
style?: CSSProperties;
|
||||
className?: string;
|
||||
updatable?: EdgeUpdatable;
|
||||
focusable?: boolean;
|
||||
};
|
||||
|
||||
type SmoothStepEdgeType<T> = DefaultEdge<T> & {
|
||||
type: 'smoothstep';
|
||||
@@ -53,6 +52,9 @@ type StepEdgeType<T> = DefaultEdge<T> & {
|
||||
pathOptions?: StepPathOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
* The Edge type is mainly used for the `edges` that get passed to the ReactFlow component.
|
||||
*/
|
||||
export type Edge<T = any> = DefaultEdge<T> | SmoothStepEdgeType<T> | BezierEdgeType<T> | StepEdgeType<T>;
|
||||
|
||||
export type EdgeMouseHandler = (event: ReactMouseEvent, edge: Edge) => void;
|
||||
@@ -85,45 +87,58 @@ export type EdgeTextProps = HTMLAttributes<SVGElement> &
|
||||
y: number;
|
||||
};
|
||||
|
||||
// props that get passed to a custom edge
|
||||
/**
|
||||
* Custom edge component props.
|
||||
*/
|
||||
export type EdgeProps<T = any> = Pick<
|
||||
Edge<T>,
|
||||
'id' | 'animated' | 'data' | 'style' | 'selected' | 'source' | 'target'
|
||||
> &
|
||||
Pick<WrapEdgeProps, 'sourceHandleId' | 'targetHandleId' | 'interactionWidth'> &
|
||||
EdgePosition &
|
||||
EdgeLabelOptions & {
|
||||
interactionWidth?: number;
|
||||
sourceHandleId?: string | null;
|
||||
targetHandleId?: string | null;
|
||||
markerStart?: string;
|
||||
markerEnd?: string;
|
||||
// @TODO: how can we get better types for pathOptions?
|
||||
pathOptions?: any;
|
||||
};
|
||||
|
||||
export type BaseEdgeProps = Pick<EdgeProps, 'style' | 'markerStart' | 'markerEnd' | 'interactionWidth'> &
|
||||
/**
|
||||
* BaseEdge component props.
|
||||
*/
|
||||
export type BaseEdgeProps = EdgeLabelOptions & {
|
||||
id?: string;
|
||||
interactionWidth?: number;
|
||||
labelX?: number;
|
||||
labelY?: number;
|
||||
markerStart?: string;
|
||||
markerEnd?: string;
|
||||
path: string;
|
||||
style?: CSSProperties;
|
||||
};
|
||||
|
||||
export type EdgeComponentProps = EdgePosition &
|
||||
EdgeLabelOptions & {
|
||||
id?: string;
|
||||
labelX?: number;
|
||||
labelY?: number;
|
||||
path: string;
|
||||
id?: EdgeProps['id'];
|
||||
markerStart?: EdgeProps['markerStart'];
|
||||
markerEnd?: EdgeProps['markerEnd'];
|
||||
interactionWidth?: EdgeProps['interactionWidth'];
|
||||
style?: EdgeProps['style'];
|
||||
sourceHandleId?: EdgeProps['sourceHandleId'];
|
||||
targetHandleId?: EdgeProps['targetHandleId'];
|
||||
};
|
||||
|
||||
export type EdgeComponentProps<T = any> = Optional<Omit<EdgeProps<T>, 'source' | 'target'>, 'id'>;
|
||||
|
||||
export type StraightEdgeProps<T = any> = Omit<EdgeComponentProps<T>, 'sourcePosition' | 'targetPosition'>;
|
||||
|
||||
export type SmoothStepEdgeProps<T = any> = EdgeComponentProps<T> & {
|
||||
pathOptions?: SmoothStepPathOptions;
|
||||
export type EdgeComponentWithPathOptions<PathOptions> = EdgeComponentProps & {
|
||||
pathOptions?: PathOptions;
|
||||
};
|
||||
|
||||
export type BezierEdgeProps<T = any> = EdgeComponentProps<T> & {
|
||||
pathOptions?: BezierPathOptions;
|
||||
};
|
||||
|
||||
export type StepEdgeProps<T = any> = EdgeComponentProps<T> & {
|
||||
pathOptions?: StepPathOptions;
|
||||
};
|
||||
|
||||
export type SimpleBezierEdgeProps<T = any> = EdgeComponentProps<T>;
|
||||
export type BezierEdgeProps = EdgeComponentWithPathOptions<BezierPathOptions>;
|
||||
export type SmoothStepEdgeProps = EdgeComponentWithPathOptions<SmoothStepPathOptions>;
|
||||
export type StepEdgeProps = EdgeComponentWithPathOptions<StepPathOptions>;
|
||||
export type StraightEdgeProps = Omit<EdgeComponentProps, 'sourcePosition' | 'targetPosition'>;
|
||||
export type SimpleBezierEdgeProps = EdgeComponentProps;
|
||||
|
||||
export type OnEdgeUpdateFunc<T = any> = (oldEdge: Edge<T>, newConnection: Connection) => void;
|
||||
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
import type { CSSProperties, MouseEvent as ReactMouseEvent } from 'react';
|
||||
import type { NodeBase, XYPosition } from '@xyflow/system';
|
||||
|
||||
/**
|
||||
* The node data structure that gets used for the nodes prop.
|
||||
* @public
|
||||
*/
|
||||
export type Node<NodeData = any, NodeType extends string | undefined = string | undefined> = NodeBase<
|
||||
NodeData,
|
||||
NodeType
|
||||
> & {
|
||||
/**
|
||||
* Inline style object
|
||||
*/
|
||||
style?: CSSProperties;
|
||||
/**
|
||||
* Inline style object
|
||||
*/
|
||||
className?: string;
|
||||
/**
|
||||
* Inline style object
|
||||
*/
|
||||
resizing?: boolean;
|
||||
};
|
||||
|
||||
@@ -17,30 +30,32 @@ export type SelectionDragHandler = (event: ReactMouseEvent, nodes: Node[]) => vo
|
||||
export type WrapNodeProps<NodeData = any> = Pick<
|
||||
Node<NodeData>,
|
||||
'id' | 'data' | 'style' | 'className' | 'dragHandle' | 'sourcePosition' | 'targetPosition' | 'hidden' | 'ariaLabel'
|
||||
> &
|
||||
Required<Pick<Node<NodeData>, 'selected' | 'type' | 'zIndex'>> & {
|
||||
isConnectable: boolean;
|
||||
xPos: number;
|
||||
yPos: number;
|
||||
xPosOrigin: number;
|
||||
yPosOrigin: number;
|
||||
positionAbsolute: XYPosition;
|
||||
initialized: boolean;
|
||||
isSelectable: boolean;
|
||||
isDraggable: boolean;
|
||||
isFocusable: boolean;
|
||||
onClick?: NodeMouseHandler;
|
||||
onDoubleClick?: NodeMouseHandler;
|
||||
onMouseEnter?: NodeMouseHandler;
|
||||
onMouseMove?: NodeMouseHandler;
|
||||
onMouseLeave?: NodeMouseHandler;
|
||||
onContextMenu?: NodeMouseHandler;
|
||||
resizeObserver: ResizeObserver | null;
|
||||
isParent: boolean;
|
||||
noDragClassName: string;
|
||||
noPanClassName: string;
|
||||
rfId: string;
|
||||
disableKeyboardA11y: boolean;
|
||||
width?: number;
|
||||
height?: number;
|
||||
};
|
||||
> & {
|
||||
type: string;
|
||||
selected: boolean;
|
||||
zIndex: number;
|
||||
isConnectable: boolean;
|
||||
xPos: number;
|
||||
yPos: number;
|
||||
xPosOrigin: number;
|
||||
yPosOrigin: number;
|
||||
positionAbsolute: XYPosition;
|
||||
initialized: boolean;
|
||||
isSelectable: boolean;
|
||||
isDraggable: boolean;
|
||||
isFocusable: boolean;
|
||||
onClick?: NodeMouseHandler;
|
||||
onDoubleClick?: NodeMouseHandler;
|
||||
onMouseEnter?: NodeMouseHandler;
|
||||
onMouseMove?: NodeMouseHandler;
|
||||
onMouseLeave?: NodeMouseHandler;
|
||||
onContextMenu?: NodeMouseHandler;
|
||||
resizeObserver: ResizeObserver | null;
|
||||
isParent: boolean;
|
||||
noDragClassName: string;
|
||||
noPanClassName: string;
|
||||
rfId: string;
|
||||
disableKeyboardA11y: boolean;
|
||||
width?: number;
|
||||
height?: number;
|
||||
};
|
||||
|
||||
@@ -6,13 +6,12 @@ import type {
|
||||
DefaultEdgeOptionsBase,
|
||||
EdgePosition,
|
||||
SmoothStepPathOptions,
|
||||
Optional,
|
||||
StepPathOptions
|
||||
} from '@xyflow/system';
|
||||
|
||||
import type { Node } from '$lib/types';
|
||||
|
||||
export type DefaultEdge<EdgeData = any> = Omit<EdgeBase<EdgeData>, 'focusable'> & {
|
||||
export type DefaultEdge<EdgeData = any> = EdgeBase<EdgeData> & {
|
||||
label?: string;
|
||||
labelStyle?: string;
|
||||
style?: string;
|
||||
@@ -34,12 +33,18 @@ type StepEdgeType<T> = DefaultEdge<T> & {
|
||||
pathOptions?: StepPathOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
* The Edge type is mainly used for the `edges` that get passed to the SvelteFlow component.
|
||||
*/
|
||||
export type Edge<T = any> =
|
||||
| DefaultEdge<T>
|
||||
| SmoothStepEdgeType<T>
|
||||
| BezierEdgeType<T>
|
||||
| StepEdgeType<T>;
|
||||
|
||||
/**
|
||||
* Custom edge component props.
|
||||
*/
|
||||
export type EdgeProps<T = any> = Omit<Edge<T>, 'sourceHandle' | 'targetHandle' | 'type'> &
|
||||
EdgePosition & {
|
||||
markerStart?: string;
|
||||
@@ -48,30 +53,30 @@ export type EdgeProps<T = any> = Omit<Edge<T>, 'sourceHandle' | 'targetHandle' |
|
||||
targetHandleId?: string | null;
|
||||
};
|
||||
|
||||
export type EdgeComponentProps<T = any> = Optional<
|
||||
Omit<
|
||||
EdgeProps<T>,
|
||||
'source' | 'target' | 'sourceHandleId' | 'targetHandleId' | 'animated' | 'selected' | 'data'
|
||||
>,
|
||||
'id'
|
||||
>;
|
||||
|
||||
export type BezierEdgeProps<T = any> = EdgeComponentProps<T> & {
|
||||
pathOptions?: BezierPathOptions;
|
||||
export type EdgeComponentProps = EdgePosition & {
|
||||
id?: EdgeProps['id'];
|
||||
hidden?: EdgeProps['hidden'];
|
||||
deletable?: EdgeProps['deletable'];
|
||||
selectable?: EdgeProps['selectable'];
|
||||
markerStart?: EdgeProps['markerStart'];
|
||||
markerEnd?: EdgeProps['markerEnd'];
|
||||
zIndex?: EdgeProps['zIndex'];
|
||||
ariaLabel?: EdgeProps['ariaLabel'];
|
||||
interactionWidth?: EdgeProps['interactionWidth'];
|
||||
label?: EdgeProps['label'];
|
||||
labelStyle?: EdgeProps['labelStyle'];
|
||||
style?: EdgeProps['style'];
|
||||
class?: EdgeProps['class'];
|
||||
};
|
||||
|
||||
export type SmoothStepEdgeProps<T = any> = EdgeComponentProps<T> & {
|
||||
pathOptions?: SmoothStepPathOptions;
|
||||
export type EdgeComponentWithPathOptions<PathOptions> = EdgeComponentProps & {
|
||||
pathOptions?: PathOptions;
|
||||
};
|
||||
|
||||
export type StepEdgeProps<T = any> = EdgeComponentProps<T> & {
|
||||
pathOptions?: StepPathOptions;
|
||||
};
|
||||
|
||||
export type StraightEdgeProps<T = any> = Omit<
|
||||
EdgeComponentProps<T>,
|
||||
'sourcePosition' | 'targetPosition'
|
||||
>;
|
||||
export type BezierEdgeProps = EdgeComponentWithPathOptions<BezierPathOptions>;
|
||||
export type SmoothStepEdgeProps = EdgeComponentWithPathOptions<SmoothStepPathOptions>;
|
||||
export type StepEdgeProps = EdgeComponentWithPathOptions<StepPathOptions>;
|
||||
export type StraightEdgeProps = Omit<EdgeComponentProps, 'sourcePosition' | 'targetPosition'>;
|
||||
|
||||
export type EdgeTypes = Record<string, ComponentType<SvelteComponent<EdgeProps>>>;
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ export type EdgeBase<EdgeData = any> = {
|
||||
zIndex?: number;
|
||||
ariaLabel?: string;
|
||||
interactionWidth?: number;
|
||||
focusable?: boolean;
|
||||
};
|
||||
|
||||
export type SmoothStepPathOptions = {
|
||||
@@ -37,7 +36,7 @@ export type BezierPathOptions = {
|
||||
|
||||
export type DefaultEdgeOptionsBase<EdgeType extends EdgeBase> = Omit<
|
||||
EdgeType,
|
||||
'id' | 'source' | 'target' | 'sourceHandle' | 'targetHandle' | 'sourceNode' | 'targetNode'
|
||||
'id' | 'source' | 'target' | 'sourceHandle' | 'targetHandle'
|
||||
>;
|
||||
|
||||
export enum ConnectionLineType {
|
||||
|
||||
Reference in New Issue
Block a user