@aquera/nile-elements 0.1.75-beta-1.2 → 0.1.75-beta-1.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 (55) hide show
  1. package/demo/index.html +5 -17
  2. package/dist/index.js +35 -16
  3. package/dist/nile-calendar/nile-calendar.test.cjs.js +1 -1
  4. package/dist/nile-calendar/nile-calendar.test.cjs.js.map +1 -1
  5. package/dist/nile-calendar/nile-calendar.test.esm.js +1 -1
  6. package/dist/nile-select/index.cjs.js +1 -1
  7. package/dist/nile-select/index.esm.js +1 -1
  8. package/dist/nile-select/nile-select.cjs.js +1 -1
  9. package/dist/nile-select/nile-select.cjs.js.map +1 -1
  10. package/dist/nile-select/nile-select.esm.js +2 -2
  11. package/dist/nile-select/nile-select.test.cjs.js +1 -1
  12. package/dist/nile-select/nile-select.test.cjs.js.map +1 -1
  13. package/dist/nile-select/nile-select.test.esm.js +1 -1
  14. package/dist/nile-select/virtual-scroll-helper.cjs.js +1 -1
  15. package/dist/nile-select/virtual-scroll-helper.cjs.js.map +1 -1
  16. package/dist/nile-select/virtual-scroll-helper.esm.js +1 -0
  17. package/dist/nile-virtual-select/index.cjs.js +1 -1
  18. package/dist/nile-virtual-select/index.esm.js +1 -1
  19. package/dist/nile-virtual-select/nile-virtual-select.cjs.js +1 -1
  20. package/dist/nile-virtual-select/nile-virtual-select.cjs.js.map +1 -1
  21. package/dist/nile-virtual-select/nile-virtual-select.css.cjs.js +1 -1
  22. package/dist/nile-virtual-select/nile-virtual-select.css.cjs.js.map +1 -1
  23. package/dist/nile-virtual-select/nile-virtual-select.css.esm.js +14 -0
  24. package/dist/nile-virtual-select/nile-virtual-select.esm.js +15 -11
  25. package/dist/nile-virtual-select/renderer.cjs.js +1 -1
  26. package/dist/nile-virtual-select/renderer.cjs.js.map +1 -1
  27. package/dist/nile-virtual-select/renderer.esm.js +10 -10
  28. package/dist/nile-virtual-select/selection-manager.cjs.js +1 -1
  29. package/dist/nile-virtual-select/selection-manager.cjs.js.map +1 -1
  30. package/dist/nile-virtual-select/selection-manager.esm.js +1 -1
  31. package/dist/src/nile-select/nile-select.d.ts +2 -0
  32. package/dist/src/nile-select/nile-select.js +5 -0
  33. package/dist/src/nile-select/nile-select.js.map +1 -1
  34. package/dist/src/nile-select/virtual-scroll-helper.js +1 -0
  35. package/dist/src/nile-select/virtual-scroll-helper.js.map +1 -1
  36. package/dist/src/nile-virtual-select/nile-virtual-select.css.js +14 -0
  37. package/dist/src/nile-virtual-select/nile-virtual-select.css.js.map +1 -1
  38. package/dist/src/nile-virtual-select/nile-virtual-select.d.ts +8 -0
  39. package/dist/src/nile-virtual-select/nile-virtual-select.js +38 -15
  40. package/dist/src/nile-virtual-select/nile-virtual-select.js.map +1 -1
  41. package/dist/src/nile-virtual-select/renderer.d.ts +1 -1
  42. package/dist/src/nile-virtual-select/renderer.js +4 -4
  43. package/dist/src/nile-virtual-select/renderer.js.map +1 -1
  44. package/dist/src/nile-virtual-select/selection-manager.js +1 -1
  45. package/dist/src/nile-virtual-select/selection-manager.js.map +1 -1
  46. package/dist/tsconfig.tsbuildinfo +1 -1
  47. package/package.json +1 -1
  48. package/src/nile-select/nile-select.ts +3 -0
  49. package/src/nile-select/virtual-scroll-helper.ts +1 -0
  50. package/src/nile-virtual-select/nile-virtual-select.css.ts +14 -0
  51. package/src/nile-virtual-select/nile-virtual-select.ts +38 -17
  52. package/src/nile-virtual-select/renderer.ts +4 -4
  53. package/src/nile-virtual-select/selection-manager.ts +1 -1
  54. package/vscode-html-custom-data.json +7 -226
  55. package/src/nile-virtual-select/temp_nile-virtual-select copy.ts +0 -1398
