|
| 1 | +export { default as default } from './actions.svelte.js'; |
| 2 | +export { default as l10n } from 'flatpickr_plus/dist/l10n'; |
| 3 | +import { default as tc, getCurrentThemeName } from './themeChanger.js'; |
| 4 | +import type { DateLimit, DateOption, Hook } from './types.js'; |
| 5 | +export type FlatpickrOptions = { |
| 6 | + allowInput?: boolean; // Allows the user to enter a date directly into the input field. |
| 7 | + allowInvalidPreload?: boolean; // Allow preloading of an invalid date. |
| 8 | + altFormat?: string; // Exactly the same as date format, but for the altInput field. |
| 9 | + altInput?: boolean; // Show the user a readable date (as per altFormat). |
| 10 | + altInputClass?: string; // Class added to the input element created by the altInput option. |
| 11 | + animate?: boolean; // Whether to enable animations, such as month transitions. |
| 12 | + appendTo?: HTMLElement; // Appends the calendar to the specified node instead of body. |
| 13 | + ariaDateFormat?: string; // Defines how the date will be formatted in the aria-label. |
| 14 | + autoFillDefaultTime?: boolean; // Whether the default time should be auto-filled. |
| 15 | + clickOpens?: boolean; // Whether clicking on the input should open the picker. |
| 16 | + closeOnSelect?: boolean; // Whether the calendar should close after date selection. |
| 17 | + conjunction?: string; // Used to join selected dates together for the date input value. |
| 18 | + dateFormat?: string; // Defines how the date will be displayed in the input box. |
| 19 | + defaultDate?: DateOption | DateOption[]; // The initial selected date(s). |
| 20 | + defaultHour?: number; // Initial value of the hour element. |
| 21 | + defaultMinute?: number; // Initial value of the minute element. |
| 22 | + defaultSeconds?: number; // Initial value of the seconds element. |
| 23 | + disable?: DateLimit<DateOption>[]; // Disables certain dates. |
| 24 | + disableMobile?: boolean; // Always use the non-native picker on mobile devices. |
| 25 | + enable?: DateLimit<DateOption>[]; // Disables all dates except these specified. |
| 26 | + enableSeconds?: boolean; // Enables seconds selection in the time picker. |
| 27 | + enableTime?: boolean; // Enables the time picker. |
| 28 | + errorHandler?: (e: Error) => void; // Custom error handling function. |
| 29 | + formatDate?: (date: Date, format: string, locale: any) => string; // Custom date formatting function. |
| 30 | + getWeek?: (date: Date) => string | number; // Outputs the week number for a given date. |
| 31 | + hourIncrement?: number; // Adjusts the step for the hour input. |
| 32 | + ignoredFocusElements?: HTMLElement[]; // Elements that will not close the calendar when clicked. |
| 33 | + inline?: boolean; // Displays the calendar inline. |
| 34 | + isMonthPicker?: boolean; // Whether the calendar is a month picker. |
| 35 | + locale?: any | Partial<any>; // The locale, either as a string or as an object. |
| 36 | + maxDate?: DateOption; // The maximum date that a user can pick. |
| 37 | + maxTime?: DateOption; // The maximum time that a user can pick. |
| 38 | + minDate?: DateOption; // The minimum date that a user can pick. |
| 39 | + minTime?: DateOption; // The minimum time that a user can pick. |
| 40 | + minuteIncrement?: number; // Adjusts the step for the minute input. |
| 41 | + mode?: 'single' | 'multiple' | 'range' | 'time'; // Date selection mode. |
| 42 | + monthSelectorType?: 'dropdown' | 'static'; // How the month selector should be shown. |
| 43 | + nextArrow?: string; // HTML for the right arrow icon. |
| 44 | + noCalendar?: boolean; // Hides the day selection in the calendar. |
| 45 | + now?: DateOption; // Specifies the current date and time. |
| 46 | + onChange?: Hook | Hook[]; // Fires when the selected dates have changed. |
| 47 | + onClose?: Hook | Hook[]; // Fires when the calendar is closed. |
| 48 | + onDayCreate?: Hook | Hook[]; // Fires for every day cell in the calendar. |
| 49 | + onDestroy?: Hook | Hook[]; // Fires before the calendar instance is destroyed. |
| 50 | + onKeyDown?: Hook | Hook[]; // Fires when valid keyboard input for the calendar is detected. |
| 51 | + onMonthChange?: Hook | Hook[]; // Fires after the month has changed. |
| 52 | + onOpen?: Hook | Hook[]; // Fires after the calendar is opened. |
| 53 | + onParseConfig?: Hook | Hook[]; // Fires after the configuration for the calendar is parsed. |
| 54 | + onReady?: Hook | Hook[]; // Fires once the calendar instance is ready. |
| 55 | + onValueUpdate?: Hook | Hook[]; // Fires immediately after any date changes. |
| 56 | + onYearChange?: Hook | Hook[]; // Fires after the year has changed. |
| 57 | + onPreCalendarPosition?: Hook | Hook[]; // Fires before the calendar position is calculated. |
| 58 | + parseDate?: (date: string, format: string) => Date; // A custom datestring parser. |
| 59 | + plugins?: Plugin[]; // Plugins for Flatpickr. |
| 60 | + position?: |
| 61 | + | 'auto' |
| 62 | + | 'above' |
| 63 | + | 'below' |
| 64 | + | 'auto left' |
| 65 | + | 'auto center' |
| 66 | + | 'auto right' |
| 67 | + | 'above left' |
| 68 | + | 'above center' |
| 69 | + | 'above right' |
| 70 | + | 'below left' |
| 71 | + | 'below center' |
| 72 | + | 'below right' |
| 73 | + | ((self: any, customElement: HTMLElement | undefined) => void); // How the calendar should be positioned. |
| 74 | + positionElement?: Element; // The element off of which the calendar will be positioned. |
| 75 | + prevArrow?: string; // HTML for the left arrow icon. |
| 76 | + shorthandCurrentMonth?: boolean; // Whether to display the current month name in shorthand mode. |
| 77 | + shorthand?: boolean; // Whether to display the current date in shorthand mode. |
| 78 | + static?: boolean; // Creates a wrapper to position the calendar. |
| 79 | + showMonths?: number; // Sets the number of months to show. |
| 80 | + time_24hr?: boolean; // Displays time picker in 24-hour mode. |
| 81 | + weekNumbers?: boolean; // Display week numbers left of the calendar. |
| 82 | + wrap?: boolean; // See external elements for Flatpickr. |
| 83 | + useLocaleYear?: boolean; // Handling year as locale year. |
| 84 | + resetMoveDefault?: boolean; // Handling reset and move to calendar to default date. |
| 85 | + resetToDefault?: boolean; // Handling reset and selected a default date. |
| 86 | +}; |
| 87 | + |
| 88 | +/** |
| 89 | + * Enum-like object defining available theme names |
| 90 | + * @enum {string} |
| 91 | + */ |
| 92 | +export const themeNames = { |
| 93 | + default: 'default', |
| 94 | + light: 'light', |
| 95 | + dark: 'dark', |
| 96 | + materialBlue: 'material_blue', |
| 97 | + materialGreen: 'material_green', |
| 98 | + materialRed: 'material_red', |
| 99 | + materialOrange: 'material_orange', |
| 100 | + airbnb: 'airbnb', |
| 101 | + confetti: 'confetti' |
| 102 | +}; |
| 103 | + |
| 104 | +/** |
| 105 | + * Retrieves a CSS file for a given theme name. |
| 106 | + * |
| 107 | + * @param { string } themeName - The name of the theme to load |
| 108 | + * @returns { Promise < string | null >} The CSS content of the theme or null if not found |
| 109 | + * |
| 110 | + * @example |
| 111 | + * // Successful theme load |
| 112 | + * const darkTheme = await themes('dark'); |
| 113 | + * |
| 114 | + * @example |
| 115 | + * // Theme not found |
| 116 | + * const missingTheme = await themes('nonexistent'); |
| 117 | + * // Returns null |
| 118 | + */ |
| 119 | +export async function themeChanger(themeName) { |
| 120 | + // Validate input |
| 121 | + if (typeof themeName !== 'string' || !themeName.trim()) { |
| 122 | + return null; |
| 123 | + } |
| 124 | + |
| 125 | + // Construct the potential theme path |
| 126 | + const themePath = `https://npmcdn.com/flatpickr/dist/themes/`; |
| 127 | + |
| 128 | + tc(themeName, themePath); |
| 129 | +} |
| 130 | +export function currentTheme() { |
| 131 | + const themePath = `https://npmcdn.com/flatpickr/dist/themes/`; |
| 132 | + return getCurrentThemeName(themePath); |
| 133 | +} |
0 commit comments