API reference
@salmonui/rich-text
130 exported symbols: 1 component, 26 functions, 1 class, 60 interfaces, 38 types and 4 constants. Each name links its page with the signature, docs and members.
import { … } from '@salmonui/rich-text';Components
RichTextContentRead-only rendering of rich text content; root class salmon-rich-text-content.
Functions
BlockEditorThe block editor (@salmonui/rich-text); value is Block[] JSON.RichTextEditorRich text editor on ProseMirror (@salmonui/rich-text). HTML value, toolbar, quick toolbars, dialogs, mentions, slash and emoji menus.blocksToHtmlSerializes blocks to sanitized HTML in the shared vocabulary (getDataAsHtml). Block ids are written as data-block-id. Pure and server-safe; unsafe values in th…cleanPastedHtmlCleans clipboard HTML for the editors: Word (mso styles, o:p, conditional comments, MsoListParagraph runs into real nested lists from the mso-list levels, clas…createContentEditableMentionTargetA MentionEditorTarget over a contenteditable element.detectPasteSourceDetects Word (desktop and online) and Google Docs clipboard HTML.embedAllowedWhether an iframe src points at an allowed embed host. embedHosts entries are exact hostnames (www.youtube-nocookie.com) or *.example.com for any subdomain of…escapeAttributeEscapes text for use inside a double-quoted HTML attribute value.escapeHtmlEscapes text for use as HTML element content.findBlockFinds a block by id anywhere in the tree (depth-first, document order).findParentIdId of the block's parent (null at the top level, undefined when not found).forEachBlockCalls fn on every block in document order.htmlToBlocksParses HTML into blocks (parseHtmlToBlocks). The HTML is sanitized first. Ids come from data-block-id; missing or duplicate ids get deterministic ones from the…htmlToTextText content of HTML as the editors count it: the sanitized content, block boundaries become blockSeparator, <br> a newline, table cells are separated by tabs,…insertBlocksInserts blocks before or after the block before / after, or into parent's children at index (default: last). Without a position they go at the end. Returns the…loadRichTextEngineLoads the headless ProseMirror engine on demand: const { createEngine } = await loadRichTextEngine().moveBlockMoves a block (with its children) before or after another block, or into another block's children. Moving a block into itself or its own subtree, or relative t…parseHtmlParses an HTML fragment into a tree. Never throws; malformed input yields the closest well-formed tree. <!DOCTYPE> is skipped, CDATA becomes text.pasteNeedsPromptWhether mode: 'prompt' needs to ask for this paste (formatted HTML; plain text never asks).plainTextToHtmlHTML for plain text (plain-text paste): paragraphs on blank lines, <br> on single newlines, runs of spaces kept as no-break spaces, all text escaped. Empty inp…removeBlocksRemoves the blocks with these ids (with their children).sanitizeHtmlSanitizes HTML against the shared vocabulary. Pure and server-safe: no DOM, no globals, deterministic, linear in the input size. sanitizeHtml(sanitizeHtml(x))…sanitizeNodesSanitizes a parsed tree (see sanitizeHtml); returns a new tree.sanitizeUrlReturns the URL to keep for use, or null when it is not allowed. Leading and trailing whitespace and control characters are trimmed and tabs and newlines remov…serializeHtmlSerializes a parsed (or sanitized) tree back to HTML.updateBlockUpdates one block: props are merged, type, content and children replace; or pass a function returning the new block (its id is kept).
Classes
Interfaces
BlockOne block. props by type: - paragraph: textAlign?; heading: level (1..6), textAlign?; - numberedListItem: start? (starts a new numbered list); checklistItem: c…BlockEditorActionsactionsRef.BlockEditorBeforeBlockMoveEventonBeforeBlockMove: preventDefault() cancels the move.BlockEditorBeforePasteEventonBeforePaste: preventDefault() cancels the paste.BlockEditorBlockChangeEventonBlockChange.BlockEditorBlockLocationWhere a block is: parent block id (null at the top level) and index among its siblings.BlockEditorBlockMoveEventonBlockMove.BlockEditorCustomItemA custom entry of the slash menu, block action menu, context menu or inline toolbar.BlockEditorItemContextWhat a custom menu entry receives.BlockEditorLabelsLabels: inserted as label atoms. An item's tone colors the label.BlockEditorMentionsMentions through the contenteditable Mention target.BlockEditorPasteEventonPaste: after pasted content was applied.BlockEditorPropsBlockEditorSelectionCaret position: the block and the character offset in its text.BlockPatchA partial update for updateBlock: props merge, the rest replaces.ContentEditableMentionOptionsEngineOptionsHighlightRangeHtmlCommentA comment (<!-- --> or a bogus comment such as <![if ...]>).HtmlElementAn element of a parsed HTML fragment. Tag and attribute names are lowercase.HtmlTextA text node; value is decoded text (never markup).HtmlToTextOptionsInlineHardBreakInlineLabelInlineLinkInlineMentionInlineTextPasteCleanupOptionsRichTextAiAssistantRichTextAiRequestRichTextBeforeCommandEventRichTextBeforeDialogOpenEventRichTextBeforePopupOpenEventRichTextCommandEventRichTextCommandsTyped commands (actionsRef.current.commands); each returns whether it applied.RichTextContentPropsRichTextEditorActionsactionsRef.current once the engine is mounted.RichTextEditorPropsTMention is the item type of mentions (its renderItem receives it).RichTextEmojiRichTextExtensionAn editor extension: schema nodes and marks, ProseMirror plugins (a factory may be async, for example the /collab Yjs binding), key bindings, input rules, comm…RichTextExtensionContextWhat an extension's plugin factory receives.RichTextExtensionToolbarItemA toolbar item an extension contributes (toolbar refers to it by id).RichTextFindOptionsRichTextImageInputRichTextLinkInputRichTextMediaInputRichTextMentionsRichTextPasteCleanupRichTextQuickToolbarsRichTextSelectionRichTextSlashCustomItemRichTextToolbarCustomItemA custom toolbar item.RichTextToolbarItemClickEventRichTextToolbarItemOptionsA built-in item with per-item options (per-item disabled).RichTextToolbarStateDerived toolbar state (onToolbarStateChange).SanitizeAllowElements and attributes an editor extension adds to the vocabulary (RichTextExtension.html). attributes maps a tag (an extension tag or a vocabulary tag) to ex…SanitizeElementA sanitized element as the sanitize hook sees it (read-only copy).SanitizeHtmlOptionsSerializeHtmlOptionsUploadResult
Types
BlockEditorBlockActionBlockEditorBlockActionIdBlock action menu entries; image and table blocks add their own.BlockEditorCommandIdCommands keyBindings can rebind: the block commands plus every RichTextEditor command id.BlockEditorContextMenuItemBlockEditorContextMenuItemIdContext menu entries.BlockEditorInlineToolbarItemBlockEditorInlineToolbarItemIdInline (selection) toolbar entries.BlockEditorLocaleTextBlockEditorSlashItemBlockEditorSlashItemIdBuilt-in slash menu entries: the transforms plus inserted blocks.BlockEditorTransformIdBlock types a block can be turned into ('turnInto', transforms).BlockPositionWhere blocks go in the insert and move helpers.BlockTypeBlock types.HighlightFnHtmlNodeInlineContentInline content of a block: text with marks, link, mention, label, hard break.InlineMarkInline formatting of text (shared with RichTextEditor marks).PasteCleanupModeHow pasted HTML is treated. 'prompt' asks the user each time (see pasteNeedsPrompt).PasteModePasteSourceWhere pasted HTML comes from, as detectPasteSource sees it.ResolvedPasteCleanupModeA mode the user (or configuration) has decided on.RichTextBulletStyleRichTextCommandNameRichTextDialogIdRichTextEditorLocaleTextRichTextKeyBindingskeyBindings prop: key -> command or action id, a function, or false to remove a default.RichTextOrderedStyleRichTextPopupIdRichTextSlashItemRichTextSlashItemIdRichTextTableStyleRichTextTextAlignRichTextToolbarItemA built-in id, the id of an extension's toolbarItems entry, item options or a custom item.RichTextToolbarItemIdBuilt-in toolbar item ids (shared names with MarkdownEditor where they overlap); '|' is a separator.SanitizeHookExtension hook (sanitize). It runs after the built-in allow-list, on every element of the sanitized tree, parents before children. It can only remove or furthe…SanitizeHookResultWhat the sanitize hook returns for an element: - undefined / 'keep': keep it as is; - null / 'remove': remove it with its content; - 'unwrap': remove the eleme…UploadHandlerUrlUseWhere a URL is used; each use has its own scheme allow-list.
Constants
BLOCK_EDITOR_DEFAULT_LOCALE_TEXTRICH_TEXT_DEFAULT_QUICK_TOOLBARSDefault quick toolbars; text is off unless toolbar="floating".RICH_TEXT_DEFAULT_TOOLBARDefault toolbar.RICH_TEXT_EDITOR_DEFAULT_LOCALE_TEXT