How to use the @sanity/initial-value-templates.getTemplates function in @sanity/initial-value-templates

To help you get started, we’ve selected a few @sanity/initial-value-templates examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanity-io / sanity / packages / @sanity / structure / src / InitialValueTemplateItem.ts View on Github external
export function defaultInitialValueTemplateItems(
  schema: Schema = getDefaultSchema()
): InitialValueTemplateItemBuilder[] {
  const templates = getTemplates()
    // Don't list templates that require parameters
    .filter(tpl => !tpl.parameters || tpl.parameters.length === 0)
    // Don't list templates that we can't create
    .filter(tpl => isActionEnabled(schema.get(tpl.schemaType), 'create'))

  // Sort templates by their schema type, in order or definition
  const typeNames = schema.getTypeNames()
  const ordered = templates.sort(
    (a, b) => typeNames.indexOf(a.schemaType) - typeNames.indexOf(b.schemaType)
  )

  // Create actual template items out of the templates
  return ordered.map(tpl => StructureBuilder.initialValueTemplateItem(tpl.id))
}

@sanity/initial-value-templates

Build templates for initial values

MIT
Latest version published 1 year ago

Package Health Score

81 / 100
Full package analysis