@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,59 @@
1
+ import * as React from 'react';
2
+ import { noop } from '../noop';
3
+ import { useInheritedState } from '../hooks/useInheritedState';
4
+ import { DropContext, DropsContext } from '../drag-n-drop/context';
5
+ /**
6
+ * Represents the KendoReact `useDroppable` hook.
7
+ * Use it to attach `drop` events to a native HTML DOM elements, or custom React Components.
8
+ *
9
+ * For more information, refer to the [KendoReact Droppable]({% slug droppable_drag-and-drop %}) article.
10
+ *
11
+ * @param ref - The `ref` of the HTML Element or React Component which will enable the `droppable` functionality.
12
+ * @param callbacks - A collection of callbacks, called by the `useDroppable` hook when a specific action occurs.
13
+ */
14
+ export function useDroppable(ref, callbacks) {
15
+ if (callbacks === void 0) { callbacks = {
16
+ onDragEnter: noop,
17
+ onDragOver: noop,
18
+ onDragLeave: noop,
19
+ onDrop: noop
20
+ }; }
21
+ var _a = callbacks.onDragEnter, onDragEnter = _a === void 0 ? noop : _a, _b = callbacks.onDragOver, onDragOver = _b === void 0 ? noop : _b, _c = callbacks.onDragLeave, onDragLeave = _c === void 0 ? noop : _c, _d = callbacks.onDrop, onDrop = _d === void 0 ? noop : _d;
22
+ var _e = useInheritedState(DropContext), setDrop = _e[1];
23
+ var _f = React.useContext(DropsContext), registerDrop = _f[1], deregisterDrop = _f[2];
24
+ var getElement = React.useCallback(function () { return ref.current && ref.current.element
25
+ ? ref.current.element
26
+ : ref.current; }, [ref]);
27
+ var target = React.useRef(null);
28
+ React.useImperativeHandle(target, function () { return ({
29
+ element: getElement(),
30
+ onDragEnter: handleDragEnter,
31
+ onDragOver: handleDragOver,
32
+ onDragLeave: handleDragLeave,
33
+ onDrop: handleDrop,
34
+ data: ref.current
35
+ }); });
36
+ var handleDragEnter = React.useCallback(function (event) {
37
+ setDrop(target, { target: ref.current, event: event });
38
+ onDragEnter(event);
39
+ }, [setDrop, ref, onDragEnter]);
40
+ var handleDragOver = React.useCallback(function (event) {
41
+ onDragOver(event);
42
+ }, [onDragOver]);
43
+ var handleDragLeave = React.useCallback(function (event) {
44
+ setDrop(null, { target: ref.current, event: event });
45
+ onDragLeave(event);
46
+ }, [setDrop, ref, onDragLeave]);
47
+ var handleDrop = React.useCallback(function (event) {
48
+ setDrop(null, { target: ref.current, event: event });
49
+ onDrop(event);
50
+ }, [setDrop, ref, onDrop]);
51
+ var register = React.useCallback(function () {
52
+ registerDrop(target);
53
+ return function () {
54
+ deregisterDrop(target);
55
+ };
56
+ }, [deregisterDrop, registerDrop]);
57
+ React.useLayoutEffect(register, [register]);
58
+ }
59
+ ;
@@ -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,21 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @hidden
4
+ */
5
+ export var useInheritedState = function (context, defaultValue) {
6
+ var _a = React.useContext(context), contextValue = _a[0], contextSetter = _a[1];
7
+ var _b = React.useState(defaultValue), localValue = _b[0], localSetter = _b[1];
8
+ var value = contextValue !== undefined ? contextValue : localValue;
9
+ var handleValueChange = function () {
10
+ var args = [];
11
+ for (var _i = 0; _i < arguments.length; _i++) {
12
+ args[_i] = arguments[_i];
13
+ }
14
+ contextValue !== undefined
15
+ ? contextSetter.apply(void 0, args) : localSetter(args[0]);
16
+ };
17
+ return [
18
+ value,
19
+ handleValueChange
20
+ ];
21
+ };
@@ -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,29 @@
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
+ /**
14
+ * @hidden
15
+ */
16
+ export var usePointer = function (props, target, extend) {
17
+ if (extend === void 0) { extend = {}; }
18
+ return Object.keys(extend).reduce(function (acc, key) {
19
+ var _a;
20
+ return (__assign({}, acc, (_a = {}, _a[key] = React.useCallback(function (syntheticEvent) {
21
+ if (extend[key]) {
22
+ extend[key](syntheticEvent);
23
+ }
24
+ if (props[key]) {
25
+ props[key]({ target: target.current, syntheticEvent: syntheticEvent });
26
+ }
27
+ }, [props[key], extend[key], target]), _a)));
28
+ }, {});
29
+ };
@@ -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,29 @@
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
+ /**
14
+ * @hidden
15
+ */
16
+ export var useMouse = function (props, target, extend) {
17
+ if (extend === void 0) { extend = {}; }
18
+ return Object.keys(extend).reduce(function (acc, key) {
19
+ var _a;
20
+ return (__assign({}, acc, (_a = {}, _a[key] = React.useCallback(function (syntheticEvent) {
21
+ if (extend[key]) {
22
+ extend[key](syntheticEvent);
23
+ }
24
+ if (props[key]) {
25
+ props[key]({ target: target.current, syntheticEvent: syntheticEvent });
26
+ }
27
+ }, [props[key], extend[key], target]), _a)));
28
+ }, {});
29
+ };
package/dist/es/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/es/main.js 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';
@@ -21,11 +20,16 @@ export * from './hocs/AsyncFocusBlur';
21
20
  export * from './hocs/withPropsContext';
