@agnos-ui/core 0.0.1-alpha.3 → 0.0.1-alpha.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.
Files changed (96) hide show
  1. package/{accordion.d.ts → components/accordion/accordion.d.ts} +13 -4
  2. package/{accordion.js → components/accordion/accordion.js} +17 -11
  3. package/components/alert/alert.d.ts +32 -0
  4. package/components/alert/alert.js +23 -0
  5. package/{alert.d.ts → components/alert/common.d.ts} +17 -21
  6. package/{alert.js → components/alert/common.js} +12 -12
  7. package/{modal → components/modal}/modal.d.ts +28 -21
  8. package/{modal → components/modal}/modal.js +39 -13
  9. package/{pagination.d.ts → components/pagination/pagination.d.ts} +3 -3
  10. package/{pagination.js → components/pagination/pagination.js} +6 -4
  11. package/{progressbar.d.ts → components/progressbar/progressbar.d.ts} +2 -3
  12. package/{progressbar.js → components/progressbar/progressbar.js} +6 -6
  13. package/{rating.d.ts → components/rating/rating.d.ts} +2 -3
  14. package/{rating.js → components/rating/rating.js} +6 -9
  15. package/components/select/select.d.ts +337 -0
  16. package/components/select/select.js +266 -0
  17. package/components/slider/slider.d.ts +239 -0
  18. package/components/slider/slider.js +389 -0
  19. package/config.d.ts +13 -8
  20. package/config.js +3 -3
  21. package/index.d.ts +23 -12
  22. package/index.js +29 -12
  23. package/package.json +32 -4
  24. package/services/extendWidget.d.ts +23 -0
  25. package/{extendWidget.js → services/extendWidget.js} +8 -1
  26. package/services/floatingUI.d.ts +48 -0
  27. package/services/floatingUI.js +97 -0
  28. package/services/focustrack.js +1 -1
  29. package/services/intersection.d.ts +1 -1
  30. package/services/intersection.js +2 -2
  31. package/services/navManager.d.ts +83 -1
  32. package/services/navManager.js +153 -37
  33. package/services/portal.js +8 -4
  34. package/services/siblingsInert.d.ts +2 -1
  35. package/services/siblingsInert.js +2 -2
  36. package/{transitions → services/transitions}/baseTransitions.d.ts +1 -2
  37. package/{transitions → services/transitions}/baseTransitions.js +7 -10
  38. package/services/transitions/bootstrap/collapse.d.ts +2 -0
  39. package/services/transitions/bootstrap/fade.d.ts +1 -0
  40. package/services/transitions/bootstrap.d.ts +2 -0
  41. package/services/transitions/bootstrap.js +2 -0
  42. package/{transitions → services/transitions}/collapse.js +1 -1
  43. package/{transitions → services/transitions}/cssTransitions.js +2 -4
  44. package/{transitions → services/transitions}/simpleClassTransition.js +1 -1
  45. package/types.d.ts +37 -4
  46. package/types.js +1 -0
  47. package/{services/directiveUtils.js → utils/directive.js} +1 -1
  48. package/{services → utils/internal}/checks.d.ts +12 -0
  49. package/{services → utils/internal}/checks.js +12 -0
  50. package/utils/internal/dom.d.ts +13 -0
  51. package/utils/internal/dom.js +49 -0
  52. package/utils/internal/isFocusable.d.ts +9 -0
  53. package/utils/internal/isFocusable.js +35 -0
  54. package/utils/internal/math.d.ts +5 -0
  55. package/utils/internal/math.js +13 -0
  56. package/utils/internal/promise.d.ts +31 -0
  57. package/utils/internal/promise.js +113 -0
  58. package/{modal → utils/internal}/scrollbars.js +1 -1
  59. package/utils/internal/textDirection.d.ts +1 -0
  60. package/utils/internal/textDirection.js +1 -0
  61. package/utils/internal/traversal.d.ts +54 -0
  62. package/utils/internal/traversal.js +105 -0
  63. package/{services → utils}/stores.d.ts +11 -35
  64. package/{services → utils}/stores.js +21 -19
  65. package/utils/writables.d.ts +26 -0
  66. package/utils/writables.js +66 -0
  67. package/extendWidget.d.ts +0 -3
  68. package/select.d.ts +0 -196
  69. package/select.js +0 -240
  70. package/services/index.d.ts +0 -8
  71. package/services/index.js +0 -8
  72. package/services/writables.d.ts +0 -8
  73. package/services/writables.js +0 -30
  74. package/transitions/bootstrap/collapse.d.ts +0 -2
  75. package/transitions/bootstrap/fade.d.ts +0 -1
  76. package/transitions/bootstrap/index.d.ts +0 -2
  77. package/transitions/bootstrap/index.js +0 -2
  78. package/transitions/index.d.ts +0 -5
  79. package/transitions/index.js +0 -5
  80. package/transitions/utils.d.ts +0 -20
  81. package/transitions/utils.js +0 -83
  82. /package/{commonProps.d.ts → components/commonProps.d.ts} +0 -0
  83. /package/{commonProps.js → components/commonProps.js} +0 -0
  84. /package/{pagination.utils.d.ts → components/pagination/bootstrap.d.ts} +0 -0
  85. /package/{pagination.utils.js → components/pagination/bootstrap.js} +0 -0
  86. /package/{transitions → services/transitions}/bootstrap/collapse.js +0 -0
  87. /package/{transitions → services/transitions}/bootstrap/fade.js +0 -0
  88. /package/{transitions → services/transitions}/collapse.d.ts +0 -0
  89. /package/{transitions → services/transitions}/cssTransitions.d.ts +0 -0
  90. /package/{transitions → services/transitions}/simpleClassTransition.d.ts +0 -0
  91. /package/{services/directiveUtils.d.ts → utils/directive.d.ts} +0 -0
  92. /package/{utils.d.ts → utils/internal/func.d.ts} +0 -0
  93. /package/{utils.js → utils/internal/func.js} +0 -0
  94. /package/{modal → utils/internal}/scrollbars.d.ts +0 -0
  95. /package/{services/sortUtils.d.ts → utils/internal/sort.d.ts} +0 -0
  96. /package/{services/sortUtils.js → utils/internal/sort.js} +0 -0
