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

@cala/react-focused-key-handler

v1.1.2

Published

A key-handler that uses react context to create key handlers focused around a component.

Downloads

64

Readme

react-focused-key-handler

A key-handler that uses react context to create key handlers focused around a component.

Status

| Branch | URL | Build Status | | ------ | ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | main | https://www.npmjs.com/package/@cala/react-focused-key-handler | Actions Status |

Installation

npm install @cala/react-focused-key-handler --save

Premise

This library solves the problem of overlapping keyhandlers in the global space when writing complex keyboard functionality. It achieves this by creating 'Focus Contexts' or layers of keyboard shortcuts that prevent fallthrough (unless specified)

Usage

First, around the border of your application, add the context provider:

import { Provider as KeyHandlerProvider } from '@cala/react-focused-key-handler';

const MyApp = () = >
  // ...

  return (
    <div>
      <KeyHandlerProvider>
        {//... etc ...}
      </KeyHandlerProvider>
    </div>
  );
}

Next, add <FocusGroup> components around the component boundries at the level which you need them. This will prevent other groups from executing under it. Children of the FocusGroup can add <KeyHandler> components as needed.

return (
  <App>
    <Provider>
      // At the layer boundary for this group of key handlers
      <FocusGroup>
        // In the children of the group add keyhandlers as needed.
        <KeyHandler triggers={[{ key: "Escape" }]} handler={handlerStub} />
      </FocusGroup>
    </Provider>
  </App>
);

<KeyHandler> components take one or more Triggers, defined by the schema in ./src/key-handler/index.tsx. In the most simple usage, key should be a key code value as defined by KeyboardEvent.protype.code, e.g. KeyA or ArrowDown.

Key melodies

React-Focused-Key-Handler also supports Key-Melodies! Key-Melodies are multi-key combinations such as dd or dw (which will be familiar commands to any vim users out there). Key-Melodies are implemented by extending <KeyHandler> to allow nesting them. So if we wanted to implement a gg key-melody for scrolling to the top of the page (again in a vim-esque fashion) we would do so like:

return (
  <App>
  //We can set the timeout in miliseconds for the time to wait till the next key in the melody is pressed before resetting 
    <Provider timeOut={3000}>
      <FocusGroup>
        <KeyHandler triggers={[{ key: "KeyG" }]}>
            <KeyHandler
              triggers={[{ key : "KeyG" }]}
              handler={scrollToTopofPage()}
            />
            //We can add/nest as many more keys we want forming an infinite amount of melodies
            <KeyHandler.....>
              <KeyHandler...../>
              .
              .
              .
              <KeyHandler...../>
            </KeyHandler>
            <KeyHandler...../>
            <KeyHandler...../>
            .
            .
            .
            <KeyHandler...../>
        </KeyHandler>
      </FocusGroup>
    </Provider>
  </App>
);

API Limitations

As of now the API does not provide the ability to have a melody share its root note with any other melody's root note or singular <KeyHandler/>'s trigger. While the API will permit you to do this it will cause unknown behaviour in your program. If you find the need to have such an API in your project feel free to extend our API and submit a PR!

Releasing

We use a script that ensures we release from the main branch, and performs the correct npm version and npm publish steps. Here is an example:

# Assuming the current version is: 1.0.0

# bumps major and creates a release candidate, publishing it to the `next` npm tag
# new version: 2.0.0-rc.0
bin/release premajor next

# bumps patch, publishing it to the `latest` npm tag
# new version: 1.0.1
bin/release patch