@uplink-protocol/calendar-controller
Version:
Flexible calendar API supporting both calendar and date-picker integrations for any JavaScript framework or library
429 lines (428 loc) • 12.5 kB
TypeScript
import { ControllerAdapter } from "@uplink-protocol/core";
import { ControllerMetadata } from "@uplink-protocol/core/dist/uplink/interfaces/metadata/controller-metadata.interface";
import { CalendarDate, CalendarMonth, CalendarYear, CalendarOptions, DateRange, YearRange } from "./interfaces";
import { TypedCalendarController, CalendarControllerBindings, CalendarControllerMethods, CalendarControllerEvents } from "./types";
/**
* CalendarControllerClass - A full featured date picker controller class.
* Provides functionality for date picking and calendar display.
*
* This controller uses a service-oriented architecture where all the core
* functionality is delegated to specialized services.
*/
export interface CalendarControllerInterface extends TypedCalendarController {
_currentDate: Date;
_selectedDate: Date | null;
_selectedDateRange: DateRange;
_focusedDate: Date | null;
_minDate: Date | null;
_maxDate: Date | null;
_disabledDates: Date[];
_disabledDaysOfWeek: number[];
_firstDayOfWeek: number;
_dateFormat: string | null;
_isRangeSelection: boolean;
_hideOtherMonthDays: boolean;
_locale: string;
_dateFormatOptions: Intl.DateTimeFormatOptions | null;
_yearRangeSize: number;
_currentYearRangeBase: number;
nextMonth?: () => void;
prevMonth?: () => void;
previousMonth?: () => void;
nextYear?: () => void;
prevYear?: () => void;
}
export declare class CalendarControllerClass implements CalendarControllerInterface {
bindings: CalendarControllerBindings;
methods: CalendarControllerMethods;
events: CalendarControllerEvents;
meta?: ControllerMetadata;
__adapter?: ControllerAdapter;
options?: CalendarOptions;
nextMonth?: () => void;
prevMonth?: () => void;
previousMonth?: () => void;
nextYear?: () => void;
prevYear?: () => void;
_currentDate: Date;
_selectedDate: Date | null;
_selectedDateRange: DateRange;
_focusedDate: Date | null;
_minDate: Date | null;
_maxDate: Date | null;
_disabledDates: Date[];
_disabledDaysOfWeek: number[];
_firstDayOfWeek: number;
_dateFormat: string | null;
_isRangeSelection: boolean;
_hideOtherMonthDays: boolean;
_locale: string;
_dateFormatOptions: Intl.DateTimeFormatOptions | null;
_yearRangeSize: number;
_currentYearRangeBase: number;
private _calendarService;
private _localizationService;
private _dateFormattingService;
private _dateSelectionService;
private _viewStateService;
private _eventManagerService;
private _navigationService;
private _constraintsService;
private _calendarGeneratorService;
private _configurationService;
private _accessibilityService;
private _accessibilityManagerService;
private _calendarStateService;
/**
* Constructor - initializes the controller with optional configuration
* @param options Calendar configuration options
*/
constructor(options?: CalendarOptions);
/**
* Generate calendar days for current month view using CalendarGeneratorService
* @returns Array of CalendarDate objects
*/
generateCalendarDays(): CalendarDate[];
/**
* Generate calendar months for year view
* @returns Array of CalendarMonth objects
*/
generateCalendarMonths(): CalendarMonth[];
/**
* Generate calendar years for year range view
* @returns Array of CalendarYear objects
*/
generateCalendarYears(): CalendarYear[];
/**
* Check if a date is disabled by constraints or disabled dates array
* @param date Date to check
* @returns true if date is disabled
*/
private isDateDisabled;
/**
* Select a date
* @param yearOrDate Year value or Date object
* @param month Month value (0-based) - optional when yearOrDate is a Date
* @param day Day value - optional when yearOrDate is a Date
*/
selectDate(yearOrDate: number | Date, month?: number, day?: number): void;
/**
* Navigate to a specific month
* @param month Month (0-based)
* @param year Year
*/
goToMonth(month: number, year: number): void;
/**
* Navigate to a specific year
* @param year Year
*/
goToYear(year: number): void;
/**
* Navigate to a specific date
* @param date Target date
*/
goToDate(date: Date): void;
/**
* Navigate to next month
*/
goToNextMonth(): void;
/**
* Navigate to previous month
*/
goToPreviousMonth(): void;
/**
* Navigate to next year
*/
goToNextYear(): void;
/**
* Navigate to previous year
*/
goToPreviousYear(): void;
/**
* Navigate to today's date
*/
goToToday(): void;
/**
* Navigate to next year range
*/
goToNextYearRange(): void;
/**
* Navigate to previous year range
*/
goToPreviousYearRange(): void;
/**
* Update current date and related bindings
* @param date New current date
*/ private updateCurrentDate;
/**
* Update view-related bindings
*/
private updateViewBindings;
/**
* Set range selection mode
* @param isRange Whether range selection is enabled
*/
setRangeSelectionMode(isRange: boolean): void;
/**
* Clear current selection
*/
clearSelection(): void;
/**
* Get formatted date string
* @returns Formatted date string or null
*/
getFormattedDate(): string | null;
/**
* Set minimum selectable date
* @param date Minimum date or null
*/
setMinDate(date: Date | null): void;
/**
* Set maximum selectable date
* @param date Maximum date or null
*/
setMaxDate(date: Date | null): void;
/**
* Set disabled dates
* @param dates Array of disabled dates
*/
setDisabledDates(dates: Date[]): void;
/**
* Add a disabled date
* @param date Date to disable
* @returns Updated disabled dates array
*/
addDisabledDate(date: Date): Date[];
/**
* Remove a disabled date
* @param date Date to enable
* @returns Updated disabled dates array
*/
removeDisabledDate(date: Date): Date[];
/**
* Get disabled dates
* @returns Array of disabled dates
*/
getDisabledDates(): Date[];
/**
* Set disabled days of the week
* @param days Array of disabled days (0 = Sunday, 1 = Monday, etc.)
* @returns Array of disabled days
*/
setDisabledDaysOfWeek(days: number[]): number[];
/**
* Add a disabled day of the week
* @param day Day of the week to disable (0 = Sunday, 1 = Monday, etc.)
* @returns Updated disabled days array
*/
addDisabledDayOfWeek(day: number): number[];
/**
* Remove a disabled day of the week
* @param day Day of the week to enable (0 = Sunday, 1 = Monday, etc.)
* @returns Updated disabled days array
*/
removeDisabledDayOfWeek(day: number): number[];
/**
* Get disabled days of the week
* @returns Array of disabled days (0 = Sunday, 1 = Monday, etc.)
*/
getDisabledDaysOfWeek(): number[];
/**
* Set locale
* @param locale Locale string
*/
setLocale(locale: string): void;
/**
* Get current locale
* @returns Current locale string
*/
getLocale(): string;
/**
* Set date format options
* @param options Intl.DateTimeFormatOptions
*/
setDateFormatOptions(options: Intl.DateTimeFormatOptions): void;
/**
* Get date format options
* @returns Current date format options
*/
getDateFormatOptions(): Intl.DateTimeFormatOptions | null;
/**
* Set focused date
* @param date Date to focus or null
*/
setFocusedDate(date: Date | null): void;
/**
* Clear focused date
*/
clearFocusedDate(): void;
/**
* Format a date with given options
* @param date Date to format
* @param options Format options or format string
* @returns Formatted date string
*/ formatDate(date: Date, options?: Intl.DateTimeFormatOptions | string): string;
/**
* Get month names in current locale
* @returns Array of month names
*/
getMonthNames(): string[];
/**
* Get weekday names in current locale
* @param short Whether to use short names
* @returns Array of weekday names
*/
getWeekdayNames(short?: boolean): string[];
/**
* Get current year range
* @returns Year range object
*/
getCurrentYearRange(): YearRange;
/**
* Set current year range based on date
* @param date Date to base range on
*/
setCurrentYearRange(date: Date): void;
/**
* Get year range base for a given date
* @param date Input date
* @returns Year range
*/
private getYearRangeBase;
/**
* Set year range size
* @param size Number of years to display
*/
setYearRangeSize(size: number): void;
/**
* Select month (navigate to month view)
* @param month Month number (0-based)
* @param year Year number
*/
selectMonth(month: number, year: number): void;
/**
* Select year (navigate to year view)
* @param year Year number
*/
selectYear(year: number): void;
/**
* Focus a specific date
* @param date Date to focus
*/
focusDate(date: Date): void;
/**
* Move focus right (next day)
*/
moveFocusRight(): void;
/**
* Move focus left (previous day)
*/
moveFocusLeft(): void;
/**
* Move focus up (previous week)
*/
moveFocusUp(): void;
/**
* Move focus down (next week)
*/
moveFocusDown(): void;
/**
* Move focus to start of month
*/
moveFocusToStartOfMonth(): void;
/**
* Move focus to end of month
*/
moveFocusToEndOfMonth(): void;
/**
* Move focus to previous month
*/
moveFocusToPreviousMonth(): void;
/**
* Move focus to next month
*/
moveFocusToNextMonth(): void;
/**
* Move focus to previous year
*/
moveFocusToPreviousYear(): void;
/**
* Move focus to next year
*/
moveFocusToNextYear(): void;
/**
* Select the currently focused date
*/
selectFocusedDate(): void;
/**
* Get accessible label for a date
* @param date Date to get label for
* @returns Accessible label string
*/
getAccessibleDateLabel(date: Date): string;
/**
* Check if date is today
* @param date Date to check
* @returns true if date is today
*/
isToday(date: Date): boolean;
/**
* Get date state description for accessibility
* @param date Date to describe
* @returns State description string
*/
getDateStateDescription(date: Date): string;
/**
* Generate month view data
* @returns Month view object
*/
generateMonthView(): {
month: number;
year: number;
weeks: {
days: CalendarDate[];
weekNumber?: number;
}[];
weekdays: string[];
};
/**
* Get week number for a date
* @param date Date to get week number for
* @returns Week number
*/
getWeekNumber(date: Date): number;
/**
* Get selected date range with flexible property access
*/
get selectedDateRange(): {
start: Date | null;
end: Date | null;
startDate: Date | null;
endDate: Date | null;
};
/**
* Set selected date range with flexible property access
*/
set selectedDateRange(value: {
start?: Date | null;
end?: Date | null;
startDate?: Date | null;
endDate?: Date | null;
});
/**
* Update all bindings with optional selective updates
* @param updates Object specifying which bindings to update
*/
private updateAllBindings; /**
* Execute batched binding updates for performance
* @param updates Array of update functions
*/
private executeBatchedBindingUpdates;
}
/**
* CalendarController - Factory function that creates and returns a new CalendarControllerClass instance.
*
* @param options Optional calendar configuration options
* @returns A CalendarControllerClass instance
*/
export declare const CalendarController: (options?: CalendarOptions) => CalendarControllerClass;