@aquera/nile-elements 1.7.1 → 1.7.3

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 (88) hide show
  1. package/README.md +7 -0
  2. package/dist/index.cjs.js +1 -1
  3. package/dist/index.esm.js +1 -1
  4. package/dist/index.js +1524 -419
  5. package/dist/nile-breadcrumb-item/nile-breadcrumb-item.cjs.js +1 -1
  6. package/dist/nile-breadcrumb-item/nile-breadcrumb-item.cjs.js.map +1 -1
  7. package/dist/nile-breadcrumb-item/nile-breadcrumb-item.esm.js +8 -6
  8. package/dist/nile-combobox/group-utils.cjs.js +2 -0
  9. package/dist/nile-combobox/group-utils.cjs.js.map +1 -0
  10. package/dist/nile-combobox/group-utils.esm.js +1 -0
  11. package/dist/nile-combobox/index.cjs.js +2 -0
  12. package/dist/nile-combobox/index.cjs.js.map +1 -0
  13. package/dist/nile-combobox/index.esm.js +1 -0
  14. package/dist/nile-combobox/nile-combobox.cjs.js +2 -0
  15. package/dist/nile-combobox/nile-combobox.cjs.js.map +1 -0
  16. package/dist/nile-combobox/nile-combobox.css.cjs.js +2 -0
  17. package/dist/nile-combobox/nile-combobox.css.cjs.js.map +1 -0
  18. package/dist/nile-combobox/nile-combobox.css.esm.js +715 -0
  19. package/dist/nile-combobox/nile-combobox.esm.js +238 -0
  20. package/dist/nile-combobox/portal-manager.cjs.js +2 -0
  21. package/dist/nile-combobox/portal-manager.cjs.js.map +1 -0
  22. package/dist/nile-combobox/portal-manager.esm.js +1 -0
  23. package/dist/nile-combobox/renderer.cjs.js +2 -0
  24. package/dist/nile-combobox/renderer.cjs.js.map +1 -0
  25. package/dist/nile-combobox/renderer.esm.js +147 -0
  26. package/dist/nile-combobox/search-manager.cjs.js +2 -0
  27. package/dist/nile-combobox/search-manager.cjs.js.map +1 -0
  28. package/dist/nile-combobox/search-manager.esm.js +1 -0
  29. package/dist/nile-combobox/selection-manager.cjs.js +2 -0
  30. package/dist/nile-combobox/selection-manager.cjs.js.map +1 -0
  31. package/dist/nile-combobox/selection-manager.esm.js +1 -0
  32. package/dist/nile-combobox/types.cjs.js +2 -0
  33. package/dist/nile-combobox/types.cjs.js.map +1 -0
  34. package/dist/nile-combobox/types.esm.js +1 -0
  35. package/dist/src/index.d.ts +1 -0
  36. package/dist/src/index.js +1 -0
  37. package/dist/src/index.js.map +1 -1
  38. package/dist/src/nile-breadcrumb-item/nile-breadcrumb-item.js +4 -2
  39. package/dist/src/nile-breadcrumb-item/nile-breadcrumb-item.js.map +1 -1
  40. package/dist/src/nile-combobox/group-utils.d.ts +26 -0
  41. package/dist/src/nile-combobox/group-utils.js +140 -0
  42. package/dist/src/nile-combobox/group-utils.js.map +1 -0
  43. package/dist/src/nile-combobox/index.d.ts +1 -0
  44. package/dist/src/nile-combobox/index.js +2 -0
  45. package/dist/src/nile-combobox/index.js.map +1 -0
  46. package/dist/src/nile-combobox/nile-combobox.css.d.ts +9 -0
  47. package/dist/src/nile-combobox/nile-combobox.css.js +724 -0
  48. package/dist/src/nile-combobox/nile-combobox.css.js.map +1 -0
  49. package/dist/src/nile-combobox/nile-combobox.d.ts +320 -0
  50. package/dist/src/nile-combobox/nile-combobox.js +1739 -0
  51. package/dist/src/nile-combobox/nile-combobox.js.map +1 -0
  52. package/dist/src/nile-combobox/nile-combobox.test.d.ts +1 -0
  53. package/dist/src/nile-combobox/nile-combobox.test.js +551 -0
  54. package/dist/src/nile-combobox/nile-combobox.test.js.map +1 -0
  55. package/dist/src/nile-combobox/portal-manager.d.ts +26 -0
  56. package/dist/src/nile-combobox/portal-manager.js +218 -0
  57. package/dist/src/nile-combobox/portal-manager.js.map +1 -0
  58. package/dist/src/nile-combobox/renderer.d.ts +24 -0
  59. package/dist/src/nile-combobox/renderer.js +279 -0
  60. package/dist/src/nile-combobox/renderer.js.map +1 -0
  61. package/dist/src/nile-combobox/search-manager.d.ts +15 -0
  62. package/dist/src/nile-combobox/search-manager.js +41 -0
  63. package/dist/src/nile-combobox/search-manager.js.map +1 -0
  64. package/dist/src/nile-combobox/selection-manager.d.ts +12 -0
  65. package/dist/src/nile-combobox/selection-manager.js +44 -0
  66. package/dist/src/nile-combobox/selection-manager.js.map +1 -0
  67. package/dist/src/nile-combobox/types.d.ts +53 -0
  68. package/dist/src/nile-combobox/types.js +8 -0
  69. package/dist/src/nile-combobox/types.js.map +1 -0
  70. package/dist/src/version.js +1 -1
  71. package/dist/src/version.js.map +1 -1
  72. package/dist/tsconfig.tsbuildinfo +1 -1
  73. package/package.json +3 -1
  74. package/src/index.ts +1 -0
  75. package/src/nile-breadcrumb-item/nile-breadcrumb-item.ts +4 -2
  76. package/src/nile-combobox/group-utils.ts +157 -0
  77. package/src/nile-combobox/index.ts +1 -0
  78. package/src/nile-combobox/nile-combobox.css.ts +726 -0
  79. package/src/nile-combobox/nile-combobox.test.ts +704 -0
  80. package/src/nile-combobox/nile-combobox.ts +1816 -0
  81. package/src/nile-combobox/portal-manager.ts +263 -0
  82. package/src/nile-combobox/renderer.ts +466 -0
  83. package/src/nile-combobox/search-manager.ts +53 -0
  84. package/src/nile-combobox/selection-manager.ts +57 -0
  85. package/src/nile-combobox/types.ts +63 -0
  86. package/vscode-html-custom-data.json +311 -4
  87. package/web-dev-server.config.mjs +9 -0
  88. package/web-test-runner.config.mjs +11 -0
