This commit is contained in:
NoryiE
2025-02-10 06:00:28 +00:00
parent b0a4a6da9c
commit 71a1fce096
2428 changed files with 0 additions and 1005324 deletions

View File

@@ -1,41 +0,0 @@
import { ref, watch, readonly, onUnmounted } from 'vue';
import { inBrowser } from '../../shared';
export const focusedElement = ref();
let active = false;
let listeners = 0;
export function useFlyout(options) {
const focus = ref(false);
if (inBrowser) {
!active && activateFocusTracking();
listeners++;
const unwatch = watch(focusedElement, (el) => {
if (el === options.el.value || options.el.value?.contains(el)) {
focus.value = true;
options.onFocus?.();
}
else {
focus.value = false;
options.onBlur?.();
}
});
onUnmounted(() => {
unwatch();
listeners--;
if (!listeners) {
deactivateFocusTracking();
}
});
}
return readonly(focus);
}
function activateFocusTracking() {
document.addEventListener('focusin', handleFocusIn);
active = true;
focusedElement.value = document.activeElement;
}
function deactivateFocusTracking() {
document.removeEventListener('focusin', handleFocusIn);
}
function handleFocusIn() {
focusedElement.value = document.activeElement;
}