Rich text editor

EditorControl · FormatControl · EditorLiteControl

Let users write letters and long documents, or quick formatted notes, inside your app.

Overview

EditorControl is a Blazor editor for letters and long documents: paragraphs, two heading levels, images and page breaks, with undo and find and replace. Use it for proposals, contracts or client letters written in the app; FormatControl is the formatting toolbar you connect to it, and EditorLiteControl binds a short note to an HTML string.

Examples

#A document with its formatting toolbar

Select text and use the toolbar; Undo, Redo and Find and replace (Ctrl+F) are the editor's own, and the line below recounts on every change. Two limits show here: S draws a strike the editor does not read back, so it is not counted and the next Undo removes it; and Font, Size and Line show your last pick, not the format of the selection, so to apply the value already shown, pick another value first.

Head

Words: 148 · Blocks: 10 · OnBlocksChanged calls: 0

#A light editor for short text

Type a note with some bold or a list and save it to the task; every keystroke raises ValueChanged with the sanitized HTML shown under Value, and a saved note is drawn from that same HTML.

Task WEB-117 · Order form · a note for Hermione Ranger
0 notes on the task
    Value
    (empty)

    Documentation

    ParameterTypeDefaultDescription
    EditorIdstring$"fx-editor-{Guid.NewGuid():N}"DOM id of the editable element. The script finds the editor by this id, so it must be unique on the page; an empty value throws ArgumentException.
    BlocksIReadOnlyList<EditorBlock>Array.Empty<EditorBlock>()Starting content. Written into the editor after the first render, and again whenever a different list arrives while AutoPush is on; handing back the list OnBlocksChanged delivered does not rewrite it. An empty list gives one empty paragraph.
    AutoPushbooltrueWhen false, a new Blocks list is not written in; call PushAsync instead.
    PaginateboolfalseLays the text out as fixed-size page cards (fx-paged on the editor, a div.fx-page per card) that the script measures and fills, splitting long paragraphs between words; a blank card and a New page button follow the last one. The script re-paginates while the user types and when the caret moves to another page after an edit. Switching the parameter keeps the current text.
    PagedCssClassstring?nullExtra class on the editor in paged mode. Set --fx-page-w, --fx-page-h, --fx-page-pad and --fx-page-bg under it to size the cards; without them a card is 5.5in by 8.5in.
    PageWidthEditorPageWidthEditorPageWidth.NormalMaximum width of the text: Narrow 640px, Normal 820px and Wide 1040px, centered; Full has no limit. Rendered as the class fx-pw-narrow, fx-pw-normal and so on.
    FontFamilystring"Merriweather"Base font, written as font-family: 'FontFamily', Georgia, serif, so give one family name. The control loads no web fonts.
    FontSizePxint18Base font size in pixels.
    LineHeightdouble1.7Base line height, unitless.
    CssClassstring?nullAdded to the editable element.
    ReadOnlyboolfalseRenders contenteditable="false" and aria-readonly="true" and blocks input; the formatting, undo, redo and replace methods then do nothing.
    SpellCheckbooltrueSets spellcheck on the editable element.
    AriaLabelstring"Document editor"Accessible name of the editable element, which has role="textbox".
    ShowToolbarboolfalseDraws the control's own ToolbarControl above the text: Undo, Redo, Bold, Italic, Underline, Align left, Align center and Find / replace. Undo and Redo stay disabled unless EnableHistory is on.
    EnableHistoryboolfalseTurns on the control's undo and redo: a snapshot after each change, with typing of one kind in one place within 750 ms merged into one step; Ctrl+Z, Ctrl+Y and Ctrl+Shift+Z (or ⌘); UndoAsync and RedoAsync. Leave it off when the host keeps its own history.
    HistoryLimitint100Most undo steps, and most redo steps, kept. Below 1 throws ArgumentOutOfRangeException.
    HistoryChangedEventCallback<EditorHistoryState>—Raised when CanUndo, CanRedo, UndoCount or RedoCount changes, including the reset after PushAsync.
    OnBlocksChangedEventCallback<IReadOnlyList<EditorBlock>>—Raised after each change in the editor (typing, a formatting command that changed the blocks, undo, redo, replace) with the whole document read back as blocks. On Blazor Server the document arrives as one SignalR message, so under the default 32 KB limit a long document stops syncing with no error on the page (only the browser console shows the dropped connection); raise HubOptions.MaximumReceiveMessageSize for long documents.
    OnSelectionChangedEventCallback<EditorSelectionInfo?>—Raised 10 ms after a mouse-up inside the editor with the selected text, its block id and its position relative to the editor's nearest positioned ancestor, or null when nothing is selected. Selecting with the keyboard does not raise it.

    EditorHistoryState is (bool CanUndo, bool CanRedo, int UndoCount, int RedoCount). EditorSelectionInfo is (string Text, string BlockId, double Top, double Left, double Width, double Bottom); Top and Bottom include that ancestor's scroll offset.

    An unhandled error has occurred. Reload 🗙

    Rejoining the server...

    Rejoin failed... trying again in seconds.

    Failed to rejoin.
    Please retry or reload the page.

    The session has been paused by the server.

    Failed to resume the session.
    Please retry or reload the page.