import type { FunctionComponent } from "react"; import type { ComponentFactory } from "../../factory/types.js"; import type { PropsWithOptionalContext, PropsWithContext } from "../../context/types.js"; import type { ElementProps, ElementWithChildrenType } from "../type-utils.js"; export type RichTextProps = { /** * The component factory used for this rich text content * * @deprecated The factory from the context will be used */ factory?: ComponentFactory; /** * The rich text to render, provided as either a HTML string or JSON encoded * structured data. */ text: NodeInput | null | undefined; /** * The CSS Class to apply to the text container */ className?: string; /** * Set the component type of the wrapper to use, defaults to a 'div' * element when not defined */ as?: ET | null; /** * Control the debugging output * * @deprecated The debug value from the context will be used */ debug?: boolean; /** * If set to true, the output will be wrapped in a Fragment and no properties * will be set on the Fragment to prevent React errors. */ noWrapper?: boolean; /** * The fieldname of this Rich Text, when it is used as part of a block */ cmsFieldName?: string | null; /** * The Element ID if this is the sole output of a Visual Builder element */ cmsId?: string | null; }; export type RichTextComponent = (props: PropsWithOptionalContext>) => ReturnType; export type RichTextImplProps = PropsWithContext & Omit, keyof RichTextProps>>; export type RichTextElementProps = Readonly<{ debug?: boolean; factory?: ComponentFactory; node: Readonly; idPrefix: string; }>; export type Node = {}; /** * Structured HTML node type for text data */ export type TextNode = Node & { text: string; } & Record; /** * Structured HTML root node */ export type RichTextNode = Node & { type: "richText"; children: Array; }; /** * Structured HTML node for structured * text */ export type StringNode = Node & { type: "string"; children: Array; }; /** * Structured HTML node type with a specific * type defined */ export type TypedNode = NodeWithChildren>; export type NodeWithChildren = T & { children?: Array; }; /** * Allowable data type to provide to the RichText * component */ export type NodeInput = string | RichTextNode | StringNode;