vgapp 1.0.2 → 1.0.3
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.
|
@@ -137,12 +137,12 @@ class VGFilesBase extends BaseModule {
|
|
|
137
137
|
Boolean(this._params?.replace) &&
|
|
138
138
|
isSingle;
|
|
139
139
|
|
|
140
|
-
if (shouldReplaceOnSingle) {
|
|
141
|
-
this.clear();
|
|
142
|
-
this.append(filesArray, true);
|
|
143
|
-
this._revokeUrls();
|
|
144
|
-
this._cleanupFakeInputs();
|
|
145
|
-
this._cleanupErrors();
|
|
140
|
+
if (shouldReplaceOnSingle) {
|
|
141
|
+
this.clear(false);
|
|
142
|
+
this.append(filesArray, true);
|
|
143
|
+
this._revokeUrls();
|
|
144
|
+
this._cleanupFakeInputs();
|
|
145
|
+
this._cleanupErrors();
|
|
146
146
|
|
|
147
147
|
this._files = this._filterFiles(filesArray);
|
|
148
148
|
if (this._params.prepend) this._files.reverse();
|
|
@@ -394,11 +394,17 @@ class VGFilesBase extends BaseModule {
|
|
|
394
394
|
$list.innerHTML = '';
|
|
395
395
|
$list.appendChild(fragment);
|
|
396
396
|
|
|
397
|
-
const $message = Selectors.find(`.${this._getClass('drop-message')}`, this._nodes.drop);
|
|
398
|
-
if ($message) {
|
|
399
|
-
if (files.length) Classes.add($message, 'has-files');
|
|
400
|
-
else Classes.remove($message, 'has-files');
|
|
401
|
-
|
|
397
|
+
const $message = Selectors.find(`.${this._getClass('drop-message')}`, this._nodes.drop);
|
|
398
|
+
if ($message) {
|
|
399
|
+
if (files.length) Classes.add($message, 'has-files');
|
|
400
|
+
else Classes.remove($message, 'has-files');
|
|
401
|
+
|
|
402
|
+
const isSingle = Number(this._params?.limits?.count) === 1;
|
|
403
|
+
if (isSingle) {
|
|
404
|
+
if (files.length) Classes.remove($message, 'show');
|
|
405
|
+
else Classes.add($message, 'show');
|
|
406
|
+
}
|
|
407
|
+
}
|
|
402
408
|
|
|
403
409
|
this._nodes.drop.appendChild($list);
|
|
404
410
|
Classes.add(this._nodes.drop, 'active');
|
|
@@ -580,12 +586,14 @@ class VGFilesBase extends BaseModule {
|
|
|
580
586
|
Selectors.findAll('[data-vg-files="generated"]', this._element).forEach(el => el.remove());
|
|
581
587
|
}
|
|
582
588
|
|
|
583
|
-
clear() {
|
|
584
|
-
this._revokeUrls();
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
this.
|
|
589
|
+
clear(resetInput = true) {
|
|
590
|
+
this._revokeUrls();
|
|
591
|
+
if (resetInput) {
|
|
592
|
+
this._resetFileInput();
|
|
593
|
+
}
|
|
594
|
+
this._cleanupFakeInputs();
|
|
595
|
+
this._cleanupErrors();
|
|
596
|
+
this._files = [];
|
|
589
597
|
|
|
590
598
|
if (this._nodes.info) {
|
|
591
599
|
Classes.remove(this._nodes.info, 'show');
|
|
@@ -596,8 +604,15 @@ class VGFilesBase extends BaseModule {
|
|
|
596
604
|
const $list = Selectors.find(`.${this._getClass('drop-list')}`, this._element);
|
|
597
605
|
if ($list) $list.innerHTML = '';
|
|
598
606
|
|
|
599
|
-
const $message = Selectors.find(`.${this._getClass('drop-message')}`, this._element);
|
|
600
|
-
if ($message)
|
|
607
|
+
const $message = Selectors.find(`.${this._getClass('drop-message')}`, this._element);
|
|
608
|
+
if ($message) {
|
|
609
|
+
Classes.remove($message, 'has-files');
|
|
610
|
+
|
|
611
|
+
const isSingle = Number(this._params?.limits?.count) === 1;
|
|
612
|
+
if (isSingle) {
|
|
613
|
+
Classes.add($message, 'show');
|
|
614
|
+
}
|
|
615
|
+
}
|
|
601
616
|
|
|
602
617
|
Classes.remove(this._nodes.drop, 'active');
|
|
603
618
|
}
|
|
@@ -207,17 +207,32 @@ class VGFiles extends VGFilesBase {
|
|
|
207
207
|
});
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
_handleChange(e) {
|
|
211
|
-
const input = e?.target;
|
|
212
|
-
this.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
210
|
+
_handleChange(e) {
|
|
211
|
+
const input = e?.target;
|
|
212
|
+
const inputFiles = this._snapshotInputFiles(input);
|
|
213
|
+
this.change(input);
|
|
214
|
+
|
|
215
|
+
if (this._params.ajax) this.uploadAll(this._files);
|
|
216
|
+
|
|
217
|
+
const payload = {
|
|
218
|
+
files: this._files,
|
|
219
|
+
input: e?.target || e?.src || '',
|
|
220
|
+
inputFiles
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
this._triggerCallback('onChange', payload);
|
|
224
|
+
this._triggerEvent('change', {
|
|
225
|
+
files: this._files,
|
|
226
|
+
input: payload.input,
|
|
227
|
+
inputFiles: payload.inputFiles
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
_snapshotInputFiles(input) {
|
|
232
|
+
const files = input?.files;
|
|
233
|
+
if (!files?.length) return [];
|
|
234
|
+
return Array.from(files);
|
|
235
|
+
}
|
|
221
236
|
|
|
222
237
|
async uploadAll(files) {
|
|
223
238
|
if (!this._params.ajax || !this._params.uploads.route) return;
|
|
@@ -84,7 +84,7 @@ const files = new VGFiles(document.querySelector('.vg-files'), {
|
|
|
84
84
|
| Колбэк | Параметры | Описание |
|
|
85
85
|
|-------|----------|--------|
|
|
86
86
|
| `onInit` | `(data)` | Инициализация завершена |
|
|
87
|
-
| `onChange` | `{ files, input }` | Изменён список файлов |
|
|
87
|
+
| `onChange` | `{ files, input, inputFiles }` | Изменён список файлов (`inputFiles` — снимок исходных `input.files`) |
|
|
88
88
|
| `onUploadStart` | `{ files, total }` | Началась загрузка |
|
|
89
89
|
| `onUploadProgress` | `{ file, progress, bytesSent, totalBytes }` | Прогресс загрузки |
|
|
90
90
|
| `onUploadComplete` | `{ file, response, status, id }` | Файл успешно загружен |
|
|
@@ -190,4 +190,4 @@ MIT. Свободно использовать и модифицировать.
|
|
|
190
190
|
|
|
191
191
|
📌 *Разработано в рамках фронтенд-системы VG Modules.*
|
|
192
192
|
> 🚀 Автор: VEGAS STUDIO (vegas-dev.com)
|
|
193
|
-
> 📍 Поддерживается в проектах VEGAS
|
|
193
|
+
> 📍 Поддерживается в проектах VEGAS
|