AUDIO
Source snapshot · 11 November 2026

Fixed hierarchical tree selection

Construction and owned profile

const tree = new RavetControls.TreeView(root, [
  { node: folder, label: 'Folder', parent: null, group, toggle },
  { node: child, label: 'Child', parent: 0, group: null, toggle: null },
  { node: sibling, label: 'Sibling', parent: null, group: null, toggle: null },
], {
  label: 'Library', multiple: true, selected: [1], active: 0,
  expanded: [], onSelection: snapshot => {}, onExpansion: snapshot => {},
});

Supply 1–256 entries in fixed depth-first preorder, with depth at most 32. A parent is null or the preceding index of its parent. Root direct elements must be exactly the top-level nodes, in order. A branch supplies an existing direct child group containing exactly its direct child item elements in order, and an existing direct child native button with the explicit attribute type="button". A leaf supplies neither. Nested text/decoration inside the button is allowed. Group-background clicks are unowned; a row click routes to the deepest item, rather than its containing ancestor.

Root, items, groups and toggles must be distinct connected HTML elements in one original live document/window. One tree owns each root/member. A removed original owner frame or replaced window document rejects later admission. Items and groups have distinct IDs of 1–128 UTF-16 code units, with no whitespace, resolving to exactly themselves in that document. Root and item labels are explicit nonblank strings of 1–256 UTF-16 code units. Root/items/groups must be non-native-interactive and non-editable, including inherited contenteditable. Other descendants cannot be native interactive/editable or have tabindex; owned items/groups/toggles are exempt from the owned tabindex check. Root descendants are scanned with a bound of 8,192 elements before writes and every admission. The implementation's model and scan bounds do not bound browser layout, document lookup or ancestor costs, or certify a real-time deadline.

Malformed profiles/models, duplicate ownership, detached/no-window documents, preorder/parent errors or capacity violations throw TypeError before changing attributes/styles or installing ownership/listeners. Entry objects and initial selected/expanded arrays are copied. Consumer mutation of the original array does not alter the fixed model.

The root owns role=tree, explicit aria-label (removing aria-labelledby), aria-multiselectable, aria-activedescendant and tabindex. It is the only sequential Tab stop while available. Items own treeitem role, explicit name/reference precedence, level/position/sibling count, selected state, branch-only expanded state and tabindex=-1. Groups own group role, tabindex=-1, hidden and inline display. Collapsed groups receive display:none!important, so hostile theme CSS cannot reveal collapsed descendants; expanded groups restore captured original display and priority. An original display:none can still make an expanded group unavailable. Toggles own button role, a bounded Expand/Collapse name (at most 265 code units), reference precedence, controls/expanded state and tabindex=-1. The native type remains consumer-owned and must stay explicitly button.

Original owned attribute/display values are at most 4,096 code units; original group style text is at most 16,384. dispose() removes listeners/observation and restores exact owned attributes/display/priority, including originally absent attributes. Original raw style serialization restores when no unrelated inline edits remain; unrelated edits survive. Cleanup restores already-owned properties even after retirement. It does not restore focus or generate/remove elements. Synchronous custom-element attribute callbacks can dispose safely during owned writes: later attribute/style writes stop before touching the cleaned-up profile.