react-day-picker 9.11.0 → 9.11.1

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.
@@ -176,6 +176,14 @@ export declare class DateLib {
176
176
  * @param interval The interval to get the months for.
177
177
  */
178
178
  eachMonthOfInterval: (interval: Interval) => Date[];
179
+ /**
180
+ * Returns the years between the given dates.
181
+ *
182
+ * @since 9.11.1
183
+ * @param interval The interval to get the years for.
184
+ * @returns The array of years in the interval.
185
+ */
186
+ eachYearOfInterval: (interval: Interval) => Date[];
179
187
  /**
180
188
  * Returns the end of the broadcast week for the given date.
181
189
  *
@@ -144,6 +144,31 @@ class DateLib {
144
144
  ? this.overrides.eachMonthOfInterval(interval)
145
145
  : (0, date_fns_1.eachMonthOfInterval)(interval);
146
146
  };
147
+ /**
148
+ * Returns the years between the given dates.
149
+ *
150
+ * @since 9.11.1
151
+ * @param interval The interval to get the years for.
152
+ * @returns The array of years in the interval.
153
+ */
154
+ this.eachYearOfInterval = (interval) => {
155
+ const years = this.overrides?.eachYearOfInterval
156
+ ? this.overrides.eachYearOfInterval(interval)
157
+ : (0, date_fns_1.eachYearOfInterval)(interval);
158
+ // Remove duplicates that may happen across DST transitions (e.g., "America/Sao_Paulo")
159
+ // See https://github.com/date-fns/tz/issues/72
160
+ const uniqueYears = new Set(years.map((d) => this.getYear(d)));
161
+ if (uniqueYears.size === years.length) {
162
+ // No duplicates, return as is
163
+ return years;
164
+ }
165
+ // Rebuild the array to ensure one date per year
166
+ const yearsArray = [];
167
+ uniqueYears.forEach((y) => {
168
+ yearsArray.push(new Date(y, 0, 1));
169
+ });
170
+ return yearsArray;
171
+ };
147
172
  /**
148
173
  * Returns the end of the broadcast week for the given date.
149
174
  *
@@ -0,0 +1,7 @@
1
+ import type { Interval } from "date-fns";
2
+ /**
3
+ * Returns the start of each Ethiopic year included in the given interval.
4
+ *
5
+ * @param interval The interval whose years should be returned.
6
+ */
7
+ export declare function eachYearOfInterval(interval: Interval): Date[];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.eachYearOfInterval = eachYearOfInterval;
4
+ const index_js_1 = require("../utils/index.js");
5
+ /**
6
+ * Returns the start of each Ethiopic year included in the given interval.
7
+ *
8
+ * @param interval The interval whose years should be returned.
9
+ */
10
+ function eachYearOfInterval(interval) {
11
+ const start = (0, index_js_1.toEthiopicDate)(new Date(interval.start));
12
+ const end = (0, index_js_1.toEthiopicDate)(new Date(interval.end));
13
+ if (end.year < start.year) {
14
+ return [];
15
+ }
16
+ const years = [];
17
+ for (let year = start.year; year <= end.year; year += 1) {
18
+ years.push((0, index_js_1.toGregorianDate)({ year, month: 1, day: 1 }));
19
+ }
20
+ return years;
21
+ }
@@ -2,6 +2,7 @@ export * from "./addMonths.js";
2
2
  export * from "./addYears.js";
3
3
  export * from "./differenceInCalendarMonths.js";
4
4
  export * from "./eachMonthOfInterval.js";
5
+ export * from "./eachYearOfInterval.js";
5
6
  export * from "./endOfMonth.js";
6
7
  export * from "./endOfWeek.js";
7
8
  export * from "./endOfYear.js";
@@ -18,6 +18,7 @@ __exportStar(require("./addMonths.js"), exports);
18
18
  __exportStar(require("./addYears.js"), exports);
19
19
  __exportStar(require("./differenceInCalendarMonths.js"), exports);
20
20
  __exportStar(require("./eachMonthOfInterval.js"), exports);
21
+ __exportStar(require("./eachYearOfInterval.js"), exports);
21
22
  __exportStar(require("./endOfMonth.js"), exports);
22
23
  __exportStar(require("./endOfWeek.js"), exports);
23
24
  __exportStar(require("./endOfYear.js"), exports);
@@ -0,0 +1,2 @@
1
+ import { type Interval } from "date-fns";
2
+ export declare function eachYearOfInterval(interval: Interval): Date[];
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.eachYearOfInterval = eachYearOfInterval;
4
+ const date_fns_1 = require("date-fns");
5
+ const dateConversion_js_1 = require("../utils/dateConversion.js");
6
+ function eachYearOfInterval(interval) {
7
+ const start = (0, date_fns_1.toDate)(interval.start);
8
+ const end = (0, date_fns_1.toDate)(interval.end);
9
+ if (end.getTime() < start.getTime()) {
10
+ return [];
11
+ }
12
+ const startYear = (0, dateConversion_js_1.toHebrewDate)(start).year;
13
+ const endYear = (0, dateConversion_js_1.toHebrewDate)(end).year;
14
+ const years = [];
15
+ for (let year = startYear; year <= endYear; year += 1) {
16
+ years.push((0, dateConversion_js_1.toGregorianDate)({ year, monthIndex: 0, day: 1 }));
17
+ }
18
+ return years;
19
+ }
@@ -2,6 +2,7 @@ export * from "./addMonths.js";
2
2
  export * from "./addYears.js";
3
3
  export * from "./differenceInCalendarMonths.js";
4
4
  export * from "./eachMonthOfInterval.js";
5
+ export * from "./eachYearOfInterval.js";
5
6
  export * from "./endOfMonth.js";
6
7
  export * from "./endOfYear.js";
7
8
  export * from "./format.js";
@@ -18,6 +18,7 @@ __exportStar(require("./addMonths.js"), exports);
18
18
  __exportStar(require("./addYears.js"), exports);
19
19
  __exportStar(require("./differenceInCalendarMonths.js"), exports);
20
20
  __exportStar(require("./eachMonthOfInterval.js"), exports);
21
+ __exportStar(require("./eachYearOfInterval.js"), exports);
21
22
  __exportStar(require("./endOfMonth.js"), exports);
22
23
  __exportStar(require("./endOfYear.js"), exports);
23
24
  __exportStar(require("./format.js"), exports);
@@ -20,15 +20,10 @@ function getYearOptions(navStart, navEnd, formatters, dateLib, reverse = false)
20
20
  return undefined;
21
21
  if (!navEnd)
22
22
  return undefined;
23
- const { startOfYear, endOfYear, addYears, getYear, isBefore, isSameYear } = dateLib;
23
+ const { startOfYear, endOfYear, eachYearOfInterval, getYear } = dateLib;
24
24
  const firstNavYear = startOfYear(navStart);
25
25
  const lastNavYear = endOfYear(navEnd);
26
- const years = [];
27
- let year = firstNavYear;
28
- while (isBefore(year, lastNavYear) || isSameYear(year, lastNavYear)) {
29
- years.push(year);
30
- year = addYears(year, 1);
31
- }
26
+ const years = eachYearOfInterval({ start: firstNavYear, end: lastNavYear });
32
27
  if (reverse)
33
28
  years.reverse();
34
29
  return years.map((year) => {
@@ -33,6 +33,12 @@ function useFocus(props, calendar, getModifiers, isSelected, dateLib) {
33
33
  const nextFocus = (0, getNextFocus_js_1.getNextFocus)(moveBy, moveDir, focusedDay, calendar.navStart, calendar.navEnd, props, dateLib);
34
34
  if (!nextFocus)
35
35
  return;
36
+ if (props.disableNavigation) {
37
+ const isNextInCalendar = calendar.days.some((day) => day.isEqualTo(nextFocus));
38
+ if (!isNextInCalendar) {
39
+ return;
40
+ }
41
+ }
36
42
  calendar.goToDay(nextFocus);
37
43
  setFocused(nextFocus);
38
44
  };
@@ -176,6 +176,14 @@ export declare class DateLib {
176
176
  * @param interval The interval to get the months for.
177
177
  */
178
178
  eachMonthOfInterval: (interval: Interval) => Date[];
179
+ /**
180
+ * Returns the years between the given dates.
181
+ *
182
+ * @since 9.11.1
183
+ * @param interval The interval to get the years for.
184
+ * @returns The array of years in the interval.
185
+ */
186
+ eachYearOfInterval: (interval: Interval) => Date[];
179
187
  /**
180
188
  * Returns the end of the broadcast week for the given date.
181
189
  *
@@ -1,5 +1,5 @@
1
1
  import { TZDate } from "@date-fns/tz";
2
- import { addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, differenceInCalendarMonths, eachMonthOfInterval, endOfISOWeek, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, getMonth, getWeek, getYear, isAfter, isBefore, isDate, isSameDay, isSameMonth, isSameYear, max, min, setMonth, setYear, startOfDay, startOfISOWeek, startOfMonth, startOfWeek, startOfYear, } from "date-fns";
2
+ import { addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, differenceInCalendarMonths, eachMonthOfInterval, eachYearOfInterval, endOfISOWeek, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, getMonth, getWeek, getYear, isAfter, isBefore, isDate, isSameDay, isSameMonth, isSameYear, max, min, setMonth, setYear, startOfDay, startOfISOWeek, startOfMonth, startOfWeek, startOfYear, } from "date-fns";
3
3
  import { enUS } from "date-fns/locale/en-US";
4
4
  import { endOfBroadcastWeek } from "../helpers/endOfBroadcastWeek.js";
5
5
  import { startOfBroadcastWeek } from "../helpers/startOfBroadcastWeek.js";
@@ -141,6 +141,31 @@ export class DateLib {
141
141
  ? this.overrides.eachMonthOfInterval(interval)
142
142
  : eachMonthOfInterval(interval);
143
143
  };
144
+ /**
145
+ * Returns the years between the given dates.
146
+ *
147
+ * @since 9.11.1
148
+ * @param interval The interval to get the years for.
149
+ * @returns The array of years in the interval.
150
+ */
151
+ this.eachYearOfInterval = (interval) => {
152
+ const years = this.overrides?.eachYearOfInterval
153
+ ? this.overrides.eachYearOfInterval(interval)
154
+ : eachYearOfInterval(interval);
155
+ // Remove duplicates that may happen across DST transitions (e.g., "America/Sao_Paulo")
156
+ // See https://github.com/date-fns/tz/issues/72
157
+ const uniqueYears = new Set(years.map((d) => this.getYear(d)));
158
+ if (uniqueYears.size === years.length) {
159
+ // No duplicates, return as is
160
+ return years;
161
+ }
162
+ // Rebuild the array to ensure one date per year
163
+ const yearsArray = [];
164
+ uniqueYears.forEach((y) => {
165
+ yearsArray.push(new Date(y, 0, 1));
166
+ });
167
+ return yearsArray;
168
+ };
144
169
  /**
145
170
  * Returns the end of the broadcast week for the given date.
146
171
  *
@@ -0,0 +1,7 @@
1
+ import type { Interval } from "date-fns";
2
+ /**
3
+ * Returns the start of each Ethiopic year included in the given interval.
4
+ *
5
+ * @param interval The interval whose years should be returned.
6
+ */
7
+ export declare function eachYearOfInterval(interval: Interval): Date[];
@@ -0,0 +1,18 @@
1
+ import { toEthiopicDate, toGregorianDate } from "../utils/index.js";
2
+ /**
3
+ * Returns the start of each Ethiopic year included in the given interval.
4
+ *
5
+ * @param interval The interval whose years should be returned.
6
+ */
7
+ export function eachYearOfInterval(interval) {
8
+ const start = toEthiopicDate(new Date(interval.start));
9
+ const end = toEthiopicDate(new Date(interval.end));
10
+ if (end.year < start.year) {
11
+ return [];
12
+ }
13
+ const years = [];
14
+ for (let year = start.year; year <= end.year; year += 1) {
15
+ years.push(toGregorianDate({ year, month: 1, day: 1 }));
16
+ }
17
+ return years;
18
+ }
@@ -2,6 +2,7 @@ export * from "./addMonths.js";
2
2
  export * from "./addYears.js";
3
3
  export * from "./differenceInCalendarMonths.js";
4
4
  export * from "./eachMonthOfInterval.js";
5
+ export * from "./eachYearOfInterval.js";
5
6
  export * from "./endOfMonth.js";
6
7
  export * from "./endOfWeek.js";
7
8
  export * from "./endOfYear.js";
@@ -2,6 +2,7 @@ export * from "./addMonths.js";
2
2
  export * from "./addYears.js";
3
3
  export * from "./differenceInCalendarMonths.js";
4
4
  export * from "./eachMonthOfInterval.js";
5
+ export * from "./eachYearOfInterval.js";
5
6
  export * from "./endOfMonth.js";
6
7
  export * from "./endOfWeek.js";
7
8
  export * from "./endOfYear.js";
@@ -0,0 +1,2 @@
1
+ import { type Interval } from "date-fns";
2
+ export declare function eachYearOfInterval(interval: Interval): Date[];
@@ -0,0 +1,16 @@
1
+ import { toDate } from "date-fns";
2
+ import { toGregorianDate, toHebrewDate } from "../utils/dateConversion.js";
3
+ export function eachYearOfInterval(interval) {
4
+ const start = toDate(interval.start);
5
+ const end = toDate(interval.end);
6
+ if (end.getTime() < start.getTime()) {
7
+ return [];
8
+ }
9
+ const startYear = toHebrewDate(start).year;
10
+ const endYear = toHebrewDate(end).year;
11
+ const years = [];
12
+ for (let year = startYear; year <= endYear; year += 1) {
13
+ years.push(toGregorianDate({ year, monthIndex: 0, day: 1 }));
14
+ }
15
+ return years;
16
+ }
@@ -2,6 +2,7 @@ export * from "./addMonths.js";
2
2
  export * from "./addYears.js";
3
3
  export * from "./differenceInCalendarMonths.js";
4
4
  export * from "./eachMonthOfInterval.js";
5
+ export * from "./eachYearOfInterval.js";
5
6
  export * from "./endOfMonth.js";
6
7
  export * from "./endOfYear.js";
7
8
  export * from "./format.js";
@@ -2,6 +2,7 @@ export * from "./addMonths.js";
2
2
  export * from "./addYears.js";
3
3
  export * from "./differenceInCalendarMonths.js";
4
4
  export * from "./eachMonthOfInterval.js";
5
+ export * from "./eachYearOfInterval.js";
5
6
  export * from "./endOfMonth.js";
6
7
  export * from "./endOfYear.js";
7
8
  export * from "./format.js";
@@ -17,15 +17,10 @@ export function getYearOptions(navStart, navEnd, formatters, dateLib, reverse =
17
17
  return undefined;
18
18
  if (!navEnd)
19
19
  return undefined;
20
- const { startOfYear, endOfYear, addYears, getYear, isBefore, isSameYear } = dateLib;
20
+ const { startOfYear, endOfYear, eachYearOfInterval, getYear } = dateLib;
21
21
  const firstNavYear = startOfYear(navStart);
22
22
  const lastNavYear = endOfYear(navEnd);
23
- const years = [];
24
- let year = firstNavYear;
25
- while (isBefore(year, lastNavYear) || isSameYear(year, lastNavYear)) {
26
- years.push(year);
27
- year = addYears(year, 1);
28
- }
23
+ const years = eachYearOfInterval({ start: firstNavYear, end: lastNavYear });
29
24
  if (reverse)
30
25
  years.reverse();
31
26
  return years.map((year) => {
@@ -30,6 +30,12 @@ export function useFocus(props, calendar, getModifiers, isSelected, dateLib) {
30
30
  const nextFocus = getNextFocus(moveBy, moveDir, focusedDay, calendar.navStart, calendar.navEnd, props, dateLib);
31
31
  if (!nextFocus)
32
32
  return;
33
+ if (props.disableNavigation) {
34
+ const isNextInCalendar = calendar.days.some((day) => day.isEqualTo(nextFocus));
35
+ if (!isNextInCalendar) {
36
+ return;
37
+ }
38
+ }
33
39
  calendar.goToDay(nextFocus);
34
40
  setFocused(nextFocus);
35
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-day-picker",
3
- "version": "9.11.0",
3
+ "version": "9.11.1",
4
4
  "description": "Customizable Date Picker for React",
5
5
  "author": "Giampaolo Bellavite <io@gpbl.dev>",
6
6
  "homepage": "https://daypicker.dev",