vuestic-ui
Version:
Vue 3 UI Framework
40 lines (39 loc) • 1.12 kB
JavaScript
import { unref } from "vue";
import { u as useEvent } from "./useEvent.js";
import { u as useHTMLElement } from "./useHTMLElement.js";
function useLongPress(el, options) {
let timeoutId = -1;
let intervalId = -1;
const handleMouseDown = () => {
var _a;
(_a = options.onStart) == null ? void 0 : _a.call(options);
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
intervalId = setInterval(() => {
var _a2;
return (_a2 = options.onUpdate) == null ? void 0 : _a2.call(options);
}, options.interval || 100);
}, unref(options.delay) || 500);
};
const handleMouseUp = () => {
var _a;
clearTimeout(timeoutId);
clearInterval(intervalId);
(_a = options.onEnd) == null ? void 0 : _a.call(options);
};
const htmlElement = useHTMLElement(el);
useEvent(["mousedown", "touchstart", "dragstart"], handleMouseDown, htmlElement);
useEvent([
"mouseup",
"mouseleave",
"touchend",
"touchcancel",
"drop",
"dragend",
"blur"
], handleMouseUp, true);
}
export {
useLongPress as u
};
//# sourceMappingURL=useLongPress.js.map