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

gutenberg-sortable-hoc

v1.0.3

Published

A Gutenberg component to turn anything into an animated, touch- and a11y-friendly sortable list. Like these images in a block with desktop wallpapers:

Downloads

4

Readme

Gutenberg Sortable

A Gutenberg component to turn anything into an animated, touch- and a11y-friendly sortable list. Like these images in a block with desktop wallpapers:

images in a wallpaper block that are sorted by dragging and dropping


Features

  • Locked axises
  • Events
  • Smooth animations
  • Auto-scrolling
  • Horizontal, vertical and grid lists
  • Touch support 👌
  • Keyboard support 💪

Installation

Using npm: $ npm install gutenberg-sortable-hoc --save

And then, using a module bundler that supports ES2015 modules (like webpack):

import Sortable from 'gutenberg-sortable-hoc';

//or, if you're not using ES6:
var Sortable = require('gutenberg-sortable-hoc');

Usage

Here's a basic example of the Sortable gutenberg component, used in a block.

    //... skipping the usual registerBlockType settings, and getting straight to the attributes:
    attributes: {
        images: {
            source: 'query',
            selector: 'img',
            query: {
                url: { source: 'attribute', attribute: 'src' },
                alt: { source: 'attribute', attribute: 'alt' }
            }
        }
    },
    edit( props ) {

        let images = ( !props.attributes.images ? [] : props.attributes.images );
        const { className, setAttributes } = props

        return (
            <div className={className}>
                <Sortable
                    className="gallery"
                    items={images}
                    axis="grid"
                    onSortEnd={ ( images ) => setAttributes({ images }) }
                >
                    {images.map((image) =>
                        <img src={image.url} alt={image.alt} class="gallery-image" />
                    )}
                </Sortable>
            </div>
        )
    },
    //... rest of the block logic

Let's break that down:

Attributes

When you register an attribute to work with Sortable, it's probably easiest to use a source: 'query' attribute. This makes it so you can just add html or components to your Sortable.

Sortable

Sortable is meant as a wrapper. Wrap it around everything you'd like to be sortable. It will add a parent div around all the children. You should also pass the attribute (in this case images) as a prop called "items". This ensures you will get back the re-sorted prop in your sortable events.

Options

There's a few options you can pass the component:

axis - The axis you'd like to sort on. This example is set to 'grid', but X and Y are also available. Y is the default.

onSortStart - What to do when sorting starts. This is a function that will get the node and it's index plus the event as it's properties returned. A simple example for this:

const highlight = ({node, index}, event) => {
    node.classList.add('highlight');
    console.log( 'the element you\'ve picked up has an index of '+index );
}

<Sortable onSortStart={highlight}>

This will give the picked up node a "highlight" class and log a message with the nodes current index.

onSortEnd - What to do when sorting has finished. This function will return the items you passed along as a prop, but now reordered according to the users' action. In the basic example above we just reset the attribute with the new sorted values.

FAQ

Module not found: can't resolve React-DOM

If you encounter this error while compiling your block, you haven't loaded in React and React Dom from WP Core as an external in your build process. This is because Sortable uses a native React component to provide certain functionality. Add the following to your webpack.config.js, and everything should work fine:

externals: {
    'react': 'React',
    'react-dom': 'ReactDOM'
},

Dependencies

Gutenberg Sortable depends on the react-sortable-hoc package by Claudéric Demers.

Contributions

All help is welcome! Please leave your feature- and/org pull-request here! 😉