refactor(handle): naming things, cleanup

This commit is contained in:
moklick
2023-01-19 15:52:39 +01:00
parent 5af609696b
commit 66b3a8e334
6 changed files with 225 additions and 205 deletions
+10 -5
View File
@@ -4,11 +4,12 @@ import { shallow } from 'zustand/shallow';
import { useStore, useStoreApi } from '../../hooks/useStore';
import { useNodeId } from '../../contexts/NodeIdContext';
import { handleMouseDown, isHandleValid } from './handler';
import { getHostForElement } from '../../utils';
import { handleMouseDown } from './handler';
import { devWarn, getHostForElement } from '../../utils';
import { addEdge } from '../../utils/graph';
import { Position } from '../../types';
import type { HandleProps, Connection, ReactFlowState } from '../../types';
import { isValidHandle } from './utils';
const alwaysValid = () => true;
@@ -37,9 +38,13 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
ref
) => {
const store = useStoreApi();
const nodeId = useNodeId();
if (!nodeId) {
devWarn('Handle: No node id found. Make sure to only use a Handle inside a custom Node.');
return null;
}
// @fixme: remove type assertion and handle nodeId === null
const nodeId = useNodeId() as string;
const { connectionStartHandle, connectOnClick, noPanClassName } = useStore(selector, shallow);
const handleId = id || null;
@@ -86,7 +91,7 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
}
const doc = getHostForElement(event.target as HTMLElement);
const { connection, isValid } = isHandleValid(
const { connection, isValid } = isValidHandle(
{
nodeId,
id: handleId,