import { type ReactNode } from 'react'; /** * Formatted text, drawn: headings, paragraphs, lists, a quote, code, a divider, * a table and links. * * Both apps drew the same thing twice, from the same source — the text tree the * protocol package builds (`toRenderTree` → `RenderBlock`, `RenderInline`) — * and the two had drifted: headings, list markers, quotes and code differed, * one app had tables and the other dropped them, one had links and the other * printed the brackets (UIG-30). The look here is Katerina's picks of * 28 September, one per difference, most of them Peek's, with the room and * colours she changed on 9 October. * * **It takes the tree, not the text.** The caller parses (the format comes from * the item's tag, never from the body) and hands the blocks in. So this package * does not depend on the protocol, and a caller can leave out a block it draws * elsewhere before passing the rest. The types below are the tree's shape; the * protocol's own types fit them. * * **Safe by construction.** The tree has nothing left to parse, and every * string here reaches the page as a React child, so it is text. Nothing is set * as HTML. * * **What a word points at stays the app's.** A person, an item from another * app, a name the app recognises in plain text: `renderReference`, * `renderText` and `renderBlock` are where each app draws its own. */ /** A run of text and the marks on it — the protocol's `RenderInline`. */ export interface RichTextRun { text: string; marks: readonly string[]; /** A `nostr:` address this run stands for. `text` is the address itself. */ reference?: string; } /** A block of the tree — the protocol's `RenderBlock`. */ export interface RichTextBlock { type: string; /** What the document called a block the tree does not know. */ typeName?: string; /** The block's address, when it has one. Drawn as `data-block-id`. */ id?: string; level?: 1 | 2 | 3; language?: string; /** A numbered list's first number. */ start?: number; /** How far a list item is indented under the items above it. A list's items stay flat; this draws them nested. */ indent?: number; /** A checklist item's tick: `true` or `false`, absent on a plain item. */ checked?: boolean; /** A callout's tone (`note`, `tip`, `important`, `warning`, `caution`), absent on a plain quote. */ tone?: string; attrs?: Record; inline?: readonly RichTextRun[]; children?: readonly RichTextBlock[]; } export type RichTextSize = 'default' | 'small'; export interface RichTextProps { /** The tree, already parsed. */ blocks: readonly RichTextBlock[]; /** * Default `default`, the size of text you read. `small` is the same text one * step down, with every heading, list, quote and table kept: an item shown * inside a card. */ size?: RichTextSize; /** * Draws plain text: what is left of a run once its links are drawn. Where an * app turns words it recognises into chips. By default the text as it is. */ renderText?: (text: string) => ReactNode; /** Draws a run that stands for an address. By default its text. */ renderReference?: (reference: string, run: RichTextRun) => ReactNode; /** * Draws a block this part has no design for (an attachment, a widget). Return * `undefined` to leave it to the part, which draws its words. */ renderBlock?: (block: RichTextBlock) => ReactNode | undefined; /** * Draws something after a line of text: after a paragraph, a heading or a * quote, and inside a list item or a table cell after its words — where a * document's chip asks for its card (SPEC §13.3). Asked of every such line; * return nothing for most. */ renderAfter?: (block: RichTextBlock) => ReactNode; /** * Ticks or unticks a checklist item, by its block id: its box is then a * control, one click where the text is read. Without it the box is a picture * of the state — for someone who may not change the text. */ onTick?: (blockId: string, checked: boolean) => void; } /** * RichText's look, for a box you draw yourself: an editor's, so that what is * being written looks the same as what is read. Put it on the editor's root. */ export declare function richTextClassName(size?: RichTextSize, className?: string): string; /** The tone a callout is drawn in: its own, or `note` for one this part does not know (§13.3). */ export declare function calloutLook(tone: string): string; export declare function RichText({ blocks, size, renderText, renderReference, renderBlock, renderAfter, onTick, }: RichTextProps): import("react").JSX.Element | null; //# sourceMappingURL=RichText.d.ts.map