@agnos-ui/core 0.10.0-next.4 → 0.11.0-next.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.
- package/{accordion-nxveC0GZ.cjs → accordion-BNq8mApi.cjs} +16 -21
- package/{accordion-47EpOD36.js → accordion-CYAFmYRn.js} +19 -24
- package/{alert-anMaigvi.js → alert-Cb9FhbFQ.js} +1 -1
- package/{collapse-CrfvGo_T.js → collapse-Cg9s33tY.js} +2 -2
- package/{collapse-Da_27YUU.cjs → collapse-yKsOxJlH.cjs} +1 -1
- package/{common-CCxNtFNM.js → common-DFyZvkII.js} +1 -1
- package/components/accordion/accordion.d.ts +18 -8
- package/components/accordion/index.cjs +1 -1
- package/components/accordion/index.js +3 -3
- package/components/alert/common.d.ts +2 -2
- package/components/alert/index.js +1 -1
- package/components/carousel/index.cjs +1 -1
- package/components/carousel/index.js +3 -3
- package/components/collapse/collapse.d.ts +3 -3
- package/components/collapse/index.cjs +1 -1
- package/components/collapse/index.js +1 -1
- package/components/drawer/drawer.d.ts +12 -2
- package/components/drawer/index.cjs +1 -1
- package/components/drawer/index.js +1 -1
- package/components/modal/index.cjs +1 -1
- package/components/modal/index.js +4 -4
- package/components/pagination/index.cjs +1 -1
- package/components/pagination/index.js +1 -1
- package/components/progressbar/index.cjs +1 -1
- package/components/progressbar/index.js +1 -1
- package/components/rating/index.cjs +1 -1
- package/components/rating/index.js +1 -1
- package/components/slider/index.cjs +1 -1
- package/components/slider/index.js +1 -1
- package/components/toast/index.cjs +1 -1
- package/components/toast/index.js +1 -1
- package/components/tree/index.cjs +1 -1
- package/components/tree/index.js +1 -1
- package/config.d.ts +0 -5
- package/{dom-Cm9_uROp.cjs → dom-BX4ImCTd.cjs} +28 -4
- package/{dom-DD1hAVZy.js → dom-Bb5ZCr_a.js} +49 -25
- package/{drawer-CGHyRTM9.js → drawer-CYtNS8c1.js} +16 -9
- package/{drawer-B5Yaqpiu.cjs → drawer-DoaLRui_.cjs} +13 -6
- package/index.cjs +12 -14
- package/index.d.ts +0 -1
- package/index.js +56 -58
- package/{modal-B_3Uxplo.cjs → modal-CMeWLNO-.cjs} +1 -1
- package/{modal-cKd3qUn1.js → modal-EHJERSIp.js} +6 -6
- package/package.json +1 -1
- package/{pagination-DlOyP_2C.js → pagination-BDKo2d3i.js} +2 -2
- package/{pagination-2Vor6JPZ.cjs → pagination-Ddk3z56A.cjs} +1 -1
- package/{progressbar-B5g76eMV.js → progressbar-BFdAfV5g.js} +2 -2
- package/{progressbar-DyBRINco.cjs → progressbar-ysfDQD0Q.cjs} +1 -1
- package/{promise-Y53vc4Ia.js → promise-D-RZVPuv.js} +1 -1
- package/{rating-C7C4-p4B.js → rating-D04FQgtR.js} +2 -2
- package/{rating-C0y1j4SC.cjs → rating-DO_fKNp3.cjs} +1 -1
- package/services/floatingUI.cjs +1 -1
- package/services/floatingUI.js +2 -2
- package/services/focusElement.cjs +1 -1
- package/services/focusElement.js +1 -1
- package/services/focustrack.cjs +1 -1
- package/services/focustrack.js +1 -1
- package/services/matchMedia.cjs +1 -1
- package/services/matchMedia.js +1 -1
- package/services/navManager.cjs +5 -5
- package/services/navManager.js +2 -2
- package/services/pointerdownPosition.cjs +1 -1
- package/services/pointerdownPosition.js +1 -1
- package/services/portal.cjs +1 -1
- package/services/portal.js +1 -1
- package/services/resizeObserver.cjs +1 -1
- package/services/resizeObserver.js +1 -1
- package/services/siblingsInert.cjs +1 -1
- package/services/siblingsInert.js +1 -1
- package/services/transitions/baseTransitions.cjs +1 -1
- package/services/transitions/baseTransitions.js +3 -3
- package/services/transitions/collapse.cjs +1 -1
- package/services/transitions/collapse.js +1 -1
- package/services/transitions/cssTransitions.cjs +1 -1
- package/services/transitions/cssTransitions.js +2 -2
- package/services/transitions/simpleClassTransition.cjs +1 -1
- package/services/transitions/simpleClassTransition.js +1 -1
- package/{slider-B4WrdTeE.js → slider-BPQIKRKL.js} +3 -3
- package/{slider-DTO58syz.cjs → slider-BRktp0--.cjs} +1 -1
- package/textDirection-cNgt24LJ.js +4 -0
- package/textDirection-zqcZ5-eK.cjs +3 -0
- package/{toaster-CT148JSJ.cjs → toaster-Kq-cZoiD.cjs} +1 -1
- package/{toaster-CRPErgI2.js → toaster-y_hXuh4o.js} +3 -3
- package/{tree-CHpFqJPx.js → tree-AM_J23Hz.js} +2 -2
- package/{tree-C4l2Wqny.cjs → tree-BAE89Xjn.cjs} +1 -1
- package/utils/directive.cjs +2 -1
- package/utils/directive.d.ts +8 -0
- package/utils/directive.js +20 -19
- package/utils/stores.cjs +5 -2
- package/utils/stores.js +6 -3
- package/utils/writables.js +11 -11
- package/{writables-Is1bF1Vt.js → writables-DYGjj5T3.js} +10 -10
- package/components/select/index.cjs +0 -5
- package/components/select/index.d.ts +0 -1
- package/components/select/index.js +0 -5
- package/components/select/select.d.ts +0 -311
- package/select-Dhsb9msC.cjs +0 -376
- package/select-nnl00UWY.js +0 -377
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import type { Placement } from '@floating-ui/dom';
|
|
2
|
-
import type { FloatingUI } from '../../services/floatingUI';
|
|
3
|
-
import type { HasFocus } from '../../services/focustrack';
|
|
4
|
-
import type { Directive, PropsConfig, Widget, WidgetFactory } from '../../types';
|
|
5
|
-
import type { WidgetsCommonPropsAndState } from '../commonProps';
|
|
6
|
-
interface SelectCommonPropsAndState<Item> extends WidgetsCommonPropsAndState {
|
|
7
|
-
/**
|
|
8
|
-
* id used for the input inside the select
|
|
9
|
-
*/
|
|
10
|
-
id: string | undefined;
|
|
11
|
-
/**
|
|
12
|
-
* aria-label used for the input inside the select
|
|
13
|
-
*
|
|
14
|
-
* @defaultValue `'Select'`
|
|
15
|
-
*/
|
|
16
|
-
ariaLabel: string | undefined;
|
|
17
|
-
/**
|
|
18
|
-
* List of selected item ids
|
|
19
|
-
*
|
|
20
|
-
* @defaultValue `[]`
|
|
21
|
-
*/
|
|
22
|
-
selected: Item[];
|
|
23
|
-
/**
|
|
24
|
-
* Filtered text to be display in the filter input
|
|
25
|
-
*
|
|
26
|
-
* @defaultValue `''`
|
|
27
|
-
*/
|
|
28
|
-
filterText: string;
|
|
29
|
-
/**
|
|
30
|
-
* true if the select is disabled
|
|
31
|
-
*
|
|
32
|
-
* @defaultValue `false`
|
|
33
|
-
*/
|
|
34
|
-
disabled: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* true if the select is open
|
|
37
|
-
*
|
|
38
|
-
* @defaultValue `false`
|
|
39
|
-
*/
|
|
40
|
-
open: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Class to be added on the dropdown menu container
|
|
43
|
-
*
|
|
44
|
-
* @defaultValue `''`
|
|
45
|
-
*/
|
|
46
|
-
menuClassName: string;
|
|
47
|
-
/**
|
|
48
|
-
* Class to be added on menu items
|
|
49
|
-
*
|
|
50
|
-
* @defaultValue `''`
|
|
51
|
-
*/
|
|
52
|
-
menuItemClassName: string;
|
|
53
|
-
/**
|
|
54
|
-
* Class to be added on selected items (displayed in the input zone)
|
|
55
|
-
*
|
|
56
|
-
* @defaultValue `''`
|
|
57
|
-
*/
|
|
58
|
-
badgeClassName: string;
|
|
59
|
-
/**
|
|
60
|
-
* true if a loading process is being done
|
|
61
|
-
*
|
|
62
|
-
* @defaultValue `false`
|
|
63
|
-
*/
|
|
64
|
-
loading: boolean;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Props for the Select component.
|
|
68
|
-
*
|
|
69
|
-
* @template Item - The type of the Select Items
|
|
70
|
-
*/
|
|
71
|
-
export interface SelectProps<Item> extends SelectCommonPropsAndState<Item> {
|
|
72
|
-
/**
|
|
73
|
-
* List of available items for the dropdown
|
|
74
|
-
*
|
|
75
|
-
* @defaultValue `[]`
|
|
76
|
-
*/
|
|
77
|
-
items: Item[];
|
|
78
|
-
/**
|
|
79
|
-
* List of allowed placements for the dropdown.
|
|
80
|
-
* This refers to the [allowedPlacements from floating UI](https://floating-ui.com/docs/autoPlacement#allowedplacements), given the different [Placement possibilities](https://floating-ui.com/docs/computePosition#placement).
|
|
81
|
-
*
|
|
82
|
-
* @defaultValue
|
|
83
|
-
* ```ts
|
|
84
|
-
* ['bottom-start', 'top-start', 'bottom-end', 'top-end']
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
allowedPlacements: Placement[];
|
|
88
|
-
/**
|
|
89
|
-
* Custom function to get the id of an item
|
|
90
|
-
* By default, the item is returned
|
|
91
|
-
*
|
|
92
|
-
* @defaultValue
|
|
93
|
-
* ```ts
|
|
94
|
-
* (item: any) => '' + item
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
itemIdFn(item: Item): string;
|
|
98
|
-
/**
|
|
99
|
-
* Retrieves navigable elements within an HTML element containing badges and the input.
|
|
100
|
-
*
|
|
101
|
-
* @param node - HTMLElement that contains the badges and the input
|
|
102
|
-
*
|
|
103
|
-
* @defaultValue
|
|
104
|
-
* ```ts
|
|
105
|
-
* (node: HTMLElement) => node.querySelectorAll('.au-select-badge,input')
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
navSelector(node: HTMLElement): NodeListOf<HTMLSpanElement | HTMLInputElement>;
|
|
109
|
-
/**
|
|
110
|
-
* Callback called dropdown open state change
|
|
111
|
-
* @param isOpen - updated open state
|
|
112
|
-
*
|
|
113
|
-
* @defaultValue
|
|
114
|
-
* ```ts
|
|
115
|
-
* () => {}
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
onOpenChange(isOpen: boolean): void;
|
|
119
|
-
/**
|
|
120
|
-
* Callback called when the text filter change
|
|
121
|
-
* @param text - Filtered text
|
|
122
|
-
*
|
|
123
|
-
* @defaultValue
|
|
124
|
-
* ```ts
|
|
125
|
-
* () => {}
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
onFilterTextChange(text: string): void;
|
|
129
|
-
/**
|
|
130
|
-
* Callback called when the selection change
|
|
131
|
-
*
|
|
132
|
-
* @defaultValue
|
|
133
|
-
* ```ts
|
|
134
|
-
* () => {}
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
onSelectedChange(selected: Item[]): void;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Item representation built from the items provided in parameters
|
|
141
|
-
*
|
|
142
|
-
* @template T - The type of the Select Items
|
|
143
|
-
*/
|
|
144
|
-
export interface ItemContext<T> {
|
|
145
|
-
/**
|
|
146
|
-
* Original item given in the parameters
|
|
147
|
-
*/
|
|
148
|
-
item: T;
|
|
149
|
-
/**
|
|
150
|
-
* Unique id to identify the item
|
|
151
|
-
*/
|
|
152
|
-
id: string;
|
|
153
|
-
/**
|
|
154
|
-
* Specify if the item is checked
|
|
155
|
-
*/
|
|
156
|
-
selected: boolean;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Represents the state of a Select component.
|
|
160
|
-
*
|
|
161
|
-
* @template Item - The type of the Select Items
|
|
162
|
-
*/
|
|
163
|
-
export interface SelectState<Item> extends SelectCommonPropsAndState<Item> {
|
|
164
|
-
/**
|
|
165
|
-
* List of item contexts, to be displayed in the menu
|
|
166
|
-
*/
|
|
167
|
-
visibleItems: ItemContext<Item>[];
|
|
168
|
-
/**
|
|
169
|
-
* List of selected items to be display
|
|
170
|
-
*/
|
|
171
|
-
selectedContexts: ItemContext<Item>[];
|
|
172
|
-
/**
|
|
173
|
-
* Highlighted item context.
|
|
174
|
-
* It is designed to define the highlighted item in the dropdown menu
|
|
175
|
-
*/
|
|
176
|
-
highlighted: ItemContext<Item> | undefined;
|
|
177
|
-
/**
|
|
178
|
-
* Current placement of the dropdown
|
|
179
|
-
*/
|
|
180
|
-
placement: Placement | undefined;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Interface representing the API for a Select component.
|
|
184
|
-
*
|
|
185
|
-
* @template Item - The type of the Select Items
|
|
186
|
-
*/
|
|
187
|
-
export interface SelectApi<Item> {
|
|
188
|
-
/**
|
|
189
|
-
* Clear all the selected items
|
|
190
|
-
*/
|
|
191
|
-
clear(): void;
|
|
192
|
-
/**
|
|
193
|
-
* Clear the filter text
|
|
194
|
-
*/
|
|
195
|
-
clearText(): void;
|
|
196
|
-
/**
|
|
197
|
-
* Highlight the given item, if there is a corresponding match among the visible list
|
|
198
|
-
*/
|
|
199
|
-
highlight(item: Item): void;
|
|
200
|
-
/**
|
|
201
|
-
* Highlight the first item among the visible list
|
|
202
|
-
*/
|
|
203
|
-
highlightFirst(): void;
|
|
204
|
-
/**
|
|
205
|
-
* Highlight the previous item among the visible list
|
|
206
|
-
* Loop to the last item if needed
|
|
207
|
-
*/
|
|
208
|
-
highlightPrevious(): void;
|
|
209
|
-
/**
|
|
210
|
-
* Highlight the next item among the visible list.
|
|
211
|
-
* Loop to the first item if needed
|
|
212
|
-
*/
|
|
213
|
-
highlightNext(): void;
|
|
214
|
-
/**
|
|
215
|
-
* Highlight the last item among the visible list
|
|
216
|
-
*/
|
|
217
|
-
highlightLast(): void;
|
|
218
|
-
/**
|
|
219
|
-
* Select the provided item.
|
|
220
|
-
* The selected list is used to
|
|
221
|
-
* @param item - the item to select
|
|
222
|
-
*/
|
|
223
|
-
select(item: Item): void;
|
|
224
|
-
/**
|
|
225
|
-
* Unselect the provided item.
|
|
226
|
-
* @param item - the item to unselect
|
|
227
|
-
*/
|
|
228
|
-
unselect(item: Item): void;
|
|
229
|
-
/**
|
|
230
|
-
* Toggle the selection of an item
|
|
231
|
-
* @param item - the item to toggle
|
|
232
|
-
* @param selected - an optional boolean to enforce the selected/unselected state instead of toggling
|
|
233
|
-
*/
|
|
234
|
-
toggleItem(item: Item, selected?: boolean): void;
|
|
235
|
-
/**
|
|
236
|
-
* open the select
|
|
237
|
-
*/
|
|
238
|
-
open(): void;
|
|
239
|
-
/**
|
|
240
|
-
* close the select
|
|
241
|
-
*/
|
|
242
|
-
close(): void;
|
|
243
|
-
/**
|
|
244
|
-
* Toggle the dropdown menu
|
|
245
|
-
* @param isOpen - If specified, set the menu in the defined state.
|
|
246
|
-
*/
|
|
247
|
-
toggle(isOpen?: boolean): void;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Interface representing the directives used in the Select component.
|
|
251
|
-
*
|
|
252
|
-
* @template Item - The type of the Select Items
|
|
253
|
-
*/
|
|
254
|
-
export interface SelectDirectives<Item> {
|
|
255
|
-
/**
|
|
256
|
-
* Directive to be used in the input group and the menu containers
|
|
257
|
-
*/
|
|
258
|
-
hasFocusDirective: HasFocus['directive'];
|
|
259
|
-
/**
|
|
260
|
-
* Directive that enables dynamic positioning of menu element
|
|
261
|
-
*/
|
|
262
|
-
floatingDirective: FloatingUI['directives']['floatingDirective'];
|
|
263
|
-
/**
|
|
264
|
-
* A directive to be applied to the input group element serves as the base for menu positioning
|
|
265
|
-
*/
|
|
266
|
-
referenceDirective: FloatingUI['directives']['referenceDirective'];
|
|
267
|
-
/**
|
|
268
|
-
* A directive to be applied to the element that contains the badges and the input
|
|
269
|
-
*/
|
|
270
|
-
inputContainerDirective: Directive;
|
|
271
|
-
/**
|
|
272
|
-
* A directive that applies all the necessary attributes to the container badges
|
|
273
|
-
*/
|
|
274
|
-
badgeAttributesDirective: Directive<ItemContext<Item>>;
|
|
275
|
-
/**
|
|
276
|
-
* A directive that applies all the necessary attributes to the dropdown menu
|
|
277
|
-
*/
|
|
278
|
-
menuAttributesDirective: Directive;
|
|
279
|
-
/**
|
|
280
|
-
* A directive that applies all the necessary attributes to the dropdown item
|
|
281
|
-
*/
|
|
282
|
-
itemAttributesDirective: Directive<ItemContext<Item>>;
|
|
283
|
-
/**
|
|
284
|
-
* A directive to be applied to the input
|
|
285
|
-
*/
|
|
286
|
-
inputDirective: Directive;
|
|
287
|
-
/**
|
|
288
|
-
* A directive to be applied to a button that closes a badge
|
|
289
|
-
*/
|
|
290
|
-
badgeCloseButtonDirective: Directive<ItemContext<Item>>;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Represents a Select widget component.
|
|
294
|
-
*
|
|
295
|
-
* @template Item - The type of the Select Items
|
|
296
|
-
*/
|
|
297
|
-
export type SelectWidget<Item> = Widget<SelectProps<Item>, SelectState<Item>, SelectApi<Item>, SelectDirectives<Item>>;
|
|
298
|
-
/**
|
|
299
|
-
* Returns a shallow copy of the default select config.
|
|
300
|
-
* @returns a copy of the default config
|
|
301
|
-
*/
|
|
302
|
-
export declare function getSelectDefaultConfig(): SelectProps<any>;
|
|
303
|
-
/**
|
|
304
|
-
* Create a SelectWidget with given config props
|
|
305
|
-
*
|
|
306
|
-
* @template Item - The type of the Select Items
|
|
307
|
-
* @param config - an optional alert config
|
|
308
|
-
* @returns a SelectWidget
|
|
309
|
-
*/
|
|
310
|
-
export declare const createSelect: WidgetFactory<SelectWidget<unknown>, <Item>(config?: PropsConfig<SelectProps<Item>>) => SelectWidget<Item>>;
|
|
311
|
-
export {};
|
package/select-Dhsb9msC.cjs
DELETED
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const tansu = require("@amadeus-it-group/tansu");
|
|
3
|
-
const dom = require("@floating-ui/dom");
|
|
4
|
-
const services_floatingUI = require("./services/floatingUI.cjs");
|
|
5
|
-
const services_focustrack = require("./services/focustrack.cjs");
|
|
6
|
-
const services_navManager = require("./services/navManager.cjs");
|
|
7
|
-
const utils_directive = require("./dom-Cm9_uROp.cjs");
|
|
8
|
-
const utils_func = require("./utils/func.cjs");
|
|
9
|
-
const utils_stores = require("./utils/stores.cjs");
|
|
10
|
-
const utils_widget = require("./utils/widget.cjs");
|
|
11
|
-
const defaultConfig = {
|
|
12
|
-
id: void 0,
|
|
13
|
-
ariaLabel: "Select",
|
|
14
|
-
open: false,
|
|
15
|
-
disabled: false,
|
|
16
|
-
items: [],
|
|
17
|
-
filterText: "",
|
|
18
|
-
loading: false,
|
|
19
|
-
selected: [],
|
|
20
|
-
navSelector: (node) => node.querySelectorAll(".au-select-badge,input"),
|
|
21
|
-
itemIdFn: (item) => "" + item,
|
|
22
|
-
onOpenChange: utils_func.noop,
|
|
23
|
-
onFilterTextChange: utils_func.noop,
|
|
24
|
-
onSelectedChange: utils_func.noop,
|
|
25
|
-
allowedPlacements: ["bottom-start", "top-start", "bottom-end", "top-end"],
|
|
26
|
-
className: "",
|
|
27
|
-
menuClassName: "",
|
|
28
|
-
menuItemClassName: "",
|
|
29
|
-
badgeClassName: ""
|
|
30
|
-
};
|
|
31
|
-
function getSelectDefaultConfig() {
|
|
32
|
-
return { ...defaultConfig };
|
|
33
|
-
}
|
|
34
|
-
const createSelect = utils_widget.createWidgetFactory("select", (config) => {
|
|
35
|
-
const [
|
|
36
|
-
{
|
|
37
|
-
id$: _dirtyId$,
|
|
38
|
-
open$: _dirtyOpen$,
|
|
39
|
-
filterText$: _dirtyFilterText$,
|
|
40
|
-
items$,
|
|
41
|
-
itemIdFn$,
|
|
42
|
-
onOpenChange$,
|
|
43
|
-
onFilterTextChange$,
|
|
44
|
-
onSelectedChange$,
|
|
45
|
-
allowedPlacements$,
|
|
46
|
-
navSelector$,
|
|
47
|
-
className$,
|
|
48
|
-
badgeClassName$,
|
|
49
|
-
ariaLabel$,
|
|
50
|
-
menuClassName$,
|
|
51
|
-
...stateProps
|
|
52
|
-
},
|
|
53
|
-
patch
|
|
54
|
-
] = utils_stores.writablesForProps(defaultConfig, config);
|
|
55
|
-
const { selected$ } = stateProps;
|
|
56
|
-
const id$ = tansu.computed(() => _dirtyId$() ?? utils_directive.generateId());
|
|
57
|
-
const filterText$ = utils_stores.bindableProp(_dirtyFilterText$, onFilterTextChange$);
|
|
58
|
-
const { hasFocus$, directive: hasFocusDirective } = services_focustrack.createHasFocus();
|
|
59
|
-
const open$ = utils_stores.bindableDerived(onOpenChange$, [_dirtyOpen$, hasFocus$], ([_dirtyOpen, hasFocus]) => _dirtyOpen && hasFocus);
|
|
60
|
-
const selectedContextsMap$ = tansu.computed(() => {
|
|
61
|
-
const selectedItemsContext = /* @__PURE__ */ new Map();
|
|
62
|
-
const itemIdFn = itemIdFn$();
|
|
63
|
-
for (const item of selected$()) {
|
|
64
|
-
const id = itemIdFn(item);
|
|
65
|
-
selectedItemsContext.set(id, {
|
|
66
|
-
item,
|
|
67
|
-
id: itemIdFn(item),
|
|
68
|
-
selected: true
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return selectedItemsContext;
|
|
72
|
-
});
|
|
73
|
-
const selectedContexts$ = tansu.computed(() => [...selectedContextsMap$().values()]);
|
|
74
|
-
const highlightedIndex$ = (function() {
|
|
75
|
-
const store = tansu.writable(0);
|
|
76
|
-
return tansu.asWritable(store, (index) => {
|
|
77
|
-
const { length } = visibleItems$();
|
|
78
|
-
if (index != void 0) {
|
|
79
|
-
if (!length) {
|
|
80
|
-
index = void 0;
|
|
81
|
-
} else if (index < 0) {
|
|
82
|
-
index = length - 1;
|
|
83
|
-
} else if (index >= length) {
|
|
84
|
-
index = 0;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
store.set(index);
|
|
88
|
-
});
|
|
89
|
-
})();
|
|
90
|
-
const itemContexts$ = tansu.computed(() => {
|
|
91
|
-
const itemContexts = /* @__PURE__ */ new Map();
|
|
92
|
-
if (open$()) {
|
|
93
|
-
const selectedContextsMap = selectedContextsMap$();
|
|
94
|
-
const itemIdFn = itemIdFn$();
|
|
95
|
-
for (const item of items$()) {
|
|
96
|
-
const id = itemIdFn(item);
|
|
97
|
-
itemContexts.set(id, {
|
|
98
|
-
item,
|
|
99
|
-
id,
|
|
100
|
-
selected: selectedContextsMap.has(id)
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return itemContexts;
|
|
105
|
-
});
|
|
106
|
-
const visibleItems$ = tansu.computed(() => open$() ? [...itemContexts$().values()] : []);
|
|
107
|
-
const highlighted$ = tansu.computed(() => {
|
|
108
|
-
const visibleItems = visibleItems$();
|
|
109
|
-
const highlightedIndex = highlightedIndex$();
|
|
110
|
-
return visibleItems.length && highlightedIndex != void 0 ? visibleItems[highlightedIndex] : void 0;
|
|
111
|
-
});
|
|
112
|
-
const {
|
|
113
|
-
directives: { floatingDirective, referenceDirective },
|
|
114
|
-
stores: { placement$ }
|
|
115
|
-
} = services_floatingUI.createFloatingUI({
|
|
116
|
-
props: {
|
|
117
|
-
computePositionOptions: tansu.asWritable(
|
|
118
|
-
tansu.computed(() => ({
|
|
119
|
-
middleware: [
|
|
120
|
-
dom.offset(5),
|
|
121
|
-
dom.autoPlacement({
|
|
122
|
-
allowedPlacements: allowedPlacements$()
|
|
123
|
-
}),
|
|
124
|
-
dom.size()
|
|
125
|
-
]
|
|
126
|
-
}))
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
const { directive: navDirective, refreshElements, focusFirst, focusLast, focusLeft, focusRight } = services_navManager.createNavManager();
|
|
131
|
-
const navManagerConfig$ = tansu.computed(
|
|
132
|
-
() => ({
|
|
133
|
-
keys: {
|
|
134
|
-
Home: focusFirst,
|
|
135
|
-
End: focusLast,
|
|
136
|
-
ArrowLeft: focusLeft,
|
|
137
|
-
ArrowRight: focusRight
|
|
138
|
-
},
|
|
139
|
-
selector: navSelector$()
|
|
140
|
-
})
|
|
141
|
-
);
|
|
142
|
-
const onRemoveBadge = (event, item) => {
|
|
143
|
-
const referenceElement = event.target;
|
|
144
|
-
refreshElements();
|
|
145
|
-
widget.api.unselect(item);
|
|
146
|
-
if (referenceElement instanceof HTMLElement) {
|
|
147
|
-
setTimeout(() => {
|
|
148
|
-
if (!focusLeft({ event, referenceElement })) {
|
|
149
|
-
focusRight({ event, referenceElement });
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
event.preventDefault();
|
|
154
|
-
};
|
|
155
|
-
const inputContainerAttributesDirective = utils_directive.createAttributesDirective(() => ({
|
|
156
|
-
attributes: {
|
|
157
|
-
role: tansu.readable("combobox"),
|
|
158
|
-
"aria-haspopup": tansu.readable("listbox"),
|
|
159
|
-
"aria-expanded": tansu.computed(() => `${open$()}`),
|
|
160
|
-
"aria-controls": tansu.computed(() => `${id$()}-menu`)
|
|
161
|
-
}
|
|
162
|
-
}));
|
|
163
|
-
const badgeAttributesDirective = utils_directive.createAttributesDirective((itemContext$) => ({
|
|
164
|
-
attributes: {
|
|
165
|
-
tabindex: tansu.readable(-1),
|
|
166
|
-
class: badgeClassName$
|
|
167
|
-
},
|
|
168
|
-
classNames: {
|
|
169
|
-
"au-select-badge": utils_stores.true$
|
|
170
|
-
},
|
|
171
|
-
events: {
|
|
172
|
-
keydown: (event) => {
|
|
173
|
-
let keyManaged = false;
|
|
174
|
-
switch (event.key) {
|
|
175
|
-
case "Backspace":
|
|
176
|
-
case "Delete": {
|
|
177
|
-
onRemoveBadge(event, itemContext$().item);
|
|
178
|
-
keyManaged = true;
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
if (keyManaged) {
|
|
183
|
-
event.preventDefault();
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}));
|
|
188
|
-
const menuAttributesDirective = utils_directive.createAttributesDirective(() => ({
|
|
189
|
-
attributes: {
|
|
190
|
-
role: tansu.readable("listbox"),
|
|
191
|
-
id: tansu.computed(() => `${id$()}-menu`),
|
|
192
|
-
"data-popper-placement": placement$,
|
|
193
|
-
class: menuClassName$
|
|
194
|
-
},
|
|
195
|
-
events: {
|
|
196
|
-
mousedown: (e) => e.preventDefault()
|
|
197
|
-
}
|
|
198
|
-
}));
|
|
199
|
-
const itemAttributesDirective = utils_directive.createAttributesDirective((itemContext$) => ({
|
|
200
|
-
attributes: {
|
|
201
|
-
role: tansu.readable("option"),
|
|
202
|
-
"aria-selected": tansu.computed(() => `${itemContext$().selected}`),
|
|
203
|
-
style: tansu.readable("cursor: pointer")
|
|
204
|
-
},
|
|
205
|
-
classNames: {
|
|
206
|
-
"au-select-item": utils_stores.true$,
|
|
207
|
-
selected: tansu.computed(() => itemContext$().selected)
|
|
208
|
-
},
|
|
209
|
-
events: {
|
|
210
|
-
click: () => widget.api.toggleItem(itemContext$().item)
|
|
211
|
-
}
|
|
212
|
-
}));
|
|
213
|
-
const inputDirective = utils_directive.createAttributesDirective(() => ({
|
|
214
|
-
attributes: {
|
|
215
|
-
id: id$,
|
|
216
|
-
type: tansu.readable("text"),
|
|
217
|
-
"aria-label": ariaLabel$,
|
|
218
|
-
"aria-autocomplete": tansu.readable("list"),
|
|
219
|
-
autocorrect: tansu.readable("off"),
|
|
220
|
-
autocapitalize: tansu.readable("none"),
|
|
221
|
-
autocomplete: tansu.readable("off")
|
|
222
|
-
},
|
|
223
|
-
classNames: {
|
|
224
|
-
"au-select-input": utils_stores.true$
|
|
225
|
-
},
|
|
226
|
-
events: {
|
|
227
|
-
input: (event) => {
|
|
228
|
-
const value = event.target.value;
|
|
229
|
-
tansu.batch(() => {
|
|
230
|
-
open$.set(value != null && value !== "");
|
|
231
|
-
filterText$.set(value);
|
|
232
|
-
});
|
|
233
|
-
},
|
|
234
|
-
keydown: ({ ctrlKey, key, preventDefault }) => {
|
|
235
|
-
let keyManaged = true;
|
|
236
|
-
switch (key) {
|
|
237
|
-
case "ArrowDown": {
|
|
238
|
-
const isOpen = open$();
|
|
239
|
-
if (isOpen) {
|
|
240
|
-
if (ctrlKey) {
|
|
241
|
-
widget.api.highlightLast();
|
|
242
|
-
} else {
|
|
243
|
-
widget.api.highlightNext();
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
widget.api.open();
|
|
247
|
-
widget.api.highlightFirst();
|
|
248
|
-
}
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
case "ArrowUp":
|
|
252
|
-
if (ctrlKey) {
|
|
253
|
-
widget.api.highlightFirst();
|
|
254
|
-
} else {
|
|
255
|
-
widget.api.highlightPrevious();
|
|
256
|
-
}
|
|
257
|
-
break;
|
|
258
|
-
case "Enter": {
|
|
259
|
-
const itemCtx = highlighted$();
|
|
260
|
-
if (itemCtx) {
|
|
261
|
-
widget.api.toggleItem(itemCtx.item);
|
|
262
|
-
}
|
|
263
|
-
break;
|
|
264
|
-
}
|
|
265
|
-
case "Escape":
|
|
266
|
-
open$.set(false);
|
|
267
|
-
break;
|
|
268
|
-
default:
|
|
269
|
-
keyManaged = false;
|
|
270
|
-
}
|
|
271
|
-
if (keyManaged) {
|
|
272
|
-
preventDefault();
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}));
|
|
277
|
-
const badgeCloseButtonDirective = utils_directive.createAttributesDirective((itemContext$) => ({
|
|
278
|
-
events: {
|
|
279
|
-
click: (event) => {
|
|
280
|
-
onRemoveBadge(event, itemContext$().item);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}));
|
|
284
|
-
const widget = {
|
|
285
|
-
...utils_stores.stateStores({
|
|
286
|
-
id$,
|
|
287
|
-
visibleItems$,
|
|
288
|
-
highlighted$,
|
|
289
|
-
open$,
|
|
290
|
-
selectedContexts$,
|
|
291
|
-
filterText$,
|
|
292
|
-
placement$,
|
|
293
|
-
className$,
|
|
294
|
-
badgeClassName$,
|
|
295
|
-
ariaLabel$,
|
|
296
|
-
menuClassName$,
|
|
297
|
-
...stateProps
|
|
298
|
-
}),
|
|
299
|
-
patch,
|
|
300
|
-
api: {
|
|
301
|
-
clear() {
|
|
302
|
-
selected$.set([]);
|
|
303
|
-
},
|
|
304
|
-
select(item) {
|
|
305
|
-
widget.api.toggleItem(item, true);
|
|
306
|
-
},
|
|
307
|
-
unselect(item) {
|
|
308
|
-
widget.api.toggleItem(item, false);
|
|
309
|
-
},
|
|
310
|
-
toggleItem(item, selected) {
|
|
311
|
-
const itemIdFn = itemIdFn$();
|
|
312
|
-
const itemId = itemIdFn(item);
|
|
313
|
-
const selectedContextsMap = selectedContextsMap$();
|
|
314
|
-
const isInSelected = selectedContextsMap.has(itemId);
|
|
315
|
-
if (selected == null) {
|
|
316
|
-
selected = !isInSelected;
|
|
317
|
-
}
|
|
318
|
-
if (selected && !itemContexts$().has(itemId) || !selected && !isInSelected) {
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
selected$.update((selectedItems) => {
|
|
322
|
-
selectedItems = [...selectedItems];
|
|
323
|
-
if (selected && !isInSelected) {
|
|
324
|
-
selectedItems.push(item);
|
|
325
|
-
} else if (!selected && isInSelected) {
|
|
326
|
-
const index = selectedItems.findIndex((item2) => itemIdFn(item2) === itemId);
|
|
327
|
-
selectedItems.splice(index, 1);
|
|
328
|
-
}
|
|
329
|
-
onSelectedChange$()?.(selectedItems);
|
|
330
|
-
return selectedItems;
|
|
331
|
-
});
|
|
332
|
-
},
|
|
333
|
-
clearText() {
|
|
334
|
-
},
|
|
335
|
-
highlight(item) {
|
|
336
|
-
const index = visibleItems$().findIndex((itemCtx) => itemCtx.item === item);
|
|
337
|
-
highlightedIndex$.set(index === -1 ? void 0 : index);
|
|
338
|
-
},
|
|
339
|
-
highlightFirst() {
|
|
340
|
-
highlightedIndex$.set(0);
|
|
341
|
-
},
|
|
342
|
-
highlightPrevious() {
|
|
343
|
-
highlightedIndex$.update((highlightedIndex) => {
|
|
344
|
-
return highlightedIndex != null ? highlightedIndex - 1 : -1;
|
|
345
|
-
});
|
|
346
|
-
},
|
|
347
|
-
highlightNext() {
|
|
348
|
-
highlightedIndex$.update((highlightedIndex) => {
|
|
349
|
-
return highlightedIndex != null ? highlightedIndex + 1 : Infinity;
|
|
350
|
-
});
|
|
351
|
-
},
|
|
352
|
-
highlightLast() {
|
|
353
|
-
highlightedIndex$.set(-1);
|
|
354
|
-
},
|
|
355
|
-
open: () => widget.api.toggle(true),
|
|
356
|
-
close: () => widget.api.toggle(false),
|
|
357
|
-
toggle(isOpen) {
|
|
358
|
-
open$.update((value) => isOpen != null ? isOpen : !value);
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
directives: {
|
|
362
|
-
hasFocusDirective,
|
|
363
|
-
floatingDirective,
|
|
364
|
-
referenceDirective,
|
|
365
|
-
inputContainerDirective: utils_directive.mergeDirectives(utils_directive.bindDirective(navDirective, navManagerConfig$), inputContainerAttributesDirective),
|
|
366
|
-
badgeAttributesDirective,
|
|
367
|
-
menuAttributesDirective,
|
|
368
|
-
itemAttributesDirective,
|
|
369
|
-
inputDirective,
|
|
370
|
-
badgeCloseButtonDirective
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
return widget;
|
|
374
|
-
});
|
|
375
|
-
exports.createSelect = createSelect;
|
|
376
|
-
exports.getSelectDefaultConfig = getSelectDefaultConfig;
|