Vue2.x plugin to create scoped or global shortcuts. No need to import a vue component into the template.

Overview

vue2-shortcut

Vue2.x plugin to create scoped or global shortcuts. No need to import a vue component into the template.

AppVeyor

Codacy Badge

Install

$ npm install --save vue2-shortcut

Usage

import Vue from 'vue';
import vShortcut from 'vue2-shortcut';
Vue.use(vShortcut);

Optional global config

You can define excludeTags or customized preventWhen function globally to prevent shortcuts from being executed

  • excludeTags: a list of html tags where shortcuts should not be triggered
  • preventWhen: a global interceptor function which returns true
  Vue.use(vShortcut, {
    excludeTags: ['input', 'textarea'],
    preventWhen: (e) => true // prevents all shortcuts
  })

Check the demo here

Define scopes for shortcuts

By default, the shorcuts will work globally. Optionally, if you want to restrict shorcuts within certain scopes, it's also easy to define a scope in vue template like this:

  <div v-shortcut-scope="'a'">
    Component A
  </div>

Then you could pass ['a'] as value for the scope property when creating shortcuts. In this way, shorcuts are triggered only when you are currently interacting with Component A

Register shortcuts

Register your shortcuts in any vue template under the mounted hook

  mounted() {
    Vue.createShortcuts(this, [
      {
        keys: ['ctrl', 'c'],
        scope: ['a'], // optional
        eventHandler: () => {
          console.log('pressing ctrl and c in scope a');
          console.log('executed once');
        },
        once: true, // optional, false by default
        unordered: true // optional, false by default
      }
    ])
  }

Deregister shortcuts

When the template is destroyed, shortcuts registered in that template will be removed automatically

Key List

Below is the list of keys mapping. Use ctrl if you want a shortcut to work with meta on mac and control on windows.

Keyboard shortcut key
A - Z a - z
0 - 9 0 - 9
F1 - F12 f1 - f12
Escape esc
Backquote backquote
Minus minus
Equal equal
Backspace del
Tab tab
CapsLock capslock
Space space
Pause pause
Delete del
ContextMenu contextmenu
BracketLeft bracketleft
BracketRight bracketright
Backslash backslash
Semicolon semicolon
Quote quote
Enter enter
Comma comma
Period period
Slash slash
ArrowLeft arrowleft
ArrowUp arrowup
ArrowRight arrowright
ArrowDown arrowdown
Control control
Shift shift
Alt alt
Meta meta
You might also like...

:eyes: Vue in React, React in Vue. Seamless integration of the two. :dancers:

vuera NOTE: This project is looking for a maintainer! Use Vue components in your React app: import React from 'react' import MyVueComponent from './My

Dec 30, 2022

🎉 基于 vite 2.0 + vue 3.0 + vue-router 4.0 + vuex 4.0 + element-plus 的后台管理系统vue3-element-admin

vue3-element-admin 🎉 基于 Vite 2.0 + Vue3.0 + Vue-Router 4.0 + Vuex 4.0 + element-plus 的后台管理系统 简介 vue3-element-admin 是一个后台前端解决方案,它基于 vue3 和 element-plu

Nov 28, 2022

Jenesius vue modal is simple library for Vue 3 only

Jenesius Vue Modal Jenesius vue modal is simple library for Vue 3 only . Site Documentation Installation npm i jenesius-vue-modal For add modals in yo

Dec 30, 2022

Mosha-vue-toastify - A light weight and fun Vue 3 toast or notification or snack bar or however you wanna call it library.

Mosha-vue-toastify - A light weight and fun Vue 3 toast or notification or snack bar or however you wanna call it library.

Mosha Vue Toastify A lightweight and fun Vue 3 toast or notification or snack bar or however you wanna call it library. English | 简体中文 Talk is cheap,

Jan 2, 2023

📓 The UI component explorer. Develop, document, & test React, Vue, Angular, Web Components, Ember, Svelte & more!

📓 The UI component explorer. Develop, document, & test React, Vue, Angular, Web Components, Ember, Svelte & more!

Build bulletproof UI components faster Storybook is a development environment for UI components. It allows you to browse a component library, view the

Jan 9, 2023

🐉 Material Component Framework for Vue

🐉 Material Component Framework for Vue

Supporting Vuetify Vuetify is a MIT licensed project that is developed and maintained full-time by John Leider and Heather Leider; with support from t

Jan 3, 2023

Universal select/multiselect/tagging component for Vue.js

Universal select/multiselect/tagging component for Vue.js

vue-multiselect Probably the most complete selecting solution for Vue.js 2.0, without jQuery. Documentation Visit: vue-multiselect.js.org Sponsors Gol

Jan 6, 2023

:clipboard: A schema-based form generator component for Vue.js

:clipboard: A schema-based form generator component for Vue.js

vue-form-generator A schema-based form generator component for Vue.js. Demo JSFiddle simple example CodePen simple example Features reactive forms bas

Dec 27, 2022

A multi-select component with nested options support for Vue.js

A multi-select component with nested options support for Vue.js

vue-treeselect A multi-select component with nested options support for Vue.js Features Single & multiple select with nested options support Fuzzy mat

Jan 5, 2023
Comments
  • Create demo page to showcase the use of v-shortcut

    Create demo page to showcase the use of v-shortcut

    • The page should consist of different sections or scopes
    • The current active scope(the one you last clicked) should be highlighted and the shortcuts component should switch to that tab
    • If any of the listed shortcut is fired, we should print it out and show it on the scope. Meanwhile, the shortcut should be highlighted in the list
    enhancement later 
    opened by Graxi 0
Owner
Graxi
Once a good programmer, always a good programmer~
Graxi
A plugin that can help you create project friendly with Vue for @vue/cli 4.5

vue-cli-plugin-patch A plugin that can help you create project friendly with Vue for @vue/cli 4.5. Install First you need to install @vue/cli globally

null 2 Jan 6, 2022
Everything you wish the HTML