mis-crystal-design-system 18.1.2 → 18.1.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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, signal, computed, effect, Component, Inject, HostListener, input, output, Injector, Directive, Self, Optional, NgModule } from '@angular/core';
2
+ import { InjectionToken, signal, computed, Component, Inject, HostListener, input, output, Injector, Directive, Self, Optional, NgModule } from '@angular/core';
3
3
  import dayjs from 'dayjs';
4
4
  import timezone from 'dayjs/plugin/timezone';
5
5
  import utc from 'dayjs/plugin/utc';
@@ -407,31 +407,8 @@ class TzDrpContainerComponent {
407
407
  format: DATE_FORMAT
408
408
  };
409
409
  }
410
- // Effect to update calendar when dates change - AFTER setting initial data
411
- effect(() => {
412
- const localSelectedDates = this.localSelectedDatesSignal();
413
- let selectedStartDate;
414
- if (localSelectedDates?.startDate) {
415
- selectedStartDate = this.parseDateWithMultipleFormats(localSelectedDates.startDate);
416
- }
417
- else {
418
- selectedStartDate = dayjs('invalid');
419
- }
420
- if (selectedStartDate.isValid()) {
421
- this.currentYearNumberSignal.set(selectedStartDate.year());
422
- this.nextYearNumberSignal.set(selectedStartDate.add(1, "month").year());
423
- this.currentMonthNumberSignal.set(selectedStartDate.get("month"));
424
- this.nextMonthNumberSignal.set(selectedStartDate.add(1, "month").month());
425
- const selectedEndDate = localSelectedDates?.endDate ? this.parseDateWithMultipleFormats(localSelectedDates.endDate) : null;
426
- if (selectedEndDate && selectedEndDate.isValid() && selectedEndDate.isAfter(selectedStartDate, 'month')) {
427
- this.nextMonthNumberSignal.set(selectedEndDate.month());
428
- this.nextYearNumberSignal.set(selectedEndDate.year());
429
- }
430
- // Update calendar dates to reflect the selected dates
431
- this.currentMonthDatesSignal.set(this.generateDates(this.currentMonthNumberSignal(), this.currentYearNumberSignal()));
432
- this.nextMonthDatesSignal.set(this.generateDates(this.nextMonthNumberSignal(), this.nextYearNumberSignal()));
433
- }
434
- }, { allowSignalWrites: true });
410
+ // Update calendar from initial selected dates
411
+ this.updateCalendarFromSelectedDates();
435
412
  }
436
413
  ngOnInit() {
437
414
  this.calculateMinMaxDays();
@@ -467,8 +444,8 @@ class TzDrpContainerComponent {
467
444
  }
468
445
  this.currentMonthNumberSignal.set(thisMonth.month());
469
446
  this.nextMonthNumberSignal.set(thisMonth.clone().add(1, "month").month());
470
- this.currentMonthSignal.set(getMonth(this.currentMonthNumber()));
471
- this.nextMonthSignal.set(getMonth(this.nextMonthNumber()));
447
+ this.currentMonthSignal.set(getMonth(this.currentMonthNumberSignal()));
448
+ this.nextMonthSignal.set(getMonth(this.nextMonthNumberSignal()));
472
449
  if (this.nextMonthNumberSignal() === 0 && direction === "PREVIOUS") {
473
450
  this.currentYearNumberSignal.set(this.currentYearNumberSignal() - 1);
474
451
  }
@@ -488,6 +465,37 @@ class TzDrpContainerComponent {
488
465
  this.nextMonthDatesSignal.set(this.generateDates(this.nextMonthNumber(), this.nextYearNumber()));
489
466
  this.calculateMinMaxDays();
490
467
  }
468
+ /**
469
+ * Update calendar month/year based on selected dates
470
+ * This method is called whenever localSelectedDatesSignal changes to keep calendar in sync
471
+ */
472
+ updateCalendarFromSelectedDates() {
473
+ const localSelectedDates = this.localSelectedDatesSignal();
474
+ let selectedStartDate;
475
+ if (localSelectedDates?.startDate) {
476
+ selectedStartDate = this.parseDateWithMultipleFormats(localSelectedDates.startDate);
477
+ }
478
+ else {
479
+ selectedStartDate = dayjs('invalid');
480
+ }
481
+ if (selectedStartDate.isValid()) {
482
+ this.currentYearNumberSignal.set(selectedStartDate.year());
483
+ this.nextYearNumberSignal.set(selectedStartDate.add(1, "month").year());
484
+ this.currentMonthNumberSignal.set(selectedStartDate.get("month"));
485
+ this.nextMonthNumberSignal.set(selectedStartDate.add(1, "month").month());
486
+ const selectedEndDate = localSelectedDates?.endDate ? this.parseDateWithMultipleFormats(localSelectedDates.endDate) : null;
487
+ if (selectedEndDate && selectedEndDate.isValid() && selectedEndDate.isAfter(selectedStartDate, 'month')) {
488
+ this.nextMonthNumberSignal.set(selectedEndDate.month());
489
+ this.nextYearNumberSignal.set(selectedEndDate.year());
490
+ }
491
+ // Update month labels
492
+ this.currentMonthSignal.set(getMonth(this.currentMonthNumberSignal()));
493
+ this.nextMonthSignal.set(getMonth(this.nextMonthNumberSignal()));
494
+ // Update calendar dates to reflect the selected dates
495
+ this.currentMonthDatesSignal.set(this.generateDates(this.currentMonthNumberSignal(), this.currentYearNumberSignal()));
496
+ this.nextMonthDatesSignal.set(this.generateDates(this.nextMonthNumberSignal(), this.nextYearNumberSignal()));
497
+ }
498
+ }
491
499
  generateDates(month, currentYearNumber) {
492
500
  let dates = [];
493
501
  const daysInMonth = dayjs().year(currentYearNumber).month(month).daysInMonth();
@@ -660,8 +668,7 @@ class TzDrpContainerComponent {
660
668
  endDate: null,
661
669
  selectedRangeLabel: this.CUSTOM_RANGE_LABEL
662
670
  });
663
- this.currentMonthDatesSignal.set(this.generateDates(this.currentMonthNumberSignal(), this.currentYearNumberSignal()));
664
- this.nextMonthDatesSignal.set(this.generateDates(this.nextMonthNumberSignal(), this.nextYearNumberSignal()));
671
+ this.updateCalendarFromSelectedDates();
665
672
  return;
666
673
  }
667
674
  this.selectionStartedSignal.set(false);
@@ -690,6 +697,7 @@ class TzDrpContainerComponent {
690
697
  endDate: formattedEndDate,
691
698
  selectedRangeLabel: this.CUSTOM_RANGE_LABEL
692
699
  });
700
+ this.updateCalendarFromSelectedDates();
693
701
  }
694
702
  else {
695
703
  this.selectionStartedSignal.set(true);
@@ -730,9 +738,8 @@ class TzDrpContainerComponent {
730
738
  endDate: null,
731
739
  selectedRangeLabel: this.CUSTOM_RANGE_LABEL
732
740
  });
741
+ this.updateCalendarFromSelectedDates();
733
742
  }
734
- this.currentMonthDatesSignal.set(this.generateDates(this.currentMonthNumberSignal(), this.currentYearNumberSignal()));
735
- this.nextMonthDatesSignal.set(this.generateDates(this.nextMonthNumberSignal(), this.nextYearNumberSignal()));
736
743
  this.isDatesValidSignal.set(false);
737
744
  if (this.localSelectedDatesSignal().startDate && this.localSelectedDatesSignal().endDate) {
738
745
  this.isDatesValidSignal.set(true);