UNPKG

8.62 kBTypeScriptView Raw
1import type { Identifier, Unsubscribe } from 'dnd-core';
2export interface XYCoord {
3 x: number;
4 y: number;
5}
6export interface HandlerManager {
7 receiveHandlerId: (handlerId: Identifier | null) => void;
8 getHandlerId: () => Identifier | null;
9}
10export interface DragSourceMonitor<DragObject = unknown, DropResult = unknown> extends HandlerManager, MonitorEventEmitter {
11 /**
12 * Returns true if no drag operation is in progress, and the owner's canDrag() returns true or is not defined.
13 */
14 canDrag(): boolean;
15 /**
16 * Returns true if a drag operation is in progress, and either the owner initiated the drag, or its isDragging() is defined and returns true.
17 */
18 isDragging(): boolean;
19 /**
20 * Returns a string or a symbol identifying the type of the current dragged item. Returns null if no item is being dragged.
21 */
22 getItemType(): Identifier | null;
23 /**
24 * Returns a plain object representing the currently dragged item. Every drag source must specify it by returning an object from its beginDrag() method.
25 * Returns null if no item is being dragged.
26 */
27 getItem<T = DragObject>(): T;
28 /**
29 * Returns a plain object representing the last recorded drop result. The drop targets may optionally specify it by returning an object from their
30 * drop() methods. When a chain of drop() is dispatched for the nested targets, bottom up, any parent that explicitly returns its own result from drop()
31 * overrides the child drop result previously set by the child. Returns null if called outside endDrag().
32 */
33 getDropResult<T = DropResult>(): T | null;
34 /**
35 * Returns true if some drop target has handled the drop event, false otherwise. Even if a target did not return a drop result, didDrop() returns true.
36 * Use it inside endDrag() to test whether any drop target has handled the drop. Returns false if called outside endDrag().
37 */
38 didDrop(): boolean;
39 /**
40 * Returns the { x, y } client offset of the pointer at the time when the current drag operation has started. Returns null if no item is being dragged.
41 */
42 getInitialClientOffset(): XYCoord | null;
43 /**
44 * Returns the { x, y } client offset of the drag source component's root DOM node at the time when the current drag operation has started.
45 * Returns null if no item is being dragged.
46 */
47 getInitialSourceClientOffset(): XYCoord | null;
48 /**
49 * Returns the last recorded { x, y } client offset of the pointer while a drag operation is in progress. Returns null if no item is being dragged.
50 */
51 getClientOffset(): XYCoord | null;
52 /**
53 * Returns the { x, y } difference between the last recorded client offset of the pointer and the client offset when the current drag operation has started.
54 * Returns null if no item is being dragged.
55 */
56 getDifferenceFromInitialOffset(): XYCoord | null;
57 /**
58 * Returns the projected { x, y } client offset of the drag source component's root DOM node, based on its position at the time when the current drag operation has
59 * started, and the movement difference. Returns null if no item is being dragged.
60 */
61 getSourceClientOffset(): XYCoord | null;
62 /**
63 * Returns the ids of the potential drop targets.
64 */
65 getTargetIds(): Identifier[];
66}
67export interface MonitorEventEmitter {
68 subscribeToStateChange(fn: () => void, options?: {
69 handlerIds?: Identifier[];
70 }): Unsubscribe;
71}
72export interface DropTargetMonitor<DragObject = unknown, DropResult = unknown> extends HandlerManager, MonitorEventEmitter {
73 /**
74 * Returns true if there is a drag operation in progress, and the owner's canDrop() returns true or is not defined.
75 */
76 canDrop(): boolean;
77 /**
78 * Returns true if there is a drag operation in progress, and the pointer is currently hovering over the owner.
79 * You may optionally pass { shallow: true } to strictly check whether only the owner is being hovered, as opposed
80 * to a nested target.
81 */
82 isOver(options?: {
83 shallow?: boolean;
84 }): boolean;
85 /**
86 * Returns a string or a symbol identifying the type of the current dragged item. Returns null if no item is being dragged.
87 */
88 getItemType(): Identifier | null;
89 /**
90 * Returns a plain object representing the currently dragged item. Every drag source must specify it by returning an object from
91 * its beginDrag() method. Returns null if no item is being dragged.
92 */
93 getItem<T = DragObject>(): T;
94 /**
95 * Returns a plain object representing the last recorded drop result. The drop targets may optionally specify it by returning an
96 * object from their drop() methods. When a chain of drop() is dispatched for the nested targets, bottom up, any parent that explicitly
97 * returns its own result from drop() overrides the drop result previously set by the child. Returns null if called outside drop().
98 */
99 getDropResult<T = DropResult>(): T | null;
100 /**
101 * Returns true if some drop target has handled the drop event, false otherwise. Even if a target did not return a drop result,
102 * didDrop() returns true. Use it inside drop() to test whether any nested drop target has already handled the drop. Returns false
103 * if called outside drop().
104 */
105 didDrop(): boolean;
106 /**
107 * Returns the { x, y } client offset of the pointer at the time when the current drag operation has started. Returns null if no item
108 * is being dragged.
109 */
110 getInitialClientOffset(): XYCoord | null;
111 /**
112 * Returns the { x, y } client offset of the drag source component's root DOM node at the time when the current drag operation has started.
113 * Returns null if no item is being dragged.
114 */
115 getInitialSourceClientOffset(): XYCoord | null;
116 /**
117 * Returns the last recorded { x, y } client offset of the pointer while a drag operation is in progress. Returns null if no item is being dragged.
118 */
119 getClientOffset(): XYCoord | null;
120 /**
121 * Returns the { x, y } difference between the last recorded client offset of the pointer and the client offset when current the drag operation has
122 * started. Returns null if no item is being dragged.
123 */
124 getDifferenceFromInitialOffset(): XYCoord | null;
125 /**
126 * Returns the projected { x, y } client offset of the drag source component's root DOM node, based on its position at the time when the current
127 * drag operation has started, and the movement difference. Returns null if no item is being dragged.
128 */
129 getSourceClientOffset(): XYCoord | null;
130}
131export interface DragLayerMonitor<DragObject = unknown> {
132 /**
133 * Returns true if a drag operation is in progress. Returns false otherwise.
134 */
135 isDragging(): boolean;
136 /**
137 * Returns a string or a symbol identifying the type of the current dragged item.
138 * Returns null if no item is being dragged.
139 */
140 getItemType(): Identifier | null;
141 /**
142 * Returns a plain object representing the currently dragged item.
143 * Every drag source must specify it by returning an object from its beginDrag() method.
144 * Returns null if no item is being dragged.
145 */
146 getItem<T = DragObject>(): T;
147 /**
148 * Returns the { x, y } client offset of the pointer at the time when the current drag operation has started.
149 * Returns null if no item is being dragged.
150 */
151 getInitialClientOffset(): XYCoord | null;
152 /**
153 * Returns the { x, y } client offset of the drag source component's root DOM node at the time when the current
154 * drag operation has started. Returns null if no item is being dragged.
155 */
156 getInitialSourceClientOffset(): XYCoord | null;
157 /**
158 * Returns the last recorded { x, y } client offset of the pointer while a drag operation is in progress.
159 * Returns null if no item is being dragged.
160 */
161 getClientOffset(): XYCoord | null;
162 /**
163 * Returns the { x, y } difference between the last recorded client offset of the pointer and the client
164 * offset when current the drag operation has started. Returns null if no item is being dragged.
165 */
166 getDifferenceFromInitialOffset(): XYCoord | null;
167 /**
168 * Returns the projected { x, y } client offset of the drag source component's root DOM node, based on its
169 * position at the time when the current drag operation has started, and the movement difference.
170 * Returns null if no item is being dragged.
171 */
172 getSourceClientOffset(): XYCoord | null;
173}