@progress/kendo-react-common 4.11.0 → 4.13.0-dev.202111231559
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/js/kendo-react-common.js +1 -1
- package/dist/es/Draggable.d.ts +50 -42
- package/dist/es/Draggable.js +78 -75
- package/dist/es/Droppable.d.ts +77 -0
- package/dist/es/Droppable.js +68 -0
- package/dist/es/drag-n-drop/context/index.d.ts +18 -0
- package/dist/es/drag-n-drop/context/index.js +24 -0
- package/dist/es/drag-n-drop/index.d.ts +21 -0
- package/dist/es/drag-n-drop/index.js +44 -0
- package/dist/es/hooks/index.d.ts +4 -0
- package/dist/es/hooks/index.js +4 -0
- package/dist/es/hooks/useCollection.d.ts +14 -0
- package/dist/es/hooks/useCollection.js +26 -0
- package/dist/es/hooks/useControlledState.d.ts +4 -0
- package/dist/es/hooks/useControlledState.js +23 -0
- package/dist/es/hooks/useDraggable.d.ts +62 -6
- package/dist/es/hooks/useDraggable.js +327 -22
- package/dist/es/hooks/useDroppable.d.ts +28 -0
- package/dist/es/hooks/useDroppable.js +59 -0
- package/dist/es/hooks/useInheritedState.d.ts +13 -0
- package/dist/es/hooks/useInheritedState.js +21 -0
- package/dist/es/hooks/usePointer.d.ts +21 -0
- package/dist/es/hooks/usePointer.js +29 -0
- package/dist/es/hooks/useTouch.d.ts +15 -0
- package/dist/es/hooks/useTouch.js +29 -0
- package/dist/es/main.d.ts +6 -2
- package/dist/es/main.js +6 -2
- package/dist/es/models/auto-scroll-options.d.ts +23 -0
- package/dist/es/models/auto-scroll-options.js +0 -0
- package/dist/es/models/index.d.ts +3 -0
- package/dist/es/models/kendo-component.d.ts +6 -0
- package/dist/es/models/kendo-component.js +0 -0
- package/dist/es/models/pointer.d.ts +23 -0
- package/dist/es/models/pointer.js +0 -0
- package/dist/es/models/touch.d.ts +17 -0
- package/dist/es/models/touch.js +0 -0
- package/dist/npm/Draggable.d.ts +50 -42
- package/dist/npm/Draggable.js +78 -75
- package/dist/npm/Droppable.d.ts +77 -0
- package/dist/npm/Droppable.js +70 -0
- package/dist/npm/drag-n-drop/context/index.d.ts +18 -0
- package/dist/npm/drag-n-drop/context/index.js +26 -0
- package/dist/npm/drag-n-drop/index.d.ts +21 -0
- package/dist/npm/drag-n-drop/index.js +46 -0
- package/dist/npm/hooks/index.d.ts +4 -0
- package/dist/npm/hooks/index.js +4 -0
- package/dist/npm/hooks/useCollection.d.ts +14 -0
- package/dist/npm/hooks/useCollection.js +28 -0
- package/dist/npm/hooks/useControlledState.d.ts +4 -0
- package/dist/npm/hooks/useControlledState.js +25 -0
- package/dist/npm/hooks/useDraggable.d.ts +62 -6
- package/dist/npm/hooks/useDraggable.js +327 -22
- package/dist/npm/hooks/useDroppable.d.ts +28 -0
- package/dist/npm/hooks/useDroppable.js +62 -0
- package/dist/npm/hooks/useInheritedState.d.ts +13 -0
- package/dist/npm/hooks/useInheritedState.js +23 -0
- package/dist/npm/hooks/usePointer.d.ts +21 -0
- package/dist/npm/hooks/usePointer.js +31 -0
- package/dist/npm/hooks/useTouch.d.ts +15 -0
- package/dist/npm/hooks/useTouch.js +31 -0
- package/dist/npm/main.d.ts +6 -2
- package/dist/npm/main.js +6 -2
- package/dist/npm/models/auto-scroll-options.d.ts +23 -0
- package/dist/npm/models/auto-scroll-options.js +2 -0
- package/dist/npm/models/index.d.ts +3 -0
- package/dist/npm/models/kendo-component.d.ts +6 -0
- package/dist/npm/models/kendo-component.js +2 -0
- package/dist/npm/models/pointer.d.ts +23 -0
- package/dist/npm/models/pointer.js +2 -0
- package/dist/npm/models/touch.d.ts +17 -0
- package/dist/npm/models/touch.js +2 -0
- package/dist/systemjs/kendo-react-common.js +1 -1
- package/package.json +11 -8
|
@@ -1,31 +1,336 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var React = require("react");
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
var kendo_draggable_common_1 = require("@progress/kendo-draggable-common");
|
|
5
|
+
var noop_1 = require("../noop");
|
|
6
|
+
var useInheritedState_1 = require("../hooks/useInheritedState");
|
|
7
|
+
var context_1 = require("../drag-n-drop/context");
|
|
8
|
+
var IGNORE_MOUSE_TIMEOUT = 2000;
|
|
9
|
+
/**
|
|
10
|
+
* Represents the KendoReact `useDraggable` hook.
|
|
11
|
+
* Use it to attach `drag` events to a native HTML DOM elements, or custom React Components.
|
|
12
|
+
*
|
|
13
|
+
* For more information, refer to the [KendoReact Draggable]({% slug draggable_drag-and-drop %}) article.
|
|
14
|
+
*
|
|
15
|
+
* @param ref - The `ref` of the HTML Element or React Component which will enable the `draggable` functionality.
|
|
16
|
+
* @param callbacks - A collection of callbacks, called by the `useDraggable` hook when a specific action occurs.
|
|
17
|
+
* @param options - Additional configuration of the `useDraggable` hook.
|
|
18
|
+
*/
|
|
19
|
+
function useDraggable(ref, callbacks, options) {
|
|
20
|
+
if (options === void 0) { options = {}; }
|
|
21
|
+
var _a = callbacks.onPress, onPress = _a === void 0 ? noop_1.noop : _a, _b = callbacks.onRelease, onRelease = _b === void 0 ? noop_1.noop : _b, _c = callbacks.onDragStart, onDragStart = _c === void 0 ? noop_1.noop : _c, _d = callbacks.onDrag, onDrag = _d === void 0 ? noop_1.noop : _d, _e = callbacks.onDragEnd, onDragEnd = _e === void 0 ? noop_1.noop : _e;
|
|
22
|
+
var _f = options.hint, hint = _f === void 0 ? null : _f, _g = options.mouseOnly, mouseOnly = _g === void 0 ? false : _g, _h = options.autoScroll, autoScroll = _h === void 0 ? true : _h, _j = options.scrollContainer, scrollContainer = _j === void 0 ? null : _j;
|
|
23
|
+
var _k = React.useState(false), pressed = _k[0], setPressed = _k[1];
|
|
24
|
+
var _l = React.useState(false), scrolling = _l[0], setScrolling = _l[1];
|
|
25
|
+
var drop = useInheritedState_1.useInheritedState(context_1.DropContext)[0];
|
|
26
|
+
var _m = useInheritedState_1.useInheritedState(context_1.DragContext), drag = _m[0], setDrag = _m[1];
|
|
27
|
+
var drops = React.useContext(context_1.DropsContext)[0];
|
|
28
|
+
var _o = React.useContext(context_1.DragsContext), drags = _o[0], registerDrag = _o[1], deregisterDrag = _o[2];
|
|
29
|
+
var velocity = React.useRef({ x: 0, y: 0 });
|
|
30
|
+
var scrollInterval = React.useRef();
|
|
31
|
+
var ignoreMouse = React.useRef(false);
|
|
32
|
+
var restoreMouseTimeout = React.useRef();
|
|
33
|
+
var unmount = React.useRef(false);
|
|
34
|
+
var offset = React.useRef({ x: 0, y: 0 });
|
|
35
|
+
var pageOffset = React.useRef({ x: 0, y: 0 });
|
|
36
|
+
var clientOffset = React.useRef({ x: 0, y: 0 });
|
|
37
|
+
var initialClientOffset = React.useRef({ x: 0, y: 0 });
|
|
38
|
+
var scrollOffset = React.useRef({ x: 0, y: 0 });
|
|
39
|
+
var initialScrollOffset = React.useRef({ x: 0, y: 0 });
|
|
40
|
+
var supportPointerEvent = Boolean(window && (typeof window !== 'undefined') && window.PointerEvent);
|
|
41
|
+
var pointers = !mouseOnly && supportPointerEvent;
|
|
42
|
+
var getElement = React.useCallback(function () { return ref.current && ref.current.element
|
|
43
|
+
? ref.current.element
|
|
44
|
+
: ref.current; }, [ref]);
|
|
45
|
+
var getHintElement = React.useCallback(function () { return hint && hint.current && hint.current.element
|
|
46
|
+
? hint.current.element
|
|
47
|
+
: hint
|
|
48
|
+
? hint.current
|
|
49
|
+
: null; }, [hint]);
|
|
50
|
+
var getScrollContainer = React.useCallback(function () { return scrollContainer && scrollContainer.current && scrollContainer.current.element
|
|
51
|
+
? scrollContainer.current.element
|
|
52
|
+
: scrollContainer
|
|
53
|
+
? scrollContainer.current
|
|
54
|
+
: null; }, [scrollContainer]);
|
|
55
|
+
var getAutoScrollContainer = React.useCallback(function () { return typeof autoScroll === 'object' && autoScroll.boundaryElementRef
|
|
56
|
+
&& autoScroll.boundaryElementRef.current && autoScroll.boundaryElementRef.current.element
|
|
57
|
+
? autoScroll.boundaryElementRef.current.element
|
|
58
|
+
: typeof autoScroll === 'object' && autoScroll.boundaryElementRef && autoScroll.boundaryElementRef.current
|
|
59
|
+
? autoScroll.boundaryElementRef.current
|
|
60
|
+
: null; }, [autoScroll]);
|
|
61
|
+
var target = React.useRef(null);
|
|
62
|
+
React.useImperativeHandle(target, function () { return ({
|
|
63
|
+
element: getElement(),
|
|
64
|
+
hint: getHintElement(),
|
|
65
|
+
onPress: handlePress,
|
|
66
|
+
onDragStart: handleDragStart,
|
|
67
|
+
onDrag: handleDrag,
|
|
68
|
+
onDragEnd: handleDragEnd,
|
|
69
|
+
onRelease: handleRelease,
|
|
70
|
+
data: ref.current
|
|
71
|
+
}); });
|
|
72
|
+
var getDocument = React.useCallback(function () {
|
|
73
|
+
var element = getElement();
|
|
74
|
+
return element ? element.ownerDocument || document : document;
|
|
75
|
+
}, [getElement]);
|
|
76
|
+
var getWindow = React.useCallback(function () {
|
|
77
|
+
var document = getDocument();
|
|
78
|
+
return document
|
|
79
|
+
? document.defaultView || window
|
|
80
|
+
: window;
|
|
81
|
+
}, [getDocument]);
|
|
82
|
+
var getState = React.useCallback(function () { return ({
|
|
83
|
+
drag: drag ? drag.current : null,
|
|
84
|
+
drop: drop ? drop.current : null,
|
|
85
|
+
drags: drags.map(function (d) { return d.current; }),
|
|
86
|
+
drops: drops.map(function (d) { return d.current; }),
|
|
87
|
+
pressed: pressed,
|
|
88
|
+
ignoreMouse: ignoreMouse.current,
|
|
89
|
+
scrollOffset: scrollOffset.current,
|
|
90
|
+
offset: offset.current,
|
|
91
|
+
pageOffset: pageOffset.current,
|
|
92
|
+
initialScrollOffset: initialScrollOffset.current,
|
|
93
|
+
clientOffset: clientOffset.current,
|
|
94
|
+
initialClientOffset: initialClientOffset.current,
|
|
95
|
+
velocity: velocity.current,
|
|
96
|
+
autoScroll: Boolean(typeof autoScroll === 'object' ? autoScroll.enabled !== false : autoScroll),
|
|
97
|
+
scrollableParent: getAutoScrollContainer(),
|
|
98
|
+
autoScrollDirection: typeof autoScroll === 'object' ? autoScroll.direction : { horizontal: true, vertical: true },
|
|
99
|
+
isScrolling: scrolling
|
|
100
|
+
}); }, [drag, drop, drags, drops, pressed, autoScroll, getAutoScrollContainer, scrolling]);
|
|
101
|
+
var handlePressedChange = React.useCallback(function (value) {
|
|
102
|
+
setPressed(value);
|
|
103
|
+
}, []);
|
|
104
|
+
var handleScrollingChange = React.useCallback(function (value) {
|
|
105
|
+
setScrolling(value);
|
|
106
|
+
}, []);
|
|
107
|
+
var handleVelocityChange = React.useCallback(function (value) {
|
|
108
|
+
velocity.current = value;
|
|
109
|
+
}, []);
|
|
110
|
+
var handleOffsetChange = React.useCallback(function (value) {
|
|
111
|
+
offset.current = value;
|
|
112
|
+
}, []);
|
|
113
|
+
var handleClientOffsetChange = React.useCallback(function (value) {
|
|
114
|
+
clientOffset.current = value;
|
|
115
|
+
}, []);
|
|
116
|
+
var handlePageOffsetChange = React.useCallback(function (value) {
|
|
117
|
+
pageOffset.current = value;
|
|
118
|
+
}, []);
|
|
119
|
+
var handleInitialClientOffsetChange = React.useCallback(function (value) {
|
|
120
|
+
initialClientOffset.current = value;
|
|
121
|
+
}, []);
|
|
122
|
+
var handleScrollOffsetChange = React.useCallback(function (value) {
|
|
123
|
+
scrollOffset.current = value;
|
|
124
|
+
}, []);
|
|
125
|
+
var handleInitialScrollOffsetChange = React.useCallback(function (value) {
|
|
126
|
+
initialScrollOffset.current = value;
|
|
127
|
+
}, []);
|
|
128
|
+
// Drag Events
|
|
129
|
+
var handlePress = React.useCallback(function (event) {
|
|
130
|
+
onPress(event);
|
|
131
|
+
}, [onPress]);
|
|
132
|
+
var handleRelease = React.useCallback(function (event) {
|
|
133
|
+
onRelease(event);
|
|
134
|
+
}, [onRelease]);
|
|
135
|
+
var handleDragStart = React.useCallback(function (event) {
|
|
136
|
+
setDrag(target, { target: ref.current, event: event });
|
|
137
|
+
onDragStart(event);
|
|
138
|
+
}, [setDrag, ref, onDragStart]);
|
|
139
|
+
var handleDrag = React.useCallback(function (event) {
|
|
140
|
+
onDrag(event);
|
|
141
|
+
}, [onDrag]);
|
|
142
|
+
var handleDragEnd = React.useCallback(function (event) {
|
|
143
|
+
if (unmount.current) {
|
|
16
144
|
return;
|
|
17
145
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
146
|
+
setDrag(null, { target: ref.current, event: event });
|
|
147
|
+
onDragEnd(event);
|
|
148
|
+
}, [onDragEnd, setDrag, ref]);
|
|
149
|
+
var dispatchDragEvent = React.useCallback(function (event) {
|
|
150
|
+
kendo_draggable_common_1.dispatchDragAndDrop(getState(), { event: event, payload: target.current }, {
|
|
151
|
+
onVelocityChange: handleVelocityChange,
|
|
152
|
+
onOffsetChange: handleOffsetChange,
|
|
153
|
+
onClientOffsetChange: handleClientOffsetChange,
|
|
154
|
+
onPageOffsetChange: handlePageOffsetChange,
|
|
155
|
+
onInitialClientOffsetChange: handleInitialClientOffsetChange,
|
|
156
|
+
onScrollOffsetChange: handleScrollOffsetChange,
|
|
157
|
+
onInitialScrollOffsetChange: handleInitialScrollOffsetChange,
|
|
158
|
+
onIsPressedChange: handlePressedChange,
|
|
159
|
+
onIsScrollingChange: handleScrollingChange
|
|
26
160
|
});
|
|
161
|
+
}, [
|
|
162
|
+
getState,
|
|
163
|
+
handleVelocityChange,
|
|
164
|
+
handleOffsetChange,
|
|
165
|
+
handlePageOffsetChange,
|
|
166
|
+
handleClientOffsetChange,
|
|
167
|
+
handleInitialClientOffsetChange,
|
|
168
|
+
handleInitialScrollOffsetChange,
|
|
169
|
+
handlePressedChange,
|
|
170
|
+
handleScrollOffsetChange,
|
|
171
|
+
handleScrollingChange
|
|
172
|
+
]);
|
|
173
|
+
// Pointer Events
|
|
174
|
+
var handlePointerDown = React.useCallback(function (event) {
|
|
175
|
+
dispatchDragEvent(event);
|
|
176
|
+
}, [dispatchDragEvent]);
|
|
177
|
+
var handlePointerMove = React.useCallback(function (event) {
|
|
178
|
+
dispatchDragEvent(event);
|
|
179
|
+
}, [dispatchDragEvent]);
|
|
180
|
+
var handlePointerCancel = React.useCallback(function (event) {
|
|
181
|
+
dispatchDragEvent(event);
|
|
182
|
+
}, [dispatchDragEvent]);
|
|
183
|
+
var handlePointerUp = React.useCallback(function (event) {
|
|
184
|
+
dispatchDragEvent(event);
|
|
185
|
+
}, [dispatchDragEvent]);
|
|
186
|
+
// Mouse Events
|
|
187
|
+
var handleMouseDown = React.useCallback(function (event) {
|
|
188
|
+
dispatchDragEvent(event);
|
|
189
|
+
}, [dispatchDragEvent]);
|
|
190
|
+
var handleMouseMove = React.useCallback(function (event) {
|
|
191
|
+
dispatchDragEvent(event);
|
|
192
|
+
}, [dispatchDragEvent]);
|
|
193
|
+
var handleMouseUp = React.useCallback(function (event) {
|
|
194
|
+
dispatchDragEvent(event);
|
|
195
|
+
}, [dispatchDragEvent]);
|
|
196
|
+
var handleContextMenu = React.useCallback(function (event) {
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
dispatchDragEvent(event);
|
|
199
|
+
}, [dispatchDragEvent]);
|
|
200
|
+
// Touch Events
|
|
201
|
+
var handleTouchStart = React.useCallback(function (event) {
|
|
202
|
+
event.preventDefault();
|
|
203
|
+
dispatchDragEvent(event);
|
|
204
|
+
}, [dispatchDragEvent]);
|
|
205
|
+
var handleTouchMove = React.useCallback(function (event) {
|
|
206
|
+
event.preventDefault();
|
|
207
|
+
dispatchDragEvent(event);
|
|
208
|
+
}, [dispatchDragEvent]);
|
|
209
|
+
var handleTouchEnd = React.useCallback(function (event) {
|
|
210
|
+
if (event.touches.length === 0 && event.changedTouches.length === 1) {
|
|
211
|
+
var currentWindow = getWindow();
|
|
212
|
+
ignoreMouse.current = true;
|
|
213
|
+
restoreMouseTimeout.current = currentWindow.setTimeout(function () { ignoreMouse.current = false; }, IGNORE_MOUSE_TIMEOUT);
|
|
214
|
+
}
|
|
215
|
+
dispatchDragEvent(event);
|
|
216
|
+
}, [dispatchDragEvent, getWindow]);
|
|
217
|
+
var handleScroll = React.useCallback(function (event) {
|
|
218
|
+
dispatchDragEvent(event);
|
|
219
|
+
}, [dispatchDragEvent]);
|
|
220
|
+
// Misc
|
|
221
|
+
var prerequisites = React.useCallback(function () {
|
|
222
|
+
var element = getElement();
|
|
223
|
+
if (element) {
|
|
224
|
+
var initialTouchAction_1 = element.style.touchAction;
|
|
225
|
+
element.style.touchAction = 'none';
|
|
226
|
+
return function () {
|
|
227
|
+
element.style.touchAction = initialTouchAction_1;
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}, [getElement]);
|
|
231
|
+
var register = React.useCallback(function () {
|
|
232
|
+
registerDrag(target);
|
|
233
|
+
return function () {
|
|
234
|
+
deregisterDrag(target);
|
|
235
|
+
};
|
|
236
|
+
}, [deregisterDrag, registerDrag]);
|
|
237
|
+
var init = function () {
|
|
238
|
+
var window = getWindow();
|
|
239
|
+
var element = getElement();
|
|
240
|
+
var document = getDocument();
|
|
241
|
+
if (pointers) {
|
|
242
|
+
if (element) {
|
|
243
|
+
var scrollable = kendo_draggable_common_1.getScrollableParent(element);
|
|
244
|
+
scrollable.addEventListener('scroll', handleScroll, { passive: true });
|
|
245
|
+
element.addEventListener('pointerdown', handlePointerDown, { passive: true });
|
|
246
|
+
}
|
|
247
|
+
if (pressed) {
|
|
248
|
+
document.addEventListener('pointermove', handlePointerMove);
|
|
249
|
+
document.addEventListener('pointerup', handlePointerUp, true);
|
|
250
|
+
document.addEventListener('contextmenu', handleContextMenu);
|
|
251
|
+
document.addEventListener('pointercancel', handlePointerCancel, { passive: true });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// Hacky-hacky iOS Safari
|
|
256
|
+
window.addEventListener('touchmove', noop_1.noop, { capture: false, passive: false });
|
|
257
|
+
if (element) {
|
|
258
|
+
element.addEventListener('mousedown', handleMouseDown, { passive: true });
|
|
259
|
+
if (!mouseOnly) {
|
|
260
|
+
element.addEventListener('touchstart', handleTouchStart, { passive: true });
|
|
261
|
+
if (pressed) {
|
|
262
|
+
element.addEventListener('touchmove', handleTouchMove, { passive: true });
|
|
263
|
+
element.addEventListener('touchend', handleTouchEnd, { passive: true });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (pressed) {
|
|
268
|
+
document.addEventListener('mousemove', handleMouseMove, { passive: true });
|
|
269
|
+
document.addEventListener('mouseup', handleMouseUp, { passive: true });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return function () {
|
|
273
|
+
if (element) {
|
|
274
|
+
var scrollable = kendo_draggable_common_1.getScrollableParent(element);
|
|
275
|
+
if (scrollable) {
|
|
276
|
+
scrollable.removeEventListener('scroll', handleScroll);
|
|
277
|
+
}
|
|
278
|
+
element.removeEventListener('pointerdown', handlePointerDown);
|
|
279
|
+
element.removeEventListener('mousedown', handleMouseDown);
|
|
280
|
+
element.removeEventListener('touchstart', handleTouchStart);
|
|
281
|
+
element.removeEventListener('touchmove', handleTouchMove);
|
|
282
|
+
element.removeEventListener('touchend', handleTouchEnd);
|
|
283
|
+
}
|
|
284
|
+
document.removeEventListener('pointermove', handlePointerMove);
|
|
285
|
+
document.removeEventListener('pointerup', handlePointerUp, true);
|
|
286
|
+
document.removeEventListener('contextmenu', handleContextMenu);
|
|
287
|
+
document.removeEventListener('pointercancel', handlePointerCancel);
|
|
288
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
289
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
290
|
+
window.removeEventListener('touchmove', noop_1.noop);
|
|
291
|
+
window.clearTimeout(restoreMouseTimeout.current);
|
|
292
|
+
};
|
|
27
293
|
};
|
|
28
|
-
React.useEffect(
|
|
29
|
-
|
|
294
|
+
React.useEffect(function () {
|
|
295
|
+
var window = getWindow();
|
|
296
|
+
if (scrolling) {
|
|
297
|
+
var scrollableParent_1 = getScrollContainer()
|
|
298
|
+
|| kendo_draggable_common_1.getScrollableParent(document.elementFromPoint(clientOffset.current.x, clientOffset.current.y));
|
|
299
|
+
window.clearInterval(scrollInterval.current);
|
|
300
|
+
scrollInterval.current = window.setInterval(function () {
|
|
301
|
+
kendo_draggable_common_1.autoScroll(scrollableParent_1, { x: velocity.current.x, y: velocity.current.y });
|
|
302
|
+
}, 50);
|
|
303
|
+
}
|
|
304
|
+
return function () {
|
|
305
|
+
window.clearInterval(scrollInterval.current);
|
|
306
|
+
};
|
|
307
|
+
}, [getElement, getScrollContainer, getWindow, scrolling]);
|
|
308
|
+
React.useEffect(prerequisites, [prerequisites]);
|
|
309
|
+
React.useEffect(init, [
|
|
310
|
+
pressed,
|
|
311
|
+
getWindow,
|
|
312
|
+
getElement,
|
|
313
|
+
getDocument,
|
|
314
|
+
mouseOnly,
|
|
315
|
+
pointers,
|
|
316
|
+
handleContextMenu,
|
|
317
|
+
handleMouseDown,
|
|
318
|
+
handleMouseMove,
|
|
319
|
+
handleMouseUp,
|
|
320
|
+
handlePointerCancel,
|
|
321
|
+
handlePointerDown,
|
|
322
|
+
handlePointerMove,
|
|
323
|
+
handlePointerUp,
|
|
324
|
+
handleTouchEnd,
|
|
325
|
+
handleTouchMove,
|
|
326
|
+
handleTouchStart,
|
|
327
|
+
handleScroll
|
|
328
|
+
]);
|
|
329
|
+
React.useEffect(function () {
|
|
330
|
+
return function () {
|
|
331
|
+
unmount.current = true;
|
|
332
|
+
};
|
|
333
|
+
}, []);
|
|
334
|
+
React.useLayoutEffect(register, [register]);
|
|
30
335
|
}
|
|
31
336
|
exports.useDraggable = useDraggable;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { NormalizedDragEvent } from '@progress/kendo-draggable-common';
|
|
3
|
+
/**
|
|
4
|
+
* Represents the `ref` object of the `Droppable` component.
|
|
5
|
+
*/
|
|
6
|
+
export interface DroppableHandle {
|
|
7
|
+
/**
|
|
8
|
+
* The element which is registered as droppable.
|
|
9
|
+
*/
|
|
10
|
+
element?: HTMLElement;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Represents the KendoReact `useDroppable` hook.
|
|
14
|
+
* Use it to attach `drop` events to a native HTML DOM elements, or custom React Components.
|
|
15
|
+
*
|
|
16
|
+
* For more information, refer to the [KendoReact Droppable]({% slug droppable_drag-and-drop %}) article.
|
|
17
|
+
*
|
|
18
|
+
* @param ref - The `ref` of the HTML Element or React Component which will enable the `droppable` functionality.
|
|
19
|
+
* @param callbacks - A collection of callbacks, called by the `useDroppable` hook when a specific action occurs.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useDroppable(ref: React.RefObject<HTMLElement | null | {
|
|
22
|
+
element: HTMLElement | null;
|
|
23
|
+
}>, callbacks?: {
|
|
24
|
+
onDragEnter?: (event: NormalizedDragEvent) => void;
|
|
25
|
+
onDragOver?: (event: NormalizedDragEvent) => void;
|
|
26
|
+
onDragLeave?: (event: NormalizedDragEvent) => void;
|
|
27
|
+
onDrop?: (event: NormalizedDragEvent) => void;
|
|
28
|
+
}): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var React = require("react");
|
|
4
|
+
var noop_1 = require("../noop");
|
|
5
|
+
var useInheritedState_1 = require("../hooks/useInheritedState");
|
|
6
|
+
var context_1 = require("../drag-n-drop/context");
|
|
7
|
+
/**
|
|
8
|
+
* Represents the KendoReact `useDroppable` hook.
|
|
9
|
+
* Use it to attach `drop` events to a native HTML DOM elements, or custom React Components.
|
|
10
|
+
*
|
|
11
|
+
* For more information, refer to the [KendoReact Droppable]({% slug droppable_drag-and-drop %}) article.
|
|
12
|
+
*
|
|
13
|
+
* @param ref - The `ref` of the HTML Element or React Component which will enable the `droppable` functionality.
|
|
14
|
+
* @param callbacks - A collection of callbacks, called by the `useDroppable` hook when a specific action occurs.
|
|
15
|
+
*/
|
|
16
|
+
function useDroppable(ref, callbacks) {
|
|
17
|
+
if (callbacks === void 0) { callbacks = {
|
|
18
|
+
onDragEnter: noop_1.noop,
|
|
19
|
+
onDragOver: noop_1.noop,
|
|
20
|
+
onDragLeave: noop_1.noop,
|
|
21
|
+
onDrop: noop_1.noop
|
|
22
|
+
}; }
|
|
23
|
+
var _a = callbacks.onDragEnter, onDragEnter = _a === void 0 ? noop_1.noop : _a, _b = callbacks.onDragOver, onDragOver = _b === void 0 ? noop_1.noop : _b, _c = callbacks.onDragLeave, onDragLeave = _c === void 0 ? noop_1.noop : _c, _d = callbacks.onDrop, onDrop = _d === void 0 ? noop_1.noop : _d;
|
|
24
|
+
var _e = useInheritedState_1.useInheritedState(context_1.DropContext), setDrop = _e[1];
|
|
25
|
+
var _f = React.useContext(context_1.DropsContext), registerDrop = _f[1], deregisterDrop = _f[2];
|
|
26
|
+
var getElement = React.useCallback(function () { return ref.current && ref.current.element
|
|
27
|
+
? ref.current.element
|
|
28
|
+
: ref.current; }, [ref]);
|
|
29
|
+
var target = React.useRef(null);
|
|
30
|
+
React.useImperativeHandle(target, function () { return ({
|
|
31
|
+
element: getElement(),
|
|
32
|
+
onDragEnter: handleDragEnter,
|
|
33
|
+
onDragOver: handleDragOver,
|
|
34
|
+
onDragLeave: handleDragLeave,
|
|
35
|
+
onDrop: handleDrop,
|
|
36
|
+
data: ref.current
|
|
37
|
+
}); });
|
|
38
|
+
var handleDragEnter = React.useCallback(function (event) {
|
|
39
|
+
setDrop(target, { target: ref.current, event: event });
|
|
40
|
+
onDragEnter(event);
|
|
41
|
+
}, [setDrop, ref, onDragEnter]);
|
|
42
|
+
var handleDragOver = React.useCallback(function (event) {
|
|
43
|
+
onDragOver(event);
|
|
44
|
+
}, [onDragOver]);
|
|
45
|
+
var handleDragLeave = React.useCallback(function (event) {
|
|
46
|
+
setDrop(null, { target: ref.current, event: event });
|
|
47
|
+
onDragLeave(event);
|
|
48
|
+
}, [setDrop, ref, onDragLeave]);
|
|
49
|
+
var handleDrop = React.useCallback(function (event) {
|
|
50
|
+
setDrop(null, { target: ref.current, event: event });
|
|
51
|
+
onDrop(event);
|
|
52
|
+
}, [setDrop, ref, onDrop]);
|
|
53
|
+
var register = React.useCallback(function () {
|
|
54
|
+
registerDrop(target);
|
|
55
|
+
return function () {
|
|
56
|
+
deregisterDrop(target);
|
|
57
|
+
};
|
|
58
|
+
}, [deregisterDrop, registerDrop]);
|
|
59
|
+
React.useLayoutEffect(register, [register]);
|
|
60
|
+
}
|
|
61
|
+
exports.useDroppable = useDroppable;
|
|
62
|
+
;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* @hidden
|
|
4
|
+
*/
|
|
5
|
+
interface Setter<T> extends Array<any> {
|
|
6
|
+
0?: T;
|
|
7
|
+
[index: number]: any;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @hidden
|
|
11
|
+
*/
|
|
12
|
+
export declare const useInheritedState: <T>(context: React.Context<[T, (...event: Setter<T>) => void]>, defaultValue?: any) => [T, (...event: Setter<T>) => void];
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var React = require("react");
|
|
4
|
+
/**
|
|
5
|
+
* @hidden
|
|
6
|
+
*/
|
|
7
|
+
exports.useInheritedState = function (context, defaultValue) {
|
|
8
|
+
var _a = React.useContext(context), contextValue = _a[0], contextSetter = _a[1];
|
|
9
|
+
var _b = React.useState(defaultValue), localValue = _b[0], localSetter = _b[1];
|
|
10
|
+
var value = contextValue !== undefined ? contextValue : localValue;
|
|
11
|
+
var handleValueChange = function () {
|
|
12
|
+
var args = [];
|
|
13
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
14
|
+
args[_i] = arguments[_i];
|
|
15
|
+
}
|
|
16
|
+
contextValue !== undefined
|
|
17
|
+
? contextSetter.apply(void 0, args) : localSetter(args[0]);
|
|
18
|
+
};
|
|
19
|
+
return [
|
|
20
|
+
value,
|
|
21
|
+
handleValueChange
|
|
22
|
+
];
|
|
23
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { KendoPointer } from '../models';
|
|
3
|
+
declare type ElementPointer = {
|
|
4
|
+
[P in keyof KendoPointer<any, any>]: (event: React.PointerEvent<any>) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* @hidden
|
|
8
|
+
*/
|
|
9
|
+
export declare const usePointer: <E extends HTMLElement, P extends KendoPointer<any, any>, R extends {}>(props: P, target: React.RefObject<R>, extend?: {
|
|
10
|
+
onPointerDown?: (args: React.PointerEvent<E>) => void;
|
|
11
|
+
onPointerMove?: (args: React.PointerEvent<E>) => void;
|
|
12
|
+
onPointerUp?: (args: React.PointerEvent<E>) => void;
|
|
13
|
+
onPointerCancel?: (args: React.PointerEvent<E>) => void;
|
|
14
|
+
onGotPointerCapture?: (args: React.PointerEvent<E>) => void;
|
|
15
|
+
onLostPointerCapture?: (args: React.PointerEvent<E>) => void;
|
|
16
|
+
onPointerEnter?: (args: React.PointerEvent<E>) => void;
|
|
17
|
+
onPointerOver?: (args: React.PointerEvent<E>) => void;
|
|
18
|
+
onPointerLeave?: (args: React.PointerEvent<E>) => void;
|
|
19
|
+
onPointerOut?: (args: React.PointerEvent<E>) => void;
|
|
20
|
+
}) => ElementPointer;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var React = require("react");
|
|
15
|
+
/**
|
|
16
|
+
* @hidden
|
|
17
|
+
*/
|
|
18
|
+
exports.usePointer = function (props, target, extend) {
|
|
19
|
+
if (extend === void 0) { extend = {}; }
|
|
20
|
+
return Object.keys(extend).reduce(function (acc, key) {
|
|
21
|
+
var _a;
|
|
22
|
+
return (__assign({}, acc, (_a = {}, _a[key] = React.useCallback(function (syntheticEvent) {
|
|
23
|
+
if (extend[key]) {
|
|
24
|
+
extend[key](syntheticEvent);
|
|
25
|
+
}
|
|
26
|
+
if (props[key]) {
|
|
27
|
+
props[key]({ target: target.current, syntheticEvent: syntheticEvent });
|
|
28
|
+
}
|
|
29
|
+
}, [props[key], extend[key], target]), _a)));
|
|
30
|
+
}, {});
|
|
31
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { KendoTouch } from '../models';
|
|
3
|
+
declare type ElementTouch = {
|
|
4
|
+
[P in keyof KendoTouch<any, any>]: (event: React.TouchEvent<any>) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* @hidden
|
|
8
|
+
*/
|
|
9
|
+
export declare const useMouse: <E extends HTMLElement, P extends KendoTouch<any, any>, R extends {}>(props: P, target: React.RefObject<R>, extend?: {
|
|
10
|
+
onTouchStart?: (args: React.TouchEvent<E>) => void;
|
|
11
|
+
onTouchMove?: (args: React.TouchEvent<E>) => void;
|
|
12
|
+
onTouchEnd?: (args: React.TouchEvent<E>) => void;
|
|
13
|
+
onTouchCancel?: (args: React.TouchEvent<E>) => void;
|
|
14
|
+
}) => ElementTouch;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var React = require("react");
|
|
15
|
+
/**
|
|
16
|
+
* @hidden
|
|
17
|
+
*/
|
|
18
|
+
exports.useMouse = function (props, target, extend) {
|
|
19
|
+
if (extend === void 0) { extend = {}; }
|
|
20
|
+
return Object.keys(extend).reduce(function (acc, key) {
|
|
21
|
+
var _a;
|
|
22
|
+
return (__assign({}, acc, (_a = {}, _a[key] = React.useCallback(function (syntheticEvent) {
|
|
23
|
+
if (extend[key]) {
|
|
24
|
+
extend[key](syntheticEvent);
|
|
25
|
+
}
|
|
26
|
+
if (props[key]) {
|
|
27
|
+
props[key]({ target: target.current, syntheticEvent: syntheticEvent });
|
|
28
|
+
}
|
|
29
|
+
}, [props[key], extend[key], target]), _a)));
|
|
30
|
+
}, {});
|
|
31
|
+
};
|
package/dist/npm/main.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export * from './canUseDOM';
|
|
|
3
3
|
export * from './canUseRef';
|
|
4
4
|
export * from './classNames';
|
|
5
5
|
export * from './clone';
|
|
6
|
-
export * from './Draggable';
|
|
7
6
|
export * from './focus';
|
|
8
7
|
export * from './FormComponent';
|
|
9
8
|
export * from './getTabIndex';
|
|
@@ -22,11 +21,11 @@ export * from './hocs/AsyncFocusBlur';
|
|
|
22
21
|
export * from './hocs/withPropsContext';
|
|
23
22
|
export * from './hooks/useDir';
|
|
24
23
|
export * from './hooks/useAsyncFocusBlur';
|
|
25
|
-
export * from './hooks/useDraggable';
|
|
26
24
|
export * from './hooks/useRtl';
|
|
27
25
|
export * from './hooks/useMouse';
|
|
28
26
|
export * from './hooks/useCustomComponent';
|
|
29
27
|
export * from './hooks/usePropsContext';
|
|
28
|
+
export * from './hooks/useCollection';
|
|
30
29
|
export * from './models';
|
|
31
30
|
export * from './icons/Icon';
|
|
32
31
|
export * from './icons/SvgIcon';
|
|
@@ -36,3 +35,8 @@ export * from './icons/models/theme-color';
|
|
|
36
35
|
export * from './typography/models/margin';
|
|
37
36
|
export * from './typography/TypographyProps';
|
|
38
37
|
export * from './typography/Typography';
|
|
38
|
+
export * from './drag-n-drop';
|
|
39
|
+
export * from './Draggable';
|
|
40
|
+
export * from './Droppable';
|
|
41
|
+
export * from './hooks/useDraggable';
|
|
42
|
+
export * from './hooks/useDroppable';
|
package/dist/npm/main.js
CHANGED
|
@@ -8,7 +8,6 @@ __export(require("./canUseDOM"));
|
|
|
8
8
|
__export(require("./canUseRef"));
|
|
9
9
|
__export(require("./classNames"));
|
|
10
10
|
__export(require("./clone"));
|
|
11
|
-
__export(require("./Draggable"));
|
|
12
11
|
__export(require("./focus"));
|
|
13
12
|
__export(require("./FormComponent"));
|
|
14
13
|
__export(require("./getTabIndex"));
|
|
@@ -26,11 +25,16 @@ __export(require("./hocs/AsyncFocusBlur"));
|
|
|
26
25
|
__export(require("./hocs/withPropsContext"));
|
|
27
26
|
__export(require("./hooks/useDir"));
|
|
28
27
|
__export(require("./hooks/useAsyncFocusBlur"));
|
|
29
|
-
__export(require("./hooks/useDraggable"));
|
|
30
28
|
__export(require("./hooks/useRtl"));
|
|
31
29
|
__export(require("./hooks/useMouse"));
|
|
32
30
|
__export(require("./hooks/useCustomComponent"));
|
|
33
31
|
__export(require("./hooks/usePropsContext"));
|
|
32
|
+
__export(require("./hooks/useCollection"));
|
|
34
33
|
__export(require("./icons/Icon"));
|
|
35
34
|
__export(require("./icons/SvgIcon"));
|
|
36
35
|
__export(require("./typography/Typography"));
|
|
36
|
+
__export(require("./drag-n-drop"));
|
|
37
|
+
__export(require("./Draggable"));
|
|
38
|
+
__export(require("./Droppable"));
|
|
39
|
+
__export(require("./hooks/useDraggable"));
|
|
40
|
+
__export(require("./hooks/useDroppable"));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Represents additional configuration options for the `autoScroll` options of the `useDraggable` hook and `Draggable` component.
|
|
4
|
+
*/
|
|
5
|
+
export interface AutoScrollOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Set to `false` to disable the `autoScroll` feature.
|
|
8
|
+
*/
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Allows the user to toggle `autoScroll` in a specific direction.
|
|
12
|
+
*/
|
|
13
|
+
direction?: {
|
|
14
|
+
horizontal: boolean;
|
|
15
|
+
vertical: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Overrides the calculated element used for boundary detection, used to calculate the `autoScroll` velocity.
|
|
19
|
+
*/
|
|
20
|
+
boundaryElementRef?: React.RefObject<HTMLElement | null | {
|
|
21
|
+
element: HTMLElement | null;
|
|
22
|
+
}> | null;
|
|
23
|
+
}
|