Line data Source code
1 : import type { SlotLayout } from '@comfyorg/graph-model/layout'
2 : import type { NodeId } from '@comfyorg/graph-model/nodeId'
3 : import type { SlotId } from '@comfyorg/graph-model/slotId'
4 :
5 : /**
6 : * Slot link drag context
7 : *
8 : * Non-reactive, per-drag ephemeral caches and RAF batching used during
9 : * link drag interactions. Keeps high-churn data out of the reactive UI state.
10 : */
11 :
12 : interface PendingPointerMoveData {
13 : clientX: number
14 : clientY: number
15 : target: EventTarget | null
16 : }
17 :
18 : export interface SlotLinkDragContext {
19 : preferredSlotForNode: Map<
20 : NodeId,
21 : { index: number; key: SlotId; layout: SlotLayout } | null
22 : >
23 : lastHoverSlotKey: string | null
24 : lastHoverNodeId: NodeId | null
25 : lastCandidateKey: string | null
26 : pendingPointerMove: PendingPointerMoveData | null
27 : lastPointerEventTarget: EventTarget | null
28 : lastPointerTargetSlotKey: string | null
29 : lastPointerTargetNodeId: NodeId | null
30 : reset: () => void
31 : dispose: () => void
32 : }
33 :
34 35695 : export function createSlotLinkDragContext(): SlotLinkDragContext {
35 35695 : const state: SlotLinkDragContext = {
36 : preferredSlotForNode: new Map(),
37 : lastHoverSlotKey: null,
38 : lastHoverNodeId: null,
39 : lastCandidateKey: null,
40 : pendingPointerMove: null,
41 : lastPointerEventTarget: null,
42 : lastPointerTargetSlotKey: null,
43 : lastPointerTargetNodeId: null,
44 : reset: () => {
45 131 : state.preferredSlotForNode = new Map()
46 131 : state.lastHoverSlotKey = null
47 131 : state.lastHoverNodeId = null
48 131 : state.lastCandidateKey = null
49 131 : state.pendingPointerMove = null
50 131 : state.lastPointerEventTarget = null
51 131 : state.lastPointerTargetSlotKey = null
52 131 : state.lastPointerTargetNodeId = null
53 : },
54 : dispose: () => {
55 65 : state.reset()
56 : }
57 : }
58 :
59 35695 : return state
60 : }
|