You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
2 months ago
|
import '../../utils/index.mjs';
|
||
|
import { isFunction } from '@vue/shared';
|
||
|
|
||
|
const REPEAT_INTERVAL = 100;
|
||
|
const REPEAT_DELAY = 600;
|
||
|
const vRepeatClick = {
|
||
|
beforeMount(el, binding) {
|
||
|
const value = binding.value;
|
||
|
const { interval = REPEAT_INTERVAL, delay = REPEAT_DELAY } = isFunction(value) ? {} : value;
|
||
|
let intervalId;
|
||
|
let delayId;
|
||
|
const handler = () => isFunction(value) ? value() : value.handler();
|
||
|
const clear = () => {
|
||
|
if (delayId) {
|
||
|
clearTimeout(delayId);
|
||
|
delayId = void 0;
|
||
|
}
|
||
|
if (intervalId) {
|
||
|
clearInterval(intervalId);
|
||
|
intervalId = void 0;
|
||
|
}
|
||
|
};
|
||
|
el.addEventListener("mousedown", (evt) => {
|
||
|
if (evt.button !== 0)
|
||
|
return;
|
||
|
clear();
|
||
|
handler();
|
||
|
document.addEventListener("mouseup", () => clear(), {
|
||
|
once: true
|
||
|
});
|
||
|
delayId = setTimeout(() => {
|
||
|
intervalId = setInterval(() => {
|
||
|
handler();
|
||
|
}, interval);
|
||
|
}, delay);
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
export { REPEAT_DELAY, REPEAT_INTERVAL, vRepeatClick };
|
||
|
//# sourceMappingURL=index.mjs.map
|