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/README.md
CHANGED
|
@@ -51,12 +51,8 @@ npm install slim-select
|
|
|
51
51
|
### or
|
|
52
52
|
|
|
53
53
|
```html
|
|
54
|
-
<script src="https://
|
|
55
|
-
<link
|
|
56
|
-
rel="stylesheet"
|
|
57
|
-
type="text/css"
|
|
58
|
-
href="https://cdnjs.cloudflare.com/ajax/libs/slim-select/<version>/slimselect.css"
|
|
59
|
-
/>
|
|
54
|
+
<script src="https://unpkg.com/slim-select@latest/dist/slimselect.min.js"></script>
|
|
55
|
+
<link rel="stylesheet" href="https://unpkg.com/slim-select@latest/dist/slimselect.css" />
|
|
60
56
|
```
|
|
61
57
|
|
|
62
58
|
## Usage
|
package/dist/render.d.ts
CHANGED
|
@@ -48,6 +48,7 @@ export default class Render {
|
|
|
48
48
|
placeholder: string;
|
|
49
49
|
values: string;
|
|
50
50
|
single: string;
|
|
51
|
+
max: string;
|
|
51
52
|
value: string;
|
|
52
53
|
valueText: string;
|
|
53
54
|
valueDelete: string;
|
|
@@ -112,5 +113,5 @@ export default class Render {
|
|
|
112
113
|
moveContentAbove(): void;
|
|
113
114
|
moveContentBelow(): void;
|
|
114
115
|
ensureElementInView(container: HTMLElement, element: HTMLElement): void;
|
|
115
|
-
putContent(
|
|
116
|
+
putContent(): 'up' | 'down';
|
|
116
117
|
}
|
package/dist/select.d.ts
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { DataArray, DataArrayPartial, Optgroup, OptgroupOptional, Option } from './store';
|
|
2
2
|
export default class Select {
|
|
3
3
|
select: HTMLSelectElement;
|
|
4
|
-
listen: boolean;
|
|
5
|
-
onSelectChange?: (data: DataArrayPartial) => void;
|
|
6
4
|
onValueChange?: (value: string[]) => void;
|
|
5
|
+
onDisabledChange?: (disabled: boolean) => void;
|
|
6
|
+
onOptionsChange?: (data: DataArrayPartial) => void;
|
|
7
|
+
listen: boolean;
|
|
7
8
|
private observer;
|
|
8
9
|
constructor(select: HTMLSelectElement);
|
|
9
10
|
enable(): void;
|
|
10
11
|
disable(): void;
|
|
11
12
|
hideUI(): void;
|
|
12
13
|
showUI(): void;
|
|
13
|
-
changeListen(
|
|
14
|
-
addSelectChangeListener(func: (data: DataArrayPartial) => void): void;
|
|
15
|
-
removeSelectChangeListener(): void;
|
|
16
|
-
addValueChangeListener(func: (value: string[]) => void): void;
|
|
17
|
-
removeValueChangeListener(): void;
|
|
14
|
+
changeListen(listen: boolean): void;
|
|
18
15
|
valueChange(ev: Event): boolean;
|
|
19
|
-
private
|
|
20
|
-
private addObserver;
|
|
21
|
-
private connectObserver;
|
|
22
|
-
private disconnectObserver;
|
|
16
|
+
private observeCall;
|
|
23
17
|
getData(): DataArrayPartial;
|
|
24
18
|
getDataFromOptgroup(optgroup: HTMLOptGroupElement): OptgroupOptional;
|
|
25
19
|
getDataFromOption(option: HTMLOptionElement): Option;
|
package/dist/settings.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export default class Settings {
|
|
|
8
8
|
isOpen: boolean;
|
|
9
9
|
triggerFocus: boolean;
|
|
10
10
|
intervalMove: NodeJS.Timeout | null;
|
|
11
|
-
|
|
11
|
+
disabled: boolean;
|
|
12
12
|
alwaysOpen: boolean;
|
|
13
13
|
showSearch: boolean;
|
|
14
14
|
searchPlaceholder: string;
|
|
@@ -26,5 +26,7 @@ export default class Settings {
|
|
|
26
26
|
minSelected: number;
|
|
27
27
|
maxSelected: number;
|
|
28
28
|
timeoutDelay: number;
|
|
29
|
+
maxValuesShown: number;
|
|
30
|
+
maxValuesMessage: string;
|
|
29
31
|
constructor(settings?: SettingsPartial);
|
|
30
32
|
}
|
package/dist/slimselect.cjs.js
CHANGED
|
@@ -67,7 +67,7 @@ class Settings {
|
|
|
67
67
|
this.id = 'ss-' + generateID();
|
|
68
68
|
this.style = settings.style || '';
|
|
69
69
|
this.class = settings.class || [];
|
|
70
|
-
this.
|
|
70
|
+
this.disabled = settings.disabled !== undefined ? settings.disabled : false;
|
|
71
71
|
this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
|
|
72
72
|
this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
|
|
73
73
|
this.searchPlaceholder = settings.searchPlaceholder || 'Search';
|
|
@@ -85,6 +85,8 @@ class Settings {
|
|
|
85
85
|
this.minSelected = settings.minSelected || 0;
|
|
86
86
|
this.maxSelected = settings.maxSelected || 1000;
|
|
87
87
|
this.timeoutDelay = settings.timeoutDelay || 200;
|
|
88
|
+
this.maxValuesShown = settings.maxValuesShown || 20;
|
|
89
|
+
this.maxValuesMessage = settings.maxValuesMessage || '{number} selected';
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
|
|
@@ -267,23 +269,21 @@ class Store {
|
|
|
267
269
|
const dataSearch = [];
|
|
268
270
|
this.data.forEach((dataObj) => {
|
|
269
271
|
if (dataObj instanceof Optgroup) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
let optOptions = [];
|
|
273
|
+
dataObj.options.forEach((option) => {
|
|
274
|
+
if (!filter || filter(option)) {
|
|
275
|
+
if (!includeOptgroup) {
|
|
276
|
+
dataSearch.push(new Option(option));
|
|
274
277
|
}
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
let optOptions = [];
|
|
279
|
-
dataObj.options.forEach((option) => {
|
|
280
|
-
if (!filter || filter(option)) {
|
|
278
|
+
else {
|
|
281
279
|
optOptions.push(new Option(option));
|
|
282
280
|
}
|
|
283
|
-
});
|
|
284
|
-
if (optOptions.length > 0) {
|
|
285
|
-
dataSearch.push(new Optgroup(dataObj));
|
|
286
281
|
}
|
|
282
|
+
});
|
|
283
|
+
if (optOptions.length > 0) {
|
|
284
|
+
let optgroup = new Optgroup(dataObj);
|
|
285
|
+
optgroup.options = optOptions;
|
|
286
|
+
dataSearch.push(optgroup);
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
if (dataObj instanceof Option) {
|
|
@@ -303,6 +303,7 @@ class Render {
|
|
|
303
303
|
placeholder: 'ss-placeholder',
|
|
304
304
|
values: 'ss-values',
|
|
305
305
|
single: 'ss-single',
|
|
306
|
+
max: 'ss-max',
|
|
306
307
|
value: 'ss-value',
|
|
307
308
|
valueText: 'ss-value-text',
|
|
308
309
|
valueDelete: 'ss-value-delete',
|
|
@@ -359,23 +360,7 @@ class Render {
|
|
|
359
360
|
this.main.main.classList.add(this.settings.openPosition === 'up' ? this.classes.openAbove : this.classes.openBelow);
|
|
360
361
|
this.moveContent();
|
|
361
362
|
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
|
-
}
|
|
363
|
+
this.moveContent();
|
|
379
364
|
const selectedOptions = this.store.getSelectedOptions();
|
|
380
365
|
if (selectedOptions.length) {
|
|
381
366
|
const selectedId = selectedOptions[selectedOptions.length - 1].id;
|
|
@@ -433,7 +418,7 @@ class Render {
|
|
|
433
418
|
}
|
|
434
419
|
};
|
|
435
420
|
main.onclick = (e) => {
|
|
436
|
-
if (
|
|
421
|
+
if (this.settings.disabled) {
|
|
437
422
|
return;
|
|
438
423
|
}
|
|
439
424
|
this.settings.isOpen ? this.callbacks.close() : this.callbacks.open();
|
|
@@ -448,7 +433,7 @@ class Render {
|
|
|
448
433
|
}
|
|
449
434
|
deselect.onclick = (e) => {
|
|
450
435
|
e.stopPropagation();
|
|
451
|
-
if (
|
|
436
|
+
if (this.settings.disabled) {
|
|
452
437
|
return;
|
|
453
438
|
}
|
|
454
439
|
let shouldDelete = true;
|
|
@@ -564,6 +549,19 @@ class Render {
|
|
|
564
549
|
placeholder.remove();
|
|
565
550
|
}
|
|
566
551
|
}
|
|
552
|
+
if (selectedOptions.length > this.settings.maxValuesShown) {
|
|
553
|
+
const singleValue = document.createElement('div');
|
|
554
|
+
singleValue.classList.add(this.classes.max);
|
|
555
|
+
singleValue.textContent = this.settings.maxValuesMessage.replace('{number}', selectedOptions.length.toString());
|
|
556
|
+
this.main.values.innerHTML = singleValue.outerHTML;
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
const maxValuesMessage = this.main.values.querySelector('.' + this.classes.max);
|
|
561
|
+
if (maxValuesMessage) {
|
|
562
|
+
maxValuesMessage.remove();
|
|
563
|
+
}
|
|
564
|
+
}
|
|
567
565
|
let removeNodes = [];
|
|
568
566
|
for (let i = 0; i < currentNodes.length; i++) {
|
|
569
567
|
const node = currentNodes[i];
|
|
@@ -618,6 +616,9 @@ class Render {
|
|
|
618
616
|
deleteDiv.onclick = (e) => {
|
|
619
617
|
e.preventDefault();
|
|
620
618
|
e.stopPropagation();
|
|
619
|
+
if (this.settings.disabled) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
621
622
|
let shouldDelete = true;
|
|
622
623
|
const before = this.store.getSelectedOptions();
|
|
623
624
|
const after = before.filter((o) => {
|
|
@@ -689,12 +690,23 @@ class Render {
|
|
|
689
690
|
}
|
|
690
691
|
moveContent() {
|
|
691
692
|
if (this.settings.contentPosition === 'relative') {
|
|
693
|
+
this.moveContentBelow();
|
|
692
694
|
return;
|
|
693
695
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
696
|
+
if (this.settings.openPosition === 'down') {
|
|
697
|
+
this.moveContentBelow();
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
else if (this.settings.openPosition === 'up') {
|
|
701
|
+
this.moveContentAbove();
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
if (this.putContent() === 'up') {
|
|
705
|
+
this.moveContentAbove();
|
|
706
|
+
}
|
|
707
|
+
else {
|
|
708
|
+
this.moveContentBelow();
|
|
709
|
+
}
|
|
698
710
|
}
|
|
699
711
|
searchDiv() {
|
|
700
712
|
const main = document.createElement('div');
|
|
@@ -905,8 +917,7 @@ class Render {
|
|
|
905
917
|
this.content.list.innerHTML = '';
|
|
906
918
|
if (data.length === 0) {
|
|
907
919
|
const noResults = document.createElement('div');
|
|
908
|
-
noResults.classList.add(this.classes.
|
|
909
|
-
noResults.classList.add(this.classes.disabled);
|
|
920
|
+
noResults.classList.add(this.classes.search);
|
|
910
921
|
noResults.innerHTML = this.settings.searchText;
|
|
911
922
|
this.content.list.appendChild(noResults);
|
|
912
923
|
return;
|
|
@@ -982,7 +993,7 @@ class Render {
|
|
|
982
993
|
optgroupClosable.appendChild(optgroupClosableSvg);
|
|
983
994
|
const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
984
995
|
optgroupClosableSvg.appendChild(optgroupClosableArrow);
|
|
985
|
-
if (d.options.some((o) => o.selected)) {
|
|
996
|
+
if (d.options.some((o) => o.selected) || this.content.search.input.value.trim() !== '') {
|
|
986
997
|
optgroupClosable.classList.add(this.classes.open);
|
|
987
998
|
optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
|
|
988
999
|
}
|
|
@@ -1041,8 +1052,7 @@ class Render {
|
|
|
1041
1052
|
optionEl.style.cssText = option.style;
|
|
1042
1053
|
}
|
|
1043
1054
|
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);
|
|
1055
|
+
optionEl.innerHTML = this.highlightText(option.html !== '' ? option.html : option.text, this.content.search.input.value, this.classes.searchHighlighter);
|
|
1046
1056
|
}
|
|
1047
1057
|
else if (option.html !== '') {
|
|
1048
1058
|
optionEl.innerHTML = option.html;
|
|
@@ -1053,7 +1063,7 @@ class Render {
|
|
|
1053
1063
|
if (this.settings.showOptionTooltips && optionEl.textContent) {
|
|
1054
1064
|
optionEl.setAttribute('title', optionEl.textContent);
|
|
1055
1065
|
}
|
|
1056
|
-
if (
|
|
1066
|
+
if (option.disabled) {
|
|
1057
1067
|
optionEl.classList.add(this.classes.disabled);
|
|
1058
1068
|
}
|
|
1059
1069
|
if (option.selected && this.settings.hideSelected) {
|
|
@@ -1074,9 +1084,8 @@ class Render {
|
|
|
1074
1084
|
if (option.disabled || (option.selected && !this.settings.allowDeselect)) {
|
|
1075
1085
|
return;
|
|
1076
1086
|
}
|
|
1077
|
-
if (this.settings.isMultiple &&
|
|
1078
|
-
|
|
1079
|
-
this.settings.maxSelected <= selectedOptions.length) {
|
|
1087
|
+
if ((this.settings.isMultiple && this.settings.maxSelected <= selectedOptions.length && !option.selected) ||
|
|
1088
|
+
(this.settings.isMultiple && this.settings.minSelected >= selectedOptions.length && option.selected)) {
|
|
1080
1089
|
return;
|
|
1081
1090
|
}
|
|
1082
1091
|
let shouldUpdate = false;
|
|
@@ -1141,23 +1150,30 @@ class Render {
|
|
|
1141
1150
|
return completedString;
|
|
1142
1151
|
}
|
|
1143
1152
|
moveContentAbove() {
|
|
1144
|
-
|
|
1153
|
+
const mainHeight = this.main.main.offsetHeight;
|
|
1145
1154
|
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
1155
|
this.main.main.classList.remove(this.classes.openBelow);
|
|
1150
1156
|
this.main.main.classList.add(this.classes.openAbove);
|
|
1151
1157
|
this.content.main.classList.remove(this.classes.openBelow);
|
|
1152
1158
|
this.content.main.classList.add(this.classes.openAbove);
|
|
1159
|
+
const containerRect = this.main.main.getBoundingClientRect();
|
|
1160
|
+
this.content.main.style.margin = '-' + (mainHeight + contentHeight - 1) + 'px 0px 0px 0px';
|
|
1161
|
+
this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
|
|
1162
|
+
this.content.main.style.left = containerRect.left + window.scrollX + 'px';
|
|
1163
|
+
this.content.main.style.width = containerRect.width + 'px';
|
|
1153
1164
|
}
|
|
1154
1165
|
moveContentBelow() {
|
|
1155
|
-
this.content.main.style.margin = '-1px 0px 0px 0px';
|
|
1156
|
-
this.content.main.style.transformOrigin = 'center top';
|
|
1157
1166
|
this.main.main.classList.remove(this.classes.openAbove);
|
|
1158
1167
|
this.main.main.classList.add(this.classes.openBelow);
|
|
1159
1168
|
this.content.main.classList.remove(this.classes.openAbove);
|
|
1160
1169
|
this.content.main.classList.add(this.classes.openBelow);
|
|
1170
|
+
const containerRect = this.main.main.getBoundingClientRect();
|
|
1171
|
+
this.content.main.style.margin = '-1px 0px 0px 0px';
|
|
1172
|
+
if (this.settings.contentPosition !== 'relative') {
|
|
1173
|
+
this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
|
|
1174
|
+
this.content.main.style.left = containerRect.left + window.scrollX + 'px';
|
|
1175
|
+
this.content.main.style.width = containerRect.width + 'px';
|
|
1176
|
+
}
|
|
1161
1177
|
}
|
|
1162
1178
|
ensureElementInView(container, element) {
|
|
1163
1179
|
const cTop = container.scrollTop + container.offsetTop;
|
|
@@ -1171,16 +1187,18 @@ class Render {
|
|
|
1171
1187
|
container.scrollTop += eBottom - cBottom;
|
|
1172
1188
|
}
|
|
1173
1189
|
}
|
|
1174
|
-
putContent(
|
|
1175
|
-
const
|
|
1176
|
-
const
|
|
1177
|
-
const
|
|
1178
|
-
const
|
|
1179
|
-
if (
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1190
|
+
putContent() {
|
|
1191
|
+
const mainHeight = this.main.main.offsetHeight;
|
|
1192
|
+
const mainRect = this.main.main.getBoundingClientRect();
|
|
1193
|
+
const contentHeight = this.content.main.offsetHeight;
|
|
1194
|
+
const spaceBelow = window.innerHeight - (mainRect.top + mainHeight);
|
|
1195
|
+
if (spaceBelow <= contentHeight) {
|
|
1196
|
+
if (mainRect.top > contentHeight) {
|
|
1197
|
+
return 'up';
|
|
1198
|
+
}
|
|
1199
|
+
else {
|
|
1200
|
+
return 'down';
|
|
1201
|
+
}
|
|
1184
1202
|
}
|
|
1185
1203
|
return 'down';
|
|
1186
1204
|
}
|
|
@@ -1191,16 +1209,17 @@ class Select {
|
|
|
1191
1209
|
this.listen = false;
|
|
1192
1210
|
this.observer = null;
|
|
1193
1211
|
this.select = select;
|
|
1212
|
+
this.select.addEventListener('change', this.valueChange.bind(this), {
|
|
1213
|
+
passive: true,
|
|
1214
|
+
});
|
|
1215
|
+
this.observer = new MutationObserver(this.observeCall.bind(this));
|
|
1216
|
+
this.changeListen(true);
|
|
1194
1217
|
}
|
|
1195
1218
|
enable() {
|
|
1196
|
-
this.disconnectObserver();
|
|
1197
1219
|
this.select.disabled = false;
|
|
1198
|
-
this.connectObserver();
|
|
1199
1220
|
}
|
|
1200
1221
|
disable() {
|
|
1201
|
-
this.disconnectObserver();
|
|
1202
1222
|
this.select.disabled = true;
|
|
1203
|
-
this.connectObserver();
|
|
1204
1223
|
}
|
|
1205
1224
|
hideUI() {
|
|
1206
1225
|
this.select.tabIndex = -1;
|
|
@@ -1212,65 +1231,54 @@ class Select {
|
|
|
1212
1231
|
this.select.style.display = '';
|
|
1213
1232
|
this.select.removeAttribute('aria-hidden');
|
|
1214
1233
|
}
|
|
1215
|
-
changeListen(
|
|
1216
|
-
this.listen =
|
|
1217
|
-
if (
|
|
1218
|
-
this.
|
|
1234
|
+
changeListen(listen) {
|
|
1235
|
+
this.listen = listen;
|
|
1236
|
+
if (listen) {
|
|
1237
|
+
if (this.observer) {
|
|
1238
|
+
this.observer.observe(this.select, {
|
|
1239
|
+
subtree: true,
|
|
1240
|
+
childList: true,
|
|
1241
|
+
attributes: true,
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1219
1244
|
}
|
|
1220
|
-
|
|
1221
|
-
this.
|
|
1245
|
+
if (!listen) {
|
|
1246
|
+
if (this.observer) {
|
|
1247
|
+
this.observer.disconnect();
|
|
1248
|
+
}
|
|
1222
1249
|
}
|
|
1223
1250
|
}
|
|
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
1251
|
valueChange(ev) {
|
|
1245
1252
|
if (this.listen && this.onValueChange) {
|
|
1246
1253
|
this.onValueChange(this.getSelectedValues());
|
|
1247
1254
|
}
|
|
1248
1255
|
return true;
|
|
1249
1256
|
}
|
|
1250
|
-
|
|
1251
|
-
if (this.
|
|
1252
|
-
|
|
1253
|
-
this.onSelectChange(this.getData());
|
|
1254
|
-
this.changeListen(true);
|
|
1257
|
+
observeCall(mutations) {
|
|
1258
|
+
if (!this.listen) {
|
|
1259
|
+
return;
|
|
1255
1260
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
this.
|
|
1260
|
-
|
|
1261
|
+
let disabledChanged = false;
|
|
1262
|
+
let optgroupOptionChanged = false;
|
|
1263
|
+
for (const m of mutations) {
|
|
1264
|
+
if (m.target === this.select) {
|
|
1265
|
+
if (m.attributeName === 'disabled') {
|
|
1266
|
+
disabledChanged = true;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
if (m.target.nodeName === 'OPTGROUP' || m.target.nodeName === 'OPTION') {
|
|
1270
|
+
optgroupOptionChanged = true;
|
|
1271
|
+
}
|
|
1261
1272
|
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
this.observer.observe(this.select, {
|
|
1267
|
-
childList: true,
|
|
1268
|
-
});
|
|
1273
|
+
if (disabledChanged && this.onDisabledChange) {
|
|
1274
|
+
this.changeListen(false);
|
|
1275
|
+
this.onDisabledChange(this.select.disabled);
|
|
1276
|
+
this.changeListen(true);
|
|
1269
1277
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
this.
|
|
1278
|
+
if (optgroupOptionChanged && this.onOptionsChange) {
|
|
1279
|
+
this.changeListen(false);
|
|
1280
|
+
this.onOptionsChange(this.getData());
|
|
1281
|
+
this.changeListen(true);
|
|
1274
1282
|
}
|
|
1275
1283
|
}
|
|
1276
1284
|
getData() {
|
|
@@ -1288,7 +1296,7 @@ class Select {
|
|
|
1288
1296
|
}
|
|
1289
1297
|
getDataFromOptgroup(optgroup) {
|
|
1290
1298
|
let data = {
|
|
1291
|
-
id:
|
|
1299
|
+
id: optgroup.id,
|
|
1292
1300
|
label: optgroup.label,
|
|
1293
1301
|
selectAll: optgroup.dataset ? optgroup.dataset.selectall === 'true' : false,
|
|
1294
1302
|
closable: optgroup.dataset ? optgroup.dataset.closable : 'off',
|
|
@@ -1304,10 +1312,10 @@ class Select {
|
|
|
1304
1312
|
}
|
|
1305
1313
|
getDataFromOption(option) {
|
|
1306
1314
|
return {
|
|
1307
|
-
id:
|
|
1315
|
+
id: option.id,
|
|
1308
1316
|
value: option.value,
|
|
1309
1317
|
text: option.text,
|
|
1310
|
-
html: option.
|
|
1318
|
+
html: option.dataset && option.dataset.html ? option.dataset.html : '',
|
|
1311
1319
|
selected: option.selected,
|
|
1312
1320
|
display: option.style.display === 'none' ? false : true,
|
|
1313
1321
|
disabled: option.disabled,
|
|
@@ -1343,6 +1351,7 @@ class Select {
|
|
|
1343
1351
|
return values;
|
|
1344
1352
|
}
|
|
1345
1353
|
setSelected(value) {
|
|
1354
|
+
this.changeListen(false);
|
|
1346
1355
|
const options = this.select.childNodes;
|
|
1347
1356
|
for (const o of options) {
|
|
1348
1357
|
if (o.nodeName === 'OPTGROUP') {
|
|
@@ -1360,6 +1369,7 @@ class Select {
|
|
|
1360
1369
|
option.selected = value.includes(option.value);
|
|
1361
1370
|
}
|
|
1362
1371
|
}
|
|
1372
|
+
this.changeListen(true);
|
|
1363
1373
|
}
|
|
1364
1374
|
updateSelect(id, style, classes) {
|
|
1365
1375
|
this.changeListen(false);
|
|
@@ -1412,8 +1422,12 @@ class Select {
|
|
|
1412
1422
|
}
|
|
1413
1423
|
createOption(info) {
|
|
1414
1424
|
const optionEl = document.createElement('option');
|
|
1415
|
-
optionEl.
|
|
1416
|
-
optionEl.
|
|
1425
|
+
optionEl.id = info.id;
|
|
1426
|
+
optionEl.value = info.value;
|
|
1427
|
+
optionEl.innerHTML = info.text;
|
|
1428
|
+
if (info.html !== '') {
|
|
1429
|
+
optionEl.setAttribute('data-html', info.html);
|
|
1430
|
+
}
|
|
1417
1431
|
if (info.selected) {
|
|
1418
1432
|
optionEl.selected = info.selected;
|
|
1419
1433
|
}
|
|
@@ -1443,15 +1457,18 @@ class Select {
|
|
|
1443
1457
|
}
|
|
1444
1458
|
destroy() {
|
|
1445
1459
|
this.changeListen(false);
|
|
1446
|
-
this.
|
|
1447
|
-
this.
|
|
1448
|
-
|
|
1460
|
+
this.select.removeEventListener('change', this.valueChange.bind(this));
|
|
1461
|
+
if (this.observer) {
|
|
1462
|
+
this.observer.disconnect();
|
|
1463
|
+
this.observer = null;
|
|
1464
|
+
}
|
|
1449
1465
|
this.showUI();
|
|
1450
1466
|
}
|
|
1451
1467
|
}
|
|
1452
1468
|
|
|
1453
1469
|
class SlimSelect {
|
|
1454
1470
|
constructor(config) {
|
|
1471
|
+
var _a;
|
|
1455
1472
|
this.events = {
|
|
1456
1473
|
search: undefined,
|
|
1457
1474
|
searchFilter: (opt, search) => {
|
|
@@ -1475,23 +1492,7 @@ class SlimSelect {
|
|
|
1475
1492
|
if (!this.settings.isOpen) {
|
|
1476
1493
|
return;
|
|
1477
1494
|
}
|
|
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
|
-
}
|
|
1495
|
+
this.render.moveContent();
|
|
1495
1496
|
});
|
|
1496
1497
|
this.documentClick = (e) => {
|
|
1497
1498
|
if (!this.settings.isOpen) {
|
|
@@ -1523,18 +1524,27 @@ class SlimSelect {
|
|
|
1523
1524
|
this.events[key] = config.events[key];
|
|
1524
1525
|
}
|
|
1525
1526
|
}
|
|
1527
|
+
this.settings.disabled = ((_a = config.settings) === null || _a === void 0 ? void 0 : _a.disabled) ? config.settings.disabled : this.selectEl.disabled;
|
|
1526
1528
|
this.settings.isMultiple = this.selectEl.multiple;
|
|
1527
1529
|
this.settings.style = this.selectEl.style.cssText;
|
|
1528
1530
|
this.settings.class = this.selectEl.className.split(' ');
|
|
1529
1531
|
this.select = new Select(this.selectEl);
|
|
1530
1532
|
this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class);
|
|
1531
1533
|
this.select.hideUI();
|
|
1532
|
-
this.select.
|
|
1533
|
-
this.setData(data);
|
|
1534
|
-
});
|
|
1535
|
-
this.select.addValueChangeListener((values) => {
|
|
1534
|
+
this.select.onValueChange = (values) => {
|
|
1536
1535
|
this.setSelected(values);
|
|
1537
|
-
}
|
|
1536
|
+
};
|
|
1537
|
+
this.select.onDisabledChange = (disabled) => {
|
|
1538
|
+
if (disabled) {
|
|
1539
|
+
this.disable();
|
|
1540
|
+
}
|
|
1541
|
+
else {
|
|
1542
|
+
this.enable();
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
this.select.onOptionsChange = (data) => {
|
|
1546
|
+
this.setData(data);
|
|
1547
|
+
};
|
|
1538
1548
|
this.store = new Store(this.settings.isMultiple ? 'multiple' : 'single', config.data ? config.data : this.select.getData());
|
|
1539
1549
|
if (config.data) {
|
|
1540
1550
|
this.select.updateOptions(this.store.getData());
|
|
@@ -1560,7 +1570,7 @@ class SlimSelect {
|
|
|
1560
1570
|
if (this.settings.openPosition === 'auto') {
|
|
1561
1571
|
window.addEventListener('scroll', this.windowScroll, false);
|
|
1562
1572
|
}
|
|
1563
|
-
if (
|
|
1573
|
+
if (this.settings.disabled) {
|
|
1564
1574
|
this.disable();
|
|
1565
1575
|
}
|
|
1566
1576
|
if (this.settings.alwaysOpen) {
|
|
@@ -1569,12 +1579,12 @@ class SlimSelect {
|
|
|
1569
1579
|
this.selectEl.slim = this;
|
|
1570
1580
|
}
|
|
1571
1581
|
enable() {
|
|
1572
|
-
this.settings.
|
|
1582
|
+
this.settings.disabled = false;
|
|
1573
1583
|
this.select.enable();
|
|
1574
1584
|
this.render.enable();
|
|
1575
1585
|
}
|
|
1576
1586
|
disable() {
|
|
1577
|
-
this.settings.
|
|
1587
|
+
this.settings.disabled = true;
|
|
1578
1588
|
this.select.disable();
|
|
1579
1589
|
this.render.disable();
|
|
1580
1590
|
}
|
|
@@ -1608,7 +1618,12 @@ class SlimSelect {
|
|
|
1608
1618
|
const data = this.store.getData();
|
|
1609
1619
|
this.select.updateOptions(data);
|
|
1610
1620
|
this.render.renderValues();
|
|
1611
|
-
this.render.
|
|
1621
|
+
if (this.render.content.search.input.value !== '') {
|
|
1622
|
+
this.search(this.render.content.search.input.value);
|
|
1623
|
+
}
|
|
1624
|
+
else {
|
|
1625
|
+
this.render.renderOptions(data);
|
|
1626
|
+
}
|
|
1612
1627
|
if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
1613
1628
|
this.events.afterChange(this.store.getSelectedOptions());
|
|
1614
1629
|
}
|
|
@@ -1625,7 +1640,7 @@ class SlimSelect {
|
|
|
1625
1640
|
}
|
|
1626
1641
|
}
|
|
1627
1642
|
open() {
|
|
1628
|
-
if (
|
|
1643
|
+
if (this.settings.disabled || this.settings.isOpen) {
|
|
1629
1644
|
return;
|
|
1630
1645
|
}
|
|
1631
1646
|
if (this.events.beforeOpen) {
|
|
@@ -1641,10 +1656,12 @@ class SlimSelect {
|
|
|
1641
1656
|
}
|
|
1642
1657
|
this.settings.isOpen = true;
|
|
1643
1658
|
}, this.settings.timeoutDelay);
|
|
1644
|
-
if (this.settings.
|
|
1645
|
-
|
|
1659
|
+
if (this.settings.contentPosition === 'absolute') {
|
|
1660
|
+
if (this.settings.intervalMove) {
|
|
1661
|
+
clearInterval(this.settings.intervalMove);
|
|
1662
|
+
}
|
|
1663
|
+
this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
|
|
1646
1664
|
}
|
|
1647
|
-
this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
|
|
1648
1665
|
}
|
|
1649
1666
|
close() {
|
|
1650
1667
|
if (!this.settings.isOpen || this.settings.alwaysOpen) {
|