@@ -0,0 +1,1739 @@
1
+ /**
2
+ * Copyright Aquera Inc 2025
3
+ *
4
+ * This source code is licensed under the BSD-3-Clause license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { __decorate } from "tslib";
8
+ import { html } from 'lit';
9
+ import { customElement, property, query, state } from 'lit/decorators.js';
10
+ import { classMap } from 'lit/directives/class-map.js';
11
+ import { ifDefined } from 'lit/directives/if-defined.js';
12
+ import { createRef, ref } from 'lit/directives/ref.js';
13
+ import { styles } from './nile-combobox.css';
14
+ import '../nile-icon';
15
+ import '../nile-popup/nile-popup';
16
+ import '../nile-tag/nile-tag';
17
+ import '../nile-option/nile-option';
18
+ import '../nile-checkbox/nile-checkbox';
19
+ import '../nile-loader/nile-loader';
20
+ import { animateTo, stopAnimations } from '../internal/animate';
21
+ import { defaultValue } from '../internal/default-value';
22
+ import { FormControlController } from '../internal/form';
23
+ import { getAnimation, setDefaultAnimation } from '../utilities/animation-registry';
24
+ import { HasSlotController } from '../internal/slot';
25
+ import { waitForEvent } from '../internal/event';
26
+ import { watch } from '../internal/watch';
27
+ import NileElement from '../internal/nile-element';
28
+ import { VirtualizerController } from '@tanstack/lit-virtual';
29
+ import { ComboboxSelectionManager } from './selection-manager.js';
30
+ import { ComboboxSearchManager } from './search-manager.js';
31
+ import { ComboboxRenderer } from './renderer.js';
32
+ import { ComboboxPortalManager } from './portal-manager.js';
33
+ import { hasGroups, flattenRows, filterRows, getOptionRows } from './group-utils.js';
34
+ import { VisibilityManager } from '../utilities/visibility-manager.js';
35
+ /**
36
+ * @summary A data-driven combobox with virtualized options, inline search, multi-select tags,
37
+ * custom value creation, and full WAI-ARIA Combobox keyboard navigation.
38
+ *
39
+ * @tag nile-combobox
40
+ * @status stable
41
+ * @since 2.0
42
+ *
43
+ * @dependency nile-icon
44
+ * @dependency nile-popup
45
+ * @dependency nile-tag
46
+ * @dependency nile-checkbox
47
+ * @dependency nile-loader
48
+ *
49
+ * @slot label - The input's label.
50
+ * @slot prefix - Prepend a presentational icon or element before the input.
51
+ * @slot clear-icon - An icon to use in lieu of the default clear icon.
52
+ * @slot expand-icon - The icon to show when the control is expanded/collapsed.
53
+ * @slot help-text - Text that describes how to use the input.
54
+ * @slot footer - Custom footer content (overrides default footer in multi-select mode).
55
+ * @slot no-results - Custom no-results content.
56
+ *
57
+ * @event nile-change - Emitted when the control's value changes.
58
+ * @event nile-clear - Emitted when the control's value is cleared.
59
+ * @event nile-input - Emitted when the control receives input.
60
+ * @event nile-focus - Emitted when the control gains focus.
61
+ * @event nile-blur - Emitted when the control loses focus.
62
+ * @event nile-show - Emitted when the dropdown opens.
63
+ * @event nile-after-show - Emitted after the dropdown opens and all animations complete.
64
+ * @event nile-hide - Emitted when the dropdown closes.
65
+ * @event nile-after-hide - Emitted after the dropdown closes and all animations complete.
66
+ * @event nile-search - Emitted (debounced) when the user types. Useful for API-driven filtering.
67
+ * @event nile-tag-remove - Emitted when a tag is removed in multi-select mode.
68
+ * @event nile-tag-add - Emitted when a custom value is added via allowCustomValue.
69
+ * @event nile-scroll-end - Emitted when scrolled to the bottom (for infinite loading).
70
+ * @event nile-invalid - Emitted when form validation constraints aren't satisfied.
71
+ * @event nile-select-all - Emitted when the Select all / Deselect all control toggles. Detail: { value, name, action: 'select-all' | 'deselect-all' }.
72
+ *
73
+ * @csspart form-control - The form control wrapper.
74
+ * @csspart form-control-label - The label wrapper.
75
+ * @csspart form-control-input - The input area wrapper.
76
+ * @csspart combobox - The combobox trigger (input + tags + icons).
77
+ * @csspart input - The text input element.
78
+ * @csspart listbox - The dropdown listbox.
79
+ * @csspart tags - The tags container in multi-select mode.
80
+ * @csspart tag - Each individual tag.
81
+ * @csspart clear-button - The clear button.
82
+ * @csspart expand-icon - The expand/collapse icon.
83
+ * @csspart top-actions - The sticky row above the option list that contains the Select all checkbox and the Selected / Show all filter toggle. Rendered only when multiple && selectAllEnabled.
84
+ * @csspart select-all - The Select all / Deselect all checkbox wrapper inside top-actions.
85
+ * @csspart show-toggle - The "Selected / Show all" filter button inside top-actions.
86
+ * @csspart no-results - The empty-state container shown when a search/filter returns no items. Contains no-results-title and no-results-subtitle.
87
+ * @csspart no-results-title - The title row of the no-results empty state.
88
+ * @csspart no-results-subtitle - The subtitle row of the no-results empty state.
89
+ * @csspart no-data - The empty-state container shown when the dataset is empty (no active search/filter).
90
+ * @csspart footer - The footer with "Show Selected" / "Clear All".
91
+ * @csspart no-results - The no-results message.
92
+ */
93
+ let NileCombobox = class NileCombobox extends NileElement {
94
+ constructor() {
95
+ super(...arguments);
96
+ this.formControlController = new FormControlController(this, {
97
+ assumeInteractionOn: ['nile-blur', 'nile-input'],
98
+ });
99
+ this.hasSlotController = new HasSlotController(this, 'help-text', 'label');
100
+ this.portalManager = new ComboboxPortalManager(this);
101
+ this.searchManager = new ComboboxSearchManager();
102
+ this.scrollElementRef = createRef();
103
+ this.virtualizerCtrl = new VirtualizerController(this, {
104
+ getScrollElement: () => this.scrollElementRef.value ?? null,
105
+ count: 0,
106
+ estimateSize: () => 38,
107
+ overscan: 5,
108
+ });
109
+ this.hScrollElementRef = createRef();
110
+ this.hVirtualizerCtrl = new VirtualizerController(this, {
111
+ getScrollElement: () => this.hScrollElementRef.value ?? null,
112
+ count: 0,
113
+ estimateSize: () => 160,
114
+ horizontal: true,
115
+ overscan: 3,
116
+ });
117
+ this.scrolling = false;
118
+ this.keyboardActiveIndex = -1;
119
+ this.hasFocus = false;
120
+ this.displayLabel = '';
121
+ this.selectedOptions = [];
122
+ /** The items displayed after filtering. Renderer reads from this. */
123
+ this.filteredData = [];
124
+ /**
125
+ * Mixed (header + option) row list, only populated when `data` contains
126
+ * group entries (`type: 'group'`). When non-empty, the listbox renders from
127
+ * this instead of `filteredData`. `filteredData` stays in sync as the
128
+ * option-only projection so existing select-all / strict-match / etc. logic
129
+ * keeps working unchanged.
130
+ */
131
+ this.filteredRows = [];
132
+ /** The complete unfiltered dataset (preserved for re-filtering). */
133
+ this.originalData = [];
134
+ this.showNoResults = false;
135
+ this.showListbox = false;
136
+ this.searchValue = '';
137
+ this.showSelectedOnly = false;
138
+ this.selectAllChecked = false;
139
+ this.selectAllIndeterminate = false;
140
+ /**
141
+ * Index into `filteredRows` of the group header that should be pinned at
142
+ * the top of the (virtualized) listbox right now. -1 means none.
143
+ * Recomputed on scroll.
144
+ */
145
+ this.stickyHeaderIndex = -1;
146
+ // ── Public properties ──
147
+ this.name = '';
148
+ this.data = [];
149
+ this.value = '';
150
+ this.defaultValue = '';
151
+ this.size = 'medium';
152
+ this.placeholder = 'Type to search...';
153
+ this.multiple = false;
154
+ this.label = '';
155
+ this.required = false;
156
+ this.disabled = false;
157
+ this.open = false;
158
+ this.clearable = false;
159
+ this.loading = false;
160
+ this.optionsLoading = false;
161
+ /** When true, skip local filtering and rely solely on the `nile-search` event for API-driven results. */
162
+ this.disableLocalSearch = false;
163
+ /** When true, displays a "+ Add [value]" option for values not in the data. */
164
+ this.allowCustomValue = false;
165
+ /** When true, typing free text and pressing Enter/Tab adds it as a tag (like nile-chip's acceptUserInput). */
166
+ this.acceptUserInput = false;
167
+ /** When true, custom values added via allowCustomValue or acceptUserInput are also appended to the suggestions list. */
168
+ this.addToSuggestions = false;
169
+ /** When true, value must match an option. On blur, reverts to the last valid value if text doesn't match. */
170
+ this.strict = false;
171
+ /** Max tags visible before showing "+N more" (0 = no limit). */
172
+ this.maxTagsVisible = 3;
173
+ /** Controls how tags wrap in multi-select mode. */
174
+ this.tagLayout = 'single-line';
175
+ /**
176
+ * Show footer with "Show Selected" and "Clear All" in multi-select mode.
177
+ * Automatically suppressed when `selectAllEnabled` is true, since the top
178
+ * actions row already provides the same controls.
179
+ */
180
+ this.showFooter = true;
181
+ /**
182
+ * When true (and `multiple` is true), renders a "Select all" / "Deselect all"
183
+ * checkbox at the top of the listbox. Operates on the currently visible,
184
+ * non-disabled options (respects the active search filter).
185
+ */
186
+ this.selectAllEnabled = false;
187
+ /**
188
+ * When true (default), data-driven group headers stick to the top of the
189
+ * listbox while scrolling through that group's options (Atlassian-style).
190
+ * Works in both plain and virtualized rendering modes. Set to false for
191
+ * inline-only headers that scroll away with their options.
192
+ */
193
+ this.stickyGroupHeader = true;
194
+ this.portal = false;
195
+ this.hoist = false;
196
+ this.placement = 'bottom';
197
+ this.form = '';
198
+ this.helpText = '';
199
+ this.errorMessage = '';
200
+ this.warning = false;
201
+ this.error = false;
202
+ this.success = false;
203
+ this.filled = false;
204
+ this.pill = false;
205
+ this.noResultsMessage = 'No result found';
206
+ this.noResultsSubtitle = 'Clear search or change filter';
207
+ this.noDataMessage = 'No data available';
208
+ /**
209
+ * Pre-defined autocomplete suggestions. Accepts a JSON array string attribute
210
+ * or a JS array property (like nile-chip). When `addToSuggestions` is true,
211
+ * custom values added by the user are appended to this list and persisted.
212
+ */
213
+ this.autoCompleteOptions = [];
214
+ /** Debounce interval (ms) for the nile-search event. */
215
+ this.debounceMs = 300;
216
+ this.allowHtmlLabel = true;
217
+ this.enableVisibilityEffect = false;
218
+ this.enableTabClose = false;
219
+ this.noWidthSync = false;
220
+ /** Number of columns in the dropdown grid (vertical scroll). When > 1, options render in a multi-column grid layout. */
221
+ this.gridColumns = 1;
222
+ /** Number of visible rows in horizontal grid mode. When > 0, enables horizontal virtual scroll with columns scrolling left/right. */
223
+ this.gridRows = 0;
224
+ /** Width of each column in horizontal grid mode (px). */
225
+ this.gridColumnWidth = 160;
226
+ this.lastVirtualizerGrouped = false;
227
+ }
228
+ // ── Accessors ──
229
+ get validity() {
230
+ return this.valueInput?.validity;
231
+ }
232
+ get validationMessage() {
233
+ return this.valueInput?.validationMessage ?? '';
234
+ }
235
+ // ── Lifecycle ──
236
+ connectedCallback() {
237
+ super.connectedCallback();
238
+ this.open = false;
239
+ this.setupBoundHandlers();
240
+ this.emit('nile-init');
241
+ this.updateComplete.then(() => {
242
+ if (this.autoCompleteOptions.length > 0 && this.data.length === 0) {
243
+ this.data = [...this.autoCompleteOptions];
244
+ }
245
+ if (this.value && this.data.length > 0) {
246
+ this.syncSelection();
247
+ }
248
+ });
249
+ }
250
+ disconnectedCallback() {
251
+ this.removeOpenListeners();
252
+ this.visibilityManager?.cleanup();
253
+ this.searchManager.cancelDebounce();
254
+ if (this.scrollTimeout) {
255
+ clearTimeout(this.scrollTimeout);
256
+ this.scrollTimeout = undefined;
257
+ }
258
+ this.portalManager.cleanupPortal();
259
+ }
260
+ firstUpdated(_changed) {
261
+ this.visibilityManager = new VisibilityManager({
262
+ host: this,
263
+ target: this.combobox,
264
+ enableVisibilityEffect: this.enableVisibilityEffect,
265
+ enableTabClose: this.enableTabClose,
266
+ isOpen: () => this.open,
267
+ onAnchorOutOfView: () => {
268
+ this.hide();
269
+ this.emit('nile-visibility-change', { visible: false, reason: 'anchor-out-of-view', name: this.name });
270
+ },
271
+ onDocumentHidden: () => {
272
+ this.hide();
273
+ this.emit('nile-visibility-change', { visible: false, reason: 'document-hidden', name: this.name });
274
+ },
275
+ emit: (event, detail) => this.emit(`nile-${event}`, detail),
276
+ });
277
+ }
278
+ updated(changedProperties) {
279
+ if (changedProperties.has('value')) {
280
+ this.syncSelection();
281
+ }
282
+ this.updateVirtualizerCount();
283
+ }
284
+ get isHorizontalGrid() {
285
+ return this.gridRows > 0 && this.gridColumns <= 1;
286
+ }
287
+ /** True when the source data contains at least one group entry. */
288
+ get hasGroupedData() {
289
+ const base = this.originalData.length > 0 ? this.originalData : this.data;
290
+ return hasGroups(base);
291
+ }
292
+ /**
293
+ * Walk filteredRows and find the index of the deepest group header whose
294
+ * virtual position is at or above `scrollTop`. That's the header that
295
+ * should be pinned at the top of the listbox right now.
296
+ */
297
+ updateStickyHeader(scrollTop) {
298
+ if (!this.stickyGroupHeader || !this.hasGroupedData) {
299
+ if (this.stickyHeaderIndex !== -1)
300
+ this.stickyHeaderIndex = -1;
301
+ return;
302
+ }
303
+ let offset = 0;
304
+ let stuck = -1;
305
+ for (let i = 0; i < this.filteredRows.length; i++) {
306
+ const row = this.filteredRows[i];
307
+ const size = row.kind === 'header' ? 32 : 38;
308
+ if (offset > scrollTop)
309
+ break;
310
+ if (row.kind === 'header')
311
+ stuck = i;
312
+ offset += size;
313
+ }
314
+ if (stuck !== this.stickyHeaderIndex)
315
+ this.stickyHeaderIndex = stuck;
316
+ }
317
+ /** Recursively keep only options whose value is in `selectedSet`; drop empty groups. */
318
+ pruneTreeBySelection(items, selectedSet) {
319
+ const out = [];
320
+ for (const item of items) {
321
+ if (item && typeof item === 'object' && item.type === 'group' && Array.isArray(item.options)) {
322
+ const kept = this.pruneTreeBySelection(item.options, selectedSet);
323
+ if (kept.length > 0)
324
+ out.push({ ...item, options: kept });
325
+ }
326
+ else if (selectedSet.has(String(this.getItemValue(item)))) {
327
+ out.push(item);
328
+ }
329
+ }
330
+ return out;
331
+ }
332
+ get hasActiveFilter() {
333
+ return !!this.searchValue || this.showSelectedOnly;
334
+ }
335
+ renderEmptyState() {
336
+ if (this.hasActiveFilter) {
337
+ return ComboboxRenderer.renderNoResults(this.noResultsMessage, this.noResultsSubtitle);
338
+ }
339
+ return ComboboxRenderer.renderNoData(this.noDataMessage);
340
+ }
341
+ get isBidirectionalGrid() {
342
+ return this.gridRows > 0 && this.gridColumns > 1;
343
+ }
344
+ get virtualRowCount() {
345
+ if (this.gridColumns > 1) {
346
+ return Math.ceil(this.filteredData.length / this.gridColumns);
347
+ }
348
+ if (this.hasGroupedData) {
349
+ return this.filteredRows.length;
350
+ }
351
+ return this.filteredData.length;
352
+ }
353
+ get virtualColumnCount() {
354
+ return Math.ceil(this.filteredData.length / Math.max(this.gridRows, 1));
355
+ }
356
+ updateVirtualizerCount() {
357
+ if (this.isHorizontalGrid) {
358
+ const hVirtualizer = this.hVirtualizerCtrl.getVirtualizer();
359
+ const colCount = this.virtualColumnCount;
360
+ if (hVirtualizer.options.count !== colCount || hVirtualizer.options.estimateSize(0) !== this.gridColumnWidth) {
361
+ hVirtualizer.setOptions({
362
+ ...hVirtualizer.options,
363
+ count: colCount,
364
+ estimateSize: () => this.gridColumnWidth,
365
+ });
366
+ hVirtualizer.measure();
367
+ }
368
+ }
369
+ else {
370
+ const virtualizer = this.virtualizerCtrl.getVirtualizer();
371
+ const count = this.virtualRowCount;
372
+ const grouped = this.hasGroupedData;
373
+ const countChanged = virtualizer.options.count !== count;
374
+ const modeChanged = this.lastVirtualizerGrouped !== grouped;
375
+ if (countChanged || modeChanged) {
376
+ const estimateSize = grouped
377
+ ? (index) => (this.filteredRows[index]?.kind === 'header' ? 32 : 38)
378
+ : () => 38;
379
+ virtualizer.setOptions({
380
+ ...virtualizer.options,
381
+ count,
382
+ estimateSize,
383
+ });
384
+ virtualizer.measure();
385
+ this.lastVirtualizerGrouped = grouped;
386
+ }
387
+ }
388
+ }
389
+ // ── Data helpers ──
390
+ getDisplayText(item) {
391
+ if (this.renderItemConfig?.getDisplayText)
392
+ return this.renderItemConfig.getDisplayText(item);
393
+ return item?.label || item?.name || item?.toString?.() || '';
394
+ }
395
+ getItemValue(item) {
396
+ if (this.renderItemConfig?.getValue)
397
+ return this.renderItemConfig.getValue(item);
398
+ return item?.value ?? item;
399
+ }
400
+ getSearchText(item) {
401
+ if (this.renderItemConfig?.getSearchText)
402
+ return this.renderItemConfig.getSearchText(item);
403
+ return this.getDisplayText(item);
404
+ }
405
+ getItemDescription(item) {
406
+ return this.renderItemConfig?.getDescription?.(item) ?? item?.description ?? '';
407
+ }
408
+ getItemPrefix(item) {
409
+ return this.renderItemConfig?.getPrefix?.(item) ?? item?.prefix ?? '';
410
+ }
411
+ getItemSuffix(item) {
412
+ return this.renderItemConfig?.getSuffix?.(item) ?? item?.suffix ?? '';
413
+ }
414
+ // ── Selection ──
415
+ syncSelection() {
416
+ const baseData = this.originalData.length > 0 ? this.originalData : this.data;
417
+ const items = this.hasGroupedData
418
+ ? getOptionRows(flattenRows(baseData)).map(r => r.item)
419
+ : baseData;
420
+ this.selectedOptions = ComboboxSelectionManager.createOptionsFromValues(this.value, items, this.getDisplayText.bind(this), this.renderItemConfig?.getValue);
421
+ if (!this.multiple) {
422
+ const label = this.selectedOptions[0]?.getTextLabel() ?? '';
423
+ this.displayLabel = label;
424
+ if (label) {
425
+ this.searchValue = label;
426
+ }
427
+ else if (!this.hasFocus) {
428
+ this.searchValue = '';
429
+ }
430
+ }
431
+ else {
432
+ this.displayLabel = '';
433
+ }
434
+ this.updateValidity();
435
+ this.updateSelectAllState();
436
+ }
437
+ // ── Select All ──
438
+ /**
439
+ * Returns the options eligible for Select All — the currently filtered data
440
+ * (so the active search/filter is respected) minus any `disabled` items.
441
+ * Mirrors nile-select's `getSelectableOptions()` contract.
442
+ */
443
+ getSelectableData() {
444
+ return this.filteredData.filter((item) => !item?.disabled);
445
+ }
446
+ /**
447
+ * Derives `selectAllChecked` + `selectAllIndeterminate` from the current
448
+ * selection vs. the selectable set. No-op when `multiple` is false.
449
+ *
450
+ * options=0 → both false (nothing to select, e.g. empty search)
451
+ * selected=0 → checked=false, indeterminate=false
452
+ * selected=options → checked=true, indeterminate=false
453
+ * otherwise (partial) → checked=false, indeterminate=true
454
+ */
455
+ updateSelectAllState() {
456
+ if (!this.multiple) {
457
+ this.selectAllChecked = false;
458
+ this.selectAllIndeterminate = false;
459
+ return;
460
+ }
461
+ const options = this.getSelectableData();
462
+ if (options.length === 0) {
463
+ this.selectAllChecked = false;
464
+ this.selectAllIndeterminate = false;
465
+ return;
466
+ }
467
+ const selectedValues = Array.isArray(this.value) ? this.value : [];
468
+ const selectedSet = new Set(selectedValues.map(String));
469
+ const selectedInView = options.reduce((n, item) => {
470
+ return n + (selectedSet.has(String(this.getItemValue(item))) ? 1 : 0);
471
+ }, 0);
472
+ if (selectedInView === 0) {
473
+ this.selectAllChecked = false;
474
+ this.selectAllIndeterminate = false;
475
+ }
476
+ else if (selectedInView === options.length) {
477
+ this.selectAllChecked = true;
478
+ this.selectAllIndeterminate = false;
479
+ }
480
+ else {
481
+ this.selectAllChecked = false;
482
+ this.selectAllIndeterminate = true;
483
+ }
484
+ }
485
+ /**
486
+ * Toggles all selectable, visible options. Indeterminate → clears selection
487
+ * (matches the "Deselect All" label flip), empty → selects all,
488
+ * fully-selected → clears.
489
+ */
490
+ handleSelectAllToggle(event) {
491
+ event.stopPropagation();
492
+ event.preventDefault();
493
+ if (!this.multiple || !this.selectAllEnabled)
494
+ return;
495
+ const options = this.getSelectableData();
496
+ if (options.length === 0)
497
+ return;
498
+ const shouldUnselectAll = this.selectAllChecked || this.selectAllIndeterminate;
499
+ const current = Array.isArray(this.value) ? [...this.value] : [];
500
+ const inViewValues = options.map(item => String(this.getItemValue(item)));
501
+ const inViewSet = new Set(inViewValues);
502
+ let next;
503
+ if (shouldUnselectAll) {
504
+ // Deselect only the in-view options; preserve selections outside the filter.
505
+ next = current.filter(v => !inViewSet.has(String(v)));
506
+ }
507
+ else {
508
+ // Select all in-view options on top of any existing (out-of-view) selection.
509
+ const merged = new Set(current.map(String));
510
+ inViewValues.forEach(v => merged.add(v));
511
+ next = Array.from(merged);
512
+ }
513
+ this.value = next;
514
+ this.searchValue = '';
515
+ this.syncSelection();
516
+ this.filterOptions('', true);
517
+ this.updateComplete.then(() => {
518
+ this.emit('nile-input', { value: this.value, name: this.name });
519
+ this.emit('nile-change', { value: this.value, name: this.name });
520
+ this.emit('nile-select-all', {
521
+ value: this.value,
522
+ name: this.name,
523
+ action: shouldUnselectAll ? 'deselect-all' : 'select-all',
524
+ });
525
+ });
526
+ }
527
+ setupBoundHandlers() {
528
+ this.handleDocumentFocusIn = (event) => {
529
+ if (!this.open)
530
+ return;
531
+ const path = event.composedPath();
532
+ const hitSelf = path.includes(this);
533
+ const hitPopup = this.popup && path.includes(this.popup);
534
+ const hitPortal = this.portal && this.portalManager.portalContainerElement && path.includes(this.portalManager.portalContainerElement);
535
+ if (!hitSelf && !hitPopup && !hitPortal)
536
+ this.hide();
537
+ };
538
+ this.handleDocumentKeyDown = (event) => {
539
+ if (!this.open && event.key !== 'ArrowDown' && event.key !== 'ArrowUp' && event.key !== 'Enter')
540
+ return;
541
+ this.onGlobalKeyDown(event);
542
+ };
543
+ this.handleDocumentMouseDown = (event) => {
544
+ if (!this.open)
545
+ return;
546
+ const path = event.composedPath();
547
+ const hitSelf = path.includes(this);
548
+ const hitPopup = this.popup && path.includes(this.popup);
549
+ const hitPortal = this.portal && this.portalManager.portalContainerElement && path.includes(this.portalManager.portalContainerElement);
550
+ if (!hitSelf && !hitPopup && !hitPortal)
551
+ this.hide();
552
+ };
553
+ this.handleWindowError = (event) => {
554
+ const msg = event.error?.message || event.message || '';
555
+ if (msg.includes("Cannot read properties of null (reading 'insertBefore')")) {
556
+ event.preventDefault();
557
+ }
558
+ };
559
+ this.handleWindowResize = () => this.portalManager.updatePosition();
560
+ this.handleWindowScroll = () => this.portalManager.updatePosition();
561
+ }
562
+ addOpenListeners() {
563
+ document.addEventListener('focusin', this.handleDocumentFocusIn);
564
+ document.addEventListener('keydown', this.handleDocumentKeyDown);
565
+ document.addEventListener('mousedown', this.handleDocumentMouseDown);
566
+ window.addEventListener('error', this.handleWindowError);
567
+ if (this.portal) {
568
+ window.addEventListener('resize', this.handleWindowResize);
569
+ window.addEventListener('scroll', this.handleWindowScroll, true);
570
+ }
571
+ }
572
+ removeOpenListeners() {
573
+ document.removeEventListener('focusin', this.handleDocumentFocusIn);
574
+ document.removeEventListener('keydown', this.handleDocumentKeyDown);
575
+ document.removeEventListener('mousedown', this.handleDocumentMouseDown);
576
+ window.removeEventListener('error', this.handleWindowError);
577
+ window.removeEventListener('resize', this.handleWindowResize);
578
+ window.removeEventListener('scroll', this.handleWindowScroll, true);
579
+ }
580
+ // ── Keyboard navigation (WAI-ARIA Combobox) ──
581
+ onInputKeyDown(event) {
582
+ switch (event.key) {
583
+ case 'ArrowDown':
584
+ event.preventDefault();
585
+ if (!this.open) {
586
+ this.show();
587
+ }
588
+ else {
589
+ this.moveActiveOption(this.gridColumns > 1 ? this.gridColumns : 1);
590
+ }
591
+ break;
592
+ case 'ArrowUp':
593
+ event.preventDefault();
594
+ if (!this.open) {
595
+ this.show();
596
+ }
597
+ else {
598
+ this.moveActiveOption(this.gridColumns > 1 ? -this.gridColumns : -1);
599
+ }
600
+ break;
601
+ case 'ArrowRight':
602
+ if (this.gridColumns > 1 && this.open) {
603
+ event.preventDefault();
604
+ this.moveActiveOption(1);
605
+ }
606
+ break;
607
+ case 'ArrowLeft':
608
+ if (this.gridColumns > 1 && this.open) {
609
+ event.preventDefault();
610
+ this.moveActiveOption(-1);
611
+ }
612
+ break;
613
+ case 'Enter':
614
+ event.preventDefault();
615
+ if (this.open) {
616
+ this.selectActiveOption();
617
+ }
618
+ else if (this.searchValue.trim() && (this.acceptUserInput || this.allowCustomValue)) {
619
+ this.addCustomValue(this.searchValue.trim());
620
+ }
621
+ else {
622
+ this.show();
623
+ }
624
+ break;
625
+ case 'Escape':
626
+ if (this.open) {
627
+ event.preventDefault();
628
+ event.stopPropagation();
629
+ this.hide();
630
+ }
631
+ break;
632
+ case 'Home':
633
+ if (this.open) {
634
+ event.preventDefault();
635
+ this.setActiveOption(0);
636
+ }
637
+ break;
638
+ case 'End':
639
+ if (this.open) {
640
+ event.preventDefault();
641
+ this.setActiveOption(this.filteredData.length - 1);
642
+ }
643
+ break;
644
+ case 'Backspace':
645
+ if (this.multiple && this.searchValue === '' && this.selectedOptions.length > 0) {
646
+ const last = this.selectedOptions[this.selectedOptions.length - 1];
647
+ this.removeTag(last);
648
+ }
649
+ break;
650
+ case 'Tab':
651
+ if (this.multiple && this.acceptUserInput && this.searchValue.trim()) {
652
+ this.addCustomValue(this.searchValue.trim());
653
+ }
654
+ if (this.open)
655
+ this.hide();
656
+ break;
657
+ }
658
+ }
659
+ onGlobalKeyDown(event) {
660
+ if (event.key === 'Escape' && this.open) {
661
+ event.preventDefault();
662
+ event.stopPropagation();
663
+ this.hide();
664
+ this.inputElement?.focus({ preventScroll: true });
665
+ }
666
+ }
667
+ getVisibleOptions() {
668
+ const root = this.portal ? this.portalManager.portalContainerElement : this.shadowRoot;
669
+ if (!root)
670
+ return [];
671
+ return root.querySelectorAll('nile-option:not([disabled])');
672
+ }
673
+ moveActiveOption(delta) {
674
+ const options = this.getVisibleOptions();
675
+ if (!options.length)
676
+ return;
677
+ let next = this.keyboardActiveIndex + delta;
678
+ if (next < 0)
679
+ next = options.length - 1;
680
+ if (next >= options.length)
681
+ next = 0;
682
+ this.setActiveOption(next);
683
+ }
684
+ setActiveOption(index) {
685
+ const options = this.getVisibleOptions();
686
+ if (!options.length)
687
+ return;
688
+ options.forEach((opt, i) => {
689
+ const el = opt;
690
+ if (i === index) {
691
+ el.setAttribute('aria-current', 'true');
692
+ el.classList.add('combobox__option--active');
693
+ el.scrollIntoView?.({ block: 'nearest' });
694
+ }
695
+ else {
696
+ el.removeAttribute('aria-current');
697
+ el.classList.remove('combobox__option--active');
698
+ }
699
+ });
700
+ this.keyboardActiveIndex = index;
701
+ }
702
+ selectActiveOption() {
703
+ const options = this.getVisibleOptions();
704
+ if (this.keyboardActiveIndex >= 0 && this.keyboardActiveIndex < options.length) {
705
+ const opt = options[this.keyboardActiveIndex];
706
+ if (opt && !opt.disabled) {
707
+ this.handleOptionSelection(opt.value);
708
+ }
709
+ }
710
+ else if (this.searchValue.trim() && (this.allowCustomValue || this.acceptUserInput)) {
711
+ this.addCustomValue(this.searchValue.trim());
712
+ }
713
+ }
714
+ // ── Input handling ──
715
+ onInputChange(event) {
716
+ event.stopPropagation();
717
+ }
718
+ onInputHandler(event) {
719
+ const target = event.target;
720
+ this.searchValue = target.value;
721
+ if (!this.open)
722
+ this.show();
723
+ this.emit('nile-input', { value: this.searchValue, name: this.name });
724
+ if (this.disableLocalSearch) {
725
+ this.searchManager.debounceSearch((q) => this.emit('nile-search', { query: q, name: this.name }), this.searchValue, this.debounceMs);
726
+ }
727
+ else {
728
+ this.filterOptions(this.searchValue);
729
+ }
730
+ this.keyboardActiveIndex = -1;
731
+ }
732
+ filterOptions(search, preserveScroll = false) {
733
+ const baseData = this.originalData.length > 0 ? this.originalData : this.data;
734
+ if (this.hasGroupedData) {
735
+ // Grouped path: filter the tree, derive options-only projection.
736
+ let tree = baseData;
737
+ if (this.showSelectedOnly) {
738
+ const selectedValues = Array.isArray(this.value) ? this.value : [this.value];
739
+ const selectedSet = new Set(selectedValues.map(v => String(v)));
740
+ tree = this.pruneTreeBySelection(baseData, selectedSet);
741
+ }
742
+ const { rows } = filterRows(tree, search, this.getSearchText.bind(this));
743
+ this.filteredRows = rows;
744
+ this.filteredData = getOptionRows(rows).map(r => r.item);
745
+ this.showNoResults = this.filteredData.length === 0;
746
+ // Recompute sticky header at current scroll (defaults to top on filter).
747
+ const st = this.scrollElementRef.value?.scrollTop ?? 0;
748
+ this.updateStickyHeader(st);
749
+ }
750
+ else {
751
+ let source = baseData;
752
+ if (this.showSelectedOnly) {
753
+ const selectedValues = Array.isArray(this.value) ? this.value : [this.value];
754
+ const selectedSet = new Set(selectedValues.map(v => String(v)));
755
+ source = baseData.filter((item) => selectedSet.has(String(this.getItemValue(item))));
756
+ }
757
+ const { filteredItems, showNoResults } = this.searchManager.filter(search, source, this.getSearchText.bind(this));
758
+ this.filteredData = filteredItems;
759
+ this.filteredRows = [];
760
+ this.showNoResults = showNoResults;
761
+ }
762
+ this.portalManager.resetMeasuredHeight();
763
+ if (!preserveScroll) {
764
+ this.resetScrollPosition();
765
+ }
766
+ this.updateSelectAllState();
767
+ this.requestUpdate();
768
+ }
769
+ // ── Focus ──
770
+ onFocusIn() {
771
+ this.hasFocus = true;
772
+ this.emit('nile-focus');
773
+ if (!this.multiple && this.displayLabel) {
774
+ this.searchValue = this.displayLabel;
775
+ this.requestUpdate();
776
+ this.updateComplete.then(() => {
777
+ this.inputElement?.select();
778
+ });
779
+ }
780
+ }
781
+ onFocusOut() {
782
+ this.hasFocus = false;
783
+ this.emit('nile-blur');
784
+ if (this.open)
785
+ return;
786
+ if (!this.multiple) {
787
+ if (this.strict) {
788
+ const baseData = this.originalData.length > 0 ? this.originalData : this.data;
789
+ const allItems = this.hasGroupedData
790
+ ? getOptionRows(flattenRows(baseData)).map(r => r.item)
791
+ : baseData;
792
+ const match = allItems.find((item) => this.getDisplayText(item).toLowerCase() === this.searchValue.toLowerCase());
793
+ if (match) {
794
+ const val = this.getItemValue(match);
795
+ if (this.value !== val) {
796
+ this.value = val;
797
+ this.syncSelection();
798
+ this.emit('nile-change', { value: this.value, name: this.name });
799
+ }
800
+ }
801
+ else {
802
+ this.searchValue = this.displayLabel;
803
+ }
804
+ }
805
+ else {
806
+ this.searchValue = this.displayLabel;
807
+ }
808
+ }
809
+ }
810
+ // ── Combobox trigger interaction ──
811
+ onTriggerMouseDown(event) {
812
+ if (this.disabled)
813
+ return;
814
+ const path = event.composedPath();
815
+ if (path.some(el => el instanceof Element && el.tagName.toLowerCase() === 'nile-icon-button'))
816
+ return;
817
+ event.preventDefault();
818
+ this.inputElement?.focus({ preventScroll: true });
819
+ if (this.open) {
820
+ this.hide();
821
+ }
822
+ else {
823
+ this.show();
824
+ }
825
+ }
826
+ // ── Option click ──
827
+ onOptionClick(event) {
828
+ // Use composedPath to find nile-option across shadow boundaries
829
+ const path = event.composedPath();
830
+ const option = path.find((el) => el.tagName === 'NILE-OPTION');
831
+ if (!option || option.disabled)
832
+ return;
833
+ this.handleOptionSelection(option.value);
834
+ }
835
+ handleOptionSelection(optionValue) {
836
+ const oldValue = this.value;
837
+ if (this.multiple) {
838
+ const current = Array.isArray(this.value) ? this.value : [];
839
+ this.value = ComboboxSelectionManager.toggleMultiValue(current, optionValue);
840
+ this.searchValue = '';
841
+ this.syncSelection();
842
+ this.filterOptions('', true);
843
+ }
844
+ else {
845
+ this.value = optionValue;
846
+ this.syncSelection();
847
+ this.searchValue = this.displayLabel;
848
+ this.hide();
849
+ }
850
+ if (JSON.stringify(this.value) !== JSON.stringify(oldValue)) {
851
+ this.updateComplete.then(() => {
852
+ this.emit('nile-input', { value: this.value, name: this.name });
853
+ this.emit('nile-change', { value: this.value, name: this.name });
854
+ });
855
+ }
856
+ this.inputElement?.focus({ preventScroll: true });
857
+ }
858
+ addCustomValue(val) {
859
+ if (this.addToSuggestions) {
860
+ const allItems = this.originalData.length > 0 ? this.originalData : this.data;
861
+ const alreadyExists = allItems.some((item) => String(this.getItemValue(item)) === val || this.getDisplayText(item) === val);
862
+ if (!alreadyExists) {
863
+ const newItem = this.renderItemConfig?.getValue
864
+ ? { value: val, label: val }
865
+ : val;
866
+ this.originalData = [...allItems, newItem];
867
+ this.data = [...this.originalData];
868
+ this.autoCompleteOptions = [...this.originalData];
869
+ this.filteredData = [...this.originalData];
870
+ }
871
+ }
872
+ if (this.multiple) {
873
+ const current = Array.isArray(this.value) ? this.value : [];
874
+ if (!current.includes(val)) {
875
+ this.value = [...current, val];
876
+ }
877
+ }
878
+ else {
879
+ this.value = val;
880
+ this.hide();
881
+ }
882
+ this.searchValue = this.multiple ? '' : val;
883
+ this.syncSelection();
884
+ this.filterOptions(this.searchValue);
885
+ this.emit('nile-tag-add', { value: val, name: this.name });
886
+ this.emit('nile-change', { value: this.value, name: this.name });
887
+ }
888
+ // ── Clear ──
889
+ onClearClick(event) {
890
+ event.stopPropagation();
891
+ this.value = this.multiple ? [] : '';
892
+ this.searchValue = '';
893
+ this.syncSelection();
894
+ this.filterOptions('');
895
+ this.emit('nile-clear', { value: this.value, name: this.name });
896
+ this.emit('nile-change', { value: this.value, name: this.name });
897
+ }
898
+ // ── Tags ──
899
+ removeTag(option) {
900
+ if (this.disabled)
901
+ return;
902
+ const current = Array.isArray(this.value) ? this.value : [];
903
+ this.value = ComboboxSelectionManager.removeValue(current, option.value);
904
+ this.syncSelection();
905
+ this.emit('nile-tag-remove', { value: this.value, name: this.name, removedtagvalue: option.value });
906
+ this.emit('nile-change', { value: this.value, name: this.name });
907
+ }
908
+ // ── Footer ──
909
+ onFooterClick(event) {
910
+ event.stopPropagation();
911
+ event.preventDefault();
912
+ }
913
+ toggleShowSelected(event) {
914
+ event.stopPropagation();
915
+ event.preventDefault();
916
+ if (this.selectedOptions.length === 0)
917
+ return;
918
+ this.showSelectedOnly = !this.showSelectedOnly;
919
+ if (this.showSelectedOnly)
920
+ this.searchValue = '';
921
+ this.filterOptions(this.searchValue);
922
+ }
923
+ clearAll() {
924
+ this.showSelectedOnly = false;
925
+ this.value = this.multiple ? [] : '';
926
+ this.filterOptions('');
927
+ this.syncSelection();
928
+ this.emit('nile-change', { value: this.value, name: this.name });
929
+ this.emit('nile-clear', { value: this.value, name: this.name });
930
+ this.resetScrollPosition();
931
+ }
932
+ // ── Scroll ──
933
+ onScroll(e) {
934
+ const target = e.target;
935
+ this.updateStickyHeader(target.scrollTop);
936
+ if (this.showSelectedOnly)
937
+ return;
938
+ this.emit('nile-scroll', { scrollTop: target.scrollTop, scrollLeft: target.scrollLeft, name: this.name });
939
+ if (!this.scrolling) {
940
+ this.scrolling = true;
941
+ this.emit('nile-scroll-start', { scrollTop: target.scrollTop, scrollLeft: target.scrollLeft, name: this.name });
942
+ }
943
+ clearTimeout(this.scrollTimeout);
944
+ this.scrollTimeout = window.setTimeout(() => {
945
+ this.scrolling = false;
946
+ }, 300);
947
+ const isAtBottom = Math.ceil(target.scrollTop) >= Math.floor(target.scrollHeight - target.offsetHeight);
948
+ if (isAtBottom) {
949
+ this.emit('nile-scroll-end', { scrollTop: target.scrollTop, scrollLeft: target.scrollLeft, name: this.name, isAtBottom: true });
950
+ }
951
+ }
952
+ // ── Show / Hide ──
953
+ async show() {
954
+ if (this.open || this.disabled)
955
+ return undefined;
956
+ this.open = true;
957
+ return waitForEvent(this, 'nile-after-show');
958
+ }
959
+ async hide() {
960
+ if (!this.open)
961
+ return undefined;
962
+ this.open = false;
963
+ return waitForEvent(this, 'nile-after-hide');
964
+ }
965
+ async handleOpenChange() {
966
+ if (this.open && !this.disabled) {
967
+ this.visibilityManager?.setup();
968
+ this.showListbox = true;
969
+ await this.updateComplete;
970
+ await this.doOpen();
971
+ if (this.portal)
972
+ this.portalManager.setupPortal();
973
+ }
974
+ else {
975
+ this.visibilityManager?.cleanup();
976
+ await this.doClose();
977
+ this.showListbox = false;
978
+ if (this.portal)
979
+ this.portalManager.cleanupPortal();
980
+ }
981
+ }
982
+ async doOpen() {
983
+ this.emit('nile-show', { value: this.value, name: this.name });
984
+ this.addOpenListeners();
985
+ this.keyboardActiveIndex = -1;
986
+ if (this.originalData.length === 0 && this.data.length > 0) {
987
+ this.originalData = [...this.data];
988
+ }
989
+ if (this.hasGroupedData) {
990
+ this.filterOptions(this.searchValue);
991
+ }
992
+ else {
993
+ this.filteredData = [...(this.originalData.length > 0 ? this.originalData : this.data)];
994
+ this.filteredRows = [];
995
+ this.showNoResults = this.filteredData.length === 0;
996
+ }
997
+ await stopAnimations(this);
998
+ if (this.popup?.popup) {
999
+ this.popup.popup.style.visibility = 'hidden';
1000
+ }
1001
+ this.popup.active = true;
1002
+ await new Promise(r => requestAnimationFrame(r));
1003
+ await new Promise(r => requestAnimationFrame(r));
1004
+ if (this.popup?.popup) {
1005
+ this.popup.popup.style.visibility = '';
1006
+ }
1007
+ const { keyframes, options } = getAnimation(this, 'combobox.show', { dir: 'ltr' });
1008
+ await animateTo(this.popup.popup, keyframes, options);
1009
+ this.resetScrollPosition();
1010
+ this.emit('nile-after-show', { value: this.value, name: this.name });
1011
+ }
1012
+ async doClose() {
1013
+ this.emit('nile-hide', { value: this.value, name: this.name });
1014
+ this.removeOpenListeners();
1015
+ await stopAnimations(this);
1016
+ const { keyframes, options } = getAnimation(this, 'combobox.hide', { dir: 'ltr' });
1017
+ await animateTo(this.popup.popup, keyframes, options);
1018
+ this.popup.active = false;
1019
+ if (this.popup?.popup)
1020
+ this.popup.popup.style.visibility = '';
1021
+ this.showSelectedOnly = false;
1022
+ this.portalManager.resetMeasuredHeight();
1023
+ if (!this.multiple) {
1024
+ this.searchValue = this.displayLabel;
1025
+ }
1026
+ this.emit('nile-after-hide', { value: this.value, name: this.name });
1027
+ }
1028
+ // ── Watchers ──
1029
+ handleDisabledChange() {
1030
+ if (this.disabled) {
1031
+ this.open = false;
1032
+ this.handleOpenChange();
1033
+ }
1034
+ }
1035
+ handleValueChange() {
1036
+ this.syncSelection();
1037
+ this.requestUpdate();
1038
+ if (this.portal && this.portalManager.portalContainerElement) {
1039
+ this.portalManager.updatePosition();
1040
+ }
1041
+ }
1042
+ handleDataChange() {
1043
+ if (this.data.length > 0 && !this.showSelectedOnly) {
1044
+ this.originalData = [...this.data];
1045
+ }
1046
+ if (this.hasGroupedData) {
1047
+ this.filterOptions(this.searchValue);
1048
+ }
1049
+ else {
1050
+ this.filteredData = [...this.data];
1051
+ this.filteredRows = [];
1052
+ }
1053
+ this.syncSelection();
1054
+ this.updateSelectAllState();
1055
+ if (!this.optionsLoading && !this.loading && this.data.length === 0) {
1056
+ this.showNoResults = true;
1057
+ }
1058
+ else if (this.data.length > 0) {
1059
+ this.showNoResults = false;
1060
+ }
1061
+ this.portalManager.resetMeasuredHeight();
1062
+ if (this.portal && this.portalManager.portalContainerElement) {
1063
+ this.portalManager.updatePosition();
1064
+ }
1065
+ this.requestUpdate();
1066
+ }
1067
+ handleAutoCompleteOptionsChange() {
1068
+ if (this.autoCompleteOptions.length > 0) {
1069
+ this.data = [...this.autoCompleteOptions];
1070
+ }
1071
+ }
1072
+ handleSelectAllConfigChange() {
1073
+ this.updateSelectAllState();
1074
+ }
1075
+ handlePortalChange() {
1076
+ if (this.open) {
1077
+ if (this.portal)
1078
+ this.portalManager.setupPortal();
1079
+ else
1080
+ this.portalManager.cleanupPortal();
1081
+ }
1082
+ }
1083
+ // ── Form integration ──
1084
+ checkValidity() { return this.valueInput.checkValidity(); }
1085
+ getForm() { return this.formControlController.getForm(); }
1086
+ reportValidity() { return this.valueInput.reportValidity(); }
1087
+ setCustomValidity(message) {
1088
+ this.valueInput.setCustomValidity(message);
1089
+ this.formControlController.updateValidity();
1090
+ }
1091
+ focus(options) { this.inputElement?.focus(options); }
1092
+ blur() { this.inputElement?.blur(); }
1093
+ handleInvalid(event) {
1094
+ this.formControlController.setValidity(false);
1095
+ this.formControlController.emitInvalidEvent(event);
1096
+ }
1097
+ updateValidity() {
1098
+ this.updateComplete.then(() => this.formControlController.updateValidity());
1099
+ }
1100
+ async resetScrollPosition() {
1101
+ await this.portalManager.resetScrollPosition();
1102
+ }
1103
+ // ── Render ──
1104
+ render() {
1105
+ const hasLabelSlot = this.hasSlotController.test('label');
1106
+ const hasLabel = this.label ? true : !!hasLabelSlot;
1107
+ const hasValue = this.multiple
1108
+ ? (Array.isArray(this.value) && this.value.length > 0)
1109
+ : (typeof this.value === 'string' && this.value !== '');
1110
+ const hasClearIcon = this.clearable && !this.disabled && hasValue;
1111
+ const hasHelpText = !!this.helpText;
1112
+ const hasErrorMessage = !!this.errorMessage;
1113
+ const isEmpty = !hasValue;
1114
+ return html `
1115
+ <div
1116
+ part="form-control"
1117
+ class=${classMap({
1118
+ 'form-control': true,
1119
+ 'form-control--small': this.size === 'small',
1120
+ 'form-control--medium': this.size === 'medium',
1121
+ 'form-control--large': this.size === 'large',
1122
+ 'form-control--has-label': hasLabel,
1123
+ 'form-control--has-help-text': hasHelpText,
1124
+ })}
1125
+ >
1126
+ <label
1127
+ id="label"
1128
+ part="form-control-label"
1129
+ class="form-control__label"
1130
+ aria-hidden=${hasLabel ? 'false' : 'true'}
1131
+ @click=${() => this.inputElement?.focus()}
1132
+ >
1133
+ <slot name="label">${this.label}</slot>
1134
+ </label>
1135
+
1136
+ <div part="form-control-input" class="form-control-input">
1137
+ <nile-popup
1138
+ class=${classMap({
1139
+ 'combobox-popup': true,
1140
+ 'combobox--open': this.open,
1141
+ 'combobox--closed': !this.open,
1142
+ 'combobox--disabled': this.disabled,
1143
+ 'combobox--focused': this.hasFocus,
1144
+ 'combobox--multiple': this.multiple,
1145
+ 'combobox--empty': isEmpty,
1146
+ 'combobox--small': this.size === 'small',
1147
+ 'combobox--medium': this.size === 'medium',
1148
+ 'combobox--large': this.size === 'large',
1149
+ 'combobox--warning': this.warning,
1150
+ 'combobox--error': this.error,
1151
+ 'combobox--success': this.success,
1152
+ 'combobox--filled': this.filled,
1153
+ 'combobox--pill': this.pill,
1154
+ })}
1155
+ placement=${this.placement}
1156
+ strategy=${this.portal ? 'fixed' : (this.hoist ? 'fixed' : 'absolute')}
1157
+ distance="6"
1158
+ ?flip=${!this.portal}
1159
+ ?shift=${!this.portal}
1160
+ sync=${ifDefined(!this.noWidthSync ? 'width' : undefined)}
1161
+ auto-size="vertical"
1162
+ auto-size-padding="10"
1163
+ >
1164
+ ${this.renderTrigger(hasClearIcon)}
1165
+ ${this.showListbox ? this.renderListbox() : html ``}
1166
+ </nile-popup>
1167
+
1168
+ ${hasHelpText ? html `<nile-form-help-text>${this.helpText}</nile-form-help-text>` : html ``}
1169
+ ${hasErrorMessage ? html `<nile-form-error-message>${this.errorMessage}</nile-form-error-message>` : html ``}
1170
+ </div>
1171
+ </div>
1172
+ `;
1173
+ }
1174
+ renderTrigger(hasClearIcon) {
1175
+ const hasTags = this.multiple && this.selectedOptions.length > 0;
1176
+ const inputPlaceholder = hasTags ? '' : this.placeholder;
1177
+ return html `
1178
+ <div
1179
+ part="combobox"
1180
+ class="combobox__trigger"
1181
+ slot="anchor"
1182
+ @mousedown=${this.onTriggerMouseDown}
1183
+ >
1184
+ <slot part="prefix" name="prefix" class="combobox__prefix"></slot>
1185
+
1186
+ <div class=${classMap({
1187
+ 'combobox__scroll-area': true,
1188
+ 'combobox__scroll-area--single-line': this.multiple && this.tagLayout === 'single-line',
1189
+ 'combobox__scroll-area--wrap': this.multiple && (this.tagLayout === 'wrap' || this.tagLayout === 'fixed-height'),
1190
+ })}>
1191
+ ${hasTags ? this.renderInlineTags() : html ``}
1192
+
1193
+ <div class="combobox__input-wrapper">
1194
+ <input
1195
+ part="input"
1196
+ class="combobox__input"
1197
+ type="text"
1198
+ placeholder=${inputPlaceholder}
1199
+ .disabled=${this.disabled}
1200
+ .value=${this.searchValue}
1201
+ autocomplete="off"
1202
+ spellcheck="false"
1203
+ autocapitalize="off"
1204
+ aria-controls="listbox"
1205
+ aria-expanded=${this.open ? 'true' : 'false'}
1206
+ aria-haspopup="listbox"
1207
+ aria-labelledby="label"
1208
+ aria-disabled=${this.disabled ? 'true' : 'false'}
1209
+ aria-describedby="help-text"
1210
+ aria-activedescendant=${this.keyboardActiveIndex >= 0 ? `option-${this.keyboardActiveIndex}` : ''}
1211
+ role="combobox"
1212
+ tabindex="0"
1213
+ @input=${this.onInputHandler}
1214
+ @keydown=${this.onInputKeyDown}
1215
+ @focus=${this.onFocusIn}
1216
+ @blur=${this.onFocusOut}
1217
+ @change=${this.onInputChange}
1218
+ />
1219
+ </div>
1220
+ </div>
1221
+
1222
+ <input
1223
+ class="combobox__value-input"
1224
+ type="text"
1225
+ ?disabled=${this.disabled}
1226
+ ?required=${this.required}
1227
+ .value=${Array.isArray(this.value) ? this.value.join(', ') : this.value}
1228
+ tabindex="-1"
1229
+ aria-hidden="true"
1230
+ @focus=${() => this.focus()}
1231
+ @invalid=${this.handleInvalid}
1232
+ />
1233
+
1234
+ <div class="combobox__actions">
1235
+ ${hasClearIcon ? this.renderClearButton() : html ``}
1236
+
1237
+ <slot name="expand-icon" part="expand-icon" class="combobox__expand-icon">
1238
+ <nile-icon
1239
+ library="system"
1240
+ name="var(--nile-icon-arrow-down, var(--ng-icon-chevron-down))"
1241
+ method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))"
1242
+ color="var(--nile-colors-dark-500, var(--ng-colors-fg-quaternary-400))"
1243
+ ></nile-icon>
1244
+ </slot>
1245
+ </div>
1246
+ </div>
1247
+ `;
1248
+ }
1249
+ renderInlineTags() {
1250
+ const tags = [];
1251
+ this.selectedOptions.forEach((option, index) => {
1252
+ if (this.maxTagsVisible > 0 && index >= this.maxTagsVisible) {
1253
+ if (index === this.maxTagsVisible) {
1254
+ tags.push(html `<span class="combobox__tags-count">+${this.selectedOptions.length - this.maxTagsVisible} More</span>`);
1255
+ }
1256
+ return;
1257
+ }
1258
+ tags.push(html `
1259
+ <nile-tag
1260
+ part="tag"
1261
+ exportparts="base:tag__base, content:tag__content, remove-button:tag__remove-button"
1262
+ ?pill=${this.pill}
1263
+ size=${this.size}
1264
+ removable
1265
+ ?disabled=${this.disabled}
1266
+ @nile-remove=${(e) => { e.stopPropagation(); this.removeTag(option); }}
1267
+ >
1268
+ ${option.getTextLabel()}
1269
+ </nile-tag>
1270
+ `);
1271
+ });
1272
+ return tags;
1273
+ }
1274
+ renderClearButton() {
1275
+ return html `
1276
+ <button
1277
+ part="clear-button"
1278
+ class="combobox__clear"
1279
+ type="button"
1280
+ aria-label="Clear"
1281
+ @mousedown=${(e) => e.stopPropagation()}
1282
+ @click=${this.onClearClick}
1283
+ tabindex="-1"
1284
+ >
1285
+ <slot name="clear-icon">
1286
+ <nile-icon
1287
+ name="var(--nile-icon-close, var(--ng-icon-x-close))"
1288
+ size="var(--nile-height-14px, var(--ng-height-16px))"
1289
+ method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))"
1290
+ library="system"
1291
+ color="var(--nile-colors-dark-500, var(--ng-colors-fg-quaternary-400))"
1292
+ ></nile-icon>
1293
+ </slot>
1294
+ </button>
1295
+ `;
1296
+ }
1297
+ renderStickyHeaderOverlay(grouped, useVirtual) {
1298
+ if (!this.stickyGroupHeader || !grouped || !useVirtual)
1299
+ return html ``;
1300
+ const idx = this.stickyHeaderIndex;
1301
+ if (idx < 0 || idx >= this.filteredRows.length)
1302
+ return html ``;
1303
+ const row = this.filteredRows[idx];
1304
+ if (row.kind !== 'header')
1305
+ return html ``;
1306
+ return html `
1307
+ <div class="combobox__group-sticky-overlay">
1308
+ ${ComboboxRenderer.renderGroupHeader(row)}
1309
+ </div>
1310
+ `;
1311
+ }
1312
+ renderListbox() {
1313
+ const showAddOption = this.allowCustomValue
1314
+ && this.searchValue.trim()
1315
+ && !this.filteredData.some((item) => {
1316
+ const v = this.getItemValue(item);
1317
+ return String(v).toLowerCase() === this.searchValue.trim().toLowerCase();
1318
+ })
1319
+ && !this.filteredData.some((item) => {
1320
+ const t = this.getDisplayText(item);
1321
+ return t.toLowerCase() === this.searchValue.trim().toLowerCase();
1322
+ });
1323
+ if (this.isHorizontalGrid) {
1324
+ return this.renderHorizontalListbox(!!showAddOption);
1325
+ }
1326
+ const isGrid = this.gridColumns > 1 || this.isBidirectionalGrid;
1327
+ const grouped = this.hasGroupedData && !isGrid;
1328
+ const useVirtual = grouped
1329
+ ? this.filteredRows.length >= 5
1330
+ : ComboboxRenderer.shouldUseVirtualizer(this.filteredData, this.gridColumns);
1331
+ const virtualizer = this.virtualizerCtrl.getVirtualizer();
1332
+ const virtualItems = (useVirtual || isGrid) ? virtualizer.getVirtualItems() : [];
1333
+ const totalSize = (useVirtual || isGrid) ? virtualizer.getTotalSize() : 0;
1334
+ return html `
1335
+ <div
1336
+ id="listbox"
1337
+ role="listbox"
1338
+ aria-expanded=${this.open ? 'true' : 'false'}
1339
+ aria-multiselectable=${this.multiple ? 'true' : 'false'}
1340
+ aria-labelledby="label"
1341
+ part="listbox"
1342
+ class="combobox__listbox ${this.isBidirectionalGrid ? 'combobox__listbox--bidirectional' : ''} ${this.portal ? 'combobox__portal-hidden' : ''}"
1343
+ tabindex="-1"
1344
+ @mouseup=${this.onOptionClick}
1345
+ @scroll=${this.onScroll}
1346
+ style="${this.portal ? 'display: none;' : ''}${this.isBidirectionalGrid ? `max-height:${this.gridRows * 38 + 16}px;` : ''}"
1347
+ ${ref(this.scrollElementRef)}
1348
+ >
1349
+ ${this.renderLoader()}
1350
+ ${this.renderSelectAll()}
1351
+ ${this.renderStickyHeaderOverlay(grouped, useVirtual)}
1352
+ ${this.showNoResults && !this.optionsLoading && !this.loading
1353
+ ? this.renderEmptyState()
1354
+ : isGrid
1355
+ ? ComboboxRenderer.renderVirtualizedGrid(virtualItems, totalSize, this.filteredData, this.value, this.multiple, this.gridColumns, this.getDisplayText.bind(this), this.getItemValue.bind(this), this.optionsLoading || this.loading, this.allowHtmlLabel, this.renderItemConfig?.getDescription ? this.getItemDescription.bind(this) : undefined, this.renderItemConfig?.getPrefix ? this.getItemPrefix.bind(this) : undefined, this.renderItemConfig?.getSuffix ? this.getItemSuffix.bind(this) : undefined, this.isBidirectionalGrid ? this.gridColumnWidth : undefined)
1356
+ : grouped
1357
+ ? (useVirtual
1358
+ ? ComboboxRenderer.renderRowsVirtualized(virtualItems, totalSize, this.filteredRows, this.value, this.multiple, this.getDisplayText.bind(this), this.getItemValue.bind(this), this.optionsLoading || this.loading, this.allowHtmlLabel, this.renderItemConfig?.getDescription ? this.getItemDescription.bind(this) : undefined, this.renderItemConfig?.getPrefix ? this.getItemPrefix.bind(this) : undefined, this.renderItemConfig?.getSuffix ? this.getItemSuffix.bind(this) : undefined)
1359
+ : ComboboxRenderer.renderRowsPlain(this.filteredRows, this.value, this.multiple, this.getDisplayText.bind(this), this.getItemValue.bind(this), this.showNoResults, this.noResultsMessage, this.optionsLoading || this.loading, this.onScroll.bind(this), this.allowHtmlLabel, this.renderItemConfig?.getDescription ? this.getItemDescription.bind(this) : undefined, this.renderItemConfig?.getPrefix ? this.getItemPrefix.bind(this) : undefined, this.renderItemConfig?.getSuffix ? this.getItemSuffix.bind(this) : undefined, undefined, this.hasActiveFilter ? this.noResultsSubtitle : undefined))
1360
+ : useVirtual
1361
+ ? ComboboxRenderer.renderVirtualizedOptions(virtualItems, totalSize, this.filteredData, this.value, this.multiple, this.getDisplayText.bind(this), this.getItemValue.bind(this), this.optionsLoading || this.loading, this.allowHtmlLabel, virtualizer.measureElement, this.renderItemConfig?.getDescription ? this.getItemDescription.bind(this) : undefined, this.renderItemConfig?.getPrefix ? this.getItemPrefix.bind(this) : undefined, this.renderItemConfig?.getSuffix ? this.getItemSuffix.bind(this) : undefined)
1362
+ : ComboboxRenderer.renderPlainOptions(this.filteredData, this.value, this.multiple, this.getDisplayText.bind(this), this.getItemValue.bind(this), this.showNoResults, this.noResultsMessage, this.optionsLoading || this.loading, this.onScroll.bind(this), this.allowHtmlLabel, this.renderItemConfig?.getDescription ? this.getItemDescription.bind(this) : undefined, this.renderItemConfig?.getPrefix ? this.getItemPrefix.bind(this) : undefined, this.renderItemConfig?.getSuffix ? this.getItemSuffix.bind(this) : undefined, undefined, this.hasActiveFilter ? this.noResultsSubtitle : undefined)}
1363
+ ${showAddOption ? html `
1364
+ <div @mouseup=${(e) => { e.stopPropagation(); this.addCustomValue(this.searchValue.trim()); }}>
1365
+ ${ComboboxRenderer.renderAddCustomOption(this.searchValue.trim(), this.multiple)}
1366
+ </div>
1367
+ ` : ''}
1368
+ ${this.multiple && this.showFooter && !this.selectAllEnabled ? this.renderFooter() : ''}
1369
+ </div>
1370
+ `;
1371
+ }
1372
+ renderHorizontalListbox(showAddOption) {
1373
+ const hVirtualizer = this.hVirtualizerCtrl.getVirtualizer();
1374
+ const virtualItems = hVirtualizer.getVirtualItems();
1375
+ const totalSize = hVirtualizer.getTotalSize();
1376
+ return html `
1377
+ <div
1378
+ id="listbox"
1379
+ role="listbox"
1380
+ aria-expanded=${this.open ? 'true' : 'false'}
1381
+ aria-multiselectable=${this.multiple ? 'true' : 'false'}
1382
+ aria-labelledby="label"
1383
+ part="listbox"
1384
+ class="combobox__listbox combobox__listbox--horizontal ${this.portal ? 'combobox__portal-hidden' : ''}"
1385
+ tabindex="-1"
1386
+ @mouseup=${this.onOptionClick}
1387
+ style=${this.portal ? 'display: none;' : ''}
1388
+ ${ref(this.hScrollElementRef)}
1389
+ >
1390
+ ${this.renderLoader()}
1391
+ ${this.renderSelectAll()}
1392
+ ${this.showNoResults && !this.optionsLoading && !this.loading
1393
+ ? this.renderEmptyState()
1394
+ : ComboboxRenderer.renderHorizontalGrid(virtualItems, totalSize, this.filteredData, this.value, this.multiple, this.gridRows, this.gridColumnWidth, this.getDisplayText.bind(this), this.getItemValue.bind(this), this.optionsLoading || this.loading, this.allowHtmlLabel, this.renderItemConfig?.getDescription ? this.getItemDescription.bind(this) : undefined, this.renderItemConfig?.getPrefix ? this.getItemPrefix.bind(this) : undefined, this.renderItemConfig?.getSuffix ? this.getItemSuffix.bind(this) : undefined)}
1395
+ ${showAddOption ? html `
1396
+ <div @mouseup=${(e) => { e.stopPropagation(); this.addCustomValue(this.searchValue.trim()); }}>
1397
+ ${ComboboxRenderer.renderAddCustomOption(this.searchValue.trim(), this.multiple)}
1398
+ </div>
1399
+ ` : ''}
1400
+ ${this.multiple && this.showFooter && !this.selectAllEnabled ? this.renderFooter() : ''}
1401
+ </div>
1402
+ `;
1403
+ }
1404
+ renderLoader() {
1405
+ if (this.loading) {
1406
+ return html `<span class="combobox__loader--center"><nile-loader size="sm"></nile-loader></span>`;
1407
+ }
1408
+ if (this.optionsLoading) {
1409
+ return html `<span class="combobox__loader"><nile-icon class="combobox__loader--icon" name="button-loading-blue"></nile-icon></span>`;
1410
+ }
1411
+ return html ``;
1412
+ }
1413
+ renderSelectAll() {
1414
+ if (!this.multiple || !this.selectAllEnabled)
1415
+ return html ``;
1416
+ const disabled = this.showNoResults || this.optionsLoading || this.loading;
1417
+ const anySelected = this.selectAllChecked || this.selectAllIndeterminate;
1418
+ const label = anySelected ? 'Deselect all' : 'Select all';
1419
+ const showToggleDisabled = this.selectedOptions.length === 0 || this.showNoResults;
1420
+ const iconColor = showToggleDisabled
1421
+ ? 'var(--nile-colors-primary-500, var(--ng-colors-fg-quaternary-400))'
1422
+ : 'var(--nile-colors-primary-600, var(--ng-colors-fg-brand-secondary-600))';
1423
+ return html `
1424
+ <div
1425
+ part="top-actions"
1426
+ class="combobox__top-actions ${disabled ? 'combobox__top-actions--disabled' : ''}"
1427
+ @mousedown=${(e) => e.preventDefault()}
1428
+ >
1429
+ <div
1430
+ class="combobox__select-all"
1431
+ @click=${this.handleSelectAllToggle}
1432
+ >
1433
+ <nile-checkbox
1434
+ ?checked=${this.selectAllChecked}
1435
+ ?indeterminate=${this.selectAllIndeterminate}
1436
+ ?disabled=${disabled}
1437
+ >
1438
+ ${label}
1439
+ </nile-checkbox>
1440
+ </div>
1441
+
1442
+ <button
1443
+ part="show-toggle"
1444
+ class="combobox__show-toggle"
1445
+ type="button"
1446
+ ?disabled=${showToggleDisabled}
1447
+ @click=${this.toggleShowSelected}
1448
+ >
1449
+ <nile-icon
1450
+ library="system"
1451
+ name="filter"
1452
+ color=${iconColor}
1453
+ ></nile-icon>
1454
+ ${this.showSelectedOnly ? 'Show all' : 'Selected'}
1455
+ </button>
1456
+ </div>
1457
+ `;
1458
+ }
1459
+ renderFooter() {
1460
+ return html `
1461
+ <div
1462
+ part="footer"
1463
+ class="combobox__footer ${this.loading ? 'loading' : ''}"
1464
+ @click=${this.onFooterClick}
1465
+ >
1466
+ <span @click=${this.toggleShowSelected} style="cursor: pointer;">
1467
+ <nile-checkbox
1468
+ ?disabled=${this.selectedOptions.length === 0}
1469
+ ?checked=${this.showSelectedOnly}
1470
+ >
1471
+ &nbsp; Show Selected
1472
+ </nile-checkbox>
1473
+ </span>
1474
+ ${this.selectedOptions.length > 0
1475
+ ? html `<span class="combobox__footer-clear" @click=${this.clearAll}>Clear All</span>`
1476
+ : ''}
1477
+ </div>
1478
+ `;
1479
+ }
1480
+ };
1481
+ NileCombobox.styles = styles;
1482
+ __decorate([
1483
+ query('.combobox-popup')
1484
+ ], NileCombobox.prototype, "popup", void 0);
1485
+ __decorate([
1486
+ query('.combobox__trigger')
1487
+ ], NileCombobox.prototype, "combobox", void 0);
1488
+ __decorate([
1489
+ query('.combobox__input')
1490
+ ], NileCombobox.prototype, "inputElement", void 0);
1491
+ __decorate([
1492
+ query('.combobox__value-input')
1493
+ ], NileCombobox.prototype, "valueInput", void 0);
1494
+ __decorate([
1495
+ state()
1496
+ ], NileCombobox.prototype, "hasFocus", void 0);
1497
+ __decorate([
1498
+ state()
1499
+ ], NileCombobox.prototype, "displayLabel", void 0);
1500
+ __decorate([
1501
+ state()
1502
+ ], NileCombobox.prototype, "selectedOptions", void 0);
1503
+ __decorate([
1504
+ state()
1505
+ ], NileCombobox.prototype, "filteredData", void 0);
1506
+ __decorate([
1507
+ state()
1508
+ ], NileCombobox.prototype, "filteredRows", void 0);
1509
+ __decorate([
1510
+ state()
1511
+ ], NileCombobox.prototype, "originalData", void 0);
1512
+ __decorate([
1513
+ state()
1514
+ ], NileCombobox.prototype, "showNoResults", void 0);
1515
+ __decorate([
1516
+ state()
1517
+ ], NileCombobox.prototype, "showListbox", void 0);
1518
+ __decorate([
1519
+ state()
1520
+ ], NileCombobox.prototype, "searchValue", void 0);
1521
+ __decorate([
1522
+ state()
1523
+ ], NileCombobox.prototype, "showSelectedOnly", void 0);
1524
+ __decorate([
1525
+ state()
1526
+ ], NileCombobox.prototype, "selectAllChecked", void 0);
1527
+ __decorate([
1528
+ state()
1529
+ ], NileCombobox.prototype, "selectAllIndeterminate", void 0);
1530
+ __decorate([
1531
+ state()
1532
+ ], NileCombobox.prototype, "stickyHeaderIndex", void 0);
1533
+ __decorate([
1534
+ property()
1535
+ ], NileCombobox.prototype, "name", void 0);
1536
+ __decorate([
1537
+ property({ type: Array })
1538
+ ], NileCombobox.prototype, "data", void 0);
1539
+ __decorate([
1540
+ property({
1541
+ converter: {
1542
+ fromAttribute: (value) => value.split(' '),
1543
+ toAttribute: (value) => value.join(' '),
1544
+ },
1545
+ })
1546
+ ], NileCombobox.prototype, "value", void 0);
1547
+ __decorate([
1548
+ defaultValue()
1549
+ ], NileCombobox.prototype, "defaultValue", void 0);
1550
+ __decorate([
1551
+ property()
1552
+ ], NileCombobox.prototype, "size", void 0);
1553
+ __decorate([
1554
+ property()
1555
+ ], NileCombobox.prototype, "placeholder", void 0);
1556
+ __decorate([
1557
+ property({ type: Boolean, reflect: true })
1558
+ ], NileCombobox.prototype, "multiple", void 0);
1559
+ __decorate([
1560
+ property()
1561
+ ], NileCombobox.prototype, "label", void 0);
1562
+ __decorate([
1563
+ property({ type: Boolean, reflect: true })
1564
+ ], NileCombobox.prototype, "required", void 0);
1565
+ __decorate([
1566
+ property({ type: Boolean, reflect: true })
1567
+ ], NileCombobox.prototype, "disabled", void 0);
1568
+ __decorate([
1569
+ property({ type: Boolean, reflect: true })
1570
+ ], NileCombobox.prototype, "open", void 0);
1571
+ __decorate([
1572
+ property({ type: Boolean, reflect: true })
1573
+ ], NileCombobox.prototype, "clearable", void 0);
1574
+ __decorate([
1575
+ property({ type: Boolean, reflect: true })
1576
+ ], NileCombobox.prototype, "loading", void 0);
1577
+ __decorate([
1578
+ property({ type: Boolean, reflect: true })
1579
+ ], NileCombobox.prototype, "optionsLoading", void 0);
1580
+ __decorate([
1581
+ property({ type: Boolean, reflect: true })
1582
+ ], NileCombobox.prototype, "disableLocalSearch", void 0);
1583
+ __decorate([
1584
+ property({ type: Boolean, reflect: true })
1585
+ ], NileCombobox.prototype, "allowCustomValue", void 0);
1586
+ __decorate([
1587
+ property({ type: Boolean, reflect: true })
1588
+ ], NileCombobox.prototype, "acceptUserInput", void 0);
1589
+ __decorate([
1590
+ property({ type: Boolean, reflect: true })
1591
+ ], NileCombobox.prototype, "addToSuggestions", void 0);
1592
+ __decorate([
1593
+ property({ type: Boolean, reflect: true })
1594
+ ], NileCombobox.prototype, "strict", void 0);
1595
+ __decorate([
1596
+ property({ attribute: 'max-tags-visible', type: Number })
1597
+ ], NileCombobox.prototype, "maxTagsVisible", void 0);
1598
+ __decorate([
1599
+ property()
1600
+ ], NileCombobox.prototype, "tagLayout", void 0);
1601
+ __decorate([
1602
+ property({ type: Boolean, reflect: true })
1603
+ ], NileCombobox.prototype, "showFooter", void 0);
1604
+ __decorate([
1605
+ property({ type: Boolean, reflect: true, attribute: 'select-all-enabled' })
1606
+ ], NileCombobox.prototype, "selectAllEnabled", void 0);
1607
+ __decorate([
1608
+ property({ type: Boolean, reflect: true, attribute: 'sticky-group-header' })
1609
+ ], NileCombobox.prototype, "stickyGroupHeader", void 0);
1610
+ __decorate([
1611
+ property({ type: Boolean, reflect: true })
1612
+ ], NileCombobox.prototype, "portal", void 0);
1613
+ __decorate([
1614
+ property({ type: Boolean })
1615
+ ], NileCombobox.prototype, "hoist", void 0);
1616
+ __decorate([
1617
+ property({ reflect: true })
1618
+ ], NileCombobox.prototype, "placement", void 0);
1619
+ __decorate([
1620
+ property({ reflect: true })
1621
+ ], NileCombobox.prototype, "form", void 0);
1622
+ __decorate([
1623
+ property({ attribute: 'help-text', reflect: true })
1624
+ ], NileCombobox.prototype, "helpText", void 0);
1625
+ __decorate([
1626
+ property({ attribute: 'error-message', reflect: true })
1627
+ ], NileCombobox.prototype, "errorMessage", void 0);
1628
+ __decorate([
1629
+ property({ type: Boolean })
1630
+ ], NileCombobox.prototype, "warning", void 0);
1631
+ __decorate([
1632
+ property({ type: Boolean })
1633
+ ], NileCombobox.prototype, "error", void 0);
1634
+ __decorate([
1635
+ property({ type: Boolean })
1636
+ ], NileCombobox.prototype, "success", void 0);
1637
+ __decorate([
1638
+ property({ type: Boolean, reflect: true })
1639
+ ], NileCombobox.prototype, "filled", void 0);
1640
+ __decorate([
1641
+ property({ type: Boolean, reflect: true })
1642
+ ], NileCombobox.prototype, "pill", void 0);
1643
+ __decorate([
1644
+ property({ type: String })
1645
+ ], NileCombobox.prototype, "noResultsMessage", void 0);
1646
+ __decorate([
1647
+ property({ type: String, attribute: 'no-results-subtitle' })
1648
+ ], NileCombobox.prototype, "noResultsSubtitle", void 0);
1649
+ __decorate([
1650
+ property({ type: String, attribute: 'no-data-message' })
1651
+ ], NileCombobox.prototype, "noDataMessage", void 0);
1652
+ __decorate([
1653
+ property({
1654
+ type: Array,
1655
+ converter: {
1656
+ fromAttribute: (value) => {
1657
+ if (!value)
1658
+ return [];
1659
+ try {
1660
+ return JSON.parse(value);
1661
+ }
1662
+ catch {
1663
+ return [];
1664
+ }
1665
+ },
1666
+ toAttribute: (value) => JSON.stringify(value),
1667
+ },
1668
+ })
1669
+ ], NileCombobox.prototype, "autoCompleteOptions", void 0);
1670
+ __decorate([
1671
+ property({ type: Number })
1672
+ ], NileCombobox.prototype, "debounceMs", void 0);
1673
+ __decorate([
1674
+ property({ attribute: false })
1675
+ ], NileCombobox.prototype, "renderItemConfig", void 0);
1676
+ __decorate([
1677
+ property({ type: Boolean, reflect: true })
1678
+ ], NileCombobox.prototype, "allowHtmlLabel", void 0);
1679
+ __decorate([
1680
+ property({ type: Boolean, reflect: true, attribute: true })
1681
+ ], NileCombobox.prototype, "enableVisibilityEffect", void 0);
1682
+ __decorate([
1683
+ property({ type: Boolean, reflect: true, attribute: true })
1684
+ ], NileCombobox.prototype, "enableTabClose", void 0);
1685
+ __decorate([
1686
+ property({ type: Boolean, reflect: true })
1687
+ ], NileCombobox.prototype, "noWidthSync", void 0);
1688
+ __decorate([
1689
+ property({ attribute: 'grid-columns', type: Number, reflect: true })
1690
+ ], NileCombobox.prototype, "gridColumns", void 0);
1691
+ __decorate([
1692
+ property({ attribute: 'grid-rows', type: Number, reflect: true })
1693
+ ], NileCombobox.prototype, "gridRows", void 0);
1694
+ __decorate([
1695
+ property({ attribute: 'grid-column-width', type: Number })
1696
+ ], NileCombobox.prototype, "gridColumnWidth", void 0);
1697
+ __decorate([
1698
+ watch('open', { waitUntilFirstUpdate: true })
1699
+ ], NileCombobox.prototype, "handleOpenChange", null);
1700
+ __decorate([
1701
+ watch('disabled', { waitUntilFirstUpdate: true })
1702
+ ], NileCombobox.prototype, "handleDisabledChange", null);
1703
+ __decorate([
1704
+ watch('value', { waitUntilFirstUpdate: true })
1705
+ ], NileCombobox.prototype, "handleValueChange", null);
1706
+ __decorate([
1707
+ watch('data', { waitUntilFirstUpdate: true })
1708
+ ], NileCombobox.prototype, "handleDataChange", null);
1709
+ __decorate([
1710
+ watch('autoCompleteOptions', { waitUntilFirstUpdate: true })
1711
+ ], NileCombobox.prototype, "handleAutoCompleteOptionsChange", null);
1712
+ __decorate([
1713
+ watch('multiple', { waitUntilFirstUpdate: true }),
1714
+ watch('selectAllEnabled', { waitUntilFirstUpdate: true })
1715
+ ], NileCombobox.prototype, "handleSelectAllConfigChange", null);
1716
+ __decorate([
1717
+ watch('portal', { waitUntilFirstUpdate: true })
1718
+ ], NileCombobox.prototype, "handlePortalChange", null);
1719
+ NileCombobox = __decorate([
1720
+ customElement('nile-combobox')
1721
+ ], NileCombobox);
1722
+ export { NileCombobox };
1723
+ // ── Default animations ──
1724
+ setDefaultAnimation('combobox.show', {
1725
+ keyframes: [
1726
+ { opacity: 0, scale: 0.9 },
1727
+ { opacity: 1, scale: 1 },
1728
+ ],
1729
+ options: { duration: 100, easing: 'ease' },
1730
+ });
1731
+ setDefaultAnimation('combobox.hide', {
1732
+ keyframes: [
1733
+ { opacity: 1, scale: 1 },
1734
+ { opacity: 0, scale: 0.9 },
1735
+ ],
1736
+ options: { duration: 100, easing: 'ease' },
1737
+ });
1738
+ export default NileCombobox;
1739
+ //# sourceMappingURL=nile-combobox.js.map