refactor(types): cleanup edge types

This commit is contained in:
moklick
2023-12-06 15:56:17 +01:00
parent b264c11c54
commit ba8ee0272a
5 changed files with 117 additions and 82 deletions
+27 -22
View File
@@ -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>>>;