22
21
  export * from './hooks/useDir';
23
22
  export * from './hooks/useAsyncFocusBlur';
24
- export * from './hooks/useDraggable';
25
23
  export * from './hooks/useRtl';
26
24
  export * from './hooks/useMouse';
27
25
  export * from './hooks/useCustomComponent';
28
26
  export * from './hooks/usePropsContext';
27
+ export * from './hooks/useCollection';
29
28
  export * from './icons/Icon';
30
29
  export * from './icons/SvgIcon';
31
30
  export * from './typography/Typography';
31
+ export * from './drag-n-drop';
32
+ export * from './Draggable';
33
+ export * from './Droppable';
34
+ export * from './hooks/useDraggable';
35
+ export * from './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
+ }
File without changes
@@ -1 +1,4 @@
1
1
  export * from './mouse';
2
+ export * from './touch';
3
+ export * from './pointer';
4
+ export * from './auto-scroll-options';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @hidden
3
+ */
4
+ export interface KendoComponent {
5
+ element: HTMLElement;
6
+ }
File without changes
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @hidden
4
+ */
5
+ export interface KendoPointer<T, E extends HTMLElement> {
6
+ onPointerDown?: (args: KendoPointerEvent<T, E>) => void;
7
+ onPointerMove?: (args: KendoPointerEvent<T, E>) => void;
8
+ onPointerUp?: (args: KendoPointerEvent<T, E>) => void;
9
+ onPointerCancel?: (args: KendoPointerEvent<T, E>) => void;
10
+ onGotPointerCapture?: (args: KendoPointerEvent<T, E>) => void;
11
+ onLostPointerCapture?: (args: KendoPointerEvent<T, E>) => void;
12
+ onPointerEnter?: (args: KendoPointerEvent<T, E>) => void;
13
+ onPointerOver?: (args: KendoPointerEvent<T, E>) => void;
14
+ onPointerLeave?: (args: KendoPointerEvent<T, E>) => void;
15
+ onPointerOut?: (args: KendoPointerEvent<T, E>) => void;
16
+ }
17
+ /**
18
+ * @hidden
19
+ */
20
+ export interface KendoPointerEvent<T, E extends HTMLElement = HTMLElement> {
21
+ syntheticEvent: React.PointerEvent<E>;
22
+ target: T;
23
+ }
File without changes
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @hidden
4
+ */
5
+ export interface KendoTouch<T, E extends HTMLElement> {
6
+ onTouchStart?: (args: KendoTouchEvent<T, E>) => void;
7
+ onTouchMove?: (args: KendoTouchEvent<T, E>) => void;
8
+ onTouchEnd?: (args: KendoTouchEvent<T, E>) => void;
9
+ onTouchCancel?: (args: KendoTouchEvent<T, E>) => void;
10
+ }
11
+ /**
12
+ * @hidden
13
+ */
14
+ export interface KendoTouchEvent<T, E extends HTMLElement = HTMLElement> {
15
+ syntheticEvent: React.TouchEvent<E>;
16
+ target: T;
17
+ }
File without changes
@@ -1,78 +1,86 @@
1
1
  import * as React from 'react';