@@ -0,0 +1,105 @@
1
+ const removeSymbol = Symbol('remove');
2
+ function _traversal(key, value, fn, index) {
3
+ const transformedValue = fn(key, value, { removeSymbol, index });
4
+ const type = Object.prototype.toString.call(transformedValue);
5
+ switch (type) {
6
+ case '[object Object]': {
7
+ const newJson = {};
8
+ const baseKey = key ? key + '.' : '';
9
+ for (const [name, objectValue] of Object.entries(transformedValue)) {
10
+ const newValue = _traversal(baseKey + name, objectValue, fn);
11
+ if (newValue !== removeSymbol) {
12
+ newJson[name] = newValue;
13
+ }
14
+ }
15
+ return newJson;
16
+ }
17
+ case '[object Map]': {
18
+ const oldMap = transformedValue;
19
+ const newMap = new Map();
20
+ const baseKey = key ? key + '.' : '';
21
+ for (const [mapKey, objectValue] of Object.entries(oldMap)) {
22
+ const newValue = _traversal(baseKey + name, objectValue, fn);
23
+ if (newValue !== removeSymbol) {
24
+ newMap.set(mapKey, newValue);
25
+ }
26
+ }
27
+ return newMap;
28
+ }
29
+ case '[object Array]': {
30
+ const ar = transformedValue;
31
+ const newArray = [];
32
+ const baseKey = (key ? key : '') + '[]';
33
+ for (let i = 0; i < ar.length; i++) {
34
+ const newValue = _traversal(baseKey, ar[i], fn, i);
35
+ if (newValue !== removeSymbol) {
36
+ newArray.push(newValue);
37
+ }
38
+ }
39
+ return newArray;
40
+ }
41
+ case '[object Set]': {
42
+ const oldSet = transformedValue;
43
+ const newSet = new Set();
44
+ const baseKey = (key ? key : '') + '[]';
45
+ const ar = [...oldSet];
46
+ for (let i = 0; i < ar.length; i++) {
47
+ const newValue = _traversal(baseKey, ar[i], fn, i);
48
+ if (newValue !== removeSymbol) {
49
+ newSet.add(newValue);
50
+ }
51
+ }
52
+ return newSet;
53
+ }
54
+ default:
55
+ break;
56
+ }
57
+ return transformedValue;
58
+ }
59
+ /**
60
+ * Creates a JSON walker function that can be used to traverse and transform
61
+ * the properties of a JSON object.
62
+ *
63
+ * @param fn - The callback function called for each property in the JSON object.
64
+ * @returns A function that takes a JSON object as input and applies the provided
65
+ * callback function to each property.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const json = {
70
+ * name: 'John',
71
+ * age: 30,
72
+ * address: {
73
+ * city: 'New York',
74
+ * country: 'USA',
75
+ * },
76
+ * useless: '',
77
+ * };
78
+ *
79
+ * const transform = createTraversal((key, value, {removeSymbol}) => {
80
+ * if (key === 'age') {
81
+ * return value * 2; // Double the age
82
+ * }
83
+ * if (key === 'useless') {
84
+ * return removeSymbol;
85
+ * }
86
+ * return value;
87
+ * });
88
+ *
89
+ * const transformedJson = transform(json);
90
+ * ```
91
+ */
92
+ export function createTraversal(fn) {
93
+ return (json) => _traversal('', json, fn);
94
+ }
95
+ /**
96
+ * Utility method to create a promise with resolve
97
+ * @returns a promise with resolve
98
+ */
99
+ export const promiseWithResolve = () => {
100
+ let resolve;
101
+ const promise = new Promise((r) => {
102
+ resolve = r;
103
+ });
104
+ return { promise, resolve: resolve };
105
+ };
@@ -1,16 +1,11 @@
1
- import type { ReadableSignal, StoreInput, StoreOptions, StoresInputValues, WritableSignal } from '@amadeus-it-group/tansu';
1
+ import type { ReadableSignal, StoreInput, StoresInputValues, WritableSignal } from '@amadeus-it-group/tansu';
2
+ import type { ConfigValidator, PropsConfig, ValuesOrReadableSignals, WritableWithDefaultOptions } from '../types';
2
3
  export type ToWritableSignal<P> = {
3
4
  [K in keyof P as `${K & string}$`]-?: WritableSignal<P[K], P[K] | undefined>;
4
5
  };
