@portabletext/types
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -9,4 +9,6 @@ import type { ArbitraryTypedObject, TypedObject } from './related.js'; | ||
* @template C Types allowed as children of this block | ||
* @template S Allowed block styles (eg `normal`, `blockquote`, `h3` etc) | ||
* @template L Allowed list item types (eg `number`, `bullet` etc) | ||
*/ | ||
export interface PortableTextBlock<M extends PortableTextMarkDefinition = PortableTextMarkDefinition, C extends TypedObject = ArbitraryTypedObject | PortableTextSpan> extends TypedObject { | ||
export interface PortableTextBlock<M extends PortableTextMarkDefinition = PortableTextMarkDefinition, C extends TypedObject = ArbitraryTypedObject | PortableTextSpan, S extends string = PortableTextBlockStyle, L extends string = PortableTextListItemType> extends TypedObject { | ||
/** | ||
@@ -40,3 +42,3 @@ * Type name identifying this as a portable text block. | ||
*/ | ||
style?: PortableTextBlockStyle; | ||
style?: S; | ||
/** | ||
@@ -46,3 +48,3 @@ * If this block is a list item, identifies which style of list item this is | ||
*/ | ||
listItem?: PortableTextListItemType; | ||
listItem?: L; | ||
/** | ||
@@ -55,5 +57,10 @@ * If this block is a list item, identifies which level of nesting it belongs within | ||
* Strictly speaking the same as a portable text block, but `listItem` is required | ||
* | ||
* @template M Mark types that be used for text spans | ||
* @template C Types allowed as children of this block | ||
* @template S Allowed block styles (eg `normal`, `blockquote`, `h3` etc) | ||
* @template L Allowed list item types (eg `number`, `bullet` etc) | ||
*/ | ||
export interface PortableTextListItemBlock<M extends PortableTextMarkDefinition = PortableTextMarkDefinition, C extends TypedObject = PortableTextSpan> extends Omit<PortableTextBlock<M, C>, 'listItem'> { | ||
listItem: string; | ||
export interface PortableTextListItemBlock<M extends PortableTextMarkDefinition = PortableTextMarkDefinition, C extends TypedObject = PortableTextSpan, S extends string = PortableTextBlockStyle, L extends string = PortableTextListItemType> extends Omit<PortableTextBlock<M, C, S, L>, 'listItem'> { | ||
listItem: L; | ||
} | ||
@@ -111,1 +118,8 @@ /** | ||
} | ||
/** | ||
* The simplest representation of a link | ||
*/ | ||
export interface PortableTextLink { | ||
_type: 'link'; | ||
href: string; | ||
} |
{ | ||
"name": "@portabletext/types", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Shared TypeScript definitions for core Portable Text data structures", | ||
@@ -5,0 +5,0 @@ "exports": "./dist/index.js", |
@@ -10,3 +10,3 @@ # @portabletext/types | ||
``` | ||
npm install --save-dev @portabletext/types | ||
npm install --save @portabletext/types | ||
``` | ||
@@ -21,3 +21,7 @@ | ||
```ts | ||
import type {PortableTextBlock, PortableTextSpan} from '@portabletext/types' | ||
import type { | ||
PortableTextBlock, | ||
PortableTextSpan, | ||
PortableTextLink | ||
} from '@portabletext/types' | ||
@@ -57,2 +61,16 @@ const headingSpan: PortableTextSpan = { | ||
] | ||
/** | ||
* 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 | ||
> | ||
``` | ||
@@ -59,0 +77,0 @@ |
@@ -10,6 +10,10 @@ import type {ArbitraryTypedObject, TypedObject} from './related.js' | ||
* @template C Types allowed as children of this block | ||
* @template S Allowed block styles (eg `normal`, `blockquote`, `h3` etc) | ||
* @template L Allowed list item types (eg `number`, `bullet` etc) | ||
*/ | ||
export interface PortableTextBlock< | ||
M extends PortableTextMarkDefinition = PortableTextMarkDefinition, | ||
C extends TypedObject = ArbitraryTypedObject | PortableTextSpan | ||
C extends TypedObject = ArbitraryTypedObject | PortableTextSpan, | ||
S extends string = PortableTextBlockStyle, | ||
L extends string = PortableTextListItemType | ||
> extends TypedObject { | ||
@@ -48,3 +52,3 @@ /** | ||
*/ | ||
style?: PortableTextBlockStyle | ||
style?: S | ||
@@ -55,3 +59,3 @@ /** | ||
*/ | ||
listItem?: PortableTextListItemType | ||
listItem?: L | ||
@@ -66,8 +70,15 @@ /** | ||
* Strictly speaking the same as a portable text block, but `listItem` is required | ||
* | ||
* @template M Mark types that be used for text spans | ||
* @template C Types allowed as children of this block | ||
* @template S Allowed block styles (eg `normal`, `blockquote`, `h3` etc) | ||
* @template L Allowed list item types (eg `number`, `bullet` etc) | ||
*/ | ||
export interface PortableTextListItemBlock< | ||
M extends PortableTextMarkDefinition = PortableTextMarkDefinition, | ||
C extends TypedObject = PortableTextSpan | ||
> extends Omit<PortableTextBlock<M, C>, 'listItem'> { | ||
listItem: string | ||
C extends TypedObject = PortableTextSpan, | ||
S extends string = PortableTextBlockStyle, | ||
L extends string = PortableTextListItemType | ||
> extends Omit<PortableTextBlock<M, C, S, L>, 'listItem'> { | ||
listItem: L | ||
} | ||
@@ -143,1 +154,9 @@ | ||
} | ||
/** | ||
* The simplest representation of a link | ||
*/ | ||
export interface PortableTextLink { | ||
_type: 'link' | ||
href: string | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15941
310
78