@shival99/z-ui 2.1.28 → 2.1.29

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 (68) hide show
  1. package/package.json +1 -1
  2. package/types/shival99-z-ui-components-z-select.d.ts +1 -1
  3. package/fesm2022/shival99-z-ui-components-z-autocomplete.mjs +0 -1079
  4. package/fesm2022/shival99-z-ui-components-z-autocomplete.mjs.map +0 -1
  5. package/fesm2022/shival99-z-ui-components-z-drawer.mjs +0 -742
  6. package/fesm2022/shival99-z-ui-components-z-drawer.mjs.map +0 -1
  7. package/fesm2022/shival99-z-ui-components-z-dropdown-menu.mjs +0 -58
  8. package/fesm2022/shival99-z-ui-components-z-dropdown-menu.mjs.map +0 -1
  9. package/fesm2022/shival99-z-ui-components-z-editor.mjs +0 -1750
  10. package/fesm2022/shival99-z-ui-components-z-editor.mjs.map +0 -1
  11. package/fesm2022/shival99-z-ui-components-z-gallery.mjs +0 -2419
  12. package/fesm2022/shival99-z-ui-components-z-gallery.mjs.map +0 -1
  13. package/fesm2022/shival99-z-ui-components-z-kanban.mjs +0 -981
  14. package/fesm2022/shival99-z-ui-components-z-kanban.mjs.map +0 -1
  15. package/fesm2022/shival99-z-ui-components-z-marquee.mjs +0 -70
  16. package/fesm2022/shival99-z-ui-components-z-marquee.mjs.map +0 -1
  17. package/fesm2022/shival99-z-ui-components-z-media-player.mjs +0 -668
  18. package/fesm2022/shival99-z-ui-components-z-media-player.mjs.map +0 -1
  19. package/fesm2022/shival99-z-ui-components-z-menu.mjs +0 -843
  20. package/fesm2022/shival99-z-ui-components-z-menu.mjs.map +0 -1
  21. package/fesm2022/shival99-z-ui-components-z-metric-card.mjs +0 -128
  22. package/fesm2022/shival99-z-ui-components-z-metric-card.mjs.map +0 -1
  23. package/fesm2022/shival99-z-ui-components-z-pagination.mjs +0 -158
  24. package/fesm2022/shival99-z-ui-components-z-pagination.mjs.map +0 -1
  25. package/fesm2022/shival99-z-ui-components-z-qrcode.mjs +0 -383
  26. package/fesm2022/shival99-z-ui-components-z-qrcode.mjs.map +0 -1
  27. package/fesm2022/shival99-z-ui-components-z-radio.mjs +0 -167
  28. package/fesm2022/shival99-z-ui-components-z-radio.mjs.map +0 -1
  29. package/fesm2022/shival99-z-ui-components-z-scrollarea.mjs +0 -131
  30. package/fesm2022/shival99-z-ui-components-z-scrollarea.mjs.map +0 -1
  31. package/fesm2022/shival99-z-ui-components-z-show-more.mjs +0 -121
  32. package/fesm2022/shival99-z-ui-components-z-show-more.mjs.map +0 -1
  33. package/fesm2022/shival99-z-ui-components-z-skeleton-auto.mjs +0 -61
  34. package/fesm2022/shival99-z-ui-components-z-skeleton-auto.mjs.map +0 -1
  35. package/fesm2022/shival99-z-ui-components-z-steps.mjs +0 -396
  36. package/fesm2022/shival99-z-ui-components-z-steps.mjs.map +0 -1
  37. package/fesm2022/shival99-z-ui-components-z-table.mjs +0 -10508
  38. package/fesm2022/shival99-z-ui-components-z-table.mjs.map +0 -1
  39. package/fesm2022/shival99-z-ui-components-z-tabs.mjs +0 -507
  40. package/fesm2022/shival99-z-ui-components-z-tabs.mjs.map +0 -1
  41. package/fesm2022/shival99-z-ui-components-z-tags.mjs +0 -349
  42. package/fesm2022/shival99-z-ui-components-z-tags.mjs.map +0 -1
  43. package/fesm2022/shival99-z-ui-components-z-timeline.mjs +0 -237
  44. package/fesm2022/shival99-z-ui-components-z-timeline.mjs.map +0 -1
  45. package/fesm2022/shival99-z-ui-components-z-upload.mjs +0 -523
  46. package/fesm2022/shival99-z-ui-components-z-upload.mjs.map +0 -1
  47. package/types/shival99-z-ui-components-z-autocomplete.d.ts +0 -290
  48. package/types/shival99-z-ui-components-z-drawer.d.ts +0 -266
  49. package/types/shival99-z-ui-components-z-dropdown-menu.d.ts +0 -54
  50. package/types/shival99-z-ui-components-z-editor.d.ts +0 -337
  51. package/types/shival99-z-ui-components-z-gallery.d.ts +0 -402
  52. package/types/shival99-z-ui-components-z-kanban.d.ts +0 -237
  53. package/types/shival99-z-ui-components-z-marquee.d.ts +0 -35
  54. package/types/shival99-z-ui-components-z-media-player.d.ts +0 -124
  55. package/types/shival99-z-ui-components-z-menu.d.ts +0 -222
  56. package/types/shival99-z-ui-components-z-metric-card.d.ts +0 -67
  57. package/types/shival99-z-ui-components-z-pagination.d.ts +0 -55
  58. package/types/shival99-z-ui-components-z-qrcode.d.ts +0 -76
  59. package/types/shival99-z-ui-components-z-radio.d.ts +0 -69
  60. package/types/shival99-z-ui-components-z-scrollarea.d.ts +0 -46
  61. package/types/shival99-z-ui-components-z-show-more.d.ts +0 -36
  62. package/types/shival99-z-ui-components-z-skeleton-auto.d.ts +0 -35
  63. package/types/shival99-z-ui-components-z-steps.d.ts +0 -106
  64. package/types/shival99-z-ui-components-z-table.d.ts +0 -1924
  65. package/types/shival99-z-ui-components-z-tabs.d.ts +0 -92
  66. package/types/shival99-z-ui-components-z-tags.d.ts +0 -128
  67. package/types/shival99-z-ui-components-z-timeline.d.ts +0 -71
  68. package/types/shival99-z-ui-components-z-upload.d.ts +0 -153
