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
|
@@ -68,7 +68,7 @@ var SlimSelect = (function () {
|
|
|
68
68
|
this.id = 'ss-' + generateID();
|
|
69
69
|
this.style = settings.style || '';
|
|
70
70
|
this.class = settings.class || [];
|
|
71
|
-
this.
|
|
71
|
+
this.disabled = settings.disabled !== undefined ? settings.disabled : false;
|
|
72
72
|
this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
|
|
73
73
|
this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
|
|
74
74
|
this.searchPlaceholder = settings.searchPlaceholder || 'Search';
|
|
@@ -86,6 +86,8 @@ var SlimSelect = (function () {
|
|
|
86
86
|
this.minSelected = settings.minSelected || 0;
|
|
87
87
|
this.maxSelected = settings.maxSelected || 1000;
|
|
88
88
|
this.timeoutDelay = settings.timeoutDelay || 200;
|
|
89
|
+
this.maxValuesShown = settings.maxValuesShown || 20;
|
|
90
|
+
this.maxValuesMessage = settings.maxValuesMessage || '{number} selected';
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
|
|
@@ -302,6 +304,7 @@ var SlimSelect = (function () {
|
|
|
302
304
|
placeholder: 'ss-placeholder',
|
|
303
305
|
values: 'ss-values',
|
|
304
306
|
single: 'ss-single',
|
|
307
|
+
max: 'ss-max',
|
|
305
308
|
value: 'ss-value',
|
|
306
309
|
valueText: 'ss-value-text',
|
|
307
310
|
valueDelete: 'ss-value-delete',
|
|
@@ -343,6 +346,7 @@ var SlimSelect = (function () {
|
|
|
343
346
|
this.callbacks = callbacks;
|
|
344
347
|
this.main = this.mainDiv();
|
|
345
348
|
this.content = this.contentDiv();
|
|
349
|
+
this.updateClassStyles();
|
|
346
350
|
this.settings.contentLocation.appendChild(this.content.main);
|
|
347
351
|
}
|
|
348
352
|
enable() {
|
|
@@ -357,24 +361,6 @@ var SlimSelect = (function () {
|
|
|
357
361
|
this.main.arrow.path.setAttribute('d', this.classes.arrowOpen);
|
|
358
362
|
this.main.main.classList.add(this.settings.openPosition === 'up' ? this.classes.openAbove : this.classes.openBelow);
|
|
359
363
|
this.moveContent();
|
|
360
|
-
this.renderOptions(this.store.getData());
|
|
361
|
-
if (this.settings.contentPosition === 'relative') {
|
|
362
|
-
this.moveContentBelow();
|
|
363
|
-
}
|
|
364
|
-
else if (this.settings.openPosition.toLowerCase() === 'up') {
|
|
365
|
-
this.moveContentAbove();
|
|
366
|
-
}
|
|
367
|
-
else if (this.settings.openPosition.toLowerCase() === 'down') {
|
|
368
|
-
this.moveContentBelow();
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
if (this.putContent(this.content.main, this.settings.isOpen) === 'up') {
|
|
372
|
-
this.moveContentAbove();
|
|
373
|
-
}
|
|
374
|
-
else {
|
|
375
|
-
this.moveContentBelow();
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
364
|
const selectedOptions = this.store.getSelectedOptions();
|
|
379
365
|
if (selectedOptions.length) {
|
|
380
366
|
const selectedId = selectedOptions[selectedOptions.length - 1].id;
|
|
@@ -391,20 +377,32 @@ var SlimSelect = (function () {
|
|
|
391
377
|
this.content.main.classList.remove(this.classes.openBelow);
|
|
392
378
|
this.main.arrow.path.setAttribute('d', this.classes.arrowClose);
|
|
393
379
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
main.
|
|
397
|
-
|
|
398
|
-
main.
|
|
399
|
-
main.classList.add(this.
|
|
400
|
-
main.classList.add(this.classes.
|
|
401
|
-
if (this.settings.
|
|
380
|
+
updateClassStyles() {
|
|
381
|
+
this.main.main.className = '';
|
|
382
|
+
this.main.main.removeAttribute('style');
|
|
383
|
+
this.content.main.className = '';
|
|
384
|
+
this.content.main.removeAttribute('style');
|
|
385
|
+
this.main.main.classList.add(this.classes.main);
|
|
386
|
+
this.content.main.classList.add(this.classes.content);
|
|
387
|
+
if (this.settings.style !== '') {
|
|
388
|
+
this.content.main.style.cssText = this.settings.style;
|
|
389
|
+
}
|
|
390
|
+
if (this.settings.class.length) {
|
|
402
391
|
for (const c of this.settings.class) {
|
|
403
392
|
if (c.trim() !== '') {
|
|
404
|
-
main.classList.add(c.trim());
|
|
393
|
+
this.main.main.classList.add(c.trim());
|
|
394
|
+
this.content.main.classList.add(c.trim());
|
|
405
395
|
}
|
|
406
396
|
}
|
|
407
397
|
}
|
|
398
|
+
if (this.settings.contentPosition === 'relative') {
|
|
399
|
+
this.content.main.classList.add('ss-' + this.settings.contentPosition);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
mainDiv() {
|
|
403
|
+
const main = document.createElement('div');
|
|
404
|
+
main.dataset.id = this.settings.id;
|
|
405
|
+
main.tabIndex = 0;
|
|
408
406
|
main.onfocus = () => {
|
|
409
407
|
if (this.settings.triggerFocus) {
|
|
410
408
|
this.callbacks.open();
|
|
@@ -432,7 +430,7 @@ var SlimSelect = (function () {
|
|
|
432
430
|
}
|
|
433
431
|
};
|
|
434
432
|
main.onclick = (e) => {
|
|
435
|
-
if (
|
|
433
|
+
if (this.settings.disabled) {
|
|
436
434
|
return;
|
|
437
435
|
}
|
|
438
436
|
this.settings.isOpen ? this.callbacks.close() : this.callbacks.open();
|
|
@@ -447,7 +445,7 @@ var SlimSelect = (function () {
|
|
|
447
445
|
}
|
|
448
446
|
deselect.onclick = (e) => {
|
|
449
447
|
e.stopPropagation();
|
|
450
|
-
if (
|
|
448
|
+
if (this.settings.disabled) {
|
|
451
449
|
return;
|
|
452
450
|
}
|
|
453
451
|
let shouldDelete = true;
|
|
@@ -457,7 +455,7 @@ var SlimSelect = (function () {
|
|
|
457
455
|
shouldDelete = this.callbacks.beforeChange(after, before) === true;
|
|
458
456
|
}
|
|
459
457
|
if (shouldDelete) {
|
|
460
|
-
this.callbacks.setSelected(['']);
|
|
458
|
+
this.callbacks.setSelected([''], false);
|
|
461
459
|
if (this.settings.closeOnSelect) {
|
|
462
460
|
this.callbacks.close();
|
|
463
461
|
}
|
|
@@ -563,6 +561,19 @@ var SlimSelect = (function () {
|
|
|
563
561
|
placeholder.remove();
|
|
564
562
|
}
|
|
565
563
|
}
|
|
564
|
+
if (selectedOptions.length > this.settings.maxValuesShown) {
|
|
565
|
+
const singleValue = document.createElement('div');
|
|
566
|
+
singleValue.classList.add(this.classes.max);
|
|
567
|
+
singleValue.textContent = this.settings.maxValuesMessage.replace('{number}', selectedOptions.length.toString());
|
|
568
|
+
this.main.values.innerHTML = singleValue.outerHTML;
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
const maxValuesMessage = this.main.values.querySelector('.' + this.classes.max);
|
|
573
|
+
if (maxValuesMessage) {
|
|
574
|
+
maxValuesMessage.remove();
|
|
575
|
+
}
|
|
576
|
+
}
|
|
566
577
|
let removeNodes = [];
|
|
567
578
|
for (let i = 0; i < currentNodes.length; i++) {
|
|
568
579
|
const node = currentNodes[i];
|
|
@@ -617,6 +628,9 @@ var SlimSelect = (function () {
|
|
|
617
628
|
deleteDiv.onclick = (e) => {
|
|
618
629
|
e.preventDefault();
|
|
619
630
|
e.stopPropagation();
|
|
631
|
+
if (this.settings.disabled) {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
620
634
|
let shouldDelete = true;
|
|
621
635
|
const before = this.store.getSelectedOptions();
|
|
622
636
|
const after = before.filter((o) => {
|
|
@@ -640,7 +654,7 @@ var SlimSelect = (function () {
|
|
|
640
654
|
selectedValues.push(o.value);
|
|
641
655
|
}
|
|
642
656
|
}
|
|
643
|
-
this.callbacks.setSelected(selectedValues);
|
|
657
|
+
this.callbacks.setSelected(selectedValues, false);
|
|
644
658
|
if (this.settings.closeOnSelect) {
|
|
645
659
|
this.callbacks.close();
|
|
646
660
|
}
|
|
@@ -661,21 +675,7 @@ var SlimSelect = (function () {
|
|
|
661
675
|
}
|
|
662
676
|
contentDiv() {
|
|
663
677
|
const main = document.createElement('div');
|
|
664
|
-
main.classList.add(this.classes.content);
|
|
665
678
|
main.dataset.id = this.settings.id;
|
|
666
|
-
if (this.settings.style !== '') {
|
|
667
|
-
main.style.cssText = this.settings.style;
|
|
668
|
-
}
|
|
669
|
-
if (this.settings.contentPosition === 'relative') {
|
|
670
|
-
main.classList.add('ss-' + this.settings.contentPosition);
|
|
671
|
-
}
|
|
672
|
-
if (this.settings.class.length) {
|
|
673
|
-
for (const c of this.settings.class) {
|
|
674
|
-
if (c.trim() !== '') {
|
|
675
|
-
main.classList.add(c.trim());
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
679
|
const search = this.searchDiv();
|
|
680
680
|
main.appendChild(search.main);
|
|
681
681
|
const list = this.listDiv();
|
|
@@ -688,12 +688,23 @@ var SlimSelect = (function () {
|
|
|
688
688
|
}
|
|
689
689
|
moveContent() {
|
|
690
690
|
if (this.settings.contentPosition === 'relative') {
|
|
691
|
+
this.moveContentBelow();
|
|
691
692
|
return;
|
|
692
693
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
694
|
+
if (this.settings.openPosition === 'down') {
|
|
695
|
+
this.moveContentBelow();
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
else if (this.settings.openPosition === 'up') {
|
|
699
|
+
this.moveContentAbove();
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (this.putContent() === 'up') {
|
|
703
|
+
this.moveContentAbove();
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
this.moveContentBelow();
|
|
707
|
+
}
|
|
697
708
|
}
|
|
698
709
|
searchDiv() {
|
|
699
710
|
const main = document.createElement('div');
|
|
@@ -776,10 +787,10 @@ var SlimSelect = (function () {
|
|
|
776
787
|
if (this.settings.isMultiple) {
|
|
777
788
|
let values = this.store.getSelected();
|
|
778
789
|
values.push(newOption.value);
|
|
779
|
-
this.callbacks.setSelected(values);
|
|
790
|
+
this.callbacks.setSelected(values, true);
|
|
780
791
|
}
|
|
781
792
|
else {
|
|
782
|
-
this.callbacks.setSelected([newOption.value]);
|
|
793
|
+
this.callbacks.setSelected([newOption.value], true);
|
|
783
794
|
}
|
|
784
795
|
this.callbacks.search('');
|
|
785
796
|
if (this.settings.closeOnSelect) {
|
|
@@ -904,8 +915,7 @@ var SlimSelect = (function () {
|
|
|
904
915
|
this.content.list.innerHTML = '';
|
|
905
916
|
if (data.length === 0) {
|
|
906
917
|
const noResults = document.createElement('div');
|
|
907
|
-
noResults.classList.add(this.classes.
|
|
908
|
-
noResults.classList.add(this.classes.disabled);
|
|
918
|
+
noResults.classList.add(this.classes.search);
|
|
909
919
|
noResults.innerHTML = this.settings.searchText;
|
|
910
920
|
this.content.list.appendChild(noResults);
|
|
911
921
|
return;
|
|
@@ -962,12 +972,12 @@ var SlimSelect = (function () {
|
|
|
962
972
|
}
|
|
963
973
|
return true;
|
|
964
974
|
});
|
|
965
|
-
this.callbacks.setSelected(newSelected);
|
|
975
|
+
this.callbacks.setSelected(newSelected, true);
|
|
966
976
|
return;
|
|
967
977
|
}
|
|
968
978
|
else {
|
|
969
979
|
const newSelected = currentSelected.concat(d.options.map((o) => o.value));
|
|
970
|
-
this.callbacks.setSelected(newSelected);
|
|
980
|
+
this.callbacks.setSelected(newSelected, true);
|
|
971
981
|
}
|
|
972
982
|
});
|
|
973
983
|
optgroupActions.appendChild(selectAll);
|
|
@@ -981,7 +991,7 @@ var SlimSelect = (function () {
|
|
|
981
991
|
optgroupClosable.appendChild(optgroupClosableSvg);
|
|
982
992
|
const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
983
993
|
optgroupClosableSvg.appendChild(optgroupClosableArrow);
|
|
984
|
-
if (d.options.some((o) => o.selected)) {
|
|
994
|
+
if (d.options.some((o) => o.selected) || this.content.search.input.value.trim() !== '') {
|
|
985
995
|
optgroupClosable.classList.add(this.classes.open);
|
|
986
996
|
optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
|
|
987
997
|
}
|
|
@@ -1040,8 +1050,7 @@ var SlimSelect = (function () {
|
|
|
1040
1050
|
optionEl.style.cssText = option.style;
|
|
1041
1051
|
}
|
|
1042
1052
|
if (this.settings.searchHighlight && this.content.search.input.value.trim() !== '') {
|
|
1043
|
-
|
|
1044
|
-
optionEl.innerHTML = this.highlightText(textOrHtml, this.content.search.input.value, this.classes.searchHighlighter);
|
|
1053
|
+
optionEl.innerHTML = this.highlightText(option.html !== '' ? option.html : option.text, this.content.search.input.value, this.classes.searchHighlighter);
|
|
1045
1054
|
}
|
|
1046
1055
|
else if (option.html !== '') {
|
|
1047
1056
|
optionEl.innerHTML = option.html;
|
|
@@ -1052,7 +1061,10 @@ var SlimSelect = (function () {
|
|
|
1052
1061
|
if (this.settings.showOptionTooltips && optionEl.textContent) {
|
|
1053
1062
|
optionEl.setAttribute('title', optionEl.textContent);
|
|
1054
1063
|
}
|
|
1055
|
-
if (
|
|
1064
|
+
if (!option.display) {
|
|
1065
|
+
optionEl.classList.add(this.classes.hide);
|
|
1066
|
+
}
|
|
1067
|
+
if (option.disabled) {
|
|
1056
1068
|
optionEl.classList.add(this.classes.disabled);
|
|
1057
1069
|
}
|
|
1058
1070
|
if (option.selected && this.settings.hideSelected) {
|
|
@@ -1073,9 +1085,8 @@ var SlimSelect = (function () {
|
|
|
1073
1085
|
if (option.disabled || (option.selected && !this.settings.allowDeselect)) {
|
|
1074
1086
|
return;
|
|
1075
1087
|
}
|
|
1076
|
-
if (this.settings.isMultiple &&
|
|
1077
|
-
|
|
1078
|
-
this.settings.maxSelected <= selectedOptions.length) {
|
|
1088
|
+
if ((this.settings.isMultiple && this.settings.maxSelected <= selectedOptions.length && !option.selected) ||
|
|
1089
|
+
(this.settings.isMultiple && this.settings.minSelected >= selectedOptions.length && option.selected)) {
|
|
1079
1090
|
return;
|
|
1080
1091
|
}
|
|
1081
1092
|
let shouldUpdate = false;
|
|
@@ -1112,7 +1123,7 @@ var SlimSelect = (function () {
|
|
|
1112
1123
|
if (!this.store.getOptionByID(elementID)) {
|
|
1113
1124
|
this.callbacks.addOption(option);
|
|
1114
1125
|
}
|
|
1115
|
-
this.callbacks.setSelected(after.map((o) => o.value));
|
|
1126
|
+
this.callbacks.setSelected(after.map((o) => o.value), false);
|
|
1116
1127
|
if (this.settings.closeOnSelect) {
|
|
1117
1128
|
this.callbacks.close();
|
|
1118
1129
|
}
|
|
@@ -1140,23 +1151,30 @@ var SlimSelect = (function () {
|
|
|
1140
1151
|
return completedString;
|
|
1141
1152
|
}
|
|
1142
1153
|
moveContentAbove() {
|
|
1143
|
-
|
|
1154
|
+
const mainHeight = this.main.main.offsetHeight;
|
|
1144
1155
|
const contentHeight = this.content.main.offsetHeight;
|
|
1145
|
-
const height = mainHeight + contentHeight - 1;
|
|
1146
|
-
this.content.main.style.margin = '-' + height + 'px 0px 0px 0px';
|
|
1147
|
-
this.content.main.style.transformOrigin = 'center bottom';
|
|
1148
1156
|
this.main.main.classList.remove(this.classes.openBelow);
|
|
1149
1157
|
this.main.main.classList.add(this.classes.openAbove);
|
|
1150
1158
|
this.content.main.classList.remove(this.classes.openBelow);
|
|
1151
1159
|
this.content.main.classList.add(this.classes.openAbove);
|
|
1160
|
+
const containerRect = this.main.main.getBoundingClientRect();
|
|
1161
|
+
this.content.main.style.margin = '-' + (mainHeight + contentHeight - 1) + 'px 0px 0px 0px';
|
|
1162
|
+
this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
|
|
1163
|
+
this.content.main.style.left = containerRect.left + window.scrollX + 'px';
|
|
1164
|
+
this.content.main.style.width = containerRect.width + 'px';
|
|
1152
1165
|
}
|
|
1153
1166
|
moveContentBelow() {
|
|
1154
|
-
this.content.main.style.margin = '-1px 0px 0px 0px';
|
|
1155
|
-
this.content.main.style.transformOrigin = 'center top';
|
|
1156
1167
|
this.main.main.classList.remove(this.classes.openAbove);
|
|
1157
1168
|
this.main.main.classList.add(this.classes.openBelow);
|
|
1158
1169
|
this.content.main.classList.remove(this.classes.openAbove);
|
|
1159
1170
|
this.content.main.classList.add(this.classes.openBelow);
|
|
1171
|
+
const containerRect = this.main.main.getBoundingClientRect();
|
|
1172
|
+
this.content.main.style.margin = '-1px 0px 0px 0px';
|
|
1173
|
+
if (this.settings.contentPosition !== 'relative') {
|
|
1174
|
+
this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
|
|
1175
|
+
this.content.main.style.left = containerRect.left + window.scrollX + 'px';
|
|
1176
|
+
this.content.main.style.width = containerRect.width + 'px';
|
|
1177
|
+
}
|
|
1160
1178
|
}
|
|
1161
1179
|
ensureElementInView(container, element) {
|
|
1162
1180
|
const cTop = container.scrollTop + container.offsetTop;
|
|
@@ -1170,16 +1188,18 @@ var SlimSelect = (function () {
|
|
|
1170
1188
|
container.scrollTop += eBottom - cBottom;
|
|
1171
1189
|
}
|
|
1172
1190
|
}
|
|
1173
|
-
putContent(
|
|
1174
|
-
const
|
|
1175
|
-
const
|
|
1176
|
-
const
|
|
1177
|
-
const
|
|
1178
|
-
if (
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1191
|
+
putContent() {
|
|
1192
|
+
const mainHeight = this.main.main.offsetHeight;
|
|
1193
|
+
const mainRect = this.main.main.getBoundingClientRect();
|
|
1194
|
+
const contentHeight = this.content.main.offsetHeight;
|
|
1195
|
+
const spaceBelow = window.innerHeight - (mainRect.top + mainHeight);
|
|
1196
|
+
if (spaceBelow <= contentHeight) {
|
|
1197
|
+
if (mainRect.top > contentHeight) {
|
|
1198
|
+
return 'up';
|
|
1199
|
+
}
|
|
1200
|
+
else {
|
|
1201
|
+
return 'down';
|
|
1202
|
+
}
|
|
1183
1203
|
}
|
|
1184
1204
|
return 'down';
|
|
1185
1205
|
}
|
|
@@ -1190,16 +1210,17 @@ var SlimSelect = (function () {
|
|
|
1190
1210
|
this.listen = false;
|
|
1191
1211
|
this.observer = null;
|
|
1192
1212
|
this.select = select;
|
|
1213
|
+
this.select.addEventListener('change', this.valueChange.bind(this), {
|
|
1214
|
+
passive: true,
|
|
1215
|
+
});
|
|
1216
|
+
this.observer = new MutationObserver(this.observeCall.bind(this));
|
|
1217
|
+
this.changeListen(true);
|
|
1193
1218
|
}
|
|
1194
1219
|
enable() {
|
|
1195
|
-
this.disconnectObserver();
|
|
1196
1220
|
this.select.disabled = false;
|
|
1197
|
-
this.connectObserver();
|
|
1198
1221
|
}
|
|
1199
1222
|
disable() {
|
|
1200
|
-
this.disconnectObserver();
|
|
1201
1223
|
this.select.disabled = true;
|
|
1202
|
-
this.connectObserver();
|
|
1203
1224
|
}
|
|
1204
1225
|
hideUI() {
|
|
1205
1226
|
this.select.tabIndex = -1;
|
|
@@ -1211,65 +1232,61 @@ var SlimSelect = (function () {
|
|
|
1211
1232
|
this.select.style.display = '';
|
|
1212
1233
|
this.select.removeAttribute('aria-hidden');
|
|
1213
1234
|
}
|
|
1214
|
-
changeListen(
|
|
1215
|
-
this.listen =
|
|
1216
|
-
if (
|
|
1217
|
-
this.
|
|
1235
|
+
changeListen(listen) {
|
|
1236
|
+
this.listen = listen;
|
|
1237
|
+
if (listen) {
|
|
1238
|
+
if (this.observer) {
|
|
1239
|
+
this.observer.observe(this.select, {
|
|
1240
|
+
subtree: true,
|
|
1241
|
+
childList: true,
|
|
1242
|
+
attributes: true,
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1218
1245
|
}
|
|
1219
|
-
|
|
1220
|
-
this.
|
|
1246
|
+
if (!listen) {
|
|
1247
|
+
if (this.observer) {
|
|
1248
|
+
this.observer.disconnect();
|
|
1249
|
+
}
|
|
1221
1250
|
}
|
|
1222
1251
|
}
|
|
1223
|
-
addSelectChangeListener(func) {
|
|
1224
|
-
this.onSelectChange = func;
|
|
1225
|
-
this.addObserver();
|
|
1226
|
-
this.connectObserver();
|
|
1227
|
-
this.changeListen(true);
|
|
1228
|
-
}
|
|
1229
|
-
removeSelectChangeListener() {
|
|
1230
|
-
this.changeListen(false);
|
|
1231
|
-
this.onSelectChange = undefined;
|
|
1232
|
-
}
|
|
1233
|
-
addValueChangeListener(func) {
|
|
1234
|
-
this.onValueChange = func;
|
|
1235
|
-
this.select.addEventListener('change', this.valueChange.bind(this), {
|
|
1236
|
-
passive: true,
|
|
1237
|
-
});
|
|
1238
|
-
}
|
|
1239
|
-
removeValueChangeListener() {
|
|
1240
|
-
this.onValueChange = undefined;
|
|
1241
|
-
this.select.removeEventListener('change', this.valueChange.bind(this));
|
|
1242
|
-
}
|
|
1243
1252
|
valueChange(ev) {
|
|
1244
1253
|
if (this.listen && this.onValueChange) {
|
|
1245
1254
|
this.onValueChange(this.getSelectedValues());
|
|
1246
1255
|
}
|
|
1247
1256
|
return true;
|
|
1248
1257
|
}
|
|
1249
|
-
|
|
1250
|
-
if (this.
|
|
1251
|
-
|
|
1252
|
-
this.onSelectChange(this.getData());
|
|
1253
|
-
this.changeListen(true);
|
|
1258
|
+
observeCall(mutations) {
|
|
1259
|
+
if (!this.listen) {
|
|
1260
|
+
return;
|
|
1254
1261
|
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
this.
|
|
1262
|
+
let classChanged = false;
|
|
1263
|
+
let disabledChanged = false;
|
|
1264
|
+
let optgroupOptionChanged = false;
|
|
1265
|
+
for (const m of mutations) {
|
|
1266
|
+
if (m.target === this.select) {
|
|
1267
|
+
if (m.attributeName === 'disabled') {
|
|
1268
|
+
disabledChanged = true;
|
|
1269
|
+
}
|
|
1270
|
+
if (m.attributeName === 'class') {
|
|
1271
|
+
classChanged = true;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
if (m.target.nodeName === 'OPTGROUP' || m.target.nodeName === 'OPTION') {
|
|
1275
|
+
optgroupOptionChanged = true;
|
|
1276
|
+
}
|
|
1260
1277
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
connectObserver() {
|
|
1264
|
-
if (this.observer) {
|
|
1265
|
-
this.observer.observe(this.select, {
|
|
1266
|
-
childList: true,
|
|
1267
|
-
});
|
|
1278
|
+
if (classChanged && this.onClassChange) {
|
|
1279
|
+
this.onClassChange(this.select.className.split(' '));
|
|
1268
1280
|
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
this.
|
|
1281
|
+
if (disabledChanged && this.onDisabledChange) {
|
|
1282
|
+
this.changeListen(false);
|
|
1283
|
+
this.onDisabledChange(this.select.disabled);
|
|
1284
|
+
this.changeListen(true);
|
|
1285
|
+
}
|
|
1286
|
+
if (optgroupOptionChanged && this.onOptionsChange) {
|
|
1287
|
+
this.changeListen(false);
|
|
1288
|
+
this.onOptionsChange(this.getData());
|
|
1289
|
+
this.changeListen(true);
|
|
1273
1290
|
}
|
|
1274
1291
|
}
|
|
1275
1292
|
getData() {
|
|
@@ -1287,7 +1304,7 @@ var SlimSelect = (function () {
|
|
|
1287
1304
|
}
|
|
1288
1305
|
getDataFromOptgroup(optgroup) {
|
|
1289
1306
|
let data = {
|
|
1290
|
-
id:
|
|
1307
|
+
id: optgroup.id,
|
|
1291
1308
|
label: optgroup.label,
|
|
1292
1309
|
selectAll: optgroup.dataset ? optgroup.dataset.selectall === 'true' : false,
|
|
1293
1310
|
closable: optgroup.dataset ? optgroup.dataset.closable : 'off',
|
|
@@ -1303,10 +1320,10 @@ var SlimSelect = (function () {
|
|
|
1303
1320
|
}
|
|
1304
1321
|
getDataFromOption(option) {
|
|
1305
1322
|
return {
|
|
1306
|
-
id:
|
|
1323
|
+
id: option.id,
|
|
1307
1324
|
value: option.value,
|
|
1308
1325
|
text: option.text,
|
|
1309
|
-
html: option.
|
|
1326
|
+
html: option.dataset && option.dataset.html ? option.dataset.html : '',
|
|
1310
1327
|
selected: option.selected,
|
|
1311
1328
|
display: option.style.display === 'none' ? false : true,
|
|
1312
1329
|
disabled: option.disabled,
|
|
@@ -1342,6 +1359,7 @@ var SlimSelect = (function () {
|
|
|
1342
1359
|
return values;
|
|
1343
1360
|
}
|
|
1344
1361
|
setSelected(value) {
|
|
1362
|
+
this.changeListen(false);
|
|
1345
1363
|
const options = this.select.childNodes;
|
|
1346
1364
|
for (const o of options) {
|
|
1347
1365
|
if (o.nodeName === 'OPTGROUP') {
|
|
@@ -1359,11 +1377,12 @@ var SlimSelect = (function () {
|
|
|
1359
1377
|
option.selected = value.includes(option.value);
|
|
1360
1378
|
}
|
|
1361
1379
|
}
|
|
1380
|
+
this.changeListen(true);
|
|
1362
1381
|
}
|
|
1363
1382
|
updateSelect(id, style, classes) {
|
|
1364
1383
|
this.changeListen(false);
|
|
1365
1384
|
if (id) {
|
|
1366
|
-
this.select.id = id;
|
|
1385
|
+
this.select.dataset.id = id;
|
|
1367
1386
|
}
|
|
1368
1387
|
if (style) {
|
|
1369
1388
|
this.select.style.cssText = style;
|
|
@@ -1411,8 +1430,12 @@ var SlimSelect = (function () {
|
|
|
1411
1430
|
}
|
|
1412
1431
|
createOption(info) {
|
|
1413
1432
|
const optionEl = document.createElement('option');
|
|
1414
|
-
optionEl.
|
|
1415
|
-
optionEl.
|
|
1433
|
+
optionEl.id = info.id;
|
|
1434
|
+
optionEl.value = info.value;
|
|
1435
|
+
optionEl.innerHTML = info.text;
|
|
1436
|
+
if (info.html !== '') {
|
|
1437
|
+
optionEl.setAttribute('data-html', info.html);
|
|
1438
|
+
}
|
|
1416
1439
|
if (info.selected) {
|
|
1417
1440
|
optionEl.selected = info.selected;
|
|
1418
1441
|
}
|
|
@@ -1442,15 +1465,19 @@ var SlimSelect = (function () {
|
|
|
1442
1465
|
}
|
|
1443
1466
|
destroy() {
|
|
1444
1467
|
this.changeListen(false);
|
|
1445
|
-
this.
|
|
1446
|
-
this.
|
|
1447
|
-
|
|
1468
|
+
this.select.removeEventListener('change', this.valueChange.bind(this));
|
|
1469
|
+
if (this.observer) {
|
|
1470
|
+
this.observer.disconnect();
|
|
1471
|
+
this.observer = null;
|
|
1472
|
+
}
|
|
1473
|
+
delete this.select.dataset.id;
|
|
1448
1474
|
this.showUI();
|
|
1449
1475
|
}
|
|
1450
1476
|
}
|
|
1451
1477
|
|
|
1452
1478
|
class SlimSelect {
|
|
1453
1479
|
constructor(config) {
|
|
1480
|
+
var _a;
|
|
1454
1481
|
this.events = {
|
|
1455
1482
|
search: undefined,
|
|
1456
1483
|
searchFilter: (opt, search) => {
|
|
@@ -1474,23 +1501,7 @@ var SlimSelect = (function () {
|
|
|
1474
1501
|
if (!this.settings.isOpen) {
|
|
1475
1502
|
return;
|
|
1476
1503
|
}
|
|
1477
|
-
|
|
1478
|
-
this.render.moveContentBelow();
|
|
1479
|
-
return;
|
|
1480
|
-
}
|
|
1481
|
-
else if (this.settings.openPosition === 'up') {
|
|
1482
|
-
this.render.moveContentAbove();
|
|
1483
|
-
return;
|
|
1484
|
-
}
|
|
1485
|
-
if (this.settings.contentPosition === 'relative') {
|
|
1486
|
-
this.render.moveContentBelow();
|
|
1487
|
-
}
|
|
1488
|
-
else if (this.render.putContent(this.render.content.main, this.settings.isOpen) === 'up') {
|
|
1489
|
-
this.render.moveContentAbove();
|
|
1490
|
-
}
|
|
1491
|
-
else {
|
|
1492
|
-
this.render.moveContentBelow();
|
|
1493
|
-
}
|
|
1504
|
+
this.render.moveContent();
|
|
1494
1505
|
});
|
|
1495
1506
|
this.documentClick = (e) => {
|
|
1496
1507
|
if (!this.settings.isOpen) {
|
|
@@ -1522,18 +1533,31 @@ var SlimSelect = (function () {
|
|
|
1522
1533
|
this.events[key] = config.events[key];
|
|
1523
1534
|
}
|
|
1524
1535
|
}
|
|
1536
|
+
this.settings.disabled = ((_a = config.settings) === null || _a === void 0 ? void 0 : _a.disabled) ? config.settings.disabled : this.selectEl.disabled;
|
|
1525
1537
|
this.settings.isMultiple = this.selectEl.multiple;
|
|
1526
1538
|
this.settings.style = this.selectEl.style.cssText;
|
|
1527
1539
|
this.settings.class = this.selectEl.className.split(' ');
|
|
1528
1540
|
this.select = new Select(this.selectEl);
|
|
1529
1541
|
this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class);
|
|
1530
1542
|
this.select.hideUI();
|
|
1531
|
-
this.select.
|
|
1532
|
-
this.setData(data);
|
|
1533
|
-
});
|
|
1534
|
-
this.select.addValueChangeListener((values) => {
|
|
1543
|
+
this.select.onValueChange = (values) => {
|
|
1535
1544
|
this.setSelected(values);
|
|
1536
|
-
}
|
|
1545
|
+
};
|
|
1546
|
+
this.select.onClassChange = (classes) => {
|
|
1547
|
+
this.settings.class = classes;
|
|
1548
|
+
this.render.updateClassStyles();
|
|
1549
|
+
};
|
|
1550
|
+
this.select.onDisabledChange = (disabled) => {
|
|
1551
|
+
if (disabled) {
|
|
1552
|
+
this.disable();
|
|
1553
|
+
}
|
|
1554
|
+
else {
|
|
1555
|
+
this.enable();
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
this.select.onOptionsChange = (data) => {
|
|
1559
|
+
this.setData(data);
|
|
1560
|
+
};
|
|
1537
1561
|
this.store = new Store(this.settings.isMultiple ? 'multiple' : 'single', config.data ? config.data : this.select.getData());
|
|
1538
1562
|
if (config.data) {
|
|
1539
1563
|
this.select.updateOptions(this.store.getData());
|
|
@@ -1559,7 +1583,7 @@ var SlimSelect = (function () {
|
|
|
1559
1583
|
if (this.settings.openPosition === 'auto') {
|
|
1560
1584
|
window.addEventListener('scroll', this.windowScroll, false);
|
|
1561
1585
|
}
|
|
1562
|
-
if (
|
|
1586
|
+
if (this.settings.disabled) {
|
|
1563
1587
|
this.disable();
|
|
1564
1588
|
}
|
|
1565
1589
|
if (this.settings.alwaysOpen) {
|
|
@@ -1568,12 +1592,12 @@ var SlimSelect = (function () {
|
|
|
1568
1592
|
this.selectEl.slim = this;
|
|
1569
1593
|
}
|
|
1570
1594
|
enable() {
|
|
1571
|
-
this.settings.
|
|
1595
|
+
this.settings.disabled = false;
|
|
1572
1596
|
this.select.enable();
|
|
1573
1597
|
this.render.enable();
|
|
1574
1598
|
}
|
|
1575
1599
|
disable() {
|
|
1576
|
-
this.settings.
|
|
1600
|
+
this.settings.disabled = true;
|
|
1577
1601
|
this.select.disable();
|
|
1578
1602
|
this.render.disable();
|
|
1579
1603
|
}
|
|
@@ -1601,14 +1625,19 @@ var SlimSelect = (function () {
|
|
|
1601
1625
|
getSelected() {
|
|
1602
1626
|
return this.store.getSelected();
|
|
1603
1627
|
}
|
|
1604
|
-
setSelected(value) {
|
|
1628
|
+
setSelected(value, runAfterChange = true) {
|
|
1605
1629
|
const selected = this.store.getSelected();
|
|
1606
1630
|
this.store.setSelectedBy('value', Array.isArray(value) ? value : [value]);
|
|
1607
1631
|
const data = this.store.getData();
|
|
1608
1632
|
this.select.updateOptions(data);
|
|
1609
1633
|
this.render.renderValues();
|
|
1610
|
-
this.render.
|
|
1611
|
-
|
|
1634
|
+
if (this.render.content.search.input.value !== '') {
|
|
1635
|
+
this.search(this.render.content.search.input.value);
|
|
1636
|
+
}
|
|
1637
|
+
else {
|
|
1638
|
+
this.render.renderOptions(data);
|
|
1639
|
+
}
|
|
1640
|
+
if (runAfterChange && this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
1612
1641
|
this.events.afterChange(this.store.getSelectedOptions());
|
|
1613
1642
|
}
|
|
1614
1643
|
}
|
|
@@ -1624,7 +1653,7 @@ var SlimSelect = (function () {
|
|
|
1624
1653
|
}
|
|
1625
1654
|
}
|
|
1626
1655
|
open() {
|
|
1627
|
-
if (
|
|
1656
|
+
if (this.settings.disabled || this.settings.isOpen) {
|
|
1628
1657
|
return;
|
|
1629
1658
|
}
|
|
1630
1659
|
if (this.events.beforeOpen) {
|
|
@@ -1640,10 +1669,12 @@ var SlimSelect = (function () {
|
|
|
1640
1669
|
}
|
|
1641
1670
|
this.settings.isOpen = true;
|
|
1642
1671
|
}, this.settings.timeoutDelay);
|
|
1643
|
-
if (this.settings.
|
|
1644
|
-
|
|
1672
|
+
if (this.settings.contentPosition === 'absolute') {
|
|
1673
|
+
if (this.settings.intervalMove) {
|
|
1674
|
+
clearInterval(this.settings.intervalMove);
|
|
1675
|
+
}
|
|
1676
|
+
this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
|
|
1645
1677
|
}
|
|
1646
|
-
this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
|
|
1647
1678
|
}
|
|
1648
1679
|
close() {
|
|
1649
1680
|
if (!this.settings.isOpen || this.settings.alwaysOpen) {
|
|
@@ -1653,7 +1684,9 @@ var SlimSelect = (function () {
|
|
|
1653
1684
|
this.events.beforeClose();
|
|
1654
1685
|
}
|
|
1655
1686
|
this.render.close();
|
|
1656
|
-
this.search
|
|
1687
|
+
if (this.render.content.search.input.value !== '') {
|
|
1688
|
+
this.search('');
|
|
1689
|
+
}
|
|
1657
1690
|
this.render.mainFocus(false);
|
|
1658
1691
|
setTimeout(() => {
|
|
1659
1692
|
if (this.events.afterClose) {
|