@radix-ng/primitives 0.33.1 → 0.33.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.
- package/calendar/README.md +1 -0
- package/calendar/index.d.ts +30 -0
- package/calendar/src/calendar-cell-trigger.directive.d.ts +54 -0
- package/calendar/src/calendar-cell.directive.d.ts +11 -0
- package/calendar/src/calendar-grid-body.directive.d.ts +5 -0
- package/calendar/src/calendar-grid-head.directive.d.ts +5 -0
- package/calendar/src/calendar-grid-row.directive.d.ts +5 -0
- package/calendar/src/calendar-grid.directive.d.ts +8 -0
- package/calendar/src/calendar-head-cell.directive.d.ts +5 -0
- package/calendar/src/calendar-header.directive.d.ts +5 -0
- package/calendar/src/calendar-heading.directive.d.ts +7 -0
- package/calendar/src/calendar-next.directive.d.ts +16 -0
- package/calendar/src/calendar-prev.directive.d.ts +16 -0
- package/calendar/src/calendar-root.directive.d.ts +148 -0
- package/calendar/src/calendar.d.ts +44 -0
- package/calendar/src//321/201alendar-/321/201ontext.token.d.ts +24 -0
- package/core/index.d.ts +2 -0
- package/core/src/chunk.d.ts +12 -0
- package/core/src/date-time/calendar.d.ts +33 -0
- package/core/src/date-time/comparators.d.ts +92 -0
- package/core/src/date-time/formatter.d.ts +30 -0
- package/core/src/date-time/index.d.ts +6 -0
- package/core/src/date-time/placeholders.d.ts +8 -0
- package/core/src/date-time/types.d.ts +28 -0
- package/core/src/date-time/utils.d.ts +1 -0
- package/core/src/kbd-constants.d.ts +1 -0
- package/core/src/watch.d.ts +41 -0
- package/fesm2022/radix-ng-primitives-calendar.mjs +941 -0
- package/fesm2022/radix-ng-primitives-calendar.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-core.mjs +544 -2
- package/fesm2022/radix-ng-primitives-core.mjs.map +1 -1
- package/hover-card/src/hover-card-root.directive.d.ts +4 -4
- package/package.json +5 -1
- package/popover/src/popover-root.directive.d.ts +4 -4
- package/tooltip/src/tooltip-root.directive.d.ts +4 -4
@@ -0,0 +1,941 @@
|
|
1
|
+
import * as i0 from '@angular/core';
|
2
|
+
import { InjectionToken, inject, ElementRef, input, computed, Directive, signal, model, booleanAttribute, linkedSignal, effect, forwardRef, NgModule } from '@angular/core';
|
3
|
+
import { isToday, getLocalTimeZone, isSameMonth, isSameDay, isEqualMonth, isEqualDay } from '@internationalized/date';
|
4
|
+
import * as kbd from '@radix-ng/primitives/core';
|
5
|
+
import { toDate, getDaysInMonth, createFormatter, createMonths, isAfter, isBefore, watch, getDefaultDate } from '@radix-ng/primitives/core';
|
6
|
+
|
7
|
+
const CALENDAR_ROOT_CONTEXT = new InjectionToken('CalendarRootContext');
|
8
|
+
function injectCalendarRootContext() {
|
9
|
+
return inject(CALENDAR_ROOT_CONTEXT);
|
10
|
+
}
|
11
|
+
|
12
|
+
class RdxCalendarCellTriggerDirective {
|
13
|
+
constructor() {
|
14
|
+
this.rootContext = injectCalendarRootContext();
|
15
|
+
this.elementRef = inject((ElementRef));
|
16
|
+
/**
|
17
|
+
* The date value provided to the cell trigger
|
18
|
+
*/
|
19
|
+
this.day = input();
|
20
|
+
/**
|
21
|
+
* The month in which the cell is rendered
|
22
|
+
*/
|
23
|
+
this.month = input();
|
24
|
+
/**
|
25
|
+
* Current day
|
26
|
+
*/
|
27
|
+
this.dayValue = computed(() => this.day()?.day.toLocaleString());
|
28
|
+
/**
|
29
|
+
* Current today state
|
30
|
+
*/
|
31
|
+
this.isDateToday = computed(() => {
|
32
|
+
return isToday(this.day(), getLocalTimeZone());
|
33
|
+
});
|
34
|
+
/**
|
35
|
+
* Current selected state
|
36
|
+
*/
|
37
|
+
this.isSelectedDate = computed(() => this.rootContext.isDateSelected(this.day()));
|
38
|
+
this.isDisabled = computed(() => this.rootContext.isDateDisabled(this.day()));
|
39
|
+
this.isOutsideView = computed(() => {
|
40
|
+
return !isSameMonth(this.day(), this.month());
|
41
|
+
});
|
42
|
+
this.isFocusedDate = computed(() => {
|
43
|
+
return !this.rootContext.disabled() && isSameDay(this.day(), this.rootContext.placeholder());
|
44
|
+
});
|
45
|
+
this.isUnavailable = computed(() => this.rootContext.isDateUnavailable?.(this.day()) ?? false);
|
46
|
+
this.labelText = computed(() => {
|
47
|
+
return this.rootContext.formatter.custom(toDate(this.day()), {
|
48
|
+
weekday: 'long',
|
49
|
+
month: 'long',
|
50
|
+
day: 'numeric',
|
51
|
+
year: 'numeric'
|
52
|
+
});
|
53
|
+
});
|
54
|
+
/**
|
55
|
+
* @ignore
|
56
|
+
*/
|
57
|
+
this.SELECTOR = '[data-rdx-calendar-cell-trigger]:not([data-outside-view]):not([data-outside-visible-view])';
|
58
|
+
}
|
59
|
+
ngAfterViewInit() {
|
60
|
+
this.currentElement = this.elementRef.nativeElement;
|
61
|
+
}
|
62
|
+
onClick() {
|
63
|
+
this.changeDate(this.day());
|
64
|
+
}
|
65
|
+
onArrowKey(event) {
|
66
|
+
const code = event.code;
|
67
|
+
if (![
|
68
|
+
kbd.ARROW_RIGHT,
|
69
|
+
kbd.ARROW_LEFT,
|
70
|
+
kbd.ARROW_UP,
|
71
|
+
kbd.ARROW_DOWN,
|
72
|
+
kbd.ENTER,
|
73
|
+
kbd.SPACE_CODE
|
74
|
+
].includes(code)) {
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
event.preventDefault();
|
78
|
+
event.stopPropagation();
|
79
|
+
const indexIncrementation = 7;
|
80
|
+
const sign = this.rootContext.dir() === 'rtl' ? -1 : 1;
|
81
|
+
switch (code) {
|
82
|
+
case kbd.ARROW_RIGHT:
|
83
|
+
this.shiftFocus(this.currentElement, sign);
|
84
|
+
break;
|
85
|
+
case kbd.ARROW_LEFT:
|
86
|
+
this.shiftFocus(this.currentElement, -sign);
|
87
|
+
break;
|
88
|
+
case kbd.ARROW_UP:
|
89
|
+
this.shiftFocus(this.currentElement, -indexIncrementation);
|
90
|
+
break;
|
91
|
+
case kbd.ARROW_DOWN:
|
92
|
+
this.shiftFocus(this.currentElement, indexIncrementation);
|
93
|
+
break;
|
94
|
+
case kbd.ENTER:
|
95
|
+
case kbd.SPACE_CODE:
|
96
|
+
this.changeDate(this.day());
|
97
|
+
}
|
98
|
+
}
|
99
|
+
shiftFocus(node, add) {
|
100
|
+
const parentElement = this.rootContext.currentElement;
|
101
|
+
const allCollectionItems = this.getSelectableCells(parentElement);
|
102
|
+
if (!allCollectionItems.length)
|
103
|
+
return;
|
104
|
+
const index = allCollectionItems.indexOf(node);
|
105
|
+
const newIndex = index + add;
|
106
|
+
if (newIndex >= 0 && newIndex < allCollectionItems.length) {
|
107
|
+
if (allCollectionItems[newIndex].hasAttribute('data-disabled')) {
|
108
|
+
this.shiftFocus(allCollectionItems[newIndex], add);
|
109
|
+
}
|
110
|
+
allCollectionItems[newIndex].focus();
|
111
|
+
return;
|
112
|
+
}
|
113
|
+
if (newIndex < 0) {
|
114
|
+
if (!this.rootContext.prevPage)
|
115
|
+
return;
|
116
|
+
this.rootContext.prevPage();
|
117
|
+
setTimeout(() => {
|
118
|
+
const newCollectionItems = this.getSelectableCells(parentElement);
|
119
|
+
if (!newCollectionItems.length)
|
120
|
+
return;
|
121
|
+
if (!this.rootContext.pagedNavigation && this.rootContext.numberOfMonths() > 1) {
|
122
|
+
// Placeholder is set to the first month of the new page
|
123
|
+
const numberOfDays = getDaysInMonth(this.rootContext.placeholder());
|
124
|
+
const computedIndex = numberOfDays - Math.abs(newIndex);
|
125
|
+
if (newCollectionItems[computedIndex].hasAttribute('data-disabled')) {
|
126
|
+
this.shiftFocus(newCollectionItems[computedIndex], add);
|
127
|
+
}
|
128
|
+
newCollectionItems[computedIndex].focus();
|
129
|
+
return;
|
130
|
+
}
|
131
|
+
const computedIndex = newCollectionItems.length - Math.abs(newIndex);
|
132
|
+
if (newCollectionItems[computedIndex].hasAttribute('data-disabled')) {
|
133
|
+
this.shiftFocus(newCollectionItems[computedIndex], add);
|
134
|
+
}
|
135
|
+
newCollectionItems[computedIndex].focus();
|
136
|
+
});
|
137
|
+
}
|
138
|
+
if (newIndex >= allCollectionItems.length) {
|
139
|
+
if (!this.rootContext.nextPage)
|
140
|
+
return;
|
141
|
+
this.rootContext.nextPage();
|
142
|
+
setTimeout(() => {
|
143
|
+
const newCollectionItems = this.getSelectableCells(parentElement);
|
144
|
+
if (!newCollectionItems.length)
|
145
|
+
return;
|
146
|
+
if (!this.rootContext.pagedNavigation && this.rootContext.numberOfMonths() > 1) {
|
147
|
+
const numberOfDays = getDaysInMonth(this.rootContext.placeholder().add({ months: this.rootContext.numberOfMonths() - 1 }));
|
148
|
+
const computedIndex = newIndex - allCollectionItems.length + (newCollectionItems.length - numberOfDays);
|
149
|
+
if (newCollectionItems[computedIndex].hasAttribute('data-disabled')) {
|
150
|
+
this.shiftFocus(newCollectionItems[computedIndex], add);
|
151
|
+
}
|
152
|
+
newCollectionItems[computedIndex].focus();
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
const computedIndex = newIndex - allCollectionItems.length;
|
156
|
+
if (newCollectionItems[computedIndex].hasAttribute('data-disabled')) {
|
157
|
+
this.shiftFocus(newCollectionItems[computedIndex], add);
|
158
|
+
}
|
159
|
+
newCollectionItems[computedIndex].focus();
|
160
|
+
});
|
161
|
+
}
|
162
|
+
}
|
163
|
+
/**
|
164
|
+
* @ignore
|
165
|
+
*/
|
166
|
+
getSelectableCells(calendar) {
|
167
|
+
return Array.from(calendar.querySelectorAll(this.SELECTOR)) ?? [];
|
168
|
+
}
|
169
|
+
/**
|
170
|
+
* @ignore
|
171
|
+
*/
|
172
|
+
changeDate(date) {
|
173
|
+
this.rootContext.onDateChange(date);
|
174
|
+
}
|
175
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarCellTriggerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
176
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.4", type: RdxCalendarCellTriggerDirective, isStandalone: true, selector: "[rdxCalendarCellTrigger]", inputs: { day: { classPropertyName: "day", publicName: "day", isSignal: true, isRequired: false, transformFunction: null }, month: { classPropertyName: "month", publicName: "month", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "button" }, listeners: { "click": "onClick()", "keydown": "onArrowKey($event)" }, properties: { "attr.aria-label": "labelText()", "attr.aria-disabled": "isDisabled() || isUnavailable() ? true : undefined", "attr.data-rdx-calendar-cell-trigger": "\"\"", "attr.tabindex": "isFocusedDate() ? 0 : isOutsideView() || isDisabled() ? undefined : -1", "attr.data-value": "day()?.toString()", "attr.data-disabled": "isDisabled() ? \"\" : undefined", "attr.data-today": "isDateToday() ? \"\" : undefined", "attr.data-outside-view": "isOutsideView() ? \"\" : undefined", "attr.data-selected": "isSelectedDate() ? \"\" : undefined", "attr.data-unavailable": "isUnavailable() ? \"\" : undefined", "attr.data-focus": "isFocusedDate() ? \"\" : undefined" } }, exportAs: ["rdxCalendarCellTrigger"], ngImport: i0 }); }
|
177
|
+
}
|
178
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarCellTriggerDirective, decorators: [{
|
179
|
+
type: Directive,
|
180
|
+
args: [{
|
181
|
+
selector: '[rdxCalendarCellTrigger]',
|
182
|
+
exportAs: 'rdxCalendarCellTrigger',
|
183
|
+
host: {
|
184
|
+
role: 'button',
|
185
|
+
'[attr.aria-label]': 'labelText()',
|
186
|
+
'[attr.aria-disabled]': 'isDisabled() || isUnavailable() ? true : undefined',
|
187
|
+
'[attr.data-rdx-calendar-cell-trigger]': '""',
|
188
|
+
'[attr.tabindex]': 'isFocusedDate() ? 0 : isOutsideView() || isDisabled() ? undefined : -1',
|
189
|
+
'[attr.data-value]': 'day()?.toString()',
|
190
|
+
'[attr.data-disabled]': 'isDisabled() ? "" : undefined',
|
191
|
+
'[attr.data-today]': 'isDateToday() ? "" : undefined',
|
192
|
+
'[attr.data-outside-view]': 'isOutsideView() ? "" : undefined',
|
193
|
+
'[attr.data-selected]': 'isSelectedDate() ? "" : undefined',
|
194
|
+
'[attr.data-unavailable]': 'isUnavailable() ? "" : undefined',
|
195
|
+
'[attr.data-focus]': 'isFocusedDate() ? "" : undefined',
|
196
|
+
'(click)': 'onClick()',
|
197
|
+
'(keydown)': 'onArrowKey($event)'
|
198
|
+
}
|
199
|
+
}]
|
200
|
+
}] });
|
201
|
+
|
202
|
+
class RdxCalendarCellDirective {
|
203
|
+
constructor() {
|
204
|
+
this.rootContext = injectCalendarRootContext();
|
205
|
+
/**
|
206
|
+
* The date of the cell
|
207
|
+
*/
|
208
|
+
this.date = input();
|
209
|
+
}
|
210
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarCellDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
211
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.4", type: RdxCalendarCellDirective, isStandalone: true, selector: "td[rdxCalendarCell]", inputs: { date: { classPropertyName: "date", publicName: "date", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "gridcell" }, properties: { "attr.aria-selected": "rootContext.isDateSelected?.(date()!) ? true : undefined", "attr.aria-disabled": "rootContext.isDateSelected?.(date()!) || rootContext.isDateUnavailable?.(date()!)", "attr.data-disabled": "rootContext.isDateSelected?.(date()!) ? \"\" : undefined" } }, ngImport: i0 }); }
|
212
|
+
}
|
213
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarCellDirective, decorators: [{
|
214
|
+
type: Directive,
|
215
|
+
args: [{
|
216
|
+
selector: 'td[rdxCalendarCell]',
|
217
|
+
host: {
|
218
|
+
role: 'gridcell',
|
219
|
+
'[attr.aria-selected]': 'rootContext.isDateSelected?.(date()!) ? true : undefined',
|
220
|
+
'[attr.aria-disabled]': 'rootContext.isDateSelected?.(date()!) || rootContext.isDateUnavailable?.(date()!)',
|
221
|
+
'[attr.data-disabled]': 'rootContext.isDateSelected?.(date()!) ? "" : undefined'
|
222
|
+
}
|
223
|
+
}]
|
224
|
+
}] });
|
225
|
+
|
226
|
+
class RdxCalendarGridBodyDirective {
|
227
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarGridBodyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
228
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.4", type: RdxCalendarGridBodyDirective, isStandalone: true, selector: "tbody[rdxCalendarGridBody]", ngImport: i0 }); }
|
229
|
+
}
|
230
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarGridBodyDirective, decorators: [{
|
231
|
+
type: Directive,
|
232
|
+
args: [{
|
233
|
+
selector: 'tbody[rdxCalendarGridBody]'
|
234
|
+
}]
|
235
|
+
}] });
|
236
|
+
|
237
|
+
class RdxCalendarGridHeadDirective {
|
238
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarGridHeadDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
239
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.4", type: RdxCalendarGridHeadDirective, isStandalone: true, selector: "thead[rdxCalendarGridHead]", host: { properties: { "attr.aria-hidden": "true" } }, ngImport: i0 }); }
|
240
|
+
}
|
241
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarGridHeadDirective, decorators: [{
|
242
|
+
type: Directive,
|
243
|
+
args: [{
|
244
|
+
selector: 'thead[rdxCalendarGridHead]',
|
245
|
+
host: {
|
246
|
+
'[attr.aria-hidden]': 'true'
|
247
|
+
}
|
248
|
+
}]
|
249
|
+
}] });
|
250
|
+
|
251
|
+
class RdxCalendarGridRowDirective {
|
252
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarGridRowDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
253
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.4", type: RdxCalendarGridRowDirective, isStandalone: true, selector: "tr[rdxCalendarGridRow]", ngImport: i0 }); }
|
254
|
+
}
|
255
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarGridRowDirective, decorators: [{
|
256
|
+
type: Directive,
|
257
|
+
args: [{
|
258
|
+
selector: 'tr[rdxCalendarGridRow]'
|
259
|
+
}]
|
260
|
+
}] });
|
261
|
+
|
262
|
+
class RdxCalendarGridDirective {
|
263
|
+
constructor() {
|
264
|
+
this.rootContext = injectCalendarRootContext();
|
265
|
+
this.disabled = computed(() => (this.rootContext.disabled() ? true : undefined));
|
266
|
+
this.readonly = computed(() => (this.rootContext.readonly ? true : undefined));
|
267
|
+
}
|
268
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarGridDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
269
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.4", type: RdxCalendarGridDirective, isStandalone: true, selector: "table[rdxCalendarGrid]", host: { attributes: { "tabindex": "-1", "role": "grid" }, properties: { "attr.aria-readonly": "readonly()", "attr.aria-disabled": "disabled()", "attr.data-readonly": "readonly() && \"\"", "attr.data-disabled": "disabled() && \"\"" } }, ngImport: i0 }); }
|
270
|
+
}
|
271
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarGridDirective, decorators: [{
|
272
|
+
type: Directive,
|
273
|
+
args: [{
|
274
|
+
selector: 'table[rdxCalendarGrid]',
|
275
|
+
host: {
|
276
|
+
tabindex: '-1',
|
277
|
+
role: 'grid',
|
278
|
+
'[attr.aria-readonly]': 'readonly()',
|
279
|
+
'[attr.aria-disabled]': 'disabled()',
|
280
|
+
'[attr.data-readonly]': 'readonly() && ""',
|
281
|
+
'[attr.data-disabled]': 'disabled() && ""'
|
282
|
+
}
|
283
|
+
}]
|
284
|
+
}] });
|
285
|
+
|
286
|
+
class RdxCalendarHeadCellDirective {
|
287
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarHeadCellDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
288
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.4", type: RdxCalendarHeadCellDirective, isStandalone: true, selector: "th[rdxCalendarHeadCell]", ngImport: i0 }); }
|
289
|
+
}
|
290
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarHeadCellDirective, decorators: [{
|
291
|
+
type: Directive,
|
292
|
+
args: [{
|
293
|
+
selector: 'th[rdxCalendarHeadCell]'
|
294
|
+
}]
|
295
|
+
}] });
|
296
|
+
|
297
|
+
class RdxCalendarHeaderDirective {
|
298
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarHeaderDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
299
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.4", type: RdxCalendarHeaderDirective, isStandalone: true, selector: "div[rdxCalendarHeader]", ngImport: i0 }); }
|
300
|
+
}
|
301
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarHeaderDirective, decorators: [{
|
302
|
+
type: Directive,
|
303
|
+
args: [{
|
304
|
+
selector: 'div[rdxCalendarHeader]'
|
305
|
+
}]
|
306
|
+
}] });
|
307
|
+
|
308
|
+
class RdxCalendarHeadingDirective {
|
309
|
+
constructor() {
|
310
|
+
this.rootContext = injectCalendarRootContext();
|
311
|
+
this.headingValue = computed(() => this.rootContext.headingValue());
|
312
|
+
}
|
313
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarHeadingDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
314
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.4", type: RdxCalendarHeadingDirective, isStandalone: true, selector: "div[rdxCalendarHeading]", host: { properties: { "attr.data-disabled": "rootContext.disabled() ? \"\" : undefined" } }, exportAs: ["rdxCalendarHeading"], ngImport: i0 }); }
|
315
|
+
}
|
316
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarHeadingDirective, decorators: [{
|
317
|
+
type: Directive,
|
318
|
+
args: [{
|
319
|
+
selector: 'div[rdxCalendarHeading]',
|
320
|
+
exportAs: 'rdxCalendarHeading',
|
321
|
+
host: {
|
322
|
+
'[attr.data-disabled]': 'rootContext.disabled() ? "" : undefined'
|
323
|
+
}
|
324
|
+
}]
|
325
|
+
}] });
|
326
|
+
|
327
|
+
class RdxCalendarNextDirective {
|
328
|
+
constructor() {
|
329
|
+
this.rootContext = injectCalendarRootContext();
|
330
|
+
/**
|
331
|
+
* The function to be used for the `next page`. Overwrites the nextPage function set on the `CalendarRoot`.
|
332
|
+
*/
|
333
|
+
this.nextPage = input();
|
334
|
+
/**
|
335
|
+
* @ignore
|
336
|
+
*/
|
337
|
+
this.disabled = computed(() => this.rootContext.disabled() || this.rootContext.isNextButtonDisabled(this.nextPage()));
|
338
|
+
}
|
339
|
+
onClick() {
|
340
|
+
this.rootContext.nextPage(this.nextPage());
|
341
|
+
}
|
342
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarNextDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
343
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.4", type: RdxCalendarNextDirective, isStandalone: true, selector: "button[rdxCalendarNext]", inputs: { nextPage: { classPropertyName: "nextPage", publicName: "nextPage", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "aria-label": "Next page" }, listeners: { "click": "onClick()" }, properties: { "disabled": "disabled()", "attr.data-disabled": "disabled() ? \"\" : undefined", "attr.aria-disabled": "disabled() ? \"\" : undefined" } }, exportAs: ["rdxCalendarNext"], ngImport: i0 }); }
|
344
|
+
}
|
345
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarNextDirective, decorators: [{
|
346
|
+
type: Directive,
|
347
|
+
args: [{
|
348
|
+
selector: 'button[rdxCalendarNext]',
|
349
|
+
exportAs: 'rdxCalendarNext',
|
350
|
+
host: {
|
351
|
+
'(click)': 'onClick()',
|
352
|
+
'[disabled]': 'disabled()',
|
353
|
+
'[attr.data-disabled]': 'disabled() ? "" : undefined',
|
354
|
+
'[attr.aria-disabled]': 'disabled() ? "" : undefined',
|
355
|
+
'aria-label': 'Next page'
|
356
|
+
}
|
357
|
+
}]
|
358
|
+
}] });
|
359
|
+
|
360
|
+
class RdxCalendarPrevDirective {
|
361
|
+
constructor() {
|
362
|
+
this.rootContext = injectCalendarRootContext();
|
363
|
+
/**
|
364
|
+
* The function to be used for the `prev page`. Overwrites the prevPage function set on the `CalendarRoot`.
|
365
|
+
*/
|
366
|
+
this.prevPage = input();
|
367
|
+
/**
|
368
|
+
* @ignore
|
369
|
+
*/
|
370
|
+
this.disabled = computed(() => this.rootContext.disabled() || this.rootContext.isNextButtonDisabled(this.prevPage()));
|
371
|
+
}
|
372
|
+
onClick() {
|
373
|
+
this.rootContext.prevPage(this.prevPage());
|
374
|
+
}
|
375
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarPrevDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
376
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.4", type: RdxCalendarPrevDirective, isStandalone: true, selector: "button[rdxCalendarPrev]", inputs: { prevPage: { classPropertyName: "prevPage", publicName: "prevPage", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "aria-label": "Previous page" }, listeners: { "click": "onClick()" }, properties: { "disabled": "disabled()", "attr.data-disabled": "disabled() ? \"\" : undefined", "attr.aria-disabled": "disabled() ? \"\" : undefined" } }, exportAs: ["rdxCalendarPrev"], ngImport: i0 }); }
|
377
|
+
}
|
378
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarPrevDirective, decorators: [{
|
379
|
+
type: Directive,
|
380
|
+
args: [{
|
381
|
+
selector: 'button[rdxCalendarPrev]',
|
382
|
+
exportAs: 'rdxCalendarPrev',
|
383
|
+
host: {
|
384
|
+
'(click)': 'onClick()',
|
385
|
+
'[disabled]': 'disabled()',
|
386
|
+
'[attr.data-disabled]': 'disabled() ? "" : undefined',
|
387
|
+
'[attr.aria-disabled]': 'disabled() ? "" : undefined',
|
388
|
+
'aria-label': 'Previous page'
|
389
|
+
}
|
390
|
+
}]
|
391
|
+
}] });
|
392
|
+
|
393
|
+
function calendarState(props) {
|
394
|
+
function isDateSelected(dateObj) {
|
395
|
+
const currentValue = props.date(); // signal read
|
396
|
+
if (Array.isArray(currentValue)) {
|
397
|
+
return currentValue.some((d) => isSameDay(d, dateObj));
|
398
|
+
}
|
399
|
+
else if (!currentValue) {
|
400
|
+
return false;
|
401
|
+
}
|
402
|
+
else {
|
403
|
+
return isSameDay(currentValue, dateObj);
|
404
|
+
}
|
405
|
+
}
|
406
|
+
const isInvalid = computed(() => {
|
407
|
+
const currentValue = props.date();
|
408
|
+
if (Array.isArray(currentValue)) {
|
409
|
+
if (!currentValue.length) {
|
410
|
+
return false;
|
411
|
+
}
|
412
|
+
for (const dateObj of currentValue) {
|
413
|
+
if (props.isDateDisabled?.(dateObj))
|
414
|
+
return true;
|
415
|
+
if (props.isDateUnavailable?.(dateObj))
|
416
|
+
return true;
|
417
|
+
}
|
418
|
+
}
|
419
|
+
else {
|
420
|
+
if (!currentValue) {
|
421
|
+
return false;
|
422
|
+
}
|
423
|
+
if (props.isDateDisabled?.(currentValue))
|
424
|
+
return true;
|
425
|
+
if (props.isDateUnavailable?.(currentValue))
|
426
|
+
return true;
|
427
|
+
}
|
428
|
+
return false;
|
429
|
+
});
|
430
|
+
return {
|
431
|
+
isDateSelected,
|
432
|
+
isInvalid
|
433
|
+
};
|
434
|
+
}
|
435
|
+
function handleNextDisabled(lastPeriodInView, nextPageFunc) {
|
436
|
+
const firstPeriodOfNextPage = nextPageFunc(lastPeriodInView);
|
437
|
+
const diff = firstPeriodOfNextPage.compare(lastPeriodInView);
|
438
|
+
const duration = {};
|
439
|
+
if (diff >= 7)
|
440
|
+
duration.day = 1;
|
441
|
+
if (diff >= getDaysInMonth(lastPeriodInView))
|
442
|
+
duration.month = 1;
|
443
|
+
return firstPeriodOfNextPage.set({ ...duration });
|
444
|
+
}
|
445
|
+
function handlePrevDisabled(firstPeriodInView, prevPageFunc) {
|
446
|
+
const lastPeriodOfPrevPage = prevPageFunc(firstPeriodInView);
|
447
|
+
const diff = firstPeriodInView.compare(lastPeriodOfPrevPage);
|
448
|
+
const duration = {};
|
449
|
+
if (diff >= 7)
|
450
|
+
duration.day = 35;
|
451
|
+
if (diff >= getDaysInMonth(firstPeriodInView))
|
452
|
+
duration.month = 13;
|
453
|
+
return lastPeriodOfPrevPage.set({ ...duration });
|
454
|
+
}
|
455
|
+
function handleNextPage(date, nextPageFunc) {
|
456
|
+
return nextPageFunc(date);
|
457
|
+
}
|
458
|
+
function handlePrevPage(date, prevPageFunc) {
|
459
|
+
return prevPageFunc(date);
|
460
|
+
}
|
461
|
+
function calendar(props) {
|
462
|
+
const formatter = createFormatter(props.locale());
|
463
|
+
const headingFormatOptions = computed(() => {
|
464
|
+
const options = {
|
465
|
+
calendar: props.placeholder().calendar.identifier
|
466
|
+
};
|
467
|
+
if (props.placeholder().calendar.identifier === 'gregory' && props.placeholder().era === 'BC') {
|
468
|
+
options.era = 'short';
|
469
|
+
}
|
470
|
+
return options;
|
471
|
+
});
|
472
|
+
const month = signal(createMonths({
|
473
|
+
dateObj: props.placeholder(),
|
474
|
+
weekStartsOn: props.weekStartsOn(),
|
475
|
+
locale: props.locale(),
|
476
|
+
fixedWeeks: props.fixedWeeks(),
|
477
|
+
numberOfMonths: props.numberOfMonths()
|
478
|
+
}));
|
479
|
+
const visibleView = computed(() => {
|
480
|
+
return month().map((month) => month.value);
|
481
|
+
});
|
482
|
+
function isOutsideVisibleView(date) {
|
483
|
+
return !visibleView().some((month) => isEqualMonth(date, month));
|
484
|
+
}
|
485
|
+
const isNextButtonDisabled = (nextPageFunc) => {
|
486
|
+
if (!props.maxValue() || !month().length)
|
487
|
+
return false;
|
488
|
+
if (props.disabled())
|
489
|
+
return true;
|
490
|
+
const lastPeriodInView = month()[month().length - 1].value;
|
491
|
+
if (!nextPageFunc && !props.nextPage()) {
|
492
|
+
const firstPeriodOfNextPage = lastPeriodInView.add({ months: 1 }).set({ day: 1 });
|
493
|
+
return isAfter(firstPeriodOfNextPage, props.maxValue());
|
494
|
+
}
|
495
|
+
const firstPeriodOfNextPage = handleNextDisabled(lastPeriodInView, nextPageFunc || props.nextPage());
|
496
|
+
return isAfter(firstPeriodOfNextPage, props.maxValue());
|
497
|
+
};
|
498
|
+
const isPrevButtonDisabled = (prevPageFunc) => {
|
499
|
+
if (!props.minValue() || !month().length)
|
500
|
+
return false;
|
501
|
+
if (props.disabled())
|
502
|
+
return true;
|
503
|
+
const firstPeriodInView = month()[0].value;
|
504
|
+
if (!prevPageFunc && !props.prevPage()) {
|
505
|
+
const lastPeriodOfPrevPage = firstPeriodInView.subtract({ months: 1 }).set({ day: 35 });
|
506
|
+
return isBefore(lastPeriodOfPrevPage, props.minValue());
|
507
|
+
}
|
508
|
+
const lastPeriodOfPrevPage = handlePrevDisabled(firstPeriodInView, prevPageFunc || props.prevPage());
|
509
|
+
return isBefore(lastPeriodOfPrevPage, props.minValue());
|
510
|
+
};
|
511
|
+
const nextPage = (nextPageFunc) => {
|
512
|
+
const firstDate = month()[0].value;
|
513
|
+
if (!nextPageFunc && !props.nextPage()) {
|
514
|
+
const newDate = firstDate.add({ months: props.pagedNavigation() ? props.numberOfMonths() : 1 });
|
515
|
+
const newMonth = createMonths({
|
516
|
+
dateObj: newDate,
|
517
|
+
weekStartsOn: props.weekStartsOn(),
|
518
|
+
locale: props.locale(),
|
519
|
+
fixedWeeks: props.fixedWeeks(),
|
520
|
+
numberOfMonths: props.numberOfMonths()
|
521
|
+
});
|
522
|
+
month.set(newMonth);
|
523
|
+
props.placeholder.set(newMonth[0].value.set({ day: 1 }));
|
524
|
+
return;
|
525
|
+
}
|
526
|
+
const newDate = handleNextPage(firstDate, nextPageFunc || props.nextPage());
|
527
|
+
const newMonth = createMonths({
|
528
|
+
dateObj: newDate,
|
529
|
+
weekStartsOn: props.weekStartsOn(),
|
530
|
+
locale: props.locale(),
|
531
|
+
fixedWeeks: props.fixedWeeks(),
|
532
|
+
numberOfMonths: props.numberOfMonths()
|
533
|
+
});
|
534
|
+
month.set(newMonth);
|
535
|
+
const duration = {};
|
536
|
+
if (!nextPageFunc) {
|
537
|
+
const diff = newMonth[0].value.compare(firstDate);
|
538
|
+
if (diff >= getDaysInMonth(firstDate)) {
|
539
|
+
duration.day = 1;
|
540
|
+
}
|
541
|
+
if (diff >= 365) {
|
542
|
+
duration.month = 1;
|
543
|
+
}
|
544
|
+
}
|
545
|
+
props.placeholder.set(newMonth[0].value.set({ ...duration }));
|
546
|
+
};
|
547
|
+
const prevPage = (prevPageFunc) => {
|
548
|
+
const firstDate = month()[0].value;
|
549
|
+
if (!prevPageFunc && !props.prevPage()) {
|
550
|
+
const newDate = firstDate.subtract({ months: props.pagedNavigation() ? props.numberOfMonths() : 1 });
|
551
|
+
const newMonth = createMonths({
|
552
|
+
dateObj: newDate,
|
553
|
+
weekStartsOn: props.weekStartsOn(),
|
554
|
+
locale: props.locale(),
|
555
|
+
fixedWeeks: props.fixedWeeks(),
|
556
|
+
numberOfMonths: props.numberOfMonths()
|
557
|
+
});
|
558
|
+
month.set(newMonth);
|
559
|
+
props.placeholder.set(newMonth[0].value.set({ day: 1 }));
|
560
|
+
return;
|
561
|
+
}
|
562
|
+
const newDate = handlePrevPage(firstDate, prevPageFunc || props.prevPage());
|
563
|
+
const newMonth = createMonths({
|
564
|
+
dateObj: newDate,
|
565
|
+
weekStartsOn: props.weekStartsOn(),
|
566
|
+
locale: props.locale(),
|
567
|
+
fixedWeeks: props.fixedWeeks(),
|
568
|
+
numberOfMonths: props.numberOfMonths()
|
569
|
+
});
|
570
|
+
month.set(newMonth);
|
571
|
+
const duration = {};
|
572
|
+
// Do not adjust the placeholder if the prevPageFunc is defined (overwrite)
|
573
|
+
if (!prevPageFunc) {
|
574
|
+
const diff = firstDate.compare(newMonth[0].value);
|
575
|
+
if (diff >= getDaysInMonth(firstDate))
|
576
|
+
duration.day = 1;
|
577
|
+
if (diff >= 365)
|
578
|
+
duration.month = 1;
|
579
|
+
}
|
580
|
+
props.placeholder.set(newMonth[0].value.set({ ...duration }));
|
581
|
+
};
|
582
|
+
function isDateDisabled(dateObj) {
|
583
|
+
if (props.isDateDisabled?.()?.(dateObj) || props.disabled())
|
584
|
+
return true;
|
585
|
+
if (props.maxValue() && isAfter(dateObj, props.maxValue()))
|
586
|
+
return true;
|
587
|
+
if (props.minValue() && isBefore(dateObj, props.minValue()))
|
588
|
+
return true;
|
589
|
+
return false;
|
590
|
+
}
|
591
|
+
const isDateUnavailable = (date) => {
|
592
|
+
return !!props.isDateUnavailable?.()?.(date);
|
593
|
+
};
|
594
|
+
const weekdays = computed(() => {
|
595
|
+
if (!month().length)
|
596
|
+
return [];
|
597
|
+
return month()[0].weeks[0].map((date) => {
|
598
|
+
return formatter.dayOfWeek(toDate(date), props.weekdayFormat());
|
599
|
+
});
|
600
|
+
});
|
601
|
+
watch([props.placeholder], ([placeholder]) => {
|
602
|
+
if (visibleView().some((month) => isEqualMonth(month, placeholder))) {
|
603
|
+
return;
|
604
|
+
}
|
605
|
+
month.set(createMonths({
|
606
|
+
dateObj: placeholder,
|
607
|
+
weekStartsOn: props.weekStartsOn(),
|
608
|
+
locale: props.locale(),
|
609
|
+
fixedWeeks: props.fixedWeeks(),
|
610
|
+
numberOfMonths: props.numberOfMonths()
|
611
|
+
}));
|
612
|
+
});
|
613
|
+
watch([props.locale, props.weekStartsOn, props.fixedWeeks, props.numberOfMonths], ([locale, weekStartsOn, fixedWeeks, numberOfMonths]) => {
|
614
|
+
month.set(createMonths({
|
615
|
+
dateObj: props.placeholder(),
|
616
|
+
weekStartsOn: weekStartsOn,
|
617
|
+
locale: locale,
|
618
|
+
fixedWeeks: fixedWeeks,
|
619
|
+
numberOfMonths: numberOfMonths
|
620
|
+
}));
|
621
|
+
});
|
622
|
+
const headingValue = computed(() => {
|
623
|
+
if (!month().length) {
|
624
|
+
return '';
|
625
|
+
}
|
626
|
+
if (props.locale() !== formatter.getLocale())
|
627
|
+
formatter.setLocale(props.locale());
|
628
|
+
if (month().length === 1) {
|
629
|
+
const _month = month()[0].value;
|
630
|
+
return `${formatter.fullMonthAndYear(toDate(_month), headingFormatOptions())}`;
|
631
|
+
}
|
632
|
+
const startMonth = toDate(month()[0].value);
|
633
|
+
const endMonth = toDate(month()[month().length - 1].value);
|
634
|
+
const startMonthName = formatter.fullMonth(startMonth, headingFormatOptions());
|
635
|
+
const endMonthName = formatter.fullMonth(endMonth, headingFormatOptions());
|
636
|
+
const startMonthYear = formatter.fullYear(startMonth, headingFormatOptions());
|
637
|
+
const endMonthYear = formatter.fullYear(endMonth, headingFormatOptions());
|
638
|
+
return startMonthYear === endMonthYear
|
639
|
+
? `${startMonthName} - ${endMonthName} ${endMonthYear}`
|
640
|
+
: `${startMonthName} ${startMonthYear} - ${endMonthName} ${endMonthYear}`;
|
641
|
+
});
|
642
|
+
const fullCalendarLabel = computed(() => `${props.calendarLabel() ?? 'Event Date'}, ${headingValue()}`);
|
643
|
+
return {
|
644
|
+
isDateDisabled,
|
645
|
+
isDateUnavailable,
|
646
|
+
isNextButtonDisabled,
|
647
|
+
isPrevButtonDisabled,
|
648
|
+
month,
|
649
|
+
weekdays,
|
650
|
+
visibleView,
|
651
|
+
isOutsideVisibleView,
|
652
|
+
formatter,
|
653
|
+
nextPage,
|
654
|
+
prevPage,
|
655
|
+
headingValue,
|
656
|
+
fullCalendarLabel
|
657
|
+
};
|
658
|
+
}
|
659
|
+
|
660
|
+
class RdxCalendarRootDirective {
|
661
|
+
constructor() {
|
662
|
+
this.elementRef = inject((ElementRef));
|
663
|
+
/**
|
664
|
+
* The controlled checked state of the calendar
|
665
|
+
*/
|
666
|
+
this.value = model();
|
667
|
+
/**
|
668
|
+
* The default placeholder date
|
669
|
+
*/
|
670
|
+
this.defaultPlaceholder = model();
|
671
|
+
this.locale = input('en');
|
672
|
+
this.defaultDate = getDefaultDate({
|
673
|
+
defaultPlaceholder: this.defaultPlaceholder(),
|
674
|
+
defaultValue: this.value(),
|
675
|
+
locale: this.locale()
|
676
|
+
});
|
677
|
+
/**
|
678
|
+
* The placeholder date, which is used to determine what month to display when no date is selected.
|
679
|
+
* This updates as the user navigates the calendar and can be used to programmatically control the calendar view
|
680
|
+
*/
|
681
|
+
this.placeholder = model(this.defaultPlaceholder() ?? this.defaultDate.copy());
|
682
|
+
this.multiple = input(false, { transform: booleanAttribute });
|
683
|
+
/**
|
684
|
+
* Whether to always display 6 weeks in the calendar
|
685
|
+
*/
|
686
|
+
this.fixedWeeks = input(false, { transform: booleanAttribute });
|
687
|
+
/**
|
688
|
+
* Whether the calendar is disabled
|
689
|
+
*/
|
690
|
+
this.disabled = input(false, { transform: booleanAttribute });
|
691
|
+
/**
|
692
|
+
* Whether to prevent the user from deselecting a date without selecting another date first
|
693
|
+
*/
|
694
|
+
this.preventDeselect = input(false, { transform: booleanAttribute });
|
695
|
+
/**
|
696
|
+
* The day of the week to start the calendar on
|
697
|
+
*/
|
698
|
+
this.weekStartsOn = input(1);
|
699
|
+
/**
|
700
|
+
* The number of months to display at once
|
701
|
+
*/
|
702
|
+
this.numberOfMonths = input(1);
|
703
|
+
/**
|
704
|
+
* The reading direction of the calendar when applicable.
|
705
|
+
*/
|
706
|
+
this.dir = input('ltr');
|
707
|
+
/**
|
708
|
+
* The minimum date that can be selected
|
709
|
+
*/
|
710
|
+
this.minValue = input();
|
711
|
+
/**
|
712
|
+
* The maximum date that can be selected
|
713
|
+
*/
|
714
|
+
this.maxValue = input();
|
715
|
+
/**
|
716
|
+
* The format to use for the weekday strings provided via the weekdays slot prop
|
717
|
+
*/
|
718
|
+
this.weekdayFormat = input('narrow');
|
719
|
+
/**
|
720
|
+
* The accessible label for the calendar
|
721
|
+
*/
|
722
|
+
this.calendarLabel = input();
|
723
|
+
/**
|
724
|
+
* Whether the calendar is readonly
|
725
|
+
*/
|
726
|
+
this.readonly = input(false, { transform: booleanAttribute });
|
727
|
+
/**
|
728
|
+
* This property causes the previous and next buttons to navigate by the number of months displayed at once, rather than one month
|
729
|
+
*/
|
730
|
+
this.pagedNavigation = input(false, { transform: booleanAttribute });
|
731
|
+
this.propsNextPage = input();
|
732
|
+
this.propsPrevPage = input();
|
733
|
+
/**
|
734
|
+
* A function that returns whether a date is disabled
|
735
|
+
*/
|
736
|
+
this.isDateDisabled = input();
|
737
|
+
/**
|
738
|
+
* A function that returns whether a date is unavailable
|
739
|
+
*/
|
740
|
+
this.isDateUnavailable = input();
|
741
|
+
this.initialFocus = input(false, { transform: booleanAttribute });
|
742
|
+
this.months = model();
|
743
|
+
/**
|
744
|
+
* The days of the week
|
745
|
+
*/
|
746
|
+
this.weekDays = model();
|
747
|
+
this.fixedWeeksRef = linkedSignal({
|
748
|
+
source: this.fixedWeeks,
|
749
|
+
computation: (value) => value
|
750
|
+
});
|
751
|
+
this.disabledRef = linkedSignal({
|
752
|
+
source: this.disabled,
|
753
|
+
computation: (value) => value
|
754
|
+
});
|
755
|
+
this.pagedNavigationRef = linkedSignal({
|
756
|
+
source: this.pagedNavigation,
|
757
|
+
computation: (value) => value
|
758
|
+
});
|
759
|
+
/**
|
760
|
+
* @ignore
|
761
|
+
*/
|
762
|
+
this.headingValue = signal('');
|
763
|
+
/**
|
764
|
+
* @ignore
|
765
|
+
*/
|
766
|
+
this.fullCalendarLabel = signal('');
|
767
|
+
this.calendar = calendar({
|
768
|
+
locale: this.locale,
|
769
|
+
placeholder: this.placeholder,
|
770
|
+
weekStartsOn: this.weekStartsOn,
|
771
|
+
fixedWeeks: this.fixedWeeksRef,
|
772
|
+
numberOfMonths: this.numberOfMonths,
|
773
|
+
minValue: this.minValue,
|
774
|
+
maxValue: this.maxValue,
|
775
|
+
disabled: this.disabledRef,
|
776
|
+
weekdayFormat: this.weekdayFormat,
|
777
|
+
pagedNavigation: this.pagedNavigationRef,
|
778
|
+
isDateDisabled: this.isDateDisabled,
|
779
|
+
isDateUnavailable: this.isDateUnavailable,
|
780
|
+
calendarLabel: this.calendarLabel,
|
781
|
+
nextPage: this.propsNextPage,
|
782
|
+
prevPage: this.propsPrevPage
|
783
|
+
});
|
784
|
+
this.nextPage = this.calendar.nextPage;
|
785
|
+
this.prevPage = this.calendar.prevPage;
|
786
|
+
this.isOutsideVisibleView = this.calendar.isOutsideVisibleView;
|
787
|
+
this.isNextButtonDisabled = this.calendar.isNextButtonDisabled;
|
788
|
+
this.isPrevButtonDisabled = this.calendar.isPrevButtonDisabled;
|
789
|
+
this.formatter = this.calendar.formatter;
|
790
|
+
effect(() => {
|
791
|
+
this.months.set(this.calendar.month());
|
792
|
+
this.weekDays.set(this.calendar.weekdays());
|
793
|
+
this.fullCalendarLabel.set(this.calendar.fullCalendarLabel());
|
794
|
+
this.headingValue.set(this.calendar.headingValue());
|
795
|
+
const { isInvalid, isDateSelected } = calendarState({
|
796
|
+
date: this.value,
|
797
|
+
isDateDisabled: this.isDateDisabled(),
|
798
|
+
isDateUnavailable: this.isDateUnavailable()
|
799
|
+
});
|
800
|
+
this.isDateSelected = isDateSelected;
|
801
|
+
this.isInvalid = isInvalid();
|
802
|
+
});
|
803
|
+
watch([this.value], (_modelValue) => {
|
804
|
+
if (Array.isArray(_modelValue) && _modelValue.length) {
|
805
|
+
const lastValue = _modelValue[_modelValue.length - 1];
|
806
|
+
if (lastValue && !isEqualDay(this.placeholder(), lastValue)) {
|
807
|
+
this.onPlaceholderChange(lastValue);
|
808
|
+
}
|
809
|
+
}
|
810
|
+
else if (!Array.isArray(_modelValue) && _modelValue && !isEqualDay(this.placeholder(), _modelValue)) {
|
811
|
+
this.onPlaceholderChange(_modelValue);
|
812
|
+
}
|
813
|
+
});
|
814
|
+
}
|
815
|
+
ngAfterViewInit() {
|
816
|
+
this.currentElement = this.elementRef.nativeElement;
|
817
|
+
}
|
818
|
+
/**
|
819
|
+
* @ignore
|
820
|
+
*/
|
821
|
+
onPlaceholderChange(value) {
|
822
|
+
this.placeholder.set(value.copy());
|
823
|
+
}
|
824
|
+
/**
|
825
|
+
* @ignore
|
826
|
+
*/
|
827
|
+
onDateChange(date) {
|
828
|
+
const currentValue = this.value();
|
829
|
+
if (!this.multiple()) {
|
830
|
+
// for single selection
|
831
|
+
if (!this.value()) {
|
832
|
+
this.value.set(date.copy());
|
833
|
+
return;
|
834
|
+
}
|
835
|
+
if (!this.preventDeselect() && isEqualDay(this.value(), date)) {
|
836
|
+
this.placeholder.set(date.copy());
|
837
|
+
this.value.set(undefined);
|
838
|
+
}
|
839
|
+
else {
|
840
|
+
this.value.set(date.copy());
|
841
|
+
}
|
842
|
+
}
|
843
|
+
else if (!this.value()) {
|
844
|
+
// for multiple selection
|
845
|
+
this.value.set([date.copy()]);
|
846
|
+
}
|
847
|
+
else if (Array.isArray(currentValue)) {
|
848
|
+
const index = currentValue.findIndex((d) => isSameDay(d, date));
|
849
|
+
if (index === -1) {
|
850
|
+
this.value.set([...currentValue, date.copy()]);
|
851
|
+
}
|
852
|
+
else if (!this.preventDeselect()) {
|
853
|
+
const next = currentValue.filter((d) => !isSameDay(d, date));
|
854
|
+
if (next.length === 0) {
|
855
|
+
this.placeholder.set(date.copy());
|
856
|
+
this.value.set(undefined);
|
857
|
+
return;
|
858
|
+
}
|
859
|
+
this.value.set(next.map((d) => d.copy()));
|
860
|
+
}
|
861
|
+
}
|
862
|
+
}
|
863
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarRootDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
864
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.4", type: RdxCalendarRootDirective, isStandalone: true, selector: "[rdxCalendarRoot]", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, defaultPlaceholder: { classPropertyName: "defaultPlaceholder", publicName: "defaultPlaceholder", isSignal: true, isRequired: false, transformFunction: null }, locale: { classPropertyName: "locale", publicName: "locale", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, multiple: { classPropertyName: "multiple", publicName: "multiple", isSignal: true, isRequired: false, transformFunction: null }, fixedWeeks: { classPropertyName: "fixedWeeks", publicName: "fixedWeeks", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, preventDeselect: { classPropertyName: "preventDeselect", publicName: "preventDeselect", isSignal: true, isRequired: false, transformFunction: null }, weekStartsOn: { classPropertyName: "weekStartsOn", publicName: "weekStartsOn", isSignal: true, isRequired: false, transformFunction: null }, numberOfMonths: { classPropertyName: "numberOfMonths", publicName: "numberOfMonths", isSignal: true, isRequired: false, transformFunction: null }, dir: { classPropertyName: "dir", publicName: "dir", isSignal: true, isRequired: false, transformFunction: null }, minValue: { classPropertyName: "minValue", publicName: "minValue", isSignal: true, isRequired: false, transformFunction: null }, maxValue: { classPropertyName: "maxValue", publicName: "maxValue", isSignal: true, isRequired: false, transformFunction: null }, weekdayFormat: { classPropertyName: "weekdayFormat", publicName: "weekdayFormat", isSignal: true, isRequired: false, transformFunction: null }, calendarLabel: { classPropertyName: "calendarLabel", publicName: "calendarLabel", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, pagedNavigation: { classPropertyName: "pagedNavigation", publicName: "pagedNavigation", isSignal: true, isRequired: false, transformFunction: null }, propsNextPage: { classPropertyName: "propsNextPage", publicName: "propsNextPage", isSignal: true, isRequired: false, transformFunction: null }, propsPrevPage: { classPropertyName: "propsPrevPage", publicName: "propsPrevPage", isSignal: true, isRequired: false, transformFunction: null }, isDateDisabled: { classPropertyName: "isDateDisabled", publicName: "isDateDisabled", isSignal: true, isRequired: false, transformFunction: null }, isDateUnavailable: { classPropertyName: "isDateUnavailable", publicName: "isDateUnavailable", isSignal: true, isRequired: false, transformFunction: null }, initialFocus: { classPropertyName: "initialFocus", publicName: "initialFocus", isSignal: true, isRequired: false, transformFunction: null }, months: { classPropertyName: "months", publicName: "months", isSignal: true, isRequired: false, transformFunction: null }, weekDays: { classPropertyName: "weekDays", publicName: "weekDays", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", defaultPlaceholder: "defaultPlaceholderChange", placeholder: "placeholderChange", months: "monthsChange", weekDays: "weekDaysChange" }, host: { attributes: { "role": "application" }, properties: { "attr.aria-label": "fullCalendarLabel()", "attr.data-disabled": "disabled() ? \"\" : undefined", "attr.data-readonly": "readonly() ? \"\" : undefined", "attr.data-invalid": "isInvalid ? \"\" : undefined", "attr.dir": "dir()" } }, providers: [
|
865
|
+
{ provide: CALENDAR_ROOT_CONTEXT, useExisting: forwardRef(() => RdxCalendarRootDirective) }
|
866
|
+
], exportAs: ["rdxCalendarRoot"], ngImport: i0 }); }
|
867
|
+
}
|
868
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarRootDirective, decorators: [{
|
869
|
+
type: Directive,
|
870
|
+
args: [{
|
871
|
+
selector: '[rdxCalendarRoot]',
|
872
|
+
exportAs: 'rdxCalendarRoot',
|
873
|
+
providers: [
|
874
|
+
{ provide: CALENDAR_ROOT_CONTEXT, useExisting: forwardRef(() => RdxCalendarRootDirective) }
|
875
|
+
],
|
876
|
+
host: {
|
877
|
+
role: 'application',
|
878
|
+
'[attr.aria-label]': 'fullCalendarLabel()',
|
879
|
+
'[attr.data-disabled]': 'disabled() ? "" : undefined',
|
880
|
+
'[attr.data-readonly]': 'readonly() ? "" : undefined',
|
881
|
+
'[attr.data-invalid]': 'isInvalid ? "" : undefined',
|
882
|
+
'[attr.dir]': 'dir()'
|
883
|
+
}
|
884
|
+
}]
|
885
|
+
}], ctorParameters: () => [] });
|
886
|
+
|
887
|
+
const _imports = [
|
888
|
+
RdxCalendarCellTriggerDirective,
|
889
|
+
RdxCalendarCellDirective,
|
890
|
+
RdxCalendarGridBodyDirective,
|
891
|
+
RdxCalendarGridHeadDirective,
|
892
|
+
RdxCalendarGridRowDirective,
|
893
|
+
RdxCalendarGridDirective,
|
894
|
+
RdxCalendarHeadCellDirective,
|
895
|
+
RdxCalendarHeaderDirective,
|
896
|
+
RdxCalendarPrevDirective,
|
897
|
+
RdxCalendarRootDirective,
|
898
|
+
RdxCalendarHeadingDirective,
|
899
|
+
RdxCalendarNextDirective
|
900
|
+
];
|
901
|
+
class RdxCalendarModule {
|
902
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
903
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarModule, imports: [RdxCalendarCellTriggerDirective,
|
904
|
+
RdxCalendarCellDirective,
|
905
|
+
RdxCalendarGridBodyDirective,
|
906
|
+
RdxCalendarGridHeadDirective,
|
907
|
+
RdxCalendarGridRowDirective,
|
908
|
+
RdxCalendarGridDirective,
|
909
|
+
RdxCalendarHeadCellDirective,
|
910
|
+
RdxCalendarHeaderDirective,
|
911
|
+
RdxCalendarPrevDirective,
|
912
|
+
RdxCalendarRootDirective,
|
913
|
+
RdxCalendarHeadingDirective,
|
914
|
+
RdxCalendarNextDirective], exports: [RdxCalendarCellTriggerDirective,
|
915
|
+
RdxCalendarCellDirective,
|
916
|
+
RdxCalendarGridBodyDirective,
|
917
|
+
RdxCalendarGridHeadDirective,
|
918
|
+
RdxCalendarGridRowDirective,
|
919
|
+
RdxCalendarGridDirective,
|
920
|
+
RdxCalendarHeadCellDirective,
|
921
|
+
RdxCalendarHeaderDirective,
|
922
|
+
RdxCalendarPrevDirective,
|
923
|
+
RdxCalendarRootDirective,
|
924
|
+
RdxCalendarHeadingDirective,
|
925
|
+
RdxCalendarNextDirective] }); }
|
926
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarModule }); }
|
927
|
+
}
|
928
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxCalendarModule, decorators: [{
|
929
|
+
type: NgModule,
|
930
|
+
args: [{
|
931
|
+
imports: [..._imports],
|
932
|
+
exports: [..._imports]
|
933
|
+
}]
|
934
|
+
}] });
|
935
|
+
|
936
|
+
/**
|
937
|
+
* Generated bundle index. Do not edit.
|
938
|
+
*/
|
939
|
+
|
940
|
+
export { RdxCalendarCellDirective, RdxCalendarCellTriggerDirective, RdxCalendarGridBodyDirective, RdxCalendarGridDirective, RdxCalendarGridHeadDirective, RdxCalendarGridRowDirective, RdxCalendarHeadCellDirective, RdxCalendarHeaderDirective, RdxCalendarHeadingDirective, RdxCalendarModule, RdxCalendarNextDirective, RdxCalendarPrevDirective, RdxCalendarRootDirective };
|
941
|
+
//# sourceMappingURL=radix-ng-primitives-calendar.mjs.map
|