nsw-design-system 3.18.9 → 3.18.10
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/js/main.js
CHANGED
|
@@ -1796,6 +1796,7 @@
|
|
|
1796
1796
|
this.label = this.element.querySelector('label.nsw-file-upload__label');
|
|
1797
1797
|
}
|
|
1798
1798
|
this.input.addEventListener('change', this.handleInputChange.bind(this));
|
|
1799
|
+
this.element.addEventListener('click', this.handleFileRemove.bind(this));
|
|
1799
1800
|
}
|
|
1800
1801
|
handleInputChange() {
|
|
1801
1802
|
if (this.input.value === '') return;
|
|
@@ -1818,6 +1819,7 @@
|
|
|
1818
1819
|
</button>`;
|
|
1819
1820
|
li.insertAdjacentHTML('afterbegin', html);
|
|
1820
1821
|
li.querySelector('.nsw-file-upload__item-filename').textContent = this.constructor.truncateString(file.name, 50);
|
|
1822
|
+
li.querySelector('.nsw-file-upload__item-filename').dataset.filename = file.name;
|
|
1821
1823
|
return li.outerHTML;
|
|
1822
1824
|
}
|
|
1823
1825
|
updateFileList() {
|
|
@@ -1826,32 +1828,43 @@
|
|
|
1826
1828
|
}
|
|
1827
1829
|
this.filesList.classList.add('active');
|
|
1828
1830
|
const dataTransfer = new DataTransfer();
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1831
|
+
const existingFiles = new Set();
|
|
1832
|
+
if (this.replaceFiles) {
|
|
1833
|
+
this.filesList.innerHTML = '';
|
|
1834
|
+
this.currentFiles = new DataTransfer();
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
// Collect existing files to maintain them in the list (if multiple is allowed)
|
|
1838
|
+
if (this.multipleUpload && this.currentFiles && this.currentFiles.files) {
|
|
1839
|
+
for (let i = 0; i < this.currentFiles.files.length; i += 1) {
|
|
1840
|
+
const file = this.currentFiles.files[i];
|
|
1841
|
+
dataTransfer.items.add(file);
|
|
1842
|
+
existingFiles.add(file.name);
|
|
1843
|
+
}
|
|
1832
1844
|
}
|
|
1833
|
-
this.currentFiles = dataTransfer;
|
|
1834
1845
|
let fileListHTML = '';
|
|
1846
|
+
|
|
1847
|
+
// Add only new files
|
|
1835
1848
|
for (let i = 0; i < this.input.files.length; i += 1) {
|
|
1836
1849
|
const file = this.input.files[i];
|
|
1837
|
-
|
|
1850
|
+
if (!existingFiles.has(file.name)) {
|
|
1851
|
+
dataTransfer.items.add(file);
|
|
1852
|
+
fileListHTML += this.createFileItem(file);
|
|
1853
|
+
}
|
|
1838
1854
|
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
} else {
|
|
1855
|
+
this.currentFiles = dataTransfer;
|
|
1856
|
+
if (fileListHTML) {
|
|
1842
1857
|
this.filesList.insertAdjacentHTML('beforeend', fileListHTML);
|
|
1843
1858
|
}
|
|
1844
1859
|
this.input.files = this.currentFiles.files;
|
|
1845
|
-
this.removeFile();
|
|
1846
|
-
}
|
|
1847
|
-
removeFile() {
|
|
1848
|
-
this.filesList.addEventListener('click', this.handleFileRemove.bind(this));
|
|
1849
1860
|
}
|
|
1850
1861
|
handleFileRemove(event) {
|
|
1851
1862
|
if (!event.target.closest('.nsw-icon-button')) return;
|
|
1852
1863
|
event.preventDefault();
|
|
1853
1864
|
const item = event.target.closest('.nsw-file-upload__item');
|
|
1854
|
-
const
|
|
1865
|
+
const {
|
|
1866
|
+
filename
|
|
1867
|
+
} = item.querySelector('.nsw-file-upload__item-filename').dataset;
|
|
1855
1868
|
const dataTransfer = new DataTransfer();
|
|
1856
1869
|
for (let i = 0; i < this.currentFiles.files.length; i += 1) {
|
|
1857
1870
|
const file = this.currentFiles.files[i];
|
package/package.json
CHANGED
|
@@ -22,6 +22,7 @@ class FileUpload {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
this.input.addEventListener('change', this.handleInputChange.bind(this))
|
|
25
|
+
this.element.addEventListener('click', this.handleFileRemove.bind(this))
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
handleInputChange() {
|
|
@@ -49,6 +50,7 @@ class FileUpload {
|
|
|
49
50
|
|
|
50
51
|
li.insertAdjacentHTML('afterbegin', html)
|
|
51
52
|
li.querySelector('.nsw-file-upload__item-filename').textContent = this.constructor.truncateString(file.name, 50)
|
|
53
|
+
li.querySelector('.nsw-file-upload__item-filename').dataset.filename = file.name
|
|
52
54
|
return li.outerHTML
|
|
53
55
|
}
|
|
54
56
|
|
|
@@ -60,39 +62,47 @@ class FileUpload {
|
|
|
60
62
|
this.filesList.classList.add('active')
|
|
61
63
|
|
|
62
64
|
const dataTransfer = new DataTransfer()
|
|
65
|
+
const existingFiles = new Set()
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
if (this.replaceFiles) {
|
|
68
|
+
this.filesList.innerHTML = ''
|
|
69
|
+
this.currentFiles = new DataTransfer()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Collect existing files to maintain them in the list (if multiple is allowed)
|
|
73
|
+
if (this.multipleUpload && this.currentFiles && this.currentFiles.files) {
|
|
74
|
+
for (let i = 0; i < this.currentFiles.files.length; i += 1) {
|
|
75
|
+
const file = this.currentFiles.files[i]
|
|
76
|
+
dataTransfer.items.add(file)
|
|
77
|
+
existingFiles.add(file.name)
|
|
78
|
+
}
|
|
67
79
|
}
|
|
68
80
|
|
|
69
|
-
this.currentFiles = dataTransfer
|
|
70
81
|
let fileListHTML = ''
|
|
71
82
|
|
|
83
|
+
// Add only new files
|
|
72
84
|
for (let i = 0; i < this.input.files.length; i += 1) {
|
|
73
85
|
const file = this.input.files[i]
|
|
74
|
-
|
|
86
|
+
if (!existingFiles.has(file.name)) {
|
|
87
|
+
dataTransfer.items.add(file)
|
|
88
|
+
fileListHTML += this.createFileItem(file)
|
|
89
|
+
}
|
|
75
90
|
}
|
|
76
91
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
92
|
+
this.currentFiles = dataTransfer
|
|
93
|
+
|
|
94
|
+
if (fileListHTML) {
|
|
80
95
|
this.filesList.insertAdjacentHTML('beforeend', fileListHTML)
|
|
81
96
|
}
|
|
82
97
|
|
|
83
98
|
this.input.files = this.currentFiles.files
|
|
84
|
-
this.removeFile()
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
removeFile() {
|
|
88
|
-
this.filesList.addEventListener('click', this.handleFileRemove.bind(this))
|
|
89
99
|
}
|
|
90
100
|
|
|
91
101
|
handleFileRemove(event) {
|
|
92
102
|
if (!event.target.closest('.nsw-icon-button')) return
|
|
93
103
|
event.preventDefault()
|
|
94
104
|
const item = event.target.closest('.nsw-file-upload__item')
|
|
95
|
-
const filename = item.querySelector('.nsw-file-upload__item-filename').
|
|
105
|
+
const { filename } = item.querySelector('.nsw-file-upload__item-filename').dataset
|
|
96
106
|
|
|
97
107
|
const dataTransfer = new DataTransfer()
|
|
98
108
|
for (let i = 0; i < this.currentFiles.files.length; i += 1) {
|