Skip to content

TreeConfig type

Home > @rimitive/view > TreeConfig

TreeConfig defines the type-level contract for a tree adapter: - attributes: Maps tag names to their attribute types for el() autocomplete - nodes: Maps tag names to their node types for RefSpec<T> (e.g., ‘div’ -> HTMLDivElement)

The base node type is derived automatically as the union of all node types in nodes. Use NodeOf<TConfig> to access it.

Separating attributes from nodes allows adapters to have clean attribute autocomplete without exposing internal node properties (like canvas’s bounds, dirty, etc).

Note: Text is just another node type created via createNode(‘text’, { value: ’…’ })

Signature:

export type TreeConfig = {
attributes: Record<string, object>;
nodes: Record<string, object>;
};
import type { TreeConfig, NodeOf } from '@rimitive/view/adapter';
// DOM tree config
type DOMTreeConfig = TreeConfig & {
attributes: {
div: { className?: string; id?: string };
button: { disabled?: boolean; textContent?: string };
};
nodes: {
div: HTMLDivElement;
button: HTMLButtonElement;
text: Text;
};
};
// Base node type is derived: HTMLDivElement | HTMLButtonElement | Text
type DOMNode = NodeOf<DOMTreeConfig>;