@shival99/z-ui 2.1.29 → 2.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/shival99-z-ui-components-z-autocomplete.mjs +1081 -0
- package/fesm2022/shival99-z-ui-components-z-autocomplete.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-drawer.mjs +742 -0
- package/fesm2022/shival99-z-ui-components-z-drawer.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-dropdown-menu.mjs +58 -0
- package/fesm2022/shival99-z-ui-components-z-dropdown-menu.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-editor.mjs +1750 -0
- package/fesm2022/shival99-z-ui-components-z-editor.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-gallery.mjs +2419 -0
- package/fesm2022/shival99-z-ui-components-z-gallery.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-kanban.mjs +981 -0
- package/fesm2022/shival99-z-ui-components-z-kanban.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-marquee.mjs +70 -0
- package/fesm2022/shival99-z-ui-components-z-marquee.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-media-player.mjs +668 -0
- package/fesm2022/shival99-z-ui-components-z-media-player.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-menu.mjs +843 -0
- package/fesm2022/shival99-z-ui-components-z-menu.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-metric-card.mjs +128 -0
- package/fesm2022/shival99-z-ui-components-z-metric-card.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-pagination.mjs +158 -0
- package/fesm2022/shival99-z-ui-components-z-pagination.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-qrcode.mjs +383 -0
- package/fesm2022/shival99-z-ui-components-z-qrcode.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-radio.mjs +167 -0
- package/fesm2022/shival99-z-ui-components-z-radio.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-scrollarea.mjs +131 -0
- package/fesm2022/shival99-z-ui-components-z-scrollarea.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-show-more.mjs +121 -0
- package/fesm2022/shival99-z-ui-components-z-show-more.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-skeleton-auto.mjs +61 -0
- package/fesm2022/shival99-z-ui-components-z-skeleton-auto.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-steps.mjs +396 -0
- package/fesm2022/shival99-z-ui-components-z-steps.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-table.mjs +10510 -0
- package/fesm2022/shival99-z-ui-components-z-table.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-tabs.mjs +507 -0
- package/fesm2022/shival99-z-ui-components-z-tabs.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-tags.mjs +349 -0
- package/fesm2022/shival99-z-ui-components-z-tags.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-timeline.mjs +237 -0
- package/fesm2022/shival99-z-ui-components-z-timeline.mjs.map +1 -0
- package/fesm2022/shival99-z-ui-components-z-upload.mjs +523 -0
- package/fesm2022/shival99-z-ui-components-z-upload.mjs.map +1 -0
- package/package.json +1 -1
- package/types/shival99-z-ui-components-z-autocomplete.d.ts +292 -0
- package/types/shival99-z-ui-components-z-calendar.d.ts +4 -4
- package/types/shival99-z-ui-components-z-drawer.d.ts +266 -0
- package/types/shival99-z-ui-components-z-dropdown-menu.d.ts +54 -0
- package/types/shival99-z-ui-components-z-editor.d.ts +337 -0
- package/types/shival99-z-ui-components-z-gallery.d.ts +402 -0
- package/types/shival99-z-ui-components-z-kanban.d.ts +237 -0
- package/types/shival99-z-ui-components-z-marquee.d.ts +35 -0
- package/types/shival99-z-ui-components-z-media-player.d.ts +124 -0
- package/types/shival99-z-ui-components-z-menu.d.ts +222 -0
- package/types/shival99-z-ui-components-z-metric-card.d.ts +67 -0
- package/types/shival99-z-ui-components-z-pagination.d.ts +55 -0
- package/types/shival99-z-ui-components-z-qrcode.d.ts +76 -0
- package/types/shival99-z-ui-components-z-radio.d.ts +69 -0
- package/types/shival99-z-ui-components-z-scrollarea.d.ts +46 -0
- package/types/shival99-z-ui-components-z-show-more.d.ts +36 -0
- package/types/shival99-z-ui-components-z-skeleton-auto.d.ts +35 -0
- package/types/shival99-z-ui-components-z-steps.d.ts +106 -0
- package/types/shival99-z-ui-components-z-table.d.ts +1924 -0
- package/types/shival99-z-ui-components-z-tabs.d.ts +92 -0
- package/types/shival99-z-ui-components-z-tags.d.ts +128 -0
- package/types/shival99-z-ui-components-z-timeline.d.ts +71 -0
- package/types/shival99-z-ui-components-z-upload.d.ts +153 -0
|
@@ -0,0 +1,1081 @@
|
|
|
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
|
+
zDropdownMaxHeight = input(null, ...(ngDevMode ? [{ debugName: "zDropdownMaxHeight" }] : []));
|
|
123
|
+
/** @deprecated Dùng zDropdownMaxHeight để đồng nhất với z-select. */
|
|
124
|
+
zHeightExpand = input(null, ...(ngDevMode ? [{ debugName: "zHeightExpand" }] : []));
|
|
125
|
+
zMaxVisible = input(null, ...(ngDevMode ? [{ debugName: "zMaxVisible" }] : []));
|
|
126
|
+
zResetOnSelect = input(true, { ...(ngDevMode ? { debugName: "zResetOnSelect" } : {}), transform: zTransform });
|
|
127
|
+
zEmptyText = input('', ...(ngDevMode ? [{ debugName: "zEmptyText" }] : []));
|
|
128
|
+
zEmptyIcon = input('lucideSearchX', ...(ngDevMode ? [{ debugName: "zEmptyIcon" }] : []));
|
|
129
|
+
zNoDataText = input('', ...(ngDevMode ? [{ debugName: "zNoDataText" }] : []));
|
|
130
|
+
zNoDataIcon = input('lucidePackageOpen', ...(ngDevMode ? [{ debugName: "zNoDataIcon" }] : []));
|
|
131
|
+
zAllowCustomValue = input(false, { ...(ngDevMode ? { debugName: "zAllowCustomValue" } : {}), transform: zTransform });
|
|
132
|
+
zDebounceTime = input(200, ...(ngDevMode ? [{ debugName: "zDebounceTime" }] : []));
|
|
133
|
+
zLoadingMore = input(false, { ...(ngDevMode ? { debugName: "zLoadingMore" } : {}), transform: zTransform });
|
|
134
|
+
zEnableLoadMore = input(false, { ...(ngDevMode ? { debugName: "zEnableLoadMore" } : {}), transform: zTransform });
|
|
135
|
+
zScrollDistance = input(2, ...(ngDevMode ? [{ debugName: "zScrollDistance" }] : []));
|
|
136
|
+
zKey = input('', ...(ngDevMode ? [{ debugName: "zKey" }] : []));
|
|
137
|
+
zOptionTemplate = input(null, ...(ngDevMode ? [{ debugName: "zOptionTemplate" }] : []));
|
|
138
|
+
zOnSearch = output();
|
|
139
|
+
zOnLoadMore = output();
|
|
140
|
+
zOnSelect = output();
|
|
141
|
+
zOnEnter = output();
|
|
142
|
+
zOnCommit = output();
|
|
143
|
+
zValueChange = output();
|
|
144
|
+
zOnBlur = output();
|
|
145
|
+
zOnFocus = output();
|
|
146
|
+
zControl = output();
|
|
147
|
+
zEvent = output();
|
|
148
|
+
_value = signal('', ...(ngDevMode ? [{ debugName: "_value" }] : []));
|
|
149
|
+
_disabled = signal(false, ...(ngDevMode ? [{ debugName: "_disabled" }] : []));
|
|
150
|
+
_formControl = signal(null, ...(ngDevMode ? [{ debugName: "_formControl" }] : []));
|
|
151
|
+
_popoverControl = signal(null, ...(ngDevMode ? [{ debugName: "_popoverControl" }] : []));
|
|
152
|
+
_selectedOption = signal(null, ...(ngDevMode ? [{ debugName: "_selectedOption" }] : []));
|
|
153
|
+
_asyncOptions = signal([], ...(ngDevMode ? [{ debugName: "_asyncOptions" }] : []));
|
|
154
|
+
_asyncKeyword = signal('', ...(ngDevMode ? [{ debugName: "_asyncKeyword" }] : []));
|
|
155
|
+
_asyncPage = signal(1, ...(ngDevMode ? [{ debugName: "_asyncPage" }] : []));
|
|
156
|
+
_asyncHasMore = signal(false, ...(ngDevMode ? [{ debugName: "_asyncHasMore" }] : []));
|
|
157
|
+
_asyncLoading = signal(false, ...(ngDevMode ? [{ debugName: "_asyncLoading" }] : []));
|
|
158
|
+
_asyncLoadingMore = signal(false, ...(ngDevMode ? [{ debugName: "_asyncLoadingMore" }] : []));
|
|
159
|
+
uiState = signal({
|
|
160
|
+
isOpen: false,
|
|
161
|
+
isFocused: false,
|
|
162
|
+
touched: false,
|
|
163
|
+
dirty: false,
|
|
164
|
+
}, ...(ngDevMode ? [{ debugName: "uiState" }] : []));
|
|
165
|
+
actualPosition = signal('bottom', ...(ngDevMode ? [{ debugName: "actualPosition" }] : []));
|
|
166
|
+
autocompleteId = zUuid('z-autocomplete');
|
|
167
|
+
dropdownId = `${this.autocompleteId}-dropdown`;
|
|
168
|
+
inputValue = signal('', ...(ngDevMode ? [{ debugName: "inputValue" }] : []));
|
|
169
|
+
debouncedQuery = signal('', ...(ngDevMode ? [{ debugName: "debouncedQuery" }] : []));
|
|
170
|
+
searchQuery = signal('', ...(ngDevMode ? [{ debugName: "searchQuery" }] : []));
|
|
171
|
+
activeIndex = signal(-1, ...(ngDevMode ? [{ debugName: "activeIndex" }] : []));
|
|
172
|
+
dropdownWidth = signal(0, ...(ngDevMode ? [{ debugName: "dropdownWidth" }] : []));
|
|
173
|
+
_pendingSearch = signal(false, ...(ngDevMode ? [{ debugName: "_pendingSearch" }] : []));
|
|
174
|
+
_localLoadingTimeout = null;
|
|
175
|
+
_loadMoreObserver = null;
|
|
176
|
+
_virtualScrollListener = null;
|
|
177
|
+
_asyncLoadSubscription = null;
|
|
178
|
+
_asyncRequestId = 0;
|
|
179
|
+
_lastFilteredOptionsLength = 0;
|
|
180
|
+
_shouldScrollActiveOption = false;
|
|
181
|
+
/** Stores input value before keyboard navigation for ESC revert */
|
|
182
|
+
_valueBeforeNavigation = null;
|
|
183
|
+
virtualizer = injectVirtualizer(() => ({
|
|
184
|
+
scrollElement: this.virtualScrollRef(),
|
|
185
|
+
count: this.filteredOptions().length,
|
|
186
|
+
estimateSize: () => this.effectiveOptionHeight(),
|
|
187
|
+
measureElement: (element) => element.getBoundingClientRect().height,
|
|
188
|
+
overscan: 5,
|
|
189
|
+
}));
|
|
190
|
+
_measureVirtualItems = effect(() => {
|
|
191
|
+
if (!this.zDynamicSize()) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const elements = this.virtualOptionElements();
|
|
195
|
+
for (const el of elements) {
|
|
196
|
+
this.virtualizer.measureElement(el.nativeElement);
|
|
197
|
+
}
|
|
198
|
+
}, ...(ngDevMode ? [{ debugName: "_measureVirtualItems" }] : []));
|
|
199
|
+
config = computed(() => ({
|
|
200
|
+
...Z_AUTOCOMPLETE_DEFAULT_CONFIG,
|
|
201
|
+
...this.zConfig(),
|
|
202
|
+
}), ...(ngDevMode ? [{ debugName: "config" }] : []));
|
|
203
|
+
hasAsyncOptions = computed(() => !!this.config().async?.load, ...(ngDevMode ? [{ debugName: "hasAsyncOptions" }] : []));
|
|
204
|
+
asyncSelectedOptions = computed(() => zResolveAsyncSelectedOptions(this.config().async), ...(ngDevMode ? [{ debugName: "asyncSelectedOptions" }] : []));
|
|
205
|
+
sourceOptions = computed(() => {
|
|
206
|
+
if (!this.hasAsyncOptions()) {
|
|
207
|
+
return this.zOptions();
|
|
208
|
+
}
|
|
209
|
+
return zMergeAsyncOptions(this._asyncOptions(), this.asyncSelectedOptions(), this.config().async?.dedupeBy);
|
|
210
|
+
}, ...(ngDevMode ? [{ debugName: "sourceOptions" }] : []));
|
|
211
|
+
isLoading = computed(() => this.zLoading() || this._asyncLoading(), ...(ngDevMode ? [{ debugName: "isLoading" }] : []));
|
|
212
|
+
isLoadingMore = computed(() => this.zLoadingMore() || this._asyncLoadingMore(), ...(ngDevMode ? [{ debugName: "isLoadingMore" }] : []));
|
|
213
|
+
canLoadMore = computed(() => this.hasAsyncOptions() ? this._asyncHasMore() : this.zEnableLoadMore(), ...(ngDevMode ? [{ debugName: "canLoadMore" }] : []));
|
|
214
|
+
isDisabled = computed(() => this._disabled() || this.zDisabled(), ...(ngDevMode ? [{ debugName: "isDisabled" }] : []));
|
|
215
|
+
isReadonly = computed(() => this.zReadonly(), ...(ngDevMode ? [{ debugName: "isReadonly" }] : []));
|
|
216
|
+
isInteractionDisabled = computed(() => this.isDisabled() || this.isReadonly() || this.zLoading(), ...(ngDevMode ? [{ debugName: "isInteractionDisabled" }] : []));
|
|
217
|
+
effectiveOptionHeight = computed(() => this.zOptionHeight() || this.config().optionHeight, ...(ngDevMode ? [{ debugName: "effectiveOptionHeight" }] : []));
|
|
218
|
+
effectiveHeightExpand = computed(() => this.zDropdownMaxHeight() ?? this.zHeightExpand() ?? this.config().dropdownMaxHeight, ...(ngDevMode ? [{ debugName: "effectiveHeightExpand" }] : []));
|
|
219
|
+
effectiveEmptyText = computed(() => this.zEmptyText() || this.config().emptyMessage, ...(ngDevMode ? [{ debugName: "effectiveEmptyText" }] : []));
|
|
220
|
+
effectiveNoDataText = computed(() => this.zNoDataText() || this.config().noDataMessage, ...(ngDevMode ? [{ debugName: "effectiveNoDataText" }] : []));
|
|
221
|
+
effectiveDebounceTime = computed(() => this.zConfig().debounceTime ?? this.zDebounceTime(), ...(ngDevMode ? [{ debugName: "effectiveDebounceTime" }] : []));
|
|
222
|
+
effectiveOptionTemplate = computed(() => {
|
|
223
|
+
const directive = this.customOptionDirective();
|
|
224
|
+
if (directive) {
|
|
225
|
+
return directive.templateRef;
|
|
226
|
+
}
|
|
227
|
+
return this.zOptionTemplate();
|
|
228
|
+
}, ...(ngDevMode ? [{ debugName: "effectiveOptionTemplate" }] : []));
|
|
229
|
+
hasCustomOptionTemplate = computed(() => this.effectiveOptionTemplate() !== null, ...(ngDevMode ? [{ debugName: "hasCustomOptionTemplate" }] : []));
|
|
230
|
+
selected = computed(() => {
|
|
231
|
+
const option = this._selectedOption();
|
|
232
|
+
if (!option) {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
return [option];
|
|
236
|
+
}, ...(ngDevMode ? [{ debugName: "selected" }] : []));
|
|
237
|
+
highlightQuery = computed(() => this.zType() === 'address_bar' ? this.searchQuery() : this.debouncedQuery(), ...(ngDevMode ? [{ debugName: "highlightQuery" }] : []));
|
|
238
|
+
/**
|
|
239
|
+
* Local-mode loading state after debounce to avoid quick flicker.
|
|
240
|
+
* Server mode relies only on zLoading from parent.
|
|
241
|
+
*/
|
|
242
|
+
isLoadingState = computed(() => {
|
|
243
|
+
if (this.config().serverSearch || this.hasAsyncOptions()) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
const hasInput = this.inputValue().trim() !== '';
|
|
247
|
+
return hasInput && this._pendingSearch();
|
|
248
|
+
}, ...(ngDevMode ? [{ debugName: "isLoadingState" }] : []));
|
|
249
|
+
isPositionTop = computed(() => {
|
|
250
|
+
const pos = this.actualPosition();
|
|
251
|
+
return pos.startsWith('top');
|
|
252
|
+
}, ...(ngDevMode ? [{ debugName: "isPositionTop" }] : []));
|
|
253
|
+
shouldUseVirtualScroll = computed(() => {
|
|
254
|
+
if (this.zVirtualScroll()) {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
if (this.hasCustomOptionTemplate()) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
if (this.canLoadMore()) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
const maxVisible = this.zMaxVisible();
|
|
264
|
+
if (maxVisible !== null && this.sourceOptions().length > maxVisible) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
return this.sourceOptions().length > 50;
|
|
268
|
+
}, ...(ngDevMode ? [{ debugName: "shouldUseVirtualScroll" }] : []));
|
|
269
|
+
filteredOptions = computed(() => {
|
|
270
|
+
const options = this.sourceOptions();
|
|
271
|
+
const cfg = this.config();
|
|
272
|
+
const allowCustom = this.zAllowCustomValue();
|
|
273
|
+
const query = this.zType() === 'address_bar' ? this.searchQuery() : this.debouncedQuery();
|
|
274
|
+
// If server search is enabled, skip local filtering - just apply maxDisplayed limit
|
|
275
|
+
if (cfg.serverSearch || this.hasAsyncOptions()) {
|
|
276
|
+
let result = options;
|
|
277
|
+
if (cfg.maxDisplayed && options.length > cfg.maxDisplayed) {
|
|
278
|
+
result = options.slice(0, cfg.maxDisplayed);
|
|
279
|
+
}
|
|
280
|
+
// Allow custom value: if no results from server, show typed text as option
|
|
281
|
+
if (allowCustom && result.length === 0 && query.trim() !== '') {
|
|
282
|
+
return [{ label: query.trim(), value: query.trim() }];
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
if (!query || query.trim() === '') {
|
|
287
|
+
if (cfg.maxDisplayed && options.length > cfg.maxDisplayed) {
|
|
288
|
+
return options.slice(0, cfg.maxDisplayed);
|
|
289
|
+
}
|
|
290
|
+
return options;
|
|
291
|
+
}
|
|
292
|
+
const normalizedQuery = zRemoveVietnamese(query.toLowerCase());
|
|
293
|
+
let filtered = options.filter(opt => {
|
|
294
|
+
const normalizedLabel = zRemoveVietnamese(opt.label.toLowerCase());
|
|
295
|
+
return normalizedLabel.includes(normalizedQuery);
|
|
296
|
+
});
|
|
297
|
+
if (cfg.maxDisplayed && filtered.length > cfg.maxDisplayed) {
|
|
298
|
+
filtered = filtered.slice(0, cfg.maxDisplayed);
|
|
299
|
+
}
|
|
300
|
+
if (allowCustom && filtered.length === 0 && query.trim() !== '') {
|
|
301
|
+
return [{ label: query.trim(), value: query.trim() }];
|
|
302
|
+
}
|
|
303
|
+
return filtered;
|
|
304
|
+
}, ...(ngDevMode ? [{ debugName: "filteredOptions" }] : []));
|
|
305
|
+
optionViews = computed(() => this.filteredOptions().map((option, index) => ({
|
|
306
|
+
option,
|
|
307
|
+
index,
|
|
308
|
+
trackKey: `${String(this._getOptionKey(option))}::${index}`,
|
|
309
|
+
})), ...(ngDevMode ? [{ debugName: "optionViews" }] : []));
|
|
310
|
+
hasValue = computed(() => {
|
|
311
|
+
const value = this.inputValue();
|
|
312
|
+
return value !== null && value !== undefined && value.trim() !== '';
|
|
313
|
+
}, ...(ngDevMode ? [{ debugName: "hasValue" }] : []));
|
|
314
|
+
currentStatus = computed(() => {
|
|
315
|
+
if (this.isDisabled()) {
|
|
316
|
+
return 'disabled';
|
|
317
|
+
}
|
|
318
|
+
if (this.isReadonly()) {
|
|
319
|
+
return 'readonly';
|
|
320
|
+
}
|
|
321
|
+
if (this.uiState().isOpen) {
|
|
322
|
+
return 'open';
|
|
323
|
+
}
|
|
324
|
+
return 'default';
|
|
325
|
+
}, ...(ngDevMode ? [{ debugName: "currentStatus" }] : []));
|
|
326
|
+
inputClasses = computed(() => zMergeClasses(zAutocompleteInputVariants({
|
|
327
|
+
zSize: this.zSize(),
|
|
328
|
+
zStatus: this.currentStatus(),
|
|
329
|
+
}), this.zLoading() && this.zLoadingOutline() ? 'z-loading-outline-active !ring-ring/50 !ring-[3px]' : '', this.class()), ...(ngDevMode ? [{ debugName: "inputClasses" }] : []));
|
|
330
|
+
state = computed(() => ({
|
|
331
|
+
focused: this.uiState().isFocused,
|
|
332
|
+
touched: this.uiState().touched,
|
|
333
|
+
dirty: this.uiState().dirty,
|
|
334
|
+
disabled: this.isDisabled(),
|
|
335
|
+
readonly: this.isReadonly(),
|
|
336
|
+
open: this.uiState().isOpen,
|
|
337
|
+
}), ...(ngDevMode ? [{ debugName: "state" }] : []));
|
|
338
|
+
_onChange = () => void 0;
|
|
339
|
+
_onTouched = () => void 0;
|
|
340
|
+
_ngControl = null;
|
|
341
|
+
_isNavigationFilling = false;
|
|
342
|
+
constructor() {
|
|
343
|
+
effect(onCleanup => {
|
|
344
|
+
const triggerEl = this.triggerRef()?.nativeElement;
|
|
345
|
+
if (!triggerEl) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const observer = new ResizeObserver(() => {
|
|
349
|
+
this.dropdownWidth.set(triggerEl.getBoundingClientRect().width);
|
|
350
|
+
});
|
|
351
|
+
observer.observe(triggerEl);
|
|
352
|
+
this.dropdownWidth.set(triggerEl.getBoundingClientRect().width);
|
|
353
|
+
onCleanup(() => {
|
|
354
|
+
observer.disconnect();
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
effect(() => {
|
|
358
|
+
const options = this.filteredOptions();
|
|
359
|
+
const { isOpen } = this.uiState();
|
|
360
|
+
if (!isOpen || options.length === 0) {
|
|
361
|
+
this._lastFilteredOptionsLength = options.length;
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const previousLength = this._lastFilteredOptionsLength;
|
|
365
|
+
const currentIndex = untracked(() => this.activeIndex());
|
|
366
|
+
this._lastFilteredOptionsLength = options.length;
|
|
367
|
+
if (currentIndex < 0 || currentIndex >= options.length || options.length <= previousLength) {
|
|
368
|
+
this.activeIndex.set(0);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
effect(() => {
|
|
372
|
+
const idx = this.activeIndex();
|
|
373
|
+
const { isOpen } = this.uiState();
|
|
374
|
+
if (!isOpen || idx < 0) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (!this._shouldScrollActiveOption || this.shouldUseVirtualScroll() || this.canLoadMore()) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
this._shouldScrollActiveOption = false;
|
|
381
|
+
const container = this.optionsContainerRef()?.nativeElement;
|
|
382
|
+
if (!container) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const options = container.querySelectorAll('.z-autocomplete-option');
|
|
386
|
+
const activeOption = options[idx];
|
|
387
|
+
if (activeOption) {
|
|
388
|
+
activeOption.scrollIntoView({ block: 'nearest' });
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
effect(onCleanup => {
|
|
392
|
+
const sentinel = this.loadMoreSentinelRef();
|
|
393
|
+
const { isOpen } = this.uiState();
|
|
394
|
+
const optionsCount = this.filteredOptions().length;
|
|
395
|
+
if (!sentinel || !isOpen || optionsCount === 0 || !this.canLoadMore()) {
|
|
396
|
+
this._cleanupLoadMoreObserver();
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
this._setupLoadMoreObserver();
|
|
400
|
+
onCleanup(() => {
|
|
401
|
+
this._cleanupLoadMoreObserver();
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
effect(onCleanup => {
|
|
405
|
+
const { isOpen } = this.uiState();
|
|
406
|
+
const useVirtual = this.shouldUseVirtualScroll();
|
|
407
|
+
const optionsCount = this.filteredOptions().length;
|
|
408
|
+
if (!isOpen || !useVirtual || optionsCount === 0) {
|
|
409
|
+
this._cleanupVirtualScrollListener();
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
requestAnimationFrame(() => {
|
|
413
|
+
requestAnimationFrame(() => {
|
|
414
|
+
this._setupVirtualScrollLoadMore();
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
onCleanup(() => {
|
|
418
|
+
this._cleanupVirtualScrollListener();
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
ngOnInit() {
|
|
423
|
+
this._setupDebounce();
|
|
424
|
+
this._emitControl();
|
|
425
|
+
queueMicrotask(() => {
|
|
426
|
+
try {
|
|
427
|
+
this._ngControl = this._injector.get(NgControl, null);
|
|
428
|
+
if (this._ngControl?.control) {
|
|
429
|
+
this._formControl.set(this._ngControl.control);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
this._ngControl = null;
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
writeValue(value) {
|
|
438
|
+
this._value.set(value ?? '');
|
|
439
|
+
this.inputValue.set(value ?? '');
|
|
440
|
+
this.debouncedQuery.set(value ?? '');
|
|
441
|
+
if (this.zType() === 'address_bar') {
|
|
442
|
+
this.searchQuery.set(value ?? '');
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
registerOnChange(fn) {
|
|
446
|
+
this._onChange = fn;
|
|
447
|
+
}
|
|
448
|
+
registerOnTouched(fn) {
|
|
449
|
+
this._onTouched = fn;
|
|
450
|
+
}
|
|
451
|
+
setDisabledState(isDisabled) {
|
|
452
|
+
this._disabled.set(isDisabled);
|
|
453
|
+
}
|
|
454
|
+
onInput(event) {
|
|
455
|
+
const { value } = event.target;
|
|
456
|
+
this._clearLocalLoadingTimer();
|
|
457
|
+
this._pendingSearch.set(false);
|
|
458
|
+
this.inputValue.set(value);
|
|
459
|
+
this._value.set(value);
|
|
460
|
+
this.uiState.update(s => ({ ...s, dirty: true }));
|
|
461
|
+
this._onChange(value);
|
|
462
|
+
if (!this._isNavigationFilling) {
|
|
463
|
+
this._query$.next(value);
|
|
464
|
+
}
|
|
465
|
+
this.zValueChange.emit(value);
|
|
466
|
+
if (!this.uiState().isOpen) {
|
|
467
|
+
this._openPanel();
|
|
468
|
+
}
|
|
469
|
+
this._selectedOption.set(null);
|
|
470
|
+
}
|
|
471
|
+
onFocus(event) {
|
|
472
|
+
if (this.isReadonly()) {
|
|
473
|
+
event.target.blur();
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
this.uiState.update(s => ({ ...s, isFocused: true }));
|
|
477
|
+
this.zOnFocus.emit(event);
|
|
478
|
+
this.zEvent.emit(zCreateEvent('focus', event));
|
|
479
|
+
this._openPanel();
|
|
480
|
+
}
|
|
481
|
+
onInputClick() {
|
|
482
|
+
if (this.uiState().isOpen) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
this._openPanel();
|
|
486
|
+
}
|
|
487
|
+
onBlur(event) {
|
|
488
|
+
this.uiState.update(s => ({ ...s, isFocused: false }));
|
|
489
|
+
this.zOnBlur.emit(event);
|
|
490
|
+
this.zEvent.emit(zCreateEvent('blur', event));
|
|
491
|
+
if (this.uiState().dirty) {
|
|
492
|
+
this.uiState.update(s => ({ ...s, touched: true }));
|
|
493
|
+
}
|
|
494
|
+
this._onTouched();
|
|
495
|
+
const currentValue = this.inputValue();
|
|
496
|
+
this.zOnCommit.emit({ value: currentValue, source: 'blur' });
|
|
497
|
+
}
|
|
498
|
+
onKeydown(event) {
|
|
499
|
+
if (this.isInteractionDisabled()) {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
const { isOpen } = this.uiState();
|
|
503
|
+
const options = this.filteredOptions();
|
|
504
|
+
const currentValue = this.inputValue();
|
|
505
|
+
const isAddressBarMode = this.zType() === 'address_bar';
|
|
506
|
+
if (event.key === 'Enter') {
|
|
507
|
+
event.preventDefault();
|
|
508
|
+
if (!isOpen) {
|
|
509
|
+
this._openPanel();
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
this._handleEnterKey(options, currentValue);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
if (!isOpen) {
|
|
516
|
+
if (event.key === 'ArrowDown') {
|
|
517
|
+
event.preventDefault();
|
|
518
|
+
this._openPanel();
|
|
519
|
+
}
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
switch (event.key) {
|
|
523
|
+
case 'ArrowDown':
|
|
524
|
+
event.preventDefault();
|
|
525
|
+
if (this._valueBeforeNavigation === null) {
|
|
526
|
+
this._valueBeforeNavigation = currentValue;
|
|
527
|
+
}
|
|
528
|
+
this._shouldScrollActiveOption = true;
|
|
529
|
+
this.activeIndex.update(i => (i < options.length - 1 ? i + 1 : 0));
|
|
530
|
+
if (isAddressBarMode) {
|
|
531
|
+
this._fillInputFromActiveOption();
|
|
532
|
+
}
|
|
533
|
+
break;
|
|
534
|
+
case 'ArrowUp':
|
|
535
|
+
event.preventDefault();
|
|
536
|
+
if (this._valueBeforeNavigation === null) {
|
|
537
|
+
this._valueBeforeNavigation = currentValue;
|
|
538
|
+
}
|
|
539
|
+
this._shouldScrollActiveOption = true;
|
|
540
|
+
this.activeIndex.update(i => (i > 0 ? i - 1 : options.length - 1));
|
|
541
|
+
if (isAddressBarMode) {
|
|
542
|
+
this._fillInputFromActiveOption();
|
|
543
|
+
}
|
|
544
|
+
break;
|
|
545
|
+
case 'Escape':
|
|
546
|
+
event.preventDefault();
|
|
547
|
+
if (isAddressBarMode && this._valueBeforeNavigation !== null) {
|
|
548
|
+
this._revertToValueBeforeNavigation();
|
|
549
|
+
}
|
|
550
|
+
this._valueBeforeNavigation = null;
|
|
551
|
+
this._closePanel();
|
|
552
|
+
break;
|
|
553
|
+
case 'Tab':
|
|
554
|
+
this._valueBeforeNavigation = null;
|
|
555
|
+
this._closePanel();
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
_handleEnterKey(options, currentValue) {
|
|
560
|
+
const trimmedValue = currentValue.trim();
|
|
561
|
+
this._valueBeforeNavigation = null;
|
|
562
|
+
this.zOnCommit.emit({ value: trimmedValue, source: 'enter' });
|
|
563
|
+
if (this.zType() === 'address_bar') {
|
|
564
|
+
this._closePanel();
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
const idx = this.activeIndex();
|
|
568
|
+
if (options.length > 0) {
|
|
569
|
+
const selectedIdx = idx >= 0 && idx < options.length ? idx : 0;
|
|
570
|
+
this.selectOption(options[selectedIdx]);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
if (this.zAllowCustomValue() && trimmedValue) {
|
|
574
|
+
this.zOnEnter.emit(trimmedValue);
|
|
575
|
+
this._resetInput();
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
_fillInputFromActiveOption() {
|
|
579
|
+
const idx = this.activeIndex();
|
|
580
|
+
const options = this.filteredOptions();
|
|
581
|
+
if (idx < 0 || idx >= options.length) {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
const option = options[idx];
|
|
585
|
+
this._isNavigationFilling = true;
|
|
586
|
+
this.inputValue.set(option.label);
|
|
587
|
+
this._value.set(option.label);
|
|
588
|
+
this._onChange(option.label);
|
|
589
|
+
this.zValueChange.emit(option.label);
|
|
590
|
+
const inputEl = this.inputRef()?.nativeElement;
|
|
591
|
+
if (inputEl) {
|
|
592
|
+
inputEl.value = option.label;
|
|
593
|
+
}
|
|
594
|
+
setTimeout(() => {
|
|
595
|
+
this._isNavigationFilling = false;
|
|
596
|
+
}, 0);
|
|
597
|
+
}
|
|
598
|
+
_revertToValueBeforeNavigation() {
|
|
599
|
+
if (this._valueBeforeNavigation === null) {
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
const value = this._valueBeforeNavigation;
|
|
603
|
+
this._isNavigationFilling = true;
|
|
604
|
+
this.inputValue.set(value);
|
|
605
|
+
this._value.set(value);
|
|
606
|
+
this._onChange(value);
|
|
607
|
+
this.zValueChange.emit(value);
|
|
608
|
+
if (this.zType() === 'address_bar') {
|
|
609
|
+
this.searchQuery.set(value);
|
|
610
|
+
}
|
|
611
|
+
const inputEl = this.inputRef()?.nativeElement;
|
|
612
|
+
if (inputEl) {
|
|
613
|
+
inputEl.value = value;
|
|
614
|
+
}
|
|
615
|
+
this._valueBeforeNavigation = null;
|
|
616
|
+
setTimeout(() => {
|
|
617
|
+
this._isNavigationFilling = false;
|
|
618
|
+
}, 0);
|
|
619
|
+
}
|
|
620
|
+
_resetInput() {
|
|
621
|
+
if (!this.zResetOnSelect()) {
|
|
622
|
+
this._closePanel();
|
|
623
|
+
this.activeIndex.set(-1);
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
this.inputValue.set('');
|
|
627
|
+
this._value.set('');
|
|
628
|
+
this._onChange('');
|
|
629
|
+
this.zValueChange.emit('');
|
|
630
|
+
if (!this.hasAsyncOptions()) {
|
|
631
|
+
this._query$.next('');
|
|
632
|
+
}
|
|
633
|
+
this._closePanel();
|
|
634
|
+
this.activeIndex.set(-1);
|
|
635
|
+
}
|
|
636
|
+
onPopoverControl(control) {
|
|
637
|
+
this._popoverControl.set(control);
|
|
638
|
+
}
|
|
639
|
+
onPopoverShow() {
|
|
640
|
+
this.uiState.update(s => ({ ...s, isOpen: true }));
|
|
641
|
+
this._resetOptionsScrollTop();
|
|
642
|
+
this._loadAsyncOptionsOnFocus();
|
|
643
|
+
// Panel chỉ mở khi user focus/click thật, tức ancestor (vd. modal) đã hết animation transform —
|
|
644
|
+
// đ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().
|
|
645
|
+
const triggerEl = this.triggerRef()?.nativeElement;
|
|
646
|
+
if (triggerEl) {
|
|
647
|
+
this.dropdownWidth.set(triggerEl.getBoundingClientRect().width);
|
|
648
|
+
}
|
|
649
|
+
setTimeout(() => {
|
|
650
|
+
this.inputRef()?.nativeElement.focus();
|
|
651
|
+
}, 50);
|
|
652
|
+
}
|
|
653
|
+
onPopoverHideStart() {
|
|
654
|
+
this.uiState.update(s => ({ ...s, isOpen: false }));
|
|
655
|
+
this.activeIndex.set(-1);
|
|
656
|
+
this._clearLocalLoadingTimer();
|
|
657
|
+
this._pendingSearch.set(false);
|
|
658
|
+
this.debouncedQuery.set('');
|
|
659
|
+
if (!this.hasAsyncOptions()) {
|
|
660
|
+
this._query$.next('');
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
onPopoverHideEnd() {
|
|
664
|
+
this.actualPosition.set('bottom');
|
|
665
|
+
}
|
|
666
|
+
onPositionChange(position) {
|
|
667
|
+
this.actualPosition.set(position);
|
|
668
|
+
}
|
|
669
|
+
selectOption(option) {
|
|
670
|
+
if (option.disabled) {
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
this.uiState.update(s => ({ ...s, dirty: true }));
|
|
674
|
+
this.zOnSelect.emit(option);
|
|
675
|
+
this._selectedOption.set(option);
|
|
676
|
+
const newValue = this.zResetOnSelect() ? '' : option.label;
|
|
677
|
+
this.inputValue.set(newValue);
|
|
678
|
+
this._value.set(newValue);
|
|
679
|
+
this.debouncedQuery.set(newValue);
|
|
680
|
+
this._onChange(newValue);
|
|
681
|
+
this.zValueChange.emit(newValue);
|
|
682
|
+
this._valueBeforeNavigation = null;
|
|
683
|
+
if (this.config().closeOnSelect) {
|
|
684
|
+
this._closePanel();
|
|
685
|
+
}
|
|
686
|
+
this.activeIndex.set(-1);
|
|
687
|
+
}
|
|
688
|
+
clearInput(event) {
|
|
689
|
+
event.stopPropagation();
|
|
690
|
+
event.preventDefault();
|
|
691
|
+
this.inputValue.set('');
|
|
692
|
+
this._value.set('');
|
|
693
|
+
this.uiState.update(s => ({ ...s, dirty: true }));
|
|
694
|
+
this._onChange('');
|
|
695
|
+
this.zValueChange.emit('');
|
|
696
|
+
this._selectedOption.set(null);
|
|
697
|
+
this._closePanel();
|
|
698
|
+
this._clearLocalLoadingTimer();
|
|
699
|
+
this._pendingSearch.set(false);
|
|
700
|
+
this.debouncedQuery.set('');
|
|
701
|
+
if (this.zType() === 'address_bar') {
|
|
702
|
+
this.searchQuery.set('');
|
|
703
|
+
}
|
|
704
|
+
if (!this.hasAsyncOptions()) {
|
|
705
|
+
this._query$.next('');
|
|
706
|
+
}
|
|
707
|
+
this.zOnCommit.emit({ value: '', source: 'blur' });
|
|
708
|
+
this._resetAsyncOptions();
|
|
709
|
+
setTimeout(() => {
|
|
710
|
+
this.inputRef()?.nativeElement.focus();
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
getOptionClasses(option, index) {
|
|
714
|
+
return zAutocompleteOptionVariants({
|
|
715
|
+
customTemplate: this.hasCustomOptionTemplate(),
|
|
716
|
+
active: this.activeIndex() === index,
|
|
717
|
+
disabled: option.disabled ?? false,
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
trackByValue = (index, option) => {
|
|
721
|
+
const key = this._getOptionKey(option);
|
|
722
|
+
return `${String(key)}::${index}`;
|
|
723
|
+
};
|
|
724
|
+
focus() {
|
|
725
|
+
this.inputRef()?.nativeElement.focus();
|
|
726
|
+
}
|
|
727
|
+
blur() {
|
|
728
|
+
this.inputRef()?.nativeElement.blur();
|
|
729
|
+
}
|
|
730
|
+
clear() {
|
|
731
|
+
this.inputValue.set('');
|
|
732
|
+
this._value.set('');
|
|
733
|
+
this.debouncedQuery.set('');
|
|
734
|
+
this._onChange('');
|
|
735
|
+
this.zValueChange.emit('');
|
|
736
|
+
this._selectedOption.set(null);
|
|
737
|
+
this._closePanel();
|
|
738
|
+
this._clearLocalLoadingTimer();
|
|
739
|
+
this._pendingSearch.set(false);
|
|
740
|
+
this._resetAsyncOptions();
|
|
741
|
+
if (this.zType() === 'address_bar') {
|
|
742
|
+
this.searchQuery.set('');
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
reset() {
|
|
746
|
+
this.clear();
|
|
747
|
+
this.uiState.update(s => ({ ...s, touched: false, dirty: false }));
|
|
748
|
+
}
|
|
749
|
+
open() {
|
|
750
|
+
this._openPanel();
|
|
751
|
+
}
|
|
752
|
+
close() {
|
|
753
|
+
this._closePanel();
|
|
754
|
+
}
|
|
755
|
+
setValue(value) {
|
|
756
|
+
this._value.set(value);
|
|
757
|
+
this.inputValue.set(value);
|
|
758
|
+
this.debouncedQuery.set(value);
|
|
759
|
+
this._selectedOption.set(null);
|
|
760
|
+
this._onChange(value);
|
|
761
|
+
if (this.zType() === 'address_bar') {
|
|
762
|
+
this.searchQuery.set(value);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
_openPanel() {
|
|
766
|
+
if (this.isInteractionDisabled()) {
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
this._popoverControl()?.show();
|
|
770
|
+
}
|
|
771
|
+
_closePanel() {
|
|
772
|
+
this._popoverControl()?.close();
|
|
773
|
+
}
|
|
774
|
+
_setupDebounce() {
|
|
775
|
+
this._query$
|
|
776
|
+
.pipe(debounceTime(this.effectiveDebounceTime()), distinctUntilChanged(), takeUntilDestroyed(this._destroyRef))
|
|
777
|
+
.subscribe(query => {
|
|
778
|
+
if (this.zType() === 'address_bar') {
|
|
779
|
+
this.searchQuery.set(query);
|
|
780
|
+
}
|
|
781
|
+
this.debouncedQuery.set(query);
|
|
782
|
+
this.zOnSearch.emit(query);
|
|
783
|
+
if (this.hasAsyncOptions()) {
|
|
784
|
+
this._loadAsyncOptions(query, false);
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
if (this.config().serverSearch) {
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
this._clearLocalLoadingTimer();
|
|
791
|
+
this._pendingSearch.set(true);
|
|
792
|
+
this._localLoadingTimeout = setTimeout(() => {
|
|
793
|
+
this._pendingSearch.set(false);
|
|
794
|
+
this._localLoadingTimeout = null;
|
|
795
|
+
}, 100);
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
_loadAsyncOptionsOnFocus() {
|
|
799
|
+
const asyncConfig = this.config().async;
|
|
800
|
+
if (!asyncConfig?.loadOnFocus) {
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
const keyword = this.inputValue().trim();
|
|
804
|
+
if (this._asyncKeyword() === keyword && this._asyncOptions().length > 0) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
this._loadAsyncOptions(keyword, false);
|
|
808
|
+
}
|
|
809
|
+
_loadAsyncOptions(keyword, append) {
|
|
810
|
+
const asyncConfig = this.config().async;
|
|
811
|
+
if (!asyncConfig) {
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
const normalizedKeyword = keyword.trim();
|
|
815
|
+
const pageSize = asyncConfig.pageSize ?? Z_ASYNC_OPTIONS_DEFAULT_PAGE_SIZE;
|
|
816
|
+
const { minLength } = this.config();
|
|
817
|
+
const canLoadEmptyOnFocus = asyncConfig.loadOnFocus && normalizedKeyword.length === 0;
|
|
818
|
+
if (!append && normalizedKeyword.length < minLength && !canLoadEmptyOnFocus) {
|
|
819
|
+
this._resetAsyncOptions();
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
if (append && (!this._asyncHasMore() || this._asyncLoading() || this._asyncLoadingMore())) {
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
const page = append ? this._asyncPage() + 1 : 1;
|
|
826
|
+
const requestId = ++this._asyncRequestId;
|
|
827
|
+
const scrollTopBeforeAppend = append ? this._getAsyncOptionsScrollTop() : null;
|
|
828
|
+
if (!append) {
|
|
829
|
+
this._asyncLoadSubscription?.unsubscribe();
|
|
830
|
+
this._asyncKeyword.set(normalizedKeyword);
|
|
831
|
+
this._asyncLoading.set(true);
|
|
832
|
+
this._asyncHasMore.set(false);
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
this._asyncLoadingMore.set(true);
|
|
836
|
+
}
|
|
837
|
+
let result;
|
|
838
|
+
try {
|
|
839
|
+
result = asyncConfig.load({
|
|
840
|
+
keyword: normalizedKeyword,
|
|
841
|
+
page,
|
|
842
|
+
pageSize,
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
catch (error) {
|
|
846
|
+
this._handleAsyncOptionsError(error, append);
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
this._asyncLoadSubscription = zToAsyncOptionsObservable(result)
|
|
850
|
+
.pipe(finalize(() => {
|
|
851
|
+
if (requestId !== this._asyncRequestId) {
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
this._asyncLoading.set(false);
|
|
855
|
+
this._asyncLoadingMore.set(false);
|
|
856
|
+
}), takeUntilDestroyed(this._destroyRef))
|
|
857
|
+
.subscribe({
|
|
858
|
+
next: response => {
|
|
859
|
+
if (requestId !== this._asyncRequestId) {
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
const nextItems = response.items ?? [];
|
|
863
|
+
const previousCount = this._asyncOptions().length;
|
|
864
|
+
const mergedOptions = append
|
|
865
|
+
? zMergeAsyncOptions(this._asyncOptions(), nextItems, asyncConfig.dedupeBy)
|
|
866
|
+
: zMergeAsyncOptions([], nextItems, asyncConfig.dedupeBy);
|
|
867
|
+
const hasNewItems = mergedOptions.length > previousCount;
|
|
868
|
+
if (append && !hasNewItems) {
|
|
869
|
+
this._asyncHasMore.set(false);
|
|
870
|
+
this._restoreAsyncOptionsScrollTop(scrollTopBeforeAppend);
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
this._asyncOptions.set(mergedOptions);
|
|
874
|
+
this._asyncPage.set(page);
|
|
875
|
+
this._asyncHasMore.set(append && !hasNewItems ? false : zResolveAsyncOptionsHasMore(response, pageSize, mergedOptions.length));
|
|
876
|
+
if (append) {
|
|
877
|
+
this._restoreAsyncOptionsScrollTop(scrollTopBeforeAppend);
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
this._resetOptionsScrollTop();
|
|
881
|
+
},
|
|
882
|
+
error: error => {
|
|
883
|
+
if (requestId !== this._asyncRequestId) {
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
this._handleAsyncOptionsError(error, append);
|
|
887
|
+
},
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
_handleAsyncOptionsError(error, append) {
|
|
891
|
+
console.error('ZAutocomplete async options load failed:', error);
|
|
892
|
+
if (!append) {
|
|
893
|
+
this._asyncOptions.set([]);
|
|
894
|
+
this._asyncPage.set(1);
|
|
895
|
+
}
|
|
896
|
+
this._asyncHasMore.set(false);
|
|
897
|
+
this._asyncLoading.set(false);
|
|
898
|
+
this._asyncLoadingMore.set(false);
|
|
899
|
+
}
|
|
900
|
+
_getAsyncOptionsScrollTop() {
|
|
901
|
+
return this._getOptionsScrollElement()?.scrollTop ?? null;
|
|
902
|
+
}
|
|
903
|
+
_restoreAsyncOptionsScrollTop(scrollTop) {
|
|
904
|
+
if (scrollTop === null) {
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
requestAnimationFrame(() => {
|
|
908
|
+
const scrollElement = this._getOptionsScrollElement();
|
|
909
|
+
if (scrollElement) {
|
|
910
|
+
scrollElement.scrollTop = scrollTop;
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
_resetOptionsScrollTop(attempt = 0) {
|
|
915
|
+
requestAnimationFrame(() => {
|
|
916
|
+
const scrollElement = this._getOptionsScrollElement();
|
|
917
|
+
if (!scrollElement && attempt < 3) {
|
|
918
|
+
this._resetOptionsScrollTop(attempt + 1);
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
if (!scrollElement) {
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
if (this.shouldUseVirtualScroll()) {
|
|
925
|
+
this.virtualizer.scrollToOffset(0);
|
|
926
|
+
}
|
|
927
|
+
scrollElement.scrollTop = 0;
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
_getOptionsScrollElement() {
|
|
931
|
+
if (this.shouldUseVirtualScroll()) {
|
|
932
|
+
return this.virtualScrollRef()?.nativeElement ?? null;
|
|
933
|
+
}
|
|
934
|
+
return this.optionsContainerRef()?.nativeElement ?? null;
|
|
935
|
+
}
|
|
936
|
+
_resetAsyncOptions() {
|
|
937
|
+
this._asyncLoadSubscription?.unsubscribe();
|
|
938
|
+
this._asyncRequestId++;
|
|
939
|
+
this._asyncOptions.set([]);
|
|
940
|
+
this._asyncKeyword.set('');
|
|
941
|
+
this._asyncPage.set(1);
|
|
942
|
+
this._asyncHasMore.set(false);
|
|
943
|
+
this._asyncLoading.set(false);
|
|
944
|
+
this._asyncLoadingMore.set(false);
|
|
945
|
+
}
|
|
946
|
+
_clearLocalLoadingTimer() {
|
|
947
|
+
if (!this._localLoadingTimeout) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
clearTimeout(this._localLoadingTimeout);
|
|
951
|
+
this._localLoadingTimeout = null;
|
|
952
|
+
}
|
|
953
|
+
_setupLoadMoreObserver() {
|
|
954
|
+
this._cleanupLoadMoreObserver();
|
|
955
|
+
const sentinel = this.loadMoreSentinelRef()?.nativeElement;
|
|
956
|
+
const container = this.optionsContainerRef()?.nativeElement;
|
|
957
|
+
if (!sentinel || !container) {
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
this._loadMoreObserver = new IntersectionObserver(entries => {
|
|
961
|
+
const entry = entries[0];
|
|
962
|
+
if (entry?.isIntersecting && !this.isLoadingMore()) {
|
|
963
|
+
this._handleLoadMore(container.scrollTop);
|
|
964
|
+
}
|
|
965
|
+
}, {
|
|
966
|
+
root: container,
|
|
967
|
+
rootMargin: '100px',
|
|
968
|
+
threshold: 0,
|
|
969
|
+
});
|
|
970
|
+
this._loadMoreObserver.observe(sentinel);
|
|
971
|
+
}
|
|
972
|
+
_cleanupLoadMoreObserver() {
|
|
973
|
+
if (!this._loadMoreObserver) {
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
this._loadMoreObserver.disconnect();
|
|
977
|
+
this._loadMoreObserver = null;
|
|
978
|
+
}
|
|
979
|
+
_setupVirtualScrollLoadMore() {
|
|
980
|
+
this._cleanupVirtualScrollListener();
|
|
981
|
+
const scrollElement = this.virtualScrollRef()?.nativeElement;
|
|
982
|
+
if (!scrollElement) {
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
const handleScroll = () => {
|
|
986
|
+
if (this.isLoadingMore()) {
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
const { scrollTop, scrollHeight, clientHeight } = scrollElement;
|
|
990
|
+
const threshold = clientHeight * this.zScrollDistance();
|
|
991
|
+
const distanceFromBottom = scrollHeight - scrollTop - clientHeight;
|
|
992
|
+
if (distanceFromBottom <= threshold) {
|
|
993
|
+
this._handleLoadMore(scrollTop);
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
scrollElement.addEventListener('scroll', handleScroll);
|
|
997
|
+
this._virtualScrollListener = () => {
|
|
998
|
+
scrollElement.removeEventListener('scroll', handleScroll);
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
_cleanupVirtualScrollListener() {
|
|
1002
|
+
if (!this._virtualScrollListener) {
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
this._virtualScrollListener();
|
|
1006
|
+
this._virtualScrollListener = null;
|
|
1007
|
+
}
|
|
1008
|
+
_handleLoadMore(scrollTop) {
|
|
1009
|
+
if (this.hasAsyncOptions()) {
|
|
1010
|
+
if (!this.canLoadMore()) {
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
this._loadAsyncOptions(this._asyncKeyword(), true);
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
this.zOnLoadMore.emit({
|
|
1017
|
+
currentCount: this.filteredOptions().length,
|
|
1018
|
+
scrollTop,
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
_emitControl() {
|
|
1022
|
+
this.zControl.emit({
|
|
1023
|
+
focus: () => this.focus(),
|
|
1024
|
+
blur: () => this.blur(),
|
|
1025
|
+
clear: () => this.clear(),
|
|
1026
|
+
reset: () => this.reset(),
|
|
1027
|
+
open: () => this.open(),
|
|
1028
|
+
close: () => this.close(),
|
|
1029
|
+
setValue: (val) => this.setValue(val),
|
|
1030
|
+
value: this._value.asReadonly(),
|
|
1031
|
+
selected: this.selected,
|
|
1032
|
+
state: this.state,
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
_getOptionKey(option) {
|
|
1036
|
+
const key = this.zKey();
|
|
1037
|
+
if (key && key in option) {
|
|
1038
|
+
return option[key];
|
|
1039
|
+
}
|
|
1040
|
+
if (key && typeof option.value === 'object' && option.value !== null && key in option.value) {
|
|
1041
|
+
return option.value[key];
|
|
1042
|
+
}
|
|
1043
|
+
return option.value;
|
|
1044
|
+
}
|
|
1045
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZAutocompleteComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1046
|
+
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 }, zDropdownMaxHeight: { classPropertyName: "zDropdownMaxHeight", publicName: "zDropdownMaxHeight", 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: [
|
|
1047
|
+
{
|
|
1048
|
+
provide: NG_VALUE_ACCESSOR,
|
|
1049
|
+
useExisting: forwardRef(() => ZAutocompleteComponent),
|
|
1050
|
+
multi: true,
|
|
1051
|
+
},
|
|
1052
|
+
], 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 });
|
|
1053
|
+
}
|
|
1054
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZAutocompleteComponent, decorators: [{
|
|
1055
|
+
type: Component,
|
|
1056
|
+
args: [{ selector: 'z-autocomplete', imports: [
|
|
1057
|
+
FormsModule,
|
|
1058
|
+
NgClass,
|
|
1059
|
+
NgTemplateOutlet,
|
|
1060
|
+
ZIconComponent,
|
|
1061
|
+
ZLoadingComponent,
|
|
1062
|
+
ZPopoverDirective,
|
|
1063
|
+
ZTooltipDirective,
|
|
1064
|
+
ZEmptyComponent,
|
|
1065
|
+
ZHighlightPipe,
|
|
1066
|
+
ZSafeHtmlPipe,
|
|
1067
|
+
], standalone: true, providers: [
|
|
1068
|
+
{
|
|
1069
|
+
provide: NG_VALUE_ACCESSOR,
|
|
1070
|
+
useExisting: forwardRef(() => ZAutocompleteComponent),
|
|
1071
|
+
multi: true,
|
|
1072
|
+
},
|
|
1073
|
+
], 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"] }]
|
|
1074
|
+
}], 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 }] }], zDropdownMaxHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "zDropdownMaxHeight", 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"] }] } });
|
|
1075
|
+
|
|
1076
|
+
/**
|
|
1077
|
+
* Generated bundle index. Do not edit.
|
|
1078
|
+
*/
|
|
1079
|
+
|
|
1080
|
+
export { ZAutocompleteComponent, ZAutocompleteOptionDirective, Z_AUTOCOMPLETE_DEFAULT_CONFIG, zAutocompleteInputVariants, zAutocompleteOptionVariants };
|
|
1081
|
+
//# sourceMappingURL=shival99-z-ui-components-z-autocomplete.mjs.map
|