@cubone/react-file-manager 1.13.1 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -32
- package/dist/react-file-manager.es.js +724 -711
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
|
|
5
|
-

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
6
8
|
|
|
7
9
|
</div>
|
|
8
10
|
|
|
@@ -12,13 +14,19 @@ An open-source React.js package for easy integration of a file manager into appl
|
|
|
12
14
|
|
|
13
15
|
## ✨ Features
|
|
14
16
|
|
|
15
|
-
- **File & Folder Management**: View, upload, download, delete, copy, move, create, and rename files
|
|
17
|
+
- **File & Folder Management**: View, upload, download, delete, copy, move, create, and rename files
|
|
18
|
+
or folders seamlessly.
|
|
16
19
|
- **Grid & List View**: Switch between grid and list views to browse files in your preferred layout.
|
|
17
|
-
- **Navigation**: Use the breadcrumb trail and sidebar navigation pane for quick directory
|
|
18
|
-
|
|
19
|
-
- **
|
|
20
|
-
|
|
21
|
-
- **
|
|
20
|
+
- **Navigation**: Use the breadcrumb trail and sidebar navigation pane for quick directory
|
|
21
|
+
traversal.
|
|
22
|
+
- **Toolbar & Context Menu**: Access all common actions (upload, download, delete, copy, move,
|
|
23
|
+
rename, etc.) via the toolbar or right-click for the same options in the context menu.
|
|
24
|
+
- **Multi-Selection**: Select multiple files and folders at once to perform bulk actions like
|
|
25
|
+
delete, copy, move, or download.
|
|
26
|
+
- **Keyboard Shortcuts**: Quickly perform file operations like copy, paste, delete, and more using
|
|
27
|
+
intuitive keyboard shortcuts.
|
|
28
|
+
- **Drag-and-Drop**: Move selected files and folders by dragging them to the desired directory,
|
|
29
|
+
making file organization effortless.
|
|
22
30
|
|
|
23
31
|

