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

@selvklart/sanity-block-selector

v4.0.4

Published

A custom block selector for Sanity

Downloads

97

Readme

@selvklart/sanity-block-selector

NPM Version

In action

base image search image

Description

Provides a component for overriding the default Sanity block selector - WithBlockSelector. There are two variants, to account for different situations: content-array - for the "Add Item" button at the bottom of content arrays portable-text - for the "..." buttons inside portable text editors

Use

The components should be used as custom input components for the fields you want to have this block selector.

The blockPreviews field controls how the block options are rendered. Each member of the array defines a group, which corresponds to an accordion tab. Each group has a title and blocks it contains, where the keys of the blocks field correspond to the names of blocks in the of array. Inside each of these, you can set a description and a imageURL to an image that represents that block (like an icon, or a preview). Both of these fields are optional, so only the title of the block (as defined in the schema will be shown).

The showOther field can be set to true to create an additional group, which displays all of the blocks defined in the schema that haven't been added to blockPreviews.

The excludedBlocks field is an array of the names of the blocks you want to have hidden from the selector.

With the text field, you can override all of the hardcoded text values in the block selector:

  • addItem: the text in the "Add item" button
  • dialogTitle: the title of the dialog
  • searchPlaceholder: the placeholder of the search input in the dialog
  • other: the name of the Other tab

With the replaceQueriesfield, you can replace the default queries for replacing the built-in block selector buttons in Sanity. By default, the default queries should work, so you shouldn't need to change this. But you have the flexibility to do so if you need to. (This is useful in case Sanity changes the layout of the Studio, and this package doesn't manage to stay up to date with it.).

These queries depend on the type option.

{
    name: 'richPortableText',
    title: 'Text',
    type: 'array',
    of: [...],
    components: {
        input: WithBlockSelector({
            type: 'portable-text',
            blockPreviews: [
                {
                    title: 'Content',
                    blocks: {
                        accordion: {
                            description: ''.
                            imageURL: '',
                        }
                    }
                }
            ],
            showOther: true,
            excludedBlocks: ['extendedBlock'],
            text: {
                addItem: 'Legg til blokk',
            },
            replaceQueries: [
                {
                    level: 'field',
                    query: '[data-testid="insert-menu-auto-collapse-menu"] [data-testid="insert-menu-button"]',
                },
                {
                    level: 'document',
                    query: 'div[data-testid="document-panel-portal"] #menu-button[data-testid="insert-menu-button"]',
                },
            ]
        })
    }
}

Scripts and getting this thing running

To install dependencies:

bun install

To start the react-cosmos documentation:

bun start

To build the package:

bun run build

To publish the package (this will also build the package automatically):

npm publish --access public