@@ -1,1398 +0,0 @@
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
-
8
- import {
9
- LitElement,
10
- html,
11
- } from 'lit';
12
- import { customElement, property } from 'lit/decorators.js';
13
- import { styles } from './nile-virtual-select.css';
14
-
15
- import '../nile-icon';
16
- import '../nile-popup/nile-popup';
17
- import '../nile-tag/nile-tag';
18
- import '../nile-checkbox/nile-checkbox';
19
- import '../nile-loader/nile-loader';
20
- import { animateTo, stopAnimations } from '../internal/animate';
21
- import { classMap } from 'lit/directives/class-map.js';
22
- import { query, state } from 'lit/decorators.js';
23
- import { defaultValue } from '../internal/default-value';
24
- import { FormControlController } from '../internal/form';
25
- import {
26
- getAnimation,
27
- setDefaultAnimation,
28
- } from '../utilities/animation-registry';
29
- import { HasSlotController } from '../internal/slot';
30
- import { waitForEvent } from '../internal/event';
31
- import { watch } from '../internal/watch';
32
- import NileElement from '../internal/nile-element';
33
- import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
34
- import type { NileFormControl } from '../internal/nile-element';
35
- import type NileOption from '../nile-option/nile-option';
36
- import type NilePopup from '../nile-popup/nile-popup';
37
- import { ifDefined } from 'lit/directives/if-defined.js';
38
-
39
- import type { VirtualOption, NileRemoveEvent, RenderItemConfig } from './types.js';
40
- import { VirtualSelectSelectionManager } from './selection-manager.js';
41
- import { VirtualSelectSearchManager } from './search-manager.js';
42
- import { VirtualSelectRenderer } from './renderer.js';
43
-
44
- /**
45
- * Nile Virtual Select component.
46
- *
47
- * @tag nile-virtual-select
48
- *
49
- */
50
-
51
- /**
52
- * @summary Virtual select component for handling large datasets with virtual scrolling.
53
- * @status stable
54
- * @since 2.0
55
- *
56
- * @dependency nile-icon
57
- * @dependency nile-popup
58
- * @dependency nile-tag
59
- * @dependency nile-checkbox
60
- *
61
- * @slot label - The input's label. Alternatively, you can use the `label` attribute.
62
- * @slot prefix - Used to prepend a presentational icon or similar element to the combobox.
63
- * @slot clear-icon - An icon to use in lieu of the default clear icon.
64
- * @slot expand-icon - The icon to show when the control is expanded and collapsed.
65
- * @slot help-text - Text that describes how to use the input. Alternatively, you can use the `help-text` attribute.
66
- *
67
- * @event nile-change - Emitted when the control's value changes.
68
- * @event nile-clear - Emitted when the control's value is cleared.
69
- * @event nile-input - Emitted when the control receives input.
70
- * @event nile-focus - Emitted when the control gains focus.
71
- * @event nile-blur - Emitted when the control loses focus.
72
- * @event nile-show - Emitted when the select's menu opens.
73
- * @event nile-after-show - Emitted after the select's menu opens and all animations are complete.
74
- * @event nile-hide - Emitted when the select's menu closes.
75
- * @event nile-after-hide - Emitted after the select's menu closes and all animations are complete.
76
- * @event nile-invalid - Emitted when the form control has been checked for validity and its constraints aren't satisfied.
77
- * @event nile-search - Emitted when the user types in the search input. The event payload includes the search query for backend search functionality.
78
- * @event nile-scroll - Emitted when the user scrolls within the virtualized container. The event payload includes scroll position information.
79
- * @event nile-scroll-start - Emitted when the user starts scrolling within the virtualized container.
80
- * @event nile-scroll-end - Emitted when the user stops scrolling and reaches the bottom of the virtualized container (debounced).
81
- *
82
- * @csspart form-control - The form control that wraps the label, input, and help text.
83
- * @csspart form-control-label - The label's wrapper.
84
- * @csspart form-control-input - The select's wrapper.
85
- * @csspart form-control-help-text - The help text's wrapper.
86
- * @csspart combobox - The container the wraps the prefix, combobox, clear icon, and expand button.
87
- * @csspart prefix - The container that wraps the prefix slot.
88
- * @csspart display-input - The element that displays the selected option's label, an `<input>` element.
89
- * @csspart listbox - The listbox container where options are slotted.
90
- * @csspart tags - The container that houses option tags when `multiple` is used.
91
- * @csspart tag - The individual tags that represent each multiselect option.
92
- * @csspart clear-button - The clear button.
93
- * @csspart expand-icon - The container that wraps the expand icon.
94
- * @csspart footer - The footer container with show selected and clear all options.
95
- */
96
-
97
- @customElement('nile-virtual-select')
98
- export class NileVirtualSelect extends NileElement implements NileFormControl {
99
- static styles: CSSResultGroup = styles;
100
-
101
- private readonly formControlController = new FormControlController(this, {
102
- assumeInteractionOn: ['nile-blur', 'nile-input'],
103
- });
104
- private readonly hasSlotController = new HasSlotController(
105
- this,
106
- 'help-text',
107
- 'label'
108
- );
109
-
110
- @query('.select') popup: NilePopup;
111
- @query('.select__display-input') displayInput: HTMLInputElement;
112
- @query('.select__value-input') valueInput: HTMLInputElement;
113
- @query('.virtualized') virtualizedContainer: HTMLElement;
114
-
115
- @state() private hasFocus = false;
116
- @state() displayLabel = '';
117
- @state() selectedOptions: VirtualOption[] = [];
118
- @state() oldValue: string | string[] = '';
119
-
120
- private scrollTimeout: number | undefined;
121
- private scrolling = false;
122
-
123
- /** The name of the select, submitted as a name/value pair with form data. */
124
- @property() name = '';
125
-
126
- /** Array of all option items for virtual scrolling */
127
- @property({ type: Array }) data: any = [];
128
-
129
- /** Original unfiltered option items for search functionality */
130
- @state() private originalOptionItems: any = [];
131
-
132
- /**
133
- * The current value of the select. When `multiple` is enabled, the value will be an array of selected values.
134
- */
135
- @property({
136
- converter: {
137
- fromAttribute: (value: string) => value.split(' '),
138
- toAttribute: (value: string[]) => value.join(' '),
139
- },
140
- })
141
- value: string | string[] = '';
142
-
143
- /** The default value of the form control. Primarily used for resetting the form control. */
144
- @defaultValue() defaultValue: string | string[] = '';
145
-
146
- /** The select's size. */
147
- @property() size: 'small' | 'medium' | 'large' = 'medium';
148
-
149
- /** Placeholder text to show as a hint when the select is empty. */
150
- @property() placeholder = 'Select...';
151
-
152
- /** Current search value */
153
- @state() searchValue: string = '';
154
-
155
- /** Enable search functionality */
156
- @property({ type: Boolean, reflect: true }) searchEnabled = false;
157
-
158
- /** Search input placeholder */
159
- @property({attribute:'internal-search-placeholder'}) internalSearchPlaceHolder = 'Search...';
160
-
161
- /** Disable local search filtering */
162
- @property({ type: Boolean, reflect: true }) disableLocalSearch = false;
163
-
164
- /** Show loading state */
165
- @property({ type: Boolean, reflect: true }) optionsLoading = false;
166
-
167
- /** Show loading state using nile-loader */
168
- @property({ type: Boolean, reflect: true }) loading = false;
169
-
170
- /** Allows more than one option to be selected. */
171
- @property({ type: Boolean, reflect: true }) multiple = false;
172
-
173
- /** Help text */
174
- @property({ attribute: 'help-text', reflect: true }) helpText = '';
175
-
176
- /** Error message */
177
- @property({ attribute: 'error-message', reflect: true }) errorMessage = '';
178
-
179
- /** Sets the input to a warning state */
180
- @property({ type: Boolean }) warning = false;
181
-
182
- /** Sets the input to an error state */
183
- @property({ type: Boolean }) error = false;
184
-
185
- /** Sets the input to a success state */
186
- @property({ type: Boolean }) success = false;
187
-
188
- /** Disables the select control. */
189
- @property({ type: Boolean, reflect: true }) disabled = false;
190
-
191
- /** Adds a clear button when the select is not empty. */
192
- @property({ type: Boolean, reflect: true }) clearable = false;
193
-
194
- /** The select's open state. */
195
- @property({ type: Boolean, reflect: true }) open = false;
196
-
197
- /**
198
- * Enable this option to prevent the listbox from being clipped when the component is placed inside a container with
199
- * `overflow: auto|scroll`. Hoisting uses a fixed positioning strategy that works in many, but not all, scenarios.
200
- */
201
- @property({ type: Boolean }) hoist = false;
202
-
203
- /** Draws a filled select. */
204
- @property({ type: Boolean, reflect: true }) filled = false;
205
-
206
- /** Draws a pill-style select with rounded edges. */
207
- @property({ type: Boolean, reflect: true }) pill = false;
208
-
209
- /** The select's label. If you need to display HTML, use the `label` slot instead. */
210
- @property() label = '';
211
-
212
- /**
213
- * The preferred placement of the select's menu. Note that the actual placement may vary as needed to keep the listbox
214
- * inside of the viewport.
215
- */
216
- @property({ reflect: true }) placement: 'top' | 'bottom' = 'bottom';
217
-
218
- /**
219
- * By default, form controls are associated with the nearest containing `<form>` element. This attribute allows you
220
- * to place the form control outside of a form and associate it with the form that has this `id`. The form must be in
221
- * the same document or shadow root for this to work.
222
- */
223
- @property({ reflect: true }) form = '';
224
-
225
- /** The select's required attribute. */
226
- @property({ type: Boolean, reflect: true }) required = false;
227
-
228
- /** Show no results message */
229
- @property({ type: Boolean }) showNoResults: boolean = false;
230
-
231
- /** No results message */
232
- @property({ type: String }) noResultsMessage: string = 'No results found';
233
-
234
- /** Show selected options only */
235
- @property({ type: Boolean }) showSelected = false;
236
-
237
- /** Enhanced configuration for rendering items with support for display text, value, and search text */
238
- @property({ attribute:false}) renderItemConfig?: RenderItemConfig;
239
-
240
- /** Block value change events */
241
- @property({ type: Boolean, reflect: true }) blockValueChange = false;
242
-
243
- /** Disable width synchronization */
244
- @property({ type: Boolean, reflect: true }) noWidthSync = false;
245
-
246
- /**
247
- * The maximum number of selected options to show when `multiple` is true. After the maximum, "+n" will be shown to
248
- * indicate the number of additional items that are selected. Set to 0 to remove the limit.
249
- */
250
- @property({ attribute: 'max-options-visible', type: Number })
251
- maxOptionsVisible = 3;
252
-
253
- @state() oldMaxOptionsVisible: number = 1;
254
-
255
- /** Gets the validity state object */
256
- get validity() {
257
- return this.valueInput?.validity;
258
- }
259
-
260
- /** Gets the validation message */
261
- get validationMessage() {
262
- return this.valueInput?.validationMessage ?? '';
263
- }
264
-
265
- connectedCallback() {
266
- super.connectedCallback();
267
- this.initializeComponent();
268
- this.setupEventListeners();
269
-
270
- this.updateComplete.then(() => {
271
- if (this.value && this.data.length > 0) {
272
- this.selectionChanged();
273
- }
274
- });
275
- }
276
-
277
- disconnectedCallback() {
278
- this.removeOpenListeners();
279
- // Clear any pending scroll timeout to prevent memory leaks
280
- if (this.scrollTimeout) {
281
- clearTimeout(this.scrollTimeout);
282
- this.scrollTimeout = undefined;
283
- }
284
- }
285
-
286
- protected updated(changedProperties: PropertyValues): void {
287
- if(changedProperties.has('value')) {
288
- this.selectionChanged();
289
- }
290
- }
291
-
292
- private initializeComponent(): void {
293
- this.open = false;
294
- this.emit('nile-init');
295
- }
296
-
297
- /**
298
- * Get display text for an item using renderItemConfig
299
- */
300
- private getDisplayText(item: any): string {
301
- if (this.renderItemConfig?.getDisplayText) {
302
- return this.renderItemConfig.getDisplayText(item);
303
- }
304
- // Fallback to basic display
305
- return item?.label || item?.name || item?.toString() || '';
306
- }
307
-
308
- /**
309
- * Get value for an item using renderItemConfig or fallback to item.value
310
- */
311
- private getItemValue(item: any): string {
312
- if (this.renderItemConfig?.getValue) {
313
- return this.renderItemConfig.getValue(item);
314
- }
315
- return item?.value || item;
316
- }
317
-
318
- /**
319
- * Get search text for an item using renderItemConfig or fallback to display text
320
- */
321
- private getSearchText(item: any): string {
322
- if (this.renderItemConfig?.getSearchText) {
323
- return this.renderItemConfig.getSearchText(item);
324
- }
325
- return this.getDisplayText(item);
326
- }
327
-
328
- private setupEventListeners(): void {
329
- this.handleDocumentFocusIn = this.handleDocumentFocusIn.bind(this);
330
- this.handleDocumentKeyDown = this.handleDocumentKeyDown.bind(this);
331
- this.handleDocumentMouseDown = this.handleDocumentMouseDown.bind(this);
332
- }
333
-
334
- private addOpenListeners(): void {
335
- document.addEventListener('focusin', this.handleDocumentFocusIn);
336
- document.addEventListener('keydown', this.handleDocumentKeyDown);
337
- document.addEventListener('mousedown', this.handleDocumentMouseDown);
338
- }
339
-
340
- private removeOpenListeners(): void {
341
- document.removeEventListener('focusin', this.handleDocumentFocusIn);
342
- document.removeEventListener('keydown', this.handleDocumentKeyDown);
343
- document.removeEventListener('mousedown', this.handleDocumentMouseDown);
344
- }
345
-
346
- private handleFocus(): void {
347
- this.hasFocus = true;
348
- this.emit('nile-focus');
349
- }
350
-
351
- private handleBlur(): void {
352
- this.hasFocus = false;
353
- this.emit('nile-blur');
354
- }
355
-
356
- private handleDocumentFocusIn(event: FocusEvent): void {
357
- if (!this.open) return;
358
- const path = event.composedPath();
359
- const hitSelf = path.includes(this);
360
- const hitPopup = this.popup && path.includes(this.popup);
361
-
362
- if (!hitSelf && !hitPopup) {
363
- this.hide();
364
- }
365
- }
366
-
367
- private handleDocumentKeyDown(event: KeyboardEvent): void {
368
- if (this.shouldIgnoreKeyPress(event)) {
369
- return;
370
- }
371
-
372
- if (this.isEscapeKey(event)) {
373
- this.handleEscapeKey(event);
374
- }
375
-
376
- if (this.isEnterOrSpaceKey(event)) {
377
- this.handleEnterOrSpaceKey(event);
378
- }
379
- }
380
-
381
- private shouldIgnoreKeyPress(event: KeyboardEvent): boolean {
382
- const target = event.target as HTMLElement;
383
- const isClearButton = target.closest('.select__clear') !== null;
384
- const isIconButton = target.closest('nile-icon-button') !== null;
385
- return isClearButton || isIconButton;
386
- }
387
-
388
- private isEscapeKey(event: KeyboardEvent): boolean {
389
- return event.key === 'Escape' && this.open;
390
- }
391
-
392
- private handleEscapeKey(event: KeyboardEvent): void {
393
- event.preventDefault();
394
- event.stopPropagation();
395
- this.hide();
396
- this.displayInput.focus({ preventScroll: true });
397
- }
398
-
399
- private isEnterOrSpaceKey(event: KeyboardEvent): boolean {
400
- return event.key === 'Enter' || event.key === ' ';
401
- }
402
-
403
- private handleEnterOrSpaceKey(event: KeyboardEvent): void {
404
- event.preventDefault();
405
- event.stopImmediatePropagation();
406
-
407
- if (!this.open) {
408
- this.show();
409
- return;
410
- }
411
-
412
- if (!this.multiple) {
413
- this.hide();
414
- this.displayInput.focus({ preventScroll: true });
415
- }
416
- }
417
-
418
- private handleDocumentMouseDown = (event: MouseEvent): void => {
419
- if (!this.open) return;
420
-
421
- const path = event.composedPath();
422
- const hitSelf = path.includes(this);
423
- const hitPopup = this.popup && path.includes(this.popup);
424
-
425
- if (!hitSelf && !hitPopup) {
426
- this.hide();
427
- }
428
- };
429
-
430
- private handleFooterClick(event: MouseEvent): void {
431
- event.stopPropagation();
432
- event.preventDefault();
433
- }
434
-
435
- private toggleShowSelected(event: Event): void {
436
- event.stopPropagation();
437
- event.preventDefault();
438
- if (this.selectedOptions?.length === 0) {
439
- return;
440
- }
441
- this.showSelected = !this.showSelected;
442
-
443
- if (this.showSelected) {
444
- const selectedValues = Array.isArray(this.value) ? this.value : [this.value];
445
- this.data = this.originalOptionItems.filter((item: any) =>
446
- selectedValues.includes(item.value)
447
- );
448
- } else {
449
- this.data = [...this.originalOptionItems];
450
- }
451
-
452
- this.requestUpdate();
453
- this.resetScrollPosition();
454
- }
455
-
456
- private unSelectAll(): void {
457
- this.showSelected = false;
458
- this.value = this.multiple ? [] : '';
459
- this.data = [...this.originalOptionItems];
460
- this.selectionChanged();
461
- this.emit('nile-change', { value: this.value, name: this.name });
462
- this.emit('nile-clear', { value: this.multiple ? this.value : '', name: this.name });
463
- this.resetScrollPosition();
464
- }
465
-
466
- private handleLabelClick(): void {
467
- this.displayInput.focus();
468
- this.hide();
469
- }
470
-
471
- private handleComboboxMouseDown(event: MouseEvent): void {
472
- if (this.shouldIgnoreComboboxClick(event)) {
473
- return;
474
- }
475
-
476
- event.preventDefault();
477
- this.displayInput.focus({ preventScroll: true });
478
- this.open = !this.open;
479
- }
480
-
481
- private shouldIgnoreComboboxClick(event: MouseEvent): boolean {
482
- const path = event.composedPath();
483
- const isIconButton = path.some(
484
- el =>
485
- el instanceof Element && el.tagName.toLowerCase() === 'nile-icon-button'
486
- );
487
- return this.disabled || isIconButton;
488
- }
489
-
490
- private handleComboboxKeyDown(event: KeyboardEvent): void {
491
- if (this.isEnterOrSpaceKey(event)) {
492
- event.preventDefault();
493
- this.open = !this.open;
494
- }
495
- }
496
-
497
- private handleClearClick(event: MouseEvent): void {
498
- event.stopPropagation();
499
- this.clearSelection();
500
- }
501
-
502
- private clearSelection(): void {
503
- const oldValue = this.value;
504
- this.value = this.multiple ? [] : '';
505
- this.selectionChanged();
506
-
507
- this.updateComplete.then(() => {
508
- this.nileInput({ value: this.value, name: this.name });
509
- this.nileChange({ value: this.value, name: this.name });
510
- this.emit('nile-clear');
511
- });
512
- }
513
-
514
- private handleClearMouseDown(event: MouseEvent): void {
515
- event.stopPropagation();
516
- }
517
-
518
- private handleOptionClick(event: MouseEvent): void {
519
- const target = event.target as HTMLElement;
520
- const option = target.closest('nile-option');
521
-
522
- if (this.shouldBlockValueChange(option)) {
523
- return;
524
- }
525
-
526
- const oldValue = this.value;
527
- this.oldValue = oldValue;
528
-
529
- if (option && !option.disabled) {
530
- this.handleOptionSelection(option);
531
- }
532
- }
533
-
534
- private shouldBlockValueChange(option: Element | null): boolean {
535
- if (this.blockValueChange && option) {
536
- this.emit('nile-block-change', { value: (option as any)?.value, name: this.name });
537
- this.hide();
538
- return true;
539
- }
540
- return false;
541
- }
542
-
543
- private handleOptionSelection(option: Element): void {
544
- const optionValue = (option as any).value;
545
-
546
- if (this.multiple) {
547
- this.toggleOptionSelection(optionValue);
548
- } else {
549
- this.setSelectedOptions(optionValue);
550
- }
551
-
552
- this.updateComplete.then(() =>
553
- this.displayInput.focus({ preventScroll: true })
554
- );
555
-
556
- if (this.value !== this.oldValue) {
557
- this.updateComplete.then(() => {
558
- this.nileInput({ value: this.value, name: this.name });
559
- this.nileChange({ value: this.value, name: this.name });
560
- });
561
- }
562
-
563
- if (!this.multiple) {
564
- this.hide();
565
- this.displayInput.focus({ preventScroll: true });
566
- }
567
- }
568
-
569
- private setSelectedOptions(optionValue: string): void {
570
- this.value = optionValue;
571
- this.selectionChanged();
572
- }
573
-
574
- private toggleOptionSelection(optionValue: string): void {
575
- const currentValues = Array.isArray(this.value) ? this.value : [];
576
-
577
- if (currentValues.includes(optionValue)) {
578
- this.value = currentValues.filter(v => v !== optionValue);
579
- } else {
580
- this.value = [...currentValues, optionValue];
581
- }
582
-
583
- this.selectionChanged();
584
- }
585
-
586
- private handleTagRemove(event: NileRemoveEvent, option: VirtualOption): void {
587
- event.stopPropagation();
588
-
589
- if (!this.disabled) {
590
- this.removeTagFromSelection(option);
591
- this.emitTagRemovalEvent(option);
592
- }
593
- }
594
-
595
- private removeTagFromSelection(option: VirtualOption): void {
596
- let currentValue = this.value;
597
- if (!Array.isArray(currentValue)) {
598
- currentValue = currentValue ? [currentValue] : [];
599
- }
600
- const newValue = currentValue.filter((v: string) => v !== option.value);
601
- this.value = newValue;
602
- this.selectionChanged();
603
- }
604
-
605
- private emitTagRemovalEvent(option: VirtualOption): void {
606
- this.updateComplete.then(() => {
607
- this.nileInput({ value: this.value, name: this.name });
608
- this.nileChange({ value: this.value, name: this.name });
609
- this.emit('nile-tag-remove', { value: this.value, name: this.name, removedtagvalue: option.value });
610
- });
611
- }
612
-
613
- private selectionChanged(): void {
614
- const itemsToSearch = this.originalOptionItems.length > 0 ? this.originalOptionItems : this.data;
615
- this.selectedOptions = VirtualSelectSelectionManager.createVirtualOptionsFromValues(
616
- this.value,
617
- itemsToSearch,
618
- this.getDisplayText.bind(this),
619
- this.renderItemConfig?.getValue
620
- );
621
-
622
- if (this.multiple) {
623
- if (this.placeholder && this.value.length === 0) {
624
- this.displayLabel = '';
625
- } else {
626
- this.displayLabel = this.selectedOptions.length + ' selected';
627
- }
628
- } else {
629
- const currentValue = Array.isArray(this.value) ? this.value[0] : this.value;
630
- const label = this.selectedOptions[0]?.getTextLabel();
631
- this.displayLabel = label ? label : currentValue ?? '';
632
- }
633
-
634
- this.updateValidity();
635
-
636
- if (this.selectedOptions.length === 0) {
637
- this.showSelected = false;
638
- }
639
-
640
- this.calculateTotalWidthOfTags();
641
- }
642
-
643
- handleSearchFocus(): void {
644
- document.removeEventListener('keydown', this.handleDocumentKeyDown);
645
- }
646
-
647
- handleSearchBlur(): void {
648
- document.addEventListener('keydown', this.handleDocumentKeyDown);
649
- }
650
-
651
- handleSearchChange(e: any): void {
652
- this.searchValue = e.detail.value;
653
-
654
- this.emit('nile-search', {
655
- query: this.searchValue,
656
- name: this.name
657
- });
658
-
659
- if (!this.disableLocalSearch) {
660
- this.filterVirtualOptions(this.searchValue);
661
- this.resetScrollPosition();
662
- }
663
- }
664
-
665
- handleScroll(e: Event): void {
666
- const target = e.target as HTMLElement;
667
-
668
- this.emit('nile-scroll', {
669
- scrollTop: target.scrollTop,
670
- scrollLeft: target.scrollLeft,
671
- name: this.name
672
- });
673
-
674
- if (!this.scrolling) {
675
- this.scrolling = true;
676
- this.emit('nile-scroll-start', {
677
- scrollTop: target.scrollTop,
678
- scrollLeft: target.scrollLeft,
679
- name: this.name
680
- });
681
- }
682
-
683
- clearTimeout(this.scrollTimeout);
684
- this.scrollTimeout = window.setTimeout(() => {
685
- if (this.scrolling) {
686
- this.scrolling = false;
687
- }
688
- }, 300);
689
-
690
- const isAtBottom = Math.ceil(target.scrollTop) >= Math.floor(target.scrollHeight - target.offsetHeight);
691
- if (isAtBottom) {
692
- this.emit('nile-scroll-end', {
693
- scrollTop: target.scrollTop,
694
- scrollLeft: target.scrollLeft,
695
- name: this.name,
696
- isAtBottom: true
697
- });
698
- }
699
- }
700
-
701
- filterVirtualOptions(searchValue: string): void {
702
- const result = VirtualSelectSearchManager.filterVirtualOptions(
703
- searchValue,
704
- this.originalOptionItems,
705
- this.data,
706
- this.getDisplayText.bind(this),
707
- this.renderItemConfig?.getSearchText
708
- );
709
-
710
- this.data = result.filteredItems;
711
- this.showNoResults = result.showNoResults;
712
- this.showSelected = false;
713
- this.requestUpdate();
714
- }
715
-
716
- private handleInvalid(event: Event): void {
717
- this.formControlController.setValidity(false);
718
- this.formControlController.emitInvalidEvent(event);
719
- }
720
-
721
- @watch('disabled', { waitUntilFirstUpdate: true })
722
- handleDisabledChange(): void {
723
- if (this.disabled) {
724
- this.open = false;
725
- this.handleOpenChange();
726
- }
727
- }
728
-
729
- @watch('value', { waitUntilFirstUpdate: true })
730
- handleValueChange(): void {
731
- this.selectionChanged();
732
- this.requestUpdate();
733
- }
734
-
735
- @watch('data', { waitUntilFirstUpdate: true })
736
- handleDataChange(): void {
737
- if (this.data.length > 0 && this.open) {
738
- this.originalOptionItems = [...this.data];
739
- }
740
-
741
- this.selectionChanged();
742
- // Show no results message when data is empty and not loading
743
- if (!this.optionsLoading && !this.loading && this.data.length === 0) {
744
- this.showNoResults = true;
745
- } else if (this.data.length > 0) {
746
- this.showNoResults = false;
747
- }
748
- this.requestUpdate();
749
- }
750
-
751
- @watch('renderItemConfig', { waitUntilFirstUpdate: true })
752
- handleRenderItemConfigChange(): void {
753
- if (this.value && this.data.length > 0) {
754
- this.selectionChanged();
755
- this.requestUpdate();
756
- }
757
- }
758
-
759
- @watch('optionsLoading', { waitUntilFirstUpdate: true })
760
- handleOptionsLoadingChange(): void {
761
- // Show no results message when loading stops and there are no results
762
- if (!this.optionsLoading && this.data.length === 0) {
763
- this.showNoResults = true;
764
- }
765
- this.requestUpdate();
766
- }
767
-
768
- @watch('loading', { waitUntilFirstUpdate: true })
769
- handleLoadingChange(): void {
770
- // Show no results message when loading stops and there are no results
771
- if (!this.loading && this.data.length === 0) {
772
- this.showNoResults = true;
773
- }
774
- this.requestUpdate();
775
- }
776
-
777
- @watch('open', { waitUntilFirstUpdate: true })
778
- async handleOpenChange(): Promise<void> {
779
- if (this.open && !this.disabled) {
780
- await this.handleOpen();
781
- } else {
782
- await this.handleClose();
783
- }
784
- }
785
-
786
- private async handleOpen(): Promise<void> {
787
- this.emit('nile-show', { value: this.value, name: this.name });
788
- this.addOpenListeners();
789
- this.showNoResults = !this.data?.length;
790
-
791
- await stopAnimations(this);
792
- this.popup.active = true;
793
-
794
- const { keyframes, options } = getAnimation(this, 'select.show', {
795
- dir: 'ltr',
796
- });
797
- await animateTo(this.popup.popup, keyframes, options);
798
-
799
- this.initializeOriginalItems();
800
- this.filterVirtualOptions(this.searchValue);
801
- this.resetScrollPosition();
802
- this.emit('nile-after-show', { value: this.value, name: this.name });
803
- }
804
-
805
- private async handleClose(): Promise<void> {
806
- this.emit('nile-hide', { value: this.value, name: this.name });
807
- this.removeOpenListeners();
808
-
809
- await stopAnimations(this);
810
- const { keyframes, options } = getAnimation(this, 'select.hide', {
811
- dir: 'ltr',
812
- });
813
- await animateTo(this.popup.popup, keyframes, options);
814
- this.popup.active = false;
815
-
816
- this.searchValue = '';
817
- this.emit('nile-after-hide', { value: this.value, name: this.name });
818
- }
819
-
820
- private initializeOriginalItems(): void {
821
- if (this.data.length > 0) {
822
- this.originalOptionItems = [...this.data];
823
- }
824
- }
825
-
826
- async show(): Promise<unknown> {
827
- if (this.open || this.disabled) {
828
- this.open = false;
829
- return undefined;
830
- }
831
-
832
- this.open = true;
833
- return waitForEvent(this, 'nile-after-show');
834
- }
835
-
836
- async hide(): Promise<unknown> {
837
- if (!this.open || this.disabled) {
838
- this.open = false;
839
- return undefined;
840
- }
841
-
842
- this.open = false;
843
- return waitForEvent(this, 'nile-after-hide');
844
- }
845
-
846
- checkValidity(): boolean {
847
- return this.valueInput.checkValidity();
848
- }
849
-
850
- getForm(): HTMLFormElement | null {
851
- return this.formControlController.getForm();
852
- }
853
-
854
- reportValidity(): boolean {
855
- return this.valueInput.reportValidity();
856
- }
857
-
858
- setCustomValidity(message: string): void {
859
- this.valueInput.setCustomValidity(message);
860
- this.formControlController.updateValidity();
861
- }
862
-
863
- focus(options?: FocusOptions): void {
864
- this.displayInput.focus(options);
865
- }
866
-
867
- blur(): void {
868
- this.displayInput.blur();
869
- }
870
-
871
- onInputChange(event: Event): void {
872
- event.stopPropagation();
873
- }
874
-
875
- render(): TemplateResult {
876
- const hasLabelSlot = this.hasSlotController.test('label');
877
- const hasHelpTextSlot = this.hasSlotController.test('help-text');
878
- const hasLabelSuffixSlot = this.hasSlotController.test('label-suffix');
879
- const hasCustomSelect = this.hasSlotController.test('custom-select');
880
- const hasLabel = this.label ? true : !!hasLabelSlot;
881
- const hasClearIcon =
882
- this.clearable && !this.disabled && this.value.length > 0;
883
- const isPlaceholderVisible = !!this.placeholder && this.value.length === 0;
884
- const hasHelpText = !!this.helpText;
885
- const hasErrorMessage = !!this.errorMessage;
886
-
887
- return html`
888
- <div
889
- part="form-control"
890
- class=${classMap({
891
- 'form-control': true,
892
- 'form-control--small': this.size === 'small',
893
- 'form-control--medium': this.size === 'medium',
894
- 'form-control--large': this.size === 'large',
895
- 'form-control--has-label': hasLabel,
896
- 'form-control--has-help-text': hasHelpText,
897
- })}
898
- >
899
- ${this.renderLabel(hasLabel, hasLabelSuffixSlot)}
900
- ${this.renderFormControlInput(hasCustomSelect, hasClearIcon, isPlaceholderVisible, hasHelpText, hasErrorMessage)}
901
- </div>
902
- `;
903
- }
904
-
905
- private renderLabel(hasLabel: boolean, hasLabelSuffixSlot: boolean): TemplateResult {
906
- return html`
907
- <label
908
- id="label"
909
- part="form-control-label"
910
- class="form-control__label"
911
- aria-hidden=${hasLabel ? 'false' : 'true'}
912
- @click=${this.handleLabelClick}
913
- >
914
- <slot name="label">${this.label}</slot>
915
- </label>
916
-
917
- ${hasLabelSuffixSlot ? html` <slot name="label-suffix"></slot> ` : ``}
918
- `;
919
- }
920
-
921
- private renderFormControlInput(
922
- hasCustomSelect: boolean,
923
- hasClearIcon: boolean,
924
- isPlaceholderVisible: boolean,
925
- hasHelpText: boolean,
926
- hasErrorMessage: boolean
927
- ): TemplateResult {
928
- return html`
929
- <div part="form-control-input" class="form-control-input">
930
- ${this.renderPopup(hasCustomSelect, hasClearIcon, isPlaceholderVisible)}
931
- ${this.renderHelpText(hasHelpText, hasErrorMessage)}
932
- </div>
933
- `;
934
- }
935
-
936
- private renderPopup(hasCustomSelect: boolean, hasClearIcon: boolean, isPlaceholderVisible: boolean): TemplateResult {
937
- return html`
938
- <nile-popup
939
- class=${classMap({
940
- select: true,
941
- 'select--warning': this.warning,
942
- 'select--error': this.error,
943
- 'select--success': this.success,
944
- 'select--standard': true,
945
- 'select--filled': this.filled,
946
- 'select--pill': this.pill,
947
- 'select--open': this.open,
948
- 'select--disabled': this.disabled,
949
- 'select--multiple': this.multiple,
950
- 'select--focused': this.hasFocus,
951
- 'select--placeholder-visible': isPlaceholderVisible,
952
- 'select--top': this.placement === 'top',
953
- 'select--bottom': this.placement === 'bottom',
954
- 'select--small': this.size === 'small',
955
- 'select--medium': this.size === 'medium',
956
- 'select--large': this.size === 'large',
957
- })}
958
- placement=${this.placement}
959
- strategy=${this.hoist ? 'fixed' : 'absolute'}
960
- distance="6"
961
- flip
962
- shift
963
- sync=${ifDefined(!this.noWidthSync ? 'width' : undefined)}
964
- auto-size="vertical"
965
- auto-size-padding="10"
966
- >
967
- ${this.renderCustomSelect(hasCustomSelect)}
968
- ${this.renderCombobox(hasCustomSelect, hasClearIcon)}
969
- ${this.renderListbox()}
970
- </nile-popup>
971
- `;
972
- }
973
-
974
- private renderCustomSelect(hasCustomSelect: boolean): TemplateResult {
975
- return hasCustomSelect
976
- ? html`<slot
977
- slot="anchor"
978
- name="custom-select"
979
- class="custom-select"
980
- @keydown=${this.handleComboboxKeyDown}
981
- @mousedown=${this.handleComboboxMouseDown}
982
- ></slot>`
983
- : html``;
984
- }
985
-
986
- private renderCombobox(hasCustomSelect: boolean, hasClearIcon: boolean): TemplateResult {
987
- return html`
988
- <div
989
- part="combobox"
990
- class=${classMap({
991
- select__combobox: true,
992
- 'select__hide-default': hasCustomSelect,
993
- })}
994
- slot="anchor"
995
- @keydown=${this.handleComboboxKeyDown}
996
- @mousedown=${this.handleComboboxMouseDown}
997
- >
998
- ${this.renderPrefix()}
999
- ${this.renderDisplayInput()}
1000
- ${this.renderTags()}
1001
- ${this.renderValueInput()}
1002
- ${this.renderClearButton(hasClearIcon)}
1003
- ${this.renderSuffix()}
1004
- ${this.renderExpandIcon()}
1005
- </div>
1006
- `;
1007
- }
1008
-
1009
- private renderPrefix(): TemplateResult {
1010
- return html`
1011
- <slot
1012
- part="prefix"
1013
- name="prefix"
1014
- class=${classMap({
1015
- select__prefix: true,
1016
- multiple: this.multiple,
1017
- })}
1018
- ></slot>
1019
- `;
1020
- }
1021
-
1022
- private renderDisplayInput(): TemplateResult {
1023
- return html`
1024
- <input
1025
- part="display-input"
1026
- class="select__display-input"
1027
- type="text"
1028
- placeholder=${this.placeholder}
1029
- .disabled=${this.disabled}
1030
- .value=${this.displayLabel}
1031
- autocomplete="off"
1032
- spellcheck="false"
1033
- autocapitalize="off"
1034
- readonly
1035
- aria-controls="listbox"
1036
- aria-expanded=${this.open ? 'true' : 'false'}
1037
- aria-haspopup="listbox"
1038
- aria-labelledby="label"
1039
- aria-disabled=${this.disabled ? 'true' : 'false'}
1040
- aria-describedby="help-text"
1041
- role="combobox"
1042
- tabindex="0"
1043
- />
1044
- `;
1045
- }
1046
-
1047
- private renderTags(): TemplateResult {
1048
- return this.multiple
1049
- ? html`
1050
- <div part="tags" class="select__tags">
1051
- ${this.selectedOptions.map((option, index) => {
1052
- if (
1053
- index < this.maxOptionsVisible ||
1054
- this.maxOptionsVisible <= 0
1055
- ) {
1056
- const classes = {
1057
- select__invisible:
1058
- index + 1 > this.oldMaxOptionsVisible &&
1059
- this.maxOptionsVisible === Infinity,
1060
- };
1061
- return html`
1062
- <nile-tag
1063
- class=${classMap(classes)}
1064
- part="tag"
1065
- exportparts="
1066
- base:tag__base,
1067
- content:tag__content,
1068
- remove-button:tag__remove-button,
1069
- remove-button__base:tag__remove-button__base
1070
- "
1071
- ?pill=${this.pill}
1072
- size=${this.size}
1073
- removable
1074
- @nile-remove=${(event: NileRemoveEvent) =>
1075
- this.handleTagRemove(event, option)}
1076
- >
1077
- ${option.getTextLabel()}
1078
- </nile-tag>
1079
- `;
1080
- } else if (index === this.maxOptionsVisible) {
1081
- return html`
1082
- <span class="select__tags-count"
1083
- >+${this.selectedOptions.length - index} More
1084
- </span>
1085
- `;
1086
- } else {
1087
- return null;
1088
- }
1089
- })}
1090
- </div>
1091
- `
1092
- : html``;
1093
- }
1094
-
1095
- private renderValueInput(): TemplateResult {
1096
- return html`
1097
- <input
1098
- class="select__value-input"
1099
- type="text"
1100
- ?disabled=${this.disabled}
1101
- ?required=${this.required}
1102
- .value=${Array.isArray(this.value)
1103
- ? this.value.join(', ')
1104
- : this.value}
1105
- tabindex="-1"
1106
- aria-hidden="true"
1107
- @focus=${() => this.focus()}
1108
- @invalid=${this.handleInvalid}
1109
- />
1110
- `;
1111
- }
1112
-
1113
- private renderClearButton(hasClearIcon: boolean): TemplateResult {
1114
- return hasClearIcon
1115
- ? html`
1116
- <button
1117
- part="clear-button"
1118
- class="select__clear"
1119
- type="button"
1120
- aria-label="clearEntry"
1121
- @mousedown=${this.handleClearMouseDown}
1122
- @click=${this.handleClearClick}
1123
- tabindex="-1"
1124
- >
1125
- <slot name="clear-icon">
1126
- <nile-icon name="close" library="system"></nile-icon>
1127
- </slot>
1128
- </button>
1129
- `
1130
- : html``;
1131
- }
1132
-
1133
- private renderSuffix(): TemplateResult {
1134
- return html`
1135
- <slot
1136
- part="suffix"
1137
- name="suffix"
1138
- class=${classMap({
1139
- select__suffix: true,
1140
- })}
1141
- ></slot>
1142
- `;
1143
- }
1144
-
1145
- private renderExpandIcon(): TemplateResult {
1146
- return html`
1147
- <slot
1148
- name="expand-icon"
1149
- part="expand-icon"
1150
- class="select__expand-icon"
1151
- >
1152
- <nile-icon library="system" name="arrowdown"></nile-icon>
1153
- </slot>
1154
- `;
1155
- }
1156
-
1157
- private renderListbox(): TemplateResult {
1158
- return html`
1159
- <div
1160
- id="listbox"
1161
- role="listbox"
1162
- aria-expanded=${this.open ? 'true' : 'false'}
1163
- aria-multiselectable=${this.multiple ? 'true' : 'false'}
1164
- aria-labelledby="label"
1165
- part="listbox"
1166
- class="select__listbox ${this.searchEnabled
1167
- ? 'select__search-enabled '
1168
- : ''}"
1169
- tabindex="-1"
1170
- @mouseup=${this.handleOptionClick}
1171
- >
1172
- ${this.renderSearch()}
1173
- ${this.getVirtualizedContent()}
1174
- ${this.renderLoader()}
1175
- ${this.renderFooter()}
1176
- </div>
1177
- `;
1178
- }
1179
-
1180
- private renderSearch(): TemplateResult {
1181
- return this.searchEnabled
1182
- ? html`
1183
- <div part="search" class="select__search">
1184
- <nile-input
1185
- size="small"
1186
- clearable
1187
- .value=${this.searchValue}
1188
- placeholder="${this.internalSearchPlaceHolder}"
1189
- @nile-input=${this.handleSearchChange}
1190
- @nile-focus=${this.handleSearchFocus}
1191
- @nile-change="${this.onInputChange}"
1192
- >
1193
- <nile-icon name="search" slot="suffix"> </nile-icon>
1194
- </nile-input>
1195
- </div>
1196
- `
1197
- : html``;
1198
- }
1199
-
1200
- private renderLoader(): TemplateResult {
1201
- if (this.loading) {
1202
- return html`
1203
- <span part="loader" class="virtual-select-loader">
1204
- <nile-loader size="sm"></nile-loader>
1205
- </span>
1206
- `;
1207
- }
1208
-
1209
- if (this.optionsLoading) {
1210
- return html`
1211
- <span part="loader" class="select__loader">
1212
- <nile-icon
1213
- class="select__loader--icon"
1214
- name="button-loading-blue"
1215
- ></nile-icon>
1216
- </span>
1217
- `;
1218
- }
1219
-
1220
- return html``;
1221
- }
1222
-
1223
- private renderFooter(): TemplateResult {
1224
- return this.multiple
1225
- ? html`
1226
- <div
1227
- part="footer"
1228
- class="select__footer"
1229
- @click="${this.handleFooterClick}"
1230
- >
1231
- <span
1232
- @click="${this.toggleShowSelected}"
1233
- style="cursor: pointer;"
1234
- >
1235
- <nile-checkbox
1236
- ?disabled="${this.selectedOptions.length === 0}"
1237
- ?checked="${this.showSelected}"
1238
- >
1239
- &nbsp; Show Selected</nile-checkbox
1240
- >
1241
- </span>
1242
- ${this.selectedOptions.length !== 0
1243
- ? html`
1244
- <span
1245
- class="select__clear"
1246
- @click="${this.unSelectAll}"
1247
- >
1248
- Clear All
1249
- </span>
1250
- `
1251
- : ``}
1252
- </div>
1253
- `
1254
- : html``;
1255
- }
1256
-
1257
- private renderHelpText(hasHelpText: boolean, hasErrorMessage: boolean): TemplateResult {
1258
- return html`
1259
- ${hasHelpText
1260
- ? html` <nile-form-help-text>${this.helpText}</nile-form-help-text> `
1261
- : ``}
1262
- ${hasErrorMessage
1263
- ? html`
1264
- <nile-form-error-message
1265
- >${this.errorMessage}</nile-form-error-message
1266
- >
1267
- `
1268
- : ``}
1269
- `;
1270
- }
1271
-
1272
- getVirtualizedContent(): TemplateResult {
1273
- return VirtualSelectRenderer.getVirtualizedContent(
1274
- this.data,
1275
- this.searchEnabled,
1276
- this.getDisplayText.bind(this),
1277
- this.value,
1278
- this.multiple,
1279
- this.renderItemConfig?.getDisplayText,
1280
- this.renderItemConfig?.getValue,
1281
- this.showNoResults,
1282
- this.noResultsMessage,
1283
- this.optionsLoading || this.loading,
1284
- this.handleScroll.bind(this)
1285
- );
1286
- }
1287
-
1288
- nileInput(value: any): void {
1289
- this.emit('nile-input', value);
1290
- }
1291
-
1292
- nileChange(value: any): void {
1293
- this.emit('nile-change', value);
1294
- }
1295
-
1296
- private updateValidity(): void {
1297
- this.updateComplete.then(() => {
1298
- this.formControlController.updateValidity();
1299
- });
1300
- }
1301
-
1302
- private calculateWidthOfSelectTagsDiv(): number | null {
1303
- if (this.shadowRoot) {
1304
- const selectTagsDiv = this.shadowRoot.querySelector('.select__tags') as HTMLElement;
1305
- if (selectTagsDiv) {
1306
- const width = selectTagsDiv.offsetWidth;
1307
- return width - 70;
1308
- }
1309
- }
1310
- return null;
1311
- }
1312
-
1313
- private calculateTotalWidthOfTags(): void {
1314
- if (this.maxOptionsVisible !== Infinity) {
1315
- this.oldMaxOptionsVisible = this.maxOptionsVisible;
1316
- }
1317
-
1318
- this.maxOptionsVisible = Infinity;
1319
- setTimeout(() => {
1320
- let widths: number[] = [];
1321
- if (this.shadowRoot) {
1322
- const tags = this.shadowRoot.querySelectorAll('nile-tag');
1323
- tags.forEach(tag => {
1324
- if (tag instanceof HTMLElement) {
1325
- widths.push(tag.offsetWidth);
1326
- }
1327
- });
1328
- }
1329
- if (this.value.length !== widths.length) {
1330
- return;
1331
- }
1332
-
1333
- let sum = widths.reduce(
1334
- (accumulator, currentValue) => accumulator + currentValue,
1335
- 0
1336
- );
1337
- const widthOfSelectTagsDiv = this.calculateWidthOfSelectTagsDiv();
1338
- if (!widthOfSelectTagsDiv) {
1339
- return;
1340
- }
1341
-
1342
- let summ = 0;
1343
- let lastindex = 0;
1344
-
1345
- for (let i = 0; i < widths.length; i++) {
1346
- summ += widths[i];
1347
-
1348
- if (summ > widthOfSelectTagsDiv) {
1349
- lastindex = i;
1350
- break;
1351
- }
1352
- }
1353
- this.maxOptionsVisible = lastindex;
1354
- }, 1);
1355
- }
1356
-
1357
- private resetScrollPosition(): void {
1358
- this.updateComplete.then(() => {
1359
- if (this.virtualizedContainer) {
1360
- this.virtualizedContainer.scrollTop = 0;
1361
-
1362
- const listbox = this.shadowRoot?.querySelector('.select__listbox') as HTMLElement;
1363
- if (listbox) {
1364
- listbox.scrollTop = 0;
1365
- }
1366
-
1367
- const virtualizer = this.virtualizedContainer.querySelector('lit-virtualizer') as HTMLElement;
1368
- if (virtualizer) {
1369
- virtualizer.scrollTop = 0;
1370
- }
1371
- }
1372
- });
1373
- }
1374
- }
1375
-
1376
- setDefaultAnimation('select.show', {
1377
- keyframes: [
1378
- { opacity: 0, scale: 0.9 },
1379
- { opacity: 1, scale: 1 },
1380
- ],
1381
- options: { duration: 100, easing: 'ease' },
1382
- });
1383
-
1384
- setDefaultAnimation('select.hide', {
1385
- keyframes: [
1386
- { opacity: 1, scale: 1 },
1387
- { opacity: 0, scale: 0.9 },
1388
- ],
1389
- options: { duration: 100, easing: 'ease' },
1390
- });
1391
-
1392
- export default NileVirtualSelect;
1393
-
1394
- // declare global {
1395
- // interface HTMLElementTagNameMap {
1396
- // 'nile-virtual-select': NileVirtualSelect;
1397
- // }
1398
- // }