@agnos-ui/core 0.0.1-alpha.4 → 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.
- package/{accordion.d.ts → components/accordion/accordion.d.ts} +3 -4
- package/{accordion.js → components/accordion/accordion.js} +10 -9
- package/components/alert/alert.d.ts +32 -0
- package/components/alert/alert.js +23 -0
- package/{alert.d.ts → components/alert/common.d.ts} +17 -21
- package/{alert.js → components/alert/common.js} +12 -12
- package/{modal → components/modal}/modal.d.ts +28 -21
- package/{modal → components/modal}/modal.js +39 -13
- package/{pagination.d.ts → components/pagination/pagination.d.ts} +3 -3
- package/{pagination.js → components/pagination/pagination.js} +6 -4
- package/{progressbar.d.ts → components/progressbar/progressbar.d.ts} +2 -3
- package/{progressbar.js → components/progressbar/progressbar.js} +6 -6
- package/{rating.d.ts → components/rating/rating.d.ts} +2 -3
- package/{rating.js → components/rating/rating.js} +6 -9
- package/components/select/select.d.ts +337 -0
- package/components/select/select.js +266 -0
- package/{slider.d.ts → components/slider/slider.d.ts} +60 -14
- package/components/slider/slider.js +389 -0
- package/config.d.ts +9 -9
- package/config.js +3 -3
- package/index.d.ts +23 -13
- package/index.js +29 -13
- package/package.json +30 -3
- package/services/extendWidget.d.ts +23 -0
- package/{extendWidget.js → services/extendWidget.js} +8 -1
- package/services/floatingUI.d.ts +48 -0
- package/services/floatingUI.js +97 -0
- package/services/focustrack.js +1 -1
- package/services/intersection.d.ts +1 -1
- package/services/intersection.js +2 -2
- package/services/navManager.d.ts +83 -1
- package/services/navManager.js +153 -37
- package/services/portal.js +8 -4
- package/services/siblingsInert.d.ts +2 -1
- package/services/siblingsInert.js +2 -2
- package/{transitions → services/transitions}/baseTransitions.d.ts +1 -2
- package/{transitions → services/transitions}/baseTransitions.js +7 -10
- package/services/transitions/bootstrap/collapse.d.ts +2 -0
- package/services/transitions/bootstrap/fade.d.ts +1 -0
- package/services/transitions/bootstrap.d.ts +2 -0
- package/services/transitions/bootstrap.js +2 -0
- package/{transitions → services/transitions}/collapse.js +1 -1
- package/{transitions → services/transitions}/cssTransitions.js +2 -4
- package/{transitions → services/transitions}/simpleClassTransition.js +1 -1
- package/types.d.ts +37 -4
- package/types.js +1 -0
- package/{services/directiveUtils.js → utils/directive.js} +1 -1
- package/{services → utils/internal}/checks.d.ts +12 -0
- package/{services → utils/internal}/checks.js +12 -0
- package/utils/internal/dom.d.ts +13 -0
- package/utils/internal/dom.js +49 -0
- package/utils/internal/math.d.ts +5 -0
- package/utils/internal/math.js +13 -0
- package/utils/internal/promise.d.ts +31 -0
- package/utils/internal/promise.js +113 -0
- package/{modal → utils/internal}/scrollbars.js +1 -1
- package/utils/internal/textDirection.d.ts +1 -0
- package/utils/internal/textDirection.js +1 -0
- package/utils/internal/traversal.d.ts +54 -0
- package/utils/internal/traversal.js +105 -0
- package/{services → utils}/stores.d.ts +11 -35
- package/{services → utils}/stores.js +21 -19
- package/utils/writables.d.ts +26 -0
- package/utils/writables.js +66 -0
- package/extendWidget.d.ts +0 -3
- package/select.d.ts +0 -196
- package/select.js +0 -240
- package/services/index.d.ts +0 -9
- package/services/index.js +0 -9
- package/services/writables.d.ts +0 -8
- package/services/writables.js +0 -30
- package/slider.js +0 -289
- package/transitions/bootstrap/collapse.d.ts +0 -2
- package/transitions/bootstrap/fade.d.ts +0 -1
- package/transitions/bootstrap/index.d.ts +0 -2
- package/transitions/bootstrap/index.js +0 -2
- package/transitions/index.d.ts +0 -5
- package/transitions/index.js +0 -5
- package/transitions/utils.d.ts +0 -20
- package/transitions/utils.js +0 -83
- /package/{commonProps.d.ts → components/commonProps.d.ts} +0 -0
- /package/{commonProps.js → components/commonProps.js} +0 -0
- /package/{pagination.utils.d.ts → components/pagination/bootstrap.d.ts} +0 -0
- /package/{pagination.utils.js → components/pagination/bootstrap.js} +0 -0
- /package/{transitions → services/transitions}/bootstrap/collapse.js +0 -0
- /package/{transitions → services/transitions}/bootstrap/fade.js +0 -0
- /package/{transitions → services/transitions}/collapse.d.ts +0 -0
- /package/{transitions → services/transitions}/cssTransitions.d.ts +0 -0
- /package/{transitions → services/transitions}/simpleClassTransition.d.ts +0 -0
- /package/{services/directiveUtils.d.ts → utils/directive.d.ts} +0 -0
- /package/{utils.d.ts → utils/internal/func.d.ts} +0 -0
- /package/{utils.js → utils/internal/func.js} +0 -0
- /package/{services → utils/internal}/isFocusable.d.ts +0 -0
- /package/{services → utils/internal}/isFocusable.js +0 -0
- /package/{modal → utils/internal}/scrollbars.d.ts +0 -0
- /package/{services/sortUtils.d.ts → utils/internal/sort.d.ts} +0 -0
- /package/{services/sortUtils.js → utils/internal/sort.js} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { asReadable, batch, computed, derived, get, readable, writable } from '@amadeus-it-group/tansu';
|
|
2
|
-
import {
|
|
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
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
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
|
-
|
|
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>;
|
package/select.js
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { asReadable, batch, computed, writable } from '@amadeus-it-group/tansu';
|
|
2
|
-
import { createHasFocus } from './services/focustrack';
|
|
3
|
-
import { stateStores, writablesForProps } from './services/stores';
|
|
4
|
-
function defaultMatchFn(item, text) {
|
|
5
|
-
return JSON.stringify(item).toLowerCase().includes(text.toLowerCase());
|
|
6
|
-
}
|
|
7
|
-
function defaultItemId(item) {
|
|
8
|
-
return '' + item;
|
|
9
|
-
}
|
|
10
|
-
const defaultConfig = {
|
|
11
|
-
opened: false,
|
|
12
|
-
disabled: false,
|
|
13
|
-
items: [],
|
|
14
|
-
filterText: '',
|
|
15
|
-
loading: false,
|
|
16
|
-
selected: [],
|
|
17
|
-
itemId: defaultItemId,
|
|
18
|
-
matchFn: defaultMatchFn,
|
|
19
|
-
onFilterTextChange: undefined,
|
|
20
|
-
className: '',
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Create a SelectWidget with given config props
|
|
24
|
-
* @param config - an optional alert config
|
|
25
|
-
* @returns a SelectWidget
|
|
26
|
-
*/
|
|
27
|
-
export function createSelect(config) {
|
|
28
|
-
// Props
|
|
29
|
-
const [{ opened$: _dirtyOpened$, items$, itemId$, matchFn$, onFilterTextChange$, ...otherProps }, patch] = writablesForProps(defaultConfig, config);
|
|
30
|
-
const { selected$, filterText$ } = otherProps;
|
|
31
|
-
const { hasFocus$, directive: hasFocusDirective } = createHasFocus();
|
|
32
|
-
const opened$ = computed(() => {
|
|
33
|
-
const _dirtyOpened = _dirtyOpened$();
|
|
34
|
-
const hasFocus = hasFocus$();
|
|
35
|
-
if (!hasFocus && _dirtyOpened) {
|
|
36
|
-
_dirtyOpened$.set(false);
|
|
37
|
-
}
|
|
38
|
-
return _dirtyOpened && hasFocus;
|
|
39
|
-
});
|
|
40
|
-
const highlightedIndex$ = (function () {
|
|
41
|
-
const store = writable(0);
|
|
42
|
-
const newStore = asReadable(store, {
|
|
43
|
-
set(index) {
|
|
44
|
-
const { length } = visible$();
|
|
45
|
-
if (index != undefined) {
|
|
46
|
-
if (!length) {
|
|
47
|
-
index = undefined;
|
|
48
|
-
}
|
|
49
|
-
else if (index < 0) {
|
|
50
|
-
index = length - 1;
|
|
51
|
-
}
|
|
52
|
-
else if (index >= length) {
|
|
53
|
-
index = 0;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
store.set(index);
|
|
57
|
-
},
|
|
58
|
-
update(fn) {
|
|
59
|
-
newStore.set(fn(store()));
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
return newStore;
|
|
63
|
-
})();
|
|
64
|
-
const visible$ = computed(() => {
|
|
65
|
-
const list = [];
|
|
66
|
-
if (opened$()) {
|
|
67
|
-
const selected = selected$();
|
|
68
|
-
const filterText = filterText$();
|
|
69
|
-
const matchFn = !filterText ? () => true : matchFn$();
|
|
70
|
-
const itemId = itemId$();
|
|
71
|
-
for (const item of items$()) {
|
|
72
|
-
if (matchFn(item, filterText)) {
|
|
73
|
-
list.push({
|
|
74
|
-
item,
|
|
75
|
-
id: itemId(item),
|
|
76
|
-
selected: selected.includes(item),
|
|
77
|
-
select: function () {
|
|
78
|
-
widget.api.select(this);
|
|
79
|
-
}.bind(item),
|
|
80
|
-
unselect: function () {
|
|
81
|
-
widget.api.unselect(this);
|
|
82
|
-
}.bind(item),
|
|
83
|
-
toggle: function () {
|
|
84
|
-
widget.api.toggleItem(this);
|
|
85
|
-
}.bind(item),
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return list;
|
|
91
|
-
});
|
|
92
|
-
const highlighted$ = computed(() => {
|
|
93
|
-
const visible = visible$();
|
|
94
|
-
const highlightedIndex = highlightedIndex$();
|
|
95
|
-
return visible.length && highlightedIndex != undefined ? visible[highlightedIndex] : undefined;
|
|
96
|
-
});
|
|
97
|
-
const widget = {
|
|
98
|
-
...stateStores({
|
|
99
|
-
visible$,
|
|
100
|
-
highlighted$,
|
|
101
|
-
opened$,
|
|
102
|
-
...otherProps,
|
|
103
|
-
}),
|
|
104
|
-
patch,
|
|
105
|
-
api: {
|
|
106
|
-
clear() {
|
|
107
|
-
selected$.set([]);
|
|
108
|
-
},
|
|
109
|
-
select(item) {
|
|
110
|
-
widget.api.toggleItem(item, true);
|
|
111
|
-
},
|
|
112
|
-
unselect(item) {
|
|
113
|
-
widget.api.toggleItem(item, false);
|
|
114
|
-
},
|
|
115
|
-
toggleItem(item, selected) {
|
|
116
|
-
if (!items$().includes(item)) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
selected$.update((selectedItems) => {
|
|
120
|
-
selectedItems = [...selectedItems];
|
|
121
|
-
const index = selectedItems.indexOf(item);
|
|
122
|
-
if (selected == null) {
|
|
123
|
-
selected = index === -1;
|
|
124
|
-
}
|
|
125
|
-
if (selected && index === -1) {
|
|
126
|
-
selectedItems.push(item);
|
|
127
|
-
}
|
|
128
|
-
else if (!selected && index !== -1) {
|
|
129
|
-
selectedItems.splice(index, 1);
|
|
130
|
-
}
|
|
131
|
-
return selectedItems;
|
|
132
|
-
});
|
|
133
|
-
},
|
|
134
|
-
clearText() {
|
|
135
|
-
// FIXME: not implemented yet!
|
|
136
|
-
},
|
|
137
|
-
highlight(item) {
|
|
138
|
-
const index = visible$().findIndex((itemCtx) => itemCtx.item === item);
|
|
139
|
-
highlightedIndex$.set(index === -1 ? undefined : index);
|
|
140
|
-
},
|
|
141
|
-
highlightFirst() {
|
|
142
|
-
highlightedIndex$.set(0);
|
|
143
|
-
},
|
|
144
|
-
highlightPrevious() {
|
|
145
|
-
highlightedIndex$.update((highlightedIndex) => {
|
|
146
|
-
return highlightedIndex != null ? highlightedIndex - 1 : -1;
|
|
147
|
-
});
|
|
148
|
-
},
|
|
149
|
-
highlightNext() {
|
|
150
|
-
highlightedIndex$.update((highlightedIndex) => {
|
|
151
|
-
return highlightedIndex != null ? highlightedIndex + 1 : Infinity;
|
|
152
|
-
});
|
|
153
|
-
},
|
|
154
|
-
highlightLast() {
|
|
155
|
-
highlightedIndex$.set(-1);
|
|
156
|
-
},
|
|
157
|
-
focus(item) {
|
|
158
|
-
// FIXME: not implemented yet!
|
|
159
|
-
},
|
|
160
|
-
focusFirst() {
|
|
161
|
-
// FIXME: not implemented yet!
|
|
162
|
-
},
|
|
163
|
-
focusPrevious() {
|
|
164
|
-
// FIXME: not implemented yet!
|
|
165
|
-
},
|
|
166
|
-
focusNext() {
|
|
167
|
-
// FIXME: not implemented yet!
|
|
168
|
-
},
|
|
169
|
-
focusLast() {
|
|
170
|
-
// FIXME: not implemented yet!
|
|
171
|
-
},
|
|
172
|
-
open: () => widget.api.toggle(true),
|
|
173
|
-
close: () => widget.api.toggle(false),
|
|
174
|
-
toggle(isOpen) {
|
|
175
|
-
_dirtyOpened$.update((value) => (isOpen != null ? isOpen : !value));
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
directives: {
|
|
179
|
-
hasFocusDirective,
|
|
180
|
-
},
|
|
181
|
-
actions: {
|
|
182
|
-
onInput({ target }) {
|
|
183
|
-
const value = target.value;
|
|
184
|
-
batch(() => {
|
|
185
|
-
patch({
|
|
186
|
-
opened: value != null && value !== '',
|
|
187
|
-
filterText: value,
|
|
188
|
-
});
|
|
189
|
-
onFilterTextChange$()?.(value);
|
|
190
|
-
});
|
|
191
|
-
},
|
|
192
|
-
onInputKeydown(e) {
|
|
193
|
-
const { ctrlKey, key } = e;
|
|
194
|
-
let keyManaged = true;
|
|
195
|
-
switch (key) {
|
|
196
|
-
case 'ArrowDown': {
|
|
197
|
-
const isOpen = opened$();
|
|
198
|
-
if (isOpen) {
|
|
199
|
-
if (ctrlKey) {
|
|
200
|
-
widget.api.highlightLast();
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
widget.api.highlightNext();
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
widget.api.open();
|
|
208
|
-
widget.api.highlightFirst();
|
|
209
|
-
}
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
case 'ArrowUp':
|
|
213
|
-
if (ctrlKey) {
|
|
214
|
-
widget.api.highlightFirst();
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
widget.api.highlightPrevious();
|
|
218
|
-
}
|
|
219
|
-
break;
|
|
220
|
-
case 'Enter': {
|
|
221
|
-
const itemCtx = highlighted$();
|
|
222
|
-
if (itemCtx) {
|
|
223
|
-
widget.api.toggleItem(itemCtx.item);
|
|
224
|
-
}
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
case 'Escape':
|
|
228
|
-
_dirtyOpened$.set(false);
|
|
229
|
-
break;
|
|
230
|
-
default:
|
|
231
|
-
keyManaged = false;
|
|
232
|
-
}
|
|
233
|
-
if (keyManaged) {
|
|
234
|
-
e.preventDefault();
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
return widget;
|
|
240
|
-
}
|
package/services/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './siblingsInert';
|
|
2
|
-
export * from './directiveUtils';
|
|
3
|
-
export * from './focustrack';
|
|
4
|
-
export * from './intersection';
|
|
5
|
-
export * from './portal';
|
|
6
|
-
export * from './stores';
|
|
7
|
-
export * from './writables';
|
|
8
|
-
export * from './navManager';
|
|
9
|
-
export * from './isFocusable';
|
package/services/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './siblingsInert';
|
|
2
|
-
export * from './directiveUtils';
|
|
3
|
-
export * from './focustrack';
|
|
4
|
-
export * from './intersection';
|
|
5
|
-
export * from './portal';
|
|
6
|
-
export * from './stores';
|
|
7
|
-
export * from './writables';
|
|
8
|
-
export * from './navManager';
|
|
9
|
-
export * from './isFocusable';
|
package/services/writables.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { WritableWithDefaultOptions } from './stores';
|
|
2
|
-
import { INVALID_VALUE } from './stores';
|
|
3
|
-
export declare const testToNormalizeValue: <T>(filter: (value: T) => boolean) => (value: T) => typeof INVALID_VALUE | T;
|
|
4
|
-
export declare const typeNumber: WritableWithDefaultOptions<number>;
|
|
5
|
-
export declare const typeBoolean: WritableWithDefaultOptions<boolean>;
|
|
6
|
-
export declare const typeString: WritableWithDefaultOptions<string>;
|
|
7
|
-
export declare const typeFunction: WritableWithDefaultOptions<(...args: any[]) => any>;
|
|
8
|
-
export declare const typeArray: WritableWithDefaultOptions<any[]>;
|
package/services/writables.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { isArray, isBoolean, isFunction, isNumber, isString } from './checks';
|
|
2
|
-
import { INVALID_VALUE } from './stores';
|
|
3
|
-
export const testToNormalizeValue = (filter) => (value) => filter(value) ? value : INVALID_VALUE;
|
|
4
|
-
export const typeNumber = {
|
|
5
|
-
normalizeValue: testToNormalizeValue(isNumber),
|
|
6
|
-
};
|
|
7
|
-
export const typeBoolean = {
|
|
8
|
-
normalizeValue: testToNormalizeValue(isBoolean),
|
|
9
|
-
};
|
|
10
|
-
export const typeString = {
|
|
11
|
-
normalizeValue: testToNormalizeValue(isString),
|
|
12
|
-
};
|
|
13
|
-
export const typeFunction = {
|
|
14
|
-
normalizeValue: testToNormalizeValue(isFunction),
|
|
15
|
-
equal: Object.is,
|
|
16
|
-
};
|
|
17
|
-
export const typeArray = {
|
|
18
|
-
normalizeValue: testToNormalizeValue(isArray),
|
|
19
|
-
equal: (a, b) => {
|
|
20
|
-
if (a === b) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
if (a?.length !== b?.length) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
return a.every((val, index) => val === b[index]);
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
};
|