@progress/kendo-react-common 4.12.0 → 4.13.0-dev.202111290654

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.
Files changed (73) hide show
  1. package/dist/cdn/js/kendo-react-common.js +1 -1
  2. package/dist/es/Draggable.d.ts +50 -42
  3. package/dist/es/Draggable.js +78 -75
  4. package/dist/es/Droppable.d.ts +77 -0
  5. package/dist/es/Droppable.js +68 -0
  6. package/dist/es/drag-n-drop/context/index.d.ts +18 -0
  7. package/dist/es/drag-n-drop/context/index.js +24 -0
  8. package/dist/es/drag-n-drop/index.d.ts +21 -0
  9. package/dist/es/drag-n-drop/index.js +44 -0
  10. package/dist/es/hooks/index.d.ts +4 -0
  11. package/dist/es/hooks/index.js +4 -0
  12. package/dist/es/hooks/useCollection.d.ts +14 -0
  13. package/dist/es/hooks/useCollection.js +26 -0
  14. package/dist/es/hooks/useControlledState.d.ts +4 -0
  15. package/dist/es/hooks/useControlledState.js +23 -0
  16. package/dist/es/hooks/useDraggable.d.ts +62 -6
  17. package/dist/es/hooks/useDraggable.js +327 -22
  18. package/dist/es/hooks/useDroppable.d.ts +28 -0
  19. package/dist/es/hooks/useDroppable.js +59 -0
  20. package/dist/es/hooks/useInheritedState.d.ts +13 -0
  21. package/dist/es/hooks/useInheritedState.js +21 -0
  22. package/dist/es/hooks/usePointer.d.ts +21 -0
  23. package/dist/es/hooks/usePointer.js +29 -0
  24. package/dist/es/hooks/useTouch.d.ts +15 -0
  25. package/dist/es/hooks/useTouch.js +29 -0
  26. package/dist/es/main.d.ts +6 -2
  27. package/dist/es/main.js +6 -2
  28. package/dist/es/models/auto-scroll-options.d.ts +23 -0
  29. package/dist/es/models/auto-scroll-options.js +0 -0
  30. package/dist/es/models/index.d.ts +3 -0
  31. package/dist/es/models/kendo-component.d.ts +6 -0
  32. package/dist/es/models/kendo-component.js +0 -0
  33. package/dist/es/models/pointer.d.ts +23 -0
  34. package/dist/es/models/pointer.js +0 -0
  35. package/dist/es/models/touch.d.ts +17 -0
  36. package/dist/es/models/touch.js +0 -0
  37. package/dist/npm/Draggable.d.ts +50 -42
  38. package/dist/npm/Draggable.js +78 -75
  39. package/dist/npm/Droppable.d.ts +77 -0
  40. package/dist/npm/Droppable.js +70 -0
  41. package/dist/npm/drag-n-drop/context/index.d.ts +18 -0
  42. package/dist/npm/drag-n-drop/context/index.js +26 -0
  43. package/dist/npm/drag-n-drop/index.d.ts +21 -0
  44. package/dist/npm/drag-n-drop/index.js +46 -0
  45. package/dist/npm/hooks/index.d.ts +4 -0
  46. package/dist/npm/hooks/index.js +4 -0
  47. package/dist/npm/hooks/useCollection.d.ts +14 -0
  48. package/dist/npm/hooks/useCollection.js +28 -0
  49. package/dist/npm/hooks/useControlledState.d.ts +4 -0
  50. package/dist/npm/hooks/useControlledState.js +25 -0
  51. package/dist/npm/hooks/useDraggable.d.ts +62 -6
  52. package/dist/npm/hooks/useDraggable.js +327 -22
  53. package/dist/npm/hooks/useDroppable.d.ts +28 -0
  54. package/dist/npm/hooks/useDroppable.js +62 -0
  55. package/dist/npm/hooks/useInheritedState.d.ts +13 -0
  56. package/dist/npm/hooks/useInheritedState.js +23 -0
  57. package/dist/npm/hooks/usePointer.d.ts +21 -0
  58. package/dist/npm/hooks/usePointer.js +31 -0
  59. package/dist/npm/hooks/useTouch.d.ts +15 -0
  60. package/dist/npm/hooks/useTouch.js +31 -0
  61. package/dist/npm/main.d.ts +6 -2
  62. package/dist/npm/main.js +6 -2
  63. package/dist/npm/models/auto-scroll-options.d.ts +23 -0
  64. package/dist/npm/models/auto-scroll-options.js +2 -0
  65. package/dist/npm/models/index.d.ts +3 -0
  66. package/dist/npm/models/kendo-component.d.ts +6 -0
  67. package/dist/npm/models/kendo-component.js +2 -0
  68. package/dist/npm/models/pointer.d.ts +23 -0
  69. package/dist/npm/models/pointer.js +2 -0
  70. package/dist/npm/models/touch.d.ts +17 -0
  71. package/dist/npm/models/touch.js +2 -0
  72. package/dist/systemjs/kendo-react-common.js +1 -1
  73. package/package.json +11 -8
