import { ActionUnion, BoundActionCreators } from '../../../../utils/typedActions'; import { Position, Viewport, GridSettings } from '../../../../types/core'; import { createCanvasUtils } from './utils/coordinateConversion'; import { NodeCanvasStore } from './store'; /** * @file Context for managing canvas viewport, panning, zooming, and grid settings */ import * as React from "react"; export type PanState = { isPanning: boolean; startPosition: Position | null; }; export type CanvasViewBox = { width: number; height: number; }; export type NodeCanvasState = { viewport: Viewport; gridSettings: GridSettings; isSpacePanning: boolean; panState: PanState; /** * Canvas container dimensions in CSS pixels. * Used as the viewbox for viewport-dependent calculations (visibility, minimap, etc). */ viewBox: CanvasViewBox; }; export declare const nodeCanvasActions: { readonly setViewport: ((viewport: Viewport) => { type: "SET_VIEWPORT"; payload: { viewport: Viewport; }; }) & { readonly type: "SET_VIEWPORT"; }; readonly panViewport: ((delta: Position) => { type: "PAN_VIEWPORT"; payload: { delta: Position; }; }) & { readonly type: "PAN_VIEWPORT"; }; readonly zoomViewport: ((scale: number, center?: Position | undefined) => { type: "ZOOM_VIEWPORT"; payload: { scale: number; center: Position | undefined; }; }) & { readonly type: "ZOOM_VIEWPORT"; }; readonly resetViewport: (() => { type: "RESET_VIEWPORT"; }) & { readonly type: "RESET_VIEWPORT"; }; readonly updateGridSettings: ((settings: Partial) => { type: "UPDATE_GRID_SETTINGS"; payload: { settings: Partial; }; }) & { readonly type: "UPDATE_GRID_SETTINGS"; }; readonly setSpacePanning: ((isSpacePanning: boolean) => { type: "SET_SPACE_PANNING"; payload: { isSpacePanning: boolean; }; }) & { readonly type: "SET_SPACE_PANNING"; }; readonly startPan: ((position: Position) => { type: "START_PAN"; payload: { position: Position; }; }) & { readonly type: "START_PAN"; }; readonly updatePan: ((position: Position) => { type: "UPDATE_PAN"; payload: { position: Position; }; }) & { readonly type: "UPDATE_PAN"; }; readonly endPan: (() => { type: "END_PAN"; }) & { readonly type: "END_PAN"; }; readonly setViewBox: ((viewBox: CanvasViewBox) => { type: "SET_VIEWBOX"; payload: { viewBox: CanvasViewBox; }; }) & { readonly type: "SET_VIEWBOX"; }; }; export type NodeCanvasAction = ActionUnion; export type NodeCanvasActionsValue = { dispatch: (action: NodeCanvasAction) => void; actions: BoundActionCreators; actionCreators: typeof nodeCanvasActions; canvasRef: React.RefObject; containerRef: React.RefObject; setContainerElement: (element: HTMLDivElement | null) => void; }; export type NodeCanvasUtils = ReturnType; export type NodeCanvasApiValue = NodeCanvasActionsValue & { store: NodeCanvasStore; utils: NodeCanvasUtils; }; export type NodeCanvasContextValue = NodeCanvasActionsValue & { state: NodeCanvasState; utils: NodeCanvasUtils; }; export declare const NodeCanvasContext: React.Context; /** * Hook to access only the canvas state * Use this when you only need to read state and don't need actions */ export declare const useNodeCanvasState: () => NodeCanvasState; export declare const useNodeCanvasViewportOffset: () => Position; export declare const useNodeCanvasViewportScale: () => number; export declare const useNodeCanvasPanActive: () => boolean; export declare const useNodeCanvasGridSettings: () => GridSettings; /** * Hook to access only the canvas actions * Use this when you only need to dispatch actions and don't need to re-render on state changes * The returned actions have stable references and won't cause re-renders */ export declare const useNodeCanvasActions: () => NodeCanvasActionsValue; export declare const useNodeCanvasUtils: () => NodeCanvasUtils; /** * Hook to access both state and actions (backward compatible) * Prefer useNodeCanvasState or useNodeCanvasActions for better performance */ export declare const useNodeCanvas: () => NodeCanvasContextValue; export declare const useNodeCanvasApi: () => NodeCanvasApiValue;