@coreui/vue-pro 5.9.0 → 5.11.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/button/CButton.js +1 -1
- package/dist/cjs/components/button/CButton.js.map +1 -1
- package/dist/cjs/components/calendar/CCalendar.d.ts +6 -6
- package/dist/cjs/components/calendar/CCalendar.js +44 -39
- 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 +183 -18
- package/dist/cjs/components/calendar/utils.js +327 -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/form/CFormControlWrapper.d.ts +2 -0
- package/dist/cjs/components/form/CFormControlWrapper.js +9 -1
- package/dist/cjs/components/form/CFormControlWrapper.js.map +1 -1
- package/dist/cjs/components/index.d.ts +2 -0
- package/dist/cjs/components/index.js +44 -36
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/components/link/CLink.js.map +1 -1
- package/dist/cjs/components/loading-button/CLoadingButton.d.ts +2 -2
- package/dist/cjs/components/multi-select/CMultiSelect.d.ts +12 -0
- package/dist/cjs/components/multi-select/CMultiSelect.js +28 -2
- package/dist/cjs/components/multi-select/CMultiSelect.js.map +1 -1
- package/dist/cjs/components/nav/CNav.d.ts +2 -2
- package/dist/cjs/components/nav/CNav.js +3 -2
- package/dist/cjs/components/nav/CNav.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/offcanvas/COffcanvas.js.map +1 -1
- package/dist/cjs/components/password-input/CPasswordInput.d.ts +190 -0
- package/dist/cjs/components/password-input/CPasswordInput.js +178 -0
- package/dist/cjs/components/password-input/CPasswordInput.js.map +1 -0
- package/dist/cjs/components/password-input/index.d.ts +6 -0
- package/dist/cjs/components/password-input/index.js +13 -0
- package/dist/cjs/components/password-input/index.js.map +1 -0
- package/dist/cjs/components/popover/CPopover.d.ts +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/components/rating/CRating.d.ts +1 -1
- package/dist/cjs/components/smart-table/CSmartTable.js +2 -2
- package/dist/cjs/components/smart-table/CSmartTable.js.map +1 -1
- package/dist/cjs/components/smart-table/utils.js.map +1 -1
- package/dist/cjs/components/stepper/CStepper.d.ts +168 -0
- package/dist/cjs/components/stepper/CStepper.js +305 -0
- package/dist/cjs/components/stepper/CStepper.js.map +1 -0
- package/dist/cjs/components/stepper/index.d.ts +6 -0
- package/dist/cjs/components/stepper/index.js +13 -0
- package/dist/cjs/components/stepper/index.js.map +1 -0
- package/dist/cjs/components/stepper/types.d.ts +15 -0
- package/dist/cjs/components/tabs/CTab.js.map +1 -1
- package/dist/cjs/components/tabs/CTabList.d.ts +2 -2
- package/dist/cjs/components/tabs/CTabList.js +3 -2
- package/dist/cjs/components/tabs/CTabList.js.map +1 -1
- package/dist/cjs/components/time-picker/utils.d.ts +10 -0
- package/dist/cjs/components/time-picker/utils.js +25 -9
- package/dist/cjs/components/time-picker/utils.js.map +1 -1
- package/dist/cjs/components/tooltip/CTooltip.d.ts +1 -1
- package/dist/cjs/components/widgets/CWidgetStatsB.js +2 -2
- package/dist/cjs/components/widgets/CWidgetStatsB.js.map +1 -1
- package/dist/cjs/components/widgets/CWidgetStatsC.js +2 -2
- package/dist/cjs/components/widgets/CWidgetStatsC.js.map +1 -1
- package/dist/cjs/index.js +50 -42
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/node_modules/vue-types/dist/index.js +567 -0
- package/dist/cjs/node_modules/vue-types/dist/index.js.map +1 -0
- package/dist/cjs/node_modules/vue-types/dist/shared/vue-types.8139b772.js +29 -0
- package/dist/cjs/node_modules/vue-types/dist/shared/vue-types.8139b772.js.map +1 -0
- package/dist/cjs/utils/getNextActiveElement.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/avatar/CAvatar.js +1 -1
- package/dist/esm/components/badge/CBadge.js +1 -1
- package/dist/esm/components/button/CButton.js +2 -2
- package/dist/esm/components/button/CButton.js.map +1 -1
- package/dist/esm/components/calendar/CCalendar.d.ts +6 -6
- package/dist/esm/components/calendar/CCalendar.js +46 -41
- 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 +183 -18
- package/dist/esm/components/calendar/utils.js +320 -44
- package/dist/esm/components/calendar/utils.js.map +1 -1
- package/dist/esm/components/card/CCard.js +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/dropdown/CDropdownToggle.js +2 -2
- package/dist/esm/components/form/CFormControlWrapper.d.ts +2 -0
- package/dist/esm/components/form/CFormControlWrapper.js +9 -1
- package/dist/esm/components/form/CFormControlWrapper.js.map +1 -1
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.js +4 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/components/link/CLink.js.map +1 -1
- package/dist/esm/components/loading-button/CLoadingButton.d.ts +2 -2
- package/dist/esm/components/multi-select/CMultiSelect.d.ts +12 -0
- package/dist/esm/components/multi-select/CMultiSelect.js +29 -3
- package/dist/esm/components/multi-select/CMultiSelect.js.map +1 -1
- package/dist/esm/components/nav/CNav.d.ts +2 -2
- package/dist/esm/components/nav/CNav.js +3 -2
- package/dist/esm/components/nav/CNav.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/offcanvas/COffcanvas.js.map +1 -1
- package/dist/esm/components/password-input/CPasswordInput.d.ts +190 -0
- package/dist/esm/components/password-input/CPasswordInput.js +176 -0
- package/dist/esm/components/password-input/CPasswordInput.js.map +1 -0
- package/dist/esm/components/password-input/index.d.ts +6 -0
- package/dist/esm/components/password-input/index.js +10 -0
- package/dist/esm/components/password-input/index.js.map +1 -0
- package/dist/esm/components/popover/CPopover.d.ts +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/components/rating/CRating.d.ts +1 -1
- package/dist/esm/components/smart-table/CSmartTable.js +2 -2
- package/dist/esm/components/smart-table/CSmartTable.js.map +1 -1
- package/dist/esm/components/smart-table/CSmartTableBody.js +1 -1
- package/dist/esm/components/smart-table/utils.js.map +1 -1
- package/dist/esm/components/stepper/CStepper.d.ts +168 -0
- package/dist/esm/components/stepper/CStepper.js +303 -0
- package/dist/esm/components/stepper/CStepper.js.map +1 -0
- package/dist/esm/components/stepper/index.d.ts +6 -0
- package/dist/esm/components/stepper/index.js +10 -0
- package/dist/esm/components/stepper/index.js.map +1 -0
- package/dist/esm/components/stepper/types.d.ts +15 -0
- package/dist/esm/components/tabs/CTab.js.map +1 -1
- package/dist/esm/components/tabs/CTabList.d.ts +2 -2
- package/dist/esm/components/tabs/CTabList.js +3 -2
- package/dist/esm/components/tabs/CTabList.js.map +1 -1
- package/dist/esm/components/time-picker/utils.d.ts +10 -0
- package/dist/esm/components/time-picker/utils.js +25 -10
- package/dist/esm/components/time-picker/utils.js.map +1 -1
- package/dist/esm/components/tooltip/CTooltip.d.ts +1 -1
- package/dist/esm/components/widgets/CWidgetStatsB.js +2 -2
- package/dist/esm/components/widgets/CWidgetStatsB.js.map +1 -1
- package/dist/esm/components/widgets/CWidgetStatsC.js +2 -2
- package/dist/esm/components/widgets/CWidgetStatsC.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node_modules/vue-types/dist/index.js +541 -0
- package/dist/esm/node_modules/vue-types/dist/index.js.map +1 -0
- package/dist/esm/node_modules/vue-types/dist/shared/vue-types.8139b772.js +25 -0
- package/dist/esm/node_modules/vue-types/dist/shared/vue-types.8139b772.js.map +1 -0
- package/dist/esm/utils/getNextActiveElement.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 +10 -10
- 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/button/CButton.ts +1 -1
- package/src/components/calendar/CCalendar.ts +108 -95
- package/src/components/calendar/types.ts +5 -0
- package/src/components/calendar/utils.ts +439 -111
- package/src/components/date-picker/CDatePicker.ts +1 -1
- package/src/components/date-range-picker/CDateRangePicker.ts +1 -1
- package/src/components/form/CFormControlWrapper.ts +35 -21
- package/src/components/index.ts +2 -0
- package/src/components/multi-select/CMultiSelect.ts +57 -26
- package/src/components/nav/CNav.ts +3 -2
- package/src/components/nav/CNavGroup.ts +7 -2
- package/src/components/password-input/CPasswordInput.ts +214 -0
- package/src/components/password-input/index.ts +10 -0
- package/src/components/range-slider/CRangeSlider.ts +7 -2
- package/src/components/stepper/CStepper.ts +384 -0
- package/src/components/stepper/__tests__/CStepper.spec.ts +175 -0
- package/src/components/stepper/index.ts +10 -0
- package/src/components/stepper/types.ts +18 -0
- package/src/components/tabs/CTabList.ts +3 -2
- package/src/components/time-picker/CTimePicker.ts +22 -22
- package/src/components/time-picker/CTimePickerRollCol.ts +3 -3
- package/src/components/time-picker/utils.ts +30 -13
- package/src/utils/index.ts +10 -1
- package/src/utils/isEqual.ts +75 -0
- package/dist/cjs/node_modules/is-plain-object/dist/is-plain-object.js +0 -37
- package/dist/cjs/node_modules/is-plain-object/dist/is-plain-object.js.map +0 -1
- package/dist/cjs/node_modules/vue-types/dist/vue-types.modern.js +0 -33
- package/dist/cjs/node_modules/vue-types/dist/vue-types.modern.js.map +0 -1
- package/dist/esm/node_modules/is-plain-object/dist/is-plain-object.js +0 -35
- package/dist/esm/node_modules/is-plain-object/dist/is-plain-object.js.map +0 -1
- package/dist/esm/node_modules/vue-types/dist/vue-types.modern.js +0 -6
- package/dist/esm/node_modules/vue-types/dist/vue-types.modern.js.map +0 -1
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import type { DisabledDate } from './
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { DisabledDate, SelectionTypes, ViewTypes } from './types'
|
|
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
|
+
*/
|
|
8
|
+
export const convertIsoWeekToDate = (isoWeek: string): Date => {
|
|
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
|
}
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Converts a date string or Date object to a Date object based on selection type.
|
|
17
|
+
* @param date - The date to convert.
|
|
18
|
+
* @param selectionType - The type of selection ('day', 'week', 'month', 'year').
|
|
19
|
+
* @returns The corresponding Date object or null if invalid.
|
|
20
|
+
*/
|
|
21
|
+
export const convertToDateObject = (date: Date | string, selectionType?: SelectionTypes): Date => {
|
|
16
22
|
if (date instanceof Date) {
|
|
17
23
|
return date
|
|
18
24
|
}
|
|
@@ -30,12 +36,12 @@ export const convertToDateObject = (
|
|
|
30
36
|
return new Date(Date.parse(date))
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Creates groups from an array.
|
|
41
|
+
* @param arr - The array to group.
|
|
42
|
+
* @param numberOfGroups - Number of groups to create.
|
|
43
|
+
* @returns An array of grouped arrays.
|
|
44
|
+
*/
|
|
39
45
|
export const createGroupsInArray = <T>(arr: T[], numberOfGroups: number): T[][] => {
|
|
40
46
|
const perGroup = Math.ceil(arr.length / numberOfGroups)
|
|
41
47
|
return Array.from({ length: numberOfGroups })
|
|
@@ -43,11 +49,14 @@ export const createGroupsInArray = <T>(arr: T[], numberOfGroups: number): T[][]
|
|
|
43
49
|
.map((_, i) => arr.slice(i * perGroup, (i + 1) * perGroup))
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Adjusts the calendar date based on order and view type.
|
|
54
|
+
* @param calendarDate - The current calendar date.
|
|
55
|
+
* @param order - The order to adjust by.
|
|
56
|
+
* @param view - The current view type.
|
|
57
|
+
* @returns The adjusted Date object.
|
|
58
|
+
*/
|
|
59
|
+
export const getCalendarDate = (calendarDate: Date, order: number, view: ViewTypes): Date => {
|
|
51
60
|
if (order !== 0 && view === 'days') {
|
|
52
61
|
return new Date(calendarDate.getFullYear(), calendarDate.getMonth() + order, 1)
|
|
53
62
|
}
|
|
@@ -63,14 +72,16 @@ export const getCalendarDate = (
|
|
|
63
72
|
return calendarDate
|
|
64
73
|
}
|
|
65
74
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Formats a date based on the selection type.
|
|
77
|
+
* @param date - The date to format.
|
|
78
|
+
* @param selectionType - The type of selection ('day', 'week', 'month', 'year').
|
|
79
|
+
* @returns A formatted date string or the original Date object.
|
|
80
|
+
*/
|
|
70
81
|
export const getDateBySelectionType = (
|
|
71
82
|
date: Date | null,
|
|
72
|
-
selectionType:
|
|
73
|
-
) => {
|
|
83
|
+
selectionType: SelectionTypes
|
|
84
|
+
): string | Date | null => {
|
|
74
85
|
if (date === null) {
|
|
75
86
|
return null
|
|
76
87
|
}
|
|
@@ -91,36 +102,89 @@ export const getDateBySelectionType = (
|
|
|
91
102
|
return date
|
|
92
103
|
}
|
|
93
104
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves the first available date within a range that is not disabled.
|
|
107
|
+
* @param startDate - Start date of the range.
|
|
108
|
+
* @param endDate - End date of the range.
|
|
109
|
+
* @param min - Minimum allowed date.
|
|
110
|
+
* @param max - Maximum allowed date.
|
|
111
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
112
|
+
* @returns The first available Date object or null if none found.
|
|
113
|
+
*/
|
|
114
|
+
export const getFirstAvailableDateInRange = (
|
|
115
|
+
startDate: Date,
|
|
116
|
+
endDate: Date,
|
|
117
|
+
min?: Date | null,
|
|
118
|
+
max?: Date | null,
|
|
119
|
+
disabledDates?: DisabledDate | DisabledDate[]
|
|
120
|
+
): Date | null => {
|
|
121
|
+
const _min = min ? new Date(Math.max(startDate.getTime(), min.getTime())) : startDate
|
|
122
|
+
const _max = max ? new Date(Math.min(endDate.getTime(), max.getTime())) : endDate
|
|
100
123
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
d.setDate(1)
|
|
124
|
+
if (disabledDates === undefined) {
|
|
125
|
+
return _min
|
|
126
|
+
}
|
|
105
127
|
|
|
106
|
-
for (
|
|
107
|
-
|
|
108
|
-
|
|
128
|
+
for (
|
|
129
|
+
const currentDate = new Date(_min);
|
|
130
|
+
currentDate <= _max;
|
|
131
|
+
currentDate.setDate(currentDate.getDate() + 1)
|
|
132
|
+
) {
|
|
133
|
+
if (!isDateDisabled(currentDate, min, max, disabledDates)) {
|
|
134
|
+
return currentDate
|
|
135
|
+
}
|
|
109
136
|
}
|
|
110
137
|
|
|
111
|
-
return
|
|
138
|
+
return null
|
|
112
139
|
}
|
|
113
140
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Retrieves an array of month names based on locale and format.
|
|
143
|
+
* @param locale - The locale string (e.g., 'en-US').
|
|
144
|
+
* @param format - The format of the month names ('short' or 'long').
|
|
145
|
+
* @returns An array of month names.
|
|
146
|
+
*/
|
|
147
|
+
export const getMonthsNames = (locale: string, format: 'short' | 'long' = 'short'): string[] => {
|
|
148
|
+
return Array.from({ length: 12 }, (_, i) => {
|
|
149
|
+
return new Date(2000, i, 1).toLocaleString(locale, { month: format })
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Retrieves an array of selectable dates from the given element.
|
|
155
|
+
* @param element - The HTML element to search for selectable dates.
|
|
156
|
+
* @param selector - The CSS selector used to identify selectable dates. Defaults to 'tr[tabindex="0"], td[tabindex="0"]'.
|
|
157
|
+
* @returns An array of HTMLElements representing the selectable dates.
|
|
158
|
+
*/
|
|
159
|
+
export const getSelectableDates = (
|
|
160
|
+
element: HTMLElement,
|
|
161
|
+
selector: string = 'tr[tabindex="0"], td[tabindex="0"]'
|
|
162
|
+
) => {
|
|
163
|
+
return [...Element.prototype.querySelectorAll.call(element, selector)] as HTMLElement[]
|
|
164
|
+
}
|
|
119
165
|
|
|
120
|
-
|
|
166
|
+
/**
|
|
167
|
+
* Generates an array of years centered around a given year.
|
|
168
|
+
* @param year - The central year.
|
|
169
|
+
* @param range - The number of years before and after the central year.
|
|
170
|
+
* @returns An array of years.
|
|
171
|
+
*/
|
|
172
|
+
export const getYears = (year: number, range: number = 6): number[] => {
|
|
173
|
+
return Array.from({ length: range * 2 }, (_, i) => year - range + i)
|
|
121
174
|
}
|
|
122
175
|
|
|
123
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Retrieves leading days (from the previous month) for a calendar view.
|
|
178
|
+
* @param year - The year.
|
|
179
|
+
* @param month - The month (0-11).
|
|
180
|
+
* @param firstDayOfWeek - The first day of the week (0-6, where 0 is Sunday).
|
|
181
|
+
* @returns An array of leading day objects.
|
|
182
|
+
*/
|
|
183
|
+
const getLeadingDays = (
|
|
184
|
+
year: number,
|
|
185
|
+
month: number,
|
|
186
|
+
firstDayOfWeek: number
|
|
187
|
+
): { date: Date; month: string }[] => {
|
|
124
188
|
// 0: sunday
|
|
125
189
|
// 1: monday
|
|
126
190
|
const dates = []
|
|
@@ -144,7 +208,13 @@ const getLeadingDays = (year: number, month: number, firstDayOfWeek: number) =>
|
|
|
144
208
|
return dates
|
|
145
209
|
}
|
|
146
210
|
|
|
147
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Retrieves all days within a specific month.
|
|
213
|
+
* @param year - The year.
|
|
214
|
+
* @param month - The month (0-11).
|
|
215
|
+
* @returns An array of day objects.
|
|
216
|
+
*/
|
|
217
|
+
const getMonthDays = (year: number, month: number): { date: Date; month: string }[] => {
|
|
148
218
|
const dates = []
|
|
149
219
|
const lastDay = new Date(year, month + 1, 0).getDate()
|
|
150
220
|
for (let i = 1; i <= lastDay; i++) {
|
|
@@ -157,11 +227,19 @@ const getMonthDays = (year: number, month: number) => {
|
|
|
157
227
|
return dates
|
|
158
228
|
}
|
|
159
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Retrieves trailing days (from the next month) for a calendar view.
|
|
232
|
+
* @param year - The year.
|
|
233
|
+
* @param month - The month (0-11).
|
|
234
|
+
* @param leadingDays - Array of leading day objects.
|
|
235
|
+
* @param monthDays - Array of current month day objects.
|
|
236
|
+
* @returns An array of trailing day objects.
|
|
237
|
+
*/
|
|
160
238
|
const getTrailingDays = (
|
|
161
239
|
year: number,
|
|
162
240
|
month: number,
|
|
163
241
|
leadingDays: { date: Date; month: string }[],
|
|
164
|
-
monthDays: { date: Date; month: string }[]
|
|
242
|
+
monthDays: { date: Date; month: string }[]
|
|
165
243
|
) => {
|
|
166
244
|
const dates = []
|
|
167
245
|
const days = 42 - (leadingDays.length + monthDays.length)
|
|
@@ -175,17 +253,38 @@ const getTrailingDays = (
|
|
|
175
253
|
return dates
|
|
176
254
|
}
|
|
177
255
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
)
|
|
256
|
+
/**
|
|
257
|
+
* Calculates the ISO week number for a given date.
|
|
258
|
+
* @param date - The date to calculate the week number for.
|
|
259
|
+
* @returns The ISO week number.
|
|
260
|
+
*/
|
|
261
|
+
export const getWeekNumber = (date: Date): number => {
|
|
262
|
+
const tempDate = new Date(date.getTime())
|
|
263
|
+
tempDate.setHours(0, 0, 0, 0)
|
|
264
|
+
|
|
265
|
+
// Thursday in current week decides the year
|
|
266
|
+
tempDate.setDate(tempDate.getDate() + 3 - ((tempDate.getDay() + 6) % 7))
|
|
267
|
+
|
|
268
|
+
const week1 = new Date(tempDate.getFullYear(), 0, 4)
|
|
269
|
+
|
|
270
|
+
// Calculate full weeks to the date
|
|
271
|
+
const weekNumber = 1 + Math.round((tempDate.getTime() - week1.getTime()) / 86_400_000 / 7)
|
|
272
|
+
|
|
273
|
+
return weekNumber
|
|
186
274
|
}
|
|
187
275
|
|
|
188
|
-
|
|
276
|
+
/**
|
|
277
|
+
* Retrieves detailed information about each week in a month for calendar rendering.
|
|
278
|
+
* @param year - The year.
|
|
279
|
+
* @param month - The month (0-11).
|
|
280
|
+
* @param firstDayOfWeek - The first day of the week (0-6, where 0 is Sunday).
|
|
281
|
+
* @returns An array of week objects containing week numbers and day details.
|
|
282
|
+
*/
|
|
283
|
+
export const getMonthDetails = (
|
|
284
|
+
year: number,
|
|
285
|
+
month: number,
|
|
286
|
+
firstDayOfWeek: number
|
|
287
|
+
): { weekNumber?: number; days: { date: Date; month: string }[] }[] => {
|
|
189
288
|
const daysPrevMonth = getLeadingDays(year, month, firstDayOfWeek)
|
|
190
289
|
const daysThisMonth = getMonthDays(year, month)
|
|
191
290
|
const daysNextMonth = getTrailingDays(year, month, daysPrevMonth, daysThisMonth)
|
|
@@ -209,35 +308,20 @@ export const getMonthDetails = (year: number, month: number, firstDayOfWeek: num
|
|
|
209
308
|
return weeks
|
|
210
309
|
}
|
|
211
310
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
while (date < endDate) {
|
|
222
|
-
date.setDate(date.getDate() + 1)
|
|
223
|
-
if (isDateDisabled(date, null, null, disabledDates)) {
|
|
224
|
-
disabled = true
|
|
225
|
-
break
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return disabled
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return false
|
|
233
|
-
}
|
|
234
|
-
|
|
311
|
+
/**
|
|
312
|
+
* Checks if a date is disabled based on the 'date' period type.
|
|
313
|
+
* @param date - The date to check.
|
|
314
|
+
* @param min - Minimum allowed date.
|
|
315
|
+
* @param max - Maximum allowed date.
|
|
316
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
317
|
+
* @returns True if the date is disabled, false otherwise.
|
|
318
|
+
*/
|
|
235
319
|
export const isDateDisabled = (
|
|
236
320
|
date: Date,
|
|
237
321
|
min?: Date | null,
|
|
238
322
|
max?: Date | null,
|
|
239
|
-
disabledDates?: DisabledDate | DisabledDate[]
|
|
240
|
-
) => {
|
|
323
|
+
disabledDates?: DisabledDate | DisabledDate[]
|
|
324
|
+
): boolean => {
|
|
241
325
|
if (min && date < min) {
|
|
242
326
|
return true
|
|
243
327
|
}
|
|
@@ -246,6 +330,10 @@ export const isDateDisabled = (
|
|
|
246
330
|
return true
|
|
247
331
|
}
|
|
248
332
|
|
|
333
|
+
if (disabledDates === undefined) {
|
|
334
|
+
return false
|
|
335
|
+
}
|
|
336
|
+
|
|
249
337
|
if (typeof disabledDates === 'function') {
|
|
250
338
|
return disabledDates(date)
|
|
251
339
|
}
|
|
@@ -273,31 +361,164 @@ export const isDateDisabled = (
|
|
|
273
361
|
return false
|
|
274
362
|
}
|
|
275
363
|
|
|
276
|
-
|
|
364
|
+
/**
|
|
365
|
+
* Checks if a date is within a specified range.
|
|
366
|
+
* @param date - The date to check.
|
|
367
|
+
* @param start - Start date of the range.
|
|
368
|
+
* @param end - End date of the range.
|
|
369
|
+
* @returns True if the date is within the range, false otherwise.
|
|
370
|
+
*/
|
|
371
|
+
export const isDateInRange = (date: Date, start: Date | null, end: Date | null): boolean => {
|
|
277
372
|
const _date = removeTimeFromDate(date)
|
|
278
373
|
const _start = start ? removeTimeFromDate(start) : null
|
|
279
374
|
const _end = end ? removeTimeFromDate(end) : null
|
|
280
375
|
|
|
281
|
-
return _start && _end && _start <= _date && _date <= _end
|
|
376
|
+
return !!(_start && _end && _start <= _date && _date <= _end)
|
|
282
377
|
}
|
|
283
378
|
|
|
284
|
-
|
|
285
|
-
|
|
379
|
+
/**
|
|
380
|
+
* Checks if a date is selected based on start and end dates.
|
|
381
|
+
* @param date - The date to check.
|
|
382
|
+
* @param start - Start date.
|
|
383
|
+
* @param end - End date.
|
|
384
|
+
* @returns True if the date is selected, false otherwise.
|
|
385
|
+
*/
|
|
386
|
+
export const isDateSelected = (date: Date, start: Date | null, end: Date | null): boolean => {
|
|
387
|
+
if (start !== null && isSameDateAs(start, date)) {
|
|
388
|
+
return true
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (end !== null && isSameDateAs(end, date)) {
|
|
392
|
+
return true
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return false
|
|
286
396
|
}
|
|
287
397
|
|
|
288
|
-
|
|
289
|
-
|
|
398
|
+
/**
|
|
399
|
+
* Determines if any date within a range is disabled.
|
|
400
|
+
* @param startDate - Start date of the range.
|
|
401
|
+
* @param endDate - End date of the range.
|
|
402
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
403
|
+
* @returns True if any date in the range is disabled, false otherwise.
|
|
404
|
+
*/
|
|
405
|
+
export const isDisableDateInRange = (
|
|
406
|
+
startDate?: Date | null,
|
|
407
|
+
endDate?: Date | null,
|
|
408
|
+
disabledDates?: DisabledDate | DisabledDate[]
|
|
409
|
+
): boolean => {
|
|
410
|
+
if (startDate && endDate) {
|
|
411
|
+
const date = new Date(startDate)
|
|
412
|
+
let disabled = false
|
|
413
|
+
|
|
414
|
+
while (date < endDate) {
|
|
415
|
+
date.setDate(date.getDate() + 1)
|
|
416
|
+
if (isDateDisabled(date, null, null, disabledDates)) {
|
|
417
|
+
disabled = true
|
|
418
|
+
break
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return disabled
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return false
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Checks if a month is disabled based on the 'month' period type.
|
|
430
|
+
* @param date - The date representing the month to check.
|
|
431
|
+
* @param min - Minimum allowed date.
|
|
432
|
+
* @param max - Maximum allowed date.
|
|
433
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
434
|
+
* @returns True if the month is disabled, false otherwise.
|
|
435
|
+
*/
|
|
436
|
+
export const isMonthDisabled = (
|
|
437
|
+
date: Date,
|
|
438
|
+
min?: Date | null,
|
|
439
|
+
max?: Date | null,
|
|
440
|
+
disabledDates?: DisabledDate | DisabledDate[]
|
|
441
|
+
) => {
|
|
442
|
+
const current = date.getFullYear() * 12 + date.getMonth()
|
|
443
|
+
const _min = min ? min.getFullYear() * 12 + min.getMonth() : null
|
|
444
|
+
const _max = max ? max.getFullYear() * 12 + max.getMonth() : null
|
|
445
|
+
|
|
446
|
+
if (_min && current < _min) {
|
|
447
|
+
return true
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (_max && current > _max) {
|
|
451
|
+
return true
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (disabledDates === undefined) {
|
|
455
|
+
return false
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const start = min ? Math.max(date.getTime(), min.getTime()) : date
|
|
459
|
+
const end = max
|
|
460
|
+
? Math.min(date.getTime(), max.getTime())
|
|
461
|
+
: new Date(new Date().getFullYear(), 11, 31)
|
|
462
|
+
|
|
463
|
+
for (
|
|
464
|
+
const currentDate = new Date(start);
|
|
465
|
+
currentDate <= end;
|
|
466
|
+
currentDate.setDate(currentDate.getDate() + 1)
|
|
467
|
+
) {
|
|
468
|
+
if (!isDateDisabled(currentDate, min, max, disabledDates)) {
|
|
469
|
+
return false
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return false
|
|
290
474
|
}
|
|
291
475
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
476
|
+
/**
|
|
477
|
+
* Checks if a month is selected based on start and end dates.
|
|
478
|
+
* @param date - The date representing the month.
|
|
479
|
+
* @param start - Start date.
|
|
480
|
+
* @param end - End date.
|
|
481
|
+
* @returns True if the month is selected, false otherwise.
|
|
482
|
+
*/
|
|
483
|
+
export const isMonthSelected = (date: Date, start: Date | null, end: Date | null): boolean => {
|
|
484
|
+
const year = date.getFullYear()
|
|
485
|
+
const month = date.getMonth()
|
|
486
|
+
|
|
487
|
+
if (start !== null && year === start.getFullYear() && month === start.getMonth()) {
|
|
488
|
+
return true
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (end !== null && year === end.getFullYear() && month === end.getMonth()) {
|
|
492
|
+
return true
|
|
493
|
+
}
|
|
295
494
|
|
|
296
|
-
|
|
297
|
-
|
|
495
|
+
return false
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Checks if a month is within a specified range.
|
|
500
|
+
* @param date - The date representing the month.
|
|
501
|
+
* @param start - Start date.
|
|
502
|
+
* @param end - End date.
|
|
503
|
+
* @returns True if the month is within the range, false otherwise.
|
|
504
|
+
*/
|
|
505
|
+
export const isMonthInRange = (date: Date, start: Date | null, end: Date | null): boolean => {
|
|
506
|
+
const year = date.getFullYear()
|
|
507
|
+
const month = date.getMonth()
|
|
508
|
+
const _start = start ? start.getFullYear() * 12 + start.getMonth() : null
|
|
509
|
+
const _end = end ? end.getFullYear() * 12 + end.getMonth() : null
|
|
510
|
+
const _date = year * 12 + month
|
|
511
|
+
|
|
512
|
+
return !!(_start && _end && _start <= _date && _date <= _end)
|
|
298
513
|
}
|
|
299
514
|
|
|
300
|
-
|
|
515
|
+
/**
|
|
516
|
+
* Checks if two dates are the same calendar date.
|
|
517
|
+
* @param date - First date.
|
|
518
|
+
* @param date2 - Second date.
|
|
519
|
+
* @returns True if both dates are the same, false otherwise.
|
|
520
|
+
*/
|
|
521
|
+
export const isSameDateAs = (date: Date | null, date2: Date | null): boolean => {
|
|
301
522
|
if (date instanceof Date && date2 instanceof Date) {
|
|
302
523
|
return (
|
|
303
524
|
date.getDate() === date2.getDate() &&
|
|
@@ -313,23 +534,130 @@ export const isSameDateAs = (date: Date | null, date2: Date | null) => {
|
|
|
313
534
|
return false
|
|
314
535
|
}
|
|
315
536
|
|
|
316
|
-
|
|
317
|
-
|
|
537
|
+
/**
|
|
538
|
+
* Checks if a date is today.
|
|
539
|
+
* @param date - The date to check.
|
|
540
|
+
* @returns True if the date is today, false otherwise.
|
|
541
|
+
*/
|
|
542
|
+
export const isToday = (date: Date): boolean => {
|
|
543
|
+
const today = new Date()
|
|
544
|
+
return isSameDateAs(date, today)
|
|
318
545
|
}
|
|
319
546
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
547
|
+
/**
|
|
548
|
+
* Checks if a year is disabled based on the 'year' period type.
|
|
549
|
+
* @param date - The date representing the year to check.
|
|
550
|
+
* @param min - Minimum allowed date.
|
|
551
|
+
* @param max - Maximum allowed date.
|
|
552
|
+
* @param disabledDates - Criteria for disabled dates.
|
|
553
|
+
* @returns True if the year is disabled, false otherwise.
|
|
554
|
+
*/
|
|
555
|
+
export const isYearDisabled = (
|
|
556
|
+
date: Date,
|
|
557
|
+
min?: Date | null,
|
|
558
|
+
max?: Date | null,
|
|
559
|
+
disabledDates?: DisabledDate | DisabledDate[]
|
|
560
|
+
) => {
|
|
561
|
+
const year = date.getFullYear()
|
|
562
|
+
const minYear = min ? min.getFullYear() : null
|
|
563
|
+
const maxYear = max ? max.getFullYear() : null
|
|
564
|
+
|
|
565
|
+
if (minYear && year < minYear) {
|
|
566
|
+
return true
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (maxYear && year > maxYear) {
|
|
570
|
+
return true
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (disabledDates === undefined) {
|
|
574
|
+
return false
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
const start = min ? Math.max(date.getTime(), min.getTime()) : date
|
|
578
|
+
const end = max
|
|
579
|
+
? Math.min(date.getTime(), max.getTime())
|
|
580
|
+
: new Date(new Date().getFullYear(), 11, 31)
|
|
581
|
+
|
|
582
|
+
for (
|
|
583
|
+
const currentDate = new Date(start);
|
|
584
|
+
currentDate <= end;
|
|
585
|
+
currentDate.setDate(currentDate.getDate() + 1)
|
|
586
|
+
) {
|
|
587
|
+
if (!isDateDisabled(currentDate, min, max, disabledDates)) {
|
|
588
|
+
return false
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
return false
|
|
327
593
|
}
|
|
328
594
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
595
|
+
/**
|
|
596
|
+
* Checks if a year is selected based on start and end dates.
|
|
597
|
+
* @param date - The date representing the year.
|
|
598
|
+
* @param start - Start date.
|
|
599
|
+
* @param end - End date.
|
|
600
|
+
* @returns True if the year matches the start's or end's year, false otherwise.
|
|
601
|
+
*/
|
|
602
|
+
export const isYearSelected = (date: Date, start: Date | null, end: Date | null): boolean => {
|
|
603
|
+
const year = date.getFullYear()
|
|
604
|
+
|
|
605
|
+
if (start !== null && year === start.getFullYear()) {
|
|
606
|
+
return true
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (end !== null && year === end.getFullYear()) {
|
|
610
|
+
return true
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return false
|
|
332
614
|
}
|
|
333
615
|
|
|
334
|
-
|
|
335
|
-
|
|
616
|
+
/**
|
|
617
|
+
* Checks if a year is within a specified range.
|
|
618
|
+
* @param date - The date representing the year.
|
|
619
|
+
* @param start - Start date.
|
|
620
|
+
* @param end - End date.
|
|
621
|
+
* @returns True if the year's value lies between start's year and end's year, false otherwise.
|
|
622
|
+
*/
|
|
623
|
+
export const isYearInRange = (date: Date, start: Date | null, end: Date | null): boolean => {
|
|
624
|
+
const year = date.getFullYear()
|
|
625
|
+
const _start = start ? start.getFullYear() : null
|
|
626
|
+
const _end = end ? end.getFullYear() : null
|
|
627
|
+
|
|
628
|
+
return !!(_start && _end && _start <= year && year <= _end)
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Removes the time component from a Date object.
|
|
633
|
+
* @param date - The original date.
|
|
634
|
+
* @returns A new Date object with the time set to 00:00:00.
|
|
635
|
+
*/
|
|
636
|
+
export const removeTimeFromDate = (date: Date): Date => {
|
|
637
|
+
const clearedDate = new Date(date)
|
|
638
|
+
clearedDate.setHours(0, 0, 0, 0)
|
|
639
|
+
return clearedDate
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Copies the time (hours, minutes, seconds, milliseconds) from one Date to another.
|
|
644
|
+
*
|
|
645
|
+
* @param {Date} target - The date whose time will be updated.
|
|
646
|
+
* @param {Date | null} source - The date to copy the time from.
|
|
647
|
+
* @returns {Date} A new Date instance with the date from `target` and time from `source`.
|
|
648
|
+
*/
|
|
649
|
+
export const setTimeFromDate = (target: Date, source: Date | null): Date => {
|
|
650
|
+
if (!(source instanceof Date)) {
|
|
651
|
+
return target
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const result = new Date(target) // create a copy to avoid mutation
|
|
655
|
+
result.setHours(
|
|
656
|
+
source.getHours(),
|
|
657
|
+
source.getMinutes(),
|
|
658
|
+
source.getSeconds(),
|
|
659
|
+
source.getMilliseconds()
|
|
660
|
+
)
|
|
661
|
+
|
|
662
|
+
return result
|
|
663
|
+
}
|
|
@@ -3,7 +3,7 @@ import { defineComponent, h, PropType } from 'vue'
|
|
|
3
3
|
import { CDateRangePicker } from '../date-range-picker/'
|
|
4
4
|
|
|
5
5
|
import { Color } from '../props'
|
|
6
|
-
import type { DisabledDate } from '../calendar/
|
|
6
|
+
import type { DisabledDate } from '../calendar/types'
|
|
7
7
|
|
|
8
8
|
const CDatePicker = defineComponent({
|
|
9
9
|
name: 'CDatePicker',
|
|
@@ -12,7 +12,7 @@ import { getInputIdOrName, getLocalDateFromString } from './utils'
|
|
|
12
12
|
import { useDebouncedCallback } from '../../composables'
|
|
13
13
|
import { Color } from '../props'
|
|
14
14
|
|
|
15
|
-
import type { DisabledDate } from '../calendar/
|
|
15
|
+
import type { DisabledDate } from '../calendar/types'
|
|
16
16
|
|
|
17
17
|
const CDateRangePicker = defineComponent({
|
|
18
18
|
name: 'CDateRangePicker',
|