# FileBrowser Widget A powerful WebAssembly-based file browser widget that can be embedded in any web application. Built with Rust and Yew, compiled to WASM for maximum performance. ## Features - 📁 **File & Directory Management**: Browse, create, delete files and directories - 📤 **Resumable Uploads**: Upload files with progress tracking using TUS protocol - 📥 **File Downloads**: Download files with proper MIME type handling - ✏️ **File Editing**: Built-in editors for text files and markdown with live preview - 🎨 **Modern UI**: Responsive Bootstrap-based interface with light/dark themes - 🔧 **Highly Configurable**: Extensive JavaScript API for customization - 🚀 **High Performance**: Compiled to WebAssembly for native-like performance - 🌐 **Cross-Browser**: Works in all modern browsers ## Quick Start ### 1. Installation #### Via npm (recommended) ```bash npm install @herocode/file-browser-widget ``` #### Manual Download Download the latest release files: - `file_browser_widget.js` - `file_browser_widget_bg.wasm` ### 2. Include Dependencies Add Bootstrap CSS and Icons to your HTML: ```html ``` ### 3. Create Container Add a container element to your HTML: ```html
``` ### 4. Initialize Widget ```javascript import init, { create_file_browser_widget, create_default_config } from '@herocode/file-browser-widget'; async function initFileBrowser() { // Initialize the WASM module await init(); // Create configuration const config = create_default_config('http://localhost:3001/files'); config.set_theme('light'); config.set_show_upload(true); config.set_show_download(true); config.set_show_delete(true); config.set_max_file_size(100 * 1024 * 1024); // 100MB // Create and mount the widget const widget = create_file_browser_widget('file-browser-container', config); console.log('FileBrowser widget initialized successfully!'); } // Initialize when page loads initFileBrowser().catch(console.error); ``` ## Configuration API ### WidgetConfig The main configuration object for customizing the widget behavior: ```javascript const config = create_default_config('http://localhost:3001/files'); // File size limit (in bytes) config.set_max_file_size(50 * 1024 * 1024); // 50MB // Feature toggles config.set_show_upload(true); config.set_show_download(true); config.set_show_delete(true); // UI customization config.set_theme('dark'); // 'light' or 'dark' config.set_css_classes('my-custom-class'); config.set_initial_path('documents/'); ``` ### Configuration Options | Option | Type | Default | Description | |--------|------|---------|-------------| | `base_endpoint` | string | required | Backend API endpoint for file operations | | `max_file_size` | number | 104857600 | Maximum file size for uploads (bytes) | | `show_upload` | boolean | true | Enable/disable upload functionality | | `show_download` | boolean | true | Enable/disable download functionality | | `show_delete` | boolean | true | Enable/disable delete functionality | | `theme` | string | 'light' | UI theme ('light' or 'dark') | | `css_classes` | string | '' | Additional CSS classes for root element | | `initial_path` | string | '' | Initial directory path to display | ## JavaScript API ### Functions #### `init()` Initialize the WASM module. Must be called before using other functions. ```javascript await init(); ``` #### `create_default_config(base_endpoint)` Create a default configuration object. ```javascript const config = create_default_config('http://localhost:3001/files'); ``` #### `create_file_browser_widget(container_id, config)` Create and mount a widget to a DOM element by ID. ```javascript const widget = create_file_browser_widget('my-container', config); ``` #### `create_file_browser_widget_on_element(element, config)` Create and mount a widget to a specific DOM element. ```javascript const element = document.getElementById('my-container'); const widget = create_file_browser_widget_on_element(element, config); ``` #### `check_browser_compatibility()` Check if the current browser supports the widget. ```javascript if (!check_browser_compatibility()) { console.error('Browser not supported'); } ``` #### `get_version()` Get the widget version. ```javascript console.log('Widget version:', get_version()); ``` ### Widget Handle The widget functions return a handle that can be used to manage the widget: ```javascript const widget = create_file_browser_widget('container', config); // Destroy the widget widget.destroy(); ``` ## Backend Requirements The widget expects a REST API compatible with the following endpoints: ### File Listing ``` GET /files/list/