vuestic-ui
Version:
Vue 3 UI Framework
35 lines (34 loc) • 1.03 kB
JavaScript
import { unref } from "vue";
import { u as useEvent } from "./useEvent.mjs";
import { u as useHTMLElement } from "./useHTMLElement.mjs";
function useLongPressKey(el, options) {
let timeoutId = -1;
let intervalId = -1;
const handleMouseDown = (e) => {
var _a;
(_a = options.onStart) == null ? void 0 : _a.call(options, e);
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
intervalId = setInterval(() => {
var _a2;
return (_a2 = options.onUpdate) == null ? void 0 : _a2.call(options, e);
}, options.interval || 100);
}, unref(options.delay) || 500);
};
const handleMouseUp = (e) => {
var _a;
clearTimeout(timeoutId);
clearInterval(intervalId);
(_a = options.onEnd) == null ? void 0 : _a.call(options, e);
};
const htmlElement = useHTMLElement(el);
useEvent(["keydown"], handleMouseDown, htmlElement);
useEvent([
"keyup",
"blur"
], handleMouseUp, true);
}
export {
useLongPressKey as u
};
//# sourceMappingURL=useLongPresKey.mjs.map