slim-select 2.2.0 → 2.2.2

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.
Files changed (118) hide show
  1. package/dist/helpers.d.ts +1 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/select.d.ts +1 -1
  4. package/dist/slimselect.cjs.js +62 -40
  5. package/dist/slimselect.es.js +62 -40
  6. package/dist/slimselect.global.js +62 -40
  7. package/dist/slimselect.js +62 -40
  8. package/dist/slimselect.min.js +1 -1
  9. package/dist/slimselect.umd.js +62 -40
  10. package/dist/slimselect.umd.min.js +1 -1
  11. package/package.json +1 -3
  12. package/src/slim-select/helpers.ts +4 -0
  13. package/src/slim-select/index.ts +26 -2
  14. package/src/slim-select/render.ts +5 -3
  15. package/src/slim-select/select.ts +12 -3
  16. package/src/vue/dist/slim-select/helpers.d.ts +5 -0
  17. package/src/vue/dist/slim-select/index.d.ts +45 -0
  18. package/src/vue/dist/slim-select/render.d.ts +116 -0
  19. package/src/vue/dist/slim-select/select.d.ts +33 -0
  20. package/src/vue/dist/slim-select/settings.d.ts +30 -0
  21. package/src/vue/dist/slim-select/store.d.ts +76 -0
  22. package/src/vue/dist/slimselectvue.es.js +114 -43
  23. package/src/vue/dist/slimselectvue.global.js +114 -43
  24. package/src/vue/dist/slimselectvue.ssr.js +114 -43
  25. package/src/vue/dist/vue/hello.d.ts +2 -0
  26. package/src/vue/dist/vue/slimselect.vue.d.ts +309 -0
  27. package/src/vue/package.json +2 -3
  28. package/src/vue/slimselect.vue +66 -2
  29. package/src/vue/tsconfig.json +3 -3
  30. package/tsconfig.json +9 -2
  31. package/.github/FUNDING.yml +0 -12
  32. package/.github/ISSUE_TEMPLATE/issue-report.md +0 -14
  33. package/.vscode/extensions.json +0 -3
  34. package/.vscode/settings.json +0 -17
  35. package/docs/404.html +0 -42
  36. package/docs/CNAME +0 -1
  37. package/docs/assets/check-mark.svg +0 -6
  38. package/docs/assets/data.js +0 -63
  39. package/docs/assets/home.css +0 -1
  40. package/docs/assets/home.js +0 -1
  41. package/docs/assets/index.css +0 -1
  42. package/docs/assets/index.js +0 -16
  43. package/docs/assets/index2.js +0 -358
  44. package/docs/assets/index3.js +0 -142
  45. package/docs/assets/index4.js +0 -60
  46. package/docs/assets/index5.js +0 -149
  47. package/docs/assets/install.js +0 -34
  48. package/docs/assets/selects.js +0 -55
  49. package/docs/favicon.ico +0 -0
  50. package/docs/index.html +0 -36
  51. package/public/404.html +0 -42
  52. package/public/CNAME +0 -1
  53. package/public/favicon.ico +0 -0
  54. package/slimselect.gif +0 -0
  55. package/src/docs/app.vue +0 -228
  56. package/src/docs/assets/images/check-mark.svg +0 -6
  57. package/src/docs/assets/images/chrome.svg +0 -22
  58. package/src/docs/assets/images/firefox.svg +0 -58
  59. package/src/docs/assets/images/github.png +0 -0
  60. package/src/docs/assets/images/ie.svg +0 -11
  61. package/src/docs/assets/images/npm.png +0 -0
  62. package/src/docs/assets/images/opera.svg +0 -15
  63. package/src/docs/assets/images/safari.svg +0 -22
  64. package/src/docs/assets/scss/_variables.scss +0 -26
  65. package/src/docs/assets/scss/alert.scss +0 -12
  66. package/src/docs/assets/scss/animations.scss +0 -8
  67. package/src/docs/assets/scss/button.scss +0 -21
  68. package/src/docs/assets/scss/index.scss +0 -8
  69. package/src/docs/assets/scss/input.scss +0 -3
  70. package/src/docs/assets/scss/layout.scss +0 -250
  71. package/src/docs/assets/scss/misc.scss +0 -162
  72. package/src/docs/assets/scss/prism.scss +0 -157
  73. package/src/docs/env.d.ts +0 -13
  74. package/src/docs/main.ts +0 -27
  75. package/src/docs/pages/data.vue +0 -134
  76. package/src/docs/pages/events/addable.vue +0 -95
  77. package/src/docs/pages/events/before_after_change.vue +0 -154
  78. package/src/docs/pages/events/before_after_open_close.vue +0 -122
  79. package/src/docs/pages/events/error.vue +0 -59
  80. package/src/docs/pages/events/index.vue +0 -33
  81. package/src/docs/pages/events/search.vue +0 -169
  82. package/src/docs/pages/events/search_filter.vue +0 -45
  83. package/src/docs/pages/frameworks/index.vue +0 -18
  84. package/src/docs/pages/frameworks/vue.vue +0 -407
  85. package/src/docs/pages/home.vue +0 -241
  86. package/src/docs/pages/install.vue +0 -105
  87. package/src/docs/pages/methods/destroy.vue +0 -66
  88. package/src/docs/pages/methods/enable_disable.vue +0 -70
  89. package/src/docs/pages/methods/get_data.vue +0 -82
  90. package/src/docs/pages/methods/get_selected.vue +0 -78
  91. package/src/docs/pages/methods/index.vue +0 -36
  92. package/src/docs/pages/methods/open_close.vue +0 -63
  93. package/src/docs/pages/methods/search.vue +0 -62
  94. package/src/docs/pages/methods/set_data.vue +0 -106
  95. package/src/docs/pages/methods/set_selected.vue +0 -70
  96. package/src/docs/pages/selects.vue +0 -213
  97. package/src/docs/pages/settings/always_open.vue +0 -88
  98. package/src/docs/pages/settings/closable.vue +0 -128
  99. package/src/docs/pages/settings/close_on_select.vue +0 -69
  100. package/src/docs/pages/settings/content_location.vue +0 -64
  101. package/src/docs/pages/settings/content_position.vue +0 -86
  102. package/src/docs/pages/settings/css.vue +0 -73
  103. package/src/docs/pages/settings/data_attributes.vue +0 -39
  104. package/src/docs/pages/settings/deselect.vue +0 -69
  105. package/src/docs/pages/settings/display.vue +0 -88
  106. package/src/docs/pages/settings/hide_selected.vue +0 -73
  107. package/src/docs/pages/settings/html.vue +0 -86
  108. package/src/docs/pages/settings/index.vue +0 -76
  109. package/src/docs/pages/settings/mandatory.vue +0 -91
  110. package/src/docs/pages/settings/min_max.vue +0 -61
  111. package/src/docs/pages/settings/open_position.vue +0 -60
  112. package/src/docs/pages/settings/placeholder.vue +0 -72
  113. package/src/docs/pages/settings/search.vue +0 -140
  114. package/src/docs/pages/settings/select.vue +0 -32
  115. package/src/docs/pages/settings/select_all.vue +0 -88
  116. package/src/docs/pages/settings/show_tooltip.vue +0 -44
  117. package/src/docs/pages/settings/styles.vue +0 -51
  118. package/src/docs/router.ts +0 -50
