1 | 'use strict';
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
---|
4 |
|
---|
5 | var actions = require('@use-gesture/core/actions');
|
---|
6 | var React = require('react');
|
---|
7 | var core = require('@use-gesture/core');
|
---|
8 | var utils = require('@use-gesture/core/utils');
|
---|
9 | var types = require('@use-gesture/core/types');
|
---|
10 |
|
---|
11 | function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
---|
12 |
|
---|
13 | var React__default = /*#__PURE__*/_interopDefault(React);
|
---|
14 |
|
---|
15 | function useRecognizers(handlers, config = {}, gestureKey, nativeHandlers) {
|
---|
16 | const ctrl = React__default["default"].useMemo(() => new core.Controller(handlers), []);
|
---|
17 | ctrl.applyHandlers(handlers, nativeHandlers);
|
---|
18 | ctrl.applyConfig(config, gestureKey);
|
---|
19 | React__default["default"].useEffect(ctrl.effect.bind(ctrl));
|
---|
20 | React__default["default"].useEffect(() => {
|
---|
21 | return ctrl.clean.bind(ctrl);
|
---|
22 | }, []);
|
---|
23 | if (config.target === undefined) {
|
---|
24 | return ctrl.bind.bind(ctrl);
|
---|
25 | }
|
---|
26 | return undefined;
|
---|
27 | }
|
---|
28 |
|
---|
29 | function useDrag(handler, config) {
|
---|
30 | actions.registerAction(actions.dragAction);
|
---|
31 | return useRecognizers({
|
---|
32 | drag: handler
|
---|
33 | }, config || {}, 'drag');
|
---|
34 | }
|
---|
35 |
|
---|
36 | function usePinch(handler, config) {
|
---|
37 | actions.registerAction(actions.pinchAction);
|
---|
38 | return useRecognizers({
|
---|
39 | pinch: handler
|
---|
40 | }, config || {}, 'pinch');
|
---|
41 | }
|
---|
42 |
|
---|
43 | function useWheel(handler, config) {
|
---|
44 | actions.registerAction(actions.wheelAction);
|
---|
45 | return useRecognizers({
|
---|
46 | wheel: handler
|
---|
47 | }, config || {}, 'wheel');
|
---|
48 | }
|
---|
49 |
|
---|
50 | function useScroll(handler, config) {
|
---|
51 | actions.registerAction(actions.scrollAction);
|
---|
52 | return useRecognizers({
|
---|
53 | scroll: handler
|
---|
54 | }, config || {}, 'scroll');
|
---|
55 | }
|
---|
56 |
|
---|
57 | function useMove(handler, config) {
|
---|
58 | actions.registerAction(actions.moveAction);
|
---|
59 | return useRecognizers({
|
---|
60 | move: handler
|
---|
61 | }, config || {}, 'move');
|
---|
62 | }
|
---|
63 |
|
---|
64 | function useHover(handler, config) {
|
---|
65 | actions.registerAction(actions.hoverAction);
|
---|
66 | return useRecognizers({
|
---|
67 | hover: handler
|
---|
68 | }, config || {}, 'hover');
|
---|
69 | }
|
---|
70 |
|
---|
71 | function createUseGesture(actions$1) {
|
---|
72 | actions$1.forEach(actions.registerAction);
|
---|
73 | return function useGesture(_handlers, _config) {
|
---|
74 | const {
|
---|
75 | handlers,
|
---|
76 | nativeHandlers,
|
---|
77 | config
|
---|
78 | } = core.parseMergedHandlers(_handlers, _config || {});
|
---|
79 | return useRecognizers(handlers, config, undefined, nativeHandlers);
|
---|
80 | };
|
---|
81 | }
|
---|
82 |
|
---|
83 | function useGesture(handlers, config) {
|
---|
84 | const hook = createUseGesture([actions.dragAction, actions.pinchAction, actions.scrollAction, actions.wheelAction, actions.moveAction, actions.hoverAction]);
|
---|
85 | return hook(handlers, config || {});
|
---|
86 | }
|
---|
87 |
|
---|
88 | exports.createUseGesture = createUseGesture;
|
---|
89 | exports.useDrag = useDrag;
|
---|
90 | exports.useGesture = useGesture;
|
---|
91 | exports.useHover = useHover;
|
---|
92 | exports.useMove = useMove;
|
---|
93 | exports.usePinch = usePinch;
|
---|
94 | exports.useScroll = useScroll;
|
---|
95 | exports.useWheel = useWheel;
|
---|
96 | Object.keys(actions).forEach(function (k) {
|
---|
97 | if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
---|
98 | enumerable: true,
|
---|
99 | get: function () { return actions[k]; }
|
---|
100 | });
|
---|
101 | });
|
---|
102 | Object.keys(utils).forEach(function (k) {
|
---|
103 | if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
---|
104 | enumerable: true,
|
---|
105 | get: function () { return utils[k]; }
|
---|
106 | });
|
---|
107 | });
|
---|
108 | Object.keys(types).forEach(function (k) {
|
---|
109 | if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
---|
110 | enumerable: true,
|
---|
111 | get: function () { return types[k]; }
|
---|
112 | });
|
---|
113 | });
|
---|