@azx-pbc/axiom-web 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +161 -2
- package/dist/address.d.ts +32 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.js +146 -0
- package/dist/address.js.map +1 -0
- package/dist/capture/MediaCapture.d.ts +45 -0
- package/dist/capture/MediaCapture.d.ts.map +1 -0
- package/dist/capture/MediaCapture.js +669 -0
- package/dist/capture/MediaCapture.js.map +1 -0
- package/dist/capture/SignatureCapture.d.ts +31 -0
- package/dist/capture/SignatureCapture.d.ts.map +1 -0
- package/dist/capture/SignatureCapture.js +329 -0
- package/dist/capture/SignatureCapture.js.map +1 -0
- package/dist/capture/copy.d.ts +101 -0
- package/dist/capture/copy.d.ts.map +1 -0
- package/dist/capture/copy.js +1369 -0
- package/dist/capture/copy.js.map +1 -0
- package/dist/capture/index.d.ts +19 -0
- package/dist/capture/index.d.ts.map +1 -0
- package/dist/capture/index.js +14 -0
- package/dist/capture/index.js.map +1 -0
- package/dist/capture/media-kind.d.ts +16 -0
- package/dist/capture/media-kind.d.ts.map +1 -0
- package/dist/capture/media-kind.js +64 -0
- package/dist/capture/media-kind.js.map +1 -0
- package/dist/capture/permissions.d.ts +109 -0
- package/dist/capture/permissions.d.ts.map +1 -0
- package/dist/capture/permissions.js +172 -0
- package/dist/capture/permissions.js.map +1 -0
- package/dist/capture/refusal.d.ts +13 -0
- package/dist/capture/refusal.d.ts.map +1 -0
- package/dist/capture/refusal.js +16 -0
- package/dist/capture/refusal.js.map +1 -0
- package/dist/controls.d.ts +64 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +2524 -0
- package/dist/controls.js.map +1 -0
- package/dist/coordinate.d.ts +38 -0
- package/dist/coordinate.d.ts.map +1 -0
- package/dist/coordinate.js +220 -0
- package/dist/coordinate.js.map +1 -0
- package/dist/copy.d.ts +313 -0
- package/dist/copy.d.ts.map +1 -0
- package/dist/copy.js +2602 -0
- package/dist/copy.js.map +1 -0
- package/dist/countries.d.ts +14 -0
- package/dist/countries.d.ts.map +1 -0
- package/dist/countries.js +264 -0
- package/dist/countries.js.map +1 -0
- package/dist/format/calendar-locale.d.ts +19 -0
- package/dist/format/calendar-locale.d.ts.map +1 -0
- package/dist/format/calendar-locale.js +38 -0
- package/dist/format/calendar-locale.js.map +1 -0
- package/dist/format/country-names.d.ts +21 -0
- package/dist/format/country-names.d.ts.map +1 -0
- package/dist/format/country-names.js +2277 -0
- package/dist/format/country-names.js.map +1 -0
- package/dist/format/date.d.ts +58 -0
- package/dist/format/date.d.ts.map +1 -0
- package/dist/format/date.js +155 -0
- package/dist/format/date.js.map +1 -0
- package/dist/format/digits.d.ts +23 -0
- package/dist/format/digits.d.ts.map +1 -0
- package/dist/format/digits.js +46 -0
- package/dist/format/digits.js.map +1 -0
- package/dist/format/index.d.ts +28 -0
- package/dist/format/index.d.ts.map +1 -0
- package/dist/format/index.js +24 -0
- package/dist/format/index.js.map +1 -0
- package/dist/format/invariant.d.ts +8 -0
- package/dist/format/invariant.d.ts.map +1 -0
- package/dist/format/invariant.js +10 -0
- package/dist/format/invariant.js.map +1 -0
- package/dist/format/locale.d.ts +33 -0
- package/dist/format/locale.d.ts.map +1 -0
- package/dist/format/locale.js +39 -0
- package/dist/format/locale.js.map +1 -0
- package/dist/format/media-type.d.ts +8 -0
- package/dist/format/media-type.d.ts.map +1 -0
- package/dist/format/media-type.js +302 -0
- package/dist/format/media-type.js.map +1 -0
- package/dist/format/money.d.ts +52 -0
- package/dist/format/money.d.ts.map +1 -0
- package/dist/format/money.js +36 -0
- package/dist/format/money.js.map +1 -0
- package/dist/format/number.d.ts +28 -0
- package/dist/format/number.d.ts.map +1 -0
- package/dist/format/number.js +91 -0
- package/dist/format/number.js.map +1 -0
- package/dist/host.d.ts +122 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +20 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/media.d.ts +42 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +151 -0
- package/dist/media.js.map +1 -0
- package/dist/pickers/DatePicker.d.ts +35 -0
- package/dist/pickers/DatePicker.d.ts.map +1 -0
- package/dist/pickers/DatePicker.js +212 -0
- package/dist/pickers/DatePicker.js.map +1 -0
- package/dist/pickers/TimeSegments.d.ts +27 -0
- package/dist/pickers/TimeSegments.d.ts.map +1 -0
- package/dist/pickers/TimeSegments.js +82 -0
- package/dist/pickers/TimeSegments.js.map +1 -0
- package/dist/pickers/day-picker-locale.d.ts +15 -0
- package/dist/pickers/day-picker-locale.d.ts.map +1 -0
- package/dist/pickers/day-picker-locale.js +46 -0
- package/dist/pickers/day-picker-locale.js.map +1 -0
- package/dist/render/dom.d.ts +100 -0
- package/dist/render/dom.d.ts.map +1 -0
- package/dist/render/dom.js +882 -0
- package/dist/render/dom.js.map +1 -0
- package/dist/render/layout.d.ts +45 -0
- package/dist/render/layout.d.ts.map +1 -0
- package/dist/render/layout.js +8 -0
- package/dist/render/layout.js.map +1 -0
- package/dist/schedule/SchedulePicker.d.ts +46 -0
- package/dist/schedule/SchedulePicker.d.ts.map +1 -0
- package/dist/schedule/SchedulePicker.js +160 -0
- package/dist/schedule/SchedulePicker.js.map +1 -0
- package/dist/schedule/timeslot.d.ts +52 -0
- package/dist/schedule/timeslot.d.ts.map +1 -0
- package/dist/schedule/timeslot.js +265 -0
- package/dist/schedule/timeslot.js.map +1 -0
- package/dist/styles.css +2151 -0
- package/dist/theme/index.d.ts +12 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +11 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/presets.d.ts +93 -0
- package/dist/theme/presets.d.ts.map +1 -0
- package/dist/theme/presets.js +200 -0
- package/dist/theme/presets.js.map +1 -0
- package/dist/tokens.css +234 -0
- package/dist/wizard-checkpoints.d.ts +18 -0
- package/dist/wizard-checkpoints.d.ts.map +1 -0
- package/dist/wizard-checkpoints.js +56 -0
- package/dist/wizard-checkpoints.js.map +1 -0
- package/package.json +76 -3
package/dist/media.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { isRecord } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import { DEFAULT_DIGIT_POLICY } from './format/digits.js';
|
|
3
|
+
import { resolveLocale } from './format/locale.js';
|
|
4
|
+
import { groupCanonicalNumericText } from './format/number.js';
|
|
5
|
+
/**
|
|
6
|
+
* One media reference as a line of text and, when the host has one, a preview.
|
|
7
|
+
*
|
|
8
|
+
* The wire holds an id, a media type and a byte count. A screenshot that concatenated the id and
|
|
9
|
+
* the type read as one malformed token (`coverimage/jpeg`), so every line here separates the
|
|
10
|
+
* members with ` · ` and states the size in the units a person reads. Sizes are base 1000, the
|
|
11
|
+
* unit spelling storage services and file managers use (`2 KB` is 2000 bytes); the base is
|
|
12
|
+
* exported so a host or a test states the same convention rather than guessing.
|
|
13
|
+
*/
|
|
14
|
+
/** The byte base this module's sizes use: 1000, not 1024. */
|
|
15
|
+
export const MEDIA_BYTE_BASE = 1000;
|
|
16
|
+
const LATIN_BYTE_UNITS = Object.freeze({
|
|
17
|
+
b: 'B',
|
|
18
|
+
scaled: ['KB', 'MB', 'GB', 'TB'],
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Localized byte-size unit symbols across all nine shipped locales.
|
|
22
|
+
*
|
|
23
|
+
* French uses octet units (`o`, `ko`, `Mo`, `Go`, `To`), Russian uses Cyrillic units
|
|
24
|
+
* (`Б`, `КБ`, `МБ`, `ГБ`, `ТБ`), Arabic uses Arabic unit words, Chinese uses `字节` for bytes
|
|
25
|
+
* alongside `KB`/`MB`/`GB`/`TB`, and the remaining five keep `B`/`KB`/`MB`/`GB`/`TB`.
|
|
26
|
+
*/
|
|
27
|
+
const BYTE_UNITS = Object.freeze({
|
|
28
|
+
en: LATIN_BYTE_UNITS,
|
|
29
|
+
es: LATIN_BYTE_UNITS,
|
|
30
|
+
pt: LATIN_BYTE_UNITS,
|
|
31
|
+
de: LATIN_BYTE_UNITS,
|
|
32
|
+
it: LATIN_BYTE_UNITS,
|
|
33
|
+
fr: Object.freeze({ b: 'o', scaled: ['ko', 'Mo', 'Go', 'To'] }),
|
|
34
|
+
ru: Object.freeze({ b: 'Б', scaled: ['КБ', 'МБ', 'ГБ', 'ТБ'] }),
|
|
35
|
+
ar: Object.freeze({
|
|
36
|
+
b: 'بايت',
|
|
37
|
+
scaled: ['كيلوبايت', 'ميغابايت', 'غيغابايت', 'تيرابايت'],
|
|
38
|
+
}),
|
|
39
|
+
zh: Object.freeze({ b: '字节', scaled: ['KB', 'MB', 'GB', 'TB'] }),
|
|
40
|
+
});
|
|
41
|
+
/** A byte count in human units, one decimal at most: `0 B`, `999 B`, `2 KB`, `1.4 MB`. */
|
|
42
|
+
export function humanSize(bytes, locale) {
|
|
43
|
+
if (!Number.isFinite(bytes) || bytes < 0)
|
|
44
|
+
return '';
|
|
45
|
+
const language = resolveLocale(locale).language;
|
|
46
|
+
const units = BYTE_UNITS[language];
|
|
47
|
+
if (bytes < MEDIA_BYTE_BASE)
|
|
48
|
+
return `${String(bytes)} ${units.b}`;
|
|
49
|
+
let value = bytes / MEDIA_BYTE_BASE;
|
|
50
|
+
let unit = 0;
|
|
51
|
+
while (value >= MEDIA_BYTE_BASE && unit < units.scaled.length - 1) {
|
|
52
|
+
value /= MEDIA_BYTE_BASE;
|
|
53
|
+
unit += 1;
|
|
54
|
+
}
|
|
55
|
+
const rounded = Math.round(value * 10) / 10;
|
|
56
|
+
const canonical = Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1);
|
|
57
|
+
const text = groupCanonicalNumericText(canonical, language, DEFAULT_DIGIT_POLICY);
|
|
58
|
+
return `${text} ${units.scaled[unit] ?? units.scaled[units.scaled.length - 1]}`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* `text` shortened in the middle when it exceeds `limit`, with the full value kept by the
|
|
62
|
+
* caller's `title`. A trailing identifier is usually the distinguishing part, so the middle is
|
|
63
|
+
* what is dropped rather than the end.
|
|
64
|
+
*/
|
|
65
|
+
export function truncateMiddle(text, limit = 28) {
|
|
66
|
+
if (text.length <= limit)
|
|
67
|
+
return text;
|
|
68
|
+
const keep = Math.max(1, Math.floor((limit - 1) / 2));
|
|
69
|
+
return `${text.slice(0, keep)}…${text.slice(text.length - keep)}`;
|
|
70
|
+
}
|
|
71
|
+
/** The reference's id, or empty text for a value that is not a reference. */
|
|
72
|
+
export function mediaId(value) {
|
|
73
|
+
return isRecord(value) && typeof value['id'] === 'string' ? value['id'] : '';
|
|
74
|
+
}
|
|
75
|
+
/** The reference's media type, or empty text for a value that is not a reference. */
|
|
76
|
+
export function mediaMime(value) {
|
|
77
|
+
return isRecord(value) && typeof value['mime'] === 'string' ? value['mime'] : '';
|
|
78
|
+
}
|
|
79
|
+
/** The host's filename for a reference, when it supplies one; otherwise empty text. */
|
|
80
|
+
export function mediaName(value) {
|
|
81
|
+
if (!isRecord(value))
|
|
82
|
+
return '';
|
|
83
|
+
const name = value['name'];
|
|
84
|
+
if (typeof name === 'string')
|
|
85
|
+
return name;
|
|
86
|
+
const filename = value['filename'];
|
|
87
|
+
return typeof filename === 'string' ? filename : '';
|
|
88
|
+
}
|
|
89
|
+
/** The reference's byte count, or `undefined` for a value that is not a reference. */
|
|
90
|
+
export function mediaBytes(value) {
|
|
91
|
+
if (!isRecord(value))
|
|
92
|
+
return undefined;
|
|
93
|
+
const bytes = value['byteSize'];
|
|
94
|
+
return typeof bytes === 'number' && Number.isFinite(bytes) ? bytes : undefined;
|
|
95
|
+
}
|
|
96
|
+
/** The friendly name of a common media type, or the subtype upper-cased. */
|
|
97
|
+
export function friendlyMediaType(mime) {
|
|
98
|
+
const common = {
|
|
99
|
+
'image/jpeg': 'JPEG',
|
|
100
|
+
'image/jpg': 'JPEG',
|
|
101
|
+
'image/png': 'PNG',
|
|
102
|
+
'image/gif': 'GIF',
|
|
103
|
+
'image/webp': 'WEBP',
|
|
104
|
+
'image/svg+xml': 'SVG',
|
|
105
|
+
'application/pdf': 'PDF',
|
|
106
|
+
'application/zip': 'ZIP',
|
|
107
|
+
'text/plain': 'TXT',
|
|
108
|
+
'text/csv': 'CSV',
|
|
109
|
+
};
|
|
110
|
+
const known = common[mime.toLowerCase()];
|
|
111
|
+
if (known !== undefined)
|
|
112
|
+
return known;
|
|
113
|
+
// A less common type keeps the subtype, which is the part a person recognises; the media
|
|
114
|
+
// type's `image/` or `application/` namespace is engineering vocabulary, not a file name.
|
|
115
|
+
const slash = mime.indexOf('/');
|
|
116
|
+
return (slash === -1 ? mime : mime.slice(slash + 1)).toUpperCase();
|
|
117
|
+
}
|
|
118
|
+
/** Whether a reference names an image this adapter can preview. */
|
|
119
|
+
export function isImageMedia(value) {
|
|
120
|
+
return mediaMime(value).startsWith('image/');
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The full line: `<id> · <mime> · <size>`, omitting a member the reference does not carry.
|
|
124
|
+
*
|
|
125
|
+
* It is the text a `title` holds and an accessible label states; the shorter form below is what
|
|
126
|
+
* fits a row.
|
|
127
|
+
*/
|
|
128
|
+
export function mediaLine(value, locale) {
|
|
129
|
+
const bytes = mediaBytes(value);
|
|
130
|
+
const name = mediaName(value);
|
|
131
|
+
return [
|
|
132
|
+
name !== '' ? name : mediaId(value),
|
|
133
|
+
friendlyMediaType(mediaMime(value)),
|
|
134
|
+
bytes === undefined ? '' : humanSize(bytes, locale),
|
|
135
|
+
]
|
|
136
|
+
.filter((part) => part !== '')
|
|
137
|
+
.join(' · ');
|
|
138
|
+
}
|
|
139
|
+
/** The line a row shows, with a long id shortened in the middle. */
|
|
140
|
+
export function mediaDisplayLine(value, limit = 28, locale) {
|
|
141
|
+
const bytes = mediaBytes(value);
|
|
142
|
+
const name = mediaName(value);
|
|
143
|
+
return [
|
|
144
|
+
name !== '' ? name : truncateMiddle(mediaId(value), limit),
|
|
145
|
+
friendlyMediaType(mediaMime(value)),
|
|
146
|
+
bytes === undefined ? '' : humanSize(bytes, locale),
|
|
147
|
+
]
|
|
148
|
+
.filter((part) => part !== '')
|
|
149
|
+
.join(' · ');
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;;;;;;;GAQG;AAEH,6DAA6D;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC;AAOpC,MAAM,gBAAgB,GAAc,MAAM,CAAC,MAAM,CAAC;IAChD,CAAC,EAAE,GAAG;IACN,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAU;CAC1C,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,GAAwC,MAAM,CAAC,MAAM,CAAC;IACpE,EAAE,EAAE,gBAAgB;IACpB,EAAE,EAAE,gBAAgB;IACpB,EAAE,EAAE,gBAAgB;IACpB,EAAE,EAAE,gBAAgB;IACpB,EAAE,EAAE,gBAAgB;IACpB,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAU,EAAE,CAAC;IACxE,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,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S,CAAC,KAAK,CAAC,CAAC;QACnC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC;KACpD;SACE,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;SAC7B,IAAI,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC","sourcesContent":["import { isRecord } from '@azx-pbc/axiom-runtime';\nimport type { WireValue } from '@azx-pbc/axiom-runtime';\nimport { DEFAULT_DIGIT_POLICY } from './format/digits.js';\nimport { resolveLocale } from './format/locale.js';\nimport type { Locale } from './format/locale.js';\nimport { groupCanonicalNumericText } from './format/number.js';\n\n/**\n * One media reference as a line of text and, when the host has one, a preview.\n *\n * The wire holds an id, a media type and a byte count. A screenshot that concatenated the id and\n * the type read as one malformed token (`coverimage/jpeg`), so every line here separates the\n * members with ` · ` and states the size in the units a person reads. Sizes are base 1000, the\n * unit spelling storage services and file managers use (`2 KB` is 2000 bytes); the base is\n * exported so a host or a test states the same convention rather than guessing.\n */\n\n/** The byte base this module's sizes use: 1000, not 1024. */\nexport const MEDIA_BYTE_BASE = 1000;\n\ninterface ByteUnits {\n readonly b: string;\n readonly scaled: readonly [string, string, string, string];\n}\n\nconst LATIN_BYTE_UNITS: ByteUnits = Object.freeze({\n b: 'B',\n scaled: ['KB', 'MB', 'GB', 'TB'] as const,\n});\n\n/**\n * Localized byte-size unit symbols across all nine shipped locales.\n *\n * French uses octet units (`o`, `ko`, `Mo`, `Go`, `To`), Russian uses Cyrillic units\n * (`Б`, `КБ`, `МБ`, `ГБ`, `ТБ`), Arabic uses Arabic unit words, Chinese uses `字节` for bytes\n * alongside `KB`/`MB`/`GB`/`TB`, and the remaining five keep `B`/`KB`/`MB`/`GB`/`TB`.\n */\nconst BYTE_UNITS: Readonly<Record<Locale, ByteUnits>> = Object.freeze({\n en: LATIN_BYTE_UNITS,\n es: LATIN_BYTE_UNITS,\n pt: LATIN_BYTE_UNITS,\n de: LATIN_BYTE_UNITS,\n it: LATIN_BYTE_UNITS,\n fr: Object.freeze({ b: 'o', scaled: ['ko', 'Mo', 'Go', 'To'] as const }),\n ru: Object.freeze({ b: 'Б', scaled: ['КБ', 'МБ', 'ГБ', 'ТБ'] as const }),\n ar: Object.freeze({\n b: 'بايت',\n scaled: ['كيلوبايت', 'ميغابايت', 'غيغابايت', 'تيرابايت'] as const,\n }),\n zh: Object.freeze({ b: '字节', scaled: ['KB', 'MB', 'GB', 'TB'] as const }),\n});\n\n/** A byte count in human units, one decimal at most: `0 B`, `999 B`, `2 KB`, `1.4 MB`. */\nexport function humanSize(bytes: number, locale?: string): string {\n if (!Number.isFinite(bytes) || bytes < 0) return '';\n const language = resolveLocale(locale).language;\n const units = BYTE_UNITS[language];\n if (bytes < MEDIA_BYTE_BASE) return `${String(bytes)} ${units.b}`;\n let value = bytes / MEDIA_BYTE_BASE;\n let unit = 0;\n while (value >= MEDIA_BYTE_BASE && unit < units.scaled.length - 1) {\n value /= MEDIA_BYTE_BASE;\n unit += 1;\n }\n const rounded = Math.round(value * 10) / 10;\n const canonical = Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1);\n const text = groupCanonicalNumericText(canonical, language, DEFAULT_DIGIT_POLICY);\n return `${text} ${units.scaled[unit] ?? units.scaled[units.scaled.length - 1]}`;\n}\n\n/**\n * `text` shortened in the middle when it exceeds `limit`, with the full value kept by the\n * caller's `title`. A trailing identifier is usually the distinguishing part, so the middle is\n * what is dropped rather than the end.\n */\nexport function truncateMiddle(text: string, limit = 28): string {\n if (text.length <= limit) return text;\n const keep = Math.max(1, Math.floor((limit - 1) / 2));\n return `${text.slice(0, keep)}…${text.slice(text.length - keep)}`;\n}\n\n/** The reference's id, or empty text for a value that is not a reference. */\nexport function mediaId(value: WireValue | undefined): string {\n return isRecord(value) && typeof value['id'] === 'string' ? value['id'] : '';\n}\n\n/** The reference's media type, or empty text for a value that is not a reference. */\nexport function mediaMime(value: WireValue | undefined): string {\n return isRecord(value) && typeof value['mime'] === 'string' ? value['mime'] : '';\n}\n\n/** The host's filename for a reference, when it supplies one; otherwise empty text. */\nexport function mediaName(value: WireValue | undefined): string {\n if (!isRecord(value)) return '';\n const name = value['name'];\n if (typeof name === 'string') return name;\n const filename = value['filename'];\n return typeof filename === 'string' ? filename : '';\n}\n\n/** The reference's byte count, or `undefined` for a value that is not a reference. */\nexport function mediaBytes(value: WireValue | undefined): number | undefined {\n if (!isRecord(value)) return undefined;\n const bytes = value['byteSize'];\n return typeof bytes === 'number' && Number.isFinite(bytes) ? bytes : undefined;\n}\n\n/** The friendly name of a common media type, or the subtype upper-cased. */\nexport function friendlyMediaType(mime: string): string {\n const common: Readonly<Record<string, string>> = {\n 'image/jpeg': 'JPEG',\n 'image/jpg': 'JPEG',\n 'image/png': 'PNG',\n 'image/gif': 'GIF',\n 'image/webp': 'WEBP',\n 'image/svg+xml': 'SVG',\n 'application/pdf': 'PDF',\n 'application/zip': 'ZIP',\n 'text/plain': 'TXT',\n 'text/csv': 'CSV',\n };\n const known = common[mime.toLowerCase()];\n if (known !== undefined) return known;\n // A less common type keeps the subtype, which is the part a person recognises; the media\n // type's `image/` or `application/` namespace is engineering vocabulary, not a file name.\n const slash = mime.indexOf('/');\n return (slash === -1 ? mime : mime.slice(slash + 1)).toUpperCase();\n}\n\n/** Whether a reference names an image this adapter can preview. */\nexport function isImageMedia(value: WireValue | undefined): boolean {\n return mediaMime(value).startsWith('image/');\n}\n\n/**\n * The full line: `<id> · <mime> · <size>`, omitting a member the reference does not carry.\n *\n * It is the text a `title` holds and an accessible label states; the shorter form below is what\n * fits a row.\n */\nexport function mediaLine(value: WireValue | undefined, locale?: string): string {\n const bytes = mediaBytes(value);\n const name = mediaName(value);\n return [\n name !== '' ? name : mediaId(value),\n friendlyMediaType(mediaMime(value)),\n bytes === undefined ? '' : humanSize(bytes, locale),\n ]\n .filter((part) => part !== '')\n .join(' · ');\n}\n\n/** The line a row shows, with a long id shortened in the middle. */\nexport function mediaDisplayLine(\n value: WireValue | undefined,\n limit = 28,\n locale?: string,\n): string {\n const bytes = mediaBytes(value);\n const name = mediaName(value);\n return [\n name !== '' ? name : truncateMiddle(mediaId(value), limit),\n friendlyMediaType(mediaMime(value)),\n bytes === undefined ? '' : humanSize(bytes, locale),\n ]\n .filter((part) => part !== '')\n .join(' · ');\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { DayPickerLocale } from 'react-day-picker/locale';
|
|
3
|
+
/** The controlled facts a date entry needs from its binding. */
|
|
4
|
+
export interface DatePickerProps {
|
|
5
|
+
readonly controlId: string;
|
|
6
|
+
readonly descriptionId: string | undefined;
|
|
7
|
+
readonly errorId: string;
|
|
8
|
+
readonly label: string;
|
|
9
|
+
readonly value: string | undefined;
|
|
10
|
+
readonly setValue: (value: string) => void;
|
|
11
|
+
readonly required: boolean;
|
|
12
|
+
readonly invalid: boolean;
|
|
13
|
+
readonly disabled: boolean;
|
|
14
|
+
readonly readOnly: boolean;
|
|
15
|
+
readonly locale: string | undefined;
|
|
16
|
+
readonly minimum: number | string | undefined;
|
|
17
|
+
readonly maximum: number | string | undefined;
|
|
18
|
+
readonly onBlur: () => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The DayPicker table the calendar paints, from the picker-only table.
|
|
22
|
+
*
|
|
23
|
+
* Its `localize` is the same object the readout reads through `calendarLocale`; the labels are
|
|
24
|
+
* the only addition. `zh` maps to `zhCN`, the only Chinese the shipped table promises.
|
|
25
|
+
*/
|
|
26
|
+
export declare function datePickerLocale(locale: string | undefined): DayPickerLocale;
|
|
27
|
+
/**
|
|
28
|
+
* A date as a text field with a calendar popover.
|
|
29
|
+
*
|
|
30
|
+
* The text accepts `YYYY-MM-DD` and displays the host locale's spelling while the field is at
|
|
31
|
+
* rest. The popover is a real dialog: selecting a day closes it, Escape closes it and returns
|
|
32
|
+
* focus to the input, and the compiled bounds disable days outside the declared range.
|
|
33
|
+
*/
|
|
34
|
+
export declare function DatePicker(props: DatePickerProps): ReactElement;
|
|
35
|
+
//# sourceMappingURL=DatePicker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatePicker.d.ts","sourceRoot":"","sources":["../../src/pickers/DatePicker.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuC,YAAY,EAAE,MAAM,OAAO,CAAC;AAG/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAQ/D,gEAAgE;AAChE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,eAAe,CAE5E;AA6ED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,YAAY,CAqK/D"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { format } from 'date-fns';
|
|
4
|
+
import { DayPicker } from 'react-day-picker';
|
|
5
|
+
import { tryParsePlainDate } from '@azx-pbc/axiom-runtime';
|
|
6
|
+
import { formatCivilDate, isCivilDateString } from '../format/date.js';
|
|
7
|
+
import { resolveLocale } from '../format/locale.js';
|
|
8
|
+
import { civilDate, civilKey, scheduleText } from '../schedule/timeslot.js';
|
|
9
|
+
import { pickerLocale, pickerMonthYear } from './day-picker-locale.js';
|
|
10
|
+
/**
|
|
11
|
+
* The DayPicker table the calendar paints, from the picker-only table.
|
|
12
|
+
*
|
|
13
|
+
* Its `localize` is the same object the readout reads through `calendarLocale`; the labels are
|
|
14
|
+
* the only addition. `zh` maps to `zhCN`, the only Chinese the shipped table promises.
|
|
15
|
+
*/
|
|
16
|
+
export function datePickerLocale(locale) {
|
|
17
|
+
return pickerLocale(resolveLocale(locale).language);
|
|
18
|
+
}
|
|
19
|
+
/** The canonical text a complete ISO date spells, or `undefined` for anything else. */
|
|
20
|
+
function isoText(text) {
|
|
21
|
+
return tryParsePlainDate(text) === undefined ? undefined : text;
|
|
22
|
+
}
|
|
23
|
+
function pad2(value) {
|
|
24
|
+
return String(value).padStart(2, '0');
|
|
25
|
+
}
|
|
26
|
+
/** Text compared without casing or repeated whitespace, as a reader may retype it. */
|
|
27
|
+
function normalized(text) {
|
|
28
|
+
return text.replace(/\s+/gu, ' ').trim().toLowerCase();
|
|
29
|
+
}
|
|
30
|
+
/** The date-fns patterns a typed entry may match, so a reader can type what the field shows. */
|
|
31
|
+
const PARSE_PATTERNS = ['PP', 'PPP', 'P', 'd MMMM yyyy', 'd MMM yyyy'];
|
|
32
|
+
/**
|
|
33
|
+
* The ISO date a typed entry spells, in ISO (`YYYY-MM-DD`) or in the locale's own spelling.
|
|
34
|
+
*
|
|
35
|
+
* The display at rest is the locale's short-month form (`Sep 3, 2026`), so a reader who types what
|
|
36
|
+
* they see must commit the same day. The candidate walk formats each day with the same date-fns
|
|
37
|
+
* table the readout and the calendar use, which also makes the numeric field order follow the
|
|
38
|
+
* locale rather than a hard-coded day/month guess.
|
|
39
|
+
*/
|
|
40
|
+
function parseText(text, locale) {
|
|
41
|
+
const trimmed = text.trim();
|
|
42
|
+
if (trimmed === '')
|
|
43
|
+
return undefined;
|
|
44
|
+
const iso = isoText(trimmed);
|
|
45
|
+
if (iso !== undefined)
|
|
46
|
+
return iso;
|
|
47
|
+
// The demo is an en-AU product: a numeric entry is day/month/year. A locale that writes
|
|
48
|
+
// month first still matches the candidate walk below, but this branch makes 03/09/2026 the
|
|
49
|
+
// third of September rather than the ninth of March.
|
|
50
|
+
const numeric = /^(\d{1,2})[./](\d{1,2})[./](\d{4})$/u.exec(trimmed);
|
|
51
|
+
if (numeric !== null) {
|
|
52
|
+
const key = `${String(Number(numeric[3])).padStart(4, '0')}-${pad2(Number(numeric[2]))}-${pad2(Number(numeric[1]))}`;
|
|
53
|
+
return tryParsePlainDate(key) === undefined ? undefined : key;
|
|
54
|
+
}
|
|
55
|
+
const yearMatch = /\b(\d{4})\b/u.exec(trimmed);
|
|
56
|
+
if (yearMatch === null)
|
|
57
|
+
return undefined;
|
|
58
|
+
const year = Number(yearMatch[1]);
|
|
59
|
+
const wanted = normalized(trimmed);
|
|
60
|
+
const table = datePickerLocale(locale);
|
|
61
|
+
for (let month = 1; month <= 12; month += 1) {
|
|
62
|
+
for (let day = 1; day <= 31; day += 1) {
|
|
63
|
+
const key = `${String(year).padStart(4, '0')}-${pad2(month)}-${pad2(day)}`;
|
|
64
|
+
if (tryParsePlainDate(key) === undefined)
|
|
65
|
+
continue;
|
|
66
|
+
const date = civilDate(key);
|
|
67
|
+
if (date === undefined)
|
|
68
|
+
continue;
|
|
69
|
+
for (const pattern of PARSE_PATTERNS) {
|
|
70
|
+
if (normalized(format(date, pattern, { locale: table })) === wanted)
|
|
71
|
+
return key;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A civil date as the host locale writes it.
|
|
79
|
+
*
|
|
80
|
+
* This is the same `formatCivilDate` the read-only value and the readout use, not date-fns's
|
|
81
|
+
* `PP`. One date therefore has one spelling in the chrome, and the parser's candidate walk
|
|
82
|
+
* already accepts that spelling for every shipped language (`PPP`, `d MMMM yyyy` or the
|
|
83
|
+
* language's own numeric order), so a reader can retype what the field shows.
|
|
84
|
+
*/
|
|
85
|
+
function displayText(iso, language) {
|
|
86
|
+
if (iso === undefined)
|
|
87
|
+
return '';
|
|
88
|
+
return isCivilDateString(iso) ? formatCivilDate(iso, language) : iso;
|
|
89
|
+
}
|
|
90
|
+
/** The `Date` a compiled bound names, when it is a civil date. */
|
|
91
|
+
function boundDate(bound) {
|
|
92
|
+
return typeof bound === 'string' ? civilDate(bound) : undefined;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A date as a text field with a calendar popover.
|
|
96
|
+
*
|
|
97
|
+
* The text accepts `YYYY-MM-DD` and displays the host locale's spelling while the field is at
|
|
98
|
+
* rest. The popover is a real dialog: selecting a day closes it, Escape closes it and returns
|
|
99
|
+
* focus to the input, and the compiled bounds disable days outside the declared range.
|
|
100
|
+
*/
|
|
101
|
+
export function DatePicker(props) {
|
|
102
|
+
const text = scheduleText(props.locale);
|
|
103
|
+
const language = resolveLocale(props.locale).language;
|
|
104
|
+
const [draft, setDraft] = useState(undefined);
|
|
105
|
+
const [open, setOpen] = useState(false);
|
|
106
|
+
const [error, setError] = useState(undefined);
|
|
107
|
+
const input = useRef(null);
|
|
108
|
+
const field = useRef(null);
|
|
109
|
+
const shown = draft ?? displayText(props.value, language);
|
|
110
|
+
const selected = props.value === undefined ? undefined : civilDate(props.value);
|
|
111
|
+
const minimum = boundDate(props.minimum);
|
|
112
|
+
const maximum = boundDate(props.maximum);
|
|
113
|
+
// `DateLib.formatMonthYear` calls `Intl.DateTimeFormat` for the year-first locales, and Chinese
|
|
114
|
+
// is the shipped one. The caption and the grid label are therefore built from the readout's
|
|
115
|
+
// month table instead; the other eight already format through date-fns and need no override.
|
|
116
|
+
const intlFreeCaption = language === 'zh';
|
|
117
|
+
const pickerLabels = {
|
|
118
|
+
labelPrevious: () => text.previousMonth,
|
|
119
|
+
labelNext: () => text.nextMonth,
|
|
120
|
+
...(intlFreeCaption ? { labelGrid: (date) => pickerMonthYear(date, language) } : {}),
|
|
121
|
+
};
|
|
122
|
+
const dateErrorId = `${props.controlId}-date-error`;
|
|
123
|
+
const describedBy = [
|
|
124
|
+
props.descriptionId,
|
|
125
|
+
props.invalid ? props.errorId : undefined,
|
|
126
|
+
error === undefined ? undefined : dateErrorId,
|
|
127
|
+
]
|
|
128
|
+
.filter((id) => id !== undefined)
|
|
129
|
+
.join(' ');
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (!open)
|
|
132
|
+
return;
|
|
133
|
+
const close = (event) => {
|
|
134
|
+
if (event.target instanceof Node && field.current?.contains(event.target) !== true) {
|
|
135
|
+
setOpen(false);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
// Escape is caught at the document in the capture phase: a calendar grid may stop the key
|
|
139
|
+
// on its way up, and the contract is that one Escape closes the dialog whatever has focus.
|
|
140
|
+
// Focus returns to the input, never to the body a removed dialog would leave behind.
|
|
141
|
+
const escape = (event) => {
|
|
142
|
+
if (event.key !== 'Escape')
|
|
143
|
+
return;
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
event.stopPropagation();
|
|
146
|
+
setOpen(false);
|
|
147
|
+
input.current?.focus();
|
|
148
|
+
};
|
|
149
|
+
document.addEventListener('mousedown', close);
|
|
150
|
+
document.addEventListener('keydown', escape, true);
|
|
151
|
+
return () => {
|
|
152
|
+
document.removeEventListener('mousedown', close);
|
|
153
|
+
document.removeEventListener('keydown', escape, true);
|
|
154
|
+
};
|
|
155
|
+
}, [open]);
|
|
156
|
+
const close = () => {
|
|
157
|
+
setOpen(false);
|
|
158
|
+
input.current?.focus();
|
|
159
|
+
};
|
|
160
|
+
const commit = () => {
|
|
161
|
+
if (draft === undefined)
|
|
162
|
+
return;
|
|
163
|
+
const parsed = parseText(draft, props.locale);
|
|
164
|
+
if (parsed === undefined) {
|
|
165
|
+
if (draft.trim() !== '') {
|
|
166
|
+
// The typed entry is kept so the reader can correct it; the store is unchanged and the
|
|
167
|
+
// field says why instead of snapping back to the old value.
|
|
168
|
+
setError(text.invalidDate);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
setError(undefined);
|
|
172
|
+
setDraft(undefined);
|
|
173
|
+
props.onBlur();
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
setError(undefined);
|
|
177
|
+
setDraft(undefined);
|
|
178
|
+
props.setValue(parsed);
|
|
179
|
+
props.onBlur();
|
|
180
|
+
};
|
|
181
|
+
const escape = (event) => {
|
|
182
|
+
if (event.key !== 'Escape')
|
|
183
|
+
return;
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
close();
|
|
186
|
+
};
|
|
187
|
+
return (_jsxs("div", { className: "ax-date-field", ref: field, children: [_jsxs("div", { className: "ax-date-row", children: [_jsx("input", { ref: input, id: props.controlId, className: "ax-control ax-control--date", type: "text", inputMode: "numeric", autoComplete: "off", placeholder: "YYYY-MM-DD", "aria-label": props.label, value: shown, "aria-required": props.required, "aria-invalid": props.invalid || error !== undefined, ...(describedBy === '' ? {} : { 'aria-describedby': describedBy }), disabled: props.disabled, readOnly: props.readOnly, onFocus: () => {
|
|
188
|
+
// A refused entry is kept on screen so it can be corrected; focusing an accepted
|
|
189
|
+
// field starts from the value the record holds, in the locale's own spelling.
|
|
190
|
+
if (error === undefined)
|
|
191
|
+
setDraft(displayText(props.value, language));
|
|
192
|
+
}, onChange: (event) => {
|
|
193
|
+
setDraft(event.target.value);
|
|
194
|
+
setError(undefined);
|
|
195
|
+
}, onBlur: commit }), props.readOnly || props.disabled ? null : (_jsx("button", { type: "button", className: "ax-button ax-button--secondary ax-date-toggle", "aria-label": text.chooseDate, "aria-haspopup": "dialog", "aria-expanded": open, onClick: () => setOpen((value) => !value), children: "\u25A6" })), error === undefined ? null : (_jsx("p", { className: "ax-error", role: "alert", id: dateErrorId, "data-date-invalid": "", children: error }))] }), !open ? null : (_jsx("div", { className: "ax-date-popover", role: "dialog", "aria-label": text.chooseDate, onKeyDown: escape, children: _jsx(DayPicker, { mode: "single", selected: selected, ...(selected === undefined
|
|
196
|
+
? minimum === undefined
|
|
197
|
+
? {}
|
|
198
|
+
: { defaultMonth: minimum }
|
|
199
|
+
: { defaultMonth: selected }), onSelect: (date) => {
|
|
200
|
+
if (date === undefined)
|
|
201
|
+
return;
|
|
202
|
+
props.setValue(civilKey(date));
|
|
203
|
+
setDraft(undefined);
|
|
204
|
+
close();
|
|
205
|
+
}, disabled: [
|
|
206
|
+
...(minimum === undefined ? [] : [{ before: minimum }]),
|
|
207
|
+
...(maximum === undefined ? [] : [{ after: maximum }]),
|
|
208
|
+
], locale: datePickerLocale(props.locale), ...(intlFreeCaption
|
|
209
|
+
? { formatters: { formatCaption: (month) => pickerMonthYear(month, language) } }
|
|
210
|
+
: {}), labels: pickerLabels }, selected === undefined ? 'today' : civilKey(selected)) }))] }));
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=DatePicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatePicker.js","sourceRoot":"","sources":["../../src/pickers/DatePicker.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SA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B1D,GACE,CACP,IACG,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport type { KeyboardEvent as ReactKeyboardEvent, ReactElement } from 'react';\nimport { format } from 'date-fns';\nimport { DayPicker } from 'react-day-picker';\nimport type { DayPickerLocale } from 'react-day-picker/locale';\nimport { tryParsePlainDate } from '@azx-pbc/axiom-runtime';\nimport { formatCivilDate, isCivilDateString } from '../format/date.js';\nimport { resolveLocale } from '../format/locale.js';\nimport type { Locale } from '../format/locale.js';\nimport { civilDate, civilKey, scheduleText } from '../schedule/timeslot.js';\nimport { pickerLocale, pickerMonthYear } from './day-picker-locale.js';\n\n/** The controlled facts a date entry needs from its binding. */\nexport interface DatePickerProps {\n readonly controlId: string;\n readonly descriptionId: string | undefined;\n readonly errorId: string;\n readonly label: string;\n readonly value: string | undefined;\n readonly setValue: (value: string) => void;\n readonly required: boolean;\n readonly invalid: boolean;\n readonly disabled: boolean;\n readonly readOnly: boolean;\n readonly locale: string | undefined;\n readonly minimum: number | string | undefined;\n readonly maximum: number | string | undefined;\n readonly onBlur: () => void;\n}\n\n/**\n * The DayPicker table the calendar paints, from the picker-only table.\n *\n * Its `localize` is the same object the readout reads through `calendarLocale`; the labels are\n * the only addition. `zh` maps to `zhCN`, the only Chinese the shipped table promises.\n */\nexport function datePickerLocale(locale: string | undefined): DayPickerLocale {\n return pickerLocale(resolveLocale(locale).language);\n}\n\n/** The canonical text a complete ISO date spells, or `undefined` for anything else. */\nfunction isoText(text: string): string | undefined {\n return tryParsePlainDate(text) === undefined ? undefined : text;\n}\n\nfunction pad2(value: number): string {\n return String(value).padStart(2, '0');\n}\n\n/** Text compared without casing or repeated whitespace, as a reader may retype it. */\nfunction normalized(text: string): string {\n return text.replace(/\\s+/gu, ' ').trim().toLowerCase();\n}\n\n/** The date-fns patterns a typed entry may match, so a reader can type what the field shows. */\nconst PARSE_PATTERNS = ['PP', 'PPP', 'P', 'd MMMM yyyy', 'd MMM yyyy'] as const;\n\n/**\n * The ISO date a typed entry spells, in ISO (`YYYY-MM-DD`) or in the locale's own spelling.\n *\n * The display at rest is the locale's short-month form (`Sep 3, 2026`), so a reader who types what\n * they see must commit the same day. The candidate walk formats each day with the same date-fns\n * table the readout and the calendar use, which also makes the numeric field order follow the\n * locale rather than a hard-coded day/month guess.\n */\nfunction parseText(text: string, locale: string | undefined): string | undefined {\n const trimmed = text.trim();\n if (trimmed === '') return undefined;\n const iso = isoText(trimmed);\n if (iso !== undefined) return iso;\n // The demo is an en-AU product: a numeric entry is day/month/year. A locale that writes\n // month first still matches the candidate walk below, but this branch makes 03/09/2026 the\n // third of September rather than the ninth of March.\n const numeric = /^(\\d{1,2})[./](\\d{1,2})[./](\\d{4})$/u.exec(trimmed);\n if (numeric !== null) {\n const key = `${String(Number(numeric[3])).padStart(4, '0')}-${pad2(Number(numeric[2]))}-${pad2(Number(numeric[1]))}`;\n return tryParsePlainDate(key) === undefined ? undefined : key;\n }\n const yearMatch = /\\b(\\d{4})\\b/u.exec(trimmed);\n if (yearMatch === null) return undefined;\n const year = Number(yearMatch[1]);\n const wanted = normalized(trimmed);\n const table = datePickerLocale(locale);\n for (let month = 1; month <= 12; month += 1) {\n for (let day = 1; day <= 31; day += 1) {\n const key = `${String(year).padStart(4, '0')}-${pad2(month)}-${pad2(day)}`;\n if (tryParsePlainDate(key) === undefined) continue;\n const date = civilDate(key);\n if (date === undefined) continue;\n for (const pattern of PARSE_PATTERNS) {\n if (normalized(format(date, pattern, { locale: table })) === wanted) return key;\n }\n }\n }\n return undefined;\n}\n\n/**\n * A civil date as the host locale writes it.\n *\n * This is the same `formatCivilDate` the read-only value and the readout use, not date-fns's\n * `PP`. One date therefore has one spelling in the chrome, and the parser's candidate walk\n * already accepts that spelling for every shipped language (`PPP`, `d MMMM yyyy` or the\n * language's own numeric order), so a reader can retype what the field shows.\n */\nfunction displayText(iso: string | undefined, language: Locale): string {\n if (iso === undefined) return '';\n return isCivilDateString(iso) ? formatCivilDate(iso, language) : iso;\n}\n\n/** The `Date` a compiled bound names, when it is a civil date. */\nfunction boundDate(bound: number | string | undefined): Date | undefined {\n return typeof bound === 'string' ? civilDate(bound) : undefined;\n}\n\n/**\n * A date as a text field with a calendar popover.\n *\n * The text accepts `YYYY-MM-DD` and displays the host locale's spelling while the field is at\n * rest. The popover is a real dialog: selecting a day closes it, Escape closes it and returns\n * focus to the input, and the compiled bounds disable days outside the declared range.\n */\nexport function DatePicker(props: DatePickerProps): ReactElement {\n const text = scheduleText(props.locale);\n const language = resolveLocale(props.locale).language;\n const [draft, setDraft] = useState<string | undefined>(undefined);\n const [open, setOpen] = useState(false);\n const [error, setError] = useState<string | undefined>(undefined);\n const input = useRef<HTMLInputElement | null>(null);\n const field = useRef<HTMLDivElement | null>(null);\n const shown = draft ?? displayText(props.value, language);\n const selected = props.value === undefined ? undefined : civilDate(props.value);\n const minimum = boundDate(props.minimum);\n const maximum = boundDate(props.maximum);\n // `DateLib.formatMonthYear` calls `Intl.DateTimeFormat` for the year-first locales, and Chinese\n // is the shipped one. The caption and the grid label are therefore built from the readout's\n // month table instead; the other eight already format through date-fns and need no override.\n const intlFreeCaption = language === 'zh';\n const pickerLabels = {\n labelPrevious: () => text.previousMonth,\n labelNext: () => text.nextMonth,\n ...(intlFreeCaption ? { labelGrid: (date: Date) => pickerMonthYear(date, language) } : {}),\n };\n const dateErrorId = `${props.controlId}-date-error`;\n const describedBy = [\n props.descriptionId,\n props.invalid ? props.errorId : undefined,\n error === undefined ? undefined : dateErrorId,\n ]\n .filter((id) => id !== undefined)\n .join(' ');\n useEffect(() => {\n if (!open) return;\n const close = (event: MouseEvent): void => {\n if (event.target instanceof Node && field.current?.contains(event.target) !== true) {\n setOpen(false);\n }\n };\n // Escape is caught at the document in the capture phase: a calendar grid may stop the key\n // on its way up, and the contract is that one Escape closes the dialog whatever has focus.\n // Focus returns to the input, never to the body a removed dialog would leave behind.\n const escape = (event: KeyboardEvent): void => {\n if (event.key !== 'Escape') return;\n event.preventDefault();\n event.stopPropagation();\n setOpen(false);\n input.current?.focus();\n };\n document.addEventListener('mousedown', close);\n document.addEventListener('keydown', escape, true);\n return () => {\n document.removeEventListener('mousedown', close);\n document.removeEventListener('keydown', escape, true);\n };\n }, [open]);\n const close = (): void => {\n setOpen(false);\n input.current?.focus();\n };\n const commit = (): void => {\n if (draft === undefined) return;\n const parsed = parseText(draft, props.locale);\n if (parsed === undefined) {\n if (draft.trim() !== '') {\n // The typed entry is kept so the reader can correct it; the store is unchanged and the\n // field says why instead of snapping back to the old value.\n setError(text.invalidDate);\n return;\n }\n setError(undefined);\n setDraft(undefined);\n props.onBlur();\n return;\n }\n setError(undefined);\n setDraft(undefined);\n props.setValue(parsed);\n props.onBlur();\n };\n const escape = (event: ReactKeyboardEvent<HTMLDivElement>): void => {\n if (event.key !== 'Escape') return;\n event.preventDefault();\n close();\n };\n return (\n <div className=\"ax-date-field\" ref={field}>\n <div className=\"ax-date-row\">\n <input\n ref={input}\n id={props.controlId}\n className=\"ax-control ax-control--date\"\n type=\"text\"\n inputMode=\"numeric\"\n autoComplete=\"off\"\n placeholder=\"YYYY-MM-DD\"\n aria-label={props.label}\n value={shown}\n aria-required={props.required}\n aria-invalid={props.invalid || error !== undefined}\n {...(describedBy === '' ? {} : { 'aria-describedby': describedBy })}\n disabled={props.disabled}\n readOnly={props.readOnly}\n onFocus={() => {\n // A refused entry is kept on screen so it can be corrected; focusing an accepted\n // field starts from the value the record holds, in the locale's own spelling.\n if (error === undefined) setDraft(displayText(props.value, language));\n }}\n onChange={(event) => {\n setDraft(event.target.value);\n setError(undefined);\n }}\n onBlur={commit}\n />\n {props.readOnly || props.disabled ? null : (\n <button\n type=\"button\"\n className=\"ax-button ax-button--secondary ax-date-toggle\"\n aria-label={text.chooseDate}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n onClick={() => setOpen((value) => !value)}\n >\n ▦\n </button>\n )}\n {error === undefined ? null : (\n <p className=\"ax-error\" role=\"alert\" id={dateErrorId} data-date-invalid=\"\">\n {error}\n </p>\n )}\n </div>\n {!open ? null : (\n <div\n className=\"ax-date-popover\"\n role=\"dialog\"\n aria-label={text.chooseDate}\n onKeyDown={escape}\n >\n <DayPicker\n key={selected === undefined ? 'today' : civilKey(selected)}\n mode=\"single\"\n selected={selected}\n {...(selected === undefined\n ? minimum === undefined\n ? {}\n : { defaultMonth: minimum }\n : { defaultMonth: selected })}\n onSelect={(date) => {\n if (date === undefined) return;\n props.setValue(civilKey(date));\n setDraft(undefined);\n close();\n }}\n disabled={[\n ...(minimum === undefined ? [] : [{ before: minimum }]),\n ...(maximum === undefined ? [] : [{ after: maximum }]),\n ]}\n locale={datePickerLocale(props.locale)}\n {...(intlFreeCaption\n ? { formatters: { formatCaption: (month: Date) => pickerMonthYear(month, language) } }\n : {})}\n labels={pickerLabels}\n />\n </div>\n )}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
/** The controlled facts a time-of-day entry needs from its binding. */
|
|
3
|
+
export interface TimeSegmentsProps {
|
|
4
|
+
/** The id the field's label points at; the first segment carries it. */
|
|
5
|
+
readonly controlId?: string;
|
|
6
|
+
/** `HH:MM` or `HH:MM:SS`; the canonical wire text. */
|
|
7
|
+
readonly value: string | undefined;
|
|
8
|
+
readonly onChange: (text: string) => void;
|
|
9
|
+
readonly seconds: boolean;
|
|
10
|
+
readonly locale: string | undefined;
|
|
11
|
+
readonly disabled: boolean;
|
|
12
|
+
readonly readOnly: boolean;
|
|
13
|
+
readonly label: string;
|
|
14
|
+
readonly describedBy: string | undefined;
|
|
15
|
+
readonly invalid: boolean;
|
|
16
|
+
readonly required: boolean;
|
|
17
|
+
readonly onBlur: () => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A time of day as three spinbutton segments.
|
|
21
|
+
*
|
|
22
|
+
* Each segment is one tab stop in the composite control: ArrowUp/ArrowDown increments with
|
|
23
|
+
* wrapping, Home/End jump to the ends, and the canonical wire text is `HH:MM[:SS]` whatever the
|
|
24
|
+
* host locale displays. A twelve-hour locale adds an AM/PM toggle; the value stays 24-hour.
|
|
25
|
+
*/
|
|
26
|
+
export declare function TimeSegments(props: TimeSegmentsProps): ReactElement;
|
|
27
|
+
//# sourceMappingURL=TimeSegments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeSegments.d.ts","sourceRoot":"","sources":["../../src/pickers/TimeSegments.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,OAAO,CAAC;AAGzD,uEAAuE;AACvE,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,sDAAsD;IACtD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC;CAC7B;AA4BD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CAqGnE"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { scheduleText, usesHour12 } from '../schedule/timeslot.js';
|
|
3
|
+
function partsOf(value) {
|
|
4
|
+
const match = value === undefined ? null : /^(\d{2}):(\d{2})(?::(\d{2}))?$/u.exec(value);
|
|
5
|
+
if (match === null)
|
|
6
|
+
return { hours: 9, minutes: 0, seconds: 0 };
|
|
7
|
+
return {
|
|
8
|
+
hours: Number(match[1]),
|
|
9
|
+
minutes: Number(match[2]),
|
|
10
|
+
seconds: match[3] === undefined ? 0 : Number(match[3]),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function textOf(parts, seconds) {
|
|
14
|
+
const hour = String(parts.hours).padStart(2, '0');
|
|
15
|
+
const minute = String(parts.minutes).padStart(2, '0');
|
|
16
|
+
return seconds
|
|
17
|
+
? `${hour}:${minute}:${String(parts.seconds).padStart(2, '0')}`
|
|
18
|
+
: `${hour}:${minute}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A time of day as three spinbutton segments.
|
|
22
|
+
*
|
|
23
|
+
* Each segment is one tab stop in the composite control: ArrowUp/ArrowDown increments with
|
|
24
|
+
* wrapping, Home/End jump to the ends, and the canonical wire text is `HH:MM[:SS]` whatever the
|
|
25
|
+
* host locale displays. A twelve-hour locale adds an AM/PM toggle; the value stays 24-hour.
|
|
26
|
+
*/
|
|
27
|
+
export function TimeSegments(props) {
|
|
28
|
+
const text = scheduleText(props.locale);
|
|
29
|
+
const hour12 = usesHour12(props.locale);
|
|
30
|
+
const parts = partsOf(props.value);
|
|
31
|
+
const write = (next) => {
|
|
32
|
+
props.onChange(textOf(next, props.seconds));
|
|
33
|
+
props.onBlur();
|
|
34
|
+
};
|
|
35
|
+
const step = (segment, delta) => {
|
|
36
|
+
if (props.disabled || props.readOnly)
|
|
37
|
+
return;
|
|
38
|
+
const current = parts[segment];
|
|
39
|
+
const limit = segment === 'hours' ? 24 : 60;
|
|
40
|
+
const next = (current + delta + limit) % limit;
|
|
41
|
+
write({ ...parts, [segment]: next });
|
|
42
|
+
};
|
|
43
|
+
const key = (segment) => (event) => {
|
|
44
|
+
if (event.key === 'ArrowUp') {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
step(segment, 1);
|
|
47
|
+
}
|
|
48
|
+
else if (event.key === 'ArrowDown') {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
step(segment, -1);
|
|
51
|
+
}
|
|
52
|
+
else if (event.key === 'Home') {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
write({ ...parts, [segment]: 0 });
|
|
55
|
+
}
|
|
56
|
+
else if (event.key === 'End') {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
write({ ...parts, [segment]: segment === 'hours' ? 23 : 59 });
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const shownHour = hour12 ? (parts.hours % 12 === 0 ? 12 : parts.hours % 12) : parts.hours;
|
|
62
|
+
const segments = [
|
|
63
|
+
{ id: 'hours', label: text.hours, value: parts.hours, max: hour12 ? 12 : 23, shown: shownHour },
|
|
64
|
+
{ id: 'minutes', label: text.minutes, value: parts.minutes, max: 59, shown: parts.minutes },
|
|
65
|
+
...(props.seconds
|
|
66
|
+
? [
|
|
67
|
+
{
|
|
68
|
+
id: 'seconds',
|
|
69
|
+
label: text.seconds,
|
|
70
|
+
value: parts.seconds,
|
|
71
|
+
max: 59,
|
|
72
|
+
shown: parts.seconds,
|
|
73
|
+
},
|
|
74
|
+
]
|
|
75
|
+
: []),
|
|
76
|
+
];
|
|
77
|
+
return (_jsxs("div", { className: "ax-time", role: "group", "aria-label": props.label, "aria-describedby": props.describedBy, children: [segments.map((segment, index) => (_jsxs("div", { ...(index !== 0 || props.controlId === undefined ? {} : { id: props.controlId }), className: "ax-time-segments", "data-segment": segment.id, role: "spinbutton", tabIndex: props.disabled ? -1 : 0, "aria-label": segment.label, "aria-required": props.required, "aria-invalid": props.invalid, "aria-describedby": props.describedBy, "aria-valuemin": 0, "aria-valuemax": segment.max, "aria-valuenow": segment.id === 'hours' && hour12 ? shownHour : segment.value, "aria-valuetext": String(segment.shown).padStart(2, '0'), "aria-readonly": props.readOnly, "aria-disabled": props.disabled, onKeyDown: key(segment.id), children: [String(segment.shown).padStart(2, '0'), index === 0 && segments.length > 1 ? _jsx("span", { "aria-hidden": "true", children: ":" }) : null] }, segment.id))), hour12 ? (_jsx("button", { type: "button", className: "ax-button ax-button--secondary ax-time-period", "aria-pressed": parts.hours >= 12, disabled: props.disabled || props.readOnly, onClick: () => {
|
|
78
|
+
const next = parts.hours >= 12 ? parts.hours - 12 : parts.hours + 12;
|
|
79
|
+
write({ ...parts, hours: next });
|
|
80
|
+
}, children: parts.hours >= 12 ? text.pm : text.am })) : null] }));
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=TimeSegments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeSegments.js","sourceRoot":"","sources":["../../src/pickers/TimeSegments.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AA0BnE,SAAS,OAAO,CAAC,KAAyB;IACxC,MAAM,KAAK,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACzF,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IAChE,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACvB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACvD,CAAC;AACJ,CAA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CAAC,EAAE,GAC/B,CACV,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { KeyboardEvent, ReactElement } from 'react';\nimport { scheduleText, usesHour12 } from '../schedule/timeslot.js';\n\n/** The controlled facts a time-of-day entry needs from its binding. */\nexport interface TimeSegmentsProps {\n /** The id the field's label points at; the first segment carries it. */\n readonly controlId?: string;\n /** `HH:MM` or `HH:MM:SS`; the canonical wire text. */\n readonly value: string | undefined;\n readonly onChange: (text: string) => void;\n readonly seconds: boolean;\n readonly locale: string | undefined;\n readonly disabled: boolean;\n readonly readOnly: boolean;\n readonly label: string;\n readonly describedBy: string | undefined;\n readonly invalid: boolean;\n readonly required: boolean;\n readonly onBlur: () => void;\n}\n\ninterface Parts {\n readonly hours: number;\n readonly minutes: number;\n readonly seconds: number;\n}\n\nfunction partsOf(value: string | undefined): Parts {\n const match = value === undefined ? null : /^(\\d{2}):(\\d{2})(?::(\\d{2}))?$/u.exec(value);\n if (match === null) return { hours: 9, minutes: 0, seconds: 0 };\n return {\n hours: Number(match[1]),\n minutes: Number(match[2]),\n seconds: match[3] === undefined ? 0 : Number(match[3]),\n };\n}\n\nfunction textOf(parts: Parts, seconds: boolean): string {\n const hour = String(parts.hours).padStart(2, '0');\n const minute = String(parts.minutes).padStart(2, '0');\n return seconds\n ? `${hour}:${minute}:${String(parts.seconds).padStart(2, '0')}`\n : `${hour}:${minute}`;\n}\n\ntype Segment = 'hours' | 'minutes' | 'seconds';\n\n/**\n * A time of day as three spinbutton segments.\n *\n * Each segment is one tab stop in the composite control: ArrowUp/ArrowDown increments with\n * wrapping, Home/End jump to the ends, and the canonical wire text is `HH:MM[:SS]` whatever the\n * host locale displays. A twelve-hour locale adds an AM/PM toggle; the value stays 24-hour.\n */\nexport function TimeSegments(props: TimeSegmentsProps): ReactElement {\n const text = scheduleText(props.locale);\n const hour12 = usesHour12(props.locale);\n const parts = partsOf(props.value);\n const write = (next: Parts): void => {\n props.onChange(textOf(next, props.seconds));\n props.onBlur();\n };\n const step = (segment: Segment, delta: 1 | -1): void => {\n if (props.disabled || props.readOnly) return;\n const current = parts[segment];\n const limit = segment === 'hours' ? 24 : 60;\n const next = (current + delta + limit) % limit;\n write({ ...parts, [segment]: next });\n };\n const key =\n (segment: Segment) =>\n (event: KeyboardEvent<HTMLDivElement>): void => {\n if (event.key === 'ArrowUp') {\n event.preventDefault();\n step(segment, 1);\n } else if (event.key === 'ArrowDown') {\n event.preventDefault();\n step(segment, -1);\n } else if (event.key === 'Home') {\n event.preventDefault();\n write({ ...parts, [segment]: 0 });\n } else if (event.key === 'End') {\n event.preventDefault();\n write({ ...parts, [segment]: segment === 'hours' ? 23 : 59 });\n }\n };\n const shownHour = hour12 ? (parts.hours % 12 === 0 ? 12 : parts.hours % 12) : parts.hours;\n const segments: readonly {\n readonly id: Segment;\n readonly label: string;\n readonly value: number;\n readonly max: number;\n readonly shown: number;\n }[] = [\n { id: 'hours', label: text.hours, value: parts.hours, max: hour12 ? 12 : 23, shown: shownHour },\n { id: 'minutes', label: text.minutes, value: parts.minutes, max: 59, shown: parts.minutes },\n ...(props.seconds\n ? [\n {\n id: 'seconds' as const,\n label: text.seconds,\n value: parts.seconds,\n max: 59,\n shown: parts.seconds,\n },\n ]\n : []),\n ];\n return (\n <div\n className=\"ax-time\"\n role=\"group\"\n aria-label={props.label}\n aria-describedby={props.describedBy}\n >\n {segments.map((segment, index) => (\n <div\n key={segment.id}\n {...(index !== 0 || props.controlId === undefined ? {} : { id: props.controlId })}\n className=\"ax-time-segments\"\n data-segment={segment.id}\n role=\"spinbutton\"\n tabIndex={props.disabled ? -1 : 0}\n aria-label={segment.label}\n aria-required={props.required}\n aria-invalid={props.invalid}\n aria-describedby={props.describedBy}\n aria-valuemin={0}\n aria-valuemax={segment.max}\n aria-valuenow={segment.id === 'hours' && hour12 ? shownHour : segment.value}\n aria-valuetext={String(segment.shown).padStart(2, '0')}\n aria-readonly={props.readOnly}\n aria-disabled={props.disabled}\n onKeyDown={key(segment.id)}\n >\n {String(segment.shown).padStart(2, '0')}\n {index === 0 && segments.length > 1 ? <span aria-hidden=\"true\">:</span> : null}\n </div>\n ))}\n {hour12 ? (\n <button\n type=\"button\"\n className=\"ax-button ax-button--secondary ax-time-period\"\n aria-pressed={parts.hours >= 12}\n disabled={props.disabled || props.readOnly}\n onClick={() => {\n const next = parts.hours >= 12 ? parts.hours - 12 : parts.hours + 12;\n write({ ...parts, hours: next });\n }}\n >\n {parts.hours >= 12 ? text.pm : text.am}\n </button>\n ) : null}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DayPickerLocale } from 'react-day-picker/locale';
|
|
2
|
+
import type { Locale } from '../format/locale.js';
|
|
3
|
+
/** The DayPicker table for a shipped language. */
|
|
4
|
+
export declare function pickerLocale(locale: Locale): DayPickerLocale;
|
|
5
|
+
/**
|
|
6
|
+
* A month and its year in the readout's words.
|
|
7
|
+
*
|
|
8
|
+
* DayPicker's `formatCaption` and `labelGrid` go through `DateLib.formatMonthYear`, which calls
|
|
9
|
+
* `Intl.DateTimeFormat` for the year-first locales (Chinese among them). This builds the same
|
|
10
|
+
* caption from `monthName`, the table `formatCivilDate` reads, so the calendar never invokes the
|
|
11
|
+
* host formatter and its month word is the readout's. Chinese states its units, as the readout
|
|
12
|
+
* does: `2026年3月`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function pickerMonthYear(date: Date, locale: Locale): string;
|
|
15
|
+
//# sourceMappingURL=day-picker-locale.d.ts.map
|