nuxt-upload-kit 0.1.10 → 0.1.12

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.10",
4
+ "version": "0.1.12",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -27,10 +27,6 @@ const module$1 = defineNuxtModule({
27
27
  ]);
28
28
  }
29
29
  _nuxt.options.alias["#upload-kit"] = resolver.resolve("./runtime");
30
- const providers = ["aws-s3", "cloudflare-r2", "azure-datalake", "firebase"];
31
- for (const provider of providers) {
32
- _nuxt.options.alias[`#upload-kit/providers/${provider}`] = resolver.resolve(`./providers/${provider}`);
33
- }
34
30
  }
35
31
  });
36
32
 
@@ -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();
@@ -460,10 +497,18 @@ This is deprecated. Use the 'storage' option instead:
460
497
  }
461
498
  return currentFile;
462
499
  }
500
+ setupInitialFiles({
501
+ initialFiles: options.initialFiles,
502
+ files,
503
+ isReady,
504
+ emitter,
505
+ initializeExistingFiles
506
+ });
463
507
  return {
464
508
  // State
465
509
  files: readonly(files),
466
510
  totalProgress,
511
+ isReady: readonly(isReady),
467
512
  // Core Methods
468
513
  addFiles,
469
514
  addFile,
@@ -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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-upload-kit",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
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": {