forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-dnd.d.ts
180 lines (145 loc) · 6.27 KB
/
react-dnd.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Type definitions for React DnD v2.0.2
// Project: https://github.com/gaearon/react-dnd
// Definitions by: Asana <https://asana.com>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///<reference path='../react/react.d.ts' />
declare module __ReactDnd {
import React = __React;
// Decorated React Components
// ----------------------------------------------------------------------
class ContextComponent<P, S> extends React.Component<P, S> {
getDecoratedComponentInstance(): React.Component<P, S>;
// Note: getManager is not yet documented on the React DnD docs.
getManager(): any;
}
class DndComponent<P, S> extends React.Component<P, S> {
getDecoratedComponentInstance(): React.Component<P, S>;
getHandlerId(): Identifier;
}
interface ContextComponentClass<P> extends React.ComponentClass<P> {
new(props?: P, context?: any): ContextComponent<P, any>;
DecoratedComponent: React.ComponentClass<P>;
}
interface DndComponentClass<P> extends React.ComponentClass<P> {
new(props?: P, context?: any): DndComponent<P, any>;
DecoratedComponent: React.ComponentClass<P>;
}
// Top-level API
// ----------------------------------------------------------------------
export function DragSource<P>(
type: Identifier | ((props: P) => Identifier),
spec: DragSourceSpec<P>,
collect: DragSourceCollector,
options?: DndOptions<P>
): (componentClass: React.ComponentClass<P> | React.StatelessComponent<P>) => DndComponentClass<P>;
export function DropTarget<P>(
types: Identifier | Identifier[] | ((props: P) => Identifier | Identifier[]),
spec: DropTargetSpec<P>,
collect: DropTargetCollector,
options?: DndOptions<P>
): (componentClass: React.ComponentClass<P> | React.StatelessComponent<P>) => DndComponentClass<P>;
export function DragDropContext<P>(
backend: Backend
): <P>(componentClass: React.ComponentClass<P> | React.StatelessComponent<P>) => ContextComponentClass<P>;
export function DragLayer<P>(
collect: DragLayerCollector,
options?: DndOptions<P>
): (componentClass: React.ComponentClass<P> | React.StatelessComponent<P>) => DndComponentClass<P>;
type DragSourceCollector = (connect: DragSourceConnector, monitor: DragSourceMonitor) => Object;
type DropTargetCollector = (connect: DropTargetConnector, monitor: DropTargetMonitor) => Object;
type DragLayerCollector = (monitor: DragLayerMonitor) => Object;
// Shared
// ----------------------------------------------------------------------
// The React DnD docs say that this can also be the ES6 Symbol.
type Identifier = string;
interface ClientOffset {
x: number;
y: number;
}
interface DndOptions<P> {
arePropsEqual?(props: P, otherProps: P): boolean;
}
// DragSource
// ----------------------------------------------------------------------
interface DragSourceSpec<P> {
beginDrag(props: P, monitor?: DragSourceMonitor, component?: React.Component<P, any>): Object;
endDrag?(props: P, monitor?: DragSourceMonitor, component?: React.Component<P, any>): void;
canDrag?(props: P, monitor?: DragSourceMonitor): boolean;
isDragging?(props: P, monitor?: DragSourceMonitor): boolean;
}
class DragSourceMonitor {
canDrag(): boolean;
isDragging(): boolean;
getItemType(): Identifier;
getItem(): Object;
getDropResult(): Object;
didDrop(): boolean;
getInitialClientOffset(): ClientOffset;
getInitialSourceClientOffset(): ClientOffset;
getClientOffset(): ClientOffset;
getDifferenceFromInitialOffset(): ClientOffset;
getSourceClientOffset(): ClientOffset;
}
class DragSourceConnector {
dragSource(): ConnectDragSource;
dragPreview(): ConnectDragPreview;
}
interface DragElementWrapper<O> {
<P>(elementOrNode: React.ReactElement<P>, options?: O): React.ReactElement<P>;
}
interface DragSourceOptions {
dropEffect?: string;
}
interface DragPreviewOptions {
captureDraggingState?: boolean;
anchorX?: number;
anchorY?: number;
}
type ConnectDragSource = DragElementWrapper<DragSourceOptions>;
type ConnectDragPreview = DragElementWrapper<DragPreviewOptions>;
/// DropTarget
// ----------------------------------------------------------------------
interface DropTargetSpec<P> {
drop?(props: P, monitor?: DropTargetMonitor, component?: React.Component<P, any>): Object|void;
hover?(props: P, monitor?: DropTargetMonitor, component?: React.Component<P, any>): void;
canDrop?(props: P, monitor?: DropTargetMonitor): boolean;
}
class DropTargetMonitor {
canDrop(): boolean;
isOver(options?: { shallow: boolean }): boolean;
getItemType(): Identifier;
getItem(): Object;
getDropResult(): Object;
didDrop(): boolean;
getInitialClientOffset(): ClientOffset;
getInitialSourceClientOffset(): ClientOffset;
getClientOffset(): ClientOffset;
getDifferenceFromInitialOffset(): ClientOffset;
getSourceClientOffset(): ClientOffset;
}
class DropTargetConnector {
dropTarget(): ConnectDropTarget;
}
type ConnectDropTarget = <P>(elementOrNode: React.ReactElement<P>) => React.ReactElement<P>;
/// DragLayerMonitor
// ----------------------------------------------------------------------
class DragLayerMonitor {
isDragging(): boolean;
getItemType(): Identifier;
getItem(): Object;
getInitialClientOffset(): ClientOffset;
getInitialSourceClientOffset(): ClientOffset;
getClientOffset(): ClientOffset;
getDifferenceFromInitialOffset(): ClientOffset;
getSourceClientOffset(): ClientOffset;
}
/// Backend
/// ---------------------------------------------------------------------
// TODO: Fill in the Backend interface.
// The React DnD docs do not cover this, and this is only needed for
// creating custom backends (i.e. not using the built-in HTML5Backend).
interface Backend {}
}
declare module "react-dnd" {
export = __ReactDnd;
}