selectic 3.0.21 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/selectic.common.js +545 -67
  2. package/dist/selectic.esm.js +546 -69
  3. package/doc/changeIcons.md +118 -0
  4. package/doc/changeText.md +1 -1
  5. package/doc/domProperties.md +57 -19
  6. package/doc/extendedProperties.md +83 -72
  7. package/doc/main.md +2 -0
  8. package/doc/params.md +177 -112
  9. package/doc/properties.md +42 -0
  10. package/package.json +4 -4
  11. package/src/ExtendedList.tsx +53 -6
  12. package/src/Filter.tsx +11 -9
  13. package/src/Icon.tsx +199 -0
  14. package/src/List.tsx +12 -6
  15. package/src/MainInput.tsx +15 -11
  16. package/src/Store.tsx +290 -123
  17. package/src/css/selectic.css +24 -0
  18. package/src/icons/caret-down.tsx +21 -0
  19. package/src/icons/caret-up.tsx +21 -0
  20. package/src/icons/check.tsx +23 -0
  21. package/src/icons/question.tsx +21 -0
  22. package/src/icons/search.tsx +21 -0
  23. package/src/icons/spinner.tsx +21 -0
  24. package/src/icons/strikeThrough.tsx +21 -0
  25. package/src/icons/times.tsx +21 -0
  26. package/src/index.tsx +78 -37
  27. package/test/Store/Store_computed.spec.js +84 -0
  28. package/test/Store/changeIcons.spec.js +154 -0
  29. package/test/Store/selectGroup.spec.js +389 -0
  30. package/test/Store/selectItem.spec.js +100 -46
  31. package/test/helper.js +38 -34
  32. package/types/ExtendedList.d.ts +7 -2
  33. package/types/Icon.d.ts +25 -0
  34. package/types/Store.d.ts +142 -5
  35. package/types/icons/caret-down.d.ts +6 -0
  36. package/types/icons/caret-up.d.ts +6 -0
  37. package/types/icons/check.d.ts +6 -0
  38. package/types/icons/question.d.ts +6 -0
  39. package/types/icons/search.d.ts +6 -0
  40. package/types/icons/spinner.d.ts +6 -0
  41. package/types/icons/strikeThrough.d.ts +6 -0
  42. package/types/icons/times.d.ts +6 -0
  43. package/types/index.d.ts +74 -1
