chore(ts): add annotations for useReactFlow/ useSvelteFlow
This commit is contained in:
@@ -10,18 +10,24 @@ const selector = (s: ReactFlowStore) => ({
|
||||
position: s.connectionStartHandle ? s.connectionPosition : null,
|
||||
});
|
||||
|
||||
type UseConnectionResult = {
|
||||
/** The start handle where the user interaction started or null */
|
||||
startHandle: ReactFlowStore['connectionStartHandle'];
|
||||
/** The target handle that's inside the connection radius or null */
|
||||
endHandle: ReactFlowStore['connectionEndHandle'];
|
||||
/** The current connection status 'valid', 'invalid' or null*/
|
||||
status: ReactFlowStore['connectionStatus'];
|
||||
/** The current connection position or null */
|
||||
position: ReactFlowStore['connectionPosition'] | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Hook for accessing the ongoing connection.
|
||||
*
|
||||
* @public
|
||||
* @returns ongoing connection: startHandle, endHandle, status, position
|
||||
* @returns ongoing connection
|
||||
*/
|
||||
export function useConnection(): {
|
||||
startHandle: ReactFlowStore['connectionStartHandle'];
|
||||
endHandle: ReactFlowStore['connectionEndHandle'];
|
||||
status: ReactFlowStore['connectionStatus'];
|
||||
position: ReactFlowStore['connectionPosition'] | null;
|
||||
} {
|
||||
export function useConnection(): UseConnectionResult {
|
||||
const ongoingConnection = useStore(selector, shallow);
|
||||
|
||||
return ongoingConnection;
|
||||
|
||||
@@ -13,7 +13,7 @@ type useHandleConnectionsParams = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Hook to check if a <Handle /> is connected to another <Handle /> and get the connections.
|
||||
* Hook to check if a <Handle /> is connected to another <Handle /> and get the connections.
|
||||
*
|
||||
* @public
|
||||
* @param param.type - handle type 'source' or 'target'
|
||||
|
||||
@@ -11,7 +11,7 @@ export type UseOnSelectionChangeOptions = {
|
||||
* Hook for registering an onSelectionChange handler.
|
||||
*
|
||||
* @public
|
||||
* @params params.onChange - The handler to register
|
||||
* @param params.onChange - The handler to register
|
||||
*/
|
||||
export function useOnSelectionChange({ onChange }: UseOnSelectionChangeOptions) {
|
||||
const store = useStoreApi();
|
||||
|
||||
@@ -86,31 +86,31 @@ const useViewportHelper = (): ViewportHelperFunctions => {
|
||||
|
||||
panZoom?.setViewport(viewport, { duration: options?.duration });
|
||||
},
|
||||
screenToFlowPosition: (position: XYPosition, options: { snapToGrid: boolean } = { snapToGrid: true }) => {
|
||||
screenToFlowPosition: (clientPosition: XYPosition, options: { snapToGrid: boolean } = { snapToGrid: true }) => {
|
||||
const { transform, snapGrid, domNode } = store.getState();
|
||||
|
||||
if (!domNode) {
|
||||
return position;
|
||||
return clientPosition;
|
||||
}
|
||||
|
||||
const { x: domX, y: domY } = domNode.getBoundingClientRect();
|
||||
|
||||
const correctedPosition = {
|
||||
x: position.x - domX,
|
||||
y: position.y - domY,
|
||||
x: clientPosition.x - domX,
|
||||
y: clientPosition.y - domY,
|
||||
};
|
||||
|
||||
return pointToRendererPoint(correctedPosition, transform, options.snapToGrid, snapGrid);
|
||||
},
|
||||
flowToScreenPosition: (position: XYPosition) => {
|
||||
flowToScreenPosition: (flowPosition: XYPosition) => {
|
||||
const { transform, domNode } = store.getState();
|
||||
|
||||
if (!domNode) {
|
||||
return position;
|
||||
return flowPosition;
|
||||
}
|
||||
|
||||
const { x: domX, y: domY } = domNode.getBoundingClientRect();
|
||||
const rendererPosition = rendererPointToPoint(position, transform);
|
||||
const rendererPosition = rendererPointToPoint(flowPosition, transform);
|
||||
|
||||
return {
|
||||
x: rendererPosition.x + domX,
|
||||
|
||||
Reference in New Issue
Block a user