|
|
24
32
|
|
|
@@ -74,7 +82,9 @@ export default App;
|
|
|
74
82
|
|
|
75
83
|
## 📂 File Structure
|
|
76
84
|
|
|
77
|
-
The `files` prop accepts an array of objects, where each object represents a file or folder. You can
|
|
85
|
+
The `files` prop accepts an array of objects, where each object represents a file or folder. You can
|
|
86
|
+
customize the structure to meet your application needs. Each file or folder object follows the
|
|
87
|
+
structure detailed below:
|
|
78
88
|
|
|
79
89
|
```typescript
|
|
80
90
|
type File = {
|
|
@@ -88,30 +98,31 @@ type File = {
|
|
|
88
98
|
|
|
89
99
|
## ⚙️ Props
|
|
90
100
|
|
|
91
|
-
| Name
|
|
92
|
-
|
|
|
93
|
-
| `acceptedFileTypes`
|
|
94
|
-
| `enableFilePreview`
|
|
95
|
-
| `filePreviewPath`
|
|
96
|
-
| `
|
|
97
|
-
| `
|
|
98
|
-
| `
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
| `
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
114
|
-
| `
|
|
101
|
+
| Name | Type | Description |
|
|
102
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| `acceptedFileTypes` | string | (Optional) A comma-separated list of allowed file extensions for uploading specific file types (e.g., `.txt, .png, .pdf`). If omitted, all file types are accepted. |
|
|
104
|
+
| `enableFilePreview` | boolean | A boolean flag indicating whether to use the default file previewer in the file manager `default: true`. |
|
|
105
|
+
| `filePreviewPath` | string | The base URL for file previews e.g.`https://example.com`, file path will be appended automatically to it i.e. `https://example.com/yourFilePath`. |
|
|
106
|
+
| `filePreviewComponent` | (file: [File](#-file-structure)) => React.ReactNode | (Optional) A callback function that provides a custom file preview. It receives the selected file as its argument and must return a valid React node, JSX element, or HTML. Use this prop to override the default file preview behavior. Example: [Custom Preview Usage](#-custom-file-preview). |
|
|
107
|
+
| `fileUploadConfig` | { url: string; headers?: { [key: string]: string } } | Configuration object for file uploads. It includes the upload URL (`url`) and an optional `headers` object for setting custom HTTP headers in the upload request. The `headers` object can accept any standard or custom headers required by the server. Example: `{ url: "https://example.com/fileupload", headers: { Authorization: "Bearer" + TOKEN, "X-Custom-Header": "value" } }` |
|
|
108
|
+
| `files` | Array<[File](#-file-structure)> | An array of file and folder objects representing the current directory structure. Each object includes `name`, `isDirectory`, and `path` properties. |
|
|
109
|
+
| `height` | string \| number | The height of the component `default: 600px`. Can be a string (e.g., `'100%'`, `'10rem'`) or a number (in pixels). |
|
|
110
|
+
| `initialPath` | string | The path of the directory to be loaded initially e.g. `/Documents`. This should be the path of a folder which is included in `files` array. Default value is `""` |
|
|
111
|
+
| `isLoading` | boolean | A boolean state indicating whether the application is currently performing an operation, such as creating, renaming, or deleting a file/folder. Displays a loading state if set `true`. |
|
|
112
|
+
| `layout` | "list" \| "grid" | Specifies the default layout style for the file manager. Can be either "list" or "grid". Default value is "grid". |
|
|
113
|
+
| `maxFileSize` | number | For limiting the maximum upload file size in bytes. |
|
|
114
|
+
| `onCreateFolder` | (name: string, parentFolder: [File](#-file-structure)) => void | A callback function triggered when a new folder is created. Use this function to update the files state to include the new folder under the specified parent folder using create folder API call to your server. |
|
|
115
|
+
| `onDelete` | (files: Array<[File](#-file-structure)>) => void | A callback function is triggered when one or more files or folders are deleted. |
|
|
116
|
+
| `onDownload` | (files: Array<[File](#-file-structure)>) => void | A callback function triggered when one or more files or folders are downloaded. |
|
|
117
|
+
| `onError` | (error: { type: string, message: string }, file: [File](#-file-structure)) => void | A callback function triggered whenever there is an error in the file manager. Where error is an object containing `type` ("upload", etc.) and a descriptive error `message`. |
|
|
118
|
+
| `onFileOpen` | (file: [File](#-file-structure)) => void | A callback function triggered when a file or folder is opened. |
|
|
119
|
+
| `onFileUploaded` | (response: { [key: string]: any }) => void | A callback function triggered after a file is successfully uploaded. Provides JSON `response` holding uploaded file details, use it to extract the uploaded file details and add it to the `files` state e.g. `setFiles((prev) => [...prev, JSON.parse(response)]);` |
|
|
120
|
+
| `onFileUploading` | (file: [File](#-file-structure), parentFolder: [File](#-file-structure)) => { [key: string]: any } | A callback function triggered during the file upload process. You can also return an object with key-value pairs that will be appended to the `FormData` along with the file being uploaded. The object can contain any number of valid properties. |
|
|
121
|
+
| `onLayoutChange` | (layout: "list" \| "grid") => void | A callback function triggered when the layout of the file manager is changed. |
|
|
122
|
+
| `onPaste` | (files: Array<[File](#-file-structure)>, destinationFolder: [File](#-file-structure), operationType: "copy" \| "move") => void | A callback function triggered when when one or more files or folders are pasted into a new location. Depending on `operationType`, use this to either copy or move the `sourceItem` to the `destinationFolder`, updating the files state accordingly. |
|
|
123
|
+
| `onRefresh` | () => void | A callback function triggered when the file manager is refreshed. Use this to refresh the `files` state to reflect any changes or updates. |
|
|
124
|
+
| `onRename` | (file: [File](#-file-structure), newName: string) => void | A callback function triggered when a file or folder is renamed. |
|
|
125
|
+
| `width` | string \| number | The width of the component `default: 100%`. Can be a string (e.g., `'100%'`, `'10rem'`) or a number (in pixels). |
|
|
115
126
|
|
|
116
127
|
## ⌨️ Keyboard Shortcuts
|
|
117
128
|
|
|
@@ -135,6 +146,25 @@ type File = {
|
|
|
135
146
|
| Refresh File List | `F5` |
|
|
136
147
|
| Clear Selection | `Esc` |
|
|
137
148
|
|
|
149
|
+
## Custom File Preview
|
|
150
|
+
|
|
151
|
+
The `FileManager` component allows you to provide a custom file preview by passing the
|
|
152
|
+
`filePreviewComponent` prop. This is an optional callback function that receives the selected file
|
|
153
|
+
as an argument and must return a valid React node, JSX element, or HTML.
|
|
154
|
+
|
|
155
|
+
### Usage Example
|
|
156
|
+
|
|
157
|
+
```jsx
|
|
158
|
+
const CustomImagePreviewer = ({ file }) => {
|
|
159
|
+
return <img src={`${file.path}`} alt={file.name} />;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
<FileManager
|
|
163
|
+
// Other props...
|
|
164
|
+
filePreviewComponent={(file) => <CustomImagePreviewer file={file} />}
|
|
165
|
+
/>;
|
|
166
|
+
```
|
|
167
|
+
|
|
138
168
|
## 🤝 Contributing
|
|
139
169
|
|
|
140
170
|
Contributions are welcome! To contribute:
|