import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; export type TreeNode = { id: Id; text: any; icon?: any; /** Whether the node is disabled */ disabled?: boolean; /** Optional URL the node links to */ href?: string; /** Optional link target (e.g., "_blank") */ target?: string; nodes?: TreeNode[]; }; export type ShowNodeOptions = { /** Whether to expand the node and its ancestors (default: true) */ expand?: boolean; /** Whether to select the node (default: true) */ select?: boolean; /** Whether to focus the node (default: true) */ focus?: boolean; }; export type CarbonTreeViewContext = TreeNode> = { treeId: any; activeNodeId: import("svelte/store").Writable; selectedNodeIds: import("svelte/store").Writable>; expandedNodeIds: import("svelte/store").Writable>; selectedIdsSetStore: import("svelte/store").Writable>; expandedIdsSetStore: import("svelte/store").Writable>; multiselectStore: import("svelte/store").Writable; clickNode: (node: Node, event?: Event) => void; selectNode: (node: Node) => void; expandNode: (node: Node, expanded: boolean) => void; focusNode: (node: Node) => void; toggleNode: (node: Node) => void; }; type $RestProps = SvelteHTMLElements["ul"]; type $Props = TreeNode> = { /** * Provide an array of nodes to render. * @default [] */ nodes?: ReadonlyArray; /** * Set the current active node id. * Only one node can be active. * @default "" */ activeId?: Node["id"]; /** * Set the node ids to be selected. * @default [] */ selectedIds?: ReadonlyArray; /** * Set the node ids to be expanded. * @default [] */ expandedIds?: ReadonlyArray; /** * Specify the TreeView size. * @default "default" */ size?: "default" | "compact"; /** * Specify the label text * @default "" */ labelText?: string; /** * Set to `true` to visually hide the label text * @default false */ hideLabel?: boolean; /** * Set to `true` to automatically collapse sibling nodes when expanding a node. * When enabled, only one node at each level can be expanded at a time. * @default false */ autoCollapse?: boolean; /** * Set to `true` to enable multi-select mode. * Supports Ctrl/Cmd+Click (toggle) and Shift+Click (range select). * @default false */ multiselect?: boolean; /** * When `multiselect` is true, `multiselectMode` controls how many nodes a selection gesture includes: * - `'node'`: only the clicked/active node (default) * - `'shallow'`: the node plus its direct non-disabled children * - `'deep'`: the node plus all non-disabled descendants * @default "node" */ multiselectMode?: "node" | "shallow" | "deep"; labelChildren?: (this: void) => void; children?: ( this: void, ...args: [ { node: Node & { expanded: boolean; leaf: boolean; selected: boolean } }, ] ) => void; [key: `data-${string}`]: unknown; }; export type TreeViewProps = TreeNode> = Omit< $RestProps, keyof $Props > & $Props; export default class TreeView< Node extends TreeNode = TreeNode, > extends SvelteComponentTyped< TreeViewProps, { focus: CustomEvent< Node & { expanded: boolean; leaf: boolean; selected: boolean } >; keydown: WindowEventMap["keydown"]; select: CustomEvent< Node & { expanded: boolean; leaf: boolean; selected: boolean } >; toggle: CustomEvent< Node & { expanded: boolean; leaf: boolean; selected: boolean } >; }, { default: { node: Node & { expanded: boolean; leaf: boolean; selected: boolean }; }; labelChildren: Record; } > { /** * Programmatically expand all nodes * @example * ```svelte * * * ``` */ expandAll: () => void; /** * Programmatically collapse all nodes * @example * ```svelte * * * ``` */ collapseAll: () => void; /** * Programmatically expand a subset of nodes. * Expands all nodes if no argument is provided. * Filter function should return `true` for nodes to expand. If not provided, expands all nodes. * @example * ```svelte * * * ``` */ expandNodes: (filterNode?: (node: Node) => boolean) => void; /** * Programmatically collapse a subset of nodes. * Collapses all nodes if no argument is provided. * Filter function should return `true` for nodes to collapse. If not provided, collapses all nodes. * @example * ```svelte * * * ``` */ collapseNodes: (filterNode?: (node: Node) => boolean) => void; /** * Programmatically show a node by `id`. * By default, the matching node will be expanded, selected, and focused. * Use the options parameter to customize this behavior. * @example * ```svelte * * * * ``` */ showNode: (id: Node["id"], options?: ShowNodeOptions) => void; }