slim-select 2.2.3 → 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 +157 -138
- package/dist/slimselect.css +1 -1
- package/dist/slimselect.css.map +1 -1
- package/dist/slimselect.es.js +157 -138
- package/dist/slimselect.global.js +157 -138
- package/dist/slimselect.js +157 -138
- package/dist/slimselect.min.js +1 -1
- package/dist/slimselect.umd.js +157 -138
- 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/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 +176 -151
- package/src/vue/dist/slimselectvue.global.js +176 -151
- package/src/vue/dist/slimselectvue.ssr.js +176 -151
- 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
|
@@ -69,7 +69,7 @@ class Settings {
|
|
|
69
69
|
this.id = 'ss-' + generateID();
|
|
70
70
|
this.style = settings.style || '';
|
|
71
71
|
this.class = settings.class || [];
|
|
72
|
-
this.
|
|
72
|
+
this.disabled = settings.disabled !== undefined ? settings.disabled : false;
|
|
73
73
|
this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
|
|
74
74
|
this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
|
|
75
75
|
this.searchPlaceholder = settings.searchPlaceholder || 'Search';
|
|
@@ -87,6 +87,8 @@ class Settings {
|
|
|
87
87
|
this.minSelected = settings.minSelected || 0;
|
|
88
88
|
this.maxSelected = settings.maxSelected || 1000;
|
|
89
89
|
this.timeoutDelay = settings.timeoutDelay || 200;
|
|
90
|
+
this.maxValuesShown = settings.maxValuesShown || 20;
|
|
91
|
+
this.maxValuesMessage = settings.maxValuesMessage || '{number} selected';
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
|
|
@@ -303,6 +305,7 @@ class Render {
|
|
|
303
305
|
placeholder: 'ss-placeholder',
|
|
304
306
|
values: 'ss-values',
|
|
305
307
|
single: 'ss-single',
|
|
308
|
+
max: 'ss-max',
|
|
306
309
|
value: 'ss-value',
|
|
307
310
|
valueText: 'ss-value-text',
|
|
308
311
|
valueDelete: 'ss-value-delete',
|
|
@@ -359,23 +362,7 @@ class Render {
|
|
|
359
362
|
this.main.main.classList.add(this.settings.openPosition === 'up' ? this.classes.openAbove : this.classes.openBelow);
|
|
360
363
|
this.moveContent();
|
|
361
364
|
this.renderOptions(this.store.getData());
|
|
362
|
-
|
|
363
|
-
this.moveContentBelow();
|
|
364
|
-
}
|
|
365
|
-
else if (this.settings.openPosition.toLowerCase() === 'up') {
|
|
366
|
-
this.moveContentAbove();
|
|
367
|
-
}
|
|
368
|
-
else if (this.settings.openPosition.toLowerCase() === 'down') {
|
|
369
|
-
this.moveContentBelow();
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
if (this.putContent(this.content.main, this.settings.isOpen) === 'up') {
|
|
373
|
-
this.moveContentAbove();
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
this.moveContentBelow();
|
|
377
|
-
}
|
|
378
|
-
}
|
|
365
|
+
this.moveContent();
|
|
379
366
|
const selectedOptions = this.store.getSelectedOptions();
|
|
380
367
|
if (selectedOptions.length) {
|
|
381
368
|
const selectedId = selectedOptions[selectedOptions.length - 1].id;
|
|
@@ -433,7 +420,7 @@ class Render {
|
|
|
433
420
|
}
|
|
434
421
|
};
|
|
435
422
|
main.onclick = (e) => {
|
|
436
|
-
if (
|
|
423
|
+
if (this.settings.disabled) {
|
|
437
424
|
return;
|
|
438
425
|
}
|
|
439
426
|
this.settings.isOpen ? this.callbacks.close() : this.callbacks.open();
|
|
@@ -448,7 +435,7 @@ class Render {
|
|
|
448
435
|
}
|
|
449
436
|
deselect.onclick = (e) => {
|
|
450
437
|
e.stopPropagation();
|
|
451
|
-
if (
|
|
438
|
+
if (this.settings.disabled) {
|
|
452
439
|
return;
|
|
453
440
|
}
|
|
454
441
|
let shouldDelete = true;
|
|
@@ -564,6 +551,19 @@ class Render {
|
|
|
564
551
|
placeholder.remove();
|
|
565
552
|
}
|
|
566
553
|
}
|
|
554
|
+
if (selectedOptions.length > this.settings.maxValuesShown) {
|
|
555
|
+
const singleValue = document.createElement('div');
|
|
556
|
+
singleValue.classList.add(this.classes.max);
|
|
557
|
+
singleValue.textContent = this.settings.maxValuesMessage.replace('{number}', selectedOptions.length.toString());
|
|
558
|
+
this.main.values.innerHTML = singleValue.outerHTML;
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
const maxValuesMessage = this.main.values.querySelector('.' + this.classes.max);
|
|
563
|
+
if (maxValuesMessage) {
|
|
564
|
+
maxValuesMessage.remove();
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
567
|
let removeNodes = [];
|
|
568
568
|
for (let i = 0; i < currentNodes.length; i++) {
|
|
569
569
|
const node = currentNodes[i];
|
|
@@ -618,6 +618,9 @@ class Render {
|
|
|
618
618
|
deleteDiv.onclick = (e) => {
|
|
619
619
|
e.preventDefault();
|
|
620
620
|
e.stopPropagation();
|
|
621
|
+
if (this.settings.disabled) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
621
624
|
let shouldDelete = true;
|
|
622
625
|
const before = this.store.getSelectedOptions();
|
|
623
626
|
const after = before.filter((o) => {
|
|
@@ -689,12 +692,23 @@ class Render {
|
|
|
689
692
|
}
|
|
690
693
|
moveContent() {
|
|
691
694
|
if (this.settings.contentPosition === 'relative') {
|
|
695
|
+
this.moveContentBelow();
|
|
692
696
|
return;
|
|
693
697
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
+
if (this.settings.openPosition === 'down') {
|
|
699
|
+
this.moveContentBelow();
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
else if (this.settings.openPosition === 'up') {
|
|
703
|
+
this.moveContentAbove();
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
if (this.putContent() === 'up') {
|
|
707
|
+
this.moveContentAbove();
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
this.moveContentBelow();
|
|
711
|
+
}
|
|
698
712
|
}
|
|
699
713
|
searchDiv() {
|
|
700
714
|
const main = document.createElement('div');
|
|
@@ -905,8 +919,7 @@ class Render {
|
|
|
905
919
|
this.content.list.innerHTML = '';
|
|
906
920
|
if (data.length === 0) {
|
|
907
921
|
const noResults = document.createElement('div');
|
|
908
|
-
noResults.classList.add(this.classes.
|
|
909
|
-
noResults.classList.add(this.classes.disabled);
|
|
922
|
+
noResults.classList.add(this.classes.search);
|
|
910
923
|
noResults.innerHTML = this.settings.searchText;
|
|
911
924
|
this.content.list.appendChild(noResults);
|
|
912
925
|
return;
|
|
@@ -982,7 +995,7 @@ class Render {
|
|
|
982
995
|
optgroupClosable.appendChild(optgroupClosableSvg);
|
|
983
996
|
const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
984
997
|
optgroupClosableSvg.appendChild(optgroupClosableArrow);
|
|
985
|
-
if (d.options.some((o) => o.selected)) {
|
|
998
|
+
if (d.options.some((o) => o.selected) || this.content.search.input.value.trim() !== '') {
|
|
986
999
|
optgroupClosable.classList.add(this.classes.open);
|
|
987
1000
|
optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
|
|
988
1001
|
}
|
|
@@ -1041,8 +1054,7 @@ class Render {
|
|
|
1041
1054
|
optionEl.style.cssText = option.style;
|
|
1042
1055
|
}
|
|
1043
1056
|
if (this.settings.searchHighlight && this.content.search.input.value.trim() !== '') {
|
|
1044
|
-
|
|
1045
|
-
optionEl.innerHTML = this.highlightText(textOrHtml, this.content.search.input.value, this.classes.searchHighlighter);
|
|
1057
|
+
optionEl.innerHTML = this.highlightText(option.html !== '' ? option.html : option.text, this.content.search.input.value, this.classes.searchHighlighter);
|
|
1046
1058
|
}
|
|
1047
1059
|
else if (option.html !== '') {
|
|
1048
1060
|
optionEl.innerHTML = option.html;
|
|
@@ -1053,7 +1065,7 @@ class Render {
|
|
|
1053
1065
|
if (this.settings.showOptionTooltips && optionEl.textContent) {
|
|
1054
1066
|
optionEl.setAttribute('title', optionEl.textContent);
|
|
1055
1067
|
}
|
|
1056
|
-
if (
|
|
1068
|
+
if (option.disabled) {
|
|
1057
1069
|
optionEl.classList.add(this.classes.disabled);
|
|
1058
1070
|
}
|
|
1059
1071
|
if (option.selected && this.settings.hideSelected) {
|
|
@@ -1074,9 +1086,8 @@ class Render {
|
|
|
1074
1086
|
if (option.disabled || (option.selected && !this.settings.allowDeselect)) {
|
|
1075
1087
|
return;
|
|
1076
1088
|
}
|
|
1077
|
-
if (this.settings.isMultiple &&
|
|
1078
|
-
|
|
1079
|
-
this.settings.maxSelected <= selectedOptions.length) {
|
|
1089
|
+
if ((this.settings.isMultiple && this.settings.maxSelected <= selectedOptions.length && !option.selected) ||
|
|
1090
|
+
(this.settings.isMultiple && this.settings.minSelected >= selectedOptions.length && option.selected)) {
|
|
1080
1091
|
return;
|
|
1081
1092
|
}
|
|
1082
1093
|
let shouldUpdate = false;
|
|
@@ -1141,23 +1152,30 @@ class Render {
|
|
|
1141
1152
|
return completedString;
|
|
1142
1153
|
}
|
|
1143
1154
|
moveContentAbove() {
|
|
1144
|
-
|
|
1155
|
+
const mainHeight = this.main.main.offsetHeight;
|
|
1145
1156
|
const contentHeight = this.content.main.offsetHeight;
|
|
1146
|
-
const height = mainHeight + contentHeight - 1;
|
|
1147
|
-
this.content.main.style.margin = '-' + height + 'px 0px 0px 0px';
|
|
1148
|
-
this.content.main.style.transformOrigin = 'center bottom';
|
|
1149
1157
|
this.main.main.classList.remove(this.classes.openBelow);
|
|
1150
1158
|
this.main.main.classList.add(this.classes.openAbove);
|
|
1151
1159
|
this.content.main.classList.remove(this.classes.openBelow);
|
|
1152
1160
|
this.content.main.classList.add(this.classes.openAbove);
|
|
1161
|
+
const containerRect = this.main.main.getBoundingClientRect();
|
|
1162
|
+
this.content.main.style.margin = '-' + (mainHeight + contentHeight - 1) + 'px 0px 0px 0px';
|
|
1163
|
+
this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
|
|
1164
|
+
this.content.main.style.left = containerRect.left + window.scrollX + 'px';
|
|
1165
|
+
this.content.main.style.width = containerRect.width + 'px';
|
|
1153
1166
|
}
|
|
1154
1167
|
moveContentBelow() {
|
|
1155
|
-
this.content.main.style.margin = '-1px 0px 0px 0px';
|
|
1156
|
-
this.content.main.style.transformOrigin = 'center top';
|
|
1157
1168
|
this.main.main.classList.remove(this.classes.openAbove);
|
|
1158
1169
|
this.main.main.classList.add(this.classes.openBelow);
|
|
1159
1170
|
this.content.main.classList.remove(this.classes.openAbove);
|
|
1160
1171
|
this.content.main.classList.add(this.classes.openBelow);
|
|
1172
|
+
const containerRect = this.main.main.getBoundingClientRect();
|
|
1173
|
+
this.content.main.style.margin = '-1px 0px 0px 0px';
|
|
1174
|
+
if (this.settings.contentPosition !== 'relative') {
|
|
1175
|
+
this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
|
|
1176
|
+
this.content.main.style.left = containerRect.left + window.scrollX + 'px';
|
|
1177
|
+
this.content.main.style.width = containerRect.width + 'px';
|
|
1178
|
+
}
|
|
1161
1179
|
}
|
|
1162
1180
|
ensureElementInView(container, element) {
|
|
1163
1181
|
const cTop = container.scrollTop + container.offsetTop;
|
|
@@ -1171,16 +1189,18 @@ class Render {
|
|
|
1171
1189
|
container.scrollTop += eBottom - cBottom;
|
|
1172
1190
|
}
|
|
1173
1191
|
}
|
|
1174
|
-
putContent(
|
|
1175
|
-
const
|
|
1176
|
-
const
|
|
1177
|
-
const
|
|
1178
|
-
const
|
|
1179
|
-
if (
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1192
|
+
putContent() {
|
|
1193
|
+
const mainHeight = this.main.main.offsetHeight;
|
|
1194
|
+
const mainRect = this.main.main.getBoundingClientRect();
|
|
1195
|
+
const contentHeight = this.content.main.offsetHeight;
|
|
1196
|
+
const spaceBelow = window.innerHeight - (mainRect.top + mainHeight);
|
|
1197
|
+
if (spaceBelow <= contentHeight) {
|
|
1198
|
+
if (mainRect.top > contentHeight) {
|
|
1199
|
+
return 'up';
|
|
1200
|
+
}
|
|
1201
|
+
else {
|
|
1202
|
+
return 'down';
|
|
1203
|
+
}
|
|
1184
1204
|
}
|
|
1185
1205
|
return 'down';
|
|
1186
1206
|
}
|
|
@@ -1191,16 +1211,17 @@ class Select {
|
|
|
1191
1211
|
this.listen = false;
|
|
1192
1212
|
this.observer = null;
|
|
1193
1213
|
this.select = select;
|
|
1214
|
+
this.select.addEventListener('change', this.valueChange.bind(this), {
|
|
1215
|
+
passive: true,
|
|
1216
|
+
});
|
|
1217
|
+
this.observer = new MutationObserver(this.observeCall.bind(this));
|
|
1218
|
+
this.changeListen(true);
|
|
1194
1219
|
}
|
|
1195
1220
|
enable() {
|
|
1196
|
-
this.disconnectObserver();
|
|
1197
1221
|
this.select.disabled = false;
|
|
1198
|
-
this.connectObserver();
|
|
1199
1222
|
}
|
|
1200
1223
|
disable() {
|
|
1201
|
-
this.disconnectObserver();
|
|
1202
1224
|
this.select.disabled = true;
|
|
1203
|
-
this.connectObserver();
|
|
1204
1225
|
}
|
|
1205
1226
|
hideUI() {
|
|
1206
1227
|
this.select.tabIndex = -1;
|
|
@@ -1212,65 +1233,54 @@ class Select {
|
|
|
1212
1233
|
this.select.style.display = '';
|
|
1213
1234
|
this.select.removeAttribute('aria-hidden');
|
|
1214
1235
|
}
|
|
1215
|
-
changeListen(
|
|
1216
|
-
this.listen =
|
|
1217
|
-
if (
|
|
1218
|
-
this.
|
|
1236
|
+
changeListen(listen) {
|
|
1237
|
+
this.listen = listen;
|
|
1238
|
+
if (listen) {
|
|
1239
|
+
if (this.observer) {
|
|
1240
|
+
this.observer.observe(this.select, {
|
|
1241
|
+
subtree: true,
|
|
1242
|
+
childList: true,
|
|
1243
|
+
attributes: true,
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1219
1246
|
}
|
|
1220
|
-
|
|
1221
|
-
this.
|
|
1247
|
+
if (!listen) {
|
|
1248
|
+
if (this.observer) {
|
|
1249
|
+
this.observer.disconnect();
|
|
1250
|
+
}
|
|
1222
1251
|
}
|
|
1223
1252
|
}
|
|
1224
|
-
addSelectChangeListener(func) {
|
|
1225
|
-
this.onSelectChange = func;
|
|
1226
|
-
this.addObserver();
|
|
1227
|
-
this.connectObserver();
|
|
1228
|
-
this.changeListen(true);
|
|
1229
|
-
}
|
|
1230
|
-
removeSelectChangeListener() {
|
|
1231
|
-
this.changeListen(false);
|
|
1232
|
-
this.onSelectChange = undefined;
|
|
1233
|
-
}
|
|
1234
|
-
addValueChangeListener(func) {
|
|
1235
|
-
this.onValueChange = func;
|
|
1236
|
-
this.select.addEventListener('change', this.valueChange.bind(this), {
|
|
1237
|
-
passive: true,
|
|
1238
|
-
});
|
|
1239
|
-
}
|
|
1240
|
-
removeValueChangeListener() {
|
|
1241
|
-
this.onValueChange = undefined;
|
|
1242
|
-
this.select.removeEventListener('change', this.valueChange.bind(this));
|
|
1243
|
-
}
|
|
1244
1253
|
valueChange(ev) {
|
|
1245
1254
|
if (this.listen && this.onValueChange) {
|
|
1246
1255
|
this.onValueChange(this.getSelectedValues());
|
|
1247
1256
|
}
|
|
1248
1257
|
return true;
|
|
1249
1258
|
}
|
|
1250
|
-
|
|
1251
|
-
if (this.
|
|
1252
|
-
|
|
1253
|
-
this.onSelectChange(this.getData());
|
|
1254
|
-
this.changeListen(true);
|
|
1259
|
+
observeCall(mutations) {
|
|
1260
|
+
if (!this.listen) {
|
|
1261
|
+
return;
|
|
1255
1262
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
this.
|
|
1260
|
-
|
|
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
|
+
}
|
|
1271
|
+
if (m.target.nodeName === 'OPTGROUP' || m.target.nodeName === 'OPTION') {
|
|
1272
|
+
optgroupOptionChanged = true;
|
|
1273
|
+
}
|
|
1261
1274
|
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
this.observer.observe(this.select, {
|
|
1267
|
-
childList: true,
|
|
1268
|
-
});
|
|
1275
|
+
if (disabledChanged && this.onDisabledChange) {
|
|
1276
|
+
this.changeListen(false);
|
|
1277
|
+
this.onDisabledChange(this.select.disabled);
|
|
1278
|
+
this.changeListen(true);
|
|
1269
1279
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
this.
|
|
1280
|
+
if (optgroupOptionChanged && this.onOptionsChange) {
|
|
1281
|
+
this.changeListen(false);
|
|
1282
|
+
this.onOptionsChange(this.getData());
|
|
1283
|
+
this.changeListen(true);
|
|
1274
1284
|
}
|
|
1275
1285
|
}
|
|
1276
1286
|
getData() {
|
|
@@ -1288,7 +1298,7 @@ class Select {
|
|
|
1288
1298
|
}
|
|
1289
1299
|
getDataFromOptgroup(optgroup) {
|
|
1290
1300
|
let data = {
|
|
1291
|
-
id:
|
|
1301
|
+
id: optgroup.id,
|
|
1292
1302
|
label: optgroup.label,
|
|
1293
1303
|
selectAll: optgroup.dataset ? optgroup.dataset.selectall === 'true' : false,
|
|
1294
1304
|
closable: optgroup.dataset ? optgroup.dataset.closable : 'off',
|
|
@@ -1304,10 +1314,10 @@ class Select {
|
|
|
1304
1314
|
}
|
|
1305
1315
|
getDataFromOption(option) {
|
|
1306
1316
|
return {
|
|
1307
|
-
id:
|
|
1317
|
+
id: option.id,
|
|
1308
1318
|
value: option.value,
|
|
1309
1319
|
text: option.text,
|
|
1310
|
-
html: option.
|
|
1320
|
+
html: option.dataset && option.dataset.html ? option.dataset.html : '',
|
|
1311
1321
|
selected: option.selected,
|
|
1312
1322
|
display: option.style.display === 'none' ? false : true,
|
|
1313
1323
|
disabled: option.disabled,
|
|
@@ -1343,6 +1353,7 @@ class Select {
|
|
|
1343
1353
|
return values;
|
|
1344
1354
|
}
|
|
1345
1355
|
setSelected(value) {
|
|
1356
|
+
this.changeListen(false);
|
|
1346
1357
|
const options = this.select.childNodes;
|
|
1347
1358
|
for (const o of options) {
|
|
1348
1359
|
if (o.nodeName === 'OPTGROUP') {
|
|
@@ -1360,6 +1371,7 @@ class Select {
|
|
|
1360
1371
|
option.selected = value.includes(option.value);
|
|
1361
1372
|
}
|
|
1362
1373
|
}
|
|
1374
|
+
this.changeListen(true);
|
|
1363
1375
|
}
|
|
1364
1376
|
updateSelect(id, style, classes) {
|
|
1365
1377
|
this.changeListen(false);
|
|
@@ -1412,8 +1424,12 @@ class Select {
|
|
|
1412
1424
|
}
|
|
1413
1425
|
createOption(info) {
|
|
1414
1426
|
const optionEl = document.createElement('option');
|
|
1415
|
-
optionEl.
|
|
1416
|
-
optionEl.
|
|
1427
|
+
optionEl.id = info.id;
|
|
1428
|
+
optionEl.value = info.value;
|
|
1429
|
+
optionEl.innerHTML = info.text;
|
|
1430
|
+
if (info.html !== '') {
|
|
1431
|
+
optionEl.setAttribute('data-html', info.html);
|
|
1432
|
+
}
|
|
1417
1433
|
if (info.selected) {
|
|
1418
1434
|
optionEl.selected = info.selected;
|
|
1419
1435
|
}
|
|
@@ -1443,15 +1459,18 @@ class Select {
|
|
|
1443
1459
|
}
|
|
1444
1460
|
destroy() {
|
|
1445
1461
|
this.changeListen(false);
|
|
1446
|
-
this.
|
|
1447
|
-
this.
|
|
1448
|
-
|
|
1462
|
+
this.select.removeEventListener('change', this.valueChange.bind(this));
|
|
1463
|
+
if (this.observer) {
|
|
1464
|
+
this.observer.disconnect();
|
|
1465
|
+
this.observer = null;
|
|
1466
|
+
}
|
|
1449
1467
|
this.showUI();
|
|
1450
1468
|
}
|
|
1451
1469
|
}
|
|
1452
1470
|
|
|
1453
1471
|
class SlimSelect {
|
|
1454
1472
|
constructor(config) {
|
|
1473
|
+
var _a;
|
|
1455
1474
|
this.events = {
|
|
1456
1475
|
search: undefined,
|
|
1457
1476
|
searchFilter: (opt, search) => {
|
|
@@ -1475,23 +1494,7 @@ class SlimSelect {
|
|
|
1475
1494
|
if (!this.settings.isOpen) {
|
|
1476
1495
|
return;
|
|
1477
1496
|
}
|
|
1478
|
-
|
|
1479
|
-
this.render.moveContentBelow();
|
|
1480
|
-
return;
|
|
1481
|
-
}
|
|
1482
|
-
else if (this.settings.openPosition === 'up') {
|
|
1483
|
-
this.render.moveContentAbove();
|
|
1484
|
-
return;
|
|
1485
|
-
}
|
|
1486
|
-
if (this.settings.contentPosition === 'relative') {
|
|
1487
|
-
this.render.moveContentBelow();
|
|
1488
|
-
}
|
|
1489
|
-
else if (this.render.putContent(this.render.content.main, this.settings.isOpen) === 'up') {
|
|
1490
|
-
this.render.moveContentAbove();
|
|
1491
|
-
}
|
|
1492
|
-
else {
|
|
1493
|
-
this.render.moveContentBelow();
|
|
1494
|
-
}
|
|
1497
|
+
this.render.moveContent();
|
|
1495
1498
|
});
|
|
1496
1499
|
this.documentClick = (e) => {
|
|
1497
1500
|
if (!this.settings.isOpen) {
|
|
@@ -1523,18 +1526,27 @@ class SlimSelect {
|
|
|
1523
1526
|
this.events[key] = config.events[key];
|
|
1524
1527
|
}
|
|
1525
1528
|
}
|
|
1529
|
+
this.settings.disabled = ((_a = config.settings) === null || _a === void 0 ? void 0 : _a.disabled) ? config.settings.disabled : this.selectEl.disabled;
|
|
1526
1530
|
this.settings.isMultiple = this.selectEl.multiple;
|
|
1527
1531
|
this.settings.style = this.selectEl.style.cssText;
|
|
1528
1532
|
this.settings.class = this.selectEl.className.split(' ');
|
|
1529
1533
|
this.select = new Select(this.selectEl);
|
|
1530
1534
|
this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class);
|
|
1531
1535
|
this.select.hideUI();
|
|
1532
|
-
this.select.
|
|
1533
|
-
this.setData(data);
|
|
1534
|
-
});
|
|
1535
|
-
this.select.addValueChangeListener((values) => {
|
|
1536
|
+
this.select.onValueChange = (values) => {
|
|
1536
1537
|
this.setSelected(values);
|
|
1537
|
-
}
|
|
1538
|
+
};
|
|
1539
|
+
this.select.onDisabledChange = (disabled) => {
|
|
1540
|
+
if (disabled) {
|
|
1541
|
+
this.disable();
|
|
1542
|
+
}
|
|
1543
|
+
else {
|
|
1544
|
+
this.enable();
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
this.select.onOptionsChange = (data) => {
|
|
1548
|
+
this.setData(data);
|
|
1549
|
+
};
|
|
1538
1550
|
this.store = new Store(this.settings.isMultiple ? 'multiple' : 'single', config.data ? config.data : this.select.getData());
|
|
1539
1551
|
if (config.data) {
|
|
1540
1552
|
this.select.updateOptions(this.store.getData());
|
|
@@ -1560,7 +1572,7 @@ class SlimSelect {
|
|
|
1560
1572
|
if (this.settings.openPosition === 'auto') {
|
|
1561
1573
|
window.addEventListener('scroll', this.windowScroll, false);
|
|
1562
1574
|
}
|
|
1563
|
-
if (
|
|
1575
|
+
if (this.settings.disabled) {
|
|
1564
1576
|
this.disable();
|
|
1565
1577
|
}
|
|
1566
1578
|
if (this.settings.alwaysOpen) {
|
|
@@ -1569,12 +1581,12 @@ class SlimSelect {
|
|
|
1569
1581
|
this.selectEl.slim = this;
|
|
1570
1582
|
}
|
|
1571
1583
|
enable() {
|
|
1572
|
-
this.settings.
|
|
1584
|
+
this.settings.disabled = false;
|
|
1573
1585
|
this.select.enable();
|
|
1574
1586
|
this.render.enable();
|
|
1575
1587
|
}
|
|
1576
1588
|
disable() {
|
|
1577
|
-
this.settings.
|
|
1589
|
+
this.settings.disabled = true;
|
|
1578
1590
|
this.select.disable();
|
|
1579
1591
|
this.render.disable();
|
|
1580
1592
|
}
|
|
@@ -1608,7 +1620,12 @@ class SlimSelect {
|
|
|
1608
1620
|
const data = this.store.getData();
|
|
1609
1621
|
this.select.updateOptions(data);
|
|
1610
1622
|
this.render.renderValues();
|
|
1611
|
-
this.render.
|
|
1623
|
+
if (this.render.content.search.input.value !== '') {
|
|
1624
|
+
this.search(this.render.content.search.input.value);
|
|
1625
|
+
}
|
|
1626
|
+
else {
|
|
1627
|
+
this.render.renderOptions(data);
|
|
1628
|
+
}
|
|
1612
1629
|
if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
1613
1630
|
this.events.afterChange(this.store.getSelectedOptions());
|
|
1614
1631
|
}
|
|
@@ -1625,7 +1642,7 @@ class SlimSelect {
|
|
|
1625
1642
|
}
|
|
1626
1643
|
}
|
|
1627
1644
|
open() {
|
|
1628
|
-
if (
|
|
1645
|
+
if (this.settings.disabled || this.settings.isOpen) {
|
|
1629
1646
|
return;
|
|
1630
1647
|
}
|
|
1631
1648
|
if (this.events.beforeOpen) {
|
|
@@ -1641,10 +1658,12 @@ class SlimSelect {
|
|
|
1641
1658
|
}
|
|
1642
1659
|
this.settings.isOpen = true;
|
|
1643
1660
|
}, this.settings.timeoutDelay);
|
|
1644
|
-
if (this.settings.
|
|
1645
|
-
|
|
1661
|
+
if (this.settings.contentPosition === 'absolute') {
|
|
1662
|
+
if (this.settings.intervalMove) {
|
|
1663
|
+
clearInterval(this.settings.intervalMove);
|
|
1664
|
+
}
|
|
1665
|
+
this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
|
|
1646
1666
|
}
|
|
1647
|
-
this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
|
|
1648
1667
|
}
|
|
1649
1668
|
close() {
|
|
1650
1669
|
if (!this.settings.isOpen || this.settings.alwaysOpen) {
|
|
@@ -1760,7 +1779,7 @@ var script = vue.defineComponent({
|
|
|
1760
1779
|
this.slim = new SlimSelect(config);
|
|
1761
1780
|
let selected = this.$props.multiple ? this.slim.getSelected() : this.slim.getSelected()[0];
|
|
1762
1781
|
if (this.value !== selected) {
|
|
1763
|
-
this.value
|
|
1782
|
+
this.slim.setSelected(this.value);
|
|
1764
1783
|
}
|
|
1765
1784
|
},
|
|
1766
1785
|
beforeUnmount() {
|
|
@@ -1769,6 +1788,13 @@ var script = vue.defineComponent({
|
|
|
1769
1788
|
}
|
|
1770
1789
|
},
|
|
1771
1790
|
watch: {
|
|
1791
|
+
modelValue: {
|
|
1792
|
+
handler: function (newVal) {
|
|
1793
|
+
var _a;
|
|
1794
|
+
(_a = this.slim) === null || _a === void 0 ? void 0 : _a.setSelected(this.getCleanValue(newVal));
|
|
1795
|
+
},
|
|
1796
|
+
immediate: true,
|
|
1797
|
+
},
|
|
1772
1798
|
data: {
|
|
1773
1799
|
handler: function (newData) {
|
|
1774
1800
|
if (this.slim) {
|
|
@@ -1781,18 +1807,7 @@ var script = vue.defineComponent({
|
|
|
1781
1807
|
computed: {
|
|
1782
1808
|
value: {
|
|
1783
1809
|
get() {
|
|
1784
|
-
|
|
1785
|
-
const val = this.$props.modelValue;
|
|
1786
|
-
if (val === undefined) {
|
|
1787
|
-
return multi ? [] : '';
|
|
1788
|
-
}
|
|
1789
|
-
if (multi && typeof val === 'string') {
|
|
1790
|
-
return [val];
|
|
1791
|
-
}
|
|
1792
|
-
if (!multi && Array.isArray(val)) {
|
|
1793
|
-
return val[0];
|
|
1794
|
-
}
|
|
1795
|
-
return multi ? [] : '';
|
|
1810
|
+
return this.getCleanValue(this.$props.modelValue);
|
|
1796
1811
|
},
|
|
1797
1812
|
set(value) {
|
|
1798
1813
|
this.$emit('update:modelValue', value);
|
|
@@ -1803,6 +1818,16 @@ var script = vue.defineComponent({
|
|
|
1803
1818
|
getSlimSelect() {
|
|
1804
1819
|
return this.slim;
|
|
1805
1820
|
},
|
|
1821
|
+
getCleanValue(val) {
|
|
1822
|
+
const multi = this.$props.multiple;
|
|
1823
|
+
if (typeof val === 'string') {
|
|
1824
|
+
return multi ? [val] : val;
|
|
1825
|
+
}
|
|
1826
|
+
if (Array.isArray(val)) {
|
|
1827
|
+
return multi ? val : val[0];
|
|
1828
|
+
}
|
|
1829
|
+
return multi ? [] : '';
|
|
1830
|
+
},
|
|
1806
1831
|
},
|
|
1807
1832
|
});
|
|
1808
1833
|
|