5
6
  export type ReadableSignals<T extends object> = {
6
7
  [K in keyof T]?: ReadableSignal<T[K] | undefined>;
7
8
  };
8
- export type ValuesOrReadableSignals<T extends object> = {
9
- [K in keyof T]?: ReadableSignal<T[K] | undefined> | T[K];
10
- };
11
- export type ValuesOrWritableSignals<T extends object> = {
12
- [K in keyof T]?: WritableSignal<T[K] | undefined> | T[K];
13
- };
14
9
  export type WithoutDollar<S extends `${string}$`> = S extends `${infer U}$` ? U : never;
15
10
  export type ValueOfStore<S extends ReadableSignal<any>> = S extends ReadableSignal<infer U> ? U : never;
16
11
  export type ToState<S extends {
@@ -51,18 +46,6 @@ export declare function createPatch<T extends object>(stores: ToWritableSignal<T
51
46
  * @returns the object with changed properties
52
47
  */
53
48
  export declare function findChangedProperties<T extends Record<string, any>>(obj1: Partial<T>, obj2: Partial<T>): Partial<T> | null;
54
- export declare const INVALID_VALUE: unique symbol;
55
- export type NormalizeValue<T> = (value: T) => T | typeof INVALID_VALUE;
56
- export interface WritableWithDefaultOptions<T> {
57
- /**
58
- * the normalize value function. should return the invalidValue symbol when the provided value is invalid
59
- */
60
- normalizeValue?: NormalizeValue<T>;
61
- /**
62
- * the equal function, allowing to compare two values. used to check if a previous and current values are equals.
63
- */
64
- equal?: StoreOptions<T>['equal'];
65
- }
66
49
  /**
67
50
  * Returns a writable store whose value is either its own value (when it is not undefined) or a default value
68
51
  * that comes either from the `config$` store (when it is not undefined) or from `defValue`.
@@ -78,9 +61,6 @@ export interface WritableWithDefaultOptions<T> {
78
61
  * @returns a writable store with the extra default value and normalization logic described above
79
62
  */
80
63
  export declare function writableWithDefault<T>(defValue: T, config$?: ReadableSignal<T | undefined>, options?: WritableWithDefaultOptions<T>, own$?: WritableSignal<T | undefined>): WritableSignal<T, T | undefined>;
81
- export type ConfigValidator<T extends object> = {
82
- [K in keyof T]?: WritableWithDefaultOptions<T[K]>;
83
- };
84
64
  /**
85
65
  * Returns true if the provided argument is a store (ReadableSignal).
86
66
  * @param x - argument that is tested
@@ -156,22 +136,18 @@ export declare const writablesWithDefault: <T extends object>(defConfig: T, prop
156
136
  * ```
157
137
  */
158
138
  export declare const writablesForProps: <T extends object>(defConfig: T, propsConfig?: PropsConfig<T> | undefined, options?: { [K in keyof T]?: WritableWithDefaultOptions<T[K]> | undefined; } | undefined) => [ToWritableSignal<T>, <U extends Partial<T>>(storesValues?: void | U | undefined) => void];
159
- export interface PropsConfig<U extends object> {
160
- /**
161
- * Object containing, for each property, either its initial value, or a store that will contain the value at any time.
162
- * When the value of a property is undefined or invalid, the value from the config is used.
163
- */
164
- props?: ValuesOrWritableSignals<U>;
165
- /**
166
- * Either a store of objects containing, for each property, the default value,
167
- * or an object containing, for each property, either a store containing the default value or the default value itself.
168
- */
169
- config?: ReadableSignal<Partial<U>> | ValuesOrReadableSignals<Partial<U>>;
170
- }
171
139
  export declare const stateStores: <A extends {
172
140
  [x: `${string}$`]: ReadableSignal<any>;
173
141
  }>(inputStores: A) => {
174
142
  state$: ReadableSignal<ToState<A>>;
175
143
  stores: { [key in `${string}$` & keyof A]: ReadableSignal<ValueOfStore<A[key]>>; };
176
144
  };
177
- export declare const bindableDerived: <T, U extends [WritableSignal<T, T>, ...StoreInput<any>[]]>(onChange$: ReadableSignal<(value: T) => void>, stores: U, adjustValue: (arg: StoresInputValues<U>) => T, equal?: (currentValue: T, newValue: T) => boolean) => ReadableSignal<T>;
145
+ /**
146
+ * Creates a computed store that binds to multiple stores and triggers a callback when the value changes.
147
+ * @param onChange$ - A readable signal callback function to execute when the value changes.
148
+ * @param stores - An array of Svelte stores, with the main store at index 0.
149
+ * @param adjustValue - A function to adjust the value of the main store. By default, the value of the main store is returned.
150
+ * @param equal - A function to determine if two values are equal. Used to compare the ajusted value with the current one.
151
+ * @returns The derived store that reflects the combined state of the input stores.
152
+ */
153
+ export declare const bindableDerived: <T, U extends [WritableSignal<T, T>, ...StoreInput<any>[]]>(onChange$: ReadableSignal<(value: T) => void>, stores: U, adjustValue?: (arg: StoresInputValues<U>) => T, equal?: (currentValue: T, newValue: T) => boolean) => ReadableSignal<T>;
@@ -1,5 +1,6 @@
1
- import { asReadable, batch, computed, derived, get, readable, writable } from '@amadeus-it-group/tansu';
2
- import { identity } from '../utils';
1
+ import { asReadable, asWritable, batch, computed, derived, get, readable, writable } from '@amadeus-it-group/tansu';
2
+ import { INVALID_VALUE } from '../types';
3
+ import { identity } from './internal/func';
3
4
  /**
4
5
  *
5
6
  * Utility function designed to create a `patch` function related to the provided stores.
@@ -56,10 +57,6 @@ export function findChangedProperties(obj1, obj2) {
56
57
  }
57
58
  return hasUpdate ? changedValues : null;
58
59
  }
59
- const update = function (updater) {
60
- this.set(updater(this()));
61
- };
62
- export const INVALID_VALUE = Symbol();
63
60
  /**
64
61
  * Returns a writable store whose value is either its own value (when it is not undefined) or a default value
65
62
  * that comes either from the `config$` store (when it is not undefined) or from `defValue`.
@@ -90,19 +87,16 @@ export function writableWithDefault(defValue, config$ = readable(undefined), opt
90
87
  };
91
88
  const validatedDefConfig$ = computed(() => callNormalizeValue(config$()), { equal });
92
89
  const validatedOwnValue$ = computed(() => callNormalizeValue(own$(), validatedDefConfig$), { equal });
93
- return asReadable(validatedOwnValue$, {
94
- set(value) {
95
- if (value !== undefined) {
96
- const normalizedValue = normalizeValue(value);
97
- if (normalizedValue === INVALID_VALUE) {
98
- console.error('Not setting invalid value', value);
99
- return;
100
- }
101
- value = normalizedValue;
90
+ return asWritable(validatedOwnValue$, (value) => {
91
+ if (value !== undefined) {
92
+ const normalizedValue = normalizeValue(value);
93
+ if (normalizedValue === INVALID_VALUE) {
94
+ console.error('Not setting invalid value', value);
95
+ return;
102
96
  }
103
- own$.set(value);
104
- },
105
- update,
97
+ value = normalizedValue;
98
+ }
99
+ own$.set(value);
106
100
  });
107
101
  }
108
102
  /**
@@ -236,7 +230,15 @@ export const stateStores = (inputStores) => {
236
230
  }),
237
231
  };
238
232
  };
239
- export const bindableDerived = (onChange$, stores, adjustValue, equal = (currentValue, newValue) => newValue === currentValue) => {
233
+ /**
234
+ * Creates a computed store that binds to multiple stores and triggers a callback when the value changes.
235
+ * @param onChange$ - A readable signal callback function to execute when the value changes.
236
+ * @param stores - An array of Svelte stores, with the main store at index 0.
237
+ * @param adjustValue - A function to adjust the value of the main store. By default, the value of the main store is returned.
238
+ * @param equal - A function to determine if two values are equal. Used to compare the ajusted value with the current one.
239
+ * @returns The derived store that reflects the combined state of the input stores.
240
+ */
241
+ export const bindableDerived = (onChange$, stores, adjustValue = (arg) => arg[0], equal = (currentValue, newValue) => newValue === currentValue) => {
240
242
  let currentValue = stores[0]();
241
243
  return derived(stores, {
242
244
  derive(values) {
@@ -0,0 +1,26 @@
1
+ import type { WritableWithDefaultOptions } from '../types';
2
+ import { INVALID_VALUE } from '../types';
3
+ export declare const testToNormalizeValue: <T>(filter: (value: any) => value is T) => (value: any) => typeof INVALID_VALUE | T;
4
+ export declare const typeNumber: WritableWithDefaultOptions<number>;
5
+ export interface TypeNumberInRangeOptions {
6
+ /** If `true`, the range checking will be strict, excluding the minimum and maximum values. Default is `false`. */
7
+ strict?: boolean;
8
+ /** If `true`, values outside the range will be clamped to the minimum or maximum. Default is `true`. */
9
+ useClamp?: boolean;
10
+ }
11
+ /**
12
+ * Factory function for creating a type constraint for numbers within a specified range.
13
+ *
14
+ * @param min - The minimum value.
15
+ * @param max - The maximum value.
16
+ * @param options - Additional options to customize the behavior.
17
+ *
18
+ * @returns A type guard function that returns the clamp value or INVALID_VALUE depending on the provided options.
19
+ */
20
+ export declare function typeNumberInRangeFactory(min: number, max: number, options?: TypeNumberInRangeOptions): WritableWithDefaultOptions<number>;
21
+ export declare const typeBoolean: WritableWithDefaultOptions<boolean>;
22
+ export declare const typeBooleanOrNull: WritableWithDefaultOptions<boolean | null>;
23
+ export declare const typeString: WritableWithDefaultOptions<string>;
24
+ export declare const typeFunction: WritableWithDefaultOptions<(...args: any[]) => any>;
25
+ export declare const typeHTMLElementOrNull: WritableWithDefaultOptions<HTMLElement | null>;
26
+ export declare const typeArray: WritableWithDefaultOptions<any[]>;
@@ -0,0 +1,66 @@
1
+ import { allowNull, clamp, isArray, isBoolean, isFunction, isHTMLElement, isNumber, isString } from './internal/checks';
2
+ import { INVALID_VALUE } from '../types';
3
+ export const testToNormalizeValue = (filter) => (value) => filter(value) ? value : INVALID_VALUE;
4
+ const numberNormalizeFn = testToNormalizeValue(isNumber);
5
+ export const typeNumber = {
6
+ normalizeValue: numberNormalizeFn,
7
+ };
8
+ /**
9
+ * Factory function for creating a type constraint for numbers within a specified range.
10
+ *
11
+ * @param min - The minimum value.
12
+ * @param max - The maximum value.
13
+ * @param options - Additional options to customize the behavior.
14
+ *
15
+ * @returns A type guard function that returns the clamp value or INVALID_VALUE depending on the provided options.
16
+ */
17
+ export function typeNumberInRangeFactory(min, max, options = {}) {
18
+ const { strict = false, useClamp = true } = options;
19
+ return {
20
+ normalizeValue: (value) => {
21
+ let normalizedNumber = numberNormalizeFn(value);
22
+ if (normalizedNumber !== INVALID_VALUE) {
23
+ if (!strict && useClamp) {
24
+ normalizedNumber = clamp(normalizedNumber, max, min);
25
+ }
26
+ if (normalizedNumber >= min && normalizedNumber <= max) {
27
+ if (!strict || (normalizedNumber !== min && normalizedNumber !== max)) {
28
+ return normalizedNumber;
29
+ }
30
+ }
31
+ }
32
+ return INVALID_VALUE;
33
+ },
34
+ };
35
+ }
36
+ export const typeBoolean = {
37
+ normalizeValue: testToNormalizeValue(isBoolean),
38
+ };
39
+ export const typeBooleanOrNull = {
40
+ normalizeValue: testToNormalizeValue(allowNull(isBoolean)),
41
+ };
42
+ export const typeString = {
43
+ normalizeValue: testToNormalizeValue(isString),
44
+ };
45
+ export const typeFunction = {
46
+ normalizeValue: testToNormalizeValue(isFunction),
47
+ equal: Object.is,
48
+ };
49
+ export const typeHTMLElementOrNull = {
50
+ normalizeValue: testToNormalizeValue(allowNull(isHTMLElement)),
51
+ equal: Object.is,
52
+ };
53
+ export const typeArray = {
54
+ normalizeValue: testToNormalizeValue(isArray),
55
+ equal: (a, b) => {
56
+ if (a === b) {
57
+ return true;
58
+ }
59
+ else {
60
+ if (a?.length !== b?.length) {
61
+ return false;
62
+ }
63
+ return a.every((val, index) => val === b[index]);
64
+ }
65
+ },
66
+ };
package/extendWidget.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { ConfigValidator } from './services/stores';
2
- import type { Widget, WidgetFactory, WidgetProps, WidgetState } from './types';
3
- export declare const extendWidgetProps: <W extends Widget<object, object, object, object, object>, ExtraProps extends object>(factory: WidgetFactory<W>, extraPropsDefaults: ExtraProps, extraPropsConfig?: ConfigValidator<ExtraProps> | undefined) => WidgetFactory<Widget<WidgetProps<W> & ExtraProps, WidgetState<W> & ExtraProps, W["api"], W["actions"], W["directives"]>>;
package/select.d.ts DELETED
@@ -1,196 +0,0 @@
1
- import type { HasFocus } from './services/focustrack';
2
- import type { PropsConfig } from './services/stores';
3
- import type { Widget } from './types';
4
- import type { WidgetsCommonPropsAndState } from './commonProps';
5
- export interface SelectCommonPropsAndState<Item> extends WidgetsCommonPropsAndState {
6
- /**
7
- * List of selected items
8
- */
9
- selected: Item[];
10
- /**
11
- * Filtered text to be display in the filter input
12
- */
13
- filterText: string;
14
- /**
15
- * true if the select is disabled
16
- */
17
- disabled: boolean;
18
- /**
19
- * true if the select is open
20
- */
21
- opened: boolean;
22
- /**
23
- * true if a loading process is being done
24
- */
25
- loading: boolean;
26
- }
27
- export interface SelectProps<T> extends SelectCommonPropsAndState<T> {
28
- /**
29
- * List of available items for the dropdown
30
- */
31
- items: T[];
32
- /**
33
- * Custom function to filter an item.
34
- * By default, item is considered as a string, and the function returns true if the text is found
35
- */
36
- matchFn(item: T, text: string): boolean;
37
- /**
38
- * Custom function to get the id of an item
39
- * By default, the item is returned
40
- */
41
- itemId(item: T): string;
42
- /**
43
- * Callback called when the text filter change
44
- * @param text - Filtered text
45
- */
46
- onFilterTextChange?(text: string): void;
47
- }
48
- /**
49
- * Item representation built from the items provided in parameters
50
- */
51
- export interface ItemCtx<T> {
52
- /**
53
- * Original item given in the parameters
54
- */
55
- item: T;
56
- /**
57
- * Unique id to identify the item
58
- */
59
- id: string;
60
- /**
61
- * Specify if the item is checked
62
- */
63
- selected: boolean;
64
- /**
65
- * Select the item
66
- */
67
- select(): void;
68
- /**
69
- * Unselect the item
70
- */
71
- unselect(): void;
72
- /**
73
- * Toggle the item selection
74
- */
75
- toggle(): void;
76
- }
77
- export interface SelectState<Item> extends SelectCommonPropsAndState<Item> {
78
- /**
79
- * List of visible items displayed in the menu
80
- */
81
- visible: ItemCtx<Item>[];
82
- /**
83
- * Highlighted item context.
84
- * It is designed to define the highlighted item in the dropdown menu
85
- */
86
- highlighted: ItemCtx<Item> | undefined;
87
- }
88
- export interface SelectApi<Item> {
89
- /**
90
- * Clear all the selected items
91
- */
92
- clear(): void;
93
- /**
94
- * Clear the filter text
95
- */
96
- clearText(): void;
97
- /**
98
- * Highlight the given item, if there is a corresponding match among the visible list
99
- */
100
- highlight(item: Item): void;
101
- /**
102
- * Highlight the first item among the visible list
103
- */
104
- highlightFirst(): void;
105
- /**
106
- * Highlight the previous item among the visible list
107
- * Loop to the last item if needed
108
- */
109
- highlightPrevious(): void;
110
- /**
111
- * Highlight the next item among the visible list.
112
- * Loop to the first item if needed
113
- */
114
- highlightNext(): void;
115
- /**
116
- * Highlight the last item among the visible list
117
- */
118
- highlightLast(): void;
119
- /**
120
- * Focus the provided item among the selected list.
121
- * The focus feature is designed to know what item must be focused in the UI, i.e. among the badge elements.
122
- */
123
- focus(item: Item): void;
124
- /**
125
- * Focus the first element
126
- */
127
- focusFirst(): void;
128
- /**
129
- * Focus the previous element. If no element was focused before the call, nothing happens.
130
- */
131
- focusPrevious(): void;
132
- /**
133
- * Focus the next element. If no element was focused before the call, nothing happens.
134
- */
135
- focusNext(): void;
136
- /**
137
- * Focus the last element. If no element was focused before the call, nothing happens.
138
- */
139
- focusLast(): void;
140
- /**
141
- * Select the provided item.
142
- * The selected list is used to
143
- * @param item - the item to select
144
- */
145
- select(item: Item): void;
146
- /**
147
- * Unselect the provided item.
148
- * @param item - the item to unselect
149
- */
150
- unselect(item: Item): void;
151
- /**
152
- * Toggle the selection of an item
153
- * @param item - the item to toggle
154
- * @param selected - an optional boolean to enforce the selected/unselected state instead of toggling
155
- */
156
- toggleItem(item: Item, selected?: boolean): void;
157
- /**
158
- * open the select
159
- */
160
- open(): void;
161
- /**
162
- * close the select
163
- */
164
- close(): void;
165
- /**
166
- * Toggle the dropdown menu
167
- * @param isOpen - If specified, set the menu in the defined state.
168
- */
169
- toggle(isOpen?: boolean): void;
170
- }
171
- export interface SelectDirectives {
172
- /**
173
- * Directive to be used in the input group and the menu containers
174
- */
175
- hasFocusDirective: HasFocus['directive'];
176
- }
177
- export interface SelectActions {
178
- /**
179
- * Method to be plugged to on the 'input' event. The input text will be used as the filter text.
180
- */
181
- onInput: (e: {
182
- target: any;
183
- }) => void;
184
- /**
185
- * Method to be plugged to on an keydown event, in order to control the keyboard interactions with the highlighted item.
186
- * It manages arrow keys to move the highlighted item, or enter to toggle the item.
187
- */
188
- onInputKeydown: (e: any) => void;
189
- }
190
- export type SelectWidget<Item> = Widget<SelectProps<Item>, SelectState<Item>, SelectApi<Item>, SelectActions, SelectDirectives>;
191
- /**
192
- * Create a SelectWidget with given config props
193
- * @param config - an optional alert config
194
- * @returns a SelectWidget
195
- */
196
- export declare function createSelect<Item>(config?: PropsConfig<SelectProps<Item>>): SelectWidget<Item>;