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

porta11y

v0.3.0

Published

Porta11y is a collection of accessibility-focused annotations, decorators and validators for Sanity’s Portable Text editor.

Downloads

7

Readme

Porta11y

Porta11y is a collection of accessibility-focused annotations, decorators and validators for Sanity’s Portable Text editor.

Portable Text is a JSON based rich text specification for modern content editing platforms. It is designed to be a format for text editing interfaces and for serializing into any human-readable format.

It provides an incredible opportunity to create editing experiences with accessibility in mind. This repository is a collection of Portable Text utilities to enrich the base editor with additional accessibility-related tools. Namely:

  • Lang annotation: an annotation to demark text snippets as being expressed in another language than the main content.
  • Del decorator: a decorator to demark text snippets as being deleted.
  • Ins decorator: a decorator to demark text snippets as being inserted.
  • Sub decorator: a decorator to demark text snippets as being subscript.
  • Sup decorator: a decorator to demark text snippets as being superscript.
  • Fake lists validator: a custom validation function to make sure lists are done via the appropriate list feature and not with text markers, resulting in more semantic HTML.

Annotations

Language switcher

The lang utility provides an annotation to demark an inline text snippet as being expressed in another language than the main content. This is important for screen-readers (WCAG 2.1 SC 3.1.2 and ATAG B.2.1.1). Refer to this article for more information.

Options

| Option name | Default value | Required | | :---------- | :------------------------------- | :------- | | title | Language switcher | No | | name | lang | No | | fieldTitle | Language tag | No | | fieldName | tag | No | | regex | /^[a-z]+(-[a-z]+)?$/i | No | | regexName | language tag | No | | icon | Material Design “Translate” icon | No | | Component | Custom Portable Text renderer | No |

Example

import { lang } from 'porta11y'

export default {
  title: 'Content',
  name: 'content',
  type: 'array',
  of: [
    {
      type: 'block',
      marks: {
        annotations: [
          lang({
            title: 'Autre langue',
            fieldTitle: 'Code de langue',
            /* Other options … */
          }),
        ],
      },
    },
  ],
}

Decorators

Sub

The sub utility is a decorator to mark a text snippet as being subscript.

Options

| Option name | Default value | Required | | :---------- | :------------------------------- | :------- | | title | Sub | No | | value | sub | No | | icon | Material Design “Subscript” icon | No | | Component | sub | No |

Example

import { sub } from 'porta11y'

export default {
  title: 'Content',
  name: 'content',
  type: 'array',
  of: [
    {
      type: 'block',
      marks: {
        decorators: [{ title: 'Strong', value: 'strong' }, sub()],
      },
    },
  ],
}

Sup

The sup utility is a decorator to mark a text snippet as being superscript.

Options

| Option name | Default value | Required | | :---------- | :--------------------------------- | :------- | | title | Sup | No | | value | sup | No | | icon | Material Design “Superscript” icon | No | | Component | sup | No |

Example

import { sup } from 'porta11y'

export default {
  title: 'Content',
  name: 'content',
  type: 'array',
  of: [
    {
      type: 'block',
      marks: {
        decorators: [{ title: 'Strong', value: 'strong' }, sup()],
      },
    },
  ],
}

Deletion

The del utility is a decorator to mark a text snippet as being a text deletion.

Options

| Option name | Default value | Required | | :---------- | :--------------------------------- | :------- | | title | Deletion | No | | value | del | No | | icon | Material Design “PencilMinus” icon | No | | Component | del (+ additional styles) | No |

Example

import { del } from 'porta11y'

export default {
  title: 'Content',
  name: 'content',
  type: 'array',
  of: [
    {
      type: 'block',
      marks: {
        decorators: [{ title: 'Strong', value: 'strong' }, del()],
      },
    },
  ],
}

Insertion

The ins utility is a decorator to mark a text snippet as being a text insertion.

Options

| Option name | Default value | Required | | :---------- | :-------------------------------- | :------- | | title | Insertion | No | | value | ins | No | | icon | Material Design “PencilPlus” icon | No | | Component | ins (+ additional styles) | No |

Example

import { ins } from 'porta11y'

export default {
  title: 'Content',
  name: 'content',
  type: 'array',
  of: [
    {
      type: 'block',
      marks: {
        decorators: [{ title: 'Strong', value: 'strong' }, ins()],
      },
    },
  ],
}

Validations

No fake lists

Sometimes lists on web pages are not marked up as lists, with ul, ol or dl elements, but separate list items with merely returns instead. This validation rule finds those cases.

Options

| Option name | Default value | Required | | :-- | :-- | :-- | | message | This looks like a list, but it is plain text. Use the bulleted list option. | No | | regex | /^\s*[-*+–—]/ | No |

Example

import { noFakeLists } from 'porta11y'

export default {
  title: 'Content',
  name: 'content',
  type: 'array',
  of: [
    {
      type: 'block',
    },
  ],
  validation: Rule => Rule.custom(noFakeLists()),
}