interface FileSystemWritableFileStream { write(data: string | ArrayBuffer | ArrayBufferView | Blob): Promise; seek(position: number): Promise; truncate(size: number): Promise; close(): Promise; } export interface FileSystemFileHandle { readonly kind: "file"; readonly name: string; isSameEntry(other: FileSystemFileHandle): Promise; getFile(): Promise; createWritable(options?: { keepExistingData?: boolean; }): Promise; } interface ShowOpenFilePickerOptions { multiple?: boolean; excludeAcceptAllOption?: boolean; types?: { description?: string; accept: Record; }[]; } interface ShowSaveFilePickerOptions { excludeAcceptAllOption?: boolean; suggestedName?: string; types?: { description?: string; accept: Record; }[]; } declare global { interface Window { showOpenFilePicker?(options?: ShowOpenFilePickerOptions): Promise; showSaveFilePicker?(options?: ShowSaveFilePickerOptions): Promise; } } export interface UseFileSystemOptions { /** Map of MIME types to array of extensions, e.g. { 'text/plain': ['.txt', '.md'] } */ accept?: Record; /** Description for the file types, e.g. "Text Files" */ description?: string; } export interface UseFileSystemSaveAsOptions extends UseFileSystemOptions { suggestedName?: string; } export type FileSystemStatus = "idle" | "picking" | "reading" | "saving" | "error"; export interface UseFileSystemReturn { /** True if the File System Access API is supported in the current browser */ isSupported: boolean; /** Current state of the file system operation */ status: FileSystemStatus; /** The current native File object containing metadata (name, size, lastModified) */ file: File | null; /** The internal FileSystemFileHandle used to write to the file */ handle: FileSystemFileHandle | null; /** The text content of the file */ content: string | null; /** Any error encountered during the operation */ error: Error | null; /** Prompts the user to pick a file to open */ open: (options?: UseFileSystemOptions) => Promise; /** Saves data directly back to the currently opened file */ save: (newContent: string | Blob, options?: UseFileSystemSaveAsOptions) => Promise; /** Prompts the user to pick a location to save a new file */ saveAs: (newContent: string | Blob, options?: UseFileSystemSaveAsOptions) => Promise; /** Clears the current file, content, and errors */ reset: () => void; } /** * A hook that utilizes the modern File System Access API to interact with local files on the user's hard drive. * Provides the ability to open, read, and continually save changes to a file without prompting for re-download. * * @param {UseFileSystemOptions} [defaultOptions] - Optional default configuration for file pickers (e.g., accepted MIME types). * @returns {UseFileSystemReturn} An object containing the file state, content, and methods to open/save files. * * @example * ```tsx * const { open, save, content, status } = useFileSystem({ accept: { 'text/plain': ['.txt'] } }); * * return ( *
* * *

File content: {content}

*
* ); * ``` */ export declare function useFileSystem(defaultOptions?: UseFileSystemOptions): UseFileSystemReturn; export {};