2
- import * as PropTypes from 'prop-types';
3
- /**
4
- * @hidden
5
- */
6
- export interface BaseDraggableEvent<T extends React.Component> {
2
+ import { DraggableOptions, DraggableHandle } from './hooks';
3
+ import { NormalizedDragEvent } from '@progress/kendo-draggable-common';
4
+ /** @hidden */
5
+ interface BaseDraggableEvent {
7
6
  /**
8
- * The target Draggable component.
7
+ * The DOM element.
9
8
  */
10
- target: T;
9
+ element: HTMLElement;
11
10
  /**
12
- * The original event.
11
+ * The target Draggable reference.
13
12
  */
14
- event: any;
13
+ target: DraggableHandle;
14
+ /**
15
+ * The normalized drag event.
16
+ */
17
+ event: NormalizedDragEvent;
15
18
  }
16
19
  /**
17
- * Represents the object of the `onPress` Draggable event.
20
+ * Represents the object of the `onPress` callback.
18
21
  */
19
- export interface DraggablePressEvent extends BaseDraggableEvent<Draggable> {
20
- /**
21
- * The element which is pressed.
22
- */
23
- element: HTMLElement;
22
+ export interface DraggablePressEvent extends BaseDraggableEvent {
24
23
  }
25
24
  /**
26
- * Represents the object of the `onDrag` Draggable event.
25
+ * Represents the object of the `onDragStart` callback.
27
26
  */
28
- export interface DraggableDragEvent extends BaseDraggableEvent<Draggable> {
29
- /**
30
- * The element which is pressed.
31
- */
32
- element: HTMLElement;
27
+ export interface DraggableDragStartEvent extends BaseDraggableEvent {
28
+ }
29
+ /**
30
+ * Represents the object of the `onDrag` callback.
31
+ */
32
+ export interface DraggableDragEvent extends BaseDraggableEvent {
33
+ }
34
+ /**
35
+ * Represents the object of the `onDragEnd` callback.
36
+ */
37
+ export interface DraggableDragEndEvent extends BaseDraggableEvent {
33
38
  }
34
39
  /**
35
- * Represents the object of the `onRelease` Draggable event.
40
+ * Represents the object of the `onRelease` callback.
36
41
  */
37
- export interface DraggableReleaseEvent extends BaseDraggableEvent<Draggable> {
42
+ export interface DraggableReleaseEvent extends BaseDraggableEvent {
38
43
  }
39
44
  /**
40
45
  * Represents the props of the KendoReact Draggable component.
41
46
  */
42
- export interface DraggableProps {
47
+ export interface DraggableProps extends DraggableOptions {
43
48
  /**
44
49
  * Fires when the user press element inside the Draggable component.
45
50
  */
46
51
  onPress?: (event: DraggablePressEvent) => void;
52
+ /**
53
+ * Fires when the user starts dragging the element inside the Draggable component.
54
+ */
55
+ onDragStart?: (event: DraggableDragStartEvent) => void;
47
56
  /**
48
57
  * Fires when the user drag the element inside the Draggable component.
49
58
  */
50
59
  onDrag?: (event: DraggableDragEvent) => void;
60
+ /**
61
+ * Fires when the user finishes dragging the element inside the Draggable component.
62
+ */
63
+ onDragEnd?: (event: DraggableDragEndEvent) => void;
51
64
  /**
52
65
  * Fires when the user release the current drag action.
53
66
  */
54
67
  onRelease?: (event: DraggableReleaseEvent) => void;
55
68
  /**
56
- * Callback to get the child element ref. Useful as the Draggable overrides ref of the child element.
69
+ * Callback to get the child element ref. Useful as the Draggable overrides ref of the child element.
57
70
  */
58
- childRef?: (childElement: HTMLElement) => void;
71
+ childRef?: React.Ref<HTMLElement | null | {
72
+ element: HTMLElement | null;
73
+ [key: string]: any;
74
+ }>;
75
+ /** @hidden */
76
+ children?: React.ReactNode;
59
77
  }
60
78
  /**
61
79
  * Represents the KendoReact Draggable component.
80
+ *
81
+ * Accepts properties of type [DraggableProps]({% slug api_common_draggableprops %}),
82
+ * and returns an object of type [DraggableHandle]({% slug api_common_draggablehandle %}) when the `ref` is obtained.
62
83
  */
63
- export declare class Draggable extends React.Component<DraggableProps, {}> {
64
- static propTypes: {
65
- children: PropTypes.Validator<PropTypes.ReactElementLike>;
66
- };
67
- /**
68
- * @hidden
69
- */
70
- element: HTMLElement | null;
71
- private draggable;
72
- componentDidMount(): void;
73
- componentWillUnmount(): void;
74
- childRef: (element: any) => void;
75
- render(): React.FunctionComponentElement<{
76
- ref: (element: any) => void;
77
- }>;
78
- }
84
+ export declare const Draggable: React.ForwardRefExoticComponent<DraggableProps & React.RefAttributes<DraggableHandle>>;
85
+ export declare type Draggable = DraggableHandle;
86
+ export {};
@@ -1,83 +1,86 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
2
  Object.defineProperty(exports, "__esModule", { value: true });
16
3
  var React = require("react");
17
- var PropTypes = require("prop-types");
18
- var kendo_draggable_1 = require("@telerik/kendo-draggable");
4
+ var hooks_1 = require("./hooks");
19
5
  /**
20
6
  * Represents the KendoReact Draggable component.
7
+ *
8
+ * Accepts properties of type [DraggableProps]({% slug api_common_draggableprops %}),
9
+ * and returns an object of type [DraggableHandle]({% slug api_common_draggablehandle %}) when the `ref` is obtained.
21
10
  */
22
- var Draggable = /** @class */ (function (_super) {
23
- __extends(Draggable, _super);
24
- function Draggable() {
25
- var _this = _super !== null && _super.apply(this, arguments) || this;
26
- /**
27
- * @hidden
28
- */
29
- _this.element = null;
30
- _this.draggable = new kendo_draggable_1.default({
31
- press: function (event) {
32
- if (_this.element && _this.props.onPress) {
33
- _this.props.onPress.call(undefined, {
34
- target: _this,
35
- event: event,
36
- element: _this.element
37
- });
38
- }
39
- },
40
- drag: function (event) {
41
- if (_this.element && _this.props.onDrag) {
42
- _this.props.onDrag.call(undefined, {
43
- target: _this,
44
- event: event,
45
- element: _this.element
46
- });
47
- }
48
- },
49
- release: function (event) {
50
- if (_this.element && _this.props.onRelease) {
51
- _this.props.onRelease.call(undefined, {
52
- target: _this,
53
- event: event
54
- });
55
- }
56
- }
11
+ exports.Draggable = React.forwardRef(function (props, ref) {
12
+ var childRef = React.useRef(null);
13
+ var target = React.useRef(null);
14
+ var getElement = React.useCallback(function () { return childRef.current && childRef.current.element
15
+ ? childRef.current.element
16
+ : childRef.current; }, [childRef]);
17
+ React.useImperativeHandle(target, function () { return ({ element: getElement() || null }); });
18
+ React.useImperativeHandle(ref, function () { return target.current; });
19
+ React.useImperativeHandle(props.childRef, function () { return childRef.current; });
20
+ var handlePress = React.useCallback(function (event) {
21
+ if (!props.onPress) {
22
+ return;
23
+ }
24
+ props.onPress({
25
+ element: getElement(),
26
+ target: target.current,
27
+ event: event
28
+ });
29
+ }, [getElement, props.onPress]);
30
+ var handleRelease = React.useCallback(function (event) {
31
+ if (!props.onRelease) {
32
+ return;
33
+ }
34
+ props.onRelease({
35
+ element: getElement(),
36
+ target: target.current,
37
+ event: event
38
+ });
39
+ }, [getElement, props.onRelease]);
40
+ var handleDragStart = React.useCallback(function (event) {
41
+ if (!props.onDragStart) {
42
+ return;
43
+ }
44
+ props.onDragStart({
45
+ element: getElement(),
46
+ target: target.current,
47
+ event: event
48
+ });
49
+ }, [props, getElement]);
50
+ var handleDrag = React.useCallback(function (event) {
51
+ if (!props.onDrag) {
52
+ return;
53
+ }
54
+ props.onDrag({
55
+ element: getElement(),
56
+ target: target.current,
57
+ event: event
57
58
  });
58
- _this.childRef = function (element) {
59
- var childRef = _this.props.childRef;
60
- _this.element = element;
61
- if (childRef && typeof childRef === 'function') {
62
- childRef(element);
63
- }
64
- };
65
- return _this;
66
- }
67
- Draggable.prototype.componentDidMount = function () {
68
- if (this.element) {
69
- this.draggable.bindTo(this.element);
59
+ }, [getElement, props.onDrag]);
60
+ var handleDragEnd = React.useCallback(function (event) {
61
+ if (!props.onDragEnd) {
62
+ return;
70
63
  }
71
- };
72
- Draggable.prototype.componentWillUnmount = function () {
73
- this.draggable.destroy();
74
- };
75
- Draggable.prototype.render = function () {
76
- return (React.cloneElement(React.Children.only(this.props.children), { ref: this.childRef }));
77
- };
78
- Draggable.propTypes = {
79
- children: PropTypes.element.isRequired
80
- };
81
- return Draggable;
82
- }(React.Component));
83
- exports.Draggable = Draggable;
64
+ props.onDragEnd({
65
+ element: getElement(),
66
+ target: target.current,
67
+ event: event
68
+ });
69
+ }, [getElement, props.onDragEnd]);
70
+ hooks_1.useDraggable(childRef, {
71
+ onPress: handlePress,
72
+ onRelease: handleRelease,
73
+ onDragStart: handleDragStart,
74
+ onDrag: handleDrag,
75
+ onDragEnd: handleDragEnd
76
+ }, {
77
+ mouseOnly: props.mouseOnly,
78
+ autoScroll: props.autoScroll,
79
+ hint: props.hint,
80
+ scrollContainer: props.scrollContainer
81
+ });
82
+ return props.children
83
+ ? (React.cloneElement(React.Children.only(props.children), { ref: childRef }))
84
+ : null;
85
+ });
86
+ exports.Draggable.displayName = 'KendoReactDraggable';