@@ -0,0 +1,24 @@
1
+ import * as React from 'react';
2
+ import { noop } from '../../noop';
3
+ /**
4
+ * @hidden
5
+ */
6
+ export var DragContext = React.createContext([
7
+ undefined,
8
+ noop
9
+ ]);
10
+ /**
11
+ * @hidden
12
+ */
13
+ export var DropContext = React.createContext([
14
+ undefined,
15
+ noop
16
+ ]);
17
+ /**
18
+ * @hidden
19
+ */
20
+ export var DragsContext = React.createContext([[], noop, noop]);
21
+ /**
22
+ * @hidden
23
+ */
24
+ export var DropsContext = React.createContext([[], noop, noop]);
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ export { NormalizedDragEvent } from '@progress/kendo-draggable-common';
3
+ /**
4
+ * Represents the properties of the `DragAndDrop` component.
5
+ */
6
+ export interface DragAndDropProps {
7
+ /**
8
+ * Represents the `children` of the `DragAndDrop` component. The `children` prop can be any valid React Element.
9
+ */
10
+ children?: React.ReactNode;
11
+ }
12
+ /**
13
+ * The `DragAndDrop` component is required for the `droppable` functionality to work properly.
14
+ *
15
+ * It is used internally to synchronize the `drag` and `drop` functionalities.
16
+ * Accepts properties of type [DragAndDropProps]({% slug api_common_draganddropprops %}).
17
+ */
18
+ export declare const DragAndDrop: {
19
+ (props: DragAndDropProps): JSX.Element;
20
+ displayName: string;
21
+ };
@@ -0,0 +1,44 @@
1
+ import * as React from 'react';
2
+ import { useCollection, COLLECTION_ACTION, useControlledState } from '../hooks';
3
+ import { DragContext, DropContext, DragsContext, DropsContext } from './context';
4
+ /**
5
+ * The `DragAndDrop` component is required for the `droppable` functionality to work properly.
6
+ *
7
+ * It is used internally to synchronize the `drag` and `drop` functionalities.
8
+ * Accepts properties of type [DragAndDropProps]({% slug api_common_draganddropprops %}).
9
+ */
10
+ export var DragAndDrop = function (props) {
11
+ var _a = useControlledState(null, undefined), drag = _a[0], setDrag = _a[1];
12
+ var _b = useControlledState(null, undefined), drop = _b[0], setDrop = _b[1];
13
+ var _c = useCollection([]), drags = _c[0], dispatchDrags = _c[1];
14
+ var _d = useCollection([]), drops = _d[0], dispatchDrops = _d[1];
15
+ var registerDrag = function (item) {
16
+ dispatchDrags({
17
+ type: COLLECTION_ACTION.add,
18
+ item: item
19
+ });
20
+ };
21
+ var deregisterDrag = function (item) {
22
+ dispatchDrags({
23
+ type: COLLECTION_ACTION.remove,
24
+ item: item
25
+ });
26
+ };
27
+ var registerDrop = function (item) {
28
+ dispatchDrops({
29
+ type: COLLECTION_ACTION.add,
30
+ item: item
31
+ });
32
+ };
33
+ var deregisterDrop = function (item) {
34
+ dispatchDrops({
35
+ type: COLLECTION_ACTION.remove,
36
+ item: item
37
+ });
38
+ };
39
+ return (React.createElement(DragContext.Provider, { value: [drag, setDrag] },
40
+ React.createElement(DropContext.Provider, { value: [drop, setDrop] },
41
+ React.createElement(DragsContext.Provider, { value: [drags, registerDrag, deregisterDrag] },
42
+ React.createElement(DropsContext.Provider, { value: [drops, registerDrop, deregisterDrop] }, props.children)))));
43
+ };
44
+ DragAndDrop.displayName = 'KendoReactDragAndDrop';
@@ -2,5 +2,9 @@ export * from './useMouse';
2
2
  export * from './useAsyncFocusBlur';
