Extras
BlockEditor
BitBlockEditor edits a document made of blocks, the way Notion-style editors do: each paragraph, heading, list item, quote or code block is edited in place, Enter splits a block and Backspace at its start joins it to the one before, and Markdown shortcuts (# , - , 1. , [] , > , ```, ---) turn a block into another type as you type, and a slash opens a menu of every block type, images included. Whole blocks are selected, moved, nested and turned into other types from the keyboard or a block menu, and dragged by their grips. The value is a BitBlockDocument, a typed model your app can read, build and store, which converts to and from JSON, Markdown and HTML without the component. The undo history is the editor's own, and an app adds block types of its own with Blazor views.
Notes
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
Markdown shortcuts
Document
## Release notes The editor reads **Markdown**, ~~HTML~~ and JSON. - Blocks - nested - [x] Shortcuts - [ ] Slash menu > One block at a time. ```csharp var doc = BitBlockDocument.FromMarkdown(text); ```
Commands
Inline formatting
code, a highlight, underline, H2O and x2.Select some of this text to **format** it, or type **bold** with its asterisks. A [link](https://bitplatform.dev), some `code`, ==a highlight==, ++underline++, H~2~O and x^2^.
Blocks
## Plan Press Escape to select a block, or use the grip beside it: click it for the menu, drag it to move the block. - Design - Sketches - Review - Build - Ship > Tab nests an item; Alt+Shift+Up and Down move a block.
Slash menu and images

## Trip notes Type / at the start of a line, or after a space, to pick a block type.  Paste or drop an image file here too.
Custom blocks
ReadOnly & Disabled
Style & Class
RTL
CSS variables
The public custom properties this component reads off its root, for what no parameter covers.
Every variable is read with a fallback and never declared by the component, so it inherits like any other custom property:
set one on :root (or in a [bit-theme] block) to restyle every instance, on any ancestor to restyle the ones inside it,
or on the Style of one instance to restyle it - and any instance nested inside it, which inherits the value too; a parameter changes one alone,
as does the real CSS property on the instance's Style / Styles when that property does not inherit (opacity: 1 keeps
one disabled instance undimmed without undimming a disabled one inside it), while an inherited one such as color or
font-family also reaches the nested instances that do not set it themselves. Leave a variable unset and the component
falls back to the theme token beside it.
BitBlockEditor CSS variables
| Name | Default value | Description |
|---|---|---|
| --bit-BlockEditor-color | --bit-clr-fg-pri | Text color of the document. |
| --bit-BlockEditor-background | --bit-clr-bg-pri | Background of the document. |
| --bit-BlockEditor-border-color | --bit-clr-brd-pri | Color of the outer border. |
| --bit-BlockEditor-border-width | --bit-shp-brd-width | Width of the outer border. |
| --bit-BlockEditor-border-radius | --bit-shp-radius-surface | Corner radius of the document. |
| --bit-BlockEditor-padding | spacing(1.5) spacing(2) | Space around the blocks. |
| --bit-BlockEditor-block-gap | spacing(0.5) | Space between two blocks. |
| --bit-BlockEditor-focus-color | --bit-clr-pri-focus | The ring around the document while a block has focus. While it is unset, the ring is the library's own --bit-shd-focus-ring. |
| --bit-BlockEditor-placeholder-color | --bit-clr-fg-sec | Placeholder of an empty block. |
| --bit-BlockEditor-muted-color | --bit-clr-fg-sec | List markers, a ticked task, a caption and a block the editor cannot show. |
| --bit-BlockEditor-quote-border-color | --bit-clr-brd-pri | The bar beside a quote. |
| --bit-BlockEditor-code-background | --bit-clr-bg-sec | Background of a code block and of inline code. |
| --bit-BlockEditor-code-font-family | --bit-tpg-font-family-mono | Font of a code block and of inline code. |
| --bit-BlockEditor-divider-color | --bit-clr-brd-sec | The line of a divider. |
| --bit-BlockEditor-label-color | --bit-BlockEditor-color | Text of the label. |
| --bit-BlockEditor-highlight-background | --bit-clr-wrn-light | Background of highlighted text. |
| --bit-BlockEditor-selection-background | --bit-clr-pri-light | Background of a selected block. |
| --bit-BlockEditor-drag-outline-color | --bit-clr-pri | Dashed outline of the block the pointer drags, in the place it would land, on the background of a selected block (--bit-BlockEditor-selection-background). |
| --bit-BlockEditor-preview-opacity | 0.92 | Opacity of the picture of that block that follows the pointer. It is placed above the page, so only a value set on :root reaches it. |
| --bit-BlockEditor-preview-shadow | --bit-shd-popup | Shadow of the picture that follows the pointer. Only a value set on :root reaches it. |
API
Every parameter, public member, sub-class and enum this component exposes.
BitBlockEditor parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| BlockTypes | IEnumerable<BitBlockType>? | null | The app's own block types, added to the built-in ones (BitBlockTypes): paragraph, heading, listItem, quote, code, image and divider. A type named as a built-in replaces it. |
| Classes | BitBlockEditorClassStyles? | null | Custom CSS classes for different parts of the editor. |
| Label | string? | null | The label shown above the editor, which names it for screen readers. Without one, the editor is named by the Document string. |
| MaxImageSize | long | 10485760 | The largest image file, in bytes, the editor takes from an upload, a paste or a drop (10 MB by default). Zero or a negative value restores the default. |
| OnImageUpload | Func<BitRichTextEditorImageUpload, Task<string?>>? | null | Stores an image file the user uploads, pastes or drops (its name, content type and bytes), and returns the address the image block shows it from. Without one, the image goes into the document itself as a data URL. A null or empty address, or an exception, fails the image, which the editor says. |
| Placeholder | string? | null | The text shown in an empty document's first block, until something is typed into it. |
| Strings | BitBlockEditorStrings? | null | The words of the editor that screen readers read out, in English by default: the name of each block's text, the document's name and the announcements. |
| Styles | BitBlockEditorClassStyles? | null | Custom CSS styles for different parts of the editor. |
BitBlockEditor public members
| Name | Type | Default value | Description |
|---|---|---|---|
| CanRedo | bool | false | Whether there is a change taken back to put back. |
| CanUndo | bool | false | Whether there is a change to take back. |
| Document | BitBlockDocument | The document the editor shows: the bound value as the editor holds it, every formatted text in its canonical form, with a paragraph to type in after a last block that holds no text. | |
| ExecuteCommandAsync | Func<BitBlockEditorCommand, string?, Task> | Runs a command on the block that holds the caret, or the last one that held it: an inline command (Bold, Italic, Highlight, ...) on the text selected in it, CreateLink with the address, TurnInto and InsertBlock with the type (heading:2, listItem:task, code:csharp, divider, ...), MoveUp, MoveDown, Indent, Outdent, Duplicate, Delete, Undo and Redo with nothing. While blocks are selected, the block commands act on them. | |
| RedoAsync | Func<Task> | Puts back the last change taken back. | |
| UndoAsync | Func<Task> | Takes back the last change: a run of typing, or one command, shortcut or paste. |
BitComponentBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AriaLabel | string? | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | string? | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | BitDir? | null | Gets or sets the text directionality for the component's content. |
| Disabled | bool | false | Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction. |
| ForceAnimation | bool | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | Dictionary<string, object> | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| Style | string? | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | string? | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | BitVisibility | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
BitComponentBase public members
| Name | Type | Default value | Description |
|---|---|---|---|
| UniqueId | Guid | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | ElementReference | Gets the reference to the root HTML element associated with this component. |
BitBlockEditorClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root element of the BitBlockEditor. |
| Label | string? | null | Custom CSS classes/styles for the label of the BitBlockEditor. |
| Document | string? | null | Custom CSS classes/styles for the element holding the blocks of the BitBlockEditor. |
| Block | string? | null | Custom CSS classes/styles for each block: the shell holding its marker, its text or view, and its children. |
| Text | string? | null | Custom CSS classes/styles for the editable text of each text and code block. |
| Marker | string? | null | Custom CSS classes/styles for the marker before a list item: its bullet, its number or its task checkbox. |
| Children | string? | null | Custom CSS classes/styles for the element holding the children of a nesting block. |
| Toolbar | string? | null | Custom CSS classes/styles for the toolbar shown over selected text. |
| ToolbarButton | string? | null | Custom CSS classes/styles for each button of the toolbar. |
| LinkPanel | string? | null | Custom CSS classes/styles for the panel that asks for a link's address. |
| SelectedBlock | string? | null | Custom CSS classes/styles for each selected block, added to its Block ones. |
| DraggedBlock | string? | null | Custom CSS classes/styles for the block the pointer drags, added to its Block ones while it is dragged. |
| Handle | string? | null | Custom CSS classes/styles for the button beside each block that selects it and opens the block menu. |
| Menu | string? | null | Custom CSS classes/styles for the block menu. |
| MenuItem | string? | null | Custom CSS classes/styles for each item of the block menu. |
| SlashMenu | string? | null | Custom CSS classes/styles for the slash menu: the filter box and the list of block types a slash typed in a text opens. |
| ImagePanel | string? | null | Custom CSS classes/styles for the panel that edits an image: its address, its upload, its alternative text, its caption and its width. |
BitBlockEditorStrings properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Document | string | "Document" | The name of the editor when it has no Label. |
| BlockPosition | string | "{0}, block {1} of {2}" | The name of each block's text: its type ({0}), its position ({1}) and how many blocks there are ({2}). |
| NestedBlockPosition | string | "{0}, level {1}, block {2} of {3}" | The name of the text of a block nested in another: its type ({0}), how deep it is ({1}), its position ({2}) and how many blocks there are ({3}). |
| Paragraph | string | "Paragraph" | A paragraph. |
| Heading | string | "Heading {0}" | A heading, with its level ({0}); also the placeholder of an empty heading. |
| BulletItem | string | "Bulleted list item" | An item of a bulleted list. |
| NumberedItem | string | "Numbered list item" | An item of a numbered list. |
| TaskItem | string | "Task" | An item of a task list. |
| TaskDone | string | "Done" | The checkbox of a task. |
| Quote | string | "Quote" | A quote. |
| Code | string | "Code" | A block of code. |
| CodeLanguage | string | "Code, {0}" | A block of code with its language ({0}). |
| Image | string | "Image" | An image. |
| Divider | string | "Divider" | A divider. |
| UnknownBlock | string | "Unsupported block: {0}" | A block whose type the editor does not know ({0}), kept and shown read-only. |
| TurnedInto | string | "Turned into {0}" | What is announced when a block turns into another type ({0}). |
| TextFormatting | string | "Text formatting" | The name of the toolbar shown over selected text. |
| Bold | string | "Bold" | The toolbar button that makes text bold. |
| Italic | string | "Italic" | The toolbar button that makes text italic. |
| Underline | string | "Underline" | The toolbar button that underlines text. |
| StrikeThrough | string | "Strikethrough" | The toolbar button that strikes text through. |
| InlineCode | string | "Inline code" | The toolbar button that makes text inline code. |
| Highlight | string | "Highlight" | The toolbar button that highlights text. |
| Subscript | string | "Subscript" | The toolbar button that lowers text. |
| Superscript | string | "Superscript" | The toolbar button that raises text. |
| Link | string | "Link" | The toolbar button that links text, and the name of the panel it opens. |
| ClearFormatting | string | "Clear formatting" | The toolbar button that takes every mark off text. |
| LinkAddress | string | "Link address" | The field of the link panel that takes the address. |
| LinkInvalid | string | "Enter a web, email or phone address." | What the link panel says of an address the editor would not keep. |
| ApplyLink | string | "Apply" | The link panel's button that links the text. |
| RemoveLink | string | "Remove link" | The link panel's button that takes the link off. |
| Cancel | string | "Cancel" | The link panel's button that closes it without a change. |
| BlockHandle | string | "Actions for {0}" | The button beside each block that selects it and opens the block menu, with the name of the block's text ({0}). |
| BlockMenu | string | "Block actions" | The name of the block menu. |
| HandleTip | string | "Drag to move, click for actions" | The tooltip of the button beside each block, which the pointer drags the block by and clicks for its menu. |
| TurnIntoGroup | string | "Turn into" | The group of the block menu that turns the selected blocks into another type. |
| BulletList | string | "Bulleted list" | The block menu's item that turns blocks into items of a bulleted list. |
| NumberedList | string | "Numbered list" | The block menu's item that turns blocks into items of a numbered list. |
| TaskList | string | "Task list" | The block menu's item that turns blocks into tasks. |
| Duplicate | string | "Duplicate" | The block menu's item that copies the selected blocks to right after them. |
| MoveUp | string | "Move up" | The block menu's item that moves the selected blocks up. |
| MoveDown | string | "Move down" | The block menu's item that moves the selected blocks down. |
| Delete | string | "Delete" | The block menu's item that deletes the selected blocks. |
| BlockCount | string | "{0} blocks" | How several blocks are named in what is announced, with their number ({0}); one block is named by its type. |
| Selected | string | "{0} selected" | What is announced when blocks are selected ({0}). |
| SelectionCleared | string | "Selection cleared" | What is announced when the selection of blocks is cleared. |
| Moved | string | "Moved {0} to position {1} of {2}" | What is announced when blocks move ({0}), where the first of them is now ({1}) and how many blocks there are ({2}). |
| Indented | string | "Indented {0}" | What is announced when blocks are nested under the block before them ({0}). |
| Outdented | string | "Outdented {0}" | What is announced when blocks come out of their parent ({0}). |
| Duplicated | string | "Duplicated {0}" | What is announced when blocks are copied ({0}). |
| Deleted | string | "Deleted {0}" | What is announced when blocks are deleted ({0}). |
| PickedUp | string | "Picked up {0}" | What is announced when the pointer picks a block up by its handle ({0}). |
| PutBack | string | "{0} put back" | What is announced when a block dragged by the pointer goes back where it was: Escape, or a release outside the document ({0}). |
| SlashMenu | string | "Block types" | The name of the slash menu's filter box and of its list of block types. |
| SlashPlaceholder | string | "Filter block types…" | What the slash menu's filter box shows while it is empty. |
| SlashNoResults | string | "No matching block type" | What the slash menu says when no block type matches its filter. |
| Inserted | string | "Inserted {0}" | What is announced when the slash menu inserts a block, with its type ({0}). |
| AddImage | string | "Add an image" | The button an image with no address shows, which opens the image panel. |
| EditImage | string | "Edit image" | The block menu's item that opens the image panel on a selected image. |
| ImageAddress | string | "Image address" | The field of the image panel that takes the image's address. |
| ImageAlt | string | "Alternative text" | The field of the image panel that takes the image's alternative text. |
| ImageCaption | string | "Caption" | The field of the image panel that takes the caption shown under the image. |
| ImageWidth | string | "Width in pixels" | The field of the image panel that takes the image's width. |
| UploadImage | string | "Upload an image" | The image panel's button that picks an image file to upload. |
| ApplyImage | string | "Apply" | The image panel's button that applies what it holds to the image. |
| ImageInvalid | string | "Enter the web address of an image, or upload one." | What the image panel says of an address the editor would not show. |
| ImageTooLarge | string | "\"{0}\" is larger than {1}." | What is said of an image file larger than MaxImageSize, with its name ({0}) and the limit ({1}). |
| ImageUnsupported | string | "\"{0}\" is not a PNG, JPEG, GIF, WebP or SVG image." | What is said of a file that is not an image the editor takes ({0}). |
| ImageUploadFailed | string | "Uploading \"{0}\" failed." | What is said when OnImageUpload failed or gave no address ({0}). |
| ImageUploading | string | "Uploading \"{0}\"…" | What is announced as an image starts uploading ({0}). |
| ImageAdded | string | "Image added" | What is announced when an image is added to the document. |
| ImageUpdated | string | "Image updated" | What is announced when the image panel changes an image. |
BitBlockDocument properties
An immutable document of blocks. Two documents are equal when their blocks are.
| Name | Type | Default value | Description |
|---|---|---|---|
| Blocks | IReadOnlyList<BitBlock> | The top-level blocks, in order. | |
| Empty | BitBlockDocument | A document with no blocks (static). | |
| ToJson / FromJson | string | The lossless JSON form, the one to store: { "v": 1, "blocks": [...] }. | |
| ToMarkdown / FromMarkdown | string | Markdown with GitHub's task lists and the emphasis extensions. An image's width, an empty paragraph and a line break in a heading are what Markdown cannot say. | |
| ToHtml / FromHtml | string | The markup a BitRichTextEditor stores, sanitized. Reading takes any HTML: what has no block becomes a paragraph of its text. |
BitBlock properties
One block of a document, immutable: change it with with or WithProp.
| Name | Type | Default value | Description |
|---|---|---|---|
| Id | string | a new random id | Unique in the document and kept through every edit of the block. |
| Type | string | The name of the block's type: paragraph, heading, listItem, quote, code, image, divider or an app's own. | |
| Text | string | "" | Inline HTML of b, i, s, code, a href, sub, sup, mark, ins and br for a text type; plain text for code; nothing for an atom. |
| Props | IReadOnlyDictionary<string, string> | empty | The block's settings, as strings: a heading's level (1-6), a list item's style (bullet, ordered, task) and checked, code's language, an image's src, alt, width and caption. |
| Children | IReadOnlyList<BitBlock> | empty | The blocks nested under it, for a type that nests (a list item). |
BitBlockType properties
A type of block. The built-ins are in BitBlockTypes.
| Name | Type | Default value | Description |
|---|---|---|---|
| Name | string | The name a block's Type refers to it by. | |
| Kind | BitBlockKind | What a block of the type holds as its text. | |
| Nests | bool | false | Whether a block of the type may hold children. |
| SlashLabel | string? | null | The words the slash menu offers the type under. |
| SlashKeywords | string? | null | More words the slash menu finds the type by. |
| Icon | RenderFragment? | null | A small decorative glyph the slash menu shows before the type's SlashLabel, drawn in the menu's text color. The built-in types have their own. |
| ToHtml | BitBlockExport? | null | Writes a block of the type as HTML, handed its children already written. |
| ToMarkdown | BitBlockExport? | null | Writes a block of the type as Markdown, handed its children already written. |
| View | RenderFragment<BitBlockContext>? | null | How the editor shows a block of an Atom type: a Blazor view handed the block and the way to change it. |
BitBlockContext properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Block | BitBlock | The block the view shows. | |
| ReadOnly | bool | Whether the editor is read-only or disabled, in which case the view changes nothing. | |
| UpdateAsync | Func<BitBlock, Task> | Replaces the block with a changed copy of it (same id) as one step of the history, and updates the bound value. |
BitBlockEditorCommand enum
| Name | Value | Description |
|---|---|---|
| Bold | 0 | Makes the selected text bold, or takes the bold off where all of it is bold; at a caret, for what is typed next. |
| Italic | 1 | Makes the selected text italic, or takes the italic off. |
| Underline | 2 | Underlines the selected text, or takes the underline off (ins, Markdown's ++x++). |
| StrikeThrough | 3 | Strikes the selected text through, or takes the line off. |
| InlineCode | 4 | Makes the selected text inline code, or takes it out of code. |
| Subscript | 5 | Lowers the selected text, or takes it back. |
| Superscript | 6 | Raises the selected text, or takes it back. |
| Highlight | 7 | Highlights the selected text (mark, Markdown's ==x==), or takes the highlight off. |
| CreateLink | 8 | Links the selected text to the address the value holds (example.com is taken as https); with no value, opens the link panel. |
| Unlink | 9 | Takes off every link the selection touches, keeping their text. |
| RemoveFormat | 10 | Takes every mark off the selected text, keeping its links. |
| TurnInto | 11 | Turns the block into the type the value names (paragraph, heading:1-6, listItem, listItem:ordered, listItem:task, quote, code, code:language, divider, or an app's type). |
| MoveUp | 12 | Moves the block, with what it holds, up past the block before it: into it when that one nests and holds blocks, and out of its parent at the start of a nested list. |
| MoveDown | 13 | Moves the block, with what it holds, down past the block after it: into it when that one nests and holds blocks, and out of its parent at the end of a nested list. |
| Indent | 14 | Nests the block under the block before it, when that one nests (a list item). |
| Outdent | 15 | Brings a nested block out of its parent one level. |
| Duplicate | 16 | Copies the block, with what it holds, to right after it. |
| Delete | 17 | Deletes the block, with what it holds. |
| InsertBlock | 18 | Inserts a new, empty block of the type the value names after the block, and puts the caret in it. |
| Undo | 19 | Takes back the last change. |
| Redo | 20 | Puts back the last change taken back. |
BitBlockKind enum
| Name | Value | Description |
|---|---|---|
| Text | 0 | Formatted text, in the inline vocabulary. |
| Code | 1 | Plain text, kept as it is. |
| Atom | 2 | No text: the block is its props, shown by the type's View. |
BitVisibility enum
| Name | Value | Description |
|---|---|---|
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
BitDir enum
| Name | Value | Description |
|---|---|---|
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.