@contentful/rich-text-types
Version:
Type definitions and constants for the Contentful rich text field type.
30 lines (29 loc) • 1.73 kB
TypeScript
import { ValidationError } from '.';
import { AssetHyperlink, AssetLinkBlock, EntryHyperlink, EntryLinkBlock, Hyperlink, ResourceLinkBlock, ResourceLinkInline } from '../nodeTypes';
import { Block, Document, Inline } from '../types';
import type { Path } from './path';
export type Node = Document | Block | Inline;
export type GetContentRule<T extends Node> = string[] | ((node: T, path: Path) => {
nodeTypes: string[];
min?: number;
});
export type ValidateData<T extends Node> = (data: T['data'], path: Path) => ValidationError[];
export declare const VOID_CONTENT: GetContentRule<Node>;
export declare class NodeAssertion<T extends Node = Node> {
private contentRule;
private validateData?;
constructor(contentRule: GetContentRule<T>, validateData?: ValidateData<T>);
assert(node: T, path: Path): ValidationError[];
}
export declare class EntityLinkAssertion<T extends EntryLinkBlock | EntryHyperlink | AssetLinkBlock | AssetHyperlink | ResourceLinkBlock | ResourceLinkInline> extends NodeAssertion<T> {
private linkType;
private type;
constructor(linkType: 'Entry' | 'Asset' | 'Contentful:Entry', contentNodeTypes: GetContentRule<T>);
private assertLink;
}
export declare class HyperLinkAssertion<T extends Hyperlink> extends NodeAssertion<T> {
constructor();
private assertLink;
}
export declare const assert: <T extends Node>(contentRule: GetContentRule<T>, validateData?: ValidateData<T>) => NodeAssertion<T>;
export declare const assertLink: <T extends EntryLinkBlock | EntryHyperlink | AssetLinkBlock | AssetHyperlink | ResourceLinkBlock | ResourceLinkInline>(linkType: "Entry" | "Asset" | "Contentful:Entry", contentRule: GetContentRule<T>) => EntityLinkAssertion<T>;