frontile 0.18.0-beta.5 → 0.18.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.
Files changed (70) hide show
  1. package/declarations/components/buttons/chip.d.ts +1 -1
  2. package/declarations/components/buttons/chip.d.ts.map +1 -1
  3. package/declarations/components/collections/dropdown/menu-context.d.ts +10 -0
  4. package/declarations/components/collections/dropdown/menu-context.d.ts.map +1 -1
  5. package/declarations/components/collections/dropdown/sub.d.ts +34 -0
  6. package/declarations/components/collections/dropdown/sub.d.ts.map +1 -1
  7. package/declarations/components/forms/autocomplete.d.ts +12 -12
  8. package/declarations/components/forms/date-input/clipboard.d.ts +34 -0
  9. package/declarations/components/forms/date-input/clipboard.d.ts.map +1 -0
  10. package/declarations/components/forms/date-input/date-input.d.ts +91 -0
  11. package/declarations/components/forms/date-input/date-input.d.ts.map +1 -0
  12. package/declarations/components/forms/date-input/segment-group.d.ts +130 -0
  13. package/declarations/components/forms/date-input/segment-group.d.ts.map +1 -0
  14. package/declarations/components/forms/date-input/segments.d.ts +137 -0
  15. package/declarations/components/forms/date-input/segments.d.ts.map +1 -0
  16. package/declarations/components/forms/date-input/types.d.ts +134 -0
  17. package/declarations/components/forms/date-input/types.d.ts.map +1 -0
  18. package/declarations/components/forms/date-input.d.ts +6 -0
  19. package/declarations/components/forms/date-input.d.ts.map +1 -0
  20. package/declarations/components/forms/date-picker/date-picker.d.ts +248 -15
  21. package/declarations/components/forms/date-picker/date-picker.d.ts.map +1 -1
  22. package/declarations/components/forms/date-picker/end-content.d.ts +33 -3
  23. package/declarations/components/forms/date-picker/end-content.d.ts.map +1 -1
  24. package/declarations/components/forms/date-picker/types.d.ts +30 -1
  25. package/declarations/components/forms/date-picker/types.d.ts.map +1 -1
  26. package/declarations/components/forms/field.d.ts +3 -0
  27. package/declarations/components/forms/field.d.ts.map +1 -1
  28. package/declarations/components/forms/index.d.ts +1 -0
  29. package/declarations/components/forms/index.d.ts.map +1 -1
  30. package/declarations/components/forms/input.d.ts +11 -11
  31. package/declarations/components/forms/native-select.d.ts +8 -8
  32. package/declarations/components/forms/select/select.d.ts +16 -16
  33. package/declarations/components/forms/textarea.d.ts +7 -7
  34. package/declarations/components/utilities/avatar.d.ts +35 -2
  35. package/declarations/components/utilities/avatar.d.ts.map +1 -1
  36. package/declarations/test-support.d.ts +30 -0
  37. package/declarations/test-support.d.ts.map +1 -1
  38. package/dist/components/buttons/chip.js.map +1 -1
  39. package/dist/components/collections/dropdown/menu-context.js.map +1 -1
  40. package/dist/components/collections/dropdown/sub.js +76 -11
  41. package/dist/components/collections/dropdown/sub.js.map +1 -1
  42. package/dist/components/forms/date-input/clipboard.js +162 -0
  43. package/dist/components/forms/date-input/clipboard.js.map +1 -0
  44. package/dist/components/forms/date-input/date-input.js +194 -0
  45. package/dist/components/forms/date-input/date-input.js.map +1 -0
  46. package/dist/components/forms/date-input/segment-group.js +271 -0
  47. package/dist/components/forms/date-input/segment-group.js.map +1 -0
  48. package/dist/components/forms/date-input/segments.js +379 -0
  49. package/dist/components/forms/date-input/segments.js.map +1 -0
  50. package/dist/components/forms/date-input/types.js +2 -0
  51. package/dist/components/forms/date-input/types.js.map +1 -0
  52. package/dist/components/forms/date-input.js +4 -0
  53. package/dist/components/forms/date-input.js.map +1 -0
  54. package/dist/components/forms/date-picker/date-picker.js +301 -14
  55. package/dist/components/forms/date-picker/date-picker.js.map +1 -1
  56. package/dist/components/forms/date-picker/end-content.js +17 -4
  57. package/dist/components/forms/date-picker/end-content.js.map +1 -1
  58. package/dist/components/forms/field.js +4 -1
  59. package/dist/components/forms/field.js.map +1 -1
  60. package/dist/components/forms/index.js +3 -0
  61. package/dist/components/forms/index.js.map +1 -1
  62. package/dist/components/utilities/avatar.js +30 -5
  63. package/dist/components/utilities/avatar.js.map +1 -1
  64. package/dist/forms.js +3 -0
  65. package/dist/forms.js.map +1 -1
  66. package/dist/index.js +3 -0
  67. package/dist/index.js.map +1 -1
  68. package/dist/test-support.js +480 -1
  69. package/dist/test-support.js.map +1 -1
  70. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clipboard.js","sources":["../../../../src/components/forms/date-input/clipboard.ts"],"sourcesContent":["import {\n isSegment,\n resolveTwoDigitYear,\n displaySegment,\n withValue\n} from './segments';\nimport type { Part, Segment, SegmentType } from './types';\n\nconst ISO_DAY = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\n\n/** The digits destined for each segment, keyed by type. */\ntype Digits = Partial<Record<SegmentType, string>>;\n\n/**\n * Writes digit strings onto the segments they name.\n *\n * Digits stay *strings* all the way in, because a year's leading zeros carry\n * meaning: `0045` is the year 45, while `45` runs through the sliding window.\n * Passing numbers here would erase that distinction and make a pasted `0045`\n * resolve differently from a typed one.\n *\n * A segment no key names is left untouched, which is what lets a partial paste\n * fill what it can. Out of bounds refuses the *whole* paste rather than\n * clamping: clamping would turn a paste of `99/99/2026` into a plausible\n * looking date the user never meant. The day is the exception by design -- its\n * bound is 31 and the real length of the month is applied later, by `toDate`,\n * so a pasted 31st of February shortens to the 28th exactly as a typed one\n * does.\n */\nfunction fill(parts: Part[], digits: Digits): Part[] | null {\n let filled = 0;\n\n const next: Part[] = [];\n for (const part of parts) {\n if (!isSegment(part)) {\n next.push(part);\n continue;\n }\n\n const raw = digits[part.type];\n if (raw === undefined) {\n next.push(part);\n continue;\n }\n\n const value = part.type === 'year' ? resolveTwoDigitYear(raw) : Number(raw);\n if (Number.isNaN(value) || value < part.min || value > part.max) {\n return null;\n }\n\n filled++;\n // A paste is a finished answer for every segment it fills.\n next.push(withValue(part, value));\n }\n\n // Nothing landed anywhere -- treat that as a refusal rather than quietly\n // handing back an untouched field.\n return filled === 0 ? null : next;\n}\n\n/** Maps digit groups onto the segments in their rendered order. */\nfunction byPosition(segments: Segment[], groups: string[]): Digits | null {\n if (groups.length === 0 || groups.length > segments.length) return null;\n\n const digits: Digits = {};\n groups.forEach((group, i) => {\n const segment = segments[i];\n if (segment) digits[segment.type] = group;\n });\n return digits;\n}\n\n/**\n * Reads pasted text into the segments, trying each strategy in turn and\n * stopping at the first that works.\n *\n * Every strategy lands in `fill`, so all three share one bounds policy. There\n * is deliberately no `new Date(text)` fallback: it parses differently in every\n * engine, and a date field that silently guesses wrong is worse than one that\n * declines.\n */\nfunction parsePasted(text: string, parts: Part[]): Part[] | null {\n const trimmed = text.trim();\n if (trimmed === '') return null;\n\n // 1. ISO, which is unambiguous and so outranks the locale's own order.\n const iso = ISO_DAY.exec(trimmed);\n if (iso) {\n const [, year, month, day] = iso;\n return fill(parts, { year, month, day });\n }\n\n const segments = parts.filter(isSegment);\n\n // 2. A bare digit run, split by each segment's width. Checked before the\n // separated form, because an unseparated run also splits into a single\n // \"group\" and would otherwise be read as one enormous month.\n if (/^\\d+$/.test(trimmed)) {\n const widths: string[] = [];\n let at = 0;\n for (const segment of segments) {\n if (at >= trimmed.length) break;\n widths.push(trimmed.slice(at, at + segment.width));\n at += segment.width;\n }\n\n // It has to end on a segment boundary, otherwise there is no telling\n // where the last number was meant to stop.\n if (at !== trimmed.length) return null;\n\n const digits = byPosition(segments, widths);\n return digits ? fill(parts, digits) : null;\n }\n\n // 3. Separated numbers, mapped positionally onto the locale's order. Fewer\n // groups than segments is a partial date and fills a prefix of them.\n const groups = trimmed.split(/\\D+/).filter(Boolean);\n const digits = byPosition(segments, groups);\n if (digits) return fill(parts, digits);\n\n return null;\n}\n\n/**\n * The field as it reads on screen, literals included. Copying the display\n * rather than an ISO string means the text round-trips through `parsePasted`\n * and still reads naturally when pasted into a document.\n *\n * Delegates each segment to `displaySegment`, the same function the group\n * renders from, so a mid-entry year (buffer `26`, uncommitted) copies as\n * `26` rather than being padded to `0026` -- padding would claim digits the\n * user never typed and would contradict what is on screen.\n */\nfunction formatForClipboard(parts: Part[]): string {\n return parts\n .map((part) => (isSegment(part) ? displaySegment(part) : part.text))\n .join('');\n}\n\n/**\n * What separates the two halves of a pasted range.\n *\n * An en or em dash needs no surrounding space, because neither ever appears\n * inside a date. A plain hyphen does: it is the ISO separator, so splitting on\n * an unspaced one would tear `2026-01-20` into pieces. The same reasoning\n * applies to the words -- `\\s+` on both sides keeps \"to\" from matching inside\n * \"total\".\n */\nconst RANGE_SEPARATOR = /\\s*[\\u2013\\u2014]\\s*|\\s+(?:-|to|until|through)\\s+/i;\n\n/**\n * Splits pasted text into the two dates of a range, or returns `null` when it\n * does not read as two.\n *\n * Only the shape is decided here; neither half is parsed. The caller runs each\n * through {@link parsePasted} and keeps the result only when both halves are\n * dates -- so text that merely contains a dash falls through to the ordinary\n * single-date handling rather than being consumed.\n */\nfunction splitRange(text: string): [string, string] | null {\n const trimmed = text.trim();\n const match = RANGE_SEPARATOR.exec(trimmed);\n if (!match) return null;\n\n const start = trimmed.slice(0, match.index).trim();\n const end = trimmed.slice(match.index + match[0].length).trim();\n if (start === '' || end === '') return null;\n\n // Three halves is not a range, and guessing which two were meant would be\n // exactly the silent wrong guess this module declines to make elsewhere.\n if (RANGE_SEPARATOR.test(end)) return null;\n\n return [start, end];\n}\n\nexport { parsePasted, formatForClipboard, splitRange };\n"],"names":["ISO_DAY","fill","parts","digits","filled","next","part","isSegment","push","raw","type","undefined","value","resolveTwoDigitYear","Number","isNaN","min","max","withValue","byPosition","segments","groups","length","forEach","group","i","segment","parsePasted","text","trimmed","trim","iso","exec","year","month","day","filter","test","widths","at","slice","width","split","Boolean","formatForClipboard","map","displaySegment","join","RANGE_SEPARATOR","splitRange","match","start","index","end"],"mappings":";;AAQA,MAAMA,OAAO,GAAG,2BAA2B;;AAE3C;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,IAAIA,CAACC,KAAa,EAAEC,MAAc,EAAiB;EAC1D,IAAIC,MAAM,GAAG,CAAC;EAEd,MAAMC,IAAY,GAAG,EAAE;AACvB,EAAA,KAAK,MAAMC,IAAI,IAAIJ,KAAK,EAAE;AACxB,IAAA,IAAI,CAACK,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K,KAAK,EAAE,IAAIE,GAAG,KAAK,EAAE,EAAE,OAAO,IAAI;;AAE3C;AACA;EACA,IAAIL,eAAe,CAACX,IAAI,CAACgB,GAAG,CAAC,EAAE,OAAO,IAAI;AAE1C,EAAA,OAAO,CAACF,KAAK,EAAEE,GAAG,CAAC;AACrB;;"}
@@ -0,0 +1,194 @@
1
+ import Component from '@glimmer/component';
2
+ import { tracked, cached } from '@glimmer/tracking';
3
+ import { on } from '@ember/modifier';
4
+ import { modifier } from 'ember-modifier';
5
+ import { useStyles } from '@frontile/theme';
6
+ import { FormControl } from '../form-control.js';
7
+ import { CloseButton } from '../../buttons/close-button.js';
8
+ import { SegmentGroup } from './segment-group.js';
9
+ import { fromDate, buildParts, resolveSegmentFormat, toDate, isSegment, hasDateChanged, carryOver } from './segments.js';
10
+ import { parseDate, toWire } from '../date-picker/value.js';
11
+ import { ref } from '../../../utils/ref.js';
12
+ import { triggerFormInputEvent } from '../../../utils/forms-utils-index.js';
13
+ import { precompileTemplate } from '@ember/template-compilation';
14
+ import { setComponentTemplate } from '@ember/component';
15
+ import { d as decorateFieldV2, i as initializeDeferredDecorator, a as decorateMethodV2 } from '../../../runtime--fcdnjmJ-BOdRhmsS.js';
16
+
17
+ /**
18
+ * A date typed into segments rather than picked from a grid. `DatePicker`
19
+ * renders the same segments and adds a calendar.
20
+ */
21
+ class DateInput extends Component {
22
+ containerRef = ref();
23
+ /**
24
+ * The segments are the state, not the value: mid-entry they hold digits that
25
+ * compose to no date at all, which no `Date` can represent.
26
+ */
27
+ static {
28
+ decorateFieldV2(this.prototype, "trackedParts", [tracked], function () {
29
+ return [];
30
+ });
31
+ }
32
+ #trackedParts = (initializeDeferredDecorator(this, "trackedParts"), void 0);
33
+ /**
34
+ * An untracked mirror of {@link parts}. The sync modifiers below need to
35
+ * read the current segments in order to rebuild them, and reading the
36
+ * tracked field inside a modifier would put it in that modifier's own
37
+ * tracking frame -- which the same modifier then writes to, re-running
38
+ * itself forever.
39
+ */
40
+ #currentParts = [];
41
+ constructor(owner, args) {
42
+ super(owner, args);
43
+ const seed = args.defaultValue;
44
+ this.setParts(fromDate(buildParts(this.locale, this.formatOptions), seed === undefined ? null : parseDate(seed)));
45
+ }
46
+ get parts() {
47
+ return this.trackedParts;
48
+ }
49
+ setParts(parts) {
50
+ this.#currentParts = parts;
51
+ this.trackedParts = parts;
52
+ }
53
+ get locale() {
54
+ return this.args.locale ?? navigator.language;
55
+ }
56
+ get formatOptions() {
57
+ // A textual month has no numeric segment to type into, so it falls back
58
+ // to a numeric one. `dateStyle: 'medium'` is the common way to hit this --
59
+ // it is DatePicker's button-trigger default. Only the month is replaced:
60
+ // the rest of the format is the consumer's and stands.
61
+ return resolveSegmentFormat(this.args.formatOptions, {
62
+ message: '<DateInput> needs numeric segments; ' + 'a textual @formatOptions month falls back to a numeric one.',
63
+ id: 'frontile.date-input.textual-format'
64
+ });
65
+ }
66
+ /**
67
+ * The composed value, or null while any segment is empty.
68
+ *
69
+ * Cached because `wireValue`, `isOutOfRange` and the template all read it
70
+ * independently, and each `toDate` walks the parts three times over.
71
+ */
72
+ get value() {
73
+ return toDate(this.parts);
74
+ }
75
+ static {
76
+ decorateMethodV2(this.prototype, "value", [cached]);
77
+ }
78
+ get wireValue() {
79
+ return toWire(this.value);
80
+ }
81
+ get isEmpty() {
82
+ return this.parts.every(p => !isSegment(p) || p.value === null);
83
+ }
84
+ get placeholderValue() {
85
+ return this.args.placeholderValue ?? new Date();
86
+ }
87
+ /**
88
+ * Whether the composed value is outside the allowed range. Never blocks a
89
+ * keystroke -- typing toward 2020 passes through 2, 20 and 202 on the way,
90
+ * and a field that refused those could not be typed into at all.
91
+ */
92
+ get isOutOfRange() {
93
+ const value = this.value;
94
+ if (!value) return false;
95
+ if (this.args.minValue && value < this.args.minValue) return true;
96
+ if (this.args.maxValue && value > this.args.maxValue) return true;
97
+ return this.args.isDateUnavailable?.(value) ?? false;
98
+ }
99
+ get isInvalid() {
100
+ return Boolean(this.args.isInvalid) || this.isOutOfRange;
101
+ }
102
+ /**
103
+ * Pushes `@value` into the segments when the argument changes. `undefined`
104
+ * is ignored, so a field bound by `Field` before the form holds anything for
105
+ * it keeps what the user typed -- the rule `DatePicker` documents.
106
+ */
107
+ syncValue = modifier((_, [raw]) => {
108
+ if (raw === undefined) return;
109
+ const parsed = parseDate(raw);
110
+ // Ignore the echo of our own `@onChange`. A controlled consumer writes
111
+ // back the value this field just reported, and rewriting the segments
112
+ // from it would destroy a partial entry: backspacing one digit of the
113
+ // year un-commits it, so the field composes `null`, reports `null`, and
114
+ // is handed `null` straight back -- which `fromDate` would spend on
115
+ // clearing every other segment too. One keystroke would empty the field.
116
+ if (!hasDateChanged(toDate(this.#currentParts), parsed)) return;
117
+ this.setParts(fromDate(this.#currentParts, parsed));
118
+ });
119
+ /**
120
+ * Rebuilds the segment order when the locale or format changes, carrying
121
+ * each segment's own state across so switching en-US to en-GB reorders the
122
+ * field without emptying it -- half-typed digits included, which is why
123
+ * this goes segment by segment rather than through the composed value.
124
+ */
125
+ syncLocale = modifier((_, [locale, format]) => {
126
+ this.setParts(carryOver(buildParts(locale, format), this.#currentParts));
127
+ });
128
+ handlePartsChange = parts => {
129
+ const before = toDate(this.#currentParts);
130
+ this.setParts(parts);
131
+ const after = toDate(parts);
132
+ // Only value transitions are reported. The four keystrokes that fill a
133
+ // month and a day compose no date at all, and report nothing.
134
+ if (hasDateChanged(before, after)) {
135
+ this.args.onChange?.(after);
136
+ triggerFormInputEvent(this.containerRef.current);
137
+ }
138
+ };
139
+ /**
140
+ * `@onBlur` means "the user left the field", not "the user left a segment",
141
+ * so a move between segments is filtered out by asking whether focus landed
142
+ * inside the container. `DatePicker` needs `ControlBlurTracker` for this
143
+ * because its focus can legitimately be in a popover outside its own DOM;
144
+ * this field has no popover, so containment is the whole question.
145
+ */
146
+ handleFocusOut = event => {
147
+ const container = this.containerRef.current;
148
+ const next = event.relatedTarget;
149
+ if (container && next instanceof Node && container.contains(next)) return;
150
+ this.args.onBlur?.();
151
+ };
152
+ /**
153
+ * A disabled or read-only field never offers it: it carries no disabled
154
+ * state of its own and would be a live button clearing a field the user may
155
+ * not change.
156
+ */
157
+ get isClearable() {
158
+ return Boolean(this.args.isClearable) && !this.isEmpty && !this.args.isDisabled && !this.args.isReadOnly;
159
+ }
160
+ /**
161
+ * Clearing removes the clear button from the DOM (`isClearable` flips
162
+ * false the instant the value is gone), so focus must be handed somewhere
163
+ * explicitly or it falls to `<body>` and a keyboard user loses their place.
164
+ */
165
+ clear = () => {
166
+ this.handlePartsChange(fromDate(this.#currentParts, null));
167
+ this.containerRef.current?.querySelector('[data-part="segment"]')?.focus();
168
+ };
169
+ get classes() {
170
+ const {
171
+ dateInput
172
+ } = useStyles();
173
+ return dateInput({
174
+ size: this.args.inputSize
175
+ });
176
+ }
177
+ static {
178
+ decorateMethodV2(this.prototype, "classes", [cached]);
179
+ }
180
+ static {
181
+ setComponentTemplate(precompileTemplate("<div {{this.syncLocale this.locale this.formatOptions}} {{this.syncValue @value}} {{this.containerRef.setup}} {{on \"focusout\" this.handleFocusOut}} class={{this.classes.base class=@classes.base}} data-component=\"date-input\" data-part=\"base\" ...attributes>\n {{#if @name}}\n <input type=\"hidden\" name={{@name}} value={{this.wireValue}} />\n {{/if}}\n\n <FormControl @id={{@id}} @size={{@inputSize}} @label={{@label}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{this.isInvalid}} @isDisabled={{@isDisabled}} as |c|>\n <div class={{this.classes.innerContainer class=@classes.innerContainer}} data-part=\"inner-container\" {{!-- The field shell lives here, not on the segment row, so the clear\n button sits inside the border. `role=\"group\"` supports neither\n aria-invalid nor aria-disabled, so the shell styles off these. --}} data-invalid={{if c.isInvalid \"true\" \"false\"}} data-disabled={{if @isDisabled \"true\" \"false\"}}>\n <SegmentGroup @parts={{this.parts}} @onPartsChange={{this.handlePartsChange}} @locale={{this.locale}} @placeholderValue={{this.placeholderValue}} @isDisabled={{@isDisabled}} @isReadOnly={{@isReadOnly}} @isInvalid={{c.isInvalid}} @id={{c.id}} @label={{@label}} @describedBy={{c.describedBy @description c.isInvalid}} @segmentLabels={{@segmentLabels}} @classes={{this.classes}} @userClasses={{@classes}} />\n {{#if this.isClearable}}\n <div data-part=\"end-content\" class={{this.classes.endContent class=@classes.endContent}}>\n <CloseButton @title=\"Clear\" @variant=\"soft\" @size=\"xs\" @class={{this.classes.clearButton class=@classes.clearButton}} data-part=\"clear-button\" @onPress={{this.clear}} />\n </div>\n {{/if}}\n </div>\n </FormControl>\n</div>", {
182
+ strictMode: true,
183
+ scope: () => ({
184
+ on,
185
+ FormControl,
186
+ SegmentGroup,
187
+ CloseButton
188
+ })
189
+ }), this);
190
+ }
191
+ }
192
+
193
+ export { DateInput, DateInput as default };
194
+ //# sourceMappingURL=date-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-input.js","sources":["../../../../src/components/forms/date-input/date-input.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { cached, tracked } from '@glimmer/tracking';\nimport { on } from '@ember/modifier';\nimport { modifier } from 'ember-modifier';\nimport { useStyles } from '@frontile/theme';\nimport { FormControl } from '../form-control';\nimport { CloseButton } from '../../buttons/close-button';\nimport { SegmentGroup } from './segment-group';\nimport {\n buildParts,\n toDate,\n fromDate,\n isSegment,\n carryOver,\n resolveSegmentFormat,\n hasDateChanged\n} from './segments';\nimport { parseDate, toWire } from '../date-picker/value';\nimport { ref } from '../../../utils/ref';\nimport { triggerFormInputEvent } from '../../../utils/forms-utils-index';\nimport type { Part, DateInputArgs, DateInputClasses } from './types';\n\ninterface DateInputSignature {\n Args: DateInputArgs;\n Element: HTMLDivElement;\n}\n\n/**\n * A date typed into segments rather than picked from a grid. `DatePicker`\n * renders the same segments and adds a calendar.\n */\nclass DateInput extends Component<DateInputSignature> {\n containerRef = ref<HTMLElement>();\n\n /**\n * The segments are the state, not the value: mid-entry they hold digits that\n * compose to no date at all, which no `Date` can represent.\n */\n @tracked private trackedParts: Part[] = [];\n\n /**\n * An untracked mirror of {@link parts}. The sync modifiers below need to\n * read the current segments in order to rebuild them, and reading the\n * tracked field inside a modifier would put it in that modifier's own\n * tracking frame -- which the same modifier then writes to, re-running\n * itself forever.\n */\n #currentParts: Part[] = [];\n\n constructor(owner: unknown, args: DateInputArgs) {\n super(owner as never, args);\n\n const seed = args.defaultValue;\n this.setParts(\n fromDate(\n buildParts(this.locale, this.formatOptions),\n seed === undefined ? null : parseDate(seed)\n )\n );\n }\n\n get parts(): Part[] {\n return this.trackedParts;\n }\n\n private setParts(parts: Part[]): void {\n this.#currentParts = parts;\n this.trackedParts = parts;\n }\n\n get locale(): string {\n return this.args.locale ?? navigator.language;\n }\n\n get formatOptions(): Intl.DateTimeFormatOptions | undefined {\n // A textual month has no numeric segment to type into, so it falls back\n // to a numeric one. `dateStyle: 'medium'` is the common way to hit this --\n // it is DatePicker's button-trigger default. Only the month is replaced:\n // the rest of the format is the consumer's and stands.\n return resolveSegmentFormat(this.args.formatOptions, {\n message:\n '<DateInput> needs numeric segments; ' +\n 'a textual @formatOptions month falls back to a numeric one.',\n id: 'frontile.date-input.textual-format'\n });\n }\n\n /**\n * The composed value, or null while any segment is empty.\n *\n * Cached because `wireValue`, `isOutOfRange` and the template all read it\n * independently, and each `toDate` walks the parts three times over.\n */\n @cached\n get value(): Date | null {\n return toDate(this.parts);\n }\n\n get wireValue(): string {\n return toWire(this.value);\n }\n\n get isEmpty(): boolean {\n return this.parts.every((p) => !isSegment(p) || p.value === null);\n }\n\n get placeholderValue(): Date {\n return this.args.placeholderValue ?? new Date();\n }\n\n /**\n * Whether the composed value is outside the allowed range. Never blocks a\n * keystroke -- typing toward 2020 passes through 2, 20 and 202 on the way,\n * and a field that refused those could not be typed into at all.\n */\n get isOutOfRange(): boolean {\n const value = this.value;\n if (!value) return false;\n\n if (this.args.minValue && value < this.args.minValue) return true;\n if (this.args.maxValue && value > this.args.maxValue) return true;\n return this.args.isDateUnavailable?.(value) ?? false;\n }\n\n get isInvalid(): boolean {\n return Boolean(this.args.isInvalid) || this.isOutOfRange;\n }\n\n /**\n * Pushes `@value` into the segments when the argument changes. `undefined`\n * is ignored, so a field bound by `Field` before the form holds anything for\n * it keeps what the user typed -- the rule `DatePicker` documents.\n */\n syncValue = modifier(\n (_: HTMLElement, [raw]: [Date | string | null | undefined]) => {\n if (raw === undefined) return;\n\n const parsed = parseDate(raw);\n\n // Ignore the echo of our own `@onChange`. A controlled consumer writes\n // back the value this field just reported, and rewriting the segments\n // from it would destroy a partial entry: backspacing one digit of the\n // year un-commits it, so the field composes `null`, reports `null`, and\n // is handed `null` straight back -- which `fromDate` would spend on\n // clearing every other segment too. One keystroke would empty the field.\n if (!hasDateChanged(toDate(this.#currentParts), parsed)) return;\n\n this.setParts(fromDate(this.#currentParts, parsed));\n }\n );\n\n /**\n * Rebuilds the segment order when the locale or format changes, carrying\n * each segment's own state across so switching en-US to en-GB reorders the\n * field without emptying it -- half-typed digits included, which is why\n * this goes segment by segment rather than through the composed value.\n */\n syncLocale = modifier(\n (\n _: HTMLElement,\n [locale, format]: [string, Intl.DateTimeFormatOptions | undefined]\n ) => {\n this.setParts(carryOver(buildParts(locale, format), this.#currentParts));\n }\n );\n\n handlePartsChange = (parts: Part[]): void => {\n const before = toDate(this.#currentParts);\n this.setParts(parts);\n const after = toDate(parts);\n\n // Only value transitions are reported. The four keystrokes that fill a\n // month and a day compose no date at all, and report nothing.\n if (hasDateChanged(before, after)) {\n this.args.onChange?.(after);\n triggerFormInputEvent(this.containerRef.current);\n }\n };\n\n /**\n * `@onBlur` means \"the user left the field\", not \"the user left a segment\",\n * so a move between segments is filtered out by asking whether focus landed\n * inside the container. `DatePicker` needs `ControlBlurTracker` for this\n * because its focus can legitimately be in a popover outside its own DOM;\n * this field has no popover, so containment is the whole question.\n */\n handleFocusOut = (event: FocusEvent): void => {\n const container = this.containerRef.current;\n const next = event.relatedTarget;\n\n if (container && next instanceof Node && container.contains(next)) return;\n\n this.args.onBlur?.();\n };\n\n /**\n * A disabled or read-only field never offers it: it carries no disabled\n * state of its own and would be a live button clearing a field the user may\n * not change.\n */\n get isClearable(): boolean {\n return (\n Boolean(this.args.isClearable) &&\n !this.isEmpty &&\n !this.args.isDisabled &&\n !this.args.isReadOnly\n );\n }\n\n /**\n * Clearing removes the clear button from the DOM (`isClearable` flips\n * false the instant the value is gone), so focus must be handed somewhere\n * explicitly or it falls to `<body>` and a keyboard user loses their place.\n */\n clear = (): void => {\n this.handlePartsChange(fromDate(this.#currentParts, null));\n this.containerRef.current\n ?.querySelector<HTMLElement>('[data-part=\"segment\"]')\n ?.focus();\n };\n\n @cached\n get classes(): DateInputClasses {\n const { dateInput } = useStyles();\n return dateInput({ size: this.args.inputSize });\n }\n\n <template>\n <div\n {{this.syncLocale this.locale this.formatOptions}}\n {{this.syncValue @value}}\n {{this.containerRef.setup}}\n {{on \"focusout\" this.handleFocusOut}}\n class={{this.classes.base class=@classes.base}}\n data-component=\"date-input\"\n data-part=\"base\"\n ...attributes\n >\n {{#if @name}}\n <input type=\"hidden\" name={{@name}} value={{this.wireValue}} />\n {{/if}}\n\n <FormControl\n @id={{@id}}\n @size={{@inputSize}}\n @label={{@label}}\n @isRequired={{@isRequired}}\n @description={{@description}}\n @errors={{@errors}}\n @isInvalid={{this.isInvalid}}\n @isDisabled={{@isDisabled}}\n as |c|\n >\n <div\n class={{this.classes.innerContainer class=@classes.innerContainer}}\n data-part=\"inner-container\"\n {{! The field shell lives here, not on the segment row, so the clear\n button sits inside the border. `role=\"group\"` supports neither\n aria-invalid nor aria-disabled, so the shell styles off these. }}\n data-invalid={{if c.isInvalid \"true\" \"false\"}}\n data-disabled={{if @isDisabled \"true\" \"false\"}}\n >\n <SegmentGroup\n @parts={{this.parts}}\n @onPartsChange={{this.handlePartsChange}}\n @locale={{this.locale}}\n @placeholderValue={{this.placeholderValue}}\n @isDisabled={{@isDisabled}}\n @isReadOnly={{@isReadOnly}}\n @isInvalid={{c.isInvalid}}\n @id={{c.id}}\n @label={{@label}}\n @describedBy={{c.describedBy @description c.isInvalid}}\n @segmentLabels={{@segmentLabels}}\n @classes={{this.classes}}\n @userClasses={{@classes}}\n />\n {{#if this.isClearable}}\n <div\n data-part=\"end-content\"\n class={{this.classes.endContent class=@classes.endContent}}\n >\n <CloseButton\n @title=\"Clear\"\n @variant=\"soft\"\n @size=\"xs\"\n @class={{this.classes.clearButton class=@classes.clearButton}}\n data-part=\"clear-button\"\n @onPress={{this.clear}}\n />\n </div>\n {{/if}}\n </div>\n </FormControl>\n </div>\n </template>\n}\n\nexport { DateInput, type DateInputSignature };\nexport default DateInput;\n"],"names":["DateInput","Component","containerRef","ref","g","prototype","tracked","i","constructor","owner","args","seed","defaultValue","setParts","fromDate","buildParts","locale","formatOptions","undefined","parseDate","parts","trackedParts","navigator","language","resolveSegmentFormat","message","id","value","toDate","n","cached","wireValue","toWire","isEmpty","every","p","isSegment","placeholderValue","Date","isOutOfRange","minValue","maxValue","isDateUnavailable","isInvalid","Boolean","syncValue","modifier","_","raw","parsed","hasDateChanged","syncLocale","format","carryOver","handlePartsChange","before","after","onChange","triggerFormInputEvent","current","handleFocusOut","event","container","next","relatedTarget","Node","contains","onBlur","isClearable","isDisabled","isReadOnly","clear","querySelector","focus","classes","dateInput","useStyles","size","inputSize","setComponentTemplate","precompileTemplate","strictMode","scope","on","FormControl","SegmentGroup","CloseButton"],"mappings":";;;;;;;;;;;;;;;;AA2BA;;;;AAIA,MAAMA,kBAAkBC,SAAA,CAAU;EAChCC,YAAA,GAAeC,KAAI;AAEnB;;;AAGC;AAHD,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,cAAA,EAAA,CAICC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAuC,EAAE;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,aAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,cAAA,CAAA,EAAA,MAAA;AAE1C;;;;;;AAMC;EACD,aAAa,GAAW,EAAE;AAE1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AC3D,IAAI,CAAC4D,UAAU;AAEzB,EAAA;AAEA;;;;;EAKAC,KAAA,GAAQA,MAAQ;AACd,IAAA,IAAI,CAACjB,iBAAiB,CAACxC,QAAA,CAAS,IAAI,CAAC,aAAa,EAAE,IAAA,CAAA,CAAA;AACpD,IAAA,IAAI,CAACZ,YAAY,CAACyD,OAAO,EACrBa,cAA2B,uBAAA,CAAA,EAC3BC,KAAA,EAAA;EACN,CAAA;EAEA,IACIC,UAA4B;IAC9B,MAAM;AAAEC,MAAAA;KAAW,GAAGC,SAAA,EAAA;AACtB,IAAA,OAAOD,SAAA,CAAU;AAAEE,MAAAA,IAAA,EAAM,IAAI,CAACnE,IAAI,CAACoE;AAAU,KAAA,CAAA;AAC/C,EAAA;AAAA,EAAA;IAAAjD,gBAAA,CAAA,IAAA,CAAAxB,SAAA,EAAA,SAAA,EAAA,CAJCyB,MAAA,CAAA,CAAA;AAAA;AAMD,EAAA;IAAAiD,oBAAA,CAAAC,kBAAA,CAAA,gxDAAA,EAoEA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,EAAA;QAAAC,WAAA;QAAAC,YAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
@@ -0,0 +1,271 @@
1
+ import Component from '@glimmer/component';
2
+ import { cached } from '@glimmer/tracking';
3
+ import { fn } from '@ember/helper';
4
+ import { on } from '@ember/modifier';
5
+ import { isSegment, displaySegment, step, deleteDigit, clearSegment, applyDigit, commitSegment } from './segments.js';
6
+ import { parsePasted, splitRange, formatForClipboard } from './clipboard.js';
7
+ import { precompileTemplate } from '@ember/template-compilation';
8
+ import { setComponentTemplate } from '@ember/component';
9
+ import { a as decorateMethodV2 } from '../../../runtime--fcdnjmJ-BOdRhmsS.js';
10
+
11
+ const DEFAULT_LABELS = {
12
+ year: 'year',
13
+ month: 'month',
14
+ day: 'day'
15
+ };
16
+ /** How much PageUp/PageDown moves, per segment. */
17
+ const PAGE_STEP = {
18
+ day: 7,
19
+ month: 3,
20
+ year: 10
21
+ };
22
+ /**
23
+ * Everything one rendered part needs, resolved to primitives.
24
+ *
25
+ * The template cannot narrow the `Part` union -- `eq` is unavailable and Glint
26
+ * does not carry a type predicate through `{{#if}}` -- so the narrowing happens
27
+ * here, in TypeScript, and the template only ever reads optional primitives.
28
+ * That keeps `part.type` off a `LiteralPart` without a cast anywhere.
29
+ */
30
+
31
+ /**
32
+ * One row of date segments. Private: `DateInput` and `DatePicker` both render
33
+ * it, and neither wants the other's `FormControl` wrapper.
34
+ */
35
+ class SegmentGroup extends Component {
36
+ get isEditable() {
37
+ return !this.args.isDisabled && !this.args.isReadOnly;
38
+ }
39
+ labelFor = type => this.args.segmentLabels?.[type] ?? DEFAULT_LABELS[type];
40
+ /**
41
+ * Built once per locale rather than inside {@link valueTextFor}: `cells`
42
+ * recomputes on every keystroke, and an `Intl` constructor is expensive
43
+ * enough that building one per keypress is the costliest thing this
44
+ * component would otherwise do.
45
+ */
46
+ get monthNames() {
47
+ return new Intl.DateTimeFormat(this.args.locale, {
48
+ month: 'long'
49
+ });
50
+ }
51
+ /**
52
+ * What a screen reader reads instead of the raw number. A month is read by
53
+ * name -- "January", not "1" -- which is the whole point of `aria-valuetext`.
54
+ */
55
+ static {
56
+ decorateMethodV2(this.prototype, "monthNames", [cached]);
57
+ }
58
+ valueTextFor = segment => {
59
+ if (segment.value === null) return undefined;
60
+ if (segment.type !== 'month') return String(segment.value);
61
+ // Any year and day will do; only the month is read back out.
62
+ return this.monthNames.format(new Date(2026, segment.value - 1, 1));
63
+ };
64
+ get cells() {
65
+ return this.args.parts.map((part, index) => {
66
+ if (!isSegment(part)) {
67
+ return {
68
+ index,
69
+ isSegment: false,
70
+ isEmpty: false,
71
+ text: part.text
72
+ };
73
+ }
74
+ return {
75
+ index,
76
+ isSegment: true,
77
+ text: displaySegment(part),
78
+ type: part.type,
79
+ isEmpty: part.value === null,
80
+ label: this.labelFor(part.type),
81
+ // `undefined` rather than `null`: an empty segment has no current
82
+ // value, and `aria-valuenow="null"` would be a value of sorts.
83
+ valueNow: part.value ?? undefined,
84
+ valueMin: part.min,
85
+ valueMax: part.max,
86
+ valueText: this.valueTextFor(part)
87
+ };
88
+ });
89
+ }
90
+ /** The segment elements, in document order -- the focus order too. */
91
+ static {
92
+ decorateMethodV2(this.prototype, "cells", [cached]);
93
+ }
94
+ segmentElements(from) {
95
+ const group = from.closest('[data-part="group"]');
96
+ return group ? Array.from(group.querySelectorAll('[data-part="segment"]')) : [];
97
+ }
98
+ /**
99
+ * Left and right are *visual* directions, so in an RTL locale they run
100
+ * against document order: pressing the left arrow in `yyyy/mm/dd` laid out
101
+ * right-to-left should move to the segment drawn to the left, which is the
102
+ * later one in the DOM.
103
+ */
104
+ focusSibling(from, delta) {
105
+ const all = this.segmentElements(from);
106
+ const step = this.isRtl(from) ? -delta : delta;
107
+ const next = all[all.indexOf(from) + step];
108
+ next?.focus();
109
+ }
110
+ isRtl(from) {
111
+ const group = from.closest('[data-part="group"]') ?? from;
112
+ return getComputedStyle(group).direction === 'rtl';
113
+ }
114
+ focusEdge(from, edge) {
115
+ const all = this.segmentElements(from);
116
+ (edge === 'first' ? all[0] : all[all.length - 1])?.focus();
117
+ }
118
+ /** Replaces one segment by index and reports the new list. */
119
+ replace(index, segment) {
120
+ const next = this.args.parts.map((part, i) => i === index ? segment : part);
121
+ this.args.onPartsChange(next);
122
+ }
123
+ handleKeyDown = (index, event) => {
124
+ const part = this.args.parts[index];
125
+ if (!part || !isSegment(part)) return;
126
+ const element = event.target;
127
+ const {
128
+ key
129
+ } = event;
130
+ // Navigation works even when the field is read-only; editing does not.
131
+ if (key === 'ArrowRight') {
132
+ event.preventDefault();
133
+ this.focusSibling(element, 1);
134
+ return;
135
+ }
136
+ if (key === 'ArrowLeft') {
137
+ event.preventDefault();
138
+ this.focusSibling(element, -1);
139
+ return;
140
+ }
141
+ if (key === 'Home') {
142
+ event.preventDefault();
143
+ this.focusEdge(element, 'first');
144
+ return;
145
+ }
146
+ if (key === 'End') {
147
+ event.preventDefault();
148
+ this.focusEdge(element, 'last');
149
+ return;
150
+ }
151
+ if (!this.isEditable) return;
152
+ if (key === 'ArrowUp' || key === 'ArrowDown') {
153
+ event.preventDefault();
154
+ const delta = key === 'ArrowUp' ? 1 : -1;
155
+ this.replace(index, step(part, delta, this.args.placeholderValue));
156
+ return;
157
+ }
158
+ if (key === 'PageUp' || key === 'PageDown') {
159
+ event.preventDefault();
160
+ const magnitude = PAGE_STEP[part.type];
161
+ const delta = key === 'PageUp' ? magnitude : -magnitude;
162
+ this.replace(index, step(part, delta, this.args.placeholderValue));
163
+ return;
164
+ }
165
+ if (key === 'Backspace') {
166
+ event.preventDefault();
167
+ this.replace(index, deleteDigit(part));
168
+ return;
169
+ }
170
+ if (key === 'Delete') {
171
+ event.preventDefault();
172
+ this.replace(index, clearSegment(part));
173
+ return;
174
+ }
175
+ if (/^\d$/.test(key)) {
176
+ event.preventDefault();
177
+ const {
178
+ segment,
179
+ isFull
180
+ } = applyDigit(part, key);
181
+ this.replace(index, segment);
182
+ // Advancing before the DOM has caught up is safe: the segment elements
183
+ // are keyed by index and are updated, never re-created.
184
+ if (isFull) this.focusSibling(element, 1);
185
+ return;
186
+ }
187
+ // Everything else -- letters, symbols -- would otherwise be inserted into
188
+ // the contenteditable span as literal text.
189
+ if (key.length === 1 && !event.metaKey && !event.ctrlKey) {
190
+ event.preventDefault();
191
+ }
192
+ };
193
+ /**
194
+ * Leaving a segment finishes it: the digits in it stop being something the
195
+ * user is still typing and become their answer, which is what turns a typed
196
+ * `26` into 2026. Tab, arrow-key navigation and a click elsewhere all arrive
197
+ * here, because moving focus is the one thing they have in common.
198
+ */
199
+ handleFocusOut = index => {
200
+ if (!this.isEditable) return;
201
+ const part = this.args.parts[index];
202
+ if (!part || !isSegment(part) || part.isCommitted) return;
203
+ const committed = commitSegment(part);
204
+ // An empty segment commits to itself; reporting it would be churn.
205
+ if (committed !== part) this.replace(index, committed);
206
+ };
207
+ /**
208
+ * `contenteditable`'s hazard: anything not handled above arrives here and
209
+ * would be written into the span's DOM, desynchronising the display from the
210
+ * model. Every input type is refused; the model is the only writer.
211
+ */
212
+ handleBeforeInput = event => {
213
+ event.preventDefault();
214
+ };
215
+ /**
216
+ * Always `preventDefault`: the browser would otherwise write the pasted text
217
+ * into the contenteditable span, and the model would no longer describe what
218
+ * is on screen. Unparseable text is dropped silently -- a date field that
219
+ * guessed would be worse than one that declined.
220
+ */
221
+ handlePaste = event => {
222
+ event.preventDefault();
223
+ if (!this.isEditable) return;
224
+ const text = event.clipboardData?.getData('text/plain') ?? '';
225
+ const parsed = parsePasted(text, this.args.parts);
226
+ if (parsed) {
227
+ this.args.onPartsChange(parsed);
228
+ return;
229
+ }
230
+ this.tryRangePaste(text);
231
+ };
232
+ /**
233
+ * A second reading of text a single date could not be made of.
234
+ *
235
+ * Both halves are parsed against *this* group's parts, which is sound
236
+ * because the two groups of a range are built from the same locale and
237
+ * format and so have identical shape, and because a half only counts when
238
+ * it parses in full -- nothing of this group's own state survives into the
239
+ * list handed to the other one.
240
+ */
241
+ tryRangePaste(text) {
242
+ const onRangePaste = this.args.onRangePaste;
243
+ if (!onRangePaste) return;
244
+ const halves = splitRange(text);
245
+ if (!halves) return;
246
+ const start = parsePasted(halves[0], this.args.parts);
247
+ const end = parsePasted(halves[1], this.args.parts);
248
+ if (start && end) onRangePaste(start, end);
249
+ }
250
+ handleCopy = event => {
251
+ event.preventDefault();
252
+ event.clipboardData?.setData('text/plain', formatForClipboard(this.args.parts));
253
+ };
254
+ handleCut = event => {
255
+ this.handleCopy(event);
256
+ if (!this.isEditable) return;
257
+ this.args.onPartsChange(this.args.parts.map(p => isSegment(p) ? clearSegment(p) : p));
258
+ };
259
+ static {
260
+ setComponentTemplate(precompileTemplate("<div role=\"group\" data-part=\"group\" id={{@id}} aria-label={{@label}} aria-labelledby={{@labelledBy}} aria-describedby={{@describedBy}} aria-disabled={{if @isDisabled \"true\"}} {{!-- `role=\"group\"` supports neither aria-readonly nor aria-invalid --\n neither is global in ARIA 1.2, and ember-template-lint's\n no-unsupported-role-attributes is right to reject them here (its\n autofixer deletes them silently, which is how they went missing\n once already). Both live on the spinbuttons below instead, where\n the role does support them and where assistive technology actually\n lands. These data attributes carry the same state for styling and\n for tests. --}} data-readonly={{if @isReadOnly \"true\" \"false\"}} data-invalid={{if @isInvalid \"true\" \"false\"}} class={{@classes.group class=@userClasses.group}} {{on \"paste\" this.handlePaste}} {{on \"copy\" this.handleCopy}} {{on \"cut\" this.handleCut}} ...attributes>\n {{#each this.cells key=\"index\" as |cell|}}\n {{#if cell.isSegment}}\n <span role=\"spinbutton\" tabindex={{unless @isDisabled \"0\"}} contenteditable={{if this.isEditable \"true\" \"false\"}} inputmode=\"numeric\" spellcheck=\"false\" autocorrect=\"off\" data-part=\"segment\" data-type={{cell.type}} data-placeholder={{if cell.isEmpty \"true\" \"false\"}} data-disabled={{if @isDisabled \"true\" \"false\"}} aria-readonly={{if @isReadOnly \"true\"}} aria-invalid={{if @isInvalid \"true\"}} aria-label={{cell.label}} aria-valuenow={{cell.valueNow}} aria-valuemin={{cell.valueMin}} aria-valuemax={{cell.valueMax}} aria-valuetext={{cell.valueText}} class={{@classes.segment class=@userClasses.segment}} {{on \"keydown\" (fn this.handleKeyDown cell.index)}} {{on \"focusout\" (fn this.handleFocusOut cell.index)}} {{on \"beforeinput\" this.handleBeforeInput}}>{{cell.text}}</span>\n {{else}}\n <span data-part=\"literal\" aria-hidden=\"true\" class={{@classes.literal class=@userClasses.literal}}>{{cell.text}}</span>\n {{/if}}\n {{/each}}\n</div>", {
261
+ strictMode: true,
262
+ scope: () => ({
263
+ on,
264
+ fn
265
+ })
266
+ }), this);
267
+ }
268
+ }
269
+
270
+ export { SegmentGroup, SegmentGroup as default };
271
+ //# sourceMappingURL=segment-group.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segment-group.js","sources":["../../../../src/components/forms/date-input/segment-group.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { cached } from '@glimmer/tracking';\nimport { fn } from '@ember/helper';\nimport { on } from '@ember/modifier';\nimport {\n isSegment,\n applyDigit,\n commitSegment,\n step,\n clearSegment,\n deleteDigit,\n displaySegment\n} from './segments';\nimport { parsePasted, formatForClipboard, splitRange } from './clipboard';\nimport type {\n Part,\n Segment,\n SegmentType,\n SegmentGroupClasses,\n SegmentGroupUserClasses\n} from './types';\n\ninterface SegmentGroupSignature {\n Args: {\n parts: Part[];\n /** Hands the whole list back; the group holds no state of its own. */\n onPartsChange: (parts: Part[]) => void;\n /**\n * Offered text that reads as two dates rather than one. Only `DatePicker`\n * in `@mode=\"range\"` supplies it, and only to its *start* group: pasting\n * a range into the end of a field and having it rewrite the start would\n * be surprising. Without it, such text is simply declined.\n */\n onRangePaste?: (start: Part[], end: Part[]) => void;\n locale: string;\n placeholderValue: Date;\n isDisabled?: boolean;\n isReadOnly?: boolean;\n isInvalid?: boolean;\n /** Rendered as the group's own id, so a `<label for>` can target it. */\n id?: string;\n /**\n * The field's name. A `role=\"group\"` is not a labelable element, so a\n * sibling `<label for>` does not name it on its own -- this does.\n */\n label?: string;\n labelledBy?: string;\n describedBy?: string;\n segmentLabels?: Partial<Record<SegmentType, string>>;\n /**\n * Only the three slots this group renders, so that `DateInput`'s\n * `dateInput` recipe and `DatePicker`'s `datePicker` recipe both satisfy\n * it. See {@link SegmentGroupClasses}.\n */\n classes: SegmentGroupClasses;\n userClasses?: SegmentGroupUserClasses;\n };\n Element: HTMLDivElement;\n}\n\nconst DEFAULT_LABELS: Record<SegmentType, string> = {\n year: 'year',\n month: 'month',\n day: 'day'\n};\n\n/** How much PageUp/PageDown moves, per segment. */\nconst PAGE_STEP: Record<SegmentType, number> = { day: 7, month: 3, year: 10 };\n\n/**\n * Everything one rendered part needs, resolved to primitives.\n *\n * The template cannot narrow the `Part` union -- `eq` is unavailable and Glint\n * does not carry a type predicate through `{{#if}}` -- so the narrowing happens\n * here, in TypeScript, and the template only ever reads optional primitives.\n * That keeps `part.type` off a `LiteralPart` without a cast anywhere.\n */\ninterface Cell {\n index: number;\n isSegment: boolean;\n /** The segment's display text, or the literal's text. */\n text: string;\n type?: SegmentType;\n isEmpty: boolean;\n label?: string;\n valueNow?: number;\n valueMin?: number;\n valueMax?: number;\n valueText?: string;\n}\n\n/**\n * One row of date segments. Private: `DateInput` and `DatePicker` both render\n * it, and neither wants the other's `FormControl` wrapper.\n */\nclass SegmentGroup extends Component<SegmentGroupSignature> {\n get isEditable(): boolean {\n return !this.args.isDisabled && !this.args.isReadOnly;\n }\n\n labelFor = (type: SegmentType): string =>\n this.args.segmentLabels?.[type] ?? DEFAULT_LABELS[type];\n\n /**\n * Built once per locale rather than inside {@link valueTextFor}: `cells`\n * recomputes on every keystroke, and an `Intl` constructor is expensive\n * enough that building one per keypress is the costliest thing this\n * component would otherwise do.\n */\n @cached\n get monthNames(): Intl.DateTimeFormat {\n return new Intl.DateTimeFormat(this.args.locale, { month: 'long' });\n }\n\n /**\n * What a screen reader reads instead of the raw number. A month is read by\n * name -- \"January\", not \"1\" -- which is the whole point of `aria-valuetext`.\n */\n valueTextFor = (segment: Segment): string | undefined => {\n if (segment.value === null) return undefined;\n if (segment.type !== 'month') return String(segment.value);\n\n // Any year and day will do; only the month is read back out.\n return this.monthNames.format(new Date(2026, segment.value - 1, 1));\n };\n\n @cached\n get cells(): Cell[] {\n return this.args.parts.map((part, index) => {\n if (!isSegment(part)) {\n return { index, isSegment: false, isEmpty: false, text: part.text };\n }\n\n return {\n index,\n isSegment: true,\n text: displaySegment(part),\n type: part.type,\n isEmpty: part.value === null,\n label: this.labelFor(part.type),\n // `undefined` rather than `null`: an empty segment has no current\n // value, and `aria-valuenow=\"null\"` would be a value of sorts.\n valueNow: part.value ?? undefined,\n valueMin: part.min,\n valueMax: part.max,\n valueText: this.valueTextFor(part)\n };\n });\n }\n\n /** The segment elements, in document order -- the focus order too. */\n private segmentElements(from: HTMLElement): HTMLElement[] {\n const group = from.closest('[data-part=\"group\"]');\n return group\n ? Array.from(group.querySelectorAll<HTMLElement>('[data-part=\"segment\"]'))\n : [];\n }\n\n /**\n * Left and right are *visual* directions, so in an RTL locale they run\n * against document order: pressing the left arrow in `yyyy/mm/dd` laid out\n * right-to-left should move to the segment drawn to the left, which is the\n * later one in the DOM.\n */\n private focusSibling(from: HTMLElement, delta: number): void {\n const all = this.segmentElements(from);\n const step = this.isRtl(from) ? -delta : delta;\n const next = all[all.indexOf(from) + step];\n next?.focus();\n }\n\n private isRtl(from: HTMLElement): boolean {\n const group = from.closest<HTMLElement>('[data-part=\"group\"]') ?? from;\n return getComputedStyle(group).direction === 'rtl';\n }\n\n private focusEdge(from: HTMLElement, edge: 'first' | 'last'): void {\n const all = this.segmentElements(from);\n (edge === 'first' ? all[0] : all[all.length - 1])?.focus();\n }\n\n /** Replaces one segment by index and reports the new list. */\n private replace(index: number, segment: Segment): void {\n const next = this.args.parts.map((part, i) =>\n i === index ? segment : part\n );\n this.args.onPartsChange(next);\n }\n\n handleKeyDown = (index: number, event: KeyboardEvent): void => {\n const part = this.args.parts[index];\n if (!part || !isSegment(part)) return;\n\n const element = event.target as HTMLElement;\n const { key } = event;\n\n // Navigation works even when the field is read-only; editing does not.\n if (key === 'ArrowRight') {\n event.preventDefault();\n this.focusSibling(element, 1);\n return;\n }\n if (key === 'ArrowLeft') {\n event.preventDefault();\n this.focusSibling(element, -1);\n return;\n }\n if (key === 'Home') {\n event.preventDefault();\n this.focusEdge(element, 'first');\n return;\n }\n if (key === 'End') {\n event.preventDefault();\n this.focusEdge(element, 'last');\n return;\n }\n\n if (!this.isEditable) return;\n\n if (key === 'ArrowUp' || key === 'ArrowDown') {\n event.preventDefault();\n const delta = key === 'ArrowUp' ? 1 : -1;\n this.replace(index, step(part, delta, this.args.placeholderValue));\n return;\n }\n\n if (key === 'PageUp' || key === 'PageDown') {\n event.preventDefault();\n const magnitude = PAGE_STEP[part.type];\n const delta = key === 'PageUp' ? magnitude : -magnitude;\n this.replace(index, step(part, delta, this.args.placeholderValue));\n return;\n }\n\n if (key === 'Backspace') {\n event.preventDefault();\n this.replace(index, deleteDigit(part));\n return;\n }\n\n if (key === 'Delete') {\n event.preventDefault();\n this.replace(index, clearSegment(part));\n return;\n }\n\n if (/^\\d$/.test(key)) {\n event.preventDefault();\n const { segment, isFull } = applyDigit(part, key);\n this.replace(index, segment);\n // Advancing before the DOM has caught up is safe: the segment elements\n // are keyed by index and are updated, never re-created.\n if (isFull) this.focusSibling(element, 1);\n return;\n }\n\n // Everything else -- letters, symbols -- would otherwise be inserted into\n // the contenteditable span as literal text.\n if (key.length === 1 && !event.metaKey && !event.ctrlKey) {\n event.preventDefault();\n }\n };\n\n /**\n * Leaving a segment finishes it: the digits in it stop being something the\n * user is still typing and become their answer, which is what turns a typed\n * `26` into 2026. Tab, arrow-key navigation and a click elsewhere all arrive\n * here, because moving focus is the one thing they have in common.\n */\n handleFocusOut = (index: number): void => {\n if (!this.isEditable) return;\n\n const part = this.args.parts[index];\n if (!part || !isSegment(part) || part.isCommitted) return;\n\n const committed = commitSegment(part);\n // An empty segment commits to itself; reporting it would be churn.\n if (committed !== part) this.replace(index, committed);\n };\n\n /**\n * `contenteditable`'s hazard: anything not handled above arrives here and\n * would be written into the span's DOM, desynchronising the display from the\n * model. Every input type is refused; the model is the only writer.\n */\n handleBeforeInput = (event: Event): void => {\n event.preventDefault();\n };\n\n /**\n * Always `preventDefault`: the browser would otherwise write the pasted text\n * into the contenteditable span, and the model would no longer describe what\n * is on screen. Unparseable text is dropped silently -- a date field that\n * guessed would be worse than one that declined.\n */\n handlePaste = (event: ClipboardEvent): void => {\n event.preventDefault();\n if (!this.isEditable) return;\n\n const text = event.clipboardData?.getData('text/plain') ?? '';\n const parsed = parsePasted(text, this.args.parts);\n if (parsed) {\n this.args.onPartsChange(parsed);\n return;\n }\n\n this.tryRangePaste(text);\n };\n\n /**\n * A second reading of text a single date could not be made of.\n *\n * Both halves are parsed against *this* group's parts, which is sound\n * because the two groups of a range are built from the same locale and\n * format and so have identical shape, and because a half only counts when\n * it parses in full -- nothing of this group's own state survives into the\n * list handed to the other one.\n */\n private tryRangePaste(text: string): void {\n const onRangePaste = this.args.onRangePaste;\n if (!onRangePaste) return;\n\n const halves = splitRange(text);\n if (!halves) return;\n\n const start = parsePasted(halves[0], this.args.parts);\n const end = parsePasted(halves[1], this.args.parts);\n if (start && end) onRangePaste(start, end);\n }\n\n handleCopy = (event: ClipboardEvent): void => {\n event.preventDefault();\n event.clipboardData?.setData(\n 'text/plain',\n formatForClipboard(this.args.parts)\n );\n };\n\n handleCut = (event: ClipboardEvent): void => {\n this.handleCopy(event);\n if (!this.isEditable) return;\n\n this.args.onPartsChange(\n this.args.parts.map((p) => (isSegment(p) ? clearSegment(p) : p))\n );\n };\n\n <template>\n <div\n role=\"group\"\n data-part=\"group\"\n id={{@id}}\n aria-label={{@label}}\n aria-labelledby={{@labelledBy}}\n aria-describedby={{@describedBy}}\n aria-disabled={{if @isDisabled \"true\"}}\n {{! `role=\"group\"` supports neither aria-readonly nor aria-invalid --\n neither is global in ARIA 1.2, and ember-template-lint's\n no-unsupported-role-attributes is right to reject them here (its\n autofixer deletes them silently, which is how they went missing\n once already). Both live on the spinbuttons below instead, where\n the role does support them and where assistive technology actually\n lands. These data attributes carry the same state for styling and\n for tests. }}\n data-readonly={{if @isReadOnly \"true\" \"false\"}}\n data-invalid={{if @isInvalid \"true\" \"false\"}}\n class={{@classes.group class=@userClasses.group}}\n {{on \"paste\" this.handlePaste}}\n {{on \"copy\" this.handleCopy}}\n {{on \"cut\" this.handleCut}}\n ...attributes\n >\n {{#each this.cells key=\"index\" as |cell|}}\n {{#if cell.isSegment}}\n <span\n role=\"spinbutton\"\n tabindex={{unless @isDisabled \"0\"}}\n contenteditable={{if this.isEditable \"true\" \"false\"}}\n inputmode=\"numeric\"\n spellcheck=\"false\"\n autocorrect=\"off\"\n data-part=\"segment\"\n data-type={{cell.type}}\n data-placeholder={{if cell.isEmpty \"true\" \"false\"}}\n data-disabled={{if @isDisabled \"true\" \"false\"}}\n aria-readonly={{if @isReadOnly \"true\"}}\n aria-invalid={{if @isInvalid \"true\"}}\n aria-label={{cell.label}}\n aria-valuenow={{cell.valueNow}}\n aria-valuemin={{cell.valueMin}}\n aria-valuemax={{cell.valueMax}}\n aria-valuetext={{cell.valueText}}\n class={{@classes.segment class=@userClasses.segment}}\n {{on \"keydown\" (fn this.handleKeyDown cell.index)}}\n {{on \"focusout\" (fn this.handleFocusOut cell.index)}}\n {{on \"beforeinput\" this.handleBeforeInput}}\n >{{cell.text}}</span>\n {{else}}\n <span\n data-part=\"literal\"\n aria-hidden=\"true\"\n class={{@classes.literal class=@userClasses.literal}}\n >{{cell.text}}</span>\n {{/if}}\n {{/each}}\n </div>\n </template>\n}\n\nexport { SegmentGroup, type SegmentGroupSignature };\nexport default SegmentGroup;\n"],"names":["DEFAULT_LABELS","year","month","day","PAGE_STEP","SegmentGroup","Component","isEditable","args","isDisabled","isReadOnly","labelFor","type","segmentLabels","monthNames","Intl","DateTimeFormat","locale","n","prototype","cached","valueTextFor","segment","value","undefined","String","format","Date","cells","parts","map","part","index","isSegment","isEmpty","text","displaySegment","label","valueNow","valueMin","min","valueMax","max","valueText","segmentElements","from","group","closest","Array","querySelectorAll","focusSibling","delta","all","step","isRtl","next","indexOf","focus","getComputedStyle","direction","focusEdge","edge","length","replace","i","onPartsChange","handleKeyDown","event","element","target","key","preventDefault","placeholderValue","magnitude","deleteDigit","clearSegment","test","isFull","applyDigit","metaKey","ctrlKey","handleFocusOut","isCommitted","committed","commitSegment","handleBeforeInput","handlePaste","clipboardData","getData","parsed","parsePasted","tryRangePaste","onRangePaste","halves","splitRange","start","end","handleCopy","setData","formatForClipboard","handleCut","p","setComponentTemplate","precompileTemplate","strictMode","scope","on","fn"],"mappings":";;;;;;;;;;AA4DA,MAAMA,cAA0C,GAAI;AAClDC,EAAAA,IAAA,EAAM,MAAA;A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