selectic 3.0.1 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.package.json.un~ +0 -0
- package/README.md +2 -0
- package/dist/selectic.common.js +134 -62
- package/dist/selectic.esm.js +135 -63
- package/doc/breakingChanges.md +55 -0
- package/doc/events.md +68 -17
- package/doc/main.md +7 -0
- package/doc/params.md +5 -2
- package/package.json +6 -5
- package/src/Filter.tsx +21 -8
- package/src/List.tsx +2 -1
- package/src/Store.tsx +73 -25
- package/src/index.tsx +85 -14
- package/test/Store/Store_creation.spec.js +56 -0
- package/test/Store/commit.spec.js +42 -9
- package/test/helper.js +3 -0
- package/types/Store.d.ts +10 -1
- package/types/index.d.ts +13 -3
|
Binary file
|
package/README.md
CHANGED
|
@@ -81,6 +81,8 @@ There are very few dependencies and code stays very small (~90kB).
|
|
|
81
81
|
|
|
82
82
|
[Read the documentation](./doc/main.md) to know how to configure Selectic and all its possibilities.
|
|
83
83
|
|
|
84
|
+
For users which are used to previous Selectic versions, they can read the [migration strategy guide](./doc/breakingChanges.md).
|
|
85
|
+
|
|
84
86
|
It uses [VTYX](https://github.com/Intersec/vtyx) for strong typing.
|
|
85
87
|
|
|
86
88
|
## Tests
|
package/dist/selectic.common.js
CHANGED
|
@@ -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,8 +191,7 @@ class SelecticStore {
|
|
|
188
191
|
return this.state.filteredOptions.length >= nbItems;
|
|
189
192
|
});
|
|
190
193
|
this.hasFetchedAllItems = vue.computed(() => {
|
|
191
|
-
|
|
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
|
}
|
|
@@ -206,6 +208,7 @@ class SelecticStore {
|
|
|
206
208
|
/* {{{ watch */
|
|
207
209
|
vue.watch(() => [this.props.options, this.props.childOptions], () => {
|
|
208
210
|
this.data.cacheItem.clear();
|
|
211
|
+
this.setAutomaticClose();
|
|
209
212
|
this.commit('isOpen', false);
|
|
210
213
|
this.buildAllOptions(true);
|
|
211
214
|
this.buildSelectedOptions();
|
|
@@ -227,9 +230,8 @@ class SelecticStore {
|
|
|
227
230
|
this.commit('disabled', this.props.disabled);
|
|
228
231
|
});
|
|
229
232
|
vue.watch(() => this.state.filteredOptions, () => {
|
|
230
|
-
var _a;
|
|
231
233
|
let areAllSelected = false;
|
|
232
|
-
const hasAllItems = (
|
|
234
|
+
const hasAllItems = vue.unref(this.hasAllItems);
|
|
233
235
|
if (hasAllItems) {
|
|
234
236
|
const selectionIsExcluded = +this.state.selectionIsExcluded;
|
|
235
237
|
/* eslint-disable-next-line no-bitwise */
|
|
@@ -249,6 +251,7 @@ class SelecticStore {
|
|
|
249
251
|
});
|
|
250
252
|
/* }}} */
|
|
251
253
|
this.closeSelectic = () => {
|
|
254
|
+
this.setAutomaticClose();
|
|
252
255
|
this.commit('isOpen', false);
|
|
253
256
|
};
|
|
254
257
|
const value = this.props.value;
|
|
@@ -262,6 +265,10 @@ class SelecticStore {
|
|
|
262
265
|
if (stateParam.hideFilter === 'auto') {
|
|
263
266
|
delete stateParam.hideFilter;
|
|
264
267
|
}
|
|
268
|
+
else if (stateParam.hideFilter === 'open') {
|
|
269
|
+
this.state.keepFilterOpen = true;
|
|
270
|
+
delete stateParam.hideFilter;
|
|
271
|
+
}
|
|
265
272
|
/* Update state */
|
|
266
273
|
assignObject(this.state, stateParam);
|
|
267
274
|
/* XXX: should be done in 2 lines, in order to set the multiple state
|
|
@@ -337,11 +344,20 @@ class SelecticStore {
|
|
|
337
344
|
break;
|
|
338
345
|
case 'disabled':
|
|
339
346
|
if (value) {
|
|
347
|
+
this.setAutomaticClose();
|
|
340
348
|
this.commit('isOpen', false);
|
|
341
349
|
}
|
|
342
350
|
break;
|
|
343
351
|
}
|
|
344
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
|
+
}
|
|
345
361
|
getItem(id) {
|
|
346
362
|
let item;
|
|
347
363
|
if (this.hasItemInStore(id)) {
|
|
@@ -384,10 +400,9 @@ class SelecticStore {
|
|
|
384
400
|
return this.buildSelectedItems(ids);
|
|
385
401
|
}
|
|
386
402
|
selectItem(id, selected, keepOpen = false) {
|
|
387
|
-
var _a;
|
|
388
403
|
const state = this.state;
|
|
389
404
|
let hasChanged = false;
|
|
390
|
-
const isPartial = (
|
|
405
|
+
const isPartial = vue.unref(this.isPartial);
|
|
391
406
|
/* Check that item is not disabled */
|
|
392
407
|
if (!isPartial) {
|
|
393
408
|
const item = state.allOptions.find((opt) => opt.id === id);
|
|
@@ -440,6 +455,10 @@ class SelecticStore {
|
|
|
440
455
|
else if (id === oldValue) {
|
|
441
456
|
return;
|
|
442
457
|
}
|
|
458
|
+
if (keepOpen) {
|
|
459
|
+
/* if keepOpen is true it means that it is an automatic change */
|
|
460
|
+
this.setAutomaticChange();
|
|
461
|
+
}
|
|
443
462
|
this.commit('internalValue', id);
|
|
444
463
|
hasChanged = true;
|
|
445
464
|
}
|
|
@@ -448,11 +467,10 @@ class SelecticStore {
|
|
|
448
467
|
}
|
|
449
468
|
}
|
|
450
469
|
toggleSelectAll() {
|
|
451
|
-
var _a;
|
|
452
470
|
if (!this.state.multiple) {
|
|
453
471
|
return;
|
|
454
472
|
}
|
|
455
|
-
const hasAllItems = (
|
|
473
|
+
const hasAllItems = vue.unref(this.hasAllItems);
|
|
456
474
|
if (!hasAllItems) {
|
|
457
475
|
const labels = this.data.labels;
|
|
458
476
|
if (this.state.searchText) {
|
|
@@ -485,8 +503,7 @@ class SelecticStore {
|
|
|
485
503
|
this.state.status.errorMessage = '';
|
|
486
504
|
}
|
|
487
505
|
clearCache(forceReset = false) {
|
|
488
|
-
|
|
489
|
-
const isPartial = (_a = this.isPartial.value) !== null && _a !== void 0 ? _a : this.isPartial;
|
|
506
|
+
const isPartial = vue.unref(this.isPartial);
|
|
490
507
|
const total = isPartial ? Infinity : 0;
|
|
491
508
|
this.data.cacheItem.clear();
|
|
492
509
|
this.state.allOptions = [];
|
|
@@ -526,14 +543,13 @@ class SelecticStore {
|
|
|
526
543
|
return !!this.getValue(id);
|
|
527
544
|
}
|
|
528
545
|
getValue(id) {
|
|
529
|
-
var _a, _b;
|
|
530
546
|
function findId(option) {
|
|
531
547
|
return option.id === id;
|
|
532
548
|
}
|
|
533
549
|
return this.state.filteredOptions.find(findId) ||
|
|
534
550
|
this.state.dynOptions.find(findId) ||
|
|
535
|
-
(
|
|
536
|
-
(
|
|
551
|
+
vue.unref(this.listOptions).find(findId) ||
|
|
552
|
+
vue.unref(this.elementOptions).find(findId);
|
|
537
553
|
}
|
|
538
554
|
convertTypeValue(oldValue) {
|
|
539
555
|
const state = this.state;
|
|
@@ -557,11 +573,11 @@ class SelecticStore {
|
|
|
557
573
|
const internalValue = state.internalValue;
|
|
558
574
|
const newValue = this.convertTypeValue(internalValue);
|
|
559
575
|
if (newValue !== internalValue) {
|
|
576
|
+
this.setAutomaticChange();
|
|
560
577
|
state.internalValue = newValue;
|
|
561
578
|
}
|
|
562
579
|
}
|
|
563
580
|
assertCorrectValue(applyStrict = false) {
|
|
564
|
-
var _a, _b;
|
|
565
581
|
const state = this.state;
|
|
566
582
|
this.assertValueType();
|
|
567
583
|
const internalValue = state.internalValue;
|
|
@@ -569,9 +585,9 @@ class SelecticStore {
|
|
|
569
585
|
const isMultiple = state.multiple;
|
|
570
586
|
const checkStrict = state.strictValue;
|
|
571
587
|
let newValue = internalValue;
|
|
572
|
-
const isPartial = (
|
|
588
|
+
const isPartial = vue.unref(this.isPartial);
|
|
573
589
|
if (isMultiple) {
|
|
574
|
-
const hasFetchedAllItems = (
|
|
590
|
+
const hasFetchedAllItems = vue.unref(this.hasFetchedAllItems);
|
|
575
591
|
if (selectionIsExcluded && hasFetchedAllItems) {
|
|
576
592
|
newValue = state.allOptions.reduce((values, option) => {
|
|
577
593
|
const id = option.id;
|
|
@@ -609,6 +625,7 @@ class SelecticStore {
|
|
|
609
625
|
}
|
|
610
626
|
}
|
|
611
627
|
if (isDifferent) {
|
|
628
|
+
this.setAutomaticChange();
|
|
612
629
|
newValue = filteredValue;
|
|
613
630
|
}
|
|
614
631
|
}
|
|
@@ -697,13 +714,12 @@ class SelecticStore {
|
|
|
697
714
|
return childOptions;
|
|
698
715
|
}
|
|
699
716
|
buildAllOptions(keepFetched = false) {
|
|
700
|
-
var _a, _b, _c;
|
|
701
717
|
const allOptions = [];
|
|
702
718
|
let listOptions = [];
|
|
703
719
|
let elementOptions = [];
|
|
704
720
|
const optionBehaviorOrder = this.state.optionBehaviorOrder;
|
|
705
721
|
let length = Infinity;
|
|
706
|
-
const isPartial = (
|
|
722
|
+
const isPartial = vue.unref(this.isPartial);
|
|
707
723
|
const arrayFromOrder = (orderValue) => {
|
|
708
724
|
switch (orderValue) {
|
|
709
725
|
case 'O': return listOptions;
|
|
@@ -729,8 +745,8 @@ class SelecticStore {
|
|
|
729
745
|
this.state.totalDynOptions = 0;
|
|
730
746
|
}
|
|
731
747
|
}
|
|
732
|
-
listOptions = (
|
|
733
|
-
elementOptions = (
|
|
748
|
+
listOptions = vue.unref(this.listOptions);
|
|
749
|
+
elementOptions = vue.unref(this.elementOptions);
|
|
734
750
|
if (this.state.optionBehaviorOperation === 'force') {
|
|
735
751
|
const orderValue = optionBehaviorOrder.find((value) => lengthFromOrder(value) > 0);
|
|
736
752
|
allOptions.push(...arrayFromOrder(orderValue));
|
|
@@ -776,7 +792,6 @@ class SelecticStore {
|
|
|
776
792
|
});
|
|
777
793
|
}
|
|
778
794
|
async buildFilteredOptions() {
|
|
779
|
-
var _a, _b, _c, _d;
|
|
780
795
|
if (!this.state.isOpen) {
|
|
781
796
|
/* Do not try to fetch anything while the select is not open */
|
|
782
797
|
return;
|
|
@@ -786,12 +801,12 @@ class SelecticStore {
|
|
|
786
801
|
const totalAllOptions = this.state.totalAllOptions;
|
|
787
802
|
const allOptionsLength = allOptions.length;
|
|
788
803
|
let filteredOptionsLength = this.state.filteredOptions.length;
|
|
789
|
-
const hasAllItems = (
|
|
804
|
+
const hasAllItems = vue.unref(this.hasAllItems);
|
|
790
805
|
if (hasAllItems) {
|
|
791
806
|
/* Everything has already been fetched and stored in filteredOptions */
|
|
792
807
|
return;
|
|
793
808
|
}
|
|
794
|
-
const hasFetchedAllItems = (
|
|
809
|
+
const hasFetchedAllItems = vue.unref(this.hasFetchedAllItems);
|
|
795
810
|
/* Check if all options have been fetched */
|
|
796
811
|
if (hasFetchedAllItems) {
|
|
797
812
|
if (!search) {
|
|
@@ -806,7 +821,7 @@ class SelecticStore {
|
|
|
806
821
|
}
|
|
807
822
|
/* When we only have partial options */
|
|
808
823
|
const offsetItem = this.state.offsetItem;
|
|
809
|
-
const marginSize = (
|
|
824
|
+
const marginSize = vue.unref(this.marginSize);
|
|
810
825
|
const endIndex = offsetItem + marginSize;
|
|
811
826
|
if (endIndex <= filteredOptionsLength) {
|
|
812
827
|
return;
|
|
@@ -814,7 +829,7 @@ class SelecticStore {
|
|
|
814
829
|
if (!search && endIndex <= allOptionsLength) {
|
|
815
830
|
this.state.filteredOptions = this.buildGroupItems(allOptions);
|
|
816
831
|
this.state.totalFilteredOptions = totalAllOptions + this.state.groups.size;
|
|
817
|
-
const isPartial = (
|
|
832
|
+
const isPartial = vue.unref(this.isPartial);
|
|
818
833
|
if (isPartial && this.state.totalDynOptions === Infinity) {
|
|
819
834
|
this.fetchData();
|
|
820
835
|
}
|
|
@@ -851,6 +866,7 @@ class SelecticStore {
|
|
|
851
866
|
}
|
|
852
867
|
else {
|
|
853
868
|
const itemIds = items.map((item) => item.id);
|
|
869
|
+
this.setAutomaticChange();
|
|
854
870
|
this.commit('internalValue', itemIds);
|
|
855
871
|
}
|
|
856
872
|
return;
|
|
@@ -871,6 +887,7 @@ class SelecticStore {
|
|
|
871
887
|
}
|
|
872
888
|
if (!items.length) {
|
|
873
889
|
if (state.strictValue) {
|
|
890
|
+
this.setAutomaticChange();
|
|
874
891
|
this.commit('internalValue', null);
|
|
875
892
|
}
|
|
876
893
|
return;
|
|
@@ -880,7 +897,6 @@ class SelecticStore {
|
|
|
880
897
|
}
|
|
881
898
|
}
|
|
882
899
|
async fetchData() {
|
|
883
|
-
var _a;
|
|
884
900
|
const state = this.state;
|
|
885
901
|
const labels = this.data.labels;
|
|
886
902
|
const fetchCallback = this.props.fetchCallback;
|
|
@@ -892,7 +908,7 @@ class SelecticStore {
|
|
|
892
908
|
const filteredOptionsLength = state.filteredOptions.length;
|
|
893
909
|
const offsetItem = state.offsetItem;
|
|
894
910
|
const pageSize = state.pageSize;
|
|
895
|
-
const marginSize = (
|
|
911
|
+
const marginSize = vue.unref(this.marginSize);
|
|
896
912
|
const endIndex = offsetItem + marginSize;
|
|
897
913
|
const dynOffset = this.data.dynOffset;
|
|
898
914
|
/* Run the query */
|
|
@@ -964,7 +980,6 @@ class SelecticStore {
|
|
|
964
980
|
return this.buildGroupItems(options.filter((option) => rgx.test(option.text)));
|
|
965
981
|
}
|
|
966
982
|
addStaticFilteredOptions(fromDynamic = false) {
|
|
967
|
-
var _a, _b;
|
|
968
983
|
const search = this.state.searchText;
|
|
969
984
|
let continueLoop = fromDynamic;
|
|
970
985
|
if (this.state.optionBehaviorOperation !== 'sort') {
|
|
@@ -984,10 +999,10 @@ class SelecticStore {
|
|
|
984
999
|
}
|
|
985
1000
|
switch (order) {
|
|
986
1001
|
case 'O':
|
|
987
|
-
options = this.filterOptions((
|
|
1002
|
+
options = this.filterOptions(vue.unref(this.listOptions), search);
|
|
988
1003
|
break;
|
|
989
1004
|
case 'E':
|
|
990
|
-
options = this.filterOptions((
|
|
1005
|
+
options = this.filterOptions(vue.unref(this.elementOptions), search);
|
|
991
1006
|
break;
|
|
992
1007
|
}
|
|
993
1008
|
this.state.filteredOptions.push(...options);
|
|
@@ -1093,11 +1108,10 @@ class SelecticStore {
|
|
|
1093
1108
|
}
|
|
1094
1109
|
}
|
|
1095
1110
|
checkAutoDisabled() {
|
|
1096
|
-
var _a, _b;
|
|
1097
1111
|
const state = this.state;
|
|
1098
|
-
const isPartial = (
|
|
1112
|
+
const isPartial = vue.unref(this.isPartial);
|
|
1099
1113
|
const doNotCheck = isPartial || this.props.disabled || !state.autoDisabled;
|
|
1100
|
-
const hasFetchedAllItems = (
|
|
1114
|
+
const hasFetchedAllItems = vue.unref(this.hasFetchedAllItems);
|
|
1101
1115
|
if (doNotCheck || !hasFetchedAllItems) {
|
|
1102
1116
|
return;
|
|
1103
1117
|
}
|
|
@@ -1110,7 +1124,10 @@ class SelecticStore {
|
|
|
1110
1124
|
const isEmpty = nb === 0;
|
|
1111
1125
|
const hasOnlyOneOption = nb === 1 && hasValidValue && !state.allowClearSelection;
|
|
1112
1126
|
if (hasOnlyOneOption || isEmpty) {
|
|
1113
|
-
|
|
1127
|
+
if (state.isOpen) {
|
|
1128
|
+
this.setAutomaticClose();
|
|
1129
|
+
this.commit('isOpen', false);
|
|
1130
|
+
}
|
|
1114
1131
|
this.commit('disabled', true);
|
|
1115
1132
|
}
|
|
1116
1133
|
else {
|
|
@@ -1118,13 +1135,12 @@ class SelecticStore {
|
|
|
1118
1135
|
}
|
|
1119
1136
|
}
|
|
1120
1137
|
checkHideFilter() {
|
|
1121
|
-
var _a;
|
|
1122
1138
|
const params = this.props.params;
|
|
1123
1139
|
if (params && params.hideFilter !== 'auto') {
|
|
1124
1140
|
return;
|
|
1125
1141
|
}
|
|
1126
1142
|
const state = this.state;
|
|
1127
|
-
const isPartial = (
|
|
1143
|
+
const isPartial = vue.unref(this.isPartial);
|
|
1128
1144
|
if (state.multiple || isPartial) {
|
|
1129
1145
|
state.hideFilter = false;
|
|
1130
1146
|
}
|
|
@@ -1414,12 +1430,12 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
|
|
|
1414
1430
|
const state = store.state;
|
|
1415
1431
|
const isMultiple = state.multiple;
|
|
1416
1432
|
const hasItems = state.filteredOptions.length === 0;
|
|
1417
|
-
const canNotSelect = !!state.searchText && !store.hasAllItems
|
|
1433
|
+
const canNotSelect = !!state.searchText && !vue.unref(store.hasAllItems);
|
|
1418
1434
|
return !isMultiple || hasItems || canNotSelect;
|
|
1419
1435
|
}
|
|
1420
1436
|
get disableRevert() {
|
|
1421
1437
|
const store = this.store;
|
|
1422
|
-
return !store.state.multiple || !store.hasFetchedAllItems
|
|
1438
|
+
return !store.state.multiple || !vue.unref(store.hasFetchedAllItems);
|
|
1423
1439
|
}
|
|
1424
1440
|
get enableRevert() {
|
|
1425
1441
|
const state = this.store.state;
|
|
@@ -1457,6 +1473,10 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
|
|
|
1457
1473
|
this.store.commit('selectionIsExcluded', !this.selectionIsExcluded);
|
|
1458
1474
|
}
|
|
1459
1475
|
togglePanel() {
|
|
1476
|
+
if (this.store.state.keepFilterOpen === true) {
|
|
1477
|
+
this.closed = false;
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1460
1480
|
this.closed = !this.closed;
|
|
1461
1481
|
}
|
|
1462
1482
|
getFocus() {
|
|
@@ -1473,7 +1493,8 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
|
|
|
1473
1493
|
/* }}} */
|
|
1474
1494
|
/* {{{ Life cycle */
|
|
1475
1495
|
mounted() {
|
|
1476
|
-
|
|
1496
|
+
const state = this.store.state;
|
|
1497
|
+
this.closed = !state.keepFilterOpen && !state.searchText;
|
|
1477
1498
|
document.addEventListener('keypress', this.onKeyPressed);
|
|
1478
1499
|
this.getFocus();
|
|
1479
1500
|
}
|
|
@@ -1482,24 +1503,27 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
|
|
|
1482
1503
|
}
|
|
1483
1504
|
/* }}} */
|
|
1484
1505
|
render() {
|
|
1506
|
+
const store = this.store;
|
|
1507
|
+
const state = store.state;
|
|
1508
|
+
const labels = store.data.labels;
|
|
1485
1509
|
return (vtyx.h("div", { class: "filter-panel" },
|
|
1486
1510
|
vtyx.h("div", { class: {
|
|
1487
1511
|
panelclosed: this.closed,
|
|
1488
1512
|
panelopened: !this.closed,
|
|
1489
1513
|
} },
|
|
1490
1514
|
vtyx.h("div", { class: "filter-panel__input form-group has-feedback" },
|
|
1491
|
-
vtyx.h("input", { type: "text", class: "form-control filter-input", placeholder: this.searchPlaceholder, value:
|
|
1515
|
+
vtyx.h("input", { type: "text", class: "form-control filter-input", placeholder: this.searchPlaceholder, value: state.searchText, on: {
|
|
1492
1516
|
'input.stop.prevent': this.onInput,
|
|
1493
1517
|
}, ref: "filterInput" }),
|
|
1494
1518
|
vtyx.h("span", { class: "fa fa-search selectic-search-scope\n form-control-feedback" })),
|
|
1495
|
-
|
|
1519
|
+
state.multiple && (vtyx.h("div", { class: "toggle-selectic" },
|
|
1496
1520
|
vtyx.h("label", { class: ['control-label', {
|
|
1497
1521
|
'selectic__label-disabled': this.disableSelectAll,
|
|
1498
1522
|
}] },
|
|
1499
|
-
vtyx.h("input", { type: "checkbox", checked:
|
|
1523
|
+
vtyx.h("input", { type: "checkbox", checked: state.status.areAllSelected, disabled: this.disableSelectAll, on: {
|
|
1500
1524
|
change: this.onSelectAll,
|
|
1501
1525
|
} }),
|
|
1502
|
-
|
|
1526
|
+
labels.selectAll))),
|
|
1503
1527
|
this.enableRevert && (vtyx.h("div", { class: ['toggle-selectic', {
|
|
1504
1528
|
'selectic__label-disabled': this.disableRevert,
|
|
1505
1529
|
}] },
|
|
@@ -1507,8 +1531,8 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
|
|
|
1507
1531
|
vtyx.h("input", { type: "checkbox", checked: this.selectionIsExcluded, disabled: this.disableRevert, on: {
|
|
1508
1532
|
change: this.onExclude,
|
|
1509
1533
|
} }),
|
|
1510
|
-
|
|
1511
|
-
vtyx.h("div", { class: "curtain-handler", on: {
|
|
1534
|
+
labels.excludeResult)))),
|
|
1535
|
+
!state.keepFilterOpen && (vtyx.h("div", { class: "curtain-handler", on: {
|
|
1512
1536
|
'click.prevent.stop': this.togglePanel,
|
|
1513
1537
|
} },
|
|
1514
1538
|
vtyx.h("span", { class: "fa fa-search" }),
|
|
@@ -1516,7 +1540,7 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
|
|
|
1516
1540
|
'fa': true,
|
|
1517
1541
|
'fa-caret-down': this.closed,
|
|
1518
1542
|
'fa-caret-up': !this.closed,
|
|
1519
|
-
} }))));
|
|
1543
|
+
} })))));
|
|
1520
1544
|
}
|
|
1521
1545
|
};
|
|
1522
1546
|
__decorate$3([
|
|
@@ -1558,9 +1582,8 @@ let List = class List extends vtyx.Vue {
|
|
|
1558
1582
|
return this.store.state.multiple;
|
|
1559
1583
|
}
|
|
1560
1584
|
get itemsMargin() {
|
|
1561
|
-
var _a;
|
|
1562
1585
|
/* XXX: I don't really know when we should use value or not... */
|
|
1563
|
-
return (
|
|
1586
|
+
return vue.unref(this.store.marginSize);
|
|
1564
1587
|
}
|
|
1565
1588
|
get shortOptions() {
|
|
1566
1589
|
const endIndex = this.endIndex;
|
|
@@ -2002,15 +2025,26 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2002
2025
|
}
|
|
2003
2026
|
get outsideListener() {
|
|
2004
2027
|
return (evt) => {
|
|
2005
|
-
const target = evt.target;
|
|
2006
2028
|
if (!this.$refs) {
|
|
2007
2029
|
/* this component should have been destroyed */
|
|
2008
2030
|
this.removeListeners();
|
|
2009
2031
|
this.store.commit('isOpen', false);
|
|
2010
2032
|
return;
|
|
2011
2033
|
}
|
|
2012
|
-
|
|
2013
|
-
|
|
2034
|
+
const store = this.store;
|
|
2035
|
+
const keepOpenWithOtherSelectic = this.params.keepOpenWithOtherSelectic;
|
|
2036
|
+
const extendedList = this.$refs.extendedList;
|
|
2037
|
+
if (!extendedList) {
|
|
2038
|
+
/* this component is not focused anymore */
|
|
2039
|
+
if (!keepOpenWithOtherSelectic) {
|
|
2040
|
+
this.removeListeners();
|
|
2041
|
+
this.store.commit('isOpen', false);
|
|
2042
|
+
}
|
|
2043
|
+
return;
|
|
2044
|
+
}
|
|
2045
|
+
const target = evt.target;
|
|
2046
|
+
if (!extendedList.$el.contains(target) && !this.$el.contains(target)) {
|
|
2047
|
+
store.commit('isOpen', false);
|
|
2014
2048
|
}
|
|
2015
2049
|
};
|
|
2016
2050
|
}
|
|
@@ -2150,7 +2184,7 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2150
2184
|
window.addEventListener('resize', this.windowResize, false);
|
|
2151
2185
|
document.addEventListener('click', this.outsideListener, true);
|
|
2152
2186
|
this.computeOffset();
|
|
2153
|
-
this
|
|
2187
|
+
this.emit('open');
|
|
2154
2188
|
}
|
|
2155
2189
|
else {
|
|
2156
2190
|
this.removeListeners();
|
|
@@ -2158,7 +2192,7 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2158
2192
|
this.$emit('change', this.getValue(), state.selectionIsExcluded, this);
|
|
2159
2193
|
this.store.resetChange();
|
|
2160
2194
|
}
|
|
2161
|
-
this
|
|
2195
|
+
this.emit('close');
|
|
2162
2196
|
}
|
|
2163
2197
|
}
|
|
2164
2198
|
compareValues(oldValue, newValue) {
|
|
@@ -2221,9 +2255,9 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2221
2255
|
const canTrigger = (oldValue !== undefined || !this.hasGivenValue) && !areSimilar;
|
|
2222
2256
|
if (canTrigger) {
|
|
2223
2257
|
const selectionIsExcluded = this.store.state.selectionIsExcluded;
|
|
2224
|
-
this
|
|
2258
|
+
this.emit('input', value, selectionIsExcluded);
|
|
2225
2259
|
if (!this.isFocused) {
|
|
2226
|
-
this
|
|
2260
|
+
this.emit('change', value, selectionIsExcluded);
|
|
2227
2261
|
this.store.resetChange();
|
|
2228
2262
|
}
|
|
2229
2263
|
}
|
|
@@ -2246,12 +2280,42 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2246
2280
|
this.store.commit('isOpen', false);
|
|
2247
2281
|
}, 0);
|
|
2248
2282
|
}
|
|
2249
|
-
|
|
2283
|
+
_emit(event, ...args) {
|
|
2250
2284
|
this.$emit(event, ...args);
|
|
2251
2285
|
if (typeof this._on === 'function') {
|
|
2252
2286
|
this._on(event, ...args);
|
|
2253
2287
|
}
|
|
2254
2288
|
}
|
|
2289
|
+
emit(event, value, isExcluded) {
|
|
2290
|
+
const automatic = this.store.state.status.automaticChange;
|
|
2291
|
+
const options = {
|
|
2292
|
+
instance: this,
|
|
2293
|
+
eventType: event,
|
|
2294
|
+
automatic,
|
|
2295
|
+
};
|
|
2296
|
+
switch (event) {
|
|
2297
|
+
case 'input':
|
|
2298
|
+
case 'change':
|
|
2299
|
+
const changeOptions = Object.assign({
|
|
2300
|
+
isExcluded: isExcluded,
|
|
2301
|
+
}, options);
|
|
2302
|
+
this._emit(event, value, changeOptions);
|
|
2303
|
+
break;
|
|
2304
|
+
case 'open':
|
|
2305
|
+
case 'focus':
|
|
2306
|
+
this._emit('open', options);
|
|
2307
|
+
this._emit('focus', options);
|
|
2308
|
+
break;
|
|
2309
|
+
case 'close':
|
|
2310
|
+
case 'blur':
|
|
2311
|
+
this._emit('close', options);
|
|
2312
|
+
this._emit('blur', options);
|
|
2313
|
+
break;
|
|
2314
|
+
case 'item:click':
|
|
2315
|
+
this._emit(event, value, options);
|
|
2316
|
+
break;
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2255
2319
|
// private extractFromNode(node: Vue.VNode, text = ''): OptionValue {
|
|
2256
2320
|
// function styleToString(staticStyle?: {[key: string]: string}): string | undefined {
|
|
2257
2321
|
// if (!staticStyle) {
|
|
@@ -2330,7 +2394,7 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2330
2394
|
/* }}} */
|
|
2331
2395
|
/* {{{ Life cycle */
|
|
2332
2396
|
created() {
|
|
2333
|
-
var _a, _b;
|
|
2397
|
+
var _a, _b, _c;
|
|
2334
2398
|
this._elementsListeners = [];
|
|
2335
2399
|
this.store = new SelecticStore({
|
|
2336
2400
|
options: this.options,
|
|
@@ -2343,8 +2407,7 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2343
2407
|
params: {
|
|
2344
2408
|
multiple: ((_a = this.multiple) !== null && _a !== void 0 ? _a : false) !== false,
|
|
2345
2409
|
pageSize: this.params.pageSize || 100,
|
|
2346
|
-
hideFilter: this.params.hideFilter !==
|
|
2347
|
-
? this.params.hideFilter : 'auto',
|
|
2410
|
+
hideFilter: (_b = this.params.hideFilter) !== null && _b !== void 0 ? _b : 'auto',
|
|
2348
2411
|
allowRevert: this.params.allowRevert,
|
|
2349
2412
|
allowClearSelection: this.params.allowClearSelection || false,
|
|
2350
2413
|
autoSelect: this.params.autoSelect === undefined
|
|
@@ -2359,7 +2422,7 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2359
2422
|
formatSelection: this.params.formatSelection,
|
|
2360
2423
|
listPosition: this.params.listPosition || 'auto',
|
|
2361
2424
|
optionBehavior: this.params.optionBehavior,
|
|
2362
|
-
isOpen: ((
|
|
2425
|
+
isOpen: ((_c = this.open) !== null && _c !== void 0 ? _c : false) !== false,
|
|
2363
2426
|
},
|
|
2364
2427
|
fetchCallback: this.params.fetchCallback,
|
|
2365
2428
|
getItemsCallback: this.params.getItemsCallback,
|
|
@@ -2418,7 +2481,7 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2418
2481
|
blur: this.checkFocus,
|
|
2419
2482
|
} }),
|
|
2420
2483
|
vtyx.h(MainInput$1, { store: store, id: id, on: {
|
|
2421
|
-
'item:click': (id) => this.emit('item:click', id
|
|
2484
|
+
'item:click': (id) => this.emit('item:click', id),
|
|
2422
2485
|
}, ref: "mainInput" }),
|
|
2423
2486
|
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" }))));
|
|
2424
2487
|
}
|
|
@@ -2505,10 +2568,19 @@ __decorate([
|
|
|
2505
2568
|
__decorate([
|
|
2506
2569
|
vtyx.Watch('store.state.internalValue')
|
|
2507
2570
|
], Selectic.prototype, "onInternalValueChange", null);
|
|
2571
|
+
__decorate([
|
|
2572
|
+
vtyx.Emit('input'),
|
|
2573
|
+
vtyx.Emit('change'),
|
|
2574
|
+
vtyx.Emit('open'),
|
|
2575
|
+
vtyx.Emit('focus'),
|
|
2576
|
+
vtyx.Emit('close'),
|
|
2577
|
+
vtyx.Emit('blur'),
|
|
2578
|
+
vtyx.Emit('item:click')
|
|
2579
|
+
], Selectic.prototype, "render", null);
|
|
2508
2580
|
Selectic = __decorate([
|
|
2509
2581
|
vtyx.Component
|
|
2510
2582
|
], Selectic);
|
|
2511
2583
|
var Selectic$1 = Selectic;
|
|
2512
2584
|
|
|
2513
2585
|
exports.changeTexts = changeTexts;
|
|
2514
|
-
exports[
|
|
2586
|
+
exports["default"] = Selectic$1;
|