/** * Base element properties shared by all element types */ export interface BaseElement { children: Node[]; class?: string; [key: string]: unknown; } /** * Generic element for types that don't need special properties */ export interface GenericElement extends BaseElement { type: GenericElementType; } /** * Link element with required href (mapped from url) */ export interface LinkElement extends BaseElement { type: 'link'; url: string; target?: '_blank' | '_self' | '_parent' | '_top'; rel?: string; title?: string; } /** * Image element with required src (mapped from url) */ export interface ImageElement extends BaseElement { type: 'image'; url: string; alt?: string; title?: string; width?: number | string; height?: number | string; loading?: 'lazy' | 'eager'; } /** * Table element with table-specific attributes */ export interface TableElement extends BaseElement { type: 'table'; border?: string | number; cellpadding?: string | number; cellspacing?: string | number; width?: string | number; height?: string | number; } /** * Table cell elements with table-specific attributes */ export interface TableCellElement extends BaseElement { type: 'td' | 'th'; colspan?: number; rowspan?: number; scope?: 'col' | 'row' | 'colgroup' | 'rowgroup'; } /** * Element node (blocks and inline elements) - Discriminated Union * Based on Slate.js JSON structure with type-specific properties */ export type Element = GenericElement | LinkElement | ImageElement | TableElement | TableCellElement; /** * Text node with formatting marks * Based on Slate.js JSON structure */ export type Text = { text: string; bold?: boolean; italic?: boolean; underline?: boolean; code?: boolean; strikethrough?: boolean; [key: string]: unknown; }; /** * Union type for all possible nodes (text or element) * Based on Slate.js JSON structure */ export type Node = Text | Element; /** * Type guard to check if a node is a text node */ export declare function isText(node: Node): node is Text; /** * Type guard to check if a node is an element node */ export declare function isElement(node: Node): node is Element; /** * Props for element renderer components (framework-agnostic) */ export interface BaseElementRendererProps { element: Element; attributes?: Record; text?: string; } /** * Props for leaf renderer components (framework-agnostic) */ export interface BaseLeafRendererProps { leaf: Text; attributes?: Record; text?: string; } /** * Generic mapping from element types to renderer components * Can be specialized for each framework: ElementMap, ElementMap, etc. */ export type BaseElementMap = { [K in ElementType]?: TRenderer; } & { [key: string]: TRenderer; }; /** * Generic mapping from leaf mark types to renderer components * Can be specialized for each framework: LeafMap, LeafMap, etc. */ export type BaseLeafMap = { [K in MarkType]?: TRenderer; } & { [key: string]: TRenderer; }; /** * Generic props for RichText component (framework-agnostic) * Can be specialized for each framework with specific renderer types */ export interface RichTextPropsBase { /** * Slate.js compatible JSON content to render */ content?: { type: 'richText'; children: Node[]; }; /** * Custom components for rendering elements by type */ elements?: BaseElementMap; /** * Custom components for rendering text marks */ leafs?: BaseLeafMap; /** * Whether to decode HTML entities in text content */ decodeHtmlEntities?: boolean; } /** * Available element types in the default implementation * Derived from the actual Element discriminated union to ensure consistency */ export type ElementType = Element['type']; /** * Available text marks in the default implementation */ export type MarkType = 'bold' | 'italic' | 'underline' | 'strikethrough' | 'code'; /** * Configuration for creating HTML components */ export type HtmlComponentConfig = { selfClosing?: boolean; attributes?: Record; className?: string; }; /** * Framework-agnostic renderer configuration */ export type RendererConfig = { elements?: Record; leafs?: Record; unknownElementFallback?: string | TElement; decodeHtmlEntities?: boolean; }; export declare const RESERVED_PROPS: Set; /** * Maps CMS attributes to standard HTML attributes */ export declare function mapAttributes(node: Element): Record; /** * Gets text marks from a text node */ export declare function getTextMarks(leaf: Text): string[]; /** * Extracts plain text content from element children recursively * This provides a developer-friendly way to access text without traversing the tree */ export declare function extractTextContent(children: Node[]): string; /** * Creates type-safe element data based on element type and attributes * This is a utility function that can be used by framework-specific renderers */ export declare function createElementData(type: string, attributes?: Record): Element; /** * Minimal HTML entity decoder to avoid extra deps */ export declare function decodeHTML(input: string): string; /** * Framework-agnostic rendering traversal logic * Returns a tree structure that can be consumed by any framework */ export interface RenderNode { type: 'element' | 'text'; content?: string; elementType?: string; attributes?: Record; marks?: string[]; children?: RenderNode[]; } /** * Converts Slate JSON to framework-agnostic render tree */ export declare function buildRenderTree(nodes: Node[], config?: RendererConfig): RenderNode[]; /** * Default element type mapping */ export declare const defaultElementTypeMap: Record; /** * Available types for generic elements that don't need special properties * Derived from defaultElementTypeMap, excluding elements with specialized interfaces */ export type GenericElementType = Exclude; /** * Default text mark mapping */ export declare const defaultMarkTypeMap: Record;