@usssa/component-library 1.0.0-alpha.182 → 1.0.0-alpha.183
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/package.json
CHANGED
|
@@ -7,7 +7,14 @@ import UBtnStd from './UBtnStd.vue'
|
|
|
7
7
|
import UInputTextStd from './UInputTextStd.vue'
|
|
8
8
|
import UTooltip from './UTooltip.vue'
|
|
9
9
|
|
|
10
|
-
const emit = defineEmits([
|
|
10
|
+
const emit = defineEmits([
|
|
11
|
+
'onUploadFactory',
|
|
12
|
+
'onViewFile',
|
|
13
|
+
'getFilesOnAdded',
|
|
14
|
+
'update:uploadedFiles',
|
|
15
|
+
'updateFileName',
|
|
16
|
+
'removeFile',
|
|
17
|
+
])
|
|
11
18
|
|
|
12
19
|
const props = defineProps({
|
|
13
20
|
autoUpload: {
|
|
@@ -18,6 +25,10 @@ const props = defineProps({
|
|
|
18
25
|
type: Boolean,
|
|
19
26
|
default: false,
|
|
20
27
|
},
|
|
28
|
+
cancelBtnLabel: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: 'Cancel',
|
|
31
|
+
},
|
|
21
32
|
dataTestId: {
|
|
22
33
|
type: String,
|
|
23
34
|
default: 'uploader',
|
|
@@ -77,6 +88,18 @@ const props = defineProps({
|
|
|
77
88
|
type: String,
|
|
78
89
|
default: 'sm',
|
|
79
90
|
},
|
|
91
|
+
updateFileNameLabel: {
|
|
92
|
+
type: String,
|
|
93
|
+
default: 'Update file name',
|
|
94
|
+
},
|
|
95
|
+
uploadedFiles: {
|
|
96
|
+
type: Array,
|
|
97
|
+
default: () => [],
|
|
98
|
+
},
|
|
99
|
+
viewBtnLabel: {
|
|
100
|
+
type: String,
|
|
101
|
+
default: 'View',
|
|
102
|
+
},
|
|
80
103
|
viewIconLabel: {
|
|
81
104
|
type: String,
|
|
82
105
|
default: 'view File Name',
|
|
@@ -87,9 +110,11 @@ const $q = useQuasar()
|
|
|
87
110
|
|
|
88
111
|
const fileDisplayName = ref([])
|
|
89
112
|
const isEditing = ref([])
|
|
90
|
-
const isFileUploaded= ref(false)
|
|
91
|
-
const isSmallWidthDevices = computed(() => $q.screen.width < 350)
|
|
92
113
|
const uploaderRef = ref(null)
|
|
114
|
+
const isSmallWidthDevices = computed(() => $q.screen.width < 350)
|
|
115
|
+
const uploadedFiles = computed(() =>
|
|
116
|
+
Array.isArray(props.uploadedFiles) ? props.uploadedFiles : []
|
|
117
|
+
)
|
|
93
118
|
|
|
94
119
|
const cancelEdit = (payload) => {
|
|
95
120
|
const { index, file } = payload
|
|
@@ -105,7 +130,7 @@ const handleViewClick = (file) => {
|
|
|
105
130
|
return emit('onViewFile', file)
|
|
106
131
|
}
|
|
107
132
|
|
|
108
|
-
const
|
|
133
|
+
const onFileAdded = (files) => {
|
|
109
134
|
files.forEach((file, index) => {
|
|
110
135
|
files[index]['displayName'] = files[index]['name']
|
|
111
136
|
fileDisplayName.value[file['__key']] = files[index]['displayName']
|
|
@@ -114,23 +139,60 @@ const OnFileAdded = (files) => {
|
|
|
114
139
|
return emit('getFilesOnAdded', uploaderRef.value.files)
|
|
115
140
|
}
|
|
116
141
|
|
|
117
|
-
const
|
|
142
|
+
const onFileUploaded = ({ files, xhr }) => {
|
|
118
143
|
files.forEach((file, index) => {
|
|
119
144
|
files[index]['uploaded_date'] = new Date()
|
|
120
145
|
})
|
|
121
|
-
isFileUploaded.value = true
|
|
122
146
|
}
|
|
123
147
|
|
|
124
148
|
const removeFile = (payload) => {
|
|
125
149
|
const { scope, file } = payload
|
|
126
|
-
|
|
127
|
-
scope.
|
|
128
|
-
|
|
150
|
+
|
|
151
|
+
const indexInScope = scope.files.findIndex((f) => f.__key === file.__key)
|
|
152
|
+
if (indexInScope !== -1) {
|
|
153
|
+
scope.removeFile(file)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const uploadedIndex = uploadedFiles.value.findIndex(
|
|
157
|
+
(f) => f.__key === file.__key
|
|
158
|
+
)
|
|
159
|
+
if (uploadedIndex !== -1) {
|
|
160
|
+
const updated = [...uploadedFiles.value]
|
|
161
|
+
updated.splice(uploadedIndex, 1)
|
|
162
|
+
|
|
163
|
+
emit('update:uploadedFiles', updated)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
emit('removeFile', file)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const scopedFiles = (files) => {
|
|
170
|
+
const combined = [...files]
|
|
171
|
+
|
|
172
|
+
uploadedFiles.value.forEach((uploadedFile) => {
|
|
173
|
+
const exists = combined.some((f) => f.__key === uploadedFile.__key)
|
|
174
|
+
if (!exists) {
|
|
175
|
+
combined.push({
|
|
176
|
+
...uploadedFile,
|
|
177
|
+
type: uploadedFile.type,
|
|
178
|
+
__status: 'uploaded',
|
|
179
|
+
uploaded: true,
|
|
180
|
+
__key: uploadedFile.__key || uploadedFile.name,
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
return combined
|
|
129
186
|
}
|
|
130
187
|
|
|
131
188
|
const updateFileName = (payload) => {
|
|
132
189
|
const { index, scope, file } = payload
|
|
133
|
-
scope.files
|
|
190
|
+
if (scope.files.length) {
|
|
191
|
+
scope.files[index].displayName = fileDisplayName.value[file['__key']]
|
|
192
|
+
} else {
|
|
193
|
+
file.displayName = fileDisplayName.value[file['__key']]
|
|
194
|
+
}
|
|
195
|
+
emit('updateFileName', fileDisplayName.value[file['__key']])
|
|
134
196
|
isEditing.value[index] = false
|
|
135
197
|
}
|
|
136
198
|
|
|
@@ -153,11 +215,15 @@ defineExpose({ upload })
|
|
|
153
215
|
:no-thumbnails="noThumbnails"
|
|
154
216
|
ref="uploaderRef"
|
|
155
217
|
:url="fileUploadUrl"
|
|
156
|
-
@added="
|
|
157
|
-
|
|
218
|
+
@added="onFileAdded"
|
|
219
|
+
:uploadedFiles="uploadedFiles"
|
|
220
|
+
@uploaded="onFileUploaded"
|
|
158
221
|
>
|
|
159
222
|
<template v-slot:header="scope">
|
|
160
|
-
<div
|
|
223
|
+
<div
|
|
224
|
+
v-if="scope.canAddFiles && !uploadedFiles.length"
|
|
225
|
+
class="q-py-md q-px-xl bg-neutral-2 uploader-content"
|
|
226
|
+
>
|
|
161
227
|
<div class="text-center">
|
|
162
228
|
<img
|
|
163
229
|
alt="Upload Files"
|
|
@@ -169,7 +235,7 @@ defineExpose({ upload })
|
|
|
169
235
|
</div>
|
|
170
236
|
<div class="list-items row">
|
|
171
237
|
<UBtnStd
|
|
172
|
-
class="q-mt-md"
|
|
238
|
+
class="q-mt-md selectFileBtn"
|
|
173
239
|
:aria-label="selectFileBtnLabel"
|
|
174
240
|
color="primary"
|
|
175
241
|
dataTestId="select-file-btn"
|
|
@@ -207,7 +273,7 @@ defineExpose({ upload })
|
|
|
207
273
|
dataTestId="file-list"
|
|
208
274
|
>
|
|
209
275
|
<q-card
|
|
210
|
-
v-for="(file, index) in scope.files"
|
|
276
|
+
v-for="(file, index) in scopedFiles(scope.files)"
|
|
211
277
|
:class="`uploader-list ${
|
|
212
278
|
file.__status == 'uploading'
|
|
213
279
|
? 'q-py-xs q-px-sm'
|
|
@@ -235,7 +301,7 @@ defineExpose({ upload })
|
|
|
235
301
|
tabindex="0"
|
|
236
302
|
/>
|
|
237
303
|
<q-icon
|
|
238
|
-
v-if="file.__img"
|
|
304
|
+
v-if="file.__img || getFileCategory(file.type)"
|
|
239
305
|
class="fa-duotone fa-solid fa-file-image"
|
|
240
306
|
:color="fileIconColor"
|
|
241
307
|
size="md"
|
|
@@ -329,6 +395,7 @@ defineExpose({ upload })
|
|
|
329
395
|
<!--End--- When File Uploading on server --End -->
|
|
330
396
|
|
|
331
397
|
<!-- When File Uploaded on server -->
|
|
398
|
+
|
|
332
399
|
<q-card-section
|
|
333
400
|
v-if="file.__status == 'uploaded'"
|
|
334
401
|
class="card-section"
|
|
@@ -339,27 +406,27 @@ defineExpose({ upload })
|
|
|
339
406
|
:class="`fa-duotone fa-solid fa-file-${getFileCategory(
|
|
340
407
|
file.type
|
|
341
408
|
)}`"
|
|
409
|
+
:aria-label="file.displayName"
|
|
342
410
|
:color="fileIconColor"
|
|
343
411
|
size="md"
|
|
344
|
-
tabindex="0"
|
|
345
412
|
/>
|
|
346
413
|
<q-icon
|
|
347
414
|
v-if="getFileCategory(file.type) == 'Unknown'"
|
|
348
415
|
class="fa-duotone fa-solid fa-file-doc"
|
|
416
|
+
:aria-label="file.displayName"
|
|
349
417
|
:color="fileIconColor"
|
|
350
418
|
size="md"
|
|
351
|
-
tabindex="0"
|
|
352
419
|
/>
|
|
353
420
|
<q-icon
|
|
354
421
|
v-if="file.__img"
|
|
355
422
|
class="fa-duotone fa-solid fa-file-image"
|
|
423
|
+
:aria-label="file.displayName"
|
|
356
424
|
:color="fileIconColor"
|
|
357
425
|
size="md"
|
|
358
|
-
tabindex="0"
|
|
359
426
|
/>
|
|
360
427
|
|
|
361
428
|
<div class="col">
|
|
362
|
-
<span class="text-caption-md title flex">
|
|
429
|
+
<span class="text-caption-md title flex" tabindex="0">
|
|
363
430
|
<UTooltip
|
|
364
431
|
anchor="center end"
|
|
365
432
|
:description="file.displayName || file.name"
|
|
@@ -404,7 +471,7 @@ defineExpose({ upload })
|
|
|
404
471
|
v-if="size == 'md'"
|
|
405
472
|
:aria-label="viewIconLabel"
|
|
406
473
|
color="primary"
|
|
407
|
-
label="
|
|
474
|
+
:label="viewBtnLabel"
|
|
408
475
|
outline
|
|
409
476
|
size="sm"
|
|
410
477
|
@onClick="handleViewClick(file)"
|
|
@@ -413,7 +480,7 @@ defineExpose({ upload })
|
|
|
413
480
|
<div v-if="isEditing[index]" class="q-my-ba">
|
|
414
481
|
<UInputTextStd
|
|
415
482
|
v-model="fileDisplayName[file.__key]"
|
|
416
|
-
label="
|
|
483
|
+
:label="editIconLabel"
|
|
417
484
|
size="md"
|
|
418
485
|
/>
|
|
419
486
|
</div>
|
|
@@ -435,7 +502,7 @@ defineExpose({ upload })
|
|
|
435
502
|
:aria-label="viewIconLabel"
|
|
436
503
|
color="primary"
|
|
437
504
|
:full-width="true"
|
|
438
|
-
label="
|
|
505
|
+
:label="viewBtnLabel"
|
|
439
506
|
:outline="true"
|
|
440
507
|
size="md"
|
|
441
508
|
@onClick="handleViewClick(file)"
|
|
@@ -446,7 +513,7 @@ defineExpose({ upload })
|
|
|
446
513
|
color="primary"
|
|
447
514
|
flat
|
|
448
515
|
:full-width="true"
|
|
449
|
-
label="
|
|
516
|
+
:label="cancelBtnLabel"
|
|
450
517
|
size="md"
|
|
451
518
|
@click="cancelEdit({ index, file })"
|
|
452
519
|
/>
|
|
@@ -457,7 +524,7 @@ defineExpose({ upload })
|
|
|
457
524
|
}`"
|
|
458
525
|
color="primary"
|
|
459
526
|
:full-width="true"
|
|
460
|
-
label="
|
|
527
|
+
:label="updateFileNameLabel"
|
|
461
528
|
size="md"
|
|
462
529
|
@click="updateFileName({ scope, file, index })"
|
|
463
530
|
/>
|