@gridkitjs/forms-core 0.0.0-dev-20261206092422
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.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/index.d.ts +3517 -0
- package/dist/index.js +8377 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3517 @@
|
|
|
1
|
+
/** A segment of a date, time or date-time field. */
|
|
2
|
+
type DateSegmentType = "year" | "month" | "day" | "hour" | "minute" | "second" | "dayPeriod";
|
|
3
|
+
/** Any segment a field types in: a date's, or a period's quarter or fiscal period. */
|
|
4
|
+
type SegmentType = DateSegmentType | "quarter" | "period";
|
|
5
|
+
/** One segment of a layout. */
|
|
6
|
+
interface DateSegment {
|
|
7
|
+
readonly type: SegmentType;
|
|
8
|
+
/** The lowest and highest value it takes: month 1 to 12, hour 1 to 12 in a 12-hour cycle, 0 and 1 for the day period. */
|
|
9
|
+
readonly min: number;
|
|
10
|
+
readonly max: number;
|
|
11
|
+
/** Characters it is shown with once left: 2 for "03", 1 for "3", 4 for a year. */
|
|
12
|
+
readonly width: number;
|
|
13
|
+
/** Shown while empty: "mm", "dd", "yyyy", "--" (messages). */
|
|
14
|
+
readonly placeholder: string;
|
|
15
|
+
/** Read with the field's label: "month" (messages). */
|
|
16
|
+
readonly label: string;
|
|
17
|
+
}
|
|
18
|
+
/** One part of a layout: a segment (by its index in `segments`), or text drawn between them. */
|
|
19
|
+
type DateLayoutPart = {
|
|
20
|
+
readonly kind: "segment";
|
|
21
|
+
readonly index: number;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "literal";
|
|
24
|
+
readonly text: string;
|
|
25
|
+
};
|
|
26
|
+
/** How a field lays out its segments in a locale. */
|
|
27
|
+
interface DateLayout {
|
|
28
|
+
/** In the order `Intl.DateTimeFormat#formatToParts` gives them. */
|
|
29
|
+
readonly parts: readonly DateLayoutPart[];
|
|
30
|
+
/** The segments alone, in typing order. */
|
|
31
|
+
readonly segments: readonly DateSegment[];
|
|
32
|
+
readonly hourCycle: "h11" | "h12" | "h23" | "h24" | null;
|
|
33
|
+
/** The locale's two day-period texts, morning first ("AM", "PM"). */
|
|
34
|
+
readonly dayPeriods: readonly [string, string];
|
|
35
|
+
/** The ten digits the locale writes, "0" to "9" first. */
|
|
36
|
+
readonly digits: string;
|
|
37
|
+
}
|
|
38
|
+
/** What a field's layout is made for. */
|
|
39
|
+
type DateLayoutFields = "date" | "time" | "dateTime" | "month" | "year";
|
|
40
|
+
interface DateLayoutOptions {
|
|
41
|
+
readonly locale: Intl.LocalesArgument;
|
|
42
|
+
readonly fields: DateLayoutFields;
|
|
43
|
+
/** The locale's hour cycle unless given. */
|
|
44
|
+
readonly hourCycle?: "h12" | "h23" | undefined;
|
|
45
|
+
/** `"minute"` by default; `"second"` adds a seconds segment. */
|
|
46
|
+
readonly precision?: "minute" | "second" | undefined;
|
|
47
|
+
/** The digits segments show; the locale's by default. */
|
|
48
|
+
readonly numberingSystem?: string | undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* How a field lays out its segments in a locale, read from
|
|
52
|
+
* `Intl.DateTimeFormat#formatToParts` for a sample moment (14 March 2026,
|
|
53
|
+
* 15:05:09): each year, month, day, hour, minute, second or day-period
|
|
54
|
+
* part becomes a segment, each literal the text drawn between them, in
|
|
55
|
+
* the order the engine gives. Whether a segment pads is read from a second
|
|
56
|
+
* sample with one-digit values, so `en-US` hours stay unpadded ("3:05 PM").
|
|
57
|
+
* Nothing is written per locale: each engine shows its own. Gregorian
|
|
58
|
+
* only. Cached per locale, options and messages.
|
|
59
|
+
*/
|
|
60
|
+
declare function dateLayout(options: DateLayoutOptions, messages: FormsMessages): DateLayout;
|
|
61
|
+
/**
|
|
62
|
+
* Segment `index` written for `value`: digits in the layout's digits,
|
|
63
|
+
* padded to the segment's width; a day period's text for 0 or 1.
|
|
64
|
+
*/
|
|
65
|
+
declare function writeSegment(layout: DateLayout, index: number, value: number): string;
|
|
66
|
+
/** The number segment `index`'s text holds, digits in any script; `null` while empty or for text that is not its value. */
|
|
67
|
+
declare function segmentValue(layout: DateLayout, index: number, text: string): number | null;
|
|
68
|
+
/**
|
|
69
|
+
* The field's text for these segment texts: joined by the layout's
|
|
70
|
+
* literals, an empty segment written as nothing ("03//2026"), and `""`
|
|
71
|
+
* when every segment is empty.
|
|
72
|
+
*/
|
|
73
|
+
declare function joinSegments(layout: DateLayout, texts: readonly string[]): string;
|
|
74
|
+
/**
|
|
75
|
+
* Each segment's text in the field's text, or `null` for text that is
|
|
76
|
+
* not segments (free text: a shortcut, a pasted date in another form).
|
|
77
|
+
* `""` is every segment empty.
|
|
78
|
+
*/
|
|
79
|
+
declare function splitSegments(layout: DateLayout, text: string): readonly string[] | null;
|
|
80
|
+
/** Where each segment's text sits in the field's text, as `[start, end)`; `null` for text that is not segments. */
|
|
81
|
+
declare function segmentSpans(layout: DateLayout, text: string): readonly (readonly [number, number])[] | null;
|
|
82
|
+
/** A stretch of a layout's parts drawn together. */
|
|
83
|
+
interface SegmentRun {
|
|
84
|
+
/** Indexes into the layout's `parts`, in order. */
|
|
85
|
+
readonly parts: readonly number[];
|
|
86
|
+
/** Whether the renderer wraps it in `dir="ltr"`: a run of several number segments in a right-to-left field. */
|
|
87
|
+
readonly leftToRight: boolean;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The layout's parts grouped into runs for a field written in
|
|
91
|
+
* `direction`. A right-to-left field cannot simply reverse its segments:
|
|
92
|
+
* `he-IL` and `fa-IR` write a date left to right even in right-to-left
|
|
93
|
+
* text (digits and `.` or `/` form one number run under the Unicode bidi
|
|
94
|
+
* rules), while `ar-EG` leads each `/` with a right-to-left mark, so its
|
|
95
|
+
* date runs right to left. So consecutive number segments joined by
|
|
96
|
+
* literals with no right-to-left character or mark form one run, read
|
|
97
|
+
* left to right; a literal with one, or a right-to-left day period,
|
|
98
|
+
* breaks it. Every other part is a run of its own. A left-to-right field
|
|
99
|
+
* is one run.
|
|
100
|
+
*/
|
|
101
|
+
declare function segmentRuns(layout: DateLayout, direction: "ltr" | "rtl"): readonly SegmentRun[];
|
|
102
|
+
|
|
103
|
+
/** No per-type flags. */
|
|
104
|
+
type NoFlags = Record<never, never>;
|
|
105
|
+
/**
|
|
106
|
+
* A stretch of values of one type. Either end may be `null` (open). `F` is
|
|
107
|
+
* the type's own flags, carried in the value beside the ends (a time range
|
|
108
|
+
* over midnight carries `overnight`); a flag is never named `start`,
|
|
109
|
+
* `end` or `rule` (which marks a `RelativeRange`).
|
|
110
|
+
* A range with both ends open is no range: an input holding one holds
|
|
111
|
+
* `null`.
|
|
112
|
+
*/
|
|
113
|
+
type Range<T, F extends object = NoFlags> = {
|
|
114
|
+
readonly start: T | null;
|
|
115
|
+
readonly end: T | null;
|
|
116
|
+
} & Readonly<F>;
|
|
117
|
+
/**
|
|
118
|
+
* Whether `end` belongs to the range: `"[)"`, half-open (`end` is the first
|
|
119
|
+
* value after it, as a date range stores the day after its last day), or
|
|
120
|
+
* `"[]"`, closed.
|
|
121
|
+
*/
|
|
122
|
+
type RangeBounds = "[)" | "[]";
|
|
123
|
+
/** One end of a range. */
|
|
124
|
+
type RangeEnd = "start" | "end";
|
|
125
|
+
/** A range kept as a rule ("the last 7 days"), resolved to ends on demand. */
|
|
126
|
+
interface RelativeRange<R> {
|
|
127
|
+
readonly kind: "relative";
|
|
128
|
+
readonly rule: R;
|
|
129
|
+
}
|
|
130
|
+
/** What a range input holds: fixed ends, or (for a type with rules) a rule. */
|
|
131
|
+
type RangeValue<T, F extends object = NoFlags, R = never> = [R] extends [
|
|
132
|
+
never
|
|
133
|
+
] ? Range<T, F> : Range<T, F> | RelativeRange<R>;
|
|
134
|
+
/** How two present ends stand: in order, with the flags that makes, or reversed. */
|
|
135
|
+
type RangeOrientation<F extends object> = {
|
|
136
|
+
readonly kind: "ordered";
|
|
137
|
+
readonly flags: F;
|
|
138
|
+
} | {
|
|
139
|
+
readonly kind: "reversed";
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Everything the range model needs to know about one value type, which the
|
|
143
|
+
* type supplies. `S` is its span (a number for numbers, a duration for
|
|
144
|
+
* dates); `C` the context its functions need (a time zone, whether
|
|
145
|
+
* `overnight` is allowed); `R` its relative rule, `never` when it has none.
|
|
146
|
+
* The model orders, checks and measures only through these functions.
|
|
147
|
+
*/
|
|
148
|
+
interface RangeKind<T, F extends object = NoFlags, S = number, C = undefined, R = never> {
|
|
149
|
+
/** Negative when `a` comes before `b`, 0 when they are one, positive after. */
|
|
150
|
+
readonly compare: (a: T, b: T) => number;
|
|
151
|
+
/** How `end` stands to `start`: a time range may call an earlier end "ordered, overnight". */
|
|
152
|
+
readonly orient: (start: T, end: T, context: C) => RangeOrientation<F>;
|
|
153
|
+
/** The flags of a range with an open end. */
|
|
154
|
+
readonly openFlags: F;
|
|
155
|
+
/** The length from `start` to `end`, both present, as stored. */
|
|
156
|
+
readonly span: (start: T, end: T, flags: F, context: C) => S;
|
|
157
|
+
readonly compareSpans: (a: S, b: S) => number;
|
|
158
|
+
/**
|
|
159
|
+
* The stored end of a half-open range for an end shown inclusive (a date:
|
|
160
|
+
* the next day). Without it, the end shown is the end stored.
|
|
161
|
+
*/
|
|
162
|
+
readonly toStoredEnd?: ((shown: T, context: C) => T) | undefined;
|
|
163
|
+
/** The end shown inclusive for a half-open range's stored end; the inverse of `toStoredEnd`. */
|
|
164
|
+
readonly toShownEnd?: ((stored: T, context: C) => T) | undefined;
|
|
165
|
+
/** The ends a rule stands for, now. Required when `R` is not `never`. */
|
|
166
|
+
readonly resolve?: ((rule: R, context: C) => Range<T, F>) | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* Whether two rules are one. Without it, rules are compared as plain
|
|
169
|
+
* data: the same keys holding the same values, deeply.
|
|
170
|
+
*/
|
|
171
|
+
readonly sameRule?: ((a: R, b: R) => boolean) | undefined;
|
|
172
|
+
}
|
|
173
|
+
/** How a range input reads two ends. */
|
|
174
|
+
interface RangeOptions<S> {
|
|
175
|
+
/** `"[)"` by default: whether the stored `end` belongs to the range. */
|
|
176
|
+
readonly bounds?: RangeBounds | undefined;
|
|
177
|
+
/** What an end before its start does: swapped (default) or an error. */
|
|
178
|
+
readonly reversed?: "swap" | "error" | undefined;
|
|
179
|
+
/** Whether a start equal to its end is allowed when that holds nothing (half-open). */
|
|
180
|
+
readonly allowEmpty?: boolean | undefined;
|
|
181
|
+
readonly minSpan?: S | undefined;
|
|
182
|
+
readonly maxSpan?: S | undefined;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Two ends as typed, made into a range: no range (both open), an ordered
|
|
186
|
+
* range (`swapped` when the ends changed places), or refused with why.
|
|
187
|
+
*/
|
|
188
|
+
type RangeReading<T, F extends object> = {
|
|
189
|
+
readonly kind: "none";
|
|
190
|
+
} | {
|
|
191
|
+
readonly kind: "range";
|
|
192
|
+
readonly range: Range<T, F>;
|
|
193
|
+
readonly swapped: boolean;
|
|
194
|
+
} | {
|
|
195
|
+
readonly kind: "unreadable";
|
|
196
|
+
readonly reason: "reversed" | "empty";
|
|
197
|
+
};
|
|
198
|
+
/** `range`'s own flags, without its ends. */
|
|
199
|
+
declare function rangeFlags<T, F extends object>(range: Range<T, F>): F;
|
|
200
|
+
/**
|
|
201
|
+
* Makes two ends as shown into the stored range. Both open is no range; one
|
|
202
|
+
* open end keeps the kind's `openFlags`. Two present ends are oriented by
|
|
203
|
+
* the kind: reversed ends are swapped (the default) or refused with
|
|
204
|
+
* `"reversed"`. The end is then stored through `toStoredEnd` for a
|
|
205
|
+
* half-open range, and a half-open range whose start is its stored end
|
|
206
|
+
* holds nothing, so it is refused with `"empty"` unless `allowEmpty`.
|
|
207
|
+
*/
|
|
208
|
+
declare function orderRange<T, F extends object, S, C, R>(kind: RangeKind<T, F, S, C, R>, start: T | null, end: T | null, options: RangeOptions<S>, context: C): RangeReading<T, F>;
|
|
209
|
+
/** The end a stored range shows: the kind's `toShownEnd` for a half-open one. */
|
|
210
|
+
declare function shownEnd<T, F extends object, S, C, R>(kind: RangeKind<T, F, S, C, R>, range: Range<T, F>, bounds: RangeBounds, context: C): T | null;
|
|
211
|
+
/** From `range`'s start to its stored end, by the kind; `null` while an end is open. */
|
|
212
|
+
declare function rangeSpan<T, F extends object, S, C, R>(kind: RangeKind<T, F, S, C, R>, range: Range<T, F>, context: C): S | null;
|
|
213
|
+
/**
|
|
214
|
+
* Whether `value` lies in `range`. An open end reaches as far as values go.
|
|
215
|
+
* A range whose stored end comes before its start (a time range over
|
|
216
|
+
* midnight) wraps: it holds what comes from its start on, and what comes
|
|
217
|
+
* before its end.
|
|
218
|
+
*/
|
|
219
|
+
declare function rangeIncludes<T, F extends object, S, C, R>(kind: RangeKind<T, F, S, C, R>, range: Range<T, F>, value: T, bounds: RangeBounds): boolean;
|
|
220
|
+
/** Whether `value` is a rule rather than fixed ends. */
|
|
221
|
+
declare function isRelativeRange<T, F extends object, R>(value: Range<T, F> | RelativeRange<R>): value is RelativeRange<R>;
|
|
222
|
+
/**
|
|
223
|
+
* The ends `value` stands for now: itself, or its rule resolved by the
|
|
224
|
+
* kind. Throws a `TypeError` for a rule when the kind has no `resolve`.
|
|
225
|
+
*/
|
|
226
|
+
declare function resolveRange<T, F extends object, S, C, R>(kind: RangeKind<T, F, S, C, R>, value: RangeValue<T, F, R>, context: C): Range<T, F>;
|
|
227
|
+
/**
|
|
228
|
+
* Whether two ranges are one: the same ends by the kind's `compare`, and
|
|
229
|
+
* the same flags; or two rules the kind's `sameRule` calls one (equal plain
|
|
230
|
+
* data without it), so a rule written inline, a new object each render,
|
|
231
|
+
* is still the value held.
|
|
232
|
+
*/
|
|
233
|
+
declare function sameRange<T, F extends object, S, C, R>(kind: RangeKind<T, F, S, C, R>, a: RangeValue<T, F, R>, b: RangeValue<T, F, R>): boolean;
|
|
234
|
+
|
|
235
|
+
/** A calendar day, no time, no zone: "2026-03-14". */
|
|
236
|
+
type PlainDate = `${number}-${number}-${number}`;
|
|
237
|
+
/** A time of day, no date, no zone: "15:05", "15:05:09", "15:05:09.250". */
|
|
238
|
+
type PlainTime = `${number}:${number}` | `${number}:${number}:${number}`;
|
|
239
|
+
/** A wall-clock date and time, no zone: "2026-03-14T15:05". */
|
|
240
|
+
type PlainDateTime = `${PlainDate}T${PlainTime}`;
|
|
241
|
+
/** An exact moment, always written in UTC: "2026-03-14T14:05:00.000Z". */
|
|
242
|
+
type Instant = `${PlainDate}T${PlainTime}Z`;
|
|
243
|
+
/** ISO weekday: 1 is Monday, 7 Sunday, as `Intl.Locale#getWeekInfo` numbers them. */
|
|
244
|
+
type Weekday = 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
245
|
+
/** A day's fields: month 1 to 12, day 1 to 31. */
|
|
246
|
+
interface DateParts {
|
|
247
|
+
readonly year: number;
|
|
248
|
+
readonly month: number;
|
|
249
|
+
readonly day: number;
|
|
250
|
+
}
|
|
251
|
+
/** A time's fields: hour 0 to 23. */
|
|
252
|
+
interface TimeParts {
|
|
253
|
+
readonly hour: number;
|
|
254
|
+
readonly minute: number;
|
|
255
|
+
readonly second: number;
|
|
256
|
+
readonly millisecond: number;
|
|
257
|
+
}
|
|
258
|
+
/** Whether `year` has a 29 February in the proleptic Gregorian calendar. */
|
|
259
|
+
declare function isLeapYear(year: number): boolean;
|
|
260
|
+
/** The days in `month` of `year`: 28 to 31. A month outside 1 to 12 counts on into the years either side. */
|
|
261
|
+
declare function daysInMonth(year: number, month: number): number;
|
|
262
|
+
/** The day `year-month-day`. Throws a `RangeError` for a day that does not exist or a year outside 1 to 9999. */
|
|
263
|
+
declare function plainDate(year: number, month: number, day: number): PlainDate;
|
|
264
|
+
/**
|
|
265
|
+
* The time `hour:minute`, with seconds when they or the milliseconds are
|
|
266
|
+
* set, and milliseconds when set: "15:05", "15:05:09", "15:05:09.250".
|
|
267
|
+
* Throws a `RangeError` for a time that does not exist (24:00 included).
|
|
268
|
+
*/
|
|
269
|
+
declare function plainTime(hour: number, minute: number, second?: number, millisecond?: number): PlainTime;
|
|
270
|
+
/** `date` at `time`. */
|
|
271
|
+
declare function plainDateTime(date: PlainDate, time: PlainTime): PlainDateTime;
|
|
272
|
+
/** `text` as a day when it is one in ISO form ("2026-03-14"); `null` otherwise. */
|
|
273
|
+
declare function toPlainDate(text: string): PlainDate | null;
|
|
274
|
+
/**
|
|
275
|
+
* `text` as a time of day when it is one in ISO form, in its shortest
|
|
276
|
+
* form ("15:05:00" is "15:05"; digits past milliseconds are dropped);
|
|
277
|
+
* `null` otherwise.
|
|
278
|
+
*/
|
|
279
|
+
declare function toPlainTime(text: string): PlainTime | null;
|
|
280
|
+
/** `text` as a wall clock when it is one in ISO form ("2026-03-14T15:05"), its time shortest; `null` otherwise. */
|
|
281
|
+
declare function toPlainDateTime(text: string): PlainDateTime | null;
|
|
282
|
+
/**
|
|
283
|
+
* `text` as an exact moment when it is an ISO date and time with `Z` or
|
|
284
|
+
* an offset (`+01:00`), written as `Date#toISOString` writes it; `null`
|
|
285
|
+
* otherwise.
|
|
286
|
+
*/
|
|
287
|
+
declare function toInstant(text: string): Instant | null;
|
|
288
|
+
/** Whether `value` is a day in canonical form. */
|
|
289
|
+
declare function isPlainDate(value: unknown): value is PlainDate;
|
|
290
|
+
/** Whether `value` is a time of day in canonical (shortest) form. */
|
|
291
|
+
declare function isPlainTime(value: unknown): value is PlainTime;
|
|
292
|
+
/** Whether `value` is a wall clock in canonical form. */
|
|
293
|
+
declare function isPlainDateTime(value: unknown): value is PlainDateTime;
|
|
294
|
+
/** Whether `value` is an exact moment in canonical form. */
|
|
295
|
+
declare function isInstant(value: unknown): value is Instant;
|
|
296
|
+
/** A day's fields. Throws a `RangeError` for text that is not a day. */
|
|
297
|
+
declare function dateParts(date: PlainDate): DateParts;
|
|
298
|
+
/** A time's fields. Throws a `RangeError` for text that is not a time of day. */
|
|
299
|
+
declare function timeParts(time: PlainTime): TimeParts;
|
|
300
|
+
/** A wall clock's day and time. */
|
|
301
|
+
declare function splitDateTime(dateTime: PlainDateTime): {
|
|
302
|
+
readonly date: PlainDate;
|
|
303
|
+
readonly time: PlainTime;
|
|
304
|
+
};
|
|
305
|
+
/** `days` days after `date` (before, when negative). */
|
|
306
|
+
declare function addDays(date: PlainDate, days: number): PlainDate;
|
|
307
|
+
/** `months` months after `date`, the day clamped to the month's length: 31 January plus a month is the last day of February. */
|
|
308
|
+
declare function addMonths(date: PlainDate, months: number): PlainDate;
|
|
309
|
+
/** `years` years after `date`; 29 February becomes 28 February in a year that has none. */
|
|
310
|
+
declare function addYears(date: PlainDate, years: number): PlainDate;
|
|
311
|
+
/** Days from `start` to `end`: negative when `end` comes first. */
|
|
312
|
+
declare function daysBetween(start: PlainDate, end: PlainDate): number;
|
|
313
|
+
/** The ISO weekday of `date`: 1 for Monday to 7 for Sunday. */
|
|
314
|
+
declare function dayOfWeek(date: PlainDate): Weekday;
|
|
315
|
+
/** The first day of `date`'s month. */
|
|
316
|
+
declare function startOfMonth(date: PlainDate): PlainDate;
|
|
317
|
+
/** The last day of `date`'s month. */
|
|
318
|
+
declare function endOfMonth(date: PlainDate): PlainDate;
|
|
319
|
+
/** Negative when `a` comes first, 0 for the same day, positive after. */
|
|
320
|
+
declare function compareDates(a: PlainDate, b: PlainDate): number;
|
|
321
|
+
/** Minutes into the day, seconds as a fraction: "01:30" is 90. */
|
|
322
|
+
declare function minutesOfDay(time: PlainTime): number;
|
|
323
|
+
/** Negative when `a` comes first in the day, 0 for the same time, positive after. */
|
|
324
|
+
declare function compareTimes(a: PlainTime, b: PlainTime): number;
|
|
325
|
+
/** Negative when `a` comes first, 0 for the same wall clock, positive after. */
|
|
326
|
+
declare function compareDateTimes(a: PlainDateTime, b: PlainDateTime): number;
|
|
327
|
+
/** Negative when `a` comes first, 0 for the same moment, positive after. */
|
|
328
|
+
declare function compareInstants(a: Instant, b: Instant): number;
|
|
329
|
+
/**
|
|
330
|
+
* `date` as a `Date` at local midnight, as the grid reads a `yyyy-mm-dd`
|
|
331
|
+
* cell, where `new Date("2026-03-01")` would be midnight in UTC: the day
|
|
332
|
+
* before west of UTC.
|
|
333
|
+
*/
|
|
334
|
+
declare function dateFromPlainDate(date: PlainDate): Date;
|
|
335
|
+
/** `dateTime` as a `Date` at that local wall clock. */
|
|
336
|
+
declare function dateFromPlainDateTime(dateTime: PlainDateTime): Date;
|
|
337
|
+
/** The local day of a `Date`, as the grid writes a date cell. */
|
|
338
|
+
declare function plainDateFromDate(date: Date): PlainDate;
|
|
339
|
+
/** `instant` as a `Date`: exact. */
|
|
340
|
+
declare function dateFromInstant(instant: Instant): Date;
|
|
341
|
+
/** A `Date` as an exact moment. */
|
|
342
|
+
declare function instantFromDate(date: Date): Instant;
|
|
343
|
+
|
|
344
|
+
/** A unit of the calendar a rule counts in. */
|
|
345
|
+
type CalendarUnit = "day" | "week" | "month" | "quarter" | "year";
|
|
346
|
+
/**
|
|
347
|
+
* A date range kept as a rule, resolved against today in a zone whenever
|
|
348
|
+
* it is shown or read. Plain data: it serializes as JSON, so a saved
|
|
349
|
+
* filter still means "the last 7 days" next month.
|
|
350
|
+
*/
|
|
351
|
+
type RelativeDateRule = {
|
|
352
|
+
/** The unit `offset` units from the one today is in: this month (0), last month (-1). */
|
|
353
|
+
readonly kind: "period";
|
|
354
|
+
readonly unit: CalendarUnit;
|
|
355
|
+
readonly offset: number;
|
|
356
|
+
/** Quarters and years counted from the fiscal year's start. */
|
|
357
|
+
readonly fiscal?: boolean | undefined;
|
|
358
|
+
} | {
|
|
359
|
+
/** The `count` units up to today (`includeToday`) or up to yesterday; "next" looks ahead from tomorrow, or from today. */
|
|
360
|
+
readonly kind: "last" | "next";
|
|
361
|
+
readonly unit: "day" | "week" | "month" | "year";
|
|
362
|
+
readonly count: number;
|
|
363
|
+
readonly includeToday: boolean;
|
|
364
|
+
} | {
|
|
365
|
+
/** From the start of the unit today is in, through today. */
|
|
366
|
+
readonly kind: "toDate";
|
|
367
|
+
readonly unit: "week" | "month" | "quarter" | "year";
|
|
368
|
+
readonly fiscal?: boolean | undefined;
|
|
369
|
+
};
|
|
370
|
+
/** What a rule is resolved against. */
|
|
371
|
+
interface DateRuleContext {
|
|
372
|
+
/** Today in the input's zone. */
|
|
373
|
+
readonly today: () => PlainDate;
|
|
374
|
+
readonly firstDayOfWeek: Weekday;
|
|
375
|
+
/** The month the fiscal year starts in, 1 to 12. */
|
|
376
|
+
readonly fiscalYearStart: number;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* The days a rule stands for at `context.today()`, half-open:
|
|
380
|
+
*
|
|
381
|
+
* - `period`: the unit `offset` units from the one today is in (a week by
|
|
382
|
+
* `firstDayOfWeek`; a quarter or year from `fiscalYearStart` when
|
|
383
|
+
* `fiscal`).
|
|
384
|
+
* - `last`: the `count` units up to tomorrow with `includeToday`, else up
|
|
385
|
+
* to today; `next`: the `count` units from tomorrow, or from today with
|
|
386
|
+
* `includeToday`. Months clamp to the month's length.
|
|
387
|
+
* - `toDate`: from the start of the unit today is in through today.
|
|
388
|
+
*/
|
|
389
|
+
declare function resolveDateRule(rule: RelativeDateRule, context: DateRuleContext): Range<PlainDate>;
|
|
390
|
+
/** Whether two rules stand for the same days, compared by value; `fiscal` absent is false. */
|
|
391
|
+
declare function sameRule(a: RelativeDateRule, b: RelativeDateRule): boolean;
|
|
392
|
+
/**
|
|
393
|
+
* Whether `value` is a rule, as read back from JSON: the right kind, a
|
|
394
|
+
* unit that kind takes, whole numbers, `count` not negative. For checking
|
|
395
|
+
* a stored filter before using it.
|
|
396
|
+
*/
|
|
397
|
+
declare function isRelativeDateRule(value: unknown): value is RelativeDateRule;
|
|
398
|
+
/** A preset: a rule (kept as the rule) or fixed ends; a rule's label comes from the messages when absent. */
|
|
399
|
+
interface DatePreset<V> {
|
|
400
|
+
readonly id: string;
|
|
401
|
+
readonly label?: string | undefined;
|
|
402
|
+
readonly value: V;
|
|
403
|
+
}
|
|
404
|
+
/** A preset that stores `rule` as the value, named by `label` or `messages.relativeRangeLabel`. */
|
|
405
|
+
declare function relativePreset(id: string, rule: RelativeDateRule, label?: string): DatePreset<RelativeRange<RelativeDateRule>>;
|
|
406
|
+
/**
|
|
407
|
+
* The presets most date range inputs want, each a rule: today, yesterday,
|
|
408
|
+
* this week, the last 7 days (today included), this month, last month,
|
|
409
|
+
* this quarter and year to date. A range input shows none unless it is
|
|
410
|
+
* given a list.
|
|
411
|
+
*/
|
|
412
|
+
declare const commonDatePresets: readonly DatePreset<RelativeRange<RelativeDateRule>>[];
|
|
413
|
+
/** What a preset is called: its own label, a rule's from the messages, else its id. */
|
|
414
|
+
declare function datePresetLabel<V>(preset: DatePreset<V>, messages: FormsMessages): string;
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* How serious a field's message is. Only `"error"` blocks a commit or a
|
|
418
|
+
* submit; the others are shown and never stop the user. Growable: a later
|
|
419
|
+
* release may add a severity.
|
|
420
|
+
*/
|
|
421
|
+
type Severity = "error" | "warning" | "info" | "success";
|
|
422
|
+
/**
|
|
423
|
+
* The most serious of `severities`, or `null` when there are none. A field
|
|
424
|
+
* showing several messages takes the state of the most serious one.
|
|
425
|
+
*/
|
|
426
|
+
declare function mostSevere(severities: Iterable<Severity>): Severity | null;
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Every string the forms show or announce of their own: validation
|
|
430
|
+
* messages, button names, counters, display-mode text and the message
|
|
431
|
+
* summary, so the forms can speak a language other than English. A message
|
|
432
|
+
* that names something takes a function, so a translation can put it where
|
|
433
|
+
* its own grammar wants it. Counts print in the locale's digits: "1,000"
|
|
434
|
+
* under `"en"`, "1.000" under `"de-DE"`.
|
|
435
|
+
*
|
|
436
|
+
* A minor release may add keys. `resolveFormsMessages` lays a partial set
|
|
437
|
+
* over the defaults, so a translation without a new key shows its English
|
|
438
|
+
* default until it gains one.
|
|
439
|
+
*/
|
|
440
|
+
interface FormsMessages {
|
|
441
|
+
/** A required field is empty. */
|
|
442
|
+
required: string;
|
|
443
|
+
/** A required checkbox is not checked. */
|
|
444
|
+
requiredChecked: string;
|
|
445
|
+
/** A required switch is off. */
|
|
446
|
+
requiredOn: string;
|
|
447
|
+
/** The text is shorter than `minLength`. */
|
|
448
|
+
tooShort: (min: number) => string;
|
|
449
|
+
/** The text is longer than `maxLength`. */
|
|
450
|
+
tooLong: (max: number) => string;
|
|
451
|
+
/** The text does not match `pattern`. */
|
|
452
|
+
patternMismatch: string;
|
|
453
|
+
/** A custom parser's fallback when the text cannot be read. */
|
|
454
|
+
unreadable: string;
|
|
455
|
+
/** A number field's text is not a number. */
|
|
456
|
+
notANumber: string;
|
|
457
|
+
/** A number field's text groups digits where the field does not; names its separators. */
|
|
458
|
+
numberGrouping: (decimal: string, group: string) => string;
|
|
459
|
+
/** A number field holding JS numbers was given more digits than one keeps exactly. */
|
|
460
|
+
numberTooPrecise: string;
|
|
461
|
+
/** A number is below `min`, written as the field writes numbers. */
|
|
462
|
+
rangeUnderflow: (min: string) => string;
|
|
463
|
+
/** A number is above `max`, written as the field writes numbers. */
|
|
464
|
+
rangeOverflow: (max: string) => string;
|
|
465
|
+
/** A number is off its step, written as the field writes numbers. */
|
|
466
|
+
stepMismatch: (step: string) => string;
|
|
467
|
+
/** A date or time is before `min`, written as display mode writes it. */
|
|
468
|
+
tooEarly: (limit: string) => string;
|
|
469
|
+
/** A date or time is after `max`, written as display mode writes it. */
|
|
470
|
+
tooLate: (limit: string) => string;
|
|
471
|
+
/** A day `isDateDisabled` marks unavailable. */
|
|
472
|
+
dateUnavailable: string;
|
|
473
|
+
/** A date's segments are partly filled. */
|
|
474
|
+
dateIncomplete: string;
|
|
475
|
+
/** A time's segments are partly filled, or a 12-hour time has no AM or PM. */
|
|
476
|
+
timeIncomplete: string;
|
|
477
|
+
/** A date's month has no such day: 31 February. */
|
|
478
|
+
dateNonexistent: string;
|
|
479
|
+
/** Text that is not a date; `example` is today as the field writes it. */
|
|
480
|
+
dateUnreadable: (example: string) => string;
|
|
481
|
+
/** Text that is not a time; `example` is a time as the field writes it. */
|
|
482
|
+
timeUnreadable: (example: string) => string;
|
|
483
|
+
/** A year typed with three digits. */
|
|
484
|
+
dateYearDigits: string;
|
|
485
|
+
/** A wall clock in an hour the clocks skipped, read as the hour after: `typed` and `read` as the field writes times. */
|
|
486
|
+
timeSkipped: (typed: string, read: string) => string;
|
|
487
|
+
/** A wall clock in an hour that happens twice, read with `offset` ("GMT+02:00"). */
|
|
488
|
+
timeRepeated: (time: string, offset: string) => string;
|
|
489
|
+
/** A wall clock in an hour the clocks skipped, refused. */
|
|
490
|
+
timeNonexistent: (typed: string) => string;
|
|
491
|
+
/** A wall clock in an hour that happens twice, refused. */
|
|
492
|
+
timeAmbiguous: (typed: string) => string;
|
|
493
|
+
/** A segment's name, read with the field's label: "month". */
|
|
494
|
+
dateSegmentName: (type: SegmentType) => string;
|
|
495
|
+
/** What an empty segment shows: "mm". */
|
|
496
|
+
dateSegmentPlaceholder: (type: SegmentType) => string;
|
|
497
|
+
/** An empty segment's value, as a screen reader reads it. */
|
|
498
|
+
segmentEmpty: string;
|
|
499
|
+
/** The button that opens a date input's calendar, and the calendar popup itself. */
|
|
500
|
+
chooseDate: string;
|
|
501
|
+
/** The button that opens a time input's time columns, and their popup. */
|
|
502
|
+
chooseTime: string;
|
|
503
|
+
/** The button that opens a date-time input's calendar and time columns, and their popup. */
|
|
504
|
+
chooseDateTime: string;
|
|
505
|
+
/** A time picker's button that chooses the time it is now. */
|
|
506
|
+
pickerNow: string;
|
|
507
|
+
/** A date-time picker's button that closes it. */
|
|
508
|
+
pickerDone: string;
|
|
509
|
+
/** The button that opens a period input's picker, and the picker popup itself. */
|
|
510
|
+
choosePeriod: string;
|
|
511
|
+
/** A period picker's button to the year before. */
|
|
512
|
+
previousYear: string;
|
|
513
|
+
/** A period picker's button to the year after. */
|
|
514
|
+
nextYear: string;
|
|
515
|
+
/** A year picker's button to the twelve years before. */
|
|
516
|
+
previousYears: string;
|
|
517
|
+
/** A year picker's button to the twelve years after. */
|
|
518
|
+
nextYears: string;
|
|
519
|
+
/** A calendar's button to the month before. */
|
|
520
|
+
previousMonth: string;
|
|
521
|
+
/** A calendar's button to the month after. */
|
|
522
|
+
nextMonth: string;
|
|
523
|
+
/** A calendar's view of months and years, which its title opens. */
|
|
524
|
+
chooseMonthYear: string;
|
|
525
|
+
/** The list of years in a calendar's month and year view. */
|
|
526
|
+
calendarYears: string;
|
|
527
|
+
/** The heading of a calendar's column of week numbers, as a screen reader reads it. */
|
|
528
|
+
weekColumn: string;
|
|
529
|
+
/** A week number in a calendar, as a screen reader reads it. */
|
|
530
|
+
weekLabel: (week: number) => string;
|
|
531
|
+
/** Read after the first day of a range in a calendar. */
|
|
532
|
+
calendarRangeStart: string;
|
|
533
|
+
/** Read after the last day of a range in a calendar. */
|
|
534
|
+
calendarRangeEnd: string;
|
|
535
|
+
/** A relative rule's name, for a preset or a rule held as the value: "Last 7 days", "This month". */
|
|
536
|
+
relativeRangeLabel: (rule: RelativeDateRule) => string;
|
|
537
|
+
/** Written after a time range's end on the day after its start: "22:00 – 06:00 +1". */
|
|
538
|
+
rangeNextDay: string;
|
|
539
|
+
/** Written before a quarter: "Q3 2026". */
|
|
540
|
+
periodQuarterPrefix: string;
|
|
541
|
+
/** Written before a fiscal year: "FY2026". */
|
|
542
|
+
fiscalYearPrefix: string;
|
|
543
|
+
/** Written before a fiscal period: "FY2026 P04". */
|
|
544
|
+
fiscalPeriodPrefix: string;
|
|
545
|
+
/** Text that is not a period; `example` is the current period as the field writes it. */
|
|
546
|
+
periodUnreadable: (example: string) => string;
|
|
547
|
+
/** Text that is not a duration; `example` is 90 minutes as the field writes them. */
|
|
548
|
+
durationUnreadable: (example: string) => string;
|
|
549
|
+
/** A negative duration where the field takes none. */
|
|
550
|
+
durationNegative: string;
|
|
551
|
+
/** A commit refused without a message, or a check that failed. */
|
|
552
|
+
checkFailed: string;
|
|
553
|
+
/** The clear button's accessible name. */
|
|
554
|
+
clear: string;
|
|
555
|
+
/** The password reveal button's accessible name. */
|
|
556
|
+
showPassword: string;
|
|
557
|
+
/** A number input's stepper button that steps up. */
|
|
558
|
+
increase: string;
|
|
559
|
+
/** A number input's stepper button that steps down. */
|
|
560
|
+
decrease: string;
|
|
561
|
+
/** A range input's first end, read with the field's label. */
|
|
562
|
+
rangeStart: string;
|
|
563
|
+
/** A range input's second end, read with the field's label. */
|
|
564
|
+
rangeEnd: string;
|
|
565
|
+
/** Drawn between a range input's two ends. */
|
|
566
|
+
rangeSeparator: string;
|
|
567
|
+
/** A range with only a start, in display mode; `start` as the input writes it. */
|
|
568
|
+
rangeFrom: (start: string) => string;
|
|
569
|
+
/** A range with only an end, in display mode; `end` as the input writes it. */
|
|
570
|
+
rangeUpTo: (end: string) => string;
|
|
571
|
+
/** A range's end comes before its start, and the input does not swap them. */
|
|
572
|
+
rangeReversed: string;
|
|
573
|
+
/** A half-open range's start is its end, so it holds nothing. */
|
|
574
|
+
rangeEmpty: string;
|
|
575
|
+
/** A range spans less than its minimum, written as the input writes spans. */
|
|
576
|
+
rangeTooShort: (span: string) => string;
|
|
577
|
+
/** A range spans more than its maximum, written as the input writes spans. */
|
|
578
|
+
rangeTooLong: (span: string) => string;
|
|
579
|
+
/** A range input's span, shown after its end. */
|
|
580
|
+
rangeSpanLabel: (span: string) => string;
|
|
581
|
+
/** A masked field's text leaves required slots empty. */
|
|
582
|
+
maskIncomplete: string;
|
|
583
|
+
/** An IBAN has the wrong length for its country, or fails its check digits. */
|
|
584
|
+
ibanInvalid: string;
|
|
585
|
+
/** A card number fails its check digit. */
|
|
586
|
+
cardNumberInvalid: string;
|
|
587
|
+
/** An IPv4 address has a part above 255, or one with a leading zero. */
|
|
588
|
+
ipv4Invalid: string;
|
|
589
|
+
/** The visible character counter. */
|
|
590
|
+
counter: (count: number, max: number) => string;
|
|
591
|
+
/** The counter's description, read with the control. */
|
|
592
|
+
counterLabel: (max: number) => string;
|
|
593
|
+
/** Announced as typing pauses near the limit. */
|
|
594
|
+
charactersLeft: (left: number) => string;
|
|
595
|
+
/** Announced as typing pauses over the limit. */
|
|
596
|
+
charactersOver: (over: number) => string;
|
|
597
|
+
/** Announced while an input loads. */
|
|
598
|
+
loading: string;
|
|
599
|
+
/** Read beside the dash an empty field shows in display mode. */
|
|
600
|
+
emptyValue: string;
|
|
601
|
+
/** A checked checkbox in display mode, and its event text. */
|
|
602
|
+
displayChecked: string;
|
|
603
|
+
/** An unchecked checkbox in display mode, and its event text. */
|
|
604
|
+
displayUnchecked: string;
|
|
605
|
+
/** A switch that is on, in display mode. */
|
|
606
|
+
displayOn: string;
|
|
607
|
+
/** A switch that is off, in display mode. */
|
|
608
|
+
displayOff: string;
|
|
609
|
+
/** The marker on an optional field's label. */
|
|
610
|
+
optional: string;
|
|
611
|
+
/** The help button's accessible name. */
|
|
612
|
+
fieldHelp: string;
|
|
613
|
+
/** A search input's placeholder. */
|
|
614
|
+
searchPlaceholder: string;
|
|
615
|
+
/** Read before a message, naming its severity. */
|
|
616
|
+
severityLabel: (severity: Severity) => string;
|
|
617
|
+
/** How many messages of one severity a summary holds. */
|
|
618
|
+
severityCount: (severity: Severity, count: number) => string;
|
|
619
|
+
/** The message summary's title. */
|
|
620
|
+
messageSummaryTitle: (count: number) => string;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* The forms' own English, counts printed in `locale`'s digits. Without a
|
|
624
|
+
* locale, the runtime's own; that one is `defaultFormsMessages`.
|
|
625
|
+
*/
|
|
626
|
+
declare function createDefaultFormsMessages(locale?: Intl.LocalesArgument): FormsMessages;
|
|
627
|
+
/** The forms' own English, which an app's messages replace key by key. */
|
|
628
|
+
declare const defaultFormsMessages: FormsMessages;
|
|
629
|
+
/**
|
|
630
|
+
* `messages` over the defaults for `locale`: every key the forms need,
|
|
631
|
+
* whichever the caller gave. The defaults themselves, the same object for
|
|
632
|
+
* the same locale, when it gave none, so a renderer memoizing on the result
|
|
633
|
+
* sees no change that is not one.
|
|
634
|
+
*/
|
|
635
|
+
declare function resolveFormsMessages(messages: Partial<FormsMessages> | undefined, locale?: Intl.LocalesArgument): FormsMessages;
|
|
636
|
+
|
|
637
|
+
/** How text reads: a value (`null` for empty), or why it cannot be read. */
|
|
638
|
+
type ParseResult<V> = {
|
|
639
|
+
readonly kind: "value";
|
|
640
|
+
readonly value: V | null;
|
|
641
|
+
} | {
|
|
642
|
+
readonly kind: "unreadable";
|
|
643
|
+
readonly message: string;
|
|
644
|
+
};
|
|
645
|
+
/** What a parser knows beside the text. */
|
|
646
|
+
interface ParseContext<V> {
|
|
647
|
+
/** The input's own reading, to fall back on. */
|
|
648
|
+
readonly defaultParse: (text: string) => ParseResult<V>;
|
|
649
|
+
readonly locale: Intl.LocalesArgument;
|
|
650
|
+
readonly messages: FormsMessages;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Reads typed text as a value. An app's parser receives the input's own in
|
|
654
|
+
* its context, so it can change one case and leave the rest to it:
|
|
655
|
+
*
|
|
656
|
+
* ```ts
|
|
657
|
+
* const parse: Parser<string> = (text, { defaultParse }) =>
|
|
658
|
+
* text === "n/a" ? parsed(null) : defaultParse(text);
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
type Parser<V> = (text: string, context: ParseContext<V>) => ParseResult<V>;
|
|
662
|
+
/**
|
|
663
|
+
* What a value is written for: `edit` while the field has focus, `display`
|
|
664
|
+
* otherwise and in display mode. A number input writes plain digits to
|
|
665
|
+
* edit and grouped digits to display; a text input writes the same for both.
|
|
666
|
+
*/
|
|
667
|
+
type FormatPurpose = "display" | "edit";
|
|
668
|
+
/** What a formatter knows beside the value. */
|
|
669
|
+
interface FormatContext<V> {
|
|
670
|
+
/** The input's own formatting, to fall back on. */
|
|
671
|
+
readonly defaultFormat: (value: V | null) => string;
|
|
672
|
+
readonly locale: Intl.LocalesArgument;
|
|
673
|
+
readonly messages: FormsMessages;
|
|
674
|
+
readonly purpose: FormatPurpose;
|
|
675
|
+
}
|
|
676
|
+
/** Writes a value as the text a field shows, `null` included. */
|
|
677
|
+
type Formatter<V> = (value: V | null, context: FormatContext<V>) => string;
|
|
678
|
+
/** Text that reads as `value`; `null` for empty. */
|
|
679
|
+
declare function parsed<V>(value: V | null): ParseResult<V>;
|
|
680
|
+
/** Text that cannot be read, and why, in words the user sees. */
|
|
681
|
+
declare function unreadable<V>(message: string): ParseResult<V>;
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* The value a checkbox takes when it is flipped. Without `threeState`,
|
|
685
|
+
* `false` and `null` go to `true` and `true` to `false`, so an app's
|
|
686
|
+
* `null` (a "select all" over a partial selection) checks on the first
|
|
687
|
+
* flip. With it, `false` → `true` → `null` → `false`.
|
|
688
|
+
*/
|
|
689
|
+
declare function nextCheckedValue(value: boolean | null, threeState: boolean): boolean | null;
|
|
690
|
+
/** The words a toggle reads as: one for `true`, one for `false`. */
|
|
691
|
+
interface BooleanWords {
|
|
692
|
+
readonly on: (messages: FormsMessages) => string;
|
|
693
|
+
readonly off: (messages: FormsMessages) => string;
|
|
694
|
+
}
|
|
695
|
+
/** A checkbox reads "Yes" or "No" (`displayChecked`, `displayUnchecked`). */
|
|
696
|
+
declare const CHECKBOX_WORDS: BooleanWords;
|
|
697
|
+
/** A switch reads "On" or "Off" (`displayOn`, `displayOff`). */
|
|
698
|
+
declare const SWITCH_WORDS: BooleanWords;
|
|
699
|
+
/**
|
|
700
|
+
* A toggle's value as text: its words for `true` and `false`, `""` for
|
|
701
|
+
* `null`. The text a toggle's events carry and display mode shows.
|
|
702
|
+
*/
|
|
703
|
+
declare function booleanFormatter(words: BooleanWords): (value: boolean | null, context: FormatContext<boolean>) => string;
|
|
704
|
+
/** Reads a toggle's words back as its value; anything else is `null`. */
|
|
705
|
+
declare function booleanParser(words: BooleanWords): (text: string, context: ParseContext<boolean>) => ParseResult<boolean>;
|
|
706
|
+
|
|
707
|
+
/** The day a week starts on in a locale, and its weekend days. */
|
|
708
|
+
interface WeekInfo {
|
|
709
|
+
readonly firstDay: Weekday;
|
|
710
|
+
readonly weekend: readonly Weekday[];
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* How weeks are numbered: `"iso"`, weeks from Monday with week 1 holding
|
|
714
|
+
* the year's first Thursday (ISO 8601); `"simple"`, weeks from the first
|
|
715
|
+
* day of week with week 1 holding 1 January (US practice).
|
|
716
|
+
*/
|
|
717
|
+
type WeekNumbering = "iso" | "simple";
|
|
718
|
+
/** A week of a year: `{ year: 2026, week: 11 }` is 2026-W11. */
|
|
719
|
+
interface WeekOfYear {
|
|
720
|
+
readonly year: number;
|
|
721
|
+
readonly week: number;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* The first day of week and the weekend in `locale`: Sunday in `en-US`,
|
|
725
|
+
* Monday in `de-DE`, Saturday in `ar-EG`. Read from
|
|
726
|
+
* `Intl.Locale#getWeekInfo`, else the getter some engines shipped before
|
|
727
|
+
* it, else CLDR's table by region. A field's `firstDayOfWeek` overrides
|
|
728
|
+
* it.
|
|
729
|
+
*/
|
|
730
|
+
declare function weekInfo(locale: Intl.LocalesArgument): WeekInfo;
|
|
731
|
+
/**
|
|
732
|
+
* The numbering a field uses unless told: `"iso"` when weeks start on
|
|
733
|
+
* Monday, `"simple"` otherwise. `Intl` no longer reports a locale's
|
|
734
|
+
* minimal days in the first week, so the numbering cannot come from it.
|
|
735
|
+
*/
|
|
736
|
+
declare function defaultWeekNumbering(firstDay: Weekday): WeekNumbering;
|
|
737
|
+
/** The first day of the week `date` falls in, weeks starting on `firstDay`. */
|
|
738
|
+
declare function startOfWeek(date: PlainDate, firstDay: Weekday): PlainDate;
|
|
739
|
+
/**
|
|
740
|
+
* The week `date` falls in. ISO: weeks from Monday, the week belonging to
|
|
741
|
+
* the year of its Thursday (`firstDay` is ignored). Simple: weeks from
|
|
742
|
+
* `firstDay`, the week belonging to the year of its last day, week 1
|
|
743
|
+
* holding 1 January. Days in the first or last week of the years 1 and
|
|
744
|
+
* 9999 may have no week to count from and throw a `RangeError`.
|
|
745
|
+
*/
|
|
746
|
+
declare function weekOf(date: PlainDate, numbering: WeekNumbering, firstDay: Weekday): WeekOfYear;
|
|
747
|
+
|
|
748
|
+
/** One day in a month grid. */
|
|
749
|
+
interface CalendarDay {
|
|
750
|
+
readonly date: PlainDate;
|
|
751
|
+
readonly weekday: Weekday;
|
|
752
|
+
/** False for the days of the months before and after that fill the first and last weeks. */
|
|
753
|
+
readonly inMonth: boolean;
|
|
754
|
+
}
|
|
755
|
+
/** One row of a month grid: seven days and the week they make. */
|
|
756
|
+
interface CalendarWeek {
|
|
757
|
+
readonly week: WeekOfYear;
|
|
758
|
+
readonly days: readonly CalendarDay[];
|
|
759
|
+
}
|
|
760
|
+
/** A month laid out for a calendar. */
|
|
761
|
+
interface MonthGrid {
|
|
762
|
+
readonly year: number;
|
|
763
|
+
readonly month: number;
|
|
764
|
+
/** The weekdays in column order, `firstDayOfWeek` first. */
|
|
765
|
+
readonly weekdays: readonly Weekday[];
|
|
766
|
+
/** Always six, so a calendar's height never changes from month to month. */
|
|
767
|
+
readonly weeks: readonly CalendarWeek[];
|
|
768
|
+
}
|
|
769
|
+
interface MonthGridOptions {
|
|
770
|
+
readonly firstDayOfWeek: Weekday;
|
|
771
|
+
/** By default `"iso"` when weeks start on Monday, `"simple"` otherwise. */
|
|
772
|
+
readonly weekNumbering?: WeekNumbering | undefined;
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* `month` of `year` as six weeks of days from `firstDayOfWeek`, with the
|
|
776
|
+
* days of the months either side filling the first and last weeks, and
|
|
777
|
+
* each week's number. A row's number is its fourth day's week, which is
|
|
778
|
+
* the week most of its days belong to even when the numbering's weeks
|
|
779
|
+
* start on another day (ISO weeks in a Sunday-first grid). Throws a
|
|
780
|
+
* `RangeError` for a month whose six weeks reach before 0001-01-01 or
|
|
781
|
+
* after 9999-12-31.
|
|
782
|
+
*/
|
|
783
|
+
declare function monthGrid(year: number, month: number, options: MonthGridOptions): MonthGrid;
|
|
784
|
+
/** A month a calendar shows, as `yyyy-mm`: "2026-03". */
|
|
785
|
+
type CalendarMonth = `${number}-${number}`;
|
|
786
|
+
/** Whether `value` is a month as a calendar holds one: "2026-03", years 1 to 9999. */
|
|
787
|
+
declare function isCalendarMonth(value: unknown): value is CalendarMonth;
|
|
788
|
+
/** The month `month` (1 to 12) of `year`. Throws a `RangeError` for a month that does not exist. */
|
|
789
|
+
declare function calendarMonth(year: number, month: number): CalendarMonth;
|
|
790
|
+
/** A month's year and its number, 1 to 12. */
|
|
791
|
+
declare function calendarMonthParts(month: CalendarMonth): {
|
|
792
|
+
readonly year: number;
|
|
793
|
+
readonly month: number;
|
|
794
|
+
};
|
|
795
|
+
/** The month `date` falls in. */
|
|
796
|
+
declare function monthOfDate(date: PlainDate): CalendarMonth;
|
|
797
|
+
/** Negative when `a` comes first, 0 for the same month, positive after. */
|
|
798
|
+
declare function compareCalendarMonths(a: CalendarMonth, b: CalendarMonth): number;
|
|
799
|
+
/** The days a calendar lets a user reach and choose. */
|
|
800
|
+
interface CalendarLimits {
|
|
801
|
+
/** The first day that can be chosen, inclusive. */
|
|
802
|
+
readonly min?: PlainDate | undefined;
|
|
803
|
+
/** The last day that can be chosen, inclusive. */
|
|
804
|
+
readonly max?: PlainDate | undefined;
|
|
805
|
+
/** Days that show but cannot be chosen. */
|
|
806
|
+
readonly isDateDisabled?: ((date: PlainDate) => boolean) | undefined;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Whether a calendar shows `date` as one that cannot be chosen: before
|
|
810
|
+
* `min`, after `max`, marked by `isDateDisabled`, or outside the months a
|
|
811
|
+
* calendar shows (before February of the year 1, after November of 9999).
|
|
812
|
+
*/
|
|
813
|
+
declare function isCalendarDayDisabled(date: PlainDate, limits: CalendarLimits): boolean;
|
|
814
|
+
/** Whether month `month` of `year` holds no day within the calendar's limits, so its month view disables it. */
|
|
815
|
+
declare function isCalendarMonthDisabled(year: number, month: number, limits: CalendarLimits): boolean;
|
|
816
|
+
/**
|
|
817
|
+
* `month` moved where a calendar showing `visibleMonths` months from it
|
|
818
|
+
* can be: no earlier than the month of `min`, and its last month no later
|
|
819
|
+
* than the month of `max`, nor than November of 9999.
|
|
820
|
+
*/
|
|
821
|
+
declare function clampCalendarMonth(month: CalendarMonth, limits: CalendarLimits, visibleMonths?: number): CalendarMonth;
|
|
822
|
+
/** `date` moved into the days focus can reach. */
|
|
823
|
+
declare function clampCalendarDate(date: PlainDate, limits: CalendarLimits): PlainDate;
|
|
824
|
+
/** `date`'s day of the month in `month`, clamped to the month's length: the 31st in February is the 28th or 29th. */
|
|
825
|
+
declare function sameDayIn(month: CalendarMonth, date: PlainDate): PlainDate;
|
|
826
|
+
/** The years a calendar's month view lists: from `min` to `max`, else 100 either side of `year`. */
|
|
827
|
+
declare function calendarYears(year: number, limits: CalendarLimits): {
|
|
828
|
+
readonly first: number;
|
|
829
|
+
readonly last: number;
|
|
830
|
+
};
|
|
831
|
+
/** Where a key moves focus in a calendar's grid. */
|
|
832
|
+
type CalendarMove = "previousDay" | "nextDay" | "previousWeek" | "nextWeek" | "startOfWeek" | "endOfWeek" | "previousMonth" | "nextMonth" | "previousYear" | "nextYear";
|
|
833
|
+
/**
|
|
834
|
+
* The day `move` takes focus to from `date`, weeks starting on
|
|
835
|
+
* `firstDayOfWeek`: a day or a week on, the week's first or last day, or
|
|
836
|
+
* the same day of the month or year before or after (clamped to the
|
|
837
|
+
* month's length). Clamped to the days focus can reach, so at the edge a
|
|
838
|
+
* key does nothing.
|
|
839
|
+
*/
|
|
840
|
+
declare function moveCalendarDate(date: PlainDate, move: CalendarMove, firstDayOfWeek: Weekday, limits: CalendarLimits): PlainDate;
|
|
841
|
+
/** What a calendar's panel shows: the days of its months, or its months and years to jump to. */
|
|
842
|
+
type CalendarView = {
|
|
843
|
+
readonly kind: "days";
|
|
844
|
+
} | {
|
|
845
|
+
readonly kind: "months";
|
|
846
|
+
/** The year whose months show. */
|
|
847
|
+
readonly year: number;
|
|
848
|
+
/** Which of the months shown the jump replaces, 0 for the first. */
|
|
849
|
+
readonly panel: number;
|
|
850
|
+
};
|
|
851
|
+
/** Where a calendar is: the months it shows, the day focus is on, its view. */
|
|
852
|
+
interface CalendarState {
|
|
853
|
+
/** The first month shown. */
|
|
854
|
+
readonly month: CalendarMonth;
|
|
855
|
+
/** The day that takes focus in the grid: always in a month shown. */
|
|
856
|
+
readonly focused: PlainDate;
|
|
857
|
+
readonly view: CalendarView;
|
|
858
|
+
}
|
|
859
|
+
/** What the calendar reducer is told. */
|
|
860
|
+
interface CalendarContext {
|
|
861
|
+
readonly firstDayOfWeek: Weekday;
|
|
862
|
+
/** How many months show side by side. */
|
|
863
|
+
readonly visibleMonths: number;
|
|
864
|
+
readonly limits: CalendarLimits;
|
|
865
|
+
}
|
|
866
|
+
/** What can happen to a calendar. */
|
|
867
|
+
type CalendarAction =
|
|
868
|
+
/** A key moved focus in the grid. */
|
|
869
|
+
{
|
|
870
|
+
readonly type: "move";
|
|
871
|
+
readonly move: CalendarMove;
|
|
872
|
+
}
|
|
873
|
+
/** A day took focus: a click, or a day of another month chosen. */
|
|
874
|
+
| {
|
|
875
|
+
readonly type: "focus";
|
|
876
|
+
readonly date: PlainDate;
|
|
877
|
+
}
|
|
878
|
+
/** The previous or next month button: the months shown move by `months`. */
|
|
879
|
+
| {
|
|
880
|
+
readonly type: "page";
|
|
881
|
+
readonly months: number;
|
|
882
|
+
}
|
|
883
|
+
/** The app's `month`: shown first. */
|
|
884
|
+
| {
|
|
885
|
+
readonly type: "show";
|
|
886
|
+
readonly month: CalendarMonth;
|
|
887
|
+
}
|
|
888
|
+
/** A month's title: the month view opens in its place. */
|
|
889
|
+
| {
|
|
890
|
+
readonly type: "openMonths";
|
|
891
|
+
readonly panel: number;
|
|
892
|
+
}
|
|
893
|
+
/** A year chosen in the month view. */
|
|
894
|
+
| {
|
|
895
|
+
readonly type: "showYear";
|
|
896
|
+
readonly year: number;
|
|
897
|
+
}
|
|
898
|
+
/** A month (1 to 12) of the view's year chosen: the days show again, from it. */
|
|
899
|
+
| {
|
|
900
|
+
readonly type: "chooseMonth";
|
|
901
|
+
readonly month: number;
|
|
902
|
+
}
|
|
903
|
+
/** Escape in the month view: the days show again, unchanged. */
|
|
904
|
+
| {
|
|
905
|
+
readonly type: "closeMonths";
|
|
906
|
+
};
|
|
907
|
+
/**
|
|
908
|
+
* Where a calendar starts: showing `month` (the app's), else the month of
|
|
909
|
+
* `focus`, with focus on `focus` when it is shown, else on its day of the
|
|
910
|
+
* month in the first month shown.
|
|
911
|
+
*/
|
|
912
|
+
declare function calendarStart(focus: PlainDate, month: CalendarMonth | undefined, context: CalendarContext): CalendarState;
|
|
913
|
+
/**
|
|
914
|
+
* The calendar after `action`: every way focus moves between days and
|
|
915
|
+
* months, and the month view opens and closes. Focus stays on a day in a
|
|
916
|
+
* month shown and within the limits; the months shown move as little as
|
|
917
|
+
* it takes.
|
|
918
|
+
*/
|
|
919
|
+
declare function calendarReducer(state: CalendarState, action: CalendarAction, context: CalendarContext): CalendarState;
|
|
920
|
+
/** A month as a calendar's title writes it: "March 2026", "März 2026". */
|
|
921
|
+
declare function formatCalendarMonth(month: CalendarMonth, locale: Intl.LocalesArgument): string;
|
|
922
|
+
/** A month's name alone: "Mar", "March". */
|
|
923
|
+
declare function formatMonthName(month: number, locale: Intl.LocalesArgument, width: "short" | "long"): string;
|
|
924
|
+
/** A weekday's name: "M", "Mon", "Monday". */
|
|
925
|
+
declare function formatWeekday(weekday: Weekday, locale: Intl.LocalesArgument, width: "narrow" | "short" | "long"): string;
|
|
926
|
+
/** A day of the month as a calendar's cell writes it, in the locale's digits: "14". */
|
|
927
|
+
declare function formatDayOfMonth(date: PlainDate, locale: Intl.LocalesArgument): string;
|
|
928
|
+
/** A year as a calendar's year list writes it, in the locale's digits. */
|
|
929
|
+
declare function formatCalendarYear(year: number, locale: Intl.LocalesArgument): string;
|
|
930
|
+
|
|
931
|
+
/** One message a field holds, ready to show. */
|
|
932
|
+
interface FieldMessage {
|
|
933
|
+
readonly severity: Severity;
|
|
934
|
+
/** The text shown, already localized. */
|
|
935
|
+
readonly text: string;
|
|
936
|
+
/**
|
|
937
|
+
* A stable id for the kind of message: `"unreadable"`, `"required"`,
|
|
938
|
+
* `"tooShort"`, `"tooLong"`, `"pattern"`, `"refused"`, or the app's own;
|
|
939
|
+
* `null` when it has none.
|
|
940
|
+
*/
|
|
941
|
+
readonly code: string | null;
|
|
942
|
+
/**
|
|
943
|
+
* Where it came from: reading the text (`"parse"`), a validator
|
|
944
|
+
* (`"validate"`), a refused commit (`"commit"`) or the app (`"app"`).
|
|
945
|
+
* Growable: a later release may add a source.
|
|
946
|
+
*/
|
|
947
|
+
readonly source: "parse" | "validate" | "commit" | "app";
|
|
948
|
+
}
|
|
949
|
+
/** A message as an app writes it: a string is an error. */
|
|
950
|
+
type FieldMessageInput = string | {
|
|
951
|
+
readonly text: string;
|
|
952
|
+
readonly severity?: Severity | undefined;
|
|
953
|
+
readonly code?: string | undefined;
|
|
954
|
+
};
|
|
955
|
+
/**
|
|
956
|
+
* Whatever an app or a validator returned, as a list of messages from
|
|
957
|
+
* `source`: one input or several, `null` and `undefined` for none.
|
|
958
|
+
*/
|
|
959
|
+
declare function toFieldMessages(input: FieldMessageInput | readonly FieldMessageInput[] | null | undefined, source: FieldMessage["source"]): FieldMessage[];
|
|
960
|
+
/**
|
|
961
|
+
* `messages` in the order a field shows them: the most serious first, and
|
|
962
|
+
* within a severity what the text could not say (parse), then a refused
|
|
963
|
+
* commit, then validators, then the app's own. Equal messages keep their
|
|
964
|
+
* order.
|
|
965
|
+
*/
|
|
966
|
+
declare function sortFieldMessages(messages: readonly FieldMessage[]): FieldMessage[];
|
|
967
|
+
/** Whether any of `messages` is an error: the only severity that blocks. */
|
|
968
|
+
declare function hasError(messages: readonly FieldMessage[]): boolean;
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
* Where a change came from. A minor release may add a member, so a `switch`
|
|
972
|
+
* over it needs a `default`.
|
|
973
|
+
*
|
|
974
|
+
* - `typing`: keys, deleting and text an input method composed.
|
|
975
|
+
* - `paste`, `drop`: text pasted or dropped in.
|
|
976
|
+
* - `step`: arrow keys or stepper buttons (number and date inputs).
|
|
977
|
+
* - `picker`: an option, a date or a row chosen in a popup.
|
|
978
|
+
* - `preset`: a preset such as "Last 7 days".
|
|
979
|
+
* - `clear`: the clear button, or Escape in a search box.
|
|
980
|
+
* - `undo`: the browser's undo or redo.
|
|
981
|
+
* - `api`: `setValue`, `reset` or a form reset.
|
|
982
|
+
* - `toggle`: a checkbox or switch flipped, by key or pointer.
|
|
983
|
+
* - `revert`: Escape put back the last committed value.
|
|
984
|
+
* - `autofill`: the text changed while the field did not have focus.
|
|
985
|
+
*/
|
|
986
|
+
type ChangeSource = "typing" | "paste" | "drop" | "step" | "picker" | "preset" | "clear" | "undo" | "api" | "toggle" | "revert" | "autofill";
|
|
987
|
+
/**
|
|
988
|
+
* What ended an edit. A minor release may add a member, so a `switch` over
|
|
989
|
+
* it needs a `default`.
|
|
990
|
+
*/
|
|
991
|
+
type CommitTrigger = "enter" | "tab" | "blur" | "picker" | "preset" | "clear" | "toggle" | "autofill";
|
|
992
|
+
/** The browser's report of a text edit. */
|
|
993
|
+
interface TextInputDetails {
|
|
994
|
+
/**
|
|
995
|
+
* The `InputEvent`'s `inputType` (`"insertText"`,
|
|
996
|
+
* `"deleteContentBackward"`, `"insertFromPaste"`, `"historyUndo"`, ...);
|
|
997
|
+
* `null` when no browser edit made the change.
|
|
998
|
+
*/
|
|
999
|
+
readonly inputType: string | null;
|
|
1000
|
+
/** The text inserted (typed, pasted, dropped, composed); `null` for a deletion. */
|
|
1001
|
+
readonly data: string | null;
|
|
1002
|
+
readonly selectionStart: number | null;
|
|
1003
|
+
readonly selectionEnd: number | null;
|
|
1004
|
+
readonly isComposing: boolean;
|
|
1005
|
+
}
|
|
1006
|
+
/** No per-input details. */
|
|
1007
|
+
type NoDetails = Record<never, never>;
|
|
1008
|
+
/**
|
|
1009
|
+
* What every forms event carries. `value` and `text` are what the field
|
|
1010
|
+
* holds after the change the event is about (the proposed value, in a
|
|
1011
|
+
* before-event); `previousValue` and `previousText` what it held before.
|
|
1012
|
+
* `N` is the native event type: `Event` in forms-dom and forms.
|
|
1013
|
+
*/
|
|
1014
|
+
interface FieldEventBase<V, N = unknown> {
|
|
1015
|
+
readonly value: V | null;
|
|
1016
|
+
readonly previousValue: V | null;
|
|
1017
|
+
readonly text: string;
|
|
1018
|
+
readonly previousText: string;
|
|
1019
|
+
readonly source: ChangeSource;
|
|
1020
|
+
/** The browser event behind it; `null` for a change the app made. */
|
|
1021
|
+
readonly nativeEvent: N | null;
|
|
1022
|
+
/** The text edit behind it; `null` when no browser edit made the change. */
|
|
1023
|
+
readonly input: TextInputDetails | null;
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* The text changed. Reading the text comes after it, so `value` and
|
|
1027
|
+
* `previousValue` are both the value the field held before the edit.
|
|
1028
|
+
* Each input adds its own details by intersection; a details key never
|
|
1029
|
+
* reuses a base field's name.
|
|
1030
|
+
*/
|
|
1031
|
+
type FieldInputEvent<V, D extends object = NoDetails, N = unknown> = FieldEventBase<V, N> & D;
|
|
1032
|
+
/** The value changed. */
|
|
1033
|
+
type FieldChangeEvent<V, D extends object = NoDetails, N = unknown> = FieldEventBase<V, N> & D;
|
|
1034
|
+
/** The field's messages were worked out again. */
|
|
1035
|
+
type FieldValidateEvent<V, D extends object = NoDetails, N = unknown> = FieldEventBase<V, N> & D & {
|
|
1036
|
+
/** Every message the field holds now, shown or not yet. */
|
|
1037
|
+
readonly messages: readonly FieldMessage[];
|
|
1038
|
+
/** Whether none of them is an error. */
|
|
1039
|
+
readonly valid: boolean;
|
|
1040
|
+
};
|
|
1041
|
+
/** The user is done: the value is committed. */
|
|
1042
|
+
type FieldCommitEvent<V, D extends object = NoDetails, N = unknown> = FieldEventBase<V, N> & D & {
|
|
1043
|
+
readonly trigger: CommitTrigger;
|
|
1044
|
+
/** Whether `value` differs from `previousValue`: the value at the last commit, or at focus. */
|
|
1045
|
+
readonly changed: boolean;
|
|
1046
|
+
/** The value when the field gained focus. */
|
|
1047
|
+
readonly initialValue: V | null;
|
|
1048
|
+
};
|
|
1049
|
+
/**
|
|
1050
|
+
* A text edit is about to happen. `text` is the proposed text; reading it
|
|
1051
|
+
* comes later, so `value` and `previousValue` are the value held now.
|
|
1052
|
+
*/
|
|
1053
|
+
type FieldBeforeInputEvent<V, D extends object = NoDetails, N = unknown> = FieldEventBase<V, N> & D & {
|
|
1054
|
+
/** False while an input method is composing: it owns the text, so the two calls below do nothing. */
|
|
1055
|
+
readonly cancelable: boolean;
|
|
1056
|
+
readonly defaultPrevented: boolean;
|
|
1057
|
+
/** The edit does not happen. */
|
|
1058
|
+
preventDefault(): void;
|
|
1059
|
+
/** Inserts `data` in place of what was typed, pasted or dropped. */
|
|
1060
|
+
setData(data: string): void;
|
|
1061
|
+
};
|
|
1062
|
+
/** The value is about to change to `value`. */
|
|
1063
|
+
type FieldBeforeChangeEvent<V, D extends object = NoDetails, N = unknown> = FieldEventBase<V, N> & D & {
|
|
1064
|
+
readonly defaultPrevented: boolean;
|
|
1065
|
+
/** The value does not change; typed text is put back as it was before this edit. */
|
|
1066
|
+
preventDefault(): void;
|
|
1067
|
+
/** Changes to `value` instead; typed text becomes `format(value)` unless it already reads as it. */
|
|
1068
|
+
setValue(value: V | null): void;
|
|
1069
|
+
};
|
|
1070
|
+
/**
|
|
1071
|
+
* The value is about to be committed. The handler may return a promise:
|
|
1072
|
+
* the commit waits for it, and so does the `onBlur` of a field being left.
|
|
1073
|
+
*/
|
|
1074
|
+
type FieldBeforeCommitEvent<V, D extends object = NoDetails, N = unknown> = FieldCommitEvent<V, D, N> & {
|
|
1075
|
+
readonly defaultPrevented: boolean;
|
|
1076
|
+
/**
|
|
1077
|
+
* Refuses the commit; `message` (default `messages.checkFailed`) shows as
|
|
1078
|
+
* an error. Called after a returned promise settles, it does nothing.
|
|
1079
|
+
*/
|
|
1080
|
+
preventDefault(message?: FieldMessageInput): void;
|
|
1081
|
+
};
|
|
1082
|
+
/** The field gained or lost focus. */
|
|
1083
|
+
interface FieldFocusEvent<V, N = unknown> {
|
|
1084
|
+
readonly value: V | null;
|
|
1085
|
+
readonly text: string;
|
|
1086
|
+
readonly nativeEvent: N | null;
|
|
1087
|
+
}
|
|
1088
|
+
/** Every handler a field calls, each optional, in the order they fire. */
|
|
1089
|
+
interface FieldHandlers<V, D extends object = NoDetails, N = unknown> {
|
|
1090
|
+
readonly onFocus?: ((event: FieldFocusEvent<V, N>) => void) | undefined;
|
|
1091
|
+
readonly onBeforeInput?: ((event: FieldBeforeInputEvent<V, D, N>) => void) | undefined;
|
|
1092
|
+
readonly onInput?: ((event: FieldInputEvent<V, D, N>) => void) | undefined;
|
|
1093
|
+
readonly onBeforeChange?: ((event: FieldBeforeChangeEvent<V, D, N>) => void) | undefined;
|
|
1094
|
+
readonly onChange?: ((event: FieldChangeEvent<V, D, N>) => void) | undefined;
|
|
1095
|
+
readonly onValidate?: ((event: FieldValidateEvent<V, D, N>) => void) | undefined;
|
|
1096
|
+
readonly onBeforeCommit?: ((event: FieldBeforeCommitEvent<V, D, N>) => void | Promise<void>) | undefined;
|
|
1097
|
+
readonly onCommit?: ((event: FieldCommitEvent<V, D, N>) => void) | undefined;
|
|
1098
|
+
readonly onBlur?: ((event: FieldFocusEvent<V, N>) => void) | undefined;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* The reading of a draft's text: `pending` while it has not been read yet
|
|
1103
|
+
* (an input method is composing, or a change delay is running), else the
|
|
1104
|
+
* parse result. A minor release may add a member.
|
|
1105
|
+
*/
|
|
1106
|
+
type TextReading<V> = {
|
|
1107
|
+
readonly kind: "pending";
|
|
1108
|
+
} | ParseResult<V>;
|
|
1109
|
+
/**
|
|
1110
|
+
* What a field shows. `current` is its value, formatted, and follows the
|
|
1111
|
+
* value when the value changes (an untouched field follows a controlled
|
|
1112
|
+
* value); `text` is text the user typed, with how it reads. A minor release
|
|
1113
|
+
* may add a member.
|
|
1114
|
+
*/
|
|
1115
|
+
type FieldDraft<V> = {
|
|
1116
|
+
readonly kind: "current";
|
|
1117
|
+
} | {
|
|
1118
|
+
readonly kind: "text";
|
|
1119
|
+
readonly text: string;
|
|
1120
|
+
readonly reading: TextReading<V>;
|
|
1121
|
+
};
|
|
1122
|
+
/**
|
|
1123
|
+
* Where the field is in an edit. A minor release may add a member, so a
|
|
1124
|
+
* `switch` over `kind` needs a `default`.
|
|
1125
|
+
*
|
|
1126
|
+
* - `idle`: not being edited.
|
|
1127
|
+
* - `editing`: focused. `initialValue` is the value when it gained focus;
|
|
1128
|
+
* `committedValue` the value at its last commit since then (or at focus).
|
|
1129
|
+
* - `checking`: an asynchronous `onBeforeCommit` is deciding. `attempt`
|
|
1130
|
+
* identifies it, so a superseded check's answer is ignored; `leaving` is
|
|
1131
|
+
* true once focus has gone (its `onBlur` waits for the answer).
|
|
1132
|
+
* - `leaving`: Tab committed and focus is about to move; the blur that
|
|
1133
|
+
* follows commits nothing more.
|
|
1134
|
+
*/
|
|
1135
|
+
type FieldPhase<V> = {
|
|
1136
|
+
readonly kind: "idle";
|
|
1137
|
+
} | {
|
|
1138
|
+
readonly kind: "editing";
|
|
1139
|
+
readonly initialValue: V | null;
|
|
1140
|
+
readonly committedValue: V | null;
|
|
1141
|
+
} | {
|
|
1142
|
+
readonly kind: "checking";
|
|
1143
|
+
readonly initialValue: V | null;
|
|
1144
|
+
readonly committedValue: V | null;
|
|
1145
|
+
readonly trigger: CommitTrigger;
|
|
1146
|
+
readonly attempt: number;
|
|
1147
|
+
readonly leaving: boolean;
|
|
1148
|
+
} | {
|
|
1149
|
+
readonly kind: "leaving";
|
|
1150
|
+
readonly initialValue: V | null;
|
|
1151
|
+
readonly committedValue: V | null;
|
|
1152
|
+
};
|
|
1153
|
+
/** One field, whole. */
|
|
1154
|
+
interface FieldState<V> {
|
|
1155
|
+
/** The last valid value; `null` is empty. */
|
|
1156
|
+
readonly value: V | null;
|
|
1157
|
+
readonly draft: FieldDraft<V>;
|
|
1158
|
+
/** What the validators said about `value`. */
|
|
1159
|
+
readonly validation: readonly FieldMessage[];
|
|
1160
|
+
/** Why the last commit was refused, until the text or value changes again. */
|
|
1161
|
+
readonly refusal: FieldMessage | null;
|
|
1162
|
+
/** Whether messages are shown yet: false until the first commit attempt or `reveal`. */
|
|
1163
|
+
readonly revealed: boolean;
|
|
1164
|
+
readonly phase: FieldPhase<V>;
|
|
1165
|
+
}
|
|
1166
|
+
/** The text on screen: `format(value)` for a `current` draft, else the typed text. */
|
|
1167
|
+
declare function fieldText<V>(state: FieldState<V>, format: (value: V | null) => string): string;
|
|
1168
|
+
/**
|
|
1169
|
+
* Every message the field holds, in display order, shown or not yet. Text
|
|
1170
|
+
* that cannot be read shows only why (and a refusal), not what the
|
|
1171
|
+
* validators said about the value it no longer shows.
|
|
1172
|
+
*/
|
|
1173
|
+
declare function fieldMessages<V>(state: FieldState<V>): FieldMessage[];
|
|
1174
|
+
/** The messages the field shows now: all of them once `revealed`, else none. */
|
|
1175
|
+
declare function shownMessages<V>(state: FieldState<V>): FieldMessage[];
|
|
1176
|
+
|
|
1177
|
+
/**
|
|
1178
|
+
* A step of a field's edit, as its controller asks for it. Parsing, the
|
|
1179
|
+
* app's hooks and value equality are the controller's, which passes their
|
|
1180
|
+
* results in (`read.reading`, `sync.equal`).
|
|
1181
|
+
*
|
|
1182
|
+
* - `focus`: the field gained focus.
|
|
1183
|
+
* - `edit`: the user changed the text; it is not read yet.
|
|
1184
|
+
* - `read`: how the typed text reads.
|
|
1185
|
+
* - `change`: the value changes; `text` is typed text that reads as it, or
|
|
1186
|
+
* `null` to show the value formatted.
|
|
1187
|
+
* - `revert`: the draft is put back (a refused change, Escape).
|
|
1188
|
+
* - `validated`: what the validators say about the value now.
|
|
1189
|
+
* - `check`: an asynchronous `onBeforeCommit` starts deciding.
|
|
1190
|
+
* - `accept`, `refuse`: a commit is allowed or refused; `next` is the phase
|
|
1191
|
+
* it leaves the field in.
|
|
1192
|
+
* - `blur`: the field lost focus.
|
|
1193
|
+
* - `sync`: a controlled value arrived; `equal` says whether it equals the
|
|
1194
|
+
* field's value.
|
|
1195
|
+
* - `reveal`: messages show from now on.
|
|
1196
|
+
*/
|
|
1197
|
+
type FieldAction<V> = {
|
|
1198
|
+
readonly type: "focus";
|
|
1199
|
+
} | {
|
|
1200
|
+
readonly type: "edit";
|
|
1201
|
+
readonly text: string;
|
|
1202
|
+
} | {
|
|
1203
|
+
readonly type: "read";
|
|
1204
|
+
readonly reading: ParseResult<V>;
|
|
1205
|
+
} | {
|
|
1206
|
+
readonly type: "change";
|
|
1207
|
+
readonly value: V | null;
|
|
1208
|
+
readonly text: string | null;
|
|
1209
|
+
} | {
|
|
1210
|
+
readonly type: "revert";
|
|
1211
|
+
readonly draft: FieldDraft<V>;
|
|
1212
|
+
} | {
|
|
1213
|
+
readonly type: "validated";
|
|
1214
|
+
readonly messages: readonly FieldMessage[];
|
|
1215
|
+
} | {
|
|
1216
|
+
readonly type: "check";
|
|
1217
|
+
readonly trigger: CommitTrigger;
|
|
1218
|
+
readonly attempt: number;
|
|
1219
|
+
readonly leaving: boolean;
|
|
1220
|
+
} | {
|
|
1221
|
+
readonly type: "accept";
|
|
1222
|
+
readonly next: "editing" | "leaving" | "idle";
|
|
1223
|
+
} | {
|
|
1224
|
+
readonly type: "refuse";
|
|
1225
|
+
readonly message: FieldMessage;
|
|
1226
|
+
readonly next: "editing" | "idle";
|
|
1227
|
+
} | {
|
|
1228
|
+
readonly type: "blur";
|
|
1229
|
+
} | {
|
|
1230
|
+
readonly type: "sync";
|
|
1231
|
+
readonly value: V | null;
|
|
1232
|
+
readonly equal: boolean;
|
|
1233
|
+
} | {
|
|
1234
|
+
readonly type: "reveal";
|
|
1235
|
+
};
|
|
1236
|
+
/**
|
|
1237
|
+
* Every transition of a field. Pure: no parsing, no callbacks, no equality
|
|
1238
|
+
* of its own. An action that means nothing in the field's phase returns the
|
|
1239
|
+
* state unchanged.
|
|
1240
|
+
*/
|
|
1241
|
+
declare function fieldReducer<V>(state: FieldState<V>, action: FieldAction<V>): FieldState<V>;
|
|
1242
|
+
|
|
1243
|
+
/** Where a change came from, and the browser's report of it. */
|
|
1244
|
+
interface ChangeCause<N> {
|
|
1245
|
+
readonly source: ChangeSource;
|
|
1246
|
+
readonly nativeEvent: N | null;
|
|
1247
|
+
readonly input: TextInputDetails | null;
|
|
1248
|
+
}
|
|
1249
|
+
/** A text edit, as forms-dom reports it. */
|
|
1250
|
+
interface TextEdit<N> extends ChangeCause<N> {
|
|
1251
|
+
/** The text after the edit; for `beforeInput`, the proposed text. */
|
|
1252
|
+
readonly text: string;
|
|
1253
|
+
}
|
|
1254
|
+
/** What forms-dom does with a text edit `onBeforeInput` saw. */
|
|
1255
|
+
type BeforeInputDecision = {
|
|
1256
|
+
readonly kind: "allow";
|
|
1257
|
+
} | {
|
|
1258
|
+
readonly kind: "prevent";
|
|
1259
|
+
} | {
|
|
1260
|
+
readonly kind: "rewrite";
|
|
1261
|
+
readonly data: string;
|
|
1262
|
+
};
|
|
1263
|
+
/**
|
|
1264
|
+
* What an input's own filter does with an edit: one of `onBeforeInput`'s
|
|
1265
|
+
* decisions, or `replace`, where the whole text becomes `text` with the
|
|
1266
|
+
* caret at `caret` (a mask laying its characters out again).
|
|
1267
|
+
*/
|
|
1268
|
+
type InputFilterDecision = BeforeInputDecision | {
|
|
1269
|
+
readonly kind: "replace";
|
|
1270
|
+
readonly text: string;
|
|
1271
|
+
readonly caret: number;
|
|
1272
|
+
};
|
|
1273
|
+
/**
|
|
1274
|
+
* An input's own judgement of an edit, after the app's `onBeforeInput` let
|
|
1275
|
+
* it through: `edit` is the edit as the app left it (its `text` the text it
|
|
1276
|
+
* would leave), `before` the text before it.
|
|
1277
|
+
*/
|
|
1278
|
+
type InputFilter<N> = (edit: TextEdit<N>, before: string) => InputFilterDecision;
|
|
1279
|
+
/**
|
|
1280
|
+
* How a commit request ended:
|
|
1281
|
+
*
|
|
1282
|
+
* - `accepted`: committed (`onCommit` has fired).
|
|
1283
|
+
* - `refused`: `onBeforeCommit` refused it; its message shows.
|
|
1284
|
+
* - `unreadable`: the text cannot be read, so nothing was committed; the
|
|
1285
|
+
* message shows.
|
|
1286
|
+
* - `checking`: not decided yet. An asynchronous `onBeforeCommit` is
|
|
1287
|
+
* deciding, or the request was made from inside a handler and runs once
|
|
1288
|
+
* the current sequence ends.
|
|
1289
|
+
*/
|
|
1290
|
+
type CommitOutcome = {
|
|
1291
|
+
readonly kind: "accepted";
|
|
1292
|
+
} | {
|
|
1293
|
+
readonly kind: "refused";
|
|
1294
|
+
} | {
|
|
1295
|
+
readonly kind: "unreadable";
|
|
1296
|
+
} | {
|
|
1297
|
+
readonly kind: "checking";
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
/** How a text was read as a date or time. */
|
|
1301
|
+
type DateReadingInfo = {
|
|
1302
|
+
readonly kind: "segments";
|
|
1303
|
+
} | {
|
|
1304
|
+
readonly kind: "iso";
|
|
1305
|
+
} | {
|
|
1306
|
+
readonly kind: "numeric";
|
|
1307
|
+
/** The order the numbers were read in: `"mdy"`, `"dmy"`, `"ymd"`. */
|
|
1308
|
+
readonly order: string;
|
|
1309
|
+
/** A one- or two-digit year took its century from the pivot. */
|
|
1310
|
+
readonly pivotedYear: boolean;
|
|
1311
|
+
} | {
|
|
1312
|
+
readonly kind: "monthName";
|
|
1313
|
+
readonly pivotedYear: boolean;
|
|
1314
|
+
} | {
|
|
1315
|
+
readonly kind: "shortcut";
|
|
1316
|
+
readonly shortcut: string;
|
|
1317
|
+
}
|
|
1318
|
+
/** A time of day from pasted or free text: "3:05 PM", "1505". */
|
|
1319
|
+
| {
|
|
1320
|
+
readonly kind: "time";
|
|
1321
|
+
};
|
|
1322
|
+
/** Why a text cannot be read as a date or time. */
|
|
1323
|
+
type DateUnreadableReason = "dateIncomplete" | "timeIncomplete" | "nonexistent" | "yearDigits" | "unreadable";
|
|
1324
|
+
/**
|
|
1325
|
+
* What a text reads as, before a field makes its value from it: nothing;
|
|
1326
|
+
* a day and a time of day (either may be absent), with the offset a
|
|
1327
|
+
* pasted ISO text named; or why it cannot be read.
|
|
1328
|
+
*/
|
|
1329
|
+
type DateTextReading = {
|
|
1330
|
+
readonly kind: "empty";
|
|
1331
|
+
} | {
|
|
1332
|
+
readonly kind: "read";
|
|
1333
|
+
readonly date: PlainDate | null;
|
|
1334
|
+
readonly time: PlainTime | null;
|
|
1335
|
+
/** Minutes east of UTC a pasted text gave ("Z", "+01:00"); `null` without one. */
|
|
1336
|
+
readonly offset: number | null;
|
|
1337
|
+
readonly info: DateReadingInfo;
|
|
1338
|
+
} | {
|
|
1339
|
+
readonly kind: "unreadable";
|
|
1340
|
+
readonly reason: DateUnreadableReason;
|
|
1341
|
+
};
|
|
1342
|
+
/** What the two-digit year pivot is told. */
|
|
1343
|
+
interface PivotOptions {
|
|
1344
|
+
/** Its year is the current year. */
|
|
1345
|
+
readonly today: PlainDate;
|
|
1346
|
+
/** A year after `max`'s takes the century before. */
|
|
1347
|
+
readonly max?: PlainDate | null | undefined;
|
|
1348
|
+
/** A year before `min`'s takes the century after. */
|
|
1349
|
+
readonly min?: PlainDate | null | undefined;
|
|
1350
|
+
}
|
|
1351
|
+
/** What the readers need to know about the field. */
|
|
1352
|
+
interface DateReadOptions extends PivotOptions {
|
|
1353
|
+
/** What the field holds: a day, a time of day, or both. */
|
|
1354
|
+
readonly fields: "date" | "time" | "dateTime";
|
|
1355
|
+
/** The field's layout: its order and day periods. */
|
|
1356
|
+
readonly layout: DateLayout;
|
|
1357
|
+
/** For month and weekday names; English names are read too. */
|
|
1358
|
+
readonly locale: Intl.LocalesArgument;
|
|
1359
|
+
/** Whether `t`, `+3` and the rest read. */
|
|
1360
|
+
readonly shortcuts: boolean;
|
|
1361
|
+
/**
|
|
1362
|
+
* The segment the user is typing in, if any: a short year there is
|
|
1363
|
+
* still being typed, so it reads as incomplete rather than pivoted.
|
|
1364
|
+
*/
|
|
1365
|
+
readonly activeSegment?: number | null | undefined;
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* The year ending in `digits` (one or two digits) within the hundred
|
|
1369
|
+
* years from 80 before the current year (ICU's rule): in 2026, 26 is 2026,
|
|
1370
|
+
* 45 is 2045, 46 is 1946. A year after `max`'s takes the century before,
|
|
1371
|
+
* one before `min`'s the century after, so a birthday field whose `max`
|
|
1372
|
+
* is today reads 36 as 1936.
|
|
1373
|
+
*/
|
|
1374
|
+
declare function pivotYear(digits: number, options: PivotOptions): number;
|
|
1375
|
+
/**
|
|
1376
|
+
* The time of day a field's segments hold once every time segment is
|
|
1377
|
+
* filled, whatever its date segments hold: a date-time field keeps it when
|
|
1378
|
+
* a shortcut sets the date. `null` for text that is not segments, a layout
|
|
1379
|
+
* without time segments, or a time not yet complete.
|
|
1380
|
+
*/
|
|
1381
|
+
declare function segmentsTime(layout: DateLayout, text: string): PlainTime | null;
|
|
1382
|
+
/**
|
|
1383
|
+
* A time of day read leniently: "15:05", "15.05", "1505", "15 h 05",
|
|
1384
|
+
* "3:05 PM", "3:05pm", "3 pm", "15:05:09.250", the locale's day-period
|
|
1385
|
+
* texts before or after it ("오후 3:05") or English `am`, `pm`, `a`, `p`.
|
|
1386
|
+
* An hour alone needs its day period. `null` for anything else.
|
|
1387
|
+
*/
|
|
1388
|
+
declare function readTimeText(text: string, layout: DateLayout): PlainTime | null;
|
|
1389
|
+
/**
|
|
1390
|
+
* A pasted or free text read whole, leniently:
|
|
1391
|
+
*
|
|
1392
|
+
* 1. Cleaned: trimmed, digits in any script as ASCII, direction marks
|
|
1393
|
+
* dropped, every kind of space a space.
|
|
1394
|
+
* 2. With shortcuts on, the shortcut grammar (`t`, `+3`, `-1me`).
|
|
1395
|
+
* 3. ISO: `2026-03-14`, `2026-03-14T15:05`, seconds and fractions
|
|
1396
|
+
* optional, a trailing `Z` or offset. A date field takes the day, a
|
|
1397
|
+
* time field the time.
|
|
1398
|
+
* 4. Eight digits: `YYYYMMDD` when that is a real day, else the locale's
|
|
1399
|
+
* order as 2-2-4.
|
|
1400
|
+
* 5. Three numbers with anything between: in the locale's order, except
|
|
1401
|
+
* that four digits first always means year, month, day.
|
|
1402
|
+
* 6. A month name with the day and year, weekday names passed over.
|
|
1403
|
+
* 7. A time after the date (or alone, in a time field): "15:05",
|
|
1404
|
+
* "3:05 PM", "3 pm", the locale's day periods or English ones.
|
|
1405
|
+
*
|
|
1406
|
+
* One- and two-digit years pivot (`pivotYear`). Anything else is
|
|
1407
|
+
* unreadable.
|
|
1408
|
+
*/
|
|
1409
|
+
declare function readDateText(text: string, options: DateReadOptions): DateTextReading;
|
|
1410
|
+
|
|
1411
|
+
/** Which moment a wall clock in a skipped or repeated hour means: Temporal's four answers. */
|
|
1412
|
+
type TimeZoneDisambiguation = "compatible" | "earlier" | "later" | "reject";
|
|
1413
|
+
/**
|
|
1414
|
+
* How a wall clock met a zone: as typed (`exact`); in an hour the clocks
|
|
1415
|
+
* skipped, read as `wallClock` (`skipped`); in an hour that happens twice,
|
|
1416
|
+
* read as one moment with the `other` beside it (`repeated`); or, with
|
|
1417
|
+
* `"reject"`, refused, with why.
|
|
1418
|
+
*/
|
|
1419
|
+
type ZonedReading = {
|
|
1420
|
+
readonly kind: "exact";
|
|
1421
|
+
readonly instant: Instant;
|
|
1422
|
+
} | {
|
|
1423
|
+
readonly kind: "skipped";
|
|
1424
|
+
readonly instant: Instant;
|
|
1425
|
+
readonly wallClock: PlainDateTime;
|
|
1426
|
+
} | {
|
|
1427
|
+
readonly kind: "repeated";
|
|
1428
|
+
readonly instant: Instant;
|
|
1429
|
+
readonly other: Instant;
|
|
1430
|
+
} | {
|
|
1431
|
+
readonly kind: "rejected";
|
|
1432
|
+
readonly reason: "skipped" | "repeated";
|
|
1433
|
+
};
|
|
1434
|
+
/**
|
|
1435
|
+
* The zone the runtime runs in. The one place forms-core reads it: only
|
|
1436
|
+
* an input whose prop says it defaults to the runtime's zone asks.
|
|
1437
|
+
*/
|
|
1438
|
+
declare function runtimeTimeZone(): string;
|
|
1439
|
+
/** Whether `name` is a time zone `Intl` knows ("Europe/Berlin", "UTC"). */
|
|
1440
|
+
declare function isTimeZone(name: string): boolean;
|
|
1441
|
+
/** The day it is in `timeZone` at `now` (milliseconds since the epoch). */
|
|
1442
|
+
declare function todayIn(timeZone: string, now: number): PlainDate;
|
|
1443
|
+
/** The wall clock in `timeZone` at `now` (milliseconds since the epoch). */
|
|
1444
|
+
declare function nowIn(timeZone: string, now: number): PlainDateTime;
|
|
1445
|
+
/** The wall clock `timeZone` shows at `instant`. */
|
|
1446
|
+
declare function wallClockOf(instant: Instant, timeZone: string): PlainDateTime;
|
|
1447
|
+
/** How far `timeZone` is from UTC at `instant`: "+01:00", "-08:00", "+05:30" (with seconds when it has them). */
|
|
1448
|
+
declare function offsetOf(instant: Instant, timeZone: string): string;
|
|
1449
|
+
/**
|
|
1450
|
+
* The moment `dateTime` is in `timeZone`. A candidate is the wall clock
|
|
1451
|
+
* less an offset the zone has on the day before or the day after it, kept
|
|
1452
|
+
* when the zone really has that offset at the candidate: two candidates
|
|
1453
|
+
* are a repeated hour, none a skipped one. `disambiguation` picks as
|
|
1454
|
+
* Temporal does: `"compatible"` (the default) takes the earlier of a
|
|
1455
|
+
* repeated hour and reads a skipped one with the offset from before the
|
|
1456
|
+
* change, so 02:30 on the night clocks go from 02:00 to 03:00 is 03:30;
|
|
1457
|
+
* `"earlier"` reads it with the offset after (01:30); `"later"` takes the
|
|
1458
|
+
* later of a repeated hour; `"reject"` refuses both. Throws a
|
|
1459
|
+
* `RangeError` for a moment outside the years 1 to 9999.
|
|
1460
|
+
*/
|
|
1461
|
+
declare function instantOf(dateTime: PlainDateTime, timeZone: string, disambiguation?: TimeZoneDisambiguation): ZonedReading;
|
|
1462
|
+
/**
|
|
1463
|
+
* The moment `dateTime` is in `timeZone`, by `disambiguation`; where it
|
|
1464
|
+
* would refuse (`"reject"`), as `"compatible"` reads it. For measuring a
|
|
1465
|
+
* span between wall clocks, which needs a moment either way.
|
|
1466
|
+
*/
|
|
1467
|
+
declare function exactInstantOf(dateTime: PlainDateTime, timeZone: string, disambiguation?: TimeZoneDisambiguation): Instant;
|
|
1468
|
+
/**
|
|
1469
|
+
* The moment `date` starts in `timeZone`: its midnight, or the first
|
|
1470
|
+
* moment after it when the clocks skipped midnight (01:00 that day).
|
|
1471
|
+
*/
|
|
1472
|
+
declare function startOfDayIn(date: PlainDate, timeZone: string): Instant;
|
|
1473
|
+
|
|
1474
|
+
/** What a date input adds to every event it fires. */
|
|
1475
|
+
interface DateDetails {
|
|
1476
|
+
/** The day as a JS `Date` at local midnight, as the grid reads a day; `null` when empty. */
|
|
1477
|
+
readonly date: Date | null;
|
|
1478
|
+
/** The value as display mode writes it; `""` when empty. */
|
|
1479
|
+
readonly formatted: string;
|
|
1480
|
+
/** The segment the edit was in; `null` for a paste, a pick or a change from code. */
|
|
1481
|
+
readonly segment: DateSegmentType | null;
|
|
1482
|
+
/** The shortcut typed ("t", "+3", "-1me"); `null` otherwise. */
|
|
1483
|
+
readonly shortcut: string | null;
|
|
1484
|
+
/** How the text on screen reads; `null` while it shows the value. */
|
|
1485
|
+
readonly reading: DateReadingInfo | null;
|
|
1486
|
+
}
|
|
1487
|
+
/** What a time input adds to every event. */
|
|
1488
|
+
type TimeDetails = Omit<DateDetails, "date" | "shortcut">;
|
|
1489
|
+
/** What a date-time input adds to every event. */
|
|
1490
|
+
interface DateTimeDetails extends DateDetails {
|
|
1491
|
+
/** For an instant: how the wall clock was read in the zone; `null` for a local date-time. */
|
|
1492
|
+
readonly zone: {
|
|
1493
|
+
readonly reading: "exact" | "skipped" | "repeated";
|
|
1494
|
+
readonly offset: string;
|
|
1495
|
+
} | null;
|
|
1496
|
+
}
|
|
1497
|
+
/** What every date, time and date-time field is told. */
|
|
1498
|
+
interface SegmentedFieldOptions {
|
|
1499
|
+
/** The field's locale unless given. */
|
|
1500
|
+
readonly locale?: Intl.LocalesArgument;
|
|
1501
|
+
/** The digits segments show; the locale's by default. */
|
|
1502
|
+
readonly numberingSystem?: string | undefined;
|
|
1503
|
+
/** How display mode writes the value; `Intl` styles by default. */
|
|
1504
|
+
readonly displayFormat?: Intl.DateTimeFormatOptions | undefined;
|
|
1505
|
+
/** The segment the user is typing in, if any, which a renderer knows: a short year there is not pivoted yet. */
|
|
1506
|
+
readonly activeSegment?: (() => number | null) | undefined;
|
|
1507
|
+
}
|
|
1508
|
+
/** How a date field reads and writes. */
|
|
1509
|
+
interface DateFieldOptions extends SegmentedFieldOptions {
|
|
1510
|
+
/** Today in the field's zone: shortcuts count from it, and the year pivot. */
|
|
1511
|
+
readonly today: () => PlainDate;
|
|
1512
|
+
/** Typing "t", "+3", "-1w", "s", "e"; on by default. */
|
|
1513
|
+
readonly shortcuts?: boolean | undefined;
|
|
1514
|
+
/** The limits, which the two-digit year pivot respects. */
|
|
1515
|
+
readonly min?: PlainDate | null | undefined;
|
|
1516
|
+
readonly max?: PlainDate | null | undefined;
|
|
1517
|
+
}
|
|
1518
|
+
/** How a time field reads and writes. */
|
|
1519
|
+
interface TimeFieldOptions extends SegmentedFieldOptions {
|
|
1520
|
+
/** The locale's hour cycle unless given. */
|
|
1521
|
+
readonly hourCycle?: "h12" | "h23" | undefined;
|
|
1522
|
+
/** `"minute"` by default; `"second"` keeps seconds. */
|
|
1523
|
+
readonly precision?: "minute" | "second" | undefined;
|
|
1524
|
+
}
|
|
1525
|
+
/** How a local date-time field reads and writes. */
|
|
1526
|
+
interface DateTimeFieldOptions extends Omit<DateFieldOptions, "min" | "max">, Omit<TimeFieldOptions, keyof SegmentedFieldOptions> {
|
|
1527
|
+
/** The time a date gets when its time is left empty; "00:00" by default. */
|
|
1528
|
+
readonly defaultTime?: PlainTime | undefined;
|
|
1529
|
+
readonly min?: PlainDateTime | null | undefined;
|
|
1530
|
+
readonly max?: PlainDateTime | null | undefined;
|
|
1531
|
+
}
|
|
1532
|
+
/** How an instant field reads and writes: wall clocks in `timeZone`. */
|
|
1533
|
+
interface InstantFieldOptions extends Omit<DateTimeFieldOptions, "min" | "max"> {
|
|
1534
|
+
readonly timeZone: string;
|
|
1535
|
+
/** Which moment a wall clock in a skipped or repeated hour means; `"compatible"` by default. */
|
|
1536
|
+
readonly disambiguation?: TimeZoneDisambiguation | undefined;
|
|
1537
|
+
readonly min?: Instant | null | undefined;
|
|
1538
|
+
readonly max?: Instant | null | undefined;
|
|
1539
|
+
}
|
|
1540
|
+
/** A day written in a date layout's segments: "03/14/2026", "14.03.2026". */
|
|
1541
|
+
declare function formatDateSegments(layout: DateLayout, date: PlainDate): string;
|
|
1542
|
+
/** A time of day written in a time layout's segments: "3:05 PM", "15:05". */
|
|
1543
|
+
declare function formatTimeSegments(layout: DateLayout, time: PlainTime): string;
|
|
1544
|
+
/** A wall clock written in a date-time layout's segments: "03/14/2026, 3:05 PM". */
|
|
1545
|
+
declare function formatDateTimeSegments(layout: DateLayout, dateTime: PlainDateTime): string;
|
|
1546
|
+
/**
|
|
1547
|
+
* A date field's own reading: its segments strictly, pasted and free text
|
|
1548
|
+
* leniently (shortcuts, ISO, numbers in the locale's order, month names),
|
|
1549
|
+
* empty as `null`, with the messages for text that is incomplete, a day
|
|
1550
|
+
* that does not exist, a three-digit year, or text that is no date ("Enter
|
|
1551
|
+
* a date such as 03/14/2026", today in the field's segments).
|
|
1552
|
+
*/
|
|
1553
|
+
declare function dateParser(options: DateFieldOptions): (text: string, context: ParseContext<PlainDate>) => ParseResult<PlainDate>;
|
|
1554
|
+
/** A date field's own writing: the day in its segments, whatever the purpose; `""` for `null`. */
|
|
1555
|
+
declare function dateFormatter(options?: Pick<DateFieldOptions, "locale" | "numberingSystem">): (value: PlainDate | null, context: FormatContext<PlainDate>) => string;
|
|
1556
|
+
/** What a date field's events carry, for its state and the event's cause. */
|
|
1557
|
+
declare function dateDetails(state: FieldState<PlainDate>, cause: ChangeCause<unknown> | null, options: DateFieldOptions & {
|
|
1558
|
+
readonly locale: Intl.LocalesArgument;
|
|
1559
|
+
readonly messages: FormsMessages;
|
|
1560
|
+
}): DateDetails;
|
|
1561
|
+
/**
|
|
1562
|
+
* A time field's own reading: its segments strictly, pasted and free text
|
|
1563
|
+
* leniently ("15:05", "3:05 PM", "1505", an ISO date-time's time), at the
|
|
1564
|
+
* field's precision; empty as `null`.
|
|
1565
|
+
*/
|
|
1566
|
+
declare function timeParser(options?: TimeFieldOptions): (text: string, context: ParseContext<PlainTime>) => ParseResult<PlainTime>;
|
|
1567
|
+
/** A time field's own writing: the time in its segments; `""` for `null`. */
|
|
1568
|
+
declare function timeFormatter(options?: TimeFieldOptions): (value: PlainTime | null, context: FormatContext<PlainTime>) => string;
|
|
1569
|
+
/** What a time field's events carry. */
|
|
1570
|
+
declare function timeDetails(state: FieldState<PlainTime>, cause: ChangeCause<unknown> | null, options: TimeFieldOptions & {
|
|
1571
|
+
readonly locale: Intl.LocalesArgument;
|
|
1572
|
+
readonly messages: FormsMessages;
|
|
1573
|
+
}): TimeDetails;
|
|
1574
|
+
/**
|
|
1575
|
+
* A local date-time field's own reading: as `dateParser` reads the date
|
|
1576
|
+
* and `timeParser` the time; a date whose time is left empty takes
|
|
1577
|
+
* `defaultTime`; a pasted offset is dropped, the wall clock kept.
|
|
1578
|
+
*/
|
|
1579
|
+
declare function dateTimeParser(options: DateTimeFieldOptions): (text: string, context: ParseContext<PlainDateTime>) => ParseResult<PlainDateTime>;
|
|
1580
|
+
/** A local date-time field's own writing: the wall clock in its segments; `""` for `null`. */
|
|
1581
|
+
declare function dateTimeFormatter(options?: Omit<TimeFieldOptions, "displayFormat">): (value: PlainDateTime | null, context: FormatContext<PlainDateTime>) => string;
|
|
1582
|
+
/** What a local date-time field's events carry; `date` is the wall clock as a local `Date`. */
|
|
1583
|
+
declare function dateTimeDetails(state: FieldState<PlainDateTime>, cause: ChangeCause<unknown> | null, options: DateTimeFieldOptions & {
|
|
1584
|
+
readonly locale: Intl.LocalesArgument;
|
|
1585
|
+
readonly messages: FormsMessages;
|
|
1586
|
+
}): DateTimeDetails;
|
|
1587
|
+
/**
|
|
1588
|
+
* An instant field's own reading: the wall clock as a local date-time
|
|
1589
|
+
* field reads it, then the moment it is in `timeZone` by
|
|
1590
|
+
* `disambiguation`; a pasted text with an offset is that moment exactly.
|
|
1591
|
+
* A wall clock `"reject"` refuses is unreadable ("02:30 doesn't exist
|
|
1592
|
+
* here: clocks go forward").
|
|
1593
|
+
*/
|
|
1594
|
+
declare function instantParser(options: InstantFieldOptions): (text: string, context: ParseContext<Instant>) => ParseResult<Instant>;
|
|
1595
|
+
/** An instant field's own writing: its wall clock in `timeZone`, in the field's segments; `""` for `null`. */
|
|
1596
|
+
declare function instantFormatter(options: Pick<InstantFieldOptions, "timeZone"> & Omit<TimeFieldOptions, "displayFormat">): (value: Instant | null, context: FormatContext<Instant>) => string;
|
|
1597
|
+
/**
|
|
1598
|
+
* What an instant field's events carry: `date` is the exact `Date`;
|
|
1599
|
+
* `zone` says how the wall clock shown was read in the zone (a skipped
|
|
1600
|
+
* hour read as the hour after, a repeated one) and the offset it has.
|
|
1601
|
+
*/
|
|
1602
|
+
declare function instantDetails(state: FieldState<Instant>, cause: ChangeCause<unknown> | null, options: InstantFieldOptions & {
|
|
1603
|
+
readonly locale: Intl.LocalesArgument;
|
|
1604
|
+
readonly messages: FormsMessages;
|
|
1605
|
+
}): DateTimeDetails;
|
|
1606
|
+
/**
|
|
1607
|
+
* The info message an instant field shows while the wall clock in `text`
|
|
1608
|
+
* falls in an hour its zone skips ("Clocks go forward here: 02:30 is read
|
|
1609
|
+
* as 03:30") or repeats ("02:30 happens twice; read as GMT+02:00"), times
|
|
1610
|
+
* as display mode writes them; `null` for any other text, a text with an
|
|
1611
|
+
* offset of its own included.
|
|
1612
|
+
*/
|
|
1613
|
+
declare function instantZoneMessage(text: string, options: InstantFieldOptions & {
|
|
1614
|
+
readonly locale: Intl.LocalesArgument;
|
|
1615
|
+
readonly messages: FormsMessages;
|
|
1616
|
+
}): string | null;
|
|
1617
|
+
|
|
1618
|
+
/** What a validator knows beside the value. */
|
|
1619
|
+
interface ValidatorContext {
|
|
1620
|
+
/** The text the field shows. */
|
|
1621
|
+
readonly text: string;
|
|
1622
|
+
readonly locale: Intl.LocalesArgument;
|
|
1623
|
+
readonly messages: FormsMessages;
|
|
1624
|
+
}
|
|
1625
|
+
/** What a validator returns: one message or several, `null` or nothing when the value is fine. */
|
|
1626
|
+
type ValidationResult = FieldMessageInput | readonly FieldMessageInput[] | null | undefined;
|
|
1627
|
+
/**
|
|
1628
|
+
* Checks a value. Called with every value, `null` included, after each
|
|
1629
|
+
* change, so it must be synchronous and cheap: anything slow or remote
|
|
1630
|
+
* belongs in `onBeforeCommit`. A string it returns is an error; a message
|
|
1631
|
+
* with another severity is shown and never blocks.
|
|
1632
|
+
*/
|
|
1633
|
+
type Validator<V> = (value: V | null, context: ValidatorContext) => ValidationResult;
|
|
1634
|
+
/** `null`, or a string of only whitespace, is `messages.required`. */
|
|
1635
|
+
declare function requiredRule<V>(): Validator<V>;
|
|
1636
|
+
/** Fewer than `min` code points is `messages.tooShort`. `null` passes. */
|
|
1637
|
+
declare function minLengthRule(min: number): Validator<string>;
|
|
1638
|
+
/** More than `max` code points is `messages.tooLong`. `null` passes. */
|
|
1639
|
+
declare function maxLengthRule(max: number): Validator<string>;
|
|
1640
|
+
/**
|
|
1641
|
+
* The whole value must match `pattern`, as the HTML `pattern` attribute
|
|
1642
|
+
* reads it; `message` replaces `messages.patternMismatch`. `null` passes.
|
|
1643
|
+
*/
|
|
1644
|
+
declare function patternRule(pattern: RegExp, message?: string): Validator<string>;
|
|
1645
|
+
/**
|
|
1646
|
+
* Anything but `true` is the message `message` picks from the catalogue:
|
|
1647
|
+
* a required checkbox (`requiredChecked`) or switch (`requiredOn`).
|
|
1648
|
+
*/
|
|
1649
|
+
declare function checkedRule(message: (messages: FormsMessages) => string): Validator<boolean>;
|
|
1650
|
+
|
|
1651
|
+
/** Writes a span for a message: "10", "14 days". */
|
|
1652
|
+
type SpanFormatter<S> = (span: S, context: ValidatorContext) => string;
|
|
1653
|
+
/**
|
|
1654
|
+
* A range shorter than `minSpan`, measured by the kind, is
|
|
1655
|
+
* `messages.rangeTooShort`, with `minSpan` written by `formatSpan`.
|
|
1656
|
+
* `context` gives the kind's context when the rule runs. A range with an
|
|
1657
|
+
* open end, and `null`, pass.
|
|
1658
|
+
*/
|
|
1659
|
+
declare function minSpanRule<T, F extends object, S, C, R>(kind: RangeKind<T, F, S, C, R>, minSpan: S, context: () => C, formatSpan: SpanFormatter<S>): Validator<Range<T, F>>;
|
|
1660
|
+
/** A range longer than `maxSpan` is `messages.rangeTooLong`; otherwise as `minSpanRule`. */
|
|
1661
|
+
declare function maxSpanRule<T, F extends object, S, C, R>(kind: RangeKind<T, F, S, C, R>, maxSpan: S, context: () => C, formatSpan: SpanFormatter<S>): Validator<Range<T, F>>;
|
|
1662
|
+
/**
|
|
1663
|
+
* Runs `rule`, a check of one value, on each present end of a range: a
|
|
1664
|
+
* number range's `min` and `max` bound both ends. A message both ends
|
|
1665
|
+
* earn is given once. Open ends and `null` pass.
|
|
1666
|
+
*/
|
|
1667
|
+
declare function endsRule<T, F extends object>(rule: Validator<T>): Validator<Range<T, F>>;
|
|
1668
|
+
|
|
1669
|
+
/** A range of days, stored half-open: `end` is the day after the last. */
|
|
1670
|
+
type DateRange = Range<PlainDate>;
|
|
1671
|
+
/** A time range's flag: its end is on the day after its start (22:00 to 06:00). */
|
|
1672
|
+
interface OvernightFlags {
|
|
1673
|
+
readonly overnight: boolean;
|
|
1674
|
+
}
|
|
1675
|
+
/** A range of times of day, which may cross midnight. */
|
|
1676
|
+
type TimeRange = Range<PlainTime, OvernightFlags>;
|
|
1677
|
+
/** What a time range kind is told: whether an end before its start means the next day. */
|
|
1678
|
+
interface TimeRangeContext {
|
|
1679
|
+
readonly overnight: boolean;
|
|
1680
|
+
}
|
|
1681
|
+
/** A date-time range's one zone, with what its rules need. */
|
|
1682
|
+
interface ZonedRangeContext extends DateRuleContext {
|
|
1683
|
+
readonly timeZone: string;
|
|
1684
|
+
readonly disambiguation: TimeZoneDisambiguation;
|
|
1685
|
+
}
|
|
1686
|
+
/**
|
|
1687
|
+
* Days, stored half-open: the end shown is the last day, the end stored
|
|
1688
|
+
* the day after, so 1 to 31 March stores `end: "2026-04-01"` and one day
|
|
1689
|
+
* shown is not an empty range. Span in days. Its rules resolve against
|
|
1690
|
+
* today; two rules are one when they are equal by value.
|
|
1691
|
+
*/
|
|
1692
|
+
declare const dateRangeKind: RangeKind<PlainDate, NoFlags, number, DateRuleContext, RelativeDateRule>;
|
|
1693
|
+
/**
|
|
1694
|
+
* Times of day. An end before its start is the next day ("overnight")
|
|
1695
|
+
* when the context allows it, else reversed; a range ending at midnight
|
|
1696
|
+
* crosses into the next day too. The end shown is the end stored
|
|
1697
|
+
* (09:00 to 17:00 stores `end: "17:00"`). Span in wall-clock minutes.
|
|
1698
|
+
*/
|
|
1699
|
+
declare const timeRangeKind: RangeKind<PlainTime, OvernightFlags, number, TimeRangeContext>;
|
|
1700
|
+
/**
|
|
1701
|
+
* Wall clocks, measured in the range's one zone: 29 March 2026 in Berlin,
|
|
1702
|
+
* midnight to midnight, is 23 hours. The end shown is the end stored. A
|
|
1703
|
+
* rule resolves to the start of its days. Span in milliseconds.
|
|
1704
|
+
*/
|
|
1705
|
+
declare const dateTimeRangeKind: RangeKind<PlainDateTime, NoFlags, number, ZonedRangeContext, RelativeDateRule>;
|
|
1706
|
+
/**
|
|
1707
|
+
* Exact moments; the zone is the one they are typed in, and where a
|
|
1708
|
+
* rule's days start. Span in milliseconds.
|
|
1709
|
+
*/
|
|
1710
|
+
declare const instantRangeKind: RangeKind<Instant, NoFlags, number, ZonedRangeContext, RelativeDateRule>;
|
|
1711
|
+
/**
|
|
1712
|
+
* The days a date range input's value stands for now: its ends, or its
|
|
1713
|
+
* rule resolved against `context.today()`. For code that needs the days
|
|
1714
|
+
* outside an event (a grid filter at filter time), and to turn a rule
|
|
1715
|
+
* into fixed dates: `setValue(resolveDateRange(value, context))`.
|
|
1716
|
+
*/
|
|
1717
|
+
declare function resolveDateRange(value: RangeValue<PlainDate, NoFlags, RelativeDateRule>, context: DateRuleContext): DateRange;
|
|
1718
|
+
/** The times days picked in a calendar get: the start of the first day and the start of the day after the last, by default. */
|
|
1719
|
+
interface DefaultTimes {
|
|
1720
|
+
readonly start: PlainTime;
|
|
1721
|
+
readonly end: PlainTime;
|
|
1722
|
+
}
|
|
1723
|
+
/**
|
|
1724
|
+
* Days picked as a wall-clock range: the first day at `times.start`, the
|
|
1725
|
+
* stored end (the day after the last) at `times.end`. 29 March picked
|
|
1726
|
+
* alone is 29 March 00:00 to 30 March 00:00.
|
|
1727
|
+
*/
|
|
1728
|
+
declare function daysToDateTimeRange(days: DateRange, times?: DefaultTimes): Range<PlainDateTime>;
|
|
1729
|
+
/** Days picked as a range of moments in `timeZone`, as `daysToDateTimeRange` picks the wall clocks. */
|
|
1730
|
+
declare function daysToInstantRange(days: DateRange, timeZone: string, times?: DefaultTimes, disambiguation?: TimeZoneDisambiguation): Range<Instant>;
|
|
1731
|
+
/** How a range writes its display text. */
|
|
1732
|
+
interface RangeTextOptions {
|
|
1733
|
+
readonly locale: Intl.LocalesArgument;
|
|
1734
|
+
readonly messages: FormsMessages;
|
|
1735
|
+
readonly displayFormat?: Intl.DateTimeFormatOptions | undefined;
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* A date range as display mode writes it, inclusive: `formatRange` of the
|
|
1739
|
+
* start and the end shown ("Mar 1 – 31, 2026"), one day once ("Mar 14,
|
|
1740
|
+
* 2026"), and an open end as `messages.rangeFrom` or `rangeUpTo`.
|
|
1741
|
+
*/
|
|
1742
|
+
declare function formatDateRange(range: DateRange, options: RangeTextOptions & {
|
|
1743
|
+
readonly bounds?: RangeBounds | undefined;
|
|
1744
|
+
}): string;
|
|
1745
|
+
/**
|
|
1746
|
+
* A time range as display mode writes it: the two times joined by
|
|
1747
|
+
* `messages.rangeSeparator`, with `messages.rangeNextDay` after an
|
|
1748
|
+
* overnight end ("22:00 – 06:00 +1"); an open end as `rangeFrom` or
|
|
1749
|
+
* `rangeUpTo`. `formatRange` is not used: for times on two days it writes
|
|
1750
|
+
* the dates too.
|
|
1751
|
+
*/
|
|
1752
|
+
declare function formatTimeRange(range: TimeRange, options: RangeTextOptions): string;
|
|
1753
|
+
/** A length of time for span limits, a day being 24 hours: `{ days: 31 }`, `{ hours: 1 }`. */
|
|
1754
|
+
interface DurationLike {
|
|
1755
|
+
readonly weeks?: number | undefined;
|
|
1756
|
+
readonly days?: number | undefined;
|
|
1757
|
+
readonly hours?: number | undefined;
|
|
1758
|
+
readonly minutes?: number | undefined;
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* `duration` in the span unit of a range kind, for `minSpan` and
|
|
1762
|
+
* `maxSpan`: days for a date range, minutes for a time range,
|
|
1763
|
+
* milliseconds for a date-time or instant range.
|
|
1764
|
+
*/
|
|
1765
|
+
declare function spanOf(duration: DurationLike, unit: "day" | "minute" | "millisecond"): number;
|
|
1766
|
+
/** A number of days as words in the validator's locale: "31 days", "31 Tage". A `SpanFormatter` for date ranges. */
|
|
1767
|
+
declare const formatDaySpan: SpanFormatter<number>;
|
|
1768
|
+
/**
|
|
1769
|
+
* A length of time in milliseconds as words, through `Intl.DurationFormat`
|
|
1770
|
+
* with `style: "short"`: hours and minutes under 48 hours ("8 hr", "1 hr,
|
|
1771
|
+
* 30 min"), days and hours from 48 ("3 days, 2 hr"). A `SpanFormatter`
|
|
1772
|
+
* for date-time and instant ranges; a time range's minutes times 60,000.
|
|
1773
|
+
*/
|
|
1774
|
+
declare const formatTimeSpan: SpanFormatter<number>;
|
|
1775
|
+
|
|
1776
|
+
/** The unit a duration's value is held in. */
|
|
1777
|
+
type DurationUnit = "millisecond" | "second" | "minute" | "hour";
|
|
1778
|
+
/** How a duration is written: `"units"` ("1h 30m"), `"clock"` ("1:30") or `"decimal"` hours ("1.5"). */
|
|
1779
|
+
type DurationNotation = "units" | "clock" | "decimal";
|
|
1780
|
+
/** How a duration field reads and writes. */
|
|
1781
|
+
interface DurationOptions {
|
|
1782
|
+
/** The field's locale unless given. */
|
|
1783
|
+
readonly locale?: Intl.LocalesArgument;
|
|
1784
|
+
/** The unit the value is held in; `"minute"` by default, so timesheet values stay whole. */
|
|
1785
|
+
readonly valueUnit?: DurationUnit | undefined;
|
|
1786
|
+
/** What a bare number means: `"hour"` by default, so "1.5" is an hour and a half. */
|
|
1787
|
+
readonly inputUnit?: "minute" | "hour" | undefined;
|
|
1788
|
+
/** The smallest part that can be typed; finer parts round half up to it. `"minute"` by default. */
|
|
1789
|
+
readonly precision?: "minute" | "second" | undefined;
|
|
1790
|
+
/** How the value is written; `"units"` by default. */
|
|
1791
|
+
readonly notation?: DurationNotation | undefined;
|
|
1792
|
+
/** How many hours a day (`d`) is: 24 by default, 8 for a working day. */
|
|
1793
|
+
readonly hoursPerDay?: number | undefined;
|
|
1794
|
+
/** Whether a duration may be negative. */
|
|
1795
|
+
readonly allowNegative?: boolean | undefined;
|
|
1796
|
+
}
|
|
1797
|
+
/** What a duration text reads as: nothing, a value in the value unit, or why it cannot be read. */
|
|
1798
|
+
type DurationReading = {
|
|
1799
|
+
readonly kind: "empty";
|
|
1800
|
+
} | {
|
|
1801
|
+
readonly kind: "duration";
|
|
1802
|
+
readonly value: number;
|
|
1803
|
+
} | {
|
|
1804
|
+
readonly kind: "unreadable";
|
|
1805
|
+
readonly reason: "negative" | "unreadable";
|
|
1806
|
+
};
|
|
1807
|
+
/**
|
|
1808
|
+
* Reads a duration: `units` ("1h 30m", "1h30m", "90m", "2d 4h", and "1h30",
|
|
1809
|
+
* a bare number after an hour being minutes; unit words in the locale or
|
|
1810
|
+
* English, any case; minutes over 59 allowed), `clock` ("1:30", "26:15",
|
|
1811
|
+
* seconds optional; minutes and seconds up to 59), or a bare number in
|
|
1812
|
+
* `inputUnit` (hours by default: "1.5" is 90 minutes). Digits in any
|
|
1813
|
+
* script; the locale's decimal separator or "."; `d` is `hoursPerDay`
|
|
1814
|
+
* hours. A sign only with `allowNegative`. The value is rounded half up to
|
|
1815
|
+
* the precision and held in `valueUnit`.
|
|
1816
|
+
*/
|
|
1817
|
+
declare function parseDuration(text: string, options?: DurationOptions): DurationReading;
|
|
1818
|
+
/**
|
|
1819
|
+
* Writes a duration held in `valueUnit`, rounded to the precision:
|
|
1820
|
+
* `"units"` through `Intl.DurationFormat` with `style: "narrow"` ("1h
|
|
1821
|
+
* 30m" in `en-US`; hours are not gathered into days), `"clock"` as hours
|
|
1822
|
+
* and minutes ("1:30", "26:15", seconds with `precision: "second"`), or
|
|
1823
|
+
* `"decimal"` hours with up to two fraction digits ("1.5", "1,5").
|
|
1824
|
+
*/
|
|
1825
|
+
declare function formatDuration(value: number, options?: DurationOptions): string;
|
|
1826
|
+
/**
|
|
1827
|
+
* A duration field's own reading, `parseDuration` in the field's locale:
|
|
1828
|
+
* empty as `null`; "Enter a duration of zero or more" for a sign the
|
|
1829
|
+
* field takes none of; "Enter a duration such as 1h 30m" otherwise.
|
|
1830
|
+
*/
|
|
1831
|
+
declare function durationParser(options?: DurationOptions): (text: string, context: ParseContext<number>) => ParseResult<number>;
|
|
1832
|
+
/** A duration field's own writing, the same whatever the purpose: `formatDuration` in the field's locale; `""` for `null`. */
|
|
1833
|
+
declare function durationFormatter(options?: DurationOptions): (value: number | null, context: FormatContext<number>) => string;
|
|
1834
|
+
/** `value` held in `from`, held in `to` instead: 90 minutes is 1.5 hours. */
|
|
1835
|
+
declare function convertDuration(value: number, from: DurationUnit, to: DurationUnit): number;
|
|
1836
|
+
/**
|
|
1837
|
+
* A duration under `min`, held in `options.valueUnit`, is
|
|
1838
|
+
* `messages.rangeUnderflow`, "Enter 15m or more", the limit written as
|
|
1839
|
+
* the field writes durations. Inclusive; `null` passes.
|
|
1840
|
+
*/
|
|
1841
|
+
declare function minDurationRule(min: number, options?: DurationOptions): Validator<number>;
|
|
1842
|
+
/** A duration over `max` is `messages.rangeOverflow`, "Enter 8h or less"; otherwise as `minDurationRule`. */
|
|
1843
|
+
declare function maxDurationRule(max: number, options?: DurationOptions): Validator<number>;
|
|
1844
|
+
/** What a duration input adds to every event. */
|
|
1845
|
+
interface DurationDetails {
|
|
1846
|
+
/** The value as display mode writes it; `""` when empty. */
|
|
1847
|
+
readonly formatted: string;
|
|
1848
|
+
/** The value in minutes, whatever `valueUnit` is; `null` when empty. */
|
|
1849
|
+
readonly minutes: number | null;
|
|
1850
|
+
}
|
|
1851
|
+
/** What a duration field's events carry. `options` holds the field's locale. */
|
|
1852
|
+
declare function durationDetails(state: FieldState<number>, options: DurationOptions): DurationDetails;
|
|
1853
|
+
|
|
1854
|
+
/** A day as display mode writes it: `dateStyle: "medium"` unless `options` say otherwise ("Mar 14, 2026", "14.03.2026"). */
|
|
1855
|
+
declare function formatDate(date: PlainDate, locale: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
1856
|
+
/** A time of day as display mode writes it: `timeStyle: "short"`, `"medium"` with seconds, unless `options` say otherwise. */
|
|
1857
|
+
declare function formatTime(time: PlainTime, locale: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
1858
|
+
/** A wall clock as display mode writes it: the date and time styles together unless `options` say otherwise. */
|
|
1859
|
+
declare function formatDateTime(dateTime: PlainDateTime, locale: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
1860
|
+
/** A moment as display mode writes it in `timeZone`, as `formatDateTime` writes its wall clock. */
|
|
1861
|
+
declare function formatInstant(instant: Instant, timeZone: string, locale: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
1862
|
+
|
|
1863
|
+
/** A month: "2026-11". */
|
|
1864
|
+
type MonthPeriod = `${number}-${number}`;
|
|
1865
|
+
/** A calendar quarter: "2026-Q3". */
|
|
1866
|
+
type QuarterPeriod = `${number}-Q${number}`;
|
|
1867
|
+
/** A calendar year: "2026". */
|
|
1868
|
+
type YearPeriod = `${number}`;
|
|
1869
|
+
/** A fiscal year, named by the year it ends in unless told otherwise: "FY2026". */
|
|
1870
|
+
type FiscalYearPeriod = `FY${number}`;
|
|
1871
|
+
/** A quarter of a fiscal year: "FY2026-Q1". */
|
|
1872
|
+
type FiscalQuarterPeriod = `FY${number}-Q${number}`;
|
|
1873
|
+
/** A month of a fiscal year, P01 to P12: "FY2026-P04". */
|
|
1874
|
+
type FiscalMonthPeriod = `FY${number}-P${number}`;
|
|
1875
|
+
/** How long a period is. */
|
|
1876
|
+
type PeriodGranularity = "month" | "quarter" | "year" | "fiscalMonth" | "fiscalQuarter" | "fiscalYear";
|
|
1877
|
+
/** The value type of each granularity. */
|
|
1878
|
+
interface PeriodValues {
|
|
1879
|
+
readonly month: MonthPeriod;
|
|
1880
|
+
readonly quarter: QuarterPeriod;
|
|
1881
|
+
readonly year: YearPeriod;
|
|
1882
|
+
readonly fiscalMonth: FiscalMonthPeriod;
|
|
1883
|
+
readonly fiscalQuarter: FiscalQuarterPeriod;
|
|
1884
|
+
readonly fiscalYear: FiscalYearPeriod;
|
|
1885
|
+
}
|
|
1886
|
+
/** An accounting or reporting period, as a string: one of `PeriodValues`. */
|
|
1887
|
+
type Period<G extends PeriodGranularity = PeriodGranularity> = PeriodValues[G];
|
|
1888
|
+
/** Where a fiscal year starts and how it is named. */
|
|
1889
|
+
interface FiscalYear {
|
|
1890
|
+
/** The month it starts in, 1 to 12. */
|
|
1891
|
+
readonly start: number;
|
|
1892
|
+
/** Whether "FY2026" names the year it starts in or the year it ends in. */
|
|
1893
|
+
readonly namedBy: "start" | "end";
|
|
1894
|
+
}
|
|
1895
|
+
/** The calendar year as a fiscal year: from January, so both namings agree. */
|
|
1896
|
+
declare const CALENDAR_FISCAL_YEAR: FiscalYear;
|
|
1897
|
+
/** A period's numbers: its year (the fiscal year's name for a fiscal period) and its place in it, from 1. */
|
|
1898
|
+
interface PeriodParts {
|
|
1899
|
+
readonly granularity: PeriodGranularity;
|
|
1900
|
+
readonly year: number;
|
|
1901
|
+
readonly index: number;
|
|
1902
|
+
}
|
|
1903
|
+
/**
|
|
1904
|
+
* A period's granularity, year and place in that year, from 1: `2026-Q3`
|
|
1905
|
+
* is 2026 and 3, `FY2026-P04` fiscal year 2026 and 4. Throws a
|
|
1906
|
+
* `RangeError` for text that is not a period.
|
|
1907
|
+
*/
|
|
1908
|
+
declare function periodParts(period: Period): PeriodParts;
|
|
1909
|
+
/** `text` as a period of `granularity` when it is one in canonical form ("2026-11", "FY2026-P04"); `null` otherwise. */
|
|
1910
|
+
declare function toPeriod<G extends PeriodGranularity>(text: string, granularity: G): Period<G> | null;
|
|
1911
|
+
/** Whether `value` is a period in canonical form, of `granularity` when given. */
|
|
1912
|
+
declare function isPeriod(value: unknown, granularity?: PeriodGranularity): value is Period;
|
|
1913
|
+
/** A period's granularity. Throws a `RangeError` for text that is not a period. */
|
|
1914
|
+
declare function periodGranularity(period: Period): PeriodGranularity;
|
|
1915
|
+
/**
|
|
1916
|
+
* Negative when `a` comes first, 0 for the same period, positive after,
|
|
1917
|
+
* for two periods of one granularity; periods of different granularities
|
|
1918
|
+
* are ordered by their text.
|
|
1919
|
+
*/
|
|
1920
|
+
declare function comparePeriods(a: Period, b: Period): number;
|
|
1921
|
+
/** The period `count` periods after `period` (before, when negative). */
|
|
1922
|
+
declare function addPeriods<G extends PeriodGranularity>(period: Period<G>, count: number): Period<G>;
|
|
1923
|
+
/**
|
|
1924
|
+
* The days a period covers, half-open: `2026-11` is [2026-11-01,
|
|
1925
|
+
* 2026-12-01). A fiscal period counts from `fiscal`'s start month: with an
|
|
1926
|
+
* April start named by the year it ends in, `FY2026` is [2025-04-01,
|
|
1927
|
+
* 2026-04-01) and `FY2026-P04` is July 2025.
|
|
1928
|
+
*/
|
|
1929
|
+
declare function periodRange(period: Period, fiscal?: FiscalYear): Range<PlainDate>;
|
|
1930
|
+
/** The period of `granularity` that `date` falls in. */
|
|
1931
|
+
declare function periodOf<G extends PeriodGranularity>(date: PlainDate, granularity: G, fiscal?: FiscalYear): Period<G>;
|
|
1932
|
+
/** How a period field lays out its segments. */
|
|
1933
|
+
interface PeriodLayoutOptions {
|
|
1934
|
+
readonly locale: Intl.LocalesArgument;
|
|
1935
|
+
readonly granularity: PeriodGranularity;
|
|
1936
|
+
/** The digits segments show; the locale's by default. */
|
|
1937
|
+
readonly numberingSystem?: string | undefined;
|
|
1938
|
+
}
|
|
1939
|
+
/**
|
|
1940
|
+
* How a period field lays out its segments: a month as the locale writes
|
|
1941
|
+
* a month and year (`11/2026`, `2026/11`), a year alone, and the others
|
|
1942
|
+
* with the messages' prefixes as literals: `Q3 2026`, `FY2026`,
|
|
1943
|
+
* `FY2026 Q1`, `FY2026 P04`.
|
|
1944
|
+
*/
|
|
1945
|
+
declare function periodLayout(options: PeriodLayoutOptions, messages: FormsMessages): DateLayout;
|
|
1946
|
+
/** A period written in its layout's segments: "11/2026", "Q3 2026", "FY2026 P04". */
|
|
1947
|
+
declare function formatPeriodSegments(layout: DateLayout, period: Period): string;
|
|
1948
|
+
/**
|
|
1949
|
+
* A period as display mode writes it: a month by `Intl` ("November
|
|
1950
|
+
* 2026"), a year by `Intl`, the others with the messages' prefixes and the
|
|
1951
|
+
* locale's digits ("Q3 2026", "FY2026", "FY2026 Q1", "FY2026 P04").
|
|
1952
|
+
*/
|
|
1953
|
+
declare function formatPeriod(period: Period, locale: Intl.LocalesArgument, messages: FormsMessages): string;
|
|
1954
|
+
/** How many years a period picker's previous and next buttons move: 1, or 12 for years. */
|
|
1955
|
+
declare function periodPageYears(granularity: PeriodGranularity): number;
|
|
1956
|
+
/**
|
|
1957
|
+
* The periods a picker shows together on the page that holds `year`: that
|
|
1958
|
+
* year's months, quarters or fiscal periods, or for a year granularity the
|
|
1959
|
+
* twelve years around it (2017 to 2028 for 2026), within 1 to 9999.
|
|
1960
|
+
*/
|
|
1961
|
+
declare function periodPage<G extends PeriodGranularity>(granularity: G, year: number): readonly Period<G>[];
|
|
1962
|
+
/**
|
|
1963
|
+
* A period as a picker's button writes it, without the year its page
|
|
1964
|
+
* names: a month's short name by `Intl` ("Nov"), "Q3", "P04", or a year
|
|
1965
|
+
* ("2026", "FY2026"), in the locale's digits.
|
|
1966
|
+
*/
|
|
1967
|
+
declare function formatPeriodPlace(period: Period, locale: Intl.LocalesArgument, messages: FormsMessages): string;
|
|
1968
|
+
/**
|
|
1969
|
+
* The title of a period picker's page that holds `year`: the year
|
|
1970
|
+
* ("2026", "FY2026"), or for a year granularity its first and last years
|
|
1971
|
+
* ("2017 – 2028").
|
|
1972
|
+
*/
|
|
1973
|
+
declare function formatPeriodPage(granularity: PeriodGranularity, year: number, locale: Intl.LocalesArgument, messages: FormsMessages): string;
|
|
1974
|
+
/** How a period field reads and writes. */
|
|
1975
|
+
interface PeriodFieldOptions<G extends PeriodGranularity = "month"> {
|
|
1976
|
+
readonly granularity: G;
|
|
1977
|
+
/** The fiscal year's start and naming; the calendar year by default. */
|
|
1978
|
+
readonly fiscalYear?: FiscalYear | undefined;
|
|
1979
|
+
/** The field's locale unless given. */
|
|
1980
|
+
readonly locale?: Intl.LocalesArgument;
|
|
1981
|
+
readonly numberingSystem?: string | undefined;
|
|
1982
|
+
/** Today in the field's zone: `t`, `+1` and `-1` count from its period, and the year pivot. */
|
|
1983
|
+
readonly today: () => PlainDate;
|
|
1984
|
+
/** `t`, `+1` and `-1` for this, next and previous period; on by default. */
|
|
1985
|
+
readonly shortcuts?: boolean | undefined;
|
|
1986
|
+
/** The segment the user is typing in, if any: a short year there is not pivoted yet. */
|
|
1987
|
+
readonly activeSegment?: (() => number | null) | undefined;
|
|
1988
|
+
}
|
|
1989
|
+
/**
|
|
1990
|
+
* A period field's own reading: its segments strictly, pasted and free
|
|
1991
|
+
* text leniently (shortcuts, the canonical form, `Q3 2026`, `FY26 P4`,
|
|
1992
|
+
* `Nov 2026`); empty as `null`. Text that is no period says "Enter a
|
|
1993
|
+
* period such as Q4 2026", the current period in the field's segments.
|
|
1994
|
+
*/
|
|
1995
|
+
declare function periodParser<G extends PeriodGranularity>(options: PeriodFieldOptions<G>): (text: string, context: ParseContext<Period<G>>) => ParseResult<Period<G>>;
|
|
1996
|
+
/** A period field's own writing: the period in its segments, whatever the purpose; `""` for `null`. */
|
|
1997
|
+
declare function periodFormatter<G extends PeriodGranularity>(options: Pick<PeriodFieldOptions<G>, "granularity" | "locale" | "numberingSystem">): (value: Period<G> | null, context: FormatContext<Period<G>>) => string;
|
|
1998
|
+
/** What a period input adds to every event. */
|
|
1999
|
+
interface PeriodDetails {
|
|
2000
|
+
/** The days the period covers, half-open. `null` when empty. */
|
|
2001
|
+
readonly range: Range<PlainDate> | null;
|
|
2002
|
+
/** The value as display mode writes it; `""` when empty. */
|
|
2003
|
+
readonly formatted: string;
|
|
2004
|
+
/** The segment the edit was in; `null` for a paste, a pick or a change from code. */
|
|
2005
|
+
readonly segment: "year" | "month" | "quarter" | "period" | null;
|
|
2006
|
+
}
|
|
2007
|
+
/** What a period field's events carry, for its state and the event's cause. */
|
|
2008
|
+
declare function periodDetails<G extends PeriodGranularity>(state: FieldState<Period<G>>, cause: ChangeCause<unknown> | null, options: PeriodFieldOptions<G> & {
|
|
2009
|
+
readonly locale: Intl.LocalesArgument;
|
|
2010
|
+
readonly messages: FormsMessages;
|
|
2011
|
+
}): PeriodDetails;
|
|
2012
|
+
|
|
2013
|
+
/**
|
|
2014
|
+
* A day before `min` is `messages.tooEarly`, "Enter Mar 1, 2026 or later",
|
|
2015
|
+
* the limit in display form (`displayFormat`, the field's, else
|
|
2016
|
+
* `dateStyle: "medium"`) in the validator's locale. Inclusive; `null`
|
|
2017
|
+
* passes.
|
|
2018
|
+
*/
|
|
2019
|
+
declare function minDateRule(min: PlainDate, displayFormat?: Intl.DateTimeFormatOptions): Validator<PlainDate>;
|
|
2020
|
+
/** A day after `max` is `messages.tooLate`, "Enter Mar 31, 2026 or earlier"; otherwise as `minDateRule`. */
|
|
2021
|
+
declare function maxDateRule(max: PlainDate, displayFormat?: Intl.DateTimeFormatOptions): Validator<PlainDate>;
|
|
2022
|
+
/** A time of day before `min` is `messages.tooEarly`; as `minDateRule`. */
|
|
2023
|
+
declare function minTimeRule(min: PlainTime, displayFormat?: Intl.DateTimeFormatOptions): Validator<PlainTime>;
|
|
2024
|
+
/** A time of day after `max` is `messages.tooLate`; as `maxDateRule`. */
|
|
2025
|
+
declare function maxTimeRule(max: PlainTime, displayFormat?: Intl.DateTimeFormatOptions): Validator<PlainTime>;
|
|
2026
|
+
/** A wall clock before `min` is `messages.tooEarly`; as `minDateRule`. */
|
|
2027
|
+
declare function minDateTimeRule(min: PlainDateTime, displayFormat?: Intl.DateTimeFormatOptions): Validator<PlainDateTime>;
|
|
2028
|
+
/** A wall clock after `max` is `messages.tooLate`; as `maxDateRule`. */
|
|
2029
|
+
declare function maxDateTimeRule(max: PlainDateTime, displayFormat?: Intl.DateTimeFormatOptions): Validator<PlainDateTime>;
|
|
2030
|
+
/** A moment before `min` is `messages.tooEarly`, the limit written in `timeZone`; as `minDateRule`. */
|
|
2031
|
+
declare function minInstantRule(min: Instant, timeZone: string, displayFormat?: Intl.DateTimeFormatOptions): Validator<Instant>;
|
|
2032
|
+
/** A moment after `max` is `messages.tooLate`, the limit written in `timeZone`; as `maxDateRule`. */
|
|
2033
|
+
declare function maxInstantRule(max: Instant, timeZone: string, displayFormat?: Intl.DateTimeFormatOptions): Validator<Instant>;
|
|
2034
|
+
/**
|
|
2035
|
+
* A period before `min` is `messages.tooEarly`, "Enter Q2 2026 or later",
|
|
2036
|
+
* the limit as display mode writes it, in the validator's locale.
|
|
2037
|
+
* Inclusive; `null` passes.
|
|
2038
|
+
*/
|
|
2039
|
+
declare function minPeriodRule<G extends PeriodGranularity>(min: Period<G>): Validator<Period<G>>;
|
|
2040
|
+
/** A period after `max` is `messages.tooLate`; as `minPeriodRule`. */
|
|
2041
|
+
declare function maxPeriodRule<G extends PeriodGranularity>(max: Period<G>): Validator<Period<G>>;
|
|
2042
|
+
/**
|
|
2043
|
+
* A day `isDateDisabled` marks is `messages.dateUnavailable`, "This date
|
|
2044
|
+
* isn't available". For a wall clock, its day is checked. `null` passes.
|
|
2045
|
+
*/
|
|
2046
|
+
declare function availableDateRule<V extends PlainDate | PlainDateTime>(isDateDisabled: (date: PlainDate) => boolean): Validator<V>;
|
|
2047
|
+
|
|
2048
|
+
/**
|
|
2049
|
+
* Where picking a range of days in a calendar stands: nothing picked yet;
|
|
2050
|
+
* a first day chosen (the anchor), waiting for the other end while
|
|
2051
|
+
* `target`, the day under the pointer or focus, previews it; or a mouse or
|
|
2052
|
+
* pen pressed on a day and dragged to `target`. `fromAnchor` marks a press
|
|
2053
|
+
* made while an anchor was already set, which picks the other end even
|
|
2054
|
+
* when it lets go on the anchor itself.
|
|
2055
|
+
*/
|
|
2056
|
+
type RangePick = {
|
|
2057
|
+
readonly kind: "idle";
|
|
2058
|
+
} | {
|
|
2059
|
+
readonly kind: "anchored";
|
|
2060
|
+
readonly anchor: PlainDate;
|
|
2061
|
+
readonly target: PlainDate;
|
|
2062
|
+
} | {
|
|
2063
|
+
readonly kind: "dragging";
|
|
2064
|
+
readonly anchor: PlainDate;
|
|
2065
|
+
readonly target: PlainDate;
|
|
2066
|
+
readonly fromAnchor: boolean;
|
|
2067
|
+
};
|
|
2068
|
+
/** The days a range covers, both ends included and in order. */
|
|
2069
|
+
interface PickedDays {
|
|
2070
|
+
readonly first: PlainDate;
|
|
2071
|
+
readonly last: PlainDate;
|
|
2072
|
+
}
|
|
2073
|
+
/** What can happen while a range is picked. */
|
|
2074
|
+
type RangePickAction =
|
|
2075
|
+
/** A day clicked, tapped, or chosen with Enter or Space. */
|
|
2076
|
+
{
|
|
2077
|
+
readonly type: "choose";
|
|
2078
|
+
readonly date: PlainDate;
|
|
2079
|
+
}
|
|
2080
|
+
/** The pointer moved over a day, or focus moved to one. */
|
|
2081
|
+
| {
|
|
2082
|
+
readonly type: "preview";
|
|
2083
|
+
readonly date: PlainDate;
|
|
2084
|
+
}
|
|
2085
|
+
/** A mouse or pen pressed on a day. */
|
|
2086
|
+
| {
|
|
2087
|
+
readonly type: "press";
|
|
2088
|
+
readonly date: PlainDate;
|
|
2089
|
+
}
|
|
2090
|
+
/** That press let go. */
|
|
2091
|
+
| {
|
|
2092
|
+
readonly type: "release";
|
|
2093
|
+
}
|
|
2094
|
+
/** That press lost its pointer: cancelled, or its capture taken. */
|
|
2095
|
+
| {
|
|
2096
|
+
readonly type: "lose";
|
|
2097
|
+
}
|
|
2098
|
+
/** Escape: a range in progress is dropped. */
|
|
2099
|
+
| {
|
|
2100
|
+
readonly type: "cancel";
|
|
2101
|
+
};
|
|
2102
|
+
/** The picking state after an action, and the days it picked, if it finished a range. */
|
|
2103
|
+
interface RangePickStep {
|
|
2104
|
+
readonly state: RangePick;
|
|
2105
|
+
readonly picked: PickedDays | null;
|
|
2106
|
+
}
|
|
2107
|
+
/** `a` and `b` as a range's first and last days, whichever comes first. */
|
|
2108
|
+
declare function pickedDays(a: PlainDate, b: PlainDate): PickedDays;
|
|
2109
|
+
/** The days a range in progress would cover now: anchor to target. `null` while nothing is anchored. */
|
|
2110
|
+
declare function rangePickPreview(state: RangePick): PickedDays | null;
|
|
2111
|
+
/**
|
|
2112
|
+
* Picking a range of days after `action`. A choice sets the anchor, then
|
|
2113
|
+
* the other end, which finishes the range; a press and a release on
|
|
2114
|
+
* another day finish it in one gesture, while a release where the press
|
|
2115
|
+
* began leaves that day anchored, as a click would. A day `selectable`
|
|
2116
|
+
* refuses cannot be an end: choosing one does nothing, and a drag let go
|
|
2117
|
+
* over one keeps its anchor. Escape drops the range in progress.
|
|
2118
|
+
*/
|
|
2119
|
+
declare function rangePickReducer(state: RangePick, action: RangePickAction, selectable: (date: PlainDate) => boolean): RangePickStep;
|
|
2120
|
+
|
|
2121
|
+
/**
|
|
2122
|
+
* An exact decimal number as text: an optional `-`, digits, and a point
|
|
2123
|
+
* before any fraction digits, as in `"-1234.5"`. A number field holds one
|
|
2124
|
+
* with `valueType: "decimal"`, and every value goes through one to be
|
|
2125
|
+
* stepped, rounded and compared without binary rounding.
|
|
2126
|
+
*/
|
|
2127
|
+
type DecimalString = string;
|
|
2128
|
+
/** A value as a number field holds it: a JS number, or an exact decimal string. */
|
|
2129
|
+
type NumberLike = number | string;
|
|
2130
|
+
/**
|
|
2131
|
+
* Intl's rounding modes, with Intl's meanings. Spelled out rather than read
|
|
2132
|
+
* from `Intl.NumberFormatOptions`, which has them only from TypeScript's
|
|
2133
|
+
* ES2023 lib, so an app type-checking against ES2022 can still read them.
|
|
2134
|
+
*/
|
|
2135
|
+
type RoundingMode = "ceil" | "floor" | "expand" | "trunc" | "halfCeil" | "halfFloor" | "halfExpand" | "halfTrunc" | "halfEven";
|
|
2136
|
+
/** Whether `text` is a decimal string: `[+-]digits[.digits]` or `[+-].digits`. */
|
|
2137
|
+
declare function isDecimalString(text: string): boolean;
|
|
2138
|
+
/**
|
|
2139
|
+
* `text` in normal form: a `-` only when it is not zero, no leading zeros
|
|
2140
|
+
* (one `0` before the point), and no trailing fraction zeros beyond
|
|
2141
|
+
* `minimumFractionDigits`. `null` when `text` is not a decimal string.
|
|
2142
|
+
*/
|
|
2143
|
+
declare function normalizeDecimal(text: string, minimumFractionDigits?: number): DecimalString | null;
|
|
2144
|
+
/**
|
|
2145
|
+
* Orders two decimals by value: `"12.5"` and `"12.50"` are equal. Throws a
|
|
2146
|
+
* `RangeError` for text that is not a decimal string, as every function
|
|
2147
|
+
* here does.
|
|
2148
|
+
*/
|
|
2149
|
+
declare function compareDecimals(a: DecimalString, b: DecimalString): -1 | 0 | 1;
|
|
2150
|
+
/** `a + b`, exactly. */
|
|
2151
|
+
declare function addDecimals(a: DecimalString, b: DecimalString): DecimalString;
|
|
2152
|
+
/** `a - b`, exactly. */
|
|
2153
|
+
declare function subtractDecimals(a: DecimalString, b: DecimalString): DecimalString;
|
|
2154
|
+
/**
|
|
2155
|
+
* `value` rounded to `fractionDigits` digits after the point by `mode`,
|
|
2156
|
+
* exactly as Intl rounds the same text: `"2.345"` is `"2.35"` with
|
|
2157
|
+
* `halfExpand` and `"2.34"` with `halfEven`. A value that rounds to zero
|
|
2158
|
+
* is `"0"`, never `"-0"`.
|
|
2159
|
+
*/
|
|
2160
|
+
declare function roundDecimal(value: DecimalString, fractionDigits: number, mode: RoundingMode): DecimalString;
|
|
2161
|
+
/** `value` times 10 to the `places`, exactly: `shiftDecimal("0.125", 2)` is `"12.5"`. */
|
|
2162
|
+
declare function shiftDecimal(value: DecimalString, places: number): DecimalString;
|
|
2163
|
+
/**
|
|
2164
|
+
* The shortest decimal that reads back as `value`, with no exponent:
|
|
2165
|
+
* `1e21` is `"1000000000000000000000"`, `-0` is `"0"`. Throws a
|
|
2166
|
+
* `RangeError` for `NaN` and the infinities.
|
|
2167
|
+
*/
|
|
2168
|
+
declare function numberToDecimal(value: number): DecimalString;
|
|
2169
|
+
/**
|
|
2170
|
+
* `value` as a JS number, and whether that number writes back as exactly
|
|
2171
|
+
* this decimal: `"0.1"` is exact, `"9007199254740993"` is not (it becomes
|
|
2172
|
+
* …992), and neither is a decimal beyond the number range.
|
|
2173
|
+
*/
|
|
2174
|
+
declare function decimalToNumber(value: DecimalString): {
|
|
2175
|
+
readonly number: number;
|
|
2176
|
+
readonly exact: boolean;
|
|
2177
|
+
};
|
|
2178
|
+
|
|
2179
|
+
type StepDirection = "up" | "down";
|
|
2180
|
+
/** One `step`, one `largeStep`, or all the way to the limit (`edge`). */
|
|
2181
|
+
type StepSize = "step" | "large" | "edge";
|
|
2182
|
+
/** A step to take, every number an exact decimal. */
|
|
2183
|
+
interface StepRequest {
|
|
2184
|
+
/** The value to step from; `null` for an empty field. */
|
|
2185
|
+
readonly value: DecimalString | null;
|
|
2186
|
+
readonly direction: StepDirection;
|
|
2187
|
+
readonly size: StepSize;
|
|
2188
|
+
/** Above zero. */
|
|
2189
|
+
readonly step: DecimalString;
|
|
2190
|
+
readonly largeStep: DecimalString;
|
|
2191
|
+
readonly min: DecimalString | null;
|
|
2192
|
+
readonly max: DecimalString | null;
|
|
2193
|
+
}
|
|
2194
|
+
/**
|
|
2195
|
+
* The value one step on, in normal form:
|
|
2196
|
+
*
|
|
2197
|
+
* - From empty, the starting point: 0, or `min` when it is above 0, or
|
|
2198
|
+
* `max` when it is below 0.
|
|
2199
|
+
* - On the step grid (multiples of `step` from `min`, or from 0 without
|
|
2200
|
+
* one), one step or one large step; off it, to the grid value that way
|
|
2201
|
+
* first, as native number inputs do (1.37 with step 0.5: up to 1.5, down
|
|
2202
|
+
* to 1).
|
|
2203
|
+
* - `edge`: to `max` going up and `min` going down; the value unchanged
|
|
2204
|
+
* when that limit is not set.
|
|
2205
|
+
* - Never past `min` or `max`: a step from a limit returns that limit,
|
|
2206
|
+
* which `compareDecimals` tells the caller is the value it had.
|
|
2207
|
+
*
|
|
2208
|
+
* The result can have more fraction digits than the field keeps; the
|
|
2209
|
+
* caller rounds it. Throws a `RangeError` for a step that is not above
|
|
2210
|
+
* zero.
|
|
2211
|
+
*/
|
|
2212
|
+
declare function stepNumber(request: StepRequest): DecimalString | null;
|
|
2213
|
+
|
|
2214
|
+
/**
|
|
2215
|
+
* Where typing in a segmented field stands:
|
|
2216
|
+
*
|
|
2217
|
+
* - `idle`: focus is elsewhere.
|
|
2218
|
+
* - `active`: a segment has focus and nothing is typed into it yet; a
|
|
2219
|
+
* digit replaces what it holds. `advanced`: typing or a separator moved
|
|
2220
|
+
* focus here, so a separator typed now does nothing (`3/14` and `314`
|
|
2221
|
+
* both work).
|
|
2222
|
+
* - `typing`: digits typed into a segment that can take more.
|
|
2223
|
+
* - `composing`: an input method owns a segment's text until it ends.
|
|
2224
|
+
* - `text`: the free-text box shows, for a shortcut; `before` is the
|
|
2225
|
+
* segments' text to go back to.
|
|
2226
|
+
*/
|
|
2227
|
+
type SegmentEntry = {
|
|
2228
|
+
readonly kind: "idle";
|
|
2229
|
+
} | {
|
|
2230
|
+
readonly kind: "active";
|
|
2231
|
+
readonly segment: number;
|
|
2232
|
+
readonly advanced: boolean;
|
|
2233
|
+
} | {
|
|
2234
|
+
readonly kind: "typing";
|
|
2235
|
+
readonly segment: number;
|
|
2236
|
+
readonly digits: string;
|
|
2237
|
+
} | {
|
|
2238
|
+
readonly kind: "composing";
|
|
2239
|
+
readonly segment: number;
|
|
2240
|
+
} | {
|
|
2241
|
+
readonly kind: "text";
|
|
2242
|
+
readonly before: string;
|
|
2243
|
+
};
|
|
2244
|
+
/** What happened in a segmented field, as forms-dom reports it. */
|
|
2245
|
+
type SegmentAction = {
|
|
2246
|
+
readonly type: "focus";
|
|
2247
|
+
readonly segment: number;
|
|
2248
|
+
}
|
|
2249
|
+
/** Characters typed into the active segment. */
|
|
2250
|
+
| {
|
|
2251
|
+
readonly type: "key";
|
|
2252
|
+
readonly text: string;
|
|
2253
|
+
} | {
|
|
2254
|
+
readonly type: "backspace";
|
|
2255
|
+
} | {
|
|
2256
|
+
readonly type: "delete";
|
|
2257
|
+
}
|
|
2258
|
+
/** ArrowUp and ArrowDown (`step`), PageUp and PageDown (`large`), Home and End (`edge`). */
|
|
2259
|
+
| {
|
|
2260
|
+
readonly type: "step";
|
|
2261
|
+
readonly direction: StepDirection;
|
|
2262
|
+
readonly size: StepSize;
|
|
2263
|
+
} | {
|
|
2264
|
+
readonly type: "move";
|
|
2265
|
+
readonly to: "next" | "previous";
|
|
2266
|
+
} | {
|
|
2267
|
+
readonly type: "paste";
|
|
2268
|
+
readonly text: string;
|
|
2269
|
+
} | {
|
|
2270
|
+
readonly type: "compositionStart";
|
|
2271
|
+
} | {
|
|
2272
|
+
readonly type: "compositionEnd";
|
|
2273
|
+
readonly text: string;
|
|
2274
|
+
}
|
|
2275
|
+
/** The free-text box's text changed; `source` is `"typing"` unless given. */
|
|
2276
|
+
| {
|
|
2277
|
+
readonly type: "textEdit";
|
|
2278
|
+
readonly text: string;
|
|
2279
|
+
readonly source?: ChangeSource | undefined;
|
|
2280
|
+
}
|
|
2281
|
+
/** Enter: the active segment is finished before the field commits. */
|
|
2282
|
+
| {
|
|
2283
|
+
readonly type: "finish";
|
|
2284
|
+
}
|
|
2285
|
+
/** Focus left the field. */
|
|
2286
|
+
| {
|
|
2287
|
+
readonly type: "leave";
|
|
2288
|
+
}
|
|
2289
|
+
/** The field's text changed from outside: a controlled value, a revert, a clear, a commit. */
|
|
2290
|
+
| {
|
|
2291
|
+
readonly type: "outside";
|
|
2292
|
+
readonly text: string;
|
|
2293
|
+
};
|
|
2294
|
+
interface SegmentState {
|
|
2295
|
+
readonly entry: SegmentEntry;
|
|
2296
|
+
/** The field's text: the segments joined by the layout's literals, or the free text. */
|
|
2297
|
+
readonly text: string;
|
|
2298
|
+
}
|
|
2299
|
+
/** What the reducer needs to know about the field. */
|
|
2300
|
+
interface SegmentContext {
|
|
2301
|
+
readonly layout: DateLayout;
|
|
2302
|
+
/**
|
|
2303
|
+
* Where an empty segment steps from: today's year, month or day, 0 for
|
|
2304
|
+
* a time. An hour is given 0 to 23 and shown in the layout's cycle; the
|
|
2305
|
+
* day period 0 for the morning, 1 for the afternoon.
|
|
2306
|
+
*/
|
|
2307
|
+
readonly reference: (segment: SegmentType) => number;
|
|
2308
|
+
/** The year a one- or two-digit year left in a segment means. */
|
|
2309
|
+
readonly pivotYear: (digits: number) => number;
|
|
2310
|
+
/** Whether letters and signs in a date segment open the free-text box. */
|
|
2311
|
+
readonly shortcuts: boolean;
|
|
2312
|
+
/** The field's text for a pasted or one-letter text that reads as a value, else `null`. */
|
|
2313
|
+
readonly readWhole: (text: string) => string | null;
|
|
2314
|
+
/** What ArrowUp and ArrowDown add to the minutes, snapping to it; 1 by default. */
|
|
2315
|
+
readonly minuteStep?: number | undefined;
|
|
2316
|
+
/**
|
|
2317
|
+
* Whether a step may leave the segments as `texts`: the renderer checks
|
|
2318
|
+
* them against `min` and `max`, so stepping never leaves the limits.
|
|
2319
|
+
* Every step is allowed without it.
|
|
2320
|
+
*/
|
|
2321
|
+
readonly allows?: ((texts: readonly string[]) => boolean) | undefined;
|
|
2322
|
+
}
|
|
2323
|
+
/** What one action did. */
|
|
2324
|
+
interface SegmentStep {
|
|
2325
|
+
readonly state: SegmentState;
|
|
2326
|
+
/** What has focus afterwards: a segment, the free-text box, or nothing (idle). */
|
|
2327
|
+
readonly focus: number | "text" | null;
|
|
2328
|
+
/** What the change was, for the event; `null` when the text did not change. */
|
|
2329
|
+
readonly source: ChangeSource | null;
|
|
2330
|
+
/**
|
|
2331
|
+
* A one-letter free text applied at once (`t`): forms-dom reports it as
|
|
2332
|
+
* typed before the segments it gave, so the events name the shortcut.
|
|
2333
|
+
* Absent otherwise.
|
|
2334
|
+
*/
|
|
2335
|
+
readonly applied?: string;
|
|
2336
|
+
}
|
|
2337
|
+
/**
|
|
2338
|
+
* Every transition of a segmented field's typing, pure: forms-dom splits
|
|
2339
|
+
* the controller's text into segments before each action and reports
|
|
2340
|
+
* what comes back. Typing moves on once a segment is complete (a digit
|
|
2341
|
+
* that cannot start a longer number, or the segment's width reached); a
|
|
2342
|
+
* digit that would leave the segment's range starts it again (1 then 3 in
|
|
2343
|
+
* a month gives 03). Separators finish a segment; Backspace in an empty
|
|
2344
|
+
* one goes back. Steps wrap, a day within its month, and clamp the day
|
|
2345
|
+
* when the month or year changes; a step the field does not allow
|
|
2346
|
+
* (`allows`) is not taken. Leaving a segment pads it and pivots a short
|
|
2347
|
+
* year. In a date segment with shortcuts on, a letter or a sign opens the
|
|
2348
|
+
* free-text box; a one-letter text that reads is applied at once.
|
|
2349
|
+
*/
|
|
2350
|
+
declare function segmentReducer(state: SegmentState, action: SegmentAction, context: SegmentContext): SegmentStep;
|
|
2351
|
+
/** A state in which no segment has focus, showing `text`. */
|
|
2352
|
+
declare function idleSegments(text: string): SegmentState;
|
|
2353
|
+
/** What a segment's spinbutton tells assistive technology. */
|
|
2354
|
+
interface SegmentAria {
|
|
2355
|
+
/** The number it holds; `null` while empty. A day period is 0 or 1. */
|
|
2356
|
+
readonly valueNow: number | null;
|
|
2357
|
+
readonly valueMin: number;
|
|
2358
|
+
/** The segment's highest value; a day's follows its month once the month is set. */
|
|
2359
|
+
readonly valueMax: number;
|
|
2360
|
+
/** The month's name, the day period's text, the digits; `messages.segmentEmpty` while empty. */
|
|
2361
|
+
readonly valueText: string;
|
|
2362
|
+
}
|
|
2363
|
+
/**
|
|
2364
|
+
* The value, range and value text of segment `index` among the field's
|
|
2365
|
+
* segment `texts`, for its `aria-valuenow`, `aria-valuemin`,
|
|
2366
|
+
* `aria-valuemax` and `aria-valuetext`: a month reads as its name in
|
|
2367
|
+
* `locale` ("March"), a day period as its text, anything else as its
|
|
2368
|
+
* digits, and an empty segment as "Empty".
|
|
2369
|
+
*/
|
|
2370
|
+
declare function segmentAria(layout: DateLayout, index: number, texts: readonly string[], locale: Intl.LocalesArgument, messages: FormsMessages): SegmentAria;
|
|
2371
|
+
|
|
2372
|
+
/**
|
|
2373
|
+
* The day a typed shortcut names, always counted from `today`, never from
|
|
2374
|
+
* the field's value: `t` today; `+3` or `+3d` three days on, `-1w` a week
|
|
2375
|
+
* back, `+2m` and `-1y` months and years (clamped to the month's length);
|
|
2376
|
+
* `s` and `e` the start and end of this month; an offset then an anchor,
|
|
2377
|
+
* `+1ms` the start of next month, `-1me` the end of last. Case-insensitive,
|
|
2378
|
+
* digits in any script. `null` for anything else, or a day past the years
|
|
2379
|
+
* 1 to 9999.
|
|
2380
|
+
*/
|
|
2381
|
+
declare function readDateShortcut(text: string, today: PlainDate): PlainDate | null;
|
|
2382
|
+
|
|
2383
|
+
/** A column of a time picker: one per time segment of the field's layout. */
|
|
2384
|
+
type TimeColumnType = "hour" | "minute" | "second" | "dayPeriod";
|
|
2385
|
+
/** One choice in a time picker's column. */
|
|
2386
|
+
interface TimeColumnOption {
|
|
2387
|
+
/**
|
|
2388
|
+
* What the column sets: the hour of the day (0 to 23), or of the half
|
|
2389
|
+
* day (0 to 11) in a 12-hour cycle; the minute; the second; 0 for the
|
|
2390
|
+
* morning and 1 for the afternoon.
|
|
2391
|
+
*/
|
|
2392
|
+
readonly value: number;
|
|
2393
|
+
/** As the field's segment writes it: "12", "03", "PM", in the locale's digits. */
|
|
2394
|
+
readonly text: string;
|
|
2395
|
+
/** No time it would give is within the limits. */
|
|
2396
|
+
readonly disabled: boolean;
|
|
2397
|
+
}
|
|
2398
|
+
/** A time picker's column, in the order the field's segments are. */
|
|
2399
|
+
interface TimeColumn {
|
|
2400
|
+
readonly type: TimeColumnType;
|
|
2401
|
+
/** The segment's name, which names the column: "hour". */
|
|
2402
|
+
readonly label: string;
|
|
2403
|
+
readonly options: readonly TimeColumnOption[];
|
|
2404
|
+
/** The value of the option the time holds; `null` while there is no time, or for minutes off the step. */
|
|
2405
|
+
readonly selected: number | null;
|
|
2406
|
+
}
|
|
2407
|
+
/**
|
|
2408
|
+
* The first and last time allowed, inclusive; `null` for no limit. With
|
|
2409
|
+
* `min` after `max` no time of day is allowed.
|
|
2410
|
+
*/
|
|
2411
|
+
interface TimeLimits {
|
|
2412
|
+
readonly min: PlainTime | null;
|
|
2413
|
+
readonly max: PlainTime | null;
|
|
2414
|
+
}
|
|
2415
|
+
/** What a time picker's columns are drawn from. */
|
|
2416
|
+
interface TimeColumnsOptions extends TimeLimits {
|
|
2417
|
+
/** The field's layout: which columns, the hour cycle, the texts and digits. */
|
|
2418
|
+
readonly layout: DateLayout;
|
|
2419
|
+
/** The minutes offered, every `minuteStep` from 0; 1 by default. */
|
|
2420
|
+
readonly minuteStep?: number | undefined;
|
|
2421
|
+
}
|
|
2422
|
+
/** No limits: every time of day. */
|
|
2423
|
+
declare const ALL_DAY: TimeLimits;
|
|
2424
|
+
/** Limits no time of day meets, for a day outside a date-time field's limits. */
|
|
2425
|
+
declare const NO_TIME: TimeLimits;
|
|
2426
|
+
/**
|
|
2427
|
+
* A time picker's columns for `time`: hours, minutes every `minuteStep`,
|
|
2428
|
+
* seconds when the layout has them, and the day period in a 12-hour cycle,
|
|
2429
|
+
* in the layout's order, each option written as its segment writes it.
|
|
2430
|
+
* An option is disabled when every time it would give, at the other
|
|
2431
|
+
* columns' values (`min`, else midnight, while `time` is `null`), falls
|
|
2432
|
+
* outside `min` and `max`.
|
|
2433
|
+
*/
|
|
2434
|
+
declare function timeColumns(time: PlainTime | null, options: TimeColumnsOptions): readonly TimeColumn[];
|
|
2435
|
+
/**
|
|
2436
|
+
* `time` within `limits`: the nearer limit when it is outside them, and
|
|
2437
|
+
* `time` itself when no time of day is allowed.
|
|
2438
|
+
*/
|
|
2439
|
+
declare function clampTime(time: PlainTime, limits: TimeLimits): PlainTime;
|
|
2440
|
+
/**
|
|
2441
|
+
* The time choosing `value` in the column `type` gives: `time` (`min`,
|
|
2442
|
+
* else midnight, while it is `null`) with that part set, then brought
|
|
2443
|
+
* within the limits. An hour keeps the half of the day in a 12-hour
|
|
2444
|
+
* cycle; a day period keeps the hour shown (3 AM becomes 3 PM).
|
|
2445
|
+
*/
|
|
2446
|
+
declare function setTimeColumn(time: PlainTime | null, type: TimeColumnType, value: number, options: TimeColumnsOptions): PlainTime;
|
|
2447
|
+
/**
|
|
2448
|
+
* `time` as the columns can show it, for a "Now" button: the minutes down
|
|
2449
|
+
* to the step, no seconds unless the layout has them, no milliseconds,
|
|
2450
|
+
* within the limits.
|
|
2451
|
+
*/
|
|
2452
|
+
declare function snapTime(time: PlainTime, options: TimeColumnsOptions): PlainTime;
|
|
2453
|
+
/**
|
|
2454
|
+
* The times a date-time field allows on `day`, for its time columns: from
|
|
2455
|
+
* `min`'s time on `min`'s day, to `max`'s time on `max`'s day, all day in
|
|
2456
|
+
* between, and none (`NO_TIME`) on a day before `min`'s or after `max`'s.
|
|
2457
|
+
*/
|
|
2458
|
+
declare function dayTimeLimits(day: PlainDate, min: PlainDateTime | null, max: PlainDateTime | null): TimeLimits;
|
|
2459
|
+
|
|
2460
|
+
/**
|
|
2461
|
+
* The way a line runs: left to right, or right to left as in Arabic and
|
|
2462
|
+
* Hebrew. A grid's rows and toolbars and a form's controls run this way, so
|
|
2463
|
+
* in `"rtl"` the first column sits at the right edge.
|
|
2464
|
+
*/
|
|
2465
|
+
type WritingDirection = "ltr" | "rtl";
|
|
2466
|
+
/**
|
|
2467
|
+
* Which way a horizontal arrow key moves along a line in `direction`: `1`
|
|
2468
|
+
* to the next column, chip or control, `-1` to the previous one, or
|
|
2469
|
+
* `null` for any other key. The arrows point the way they move, so in
|
|
2470
|
+
* `"rtl"`, where the next one is to the left, `ArrowLeft` moves forward.
|
|
2471
|
+
*/
|
|
2472
|
+
declare function inlineStep(key: string, direction?: WritingDirection): 1 | -1 | null;
|
|
2473
|
+
|
|
2474
|
+
/**
|
|
2475
|
+
* Runs `callback` once after `delay` milliseconds and returns the function
|
|
2476
|
+
* that cancels it. forms-core keeps no timers of its own, so it can run
|
|
2477
|
+
* anywhere: whoever drives a field hands it one of these, the browser's
|
|
2478
|
+
* timers in a page and a fake one in a test.
|
|
2479
|
+
*/
|
|
2480
|
+
type Schedule = (callback: () => void, delay: number) => () => void;
|
|
2481
|
+
|
|
2482
|
+
/**
|
|
2483
|
+
* What a field is given: its value, how it reads and writes text, how it
|
|
2484
|
+
* validates, and the app's handlers. A renderer passes the latest on every
|
|
2485
|
+
* update through `setOptions`.
|
|
2486
|
+
*/
|
|
2487
|
+
interface FieldOptions<V, D extends object = NoDetails, N = unknown> extends FieldHandlers<V, D, N> {
|
|
2488
|
+
/** Present (`null` included) means controlled: see `FieldController.sync`. */
|
|
2489
|
+
readonly value?: V | null | undefined;
|
|
2490
|
+
/** The value of an uncontrolled field at first, and what `reset` returns to. */
|
|
2491
|
+
readonly defaultValue?: V | null | undefined;
|
|
2492
|
+
/** The app's reading of typed text; its context holds `defaultParse`. */
|
|
2493
|
+
readonly parse?: Parser<V> | undefined;
|
|
2494
|
+
/** The app's writing of the value; its context holds `defaultFormat`. */
|
|
2495
|
+
readonly format?: Formatter<V> | undefined;
|
|
2496
|
+
/** The input's own reading. */
|
|
2497
|
+
readonly defaultParse: (text: string, context: ParseContext<V>) => ParseResult<V>;
|
|
2498
|
+
/** The input's own writing. */
|
|
2499
|
+
readonly defaultFormat: (value: V | null, context: FormatContext<V>) => string;
|
|
2500
|
+
/** Whether two values are one; `Object.is` by default. Never called with `null`. */
|
|
2501
|
+
readonly equals?: ((a: V, b: V) => boolean) | undefined;
|
|
2502
|
+
/**
|
|
2503
|
+
* The input's own judgement of each edit the app's `onBeforeInput` lets
|
|
2504
|
+
* through, outside a composition: a number input refusing letters, or
|
|
2505
|
+
* cleaning a paste.
|
|
2506
|
+
*/
|
|
2507
|
+
readonly filterInput?: InputFilter<N> | undefined;
|
|
2508
|
+
readonly validators?: readonly Validator<V>[] | undefined;
|
|
2509
|
+
/**
|
|
2510
|
+
* The input's own details, added to every event it fires. `cause` is
|
|
2511
|
+
* the change the event is about: its source and, for a text edit, where
|
|
2512
|
+
* in the text it happened (a date field names the segment from it).
|
|
2513
|
+
*/
|
|
2514
|
+
readonly details?: ((current: FieldState<V>, previous: FieldState<V>, cause: ChangeCause<N>) => D) | undefined;
|
|
2515
|
+
/**
|
|
2516
|
+
* Milliseconds typing must pause before the text is read (`onChange`),
|
|
2517
|
+
* for a search box. `onInput` fires at once, and a commit reads at once.
|
|
2518
|
+
* Needs `schedule`; 0, the default, reads at once.
|
|
2519
|
+
*/
|
|
2520
|
+
readonly changeDelay?: number | undefined;
|
|
2521
|
+
/** Whether leaving the field commits it: true by default, false for a toggle, which commits as it flips. */
|
|
2522
|
+
readonly commitOnLeave?: boolean | undefined;
|
|
2523
|
+
/** The timer `changeDelay` runs on. */
|
|
2524
|
+
readonly schedule?: Schedule | undefined;
|
|
2525
|
+
readonly locale?: Intl.LocalesArgument;
|
|
2526
|
+
readonly messages: FormsMessages;
|
|
2527
|
+
}
|
|
2528
|
+
/**
|
|
2529
|
+
* One field's state and every request that moves it, for a renderer to
|
|
2530
|
+
* drive: forms-dom calls the text and focus requests from the browser's
|
|
2531
|
+
* events, the app the value requests. Each request runs its sequence of
|
|
2532
|
+
* handlers to the end before the next starts: one made from inside a
|
|
2533
|
+
* handler is queued behind it.
|
|
2534
|
+
*/
|
|
2535
|
+
interface FieldController<V, D extends object = NoDetails, N = unknown> {
|
|
2536
|
+
readonly getState: () => FieldState<V>;
|
|
2537
|
+
/** The text on screen. */
|
|
2538
|
+
readonly getText: () => string;
|
|
2539
|
+
/** Every message the field holds, in display order; the same array until the state changes. */
|
|
2540
|
+
readonly getMessages: () => readonly FieldMessage[];
|
|
2541
|
+
/** Calls `listener` once after each request that changed the state. */
|
|
2542
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
2543
|
+
/** Replaces the options, silently: no listener is called. */
|
|
2544
|
+
readonly setOptions: (options: FieldOptions<V, D, N>) => void;
|
|
2545
|
+
/**
|
|
2546
|
+
* `onBeforeInput` for an edit about to happen, then the input's
|
|
2547
|
+
* `filterInput`, and what to do with it.
|
|
2548
|
+
*/
|
|
2549
|
+
readonly beforeInput: (edit: TextEdit<N> & {
|
|
2550
|
+
readonly cancelable: boolean;
|
|
2551
|
+
}) => InputFilterDecision;
|
|
2552
|
+
/**
|
|
2553
|
+
* The text changed. Read at once, after `changeDelay`, or, while an input
|
|
2554
|
+
* method composes (`input.isComposing`), once composition ends. While the
|
|
2555
|
+
* field is idle the change is autofill: read and committed at once.
|
|
2556
|
+
*/
|
|
2557
|
+
readonly input: (edit: TextEdit<N>) => void;
|
|
2558
|
+
/** An input method finished composing: the text is read. */
|
|
2559
|
+
readonly endComposition: (nativeEvent: N | null) => void;
|
|
2560
|
+
/**
|
|
2561
|
+
* The input's own `filterInput` alone, for the text an input method
|
|
2562
|
+
* composed, judged as one insert over the range the composition
|
|
2563
|
+
* replaced once it has ended: `before` is the text from before it began.
|
|
2564
|
+
* The app's `onBeforeInput` saw the composition as it happened. `allow`
|
|
2565
|
+
* for an input with no filter.
|
|
2566
|
+
*/
|
|
2567
|
+
readonly filterComposition: (edit: TextEdit<N>, before: string) => InputFilterDecision;
|
|
2568
|
+
/**
|
|
2569
|
+
* How `text` reads with the field's parser (the app's `parse` around the
|
|
2570
|
+
* input's own), changing nothing: a segmented date field checks a paste
|
|
2571
|
+
* with it before taking it.
|
|
2572
|
+
*/
|
|
2573
|
+
readonly read: (text: string) => ParseResult<V>;
|
|
2574
|
+
readonly focus: (nativeEvent: N | null) => void;
|
|
2575
|
+
/** Reads any unread text, then commits it. */
|
|
2576
|
+
readonly commit: (trigger: CommitTrigger, nativeEvent: N | null) => CommitOutcome;
|
|
2577
|
+
/** Focus went: the edit commits, unless Tab did already. */
|
|
2578
|
+
readonly blur: (nativeEvent: N | null) => void;
|
|
2579
|
+
/** Escape: back to the last commit. False when there is nothing to put back. */
|
|
2580
|
+
readonly revert: (nativeEvent: N | null) => boolean;
|
|
2581
|
+
/** The clear button: `null`, then a commit. */
|
|
2582
|
+
readonly clear: (nativeEvent: N | null) => CommitOutcome;
|
|
2583
|
+
/** A value chosen whole (a toggle, an option, a preset), then a commit. */
|
|
2584
|
+
readonly pick: (value: V | null, source: ChangeSource, trigger: CommitTrigger, nativeEvent: N | null) => CommitOutcome;
|
|
2585
|
+
/**
|
|
2586
|
+
* A value set whole without a commit (a step, a part of a composite
|
|
2587
|
+
* input): the change chain to `value`, with `cause`'s source and native
|
|
2588
|
+
* event. Typed text gives way to the value formatted, even when the value
|
|
2589
|
+
* stays.
|
|
2590
|
+
*/
|
|
2591
|
+
readonly change: (value: V | null, cause: ChangeCause<N>) => void;
|
|
2592
|
+
/** `change` to `value` with `source: "api"`. */
|
|
2593
|
+
readonly setValue: (value: V | null) => void;
|
|
2594
|
+
/** The change chain back to `defaultValue` (or `null`), with `source: "api"`. */
|
|
2595
|
+
readonly reset: () => void;
|
|
2596
|
+
/**
|
|
2597
|
+
* The controlled value, which a renderer passes on every update. Adopted
|
|
2598
|
+
* whenever the user is not typing, with no event; while they type it is
|
|
2599
|
+
* held, and the first `sync` after the edit ends adopts it.
|
|
2600
|
+
*/
|
|
2601
|
+
readonly sync: (value: V | null) => void;
|
|
2602
|
+
/** Messages show from now on: a form's submit reveals every field. */
|
|
2603
|
+
readonly reveal: () => void;
|
|
2604
|
+
/** Cancels a scheduled reading and ignores a pending check's answer. */
|
|
2605
|
+
readonly destroy: () => void;
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* A controller for one field. The field starts idle with `value` when
|
|
2609
|
+
* given (controlled), else `defaultValue`, else `null`, validated but with
|
|
2610
|
+
* no message shown.
|
|
2611
|
+
*/
|
|
2612
|
+
declare function createFieldController<V, D extends object = NoDetails, N = unknown>(initialOptions: FieldOptions<V, D, N>): FieldController<V, D, N>;
|
|
2613
|
+
|
|
2614
|
+
/** Each part's value, by part name; `null` for an empty part. */
|
|
2615
|
+
type PartValues<P extends Record<string, unknown>> = {
|
|
2616
|
+
readonly [K in keyof P]: P[K] | null;
|
|
2617
|
+
};
|
|
2618
|
+
/** Each part's text, by part name. */
|
|
2619
|
+
type PartTexts<P extends Record<string, unknown>> = {
|
|
2620
|
+
readonly [K in keyof P]: string;
|
|
2621
|
+
};
|
|
2622
|
+
/**
|
|
2623
|
+
* Which part an event is about: the part whose edit it is, `"all"` for a
|
|
2624
|
+
* value set whole (`setValue`, a controlled value, a revert or clear), and
|
|
2625
|
+
* on a commit the part that differs from the last commit (`"all"` when
|
|
2626
|
+
* several do, `null` when none does).
|
|
2627
|
+
*/
|
|
2628
|
+
type PartChange<P extends Record<string, unknown>> = keyof P | "all" | null;
|
|
2629
|
+
/** How one part reads and writes its text. The composite owns its value and events. */
|
|
2630
|
+
type PartOptions<T, N = unknown> = Pick<FieldOptions<T, NoDetails, N>, "parse" | "format" | "defaultParse" | "defaultFormat" | "equals" | "filterInput" | "locale">;
|
|
2631
|
+
/** What `assemble` knows beside the parts' values. */
|
|
2632
|
+
interface AssembleContext {
|
|
2633
|
+
readonly locale: Intl.LocalesArgument;
|
|
2634
|
+
readonly messages: FormsMessages;
|
|
2635
|
+
}
|
|
2636
|
+
/** What a composite input's `details` is told beside the field's state. */
|
|
2637
|
+
interface CompositeDetailsContext<P extends Record<string, unknown>, N = unknown> {
|
|
2638
|
+
readonly changed: PartChange<P>;
|
|
2639
|
+
readonly parts: {
|
|
2640
|
+
readonly [K in keyof P]: FieldState<P[K]>;
|
|
2641
|
+
};
|
|
2642
|
+
readonly texts: PartTexts<P>;
|
|
2643
|
+
/** The change the event is about, as `FieldOptions.details` receives it. */
|
|
2644
|
+
readonly cause: ChangeCause<N>;
|
|
2645
|
+
}
|
|
2646
|
+
/**
|
|
2647
|
+
* What a composite input is given: the field's options, as for one input,
|
|
2648
|
+
* with how each part reads and writes, and how the parts' values make the
|
|
2649
|
+
* one value the app sees and back. The renderer passes the latest on every
|
|
2650
|
+
* update through `setOptions`.
|
|
2651
|
+
*/
|
|
2652
|
+
interface CompositeFieldOptions<V, P extends Record<string, unknown>, D extends object = NoDetails, N = unknown> extends Omit<FieldOptions<V, D, N>, "parse" | "format" | "defaultParse" | "defaultFormat" | "details" | "filterInput" | "changeDelay" | "schedule" | "commitOnLeave"> {
|
|
2653
|
+
/** Each part, in the order the parts are read: a part's unreadable text is reported first. */
|
|
2654
|
+
readonly parts: {
|
|
2655
|
+
readonly [K in keyof P]: PartOptions<P[K], N>;
|
|
2656
|
+
};
|
|
2657
|
+
/** The value the parts make, or why they make none (an end before its start). */
|
|
2658
|
+
readonly assemble: (parts: PartValues<P>, context: AssembleContext) => ParseResult<V>;
|
|
2659
|
+
/** Each part's value within `value`. */
|
|
2660
|
+
readonly split: (value: V | null) => PartValues<P>;
|
|
2661
|
+
/** The field's text, which events carry: the parts' texts, joined. */
|
|
2662
|
+
readonly join: (texts: PartTexts<P>) => string;
|
|
2663
|
+
/** The input's own details, added to every event the field fires. */
|
|
2664
|
+
readonly details?: ((current: FieldState<V>, previous: FieldState<V>, context: CompositeDetailsContext<P, N>) => D) | undefined;
|
|
2665
|
+
}
|
|
2666
|
+
/**
|
|
2667
|
+
* One part's controller, for a renderer to attach a control to as it
|
|
2668
|
+
* would a field's: its text and state are the part's own; its edits,
|
|
2669
|
+
* Enter, Escape and the clear button act on the whole field.
|
|
2670
|
+
*/
|
|
2671
|
+
type PartController<T, N = unknown> = Pick<FieldController<T, NoDetails, N>, "getState" | "getText" | "getMessages" | "subscribe" | "beforeInput" | "input" | "endComposition" | "filterComposition" | "read" | "focus" | "commit" | "blur" | "revert" | "clear" | "reset" | "change">;
|
|
2672
|
+
/** The field and its parts, whole: one object until any of them changes. */
|
|
2673
|
+
interface CompositeState<V, P extends Record<string, unknown>> {
|
|
2674
|
+
readonly field: FieldState<V>;
|
|
2675
|
+
readonly parts: {
|
|
2676
|
+
readonly [K in keyof P]: FieldState<P[K]>;
|
|
2677
|
+
};
|
|
2678
|
+
}
|
|
2679
|
+
/**
|
|
2680
|
+
* An input made of parts (both ends of a range, an amount and its
|
|
2681
|
+
* currency) driven as one field. Expect this API to change while its first
|
|
2682
|
+
* users settle it.
|
|
2683
|
+
*/
|
|
2684
|
+
interface CompositeController<V, P extends Record<string, unknown>, D extends object = NoDetails, N = unknown> {
|
|
2685
|
+
/** The field the app sees: its events, value and messages. */
|
|
2686
|
+
readonly field: Omit<FieldController<V, D, N>, "setOptions">;
|
|
2687
|
+
/** One controller per part, for a renderer to attach a control to. */
|
|
2688
|
+
readonly parts: {
|
|
2689
|
+
readonly [K in keyof P]: PartController<P[K], N>;
|
|
2690
|
+
};
|
|
2691
|
+
readonly getState: () => CompositeState<V, P>;
|
|
2692
|
+
/** Calls `listener` after each request that changed the field or a part. */
|
|
2693
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
2694
|
+
/** Replaces the options, silently. */
|
|
2695
|
+
readonly setOptions: (options: CompositeFieldOptions<V, P, D, N>) => void;
|
|
2696
|
+
/**
|
|
2697
|
+
* Focus left the whole input (a part's own blur cannot tell): the field
|
|
2698
|
+
* commits with `trigger` `"tab"` or `"blur"`, then `onBlur`.
|
|
2699
|
+
*/
|
|
2700
|
+
readonly leave: (by: "tab" | "blur", nativeEvent: N | null) => void;
|
|
2701
|
+
/** Cancels what the field and its parts wait for. */
|
|
2702
|
+
readonly destroy: () => void;
|
|
2703
|
+
}
|
|
2704
|
+
/**
|
|
2705
|
+
* A controller for an input made of parts. Each part is a field of its
|
|
2706
|
+
* own with no app handlers: it reads, filters and writes its text as a
|
|
2707
|
+
* lone input does. The composite relays every part edit to the field the
|
|
2708
|
+
* app sees as an edit of the joined text, so `onBeforeInput` and `onInput`
|
|
2709
|
+
* fire with the part's edit, and the field reads its value from the parts
|
|
2710
|
+
* (`assemble`), then runs the change chain. A value the field takes whole
|
|
2711
|
+
* (`setValue` in `onBeforeChange`, a controlled value, a revert, a clear)
|
|
2712
|
+
* is pushed into the parts by `split`; a part whose text already reads as
|
|
2713
|
+
* its value keeps it while the user types, and every part shows its value
|
|
2714
|
+
* formatted once the field commits.
|
|
2715
|
+
*
|
|
2716
|
+
* Tab from part to part commits only the part, normalizing its text.
|
|
2717
|
+
* Enter in a part commits the field; Escape reverts it. Focus entering a
|
|
2718
|
+
* part of an idle field fires `onFocus`; focus leaving the whole input is
|
|
2719
|
+
* the renderer's to report through `leave`. Parts read at once: they take
|
|
2720
|
+
* no `changeDelay`.
|
|
2721
|
+
*/
|
|
2722
|
+
declare function createCompositeController<V, P extends Record<string, unknown>, D extends object = NoDetails, N = unknown>(initialOptions: CompositeFieldOptions<V, P, D, N>): CompositeController<V, P, D, N>;
|
|
2723
|
+
|
|
2724
|
+
/** A token of an app's own: one character it accepts, and how it is written. */
|
|
2725
|
+
interface MaskTokenDefinition {
|
|
2726
|
+
/** Tested against one character, after its digits and full-width forms become ASCII. */
|
|
2727
|
+
readonly accept: RegExp;
|
|
2728
|
+
/** Whether the slot may stay empty. False by default. */
|
|
2729
|
+
readonly optional?: boolean | undefined;
|
|
2730
|
+
/** Applied to the character before it is kept; the case tokens still apply after. */
|
|
2731
|
+
readonly transform?: ((character: string) => string) | undefined;
|
|
2732
|
+
}
|
|
2733
|
+
/** One-character token names, beside the built-in tokens, which they may replace. */
|
|
2734
|
+
type MaskTokens = Readonly<Record<string, RegExp | MaskTokenDefinition>>;
|
|
2735
|
+
/** How letters typed into a slot are written, as `>`, `<` and `|` set it. */
|
|
2736
|
+
type MaskLetterCase = "upper" | "lower" | "keep";
|
|
2737
|
+
/**
|
|
2738
|
+
* One place in a compiled pattern: a slot that takes a character, or a
|
|
2739
|
+
* literal printed as it is. `section` numbers the optional section (`[ ]`)
|
|
2740
|
+
* it sits in, `null` outside one.
|
|
2741
|
+
*/
|
|
2742
|
+
type MaskSlot = {
|
|
2743
|
+
readonly kind: "input";
|
|
2744
|
+
/** The token that made it: `"0"`, `"L"`, an app's own. */
|
|
2745
|
+
readonly token: string;
|
|
2746
|
+
readonly accepts: (character: string) => boolean;
|
|
2747
|
+
readonly optional: boolean;
|
|
2748
|
+
readonly transform: ((character: string) => string) | null;
|
|
2749
|
+
readonly letterCase: MaskLetterCase;
|
|
2750
|
+
readonly section: number | null;
|
|
2751
|
+
} | {
|
|
2752
|
+
readonly kind: "literal";
|
|
2753
|
+
readonly character: string;
|
|
2754
|
+
readonly section: number | null;
|
|
2755
|
+
};
|
|
2756
|
+
/** A pattern compiled into its slots. */
|
|
2757
|
+
interface CompiledMask {
|
|
2758
|
+
readonly pattern: string;
|
|
2759
|
+
readonly slots: readonly MaskSlot[];
|
|
2760
|
+
}
|
|
2761
|
+
/**
|
|
2762
|
+
* A compiled pattern, or why it could not be compiled. `position` is the
|
|
2763
|
+
* index in the pattern where the problem starts, `null` for a problem in
|
|
2764
|
+
* the custom tokens.
|
|
2765
|
+
*/
|
|
2766
|
+
type MaskCompileResult = {
|
|
2767
|
+
readonly kind: "compiled";
|
|
2768
|
+
readonly mask: CompiledMask;
|
|
2769
|
+
} | {
|
|
2770
|
+
readonly kind: "error";
|
|
2771
|
+
readonly message: string;
|
|
2772
|
+
readonly position: number | null;
|
|
2773
|
+
};
|
|
2774
|
+
/**
|
|
2775
|
+
* Compiles `pattern` on the .NET-style grammar: `0` a digit, `9` an
|
|
2776
|
+
* optional digit, `#` an optional digit, `+` or `-`, `L` a letter, `?` an
|
|
2777
|
+
* optional letter, `&` any character but a space, `C` any optional
|
|
2778
|
+
* character, `A` a letter or digit, `a` an optional one; `>`, `<` and `|`
|
|
2779
|
+
* upper-case, lower-case or keep the letters after them; `\` makes the next
|
|
2780
|
+
* character a literal; `[ ]` holds an optional section, which appears once
|
|
2781
|
+
* one of its slots is filled; anything else is a literal. `tokens` adds
|
|
2782
|
+
* one-character tokens of an app's own, or replaces built-in ones.
|
|
2783
|
+
*
|
|
2784
|
+
* A malformed pattern (an unclosed, nested or stray bracket, an empty
|
|
2785
|
+
* section, a trailing `\`, no slot at all) is an error with its position.
|
|
2786
|
+
*/
|
|
2787
|
+
declare function compileMask(pattern: string, tokens?: MaskTokens): MaskCompileResult;
|
|
2788
|
+
|
|
2789
|
+
/** A pattern, several tried in order as the text grows, or a function choosing one from the raw text. */
|
|
2790
|
+
type MaskSource = string | readonly string[] | ((raw: string) => string);
|
|
2791
|
+
/** A mask: its pattern, its own tokens and how it prints. */
|
|
2792
|
+
interface MaskOptions {
|
|
2793
|
+
readonly mask: MaskSource;
|
|
2794
|
+
/** One-character names, beside the built-in tokens, which they may replace. */
|
|
2795
|
+
readonly tokens?: MaskTokens | undefined;
|
|
2796
|
+
/** One character, shown in empty slots while focused; `"_"` by default, `""` for none. */
|
|
2797
|
+
readonly promptCharacter?: string | undefined;
|
|
2798
|
+
/** Whose rules `>` and `<` change case by; the runtime's by default. */
|
|
2799
|
+
readonly locale?: Intl.LocalesArgument;
|
|
2800
|
+
}
|
|
2801
|
+
/** Text in a masked control, with the selection. */
|
|
2802
|
+
interface MaskedText {
|
|
2803
|
+
readonly text: string;
|
|
2804
|
+
readonly selectionStart: number;
|
|
2805
|
+
readonly selectionEnd: number;
|
|
2806
|
+
}
|
|
2807
|
+
/** A browser edit, as `beforeinput` reports it. */
|
|
2808
|
+
interface MaskEdit {
|
|
2809
|
+
readonly inputType: string;
|
|
2810
|
+
/** The text inserted; `null` for a deletion. */
|
|
2811
|
+
readonly data: string | null;
|
|
2812
|
+
}
|
|
2813
|
+
/** What a mask makes of some text. */
|
|
2814
|
+
interface MaskDetails {
|
|
2815
|
+
/** Only the characters typed into input slots. */
|
|
2816
|
+
readonly raw: string;
|
|
2817
|
+
/** With literals, without prompt characters, cut after the last character typed. */
|
|
2818
|
+
readonly formatted: string;
|
|
2819
|
+
/** Every required slot (of the pattern in use, and of each optional section begun) is filled. */
|
|
2820
|
+
readonly complete: boolean;
|
|
2821
|
+
/** The pattern in use. */
|
|
2822
|
+
readonly pattern: string;
|
|
2823
|
+
}
|
|
2824
|
+
/** What an edit leaves. */
|
|
2825
|
+
interface MaskResult extends MaskDetails {
|
|
2826
|
+
/** The text to show, prompt characters included while focused. */
|
|
2827
|
+
readonly text: string;
|
|
2828
|
+
readonly caret: number;
|
|
2829
|
+
/** False when the edit changed nothing the mask accepts (a letter in a digit slot): the input refuses it. */
|
|
2830
|
+
readonly accepted: boolean;
|
|
2831
|
+
}
|
|
2832
|
+
/** Whether a mask's value is only the characters typed, or the text with its literals. */
|
|
2833
|
+
type MaskValueFormat = "raw" | "formatted";
|
|
2834
|
+
/**
|
|
2835
|
+
* What `edit` does to `current` under the mask. A selection removes the
|
|
2836
|
+
* characters in it; Backspace removes the character before the caret and
|
|
2837
|
+
* Delete the one after it, stepping over literals; the characters after
|
|
2838
|
+
* move back, and one that no longer fits is dropped with the rest. An
|
|
2839
|
+
* insert fills the slots from the caret, each character the next slot that
|
|
2840
|
+
* accepts it, and a character equal to the next literal steps past it
|
|
2841
|
+
* (skipping optional slots before it). Typing is strict: a character no
|
|
2842
|
+
* slot takes, or one that would push another out, refuses the whole edit.
|
|
2843
|
+
* A paste, a drop, autofill or composed text is lenient: what fits nowhere
|
|
2844
|
+
* is dropped. The pattern is chosen again for what the edit leaves.
|
|
2845
|
+
*
|
|
2846
|
+
* The caret goes after the last character inserted and past the literals
|
|
2847
|
+
* after it; after a deletion, to where the first removed character was.
|
|
2848
|
+
* Undo, redo and other edits the mask cannot place leave `accepted` false.
|
|
2849
|
+
*/
|
|
2850
|
+
declare function applyMaskEdit(options: MaskOptions, current: MaskedText, edit: MaskEdit, focused: boolean): MaskResult;
|
|
2851
|
+
/**
|
|
2852
|
+
* `raw` laid into the mask, as a value from the app or a commit shows it,
|
|
2853
|
+
* with the caret at the first empty slot. Laid in leniently, so a
|
|
2854
|
+
* formatted value (with its literals) reads too.
|
|
2855
|
+
*/
|
|
2856
|
+
declare function formatMasked(options: MaskOptions, raw: string, focused: boolean): MaskResult;
|
|
2857
|
+
/** Whether `raw` can still become complete by typing more: some pattern takes every character of it, in order. */
|
|
2858
|
+
declare function isValidMaskStart(options: MaskOptions, raw: string): boolean;
|
|
2859
|
+
/** What the mask makes of `text`, focused or display text alike. */
|
|
2860
|
+
declare function maskDetails(options: MaskOptions, text: string): MaskDetails;
|
|
2861
|
+
|
|
2862
|
+
/**
|
|
2863
|
+
* A masked field's own reading: no character typed is `null`; complete
|
|
2864
|
+
* text is its raw characters, or with `valueFormat: "formatted"` its
|
|
2865
|
+
* formatted text; incomplete text is unreadable with
|
|
2866
|
+
* `messages.maskIncomplete`, so the value stays the last complete one.
|
|
2867
|
+
* Text with characters no slot takes (after an undo) is unreadable with
|
|
2868
|
+
* `messages.patternMismatch`.
|
|
2869
|
+
*/
|
|
2870
|
+
declare function maskParser(options: MaskOptions, valueFormat?: MaskValueFormat): (text: string, context: ParseContext<string>) => ParseResult<string>;
|
|
2871
|
+
/**
|
|
2872
|
+
* A masked field's own writing: the value laid into the mask, with the
|
|
2873
|
+
* prompt in empty slots while the field has focus (`purpose: "edit"`, so
|
|
2874
|
+
* an empty field shows the template), and the formatted text otherwise.
|
|
2875
|
+
*/
|
|
2876
|
+
declare function maskFormatter(options: MaskOptions): (value: string | null, context: FormatContext<string>) => string;
|
|
2877
|
+
/**
|
|
2878
|
+
* A masked field's judgement of an edit, its `filterInput`: the edit
|
|
2879
|
+
* worked out by `applyMaskEdit` on the text before it and the selection,
|
|
2880
|
+
* replacing the whole text and placing the caret, or refused. An edit with
|
|
2881
|
+
* no browser report (an app's change) and undo or redo stand as they are.
|
|
2882
|
+
* `options` hold the field's locale.
|
|
2883
|
+
*/
|
|
2884
|
+
declare function filterMaskEdit<N>(edit: TextEdit<N>, before: string, options: MaskOptions): InputFilterDecision;
|
|
2885
|
+
/** What a masked input tells the browser's keyboard. */
|
|
2886
|
+
interface MaskInputHints {
|
|
2887
|
+
/** `"numeric"` when every slot of every pattern is a built-in digit slot (`0`, `9`); a function mask is `"text"`. */
|
|
2888
|
+
readonly inputMode: "numeric" | "text";
|
|
2889
|
+
/** Whether a pattern upper-cases letters, for `autocapitalize="characters"`. A function mask is judged by its first pattern. */
|
|
2890
|
+
readonly upperCase: boolean;
|
|
2891
|
+
}
|
|
2892
|
+
/** The keyboard a mask wants. Throws on a malformed pattern, as the engine does. */
|
|
2893
|
+
declare function maskInputHints(options: MaskOptions): MaskInputHints;
|
|
2894
|
+
|
|
2895
|
+
/** A ready-made mask: its options, its check, the keyboard it wants and the value it keeps. */
|
|
2896
|
+
interface MaskPreset {
|
|
2897
|
+
readonly options: MaskOptions;
|
|
2898
|
+
/** Checks a complete value further: a checksum, a range. */
|
|
2899
|
+
readonly validate?: Validator<string> | undefined;
|
|
2900
|
+
readonly inputMode: "numeric" | "decimal" | "text";
|
|
2901
|
+
readonly autoComplete?: string | undefined;
|
|
2902
|
+
readonly valueFormat: MaskValueFormat;
|
|
2903
|
+
}
|
|
2904
|
+
/** The presets `MaskedInput` takes by name. */
|
|
2905
|
+
interface MaskPresets {
|
|
2906
|
+
/** An IBAN, grouped in fours, sized by its country; raw value, checked by `ibanRule`. */
|
|
2907
|
+
readonly iban: MaskPreset;
|
|
2908
|
+
/** A card number, grouped by its length; raw digits, checked by `luhnRule`. */
|
|
2909
|
+
readonly cardNumber: MaskPreset;
|
|
2910
|
+
/** An IPv4 address, `.` moving to the next part; formatted value, checked by `ipv4Rule`. */
|
|
2911
|
+
readonly ipv4: MaskPreset;
|
|
2912
|
+
/** `12345` or `12345-6789`. */
|
|
2913
|
+
readonly postalCodeUS: MaskPreset;
|
|
2914
|
+
/** `K1A 0B1`. */
|
|
2915
|
+
readonly postalCodeCA: MaskPreset;
|
|
2916
|
+
/** `SW1A 1AA`, `M1 1AA` and the other UK shapes. */
|
|
2917
|
+
readonly postalCodeGB: MaskPreset;
|
|
2918
|
+
/** `10115`. */
|
|
2919
|
+
readonly postalCodeDE: MaskPreset;
|
|
2920
|
+
/** `1012 AB`. */
|
|
2921
|
+
readonly postalCodeNL: MaskPreset;
|
|
2922
|
+
/** `01310-100`. */
|
|
2923
|
+
readonly postalCodeBR: MaskPreset;
|
|
2924
|
+
/** `100-0001`. */
|
|
2925
|
+
readonly postalCodeJP: MaskPreset;
|
|
2926
|
+
}
|
|
2927
|
+
/**
|
|
2928
|
+
* Ready-made masks. Postal codes keep their separators, as addresses print
|
|
2929
|
+
* them; an IPv4 address keeps its dots, which its raw digits would lose.
|
|
2930
|
+
*/
|
|
2931
|
+
declare const maskPresets: MaskPresets;
|
|
2932
|
+
|
|
2933
|
+
/**
|
|
2934
|
+
* An IBAN with the wrong length for its country, or whose check digits
|
|
2935
|
+
* fail, is `messages.ibanInvalid`. Spaces are ignored. `null` passes.
|
|
2936
|
+
*/
|
|
2937
|
+
declare function ibanRule(): Validator<string>;
|
|
2938
|
+
/** A card number whose check digit fails (Luhn) is `messages.cardNumberInvalid`. Spaces are ignored. `null` passes. */
|
|
2939
|
+
declare function luhnRule(): Validator<string>;
|
|
2940
|
+
/** An IPv4 address with a part above 255 or a leading zero is `messages.ipv4Invalid`. `null` passes. */
|
|
2941
|
+
declare function ipv4Rule(): Validator<string>;
|
|
2942
|
+
|
|
2943
|
+
/** How a locale writes numbers, read from `Intl.NumberFormat#formatToParts`. */
|
|
2944
|
+
interface NumberSymbols {
|
|
2945
|
+
/** The numbering system the field writes in: `"latn"`, `"arab"`, `"deva"`, ... */
|
|
2946
|
+
readonly numberingSystem: string;
|
|
2947
|
+
/** Its ten digits, zero first. */
|
|
2948
|
+
readonly digits: string;
|
|
2949
|
+
readonly decimal: string;
|
|
2950
|
+
/** `""` when the field writes no grouping. */
|
|
2951
|
+
readonly group: string;
|
|
2952
|
+
/** Digits in the last group, then in every group before it: `[3, 3]`, or `[3, 2]` for lakh grouping. */
|
|
2953
|
+
readonly groupSizes: readonly [primary: number, secondary: number];
|
|
2954
|
+
/** 2 where a four-digit number is written ungrouped ("1234" in `es-ES`), else 1. */
|
|
2955
|
+
readonly minimumGroupingDigits: 1 | 2;
|
|
2956
|
+
/** Without the direction marks Intl puts around it. */
|
|
2957
|
+
readonly minus: string;
|
|
2958
|
+
readonly percent: string;
|
|
2959
|
+
/** Whether the locale writes numbers left to right inside right-to-left text. */
|
|
2960
|
+
readonly numbersLeftToRight: boolean;
|
|
2961
|
+
}
|
|
2962
|
+
/** What a field may set over its locale's symbols. */
|
|
2963
|
+
interface NumberSymbolOverrides {
|
|
2964
|
+
/** Replaces the locale's decimal separator; it must differ from the group separator. */
|
|
2965
|
+
readonly decimalSeparator?: string | undefined;
|
|
2966
|
+
/** Replaces the locale's group separator; `""` writes no grouping. */
|
|
2967
|
+
readonly groupSeparator?: string | undefined;
|
|
2968
|
+
readonly groupSizes?: readonly [primary: number, secondary: number] | undefined;
|
|
2969
|
+
/** The digits the field writes: `"latn"` keeps Latin digits in `ar-EG`. */
|
|
2970
|
+
readonly numberingSystem?: string | undefined;
|
|
2971
|
+
}
|
|
2972
|
+
/**
|
|
2973
|
+
* How `locale` writes numbers: its separators, group sizes, digits, minus
|
|
2974
|
+
* and percent signs, read from Intl at run time (they differ between ICU
|
|
2975
|
+
* versions), with the field's overrides laid over them. Separators that
|
|
2976
|
+
* would clash (an empty decimal separator, or both the same) and group
|
|
2977
|
+
* sizes that are not positive whole numbers are ignored, leaving the
|
|
2978
|
+
* locale's own. Cached per locale and overrides.
|
|
2979
|
+
*/
|
|
2980
|
+
declare function numberSymbols(locale: Intl.LocalesArgument, overrides?: NumberSymbolOverrides): NumberSymbols;
|
|
2981
|
+
|
|
2982
|
+
type NumberStyle = "decimal" | "percent" | "currency" | "unit";
|
|
2983
|
+
/** How a negative number is written: `-12`, `(12)` or `12-`. Each is read in every field. */
|
|
2984
|
+
type NegativeStyle = "minus" | "parentheses" | "trailingMinus";
|
|
2985
|
+
/** Whether 12 % is stored as 0.12 (`"fraction"`, Intl's reading) or as 12 (`"percent"`). */
|
|
2986
|
+
type PercentScale = "fraction" | "percent";
|
|
2987
|
+
/** What a number field holds: a JS `number`, or an exact decimal string. */
|
|
2988
|
+
type NumberValueType = "number" | "decimal";
|
|
2989
|
+
/** The value type `T` names. */
|
|
2990
|
+
type NumberValue<T extends NumberValueType> = T extends "decimal" ? string : number;
|
|
2991
|
+
/**
|
|
2992
|
+
* How numbers read and write. Every name `Intl.NumberFormatOptions` also
|
|
2993
|
+
* has means what it means there, so a grid column's `format` can be passed
|
|
2994
|
+
* on. As in Intl, `currency` and `unit` take effect with their `style`, and
|
|
2995
|
+
* an unknown currency code or unit throws Intl's `RangeError`.
|
|
2996
|
+
*/
|
|
2997
|
+
interface NumberOptions extends NumberSymbolOverrides {
|
|
2998
|
+
readonly locale?: Intl.LocalesArgument;
|
|
2999
|
+
/** `"decimal"` by default. */
|
|
3000
|
+
readonly style?: NumberStyle | undefined;
|
|
3001
|
+
/** ISO 4217 code; with `style: "currency"`. */
|
|
3002
|
+
readonly currency?: string | undefined;
|
|
3003
|
+
/** `"symbol"` by default. */
|
|
3004
|
+
readonly currencyDisplay?: "symbol" | "narrowSymbol" | "code" | "name" | undefined;
|
|
3005
|
+
/** An Intl unit identifier (`"kilogram"`, `"kilometer-per-hour"`); with `style: "unit"`. */
|
|
3006
|
+
readonly unit?: string | undefined;
|
|
3007
|
+
/** `"short"` by default. */
|
|
3008
|
+
readonly unitDisplay?: "short" | "narrow" | "long" | undefined;
|
|
3009
|
+
/** 0 by default; a currency's minor units. For a percent, of the number shown. */
|
|
3010
|
+
readonly minimumFractionDigits?: number | undefined;
|
|
3011
|
+
/** Unset: no rounding, every digit typed is kept (a currency: its minor units). */
|
|
3012
|
+
readonly maximumFractionDigits?: number | undefined;
|
|
3013
|
+
/** `"halfExpand"` (ties away from zero) by default. */
|
|
3014
|
+
readonly roundingMode?: RoundingMode | undefined;
|
|
3015
|
+
/** Group the integer digits when the value is shown formatted. On by default. */
|
|
3016
|
+
readonly useGrouping?: boolean | undefined;
|
|
3017
|
+
/** `"minus"` by default. */
|
|
3018
|
+
readonly negative?: NegativeStyle | undefined;
|
|
3019
|
+
/** `"fraction"` by default. */
|
|
3020
|
+
readonly percentScale?: PercentScale | undefined;
|
|
3021
|
+
}
|
|
3022
|
+
/** The fraction digits a field writes, and rounds its value to. */
|
|
3023
|
+
interface FractionDigits {
|
|
3024
|
+
readonly minimum: number;
|
|
3025
|
+
/** `null`: no rounding, every digit is kept. */
|
|
3026
|
+
readonly maximum: number | null;
|
|
3027
|
+
}
|
|
3028
|
+
/**
|
|
3029
|
+
* The fraction digits `options` ask for: the minimum written and the
|
|
3030
|
+
* maximum kept. A currency defaults both to its minor units; otherwise the
|
|
3031
|
+
* minimum is 0 and there is no maximum. A maximum below the minimum is
|
|
3032
|
+
* raised to it. A field has fixed decimals when the two are equal.
|
|
3033
|
+
*/
|
|
3034
|
+
declare function numberFractionDigits(options?: NumberOptions): FractionDigits;
|
|
3035
|
+
|
|
3036
|
+
/** How a text was read. */
|
|
3037
|
+
interface NumberReadingInfo {
|
|
3038
|
+
/** The character taken as the decimal point, as typed; `null` when there was none. */
|
|
3039
|
+
readonly decimalSeparator: string | null;
|
|
3040
|
+
/** Whether the integer digits were grouped. */
|
|
3041
|
+
readonly grouped: boolean;
|
|
3042
|
+
/** How a negative number was written; `null` for one that is not negative. */
|
|
3043
|
+
readonly negative: NegativeStyle | null;
|
|
3044
|
+
/** The numbering systems of the digits typed, in the order met: `["latn"]`, `["arab"]`, `["latn", "fullwide"]`. */
|
|
3045
|
+
readonly digits: readonly string[];
|
|
3046
|
+
/** The text was a paste or drop that clean-up rewrote. */
|
|
3047
|
+
readonly cleaned: boolean;
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
/** A paste turned into the field's own text, and how it was read. */
|
|
3051
|
+
interface CleanedNumber {
|
|
3052
|
+
/** The field's edit text: its digits and decimal separator, a leading minus, no grouping, every digit kept. */
|
|
3053
|
+
readonly text: string;
|
|
3054
|
+
/** How the pasted text was read; `cleaned` is true. */
|
|
3055
|
+
readonly info: NumberReadingInfo;
|
|
3056
|
+
}
|
|
3057
|
+
/**
|
|
3058
|
+
* Turns pasted or dropped text, copied from a web page, a PDF or a
|
|
3059
|
+
* spreadsheet in another locale, into the field's own edit text, or
|
|
3060
|
+
* returns `null` to refuse it. Currency signs and codes, percent signs and
|
|
3061
|
+
* the field's unit are dropped; parentheses or a leading or trailing minus
|
|
3062
|
+
* give the sign; any other letter refuses the paste, since dropping it
|
|
3063
|
+
* could change the number ("12abc", "1e5"). When both `.` and `,` appear,
|
|
3064
|
+
* the last is the decimal point ("$1,234.50" becomes "1234,50" in
|
|
3065
|
+
* `de-DE`); a lone mark is decided by the field's locale, so "1.234"
|
|
3066
|
+
* pasted into `de-DE` is 1234.
|
|
3067
|
+
*/
|
|
3068
|
+
declare function cleanPastedNumber(text: string, options?: NumberOptions): CleanedNumber | null;
|
|
3069
|
+
|
|
3070
|
+
/**
|
|
3071
|
+
* Which text `formatNumber` writes:
|
|
3072
|
+
*
|
|
3073
|
+
* - `display`: what a field shows when it does not have focus: grouped,
|
|
3074
|
+
* fraction digits padded, the negative style; no currency, percent sign
|
|
3075
|
+
* or unit.
|
|
3076
|
+
* - `edit`: what a focused field shows: no grouping, a leading minus, the
|
|
3077
|
+
* digits the value has, padded to the minimum.
|
|
3078
|
+
* - `full`: Intl's whole text, with the currency, percent sign or unit, as
|
|
3079
|
+
* display mode, the `formatted` event detail and a grid cell show it.
|
|
3080
|
+
*/
|
|
3081
|
+
type NumberTextForm = "display" | "edit" | "full";
|
|
3082
|
+
/** Where the currency, percent sign or unit sits around the number, for an input's adornments. */
|
|
3083
|
+
interface NumberAffixes {
|
|
3084
|
+
readonly prefix: string;
|
|
3085
|
+
readonly suffix: string;
|
|
3086
|
+
}
|
|
3087
|
+
/**
|
|
3088
|
+
* `value` as text, in one of three forms (`display` by default; see
|
|
3089
|
+
* `NumberTextForm`). A decimal string is formatted without passing through
|
|
3090
|
+
* a JS number, so every digit of a 20-digit amount is written. With no
|
|
3091
|
+
* maximum, every fraction digit of the value is written; with one, the
|
|
3092
|
+
* value is rounded to it by `roundingMode`. Nothing is written as "-0".
|
|
3093
|
+
* Throws a `RangeError` for a string that is not a decimal, or a number
|
|
3094
|
+
* that is not finite.
|
|
3095
|
+
*/
|
|
3096
|
+
declare function formatNumber(value: NumberLike, options?: NumberOptions, form?: NumberTextForm): string;
|
|
3097
|
+
/**
|
|
3098
|
+
* The currency, percent sign or unit written before and after the number
|
|
3099
|
+
* in `full` text, trimmed of spacing, for an input to draw beside its
|
|
3100
|
+
* text: `$` before in `en-US`, `€` after in `de-DE`, `%` before in
|
|
3101
|
+
* `tr-TR`. A spelled-out name agrees with `value` ("1 euro", "2 euros");
|
|
3102
|
+
* without one it is written for 0. Both are `""` for a plain decimal.
|
|
3103
|
+
*/
|
|
3104
|
+
declare function numberAffixes(options?: NumberOptions, value?: NumberLike): NumberAffixes;
|
|
3105
|
+
/**
|
|
3106
|
+
* Intl's text for the range from `start` to `end`, in the `full` form:
|
|
3107
|
+
* "10–20", "10,00–20,00 €". Ends that write the same are written once
|
|
3108
|
+
* ("10", where Intl writes "~10"). A negative end in another `negative`
|
|
3109
|
+
* style than the minus writes each end whole around the locale's range
|
|
3110
|
+
* separator: "(10)–20".
|
|
3111
|
+
*/
|
|
3112
|
+
declare function formatNumberRange(start: NumberLike, end: NumberLike, options?: NumberOptions): string;
|
|
3113
|
+
|
|
3114
|
+
/** How a number field takes what is typed, pasted and dropped into it. */
|
|
3115
|
+
interface NumberEntryOptions extends NumberOptions {
|
|
3116
|
+
/** Whether a minus or parentheses may be typed; false for a field whose `min` is 0 or above. True by default. */
|
|
3117
|
+
readonly negatives?: boolean | undefined;
|
|
3118
|
+
/** Refuses a digit that would type more fraction digits than the maximum, instead of rounding them. */
|
|
3119
|
+
readonly limitFractionDigits?: boolean | undefined;
|
|
3120
|
+
/**
|
|
3121
|
+
* `"fixed"` (default): a field with fixed decimals shows them all while
|
|
3122
|
+
* it has a value, the decimal separator jumps into them and they are
|
|
3123
|
+
* typed over. `"free"`: digits and one separator, typed as anywhere else.
|
|
3124
|
+
*/
|
|
3125
|
+
readonly decimalEntry?: "fixed" | "free" | undefined;
|
|
3126
|
+
}
|
|
3127
|
+
/** What a number field does with an edit, and how clean-up read a paste. */
|
|
3128
|
+
interface NumberEntry {
|
|
3129
|
+
readonly decision: InputFilterDecision;
|
|
3130
|
+
/** How clean-up read the paste or drop the decision inserts; `null` for any other edit. */
|
|
3131
|
+
readonly pasted: NumberReadingInfo | null;
|
|
3132
|
+
}
|
|
3133
|
+
/**
|
|
3134
|
+
* The fraction digits a field types in place, or `null` when it types
|
|
3135
|
+
* them freely: with fixed-decimal entry, a minimum equal to a maximum
|
|
3136
|
+
* above zero.
|
|
3137
|
+
*/
|
|
3138
|
+
declare function fixedFractionDigits(options: NumberEntryOptions): number | null;
|
|
3139
|
+
/**
|
|
3140
|
+
* A number field's judgement of an edit, its `filterInput`: `edit` is the
|
|
3141
|
+
* edit as the app's `onBeforeInput` left it, `before` the text before it.
|
|
3142
|
+
*
|
|
3143
|
+
* Free entry keeps what can still become a number: digits, the decimal
|
|
3144
|
+
* separator once (none in a field with no fraction digits), group
|
|
3145
|
+
* separators where the grouping allows, a sign (none when `negatives` is
|
|
3146
|
+
* false). Letters, currency signs and the rest are refused, deletions and
|
|
3147
|
+
* undo always stand, and a paste or drop is cleaned by `cleanPastedNumber`
|
|
3148
|
+
* and inserted in its place, or refused.
|
|
3149
|
+
*
|
|
3150
|
+
* A field with fixed decimals (`fixedFractionDigits`) replaces the whole
|
|
3151
|
+
* text on every edit instead: the decimals always show once it has a
|
|
3152
|
+
* value, digits go before them, the decimal separator (or `.` or `,`)
|
|
3153
|
+
* moves the caret into them, they are typed over and never grow, and deleting turns
|
|
3154
|
+
* one to zero. A paste is rounded to them. Text that is not a
|
|
3155
|
+
* fixed-decimal text (after an undo) is edited freely until it is again.
|
|
3156
|
+
*/
|
|
3157
|
+
declare function filterNumberEdit<N>(edit: TextEdit<N>, before: string, options?: NumberEntryOptions): NumberEntry;
|
|
3158
|
+
/**
|
|
3159
|
+
* Where the caret goes when a number field's text is written again (the
|
|
3160
|
+
* edit form on focus, the padded text on commit): after as many digits,
|
|
3161
|
+
* decimal separators and signs as it had before it, so group separators
|
|
3162
|
+
* added or removed around it do not move it. A caret at the end stays at
|
|
3163
|
+
* the end.
|
|
3164
|
+
*/
|
|
3165
|
+
declare function numberCaret(options?: NumberOptions): (previousText: string, caret: number, nextText: string) => number;
|
|
3166
|
+
|
|
3167
|
+
/** How a number field reads and writes, and the value type it holds. */
|
|
3168
|
+
interface NumberFieldOptions<T extends NumberValueType = NumberValueType> extends NumberOptions {
|
|
3169
|
+
/** `"number"` (default): a JS number. `"decimal"`: an exact decimal string (`"1234.50"`). */
|
|
3170
|
+
readonly valueType?: T | undefined;
|
|
3171
|
+
}
|
|
3172
|
+
/** What a number field adds to every event it fires. */
|
|
3173
|
+
interface NumberDetails {
|
|
3174
|
+
/** The value as an exact decimal string, whatever the value type; `null` when empty. */
|
|
3175
|
+
readonly decimal: DecimalString | null;
|
|
3176
|
+
/** The value as display mode writes it, currency, percent sign or unit included; `""` when empty. */
|
|
3177
|
+
readonly formatted: string;
|
|
3178
|
+
/** How the text on screen reads; `null` while it shows the value formatted, or cannot be read. */
|
|
3179
|
+
readonly reading: NumberReadingInfo | null;
|
|
3180
|
+
}
|
|
3181
|
+
/**
|
|
3182
|
+
* A number field's own reading: `parseNumber`, then the value rounded to
|
|
3183
|
+
* the maximum fraction digits by `roundingMode` (so `onChange` carries the
|
|
3184
|
+
* value that will be stored), scaled for a percent, and held as the value
|
|
3185
|
+
* type. As a JS number, text whose rounded digits a number cannot keep
|
|
3186
|
+
* exactly ("9007199254740993") is unreadable rather than silently changed.
|
|
3187
|
+
* The locale is the field's unless `options` names one.
|
|
3188
|
+
*/
|
|
3189
|
+
declare function numberParser<T extends NumberValueType = "number">(options?: NumberFieldOptions<T>): (text: string, context: ParseContext<NumberValue<T>>) => ParseResult<NumberValue<T>>;
|
|
3190
|
+
/**
|
|
3191
|
+
* A number field's own writing: the `edit` form while it has focus and the
|
|
3192
|
+
* `display` form otherwise (`FormatContext.purpose`), `""` for `null`. The
|
|
3193
|
+
* locale is the field's unless `options` names one.
|
|
3194
|
+
*/
|
|
3195
|
+
declare function numberFormatter<V extends NumberLike>(options?: NumberOptions): (value: V | null, context: FormatContext<V>) => string;
|
|
3196
|
+
/**
|
|
3197
|
+
* A number field's details for `state`, what its `FieldOptions.details`
|
|
3198
|
+
* returns. `pasted` is how clean-up read the paste the text on screen came
|
|
3199
|
+
* from, which the input remembers until the next edit (`cleanPastedNumber`);
|
|
3200
|
+
* without it, `reading` describes the text as typed. `options` holds the
|
|
3201
|
+
* field's locale.
|
|
3202
|
+
*/
|
|
3203
|
+
declare function numberDetails<V extends NumberLike>(state: FieldState<V>, options: NumberOptions, pasted?: NumberReadingInfo | null): NumberDetails;
|
|
3204
|
+
/** A step a number field takes, its numbers in the field's value units. */
|
|
3205
|
+
interface NumberStep {
|
|
3206
|
+
readonly direction: StepDirection;
|
|
3207
|
+
readonly size: StepSize;
|
|
3208
|
+
/** Above zero. */
|
|
3209
|
+
readonly step: NumberLike;
|
|
3210
|
+
readonly largeStep: NumberLike;
|
|
3211
|
+
readonly min: NumberLike | null;
|
|
3212
|
+
readonly max: NumberLike | null;
|
|
3213
|
+
}
|
|
3214
|
+
/**
|
|
3215
|
+
* The value a step takes a number field to, as `stepNumber` works it out
|
|
3216
|
+
* exactly, rounded to the field's maximum fraction digits (of the number
|
|
3217
|
+
* shown, for a percent) and held as its value type. At a limit it is the
|
|
3218
|
+
* value the field has; from empty, the starting point.
|
|
3219
|
+
*/
|
|
3220
|
+
declare function stepNumberValue<T extends NumberValueType = "number">(value: NumberValue<T> | null, step: NumberStep, options?: NumberFieldOptions<T>): NumberValue<T> | null;
|
|
3221
|
+
|
|
3222
|
+
/**
|
|
3223
|
+
* Why a text is not a number:
|
|
3224
|
+
*
|
|
3225
|
+
* - `notANumber`: a letter, a second decimal separator, a group separator
|
|
3226
|
+
* after it, an exponent.
|
|
3227
|
+
* - `incomplete`: a sign or separator with no digit yet ("-", ","), or an
|
|
3228
|
+
* opening parenthesis with no closing one.
|
|
3229
|
+
* - `grouping`: group separators where the field does not group ("1,5" in
|
|
3230
|
+
* `en-US`).
|
|
3231
|
+
* - `tooPrecise`: more digits than a JS number keeps exactly, for a field
|
|
3232
|
+
* holding numbers (`numberParser`).
|
|
3233
|
+
*
|
|
3234
|
+
* A minor release may add a member.
|
|
3235
|
+
*/
|
|
3236
|
+
type NumberUnreadableReason = "notANumber" | "incomplete" | "grouping" | "tooPrecise";
|
|
3237
|
+
/** What a text reads as: nothing, an exact number, or why it is not one. */
|
|
3238
|
+
type NumberReading = {
|
|
3239
|
+
readonly kind: "empty";
|
|
3240
|
+
} | {
|
|
3241
|
+
readonly kind: "number";
|
|
3242
|
+
/** Exact, as typed: point decimal, no grouping, no trailing fraction zeros. */
|
|
3243
|
+
readonly decimal: DecimalString;
|
|
3244
|
+
readonly info: NumberReadingInfo;
|
|
3245
|
+
} | {
|
|
3246
|
+
readonly kind: "unreadable";
|
|
3247
|
+
readonly reason: NumberUnreadableReason;
|
|
3248
|
+
};
|
|
3249
|
+
/**
|
|
3250
|
+
* Reads text a user typed, strictly by the field's symbols, as an exact
|
|
3251
|
+
* decimal; it never rounds or guesses. It takes:
|
|
3252
|
+
*
|
|
3253
|
+
* - any Unicode decimal digits (`١٢٣` reads as 123 in `en-US`), and
|
|
3254
|
+
* full-width forms from an input method;
|
|
3255
|
+
* - the field's decimal separator once, and its group separator between
|
|
3256
|
+
* integer digits where its grouping allows ("1,5" is `grouping` in
|
|
3257
|
+
* `en-US`), each with its lookalikes (any space for a space);
|
|
3258
|
+
* - a leading `-` or `+`, a trailing `-`, or parentheses;
|
|
3259
|
+
* - the field's own currency sign or code, percent sign or unit at either
|
|
3260
|
+
* end, so its `full` text reads back.
|
|
3261
|
+
*
|
|
3262
|
+
* "12," reads as 12, ",5" as 0.5, "007" as 7, and "-0" as 0.
|
|
3263
|
+
*/
|
|
3264
|
+
declare function parseNumber(text: string, options?: NumberOptions): NumberReading;
|
|
3265
|
+
|
|
3266
|
+
/**
|
|
3267
|
+
* The range kind of JS numbers. The span is `end - start`, worked out
|
|
3268
|
+
* exactly (0.3 to 0.1 spans 0.2, never 0.19999999999999998), the same
|
|
3269
|
+
* whatever the bounds. Numbers show the end they store, so it has no
|
|
3270
|
+
* shown-versus-stored conversion.
|
|
3271
|
+
*/
|
|
3272
|
+
declare const numberRangeKind: RangeKind<number>;
|
|
3273
|
+
/** The range kind of exact decimal strings: as `numberRangeKind`, the span a decimal string too. */
|
|
3274
|
+
declare const decimalRangeKind: RangeKind<DecimalString, NoFlags, DecimalString>;
|
|
3275
|
+
/** The range kind of a number field's value type: `numberRangeKind`, or `decimalRangeKind` for `"decimal"`. */
|
|
3276
|
+
declare function numberRangeKindOf<T extends NumberValueType = "number">(valueType: T | undefined): RangeKind<NumberValue<T>, NoFlags, NumberValue<T>>;
|
|
3277
|
+
|
|
3278
|
+
/**
|
|
3279
|
+
* A number below `min` is `messages.rangeUnderflow`, "Enter 10 or more".
|
|
3280
|
+
* Compared as exact decimals, so either value type works and a decimal
|
|
3281
|
+
* limit keeps every digit. `options` are the field's, to write `min` the
|
|
3282
|
+
* way it writes numbers. `null` passes.
|
|
3283
|
+
*/
|
|
3284
|
+
declare function minRule<V extends NumberLike>(min: NumberLike, options?: NumberOptions): Validator<V>;
|
|
3285
|
+
/** A number above `max` is `messages.rangeOverflow`, "Enter 100 or less"; otherwise as `minRule`. */
|
|
3286
|
+
declare function maxRule<V extends NumberLike>(max: NumberLike, options?: NumberOptions): Validator<V>;
|
|
3287
|
+
/**
|
|
3288
|
+
* A number that is not a whole number of `step`s from `base` is
|
|
3289
|
+
* `messages.stepMismatch`, "Enter a multiple of 0.05". Exact, so 0.15 is
|
|
3290
|
+
* three steps of 0.05. A number input's `step` only drives stepping; this
|
|
3291
|
+
* rule is for a field whose values must sit on it. Throws a `RangeError`
|
|
3292
|
+
* for a step that is not above zero. `null` passes.
|
|
3293
|
+
*/
|
|
3294
|
+
declare function stepRule<V extends NumberLike>(step: NumberLike, base?: NumberLike, options?: NumberOptions): Validator<V>;
|
|
3295
|
+
|
|
3296
|
+
/** What opened a popup: its button, or a key in the field (F4, Alt+ArrowDown). */
|
|
3297
|
+
type PopupOpenReason = "button" | "keyboard";
|
|
3298
|
+
/**
|
|
3299
|
+
* What closed a popup: Escape; a press outside it; a scroll outside it or
|
|
3300
|
+
* the window resizing, which would leave it behind its field; focus or
|
|
3301
|
+
* the window leaving it; the overlay it was opened above closing
|
|
3302
|
+
* (`"parent"`); its button pressed again; a value chosen in it
|
|
3303
|
+
* (`"picker"`); or the field turning disabled, read-only or display-only.
|
|
3304
|
+
*/
|
|
3305
|
+
type PopupCloseReason = "escape" | "outside" | "scroll" | "resize" | "blur" | "parent" | "button" | "picker" | "disabled";
|
|
3306
|
+
/** What `onOpenChange` is told as a popup opens or closes. */
|
|
3307
|
+
type PopupOpenChange = {
|
|
3308
|
+
readonly open: true;
|
|
3309
|
+
readonly reason: PopupOpenReason;
|
|
3310
|
+
} | {
|
|
3311
|
+
readonly open: false;
|
|
3312
|
+
readonly reason: PopupCloseReason;
|
|
3313
|
+
};
|
|
3314
|
+
/** Whether a popup is open, and what opened it. */
|
|
3315
|
+
type PopupState = {
|
|
3316
|
+
readonly kind: "closed";
|
|
3317
|
+
} | {
|
|
3318
|
+
readonly kind: "open";
|
|
3319
|
+
readonly openedBy: PopupOpenReason;
|
|
3320
|
+
};
|
|
3321
|
+
/** What can happen to a popup. */
|
|
3322
|
+
type PopupAction = {
|
|
3323
|
+
readonly type: "open";
|
|
3324
|
+
readonly reason: PopupOpenReason;
|
|
3325
|
+
} | {
|
|
3326
|
+
readonly type: "close";
|
|
3327
|
+
readonly reason: PopupCloseReason;
|
|
3328
|
+
}
|
|
3329
|
+
/** Its button: opens a closed popup, closes an open one. */
|
|
3330
|
+
| {
|
|
3331
|
+
readonly type: "toggle";
|
|
3332
|
+
};
|
|
3333
|
+
/** The popup after an action, and what `onOpenChange` is told: `null` when nothing changed. */
|
|
3334
|
+
interface PopupStep {
|
|
3335
|
+
readonly state: PopupState;
|
|
3336
|
+
readonly change: PopupOpenChange | null;
|
|
3337
|
+
}
|
|
3338
|
+
declare const POPUP_CLOSED: PopupState;
|
|
3339
|
+
/**
|
|
3340
|
+
* A popup's open state after `action`. Opening an open popup and closing
|
|
3341
|
+
* a closed one change nothing, so `onOpenChange` hears each change once.
|
|
3342
|
+
*/
|
|
3343
|
+
declare function popupReducer(state: PopupState, action: PopupAction): PopupStep;
|
|
3344
|
+
|
|
3345
|
+
/** The parts of a range input: its two ends, each a value of `T`. */
|
|
3346
|
+
type RangeEnds<T> = {
|
|
3347
|
+
start: T;
|
|
3348
|
+
end: T;
|
|
3349
|
+
};
|
|
3350
|
+
/** What every range input adds to its events. */
|
|
3351
|
+
interface RangeDetails<T, F extends object = NoFlags, S = number, R = never> {
|
|
3352
|
+
/**
|
|
3353
|
+
* The end this event is about: the end typed in; `"both"` for a value
|
|
3354
|
+
* set whole (`setValue`, a controlled value, a revert or clear); on a
|
|
3355
|
+
* commit, the end that differs from the last commit (`"both"` when both
|
|
3356
|
+
* do, `null` when neither does).
|
|
3357
|
+
*/
|
|
3358
|
+
readonly changedEnd: RangeEnd | "both" | null;
|
|
3359
|
+
/** The ends the value stands for now: the value itself, or its rule resolved. `null` when empty. */
|
|
3360
|
+
readonly resolved: Range<T, F> | null;
|
|
3361
|
+
/** From start to end; `null` while an end is open or the field is empty. */
|
|
3362
|
+
readonly span: S | null;
|
|
3363
|
+
readonly bounds: RangeBounds;
|
|
3364
|
+
/** Each end's text as shown. */
|
|
3365
|
+
readonly startText: string;
|
|
3366
|
+
readonly endText: string;
|
|
3367
|
+
/** The rule, when the value is one. */
|
|
3368
|
+
readonly rule: R | null;
|
|
3369
|
+
}
|
|
3370
|
+
/**
|
|
3371
|
+
* The range two ends as shown make, for a range input's `assemble`:
|
|
3372
|
+
* `orderRange` with its refusals as `messages.rangeReversed` and
|
|
3373
|
+
* `messages.rangeEmpty`, and both ends empty as `null`.
|
|
3374
|
+
*/
|
|
3375
|
+
declare function readRangeEnds<T, F extends object, S, C, R>(kind: RangeKind<T, F, S, C, R>, ends: PartValues<RangeEnds<T>>, options: RangeOptions<S>, context: C, { messages }: AssembleContext): ParseResult<Range<T, F>>;
|
|
3376
|
+
/** The ends a range input shows for `range`, for its `split`: the end through `toShownEnd` when half-open. */
|
|
3377
|
+
declare function rangeEnds<T, F extends object, S, C, R>(kind: RangeKind<T, F, S, C, R>, range: Range<T, F> | null, bounds: RangeBounds, context: C): PartValues<RangeEnds<T>>;
|
|
3378
|
+
/** What a range input's events carry, from its value and its ends' texts. */
|
|
3379
|
+
declare function rangeDetails<T, F extends object, S, C, R = never>(kind: RangeKind<T, F, S, C, R>, resolved: Range<T, F> | null, changed: PartChange<RangeEnds<T>>, texts: PartTexts<RangeEnds<T>>, bounds: RangeBounds, context: C, rule?: R | null): RangeDetails<T, F, S, R>;
|
|
3380
|
+
|
|
3381
|
+
/** What a form knows of one of its fields: enough to list its messages. */
|
|
3382
|
+
interface RegisteredField {
|
|
3383
|
+
/** Unique in the form: the id of the element a message links to. */
|
|
3384
|
+
readonly id: string;
|
|
3385
|
+
/** The messages the field shows, in its own order. */
|
|
3386
|
+
readonly messages: readonly FieldMessage[];
|
|
3387
|
+
}
|
|
3388
|
+
/**
|
|
3389
|
+
* The fields of one form, for a summary of their messages, and the fields'
|
|
3390
|
+
* ways to reveal their messages, for a submit attempt. A renderer creates
|
|
3391
|
+
* one per form; fields register and unregister themselves.
|
|
3392
|
+
*/
|
|
3393
|
+
interface FieldRegistry<F extends RegisteredField> {
|
|
3394
|
+
/**
|
|
3395
|
+
* Adds `field`, in place of a field registered under the same id, and
|
|
3396
|
+
* returns what removes it again.
|
|
3397
|
+
*/
|
|
3398
|
+
readonly register: (field: F) => () => void;
|
|
3399
|
+
/**
|
|
3400
|
+
* Adds what shows one field's messages, as a commit attempt would, and
|
|
3401
|
+
* returns what removes it again.
|
|
3402
|
+
*/
|
|
3403
|
+
readonly addRevealer: (reveal: () => void) => () => void;
|
|
3404
|
+
/** Shows every field's messages, as a submit attempt does. */
|
|
3405
|
+
readonly revealAll: () => void;
|
|
3406
|
+
/**
|
|
3407
|
+
* Every registered field, in the order the registry was created with.
|
|
3408
|
+
* The same array until a field registers or unregisters.
|
|
3409
|
+
*/
|
|
3410
|
+
readonly getFields: () => readonly F[];
|
|
3411
|
+
/** Calls `listener` whenever the fields change, and returns what stops it. */
|
|
3412
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
3413
|
+
}
|
|
3414
|
+
/**
|
|
3415
|
+
* A registry of a form's fields, listed in `order`, or in the order they
|
|
3416
|
+
* registered without one. A renderer passes its fields' place in the page,
|
|
3417
|
+
* which forms-core cannot see.
|
|
3418
|
+
*/
|
|
3419
|
+
declare function createFieldRegistry<F extends RegisteredField>(order?: (a: F, b: F) => number): FieldRegistry<F>;
|
|
3420
|
+
/** One line of a message summary: a message and the field showing it. */
|
|
3421
|
+
interface SummaryItem<F extends RegisteredField> {
|
|
3422
|
+
readonly field: F;
|
|
3423
|
+
readonly message: FieldMessage;
|
|
3424
|
+
}
|
|
3425
|
+
/** How many messages of one severity a summary lists. */
|
|
3426
|
+
interface SeverityCount {
|
|
3427
|
+
readonly severity: Severity;
|
|
3428
|
+
readonly count: number;
|
|
3429
|
+
}
|
|
3430
|
+
/** What a message summary lists. */
|
|
3431
|
+
interface MessageSummary<F extends RegisteredField> {
|
|
3432
|
+
/** Field by field in their order, each field's most serious first. */
|
|
3433
|
+
readonly items: readonly SummaryItem<F>[];
|
|
3434
|
+
/** Most serious first, leaving out a severity with none. */
|
|
3435
|
+
readonly counts: readonly SeverityCount[];
|
|
3436
|
+
}
|
|
3437
|
+
/** The messages of `fields` whose severity is one of `severities`, with their counts. */
|
|
3438
|
+
declare function summarizeMessages<F extends RegisteredField>(fields: readonly F[], severities: readonly Severity[]): MessageSummary<F>;
|
|
3439
|
+
|
|
3440
|
+
/** How a text input reads its text. */
|
|
3441
|
+
interface TextParseOptions {
|
|
3442
|
+
/** Drops leading and trailing whitespace from the value. */
|
|
3443
|
+
readonly trim?: boolean | undefined;
|
|
3444
|
+
/** Upper-cases the value in the context's locale. */
|
|
3445
|
+
readonly uppercase?: boolean | undefined;
|
|
3446
|
+
}
|
|
3447
|
+
/**
|
|
3448
|
+
* A text input's own reading: the text as it is, trimmed or upper-cased
|
|
3449
|
+
* when asked, and `null` when that leaves it empty. Whitespace is kept
|
|
3450
|
+
* unless `trim` is set, so `requiredRule` is what refuses a blank value.
|
|
3451
|
+
* Text always reads, so it never returns `unreadable`.
|
|
3452
|
+
*/
|
|
3453
|
+
declare function textParser(options?: TextParseOptions): (text: string, context: ParseContext<string>) => ParseResult<string>;
|
|
3454
|
+
/** A text input's own formatting: the value as it is, `""` for `null`. */
|
|
3455
|
+
declare function formatText(value: string | null): string;
|
|
3456
|
+
/**
|
|
3457
|
+
* The characters in `text` as a `maxLength` counts them: code points,
|
|
3458
|
+
* closer to "characters" than UTF-16 units, and how databases count a
|
|
3459
|
+
* `VARCHAR`. A simple emoji is one; a composed one (a family, a flag) is
|
|
3460
|
+
* several, as a database would count it.
|
|
3461
|
+
*/
|
|
3462
|
+
declare function countCharacters(text: string): number;
|
|
3463
|
+
/**
|
|
3464
|
+
* What a character counter announces when typing pauses: the characters
|
|
3465
|
+
* left once 10% of `max` or fewer remain, the characters too many once
|
|
3466
|
+
* over it, else nothing.
|
|
3467
|
+
*/
|
|
3468
|
+
declare function counterAnnouncement(count: number, max: number, messages: FormsMessages): string | null;
|
|
3469
|
+
|
|
3470
|
+
/**
|
|
3471
|
+
* The index of the item `query` — what was typed, buffered for a moment —
|
|
3472
|
+
* picks, matched case-insensitively against the start of each label and
|
|
3473
|
+
* wrapping round the end; `-1` when none matches.
|
|
3474
|
+
*
|
|
3475
|
+
* `from` is the item focused now. A single letter, or the same letter
|
|
3476
|
+
* typed again and again, searches from the item after it, so repeating a
|
|
3477
|
+
* letter steps through every item it starts. A longer query searches from
|
|
3478
|
+
* `from` itself, so the item already found stays put while what is typed
|
|
3479
|
+
* still matches it.
|
|
3480
|
+
*/
|
|
3481
|
+
declare function typeaheadIndex(labels: readonly string[], from: number, query: string): number;
|
|
3482
|
+
|
|
3483
|
+
/**
|
|
3484
|
+
* One entry per row: its measured height once known, `undefined` until then.
|
|
3485
|
+
* A row never yet rendered (or rendered but not yet observed) falls back to
|
|
3486
|
+
* `visibleRange`'s own `estimatedHeight` argument.
|
|
3487
|
+
*/
|
|
3488
|
+
type RowHeights = readonly (number | undefined)[];
|
|
3489
|
+
interface VisibleRange {
|
|
3490
|
+
readonly startIndex: number;
|
|
3491
|
+
readonly endIndex: number;
|
|
3492
|
+
/** Total height of every row before `startIndex` — the leading spacer's height. */
|
|
3493
|
+
readonly offsetBefore: number;
|
|
3494
|
+
/** Total height of every row after `endIndex` — the trailing spacer's height. */
|
|
3495
|
+
readonly offsetAfter: number;
|
|
3496
|
+
}
|
|
3497
|
+
/**
|
|
3498
|
+
* Which rows of a dynamic-height, virtualized list fall within
|
|
3499
|
+
* `[scrollTop, scrollTop + viewportHeight)`, padded by `overscan` rows on
|
|
3500
|
+
* each side and clamped to the array's own bounds.
|
|
3501
|
+
*
|
|
3502
|
+
* Walks a cumulative-offset prefix sum built from `heights` (measured height
|
|
3503
|
+
* where known, `estimatedHeight` otherwise) rather than assuming a uniform
|
|
3504
|
+
* row height — a grid's rows are not uniform (`.is-wrapped` cells, group
|
|
3505
|
+
* header/summary rows), so a fixed-height virtualizer would either break
|
|
3506
|
+
* wrapping or force it out of scope.
|
|
3507
|
+
*
|
|
3508
|
+
* `O(n)` in `heights.length`. Deliberately not a Fenwick tree or a
|
|
3509
|
+
* binary-searchable prefix-sum structure — that optimization belongs in the
|
|
3510
|
+
* mutable height cache that already owns mutability (`createRowVirtualizer`
|
|
3511
|
+
* in `@gridkitjs/forms-dom`), not in this pure function's contract, and is not
|
|
3512
|
+
* worth taking on until a profiled scenario actually shows it matters at
|
|
3513
|
+
* realistic row counts.
|
|
3514
|
+
*/
|
|
3515
|
+
declare function visibleRange(heights: RowHeights, estimatedHeight: number, scrollTop: number, viewportHeight: number, overscan: number): VisibleRange;
|
|
3516
|
+
|
|
3517
|
+
export { ALL_DAY, type AssembleContext, type BeforeInputDecision, type BooleanWords, CALENDAR_FISCAL_YEAR, CHECKBOX_WORDS, type CalendarAction, type CalendarContext, type CalendarDay, type CalendarLimits, type CalendarMonth, type CalendarMove, type CalendarState, type CalendarUnit, type CalendarView, type CalendarWeek, type ChangeCause, type ChangeSource, type CleanedNumber, type CommitOutcome, type CommitTrigger, type CompiledMask, type CompositeController, type CompositeDetailsContext, type CompositeFieldOptions, type CompositeState, type DateDetails, type DateFieldOptions, type DateLayout, type DateLayoutFields, type DateLayoutOptions, type DateLayoutPart, type DateParts, type DatePreset, type DateRange, type DateReadOptions, type DateReadingInfo, type DateRuleContext, type DateSegment, type DateSegmentType, type DateTextReading, type DateTimeDetails, type DateTimeFieldOptions, type DateUnreadableReason, type DecimalString, type DefaultTimes, type DurationDetails, type DurationLike, type DurationNotation, type DurationOptions, type DurationReading, type DurationUnit, type FieldAction, type FieldBeforeChangeEvent, type FieldBeforeCommitEvent, type FieldBeforeInputEvent, type FieldChangeEvent, type FieldCommitEvent, type FieldController, type FieldDraft, type FieldEventBase, type FieldFocusEvent, type FieldHandlers, type FieldInputEvent, type FieldMessage, type FieldMessageInput, type FieldOptions, type FieldPhase, type FieldRegistry, type FieldState, type FieldValidateEvent, type FiscalMonthPeriod, type FiscalQuarterPeriod, type FiscalYear, type FiscalYearPeriod, type FormatContext, type FormatPurpose, type Formatter, type FormsMessages, type FractionDigits, type InputFilter, type InputFilterDecision, type Instant, type InstantFieldOptions, type MaskCompileResult, type MaskDetails, type MaskEdit, type MaskInputHints, type MaskLetterCase, type MaskOptions, type MaskPreset, type MaskPresets, type MaskResult, type MaskSlot, type MaskSource, type MaskTokenDefinition, type MaskTokens, type MaskValueFormat, type MaskedText, type MessageSummary, type MonthGrid, type MonthGridOptions, type MonthPeriod, NO_TIME, type NegativeStyle, type NoDetails, type NoFlags, type NumberAffixes, type NumberDetails, type NumberEntry, type NumberEntryOptions, type NumberFieldOptions, type NumberLike, type NumberOptions, type NumberReading, type NumberReadingInfo, type NumberStep, type NumberStyle, type NumberSymbolOverrides, type NumberSymbols, type NumberTextForm, type NumberUnreadableReason, type NumberValue, type NumberValueType, type OvernightFlags, POPUP_CLOSED, type ParseContext, type ParseResult, type Parser, type PartChange, type PartController, type PartOptions, type PartTexts, type PartValues, type PercentScale, type Period, type PeriodDetails, type PeriodFieldOptions, type PeriodGranularity, type PeriodLayoutOptions, type PeriodParts, type PeriodValues, type PickedDays, type PivotOptions, type PlainDate, type PlainDateTime, type PlainTime, type PopupAction, type PopupCloseReason, type PopupOpenChange, type PopupOpenReason, type PopupState, type PopupStep, type QuarterPeriod, type Range, type RangeBounds, type RangeDetails, type RangeEnd, type RangeEnds, type RangeKind, type RangeOptions, type RangeOrientation, type RangePick, type RangePickAction, type RangePickStep, type RangeReading, type RangeTextOptions, type RangeValue, type RegisteredField, type RelativeDateRule, type RelativeRange, type RoundingMode, type RowHeights, SWITCH_WORDS, type Schedule, type SegmentAction, type SegmentAria, type SegmentContext, type SegmentEntry, type SegmentRun, type SegmentState, type SegmentStep, type SegmentType, type Severity, type SeverityCount, type SpanFormatter, type StepDirection, type StepRequest, type StepSize, type SummaryItem, type TextEdit, type TextInputDetails, type TextParseOptions, type TextReading, type TimeColumn, type TimeColumnOption, type TimeColumnType, type TimeColumnsOptions, type TimeDetails, type TimeFieldOptions, type TimeLimits, type TimeParts, type TimeRange, type TimeRangeContext, type TimeZoneDisambiguation, type ValidationResult, type Validator, type ValidatorContext, type VisibleRange, type WeekInfo, type WeekNumbering, type WeekOfYear, type Weekday, type WritingDirection, type YearPeriod, type ZonedRangeContext, type ZonedReading, addDays, addDecimals, addMonths, addPeriods, addYears, applyMaskEdit, availableDateRule, booleanFormatter, booleanParser, calendarMonth, calendarMonthParts, calendarReducer, calendarStart, calendarYears, checkedRule, clampCalendarDate, clampCalendarMonth, clampTime, cleanPastedNumber, commonDatePresets, compareCalendarMonths, compareDateTimes, compareDates, compareDecimals, compareInstants, comparePeriods, compareTimes, compileMask, convertDuration, countCharacters, counterAnnouncement, createCompositeController, createDefaultFormsMessages, createFieldController, createFieldRegistry, dateDetails, dateFormatter, dateFromInstant, dateFromPlainDate, dateFromPlainDateTime, dateLayout, dateParser, dateParts, datePresetLabel, dateRangeKind, dateTimeDetails, dateTimeFormatter, dateTimeParser, dateTimeRangeKind, dayOfWeek, dayTimeLimits, daysBetween, daysInMonth, daysToDateTimeRange, daysToInstantRange, decimalRangeKind, decimalToNumber, defaultFormsMessages, defaultWeekNumbering, durationDetails, durationFormatter, durationParser, endOfMonth, endsRule, exactInstantOf, fieldMessages, fieldReducer, fieldText, filterMaskEdit, filterNumberEdit, fixedFractionDigits, formatCalendarMonth, formatCalendarYear, formatDate, formatDateRange, formatDateSegments, formatDateTime, formatDateTimeSegments, formatDayOfMonth, formatDaySpan, formatDuration, formatInstant, formatMasked, formatMonthName, formatNumber, formatNumberRange, formatPeriod, formatPeriodPage, formatPeriodPlace, formatPeriodSegments, formatText, formatTime, formatTimeRange, formatTimeSegments, formatTimeSpan, formatWeekday, hasError, ibanRule, idleSegments, inlineStep, instantDetails, instantFormatter, instantFromDate, instantOf, instantParser, instantRangeKind, instantZoneMessage, ipv4Rule, isCalendarDayDisabled, isCalendarMonth, isCalendarMonthDisabled, isDecimalString, isInstant, isLeapYear, isPeriod, isPlainDate, isPlainDateTime, isPlainTime, isRelativeDateRule, isRelativeRange, isTimeZone, isValidMaskStart, joinSegments, luhnRule, maskDetails, maskFormatter, maskInputHints, maskParser, maskPresets, maxDateRule, maxDateTimeRule, maxDurationRule, maxInstantRule, maxLengthRule, maxPeriodRule, maxRule, maxSpanRule, maxTimeRule, minDateRule, minDateTimeRule, minDurationRule, minInstantRule, minLengthRule, minPeriodRule, minRule, minSpanRule, minTimeRule, minutesOfDay, monthGrid, monthOfDate, mostSevere, moveCalendarDate, nextCheckedValue, normalizeDecimal, nowIn, numberAffixes, numberCaret, numberDetails, numberFormatter, numberFractionDigits, numberParser, numberRangeKind, numberRangeKindOf, numberSymbols, numberToDecimal, offsetOf, orderRange, parseDuration, parseNumber, parsed, patternRule, periodDetails, periodFormatter, periodGranularity, periodLayout, periodOf, periodPage, periodPageYears, periodParser, periodParts, periodRange, pickedDays, pivotYear, plainDate, plainDateFromDate, plainDateTime, plainTime, popupReducer, rangeDetails, rangeEnds, rangeFlags, rangeIncludes, rangePickPreview, rangePickReducer, rangeSpan, readDateShortcut, readDateText, readRangeEnds, readTimeText, relativePreset, requiredRule, resolveDateRange, resolveDateRule, resolveFormsMessages, resolveRange, roundDecimal, runtimeTimeZone, sameDayIn, sameRange, sameRule, segmentAria, segmentReducer, segmentRuns, segmentSpans, segmentValue, segmentsTime, setTimeColumn, shiftDecimal, shownEnd, shownMessages, snapTime, sortFieldMessages, spanOf, splitDateTime, splitSegments, startOfDayIn, startOfMonth, startOfWeek, stepNumber, stepNumberValue, stepRule, subtractDecimals, summarizeMessages, textParser, timeColumns, timeDetails, timeFormatter, timeParser, timeParts, timeRangeKind, toFieldMessages, toInstant, toPeriod, toPlainDate, toPlainDateTime, toPlainTime, todayIn, typeaheadIndex, unreadable, visibleRange, wallClockOf, weekInfo, weekOf, writeSegment };
|