slim-select 2.1.0 → 2.2.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.
Files changed (46) hide show
  1. package/README.md +8 -0
  2. package/dist/render.d.ts +9 -2
  3. package/dist/select.d.ts +6 -6
  4. package/dist/settings.d.ts +0 -3
  5. package/dist/slimselect.cjs.js +148 -51
  6. package/dist/slimselect.css +1 -1
  7. package/dist/slimselect.css.map +1 -1
  8. package/dist/slimselect.es.js +148 -51
  9. package/dist/slimselect.global.js +148 -51
  10. package/dist/slimselect.js +148 -51
  11. package/dist/slimselect.min.js +1 -1
  12. package/dist/slimselect.umd.js +148 -51
  13. package/dist/slimselect.umd.min.js +1 -1
  14. package/dist/store.d.ts +5 -0
  15. package/docs/assets/data.js +7 -3
  16. package/docs/assets/home.css +1 -1
  17. package/docs/assets/home.js +1 -1
  18. package/docs/assets/index.css +1 -1
  19. package/docs/assets/index.js +7 -7
  20. package/docs/assets/index2.js +119 -35
  21. package/docs/assets/index3.js +22 -15
  22. package/docs/assets/index4.js +1 -1
  23. package/docs/assets/index5.js +4 -2
  24. package/docs/assets/install.js +4 -4
  25. package/docs/assets/selects.js +1 -1
  26. package/package.json +2 -2
  27. package/src/docs/app.vue +2 -1
  28. package/src/docs/pages/data.vue +4 -0
  29. package/src/docs/pages/events/search.vue +29 -15
  30. package/src/docs/pages/frameworks/vue.vue +3 -1
  31. package/src/docs/pages/home.vue +104 -57
  32. package/src/docs/pages/settings/closable.vue +128 -0
  33. package/src/docs/pages/settings/index.vue +6 -3
  34. package/src/docs/pages/settings/select_all.vue +88 -0
  35. package/src/slim-select/index.ts +3 -1
  36. package/src/slim-select/render.ts +164 -34
  37. package/src/slim-select/select.ts +35 -27
  38. package/src/slim-select/settings.ts +0 -4
  39. package/src/slim-select/slimselect.scss +112 -11
  40. package/src/slim-select/store.ts +19 -1
  41. package/src/vue/README.md +48 -0
  42. package/src/vue/dist/slimselectvue.es.js +148 -51
  43. package/src/vue/dist/slimselectvue.global.js +148 -51
  44. package/src/vue/dist/slimselectvue.ssr.js +148 -51
  45. package/src/vue/package.json +3 -2
  46. package/src/docs/pages/settings/select_by_group.vue +0 -46
