yeah
This commit is contained in:
98
appOLDD/plugins/keyboard.shortcut.client.ts
Normal file
98
appOLDD/plugins/keyboard.shortcut.client.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { useUiStore } from '~/store/ui'
|
||||
import { usePlayerStore } from '~/store/player'
|
||||
import { useCardStore } from '~/store/card'
|
||||
import { useDataStore } from '~/store/data'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
// Ne s'exécuter que côté client
|
||||
if (process.server) return
|
||||
|
||||
const ui = useUiStore()
|
||||
const player = usePlayerStore()
|
||||
const cardStore = useCardStore()
|
||||
const dataStore = useDataStore()
|
||||
|
||||
function isInputElement(target: EventTarget | null): boolean {
|
||||
return (
|
||||
target instanceof HTMLInputElement ||
|
||||
target instanceof HTMLTextAreaElement ||
|
||||
target instanceof HTMLSelectElement ||
|
||||
(target instanceof HTMLElement && target.isContentEditable)
|
||||
)
|
||||
}
|
||||
|
||||
function handleKeyDown(e: KeyboardEvent) {
|
||||
// console.log('Key pressed:', e.code, 'Key:', e.key, 'Target:', e.target)
|
||||
|
||||
// Ne pas interférer avec les champs de formulaire
|
||||
if (isInputElement(e.target as HTMLElement)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Gestion du raccourci de recherche (Ctrl+F / Cmd+F)
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'f') {
|
||||
e.preventDefault()
|
||||
if (!ui.showSearch) {
|
||||
ui.openSearch()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Gestion des autres touches uniquement si pas de touche de contrôle enfoncée
|
||||
if (e.ctrlKey || e.altKey || e.metaKey) {
|
||||
return
|
||||
}
|
||||
|
||||
switch (e.code) {
|
||||
// Gestion de la barre d'espace pour play/pause
|
||||
case 'KeyR': // R pour révéler toutes les cartes
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
if (!isInputElement(e.target as HTMLElement) && ui.getSelectedBox) {
|
||||
const tracks = dataStore.getTracksByboxId(ui.getSelectedBox.id)
|
||||
cardStore.revealAllCards(tracks)
|
||||
}
|
||||
break
|
||||
|
||||
case 'KeyH': // H pour cacher toutes les cartes
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
if (!isInputElement(e.target as HTMLElement) && ui.getSelectedBox) {
|
||||
const tracks = dataStore.getTracksByboxId(ui.getSelectedBox.id)
|
||||
cardStore.hideAllCards(tracks)
|
||||
}
|
||||
break
|
||||
|
||||
case 'Space': // Espace pour play/pause
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
const selectedBox = ui.getSelectedBox
|
||||
// Si une box est sélectionnée et qu'aucune piste n'est en cours de lecture
|
||||
if (selectedBox && !player.currentTrack) {
|
||||
player.playBox(selectedBox)
|
||||
} else if (player.currentTrack) {
|
||||
// Comportement normal si une piste est déjà chargée
|
||||
player.togglePlay()
|
||||
}
|
||||
return false
|
||||
|
||||
// Gestion de la touche Échap pour fermer la boîte
|
||||
case 'Escape':
|
||||
e.preventDefault()
|
||||
ui.closeBox()
|
||||
break
|
||||
|
||||
// Gestion des touches fléchées (à implémenter si nécessaire)
|
||||
case 'ArrowUp':
|
||||
case 'ArrowDown':
|
||||
case 'ArrowLeft':
|
||||
case 'ArrowRight':
|
||||
// Implémentation future de la navigation au clavier
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Ajout de l'écouteur d'événements avec capture pour intercepter l'événement plus tôt
|
||||
window.addEventListener('keydown', handleKeyDown, { capture: true, passive: false })
|
||||
})
|
||||
Reference in New Issue
Block a user