@spartan-ng/brain 1.11.0-beta.1 → 1.11.0-beta.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.
|
@@ -373,12 +373,54 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImpo
|
|
|
373
373
|
}]
|
|
374
374
|
}] });
|
|
375
375
|
|
|
376
|
+
const BrnCalendarMonthToken = new InjectionToken('BrnCalendarMonthToken');
|
|
377
|
+
/**
|
|
378
|
+
* Inject the month context, if the element is rendered within a `brnCalendarMonth`.
|
|
379
|
+
*/
|
|
380
|
+
function injectBrnCalendarMonth() {
|
|
381
|
+
return inject(BrnCalendarMonthToken, { optional: true });
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Scopes the grid, weeks, weekdays, cells, header and selects within it to a single displayed month.
|
|
385
|
+
* Use it to render multiple months, e.g. with `numberOfMonths` on `brnCalendarRange`.
|
|
386
|
+
*/
|
|
387
|
+
class BrnCalendarMonth {
|
|
388
|
+
/** Access the calendar */
|
|
389
|
+
_calendar = injectBrnCalendar();
|
|
390
|
+
/** Access the date adapter */
|
|
391
|
+
_dateAdapter = injectDateAdapter();
|
|
392
|
+
/** The offset of this month relative to the first displayed month. */
|
|
393
|
+
offset = input(0, { ...(ngDevMode ? { debugName: "offset" } : /* istanbul ignore next */ {}), transform: (value) => numberAttribute(value, 0) });
|
|
394
|
+
/** @internal The header of this month. */
|
|
395
|
+
header = contentChild(BrnCalendarHeader, ...(ngDevMode ? [{ debugName: "header" }] : /* istanbul ignore next */ []));
|
|
396
|
+
_data = computed(() => this._calendar.months?.()[this.offset()], ...(ngDevMode ? [{ debugName: "_data" }] : /* istanbul ignore next */ []));
|
|
397
|
+
/** The first day of the displayed month. */
|
|
398
|
+
month = computed(() => this._data()?.month ?? this._dateAdapter.startOfMonth(this._calendar.focusedDate()), { ...(ngDevMode ? { debugName: "month" } : /* istanbul ignore next */ {}), equal: (a, b) => this._dateAdapter.isSameMonth(a, b) });
|
|
399
|
+
/** The days to render for this month. */
|
|
400
|
+
days = computed(() => this._data()?.days ?? this._calendar.days(), { ...(ngDevMode ? { debugName: "days" } : /* istanbul ignore next */ {}), equal: (a, b) => compareDays(a, b, this._dateAdapter) });
|
|
401
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarMonth, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
402
|
+
/** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.16", type: BrnCalendarMonth, isStandalone: true, selector: "[brnCalendarMonth]", inputs: { offset: { classPropertyName: "offset", publicName: "offset", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "data-slot": "calendar-month" } }, providers: [{ provide: BrnCalendarMonthToken, useExisting: BrnCalendarMonth }], queries: [{ propertyName: "header", first: true, predicate: BrnCalendarHeader, descendants: true, isSignal: true }], exportAs: ["brnCalendarMonth"], ngImport: i0 });
|
|
403
|
+
}
|
|
404
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarMonth, decorators: [{
|
|
405
|
+
type: Directive,
|
|
406
|
+
args: [{
|
|
407
|
+
selector: '[brnCalendarMonth]',
|
|
408
|
+
exportAs: 'brnCalendarMonth',
|
|
409
|
+
providers: [{ provide: BrnCalendarMonthToken, useExisting: BrnCalendarMonth }],
|
|
410
|
+
host: {
|
|
411
|
+
'data-slot': 'calendar-month',
|
|
412
|
+
},
|
|
413
|
+
}]
|
|
414
|
+
}], propDecorators: { offset: [{ type: i0.Input, args: [{ isSignal: true, alias: "offset", required: false }] }], header: [{ type: i0.ContentChild, args: [i0.forwardRef(() => BrnCalendarHeader), { isSignal: true }] }] } });
|
|
415
|
+
|
|
376
416
|
class BrnCalendarCellButton {
|
|
377
417
|
/** Access the date adapter */
|
|
378
418
|
_dateAdapter = injectDateAdapter();
|
|
379
419
|
_destroyRef = inject(DestroyRef);
|
|
380
420
|
/** Access the calendar component */
|
|
381
421
|
_calendar = injectBrnCalendar();
|
|
422
|
+
/** Access the month this cell belongs to, if rendering multiple months */
|
|
423
|
+
_month = injectBrnCalendarMonth();
|
|
382
424
|
/** Access the element ref */
|
|
383
425
|
_elementRef = inject(ElementRef);
|
|
384
426
|
/** The date this cell represents */
|
|
@@ -393,11 +435,15 @@ class BrnCalendarCellButton {
|
|
|
393
435
|
this._calendar.registerCalendarCell(this);
|
|
394
436
|
this._destroyRef.onDestroy(() => this._calendar.unregisterCalendarCell(this));
|
|
395
437
|
}
|
|
396
|
-
/**
|
|
397
|
-
|
|
438
|
+
/**
|
|
439
|
+
* Whether this date is focusable.
|
|
440
|
+
* Days outside of their month are never focusable, as the same date is also rendered within its own month.
|
|
441
|
+
*/
|
|
442
|
+
focusable = computed(() => !this.disabled() && !this.outside() && this._dateAdapter.isSameDay(this._calendar.focusedDate(), this.date()), ...(ngDevMode ? [{ debugName: "focusable" }] : /* istanbul ignore next */ []));
|
|
443
|
+
/** Whether this date is outside of the month it is rendered in */
|
|
398
444
|
outside = computed(() => {
|
|
399
|
-
const
|
|
400
|
-
return !this._dateAdapter.isSameMonth(this.date(),
|
|
445
|
+
const month = this._month?.month() ?? this._calendar.focusedDate();
|
|
446
|
+
return !this._dateAdapter.isSameMonth(this.date(), month);
|
|
401
447
|
}, ...(ngDevMode ? [{ debugName: "outside" }] : /* istanbul ignore next */ []));
|
|
402
448
|
/** Whether this date is today */
|
|
403
449
|
today = computed(() => this._dateAdapter.isSameDay(this.date(), this._dateAdapter.now()), ...(ngDevMode ? [{ debugName: "today" }] : /* istanbul ignore next */ []));
|
|
@@ -558,8 +604,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImpo
|
|
|
558
604
|
class BrnCalendarGrid {
|
|
559
605
|
/** Access the calendar component */
|
|
560
606
|
_calendar = injectBrnCalendar();
|
|
607
|
+
/** Access the month this grid belongs to, if rendering multiple months */
|
|
608
|
+
_month = injectBrnCalendarMonth();
|
|
561
609
|
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarGrid, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
562
|
-
/** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnCalendarGrid, isStandalone: true, selector: "[brnCalendarGrid]", host: { attributes: { "role": "grid" }, properties: { "attr.aria-labelledby": "_calendar.header()?.id()" } }, exportAs: ["brnCalendarGrid"], ngImport: i0 });
|
|
610
|
+
/** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnCalendarGrid, isStandalone: true, selector: "[brnCalendarGrid]", host: { attributes: { "role": "grid" }, properties: { "attr.aria-labelledby": "(_month?.header() ?? _calendar.header())?.id()" } }, exportAs: ["brnCalendarGrid"], ngImport: i0 });
|
|
563
611
|
}
|
|
564
612
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarGrid, decorators: [{
|
|
565
613
|
type: Directive,
|
|
@@ -568,7 +616,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImpo
|
|
|
568
616
|
exportAs: 'brnCalendarGrid',
|
|
569
617
|
host: {
|
|
570
618
|
role: 'grid',
|
|
571
|
-
'[attr.aria-labelledby]': '_calendar.header()?.id()',
|
|
619
|
+
'[attr.aria-labelledby]': '(_month?.header() ?? _calendar.header())?.id()',
|
|
572
620
|
},
|
|
573
621
|
}]
|
|
574
622
|
}] });
|
|
@@ -578,12 +626,18 @@ class BrnCalendarMonthSelect {
|
|
|
578
626
|
_select = inject(BrnSelect);
|
|
579
627
|
/** Access the calendar */
|
|
580
628
|
_calendar = injectBrnCalendar();
|
|
629
|
+
/** Access the month this select belongs to, if rendering multiple months */
|
|
630
|
+
_month = injectBrnCalendarMonth();
|
|
581
631
|
/** Access the date adapter */
|
|
582
632
|
_dateAdapter = injectDateAdapter();
|
|
583
633
|
/** Access the calendar i18n */
|
|
584
634
|
_i18n = injectBrnCalendarI18n();
|
|
635
|
+
/** The month displayed by this select */
|
|
636
|
+
_displayedMonth = computed(() => this._month?.month() ?? this._calendar.focusedDate(), ...(ngDevMode ? [{ debugName: "_displayedMonth" }] : /* istanbul ignore next */ []));
|
|
637
|
+
/** Whether the select value is being synced from the calendar rather than picked by the user */
|
|
638
|
+
_syncing = false;
|
|
585
639
|
_selectedMonth = computed(() => {
|
|
586
|
-
return this._i18n.config().months()[this._dateAdapter.getMonth(this.
|
|
640
|
+
return this._i18n.config().months()[this._dateAdapter.getMonth(this._displayedMonth())];
|
|
587
641
|
}, ...(ngDevMode ? [{ debugName: "_selectedMonth" }] : /* istanbul ignore next */ []));
|
|
588
642
|
constructor() {
|
|
589
643
|
// React to user selection through the injected select's typed `value` output rather than a
|
|
@@ -592,12 +646,13 @@ class BrnCalendarMonthSelect {
|
|
|
592
646
|
outputToObservable(this._select.value)
|
|
593
647
|
.pipe(takeUntilDestroyed())
|
|
594
648
|
.subscribe((value) => {
|
|
595
|
-
|
|
649
|
+
// writeValue emits on the same output; only a real user selection should move focus.
|
|
650
|
+
if (!this._syncing && typeof value === 'string') {
|
|
596
651
|
this.monthSelected(value);
|
|
597
652
|
}
|
|
598
653
|
});
|
|
599
654
|
effect(() => {
|
|
600
|
-
this.
|
|
655
|
+
this._syncSelect(this._selectedMonth());
|
|
601
656
|
});
|
|
602
657
|
}
|
|
603
658
|
/** Focus selected month */
|
|
@@ -609,16 +664,31 @@ class BrnCalendarMonthSelect {
|
|
|
609
664
|
const focusedDate = this._calendar.focusedDate();
|
|
610
665
|
// Start from the first of the month so a day that does not exist in the target month
|
|
611
666
|
// (e.g. the 31st) cannot roll over into the following month - clamp it instead.
|
|
612
|
-
const targetDate = this._dateAdapter.set(this._dateAdapter.startOfMonth(
|
|
667
|
+
const targetDate = this._dateAdapter.set(this._dateAdapter.startOfMonth(this._displayedMonth()), { month });
|
|
613
668
|
const lastDay = this._dateAdapter.getDate(this._dateAdapter.endOfMonth(targetDate));
|
|
614
669
|
const day = Math.min(this._dateAdapter.getDate(focusedDate), lastDay);
|
|
615
670
|
// Like the previous/next buttons, constrain the target to min/max instead of letting
|
|
616
671
|
// setFocusedDate reject it: otherwise the grid stays on the old month.
|
|
617
672
|
const target = this._calendar.constrainDate(this._dateAdapter.set(targetDate, { day }));
|
|
618
673
|
this._calendar.setFocusedDate(target);
|
|
674
|
+
// Keep the selected month at the position of this select when rendering multiple months.
|
|
675
|
+
// A rejected target leaves the focused date unchanged, so the displayed months must not move.
|
|
676
|
+
if (this._dateAdapter.isSameDay(this._calendar.focusedDate(), target)) {
|
|
677
|
+
this._calendar.showMonth?.(target, this._month?.offset() ?? 0);
|
|
678
|
+
}
|
|
619
679
|
// The select already shows the picked month. When the focused month did not change
|
|
620
680
|
// (target rejected or constrained back into it), the effect does not run again.
|
|
621
|
-
this.
|
|
681
|
+
this._syncSelect(this._selectedMonth());
|
|
682
|
+
}
|
|
683
|
+
/** Write the calendar's value into the select without treating it as a user selection */
|
|
684
|
+
_syncSelect(value) {
|
|
685
|
+
this._syncing = true;
|
|
686
|
+
try {
|
|
687
|
+
this._select.writeValue(value);
|
|
688
|
+
}
|
|
689
|
+
finally {
|
|
690
|
+
this._syncing = false;
|
|
691
|
+
}
|
|
622
692
|
}
|
|
623
693
|
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarMonthSelect, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
624
694
|
/** @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 });
|
|
@@ -685,7 +755,9 @@ class BrnCalendarNextButton {
|
|
|
685
755
|
const focusedDate = this._calendar.focusedDate();
|
|
686
756
|
const date = this._dateAdapter.getDate(focusedDate);
|
|
687
757
|
// go to start of month first, then add 1 month to avoid day overflow
|
|
688
|
-
|
|
758
|
+
// when rendering multiple months, navigate relative to the last displayed month
|
|
759
|
+
const displayedMonth = this._calendar.months?.().at(-1)?.month ?? focusedDate;
|
|
760
|
+
let nextMonthTarget = this._dateAdapter.startOfMonth(displayedMonth);
|
|
689
761
|
nextMonthTarget = this._dateAdapter.add(nextMonthTarget, { months: 1 });
|
|
690
762
|
const lastDay = this._dateAdapter.endOfMonth(nextMonthTarget);
|
|
691
763
|
// if we are on a date that does not exist in the next month, clamp to the last day of the month.
|
|
@@ -743,7 +815,9 @@ class BrnCalendarPreviousButton {
|
|
|
743
815
|
const focusedDate = this._calendar.focusedDate();
|
|
744
816
|
const date = this._dateAdapter.getDate(focusedDate);
|
|
745
817
|
// go to start of month first, then subtract 1 month to avoid day overflow
|
|
746
|
-
|
|
818
|
+
// when rendering multiple months, navigate relative to the first displayed month
|
|
819
|
+
const displayedMonth = this._calendar.months?.()[0]?.month ?? focusedDate;
|
|
820
|
+
let previousMonthTarget = this._dateAdapter.startOfMonth(displayedMonth);
|
|
747
821
|
previousMonthTarget = this._dateAdapter.subtract(previousMonthTarget, { months: 1 });
|
|
748
822
|
const lastDay = this._dateAdapter.endOfMonth(previousMonthTarget);
|
|
749
823
|
// if we are on a date that does not exist in the previous month, clamp to the last day of the month.
|
|
@@ -774,6 +848,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImpo
|
|
|
774
848
|
class BrnCalendarWeek {
|
|
775
849
|
/** Access the calendar */
|
|
776
850
|
_calendar = injectBrnCalendar();
|
|
851
|
+
/** Access the month this week belongs to, if rendering multiple months */
|
|
852
|
+
_month = injectBrnCalendarMonth();
|
|
777
853
|
/** Access the view container ref */
|
|
778
854
|
_viewContainerRef = inject(ViewContainerRef);
|
|
779
855
|
/** Access the change detector */
|
|
@@ -782,7 +858,7 @@ class BrnCalendarWeek {
|
|
|
782
858
|
_templateRef = inject(TemplateRef);
|
|
783
859
|
// get the weeks to display.
|
|
784
860
|
_weeks = computed(() => {
|
|
785
|
-
const days = this._calendar.days();
|
|
861
|
+
const days = this._month?.days() ?? this._calendar.days();
|
|
786
862
|
const weeks = [];
|
|
787
863
|
for (let i = 0; i < days.length; i += 7) {
|
|
788
864
|
weeks.push(days.slice(i, i + 7));
|
|
@@ -838,6 +914,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImpo
|
|
|
838
914
|
class BrnCalendarWeekday {
|
|
839
915
|
/** Access the calendar */
|
|
840
916
|
_calendar = injectBrnCalendar();
|
|
917
|
+
/** Access the month these weekdays belong to, if rendering multiple months */
|
|
918
|
+
_month = injectBrnCalendarMonth();
|
|
841
919
|
/** Access the date time adapter */
|
|
842
920
|
_dateAdapter = injectDateAdapter();
|
|
843
921
|
/** Access the view container ref */
|
|
@@ -847,7 +925,7 @@ class BrnCalendarWeekday {
|
|
|
847
925
|
/** Access the template ref */
|
|
848
926
|
_templateRef = inject(TemplateRef);
|
|
849
927
|
/** Get the days of the week to display in the header. */
|
|
850
|
-
_weekdays = computed(() => this._calendar.days().slice(0, 7), ...(ngDevMode ? [{ debugName: "_weekdays" }] : /* istanbul ignore next */ []));
|
|
928
|
+
_weekdays = computed(() => (this._month?.days() ?? this._calendar.days()).slice(0, 7), ...(ngDevMode ? [{ debugName: "_weekdays" }] : /* istanbul ignore next */ []));
|
|
851
929
|
/** Store the view refs */
|
|
852
930
|
_viewRefs = [];
|
|
853
931
|
// Make sure the template checker knows the type of the context with which the
|
|
@@ -901,10 +979,16 @@ class BrnCalendarYearSelect {
|
|
|
901
979
|
_select = inject(BrnSelect);
|
|
902
980
|
/** Access the calendar */
|
|
903
981
|
_calendar = injectBrnCalendar();
|
|
982
|
+
/** Access the month this select belongs to, if rendering multiple months */
|
|
983
|
+
_month = injectBrnCalendarMonth();
|
|
984
|
+
/** The month displayed by this select */
|
|
985
|
+
_displayedMonth = computed(() => this._month?.month() ?? this._calendar.focusedDate(), ...(ngDevMode ? [{ debugName: "_displayedMonth" }] : /* istanbul ignore next */ []));
|
|
904
986
|
/** Access the date adapter */
|
|
905
987
|
_dateAdapter = injectDateAdapter();
|
|
906
988
|
/** Access the calendar i18n */
|
|
907
989
|
_i18n = injectBrnCalendarI18n();
|
|
990
|
+
/** Whether the select value is being synced from the calendar rather than picked by the user */
|
|
991
|
+
_syncing = false;
|
|
908
992
|
constructor() {
|
|
909
993
|
// React to user selection through the injected select's typed `value` output rather than a
|
|
910
994
|
// host-listener `$event` (which Angular types as `Event`). The year select's values are
|
|
@@ -912,12 +996,13 @@ class BrnCalendarYearSelect {
|
|
|
912
996
|
outputToObservable(this._select.value)
|
|
913
997
|
.pipe(takeUntilDestroyed())
|
|
914
998
|
.subscribe((value) => {
|
|
915
|
-
|
|
999
|
+
// writeValue emits on the same output; only a real user selection should move focus.
|
|
1000
|
+
if (!this._syncing && typeof value === 'number') {
|
|
916
1001
|
this.yearSelected(value);
|
|
917
1002
|
}
|
|
918
1003
|
});
|
|
919
1004
|
effect(() => {
|
|
920
|
-
this.
|
|
1005
|
+
this._syncSelect(this._dateAdapter.getYear(this._displayedMonth()));
|
|
921
1006
|
});
|
|
922
1007
|
}
|
|
923
1008
|
/** Focus selected year */
|
|
@@ -925,15 +1010,30 @@ class BrnCalendarYearSelect {
|
|
|
925
1010
|
const focusedDate = this._calendar.focusedDate();
|
|
926
1011
|
// Start from the first of the month so a day that does not exist in the target year
|
|
927
1012
|
// (e.g. the 29th of February in a non-leap year) is clamped instead of rolling over.
|
|
928
|
-
const targetDate = this._dateAdapter.set(this._dateAdapter.startOfMonth(
|
|
1013
|
+
const targetDate = this._dateAdapter.set(this._dateAdapter.startOfMonth(this._displayedMonth()), { year });
|
|
929
1014
|
const lastDay = this._dateAdapter.getDate(this._dateAdapter.endOfMonth(targetDate));
|
|
930
1015
|
const day = Math.min(this._dateAdapter.getDate(focusedDate), lastDay);
|
|
931
1016
|
// Like the previous/next buttons, constrain the target to min/max instead of letting
|
|
932
1017
|
// setFocusedDate reject it: otherwise the grid stays on the old year.
|
|
933
1018
|
const target = this._calendar.constrainDate(this._dateAdapter.set(targetDate, { day }));
|
|
934
1019
|
this._calendar.setFocusedDate(target);
|
|
1020
|
+
// Keep the selected year at the position of this select when rendering multiple months.
|
|
1021
|
+
// A rejected target leaves the focused date unchanged, so the displayed months must not move.
|
|
1022
|
+
if (this._dateAdapter.isSameDay(this._calendar.focusedDate(), target)) {
|
|
1023
|
+
this._calendar.showMonth?.(target, this._month?.offset() ?? 0);
|
|
1024
|
+
}
|
|
935
1025
|
// Keep the select on the year actually shown when the target was rejected.
|
|
936
|
-
this.
|
|
1026
|
+
this._syncSelect(this._dateAdapter.getYear(this._displayedMonth()));
|
|
1027
|
+
}
|
|
1028
|
+
/** Write the calendar's value into the select without treating it as a user selection */
|
|
1029
|
+
_syncSelect(value) {
|
|
1030
|
+
this._syncing = true;
|
|
1031
|
+
try {
|
|
1032
|
+
this._select.writeValue(value);
|
|
1033
|
+
}
|
|
1034
|
+
finally {
|
|
1035
|
+
this._syncing = false;
|
|
1036
|
+
}
|
|
937
1037
|
}
|
|
938
1038
|
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarYearSelect, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
939
1039
|
/** @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 });
|
|
@@ -1200,6 +1300,8 @@ class BrnCalendarRange {
|
|
|
1200
1300
|
_weekStartsOn = computed(() => this.weekStartsOn() ?? this._i18n.config().firstDayOfWeek(), ...(ngDevMode ? [{ debugName: "_weekStartsOn" }] : /* istanbul ignore next */ []));
|
|
1201
1301
|
/** The default focused date. */
|
|
1202
1302
|
defaultFocusedDate = input(...(ngDevMode ? [undefined, { debugName: "defaultFocusedDate" }] : /* istanbul ignore next */ []));
|
|
1303
|
+
/** The number of months to display. */
|
|
1304
|
+
numberOfMonths = input(1, { ...(ngDevMode ? { debugName: "numberOfMonths" } : /* istanbul ignore next */ {}), transform: (value) => Math.max(1, Math.floor(numberAttribute(value, 1))) });
|
|
1203
1305
|
/** @internal Access the header */
|
|
1204
1306
|
header = contentChild(BrnCalendarHeader, ...(ngDevMode ? [{ debugName: "header" }] : /* istanbul ignore next */ []));
|
|
1205
1307
|
/**
|
|
@@ -1245,13 +1347,52 @@ class BrnCalendarRange {
|
|
|
1245
1347
|
* The selected end date
|
|
1246
1348
|
*/
|
|
1247
1349
|
endDate = model(...(ngDevMode ? [undefined, { debugName: "endDate" }] : /* istanbul ignore next */ []));
|
|
1350
|
+
/**
|
|
1351
|
+
* The first displayed month. It only moves when the focused date leaves the displayed months,
|
|
1352
|
+
* so navigating within the displayed months does not shift them.
|
|
1353
|
+
*/
|
|
1354
|
+
_firstMonth = linkedSignal({ ...(ngDevMode ? { debugName: "_firstMonth" } : /* istanbul ignore next */ {}), source: () => ({ focusedDate: this.focusedDate(), numberOfMonths: this.numberOfMonths() }),
|
|
1355
|
+
computation: ({ focusedDate, numberOfMonths }, previous) => {
|
|
1356
|
+
const focusedMonth = this._dateAdapter.startOfMonth(focusedDate);
|
|
1357
|
+
if (!previous) {
|
|
1358
|
+
return focusedMonth;
|
|
1359
|
+
}
|
|
1360
|
+
const offset = this._monthDifference(previous.value, focusedMonth);
|
|
1361
|
+
if (offset < 0) {
|
|
1362
|
+
return focusedMonth;
|
|
1363
|
+
}
|
|
1364
|
+
if (offset >= numberOfMonths) {
|
|
1365
|
+
return this._dateAdapter.subtract(focusedMonth, { months: numberOfMonths - 1 });
|
|
1366
|
+
}
|
|
1367
|
+
return previous.value;
|
|
1368
|
+
},
|
|
1369
|
+
equal: (a, b) => this._dateAdapter.isSameMonth(a, b) });
|
|
1370
|
+
/** The months to display, starting with the first displayed month. */
|
|
1371
|
+
months = computed(() => {
|
|
1372
|
+
const firstMonth = this._firstMonth();
|
|
1373
|
+
return Array.from({ length: this.numberOfMonths() }, (_, offset) => {
|
|
1374
|
+
const month = this._dateAdapter.add(firstMonth, { months: offset });
|
|
1375
|
+
return { month, days: this._getDays(month) };
|
|
1376
|
+
});
|
|
1377
|
+
}, ...(ngDevMode ? [{ debugName: "months" }] : /* istanbul ignore next */ []));
|
|
1248
1378
|
/**
|
|
1249
1379
|
* Get all the days to display, this is the days of the current month
|
|
1250
1380
|
* and the days of the previous and next month to fill the grid.
|
|
1251
1381
|
*/
|
|
1252
|
-
days = computed(() => {
|
|
1382
|
+
days = computed(() => this._getDays(this.focusedDate()), { ...(ngDevMode ? { debugName: "days" } : /* istanbul ignore next */ {}), equal: (a, b) => compareDays(a, b, this._dateAdapter) });
|
|
1383
|
+
/** Show the month of the given date at the given offset of the displayed months. */
|
|
1384
|
+
showMonth(date, offset) {
|
|
1385
|
+
const month = this._dateAdapter.startOfMonth(date);
|
|
1386
|
+
this._firstMonth.set(this._dateAdapter.subtract(month, { months: offset }));
|
|
1387
|
+
}
|
|
1388
|
+
_monthDifference(from, to) {
|
|
1389
|
+
return ((this._dateAdapter.getYear(to) - this._dateAdapter.getYear(from)) * 12 +
|
|
1390
|
+
this._dateAdapter.getMonth(to) -
|
|
1391
|
+
this._dateAdapter.getMonth(from));
|
|
1392
|
+
}
|
|
1393
|
+
/** Get the days of the month of the given date, padded to full weeks. */
|
|
1394
|
+
_getDays(month) {
|
|
1253
1395
|
const weekStartsOn = this._weekStartsOn();
|
|
1254
|
-
const month = this.focusedDate();
|
|
1255
1396
|
const days = [];
|
|
1256
1397
|
// Get the first and last day of the month.
|
|
1257
1398
|
let firstDay = this._dateAdapter.startOfMonth(month);
|
|
@@ -1271,7 +1412,7 @@ class BrnCalendarRange {
|
|
|
1271
1412
|
firstDay = this._dateAdapter.add(firstDay, { days: 1 });
|
|
1272
1413
|
}
|
|
1273
1414
|
return days;
|
|
1274
|
-
}
|
|
1415
|
+
}
|
|
1275
1416
|
isSelected(date) {
|
|
1276
1417
|
const start = this.startDate();
|
|
1277
1418
|
const end = this.endDate();
|
|
@@ -1358,7 +1499,7 @@ class BrnCalendarRange {
|
|
|
1358
1499
|
// wait until the cells have all updated
|
|
1359
1500
|
afterNextRender({
|
|
1360
1501
|
write: () => {
|
|
1361
|
-
const cell = this._cells.find((c) => this._dateAdapter.isSameDay(c.date(), date));
|
|
1502
|
+
const cell = this._cells.find((c) => !c.outside() && this._dateAdapter.isSameDay(c.date(), date));
|
|
1362
1503
|
if (cell) {
|
|
1363
1504
|
cell.focus();
|
|
1364
1505
|
}
|
|
@@ -1416,7 +1557,7 @@ class BrnCalendarRange {
|
|
|
1416
1557
|
this._cells.push(cell);
|
|
1417
1558
|
}
|
|
1418
1559
|
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarRange, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1419
|
-
/** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.16", type: BrnCalendarRange, isStandalone: true, selector: "[brnCalendarRange]", inputs: { highlightDays: { classPropertyName: "highlightDays", publicName: "highlightDays", isSignal: true, isRequired: false, transformFunction: null }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, dateDisabled: { classPropertyName: "dateDisabled", publicName: "dateDisabled", isSignal: true, isRequired: false, transformFunction: null }, weekStartsOn: { classPropertyName: "weekStartsOn", publicName: "weekStartsOn", isSignal: true, isRequired: false, transformFunction: null }, defaultFocusedDate: { classPropertyName: "defaultFocusedDate", publicName: "defaultFocusedDate", isSignal: true, isRequired: false, transformFunction: null }, startDate: { classPropertyName: "startDate", publicName: "startDate", isSignal: true, isRequired: false, transformFunction: null }, endDate: { classPropertyName: "endDate", publicName: "endDate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { focusedDateChange: "focusedDateChange", startDate: "startDateChange", endDate: "endDateChange" }, providers: [provideBrnCalendar(BrnCalendarRange)], queries: [{ propertyName: "header", first: true, predicate: BrnCalendarHeader, descendants: true, isSignal: true }], exportAs: ["brnCalendarRange"], ngImport: i0 });
|
|
1560
|
+
/** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.16", type: BrnCalendarRange, isStandalone: true, selector: "[brnCalendarRange]", inputs: { highlightDays: { classPropertyName: "highlightDays", publicName: "highlightDays", isSignal: true, isRequired: false, transformFunction: null }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, dateDisabled: { classPropertyName: "dateDisabled", publicName: "dateDisabled", isSignal: true, isRequired: false, transformFunction: null }, weekStartsOn: { classPropertyName: "weekStartsOn", publicName: "weekStartsOn", isSignal: true, isRequired: false, transformFunction: null }, defaultFocusedDate: { classPropertyName: "defaultFocusedDate", publicName: "defaultFocusedDate", isSignal: true, isRequired: false, transformFunction: null }, numberOfMonths: { classPropertyName: "numberOfMonths", publicName: "numberOfMonths", isSignal: true, isRequired: false, transformFunction: null }, startDate: { classPropertyName: "startDate", publicName: "startDate", isSignal: true, isRequired: false, transformFunction: null }, endDate: { classPropertyName: "endDate", publicName: "endDate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { focusedDateChange: "focusedDateChange", startDate: "startDateChange", endDate: "endDateChange" }, providers: [provideBrnCalendar(BrnCalendarRange)], queries: [{ propertyName: "header", first: true, predicate: BrnCalendarHeader, descendants: true, isSignal: true }], exportAs: ["brnCalendarRange"], ngImport: i0 });
|
|
1420
1561
|
}
|
|
1421
1562
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarRange, decorators: [{
|
|
1422
1563
|
type: Directive,
|
|
@@ -1425,7 +1566,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImpo
|
|
|
1425
1566
|
exportAs: 'brnCalendarRange',
|
|
1426
1567
|
providers: [provideBrnCalendar(BrnCalendarRange)],
|
|
1427
1568
|
}]
|
|
1428
|
-
}], propDecorators: { highlightDays: [{ type: i0.Input, args: [{ isSignal: true, alias: "highlightDays", required: false }] }], min: [{ type: i0.Input, args: [{ isSignal: true, alias: "min", required: false }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "max", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], dateDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "dateDisabled", required: false }] }], weekStartsOn: [{ type: i0.Input, args: [{ isSignal: true, alias: "weekStartsOn", required: false }] }], defaultFocusedDate: [{ type: i0.Input, args: [{ isSignal: true, alias: "defaultFocusedDate", required: false }] }], header: [{ type: i0.ContentChild, args: [i0.forwardRef(() => BrnCalendarHeader), { isSignal: true }] }], focusedDateChange: [{ type: i0.Output, args: ["focusedDateChange"] }], startDate: [{ type: i0.Input, args: [{ isSignal: true, alias: "startDate", required: false }] }, { type: i0.Output, args: ["startDateChange"] }], endDate: [{ type: i0.Input, args: [{ isSignal: true, alias: "endDate", required: false }] }, { type: i0.Output, args: ["endDateChange"] }] } });
|
|
1569
|
+
}], propDecorators: { highlightDays: [{ type: i0.Input, args: [{ isSignal: true, alias: "highlightDays", required: false }] }], min: [{ type: i0.Input, args: [{ isSignal: true, alias: "min", required: false }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "max", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], dateDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "dateDisabled", required: false }] }], weekStartsOn: [{ type: i0.Input, args: [{ isSignal: true, alias: "weekStartsOn", required: false }] }], defaultFocusedDate: [{ type: i0.Input, args: [{ isSignal: true, alias: "defaultFocusedDate", required: false }] }], numberOfMonths: [{ type: i0.Input, args: [{ isSignal: true, alias: "numberOfMonths", required: false }] }], header: [{ type: i0.ContentChild, args: [i0.forwardRef(() => BrnCalendarHeader), { isSignal: true }] }], focusedDateChange: [{ type: i0.Output, args: ["focusedDateChange"] }], startDate: [{ type: i0.Input, args: [{ isSignal: true, alias: "startDate", required: false }] }, { type: i0.Output, args: ["startDateChange"] }], endDate: [{ type: i0.Input, args: [{ isSignal: true, alias: "endDate", required: false }] }, { type: i0.Output, args: ["endDateChange"] }] } });
|
|
1429
1570
|
|
|
1430
1571
|
const BrnMonthYearCalendarToken = new InjectionToken('BrnMonthYearCalendarToken');
|
|
1431
1572
|
function provideBrnMonthYearCalendar(instance) {
|
|
@@ -1919,6 +2060,7 @@ const BrnCalendarImports = [
|
|
|
1919
2060
|
BrnCalendarWeekday,
|
|
1920
2061
|
BrnCalendar,
|
|
1921
2062
|
BrnCalendarCell,
|
|
2063
|
+
BrnCalendarMonth,
|
|
1922
2064
|
BrnCalendarMulti,
|
|
1923
2065
|
BrnCalendarRange,
|
|
1924
2066
|
BrnCalendarMonthSelect,
|
|
@@ -1936,5 +2078,5 @@ const BrnCalendarImports = [
|
|
|
1936
2078
|
* Generated bundle index. Do not edit.
|
|
1937
2079
|
*/
|
|
1938
2080
|
|
|
1939
|
-
export { BrnCalendar, BrnCalendarCell, BrnCalendarCellButton, BrnCalendarGrid, BrnCalendarHeader, BrnCalendarI18nService, BrnCalendarI18nToken, BrnCalendarImports, BrnCalendarMonthSelect, BrnCalendarMulti, BrnCalendarNextButton, BrnCalendarPreviousButton, BrnCalendarRange, BrnCalendarToken, BrnCalendarWeek, BrnCalendarWeekday, BrnCalendarYearSelect, BrnMonthYearCalendar, BrnMonthYearCalendarGrid, BrnMonthYearCalendarHeader, BrnMonthYearCalendarMonthButton, BrnMonthYearCalendarNextButton, BrnMonthYearCalendarPreviousButton, BrnMonthYearCalendarToken, BrnMonthYearCalendarYearButton, injectBrnCalendar, injectBrnCalendarI18n, injectBrnMonthYearCalendar, provideBrnCalendar, provideBrnCalendarI18n, provideBrnMonthYearCalendar };
|
|
2081
|
+
export { BrnCalendar, BrnCalendarCell, BrnCalendarCellButton, BrnCalendarGrid, BrnCalendarHeader, BrnCalendarI18nService, BrnCalendarI18nToken, BrnCalendarImports, BrnCalendarMonth, BrnCalendarMonthSelect, BrnCalendarMonthToken, BrnCalendarMulti, BrnCalendarNextButton, BrnCalendarPreviousButton, BrnCalendarRange, BrnCalendarToken, BrnCalendarWeek, BrnCalendarWeekday, BrnCalendarYearSelect, BrnMonthYearCalendar, BrnMonthYearCalendarGrid, BrnMonthYearCalendarHeader, BrnMonthYearCalendarMonthButton, BrnMonthYearCalendarNextButton, BrnMonthYearCalendarPreviousButton, BrnMonthYearCalendarToken, BrnMonthYearCalendarYearButton, injectBrnCalendar, injectBrnCalendarI18n, injectBrnCalendarMonth, injectBrnMonthYearCalendar, provideBrnCalendar, provideBrnCalendarI18n, provideBrnMonthYearCalendar };
|
|
1940
2082
|
//# sourceMappingURL=spartan-ng-brain-calendar.mjs.map
|