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

sanity-plugin-sync-content

v1.2.0

Published

A Sanity plugin for copy and pasting referenced blocks in array type of fields in Sanity Studio. Based on sanity-plugin-copy-paste, but was configured to fit the use cases of our projects needs.

Downloads

48

Readme

Sanity Plugin Sync Content

A Sanity plugin for copy and pasting referenced blocks in array type of fields in Sanity Studio. Based on sanity-plugin-copy-paste, but was configured to fit the use cases of our projects needs.

This is a Sanity Studio v3 plugin.

🔌 Installation

npm install sanity-plugin-sync-content

🧑‍💻 Usage

Add it as a plugin in sanity.config.ts (or .js):

import { defineConfig } from 'sanity';
import { syncContentPlugin } from 'sanity-plugin-sync-content';

export default defineConfig({
  //...
  plugins: [
    // ...other plugins
    syncContentPlugin(),
  ],
});

Just add directly the defineField for copyPaste directly into any of your referenced block array like so:

import { defineConfig } from 'sanity';
import { copyPaste } from 'sanity-plugin-sync-content';

export default defineType({
  name: 'my-section',
  title: 'My Example Section',
  type: 'object',
  fields: [
    copyPaste,
    // ...your-other-fields
  ],
});

📃 Overriding copyPaste field configuration

You can override some of the configuration for the copyPaste field like so:

export default defineType({
  name: 'my-section',
  title: 'My Example Section',
  type: 'object',
  fields: [
    {
      ...copyPaste,
      title: 'The New Copy Paste Title',
      hidden: () => {
        // Some logic

        return true;
      },
      // ...other configurations
    },
    // ...your-other-fields
  ],
});

🌐 Localization

This plugin uses the Studio UI Localization resource bundle, it is now possible to localize the fields to fit your needs.

Here is the default English bundle:

{
  // Title of the schema field
  'schema.title': 'Copy/paste the item',

  // Toast
  'toast.success.copy.title': 'Copied successfully',
  'toast.success.paste.title': 'Pasted successfully',
  'toast.success.duplicate.title':
    'Duplicated to {{pageCount}} pages successfully',
  'toast.warning.duplicate.title':
    'Duplicated to {{pageCount}} pages with some warnings',
  'toast.error.title': 'Something went wrong',

  // Dialog
  'dialog.header.title': 'Duplicate to multiple pages',
  'dialog.checkbox.form.title': 'Ordered by update date',
  'dialog.deselect.title': 'Deselect all',
  'dialog.pasting.title': 'Duplicating to selected pages...',
  'dialog.paste.title': 'Duplicate the block to selected pages',
  'dialog.loading.title': 'Loading some content…',

  // Buttons
  'button.duplicate.title': 'Duplicate to multiple pages',
  'button.copy.title': 'Copy',
  'button.paste.title': 'Paste',
  'button.pasting.title': 'Pasting...',
}

Available locales to be overriden

  • en-US
  • de-DE

If you want to override or add a new language, you will need to create a custom bundle with your desired translations. In order to override/add you must use sanity-plugin-sync-content as the namespace and add it to the i18n object in your sanity plugin configuration. Here is an example:

const myEnglishOverride = defineLocaleResourceBundle({
  // make sure the `locale` language code corresponds to the one you want to override
  locale: 'en-US',
  namespace: 'sanity-plugin-sync-content',
  resources: {
    'button.copy.title': 'My custom Copy title',
  },
});

// sanity.config.ts
export default defineConfig({
  // ...
  i18n: {
    bundles: [myEnglishOverride],
  },
});

📝 License

MIT © Evelan

🧪 Develop & test

This plugin uses @sanity/plugin-kit with default configuration for build & watch scripts.

See Testing a plugin in Sanity Studio on how to run this plugin with hotreload in the studio.

Release new version

Run "CI & Release" workflow. Make sure to select the main branch and check "Release new version".

Semantic release will only release on configured branches, so it is safe to run release on any branch.