TextBlock
Base class for purely textual blocks (paragraph, heading, dialogue…). Owns a single TextBehavior and proxies the standard Block text API to it, removing the proxy boilerplate previously duplicated in every text block.
Related guide: Extensions →
Hybrid blocks (MegaBlock + TextBehavior, like ListItem) must NOT extend this class — their children/positions logic differs.
Import
import { TextBlock } from '@aionbuilders/nabu/extend';Constructor
new TextBlock(nabu: Nabu, node: NabuNode, textContainer?: LoroText)| Parameter | Type | Description |
|---|---|---|
nabu | Nabu | n/a |
node | NabuNode | n/a |
textContaineroptional | LoroText | Existing LoroText container. Defaults to the node's "text" container (created if missing). |
Properties
container
container: LoroTextThe Loro text of the block: the source of its text and delta.
positions
positions: numberCaret positions of the block: its text length plus one (reactive).
selection
selection: {
direction: 'none' | 'forward' | 'backward';
from: number;
isCollapsed: boolean;
to: number;
} | nullThe selection inside this block, { from, to, direction } in text offsets, or null (reactive).
wordCount
wordCount: numberNumber of words in the text (reactive).
behavior readonly
readonly behavior: TextBehaviorThe text behavior of the block (behaviors.get('text')): reads and edits the text, selection, marks and clipboard form.
delta readonly
readonly delta: DeltaOp[]The text with its marks, as a Loro delta (reactive).
text readonly
readonly text: stringThe plain text of the block (reactive).
Methods
absorbs()
absorbs(block: Block): boolean| Parameter | Type | Description |
|---|---|---|
block | Block | n/a |
applyDelta()
applyDelta(data?: Delta<string>[]): void| Parameter | Type | Default | Description |
|---|---|---|---|
dataoptional | Delta<string>[] | [] | n/a |
beforeinput()
beforeinput(event: InputEvent): any| Parameter | Type | Description |
|---|---|---|
event | InputEvent | n/a |
delete()
delete(deletion?: object): void| Parameter | Type | Description |
|---|---|---|
deletionoptional | object | n/a |
deletion.fromoptional | number | n/a |
deletion.indexoptional | number | n/a |
deletion.lengthoptional | number | n/a |
deletion.tooptional | number | n/a |
getDOMPoint()
getDOMPoint(targetOffset: number): { node: Node; offset: number } | nullRetrouve le nœud texte et l'offset DOM pour un offset Modèle donné
| Parameter | Type | Description |
|---|---|---|
targetOffset | number | n/a |
insert()
insert(index: number, text: string): void| Parameter | Type | Description |
|---|---|---|
index | number | n/a |
text | string | n/a |
split()
split(options?: object): { block: Block } | null| Parameter | Type | Description |
|---|---|---|
optionsoptional | object | n/a |
options.fromoptional | number | n/a |
options.indexoptional | number | n/a |
options.lengthoptional | number | n/a |
options.offsetoptional | number | n/a |
options.tooptional | number | n/a |
Inherited
From Block behaviors, component, element, id, index, isIntermediate, isolatesSelection, isSelectionEnd, isSelectionStart, marksEnabled, nabu, next, node, parent, parents, pastesAsPlainText, placeholder, previous, selected, serializers, splitsOnEnter, transformsEnabled, type, fromHTML, fromMarkdown, htmlRules, htmlSiblings, markdownRules, toHtml, toMarkdown, adoptsPastedTypes, hidesChildren, requiredParent, acceptPaste, ascend, clearSelection, commit, consume, destroy, dragRange, findBackward, findForward, findLastDescendant, focus, getAdjacentSiblings, keydown, mergeWith, resolveOffset, retype, serialize, transformTo, create, load
Source: src/lib/blocks/text-block.svelte.js:21