selectic 3.1.0 → 3.1.2

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.
@@ -1,5 +1,6 @@
1
1
  const _ = require('../tools.js');
2
2
  const {
3
+ DEBOUNCE_REQUEST,
3
4
  getOptions,
4
5
  sleep,
5
6
  buildFetchCb,
@@ -173,7 +174,7 @@ tape.test('toggleSelectAll()', (st) => {
173
174
  store.commit('isOpen', true);
174
175
 
175
176
  command.fetch();
176
- await _.deferPromise(command.promise);
177
+ await _.nextVueTick(store, command.promise, sleep(0) /* await request resolution */);
177
178
 
178
179
  t.deepEqual([store.state.totalFilteredOptions, store.state.filteredOptions.length], [20, 10]);
179
180
  store.toggleSelectAll();
@@ -255,10 +256,14 @@ tape.test('toggleSelectAll()', (st) => {
255
256
  fetchCallback: buildFetchCb({total: 20, searchTotal: 20, command, spy}),
256
257
  });
257
258
  await sleep(0);
259
+
258
260
  store.commit('isOpen', true);
259
261
  store.commit('searchText', '1');
260
262
 
263
+ await sleep(DEBOUNCE_REQUEST); // await request is sent
264
+
261
265
  command.fetch();
266
+
262
267
  await _.deferPromise(command.promise);
263
268
 
264
269
  t.deepEqual([store.state.totalFilteredOptions, store.state.filteredOptions.length], [20, 10]);
package/test/helper.js CHANGED
@@ -233,6 +233,9 @@ function resetCall(spy, keepValue = false) {
233
233
  }
234
234
  }
235
235
 
236
+ /* parameter sets in store */
237
+ const DEBOUNCE_REQUEST = 250;
238
+
236
239
  module.exports = {
237
240
  sleep,
238
241
  getInitialState,
@@ -243,4 +246,5 @@ module.exports = {
243
246
  toHaveBeenCalled,
244
247
  toHaveBeenCalledWith,
245
248
  resetCall,
249
+ DEBOUNCE_REQUEST,
246
250
  };
package/test/tools.js CHANGED
@@ -56,11 +56,15 @@ async function deferPromise(promise, waitAtStart = false) {
56
56
  return result;
57
57
  }
58
58
 
59
- function nextVueTick(_vueComponent, afterPromise) {
59
+ function nextVueTick(_vueComponent, afterPromise, after2ndPromise) {
60
60
  const promise = new Promise(async (resolve) => {
61
61
  if (afterPromise) {
62
62
  await afterPromise;
63
63
  }
64
+ if (after2ndPromise) {
65
+ await after2ndPromise;
66
+ }
67
+
64
68
  // next tick is now deprecated
65
69
  await sleep(0);
66
70
  resolve();
@@ -2,11 +2,11 @@ import { Vue, h } from 'vtyx';
2
2
  import Store, { OptionItem } from './Store';
3
3
  export interface Props {
4
4
  store: Store;
5
- width: number;
6
- elementTop: number;
7
- elementBottom: number;
8
- elementLeft: number;
9
- elementRight: number;
5
+ width?: number;
6
+ elementTop?: number;
7
+ elementBottom?: number;
8
+ elementLeft?: number;
9
+ elementRight?: number;
10
10
  }
11
11
  export default class ExtendedList extends Vue<Props> {
12
12
  private store;
package/types/List.d.ts CHANGED
@@ -2,9 +2,6 @@ import { Vue, h } from 'vtyx';
2
2
  import Store, { OptionItem } from './Store';
3
3
  export interface Props {
4
4
  store: Store;
5
- options?: any[];
6
- nbItems?: number;
7
- multiple?: boolean;
8
5
  }
9
6
  export default class List extends Vue<Props> {
10
7
  $refs: {
package/types/Store.d.ts CHANGED
@@ -30,10 +30,15 @@ export interface GroupValue {
30
30
  id: StrictOptionId;
31
31
  text: string;
32
32
  }
33
- export declare type FetchCallback = (_search: string, _offsetItem: number, _pageSize: number) => Promise<{
33
+ export declare type RequestResult = {
34
+ /** The total number of expecting options.
35
+ * Needed to know if there are more items to fetch, and to size the scrollbar.
36
+ */
34
37
  total: number;
38
+ /** The list of the options. */
35
39
  result: OptionValue[];
36
- }>;
40
+ };
41
+ export declare type FetchCallback = (_search: string, _offsetItem: number, _pageSize: number) => Promise<RequestResult>;
37
42
  export declare type GetCallback = (_ids: OptionId[]) => Promise<OptionValue[]>;
38
43
  export declare type FormatCallback = (_option: OptionItem) => OptionItem;
39
44
  export declare type SelectionOverflow =
@@ -277,6 +282,8 @@ export default class SelecticStore {
277
282
  state: SelecticStoreState;
278
283
  data: Data;
279
284
  private requestId;
285
+ private requestSearchId;
286
+ private isRequesting;
280
287
  private cacheRequest;
281
288
  private closeSelectic;
282
289
  /** Number of item to pre-display */
@@ -309,14 +316,20 @@ export default class SelecticStore {
309
316
  private convertTypeValue;
310
317
  private assertValueType;
311
318
  private assertCorrectValue;
319
+ /** Reset the display cache in order to rebuild it */
320
+ private clearDisplay;
321
+ /** rebuild the state filteredOptions to normalize their values */
312
322
  private updateFilteredOptions;
313
323
  private addGroups;
314
324
  /** This method is for the computed property listOptions */
315
325
  private getListOptions;
326
+ /** This method is for the computed property elementOptions */
316
327
  private getElementOptions;
328
+ /** Generate the list of all options by combining the 3 option lists */
317
329
  private buildAllOptions;
318
330
  private buildFilteredOptions;
319
331
  private buildSelectedOptions;
332
+ private fetchRequest;
320
333
  private fetchData;
321
334
  private filterOptions;
322
335
  private addStaticFilteredOptions;
package/types/index.d.ts CHANGED
@@ -108,10 +108,10 @@ export interface Props {
108
108
  /** Replace the default icon family used in Selectic */
109
109
  iconFamily?: IconFamily;
110
110
  /** If enabled, it resets the dynamic cache when selectic opens */
111
- noCache?: Boolean;
111
+ noCache?: boolean;
112
112
  /** If true, the component opens (at start or if it is closed).
113
113
  * If false, the components closes (if it is opened). */
114
- open?: Boolean;
114
+ open?: boolean;
115
115
  /** Props which is not expected to change during the life time of the
116
116
  * component.
117
117
  * These parameters modify the component behavior but are not official
package/types/tools.d.ts CHANGED
@@ -25,3 +25,7 @@ export declare function assignObject<T>(obj: Partial<T>, ...sourceObjects: Array
25
25
  * @returns true if there are no difference
26
26
  */
27
27
  export declare function compareOptions(oldOptions: OptionValue[], newOptions: OptionValue[]): boolean;
28
+ export declare function debug(fName: string, step: string, ...args: any[]): void;
29
+ export declare namespace debug {
30
+ var enable: (display: boolean) => void;
31
+ }