@coreui/vue-pro 5.9.0 → 5.10.0
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/README.md +1 -1
- package/dist/cjs/components/accordion/CAccordionBody.js +2 -1
- package/dist/cjs/components/accordion/CAccordionBody.js.map +1 -1
- package/dist/cjs/components/accordion/CAccordionButton.js +3 -1
- package/dist/cjs/components/accordion/CAccordionButton.js.map +1 -1
- package/dist/cjs/components/accordion/CAccordionItem.d.ts +8 -0
- package/dist/cjs/components/accordion/CAccordionItem.js +10 -2
- package/dist/cjs/components/accordion/CAccordionItem.js.map +1 -1
- package/dist/cjs/components/calendar/CCalendar.d.ts +6 -6
- package/dist/cjs/components/calendar/CCalendar.js +40 -36
- package/dist/cjs/components/calendar/CCalendar.js.map +1 -1
- package/dist/cjs/components/calendar/types.d.ts +3 -0
- package/dist/cjs/components/calendar/utils.d.ts +175 -18
- package/dist/cjs/components/calendar/utils.js +311 -43
- package/dist/cjs/components/calendar/utils.js.map +1 -1
- package/dist/cjs/components/date-picker/CDatePicker.d.ts +1 -1
- package/dist/cjs/components/date-range-picker/CDateRangePicker.d.ts +1 -1
- package/dist/cjs/components/multi-select/CMultiSelect.js +5 -1
- package/dist/cjs/components/multi-select/CMultiSelect.js.map +1 -1
- package/dist/cjs/components/nav/CNavGroup.js +6 -2
- package/dist/cjs/components/nav/CNavGroup.js.map +1 -1
- package/dist/cjs/components/range-slider/CRangeSlider.js +6 -2
- package/dist/cjs/components/range-slider/CRangeSlider.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +2 -1
- package/dist/cjs/utils/isEqual.d.ts +2 -0
- package/dist/cjs/utils/isEqual.js +78 -0
- package/dist/cjs/utils/isEqual.js.map +1 -0
- package/dist/esm/components/accordion/CAccordionBody.js +2 -1
- package/dist/esm/components/accordion/CAccordionBody.js.map +1 -1
- package/dist/esm/components/accordion/CAccordionButton.js +3 -1
- package/dist/esm/components/accordion/CAccordionButton.js.map +1 -1
- package/dist/esm/components/accordion/CAccordionItem.d.ts +8 -0
- package/dist/esm/components/accordion/CAccordionItem.js +11 -3
- package/dist/esm/components/accordion/CAccordionItem.js.map +1 -1
- package/dist/esm/components/calendar/CCalendar.d.ts +6 -6
- package/dist/esm/components/calendar/CCalendar.js +42 -38
- package/dist/esm/components/calendar/CCalendar.js.map +1 -1
- package/dist/esm/components/calendar/types.d.ts +3 -0
- package/dist/esm/components/calendar/utils.d.ts +175 -18
- package/dist/esm/components/calendar/utils.js +305 -44
- package/dist/esm/components/calendar/utils.js.map +1 -1
- package/dist/esm/components/date-picker/CDatePicker.d.ts +1 -1
- package/dist/esm/components/date-range-picker/CDateRangePicker.d.ts +1 -1
- package/dist/esm/components/multi-select/CMultiSelect.js +5 -1
- package/dist/esm/components/multi-select/CMultiSelect.js.map +1 -1
- package/dist/esm/components/nav/CNavGroup.js +6 -2
- package/dist/esm/components/nav/CNavGroup.js.map +1 -1
- package/dist/esm/components/range-slider/CRangeSlider.js +6 -2
- package/dist/esm/components/range-slider/CRangeSlider.js.map +1 -1
- package/dist/esm/utils/index.d.ts +2 -1
- package/dist/esm/utils/isEqual.d.ts +2 -0
- package/dist/esm/utils/isEqual.js +74 -0
- package/dist/esm/utils/isEqual.js.map +1 -0
- package/package.json +6 -6
- package/src/components/accordion/CAccordionBody.ts +2 -1
- package/src/components/accordion/CAccordionButton.ts +3 -1
- package/src/components/accordion/CAccordionItem.ts +11 -3
- package/src/components/calendar/CCalendar.ts +62 -52
- package/src/components/calendar/types.ts +5 -0
- package/src/components/calendar/utils.ts +414 -109
- package/src/components/date-picker/CDatePicker.ts +1 -1
- package/src/components/date-range-picker/CDateRangePicker.ts +1 -1
- package/src/components/multi-select/CMultiSelect.ts +10 -2
- package/src/components/nav/CNavGroup.ts +7 -2
- package/src/components/range-slider/CRangeSlider.ts +7 -2
- package/src/utils/index.ts +10 -1
- package/src/utils/isEqual.ts +75 -0
|
@@ -1,17 +1,83 @@
|
|
|
1
|
-
import type { DisabledDate } from './
|
|
1
|
+
import type { DisabledDate, SelectionTypes, ViewTypes } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Converts an ISO week string to a Date object representing the Monday of that week.
|
|
4
|
+
* @param isoWeek - The ISO week string (e.g., "2023W05" or "2023w05").
|
|
5
|
+
* @returns The Date object for the Monday of the specified week, or null if invalid.
|
|
6
|
+
*/
|
|
2
7
|
export declare const convertIsoWeekToDate: (isoWeek: string) => Date;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Converts a date string or Date object to a Date object based on selection type.
|
|
10
|
+
* @param date - The date to convert.
|
|
11
|
+
* @param selectionType - The type of selection ('day', 'week', 'month', 'year').
|
|
12
|
+
* @returns The corresponding Date object or null if invalid.
|
|
13
|
+
*/
|
|
14
|
+
export declare const convertToDateObject: (date: Date | string, selectionType?: SelectionTypes) => Date;
|
|
15
|
+
/**
|
|
16
|
+
* Creates groups from an array.
|
|
17
|
+
* @param arr - The array to group.
|
|
18
|
+
* @param numberOfGroups - Number of groups to create.
|
|
19
|
+
* @returns An array of grouped arrays.
|
|
20
|
+
*/
|
|
6
21
|
export declare const createGroupsInArray: <T>(arr: T[], numberOfGroups: number) => T[][];
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Adjusts the calendar date based on order and view type.
|
|
24
|
+
* @param calendarDate - The current calendar date.
|
|
25
|
+
* @param order - The order to adjust by.
|
|
26
|
+
* @param view - The current view type.
|
|
27
|
+
* @returns The adjusted Date object.
|
|
28
|
+
*/
|
|
29
|
+
export declare const getCalendarDate: (calendarDate: Date, order: number, view: ViewTypes) => Date;
|
|
30
|
+
/**
|
|
31
|
+
* Formats a date based on the selection type.
|
|
32
|
+
* @param date - The date to format.
|
|
33
|
+
* @param selectionType - The type of selection ('day', 'week', 'month', 'year').
|
|
34
|
+
* @returns A formatted date string or the original Date object.
|
|
35
|
+
*/
|
|
36
|
+
export declare const getDateBySelectionType: (date: Date | null, selectionType: SelectionTypes) => string | Date | null;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves the first available date within a range that is not disabled.
|
|
39
|
+
* @param startDate - Start date of the range.
|
|
40
|
+
* @param endDate - End date of the range.
|
|
41
|
+
* @param min - Minimum allowed date.
|
|
42
|
+
* @param max - Maximum allowed date.
|
|
43
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
44
|
+
* @returns The first available Date object or null if none found.
|
|
45
|
+
*/
|
|
46
|
+
export declare const getFirstAvailableDateInRange: (startDate: Date, endDate: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => Date | null;
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves an array of month names based on locale and format.
|
|
49
|
+
* @param locale - The locale string (e.g., 'en-US').
|
|
50
|
+
* @param format - The format of the month names ('short' or 'long').
|
|
51
|
+
* @returns An array of month names.
|
|
52
|
+
*/
|
|
53
|
+
export declare const getMonthsNames: (locale: string, format?: "short" | "long") => string[];
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves an array of selectable dates from the given element.
|
|
56
|
+
* @param element - The HTML element to search for selectable dates.
|
|
57
|
+
* @param selector - The CSS selector used to identify selectable dates. Defaults to 'tr[tabindex="0"], td[tabindex="0"]'.
|
|
58
|
+
* @returns An array of HTMLElements representing the selectable dates.
|
|
59
|
+
*/
|
|
60
|
+
export declare const getSelectableDates: (element: HTMLElement, selector?: string) => HTMLElement[];
|
|
61
|
+
/**
|
|
62
|
+
* Generates an array of years centered around a given year.
|
|
63
|
+
* @param year - The central year.
|
|
64
|
+
* @param range - The number of years before and after the central year.
|
|
65
|
+
* @returns An array of years.
|
|
66
|
+
*/
|
|
67
|
+
export declare const getYears: (year: number, range?: number) => number[];
|
|
68
|
+
/**
|
|
69
|
+
* Calculates the ISO week number for a given date.
|
|
70
|
+
* @param date - The date to calculate the week number for.
|
|
71
|
+
* @returns The ISO week number.
|
|
72
|
+
*/
|
|
14
73
|
export declare const getWeekNumber: (date: Date) => number;
|
|
74
|
+
/**
|
|
75
|
+
* Retrieves detailed information about each week in a month for calendar rendering.
|
|
76
|
+
* @param year - The year.
|
|
77
|
+
* @param month - The month (0-11).
|
|
78
|
+
* @param firstDayOfWeek - The first day of the week (0-6, where 0 is Sunday).
|
|
79
|
+
* @returns An array of week objects containing week numbers and day details.
|
|
80
|
+
*/
|
|
15
81
|
export declare const getMonthDetails: (year: number, month: number, firstDayOfWeek: number) => {
|
|
16
82
|
weekNumber?: number;
|
|
17
83
|
days: {
|
|
@@ -19,14 +85,105 @@ export declare const getMonthDetails: (year: number, month: number, firstDayOfWe
|
|
|
19
85
|
month: string;
|
|
20
86
|
}[];
|
|
21
87
|
}[];
|
|
22
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Checks if a date is disabled based on the 'date' period type.
|
|
90
|
+
* @param date - The date to check.
|
|
91
|
+
* @param min - Minimum allowed date.
|
|
92
|
+
* @param max - Maximum allowed date.
|
|
93
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
94
|
+
* @returns True if the date is disabled, false otherwise.
|
|
95
|
+
*/
|
|
23
96
|
export declare const isDateDisabled: (date: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Checks if a date is within a specified range.
|
|
99
|
+
* @param date - The date to check.
|
|
100
|
+
* @param start - Start date of the range.
|
|
101
|
+
* @param end - End date of the range.
|
|
102
|
+
* @returns True if the date is within the range, false otherwise.
|
|
103
|
+
*/
|
|
104
|
+
export declare const isDateInRange: (date: Date, start: Date | null, end: Date | null) => boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Checks if a date is selected based on start and end dates.
|
|
107
|
+
* @param date - The date to check.
|
|
108
|
+
* @param start - Start date.
|
|
109
|
+
* @param end - End date.
|
|
110
|
+
* @returns True if the date is selected, false otherwise.
|
|
111
|
+
*/
|
|
112
|
+
export declare const isDateSelected: (date: Date, start: Date | null, end: Date | null) => boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Determines if any date within a range is disabled.
|
|
115
|
+
* @param startDate - Start date of the range.
|
|
116
|
+
* @param endDate - End date of the range.
|
|
117
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
118
|
+
* @returns True if any date in the range is disabled, false otherwise.
|
|
119
|
+
*/
|
|
120
|
+
export declare const isDisableDateInRange: (startDate?: Date | null, endDate?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Checks if a month is disabled based on the 'month' period type.
|
|
123
|
+
* @param date - The date representing the month to check.
|
|
124
|
+
* @param min - Minimum allowed date.
|
|
125
|
+
* @param max - Maximum allowed date.
|
|
126
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
127
|
+
* @returns True if the month is disabled, false otherwise.
|
|
128
|
+
*/
|
|
129
|
+
export declare const isMonthDisabled: (date: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Checks if a month is selected based on start and end dates.
|
|
132
|
+
* @param date - The date representing the month.
|
|
133
|
+
* @param start - Start date.
|
|
134
|
+
* @param end - End date.
|
|
135
|
+
* @returns True if the month is selected, false otherwise.
|
|
136
|
+
*/
|
|
137
|
+
export declare const isMonthSelected: (date: Date, start: Date | null, end: Date | null) => boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Checks if a month is within a specified range.
|
|
140
|
+
* @param date - The date representing the month.
|
|
141
|
+
* @param start - Start date.
|
|
142
|
+
* @param end - End date.
|
|
143
|
+
* @returns True if the month is within the range, false otherwise.
|
|
144
|
+
*/
|
|
145
|
+
export declare const isMonthInRange: (date: Date, start: Date | null, end: Date | null) => boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Checks if two dates are the same calendar date.
|
|
148
|
+
* @param date - First date.
|
|
149
|
+
* @param date2 - Second date.
|
|
150
|
+
* @returns True if both dates are the same, false otherwise.
|
|
151
|
+
*/
|
|
28
152
|
export declare const isSameDateAs: (date: Date | null, date2: Date | null) => boolean;
|
|
29
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Checks if a date is today.
|
|
155
|
+
* @param date - The date to check.
|
|
156
|
+
* @returns True if the date is today, false otherwise.
|
|
157
|
+
*/
|
|
30
158
|
export declare const isToday: (date: Date) => boolean;
|
|
31
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Checks if a year is disabled based on the 'year' period type.
|
|
161
|
+
* @param date - The date representing the year to check.
|
|
162
|
+
* @param min - Minimum allowed date.
|
|
163
|
+
* @param max - Maximum allowed date.
|
|
164
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
165
|
+
* @returns True if the year is disabled, false otherwise.
|
|
166
|
+
*/
|
|
167
|
+
export declare const isYearDisabled: (date: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Checks if a year is selected based on start and end dates.
|
|
170
|
+
* @param date - The date representing the year.
|
|
171
|
+
* @param start - Start date.
|
|
172
|
+
* @param end - End date.
|
|
173
|
+
* @returns True if the year matches the start's or end's year, false otherwise.
|
|
174
|
+
*/
|
|
175
|
+
export declare const isYearSelected: (date: Date, start: Date | null, end: Date | null) => boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Checks if a year is within a specified range.
|
|
178
|
+
* @param date - The date representing the year.
|
|
179
|
+
* @param start - Start date.
|
|
180
|
+
* @param end - End date.
|
|
181
|
+
* @returns True if the year's value lies between start's year and end's year, false otherwise.
|
|
182
|
+
*/
|
|
183
|
+
export declare const isYearInRange: (date: Date, start: Date | null, end: Date | null) => boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Removes the time component from a Date object.
|
|
186
|
+
* @param date - The original date.
|
|
187
|
+
* @returns A new Date object with the time set to 00:00:00.
|
|
188
|
+
*/
|
|
32
189
|
export declare const removeTimeFromDate: (date: Date) => Date;
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Converts an ISO week string to a Date object representing the Monday of that week.
|
|
5
|
+
* @param isoWeek - The ISO week string (e.g., "2023W05" or "2023w05").
|
|
6
|
+
* @returns The Date object for the Monday of the specified week, or null if invalid.
|
|
7
|
+
*/
|
|
3
8
|
const convertIsoWeekToDate = (isoWeek) => {
|
|
4
|
-
const [year, week] = isoWeek.split(/
|
|
5
|
-
|
|
6
|
-
const date = new Date(Number(year), 0, 4);
|
|
7
|
-
// Get previous Monday, add 7 days for each week after first
|
|
9
|
+
const [year, week] = isoWeek.split(/[Ww]/);
|
|
10
|
+
const date = new Date(Number(year), 0, 4); // 4th Jan is always in week 1
|
|
8
11
|
date.setDate(date.getDate() - (date.getDay() || 7) + 1 + (Number(week) - 1) * 7);
|
|
9
12
|
return date;
|
|
10
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Converts a date string or Date object to a Date object based on selection type.
|
|
16
|
+
* @param date - The date to convert.
|
|
17
|
+
* @param selectionType - The type of selection ('day', 'week', 'month', 'year').
|
|
18
|
+
* @returns The corresponding Date object or null if invalid.
|
|
19
|
+
*/
|
|
11
20
|
const convertToDateObject = (date, selectionType) => {
|
|
12
21
|
if (date instanceof Date) {
|
|
13
22
|
return date;
|
|
@@ -22,12 +31,25 @@ const convertToDateObject = (date, selectionType) => {
|
|
|
22
31
|
}
|
|
23
32
|
return new Date(Date.parse(date));
|
|
24
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Creates groups from an array.
|
|
36
|
+
* @param arr - The array to group.
|
|
37
|
+
* @param numberOfGroups - Number of groups to create.
|
|
38
|
+
* @returns An array of grouped arrays.
|
|
39
|
+
*/
|
|
25
40
|
const createGroupsInArray = (arr, numberOfGroups) => {
|
|
26
41
|
const perGroup = Math.ceil(arr.length / numberOfGroups);
|
|
27
42
|
return Array.from({ length: numberOfGroups })
|
|
28
43
|
.fill('')
|
|
29
44
|
.map((_, i) => arr.slice(i * perGroup, (i + 1) * perGroup));
|
|
30
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Adjusts the calendar date based on order and view type.
|
|
48
|
+
* @param calendarDate - The current calendar date.
|
|
49
|
+
* @param order - The order to adjust by.
|
|
50
|
+
* @param view - The current view type.
|
|
51
|
+
* @returns The adjusted Date object.
|
|
52
|
+
*/
|
|
31
53
|
const getCalendarDate = (calendarDate, order, view) => {
|
|
32
54
|
if (order !== 0 && view === 'days') {
|
|
33
55
|
return new Date(calendarDate.getFullYear(), calendarDate.getMonth() + order, 1);
|
|
@@ -40,6 +62,12 @@ const getCalendarDate = (calendarDate, order, view) => {
|
|
|
40
62
|
}
|
|
41
63
|
return calendarDate;
|
|
42
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* Formats a date based on the selection type.
|
|
67
|
+
* @param date - The date to format.
|
|
68
|
+
* @param selectionType - The type of selection ('day', 'week', 'month', 'year').
|
|
69
|
+
* @returns A formatted date string or the original Date object.
|
|
70
|
+
*/
|
|
43
71
|
const getDateBySelectionType = (date, selectionType) => {
|
|
44
72
|
if (date === null) {
|
|
45
73
|
return null;
|
|
@@ -56,23 +84,42 @@ const getDateBySelectionType = (date, selectionType) => {
|
|
|
56
84
|
}
|
|
57
85
|
return date;
|
|
58
86
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves an array of month names based on locale and format.
|
|
89
|
+
* @param locale - The locale string (e.g., 'en-US').
|
|
90
|
+
* @param format - The format of the month names ('short' or 'long').
|
|
91
|
+
* @returns An array of month names.
|
|
92
|
+
*/
|
|
93
|
+
const getMonthsNames = (locale, format = 'short') => {
|
|
94
|
+
return Array.from({ length: 12 }, (_, i) => {
|
|
95
|
+
return new Date(2000, i, 1).toLocaleString(locale, { month: format });
|
|
96
|
+
});
|
|
68
97
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves an array of selectable dates from the given element.
|
|
100
|
+
* @param element - The HTML element to search for selectable dates.
|
|
101
|
+
* @param selector - The CSS selector used to identify selectable dates. Defaults to 'tr[tabindex="0"], td[tabindex="0"]'.
|
|
102
|
+
* @returns An array of HTMLElements representing the selectable dates.
|
|
103
|
+
*/
|
|
104
|
+
const getSelectableDates = (element, selector = 'tr[tabindex="0"], td[tabindex="0"]') => {
|
|
105
|
+
return [...Element.prototype.querySelectorAll.call(element, selector)];
|
|
75
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* Generates an array of years centered around a given year.
|
|
109
|
+
* @param year - The central year.
|
|
110
|
+
* @param range - The number of years before and after the central year.
|
|
111
|
+
* @returns An array of years.
|
|
112
|
+
*/
|
|
113
|
+
const getYears = (year, range = 6) => {
|
|
114
|
+
return Array.from({ length: range * 2 }, (_, i) => year - range + i);
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves leading days (from the previous month) for a calendar view.
|
|
118
|
+
* @param year - The year.
|
|
119
|
+
* @param month - The month (0-11).
|
|
120
|
+
* @param firstDayOfWeek - The first day of the week (0-6, where 0 is Sunday).
|
|
121
|
+
* @returns An array of leading day objects.
|
|
122
|
+
*/
|
|
76
123
|
const getLeadingDays = (year, month, firstDayOfWeek) => {
|
|
77
124
|
// 0: sunday
|
|
78
125
|
// 1: monday
|
|
@@ -93,6 +140,12 @@ const getLeadingDays = (year, month, firstDayOfWeek) => {
|
|
|
93
140
|
}
|
|
94
141
|
return dates;
|
|
95
142
|
};
|
|
143
|
+
/**
|
|
144
|
+
* Retrieves all days within a specific month.
|
|
145
|
+
* @param year - The year.
|
|
146
|
+
* @param month - The month (0-11).
|
|
147
|
+
* @returns An array of day objects.
|
|
148
|
+
*/
|
|
96
149
|
const getMonthDays = (year, month) => {
|
|
97
150
|
const dates = [];
|
|
98
151
|
const lastDay = new Date(year, month + 1, 0).getDate();
|
|
@@ -104,6 +157,14 @@ const getMonthDays = (year, month) => {
|
|
|
104
157
|
}
|
|
105
158
|
return dates;
|
|
106
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* Retrieves trailing days (from the next month) for a calendar view.
|
|
162
|
+
* @param year - The year.
|
|
163
|
+
* @param month - The month (0-11).
|
|
164
|
+
* @param leadingDays - Array of leading day objects.
|
|
165
|
+
* @param monthDays - Array of current month day objects.
|
|
166
|
+
* @returns An array of trailing day objects.
|
|
167
|
+
*/
|
|
107
168
|
const getTrailingDays = (year, month, leadingDays, monthDays) => {
|
|
108
169
|
const dates = [];
|
|
109
170
|
const days = 42 - (leadingDays.length + monthDays.length);
|
|
@@ -115,11 +176,28 @@ const getTrailingDays = (year, month, leadingDays, monthDays) => {
|
|
|
115
176
|
}
|
|
116
177
|
return dates;
|
|
117
178
|
};
|
|
179
|
+
/**
|
|
180
|
+
* Calculates the ISO week number for a given date.
|
|
181
|
+
* @param date - The date to calculate the week number for.
|
|
182
|
+
* @returns The ISO week number.
|
|
183
|
+
*/
|
|
118
184
|
const getWeekNumber = (date) => {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
185
|
+
const tempDate = new Date(date.getTime());
|
|
186
|
+
tempDate.setHours(0, 0, 0, 0);
|
|
187
|
+
// Thursday in current week decides the year
|
|
188
|
+
tempDate.setDate(tempDate.getDate() + 3 - ((tempDate.getDay() + 6) % 7));
|
|
189
|
+
const week1 = new Date(tempDate.getFullYear(), 0, 4);
|
|
190
|
+
// Calculate full weeks to the date
|
|
191
|
+
const weekNumber = 1 + Math.round((tempDate.getTime() - week1.getTime()) / 86_400_000 / 7);
|
|
192
|
+
return weekNumber;
|
|
122
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* Retrieves detailed information about each week in a month for calendar rendering.
|
|
196
|
+
* @param year - The year.
|
|
197
|
+
* @param month - The month (0-11).
|
|
198
|
+
* @param firstDayOfWeek - The first day of the week (0-6, where 0 is Sunday).
|
|
199
|
+
* @returns An array of week objects containing week numbers and day details.
|
|
200
|
+
*/
|
|
123
201
|
const getMonthDetails = (year, month, firstDayOfWeek) => {
|
|
124
202
|
const daysPrevMonth = getLeadingDays(year, month, firstDayOfWeek);
|
|
125
203
|
const daysThisMonth = getMonthDays(year, month);
|
|
@@ -139,21 +217,14 @@ const getMonthDetails = (year, month, firstDayOfWeek) => {
|
|
|
139
217
|
});
|
|
140
218
|
return weeks;
|
|
141
219
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return disabled;
|
|
154
|
-
}
|
|
155
|
-
return false;
|
|
156
|
-
};
|
|
220
|
+
/**
|
|
221
|
+
* Checks if a date is disabled based on the 'date' period type.
|
|
222
|
+
* @param date - The date to check.
|
|
223
|
+
* @param min - Minimum allowed date.
|
|
224
|
+
* @param max - Maximum allowed date.
|
|
225
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
226
|
+
* @returns True if the date is disabled, false otherwise.
|
|
227
|
+
*/
|
|
157
228
|
const isDateDisabled = (date, min, max, disabledDates) => {
|
|
158
229
|
if (min && date < min) {
|
|
159
230
|
return true;
|
|
@@ -161,6 +232,9 @@ const isDateDisabled = (date, min, max, disabledDates) => {
|
|
|
161
232
|
if (max && date > max) {
|
|
162
233
|
return true;
|
|
163
234
|
}
|
|
235
|
+
if (disabledDates === undefined) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
164
238
|
if (typeof disabledDates === 'function') {
|
|
165
239
|
return disabledDates(date);
|
|
166
240
|
}
|
|
@@ -182,15 +256,128 @@ const isDateDisabled = (date, min, max, disabledDates) => {
|
|
|
182
256
|
}
|
|
183
257
|
return false;
|
|
184
258
|
};
|
|
259
|
+
/**
|
|
260
|
+
* Checks if a date is within a specified range.
|
|
261
|
+
* @param date - The date to check.
|
|
262
|
+
* @param start - Start date of the range.
|
|
263
|
+
* @param end - End date of the range.
|
|
264
|
+
* @returns True if the date is within the range, false otherwise.
|
|
265
|
+
*/
|
|
185
266
|
const isDateInRange = (date, start, end) => {
|
|
186
267
|
const _date = removeTimeFromDate(date);
|
|
187
268
|
const _start = start ? removeTimeFromDate(start) : null;
|
|
188
269
|
const _end = end ? removeTimeFromDate(end) : null;
|
|
189
|
-
return _start && _end && _start <= _date && _date <= _end;
|
|
270
|
+
return !!(_start && _end && _start <= _date && _date <= _end);
|
|
190
271
|
};
|
|
272
|
+
/**
|
|
273
|
+
* Checks if a date is selected based on start and end dates.
|
|
274
|
+
* @param date - The date to check.
|
|
275
|
+
* @param start - Start date.
|
|
276
|
+
* @param end - End date.
|
|
277
|
+
* @returns True if the date is selected, false otherwise.
|
|
278
|
+
*/
|
|
191
279
|
const isDateSelected = (date, start, end) => {
|
|
192
|
-
|
|
280
|
+
if (start !== null && isSameDateAs(start, date)) {
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
if (end !== null && isSameDateAs(end, date)) {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
return false;
|
|
193
287
|
};
|
|
288
|
+
/**
|
|
289
|
+
* Determines if any date within a range is disabled.
|
|
290
|
+
* @param startDate - Start date of the range.
|
|
291
|
+
* @param endDate - End date of the range.
|
|
292
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
293
|
+
* @returns True if any date in the range is disabled, false otherwise.
|
|
294
|
+
*/
|
|
295
|
+
const isDisableDateInRange = (startDate, endDate, disabledDates) => {
|
|
296
|
+
if (startDate && endDate) {
|
|
297
|
+
const date = new Date(startDate);
|
|
298
|
+
let disabled = false;
|
|
299
|
+
while (date < endDate) {
|
|
300
|
+
date.setDate(date.getDate() + 1);
|
|
301
|
+
if (isDateDisabled(date, null, null, disabledDates)) {
|
|
302
|
+
disabled = true;
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return disabled;
|
|
307
|
+
}
|
|
308
|
+
return false;
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Checks if a month is disabled based on the 'month' period type.
|
|
312
|
+
* @param date - The date representing the month to check.
|
|
313
|
+
* @param min - Minimum allowed date.
|
|
314
|
+
* @param max - Maximum allowed date.
|
|
315
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
316
|
+
* @returns True if the month is disabled, false otherwise.
|
|
317
|
+
*/
|
|
318
|
+
const isMonthDisabled = (date, min, max, disabledDates) => {
|
|
319
|
+
const current = date.getFullYear() * 12 + date.getMonth();
|
|
320
|
+
const _min = min ? min.getFullYear() * 12 + min.getMonth() : null;
|
|
321
|
+
const _max = max ? max.getFullYear() * 12 + max.getMonth() : null;
|
|
322
|
+
if (_min && current < _min) {
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
if (_max && current > _max) {
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
328
|
+
if (disabledDates === undefined) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
const start = min ? Math.max(date.getTime(), min.getTime()) : date;
|
|
332
|
+
const end = max
|
|
333
|
+
? Math.min(date.getTime(), max.getTime())
|
|
334
|
+
: new Date(new Date().getFullYear(), 11, 31);
|
|
335
|
+
for (const currentDate = new Date(start); currentDate <= end; currentDate.setDate(currentDate.getDate() + 1)) {
|
|
336
|
+
if (!isDateDisabled(currentDate, min, max, disabledDates)) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return false;
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Checks if a month is selected based on start and end dates.
|
|
344
|
+
* @param date - The date representing the month.
|
|
345
|
+
* @param start - Start date.
|
|
346
|
+
* @param end - End date.
|
|
347
|
+
* @returns True if the month is selected, false otherwise.
|
|
348
|
+
*/
|
|
349
|
+
const isMonthSelected = (date, start, end) => {
|
|
350
|
+
const year = date.getFullYear();
|
|
351
|
+
const month = date.getMonth();
|
|
352
|
+
if (start !== null && year === start.getFullYear() && month === start.getMonth()) {
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
if (end !== null && year === end.getFullYear() && month === end.getMonth()) {
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
return false;
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* Checks if a month is within a specified range.
|
|
362
|
+
* @param date - The date representing the month.
|
|
363
|
+
* @param start - Start date.
|
|
364
|
+
* @param end - End date.
|
|
365
|
+
* @returns True if the month is within the range, false otherwise.
|
|
366
|
+
*/
|
|
367
|
+
const isMonthInRange = (date, start, end) => {
|
|
368
|
+
const year = date.getFullYear();
|
|
369
|
+
const month = date.getMonth();
|
|
370
|
+
const _start = start ? start.getFullYear() * 12 + start.getMonth() : null;
|
|
371
|
+
const _end = end ? end.getFullYear() * 12 + end.getMonth() : null;
|
|
372
|
+
const _date = year * 12 + month;
|
|
373
|
+
return !!(_start && _end && _start <= _date && _date <= _end);
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* Checks if two dates are the same calendar date.
|
|
377
|
+
* @param date - First date.
|
|
378
|
+
* @param date2 - Second date.
|
|
379
|
+
* @returns True if both dates are the same, false otherwise.
|
|
380
|
+
*/
|
|
194
381
|
const isSameDateAs = (date, date2) => {
|
|
195
382
|
if (date instanceof Date && date2 instanceof Date) {
|
|
196
383
|
return (date.getDate() === date2.getDate() &&
|
|
@@ -202,13 +389,87 @@ const isSameDateAs = (date, date2) => {
|
|
|
202
389
|
}
|
|
203
390
|
return false;
|
|
204
391
|
};
|
|
392
|
+
/**
|
|
393
|
+
* Checks if a date is today.
|
|
394
|
+
* @param date - The date to check.
|
|
395
|
+
* @returns True if the date is today, false otherwise.
|
|
396
|
+
*/
|
|
205
397
|
const isToday = (date) => {
|
|
206
398
|
const today = new Date();
|
|
207
|
-
return (date
|
|
208
|
-
|
|
209
|
-
|
|
399
|
+
return isSameDateAs(date, today);
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* Checks if a year is disabled based on the 'year' period type.
|
|
403
|
+
* @param date - The date representing the year to check.
|
|
404
|
+
* @param min - Minimum allowed date.
|
|
405
|
+
* @param max - Maximum allowed date.
|
|
406
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
407
|
+
* @returns True if the year is disabled, false otherwise.
|
|
408
|
+
*/
|
|
409
|
+
const isYearDisabled = (date, min, max, disabledDates) => {
|
|
410
|
+
const year = date.getFullYear();
|
|
411
|
+
const minYear = min ? min.getFullYear() : null;
|
|
412
|
+
const maxYear = max ? max.getFullYear() : null;
|
|
413
|
+
if (minYear && year < minYear) {
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
if (maxYear && year > maxYear) {
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
if (disabledDates === undefined) {
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
const start = min ? Math.max(date.getTime(), min.getTime()) : date;
|
|
423
|
+
const end = max
|
|
424
|
+
? Math.min(date.getTime(), max.getTime())
|
|
425
|
+
: new Date(new Date().getFullYear(), 11, 31);
|
|
426
|
+
for (const currentDate = new Date(start); currentDate <= end; currentDate.setDate(currentDate.getDate() + 1)) {
|
|
427
|
+
if (!isDateDisabled(currentDate, min, max, disabledDates)) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return false;
|
|
432
|
+
};
|
|
433
|
+
/**
|
|
434
|
+
* Checks if a year is selected based on start and end dates.
|
|
435
|
+
* @param date - The date representing the year.
|
|
436
|
+
* @param start - Start date.
|
|
437
|
+
* @param end - End date.
|
|
438
|
+
* @returns True if the year matches the start's or end's year, false otherwise.
|
|
439
|
+
*/
|
|
440
|
+
const isYearSelected = (date, start, end) => {
|
|
441
|
+
const year = date.getFullYear();
|
|
442
|
+
if (start !== null && year === start.getFullYear()) {
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
if (end !== null && year === end.getFullYear()) {
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
return false;
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* Checks if a year is within a specified range.
|
|
452
|
+
* @param date - The date representing the year.
|
|
453
|
+
* @param start - Start date.
|
|
454
|
+
* @param end - End date.
|
|
455
|
+
* @returns True if the year's value lies between start's year and end's year, false otherwise.
|
|
456
|
+
*/
|
|
457
|
+
const isYearInRange = (date, start, end) => {
|
|
458
|
+
const year = date.getFullYear();
|
|
459
|
+
const _start = start ? start.getFullYear() : null;
|
|
460
|
+
const _end = end ? end.getFullYear() : null;
|
|
461
|
+
return !!(_start && _end && _start <= year && year <= _end);
|
|
462
|
+
};
|
|
463
|
+
/**
|
|
464
|
+
* Removes the time component from a Date object.
|
|
465
|
+
* @param date - The original date.
|
|
466
|
+
* @returns A new Date object with the time set to 00:00:00.
|
|
467
|
+
*/
|
|
468
|
+
const removeTimeFromDate = (date) => {
|
|
469
|
+
const clearedDate = new Date(date);
|
|
470
|
+
clearedDate.setHours(0, 0, 0, 0);
|
|
471
|
+
return clearedDate;
|
|
210
472
|
};
|
|
211
|
-
const removeTimeFromDate = (date) => new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
212
473
|
|
|
213
474
|
exports.convertIsoWeekToDate = convertIsoWeekToDate;
|
|
214
475
|
exports.convertToDateObject = convertToDateObject;
|
|
@@ -217,13 +478,20 @@ exports.getCalendarDate = getCalendarDate;
|
|
|
217
478
|
exports.getDateBySelectionType = getDateBySelectionType;
|
|
218
479
|
exports.getMonthDetails = getMonthDetails;
|
|
219
480
|
exports.getMonthsNames = getMonthsNames;
|
|
481
|
+
exports.getSelectableDates = getSelectableDates;
|
|
220
482
|
exports.getWeekNumber = getWeekNumber;
|
|
221
483
|
exports.getYears = getYears;
|
|
222
484
|
exports.isDateDisabled = isDateDisabled;
|
|
223
485
|
exports.isDateInRange = isDateInRange;
|
|
224
486
|
exports.isDateSelected = isDateSelected;
|
|
225
487
|
exports.isDisableDateInRange = isDisableDateInRange;
|
|
488
|
+
exports.isMonthDisabled = isMonthDisabled;
|
|
489
|
+
exports.isMonthInRange = isMonthInRange;
|
|
490
|
+
exports.isMonthSelected = isMonthSelected;
|
|
226
491
|
exports.isSameDateAs = isSameDateAs;
|
|
227
492
|
exports.isToday = isToday;
|
|
493
|
+
exports.isYearDisabled = isYearDisabled;
|
|
494
|
+
exports.isYearInRange = isYearInRange;
|
|
495
|
+
exports.isYearSelected = isYearSelected;
|
|
228
496
|
exports.removeTimeFromDate = removeTimeFromDate;
|
|
229
497
|
//# sourceMappingURL=utils.js.map
|