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
@@ -54,6 +54,8 @@ var SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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 SlimSelectVue = (function (vue) {
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
  }
@@ -55,6 +55,8 @@ class Optgroup {
55
55
  constructor(optgroup) {
56
56
  this.id = !optgroup.id || optgroup.id === '' ? generateID() : optgroup.id;
57
57
  this.label = optgroup.label || '';
58
+ this.selectAll = optgroup.selectAll === undefined ? false : optgroup.selectAll;
59
+ this.closable = optgroup.closable || 'off';
58
60
  this.options = [];
59
61
  if (optgroup.options) {
60
62
  for (const o of optgroup.options) {
@@ -201,6 +203,14 @@ class Store {
201
203
  });
202
204
  return selectedIDs;
203
205
  }
206
+ getOptgroupByID(id) {
207
+ for (let dataObj of this.data) {
208
+ if (dataObj instanceof Optgroup && dataObj.id === id) {
209
+ return dataObj;
210
+ }
211
+ }
212
+ return null;
213
+ }
204
214
  getOptionByID(id) {
205
215
  let options = this.filter((opt) => {
206
216
  return opt.id === id;
@@ -235,7 +245,7 @@ class Store {
235
245
  }
236
246
  });
237
247
  if (optOptions.length > 0) {
238
- dataSearch.push(new Optgroup({ id: dataObj.id, label: dataObj.label, options: optOptions }));
248
+ dataSearch.push(new Optgroup(dataObj));
239
249
  }
240
250
  }
241
251
  }
@@ -276,11 +286,18 @@ class Render {
276
286
  list: 'ss-list',
277
287
  optgroup: 'ss-optgroup',
278
288
  optgroupLabel: 'ss-optgroup-label',
279
- optgroupSelectable: 'ss-optgroup-selectable',
289
+ optgroupLabelText: 'ss-optgroup-label-text',
290
+ optgroupActions: 'ss-optgroup-actions',
291
+ optgroupSelectAll: 'ss-selectall',
292
+ optgroupSelectAllBox: 'M60,10 L10,10 L10,90 L90,90 L90,50',
293
+ optgroupSelectAllCheck: 'M30,45 L50,70 L90,10',
294
+ optgroupClosable: 'ss-closable',
280
295
  option: 'ss-option',
281
- optionSelected: 'ss-option-selected',
282
296
  optionDelete: 'M10,10 L90,90 M10,90 L90,10',
283
297
  highlighted: 'ss-highlighted',
298
+ open: 'ss-open',
299
+ close: 'ss-close',
300
+ selected: 'ss-selected',
284
301
  error: 'ss-error',
285
302
  disabled: 'ss-disabled',
286
303
  hide: 'ss-hide',
@@ -290,8 +307,6 @@ class Render {
290
307
  this.callbacks = callbacks;
291
308
  this.main = this.mainDiv();
292
309
  this.content = this.contentDiv();
293
- this.renderValues();
294
- this.renderOptions(this.store.getData());
295
310
  this.settings.contentLocation.appendChild(this.content.main);
296
311
  }
297
312
  enable() {
@@ -804,25 +819,23 @@ class Render {
804
819
  }
805
820
  for (let i = 0; i < options.length; i++) {
806
821
  if (options[i].classList.contains(this.classes.highlighted)) {
807
- options[i].classList.remove(this.classes.highlighted);
808
- if (dir === 'down') {
809
- if (i + 1 < options.length) {
810
- options[i + 1].classList.add(this.classes.highlighted);
811
- this.ensureElementInView(this.content.list, options[i + 1]);
812
- }
813
- else {
814
- options[0].classList.add(this.classes.highlighted);
815
- this.ensureElementInView(this.content.list, options[0]);
822
+ const prevOption = options[i];
823
+ prevOption.classList.remove(this.classes.highlighted);
824
+ const prevParent = prevOption.parentElement;
825
+ if (prevParent && prevParent.classList.contains(this.classes.open)) {
826
+ const optgroupLabel = prevParent.querySelector('.' + this.classes.optgroupLabel);
827
+ if (optgroupLabel) {
828
+ optgroupLabel.click();
816
829
  }
817
830
  }
818
- else {
819
- if (i - 1 >= 0) {
820
- options[i - 1].classList.add(this.classes.highlighted);
821
- this.ensureElementInView(this.content.list, options[i - 1]);
822
- }
823
- else {
824
- options[options.length - 1].classList.add(this.classes.highlighted);
825
- this.ensureElementInView(this.content.list, options[options.length - 1]);
831
+ let selectOption = options[dir === 'down' ? (i + 1 < options.length ? i + 1 : 0) : i - 1 >= 0 ? i - 1 : options.length - 1];
832
+ selectOption.classList.add(this.classes.highlighted);
833
+ this.ensureElementInView(this.content.list, selectOption);
834
+ const selectParent = selectOption.parentElement;
835
+ if (selectParent && selectParent.classList.contains(this.classes.close)) {
836
+ const optgroupLabel = selectParent.querySelector('.' + this.classes.optgroupLabel);
837
+ if (optgroupLabel) {
838
+ optgroupLabel.click();
826
839
  }
827
840
  }
828
841
  return;
@@ -867,18 +880,95 @@ class Render {
867
880
  optgroupEl.classList.add(this.classes.optgroup);
868
881
  const optgroupLabel = document.createElement('div');
869
882
  optgroupLabel.classList.add(this.classes.optgroupLabel);
870
- optgroupLabel.innerHTML = d.label;
871
- if (this.settings.selectByGroup && this.settings.isMultiple) {
872
- optgroupLabel.classList.add(this.classes.optgroupSelectable);
883
+ optgroupEl.appendChild(optgroupLabel);
884
+ const optgroupLabelText = document.createElement('div');
885
+ optgroupLabelText.classList.add(this.classes.optgroupLabelText);
886
+ optgroupLabelText.textContent = d.label;
887
+ optgroupLabel.appendChild(optgroupLabelText);
888
+ const optgroupActions = document.createElement('div');
889
+ optgroupActions.classList.add(this.classes.optgroupActions);
890
+ optgroupLabel.appendChild(optgroupActions);
891
+ if (this.settings.isMultiple && d.selectAll) {
892
+ const selectAll = document.createElement('div');
893
+ selectAll.classList.add(this.classes.optgroupSelectAll);
894
+ let allSelected = true;
895
+ for (const o of d.options) {
896
+ if (!o.selected) {
897
+ allSelected = false;
898
+ break;
899
+ }
900
+ }
901
+ if (allSelected) {
902
+ selectAll.classList.add(this.classes.selected);
903
+ }
904
+ const selectAllText = document.createElement('span');
905
+ selectAllText.textContent = 'Select All';
906
+ selectAll.appendChild(selectAllText);
907
+ const selectAllSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
908
+ selectAllSvg.setAttribute('viewBox', '0 0 100 100');
909
+ selectAll.appendChild(selectAllSvg);
910
+ const selectAllBox = document.createElementNS('http://www.w3.org/2000/svg', 'path');
911
+ selectAllBox.setAttribute('d', this.classes.optgroupSelectAllBox);
912
+ selectAllSvg.appendChild(selectAllBox);
913
+ const selectAllCheck = document.createElementNS('http://www.w3.org/2000/svg', 'path');
914
+ selectAllCheck.setAttribute('d', this.classes.optgroupSelectAllCheck);
915
+ selectAllSvg.appendChild(selectAllCheck);
916
+ selectAll.addEventListener('click', (e) => {
917
+ e.preventDefault();
918
+ e.stopPropagation();
919
+ const currentSelected = this.store.getSelected();
920
+ if (allSelected) {
921
+ const newSelected = currentSelected.filter((s) => {
922
+ for (const o of d.options) {
923
+ if (s === o.value) {
924
+ return false;
925
+ }
926
+ }
927
+ return true;
928
+ });
929
+ this.callbacks.setSelected(newSelected);
930
+ return;
931
+ }
932
+ else {
933
+ const newSelected = currentSelected.concat(d.options.map((o) => o.value));
934
+ this.callbacks.setSelected(newSelected);
935
+ }
936
+ });
937
+ optgroupActions.appendChild(selectAll);
938
+ }
939
+ if (d.closable !== 'off') {
940
+ const optgroupClosable = document.createElement('div');
941
+ optgroupClosable.classList.add(this.classes.optgroupClosable);
942
+ const optgroupClosableSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
943
+ optgroupClosableSvg.setAttribute('viewBox', '0 0 100 100');
944
+ optgroupClosableSvg.classList.add(this.classes.arrow);
945
+ optgroupClosable.appendChild(optgroupClosableSvg);
946
+ const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
947
+ optgroupClosableArrow.setAttribute('d', this.classes.arrow);
948
+ optgroupClosableSvg.appendChild(optgroupClosableArrow);
949
+ if (d.closable === 'open') {
950
+ optgroupEl.classList.add(this.classes.open);
951
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
952
+ }
953
+ else if (d.closable === 'close') {
954
+ optgroupEl.classList.add(this.classes.close);
955
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowClose);
956
+ }
873
957
  optgroupLabel.addEventListener('click', (e) => {
874
958
  e.preventDefault();
875
959
  e.stopPropagation();
876
- for (const childEl of optgroupEl.children) {
877
- if (childEl.className.indexOf(this.classes.option) !== -1) {
878
- childEl.click();
879
- }
960
+ if (optgroupEl.classList.contains(this.classes.close)) {
961
+ optgroupEl.classList.remove(this.classes.close);
962
+ optgroupEl.classList.add(this.classes.open);
963
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
964
+ }
965
+ else {
966
+ optgroupEl.classList.remove(this.classes.open);
967
+ optgroupEl.classList.add(this.classes.close);
968
+ optgroupClosableArrow.setAttribute('d', this.classes.arrowClose);
880
969
  }
881
970
  });
971
+ optgroupActions.appendChild(optgroupClosable);
882
972
  }
883
973
  optgroupEl.appendChild(optgroupLabel);
884
974
  for (const o of d.options) {
@@ -930,10 +1020,10 @@ class Render {
930
1020
  optionEl.classList.add(this.classes.hide);
931
1021
  }
932
1022
  if (option.selected) {
933
- optionEl.classList.add(this.classes.optionSelected);
1023
+ optionEl.classList.add(this.classes.selected);
934
1024
  }
935
1025
  else {
936
- optionEl.classList.remove(this.classes.optionSelected);
1026
+ optionEl.classList.remove(this.classes.selected);
937
1027
  }
938
1028
  optionEl.addEventListener('click', (e) => {
939
1029
  e.preventDefault();
@@ -1155,8 +1245,10 @@ class Select {
1155
1245
  }
1156
1246
  getDataFromOptgroup(optgroup) {
1157
1247
  let data = {
1158
- id: '',
1248
+ id: (optgroup.dataset ? optgroup.dataset.id : false) || '',
1159
1249
  label: optgroup.label,
1250
+ selectAll: optgroup.dataset ? optgroup.dataset.selectall === 'true' : false,
1251
+ closable: optgroup.dataset ? optgroup.dataset.closable : 'off',
1160
1252
  options: [],
1161
1253
  };
1162
1254
  const options = optgroup.childNodes;
@@ -1167,6 +1259,22 @@ class Select {
1167
1259
  }
1168
1260
  return data;
1169
1261
  }
1262
+ getDataFromOption(option) {
1263
+ return {
1264
+ id: (option.dataset ? option.dataset.id : false) || '',
1265
+ value: option.value,
1266
+ text: option.text,
1267
+ html: option.innerHTML,
1268
+ selected: option.selected,
1269
+ display: option.style.display === 'none' ? false : true,
1270
+ disabled: option.disabled,
1271
+ mandatory: option.dataset ? option.dataset.mandatory === 'true' : false,
1272
+ placeholder: option.dataset.placeholder === 'true',
1273
+ class: option.className,
1274
+ style: option.style.cssText,
1275
+ data: option.dataset,
1276
+ };
1277
+ }
1170
1278
  getSelectedValues() {
1171
1279
  let values = [];
1172
1280
  const options = this.select.childNodes;
@@ -1191,22 +1299,6 @@ class Select {
1191
1299
  }
1192
1300
  return values;
1193
1301
  }
1194
- getDataFromOption(option) {
1195
- return {
1196
- id: (option.dataset ? option.dataset.id : false) || generateID(),
1197
- value: option.value,
1198
- text: option.text,
1199
- html: option.innerHTML,
1200
- selected: option.selected,
1201
- display: option.style.display === 'none' ? false : true,
1202
- disabled: option.disabled,
1203
- mandatory: option.dataset ? option.dataset.mandatory === 'true' : false,
1204
- placeholder: option.dataset.placeholder === 'true',
1205
- class: option.className,
1206
- style: option.style.cssText,
1207
- data: option.dataset,
1208
- };
1209
- }
1210
1302
  setSelected(value) {
1211
1303
  const options = this.select.childNodes;
1212
1304
  for (const o of options) {
@@ -1261,6 +1353,12 @@ class Select {
1261
1353
  const optgroupEl = document.createElement('optgroup');
1262
1354
  optgroupEl.id = optgroup.id;
1263
1355
  optgroupEl.label = optgroup.label;
1356
+ if (optgroup.selectAll) {
1357
+ optgroupEl.dataset.selectAll = 'true';
1358
+ }
1359
+ if (optgroup.closable !== 'off') {
1360
+ optgroupEl.dataset.closable = optgroup.closable;
1361
+ }
1264
1362
  if (optgroup.options) {
1265
1363
  for (const o of optgroup.options) {
1266
1364
  optgroupEl.appendChild(this.createOption(o));
@@ -1317,8 +1415,6 @@ class Settings {
1317
1415
  this.isOpen = false;
1318
1416
  this.triggerFocus = true;
1319
1417
  this.intervalMove = null;
1320
- this.mainHeight = 30;
1321
- this.contentHeight = 0;
1322
1418
  if (!settings) {
1323
1419
  settings = {};
1324
1420
  }
@@ -1340,7 +1436,6 @@ class Settings {
1340
1436
  this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;
1341
1437
  this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;
1342
1438
  this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;
1343
- this.selectByGroup = settings.selectByGroup !== undefined ? settings.selectByGroup : false;
1344
1439
  this.minSelected = settings.minSelected || 0;
1345
1440
  this.maxSelected = settings.maxSelected || 1000;
1346
1441
  this.timeoutDelay = settings.timeoutDelay || 200;
@@ -1447,6 +1542,8 @@ class SlimSelect {
1447
1542
  afterChange: this.events.afterChange,
1448
1543
  };
1449
1544
  this.render = new Render(this.settings, this.store, callbacks);
1545
+ this.render.renderValues();
1546
+ this.render.renderOptions(this.store.getData());
1450
1547
  if (this.selectEl.parentNode) {
1451
1548
  this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling);
1452
1549
  }
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@slim-select/vue",
3
- "version": "1.0.0",
3
+ "private": false,
4
+ "version": "1.1.0",
4
5
  "description": "Vue integration",
5
6
  "repository": {
6
7
  "type": "git",
@@ -10,7 +11,7 @@
10
11
  "vue"
11
12
  ],
12
13
  "author": "Brian Voelker <brian@webiswhatido.com> (http://webiswhatido.com)",
13
- "homepage": "https://slimselectjs.com",
14
+ "homepage": "https://slimselectjs.com/frameworks#vue",
14
15
  "license": "MIT",
15
16
  "bugs": {
16
17
  "url": "https://github.com/brianvoe/slim-select/issues"