chore(onbeforedelete): use correct node/edge types, pass generic
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
|||||||
applyNodeChanges,
|
applyNodeChanges,
|
||||||
OnNodesChange,
|
OnNodesChange,
|
||||||
OnConnect,
|
OnConnect,
|
||||||
|
OnBeforeDelete,
|
||||||
} from '@xyflow/react';
|
} from '@xyflow/react';
|
||||||
|
|
||||||
import ColorSelectorNode from './ColorSelectorNode';
|
import ColorSelectorNode from './ColorSelectorNode';
|
||||||
@@ -142,6 +143,8 @@ const CustomNodeFlow = () => {
|
|||||||
[setEdges]
|
[setEdges]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onBeforeDelete: OnBeforeDelete<MyNode> = useCallback(async (params) => true, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactFlow
|
<ReactFlow
|
||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
@@ -159,6 +162,7 @@ const CustomNodeFlow = () => {
|
|||||||
fitView
|
fitView
|
||||||
minZoom={0.3}
|
minZoom={0.3}
|
||||||
maxZoom={2}
|
maxZoom={2}
|
||||||
|
onBeforeDelete={onBeforeDelete}
|
||||||
>
|
>
|
||||||
<MiniMap
|
<MiniMap
|
||||||
nodeStrokeColor={(n: MyNode): string => {
|
nodeStrokeColor={(n: MyNode): string => {
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ export {
|
|||||||
type ColorMode,
|
type ColorMode,
|
||||||
type ColorModeClass,
|
type ColorModeClass,
|
||||||
type HandleType,
|
type HandleType,
|
||||||
type OnBeforeDelete,
|
|
||||||
type ShouldResize,
|
type ShouldResize,
|
||||||
type OnResizeStart,
|
type OnResizeStart,
|
||||||
type OnResize,
|
type OnResize,
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import type {
|
|||||||
IsValidConnection,
|
IsValidConnection,
|
||||||
ColorMode,
|
ColorMode,
|
||||||
SnapGrid,
|
SnapGrid,
|
||||||
OnBeforeDelete,
|
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -44,6 +43,7 @@ import type {
|
|||||||
SelectionDragHandler,
|
SelectionDragHandler,
|
||||||
EdgeMouseHandler,
|
EdgeMouseHandler,
|
||||||
OnNodeDrag,
|
OnNodeDrag,
|
||||||
|
OnBeforeDelete,
|
||||||
} from '.';
|
} from '.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
FitBounds,
|
FitBounds,
|
||||||
XYPosition,
|
XYPosition,
|
||||||
NodeProps,
|
NodeProps,
|
||||||
|
OnBeforeDeleteBase,
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import type { NodeChange, EdgeChange, Node, Edge, ReactFlowInstance, EdgeProps } from '.';
|
import type { NodeChange, EdgeChange, Node, Edge, ReactFlowInstance, EdgeProps } from '.';
|
||||||
@@ -59,3 +60,8 @@ export type ViewportHelperFunctions = {
|
|||||||
flowToScreenPosition: (position: XYPosition) => XYPosition;
|
flowToScreenPosition: (position: XYPosition) => XYPosition;
|
||||||
viewportInitialized: boolean;
|
viewportInitialized: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type OnBeforeDelete<NodeType extends Node = Node, EdgeType extends Edge = Edge> = OnBeforeDeleteBase<
|
||||||
|
NodeType,
|
||||||
|
EdgeType
|
||||||
|
>;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import {
|
|||||||
type EdgeLookup,
|
type EdgeLookup,
|
||||||
type ConnectionLookup,
|
type ConnectionLookup,
|
||||||
type NodeLookup,
|
type NodeLookup,
|
||||||
OnBeforeDelete,
|
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -43,6 +42,7 @@ import type {
|
|||||||
UnselectNodesAndEdgesParams,
|
UnselectNodesAndEdgesParams,
|
||||||
OnDelete,
|
OnDelete,
|
||||||
OnNodeDrag,
|
OnNodeDrag,
|
||||||
|
OnBeforeDelete,
|
||||||
} from '.';
|
} from '.';
|
||||||
|
|
||||||
export type ReactFlowStore = {
|
export type ReactFlowStore = {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import {
|
|||||||
type OnConnectStart,
|
type OnConnectStart,
|
||||||
type OnConnectEnd,
|
type OnConnectEnd,
|
||||||
type NodeLookup,
|
type NodeLookup,
|
||||||
type OnBeforeDelete,
|
|
||||||
type EdgeLookup
|
type EdgeLookup
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
@@ -47,7 +46,8 @@ import type {
|
|||||||
Edge,
|
Edge,
|
||||||
FitViewOptions,
|
FitViewOptions,
|
||||||
OnDelete,
|
OnDelete,
|
||||||
OnEdgeCreate
|
OnEdgeCreate,
|
||||||
|
OnBeforeDelete
|
||||||
} from '$lib/types';
|
} from '$lib/types';
|
||||||
import { createNodesStore, createEdgesStore } from './utils';
|
import { createNodesStore, createEdgesStore } from './utils';
|
||||||
import { initConnectionProps, type ConnectionProps } from './derived-connection-props';
|
import { initConnectionProps, type ConnectionProps } from './derived-connection-props';
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import type {
|
|||||||
Position,
|
Position,
|
||||||
XYPosition,
|
XYPosition,
|
||||||
ConnectingHandle,
|
ConnectingHandle,
|
||||||
Connection
|
Connection,
|
||||||
|
OnBeforeDeleteBase
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import type { Node } from './nodes';
|
import type { Node } from './nodes';
|
||||||
@@ -52,3 +53,7 @@ export type FitViewOptions = FitViewOptionsBase<Node>;
|
|||||||
|
|
||||||
export type OnDelete = (params: { nodes: Node[]; edges: Edge[] }) => void;
|
export type OnDelete = (params: { nodes: Node[]; edges: Edge[] }) => void;
|
||||||
export type OnEdgeCreate = (connection: Connection) => Edge | Connection | void;
|
export type OnEdgeCreate = (connection: Connection) => Edge | Connection | void;
|
||||||
|
export type OnBeforeDelete<
|
||||||
|
NodeType extends Node = Node,
|
||||||
|
EdgeType extends Edge = Edge
|
||||||
|
> = OnBeforeDeleteBase<NodeType, EdgeType>;
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ export type ColorMode = ColorModeClass | 'system';
|
|||||||
|
|
||||||
export type ConnectionLookup = Map<string, Map<string, Connection>>;
|
export type ConnectionLookup = Map<string, Map<string, Connection>>;
|
||||||
|
|
||||||
export type OnBeforeDelete = <NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>({
|
export type OnBeforeDeleteBase<NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase> = ({
|
||||||
nodes,
|
nodes,
|
||||||
edges,
|
edges,
|
||||||
}: {
|
}: {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
NodeDragItem,
|
NodeDragItem,
|
||||||
CoordinateExtent,
|
CoordinateExtent,
|
||||||
OnError,
|
OnError,
|
||||||
OnBeforeDelete,
|
OnBeforeDeleteBase,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { errorMessages } from '../constants';
|
import { errorMessages } from '../constants';
|
||||||
|
|
||||||
@@ -347,7 +347,7 @@ export async function getElementsToRemove<NodeType extends NodeBase = NodeBase,
|
|||||||
edgesToRemove: Partial<EdgeType>[];
|
edgesToRemove: Partial<EdgeType>[];
|
||||||
nodes: NodeType[];
|
nodes: NodeType[];
|
||||||
edges: EdgeType[];
|
edges: EdgeType[];
|
||||||
onBeforeDelete?: OnBeforeDelete;
|
onBeforeDelete?: OnBeforeDeleteBase<NodeType, EdgeType>;
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
nodes: NodeType[];
|
nodes: NodeType[];
|
||||||
edges: EdgeType[];
|
edges: EdgeType[];
|
||||||
|
|||||||
Reference in New Issue
Block a user