Blame view

天文台pc/tianwentai-ui/node_modules/dnd-core/src/interfaces.ts 6.39 KB
bc518174   王天杨   提交两个项目文件
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  export type Identifier = string | symbol
  export type SourceType = Identifier
  export type TargetType = Identifier | Identifier[]
  export type Unsubscribe = () => void
  export type Listener = () => void
  
  export interface XYCoord {
  	x: number
  	y: number
  }
  
  export enum HandlerRole {
  	SOURCE = 'SOURCE',
  	TARGET = 'TARGET',
  }
  
  export interface Backend {
  	setup(): void
  	teardown(): void
  	connectDragSource(sourceId: any, node?: any, options?: any): Unsubscribe
  	connectDragPreview(sourceId: any, node?: any, options?: any): Unsubscribe
  	connectDropTarget(targetId: any, node?: any, options?: any): Unsubscribe
  	profile(): Record<string, number>
  }
  
  export interface DragDropMonitor {
  	subscribeToStateChange(
  		listener: Listener,
  		options?: {
  			handlerIds?: Identifier[]
  		},
  	): Unsubscribe
  	subscribeToOffsetChange(listener: Listener): Unsubscribe
  	canDragSource(sourceId: Identifier | undefined): boolean
  	canDropOnTarget(targetId: Identifier | undefined): boolean
  
  	/**
  	 * Returns true if a drag operation is in progress, and either the owner initiated the drag, or its isDragging()
  	 * is defined and returns true.
  	 */
  	isDragging(): boolean
  	isDraggingSource(sourceId: Identifier | undefined): boolean
  	isOverTarget(
  		targetId: Identifier | undefined,
  		options?: {
  			shallow?: boolean
  		},
  	): boolean
  
  	/**
  	 * Returns a string or a symbol identifying the type of the current dragged item. Returns null if no item is being dragged.
  	 */
  	getItemType(): Identifier | null
  
  	/**
  	 * Returns a plain object representing the currently dragged item. Every drag source must specify it by returning an object
  	 * from its beginDrag() method. Returns null if no item is being dragged.
  	 */
  	getItem(): any
  	getSourceId(): Identifier | null
  	getTargetIds(): Identifier[]
  	/**
  	 * Returns a plain object representing the last recorded drop result. The drop targets may optionally specify it by returning an
  	 * object from their 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() overrides the child drop result previously set by the child. Returns null if
  	 * called outside endDrag().
  	 */
  	getDropResult(): any
  	/**
  	 * 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. Use it inside endDrag() to test whether any drop target has handled the drop. Returns false if called
  	 * outside endDrag().
  	 */
  	didDrop(): boolean
  	isSourcePublic(): boolean | null
  	/**
  	 * 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.
  	 */
  	getInitialClientOffset(): XYCoord | null
  	/**
  	 * 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. Returns null if no item is being dragged.
  	 */
  	getInitialSourceClientOffset(): XYCoord | null
  
  	/**
  	 * 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.
  	 */
  	getClientOffset(): XYCoord | null
  
  	/**
  	 * 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 started, and the movement difference. Returns null if no item is being dragged.
  	 */
  	getSourceClientOffset(): XYCoord | null
  
  	/**
  	 * 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. Returns null if no item is being dragged.
  	 */
  	getDifferenceFromInitialOffset(): XYCoord | null
  }
  
  export interface HandlerRegistry {
  	addSource(type: SourceType, source: DragSource): Identifier
  	addTarget(type: TargetType, target: DropTarget): Identifier
  	containsHandler(handler: DragSource | DropTarget): boolean
  	getSource(sourceId: Identifier, includePinned?: boolean): DragSource
  	getSourceType(sourceId: Identifier): SourceType
  	getTargetType(targetId: Identifier): TargetType
  	getTarget(targetId: Identifier): DropTarget
  	isSourceId(handlerId: Identifier): boolean
  	isTargetId(handlerId: Identifier): boolean
  	removeSource(sourceId: Identifier): void
  	removeTarget(targetId: Identifier): void
  	pinSource(sourceId: Identifier): void
  	unpinSource(): void
  }
  
  export interface Action<Payload> {
  	type: Identifier
  	payload: Payload
  }
  export interface SentinelAction {
  	type: Identifier
  }
  
  export type ActionCreator<Payload> = (args: any[]) => Action<Payload>
  
  export interface BeginDragOptions {
  	publishSource?: boolean
  	clientOffset?: XYCoord
  	getSourceClientOffset?: (sourceId: Identifier | undefined) => XYCoord
  }
  
  export interface InitCoordsPayload {
  	clientOffset: XYCoord | null
  	sourceClientOffset: XYCoord | null
  }
  
  export interface BeginDragPayload {
  	itemType: Identifier
  	item: any
  	sourceId: Identifier
  	clientOffset: XYCoord | null
  	sourceClientOffset: XYCoord | null
  	isSourcePublic: boolean
  }
  
  export interface HoverPayload {
  	targetIds: Identifier[]
  	clientOffset: XYCoord | null
  }
  
  export interface HoverOptions {
  	clientOffset?: XYCoord
  }
  
  export interface DropPayload {
  	dropResult: any
  }
  
  export interface TargetIdPayload {
  	targetId: Identifier
  }
  
  export interface SourceIdPayload {
  	sourceId: Identifier
  }
  
  export interface DragDropActions {
  	beginDrag(
  		sourceIds?: Identifier[],
  		options?: any,
  	): Action<BeginDragPayload> | undefined
  	publishDragSource(): SentinelAction | undefined
  	hover(targetIds: Identifier[], options?: any): Action<HoverPayload>
  	drop(options?: any): void
  	endDrag(): SentinelAction
  }
  
  export interface DragDropManager {
  	getMonitor(): DragDropMonitor
  	getBackend(): Backend
  	getRegistry(): HandlerRegistry
  	getActions(): DragDropActions
  	dispatch(action: any): void
  }
  
  export type BackendFactory = (
  	manager: DragDropManager,
  	globalContext?: any,
  	configuration?: any,
  ) => Backend
  
  export interface DragSource {
  	beginDrag(monitor: DragDropMonitor, targetId: Identifier): void
  	endDrag(monitor: DragDropMonitor, targetId: Identifier): void
  	canDrag(monitor: DragDropMonitor, targetId: Identifier): boolean
  	isDragging(monitor: DragDropMonitor, targetId: Identifier): boolean
  }
  
  export interface DropTarget {
  	canDrop(monitor: DragDropMonitor, targetId: Identifier): boolean
  	hover(monitor: DragDropMonitor, targetId: Identifier): void
  	drop(monitor: DragDropMonitor, targetId: Identifier): any
  }