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