@agnos-ui/core 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/{accordion-D9AonDII.cjs → accordion-BNq8mApi.cjs} +16 -21
  2. package/{accordion-qJyqAAwZ.js → accordion-CYAFmYRn.js} +19 -24
  3. package/{alert-anMaigvi.js → alert-Cb9FhbFQ.js} +1 -1
  4. package/{collapse-CPXAHvle.js → collapse-Cg9s33tY.js} +2 -2
  5. package/{collapse-DVb_2jIl.cjs → collapse-yKsOxJlH.cjs} +1 -1
  6. package/{common-CCxNtFNM.js → common-DFyZvkII.js} +1 -1
  7. package/components/accordion/accordion.d.ts +18 -8
  8. package/components/accordion/index.cjs +1 -1
  9. package/components/accordion/index.js +3 -3
  10. package/components/alert/common.d.ts +2 -2
  11. package/components/alert/index.js +1 -1
  12. package/components/carousel/index.cjs +1 -1
  13. package/components/carousel/index.js +3 -3
  14. package/components/collapse/collapse.d.ts +3 -3
  15. package/components/collapse/index.cjs +1 -1
  16. package/components/collapse/index.js +1 -1
  17. package/components/drawer/drawer.d.ts +2 -2
  18. package/components/drawer/index.cjs +1 -1
  19. package/components/drawer/index.js +1 -1
  20. package/components/modal/index.cjs +1 -1
  21. package/components/modal/index.js +4 -4
  22. package/components/pagination/index.cjs +1 -1
  23. package/components/pagination/index.js +1 -1
  24. package/components/progressbar/index.cjs +1 -1
  25. package/components/progressbar/index.js +1 -1
  26. package/components/rating/index.cjs +1 -1
  27. package/components/rating/index.js +1 -1
  28. package/components/slider/index.cjs +1 -1
  29. package/components/slider/index.js +1 -1
  30. package/components/toast/index.cjs +1 -1
  31. package/components/toast/index.js +1 -1
  32. package/components/tree/index.cjs +1 -1
  33. package/components/tree/index.js +1 -1
  34. package/config.d.ts +0 -5
  35. package/{dom-R8VxJgdK.cjs → dom-BX4ImCTd.cjs} +7 -4
  36. package/{dom-iY0R3D7u.js → dom-Bb5ZCr_a.js} +30 -27
  37. package/{drawer-CVoNTDrc.js → drawer-CYtNS8c1.js} +8 -5
  38. package/{drawer-77u4kG4M.cjs → drawer-DoaLRui_.cjs} +5 -2
  39. package/index.cjs +11 -14
  40. package/index.d.ts +0 -1
  41. package/index.js +55 -58
  42. package/{modal-ywc6mk_R.cjs → modal-CMeWLNO-.cjs} +1 -1
  43. package/{modal-CJVVF65o.js → modal-EHJERSIp.js} +6 -6
  44. package/package.json +1 -1
  45. package/{pagination-D19l6t0x.js → pagination-BDKo2d3i.js} +2 -2
  46. package/{pagination-CRMoSXs3.cjs → pagination-Ddk3z56A.cjs} +1 -1
  47. package/{progressbar-r0zha1kn.js → progressbar-BFdAfV5g.js} +2 -2
  48. package/{progressbar-DeqZeuKP.cjs → progressbar-ysfDQD0Q.cjs} +1 -1
  49. package/{promise-Y53vc4Ia.js → promise-D-RZVPuv.js} +1 -1
  50. package/{rating-D5Usb5P6.js → rating-D04FQgtR.js} +2 -2
  51. package/{rating-DOPnxyms.cjs → rating-DO_fKNp3.cjs} +1 -1
  52. package/services/floatingUI.cjs +1 -1
  53. package/services/floatingUI.js +2 -2
  54. package/services/focusElement.cjs +1 -1
  55. package/services/focusElement.js +1 -1
  56. package/services/focustrack.cjs +1 -1
  57. package/services/focustrack.js +1 -1
  58. package/services/matchMedia.cjs +1 -1
  59. package/services/matchMedia.js +1 -1
  60. package/services/navManager.cjs +5 -5
  61. package/services/navManager.js +2 -2
  62. package/services/pointerdownPosition.cjs +1 -1
  63. package/services/pointerdownPosition.js +1 -1
  64. package/services/portal.cjs +1 -1
  65. package/services/portal.js +1 -1
  66. package/services/resizeObserver.cjs +1 -1
  67. package/services/resizeObserver.js +1 -1
  68. package/services/siblingsInert.cjs +1 -1
  69. package/services/siblingsInert.js +1 -1
  70. package/services/transitions/baseTransitions.cjs +1 -1
  71. package/services/transitions/baseTransitions.js +3 -3
  72. package/services/transitions/collapse.cjs +1 -1
  73. package/services/transitions/collapse.js +1 -1
  74. package/services/transitions/cssTransitions.cjs +1 -1
  75. package/services/transitions/cssTransitions.js +2 -2
  76. package/services/transitions/simpleClassTransition.cjs +1 -1
  77. package/services/transitions/simpleClassTransition.js +1 -1
  78. package/{slider--fcvBfF0.js → slider-BPQIKRKL.js} +3 -3
  79. package/{slider-CJIW2sDq.cjs → slider-BRktp0--.cjs} +1 -1
  80. package/textDirection-cNgt24LJ.js +4 -0
  81. package/textDirection-zqcZ5-eK.cjs +3 -0
  82. package/{toaster-BjBdgZGB.cjs → toaster-Kq-cZoiD.cjs} +1 -1
  83. package/{toaster-D1b7QvRg.js → toaster-y_hXuh4o.js} +3 -3
  84. package/{tree-CUtbJPZT.js → tree-AM_J23Hz.js} +2 -2
  85. package/{tree-Pj-WcKId.cjs → tree-BAE89Xjn.cjs} +1 -1
  86. package/utils/directive.cjs +1 -1
  87. package/utils/directive.js +19 -19
  88. package/utils/stores.cjs +5 -2
  89. package/utils/stores.js +6 -3
  90. package/utils/writables.js +11 -11
  91. package/{writables-Is1bF1Vt.js → writables-DYGjj5T3.js} +10 -10
  92. package/components/select/index.cjs +0 -5
  93. package/components/select/index.d.ts +0 -1
  94. package/components/select/index.js +0 -5
  95. package/components/select/select.d.ts +0 -311
  96. package/select-BLA3Onle.js +0 -377
  97. package/select-Dx3GWZPt.cjs +0 -376
