@energysage/es-ds-components 3.1.6 → 3.1.7

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.
@@ -48,6 +48,15 @@ const props = defineProps({
48
48
  default: false,
49
49
  required: false,
50
50
  },
51
+ /**
52
+ * When true, allows multiple file selection. When false, restricts to single file selection.
53
+ * Defaults to true to maintain backward compatibility.
54
+ */
55
+ multiple: {
56
+ type: Boolean,
57
+ default: true,
58
+ required: false,
59
+ },
51
60
  });
52
61
 
53
62
  let currentFiles: Array<File> = [];
@@ -204,6 +213,13 @@ async function verifyFiles(files: Array<File>) {
204
213
  // @ts-expect-error basically we're filtering out the non-Files here
205
214
  newValidFiles = newValidFiles.filter((file) => file && file.status === 'fulfilled').map((file) => file.value);
206
215
 
216
+ // If multiple is false, only keep the first file
217
+ if (!props.multiple && newValidFiles.length > 0) {
218
+ newValidFiles = [newValidFiles[0]];
219
+ // Clear existing files when single mode is enabled
220
+ currentFiles = [];
221
+ }
222
+
207
223
  // If the new file with name already exists in the current files
208
224
  // Don't upload the new file and display an error
209
225
  const duplicateFiles = newValidFiles.filter(({ name }) => currentFiles.some((file) => file.name === name));
@@ -211,7 +227,13 @@ async function verifyFiles(files: Array<File>) {
211
227
 
212
228
  // For new files with unused names, add them to files
213
229
  newValidFiles = newValidFiles.filter(({ name }) => !currentFiles.some((file) => file.name === name));
214
- currentFiles = [...currentFiles, ...newValidFiles];
230
+
231
+ // In single file mode, replace existing files instead of adding to them
232
+ if (!props.multiple && newValidFiles.length > 0) {
233
+ currentFiles = newValidFiles;
234
+ } else {
235
+ currentFiles = [...currentFiles, ...newValidFiles];
236
+ }
215
237
 
216
238
  if (newValidFiles.length > 0) {
217
239
  emit('readyToUpload', newValidFiles);
@@ -328,7 +350,7 @@ const openFilePicker = () => {
328
350
  type="file"
329
351
  :accept="fileTypes.join(', ')"
330
352
  style="display: none"
331
- multiple
353
+ :multiple="multiple"
332
354
  @change="onFileChanged($event)" />
333
355
  </div>
334
356
  </template>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@energysage/es-ds-components",
3
- "version": "3.1.6",
3
+ "version": "3.1.7",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "An EnergySage Vue component library",