UNPKG

@limitless-angular/sanity

Version:

A powerful Angular library for Sanity.io integration, featuring Portable Text rendering and optimized image loading.

44 lines (43 loc) 2 kB
import { TemplateRef, Type } from '@angular/core'; import { PortableTextBlock, PortableTextBlockStyle, PortableTextListItemBlock, PortableTextListItemType, TypedObject } from '@portabletext/types'; import type { ToolkitPortableTextList } from '@portabletext/toolkit'; import { PortableTextTypeComponent, PortableTextMarkComponent, PortableTextBlockComponent, PortableTextListItemComponent, PortableTextListComponent } from './directives/portable-text-directives'; export interface PortableTextComponents { types?: Record<string, Type<PortableTextTypeComponent>>; marks?: Record<string, Type<PortableTextMarkComponent> | undefined>; block?: Record<PortableTextBlockStyle, Type<PortableTextBlockComponent>>; list?: Record<PortableTextListItemType, Type<PortableTextListComponent>>; listItem?: Record<PortableTextListItemType, Type<PortableTextListItemComponent>> | Type<PortableTextListItemComponent>; hardBreak?: Type<unknown> | false; } export type NodeType = 'block' | 'mark' | 'blockStyle' | 'listStyle' | 'listItemStyle'; export type MissingComponentHandler = (message: string, options: { type: string; nodeType: NodeType; }) => void; export interface Serializable<T> { node: T; isInline: boolean; } export interface SerializedBlock { _key?: string; children: any[]; isInline: boolean; node: PortableTextBlock | PortableTextListItemBlock; } export interface RenderNodeContext<Node extends TypedObject = TypedObject> { $implicit: Node; isInline: boolean; components: Partial<PortableTextComponents>; } export interface TemplateContext<Node extends TypedObject> { $implicit: Node; isInline?: boolean; components: Partial<PortableTextComponents>; renderNode: TemplateRef<RenderNodeContext>; } /** * A virtual "list" node for Portable Text - not strictly part of Portable Text, * but generated by this library to ease the rendering of lists in HTML etc */ export type PortableTextListBlock = ToolkitPortableTextList;