slim-select 2.2.3 → 2.3.1
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/README.md +2 -6
- package/dist/index.d.ts +1 -1
- package/dist/render.d.ts +4 -2
- package/dist/select.d.ts +6 -11
- package/dist/settings.d.ts +3 -1
- package/dist/slimselect.cjs.js +206 -173
- package/dist/slimselect.css +1 -1
- package/dist/slimselect.css.map +1 -1
- package/dist/slimselect.es.js +206 -173
- package/dist/slimselect.global.js +206 -173
- package/dist/slimselect.js +206 -173
- package/dist/slimselect.min.js +1 -1
- package/dist/slimselect.umd.js +206 -173
- package/dist/slimselect.umd.min.js +1 -1
- package/jest.config.js +1 -0
- package/package.json +4 -4
- package/src/slim-select/index.ts +45 -35
- package/src/slim-select/render.ts +146 -97
- package/src/slim-select/select.test.ts +143 -23
- package/src/slim-select/select.ts +110 -91
- package/src/slim-select/settings.ts +6 -2
- package/src/slim-select/slimselect.scss +33 -10
- package/src/slim-select/store.test.ts +22 -0
- package/src/vue/dist/slim-select/index.d.ts +1 -1
- package/src/vue/dist/slim-select/render.d.ts +4 -2
- package/src/vue/dist/slim-select/select.d.ts +6 -11
- package/src/vue/dist/slim-select/settings.d.ts +3 -1
- package/src/vue/dist/slimselectvue.es.js +225 -186
- package/src/vue/dist/slimselectvue.global.js +225 -186
- package/src/vue/dist/slimselectvue.ssr.js +225 -186
- package/src/vue/dist/vue/slimselect.vue.d.ts +21 -17
- package/src/vue/package.json +1 -1
- package/src/vue/slimselect.vue +27 -23
package/dist/slimselect.umd.js
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
this.id = 'ss-' + generateID();
|
|
72
72
|
this.style = settings.style || '';
|
|
73
73
|
this.class = settings.class || [];
|
|
74
|
-
this.
|
|
74
|
+
this.disabled = settings.disabled !== undefined ? settings.disabled : false;
|
|
75
75
|
this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
|
|
76
76
|
this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
|
|
77
77
|
this.searchPlaceholder = settings.searchPlaceholder || 'Search';
|
|
@@ -89,6 +89,8 @@
|
|
|
89
89
|
this.minSelected = settings.minSelected || 0;
|
|
90
90
|
this.maxSelected = settings.maxSelected || 1000;
|
|
91
91
|
this.timeoutDelay = settings.timeoutDelay || 200;
|
|
92
|
+
this.maxValuesShown = settings.maxValuesShown || 20;
|
|
93
|
+
this.maxValuesMessage = settings.maxValuesMessage || '{number} selected';
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
|
|
@@ -305,6 +307,7 @@
|
|
|
305
307
|
placeholder: 'ss-placeholder',
|
|
306
308
|
values: 'ss-values',
|
|
307
309
|
single: 'ss-single',
|
|
310
|
+
max: 'ss-max',
|
|
308
311
|
value: 'ss-value',
|
|
309
312
|
valueText: 'ss-value-text',
|
|
310
313
|
valueDelete: 'ss-value-delete',
|
|
@@ -346,6 +349,7 @@
|
|
|
346
349
|
this.callbacks = callbacks;
|
|
347
350
|
this.main = this.mainDiv();
|
|
348
351
|
this.content = this.contentDiv();
|
|
352
|
+
this.updateClassStyles();
|
|
349
353
|
this.settings.contentLocation.appendChild(this.content.main);
|
|
350
354
|
}
|
|
351
355
|
enable() {
|
|
@@ -360,24 +364,6 @@
|
|
|
360
364
|
this.main.arrow.path.setAttribute('d', this.classes.arrowOpen);
|
|
361
365
|
this.main.main.classList.add(this.settings.openPosition === 'up' ? this.classes.openAbove : this.classes.openBelow);
|
|
362
366
|
this.moveContent();
|
|
363
|
-
this.renderOptions(this.store.getData());
|
|
364
|
-
if (this.settings.contentPosition === 'relative') {
|
|
365
|
-
this.moveContentBelow();
|
|
366
|
-
}
|
|
367
|
-
else if (this.settings.openPosition.toLowerCase() === 'up') {
|
|
368
|
-
this.moveContentAbove();
|
|
369
|
-
}
|
|
370
|
-
else if (this.settings.openPosition.toLowerCase() === 'down') {
|
|
371
|
-
this.moveContentBelow();
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
if (this.putContent(this.content.main, this.settings.isOpen) === 'up') {
|
|
375
|
-
this.moveContentAbove();
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
this.moveContentBelow();
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
367
|
const selectedOptions = this.store.getSelectedOptions();
|
|
382
368
|
if (selectedOptions.length) {
|
|
383
369
|
const selectedId = selectedOptions[selectedOptions.length - 1].id;
|
|
@@ -394,20 +380,32 @@
|
|
|
394
380
|
this.content.main.classList.remove(this.classes.openBelow);
|
|
395
381
|
this.main.arrow.path.setAttribute('d', this.classes.arrowClose);
|
|
396
382
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
main.
|
|
400
|
-
|
|
401
|
-
main.
|
|
402
|
-
main.classList.add(this.
|
|
403
|
-
main.classList.add(this.classes.
|
|
404
|
-
if (this.settings.
|
|
383
|
+
updateClassStyles() {
|
|
384
|
+
this.main.main.className = '';
|
|
385
|
+
this.main.main.removeAttribute('style');
|
|
386
|
+
this.content.main.className = '';
|
|
387
|
+
this.content.main.removeAttribute('style');
|
|
388
|
+
this.main.main.classList.add(this.classes.main);
|
|
389
|
+
this.content.main.classList.add(this.classes.content);
|
|
390
|
+
if (this.settings.style !== '') {
|
|
391
|
+
this.content.main.style.cssText = this.settings.style;
|
|
392
|
+
}
|
|
393
|
+
if (this.settings.class.length) {
|
|
405
394
|
for (const c of this.settings.class) {
|
|
406
395
|
if (c.trim() !== '') {
|
|
407
|
-
main.classList.add(c.trim());
|
|
396
|
+
this.main.main.classList.add(c.trim());
|
|
397
|
+
this.content.main.classList.add(c.trim());
|
|
408
398
|
}
|
|
409
399
|
}
|
|
410
400
|
}
|
|
401
|
+
if (this.settings.contentPosition === 'relative') {
|
|
402
|
+
this.content.main.classList.add('ss-' + this.settings.contentPosition);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
mainDiv() {
|
|
406
|
+
const main = document.createElement('div');
|
|
407
|
+
main.dataset.id = this.settings.id;
|
|
408
|
+
main.tabIndex = 0;
|
|
411
409
|
main.onfocus = () => {
|
|
412
410
|
if (this.settings.triggerFocus) {
|
|
413
411
|
this.callbacks.open();
|
|
@@ -435,7 +433,7 @@
|
|
|
435
433
|
}
|
|
436
434
|
};
|
|
437
435
|
main.onclick = (e) => {
|
|
438
|
-
if (
|
|
436
|
+
if (this.settings.disabled) {
|
|
439
437
|
return;
|
|
440
438
|
}
|
|
441
439
|
this.settings.isOpen ? this.callbacks.close() : this.callbacks.open();
|
|
@@ -450,7 +448,7 @@
|
|
|
450
448
|
}
|
|
451
449
|
deselect.onclick = (e) => {
|
|
452
450
|
e.stopPropagation();
|
|
453
|
-
if (
|
|
451
|
+
if (this.settings.disabled) {
|
|
454
452
|
return;
|
|
455
453
|
}
|
|
456
454
|
let shouldDelete = true;
|
|
@@ -460,7 +458,7 @@
|
|
|
460
458
|
shouldDelete = this.callbacks.beforeChange(after, before) === true;
|
|
461
459
|
}
|
|
462
460
|
if (shouldDelete) {
|
|
463
|
-
this.callbacks.setSelected(['']);
|
|
461
|
+
this.callbacks.setSelected([''], false);
|
|
464
462
|
if (this.settings.closeOnSelect) {
|
|
465
463
|
this.callbacks.close();
|
|
466
464
|
}
|
|
@@ -566,6 +564,19 @@
|
|
|
566
564
|
placeholder.remove();
|
|
567
565
|
}
|
|
568
566
|
}
|
|
567
|
+
if (selectedOptions.length > this.settings.maxValuesShown) {
|
|
568
|
+
const singleValue = document.createElement('div');
|
|
569
|
+
singleValue.classList.add(this.classes.max);
|
|
570
|
+
singleValue.textContent = this.settings.maxValuesMessage.replace('{number}', selectedOptions.length.toString());
|
|
571
|
+
this.main.values.innerHTML = singleValue.outerHTML;
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
const maxValuesMessage = this.main.values.querySelector('.' + this.classes.max);
|
|
576
|
+
if (maxValuesMessage) {
|
|
577
|
+
maxValuesMessage.remove();
|
|
578
|
+
}
|
|
579
|
+
}
|
|
569
580
|
let removeNodes = [];
|
|
570
581
|
for (let i = 0; i < currentNodes.length; i++) {
|
|
571
582
|
const node = currentNodes[i];
|
|
@@ -620,6 +631,9 @@
|
|
|
620
631
|
deleteDiv.onclick = (e) => {
|
|
621
632
|
e.preventDefault();
|
|
622
633
|
e.stopPropagation();
|
|
634
|
+
if (this.settings.disabled) {
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
623
637
|
let shouldDelete = true;
|
|
624
638
|
const before = this.store.getSelectedOptions();
|
|
625
639
|
const after = before.filter((o) => {
|
|
@@ -643,7 +657,7 @@
|
|
|
643
657
|
selectedValues.push(o.value);
|
|
644
658
|
}
|
|
645
659
|
}
|
|
646
|
-
this.callbacks.setSelected(selectedValues);
|
|
660
|
+
this.callbacks.setSelected(selectedValues, false);
|
|
647
661
|
if (this.settings.closeOnSelect) {
|
|
648
662
|
this.callbacks.close();
|
|
649
663
|
}
|
|
@@ -664,21 +678,7 @@
|
|
|
664
678
|
}
|
|
665
679
|
contentDiv() {
|
|
666
680
|
const main = document.createElement('div');
|
|
667
|
-
main.classList.add(this.classes.content);
|
|
668
681
|
main.dataset.id = this.settings.id;
|
|
669
|
-
if (this.settings.style !== '') {
|
|
670
|
-
main.style.cssText = this.settings.style;
|
|
671
|
-
}
|
|
672
|
-
if (this.settings.contentPosition === 'relative') {
|
|
673
|
-
main.classList.add('ss-' + this.settings.contentPosition);
|
|
674
|
-
}
|
|
675
|
-
if (this.settings.class.length) {
|
|
676
|
-
for (const c of this.settings.class) {
|
|
677
|
-
if (c.trim() !== '') {
|
|
678
|
-
main.classList.add(c.trim());
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
682
|
const search = this.searchDiv();
|
|
683
683
|
main.appendChild(search.main);
|
|
684
684
|
const list = this.listDiv();
|
|
@@ -691,12 +691,23 @@
|
|
|
691
691
|
}
|
|
692
692
|
moveContent() {
|
|
693
693
|
if (this.settings.contentPosition === 'relative') {
|
|
694
|
+
this.moveContentBelow();
|
|
694
695
|
return;
|
|
695
696
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
697
|
+
if (this.settings.openPosition === 'down') {
|
|
698
|
+
this.moveContentBelow();
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
else if (this.settings.openPosition === 'up') {
|
|
702
|
+
this.moveContentAbove();
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
if (this.putContent() === 'up') {
|
|
706
|
+
this.moveContentAbove();
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
this.moveContentBelow();
|
|
710
|
+
}
|
|
700
711
|
}
|
|
701
712
|
searchDiv() {
|
|
702
713
|
const main = document.createElement('div');
|
|
@@ -779,10 +790,10 @@
|
|
|
779
790
|
if (this.settings.isMultiple) {
|
|
780
791
|
let values = this.store.getSelected();
|
|
781
792
|
values.push(newOption.value);
|
|
782
|
-
this.callbacks.setSelected(values);
|
|
793
|
+
this.callbacks.setSelected(values, true);
|
|
783
794
|
}
|
|
784
795
|
else {
|
|
785
|
-
this.callbacks.setSelected([newOption.value]);
|
|
796
|
+
this.callbacks.setSelected([newOption.value], true);
|
|
786
797
|
}
|
|
787
798
|
this.callbacks.search('');
|
|
788
799
|
if (this.settings.closeOnSelect) {
|
|
@@ -907,8 +918,7 @@
|
|
|
907
918
|
this.content.list.innerHTML = '';
|
|
908
919
|
if (data.length === 0) {
|
|
909
920
|
const noResults = document.createElement('div');
|
|
910
|
-
noResults.classList.add(this.classes.
|
|
911
|
-
noResults.classList.add(this.classes.disabled);
|
|
921
|
+
noResults.classList.add(this.classes.search);
|
|
912
922
|
noResults.innerHTML = this.settings.searchText;
|
|
913
923
|
this.content.list.appendChild(noResults);
|
|
914
924
|
return;
|
|
@@ -965,12 +975,12 @@
|
|
|
965
975
|
}
|
|
966
976
|
return true;
|
|
967
977
|
});
|
|
968
|
-
this.callbacks.setSelected(newSelected);
|
|
978
|
+
this.callbacks.setSelected(newSelected, true);
|
|
969
979
|
return;
|
|
970
980
|
}
|
|
971
981
|
else {
|
|
972
982
|
const newSelected = currentSelected.concat(d.options.map((o) => o.value));
|
|
973
|
-
this.callbacks.setSelected(newSelected);
|
|
983
|
+
this.callbacks.setSelected(newSelected, true);
|
|
974
984
|
}
|
|
975
985
|
});
|
|
976
986
|
optgroupActions.appendChild(selectAll);
|
|
@@ -984,7 +994,7 @@
|
|
|
984
994
|
optgroupClosable.appendChild(optgroupClosableSvg);
|
|
985
995
|
const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
986
996
|
optgroupClosableSvg.appendChild(optgroupClosableArrow);
|
|
987
|
-
if (d.options.some((o) => o.selected)) {
|
|
997
|
+
if (d.options.some((o) => o.selected) || this.content.search.input.value.trim() !== '') {
|
|
988
998
|
optgroupClosable.classList.add(this.classes.open);
|
|
989
999
|
optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
|
|
990
1000
|
}
|
|
@@ -1043,8 +1053,7 @@
|
|
|
1043
1053
|
optionEl.style.cssText = option.style;
|
|
1044
1054
|
}
|
|
1045
1055
|
if (this.settings.searchHighlight && this.content.search.input.value.trim() !== '') {
|
|
1046
|
-
|
|
1047
|
-
optionEl.innerHTML = this.highlightText(textOrHtml, this.content.search.input.value, this.classes.searchHighlighter);
|
|
1056
|
+
optionEl.innerHTML = this.highlightText(option.html !== '' ? option.html : option.text, this.content.search.input.value, this.classes.searchHighlighter);
|
|
1048
1057
|
}
|
|
1049
1058
|
else if (option.html !== '') {
|
|
1050
1059
|
optionEl.innerHTML = option.html;
|
|
@@ -1055,7 +1064,10 @@
|
|
|
1055
1064
|
if (this.settings.showOptionTooltips && optionEl.textContent) {
|
|
1056
1065
|
optionEl.setAttribute('title', optionEl.textContent);
|
|
1057
1066
|
}
|
|
1058
|
-
if (
|
|
1067
|
+
if (!option.display) {
|
|
1068
|
+
optionEl.classList.add(this.classes.hide);
|
|
1069
|
+
}
|
|
1070
|
+
if (option.disabled) {
|
|
1059
1071
|
optionEl.classList.add(this.classes.disabled);
|
|
1060
1072
|
}
|
|
1061
1073
|
if (option.selected && this.settings.hideSelected) {
|
|
@@ -1076,9 +1088,8 @@
|
|
|
1076
1088
|
if (option.disabled || (option.selected && !this.settings.allowDeselect)) {
|
|
1077
1089
|
return;
|
|
1078
1090
|
}
|
|
1079
|
-
if (this.settings.isMultiple &&
|
|
1080
|
-
|
|
1081
|
-
this.settings.maxSelected <= selectedOptions.length) {
|
|
1091
|
+
if ((this.settings.isMultiple && this.settings.maxSelected <= selectedOptions.length && !option.selected) ||
|
|
1092
|
+
(this.settings.isMultiple && this.settings.minSelected >= selectedOptions.length && option.selected)) {
|
|
1082
1093
|
return;
|
|
1083
1094
|
}
|
|
1084
1095
|
let shouldUpdate = false;
|
|
@@ -1115,7 +1126,7 @@
|
|
|
1115
1126
|
if (!this.store.getOptionByID(elementID)) {
|
|
1116
1127
|
this.callbacks.addOption(option);
|
|
1117
1128
|
}
|
|
1118
|
-
this.callbacks.setSelected(after.map((o) => o.value));
|
|
1129
|
+
this.callbacks.setSelected(after.map((o) => o.value), false);
|
|
1119
1130
|
if (this.settings.closeOnSelect) {
|
|
1120
1131
|
this.callbacks.close();
|
|
1121
1132
|
}
|
|
@@ -1143,23 +1154,30 @@
|
|
|
1143
1154
|
return completedString;
|
|
1144
1155
|
}
|
|
1145
1156
|
moveContentAbove() {
|
|
1146
|
-
|
|
1157
|
+
const mainHeight = this.main.main.offsetHeight;
|
|
1147
1158
|
const contentHeight = this.content.main.offsetHeight;
|
|
1148
|
-
const height = mainHeight + contentHeight - 1;
|
|
1149
|
-
this.content.main.style.margin = '-' + height + 'px 0px 0px 0px';
|
|
1150
|
-
this.content.main.style.transformOrigin = 'center bottom';
|
|
1151
1159
|
this.main.main.classList.remove(this.classes.openBelow);
|
|
1152
1160
|
this.main.main.classList.add(this.classes.openAbove);
|
|
1153
1161
|
this.content.main.classList.remove(this.classes.openBelow);
|
|
1154
1162
|
this.content.main.classList.add(this.classes.openAbove);
|
|
1163
|
+
const containerRect = this.main.main.getBoundingClientRect();
|
|
1164
|
+
this.content.main.style.margin = '-' + (mainHeight + contentHeight - 1) + 'px 0px 0px 0px';
|
|
1165
|
+
this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
|
|
1166
|
+
this.content.main.style.left = containerRect.left + window.scrollX + 'px';
|
|
1167
|
+
this.content.main.style.width = containerRect.width + 'px';
|
|
1155
1168
|
}
|
|
1156
1169
|
moveContentBelow() {
|
|
1157
|
-
this.content.main.style.margin = '-1px 0px 0px 0px';
|
|
1158
|
-
this.content.main.style.transformOrigin = 'center top';
|
|
1159
1170
|
this.main.main.classList.remove(this.classes.openAbove);
|
|
1160
1171
|
this.main.main.classList.add(this.classes.openBelow);
|
|
1161
1172
|
this.content.main.classList.remove(this.classes.openAbove);
|
|
1162
1173
|
this.content.main.classList.add(this.classes.openBelow);
|
|
1174
|
+
const containerRect = this.main.main.getBoundingClientRect();
|
|
1175
|
+
this.content.main.style.margin = '-1px 0px 0px 0px';
|
|
1176
|
+
if (this.settings.contentPosition !== 'relative') {
|
|
1177
|
+
this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
|
|
1178
|
+
this.content.main.style.left = containerRect.left + window.scrollX + 'px';
|
|
1179
|
+
this.content.main.style.width = containerRect.width + 'px';
|
|
1180
|
+
}
|
|
1163
1181
|
}
|
|
1164
1182
|
ensureElementInView(container, element) {
|
|
1165
1183
|
const cTop = container.scrollTop + container.offsetTop;
|
|
@@ -1173,16 +1191,18 @@
|
|
|
1173
1191
|
container.scrollTop += eBottom - cBottom;
|
|
1174
1192
|
}
|
|
1175
1193
|
}
|
|
1176
|
-
putContent(
|
|
1177
|
-
const
|
|
1178
|
-
const
|
|
1179
|
-
const
|
|
1180
|
-
const
|
|
1181
|
-
if (
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1194
|
+
putContent() {
|
|
1195
|
+
const mainHeight = this.main.main.offsetHeight;
|
|
1196
|
+
const mainRect = this.main.main.getBoundingClientRect();
|
|
1197
|
+
const contentHeight = this.content.main.offsetHeight;
|
|
1198
|
+
const spaceBelow = window.innerHeight - (mainRect.top + mainHeight);
|
|
1199
|
+
if (spaceBelow <= contentHeight) {
|
|
1200
|
+
if (mainRect.top > contentHeight) {
|
|
1201
|
+
return 'up';
|
|
1202
|
+
}
|
|
1203
|
+
else {
|
|
1204
|
+
return 'down';
|
|
1205
|
+
}
|
|
1186
1206
|
}
|
|
1187
1207
|
return 'down';
|
|
1188
1208
|
}
|
|
@@ -1193,16 +1213,17 @@
|
|
|
1193
1213
|
this.listen = false;
|
|
1194
1214
|
this.observer = null;
|
|
1195
1215
|
this.select = select;
|
|
1216
|
+
this.select.addEventListener('change', this.valueChange.bind(this), {
|
|
1217
|
+
passive: true,
|
|
1218
|
+
});
|
|
1219
|
+
this.observer = new MutationObserver(this.observeCall.bind(this));
|
|
1220
|
+
this.changeListen(true);
|
|
1196
1221
|
}
|
|
1197
1222
|
enable() {
|
|
1198
|
-
this.disconnectObserver();
|
|
1199
1223
|
this.select.disabled = false;
|
|
1200
|
-
this.connectObserver();
|
|
1201
1224
|
}
|
|
1202
1225
|
disable() {
|
|
1203
|
-
this.disconnectObserver();
|
|
1204
1226
|
this.select.disabled = true;
|
|
1205
|
-
this.connectObserver();
|
|
1206
1227
|
}
|
|
1207
1228
|
hideUI() {
|
|
1208
1229
|
this.select.tabIndex = -1;
|
|
@@ -1214,65 +1235,61 @@
|
|
|
1214
1235
|
this.select.style.display = '';
|
|
1215
1236
|
this.select.removeAttribute('aria-hidden');
|
|
1216
1237
|
}
|
|
1217
|
-
changeListen(
|
|
1218
|
-
this.listen =
|
|
1219
|
-
if (
|
|
1220
|
-
this.
|
|
1238
|
+
changeListen(listen) {
|
|
1239
|
+
this.listen = listen;
|
|
1240
|
+
if (listen) {
|
|
1241
|
+
if (this.observer) {
|
|
1242
|
+
this.observer.observe(this.select, {
|
|
1243
|
+
subtree: true,
|
|
1244
|
+
childList: true,
|
|
1245
|
+
attributes: true,
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1221
1248
|
}
|
|
1222
|
-
|
|
1223
|
-
this.
|
|
1249
|
+
if (!listen) {
|
|
1250
|
+
if (this.observer) {
|
|
1251
|
+
this.observer.disconnect();
|
|
1252
|
+
}
|
|
1224
1253
|
}
|
|
1225
1254
|
}
|
|
1226
|
-
addSelectChangeListener(func) {
|
|
1227
|
-
this.onSelectChange = func;
|
|
1228
|
-
this.addObserver();
|
|
1229
|
-
this.connectObserver();
|
|
1230
|
-
this.changeListen(true);
|
|
1231
|
-
}
|
|
1232
|
-
removeSelectChangeListener() {
|
|
1233
|
-
this.changeListen(false);
|
|
1234
|
-
this.onSelectChange = undefined;
|
|
1235
|
-
}
|
|
1236
|
-
addValueChangeListener(func) {
|
|
1237
|
-
this.onValueChange = func;
|
|
1238
|
-
this.select.addEventListener('change', this.valueChange.bind(this), {
|
|
1239
|
-
passive: true,
|
|
1240
|
-
});
|
|
1241
|
-
}
|
|
1242
|
-
removeValueChangeListener() {
|
|
1243
|
-
this.onValueChange = undefined;
|
|
1244
|
-
this.select.removeEventListener('change', this.valueChange.bind(this));
|
|
1245
|
-
}
|
|
1246
1255
|
valueChange(ev) {
|
|
1247
1256
|
if (this.listen && this.onValueChange) {
|
|
1248
1257
|
this.onValueChange(this.getSelectedValues());
|
|
1249
1258
|
}
|
|
1250
1259
|
return true;
|
|
1251
1260
|
}
|
|
1252
|
-
|
|
1253
|
-
if (this.
|
|
1254
|
-
|
|
1255
|
-
this.onSelectChange(this.getData());
|
|
1256
|
-
this.changeListen(true);
|
|
1261
|
+
observeCall(mutations) {
|
|
1262
|
+
if (!this.listen) {
|
|
1263
|
+
return;
|
|
1257
1264
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
this.
|
|
1265
|
+
let classChanged = false;
|
|
1266
|
+
let disabledChanged = false;
|
|
1267
|
+
let optgroupOptionChanged = false;
|
|
1268
|
+
for (const m of mutations) {
|
|
1269
|
+
if (m.target === this.select) {
|
|
1270
|
+
if (m.attributeName === 'disabled') {
|
|
1271
|
+
disabledChanged = true;
|
|
1272
|
+
}
|
|
1273
|
+
if (m.attributeName === 'class') {
|
|
1274
|
+
classChanged = true;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
if (m.target.nodeName === 'OPTGROUP' || m.target.nodeName === 'OPTION') {
|
|
1278
|
+
optgroupOptionChanged = true;
|
|
1279
|
+
}
|
|
1263
1280
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
connectObserver() {
|
|
1267
|
-
if (this.observer) {
|
|
1268
|
-
this.observer.observe(this.select, {
|
|
1269
|
-
childList: true,
|
|
1270
|
-
});
|
|
1281
|
+
if (classChanged && this.onClassChange) {
|
|
1282
|
+
this.onClassChange(this.select.className.split(' '));
|
|
1271
1283
|
}
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
this.
|
|
1284
|
+
if (disabledChanged && this.onDisabledChange) {
|
|
1285
|
+
this.changeListen(false);
|
|
1286
|
+
this.onDisabledChange(this.select.disabled);
|
|
1287
|
+
this.changeListen(true);
|
|
1288
|
+
}
|
|
1289
|
+
if (optgroupOptionChanged && this.onOptionsChange) {
|
|
1290
|
+
this.changeListen(false);
|
|
1291
|
+
this.onOptionsChange(this.getData());
|
|
1292
|
+
this.changeListen(true);
|
|
1276
1293
|
}
|
|
1277
1294
|
}
|
|
1278
1295
|
getData() {
|
|
@@ -1290,7 +1307,7 @@
|
|
|
1290
1307
|
}
|
|
1291
1308
|
getDataFromOptgroup(optgroup) {
|
|
1292
1309
|
let data = {
|
|
1293
|
-
id:
|
|
1310
|
+
id: optgroup.id,
|
|
1294
1311
|
label: optgroup.label,
|
|
1295
1312
|
selectAll: optgroup.dataset ? optgroup.dataset.selectall === 'true' : false,
|
|
1296
1313
|
closable: optgroup.dataset ? optgroup.dataset.closable : 'off',
|
|
@@ -1306,10 +1323,10 @@
|
|
|
1306
1323
|
}
|
|
1307
1324
|
getDataFromOption(option) {
|
|
1308
1325
|
return {
|
|
1309
|
-
id:
|
|
1326
|
+
id: option.id,
|
|
1310
1327
|
value: option.value,
|
|
1311
1328
|
text: option.text,
|
|
1312
|
-
html: option.
|
|
1329
|
+
html: option.dataset && option.dataset.html ? option.dataset.html : '',
|
|
1313
1330
|
selected: option.selected,
|
|
1314
1331
|
display: option.style.display === 'none' ? false : true,
|
|
1315
1332
|
disabled: option.disabled,
|
|
@@ -1345,6 +1362,7 @@
|
|
|
1345
1362
|
return values;
|
|
1346
1363
|
}
|
|
1347
1364
|
setSelected(value) {
|
|
1365
|
+
this.changeListen(false);
|
|
1348
1366
|
const options = this.select.childNodes;
|
|
1349
1367
|
for (const o of options) {
|
|
1350
1368
|
if (o.nodeName === 'OPTGROUP') {
|
|
@@ -1362,11 +1380,12 @@
|
|
|
1362
1380
|
option.selected = value.includes(option.value);
|
|
1363
1381
|
}
|
|
1364
1382
|
}
|
|
1383
|
+
this.changeListen(true);
|
|
1365
1384
|
}
|
|
1366
1385
|
updateSelect(id, style, classes) {
|
|
1367
1386
|
this.changeListen(false);
|
|
1368
1387
|
if (id) {
|
|
1369
|
-
this.select.id = id;
|
|
1388
|
+
this.select.dataset.id = id;
|
|
1370
1389
|
}
|
|
1371
1390
|
if (style) {
|
|
1372
1391
|
this.select.style.cssText = style;
|
|
@@ -1414,8 +1433,12 @@
|
|
|
1414
1433
|
}
|
|
1415
1434
|
createOption(info) {
|
|
1416
1435
|
const optionEl = document.createElement('option');
|
|
1417
|
-
optionEl.
|
|
1418
|
-
optionEl.
|
|
1436
|
+
optionEl.id = info.id;
|
|
1437
|
+
optionEl.value = info.value;
|
|
1438
|
+
optionEl.innerHTML = info.text;
|
|
1439
|
+
if (info.html !== '') {
|
|
1440
|
+
optionEl.setAttribute('data-html', info.html);
|
|
1441
|
+
}
|
|
1419
1442
|
if (info.selected) {
|
|
1420
1443
|
optionEl.selected = info.selected;
|
|
1421
1444
|
}
|
|
@@ -1445,15 +1468,19 @@
|
|
|
1445
1468
|
}
|
|
1446
1469
|
destroy() {
|
|
1447
1470
|
this.changeListen(false);
|
|
1448
|
-
this.
|
|
1449
|
-
this.
|
|
1450
|
-
|
|
1471
|
+
this.select.removeEventListener('change', this.valueChange.bind(this));
|
|
1472
|
+
if (this.observer) {
|
|
1473
|
+
this.observer.disconnect();
|
|
1474
|
+
this.observer = null;
|
|
1475
|
+
}
|
|
1476
|
+
delete this.select.dataset.id;
|
|
1451
1477
|
this.showUI();
|
|
1452
1478
|
}
|
|
1453
1479
|
}
|
|
1454
1480
|
|
|
1455
1481
|
class SlimSelect {
|
|
1456
1482
|
constructor(config) {
|
|
1483
|
+
var _a;
|
|
1457
1484
|
this.events = {
|
|
1458
1485
|
search: undefined,
|
|
1459
1486
|
searchFilter: (opt, search) => {
|
|
@@ -1477,23 +1504,7 @@
|
|
|
1477
1504
|
if (!this.settings.isOpen) {
|
|
1478
1505
|
return;
|
|
1479
1506
|
}
|
|
1480
|
-
|
|
1481
|
-
this.render.moveContentBelow();
|
|
1482
|
-
return;
|
|
1483
|
-
}
|
|
1484
|
-
else if (this.settings.openPosition === 'up') {
|
|
1485
|
-
this.render.moveContentAbove();
|
|
1486
|
-
return;
|
|
1487
|
-
}
|
|
1488
|
-
if (this.settings.contentPosition === 'relative') {
|
|
1489
|
-
this.render.moveContentBelow();
|
|
1490
|
-
}
|
|
1491
|
-
else if (this.render.putContent(this.render.content.main, this.settings.isOpen) === 'up') {
|
|
1492
|
-
this.render.moveContentAbove();
|
|
1493
|
-
}
|
|
1494
|
-
else {
|
|
1495
|
-
this.render.moveContentBelow();
|
|
1496
|
-
}
|
|
1507
|
+
this.render.moveContent();
|
|
1497
1508
|
});
|
|
1498
1509
|
this.documentClick = (e) => {
|
|
1499
1510
|
if (!this.settings.isOpen) {
|
|
@@ -1525,18 +1536,31 @@
|
|
|
1525
1536
|
this.events[key] = config.events[key];
|
|
1526
1537
|
}
|
|
1527
1538
|
}
|
|
1539
|
+
this.settings.disabled = ((_a = config.settings) === null || _a === void 0 ? void 0 : _a.disabled) ? config.settings.disabled : this.selectEl.disabled;
|
|
1528
1540
|
this.settings.isMultiple = this.selectEl.multiple;
|
|
1529
1541
|
this.settings.style = this.selectEl.style.cssText;
|
|
1530
1542
|
this.settings.class = this.selectEl.className.split(' ');
|
|
1531
1543
|
this.select = new Select(this.selectEl);
|
|
1532
1544
|
this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class);
|
|
1533
1545
|
this.select.hideUI();
|
|
1534
|
-
this.select.
|
|
1535
|
-
this.setData(data);
|
|
1536
|
-
});
|
|
1537
|
-
this.select.addValueChangeListener((values) => {
|
|
1546
|
+
this.select.onValueChange = (values) => {
|
|
1538
1547
|
this.setSelected(values);
|
|
1539
|
-
}
|
|
1548
|
+
};
|
|
1549
|
+
this.select.onClassChange = (classes) => {
|
|
1550
|
+
this.settings.class = classes;
|
|
1551
|
+
this.render.updateClassStyles();
|
|
1552
|
+
};
|
|
1553
|
+
this.select.onDisabledChange = (disabled) => {
|
|
1554
|
+
if (disabled) {
|
|
1555
|
+
this.disable();
|
|
1556
|
+
}
|
|
1557
|
+
else {
|
|
1558
|
+
this.enable();
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
this.select.onOptionsChange = (data) => {
|
|
1562
|
+
this.setData(data);
|
|
1563
|
+
};
|
|
1540
1564
|
this.store = new Store(this.settings.isMultiple ? 'multiple' : 'single', config.data ? config.data : this.select.getData());
|
|
1541
1565
|
if (config.data) {
|
|
1542
1566
|
this.select.updateOptions(this.store.getData());
|
|
@@ -1562,7 +1586,7 @@
|
|
|
1562
1586
|
if (this.settings.openPosition === 'auto') {
|
|
1563
1587
|
window.addEventListener('scroll', this.windowScroll, false);
|
|
1564
1588
|
}
|
|
1565
|
-
if (
|
|
1589
|
+
if (this.settings.disabled) {
|
|
1566
1590
|
this.disable();
|
|
1567
1591
|
}
|
|
1568
1592
|
if (this.settings.alwaysOpen) {
|
|
@@ -1571,12 +1595,12 @@
|
|
|
1571
1595
|
this.selectEl.slim = this;
|
|
1572
1596
|
}
|
|
1573
1597
|
enable() {
|
|
1574
|
-
this.settings.
|
|
1598
|
+
this.settings.disabled = false;
|
|
1575
1599
|
this.select.enable();
|
|
1576
1600
|
this.render.enable();
|
|
1577
1601
|
}
|
|
1578
1602
|
disable() {
|
|
1579
|
-
this.settings.
|
|
1603
|
+
this.settings.disabled = true;
|
|
1580
1604
|
this.select.disable();
|
|
1581
1605
|
this.render.disable();
|
|
1582
1606
|
}
|
|
@@ -1604,14 +1628,19 @@
|
|
|
1604
1628
|
getSelected() {
|
|
1605
1629
|
return this.store.getSelected();
|
|
1606
1630
|
}
|
|
1607
|
-
setSelected(value) {
|
|
1631
|
+
setSelected(value, runAfterChange = true) {
|
|
1608
1632
|
const selected = this.store.getSelected();
|
|
1609
1633
|
this.store.setSelectedBy('value', Array.isArray(value) ? value : [value]);
|
|
1610
1634
|
const data = this.store.getData();
|
|
1611
1635
|
this.select.updateOptions(data);
|
|
1612
1636
|
this.render.renderValues();
|
|
1613
|
-
this.render.
|
|
1614
|
-
|
|
1637
|
+
if (this.render.content.search.input.value !== '') {
|
|
1638
|
+
this.search(this.render.content.search.input.value);
|
|
1639
|
+
}
|
|
1640
|
+
else {
|
|
1641
|
+
this.render.renderOptions(data);
|
|
1642
|
+
}
|
|
1643
|
+
if (runAfterChange && this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
1615
1644
|
this.events.afterChange(this.store.getSelectedOptions());
|
|
1616
1645
|
}
|
|
1617
1646
|
}
|
|
@@ -1627,7 +1656,7 @@
|
|
|
1627
1656
|
}
|
|
1628
1657
|
}
|
|
1629
1658
|
open() {
|
|
1630
|
-
if (
|
|
1659
|
+
if (this.settings.disabled || this.settings.isOpen) {
|
|
1631
1660
|
return;
|
|
1632
1661
|
}
|
|
1633
1662
|
if (this.events.beforeOpen) {
|
|
@@ -1643,10 +1672,12 @@
|
|
|
1643
1672
|
}
|
|
1644
1673
|
this.settings.isOpen = true;
|
|
1645
1674
|
}, this.settings.timeoutDelay);
|
|
1646
|
-
if (this.settings.
|
|
1647
|
-
|
|
1675
|
+
if (this.settings.contentPosition === 'absolute') {
|
|
1676
|
+
if (this.settings.intervalMove) {
|
|
1677
|
+
clearInterval(this.settings.intervalMove);
|
|
1678
|
+
}
|
|
1679
|
+
this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
|
|
1648
1680
|
}
|
|
1649
|
-
this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
|
|
1650
1681
|
}
|
|
1651
1682
|
close() {
|
|
1652
1683
|
if (!this.settings.isOpen || this.settings.alwaysOpen) {
|
|
@@ -1656,7 +1687,9 @@
|
|
|
1656
1687
|
this.events.beforeClose();
|
|
1657
1688
|
}
|
|
1658
1689
|
this.render.close();
|
|
1659
|
-
this.search
|
|
1690
|
+
if (this.render.content.search.input.value !== '') {
|
|
1691
|
+
this.search('');
|
|
1692
|
+
}
|
|
1660
1693
|
this.render.mainFocus(false);
|
|
1661
1694
|
setTimeout(() => {
|
|
1662
1695
|
if (this.events.afterClose) {
|