slim-select 2.2.2 → 2.3.0
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/render.d.ts +2 -1
- package/dist/select.d.ts +5 -11
- package/dist/settings.d.ts +3 -1
- package/dist/slimselect.cjs.js +168 -151
- package/dist/slimselect.css +1 -1
- package/dist/slimselect.css.map +1 -1
- package/dist/slimselect.es.js +168 -151
- package/dist/slimselect.global.js +168 -151
- package/dist/slimselect.js +168 -151
- package/dist/slimselect.min.js +1 -1
- package/dist/slimselect.umd.js +168 -151
- 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 +32 -31
- package/src/slim-select/render.ts +95 -52
- package/src/slim-select/select.test.ts +143 -23
- package/src/slim-select/select.ts +93 -89
- 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/slim-select/store.ts +19 -16
- package/src/vue/dist/slim-select/render.d.ts +2 -1
- package/src/vue/dist/slim-select/select.d.ts +5 -11
- package/src/vue/dist/slim-select/settings.d.ts +3 -1
- package/src/vue/dist/slimselectvue.es.js +187 -164
- package/src/vue/dist/slimselectvue.global.js +187 -164
- package/src/vue/dist/slimselectvue.ssr.js +187 -164
- package/src/vue/dist/vue/slimselect.vue.d.ts +17 -15
- 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
|
|
|
@@ -271,23 +273,21 @@
|
|
|
271
273
|
const dataSearch = [];
|
|
272
274
|
this.data.forEach((dataObj) => {
|
|
273
275
|
if (dataObj instanceof Optgroup) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
276
|
+
let optOptions = [];
|
|
277
|
+
dataObj.options.forEach((option) => {
|
|
278
|
+
if (!filter || filter(option)) {
|
|
279
|
+
if (!includeOptgroup) {
|
|
280
|
+
dataSearch.push(new Option(option));
|
|
278
281
|
}
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
let optOptions = [];
|
|
283
|
-
dataObj.options.forEach((option) => {
|
|
284
|
-
if (!filter || filter(option)) {
|
|
282
|
+
else {
|
|
285
283
|
optOptions.push(new Option(option));
|
|
286
284
|
}
|
|
287
|
-
});
|
|
288
|
-
if (optOptions.length > 0) {
|
|
289
|
-
dataSearch.push(new Optgroup(dataObj));
|
|
290
285
|
}
|
|
286
|
+
});
|
|
287
|
+
if (optOptions.length > 0) {
|
|
288
|
+
let optgroup = new Optgroup(dataObj);
|
|
289
|
+
optgroup.options = optOptions;
|
|
290
|
+
dataSearch.push(optgroup);
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
if (dataObj instanceof Option) {
|
|
@@ -307,6 +307,7 @@
|
|
|
307
307
|
placeholder: 'ss-placeholder',
|
|
308
308
|
values: 'ss-values',
|
|
309
309
|
single: 'ss-single',
|
|
310
|
+
max: 'ss-max',
|
|
310
311
|
value: 'ss-value',
|
|
311
312
|
valueText: 'ss-value-text',
|
|
312
313
|
valueDelete: 'ss-value-delete',
|
|
@@ -363,23 +364,7 @@
|
|
|
363
364
|
this.main.main.classList.add(this.settings.openPosition === 'up' ? this.classes.openAbove : this.classes.openBelow);
|
|
364
365
|
this.moveContent();
|
|
365
366
|
this.renderOptions(this.store.getData());
|
|
366
|
-
|
|
367
|
-
this.moveContentBelow();
|
|
368
|
-
}
|
|
369
|
-
else if (this.settings.openPosition.toLowerCase() === 'up') {
|
|
370
|
-
this.moveContentAbove();
|
|
371
|
-
}
|
|
372
|
-
else if (this.settings.openPosition.toLowerCase() === 'down') {
|
|
373
|
-
this.moveContentBelow();
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
if (this.putContent(this.content.main, this.settings.isOpen) === 'up') {
|
|
377
|
-
this.moveContentAbove();
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
this.moveContentBelow();
|
|
381
|
-
}
|
|
382
|
-
}
|
|
367
|
+
this.moveContent();
|
|
383
368
|
const selectedOptions = this.store.getSelectedOptions();
|
|
384
369
|
if (selectedOptions.length) {
|
|
385
370
|
const selectedId = selectedOptions[selectedOptions.length - 1].id;
|
|
@@ -437,7 +422,7 @@
|
|
|
437
422
|
}
|
|
438
423
|
};
|
|
439
424
|
main.onclick = (e) => {
|
|
440
|
-
if (
|
|
425
|
+
if (this.settings.disabled) {
|
|
441
426
|
return;
|
|
442
427
|
}
|
|
443
428
|
this.settings.isOpen ? this.callbacks.close() : this.callbacks.open();
|
|
@@ -452,7 +437,7 @@
|
|
|
452
437
|
}
|
|
453
438
|
deselect.onclick = (e) => {
|
|
454
439
|
e.stopPropagation();
|
|
455
|
-
if (
|
|
440
|
+
if (this.settings.disabled) {
|
|
456
441
|
return;
|
|
457
442
|
}
|
|
458
443
|
let shouldDelete = true;
|
|
@@ -568,6 +553,19 @@
|
|
|
568
553
|
placeholder.remove();
|
|
569
554
|
}
|
|
570
555
|
}
|
|
556
|
+
if (selectedOptions.length > this.settings.maxValuesShown) {
|
|
557
|
+
const singleValue = document.createElement('div');
|
|
558
|
+
singleValue.classList.add(this.classes.max);
|
|
559
|
+
singleValue.textContent = this.settings.maxValuesMessage.replace('{number}', selectedOptions.length.toString());
|
|
560
|
+
this.main.values.innerHTML = singleValue.outerHTML;
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
const maxValuesMessage = this.main.values.querySelector('.' + this.classes.max);
|
|
565
|
+
if (maxValuesMessage) {
|
|
566
|
+
maxValuesMessage.remove();
|
|
567
|
+
}
|
|
568
|
+
}
|
|
571
569
|
let removeNodes = [];
|
|
572
570
|
for (let i = 0; i < currentNodes.length; i++) {
|
|
573
571
|
const node = currentNodes[i];
|
|
@@ -622,6 +620,9 @@
|
|
|
622
620
|
deleteDiv.onclick = (e) => {
|
|
623
621
|
e.preventDefault();
|
|
624
622
|
e.stopPropagation();
|
|
623
|
+
if (this.settings.disabled) {
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
625
626
|
let shouldDelete = true;
|
|
626
627
|
const before = this.store.getSelectedOptions();
|
|
627
628
|
const after = before.filter((o) => {
|
|
@@ -693,12 +694,23 @@
|
|
|
693
694
|
}
|
|
694
695
|
moveContent() {
|
|
695
696
|
if (this.settings.contentPosition === 'relative') {
|
|
697
|
+
this.moveContentBelow();
|
|
696
698
|
return;
|
|
697
699
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
700
|
+
if (this.settings.openPosition === 'down') {
|
|
701
|
+
this.moveContentBelow();
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
else if (this.settings.openPosition === 'up') {
|
|
705
|
+
this.moveContentAbove();
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
if (this.putContent() === 'up') {
|
|
709
|
+
this.moveContentAbove();
|
|
710
|
+
}
|
|
711
|
+
else {
|
|
712
|
+
this.moveContentBelow();
|
|
713
|
+
}
|
|
702
714
|
}
|
|
703
715
|
searchDiv() {
|
|
704
716
|
const main = document.createElement('div');
|
|
@@ -909,8 +921,7 @@
|
|
|
909
921
|
this.content.list.innerHTML = '';
|
|
910
922
|
if (data.length === 0) {
|
|
911
923
|
const noResults = document.createElement('div');
|
|
912
|
-
noResults.classList.add(this.classes.
|
|
913
|
-
noResults.classList.add(this.classes.disabled);
|
|
924
|
+
noResults.classList.add(this.classes.search);
|
|
914
925
|
noResults.innerHTML = this.settings.searchText;
|
|
915
926
|
this.content.list.appendChild(noResults);
|
|
916
927
|
return;
|
|
@@ -986,7 +997,7 @@
|
|
|
986
997
|
optgroupClosable.appendChild(optgroupClosableSvg);
|
|
987
998
|
const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
988
999
|
optgroupClosableSvg.appendChild(optgroupClosableArrow);
|
|
989
|
-
if (d.options.some((o) => o.selected)) {
|
|
1000
|
+
if (d.options.some((o) => o.selected) || this.content.search.input.value.trim() !== '') {
|
|
990
1001
|
optgroupClosable.classList.add(this.classes.open);
|
|
991
1002
|
optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
|
|
992
1003
|
}
|
|
@@ -1045,8 +1056,7 @@
|
|
|
1045
1056
|
optionEl.style.cssText = option.style;
|
|
1046
1057
|
}
|
|
1047
1058
|
if (this.settings.searchHighlight && this.content.search.input.value.trim() !== '') {
|
|
1048
|
-
|
|
1049
|
-
optionEl.innerHTML = this.highlightText(textOrHtml, this.content.search.input.value, this.classes.searchHighlighter);
|
|
1059
|
+
optionEl.innerHTML = this.highlightText(option.html !== '' ? option.html : option.text, this.content.search.input.value, this.classes.searchHighlighter);
|
|
1050
1060
|
}
|
|
1051
1061
|
else if (option.html !== '') {
|
|
1052
1062
|
optionEl.innerHTML = option.html;
|
|
@@ -1057,7 +1067,7 @@
|
|
|
1057
1067
|
if (this.settings.showOptionTooltips && optionEl.textContent) {
|
|
1058
1068
|
optionEl.setAttribute('title', optionEl.textContent);
|
|
1059
1069
|
}
|
|
1060
|
-
if (
|
|
1070
|
+
if (option.disabled) {
|
|
1061
1071
|
optionEl.classList.add(this.classes.disabled);
|
|
1062
1072
|
}
|
|
1063
1073
|
if (option.selected && this.settings.hideSelected) {
|
|
@@ -1078,9 +1088,8 @@
|
|
|
1078
1088
|
if (option.disabled || (option.selected && !this.settings.allowDeselect)) {
|
|
1079
1089
|
return;
|
|
1080
1090
|
}
|
|
1081
|
-
if (this.settings.isMultiple &&
|
|
1082
|
-
|
|
1083
|
-
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)) {
|
|
1084
1093
|
return;
|
|
1085
1094
|
}
|
|
1086
1095
|
let shouldUpdate = false;
|
|
@@ -1145,23 +1154,30 @@
|
|
|
1145
1154
|
return completedString;
|
|
1146
1155
|
}
|
|
1147
1156
|
moveContentAbove() {
|
|
1148
|
-
|
|
1157
|
+
const mainHeight = this.main.main.offsetHeight;
|
|
1149
1158
|
const contentHeight = this.content.main.offsetHeight;
|
|
1150
|
-
const height = mainHeight + contentHeight - 1;
|
|
1151
|
-
this.content.main.style.margin = '-' + height + 'px 0px 0px 0px';
|
|
1152
|
-
this.content.main.style.transformOrigin = 'center bottom';
|
|
1153
1159
|
this.main.main.classList.remove(this.classes.openBelow);
|
|
1154
1160
|
this.main.main.classList.add(this.classes.openAbove);
|
|
1155
1161
|
this.content.main.classList.remove(this.classes.openBelow);
|
|
1156
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';
|
|
1157
1168
|
}
|
|
1158
1169
|
moveContentBelow() {
|
|
1159
|
-
this.content.main.style.margin = '-1px 0px 0px 0px';
|
|
1160
|
-
this.content.main.style.transformOrigin = 'center top';
|
|
1161
1170
|
this.main.main.classList.remove(this.classes.openAbove);
|
|
1162
1171
|
this.main.main.classList.add(this.classes.openBelow);
|
|
1163
1172
|
this.content.main.classList.remove(this.classes.openAbove);
|
|
1164
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
|
+
}
|
|
1165
1181
|
}
|
|
1166
1182
|
ensureElementInView(container, element) {
|
|
1167
1183
|
const cTop = container.scrollTop + container.offsetTop;
|
|
@@ -1175,16 +1191,18 @@
|
|
|
1175
1191
|
container.scrollTop += eBottom - cBottom;
|
|
1176
1192
|
}
|
|
1177
1193
|
}
|
|
1178
|
-
putContent(
|
|
1179
|
-
const
|
|
1180
|
-
const
|
|
1181
|
-
const
|
|
1182
|
-
const
|
|
1183
|
-
if (
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
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
|
+
}
|
|
1188
1206
|
}
|
|
1189
1207
|
return 'down';
|
|
1190
1208
|
}
|
|
@@ -1195,16 +1213,17 @@
|
|
|
1195
1213
|
this.listen = false;
|
|
1196
1214
|
this.observer = null;
|
|
1197
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);
|
|
1198
1221
|
}
|
|
1199
1222
|
enable() {
|
|
1200
|
-
this.disconnectObserver();
|
|
1201
1223
|
this.select.disabled = false;
|
|
1202
|
-
this.connectObserver();
|
|
1203
1224
|
}
|
|
1204
1225
|
disable() {
|
|
1205
|
-
this.disconnectObserver();
|
|
1206
1226
|
this.select.disabled = true;
|
|
1207
|
-
this.connectObserver();
|
|
1208
1227
|
}
|
|
1209
1228
|
hideUI() {
|
|
1210
1229
|
this.select.tabIndex = -1;
|
|
@@ -1216,65 +1235,54 @@
|
|
|
1216
1235
|
this.select.style.display = '';
|
|
1217
1236
|
this.select.removeAttribute('aria-hidden');
|
|
1218
1237
|
}
|
|
1219
|
-
changeListen(
|
|
1220
|
-
this.listen =
|
|
1221
|
-
if (
|
|
1222
|
-
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
|
+
}
|
|
1223
1248
|
}
|
|
1224
|
-
|
|
1225
|
-
this.
|
|
1249
|
+
if (!listen) {
|
|
1250
|
+
if (this.observer) {
|
|
1251
|
+
this.observer.disconnect();
|
|
1252
|
+
}
|
|
1226
1253
|
}
|
|
1227
1254
|
}
|
|
1228
|
-
addSelectChangeListener(func) {
|
|
1229
|
-
this.onSelectChange = func;
|
|
1230
|
-
this.addObserver();
|
|
1231
|
-
this.connectObserver();
|
|
1232
|
-
this.changeListen(true);
|
|
1233
|
-
}
|
|
1234
|
-
removeSelectChangeListener() {
|
|
1235
|
-
this.changeListen(false);
|
|
1236
|
-
this.onSelectChange = undefined;
|
|
1237
|
-
}
|
|
1238
|
-
addValueChangeListener(func) {
|
|
1239
|
-
this.onValueChange = func;
|
|
1240
|
-
this.select.addEventListener('change', this.valueChange.bind(this), {
|
|
1241
|
-
passive: true,
|
|
1242
|
-
});
|
|
1243
|
-
}
|
|
1244
|
-
removeValueChangeListener() {
|
|
1245
|
-
this.onValueChange = undefined;
|
|
1246
|
-
this.select.removeEventListener('change', this.valueChange.bind(this));
|
|
1247
|
-
}
|
|
1248
1255
|
valueChange(ev) {
|
|
1249
1256
|
if (this.listen && this.onValueChange) {
|
|
1250
1257
|
this.onValueChange(this.getSelectedValues());
|
|
1251
1258
|
}
|
|
1252
1259
|
return true;
|
|
1253
1260
|
}
|
|
1254
|
-
|
|
1255
|
-
if (this.
|
|
1256
|
-
|
|
1257
|
-
this.onSelectChange(this.getData());
|
|
1258
|
-
this.changeListen(true);
|
|
1261
|
+
observeCall(mutations) {
|
|
1262
|
+
if (!this.listen) {
|
|
1263
|
+
return;
|
|
1259
1264
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
this.
|
|
1264
|
-
|
|
1265
|
+
let disabledChanged = false;
|
|
1266
|
+
let optgroupOptionChanged = false;
|
|
1267
|
+
for (const m of mutations) {
|
|
1268
|
+
if (m.target === this.select) {
|
|
1269
|
+
if (m.attributeName === 'disabled') {
|
|
1270
|
+
disabledChanged = true;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
if (m.target.nodeName === 'OPTGROUP' || m.target.nodeName === 'OPTION') {
|
|
1274
|
+
optgroupOptionChanged = true;
|
|
1275
|
+
}
|
|
1265
1276
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
this.observer.observe(this.select, {
|
|
1271
|
-
childList: true,
|
|
1272
|
-
});
|
|
1277
|
+
if (disabledChanged && this.onDisabledChange) {
|
|
1278
|
+
this.changeListen(false);
|
|
1279
|
+
this.onDisabledChange(this.select.disabled);
|
|
1280
|
+
this.changeListen(true);
|
|
1273
1281
|
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
this.
|
|
1282
|
+
if (optgroupOptionChanged && this.onOptionsChange) {
|
|
1283
|
+
this.changeListen(false);
|
|
1284
|
+
this.onOptionsChange(this.getData());
|
|
1285
|
+
this.changeListen(true);
|
|
1278
1286
|
}
|
|
1279
1287
|
}
|
|
1280
1288
|
getData() {
|
|
@@ -1292,7 +1300,7 @@
|
|
|
1292
1300
|
}
|
|
1293
1301
|
getDataFromOptgroup(optgroup) {
|
|
1294
1302
|
let data = {
|
|
1295
|
-
id:
|
|
1303
|
+
id: optgroup.id,
|
|
1296
1304
|
label: optgroup.label,
|
|
1297
1305
|
selectAll: optgroup.dataset ? optgroup.dataset.selectall === 'true' : false,
|
|
1298
1306
|
closable: optgroup.dataset ? optgroup.dataset.closable : 'off',
|
|
@@ -1308,10 +1316,10 @@
|
|
|
1308
1316
|
}
|
|
1309
1317
|
getDataFromOption(option) {
|
|
1310
1318
|
return {
|
|
1311
|
-
id:
|
|
1319
|
+
id: option.id,
|
|
1312
1320
|
value: option.value,
|
|
1313
1321
|
text: option.text,
|
|
1314
|
-
html: option.
|
|
1322
|
+
html: option.dataset && option.dataset.html ? option.dataset.html : '',
|
|
1315
1323
|
selected: option.selected,
|
|
1316
1324
|
display: option.style.display === 'none' ? false : true,
|
|
1317
1325
|
disabled: option.disabled,
|
|
@@ -1347,6 +1355,7 @@
|
|
|
1347
1355
|
return values;
|
|
1348
1356
|
}
|
|
1349
1357
|
setSelected(value) {
|
|
1358
|
+
this.changeListen(false);
|
|
1350
1359
|
const options = this.select.childNodes;
|
|
1351
1360
|
for (const o of options) {
|
|
1352
1361
|
if (o.nodeName === 'OPTGROUP') {
|
|
@@ -1364,6 +1373,7 @@
|
|
|
1364
1373
|
option.selected = value.includes(option.value);
|
|
1365
1374
|
}
|
|
1366
1375
|
}
|
|
1376
|
+
this.changeListen(true);
|
|
1367
1377
|
}
|
|
1368
1378
|
updateSelect(id, style, classes) {
|
|
1369
1379
|
this.changeListen(false);
|
|
@@ -1416,8 +1426,12 @@
|
|
|
1416
1426
|
}
|
|
1417
1427
|
createOption(info) {
|
|
1418
1428
|
const optionEl = document.createElement('option');
|
|
1419
|
-
optionEl.
|
|
1420
|
-
optionEl.
|
|
1429
|
+
optionEl.id = info.id;
|
|
1430
|
+
optionEl.value = info.value;
|
|
1431
|
+
optionEl.innerHTML = info.text;
|
|
1432
|
+
if (info.html !== '') {
|
|
1433
|
+
optionEl.setAttribute('data-html', info.html);
|
|
1434
|
+
}
|
|
1421
1435
|
if (info.selected) {
|
|
1422
1436
|
optionEl.selected = info.selected;
|
|
1423
1437
|
}
|
|
@@ -1447,15 +1461,18 @@
|
|
|
1447
1461
|
}
|
|
1448
1462
|
destroy() {
|
|
1449
1463
|
this.changeListen(false);
|
|
1450
|
-
this.
|
|
1451
|
-
this.
|
|
1452
|
-
|
|
1464
|
+
this.select.removeEventListener('change', this.valueChange.bind(this));
|
|
1465
|
+
if (this.observer) {
|
|
1466
|
+
this.observer.disconnect();
|
|
1467
|
+
this.observer = null;
|
|
1468
|
+
}
|
|
1453
1469
|
this.showUI();
|
|
1454
1470
|
}
|
|
1455
1471
|
}
|
|
1456
1472
|
|
|
1457
1473
|
class SlimSelect {
|
|
1458
1474
|
constructor(config) {
|
|
1475
|
+
var _a;
|
|
1459
1476
|
this.events = {
|
|
1460
1477
|
search: undefined,
|
|
1461
1478
|
searchFilter: (opt, search) => {
|
|
@@ -1479,23 +1496,7 @@
|
|
|
1479
1496
|
if (!this.settings.isOpen) {
|
|
1480
1497
|
return;
|
|
1481
1498
|
}
|
|
1482
|
-
|
|
1483
|
-
this.render.moveContentBelow();
|
|
1484
|
-
return;
|
|
1485
|
-
}
|
|
1486
|
-
else if (this.settings.openPosition === 'up') {
|
|
1487
|
-
this.render.moveContentAbove();
|
|
1488
|
-
return;
|
|
1489
|
-
}
|
|
1490
|
-
if (this.settings.contentPosition === 'relative') {
|
|
1491
|
-
this.render.moveContentBelow();
|
|
1492
|
-
}
|
|
1493
|
-
else if (this.render.putContent(this.render.content.main, this.settings.isOpen) === 'up') {
|
|
1494
|
-
this.render.moveContentAbove();
|
|
1495
|
-
}
|
|
1496
|
-
else {
|
|
1497
|
-
this.render.moveContentBelow();
|
|
1498
|
-
}
|
|
1499
|
+
this.render.moveContent();
|
|
1499
1500
|
});
|
|
1500
1501
|
this.documentClick = (e) => {
|
|
1501
1502
|
if (!this.settings.isOpen) {
|
|
@@ -1527,18 +1528,27 @@
|
|
|
1527
1528
|
this.events[key] = config.events[key];
|
|
1528
1529
|
}
|
|
1529
1530
|
}
|
|
1531
|
+
this.settings.disabled = ((_a = config.settings) === null || _a === void 0 ? void 0 : _a.disabled) ? config.settings.disabled : this.selectEl.disabled;
|
|
1530
1532
|
this.settings.isMultiple = this.selectEl.multiple;
|
|
1531
1533
|
this.settings.style = this.selectEl.style.cssText;
|
|
1532
1534
|
this.settings.class = this.selectEl.className.split(' ');
|
|
1533
1535
|
this.select = new Select(this.selectEl);
|
|
1534
1536
|
this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class);
|
|
1535
1537
|
this.select.hideUI();
|
|
1536
|
-
this.select.
|
|
1537
|
-
this.setData(data);
|
|
1538
|
-
});
|
|
1539
|
-
this.select.addValueChangeListener((values) => {
|
|
1538
|
+
this.select.onValueChange = (values) => {
|
|
1540
1539
|
this.setSelected(values);
|
|
1541
|
-
}
|
|
1540
|
+
};
|
|
1541
|
+
this.select.onDisabledChange = (disabled) => {
|
|
1542
|
+
if (disabled) {
|
|
1543
|
+
this.disable();
|
|
1544
|
+
}
|
|
1545
|
+
else {
|
|
1546
|
+
this.enable();
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
this.select.onOptionsChange = (data) => {
|
|
1550
|
+
this.setData(data);
|
|
1551
|
+
};
|
|
1542
1552
|
this.store = new Store(this.settings.isMultiple ? 'multiple' : 'single', config.data ? config.data : this.select.getData());
|
|
1543
1553
|
if (config.data) {
|
|
1544
1554
|
this.select.updateOptions(this.store.getData());
|
|
@@ -1564,7 +1574,7 @@
|
|
|
1564
1574
|
if (this.settings.openPosition === 'auto') {
|
|
1565
1575
|
window.addEventListener('scroll', this.windowScroll, false);
|
|
1566
1576
|
}
|
|
1567
|
-
if (
|
|
1577
|
+
if (this.settings.disabled) {
|
|
1568
1578
|
this.disable();
|
|
1569
1579
|
}
|
|
1570
1580
|
if (this.settings.alwaysOpen) {
|
|
@@ -1573,12 +1583,12 @@
|
|
|
1573
1583
|
this.selectEl.slim = this;
|
|
1574
1584
|
}
|
|
1575
1585
|
enable() {
|
|
1576
|
-
this.settings.
|
|
1586
|
+
this.settings.disabled = false;
|
|
1577
1587
|
this.select.enable();
|
|
1578
1588
|
this.render.enable();
|
|
1579
1589
|
}
|
|
1580
1590
|
disable() {
|
|
1581
|
-
this.settings.
|
|
1591
|
+
this.settings.disabled = true;
|
|
1582
1592
|
this.select.disable();
|
|
1583
1593
|
this.render.disable();
|
|
1584
1594
|
}
|
|
@@ -1612,7 +1622,12 @@
|
|
|
1612
1622
|
const data = this.store.getData();
|
|
1613
1623
|
this.select.updateOptions(data);
|
|
1614
1624
|
this.render.renderValues();
|
|
1615
|
-
this.render.
|
|
1625
|
+
if (this.render.content.search.input.value !== '') {
|
|
1626
|
+
this.search(this.render.content.search.input.value);
|
|
1627
|
+
}
|
|
1628
|
+
else {
|
|
1629
|
+
this.render.renderOptions(data);
|
|
1630
|
+
}
|
|
1616
1631
|
if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
1617
1632
|
this.events.afterChange(this.store.getSelectedOptions());
|
|
1618
1633
|
}
|
|
@@ -1629,7 +1644,7 @@
|
|
|
1629
1644
|
}
|
|
1630
1645
|
}
|
|
1631
1646
|
open() {
|
|
1632
|
-
if (
|
|
1647
|
+
if (this.settings.disabled || this.settings.isOpen) {
|
|
1633
1648
|
return;
|
|
1634
1649
|
}
|
|
1635
1650
|
if (this.events.beforeOpen) {
|
|
@@ -1645,10 +1660,12 @@
|
|
|
1645
1660
|
}
|
|
1646
1661
|
this.settings.isOpen = true;
|
|
1647
1662
|
}, this.settings.timeoutDelay);
|
|
1648
|
-
if (this.settings.
|
|
1649
|
-
|
|
1663
|
+
if (this.settings.contentPosition === 'absolute') {
|
|
1664
|
+
if (this.settings.intervalMove) {
|
|
1665
|
+
clearInterval(this.settings.intervalMove);
|
|
1666
|
+
}
|
|
1667
|
+
this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
|
|
1650
1668
|
}
|
|
1651
|
-
this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
|
|
1652
1669
|
}
|
|
1653
1670
|
close() {
|
|
1654
1671
|
if (!this.settings.isOpen || this.settings.alwaysOpen) {
|