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
package/dist/selectic.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Prop, Watch, Component, Vue, h } from 'vtyx';
|
|
2
|
-
import { reactive, computed, watch } from 'vue';
|
|
1
|
+
import { Prop, Watch, Component, Vue, h, Emit } from 'vtyx';
|
|
2
|
+
import { reactive, computed, unref, watch } from 'vue';
|
|
3
3
|
|
|
4
4
|
function styleInject(css, ref) {
|
|
5
5
|
if ( ref === void 0 ) ref = {};
|
|
@@ -103,6 +103,7 @@ class SelecticStore {
|
|
|
103
103
|
disabled: false,
|
|
104
104
|
placeholder: '',
|
|
105
105
|
hideFilter: false,
|
|
106
|
+
keepFilterOpen: false,
|
|
106
107
|
allowRevert: undefined,
|
|
107
108
|
allowClearSelection: false,
|
|
108
109
|
autoSelect: true,
|
|
@@ -132,6 +133,8 @@ class SelecticStore {
|
|
|
132
133
|
errorMessage: '',
|
|
133
134
|
areAllSelected: false,
|
|
134
135
|
hasChanged: false,
|
|
136
|
+
automaticChange: false,
|
|
137
|
+
automaticClose: false,
|
|
135
138
|
},
|
|
136
139
|
});
|
|
137
140
|
/* Do not need reactivity */
|
|
@@ -184,8 +187,7 @@ class SelecticStore {
|
|
|
184
187
|
return this.state.filteredOptions.length >= nbItems;
|
|
185
188
|
});
|
|
186
189
|
this.hasFetchedAllItems = computed(() => {
|
|
187
|
-
|
|
188
|
-
const isPartial = (_a = this.isPartial.value) !== null && _a !== void 0 ? _a : this.isPartial;
|
|
190
|
+
const isPartial = unref(this.isPartial);
|
|
189
191
|
if (!isPartial) {
|
|
190
192
|
return true;
|
|
191
193
|
}
|
|
@@ -202,6 +204,7 @@ class SelecticStore {
|
|
|
202
204
|
/* {{{ watch */
|
|
203
205
|
watch(() => [this.props.options, this.props.childOptions], () => {
|
|
204
206
|
this.data.cacheItem.clear();
|
|
207
|
+
this.setAutomaticClose();
|
|
205
208
|
this.commit('isOpen', false);
|
|
206
209
|
this.buildAllOptions(true);
|
|
207
210
|
this.buildSelectedOptions();
|
|
@@ -223,9 +226,8 @@ class SelecticStore {
|
|
|
223
226
|
this.commit('disabled', this.props.disabled);
|
|
224
227
|
});
|
|
225
228
|
watch(() => this.state.filteredOptions, () => {
|
|
226
|
-
var _a;
|
|
227
229
|
let areAllSelected = false;
|
|
228
|
-
const hasAllItems = (
|
|
230
|
+
const hasAllItems = unref(this.hasAllItems);
|
|
229
231
|
if (hasAllItems) {
|
|
230
232
|
const selectionIsExcluded = +this.state.selectionIsExcluded;
|
|
231
233
|
/* eslint-disable-next-line no-bitwise */
|
|
@@ -245,6 +247,7 @@ class SelecticStore {
|
|
|
245
247
|
});
|
|
246
248
|
/* }}} */
|
|
247
249
|
this.closeSelectic = () => {
|
|
250
|
+
this.setAutomaticClose();
|
|
248
251
|
this.commit('isOpen', false);
|
|
249
252
|
};
|
|
250
253
|
const value = this.props.value;
|
|
@@ -258,6 +261,10 @@ class SelecticStore {
|
|
|
258
261
|
if (stateParam.hideFilter === 'auto') {
|
|
259
262
|
delete stateParam.hideFilter;
|
|
260
263
|
}
|
|
264
|
+
else if (stateParam.hideFilter === 'open') {
|
|
265
|
+
this.state.keepFilterOpen = true;
|
|
266
|
+
delete stateParam.hideFilter;
|
|
267
|
+
}
|
|
261
268
|
/* Update state */
|
|
262
269
|
assignObject(this.state, stateParam);
|
|
263
270
|
/* XXX: should be done in 2 lines, in order to set the multiple state
|
|
@@ -333,11 +340,20 @@ class SelecticStore {
|
|
|
333
340
|
break;
|
|
334
341
|
case 'disabled':
|
|
335
342
|
if (value) {
|
|
343
|
+
this.setAutomaticClose();
|
|
336
344
|
this.commit('isOpen', false);
|
|
337
345
|
}
|
|
338
346
|
break;
|
|
339
347
|
}
|
|
340
348
|
}
|
|
349
|
+
setAutomaticChange() {
|
|
350
|
+
this.state.status.automaticChange = true;
|
|
351
|
+
setTimeout(() => this.state.status.automaticChange = false, 0);
|
|
352
|
+
}
|
|
353
|
+
setAutomaticClose() {
|
|
354
|
+
this.state.status.automaticClose = true;
|
|
355
|
+
setTimeout(() => this.state.status.automaticClose = false, 0);
|
|
356
|
+
}
|
|
341
357
|
getItem(id) {
|
|
342
358
|
let item;
|
|
343
359
|
if (this.hasItemInStore(id)) {
|
|
@@ -380,10 +396,9 @@ class SelecticStore {
|
|
|
380
396
|
return this.buildSelectedItems(ids);
|
|
381
397
|
}
|
|
382
398
|
selectItem(id, selected, keepOpen = false) {
|
|
383
|
-
var _a;
|
|
384
399
|
const state = this.state;
|
|
385
400
|
let hasChanged = false;
|
|
386
|
-
const isPartial = (
|
|
401
|
+
const isPartial = unref(this.isPartial);
|
|
387
402
|
/* Check that item is not disabled */
|
|
388
403
|
if (!isPartial) {
|
|
389
404
|
const item = state.allOptions.find((opt) => opt.id === id);
|
|
@@ -436,6 +451,10 @@ class SelecticStore {
|
|
|
436
451
|
else if (id === oldValue) {
|
|
437
452
|
return;
|
|
438
453
|
}
|
|
454
|
+
if (keepOpen) {
|
|
455
|
+
/* if keepOpen is true it means that it is an automatic change */
|
|
456
|
+
this.setAutomaticChange();
|
|
457
|
+
}
|
|
439
458
|
this.commit('internalValue', id);
|
|
440
459
|
hasChanged = true;
|
|
441
460
|
}
|
|
@@ -444,11 +463,10 @@ class SelecticStore {
|
|
|
444
463
|
}
|
|
445
464
|
}
|
|
446
465
|
toggleSelectAll() {
|
|
447
|
-
var _a;
|
|
448
466
|
if (!this.state.multiple) {
|
|
449
467
|
return;
|
|
450
468
|
}
|
|
451
|
-
const hasAllItems = (
|
|
469
|
+
const hasAllItems = unref(this.hasAllItems);
|
|
452
470
|
if (!hasAllItems) {
|
|
453
471
|
const labels = this.data.labels;
|
|
454
472
|
if (this.state.searchText) {
|
|
@@ -481,8 +499,7 @@ class SelecticStore {
|
|
|
481
499
|
this.state.status.errorMessage = '';
|
|
482
500
|
}
|
|
483
501
|
clearCache(forceReset = false) {
|
|
484
|
-
|
|
485
|
-
const isPartial = (_a = this.isPartial.value) !== null && _a !== void 0 ? _a : this.isPartial;
|
|
502
|
+
const isPartial = unref(this.isPartial);
|
|
486
503
|
const total = isPartial ? Infinity : 0;
|
|
487
504
|
this.data.cacheItem.clear();
|
|
488
505
|
this.state.allOptions = [];
|
|
@@ -522,14 +539,13 @@ class SelecticStore {
|
|
|
522
539
|
return !!this.getValue(id);
|
|
523
540
|
}
|
|
524
541
|
getValue(id) {
|
|
525
|
-
var _a, _b;
|
|
526
542
|
function findId(option) {
|
|
527
543
|
return option.id === id;
|
|
528
544
|
}
|
|
529
545
|
return this.state.filteredOptions.find(findId) ||
|
|
530
546
|
this.state.dynOptions.find(findId) ||
|
|
531
|
-
(
|
|
532
|
-
(
|
|
547
|
+
unref(this.listOptions).find(findId) ||
|
|
548
|
+
unref(this.elementOptions).find(findId);
|
|
533
549
|
}
|
|
534
550
|
convertTypeValue(oldValue) {
|
|
535
551
|
const state = this.state;
|
|
@@ -553,11 +569,11 @@ class SelecticStore {
|
|
|
553
569
|
const internalValue = state.internalValue;
|
|
554
570
|
const newValue = this.convertTypeValue(internalValue);
|
|
555
571
|
if (newValue !== internalValue) {
|
|
572
|
+
this.setAutomaticChange();
|
|
556
573
|
state.internalValue = newValue;
|
|
557
574
|
}
|
|
558
575
|
}
|
|
559
576
|
assertCorrectValue(applyStrict = false) {
|
|
560
|
-
var _a, _b;
|
|
561
577
|
const state = this.state;
|
|
562
578
|
this.assertValueType();
|
|
563
579
|
const internalValue = state.internalValue;
|
|
@@ -565,9 +581,9 @@ class SelecticStore {
|
|
|
565
581
|
const isMultiple = state.multiple;
|
|
566
582
|
const checkStrict = state.strictValue;
|
|
567
583
|
let newValue = internalValue;
|
|
568
|
-
const isPartial = (
|
|
584
|
+
const isPartial = unref(this.isPartial);
|
|
569
585
|
if (isMultiple) {
|
|
570
|
-
const hasFetchedAllItems = (
|
|
586
|
+
const hasFetchedAllItems = unref(this.hasFetchedAllItems);
|
|
571
587
|
if (selectionIsExcluded && hasFetchedAllItems) {
|
|
572
588
|
newValue = state.allOptions.reduce((values, option) => {
|
|
573
589
|
const id = option.id;
|
|
@@ -605,6 +621,7 @@ class SelecticStore {
|
|
|
605
621
|
}
|
|
606
622
|
}
|
|
607
623
|
if (isDifferent) {
|
|
624
|
+
this.setAutomaticChange();
|
|
608
625
|
newValue = filteredValue;
|
|
609
626
|
}
|
|
610
627
|
}
|
|
@@ -693,13 +710,12 @@ class SelecticStore {
|
|
|
693
710
|
return childOptions;
|
|
694
711
|
}
|
|
695
712
|
buildAllOptions(keepFetched = false) {
|
|
696
|
-
var _a, _b, _c;
|
|
697
713
|
const allOptions = [];
|
|
698
714
|
let listOptions = [];
|
|
699
715
|
let elementOptions = [];
|
|
700
716
|
const optionBehaviorOrder = this.state.optionBehaviorOrder;
|
|
701
717
|
let length = Infinity;
|
|
702
|
-
const isPartial = (
|
|
718
|
+
const isPartial = unref(this.isPartial);
|
|
703
719
|
const arrayFromOrder = (orderValue) => {
|
|
704
720
|
switch (orderValue) {
|
|
705
721
|
case 'O': return listOptions;
|
|
@@ -725,8 +741,8 @@ class SelecticStore {
|
|
|
725
741
|
this.state.totalDynOptions = 0;
|
|
726
742
|
}
|
|
727
743
|
}
|
|
728
|
-
listOptions = (
|
|
729
|
-
elementOptions = (
|
|
744
|
+
listOptions = unref(this.listOptions);
|
|
745
|
+
elementOptions = unref(this.elementOptions);
|
|
730
746
|
if (this.state.optionBehaviorOperation === 'force') {
|
|
731
747
|
const orderValue = optionBehaviorOrder.find((value) => lengthFromOrder(value) > 0);
|
|
732
748
|
allOptions.push(...arrayFromOrder(orderValue));
|
|
@@ -772,7 +788,6 @@ class SelecticStore {
|
|
|
772
788
|
});
|
|
773
789
|
}
|
|
774
790
|
async buildFilteredOptions() {
|
|
775
|
-
var _a, _b, _c, _d;
|
|
776
791
|
if (!this.state.isOpen) {
|
|
777
792
|
/* Do not try to fetch anything while the select is not open */
|
|
778
793
|
return;
|
|
@@ -782,12 +797,12 @@ class SelecticStore {
|
|
|
782
797
|
const totalAllOptions = this.state.totalAllOptions;
|
|
783
798
|
const allOptionsLength = allOptions.length;
|
|
784
799
|
let filteredOptionsLength = this.state.filteredOptions.length;
|
|
785
|
-
const hasAllItems = (
|
|
800
|
+
const hasAllItems = unref(this.hasAllItems);
|
|
786
801
|
if (hasAllItems) {
|
|
787
802
|
/* Everything has already been fetched and stored in filteredOptions */
|
|
788
803
|
return;
|
|
789
804
|
}
|
|
790
|
-
const hasFetchedAllItems = (
|
|
805
|
+
const hasFetchedAllItems = unref(this.hasFetchedAllItems);
|
|
791
806
|
/* Check if all options have been fetched */
|
|
792
807
|
if (hasFetchedAllItems) {
|
|
793
808
|
if (!search) {
|
|
@@ -802,7 +817,7 @@ class SelecticStore {
|
|
|
802
817
|
}
|
|
803
818
|
/* When we only have partial options */
|
|
804
819
|
const offsetItem = this.state.offsetItem;
|
|
805
|
-
const marginSize = (
|
|
820
|
+
const marginSize = unref(this.marginSize);
|
|
806
821
|
const endIndex = offsetItem + marginSize;
|
|
807
822
|
if (endIndex <= filteredOptionsLength) {
|
|
808
823
|
return;
|
|
@@ -810,7 +825,7 @@ class SelecticStore {
|
|
|
810
825
|
if (!search && endIndex <= allOptionsLength) {
|
|
811
826
|
this.state.filteredOptions = this.buildGroupItems(allOptions);
|
|
812
827
|
this.state.totalFilteredOptions = totalAllOptions + this.state.groups.size;
|
|
813
|
-
const isPartial = (
|
|
828
|
+
const isPartial = unref(this.isPartial);
|
|
814
829
|
if (isPartial && this.state.totalDynOptions === Infinity) {
|
|
815
830
|
this.fetchData();
|
|
816
831
|
}
|
|
@@ -847,6 +862,7 @@ class SelecticStore {
|
|
|
847
862
|
}
|
|
848
863
|
else {
|
|
849
864
|
const itemIds = items.map((item) => item.id);
|
|
865
|
+
this.setAutomaticChange();
|
|
850
866
|
this.commit('internalValue', itemIds);
|
|
851
867
|
}
|
|
852
868
|
return;
|
|
@@ -867,6 +883,7 @@ class SelecticStore {
|
|
|
867
883
|
}
|
|
868
884
|
if (!items.length) {
|
|
869
885
|
if (state.strictValue) {
|
|
886
|
+
this.setAutomaticChange();
|
|
870
887
|
this.commit('internalValue', null);
|
|
871
888
|
}
|
|
872
889
|
return;
|
|
@@ -876,7 +893,6 @@ class SelecticStore {
|
|
|
876
893
|
}
|
|
877
894
|
}
|
|
878
895
|
async fetchData() {
|
|
879
|
-
var _a;
|
|
880
896
|
const state = this.state;
|
|
881
897
|
const labels = this.data.labels;
|
|
882
898
|
const fetchCallback = this.props.fetchCallback;
|
|
@@ -888,7 +904,7 @@ class SelecticStore {
|
|
|
888
904
|
const filteredOptionsLength = state.filteredOptions.length;
|
|
889
905
|
const offsetItem = state.offsetItem;
|
|
890
906
|
const pageSize = state.pageSize;
|
|
891
|
-
const marginSize = (
|
|
907
|
+
const marginSize = unref(this.marginSize);
|
|
892
908
|
const endIndex = offsetItem + marginSize;
|
|
893
909
|
const dynOffset = this.data.dynOffset;
|
|
894
910
|
/* Run the query */
|
|
@@ -960,7 +976,6 @@ class SelecticStore {
|
|
|
960
976
|
return this.buildGroupItems(options.filter((option) => rgx.test(option.text)));
|
|
961
977
|
}
|
|
962
978
|
addStaticFilteredOptions(fromDynamic = false) {
|
|
963
|
-
var _a, _b;
|
|
964
979
|
const search = this.state.searchText;
|
|
965
980
|
let continueLoop = fromDynamic;
|
|
966
981
|
if (this.state.optionBehaviorOperation !== 'sort') {
|
|
@@ -980,10 +995,10 @@ class SelecticStore {
|
|
|
980
995
|
}
|
|
981
996
|
switch (order) {
|
|
982
997
|
case 'O':
|
|
983
|
-
options = this.filterOptions((
|
|
998
|
+
options = this.filterOptions(unref(this.listOptions), search);
|
|
984
999
|
break;
|
|
985
1000
|
case 'E':
|
|
986
|
-
options = this.filterOptions((
|
|
1001
|
+
options = this.filterOptions(unref(this.elementOptions), search);
|
|
987
1002
|
break;
|
|
988
1003
|
}
|
|
989
1004
|
this.state.filteredOptions.push(...options);
|
|
@@ -1089,11 +1104,10 @@ class SelecticStore {
|
|
|
1089
1104
|
}
|
|
1090
1105
|
}
|
|
1091
1106
|
checkAutoDisabled() {
|
|
1092
|
-
var _a, _b;
|
|
1093
1107
|
const state = this.state;
|
|
1094
|
-
const isPartial = (
|
|
1108
|
+
const isPartial = unref(this.isPartial);
|
|
1095
1109
|
const doNotCheck = isPartial || this.props.disabled || !state.autoDisabled;
|
|
1096
|
-
const hasFetchedAllItems = (
|
|
1110
|
+
const hasFetchedAllItems = unref(this.hasFetchedAllItems);
|
|
1097
1111
|
if (doNotCheck || !hasFetchedAllItems) {
|
|
1098
1112
|
return;
|
|
1099
1113
|
}
|
|
@@ -1106,7 +1120,10 @@ class SelecticStore {
|
|
|
1106
1120
|
const isEmpty = nb === 0;
|
|
1107
1121
|
const hasOnlyOneOption = nb === 1 && hasValidValue && !state.allowClearSelection;
|
|
1108
1122
|
if (hasOnlyOneOption || isEmpty) {
|
|
1109
|
-
|
|
1123
|
+
if (state.isOpen) {
|
|
1124
|
+
this.setAutomaticClose();
|
|
1125
|
+
this.commit('isOpen', false);
|
|
1126
|
+
}
|
|
1110
1127
|
this.commit('disabled', true);
|
|
1111
1128
|
}
|
|
1112
1129
|
else {
|
|
@@ -1114,13 +1131,12 @@ class SelecticStore {
|
|
|
1114
1131
|
}
|
|
1115
1132
|
}
|
|
1116
1133
|
checkHideFilter() {
|
|
1117
|
-
var _a;
|
|
1118
1134
|
const params = this.props.params;
|
|
1119
1135
|
if (params && params.hideFilter !== 'auto') {
|
|
1120
1136
|
return;
|
|
1121
1137
|
}
|
|
1122
1138
|
const state = this.state;
|
|
1123
|
-
const isPartial = (
|
|
1139
|
+
const isPartial = unref(this.isPartial);
|
|
1124
1140
|
if (state.multiple || isPartial) {
|
|
1125
1141
|
state.hideFilter = false;
|
|
1126
1142
|
}
|
|
@@ -1410,12 +1426,12 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1410
1426
|
const state = store.state;
|
|
1411
1427
|
const isMultiple = state.multiple;
|
|
1412
1428
|
const hasItems = state.filteredOptions.length === 0;
|
|
1413
|
-
const canNotSelect = !!state.searchText && !store.hasAllItems
|
|
1429
|
+
const canNotSelect = !!state.searchText && !unref(store.hasAllItems);
|
|
1414
1430
|
return !isMultiple || hasItems || canNotSelect;
|
|
1415
1431
|
}
|
|
1416
1432
|
get disableRevert() {
|
|
1417
1433
|
const store = this.store;
|
|
1418
|
-
return !store.state.multiple || !store.hasFetchedAllItems
|
|
1434
|
+
return !store.state.multiple || !unref(store.hasFetchedAllItems);
|
|
1419
1435
|
}
|
|
1420
1436
|
get enableRevert() {
|
|
1421
1437
|
const state = this.store.state;
|
|
@@ -1453,6 +1469,10 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1453
1469
|
this.store.commit('selectionIsExcluded', !this.selectionIsExcluded);
|
|
1454
1470
|
}
|
|
1455
1471
|
togglePanel() {
|
|
1472
|
+
if (this.store.state.keepFilterOpen === true) {
|
|
1473
|
+
this.closed = false;
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1456
1476
|
this.closed = !this.closed;
|
|
1457
1477
|
}
|
|
1458
1478
|
getFocus() {
|
|
@@ -1469,7 +1489,8 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1469
1489
|
/* }}} */
|
|
1470
1490
|
/* {{{ Life cycle */
|
|
1471
1491
|
mounted() {
|
|
1472
|
-
|
|
1492
|
+
const state = this.store.state;
|
|
1493
|
+
this.closed = !state.keepFilterOpen && !state.searchText;
|
|
1473
1494
|
document.addEventListener('keypress', this.onKeyPressed);
|
|
1474
1495
|
this.getFocus();
|
|
1475
1496
|
}
|
|
@@ -1478,24 +1499,27 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1478
1499
|
}
|
|
1479
1500
|
/* }}} */
|
|
1480
1501
|
render() {
|
|
1502
|
+
const store = this.store;
|
|
1503
|
+
const state = store.state;
|
|
1504
|
+
const labels = store.data.labels;
|
|
1481
1505
|
return (h("div", { class: "filter-panel" },
|
|
1482
1506
|
h("div", { class: {
|
|
1483
1507
|
panelclosed: this.closed,
|
|
1484
1508
|
panelopened: !this.closed,
|
|
1485
1509
|
} },
|
|
1486
1510
|
h("div", { class: "filter-panel__input form-group has-feedback" },
|
|
1487
|
-
h("input", { type: "text", class: "form-control filter-input", placeholder: this.searchPlaceholder, value:
|
|
1511
|
+
h("input", { type: "text", class: "form-control filter-input", placeholder: this.searchPlaceholder, value: state.searchText, on: {
|
|
1488
1512
|
'input.stop.prevent': this.onInput,
|
|
1489
1513
|
}, ref: "filterInput" }),
|
|
1490
1514
|
h("span", { class: "fa fa-search selectic-search-scope\n form-control-feedback" })),
|
|
1491
|
-
|
|
1515
|
+
state.multiple && (h("div", { class: "toggle-selectic" },
|
|
1492
1516
|
h("label", { class: ['control-label', {
|
|
1493
1517
|
'selectic__label-disabled': this.disableSelectAll,
|
|
1494
1518
|
}] },
|
|
1495
|
-
h("input", { type: "checkbox", checked:
|
|
1519
|
+
h("input", { type: "checkbox", checked: state.status.areAllSelected, disabled: this.disableSelectAll, on: {
|
|
1496
1520
|
change: this.onSelectAll,
|
|
1497
1521
|
} }),
|
|
1498
|
-
|
|
1522
|
+
labels.selectAll))),
|
|
1499
1523
|
this.enableRevert && (h("div", { class: ['toggle-selectic', {
|
|
1500
1524
|
'selectic__label-disabled': this.disableRevert,
|
|
1501
1525
|
}] },
|
|
@@ -1503,8 +1527,8 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1503
1527
|
h("input", { type: "checkbox", checked: this.selectionIsExcluded, disabled: this.disableRevert, on: {
|
|
1504
1528
|
change: this.onExclude,
|
|
1505
1529
|
} }),
|
|
1506
|
-
|
|
1507
|
-
h("div", { class: "curtain-handler", on: {
|
|
1530
|
+
labels.excludeResult)))),
|
|
1531
|
+
!state.keepFilterOpen && (h("div", { class: "curtain-handler", on: {
|
|
1508
1532
|
'click.prevent.stop': this.togglePanel,
|
|
1509
1533
|
} },
|
|
1510
1534
|
h("span", { class: "fa fa-search" }),
|
|
@@ -1512,7 +1536,7 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1512
1536
|
'fa': true,
|
|
1513
1537
|
'fa-caret-down': this.closed,
|
|
1514
1538
|
'fa-caret-up': !this.closed,
|
|
1515
|
-
} }))));
|
|
1539
|
+
} })))));
|
|
1516
1540
|
}
|
|
1517
1541
|
};
|
|
1518
1542
|
__decorate$3([
|
|
@@ -1554,9 +1578,8 @@ let List = class List extends Vue {
|
|
|
1554
1578
|
return this.store.state.multiple;
|
|
1555
1579
|
}
|
|
1556
1580
|
get itemsMargin() {
|
|
1557
|
-
var _a;
|
|
1558
1581
|
/* XXX: I don't really know when we should use value or not... */
|
|
1559
|
-
return (
|
|
1582
|
+
return unref(this.store.marginSize);
|
|
1560
1583
|
}
|
|
1561
1584
|
get shortOptions() {
|
|
1562
1585
|
const endIndex = this.endIndex;
|
|
@@ -1998,15 +2021,26 @@ let Selectic = class Selectic extends Vue {
|
|
|
1998
2021
|
}
|
|
1999
2022
|
get outsideListener() {
|
|
2000
2023
|
return (evt) => {
|
|
2001
|
-
const target = evt.target;
|
|
2002
2024
|
if (!this.$refs) {
|
|
2003
2025
|
/* this component should have been destroyed */
|
|
2004
2026
|
this.removeListeners();
|
|
2005
2027
|
this.store.commit('isOpen', false);
|
|
2006
2028
|
return;
|
|
2007
2029
|
}
|
|
2008
|
-
|
|
2009
|
-
|
|
2030
|
+
const store = this.store;
|
|
2031
|
+
const keepOpenWithOtherSelectic = this.params.keepOpenWithOtherSelectic;
|
|
2032
|
+
const extendedList = this.$refs.extendedList;
|
|
2033
|
+
if (!extendedList) {
|
|
2034
|
+
/* this component is not focused anymore */
|
|
2035
|
+
if (!keepOpenWithOtherSelectic) {
|
|
2036
|
+
this.removeListeners();
|
|
2037
|
+
this.store.commit('isOpen', false);
|
|
2038
|
+
}
|
|
2039
|
+
return;
|
|
2040
|
+
}
|
|
2041
|
+
const target = evt.target;
|
|
2042
|
+
if (!extendedList.$el.contains(target) && !this.$el.contains(target)) {
|
|
2043
|
+
store.commit('isOpen', false);
|
|
2010
2044
|
}
|
|
2011
2045
|
};
|
|
2012
2046
|
}
|
|
@@ -2146,7 +2180,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2146
2180
|
window.addEventListener('resize', this.windowResize, false);
|
|
2147
2181
|
document.addEventListener('click', this.outsideListener, true);
|
|
2148
2182
|
this.computeOffset();
|
|
2149
|
-
this
|
|
2183
|
+
this.emit('open');
|
|
2150
2184
|
}
|
|
2151
2185
|
else {
|
|
2152
2186
|
this.removeListeners();
|
|
@@ -2154,7 +2188,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2154
2188
|
this.$emit('change', this.getValue(), state.selectionIsExcluded, this);
|
|
2155
2189
|
this.store.resetChange();
|
|
2156
2190
|
}
|
|
2157
|
-
this
|
|
2191
|
+
this.emit('close');
|
|
2158
2192
|
}
|
|
2159
2193
|
}
|
|
2160
2194
|
compareValues(oldValue, newValue) {
|
|
@@ -2217,9 +2251,9 @@ let Selectic = class Selectic extends Vue {
|
|
|
2217
2251
|
const canTrigger = (oldValue !== undefined || !this.hasGivenValue) && !areSimilar;
|
|
2218
2252
|
if (canTrigger) {
|
|
2219
2253
|
const selectionIsExcluded = this.store.state.selectionIsExcluded;
|
|
2220
|
-
this
|
|
2254
|
+
this.emit('input', value, selectionIsExcluded);
|
|
2221
2255
|
if (!this.isFocused) {
|
|
2222
|
-
this
|
|
2256
|
+
this.emit('change', value, selectionIsExcluded);
|
|
2223
2257
|
this.store.resetChange();
|
|
2224
2258
|
}
|
|
2225
2259
|
}
|
|
@@ -2242,12 +2276,42 @@ let Selectic = class Selectic extends Vue {
|
|
|
2242
2276
|
this.store.commit('isOpen', false);
|
|
2243
2277
|
}, 0);
|
|
2244
2278
|
}
|
|
2245
|
-
|
|
2279
|
+
_emit(event, ...args) {
|
|
2246
2280
|
this.$emit(event, ...args);
|
|
2247
2281
|
if (typeof this._on === 'function') {
|
|
2248
2282
|
this._on(event, ...args);
|
|
2249
2283
|
}
|
|
2250
2284
|
}
|
|
2285
|
+
emit(event, value, isExcluded) {
|
|
2286
|
+
const automatic = this.store.state.status.automaticChange;
|
|
2287
|
+
const options = {
|
|
2288
|
+
instance: this,
|
|
2289
|
+
eventType: event,
|
|
2290
|
+
automatic,
|
|
2291
|
+
};
|
|
2292
|
+
switch (event) {
|
|
2293
|
+
case 'input':
|
|
2294
|
+
case 'change':
|
|
2295
|
+
const changeOptions = Object.assign({
|
|
2296
|
+
isExcluded: isExcluded,
|
|
2297
|
+
}, options);
|
|
2298
|
+
this._emit(event, value, changeOptions);
|
|
2299
|
+
break;
|
|
2300
|
+
case 'open':
|
|
2301
|
+
case 'focus':
|
|
2302
|
+
this._emit('open', options);
|
|
2303
|
+
this._emit('focus', options);
|
|
2304
|
+
break;
|
|
2305
|
+
case 'close':
|
|
2306
|
+
case 'blur':
|
|
2307
|
+
this._emit('close', options);
|
|
2308
|
+
this._emit('blur', options);
|
|
2309
|
+
break;
|
|
2310
|
+
case 'item:click':
|
|
2311
|
+
this._emit(event, value, options);
|
|
2312
|
+
break;
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2251
2315
|
// private extractFromNode(node: Vue.VNode, text = ''): OptionValue {
|
|
2252
2316
|
// function styleToString(staticStyle?: {[key: string]: string}): string | undefined {
|
|
2253
2317
|
// if (!staticStyle) {
|
|
@@ -2326,7 +2390,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2326
2390
|
/* }}} */
|
|
2327
2391
|
/* {{{ Life cycle */
|
|
2328
2392
|
created() {
|
|
2329
|
-
var _a, _b;
|
|
2393
|
+
var _a, _b, _c;
|
|
2330
2394
|
this._elementsListeners = [];
|
|
2331
2395
|
this.store = new SelecticStore({
|
|
2332
2396
|
options: this.options,
|
|
@@ -2339,8 +2403,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2339
2403
|
params: {
|
|
2340
2404
|
multiple: ((_a = this.multiple) !== null && _a !== void 0 ? _a : false) !== false,
|
|
2341
2405
|
pageSize: this.params.pageSize || 100,
|
|
2342
|
-
hideFilter: this.params.hideFilter !==
|
|
2343
|
-
? this.params.hideFilter : 'auto',
|
|
2406
|
+
hideFilter: (_b = this.params.hideFilter) !== null && _b !== void 0 ? _b : 'auto',
|
|
2344
2407
|
allowRevert: this.params.allowRevert,
|
|
2345
2408
|
allowClearSelection: this.params.allowClearSelection || false,
|
|
2346
2409
|
autoSelect: this.params.autoSelect === undefined
|
|
@@ -2355,7 +2418,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2355
2418
|
formatSelection: this.params.formatSelection,
|
|
2356
2419
|
listPosition: this.params.listPosition || 'auto',
|
|
2357
2420
|
optionBehavior: this.params.optionBehavior,
|
|
2358
|
-
isOpen: ((
|
|
2421
|
+
isOpen: ((_c = this.open) !== null && _c !== void 0 ? _c : false) !== false,
|
|
2359
2422
|
},
|
|
2360
2423
|
fetchCallback: this.params.fetchCallback,
|
|
2361
2424
|
getItemsCallback: this.params.getItemsCallback,
|
|
@@ -2414,7 +2477,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2414
2477
|
blur: this.checkFocus,
|
|
2415
2478
|
} }),
|
|
2416
2479
|
h(MainInput$1, { store: store, id: id, on: {
|
|
2417
|
-
'item:click': (id) => this.emit('item:click', id
|
|
2480
|
+
'item:click': (id) => this.emit('item:click', id),
|
|
2418
2481
|
}, ref: "mainInput" }),
|
|
2419
2482
|
this.isFocused && (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" }))));
|
|
2420
2483
|
}
|
|
@@ -2501,6 +2564,15 @@ __decorate([
|
|
|
2501
2564
|
__decorate([
|
|
2502
2565
|
Watch('store.state.internalValue')
|
|
2503
2566
|
], Selectic.prototype, "onInternalValueChange", null);
|
|
2567
|
+
__decorate([
|
|
2568
|
+
Emit('input'),
|
|
2569
|
+
Emit('change'),
|
|
2570
|
+
Emit('open'),
|
|
2571
|
+
Emit('focus'),
|
|
2572
|
+
Emit('close'),
|
|
2573
|
+
Emit('blur'),
|
|
2574
|
+
Emit('item:click')
|
|
2575
|
+
], Selectic.prototype, "render", null);
|
|
2504
2576
|
Selectic = __decorate([
|
|
2505
2577
|
Component
|
|
2506
2578
|
], Selectic);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Breaking changes
|
|
2
|
+
|
|
3
|
+
[Back to documentation index](main.md)
|
|
4
|
+
|
|
5
|
+
This document is mainly for users which had projects with oldest Selectic
|
|
6
|
+
version which want to upgrade them to latest version.
|
|
7
|
+
|
|
8
|
+
**This is not something you have to read to understand and to use Selectic.**
|
|
9
|
+
|
|
10
|
+
## 1.3.x → 3.x
|
|
11
|
+
|
|
12
|
+
### Vue2 → Vue3
|
|
13
|
+
|
|
14
|
+
Selectic 3.x uses Vue3 instead of Vue2. The library should be changed and may
|
|
15
|
+
impact the whole project.
|
|
16
|
+
|
|
17
|
+
You should read [Vue3 migration strategy](https://v3.vuejs.org/guide/migration/introduction.html)
|
|
18
|
+
to see all implications.
|
|
19
|
+
|
|
20
|
+
### Events listener
|
|
21
|
+
|
|
22
|
+
The argument given when events are emitted have been changed.
|
|
23
|
+
|
|
24
|
+
For example to listen to a `change` event with Selectic 1.3.x you could write something like:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
<Selectic @change="(id, isExcluded, instance) => ..."></Selectic>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
With Selectic 3.x you should write:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
<Selectic @change="(id, information) => ..."></Selectic>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
where `information` contains all options related to the event.
|
|
37
|
+
```
|
|
38
|
+
{
|
|
39
|
+
instance: selecticInstance,
|
|
40
|
+
eventType: 'change';
|
|
41
|
+
automatic: false,
|
|
42
|
+
isExcluded: false,
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
An object rather than severals arguments is much better because it is much
|
|
46
|
+
more robust to further changes.
|
|
47
|
+
|
|
48
|
+
[Read more about the events in the dedicated section](events.md).
|
|
49
|
+
|
|
50
|
+
### `<option>` slots
|
|
51
|
+
|
|
52
|
+
It is currently no more possible to use `<option>` slots in Selectic.
|
|
53
|
+
|
|
54
|
+
We can hope that a solution will be found soon, but currently only the static
|
|
55
|
+
and dynamic mode are available.
|