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

undoer

v0.1.1

Published

Native undo/redo behavior for web

Downloads

21

Readme

Native undo/redo behavior for web. This lets you push native undo stack events onto your pages, so that users can use Ctrl/Cmd-Z—or even use some other gesture (e.g., on iOS devices, you can shake your phone to Undo).

See a writeup on how this works or an awesome maze-based demo for more.

Usage

Install on NPM/Yarn via undoer. You can use this element as a Web Component or as pure, imperative JavaScript.

Web Component

Add the dependency to your JS and register it as a CE:

import UndoerElement from './node_modules/undoer/element.js';
customElements.define('undoer-element', UndoerElement);

Then add the element to your page, optionally adding state attribute to set its zero initial state (otherwise it will be null):

<undoer-element state="initial state"></undoer-element>

Finally, use the element's JavaScript API:

const undoerEl = document.querySelector('undoer-element');

undoerEl.addEventListener('state', (ev) => {
  console.info('user undo or redid', ev.detail);
});

// set new state with
undoerEl.state = 'new state';
undoerEl.state = /* any object */ ;

// or via attribute for string state
undoerEl.setAttribute('state', 'new state');

Imperative JavaScript

You can also use the raw Undoer class without CEs:

import {Undoer} from './node_modules/undoer/undoer.js';
// or
import {Undoer} from 'undoer';  // your build system might allow this

// construct with callback and push state
const initialState = null;  // default is null
const undoer = new Undoer((data) => {
  console.info('user undo or redid', data);
}, initialState);
undoer.push('new state');

Notes

This makes sense as a Web Component as the undo behavior works by adding a hidden <div contentEditable> to your page. In the WC case, this is as a child of the element: in the imperative case, it's added (by default) to document.body.