@kaliber/sanity-plugin-duplicate

2.0.3 • Public • Published

Sanity plugin duplicate

Replaces the default duplicate function of Sanity and allows for the schema to determine how to handle duplication of specific fields.

Installation

> yarn add @kaliber/sanity-plugin-duplicate

config/default.js

{
  kaliber: [
    compileWithBabel: [
      /@kaliber\/sanity-plugin-duplicate/,
      ...
    ],
    ...
  ],
  ...
}

admin/sanity.config.js

defineConfig({
    ...

    plugins: [
      preview({ reportError }),
      ...
    ],
})

Signatures of reportError:

(e: Error) => void

Additional setup

Customize duplication can be done by setting the Kaliber duplicate option.

import { clear } from '@kaliber/sanity-plugin-duplicate'

export const page = {
  type: 'document',
  name: 'page',
  title: 'Page',
  ...
  fields: [
    {
      title: 'My Field',
      name: 'myField',
      type: 'string',
      ...
      options: {
        kaliber: {
          duplicate: clear,
          ...
        },
        ...
      }
    }
  ]

The duplicate option allows for the following values:

  • A regular value, this value is used in the duplication
  • The clear symbol, the field is cleared (removed) during duplication
  • A function, the function is called with the current value to generate a new value

Common example for things like titles:

  options: {
    kaliber: {
      duplicate(previousValue) {
        return `${previousValue} (copy)`
      }
    }
  }

Development

> yarn
> yarn link
project/> yarn link @kaliber/sanity-plugin-duplicate
project/> yarn add @kaliber/sanity-plugin-duplicate@link:./node_modules/@kaliber/sanity-plugin-duplicate

Publish

yarn publish
git push
git push --tags

Disclaimer

This library is intended for internal use, we provide no support, use at your own risk.

Package Sidebar

Install

npm i @kaliber/sanity-plugin-duplicate

Weekly Downloads

2

Version

2.0.3

License

MIT

Unpacked Size

16.3 kB

Total Files

16

Last publish

Collaborators

  • nhoenderop
  • erwin-kaliber
  • melissabos18
  • janbru
  • albertkaliber
  • jerryduijm
  • hjsielcken
  • kaliber-owner
  • daveykropf
  • eecolor