rich-text-solid-renderer
Version:
contentful rich text renderer for solid js
284 lines (283 loc) • 7.46 kB
TypeScript
/** @format */
export declare enum MARKS {
BOLD = "bold",
ITALIC = "italic",
UNDERLINE = "underline",
CODE = "code"
}
/**
* Map of all Contentful block types. Blocks contain inline or block nodes.
*/
export declare enum BLOCKS {
DOCUMENT = "document",
PARAGRAPH = "paragraph",
HEADING_1 = "heading-1",
HEADING_2 = "heading-2",
HEADING_3 = "heading-3",
HEADING_4 = "heading-4",
HEADING_5 = "heading-5",
HEADING_6 = "heading-6",
OL_LIST = "ordered-list",
UL_LIST = "unordered-list",
LIST_ITEM = "list-item",
HR = "hr",
QUOTE = "blockquote",
EMBEDDED_ENTRY = "embedded-entry-block",
EMBEDDED_ASSET = "embedded-asset-block",
TABLE = "table",
TABLE_ROW = "table-row",
TABLE_CELL = "table-cell",
TABLE_HEADER_CELL = "table-header-cell"
}
export declare enum INLINES {
HYPERLINK = "hyperlink",
ENTRY_HYPERLINK = "entry-hyperlink",
ASSET_HYPERLINK = "asset-hyperlink",
EMBEDDED_ENTRY = "embedded-entry-inline"
}
declare type EmptyNodeData = Record<string, never>;
export interface Heading1 extends Block {
nodeType: BLOCKS.HEADING_1;
data: EmptyNodeData;
content: Array<Inline | Text>;
}
export interface Heading2 extends Block {
nodeType: BLOCKS.HEADING_2;
data: EmptyNodeData;
content: Array<Inline | Text>;
}
export interface Heading3 extends Block {
nodeType: BLOCKS.HEADING_3;
data: EmptyNodeData;
content: Array<Inline | Text>;
}
export interface Heading4 extends Block {
nodeType: BLOCKS.HEADING_4;
data: EmptyNodeData;
content: Array<Inline | Text>;
}
export interface Heading5 extends Block {
nodeType: BLOCKS.HEADING_5;
data: EmptyNodeData;
content: Array<Inline | Text>;
}
export interface Heading6 extends Block {
nodeType: BLOCKS.HEADING_6;
data: EmptyNodeData;
content: Array<Inline | Text>;
}
export interface Paragraph extends Block {
nodeType: BLOCKS.PARAGRAPH;
data: EmptyNodeData;
content: Array<Inline | Text>;
}
export interface Quote extends Block {
nodeType: BLOCKS.QUOTE;
data: EmptyNodeData;
content: Paragraph[];
}
export interface Hr extends Block {
nodeType: BLOCKS.HR;
/**
*
* @maxItems 0
*/
data: EmptyNodeData;
content: Array<Inline | Text>;
}
export interface OrderedList extends Block {
nodeType: BLOCKS.OL_LIST;
data: EmptyNodeData;
content: ListItem[];
}
export interface UnorderedList extends Block {
nodeType: BLOCKS.UL_LIST;
data: EmptyNodeData;
content: ListItem[];
}
export interface ListItem extends Block {
nodeType: BLOCKS.LIST_ITEM;
data: EmptyNodeData;
content: ListItemBlock[];
}
export interface Link<T extends string = string> {
sys: {
type: 'Link';
linkType: T;
id: string;
};
}
export interface EntryLinkBlock extends Block {
nodeType: BLOCKS.EMBEDDED_ENTRY;
data: {
target: Link<'Entry'>;
};
/**
*
* @maxItems 0
*/
content: Array<Inline | Text>;
}
export interface AssetLinkBlock extends Block {
nodeType: BLOCKS.EMBEDDED_ASSET;
data: {
target: Link<'Asset'>;
};
/**
*
* @maxItems 0
*/
content: Array<Inline | Text>;
}
export interface EntryLinkInline extends Inline {
nodeType: INLINES.EMBEDDED_ENTRY;
data: {
target: Link<'Entry'>;
};
/**
*
* @maxItems 0
*/
content: Text[];
}
export interface Hyperlink extends Inline {
nodeType: INLINES.HYPERLINK;
data: {
uri: string;
};
content: Text[];
}
export interface AssetHyperlink extends Inline {
nodeType: INLINES.ASSET_HYPERLINK;
data: {
target: Link<'Asset'>;
};
content: Text[];
}
export interface EntryHyperlink extends Inline {
nodeType: INLINES.ENTRY_HYPERLINK;
data: {
target: Link<'Entry'>;
};
content: Text[];
}
export interface TableCell extends Block {
nodeType: BLOCKS.TABLE_HEADER_CELL | BLOCKS.TABLE_CELL;
data: {
colspan?: number;
rowspan?: number;
};
/**
* @minItems 1
*/
content: Paragraph[];
}
export interface TableHeaderCell extends TableCell {
nodeType: BLOCKS.TABLE_HEADER_CELL;
}
export interface TableRow extends Block {
nodeType: BLOCKS.TABLE_ROW;
data: EmptyNodeData;
/**
* @minItems 1
*/
content: TableCell[];
}
export interface Table extends Block {
nodeType: BLOCKS.TABLE;
data: EmptyNodeData;
/**
* @minItems 1
*/
content: TableRow[];
}
/**
* @additionalProperties true
*/
export declare type NodeData = Record<string, any>;
export interface Node {
readonly nodeType: string;
data: NodeData;
}
export interface Block extends Node {
nodeType: BLOCKS;
content: Array<Block | Inline | Text>;
}
export interface Inline extends Node {
nodeType: INLINES;
content: Array<Inline | Text>;
}
export interface TopLevelBlock extends Block {
nodeType: TopLevelBlockEnum;
}
export interface Document extends Node {
nodeType: BLOCKS.DOCUMENT;
content: TopLevelBlock[];
}
export interface Text extends Node {
nodeType: 'text';
value: string;
marks: Mark[];
}
export interface Mark {
type: string;
}
export interface ListItemBlock extends Block {
nodeType: ListItemBlockEnum;
}
export declare type TopLevelBlockEnum = BLOCKS.PARAGRAPH | BLOCKS.HEADING_1 | BLOCKS.HEADING_2 | BLOCKS.HEADING_3 | BLOCKS.HEADING_4 | BLOCKS.HEADING_5 | BLOCKS.HEADING_6 | BLOCKS.OL_LIST | BLOCKS.UL_LIST | BLOCKS.HR | BLOCKS.QUOTE | BLOCKS.EMBEDDED_ENTRY | BLOCKS.EMBEDDED_ASSET | BLOCKS.TABLE;
/**
* Array of all top level block types.
* Only these block types can be the direct children of the document.
*/
export declare const TOP_LEVEL_BLOCKS: TopLevelBlockEnum[];
export declare type ListItemBlockEnum = BLOCKS.PARAGRAPH | BLOCKS.HEADING_1 | BLOCKS.HEADING_2 | BLOCKS.HEADING_3 | BLOCKS.HEADING_4 | BLOCKS.HEADING_5 | BLOCKS.HEADING_6 | BLOCKS.OL_LIST | BLOCKS.UL_LIST | BLOCKS.HR | BLOCKS.QUOTE | BLOCKS.EMBEDDED_ENTRY | BLOCKS.EMBEDDED_ASSET;
/**
* Array of all allowed block types inside list items
*/
export declare const LIST_ITEM_BLOCKS: TopLevelBlockEnum[];
export declare const TABLE_BLOCKS: BLOCKS[];
/**
* Array of all void block types
*/
export declare const VOID_BLOCKS: BLOCKS[];
/**
* Dictionary of all container block types, and the set block types they accept as children.
*
* Note: This does not include `[BLOCKS.DOCUMENT]: TOP_LEVEL_BLOCKS`
*/
export declare const CONTAINERS: {
"ordered-list": BLOCKS[];
"unordered-list": BLOCKS[];
"list-item": TopLevelBlockEnum[];
blockquote: BLOCKS[];
table: BLOCKS[];
"table-row": BLOCKS[];
"table-cell": BLOCKS[];
"table-header-cell": BLOCKS[];
};
/**
* Array of all heading levels
*/
export declare const HEADINGS: BLOCKS[];
/**
* Array of all block types that may contain text and inline nodes.
*/
export declare const TEXT_CONTAINERS: BLOCKS[];
/**
* Node types before `tables` release.
*/
export declare const V1_NODE_TYPES: string[];
/**
* Checks if the node is an instance of Inline.
*/
export declare function isInline(node: Node): node is Inline;
/**
* Checks if the node is an instance of Block.
*/
export declare function isBlock(node: Node): node is Block;
/**
* Checks if the node is an instance of Text.
*/
export declare function isText(node: Node): node is Text;
export {};