@@ -0,0 +1,154 @@
1
+ const tape = require('tape');
2
+ const _ = require('../tools.js');
3
+ const StoreFile = require('../dist/Store.js');
4
+ const Store = StoreFile.default;
5
+
6
+ tape.only('changeIcons()', (sTest) => {
7
+ sTest.test('should have default icons', (t) => {
8
+ const store = new Store();
9
+
10
+ t.is(typeof store.data.icons, 'object');
11
+ t.is(store.data.iconFamily, 'selectic');
12
+
13
+ /* is empty by default */
14
+ t.deepEqual(store.data.icons, {});
15
+
16
+ t.end();
17
+ });
18
+
19
+ sTest.test('should change icons for an instance', (t) => {
20
+ const store = new Store({
21
+ icons: {
22
+ spin: 'pulse',
23
+ check: 'thumbs-up',
24
+ },
25
+ });
26
+ const storeRef = new Store();
27
+
28
+ /* Test some values */
29
+ t.is(store.data.icons.spin, 'pulse');
30
+ t.is(store.data.icons.check, 'thumbs-up');
31
+
32
+ /* Assert it has not change other instances */
33
+ t.is(storeRef.data.icons.spin, undefined);
34
+ t.is(storeRef.data.icons.check, undefined);
35
+ t.end();
36
+ });
37
+
38
+ sTest.test('should change icon family for an instance', (t) => {
39
+ const store = new Store({
40
+ iconFamily: 'font-awesome-4',
41
+ });
42
+ const storeRef = new Store();
43
+
44
+ /* Test icon family value */
45
+ t.is(store.data.iconFamily, 'font-awesome-4');
46
+
47
+ /* Assert it has not change other instances */
48
+ t.is(storeRef.data.iconFamily, 'selectic');
49
+ t.end();
50
+ });
51
+
52
+ sTest.test('should change dynamically texts for an instance', (t) => {
53
+ const store = new Store();
54
+ const storeExistingRef = new Store();
55
+
56
+ store.changeIcons({
57
+ times: 'trash',
58
+ search: 'magnify',
59
+ });
60
+
61
+ /* Test some values */
62
+ t.is(store.data.icons.times, 'trash');
63
+ t.is(store.data.icons.search, 'magnify');
64
+ t.is(store.data.icons.spin, undefined);
65
+ t.is(store.data.iconFamily, 'selectic');
66
+
67
+ /* Assert it has not change other instances */
68
+ t.is(storeExistingRef.data.icons.times, undefined);
69
+ t.is(storeExistingRef.data.icons.search, undefined);
70
+ t.is(storeExistingRef.data.icons.spin, undefined);
71
+ t.is(storeExistingRef.data.iconFamily, 'selectic');
72
+
73
+ const storeNewRef = new Store();
74
+ /* Assert it has not change newly created instances */
75
+ t.is(storeNewRef.data.icons.times, undefined);
76
+ t.is(storeNewRef.data.icons.search, undefined);
77
+ t.is(storeNewRef.data.icons.spin, undefined);
78
+ t.is(storeNewRef.data.iconFamily, 'selectic');
79
+
80
+ // assert it keeps previous value and update them
81
+ store.changeIcons({
82
+ search: 'search',
83
+ spin: 'rotate',
84
+ });
85
+
86
+ t.is(store.data.icons.times, 'trash');
87
+ t.is(store.data.icons.search, 'search');
88
+ t.is(store.data.icons.spin, 'rotate');
89
+ t.is(store.data.iconFamily, 'selectic');
90
+
91
+ /* Assert it has not change other instances */
92
+ t.is(storeExistingRef.data.icons.times, undefined);
93
+ t.is(storeExistingRef.data.icons.search, undefined);
94
+ t.is(storeExistingRef.data.icons.spin, undefined);
95
+ t.is(storeExistingRef.data.iconFamily, 'selectic');
96
+
97
+ // assert it could change icon family
98
+ store.changeIcons(null, 'font-awesome-5');
99
+
100
+ t.is(store.data.icons.times, 'trash');
101
+ t.is(store.data.icons.search, 'search');
102
+ t.is(store.data.icons.spin, 'rotate');
103
+ t.is(store.data.iconFamily, 'font-awesome-5');
104
+
105
+ /* Assert it has not change other instances */
106
+ t.is(storeExistingRef.data.icons.times, undefined);
107
+ t.is(storeExistingRef.data.icons.search, undefined);
108
+ t.is(storeExistingRef.data.icons.spin, undefined);
109
+ t.is(storeExistingRef.data.iconFamily, 'selectic');
110
+
111
+ // assert it could change both icons and icon family
112
+ store.changeIcons({
113
+ times: 'question',
114
+ spin: 'pulse',
115
+ }, 'prefix:my-icon myIc-');
116
+
117
+ t.is(store.data.icons.times, 'question');
118
+ t.is(store.data.icons.search, 'search');
119
+ t.is(store.data.icons.spin, 'pulse');
120
+ t.is(store.data.iconFamily, 'prefix:my-icon myIc-');
121
+
122
+ /* Assert it has not change other instances */
123
+ t.is(storeExistingRef.data.icons.times, undefined);
124
+ t.is(storeExistingRef.data.icons.search, undefined);
125
+ t.is(storeExistingRef.data.icons.spin, undefined);
126
+ t.is(storeExistingRef.data.iconFamily, 'selectic');
127
+
128
+ t.end();
129
+ });
130
+
131
+ sTest.test('should change texts for all new instances', (t) => {
132
+ const oldStore = new Store();
133
+
134
+ StoreFile.changeIcons({
135
+ 'caret-down': 'arrow-down',
136
+ }, 'font-awesome-4');
137
+
138
+ const store = new Store();
139
+
140
+ /* Test some values */
141
+ t.is(store.data.icons['caret-down'], 'arrow-down');
142
+ t.is(store.data.iconFamily, 'font-awesome-4');
143
+
144
+ /* Existing instance keeps its values */
145
+ t.is(oldStore.data.icons['caret-down'], undefined);
146
+ t.is(oldStore.data.iconFamily, 'selectic');
147
+
148
+ /* restore default values */
149
+ StoreFile.changeIcons({
150
+ 'caret-down': 'caret-down',
151
+ }, 'selectic');
152
+ t.end();
153
+ });
154
+ });
@@ -0,0 +1,389 @@
1
+ const _ = require('../tools.js');
2
+ const {
3
+ buildFetchCb,
4
+ getOptions,
5
+ resetCall,
6
+ } = require('../helper.js');
7
+ const tape = require('tape');
8
+ const StoreFile = require('../dist/Store.js');
9
+ const Store = StoreFile.default;
10
+
11
+ tape.test('selectGroup()', (st) => {
12
+ function getStaticOptions() {
13
+ const group1 = getOptions(10, 'gp1-', 0, 'group1');
14
+ const group2 = getOptions(20, 'gp2-', 10, 'group2');
15
+ const group3 = getOptions(10, 'gp3-', 30, 'group3');
16
+
17
+ group3[0].disabled = true;
18
+ group3[5].disabled = true;
19
+ group3[6].exclusive = true;
20
+ group3[9].exclusive = true;
21
+
22
+ return group1.concat(group2, group3);
23
+ }
24
+ const group1Ids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
25
+ const group2FilteredIds = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21];
26
+ const group2Ids = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29];
27
+ const group3Ids = [31, 32, 33, 34, 37, 38];
28
+
29
+ st.test('when "multiple" is false', (section) => {
30
+ section.test('with static mode', (sTest) => {
31
+ function getStore() {
32
+ const options = getStaticOptions();
33
+ const store = new Store({
34
+ options: options,
35
+ params: {
36
+ multiple: false,
37
+ autoSelect: false,
38
+ strictValue: true,
39
+ },
40
+ });
41
+
42
+ return store;
43
+ }
44
+
45
+ sTest.test('should not change selection', async (t) => {
46
+ const store = getStore();
47
+ await _.nextVueTick(store);
48
+ store.commit('isOpen', true);
49
+ await _.sleep(0);
50
+
51
+ t.is(store.state.internalValue, null, 'initialization');
52
+
53
+ store.selectGroup('group1', true);
54
+
55
+ t.is(store.state.internalValue, null);
56
+ t.is(store.state.status.hasChanged, false);
57
+
58
+ /* Check if it also not changed value when there is one */
59
+
60
+ store.selectItem(5, true);
61
+ /* reset status to check that it is modified */
62
+ store.state.status.hasChanged = false;
63
+
64
+ store.selectGroup('group2', true);
65
+
66
+ t.is(store.state.internalValue, 5);
67
+ t.is(store.state.status.hasChanged, false);
68
+
69
+ t.end();
70
+ });
71
+ });
72
+
73
+ section.test('with dynamic mode', (sTest) => {
74
+ sTest.test('should not select any value', async (t) => {
75
+ const command = {};
76
+ const spy = {};
77
+
78
+ const store = new Store({
79
+ fetchCallback: buildFetchCb({
80
+ total: 300,
81
+ group: [{
82
+ name: 'g1',
83
+ offset: 0,
84
+ }, {
85
+ name: 'g2',
86
+ offset: 20,
87
+ }, {
88
+ name: 'g3',
89
+ offset: 250,
90
+ }],
91
+ command,
92
+ spy,
93
+ }),
94
+ groups: [{
95
+ id: 'g1',
96
+ name: 'Group 1',
97
+ }, {
98
+ id: 'g2',
99
+ name: 'Group 2',
100
+ }, {
101
+ id: 'g3',
102
+ name: 'Group 3',
103
+ }],
104
+ });
105
+ await _.nextVueTick(store);
106
+ store.commit('isOpen', true);
107
+ command.fetch();
108
+ resetCall(spy);
109
+
110
+ await _.nextVueTick(store, command.promise);
111
+
112
+ t.is(store.state.internalValue, null, 'initialization');
113
+ t.is(store.state.filteredOptions[0].id, 'g1', 'initialization checks group is visible');
114
+
115
+ store.selectGroup('g1', true);
116
+
117
+ /* Currently selection is blocked for dynamic mode */
118
+
119
+ t.is(store.state.internalValue, null);
120
+ t.is(store.state.status.hasChanged, false);
121
+
122
+ t.end();
123
+ });
124
+ });
125
+ });
126
+
127
+ st.test('when "multiple" is true', (section) => {
128
+ section.test('with static mode', (sTest) => {
129
+ function getStore() {
130
+ const options = getStaticOptions();
131
+ const store = new Store({
132
+ options: options,
133
+ params: {
134
+ multiple: true,
135
+ strictValue: true,
136
+ },
137
+ });
138
+
139
+ return store;
140
+ }
141
+
142
+ sTest.test('should select several value', async (t) => {
143
+ const store = getStore();
144
+ await _.nextVueTick(store);
145
+ store.commit('isOpen', true);
146
+ await _.sleep(0);
147
+
148
+ t.deepEqual(store.state.internalValue, [], 'initialization');
149
+
150
+ store.selectGroup('group1', true);
151
+
152
+ t.deepEqual(store.state.internalValue, group1Ids);
153
+ t.is(store.state.status.hasChanged, true);
154
+
155
+ /* it should add selection to the current selection */
156
+
157
+ /* reset status to check that it is modified */
158
+ store.state.status.hasChanged = false;
159
+
160
+ store.selectGroup('group2', true);
161
+
162
+ t.deepEqual(store.state.internalValue, group1Ids.concat(group2Ids));
163
+ t.is(store.state.status.hasChanged, true);
164
+
165
+ t.end();
166
+ });
167
+
168
+ sTest.test('should not duplicate already selected values', async (t) => {
169
+ const store = getStore();
170
+ await _.nextVueTick(store);
171
+ store.commit('isOpen', true);
172
+ await _.sleep(0);
173
+
174
+ store.selectItem(1, true);
175
+ store.selectItem(6, true);
176
+ store.selectItem(11, true);
177
+ t.deepEqual(store.state.internalValue, [1, 6, 11], 'initialization');
178
+
179
+ store.selectGroup('group1', true);
180
+
181
+ t.deepEqual(store.state.internalValue, [1, 6, 11, 0, 2, 3, 4, 5, 7, 8, 9]);
182
+ t.is(store.state.status.hasChanged, true);
183
+
184
+ /* reset status to check that it is modified */
185
+ store.state.status.hasChanged = false;
186
+
187
+ store.selectGroup('group1', true);
188
+
189
+ t.deepEqual(store.state.internalValue, [1, 6, 11, 0, 2, 3, 4, 5, 7, 8, 9]);
190
+ t.is(store.state.status.hasChanged, false,
191
+ 'should not considered as changed if no new elements are added');
192
+
193
+ t.end();
194
+ });
195
+
196
+ sTest.test('should not select disabled and exclusive values', async (t) => {
197
+ const store = getStore();
198
+ await _.nextVueTick(store);
199
+ store.commit('isOpen', true);
200
+ await _.sleep(0);
201
+
202
+ t.deepEqual(store.state.internalValue, [], 'initialization');
203
+
204
+ store.selectGroup('group3', true);
205
+
206
+ t.deepEqual(store.state.internalValue, group3Ids, 'should not contains disabled and exclusive items');
207
+ t.is(store.state.status.hasChanged, true);
208
+
209
+ t.end();
210
+ });
211
+
212
+ sTest.test('should unselect values', async (t) => {
213
+ const store = getStore();
214
+ await _.nextVueTick(store);
215
+ store.commit('isOpen', true);
216
+ await _.sleep(0);
217
+ store.selectItem(1, true);
218
+ store.selectItem(6, true);
219
+ store.selectItem(11, true);
220
+ store.selectGroup('group2', true);
221
+ store.selectItem(31, true);
222
+
223
+ t.deepEqual(store.state.internalValue, [1, 6, 11, 10, ...group2Ids.slice(2), 31], 'initialization');
224
+
225
+ store.selectGroup('group2', false);
226
+
227
+ t.deepEqual(store.state.internalValue, [1, 6, 31]);
228
+ t.is(store.state.status.hasChanged, true);
229
+
230
+ /* Remove already not selected group */
231
+ /* reset status to check that it is modified */
232
+ store.state.status.hasChanged = false;
233
+
234
+ store.selectGroup('group2', false);
235
+
236
+ t.deepEqual(store.state.internalValue, [1, 6, 31], 'should not changed');
237
+ t.is(store.state.status.hasChanged, false,
238
+ 'should not considered as changed if no new elements are removed');
239
+
240
+ /* should remove partial selection */
241
+
242
+ store.selectGroup('group1', false);
243
+
244
+ t.deepEqual(store.state.internalValue, [31]);
245
+ t.is(store.state.status.hasChanged, true);
246
+
247
+ t.end();
248
+ });
249
+
250
+ sTest.test('should apply only on filtered elements', async (t) => {
251
+ const store = getStore();
252
+ await _.nextVueTick(store);
253
+ store.commit('isOpen', true);
254
+ store.commit('searchText', '1');
255
+ store.selectItem(37, true);
256
+ await _.sleep(0);
257
+
258
+ t.deepEqual(store.state.internalValue, [37], 'initialization');
259
+
260
+ store.selectGroup('group2', true);
261
+
262
+ t.deepEqual(store.state.internalValue, [37, ...group2FilteredIds]);
263
+ t.is(store.state.status.hasChanged, true);
264
+
265
+ /* it should remove selection */
266
+
267
+ /* reset status to check that it is modified */
268
+ store.state.status.hasChanged = false;
269
+
270
+ store.selectGroup('group2', false);
271
+
272
+ t.deepEqual(store.state.internalValue, [37]);
273
+ t.is(store.state.status.hasChanged, true);
274
+
275
+ /* it should remove only filtered selection */
276
+
277
+ store.selectItem(31, true);
278
+
279
+ /* reset status to check that it is modified */
280
+ store.state.status.hasChanged = false;
281
+
282
+ store.selectGroup('group3', false);
283
+
284
+ t.deepEqual(store.state.internalValue, [37]);
285
+ t.is(store.state.status.hasChanged, true);
286
+
287
+ t.end();
288
+ });
289
+
290
+ sTest.test('should have set items as selected', async (t) => {
291
+ const store = getStore();
292
+ await _.nextVueTick(store);
293
+ store.commit('isOpen', true);
294
+ await _.sleep(0);
295
+
296
+ store.selectGroup('group1', true);
297
+ t.is(store.state.filteredOptions[0].selected, true, 'should select the group');
298
+ t.is(store.state.filteredOptions[1].selected, true); // id: 0
299
+ t.is(store.state.filteredOptions[2].selected, true);
300
+ t.is(store.state.filteredOptions[3].selected, true);
301
+ t.is(store.state.filteredOptions[4].selected, true);
302
+ t.is(store.state.filteredOptions[5].selected, true);
303
+ t.is(store.state.filteredOptions[6].selected, true);
304
+ t.is(store.state.filteredOptions[7].selected, true);
305
+ t.is(store.state.filteredOptions[8].selected, true);
306
+ t.is(store.state.filteredOptions[9].selected, true);
307
+ t.is(store.state.filteredOptions[10].selected, true);
308
+ t.is(store.state.filteredOptions[11].selected, false);
309
+
310
+ store.selectItem(5, false);
311
+ t.is(store.state.filteredOptions[0].selected, false, 'should unselect the group');
312
+ t.is(store.state.filteredOptions[6].selected, false); // id: 5
313
+
314
+ t.end();
315
+ });
316
+
317
+ sTest.test('should not close list', async (t) => {
318
+ const store = getStore();
319
+ await _.nextVueTick(store);
320
+ store.commit('isOpen', true);
321
+ await _.sleep(0);
322
+
323
+ store.selectGroup('group1', true);
324
+ t.is(store.state.isOpen, true);
325
+
326
+ store.selectItem('group1', false);
327
+ t.is(store.state.isOpen, true);
328
+
329
+ t.end();
330
+ });
331
+ });
332
+
333
+ section.test('with dynamic mode', (sTest) => {
334
+ sTest.test('should not select any value', async (t) => {
335
+ const command = {};
336
+ const spy = {};
337
+
338
+ const store = new Store({
339
+ params: {
340
+ multiple: true,
341
+ },
342
+ fetchCallback: buildFetchCb({
343
+ total: 300,
344
+ group: [{
345
+ name: 'g1',
346
+ offset: 0,
347
+ }, {
348
+ name: 'g2',
349
+ offset: 20,
350
+ }, {
351
+ name: 'g3',
352
+ offset: 250,
353
+ }],
354
+ command,
355
+ spy,
356
+ }),
357
+ groups: [{
358
+ id: 'g1',
359
+ name: 'Group 1',
360
+ }, {
361
+ id: 'g2',
362
+ name: 'Group 2',
363
+ }, {
364
+ id: 'g3',
365
+ name: 'Group 3',
366
+ }],
367
+ });
368
+ await _.nextVueTick(store);
369
+ store.commit('isOpen', true);
370
+ command.fetch();
371
+ resetCall(spy);
372
+
373
+ await _.nextVueTick(store, command.promise);
374
+
375
+ t.deepEqual(store.state.internalValue, [], 'initialization');
376
+ t.is(store.state.filteredOptions[0].id, 'g1', 'initialization checks group is visible');
377
+
378
+ store.selectGroup('g1', true);
379
+
380
+ /* Currently selection is blocked for dynamic mode */
381
+
382
+ t.deepEqual(store.state.internalValue, []);
383
+ t.is(store.state.status.hasChanged, false);
384
+
385
+ t.end();
386
+ });
387
+ });
388
+ });
389
+ });