nuxt-upload-kit 0.1.11 → 0.1.13

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-upload-kit",
3
3
  "configKey": "uploadKit",
4
- "version": "0.1.11",
4
+ "version": "0.1.13",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -184,6 +184,7 @@ export declare const useUploadKit: <TUploadResult = any>(_options?: UploadOption
184
184
  };
185
185
  })[]>>;
186
186
  totalProgress: import("vue").ComputedRef<number>;
187
+ isReady: Readonly<import("vue").Ref<boolean, boolean>>;
187
188
  addFiles: (newFiles: File[]) => Promise<UploadFile[]>;
188
189
  addFile: (file: File) => Promise<UploadFile>;
189
190
  onGetRemoteFile: (fn: GetRemoteFileFn) => void;
@@ -1,5 +1,5 @@
1
1
  import mitt from "mitt";
2
- import { computed, onBeforeUnmount, readonly, ref } from "vue";
2
+ import { computed, isRef, onBeforeUnmount, readonly, ref, toValue, watch } from "vue";
3
3
  import { ValidatorAllowedFileTypes, ValidatorMaxFileSize, ValidatorMaxFiles } from "./validators/index.js";
4
4
  import { PluginThumbnailGenerator, PluginImageCompressor } from "./plugins/index.js";
5
5
  import { createPluginContext, createFileError, cleanupObjectURLs } from "./utils.js";
@@ -23,11 +23,48 @@ const defaultOptions = {
23
23
  imageCompression: false,
24
24
  autoUpload: false
25
25
  };
26
+ function setupInitialFiles({
27
+ initialFiles,
28
+ files,
29
+ isReady,
30
+ emitter,
31
+ initializeExistingFiles
32
+ }) {
33
+ if (initialFiles === void 0) return;
34
+ let isInitialized = false;
35
+ const doInitialize = async (value) => {
36
+ if (isInitialized || !value || files.value.length > 0) return;
37
+ const paths = Array.isArray(value) ? value : [value];
38
+ if (paths.length > 0 && paths.every(Boolean)) {
39
+ isInitialized = true;
40
+ try {
41
+ await initializeExistingFiles(paths.map((id) => ({ id })));
42
+ isReady.value = true;
43
+ emitter.emit("initialFiles:loaded", files.value);
44
+ } catch (error) {
45
+ isReady.value = true;
46
+ emitter.emit("initialFiles:error", error);
47
+ }
48
+ } else {
49
+ isReady.value = true;
50
+ }
51
+ };
52
+ if (isRef(initialFiles)) {
53
+ watch(
54
+ () => toValue(initialFiles),
55
+ (newValue) => doInitialize(newValue),
56
+ { immediate: true }
57
+ );
58
+ } else {
59
+ doInitialize(initialFiles);
60
+ }
61
+ }
26
62
  export const useUploadKit = (_options = {}) => {
27
63
  const options = { ...defaultOptions, ..._options };
28
64
  const files = ref([]);
29
65
  const emitter = mitt();
30
66
  const status = ref("waiting");
67
+ const isReady = ref(options.initialFiles === void 0);
31
68
  const createdObjectURLs = /* @__PURE__ */ new Map();
32
69
  let hasEmittedFilesUploaded = false;
33
70
  const pluginEmitFunctions = /* @__PURE__ */ new Map();
@@ -164,8 +201,10 @@ This is deprecated. Use the 'storage' option instead:
164
201
  remoteUrl: remoteFileData.remoteUrl,
165
202
  preview: remoteFileData.preview || file.preview || remoteFileData.remoteUrl,
166
203
  // Use preview from storage, passed-in value, or fallback to remoteUrl
167
- source: "storage"
204
+ source: "storage",
168
205
  // File loaded from remote storage
206
+ // Set uploadResult for consistency with newly uploaded files
207
+ uploadResult: remoteFileData.uploadResult
169
208
  };
170
209
  return existingFile;
171
210
  })
@@ -460,10 +499,18 @@ This is deprecated. Use the 'storage' option instead:
460
499
  }
461
500
  return currentFile;
462
501
  }
502
+ setupInitialFiles({
503
+ initialFiles: options.initialFiles,
504
+ files,
505
+ isReady,
506
+ emitter,
507
+ initializeExistingFiles
508
+ });
463
509
  return {
464
510
  // State
465
511
  files: readonly(files),
466
512
  totalProgress,
513
+ isReady: readonly(isReady),
467
514
  // Core Methods
468
515
  addFiles,
469
516
  addFile,
@@ -119,7 +119,12 @@ export const PluginAzureDataLake = defineStorageAdapter((options) => {
119
119
  return {
120
120
  size: properties.contentLength || 0,
121
121
  mimeType: properties.contentType || "application/octet-stream",
122
- remoteUrl: fileClient.url
122
+ remoteUrl: fileClient.url,
123
+ // Include uploadResult for consistency with newly uploaded files
124
+ uploadResult: {
125
+ url: fileClient.url,
126
+ blobPath: fileClient.name
127
+ }
123
128
  };
124
129
  }, `Get remote file "${fileId}"`);
125
130
  },
