API / @aionbuilders/nabu

Region

Class Stability: stable

One division of the document, as computed by the registry (ADR 018 §3.4). A read-only VIEW over a region BLOCK, a container of the tree: the structure (level, parent, children, index, path) is derived from the tree; title / fields / label / blocks / wordCount read reactive state when you read them.

Related guide: Regions →

A region is a region block at the root of the document or directly in the body of another region. Its BODY is the children of its block: any blocks, sub-regions included.

Import

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

Constructor

TypeScript
new Region(registry: Regions, init: object)
Parameters of the constructor
ParameterTypeDescription
registryRegionsn/a
initobjectn/a
init.blockRegionBlockn/a
init.defRegionTypeDef | undefinedn/a
init.levelnumbern/a
init.positionnumbern/a
init.typestringn/a

Properties

block

TypeScript
block: RegionBlock

The region block.

children

TypeScript
children: Region[]

The direct sub-regions, in order.

def

TypeScript
def: RegionTypeDef | undefined

The declared type, or undefined when the block's type is not declared (a document from a richer editor).

index

TypeScript
index: number | null

The number within its numbering scope (see numbering in ADR 016 §3.2), null when not numbered.

level

TypeScript
level: number

Depth, 1 = highest. A region whose type is not declared gets the deepest declared level.

parent

TypeScript
parent: Region | null

The nearest region ancestor.

path

TypeScript
path: number[]

The indexes of the numbered ancestors, then of this region ([2, 1]).

position

TypeScript
position: number

Rank among all regions, in document order (0-based).

type

TypeScript
type: string

The region type id.

blocks readonly

TypeScript
readonly blocks: Block[]

The direct children of the body (sub-regions included). Reactive.

fields readonly

TypeScript
readonly fields: Record<string, any>

The fields of the region (reactive); title is the plain text of the header.

label readonly

TypeScript
readonly label: string

The label template applied ("1.1 The ferryman"). Reactive (the title). Empty when the template yields nothing.

marker readonly

TypeScript
readonly marker: RegionBlock

Alias of Region#block, from the time a region was a marker.

ownBlocks readonly

TypeScript
readonly ownBlocks: Block[]

The direct children of the body that are not regions: the region's own content. Reactive.

ownWordCount readonly

TypeScript
readonly ownWordCount: number

Words of the region's own content: body text outside sub-regions (their titles and bodies excluded, like every title). Reactive.

pathString readonly

TypeScript
readonly pathString: string

The path as text ("2.1"; empty when nothing on the way is numbered).

prefix readonly

TypeScript
readonly prefix: string

The label template applied with an EMPTY title ("1.1", "Chapter 2"): what the seam shows before the editable title. Empty when the template holds only the title.

title readonly

TypeScript
readonly title: string

The title: the plain text of the header (reactive).

wordCount readonly

TypeScript
readonly wordCount: number

Words of the body text, sub-regions' bodies included, summed from the blocks' own wordCount (no rendering). NO title is counted: neither this region's nor its sub-regions' (a region block's own wordCount is its body only). Reactive.

Methods

setField()

TypeScript
setField(name: string, value: unknown): boolean

Sets a field of the region (validated, own undo step); title replaces the header text.

Parameters of setField
ParameterTypeDescription
namestringn/a
valueunknownn/a

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