nuxt-upload-kit 0.1.25 → 0.1.26

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.25",
4
+ "version": "0.1.26",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -223,6 +223,7 @@ export declare const useUploadKit: <TUploadResult = any>(_options?: UploadOption
223
223
  replaceFileData: (fileId: string, newData: Blob, newName?: string, shouldAutoUpload?: boolean) => Promise<UploadFile<any>>;
224
224
  updateFile: (fileId: string, updatedFile: Partial<UploadFile<TUploadResult>>) => void;
225
225
  initializeExistingFiles: (initialFiles: InitialFileInput[]) => Promise<void>;
226
+ appendExistingFiles: (initialFiles: InitialFileInput[]) => Promise<UploadFile<TUploadResult>[]>;
226
227
  addPlugin: (plugin: UploaderPlugin<any, any>) => void;
227
228
  on: {
228
229
  <K extends keyof UploaderEvents<TUploadResult>>(type: K, handler: (event: UploaderEvents<TUploadResult>[K]) => void): void;
@@ -92,15 +92,15 @@ export const useUploadKit = (_options = {}) => {
92
92
  const updateFile = (fileId, updatedFile) => {
93
93
  files.value = files.value.map((file) => file.id === fileId ? { ...file, ...updatedFile } : file);
94
94
  };
95
- const initializeExistingFiles = async (initialFiles) => {
96
- const initializedfiles = await Promise.all(
95
+ const resolveRemoteFiles = async (initialFiles) => {
96
+ const storagePlugin = getStoragePlugin();
97
+ if (!storagePlugin?.hooks.getRemoteFile) {
98
+ throw new Error("Storage plugin with getRemoteFile hook is required to resolve remote files");
99
+ }
100
+ const resolved = await Promise.all(
97
101
  initialFiles.map(async (file) => {
98
102
  const storageKey = file.storageKey;
99
103
  if (!storageKey) return null;
100
- const storagePlugin = getStoragePlugin();
101
- if (!storagePlugin?.hooks.getRemoteFile) {
102
- throw new Error("Storage plugin with getRemoteFile hook is required to initialize existing files");
103
- }
104
104
  const context = createPluginContext(storagePlugin.id, files.value, options, emitter, storagePlugin);
105
105
  const remoteFileData = await storagePlugin.hooks.getRemoteFile(storageKey, context);
106
106
  const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
@@ -124,8 +124,27 @@ export const useUploadKit = (_options = {}) => {
124
124
  return existingFile;
125
125
  })
126
126
  );
127
- const filteredFiles = initializedfiles.filter((f) => f !== null);
128
- files.value = [...filteredFiles];
127
+ return resolved.filter((f) => f !== null);
128
+ };
129
+ const initializeExistingFiles = async (initialFiles) => {
130
+ const resolvedFiles = await resolveRemoteFiles(initialFiles);
131
+ files.value = [...resolvedFiles];
132
+ };
133
+ const appendExistingFiles = async (initialFiles) => {
134
+ const existingKeys = new Set(files.value.map((f) => f.storageKey).filter(Boolean));
135
+ let filesToAdd = initialFiles.filter((f) => f.storageKey && !existingKeys.has(f.storageKey));
136
+ if (filesToAdd.length === 0) return [];
137
+ if (options.maxFiles !== false && options.maxFiles !== void 0) {
138
+ const available = options.maxFiles - files.value.length;
139
+ if (available <= 0) return [];
140
+ filesToAdd = filesToAdd.slice(0, available);
141
+ }
142
+ const resolvedFiles = await resolveRemoteFiles(filesToAdd);
143
+ files.value.push(...resolvedFiles);
144
+ resolvedFiles.forEach((file) => {
145
+ emitter.emit("file:added", file);
146
+ });
147
+ return resolvedFiles;
129
148
  };
130
149
  const addFile = async (file) => {
131
150
  const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
@@ -266,6 +285,7 @@ export const useUploadKit = (_options = {}) => {
266
285
  replaceFileData: fileOps.replaceFileData,
267
286
  updateFile,
268
287
  initializeExistingFiles,
288
+ appendExistingFiles,
269
289
  // Utilities
270
290
  addPlugin,
271
291
  // Events
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-upload-kit",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
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",