refactor(types): only export HandleProps but not HandleComponentProps

This commit is contained in:
moklick
2024-05-07 16:22:26 +02:00
parent 5093213116
commit 2b0d75ddaa
8 changed files with 19 additions and 41 deletions
@@ -1,7 +1,7 @@
import { memo, FC, useEffect, useCallback } from 'react'; import { memo, FC, useEffect, useCallback } from 'react';
import { Handle, Position, NodeProps, useHandleConnections, Connection, HandleComponentProps } from '@xyflow/react'; import { Handle, Position, NodeProps, useHandleConnections, Connection, HandleProps } from '@xyflow/react';
function CustomHandle({ nodeId, ...handleProps }: HandleComponentProps & { nodeId: string }) { function CustomHandle({ nodeId, ...handleProps }: HandleProps & { nodeId: string }) {
const onConnect = useCallback( const onConnect = useCallback(
(connections: Connection[]) => console.log('onConnect handler, node id:', nodeId, connections), (connections: Connection[]) => console.log('onConnect handler, node id:', nodeId, connections),
[nodeId] [nodeId]
@@ -1,7 +1,7 @@
import { memo, FC, useEffect, useCallback } from 'react'; import { memo, FC, useEffect, useCallback } from 'react';
import { Handle, Position, NodeProps, useHandleConnections, Connection, HandleComponentProps } from '@xyflow/react'; import { Handle, Position, NodeProps, useHandleConnections, Connection, HandleProps } from '@xyflow/react';
function CustomHandle({ nodeId, ...handleProps }: HandleComponentProps & { nodeId: string }) { function CustomHandle({ nodeId, ...handleProps }: HandleProps & { nodeId: string }) {
const onConnect = useCallback( const onConnect = useCallback(
(connections: Connection[]) => { (connections: Connection[]) => {
console.log('onConnect handler, node id:', nodeId, connections); console.log('onConnect handler, node id:', nodeId, connections);
@@ -14,10 +14,11 @@ import {
getHostForElement, getHostForElement,
isMouseEvent, isMouseEvent,
addEdge, addEdge,
type HandleProps, type HandleProps as HandlePropsSystem,
type Connection, type Connection,
type HandleType, type HandleType,
ConnectionMode, ConnectionMode,
OnConnect,
} from '@xyflow/system'; } from '@xyflow/system';
import { useStore, useStoreApi } from '../../hooks/useStore'; import { useStore, useStoreApi } from '../../hooks/useStore';
@@ -25,7 +26,10 @@ import { useNodeId } from '../../contexts/NodeIdContext';
import { type ReactFlowState } from '../../types'; import { type ReactFlowState } from '../../types';
import { fixedForwardRef } from '../../utils'; import { fixedForwardRef } from '../../utils';
export interface HandleComponentProps extends HandleProps, Omit<HTMLAttributes<HTMLDivElement>, 'id'> {} export interface HandleProps extends HandlePropsSystem, Omit<HTMLAttributes<HTMLDivElement>, 'id'> {
/** Callback called when connection is made */
onConnect?: OnConnect;
}
const selector = (s: ReactFlowState) => ({ const selector = (s: ReactFlowState) => ({
connectOnClick: s.connectOnClick, connectOnClick: s.connectOnClick,
@@ -75,7 +79,7 @@ function HandleComponent(
onMouseDown, onMouseDown,
onTouchStart, onTouchStart,
...rest ...rest
}: HandleComponentProps, }: HandleProps,
ref: ForwardedRef<HTMLDivElement> ref: ForwardedRef<HTMLDivElement>
) { ) {
const handleId = id || null; const handleId = id || null;
+1 -1
View File
@@ -1,5 +1,5 @@
export { default as ReactFlow } from './container/ReactFlow'; export { default as ReactFlow } from './container/ReactFlow';
export { Handle, type HandleComponentProps } from './components/Handle'; export { Handle, type HandleProps } from './components/Handle';
export { EdgeText } from './components/Edges/EdgeText'; export { EdgeText } from './components/Edges/EdgeText';
export { StraightEdge } from './components/Edges/StraightEdge'; export { StraightEdge } from './components/Edges/StraightEdge';
export { StepEdge } from './components/Edges/StepEdge'; export { StepEdge } from './components/Edges/StepEdge';
@@ -13,9 +13,9 @@
} from '@xyflow/system'; } from '@xyflow/system';
import { useStore } from '$lib/store'; import { useStore } from '$lib/store';
import type { HandleComponentProps } from '$lib/types'; import type { HandleProps } from '$lib/types';
type $$Props = HandleComponentProps; type $$Props = HandleProps;
export let id: $$Props['id'] = undefined; export let id: $$Props['id'] = undefined;
export let type: $$Props['type'] = 'source'; export let type: $$Props['type'] = 'source';
+1 -1
View File
@@ -46,7 +46,7 @@ export type {
EdgeTypes, EdgeTypes,
DefaultEdgeOptions DefaultEdgeOptions
} from '$lib/types/edges'; } from '$lib/types/edges';
export type { HandleComponentProps, FitViewOptions } from '$lib/types/general'; export type { HandleProps, FitViewOptions } from '$lib/types/general';
export type { export type {
Node, Node,
NodeTypes, NodeTypes,
+3 -27
View File
@@ -1,12 +1,11 @@
import type { ShortcutModifierDefinition } from '@svelte-put/shortcut'; import type { ShortcutModifierDefinition } from '@svelte-put/shortcut';
import type { import type {
FitViewOptionsBase, FitViewOptionsBase,
HandleType,
Position,
XYPosition, XYPosition,
ConnectingHandle, ConnectingHandle,
Connection, Connection,
OnBeforeDeleteBase OnBeforeDeleteBase,
HandleProps as HandlePropsSystem
} from '@xyflow/system'; } from '@xyflow/system';
import type { Node } from './nodes'; import type { Node } from './nodes';
@@ -23,32 +22,9 @@ export type ConnectionData = {
connectionStatus: string | null; connectionStatus: string | null;
}; };
export type HandleComponentProps = { export type HandleProps = HandlePropsSystem & {
/** Type of the handle
* @example HandleType.Source, HandleType.Target
*/
type: HandleType;
/** Position of the handle
* @example Position.TopLeft, Position.TopRight,
* Position.BottomLeft, Position.BottomRight
*/
position?: Position;
/** Id of the handle
* @remarks optional if there is only one handle of this type
*/
id?: string;
class?: string; class?: string;
style?: string; style?: string;
/** Should you be able to connect from/to this handle */
isConnectable?: boolean;
/** Shoould you be able to connect from this handle */
isConnectableStart?: boolean;
/** Should you be able to connect to this handle */
isConnectableEnd?: boolean;
/** Function that is called when checking if connection is valid.
* Overrides the isValidConnection on the Flow component.
*/
isValidConnection?: IsValidConnection;
onconnect?: (connections: Connection[]) => void; onconnect?: (connections: Connection[]) => void;
ondisconnect?: (connections: Connection[]) => void; ondisconnect?: (connections: Connection[]) => void;
}; };
+1 -3
View File
@@ -1,4 +1,4 @@
import type { Position, OnConnect, IsValidConnection } from '.'; import type { Position, IsValidConnection } from '.';
export type HandleType = 'source' | 'target'; export type HandleType = 'source' | 'target';
@@ -42,8 +42,6 @@ export type HandleProps = {
isConnectableStart?: boolean; isConnectableStart?: boolean;
/** Should you be able to connect to this handle */ /** Should you be able to connect to this handle */
isConnectableEnd?: boolean; isConnectableEnd?: boolean;
/** Callback called when connection is made */
onConnect?: OnConnect;
/** Callback if connection is valid /** Callback if connection is valid
* @remarks connection becomes an edge if isValidConnection returns true * @remarks connection becomes an edge if isValidConnection returns true
*/ */