import { defineWebComponent } from './define'; import { FileTree, type FileTreeFile } from '../components/file-tree'; interface Props extends Record { /** The files to render. Set as a JS property (array of `{ path, url?, code?, language?, type?, additions?, deletions?, status? }`). */ files: FileTreeFile[]; /** Selected file path — highlighted in the tree. */ activeFile?: string; /** Folder paths expanded initially. Omit to start with all folders open. */ defaultExpanded?: string[]; /** Show a changed-files summary header (file count + summed `+/-` + Collapse-all). Attribute: `summary`. Off by default. */ summary?: boolean; } interface Events extends Record { /** Fired when a file is selected. `detail.path` = the file's path. */ 'kai-select': { path: string }; } /** * `` — a collapsible, keyboard-navigable file explorer built from a * flat list of `/`-delimited paths (folders are derived). ARIA `tree`/`treeitem`. * Selecting a file fires a `select` event (`detail.path`). Fills its container. * * For a changed-files / diff view, give each file `additions`/`deletions`/`status` * (rendered as trailing `+N`/`-N` stats and a colored status letter), and set the * `summary` attribute for a header with the changed-file count, summed `+/-`, and a * Collapse-all toggle. Restyle the diff bits via `::part(summary | status | * stat-additions | stat-deletions)`. */ defineWebComponent('kai-file-tree', { files: [], activeFile: undefined, defaultExpanded: undefined, summary: false, }, (props, { dispatch, flag }) => ( <> {/* Fill the container + own the scroll (see resizable.tsx fill technique: a definite `1fr` grid cell scoped to a wrapper, NOT :host, so the facade's sibling portal-mount div can't steal a grid track). */}
dispatch('kai-select', { path })} />
));