Mixins / foldkit-mixins-ui

TreeView

namespace · packages/mixins-ui/src/treeView.ts:1

export * as TreeView from './treeView.js'

In the guides

Members

TreeView.checkedAs

function · packages/mixins-ui/src/treeView.ts:246

function checkedAs(
  nodes: ReadonlyArray<TreeNode>,
  checked: ReadonlyArray<string>,
  as: CheckedValue,
): ReadonlyArray<string>

The Model's checked (the checked rows holding no rows) as the value an application stores or sends, in tree order:

  • 'leaf': the checked rows holding no rows, which is what checked holds.
  • 'branch': every fully checked row, rows holding rows and not.
  • 'trunk': the outermost fully checked rows, so a checked folder stands for everything in it.

A row holding rows is fully checked as checksOf reads it: every row it holds that holds none is checked, a disabled one included, so a folder with an unchecked disabled file is not listed and its checked files are. Ids the tree does not hold are left out. leavesOf is the way back, so the Model stays the one owner of what is checked.

TreeView.CheckedValue

type · packages/mixins-ui/src/treeView.ts:230

type CheckedValue = 'leaf' | 'branch' | 'trunk'

Which rows a checked value lists: see checkedAs.

TreeView.checksOf

function · packages/mixins-ui/src/treeView.ts:216

function checksOf(
  nodes: ReadonlyArray<TreeNode>,
  checked: ReadonlyArray<string>,
): ReadonlyMap<string, boolean | 'mixed'>

Each row's check: true when every row it holds that holds none is checked, 'mixed' when some are, false when none are.

TreeView.configure

function · packages/mixins-ui/src/treeView.ts:545

function configure<const Names extends string = never>(
  config: Presets<TreeViewPreset, Names>,
): {
  readonly view: <Outer>(
    options: TreeViewView<Outer> & PresetOption<Names>,
    h: HtmlBuilder<Outer>,
  ) => Html
}

The application's own TreeView: base for every use, presets chosen at a use with preset, and the call over both. mixins concatenate in that order (TreeView.fluid goes in base); any other option given at the call replaces the preset's.

TreeView.fluid

const · packages/mixins-ui/src/treeView/fluid.ts:14

const fluid: readonly [Mixin<never>]

What moves the highlight: on the root, one highlight follows the pointer to the nearest showing row, and to the row the keys focus, at its own indentation. Pass it beside the style; until it runs, each row marks its own hover and the drawn highlight shows nothing.

TreeView.init

function · packages/mixins-ui/src/treeView.ts:101

function init(options: {
  readonly id: string
  readonly open?: ReadonlyArray<string>
  readonly checked?: ReadonlyArray<string>
  readonly checkable?: boolean
}): Model

TreeView.itemId

function · packages/mixins-ui/src/treeView.ts:117

function itemId(model: Model, id: string): string

The DOM id of a row's treeitem.

TreeView.leavesOf

function · packages/mixins-ui/src/treeView.ts:269

function leavesOf(
  nodes: ReadonlyArray<TreeNode>,
  value: ReadonlyArray<string>,
): ReadonlyArray<string>

The checked rows holding no rows that a value stands for, in tree order, to seed or write the Model's checked: an id of a row holding rows stands for every such row beneath it, whichever value the application keeps (checkedAs), and ids the tree does not hold are ignored.

TreeView.Message

const · packages/mixins-ui/src/treeView.ts:84

const Message: MessageUnion<{
  readonly Pressed: { readonly key: Schema.String }
  readonly Focused: { readonly id: Schema.String }
  readonly Clicked: { readonly id: Schema.String }
  readonly Checked: { readonly id: Schema.String }
  readonly QueryExpired: { readonly generation: Schema.Number }
  readonly CompletedFocusItem: {}
}>

TreeView.Model

const · packages/mixins-ui/src/treeView.ts:66

const Model: Schema.Struct<{
  readonly id: Schema.String
  readonly current: Schema.Option<Schema.String>
  readonly open: Schema.$Array<Schema.String>
  readonly selected: Schema.Option<Schema.String>
  readonly checked: Schema.$Array<Schema.String>
  readonly checkable: Schema.Boolean
  readonly typeahead: Schema.Struct<{
    readonly query: Schema.String
    readonly generation: Schema.Number
  }>
}>

TreeView.TreeNode

interface · packages/mixins-ui/src/treeView.ts:49

interface TreeNode {
  readonly id: string
  readonly label: string
  readonly children?: ReadonlyArray<TreeNode> | undefined
  readonly disabled?: boolean | undefined
  readonly icon?: Html | undefined
  readonly openIcon?: Html | undefined
  readonly content?: Html | undefined
  readonly trailing?: Html | undefined
  readonly action?: Html | undefined
}

A row of the tree, and the rows it holds.

TreeView.TreeViewPreset

type · packages/mixins-ui/src/treeView.ts:535

type TreeViewPreset = Pick<TreeViewView<never>, 'direction' | 'style'> & {
  readonly mixins?: MixinList<never>
}

What a TreeView is given once: its look and the options that hold no Message.

TreeView.TreeViewSlots

const · packages/mixins-ui/src/treeView/slots.ts:9

const TreeViewSlots: Slots.Contract<{ readonly root: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [Event.EventToken<"keydown">], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-label">], readonly Slot.RequirementName[], boolean>; readonly item: Slot.UnnamedSlot<Capability.Capability<"Focusable", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [Event.EventToken<"focus">], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-expanded">, Attr.AttrToken<"aria-selected">, Attr.AttrToken<"aria-checked">, Attr.AttrToken<"aria-disabled">], readonly Slot.RequirementName[], boolean>; readonly row: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly chevron: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly checkbox: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly Slot.AttributeName[], readonly Slot.RequirementName[], b …;

The tree's Slots. Each row is an item (the treeitem, which takes focus) holding a row (the line drawn and clicked) and, when it holds rows, a group. A node's icon stands in icon, its trailing after the label in trailing, and its action at the row's end in action.

TreeView.TreeViewView

interface · packages/mixins-ui/src/treeView.ts:412

interface TreeViewView<ParentMessage> {
  readonly label: string
  readonly model: Model
  readonly nodes: ReadonlyArray<TreeNode>
  readonly onMessage: (message: Message) => NoInfer<ParentMessage>
  readonly direction?: 'ltr' | 'rtl' | undefined
  readonly checkable?: boolean | undefined
  readonly style?: NamedStyle<typeof TreeViewSlots> | undefined
  readonly mixins?: MixinList<ParentMessage> | undefined
}

TreeView.update

function · packages/mixins-ui/src/treeView.ts:283

function update(
  nodes: ReadonlyArray<TreeNode>,
  options?: {
    readonly checkable?: boolean | undefined
  },
): (model: Model, message: Message) => Return

The tree's update over nodes, the tree the view draws; the same Model when nothing changes. Pass the same nodes the view gets, built once, and checkable as the view has it, which makes Space check the current row.

TreeView.view

function · packages/mixins-ui/src/treeView.ts:429

function view<ParentMessage>(
  options: TreeViewView<ParentMessage>,
  h: HtmlBuilder<ParentMessage>,
): Html