package/dist/helpers.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export declare function generateID(): string;
2
2
  export declare function hasClassInTree(element: HTMLElement, className: string): any;
3
3
  export declare function debounce(func: (...params: any[]) => void, wait?: number, immediate?: boolean): () => void;
4
+ export declare function isEqual(a: any, b: any): boolean;
4
5
  export declare function kebabCase(str: string): string;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import Settings, { SettingsPartial } from './settings';
1
2
  import Render from './render';
2
3
  import Select from './select';
3
- import Settings, { SettingsPartial } from './settings';
4
4
  import Store, { DataArray, DataArrayPartial, Option, OptionOptional } from './store';
5
5
  export interface Config {
6
6
  select: string | Element;
package/dist/select.d.ts CHANGED
@@ -15,7 +15,7 @@ export default class Select {
15
15
  removeSelectChangeListener(): void;
16
16
  addValueChangeListener(func: (value: string[]) => void): void;
17
17
  removeValueChangeListener(): void;
18
- valueChange(ev: Event): any;
18
+ valueChange(ev: Event): boolean;
19
19
  private observeWrapper;
20
20
  private addObserver;
21
21
  private connectObserver;
@@ -44,11 +44,50 @@ function debounce(func, wait = 50, immediate = false) {
44
44
  }
45
45
  };
46
46
  }
