API / @aionbuilders/nabu/extend TextBehavior Class Stability: stable Stable contract
The editing of a block's rich text: wraps a Loro text and offers the reactive text and delta, the selection in that text, and insertion, deletion, splitting, marks and links. Text blocks use it through TextBlock; a container with a header (list item, toggle) owns one.
Related guide: Extensions →
Import TypeScript Copy
import { TextBehavior } from '@aionbuilders/nabu/extend' ; Constructor TypeScript Copy
new TextBehavior (block: Block , container ?: LoroText) Parameters of the constructor Parameter Type Description blockBlock n/a containeroptional LoroTextn/a
Properties TypeScript Copy
block : Block TypeScript Copy
container : LoroText TypeScript Copy
delta : DeltaOp[] TypeScript Copy
positions : number TypeScript Copy
selection : {
direction : 'none' | 'forward' | 'backward' ;
from : number;
isCollapsed : boolean;
to : number;
} | null TypeScript Copy
text : string TypeScript Copy
readonly wordCount : number Number of words in this text: segmented with Intl.Segmenter in the language of the editor (nabu.lang) when the platform
has it, so Chinese or Japanese text counts its words rather than one per sentence; whitespace-separated otherwise. See
utils/words.js. Reactive in the text and in nabu.lang.
Methods TypeScript Copy
absorbs (other: Block): boolean Parameters of absorbs Parameter Type Description otherBlock n/a
TypeScript Copy
applyDelta (data ?: Delta < string > []): void Parameters of applyDelta Parameter Type Default Description dataoptional Delta<string>[][]n/a
TypeScript Copy
applyMark (
markName: string ,
value: any ,
sel: Pick <{
direction : 'none' | 'forward' | 'backward' ;
from : number ;
isCollapsed : boolean ;
to : number ;
} , 'from' | 'isCollapsed' | 'to' > | null
): void Parameters of applyMark Parameter Type Description markNamestringn/a valueanyn/a selPick<{
direction: 'none' | 'forward' | 'backward';
from: number;
isCollapsed: boolean;
to: number;
}, 'from' | 'isCollapsed' | 'to'> | nulln/a
TypeScript Copy
delete (
deletion ?: object ,
selection ?: {
direction : 'none' | 'forward' | 'backward' ;
from: number;
isCollapsed: boolean;
to: number;
} | null
): void Parameters of delete Parameter Type Default Description deletionoptional objectn/a n/a deletion.fromoptional numbern/a n/a deletion.indexoptional numbern/a n/a deletion.lengthoptional numbern/a n/a deletion.tooptional numbern/a n/a selectionoptional {
direction: 'none' | 'forward' | 'backward';
from: number;
isCollapsed: boolean;
to: number;
} | null...n/a
TypeScript Copy
getDOMPoint (targetOffset: number , element ?: HTMLElement | null ): { node : Node; offset: number } | null Retrouve le nœud texte et l'offset DOM pour un offset Modèle donné
Parameters of getDOMPoint Parameter Type Default Description targetOffsetnumbern/a n/a elementoptional HTMLElement | null...
TypeScript Copy
insert (index: number , text: string): void Parameters of insert Parameter Type Description indexnumbern/a textstringn/a
TypeScript Copy
isMarkActive (
markName: string ,
sel: Pick <{
direction : 'none' | 'forward' | 'backward' ;
from : number ;
isCollapsed : boolean ;
to : number ;
} , 'from' | 'isCollapsed' | 'to' > | null
): boolean Parameters of isMarkActive Parameter Type Description markNamestringn/a selPick<{
direction: 'none' | 'forward' | 'backward';
from: number;
isCollapsed: boolean;
to: number;
}, 'from' | 'isCollapsed' | 'to'> | nulln/a
TypeScript Copy
removeMark (
markName: string ,
sel: Pick <{
direction : 'none' | 'forward' | 'backward' ;
from : number ;
isCollapsed : boolean ;
to : number ;
} , 'from' | 'isCollapsed' | 'to' > | null
): void Parameters of removeMark Parameter Type Description markNamestringn/a selPick<{
direction: 'none' | 'forward' | 'backward';
from: number;
isCollapsed: boolean;
to: number;
}, 'from' | 'isCollapsed' | 'to'> | nulln/a
TypeScript Copy
split (
options ?: object ,
selection ?: {
direction : 'none' | 'forward' | 'backward' ;
from: number;
isCollapsed: boolean;
to: number;
} | null
): { block : Block } | null Parameters of split Parameter Type Default Description optionsoptional objectn/a n/a options.fromoptional numbern/a n/a options.indexoptional numbern/a n/a options.lengthoptional numbern/a n/a options.offsetoptional numbern/a n/a options.tooptional numbern/a n/a selectionoptional {
direction: 'none' | 'forward' | 'backward';
from: number;
isCollapsed: boolean;
to: number;
} | null...n/a
Returns { block: Block } | null
TypeScript Copy
toClipboardBlock (context ?: object): PasteBlock Serializes a (partial) range of this block's text as a PasteBlock.
Parameters of toClipboardBlock Parameter Type Default Description contextoptional object{}n/a context.fromoptional number0n/a context.partialoptional false | 'both' | 'start' | 'end'falsen/a context.propsoptional Record<string, any>{}n/a context.tooptional number | nullnulln/a
TypeScript Copy
toggleMark (
markName: string ,
value: any ,
sel: Pick <{
direction : 'none' | 'forward' | 'backward' ;
from : number ;
isCollapsed : boolean ;
to : number ;
} , 'from' | 'isCollapsed' | 'to' > | null
): void Parameters of toggleMark Parameter Type Description markNamestringn/a valueanyn/a selPick<{
direction: 'none' | 'forward' | 'backward';
from: number;
isCollapsed: boolean;
to: number;
}, 'from' | 'isCollapsed' | 'to'> | nulln/a
TypeScript Copy
toJSON (): { text : string; [mark: string]: any }[] Converts the text delta to a Slate-like JSON format.
TypeScript Copy
toMarkdown (options ?: object): string Parameters of toMarkdown Parameter Type Description optionsoptional objectoptions.rawBreaksoptional booleann/a
Source: src/lib/behaviors/text/text.behavior.svelte.js:188