slim-select 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/render.d.ts +2 -1
- package/dist/select.d.ts +1 -0
- package/dist/slimselect.cjs.js +50 -36
- package/dist/slimselect.es.js +50 -36
- package/dist/slimselect.global.js +50 -36
- package/dist/slimselect.js +50 -36
- package/dist/slimselect.min.js +1 -1
- package/dist/slimselect.umd.js +50 -36
- package/dist/slimselect.umd.min.js +1 -1
- package/package.json +1 -1
- package/src/slim-select/index.ts +13 -4
- package/src/slim-select/render.ts +53 -47
- package/src/slim-select/select.ts +19 -4
- package/src/vue/dist/slim-select/index.d.ts +1 -1
- package/src/vue/dist/slim-select/render.d.ts +2 -1
- package/src/vue/dist/slim-select/select.d.ts +1 -0
- package/src/vue/dist/slimselectvue.es.js +50 -36
- package/src/vue/dist/slimselectvue.global.js +50 -36
- package/src/vue/dist/slimselectvue.ssr.js +50 -36
- package/src/vue/dist/vue/slimselect.vue.d.ts +4 -2
- package/src/vue/package.json +1 -1
|
@@ -347,6 +347,7 @@ class Render {
|
|
|
347
347
|
this.callbacks = callbacks;
|
|
348
348
|
this.main = this.mainDiv();
|
|
349
349
|
this.content = this.contentDiv();
|
|
350
|
+
this.updateClassStyles();
|
|
350
351
|
this.settings.contentLocation.appendChild(this.content.main);
|
|
351
352
|
}
|
|
352
353
|
enable() {
|
|
@@ -361,8 +362,6 @@ class Render {
|
|
|
361
362
|
this.main.arrow.path.setAttribute('d', this.classes.arrowOpen);
|
|
362
363
|
this.main.main.classList.add(this.settings.openPosition === 'up' ? this.classes.openAbove : this.classes.openBelow);
|
|
363
364
|
this.moveContent();
|
|
364
|
-
this.renderOptions(this.store.getData());
|
|
365
|
-
this.moveContent();
|
|
366
365
|
const selectedOptions = this.store.getSelectedOptions();
|
|
367
366
|
if (selectedOptions.length) {
|
|
368
367
|
const selectedId = selectedOptions[selectedOptions.length - 1].id;
|
|
@@ -379,20 +378,32 @@ class Render {
|
|
|
379
378
|
this.content.main.classList.remove(this.classes.openBelow);
|
|
380
379
|
this.main.arrow.path.setAttribute('d', this.classes.arrowClose);
|
|
381
380
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
main.
|
|
385
|
-
|
|
386
|
-
main.
|
|
387
|
-
main.classList.add(this.
|
|
388
|
-
main.classList.add(this.classes.
|
|
389
|
-
if (this.settings.
|
|
381
|
+
updateClassStyles() {
|
|
382
|
+
this.main.main.className = '';
|
|
383
|
+
this.main.main.removeAttribute('style');
|
|
384
|
+
this.content.main.className = '';
|
|
385
|
+
this.content.main.removeAttribute('style');
|
|
386
|
+
this.main.main.classList.add(this.classes.main);
|
|
387
|
+
this.content.main.classList.add(this.classes.content);
|
|
388
|
+
if (this.settings.style !== '') {
|
|
389
|
+
this.content.main.style.cssText = this.settings.style;
|
|
390
|
+
}
|
|
391
|
+
if (this.settings.class.length) {
|
|
390
392
|
for (const c of this.settings.class) {
|
|
391
393
|
if (c.trim() !== '') {
|
|
392
|
-
main.classList.add(c.trim());
|
|
394
|
+
this.main.main.classList.add(c.trim());
|
|
395
|
+
this.content.main.classList.add(c.trim());
|
|
393
396
|
}
|
|
394
397
|
}
|
|
395
398
|
}
|
|
399
|
+
if (this.settings.contentPosition === 'relative') {
|
|
400
|
+
this.content.main.classList.add('ss-' + this.settings.contentPosition);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
mainDiv() {
|
|
404
|
+
const main = document.createElement('div');
|
|
405
|
+
main.dataset.id = this.settings.id;
|
|
406
|
+
main.tabIndex = 0;
|
|
396
407
|
main.onfocus = () => {
|
|
397
408
|
if (this.settings.triggerFocus) {
|
|
398
409
|
this.callbacks.open();
|
|
@@ -445,7 +456,7 @@ class Render {
|
|
|
445
456
|
shouldDelete = this.callbacks.beforeChange(after, before) === true;
|
|
446
457
|
}
|
|
447
458
|
if (shouldDelete) {
|
|
448
|
-
this.callbacks.setSelected(['']);
|
|
459
|
+
this.callbacks.setSelected([''], false);
|
|
449
460
|
if (this.settings.closeOnSelect) {
|
|
450
461
|
this.callbacks.close();
|
|
451
462
|
}
|
|
@@ -644,7 +655,7 @@ class Render {
|
|
|
644
655
|
selectedValues.push(o.value);
|
|
645
656
|
}
|
|
646
657
|
}
|
|
647
|
-
this.callbacks.setSelected(selectedValues);
|
|
658
|
+
this.callbacks.setSelected(selectedValues, false);
|
|
648
659
|
if (this.settings.closeOnSelect) {
|
|
649
660
|
this.callbacks.close();
|
|
650
661
|
}
|
|
@@ -665,21 +676,7 @@ class Render {
|
|
|
665
676
|
}
|
|
666
677
|
contentDiv() {
|
|
667
678
|
const main = document.createElement('div');
|
|
668
|
-
main.classList.add(this.classes.content);
|
|
669
679
|
main.dataset.id = this.settings.id;
|
|
670
|
-
if (this.settings.style !== '') {
|
|
671
|
-
main.style.cssText = this.settings.style;
|
|
672
|
-
}
|
|
673
|
-
if (this.settings.contentPosition === 'relative') {
|
|
674
|
-
main.classList.add('ss-' + this.settings.contentPosition);
|
|
675
|
-
}
|
|
676
|
-
if (this.settings.class.length) {
|
|
677
|
-
for (const c of this.settings.class) {
|
|
678
|
-
if (c.trim() !== '') {
|
|
679
|
-
main.classList.add(c.trim());
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
680
|
const search = this.searchDiv();
|
|
684
681
|
main.appendChild(search.main);
|
|
685
682
|
const list = this.listDiv();
|
|
@@ -791,10 +788,10 @@ class Render {
|
|
|
791
788
|
if (this.settings.isMultiple) {
|
|
792
789
|
let values = this.store.getSelected();
|
|
793
790
|
values.push(newOption.value);
|
|
794
|
-
this.callbacks.setSelected(values);
|
|
791
|
+
this.callbacks.setSelected(values, true);
|
|
795
792
|
}
|
|
796
793
|
else {
|
|
797
|
-
this.callbacks.setSelected([newOption.value]);
|
|
794
|
+
this.callbacks.setSelected([newOption.value], true);
|
|
798
795
|
}
|
|
799
796
|
this.callbacks.search('');
|
|
800
797
|
if (this.settings.closeOnSelect) {
|
|
@@ -976,12 +973,12 @@ class Render {
|
|
|
976
973
|
}
|
|
977
974
|
return true;
|
|
978
975
|
});
|
|
979
|
-
this.callbacks.setSelected(newSelected);
|
|
976
|
+
this.callbacks.setSelected(newSelected, true);
|
|
980
977
|
return;
|
|
981
978
|
}
|
|
982
979
|
else {
|
|
983
980
|
const newSelected = currentSelected.concat(d.options.map((o) => o.value));
|
|
984
|
-
this.callbacks.setSelected(newSelected);
|
|
981
|
+
this.callbacks.setSelected(newSelected, true);
|
|
985
982
|
}
|
|
986
983
|
});
|
|
987
984
|
optgroupActions.appendChild(selectAll);
|
|
@@ -1065,6 +1062,9 @@ class Render {
|
|
|
1065
1062
|
if (this.settings.showOptionTooltips && optionEl.textContent) {
|
|
1066
1063
|
optionEl.setAttribute('title', optionEl.textContent);
|
|
1067
1064
|
}
|
|
1065
|
+
if (!option.display) {
|
|
1066
|
+
optionEl.classList.add(this.classes.hide);
|
|
1067
|
+
}
|
|
1068
1068
|
if (option.disabled) {
|
|
1069
1069
|
optionEl.classList.add(this.classes.disabled);
|
|
1070
1070
|
}
|
|
@@ -1124,7 +1124,7 @@ class Render {
|
|
|
1124
1124
|
if (!this.store.getOptionByID(elementID)) {
|
|
1125
1125
|
this.callbacks.addOption(option);
|
|
1126
1126
|
}
|
|
1127
|
-
this.callbacks.setSelected(after.map((o) => o.value));
|
|
1127
|
+
this.callbacks.setSelected(after.map((o) => o.value), false);
|
|
1128
1128
|
if (this.settings.closeOnSelect) {
|
|
1129
1129
|
this.callbacks.close();
|
|
1130
1130
|
}
|
|
@@ -1260,6 +1260,7 @@ class Select {
|
|
|
1260
1260
|
if (!this.listen) {
|
|
1261
1261
|
return;
|
|
1262
1262
|
}
|
|
1263
|
+
let classChanged = false;
|
|
1263
1264
|
let disabledChanged = false;
|
|
1264
1265
|
let optgroupOptionChanged = false;
|
|
1265
1266
|
for (const m of mutations) {
|
|
@@ -1267,11 +1268,17 @@ class Select {
|
|
|
1267
1268
|
if (m.attributeName === 'disabled') {
|
|
1268
1269
|
disabledChanged = true;
|
|
1269
1270
|
}
|
|
1271
|
+
if (m.attributeName === 'class') {
|
|
1272
|
+
classChanged = true;
|
|
1273
|
+
}
|
|
1270
1274
|
}
|
|
1271
1275
|
if (m.target.nodeName === 'OPTGROUP' || m.target.nodeName === 'OPTION') {
|
|
1272
1276
|
optgroupOptionChanged = true;
|
|
1273
1277
|
}
|
|
1274
1278
|
}
|
|
1279
|
+
if (classChanged && this.onClassChange) {
|
|
1280
|
+
this.onClassChange(this.select.className.split(' '));
|
|
1281
|
+
}
|
|
1275
1282
|
if (disabledChanged && this.onDisabledChange) {
|
|
1276
1283
|
this.changeListen(false);
|
|
1277
1284
|
this.onDisabledChange(this.select.disabled);
|
|
@@ -1376,7 +1383,7 @@ class Select {
|
|
|
1376
1383
|
updateSelect(id, style, classes) {
|
|
1377
1384
|
this.changeListen(false);
|
|
1378
1385
|
if (id) {
|
|
1379
|
-
this.select.id = id;
|
|
1386
|
+
this.select.dataset.id = id;
|
|
1380
1387
|
}
|
|
1381
1388
|
if (style) {
|
|
1382
1389
|
this.select.style.cssText = style;
|
|
@@ -1464,6 +1471,7 @@ class Select {
|
|
|
1464
1471
|
this.observer.disconnect();
|
|
1465
1472
|
this.observer = null;
|
|
1466
1473
|
}
|
|
1474
|
+
delete this.select.dataset.id;
|
|
1467
1475
|
this.showUI();
|
|
1468
1476
|
}
|
|
1469
1477
|
}
|
|
@@ -1536,6 +1544,10 @@ class SlimSelect {
|
|
|
1536
1544
|
this.select.onValueChange = (values) => {
|
|
1537
1545
|
this.setSelected(values);
|
|
1538
1546
|
};
|
|
1547
|
+
this.select.onClassChange = (classes) => {
|
|
1548
|
+
this.settings.class = classes;
|
|
1549
|
+
this.render.updateClassStyles();
|
|
1550
|
+
};
|
|
1539
1551
|
this.select.onDisabledChange = (disabled) => {
|
|
1540
1552
|
if (disabled) {
|
|
1541
1553
|
this.disable();
|
|
@@ -1614,7 +1626,7 @@ class SlimSelect {
|
|
|
1614
1626
|
getSelected() {
|
|
1615
1627
|
return this.store.getSelected();
|
|
1616
1628
|
}
|
|
1617
|
-
setSelected(value) {
|
|
1629
|
+
setSelected(value, runAfterChange = true) {
|
|
1618
1630
|
const selected = this.store.getSelected();
|
|
1619
1631
|
this.store.setSelectedBy('value', Array.isArray(value) ? value : [value]);
|
|
1620
1632
|
const data = this.store.getData();
|
|
@@ -1626,7 +1638,7 @@ class SlimSelect {
|
|
|
1626
1638
|
else {
|
|
1627
1639
|
this.render.renderOptions(data);
|
|
1628
1640
|
}
|
|
1629
|
-
if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
1641
|
+
if (runAfterChange && this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
1630
1642
|
this.events.afterChange(this.store.getSelectedOptions());
|
|
1631
1643
|
}
|
|
1632
1644
|
}
|
|
@@ -1673,7 +1685,9 @@ class SlimSelect {
|
|
|
1673
1685
|
this.events.beforeClose();
|
|
1674
1686
|
}
|
|
1675
1687
|
this.render.close();
|
|
1676
|
-
this.search
|
|
1688
|
+
if (this.render.content.search.input.value !== '') {
|
|
1689
|
+
this.search('');
|
|
1690
|
+
}
|
|
1677
1691
|
this.render.mainFocus(false);
|
|
1678
1692
|
setTimeout(() => {
|
|
1679
1693
|
if (this.events.afterClose) {
|
|
@@ -67,6 +67,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
67
67
|
select: {
|
|
68
68
|
select: HTMLSelectElement;
|
|
69
69
|
onValueChange?: ((value: string[]) => void) | undefined;
|
|
70
|
+
onClassChange?: ((classes: string[]) => void) | undefined;
|
|
70
71
|
onDisabledChange?: ((disabled: boolean) => void) | undefined;
|
|
71
72
|
onOptionsChange?: ((data: DataArrayPartial) => void) | undefined;
|
|
72
73
|
listen: boolean;
|
|
@@ -161,7 +162,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
161
162
|
open: () => void;
|
|
162
163
|
close: () => void;
|
|
163
164
|
addable?: ((value: string) => string | import("../slim-select/store").OptionOptional | Promise<string | import("../slim-select/store").OptionOptional>) | undefined;
|
|
164
|
-
setSelected: (value: string[]) => void;
|
|
165
|
+
setSelected: (value: string[], runAfterChange: boolean) => void;
|
|
165
166
|
addOption: (option: Option) => void;
|
|
166
167
|
search: (search: string) => void;
|
|
167
168
|
beforeChange?: ((newVal: Option[], oldVal: Option[]) => boolean | void) | undefined;
|
|
@@ -239,6 +240,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
239
240
|
disable: () => void;
|
|
240
241
|
open: () => void;
|
|
241
242
|
close: () => void;
|
|
243
|
+
updateClassStyles: () => void;
|
|
242
244
|
mainDiv: () => import("../slim-select/render").Main;
|
|
243
245
|
mainFocus: (trigger: boolean) => void;
|
|
244
246
|
placeholder: () => HTMLDivElement;
|
|
@@ -278,7 +280,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
278
280
|
getData: () => import("../slim-select/store").DataArray;
|
|
279
281
|
setData: (data: DataArrayPartial) => void;
|
|
280
282
|
getSelected: () => string[];
|
|
281
|
-
setSelected: (value: string | string[]) => void;
|
|
283
|
+
setSelected: (value: string | string[], runAfterChange?: boolean) => void;
|
|
282
284
|
addOption: (option: import("../slim-select/store").OptionOptional) => void;
|
|
283
285
|
open: () => void;
|
|
284
286
|
close: () => void;
|