3
3
  export * from './useDir';
4
4
  export * from './useDraggable';
5
+ export * from './useDroppable';
5
6
  export * from './useRtl';
6
7
  export * from './useCustomComponent';
8
+ export * from './useControlledState';
9
+ export * from './useInheritedState';
10
+ export * from './useCollection';
@@ -2,5 +2,9 @@ export * from './useMouse';
2
2
  export * from './useAsyncFocusBlur';
3
3
  export * from './useDir';
4
4
  export * from './useDraggable';
5
+ export * from './useDroppable';
5
6
  export * from './useRtl';
6
7
  export * from './useCustomComponent';
8
+ export * from './useControlledState';
9
+ export * from './useInheritedState';
10
+ export * from './useCollection';
@@ -0,0 +1,14 @@
1
+ /** @hidden */
2
+ export declare enum COLLECTION_ACTION {
3
+ add = 0,
4
+ remove = 1
5
+ }
6
+ /** @hidden */
7
+ export declare type Collection<T> = T[];
8
+ /** @hidden */
9
+ export interface CollectionAction<T> {
10
+ type: COLLECTION_ACTION;
11
+ item: T;
12
+ }
13
+ /** @hidden */
14
+ export declare const useCollection: <T extends any>(initial?: T[]) => [T[], (event: CollectionAction<T>) => void];
@@ -0,0 +1,26 @@
1
+ import * as React from 'react';
2
+ /** @hidden */
3
+ export var COLLECTION_ACTION;
4
+ (function (COLLECTION_ACTION) {
5
+ COLLECTION_ACTION[COLLECTION_ACTION["add"] = 0] = "add";
6
+ COLLECTION_ACTION[COLLECTION_ACTION["remove"] = 1] = "remove";
7
+ })(COLLECTION_ACTION || (COLLECTION_ACTION = {}));
8
+ /** @hidden */
9
+ export var useCollection = function (initial) {
10
+ if (initial === void 0) { initial = []; }
11
+ var collection = React.useRef(initial);
12
+ var handleCollectionAction = React.useCallback(function (action) {
13
+ switch (action.type) {
14
+ case COLLECTION_ACTION.add:
15
+ collection.current.push(action.item);
16
+ break;
17
+ case COLLECTION_ACTION.remove:
18
+ var index = collection.current.indexOf(action.item);
19
+ collection.current.splice(index, 1);
20
+ break;
21
+ default:
22
+ break;
23
+ }
24
+ }, []);
25
+ return [collection.current, handleCollectionAction];
26
+ };
@@ -0,0 +1,4 @@
1
+ /** @hidden */
2
+ export declare type ControlledStateHook<T, A = any> = [T, (value: T, args?: A) => void];
3
+ /** @hidden */
4
+ export declare const useControlledState: <T = any, A = any>(defaultProp: T, prop?: T, callback?: any) => [T, (value: T, args?: any) => void];
@@ -0,0 +1,23 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import * as React from 'react';
13
+ /** @hidden */
14
+ export var useControlledState = function (defaultProp, prop, callback) {
15
+ var _a = React.useState(prop || defaultProp), state = _a[0], setState = _a[1];
16
+ var handleSetEdit = React.useCallback(function (value, args) {
17
+ setState(value);
18
+ if (callback) {
19
+ callback.call(undefined, __assign({}, args, { value: value }));
20
+ }
21
+ }, [callback, setState]);
22
+ return [prop !== undefined ? prop : state, handleSetEdit];
23
+ };
@@ -1,7 +1,63 @@
1
1
  import * as React from 'react';
