API / @aionbuilders/nabu/extend

NabuSelection

Class Stability: stable Stable contract

Utilitaire réactif pour gérer la sélection de texte avec Svelte 5 runes

Note Not exported by name: you reach it through nabu.selection.

Related guide: Extensions →

Import

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

Extends SvelteSelection

Constructor

TypeScript
new NabuSelection(nabu: Nabu)
Parameters of the constructor
ParameterTypeDescription
nabuNabun/a

Properties

anchorBlock

TypeScript
anchorBlock: Block | null | undefined

blocks

TypeScript
blocks: Set<Block>

The blocks the selection covers (flagged selected: highlighted, marked, …). A selection that does not lie entirely in one block leaves out the blocks that isolate their text (Block#isolatesSelection): a title is not part of a range. Nor does it hold the HIDDEN content of a block that hides its children (the body of a collapsed toggle, hidesChildren): a mark or a highlight never reaches text nobody sees (P-112). Deleting a range still removes such a body with its owner: the deletion walks the tree itself (container.utils.js), it does not read this set.

end

TypeScript
end: {
    block: Block;
    direction: 'none' | 'forward' | 'backward';
    from: number;
    to: number;
  } | null | undefined

endBlock

TypeScript
endBlock: Block | null | undefined

focusBlock

TypeScript
focusBlock: Block | null | undefined

isRange

TypeScript
isRange: boolean

True while the selection is a non-collapsed range across several blocks. The editor mirrors it as data-nabu-range on its root, which the stylesheet uses to not highlight isolated blocks (the model leaves them out of the range, see blocks).

start

TypeScript
start: {
    block: Block;
    direction: 'none' | 'forward' | 'backward';
    from: number;
    to: number;
  } | null | undefined

startBlock

TypeScript
startBlock: Block | null | undefined

Methods

selectBetween()

TypeScript
selectBetween(first: Block, last: Block): boolean

Selects the text of the document between two blocks (first block start -> last block end).

Parameters of selectBetween
ParameterTypeDescription
firstBlockn/a
lastBlockn/a

selectBlockText()

TypeScript
selectBlockText(block: Block): boolean

Selects exactly the text of block (Select All inside an isolated field).

Parameters of selectBlockText
ParameterTypeDescription
blockBlockn/a

Returns boolean

False when the block has no DOM point to select

setCursor()

TypeScript
setCursor(block: Block, offset: number): void

Définit le curseur à un endroit précis du document (Modèle -> DOM)

Parameters of setCursor
ParameterTypeDescription
blockBlockn/a
offsetnumbern/a

Inherited

From SvelteSelection anchorNode, anchorOffset, endOffset, focusNode, focusOffset, is, isCollapsed, startOffset, text, range, sync

Examples

TypeScript
const selection = new SvelteSelection();
// Utiliser selection.text, selection.isCollapsed, etc. dans vos composants

Source: src/lib/blocks/selection.svelte.js:12