chore(types): cleanup

This commit is contained in:
moklick
2023-10-23 17:47:50 +02:00
parent 6de9bbc916
commit e5acbbcf9d
6 changed files with 27 additions and 25 deletions
+1 -1
View File
@@ -178,7 +178,7 @@ export default function useReactFlow<NodeData = any, EdgeData = any>(): ReactFlo
const getNodeRect = useCallback( const getNodeRect = useCallback(
( (
nodeOrRect: (Partial<Node<NodeData>> & { id: Node['id'] }) | Rect nodeOrRect: Node<NodeData> | { id: Node['id'] } | Rect
): [Rect | null, Node<NodeData> | null | undefined, boolean] => { ): [Rect | null, Node<NodeData> | null | undefined, boolean] => {
const isRect = isRectObject(nodeOrRect); const isRect = isRectObject(nodeOrRect);
const node = isRect ? null : store.getState().nodes.find((n) => n.id === nodeOrRect.id); const node = isRect ? null : store.getState().nodes.find((n) => n.id === nodeOrRect.id);
+7 -7
View File
@@ -10,8 +10,8 @@ export type ReactFlowJsonObject<NodeData = any, EdgeData = any> = {
}; };
export type DeleteElementsOptions = { export type DeleteElementsOptions = {
nodes?: (Partial<Node> & { id: Node['id'] })[]; nodes?: (Node | { id: Node['id'] })[];
edges?: (Partial<Edge> & { id: Edge['id'] })[]; edges?: (Edge | { id: Edge['id'] })[];
}; };
export namespace Instance { export namespace Instance {
@@ -33,18 +33,18 @@ export namespace Instance {
deletedEdges: Edge[]; deletedEdges: Edge[];
}; };
export type GetIntersectingNodes<NodeData> = ( export type GetIntersectingNodes<NodeData> = (
node: (Partial<Node<NodeData>> & { id: Node['id'] }) | Rect, node: Node<NodeData> | { id: Node['id'] } | Rect,
partially?: boolean, partially?: boolean,
nodes?: Node<NodeData>[] nodes?: Node<NodeData>[]
) => Node<NodeData>[]; ) => Node<NodeData>[];
export type IsNodeIntersecting<NodeData> = ( export type IsNodeIntersecting<NodeData> = (
node: (Partial<Node<NodeData>> & { id: Node['id'] }) | Rect, node: Node<NodeData> | { id: Node['id'] } | Rect,
area: Rect, area: Rect,
partially?: boolean partially?: boolean
) => boolean; ) => boolean;
export type getConnectedEdges = (id: string | (Partial<Node> & { id: Node['id'] })[]) => Edge[]; export type getConnectedEdges = (id: string | (Node | { id: Node['id'] })[]) => Edge[];
export type getIncomers = (node: string | (Partial<Node> & { id: Node['id'] })) => Node[]; export type getIncomers = (node: string | Node | { id: Node['id'] }) => Node[];
export type getOutgoers = (node: string | (Partial<Node> & { id: Node['id'] })) => Node[]; export type getOutgoers = (node: string | Node | { id: Node['id'] }) => Node[];
} }
export type ReactFlowInstance<NodeData = any, EdgeData = any> = { export type ReactFlowInstance<NodeData = any, EdgeData = any> = {
+14 -14
View File
@@ -31,26 +31,26 @@ export function useSvelteFlow(): {
getViewport: () => Viewport; getViewport: () => Viewport;
fitView: (options?: FitViewOptions) => void; fitView: (options?: FitViewOptions) => void;
getIntersectingNodes: ( getIntersectingNodes: (
nodeOrRect: (Partial<Node> & { id: Node['id'] }) | Rect, nodeOrRect: Node | { id: Node['id'] } | Rect,
partially?: boolean, partially?: boolean,
nodesToIntersect?: Node[] nodesToIntersect?: Node[]
) => Node[]; ) => Node[];
isNodeIntersecting: ( isNodeIntersecting: (
nodeOrRect: (Partial<Node> & { id: Node['id'] }) | Rect, nodeOrRect: Node | { id: Node['id'] } | Rect,
area: Rect, area: Rect,
partially?: boolean partially?: boolean
) => boolean; ) => boolean;
fitBounds: (bounds: Rect, options?: FitBoundsOptions) => void; fitBounds: (bounds: Rect, options?: FitBoundsOptions) => void;
deleteElements: ( deleteElements: (
nodesToRemove?: Partial<Node> & { id: string }[], nodesToRemove?: (Node | { id: Node['id'] })[],
edgesToRemove?: Partial<Edge> & { id: string }[] edgesToRemove?: (Edge | { id: Edge['id'] })[]
) => { deletedNodes: Node[]; deletedEdges: Edge[] }; ) => { deletedNodes: Node[]; deletedEdges: Edge[] };
screenToFlowCoordinate: (position: XYPosition) => XYPosition; screenToFlowCoordinate: (position: XYPosition) => XYPosition;
flowToScreenCoordinate: (position: XYPosition) => XYPosition; flowToScreenCoordinate: (position: XYPosition) => XYPosition;
viewport: Writable<Viewport>; viewport: Writable<Viewport>;
getConnectedEdges: (id: string | (Partial<Node> & { id: Node['id'] })[]) => Edge[]; getConnectedEdges: (id: string | (Node | { id: Node['id'] })[]) => Edge[];
getIncomers: (node: string | (Partial<Node> & { id: Node['id'] })) => Node[]; getIncomers: (node: string | Node | { id: Node['id'] }) => Node[];
getOutgoers: (node: string | (Partial<Node> & { id: Node['id'] })) => Node[]; getOutgoers: (node: string | Node | { id: Node['id'] }) => Node[];
} { } {
const { const {
zoomIn, zoomIn,
@@ -69,7 +69,7 @@ export function useSvelteFlow(): {
} = useStore(); } = useStore();
const getNodeRect = ( const getNodeRect = (
nodeOrRect: (Partial<Node> & { id: Node['id'] }) | Rect nodeOrRect: Node | { id: Node['id'] } | Rect
): [Rect | null, Node | null | undefined, boolean] => { ): [Rect | null, Node | null | undefined, boolean] => {
const isRect = isRectObject(nodeOrRect); const isRect = isRectObject(nodeOrRect);
const node = isRect ? null : get(nodes).find((n) => n.id === nodeOrRect.id); const node = isRect ? null : get(nodes).find((n) => n.id === nodeOrRect.id);
@@ -136,7 +136,7 @@ export function useSvelteFlow(): {
); );
}, },
getIntersectingNodes: ( getIntersectingNodes: (
nodeOrRect: (Partial<Node> & { id: Node['id'] }) | Rect, nodeOrRect: Node | { id: Node['id'] } | Rect,
partially = true, partially = true,
nodesToIntersect?: Node[] nodesToIntersect?: Node[]
) => { ) => {
@@ -155,11 +155,11 @@ export function useSvelteFlow(): {
const overlappingArea = getOverlappingArea(currNodeRect, nodeRect); const overlappingArea = getOverlappingArea(currNodeRect, nodeRect);
const partiallyVisible = partially && overlappingArea > 0; const partiallyVisible = partially && overlappingArea > 0;
return partiallyVisible || overlappingArea >= nodeOrRect.width! * nodeOrRect.height!; return partiallyVisible || overlappingArea >= nodeRect.width * nodeRect.height;
}); });
}, },
isNodeIntersecting: ( isNodeIntersecting: (
nodeOrRect: (Partial<Node> & { id: Node['id'] }) | Rect, nodeOrRect: Node | { id: Node['id'] } | Rect,
area: Rect, area: Rect,
partially = true partially = true
) => { ) => {
@@ -172,11 +172,11 @@ export function useSvelteFlow(): {
const overlappingArea = getOverlappingArea(nodeRect, area); const overlappingArea = getOverlappingArea(nodeRect, area);
const partiallyVisible = partially && overlappingArea > 0; const partiallyVisible = partially && overlappingArea > 0;
return partiallyVisible || overlappingArea >= nodeOrRect.width! * nodeOrRect.height!; return partiallyVisible || overlappingArea >= nodeRect.width * nodeRect.height;
}, },
deleteElements: ( deleteElements: (
nodesToRemove: Partial<Node> & { id: string }[] = [], nodesToRemove: (Node | { id: Node['id'] })[] = [],
edgesToRemove: Partial<Edge> & { id: string }[] = [] edgesToRemove: (Edge | { id: Edge['id'] })[] = []
) => { ) => {
const _nodes = get(nodes); const _nodes = get(nodes);
const _edges = get(edges); const _edges = get(edges);
+2
View File
@@ -39,6 +39,8 @@ export type Edge<T = any> =
export type EdgeProps = Omit<Edge, 'sourceHandle' | 'targetHandle'> & export type EdgeProps = Omit<Edge, 'sourceHandle' | 'targetHandle'> &
EdgePosition & { EdgePosition & {
markerStart?: string;
markerEnd?: string;
sourceHandleId?: string | null; sourceHandleId?: string | null;
targetHandleId?: string | null; targetHandleId?: string | null;
}; };
+1 -1
View File
@@ -63,7 +63,7 @@ export type FitViewOptionsBase<NodeType extends NodeBase> = {
minZoom?: number; minZoom?: number;
maxZoom?: number; maxZoom?: number;
duration?: number; duration?: number;
nodes?: (Partial<NodeType> & { id: NodeType['id'] })[]; nodes?: (NodeType | { id: NodeType['id'] })[];
}; };
export type Viewport = { export type Viewport = {
+2 -2
View File
@@ -35,7 +35,7 @@ export const isNodeBase = <NodeType extends NodeBase = NodeBase, EdgeType extend
): element is NodeType => 'id' in element && !('source' in element) && !('target' in element); ): element is NodeType => 'id' in element && !('source' in element) && !('target' in element);
export const getOutgoersBase = <NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>( export const getOutgoersBase = <NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(
node: Partial<NodeType> & { id: string }, node: NodeType | { id: string },
nodes: NodeType[], nodes: NodeType[],
edges: EdgeType[] edges: EdgeType[]
): NodeType[] => { ): NodeType[] => {
@@ -54,7 +54,7 @@ export const getOutgoersBase = <NodeType extends NodeBase = NodeBase, EdgeType e
}; };
export const getIncomersBase = <NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>( export const getIncomersBase = <NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(
node: Partial<NodeType> & { id: string }, node: NodeType | { id: string },
nodes: NodeType[], nodes: NodeType[],
edges: EdgeType[] edges: EdgeType[]
): NodeType[] => { ): NodeType[] => {