source: imaps-frontend/node_modules/@use-gesture/react/dist/use-gesture-react.esm.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.2 KB
Line 
1import { registerAction, dragAction, pinchAction, wheelAction, scrollAction, moveAction, hoverAction } from '@use-gesture/core/actions';
2export * from '@use-gesture/core/actions';
3import React from 'react';
4import { Controller, parseMergedHandlers } from '@use-gesture/core';
5export * from '@use-gesture/core/utils';
6export * from '@use-gesture/core/types';
7
8function useRecognizers(handlers, config = {}, gestureKey, nativeHandlers) {
9 const ctrl = React.useMemo(() => new Controller(handlers), []);
10 ctrl.applyHandlers(handlers, nativeHandlers);
11 ctrl.applyConfig(config, gestureKey);
12 React.useEffect(ctrl.effect.bind(ctrl));
13 React.useEffect(() => {
14 return ctrl.clean.bind(ctrl);
15 }, []);
16 if (config.target === undefined) {
17 return ctrl.bind.bind(ctrl);
18 }
19 return undefined;
20}
21
22function useDrag(handler, config) {
23 registerAction(dragAction);
24 return useRecognizers({
25 drag: handler
26 }, config || {}, 'drag');
27}
28
29function usePinch(handler, config) {
30 registerAction(pinchAction);
31 return useRecognizers({
32 pinch: handler
33 }, config || {}, 'pinch');
34}
35
36function useWheel(handler, config) {
37 registerAction(wheelAction);
38 return useRecognizers({
39 wheel: handler
40 }, config || {}, 'wheel');
41}
42
43function useScroll(handler, config) {
44 registerAction(scrollAction);
45 return useRecognizers({
46 scroll: handler
47 }, config || {}, 'scroll');
48}
49
50function useMove(handler, config) {
51 registerAction(moveAction);
52 return useRecognizers({
53 move: handler
54 }, config || {}, 'move');
55}
56
57function useHover(handler, config) {
58 registerAction(hoverAction);
59 return useRecognizers({
60 hover: handler
61 }, config || {}, 'hover');
62}
63
64function createUseGesture(actions) {
65 actions.forEach(registerAction);
66 return function useGesture(_handlers, _config) {
67 const {
68 handlers,
69 nativeHandlers,
70 config
71 } = parseMergedHandlers(_handlers, _config || {});
72 return useRecognizers(handlers, config, undefined, nativeHandlers);
73 };
74}
75
76function useGesture(handlers, config) {
77 const hook = createUseGesture([dragAction, pinchAction, scrollAction, wheelAction, moveAction, hoverAction]);
78 return hook(handlers, config || {});
79}
80
81export { createUseGesture, useDrag, useGesture, useHover, useMove, usePinch, useScroll, useWheel };
Note: See TracBrowser for help on using the repository browser.