Skip to content

code/editor/FileTree

import { … } from 'zidane-ui/code/editor'ui/src/code/editor/FileTree.tsx

Components#

FileTreeComponent#

The workspace file tree: rows from entries, painted with gitStatus, reporting selection, opens and right-clicks.

TypeScript
function FileTree(props: FileTreeProps): Element
Parameters
NameTypeDescription
propsFileTreeProps

The paths, git status and selection to show, and the handlers it reports to.

Element
FileTree props
NameTypeDescription
className?string

Extra classes on the root element.

controlRef?RefObject<FileTreeControl | null>

Receives the imperative handle for search and reveal.

editing?FileTreeEditing

Rename, create, drag and drop. Absent: the tree only browses. Read when the tree is created.

entriesreadonly TreeEntry[]

The paths to show, flat.

gitStatusreadonly TreeGitStatus[]

Git status painted on the rows.

label?string

Accessible name. Default: the fileTree label.

onContextMenu?(target: { kind: 'file' | 'folder'; path: string }, at: { x: number; y: number }) => void

Right-click on a row.

onExpandFolder?(path: string) => void

An ignored folder listed as one node was expanded (its path, without the trailing /).

onOpen(path: string, modifiers: { ctrlKey: boolean; metaKey: boolean }) => void

Fired when the user activates a file (click / Enter), with the modifiers held.

onSelect(path: string | null) => void

Called with the newly selected path, or null when the selection clears.

openPaths?readonly string[]

Files open in the editor: the folders holding them start expanded, every other folder starts collapsed. Read when the tree is created only.

selectedPathstring | null

The selected row's path; null for none.

style?CSSProperties

Inline styles on the root element, merged after the component's own.

ui/src/code/editor/FileTree.tsx:131

Functions#

ancestorDirsFunction#

Every folder holding one of paths (src/, src/chat/), as tree ids.

TypeScript
function ancestorDirs(paths: readonly string[]): string[]
Parameters
NameTypeDescription
pathsreadonly string[]

File paths relative to the tree's root.

string[]

ui/src/code/editor/FileTree.tsx:439

Constants#

TREE_PATH_MIMEConstant#

The drag data type a tree row carries (its path, relative to the tree's root): what an editor takes to open it.

TypeScript
const TREE_PATH_MIME = 'application/x-zidane-tree-path'

ui/src/code/editor/FileTree.tsx:39

Interfaces#

FileTreeControlInterface#

Imperative handle for the bits of the model the tab drives itself.

TypeScript
interface FileTreeControl
FileTreeControl properties
NameTypeDescription
resync() => void

Drops what the tree changed on its own (an optimistic rename or move that failed) and shows entries again.

reveal(path: string) => boolean

Expand ancestors, scroll to and select only path (a folder expands too). false: the tree has no such row.

revealSoon(path: string) => void

Reveals path now, or once the next entries hold it (a row the host just made).

setSearch(value: string | null) => void

Filter rows by substring; null clears.

startCreate(dir: string, kind: 'file' | 'folder', name: string) => boolean

With editing: a placeholder row named name (or the next free variant) in folder dir ('': the root), renamed in place; the chosen name goes to editing.onCreate. false when the tree can't.

startRename(path: string) => boolean

With editing: renames path in place. false when the tree has no such row.

ui/src/code/editor/FileTree.tsx:60

FileTreeEditingInterface#

What the tree reports when it is editable. Paths are relative to its root, without a trailing /.

TypeScript
interface FileTreeEditing
FileTreeEditing properties
NameTypeDescription
onCreate(path: string, kind: 'file' | 'folder') => void

A placeholder row (control.startCreate) named: create it.

onDropFiles?(toDir: string, data: DataTransfer) => void

Files dragged in from outside the page, dropped on folder toDir. Read data now: it empties after the drop.

onError?(message: string) => void

The tree refused a name itself (a sibling has it, or it is empty).

onMove(paths: readonly string[], toDir: string, copy: boolean) => void

Rows dragged onto folder toDir ('': the root); copy: ⌥ was held.

onRename(from: string, to: string, kind: 'file' | 'folder') => void

A row renamed in place.

ui/src/code/editor/FileTree.tsx:79

FileTreePropsInterface#

Props for FileTree.

TypeScript
interface FileTreeProps
FileTreeProps properties
NameTypeDescription
className?string

Extra classes on the root element.

controlRef?RefObject<FileTreeControl | null>

Receives the imperative handle for search and reveal.

editing?FileTreeEditing

Rename, create, drag and drop. Absent: the tree only browses. Read when the tree is created.

entriesreadonly TreeEntry[]

The paths to show, flat.

gitStatusreadonly TreeGitStatus[]

Git status painted on the rows.

label?string

Accessible name. Default: the fileTree label.

onContextMenu?(target: { kind: 'file' | 'folder'; path: string }, at: { x: number; y: number }) => void

Right-click on a row.

onExpandFolder?(path: string) => void

An ignored folder listed as one node was expanded (its path, without the trailing /).

onOpen(path: string, modifiers: { ctrlKey: boolean; metaKey: boolean }) => void

Fired when the user activates a file (click / Enter), with the modifiers held.

onSelect(path: string | null) => void

Called with the newly selected path, or null when the selection clears.

openPaths?readonly string[]

Files open in the editor: the folders holding them start expanded, every other folder starts collapsed. Read when the tree is created only.

selectedPathstring | null

The selected row's path; null for none.

style?CSSProperties

Inline styles on the root element, merged after the component's own.

ui/src/code/editor/FileTree.tsx:93

TreeEntryInterface#

One path in the tree.

TypeScript
interface TreeEntry
TreeEntry properties
NameTypeDescription
ignored?boolean

Dimmed (gitignored).

kind'dir' | 'file'

A file or a directory.

pathstring

Relative to the tree's root; directories end with / (listed only when empty).

ui/src/code/editor/FileTree.tsx:42

TreeGitStatusInterface#

A path's git status, painted on its row.

TypeScript
interface TreeGitStatus
TreeGitStatus properties
NameTypeDescription
pathstring

Relative to the tree's root, without a trailing /.

status'added' | 'deleted' | 'ignored' | 'modified' | 'renamed' | 'untracked'

The change git reports for the path; ignored dims the row.

ui/src/code/editor/FileTree.tsx:52