react-day-picker 9.13.1 → 9.14.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/DayPicker.js +1 -1
- package/dist/cjs/UI.d.ts +21 -14
- package/dist/cjs/UI.js +2 -2
- package/dist/cjs/hijri/index.d.ts +28 -0
- package/dist/cjs/hijri/index.js +98 -0
- package/dist/cjs/hijri/lib/addMonths.d.ts +1 -0
- package/dist/cjs/hijri/lib/addMonths.js +9 -0
- package/dist/cjs/hijri/lib/addYears.d.ts +1 -0
- package/dist/cjs/hijri/lib/addYears.js +9 -0
- package/dist/cjs/hijri/lib/differenceInCalendarMonths.d.ts +1 -0
- package/dist/cjs/hijri/lib/differenceInCalendarMonths.js +10 -0
- package/dist/cjs/hijri/lib/eachMonthOfInterval.d.ts +2 -0
- package/dist/cjs/hijri/lib/eachMonthOfInterval.js +29 -0
- package/dist/cjs/hijri/lib/eachYearOfInterval.d.ts +2 -0
- package/dist/cjs/hijri/lib/eachYearOfInterval.js +19 -0
- package/dist/cjs/hijri/lib/endOfMonth.d.ts +1 -0
- package/dist/cjs/hijri/lib/endOfMonth.js +14 -0
- package/dist/cjs/hijri/lib/endOfYear.d.ts +1 -0
- package/dist/cjs/hijri/lib/endOfYear.js +14 -0
- package/dist/cjs/hijri/lib/fallbackLocaleData.d.ts +5 -0
- package/dist/cjs/hijri/lib/fallbackLocaleData.js +111 -0
- package/dist/cjs/hijri/lib/format.d.ts +3 -0
- package/dist/cjs/hijri/lib/format.js +149 -0
- package/dist/cjs/hijri/lib/getMonth.d.ts +1 -0
- package/dist/cjs/hijri/lib/getMonth.js +7 -0
- package/dist/cjs/hijri/lib/getYear.d.ts +1 -0
- package/dist/cjs/hijri/lib/getYear.js +7 -0
- package/dist/cjs/hijri/lib/index.d.ts +17 -0
- package/dist/cjs/hijri/lib/index.js +33 -0
- package/dist/cjs/hijri/lib/isSameMonth.d.ts +1 -0
- package/dist/cjs/hijri/lib/isSameMonth.js +10 -0
- package/dist/cjs/hijri/lib/isSameYear.d.ts +1 -0
- package/dist/cjs/hijri/lib/isSameYear.js +9 -0
- package/dist/cjs/hijri/lib/newDate.d.ts +1 -0
- package/dist/cjs/hijri/lib/newDate.js +7 -0
- package/dist/cjs/hijri/lib/setMonth.d.ts +1 -0
- package/dist/cjs/hijri/lib/setMonth.js +27 -0
- package/dist/cjs/hijri/lib/setYear.d.ts +1 -0
- package/dist/cjs/hijri/lib/setYear.js +15 -0
- package/dist/cjs/hijri/lib/startOfMonth.d.ts +1 -0
- package/dist/cjs/hijri/lib/startOfMonth.js +12 -0
- package/dist/cjs/hijri/lib/startOfYear.d.ts +1 -0
- package/dist/cjs/hijri/lib/startOfYear.js +12 -0
- package/dist/cjs/hijri/utils/conversion.d.ts +5 -0
- package/dist/cjs/hijri/utils/conversion.js +40 -0
- package/dist/cjs/hijri/utils/daysInMonth.d.ts +1 -0
- package/dist/cjs/hijri/utils/daysInMonth.js +24 -0
- package/dist/cjs/hijri/utils/range.d.ts +21 -0
- package/dist/cjs/hijri/utils/range.js +104 -0
- package/dist/cjs/hijri/utils/types.d.ts +5 -0
- package/dist/cjs/hijri/utils/types.js +2 -0
- package/dist/cjs/locale/ja-Hira.js +1 -1
- package/dist/cjs/locale/se.js +2 -2
- package/dist/cjs/selection/useRange.js +22 -4
- package/dist/cjs/types/props.d.ts +27 -3
- package/dist/esm/DayPicker.js +1 -1
- package/dist/esm/UI.d.ts +21 -14
- package/dist/esm/UI.js +2 -2
- package/dist/esm/hijri/index.d.ts +28 -0
- package/dist/esm/hijri/index.js +55 -0
- package/dist/esm/hijri/lib/addMonths.d.ts +1 -0
- package/dist/esm/hijri/lib/addMonths.js +6 -0
- package/dist/esm/hijri/lib/addYears.d.ts +1 -0
- package/dist/esm/hijri/lib/addYears.js +6 -0
- package/dist/esm/hijri/lib/differenceInCalendarMonths.d.ts +1 -0
- package/dist/esm/hijri/lib/differenceInCalendarMonths.js +7 -0
- package/dist/esm/hijri/lib/eachMonthOfInterval.d.ts +2 -0
- package/dist/esm/hijri/lib/eachMonthOfInterval.js +26 -0
- package/dist/esm/hijri/lib/eachYearOfInterval.d.ts +2 -0
- package/dist/esm/hijri/lib/eachYearOfInterval.js +16 -0
- package/dist/esm/hijri/lib/endOfMonth.d.ts +1 -0
- package/dist/esm/hijri/lib/endOfMonth.js +11 -0
- package/dist/esm/hijri/lib/endOfYear.d.ts +1 -0
- package/dist/esm/hijri/lib/endOfYear.js +11 -0
- package/dist/esm/hijri/lib/fallbackLocaleData.d.ts +5 -0
- package/dist/esm/hijri/lib/fallbackLocaleData.js +105 -0
- package/dist/esm/hijri/lib/format.d.ts +3 -0
- package/dist/esm/hijri/lib/format.js +146 -0
- package/dist/esm/hijri/lib/getMonth.d.ts +1 -0
- package/dist/esm/hijri/lib/getMonth.js +4 -0
- package/dist/esm/hijri/lib/getYear.d.ts +1 -0
- package/dist/esm/hijri/lib/getYear.js +4 -0
- package/dist/esm/hijri/lib/index.d.ts +17 -0
- package/dist/esm/hijri/lib/index.js +17 -0
- package/dist/esm/hijri/lib/isSameMonth.d.ts +1 -0
- package/dist/esm/hijri/lib/isSameMonth.js +7 -0
- package/dist/esm/hijri/lib/isSameYear.d.ts +1 -0
- package/dist/esm/hijri/lib/isSameYear.js +6 -0
- package/dist/esm/hijri/lib/newDate.d.ts +1 -0
- package/dist/esm/hijri/lib/newDate.js +4 -0
- package/dist/esm/hijri/lib/setMonth.d.ts +1 -0
- package/dist/esm/hijri/lib/setMonth.js +24 -0
- package/dist/esm/hijri/lib/setYear.d.ts +1 -0
- package/dist/esm/hijri/lib/setYear.js +12 -0
- package/dist/esm/hijri/lib/startOfMonth.d.ts +1 -0
- package/dist/esm/hijri/lib/startOfMonth.js +9 -0
- package/dist/esm/hijri/lib/startOfYear.d.ts +1 -0
- package/dist/esm/hijri/lib/startOfYear.js +9 -0
- package/dist/esm/hijri/utils/conversion.d.ts +5 -0
- package/dist/esm/hijri/utils/conversion.js +36 -0
- package/dist/esm/hijri/utils/daysInMonth.d.ts +1 -0
- package/dist/esm/hijri/utils/daysInMonth.js +21 -0
- package/dist/esm/hijri/utils/range.d.ts +21 -0
- package/dist/esm/hijri/utils/range.js +96 -0
- package/dist/esm/hijri/utils/types.d.ts +5 -0
- package/dist/esm/hijri/utils/types.js +1 -0
- package/dist/esm/locale/ja-Hira.js +1 -1
- package/dist/esm/locale/se.js +2 -2
- package/dist/esm/selection/useRange.js +22 -4
- package/dist/esm/types/props.d.ts +27 -3
- package/hijri.d.ts +1 -0
- package/hijri.js +2 -0
- package/package.json +26 -13
- package/src/style.css.d.ts +3 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./addMonths.js";
|
|
2
|
+
export * from "./addYears.js";
|
|
3
|
+
export * from "./differenceInCalendarMonths.js";
|
|
4
|
+
export * from "./eachMonthOfInterval.js";
|
|
5
|
+
export * from "./eachYearOfInterval.js";
|
|
6
|
+
export * from "./endOfMonth.js";
|
|
7
|
+
export * from "./endOfYear.js";
|
|
8
|
+
export * from "./format.js";
|
|
9
|
+
export * from "./getMonth.js";
|
|
10
|
+
export * from "./getYear.js";
|
|
11
|
+
export * from "./isSameMonth.js";
|
|
12
|
+
export * from "./isSameYear.js";
|
|
13
|
+
export * from "./newDate.js";
|
|
14
|
+
export * from "./setMonth.js";
|
|
15
|
+
export * from "./setYear.js";
|
|
16
|
+
export * from "./startOfMonth.js";
|
|
17
|
+
export * from "./startOfYear.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./addMonths.js";
|
|
2
|
+
export * from "./addYears.js";
|
|
3
|
+
export * from "./differenceInCalendarMonths.js";
|
|
4
|
+
export * from "./eachMonthOfInterval.js";
|
|
5
|
+
export * from "./eachYearOfInterval.js";
|
|
6
|
+
export * from "./endOfMonth.js";
|
|
7
|
+
export * from "./endOfYear.js";
|
|
8
|
+
export * from "./format.js";
|
|
9
|
+
export * from "./getMonth.js";
|
|
10
|
+
export * from "./getYear.js";
|
|
11
|
+
export * from "./isSameMonth.js";
|
|
12
|
+
export * from "./isSameYear.js";
|
|
13
|
+
export * from "./newDate.js";
|
|
14
|
+
export * from "./setMonth.js";
|
|
15
|
+
export * from "./setYear.js";
|
|
16
|
+
export * from "./startOfMonth.js";
|
|
17
|
+
export * from "./startOfYear.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isSameMonth(dateLeft: Date, dateRight: Date): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { toHijriDate } from "../utils/conversion.js";
|
|
2
|
+
export function isSameMonth(dateLeft, dateRight) {
|
|
3
|
+
const hijriLeft = toHijriDate(dateLeft);
|
|
4
|
+
const hijriRight = toHijriDate(dateRight);
|
|
5
|
+
return (hijriLeft.year === hijriRight.year &&
|
|
6
|
+
hijriLeft.monthIndex === hijriRight.monthIndex);
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isSameYear(dateLeft: Date, dateRight: Date): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function newDate(year: number, monthIndex: number, day: number): Date;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setMonth(date: Date, monthIndex: number): Date;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { toGregorianDate, toHijriDate } from "../utils/conversion.js";
|
|
2
|
+
import { getDaysInMonth } from "../utils/daysInMonth.js";
|
|
3
|
+
export function setMonth(date, monthIndex) {
|
|
4
|
+
const hijri = toHijriDate(date);
|
|
5
|
+
// Handle overflow/underflow of monthIndex
|
|
6
|
+
// Note: monthIndex argument is absolute month index for the year.
|
|
7
|
+
// E.g. setMonth(..., 13) sets to Safar next year.
|
|
8
|
+
let targetYear = hijri.year;
|
|
9
|
+
let targetMonth = monthIndex;
|
|
10
|
+
if (targetMonth > 11 || targetMonth < 0) {
|
|
11
|
+
targetYear += Math.floor(targetMonth / 12);
|
|
12
|
+
targetMonth = targetMonth % 12;
|
|
13
|
+
if (targetMonth < 0) {
|
|
14
|
+
targetMonth += 12;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const daysInTargetMonth = getDaysInMonth(targetYear, targetMonth);
|
|
18
|
+
const day = Math.min(hijri.day, daysInTargetMonth);
|
|
19
|
+
return toGregorianDate({
|
|
20
|
+
year: targetYear,
|
|
21
|
+
monthIndex: targetMonth,
|
|
22
|
+
day,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setYear(date: Date, year: number): Date;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { toGregorianDate, toHijriDate } from "../utils/conversion.js";
|
|
2
|
+
import { getDaysInMonth } from "../utils/daysInMonth.js";
|
|
3
|
+
export function setYear(date, year) {
|
|
4
|
+
const hijri = toHijriDate(date);
|
|
5
|
+
const daysInTargetMonth = getDaysInMonth(year, hijri.monthIndex);
|
|
6
|
+
const day = Math.min(hijri.day, daysInTargetMonth);
|
|
7
|
+
return toGregorianDate({
|
|
8
|
+
year,
|
|
9
|
+
monthIndex: hijri.monthIndex,
|
|
10
|
+
day,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function startOfMonth(date: Date): Date;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function startOfYear(date: Date): Date;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { HijriDate } from "./types.js";
|
|
2
|
+
/** Convert a Gregorian date to a Hijri date. */
|
|
3
|
+
export declare function toHijriDate(date: Date): HijriDate;
|
|
4
|
+
/** Convert a Hijri date back to the Gregorian calendar. */
|
|
5
|
+
export declare function toGregorianDate(hijri: HijriDate): Date;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { gregorianToHijri, hijriToGregorian } from "@tabby_ai/hijri-converter";
|
|
2
|
+
import { clampGregorianDate, clampHijriDate, GREGORIAN_MIN_DATE, getGregorianDateParts, } from "./range.js";
|
|
3
|
+
/** Convert a Gregorian date to a Hijri date. */
|
|
4
|
+
export function toHijriDate(date) {
|
|
5
|
+
const clamped = clampGregorianDate(date);
|
|
6
|
+
const { year, month, day } = getGregorianDateParts(clamped);
|
|
7
|
+
// gregorianToHijri uses 1-indexed months
|
|
8
|
+
const hijri = gregorianToHijri({ year, month, day });
|
|
9
|
+
return {
|
|
10
|
+
year: hijri.year,
|
|
11
|
+
monthIndex: hijri.month - 1, // Convert to 0-indexed
|
|
12
|
+
day: hijri.day,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Convert a Hijri date back to the Gregorian calendar. */
|
|
16
|
+
export function toGregorianDate(hijri) {
|
|
17
|
+
const clamped = clampHijriDate(hijri);
|
|
18
|
+
// hijriToGregorian expects 1-indexed months. Probe down from the candidate
|
|
19
|
+
// day to handle invalid month/day combinations without throwing.
|
|
20
|
+
for (let day = clamped.day; day >= 1; day -= 1) {
|
|
21
|
+
try {
|
|
22
|
+
const gregorian = hijriToGregorian({
|
|
23
|
+
year: clamped.year,
|
|
24
|
+
month: clamped.monthIndex + 1,
|
|
25
|
+
day,
|
|
26
|
+
});
|
|
27
|
+
return clampGregorianDate(new Date(gregorian.year, gregorian.month - 1, gregorian.day));
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Try a lower day for months that only have 29 days.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Fallback to the minimum supported Gregorian date if conversion probing
|
|
34
|
+
// somehow fails for all days.
|
|
35
|
+
return new Date(GREGORIAN_MIN_DATE);
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDaysInMonth(year: number, monthIndex: number): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { toGregorianDate, toHijriDate } from "./conversion.js";
|
|
2
|
+
import { clampHijriDate } from "./range.js";
|
|
3
|
+
const MAX_DAY_IN_HIJRI_MONTH = 30;
|
|
4
|
+
const MIN_DAY_IN_HIJRI_MONTH = 29;
|
|
5
|
+
export function getDaysInMonth(year, monthIndex) {
|
|
6
|
+
const clamped = clampHijriDate({ year, monthIndex, day: 1 });
|
|
7
|
+
for (let day = MAX_DAY_IN_HIJRI_MONTH; day >= MIN_DAY_IN_HIJRI_MONTH; day -= 1) {
|
|
8
|
+
const candidateDate = toGregorianDate({
|
|
9
|
+
year: clamped.year,
|
|
10
|
+
monthIndex: clamped.monthIndex,
|
|
11
|
+
day,
|
|
12
|
+
});
|
|
13
|
+
const roundTrip = toHijriDate(candidateDate);
|
|
14
|
+
if (roundTrip.year === clamped.year &&
|
|
15
|
+
roundTrip.monthIndex === clamped.monthIndex &&
|
|
16
|
+
roundTrip.day === day) {
|
|
17
|
+
return day;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return MIN_DAY_IN_HIJRI_MONTH;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HijriDate } from "./types.js";
|
|
2
|
+
type GregorianDateParts = {
|
|
3
|
+
year: number;
|
|
4
|
+
month: number;
|
|
5
|
+
day: number;
|
|
6
|
+
};
|
|
7
|
+
/** Returns Gregorian date parts while preserving years < 100. */
|
|
8
|
+
export declare function getGregorianDateParts(date: Date): GregorianDateParts;
|
|
9
|
+
/** Internal Gregorian lower bound supported by the Hijri converter. */
|
|
10
|
+
export declare const GREGORIAN_MIN_DATE: Date;
|
|
11
|
+
/** Internal Gregorian upper bound supported by the Hijri converter. */
|
|
12
|
+
export declare const GREGORIAN_MAX_DATE: Date;
|
|
13
|
+
/** Clamp a Gregorian date to the supported Hijri conversion range. */
|
|
14
|
+
export declare function clampGregorianDate(date: Date): Date;
|
|
15
|
+
/** Returns whether the provided Gregorian date was clamped. */
|
|
16
|
+
export declare function wasGregorianDateClamped(date: Date): boolean;
|
|
17
|
+
/** Clamp a Hijri date to the supported range and normalize month overflow. */
|
|
18
|
+
export declare function clampHijriDate(date: HijriDate): HijriDate;
|
|
19
|
+
/** Returns whether the provided Hijri date was clamped. */
|
|
20
|
+
export declare function wasHijriDateClamped(date: HijriDate): boolean;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const MAX_HIJRI_DAY = 30;
|
|
2
|
+
const MONTHS_PER_YEAR = 12;
|
|
3
|
+
const HIJRI_MIN = { year: 1343, monthIndex: 0, day: 1 };
|
|
4
|
+
const HIJRI_MAX = { year: 1500, monthIndex: 11, day: 30 };
|
|
5
|
+
const GREGORIAN_MIN = { year: 1924, month: 8, day: 1 };
|
|
6
|
+
const GREGORIAN_MAX = { year: 2077, month: 11, day: 16 };
|
|
7
|
+
function compareGregorianDates(left, right) {
|
|
8
|
+
if (left.year !== right.year) {
|
|
9
|
+
return left.year - right.year;
|
|
10
|
+
}
|
|
11
|
+
if (left.month !== right.month) {
|
|
12
|
+
return left.month - right.month;
|
|
13
|
+
}
|
|
14
|
+
return left.day - right.day;
|
|
15
|
+
}
|
|
16
|
+
function createDate(parts) {
|
|
17
|
+
return new Date(parts.year, parts.month - 1, parts.day);
|
|
18
|
+
}
|
|
19
|
+
function normalizeHijriMonth(year, monthIndex) {
|
|
20
|
+
let normalizedYear = year + Math.trunc(monthIndex / MONTHS_PER_YEAR);
|
|
21
|
+
let normalizedMonth = monthIndex % MONTHS_PER_YEAR;
|
|
22
|
+
if (normalizedMonth < 0) {
|
|
23
|
+
normalizedMonth += MONTHS_PER_YEAR;
|
|
24
|
+
normalizedYear -= 1;
|
|
25
|
+
}
|
|
26
|
+
return { year: normalizedYear, monthIndex: normalizedMonth };
|
|
27
|
+
}
|
|
28
|
+
/** Returns Gregorian date parts while preserving years < 100. */
|
|
29
|
+
export function getGregorianDateParts(date) {
|
|
30
|
+
const useUTC = date.getFullYear() < 100;
|
|
31
|
+
return {
|
|
32
|
+
year: useUTC ? date.getUTCFullYear() : date.getFullYear(),
|
|
33
|
+
month: (useUTC ? date.getUTCMonth() : date.getMonth()) + 1,
|
|
34
|
+
day: useUTC ? date.getUTCDate() : date.getDate(),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Internal Gregorian lower bound supported by the Hijri converter. */
|
|
38
|
+
export const GREGORIAN_MIN_DATE = createDate(GREGORIAN_MIN);
|
|
39
|
+
/** Internal Gregorian upper bound supported by the Hijri converter. */
|
|
40
|
+
export const GREGORIAN_MAX_DATE = createDate(GREGORIAN_MAX);
|
|
41
|
+
/** Clamp a Gregorian date to the supported Hijri conversion range. */
|
|
42
|
+
export function clampGregorianDate(date) {
|
|
43
|
+
const parts = getGregorianDateParts(date);
|
|
44
|
+
if (compareGregorianDates(parts, GREGORIAN_MIN) < 0) {
|
|
45
|
+
return createDate(GREGORIAN_MIN);
|
|
46
|
+
}
|
|
47
|
+
if (compareGregorianDates(parts, GREGORIAN_MAX) > 0) {
|
|
48
|
+
return createDate(GREGORIAN_MAX);
|
|
49
|
+
}
|
|
50
|
+
return date;
|
|
51
|
+
}
|
|
52
|
+
/** Returns whether the provided Gregorian date was clamped. */
|
|
53
|
+
export function wasGregorianDateClamped(date) {
|
|
54
|
+
return clampGregorianDate(date) !== date;
|
|
55
|
+
}
|
|
56
|
+
/** Clamp a Hijri date to the supported range and normalize month overflow. */
|
|
57
|
+
export function clampHijriDate(date) {
|
|
58
|
+
const normalized = normalizeHijriMonth(date.year, date.monthIndex);
|
|
59
|
+
const candidate = {
|
|
60
|
+
year: normalized.year,
|
|
61
|
+
monthIndex: normalized.monthIndex,
|
|
62
|
+
day: Math.min(Math.max(date.day, 1), MAX_HIJRI_DAY),
|
|
63
|
+
};
|
|
64
|
+
if (candidate.year < HIJRI_MIN.year) {
|
|
65
|
+
return { ...HIJRI_MIN };
|
|
66
|
+
}
|
|
67
|
+
if (candidate.year > HIJRI_MAX.year) {
|
|
68
|
+
return { ...HIJRI_MAX };
|
|
69
|
+
}
|
|
70
|
+
if (candidate.year === HIJRI_MIN.year &&
|
|
71
|
+
candidate.monthIndex < HIJRI_MIN.monthIndex) {
|
|
72
|
+
return { ...HIJRI_MIN };
|
|
73
|
+
}
|
|
74
|
+
if (candidate.year === HIJRI_MAX.year &&
|
|
75
|
+
candidate.monthIndex > HIJRI_MAX.monthIndex) {
|
|
76
|
+
return { ...HIJRI_MAX };
|
|
77
|
+
}
|
|
78
|
+
if (candidate.year === HIJRI_MIN.year &&
|
|
79
|
+
candidate.monthIndex === HIJRI_MIN.monthIndex &&
|
|
80
|
+
candidate.day < HIJRI_MIN.day) {
|
|
81
|
+
return { ...HIJRI_MIN };
|
|
82
|
+
}
|
|
83
|
+
if (candidate.year === HIJRI_MAX.year &&
|
|
84
|
+
candidate.monthIndex === HIJRI_MAX.monthIndex &&
|
|
85
|
+
candidate.day > HIJRI_MAX.day) {
|
|
86
|
+
return { ...HIJRI_MAX };
|
|
87
|
+
}
|
|
88
|
+
return candidate;
|
|
89
|
+
}
|
|
90
|
+
/** Returns whether the provided Hijri date was clamped. */
|
|
91
|
+
export function wasHijriDateClamped(date) {
|
|
92
|
+
const clamped = clampHijriDate(date);
|
|
93
|
+
return (clamped.year !== date.year ||
|
|
94
|
+
clamped.monthIndex !== date.monthIndex ||
|
|
95
|
+
clamped.day !== date.day);
|
|
96
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/locale/se.js
CHANGED
|
@@ -8,7 +8,7 @@ export const se = {
|
|
|
8
8
|
const lib = dateLib ?? new DateLib(options);
|
|
9
9
|
let label = lib.format(date, "PPPP");
|
|
10
10
|
if (modifiers.today)
|
|
11
|
-
label = `
|
|
11
|
+
label = `Odne, ${label}`;
|
|
12
12
|
if (modifiers.selected)
|
|
13
13
|
label = `${label}, válljejuvvon`;
|
|
14
14
|
return label;
|
|
@@ -23,7 +23,7 @@ export const se = {
|
|
|
23
23
|
const lib = dateLib ?? new DateLib(options);
|
|
24
24
|
let label = lib.format(date, "PPPP");
|
|
25
25
|
if (modifiers?.today) {
|
|
26
|
-
label = `
|
|
26
|
+
label = `Odne, ${label}`;
|
|
27
27
|
}
|
|
28
28
|
return label;
|
|
29
29
|
},
|
|
@@ -11,15 +11,33 @@ import { rangeIncludesDate } from "../utils/rangeIncludesDate.js";
|
|
|
11
11
|
* range, and a function to check if a date is within the range.
|
|
12
12
|
*/
|
|
13
13
|
export function useRange(props, dateLib) {
|
|
14
|
-
const { disabled, excludeDisabled, selected: initiallySelected, required, onSelect, } = props;
|
|
14
|
+
const { disabled, excludeDisabled, resetOnSelect, selected: initiallySelected, required, onSelect, } = props;
|
|
15
15
|
const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : undefined);
|
|
16
16
|
const selected = !onSelect ? internallySelected : initiallySelected;
|
|
17
17
|
const isSelected = (date) => selected && rangeIncludesDate(selected, date, false, dateLib);
|
|
18
18
|
const select = (triggerDate, modifiers, e) => {
|
|
19
19
|
const { min, max } = props;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
let newRange;
|
|
21
|
+
if (triggerDate) {
|
|
22
|
+
const selectedFrom = selected?.from;
|
|
23
|
+
const selectedTo = selected?.to;
|
|
24
|
+
const hasFullRange = !!selectedFrom && !!selectedTo;
|
|
25
|
+
const isClickingSingleDayRange = !!selectedFrom &&
|
|
26
|
+
!!selectedTo &&
|
|
27
|
+
dateLib.isSameDay(selectedFrom, selectedTo) &&
|
|
28
|
+
dateLib.isSameDay(triggerDate, selectedFrom);
|
|
29
|
+
if (resetOnSelect && (hasFullRange || !selected?.from)) {
|
|
30
|
+
if (!required && isClickingSingleDayRange) {
|
|
31
|
+
newRange = undefined;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
newRange = { from: triggerDate, to: undefined };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
newRange = addToRange(triggerDate, selected, min, max, required, dateLib);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
23
41
|
if (excludeDisabled && disabled && newRange?.from && newRange.to) {
|
|
24
42
|
if (rangeContainsModifiers({ from: newRange.from, to: newRange.to }, disabled, dateLib)) {
|
|
25
43
|
// if a disabled days is found, the range is reset
|
|
@@ -399,7 +399,12 @@ export interface PropsBase {
|
|
|
399
399
|
nonce?: HTMLDivElement["nonce"];
|
|
400
400
|
/** Add a `title` attribute to the container element. */
|
|
401
401
|
title?: HTMLDivElement["title"];
|
|
402
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* Add the language tag to the container element.
|
|
404
|
+
*
|
|
405
|
+
* When omitted, DayPicker uses the active locale code (`locale.code`).
|
|
406
|
+
* Set this prop to override the language tag.
|
|
407
|
+
*/
|
|
403
408
|
lang?: HTMLDivElement["lang"];
|
|
404
409
|
/**
|
|
405
410
|
* The locale object used to localize dates. Pass a locale from
|
|
@@ -654,9 +659,18 @@ export interface PropsRangeRequired {
|
|
|
654
659
|
/**
|
|
655
660
|
* When `true`, the range will reset when including a disabled day.
|
|
656
661
|
*
|
|
657
|
-
* @since
|
|
662
|
+
* @since 9.0.2
|
|
658
663
|
*/
|
|
659
664
|
excludeDisabled?: boolean | undefined;
|
|
665
|
+
/**
|
|
666
|
+
* When `true`, clicking a day starts a new range if there is no current start
|
|
667
|
+
* date or if a range is already complete. In those cases, the clicked day
|
|
668
|
+
* becomes the start of the new range.
|
|
669
|
+
*
|
|
670
|
+
* @since 9.14
|
|
671
|
+
* @see https://daypicker.dev/selections/range-mode#reset-selection
|
|
672
|
+
*/
|
|
673
|
+
resetOnSelect?: boolean | undefined;
|
|
660
674
|
/** The selected range. */
|
|
661
675
|
selected: DateRange | undefined;
|
|
662
676
|
/** Event handler when a range is selected. */
|
|
@@ -685,10 +699,20 @@ export interface PropsRange {
|
|
|
685
699
|
/**
|
|
686
700
|
* When `true`, the range will reset when including a disabled day.
|
|
687
701
|
*
|
|
688
|
-
* @since
|
|
702
|
+
* @since 9.0.2
|
|
689
703
|
* @see https://daypicker.dev/docs/selection-modes#exclude-disabled
|
|
690
704
|
*/
|
|
691
705
|
excludeDisabled?: boolean | undefined;
|
|
706
|
+
/**
|
|
707
|
+
* When `true`, clicking a day starts a new range if there is no current start
|
|
708
|
+
* date or if a range is already complete. In those cases, the clicked day
|
|
709
|
+
* becomes the start of the new range. When `required` is `false`, clicking
|
|
710
|
+
* the same day of a single-day range clears the selection.
|
|
711
|
+
*
|
|
712
|
+
* @since 9.14
|
|
713
|
+
* @see https://daypicker.dev/selections/range-mode#reset-selection
|
|
714
|
+
*/
|
|
715
|
+
resetOnSelect?: boolean | undefined;
|
|
692
716
|
/** The selected range. */
|
|
693
717
|
selected?: DateRange | undefined;
|
|
694
718
|
/** Event handler when the selection changes. */
|
package/hijri.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./dist/cjs/hijri/index.d.ts";
|
package/hijri.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-day-picker",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.14.0",
|
|
4
4
|
"description": "Customizable Date Picker for React",
|
|
5
5
|
"author": "Giampaolo Bellavite <io@gpbl.dev>",
|
|
6
6
|
"homepage": "https://daypicker.dev",
|
|
@@ -85,6 +85,16 @@
|
|
|
85
85
|
"default": "./dist/cjs/ethiopic/index.js"
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
|
+
"./hijri": {
|
|
89
|
+
"import": {
|
|
90
|
+
"types": "./dist/esm/hijri/index.d.ts",
|
|
91
|
+
"default": "./dist/esm/hijri/index.js"
|
|
92
|
+
},
|
|
93
|
+
"require": {
|
|
94
|
+
"types": "./dist/cjs/hijri/index.d.ts",
|
|
95
|
+
"default": "./dist/cjs/hijri/index.js"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
88
98
|
"./style": {
|
|
89
99
|
"sass": "./src/style.css"
|
|
90
100
|
},
|
|
@@ -93,11 +103,11 @@
|
|
|
93
103
|
"default": "./src/style.css"
|
|
94
104
|
},
|
|
95
105
|
"import": {
|
|
96
|
-
"types": "./src/style.
|
|
106
|
+
"types": "./src/style.css.d.ts",
|
|
97
107
|
"default": "./src/style.css"
|
|
98
108
|
},
|
|
99
109
|
"require": {
|
|
100
|
-
"types": "./src/style.
|
|
110
|
+
"types": "./src/style.css.d.ts",
|
|
101
111
|
"default": "./src/style.css"
|
|
102
112
|
}
|
|
103
113
|
},
|
|
@@ -228,36 +238,39 @@
|
|
|
228
238
|
"buddhist.d.ts",
|
|
229
239
|
"hebrew.js",
|
|
230
240
|
"hebrew.d.ts",
|
|
241
|
+
"hijri.js",
|
|
242
|
+
"hijri.d.ts",
|
|
231
243
|
"locale.js",
|
|
232
244
|
"locale.d.ts"
|
|
233
245
|
],
|
|
234
246
|
"dependencies": {
|
|
235
247
|
"@date-fns/tz": "^1.4.1",
|
|
248
|
+
"@tabby_ai/hijri-converter": "1.0.5",
|
|
236
249
|
"date-fns": "^4.1.0",
|
|
237
|
-
"date-fns-jalali": "
|
|
250
|
+
"date-fns-jalali": "4.1.0-0"
|
|
238
251
|
},
|
|
239
252
|
"devDependencies": {
|
|
240
|
-
"@biomejs/biome": "2.3.
|
|
253
|
+
"@biomejs/biome": "2.3.14",
|
|
241
254
|
"@jest/types": "^30.2.0",
|
|
242
255
|
"@radix-ui/react-select": "^2.2.6",
|
|
243
|
-
"@swc/core": "^1.15.
|
|
256
|
+
"@swc/core": "^1.15.11",
|
|
244
257
|
"@swc/jest": "^0.2.39",
|
|
245
258
|
"@testing-library/dom": "^10.4.1",
|
|
246
259
|
"@testing-library/jest-dom": "^6.9.1",
|
|
247
|
-
"@testing-library/react": "^16.3.
|
|
260
|
+
"@testing-library/react": "^16.3.2",
|
|
248
261
|
"@testing-library/user-event": "^14.6.1",
|
|
249
262
|
"@types/jest": "^30.0.0",
|
|
250
|
-
"@types/node": "^
|
|
251
|
-
"@types/react": "^19.2.
|
|
263
|
+
"@types/node": "^25.2.3",
|
|
264
|
+
"@types/react": "^19.2.13",
|
|
252
265
|
"@types/react-dom": "^19.2.3",
|
|
253
266
|
"jest": "^30.2.0",
|
|
254
267
|
"jest-environment-jsdom": "^30.2.0",
|
|
255
268
|
"jest-transform-css": "^6.0.3",
|
|
256
269
|
"mockdate": "^3.0.5",
|
|
257
|
-
"prettier": "^3.
|
|
258
|
-
"prettier-plugin-jsdoc": "^1.
|
|
259
|
-
"react": "^19.2.
|
|
260
|
-
"react-dom": "^19.2.
|
|
270
|
+
"prettier": "^3.8.1",
|
|
271
|
+
"prettier-plugin-jsdoc": "^1.8.0",
|
|
272
|
+
"react": "^19.2.4",
|
|
273
|
+
"react-dom": "^19.2.4",
|
|
261
274
|
"ts-node": "^10.9.2",
|
|
262
275
|
"tslib": "^2.8.1",
|
|
263
276
|
"typescript": "^5.9.3",
|