@kato-lee/components 1.0.5 → 1.0.7

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.
@@ -1,10 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Pipe, Component, ViewChild, Input, EventEmitter, Self, Optional, Output, NgModule } from '@angular/core';
2
+ import { Pipe, Component, ViewChild, Input, EventEmitter, Self, Optional, Output, NgModule, ViewEncapsulation, ChangeDetectionStrategy } from '@angular/core';
3
3
  import { ESCAPE } from '@kato-lee/cdk/keycodes';
4
4
  import * as i10 from '@angular/common';
5
5
  import { CommonModule } from '@angular/common';
6
6
  import * as i1 from '@angular/forms';
7
- import { FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
7
+ import { FormsModule, ReactiveFormsModule, Validators, FormControl } from '@angular/forms';
8
8
  import * as i2 from '@kato-lee/material/form-field';
9
9
  import { MatFormFieldModule } from '@kato-lee/material/form-field';
10
10
  import * as i7 from '@kato-lee/material/select';
@@ -22,13 +22,15 @@ import { MatDatepickerModule } from '@kato-lee/material/datepicker';
22
22
  import * as i8 from '@kato-lee/material/tooltip';
23
23
  import { MatTooltipModule } from '@kato-lee/material/tooltip';
24
24
  import { takeUntil } from 'rxjs/operators';
25
- import { Subject, takeUntil as takeUntil$1, map, debounceTime } from 'rxjs';
25
+ import { Subject, takeUntil as takeUntil$1, map, debounceTime, distinctUntilChanged, firstValueFrom } from 'rxjs';
26
26
  import * as i9 from '@kato-lee/material/menu';
27
27
  import { MatMenuModule } from '@kato-lee/material/menu';
28
28
  import * as i2$1 from '@kato-lee/material/progress-spinner';
29
29
  import { MatProgressSpinnerModule } from '@kato-lee/material/progress-spinner';
30
30
  import * as i5$1 from '@kato-lee/material/autocomplete';
31
31
  import { MatAutocompleteModule } from '@kato-lee/material/autocomplete';
32
+ import * as i1$1 from '@angular/common/http';
33
+ import * as i2$2 from '@kato-lee/components/toast';
32
34
 
33
35
  class TakErrorEqualsPipe {
34
36
  transform(errors, error, args) {
@@ -1383,6 +1385,171 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
1383
1385
  type: Output
1384
1386
  }] } });
1385
1387
 
