github.com/hernad/nomad@v1.6.112/ui/app/modifiers/keyboard-shortcut.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { inject as service } from '@ember/service'; 7 import Modifier from 'ember-modifier'; 8 import { registerDestructor } from '@ember/destroyable'; 9 10 export default class KeyboardShortcutModifier extends Modifier { 11 @service keyboard; 12 @service router; 13 14 modify( 15 element, 16 _positional, 17 { 18 label, 19 pattern = '', 20 action = () => {}, 21 menuLevel = false, 22 enumerated = false, 23 exclusive = false, 24 } 25 ) { 26 let commands = [ 27 { 28 label, 29 action, 30 pattern, 31 element, 32 menuLevel, 33 enumerated, 34 exclusive, 35 }, 36 ]; 37 38 this.keyboard.addCommands(commands); 39 registerDestructor(this, () => { 40 this.keyboard.removeCommands(commands); 41 }); 42 } 43 }