Skip to main content
cngx-src documentation

flattenTree

Functionutils/tree

projects/utils/tree.ts

Description#

Flatten a tree in DFS order. Each emitted FlatTreeNode carries aria-level (depth + 1), aria-posinset, and aria-setsize data so the rendering layer can bind them directly.

Signature#

flattenTree(nodes, idFn: IdFn, labelFn: LabelFn)

Parameters#

@paramnodes

Root-level tree nodes.

@paramidFnIdFn= defaultIdFn as IdFn

Derives a stable id from (value, path). Defaults to path.join('.') — adequate for static trees; supply a key-based idFn for data that may be re-ordered without changing identity.

@paramlabelFnLabelFn= defaultLabelFn as LabelFn

Derives visible label. Defaults to String(value).

Returns#

FlatTreeNode[]