chore(defineShortcuts): config prop whenever more flexible (#149)

This commit is contained in:
Sylvain Marroufin
2023-05-02 14:47:31 +02:00
committed by GitHub
parent 8830d848fd
commit b85a8e7203

View File

@@ -1,4 +1,4 @@
import type { Ref, ComputedRef } from 'vue' import type { ComputedRef, WatchSource } from 'vue'
import { logicAnd, logicNot } from '@vueuse/math' import { logicAnd, logicNot } from '@vueuse/math'
import { computed, onMounted, onBeforeUnmount } from 'vue' import { computed, onMounted, onBeforeUnmount } from 'vue'
import { useShortcuts } from './useShortcuts' import { useShortcuts } from './useShortcuts'
@@ -6,7 +6,7 @@ import { useShortcuts } from './useShortcuts'
export interface ShortcutConfig { export interface ShortcutConfig {
handler: Function handler: Function
usingInput?: string | boolean usingInput?: string | boolean
whenever?: Ref<Boolean>[] whenever?: WatchSource<Boolean>[]
} }
export interface ShortcutsConfig { export interface ShortcutsConfig {
@@ -89,7 +89,7 @@ export const defineShortcuts = (config: ShortcutsConfig) => {
} }
// Create shortcut computed // Create shortcut computed
const conditions = [] const conditions: ComputedRef<Boolean>[] = []
if (!(shortcutConfig as ShortcutConfig).usingInput) { if (!(shortcutConfig as ShortcutConfig).usingInput) {
conditions.push(logicNot(usingInput)) conditions.push(logicNot(usingInput))
} else if (typeof (shortcutConfig as ShortcutConfig).usingInput === 'string') { } else if (typeof (shortcutConfig as ShortcutConfig).usingInput === 'string') {