47
+ function isEqual(a, b) {
48
+ return JSON.stringify(a) === JSON.stringify(b);
49
+ }
47
50
  function kebabCase(str) {
48
51
  const result = str.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (match) => '-' + match.toLowerCase());
49
52
  return str[0] === str[0].toUpperCase() ? result.substring(1) : result;
50
53
  }
51
54
 
55
+ class Settings {
56
+ constructor(settings) {
57
+ this.id = '';
58
+ this.style = '';
59
+ this.class = [];
60
+ this.isMultiple = false;
61
+ this.isOpen = false;
62
+ this.triggerFocus = true;
63
+ this.intervalMove = null;
64
+ if (!settings) {
65
+ settings = {};
66
+ }
67
+ this.id = 'ss-' + generateID();
68
+ this.style = settings.style || '';
69
+ this.class = settings.class || [];
70
+ this.isEnabled = settings.isEnabled !== undefined ? settings.isEnabled : true;
71
+ this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
72
+ this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
73
+ this.searchPlaceholder = settings.searchPlaceholder || 'Search';
74
+ this.searchText = settings.searchText || 'No Results';
75
+ this.searchingText = settings.searchingText || 'Searching...';
76
+ this.searchHighlight = settings.searchHighlight !== undefined ? settings.searchHighlight : false;
77
+ this.closeOnSelect = settings.closeOnSelect !== undefined ? settings.closeOnSelect : true;
78
+ this.contentLocation = settings.contentLocation || document.body;
79
+ this.contentPosition = settings.contentPosition || 'absolute';
80
+ this.openPosition = settings.openPosition || 'auto';
81
+ this.placeholderText = settings.placeholderText || 'Select Value';
82
+ this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;
83
+ this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;
84
+ this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;
85
+ this.minSelected = settings.minSelected || 0;
86
+ this.maxSelected = settings.maxSelected || 1000;
87
+ this.timeoutDelay = settings.timeoutDelay || 200;
88
+ }
89
+ }
90
+
52
91
  class Optgroup {
53
92
  constructor(optgroup) {
54
93
  this.id = !optgroup.id || optgroup.id === '' ? generateID() : optgroup.id;
@@ -942,9 +981,12 @@ class Render {
942
981
  optgroupClosableSvg.classList.add(this.classes.arrow);
943
982
  optgroupClosable.appendChild(optgroupClosableSvg);
944
983
  const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
945
- optgroupClosableArrow.setAttribute('d', this.classes.arrow);
946
984
  optgroupClosableSvg.appendChild(optgroupClosableArrow);
947
- if (d.closable === 'open') {
985
+ if (d.options.some((o) => o.selected)) {
986
+ optgroupClosable.classList.add(this.classes.open);
987
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
988
+ }
989
+ else if (d.closable === 'open') {
948
990
  optgroupEl.classList.add(this.classes.open);
949
991
  optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
950
992
  }
@@ -1191,16 +1233,19 @@ class Select {
1191
1233
  }
1192
1234
  addValueChangeListener(func) {
1193
1235
  this.onValueChange = func;
1194
- this.select.addEventListener('change', this.valueChange.bind(this));
1236
+ this.select.addEventListener('change', this.valueChange.bind(this), {
1237
+ passive: true,
1238
+ });
1195
1239
  }
1196
1240
  removeValueChangeListener() {
1197
1241
  this.onValueChange = undefined;
1198
1242
  this.select.removeEventListener('change', this.valueChange.bind(this));
1199
1243
  }
1200
1244
  valueChange(ev) {
1201
- if (this.onValueChange) {
1245
+ if (this.listen && this.onValueChange) {
1202
1246
  this.onValueChange(this.getSelectedValues());
1203
1247
  }
1248
+ return true;
1204
1249
  }
1205
1250
  observeWrapper(mutations) {
1206
1251
  if (this.onSelectChange) {
@@ -1345,6 +1390,7 @@ class Select {
1345
1390
  this.select.appendChild(this.createOption(d));
1346
1391
  }
1347
1392
  }
1393
+ this.select.dispatchEvent(new Event('change'));
1348
1394
  this.changeListen(true);
1349
1395
  }
1350
1396
  createOptgroup(optgroup) {
@@ -1404,42 +1450,6 @@ class Select {
1404
1450
  }
1405
1451
  }
1406
1452
 
1407
- class Settings {
1408
- constructor(settings) {
1409
- this.id = '';
1410
- this.style = '';
1411
- this.class = [];
1412
- this.isMultiple = false;
1413
- this.isOpen = false;
1414
- this.triggerFocus = true;
1415
- this.intervalMove = null;
1416
- if (!settings) {
1417
- settings = {};
1418
- }
1419
- this.id = 'ss-' + generateID();
1420
- this.style = settings.style || '';
1421
- this.class = settings.class || [];
1422
- this.isEnabled = settings.isEnabled !== undefined ? settings.isEnabled : true;
1423
- this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
1424
- this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
1425
- this.searchPlaceholder = settings.searchPlaceholder || 'Search';
1426
- this.searchText = settings.searchText || 'No Results';
1427
- this.searchingText = settings.searchingText || 'Searching...';
1428
- this.searchHighlight = settings.searchHighlight !== undefined ? settings.searchHighlight : false;
1429
- this.closeOnSelect = settings.closeOnSelect !== undefined ? settings.closeOnSelect : true;
1430
- this.contentLocation = settings.contentLocation || document.body;
1431
- this.contentPosition = settings.contentPosition || 'absolute';
1432
- this.openPosition = settings.openPosition || 'auto';
1433
- this.placeholderText = settings.placeholderText || 'Select Value';
1434
- this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;
1435
- this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;
1436
- this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;
1437
- this.minSelected = settings.minSelected || 0;
1438
- this.maxSelected = settings.maxSelected || 1000;
1439
- this.timeoutDelay = settings.timeoutDelay || 200;
1440
- }
1441
- }
1442
-
1443
1453
  class SlimSelect {
1444
1454
  constructor(config) {
1445
1455
  this.events = {
@@ -1572,6 +1582,7 @@ class SlimSelect {
1572
1582
  return this.store.getData();
1573
1583
  }
1574
1584
  setData(data) {
1585
+ const selected = this.store.getSelected();
1575
1586
  const err = this.store.validateDataArray(data);
1576
1587
  if (err) {
1577
1588
  if (this.events.error) {
@@ -1584,23 +1595,34 @@ class SlimSelect {
1584
1595
  this.select.updateOptions(dataClean);
1585
1596
  this.render.renderValues();
1586
1597
  this.render.renderOptions(dataClean);
1598
+ if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
1599
+ this.events.afterChange(this.store.getSelectedOptions());
1600
+ }
1587
1601
  }
1588
1602
  getSelected() {
1589
1603
  return this.store.getSelected();
1590
1604
  }
1591
1605
  setSelected(value) {
1606
+ const selected = this.store.getSelected();
1592
1607
  this.store.setSelectedBy('value', Array.isArray(value) ? value : [value]);
1593
1608
  const data = this.store.getData();
1594
1609
  this.select.updateOptions(data);
1595
1610
  this.render.renderValues();
1596
1611
  this.render.renderOptions(data);
1612
+ if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
1613
+ this.events.afterChange(this.store.getSelectedOptions());
1614
+ }
1597
1615
  }
1598
1616
  addOption(option) {
1617
+ const selected = this.store.getSelected();
1599
1618
  this.store.addOption(option);
1600
1619
  const data = this.store.getData();
1601
1620
  this.select.updateOptions(data);
1602
1621
  this.render.renderValues();
1603
1622
  this.render.renderOptions(data);
1623
+ if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
1624
+ this.events.afterChange(this.store.getSelectedOptions());
1625
+ }
1604
1626
  }
1605
1627
  open() {
1606
1628
  if (!this.settings.isEnabled || this.settings.isOpen) {
@@ -42,11 +42,50 @@ function debounce(func, wait = 50, immediate = false) {
42
42
  }
43
43
  };
44
44
  }
45
+ function isEqual(a, b) {
46
+ return JSON.stringify(a) === JSON.stringify(b);
47
+ }
45
48
  function kebabCase(str) {
46
49
  const result = str.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (match) => '-' + match.toLowerCase());
47
50
  return str[0] === str[0].toUpperCase() ? result.substring(1) : result;
48
51
  }
49
52
 
53
+ class Settings {
54
+ constructor(settings) {
55
+ this.id = '';
56
+ this.style = '';
57
+ this.class = [];
58
+ this.isMultiple = false;
59
+ this.isOpen = false;
60
+ this.triggerFocus = true;
61
+ this.intervalMove = null;
62
+ if (!settings) {
63
+ settings = {};
64
+ }
65
+ this.id = 'ss-' + generateID();
66
+ this.style = settings.style || '';
67
+ this.class = settings.class || [];
68
+ this.isEnabled = settings.isEnabled !== undefined ? settings.isEnabled : true;
69
+ this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
70
+ this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
71
+ this.searchPlaceholder = settings.searchPlaceholder || 'Search';
72
+ this.searchText = settings.searchText || 'No Results';
73
+ this.searchingText = settings.searchingText || 'Searching...';
74
+ this.searchHighlight = settings.searchHighlight !== undefined ? settings.searchHighlight : false;
75
+ this.closeOnSelect = settings.closeOnSelect !== undefined ? settings.closeOnSelect : true;
76
+ this.contentLocation = settings.contentLocation || document.body;
77
+ this.contentPosition = settings.contentPosition || 'absolute';
78
+ this.openPosition = settings.openPosition || 'auto';
79
+ this.placeholderText = settings.placeholderText || 'Select Value';
80
+ this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;
81
+ this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;
82
+ this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;
83
+ this.minSelected = settings.minSelected || 0;
84
+ this.maxSelected = settings.maxSelected || 1000;
85
+ this.timeoutDelay = settings.timeoutDelay || 200;
86
+ }
87
+ }
88
+
50
89
  class Optgroup {
51
90
  constructor(optgroup) {
52
91
  this.id = !optgroup.id || optgroup.id === '' ? generateID() : optgroup.id;
@@ -940,9 +979,12 @@ class Render {
940
979
  optgroupClosableSvg.classList.add(this.classes.arrow);
941
980
  optgroupClosable.appendChild(optgroupClosableSvg);
942
981
  const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
943
- optgroupClosableArrow.setAttribute('d', this.classes.arrow);
944
982
  optgroupClosableSvg.appendChild(optgroupClosableArrow);
945
- if (d.closable === 'open') {
983
+ if (d.options.some((o) => o.selected)) {
984
+ optgroupClosable.classList.add(this.classes.open);
985
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
986
+ }
987
+ else if (d.closable === 'open') {
946
988
  optgroupEl.classList.add(this.classes.open);
947
989
  optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
948
990
  }
@@ -1189,16 +1231,19 @@ class Select {
1189
1231
  }
1190
1232
  addValueChangeListener(func) {
1191
1233
  this.onValueChange = func;
1192
- this.select.addEventListener('change', this.valueChange.bind(this));
1234
+ this.select.addEventListener('change', this.valueChange.bind(this), {
1235
+ passive: true,
1236
+ });
1193
1237
  }
1194
1238
  removeValueChangeListener() {
1195
1239
  this.onValueChange = undefined;
1196
1240
  this.select.removeEventListener('change', this.valueChange.bind(this));
1197
1241
  }
1198
1242
  valueChange(ev) {
1199
- if (this.onValueChange) {
1243
+ if (this.listen && this.onValueChange) {
1200
1244
  this.onValueChange(this.getSelectedValues());
1201
1245
  }
1246
+ return true;
1202
1247
  }
1203
1248
  observeWrapper(mutations) {
1204
1249
  if (this.onSelectChange) {
@@ -1343,6 +1388,7 @@ class Select {
1343
1388
  this.select.appendChild(this.createOption(d));
1344
1389
  }
1345
1390
  }
1391
+ this.select.dispatchEvent(new Event('change'));
1346
1392
  this.changeListen(true);
1347
1393
  }
1348
1394
  createOptgroup(optgroup) {
@@ -1402,42 +1448,6 @@ class Select {
1402
1448
  }
1403
1449
  }
1404
1450
 
1405
- class Settings {
1406
- constructor(settings) {
1407
- this.id = '';
1408
- this.style = '';
1409
- this.class = [];
1410
- this.isMultiple = false;
1411
- this.isOpen = false;
1412
- this.triggerFocus = true;
1413
- this.intervalMove = null;
1414
- if (!settings) {
1415
- settings = {};
1416
- }
1417
- this.id = 'ss-' + generateID();
1418
- this.style = settings.style || '';
1419
- this.class = settings.class || [];
1420
- this.isEnabled = settings.isEnabled !== undefined ? settings.isEnabled : true;
1421
- this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
1422
- this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
1423
- this.searchPlaceholder = settings.searchPlaceholder || 'Search';
1424
- this.searchText = settings.searchText || 'No Results';
1425
- this.searchingText = settings.searchingText || 'Searching...';
1426
- this.searchHighlight = settings.searchHighlight !== undefined ? settings.searchHighlight : false;
1427
- this.closeOnSelect = settings.closeOnSelect !== undefined ? settings.closeOnSelect : true;
1428
- this.contentLocation = settings.contentLocation || document.body;
1429
- this.contentPosition = settings.contentPosition || 'absolute';
1430
- this.openPosition = settings.openPosition || 'auto';
1431
- this.placeholderText = settings.placeholderText || 'Select Value';
1432
- this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;
1433
- this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;
1434
- this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;
1435
- this.minSelected = settings.minSelected || 0;
1436
- this.maxSelected = settings.maxSelected || 1000;
1437
- this.timeoutDelay = settings.timeoutDelay || 200;
1438
- }
1439
- }
1440
-
1441
1451
  class SlimSelect {
1442
1452
  constructor(config) {
1443
1453
  this.events = {
@@ -1570,6 +1580,7 @@ class SlimSelect {
1570
1580
  return this.store.getData();
1571
1581
  }
1572
1582
  setData(data) {
1583
+ const selected = this.store.getSelected();
1573
1584
  const err = this.store.validateDataArray(data);
1574
1585
  if (err) {
1575
1586
  if (this.events.error) {
@@ -1582,23 +1593,34 @@ class SlimSelect {
1582
1593
  this.select.updateOptions(dataClean);
1583
1594
  this.render.renderValues();
1584
1595
  this.render.renderOptions(dataClean);
1596
+ if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
1597
+ this.events.afterChange(this.store.getSelectedOptions());
1598
+ }
1585
1599
  }
1586
1600
  getSelected() {
1587
1601
  return this.store.getSelected();
1588
1602
  }
1589
1603
  setSelected(value) {
1604
+ const selected = this.store.getSelected();
1590
1605
  this.store.setSelectedBy('value', Array.isArray(value) ? value : [value]);
1591
1606
  const data = this.store.getData();
1592
1607
  this.select.updateOptions(data);
1593
1608
  this.render.renderValues();
1594
1609
  this.render.renderOptions(data);
1610
+ if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
1611
+ this.events.afterChange(this.store.getSelectedOptions());
1612
+ }
1595
1613
  }
1596
1614
  addOption(option) {
1615
+ const selected = this.store.getSelected();
1597
1616
  this.store.addOption(option);
1598
1617
  const data = this.store.getData();
1599
1618
  this.select.updateOptions(data);
1600
1619
  this.render.renderValues();
1601
1620
  this.render.renderOptions(data);
1621
+ if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
1622
+ this.events.afterChange(this.store.getSelectedOptions());
1623
+ }
1602
1624
  }
1603
1625
  open() {
1604
1626
  if (!this.settings.isEnabled || this.settings.isOpen) {
@@ -45,11 +45,50 @@ var SlimSelect = (function () {
45
45
  }
46
46
  };
47
47
  }
48
+ function isEqual(a, b) {
49
+ return JSON.stringify(a) === JSON.stringify(b);
50
+ }
48
51
  function kebabCase(str) {
49
52
  const result = str.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (match) => '-' + match.toLowerCase());
50
53
  return str[0] === str[0].toUpperCase() ? result.substring(1) : result;
51
54
  }
52
55
 
56
+ class Settings {
57
+ constructor(settings) {
58
+ this.id = '';
59
+ this.style = '';
60
+ this.class = [];
61
+ this.isMultiple = false;
62
+ this.isOpen = false;
63
+ this.triggerFocus = true;
64
+ this.intervalMove = null;
65
+ if (!settings) {
66
+ settings = {};
67
+ }
68
+ this.id = 'ss-' + generateID();
69
+ this.style = settings.style || '';
70
+ this.class = settings.class || [];
71
+ this.isEnabled = settings.isEnabled !== undefined ? settings.isEnabled : true;
72
+ this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
73
+ this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
74
+ this.searchPlaceholder = settings.searchPlaceholder || 'Search';
75
+ this.searchText = settings.searchText || 'No Results';
76
+ this.searchingText = settings.searchingText || 'Searching...';
77
+ this.searchHighlight = settings.searchHighlight !== undefined ? settings.searchHighlight : false;
78
+ this.closeOnSelect = settings.closeOnSelect !== undefined ? settings.closeOnSelect : true;
79
+ this.contentLocation = settings.contentLocation || document.body;
80
+ this.contentPosition = settings.contentPosition || 'absolute';
81
+ this.openPosition = settings.openPosition || 'auto';
82
+ this.placeholderText = settings.placeholderText || 'Select Value';
83
+ this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;
84
+ this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;
85
+ this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;
86
+ this.minSelected = settings.minSelected || 0;
87
+ this.maxSelected = settings.maxSelected || 1000;
88
+ this.timeoutDelay = settings.timeoutDelay || 200;
89
+ }
90
+ }
91
+
53
92
  class Optgroup {
54
93
  constructor(optgroup) {
55
94
  this.id = !optgroup.id || optgroup.id === '' ? generateID() : optgroup.id;
@@ -943,9 +982,12 @@ var SlimSelect = (function () {
943
982
  optgroupClosableSvg.classList.add(this.classes.arrow);
944
983
  optgroupClosable.appendChild(optgroupClosableSvg);
945
984
  const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
946
- optgroupClosableArrow.setAttribute('d', this.classes.arrow);
947
985
  optgroupClosableSvg.appendChild(optgroupClosableArrow);
948
- if (d.closable === 'open') {
986
+ if (d.options.some((o) => o.selected)) {
987
+ optgroupClosable.classList.add(this.classes.open);
988
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
989
+ }
990
+ else if (d.closable === 'open') {
949
991
  optgroupEl.classList.add(this.classes.open);
950
992
  optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
951
993
  }
@@ -1192,16 +1234,19 @@ var SlimSelect = (function () {
1192
1234
  }
1193
1235
  addValueChangeListener(func) {
1194
1236
  this.onValueChange = func;
1195
- this.select.addEventListener('change', this.valueChange.bind(this));
1237
+ this.select.addEventListener('change', this.valueChange.bind(this), {
1238
+ passive: true,
1239
+ });
1196
1240
  }
1197
1241
  removeValueChangeListener() {
1198
1242
  this.onValueChange = undefined;
1199
1243
  this.select.removeEventListener('change', this.valueChange.bind(this));
1200
1244
  }
1201
1245
  valueChange(ev) {
1202
- if (this.onValueChange) {
1246
+ if (this.listen && this.onValueChange) {
1203
1247
  this.onValueChange(this.getSelectedValues());
1204
1248
  }
1249
+ return true;
1205
1250
  }
1206
1251
  observeWrapper(mutations) {
1207
1252
  if (this.onSelectChange) {
@@ -1346,6 +1391,7 @@ var SlimSelect = (function () {
1346
1391
  this.select.appendChild(this.createOption(d));
1347
1392
  }
1348
1393
  }
1394
+ this.select.dispatchEvent(new Event('change'));
1349
1395
  this.changeListen(true);
1350
1396
  }
1351
1397
  createOptgroup(optgroup) {
@@ -1405,42 +1451,6 @@ var SlimSelect = (function () {
1405
1451
  }
1406
1452
  }
1407
1453
 
1408
- class Settings {
1409
- constructor(settings) {
1410
- this.id = '';
1411
- this.style = '';
1412
- this.class = [];
1413
- this.isMultiple = false;
1414
- this.isOpen = false;
1415
- this.triggerFocus = true;
1416
- this.intervalMove = null;
1417
- if (!settings) {
1418
- settings = {};
1419
- }
1420
- this.id = 'ss-' + generateID();
1421
- this.style = settings.style || '';
1422
- this.class = settings.class || [];
1423
- this.isEnabled = settings.isEnabled !== undefined ? settings.isEnabled : true;
1424
- this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
1425
- this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
1426
- this.searchPlaceholder = settings.searchPlaceholder || 'Search';
1427
- this.searchText = settings.searchText || 'No Results';
1428
- this.searchingText = settings.searchingText || 'Searching...';
1429
- this.searchHighlight = settings.searchHighlight !== undefined ? settings.searchHighlight : false;
1430
- this.closeOnSelect = settings.closeOnSelect !== undefined ? settings.closeOnSelect : true;
1431
- this.contentLocation = settings.contentLocation || document.body;
1432
- this.contentPosition = settings.contentPosition || 'absolute';
1433
- this.openPosition = settings.openPosition || 'auto';
1434
- this.placeholderText = settings.placeholderText || 'Select Value';
1435
- this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;
1436
- this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;
1437
- this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;
1438
- this.minSelected = settings.minSelected || 0;
1439
- this.maxSelected = settings.maxSelected || 1000;
1440
- this.timeoutDelay = settings.timeoutDelay || 200;
1441
- }
1442
- }
1443
-
1444
1454
  class SlimSelect {
1445
1455
  constructor(config) {
1446
1456
  this.events = {
@@ -1573,6 +1583,7 @@ var SlimSelect = (function () {
1573
1583
  return this.store.getData();
1574
1584
  }
1575
1585
  setData(data) {
1586
+ const selected = this.store.getSelected();
1576
1587
  const err = this.store.validateDataArray(data);
1577
1588
  if (err) {
1578
1589
  if (this.events.error) {
@@ -1585,23 +1596,34 @@ var SlimSelect = (function () {
1585
1596
  this.select.updateOptions(dataClean);
1586
1597
  this.render.renderValues();
1587
1598
  this.render.renderOptions(dataClean);
1599
+ if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
1600
+ this.events.afterChange(this.store.getSelectedOptions());
1601
+ }
1588
1602
  }
1589
1603
  getSelected() {
1590
1604
  return this.store.getSelected();
1591
1605
  }
1592
1606
  setSelected(value) {
1607
+ const selected = this.store.getSelected();
1593
1608
  this.store.setSelectedBy('value', Array.isArray(value) ? value : [value]);
1594
1609
  const data = this.store.getData();
1595
1610
  this.select.updateOptions(data);
1596
1611
  this.render.renderValues();
1597
1612
  this.render.renderOptions(data);
1613
+ if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
1614
+ this.events.afterChange(this.store.getSelectedOptions());
1615
+ }
1598
1616
  }
1599
1617
  addOption(option) {
1618
+ const selected = this.store.getSelected();
1600
1619
  this.store.addOption(option);
1601
1620
  const data = this.store.getData();
1602
1621
  this.select.updateOptions(data);
1603
1622
  this.render.renderValues();
1604
1623
  this.render.renderOptions(data);
1624
+ if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
1625
+ this.events.afterChange(this.store.getSelectedOptions());
1626
+ }
1605
1627
  }
1606
1628
  open() {
1607
1629
  if (!this.settings.isEnabled || this.settings.isOpen) {