declare global { namespace Filesystem { export type FileResult = { name: string; path: string; content?: string | ArrayBuffer; browser_file?: File; no_file?: boolean; }; /** * The resource identifier group, used to allow the file dialog (open and save) to remember where it was last used */ export type ResourceID = string | 'texture' | 'minecraft_skin' | 'dev_plugin' | 'animation' | 'animation_particle' | 'animation_audio' | 'theme' | 'model' | 'gltf' | 'obj' | 'preview_background' | 'screenshot' | 'palette'; export type ReadType = 'buffer' | 'binary' | 'text' | 'image' | 'none'; export interface ReadOptions { readtype?: ReadType | ((file: string) => ReadType); errorbox?: boolean; /** File Extensions */ extensions?: string[]; } export interface ImportOptions extends ReadOptions { /** Name of the file type */ type: string; /** File Extensions */ extensions: string[]; /** Allow selection of multiple elements */ multiple?: boolean; /** File picker start path */ startpath?: string; /** The resource identifier group, used to allow the file dialog (open and save) to remember where it was last used */ resource_id?: ResourceID; /** Title of the file picker window */ title?: string; } /** * Opens a file picker dialog to import one or multiple files into Blockbench * @param options Import options * @param callback Callback to run once the files are imported * @returns */ export function importFile(options: ImportOptions, callback?: (files: FileResult[]) => void): void; export function getImageSource(file: FileResult | string): string; export function readFile(files: string[] | File[], options?: ReadOptions, callback?: (files: FileResult[]) => void): false | { name: string; path: any; }[]; export const read: typeof readFile; export interface PickDirOptions { /**Location where the file dialog starts off */ startpath?: string; /** The resource identifier group, used to allow the file dialog (open and save) to remember where it was last used */ resource_id?: ResourceID; /** Window title for the file picker */ title?: string; } /** * Pick a directory. Desktop app only. */ export function pickDirectory(options?: PickDirOptions): string | undefined; export interface ExportOptions extends WriteOptions { /** * Name of the file type */ type: string; /** * File extensions */ extensions: string[]; /** * Suggested file name */ name?: string; /** * Directory path where the file dialog opens */ startpath?: string; /** * The resource identifier group, used to allow the file dialog (open and save) to remember where it was last used */ resource_id?: string; } /** * Open a file save dialog to let the user pick a location and name to save a file. On the web app, this might save the file directoy into the downloads folder depending on browser settings. * @param options Export options * @param callback Callback to run once the file is saved * @returns */ export function exportFile(options: ExportOptions, callback?: (file_path: string) => void): void; type WriteType = 'text' | 'buffer' | 'binary' | 'zip' | 'image'; export interface WriteOptions { content?: string | ArrayBuffer | Blob; savetype?: WriteType | ((file: string) => WriteType); custom_writer?: (content: string | ArrayBuffer | Blob, file_path: string, callback?: (file_path: string) => void) => void; } /** * Writes a file to the file system. Desktop app only. */ export function writeFile(file_path: string, options: WriteOptions, callback?: (file_path: string) => void): void; export function showFileInFolder(path: string): void; export interface FindFileOptions { recursive: boolean; filter_regex: RegExp; priority_regex?: RegExp; json?: boolean; read_file?: boolean; } /** * Find a file in a directory based on content within the file, optionally optimized via file name match * @param {string[]} base_directories List of base directory paths to search in */ export function findFileFromContent(base_directories: string[], options: FindFileOptions, check_file: (path: string, content: string | object) => T): T | undefined; export interface DragHandlerOptions { /** * Allowed file extensions */ extensions: string[] | (() => string[]); /** * Whether or not to enable the drag handler */ condition?: ConditionResolvable; /** * Drop target element */ element?: string | HTMLElement | (() => string | HTMLElement | boolean); /** * If true, the drop will work on all child elements of the specified element */ propagate?: boolean; readtype?: ReadType; /** * Whether to display an error box when importing a dragged file fails */ errorbox?: boolean; } export interface DragHandler extends DragHandlerOptions { cb: (files: FileResult[], event: DragEvent) => void; delete: () => void; } export const drag_handlers: Record; /** * Handle files being drag & dropped into Blockbench * @param id ID of the handler * @param options Options * @param callback Callback when a file is dropped * @returns */ export function addDragHandler(id: string, options: DragHandlerOptions, callback?: (files: FileResult[], event: DragEvent) => void): DragHandler; export function removeDragHandler(id: string): void; export function getFilePaths(file_names: FileList): string[] | File[]; export {}; } } export {};