@sevtech/kit 0.0.1

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.
@@ -0,0 +1,583 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, inject, Injectable, viewChild, input, booleanAttribute, numberAttribute, computed, effect, Directive, contentChild, TemplateRef, signal, forwardRef, HostListener, ChangeDetectionStrategy, Component } from '@angular/core';
3
+ import { NgTemplateOutlet } from '@angular/common';
4
+ import * as i2 from '@angular/forms';
5
+ import { FormControl, ReactiveFormsModule, NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms';
6
+ import * as i3 from 'primeng/iconfield';
7
+ import { IconFieldModule } from 'primeng/iconfield';
8
+ import * as i4 from 'primeng/inputicon';
9
+ import { InputIconModule } from 'primeng/inputicon';
10
+ import { HttpClient } from '@angular/common/http';
11
+ import { isDefined, isFunction, isNil, isArray, noop, isNonEmptyString, isEmptyArray, isNonEmptyArray, isString } from '@sevtech/kit/misc';
12
+ import { map, BehaviorSubject, filter, switchMap, debounceTime, distinctUntilChanged, skip, tap, first, catchError, of } from 'rxjs';
13
+ import { toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
14
+ import * as i1 from 'primeng/inputtext';
15
+ import { InputText, InputTextModule } from 'primeng/inputtext';
16
+ import { Overlay } from 'primeng/overlay';
17
+ import { AutoFocus } from 'primeng/autofocus';
18
+ import { htmlBooleanAttribute } from '@sevtech/kit/ng-misc';
19
+ import { PrimeNG } from 'primeng/config';
20
+
21
+ const DEFAULT_CONFIG = {
22
+ delay: 300,
23
+ apiUrl: '/yoda/ajax',
24
+ itemsShow: 20,
25
+ minQueryLength: 0,
26
+ };
27
+ const CONFIG = new InjectionToken('[CONFIG]: Конфигурация параметров по умолчанию', {
28
+ providedIn: 'root',
29
+ factory: () => DEFAULT_CONFIG,
30
+ });
31
+ function provideYodaConfig(config) {
32
+ return {
33
+ provide: CONFIG,
34
+ useValue: {
35
+ ...DEFAULT_CONFIG,
36
+ ...config,
37
+ },
38
+ };
39
+ }
40
+
41
+ class YodaService {
42
+ constructor() {
43
+ this.config = inject(CONFIG);
44
+ this.httpClient = inject(HttpClient);
45
+ }
46
+ request(params) {
47
+ const [url, queryParams] = this.buildUrl(params);
48
+ return this.httpClient.get(url, {
49
+ params: queryParams,
50
+ responseType: 'json',
51
+ });
52
+ }
53
+ buildUrl({ apiUrl, ...params }) {
54
+ if (isDefined(apiUrl)) {
55
+ return isFunction(apiUrl) ? [apiUrl(params), {}] : [apiUrl, params];
56
+ }
57
+ if (isNil(params.action) || isNil(params.repository)) {
58
+ throw new Error('[YODA]: action or repository is not defined');
59
+ }
60
+ return [this.config.apiUrl, params];
61
+ }
62
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: YodaService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
63
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: YodaService, providedIn: 'root' }); }
64
+ }
65
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: YodaService, decorators: [{
66
+ type: Injectable,
67
+ args: [{
68
+ providedIn: 'root'
69
+ }]
70
+ }] });
71
+
72
+ class YodaBase {
73
+ get inputElementRef() {
74
+ return this.inputRef()?.el.nativeElement ?? null;
75
+ }
76
+ constructor() {
77
+ this.config = inject(CONFIG);
78
+ this.primeConfig = inject(PrimeNG);
79
+ this.inputRef = viewChild(InputText, ...(ngDevMode ? [{ debugName: "inputRef" }] : []));
80
+ this.id = input(...(ngDevMode ? [undefined, { debugName: "id" }] : []));
81
+ this.name = input(...(ngDevMode ? [undefined, { debugName: "name" }] : []));
82
+ this.placeholder = input(...(ngDevMode ? [undefined, { debugName: "placeholder" }] : []));
83
+ this.size = input(...(ngDevMode ? [undefined, { debugName: "size" }] : []));
84
+ this.autocomplete = input('off', ...(ngDevMode ? [{ debugName: "autocomplete" }] : []));
85
+ this.variant = input('outlined', ...(ngDevMode ? [{ debugName: "variant" }] : []));
86
+ this.disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
87
+ this.autofocus = input(false, ...(ngDevMode ? [{ debugName: "autofocus", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
88
+ this.required = input(undefined, ...(ngDevMode ? [{ debugName: "required", transform: htmlBooleanAttribute }] : [{ transform: htmlBooleanAttribute }]));
89
+ this.inputReadonly = input(undefined, ...(ngDevMode ? [{ debugName: "inputReadonly", alias: 'readonly', transform: htmlBooleanAttribute }] : [{ alias: 'readonly', transform: htmlBooleanAttribute }]));
90
+ this.tabindex = input(undefined, ...(ngDevMode ? [{ debugName: "tabindex", transform: numberAttribute }] : [{ transform: numberAttribute }]));
91
+ this.minlength = input(undefined, ...(ngDevMode ? [{ debugName: "minlength", transform: numberAttribute }] : [{ transform: numberAttribute }]));
92
+ this.maxlength = input(undefined, ...(ngDevMode ? [{ debugName: "maxlength", transform: numberAttribute }] : [{ transform: numberAttribute }]));
93
+ this.inputSize = input(undefined, ...(ngDevMode ? [{ debugName: "inputSize", transform: numberAttribute }] : [{ transform: numberAttribute }]));
94
+ this.overlayOptions = input(...(ngDevMode ? [undefined, { debugName: "overlayOptions" }] : []));
95
+ this.overlayHideTransition = input('.1s linear', ...(ngDevMode ? [{ debugName: "overlayHideTransition" }] : []));
96
+ this.overlayShowTransition = input('.12s cubic-bezier(0, 0, 0.2, 1)', ...(ngDevMode ? [{ debugName: "overlayShowTransition" }] : []));
97
+ this.overlayAppendTo = input('body', ...(ngDevMode ? [{ debugName: "overlayAppendTo" }] : []));
98
+ this.appendTo$$ = computed(this.computeAppendTo.bind(this), ...(ngDevMode ? [{ debugName: "appendTo$$" }] : []));
99
+ effect(() => this.changeInputSize(this.inputRef(), this.size()));
100
+ }
101
+ computeAppendTo() {
102
+ return this.overlayAppendTo() || this.primeConfig.overlayOptions?.appendTo;
103
+ }
104
+ changeInputSize(inputRef, size) {
105
+ if (isNil(inputRef) || isNil(size)) {
106
+ return;
107
+ }
108
+ inputRef.pSize = size;
109
+ }
110
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: YodaBase, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
111
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "20.3.17", type: YodaBase, isStandalone: true, inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, autocomplete: { classPropertyName: "autocomplete", publicName: "autocomplete", isSignal: true, isRequired: false, transformFunction: null }, variant: { classPropertyName: "variant", publicName: "variant", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, autofocus: { classPropertyName: "autofocus", publicName: "autofocus", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, inputReadonly: { classPropertyName: "inputReadonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, tabindex: { classPropertyName: "tabindex", publicName: "tabindex", isSignal: true, isRequired: false, transformFunction: null }, minlength: { classPropertyName: "minlength", publicName: "minlength", isSignal: true, isRequired: false, transformFunction: null }, maxlength: { classPropertyName: "maxlength", publicName: "maxlength", isSignal: true, isRequired: false, transformFunction: null }, inputSize: { classPropertyName: "inputSize", publicName: "inputSize", isSignal: true, isRequired: false, transformFunction: null }, overlayOptions: { classPropertyName: "overlayOptions", publicName: "overlayOptions", isSignal: true, isRequired: false, transformFunction: null }, overlayHideTransition: { classPropertyName: "overlayHideTransition", publicName: "overlayHideTransition", isSignal: true, isRequired: false, transformFunction: null }, overlayShowTransition: { classPropertyName: "overlayShowTransition", publicName: "overlayShowTransition", isSignal: true, isRequired: false, transformFunction: null }, overlayAppendTo: { classPropertyName: "overlayAppendTo", publicName: "overlayAppendTo", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "inputRef", first: true, predicate: InputText, descendants: true, isSignal: true }], ngImport: i0 }); }
112
+ }
113
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: YodaBase, decorators: [{
114
+ type: Directive
115
+ }], ctorParameters: () => [], propDecorators: { inputRef: [{ type: i0.ViewChild, args: [i0.forwardRef(() => InputText), { isSignal: true }] }], id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], autocomplete: [{ type: i0.Input, args: [{ isSignal: true, alias: "autocomplete", required: false }] }], variant: [{ type: i0.Input, args: [{ isSignal: true, alias: "variant", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], autofocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "autofocus", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], inputReadonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], tabindex: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabindex", required: false }] }], minlength: [{ type: i0.Input, args: [{ isSignal: true, alias: "minlength", required: false }] }], maxlength: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxlength", required: false }] }], inputSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "inputSize", required: false }] }], overlayOptions: [{ type: i0.Input, args: [{ isSignal: true, alias: "overlayOptions", required: false }] }], overlayHideTransition: [{ type: i0.Input, args: [{ isSignal: true, alias: "overlayHideTransition", required: false }] }], overlayShowTransition: [{ type: i0.Input, args: [{ isSignal: true, alias: "overlayShowTransition", required: false }] }], overlayAppendTo: [{ type: i0.Input, args: [{ isSignal: true, alias: "overlayAppendTo", required: false }] }] } });
116
+
117
+ function limitIndex(index, max, circular) {
118
+ if (circular) {
119
+ return index < 0
120
+ ? max
121
+ : index > max
122
+ ? 0
123
+ : index;
124
+ }
125
+ return Math.max(0, Math.min(index || 0, max));
126
+ }
127
+ function findFirstValidIndex(options, isValid) {
128
+ if (isArray(options)) {
129
+ return options.findIndex(isValid);
130
+ }
131
+ return -1;
132
+ }
133
+
134
+ // TODO:
135
+ // 1. Вынести иконки в отдельных компонент
136
+ // 2. Вынести список в отдельный компонент
137
+ // 3. Cделать select режим
138
+ // 4. Cделать multiple режим
139
+ // 5. Сделать режим отображения списка как в оверлее так и как часть контента
140
+ // 6. Cделать оутпут евент с выбранными опциями
141
+ // 7. на мобилках нужно показывать мобильный дропдаун
142
+ class Yoda extends YodaBase {
143
+ get isDisabled() {
144
+ return this.queryStringControl.disabled;
145
+ }
146
+ get transformOptionsFn() {
147
+ return this.transformOptions();
148
+ }
149
+ get disabledOptionFn() {
150
+ return this.disabledOption();
151
+ }
152
+ constructor() {
153
+ super();
154
+ this.yodaService = inject(YodaService);
155
+ this.listRef = viewChild('listRef', ...(ngDevMode ? [{ debugName: "listRef" }] : []));
156
+ this.hintContentRef = contentChild('hint', ...(ngDevMode ? [{ debugName: "hintContentRef", read: TemplateRef }] : [{ read: TemplateRef }]));
157
+ this.emptyContentRef = contentChild('empty', ...(ngDevMode ? [{ debugName: "emptyContentRef", read: TemplateRef }] : [{ read: TemplateRef }]));
158
+ this.headerContentRef = contentChild('header', ...(ngDevMode ? [{ debugName: "headerContentRef", read: TemplateRef }] : [{ read: TemplateRef }]));
159
+ this.footerContentRef = contentChild('footer', ...(ngDevMode ? [{ debugName: "footerContentRef", read: TemplateRef }] : [{ read: TemplateRef }]));
160
+ this.optionContentRef = contentChild('option', ...(ngDevMode ? [{ debugName: "optionContentRef", read: TemplateRef }] : [{ read: TemplateRef }]));
161
+ this.groupOptionContentRef = contentChild('groupOption', ...(ngDevMode ? [{ debugName: "groupOptionContentRef", read: TemplateRef }] : [{ read: TemplateRef }]));
162
+ this.action = input(...(ngDevMode ? [undefined, { debugName: "action" }] : []));
163
+ this.repository = input(...(ngDevMode ? [undefined, { debugName: "repository" }] : []));
164
+ this.apiUrl = input(...(ngDevMode ? [undefined, { debugName: "apiUrl" }] : []));
165
+ this.hintMessage = input(...(ngDevMode ? [undefined, { debugName: "hintMessage" }] : []));
166
+ this.createMode = input('always', ...(ngDevMode ? [{ debugName: "createMode" }] : []));
167
+ this.scrollHeight = input('200px', ...(ngDevMode ? [{ debugName: "scrollHeight" }] : []));
168
+ this.emptyMessage = input('Элементы не найдены', ...(ngDevMode ? [{ debugName: "emptyMessage" }] : []));
169
+ this.viewMode = input('overlay', ...(ngDevMode ? [{ debugName: "viewMode" }] : []));
170
+ this.group = input(true, ...(ngDevMode ? [{ debugName: "group", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
171
+ this.create = input(false, ...(ngDevMode ? [{ debugName: "create", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
172
+ this.showHint = input(true, ...(ngDevMode ? [{ debugName: "showHint", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
173
+ this.showEmpty = input(true, ...(ngDevMode ? [{ debugName: "showEmpty", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
174
+ this.showClear = input(true, ...(ngDevMode ? [{ debugName: "showClear", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
175
+ this.showCreate = input(true, ...(ngDevMode ? [{ debugName: "showCreate", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
176
+ this.loopScroll = input(true, ...(ngDevMode ? [{ debugName: "loopScroll", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
177
+ this.showLoading = input(true, ...(ngDevMode ? [{ debugName: "showLoading", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
178
+ this.selectGroup = input(false, ...(ngDevMode ? [{ debugName: "selectGroup", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
179
+ this.groupSticky = input(false, ...(ngDevMode ? [{ debugName: "groupSticky", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
180
+ this.showDropdown = input(true, ...(ngDevMode ? [{ debugName: "showDropdown", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
181
+ this.autoSelect = input(false, ...(ngDevMode ? [{ debugName: "autoSelect", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
182
+ this.delay = input(this.config.delay, ...(ngDevMode ? [{ debugName: "delay", transform: (value) => numberAttribute(value, this.config.delay) }] : [{
183
+ transform: (value) => numberAttribute(value, this.config.delay),
184
+ }]));
185
+ this.itemsShow = input(this.config.itemsShow, ...(ngDevMode ? [{ debugName: "itemsShow", transform: (value) => numberAttribute(value, this.config.itemsShow) }] : [{
186
+ transform: (value) => numberAttribute(value, this.config.itemsShow),
187
+ }]));
188
+ this.minQueryLength = input(this.config.minQueryLength, ...(ngDevMode ? [{ debugName: "minQueryLength", transform: (value) => numberAttribute(value, this.config.minQueryLength) }] : [{
189
+ transform: (value) => numberAttribute(value, this.config.minQueryLength),
190
+ }]));
191
+ // TODO: сделать поддержку в интерфейсе
192
+ this.disabledOption = input(...(ngDevMode ? [undefined, { debugName: "disabledOption" }] : []));
193
+ this.transformOptions = input(...(ngDevMode ? [undefined, { debugName: "transformOptions" }] : []));
194
+ this.onTouched = noop;
195
+ this.onChange = noop;
196
+ this.onValidationChange = noop;
197
+ this.touched$$ = signal(false, ...(ngDevMode ? [{ debugName: "touched$$" }] : []));
198
+ this.isLoading$$ = signal(false, ...(ngDevMode ? [{ debugName: "isLoading$$" }] : []));
199
+ this.overlayVisible$$ = signal(false, ...(ngDevMode ? [{ debugName: "overlayVisible$$" }] : []));
200
+ this.focusedOptionIndex$$ = signal(-1, ...(ngDevMode ? [{ debugName: "focusedOptionIndex$$" }] : []));
201
+ this.queryString$$ = signal('', ...(ngDevMode ? [{ debugName: "queryString$$" }] : []));
202
+ this.options$$ = signal(null, ...(ngDevMode ? [{ debugName: "options$$" }] : []));
203
+ this.selectedOptions$$ = signal(null, ...(ngDevMode ? [{ debugName: "selectedOptions$$" }] : []));
204
+ this.queryStringControl = new FormControl(null);
205
+ this.queryString$ = this.queryStringControl.valueChanges.pipe(map((value) => this.normalizeQueryString(value)));
206
+ this.controlSubject = new BehaviorSubject(null);
207
+ this.isCreatDisabled$$ = computed(this.computeCreatDisabled.bind(this), ...(ngDevMode ? [{ debugName: "isCreatDisabled$$" }] : []));
208
+ this.iconType$$ = computed(this.computeIconType.bind(this), ...(ngDevMode ? [{ debugName: "iconType$$" }] : []));
209
+ this.canShowCreate$$ = computed(this.computeCanShowCreate.bind(this), ...(ngDevMode ? [{ debugName: "canShowCreate$$" }] : []));
210
+ this.filteredOptions$$ = computed(this.computeFilteredOptions.bind(this), ...(ngDevMode ? [{ debugName: "filteredOptions$$" }] : []));
211
+ this.optionsListStatus$$ = computed(this.computeOptionsListStatus.bind(this), ...(ngDevMode ? [{ debugName: "optionsListStatus$$" }] : []));
212
+ this.invalid$$ = toSignal(this.controlSubject.pipe(filter(isDefined), switchMap((control) => control.statusChanges), map((status) => status === 'INVALID')), { initialValue: false });
213
+ effect(this.markTouched.bind(this));
214
+ effect(() => this.changeDisabledState(this.disabled()));
215
+ this.queryString$
216
+ .pipe(debounceTime(this.delay()), distinctUntilChanged(this.compareFunction), skip(1), tap((queryString) => this.prepareSearch(queryString)), filter((query) => this.isValidQuery(query)), switchMap((query) => this.request(query, 1 /* ActionType.Search */)), tap((data) => this.handleSearch(data)), takeUntilDestroyed())
217
+ .subscribe();
218
+ }
219
+ compareFunction(previos, current) {
220
+ return isNonEmptyString(current) ? previos === current : false;
221
+ }
222
+ validate(control) {
223
+ if (isNil(this.controlSubject.getValue())) {
224
+ this.controlSubject.next(control);
225
+ }
226
+ return null;
227
+ }
228
+ registerOnValidatorChange(onValidationChange) {
229
+ this.onValidationChange = onValidationChange;
230
+ }
231
+ writeValue(value) {
232
+ if (isNil(value)) {
233
+ return;
234
+ }
235
+ this.request(value, 0 /* ActionType.Get */)
236
+ .pipe(first(), tap((data) => this.updateWithSelection(data)))
237
+ .subscribe();
238
+ }
239
+ registerOnChange(onChange) {
240
+ this.onChange = onChange;
241
+ }
242
+ registerOnTouched(onTouched) {
243
+ this.onTouched = onTouched;
244
+ }
245
+ setDisabledState(isDisabled) {
246
+ this.changeDisabledState(isDisabled);
247
+ }
248
+ isValidQuery(queryString) {
249
+ return queryString.length > this.minQueryLength();
250
+ }
251
+ actionIconClick(event, type) {
252
+ event.stopPropagation();
253
+ if (isDefined(this.inputElementRef)) {
254
+ this.inputElementRef.focus();
255
+ }
256
+ switch (type) {
257
+ case 'clear':
258
+ return this.clear();
259
+ case 'create':
260
+ return this.createByQuery();
261
+ }
262
+ }
263
+ showOverlay() {
264
+ this.overlayVisible$$.set(true);
265
+ this.focusFirstValidOption();
266
+ }
267
+ hideOverlay() {
268
+ this.overlayVisible$$.set(false);
269
+ this.focusedOptionIndex$$.set(-1);
270
+ }
271
+ clear() {
272
+ this.options$$.set(null);
273
+ this.updateQueryString(null);
274
+ this.updateSelectedOption(null);
275
+ }
276
+ inputFocus(event) {
277
+ event.preventDefault();
278
+ event.stopPropagation();
279
+ if (this.overlayVisible$$()) {
280
+ return;
281
+ }
282
+ if (this.inputReadonly() || this.isDisabled || isNil(this.optionsListStatus$$())) {
283
+ return;
284
+ }
285
+ this.overlayVisible$$.set(true);
286
+ }
287
+ onSelectOption(event) {
288
+ if (this.isDisabled || this.inputReadonly() || !this.overlayVisible$$() || this.isLoading$$()) {
289
+ return;
290
+ }
291
+ event.stopPropagation();
292
+ event.preventDefault();
293
+ this.selectFocusedOption();
294
+ }
295
+ moveFocus(event, index) {
296
+ if (!this.overlayVisible$$() || this.isDisabled || this.inputReadonly() || this.isLoading$$()) {
297
+ return;
298
+ }
299
+ event.preventDefault();
300
+ event.stopPropagation();
301
+ const options = this.filteredOptions$$();
302
+ if (isNil(options)) {
303
+ return;
304
+ }
305
+ this.focusedOptionIndex$$.update((currentIndex) => {
306
+ if (event instanceof PointerEvent) {
307
+ return this.isValidOption(options.at(index)) ? index : currentIndex;
308
+ }
309
+ return this.findNextValidIndex(options, currentIndex, index);
310
+ });
311
+ if (event instanceof KeyboardEvent) {
312
+ this.scrollToFocused();
313
+ }
314
+ }
315
+ computeFilteredOptions() {
316
+ let options = this.options$$();
317
+ if (isNil(options)) {
318
+ return null;
319
+ }
320
+ if (this.itemsShow() > 0) {
321
+ options = options.slice(0, this.itemsShow());
322
+ }
323
+ return options;
324
+ }
325
+ computeCanShowCreate() {
326
+ if (!this.create()) {
327
+ return false;
328
+ }
329
+ if (this.createMode() === 'always') {
330
+ return true;
331
+ }
332
+ return isEmptyArray(this.filteredOptions$$());
333
+ }
334
+ computeCreatDisabled() {
335
+ if (!this.create() || this.isLoading$$()) {
336
+ return true;
337
+ }
338
+ return !this.isValidQuery(this.queryString$$());
339
+ }
340
+ computeIconType() {
341
+ if (this.showLoading() && this.isLoading$$()) {
342
+ return 'loading';
343
+ }
344
+ if (this.showClear() && this.queryString$$().length > 0) {
345
+ return 'clear';
346
+ }
347
+ if (this.showDropdown()) {
348
+ return 'default';
349
+ }
350
+ }
351
+ computeOptionsListStatus() {
352
+ if (this.canShowHint(this.queryString$$())) {
353
+ return 'hint';
354
+ }
355
+ if (this.canShowEmpty(this.filteredOptions$$())) {
356
+ return 'empty';
357
+ }
358
+ if (isNonEmptyArray(this.filteredOptions$$())) {
359
+ return 'list';
360
+ }
361
+ return null;
362
+ }
363
+ focusFirstValidOption() {
364
+ const options = this.filteredOptions$$();
365
+ if (isNonEmptyArray(options)) {
366
+ this.focusedOptionIndex$$.set(findFirstValidIndex(options, (option) => this.isValidOption(option)));
367
+ }
368
+ }
369
+ updateQueryString(value, emitEvent = true) {
370
+ this.queryStringControl.patchValue(value, { emitEvent });
371
+ this.queryString$$.set(this.normalizeQueryString(value));
372
+ }
373
+ selectFocusedOption() {
374
+ const option = this.getFocusedOption(this.focusedOptionIndex$$(), this.filteredOptions$$());
375
+ if (isNil(option) || !this.isValidOption(option)) {
376
+ return;
377
+ }
378
+ this.updateSelectedOption(option);
379
+ this.updateQueryString(option.label, false);
380
+ this.overlayVisible$$.set(false);
381
+ this.inputElementRef?.blur();
382
+ }
383
+ findNextValidIndex(options, start, step) {
384
+ let nextIndex = limitIndex(start + step, options.length - 1, this.loopScroll());
385
+ for (let i = 0; i < options.length; i++) {
386
+ const item = options.at(nextIndex);
387
+ if (this.isValidOption(item)) {
388
+ return nextIndex;
389
+ }
390
+ nextIndex = limitIndex(nextIndex + step, options.length - 1, this.loopScroll());
391
+ if (nextIndex === start) {
392
+ break;
393
+ }
394
+ }
395
+ return start;
396
+ }
397
+ isValidOption(option) {
398
+ return isDefined(option) && !this.isDisabledOption(option) && this.canSelectGroupOption(option);
399
+ }
400
+ isDisabledOption(option) {
401
+ return isFunction(this.disabledOptionFn) ? this.disabledOptionFn(option) : false;
402
+ }
403
+ canSelectGroupOption(option) {
404
+ return !this.selectGroup() ? !option.groupHead : true;
405
+ }
406
+ updateSelectedOption(option) {
407
+ this.selectedOptions$$.set(option);
408
+ this.onChange(option?.value ?? null);
409
+ this.onValidationChange();
410
+ }
411
+ handleSearch(options) {
412
+ this.overlayVisible$$.set(true);
413
+ this.options$$.set(options);
414
+ this.focusFirstValidOption();
415
+ if (this.autoSelect() && options.length === 1) {
416
+ this.selectFocusedOption();
417
+ }
418
+ }
419
+ prepareSearch(queryString) {
420
+ this.touched$$.set(true);
421
+ this.queryString$$.set(queryString);
422
+ if (this.selectedOptions$$()) {
423
+ this.updateSelectedOption(null);
424
+ }
425
+ if (!this.overlayVisible$$()) {
426
+ this.overlayVisible$$.set(true);
427
+ }
428
+ if (queryString.length <= this.minQueryLength()) {
429
+ this.options$$.set(null);
430
+ }
431
+ }
432
+ canShowHint(queryString) {
433
+ return this.showHint() && !this.isValidQuery(queryString) && this.hasHintContent();
434
+ }
435
+ canShowEmpty(options) {
436
+ return this.showEmpty() && isEmptyArray(options) && this.hasEmptyContent();
437
+ }
438
+ hasHintContent() {
439
+ return isDefined(this.hintContentRef()) || isNonEmptyString(this.hintMessage());
440
+ }
441
+ hasEmptyContent() {
442
+ return isDefined(this.emptyContentRef()) || isNonEmptyString(this.emptyMessage());
443
+ }
444
+ getFocusedOption(index, options) {
445
+ if (isNil(options) || index < 0) {
446
+ return null;
447
+ }
448
+ return options.at(index) ?? null;
449
+ }
450
+ request(queryString, type) {
451
+ this.isLoading$$.set(true);
452
+ return this.yodaService
453
+ .request({
454
+ type,
455
+ queryString,
456
+ action: this.action(),
457
+ apiUrl: this.apiUrl(),
458
+ repository: this.repository(),
459
+ })
460
+ .pipe(map((data) => this.transformResponse(data)), map((options) => this.flattenOptions(options)), tap(() => this.isLoading$$.set(false)), catchError(() => {
461
+ this.isLoading$$.set(false);
462
+ return of([]);
463
+ }));
464
+ }
465
+ createByQuery() {
466
+ if (this.isCreatDisabled$$()) {
467
+ return;
468
+ }
469
+ this.request(this.queryString$$(), 2 /* ActionType.Create */)
470
+ .pipe(first(), tap((data) => this.updateWithSelection(data)))
471
+ .subscribe();
472
+ }
473
+ updateWithSelection(options) {
474
+ if (isNil(options) || options.length === 0) {
475
+ return;
476
+ }
477
+ this.options$$.update((state) => [...options, ...(state ?? [])]);
478
+ this.focusFirstValidOption();
479
+ this.selectFocusedOption();
480
+ }
481
+ transformResponse(data) {
482
+ if (isFunction(this.transformOptionsFn)) {
483
+ return this.transformOptionsFn(data);
484
+ }
485
+ return data.map(([value, label, ...payload]) => ({ value, label, payload }));
486
+ }
487
+ flattenOptions(options) {
488
+ return options.flatMap((item) => {
489
+ if ('items' in item && isArray(item.items)) {
490
+ const { items, ...options } = item;
491
+ return [{ ...options, groupHead: true }, ...items];
492
+ }
493
+ return item;
494
+ });
495
+ }
496
+ normalizeQueryString(value) {
497
+ return isString(value) ? value.trim() : '';
498
+ }
499
+ changeDisabledState(isDisabled) {
500
+ return isDisabled ? this.queryStringControl.disable() : this.queryStringControl.enable();
501
+ }
502
+ markTouched() {
503
+ if (this.touched$$()) {
504
+ this.onTouched();
505
+ }
506
+ }
507
+ scrollToFocused() {
508
+ const index = this.focusedOptionIndex$$();
509
+ const container = this.listRef()?.nativeElement;
510
+ if (isNil(container) || index < 0) {
511
+ return;
512
+ }
513
+ const listItem = container.querySelector(`li[data-index="${index}"]`);
514
+ if (isNil(listItem) || !isFunction(listItem.scrollIntoView)) {
515
+ return;
516
+ }
517
+ const options = {
518
+ behavior: 'auto',
519
+ block: 'nearest',
520
+ inline: 'nearest',
521
+ };
522
+ if (this.groupSticky()) {
523
+ options.inline = 'center';
524
+ options.block = 'center';
525
+ }
526
+ listItem.scrollIntoView(options);
527
+ }
528
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: Yoda, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
529
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.17", type: Yoda, isStandalone: true, selector: "erp-yoda", inputs: { action: { classPropertyName: "action", publicName: "action", isSignal: true, isRequired: false, transformFunction: null }, repository: { classPropertyName: "repository", publicName: "repository", isSignal: true, isRequired: false, transformFunction: null }, apiUrl: { classPropertyName: "apiUrl", publicName: "apiUrl", isSignal: true, isRequired: false, transformFunction: null }, hintMessage: { classPropertyName: "hintMessage", publicName: "hintMessage", isSignal: true, isRequired: false, transformFunction: null }, createMode: { classPropertyName: "createMode", publicName: "createMode", isSignal: true, isRequired: false, transformFunction: null }, scrollHeight: { classPropertyName: "scrollHeight", publicName: "scrollHeight", isSignal: true, isRequired: false, transformFunction: null }, emptyMessage: { classPropertyName: "emptyMessage", publicName: "emptyMessage", isSignal: true, isRequired: false, transformFunction: null }, viewMode: { classPropertyName: "viewMode", publicName: "viewMode", isSignal: true, isRequired: false, transformFunction: null }, group: { classPropertyName: "group", publicName: "group", isSignal: true, isRequired: false, transformFunction: null }, create: { classPropertyName: "create", publicName: "create", isSignal: true, isRequired: false, transformFunction: null }, showHint: { classPropertyName: "showHint", publicName: "showHint", isSignal: true, isRequired: false, transformFunction: null }, showEmpty: { classPropertyName: "showEmpty", publicName: "showEmpty", isSignal: true, isRequired: false, transformFunction: null }, showClear: { classPropertyName: "showClear", publicName: "showClear", isSignal: true, isRequired: false, transformFunction: null }, showCreate: { classPropertyName: "showCreate", publicName: "showCreate", isSignal: true, isRequired: false, transformFunction: null }, loopScroll: { classPropertyName: "loopScroll", publicName: "loopScroll", isSignal: true, isRequired: false, transformFunction: null }, showLoading: { classPropertyName: "showLoading", publicName: "showLoading", isSignal: true, isRequired: false, transformFunction: null }, selectGroup: { classPropertyName: "selectGroup", publicName: "selectGroup", isSignal: true, isRequired: false, transformFunction: null }, groupSticky: { classPropertyName: "groupSticky", publicName: "groupSticky", isSignal: true, isRequired: false, transformFunction: null }, showDropdown: { classPropertyName: "showDropdown", publicName: "showDropdown", isSignal: true, isRequired: false, transformFunction: null }, autoSelect: { classPropertyName: "autoSelect", publicName: "autoSelect", isSignal: true, isRequired: false, transformFunction: null }, delay: { classPropertyName: "delay", publicName: "delay", isSignal: true, isRequired: false, transformFunction: null }, itemsShow: { classPropertyName: "itemsShow", publicName: "itemsShow", isSignal: true, isRequired: false, transformFunction: null }, minQueryLength: { classPropertyName: "minQueryLength", publicName: "minQueryLength", isSignal: true, isRequired: false, transformFunction: null }, disabledOption: { classPropertyName: "disabledOption", publicName: "disabledOption", isSignal: true, isRequired: false, transformFunction: null }, transformOptions: { classPropertyName: "transformOptions", publicName: "transformOptions", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "keydown.tab": "hideOverlay()", "keydown.enter": "onSelectOption($event)", "keydown.arrowup": "moveFocus($event,-1)", "keydown.arrowdown": "moveFocus($event,1)" } }, providers: [
530
+ {
531
+ multi: true,
532
+ useExisting: forwardRef(() => Yoda),
533
+ provide: NG_VALUE_ACCESSOR,
534
+ },
535
+ {
536
+ multi: true,
537
+ useExisting: forwardRef(() => Yoda),
538
+ provide: NG_VALIDATORS,
539
+ },
540
+ ], queries: [{ propertyName: "hintContentRef", first: true, predicate: ["hint"], descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "emptyContentRef", first: true, predicate: ["empty"], descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "headerContentRef", first: true, predicate: ["header"], descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "footerContentRef", first: true, predicate: ["footer"], descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "optionContentRef", first: true, predicate: ["option"], descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "groupOptionContentRef", first: true, predicate: ["groupOption"], descendants: true, read: TemplateRef, isSignal: true }], viewQueries: [{ propertyName: "listRef", first: true, predicate: ["listRef"], descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0, template: "@let optionsListStatus = optionsListStatus$$();\n\n<p-iconfield>\n @if (showCreate() && canShowCreate$$()) {\n <p-inputicon\n class=\"pi pi-plus action\"\n [class.action__disabled]=\"isCreatDisabled$$()\"\n (click)=\"actionIconClick($event, 'create')\"\n />\n }\n\n <input\n #inputRef\n pInputText\n type=\"text\"\n role=\"combobox\"\n aria-autocomplete=\"list\"\n [class.ng-invalid.ng-dirty]=\"invalid$$()\"\n [attr.id]=\"id()\"\n [attr.name]=\"name()\"\n [attr.size]=\"inputSize()\"\n [attr.tabindex]=\"tabindex()\"\n [attr.required]=\"required()\"\n [attr.maxlength]=\"maxlength()\"\n [attr.minlength]=\"minlength()\"\n [attr.readonly]=\"inputReadonly()\"\n [attr.placeholder]=\"placeholder()\"\n [attr.autocomplete]=\"autocomplete()\"\n [variant]=\"variant()\"\n [pAutoFocus]=\"autofocus()\"\n [formControl]=\"queryStringControl\"\n (focus)=\"inputFocus($event)\"\n />\n\n @if (viewMode() === 'overlay') {\n <p-overlay\n #overlay\n target=\"@parent\"\n [appendTo]=\"appendTo$$()\"\n [options]=\"overlayOptions()\"\n [visible]=\"overlayVisible$$()\"\n [showTransitionOptions]=\"overlayShowTransition()\"\n [hideTransitionOptions]=\"overlayHideTransition()\"\n (onHide)=\"hideOverlay()\"\n (onBeforeShow)=\"showOverlay()\"\n >\n <ng-container\n [ngTemplateOutlet]=\"listLayoutTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: 'overlay' }\"\n />\n </p-overlay>\n }\n\n <ng-container\n [ngTemplateOutlet]=\"inputIconTempate\"\n [ngTemplateOutletContext]=\"{ $implicit: iconType$$() }\"\n />\n</p-iconfield>\n\n@if (viewMode() === 'inline') {\n <ng-container\n [ngTemplateOutlet]=\"listLayoutTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: 'inline' }\"\n />\n}\n\n<ng-template\n #inputIconTempate\n let-type\n>\n @switch (type) {\n @case ('loading') {\n <p-inputicon\n class=\"pi pi-spinner pi-spin\"\n (click)=\"actionIconClick($event, type)\"\n />\n }\n\n @case ('clear') {\n <p-inputicon\n class=\"pi pi-times action\"\n (click)=\"actionIconClick($event, type)\"\n />\n }\n\n @case ('default') {\n <p-inputicon\n class=\"pi pi-angle-down action\"\n (click)=\"actionIconClick($event, type)\"\n />\n }\n }\n</ng-template>\n\n<ng-template\n #listLayoutTemplate\n let-layoutStyleClass\n>\n @let headerContent = headerContentRef();\n @let footerContent = footerContentRef();\n\n @if (optionsListStatus) {\n <section\n class=\"yoda-list-layout\"\n [class]=\"layoutStyleClass\"\n >\n @if (optionsListStatus === 'list' && headerContent) {\n <header>\n <ng-container [ngTemplateOutlet]=\"headerContent\" />\n </header>\n }\n\n <div\n class=\"yoda-list-layout__content\"\n tabindex=\"-1\"\n [style.max-block-size]=\"scrollHeight()\"\n >\n <ng-container [ngTemplateOutlet]=\"listTemplate\" />\n </div>\n\n @if (optionsListStatus === 'list' && footerContent) {\n <footer>\n <ng-container [ngTemplateOutlet]=\"footerContent\" />\n </footer>\n }\n </section>\n }\n</ng-template>\n\n<ng-template #listTemplate>\n <ul\n #listRef\n class=\"yoda-list\"\n role=\"listbox\"\n [class.list--group]=\"group()\"\n >\n @switch (optionsListStatus$$()) {\n @case ('hint') {\n @let hintTemplate = hintContentRef();\n <li class=\"yoda-list__option list__option--hint\">\n @if (hintTemplate) {\n <ng-container [ngTemplateOutlet]=\"hintTemplate\" />\n } @else {\n <span>{{ hintMessage() }}</span>\n }\n </li>\n }\n @case ('empty') {\n @let emptyTemplate = emptyContentRef();\n <li class=\"yoda-list__option yoda-list__option--empty\">\n @if (emptyTemplate) {\n <ng-container [ngTemplateOutlet]=\"emptyTemplate\" />\n } @else {\n <span>{{ emptyMessage() }}</span>\n }\n </li>\n }\n @case ('list') {\n @for (item of filteredOptions$$(); track item.value; let index = $index) {\n @let isGroupHead = group() && item.groupHead;\n @let isFocused = focusedOptionIndex$$() === index;\n @let isSelected = selectedOptions$$()?.value === item.value;\n\n <li\n class=\"yoda-list__option\"\n role=\"option\"\n [class.focus]=\"isFocused\"\n [class.select]=\"isSelected\"\n [class.group-head]=\"isGroupHead\"\n [class.group-head--sticky]=\"isGroupHead && groupSticky()\"\n [attr.data-index]=\"index\"\n (click)=\"onSelectOption($event)\"\n (pointerenter)=\"moveFocus($event, index)\"\n >\n <ng-container\n [ngTemplateOutlet]=\"listItemTemplate\"\n [ngTemplateOutletContext]=\"{\n $implicit: item,\n template: isGroupHead ? groupOptionContentRef() : optionContentRef(),\n }\"\n />\n </li>\n }\n }\n }\n </ul>\n</ng-template>\n\n<ng-template\n #listItemTemplate\n let-item\n let-template=\"template\"\n>\n @if (template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"{ $implicit: item }\"\n />\n } @else {\n {{ item?.label }}\n }\n</ng-template>\n", styles: ["::ng-deep :root{--yoda-overlay-layout-padding-y: .5rem;--yoda-overlay-color: var(--p-overlay-select-color);--yoda-overlay-border-color: var(--p-overlay-select-border-color);--yoda-overlay-border-radius: var(--p-overlay-select-border-radius);--yoda-overlay-shadow: var(--p-overlay-select-shadow);--yoda-list-gap: .125rem;--yoda-list-padding-x: .75rem;--yoda-list-padding-y: .5rem;--yoda-list-background: var(--p-overlay-select-background);--yoda-list-color: var(--p-text-color);--yoda-list-muted-color: var(--p-text-muted-color);--yoda-list-header-padding: var(--yoda-list-padding-y) var(--yoda-list-padding-x);--yoda-list-footer-padding: var(--yoda-list-padding-y) var(--yoda-list-padding-x);--yoda-list-option-padding: var(--yoda-list-padding-y) var(--yoda-list-padding-x);--yoda-list-group-option-padding: var(--yoda-list-padding-y) calc(var(--yoda-list-padding-x) * 2);--yoda-list-option-focus-color: var(--p-text-hover-color);--yoda-list-option-focus-background: var(--p-surface-100);--yoda-list-option-selected-color: var(--p-highlight-focus-color);--yoda-list-option-selected-background: var(--p-highlight-background);--yoda-list-option-focus-selected-background: var( --p-highlight-focus-background )}:host{inline-size:100%}:host input{inline-size:100%;text-overflow:ellipsis}:host input:disabled{cursor:not-allowed}:host p-inputicon.action{cursor:pointer}:host p-inputicon.action__disabled{cursor:not-allowed}:host.p-component p-iconfield,:host.p-component input{border-radius:inherit}.yoda-list{color:var(--yoda-list-color);margin:0;list-style-type:none;display:flex;flex-direction:column}.yoda-list--group .yoda-list__option{padding:var(--yoda-list-group-option-padding)}.yoda-list--group .yoda-list__option.group-head,.yoda-list--group .yoda-list__option.yoda-list__option--hint,.yoda-list--group .yoda-list__option.yoda-list__option--empty{padding:var(--yoda-list-option-padding)}.yoda-list--group .yoda-list__option.group-head--sticky{position:sticky;top:0}.yoda-list__option{padding:var(--yoda-list-option-padding)}.yoda-list__option--hint span,.yoda-list__option--empty span{color:var(--yoda-list-muted-color)}.yoda-list__option[role=option]{text-overflow:ellipsis;overflow:hidden;white-space:nowrap;background:var(--yoda-list-background)}.yoda-list__option[role=option].focus{cursor:pointer;color:var(--yoda-list-option-focus-color);background:var(--yoda-list-option-focus-background)}.yoda-list__option[role=option].select{color:var(--yoda-list-option-selected-color);background:var(--yoda-list-option-selected-background)}.yoda-list__option[role=option].select.focus{background:var(--yoda-list-option-focus-selected-background)}.yoda-list-layout{display:flex;flex-direction:column;flex-wrap:nowrap;outline:none}.yoda-list-layout.overlay{min-inline-size:100%;max-inline-size:0;overflow:hidden;color:var(--yoda-overlay-color);background:var(--yoda-list-background);border:1px solid var(--yoda-overlay-border-color);border-radius:var(--yoda-overlay-border-radius);box-shadow:var(--yoda-overlay-shadow)}.yoda-list-layout.inline{width:100%;display:inline-flex}.yoda-list-layout header,.yoda-list-layout footer{display:flex;flex-direction:column;gap:var(--yoda-list-gap)}.yoda-list-layout header{padding:var(--yoda-list-header-padding)}.yoda-list-layout footer{padding:var(--yoda-list-footer-padding)}.yoda-list-layout__content{overflow:auto;outline:none}\n"], dependencies: [{ kind: "directive", type: AutoFocus, selector: "[pAutoFocus]", inputs: ["pAutoFocus"] }, { kind: "component", type: Overlay, selector: "p-overlay", inputs: ["hostName", "visible", "mode", "style", "styleClass", "contentStyle", "contentStyleClass", "target", "autoZIndex", "baseZIndex", "showTransitionOptions", "hideTransitionOptions", "listener", "responsive", "options", "appendTo", "hostAttrSelector"], outputs: ["visibleChange", "onBeforeShow", "onShow", "onBeforeHide", "onHide", "onAnimationStart", "onAnimationDone"] }, { kind: "ngmodule", type: InputTextModule }, { kind: "directive", type: i1.InputText, selector: "[pInputText]", inputs: ["hostName", "ptInputText", "pSize", "variant", "fluid", "invalid"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "ngmodule", type: IconFieldModule }, { kind: "component", type: i3.IconField, selector: "p-iconfield, p-iconField, p-icon-field", inputs: ["hostName", "iconPosition", "styleClass"] }, { kind: "ngmodule", type: InputIconModule }, { kind: "component", type: i4.InputIcon, selector: "p-inputicon, p-inputIcon", inputs: ["hostName", "styleClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
541
+ }
542
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: Yoda, decorators: [{
543
+ type: Component,
544
+ args: [{ selector: 'erp-yoda', changeDetection: ChangeDetectionStrategy.OnPush, imports: [
545
+ AutoFocus,
546
+ Overlay,
547
+ InputTextModule,
548
+ ReactiveFormsModule,
549
+ NgTemplateOutlet,
550
+ IconFieldModule,
551
+ InputIconModule,
552
+ ], providers: [
553
+ {
554
+ multi: true,
555
+ useExisting: forwardRef(() => Yoda),
556
+ provide: NG_VALUE_ACCESSOR,
557
+ },
558
+ {
559
+ multi: true,
560
+ useExisting: forwardRef(() => Yoda),
561
+ provide: NG_VALIDATORS,
562
+ },
563
+ ], template: "@let optionsListStatus = optionsListStatus$$();\n\n<p-iconfield>\n @if (showCreate() && canShowCreate$$()) {\n <p-inputicon\n class=\"pi pi-plus action\"\n [class.action__disabled]=\"isCreatDisabled$$()\"\n (click)=\"actionIconClick($event, 'create')\"\n />\n }\n\n <input\n #inputRef\n pInputText\n type=\"text\"\n role=\"combobox\"\n aria-autocomplete=\"list\"\n [class.ng-invalid.ng-dirty]=\"invalid$$()\"\n [attr.id]=\"id()\"\n [attr.name]=\"name()\"\n [attr.size]=\"inputSize()\"\n [attr.tabindex]=\"tabindex()\"\n [attr.required]=\"required()\"\n [attr.maxlength]=\"maxlength()\"\n [attr.minlength]=\"minlength()\"\n [attr.readonly]=\"inputReadonly()\"\n [attr.placeholder]=\"placeholder()\"\n [attr.autocomplete]=\"autocomplete()\"\n [variant]=\"variant()\"\n [pAutoFocus]=\"autofocus()\"\n [formControl]=\"queryStringControl\"\n (focus)=\"inputFocus($event)\"\n />\n\n @if (viewMode() === 'overlay') {\n <p-overlay\n #overlay\n target=\"@parent\"\n [appendTo]=\"appendTo$$()\"\n [options]=\"overlayOptions()\"\n [visible]=\"overlayVisible$$()\"\n [showTransitionOptions]=\"overlayShowTransition()\"\n [hideTransitionOptions]=\"overlayHideTransition()\"\n (onHide)=\"hideOverlay()\"\n (onBeforeShow)=\"showOverlay()\"\n >\n <ng-container\n [ngTemplateOutlet]=\"listLayoutTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: 'overlay' }\"\n />\n </p-overlay>\n }\n\n <ng-container\n [ngTemplateOutlet]=\"inputIconTempate\"\n [ngTemplateOutletContext]=\"{ $implicit: iconType$$() }\"\n />\n</p-iconfield>\n\n@if (viewMode() === 'inline') {\n <ng-container\n [ngTemplateOutlet]=\"listLayoutTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: 'inline' }\"\n />\n}\n\n<ng-template\n #inputIconTempate\n let-type\n>\n @switch (type) {\n @case ('loading') {\n <p-inputicon\n class=\"pi pi-spinner pi-spin\"\n (click)=\"actionIconClick($event, type)\"\n />\n }\n\n @case ('clear') {\n <p-inputicon\n class=\"pi pi-times action\"\n (click)=\"actionIconClick($event, type)\"\n />\n }\n\n @case ('default') {\n <p-inputicon\n class=\"pi pi-angle-down action\"\n (click)=\"actionIconClick($event, type)\"\n />\n }\n }\n</ng-template>\n\n<ng-template\n #listLayoutTemplate\n let-layoutStyleClass\n>\n @let headerContent = headerContentRef();\n @let footerContent = footerContentRef();\n\n @if (optionsListStatus) {\n <section\n class=\"yoda-list-layout\"\n [class]=\"layoutStyleClass\"\n >\n @if (optionsListStatus === 'list' && headerContent) {\n <header>\n <ng-container [ngTemplateOutlet]=\"headerContent\" />\n </header>\n }\n\n <div\n class=\"yoda-list-layout__content\"\n tabindex=\"-1\"\n [style.max-block-size]=\"scrollHeight()\"\n >\n <ng-container [ngTemplateOutlet]=\"listTemplate\" />\n </div>\n\n @if (optionsListStatus === 'list' && footerContent) {\n <footer>\n <ng-container [ngTemplateOutlet]=\"footerContent\" />\n </footer>\n }\n </section>\n }\n</ng-template>\n\n<ng-template #listTemplate>\n <ul\n #listRef\n class=\"yoda-list\"\n role=\"listbox\"\n [class.list--group]=\"group()\"\n >\n @switch (optionsListStatus$$()) {\n @case ('hint') {\n @let hintTemplate = hintContentRef();\n <li class=\"yoda-list__option list__option--hint\">\n @if (hintTemplate) {\n <ng-container [ngTemplateOutlet]=\"hintTemplate\" />\n } @else {\n <span>{{ hintMessage() }}</span>\n }\n </li>\n }\n @case ('empty') {\n @let emptyTemplate = emptyContentRef();\n <li class=\"yoda-list__option yoda-list__option--empty\">\n @if (emptyTemplate) {\n <ng-container [ngTemplateOutlet]=\"emptyTemplate\" />\n } @else {\n <span>{{ emptyMessage() }}</span>\n }\n </li>\n }\n @case ('list') {\n @for (item of filteredOptions$$(); track item.value; let index = $index) {\n @let isGroupHead = group() && item.groupHead;\n @let isFocused = focusedOptionIndex$$() === index;\n @let isSelected = selectedOptions$$()?.value === item.value;\n\n <li\n class=\"yoda-list__option\"\n role=\"option\"\n [class.focus]=\"isFocused\"\n [class.select]=\"isSelected\"\n [class.group-head]=\"isGroupHead\"\n [class.group-head--sticky]=\"isGroupHead && groupSticky()\"\n [attr.data-index]=\"index\"\n (click)=\"onSelectOption($event)\"\n (pointerenter)=\"moveFocus($event, index)\"\n >\n <ng-container\n [ngTemplateOutlet]=\"listItemTemplate\"\n [ngTemplateOutletContext]=\"{\n $implicit: item,\n template: isGroupHead ? groupOptionContentRef() : optionContentRef(),\n }\"\n />\n </li>\n }\n }\n }\n </ul>\n</ng-template>\n\n<ng-template\n #listItemTemplate\n let-item\n let-template=\"template\"\n>\n @if (template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"{ $implicit: item }\"\n />\n } @else {\n {{ item?.label }}\n }\n</ng-template>\n", styles: ["::ng-deep :root{--yoda-overlay-layout-padding-y: .5rem;--yoda-overlay-color: var(--p-overlay-select-color);--yoda-overlay-border-color: var(--p-overlay-select-border-color);--yoda-overlay-border-radius: var(--p-overlay-select-border-radius);--yoda-overlay-shadow: var(--p-overlay-select-shadow);--yoda-list-gap: .125rem;--yoda-list-padding-x: .75rem;--yoda-list-padding-y: .5rem;--yoda-list-background: var(--p-overlay-select-background);--yoda-list-color: var(--p-text-color);--yoda-list-muted-color: var(--p-text-muted-color);--yoda-list-header-padding: var(--yoda-list-padding-y) var(--yoda-list-padding-x);--yoda-list-footer-padding: var(--yoda-list-padding-y) var(--yoda-list-padding-x);--yoda-list-option-padding: var(--yoda-list-padding-y) var(--yoda-list-padding-x);--yoda-list-group-option-padding: var(--yoda-list-padding-y) calc(var(--yoda-list-padding-x) * 2);--yoda-list-option-focus-color: var(--p-text-hover-color);--yoda-list-option-focus-background: var(--p-surface-100);--yoda-list-option-selected-color: var(--p-highlight-focus-color);--yoda-list-option-selected-background: var(--p-highlight-background);--yoda-list-option-focus-selected-background: var( --p-highlight-focus-background )}:host{inline-size:100%}:host input{inline-size:100%;text-overflow:ellipsis}:host input:disabled{cursor:not-allowed}:host p-inputicon.action{cursor:pointer}:host p-inputicon.action__disabled{cursor:not-allowed}:host.p-component p-iconfield,:host.p-component input{border-radius:inherit}.yoda-list{color:var(--yoda-list-color);margin:0;list-style-type:none;display:flex;flex-direction:column}.yoda-list--group .yoda-list__option{padding:var(--yoda-list-group-option-padding)}.yoda-list--group .yoda-list__option.group-head,.yoda-list--group .yoda-list__option.yoda-list__option--hint,.yoda-list--group .yoda-list__option.yoda-list__option--empty{padding:var(--yoda-list-option-padding)}.yoda-list--group .yoda-list__option.group-head--sticky{position:sticky;top:0}.yoda-list__option{padding:var(--yoda-list-option-padding)}.yoda-list__option--hint span,.yoda-list__option--empty span{color:var(--yoda-list-muted-color)}.yoda-list__option[role=option]{text-overflow:ellipsis;overflow:hidden;white-space:nowrap;background:var(--yoda-list-background)}.yoda-list__option[role=option].focus{cursor:pointer;color:var(--yoda-list-option-focus-color);background:var(--yoda-list-option-focus-background)}.yoda-list__option[role=option].select{color:var(--yoda-list-option-selected-color);background:var(--yoda-list-option-selected-background)}.yoda-list__option[role=option].select.focus{background:var(--yoda-list-option-focus-selected-background)}.yoda-list-layout{display:flex;flex-direction:column;flex-wrap:nowrap;outline:none}.yoda-list-layout.overlay{min-inline-size:100%;max-inline-size:0;overflow:hidden;color:var(--yoda-overlay-color);background:var(--yoda-list-background);border:1px solid var(--yoda-overlay-border-color);border-radius:var(--yoda-overlay-border-radius);box-shadow:var(--yoda-overlay-shadow)}.yoda-list-layout.inline{width:100%;display:inline-flex}.yoda-list-layout header,.yoda-list-layout footer{display:flex;flex-direction:column;gap:var(--yoda-list-gap)}.yoda-list-layout header{padding:var(--yoda-list-header-padding)}.yoda-list-layout footer{padding:var(--yoda-list-footer-padding)}.yoda-list-layout__content{overflow:auto;outline:none}\n"] }]
564
+ }], ctorParameters: () => [], propDecorators: { listRef: [{ type: i0.ViewChild, args: ['listRef', { isSignal: true }] }], hintContentRef: [{ type: i0.ContentChild, args: ['hint', { ...{ read: TemplateRef }, isSignal: true }] }], emptyContentRef: [{ type: i0.ContentChild, args: ['empty', { ...{ read: TemplateRef }, isSignal: true }] }], headerContentRef: [{ type: i0.ContentChild, args: ['header', { ...{ read: TemplateRef }, isSignal: true }] }], footerContentRef: [{ type: i0.ContentChild, args: ['footer', { ...{ read: TemplateRef }, isSignal: true }] }], optionContentRef: [{ type: i0.ContentChild, args: ['option', { ...{ read: TemplateRef }, isSignal: true }] }], groupOptionContentRef: [{ type: i0.ContentChild, args: ['groupOption', { ...{ read: TemplateRef }, isSignal: true }] }], action: [{ type: i0.Input, args: [{ isSignal: true, alias: "action", required: false }] }], repository: [{ type: i0.Input, args: [{ isSignal: true, alias: "repository", required: false }] }], apiUrl: [{ type: i0.Input, args: [{ isSignal: true, alias: "apiUrl", required: false }] }], hintMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "hintMessage", required: false }] }], createMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "createMode", required: false }] }], scrollHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "scrollHeight", required: false }] }], emptyMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "emptyMessage", required: false }] }], viewMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewMode", required: false }] }], group: [{ type: i0.Input, args: [{ isSignal: true, alias: "group", required: false }] }], create: [{ type: i0.Input, args: [{ isSignal: true, alias: "create", required: false }] }], showHint: [{ type: i0.Input, args: [{ isSignal: true, alias: "showHint", required: false }] }], showEmpty: [{ type: i0.Input, args: [{ isSignal: true, alias: "showEmpty", required: false }] }], showClear: [{ type: i0.Input, args: [{ isSignal: true, alias: "showClear", required: false }] }], showCreate: [{ type: i0.Input, args: [{ isSignal: true, alias: "showCreate", required: false }] }], loopScroll: [{ type: i0.Input, args: [{ isSignal: true, alias: "loopScroll", required: false }] }], showLoading: [{ type: i0.Input, args: [{ isSignal: true, alias: "showLoading", required: false }] }], selectGroup: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectGroup", required: false }] }], groupSticky: [{ type: i0.Input, args: [{ isSignal: true, alias: "groupSticky", required: false }] }], showDropdown: [{ type: i0.Input, args: [{ isSignal: true, alias: "showDropdown", required: false }] }], autoSelect: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoSelect", required: false }] }], delay: [{ type: i0.Input, args: [{ isSignal: true, alias: "delay", required: false }] }], itemsShow: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemsShow", required: false }] }], minQueryLength: [{ type: i0.Input, args: [{ isSignal: true, alias: "minQueryLength", required: false }] }], disabledOption: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabledOption", required: false }] }], transformOptions: [{ type: i0.Input, args: [{ isSignal: true, alias: "transformOptions", required: false }] }], hideOverlay: [{
565
+ type: HostListener,
566
+ args: ['keydown.tab']
567
+ }], onSelectOption: [{
568
+ type: HostListener,
569
+ args: ['keydown.enter', ['$event']]
570
+ }], moveFocus: [{
571
+ type: HostListener,
572
+ args: ['keydown.arrowup', ['$event', '-1']]
573
+ }, {
574
+ type: HostListener,
575
+ args: ['keydown.arrowdown', ['$event', '1']]
576
+ }] } });
577
+
578
+ /**
579
+ * Generated bundle index. Do not edit.
580
+ */
581
+
582
+ export { Yoda, provideYodaConfig };
583
+ //# sourceMappingURL=ui-yoda.mjs.map