nuxt-upload-kit 0.1.4 → 0.1.5
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
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
- 🎥 **Video Compression** - FFmpeg-powered video compression (optional)
|
|
15
15
|
- ✅ **Validation** - File type, size, and count validation out of the box
|
|
16
16
|
- 📊 **Progress Tracking** - Real-time upload progress with events
|
|
17
|
-
- 🔄 **File Lifecycle** - Complete control over file preprocessing, processing, and post-upload
|
|
18
17
|
|
|
19
18
|
## Installation
|
|
20
19
|
|
|
@@ -91,80 +90,9 @@ const handleUpload = () => uploader.upload()
|
|
|
91
90
|
</template>
|
|
92
91
|
```
|
|
93
92
|
|
|
94
|
-
##
|
|
93
|
+
## Documentation
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
import { PluginAzureDataLake } from "nuxt-upload-kit"
|
|
100
|
-
|
|
101
|
-
const uploader = useUploadKit({
|
|
102
|
-
storage: PluginAzureDataLake({
|
|
103
|
-
sasURL: "https://your-storage.blob.core.windows.net/container?sv=...",
|
|
104
|
-
path: "uploads/images",
|
|
105
|
-
}),
|
|
106
|
-
thumbnails: true,
|
|
107
|
-
})
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
## Configuration Options
|
|
111
|
-
|
|
112
|
-
| Option | Type | Default | Description |
|
|
113
|
-
| ------------------ | ------------------------------- | ------- | ------------------------------- |
|
|
114
|
-
| `storage` | `StoragePlugin` | - | Storage plugin for file uploads |
|
|
115
|
-
| `plugins` | `ProcessingPlugin[]` | `[]` | Additional processing plugins |
|
|
116
|
-
| `maxFiles` | `number \| false` | `false` | Maximum number of files |
|
|
117
|
-
| `maxFileSize` | `number \| false` | `false` | Maximum file size in bytes |
|
|
118
|
-
| `allowedFileTypes` | `string[] \| false` | `false` | Allowed MIME types |
|
|
119
|
-
| `thumbnails` | `boolean \| ThumbnailOptions` | `false` | Enable thumbnail generation |
|
|
120
|
-
| `imageCompression` | `boolean \| CompressionOptions` | `false` | Enable image compression |
|
|
121
|
-
| `autoProceed` | `boolean` | `false` | Auto-upload after adding files |
|
|
122
|
-
|
|
123
|
-
## Events
|
|
124
|
-
|
|
125
|
-
```typescript
|
|
126
|
-
uploader.on("file:added", (file) => console.log("Added:", file.name))
|
|
127
|
-
uploader.on("file:removed", (file) => console.log("Removed:", file.name))
|
|
128
|
-
uploader.on("file:error", ({ file, error }) => console.error(error))
|
|
129
|
-
uploader.on("upload:start", (files) => console.log("Starting upload"))
|
|
130
|
-
uploader.on("upload:progress", ({ file, progress }) => console.log(progress))
|
|
131
|
-
uploader.on("upload:complete", (files) => console.log("Complete!"))
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
## Creating Custom Plugins
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
import { defineProcessingPlugin } from "nuxt-upload-kit"
|
|
138
|
-
|
|
139
|
-
const MyPlugin = defineProcessingPlugin<{ option: string }>((options) => ({
|
|
140
|
-
id: "my-plugin",
|
|
141
|
-
hooks: {
|
|
142
|
-
validate: async (file, context) => {
|
|
143
|
-
// Validation logic
|
|
144
|
-
return file
|
|
145
|
-
},
|
|
146
|
-
process: async (file, context) => {
|
|
147
|
-
// Processing logic
|
|
148
|
-
context.emit("processed", { file })
|
|
149
|
-
return file
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
}))
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
## Optional Dependencies
|
|
156
|
-
|
|
157
|
-
For video compression, install FFmpeg:
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
pnpm add @ffmpeg/ffmpeg @ffmpeg/util
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
For Azure storage, install the Azure SDK:
|
|
164
|
-
|
|
165
|
-
```bash
|
|
166
|
-
pnpm add @azure/storage-file-datalake
|
|
167
|
-
```
|
|
95
|
+
For full documentation, visit [nuxt-upload-kit.vercel.app](https://nuxt-upload-kit.vercel.app)
|
|
168
96
|
|
|
169
97
|
## License
|
|
170
98
|
|
package/dist/module.json
CHANGED
|
@@ -21,7 +21,7 @@ const defaultOptions = {
|
|
|
21
21
|
maxFiles: false,
|
|
22
22
|
thumbnails: false,
|
|
23
23
|
imageCompression: false,
|
|
24
|
-
|
|
24
|
+
autoUpload: false
|
|
25
25
|
};
|
|
26
26
|
export const useUploadKit = (_options = {}) => {
|
|
27
27
|
const options = { ...defaultOptions, ..._options };
|
|
@@ -29,6 +29,7 @@ export const useUploadKit = (_options = {}) => {
|
|
|
29
29
|
const emitter = mitt();
|
|
30
30
|
const status = ref("waiting");
|
|
31
31
|
const createdObjectURLs = /* @__PURE__ */ new Map();
|
|
32
|
+
let hasEmittedFilesUploaded = false;
|
|
32
33
|
const pluginEmitFunctions = /* @__PURE__ */ new Map();
|
|
33
34
|
const getPluginEmitFn = (pluginId) => {
|
|
34
35
|
let emitFn = pluginEmitFunctions.get(pluginId);
|
|
@@ -199,7 +200,8 @@ This is deprecated. Use the 'storage' option instead:
|
|
|
199
200
|
const fileToAdd = preprocessedFile || validatedFile;
|
|
200
201
|
files.value.push(fileToAdd);
|
|
201
202
|
emitter.emit("file:added", fileToAdd);
|
|
202
|
-
|
|
203
|
+
hasEmittedFilesUploaded = false;
|
|
204
|
+
if (options.autoUpload) {
|
|
203
205
|
upload();
|
|
204
206
|
}
|
|
205
207
|
return validatedFile;
|
|
@@ -320,7 +322,8 @@ This is deprecated. Use the 'storage' option instead:
|
|
|
320
322
|
files.value[index] = finalFile;
|
|
321
323
|
emitter.emit("file:replaced", finalFile);
|
|
322
324
|
emitter.emit("file:added", finalFile);
|
|
323
|
-
|
|
325
|
+
hasEmittedFilesUploaded = false;
|
|
326
|
+
const shouldUpload = shouldAutoUpload ?? options.autoUpload;
|
|
324
327
|
if (shouldUpload) {
|
|
325
328
|
upload();
|
|
326
329
|
}
|
|
@@ -400,6 +403,11 @@ This is deprecated. Use the 'storage' option instead:
|
|
|
400
403
|
}
|
|
401
404
|
const completed = files.value.filter((f) => f.status === "complete");
|
|
402
405
|
emitter.emit("upload:complete", completed);
|
|
406
|
+
const allComplete = files.value.every((f) => f.status === "complete");
|
|
407
|
+
if (allComplete && files.value.length > 0 && !hasEmittedFilesUploaded) {
|
|
408
|
+
hasEmittedFilesUploaded = true;
|
|
409
|
+
emitter.emit("files:uploaded", files.value);
|
|
410
|
+
}
|
|
403
411
|
};
|
|
404
412
|
const reset = () => {
|
|
405
413
|
cleanupObjectURLs(createdObjectURLs);
|
|
@@ -431,25 +439,23 @@ This is deprecated. Use the 'storage' option instead:
|
|
|
431
439
|
let currentFile = file;
|
|
432
440
|
for (const plugin of options.plugins) {
|
|
433
441
|
const hook = plugin.hooks[stage];
|
|
434
|
-
if (hook)
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
emitter.emit("file:error", { file: currentFile, error });
|
|
449
|
-
}
|
|
450
|
-
console.error(`Plugin ${plugin.id} ${stage} hook error:`, error);
|
|
451
|
-
return null;
|
|
442
|
+
if (!hook) continue;
|
|
443
|
+
try {
|
|
444
|
+
const context = {
|
|
445
|
+
files: files.value,
|
|
446
|
+
options,
|
|
447
|
+
emit: getPluginEmitFn(plugin.id)
|
|
448
|
+
};
|
|
449
|
+
const result = await callPluginHook(hook, stage, currentFile, context);
|
|
450
|
+
if (result && currentFile && "id" in result) {
|
|
451
|
+
currentFile = result;
|
|
452
|
+
}
|
|
453
|
+
} catch (error) {
|
|
454
|
+
if (currentFile) {
|
|
455
|
+
emitter.emit("file:error", { file: currentFile, error });
|
|
452
456
|
}
|
|
457
|
+
console.error(`Plugin ${plugin.id} ${stage} hook error:`, error);
|
|
458
|
+
return null;
|
|
453
459
|
}
|
|
454
460
|
}
|
|
455
461
|
return currentFile;
|
|
@@ -230,7 +230,7 @@ export interface UploadOptions {
|
|
|
230
230
|
* Automatically start upload after files are added
|
|
231
231
|
* @default false
|
|
232
232
|
*/
|
|
233
|
-
|
|
233
|
+
autoUpload?: boolean;
|
|
234
234
|
}
|
|
235
235
|
export interface ThumbnailOptions {
|
|
236
236
|
width?: number;
|
|
@@ -265,6 +265,8 @@ type CoreUploaderEvents<TUploadResult = any> = {
|
|
|
265
265
|
oldIndex: number;
|
|
266
266
|
newIndex: number;
|
|
267
267
|
};
|
|
268
|
+
/** Emitted when all files have finished uploading (all files have 'complete' status) */
|
|
269
|
+
"files:uploaded": Array<Readonly<UploadFile<TUploadResult>>>;
|
|
268
270
|
};
|
|
269
271
|
export type UploaderEvents<TUploadResult = any> = CoreUploaderEvents<TUploadResult>;
|
|
270
272
|
/**
|
package/package.json
CHANGED