lexical_editor_flutter library
A Lexical editor for Flutter with everything already wired up.
The other packages in this repository are deliberately narrow, so that an application pays only for the node types it uses. This one is the opposite: every node type, the editing behaviour each of them needs, undo, and a theme that presents all of them.
final editor = createLexicalEditor();
LexicalEditorField(
editor: editor,
baseTextStyle: Theme.of(context).textTheme.bodyMedium!,
)
Everything it assembles is available on its own. Reach for the individual packages when a document must not contain something: the node registry is closed at construction, so a type that was never registered cannot be created, pasted or imported — and an unknown one in a stored document is refused loudly rather than silently dropped.
Classes
- AutoLinkNode
- A link the editor created automatically from typed text.
- BaseSelection
- Common interface of every selection kind.
- BlockCaret
- A caret to paint over a block's text.
- BlockMarker
- A marker rendered before a block's content, such as a bullet or a number.
- BlockOffsetMap
- The bidirectional map between one block's flat text and its model points.
- BlockPoint
- A point together with the block that contains it.
- BlockRegistry
- The blocks currently mounted, keyed by node.
- BlockRegistryScope
- Makes the BlockRegistry of the enclosing document available to descendants.
- BlockSelectionSpan
- One block's share of a selection that may cover several.
- BlockStyle
- Everything a block-level element needs to present itself.
- BuiltBlockSpan
- The rendered form of one block's inline content.
- CallbackMentionSource
- A source backed by a plain function.
- CaretContext
- The text immediately before the caret, and where the caret sits in it.
- CodeHighlightNode
- A run of code carrying a syntax-highlight classification.
- CodeLanguage
- How one language is taken apart into tokens.
- CodeNode
- A block of source code.
- CodeToken
- One run of source text and what it was classified as.
- DecoratorBlockNode
- A decorator that occupies a whole block, and can be aligned.
- DecoratorNode
- A node whose visual representation is supplied by the host application.
- DocumentSelection
- The model's selection, split across the blocks it touches.
- EditingWindow
- One block's contribution to the platform's editing value.
- EditorConfig
- Static configuration of one editor.
- EditorState
- A committed or pending snapshot of the document.
- EditorUpdate
- Everything a listener needs to know about one commit.
- ElementNode
- A node that owns children.
- EmbedTarget
- A URL that turned out to be embeddable.
- FigmaNode
- A Figma file or prototype.
- ForeignSelection
- Someone else's range and caret, painted in their own colour.
- GridCell
- Assigns a GridPlacement to a child of LexicalGrid.
- GridPlacement
- Where a child sits in a LexicalGrid, and how far it reaches.
- HashtagNode
-
A tag such as
#flutter. - HeadingNode
- A section heading.
- HistoryChange
- The classification of a single commit.
- HistoryState
- The undo and redo stacks.
- HorizontalRuleNode
-
A horizontal rule — the
---between two sections. - ImageAttributes
- What an inserted image starts out as.
- ImageNode
- An image in the document.
- ImageSizeLimits
- How large an image is allowed to be.
- ImportLimits
- Bounds enforced by the JSON importer.
- LexicalBuilder
- Builds a widget from the editor's current state, after every commit.
-
LexicalCommand<
P> - A dispatchable, typed command.
- LexicalDocument
- Renders the document held by a LexicalEditor.
- LexicalDocumentState
- State of a LexicalDocument; exposed so the editable layer can reach the block registry.
- LexicalEditable
- An editable Lexical document.
- LexicalEditableState
- State of a LexicalEditable; exposed for caret and selection geometry.
- LexicalEditor
- Owns a document, its registry, and the update lifecycle.
- LexicalEditorField
- A ready-to-use editor: every node type, the default theme, history.
- LexicalEditorScope
- Makes the LexicalEditor rendering a document available to its subtree.
- LexicalEmbedView
- A card standing in for an embedded video, tweet or Figma document.
- LexicalGrid
- Lays children out in a grid of columnCount equal columns.
- LexicalHorizontalRuleView
- A thematic break: a hairline across the writing column.
- LexicalImageStyle
- How the selection chrome around an editable image is drawn.
- LexicalImageView
- An image with drag handles, drawn for an ImageNode.
- LexicalInlineBlock
- Renders one block's inline content.
- LexicalInput
- Owns the platform text-input connection for one editor.
- LexicalInteraction
- Declares which node types react to the pointer, and what happens when they do.
- LexicalInteractionRegion
- Turns pointer movement over a document into LexicalInteraction callbacks.
- LexicalInteractionRegionState
- State of a LexicalInteractionRegion, for feeding in external taps.
- LexicalMentions
-
The
@mentiontypeahead of aLexicalEditorField. - LexicalNode
- Base class of every node in the document tree.
- LexicalNodeHit
- A node under the pointer, with everything needed to act on it.
- LexicalPalette
- The colours a document is drawn with.
- LexicalRenderStats
- Counts how much work a commit caused. Test-only.
- LexicalSelectionOverlay
- The handles, toolbar and magnifier of one editable.
- LexicalTheme
- The visual configuration of a rendered document.
- LineBreakNode
- A hard line break inside a block.
- LinkNode
- A hyperlink wrapping inline content.
- ListItemNode
- One entry in a list.
- ListNode
- A list container.
- MarkNode
- Inline content tagged with one or more annotation identifiers.
- MentionMatch
- A trigger found in the text before the caret.
- MentionNode
- A reference to an entity: a person, an issue, a document, anything.
- MentionQuery
- What the controller asks a source for.
- MentionScope
- Wires mention typeahead onto a LexicalEditable.
- MentionScopeState
- State of a MentionScope; exposed so a host can drive it programmatically.
- MentionSearchController
- Drives mention search: debounce, stale-response rejection and caching.
- MentionSearchState
- What the picker should currently show.
- MentionSource
- Supplies suggestions for a query.
- MentionSuggestion
- One entity offered to the user.
- MentionTrigger
- Declares one way a mention can be started.
- MountedBlock
- What the input and selection layers need to know about a mounted block.
- NodeRegistry
- The set of node types one editor understands.
- NodeReplacement
- Substitutes a different implementation for a registered node type.
- NodeSelection
- A set of whole nodes selected as units, typically decorators.
-
NodeSpec<
T extends LexicalNode> - Declares one node type to an editor.
- NodeState
- Arbitrary key/value data attached to a node.
- OffsetSegment
- One node's contribution to a block's flat text.
- ParagraphNode
- An ordinary block of text.
- Point
- One end of a RangeSelection.
- QuoteNode
- A block quote.
- RangeSelection
- A contiguous selection between two points.
- RegisteredBlock
- Registers its inline block with the enclosing BlockRegistry while mounted.
- RemoteSelection
- Someone else's selection, to paint alongside the local one.
- RenderLexicalBlock
- Lays out and paints the inline content of a single block.
- RenderLexicalGrid
- The render object behind LexicalGrid.
- ResolvedPoint
- A resolved position in the document.
- RootNode
- The single top-level node of a document.
- SelectionEndpoints
- Where the two ends of a selection sit, in global coordinates.
- SpanBuilder
- Builds spans and offset maps for inline content.
- StyleValue
- What one entry of a StylePatch does to its declaration.
- TableCellHeaderState
- Which header roles a cell plays, as a bitmask.
- TableCellNode
- A table cell.
- TableCellRange
- A rectangle of grid slots.
- TableCellRef
- One cell, together with where it actually sits.
- TableGrid
- A table resolved into slots.
- TableNode
- A table.
- TableRowNode
- A table row.
- TableSelection
- A rectangle of selected cells, resolved against a table.
- TableShape
- The shape a new table is created with.
- TabNode
- A tab character.
- TextNode
- A run of text with uniform formatting.
- TweetNode
- A tweet, by whatever the site is called this year.
- UnknownNode
- A node whose type is not registered on this editor.
- WindowAnchor
- Where a previous window sat, so the next one can stay put.
- YouTubeNode
- A YouTube video.
Enums
- CommandPriority
- Where a handler sits in the dispatch order.
- DirtyType
- How much of the document changed in the current update.
- ElementFormat
- Block alignment, serialized as a string on element nodes.
- EmbedKind
- The kinds of embed Lexical has.
- HeadingTag
- The heading levels Lexical serializes.
- HistoryChangeType
- The shape of a change, used to decide whether a run continues.
- HistoryMergeAction
- How one commit relates to the previous undo entry.
- ImageHandle
- Which handle is being dragged.
- ListType
- The kinds of list Lexical serializes.
- NodeDirection
- Resolved writing direction of a block.
- NodeMutation
- What happened to a node during one commit.
- PointType
- What a Point's offset counts.
- SelectionUnit
- What a caret movement steps over.
- TabBehaviour
- What the Tab key does.
- TextDetail
- A flag in a text node's detail mask.
- TextFormat
- A single text format, as a bit in a text node's format mask.
- TextMode
- How a text node behaves under editing.
- UnknownNodePolicy
- What an editor should do with a node type it does not recognize.
Extension Types
- NodeKey
-
Opaque identifier of a node within an
EditorState.
Extensions
- ElementNodeSelection on ElementNode
- Selection helpers for element nodes.
- ElementNodeStylePatch on ElementNode
- Patching the style an element hands to text typed into it.
- LexicalNodeSelection on LexicalNode
- Selection helpers shared by every node type.
- RangeSelectionEditing on RangeSelection
- The editing operations of a range selection.
- RangeSelectionStylePatch on RangeSelection
- Patching the style a collapsed selection will type with.
- TextNodeSelection on TextNode
- Selection helpers for text nodes.
- TextNodeStylePatch on TextNode
- Patching the style of a text node.
Constants
-
addMarkCommand
→ const LexicalCommand<
String> - Marks the selection with the identifier in the payload.
-
builtInCodeLanguages
→ const List<
CodeLanguage> - Every language this package can highlight out of the box.
-
canRedoCommand
→ const LexicalCommand<
bool> - Reports whether a redo is available. Dispatched by the history plugin.
-
canUndoCommand
→ const LexicalCommand<
bool> - Reports whether an undo is available. Dispatched by the history plugin.
-
clearEditorCommand
→ const LexicalCommand<
void> - Empty the document.
-
clearHistoryCommand
→ const LexicalCommand<
void> - Discard the undo and redo stacks.
- collaborationTag → const String
- The tag a collaborative change carries.
-
copyCommand
→ const LexicalCommand<
void> - Copy the selection to the clipboard.
-
cutCommand
→ const LexicalCommand<
void> - Cut the selection to the clipboard.
- defaultWindowRadius → const int
- How much text either side of the caret the platform is told about.
-
deleteCharacterCommand
→ const LexicalCommand<
bool> - Delete the selection, or one character when it is collapsed.
-
deleteLineCommand
→ const LexicalCommand<
bool> -
Delete to the line boundary.
truedeletes backwards. -
deleteTableColumnCommand
→ const LexicalCommand<
void> - Removes the columns the selection touches.
-
deleteTableCommand
→ const LexicalCommand<
void> - Removes the whole table.
-
deleteTableRowCommand
→ const LexicalCommand<
void> - Removes the rows the selection touches.
-
deleteWordCommand
→ const LexicalCommand<
bool> -
Delete a word.
truedeletes backwards. -
formatElementCommand
→ const LexicalCommand<
ElementFormat> - Set block alignment over the selection.
-
formatTextCommand
→ const LexicalCommand<
TextFormat> - Toggle a text format over the selection.
- historicTag → const String
- Update tag marking a change produced by history, so it is not recorded.
- historyMergeTag → const String
- Update tag that folds the change into the previous undo entry.
- historyPushTag → const String
- Update tag that forces a new undo entry.
- imeUpdateTag → const String
- Marks an update that came from the platform input method.
-
indentContentCommand
→ const LexicalCommand<
void> - Increase the indent of the selected blocks.
-
inputActionCommand
→ const LexicalCommand<
TextInputAction> - Fired when the platform requests an editing action Flutter models as an input action rather than as text — the return key on a single-line field, for instance.
-
insertEmbedFromUrlCommand
→ const LexicalCommand<
String> - Inserts an embed for a pasted URL, if the URL is one Lexical can embed.
-
insertFigmaCommand
→ const LexicalCommand<
String> - Inserts a Figma document by id.
-
insertImageCommand
→ const LexicalCommand<
ImageAttributes> - Inserts an image at the selection.
-
insertLineBreakCommand
→ const LexicalCommand<
bool> - Insert a hard line break inside the current block.
-
insertParagraphCommand
→ const LexicalCommand<
void> - Split the current block, creating a new one.
-
insertTabCommand
→ const LexicalCommand<
void> - Insert a tab node.
-
insertTableColumnCommand
→ const LexicalCommand<
bool> -
Inserts a column; the payload is
truefor right of the current column. -
insertTableCommand
→ const LexicalCommand<
TableShape> - Inserts a table at the caret.
-
insertTableRowCommand
→ const LexicalCommand<
bool> -
Inserts a row; the payload is
truefor below the current row. -
insertTextCommand
→ const LexicalCommand<
String> - Insert plain text at the selection.
-
insertTweetCommand
→ const LexicalCommand<
String> - Inserts a tweet by status id.
-
insertYouTubeCommand
→ const LexicalCommand<
String> - Inserts a YouTube video by id.
-
interactiveNodeTypes
→ const Set<
String> - The node types that can point somewhere: links, mentions, hashtags.
-
keyDownCommand
→ const LexicalCommand<
KeyEvent> - A raw key press, before any default handling.
- markdownImageMaxWidth → const double
-
The
maxWidthgiven to an image parsed from markdown. - maxIndent → const int
- How deep indentContentCommand will nest a block.
- maxTransformCycles → const int
- How many times the transform loop may repeat before it is called a bug.
-
mergeTableCellsCommand
→ const LexicalCommand<
void> - Merges the selected cells into one.
-
moveTableCellCommand
→ const LexicalCommand<
bool> -
Moves the caret one cell; the payload is
trueto move backwards. - nodeStateKey → const String
- The reserved JSON key under which non-flat node state is nested.
-
outdentContentCommand
→ const LexicalCommand<
void> - Decrease the indent of the selected blocks.
-
pasteCommand
→ const LexicalCommand<
void> - Paste the clipboard at the selection.
-
redoCommand
→ const LexicalCommand<
void> - Redo the last undone change.
-
removeMarkCommand
→ const LexicalCommand<
String> - Removes the identifier in the payload from the whole document.
-
removeTextCommand
→ const LexicalCommand<
void> - Remove the selected content without inserting anything.
-
replaceTextCommand
→ const LexicalCommand<
String> - Replace the selected range with text, as one operation.
-
safeUrlSchemes
→ const Set<
String> - URL schemes that are safe to follow from an editor document.
-
selectAllCommand
→ const LexicalCommand<
void> - Select the whole document.
-
selectionChangeCommand
→ const LexicalCommand<
void> - Fired after the selection changed.
-
setTableCellBackgroundCommand
→ const LexicalCommand<
String?> -
Sets the background of the selected cells, or clears it with
null. -
toggleLinkCommand
→ const LexicalCommand<
String?> - Wraps the selection in a link, retargets the one it is in, or removes it.
-
toggleTableColumnHeaderCommand
→ const LexicalCommand<
void> - Toggles the header role of the columns the selection touches.
-
toggleTableRowHeaderCommand
→ const LexicalCommand<
void> - Toggles the header role of the rows the selection touches.
-
undoCommand
→ const LexicalCommand<
void> - Undo the last change.
-
unmergeTableCellCommand
→ const LexicalCommand<
void> - Splits the merged cell at the caret.
- windowRewindowMargin → const int
- How close the caret may come to a window edge before the window moves.
Properties
-
codeNodes
→ List<
NodeSpec< LexicalNode> > -
The node specs this package contributes.
no setter
-
coreNodes
→ List<
NodeSpec< LexicalNode> > -
Node specs for the types
lexical_coreimplements itself.no setter - defaultHashtagPattern → RegExp
-
What counts as a hashtag.
final
-
embedNodes
→ List<
NodeSpec< LexicalNode> > -
The node specs this package contributes.
no setter
-
embedTransformers
→ List<
ElementTransformer> -
Both embed rules, in the order they have to be tried.
final
- embedUrlTransformer → ElementTransformer
-
A line that is nothing but an embeddable URL.
final
-
hashtagNodes
→ List<
NodeSpec< LexicalNode> > -
The node specs this package contributes.
no setter
-
imageNodes
→ List<
NodeSpec< LexicalNode> > -
The node specs this package contributes.
no setter
- imageTransformer → TextMatchTransformer
-
, in both directions.final - isBuildingWidgets → bool
-
Whether the framework is building widgets at this moment.
no setter
-
lexicalNodes
→ List<
NodeSpec< LexicalNode> > -
Every node type this bundle knows, on top of the core types.
no setter
-
linkNodes
→ List<
NodeSpec< LexicalNode> > -
The node specs this package contributes.
no setter
-
listNodes
→ List<
NodeSpec< LexicalNode> > -
The node specs this package contributes.
no setter
-
markNodes
→ List<
NodeSpec< LexicalNode> > -
The node specs this package contributes.
no setter
-
mentionNodes
→ List<
NodeSpec< LexicalNode> > -
The node specs this package contributes.
no setter
-
richTextNodes
→ List<
NodeSpec< LexicalNode> > -
The node specs this package contributes.
no setter
-
tableNodes
→ List<
NodeSpec< LexicalNode> > -
The node specs this package contributes.
no setter
- tableTransformer → ElementTransformer
-
GitHub-flavoured tables, in both directions.
final
- tweetTransformer → ElementTransformer
-
<tweet id="1234567890" />, exactly as the playground writes it.final
Functions
-
$applyNodeReplacement<
T extends LexicalNode> (T node) → T -
Applies any registered replacement for
node's type. -
$buildEditingWindow(
{WindowAnchor? previous, BlockOffsetMap? reuseOffsets, int radius = defaultWindowRadius, TextRange composing = TextRange.empty}) → EditingWindow? -
Builds the editing window for the current selection, or
null. -
$clearTableCells(
TableGrid grid, TableCellRange range) → void -
Empties every cell in
range, leaving the table's shape alone. -
$computeTableGrid(
TableNode table) → TableGrid -
Resolves
tableinto a grid of slots. -
$copyBlockFormatIndent(
ElementNode source, ElementNode destination) → void - Carries a block's own layout across a conversion.
-
$createAutoLinkNode(
String url, {String? rel, String? target, String? title, bool isUnlinked = false}) → AutoLinkNode - Creates an auto-detected link, applying any registered node replacement.
-
$createCodeHighlightNode(
String text, [String? highlightType]) → CodeHighlightNode - Creates a highlight run, applying any registered node replacement.
-
$createCodeNode(
[String? language]) → CodeNode - Creates a code block, applying any registered node replacement.
-
$createFigmaNode(
String documentId) → FigmaNode - Creates a Figma embed, applying any registered node replacement.
-
$createHashtagNode(
[String text = '']) → HashtagNode - Creates a hashtag, applying any registered node replacement.
-
$createHeadingNode(
[HeadingTag tag = HeadingTag.h1]) → HeadingNode - Creates a heading, applying any registered node replacement.
-
$createHorizontalRuleNode(
) → HorizontalRuleNode - Creates a horizontal rule, applying any registered node replacement.
-
$createImageNode(
{required String src, String altText = '', double width = 0, double height = 0, double maxWidth = ImageNode.defaultMaxWidth, bool showCaption = false, Map< String, Object?> ? caption}) → ImageNode - Creates an image, applying any registered node replacement.
-
$createLineBreakNode(
) → LineBreakNode - Creates a line break, applying any registered node replacement.
-
$createLinkNode(
String url, {String? rel, String? target, String? title}) → LinkNode - Creates a link, applying any registered node replacement.
-
$createListItemNode(
[bool? checked]) → ListItemNode - Creates a list item, applying any registered node replacement.
-
$createListNode(
[ListType listType = ListType.bullet, int start = 1]) → ListNode - Creates a list, applying any registered node replacement.
-
$createMarkNode(
[List< String> ? ids]) → MarkNode - Creates a mark, applying any registered node replacement.
-
$createMentionNode(
{required String text, required String mentionType, required String mentionId, String trigger = '@'}) → MentionNode - Creates a mention, applying any registered node replacement.
-
$createParagraphNode(
) → ParagraphNode - Creates a paragraph, applying any registered node replacement.
-
$createQuoteNode(
) → QuoteNode - Creates a quote, applying any registered node replacement.
-
$createRangeSelection(
) → RangeSelection - Creates a collapsed selection at the start of the document.
-
$createTableCellNode(
{int headerState = TableCellHeaderState.none, int colSpan = 1, int rowSpan = 1, String? backgroundColor}) → TableCellNode - Creates a table cell, applying any registered node replacement.
-
$createTableNode(
) → TableNode - Creates a table, applying any registered node replacement.
-
$createTableNodeWithDimensions(
int rows, int columns, {bool includeHeaders = false}) → TableNode -
Builds a
rows×columnstable, each cell holding an empty paragraph. -
$createTableRowNode(
[int? height]) → TableRowNode - Creates a table row, applying any registered node replacement.
-
$createTabNode(
) → TabNode - Creates a tab node, applying any registered node replacement.
-
$createTextNode(
[String text = '']) → TextNode - Creates a text node, applying any registered node replacement.
-
$createTweetNode(
String tweetId) → TweetNode - Creates a tweet embed, applying any registered node replacement.
-
$createYouTubeNode(
String videoId) → YouTubeNode - Creates a YouTube embed, applying any registered node replacement.
-
$deleteTable(
TableNode table) → void - Removes the whole table.
-
$deleteTableColumns(
TableGrid grid, int startColumn, [int count = 1]) → bool -
Removes
countcolumns starting atstartColumn. -
$deleteTableRows(
TableGrid grid, int startRow, [int count = 1]) → bool -
Removes
countrows starting atstartRow. -
$ensureForwardRangeSelection(
RangeSelection selection) → void -
Swaps
selection's ends so the anchor comes first. -
$forEachSelectedTextNode(
void fn(TextNode textNode), {BaseSelection? selection}) → void -
Runs
fnover every text node the selection covers. -
$getActiveEditor(
) → LexicalEditor -
The editor the current
$call belongs to. -
$getActiveEditorState(
) → EditorState -
The editor state the current
$call should read or write. -
$getLinkAtSelection(
) → LinkNode? -
The link the selection sits in, or
null. -
$getMarkedText(
String id) → String -
The text carrying
id, or an empty string when nothing does. -
$getMarkIdsAtSelection(
) → Set< String> - The identifiers on the marks the selection touches.
-
$getNearestBlock(
LexicalNode node) → ElementNode -
The nearest block-level ancestor of
node, or the root. -
$getNextBlock(
ElementNode block) → ElementNode? -
The block after
blockin document order, ornull. -
$getNodeByKey(
NodeKey key) → LexicalNode? -
The node with
keyin the active state, ornull. -
$getPreviousBlock(
ElementNode block) → ElementNode? -
The block before
blockin document order, ornull. -
$getRoot(
) → RootNode - The root of the active state.
-
$getSelection(
) → BaseSelection? - Returns the selection of the active editor state, if any.
-
$getSelectionStyleValueForProperty(
BaseSelection selection, String property, [String defaultValue = '']) → String -
The value every selected text node gives
property, ordefaultValue. -
$getTableCellForNode(
LexicalNode? node) → TableCellNode? -
The table cell containing
node, ornull. -
$getTableForNode(
LexicalNode? node) → TableNode? -
The table containing
node, ornull. -
$highlightCode(
CodeNode node) → bool -
Brings
node's children in line with the tokens its text produces. -
$insertEmbed(
LexicalNode node) → void -
Puts
nodeon its own line at the selection, with a way out below it. -
$insertImage(
ImageAttributes attributes) → void - Inserts an image at the selection, inside a paragraph.
-
$insertMention(
{required MentionMatch match, required MentionSuggestion suggestion, MentionLabelBuilder label = defaultMentionLabel, bool trailingSpace = true}) → void -
Replaces
match's range with a mention forsuggestion. -
$insertTableColumns(
TableGrid grid, {required int atColumn, required bool after, int count = 1}) → void -
Inserts
countcolumns left or right of the column holdingatColumn. -
$insertTableRows(
TableGrid grid, {required int atRow, required bool below, int count = 1}) → void -
Inserts
countrows above or below the row holdingatRow. -
$isAtEndOfNode(
Point point, ElementNode element) → bool -
Whether nothing of
element's content lies afterpoint. -
$isAtNodeEnd(
Point point) → bool -
Whether
pointaddresses the very end of the node it sits in. -
$isAtStartOfNode(
Point point, ElementNode element) → bool -
Whether nothing of
element's content lies beforepoint. -
$isBlock(
LexicalNode? node) → bool -
Whether
nodeis a block whose content is a line rather than more blocks. -
$isHorizontalRuleNode(
LexicalNode? node) → bool -
Whether
nodeis a horizontal rule. -
$isParentElementRtl(
RangeSelection selection) → bool -
Whether the block
selection's anchor sits in reads right-to-left. -
$isParentRtl(
LexicalNode node) → bool -
Whether the element
nodesits in reads right-to-left. -
$markSelection(
String id) → void -
Tags the selection with
id. -
$mergeTableCells(
TableGrid grid, TableCellRange range) → TableCellNode? -
Merges every cell in
rangeinto its top-left cell. -
$nextTableCell(
TableGrid grid, TableCellNode from, {bool backwards = false}) → TableCellNode? -
The cell after
fromin reading order, ornullat the table's end. -
$patchStyleText(
BaseSelection? selection, StylePatch patch) → void -
Applies
patchto every text node the selection covers. -
$removeMark(
String id) → void -
Removes
idfrom every mark in the document. -
$rescueTableSelection(
TableNode table) → void -
Puts the caret back in
tablewhen the cell it was in has been removed. -
$resolveDocumentSelection(
) → DocumentSelection? - Resolves the active selection into per-block spans.
-
$resolveSelectionSpans(
RangeSelection selection) → DocumentSelection? - Resolves any pair of points into per-block spans.
-
$selectAll(
) → void - Selects the whole document.
-
$selectTableCells(
TableCellNode from, TableCellNode to) → TableSelection? -
Selects every cell in the rectangle
fromandtospan. -
$selectTableCellStart(
TableCellNode cell) → void -
Places a collapsed caret at the start of
cell's content. -
$setBlocksType(
BaseSelection? selection, ElementNode createElement(), {void afterCreateElement(ElementNode source, ElementNode destination) = $copyBlockFormatIndent}) → void - Replaces every block the selection touches with a fresh element.
-
$setSelection(
BaseSelection? selection) → void - Replaces the selection of the pending editor state.
-
$setTableCellBackground(
Iterable< TableCellNode> cells, String? color) → void -
Sets the raw background colour of
cells, or clears it withnull. -
$sliceSelectedTextContent(
BaseSelection selection, TextNode textNode) → String -
The text of
textNodethatselectioncovers. -
$tableSelectionOf(
[BaseSelection? selection]) → TableSelection? -
Reads the active selection as a rectangle of cells, or
null. -
$textBeforeCaret(
{required int limit}) → CaretContext? -
Collects at most
limitcode units of text before the caret. -
$toggleLink(
String? url, {String? rel, String? target, String? title}) → void -
Links the selection to
url, or unlinks it whenurlisnull. -
$toggleTableColumnHeader(
TableGrid grid, int column) → void -
Turns the header role of every cell in
columnon or off. -
$toggleTableRowHeader(
TableGrid grid, int row) → void -
Turns the header role of every cell anchored in
rowon or off. -
$trimTextContentFromAnchor(
LexicalEditor editor, Point anchor, int count) → void -
Removes
countcharacters of content ending atanchor. -
$unmergeTableCell(
TableGrid grid, TableCellNode cell) → void -
Splits
cellback into one cell per slot it covered. -
applyCaseTransform(
String text, int format) → String - Applies the case-transform format bits to a rendered string.
-
assertTreeIntegrity(
RootNode root) → bool -
Walks the tree from
rootand throws on the first broken invariant. -
buildModelOffsets(
ElementNode block) → BlockOffsetMap -
Builds
block's flat text and offset map from the model alone. -
classifyChange(
EditorUpdate update) → HistoryChange -
Classifies
updateas a continuable run or as something that breaks one. -
createLexicalEditor(
{List< NodeSpec< nodes = const [], List<LexicalNode> >NodeReplacement> replacements = const [], EditorConfig config = const EditorConfig(), EditorState? initialEditorState}) → LexicalEditor - Creates an editor understanding every type in lexicalNodes.
-
defaultCodeHighlightStyles(
LexicalPalette palette) → Map< String, TextStyle> -
Colours for the syntax-highlight token classes, chosen for
palette. -
defaultCssStyleResolver(
String css, TextStyle base) → TextStyle - The default resolver: the handful of declarations Lexical's toolbars emit.
-
defaultEmbedThumbnailResolver(
EmbedKind kind, String id) → ImageProvider< Object> ? - Uses YouTube's public thumbnail, and nothing for the other kinds.
-
defaultHeadingStyles(
TextStyle baseTextStyle) → Map< HeadingTag, TextStyle> - The heading styles the default theme applies, by tag.
-
defaultImageResolver(
String src) → ImageProvider< Object> ? -
Resolves
http(s):URLs,data:URIs and asset paths, and nothing else. -
defaultLexicalContextMenu(
BuildContext context, LexicalEditableState editable) → Widget - The platform's own selection menu, with the usual four entries.
-
defaultLexicalTheme(
{required TextStyle baseTextStyle, LexicalPalette palette = const LexicalPalette(), double blockSpacing = 10, String monospaceFamily = 'monospace', List< String> monospaceFallback = const ['Menlo', 'Consolas', 'Courier New'], Map<String, TextStyle> ? codeHighlightStyles}) → LexicalTheme - Builds a theme presenting every node type this bundle registers.
-
defaultMentionLabel(
MentionTrigger trigger, MentionSuggestion suggestion) → String - The default label: the trigger character followed by the entity's name.
-
embedDecoratorBuilders(
{EmbedOpener? onOpen, EmbedThumbnailResolver thumbnailResolver = defaultEmbedThumbnailResolver, String labelFor(EmbedKind kind, String id)?, double maxWidth = 560}) → Map< String, Widget Function(BuildContext, DecoratorNode)> -
Decorator builders for
youtube,tweetandfigma. -
flatSelectionFor(
BlockSelectionSpan span, BlockOffsetMap offsets) → TextSelection? -
Converts
spaninto flat offsets againstoffsets, ornullwhen empty. -
getCssFromStyleObject(
Map< String, String> styles) → String -
Serializes
stylesback into an inline CSS string. -
getStyleObjectFromCss(
String css) → Map< String, String> - Parses inline CSS text into its declarations, in source order.
-
hitTestNodes(
{required BlockRegistry registry, required LexicalEditor editor, required Set< String> types, required Offset globalPosition}) → LexicalNodeHit? -
The interactive node under
globalPosition, ornull. -
horizontalRuleDecoratorBuilders(
{Color? color, double thickness = 1, double spacing = 8}) → Map< String, DecoratorBuilder> -
The builder for the
horizontalruledecorator. -
imageDecoratorBuilders(
{required LexicalEditor editor, ImageSizeLimits limits = const ImageSizeLimits(), ImageResolver resolver = defaultImageResolver, bool editable = true, bool captionsEnabled = true, bool preserveAspectRatio = true, TextStyle? captionStyle, Widget placeholderBuilder(BuildContext context, String src)?, LexicalImageStyle style = const LexicalImageStyle()}) → Map< String, Widget Function(BuildContext, DecoratorNode)> -
A decorator builder for
image, ready to hand to the renderer. -
imageMarkdownTransformer(
{double maxWidth = markdownImageMaxWidth}) → TextMatchTransformer -
The image rule, with a
maxWidthof your choosing. -
isCurrentlyReadOnlyMode(
) → bool - Whether the active context forbids mutation.
-
isInlineContent(
LexicalNode node) → bool -
Whether
nodecontributes to an inline run rather than being its own block. -
isSafeUrl(
String url) → bool -
Whether
urlis safe to make tappable. -
jsonDeepEquals(
Object? a, Object? b) → bool - Deep-compares two decoded JSON values.
-
jsonFirstDifference(
Object? a, Object? b, [String path = r'$']) → String? -
Returns a human-readable path to the first difference between
aandb, ornullwhen they are deeply equal. -
lexicalDecoratorBuilders(
{required LexicalEditor editor, ImageSizeLimits imageLimits = const ImageSizeLimits(), ImageResolver imageResolver = defaultImageResolver, bool editable = true, bool captionsEnabled = true, LexicalImageStyle imageStyle = const LexicalImageStyle(), Widget imagePlaceholderBuilder(BuildContext context, String src)?, EmbedOpener? onOpenEmbed, EmbedThumbnailResolver embedThumbnails = defaultEmbedThumbnailResolver}) → Map< String, DecoratorBuilder> - Widget builders for every decorator type in this bundle.
-
matchEmbedUrl(
String url) → EmbedTarget? -
Recognises an embeddable URL, or returns
null. -
matchMentionTrigger(
String text, int caretOffset, List< MentionTrigger> triggers) → MentionMatch? -
Finds the mention trigger governing the caret, or
null. -
parseCssColor(
String? value) → Color? -
Parses
#rgb,#rrggbb,#rrggbbaa,rgb(...)andrgba(...). -
parseCssDeclarations(
String css) → Map< String, String> -
Parses a CSS declaration list into
property -> valuepairs. -
parseCssFontWeight(
String? value) → FontWeight? -
Parses a CSS
font-weight, numeric or keyword. -
parseCssLength(
String? value, double? base) → double? -
Parses a CSS length in
px,pt,emorreminto logical pixels. -
parseCssTextDecoration(
String? value) → TextDecoration? -
Parses a CSS
text-decorationshorthand, keeping only the line values. -
registerCode(
LexicalEditor editor, {String indent = ' '}) → Unsubscribe - Makes Enter and Tab behave the way they do in an editor, inside code.
-
registerCodeHighlighting(
LexicalEditor editor) → Unsubscribe - Re-highlights a code block whenever its text or its language changes.
-
registerEmbed(
LexicalEditor editor) → Unsubscribe -
Registers the embed commands on
editor. -
registerHashtag(
LexicalEditor editor, {RegExp? pattern, Set< String> excludedAncestors = const {'code'}}) → Unsubscribe - Detects hashtags as they are typed, and undoes the detection when the text stops being one.
-
registerHistory(
LexicalEditor editor, {HistoryState? state, void onChange(HistoryState state)?}) → Unsubscribe -
Wires undo and redo into
editor. -
registerImage(
LexicalEditor editor) → Unsubscribe -
Registers insertImageCommand on
editor. -
registerLexical(
LexicalEditor editor, {HistoryState? history}) → Unsubscribe - Registers the editing behaviour every node type in this bundle needs.
-
registerLink(
LexicalEditor editor) → Unsubscribe -
Registers toggleLinkCommand and the empty-link cleanup on
editor. -
registerList(
LexicalEditor editor) → Unsubscribe - Wires list behaviour on top of registerListNumbering.
-
registerListNumbering(
LexicalEditor editor) → Unsubscribe - Registers the transform that keeps item numbering in step with positions.
-
registerMark(
LexicalEditor editor) → Unsubscribe -
Registers addMarkCommand and removeMarkCommand on
editor. -
registerPlainText(
LexicalEditor editor) → Unsubscribe - Wires the commands a plain-text editor needs.
-
registerRichText(
LexicalEditor editor) → Unsubscribe - Wires the commands a rich-text editor needs.
-
registerTable(
LexicalEditor editor) → Unsubscribe -
Wires table editing onto
editor. -
renumberItems(
ListNode list) → void -
Renumbers
list's direct item children from its start value. -
resizeImage(
{required Size start, required Offset delta, required ImageHandle handle, ImageSizeLimits limits = const ImageSizeLimits(), double? aspectRatio}) → Size -
The size a drag of
deltaonhandleproduces, starting fromstart. -
tableBlockLayouts(
{double spacing = 0, Color? selectedCellColor}) → Map< String, BlockLayoutBuilder> - The block layout that makes a table look like one.
-
tokenizeCode(
String source, {String? language}) → List< CodeToken> -
Splits
sourceinto classified runs forlanguage. -
whenBuildIsDone(
VoidCallback action) → void -
Runs
actionnow, or at the end of the frame if a build is in progress.
Typedefs
- BlockLayoutBuilder = Widget Function(BuildContext context, ElementNode element, Widget buildChild(LexicalNode node))
- Lays out a block whose children are not simply stacked.
- BlockMarkerBuilder = BlockMarker? Function(BuildContext context, ElementNode node)
-
Builds the marker for one block, or returns
nullfor none. - BlockStyleResolver = BlockStyle Function(ElementNode node, BlockStyle base)
- Refines a block's presentation using the node itself.
-
CommandHandler<
P> = bool Function(P payload) - Handles a dispatched command.
- CssStyleResolver = TextStyle Function(String css, TextStyle base)
-
Resolves a node's raw
stylestring onto a TextStyle. - DecoratorBuilder = Widget Function(BuildContext context, DecoratorNode node)
- Renders a decorator node.
- EditableListener = void Function(bool editable)
- Called when the editor's editable flag changes.
- EmbedOpener = void Function(EmbedKind kind, String url)
- Opens an embed outside the editor.
-
EmbedThumbnailResolver
= ImageProvider<
Object> ? Function(EmbedKind kind, String id) -
Finds a still image for an embed, or returns
nullfor a plain card. -
ImageResolver
= ImageProvider<
Object> ? Function(String src) -
Turns a node's
srcinto something Flutter can draw. - LexicalContextMenuBuilder = Widget Function(BuildContext context, LexicalEditableState editable)
- Builds the menu shown over a selection.
- LexicalNodeHitCallback = void Function(LexicalNodeHit hit)
- Called when the pointer enters, leaves or taps an interactive node.
-
MentionEditableBuilder
= Widget Function(BuildContext context, GlobalKey<
LexicalEditableState> key) - Builds the editable the popover is anchored to.
- MentionItemBuilder = Widget Function(BuildContext context, MentionSuggestion suggestion, bool highlighted)
- Builds one row of the suggestion list.
- MentionLabelBuilder = String Function(MentionTrigger trigger, MentionSuggestion suggestion)
- Builds the label an inserted mention carries.
- MentionSurfaceBuilder = Widget Function(BuildContext context, Widget list)
- Wraps the suggestion list in the popover's own chrome.
-
MutationListener
= void Function(Map<
NodeKey, NodeMutation> mutations) - Called after a commit with the mutations affecting one node type.
- NodeTransform = void Function(LexicalNode node)
- Runs over one dirty node of the type it was registered for.
-
StylePatch
= Map<
String, StyleValue> - CSS declarations to apply, keyed by property name.
- TextContentListener = void Function(String textContent)
- Called after a commit in which the document's plain text changed.
- TokenBuilder = Widget Function(BuildContext context, TextNode node, TextStyle style)
- Renders a token-mode text node as a widget rather than as text.
- Unsubscribe = void Function()
-
Cancels a registration. Every
register*returns one. - UpdateListener = void Function(EditorUpdate update)
- Called after a commit.
Exceptions / Errors
- ImportLimitExceededException
- Thrown when an import exceeds a configured resource limit.
- LexicalException
-
Base class for all errors raised by
lexical_core. - LexicalImportException
- Base class for failures while importing a serialized document.
- LexicalStateError
- Thrown when an API is used outside the editor context it requires.
- LexicalTreeError
- Thrown when the node tree violates a structural invariant.
- MalformedDocumentException
- Thrown when a serialized document is structurally malformed.
- UnknownNodeTypeException
- Thrown when a serialized node names a type that is not registered.