/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The Schematic canvas's gestures (#57, #153, #159, #176, #179, #189, #353): * the pointer handlers over the camera's mode machine — a pan, a pinch, the * zoom box and the marquee, Move and its preview (invariant 4), Connect and its * Shift session (invariant 11), Retarget and Extend, each held to the host's * veto (invariant 6), and the taps, each hit-testing what the painter draws * (invariant 9); the canvas's keys, and the frame's and the page's while the * pointer is over it (invariant 16), each it acts on going no further than the * Schematic (#1398); and the link or the net lit under the pointer (#1403, * invariant 12). Every gesture that writes is one step of the editing's * history (`../edits.ts`, #1388). * * Which pointer a gesture is, the fingers the canvas holds and each way a * gesture ends are not this hook's: the canvas is a surface of the shared * pointer core (east-ui-components' `src/pointer/`, `useSurfaceGestures`), * which holds every surface's gestures to one rule (invariants 33, 34). A * finger is gone as it lifts, as the browser takes it back and as the canvas * loses its capture, and one whose end is never heard is let go of as the next * first finger lands or the window loses the page — so no finger is remembered * into a pinch that never ends. One gesture is in flight at a time, its * pointer's: another pointer's moves and release are not its, and a second * finger, a new press, a lost pointer and the window losing the page each let * go of it. What the hook holds is what the canvas's gestures do: what a press * begins under the tool in force, what its drag draws, what its release * records, and what letting go puts back, recording nothing (`drop`). Two * fingers pinch: the drawing zooms by how far apart they are drawn and is * carried with them, each finger staying on the point of the drawing it * touched (`camera.ts`' `pinchAbout`). * * The commit-phase snapshot reads the gestures' state (`use-paint.ts`, * invariant 1), and the handlers read the snapshot: {@link useGestureState} * holds the state — the tool in force, a Move's preview, Connect's draft and * its flash, the box in flight and the link lit — and is made before the * snapshot; {@link useGestures} holds the handlers, and is made after it. * * @packageDocumentation */ import { type RefObject } from "react"; import type RBush from "rbush"; import { type option } from "@elaraai/east"; import type { SchematicValue } from "../data.js"; import { type NetLeg } from "../edits.js"; import type { SchematicWords } from "../messages.js"; import type { SchematicTool } from "../tools.js"; import { type DrawnItem, type DrawnLink, type DrawnNet, type DrawnZone, type SchematicDrawn, type SchematicRef } from "./drawn"; import type { SchematicLayerState } from "./layers"; import type { LodTier } from "./model"; import { type ItemBox, type LinkIndex } from "./selection"; import type { Camera, CameraMoves } from "./use-camera"; import type { CanvasSelection, SchematicStanding, SelectionSteps } from "./use-canvas-selection"; import { type Paint } from "./use-paint"; import type { SchematicCanvasEditing } from "./view"; type Pt = { x: number; y: number; }; /** What {@link useGestureState} reads. */ export interface GestureStateProps { /** The payload, decoded: its kinds, which write and which draw only (`../edits.ts`' `editKinds`). */ readonly value: SchematicValue; /** The tool held, the frame's. */ readonly tool: SchematicTool; /** Whether main is below 480px (#1394, D15): a selected link draws no handle, and takes no re-target's drag. */ readonly narrow: boolean; /** Whether what the canvas draws is retained (#1398, CL8): no gesture edits it. */ readonly retained: boolean; /** Each entity's reference by its id on the canvas. */ readonly refById: ReadonlyMap; /** The link or the net selected, and a net's leg (`use-canvas-selection.ts`). */ readonly selectedLink: CanvasSelection["selectedLink"]; /** The items selected (`use-canvas-selection.ts`): what a Shift marquee unions into. */ readonly selected: ReadonlySet; } /** * The gestures' state (see the module docs). * * @param props - The payload, the tool held, the layout and what stands in, each entity's reference, and what is * selected * @returns The kinds as the edits read them, the link lit, whether the selected link writes, a Move's preview — each * item its drag moves, where it has it — the tool in force, Connect's draft and its flash, and the box in flight and * its preview */ export declare function useGestureState({ value, tool, narrow, retained, refById, selectedLink, selected }: GestureStateProps): { kinds: import("../edits.js").EditKinds; movableKinds: ReadonlySet; lit: string | undefined; setLit: import("react").Dispatch>; selectedLinkEditable: boolean; dragMoves: ReadonlyMap; setDragMoves: import("react").Dispatch>>; setTempTool: import("react").Dispatch>; effectiveTool: "connect" | "marquee" | "move" | "select" | "zoom"; isBoxTool: boolean; connectDraft: { from: string; toWorld: Pt; target: string | undefined; retarget?: string; forbidden?: string; reason?: string | undefined; } | null; setConnectDraft: import("react").Dispatch>; connectFlashRef: RefObject<{ from: string; to: string; t0: number; } | null>; flashRafRef: RefObject; setBoxDrag: import("react").Dispatch; } | null>>; selRect: { x: number; y: number; w: number; h: number; } | null; marqueeCount: number; marqueePreview: ReadonlySet | null; }; /** The gestures' state: {@link useGestureState}'s. */ export type GestureState = ReturnType; /** What {@link useGestures} reads. */ export interface GesturesProps { /** The payload, decoded: its kinds' veto, `canConnect`. */ readonly value: SchematicValue; /** What the canvas draws: its reader's stored rows, the editing session's drafts in place (#1388). */ readonly data: SchematicDrawn; /** What the layers hide, lock and dim. */ readonly layers: SchematicLayerState; /** The tool held, the frame's. */ readonly tool: SchematicTool; /** The link kind Connect draws; `undefined` where no link kind is editable. */ readonly linkKind: string | undefined; /** The Schematic's words. */ readonly words: SchematicWords; /** How the canvas records its gestures; `undefined` where no record is edited. */ readonly editing: SchematicCanvasEditing | undefined; /** Told why a gesture was refused, or — `undefined` — that one has been recorded since. */ readonly onRefused: (words: string | undefined) => void; /** Told when Enter, or a double-click on an entity, opens the selection in the inspector's Details; `undefined` with no inspector. */ readonly onOpen: (() => void) | undefined; /** What a Connect's new link or net takes its other fields from, by its kind's slot (§4.3, #1390). */ readonly connectValues: (slot: string) => option; /** The drawing's extent's width, in world units: what a Move is held inside. */ readonly W: number; /** The drawing's extent's height, in world units. */ readonly H: number; /** The canvas's element: what a key the frame or the window hears is the canvas's by. */ readonly canvasRef: RefObject; /** Each entity's reference by its id on the canvas. */ readonly refById: ReadonlyMap; /** Each item's label by its id: what a refusal's words name it by. */ readonly labelById: ReadonlyMap; /** What never selects, by any path: a locked layer's entities, and what the narrowing takes out (SC27, #1392). */ readonly inertKeys: ReadonlySet; /** What the narrowing takes out of every list and of the selection, its context among it (#1392). */ readonly narrowedOut: ReadonlySet; /** The zones drawn, a hidden layer's left out: what a tap selects a zone among. */ readonly shownZones: readonly DrawnZone[]; /** What is selected that the drawing doesn't draw and still stands: Del deletes its items with the rest (#1393). */ readonly standing: SchematicStanding; /** The items in view: what a tap finds an item among. */ readonly visibleItems: readonly DrawnItem[]; /** What each item in view draws as at the zoom. */ readonly tiers: ReadonlyMap; /** The tier the zoom's band draws its items at. */ readonly lod: LodTier; /** The items drawn, by their boxes: what the marquee sweeps. */ readonly index: RBush; /** Each item drawn, by its id: what a link's end is worked out over (#1403). */ readonly itemById: ReadonlyMap; /** The links' lanes, as the painter fans them (#180). */ readonly lanes: ReadonlyMap; /** The links' R-tree: what a hover, a tap and a drop search for the link or the net under a point (#1403). */ readonly linkTree: LinkIndex; /** Each link drawn, by its id. */ readonly linkById: ReadonlyMap; /** Each net drawn, by its id. */ readonly netById: ReadonlyMap; /** Whether a library card is dragged: nothing lights under the pointer meanwhile. */ readonly dragging: boolean; /** What is selected, and its funnels (`use-canvas-selection.ts`). */ readonly canvasSelection: CanvasSelection; /** The zones' clear and the steps (`use-canvas-selection.ts`). */ readonly selectionSteps: SelectionSteps; /** The camera (`use-camera.ts`). */ readonly camera: Camera; /** What moves the camera (`use-camera.ts`). */ readonly cameraMoves: CameraMoves; /** The commit-phase snapshot and the painter's apply (`use-paint.ts`). */ readonly paint: Paint; /** The gestures' state ({@link useGestureState}'s). */ readonly gestureState: GestureState; } /** * The gestures' handlers (see the module docs). * * @param props - The payload and what the canvas draws, the tool and how the canvas records and tells, the drawing's * extent and what the hit-tests search, what is selected and its funnels, the camera and what moves it, the snapshot, * and the gestures' state * @returns Whether the pointer is over the canvas, the canvas's keys, the hit-tests of an item, a zone and a link or a * net under a point, the pointer handlers the canvas's element carries (`surface`), and the double-click's */ export declare function useGestures({ value, data, layers, tool, linkKind, words, editing, onRefused, onOpen, connectValues, W, H, canvasRef, refById, labelById, inertKeys, narrowedOut, shownZones, standing, visibleItems, tiers, lod, index, itemById, lanes, linkTree, linkById, netById, dragging, canvasSelection, selectionSteps, camera, cameraMoves, paint, gestureState, }: GesturesProps): { hoveredRef: RefObject; onCanvasKeyDown: (e: React.KeyboardEvent) => void; onFrameKeyDown: (e: React.KeyboardEvent) => void; itemKeyAt: (host: HTMLElement, clientX: number, clientY: number, accept?: (id: string) => boolean) => string | undefined; zoneKeyAt: (host: HTMLElement, clientX: number, clientY: number, accept?: (id: string) => boolean) => string | undefined; linkKeyAt: (host: HTMLElement, clientX: number, clientY: number, accept?: (id: string) => boolean) => { key: string; leg: NetLeg | null; } | undefined; surface: import("@elaraai/east-ui-components/internal").SurfaceGestures; onCanvasDoubleClick: (e: React.MouseEvent) => void; }; /** The gestures' handlers: {@link useGestures}'. */ export type Gestures = ReturnType; export {}; //# sourceMappingURL=use-gestures.d.ts.map