nsw-design-system 3.18.8 → 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
|
@@ -368,14 +368,13 @@
|
|
|
368
368
|
if (this.allBreadcrumbs.children.length > 3) {
|
|
369
369
|
this.createToggle();
|
|
370
370
|
}
|
|
371
|
-
this.element.addEventListener('click', event => {
|
|
372
|
-
event.preventDefault();
|
|
373
|
-
this.allBreadcrumbs.classList.toggle('nsw-breadcrumbs__show-all');
|
|
374
|
-
});
|
|
375
371
|
}
|
|
376
372
|
createToggle() {
|
|
377
373
|
const toggle = this.constructor.createElement('li', ['nsw-breadcrumbs__show-more-toggle']);
|
|
378
374
|
toggle.innerHTML = '<button aria-label="Show more breadcrumbs" class="nsw-breadcrumbs__toggle-button" type="button">…</button>';
|
|
375
|
+
toggle.addEventListener('click', () => {
|
|
376
|
+
this.allBreadcrumbs.classList.toggle('nsw-breadcrumbs__show-all');
|
|
377
|
+
});
|
|
379
378
|
this.allBreadcrumbs.insertBefore(toggle, this.secondBreadcrumb);
|
|
380
379
|
}
|
|
381
380
|
static createElement(tag) {
|
|
@@ -1797,6 +1796,7 @@
|
|
|
1797
1796
|
this.label = this.element.querySelector('label.nsw-file-upload__label');
|
|
1798
1797
|
}
|
|
1799
1798
|
this.input.addEventListener('change', this.handleInputChange.bind(this));
|
|
1799
|
+
this.element.addEventListener('click', this.handleFileRemove.bind(this));
|
|
1800
1800
|
}
|
|
1801
1801
|
handleInputChange() {
|
|
1802
1802
|
if (this.input.value === '') return;
|
|
@@ -1819,6 +1819,7 @@
|
|
|
1819
1819
|
</button>`;
|
|
1820
1820
|
li.insertAdjacentHTML('afterbegin', html);
|
|
1821
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;
|
|
1822
1823
|
return li.outerHTML;
|
|
1823
1824
|
}
|
|
1824
1825
|
updateFileList() {
|
|
@@ -1827,32 +1828,43 @@
|
|
|
1827
1828
|
}
|
|
1828
1829
|
this.filesList.classList.add('active');
|
|
1829
1830
|
const dataTransfer = new DataTransfer();
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
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
|
+
}
|
|
1833
1844
|
}
|
|
1834
|
-
this.currentFiles = dataTransfer;
|
|
1835
1845
|
let fileListHTML = '';
|
|
1846
|
+
|
|
1847
|
+
// Add only new files
|
|
1836
1848
|
for (let i = 0; i < this.input.files.length; i += 1) {
|
|
1837
1849
|
const file = this.input.files[i];
|
|
1838
|
-
|
|
1850
|
+
if (!existingFiles.has(file.name)) {
|
|
1851
|
+
dataTransfer.items.add(file);
|
|
1852
|
+
fileListHTML += this.createFileItem(file);
|
|
1853
|
+
}
|
|
1839
1854
|
}
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
} else {
|
|
1855
|
+
this.currentFiles = dataTransfer;
|
|
1856
|
+
if (fileListHTML) {
|
|
1843
1857
|
this.filesList.insertAdjacentHTML('beforeend', fileListHTML);
|
|
1844
1858
|
}
|
|
1845
1859
|
this.input.files = this.currentFiles.files;
|
|
1846
|
-
this.removeFile();
|
|
1847
|
-
}
|
|
1848
|
-
removeFile() {
|
|
1849
|
-
this.filesList.addEventListener('click', this.handleFileRemove.bind(this));
|
|
1850
1860
|
}
|
|
1851
1861
|
handleFileRemove(event) {
|
|
1852
1862
|
if (!event.target.closest('.nsw-icon-button')) return;
|
|
1853
1863
|
event.preventDefault();
|
|
1854
1864
|
const item = event.target.closest('.nsw-file-upload__item');
|
|
1855
|
-
const
|
|
1865
|
+
const {
|
|
1866
|
+
filename
|
|
1867
|
+
} = item.querySelector('.nsw-file-upload__item-filename').dataset;
|
|
1856
1868
|
const dataTransfer = new DataTransfer();
|
|
1857
1869
|
for (let i = 0; i < this.currentFiles.files.length; i += 1) {
|
|
1858
1870
|
const file = this.currentFiles.files[i];
|
package/package.json
CHANGED
|
@@ -10,16 +10,14 @@ class Breadcrumbs {
|
|
|
10
10
|
if (this.allBreadcrumbs.children.length > 3) {
|
|
11
11
|
this.createToggle()
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
this.element.addEventListener('click', (event) => {
|
|
15
|
-
event.preventDefault()
|
|
16
|
-
this.allBreadcrumbs.classList.toggle('nsw-breadcrumbs__show-all')
|
|
17
|
-
})
|
|
18
13
|
}
|
|
19
14
|
|
|
20
15
|
createToggle() {
|
|
21
16
|
const toggle = this.constructor.createElement('li', ['nsw-breadcrumbs__show-more-toggle'])
|
|
22
17
|
toggle.innerHTML = '<button aria-label="Show more breadcrumbs" class="nsw-breadcrumbs__toggle-button" type="button">…</button>'
|
|
18
|
+
toggle.addEventListener('click', () => {
|
|
19
|
+
this.allBreadcrumbs.classList.toggle('nsw-breadcrumbs__show-all')
|
|
20
|
+
})
|
|
23
21
|
|
|
24
22
|
this.allBreadcrumbs.insertBefore(toggle, this.secondBreadcrumb)
|
|
25
23
|
}
|
|
@@ -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) {
|