@3kles/kles-material-dynamicforms 14.9.2 → 14.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import { CommonModule } from '@angular/common';
5
5
  import * as i2 from '@angular/forms';
6
6
  import { FormControl, Validators, FormControlDirective, FormControlName, NG_VALUE_ACCESSOR, UntypedFormGroup, UntypedFormControl, FormArray, FormGroup, ReactiveFormsModule, FormsModule } from '@angular/forms';
7
7
  import { concat, of, Subject, Observable, BehaviorSubject, ReplaySubject } from 'rxjs';
8
- import { take, catchError, map, takeUntil, startWith, switchMap, debounceTime, distinctUntilChanged } from 'rxjs/operators';
8
+ import { take, catchError, map, takeUntil, startWith, switchMap, debounceTime } from 'rxjs/operators';
9
9
  import * as i7$1 from '@angular/material/core';
10
10
  import { MAT_DATE_LOCALE, MAT_DATE_FORMATS, MatNativeDateModule, MatOption, ErrorStateMatcher } from '@angular/material/core';
11
11
  import * as i4 from '@angular/material/button';
@@ -2353,7 +2353,7 @@ class KlesFormSelectSearchComponent extends KlesFieldAbstract {
2353
2353
  this.selectAllControl = new UntypedFormControl(false);
2354
2354
  this.isLoading = false;
2355
2355
  this.optionsFiltered$ = new ReplaySubject(1);
2356
- this.openChange$ = new Subject();
2356
+ this.openChange$ = new BehaviorSubject(false);
2357
2357
  this.compareFn = (o1, o2) => {
2358
2358
  if (this.field.property && o1 && o2) {
2359
2359
  return o1[this.field.property] === o2[this.field.property];
@@ -2372,15 +2372,7 @@ class KlesFormSelectSearchComponent extends KlesFieldAbstract {
2372
2372
  else {
2373
2373
  this.options$ = new BehaviorSubject([]);
2374
2374
  }
2375
- this.openChange$
2376
- .pipe(takeUntil(this._onDestroy), switchMap((isOpen) => {
2377
- return this.onOpenChange(isOpen);
2378
- }))
2379
- .subscribe((options) => {
2380
- this.options$.next(options);
2381
- this.isLoading = false;
2382
- this.ref.markForCheck();
2383
- });
2375
+ this.openChangeEvent();
2384
2376
  }
2385
2377
  else {
2386
2378
  if (this.field.options instanceof Observable) {
@@ -2393,7 +2385,7 @@ class KlesFormSelectSearchComponent extends KlesFieldAbstract {
2393
2385
  this.options$ = of(this.field.options);
2394
2386
  }
2395
2387
  }
2396
- this.searchControl.valueChanges.pipe(takeUntil(this._onDestroy), debounceTime(200), startWith(this.searchControl.value), distinctUntilChanged(), switchMap(value => {
2388
+ this.searchControl.valueChanges.pipe(takeUntil(this._onDestroy), debounceTime(this.field.debounceTime || 0), startWith(this.searchControl.value), switchMap(value => {
2397
2389
  return concat(of({ loading: true, options: [] }), this.onSearchChange(value).pipe(map((options) => ({ loading: false, options }))));
2398
2390
  })).subscribe(({ loading, options }) => {
2399
2391
  this.isLoading = loading;
@@ -2435,6 +2427,17 @@ class KlesFormSelectSearchComponent extends KlesFieldAbstract {
2435
2427
  this.group.controls[this.field.name].patchValue([]);
2436
2428
  }
2437
2429
  }
2430
+ openChangeEvent() {
2431
+ this.openChange$
2432
+ .pipe(takeUntil(this._onDestroy), switchMap((isOpen) => {
2433
+ return this.onOpenChange(isOpen);
2434
+ }))
2435
+ .subscribe((options) => {
2436
+ this.options$.next(options);
2437
+ this.isLoading = false;
2438
+ this.ref.markForCheck();
2439
+ });
2440
+ }
2438
2441
  onOpenChange(isOpen) {
2439
2442
  if (isOpen) {
2440
2443
  if (this.field.options instanceof Observable) {
@@ -2443,7 +2446,7 @@ class KlesFormSelectSearchComponent extends KlesFieldAbstract {
2443
2446
  }
2444
2447
  else if (this.field.options instanceof Function) {
2445
2448
  this.isLoading = true;
2446
- return this.field.options();
2449
+ return this.field.options().pipe(take(1));
2447
2450
  }
2448
2451
  else {
2449
2452
  return of(this.field.options);
@@ -3117,33 +3120,39 @@ class KlesFormSelectLazySearchComponent extends KlesFormSelectSearchComponent {
3117
3120
  }
3118
3121
  ngOnInit() {
3119
3122
  this.field.lazy = true;
3123
+ this.field.debounceTime = this.field.debounceTime ? this.field.debounceTime : 500;
3120
3124
  super.ngOnInit();
3121
- this.openChange$.pipe(takeUntil(this._onDestroy))
3122
- .subscribe((open) => {
3123
- if (open) {
3124
- this.searchControl.reset(null);
3125
- }
3126
- else {
3127
- this.searchControl.reset(null, { emitEvent: false });
3128
- }
3129
- });
3130
3125
  }
3131
3126
  ngOnDestroy() {
3132
3127
  super.ngOnDestroy();
3133
3128
  }
3134
3129
  onSearchChange(value) {
3135
3130
  if (this.field.options instanceof Function) {
3136
- if (value) {
3137
- return this.field.options(value).pipe(take(1));
3138
- }
3139
- else {
3140
- return this.field.options().pipe(take(1));
3131
+ if (this.openChange$.getValue() && this.field.options instanceof Function) {
3132
+ if (value) {
3133
+ return this.field.options(value).pipe(take(1));
3134
+ }
3135
+ else {
3136
+ return this.field.options().pipe(take(1));
3137
+ }
3141
3138
  }
3139
+ return of(this.group.controls[this.field.name].value ? [this.group.controls[this.field.name].value] : []);
3142
3140
  }
3143
3141
  else {
3144
3142
  return super.onSearchChange(value);
3145
3143
  }
3146
3144
  }
3145
+ openChangeEvent() {
3146
+ this.openChange$
3147
+ .pipe(takeUntil(this._onDestroy), switchMap((isOpen) => {
3148
+ return this.onOpenChange(isOpen);
3149
+ }))
3150
+ .subscribe((options) => {
3151
+ this.optionsFiltered$.next(options);
3152
+ this.isLoading = false;
3153
+ this.ref.markForCheck();
3154
+ });
3155
+ }
3147
3156
  }
3148
3157
  KlesFormSelectLazySearchComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KlesFormSelectLazySearchComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
3149
3158
  KlesFormSelectLazySearchComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: KlesFormSelectLazySearchComponent, selector: "kles-form-select-lazy-search", usesInheritance: true, ngImport: i0, template: `