@anglr/datetime 9.0.0-beta.20241007061121 → 9.0.0-beta.20241007072706
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/es2022/src/modules/calendar/components/monthCalendar/monthCalendar.component.js +91 -141
- package/es2022/src/modules/calendar/components/monthCalendar/monthCalendar.component.js.map +1 -1
- package/package.json +1 -1
- package/src/modules/calendar/components/monthCalendar/monthCalendar.component.d.ts +13 -38
- package/src/modules/calendar/components/monthCalendar/monthCalendar.component.d.ts.map +1 -1
- package/src/modules/calendar/components/monthCalendar/monthCalendar.component.html +5 -5
- package/version.bak +1 -1
|
@@ -1,192 +1,142 @@
|
|
|
1
|
-
import { Component, ChangeDetectionStrategy,
|
|
2
|
-
import { KeyValuePipe } from '@angular/common';
|
|
3
|
-
import { isString
|
|
1
|
+
import { Component, ChangeDetectionStrategy, Inject, TemplateRef, input, viewChild, contentChild, computed, effect, inject } from '@angular/core';
|
|
2
|
+
import { KeyValuePipe, NgTemplateOutlet } from '@angular/common';
|
|
3
|
+
import { isString } from '@jscrpt/common';
|
|
4
4
|
import { CalendarDayTemplateDirective } from '../../directives';
|
|
5
5
|
import { MonthCalendarDayFormat, CalendarDayAspectRatio } from '../../misc';
|
|
6
6
|
import { EventParser } from '../../services';
|
|
7
7
|
import { DATE_API, FORMAT_PROVIDER } from '../../../../misc/tokens';
|
|
8
8
|
import * as i0 from "@angular/core";
|
|
9
9
|
import * as i1 from "../../services";
|
|
10
|
+
/**
|
|
11
|
+
* Transform function for `CalendarDayAspectRatio` allowing enter value as number or member name of `CalendarDayAspectRatio`
|
|
12
|
+
*/
|
|
13
|
+
function dayAspectRatioAttribute(value) {
|
|
14
|
+
if (isString(value)) {
|
|
15
|
+
return CalendarDayAspectRatio[value];
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
10
19
|
/**
|
|
11
20
|
* Component used for displaying month calendar
|
|
12
21
|
*/
|
|
13
22
|
export class MonthCalendarComponent {
|
|
14
|
-
/**
|
|
15
|
-
* Calendar day template to be used
|
|
16
|
-
*/
|
|
17
|
-
get calendarDayTemplate() {
|
|
18
|
-
return this.customCalendarDayTemplate ?? this.defaultCalendarDayTemplate;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Aspect ratio for displayed calendar day cell
|
|
22
|
-
*/
|
|
23
|
-
get dayAspectRatio() {
|
|
24
|
-
return this.dayAspectRatioValue;
|
|
25
|
-
}
|
|
26
|
-
set dayAspectRatio(value) {
|
|
27
|
-
if (isString(value)) {
|
|
28
|
-
this.dayAspectRatioValue = CalendarDayAspectRatio[value];
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
this.dayAspectRatioValue = value;
|
|
32
|
-
}
|
|
33
23
|
//######################### constructor #########################
|
|
34
24
|
constructor(dateApi, formatProvider, eventParser) {
|
|
35
25
|
this.dateApi = dateApi;
|
|
36
26
|
this.formatProvider = formatProvider;
|
|
37
27
|
this.eventParser = eventParser;
|
|
38
|
-
//######################### protected properties -
|
|
28
|
+
//######################### protected properties - children #########################
|
|
39
29
|
/**
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
|
-
this.dayAspectRatioValue = CalendarDayAspectRatio.ThreeToTwo;
|
|
43
|
-
/**
|
|
44
|
-
* Data that represents calendar data
|
|
30
|
+
* Default calendar day template
|
|
45
31
|
*/
|
|
46
|
-
this.
|
|
32
|
+
this.defaultCalendarDayTemplate = viewChild.required(CalendarDayTemplateDirective, { read: TemplateRef });
|
|
47
33
|
/**
|
|
48
|
-
*
|
|
34
|
+
* Custom calendar day template
|
|
49
35
|
*/
|
|
50
|
-
this.
|
|
36
|
+
this.customCalendarDayTemplate = contentChild(CalendarDayTemplateDirective, { read: TemplateRef });
|
|
51
37
|
//######################### public properties - inputs #########################
|
|
52
38
|
/**
|
|
53
39
|
* Indication that week number should be displayed
|
|
54
40
|
*/
|
|
55
|
-
this.showWeekNumber = false;
|
|
41
|
+
this.showWeekNumber = input(false);
|
|
42
|
+
/**
|
|
43
|
+
* Date that should be displayed in month calendar
|
|
44
|
+
*/
|
|
45
|
+
this.display = input(inject(DATE_API).now().value);
|
|
56
46
|
/**
|
|
57
47
|
* Format for displaying week day names
|
|
58
48
|
*/
|
|
59
|
-
this.weekDayName = MonthCalendarDayFormat.Short;
|
|
49
|
+
this.weekDayName = input(MonthCalendarDayFormat.Short);
|
|
50
|
+
/**
|
|
51
|
+
* Aspect ratio for displayed calendar day cell
|
|
52
|
+
*/
|
|
53
|
+
this.dayAspectRatio = input(CalendarDayAspectRatio.ThreeToTwo, { transform: dayAspectRatioAttribute });
|
|
60
54
|
/**
|
|
61
55
|
* Array of events that should be displayed
|
|
62
56
|
*/
|
|
63
|
-
this.events = [];
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
* Called when input value changes
|
|
76
|
-
*/
|
|
77
|
-
ngOnChanges(changes) {
|
|
78
|
-
if (nameof('weekDayName') in changes) {
|
|
79
|
-
this.initWeekdayNames();
|
|
80
|
-
}
|
|
81
|
-
if (nameof('display') in changes) {
|
|
82
|
-
this.initializeDisplayCalendar();
|
|
83
|
-
}
|
|
84
|
-
if (nameof('events') in changes && !(nameof('display') in changes)) {
|
|
85
|
-
this.initAndAttachEventData();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
//######################### protected methods #########################
|
|
89
|
-
/**
|
|
90
|
-
* Initialize weekday names
|
|
91
|
-
*/
|
|
92
|
-
initWeekdayNames() {
|
|
93
|
-
this.weekDayNames = [];
|
|
94
|
-
switch (this.weekDayName) {
|
|
95
|
-
default:
|
|
96
|
-
// case MonthCalendarDayFormat.None:
|
|
97
|
-
{
|
|
98
|
-
for (let x = 0; x < 7; x++) {
|
|
99
|
-
this.weekDayNames.push('');
|
|
57
|
+
this.events = input([]);
|
|
58
|
+
this.calendarDayTemplate = computed(() => this.customCalendarDayTemplate() ?? this.defaultCalendarDayTemplate());
|
|
59
|
+
this.weekDayNames = computed(() => {
|
|
60
|
+
const weekDayNames = [];
|
|
61
|
+
switch (this.weekDayName()) {
|
|
62
|
+
default:
|
|
63
|
+
// case MonthCalendarDayFormat.None:
|
|
64
|
+
{
|
|
65
|
+
for (let x = 0; x < 7; x++) {
|
|
66
|
+
weekDayNames.push('');
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
100
69
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
70
|
+
case MonthCalendarDayFormat.Short:
|
|
71
|
+
{
|
|
72
|
+
const names = this.dateApi.weekdays(true);
|
|
73
|
+
weekDayNames.push(...names);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case MonthCalendarDayFormat.Full:
|
|
77
|
+
{
|
|
78
|
+
const names = this.dateApi.weekdays();
|
|
79
|
+
weekDayNames.push(...names);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return weekDayNames;
|
|
84
|
+
});
|
|
85
|
+
this.calendarData = computed(() => {
|
|
86
|
+
const display = this.display();
|
|
87
|
+
const workDate = this.dateApi.getValue(display);
|
|
88
|
+
workDate.startOfMonth()
|
|
89
|
+
.startOfWeek();
|
|
90
|
+
const calendarData = {};
|
|
91
|
+
do {
|
|
92
|
+
const weekData = calendarData[workDate.format(this.formatProvider.week)] = [];
|
|
93
|
+
for (let x = 0; x < 7; x++) {
|
|
94
|
+
weekData.push({
|
|
95
|
+
date: workDate.value,
|
|
96
|
+
day: workDate.dayOfMonth(),
|
|
97
|
+
events: [],
|
|
98
|
+
isCurrentMonth: workDate.isSameMonth(display),
|
|
99
|
+
isWeekend: workDate.isWeekend(),
|
|
100
|
+
week: +workDate.format(this.formatProvider.week),
|
|
101
|
+
});
|
|
102
|
+
workDate.addDays(1);
|
|
108
103
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
104
|
+
workDate.startOfWeek();
|
|
105
|
+
} while (workDate.isSameMonth(display));
|
|
106
|
+
return calendarData;
|
|
107
|
+
});
|
|
108
|
+
effect(() => {
|
|
109
|
+
const events = this.eventParser.getEventsPerDay(this.events());
|
|
110
|
+
const calendarData = this.calendarData();
|
|
111
|
+
for (const week in calendarData) {
|
|
112
|
+
const weekData = calendarData[week];
|
|
113
|
+
for (const day of weekData) {
|
|
114
|
+
const found = events.find(itm => this.dateApi.getValue(itm[0]).isSame(day.date));
|
|
115
|
+
day.events = found?.[1] ?? [];
|
|
114
116
|
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Initialize date for calendar that should be displayed
|
|
119
|
-
*/
|
|
120
|
-
initializeDisplayCalendar() {
|
|
121
|
-
this.display ??= this.dateApi.now().value;
|
|
122
|
-
const workDate = this.dateApi.getValue(this.display);
|
|
123
|
-
workDate.startOfMonth()
|
|
124
|
-
.startOfWeek();
|
|
125
|
-
this.calendarData = {};
|
|
126
|
-
do {
|
|
127
|
-
const weekData = this.calendarData[workDate.format(this.formatProvider.week)] = [];
|
|
128
|
-
for (let x = 0; x < 7; x++) {
|
|
129
|
-
weekData.push({
|
|
130
|
-
date: workDate.value,
|
|
131
|
-
day: workDate.dayOfMonth(),
|
|
132
|
-
events: [],
|
|
133
|
-
isCurrentMonth: workDate.isSameMonth(this.display),
|
|
134
|
-
isWeekend: workDate.isWeekend(),
|
|
135
|
-
week: +workDate.format(this.formatProvider.week),
|
|
136
|
-
});
|
|
137
|
-
workDate.addDays(1);
|
|
138
|
-
}
|
|
139
|
-
workDate.startOfWeek();
|
|
140
|
-
} while (workDate.isSameMonth(this.display));
|
|
141
|
-
this.initAndAttachEventData();
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Initialize and attaches event data
|
|
145
|
-
*/
|
|
146
|
-
initAndAttachEventData() {
|
|
147
|
-
const events = this.eventParser.getEventsPerDay(this.events);
|
|
148
|
-
for (const week in this.calendarData) {
|
|
149
|
-
const weekData = this.calendarData[week];
|
|
150
|
-
for (const day of weekData) {
|
|
151
|
-
const found = events.find(itm => this.dateApi.getValue(itm[0]).isSame(day.date));
|
|
152
|
-
day.events = found?.[1] ?? [];
|
|
153
117
|
}
|
|
154
|
-
|
|
118
|
+
//TODO: test whether event are refreshed when changed
|
|
119
|
+
});
|
|
155
120
|
}
|
|
156
121
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: MonthCalendarComponent, deps: [{ token: DATE_API }, { token: FORMAT_PROVIDER }, { token: i1.EventParser }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
157
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.7", type: MonthCalendarComponent, isStandalone: true, selector: "month-calendar", inputs: { showWeekNumber: "showWeekNumber", display: "display", weekDayName: "weekDayName", dayAspectRatio: "dayAspectRatio", events: "events" }, providers: [
|
|
122
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.7", type: MonthCalendarComponent, isStandalone: true, selector: "month-calendar", inputs: { showWeekNumber: { classPropertyName: "showWeekNumber", publicName: "showWeekNumber", isSignal: true, isRequired: false, transformFunction: null }, display: { classPropertyName: "display", publicName: "display", isSignal: true, isRequired: false, transformFunction: null }, weekDayName: { classPropertyName: "weekDayName", publicName: "weekDayName", isSignal: true, isRequired: false, transformFunction: null }, dayAspectRatio: { classPropertyName: "dayAspectRatio", publicName: "dayAspectRatio", isSignal: true, isRequired: false, transformFunction: null }, events: { classPropertyName: "events", publicName: "events", isSignal: true, isRequired: false, transformFunction: null } }, providers: [
|
|
158
123
|
EventParser,
|
|
159
|
-
], queries: [{ propertyName: "customCalendarDayTemplate", first: true, predicate: CalendarDayTemplateDirective, descendants: true, read: TemplateRef,
|
|
124
|
+
], queries: [{ propertyName: "customCalendarDayTemplate", first: true, predicate: CalendarDayTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], viewQueries: [{ propertyName: "defaultCalendarDayTemplate", first: true, predicate: CalendarDayTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: "<div *calendarDayTemplate=\"let data\" class=\"default-calendar-day\" [class.is-weekend]=\"data.isWeekend\" [class.is-other-month]=\"!data.isCurrentMonth\">{{data.day}}</div>\n\n<div></div>\n\n@for(dayName of weekDayNames(); track dayName)\n{\n <div [class.week-day-name]=\"dayName\">{{dayName}}</div>\n}\n\n@for(weekData of calendarData() | keyvalue; track weekData)\n{\n <div class=\"week-number\">\n @if(showWeekNumber())\n {\n {{weekData.key}}\n }\n </div>\n \n @for(dayData of weekData.value; track dayData)\n {\n <div [style.padding-bottom.%]=\"dayAspectRatio()\" class=\"day-wrapper\">\n <div class=\"day-content\"><ng-container *ngTemplateOutlet=\"calendarDayTemplate(); context: {$implicit: dayData}\"/></div>\n </div>\n }\n}\n", dependencies: [{ kind: "directive", type: CalendarDayTemplateDirective, selector: "[calendarDayTemplate]" }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "pipe", type: KeyValuePipe, name: "keyvalue" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
160
125
|
}
|
|
161
126
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: MonthCalendarComponent, decorators: [{
|
|
162
127
|
type: Component,
|
|
163
128
|
args: [{ selector: 'month-calendar', standalone: true, imports: [
|
|
164
129
|
CalendarDayTemplateDirective,
|
|
130
|
+
NgTemplateOutlet,
|
|
165
131
|
KeyValuePipe,
|
|
166
132
|
], providers: [
|
|
167
133
|
EventParser,
|
|
168
|
-
], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div *calendarDayTemplate=\"let data\" class=\"default-calendar-day\" [class.is-weekend]=\"data.isWeekend\" [class.is-other-month]=\"!data.isCurrentMonth\">{{data.day}}</div>\n\n<div></div>\n\n@for(dayName of weekDayNames; track dayName)\n{\n <div [class.week-day-name]=\"dayName\">{{dayName}}</div>\n}\n\n@for(weekData of calendarData | keyvalue; track weekData)\n{\n <div class=\"week-number\">\n @if(showWeekNumber)\n {\n {{weekData.key}}\n }\n </div>\n \n @for(dayData of weekData.value; track dayData)\n {\n <div [style.padding-bottom.%]=\"
|
|
134
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div *calendarDayTemplate=\"let data\" class=\"default-calendar-day\" [class.is-weekend]=\"data.isWeekend\" [class.is-other-month]=\"!data.isCurrentMonth\">{{data.day}}</div>\n\n<div></div>\n\n@for(dayName of weekDayNames(); track dayName)\n{\n <div [class.week-day-name]=\"dayName\">{{dayName}}</div>\n}\n\n@for(weekData of calendarData() | keyvalue; track weekData)\n{\n <div class=\"week-number\">\n @if(showWeekNumber())\n {\n {{weekData.key}}\n }\n </div>\n \n @for(dayData of weekData.value; track dayData)\n {\n <div [style.padding-bottom.%]=\"dayAspectRatio()\" class=\"day-wrapper\">\n <div class=\"day-content\"><ng-container *ngTemplateOutlet=\"calendarDayTemplate(); context: {$implicit: dayData}\"/></div>\n </div>\n }\n}\n" }]
|
|
169
135
|
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
170
136
|
type: Inject,
|
|
171
137
|
args: [DATE_API]
|
|
172
138
|
}] }, { type: undefined, decorators: [{
|
|
173
139
|
type: Inject,
|
|
174
140
|
args: [FORMAT_PROVIDER]
|
|
175
|
-
}] }, { type: i1.EventParser }]
|
|
176
|
-
type: ViewChild,
|
|
177
|
-
args: [CalendarDayTemplateDirective, { static: true, read: TemplateRef }]
|
|
178
|
-
}], customCalendarDayTemplate: [{
|
|
179
|
-
type: ContentChild,
|
|
180
|
-
args: [CalendarDayTemplateDirective, { static: true, read: TemplateRef }]
|
|
181
|
-
}], showWeekNumber: [{
|
|
182
|
-
type: Input
|
|
183
|
-
}], display: [{
|
|
184
|
-
type: Input
|
|
185
|
-
}], weekDayName: [{
|
|
186
|
-
type: Input
|
|
187
|
-
}], dayAspectRatio: [{
|
|
188
|
-
type: Input
|
|
189
|
-
}], events: [{
|
|
190
|
-
type: Input
|
|
191
|
-
}] } });
|
|
141
|
+
}] }, { type: i1.EventParser }] });
|
|
192
142
|
//# sourceMappingURL=monthCalendar.component.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monthCalendar.component.js","sourceRoot":"","sources":["../../../../../../src/modules/calendar/components/monthCalendar/monthCalendar.component.ts","../../../../../../src/modules/calendar/components/monthCalendar/monthCalendar.component.html"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,EAAU,SAAS,EAAE,WAAW,EAAE,YAAY,EAA2B,MAAM,eAAe,CAAC;AACxJ,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAa,QAAQ,EAAE,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAC,4BAA4B,EAA6B,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAC,sBAAsB,EAAE,sBAAsB,EAAC,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,QAAQ,EAAE,eAAe,EAAC,MAAM,yBAAyB,CAAC;;;AAIlE;;GAEG;AAiBH,MAAM,OAAO,sBAAsB;IAc/B;;OAEG;IACH,IAAc,mBAAmB;QAE7B,OAAO,IAAI,CAAC,yBAAyB,IAAI,IAAI,CAAC,0BAA0B,CAAC;IAC7E,CAAC;IAyCD;;OAEG;IACH,IACW,cAAc;QAErB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IACpC,CAAC;IACD,IAAW,cAAc,CAAC,KA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C,CAAC;gBACjF,GAAG,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAClC,CAAC;QACL,CAAC;IACL,CAAC;8GA/NQ,sBAAsB,kBAwFX,QAAQ,aACR,eAAe;kGAzF1B,sBAAsB,+MAL/B;YACI,WAAW;SACd,iFAyCa,4BAA4B,2BAAuB,WAAW,uGANjE,4BAA4B,2BAAuB,WAAW,gEC/D7E,2yBAyBA,4CDHQ,4BAA4B,6DAC5B,YAAY;;2FAQP,sBAAsB;kBAhBlC,SAAS;+BAEI,gBAAgB,cAEd,IAAI,WAEhB;wBACI,4BAA4B;wBAC5B,YAAY;qBACf,aAED;wBACI,WAAW;qBACd,mBACgB,uBAAuB,CAAC,MAAM;;0BA0FlC,MAAM;2BAAC,QAAQ;;0BACf,MAAM;2BAAC,eAAe;mEAxDzB,0BAA0B;sBADnC,SAAS;uBAAC,4BAA4B,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAC;gBAOhE,yBAAyB;sBADlC,YAAY;uBAAC,4BAA4B,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAC;gBAStE,cAAc;sBADpB,KAAK;gBAOC,OAAO;sBADb,KAAK;gBAOC,WAAW;sBADjB,KAAK;gBAOK,cAAc;sBADxB,KAAK;gBAqBC,MAAM;sBADZ,KAAK","sourcesContent":["import {Component, ChangeDetectionStrategy, Input, Inject, OnInit, ViewChild, TemplateRef, ContentChild, OnChanges, SimpleChanges} from '@angular/core';\nimport {KeyValuePipe} from '@angular/common';\nimport {Dictionary, isString, nameof} from '@jscrpt/common';\n\nimport {CalendarDayData, EventData} from '../../interfaces';\nimport {CalendarDayTemplateDirective, CalendarDayTemplateContext} from '../../directives';\nimport {MonthCalendarDayFormat, CalendarDayAspectRatio} from '../../misc';\nimport {EventParser} from '../../services';\nimport {DATE_API, FORMAT_PROVIDER} from '../../../../misc/tokens';\nimport {DateApi} from '../../../../services';\nimport {FormatProvider} from '../../../../interfaces';\n\n/**\n * Component used for displaying month calendar\n */\n@Component(\n{\n selector: 'month-calendar',\n templateUrl: 'monthCalendar.component.html',\n standalone: true,\n imports:\n [\n CalendarDayTemplateDirective,\n KeyValuePipe,\n ],\n providers:\n [\n EventParser,\n ],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class MonthCalendarComponent<TDate = unknown, TEvent = unknown> implements OnInit, OnChanges\n{\n //######################### protected properties - template bindings #########################\n\n /**\n * Aspect ratio for displayed calendar day cell\n */\n protected dayAspectRatioValue: number = CalendarDayAspectRatio.ThreeToTwo;\n\n /**\n * Data that represents calendar data\n */\n protected calendarData: Dictionary<CalendarDayData<TDate, TEvent>[]> = {};\n\n /**\n * Calendar day template to be used\n */\n protected get calendarDayTemplate(): TemplateRef<CalendarDayTemplateContext>\n {\n return this.customCalendarDayTemplate ?? this.defaultCalendarDayTemplate;\n }\n\n /**\n * Array of weekday names\n */\n protected weekDayNames: string[] = [];\n\n //######################### protected properties - children #########################\n\n /**\n * Default calendar day template\n */\n @ViewChild(CalendarDayTemplateDirective, {static: true, read: TemplateRef})\n protected defaultCalendarDayTemplate!: TemplateRef<CalendarDayTemplateContext>;\n\n /**\n * Custom calendar day template\n */\n @ContentChild(CalendarDayTemplateDirective, {static: true, read: TemplateRef})\n protected customCalendarDayTemplate: TemplateRef<CalendarDayTemplateContext>|undefined|null;\n\n //######################### public properties - inputs #########################\n\n /**\n * Indication that week number should be displayed\n */\n @Input()\n public showWeekNumber: boolean = false;\n\n /**\n * Date that should be displayed in month calendar\n */\n @Input()\n public display: TDate|undefined|null;\n\n /**\n * Format for displaying week day names\n */\n @Input()\n public weekDayName: MonthCalendarDayFormat = MonthCalendarDayFormat.Short;\n\n /**\n * Aspect ratio for displayed calendar day cell\n */\n @Input()\n public get dayAspectRatio(): number\n {\n return this.dayAspectRatioValue;\n }\n public set dayAspectRatio(value: number)\n {\n if(isString(value))\n {\n this.dayAspectRatioValue = CalendarDayAspectRatio[value] as unknown as number;\n\n return;\n }\n\n this.dayAspectRatioValue = value;\n }\n\n /**\n * Array of events that should be displayed\n */\n @Input()\n public events: EventData<TDate, TEvent>[] = [];\n\n //######################### constructor #########################\n constructor(@Inject(DATE_API) protected dateApi: DateApi<TDate>,\n @Inject(FORMAT_PROVIDER) protected formatProvider: FormatProvider,\n protected eventParser: EventParser<TDate, TEvent>,)\n {\n }\n\n //######################### public methods - implementation of OnInit #########################\n\n /**\n * Initialize component\n */\n public ngOnInit(): void\n {\n this.initWeekdayNames();\n this.initializeDisplayCalendar();\n }\n\n //######################### public methods - implementation of OnChanges #########################\n\n /**\n * Called when input value changes\n */\n public ngOnChanges(changes: SimpleChanges): void\n {\n if(nameof<MonthCalendarComponent>('weekDayName') in changes)\n {\n this.initWeekdayNames();\n }\n\n if(nameof<MonthCalendarComponent>('display') in changes)\n {\n this.initializeDisplayCalendar();\n }\n\n if(nameof<MonthCalendarComponent>('events') in changes && !(nameof<MonthCalendarComponent>('display') in changes))\n {\n this.initAndAttachEventData();\n }\n }\n\n //######################### protected methods #########################\n\n /**\n * Initialize weekday names\n */\n protected initWeekdayNames(): void\n {\n this.weekDayNames = [];\n\n switch(this.weekDayName)\n {\n default:\n // case MonthCalendarDayFormat.None:\n {\n for(let x = 0; x < 7; x++)\n {\n this.weekDayNames.push('');\n }\n\n break;\n }\n case MonthCalendarDayFormat.Short:\n {\n const names = this.dateApi.weekdays(true);\n this.weekDayNames.push(...names);\n\n break;\n }\n case MonthCalendarDayFormat.Full:\n {\n const names = this.dateApi.weekdays();\n this.weekDayNames.push(...names);\n\n break;\n }\n }\n }\n\n /**\n * Initialize date for calendar that should be displayed\n */\n protected initializeDisplayCalendar(): void\n {\n this.display ??= this.dateApi.now().value;\n\n const workDate = this.dateApi.getValue(this.display);\n\n workDate.startOfMonth()\n .startOfWeek();\n\n this.calendarData = {};\n\n do\n {\n const weekData: CalendarDayData<TDate, TEvent>[] = this.calendarData[workDate.format(this.formatProvider.week)] = [];\n\n for(let x = 0; x < 7; x++)\n {\n weekData.push(\n {\n date: workDate.value,\n day: workDate.dayOfMonth(),\n events: [],\n isCurrentMonth: workDate.isSameMonth(this.display),\n isWeekend: workDate.isWeekend(),\n week: +workDate.format(this.formatProvider.week),\n });\n\n workDate.addDays(1);\n }\n\n workDate.startOfWeek();\n }\n while(workDate.isSameMonth(this.display));\n\n this.initAndAttachEventData();\n }\n\n /**\n * Initialize and attaches event data\n */\n protected initAndAttachEventData(): void\n {\n const events = this.eventParser.getEventsPerDay(this.events);\n\n for(const week in this.calendarData)\n {\n const weekData = this.calendarData[week];\n\n for(const day of weekData)\n {\n const found = events.find(itm => this.dateApi.getValue(itm[0]).isSame(day.date));\n day.events = found?.[1] ?? [];\n }\n }\n }\n\n //######################### ng language server #########################\n\n /**\n * Custom input type for `weekDayName` input\n */\n public static ngAcceptInputType_weekDayName: keyof typeof MonthCalendarDayFormat;\n\n /**\n * Custom input type for `dayAspectRatio` input\n */\n public static ngAcceptInputType_dayAspectRatio: keyof typeof CalendarDayAspectRatio|number;\n}","<div *calendarDayTemplate=\"let data\" class=\"default-calendar-day\" [class.is-weekend]=\"data.isWeekend\" [class.is-other-month]=\"!data.isCurrentMonth\">{{data.day}}</div>\n\n<div></div>\n\n@for(dayName of weekDayNames; track dayName)\n{\n <div [class.week-day-name]=\"dayName\">{{dayName}}</div>\n}\n\n@for(weekData of calendarData | keyvalue; track weekData)\n{\n <div class=\"week-number\">\n @if(showWeekNumber)\n {\n {{weekData.key}}\n }\n </div>\n \n @for(dayData of weekData.value; track dayData)\n {\n <div [style.padding-bottom.%]=\"dayAspectRatioValue\" class=\"day-wrapper\">\n <div class=\"day-content\"><ng-container *ngTemplateOutlet=\"calendarDayTemplate; context: {$implicit: dayData}\"/></div>\n </div>\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"monthCalendar.component.js","sourceRoot":"","sources":["../../../../../../src/modules/calendar/components/monthCalendar/monthCalendar.component.ts","../../../../../../src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GAAG,EAAE;YAER,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAC/D,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YAEzC,KAAI,MAAM,IAAI,IAAI,YAAY,EAC9B,CAAC;gBACG,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;gBAEpC,KAAI,MAAM,GAAG,IAAI,QAAQ,EACzB,CAAC;oBACG,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;oBACjF,GAAG,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;gBAClC,CAAC;YACL,CAAC;YACD,qDAAqD;QACzD,CAAC,CAAC,CAAC;IACP,CAAC;8GAzJQ,sBAAsB,kBA2DX,QAAQ,aACR,eAAe;kGA5D1B,sBAAsB,kvBAL/B;YACI,WAAW;SACd,iFAgCkH,4BAA4B,2BAAS,WAAW,yGALxD,4BAA4B,2BAAS,WAAW,6CCrE/J,gzBAyBA,4CDUQ,4BAA4B,kEAC5B,gBAAgB,+IAChB,YAAY;;2FAQP,sBAAsB;kBAjBlC,SAAS;+BAEI,gBAAgB,cAEd,IAAI,WAEhB;wBACI,4BAA4B;wBAC5B,gBAAgB;wBAChB,YAAY;qBACf,aAED;wBACI,WAAW;qBACd,mBACgB,uBAAuB,CAAC,MAAM;;0BA6DlC,MAAM;2BAAC,QAAQ;;0BACf,MAAM;2BAAC,eAAe","sourcesContent":["import {Component, ChangeDetectionStrategy, Inject, TemplateRef, Signal, input, InputSignal, viewChild, contentChild, InputSignalWithTransform, computed, effect, inject} from '@angular/core';\nimport {KeyValuePipe, NgTemplateOutlet} from '@angular/common';\nimport {Dictionary, isString} from '@jscrpt/common';\n\nimport {CalendarDayData, EventData} from '../../interfaces';\nimport {CalendarDayTemplateDirective, CalendarDayTemplateContext} from '../../directives';\nimport {MonthCalendarDayFormat, CalendarDayAspectRatio} from '../../misc';\nimport {EventParser} from '../../services';\nimport {DATE_API, FORMAT_PROVIDER} from '../../../../misc/tokens';\nimport {DateApi} from '../../../../services';\nimport {FormatProvider} from '../../../../interfaces';\n\n/**\n * Transform function for `CalendarDayAspectRatio` allowing enter value as number or member name of `CalendarDayAspectRatio`\n */\nfunction dayAspectRatioAttribute(value: keyof typeof CalendarDayAspectRatio|number): CalendarDayAspectRatio\n{\n if(isString(value))\n {\n return CalendarDayAspectRatio[value];\n }\n\n return value;\n}\n\n/**\n * Component used for displaying month calendar\n */\n@Component(\n{\n selector: 'month-calendar',\n templateUrl: 'monthCalendar.component.html',\n standalone: true,\n imports:\n [\n CalendarDayTemplateDirective,\n NgTemplateOutlet,\n KeyValuePipe,\n ],\n providers:\n [\n EventParser,\n ],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class MonthCalendarComponent<TDate = unknown, TEvent = unknown>\n{\n //######################### protected properties - template bindings #########################\n\n /**\n * Data that represents calendar data\n */\n protected calendarData: Signal<Dictionary<CalendarDayData<TDate, TEvent>[]>>;\n\n /**\n * Calendar day template to be used\n */\n protected calendarDayTemplate: Signal<TemplateRef<CalendarDayTemplateContext>>;\n\n /**\n * Array of weekday names\n */\n protected weekDayNames: Signal<string[]>;\n\n //######################### protected properties - children #########################\n\n /**\n * Default calendar day template\n */\n protected defaultCalendarDayTemplate: Signal<TemplateRef<CalendarDayTemplateContext>> = viewChild.required(CalendarDayTemplateDirective, {read: TemplateRef});\n\n /**\n * Custom calendar day template\n */\n protected customCalendarDayTemplate: Signal<TemplateRef<CalendarDayTemplateContext>|undefined|null> = contentChild(CalendarDayTemplateDirective, {read: TemplateRef});\n\n //######################### public properties - inputs #########################\n\n /**\n * Indication that week number should be displayed\n */\n public showWeekNumber: InputSignal<boolean> = input(false);\n\n /**\n * Date that should be displayed in month calendar\n */\n public display: InputSignal<TDate> = input(inject<DateApi<TDate>>(DATE_API).now().value);\n\n /**\n * Format for displaying week day names\n */\n public weekDayName: InputSignal<MonthCalendarDayFormat> = input<MonthCalendarDayFormat>(MonthCalendarDayFormat.Short);\n\n /**\n * Aspect ratio for displayed calendar day cell\n */\n public dayAspectRatio: InputSignalWithTransform<CalendarDayAspectRatio, keyof typeof CalendarDayAspectRatio|number> = input<CalendarDayAspectRatio, keyof typeof CalendarDayAspectRatio|number>(CalendarDayAspectRatio.ThreeToTwo, {transform: dayAspectRatioAttribute});\n\n /**\n * Array of events that should be displayed\n */\n public events: InputSignal<EventData<TDate, TEvent>[]> = input<EventData<TDate, TEvent>[]>([]);\n\n //######################### constructor #########################\n constructor(@Inject(DATE_API) protected dateApi: DateApi<TDate>,\n @Inject(FORMAT_PROVIDER) protected formatProvider: FormatProvider,\n protected eventParser: EventParser<TDate, TEvent>,)\n {\n this.calendarDayTemplate = computed(() => this.customCalendarDayTemplate() ?? this.defaultCalendarDayTemplate());\n\n this.weekDayNames = computed(() =>\n {\n const weekDayNames = [];\n\n switch(this.weekDayName())\n {\n default:\n // case MonthCalendarDayFormat.None:\n {\n for(let x = 0; x < 7; x++)\n {\n weekDayNames.push('');\n }\n \n break;\n }\n case MonthCalendarDayFormat.Short:\n {\n const names = this.dateApi.weekdays(true);\n weekDayNames.push(...names);\n \n break;\n }\n case MonthCalendarDayFormat.Full:\n {\n const names = this.dateApi.weekdays();\n weekDayNames.push(...names);\n \n break;\n }\n }\n\n return weekDayNames;\n });\n\n this.calendarData = computed(() =>\n {\n const display = this.display();\n const workDate = this.dateApi.getValue(display);\n\n workDate.startOfMonth()\n .startOfWeek();\n \n const calendarData: Dictionary<CalendarDayData<TDate, TEvent>[]> = {};\n \n do\n {\n const weekData: CalendarDayData<TDate, TEvent>[] = calendarData[workDate.format(this.formatProvider.week)] = [];\n \n for(let x = 0; x < 7; x++)\n {\n weekData.push(\n {\n date: workDate.value,\n day: workDate.dayOfMonth(),\n events: [],\n isCurrentMonth: workDate.isSameMonth(display),\n isWeekend: workDate.isWeekend(),\n week: +workDate.format(this.formatProvider.week),\n });\n \n workDate.addDays(1);\n }\n \n workDate.startOfWeek();\n }\n while(workDate.isSameMonth(display));\n \n return calendarData;\n });\n\n effect(() =>\n {\n const events = this.eventParser.getEventsPerDay(this.events());\n const calendarData = this.calendarData();\n\n for(const week in calendarData)\n {\n const weekData = calendarData[week];\n \n for(const day of weekData)\n {\n const found = events.find(itm => this.dateApi.getValue(itm[0]).isSame(day.date));\n day.events = found?.[1] ?? [];\n }\n }\n //TODO: test whether event are refreshed when changed\n });\n }\n\n //######################### ng language server #########################\n\n /**\n * Custom input type for `weekDayName` input\n */\n public static ngAcceptInputType_weekDayName: keyof typeof MonthCalendarDayFormat;\n\n /**\n * Custom input type for `dayAspectRatio` input\n */\n public static ngAcceptInputType_dayAspectRatio: keyof typeof CalendarDayAspectRatio|number;\n}","<div *calendarDayTemplate=\"let data\" class=\"default-calendar-day\" [class.is-weekend]=\"data.isWeekend\" [class.is-other-month]=\"!data.isCurrentMonth\">{{data.day}}</div>\n\n<div></div>\n\n@for(dayName of weekDayNames(); track dayName)\n{\n <div [class.week-day-name]=\"dayName\">{{dayName}}</div>\n}\n\n@for(weekData of calendarData() | keyvalue; track weekData)\n{\n <div class=\"week-number\">\n @if(showWeekNumber())\n {\n {{weekData.key}}\n }\n </div>\n \n @for(dayData of weekData.value; track dayData)\n {\n <div [style.padding-bottom.%]=\"dayAspectRatio()\" class=\"day-wrapper\">\n <div class=\"day-content\"><ng-container *ngTemplateOutlet=\"calendarDayTemplate(); context: {$implicit: dayData}\"/></div>\n </div>\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TemplateRef, Signal, InputSignal, InputSignalWithTransform } from '@angular/core';
|
|
2
2
|
import { Dictionary } from '@jscrpt/common';
|
|
3
3
|
import { CalendarDayData, EventData } from '../../interfaces';
|
|
4
4
|
import { CalendarDayTemplateContext } from '../../directives';
|
|
@@ -10,76 +10,51 @@ import * as i0 from "@angular/core";
|
|
|
10
10
|
/**
|
|
11
11
|
* Component used for displaying month calendar
|
|
12
12
|
*/
|
|
13
|
-
export declare class MonthCalendarComponent<TDate = unknown, TEvent = unknown>
|
|
13
|
+
export declare class MonthCalendarComponent<TDate = unknown, TEvent = unknown> {
|
|
14
14
|
protected dateApi: DateApi<TDate>;
|
|
15
15
|
protected formatProvider: FormatProvider;
|
|
16
16
|
protected eventParser: EventParser<TDate, TEvent>;
|
|
17
|
-
/**
|
|
18
|
-
* Aspect ratio for displayed calendar day cell
|
|
19
|
-
*/
|
|
20
|
-
protected dayAspectRatioValue: number;
|
|
21
17
|
/**
|
|
22
18
|
* Data that represents calendar data
|
|
23
19
|
*/
|
|
24
|
-
protected calendarData: Dictionary<CalendarDayData<TDate, TEvent>[]
|
|
20
|
+
protected calendarData: Signal<Dictionary<CalendarDayData<TDate, TEvent>[]>>;
|
|
25
21
|
/**
|
|
26
22
|
* Calendar day template to be used
|
|
27
23
|
*/
|
|
28
|
-
protected
|
|
24
|
+
protected calendarDayTemplate: Signal<TemplateRef<CalendarDayTemplateContext>>;
|
|
29
25
|
/**
|
|
30
26
|
* Array of weekday names
|
|
31
27
|
*/
|
|
32
|
-
protected weekDayNames: string[]
|
|
28
|
+
protected weekDayNames: Signal<string[]>;
|
|
33
29
|
/**
|
|
34
30
|
* Default calendar day template
|
|
35
31
|
*/
|
|
36
|
-
protected defaultCalendarDayTemplate: TemplateRef<CalendarDayTemplateContext
|
|
32
|
+
protected defaultCalendarDayTemplate: Signal<TemplateRef<CalendarDayTemplateContext>>;
|
|
37
33
|
/**
|
|
38
34
|
* Custom calendar day template
|
|
39
35
|
*/
|
|
40
|
-
protected customCalendarDayTemplate: TemplateRef<CalendarDayTemplateContext> | undefined | null
|
|
36
|
+
protected customCalendarDayTemplate: Signal<TemplateRef<CalendarDayTemplateContext> | undefined | null>;
|
|
41
37
|
/**
|
|
42
38
|
* Indication that week number should be displayed
|
|
43
39
|
*/
|
|
44
|
-
showWeekNumber: boolean
|
|
40
|
+
showWeekNumber: InputSignal<boolean>;
|
|
45
41
|
/**
|
|
46
42
|
* Date that should be displayed in month calendar
|
|
47
43
|
*/
|
|
48
|
-
display: TDate
|
|
44
|
+
display: InputSignal<TDate>;
|
|
49
45
|
/**
|
|
50
46
|
* Format for displaying week day names
|
|
51
47
|
*/
|
|
52
|
-
weekDayName: MonthCalendarDayFormat
|
|
48
|
+
weekDayName: InputSignal<MonthCalendarDayFormat>;
|
|
53
49
|
/**
|
|
54
50
|
* Aspect ratio for displayed calendar day cell
|
|
55
51
|
*/
|
|
56
|
-
|
|
57
|
-
set dayAspectRatio(value: number);
|
|
52
|
+
dayAspectRatio: InputSignalWithTransform<CalendarDayAspectRatio, keyof typeof CalendarDayAspectRatio | number>;
|
|
58
53
|
/**
|
|
59
54
|
* Array of events that should be displayed
|
|
60
55
|
*/
|
|
61
|
-
events: EventData<TDate, TEvent>[]
|
|
56
|
+
events: InputSignal<EventData<TDate, TEvent>[]>;
|
|
62
57
|
constructor(dateApi: DateApi<TDate>, formatProvider: FormatProvider, eventParser: EventParser<TDate, TEvent>);
|
|
63
|
-
/**
|
|
64
|
-
* Initialize component
|
|
65
|
-
*/
|
|
66
|
-
ngOnInit(): void;
|
|
67
|
-
/**
|
|
68
|
-
* Called when input value changes
|
|
69
|
-
*/
|
|
70
|
-
ngOnChanges(changes: SimpleChanges): void;
|
|
71
|
-
/**
|
|
72
|
-
* Initialize weekday names
|
|
73
|
-
*/
|
|
74
|
-
protected initWeekdayNames(): void;
|
|
75
|
-
/**
|
|
76
|
-
* Initialize date for calendar that should be displayed
|
|
77
|
-
*/
|
|
78
|
-
protected initializeDisplayCalendar(): void;
|
|
79
|
-
/**
|
|
80
|
-
* Initialize and attaches event data
|
|
81
|
-
*/
|
|
82
|
-
protected initAndAttachEventData(): void;
|
|
83
58
|
/**
|
|
84
59
|
* Custom input type for `weekDayName` input
|
|
85
60
|
*/
|
|
@@ -89,6 +64,6 @@ export declare class MonthCalendarComponent<TDate = unknown, TEvent = unknown> i
|
|
|
89
64
|
*/
|
|
90
65
|
static ngAcceptInputType_dayAspectRatio: keyof typeof CalendarDayAspectRatio | number;
|
|
91
66
|
static ɵfac: i0.ɵɵFactoryDeclaration<MonthCalendarComponent<any, any>, never>;
|
|
92
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<MonthCalendarComponent<any, any>, "month-calendar", never, { "showWeekNumber": { "alias": "showWeekNumber"; "required": false; }; "display": { "alias": "display"; "required": false; }; "weekDayName": { "alias": "weekDayName"; "required": false; }; "dayAspectRatio": { "alias": "dayAspectRatio"; "required": false; }; "events": { "alias": "events"; "required": false; }; }, {}, ["customCalendarDayTemplate"], never, true, never>;
|
|
67
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<MonthCalendarComponent<any, any>, "month-calendar", never, { "showWeekNumber": { "alias": "showWeekNumber"; "required": false; "isSignal": true; }; "display": { "alias": "display"; "required": false; "isSignal": true; }; "weekDayName": { "alias": "weekDayName"; "required": false; "isSignal": true; }; "dayAspectRatio": { "alias": "dayAspectRatio"; "required": false; "isSignal": true; }; "events": { "alias": "events"; "required": false; "isSignal": true; }; }, {}, ["customCalendarDayTemplate"], never, true, never>;
|
|
93
68
|
}
|
|
94
69
|
//# sourceMappingURL=monthCalendar.component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monthCalendar.component.d.ts","sourceRoot":"","sources":["monthCalendar.component.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"monthCalendar.component.d.ts","sourceRoot":"","sources":["monthCalendar.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,WAAW,EAAE,MAAM,EAAS,WAAW,EAA2B,wBAAwB,EAA2B,MAAM,eAAe,C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;;OAEG;IACI,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,CAAuD;IAEzF;;OAEG;IACI,WAAW,EAAE,WAAW,CAAC,sBAAsB,CAAC,CAA+D;IAEtH;;OAEG;IACI,cAAc,EAAE,wBAAwB,CAAC,sBAAsB,EAAE,MAAM,OAAO,sBAAsB,GAAC,MAAM,CAAC,CAAsJ;IAEzQ;;OAEG;IACI,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,CAAyC;gBAGvD,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EAChB,cAAc,EAAE,cAAc,EACvD,WAAW,EAAE,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC;IAgG7D;;OAEG;IACH,OAAc,6BAA6B,EAAE,MAAM,OAAO,sBAAsB,CAAC;IAEjF;;OAEG;IACH,OAAc,gCAAgC,EAAE,MAAM,OAAO,sBAAsB,GAAC,MAAM,CAAC;yCArKlF,sBAAsB;2CAAtB,sBAAsB;CAsKlC"}
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
<div></div>
|
|
4
4
|
|
|
5
|
-
@for(dayName of weekDayNames; track dayName)
|
|
5
|
+
@for(dayName of weekDayNames(); track dayName)
|
|
6
6
|
{
|
|
7
7
|
<div [class.week-day-name]="dayName">{{dayName}}</div>
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
@for(weekData of calendarData | keyvalue; track weekData)
|
|
10
|
+
@for(weekData of calendarData() | keyvalue; track weekData)
|
|
11
11
|
{
|
|
12
12
|
<div class="week-number">
|
|
13
|
-
@if(showWeekNumber)
|
|
13
|
+
@if(showWeekNumber())
|
|
14
14
|
{
|
|
15
15
|
{{weekData.key}}
|
|
16
16
|
}
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
|
|
19
19
|
@for(dayData of weekData.value; track dayData)
|
|
20
20
|
{
|
|
21
|
-
<div [style.padding-bottom.%]="
|
|
22
|
-
<div class="day-content"><ng-container *ngTemplateOutlet="calendarDayTemplate; context: {$implicit: dayData}"/></div>
|
|
21
|
+
<div [style.padding-bottom.%]="dayAspectRatio()" class="day-wrapper">
|
|
22
|
+
<div class="day-content"><ng-container *ngTemplateOutlet="calendarDayTemplate(); context: {$implicit: dayData}"/></div>
|
|
23
23
|
</div>
|
|
24
24
|
}
|
|
25
25
|
}
|
package/version.bak
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
9.0.0-beta.
|
|
1
|
+
9.0.0-beta.20241007072706
|