@@ -51,6 +51,8 @@ class Optgroup {
51
51
  constructor(optgroup) {
52
52
  this.id = !optgroup.id || optgroup.id === '' ? generateID() : optgroup.id;
53
53
  this.label = optgroup.label || '';
54
+ this.selectAll = optgroup.selectAll === undefined ? false : optgroup.selectAll;
55
+ this.closable = optgroup.closable || 'off';
54
56
  this.options = [];
55
57
  if (optgroup.options) {
56
58
  for (const o of optgroup.options) {
@@ -197,6 +199,14 @@ class Store {
197
199
  });
198
200
  return selectedIDs;
199
201
  }
202
+ getOptgroupByID(id) {
203
+ for (let dataObj of this.data) {
204
+ if (dataObj instanceof Optgroup && dataObj.id === id) {
205
+ return dataObj;
206
+ }
207
+ }
208
+ return null;
209
+ }
200
210
  getOptionByID(id) {
201
211
  let options = this.filter((opt) => {
202
212
  return opt.id === id;
@@ -231,7 +241,7 @@ class Store {
231
241
  }
232
242
  });
233
243
  if (optOptions.length > 0) {
234
- dataSearch.push(new Optgroup({ id: dataObj.id, label: dataObj.label, options: optOptions }));
244
+ dataSearch.push(new Optgroup(dataObj));
235
245
  }
236
246
  }
237
247
  }
@@ -272,11 +282,18 @@ class Render {
272
282
  list: 'ss-list',
273
283
  optgroup: 'ss-optgroup',
274
284
  optgroupLabel: 'ss-optgroup-label',
275
- optgroupSelectable: 'ss-optgroup-selectable',
285
+ optgroupLabelText: 'ss-optgroup-label-text',
286
+ optgroupActions: 'ss-optgroup-actions',
287
+ optgroupSelectAll: 'ss-selectall',
288
+ optgroupSelectAllBox: 'M60,10 L10,10 L10,90 L90,90 L90,50',
289
+ optgroupSelectAllCheck: 'M30,45 L50,70 L90,10',
290
+ optgroupClosable: 'ss-closable',
276
291
  option: 'ss-option',
277
- optionSelected: 'ss-option-selected',
278
292
  optionDelete: 'M10,10 L90,90 M10,90 L90,10',
279
293
  highlighted: 'ss-highlighted',
294
+ open: 'ss-open',
295
+ close: 'ss-close',
296
+ selected: 'ss-selected',
280
297
  error: 'ss-error',
281
298
  disabled: 'ss-disabled',
282
299
  hide: 'ss-hide',
@@ -286,8 +303,6 @@ class Render {
286
303
  this.callbacks = callbacks;
287
304
  this.main = this.mainDiv();
288
305
  this.content = this.contentDiv();
289
- this.renderValues();
290
- this.renderOptions(this.store.getData());
291
306
  this.settings.contentLocation.appendChild(this.content.main);
292
307
  }
293
308
  enable() {
@@ -800,25 +815,23 @@ class Render {
800
815
  }
801
816
  for (let i = 0; i < options.length; i++) {
802
817
  if (options[i].classList.contains(this.classes.highlighted)) {
803
- options[i].classList.remove(this.classes.highlighted);
804
- if (dir === 'down') {
805
- if (i + 1 < options.length) {
806
- options[i + 1].classList.add(this.classes.highlighted);
807
- this.ensureElementInView(this.content.list, options[i + 1]);
808
- }
809
- else {
810
- options[0].classList.add(this.classes.highlighted);
811
- this.ensureElementInView(this.content.list, options[0]);
818
+ const prevOption = options[i];
819
+ prevOption.classList.remove(this.classes.highlighted);
820
+ const prevParent = prevOption.parentElement;
821
+ if (prevParent && prevParent.classList.contains(this.classes.open)) {
822
+ const optgroupLabel = prevParent.querySelector('.' + this.classes.optgroupLabel);
823
+ if (optgroupLabel) {
824
+ optgroupLabel.click();
812
825
  }
813
826
  }
814
- else {
815
- if (i - 1 >= 0) {
816
- options[i - 1].classList.add(this.classes.highlighted);
817
- this.ensureElementInView(this.content.list, options[i - 1]);
818
- }
819
- else {
820
- options[options.length - 1].classList.add(this.classes.highlighted);
821
- this.ensureElementInView(this.content.list, options[options.length - 1]);
827
+ let selectOption = options[dir === 'down' ? (i + 1 < options.length ? i + 1 : 0) : i - 1 >= 0 ? i - 1 : options.length - 1];
828
+ selectOption.classList.add(this.classes.highlighted);
829
+ this.ensureElementInView(this.content.list, selectOption);
830
+ const selectParent = selectOption.parentElement;
831
+ if (selectParent && selectParent.classList.contains(this.classes.close)) {
832
+ const optgroupLabel = selectParent.querySelector('.' + this.classes.optgroupLabel);
833
+ if (optgroupLabel) {
834
+ optgroupLabel.click();
822
835
  }
823
836
  }
824
837
  return;
@@ -863,18 +876,95 @@ class Render {
863
876
  optgroupEl.classList.add(this.classes.optgroup);
864
877
  const optgroupLabel = document.createElement('div');
865
878
  optgroupLabel.classList.add(this.classes.optgroupLabel);
866
- optgroupLabel.innerHTML = d.label;
867
- if (this.settings.selectByGroup && this.settings.isMultiple) {
868
- optgroupLabel.classList.add(this.classes.optgroupSelectable);
879
+ optgroupEl.appendChild(optgroupLabel);
880
+ const optgroupLabelText = document.createElement('div');
881
+ optgroupLabelText.classList.add(this.classes.optgroupLabelText);
882
+ optgroupLabelText.textContent = d.label;
883
+ optgroupLabel.appendChild(optgroupLabelText);
884
+ const optgroupActions = document.createElement('div');
885
+ optgroupActions.classList.add(this.classes.optgroupActions);
886
+ optgroupLabel.appendChild(optgroupActions);
887
+ if (this.settings.isMultiple && d.selectAll) {
888
+ const selectAll = document.createElement('div');
889
+ selectAll.classList.add(this.classes.optgroupSelectAll);
890
+ let allSelected = true;
891
+ for (const o of d.options) {
892
+ if (!o.selected) {
893
+ allSelected = false;
894
+ break;
895
+ }
896
+ }
897
+ if (allSelected) {
898
+ selectAll.classList.add(this.classes.selected);
899
+ }
900
+ const selectAllText = document.createElement('span');
901
+ selectAllText.textContent = 'Select All';
902
+ selectAll.appendChild(selectAllText);
903
+ const selectAllSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
904
+ selectAllSvg.setAttribute('viewBox', '0 0 100 100');
905
+ selectAll.appendChild(selectAllSvg);
906
+ const selectAllBox = document.createElementNS('http://www.w3.org/2000/svg', 'path');
907
+ selectAllBox.setAttribute('d', this.classes.optgroupSelectAllBox);
908
+ selectAllSvg.appendChild(selectAllBox);
909
+ const selectAllCheck = document.createElementNS('http://www.w3.org/2000/svg', 'path');
910
+ selectAllCheck.setAttribute('d', this.classes.optgroupSelectAllCheck);
911
+ selectAllSvg.appendChild(selectAllCheck);
912
+ selectAll.addEventListener('click', (e) => {
913
+ e.preventDefault();
914
+ e.stopPropagation();
915
+ const currentSelected = this.store.getSelected();
916
+ if (allSelected) {
917
+ const newSelected = currentSelected.filter((s) => {
918
+ for (const o of d.options) {
919
+ if (s === o.value) {
920
+ return false;
921
+ }
922
+ }
923
+ return true;
924
+ });
925
+ this.callbacks.setSelected(newSelected);
926
+ return;
927
+ }
928
+ else {
929
+ const newSelected = currentSelected.concat(d.options.map((o) => o.value));
930
+ this.callbacks.setSelected(newSelected);
931
+ }
932
+ });
933
+ optgroupActions.appendChild(selectAll);
934
+ }
935
+ if (d.closable !== 'off') {
936
+ const optgroupClosable = document.createElement('div');
937
+ optgroupClosable.classList.add(this.classes.optgroupClosable);
938
+ const optgroupClosableSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
939
+ optgroupClosableSvg.setAttribute('viewBox', '0 0 100 100');
940
+ optgroupClosableSvg.classList.add(this.classes.arrow);
941
+ optgroupClosable.appendChild(optgroupClosableSvg);
942
+ const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
943
+ optgroupClosableArrow.setAttribute('d', this.classes.arrow);
944
+ optgroupClosableSvg.appendChild(optgroupClosableArrow);
945
+ if (d.closable === 'open') {
946
+ optgroupEl.classList.add(this.classes.open);
947
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
948
+ }
949
+ else if (d.closable === 'close') {
950
+ optgroupEl.classList.add(this.classes.close);
951
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowClose);
952
+ }
869
953
  optgroupLabel.addEventListener('click', (e) => {
870
954
  e.preventDefault();
871
955
  e.stopPropagation();
872
- for (const childEl of optgroupEl.children) {
873
- if (childEl.className.indexOf(this.classes.option) !== -1) {
874
- childEl.click();
875
- }
956
+ if (optgroupEl.classList.contains(this.classes.close)) {
957
+ optgroupEl.classList.remove(this.classes.close);
958
+ optgroupEl.classList.add(this.classes.open);
959
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
960
+ }
961
+ else {
962
+ optgroupEl.classList.remove(this.classes.open);
963
+ optgroupEl.classList.add(this.classes.close);
964
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowClose);
876
965
  }
877
966
  });
967
+ optgroupActions.appendChild(optgroupClosable);
878
968
  }
879
969
  optgroupEl.appendChild(optgroupLabel);
880
970
  for (const o of d.options) {
@@ -926,10 +1016,10 @@ class Render {
926
1016
  optionEl.classList.add(this.classes.hide);
927
1017
  }
928
1018
  if (option.selected) {
929
- optionEl.classList.add(this.classes.optionSelected);
1019
+ optionEl.classList.add(this.classes.selected);
930
1020
  }
931
1021
  else {
932
- optionEl.classList.remove(this.classes.optionSelected);
1022
+ optionEl.classList.remove(this.classes.selected);
933
1023
  }
934
1024
  optionEl.addEventListener('click', (e) => {
935
1025
  e.preventDefault();
@@ -1151,8 +1241,10 @@ class Select {
1151
1241
  }
1152
1242
  getDataFromOptgroup(optgroup) {
1153
1243
  let data = {
1154
- id: '',
1244
+ id: (optgroup.dataset ? optgroup.dataset.id : false) || '',
1155
1245
  label: optgroup.label,
1246
+ selectAll: optgroup.dataset ? optgroup.dataset.selectall === 'true' : false,
1247
+ closable: optgroup.dataset ? optgroup.dataset.closable : 'off',
1156
1248
  options: [],
1157
1249
  };
1158
1250
  const options = optgroup.childNodes;
@@ -1163,6 +1255,22 @@ class Select {
1163
1255
  }
1164
1256
  return data;
1165
1257
  }
1258
+ getDataFromOption(option) {
1259
+ return {
1260
+ id: (option.dataset ? option.dataset.id : false) || '',
1261
+ value: option.value,
1262
+ text: option.text,
1263
+ html: option.innerHTML,
1264
+ selected: option.selected,
1265
+ display: option.style.display === 'none' ? false : true,
1266
+ disabled: option.disabled,
1267
+ mandatory: option.dataset ? option.dataset.mandatory === 'true' : false,
1268
+ placeholder: option.dataset.placeholder === 'true',
1269
+ class: option.className,
1270
+ style: option.style.cssText,
1271
+ data: option.dataset,
1272
+ };
1273
+ }
1166
1274
  getSelectedValues() {
1167
1275
  let values = [];
1168
1276
  const options = this.select.childNodes;
@@ -1187,22 +1295,6 @@ class Select {
1187
1295
  }
1188
1296
  return values;
1189
1297
  }
1190
- getDataFromOption(option) {
1191
- return {
1192
- id: (option.dataset ? option.dataset.id : false) || generateID(),
1193
- value: option.value,
1194
- text: option.text,
1195
- html: option.innerHTML,
1196
- selected: option.selected,
1197
- display: option.style.display === 'none' ? false : true,
1198
- disabled: option.disabled,
1199
- mandatory: option.dataset ? option.dataset.mandatory === 'true' : false,
1200
- placeholder: option.dataset.placeholder === 'true',
1201
- class: option.className,
1202
- style: option.style.cssText,
1203
- data: option.dataset,
1204
- };
1205
- }
1206
1298
  setSelected(value) {
1207
1299
  const options = this.select.childNodes;
1208
1300
  for (const o of options) {
@@ -1257,6 +1349,12 @@ class Select {
1257
1349
  const optgroupEl = document.createElement('optgroup');
1258
1350
  optgroupEl.id = optgroup.id;
1259
1351
  optgroupEl.label = optgroup.label;
1352
+ if (optgroup.selectAll) {
1353
+ optgroupEl.dataset.selectAll = 'true';
1354
+ }
1355
+ if (optgroup.closable !== 'off') {
1356
+ optgroupEl.dataset.closable = optgroup.closable;
1357
+ }
1260
1358
  if (optgroup.options) {
1261
1359
  for (const o of optgroup.options) {
1262
1360
  optgroupEl.appendChild(this.createOption(o));
@@ -1313,8 +1411,6 @@ class Settings {
1313
1411
  this.isOpen = false;
1314
1412
  this.triggerFocus = true;
1315
1413
  this.intervalMove = null;
1316
- this.mainHeight = 30;
1317
- this.contentHeight = 0;
1318
1414
  if (!settings) {
1319
1415
  settings = {};
1320
1416
  }
@@ -1336,7 +1432,6 @@ class Settings {
1336
1432
  this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;
1337
1433
  this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;
1338
1434
  this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;
1339
- this.selectByGroup = settings.selectByGroup !== undefined ? settings.selectByGroup : false;
1340
1435
  this.minSelected = settings.minSelected || 0;
1341
1436
  this.maxSelected = settings.maxSelected || 1000;
1342
1437
  this.timeoutDelay = settings.timeoutDelay || 200;
@@ -1443,6 +1538,8 @@ class SlimSelect {
1443
1538
  afterChange: this.events.afterChange,
1444
1539
  };
1445
1540
  this.render = new Render(this.settings, this.store, callbacks);
1541
+ this.render.renderValues();
1542
+ this.render.renderOptions(this.store.getData());
1446
1543
  if (this.selectEl.parentNode) {
1447
1544
  this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling);
1448
1545
  }
@@ -54,6 +54,8 @@ var SlimSelect = (function () {
54
54
  constructor(optgroup) {
55
55
  this.id = !optgroup.id || optgroup.id === '' ? generateID() : optgroup.id;
56
56
  this.label = optgroup.label || '';
57
+ this.selectAll = optgroup.selectAll === undefined ? false : optgroup.selectAll;
58
+ this.closable = optgroup.closable || 'off';
57
59
  this.options = [];
58
60
  if (optgroup.options) {
59
61
  for (const o of optgroup.options) {
@@ -200,6 +202,14 @@ var SlimSelect = (function () {
200
202
  });
201
203
  return selectedIDs;
202
204
  }
205
+ getOptgroupByID(id) {
206
+ for (let dataObj of this.data) {
207
+ if (dataObj instanceof Optgroup && dataObj.id === id) {
208
+ return dataObj;
209
+ }
210
+ }
211
+ return null;
212
+ }
203
213
  getOptionByID(id) {
204
214
  let options = this.filter((opt) => {
205
215
  return opt.id === id;
@@ -234,7 +244,7 @@ var SlimSelect = (function () {
234
244
  }
235
245
  });
236
246
  if (optOptions.length > 0) {
237
- dataSearch.push(new Optgroup({ id: dataObj.id, label: dataObj.label, options: optOptions }));
247
+ dataSearch.push(new Optgroup(dataObj));
238
248
  }
239
249
  }
240
250
  }
@@ -275,11 +285,18 @@ var SlimSelect = (function () {
275
285
  list: 'ss-list',
276
286
  optgroup: 'ss-optgroup',
277
287
  optgroupLabel: 'ss-optgroup-label',
278
- optgroupSelectable: 'ss-optgroup-selectable',
288
+ optgroupLabelText: 'ss-optgroup-label-text',
289
+ optgroupActions: 'ss-optgroup-actions',
290
+ optgroupSelectAll: 'ss-selectall',
291
+ optgroupSelectAllBox: 'M60,10 L10,10 L10,90 L90,90 L90,50',
292
+ optgroupSelectAllCheck: 'M30,45 L50,70 L90,10',
293
+ optgroupClosable: 'ss-closable',
279
294
  option: 'ss-option',
280
- optionSelected: 'ss-option-selected',
281
295
  optionDelete: 'M10,10 L90,90 M10,90 L90,10',
282
296
  highlighted: 'ss-highlighted',
297
+ open: 'ss-open',
298
+ close: 'ss-close',
299
+ selected: 'ss-selected',
283
300
  error: 'ss-error',
284
301
  disabled: 'ss-disabled',
285
302
  hide: 'ss-hide',
@@ -289,8 +306,6 @@ var SlimSelect = (function () {
289
306
  this.callbacks = callbacks;
290
307
  this.main = this.mainDiv();
291
308
  this.content = this.contentDiv();
292
- this.renderValues();
293
- this.renderOptions(this.store.getData());
294
309
  this.settings.contentLocation.appendChild(this.content.main);
295
310
  }
296
311
  enable() {
@@ -803,25 +818,23 @@ var SlimSelect = (function () {
803
818
  }
804
819
  for (let i = 0; i < options.length; i++) {
805
820
  if (options[i].classList.contains(this.classes.highlighted)) {
806
- options[i].classList.remove(this.classes.highlighted);
807
- if (dir === 'down') {
808
- if (i + 1 < options.length) {
809
- options[i + 1].classList.add(this.classes.highlighted);
810
- this.ensureElementInView(this.content.list, options[i + 1]);
811
- }
812
- else {
813
- options[0].classList.add(this.classes.highlighted);
814
- this.ensureElementInView(this.content.list, options[0]);
821
+ const prevOption = options[i];
822
+ prevOption.classList.remove(this.classes.highlighted);
823
+ const prevParent = prevOption.parentElement;
824
+ if (prevParent && prevParent.classList.contains(this.classes.open)) {
825
+ const optgroupLabel = prevParent.querySelector('.' + this.classes.optgroupLabel);
826
+ if (optgroupLabel) {
827
+ optgroupLabel.click();
815
828
  }
816
829
  }
817
- else {
818
- if (i - 1 >= 0) {
819
- options[i - 1].classList.add(this.classes.highlighted);
820
- this.ensureElementInView(this.content.list, options[i - 1]);
821
- }
822
- else {
823
- options[options.length - 1].classList.add(this.classes.highlighted);
824
- this.ensureElementInView(this.content.list, options[options.length - 1]);
830
+ let selectOption = options[dir === 'down' ? (i + 1 < options.length ? i + 1 : 0) : i - 1 >= 0 ? i - 1 : options.length - 1];
831
+ selectOption.classList.add(this.classes.highlighted);
832
+ this.ensureElementInView(this.content.list, selectOption);
833
+ const selectParent = selectOption.parentElement;
834
+ if (selectParent && selectParent.classList.contains(this.classes.close)) {
835
+ const optgroupLabel = selectParent.querySelector('.' + this.classes.optgroupLabel);
836
+ if (optgroupLabel) {
837
+ optgroupLabel.click();
825
838
  }
826
839
  }
827
840
  return;
@@ -866,18 +879,95 @@ var SlimSelect = (function () {
866
879
  optgroupEl.classList.add(this.classes.optgroup);
867
880
  const optgroupLabel = document.createElement('div');
868
881
  optgroupLabel.classList.add(this.classes.optgroupLabel);
869
- optgroupLabel.innerHTML = d.label;
870
- if (this.settings.selectByGroup && this.settings.isMultiple) {
871
- optgroupLabel.classList.add(this.classes.optgroupSelectable);
882
+ optgroupEl.appendChild(optgroupLabel);
883
+ const optgroupLabelText = document.createElement('div');
884
+ optgroupLabelText.classList.add(this.classes.optgroupLabelText);
885
+ optgroupLabelText.textContent = d.label;
886
+ optgroupLabel.appendChild(optgroupLabelText);
887
+ const optgroupActions = document.createElement('div');
888
+ optgroupActions.classList.add(this.classes.optgroupActions);
889
+ optgroupLabel.appendChild(optgroupActions);
890
+ if (this.settings.isMultiple && d.selectAll) {
891
+ const selectAll = document.createElement('div');
892
+ selectAll.classList.add(this.classes.optgroupSelectAll);
893
+ let allSelected = true;
894
+ for (const o of d.options) {
895
+ if (!o.selected) {
896
+ allSelected = false;
897
+ break;
898
+ }
899
+ }
900
+ if (allSelected) {
901
+ selectAll.classList.add(this.classes.selected);
902
+ }
903
+ const selectAllText = document.createElement('span');
904
+ selectAllText.textContent = 'Select All';
905
+ selectAll.appendChild(selectAllText);
906
+ const selectAllSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
907
+ selectAllSvg.setAttribute('viewBox', '0 0 100 100');
908
+ selectAll.appendChild(selectAllSvg);
909
+ const selectAllBox = document.createElementNS('http://www.w3.org/2000/svg', 'path');
910
+ selectAllBox.setAttribute('d', this.classes.optgroupSelectAllBox);
911
+ selectAllSvg.appendChild(selectAllBox);
912
+ const selectAllCheck = document.createElementNS('http://www.w3.org/2000/svg', 'path');
913
+ selectAllCheck.setAttribute('d', this.classes.optgroupSelectAllCheck);
914
+ selectAllSvg.appendChild(selectAllCheck);
915
+ selectAll.addEventListener('click', (e) => {
916
+ e.preventDefault();
917
+ e.stopPropagation();
918
+ const currentSelected = this.store.getSelected();
919
+ if (allSelected) {
920
+ const newSelected = currentSelected.filter((s) => {
921
+ for (const o of d.options) {
922
+ if (s === o.value) {
923
+ return false;
924
+ }
925
+ }
926
+ return true;
927
+ });
928
+ this.callbacks.setSelected(newSelected);
929
+ return;
930
+ }
931
+ else {
932
+ const newSelected = currentSelected.concat(d.options.map((o) => o.value));
933
+ this.callbacks.setSelected(newSelected);
934
+ }
935
+ });
936
+ optgroupActions.appendChild(selectAll);
937
+ }
938
+ if (d.closable !== 'off') {
939
+ const optgroupClosable = document.createElement('div');
940
+ optgroupClosable.classList.add(this.classes.optgroupClosable);
941
+ const optgroupClosableSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
942
+ optgroupClosableSvg.setAttribute('viewBox', '0 0 100 100');
943
+ optgroupClosableSvg.classList.add(this.classes.arrow);
944
+ optgroupClosable.appendChild(optgroupClosableSvg);
945
+ const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
946
+ optgroupClosableArrow.setAttribute('d', this.classes.arrow);
947
+ optgroupClosableSvg.appendChild(optgroupClosableArrow);
948
+ if (d.closable === 'open') {
949
+ optgroupEl.classList.add(this.classes.open);
950
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
951
+ }
952
+ else if (d.closable === 'close') {
953
+ optgroupEl.classList.add(this.classes.close);
954
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowClose);
955
+ }
872
956
  optgroupLabel.addEventListener('click', (e) => {
873
957
  e.preventDefault();
874
958
  e.stopPropagation();
875
- for (const childEl of optgroupEl.children) {
876
- if (childEl.className.indexOf(this.classes.option) !== -1) {
877
- childEl.click();
878
- }
959
+ if (optgroupEl.classList.contains(this.classes.close)) {
960
+ optgroupEl.classList.remove(this.classes.close);
961
+ optgroupEl.classList.add(this.classes.open);
962
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
963
+ }
964
+ else {
965
+ optgroupEl.classList.remove(this.classes.open);
966
+ optgroupEl.classList.add(this.classes.close);
967
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowClose);
879
968
  }
880
969
  });
970
+ optgroupActions.appendChild(optgroupClosable);
881
971
  }
882
972
  optgroupEl.appendChild(optgroupLabel);
883
973
  for (const o of d.options) {
@@ -929,10 +1019,10 @@ var SlimSelect = (function () {
929
1019
  optionEl.classList.add(this.classes.hide);
930
1020
  }
931
1021
  if (option.selected) {
932
- optionEl.classList.add(this.classes.optionSelected);
1022
+ optionEl.classList.add(this.classes.selected);
933
1023
  }
934
1024
  else {
935
- optionEl.classList.remove(this.classes.optionSelected);
1025
+ optionEl.classList.remove(this.classes.selected);
936
1026
  }
937
1027
  optionEl.addEventListener('click', (e) => {
938
1028
  e.preventDefault();
@@ -1154,8 +1244,10 @@ var SlimSelect = (function () {
1154
1244
  }
1155
1245
  getDataFromOptgroup(optgroup) {
1156
1246
  let data = {
1157
- id: '',
1247
+ id: (optgroup.dataset ? optgroup.dataset.id : false) || '',
1158
1248
  label: optgroup.label,
1249
+ selectAll: optgroup.dataset ? optgroup.dataset.selectall === 'true' : false,
1250
+ closable: optgroup.dataset ? optgroup.dataset.closable : 'off',
1159
1251
  options: [],
1160
1252
  };
1161
1253
  const options = optgroup.childNodes;
@@ -1166,6 +1258,22 @@ var SlimSelect = (function () {
1166
1258
  }
1167
1259
  return data;
1168
1260
  }
1261
+ getDataFromOption(option) {
1262
+ return {
1263
+ id: (option.dataset ? option.dataset.id : false) || '',
1264
+ value: option.value,
1265
+ text: option.text,
1266
+ html: option.innerHTML,
1267
+ selected: option.selected,
1268
+ display: option.style.display === 'none' ? false : true,
1269
+ disabled: option.disabled,
1270
+ mandatory: option.dataset ? option.dataset.mandatory === 'true' : false,
1271
+ placeholder: option.dataset.placeholder === 'true',
1272
+ class: option.className,
1273
+ style: option.style.cssText,
1274
+ data: option.dataset,
1275
+ };
1276
+ }
1169
1277
  getSelectedValues() {
1170
1278
  let values = [];
1171
1279
  const options = this.select.childNodes;
@@ -1190,22 +1298,6 @@ var SlimSelect = (function () {
1190
1298
  }
1191
1299
  return values;
1192
1300
  }
1193
- getDataFromOption(option) {
1194
- return {
1195
- id: (option.dataset ? option.dataset.id : false) || generateID(),
1196
- value: option.value,
1197
- text: option.text,
1198
- html: option.innerHTML,
1199
- selected: option.selected,
1200
- display: option.style.display === 'none' ? false : true,
1201
- disabled: option.disabled,
1202
- mandatory: option.dataset ? option.dataset.mandatory === 'true' : false,
1203
- placeholder: option.dataset.placeholder === 'true',
1204
- class: option.className,
1205
- style: option.style.cssText,
1206
- data: option.dataset,
1207
- };
1208
- }
1209
1301
  setSelected(value) {
1210
1302
  const options = this.select.childNodes;
1211
1303
  for (const o of options) {
@@ -1260,6 +1352,12 @@ var SlimSelect = (function () {
1260
1352
  const optgroupEl = document.createElement('optgroup');
1261
1353
  optgroupEl.id = optgroup.id;
1262
1354
  optgroupEl.label = optgroup.label;
1355
+ if (optgroup.selectAll) {
1356
+ optgroupEl.dataset.selectAll = 'true';
1357
+ }
1358
+ if (optgroup.closable !== 'off') {
1359
+ optgroupEl.dataset.closable = optgroup.closable;
1360
+ }
1263
1361
  if (optgroup.options) {
1264
1362
  for (const o of optgroup.options) {
1265
1363
  optgroupEl.appendChild(this.createOption(o));
@@ -1316,8 +1414,6 @@ var SlimSelect = (function () {
1316
1414
  this.isOpen = false;
1317
1415
  this.triggerFocus = true;
1318
1416
  this.intervalMove = null;
1319
- this.mainHeight = 30;
1320
- this.contentHeight = 0;
1321
1417
  if (!settings) {
1322
1418
  settings = {};
1323
1419
  }
@@ -1339,7 +1435,6 @@ var SlimSelect = (function () {
1339
1435
  this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;
1340
1436
  this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;
1341
1437
  this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;
1342
- this.selectByGroup = settings.selectByGroup !== undefined ? settings.selectByGroup : false;
1343
1438
  this.minSelected = settings.minSelected || 0;
1344
1439
  this.maxSelected = settings.maxSelected || 1000;
1345
1440
  this.timeoutDelay = settings.timeoutDelay || 200;
@@ -1446,6 +1541,8 @@ var SlimSelect = (function () {
1446
1541
  afterChange: this.events.afterChange,
1447
1542
  };
1448
1543
  this.render = new Render(this.settings, this.store, callbacks);
1544
+ this.render.renderValues();
1545
+ this.render.renderOptions(this.store.getData());
1449
1546
  if (this.selectEl.parentNode) {
1450
1547
  this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling);
1451
1548
  }