@@ -1,4 +1,5 @@
1
1
  import type { Emitter } from "mitt";
2
+ import type { MaybeRef } from "vue";
2
3
  /**
3
4
  * PUBLIC API - Types users commonly need
4
5
  * These are exported from the main package
@@ -231,6 +232,25 @@ export interface UploadOptions {
231
232
  * @default false
232
233
  */
233
234
  autoUpload?: boolean;
235
+ /**
236
+ * Initialize with existing file paths/IDs (e.g., from a form model)
237
+ * Accepts a static array or a reactive ref for deferred initialization.
238
+ *
239
+ * When a ref is provided, the composable watches it and initializes
240
+ * files once on first truthy value.
241
+ *
242
+ * @example Static value
243
+ * ```typescript
244
+ * useUploadKit({ initialFiles: ['path/to/image.jpg'] })
245
+ * ```
246
+ *
247
+ * @example Reactive ref (from defineModel)
248
+ * ```typescript
249
+ * const model = defineModel<string[]>()
250
+ * useUploadKit({ initialFiles: model })
251
+ * ```
252
+ */
253
+ initialFiles?: MaybeRef<string | string[] | undefined>;
234
254
  }
235
255
  export interface ThumbnailOptions {
236
256
  width?: number;
@@ -267,6 +287,10 @@ type CoreUploaderEvents<TUploadResult = any> = {
267
287
  };
268
288
  /** Emitted when all files have finished uploading (all files have 'complete' status) */
269
289
  "files:uploaded": Array<Readonly<UploadFile<TUploadResult>>>;
290
+ /** Emitted when initialFiles have been loaded from storage */
291
+ "initialFiles:loaded": Array<Readonly<UploadFile<TUploadResult>>>;
292
+ /** Emitted when initialFiles failed to load */
293
+ "initialFiles:error": unknown;
270
294
  };
271
295
  export type UploaderEvents<TUploadResult = any> = CoreUploaderEvents<TUploadResult>;
272
296
  /**
@@ -485,10 +509,16 @@ export type Processor = (file: UploadFile) => Promise<File | Blob>;
485
509
  export interface UploadBlob {
486
510
  blobPath: string;
487
511
  }
488
- type MinimumRemoteFileAttributes = {
512
+ export type MinimumRemoteFileAttributes<TUploadResult = any> = {
489
513
  size: number;
490
514
  mimeType: string;
491
515
  remoteUrl: string;
492
516
  preview?: string;
517
+ /**
518
+ * Optional upload result from storage plugin.
519
+ * When provided, this will be set on initialized files for consistency
520
+ * with newly uploaded files, eliminating the need for special handling.
521
+ */
522
+ uploadResult?: TUploadResult;
493
523
  };
494
524
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-upload-kit",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "A powerful, plugin-based file upload manager for Nuxt applications",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/genu/nuxt-upload-kit.git",
@@ -43,9 +43,9 @@
43
43
  "mitt": "^3.0.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@aws-sdk/client-s3": "^3.970.0",
47
- "@aws-sdk/lib-storage": "^3.970.0",
48
- "@azure/storage-file-datalake": "^12.28.1",
46
+ "@aws-sdk/client-s3": "^3.974.0",
47
+ "@aws-sdk/lib-storage": "^3.974.0",
48
+ "@azure/storage-file-datalake": "^12.29.0",
49
49
  "@ffmpeg/ffmpeg": "0.12.15",
50
50
  "@ffmpeg/util": "0.12.2",
51
51
  "@nuxt/devtools": "^3.1.1",
@@ -55,19 +55,19 @@
55
55
  "@nuxt/test-utils": "^3.23.0",
56
56
  "@types/node": "latest",
57
57
  "@vitejs/plugin-vue": "^6.0.3",
58
- "@vitest/coverage-v8": "^4.0.17",
58
+ "@vitest/coverage-v8": "^4.0.18",
59
59
  "changelogen": "^0.6.2",
60
60
  "eslint": "^9.39.2",
61
61
  "eslint-config-prettier": "10.1.8",
62
62
  "eslint-plugin-prettier": "5.5.5",
63
63
  "firebase": "^12.8.0",
64
- "happy-dom": "^20.3.1",
64
+ "happy-dom": "^20.3.4",
65
65
  "nuxt": "^4.2.2",
66
- "prettier": "^3.8.0",
66
+ "prettier": "^3.8.1",
67
67
  "typescript": "~5.9.3",
68
68
  "unbuild": "^3.6.1",
69
- "vitest": "^4.0.17",
70
- "vue": "^3.5.26",
69
+ "vitest": "^4.0.18",
70
+ "vue": "^3.5.27",
71
71
  "vue-tsc": "^3.2.2"
72
72
  },
73
73
  "peerDependencies": {