1.0.1 • Published 3 months ago
sanity-plugin-sync-content v1.0.1
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
]
})
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.