Skip to main content

Explorer

Usage

import { explorer, filePickerSave, filePickerOpen, folderPicker } from "/42/ui/desktop/explorer.js"

Function Signature

await explorer(path: string, options: Plan): ExplorerComponent

Parameters

ParameterTypeDescription
pathstringThe initial directory path to open. Defaults to /.
optionsPlan

Options

The options parameter accepts the following properties:

PropertyTypeDescription
pictostringIcon to display in the dialog. Defaults to transparent.
isPickerbooleanIf true, enables file picker mode.
filterstringFilter for displayed files (e.g., *.txt).
filterTypestringType of filter applied. Defaults to disable.
multiselectablebooleanAllows selecting multiple files. Defaults to false.
dialogPlan
signalAbortSignalOptional signal to abort the operation.

Notes

  • You can navigate to parent directories using Alt+Up or Backspace, as long as no file is selected and you're not focusing a button.

Example Usage

Basic Explorer

await explorer("/", {
picto: "folder",
multiselectable: true,
})

File Picker

await explorer("~/documents", {
isPicker: true,
filter: "*.txt",
dialog: {
class: "custom-dialog",
},
})

Save File Dialog

await filePickerSave("~/downloads", {
suggestedName: "newfile.txt",
})

File Picker Open

Function Signature

await filePickerOpen(path: string, options: Plan): { ok: boolean, directory: string, selection: string[] }

Parameters

ParameterTypeDescription
pathstringThe initial directory path to open. Defaults to /.
optionsPlan

Options

PropertyTypeDescription
multiplebooleanAllows selecting multiple files. Defaults to false.
returnFilesbooleanIf true, returns file objects instead of paths. Defaults to false.
dialogPlan

Example Usage

await filePickerOpen("~/documents", {
multiple: true,
returnFiles: true,
})

File Picker Save

Function Signature

await filePickerSave(path: string, options: Plan): { ok: boolean, directory: string, selection: string[] }

Parameters

ParameterTypeDescription
pathstringThe initial directory path to open. Defaults to /.
optionsPlan

Options

PropertyTypeDescription
suggestedNamestringDefault name for the file to save.
dialogobjectDialog-specific options like class, footer, etc.

Example Usage

await filePickerSave("~/downloads", {
suggestedName: "newfile.txt",
})

Folder Picker

Function Signature

await folderPicker(path: string, options: Plan): {ok: boolean, directory: string, paths: string[]}: { ok: boolean, directory: string, paths: string[] }

Parameters

ParameterTypeDescription
pathstringThe initial directory path to open. Defaults to /.
optionsPlan

Options

PropertyTypeDescription
returnPathsbooleanIf true, returns all paths in the selected folder.
dialogPlan

Example Usage

await folderPicker("~/projects", {
returnPaths: true,
})