@lumx/core 4.28.1-alpha.0 → 4.29.0-next.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.
@@ -0,0 +1,34 @@
1
+ /** Calendar days: the day of a `Date` is its local date, the time of day is ignored. */
2
+ /** Check that `date` is a valid date. */
3
+ export declare const isDateValid: (date?: Date | null) => date is Date;
4
+ /**
5
+ * Get the calendar date of a day: the `00:00 UTC` instant whose local date is the day, else the local start of the
6
+ * day (ex: clock change at midnight in `Atlantic/Azores`). Every date that a date picker sets is a calendar date.
7
+ * The day overflows like the `Date` constructor. Two-digit years are not mapped to 19xx.
8
+ */
9
+ export declare function getCalendarDate(year: number, monthIndex: number, day: number): Date;
10
+ /** Get the calendar date of the day of `date`. */
11
+ export declare const toCalendarDate: (date: Date) => Date;
12
+ /** Check that `date1` and `date2` are on the same day. `false` if one of them is not a valid date. */
13
+ export declare const isSameDay: (date1?: Date | null, date2?: Date | null) => boolean;
14
+ /**
15
+ * Check that the day of `date` is in the range (`minDate` and `maxDate` days included).
16
+ * An invalid `minDate` or `maxDate` is ignored.
17
+ */
18
+ export declare const isDateInRange: (date: Date, minDate?: Date, maxDate?: Date) => boolean;
19
+ /**
20
+ * Snap a date to the range: the calendar date of the `minDate` day when `date` is before the range, the calendar
21
+ * date of the `maxDate` day when it is after. Returns `date` itself when it is in the range.
22
+ */
23
+ export declare function snapDateToRange(date: Date, minDate?: Date, maxDate?: Date): Date;
24
+ /** `YYYY-MM-DD` key of the day of `date` (the `data-date` attribute of a calendar grid day). */
25
+ export declare const getDateKey: (date: Date) => string;
26
+ /** Parse a `YYYY-MM-DD` key (see {@link getDateKey}) to its calendar date. `undefined` when not a valid key. */
27
+ export declare function parseDateKey(key: string | null | undefined): Date | undefined;
28
+ /** Number of days in a month (`monthIndex`: 0 = January). */
29
+ export declare function getDaysInMonth(year: number, monthIndex: number): number;
30
+ /**
31
+ * Add a number of months to a date, on the first day of the month (no month length mismatch).
32
+ * Keeps the time of day.
33
+ */
34
+ export declare function addMonthResetDay(date: Date, monthOffset: number): Date;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Options of the long date format (the text of a date picker field).
3
+ * Gregorian calendar: `parseDate` reads the typed fields as Gregorian (ex: no Buddhist year in `th`).
4
+ */
5
+ export declare const LONG_DATE_FORMAT: Intl.DateTimeFormatOptions;
6
+ /**
7
+ * Format a date in the long format of the locale (ex: `November 12, 2026`, `12 novembre 2026`).
8
+ * Empty string when there is no valid date.
9
+ */
10
+ export declare const formatDate: (date: Date | undefined, locale: string) => string;
11
+ /** Format the day number of a date in the locale (only the digits when the locale format has digits). */
12
+ export declare function formatDayNumber(date: Date, locale: string): string;
@@ -0,0 +1,39 @@
1
+ /** A keyboard move in the calendar grid. */
2
+ export type CalendarMove =
3
+ /** Right arrow. */
4
+ 'nextDay'
5
+ /** Left arrow. */
6
+ | 'previousDay'
7
+ /** Down arrow. */
8
+ | 'nextWeek'
9
+ /** Up arrow. */
10
+ | 'previousWeek'
11
+ /** Page Down: same day number in the next month (last day if missing). */
12
+ | 'nextMonth'
13
+ /** Page Up: same day number in the previous month (last day if missing). */
14
+ | 'previousMonth'
15
+ /** Shift+Page Down: same day and month in the next year (last day if missing). */
16
+ | 'nextYear'
17
+ /** Shift+Page Up: same day and month in the previous year (last day if missing). */
18
+ | 'previousYear'
19
+ /** Home: first day of the week row. */
20
+ | 'weekStart'
21
+ /** End: last day of the week row. */
22
+ | 'weekEnd'
23
+ /** Ctrl+Home: first day of the month. */
24
+ | 'monthStart'
25
+ /** Ctrl+End: last day of the month. */
26
+ | 'monthEnd';
27
+ export interface CalendarTargetOptions {
28
+ /** Date before which days are out of range. */
29
+ minDate?: Date;
30
+ /** Date after which days are out of range. */
31
+ maxDate?: Date;
32
+ /** First day of the week (0 = Sunday), for the week row moves. Default: Monday. */
33
+ weekStartDay?: number;
34
+ }
35
+ /**
36
+ * Get the target date of a keyboard move in the calendar grid. Day to year moves: `undefined` out of the range
37
+ * (APG: focus does not move). Week row and month edges: kept in the month, then snapped to the range.
38
+ */
39
+ export declare function getCalendarTargetDate(date: Date, move: CalendarMove, { minDate, maxDate, weekStartDay }?: CalendarTargetOptions): Date | undefined;
@@ -0,0 +1,7 @@
1
+ import { Locale } from '../locale/types';
2
+ /** Get first day of week for locale from the browser API */
3
+ export declare const getFromBrowser: (locale: Locale) => number | undefined;
4
+ /**
5
+ * Get first day of the week for the given locale code (language + region).
6
+ */
7
+ export declare const getFirstDayOfWeek: (locale: Locale) => number | undefined;
@@ -0,0 +1,17 @@
1
+ import { WeekDayInfo } from './getWeekDays';
2
+ import { Locale } from '../locale/types';
3
+ type AnnotatedDay = {
4
+ date: Date;
5
+ isOutOfRange?: boolean;
6
+ };
7
+ type AnnotatedWeek = Partial<Record<number, AnnotatedDay>>;
8
+ interface MonthCalendar {
9
+ weekDays: Array<WeekDayInfo>;
10
+ weeks: Array<AnnotatedWeek>;
11
+ }
12
+ /**
13
+ * Get month calendar.
14
+ * A list of weeks with days indexed by week day number.
15
+ */
16
+ export declare const getMonthCalendar: (locale: Locale, referenceDate?: Date, rangeMinDate?: Date, rangeMaxDate?: Date) => MonthCalendar;
17
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Locale } from '../locale/types';
2
+ export type WeekDayInfo = {
3
+ letter: string;
4
+ number: number;
5
+ long: string;
6
+ };
7
+ export declare const DAYS_PER_WEEK = 7;
8
+ /**
9
+ * List week days (based on locale) with the week day letter (ex: "M" for "Monday") and week day number
10
+ * (0-based index starting on Sunday).
11
+ */
12
+ export declare const getWeekDays: (locale: Locale) => Array<WeekDayInfo>;
@@ -0,0 +1 @@
1
+ export declare const getYearDisplayName: (locale: string) => string | undefined;
@@ -0,0 +1,18 @@
1
+ export interface ParseDateOptions {
2
+ /** Reference date for the current year and the two-digit year window. Default: now. */
3
+ today?: Date;
4
+ }
5
+ /**
6
+ * Parse a date typed in a date field, in the formats of the locale:
7
+ *
8
+ * 1. The long format with the locale month names (ex: `November 12, 2026`, `12 novembre 2026`, `12 nov. 2026`).
9
+ * 2. A numeric date in the field order of the locale (`fr-FR` day/month/year, `en-US` month/day/year). Any
10
+ * non-digit characters separate the fields (ex: `12/11/2026`, `12.11.26`, `12 11 2026`).
11
+ * 3. A two-digit year: the year nearest to today, 50 years back to 49 years forward (`85` → 1985, `26` → 2026).
12
+ * 4. A day and a month with no year: the current year.
13
+ *
14
+ * A single number, an impossible date (ex: `31/02/2026`) or any other text is not valid (`undefined`).
15
+ *
16
+ * @return The calendar date of the day (see `getCalendarDate`), or `undefined` when the text is not a valid date.
17
+ */
18
+ export declare function parseDate(text: string, locale: string, { today }?: ParseDateOptions): Date | undefined;
@@ -0,0 +1,9 @@
1
+ import { Locale } from './types';
2
+ /**
3
+ * Parse locale code
4
+ * @example
5
+ * parseLocale('EN') // => { code: 'en', language: 'en' }
6
+ * parseLocale('en_us') // => { code: 'en-US', language: 'en', region: 'US' }
7
+ * parseLocale('EN-US') // => { code: 'en-US', language: 'en', region: 'US' }
8
+ */
9
+ export declare function parseLocale(locale: string): Locale | undefined;
@@ -0,0 +1,8 @@
1
+ export interface Locale {
2
+ /** ISO locale code `lang-REGION` (ex: `en-US`) */
3
+ code: string;
4
+ /** ISO locale language code (ex: `en`) */
5
+ language: string;
6
+ /** ISO locale region code (ex: `US`) */
7
+ region?: string;
8
+ }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "dependencies": {
9
9
  "@floating-ui/dom": "^1.7.5",
10
- "@lumx/icons": "^4.28.1-alpha.0",
10
+ "@lumx/icons": "^4.29.0-next.1",
11
11
  "classnames": "^2.3.2",
12
12
  "focus-visible": "^5.0.2",
13
13
  "lodash": "4.18.1",
@@ -66,7 +66,7 @@
66
66
  "update-version-changelog": "yarn version-changelog ../../CHANGELOG.md"
67
67
  },
68
68
  "sideEffects": false,
69
- "version": "4.28.1-alpha.0",
69
+ "version": "4.29.0-next.1",
70
70
  "devDependencies": {
71
71
  "@rollup/plugin-typescript": "^12.3.0",
72
72
  "@testing-library/dom": "^10.4.1",
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Time zones of the date tests (offset on 2026-11-04): UTC, negative offsets, a positive offset, and a zone that
3
+ * changes its clocks at midnight (no `00:00 UTC` on 2026-03-29 local).
4
+ * `offset`: the `getTimezoneOffset()` minutes, positive west of UTC (ex: `300` in New York).
5
+ */
6
+ declare const TEST_TIME_ZONES: {
7
+ timeZone: string;
8
+ offset: number;
9
+ }[];
10
+ /**
11
+ * Run a test suite in each test time zone.
12
+ *
13
+ * Node applies a new `process.env.TZ` at once. The zone is set in a `beforeAll`, so make the dates in the tests
14
+ * (or in hooks), never in the `describe` body.
15
+ */
16
+ export declare function describeInTimeZones(name: string, suite: (zone: (typeof TEST_TIME_ZONES)[number]) => void): void;
17
+ export {};