@portabletext/toolkit - v6.0.0
    Preparing search index...

    Function nestLists

    • Takes an array of blocks and returns an array of nodes optimized for rendering in HTML-like environment, where lists are nested inside of eachother instead of appearing "flat" as in native Portable Text data structures.

      Note that the list node is not a native Portable Text node type, and thus is represented using the @list type name ({_type: '@list'}).

      The nesting can be configured in two modes:

      • direct: deeper list nodes will appear as a direct child of the parent list
      • html, deeper list nodes will appear as a child of the last list item in the parent list

      When using direct, all list nodes will be of type ToolkitPortableTextDirectList, while with html they will be of type ToolkitPortableTextHtmlList

      These modes are available as LIST_NEST_MODE_HTML and LIST_NEST_MODE_DIRECT.

      In both modes, a list node is always nested as deeply as its level says it is. List items can start at any level and skip any number of levels, so the levels that were never authored are generated to keep the two in sync - meaning renderers can indent by tree depth or by level and get the same result. A generated list holds an empty list item in html mode, since HTML can only nest a list inside a list item, and holds nothing but the deeper list in direct mode.

      Type Parameters

      • T extends TypedObject =
            | TypedObject
            | PortableTextBlock<
                PortableTextMarkDefinition,
                PortableTextSpan
                | ArbitraryTypedObject,
                PortableTextBlockStyle,
                PortableTextListItemType,
            >

      Parameters

      • blocks: T[]

        Array of Portable Text blocks and other arbitrary types

      • mode: "direct"

        Mode to use for nesting, direct or html

      Returns (ToolkitPortableTextDirectList | T)[]

      Array of potentially nested nodes optimized for rendering

    • Takes an array of blocks and returns an array of nodes optimized for rendering in HTML-like environment, where lists are nested inside of eachother instead of appearing "flat" as in native Portable Text data structures.

      Note that the list node is not a native Portable Text node type, and thus is represented using the @list type name ({_type: '@list'}).

      The nesting can be configured in two modes:

      • direct: deeper list nodes will appear as a direct child of the parent list
      • html, deeper list nodes will appear as a child of the last list item in the parent list

      When using direct, all list nodes will be of type ToolkitPortableTextDirectList, while with html they will be of type ToolkitPortableTextHtmlList

      These modes are available as LIST_NEST_MODE_HTML and LIST_NEST_MODE_DIRECT.

      In both modes, a list node is always nested as deeply as its level says it is. List items can start at any level and skip any number of levels, so the levels that were never authored are generated to keep the two in sync - meaning renderers can indent by tree depth or by level and get the same result. A generated list holds an empty list item in html mode, since HTML can only nest a list inside a list item, and holds nothing but the deeper list in direct mode.

      Type Parameters

      • T extends TypedObject =
            | TypedObject
            | PortableTextBlock<
                PortableTextMarkDefinition,
                PortableTextSpan
                | ArbitraryTypedObject,
                PortableTextBlockStyle,
                PortableTextListItemType,
            >

      Parameters

      • blocks: T[]

        Array of Portable Text blocks and other arbitrary types

      • mode: "html"

        Mode to use for nesting, direct or html

      Returns (ToolkitPortableTextHtmlList | T)[]

      Array of potentially nested nodes optimized for rendering

    • Takes an array of blocks and returns an array of nodes optimized for rendering in HTML-like environment, where lists are nested inside of eachother instead of appearing "flat" as in native Portable Text data structures.

      Note that the list node is not a native Portable Text node type, and thus is represented using the @list type name ({_type: '@list'}).

      The nesting can be configured in two modes:

      • direct: deeper list nodes will appear as a direct child of the parent list
      • html, deeper list nodes will appear as a child of the last list item in the parent list

      When using direct, all list nodes will be of type ToolkitPortableTextDirectList, while with html they will be of type ToolkitPortableTextHtmlList

      These modes are available as LIST_NEST_MODE_HTML and LIST_NEST_MODE_DIRECT.

      In both modes, a list node is always nested as deeply as its level says it is. List items can start at any level and skip any number of levels, so the levels that were never authored are generated to keep the two in sync - meaning renderers can indent by tree depth or by level and get the same result. A generated list holds an empty list item in html mode, since HTML can only nest a list inside a list item, and holds nothing but the deeper list in direct mode.

      Type Parameters

      • T extends TypedObject =
            | TypedObject
            | PortableTextBlock<
                PortableTextMarkDefinition,
                PortableTextSpan
                | ArbitraryTypedObject,
                PortableTextBlockStyle,
                PortableTextListItemType,
            >

      Parameters

      • blocks: T[]

        Array of Portable Text blocks and other arbitrary types

      • mode: "html" | "direct"

        Mode to use for nesting, direct or html

      Returns (ToolkitPortableTextHtmlList | ToolkitPortableTextDirectList | T)[]

      Array of potentially nested nodes optimized for rendering