|
|
@ -1,15 +1,15 @@ |
|
|
|
import { isClient } from '@vueuse/core' |
|
|
|
import { isClient } from '@vueuse/core' |
|
|
|
import type { Ref } from 'vue' |
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
|
|
|
|
|
|
|
|
function useSelectedCellKeyupListener( |
|
|
|
function useSelectedCellKeyupListener( |
|
|
|
selected: Ref<boolean>, |
|
|
|
selected: Ref<boolean | undefined> | ComputedRef<boolean | undefined>, |
|
|
|
handler: (e: KeyboardEvent) => void, |
|
|
|
handler: (e: KeyboardEvent) => void, |
|
|
|
{ immediate = false }: { immediate?: boolean } = {}, |
|
|
|
{ immediate = false }: { immediate?: boolean } = {}, |
|
|
|
) { |
|
|
|
) { |
|
|
|
if (isClient) { |
|
|
|
if (isClient) { |
|
|
|
watch( |
|
|
|
watch( |
|
|
|
selected, |
|
|
|
selected, |
|
|
|
(nextVal: boolean, _: boolean, cleanup) => { |
|
|
|
(nextVal: boolean | undefined, _: boolean | undefined, cleanup) => { |
|
|
|
// bind listener when `selected` is truthy
|
|
|
|
// bind listener when `selected` is truthy
|
|
|
|
if (nextVal) { |
|
|
|
if (nextVal) { |
|
|
|
document.addEventListener('keydown', handler, true) |
|
|
|
document.addEventListener('keydown', handler, true) |
|
|
|