fix(core): allow null as key-code

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2022-12-02 15:03:28 +01:00
committed by Braks
parent 7dfceb2133
commit 91d7c9d52a
3 changed files with 29 additions and 27 deletions
+21 -19
View File
@@ -10,7 +10,7 @@ function isInputDOMNode(event: KeyboardEvent): boolean {
return ['INPUT', 'SELECT', 'TEXTAREA'].includes(target?.nodeName) || hasAttribute || !!closest return ['INPUT', 'SELECT', 'TEXTAREA'].includes(target?.nodeName) || hasAttribute || !!closest
} }
export default (keyFilter: MaybeRef<KeyFilter>, onChange?: (keyPressed: boolean) => void): Ref<boolean> => { export default (keyFilter: MaybeRef<KeyFilter | null>, onChange?: (keyPressed: boolean) => void): Ref<boolean> => {
const window = useWindow() const window = useWindow()
let isPressed = $ref(unref(keyFilter) === true) let isPressed = $ref(unref(keyFilter) === true)
@@ -27,27 +27,29 @@ export default (keyFilter: MaybeRef<KeyFilter>, onChange?: (keyPressed: boolean)
return return
} }
onKeyStroke( if (unrefKeyFilter) {
unrefKeyFilter, onKeyStroke(
(e) => { unrefKeyFilter,
if (isInputDOMNode(e)) return (e) => {
if (isInputDOMNode(e)) return
e.preventDefault() e.preventDefault()
isPressed = true isPressed = true
}, },
{ eventName: 'keydown' }, { eventName: 'keydown' },
) )
onKeyStroke( onKeyStroke(
unrefKeyFilter, unrefKeyFilter,
(e) => { (e) => {
if (isInputDOMNode(e)) return if (isInputDOMNode(e)) return
e.preventDefault() e.preventDefault()
isPressed = false isPressed = false
}, },
{ eventName: 'keyup' }, { eventName: 'keyup' },
) )
}
}) })
if (typeof window.addEventListener !== 'undefined') { if (typeof window.addEventListener !== 'undefined') {
+4 -4
View File
@@ -113,10 +113,10 @@ export interface FlowProps {
/** @deprecated use {@link ConnectionLineOptions.style} */ /** @deprecated use {@link ConnectionLineOptions.style} */
connectionLineStyle?: CSSProperties | null connectionLineStyle?: CSSProperties | null
connectionLineOptions?: ConnectionLineOptions connectionLineOptions?: ConnectionLineOptions
deleteKeyCode?: KeyFilter deleteKeyCode?: KeyFilter | null
selectionKeyCode?: KeyFilter selectionKeyCode?: KeyFilter | null
multiSelectionKeyCode?: KeyFilter multiSelectionKeyCode?: KeyFilter | null
zoomActivationKeyCode?: KeyFilter zoomActivationKeyCode?: KeyFilter | null
snapToGrid?: boolean snapToGrid?: boolean
snapGrid?: SnapGrid snapGrid?: SnapGrid
onlyRenderVisibleElements?: boolean onlyRenderVisibleElements?: boolean
+4 -4
View File
@@ -65,10 +65,10 @@ export interface State extends Omit<FlowOptions, 'id' | 'modelValue'> {
userSelectionActive: boolean userSelectionActive: boolean
multiSelectionActive: boolean multiSelectionActive: boolean
deleteKeyCode: KeyFilter deleteKeyCode: KeyFilter | null
selectionKeyCode: KeyFilter selectionKeyCode: KeyFilter | null
multiSelectionKeyCode: KeyFilter multiSelectionKeyCode: KeyFilter | null
zoomActivationKeyCode: KeyFilter zoomActivationKeyCode: KeyFilter | null
connectionMode: ConnectionMode connectionMode: ConnectionMode
connectionLineOptions: ConnectionLineOptions connectionLineOptions: ConnectionLineOptions