1388
+ class TakRemoteAutocompleteFieldComponent {
1389
+ constructor(_http, _cd, _toast) {
1390
+ this._http = _http;
1391
+ this._cd = _cd;
1392
+ this._toast = _toast;
1393
+ this.remoteUrl = '';
1394
+ this.params = {};
1395
+ this.option = 'option';
1396
+ this.extraInfo = '';
1397
+ this.justOneLoad = false;
1398
+ this.onSelect = new EventEmitter();
1399
+ this.suggestions = [];
1400
+ this.autocomplete = new FormControl();
1401
+ this._isLoading = false;
1402
+ this.isValueSelected = false;
1403
+ this._unsubscribe$ = new Subject();
1404
+ this._isLoadingItem = false;
1405
+ this._isRequired = true;
1406
+ this._value = '';
1407
+ this._notSuggestions = false;
1408
+ this.wasLoaded = false;
1409
+ }
1410
+ async ngOnInit() {
1411
+ if (!this.justOneLoad) {
1412
+ this.autocomplete.valueChanges
1413
+ .pipe(takeUntil$1(this._unsubscribe$), debounceTime(500), distinctUntilChanged())
1414
+ .subscribe(async (value) => {
1415
+ if (value &&
1416
+ !this.suggestions.filter(suggestion => suggestion.getNombre() === value).length) {
1417
+ this._isLoading = true;
1418
+ this._cd.markForCheck();
1419
+ try {
1420
+ const result = await firstValueFrom(this._http.get(this.remoteUrl, {
1421
+ params: this.params,
1422
+ }));
1423
+ if (result.length !== 0) {
1424
+ this.suggestions = result;
1425
+ if (`${value}`.toLocaleLowerCase() ===
1426
+ `${this.suggestions[0][this.option]}`.toLocaleLowerCase()) {
1427
+ this.autocomplete.setValue(`${this.suggestions[0][this.option]}`, {
1428
+ emitEvent: false,
1429
+ });
1430
+ this.onSelect.emit(this.suggestions[0]);
1431
+ document.body.dispatchEvent(TAK_PRESS_ESC_KEY);
1432
+ }
1433
+ }
1434
+ else {
1435
+ this._toast.notification('No existen items que contengan esta palabra clave');
1436
+ }
1437
+ }
1438
+ catch (error) {
1439
+ this._toast.danger(error.error.message);
1440
+ }
1441
+ this._isLoading = false;
1442
+ this._cd.markForCheck();
1443
+ }
1444
+ });
1445
+ }
1446
+ else {
1447
+ try {
1448
+ const result = await firstValueFrom(this._http.get(this.remoteUrl, {
1449
+ params: this.params,
1450
+ }));
1451
+ this.suggestions = result;
1452
+ this.wasLoaded = true;
1453
+ this._cd.markForCheck();
1454
+ this._filteredOptions = this.autocomplete.valueChanges.pipe(takeUntil$1(this._unsubscribe$), map(() => this._filter()));
1455
+ }
1456
+ catch (error) {
1457
+ this._toast.danger(error.error.message);
1458
+ }
1459
+ }
1460
+ }
1461
+ _filter() {
1462
+ const value = typeof `${this.autocomplete.value}` === 'string'
1463
+ ? `${this.autocomplete.value}`.toLowerCase()
1464
+ : `${this.autocomplete.value[this.option]}`.toLowerCase();
1465
+ const option = this.suggestions.filter(res => `${res[this.option]}`.toLowerCase().includes(value));
1466
+ if (!option.length)
1467
+ this._notSuggestions = true;
1468
+ else
1469
+ this._notSuggestions = false;
1470
+ return option;
1471
+ }
1472
+ async refresh() {
1473
+ try {
1474
+ const result = await firstValueFrom(this._http.get(this.remoteUrl, {
1475
+ params: this.params,
1476
+ }));
1477
+ this.suggestions = result;
1478
+ this.autocomplete.setValue('');
1479
+ this._toast.notification('Data actualizada correctamente');
1480
+ this._cd.markForCheck();
1481
+ }
1482
+ catch (error) {
1483
+ this._toast.danger(error.error.message);
1484
+ }
1485
+ }
1486
+ reset() {
1487
+ if (!this.justOneLoad) {
1488
+ this.autocomplete.reset();
1489
+ }
1490
+ else {
1491
+ this.autocomplete.setValue('');
1492
+ }
1493
+ this.onSelect.emit(null);
1494
+ }
1495
+ emit(el, option) {
1496
+ if (el.isUserInput) {
1497
+ this.onSelect.emit(option);
1498
+ }
1499
+ }
1500
+ ngOnDestroy() {
1501
+ this._unsubscribe$.next();
1502
+ this._unsubscribe$.complete();
1503
+ }
1504
+ get isLoading() {
1505
+ return this._isLoading;
1506
+ }
1507
+ get isRequired() {
1508
+ return this._isRequired;
1509
+ }
1510
+ get isLoadingItem() {
1511
+ return this._isLoadingItem;
1512
+ }
1513
+ get filteredOptions() {
1514
+ return this._filteredOptions;
1515
+ }
1516
+ get value() {
1517
+ return `${this._value}`;
1518
+ }
1519
+ get notSuggestions() {
1520
+ return this._notSuggestions;
1521
+ }
1522
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: TakRemoteAutocompleteFieldComponent, deps: [{ token: i1$1.HttpClient }, { token: i0.ChangeDetectorRef }, { token: i2$2.TakToast }], target: i0.ɵɵFactoryTarget.Component }); }
1523
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.3.3", type: TakRemoteAutocompleteFieldComponent, isStandalone: true, selector: "tak-remote-autocomplete-field", inputs: { remoteUrl: "remoteUrl", params: "params", option: "option", extraInfo: "extraInfo", justOneLoad: "justOneLoad" }, outputs: { onSelect: "onSelect" }, ngImport: i0, template: "@if (!justOneLoad || (justOneLoad && wasLoaded)) {\r\n <mat-form-field appearance=\"standard\">\r\n <mat-label>\r\n <ng-content></ng-content>{{ ' ' }}\r\n @if (isRequired) {\r\n <span class=\"gcm-field__danger-x\">*</span>\r\n }\r\n </mat-label>\r\n <input matInput [formControl]=\"autocomplete\" [matAutocomplete]=\"auto\" />\r\n\r\n @if (isLoading || (autocomplete.value === null && isLoadingItem)) {\r\n <mat-spinner\r\n mat-icon-button\r\n [diameter]=\"15\"\r\n mode=\"indeterminate\"\r\n class=\"spinner-loading\"\r\n ></mat-spinner>\r\n }\r\n <!---->\r\n\r\n @if (autocomplete.value) {\r\n <button mat-icon-button matSuffix (click)=\"reset()\">\r\n <mat-icon>close</mat-icon>\r\n </button>\r\n }\r\n @if (justOneLoad && !autocomplete.value) {\r\n <button mat-icon-button matSuffix (click)=\"refresh()\">\r\n <mat-icon>refresh</mat-icon>\r\n </button>\r\n }\r\n\r\n <mat-autocomplete autoActiveFirstOption #auto=\"matAutocomplete\">\r\n @if (!justOneLoad) {\r\n @for (suggestion of suggestions; track $index) {\r\n <mat-option\r\n [value]=\"suggestion[option]\"\r\n title=\"{{ suggestion[option] }} {{\r\n extraInfo ? '(' + suggestion[extraInfo] + ')' : ''\r\n }}\"\r\n (onSelectionChange)=\"emit($event, suggestion)\"\r\n >\r\n <span>{{ suggestion[option] }}</span>\r\n @if (extraInfo) {\r\n <span class=\"mat-option-span-extra\">{{ suggestion[extraInfo] }}</span>\r\n }\r\n </mat-option>\r\n }\r\n @if (notSuggestions) {\r\n <mat-option>\r\n <span class=\"tak-autocomplete-not-records\"> No se encuentran resultados </span>\r\n </mat-option>\r\n }\r\n } @else {\r\n @for (suggestion of filteredOptions | async; track $index) {\r\n <mat-option\r\n [value]=\"suggestion[option]\"\r\n title=\"{{ suggestion[option] }} {{\r\n extraInfo ? '(' + suggestion[extraInfo] + ')' : ''\r\n }}\"\r\n (onSelectionChange)=\"emit($event, suggestion)\"\r\n >\r\n <span>{{ suggestion[option] }}</span>\r\n @if (extraInfo) {\r\n <span class=\"mat-option-span-extra\">{{ suggestion[extraInfo] }}</span>\r\n }\r\n </mat-option>\r\n }\r\n @if (notSuggestions) {\r\n <mat-option>\r\n <span class=\"tak-autocomplete-not-records\"> No se encuentran resultados </span>\r\n </mat-option>\r\n }\r\n }\r\n </mat-autocomplete>\r\n </mat-form-field>\r\n}\r\n", styles: ["mat-spinner.spinner-loading{display:inline;margin-left:-10px}mat-spinner.spinner-loading>svg{margin-top:-5px}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.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: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "ngmodule", type: MatProgressSpinnerModule }, { kind: "component", type: i2$1.MatProgressSpinner, selector: "mat-progress-spinner, mat-spinner", inputs: ["color", "diameter", "strokeWidth", "mode", "value"], exportAs: ["matProgressSpinner"] }, { kind: "ngmodule", type: MatFormFieldModule }, { kind: "component", type: i2.MatFormField, selector: "mat-form-field", inputs: ["color", "appearance", "hideRequiredMarker", "hintLabel", "floatLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i2.MatLabel, selector: "mat-label" }, { kind: "directive", type: i2.MatSuffix, selector: "[matSuffix]" }, { kind: "ngmodule", type: MatInputModule }, { kind: "directive", type: i6.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "ngmodule", type: MatAutocompleteModule }, { kind: "component", type: i5$1.MatAutocomplete, selector: "mat-autocomplete", inputs: ["disableRipple"], exportAs: ["matAutocomplete"] }, { kind: "directive", type: i5$1.MatAutocompleteTrigger, selector: "input[matAutocomplete], textarea[matAutocomplete]", exportAs: ["matAutocompleteTrigger"] }, { kind: "component", type: i4.MatOption, selector: "mat-option", exportAs: ["matOption"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i5.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i3.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { kind: "ngmodule", type: CommonModule }, { kind: "pipe", type: i10.AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
1524
+ }
1525
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: TakRemoteAutocompleteFieldComponent, decorators: [{
1526
+ type: Component,
1527
+ args: [{ standalone: true, imports: [
1528
+ FormsModule,
1529
+ MatProgressSpinnerModule,
1530
+ MatFormFieldModule,
1531
+ MatFormFieldModule,
1532
+ MatInputModule,
1533
+ ReactiveFormsModule,
1534
+ MatAutocompleteModule,
1535
+ MatIconModule,
1536
+ MatButtonModule,
1537
+ CommonModule,
1538
+ ], selector: 'tak-remote-autocomplete-field', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (!justOneLoad || (justOneLoad && wasLoaded)) {\r\n <mat-form-field appearance=\"standard\">\r\n <mat-label>\r\n <ng-content></ng-content>{{ ' ' }}\r\n @if (isRequired) {\r\n <span class=\"gcm-field__danger-x\">*</span>\r\n }\r\n </mat-label>\r\n <input matInput [formControl]=\"autocomplete\" [matAutocomplete]=\"auto\" />\r\n\r\n @if (isLoading || (autocomplete.value === null && isLoadingItem)) {\r\n <mat-spinner\r\n mat-icon-button\r\n [diameter]=\"15\"\r\n mode=\"indeterminate\"\r\n class=\"spinner-loading\"\r\n ></mat-spinner>\r\n }\r\n <!---->\r\n\r\n @if (autocomplete.value) {\r\n <button mat-icon-button matSuffix (click)=\"reset()\">\r\n <mat-icon>close</mat-icon>\r\n </button>\r\n }\r\n @if (justOneLoad && !autocomplete.value) {\r\n <button mat-icon-button matSuffix (click)=\"refresh()\">\r\n <mat-icon>refresh</mat-icon>\r\n </button>\r\n }\r\n\r\n <mat-autocomplete autoActiveFirstOption #auto=\"matAutocomplete\">\r\n @if (!justOneLoad) {\r\n @for (suggestion of suggestions; track $index) {\r\n <mat-option\r\n [value]=\"suggestion[option]\"\r\n title=\"{{ suggestion[option] }} {{\r\n extraInfo ? '(' + suggestion[extraInfo] + ')' : ''\r\n }}\"\r\n (onSelectionChange)=\"emit($event, suggestion)\"\r\n >\r\n <span>{{ suggestion[option] }}</span>\r\n @if (extraInfo) {\r\n <span class=\"mat-option-span-extra\">{{ suggestion[extraInfo] }}</span>\r\n }\r\n </mat-option>\r\n }\r\n @if (notSuggestions) {\r\n <mat-option>\r\n <span class=\"tak-autocomplete-not-records\"> No se encuentran resultados </span>\r\n </mat-option>\r\n }\r\n } @else {\r\n @for (suggestion of filteredOptions | async; track $index) {\r\n <mat-option\r\n [value]=\"suggestion[option]\"\r\n title=\"{{ suggestion[option] }} {{\r\n extraInfo ? '(' + suggestion[extraInfo] + ')' : ''\r\n }}\"\r\n (onSelectionChange)=\"emit($event, suggestion)\"\r\n >\r\n <span>{{ suggestion[option] }}</span>\r\n @if (extraInfo) {\r\n <span class=\"mat-option-span-extra\">{{ suggestion[extraInfo] }}</span>\r\n }\r\n </mat-option>\r\n }\r\n @if (notSuggestions) {\r\n <mat-option>\r\n <span class=\"tak-autocomplete-not-records\"> No se encuentran resultados </span>\r\n </mat-option>\r\n }\r\n }\r\n </mat-autocomplete>\r\n </mat-form-field>\r\n}\r\n", styles: ["mat-spinner.spinner-loading{display:inline;margin-left:-10px}mat-spinner.spinner-loading>svg{margin-top:-5px}\n"] }]
1539
+ }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i0.ChangeDetectorRef }, { type: i2$2.TakToast }], propDecorators: { remoteUrl: [{
1540
+ type: Input
1541
+ }], params: [{
1542
+ type: Input
1543
+ }], option: [{
1544
+ type: Input
1545
+ }], extraInfo: [{
1546
+ type: Input
1547
+ }], justOneLoad: [{
1548
+ type: Input
1549
+ }], onSelect: [{
1550
+ type: Output
1551
+ }] } });
1552
+
1386
1553
  const components = [
1387
1554
  TakSelectFieldComponent,
1388
1555
  TakDateFieldComponent,
@@ -1417,10 +1584,12 @@ class TakFieldsModule {
1417
1584
  MatOptionModule,
1418
1585
  MatSelectModule,
1419
1586
  MatTooltipModule,
1420
- MatMenuModule], exports: [ReactiveFormsModule,
1587
+ MatMenuModule,
1588
+ TakRemoteAutocompleteFieldComponent], exports: [ReactiveFormsModule,
1421
1589
  MatAutocompleteModule,
1422
1590
  FormsModule,
1423
- MatNativeDateModule, TakSelectFieldComponent,
1591
+ MatNativeDateModule,
1592
+ TakRemoteAutocompleteFieldComponent, TakSelectFieldComponent,
1424
1593
  TakDateFieldComponent,
1425
1594
  TakAutocompleteFieldComponent,
1426
1595
  TakDateRangeFieldComponent,
@@ -1443,7 +1612,8 @@ class TakFieldsModule {
1443
1612
  MatOptionModule,
1444
1613
  MatSelectModule,
1445
1614
  MatTooltipModule,
1446
- MatMenuModule, ReactiveFormsModule,
1615
+ MatMenuModule,
1616
+ TakRemoteAutocompleteFieldComponent, ReactiveFormsModule,
1447
1617
  MatAutocompleteModule,
1448
1618
  FormsModule,
1449
1619
  MatNativeDateModule] }); }
