mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-11 08:00:21 +00:00
Add CanvasPointer API (#308)
* Add position rounding feature Replaces previous impls. which only worked on some items, and were triggered when unexpected e.g. clicking a node that hadn't been moved. Update test expectations * Narrow TS types - readonly * nit - Clean up, Doc * nit - Clean up legacy accessors Marks as deprecated * Fix TS type - IContextMenuOptions.scale * [Refactor] dist2 for use in pointer API * Add CanvasPointer - API for pointer events Add TS strict types Add final click drag distance math Add option to retain events * nit - Rename * nit * Remove Subgraph - unused & not maintained * Remove live_mode Unused, not maintained. * Update README Remove live_mode reference * Update delete selected - include reroutes & groups * Bypass link menu if alt/shift pressed * Remove old dragged_node interface Incomplete impl. - unused. Superceded by selectedItems * Fix top/left edge of rectangles not in hitbox * [Refactor] Match function names to interface names * Add interface to find widgets by Point LGraphNode.getWidgetOnPos * Add widget search param - includeDisabled * nit - Doc * Rewrite canvas mouse handling - Rewrites most pointer handling to use CanvasPointer callbacks - All callbacks are declared ahead of time during the initial pointerdown event, logically grouped together - Drastically simplifies the alteration or creation of new click / drag interactions - Click events are all clicks, rather than some processed on mouse down, others on mouse up - Functions return instead of setting and repeatedly checking multiple state vars - Removes all lines that needed THIRTEEN tab indents * Split middle click out from processMouseDown * Use pointer API for link menus * Narrow canvas event interfaces * Fix canvas event types Replaces original workarounds with final types * Refactor - deprecated isInsideRectangle * Add canvas hovering over state - Centralises cursor set behaviour - Provides simple downstream override * nit * [Refactor] Use measure functions * Add double-click API to CanvasPointer a * nit - Doc * Allow larger gap between double click events * Rewrite double-click into CanvasPointer actions * Improve double-click UX Prefer down events over up events * Add production defaults * Add middle-click handling * Remove debug code * Remove redundant code * Fix add reroute alt-click adds two undo steps * Fix click on connected input disconnects Old behaviour was to disconnect, then recreate a new link on drop. * Add module export: CanvasPointer
This commit is contained in:
@@ -10,41 +10,32 @@ import type { LGraphGroup } from "../LGraphGroup"
|
||||
/** For Canvas*Event - adds graph space co-ordinates (property names are shipped) */
|
||||
export interface ICanvasPosition {
|
||||
/** X co-ordinate of the event, in graph space (NOT canvas space) */
|
||||
canvasX?: number
|
||||
canvasX: number
|
||||
/** Y co-ordinate of the event, in graph space (NOT canvas space) */
|
||||
canvasY?: number
|
||||
canvasY: number
|
||||
}
|
||||
|
||||
/** For Canvas*Event */
|
||||
export interface IDeltaPosition {
|
||||
deltaX?: number
|
||||
deltaY?: number
|
||||
deltaX: number
|
||||
deltaY: number
|
||||
}
|
||||
|
||||
interface LegacyMouseEvent {
|
||||
/** @deprecated Part of DragAndScale mouse API - incomplete / not maintained */
|
||||
dragging?: boolean
|
||||
click_time?: number
|
||||
}
|
||||
|
||||
/** PointerEvent with canvasX/Y and deltaX/Y properties */
|
||||
export interface CanvasPointerEvent extends PointerEvent, CanvasMouseEvent { }
|
||||
|
||||
/** MouseEvent with canvasX/Y and deltaX/Y properties */
|
||||
export interface CanvasMouseEvent extends MouseEvent, ICanvasPosition, IDeltaPosition {
|
||||
/** @deprecated Part of DragAndScale mouse API - incomplete / not maintained */
|
||||
dragging?: boolean
|
||||
click_time?: number
|
||||
dataTransfer?: unknown
|
||||
}
|
||||
|
||||
/** WheelEvent with canvasX/Y properties */
|
||||
export interface CanvasWheelEvent extends WheelEvent, ICanvasPosition {
|
||||
dragging?: boolean
|
||||
click_time?: number
|
||||
dataTransfer?: unknown
|
||||
}
|
||||
export interface CanvasMouseEvent extends MouseEvent, Readonly<ICanvasPosition>, Readonly<IDeltaPosition>, LegacyMouseEvent { }
|
||||
|
||||
/** DragEvent with canvasX/Y and deltaX/Y properties */
|
||||
export interface CanvasDragEvent extends DragEvent, ICanvasPosition, IDeltaPosition { }
|
||||
|
||||
/** TouchEvent with canvasX/Y and deltaX/Y properties */
|
||||
export interface CanvasTouchEvent extends TouchEvent, ICanvasPosition, IDeltaPosition { }
|
||||
|
||||
export type CanvasEventDetail =
|
||||
GenericEventDetail
|
||||
| DragggingCanvasEventDetail
|
||||
|
||||
@@ -16,6 +16,22 @@ export enum RenderShape {
|
||||
HollowCircle = 7,
|
||||
}
|
||||
|
||||
/** Bit flags used to indicate what the pointer is currently hovering over. */
|
||||
export enum CanvasItem {
|
||||
/** No items / none */
|
||||
Nothing = 0,
|
||||
/** At least one node */
|
||||
Node = 1 << 0,
|
||||
/** At least one group */
|
||||
Group = 1 << 1,
|
||||
/** A reroute (not its path) */
|
||||
Reroute = 1 << 2,
|
||||
/** The path of a link */
|
||||
Link = 1 << 3,
|
||||
/** A resize in the bottom-right corner */
|
||||
ResizeSe = 1 << 4,
|
||||
}
|
||||
|
||||
/** The direction that a link point will flow towards - e.g. horizontal outputs are right by default */
|
||||
export enum LinkDirection {
|
||||
NONE = 0,
|
||||
|
||||
Reference in New Issue
Block a user