Sanity Library Reference Docs
    Preparing search index...

    Class DocumentBuilder

    A DocumentBuilder is used to build a document node.

    Implements

    Index

    Constructors

    Properties

    "[serializableMarker]": true

    Brand consumed by isSerializable (avoids circular instanceof imports)

    Methods

    • Set the view IDs to open as split panes by default when the document is opened. Pass an array of view IDs that match the IDs defined in views(). If specified with 2+ valid view IDs, the document will open in split-pane mode.

      Parameters

      • viewIds: string[]

        Array of view IDs to open as split panes

      Returns DocumentBuilder

      document builder with defaultPanes config. See DocumentBuilder

      S.document()
      .schemaType('article')
      .views([
      S.view.form().id('editor'),
      S.view.component(PreviewPane).id('preview').title('Preview')
      ])
      .defaultPanes(['editor', 'preview']) // Opens both as split panes
    • Configure the document builder to render a singleton.

      Sugar for .schemaType(<schemaType>).documentId(<documentId>), where both values are read from the singleton definition registered under the provided singleton definition id in the document.singletons configuration. A SerializeError is thrown immediately if no such definition exists.

      The singleton's generated initial value template (the template tagged with the singleton definition id) is also selected if it exists, so the singleton's initial value applies deterministically even when the type has multiple templates.

      Subsequent .documentId(...), .schemaType(...), or .initialValueTemplate(...) calls override these defaults, preserving the immutable-builder ergonomics of the rest of DocumentBuilder.

      Parameters

      • singletonId: string

        the singleton definition id

      Returns DocumentBuilder

      document builder configured for the singleton