@@ -1469,12 +1639,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
1469
1639
  MatSelectModule,
1470
1640
  MatTooltipModule,
1471
1641
  MatMenuModule,
1642
+ TakRemoteAutocompleteFieldComponent,
1472
1643
  ],
1473
1644
  exports: [
1474
1645
  ReactiveFormsModule,
1475
1646
  MatAutocompleteModule,
1476
1647
  FormsModule,
1477
1648
  MatNativeDateModule,
1649
+ TakRemoteAutocompleteFieldComponent,
1478
1650
  ...components,
1479
1651
  ],
1480
1652
  providers: [{ provide: MAT_DATE_LOCALE, useValue: 'es-ES' }],
@@ -1498,5 +1670,5 @@ const email = Validators.pattern(TAK_PTRN_EMAIL);
1498
1670
  * Generated bundle index. Do not edit.
1499
1671
  */
1500
1672
 
1501
- export { TAK_DEFAULT_APPEARANCE_FORM, TAK_PRESS_ESC_KEY, TAK_PTRN_EMAIL, TAK_PTRN_NONSP, TAK_PTRN_NUMRC, TakAutocompleteFieldComponent, TakDateFieldComponent, TakDateRangeFieldComponent, TakErrorComponent, TakErrorEqualsPipe, TakErrorMsgPipe, TakFieldsModule, TakGeneralFieldComponent, TakMoneyFieldComponent, TakNumberFieldComponent, TakSelectFieldComponent, TakTextareaComponent, email, max, maxLength, min, minLength, onlyNumber, required, withOutSpaces };
1673
+ export { TAK_DEFAULT_APPEARANCE_FORM, TAK_PRESS_ESC_KEY, TAK_PTRN_EMAIL, TAK_PTRN_NONSP, TAK_PTRN_NUMRC, TakAutocompleteFieldComponent, TakDateFieldComponent, TakDateRangeFieldComponent, TakErrorComponent, TakErrorEqualsPipe, TakErrorMsgPipe, TakFieldsModule, TakGeneralFieldComponent, TakMoneyFieldComponent, TakNumberFieldComponent, TakRemoteAutocompleteFieldComponent, TakSelectFieldComponent, TakTextareaComponent, email, max, maxLength, min, minLength, onlyNumber, required, withOutSpaces };
1502
1674
  //# sourceMappingURL=kato-lee-components-fields.mjs.map