@@ -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 {};
@@ -1,377 +0,0 @@
1
- import { computed, writable, asWritable, readable, batch } from "@amadeus-it-group/tansu";
2
- import { offset, autoPlacement, size } from "@floating-ui/dom";
3
- import { createFloatingUI } from "./services/floatingUI.js";
4
- import { createHasFocus } from "./services/focustrack.js";
5
- import { createNavManager } from "./services/navManager.js";
6
- import { w as generateId, o as mergeDirectives, q as createAttributesDirective, a as bindDirective } from "./dom-iY0R3D7u.js";
7
- import { noop } from "./utils/func.js";
8
- import { writablesForProps, bindableProp, bindableDerived, stateStores, true$ } from "./utils/stores.js";
9
- import { createWidgetFactory } from "./utils/widget.js";
10
- const defaultConfig = {
11
- id: void 0,
12
- ariaLabel: "Select",
13
- open: false,
14
- disabled: false,
15
- items: [],
16
- filterText: "",
17
- loading: false,
18
- selected: [],
19
- navSelector: (node) => node.querySelectorAll(".au-select-badge,input"),
20
- itemIdFn: (item) => "" + item,
21
- onOpenChange: noop,
22
- onFilterTextChange: noop,
23
- onSelectedChange: noop,
24
- allowedPlacements: ["bottom-start", "top-start", "bottom-end", "top-end"],
25
- className: "",
26
- menuClassName: "",
27
- menuItemClassName: "",
28
- badgeClassName: ""
29
- };
30
- function getSelectDefaultConfig() {
31
- return { ...defaultConfig };
32
- }
33
- const createSelect = createWidgetFactory("select", (config) => {
34
- const [
35
- {
36
- id$: _dirtyId$,
37
- open$: _dirtyOpen$,
38
- filterText$: _dirtyFilterText$,
39
- items$,
40
- itemIdFn$,
41
- onOpenChange$,
42
- onFilterTextChange$,
43
- onSelectedChange$,
44
- allowedPlacements$,
45
- navSelector$,
46
- className$,
47
- badgeClassName$,
48
- ariaLabel$,
49
- menuClassName$,
50
- ...stateProps
51
- },
52
- patch
53
- ] = writablesForProps(defaultConfig, config);
54
- const { selected$ } = stateProps;
55
- const id$ = computed(() => _dirtyId$() ?? generateId());
56
- const filterText$ = bindableProp(_dirtyFilterText$, onFilterTextChange$);
57
- const { hasFocus$, directive: hasFocusDirective } = createHasFocus();
58
- const open$ = bindableDerived(onOpenChange$, [_dirtyOpen$, hasFocus$], ([_dirtyOpen, hasFocus]) => _dirtyOpen && hasFocus);
59
- const selectedContextsMap$ = computed(() => {
60
- const selectedItemsContext = /* @__PURE__ */ new Map();
61
- const itemIdFn = itemIdFn$();
62
- for (const item of selected$()) {
63
- const id = itemIdFn(item);
64
- selectedItemsContext.set(id, {
65
- item,
66
- id: itemIdFn(item),
67
- selected: true
68
- });
69
- }
70
- return selectedItemsContext;
71
- });
72
- const selectedContexts$ = computed(() => [...selectedContextsMap$().values()]);
73
- const highlightedIndex$ = (function() {
74
- const store = writable(0);
75
- return asWritable(store, (index) => {
76
- const { length } = visibleItems$();
77
- if (index != void 0) {
78
- if (!length) {
79
- index = void 0;
80
- } else if (index < 0) {
81
- index = length - 1;
82
- } else if (index >= length) {
83
- index = 0;
84
- }
85
- }
86
- store.set(index);
87
- });
88
- })();
89
- const itemContexts$ = computed(() => {
90
- const itemContexts = /* @__PURE__ */ new Map();
91
- if (open$()) {
92
- const selectedContextsMap = selectedContextsMap$();
93
- const itemIdFn = itemIdFn$();
94
- for (const item of items$()) {
95
- const id = itemIdFn(item);
96
- itemContexts.set(id, {
97
- item,
98
- id,
99
- selected: selectedContextsMap.has(id)
100
- });
101
- }
102
- }
103
- return itemContexts;
104
- });
105
- const visibleItems$ = computed(() => open$() ? [...itemContexts$().values()] : []);
106
- const highlighted$ = computed(() => {
107
- const visibleItems = visibleItems$();
108
- const highlightedIndex = highlightedIndex$();
109
- return visibleItems.length && highlightedIndex != void 0 ? visibleItems[highlightedIndex] : void 0;
110
- });
111
- const {
112
- directives: { floatingDirective, referenceDirective },
113
- stores: { placement$ }
114
- } = createFloatingUI({
115
- props: {
116
- computePositionOptions: asWritable(
117
- computed(() => ({
118
- middleware: [
119
- offset(5),
120
- autoPlacement({
121
- allowedPlacements: allowedPlacements$()
122
- }),
123
- size()
124
- ]
125
- }))
126
- )
127
- }
128
- });
129
- const { directive: navDirective, refreshElements, focusFirst, focusLast, focusLeft, focusRight } = createNavManager();
130
- const navManagerConfig$ = computed(
131
- () => ({
132
- keys: {
133
- Home: focusFirst,
134
- End: focusLast,
135
- ArrowLeft: focusLeft,
136
- ArrowRight: focusRight
137
- },
138
- selector: navSelector$()
139
- })
140
- );
141
- const onRemoveBadge = (event, item) => {
142
- const referenceElement = event.target;
143
- refreshElements();
144
- widget.api.unselect(item);
145
- if (referenceElement instanceof HTMLElement) {
146
- setTimeout(() => {
147
- if (!focusLeft({ event, referenceElement })) {
148
- focusRight({ event, referenceElement });
149
- }
150
- });
151
- }
152
- event.preventDefault();
153
- };
154
- const inputContainerAttributesDirective = createAttributesDirective(() => ({
155
- attributes: {
156
- role: readable("combobox"),
157
- "aria-haspopup": readable("listbox"),
158
- "aria-expanded": computed(() => `${open$()}`),
159
- "aria-controls": computed(() => `${id$()}-menu`)
160
- }
161
- }));
162
- const badgeAttributesDirective = createAttributesDirective((itemContext$) => ({
163
- attributes: {
164
- tabindex: readable(-1),
165
- class: badgeClassName$
166
- },
167
- classNames: {
168
- "au-select-badge": true$
169
- },
170
- events: {
171
- keydown: (event) => {
172
- let keyManaged = false;
173
- switch (event.key) {
174
- case "Backspace":
175
- case "Delete": {
176
- onRemoveBadge(event, itemContext$().item);
177
- keyManaged = true;
178
- break;
179
- }
180
- }
181
- if (keyManaged) {
182
- event.preventDefault();
183
- }
184
- }
185
- }
186
- }));
187
- const menuAttributesDirective = createAttributesDirective(() => ({
188
- attributes: {
189
- role: readable("listbox"),
190
- id: computed(() => `${id$()}-menu`),
191
- "data-popper-placement": placement$,
192
- class: menuClassName$
193
- },
194
- events: {
195
- mousedown: (e) => e.preventDefault()
196
- }
197
- }));
198
- const itemAttributesDirective = createAttributesDirective((itemContext$) => ({
199
- attributes: {
200
- role: readable("option"),
201
- "aria-selected": computed(() => `${itemContext$().selected}`),
202
- style: readable("cursor: pointer")
203
- },
204
- classNames: {
205
- "au-select-item": true$,
206
- selected: computed(() => itemContext$().selected)
207
- },
208
- events: {
209
- click: () => widget.api.toggleItem(itemContext$().item)
210
- }
211
- }));
212
- const inputDirective = createAttributesDirective(() => ({
213
- attributes: {
214
- id: id$,
215
- type: readable("text"),
216
- "aria-label": ariaLabel$,
217
- "aria-autocomplete": readable("list"),
218
- autocorrect: readable("off"),
219
- autocapitalize: readable("none"),
220
- autocomplete: readable("off")
221
- },
222
- classNames: {
223
- "au-select-input": true$
224
- },
225
- events: {
226
- input: (event) => {
227
- const value = event.target.value;
228
- batch(() => {
229
- open$.set(value != null && value !== "");
230
- filterText$.set(value);
231
- });
232
- },
233
- keydown: ({ ctrlKey, key, preventDefault }) => {
234
- let keyManaged = true;
235
- switch (key) {
236
- case "ArrowDown": {
237
- const isOpen = open$();
238
- if (isOpen) {
239
- if (ctrlKey) {
240
- widget.api.highlightLast();
241
- } else {
242
- widget.api.highlightNext();
243
- }
244
- } else {
245
- widget.api.open();
246
- widget.api.highlightFirst();
247
- }
248
- break;
249
- }
250
- case "ArrowUp":
251
- if (ctrlKey) {
252
- widget.api.highlightFirst();
253
- } else {
254
- widget.api.highlightPrevious();
255
- }
256
- break;
257
- case "Enter": {
258
- const itemCtx = highlighted$();
259
- if (itemCtx) {
260
- widget.api.toggleItem(itemCtx.item);
261
- }
262
- break;
263
- }
264
- case "Escape":
265
- open$.set(false);
266
- break;
267
- default:
268
- keyManaged = false;
269
- }
270
- if (keyManaged) {
271
- preventDefault();
272
- }
273
- }
274
- }
275
- }));
276
- const badgeCloseButtonDirective = createAttributesDirective((itemContext$) => ({
277
- events: {
278
- click: (event) => {
279
- onRemoveBadge(event, itemContext$().item);
280
- }
281
- }
282
- }));
283
- const widget = {
284
- ...stateStores({
285
- id$,
286
- visibleItems$,
287
- highlighted$,
288
- open$,
289
- selectedContexts$,
290
- filterText$,
291
- placement$,
292
- className$,
293
- badgeClassName$,
294
- ariaLabel$,
295
- menuClassName$,
296
- ...stateProps
297
- }),
298
- patch,
299
- api: {
300
- clear() {
301
- selected$.set([]);
302
- },
303
- select(item) {
304
- widget.api.toggleItem(item, true);
305
- },
306
- unselect(item) {
307
- widget.api.toggleItem(item, false);
308
- },
309
- toggleItem(item, selected) {
310
- const itemIdFn = itemIdFn$();
311
- const itemId = itemIdFn(item);
312
- const selectedContextsMap = selectedContextsMap$();
313
- const isInSelected = selectedContextsMap.has(itemId);
314
- if (selected == null) {
315
- selected = !isInSelected;
316
- }
317
- if (selected && !itemContexts$().has(itemId) || !selected && !isInSelected) {
318
- return;
319
- }
320
- selected$.update((selectedItems) => {
321
- selectedItems = [...selectedItems];
322
- if (selected && !isInSelected) {
323
- selectedItems.push(item);
324
- } else if (!selected && isInSelected) {
325
- const index = selectedItems.findIndex((item2) => itemIdFn(item2) === itemId);
326
- selectedItems.splice(index, 1);
327
- }
328
- onSelectedChange$()?.(selectedItems);
329
- return selectedItems;
330
- });
331
- },
332
- clearText() {
333
- },
334
- highlight(item) {
335
- const index = visibleItems$().findIndex((itemCtx) => itemCtx.item === item);
336
- highlightedIndex$.set(index === -1 ? void 0 : index);
337
- },
338
- highlightFirst() {
339
- highlightedIndex$.set(0);
340
- },
341
- highlightPrevious() {
342
- highlightedIndex$.update((highlightedIndex) => {
343
- return highlightedIndex != null ? highlightedIndex - 1 : -1;
344
- });
345
- },
346
- highlightNext() {
347
- highlightedIndex$.update((highlightedIndex) => {
348
- return highlightedIndex != null ? highlightedIndex + 1 : Infinity;
349
- });
350
- },
351
- highlightLast() {
352
- highlightedIndex$.set(-1);
353
- },
354
- open: () => widget.api.toggle(true),
355
- close: () => widget.api.toggle(false),
356
- toggle(isOpen) {
357
- open$.update((value) => isOpen != null ? isOpen : !value);
358
- }
359
- },
360
- directives: {
361
- hasFocusDirective,
362
- floatingDirective,
363
- referenceDirective,
364
- inputContainerDirective: mergeDirectives(bindDirective(navDirective, navManagerConfig$), inputContainerAttributesDirective),
365
- badgeAttributesDirective,
366
- menuAttributesDirective,
367
- itemAttributesDirective,
368
- inputDirective,
369
- badgeCloseButtonDirective
370
- }
371
- };
372
- return widget;
373
- });
374
- export {
375
- createSelect as c,
376
- getSelectDefaultConfig as g
377
- };