selectic 3.0.0 → 3.0.4

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.
@@ -107,6 +107,7 @@ class SelecticStore {
107
107
  disabled: false,
108
108
  placeholder: '',
109
109
  hideFilter: false,
110
+ keepFilterOpen: false,
110
111
  allowRevert: undefined,
111
112
  allowClearSelection: false,
112
113
  autoSelect: true,
@@ -136,6 +137,8 @@ class SelecticStore {
136
137
  errorMessage: '',
137
138
  areAllSelected: false,
138
139
  hasChanged: false,
140
+ automaticChange: false,
141
+ automaticClose: false,
139
142
  },
140
143
  });
141
144
  /* Do not need reactivity */
@@ -188,22 +191,33 @@ class SelecticStore {
188
191
  return this.state.filteredOptions.length >= nbItems;
189
192
  });
190
193
  this.hasFetchedAllItems = vue.computed(() => {
191
- var _a;
192
- const isPartial = (_a = this.isPartial.value) !== null && _a !== void 0 ? _a : this.isPartial;
194
+ const isPartial = vue.unref(this.isPartial);
193
195
  if (!isPartial) {
194
196
  return true;
195
197
  }
196
198
  const state = this.state;
197
199
  return state.dynOptions.length === state.totalDynOptions;
198
200
  });
201
+ this.listOptions = vue.computed(() => {
202
+ return this.getListOptions();
203
+ });
204
+ this.elementOptions = vue.computed(() => {
205
+ return this.getElementOptions();
206
+ });
199
207
  /* }}} */
200
208
  /* {{{ watch */
201
209
  vue.watch(() => [this.props.options, this.props.childOptions], () => {
202
210
  this.data.cacheItem.clear();
211
+ this.setAutomaticClose();
203
212
  this.commit('isOpen', false);
204
213
  this.buildAllOptions(true);
205
214
  this.buildSelectedOptions();
206
215
  });
