API / @aionbuilders/nabu/extend

TextBlock

Class Stability: stable Stable contract

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

TypeScript
import { TextBlock } from '@aionbuilders/nabu/extend';

Extends Block

Constructor

TypeScript
new TextBlock(nabu: Nabu, node: NabuNode, textContainer?: LoroText)
Parameters of the constructor
ParameterTypeDescription
nabuNabun/a
nodeNabuNoden/a
textContaineroptionalLoroText

Existing LoroText container. Defaults to the node's "text" container (created if missing).

Properties

container

TypeScript
container: LoroText

The Loro text of the block: the source of its text and delta.

positions

TypeScript
positions: number

Caret positions of the block: its text length plus one (reactive).

selection

TypeScript
selection: {
    direction: 'none' | 'forward' | 'backward';
    from: number;
    isCollapsed: boolean;
    to: number;
  } | null

The selection inside this block, { from, to, direction } in text offsets, or null (reactive).

wordCount

TypeScript
wordCount: number

Number of words in the text (reactive).

behavior readonly

TypeScript
readonly behavior: TextBehavior

The text behavior of the block (behaviors.get('text')): reads and edits the text, selection, marks and clipboard form.

delta readonly

TypeScript
readonly delta: DeltaOp[]

The text with its marks, as a Loro delta (reactive).

text readonly

TypeScript
readonly text: string

The plain text of the block (reactive).

Methods

absorbs()

TypeScript
absorbs(block: Block): boolean
Parameters of absorbs
ParameterTypeDescription
blockBlockn/a

applyDelta()

TypeScript
applyDelta(data?: Delta<string>[]): void
Parameters of applyDelta
ParameterTypeDefaultDescription
dataoptionalDelta<string>[][]n/a

beforeinput()

TypeScript
beforeinput(event: InputEvent): any
Parameters of beforeinput
ParameterTypeDescription
eventInputEventn/a

delete()

TypeScript
delete(deletion?: object): void
Parameters of delete
ParameterTypeDescription
deletionoptionalobjectn/a
deletion.fromoptionalnumbern/a
deletion.indexoptionalnumbern/a
deletion.lengthoptionalnumbern/a
deletion.tooptionalnumbern/a

getDOMPoint()

TypeScript
getDOMPoint(targetOffset: number): { node: Node; offset: number } | null

Retrouve le nœud texte et l'offset DOM pour un offset Modèle donné

Parameters of getDOMPoint
ParameterTypeDescription
targetOffsetnumbern/a

insert()

TypeScript
insert(index: number, text: string): void
Parameters of insert
ParameterTypeDescription
indexnumbern/a
textstringn/a

split()

TypeScript
split(options?: object): { block: Block } | null
Parameters of split
ParameterTypeDescription
optionsoptionalobjectn/a
options.fromoptionalnumbern/a
options.indexoptionalnumbern/a
options.lengthoptionalnumbern/a
options.offsetoptionalnumbern/a
options.tooptionalnumbern/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