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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tinloof/sanity-document-options

v1.2.1

Published

Configure document actions, badges, templates, and structure directly in your schema definitions.

Readme

@tinloof/sanity-document-options

Configure document actions, badges, templates, and structure directly in your schema definitions.

Installation

npm install @tinloof/sanity-document-options

Basic Setup

Add the plugin to your sanity.config.ts:

import {defineConfig} from "sanity";
import {documentOptions} from "@tinloof/sanity-document-options";

export default defineConfig({
  plugins: [documentOptions()],
});

Disable Structure Tool

If you want to use only document options (actions, badges, templates) without the structure tool:

export default defineConfig({
  plugins: [documentOptions({structure: false})],
});

Features

✅ Zero Configuration

Works out of the box - automatically creates structure from your schemas.

✅ Document Actions & Badges

Configure actions and badges directly in schema options.

✅ Document Templates

Define initial value templates in schemas.

✅ Structure Options

Control how documents appear in the studio structure.

✅ Grouping & Organization

Organize documents into collapsible groups.

✅ Singletons & Ordering

Create single-instance documents or enable drag-and-drop ordering.

✅ Localization Support

Multi-language content with locale-specific views.

Usage Examples

Document Actions

defineType({
  name: "post",
  type: "document",
  options: {
    document: {
      actions: (prev, context) => {
        // Remove delete for published posts
        if (context.published) {
          return prev.filter((action) => action.action !== "delete");
        }
        return prev;
      },
    },
  },
});

Document Badges

defineType({
  name: "article",
  type: "document",
  options: {
    document: {
      badges: (prev, context) =>
        [
          ...prev,
          context.published && {
            label: "Published",
            color: "success",
          },
        ].filter(Boolean),
    },
  },
});

Document Templates

defineType({
  name: "page",
  type: "document",
  options: {
    schema: {
      templates: [
        {
          id: "page-blog",
          title: "Blog Post",
          schemaType: "page",
          value: {category: "blog"},
        },
      ],
    },
  },
});

Structure Groups

defineType({
  name: "settings",
  type: "document",
  options: {
    structureGroup: "configuration",
  },
});

Singleton Documents

defineType({
  name: "homePage",
  type: "document",
  options: {
    structureGroup: "pages",
    structureOptions: {
      singleton: true,
      icon: HomeIcon,
      title: "Home Page",
    },
  },
});

Orderable Documents

defineType({
  name: "menuItem",
  type: "document",
  options: {
    structureGroup: "navigation",
    structureOptions: {
      orderable: true,
      icon: MenuIcon,
    },
  },
});

Localized Documents

// Plugin configuration
documentOptions({
  structure: {
    locales: [
      {id: "en", title: "English"},
      {id: "fr", title: "French"},
    ],
  },
});

// Schema configuration
defineType({
  name: "article",
  type: "document",
  options: {
    localized: true,
  },
  fields: [
    {name: "locale", type: "string", hidden: true},
    // ... other fields
  ],
});

Custom Structure Builder

defineType({
  name: "product",
  type: "document",
  options: {
    structureGroup: "commerce",
    structureOptions: (S, context) =>
      S.listItem()
        .title("Products by Category")
        .child(
          S.list()
            .title("Categories")
            .items([
              S.listItem()
                .title("Electronics")
                .child(
                  S.documentTypeList("product").filter(
                    'category == "electronics"',
                  ),
                ),
            ]),
        ),
  },
});

Plugin Options

documentOptions({
  structure?: {
    locales?: Locale[];        // Locale configuration
    hide?: string[];           // Document types to hide
    toolTitle?: string;        // Structure tool title
    localeFieldName?: string;  // Locale field name (default: "locale")
  } | false,                   // Pass false to disable structure tool
});

Schema Options

interface DocumentOptions {
  // Structure configuration
  structureGroup?: string;
  structureOptions?:
    | StructureBuiltinOptions
    | ((
        S: StructureBuilder,
        context: StructureResolverContext,
      ) => ListItemBuilder);
  localized?: boolean;

  // Document options
  document?: {
    actions?: (prev, context) => DocumentActionComponent[];
    badges?: (prev, context) => DocumentBadgeComponent[];
    newDocumentOptions?: (prev, context) => TemplateItem[];
  };

  // Schema options
  schema?: {
    templates?: Template[] | ((prev, context) => Template[]);
  };
}

Built-in Structure Options

type StructureBuiltinOptions = {
  singleton?: boolean;
  orderable?: boolean;
  icon?: React.ComponentType | React.ReactNode;
  title?: string;
  views?: (S: StructureBuilder) => (View | ViewBuilder)[];
};

License

MIT © Tinloof