@cubone/react-file-manager 1.6.0 → 1.7.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 CHANGED
@@ -1,6 +1,15 @@
1
- ![React File Manager](https://github.com/user-attachments/assets/53b09633-220e-460d-a5a5-48f553640dd0)
1
+ ![React File Manager](https://github.com/user-attachments/assets/cad4d71d-a2fd-4064-9fce-c0c3a7cb4613)
2
2
 
3
+ <div align="center">
4
+
5
+ ![NPM Downloads](https://img.shields.io/npm/d18m/%40cubone%2Freact-file-manager?style=for-the-badge) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40cubone%2Freact-file-manager?style=for-the-badge) ![NPM Version](https://img.shields.io/npm/v/%40cubone%2Freact-file-manager?style=for-the-badge&color=%23c87d32)
6
+
7
+ </div>
8
+ <br>
9
+
10
+ <p>
3
11
  An open-source React.js package for easy integration of a file manager into applications. It provides a user-friendly interface for managing files and folders, including viewing, uploading, and deleting, with full UI and backend integration.
12
+ </p>
4
13
 
5
14
  ## ✨ Features
6
15
 
@@ -21,7 +30,7 @@ npm i @cubone/react-file-manager
21
30
 
22
31
  Here’s a basic example of how to use the File Manager Component in your React application:
23
32
 
24
- ```javascript
33
+ ```jsx
25
34
  import { useState } from "react";
26
35
  import { FileManager } from "@cubone/react-file-manager";
27
36
  import "@cubone/react-file-manager/dist/style.css";
@@ -32,19 +41,19 @@ function App() {
32
41
  name: "Documents",
33
42
  isDirectory: true, // Folder
34
43
  path: "/Documents", // Located in Root directory
35
- updatedAt: "2024-09-09T10:30:00Z", // Last updated time (ISO 8601 format)
44
+ updatedAt: "2024-09-09T10:30:00Z", // Last updated time
36
45
  },
37
46
  {
38
47
  name: "Pictures",
39
- isDirectory: true, // Folder
40
- path: "/Pictures", // Located in Root directory
41
- updatedAt: "2024-09-09T11:00:00Z", // Last updated time (ISO 8601 format)
48
+ isDirectory: true,
49
+ path: "/Pictures", // Located in Root directory as well
50
+ updatedAt: "2024-09-09T11:00:00Z",
42
51
  },
43
52
  {
44
53
  name: "Pic.png",
45
54
  isDirectory: false, // File
46
55
  path: "/Pictures/Pic.png", // Located inside the "Pictures" folder
47
- updatedAt: "2024-09-08T16:45:00Z", // Last updated time (ISO 8601 format)
56
+ updatedAt: "2024-09-08T16:45:00Z",
48
57
  size: 2048, // File size in bytes (example: 2 KB)
49
58
  },
50
59
  ]);
@@ -55,6 +64,8 @@ function App() {
55
64
  </>
56
65
  );
57
66
  }
67
+
68
+ export default App;
58
69
  ```
59
70
 
60
71
  ## 📂 File Structure
@@ -63,30 +74,39 @@ The `files` prop accepts an array of objects, where each object represents a fil
63
74
 
64
75
  ```typescript
65
76
  type File = {
66
- name: string;
67
- isDirectory: boolean;
68
- path: string;
69
- updatedAt?: string;
70
- size?: number;
77
+ name: string; // The name of the file or folder
78
+ isDirectory: boolean; // `true` if it's a folder, `false` if it's a file
79
+ path: string; // Full path of the file or folder
80
+ updatedAt?: string; // Optional: Last update timestamp in ISO 8601 format
81
+ size?: number; // Optional: File size in bytes (only applicable for files)
71
82
  };
72
83
  ```
73
84
 
85
+ Here is the updated table with the props sorted in ascending order by name:
86
+
74
87
  ## ⚙️ Props
75
88
 
76
- | Name | Type | Description |
77
- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
78
- | `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. |
79
- | `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`. |
80
- | `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" } }` |
81
- | `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`. |
82
- | `allowedFileExtensions` | String | A comma-separated list of allowed file extensions for uploading files. (e.g., `.txt, .png, .pdf`). |
83
- | `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. |
84
- | `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. |
85
- | `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)]);` |
86
- | `onRename` | (file: [File](#-file-structure), newName: string) => void | A callback function triggered when a file or folder is renamed. |
87
- | `onDelete` | (file: [File](#-file-structure)) => void | A callback function triggered when a file or folder is deleted. |
88
- | `onPaste` | (file: [File](#-file-structure), destinationFolder: [File](#-file-structure), operationType: "copy" \| "move") => void | A callback function triggered when a file or folder is 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. |
89
- | `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. |
89
+ | Name | Type | Description |
90
+ | ------------------- | ---------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
91
+ | `acceptedFileTypes` | String | A comma-separated list of allowed file extensions for uploading files. (e.g.,`.txt, .png, .pdf`). |
92
+ | `enableFilePreview` | boolean | A boolean flag indicating whether to use the default file previewer in the file manager. |
93
+ | `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`. |
94
+ | `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" } }` |
95
+ | `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. |
96
+ | `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`. |
97
+ | `layout` | "list" \| "grid" | Specifies the default layout style for the file manager. Can be either "list" or "grid". Default value is "grid". |
98
+ | `maxFileSize` | number | For limiting the maximum upload file size in bytes. |
99
+ | `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. |
100
+ | `onDelete` | (file: [File](#-file-structure)) => void | A callback function triggered when a file or folder is deleted. |
101
+ | `onDownload` | (file: [File](#-file-structure)) => void | A callback function triggered when a file is downloaded. |
102
+ | `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`. |
103
+ | `onFileOpen` | (file: [File](#-file-structure)) => void | A callback function triggered when a file or folder is opened. |
104
+ | `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)]);` |
105
+ | `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. |
106
+ | `onLayoutChange` | (layout: "list" \| "grid") => void | A callback function triggered when the layout of the file manager is changed. |
107
+ | `onPaste` | (file: [File](#-file-structure), destinationFolder: [File](#-file-structure), operationType: "copy" \| "move") => void | A callback function triggered when a file or folder is 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. |
108
+ | `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. |
109
+ | `onRename` | (file: [File](#-file-structure), newName: string) => void | A callback function triggered when a file or folder is renamed. |
90
110
 
91
111
  ## 🤝 Contributing
92
112