1 | import type { SourceType, TargetType } from 'dnd-core';
|
2 | import type { DragPreviewOptions, DragSourceMonitor, DragSourceOptions, DropTargetMonitor, DropTargetOptions } from '../types/index.js';
|
3 | export declare type FactoryOrInstance<T> = T | (() => T);
|
4 | export declare type DragObjectFactory<T> = (monitor: DragSourceMonitor<T>) => T | null;
|
5 | export interface DragSourceHookSpec<DragObject, DropResult, CollectedProps> {
|
6 | /**
|
7 | * The type of item being dragged. This is required when using the function form of spec.item.
|
8 | * If spec.item is a static object, the type may either be defined on that object as `item.type`, or it may
|
9 | * be defined here.
|
10 | */
|
11 | type: SourceType;
|
12 | /**
|
13 | * This property generates or defines a plain javascript item describing
|
14 | * the data being dragged. This is the only information available to the
|
15 | * drop targets about the drag source so it's important to pick the minimal
|
16 | * data they need to know.
|
17 | *
|
18 | * You may be tempted to put a reference to the component or complex object here,
|
19 | * but you should try very hard to avoid doing this because it couples the
|
20 | * drag sources and drop targets. It's a good idea to use something like
|
21 | * { id: props.id }
|
22 | *
|
23 | * If a function-form is used, it is invoked when the drag begins and returns a draggable item.
|
24 | * If the function returns null, the drag is canceled
|
25 | *
|
26 | */
|
27 | item?: DragObject | DragObjectFactory<DragObject>;
|
28 | /**
|
29 | * The drag source options
|
30 | */
|
31 | options?: DragSourceOptions;
|
32 | /**
|
33 | * DragPreview options
|
34 | */
|
35 | previewOptions?: DragPreviewOptions;
|
36 | /**
|
37 | * Optional.
|
38 | * When the dragging stops, endDrag is called. For every beginDrag call, a corresponding endDrag call is guaranteed.
|
39 | * You may call monitor.didDrop() to check whether or not the drop was handled by a compatible drop target. If it was handled,
|
40 | * and the drop target specified a drop result by returning a plain object from its drop() method, it will be available as
|
41 | * monitor.getDropResult(). This method is a good place to fire a Flux action. Note: If the component is unmounted while dragging,
|
42 | * component parameter is set to be null.
|
43 | */
|
44 | end?: (draggedItem: DragObject, monitor: DragSourceMonitor<DragObject, DropResult>) => void;
|
45 | /**
|
46 | * Optional.
|
47 | * Use it to specify whether the dragging is currently allowed. If you want to always allow it, just omit this method.
|
48 | * Specifying it is handy if you'd like to disable dragging based on some predicate over props. Note: You may not call
|
49 | * monitor.canDrag() inside this method.
|
50 | */
|
51 | canDrag?: boolean | ((monitor: DragSourceMonitor<DragObject, DropResult>) => boolean);
|
52 | /**
|
53 | * Optional.
|
54 | * By default, only the drag source that initiated the drag operation is considered to be dragging. You can
|
55 | * override this behavior by defining a custom isDragging method. It might return something like props.id === monitor.getItem().id.
|
56 | * Do this if the original component may be unmounted during the dragging and later “resurrected” with a different parent.
|
57 | * For example, when moving a card across the lists in a Kanban board, you want it to retain the dragged appearance—even though
|
58 | * technically, the component gets unmounted and a different one gets mounted every time you move it to another list.
|
59 | *
|
60 | * Note: You may not call monitor.isDragging() inside this method.
|
61 | */
|
62 | isDragging?: (monitor: DragSourceMonitor<DragObject, DropResult>) => boolean;
|
63 | /**
|
64 | * A function to collect rendering properties
|
65 | */
|
66 | collect?: (monitor: DragSourceMonitor<DragObject, DropResult>) => CollectedProps;
|
67 | }
|
68 | /**
|
69 | * Interface for the DropTarget specification object
|
70 | */
|
71 | export interface DropTargetHookSpec<DragObject, DropResult, CollectedProps> {
|
72 | /**
|
73 | * The kinds of dragItems this dropTarget accepts
|
74 | */
|
75 | accept: TargetType;
|
76 | /**
|
77 | * The drop target options
|
78 | */
|
79 | options?: DropTargetOptions;
|
80 | /**
|
81 | * Optional.
|
82 | * Called when a compatible item is dropped on the target. You may either return undefined, or a plain object.
|
83 | * If you return an object, it is going to become the drop result and will be available to the drag source in its
|
84 | * endDrag method as monitor.getDropResult(). This is useful in case you want to perform different actions
|
85 | * depending on which target received the drop. If you have nested drop targets, you can test whether a nested
|
86 | * target has already handled drop by checking monitor.didDrop() and monitor.getDropResult(). Both this method and
|
87 | * the source's endDrag method are good places to fire Flux actions. This method will not be called if canDrop()
|
88 | * is defined and returns false.
|
89 | */
|
90 | drop?: (item: DragObject, monitor: DropTargetMonitor<DragObject, DropResult>) => DropResult | undefined;
|
91 | /**
|
92 | * Optional.
|
93 | * Called when an item is hovered over the component. You can check monitor.isOver({ shallow: true }) to test whether
|
94 | * the hover happens over just the current target, or over a nested one. Unlike drop(), this method will be called even
|
95 | * if canDrop() is defined and returns false. You can check monitor.canDrop() to test whether this is the case.
|
96 | */
|
97 | hover?: (item: DragObject, monitor: DropTargetMonitor<DragObject, DropResult>) => void;
|
98 | /**
|
99 | * Optional. Use it to specify whether the drop target is able to accept the item. If you want to always allow it, just
|
100 | * omit this method. Specifying it is handy if you'd like to disable dropping based on some predicate over props or
|
101 | * monitor.getItem(). Note: You may not call monitor.canDrop() inside this method.
|
102 | */
|
103 | canDrop?: (item: DragObject, monitor: DropTargetMonitor<DragObject, DropResult>) => boolean;
|
104 | /**
|
105 | * A function to collect rendering properties
|
106 | */
|
107 | collect?: (monitor: DropTargetMonitor<DragObject, DropResult>) => CollectedProps;
|
108 | }
|