nsw-design-system 3.18.9 → 3.18.11
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,9 +1796,9 @@
|
|
|
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
|
-
if (this.input.value === '') return;
|
|
1802
1802
|
this.updateFileList();
|
|
1803
1803
|
}
|
|
1804
1804
|
createFileList() {
|
|
@@ -1818,40 +1818,65 @@
|
|
|
1818
1818
|
</button>`;
|
|
1819
1819
|
li.insertAdjacentHTML('afterbegin', html);
|
|
1820
1820
|
li.querySelector('.nsw-file-upload__item-filename').textContent = this.constructor.truncateString(file.name, 50);
|
|
1821
|
+
li.querySelector('.nsw-file-upload__item-filename').dataset.filename = file.name;
|
|
1821
1822
|
return li.outerHTML;
|
|
1822
1823
|
}
|
|
1823
1824
|
updateFileList() {
|
|
1825
|
+
if (this.input.files.length === 0) {
|
|
1826
|
+
// If there are previously stored files, re-sync the input and exit.
|
|
1827
|
+
if (this.currentFiles && this.currentFiles.files && this.currentFiles.files.length > 0) {
|
|
1828
|
+
this.input.files = this.currentFiles.files;
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
// Clear list if otherwise
|
|
1832
|
+
if (this.filesList) {
|
|
1833
|
+
this.filesList.innerHTML = '';
|
|
1834
|
+
this.filesList.classList.remove('active');
|
|
1835
|
+
}
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1824
1838
|
if (!this.filesList) {
|
|
1825
1839
|
this.createFileList();
|
|
1826
1840
|
}
|
|
1827
1841
|
this.filesList.classList.add('active');
|
|
1828
1842
|
const dataTransfer = new DataTransfer();
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1843
|
+
const existingFiles = new Set();
|
|
1844
|
+
if (this.replaceFiles) {
|
|
1845
|
+
this.filesList.innerHTML = '';
|
|
1846
|
+
this.currentFiles = new DataTransfer();
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
// Collect existing files to maintain them in the list (if multiple is allowed)
|
|
1850
|
+
if (this.multipleUpload && this.currentFiles && this.currentFiles.files) {
|
|
1851
|
+
for (let i = 0; i < this.currentFiles.files.length; i += 1) {
|
|
1852
|
+
const file = this.currentFiles.files[i];
|
|
1853
|
+
dataTransfer.items.add(file);
|
|
1854
|
+
existingFiles.add(file.name);
|
|
1855
|
+
}
|
|
1832
1856
|
}
|
|
1833
|
-
this.currentFiles = dataTransfer;
|
|
1834
1857
|
let fileListHTML = '';
|
|
1858
|
+
|
|
1859
|
+
// Add only new files
|
|
1835
1860
|
for (let i = 0; i < this.input.files.length; i += 1) {
|
|
1836
1861
|
const file = this.input.files[i];
|
|
1837
|
-
|
|
1862
|
+
if (!existingFiles.has(file.name)) {
|
|
1863
|
+
dataTransfer.items.add(file);
|
|
1864
|
+
fileListHTML += this.createFileItem(file);
|
|
1865
|
+
}
|
|
1838
1866
|
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
} else {
|
|
1867
|
+
this.currentFiles = dataTransfer;
|
|
1868
|
+
if (fileListHTML) {
|
|
1842
1869
|
this.filesList.insertAdjacentHTML('beforeend', fileListHTML);
|
|
1843
1870
|
}
|
|
1844
1871
|
this.input.files = this.currentFiles.files;
|
|
1845
|
-
this.removeFile();
|
|
1846
|
-
}
|
|
1847
|
-
removeFile() {
|
|
1848
|
-
this.filesList.addEventListener('click', this.handleFileRemove.bind(this));
|
|
1849
1872
|
}
|
|
1850
1873
|
handleFileRemove(event) {
|
|
1851
1874
|
if (!event.target.closest('.nsw-icon-button')) return;
|
|
1852
1875
|
event.preventDefault();
|
|
1853
1876
|
const item = event.target.closest('.nsw-file-upload__item');
|
|
1854
|
-
const
|
|
1877
|
+
const {
|
|
1878
|
+
filename
|
|
1879
|
+
} = item.querySelector('.nsw-file-upload__item-filename').dataset;
|
|
1855
1880
|
const dataTransfer = new DataTransfer();
|
|
1856
1881
|
for (let i = 0; i < this.currentFiles.files.length; i += 1) {
|
|
1857
1882
|
const file = this.currentFiles.files[i];
|
package/package.json
CHANGED
|
@@ -22,10 +22,10 @@ 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() {
|
|
28
|
-
if (this.input.value === '') return
|
|
29
29
|
this.updateFileList()
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -49,10 +49,25 @@ class FileUpload {
|
|
|
49
49
|
|
|
50
50
|
li.insertAdjacentHTML('afterbegin', html)
|
|
51
51
|
li.querySelector('.nsw-file-upload__item-filename').textContent = this.constructor.truncateString(file.name, 50)
|
|
52
|
+
li.querySelector('.nsw-file-upload__item-filename').dataset.filename = file.name
|
|
52
53
|
return li.outerHTML
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
updateFileList() {
|
|
57
|
+
if (this.input.files.length === 0) {
|
|
58
|
+
// If there are previously stored files, re-sync the input and exit.
|
|
59
|
+
if (this.currentFiles && this.currentFiles.files && this.currentFiles.files.length > 0) {
|
|
60
|
+
this.input.files = this.currentFiles.files
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
// Clear list if otherwise
|
|
64
|
+
if (this.filesList) {
|
|
65
|
+
this.filesList.innerHTML = ''
|
|
66
|
+
this.filesList.classList.remove('active')
|
|
67
|
+
}
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
56
71
|
if (!this.filesList) {
|
|
57
72
|
this.createFileList()
|
|
58
73
|
}
|
|
@@ -60,39 +75,47 @@ class FileUpload {
|
|
|
60
75
|
this.filesList.classList.add('active')
|
|
61
76
|
|
|
62
77
|
const dataTransfer = new DataTransfer()
|
|
78
|
+
const existingFiles = new Set()
|
|
63
79
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
if (this.replaceFiles) {
|
|
81
|
+
this.filesList.innerHTML = ''
|
|
82
|
+
this.currentFiles = new DataTransfer()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Collect existing files to maintain them in the list (if multiple is allowed)
|
|
86
|
+
if (this.multipleUpload && this.currentFiles && this.currentFiles.files) {
|
|
87
|
+
for (let i = 0; i < this.currentFiles.files.length; i += 1) {
|
|
88
|
+
const file = this.currentFiles.files[i]
|
|
89
|
+
dataTransfer.items.add(file)
|
|
90
|
+
existingFiles.add(file.name)
|
|
91
|
+
}
|
|
67
92
|
}
|
|
68
93
|
|
|
69
|
-
this.currentFiles = dataTransfer
|
|
70
94
|
let fileListHTML = ''
|
|
71
95
|
|
|
96
|
+
// Add only new files
|
|
72
97
|
for (let i = 0; i < this.input.files.length; i += 1) {
|
|
73
98
|
const file = this.input.files[i]
|
|
74
|
-
|
|
99
|
+
if (!existingFiles.has(file.name)) {
|
|
100
|
+
dataTransfer.items.add(file)
|
|
101
|
+
fileListHTML += this.createFileItem(file)
|
|
102
|
+
}
|
|
75
103
|
}
|
|
76
104
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
105
|
+
this.currentFiles = dataTransfer
|
|
106
|
+
|
|
107
|
+
if (fileListHTML) {
|
|
80
108
|
this.filesList.insertAdjacentHTML('beforeend', fileListHTML)
|
|
81
109
|
}
|
|
82
110
|
|
|
83
111
|
this.input.files = this.currentFiles.files
|
|
84
|
-
this.removeFile()
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
removeFile() {
|
|
88
|
-
this.filesList.addEventListener('click', this.handleFileRemove.bind(this))
|
|
89
112
|
}
|
|
90
113
|
|
|
91
114
|
handleFileRemove(event) {
|
|
92
115
|
if (!event.target.closest('.nsw-icon-button')) return
|
|
93
116
|
event.preventDefault()
|
|
94
117
|
const item = event.target.closest('.nsw-file-upload__item')
|
|
95
|
-
const filename = item.querySelector('.nsw-file-upload__item-filename').
|
|
118
|
+
const { filename } = item.querySelector('.nsw-file-upload__item-filename').dataset
|
|
96
119
|
|
|
97
120
|
const dataTransfer = new DataTransfer()
|
|
98
121
|
for (let i = 0; i < this.currentFiles.files.length; i += 1) {
|