2
- /** @hidden */
3
- export declare function useDraggable(ref: React.RefObject<HTMLDivElement | HTMLSpanElement | null>, { onPress, onDrag, onRelease }: {
4
- onPress?: Function;
5
- onDrag?: Function;
6
- onRelease?: Function;
7
- }): void;
2
+ import { NormalizedDragEvent } from '@progress/kendo-draggable-common';
3
+ import { AutoScrollOptions } from '../models';
4
+ /**
5
+ * Represents the `ref` object of the `Draggable` component.
6
+ */
7
+ export interface DraggableHandle {
8
+ /**
9
+ * The element which is being dragged.
10
+ */
11
+ element: HTMLElement | null;
12
+ }
13
+ /**
14
+ * Represents the configuration object type of the `Draggable` component and `useDraggable` hook.
15
+ */
16
+ export interface DraggableOptions {
17
+ /**
18
+ * Set the `hint` to override the element used for collision detection.
19
+ *
20
+ * For more information, refer to the [Drag Hint]({% slug drag-hint_drag-and-drop %}) article.
21
+ */
22
+ hint?: React.RefObject<HTMLElement | null | {
23
+ element: HTMLElement | null;
24
+ }> | null;
25
+ /**
26
+ * Set the `mouseOnly` property to `true` to stop the draggable from attaching `touch` event handlers.
27
+ *
28
+ * Defaults to `false`.
29
+ */
30
+ mouseOnly?: boolean;
31
+ /**
32
+ * Set the `autoScroll` property to `false` to disable automatic container scroll when close to the edge.
33
+ * For more information, refer to the [Auto Scroll]({% slug auto-scroll_drag-and-drop %}) article.
34
+ *
35
+ * Defaults to `true`.
36
+ */
37
+ autoScroll?: boolean | AutoScrollOptions;
38
+ /**
39
+ * @hidden
40
+ */
41
+ scrollContainer?: React.RefObject<HTMLElement | null | {
42
+ element: HTMLElement | null;
43
+ }>;
44
+ }
45
+ /**
46
+ * Represents the KendoReact `useDraggable` hook.
47
+ * Use it to attach `drag` events to a native HTML DOM elements, or custom React Components.
48
+ *
49
+ * For more information, refer to the [KendoReact Draggable]({% slug draggable_drag-and-drop %}) article.
50
+ *
51
+ * @param ref - The `ref` of the HTML Element or React Component which will enable the `draggable` functionality.
52
+ * @param callbacks - A collection of callbacks, called by the `useDraggable` hook when a specific action occurs.
53
+ * @param options - Additional configuration of the `useDraggable` hook.
54
+ */
55
+ export declare function useDraggable(ref: React.RefObject<HTMLElement | null | {
56
+ element: HTMLElement | null;
57
+ }>, callbacks: {
58
+ onPress?: (event: NormalizedDragEvent) => void;
59
+ onRelease?: (event: NormalizedDragEvent) => void;
60
+ onDragStart?: (event: NormalizedDragEvent) => void;
61
+ onDrag?: (event: NormalizedDragEvent) => void;
62
+ onDragEnd?: (event: NormalizedDragEvent) => void;
63
+ }, options?: DraggableOptions): void;
@@ -1,28 +1,333 @@
1
1
  import * as React from 'react';
