Region
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
import { Region } from '@aionbuilders/nabu';Constructor
new Region(registry: Regions, init: object)| Parameter | Type | Description |
|---|---|---|
registry | Regions | n/a |
init | object | n/a |
init.block | RegionBlock | n/a |
init.def | RegionTypeDef | undefined | n/a |
init.level | number | n/a |
init.position | number | n/a |
init.type | string | n/a |
Properties
block
block: RegionBlockThe region block.
children
children: Region[]The direct sub-regions, in order.
def
def: RegionTypeDef | undefinedThe declared type, or undefined when the block's type is not declared (a document from a richer editor).
index
index: number | nullThe number within its numbering scope (see numbering in ADR 016 §3.2), null when not numbered.
level
level: numberDepth, 1 = highest. A region whose type is not declared gets the deepest declared level.
parent
parent: Region | nullThe nearest region ancestor.
path
path: number[]The indexes of the numbered ancestors, then of this region ([2, 1]).
position
position: numberRank among all regions, in document order (0-based).
type
type: stringThe region type id.
blocks readonly
readonly blocks: Block[]The direct children of the body (sub-regions included). Reactive.
fields readonly
readonly fields: Record<string, any>The fields of the region (reactive); title is the plain text of the header.
label readonly
readonly label: stringThe label template applied ("1.1 The ferryman"). Reactive (the title). Empty when the template yields nothing.
marker readonly
readonly marker: RegionBlockAlias of Region#block, from the time a region was a marker.
ownBlocks readonly
readonly ownBlocks: Block[]The direct children of the body that are not regions: the region's own content. Reactive.
ownWordCount readonly
readonly ownWordCount: numberWords of the region's own content: body text outside sub-regions (their titles and bodies excluded, like every title). Reactive.
pathString readonly
readonly pathString: stringThe path as text ("2.1"; empty when nothing on the way is numbered).
prefix readonly
readonly prefix: stringThe 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
readonly title: stringThe title: the plain text of the header (reactive).
wordCount readonly
readonly wordCount: numberWords 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()
setField(name: string, value: unknown): booleanSets a field of the region (validated, own undo step); title replaces the header text.
| Parameter | Type | Description |
|---|---|---|
name | string | n/a |
value | unknown | n/a |
Source: src/lib/blocks/region/regions.svelte.js:21