npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-cli-keyboard-actions

v0.3.2

Published

EmberCLI addon to generate components that can respond to keyboard events.

Downloads

7

Readme

Ember CLI Keyboard Actions

A small mixin to make intercepting keyboard events easier to pick up and react to.

Installation

ember install:addon ember-cli-keyboard-actions

Changelog

###v0.3.0

  • Added ability to add actions for chords

###v0.2.1

  • Fixed issue where returning true/false from an action wouldn't alter the bubbling of the event.

###v0.2.0

  • Added a catch-all 'any' range that will fire on all keypresses.
  • The keyCode of the pressed key will now be passed to the handler.
  • Abstracted function resolving code out to a separate class.
  • Added code documentation

###v0.1.5

  • Run through ESLint for stricter linting checks.

###v0.1.4

  • Fixed a 'bug' causing keycode ranges to fail.

###v0.1.3

  • Added ability to use a string as the action to have it resolve a function from the view.
  • Added support for a-z and 0-9 as named keys.
  • Added support for 'key range' events.

Importing

Simply import the mixin at the top of your component or view

import KeyboardActionsMixin from 'ember-cli-keyboard-actions/mixins/keyboard-actions.js'

and pass it to your component or view as you would any other mixin.

export default Ember.Component.extend(
  KeyboardActionsMixin,
  {
  }
);

Usage

Create an object on your component or view with one of the following keys to respond to the correct event:

  • keyDownActions
  • keyUpActions
  • keyPressActions

Within this object, specific key events can be defined using either the name of the key, or the word 'key' followed by the correct keyCode.

keyDownActions: {
  backspace: function () {
    console.log('Backspace pressed');
  },
  key27: function () {
    console.log('Escape pressed');
  }
}

Alternatively, setting a string as the action will attempt to resolve the corresponding function from the view.

doSomeStuff: function () {
  console.log('Did some stuff');
},
keyDownActions: {
  backspace: 'doSomeStuff'
},

Key names currently supported:

  • tab
  • backspace
  • enter
  • capsLock
  • escape
  • pageUp
  • pageDown
  • end
  • home
  • left
  • up
  • right
  • down
  • insert
  • delete
  • space
  • a - z
  • 0 - 9

Actions can also be hooked in to a number of 'range' events, for instance declaring a keyDownAction 'alphanumeric' will trigger whenever an alphanumeric key is pressed.

Key ranges currently supported:

  • alphanumeric (a-z, 0-9)
  • alpha (a-z)
  • numeric (0-9)
  • any (ALL keys)

Chords / Shortcuts

A special set of actions can be defined under the key keyChordActions that can be used to assign actions to keys pressed while CTRL, ALT or SHIFT are being held down.

  keyChordActions: {
    'ctrl': {
      'a': function () {
        console.log('Ctrl + A pressed');
      }
    },
    'alt': {
      'a': function () {
        console.log('Alt + A pressed');
      }
    },
    'shift': {
      'a': function () {
        console.log('Shift + A pressed');
      }
    },
    'ctrl.alt': {
      'a': function () {
        console.log('Ctrl, Alt + A pressed');
      }
    },
    'ctrl.alt.shift': {
      'a': function () {
        console.log('Ctrl, Shift, Alt + A pressed');
      }
    }
  },

Full Example

import Ember from 'ember';
import KeyboardActionMixin from 'ember-cli-keyboard-actions/mixins/keyboard-actions.js';

export default Ember.Component.extend(
  KeyboardActionMixin,
  {
    doSomeStuff: function () {
      console.log('Did some stuff');
    },
    recogniseAlphaEvent: function () {
      console.log('Alpha event');
    },
    keyDownActions: {
      backspace: 'doSomeStuff',
      alpha: 'recogniseAlphaEvent',
      numeric: function () {
        console.log('Numeric event');
      }
    },
    keyUpActions: {
      escape: function () {
        console.log('Tab pressed on keyUp');
      }
    },
    keyPressActions: {
      key101: function () {
        console.log('Left pressed on keyPress');
      }
    }
  }
);

For more information on using ember-cli, visit http://www.ember-cli.com/.