@ethlete/cdk 5.0.0-next.43 → 5.0.0-next.44

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @ethlete/cdk
2
2
 
3
+ ## 5.0.0-next.44
4
+
5
+ ### Patch Changes
6
+
7
+ - `etInput` now follows a `[formControl]` that switches to a new FormControl, so errors and the invalid state reflect the current control.
8
+ - Fix `etSort` ignoring a replaced `sortControl`, `sortByControl` or `sortDirectionControl`: it now watches the new control instead of the old one.
9
+
3
10
  ## 5.0.0-next.43
4
11
 
5
12
  ### Patch Changes
@@ -4,7 +4,7 @@ import * as i1$5 from "@angular/cdk/portal";
4
4
  import { CdkPortal, CdkPortalOutlet, ComponentPortal, PortalModule, TemplatePortal } from "@angular/cdk/portal";
5
5
  import { DomSanitizer, Title } from "@angular/platform-browser";
6
6
  import { outputFromObservable, outputToObservable, takeUntilDestroyed, toObservable, toSignal } from "@angular/core/rxjs-interop";
7
- import { BehaviorSubject, EMPTY, Observable, Subject, Subscription, catchError, combineLatest, debounceTime, distinctUntilChanged, filter, finalize, from, fromEvent, map, merge, of, pairwise, shareReplay, skip, skipUntil, skipWhile, startWith, switchMap, take, takeUntil, takeWhile, tap, throwError, timer, withLatestFrom } from "rxjs";
7
+ import { BehaviorSubject, EMPTY, Observable, ReplaySubject, Subject, Subscription, catchError, combineLatest, debounceTime, distinctUntilChanged, filter, finalize, from, fromEvent, map, merge, of, pairwise, shareReplay, skip, skipUntil, skipWhile, startWith, switchMap, take, takeUntil, takeWhile, tap, throwError, timer, withLatestFrom } from "rxjs";
8
8
  import { __decorate, __metadata } from "tslib";
9
9
  import { AsyncPipe, DOCUMENT as DOCUMENT$1, Location, NgClass, NgComponentOutlet, NgStyle, NgTemplateOutlet } from "@angular/common";
10
10
  import * as i1$4 from "@ethlete/core";
@@ -5188,7 +5188,7 @@ var InputDirective = class InputDirective {
5188
5188
  return this._formFieldStateService.labelId();
5189
5189
  }
5190
5190
  get invalid$() {
5191
- return this.control.statusChanges.pipe(startWith(this.control.status), map((s) => s === "INVALID"));
5191
+ return this._control$.pipe(switchMap((control) => control.statusChanges.pipe(startWith(control.status))), map((s) => s === "INVALID"));
5192
5192
  }
5193
5193
  get invalid() {
5194
5194
  return this.control.invalid;
@@ -5265,6 +5265,7 @@ var InputDirective = class InputDirective {
5265
5265
  "time",
5266
5266
  "week"
5267
5267
  ];
5268
+ this._control$ = new ReplaySubject(1);
5268
5269
  this._id = `et-input-${++nextUniqueId$5}`;
5269
5270
  this.autocomplete = input(null, ...ngDevMode ? [{ debugName: "autocomplete" }] : /* istanbul ignore next */ []);
5270
5271
  this.placeholder = input(null, ...ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []);
@@ -5279,14 +5280,25 @@ var InputDirective = class InputDirective {
5279
5280
  if (exposeInputVarsDirective) exposeInputVarsDirective._monitorInput(this);
5280
5281
  });
5281
5282
  }
