@spartan-ng/brain 1.10.1 → 1.11.0-beta.2

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.
@@ -582,6 +582,8 @@ class BrnCalendarMonthSelect {
582
582
  _dateAdapter = injectDateAdapter();
583
583
  /** Access the calendar i18n */
584
584
  _i18n = injectBrnCalendarI18n();
585
+ /** Whether the select value is being synced from the calendar rather than picked by the user */
586
+ _syncing = false;
585
587
  _selectedMonth = computed(() => {
586
588
  return this._i18n.config().months()[this._dateAdapter.getMonth(this._calendar.focusedDate())];
587
589
  }, ...(ngDevMode ? [{ debugName: "_selectedMonth" }] : /* istanbul ignore next */ []));
@@ -592,12 +594,13 @@ class BrnCalendarMonthSelect {
592
594
  outputToObservable(this._select.value)
593
595
  .pipe(takeUntilDestroyed())
594
596
  .subscribe((value) => {
595
- if (typeof value === 'string') {
597
+ // writeValue emits on the same output; only a real user selection should move focus.
598
+ if (!this._syncing && typeof value === 'string') {
596
599
  this.monthSelected(value);
597
600
  }
598
601
  });
599
602
  effect(() => {
600
- this._select.writeValue(this._selectedMonth());
603
+ this._syncSelect(this._selectedMonth());
601
604
  });
602
605
  }
603
606
  /** Focus selected month */
@@ -618,7 +621,17 @@ class BrnCalendarMonthSelect {
618
621
  this._calendar.setFocusedDate(target);
619
622
  // The select already shows the picked month. When the focused month did not change
620
623
  // (target rejected or constrained back into it), the effect does not run again.
621
- this._select.writeValue(this._selectedMonth());
624
+ this._syncSelect(this._selectedMonth());
625
+ }
626
+ /** Write the calendar's value into the select without treating it as a user selection */
627
+ _syncSelect(value) {
628
+ this._syncing = true;
629
+ try {
630
+ this._select.writeValue(value);
631
+ }
632
+ finally {
633
+ this._syncing = false;
634
+ }
622
635
  }
623
636
  /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarMonthSelect, deps: [], target: i0.ɵɵFactoryTarget.Directive });
624
637
  /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnCalendarMonthSelect, isStandalone: true, selector: "brnSelect[brnCalendarMonthSelect],hlm-select[brnCalendarMonthSelect]", exportAs: ["brnCalendarMonthSelect"], ngImport: i0 });
@@ -905,6 +918,8 @@ class BrnCalendarYearSelect {
905
918
  _dateAdapter = injectDateAdapter();
906
919
  /** Access the calendar i18n */
907
920
  _i18n = injectBrnCalendarI18n();
921
+ /** Whether the select value is being synced from the calendar rather than picked by the user */
922
+ _syncing = false;
908
923
  constructor() {
909
924
  // React to user selection through the injected select's typed `value` output rather than a
910
925
  // host-listener `$event` (which Angular types as `Event`). The year select's values are
@@ -912,12 +927,13 @@ class BrnCalendarYearSelect {
912
927
  outputToObservable(this._select.value)
913
928
  .pipe(takeUntilDestroyed())
914
929
  .subscribe((value) => {
915
- if (typeof value === 'number') {
930
+ // writeValue emits on the same output; only a real user selection should move focus.
931
+ if (!this._syncing && typeof value === 'number') {
916
932
  this.yearSelected(value);
917
933
  }
918
934
  });
919
935
  effect(() => {
920
- this._select.writeValue(this._dateAdapter.getYear(this._calendar.focusedDate()));
936
+ this._syncSelect(this._dateAdapter.getYear(this._calendar.focusedDate()));
921
937
  });
922
938
  }
923
939
  /** Focus selected year */
@@ -933,7 +949,17 @@ class BrnCalendarYearSelect {
933
949
  const target = this._calendar.constrainDate(this._dateAdapter.set(targetDate, { day }));
934
950
  this._calendar.setFocusedDate(target);
935
951
  // Keep the select on the year actually shown when the target was rejected.
936
- this._select.writeValue(this._dateAdapter.getYear(this._calendar.focusedDate()));
952
+ this._syncSelect(this._dateAdapter.getYear(this._calendar.focusedDate()));
953
+ }
954
+ /** Write the calendar's value into the select without treating it as a user selection */
955
+ _syncSelect(value) {
956
+ this._syncing = true;
957
+ try {
958
+ this._select.writeValue(value);
959
+ }
960
+ finally {
961
+ this._syncing = false;
962
+ }
937
963
  }
938
964
  /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarYearSelect, deps: [], target: i0.ɵɵFactoryTarget.Directive });
939
965
  /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnCalendarYearSelect, isStandalone: true, selector: "brnSelect[brnCalendarYearSelect],hlm-select[brnCalendarYearSelect]", exportAs: ["brnCalendarYearSelect"], ngImport: i0 });