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.
- package/README.md +2 -0
- package/dist/selectic.common.js +177 -90
- package/dist/selectic.esm.js +178 -91
- 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 +136 -57
- package/src/index.tsx +69 -11
- package/test/Store/Store_creation.spec.js +93 -0
- package/test/Store/clearCache.spec.js +20 -0
- package/test/Store/commit.spec.js +188 -1
- package/test/helper.js +3 -0
- package/types/Store.d.ts +13 -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,22 +187,33 @@ 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
|
}
|
|
192
194
|
const state = this.state;
|
|
193
195
|
return state.dynOptions.length === state.totalDynOptions;
|
|
194
196
|
});
|
|
197
|
+
this.listOptions = computed(() => {
|
|
198
|
+
return this.getListOptions();
|
|
199
|
+
});
|
|
200
|
+
this.elementOptions = computed(() => {
|
|
201
|
+
return this.getElementOptions();
|
|
202
|
+
});
|
|
195
203
|
/* }}} */
|
|
196
204
|
/* {{{ watch */
|
|
197
205
|
watch(() => [this.props.options, this.props.childOptions], () => {
|
|
198
206
|
this.data.cacheItem.clear();
|
|
207
|
+
this.setAutomaticClose();
|
|
199
208
|
this.commit('isOpen', false);
|
|
200
209
|
this.buildAllOptions(true);
|
|
201
210
|
this.buildSelectedOptions();
|
|
202
211
|
});
|
|
212
|
+
watch(() => [this.listOptions, this.elementOptions], () => {
|
|
213
|
+
/* TODO: transform allOptions as a computed properties and this
|
|
214
|
+
* watcher become useless */
|
|
215
|
+
this.buildAllOptions(true);
|
|
216
|
+
});
|
|
203
217
|
watch(() => this.props.value, () => {
|
|
204
218
|
var _a;
|
|
205
219
|
const value = (_a = this.props.value) !== null && _a !== void 0 ? _a : null;
|
|
@@ -212,9 +226,8 @@ class SelecticStore {
|
|
|
212
226
|
this.commit('disabled', this.props.disabled);
|
|
213
227
|
});
|
|
214
228
|
watch(() => this.state.filteredOptions, () => {
|
|
215
|
-
var _a;
|
|
216
229
|
let areAllSelected = false;
|
|
217
|
-
const hasAllItems = (
|
|
230
|
+
const hasAllItems = unref(this.hasAllItems);
|
|
218
231
|
if (hasAllItems) {
|
|
219
232
|
const selectionIsExcluded = +this.state.selectionIsExcluded;
|
|
220
233
|
/* eslint-disable-next-line no-bitwise */
|
|
@@ -234,6 +247,7 @@ class SelecticStore {
|
|
|
234
247
|
});
|
|
235
248
|
/* }}} */
|
|
236
249
|
this.closeSelectic = () => {
|
|
250
|
+
this.setAutomaticClose();
|
|
237
251
|
this.commit('isOpen', false);
|
|
238
252
|
};
|
|
239
253
|
const value = this.props.value;
|
|
@@ -247,9 +261,16 @@ class SelecticStore {
|
|
|
247
261
|
if (stateParam.hideFilter === 'auto') {
|
|
248
262
|
delete stateParam.hideFilter;
|
|
249
263
|
}
|
|
264
|
+
else if (stateParam.hideFilter === 'open') {
|
|
265
|
+
this.state.keepFilterOpen = true;
|
|
266
|
+
delete stateParam.hideFilter;
|
|
267
|
+
}
|
|
250
268
|
/* Update state */
|
|
251
|
-
assignObject(this.state, stateParam
|
|
252
|
-
|
|
269
|
+
assignObject(this.state, stateParam);
|
|
270
|
+
/* XXX: should be done in 2 lines, in order to set the multiple state
|
|
271
|
+
* and ensure convertValue run with correct state */
|
|
272
|
+
assignObject(this.state, {
|
|
273
|
+
internalValue: this.convertTypeValue(value),
|
|
253
274
|
selectionIsExcluded: props.selectionIsExcluded,
|
|
254
275
|
disabled: props.disabled,
|
|
255
276
|
});
|
|
@@ -319,11 +340,20 @@ class SelecticStore {
|
|
|
319
340
|
break;
|
|
320
341
|
case 'disabled':
|
|
321
342
|
if (value) {
|
|
343
|
+
this.setAutomaticClose();
|
|
322
344
|
this.commit('isOpen', false);
|
|
323
345
|
}
|
|
324
346
|
break;
|
|
325
347
|
}
|
|
326
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
|
+
}
|
|
327
357
|
getItem(id) {
|
|
328
358
|
let item;
|
|
329
359
|
if (this.hasItemInStore(id)) {
|
|
@@ -366,10 +396,9 @@ class SelecticStore {
|
|
|
366
396
|
return this.buildSelectedItems(ids);
|
|
367
397
|
}
|
|
368
398
|
selectItem(id, selected, keepOpen = false) {
|
|
369
|
-
var _a;
|
|
370
399
|
const state = this.state;
|
|
371
400
|
let hasChanged = false;
|
|
372
|
-
const isPartial = (
|
|
401
|
+
const isPartial = unref(this.isPartial);
|
|
373
402
|
/* Check that item is not disabled */
|
|
374
403
|
if (!isPartial) {
|
|
375
404
|
const item = state.allOptions.find((opt) => opt.id === id);
|
|
@@ -422,6 +451,10 @@ class SelecticStore {
|
|
|
422
451
|
else if (id === oldValue) {
|
|
423
452
|
return;
|
|
424
453
|
}
|
|
454
|
+
if (keepOpen) {
|
|
455
|
+
/* if keepOpen is true it means that it is an automatic change */
|
|
456
|
+
this.setAutomaticChange();
|
|
457
|
+
}
|
|
425
458
|
this.commit('internalValue', id);
|
|
426
459
|
hasChanged = true;
|
|
427
460
|
}
|
|
@@ -430,11 +463,10 @@ class SelecticStore {
|
|
|
430
463
|
}
|
|
431
464
|
}
|
|
432
465
|
toggleSelectAll() {
|
|
433
|
-
var _a;
|
|
434
466
|
if (!this.state.multiple) {
|
|
435
467
|
return;
|
|
436
468
|
}
|
|
437
|
-
const hasAllItems = (
|
|
469
|
+
const hasAllItems = unref(this.hasAllItems);
|
|
438
470
|
if (!hasAllItems) {
|
|
439
471
|
const labels = this.data.labels;
|
|
440
472
|
if (this.state.searchText) {
|
|
@@ -467,8 +499,7 @@ class SelecticStore {
|
|
|
467
499
|
this.state.status.errorMessage = '';
|
|
468
500
|
}
|
|
469
501
|
clearCache(forceReset = false) {
|
|
470
|
-
|
|
471
|
-
const isPartial = (_a = this.isPartial.value) !== null && _a !== void 0 ? _a : this.isPartial;
|
|
502
|
+
const isPartial = unref(this.isPartial);
|
|
472
503
|
const total = isPartial ? Infinity : 0;
|
|
473
504
|
this.data.cacheItem.clear();
|
|
474
505
|
this.state.allOptions = [];
|
|
@@ -513,39 +544,46 @@ class SelecticStore {
|
|
|
513
544
|
}
|
|
514
545
|
return this.state.filteredOptions.find(findId) ||
|
|
515
546
|
this.state.dynOptions.find(findId) ||
|
|
516
|
-
this.
|
|
517
|
-
this.
|
|
547
|
+
unref(this.listOptions).find(findId) ||
|
|
548
|
+
unref(this.elementOptions).find(findId);
|
|
518
549
|
}
|
|
519
|
-
|
|
550
|
+
convertTypeValue(oldValue) {
|
|
520
551
|
const state = this.state;
|
|
521
|
-
const internalValue = state.internalValue;
|
|
522
552
|
const isMultiple = state.multiple;
|
|
523
|
-
let newValue =
|
|
553
|
+
let newValue = oldValue;
|
|
524
554
|
if (isMultiple) {
|
|
525
|
-
if (!Array.isArray(
|
|
526
|
-
newValue =
|
|
555
|
+
if (!Array.isArray(oldValue)) {
|
|
556
|
+
newValue = oldValue === null ? [] : [oldValue];
|
|
527
557
|
}
|
|
528
558
|
}
|
|
529
559
|
else {
|
|
530
|
-
if (Array.isArray(
|
|
531
|
-
const value =
|
|
560
|
+
if (Array.isArray(oldValue)) {
|
|
561
|
+
const value = oldValue[0];
|
|
532
562
|
newValue = typeof value === 'undefined' ? null : value;
|
|
533
563
|
}
|
|
534
564
|
}
|
|
535
|
-
|
|
565
|
+
return newValue;
|
|
566
|
+
}
|
|
567
|
+
assertValueType() {
|
|
568
|
+
const state = this.state;
|
|
569
|
+
const internalValue = state.internalValue;
|
|
570
|
+
const newValue = this.convertTypeValue(internalValue);
|
|
571
|
+
if (newValue !== internalValue) {
|
|
572
|
+
this.setAutomaticChange();
|
|
573
|
+
state.internalValue = newValue;
|
|
574
|
+
}
|
|
536
575
|
}
|
|
537
576
|
assertCorrectValue(applyStrict = false) {
|
|
538
|
-
var _a, _b;
|
|
539
577
|
const state = this.state;
|
|
578
|
+
this.assertValueType();
|
|
540
579
|
const internalValue = state.internalValue;
|
|
541
580
|
const selectionIsExcluded = state.selectionIsExcluded;
|
|
542
581
|
const isMultiple = state.multiple;
|
|
543
582
|
const checkStrict = state.strictValue;
|
|
544
583
|
let newValue = internalValue;
|
|
545
|
-
const isPartial = (
|
|
546
|
-
this.assertValueType();
|
|
584
|
+
const isPartial = unref(this.isPartial);
|
|
547
585
|
if (isMultiple) {
|
|
548
|
-
const hasFetchedAllItems = (
|
|
586
|
+
const hasFetchedAllItems = unref(this.hasFetchedAllItems);
|
|
549
587
|
if (selectionIsExcluded && hasFetchedAllItems) {
|
|
550
588
|
newValue = state.allOptions.reduce((values, option) => {
|
|
551
589
|
const id = option.id;
|
|
@@ -573,7 +611,7 @@ class SelecticStore {
|
|
|
573
611
|
return;
|
|
574
612
|
}
|
|
575
613
|
}
|
|
576
|
-
else if (!this.hasItemInStore(newValue)) {
|
|
614
|
+
else if (newValue !== null && !this.hasItemInStore(newValue)) {
|
|
577
615
|
filteredValue = null;
|
|
578
616
|
isDifferent = true;
|
|
579
617
|
if (isPartial && !applyStrict) {
|
|
@@ -583,6 +621,7 @@ class SelecticStore {
|
|
|
583
621
|
}
|
|
584
622
|
}
|
|
585
623
|
if (isDifferent) {
|
|
624
|
+
this.setAutomaticChange();
|
|
586
625
|
newValue = filteredValue;
|
|
587
626
|
}
|
|
588
627
|
}
|
|
@@ -602,13 +641,14 @@ class SelecticStore {
|
|
|
602
641
|
this.state.groups.set(group.id, group.text);
|
|
603
642
|
});
|
|
604
643
|
}
|
|
605
|
-
/*
|
|
644
|
+
/* This method is for the computed property listOptions */
|
|
606
645
|
getListOptions() {
|
|
607
646
|
const options = this.props.options;
|
|
608
647
|
const listOptions = [];
|
|
609
648
|
if (!Array.isArray(options)) {
|
|
610
649
|
return listOptions;
|
|
611
650
|
}
|
|
651
|
+
const state = this.state;
|
|
612
652
|
options.forEach((option) => {
|
|
613
653
|
/* manage simple string */
|
|
614
654
|
if (typeof option === 'string') {
|
|
@@ -621,13 +661,13 @@ class SelecticStore {
|
|
|
621
661
|
const group = option.group;
|
|
622
662
|
const subOptions = option.options;
|
|
623
663
|
/* check for groups */
|
|
624
|
-
if (group && !
|
|
625
|
-
|
|
664
|
+
if (group && !state.groups.has(group)) {
|
|
665
|
+
state.groups.set(group, String(group));
|
|
626
666
|
}
|
|
627
667
|
/* check for sub options */
|
|
628
668
|
if (subOptions) {
|
|
629
669
|
const groupId = option.id;
|
|
630
|
-
|
|
670
|
+
state.groups.set(groupId, option.text);
|
|
631
671
|
subOptions.forEach((subOpt) => {
|
|
632
672
|
subOpt.group = groupId;
|
|
633
673
|
});
|
|
@@ -638,24 +678,25 @@ class SelecticStore {
|
|
|
638
678
|
});
|
|
639
679
|
return listOptions;
|
|
640
680
|
}
|
|
641
|
-
/*
|
|
681
|
+
/* This method is for the computed property elementOptions */
|
|
642
682
|
getElementOptions() {
|
|
643
683
|
const options = this.props.childOptions;
|
|
644
684
|
const childOptions = [];
|
|
645
685
|
if (!Array.isArray(options) || options.length === 0) {
|
|
646
686
|
return childOptions;
|
|
647
687
|
}
|
|
688
|
+
const state = this.state;
|
|
648
689
|
options.forEach((option) => {
|
|
649
690
|
const group = option.group;
|
|
650
691
|
const subOptions = option.options;
|
|
651
692
|
/* check for groups */
|
|
652
|
-
if (group && !
|
|
653
|
-
|
|
693
|
+
if (group && !state.groups.has(group)) {
|
|
694
|
+
state.groups.set(group, String(group));
|
|
654
695
|
}
|
|
655
696
|
/* check for sub options */
|
|
656
697
|
if (subOptions) {
|
|
657
698
|
const groupId = option.id;
|
|
658
|
-
|
|
699
|
+
state.groups.set(groupId, option.text);
|
|
659
700
|
const sOpts = subOptions.map((subOpt) => {
|
|
660
701
|
return Object.assign({}, subOpt, {
|
|
661
702
|
group: groupId,
|
|
@@ -669,13 +710,12 @@ class SelecticStore {
|
|
|
669
710
|
return childOptions;
|
|
670
711
|
}
|
|
671
712
|
buildAllOptions(keepFetched = false) {
|
|
672
|
-
var _a;
|
|
673
713
|
const allOptions = [];
|
|
674
714
|
let listOptions = [];
|
|
675
715
|
let elementOptions = [];
|
|
676
716
|
const optionBehaviorOrder = this.state.optionBehaviorOrder;
|
|
677
717
|
let length = Infinity;
|
|
678
|
-
const isPartial = (
|
|
718
|
+
const isPartial = unref(this.isPartial);
|
|
679
719
|
const arrayFromOrder = (orderValue) => {
|
|
680
720
|
switch (orderValue) {
|
|
681
721
|
case 'O': return listOptions;
|
|
@@ -701,8 +741,8 @@ class SelecticStore {
|
|
|
701
741
|
this.state.totalDynOptions = 0;
|
|
702
742
|
}
|
|
703
743
|
}
|
|
704
|
-
listOptions = this.
|
|
705
|
-
elementOptions = this.
|
|
744
|
+
listOptions = unref(this.listOptions);
|
|
745
|
+
elementOptions = unref(this.elementOptions);
|
|
706
746
|
if (this.state.optionBehaviorOperation === 'force') {
|
|
707
747
|
const orderValue = optionBehaviorOrder.find((value) => lengthFromOrder(value) > 0);
|
|
708
748
|
allOptions.push(...arrayFromOrder(orderValue));
|
|
@@ -748,7 +788,6 @@ class SelecticStore {
|
|
|
748
788
|
});
|
|
749
789
|
}
|
|
750
790
|
async buildFilteredOptions() {
|
|
751
|
-
var _a, _b, _c, _d;
|
|
752
791
|
if (!this.state.isOpen) {
|
|
753
792
|
/* Do not try to fetch anything while the select is not open */
|
|
754
793
|
return;
|
|
@@ -758,12 +797,12 @@ class SelecticStore {
|
|
|
758
797
|
const totalAllOptions = this.state.totalAllOptions;
|
|
759
798
|
const allOptionsLength = allOptions.length;
|
|
760
799
|
let filteredOptionsLength = this.state.filteredOptions.length;
|
|
761
|
-
const hasAllItems = (
|
|
800
|
+
const hasAllItems = unref(this.hasAllItems);
|
|
762
801
|
if (hasAllItems) {
|
|
763
802
|
/* Everything has already been fetched and stored in filteredOptions */
|
|
764
803
|
return;
|
|
765
804
|
}
|
|
766
|
-
const hasFetchedAllItems = (
|
|
805
|
+
const hasFetchedAllItems = unref(this.hasFetchedAllItems);
|
|
767
806
|
/* Check if all options have been fetched */
|
|
768
807
|
if (hasFetchedAllItems) {
|
|
769
808
|
if (!search) {
|
|
@@ -778,7 +817,7 @@ class SelecticStore {
|
|
|
778
817
|
}
|
|
779
818
|
/* When we only have partial options */
|
|
780
819
|
const offsetItem = this.state.offsetItem;
|
|
781
|
-
const marginSize = (
|
|
820
|
+
const marginSize = unref(this.marginSize);
|
|
782
821
|
const endIndex = offsetItem + marginSize;
|
|
783
822
|
if (endIndex <= filteredOptionsLength) {
|
|
784
823
|
return;
|
|
@@ -786,7 +825,7 @@ class SelecticStore {
|
|
|
786
825
|
if (!search && endIndex <= allOptionsLength) {
|
|
787
826
|
this.state.filteredOptions = this.buildGroupItems(allOptions);
|
|
788
827
|
this.state.totalFilteredOptions = totalAllOptions + this.state.groups.size;
|
|
789
|
-
const isPartial = (
|
|
828
|
+
const isPartial = unref(this.isPartial);
|
|
790
829
|
if (isPartial && this.state.totalDynOptions === Infinity) {
|
|
791
830
|
this.fetchData();
|
|
792
831
|
}
|
|
@@ -804,54 +843,56 @@ class SelecticStore {
|
|
|
804
843
|
}
|
|
805
844
|
async buildSelectedOptions() {
|
|
806
845
|
const internalValue = this.state.internalValue;
|
|
807
|
-
|
|
846
|
+
const state = this.state;
|
|
847
|
+
if (state.multiple) {
|
|
808
848
|
/* display partial information about selected items */
|
|
809
|
-
|
|
849
|
+
state.selectedOptions = this.buildSelectedItems(internalValue);
|
|
810
850
|
const items = await this.getItems(internalValue).catch(() => []);
|
|
811
|
-
if (internalValue !==
|
|
851
|
+
if (internalValue !== state.internalValue) {
|
|
812
852
|
/* Values have been deprecated */
|
|
813
853
|
return;
|
|
814
854
|
}
|
|
815
855
|
if (items.length !== internalValue.length) {
|
|
816
|
-
if (!
|
|
817
|
-
const updatedItems =
|
|
856
|
+
if (!state.strictValue) {
|
|
857
|
+
const updatedItems = state.selectedOptions.map((option) => {
|
|
818
858
|
const foundItem = items.find((item) => item.id === option.id);
|
|
819
859
|
return foundItem || option;
|
|
820
860
|
});
|
|
821
|
-
|
|
861
|
+
state.selectedOptions = updatedItems;
|
|
822
862
|
}
|
|
823
863
|
else {
|
|
824
864
|
const itemIds = items.map((item) => item.id);
|
|
865
|
+
this.setAutomaticChange();
|
|
825
866
|
this.commit('internalValue', itemIds);
|
|
826
867
|
}
|
|
827
868
|
return;
|
|
828
869
|
}
|
|
829
870
|
/* display full information about selected items */
|
|
830
|
-
|
|
871
|
+
state.selectedOptions = items;
|
|
831
872
|
}
|
|
832
873
|
else if (internalValue === null) {
|
|
833
|
-
|
|
874
|
+
state.selectedOptions = null;
|
|
834
875
|
}
|
|
835
876
|
else {
|
|
836
877
|
/* display partial information about selected items */
|
|
837
|
-
|
|
878
|
+
state.selectedOptions = this.buildSelectedItems([internalValue])[0];
|
|
838
879
|
const items = await this.getItems([internalValue]).catch(() => []);
|
|
839
|
-
if (internalValue !==
|
|
880
|
+
if (internalValue !== state.internalValue) {
|
|
840
881
|
/* Values have been deprecated */
|
|
841
882
|
return;
|
|
842
883
|
}
|
|
843
884
|
if (!items.length) {
|
|
844
|
-
if (
|
|
885
|
+
if (state.strictValue) {
|
|
886
|
+
this.setAutomaticChange();
|
|
845
887
|
this.commit('internalValue', null);
|
|
846
888
|
}
|
|
847
889
|
return;
|
|
848
890
|
}
|
|
849
891
|
/* display full information about selected items */
|
|
850
|
-
|
|
892
|
+
state.selectedOptions = items[0];
|
|
851
893
|
}
|
|
852
894
|
}
|
|
853
895
|
async fetchData() {
|
|
854
|
-
var _a;
|
|
855
896
|
const state = this.state;
|
|
856
897
|
const labels = this.data.labels;
|
|
857
898
|
const fetchCallback = this.props.fetchCallback;
|
|
@@ -863,7 +904,7 @@ class SelecticStore {
|
|
|
863
904
|
const filteredOptionsLength = state.filteredOptions.length;
|
|
864
905
|
const offsetItem = state.offsetItem;
|
|
865
906
|
const pageSize = state.pageSize;
|
|
866
|
-
const marginSize = (
|
|
907
|
+
const marginSize = unref(this.marginSize);
|
|
867
908
|
const endIndex = offsetItem + marginSize;
|
|
868
909
|
const dynOffset = this.data.dynOffset;
|
|
869
910
|
/* Run the query */
|
|
@@ -954,10 +995,10 @@ class SelecticStore {
|
|
|
954
995
|
}
|
|
955
996
|
switch (order) {
|
|
956
997
|
case 'O':
|
|
957
|
-
options = this.filterOptions(this.
|
|
998
|
+
options = this.filterOptions(unref(this.listOptions), search);
|
|
958
999
|
break;
|
|
959
1000
|
case 'E':
|
|
960
|
-
options = this.filterOptions(this.
|
|
1001
|
+
options = this.filterOptions(unref(this.elementOptions), search);
|
|
961
1002
|
break;
|
|
962
1003
|
}
|
|
963
1004
|
this.state.filteredOptions.push(...options);
|
|
@@ -1063,11 +1104,10 @@ class SelecticStore {
|
|
|
1063
1104
|
}
|
|
1064
1105
|
}
|
|
1065
1106
|
checkAutoDisabled() {
|
|
1066
|
-
var _a, _b;
|
|
1067
1107
|
const state = this.state;
|
|
1068
|
-
const isPartial = (
|
|
1108
|
+
const isPartial = unref(this.isPartial);
|
|
1069
1109
|
const doNotCheck = isPartial || this.props.disabled || !state.autoDisabled;
|
|
1070
|
-
const hasFetchedAllItems = (
|
|
1110
|
+
const hasFetchedAllItems = unref(this.hasFetchedAllItems);
|
|
1071
1111
|
if (doNotCheck || !hasFetchedAllItems) {
|
|
1072
1112
|
return;
|
|
1073
1113
|
}
|
|
@@ -1080,7 +1120,10 @@ class SelecticStore {
|
|
|
1080
1120
|
const isEmpty = nb === 0;
|
|
1081
1121
|
const hasOnlyOneOption = nb === 1 && hasValidValue && !state.allowClearSelection;
|
|
1082
1122
|
if (hasOnlyOneOption || isEmpty) {
|
|
1083
|
-
|
|
1123
|
+
if (state.isOpen) {
|
|
1124
|
+
this.setAutomaticClose();
|
|
1125
|
+
this.commit('isOpen', false);
|
|
1126
|
+
}
|
|
1084
1127
|
this.commit('disabled', true);
|
|
1085
1128
|
}
|
|
1086
1129
|
else {
|
|
@@ -1088,13 +1131,12 @@ class SelecticStore {
|
|
|
1088
1131
|
}
|
|
1089
1132
|
}
|
|
1090
1133
|
checkHideFilter() {
|
|
1091
|
-
var _a;
|
|
1092
1134
|
const params = this.props.params;
|
|
1093
1135
|
if (params && params.hideFilter !== 'auto') {
|
|
1094
1136
|
return;
|
|
1095
1137
|
}
|
|
1096
1138
|
const state = this.state;
|
|
1097
|
-
const isPartial = (
|
|
1139
|
+
const isPartial = unref(this.isPartial);
|
|
1098
1140
|
if (state.multiple || isPartial) {
|
|
1099
1141
|
state.hideFilter = false;
|
|
1100
1142
|
}
|
|
@@ -1384,12 +1426,12 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1384
1426
|
const state = store.state;
|
|
1385
1427
|
const isMultiple = state.multiple;
|
|
1386
1428
|
const hasItems = state.filteredOptions.length === 0;
|
|
1387
|
-
const canNotSelect = !!state.searchText && !store.hasAllItems
|
|
1429
|
+
const canNotSelect = !!state.searchText && !unref(store.hasAllItems);
|
|
1388
1430
|
return !isMultiple || hasItems || canNotSelect;
|
|
1389
1431
|
}
|
|
1390
1432
|
get disableRevert() {
|
|
1391
1433
|
const store = this.store;
|
|
1392
|
-
return !store.state.multiple || !store.hasFetchedAllItems
|
|
1434
|
+
return !store.state.multiple || !unref(store.hasFetchedAllItems);
|
|
1393
1435
|
}
|
|
1394
1436
|
get enableRevert() {
|
|
1395
1437
|
const state = this.store.state;
|
|
@@ -1427,6 +1469,10 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1427
1469
|
this.store.commit('selectionIsExcluded', !this.selectionIsExcluded);
|
|
1428
1470
|
}
|
|
1429
1471
|
togglePanel() {
|
|
1472
|
+
if (this.store.state.keepFilterOpen === true) {
|
|
1473
|
+
this.closed = false;
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1430
1476
|
this.closed = !this.closed;
|
|
1431
1477
|
}
|
|
1432
1478
|
getFocus() {
|
|
@@ -1443,7 +1489,8 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1443
1489
|
/* }}} */
|
|
1444
1490
|
/* {{{ Life cycle */
|
|
1445
1491
|
mounted() {
|
|
1446
|
-
|
|
1492
|
+
const state = this.store.state;
|
|
1493
|
+
this.closed = !state.keepFilterOpen && !state.searchText;
|
|
1447
1494
|
document.addEventListener('keypress', this.onKeyPressed);
|
|
1448
1495
|
this.getFocus();
|
|
1449
1496
|
}
|
|
@@ -1452,24 +1499,27 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1452
1499
|
}
|
|
1453
1500
|
/* }}} */
|
|
1454
1501
|
render() {
|
|
1502
|
+
const store = this.store;
|
|
1503
|
+
const state = store.state;
|
|
1504
|
+
const labels = store.data.labels;
|
|
1455
1505
|
return (h("div", { class: "filter-panel" },
|
|
1456
1506
|
h("div", { class: {
|
|
1457
1507
|
panelclosed: this.closed,
|
|
1458
1508
|
panelopened: !this.closed,
|
|
1459
1509
|
} },
|
|
1460
1510
|
h("div", { class: "filter-panel__input form-group has-feedback" },
|
|
1461
|
-
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: {
|
|
1462
1512
|
'input.stop.prevent': this.onInput,
|
|
1463
1513
|
}, ref: "filterInput" }),
|
|
1464
1514
|
h("span", { class: "fa fa-search selectic-search-scope\n form-control-feedback" })),
|
|
1465
|
-
|
|
1515
|
+
state.multiple && (h("div", { class: "toggle-selectic" },
|
|
1466
1516
|
h("label", { class: ['control-label', {
|
|
1467
1517
|
'selectic__label-disabled': this.disableSelectAll,
|
|
1468
1518
|
}] },
|
|
1469
|
-
h("input", { type: "checkbox", checked:
|
|
1519
|
+
h("input", { type: "checkbox", checked: state.status.areAllSelected, disabled: this.disableSelectAll, on: {
|
|
1470
1520
|
change: this.onSelectAll,
|
|
1471
1521
|
} }),
|
|
1472
|
-
|
|
1522
|
+
labels.selectAll))),
|
|
1473
1523
|
this.enableRevert && (h("div", { class: ['toggle-selectic', {
|
|
1474
1524
|
'selectic__label-disabled': this.disableRevert,
|
|
1475
1525
|
}] },
|
|
@@ -1477,8 +1527,8 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1477
1527
|
h("input", { type: "checkbox", checked: this.selectionIsExcluded, disabled: this.disableRevert, on: {
|
|
1478
1528
|
change: this.onExclude,
|
|
1479
1529
|
} }),
|
|
1480
|
-
|
|
1481
|
-
h("div", { class: "curtain-handler", on: {
|
|
1530
|
+
labels.excludeResult)))),
|
|
1531
|
+
!state.keepFilterOpen && (h("div", { class: "curtain-handler", on: {
|
|
1482
1532
|
'click.prevent.stop': this.togglePanel,
|
|
1483
1533
|
} },
|
|
1484
1534
|
h("span", { class: "fa fa-search" }),
|
|
@@ -1486,7 +1536,7 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1486
1536
|
'fa': true,
|
|
1487
1537
|
'fa-caret-down': this.closed,
|
|
1488
1538
|
'fa-caret-up': !this.closed,
|
|
1489
|
-
} }))));
|
|
1539
|
+
} })))));
|
|
1490
1540
|
}
|
|
1491
1541
|
};
|
|
1492
1542
|
__decorate$3([
|
|
@@ -1528,9 +1578,8 @@ let List = class List extends Vue {
|
|
|
1528
1578
|
return this.store.state.multiple;
|
|
1529
1579
|
}
|
|
1530
1580
|
get itemsMargin() {
|
|
1531
|
-
var _a;
|
|
1532
1581
|
/* XXX: I don't really know when we should use value or not... */
|
|
1533
|
-
return (
|
|
1582
|
+
return unref(this.store.marginSize);
|
|
1534
1583
|
}
|
|
1535
1584
|
get shortOptions() {
|
|
1536
1585
|
const endIndex = this.endIndex;
|
|
@@ -2120,7 +2169,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2120
2169
|
window.addEventListener('resize', this.windowResize, false);
|
|
2121
2170
|
document.addEventListener('click', this.outsideListener, true);
|
|
2122
2171
|
this.computeOffset();
|
|
2123
|
-
this
|
|
2172
|
+
this.emit('open');
|
|
2124
2173
|
}
|
|
2125
2174
|
else {
|
|
2126
2175
|
this.removeListeners();
|
|
@@ -2128,7 +2177,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2128
2177
|
this.$emit('change', this.getValue(), state.selectionIsExcluded, this);
|
|
2129
2178
|
this.store.resetChange();
|
|
2130
2179
|
}
|
|
2131
|
-
this
|
|
2180
|
+
this.emit('close');
|
|
2132
2181
|
}
|
|
2133
2182
|
}
|
|
2134
2183
|
compareValues(oldValue, newValue) {
|
|
@@ -2158,7 +2207,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2158
2207
|
this.store.props.selectionIsExcluded = this.selectionIsExcluded;
|
|
2159
2208
|
}
|
|
2160
2209
|
onOptionsChange() {
|
|
2161
|
-
this.store.props.options = this.options;
|
|
2210
|
+
this.store.props.options = Array.from(this.options);
|
|
2162
2211
|
}
|
|
2163
2212
|
onTextsChange() {
|
|
2164
2213
|
const texts = this.texts;
|
|
@@ -2191,9 +2240,9 @@ let Selectic = class Selectic extends Vue {
|
|
|
2191
2240
|
const canTrigger = (oldValue !== undefined || !this.hasGivenValue) && !areSimilar;
|
|
2192
2241
|
if (canTrigger) {
|
|
2193
2242
|
const selectionIsExcluded = this.store.state.selectionIsExcluded;
|
|
2194
|
-
this
|
|
2243
|
+
this.emit('input', value, selectionIsExcluded);
|
|
2195
2244
|
if (!this.isFocused) {
|
|
2196
|
-
this
|
|
2245
|
+
this.emit('change', value, selectionIsExcluded);
|
|
2197
2246
|
this.store.resetChange();
|
|
2198
2247
|
}
|
|
2199
2248
|
}
|
|
@@ -2216,12 +2265,42 @@ let Selectic = class Selectic extends Vue {
|
|
|
2216
2265
|
this.store.commit('isOpen', false);
|
|
2217
2266
|
}, 0);
|
|
2218
2267
|
}
|
|
2219
|
-
|
|
2268
|
+
_emit(event, ...args) {
|
|
2220
2269
|
this.$emit(event, ...args);
|
|
2221
2270
|
if (typeof this._on === 'function') {
|
|
2222
2271
|
this._on(event, ...args);
|
|
2223
2272
|
}
|
|
2224
2273
|
}
|
|
2274
|
+
emit(event, value, isExcluded) {
|
|
2275
|
+
const automatic = this.store.state.status.automaticChange;
|
|
2276
|
+
const options = {
|
|
2277
|
+
instance: this,
|
|
2278
|
+
eventType: event,
|
|
2279
|
+
automatic,
|
|
2280
|
+
};
|
|
2281
|
+
switch (event) {
|
|
2282
|
+
case 'input':
|
|
2283
|
+
case 'change':
|
|
2284
|
+
const changeOptions = Object.assign({
|
|
2285
|
+
isExcluded: isExcluded,
|
|
2286
|
+
}, options);
|
|
2287
|
+
this._emit(event, value, changeOptions);
|
|
2288
|
+
break;
|
|
2289
|
+
case 'open':
|
|
2290
|
+
case 'focus':
|
|
2291
|
+
this._emit('open', options);
|
|
2292
|
+
this._emit('focus', options);
|
|
2293
|
+
break;
|
|
2294
|
+
case 'close':
|
|
2295
|
+
case 'blur':
|
|
2296
|
+
this._emit('close', options);
|
|
2297
|
+
this._emit('blur', options);
|
|
2298
|
+
break;
|
|
2299
|
+
case 'item:click':
|
|
2300
|
+
this._emit(event, value, options);
|
|
2301
|
+
break;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2225
2304
|
// private extractFromNode(node: Vue.VNode, text = ''): OptionValue {
|
|
2226
2305
|
// function styleToString(staticStyle?: {[key: string]: string}): string | undefined {
|
|
2227
2306
|
// if (!staticStyle) {
|
|
@@ -2300,7 +2379,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2300
2379
|
/* }}} */
|
|
2301
2380
|
/* {{{ Life cycle */
|
|
2302
2381
|
created() {
|
|
2303
|
-
var _a, _b;
|
|
2382
|
+
var _a, _b, _c;
|
|
2304
2383
|
this._elementsListeners = [];
|
|
2305
2384
|
this.store = new SelecticStore({
|
|
2306
2385
|
options: this.options,
|
|
@@ -2313,8 +2392,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2313
2392
|
params: {
|
|
2314
2393
|
multiple: ((_a = this.multiple) !== null && _a !== void 0 ? _a : false) !== false,
|
|
2315
2394
|
pageSize: this.params.pageSize || 100,
|
|
2316
|
-
hideFilter: this.params.hideFilter !==
|
|
2317
|
-
? this.params.hideFilter : 'auto',
|
|
2395
|
+
hideFilter: (_b = this.params.hideFilter) !== null && _b !== void 0 ? _b : 'auto',
|
|
2318
2396
|
allowRevert: this.params.allowRevert,
|
|
2319
2397
|
allowClearSelection: this.params.allowClearSelection || false,
|
|
2320
2398
|
autoSelect: this.params.autoSelect === undefined
|
|
@@ -2329,7 +2407,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2329
2407
|
formatSelection: this.params.formatSelection,
|
|
2330
2408
|
listPosition: this.params.listPosition || 'auto',
|
|
2331
2409
|
optionBehavior: this.params.optionBehavior,
|
|
2332
|
-
isOpen: ((
|
|
2410
|
+
isOpen: ((_c = this.open) !== null && _c !== void 0 ? _c : false) !== false,
|
|
2333
2411
|
},
|
|
2334
2412
|
fetchCallback: this.params.fetchCallback,
|
|
2335
2413
|
getItemsCallback: this.params.getItemsCallback,
|
|
@@ -2388,7 +2466,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2388
2466
|
blur: this.checkFocus,
|
|
2389
2467
|
} }),
|
|
2390
2468
|
h(MainInput$1, { store: store, id: id, on: {
|
|
2391
|
-
'item:click': (id) => this.emit('item:click', id
|
|
2469
|
+
'item:click': (id) => this.emit('item:click', id),
|
|
2392
2470
|
}, ref: "mainInput" }),
|
|
2393
2471
|
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" }))));
|
|
2394
2472
|
}
|
|
@@ -2475,6 +2553,15 @@ __decorate([
|
|
|
2475
2553
|
__decorate([
|
|
2476
2554
|
Watch('store.state.internalValue')
|
|
2477
2555
|
], Selectic.prototype, "onInternalValueChange", null);
|
|
2556
|
+
__decorate([
|
|
2557
|
+
Emit('input'),
|
|
2558
|
+
Emit('change'),
|
|
2559
|
+
Emit('open'),
|
|
2560
|
+
Emit('focus'),
|
|
2561
|
+
Emit('close'),
|
|
2562
|
+
Emit('blur'),
|
|
2563
|
+
Emit('item:click')
|
|
2564
|
+
], Selectic.prototype, "render", null);
|
|
2478
2565
|
Selectic = __decorate([
|
|
2479
2566
|
Component
|
|
2480
2567
|
], Selectic);
|