5283
+ ngDoCheck() {
5284
+ this._syncControl();
5285
+ }
5286
+ _syncControl() {
5287
+ const control = this.control;
5288
+ if (control !== this._watchedControl) {
5289
+ this._watchedControl = control;
5290
+ this._control$.next(control);
5291
+ }
5292
+ }
5282
5293
  ngOnInit() {
5283
- const controlStateChanges$ = combineLatest([this.control.statusChanges.pipe(startWith(this.control.status)), this.control.valueChanges.pipe(startWith(this.control.value))]).pipe(debounceTime(0), map(([status, value]) => ({
5294
+ this._syncControl();
5295
+ const controlStateChanges$ = this._control$.pipe(switchMap((control) => combineLatest([control.statusChanges.pipe(startWith(control.status)), control.valueChanges.pipe(startWith(control.value))])), debounceTime(0), map(([status, value]) => ({
5284
5296
  status,
5285
5297
  value
5286
5298
  })));
5287
5299
  controlStateChanges$.pipe(map(() => this.control.errors), filter((errors) => !equal(errors, this.errors)), tap((errors) => this._inputStateService.errors$.next(errors)), takeUntil(this._destroy$)).subscribe();
5288
5300
  controlStateChanges$.pipe(tap(() => this._detectControlRequiredValidationChanges()), tap(() => this._detectControlDisabledChanges()), takeUntil(this._destroy$)).subscribe();
5289
- this.control.valueChanges?.pipe(takeUntil(this._destroy$), tap((value) => {
5301
+ this._control$.pipe(switchMap((control) => control.valueChanges), takeUntil(this._destroy$), tap((value) => {
5290
5302
  if (this._inputStateService.lastUpdateType() === "internal") {
5291
5303
  this._inputStateService.lastUpdateType$.next(null);
5292
5304
  return;
@@ -26415,6 +26427,7 @@ var SortDirective = class SortDirective {
26415
26427
  this._defaultOptions = inject(SORT_DEFAULT_OPTIONS, { optional: true });
26416
26428
  this.sortables = /* @__PURE__ */ new Map();
26417
26429
  this._stateChanges = new Subject();
26430
+ this._controlSubscription = new Subscription();
26418
26431
  this._isInitialized = false;
26419
26432
  this._pendingSubscribers = [];
26420
26433
  this.initialized = new Observable((subscriber) => {
@@ -26469,7 +26482,12 @@ var SortDirective = class SortDirective {
26469
26482
  this.active = this.sortByControl.value;
26470
26483
  this.direction = this.sortDirectionControl.value;
26471
26484
  }
26472
- if (this.sortControl) this.sortControl.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((value) => {
26485
+ this._watchControls();
26486
+ }
26487
+ _watchControls() {
26488
+ this._controlSubscription.unsubscribe();
26489
+ this._controlSubscription = new Subscription();
26490
+ if (this.sortControl) this._controlSubscription.add(this.sortControl.valueChanges.subscribe((value) => {
26473
26491
  if (value) {
26474
26492
  if (this.active !== value.active) this.active = value.active;
26475
26493
  if (this.direction !== value.direction) this.direction = value.direction;
@@ -26478,24 +26496,30 @@ var SortDirective = class SortDirective {
26478
26496
  this.direction = "";
26479
26497
  }
26480
26498
  this._stateChanges.next();
26481
- });
26482
- if (this.sortByControl) this.sortByControl.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((value) => {
26499
+ }));
26500
+ if (this.sortByControl) this._controlSubscription.add(this.sortByControl.valueChanges.subscribe((value) => {
26483
26501
  if (value) {
26484
26502
  if (this.active !== value) this.active = value;
26485
26503
  } else this.active = void 0;
26486
26504
  this._stateChanges.next();
26487
- });
26488
- if (this.sortDirectionControl) this.sortDirectionControl.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((value) => {
26505
+ }));
26506
+ if (this.sortDirectionControl) this._controlSubscription.add(this.sortDirectionControl.valueChanges.subscribe((value) => {
26489
26507
  if (value) {
26490
26508
  if (this.direction !== value) this.direction = value;
26491
26509
  } else this.direction = "";
26492
26510
  this._stateChanges.next();
26493
- });
26511
+ }));
26494
26512
  }
26495
- ngOnChanges() {
26513
+ ngOnChanges(changes) {
26514
+ if ([
26515
+ "sortControl",
26516
+ "sortByControl",
26517
+ "sortDirectionControl"
26518
+ ].some((key) => changes[key] && !changes[key].firstChange)) this._watchControls();
26496
26519
  this._stateChanges.next();
26497
26520
  }
26498
26521
  ngOnDestroy() {
26522
+ this._controlSubscription.unsubscribe();
26499
26523
  this._stateChanges.complete();
26500
26524
  }
26501
26525
  _markInitialized() {