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

front-slate-edit-list

v0.12.2-1

Published

A Slate plugin to handle keyboard events in lists.

Downloads

28

Readme

slate-edit-list

NPM version Linux Build Status

A Slate plugin to handle keyboard events in lists. List items can contain blocks.

Demo: gitbookio.github.io/slate-edit-list/

Install

npm install slate-edit-list

Features

Natural keybindings:

  • Pressing Enter insert a new list item
  • Pressing Shift+Enter split the block in the list item
  • Pressing Tab increase the depth of the item (creates a sub-list)
  • Pressing Shift+Tab decrease the depth of the item
  • Pressing Delete (OSX) or Backspace at the start, remove the list item (or the list)

Simple validation/normalization (see assumptions about the schema):

  • Lists can contain only list items, and at least one.
  • List items can only be the direct children of a list.
  • List items must always contain blocks.

Useful transforms: see Utilities and Transform.

Simple Usage

import EditList from 'slate-edit-list'

const plugins = [
  EditList()
]

Arguments

This plugin accepts options to redefine the following block types:

  • types: string = ["ol_list", "ul_list"] — the array of possible types for list containers. First value will be used as default.
  • typeItem: string = "list_item" — type for list items.
  • typeDefault: string = "paragraph" — type for default block in list items.
  • canMerge: (Node, Node) => boolean — controls which list can be merged automatically (for example when they are adjacent). Defaults to merging list with identical types

Assumption about the schema

You can use this plugins with custom list block types (using plugin arguments). But your lists structure should still conform to a few rules. These rules are implemented as schema.

Here is what a minimal list would look like:

nodes:
    - kind: block
      type: ul_list # Default type for bulleted lists container
      nodes:
          - kind: block
            type: list_item # List containers can only contain list items
            nodes:
              # List items contain blocks. They cannot be the direct container of text.
              - kind: block
                type: paragraph # Default type of blocks in a list item
                nodes:
                  - kind: text
                    text: Hello World

And here is an example of a multi-level list:

nodes:
  - kind: block
    type: ol_list
    nodes:
      - kind: block
        type: list_item
        nodes:
          - kind: block
            type: paragraph
            nodes:
              - kind: text
                text: Item 1
          - kind: block
            type: ol_list
            nodes:
              - kind: block
                type: list_item
                nodes:
                  - kind: block
                    type: paragraph
                    nodes:
                      - kind: text
                        text: Item 1.1
              - kind: block
                type: list_item
                nodes:
                  - kind: block
                    type: paragraph
                    nodes:
                      - kind: text
                        text: Item 1.2

Utilities and Transform

slate-edit-list exports utilities and transforms:

plugin.utils.isSelectionInList(value: Value, type?: string) => Boolean

Return true if selection is inside a list (and it can be unwrap). Optional param type can be supplied to deduce whether list is of specified type.

plugin.utils.isList(node: Node) => Boolean

Return true if the node is one of the list type.

plugin.utils.getItemDepth(value: Value, block: Block?) => Number

Returns the depth of the current item (or the depth of the given block) in a list. 0 means not in a list.

plugin.utils.getCurrentItem(value: Value, block: Block?) => Block || Void

Returns the current item at selection (or at the given block).

plugin.utils.getCurrentList(value: Value, block: Block?) => Block || Void

Returns the current list at selection (or at the given block).

plugin.utils.getItemsAtRange(value: Value, range: Selection?) => List<Node>

Return the list of items at the given range. The returned items are the highest list of of successive items that cover the given range.

The returned list is empty if no such list can be found.

plugin.changes.increaseItemDepth(change: Change) => Transform

Increase the depth of the current item.

plugin.changes.decreaseItemDepth(change: Change) => Transform

Decrease the depth of the current item.

plugin.changes.wrapInList(change: Change, type: String?, data: Object|Data?) => Transform

Wrap the current blocks in list items of a list container of the given type. You can pass optional data for the created list container.

plugin.changes.unwrapList(change: Change) => Transform

Unwrap all items at range from their list.

plugin.changes.splitListItem(change: Change) => Transform

Split current block into a new list item.