Favivon - Correção

This commit is contained in:
2026-05-30 19:59:39 -03:00
parent 76ddaa815d
commit d7dfd221f0
32859 changed files with 5459654 additions and 404 deletions
@@ -0,0 +1,17 @@
import type { CalendarDay } from "../classes/index.js";
import type { Modifiers } from "../types/index.js";
/**
* Calculates the focus target day based on priority.
*
* This function determines the day that should receive focus in the calendar,
* prioritizing days with specific modifiers (e.g., "focused", "today") or
* selection states.
*
* @param days The array of `CalendarDay` objects to evaluate.
* @param getModifiers A function to retrieve the modifiers for a given day.
* @param isSelected A function to determine if a day is selected.
* @param lastFocused The last focused day, if any.
* @returns The `CalendarDay` that should receive focus, or `undefined` if no
* focusable day is found.
*/
export declare function calculateFocusTarget(days: CalendarDay[], getModifiers: (day: CalendarDay) => Modifiers, isSelected: (date: Date) => boolean, lastFocused: CalendarDay | undefined): CalendarDay | undefined;
+73
View File
@@ -0,0 +1,73 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateFocusTarget = calculateFocusTarget;
const UI_js_1 = require("../UI.js");
var FocusTargetPriority;
(function (FocusTargetPriority) {
FocusTargetPriority[FocusTargetPriority["Today"] = 0] = "Today";
FocusTargetPriority[FocusTargetPriority["Selected"] = 1] = "Selected";
FocusTargetPriority[FocusTargetPriority["LastFocused"] = 2] = "LastFocused";
FocusTargetPriority[FocusTargetPriority["FocusedModifier"] = 3] = "FocusedModifier";
})(FocusTargetPriority || (FocusTargetPriority = {}));
/**
* Determines if a day is focusable based on its modifiers.
*
* A day is considered focusable if it is not disabled, hidden, or outside the
* displayed month.
*
* @param modifiers The modifiers applied to the day.
* @returns `true` if the day is focusable, otherwise `false`.
*/
function isFocusableDay(modifiers) {
return (!modifiers[UI_js_1.DayFlag.disabled] &&
!modifiers[UI_js_1.DayFlag.hidden] &&
!modifiers[UI_js_1.DayFlag.outside]);
}
/**
* Calculates the focus target day based on priority.
*
* This function determines the day that should receive focus in the calendar,
* prioritizing days with specific modifiers (e.g., "focused", "today") or
* selection states.
*
* @param days The array of `CalendarDay` objects to evaluate.
* @param getModifiers A function to retrieve the modifiers for a given day.
* @param isSelected A function to determine if a day is selected.
* @param lastFocused The last focused day, if any.
* @returns The `CalendarDay` that should receive focus, or `undefined` if no
* focusable day is found.
*/
function calculateFocusTarget(days, getModifiers, isSelected, lastFocused) {
let focusTarget;
let foundFocusTargetPriority = -1;
for (const day of days) {
const modifiers = getModifiers(day);
if (isFocusableDay(modifiers)) {
if (modifiers[UI_js_1.DayFlag.focused] &&
foundFocusTargetPriority < FocusTargetPriority.FocusedModifier) {
focusTarget = day;
foundFocusTargetPriority = FocusTargetPriority.FocusedModifier;
}
else if (lastFocused?.isEqualTo(day) &&
foundFocusTargetPriority < FocusTargetPriority.LastFocused) {
focusTarget = day;
foundFocusTargetPriority = FocusTargetPriority.LastFocused;
}
else if (isSelected(day.date) &&
foundFocusTargetPriority < FocusTargetPriority.Selected) {
focusTarget = day;
foundFocusTargetPriority = FocusTargetPriority.Selected;
}
else if (modifiers[UI_js_1.DayFlag.today] &&
foundFocusTargetPriority < FocusTargetPriority.Today) {
focusTarget = day;
foundFocusTargetPriority = FocusTargetPriority.Today;
}
}
}
if (!focusTarget) {
// Return the first day that is focusable
focusTarget = days.find((day) => isFocusableDay(getModifiers(day)));
}
return focusTarget;
}
+16
View File
@@ -0,0 +1,16 @@
import type { CalendarDay, DateLib } from "../classes/index.js";
import type { DayPickerProps, Modifiers } from "../types/index.js";
/**
* Creates a function to retrieve the modifiers for a given day.
*
* This function calculates both internal and custom modifiers for each day
* based on the provided calendar days and DayPicker props.
*
* @private
* @param days The array of `CalendarDay` objects to process.
* @param props The DayPicker props, including modifiers and configuration
* options.
* @param dateLib The date library to use for date manipulation.
* @returns A function that retrieves the modifiers for a given `CalendarDay`.
*/
export declare function createGetModifiers(days: CalendarDay[], props: DayPickerProps, navStart: Date | undefined, navEnd: Date | undefined, dateLib: DateLib): (day: CalendarDay) => Modifiers;
+95
View File
@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createGetModifiers = createGetModifiers;
const UI_js_1 = require("../UI.js");
const dateMatchModifiers_js_1 = require("../utils/dateMatchModifiers.js");
/**
* Creates a function to retrieve the modifiers for a given day.
*
* This function calculates both internal and custom modifiers for each day
* based on the provided calendar days and DayPicker props.
*
* @private
* @param days The array of `CalendarDay` objects to process.
* @param props The DayPicker props, including modifiers and configuration
* options.
* @param dateLib The date library to use for date manipulation.
* @returns A function that retrieves the modifiers for a given `CalendarDay`.
*/
function createGetModifiers(days, props, navStart, navEnd, dateLib) {
const { disabled, hidden, modifiers, showOutsideDays, broadcastCalendar, today = dateLib.today(), } = props;
const { isSameDay, isSameMonth, startOfMonth, isBefore, endOfMonth, isAfter, } = dateLib;
const computedNavStart = navStart && startOfMonth(navStart);
const computedNavEnd = navEnd && endOfMonth(navEnd);
const internalModifiersMap = {
[UI_js_1.DayFlag.focused]: [],
[UI_js_1.DayFlag.outside]: [],
[UI_js_1.DayFlag.disabled]: [],
[UI_js_1.DayFlag.hidden]: [],
[UI_js_1.DayFlag.today]: [],
};
const customModifiersMap = {};
for (const day of days) {
const { date, displayMonth } = day;
const isOutside = Boolean(displayMonth && !isSameMonth(date, displayMonth));
const isBeforeNavStart = Boolean(computedNavStart && isBefore(date, computedNavStart));
const isAfterNavEnd = Boolean(computedNavEnd && isAfter(date, computedNavEnd));
const isDisabled = Boolean(disabled && (0, dateMatchModifiers_js_1.dateMatchModifiers)(date, disabled, dateLib));
const isHidden = Boolean(hidden && (0, dateMatchModifiers_js_1.dateMatchModifiers)(date, hidden, dateLib)) ||
isBeforeNavStart ||
isAfterNavEnd ||
// Broadcast calendar will show outside days as default
(!broadcastCalendar && !showOutsideDays && isOutside) ||
(broadcastCalendar && showOutsideDays === false && isOutside);
const isToday = isSameDay(date, today);
if (isOutside)
internalModifiersMap.outside.push(day);
if (isDisabled)
internalModifiersMap.disabled.push(day);
if (isHidden)
internalModifiersMap.hidden.push(day);
if (isToday)
internalModifiersMap.today.push(day);
// Add custom modifiers
if (modifiers) {
Object.keys(modifiers).forEach((name) => {
const modifierValue = modifiers?.[name];
const isMatch = modifierValue
? (0, dateMatchModifiers_js_1.dateMatchModifiers)(date, modifierValue, dateLib)
: false;
if (!isMatch)
return;
if (customModifiersMap[name]) {
customModifiersMap[name].push(day);
}
else {
customModifiersMap[name] = [day];
}
});
}
}
return (day) => {
// Initialize all the modifiers to false
const dayFlags = {
[UI_js_1.DayFlag.focused]: false,
[UI_js_1.DayFlag.disabled]: false,
[UI_js_1.DayFlag.hidden]: false,
[UI_js_1.DayFlag.outside]: false,
[UI_js_1.DayFlag.today]: false,
};
const customModifiers = {};
// Find the modifiers for the given day
for (const name in internalModifiersMap) {
const days = internalModifiersMap[name];
dayFlags[name] = days.some((d) => d === day);
}
for (const name in customModifiersMap) {
customModifiers[name] = customModifiersMap[name].some((d) => d === day);
}
return {
...dayFlags,
// custom modifiers should override all the previous ones
...customModifiers,
};
};
}
+13
View File
@@ -0,0 +1,13 @@
import type { DateLib } from "../classes/index.js";
/**
* Returns the end date of the week in the broadcast calendar.
*
* The broadcast week ends on the last day of the last broadcast week for the
* given date.
*
* @since 9.4.0
* @param date The date for which to calculate the end of the broadcast week.
* @param dateLib The date library to use for date manipulation.
* @returns The end date of the broadcast week.
*/
export declare function endOfBroadcastWeek(date: Date, dateLib: DateLib): Date;
+22
View File
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.endOfBroadcastWeek = endOfBroadcastWeek;
const getBroadcastWeeksInMonth_js_1 = require("./getBroadcastWeeksInMonth.js");
const startOfBroadcastWeek_js_1 = require("./startOfBroadcastWeek.js");
/**
* Returns the end date of the week in the broadcast calendar.
*
* The broadcast week ends on the last day of the last broadcast week for the
* given date.
*
* @since 9.4.0
* @param date The date for which to calculate the end of the broadcast week.
* @param dateLib The date library to use for date manipulation.
* @returns The end date of the broadcast week.
*/
function endOfBroadcastWeek(date, dateLib) {
const startDate = (0, startOfBroadcastWeek_js_1.startOfBroadcastWeek)(date, dateLib);
const numberOfWeeks = (0, getBroadcastWeeksInMonth_js_1.getBroadcastWeeksInMonth)(date, dateLib);
const endDate = dateLib.addDays(startDate, numberOfWeeks * 7 - 1);
return endDate;
}
@@ -0,0 +1,14 @@
import type { DateLib } from "../classes/index.js";
/**
* Returns the number of weeks to display in the broadcast calendar for a given
* month.
*
* The broadcast calendar may have either 4 or 5 weeks in a month, depending on
* the start and end dates of the broadcast weeks.
*
* @since 9.4.0
* @param month The month for which to calculate the number of weeks.
* @param dateLib The date library to use for date manipulation.
* @returns The number of weeks in the broadcast calendar (4 or 5).
*/
export declare function getBroadcastWeeksInMonth(month: Date, dateLib: DateLib): 4 | 5;
@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBroadcastWeeksInMonth = getBroadcastWeeksInMonth;
const FIVE_WEEKS = 5;
const FOUR_WEEKS = 4;
/**
* Returns the number of weeks to display in the broadcast calendar for a given
* month.
*
* The broadcast calendar may have either 4 or 5 weeks in a month, depending on
* the start and end dates of the broadcast weeks.
*
* @since 9.4.0
* @param month The month for which to calculate the number of weeks.
* @param dateLib The date library to use for date manipulation.
* @returns The number of weeks in the broadcast calendar (4 or 5).
*/
function getBroadcastWeeksInMonth(month, dateLib) {
// Get the first day of the month
const firstDayOfMonth = dateLib.startOfMonth(month);
// Get the day of the week for the first day of the month (1-7, where 1 is Monday)
const firstDayOfWeek = firstDayOfMonth.getDay() > 0 ? firstDayOfMonth.getDay() : 7;
const broadcastStartDate = dateLib.addDays(month, -firstDayOfWeek + 1);
const lastDateOfLastWeek = dateLib.addDays(broadcastStartDate, FIVE_WEEKS * 7 - 1);
const numberOfWeeks = dateLib.getMonth(month) === dateLib.getMonth(lastDateOfLastWeek)
? FIVE_WEEKS
: FOUR_WEEKS;
return numberOfWeeks;
}
@@ -0,0 +1,14 @@
import type { ClassNames, ModifiersClassNames } from "../types/index.js";
/**
* Returns the class names for a day based on its modifiers.
*
* This function combines the base class name for the day with any class names
* associated with active modifiers.
*
* @param modifiers The modifiers applied to the day.
* @param classNames The base class names for the calendar elements.
* @param modifiersClassNames The class names associated with specific
* modifiers.
* @returns An array of class names for the day.
*/
export declare function getClassNamesForModifiers(modifiers: Record<string, boolean>, classNames: ClassNames, modifiersClassNames?: ModifiersClassNames): string[];
@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getClassNamesForModifiers = getClassNamesForModifiers;
const UI_js_1 = require("../UI.js");
/**
* Returns the class names for a day based on its modifiers.
*
* This function combines the base class name for the day with any class names
* associated with active modifiers.
*
* @param modifiers The modifiers applied to the day.
* @param classNames The base class names for the calendar elements.
* @param modifiersClassNames The class names associated with specific
* modifiers.
* @returns An array of class names for the day.
*/
function getClassNamesForModifiers(modifiers, classNames, modifiersClassNames = {}) {
const modifierClassNames = Object.entries(modifiers)
.filter(([, active]) => active === true)
.reduce((previousValue, [key]) => {
if (modifiersClassNames[key]) {
previousValue.push(modifiersClassNames[key]);
}
else if (classNames[UI_js_1.DayFlag[key]]) {
previousValue.push(classNames[UI_js_1.DayFlag[key]]);
}
else if (classNames[UI_js_1.SelectionState[key]]) {
previousValue.push(classNames[UI_js_1.SelectionState[key]]);
}
return previousValue;
}, [classNames[UI_js_1.UI.Day]]);
return modifierClassNames;
}
+12
View File
@@ -0,0 +1,12 @@
import type { CustomComponents, DayPickerProps } from "../types/index.js";
/**
* Merges custom components from the props with the default components.
*
* This function ensures that any custom components provided in the props
* override the default components.
*
* @param customComponents The custom components provided in the DayPicker
* props.
* @returns An object containing the merged components.
*/
export declare function getComponents(customComponents: DayPickerProps["components"]): CustomComponents;
+53
View File
@@ -0,0 +1,53 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getComponents = getComponents;
const components = __importStar(require("../components/custom-components.js"));
/**
* Merges custom components from the props with the default components.
*
* This function ensures that any custom components provided in the props
* override the default components.
*
* @param customComponents The custom components provided in the DayPicker
* props.
* @returns An object containing the merged components.
*/
function getComponents(customComponents) {
return {
...components,
...customComponents,
};
}
+11
View File
@@ -0,0 +1,11 @@
import type { DayPickerProps } from "../types/index.js";
/**
* Extracts `data-` attributes from the DayPicker props.
*
* This function collects all `data-` attributes from the props and adds
* additional attributes based on the DayPicker configuration.
*
* @param props The DayPicker props.
* @returns An object containing the `data-` attributes.
*/
export declare function getDataAttributes(props: DayPickerProps): Record<string, unknown>;
+28
View File
@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDataAttributes = getDataAttributes;
/**
* Extracts `data-` attributes from the DayPicker props.
*
* This function collects all `data-` attributes from the props and adds
* additional attributes based on the DayPicker configuration.
*
* @param props The DayPicker props.
* @returns An object containing the `data-` attributes.
*/
function getDataAttributes(props) {
const dataAttributes = {
"data-mode": props.mode ?? undefined,
"data-required": "required" in props ? props.required : undefined,
"data-multiple-months": (props.numberOfMonths && props.numberOfMonths > 1) || undefined,
"data-week-numbers": props.showWeekNumber || undefined,
"data-broadcast-calendar": props.broadcastCalendar || undefined,
"data-nav-layout": props.navLayout || undefined,
};
Object.entries(props).forEach(([key, val]) => {
if (key.startsWith("data-")) {
dataAttributes[key] = val;
}
});
return dataAttributes;
}
+15
View File
@@ -0,0 +1,15 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DayPickerProps } from "../types/props.js";
/**
* Returns all the dates to display in the calendar.
*
* This function calculates the range of dates to display based on the provided
* display months, constraints, and calendar configuration.
*
* @param displayMonths The months to display in the calendar.
* @param maxDate The maximum date to include in the range.
* @param props The DayPicker props, including calendar configuration options.
* @param dateLib The date library to use for date manipulation.
* @returns An array of dates to display in the calendar.
*/
export declare function getDates(displayMonths: Date[], maxDate: Date | undefined, props: Pick<DayPickerProps, "ISOWeek" | "fixedWeeks" | "broadcastCalendar">, dateLib: DateLib): Date[];
+60
View File
@@ -0,0 +1,60 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDates = getDates;
/**
* Returns all the dates to display in the calendar.
*
* This function calculates the range of dates to display based on the provided
* display months, constraints, and calendar configuration.
*
* @param displayMonths The months to display in the calendar.
* @param maxDate The maximum date to include in the range.
* @param props The DayPicker props, including calendar configuration options.
* @param dateLib The date library to use for date manipulation.
* @returns An array of dates to display in the calendar.
*/
function getDates(displayMonths, maxDate, props, dateLib) {
const firstMonth = displayMonths[0];
const lastMonth = displayMonths[displayMonths.length - 1];
const { ISOWeek, fixedWeeks, broadcastCalendar } = props ?? {};
const { addDays, differenceInCalendarDays, differenceInCalendarMonths, endOfBroadcastWeek, endOfISOWeek, endOfMonth, endOfWeek, isAfter, startOfBroadcastWeek, startOfISOWeek, startOfWeek, } = dateLib;
const startWeekFirstDate = broadcastCalendar
? startOfBroadcastWeek(firstMonth, dateLib)
: ISOWeek
? startOfISOWeek(firstMonth)
: startOfWeek(firstMonth);
const displayMonthsWeekEnd = broadcastCalendar
? endOfBroadcastWeek(lastMonth)
: ISOWeek
? endOfISOWeek(endOfMonth(lastMonth))
: endOfWeek(endOfMonth(lastMonth));
// If maxDate is set, clamp the grid to the end of that week.
const constraintWeekEnd = maxDate &&
(broadcastCalendar
? endOfBroadcastWeek(maxDate)
: ISOWeek
? endOfISOWeek(maxDate)
: endOfWeek(maxDate));
// Pick the earliest week end between the displayed months and the constraint.
const gridEndDate = constraintWeekEnd && isAfter(displayMonthsWeekEnd, constraintWeekEnd)
? constraintWeekEnd
: displayMonthsWeekEnd;
const nOfDays = differenceInCalendarDays(gridEndDate, startWeekFirstDate);
const nOfMonths = differenceInCalendarMonths(lastMonth, firstMonth) + 1;
const dates = [];
for (let i = 0; i <= nOfDays; i++) {
const date = addDays(startWeekFirstDate, i);
dates.push(date);
}
// If fixed weeks is enabled, add the extra dates to the array
const nrOfDaysWithFixedWeeks = broadcastCalendar ? 35 : 42;
const extraDates = nrOfDaysWithFixedWeeks * nOfMonths;
if (fixedWeeks && dates.length < extraDates) {
const daysToAdd = extraDates - dates.length;
for (let i = 0; i < daysToAdd; i++) {
const date = addDays(dates[dates.length - 1], 1);
dates.push(date);
}
}
return dates;
}
+10
View File
@@ -0,0 +1,10 @@
import type { CalendarDay, CalendarMonth } from "../classes/index.js";
/**
* Returns all the days belonging to the calendar by merging the days in the
* weeks for each month.
*
* @param calendarMonths The array of calendar months.
* @returns An array of `CalendarDay` objects representing all the days in the
* calendar.
*/
export declare function getDays(calendarMonths: CalendarMonth[]): CalendarDay[];
+20
View File
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDays = getDays;
/**
* Returns all the days belonging to the calendar by merging the days in the
* weeks for each month.
*
* @param calendarMonths The array of calendar months.
* @returns An array of `CalendarDay` objects representing all the days in the
* calendar.
*/
function getDays(calendarMonths) {
const initialDays = [];
return calendarMonths.reduce((days, month) => {
const weekDays = month.weeks.reduce((weekDays, week) => {
return weekDays.concat(week.days.slice());
}, initialDays.slice());
return days.concat(weekDays.slice());
}, initialDays.slice());
}
@@ -0,0 +1,11 @@
import type { ClassNames } from "../types/index.js";
/**
* Returns the default class names for the UI elements.
*
* This function generates a mapping of default class names for various UI
* elements, day flags, selection states, and animations.
*
* @returns An object containing the default class names.
* @group Utilities
*/
export declare function getDefaultClassNames(): ClassNames;
+33
View File
@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDefaultClassNames = getDefaultClassNames;
const UI_js_1 = require("../UI.js");
/**
* Returns the default class names for the UI elements.
*
* This function generates a mapping of default class names for various UI
* elements, day flags, selection states, and animations.
*
* @returns An object containing the default class names.
* @group Utilities
*/
function getDefaultClassNames() {
const classNames = {};
for (const key in UI_js_1.UI) {
classNames[UI_js_1.UI[key]] =
`rdp-${UI_js_1.UI[key]}`;
}
for (const key in UI_js_1.DayFlag) {
classNames[UI_js_1.DayFlag[key]] =
`rdp-${UI_js_1.DayFlag[key]}`;
}
for (const key in UI_js_1.SelectionState) {
classNames[UI_js_1.SelectionState[key]] =
`rdp-${UI_js_1.SelectionState[key]}`;
}
for (const key in UI_js_1.Animation) {
classNames[UI_js_1.Animation[key]] =
`rdp-${UI_js_1.Animation[key]}`;
}
return classNames;
}
+13
View File
@@ -0,0 +1,13 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DayPickerProps } from "../types/index.js";
/**
* Returns the months to display in the calendar.
*
* @param firstDisplayedMonth The first month currently displayed in the
* calendar.
* @param calendarEndMonth The latest month the user can navigate to.
* @param props The DayPicker props, including `numberOfMonths`.
* @param dateLib The date library to use for date manipulation.
* @returns An array of dates representing the months to display.
*/
export declare function getDisplayMonths(firstDisplayedMonth: Date, calendarEndMonth: Date | undefined, props: Pick<DayPickerProps, "numberOfMonths">, dateLib: DateLib): Date[];
+25
View File
@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDisplayMonths = getDisplayMonths;
/**
* Returns the months to display in the calendar.
*
* @param firstDisplayedMonth The first month currently displayed in the
* calendar.
* @param calendarEndMonth The latest month the user can navigate to.
* @param props The DayPicker props, including `numberOfMonths`.
* @param dateLib The date library to use for date manipulation.
* @returns An array of dates representing the months to display.
*/
function getDisplayMonths(firstDisplayedMonth, calendarEndMonth, props, dateLib) {
const { numberOfMonths = 1 } = props;
const months = [];
for (let i = 0; i < numberOfMonths; i++) {
const month = dateLib.addMonths(firstDisplayedMonth, i);
if (calendarEndMonth && month > calendarEndMonth) {
break;
}
months.push(month);
}
return months;
}
+19
View File
@@ -0,0 +1,19 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DayPickerProps, MoveFocusBy, MoveFocusDir } from "../types/index.js";
/**
* Calculates the next date that should be focused in the calendar.
*
* This function determines the next focusable date based on the movement
* direction, constraints, and calendar configuration.
*
* @param moveBy The unit of movement (e.g., "day", "week").
* @param moveDir The direction of movement ("before" or "after").
* @param refDate The reference date from which to calculate the next focusable
* date.
* @param navStart The earliest date the user can navigate to.
* @param navEnd The latest date the user can navigate to.
* @param props The DayPicker props, including calendar configuration options.
* @param dateLib The date library to use for date manipulation.
* @returns The next focusable date.
*/
export declare function getFocusableDate(moveBy: MoveFocusBy, moveDir: MoveFocusDir, refDate: Date, navStart: Date | undefined, navEnd: Date | undefined, props: Pick<DayPickerProps, "ISOWeek" | "broadcastCalendar">, dateLib: DateLib): Date;
+47
View File
@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFocusableDate = getFocusableDate;
/**
* Calculates the next date that should be focused in the calendar.
*
* This function determines the next focusable date based on the movement
* direction, constraints, and calendar configuration.
*
* @param moveBy The unit of movement (e.g., "day", "week").
* @param moveDir The direction of movement ("before" or "after").
* @param refDate The reference date from which to calculate the next focusable
* date.
* @param navStart The earliest date the user can navigate to.
* @param navEnd The latest date the user can navigate to.
* @param props The DayPicker props, including calendar configuration options.
* @param dateLib The date library to use for date manipulation.
* @returns The next focusable date.
*/
function getFocusableDate(moveBy, moveDir, refDate, navStart, navEnd, props, dateLib) {
const { ISOWeek, broadcastCalendar } = props;
const { addDays, addMonths, addWeeks, addYears, endOfBroadcastWeek, endOfISOWeek, endOfWeek, max, min, startOfBroadcastWeek, startOfISOWeek, startOfWeek, } = dateLib;
const moveFns = {
day: addDays,
week: addWeeks,
month: addMonths,
year: addYears,
startOfWeek: (date) => broadcastCalendar
? startOfBroadcastWeek(date, dateLib)
: ISOWeek
? startOfISOWeek(date)
: startOfWeek(date),
endOfWeek: (date) => broadcastCalendar
? endOfBroadcastWeek(date)
: ISOWeek
? endOfISOWeek(date)
: endOfWeek(date),
};
let focusableDate = moveFns[moveBy](refDate, moveDir === "after" ? 1 : -1);
if (moveDir === "before" && navStart) {
focusableDate = max([navStart, focusableDate]);
}
else if (moveDir === "after" && navEnd) {
focusableDate = min([navEnd, focusableDate]);
}
return focusableDate;
}
+20
View File
@@ -0,0 +1,20 @@
import * as defaultFormatters from "../formatters/index.js";
import type { DayPickerProps } from "../types/index.js";
/**
* Merges custom formatters from the props with the default formatters.
*
* @param customFormatters The custom formatters provided in the DayPicker
* props.
* @returns The merged formatters object.
*/
export declare function getFormatters(customFormatters: DayPickerProps["formatters"]): {
formatCaption: typeof defaultFormatters.formatCaption;
formatDay: typeof defaultFormatters.formatDay;
formatMonthDropdown: typeof defaultFormatters.formatMonthDropdown;
formatMonthCaption: typeof defaultFormatters.formatMonthCaption;
formatWeekNumber: typeof defaultFormatters.formatWeekNumber;
formatWeekNumberHeader: typeof defaultFormatters.formatWeekNumberHeader;
formatWeekdayName: typeof defaultFormatters.formatWeekdayName;
formatYearDropdown: typeof defaultFormatters.formatYearDropdown;
formatYearCaption: typeof defaultFormatters.formatYearCaption;
};
+57
View File
@@ -0,0 +1,57 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFormatters = getFormatters;
const defaultFormatters = __importStar(require("../formatters/index.js"));
/**
* Merges custom formatters from the props with the default formatters.
*
* @param customFormatters The custom formatters provided in the DayPicker
* props.
* @returns The merged formatters object.
*/
function getFormatters(customFormatters) {
if (customFormatters?.formatMonthCaption && !customFormatters.formatCaption) {
customFormatters.formatCaption = customFormatters.formatMonthCaption;
}
if (customFormatters?.formatYearCaption &&
!customFormatters.formatYearDropdown) {
customFormatters.formatYearDropdown = customFormatters.formatYearCaption;
}
return {
...defaultFormatters,
...customFormatters,
};
}
+14
View File
@@ -0,0 +1,14 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DayPickerProps } from "../types/props.js";
/**
* Determines the initial month to display in the calendar based on the provided
* props.
*
* This function calculates the starting month, considering constraints such as
* `startMonth`, `endMonth`, and the number of months to display.
*
* @param props The DayPicker props, including navigation and date constraints.
* @param dateLib The date library to use for date manipulation.
* @returns The initial month to display.
*/
export declare function getInitialMonth(props: Pick<DayPickerProps, "fromYear" | "toYear" | "month" | "defaultMonth" | "today" | "numberOfMonths" | "timeZone">, navStart: Date | undefined, navEnd: Date | undefined, dateLib: DateLib): Date;
+28
View File
@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInitialMonth = getInitialMonth;
/**
* Determines the initial month to display in the calendar based on the provided
* props.
*
* This function calculates the starting month, considering constraints such as
* `startMonth`, `endMonth`, and the number of months to display.
*
* @param props The DayPicker props, including navigation and date constraints.
* @param dateLib The date library to use for date manipulation.
* @returns The initial month to display.
*/
function getInitialMonth(props, navStart, navEnd, dateLib) {
const { month, defaultMonth, today = dateLib.today(), numberOfMonths = 1, } = props;
let initialMonth = month || defaultMonth || today;
const { differenceInCalendarMonths, addMonths, startOfMonth } = dateLib;
if (navEnd &&
differenceInCalendarMonths(navEnd, initialMonth) < numberOfMonths - 1) {
const offset = -1 * (numberOfMonths - 1);
initialMonth = addMonths(navEnd, offset);
}
if (navStart && differenceInCalendarMonths(initialMonth, navStart) < 0) {
initialMonth = navStart;
}
return startOfMonth(initialMonth);
}
+13
View File
@@ -0,0 +1,13 @@
import type { DateLibOptions } from "../classes/DateLib.js";
import type { DayPickerProps, Labels } from "../types/index.js";
/**
* Merges custom labels from the props with the default labels.
*
* When available, uses the locale-provided translation for `labelNext`.
*
* @param customLabels The custom labels provided in the DayPicker props.
* @param options Options from the date library, used to resolve locale
* translations.
* @returns The merged labels object with locale-aware defaults.
*/
export declare function getLabels(customLabels: DayPickerProps["labels"], options: DateLibOptions): Labels;
+75
View File
@@ -0,0 +1,75 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLabels = getLabels;
const defaultLabels = __importStar(require("../labels/index.js"));
const resolveLabel = (defaultLabel, customLabel, localeLabel) => {
if (customLabel)
return customLabel;
if (localeLabel) {
return (typeof localeLabel === "function"
? localeLabel
: (..._args) => localeLabel);
}
return defaultLabel;
};
/**
* Merges custom labels from the props with the default labels.
*
* When available, uses the locale-provided translation for `labelNext`.
*
* @param customLabels The custom labels provided in the DayPicker props.
* @param options Options from the date library, used to resolve locale
* translations.
* @returns The merged labels object with locale-aware defaults.
*/
function getLabels(customLabels, options) {
const localeLabels = options.locale?.labels ?? {};
return {
...defaultLabels,
...(customLabels ?? {}),
labelDayButton: resolveLabel(defaultLabels.labelDayButton, customLabels?.labelDayButton, localeLabels.labelDayButton),
labelMonthDropdown: resolveLabel(defaultLabels.labelMonthDropdown, customLabels?.labelMonthDropdown, localeLabels.labelMonthDropdown),
labelNext: resolveLabel(defaultLabels.labelNext, customLabels?.labelNext, localeLabels.labelNext),
labelPrevious: resolveLabel(defaultLabels.labelPrevious, customLabels?.labelPrevious, localeLabels.labelPrevious),
labelWeekNumber: resolveLabel(defaultLabels.labelWeekNumber, customLabels?.labelWeekNumber, localeLabels.labelWeekNumber),
labelYearDropdown: resolveLabel(defaultLabels.labelYearDropdown, customLabels?.labelYearDropdown, localeLabels.labelYearDropdown),
labelGrid: resolveLabel(defaultLabels.labelGrid, customLabels?.labelGrid, localeLabels.labelGrid),
labelGridcell: resolveLabel(defaultLabels.labelGridcell, customLabels?.labelGridcell, localeLabels.labelGridcell),
labelNav: resolveLabel(defaultLabels.labelNav, customLabels?.labelNav, localeLabels.labelNav),
labelWeekNumberHeader: resolveLabel(defaultLabels.labelWeekNumberHeader, customLabels?.labelWeekNumberHeader, localeLabels.labelWeekNumberHeader),
labelWeekday: resolveLabel(defaultLabels.labelWeekday, customLabels?.labelWeekday, localeLabels.labelWeekday),
};
}
+19
View File
@@ -0,0 +1,19 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DropdownOption } from "../components/Dropdown.js";
import type { Formatters } from "../types/index.js";
/**
* Returns the months to show in the dropdown.
*
* This function generates a list of months for the current year, formatted
* using the provided formatter, and determines whether each month should be
* disabled based on the navigation range.
*
* @param displayMonth The currently displayed month.
* @param navStart The start date for navigation.
* @param navEnd The end date for navigation.
* @param formatters The formatters to use for formatting the month labels.
* @param dateLib The date library to use for date manipulation.
* @returns An array of dropdown options representing the months, or `undefined`
* if no months are available.
*/
export declare function getMonthOptions(displayMonth: Date, navStart: Date | undefined, navEnd: Date | undefined, formatters: Pick<Formatters, "formatMonthDropdown">, dateLib: DateLib): DropdownOption[] | undefined;
+34
View File
@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMonthOptions = getMonthOptions;
/**
* Returns the months to show in the dropdown.
*
* This function generates a list of months for the current year, formatted
* using the provided formatter, and determines whether each month should be
* disabled based on the navigation range.
*
* @param displayMonth The currently displayed month.
* @param navStart The start date for navigation.
* @param navEnd The end date for navigation.
* @param formatters The formatters to use for formatting the month labels.
* @param dateLib The date library to use for date manipulation.
* @returns An array of dropdown options representing the months, or `undefined`
* if no months are available.
*/
function getMonthOptions(displayMonth, navStart, navEnd, formatters, dateLib) {
const { startOfMonth, startOfYear, endOfYear, eachMonthOfInterval, getMonth, } = dateLib;
const months = eachMonthOfInterval({
start: startOfYear(displayMonth),
end: endOfYear(displayMonth),
});
const options = months.map((month) => {
const label = formatters.formatMonthDropdown(month, dateLib);
const value = getMonth(month);
const disabled = (navStart && month < startOfMonth(navStart)) ||
(navEnd && month > startOfMonth(navEnd)) ||
false;
return { value, label, disabled };
});
return options;
}
+18
View File
@@ -0,0 +1,18 @@
import type { DateLib } from "../classes/DateLib.js";
import { CalendarMonth } from "../classes/index.js";
import type { DayPickerProps } from "../types/index.js";
/**
* Returns the months to display in the calendar.
*
* This function generates `CalendarMonth` objects for each month to be
* displayed, including their weeks and days, based on the provided display
* months and dates.
*
* @param displayMonths The months (as dates) to display in the calendar.
* @param dates The dates to display in the calendar.
* @param props Options from the DayPicker props context.
* @param dateLib The date library to use for date manipulation.
* @returns An array of `CalendarMonth` objects representing the months to
* display.
*/
export declare function getMonths(displayMonths: Date[], dates: Date[], props: Pick<DayPickerProps, "broadcastCalendar" | "fixedWeeks" | "ISOWeek" | "reverseMonths">, dateLib: DateLib): CalendarMonth[];
+67
View File
@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMonths = getMonths;
const index_js_1 = require("../classes/index.js");
/**
* Returns the months to display in the calendar.
*
* This function generates `CalendarMonth` objects for each month to be
* displayed, including their weeks and days, based on the provided display
* months and dates.
*
* @param displayMonths The months (as dates) to display in the calendar.
* @param dates The dates to display in the calendar.
* @param props Options from the DayPicker props context.
* @param dateLib The date library to use for date manipulation.
* @returns An array of `CalendarMonth` objects representing the months to
* display.
*/
function getMonths(displayMonths, dates, props, dateLib) {
const { addDays, endOfBroadcastWeek, endOfISOWeek, endOfMonth, endOfWeek, getISOWeek, getWeek, startOfBroadcastWeek, startOfISOWeek, startOfWeek, } = dateLib;
const dayPickerMonths = displayMonths.reduce((months, month) => {
const firstDateOfFirstWeek = props.broadcastCalendar
? startOfBroadcastWeek(month, dateLib)
: props.ISOWeek
? startOfISOWeek(month)
: startOfWeek(month);
const lastDateOfLastWeek = props.broadcastCalendar
? endOfBroadcastWeek(month)
: props.ISOWeek
? endOfISOWeek(endOfMonth(month))
: endOfWeek(endOfMonth(month));
/** The dates to display in the month. */
const monthDates = dates.filter((date) => {
return date >= firstDateOfFirstWeek && date <= lastDateOfLastWeek;
});
const nrOfDaysWithFixedWeeks = props.broadcastCalendar ? 35 : 42;
if (props.fixedWeeks && monthDates.length < nrOfDaysWithFixedWeeks) {
const extraDates = dates.filter((date) => {
const daysToAdd = nrOfDaysWithFixedWeeks - monthDates.length;
return (date > lastDateOfLastWeek &&
date <= addDays(lastDateOfLastWeek, daysToAdd));
});
monthDates.push(...extraDates);
}
const weeks = monthDates.reduce((weeks, date) => {
const weekNumber = props.ISOWeek ? getISOWeek(date) : getWeek(date);
const week = weeks.find((week) => week.weekNumber === weekNumber);
const day = new index_js_1.CalendarDay(date, month, dateLib);
if (!week) {
weeks.push(new index_js_1.CalendarWeek(weekNumber, [day]));
}
else {
week.days.push(day);
}
return weeks;
}, []);
const dayPickerMonth = new index_js_1.CalendarMonth(month, weeks);
months.push(dayPickerMonth);
return months;
}, []);
if (!props.reverseMonths) {
return dayPickerMonths;
}
else {
return dayPickerMonths.reverse();
}
}
+10
View File
@@ -0,0 +1,10 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DayPickerProps } from "../types/index.js";
/**
* Returns the start and end months for calendar navigation.
*
* @param props The DayPicker props, including navigation and layout options.
* @param dateLib The date library to use for date manipulation.
* @returns A tuple containing the start and end months for navigation.
*/
export declare function getNavMonths(props: Pick<DayPickerProps, "captionLayout" | "endMonth" | "startMonth" | "today" | "timeZone" | "fromMonth" | "fromYear" | "toMonth" | "toYear">, dateLib: DateLib): [start: Date | undefined, end: Date | undefined];
+52
View File
@@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNavMonths = getNavMonths;
/**
* Returns the start and end months for calendar navigation.
*
* @param props The DayPicker props, including navigation and layout options.
* @param dateLib The date library to use for date manipulation.
* @returns A tuple containing the start and end months for navigation.
*/
function getNavMonths(props, dateLib) {
let { startMonth, endMonth } = props;
const { startOfYear, startOfDay, startOfMonth, endOfMonth, addYears, endOfYear, newDate, today, } = dateLib;
// Handle deprecated code
const { fromYear, toYear, fromMonth, toMonth } = props;
if (!startMonth && fromMonth) {
startMonth = fromMonth;
}
if (!startMonth && fromYear) {
startMonth = dateLib.newDate(fromYear, 0, 1);
}
if (!endMonth && toMonth) {
endMonth = toMonth;
}
if (!endMonth && toYear) {
endMonth = newDate(toYear, 11, 31);
}
const hasYearDropdown = props.captionLayout === "dropdown" ||
props.captionLayout === "dropdown-years";
if (startMonth) {
startMonth = startOfMonth(startMonth);
}
else if (fromYear) {
startMonth = newDate(fromYear, 0, 1);
}
else if (!startMonth && hasYearDropdown) {
startMonth = startOfYear(addYears(props.today ?? today(), -100));
}
if (endMonth) {
endMonth = endOfMonth(endMonth);
}
else if (toYear) {
endMonth = newDate(toYear, 11, 31);
}
else if (!endMonth && hasYearDropdown) {
endMonth = endOfYear(props.today ?? today());
}
return [
startMonth ? startOfDay(startMonth) : startMonth,
endMonth ? startOfDay(endMonth) : endMonth,
];
}
+21
View File
@@ -0,0 +1,21 @@
import type { DateLib } from "../classes/DateLib.js";
import { CalendarDay } from "../classes/index.js";
import type { DayPickerProps, MoveFocusBy, MoveFocusDir } from "../types/index.js";
/**
* Determines the next focusable day in the calendar.
*
* This function recursively calculates the next focusable day based on the
* movement direction and modifiers applied to the days.
*
* @param moveBy The unit of movement (e.g., "day", "week").
* @param moveDir The direction of movement ("before" or "after").
* @param refDay The currently focused day.
* @param calendarStartMonth The earliest month the user can navigate to.
* @param calendarEndMonth The latest month the user can navigate to.
* @param props The DayPicker props, including modifiers and configuration
* options.
* @param dateLib The date library to use for date manipulation.
* @param attempt The current recursion attempt (used to limit recursion depth).
* @returns The next focusable day, or `undefined` if no focusable day is found.
*/
export declare function getNextFocus(moveBy: MoveFocusBy, moveDir: MoveFocusDir, refDay: CalendarDay, calendarStartMonth: Date | undefined, calendarEndMonth: Date | undefined, props: Pick<DayPickerProps, "disabled" | "hidden" | "modifiers" | "ISOWeek" | "timeZone">, dateLib: DateLib, attempt?: number): CalendarDay | undefined;
+40
View File
@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNextFocus = getNextFocus;
const index_js_1 = require("../classes/index.js");
const dateMatchModifiers_js_1 = require("../utils/dateMatchModifiers.js");
const getFocusableDate_js_1 = require("./getFocusableDate.js");
/**
* Determines the next focusable day in the calendar.
*
* This function recursively calculates the next focusable day based on the
* movement direction and modifiers applied to the days.
*
* @param moveBy The unit of movement (e.g., "day", "week").
* @param moveDir The direction of movement ("before" or "after").
* @param refDay The currently focused day.
* @param calendarStartMonth The earliest month the user can navigate to.
* @param calendarEndMonth The latest month the user can navigate to.
* @param props The DayPicker props, including modifiers and configuration
* options.
* @param dateLib The date library to use for date manipulation.
* @param attempt The current recursion attempt (used to limit recursion depth).
* @returns The next focusable day, or `undefined` if no focusable day is found.
*/
function getNextFocus(moveBy, moveDir, refDay, calendarStartMonth, calendarEndMonth, props, dateLib, attempt = 0) {
if (attempt > 365) {
// Limit the recursion to 365 attempts
return undefined;
}
const focusableDate = (0, getFocusableDate_js_1.getFocusableDate)(moveBy, moveDir, refDay.date, calendarStartMonth, calendarEndMonth, props, dateLib);
const isDisabled = Boolean(props.disabled &&
(0, dateMatchModifiers_js_1.dateMatchModifiers)(focusableDate, props.disabled, dateLib));
const isHidden = Boolean(props.hidden && (0, dateMatchModifiers_js_1.dateMatchModifiers)(focusableDate, props.hidden, dateLib));
const targetMonth = focusableDate;
const focusDay = new index_js_1.CalendarDay(focusableDate, targetMonth, dateLib);
if (!isDisabled && !isHidden) {
return focusDay;
}
// Recursively attempt to find the next focusable date
return getNextFocus(moveBy, moveDir, focusDay, calendarStartMonth, calendarEndMonth, props, dateLib, attempt + 1);
}
+20
View File
@@ -0,0 +1,20 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DayPickerProps } from "../types/index.js";
/**
* Returns the next month the user can navigate to, based on the given options.
*
* The next month is not always the next calendar month:
*
* - If it is after the `calendarEndMonth`, it returns `undefined`.
* - If paged navigation is enabled, it skips forward by the number of displayed
* months.
*
* @param firstDisplayedMonth The first month currently displayed in the
* calendar.
* @param calendarEndMonth The latest month the user can navigate to.
* @param options Navigation options, including `numberOfMonths` and
* `pagedNavigation`.
* @param dateLib The date library to use for date manipulation.
* @returns The next month, or `undefined` if navigation is not possible.
*/
export declare function getNextMonth(firstDisplayedMonth: Date, calendarEndMonth: Date | undefined, options: Pick<DayPickerProps, "numberOfMonths" | "pagedNavigation" | "disableNavigation">, dateLib: DateLib): Date | undefined;
+37
View File
@@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNextMonth = getNextMonth;
/**
* Returns the next month the user can navigate to, based on the given options.
*
* The next month is not always the next calendar month:
*
* - If it is after the `calendarEndMonth`, it returns `undefined`.
* - If paged navigation is enabled, it skips forward by the number of displayed
* months.
*
* @param firstDisplayedMonth The first month currently displayed in the
* calendar.
* @param calendarEndMonth The latest month the user can navigate to.
* @param options Navigation options, including `numberOfMonths` and
* `pagedNavigation`.
* @param dateLib The date library to use for date manipulation.
* @returns The next month, or `undefined` if navigation is not possible.
*/
function getNextMonth(firstDisplayedMonth, calendarEndMonth, options, dateLib) {
if (options.disableNavigation) {
return undefined;
}
const { pagedNavigation, numberOfMonths = 1 } = options;
const { startOfMonth, addMonths, differenceInCalendarMonths } = dateLib;
const offset = pagedNavigation ? numberOfMonths : 1;
const month = startOfMonth(firstDisplayedMonth);
if (!calendarEndMonth) {
return addMonths(month, offset);
}
const monthsDiff = differenceInCalendarMonths(calendarEndMonth, firstDisplayedMonth);
if (monthsDiff < numberOfMonths) {
return undefined;
}
return addMonths(month, offset);
}
+21
View File
@@ -0,0 +1,21 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DayPickerProps } from "../types/index.js";
/**
* Returns the previous month the user can navigate to, based on the given
* options.
*
* The previous month is not always the previous calendar month:
*
* - If it is before the `calendarStartMonth`, it returns `undefined`.
* - If paged navigation is enabled, it skips back by the number of displayed
* months.
*
* @param firstDisplayedMonth The first month currently displayed in the
* calendar.
* @param calendarStartMonth The earliest month the user can navigate to.
* @param options Navigation options, including `numberOfMonths` and
* `pagedNavigation`.
* @param dateLib The date library to use for date manipulation.
* @returns The previous month, or `undefined` if navigation is not possible.
*/
export declare function getPreviousMonth(firstDisplayedMonth: Date, calendarStartMonth: Date | undefined, options: Pick<DayPickerProps, "numberOfMonths" | "pagedNavigation" | "disableNavigation">, dateLib: DateLib): Date | undefined;
+38
View File
@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPreviousMonth = getPreviousMonth;
/**
* Returns the previous month the user can navigate to, based on the given
* options.
*
* The previous month is not always the previous calendar month:
*
* - If it is before the `calendarStartMonth`, it returns `undefined`.
* - If paged navigation is enabled, it skips back by the number of displayed
* months.
*
* @param firstDisplayedMonth The first month currently displayed in the
* calendar.
* @param calendarStartMonth The earliest month the user can navigate to.
* @param options Navigation options, including `numberOfMonths` and
* `pagedNavigation`.
* @param dateLib The date library to use for date manipulation.
* @returns The previous month, or `undefined` if navigation is not possible.
*/
function getPreviousMonth(firstDisplayedMonth, calendarStartMonth, options, dateLib) {
if (options.disableNavigation) {
return undefined;
}
const { pagedNavigation, numberOfMonths } = options;
const { startOfMonth, addMonths, differenceInCalendarMonths } = dateLib;
const offset = pagedNavigation ? (numberOfMonths ?? 1) : 1;
const month = startOfMonth(firstDisplayedMonth);
if (!calendarStartMonth) {
return addMonths(month, -offset);
}
const monthsDiff = differenceInCalendarMonths(month, calendarStartMonth);
if (monthsDiff <= 0) {
return undefined;
}
return addMonths(month, -offset);
}
@@ -0,0 +1,14 @@
import type { CSSProperties } from "react";
import type { Modifiers, ModifiersStyles, Styles } from "../types/index.js";
/**
* Returns the computed style for a day based on its modifiers.
*
* This function merges the base styles for the day with any styles associated
* with active modifiers.
*
* @param dayModifiers The modifiers applied to the day.
* @param styles The base styles for the calendar elements.
* @param modifiersStyles The styles associated with specific modifiers.
* @returns The computed style for the day.
*/
export declare function getStyleForModifiers(dayModifiers: Modifiers, styles?: Partial<Styles>, modifiersStyles?: Partial<ModifiersStyles>): CSSProperties;
+27
View File
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStyleForModifiers = getStyleForModifiers;
const UI_js_1 = require("../UI.js");
/**
* Returns the computed style for a day based on its modifiers.
*
* This function merges the base styles for the day with any styles associated
* with active modifiers.
*
* @param dayModifiers The modifiers applied to the day.
* @param styles The base styles for the calendar elements.
* @param modifiersStyles The styles associated with specific modifiers.
* @returns The computed style for the day.
*/
function getStyleForModifiers(dayModifiers, styles = {}, modifiersStyles = {}) {
let style = { ...styles?.[UI_js_1.UI.Day] };
Object.entries(dayModifiers)
.filter(([, active]) => active === true)
.forEach(([modifier]) => {
style = {
...style,
...modifiersStyles?.[modifier],
};
});
return style;
}
+12
View File
@@ -0,0 +1,12 @@
import type { DateLib } from "../classes/DateLib.js";
/**
* Generates a series of 7 days, starting from the beginning of the week, to use
* for formatting weekday names (e.g., Monday, Tuesday, etc.).
*
* @param dateLib The date library to use for date manipulation.
* @param ISOWeek Whether to use ISO week numbering (weeks start on Monday).
* @param broadcastCalendar Whether to use the broadcast calendar (weeks start
* on Monday, but may include adjustments for broadcast-specific rules).
* @returns An array of 7 dates representing the weekdays.
*/
export declare function getWeekdays(dateLib: DateLib, ISOWeek?: boolean | undefined, broadcastCalendar?: boolean | undefined, today?: Date): Date[];
+27
View File
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWeekdays = getWeekdays;
/**
* Generates a series of 7 days, starting from the beginning of the week, to use
* for formatting weekday names (e.g., Monday, Tuesday, etc.).
*
* @param dateLib The date library to use for date manipulation.
* @param ISOWeek Whether to use ISO week numbering (weeks start on Monday).
* @param broadcastCalendar Whether to use the broadcast calendar (weeks start
* on Monday, but may include adjustments for broadcast-specific rules).
* @returns An array of 7 dates representing the weekdays.
*/
function getWeekdays(dateLib, ISOWeek, broadcastCalendar, today) {
const referenceToday = today ?? dateLib.today();
const start = broadcastCalendar
? dateLib.startOfBroadcastWeek(referenceToday, dateLib)
: ISOWeek
? dateLib.startOfISOWeek(referenceToday)
: dateLib.startOfWeek(referenceToday);
const days = [];
for (let i = 0; i < 7; i++) {
const day = dateLib.addDays(start, i);
days.push(day);
}
return days;
}
+8
View File
@@ -0,0 +1,8 @@
import type { CalendarMonth, CalendarWeek } from "../classes/index.js";
/**
* Returns an array of calendar weeks from an array of calendar months.
*
* @param months The array of calendar months.
* @returns An array of calendar weeks.
*/
export declare function getWeeks(months: CalendarMonth[]): CalendarWeek[];
+15
View File
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWeeks = getWeeks;
/**
* Returns an array of calendar weeks from an array of calendar months.
*
* @param months The array of calendar months.
* @returns An array of calendar weeks.
*/
function getWeeks(months) {
const initialWeeks = [];
return months.reduce((weeks, month) => {
return weeks.concat(month.weeks.slice());
}, initialWeeks.slice());
}
+18
View File
@@ -0,0 +1,18 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DropdownOption } from "../components/Dropdown.js";
import type { Formatters } from "../types/index.js";
/**
* Returns the years to display in the dropdown.
*
* This function generates a list of years between the navigation start and end
* dates, formatted using the provided formatter.
*
* @param navStart The start date for navigation.
* @param navEnd The end date for navigation.
* @param formatters The formatters to use for formatting the year labels.
* @param dateLib The date library to use for date manipulation.
* @param reverse If true, reverses the order of the years (descending).
* @returns An array of dropdown options representing the years, or `undefined`
* if `navStart` or `navEnd` is not provided.
*/
export declare function getYearOptions(navStart: Date | undefined, navEnd: Date | undefined, formatters: Pick<Formatters, "formatYearDropdown">, dateLib: DateLib, reverse?: boolean): DropdownOption[] | undefined;
+37
View File
@@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getYearOptions = getYearOptions;
/**
* Returns the years to display in the dropdown.
*
* This function generates a list of years between the navigation start and end
* dates, formatted using the provided formatter.
*
* @param navStart The start date for navigation.
* @param navEnd The end date for navigation.
* @param formatters The formatters to use for formatting the year labels.
* @param dateLib The date library to use for date manipulation.
* @param reverse If true, reverses the order of the years (descending).
* @returns An array of dropdown options representing the years, or `undefined`
* if `navStart` or `navEnd` is not provided.
*/
function getYearOptions(navStart, navEnd, formatters, dateLib, reverse = false) {
if (!navStart)
return undefined;
if (!navEnd)
return undefined;
const { startOfYear, endOfYear, eachYearOfInterval, getYear } = dateLib;
const firstNavYear = startOfYear(navStart);
const lastNavYear = endOfYear(navEnd);
const years = eachYearOfInterval({ start: firstNavYear, end: lastNavYear });
if (reverse)
years.reverse();
return years.map((year) => {
const label = formatters.formatYearDropdown(year, dateLib);
return {
value: getYear(year),
label,
disabled: false,
};
});
}
+1
View File
@@ -0,0 +1 @@
export * from "./getDefaultClassNames.js";
+18
View File
@@ -0,0 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
// Only export helpers that can be useful to other developers.
__exportStar(require("./getDefaultClassNames.js"), exports);
@@ -0,0 +1,14 @@
import type { DateLib } from "../classes/index.js";
/**
* Returns the start date of the week in the broadcast calendar.
*
* The broadcast week starts on Monday. If the first day of the month is not a
* Monday, this function calculates the previous Monday as the start of the
* broadcast week.
*
* @since 9.4.0
* @param date The date for which to calculate the start of the broadcast week.
* @param dateLib The date library to use for date manipulation.
* @returns The start date of the broadcast week.
*/
export declare function startOfBroadcastWeek(date: Date, dateLib: DateLib): Date;
+28
View File
@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startOfBroadcastWeek = startOfBroadcastWeek;
/**
* Returns the start date of the week in the broadcast calendar.
*
* The broadcast week starts on Monday. If the first day of the month is not a
* Monday, this function calculates the previous Monday as the start of the
* broadcast week.
*
* @since 9.4.0
* @param date The date for which to calculate the start of the broadcast week.
* @param dateLib The date library to use for date manipulation.
* @returns The start date of the broadcast week.
*/
function startOfBroadcastWeek(date, dateLib) {
const firstOfMonth = dateLib.startOfMonth(date);
const dayOfWeek = firstOfMonth.getDay();
if (dayOfWeek === 1) {
return firstOfMonth;
}
else if (dayOfWeek === 0) {
return dateLib.addDays(firstOfMonth, -1 * 6);
}
else {
return dateLib.addDays(firstOfMonth, -1 * (dayOfWeek - 1));
}
}
+24
View File
@@ -0,0 +1,24 @@
export type DispatchStateAction<T> = React.Dispatch<React.SetStateAction<T>>;
/**
* A custom hook for managing both controlled and uncontrolled component states.
*
* This hook allows a component to support both controlled and uncontrolled
* states by determining whether the `controlledValue` is provided. If it is
* undefined, the hook falls back to using the internal state.
*
* @example
* // Uncontrolled usage
* const [value, setValue] = useControlledValue(0, undefined);
*
* // Controlled usage
* const [value, setValue] = useControlledValue(0, props.value);
*
* @template T - The type of the value.
* @param defaultValue The initial value for the uncontrolled state.
* @param controlledValue The value for the controlled state. If undefined, the
* component will use the uncontrolled state.
* @returns A tuple where the first element is the current value (either
* controlled or uncontrolled) and the second element is a setter function to
* update the value.
*/
export declare function useControlledValue<T>(defaultValue: T, controlledValue: T | undefined): [T, DispatchStateAction<T>];
+31
View File
@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useControlledValue = useControlledValue;
const react_1 = require("react");
/**
* A custom hook for managing both controlled and uncontrolled component states.
*
* This hook allows a component to support both controlled and uncontrolled
* states by determining whether the `controlledValue` is provided. If it is
* undefined, the hook falls back to using the internal state.
*
* @example
* // Uncontrolled usage
* const [value, setValue] = useControlledValue(0, undefined);
*
* // Controlled usage
* const [value, setValue] = useControlledValue(0, props.value);
*
* @template T - The type of the value.
* @param defaultValue The initial value for the uncontrolled state.
* @param controlledValue The value for the controlled state. If undefined, the
* component will use the uncontrolled state.
* @returns A tuple where the first element is the current value (either
* controlled or uncontrolled) and the second element is a setter function to
* update the value.
*/
function useControlledValue(defaultValue, controlledValue) {
const [uncontrolledValue, setValue] = (0, react_1.useState)(defaultValue);
const value = controlledValue === undefined ? uncontrolledValue : controlledValue;
return [value, setValue];
}