routie dev init since i didn't adhere to any proper guidance up until now
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
// Utilities
|
||||
import { onScopeDispose } from 'vue';
|
||||
import { IN_BROWSER } from "../../util/index.js";
|
||||
const HOLD_REPEAT = 50;
|
||||
const HOLD_DELAY = 500;
|
||||
export function useHold({
|
||||
toggleUpDown
|
||||
}) {
|
||||
let timeout = -1;
|
||||
let interval = -1;
|
||||
onScopeDispose(holdStop);
|
||||
function holdStart(value) {
|
||||
holdStop();
|
||||
tick(value);
|
||||
window.addEventListener('pointerup', holdStop);
|
||||
document.addEventListener('blur', holdStop);
|
||||
timeout = window.setTimeout(() => {
|
||||
interval = window.setInterval(() => tick(value), HOLD_REPEAT);
|
||||
}, HOLD_DELAY);
|
||||
}
|
||||
function holdStop() {
|
||||
if (!IN_BROWSER) return;
|
||||
window.clearTimeout(timeout);
|
||||
window.clearInterval(interval);
|
||||
window.removeEventListener('pointerup', holdStop);
|
||||
document.removeEventListener('blur', holdStop);
|
||||
}
|
||||
onScopeDispose(holdStop);
|
||||
function tick(value) {
|
||||
toggleUpDown(value === 'up');
|
||||
}
|
||||
return {
|
||||
holdStart,
|
||||
holdStop
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=hold.js.map
|
||||
Reference in New Issue
Block a user