API / @aionbuilders/nabu

Regions

Class Stability: stable

Document-level reactive registry of the regions (ADR 018 §3.4): a pure, derived view over the TREE (stores nothing in Loro). Lazy and cheap: ONE pass over the root blocks and the bodies of the regions builds everything, and it only re-runs when the STRUCTURE changes (a region inserted / moved / deleted / retyped, a child added to a region body), not when text is typed. Obtain it with Regions.get(nabu); RegionsExtension also installs it as nabu.regions.

Related guide: Regions →

Import

TypeScript
import { Regions } from '@aionbuilders/nabu';

Constructor

TypeScript
new Regions(nabu: Nabu, config: RegionsConfig)
Parameters of the constructor
ParameterTypeDescription
nabuNabun/a
configRegionsConfign/a

Static members

static get()

TypeScript
get(nabu: Nabu): Regions
Parameters of get
ParameterTypeDescription
nabuNabun/a

Properties

caret

TypeScript
caret: Region | null

The region that shows the caret: the DEEPEST region holding the selection anchor (a title counts), only while the editor has the focus. null otherwise. Reactive; computed once for all the regions (each Region.svelte compares itself to it).

config readonly

TypeScript
readonly config: RegionsConfig

The resolved configuration (declared types).

count readonly

TypeScript
readonly count: number

The number of regions.

list readonly

TypeScript
readonly list: Region[]

Every region, in document order (pre-order of the tree).

preamble readonly

TypeScript
readonly preamble: Preamble

The root blocks before the first root region (the whole document when there is no region). They are outside any region.

tree readonly

TypeScript
readonly tree: Region[]

The top-level regions; each one holds its children.

Methods

at()

TypeScript
at(target?: Block | { block: Block } | null): Region | null

The deepest region containing a block: its nearest region ancestor, the block itself when it is a region. target is a block or an { block } position (as the selection offers); omitted = the block holding the selection anchor. null outside any region (the preamble) or when there is nothing to resolve.

Parameters of at
ParameterTypeDescription
targetoptionalBlock | { block: Block } | nulln/a

next()

TypeScript
next(region: Region): Region | null

The region after this one, in document order (a sub-region, then the following sibling…).

Parameters of next
ParameterTypeDescription
regionRegionn/a

of()

TypeScript
of(block: string | Block): Region | null

The region of a region block.

Parameters of of
ParameterTypeDescription
blockstring | Blockn/a

parentOf()

TypeScript
parentOf(region: Region): Region | null
Parameters of parentOf
ParameterTypeDescription
regionRegionn/a

prev()

TypeScript
prev(region: Region): Region | null

The region before this one, in document order.

Parameters of prev
ParameterTypeDescription
regionRegionn/a

start()

TypeScript
start(): void

System hook (nabu.systems, called when the editor mounts): follows the focus of the editor, for Regions#caret. Idempotent.

stop()

TypeScript
stop(): void

System hook: stops following the focus.

Source: src/lib/blocks/region/regions.svelte.js:110