2
- import Draggable from '@telerik/kendo-draggable';
3
- /** @hidden */
4
- export function useDraggable(ref, _a) {
5
- var onPress = _a.onPress, onDrag = _a.onDrag, onRelease = _a.onRelease;
6
- var draggable = React.useMemo(function () { return new Draggable({
7
- press: onPress,
8
- drag: onDrag,
9
- release: onRelease
10
- }); }, []);
11
- var initDraggable = function () {
12
- var element = ref.current;
13
- if (!element) {
2
+ import { dispatchDragAndDrop, autoScroll as autoScrollElement, getScrollableParent } from '@progress/kendo-draggable-common';
3
+ import { noop } from '../noop';
4
+ import { useInheritedState } from '../hooks/useInheritedState';
5
+ import { DragContext, DropContext, DragsContext, DropsContext } from '../drag-n-drop/context';
6
+ var IGNORE_MOUSE_TIMEOUT = 2000;
7
+ /**
8
+ * Represents the KendoReact `useDraggable` hook.
9
+ * Use it to attach `drag` events to a native HTML DOM elements, or custom React Components.
10
+ *
11
+ * For more information, refer to the [KendoReact Draggable]({% slug draggable_drag-and-drop %}) article.
12
+ *
13
+ * @param ref - The `ref` of the HTML Element or React Component which will enable the `draggable` functionality.
14
+ * @param callbacks - A collection of callbacks, called by the `useDraggable` hook when a specific action occurs.
15
+ * @param options - Additional configuration of the `useDraggable` hook.
16
+ */
17
+ export function useDraggable(ref, callbacks, options) {
18
+ if (options === void 0) { options = {}; }
19
+ var _a = callbacks.onPress, onPress = _a === void 0 ? noop : _a, _b = callbacks.onRelease, onRelease = _b === void 0 ? noop : _b, _c = callbacks.onDragStart, onDragStart = _c === void 0 ? noop : _c, _d = callbacks.onDrag, onDrag = _d === void 0 ? noop : _d, _e = callbacks.onDragEnd, onDragEnd = _e === void 0 ? noop : _e;
20
+ 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;
21
+ var _k = React.useState(false), pressed = _k[0], setPressed = _k[1];
22
+ var _l = React.useState(false), scrolling = _l[0], setScrolling = _l[1];
23
+ var drop = useInheritedState(DropContext)[0];
24
+ var _m = useInheritedState(DragContext), drag = _m[0], setDrag = _m[1];
25
+ var drops = React.useContext(DropsContext)[0];
26
+ var _o = React.useContext(DragsContext), drags = _o[0], registerDrag = _o[1], deregisterDrag = _o[2];
27
+ var velocity = React.useRef({ x: 0, y: 0 });
28
+ var scrollInterval = React.useRef();
29
+ var ignoreMouse = React.useRef(false);
30
+ var restoreMouseTimeout = React.useRef();
31
+ var unmount = React.useRef(false);
32
+ var offset = React.useRef({ x: 0, y: 0 });
33
+ var pageOffset = React.useRef({ x: 0, y: 0 });
34
+ var clientOffset = React.useRef({ x: 0, y: 0 });
35
+ var initialClientOffset = React.useRef({ x: 0, y: 0 });
36
+ var scrollOffset = React.useRef({ x: 0, y: 0 });
37
+ var initialScrollOffset = React.useRef({ x: 0, y: 0 });
38
+ var supportPointerEvent = Boolean(window && (typeof window !== 'undefined') && window.PointerEvent);
39
+ var pointers = !mouseOnly && supportPointerEvent;
40
+ var getElement = React.useCallback(function () { return ref.current && ref.current.element
41
+ ? ref.current.element
42
+ : ref.current; }, [ref]);
43
+ var getHintElement = React.useCallback(function () { return hint && hint.current && hint.current.element
44
+ ? hint.current.element
45
+ : hint
46
+ ? hint.current
47
+ : null; }, [hint]);
48
+ var getScrollContainer = React.useCallback(function () { return scrollContainer && scrollContainer.current && scrollContainer.current.element
49
+ ? scrollContainer.current.element
50
+ : scrollContainer
51
+ ? scrollContainer.current
52
+ : null; }, [scrollContainer]);
53
+ var getAutoScrollContainer = React.useCallback(function () { return typeof autoScroll === 'object' && autoScroll.boundaryElementRef
54
+ && autoScroll.boundaryElementRef.current && autoScroll.boundaryElementRef.current.element
55
+ ? autoScroll.boundaryElementRef.current.element
56
+ : typeof autoScroll === 'object' && autoScroll.boundaryElementRef && autoScroll.boundaryElementRef.current
57
+ ? autoScroll.boundaryElementRef.current
58
+ : null; }, [autoScroll]);
59
+ var target = React.useRef(null);
60
+ React.useImperativeHandle(target, function () { return ({
61
+ element: getElement(),
62
+ hint: getHintElement(),
63
+ onPress: handlePress,
64
+ onDragStart: handleDragStart,
65
+ onDrag: handleDrag,
66
+ onDragEnd: handleDragEnd,
67
+ onRelease: handleRelease,
68
+ data: ref.current
69
+ }); });
70
+ var getDocument = React.useCallback(function () {
71
+ var element = getElement();
72
+ return element ? element.ownerDocument || document : document;
73
+ }, [getElement]);
74
+ var getWindow = React.useCallback(function () {
75
+ var document = getDocument();
76
+ return document
77
+ ? document.defaultView || window
78
+ : window;
79
+ }, [getDocument]);
80
+ var getState = React.useCallback(function () { return ({
81
+ drag: drag ? drag.current : null,
82
+ drop: drop ? drop.current : null,
83
+ drags: drags.map(function (d) { return d.current; }),
84
+ drops: drops.map(function (d) { return d.current; }),
85
+ pressed: pressed,
86
+ ignoreMouse: ignoreMouse.current,
87
+ scrollOffset: scrollOffset.current,
88
+ offset: offset.current,
89
+ pageOffset: pageOffset.current,
90
+ initialScrollOffset: initialScrollOffset.current,
91
+ clientOffset: clientOffset.current,
92
+ initialClientOffset: initialClientOffset.current,
93
+ velocity: velocity.current,
94
+ autoScroll: Boolean(typeof autoScroll === 'object' ? autoScroll.enabled !== false : autoScroll),
95
+ scrollableParent: getAutoScrollContainer(),
96
+ autoScrollDirection: typeof autoScroll === 'object' ? autoScroll.direction : { horizontal: true, vertical: true },
97
+ isScrolling: scrolling
98
+ }); }, [drag, drop, drags, drops, pressed, autoScroll, getAutoScrollContainer, scrolling]);
99
+ var handlePressedChange = React.useCallback(function (value) {
100
+ setPressed(value);
101
+ }, []);
102
+ var handleScrollingChange = React.useCallback(function (value) {
103
+ setScrolling(value);
104
+ }, []);
105
+ var handleVelocityChange = React.useCallback(function (value) {
106
+ velocity.current = value;
107
+ }, []);
108
+ var handleOffsetChange = React.useCallback(function (value) {
109
+ offset.current = value;
110
+ }, []);
111
+ var handleClientOffsetChange = React.useCallback(function (value) {
112
+ clientOffset.current = value;
113
+ }, []);
114
+ var handlePageOffsetChange = React.useCallback(function (value) {
115
+ pageOffset.current = value;
116
+ }, []);
117
+ var handleInitialClientOffsetChange = React.useCallback(function (value) {
118
+ initialClientOffset.current = value;
119
+ }, []);
120
+ var handleScrollOffsetChange = React.useCallback(function (value) {
121
+ scrollOffset.current = value;
122
+ }, []);
123
+ var handleInitialScrollOffsetChange = React.useCallback(function (value) {
124
+ initialScrollOffset.current = value;
125
+ }, []);
126
+ // Drag Events
127
+ var handlePress = React.useCallback(function (event) {
128
+ onPress(event);
129
+ }, [onPress]);
130
+ var handleRelease = React.useCallback(function (event) {
131
+ onRelease(event);
132
+ }, [onRelease]);
133
+ var handleDragStart = React.useCallback(function (event) {
134
+ setDrag(target, { target: ref.current, event: event });
135
+ onDragStart(event);
136
+ }, [setDrag, ref, onDragStart]);
137
+ var handleDrag = React.useCallback(function (event) {
138
+ onDrag(event);
139
+ }, [onDrag]);
140
+ var handleDragEnd = React.useCallback(function (event) {
141
+ if (unmount.current) {
14
142
  return;
15
143
  }
16
- draggable.bindTo(element);
17
- return function () { draggable.destroy(); };
18
- };
19
- var updateDraggable = function () {
20
- draggable.update({
21
- press: onPress,
22
- drag: onDrag,
23
- release: onRelease
144
+ setDrag(null, { target: ref.current, event: event });
145
+ onDragEnd(event);
146
+ }, [onDragEnd, setDrag, ref]);
147
+ var dispatchDragEvent = React.useCallback(function (event) {
148
+ dispatchDragAndDrop(getState(), { event: event, payload: target.current }, {
149
+ onVelocityChange: handleVelocityChange,
150
+ onOffsetChange: handleOffsetChange,
151
+ onClientOffsetChange: handleClientOffsetChange,
152
+ onPageOffsetChange: handlePageOffsetChange,
153
+ onInitialClientOffsetChange: handleInitialClientOffsetChange,
154
+ onScrollOffsetChange: handleScrollOffsetChange,
155
+ onInitialScrollOffsetChange: handleInitialScrollOffsetChange,
156
+ onIsPressedChange: handlePressedChange,
157
+ onIsScrollingChange: handleScrollingChange
24
158
  });
159
+ }, [
160
+ getState,
161
+ handleVelocityChange,
162
+ handleOffsetChange,
163
+ handlePageOffsetChange,
164
+ handleClientOffsetChange,
165
+ handleInitialClientOffsetChange,
166
+ handleInitialScrollOffsetChange,
167
+ handlePressedChange,
168
+ handleScrollOffsetChange,
169
+ handleScrollingChange
170
+ ]);
171
+ // Pointer Events
172
+ var handlePointerDown = React.useCallback(function (event) {
173
+ dispatchDragEvent(event);
174
+ }, [dispatchDragEvent]);
175
+ var handlePointerMove = React.useCallback(function (event) {
176
+ dispatchDragEvent(event);
177
+ }, [dispatchDragEvent]);
178
+ var handlePointerCancel = React.useCallback(function (event) {
179
+ dispatchDragEvent(event);
180
+ }, [dispatchDragEvent]);
181
+ var handlePointerUp = React.useCallback(function (event) {
182
+ dispatchDragEvent(event);
183
+ }, [dispatchDragEvent]);
184
+ // Mouse Events
185
+ var handleMouseDown = React.useCallback(function (event) {
186
+ dispatchDragEvent(event);
187
+ }, [dispatchDragEvent]);
188
+ var handleMouseMove = React.useCallback(function (event) {
189
+ dispatchDragEvent(event);
190
+ }, [dispatchDragEvent]);
191
+ var handleMouseUp = React.useCallback(function (event) {
192
+ dispatchDragEvent(event);
193
+ }, [dispatchDragEvent]);
194
+ var handleContextMenu = React.useCallback(function (event) {
195
+ event.preventDefault();
196
+ dispatchDragEvent(event);
197
+ }, [dispatchDragEvent]);
198
+ // Touch Events
199
+ var handleTouchStart = React.useCallback(function (event) {
200
+ event.preventDefault();
201
+ dispatchDragEvent(event);
202
+ }, [dispatchDragEvent]);
203
+ var handleTouchMove = React.useCallback(function (event) {
204
+ event.preventDefault();
205
+ dispatchDragEvent(event);
206
+ }, [dispatchDragEvent]);
207
+ var handleTouchEnd = React.useCallback(function (event) {
208
+ if (event.touches.length === 0 && event.changedTouches.length === 1) {
209
+ var currentWindow = getWindow();
210
+ ignoreMouse.current = true;
211
+ restoreMouseTimeout.current = currentWindow.setTimeout(function () { ignoreMouse.current = false; }, IGNORE_MOUSE_TIMEOUT);
212
+ }
213
+ dispatchDragEvent(event);
214
+ }, [dispatchDragEvent, getWindow]);
215
+ var handleScroll = React.useCallback(function (event) {
216
+ dispatchDragEvent(event);
217
+ }, [dispatchDragEvent]);
218
+ // Misc
219
+ var prerequisites = React.useCallback(function () {
220
+ var element = getElement();
221
+ if (element) {
222
+ var initialTouchAction_1 = element.style.touchAction;
223
+ element.style.touchAction = 'none';
224
+ return function () {
225
+ element.style.touchAction = initialTouchAction_1;
226
+ };
227
+ }
228
+ }, [getElement]);
229
+ var register = React.useCallback(function () {
230
+ registerDrag(target);
231
+ return function () {
232
+ deregisterDrag(target);
233
+ };
234
+ }, [deregisterDrag, registerDrag]);
235
+ var init = function () {
236
+ var window = getWindow();
237
+ var element = getElement();
238
+ var document = getDocument();
239
+ if (pointers) {
240
+ if (element) {
241
+ var scrollable = getScrollableParent(element);
242
+ scrollable.addEventListener('scroll', handleScroll, { passive: true });
243
+ element.addEventListener('pointerdown', handlePointerDown, { passive: true });
244
+ }
245
+ if (pressed) {
246
+ document.addEventListener('pointermove', handlePointerMove);
247
+ document.addEventListener('pointerup', handlePointerUp, true);
248
+ document.addEventListener('contextmenu', handleContextMenu);
249
+ document.addEventListener('pointercancel', handlePointerCancel, { passive: true });
250
+ }
251
+ }
252
+ else {
253
+ // Hacky-hacky iOS Safari
254
+ window.addEventListener('touchmove', noop, { capture: false, passive: false });
255
+ if (element) {
256
+ element.addEventListener('mousedown', handleMouseDown, { passive: true });
257
+ if (!mouseOnly) {
258
+ element.addEventListener('touchstart', handleTouchStart, { passive: true });
259
+ if (pressed) {
260
+ element.addEventListener('touchmove', handleTouchMove, { passive: true });
261
+ element.addEventListener('touchend', handleTouchEnd, { passive: true });
262
+ }
263
+ }
264
+ }
265
+ if (pressed) {
266
+ document.addEventListener('mousemove', handleMouseMove, { passive: true });
267
+ document.addEventListener('mouseup', handleMouseUp, { passive: true });
268
+ }
269
+ }
270
+ return function () {
271
+ if (element) {
272
+ var scrollable = getScrollableParent(element);
273
+ if (scrollable) {
274
+ scrollable.removeEventListener('scroll', handleScroll);
275
+ }
276
+ element.removeEventListener('pointerdown', handlePointerDown);
277
+ element.removeEventListener('mousedown', handleMouseDown);
278
+ element.removeEventListener('touchstart', handleTouchStart);
279
+ element.removeEventListener('touchmove', handleTouchMove);
280
+ element.removeEventListener('touchend', handleTouchEnd);
281
+ }
282
+ document.removeEventListener('pointermove', handlePointerMove);
283
+ document.removeEventListener('pointerup', handlePointerUp, true);
284
+ document.removeEventListener('contextmenu', handleContextMenu);
285
+ document.removeEventListener('pointercancel', handlePointerCancel);
286
+ document.removeEventListener('mousemove', handleMouseMove);
287
+ document.removeEventListener('mouseup', handleMouseUp);
288
+ window.removeEventListener('touchmove', noop);
289
+ window.clearTimeout(restoreMouseTimeout.current);
290
+ };
25
291
  };
26
- React.useEffect(initDraggable, []);
27
- React.useEffect(updateDraggable, [onPress, onDrag, onRelease]);
292
+ React.useEffect(function () {
293
+ var window = getWindow();
294
+ if (scrolling) {
295
+ var scrollableParent_1 = getScrollContainer()
296
+ || getScrollableParent(document.elementFromPoint(clientOffset.current.x, clientOffset.current.y));
297
+ window.clearInterval(scrollInterval.current);
298
+ scrollInterval.current = window.setInterval(function () {
299
+ autoScrollElement(scrollableParent_1, { x: velocity.current.x, y: velocity.current.y });
300
+ }, 50);
301
+ }
302
+ return function () {
303
+ window.clearInterval(scrollInterval.current);
304
+ };
305
+ }, [getElement, getScrollContainer, getWindow, scrolling]);
306
+ React.useEffect(prerequisites, [prerequisites]);
307
+ React.useEffect(init, [
308
+ pressed,
309
+ getWindow,
310
+ getElement,
311
+ getDocument,
312
+ mouseOnly,
313
+ pointers,
314
+ handleContextMenu,
315
+ handleMouseDown,
316
+ handleMouseMove,
317
+ handleMouseUp,
318
+ handlePointerCancel,
319
+ handlePointerDown,
320
+ handlePointerMove,
321
+ handlePointerUp,
322
+ handleTouchEnd,
323
+ handleTouchMove,
324
+ handleTouchStart,
325
+ handleScroll
326
+ ]);
327
+ React.useEffect(function () {
328
+ return function () {
329
+ unmount.current = true;
330
+ };
331
+ }, []);
332
+ React.useLayoutEffect(register, [register]);
28
333
  }
@@ -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;