@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.
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,77 @@
1
+ import * as React from 'react';
2
+ import { DroppableHandle } from './hooks';
3
+ import { NormalizedDragEvent } from '@progress/kendo-draggable-common';
4
+ /** @hidden */
5
+ interface BaseDroppableEvent {
6
+ /**
7
+ * The DOM element.
8
+ */
9
+ element: HTMLElement;
10
+ /**
11
+ * The target Draggable reference.
12
+ */
13
+ target: DroppableHandle;
14
+ /**
15
+ * The normalized drag event.
16
+ */
17
+ event: NormalizedDragEvent;
18
+ }
19
+ /**
20
+ * Represents the object of the `onDragEnter` callback.
21
+ */
22
+ export interface DroppableDragEnterEvent extends BaseDroppableEvent {
23
+ }
24
+ /**
25
+ * Represents the object of the `onDragOver` callback.
26
+ */
27
+ export interface DroppableDragOverEvent extends BaseDroppableEvent {
28
+ }
29
+ /**
30
+ * Represents the object of the `onDragLeave` callback.
31
+ */
32
+ export interface DroppableDragLeaveEvent extends BaseDroppableEvent {
33
+ }
34
+ /**
35
+ * Represents the object of the `onDrop` callback.
36
+ */
37
+ export interface DroppableDropEvent extends BaseDroppableEvent {
38
+ }
39
+ /**
40
+ * Represents the props of the KendoReact Droppable component.
41
+ */
42
+ export interface DroppableProps {
43
+ /**
44
+ * Fires when the user enters the element during drag.
45
+ */
46
+ onDragEnter?: (event: DroppableDragEnterEvent) => void;
47
+ /**
48
+ * Fires when the user is dragging an element over the Droppable component.
49
+ */
50
+ onDragOver?: (event: DroppableDragOverEvent) => void;
51
+ /**
52
+ * Fires when the user leaves the element during drag.
53
+ */
54
+ onDragLeave?: (event: DroppableDragLeaveEvent) => void;
55
+ /**
56
+ * Fires when the user drops a draggable element inside the Droppable component.
57
+ */
58
+ onDrop?: (event: DroppableDropEvent) => void;
59
+ /**
60
+ * Callback to get the child element ref. Useful as the Droppable overrides ref of the child element.
61
+ */
62
+ childRef?: React.Ref<HTMLElement | null | {
63
+ element: HTMLElement | null;
64
+ [key: string]: any;
65
+ }>;
66
+ /** @hidden */
67
+ children?: React.ReactNode;
68
+ }
69
+ /**
70
+ * Represents the KendoReact Droppable component.
71
+ *
72
+ * Accepts properties of type [DroppableProps]({% slug api_common_droppableprops %}),
73
+ * and returns an object of type [DroppableHandle]({% slug api_common_droppablehandle %}) when the `ref` is obtained.
74
+ */
75
+ export declare const Droppable: React.ForwardRefExoticComponent<DroppableProps & React.RefAttributes<DroppableHandle>>;
76
+ export declare type Droppable = DroppableHandle;
77
+ export {};
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var React = require("react");
4
+ var hooks_1 = require("./hooks");
5
+ /**
6
+ * Represents the KendoReact Droppable component.
7
+ *
8
+ * Accepts properties of type [DroppableProps]({% slug api_common_droppableprops %}),
9
+ * and returns an object of type [DroppableHandle]({% slug api_common_droppablehandle %}) when the `ref` is obtained.
10
+ */
11
+ exports.Droppable = 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() || undefined }); });
18
+ React.useImperativeHandle(ref, function () { return target.current; });
19
+ React.useImperativeHandle(props.childRef, function () { return childRef.current; });
20
+ var handleDragEnter = React.useCallback(function (event) {
21
+ if (!props.onDragEnter) {
22
+ return;
23
+ }
24
+ props.onDragEnter({
25
+ element: getElement(),
26
+ target: target.current,
27
+ event: event
28
+ });
29
+ }, [props.onDragEnter, getElement]);
30
+ var handleDragOver = React.useCallback(function (event) {
31
+ if (!props.onDragOver) {
32
+ return;
33
+ }
34
+ props.onDragOver({
35
+ element: getElement(),
36
+ target: target.current,
37
+ event: event
38
+ });
39
+ }, [getElement, props.onDragOver]);
40
+ var handleDragLeave = React.useCallback(function (event) {
41
+ if (!props.onDragLeave) {
42
+ return;
43
+ }
44
+ props.onDragLeave({
45
+ element: getElement(),
46
+ target: target.current,
47
+ event: event
48
+ });
49
+ }, [props.onDragLeave, getElement]);
50
+ var handleDrop = React.useCallback(function (event) {
51
+ if (!props.onDrop) {
52
+ return;
53
+ }
54
+ props.onDrop({
55
+ element: getElement(),
56
+ target: target.current,
57
+ event: event
58
+ });
59
+ }, [props.onDrop, getElement]);
60
+ hooks_1.useDroppable(childRef, {
61
+ onDragEnter: handleDragEnter,
62
+ onDragOver: handleDragOver,
63
+ onDragLeave: handleDragLeave,
64
+ onDrop: handleDrop
65
+ });
66
+ return props.children
67
+ ? (React.cloneElement(React.Children.only(props.children), { ref: childRef }))
68
+ : null;
69
+ });
70
+ exports.Droppable.displayName = 'KendoReactDroppable';
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ import { DragTarget, DropTarget } from '@progress/kendo-draggable-common';
3
+ /**
4
+ * @hidden
5
+ */
6
+ export declare const DragContext: React.Context<[React.RefObject<DragTarget>, (value: React.RefObject<DragTarget>, args?: any) => void]>;
7
+ /**
8
+ * @hidden
9
+ */
10
+ export declare const DropContext: React.Context<[React.RefObject<DropTarget>, (value: React.RefObject<DropTarget>, args?: any) => void]>;
11
+ /**
12
+ * @hidden
13
+ */
14
+ export declare const DragsContext: React.Context<[React.RefObject<DragTarget>[], Function, Function]>;
15
+ /**
16
+ * @hidden
17
+ */
18
+ export declare const DropsContext: React.Context<[React.RefObject<DropTarget>[], Function, Function]>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var React = require("react");
4
+ var noop_1 = require("../../noop");
5
+ /**
6
+ * @hidden
7
+ */
8
+ exports.DragContext = React.createContext([
9
+ undefined,
10
+ noop_1.noop
11
+ ]);
12
+ /**
13
+ * @hidden
14
+ */
15
+ exports.DropContext = React.createContext([
16
+ undefined,
17
+ noop_1.noop
18
+ ]);
19
+ /**
20
+ * @hidden
21
+ */
22
+ exports.DragsContext = React.createContext([[], noop_1.noop, noop_1.noop]);
23
+ /**
24
+ * @hidden
25
+ */
26
+ exports.DropsContext = React.createContext([[], noop_1.noop, noop_1.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,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var React = require("react");
4
+ var hooks_1 = require("../hooks");
5
+ var context_1 = require("./context");
6
+ /**
7
+ * The `DragAndDrop` component is required for the `droppable` functionality to work properly.
8
+ *
9
+ * It is used internally to synchronize the `drag` and `drop` functionalities.
10
+ * Accepts properties of type [DragAndDropProps]({% slug api_common_draganddropprops %}).
11
+ */
12
+ exports.DragAndDrop = function (props) {
13
+ var _a = hooks_1.useControlledState(null, undefined), drag = _a[0], setDrag = _a[1];
14
+ var _b = hooks_1.useControlledState(null, undefined), drop = _b[0], setDrop = _b[1];
15
+ var _c = hooks_1.useCollection([]), drags = _c[0], dispatchDrags = _c[1];
16
+ var _d = hooks_1.useCollection([]), drops = _d[0], dispatchDrops = _d[1];
17
+ var registerDrag = function (item) {
18
+ dispatchDrags({
19
+ type: hooks_1.COLLECTION_ACTION.add,
20
+ item: item
21
+ });
22
+ };
23
+ var deregisterDrag = function (item) {
24
+ dispatchDrags({
25
+ type: hooks_1.COLLECTION_ACTION.remove,
26
+ item: item
27
+ });
28
+ };
29
+ var registerDrop = function (item) {
30
+ dispatchDrops({
31
+ type: hooks_1.COLLECTION_ACTION.add,
32
+ item: item
33
+ });
34
+ };
35
+ var deregisterDrop = function (item) {
36
+ dispatchDrops({
37
+ type: hooks_1.COLLECTION_ACTION.remove,
38
+ item: item
39
+ });
40
+ };
41
+ return (React.createElement(context_1.DragContext.Provider, { value: [drag, setDrag] },
42
+ React.createElement(context_1.DropContext.Provider, { value: [drop, setDrop] },
43
+ React.createElement(context_1.DragsContext.Provider, { value: [drags, registerDrag, deregisterDrag] },
44
+ React.createElement(context_1.DropsContext.Provider, { value: [drops, registerDrop, deregisterDrop] }, props.children)))));
45
+ };
46
+ exports.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';
@@ -7,5 +7,9 @@ __export(require("./useMouse"));
7
7
  __export(require("./useAsyncFocusBlur"));
8
8
  __export(require("./useDir"));
9
9
  __export(require("./useDraggable"));
10
+ __export(require("./useDroppable"));
10
11
  __export(require("./useRtl"));
11
12
  __export(require("./useCustomComponent"));
13
+ __export(require("./useControlledState"));
14
+ __export(require("./useInheritedState"));
15
+ __export(require("./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,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var React = require("react");
4
+ /** @hidden */
5
+ var COLLECTION_ACTION;
6
+ (function (COLLECTION_ACTION) {
7
+ COLLECTION_ACTION[COLLECTION_ACTION["add"] = 0] = "add";
8
+ COLLECTION_ACTION[COLLECTION_ACTION["remove"] = 1] = "remove";
9
+ })(COLLECTION_ACTION = exports.COLLECTION_ACTION || (exports.COLLECTION_ACTION = {}));
10
+ /** @hidden */
11
+ exports.useCollection = function (initial) {
12
+ if (initial === void 0) { initial = []; }
13
+ var collection = React.useRef(initial);
14
+ var handleCollectionAction = React.useCallback(function (action) {
15
+ switch (action.type) {
16
+ case COLLECTION_ACTION.add:
17
+ collection.current.push(action.item);
18
+ break;
19
+ case COLLECTION_ACTION.remove:
20
+ var index = collection.current.indexOf(action.item);
21
+ collection.current.splice(index, 1);
22
+ break;
23
+ default:
24
+ break;
25
+ }
26
+ }, []);
27
+ return [collection.current, handleCollectionAction];
28
+ };
@@ -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,25 @@
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
+ /** @hidden */
16
+ exports.useControlledState = function (defaultProp, prop, callback) {
17
+ var _a = React.useState(prop || defaultProp), state = _a[0], setState = _a[1];
18
+ var handleSetEdit = React.useCallback(function (value, args) {
19
+ setState(value);
20
+ if (callback) {
21
+ callback.call(undefined, __assign({}, args, { value: value }));
22
+ }
23
+ }, [callback, setState]);
24
+ return [prop !== undefined ? prop : state, handleSetEdit];
25
+ };
@@ -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;