Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@portabletext/types

portabletext724.9kMIT2.0.13TypeScript support: included

Shared TypeScript definitions for core Portable Text data structures

portable-text

readme

@portabletext/types

npm versionBuild Status

TypeScript types for Portable Text

Installation

npm install --save @portabletext/types

Documentation

See https://portabletext.github.io/types/

Usage

import type {
  PortableTextBlock,
  PortableTextSpan,
  PortableTextLink
} from '@portabletext/types'

const headingSpan: PortableTextSpan = {
  _type: 'span',
  _key: '5p4n',
  text: 'A simple Portable Text heading block',
  marks: [],
}

const myBlocks: PortableTextBlock[] = [
  {
    _type: 'block',
    _key: 'abc123',
    style: 'h1',
    children: [headingSpan],
    markDefs: [],
  },
  {
    _type: 'block',
    _key: 'xyz987',
    style: 'normal',
    children: [
      {_type: 'span', _key: 'c7', text: 'Check out the ', marks: []}
      {_type: 'span', _key: 'x2', text: 'TypeScript definitions', marks: ['m4hl1nk']},
      {_type: 'span', _key: 'u5', text: ' if you are using TS!', marks: []}
    ],
    markDefs: [
      {
        _key: 'm4hl1nk',
        _type: 'link',
        href: 'https://github.com/portabletext/types'
      }
    ],
  },
]

/**
 * Very specific Portable Text block, where:
 * - Only link and author references (custom) are allowed as marks
 * - Only Portable Text spans and `localCurrency` objects can be inline children
 * - Blocks can only be of style `normal` or `call-to-action` (custom)
 * - List items can only be of type `bullet`
 */
type MyCustomBlock = PortableTextListItemBlock<
  PortableTextLink | AuthorReference, // `M`: Marks
  PortableTextSpan | LocalCurrency,   // `C`: Children
  'normal' | 'call-to-action',        // `S`: Styles
  'bullet'                            // `L`: List item types
>

License

MIT © Sanity.io

changelog

📓 Changelog

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.0.13 (2024-04-10)

Bug Fixes

  • deps: update dependency @sanity/pkg-utils to ^6.3.0 (#74) (88c52d4)

2.0.12 (2024-04-05)

Bug Fixes

2.0.11 (2024-03-20)

Bug Fixes

  • deps: update dependency @sanity/pkg-utils to ^5.1.4 (#65) (fc74584)

2.0.10 (2024-03-18)

Bug Fixes

2.0.9 (2024-03-16)

Bug Fixes

2.0.8 (2023-10-10)

Bug Fixes

  • deps: update dependency @sanity/pkg-utils to v3 (#42) (a4547af)

2.0.7 (2023-09-28)

Bug Fixes

  • ci: switch to release-please (b13b11d)

2.0.6 (2023-08-23)

Bug Fixes

2.0.5 (2023-06-23)

Bug Fixes

  • update TypeScript to v5 (f0266bf)

2.0.4 (2023-06-23)

Bug Fixes

2.0.3 (2023-06-23)

Bug Fixes

  • bump pkg-utils (cfa0679)
  • remove pkg.exports.node condition (3a8e353)

2.0.2 (2023-01-30)

Bug Fixes