Comparing version 0.0.5 to 0.0.6
@@ -0,1 +1,2 @@ | ||
import { Ref } from 'vue'; | ||
interface useKeyboardOptions { | ||
@@ -19,3 +20,3 @@ keyup?: UseKeyboardHandlers; | ||
} | ||
export default function useKeyboard(options?: useKeyboardOptions): Readonly<UseKeyboardState>; | ||
export default function useKeyboard(options?: useKeyboardOptions, enabledRef?: Ref<boolean>): Readonly<UseKeyboardState>; | ||
export {}; |
@@ -1,4 +0,4 @@ | ||
import { onBeforeMount, onBeforeUnmount, reactive, readonly } from 'vue'; | ||
import { onBeforeMount, onBeforeUnmount, reactive, readonly, watch } from 'vue'; | ||
import { on, off } from 'evtd'; | ||
export default function useKeyboard(options = {}) { | ||
export default function useKeyboard(options = {}, enabledRef) { | ||
const state = reactive({ | ||
@@ -83,10 +83,26 @@ ctrl: false, | ||
onBeforeMount(() => { | ||
on('keydown', document, keydownHandler); | ||
on('keyup', document, keyupHandler); | ||
if (enabledRef === undefined || enabledRef.value) { | ||
on('keydown', document, keydownHandler); | ||
on('keyup', document, keyupHandler); | ||
} | ||
if (enabledRef !== undefined) { | ||
watch(enabledRef, value => { | ||
if (value) { | ||
on('keydown', document, keydownHandler); | ||
on('keyup', document, keyupHandler); | ||
} | ||
else { | ||
off('keydown', document, keydownHandler); | ||
off('keyup', document, keyupHandler); | ||
} | ||
}); | ||
} | ||
}); | ||
onBeforeUnmount(() => { | ||
off('keydown', document, keydownHandler); | ||
off('keyup', document, keyupHandler); | ||
if (enabledRef === undefined || enabledRef.value) { | ||
off('keydown', document, keydownHandler); | ||
off('keyup', document, keyupHandler); | ||
} | ||
}); | ||
return readonly(state); | ||
} |
@@ -0,1 +1,2 @@ | ||
import { Ref } from 'vue'; | ||
interface useKeyboardOptions { | ||
@@ -19,3 +20,3 @@ keyup?: UseKeyboardHandlers; | ||
} | ||
export default function useKeyboard(options?: useKeyboardOptions): Readonly<UseKeyboardState>; | ||
export default function useKeyboard(options?: useKeyboardOptions, enabledRef?: Ref<boolean>): Readonly<UseKeyboardState>; | ||
export {}; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const evtd_1 = require("evtd"); | ||
function useKeyboard(options = {}) { | ||
function useKeyboard(options = {}, enabledRef) { | ||
const state = vue_1.reactive({ | ||
@@ -86,8 +86,24 @@ ctrl: false, | ||
vue_1.onBeforeMount(() => { | ||
evtd_1.on('keydown', document, keydownHandler); | ||
evtd_1.on('keyup', document, keyupHandler); | ||
if (enabledRef === undefined || enabledRef.value) { | ||
evtd_1.on('keydown', document, keydownHandler); | ||
evtd_1.on('keyup', document, keyupHandler); | ||
} | ||
if (enabledRef !== undefined) { | ||
vue_1.watch(enabledRef, value => { | ||
if (value) { | ||
evtd_1.on('keydown', document, keydownHandler); | ||
evtd_1.on('keyup', document, keyupHandler); | ||
} | ||
else { | ||
evtd_1.off('keydown', document, keydownHandler); | ||
evtd_1.off('keyup', document, keyupHandler); | ||
} | ||
}); | ||
} | ||
}); | ||
vue_1.onBeforeUnmount(() => { | ||
evtd_1.off('keydown', document, keydownHandler); | ||
evtd_1.off('keyup', document, keyupHandler); | ||
if (enabledRef === undefined || enabledRef.value) { | ||
evtd_1.off('keydown', document, keydownHandler); | ||
evtd_1.off('keyup', document, keyupHandler); | ||
} | ||
}); | ||
@@ -94,0 +110,0 @@ return vue_1.readonly(state); |
{ | ||
"name": "vooks", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35734
937