From feea191ecf68fb22e466466a516254513051fd7e Mon Sep 17 00:00:00 2001 From: konrad Date: Sat, 13 Nov 2021 20:28:29 +0000 Subject: [PATCH] feat: add v-shortcut directive for keyboard shortcuts (#942) Co-authored-by: kolaente Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/942 Reviewed-by: dpschen Co-authored-by: konrad Co-committed-by: konrad --- package.json | 1 + src/components/home/MenuButton.vue | 20 +- src/components/home/contentAuth.vue | 3 +- src/components/home/topNavigation.vue | 56 +++--- src/components/misc/keyboard-shortcuts.vue | 72 ------- .../misc/keyboard-shortcuts/index.vue | 54 +++++ .../misc/keyboard-shortcuts/shortcuts.js | 88 +++++++++ src/components/misc/shortcut.vue | 14 +- src/components/modal/modal.vue | 3 +- src/directives/shortcut.ts | 17 ++ src/helpers/isAppleDevice.ts | 10 + src/i18n/lang/en.json | 9 + src/main.ts | 6 +- src/plugins/shortkey/helpers.js | 78 -------- src/plugins/shortkey/index.js | 186 ------------------ src/views/list/ShowList.vue | 8 + src/views/tasks/TaskDetailView.vue | 15 +- yarn.lock | 5 + 18 files changed, 251 insertions(+), 394 deletions(-) delete mode 100644 src/components/misc/keyboard-shortcuts.vue create mode 100644 src/components/misc/keyboard-shortcuts/index.vue create mode 100644 src/components/misc/keyboard-shortcuts/shortcuts.js create mode 100644 src/directives/shortcut.ts create mode 100644 src/helpers/isAppleDevice.ts delete mode 100644 src/plugins/shortkey/helpers.js delete mode 100644 src/plugins/shortkey/index.js diff --git a/package.json b/package.json index 5453bccdd..933d66065 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "browserslist:update": "npx browserslist@latest --update-db" }, "dependencies": { + "@github/hotkey": "^1.6.0", "@kyvg/vue3-notification": "2.3.4", "@sentry/tracing": "6.14.3", "@sentry/vue": "6.14.3", diff --git a/src/components/home/MenuButton.vue b/src/components/home/MenuButton.vue index ec5caeeac..14a2e4699 100644 --- a/src/components/home/MenuButton.vue +++ b/src/components/home/MenuButton.vue @@ -1,16 +1,17 @@ \ No newline at end of file diff --git a/src/components/misc/keyboard-shortcuts/index.vue b/src/components/misc/keyboard-shortcuts/index.vue new file mode 100644 index 000000000..c46d209e6 --- /dev/null +++ b/src/components/misc/keyboard-shortcuts/index.vue @@ -0,0 +1,54 @@ + + + + + \ No newline at end of file diff --git a/src/components/misc/keyboard-shortcuts/shortcuts.js b/src/components/misc/keyboard-shortcuts/shortcuts.js new file mode 100644 index 000000000..bcc5014b4 --- /dev/null +++ b/src/components/misc/keyboard-shortcuts/shortcuts.js @@ -0,0 +1,88 @@ +import {isAppleDevice} from '@/helpers/isAppleDevice' + +const ctrl = isAppleDevice() ? '⌘' : 'ctrl' + +export const KEYBOARD_SHORTCUTS = [ + { + title: 'keyboardShortcuts.general', + available: () => null, + shortcuts: [ + { + title: 'keyboardShortcuts.toggleMenu', + keys: [ctrl, 'e'], + }, + { + title: 'keyboardShortcuts.quickSearch', + keys: [ctrl, 'k'], + }, + ], + }, + { + title: 'list.kanban.title', + available: (route) => route.name === 'list.kanban', + shortcuts: [ + { + title: 'keyboardShortcuts.task.done', + keys: [ctrl, 'click'], + }, + ], + }, + { + title: 'keyboardShortcuts.list.title', + available: (route) => route.name.startsWith('list.'), + shortcuts: [ + { + title: 'keyboardShortcuts.list.switchToListView', + keys: ['g', 'l'], + combination: 'then', + }, + { + title: 'keyboardShortcuts.list.switchToGanttView', + keys: ['g', 'g'], + combination: 'then', + }, + { + title: 'keyboardShortcuts.list.switchToTableView', + keys: ['g', 't'], + combination: 'then', + }, + { + title: 'keyboardShortcuts.list.switchToKanbanView', + keys: ['g', 'k'], + combination: 'then', + }, + ], + }, + { + title: 'keyboardShortcuts.task.title', + available: (route) => [ + 'task.detail', + 'task.list.detail', + 'task.gantt.detail', + 'task.kanban.detail', + 'task.detail', + ].includes(route.name), + shortcuts: [ + { + title: 'keyboardShortcuts.task.assign', + keys: ['a'], + }, + { + title: 'keyboardShortcuts.task.labels', + keys: ['l'], + }, + { + title: 'keyboardShortcuts.task.dueDate', + keys: ['d'], + }, + { + title: 'keyboardShortcuts.task.attachment', + keys: ['f'], + }, + { + title: 'keyboardShortcuts.task.related', + keys: ['r'], + }, + ], + }, +] diff --git a/src/components/misc/shortcut.vue b/src/components/misc/shortcut.vue index 5d155db20..8c1809eaf 100644 --- a/src/components/misc/shortcut.vue +++ b/src/components/misc/shortcut.vue @@ -1,10 +1,10 @@ diff --git a/src/components/modal/modal.vue b/src/components/modal/modal.vue index 0f05b2190..76fcac454 100644 --- a/src/components/modal/modal.vue +++ b/src/components/modal/modal.vue @@ -12,8 +12,7 @@ class="modal-container" :class="{'has-overflow': overflow}" @click.self.prevent.stop="$emit('close')" - @shortkey="$emit('close')" - v-shortkey="['esc']" + v-shortcut="'Escape'" >