216
+ vue.watch(() => [this.listOptions, this.elementOptions], () => {
217
+ /* TODO: transform allOptions as a computed properties and this
218
+ * watcher become useless */
219
+ this.buildAllOptions(true);
220
+ });
207
221
  vue.watch(() => this.props.value, () => {
208
222
  var _a;
209
223
  const value = (_a = this.props.value) !== null && _a !== void 0 ? _a : null;
@@ -216,9 +230,8 @@ class SelecticStore {
216
230
  this.commit('disabled', this.props.disabled);
217
231
  });
218
232
  vue.watch(() => this.state.filteredOptions, () => {
219
- var _a;
220
233
  let areAllSelected = false;
221
- const hasAllItems = (_a = this.hasAllItems.value) !== null && _a !== void 0 ? _a : this.hasAllItems;
234
+ const hasAllItems = vue.unref(this.hasAllItems);
222
235
  if (hasAllItems) {
223
236
  const selectionIsExcluded = +this.state.selectionIsExcluded;
224
237
  /* eslint-disable-next-line no-bitwise */
@@ -238,6 +251,7 @@ class SelecticStore {
238
251
  });
239
252
  /* }}} */
240
253
  this.closeSelectic = () => {
254
+ this.setAutomaticClose();
241
255
  this.commit('isOpen', false);
242
256
  };
243
257
  const value = this.props.value;
@@ -251,9 +265,16 @@ class SelecticStore {
251
265
  if (stateParam.hideFilter === 'auto') {
252
266
  delete stateParam.hideFilter;
253
267
  }
268
+ else if (stateParam.hideFilter === 'open') {
269
+ this.state.keepFilterOpen = true;
270
+ delete stateParam.hideFilter;
271
+ }
254
272
  /* Update state */
255
- assignObject(this.state, stateParam, {
256
- internalValue: value,
273
+ assignObject(this.state, stateParam);
274
+ /* XXX: should be done in 2 lines, in order to set the multiple state
275
+ * and ensure convertValue run with correct state */
276
+ assignObject(this.state, {
277
+ internalValue: this.convertTypeValue(value),
257
278
  selectionIsExcluded: props.selectionIsExcluded,
258
279
  disabled: props.disabled,
259
280
  });
@@ -323,11 +344,20 @@ class SelecticStore {
323
344
  break;
324
345
  case 'disabled':
325
346
  if (value) {
347
+ this.setAutomaticClose();
326
348
  this.commit('isOpen', false);
327
349
  }
328
350
  break;
329
351
  }
330
352
  }
353
+ setAutomaticChange() {
354
+ this.state.status.automaticChange = true;
355
+ setTimeout(() => this.state.status.automaticChange = false, 0);
356
+ }
357
+ setAutomaticClose() {
358
+ this.state.status.automaticClose = true;
359
+ setTimeout(() => this.state.status.automaticClose = false, 0);
360
+ }
331
361
  getItem(id) {
332
362
  let item;
333
363
  if (this.hasItemInStore(id)) {
@@ -370,10 +400,9 @@ class SelecticStore {
370
400
  return this.buildSelectedItems(ids);
371
401
  }
372
402
  selectItem(id, selected, keepOpen = false) {
373
- var _a;
374
403
  const state = this.state;
375
404
  let hasChanged = false;
376
- const isPartial = (_a = this.isPartial.value) !== null && _a !== void 0 ? _a : this.isPartial;
405
+ const isPartial = vue.unref(this.isPartial);
377
406
  /* Check that item is not disabled */
378
407
  if (!isPartial) {
379
408
  const item = state.allOptions.find((opt) => opt.id === id);
@@ -426,6 +455,10 @@ class SelecticStore {
426
455
  else if (id === oldValue) {
427
456
  return;
428
457
  }
458
+ if (keepOpen) {
459
+ /* if keepOpen is true it means that it is an automatic change */
460
+ this.setAutomaticChange();
461
+ }
429
462
  this.commit('internalValue', id);
430
463
  hasChanged = true;
431
464
  }
@@ -434,11 +467,10 @@ class SelecticStore {
434
467
  }
435
468
  }
436
469
  toggleSelectAll() {
437
- var _a;
438
470
  if (!this.state.multiple) {
439
471
  return;
440
472
  }
441
- const hasAllItems = (_a = this.hasAllItems.value) !== null && _a !== void 0 ? _a : this.hasAllItems;
473
+ const hasAllItems = vue.unref(this.hasAllItems);
442
474
  if (!hasAllItems) {
443
475
  const labels = this.data.labels;
444
476
  if (this.state.searchText) {
@@ -471,8 +503,7 @@ class SelecticStore {
471
503
  this.state.status.errorMessage = '';
472
504
  }
473
505
  clearCache(forceReset = false) {
474
- var _a;
475
- const isPartial = (_a = this.isPartial.value) !== null && _a !== void 0 ? _a : this.isPartial;
506
+ const isPartial = vue.unref(this.isPartial);
476
507
  const total = isPartial ? Infinity : 0;
477
508
  this.data.cacheItem.clear();
478
509
  this.state.allOptions = [];
@@ -517,39 +548,46 @@ class SelecticStore {
517
548
  }
518
549
  return this.state.filteredOptions.find(findId) ||
519
550
  this.state.dynOptions.find(findId) ||
520
- this.getListOptions().find(findId) ||
521
- this.getElementOptions().find(findId);
551
+ vue.unref(this.listOptions).find(findId) ||
552
+ vue.unref(this.elementOptions).find(findId);
522
553
  }
523
- assertValueType() {
554
+ convertTypeValue(oldValue) {
524
555
  const state = this.state;
525
- const internalValue = state.internalValue;
526
556
  const isMultiple = state.multiple;
527
- let newValue = internalValue;
557
+ let newValue = oldValue;
528
558
  if (isMultiple) {
529
- if (!Array.isArray(internalValue)) {
530
- newValue = internalValue === null ? [] : [internalValue];
559
+ if (!Array.isArray(oldValue)) {
560
+ newValue = oldValue === null ? [] : [oldValue];
531
561
  }
532
562
  }
533
563
  else {
534
- if (Array.isArray(internalValue)) {
535
- const value = internalValue[0];
564
+ if (Array.isArray(oldValue)) {
565
+ const value = oldValue[0];
536
566
  newValue = typeof value === 'undefined' ? null : value;
537
567
  }
538
568
  }
539
- state.internalValue = newValue;
569
+ return newValue;
570
+ }
571
+ assertValueType() {
572
+ const state = this.state;
573
+ const internalValue = state.internalValue;
574
+ const newValue = this.convertTypeValue(internalValue);
575
+ if (newValue !== internalValue) {
576
+ this.setAutomaticChange();
577
+ state.internalValue = newValue;
578
+ }
540
579
  }
541
580
  assertCorrectValue(applyStrict = false) {
542
- var _a, _b;
543
581
  const state = this.state;
582
+ this.assertValueType();
544
583
  const internalValue = state.internalValue;
545
584
  const selectionIsExcluded = state.selectionIsExcluded;
546
585
  const isMultiple = state.multiple;
547
586
  const checkStrict = state.strictValue;
548
587
  let newValue = internalValue;
549
- const isPartial = (_a = this.isPartial.value) !== null && _a !== void 0 ? _a : this.isPartial;
550
- this.assertValueType();
588
+ const isPartial = vue.unref(this.isPartial);
551
589
  if (isMultiple) {
552
- const hasFetchedAllItems = (_b = this.hasFetchedAllItems.value) !== null && _b !== void 0 ? _b : this.hasFetchedAllItems;
590
+ const hasFetchedAllItems = vue.unref(this.hasFetchedAllItems);
553
591
  if (selectionIsExcluded && hasFetchedAllItems) {
554
592
  newValue = state.allOptions.reduce((values, option) => {
555
593
  const id = option.id;
@@ -577,7 +615,7 @@ class SelecticStore {
577
615
  return;
578
616
  }
579
617
  }
580
- else if (!this.hasItemInStore(newValue)) {
618
+ else if (newValue !== null && !this.hasItemInStore(newValue)) {
581
619
  filteredValue = null;
582
620
  isDifferent = true;
583
621
  if (isPartial && !applyStrict) {
@@ -587,6 +625,7 @@ class SelecticStore {
587
625
  }
588
626
  }
589
627
  if (isDifferent) {
628
+ this.setAutomaticChange();
590
629
  newValue = filteredValue;
591
630
  }
592
631
  }
@@ -606,13 +645,14 @@ class SelecticStore {
606
645
  this.state.groups.set(group.id, group.text);
607
646
  });
608
647
  }
609
- /* XXX: This is not a computed property to avoid consuming more memory */
648
+ /* This method is for the computed property listOptions */
610
649
  getListOptions() {
611
650
  const options = this.props.options;
612
651
  const listOptions = [];
613
652
  if (!Array.isArray(options)) {
614
653
  return listOptions;
615
654
  }
655
+ const state = this.state;
616
656
  options.forEach((option) => {
617
657
  /* manage simple string */
618
658
  if (typeof option === 'string') {
@@ -625,13 +665,13 @@ class SelecticStore {
625
665
  const group = option.group;
626
666
  const subOptions = option.options;
627
667
  /* check for groups */
628
- if (group && !this.state.groups.has(group)) {
629
- this.state.groups.set(group, String(group));
668
+ if (group && !state.groups.has(group)) {
669
+ state.groups.set(group, String(group));
630
670
  }
631
671
  /* check for sub options */
632
672
  if (subOptions) {
633
673
  const groupId = option.id;
634
- this.state.groups.set(groupId, option.text);
674
+ state.groups.set(groupId, option.text);
635
675
  subOptions.forEach((subOpt) => {
636
676
  subOpt.group = groupId;
637
677
  });
@@ -642,24 +682,25 @@ class SelecticStore {
642
682
  });
643
683
  return listOptions;
644
684
  }
645
- /* XXX: This is not a computed property to avoid consuming more memory */
685
+ /* This method is for the computed property elementOptions */
646
686
  getElementOptions() {
647
687
  const options = this.props.childOptions;
648
688
  const childOptions = [];
649
689
  if (!Array.isArray(options) || options.length === 0) {
650
690
  return childOptions;
651
691
  }
692
+ const state = this.state;
652
693
  options.forEach((option) => {
653
694
  const group = option.group;
654
695
  const subOptions = option.options;
655
696
  /* check for groups */
656
- if (group && !this.state.groups.has(group)) {
657
- this.state.groups.set(group, String(group));
697
+ if (group && !state.groups.has(group)) {
698
+ state.groups.set(group, String(group));
658
699
  }
659
700
  /* check for sub options */
660
701
  if (subOptions) {
661
702
  const groupId = option.id;
662
- this.state.groups.set(groupId, option.text);
703
+ state.groups.set(groupId, option.text);
663
704
  const sOpts = subOptions.map((subOpt) => {
664
705
  return Object.assign({}, subOpt, {
665
706
  group: groupId,
@@ -673,13 +714,12 @@ class SelecticStore {
673
714
  return childOptions;
674
715
  }
675
716
  buildAllOptions(keepFetched = false) {
676
- var _a;
677
717
  const allOptions = [];
678
718
  let listOptions = [];
679
719
  let elementOptions = [];
680
720
  const optionBehaviorOrder = this.state.optionBehaviorOrder;
681
721
  let length = Infinity;
682
- const isPartial = (_a = this.isPartial.value) !== null && _a !== void 0 ? _a : this.isPartial;
722
+ const isPartial = vue.unref(this.isPartial);
683
723
  const arrayFromOrder = (orderValue) => {
684
724
  switch (orderValue) {
685
725
  case 'O': return listOptions;
@@ -705,8 +745,8 @@ class SelecticStore {
705
745
  this.state.totalDynOptions = 0;
706
746
  }
707
747
  }
708
- listOptions = this.getListOptions();
709
- elementOptions = this.getElementOptions();
748
+ listOptions = vue.unref(this.listOptions);
749
+ elementOptions = vue.unref(this.elementOptions);
710
750
  if (this.state.optionBehaviorOperation === 'force') {
711
751
  const orderValue = optionBehaviorOrder.find((value) => lengthFromOrder(value) > 0);
712
752
  allOptions.push(...arrayFromOrder(orderValue));
@@ -752,7 +792,6 @@ class SelecticStore {
752
792
  });
753
793
  }
754
794
  async buildFilteredOptions() {
755
- var _a, _b, _c, _d;
756
795
  if (!this.state.isOpen) {
757
796
  /* Do not try to fetch anything while the select is not open */
758
797
  return;
@@ -762,12 +801,12 @@ class SelecticStore {
762
801
  const totalAllOptions = this.state.totalAllOptions;
763
802
  const allOptionsLength = allOptions.length;
764
803
  let filteredOptionsLength = this.state.filteredOptions.length;
765
- const hasAllItems = (_a = this.hasAllItems.value) !== null && _a !== void 0 ? _a : this.hasAllItems;
804
+ const hasAllItems = vue.unref(this.hasAllItems);
766
805
  if (hasAllItems) {
767
806
  /* Everything has already been fetched and stored in filteredOptions */
768
807
  return;
769
808
  }
770
- const hasFetchedAllItems = (_b = this.hasFetchedAllItems.value) !== null && _b !== void 0 ? _b : this.hasFetchedAllItems;
809
+ const hasFetchedAllItems = vue.unref(this.hasFetchedAllItems);
771
810
  /* Check if all options have been fetched */
772
811
  if (hasFetchedAllItems) {
773
812
  if (!search) {
@@ -782,7 +821,7 @@ class SelecticStore {
782
821
  }
783
822
  /* When we only have partial options */
784
823
  const offsetItem = this.state.offsetItem;
785
- const marginSize = (_c = this.marginSize.value) !== null && _c !== void 0 ? _c : this.marginSize;
824
+ const marginSize = vue.unref(this.marginSize);
786
825
  const endIndex = offsetItem + marginSize;
787
826
  if (endIndex <= filteredOptionsLength) {
788
827
  return;
@@ -790,7 +829,7 @@ class SelecticStore {
790
829
  if (!search && endIndex <= allOptionsLength) {
791
830
  this.state.filteredOptions = this.buildGroupItems(allOptions);
792
831
  this.state.totalFilteredOptions = totalAllOptions + this.state.groups.size;
793
- const isPartial = (_d = this.isPartial.value) !== null && _d !== void 0 ? _d : this.isPartial;
832
+ const isPartial = vue.unref(this.isPartial);
794
833
  if (isPartial && this.state.totalDynOptions === Infinity) {
795
834
  this.fetchData();
796
835
  }
@@ -808,54 +847,56 @@ class SelecticStore {
808
847
  }
809
848
  async buildSelectedOptions() {
810
849
  const internalValue = this.state.internalValue;
811
- if (this.state.multiple) {
850
+ const state = this.state;
851
+ if (state.multiple) {
812
852
  /* display partial information about selected items */
813
- this.state.selectedOptions = this.buildSelectedItems(internalValue);
853
+ state.selectedOptions = this.buildSelectedItems(internalValue);
814
854
  const items = await this.getItems(internalValue).catch(() => []);
815
- if (internalValue !== this.state.internalValue) {
855
+ if (internalValue !== state.internalValue) {
816
856
  /* Values have been deprecated */
817
857
  return;
818
858
  }
819
859
  if (items.length !== internalValue.length) {
820
- if (!this.state.strictValue) {
821
- const updatedItems = this.state.selectedOptions.map((option) => {
860
+ if (!state.strictValue) {
861
+ const updatedItems = state.selectedOptions.map((option) => {
822
862
  const foundItem = items.find((item) => item.id === option.id);
823
863
  return foundItem || option;
824
864
  });
825
- this.state.selectedOptions = updatedItems;
865
+ state.selectedOptions = updatedItems;
826
866
  }
827
867
  else {
828
868
  const itemIds = items.map((item) => item.id);
869
+ this.setAutomaticChange();
829
870
  this.commit('internalValue', itemIds);
830
871
  }
831
872
  return;
832
873
  }
833
874
  /* display full information about selected items */
834
- this.state.selectedOptions = items;
875
+ state.selectedOptions = items;
835
876
  }
836
877
  else if (internalValue === null) {
837
- this.state.selectedOptions = null;
878
+ state.selectedOptions = null;
838
879
  }
839
880
  else {
840
881
  /* display partial information about selected items */
841
- this.state.selectedOptions = this.buildSelectedItems([internalValue])[0];
882
+ state.selectedOptions = this.buildSelectedItems([internalValue])[0];
842
883
  const items = await this.getItems([internalValue]).catch(() => []);
843
- if (internalValue !== this.state.internalValue) {
884
+ if (internalValue !== state.internalValue) {
844
885
  /* Values have been deprecated */
845
886
  return;
846
887
  }
847
888
  if (!items.length) {
848
- if (this.state.strictValue) {
889
+ if (state.strictValue) {
890
+ this.setAutomaticChange();
849
891
  this.commit('internalValue', null);
850
892
  }
851
893
  return;
852
894
  }
853
895
  /* display full information about selected items */
854
- this.state.selectedOptions = items[0];
896
+ state.selectedOptions = items[0];
855
897
  }
856
898
  }
857
899
  async fetchData() {
858
- var _a;
859
900
  const state = this.state;
860
901
  const labels = this.data.labels;
861
902
  const fetchCallback = this.props.fetchCallback;
@@ -867,7 +908,7 @@ class SelecticStore {
867
908
  const filteredOptionsLength = state.filteredOptions.length;
868
909
  const offsetItem = state.offsetItem;
869
910
  const pageSize = state.pageSize;
870
- const marginSize = (_a = this.marginSize.value) !== null && _a !== void 0 ? _a : this.marginSize;
911
+ const marginSize = vue.unref(this.marginSize);
871
912
  const endIndex = offsetItem + marginSize;
872
913
  const dynOffset = this.data.dynOffset;
873
914
  /* Run the query */
@@ -958,10 +999,10 @@ class SelecticStore {
958
999
  }
959
1000
  switch (order) {
960
1001
  case 'O':
961
- options = this.filterOptions(this.getListOptions(), search);
1002
+ options = this.filterOptions(vue.unref(this.listOptions), search);
962
1003
  break;
963
1004
  case 'E':
964
- options = this.filterOptions(this.getElementOptions(), search);
1005
+ options = this.filterOptions(vue.unref(this.elementOptions), search);
965
1006
  break;
966
1007
  }
967
1008
  this.state.filteredOptions.push(...options);
@@ -1067,11 +1108,10 @@ class SelecticStore {
1067
1108
  }
1068
1109
  }
1069
1110
  checkAutoDisabled() {
1070
- var _a, _b;
1071
1111
  const state = this.state;
1072
- const isPartial = (_a = this.isPartial.value) !== null && _a !== void 0 ? _a : this.isPartial;
1112
+ const isPartial = vue.unref(this.isPartial);
1073
1113
  const doNotCheck = isPartial || this.props.disabled || !state.autoDisabled;
1074
- const hasFetchedAllItems = (_b = this.hasFetchedAllItems.value) !== null && _b !== void 0 ? _b : this.hasFetchedAllItems;
1114
+ const hasFetchedAllItems = vue.unref(this.hasFetchedAllItems);
1075
1115
  if (doNotCheck || !hasFetchedAllItems) {
1076
1116
  return;
1077
1117
  }
@@ -1084,7 +1124,10 @@ class SelecticStore {
1084
1124
  const isEmpty = nb === 0;
1085
1125
  const hasOnlyOneOption = nb === 1 && hasValidValue && !state.allowClearSelection;
1086
1126
  if (hasOnlyOneOption || isEmpty) {
1087
- this.commit('isOpen', false);
1127
+ if (state.isOpen) {
1128
+ this.setAutomaticClose();
1129
+ this.commit('isOpen', false);
1130
+ }
1088
1131
  this.commit('disabled', true);
1089
1132
  }
1090
1133
  else {
@@ -1092,13 +1135,12 @@ class SelecticStore {
1092
1135
  }
1093
1136
  }
1094
1137
  checkHideFilter() {
1095
- var _a;
1096
1138
  const params = this.props.params;
1097
1139
  if (params && params.hideFilter !== 'auto') {
1098
1140
  return;
1099
1141
  }
1100
1142
  const state = this.state;
1101
- const isPartial = (_a = this.isPartial.value) !== null && _a !== void 0 ? _a : this.isPartial;
1143
+ const isPartial = vue.unref(this.isPartial);
1102
1144
  if (state.multiple || isPartial) {
1103
1145
  state.hideFilter = false;
1104
1146
  }
@@ -1388,12 +1430,12 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
1388
1430
  const state = store.state;
1389
1431
  const isMultiple = state.multiple;
1390
1432
  const hasItems = state.filteredOptions.length === 0;
1391
- const canNotSelect = !!state.searchText && !store.hasAllItems.value;
1433
+ const canNotSelect = !!state.searchText && !vue.unref(store.hasAllItems);
1392
1434
  return !isMultiple || hasItems || canNotSelect;
1393
1435
  }
1394
1436
  get disableRevert() {
1395
1437
  const store = this.store;
1396
- return !store.state.multiple || !store.hasFetchedAllItems.value;
1438
+ return !store.state.multiple || !vue.unref(store.hasFetchedAllItems);
1397
1439
  }
1398
1440
  get enableRevert() {
1399
1441
  const state = this.store.state;
@@ -1431,6 +1473,10 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
1431
1473
  this.store.commit('selectionIsExcluded', !this.selectionIsExcluded);
1432
1474
  }
1433
1475
  togglePanel() {
1476
+ if (this.store.state.keepFilterOpen === true) {
1477
+ this.closed = false;
1478
+ return;
1479
+ }
1434
1480
  this.closed = !this.closed;
1435
1481
  }
1436
1482
  getFocus() {
@@ -1447,7 +1493,8 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
1447
1493
  /* }}} */
1448
1494
  /* {{{ Life cycle */
1449
1495
  mounted() {
1450
- this.closed = !this.store.state.searchText;
1496
+ const state = this.store.state;
1497
+ this.closed = !state.keepFilterOpen && !state.searchText;
1451
1498
  document.addEventListener('keypress', this.onKeyPressed);
1452
1499
  this.getFocus();
1453
1500
  }
@@ -1456,24 +1503,27 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
1456
1503
  }
1457
1504
  /* }}} */
1458
1505
  render() {
1506
+ const store = this.store;
1507
+ const state = store.state;
1508
+ const labels = store.data.labels;
1459
1509
  return (vtyx.h("div", { class: "filter-panel" },
1460
1510
  vtyx.h("div", { class: {
1461
1511
  panelclosed: this.closed,
1462
1512
  panelopened: !this.closed,
1463
1513
  } },
1464
1514
  vtyx.h("div", { class: "filter-panel__input form-group has-feedback" },
1465
- vtyx.h("input", { type: "text", class: "form-control filter-input", placeholder: this.searchPlaceholder, value: this.store.state.searchText, on: {
1515
+ vtyx.h("input", { type: "text", class: "form-control filter-input", placeholder: this.searchPlaceholder, value: state.searchText, on: {
1466
1516
  'input.stop.prevent': this.onInput,
1467
1517
  }, ref: "filterInput" }),
1468
1518
  vtyx.h("span", { class: "fa fa-search selectic-search-scope\n form-control-feedback" })),
1469
- this.store.state.multiple && (vtyx.h("div", { class: "toggle-selectic" },
1519
+ state.multiple && (vtyx.h("div", { class: "toggle-selectic" },
1470
1520
  vtyx.h("label", { class: ['control-label', {
1471
1521
  'selectic__label-disabled': this.disableSelectAll,
1472
1522
  }] },
1473
- vtyx.h("input", { type: "checkbox", checked: this.store.state.status.areAllSelected, disabled: this.disableSelectAll, on: {
1523
+ vtyx.h("input", { type: "checkbox", checked: state.status.areAllSelected, disabled: this.disableSelectAll, on: {
1474
1524
  change: this.onSelectAll,
1475
1525
  } }),
1476
- this.store.data.labels.selectAll))),
1526
+ labels.selectAll))),
1477
1527
  this.enableRevert && (vtyx.h("div", { class: ['toggle-selectic', {
1478
1528
  'selectic__label-disabled': this.disableRevert,
1479
1529
  }] },
@@ -1481,8 +1531,8 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
1481
1531
  vtyx.h("input", { type: "checkbox", checked: this.selectionIsExcluded, disabled: this.disableRevert, on: {
1482
1532
  change: this.onExclude,
1483
1533
  } }),
1484
- this.store.data.labels.excludeResult)))),
1485
- vtyx.h("div", { class: "curtain-handler", on: {
1534
+ labels.excludeResult)))),
1535
+ !state.keepFilterOpen && (vtyx.h("div", { class: "curtain-handler", on: {
1486
1536
  'click.prevent.stop': this.togglePanel,
1487
1537
  } },
1488
1538
  vtyx.h("span", { class: "fa fa-search" }),
@@ -1490,7 +1540,7 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
1490
1540
  'fa': true,
1491
1541
  'fa-caret-down': this.closed,
1492
1542
  'fa-caret-up': !this.closed,
1493
- } }))));
1543
+ } })))));
1494
1544
  }
1495
1545
  };
1496
1546
  __decorate$3([
@@ -1532,9 +1582,8 @@ let List = class List extends vtyx.Vue {
1532
1582
  return this.store.state.multiple;
1533
1583
  }
1534
1584
  get itemsMargin() {
1535
- var _a;
1536
1585
  /* XXX: I don't really know when we should use value or not... */
1537
- return (_a = this.store.marginSize.value) !== null && _a !== void 0 ? _a : this.store.marginSize;
1586
+ return vue.unref(this.store.marginSize);
1538
1587
  }
1539
1588
  get shortOptions() {
1540
1589
  const endIndex = this.endIndex;
@@ -2124,7 +2173,7 @@ let Selectic = class Selectic extends vtyx.Vue {
2124
2173
  window.addEventListener('resize', this.windowResize, false);
2125
2174
  document.addEventListener('click', this.outsideListener, true);
2126
2175
  this.computeOffset();
2127
- this.$emit('open', this);
2176
+ this.emit('open');
2128
2177
  }
2129
2178
  else {
2130
2179
  this.removeListeners();
@@ -2132,7 +2181,7 @@ let Selectic = class Selectic extends vtyx.Vue {
2132
2181
  this.$emit('change', this.getValue(), state.selectionIsExcluded, this);
2133
2182
  this.store.resetChange();
2134
2183
  }
2135
- this.$emit('close', this);
2184
+ this.emit('close');
2136
2185
  }
2137
2186
  }
2138
2187
  compareValues(oldValue, newValue) {
@@ -2162,7 +2211,7 @@ let Selectic = class Selectic extends vtyx.Vue {
2162
2211
  this.store.props.selectionIsExcluded = this.selectionIsExcluded;
2163
2212
  }
2164
2213
  onOptionsChange() {
2165
- this.store.props.options = this.options;
2214
+ this.store.props.options = Array.from(this.options);
2166
2215
  }
2167
2216
  onTextsChange() {
2168
2217
  const texts = this.texts;
@@ -2195,9 +2244,9 @@ let Selectic = class Selectic extends vtyx.Vue {
2195
2244
  const canTrigger = (oldValue !== undefined || !this.hasGivenValue) && !areSimilar;
2196
2245
  if (canTrigger) {
2197
2246
  const selectionIsExcluded = this.store.state.selectionIsExcluded;
2198
- this.$emit('input', value, selectionIsExcluded, this);
2247
+ this.emit('input', value, selectionIsExcluded);
2199
2248
  if (!this.isFocused) {
2200
- this.$emit('change', value, selectionIsExcluded, this);
2249
+ this.emit('change', value, selectionIsExcluded);
2201
2250
  this.store.resetChange();
2202
2251
  }
2203
2252
  }
@@ -2220,12 +2269,42 @@ let Selectic = class Selectic extends vtyx.Vue {
2220
2269
  this.store.commit('isOpen', false);
2221
2270
  }, 0);
2222
2271
  }
2223
- emit(event, ...args) {
2272
+ _emit(event, ...args) {
2224
2273
  this.$emit(event, ...args);
2225
2274
  if (typeof this._on === 'function') {
2226
2275
  this._on(event, ...args);
2227
2276
  }
2228
2277
  }
2278
+ emit(event, value, isExcluded) {
2279
+ const automatic = this.store.state.status.automaticChange;
2280
+ const options = {
2281
+ instance: this,
2282
+ eventType: event,
2283
+ automatic,
2284
+ };
2285
+ switch (event) {
2286
+ case 'input':
2287
+ case 'change':
2288
+ const changeOptions = Object.assign({
2289
+ isExcluded: isExcluded,
2290
+ }, options);
2291
+ this._emit(event, value, changeOptions);
2292
+ break;
2293
+ case 'open':
2294
+ case 'focus':
2295
+ this._emit('open', options);
2296
+ this._emit('focus', options);
2297
+ break;
2298
+ case 'close':
2299
+ case 'blur':
2300
+ this._emit('close', options);
2301
+ this._emit('blur', options);
2302
+ break;
2303
+ case 'item:click':
2304
+ this._emit(event, value, options);
2305
+ break;
2306
+ }
2307
+ }
2229
2308
  // private extractFromNode(node: Vue.VNode, text = ''): OptionValue {
2230
2309
  // function styleToString(staticStyle?: {[key: string]: string}): string | undefined {
2231
2310
  // if (!staticStyle) {
@@ -2304,7 +2383,7 @@ let Selectic = class Selectic extends vtyx.Vue {
2304
2383
  /* }}} */
2305
2384
  /* {{{ Life cycle */
2306
2385
  created() {
2307
- var _a, _b;
2386
+ var _a, _b, _c;
2308
2387
  this._elementsListeners = [];
2309
2388
  this.store = new SelecticStore({
2310
2389
  options: this.options,
@@ -2317,8 +2396,7 @@ let Selectic = class Selectic extends vtyx.Vue {
2317
2396
  params: {
2318
2397
  multiple: ((_a = this.multiple) !== null && _a !== void 0 ? _a : false) !== false,
2319
2398
  pageSize: this.params.pageSize || 100,
2320
- hideFilter: this.params.hideFilter !== undefined
2321
- ? this.params.hideFilter : 'auto',
2399
+ hideFilter: (_b = this.params.hideFilter) !== null && _b !== void 0 ? _b : 'auto',
2322
2400
  allowRevert: this.params.allowRevert,
2323
2401
  allowClearSelection: this.params.allowClearSelection || false,
2324
2402
  autoSelect: this.params.autoSelect === undefined
@@ -2333,7 +2411,7 @@ let Selectic = class Selectic extends vtyx.Vue {
2333
2411
  formatSelection: this.params.formatSelection,
2334
2412
  listPosition: this.params.listPosition || 'auto',
2335
2413
  optionBehavior: this.params.optionBehavior,
2336
- isOpen: ((_b = this.open) !== null && _b !== void 0 ? _b : false) !== false,
2414
+ isOpen: ((_c = this.open) !== null && _c !== void 0 ? _c : false) !== false,
2337
2415
  },
2338
2416
  fetchCallback: this.params.fetchCallback,
2339
2417
  getItemsCallback: this.params.getItemsCallback,
@@ -2392,7 +2470,7 @@ let Selectic = class Selectic extends vtyx.Vue {
2392
2470
  blur: this.checkFocus,
2393
2471
  } }),
2394
2472
  vtyx.h(MainInput$1, { store: store, id: id, on: {
2395
- 'item:click': (id) => this.emit('item:click', id, this),
2473
+ 'item:click': (id) => this.emit('item:click', id),
2396
2474
  }, ref: "mainInput" }),
2397
2475
  this.isFocused && (vtyx.h(ExtendedList$1, { class: this.className, store: store, elementBottom: this.elementBottom, elementTop: this.elementTop, elementLeft: this.elementLeft, elementRight: this.elementRight, width: this.width, ref: "extendedList" }))));
2398
2476
  }
@@ -2479,10 +2557,19 @@ __decorate([
2479
2557
  __decorate([
2480
2558
  vtyx.Watch('store.state.internalValue')
2481
2559
  ], Selectic.prototype, "onInternalValueChange", null);
2560
+ __decorate([
2561
+ vtyx.Emit('input'),
2562
+ vtyx.Emit('change'),
2563
+ vtyx.Emit('open'),
2564
+ vtyx.Emit('focus'),
2565
+ vtyx.Emit('close'),
2566
+ vtyx.Emit('blur'),
2567
+ vtyx.Emit('item:click')
2568
+ ], Selectic.prototype, "render", null);
2482
2569
  Selectic = __decorate([
2483
2570
  vtyx.Component
2484
2571
  ], Selectic);
2485
2572
  var Selectic$1 = Selectic;
2486
2573
 
2487
2574
  exports.changeTexts = changeTexts;
2488
- exports['default'] = Selectic$1;
2575
+ exports["default"] = Selectic$1;