@headless-adminapp/app 1.4.13 → 1.4.14
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.
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useLongPress.d.ts +12 -0
- package/hooks/useLongPress.js +48 -0
- package/package.json +2 -2
package/hooks/index.d.ts
CHANGED
package/hooks/index.js
CHANGED
|
@@ -22,3 +22,4 @@ __exportStar(require("./useStorageState"), exports);
|
|
|
22
22
|
__exportStar(require("./useSystemColorScheme"), exports);
|
|
23
23
|
var useItemsWithKey_1 = require("./useItemsWithKey");
|
|
24
24
|
Object.defineProperty(exports, "useItemsWithKey", { enumerable: true, get: function () { return useItemsWithKey_1.useItemsWithKey; } });
|
|
25
|
+
__exportStar(require("./useLongPress"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
isPreventDefault?: boolean;
|
|
3
|
+
delay?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare const useLongPress: (callback: (e: TouchEvent | MouseEvent) => void, { isPreventDefault, delay }?: Options) => {
|
|
6
|
+
readonly onMouseDown: (e: any) => void;
|
|
7
|
+
readonly onTouchStart: (e: any) => void;
|
|
8
|
+
readonly onMouseUp: () => void;
|
|
9
|
+
readonly onMouseLeave: () => void;
|
|
10
|
+
readonly onTouchEnd: () => void;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLongPress = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const util_1 = require("react-use/lib/misc/util");
|
|
6
|
+
const isTouchEvent = (ev) => {
|
|
7
|
+
return 'touches' in ev;
|
|
8
|
+
};
|
|
9
|
+
const preventDefault = (ev) => {
|
|
10
|
+
if (!isTouchEvent(ev))
|
|
11
|
+
return;
|
|
12
|
+
if (ev.touches.length < 2 && ev.preventDefault) {
|
|
13
|
+
ev.preventDefault();
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const useLongPress = (callback, { isPreventDefault = true, delay = 300 } = {}) => {
|
|
17
|
+
const timeout = (0, react_1.useRef)();
|
|
18
|
+
const target = (0, react_1.useRef)();
|
|
19
|
+
const start = (0, react_1.useCallback)((event) => {
|
|
20
|
+
// prevent ghost click on mobile devices
|
|
21
|
+
if (isPreventDefault && event.target) {
|
|
22
|
+
(0, util_1.on)(event.target, 'touchend', preventDefault, { passive: false });
|
|
23
|
+
target.current = event.target;
|
|
24
|
+
}
|
|
25
|
+
timeout.current = setTimeout(() => callback(event), delay);
|
|
26
|
+
}, [callback, delay, isPreventDefault]);
|
|
27
|
+
const clear = (0, react_1.useCallback)(() => {
|
|
28
|
+
// clearTimeout and removeEventListener
|
|
29
|
+
timeout.current && clearTimeout(timeout.current);
|
|
30
|
+
if (isPreventDefault && target.current) {
|
|
31
|
+
(0, util_1.off)(target.current, 'touchend', preventDefault);
|
|
32
|
+
}
|
|
33
|
+
}, [isPreventDefault]);
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
|
+
window.addEventListener('touchmove', clear);
|
|
36
|
+
return () => {
|
|
37
|
+
window.removeEventListener('touchmove', clear);
|
|
38
|
+
};
|
|
39
|
+
}, [clear]);
|
|
40
|
+
return {
|
|
41
|
+
onMouseDown: (e) => start(e),
|
|
42
|
+
onTouchStart: (e) => start(e),
|
|
43
|
+
onMouseUp: clear,
|
|
44
|
+
onMouseLeave: clear,
|
|
45
|
+
onTouchEnd: clear,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.useLongPress = useLongPress;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/app",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"uuid": "11.0.3",
|
|
39
39
|
"yup": "^1.4.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "0792de20ccf4a33c064428de55263fcf13de5543"
|
|
42
42
|
}
|