1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | import * as React from 'react';
|
19 |
|
20 | export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
21 |
|
22 | export interface Position {
|
23 | x: number;
|
24 | y: number;
|
25 | }
|
26 |
|
27 | export interface BoxModel {
|
28 |
|
29 | marginBox: Rect;
|
30 |
|
31 | borderBox: Rect;
|
32 |
|
33 | paddingBox: Rect;
|
34 |
|
35 | contentBox: Rect;
|
36 |
|
37 | border: Spacing;
|
38 | padding: Spacing;
|
39 | margin: Spacing;
|
40 | }
|
41 |
|
42 |
|
43 | export interface Rect {
|
44 |
|
45 | top: number;
|
46 | right: number;
|
47 | bottom: number;
|
48 | left: number;
|
49 | width: number;
|
50 | height: number;
|
51 |
|
52 | x: number;
|
53 | y: number;
|
54 |
|
55 | center: Position;
|
56 | }
|
57 |
|
58 | export interface Spacing {
|
59 | top: number;
|
60 | right: number;
|
61 | bottom: number;
|
62 | left: number;
|
63 | }
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | export type Id = string;
|
70 | export type DraggableId = Id;
|
71 | export type DroppableId = Id;
|
72 | export type TypeId = Id;
|
73 | export type ContextId = Id;
|
74 | export type ElementId = Id;
|
75 |
|
76 | export type DroppableMode = 'standard' | 'virtual';
|
77 |
|
78 | export interface DroppableDescriptor {
|
79 | id: DroppableId;
|
80 | type: TypeId;
|
81 | mode: DroppableMode;
|
82 | }
|
83 |
|
84 | export interface DraggableDescriptor {
|
85 | id: DraggableId;
|
86 | index: number;
|
87 |
|
88 | droppableId: DroppableId;
|
89 |
|
90 |
|
91 | type: TypeId;
|
92 | }
|
93 |
|
94 | export interface DraggableOptions {
|
95 | canDragInteractiveElements: boolean;
|
96 | shouldRespectForcePress: boolean;
|
97 | isEnabled: boolean;
|
98 | }
|
99 |
|
100 | export type Direction = 'horizontal' | 'vertical';
|
101 |
|
102 | export interface VerticalAxis {
|
103 | direction: 'vertical';
|
104 | line: 'y';
|
105 | start: 'top';
|
106 | end: 'bottom';
|
107 | size: 'height';
|
108 | crossAxisLine: 'x';
|
109 | crossAxisStart: 'left';
|
110 | crossAxisEnd: 'right';
|
111 | crossAxisSize: 'width';
|
112 | }
|
113 |
|
114 | export interface HorizontalAxis {
|
115 | direction: 'horizontal';
|
116 | line: 'x';
|
117 | start: 'left';
|
118 | end: 'right';
|
119 | size: 'width';
|
120 | crossAxisLine: 'y';
|
121 | crossAxisStart: 'top';
|
122 | crossAxisEnd: 'bottom';
|
123 | crossAxisSize: 'height';
|
124 | }
|
125 |
|
126 | export type Axis = VerticalAxis | HorizontalAxis;
|
127 |
|
128 | export interface ScrollSize {
|
129 | scrollHeight: number;
|
130 | scrollWidth: number;
|
131 | }
|
132 |
|
133 | export interface ScrollDifference {
|
134 | value: Position;
|
135 |
|
136 |
|
137 |
|
138 | displacement: Position;
|
139 | }
|
140 |
|
141 | export interface ScrollDetails {
|
142 | initial: Position;
|
143 | current: Position;
|
144 |
|
145 | max: Position;
|
146 | diff: ScrollDifference;
|
147 | }
|
148 |
|
149 | export interface Placeholder {
|
150 | client: BoxModel;
|
151 | tagName: string;
|
152 | display: string;
|
153 | }
|
154 |
|
155 | export interface DraggableDimension {
|
156 | descriptor: DraggableDescriptor;
|
157 |
|
158 | placeholder: Placeholder;
|
159 |
|
160 | client: BoxModel;
|
161 |
|
162 | page: BoxModel;
|
163 |
|
164 |
|
165 | displaceBy: Position;
|
166 | }
|
167 |
|
168 | export interface Scrollable {
|
169 |
|
170 |
|
171 | pageMarginBox: Rect;
|
172 |
|
173 | frameClient: BoxModel;
|
174 | scrollSize: ScrollSize;
|
175 |
|
176 |
|
177 | shouldClipSubject: boolean;
|
178 | scroll: ScrollDetails;
|
179 | }
|
180 |
|
181 | export interface PlaceholderInSubject {
|
182 |
|
183 |
|
184 | increasedBy: Position | null | undefined;
|
185 | placeholderSize: Position;
|
186 |
|
187 |
|
188 | oldFrameMaxScroll: Position | null | undefined;
|
189 | }
|
190 |
|
191 | export interface DroppableSubject {
|
192 |
|
193 | page: BoxModel;
|
194 | withPlaceholder: PlaceholderInSubject | null | undefined;
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 | active: Rect | null | undefined;
|
202 | }
|
203 |
|
204 | export interface DroppableDimension {
|
205 | descriptor: DroppableDescriptor;
|
206 | axis: Axis;
|
207 | isEnabled: boolean;
|
208 | isCombineEnabled: boolean;
|
209 |
|
210 | client: BoxModel;
|
211 |
|
212 | isFixedOnPage: boolean;
|
213 |
|
214 | page: BoxModel;
|
215 |
|
216 | frame: Scrollable | null | undefined;
|
217 |
|
218 | subject: DroppableSubject;
|
219 | }
|
220 |
|
221 | export interface DraggableLocation {
|
222 | droppableId: DroppableId;
|
223 | index: number;
|
224 | }
|
225 |
|
226 | export interface DraggableIdMap {
|
227 | [id: string]: true;
|
228 | }
|
229 |
|
230 | export interface DroppableIdMap {
|
231 | [id: string]: true;
|
232 | }
|
233 |
|
234 | export interface DraggableDimensionMap {
|
235 | [key: string]: DraggableDimension;
|
236 | }
|
237 | export interface DroppableDimensionMap {
|
238 | [key: string]: DroppableDimension;
|
239 | }
|
240 |
|
241 | export interface Displacement {
|
242 | draggableId: DraggableId;
|
243 | shouldAnimate: boolean;
|
244 | }
|
245 |
|
246 | export interface DisplacementMap {
|
247 | [key: string]: Displacement;
|
248 | }
|
249 |
|
250 | export interface DisplacedBy {
|
251 | value: number;
|
252 | point: Position;
|
253 | }
|
254 |
|
255 |
|
256 | export interface Combine {
|
257 | draggableId: DraggableId;
|
258 | droppableId: DroppableId;
|
259 | }
|
260 |
|
261 | export interface DisplacementGroups {
|
262 | all: DraggableId[];
|
263 | visible: DisplacementMap;
|
264 | invisible: DraggableIdMap;
|
265 | }
|
266 |
|
267 | export interface ReorderImpact {
|
268 | type: 'REORDER';
|
269 | destination: DraggableLocation;
|
270 | }
|
271 |
|
272 | export interface CombineImpact {
|
273 | type: 'COMBINE';
|
274 | combine: Combine;
|
275 | }
|
276 |
|
277 | export type ImpactLocation = ReorderImpact | CombineImpact;
|
278 |
|
279 | export interface Displaced {
|
280 | forwards: DisplacementGroups;
|
281 | backwards: DisplacementGroups;
|
282 | }
|
283 |
|
284 | export interface DragImpact {
|
285 | displaced: DisplacementGroups;
|
286 | displacedBy: DisplacedBy;
|
287 | at: ImpactLocation | null | undefined;
|
288 | }
|
289 |
|
290 | export interface ClientPositions {
|
291 |
|
292 |
|
293 |
|
294 | selection: Position;
|
295 |
|
296 | borderBoxCenter: Position;
|
297 |
|
298 | offset: Position;
|
299 | }
|
300 |
|
301 | export interface PagePositions {
|
302 | selection: Position;
|
303 | borderBoxCenter: Position;
|
304 |
|
305 | offset: Position;
|
306 | }
|
307 |
|
308 |
|
309 |
|
310 |
|
311 | export type MovementMode = 'FLUID' | 'SNAP';
|
312 |
|
313 | export interface DragPositions {
|
314 | client: ClientPositions;
|
315 | page: PagePositions;
|
316 | }
|
317 |
|
318 | export interface DraggableRubric {
|
319 | draggableId: DraggableId;
|
320 | type: TypeId;
|
321 | source: DraggableLocation;
|
322 | }
|
323 |
|
324 |
|
325 |
|
326 |
|
327 | export interface BeforeCapture {
|
328 | draggableId: DraggableId;
|
329 | mode: MovementMode;
|
330 | }
|
331 |
|
332 |
|
333 | export interface DragStart extends DraggableRubric {
|
334 | mode: MovementMode;
|
335 | }
|
336 |
|
337 | export interface DragUpdate extends DragStart {
|
338 |
|
339 | destination: DraggableLocation | null | undefined;
|
340 |
|
341 | combine: Combine | null | undefined;
|
342 | }
|
343 |
|
344 | export type DropReason = 'DROP' | 'CANCEL';
|
345 |
|
346 | export interface DropResult extends DragUpdate {
|
347 | reason: DropReason;
|
348 | }
|
349 |
|
350 | export interface ScrollOptions {
|
351 | shouldPublishImmediately: boolean;
|
352 | }
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 | export interface LiftRequest {
|
361 | draggableId: DraggableId;
|
362 | scrollOptions: ScrollOptions;
|
363 | }
|
364 |
|
365 | export interface Critical {
|
366 | draggable: DraggableDescriptor;
|
367 | droppable: DroppableDescriptor;
|
368 | }
|
369 |
|
370 | export interface Viewport {
|
371 |
|
372 | frame: Rect;
|
373 | scroll: ScrollDetails;
|
374 | }
|
375 |
|
376 | export interface LiftEffect {
|
377 | inVirtualList: boolean;
|
378 | effected: DraggableIdMap;
|
379 | displacedBy: DisplacedBy;
|
380 | }
|
381 |
|
382 | export interface DimensionMap {
|
383 | draggables: DraggableDimensionMap;
|
384 | droppables: DroppableDimensionMap;
|
385 | }
|
386 |
|
387 | export interface DroppablePublish {
|
388 | droppableId: DroppableId;
|
389 | scroll: Position;
|
390 | }
|
391 |
|
392 | export interface Published {
|
393 | additions: DraggableDimension[];
|
394 | removals: DraggableId[];
|
395 | modified: DroppablePublish[];
|
396 | }
|
397 |
|
398 | export interface CompletedDrag {
|
399 | critical: Critical;
|
400 | result: DropResult;
|
401 | impact: DragImpact;
|
402 | afterCritical: LiftEffect;
|
403 | }
|
404 |
|
405 | export interface IdleState {
|
406 | phase: 'IDLE';
|
407 | completed: CompletedDrag | null | undefined;
|
408 | shouldFlush: boolean;
|
409 | }
|
410 |
|
411 | export interface DraggingState {
|
412 | phase: 'DRAGGING';
|
413 | isDragging: true;
|
414 | critical: Critical;
|
415 | movementMode: MovementMode;
|
416 | dimensions: DimensionMap;
|
417 | initial: DragPositions;
|
418 | current: DragPositions;
|
419 | impact: DragImpact;
|
420 | viewport: Viewport;
|
421 | afterCritical: LiftEffect;
|
422 | onLiftImpact: DragImpact;
|
423 |
|
424 | isWindowScrollAllowed: boolean;
|
425 |
|
426 | scrollJumpRequest: Position | null | undefined;
|
427 |
|
428 | forceShouldAnimate: boolean | null | undefined;
|
429 | }
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 | export interface CollectingState extends Omit<DraggingState, 'phase'> {
|
437 | phase: 'COLLECTING';
|
438 | }
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 | export interface DropPendingState extends Omit<DraggingState, 'phase'> {
|
445 | phase: 'DROP_PENDING';
|
446 | isWaiting: boolean;
|
447 | reason: DropReason;
|
448 | }
|
449 |
|
450 |
|
451 | export interface DropAnimatingState {
|
452 | phase: 'DROP_ANIMATING';
|
453 | completed: CompletedDrag;
|
454 | newHomeClientOffset: Position;
|
455 | dropDuration: number;
|
456 |
|
457 | dimensions: DimensionMap;
|
458 | }
|
459 |
|
460 | export type State = IdleState | DraggingState | CollectingState | DropPendingState | DropAnimatingState;
|
461 |
|
462 | export type StateWhenUpdatesAllowed = DraggingState | CollectingState;
|
463 |
|
464 | export type Announce = (message: string) => void;
|
465 |
|
466 | export type InOutAnimationMode = 'none' | 'open' | 'close';
|
467 |
|
468 | export interface ResponderProvided {
|
469 | announce: Announce;
|
470 | }
|
471 |
|
472 | export type OnBeforeCaptureResponder = (before: BeforeCapture) => void;
|
473 |
|
474 | export type OnBeforeDragStartResponder = (start: DragStart) => void;
|
475 |
|
476 | export type OnDragStartResponder = (start: DragStart, provided: ResponderProvided) => void;
|
477 |
|
478 | export type OnDragUpdateResponder = (update: DragUpdate, provided: ResponderProvided) => void;
|
479 |
|
480 | export type OnDragEndResponder = (result: DropResult, provided: ResponderProvided) => void;
|
481 |
|
482 | export interface Responders {
|
483 | onBeforeCapture?: OnBeforeCaptureResponder | undefined;
|
484 | onBeforeDragStart?: OnBeforeDragStartResponder | undefined;
|
485 | onDragStart?: OnDragStartResponder | undefined;
|
486 | onDragUpdate?: OnDragUpdateResponder | undefined;
|
487 |
|
488 | onDragEnd: OnDragEndResponder;
|
489 | }
|
490 |
|
491 | export interface StopDragOptions {
|
492 | shouldBlockNextClick: boolean;
|
493 | }
|
494 |
|
495 | export interface DragActions {
|
496 | drop: (args?: StopDragOptions) => void;
|
497 | cancel: (args?: StopDragOptions) => void;
|
498 | isActive: () => boolean;
|
499 | shouldRespectForcePress: () => boolean;
|
500 | }
|
501 |
|
502 | export interface FluidDragActions extends DragActions {
|
503 | move: (clientSelection: Position) => void;
|
504 | }
|
505 |
|
506 | export interface SnapDragActions extends DragActions {
|
507 | moveUp: () => void;
|
508 | moveDown: () => void;
|
509 | moveRight: () => void;
|
510 | moveLeft: () => void;
|
511 | }
|
512 |
|
513 | export interface PreDragActions {
|
514 |
|
515 | isActive: () => boolean;
|
516 |
|
517 | shouldRespectForcePress: () => boolean;
|
518 |
|
519 | fluidLift: (clientSelection: Position) => FluidDragActions;
|
520 | snapLift: () => SnapDragActions;
|
521 |
|
522 | abort: () => void;
|
523 | }
|
524 |
|
525 | export interface TryGetLockOptions {
|
526 | sourceEvent?: Event | undefined;
|
527 | }
|
528 |
|
529 | export type TryGetLock = (
|
530 | draggableId: DraggableId,
|
531 | forceStop?: () => void,
|
532 | options?: TryGetLockOptions,
|
533 | ) => PreDragActions | null;
|
534 |
|
535 | export interface SensorAPI {
|
536 | tryGetLock: TryGetLock;
|
537 | canGetLock: (id: DraggableId) => boolean;
|
538 | isLockClaimed: () => boolean;
|
539 | tryReleaseLock: () => void;
|
540 | findClosestDraggableId: (event: Event) => DraggableId | null;
|
541 | findOptionsForDraggable: (id: DraggableId) => DraggableOptions | null;
|
542 | }
|
543 |
|
544 | export type Sensor = (api: SensorAPI) => void;
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 | export interface DragDropContextProps extends Responders {
|
553 | children: React.ReactNode | null;
|
554 | dragHandleUsageInstructions?: string | undefined;
|
555 | nonce?: string | undefined;
|
556 | enableDefaultSensors?: boolean | undefined;
|
557 | sensors?: Sensor[] | undefined;
|
558 | }
|
559 |
|
560 | export class DragDropContext extends React.Component<DragDropContextProps> {}
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 | export interface DroppableProvidedProps {
|
569 |
|
570 | 'data-rbd-droppable-context-id': ContextId;
|
571 |
|
572 | 'data-rbd-droppable-id': DroppableId;
|
573 | }
|
574 |
|
575 | export interface DroppableProvided {
|
576 | innerRef: (element: HTMLElement | null) => void;
|
577 | placeholder: React.ReactNode;
|
578 | droppableProps: DroppableProvidedProps;
|
579 | }
|
580 |
|
581 | export interface DroppableStateSnapshot {
|
582 | isDraggingOver: boolean;
|
583 | draggingOverWith: DraggableId | null | undefined;
|
584 | draggingFromThisWith: DraggableId | null | undefined;
|
585 | isUsingPlaceholder: boolean;
|
586 | }
|
587 |
|
588 | export interface DroppableProps {
|
589 | droppableId: DroppableId;
|
590 | type?: TypeId | undefined;
|
591 | mode?: DroppableMode | undefined;
|
592 | isDropDisabled?: boolean | undefined;
|
593 | isCombineEnabled?: boolean | undefined;
|
594 | direction?: Direction | undefined;
|
595 | ignoreContainerClipping?: boolean | undefined;
|
596 | renderClone?: DraggableChildrenFn | undefined;
|
597 | getContainerForClone?: (() => HTMLElement) | undefined;
|
598 | children(provided: DroppableProvided, snapshot: DroppableStateSnapshot): React.ReactElement<HTMLElement>;
|
599 | }
|
600 |
|
601 | export class Droppable extends React.Component<DroppableProps> {}
|
602 |
|
603 | /**
|
604 | * Draggable
|
605 | */
|
606 |
|
607 | // Refer to https://github.com/atlassian/react-beautiful-dnd/blob/master/src/view/draggable/draggable-types.js
|
608 |
|
609 | export interface DropAnimation {
|
610 | duration: number;
|
611 | curve: string;
|
612 | moveTo: Position;
|
613 | /**
|
614 | * This value will actually be `null` instead of `undefined`.
|
615 | *
|
616 | * The type is fudged because `null` is not compatible with the
|
617 | * `React.CSSProperties` type.
|
618 | *
|
619 | * The `style` prop should interpret `null` and `undefined` the same way.
|
620 | */
|
621 | opacity: number | undefined;
|
622 | /**
|
623 | * This value will actually be `null` instead of `undefined`.
|
624 | *
|
625 | * The type is fudged because `null` is not compatible with the
|
626 | * `React.CSSProperties` type.
|
627 | *
|
628 | * The `style` prop should interpret `null` and `undefined` the same way.
|
629 | */
|
630 | scale: number | undefined;
|
631 | }
|
632 |
|
633 | export interface NotDraggingStyle {
|
634 | /**
|
635 | * This value will actually be `null` instead of `undefined`.
|
636 | *
|
637 | * The type is fudged because `null` is not compatible with the
|
638 | * `React.CSSProperties` type.
|
639 | *
|
640 | * The `style` prop should interpret `null` and `undefined` the same way.
|
641 | */
|
642 | transform: string | undefined;
|
643 | /**
|
644 | * This value will actually be `null` instead of `undefined`.
|
645 | *
|
646 | * The type is fudged because `null` is not compatible with the
|
647 | * `React.CSSProperties` type.
|
648 | *
|
649 | * The `style` prop should interpret `null` and `undefined` the same way.
|
650 | */
|
651 | transition: 'none' | undefined;
|
652 | }
|
653 |
|
654 | export interface DraggingStyle {
|
655 | position: 'fixed';
|
656 | top: number;
|
657 | left: number;
|
658 | boxSizing: 'border-box';
|
659 | width: number;
|
660 | height: number;
|
661 | transition: string;
|
662 | /**
|
663 | * This value will actually be `null` instead of `undefined`.
|
664 | *
|
665 | * The type is fudged because `null` is not compatible with the
|
666 | * `React.CSSProperties` type.
|
667 | *
|
668 | * The `style` prop should interpret `null` and `undefined` the same way.
|
669 | */
|
670 | transform: string | undefined;
|
671 | zIndex: number;
|
672 | /**
|
673 | * This value will actually be `null` instead of `undefined`.
|
674 | *
|
675 | * The type is fudged because `null` is not compatible with the
|
676 | * `React.CSSProperties` type.
|
677 | *
|
678 | * The `style` prop should interpret `null` and `undefined` the same way.
|
679 | */
|
680 | opacity: number | undefined;
|
681 | pointerEvents: 'none';
|
682 | }
|
683 |
|
684 | export interface DraggableProvidedDraggableProps {
|
685 | // inline style
|
686 | style?: DraggingStyle | NotDraggingStyle | undefined;
|
687 | // used for shared global styles
|
688 | 'data-rbd-draggable-context-id': string;
|
689 | 'data-rbd-draggable-id': string;
|
690 | onTransitionEnd?: React.TransitionEventHandler<any> | undefined;
|
691 | }
|
692 |
|
693 | export interface DraggableProvidedDragHandleProps {
|
694 | 'data-rbd-drag-handle-draggable-id': DraggableId;
|
695 | 'data-rbd-drag-handle-context-id': ContextId;
|
696 | 'aria-describedby': ElementId;
|
697 |
|
698 | role: string;
|
699 | tabIndex: number;
|
700 | draggable: boolean;
|
701 | onDragStart: React.DragEventHandler<any>;
|
702 | }
|
703 |
|
704 | export interface DraggableProvided {
|
705 | // will be removed after move to react 16
|
706 | innerRef: (element: HTMLElement | null) => void;
|
707 | draggableProps: DraggableProvidedDraggableProps;
|
708 | dragHandleProps: DraggableProvidedDragHandleProps | null | undefined;
|
709 | }
|
710 |
|
711 | export interface DraggableStateSnapshot {
|
712 | isDragging: boolean;
|
713 | isDropAnimating: boolean;
|
714 | isClone: boolean;
|
715 | dropAnimation: DropAnimation | null | undefined;
|
716 | draggingOver: DroppableId | null | undefined;
|
717 |
|
718 | combineWith: DraggableId | null | undefined;
|
719 |
|
720 | combineTargetFor: DraggableId | null | undefined;
|
721 |
|
722 | mode: MovementMode | null | undefined;
|
723 | }
|
724 |
|
725 | export type DraggableChildrenFn = (
|
726 | provided: DraggableProvided,
|
727 | snapshot: DraggableStateSnapshot,
|
728 | rubric: DraggableRubric,
|
729 | ) => React.ReactElement<HTMLElement>;
|
730 |
|
731 | export interface DraggableProps {
|
732 | draggableId: DraggableId;
|
733 | index: number;
|
734 | children: DraggableChildrenFn;
|
735 | isDragDisabled?: boolean | undefined;
|
736 | disableInteractiveElementBlocking?: boolean | undefined;
|
737 | shouldRespectForcePress?: boolean | undefined;
|
738 | }
|
739 |
|
740 | export class Draggable extends React.Component<DraggableProps> {}
|
741 |
|
742 | export function resetServerContext(): void;
|
743 |
|
744 | export const useMouseSensor: Sensor;
|
745 | export const useTouchSensor: Sensor;
|
746 | export const useKeyboardSensor: Sensor;
|