Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·part ofmodule tree.module·originates fromworld 07158574-5…

fromFlat

Build the recursive node table `Z.tree` expects from a flat array of items where each item carries a parent link. Useful for ECS entity snapshots (each entity has `parentId`) and any other parent-pointer dataset.

byzero-proxy @ DESKTOP-DB3UJOJ·posted 2mo ago
What it does

fromFlat

Build the recursive node table Z.tree expects from a flat array of items where each item carries a parent link. Useful for ECS entity snapshots (each entity has parentId) and any other parent-pointer dataset.

Exports

  • fromFlat(items, opts?) -> (roots, nodeById) — returns the array of root nodes and a stringified-id → node map. Module returns the builder function directly.

Types:

  • FromFlatOpts = { idKey?, parentKey?, labelFn?, iconFn?, actionsFn?, expanded?, defaultExpanded? }
  • TreeNode = { key, label, children?, payload, icon?, actions?, expanded? }

Usage

local fromFlat = require("@builtin::modules.zui.widget.tree.fromFlat")

local roots, byId = fromFlat(entities, {
    idKey           = "id",
    parentKey       = "parentId",
    labelFn         = function(e) return e.name or "#" .. e.id end,
    iconFn          = function(e) return e.children and "▣" or "·" end,
    expanded        = state.expanded,
    defaultExpanded = false,
})

Notes

  • Items missing the id field are silently skipped — we cannot place them in the tree without a key, and crashing on bad data would kill the inspector.
  • Items whose parentKey value isn't found in the input array are treated as roots, matching typical ECS behaviour where a filtered list may contain children whose parents were filtered out.
  • The expanded map is consulted by stringified key first, then by the raw id; absent keys fall back to defaultExpanded.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

ZuiTreeFromFlat Module Build the recursive node table Z.tree expects from a flat array of items where each item carries a parent link. Useful for ECS entity snapshots (each entity has `parentId`) and any other parent-pointer dataset. Items whose `parentKey` value isn't found in the input array are treated as roots — this matches typical ECS behavior where a filtered list may contain children whose parents were filtered out. Cycles are broken by depth tracking; we never revisit an id. Consumers: local fromFlat = require("modules.deprecated.zui.widget.tree.fromFlat") local nodes = fromFlat(entities, { idKey = "id", -- field on each item used as node.key parentKey = "parentId", -- field pointing at the parent's id (nil = root) labelFn = function(e) return e.name or "#" .. e.id end, iconFn = function(e) return e.children and "▣" or "·" end, actionsFn = function(e) return nil end, expanded = state.expanded, -- map of id -> bool defaultExpanded = false, -- when an id isn't in the map })

valueOf(item: ?, key: ?) → void

Internal: read a field from an item without invoking metatable hooks.

argtypedescription
item?
key?

call(fn: ?, item: ?, default: ?) → void

Internal: invoke an optional callback with the item; fall back to a default on absence or pcall failure.

argtypedescription
fn?
item?
default?

build(items: { any }?, opts: FromFlatOpts?) →

Convert a flat array of parent-pointer records into the recursive `{ key, label, children, ... }` node table that `Z.tree` consumes. `"parentId"`), `labelFn(item)`, `iconFn(item)`, `actionsFn(item)`, `expanded` (id → bool), `defaultExpanded` (bool for ids absent from `expanded`). `nodeById` (a map from stringified id to its node, for direct lookup).

argtypedescription
items{ any }?Array of records. Items missing the id field are skipped.
optsFromFlatOpts?Optional. `idKey` (default `"id"`), `parentKey` (default

examples

local roots = fromFlat(entities, { labelFn = function(e) return e.name end })
⌬ Types
FromFlatOpts = {TreeNode = {

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

3items
·
other · born here
▤file
▲ 0↑ born
backing path · modules/deprecated/zui.module/widget.module/tree.module/fromFlat.module

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.