@@ -1,1079 +0,0 @@
1
- import { NgClass, NgTemplateOutlet } from '@angular/common';
2
- import * as i0 from '@angular/core';
3
- import { inject, TemplateRef, Directive, Injector, DestroyRef, viewChild, viewChildren, contentChild, input, output, signal, effect, computed, untracked, forwardRef, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
4
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
- import { NgControl, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
6
- import { injectVirtualizer } from '@shival99/angular-virtual';
7
- import { ZEmptyComponent } from '@shival99/z-ui/components/z-empty';
8
- import { ZIconComponent } from '@shival99/z-ui/components/z-icon';
9
- import { ZLoadingComponent } from '@shival99/z-ui/components/z-loading';
10
- import { ZPopoverDirective } from '@shival99/z-ui/components/z-popover';
11
- import { ZTooltipDirective } from '@shival99/z-ui/components/z-tooltip';
12
- import { ZHighlightPipe, ZSafeHtmlPipe } from '@shival99/z-ui/pipes';
13
- import { zTransform, zUuid, zResolveAsyncSelectedOptions, zMergeAsyncOptions, zRemoveVietnamese, zMergeClasses, zCreateEvent, Z_ASYNC_OPTIONS_DEFAULT_PAGE_SIZE, zToAsyncOptionsObservable, zResolveAsyncOptionsHasMore } from '@shival99/z-ui/utils';
14
- import { Subject, debounceTime, distinctUntilChanged, finalize } from 'rxjs';
15
- import { cva } from 'class-variance-authority';
16
-
17
- class ZAutocompleteOptionDirective {
18
- templateRef = inject((TemplateRef));
19
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZAutocompleteOptionDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
20
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.9", type: ZAutocompleteOptionDirective, isStandalone: true, selector: "[z-autocomplete-option], [zAutocompleteOption]", ngImport: i0 });
21
- }
22
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZAutocompleteOptionDirective, decorators: [{
23
- type: Directive,
24
- args: [{
25
- selector: '[z-autocomplete-option], [zAutocompleteOption]',
26
- standalone: true,
27
- }]
28
- }] });
29
-
30
- const Z_AUTOCOMPLETE_DEFAULT_CONFIG = {
31
- minLength: 1,
32
- debounceTime: 0,
33
- maxDisplayed: 0,
34
- highlightMatch: true,
35
- emptyMessage: 'i18n_z_ui_autocomplete_no_results',
36
- noDataMessage: 'i18n_z_ui_autocomplete_no_data',
37
- closeOnSelect: true,
38
- optionHeight: 36,
39
- dropdownMaxHeight: 280,
40
- serverSearch: false,
41
- };
42
-
43
- const zAutocompleteInputVariants = cva([
44
- 'flex w-full items-center rounded-sm border border-input bg-white shadow-xs',
45
- 'transition-[border-color,box-shadow,background-color,color,opacity,border-radius] duration-200',
46
- 'dark:bg-input/30 dark:border-input dark:hover:bg-input/50',
47
- 'outline-none',
48
- 'text-sm',
49
- ], {
50
- variants: {
51
- zSize: {
52
- sm: 'h-8 px-2 gap-2 text-sm',
53
- default: 'h-9 px-2.5 gap-2 text-sm',
54
- lg: 'h-10 px-3 gap-2.5 text-sm',
55
- },
56
- zStatus: {
57
- default: 'focus-within:border-ring focus-within:ring-ring/50 focus-within:ring-[3px]',
58
- open: 'border-ring',
59
- error: 'border-destructive! ring-destructive/20 ring-[3px] focus-within:border-destructive! focus-within:ring-destructive/30',
60
- disabled: 'opacity-50 cursor-not-allowed bg-muted! text-muted-foreground',
61
- readonly: 'cursor-default bg-muted/50 text-muted-foreground',
62
- },
63
- },
64
- defaultVariants: {
65
- zSize: 'default',
66
- zStatus: 'default',
67
- },
68
- });
69
- const zAutocompleteOptionVariants = cva('px-2 py-1.5 cursor-pointer transition-colors text-sm rounded-sm outline-none', {
70
- variants: {
71
- customTemplate: {
72
- true: 'block h-auto whitespace-normal',
73
- false: 'flex items-center gap-2 whitespace-nowrap',
74
- },
75
- active: {
76
- true: 'bg-primary/15 text-primary',
77
- false: 'hover:bg-primary/10 hover:text-foreground',
78
- },
79
- disabled: {
80
- true: 'opacity-50 cursor-not-allowed pointer-events-none',
81
- false: '',
82
- },
83
- },
84
- defaultVariants: {
85
- customTemplate: false,
86
- active: false,
87
- disabled: false,
88
- },
89
- });
90
-
91
- class ZAutocompleteComponent {
92
- _injector = inject(Injector);
93
- _destroyRef = inject(DestroyRef);
94
- _query$ = new Subject();
95
- triggerRef = viewChild('triggerEl', ...(ngDevMode ? [{ debugName: "triggerRef" }] : []));
96
- inputRef = viewChild('inputEl', ...(ngDevMode ? [{ debugName: "inputRef" }] : []));
97
- dropdownTpl = viewChild('dropdownTpl', ...(ngDevMode ? [{ debugName: "dropdownTpl" }] : []));
98
- virtualScrollRef = viewChild('virtualScrollElement', ...(ngDevMode ? [{ debugName: "virtualScrollRef" }] : []));
99
- optionsContainerRef = viewChild('optionsContainer', ...(ngDevMode ? [{ debugName: "optionsContainerRef" }] : []));
100
- loadMoreSentinelRef = viewChild('loadMoreSentinel', ...(ngDevMode ? [{ debugName: "loadMoreSentinelRef" }] : []));
101
- virtualOptionElements = viewChildren('virtualOptionEl', ...(ngDevMode ? [{ debugName: "virtualOptionElements" }] : []));
102
- customOptionDirective = contentChild((ZAutocompleteOptionDirective), ...(ngDevMode ? [{ debugName: "customOptionDirective" }] : []));
103
- class = input('', ...(ngDevMode ? [{ debugName: "class" }] : []));
104
- zOptions = input([], ...(ngDevMode ? [{ debugName: "zOptions" }] : []));
105
- zConfig = input({}, ...(ngDevMode ? [{ debugName: "zConfig" }] : []));
106
- zSize = input('default', ...(ngDevMode ? [{ debugName: "zSize" }] : []));
107
- zType = input('default', ...(ngDevMode ? [{ debugName: "zType" }] : []));
108
- zLabel = input('', ...(ngDevMode ? [{ debugName: "zLabel" }] : []));
109
- zLabelClass = input('', ...(ngDevMode ? [{ debugName: "zLabelClass" }] : []));
110
- zPlaceholder = input('', ...(ngDevMode ? [{ debugName: "zPlaceholder" }] : []));
111
- zDisabled = input(false, { ...(ngDevMode ? { debugName: "zDisabled" } : {}), transform: zTransform });
112
- zReadonly = input(false, { ...(ngDevMode ? { debugName: "zReadonly" } : {}), transform: zTransform });
113
- zLoading = input(false, { ...(ngDevMode ? { debugName: "zLoading" } : {}), transform: zTransform });
114
- zLoadingOutline = input(false, { ...(ngDevMode ? { debugName: "zLoadingOutline" } : {}), transform: zTransform });
115
- zRequired = input(false, { ...(ngDevMode ? { debugName: "zRequired" } : {}), transform: zTransform });
116
- zPrefix = input('', ...(ngDevMode ? [{ debugName: "zPrefix" }] : []));
117
- zSuffix = input('', ...(ngDevMode ? [{ debugName: "zSuffix" }] : []));
118
- zAllowClear = input(true, { ...(ngDevMode ? { debugName: "zAllowClear" } : {}), transform: zTransform });
119
- zVirtualScroll = input(false, { ...(ngDevMode ? { debugName: "zVirtualScroll" } : {}), transform: zTransform });
120
- zDynamicSize = input(true, { ...(ngDevMode ? { debugName: "zDynamicSize" } : {}), transform: zTransform });
121
- zOptionHeight = input(36, ...(ngDevMode ? [{ debugName: "zOptionHeight" }] : []));
122
- zHeightExpand = input(280, ...(ngDevMode ? [{ debugName: "zHeightExpand" }] : []));
123
- zMaxVisible = input(null, ...(ngDevMode ? [{ debugName: "zMaxVisible" }] : []));
124
- zResetOnSelect = input(true, { ...(ngDevMode ? { debugName: "zResetOnSelect" } : {}), transform: zTransform });
125
- zEmptyText = input('', ...(ngDevMode ? [{ debugName: "zEmptyText" }] : []));
126
- zEmptyIcon = input('lucideSearchX', ...(ngDevMode ? [{ debugName: "zEmptyIcon" }] : []));
127
- zNoDataText = input('', ...(ngDevMode ? [{ debugName: "zNoDataText" }] : []));
128
- zNoDataIcon = input('lucidePackageOpen', ...(ngDevMode ? [{ debugName: "zNoDataIcon" }] : []));
129
- zAllowCustomValue = input(false, { ...(ngDevMode ? { debugName: "zAllowCustomValue" } : {}), transform: zTransform });
130
- zDebounceTime = input(200, ...(ngDevMode ? [{ debugName: "zDebounceTime" }] : []));
131
- zLoadingMore = input(false, { ...(ngDevMode ? { debugName: "zLoadingMore" } : {}), transform: zTransform });
132
- zEnableLoadMore = input(false, { ...(ngDevMode ? { debugName: "zEnableLoadMore" } : {}), transform: zTransform });
133
- zScrollDistance = input(2, ...(ngDevMode ? [{ debugName: "zScrollDistance" }] : []));
134
- zKey = input('', ...(ngDevMode ? [{ debugName: "zKey" }] : []));
135
- zOptionTemplate = input(null, ...(ngDevMode ? [{ debugName: "zOptionTemplate" }] : []));
136
- zOnSearch = output();
137
- zOnLoadMore = output();
138
- zOnSelect = output();
139
- zOnEnter = output();
140
- zOnCommit = output();
141
- zValueChange = output();
142
- zOnBlur = output();
143
- zOnFocus = output();
144
- zControl = output();
145
- zEvent = output();
146
- _value = signal('', ...(ngDevMode ? [{ debugName: "_value" }] : []));
147
- _disabled = signal(false, ...(ngDevMode ? [{ debugName: "_disabled" }] : []));
148
- _formControl = signal(null, ...(ngDevMode ? [{ debugName: "_formControl" }] : []));
149
- _popoverControl = signal(null, ...(ngDevMode ? [{ debugName: "_popoverControl" }] : []));
150
- _selectedOption = signal(null, ...(ngDevMode ? [{ debugName: "_selectedOption" }] : []));
151
- _asyncOptions = signal([], ...(ngDevMode ? [{ debugName: "_asyncOptions" }] : []));
152
- _asyncKeyword = signal('', ...(ngDevMode ? [{ debugName: "_asyncKeyword" }] : []));
153
- _asyncPage = signal(1, ...(ngDevMode ? [{ debugName: "_asyncPage" }] : []));
154
- _asyncHasMore = signal(false, ...(ngDevMode ? [{ debugName: "_asyncHasMore" }] : []));
155
- _asyncLoading = signal(false, ...(ngDevMode ? [{ debugName: "_asyncLoading" }] : []));
156
- _asyncLoadingMore = signal(false, ...(ngDevMode ? [{ debugName: "_asyncLoadingMore" }] : []));
157
- uiState = signal({
158
- isOpen: false,
159
- isFocused: false,
160
- touched: false,
161
- dirty: false,
162
- }, ...(ngDevMode ? [{ debugName: "uiState" }] : []));
163
- actualPosition = signal('bottom', ...(ngDevMode ? [{ debugName: "actualPosition" }] : []));
164
- autocompleteId = zUuid('z-autocomplete');
165
- dropdownId = `${this.autocompleteId}-dropdown`;
166
- inputValue = signal('', ...(ngDevMode ? [{ debugName: "inputValue" }] : []));
167
- debouncedQuery = signal('', ...(ngDevMode ? [{ debugName: "debouncedQuery" }] : []));
168
- searchQuery = signal('', ...(ngDevMode ? [{ debugName: "searchQuery" }] : []));
169
- activeIndex = signal(-1, ...(ngDevMode ? [{ debugName: "activeIndex" }] : []));
170
- dropdownWidth = signal(0, ...(ngDevMode ? [{ debugName: "dropdownWidth" }] : []));
171
- _pendingSearch = signal(false, ...(ngDevMode ? [{ debugName: "_pendingSearch" }] : []));
172
- _localLoadingTimeout = null;
173
- _loadMoreObserver = null;
174
- _virtualScrollListener = null;
175
- _asyncLoadSubscription = null;
176
- _asyncRequestId = 0;
177
- _lastFilteredOptionsLength = 0;
178
- _shouldScrollActiveOption = false;
179
- /** Stores input value before keyboard navigation for ESC revert */
180
- _valueBeforeNavigation = null;
181
- virtualizer = injectVirtualizer(() => ({
182
- scrollElement: this.virtualScrollRef(),
183
- count: this.filteredOptions().length,
184
- estimateSize: () => this.effectiveOptionHeight(),
185
- measureElement: (element) => element.getBoundingClientRect().height,
186
- overscan: 5,
187
- }));
188
- _measureVirtualItems = effect(() => {
189
- if (!this.zDynamicSize()) {
190
- return;
191
- }
192
- const elements = this.virtualOptionElements();
193
- for (const el of elements) {
194
- this.virtualizer.measureElement(el.nativeElement);
195
- }
196
- }, ...(ngDevMode ? [{ debugName: "_measureVirtualItems" }] : []));
197
- config = computed(() => ({
198
- ...Z_AUTOCOMPLETE_DEFAULT_CONFIG,
199
- ...this.zConfig(),
200
- }), ...(ngDevMode ? [{ debugName: "config" }] : []));
201
- hasAsyncOptions = computed(() => !!this.config().async?.load, ...(ngDevMode ? [{ debugName: "hasAsyncOptions" }] : []));
202
- asyncSelectedOptions = computed(() => zResolveAsyncSelectedOptions(this.config().async), ...(ngDevMode ? [{ debugName: "asyncSelectedOptions" }] : []));
203
- sourceOptions = computed(() => {
204
- if (!this.hasAsyncOptions()) {
205
- return this.zOptions();
206
- }
207
- return zMergeAsyncOptions(this._asyncOptions(), this.asyncSelectedOptions(), this.config().async?.dedupeBy);
208
- }, ...(ngDevMode ? [{ debugName: "sourceOptions" }] : []));
209
- isLoading = computed(() => this.zLoading() || this._asyncLoading(), ...(ngDevMode ? [{ debugName: "isLoading" }] : []));
210
- isLoadingMore = computed(() => this.zLoadingMore() || this._asyncLoadingMore(), ...(ngDevMode ? [{ debugName: "isLoadingMore" }] : []));
211
- canLoadMore = computed(() => this.hasAsyncOptions() ? this._asyncHasMore() : this.zEnableLoadMore(), ...(ngDevMode ? [{ debugName: "canLoadMore" }] : []));
212
- isDisabled = computed(() => this._disabled() || this.zDisabled(), ...(ngDevMode ? [{ debugName: "isDisabled" }] : []));
213
- isReadonly = computed(() => this.zReadonly(), ...(ngDevMode ? [{ debugName: "isReadonly" }] : []));
214
- isInteractionDisabled = computed(() => this.isDisabled() || this.isReadonly() || this.zLoading(), ...(ngDevMode ? [{ debugName: "isInteractionDisabled" }] : []));
215
- effectiveOptionHeight = computed(() => this.zOptionHeight() || this.config().optionHeight, ...(ngDevMode ? [{ debugName: "effectiveOptionHeight" }] : []));
216
- effectiveHeightExpand = computed(() => this.zHeightExpand() || this.config().dropdownMaxHeight, ...(ngDevMode ? [{ debugName: "effectiveHeightExpand" }] : []));
217
- effectiveEmptyText = computed(() => this.zEmptyText() || this.config().emptyMessage, ...(ngDevMode ? [{ debugName: "effectiveEmptyText" }] : []));
218
- effectiveNoDataText = computed(() => this.zNoDataText() || this.config().noDataMessage, ...(ngDevMode ? [{ debugName: "effectiveNoDataText" }] : []));
219
- effectiveDebounceTime = computed(() => this.zConfig().debounceTime ?? this.zDebounceTime(), ...(ngDevMode ? [{ debugName: "effectiveDebounceTime" }] : []));
220
- effectiveOptionTemplate = computed(() => {
221
- const directive = this.customOptionDirective();
222
- if (directive) {
223
- return directive.templateRef;
224
- }
225
- return this.zOptionTemplate();
226
- }, ...(ngDevMode ? [{ debugName: "effectiveOptionTemplate" }] : []));
227
- hasCustomOptionTemplate = computed(() => this.effectiveOptionTemplate() !== null, ...(ngDevMode ? [{ debugName: "hasCustomOptionTemplate" }] : []));
228
- selected = computed(() => {
229
- const option = this._selectedOption();
230
- if (!option) {
231
- return [];
232
- }
233
- return [option];
234
- }, ...(ngDevMode ? [{ debugName: "selected" }] : []));
235
- highlightQuery = computed(() => this.zType() === 'address_bar' ? this.searchQuery() : this.debouncedQuery(), ...(ngDevMode ? [{ debugName: "highlightQuery" }] : []));
236
- /**
237
- * Local-mode loading state after debounce to avoid quick flicker.
238
- * Server mode relies only on zLoading from parent.
239
- */
240
- isLoadingState = computed(() => {
241
- if (this.config().serverSearch || this.hasAsyncOptions()) {
242
- return false;
243
- }
244
- const hasInput = this.inputValue().trim() !== '';
245
- return hasInput && this._pendingSearch();
246
- }, ...(ngDevMode ? [{ debugName: "isLoadingState" }] : []));
247
- isPositionTop = computed(() => {
248
- const pos = this.actualPosition();
249
- return pos.startsWith('top');
250
- }, ...(ngDevMode ? [{ debugName: "isPositionTop" }] : []));
251
- shouldUseVirtualScroll = computed(() => {
252
- if (this.zVirtualScroll()) {
253
- return true;
254
- }
255
- if (this.hasCustomOptionTemplate()) {
256
- return false;
257
- }
258
- if (this.canLoadMore()) {
259
- return false;
260
- }
261
- const maxVisible = this.zMaxVisible();
262
- if (maxVisible !== null && this.sourceOptions().length > maxVisible) {
263
- return true;
264
- }
265
- return this.sourceOptions().length > 50;
266
- }, ...(ngDevMode ? [{ debugName: "shouldUseVirtualScroll" }] : []));
267
- filteredOptions = computed(() => {
268
- const options = this.sourceOptions();
269
- const cfg = this.config();
270
- const allowCustom = this.zAllowCustomValue();
271
- const query = this.zType() === 'address_bar' ? this.searchQuery() : this.debouncedQuery();
272
- // If server search is enabled, skip local filtering - just apply maxDisplayed limit
273
- if (cfg.serverSearch || this.hasAsyncOptions()) {
274
- let result = options;
275
- if (cfg.maxDisplayed && options.length > cfg.maxDisplayed) {
276
- result = options.slice(0, cfg.maxDisplayed);
277
- }
278
- // Allow custom value: if no results from server, show typed text as option
279
- if (allowCustom && result.length === 0 && query.trim() !== '') {
280
- return [{ label: query.trim(), value: query.trim() }];
281
- }
282
- return result;
283
- }
284
- if (!query || query.trim() === '') {
285
- if (cfg.maxDisplayed && options.length > cfg.maxDisplayed) {
286
- return options.slice(0, cfg.maxDisplayed);
287
- }
288
- return options;
289
- }
290
- const normalizedQuery = zRemoveVietnamese(query.toLowerCase());
291
- let filtered = options.filter(opt => {
292
- const normalizedLabel = zRemoveVietnamese(opt.label.toLowerCase());
293
- return normalizedLabel.includes(normalizedQuery);
294
- });
295
- if (cfg.maxDisplayed && filtered.length > cfg.maxDisplayed) {
296
- filtered = filtered.slice(0, cfg.maxDisplayed);
297
- }
298
- if (allowCustom && filtered.length === 0 && query.trim() !== '') {
299
- return [{ label: query.trim(), value: query.trim() }];
300
- }
301
- return filtered;
302
- }, ...(ngDevMode ? [{ debugName: "filteredOptions" }] : []));
303
- optionViews = computed(() => this.filteredOptions().map((option, index) => ({
304
- option,
305
- index,
306
- trackKey: `${String(this._getOptionKey(option))}::${index}`,
307
- })), ...(ngDevMode ? [{ debugName: "optionViews" }] : []));
308
- hasValue = computed(() => {
309
- const value = this.inputValue();
310
- return value !== null && value !== undefined && value.trim() !== '';
311
- }, ...(ngDevMode ? [{ debugName: "hasValue" }] : []));
312
- currentStatus = computed(() => {
313
- if (this.isDisabled()) {
314
- return 'disabled';
315
- }
316
- if (this.isReadonly()) {
317
- return 'readonly';
318
- }
319
- if (this.uiState().isOpen) {
320
- return 'open';
321
- }
322
- return 'default';
323
- }, ...(ngDevMode ? [{ debugName: "currentStatus" }] : []));
324
- inputClasses = computed(() => zMergeClasses(zAutocompleteInputVariants({
325
- zSize: this.zSize(),
326
- zStatus: this.currentStatus(),
327
- }), this.zLoading() && this.zLoadingOutline() ? 'z-loading-outline-active !ring-ring/50 !ring-[3px]' : '', this.class()), ...(ngDevMode ? [{ debugName: "inputClasses" }] : []));
328
- state = computed(() => ({
329
- focused: this.uiState().isFocused,
330
- touched: this.uiState().touched,
331
- dirty: this.uiState().dirty,
332
- disabled: this.isDisabled(),
333
- readonly: this.isReadonly(),
334
- open: this.uiState().isOpen,
335
- }), ...(ngDevMode ? [{ debugName: "state" }] : []));
336
- _onChange = () => void 0;
337
- _onTouched = () => void 0;
338
- _ngControl = null;
339
- _isNavigationFilling = false;
340
- constructor() {
341
- effect(onCleanup => {
342
- const triggerEl = this.triggerRef()?.nativeElement;
343
- if (!triggerEl) {
344
- return;
345
- }
346
- const observer = new ResizeObserver(() => {
347
- this.dropdownWidth.set(triggerEl.getBoundingClientRect().width);
348
- });
349
- observer.observe(triggerEl);
350
- this.dropdownWidth.set(triggerEl.getBoundingClientRect().width);
351
- onCleanup(() => {
352
- observer.disconnect();
353
- });
354
- });
355
- effect(() => {
356
- const options = this.filteredOptions();
357
- const { isOpen } = this.uiState();
358
- if (!isOpen || options.length === 0) {
359
- this._lastFilteredOptionsLength = options.length;
360
- return;
361
- }
362
- const previousLength = this._lastFilteredOptionsLength;
363
- const currentIndex = untracked(() => this.activeIndex());
364
- this._lastFilteredOptionsLength = options.length;
365
- if (currentIndex < 0 || currentIndex >= options.length || options.length <= previousLength) {
366
- this.activeIndex.set(0);
367
- }
368
- });
369
- effect(() => {
370
- const idx = this.activeIndex();
371
- const { isOpen } = this.uiState();
372
- if (!isOpen || idx < 0) {
373
- return;
374
- }
375
- if (!this._shouldScrollActiveOption || this.shouldUseVirtualScroll() || this.canLoadMore()) {
376
- return;
377
- }
378
- this._shouldScrollActiveOption = false;
379
- const container = this.optionsContainerRef()?.nativeElement;
380
- if (!container) {
381
- return;
382
- }
383
- const options = container.querySelectorAll('.z-autocomplete-option');
384
- const activeOption = options[idx];
385
- if (activeOption) {
386
- activeOption.scrollIntoView({ block: 'nearest' });
387
- }
388
- });
389
- effect(onCleanup => {
390
- const sentinel = this.loadMoreSentinelRef();
391
- const { isOpen } = this.uiState();
392
- const optionsCount = this.filteredOptions().length;
393
- if (!sentinel || !isOpen || optionsCount === 0 || !this.canLoadMore()) {
394
- this._cleanupLoadMoreObserver();
395
- return;
396
- }
397
- this._setupLoadMoreObserver();
398
- onCleanup(() => {
399
- this._cleanupLoadMoreObserver();
400
- });
401
- });
402
- effect(onCleanup => {
403
- const { isOpen } = this.uiState();
404
- const useVirtual = this.shouldUseVirtualScroll();
405
- const optionsCount = this.filteredOptions().length;
406
- if (!isOpen || !useVirtual || optionsCount === 0) {
407
- this._cleanupVirtualScrollListener();
408
- return;
409
- }
410
- requestAnimationFrame(() => {
411
- requestAnimationFrame(() => {
412
- this._setupVirtualScrollLoadMore();
413
- });
414
- });
415
- onCleanup(() => {
416
- this._cleanupVirtualScrollListener();
417
- });
418
- });
419
- }
420
- ngOnInit() {
421
- this._setupDebounce();
422
- this._emitControl();
423
- queueMicrotask(() => {
424
- try {
425
- this._ngControl = this._injector.get(NgControl, null);
426
- if (this._ngControl?.control) {
427
- this._formControl.set(this._ngControl.control);
428
- }
429
- }
430
- catch {
431
- this._ngControl = null;
432
- }
433
- });
434
- }
435
- writeValue(value) {
436
- this._value.set(value ?? '');
437
- this.inputValue.set(value ?? '');
438
- this.debouncedQuery.set(value ?? '');
439
- if (this.zType() === 'address_bar') {
440
- this.searchQuery.set(value ?? '');
441
- }
442
- }
443
- registerOnChange(fn) {
444
- this._onChange = fn;
445
- }
446
- registerOnTouched(fn) {
447
- this._onTouched = fn;
448
- }
449
- setDisabledState(isDisabled) {
450
- this._disabled.set(isDisabled);
451
- }
452
- onInput(event) {
453
- const { value } = event.target;
454
- this._clearLocalLoadingTimer();
455
- this._pendingSearch.set(false);
456
- this.inputValue.set(value);
457
- this._value.set(value);
458
- this.uiState.update(s => ({ ...s, dirty: true }));
459
- this._onChange(value);
460
- if (!this._isNavigationFilling) {
461
- this._query$.next(value);
462
- }
463
- this.zValueChange.emit(value);
464
- if (!this.uiState().isOpen) {
465
- this._openPanel();
466
- }
467
- this._selectedOption.set(null);
468
- }
469
- onFocus(event) {
470
- if (this.isReadonly()) {
471
- event.target.blur();
472
- return;
473
- }
474
- this.uiState.update(s => ({ ...s, isFocused: true }));
475
- this.zOnFocus.emit(event);
476
- this.zEvent.emit(zCreateEvent('focus', event));
477
- this._openPanel();
478
- }
479
- onInputClick() {
480
- if (this.uiState().isOpen) {
481
- return;
482
- }
483
- this._openPanel();
484
- }
485
- onBlur(event) {
486
- this.uiState.update(s => ({ ...s, isFocused: false }));
487
- this.zOnBlur.emit(event);
488
- this.zEvent.emit(zCreateEvent('blur', event));
489
- if (this.uiState().dirty) {
490
- this.uiState.update(s => ({ ...s, touched: true }));
491
- }
492
- this._onTouched();
493
- const currentValue = this.inputValue();
494
- this.zOnCommit.emit({ value: currentValue, source: 'blur' });
495
- }
496
- onKeydown(event) {
497
- if (this.isInteractionDisabled()) {
498
- return;
499
- }
500
- const { isOpen } = this.uiState();
501
- const options = this.filteredOptions();
502
- const currentValue = this.inputValue();
503
- const isAddressBarMode = this.zType() === 'address_bar';
504
- if (event.key === 'Enter') {
505
- event.preventDefault();
506
- if (!isOpen) {
507
- this._openPanel();
508
- return;
509
- }
510
- this._handleEnterKey(options, currentValue);
511
- return;
512
- }
513
- if (!isOpen) {
514
- if (event.key === 'ArrowDown') {
515
- event.preventDefault();
516
- this._openPanel();
517
- }
518
- return;
519
- }
520
- switch (event.key) {
521
- case 'ArrowDown':
522
- event.preventDefault();
523
- if (this._valueBeforeNavigation === null) {
524
- this._valueBeforeNavigation = currentValue;
525
- }
526
- this._shouldScrollActiveOption = true;
527
- this.activeIndex.update(i => (i < options.length - 1 ? i + 1 : 0));
528
- if (isAddressBarMode) {
529
- this._fillInputFromActiveOption();
530
- }
531
- break;
532
- case 'ArrowUp':
533
- event.preventDefault();
534
- if (this._valueBeforeNavigation === null) {
535
- this._valueBeforeNavigation = currentValue;
536
- }
537
- this._shouldScrollActiveOption = true;
538
- this.activeIndex.update(i => (i > 0 ? i - 1 : options.length - 1));
539
- if (isAddressBarMode) {
540
- this._fillInputFromActiveOption();
541
- }
542
- break;
543
- case 'Escape':
544
- event.preventDefault();
545
- if (isAddressBarMode && this._valueBeforeNavigation !== null) {
546
- this._revertToValueBeforeNavigation();
547
- }
548
- this._valueBeforeNavigation = null;
549
- this._closePanel();
550
- break;
551
- case 'Tab':
552
- this._valueBeforeNavigation = null;
553
- this._closePanel();
554
- break;
555
- }
556
- }
557
- _handleEnterKey(options, currentValue) {
558
- const trimmedValue = currentValue.trim();
559
- this._valueBeforeNavigation = null;
560
- this.zOnCommit.emit({ value: trimmedValue, source: 'enter' });
561
- if (this.zType() === 'address_bar') {
562
- this._closePanel();
563
- return;
564
- }
565
- const idx = this.activeIndex();
566
- if (options.length > 0) {
567
- const selectedIdx = idx >= 0 && idx < options.length ? idx : 0;
568
- this.selectOption(options[selectedIdx]);
569
- return;
570
- }
571
- if (this.zAllowCustomValue() && trimmedValue) {
572
- this.zOnEnter.emit(trimmedValue);
573
- this._resetInput();
574
- }
575
- }
576
- _fillInputFromActiveOption() {
577
- const idx = this.activeIndex();
578
- const options = this.filteredOptions();
579
- if (idx < 0 || idx >= options.length) {
580
- return;
581
- }
582
- const option = options[idx];
583
- this._isNavigationFilling = true;
584
- this.inputValue.set(option.label);
585
- this._value.set(option.label);
586
- this._onChange(option.label);
587
- this.zValueChange.emit(option.label);
588
- const inputEl = this.inputRef()?.nativeElement;
589
- if (inputEl) {
590
- inputEl.value = option.label;
591
- }
592
- setTimeout(() => {
593
- this._isNavigationFilling = false;
594
- }, 0);
595
- }
596
- _revertToValueBeforeNavigation() {
597
- if (this._valueBeforeNavigation === null) {
598
- return;
599
- }
600
- const value = this._valueBeforeNavigation;
601
- this._isNavigationFilling = true;
602
- this.inputValue.set(value);
603
- this._value.set(value);
604
- this._onChange(value);
605
- this.zValueChange.emit(value);
606
- if (this.zType() === 'address_bar') {
607
- this.searchQuery.set(value);
608
- }
609
- const inputEl = this.inputRef()?.nativeElement;
610
- if (inputEl) {
611
- inputEl.value = value;
612
- }
613
- this._valueBeforeNavigation = null;
614
- setTimeout(() => {
615
- this._isNavigationFilling = false;
616
- }, 0);
617
- }
618
- _resetInput() {
619
- if (!this.zResetOnSelect()) {
620
- this._closePanel();
621
- this.activeIndex.set(-1);
622
- return;
623
- }
624
- this.inputValue.set('');
625
- this._value.set('');
626
- this._onChange('');
627
- this.zValueChange.emit('');
628
- if (!this.hasAsyncOptions()) {
629
- this._query$.next('');
630
- }
631
- this._closePanel();
632
- this.activeIndex.set(-1);
633
- }
634
- onPopoverControl(control) {
635
- this._popoverControl.set(control);
636
- }
637
- onPopoverShow() {
638
- this.uiState.update(s => ({ ...s, isOpen: true }));
639
- this._resetOptionsScrollTop();
640
- this._loadAsyncOptionsOnFocus();
641
- // Panel chỉ mở khi user focus/click thật, tức ancestor (vd. modal) đã hết animation transform —
642
- // đo lại ở đây để tránh dùng width "đóng băng" từ lúc effect khởi tạo đo hụt giữa lúc scale().
643
- const triggerEl = this.triggerRef()?.nativeElement;
644
- if (triggerEl) {
645
- this.dropdownWidth.set(triggerEl.getBoundingClientRect().width);
646
- }
647
- setTimeout(() => {
648
- this.inputRef()?.nativeElement.focus();
649
- }, 50);
650
- }
651
- onPopoverHideStart() {
652
- this.uiState.update(s => ({ ...s, isOpen: false }));
653
- this.activeIndex.set(-1);
654
- this._clearLocalLoadingTimer();
655
- this._pendingSearch.set(false);
656
- this.debouncedQuery.set('');
657
- if (!this.hasAsyncOptions()) {
658
- this._query$.next('');
659
- }
660
- }
661
- onPopoverHideEnd() {
662
- this.actualPosition.set('bottom');
663
- }
664
- onPositionChange(position) {
665
- this.actualPosition.set(position);
666
- }
667
- selectOption(option) {
668
- if (option.disabled) {
669
- return;
670
- }
671
- this.uiState.update(s => ({ ...s, dirty: true }));
672
- this.zOnSelect.emit(option);
673
- this._selectedOption.set(option);
674
- const newValue = this.zResetOnSelect() ? '' : option.label;
675
- this.inputValue.set(newValue);
676
- this._value.set(newValue);
677
- this.debouncedQuery.set(newValue);
678
- this._onChange(newValue);
679
- this.zValueChange.emit(newValue);
680
- this._valueBeforeNavigation = null;
681
- if (this.config().closeOnSelect) {
682
- this._closePanel();
683
- }
684
- this.activeIndex.set(-1);
685
- }
686
- clearInput(event) {
687
- event.stopPropagation();
688
- event.preventDefault();
689
- this.inputValue.set('');
690
- this._value.set('');
691
- this.uiState.update(s => ({ ...s, dirty: true }));
692
- this._onChange('');
693
- this.zValueChange.emit('');
694
- this._selectedOption.set(null);
695
- this._closePanel();
696
- this._clearLocalLoadingTimer();
697
- this._pendingSearch.set(false);
698
- this.debouncedQuery.set('');
699
- if (this.zType() === 'address_bar') {
700
- this.searchQuery.set('');
701
- }
702
- if (!this.hasAsyncOptions()) {
703
- this._query$.next('');
704
- }
705
- this.zOnCommit.emit({ value: '', source: 'blur' });
706
- this._resetAsyncOptions();
707
- setTimeout(() => {
708
- this.inputRef()?.nativeElement.focus();
709
- });
710
- }
711
- getOptionClasses(option, index) {
712
- return zAutocompleteOptionVariants({
713
- customTemplate: this.hasCustomOptionTemplate(),
714
- active: this.activeIndex() === index,
715
- disabled: option.disabled ?? false,
716
- });
717
- }
718
- trackByValue = (index, option) => {
719
- const key = this._getOptionKey(option);
720
- return `${String(key)}::${index}`;
721
- };
722
- focus() {
723
- this.inputRef()?.nativeElement.focus();
724
- }
725
- blur() {
726
- this.inputRef()?.nativeElement.blur();
727
- }
728
- clear() {
729
- this.inputValue.set('');
730
- this._value.set('');
731
- this.debouncedQuery.set('');
732
- this._onChange('');
733
- this.zValueChange.emit('');
734
- this._selectedOption.set(null);
735
- this._closePanel();
736
- this._clearLocalLoadingTimer();
737
- this._pendingSearch.set(false);
738
- this._resetAsyncOptions();
739
- if (this.zType() === 'address_bar') {
740
- this.searchQuery.set('');
741
- }
742
- }
743
- reset() {
744
- this.clear();
745
- this.uiState.update(s => ({ ...s, touched: false, dirty: false }));
746
- }
747
- open() {
748
- this._openPanel();
749
- }
750
- close() {
751
- this._closePanel();
752
- }
753
- setValue(value) {
754
- this._value.set(value);
755
- this.inputValue.set(value);
756
- this.debouncedQuery.set(value);
757
- this._selectedOption.set(null);
758
- this._onChange(value);
759
- if (this.zType() === 'address_bar') {
760
- this.searchQuery.set(value);
761
- }
762
- }
763
- _openPanel() {
764
- if (this.isInteractionDisabled()) {
765
- return;
766
- }
767
- this._popoverControl()?.show();
768
- }
769
- _closePanel() {
770
- this._popoverControl()?.close();
771
- }
772
- _setupDebounce() {
773
- this._query$
774
- .pipe(debounceTime(this.effectiveDebounceTime()), distinctUntilChanged(), takeUntilDestroyed(this._destroyRef))
775
- .subscribe(query => {
776
- if (this.zType() === 'address_bar') {
777
- this.searchQuery.set(query);
778
- }
779
- this.debouncedQuery.set(query);
780
- this.zOnSearch.emit(query);
781
- if (this.hasAsyncOptions()) {
782
- this._loadAsyncOptions(query, false);
783
- return;
784
- }
785
- if (this.config().serverSearch) {
786
- return;
787
- }
788
- this._clearLocalLoadingTimer();
789
- this._pendingSearch.set(true);
790
- this._localLoadingTimeout = setTimeout(() => {
791
- this._pendingSearch.set(false);
792
- this._localLoadingTimeout = null;
793
- }, 100);
794
- });
795
- }
796
- _loadAsyncOptionsOnFocus() {
797
- const asyncConfig = this.config().async;
798
- if (!asyncConfig?.loadOnFocus) {
799
- return;
800
- }
801
- const keyword = this.inputValue().trim();
802
- if (this._asyncKeyword() === keyword && this._asyncOptions().length > 0) {
803
- return;
804
- }
805
- this._loadAsyncOptions(keyword, false);
806
- }
807
- _loadAsyncOptions(keyword, append) {
808
- const asyncConfig = this.config().async;
809
- if (!asyncConfig) {
810
- return;
811
- }
812
- const normalizedKeyword = keyword.trim();
813
- const pageSize = asyncConfig.pageSize ?? Z_ASYNC_OPTIONS_DEFAULT_PAGE_SIZE;
814
- const { minLength } = this.config();
815
- const canLoadEmptyOnFocus = asyncConfig.loadOnFocus && normalizedKeyword.length === 0;
816
- if (!append && normalizedKeyword.length < minLength && !canLoadEmptyOnFocus) {
817
- this._resetAsyncOptions();
818
- return;
819
- }
820
- if (append && (!this._asyncHasMore() || this._asyncLoading() || this._asyncLoadingMore())) {
821
- return;
822
- }
823
- const page = append ? this._asyncPage() + 1 : 1;
824
- const requestId = ++this._asyncRequestId;
825
- const scrollTopBeforeAppend = append ? this._getAsyncOptionsScrollTop() : null;
826
- if (!append) {
827
- this._asyncLoadSubscription?.unsubscribe();
828
- this._asyncKeyword.set(normalizedKeyword);
829
- this._asyncLoading.set(true);
830
- this._asyncHasMore.set(false);
831
- }
832
- else {
833
- this._asyncLoadingMore.set(true);
834
- }
835
- let result;
836
- try {
837
- result = asyncConfig.load({
838
- keyword: normalizedKeyword,
839
- page,
840
- pageSize,
841
- });
842
- }
843
- catch (error) {
844
- this._handleAsyncOptionsError(error, append);
845
- return;
846
- }
847
- this._asyncLoadSubscription = zToAsyncOptionsObservable(result)
848
- .pipe(finalize(() => {
849
- if (requestId !== this._asyncRequestId) {
850
- return;
851
- }
852
- this._asyncLoading.set(false);
853
- this._asyncLoadingMore.set(false);
854
- }), takeUntilDestroyed(this._destroyRef))
855
- .subscribe({
856
- next: response => {
857
- if (requestId !== this._asyncRequestId) {
858
- return;
859
- }
860
- const nextItems = response.items ?? [];
861
- const previousCount = this._asyncOptions().length;
862
- const mergedOptions = append
863
- ? zMergeAsyncOptions(this._asyncOptions(), nextItems, asyncConfig.dedupeBy)
864
- : zMergeAsyncOptions([], nextItems, asyncConfig.dedupeBy);
865
- const hasNewItems = mergedOptions.length > previousCount;
866
- if (append && !hasNewItems) {
867
- this._asyncHasMore.set(false);
868
- this._restoreAsyncOptionsScrollTop(scrollTopBeforeAppend);
869
- return;
870
- }
871
- this._asyncOptions.set(mergedOptions);
872
- this._asyncPage.set(page);
873
- this._asyncHasMore.set(append && !hasNewItems ? false : zResolveAsyncOptionsHasMore(response, pageSize, mergedOptions.length));
874
- if (append) {
875
- this._restoreAsyncOptionsScrollTop(scrollTopBeforeAppend);
876
- return;
877
- }
878
- this._resetOptionsScrollTop();
879
- },
880
- error: error => {
881
- if (requestId !== this._asyncRequestId) {
882
- return;
883
- }
884
- this._handleAsyncOptionsError(error, append);
885
- },
886
- });
887
- }
888
- _handleAsyncOptionsError(error, append) {
889
- console.error('ZAutocomplete async options load failed:', error);
890
- if (!append) {
891
- this._asyncOptions.set([]);
892
- this._asyncPage.set(1);
893
- }
894
- this._asyncHasMore.set(false);
895
- this._asyncLoading.set(false);
896
- this._asyncLoadingMore.set(false);
897
- }
898
- _getAsyncOptionsScrollTop() {
899
- return this._getOptionsScrollElement()?.scrollTop ?? null;
900
- }
901
- _restoreAsyncOptionsScrollTop(scrollTop) {
902
- if (scrollTop === null) {
903
- return;
904
- }
905
- requestAnimationFrame(() => {
906
- const scrollElement = this._getOptionsScrollElement();
907
- if (scrollElement) {
908
- scrollElement.scrollTop = scrollTop;
909
- }
910
- });
911
- }
912
- _resetOptionsScrollTop(attempt = 0) {
913
- requestAnimationFrame(() => {
914
- const scrollElement = this._getOptionsScrollElement();
915
- if (!scrollElement && attempt < 3) {
916
- this._resetOptionsScrollTop(attempt + 1);
917
- return;
918
- }
919
- if (!scrollElement) {
920
- return;
921
- }
922
- if (this.shouldUseVirtualScroll()) {
923
- this.virtualizer.scrollToOffset(0);
924
- }
925
- scrollElement.scrollTop = 0;
926
- });
927
- }
928
- _getOptionsScrollElement() {
929
- if (this.shouldUseVirtualScroll()) {
930
- return this.virtualScrollRef()?.nativeElement ?? null;
931
- }
932
- return this.optionsContainerRef()?.nativeElement ?? null;
933
- }
934
- _resetAsyncOptions() {
935
- this._asyncLoadSubscription?.unsubscribe();
936
- this._asyncRequestId++;
937
- this._asyncOptions.set([]);
938
- this._asyncKeyword.set('');
939
- this._asyncPage.set(1);
940
- this._asyncHasMore.set(false);
941
- this._asyncLoading.set(false);
942
- this._asyncLoadingMore.set(false);
943
- }
944
- _clearLocalLoadingTimer() {
945
- if (!this._localLoadingTimeout) {
946
- return;
947
- }
948
- clearTimeout(this._localLoadingTimeout);
949
- this._localLoadingTimeout = null;
950
- }
951
- _setupLoadMoreObserver() {
952
- this._cleanupLoadMoreObserver();
953
- const sentinel = this.loadMoreSentinelRef()?.nativeElement;
954
- const container = this.optionsContainerRef()?.nativeElement;
955
- if (!sentinel || !container) {
956
- return;
957
- }
958
- this._loadMoreObserver = new IntersectionObserver(entries => {
959
- const entry = entries[0];
960
- if (entry?.isIntersecting && !this.isLoadingMore()) {
961
- this._handleLoadMore(container.scrollTop);
962
- }
963
- }, {
964
- root: container,
965
- rootMargin: '100px',
966
- threshold: 0,
967
- });
968
- this._loadMoreObserver.observe(sentinel);
969
- }
970
- _cleanupLoadMoreObserver() {
971
- if (!this._loadMoreObserver) {
972
- return;
973
- }
974
- this._loadMoreObserver.disconnect();
975
- this._loadMoreObserver = null;
976
- }
977
- _setupVirtualScrollLoadMore() {
978
- this._cleanupVirtualScrollListener();
979
- const scrollElement = this.virtualScrollRef()?.nativeElement;
980
- if (!scrollElement) {
981
- return;
982
- }
983
- const handleScroll = () => {
984
- if (this.isLoadingMore()) {
985
- return;
986
- }
987
- const { scrollTop, scrollHeight, clientHeight } = scrollElement;
988
- const threshold = clientHeight * this.zScrollDistance();
989
- const distanceFromBottom = scrollHeight - scrollTop - clientHeight;
990
- if (distanceFromBottom <= threshold) {
991
- this._handleLoadMore(scrollTop);
992
- }
993
- };
994
- scrollElement.addEventListener('scroll', handleScroll);
995
- this._virtualScrollListener = () => {
996
- scrollElement.removeEventListener('scroll', handleScroll);
997
- };
998
- }
999
- _cleanupVirtualScrollListener() {
1000
- if (!this._virtualScrollListener) {
1001
- return;
1002
- }
1003
- this._virtualScrollListener();
1004
- this._virtualScrollListener = null;
1005
- }
1006
- _handleLoadMore(scrollTop) {
1007
- if (this.hasAsyncOptions()) {
1008
- if (!this.canLoadMore()) {
1009
- return;
1010
- }
1011
- this._loadAsyncOptions(this._asyncKeyword(), true);
1012
- return;
1013
- }
1014
- this.zOnLoadMore.emit({
1015
- currentCount: this.filteredOptions().length,
1016
- scrollTop,
1017
- });
1018
- }
1019
- _emitControl() {
1020
- this.zControl.emit({
1021
- focus: () => this.focus(),
1022
- blur: () => this.blur(),
1023
- clear: () => this.clear(),
1024
- reset: () => this.reset(),
1025
- open: () => this.open(),
1026
- close: () => this.close(),
1027
- setValue: (val) => this.setValue(val),
1028
- value: this._value.asReadonly(),
1029
- selected: this.selected,
1030
- state: this.state,
1031
- });
1032
- }
1033
- _getOptionKey(option) {
1034
- const key = this.zKey();
1035
- if (key && key in option) {
1036
- return option[key];
1037
- }
1038
- if (key && typeof option.value === 'object' && option.value !== null && key in option.value) {
1039
- return option.value[key];
1040
- }
1041
- return option.value;
1042
- }
1043
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZAutocompleteComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1044
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.9", type: ZAutocompleteComponent, isStandalone: true, selector: "z-autocomplete", inputs: { class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, zOptions: { classPropertyName: "zOptions", publicName: "zOptions", isSignal: true, isRequired: false, transformFunction: null }, zConfig: { classPropertyName: "zConfig", publicName: "zConfig", isSignal: true, isRequired: false, transformFunction: null }, zSize: { classPropertyName: "zSize", publicName: "zSize", isSignal: true, isRequired: false, transformFunction: null }, zType: { classPropertyName: "zType", publicName: "zType", isSignal: true, isRequired: false, transformFunction: null }, zLabel: { classPropertyName: "zLabel", publicName: "zLabel", isSignal: true, isRequired: false, transformFunction: null }, zLabelClass: { classPropertyName: "zLabelClass", publicName: "zLabelClass", isSignal: true, isRequired: false, transformFunction: null }, zPlaceholder: { classPropertyName: "zPlaceholder", publicName: "zPlaceholder", isSignal: true, isRequired: false, transformFunction: null }, zDisabled: { classPropertyName: "zDisabled", publicName: "zDisabled", isSignal: true, isRequired: false, transformFunction: null }, zReadonly: { classPropertyName: "zReadonly", publicName: "zReadonly", isSignal: true, isRequired: false, transformFunction: null }, zLoading: { classPropertyName: "zLoading", publicName: "zLoading", isSignal: true, isRequired: false, transformFunction: null }, zLoadingOutline: { classPropertyName: "zLoadingOutline", publicName: "zLoadingOutline", isSignal: true, isRequired: false, transformFunction: null }, zRequired: { classPropertyName: "zRequired", publicName: "zRequired", isSignal: true, isRequired: false, transformFunction: null }, zPrefix: { classPropertyName: "zPrefix", publicName: "zPrefix", isSignal: true, isRequired: false, transformFunction: null }, zSuffix: { classPropertyName: "zSuffix", publicName: "zSuffix", isSignal: true, isRequired: false, transformFunction: null }, zAllowClear: { classPropertyName: "zAllowClear", publicName: "zAllowClear", isSignal: true, isRequired: false, transformFunction: null }, zVirtualScroll: { classPropertyName: "zVirtualScroll", publicName: "zVirtualScroll", isSignal: true, isRequired: false, transformFunction: null }, zDynamicSize: { classPropertyName: "zDynamicSize", publicName: "zDynamicSize", isSignal: true, isRequired: false, transformFunction: null }, zOptionHeight: { classPropertyName: "zOptionHeight", publicName: "zOptionHeight", isSignal: true, isRequired: false, transformFunction: null }, zHeightExpand: { classPropertyName: "zHeightExpand", publicName: "zHeightExpand", isSignal: true, isRequired: false, transformFunction: null }, zMaxVisible: { classPropertyName: "zMaxVisible", publicName: "zMaxVisible", isSignal: true, isRequired: false, transformFunction: null }, zResetOnSelect: { classPropertyName: "zResetOnSelect", publicName: "zResetOnSelect", isSignal: true, isRequired: false, transformFunction: null }, zEmptyText: { classPropertyName: "zEmptyText", publicName: "zEmptyText", isSignal: true, isRequired: false, transformFunction: null }, zEmptyIcon: { classPropertyName: "zEmptyIcon", publicName: "zEmptyIcon", isSignal: true, isRequired: false, transformFunction: null }, zNoDataText: { classPropertyName: "zNoDataText", publicName: "zNoDataText", isSignal: true, isRequired: false, transformFunction: null }, zNoDataIcon: { classPropertyName: "zNoDataIcon", publicName: "zNoDataIcon", isSignal: true, isRequired: false, transformFunction: null }, zAllowCustomValue: { classPropertyName: "zAllowCustomValue", publicName: "zAllowCustomValue", isSignal: true, isRequired: false, transformFunction: null }, zDebounceTime: { classPropertyName: "zDebounceTime", publicName: "zDebounceTime", isSignal: true, isRequired: false, transformFunction: null }, zLoadingMore: { classPropertyName: "zLoadingMore", publicName: "zLoadingMore", isSignal: true, isRequired: false, transformFunction: null }, zEnableLoadMore: { classPropertyName: "zEnableLoadMore", publicName: "zEnableLoadMore", isSignal: true, isRequired: false, transformFunction: null }, zScrollDistance: { classPropertyName: "zScrollDistance", publicName: "zScrollDistance", isSignal: true, isRequired: false, transformFunction: null }, zKey: { classPropertyName: "zKey", publicName: "zKey", isSignal: true, isRequired: false, transformFunction: null }, zOptionTemplate: { classPropertyName: "zOptionTemplate", publicName: "zOptionTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { zOnSearch: "zOnSearch", zOnLoadMore: "zOnLoadMore", zOnSelect: "zOnSelect", zOnEnter: "zOnEnter", zOnCommit: "zOnCommit", zValueChange: "zValueChange", zOnBlur: "zOnBlur", zOnFocus: "zOnFocus", zControl: "zControl", zEvent: "zEvent" }, providers: [
1045
- {
1046
- provide: NG_VALUE_ACCESSOR,
1047
- useExisting: forwardRef(() => ZAutocompleteComponent),
1048
- multi: true,
1049
- },
1050
- ], queries: [{ propertyName: "customOptionDirective", first: true, predicate: (ZAutocompleteOptionDirective), descendants: true, isSignal: true }], viewQueries: [{ propertyName: "triggerRef", first: true, predicate: ["triggerEl"], descendants: true, isSignal: true }, { propertyName: "inputRef", first: true, predicate: ["inputEl"], descendants: true, isSignal: true }, { propertyName: "dropdownTpl", first: true, predicate: ["dropdownTpl"], descendants: true, isSignal: true }, { propertyName: "virtualScrollRef", first: true, predicate: ["virtualScrollElement"], descendants: true, isSignal: true }, { propertyName: "optionsContainerRef", first: true, predicate: ["optionsContainer"], descendants: true, isSignal: true }, { propertyName: "loadMoreSentinelRef", first: true, predicate: ["loadMoreSentinel"], descendants: true, isSignal: true }, { propertyName: "virtualOptionElements", predicate: ["virtualOptionEl"], descendants: true, isSignal: true }], exportAs: ["zAutocomplete"], ngImport: i0, template: "<div class=\"z-autocomplete-wrapper relative flex w-full flex-col gap-2\">\n @if (zLabel()) {\n <label [for]=\"autocompleteId\" class=\"text-xs leading-none font-medium\" [class]=\"zLabelClass()\">\n {{ zLabel() }}\n @if (zRequired()) {\n <span class=\"text-destructive! ml-0.5\">*</span>\n }\n </label>\n }\n\n <div\n #triggerEl\n z-popover\n [zPopoverContent]=\"dropdownTpl\"\n [zOffset]=\"0\"\n [zDisabled]=\"isInteractionDisabled()\"\n zPopoverWidth=\"trigger\"\n zPopoverTrigger=\"manual\"\n zPosition=\"bottom\"\n zClass=\"border-0 shadow-none bg-transparent p-0\"\n (zControl)=\"onPopoverControl($event)\"\n (zShow)=\"onPopoverShow()\"\n (zHideStart)=\"onPopoverHideStart()\"\n (zHide)=\"onPopoverHideEnd()\"\n (zPositionChange)=\"onPositionChange($event)\"\n class=\"z-autocomplete-trigger\"\n [class]=\"inputClasses()\"\n z-tooltip\n [zContent]=\"inputValue()\"\n zTooltipTrigger=\"hover\"\n zTooltipPosition=\"top\"\n [zTooltipDisabled]=\"uiState().isFocused || uiState().isOpen || !hasValue()\"\n [zTriggerElement]=\"inputEl\"\n [class.z-autocomplete-open]=\"uiState().isOpen\"\n [class.z-autocomplete-open-top]=\"uiState().isOpen && isPositionTop()\"\n [class.z-autocomplete-open-bottom]=\"uiState().isOpen && !isPositionTop()\"\n role=\"combobox\"\n [attr.aria-expanded]=\"uiState().isOpen\"\n [attr.aria-haspopup]=\"'listbox'\"\n [attr.aria-controls]=\"dropdownId\">\n @if (zPrefix()) {\n <z-icon [zType]=\"zPrefix() || 'lucideSearch'\" zSize=\"16\" class=\"text-muted-foreground shrink-0\" />\n }\n\n <input\n #inputEl\n [id]=\"autocompleteId\"\n type=\"text\"\n class=\"z-autocomplete-input placeholder:text-muted-foreground min-w-0 flex-1 overflow-hidden bg-transparent text-ellipsis whitespace-nowrap outline-none\"\n [class.text-sm]=\"zSize() === 'sm' || zSize() === 'default'\"\n [placeholder]=\"zPlaceholder()\"\n [disabled]=\"isDisabled()\"\n [readOnly]=\"isReadonly()\"\n [value]=\"inputValue()\"\n (mousedown)=\"isReadonly() && $event.preventDefault()\"\n (input)=\"onInput($event)\"\n (focus)=\"onFocus($event)\"\n (blur)=\"onBlur($event)\"\n (click)=\"onInputClick()\"\n (keydown)=\"onKeydown($event)\"\n autocomplete=\"off\"\n autocorrect=\"off\"\n spellcheck=\"false\" />\n\n @if (isLoading() || isLoadingState() || isLoadingMore()) {\n <z-icon zType=\"lucideLoaderCircle\" zSize=\"16\" class=\"text-muted-foreground shrink-0 animate-spin\" />\n } @else {\n @if (zAllowClear() && hasValue() && !isDisabled() && !isReadonly()) {\n <button\n type=\"button\"\n class=\"text-muted-foreground hover:text-foreground flex shrink-0 cursor-pointer items-center justify-center transition-colors\"\n (mousedown)=\"clearInput($event)\"\n tabindex=\"-1\">\n <z-icon zType=\"lucideX\" zSize=\"18\" class=\"cursor-pointer!\" />\n </button>\n }\n\n @if (zSuffix()) {\n <z-icon [zType]=\"zSuffix() || 'lucideSearch'\" zSize=\"16\" class=\"text-muted-foreground shrink-0\" />\n }\n }\n </div>\n</div>\n\n<ng-template #dropdownTpl let-close=\"close\">\n <div\n [id]=\"dropdownId\"\n class=\"z-autocomplete-dropdown bg-popover border-ring overflow-hidden border shadow-[var(--z-popover-shadow)]\"\n [class.z-autocomplete-dropdown-bottom]=\"!isPositionTop()\"\n [class.rounded-b-sm]=\"!isPositionTop()\"\n [class.rounded-t-sm]=\"isPositionTop()\"\n [class.border-t-0]=\"!isPositionTop()\"\n [class.border-b-0]=\"isPositionTop()\"\n [style.width.px]=\"dropdownWidth()\"\n role=\"listbox\"\n (mousedown)=\"$event.preventDefault()\">\n @if (isLoading() || isLoadingState()) {\n <div\n class=\"z-autocomplete-content-state flex flex-col items-center justify-center\"\n [style.minHeight.px]=\"effectiveHeightExpand()\">\n <z-loading [zLoading]=\"true\" zSize=\"default\" />\n </div>\n } @else {\n @if (filteredOptions().length === 0) {\n <!-- Empty State -->\n <div\n class=\"z-autocomplete-content-state flex flex-col items-center justify-center p-1\"\n [style.minHeight.px]=\"effectiveHeightExpand()\">\n @if (inputValue().trim() !== '') {\n <!-- Searched but no results -->\n <z-empty [zIcon]=\"zEmptyIcon()\" zSize=\"sm\" [zMessage]=\"effectiveEmptyText()\" />\n } @else {\n <!-- No data initially -->\n <z-empty [zIcon]=\"zNoDataIcon()\" zSize=\"sm\" [zMessage]=\"effectiveNoDataText()\" />\n }\n </div>\n } @else if (shouldUseVirtualScroll()) {\n <!-- Virtual Scroll Mode -->\n <div\n #virtualScrollElement\n class=\"z-autocomplete-content-state z-autocomplete-options z-autocomplete-virtual-scroll relative overflow-x-hidden overflow-y-auto overscroll-y-contain p-1\"\n [style.height.px]=\"effectiveHeightExpand()\">\n <div class=\"z-autocomplete-virtual-inner relative\" [style.height.px]=\"virtualizer.getTotalSize()\">\n @for (virtualItem of virtualizer.getVirtualItems(); track virtualItem.index) {\n @let opt = filteredOptions()[virtualItem.index];\n @let isActive = activeIndex() === virtualItem.index;\n <div\n #virtualOptionEl\n class=\"z-autocomplete-option absolute right-0 left-0 min-w-0\"\n [ngClass]=\"getOptionClasses(opt, virtualItem.index)\"\n [attr.data-index]=\"virtualItem.index\"\n [style.display]=\"hasCustomOptionTemplate() ? 'block' : null\"\n [style.height.px]=\"zDynamicSize() ? null : effectiveOptionHeight()\"\n [style.minHeight.px]=\"zDynamicSize() ? effectiveOptionHeight() : null\"\n [style.overflow]=\"hasCustomOptionTemplate() ? 'visible' : null\"\n [style.transform]=\"'translateY(' + virtualItem.start + 'px)'\"\n [attr.aria-selected]=\"isActive\"\n role=\"option\"\n (mouseenter)=\"activeIndex.set(virtualItem.index)\"\n (click)=\"selectOption(opt)\">\n @if (effectiveOptionTemplate()) {\n <ng-container\n *ngTemplateOutlet=\"effectiveOptionTemplate()!; context: { $implicit: opt, active: isActive }\" />\n } @else {\n @if (opt.icon) {\n <z-icon [zType]=\"opt.icon\" zSize=\"16\" class=\"shrink-0\" />\n }\n <div class=\"min-w-0 flex-1\">\n <span\n class=\"block min-w-0 truncate\"\n z-tooltip\n [zContent]=\"opt.label\"\n zPosition=\"top\"\n [zHideDelay]=\"0\"\n [zOffset]=\"5\"\n [zArrow]=\"false\"\n [zTriggerElement]=\"virtualOptionEl\"\n [innerHTML]=\"\n config().highlightMatch ? (opt.label | zHighlight: highlightQuery() | zSafeHtml) : opt.label\n \"></span>\n @if (opt.description) {\n <span class=\"text-muted-foreground block min-w-0 truncate text-xs\">{{ opt.description }}</span>\n }\n </div>\n }\n </div>\n }\n </div>\n </div>\n } @else {\n <!-- Normal Scroll Mode -->\n <div\n #optionsContainer\n class=\"z-autocomplete-content-state z-autocomplete-options flex flex-col gap-0.75 overflow-x-hidden overflow-y-auto overscroll-y-contain p-1\"\n [style.minHeight.px]=\"effectiveHeightExpand()\"\n [style.maxHeight.px]=\"effectiveHeightExpand()\">\n @for (item of optionViews(); track item.trackKey) {\n @let opt = item.option;\n @let i = item.index;\n @let isActive = activeIndex() === i;\n <div\n #optionEl2\n class=\"z-autocomplete-option relative min-w-0\"\n [ngClass]=\"getOptionClasses(opt, i)\"\n [style.display]=\"hasCustomOptionTemplate() ? 'block' : null\"\n [style.minHeight.px]=\"hasCustomOptionTemplate() ? null : effectiveOptionHeight()\"\n [style.overflow]=\"hasCustomOptionTemplate() ? 'visible' : null\"\n [attr.aria-selected]=\"isActive\"\n role=\"option\"\n (mouseenter)=\"activeIndex.set(i)\"\n (click)=\"selectOption(opt)\">\n @if (effectiveOptionTemplate()) {\n <ng-container\n *ngTemplateOutlet=\"effectiveOptionTemplate()!; context: { $implicit: opt, active: isActive }\" />\n } @else {\n @if (opt.icon) {\n <z-icon [zType]=\"opt.icon\" zSize=\"16\" class=\"shrink-0\" />\n }\n <div class=\"min-w-0 flex-1\">\n <span\n class=\"block min-w-0 truncate\"\n z-tooltip\n [zContent]=\"opt.label\"\n zPosition=\"top\"\n [zHideDelay]=\"0\"\n [zOffset]=\"5\"\n [zArrow]=\"false\"\n [zTriggerElement]=\"optionEl2\"\n [innerHTML]=\"\n config().highlightMatch ? (opt.label | zHighlight: highlightQuery() | zSafeHtml) : opt.label\n \"></span>\n @if (opt.description) {\n <span class=\"text-muted-foreground block min-w-0 truncate text-xs\">{{ opt.description }}</span>\n }\n </div>\n }\n </div>\n }\n @if (canLoadMore()) {\n <div #loadMoreSentinel class=\"h-px w-full shrink-0\"></div>\n }\n </div>\n }\n\n @if (isLoadingMore()) {\n <div class=\"z-autocomplete-loading-more border-border/50 flex items-center justify-center border-t py-1.5\">\n <z-loading zSize=\"xs\" [zLoading]=\"true\" />\n </div>\n }\n }\n </div>\n</ng-template>\n", styles: [".z-autocomplete-wrapper{width:100%}.z-autocomplete-trigger{-webkit-user-select:none;user-select:none}.z-autocomplete-trigger:focus-within{outline:none}.z-autocomplete-trigger *{cursor:inherit}.z-autocomplete-input{text-overflow:ellipsis;overflow:hidden}.z-autocomplete-input::placeholder{color:hsl(var(--muted-foreground))}.z-autocomplete-input:disabled{cursor:not-allowed}.z-autocomplete-open-bottom{border-bottom-left-radius:0!important;border-bottom-right-radius:0!important}.z-autocomplete-open-top{border-top-left-radius:0!important;border-top-right-radius:0!important}.z-autocomplete-dropdown{animation:z-autocomplete-dropdown-from-top .15s ease-out}.z-autocomplete-dropdown-bottom{animation:z-autocomplete-dropdown-from-bottom .15s ease-out}@keyframes z-autocomplete-dropdown-from-top{0%{opacity:0;transform:translateY(-.5rem)}to{opacity:1;transform:translateY(0)}}@keyframes z-autocomplete-dropdown-from-bottom{0%{opacity:0;transform:translateY(.5rem)}to{opacity:1;transform:translateY(0)}}.z-autocomplete-separator{display:none}.z-autocomplete-options{overflow-x:hidden!important}.z-autocomplete-scrollbar{--scrollbar-padding: 0;--scrollbar-track-color: transparent;--scrollbar-thumb-color: hsl(var(--muted-foreground) / .3);--scrollbar-thumb-hover-color: hsl(var(--muted-foreground) / .5);--scrollbar-size: 6px}.z-autocomplete-virtual-scroll .z-autocomplete-virtual-inner{width:100%}.z-autocomplete-content-state{animation:z-autocomplete-content-fade-in .15s ease-out}@keyframes z-autocomplete-content-fade-in{0%{opacity:0}to{opacity:1}}.z-autocomplete-option mark{background:transparent;color:hsl(var(--primary));font-weight:600}.z-autocomplete-option{transition:background-color .1s ease,color .1s ease}.z-autocomplete-options:not(.z-autocomplete-virtual-scroll) .z-autocomplete-option{animation:z-autocomplete-option-enter .12s ease-out;animation-fill-mode:both}@keyframes z-autocomplete-option-enter{0%{opacity:0}to{opacity:1}}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: ZIconComponent, selector: "z-icon, [z-icon]", inputs: ["class", "zType", "zAnimatedType", "zAnimate", "zAnimationTrigger", "zSize", "zStrokeWidth", "zSvg"] }, { kind: "component", type: ZLoadingComponent, selector: "z-loading", inputs: ["class", "zSpinner", "zSize", "zColor", "zText", "zOverlay", "zOverlayType", "zFullscreen", "zLoading"] }, { kind: "directive", type: ZPopoverDirective, selector: "[z-popover]", inputs: ["zPopoverContent", "zPosition", "zTrigger", "zPopoverTrigger", "zClass", "zShowDelay", "zHideDelay", "zDisabled", "zOffset", "zPopoverWidth", "zTriggerRef", "zManualClose", "zOutsideClickClose", "zScrollClose", "zSticky", "zShowArrow", "zKeyboardSafe"], outputs: ["zShow", "zHide", "zHideStart", "zControl", "zPositionChange", "zOutsideClick"], exportAs: ["zPopover"] }, { kind: "directive", type: ZTooltipDirective, selector: "[z-tooltip], [zTooltip]", inputs: ["zContent", "zPosition", "zTooltipPosition", "zTrigger", "zTooltipTrigger", "zTooltipType", "zTooltipSize", "zClass", "zTooltipClass", "zShowDelay", "zTooltipShowDelay", "zHideDelay", "zTooltipHideDelay", "zArrow", "zTooltipArrow", "zDisabled", "zTooltipDisabled", "zOffset", "zTooltipOffset", "zAutoDetect", "zTriggerElement", "zAlwaysShow", "zMaxWidth"], outputs: ["zShow", "zHide"], exportAs: ["zTooltip"] }, { kind: "component", type: ZEmptyComponent, selector: "z-empty", inputs: ["class", "zType", "zIcon", "zIconSize", "zSize", "zMessage", "zDescription"] }, { kind: "pipe", type: ZHighlightPipe, name: "zHighlight" }, { kind: "pipe", type: ZSafeHtmlPipe, name: "zSafeHtml" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1051
- }
1052
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZAutocompleteComponent, decorators: [{
1053
- type: Component,
1054
- args: [{ selector: 'z-autocomplete', imports: [
1055
- FormsModule,
1056
- NgClass,
1057
- NgTemplateOutlet,
1058
- ZIconComponent,
1059
- ZLoadingComponent,
1060
- ZPopoverDirective,
1061
- ZTooltipDirective,
1062
- ZEmptyComponent,
1063
- ZHighlightPipe,
1064
- ZSafeHtmlPipe,
1065
- ], standalone: true, providers: [
1066
- {
1067
- provide: NG_VALUE_ACCESSOR,
1068
- useExisting: forwardRef(() => ZAutocompleteComponent),
1069
- multi: true,
1070
- },
1071
- ], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, exportAs: 'zAutocomplete', template: "<div class=\"z-autocomplete-wrapper relative flex w-full flex-col gap-2\">\n @if (zLabel()) {\n <label [for]=\"autocompleteId\" class=\"text-xs leading-none font-medium\" [class]=\"zLabelClass()\">\n {{ zLabel() }}\n @if (zRequired()) {\n <span class=\"text-destructive! ml-0.5\">*</span>\n }\n </label>\n }\n\n <div\n #triggerEl\n z-popover\n [zPopoverContent]=\"dropdownTpl\"\n [zOffset]=\"0\"\n [zDisabled]=\"isInteractionDisabled()\"\n zPopoverWidth=\"trigger\"\n zPopoverTrigger=\"manual\"\n zPosition=\"bottom\"\n zClass=\"border-0 shadow-none bg-transparent p-0\"\n (zControl)=\"onPopoverControl($event)\"\n (zShow)=\"onPopoverShow()\"\n (zHideStart)=\"onPopoverHideStart()\"\n (zHide)=\"onPopoverHideEnd()\"\n (zPositionChange)=\"onPositionChange($event)\"\n class=\"z-autocomplete-trigger\"\n [class]=\"inputClasses()\"\n z-tooltip\n [zContent]=\"inputValue()\"\n zTooltipTrigger=\"hover\"\n zTooltipPosition=\"top\"\n [zTooltipDisabled]=\"uiState().isFocused || uiState().isOpen || !hasValue()\"\n [zTriggerElement]=\"inputEl\"\n [class.z-autocomplete-open]=\"uiState().isOpen\"\n [class.z-autocomplete-open-top]=\"uiState().isOpen && isPositionTop()\"\n [class.z-autocomplete-open-bottom]=\"uiState().isOpen && !isPositionTop()\"\n role=\"combobox\"\n [attr.aria-expanded]=\"uiState().isOpen\"\n [attr.aria-haspopup]=\"'listbox'\"\n [attr.aria-controls]=\"dropdownId\">\n @if (zPrefix()) {\n <z-icon [zType]=\"zPrefix() || 'lucideSearch'\" zSize=\"16\" class=\"text-muted-foreground shrink-0\" />\n }\n\n <input\n #inputEl\n [id]=\"autocompleteId\"\n type=\"text\"\n class=\"z-autocomplete-input placeholder:text-muted-foreground min-w-0 flex-1 overflow-hidden bg-transparent text-ellipsis whitespace-nowrap outline-none\"\n [class.text-sm]=\"zSize() === 'sm' || zSize() === 'default'\"\n [placeholder]=\"zPlaceholder()\"\n [disabled]=\"isDisabled()\"\n [readOnly]=\"isReadonly()\"\n [value]=\"inputValue()\"\n (mousedown)=\"isReadonly() && $event.preventDefault()\"\n (input)=\"onInput($event)\"\n (focus)=\"onFocus($event)\"\n (blur)=\"onBlur($event)\"\n (click)=\"onInputClick()\"\n (keydown)=\"onKeydown($event)\"\n autocomplete=\"off\"\n autocorrect=\"off\"\n spellcheck=\"false\" />\n\n @if (isLoading() || isLoadingState() || isLoadingMore()) {\n <z-icon zType=\"lucideLoaderCircle\" zSize=\"16\" class=\"text-muted-foreground shrink-0 animate-spin\" />\n } @else {\n @if (zAllowClear() && hasValue() && !isDisabled() && !isReadonly()) {\n <button\n type=\"button\"\n class=\"text-muted-foreground hover:text-foreground flex shrink-0 cursor-pointer items-center justify-center transition-colors\"\n (mousedown)=\"clearInput($event)\"\n tabindex=\"-1\">\n <z-icon zType=\"lucideX\" zSize=\"18\" class=\"cursor-pointer!\" />\n </button>\n }\n\n @if (zSuffix()) {\n <z-icon [zType]=\"zSuffix() || 'lucideSearch'\" zSize=\"16\" class=\"text-muted-foreground shrink-0\" />\n }\n }\n </div>\n</div>\n\n<ng-template #dropdownTpl let-close=\"close\">\n <div\n [id]=\"dropdownId\"\n class=\"z-autocomplete-dropdown bg-popover border-ring overflow-hidden border shadow-[var(--z-popover-shadow)]\"\n [class.z-autocomplete-dropdown-bottom]=\"!isPositionTop()\"\n [class.rounded-b-sm]=\"!isPositionTop()\"\n [class.rounded-t-sm]=\"isPositionTop()\"\n [class.border-t-0]=\"!isPositionTop()\"\n [class.border-b-0]=\"isPositionTop()\"\n [style.width.px]=\"dropdownWidth()\"\n role=\"listbox\"\n (mousedown)=\"$event.preventDefault()\">\n @if (isLoading() || isLoadingState()) {\n <div\n class=\"z-autocomplete-content-state flex flex-col items-center justify-center\"\n [style.minHeight.px]=\"effectiveHeightExpand()\">\n <z-loading [zLoading]=\"true\" zSize=\"default\" />\n </div>\n } @else {\n @if (filteredOptions().length === 0) {\n <!-- Empty State -->\n <div\n class=\"z-autocomplete-content-state flex flex-col items-center justify-center p-1\"\n [style.minHeight.px]=\"effectiveHeightExpand()\">\n @if (inputValue().trim() !== '') {\n <!-- Searched but no results -->\n <z-empty [zIcon]=\"zEmptyIcon()\" zSize=\"sm\" [zMessage]=\"effectiveEmptyText()\" />\n } @else {\n <!-- No data initially -->\n <z-empty [zIcon]=\"zNoDataIcon()\" zSize=\"sm\" [zMessage]=\"effectiveNoDataText()\" />\n }\n </div>\n } @else if (shouldUseVirtualScroll()) {\n <!-- Virtual Scroll Mode -->\n <div\n #virtualScrollElement\n class=\"z-autocomplete-content-state z-autocomplete-options z-autocomplete-virtual-scroll relative overflow-x-hidden overflow-y-auto overscroll-y-contain p-1\"\n [style.height.px]=\"effectiveHeightExpand()\">\n <div class=\"z-autocomplete-virtual-inner relative\" [style.height.px]=\"virtualizer.getTotalSize()\">\n @for (virtualItem of virtualizer.getVirtualItems(); track virtualItem.index) {\n @let opt = filteredOptions()[virtualItem.index];\n @let isActive = activeIndex() === virtualItem.index;\n <div\n #virtualOptionEl\n class=\"z-autocomplete-option absolute right-0 left-0 min-w-0\"\n [ngClass]=\"getOptionClasses(opt, virtualItem.index)\"\n [attr.data-index]=\"virtualItem.index\"\n [style.display]=\"hasCustomOptionTemplate() ? 'block' : null\"\n [style.height.px]=\"zDynamicSize() ? null : effectiveOptionHeight()\"\n [style.minHeight.px]=\"zDynamicSize() ? effectiveOptionHeight() : null\"\n [style.overflow]=\"hasCustomOptionTemplate() ? 'visible' : null\"\n [style.transform]=\"'translateY(' + virtualItem.start + 'px)'\"\n [attr.aria-selected]=\"isActive\"\n role=\"option\"\n (mouseenter)=\"activeIndex.set(virtualItem.index)\"\n (click)=\"selectOption(opt)\">\n @if (effectiveOptionTemplate()) {\n <ng-container\n *ngTemplateOutlet=\"effectiveOptionTemplate()!; context: { $implicit: opt, active: isActive }\" />\n } @else {\n @if (opt.icon) {\n <z-icon [zType]=\"opt.icon\" zSize=\"16\" class=\"shrink-0\" />\n }\n <div class=\"min-w-0 flex-1\">\n <span\n class=\"block min-w-0 truncate\"\n z-tooltip\n [zContent]=\"opt.label\"\n zPosition=\"top\"\n [zHideDelay]=\"0\"\n [zOffset]=\"5\"\n [zArrow]=\"false\"\n [zTriggerElement]=\"virtualOptionEl\"\n [innerHTML]=\"\n config().highlightMatch ? (opt.label | zHighlight: highlightQuery() | zSafeHtml) : opt.label\n \"></span>\n @if (opt.description) {\n <span class=\"text-muted-foreground block min-w-0 truncate text-xs\">{{ opt.description }}</span>\n }\n </div>\n }\n </div>\n }\n </div>\n </div>\n } @else {\n <!-- Normal Scroll Mode -->\n <div\n #optionsContainer\n class=\"z-autocomplete-content-state z-autocomplete-options flex flex-col gap-0.75 overflow-x-hidden overflow-y-auto overscroll-y-contain p-1\"\n [style.minHeight.px]=\"effectiveHeightExpand()\"\n [style.maxHeight.px]=\"effectiveHeightExpand()\">\n @for (item of optionViews(); track item.trackKey) {\n @let opt = item.option;\n @let i = item.index;\n @let isActive = activeIndex() === i;\n <div\n #optionEl2\n class=\"z-autocomplete-option relative min-w-0\"\n [ngClass]=\"getOptionClasses(opt, i)\"\n [style.display]=\"hasCustomOptionTemplate() ? 'block' : null\"\n [style.minHeight.px]=\"hasCustomOptionTemplate() ? null : effectiveOptionHeight()\"\n [style.overflow]=\"hasCustomOptionTemplate() ? 'visible' : null\"\n [attr.aria-selected]=\"isActive\"\n role=\"option\"\n (mouseenter)=\"activeIndex.set(i)\"\n (click)=\"selectOption(opt)\">\n @if (effectiveOptionTemplate()) {\n <ng-container\n *ngTemplateOutlet=\"effectiveOptionTemplate()!; context: { $implicit: opt, active: isActive }\" />\n } @else {\n @if (opt.icon) {\n <z-icon [zType]=\"opt.icon\" zSize=\"16\" class=\"shrink-0\" />\n }\n <div class=\"min-w-0 flex-1\">\n <span\n class=\"block min-w-0 truncate\"\n z-tooltip\n [zContent]=\"opt.label\"\n zPosition=\"top\"\n [zHideDelay]=\"0\"\n [zOffset]=\"5\"\n [zArrow]=\"false\"\n [zTriggerElement]=\"optionEl2\"\n [innerHTML]=\"\n config().highlightMatch ? (opt.label | zHighlight: highlightQuery() | zSafeHtml) : opt.label\n \"></span>\n @if (opt.description) {\n <span class=\"text-muted-foreground block min-w-0 truncate text-xs\">{{ opt.description }}</span>\n }\n </div>\n }\n </div>\n }\n @if (canLoadMore()) {\n <div #loadMoreSentinel class=\"h-px w-full shrink-0\"></div>\n }\n </div>\n }\n\n @if (isLoadingMore()) {\n <div class=\"z-autocomplete-loading-more border-border/50 flex items-center justify-center border-t py-1.5\">\n <z-loading zSize=\"xs\" [zLoading]=\"true\" />\n </div>\n }\n }\n </div>\n</ng-template>\n", styles: [".z-autocomplete-wrapper{width:100%}.z-autocomplete-trigger{-webkit-user-select:none;user-select:none}.z-autocomplete-trigger:focus-within{outline:none}.z-autocomplete-trigger *{cursor:inherit}.z-autocomplete-input{text-overflow:ellipsis;overflow:hidden}.z-autocomplete-input::placeholder{color:hsl(var(--muted-foreground))}.z-autocomplete-input:disabled{cursor:not-allowed}.z-autocomplete-open-bottom{border-bottom-left-radius:0!important;border-bottom-right-radius:0!important}.z-autocomplete-open-top{border-top-left-radius:0!important;border-top-right-radius:0!important}.z-autocomplete-dropdown{animation:z-autocomplete-dropdown-from-top .15s ease-out}.z-autocomplete-dropdown-bottom{animation:z-autocomplete-dropdown-from-bottom .15s ease-out}@keyframes z-autocomplete-dropdown-from-top{0%{opacity:0;transform:translateY(-.5rem)}to{opacity:1;transform:translateY(0)}}@keyframes z-autocomplete-dropdown-from-bottom{0%{opacity:0;transform:translateY(.5rem)}to{opacity:1;transform:translateY(0)}}.z-autocomplete-separator{display:none}.z-autocomplete-options{overflow-x:hidden!important}.z-autocomplete-scrollbar{--scrollbar-padding: 0;--scrollbar-track-color: transparent;--scrollbar-thumb-color: hsl(var(--muted-foreground) / .3);--scrollbar-thumb-hover-color: hsl(var(--muted-foreground) / .5);--scrollbar-size: 6px}.z-autocomplete-virtual-scroll .z-autocomplete-virtual-inner{width:100%}.z-autocomplete-content-state{animation:z-autocomplete-content-fade-in .15s ease-out}@keyframes z-autocomplete-content-fade-in{0%{opacity:0}to{opacity:1}}.z-autocomplete-option mark{background:transparent;color:hsl(var(--primary));font-weight:600}.z-autocomplete-option{transition:background-color .1s ease,color .1s ease}.z-autocomplete-options:not(.z-autocomplete-virtual-scroll) .z-autocomplete-option{animation:z-autocomplete-option-enter .12s ease-out;animation-fill-mode:both}@keyframes z-autocomplete-option-enter{0%{opacity:0}to{opacity:1}}\n"] }]
1072
- }], ctorParameters: () => [], propDecorators: { triggerRef: [{ type: i0.ViewChild, args: ['triggerEl', { isSignal: true }] }], inputRef: [{ type: i0.ViewChild, args: ['inputEl', { isSignal: true }] }], dropdownTpl: [{ type: i0.ViewChild, args: ['dropdownTpl', { isSignal: true }] }], virtualScrollRef: [{ type: i0.ViewChild, args: ['virtualScrollElement', { isSignal: true }] }], optionsContainerRef: [{ type: i0.ViewChild, args: ['optionsContainer', { isSignal: true }] }], loadMoreSentinelRef: [{ type: i0.ViewChild, args: ['loadMoreSentinel', { isSignal: true }] }], virtualOptionElements: [{ type: i0.ViewChildren, args: ['virtualOptionEl', { isSignal: true }] }], customOptionDirective: [{ type: i0.ContentChild, args: [i0.forwardRef(() => ZAutocompleteOptionDirective), { isSignal: true }] }], class: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }], zOptions: [{ type: i0.Input, args: [{ isSignal: true, alias: "zOptions", required: false }] }], zConfig: [{ type: i0.Input, args: [{ isSignal: true, alias: "zConfig", required: false }] }], zSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "zSize", required: false }] }], zType: [{ type: i0.Input, args: [{ isSignal: true, alias: "zType", required: false }] }], zLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "zLabel", required: false }] }], zLabelClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "zLabelClass", required: false }] }], zPlaceholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "zPlaceholder", required: false }] }], zDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "zDisabled", required: false }] }], zReadonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "zReadonly", required: false }] }], zLoading: [{ type: i0.Input, args: [{ isSignal: true, alias: "zLoading", required: false }] }], zLoadingOutline: [{ type: i0.Input, args: [{ isSignal: true, alias: "zLoadingOutline", required: false }] }], zRequired: [{ type: i0.Input, args: [{ isSignal: true, alias: "zRequired", required: false }] }], zPrefix: [{ type: i0.Input, args: [{ isSignal: true, alias: "zPrefix", required: false }] }], zSuffix: [{ type: i0.Input, args: [{ isSignal: true, alias: "zSuffix", required: false }] }], zAllowClear: [{ type: i0.Input, args: [{ isSignal: true, alias: "zAllowClear", required: false }] }], zVirtualScroll: [{ type: i0.Input, args: [{ isSignal: true, alias: "zVirtualScroll", required: false }] }], zDynamicSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "zDynamicSize", required: false }] }], zOptionHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "zOptionHeight", required: false }] }], zHeightExpand: [{ type: i0.Input, args: [{ isSignal: true, alias: "zHeightExpand", required: false }] }], zMaxVisible: [{ type: i0.Input, args: [{ isSignal: true, alias: "zMaxVisible", required: false }] }], zResetOnSelect: [{ type: i0.Input, args: [{ isSignal: true, alias: "zResetOnSelect", required: false }] }], zEmptyText: [{ type: i0.Input, args: [{ isSignal: true, alias: "zEmptyText", required: false }] }], zEmptyIcon: [{ type: i0.Input, args: [{ isSignal: true, alias: "zEmptyIcon", required: false }] }], zNoDataText: [{ type: i0.Input, args: [{ isSignal: true, alias: "zNoDataText", required: false }] }], zNoDataIcon: [{ type: i0.Input, args: [{ isSignal: true, alias: "zNoDataIcon", required: false }] }], zAllowCustomValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "zAllowCustomValue", required: false }] }], zDebounceTime: [{ type: i0.Input, args: [{ isSignal: true, alias: "zDebounceTime", required: false }] }], zLoadingMore: [{ type: i0.Input, args: [{ isSignal: true, alias: "zLoadingMore", required: false }] }], zEnableLoadMore: [{ type: i0.Input, args: [{ isSignal: true, alias: "zEnableLoadMore", required: false }] }], zScrollDistance: [{ type: i0.Input, args: [{ isSignal: true, alias: "zScrollDistance", required: false }] }], zKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "zKey", required: false }] }], zOptionTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "zOptionTemplate", required: false }] }], zOnSearch: [{ type: i0.Output, args: ["zOnSearch"] }], zOnLoadMore: [{ type: i0.Output, args: ["zOnLoadMore"] }], zOnSelect: [{ type: i0.Output, args: ["zOnSelect"] }], zOnEnter: [{ type: i0.Output, args: ["zOnEnter"] }], zOnCommit: [{ type: i0.Output, args: ["zOnCommit"] }], zValueChange: [{ type: i0.Output, args: ["zValueChange"] }], zOnBlur: [{ type: i0.Output, args: ["zOnBlur"] }], zOnFocus: [{ type: i0.Output, args: ["zOnFocus"] }], zControl: [{ type: i0.Output, args: ["zControl"] }], zEvent: [{ type: i0.Output, args: ["zEvent"] }] } });
1073
-
1074
- /**
1075
- * Generated bundle index. Do not edit.
1076
- */
1077
-
1078
- export { ZAutocompleteComponent, ZAutocompleteOptionDirective, Z_AUTOCOMPLETE_DEFAULT_CONFIG, zAutocompleteInputVariants, zAutocompleteOptionVariants };
1079
- //# sourceMappingURL=shival99-z-ui-components-z-autocomplete.mjs.map