frontile 0.18.0 → 0.18.2

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 (155) hide show
  1. package/declarations/-private/get-config.d.ts.map +1 -1
  2. package/declarations/-private/timer.d.ts +3 -3
  3. package/declarations/-private/timer.d.ts.map +1 -1
  4. package/declarations/components/buttons/chip.d.ts +1 -1
  5. package/declarations/components/buttons/chip.d.ts.map +1 -1
  6. package/declarations/components/buttons/close-button.d.ts +2 -2
  7. package/declarations/components/buttons/close-button.d.ts.map +1 -1
  8. package/declarations/components/collections/listbox/item.d.ts +2 -2
  9. package/declarations/components/collections/listbox/item.d.ts.map +1 -1
  10. package/declarations/components/collections/simple-table/column.d.ts +6 -0
  11. package/declarations/components/collections/simple-table/column.d.ts.map +1 -1
  12. package/declarations/components/collections/simple-table/footer.d.ts +2 -1
  13. package/declarations/components/collections/simple-table/footer.d.ts.map +1 -1
  14. package/declarations/components/collections/simple-table/header.d.ts +2 -1
  15. package/declarations/components/collections/simple-table/header.d.ts.map +1 -1
  16. package/declarations/components/collections/simple-table/index.d.ts +1 -1
  17. package/declarations/components/collections/simple-table/index.d.ts.map +1 -1
  18. package/declarations/components/collections/table/checkbox.d.ts +1 -1
  19. package/declarations/components/collections/table/checkbox.d.ts.map +1 -1
  20. package/declarations/components/collections/table/column-visibility.d.ts +2 -2
  21. package/declarations/components/collections/table/column-visibility.d.ts.map +1 -1
  22. package/declarations/components/collections/table/table.d.ts +9 -7
  23. package/declarations/components/collections/table/table.d.ts.map +1 -1
  24. package/declarations/components/forms/autocomplete.d.ts +12 -12
  25. package/declarations/components/forms/checkbox.d.ts +2 -2
  26. package/declarations/components/forms/checkbox.d.ts.map +1 -1
  27. package/declarations/components/forms/date-input/clipboard.d.ts +34 -0
  28. package/declarations/components/forms/date-input/clipboard.d.ts.map +1 -0
  29. package/declarations/components/forms/date-input/date-input.d.ts +93 -0
  30. package/declarations/components/forms/date-input/date-input.d.ts.map +1 -0
  31. package/declarations/components/forms/date-input/segment-group.d.ts +132 -0
  32. package/declarations/components/forms/date-input/segment-group.d.ts.map +1 -0
  33. package/declarations/components/forms/date-input/segments.d.ts +163 -0
  34. package/declarations/components/forms/date-input/segments.d.ts.map +1 -0
  35. package/declarations/components/forms/date-input/types.d.ts +175 -0
  36. package/declarations/components/forms/date-input/types.d.ts.map +1 -0
  37. package/declarations/components/forms/date-input.d.ts +6 -0
  38. package/declarations/components/forms/date-input.d.ts.map +1 -0
  39. package/declarations/components/forms/date-picker/date-picker.d.ts +263 -15
  40. package/declarations/components/forms/date-picker/date-picker.d.ts.map +1 -1
  41. package/declarations/components/forms/date-picker/end-content.d.ts +33 -3
  42. package/declarations/components/forms/date-picker/end-content.d.ts.map +1 -1
  43. package/declarations/components/forms/date-picker/types.d.ts +45 -2
  44. package/declarations/components/forms/date-picker/types.d.ts.map +1 -1
  45. package/declarations/components/forms/date-picker/value.d.ts +21 -5
  46. package/declarations/components/forms/date-picker/value.d.ts.map +1 -1
  47. package/declarations/components/forms/field.d.ts +7 -5
  48. package/declarations/components/forms/field.d.ts.map +1 -1
  49. package/declarations/components/forms/form.d.ts +5 -5
  50. package/declarations/components/forms/form.d.ts.map +1 -1
  51. package/declarations/components/forms/index.d.ts +1 -0
  52. package/declarations/components/forms/index.d.ts.map +1 -1
  53. package/declarations/components/forms/input-otp.d.ts +5 -5
  54. package/declarations/components/forms/input-otp.d.ts.map +1 -1
  55. package/declarations/components/forms/input.d.ts +15 -15
  56. package/declarations/components/forms/input.d.ts.map +1 -1
  57. package/declarations/components/forms/native-select.d.ts +10 -10
  58. package/declarations/components/forms/native-select.d.ts.map +1 -1
  59. package/declarations/components/forms/radio.d.ts +2 -2
  60. package/declarations/components/forms/radio.d.ts.map +1 -1
  61. package/declarations/components/forms/select/select.d.ts +16 -16
  62. package/declarations/components/forms/textarea.d.ts +10 -10
  63. package/declarations/components/forms/textarea.d.ts.map +1 -1
  64. package/declarations/components/navigation/pagination/pagination.d.ts +32 -1
  65. package/declarations/components/navigation/pagination/pagination.d.ts.map +1 -1
  66. package/declarations/components/overlays/overlay.d.ts +4 -4
  67. package/declarations/components/overlays/overlay.d.ts.map +1 -1
  68. package/declarations/components/utilities/avatar.d.ts +35 -2
  69. package/declarations/components/utilities/avatar.d.ts.map +1 -1
  70. package/declarations/components/utilities/collapsible.d.ts +16 -0
  71. package/declarations/components/utilities/collapsible.d.ts.map +1 -1
  72. package/declarations/test-support.d.ts +30 -0
  73. package/declarations/test-support.d.ts.map +1 -1
  74. package/declarations/utils/forms-utils-index.d.ts +1 -1
  75. package/declarations/utils/forms-utils-index.d.ts.map +1 -1
  76. package/declarations/utils/nested-data.d.ts +17 -0
  77. package/declarations/utils/nested-data.d.ts.map +1 -1
  78. package/dist/components/buttons/chip.js.map +1 -1
  79. package/dist/components/buttons/close-button.js +5 -12
  80. package/dist/components/buttons/close-button.js.map +1 -1
  81. package/dist/components/collections/listbox/item.js +4 -11
  82. package/dist/components/collections/listbox/item.js.map +1 -1
  83. package/dist/components/collections/simple-table/column.js +2 -2
  84. package/dist/components/collections/simple-table/column.js.map +1 -1
  85. package/dist/components/collections/simple-table/footer.js +1 -1
  86. package/dist/components/collections/simple-table/footer.js.map +1 -1
  87. package/dist/components/collections/simple-table/header.js +1 -1
  88. package/dist/components/collections/simple-table/header.js.map +1 -1
  89. package/dist/components/collections/simple-table/index.js +1 -1
  90. package/dist/components/collections/simple-table/index.js.map +1 -1
  91. package/dist/components/collections/table/checkbox.js +2 -7
  92. package/dist/components/collections/table/checkbox.js.map +1 -1
  93. package/dist/components/collections/table/column-visibility.js +2 -7
  94. package/dist/components/collections/table/column-visibility.js.map +1 -1
  95. package/dist/components/forms/checkbox.js +4 -12
  96. package/dist/components/forms/checkbox.js.map +1 -1
  97. package/dist/components/forms/date-input/clipboard.js +231 -0
  98. package/dist/components/forms/date-input/clipboard.js.map +1 -0
  99. package/dist/components/forms/date-input/date-input.js +204 -0
  100. package/dist/components/forms/date-input/date-input.js.map +1 -0
  101. package/dist/components/forms/date-input/segment-group.js +292 -0
  102. package/dist/components/forms/date-input/segment-group.js.map +1 -0
  103. package/dist/components/forms/date-input/segments.js +562 -0
  104. package/dist/components/forms/date-input/segments.js.map +1 -0
  105. package/dist/components/forms/date-input/types.js +2 -0
  106. package/dist/components/forms/date-input/types.js.map +1 -0
  107. package/dist/components/forms/date-input.js +4 -0
  108. package/dist/components/forms/date-input.js.map +1 -0
  109. package/dist/components/forms/date-picker/date-picker.js +361 -20
  110. package/dist/components/forms/date-picker/date-picker.js.map +1 -1
  111. package/dist/components/forms/date-picker/end-content.js +17 -4
  112. package/dist/components/forms/date-picker/end-content.js.map +1 -1
  113. package/dist/components/forms/date-picker/value.js +44 -6
  114. package/dist/components/forms/date-picker/value.js.map +1 -1
  115. package/dist/components/forms/field.js +12 -20
  116. package/dist/components/forms/field.js.map +1 -1
  117. package/dist/components/forms/form.js +11 -27
  118. package/dist/components/forms/form.js.map +1 -1
  119. package/dist/components/forms/index.js +5 -2
  120. package/dist/components/forms/index.js.map +1 -1
  121. package/dist/components/forms/input-otp.js +10 -26
  122. package/dist/components/forms/input-otp.js.map +1 -1
  123. package/dist/components/forms/input.js +9 -22
  124. package/dist/components/forms/input.js.map +1 -1
  125. package/dist/components/forms/native-select.js +5 -12
  126. package/dist/components/forms/native-select.js.map +1 -1
  127. package/dist/components/forms/radio.js +4 -12
  128. package/dist/components/forms/radio.js.map +1 -1
  129. package/dist/components/forms/textarea.js +6 -17
  130. package/dist/components/forms/textarea.js.map +1 -1
  131. package/dist/components/navigation/pagination/pagination.js +18 -2
  132. package/dist/components/navigation/pagination/pagination.js.map +1 -1
  133. package/dist/components/notifications/index.js +1 -1
  134. package/dist/components/overlays/overlay.js +8 -21
  135. package/dist/components/overlays/overlay.js.map +1 -1
  136. package/dist/components/utilities/avatar.js +26 -5
  137. package/dist/components/utilities/avatar.js.map +1 -1
  138. package/dist/components/utilities/collapsible.js +47 -3
  139. package/dist/components/utilities/collapsible.js.map +1 -1
  140. package/dist/forms.js +5 -2
  141. package/dist/forms.js.map +1 -1
  142. package/dist/index.js +6 -3
  143. package/dist/index.js.map +1 -1
  144. package/dist/{manager-jDaRVZ5o.js → manager-Dge4r8Vn.js} +9 -19
  145. package/dist/manager-Dge4r8Vn.js.map +1 -0
  146. package/dist/notifications.js +1 -1
  147. package/dist/services/notifications.js +1 -1
  148. package/dist/test-support.js +903 -389
  149. package/dist/test-support.js.map +1 -1
  150. package/dist/utils/forms-utils-index.js +1 -1
  151. package/dist/utils/forms-utils-index.js.map +1 -1
  152. package/dist/utils/nested-data.js +28 -1
  153. package/dist/utils/nested-data.js.map +1 -1
  154. package/package.json +10 -10
  155. package/dist/manager-jDaRVZ5o.js.map +0 -1
@@ -2,24 +2,30 @@ import Component from '@glimmer/component';
2
2
  import { tracked, cached } from '@glimmer/tracking';
3
3
  import { modifier } from 'ember-modifier';
4
4
  import { hash, concat } from '@ember/helper';
5
+ import { on } from '@ember/modifier';
5
6
  import { useStyles } from '@frontile/theme';
6
7
  import { FormControl } from '../form-control.js';
7
8
  import { DatePickerTrigger } from './trigger.js';
8
9
  import { DatePickerEndContent } from './end-content.js';
10
+ import { SegmentGroup } from '../date-input/segment-group.js';
11
+ import { buildParts, fromDate, resolveSegmentFormat, carryOver, timeOf, hasDateChanged, toDate } from '../date-input/segments.js';
9
12
  import { Popover } from '../../overlays/popover.js';
10
13
  import { Calendar } from '../../collections/calendar/calendar.js';
11
14
  import { ref } from '../../../utils/ref.js';
12
15
  import { C as ControlBlurTracker } from '../../../control-blur-C8OnSQR5.js';
13
16
  import { triggerFormInputEvent } from '../../../utils/forms-utils-index.js';
14
- import { parseRange, parseDate, formatValue, isEmptyValue, toWire } from './value.js';
17
+ import { parseRange, parseDate, formatValue, DEFAULT_TIME_FORMAT, isEmptyValue, withTimeOf, toWire } from './value.js';
15
18
  import { precompileTemplate } from '@ember/template-compilation';
16
19
  import { setComponentTemplate } from '@ember/component';
17
20
  import { d as decorateFieldV2, i as initializeDeferredDecorator, a as decorateMethodV2 } from '../../../runtime--fcdnjmJ-BOdRhmsS.js';
18
21
 
19
22
  /**
20
- * A date field: a button trigger showing the formatted value, and a calendar
21
- * in a popover. `@mode="range"` switches both the calendar and the value shape
22
- * to a `{ start, end }` range.
23
+ * A date field: segments the value can be typed into, a calendar button that
24
+ * opens a calendar in a popover, and -- under `@isEditable={{false}}` -- the
25
+ * older button trigger showing the formatted value instead. `@mode="range"`
26
+ * switches both the calendar and the value shape to a `{ start, end }` range,
27
+ * and -- when editable -- renders two groups of segments with a separator
28
+ * between them.
23
29
  */
24
30
  class DatePicker extends Component {
25
31
  triggerRef = ref();
@@ -43,12 +49,111 @@ class DatePicker extends Component {
43
49
  });
44
50
  }
45
51
  #isOpen = (initializeDeferredDecorator(this, "isOpen"), void 0);
52
+ static {
53
+ decorateFieldV2(this.prototype, "trackedParts", [tracked], function () {
54
+ return [];
55
+ });
56
+ }
57
+ #trackedParts = (initializeDeferredDecorator(this, "trackedParts"), void 0);
58
+ /**
59
+ * The segments, on the editable path. They are not a second source of truth
60
+ * for the value -- {@link internalValue} is -- but they cannot be derived
61
+ * from it either: mid-entry they hold digits that compose to no date at all,
62
+ * which no `Date` can represent. The calendar writes here through
63
+ * {@link commitValue}; typing writes there through {@link handlePartsChange}.
64
+ */
65
+ static {
66
+ decorateFieldV2(this.prototype, "trackedEndParts", [tracked], function () {
67
+ return [];
68
+ });
69
+ }
70
+ #trackedEndParts = (initializeDeferredDecorator(this, "trackedEndParts"), void 0);
71
+ /**
72
+ * The second group, in `@mode="range"` only. {@link trackedParts} is that
73
+ * mode's *start* group, so every path that writes one writes both.
74
+ */
75
+ /**
76
+ * An untracked mirror of {@link parts}. The sync modifiers below rebuild the
77
+ * segments from the current ones, and reading the tracked field inside a
78
+ * modifier would put it in that modifier's own tracking frame -- which the
79
+ * same modifier then writes to, re-running itself forever. `DateInput`
80
+ * carries the same pair for the same reason.
81
+ */
82
+ #currentParts = [];
83
+ /** The same mirror, for {@link trackedEndParts}. */
84
+ #currentEndParts = [];
46
85
  constructor(owner, args) {
47
86
  super(owner, args);
48
87
  const seed = args.defaultValue;
49
88
  if (seed !== undefined) {
50
89
  this.internalValue = this.parseIncoming(seed);
51
90
  }
91
+ this.writeParts(this.internalValue, () => buildParts(this.locale, this.segmentFormat, this.timeOptions));
92
+ }
93
+ get parts() {
94
+ return this.trackedParts;
95
+ }
96
+ get endParts() {
97
+ return this.trackedEndParts;
98
+ }
99
+ setParts(parts) {
100
+ this.#currentParts = parts;
101
+ this.trackedParts = parts;
102
+ }
103
+ setEndParts(parts) {
104
+ this.#currentEndParts = parts;
105
+ this.trackedEndParts = parts;
106
+ }
107
+ /**
108
+ * Writes a value across the segments, whichever mode is in play.
109
+ *
110
+ * `onto` supplies the list each group is written into -- the current
111
+ * segments when a value moved, a freshly built row when the locale or the
112
+ * format changed. It is a function because range mode needs two independent
113
+ * lists and must not hand the same array to both groups.
114
+ */
115
+ writeParts(value, onto) {
116
+ if (!this.isRangeMode) {
117
+ this.setParts(fromDate(onto('start'), value));
118
+ return;
119
+ }
120
+ const range = value;
121
+ this.setParts(fromDate(onto('start'), range?.start ?? null));
122
+ this.setEndParts(fromDate(onto('end'), range?.end ?? null));
123
+ }
124
+ /** Whether the value is typed rather than only picked. */
125
+ get isSegmented() {
126
+ return this.args.isEditable ?? true;
127
+ }
128
+ /**
129
+ * The format the segments are built from. The editable default is numeric;
130
+ * `{ dateStyle: 'medium' }` -- this component's own button default --
131
+ * renders "Jan" and has no numeric segment to type into, so a textual
132
+ * format falls back to the numeric default rather than rendering a field
133
+ * nobody can type in.
134
+ */
135
+ get segmentFormat() {
136
+ // Only the month is replaced; any other field the consumer named stands.
137
+ return resolveSegmentFormat(this.args.formatOptions, {
138
+ message: 'An editable <DatePicker> needs numeric segments; ' + 'a textual @formatOptions month falls back to a numeric one. ' + 'Pass @isEditable={{false}} for the formatted button trigger.',
139
+ id: 'frontile.date-picker.textual-format'
140
+ });
141
+ }
142
+ get placeholderValue() {
143
+ return this.args.placeholderValue ?? new Date();
144
+ }
145
+ /** The time segments the field adds to the date, if any. */
146
+ get timeOptions() {
147
+ return {
148
+ granularity: this.args.granularity,
149
+ hourCycle: this.args.hourCycle
150
+ };
151
+ }
152
+ static {
153
+ decorateMethodV2(this.prototype, "timeOptions", [cached]);
154
+ }
155
+ get hasTime() {
156
+ return (this.args.granularity ?? 'day') !== 'day';
52
157
  }
53
158
  get mode() {
54
159
  return this.args.mode ?? 'single';
@@ -82,12 +187,46 @@ class DatePicker extends Component {
82
187
  * before the form holds anything for it -- keeps whatever the user chose.
83
188
  */
84
189
  syncValue = modifier((_, [raw]) => {
85
- if (raw !== undefined) {
86
- this.internalValue = this.parseIncoming(raw);
190
+ if (raw === undefined) return;
191
+ const parsed = this.parseIncoming(raw);
192
+ this.internalValue = parsed;
193
+ // The segments are a second rendering of the same value, so an argument
194
+ // change has to reach them too; without this a `@value`-controlled picker
195
+ // shows empty segments. `#currentParts` rather than `this.parts` -- see
196
+ // the field's own comment.
197
+ //
198
+ // Unless the argument is merely the echo of our own `@onChange`: a
199
+ // controlled consumer writes back what we just reported, and rewriting the
200
+ // segments from it would destroy a partial entry. Backspacing one digit of
201
+ // the year un-commits it, so the field composes `null`, reports `null`, and
202
+ // is handed `null` straight back -- and `writeParts` would spend that on
203
+ // clearing every other segment, both groups in range mode. One keystroke
204
+ // would empty the field.
205
+ if (this.isSegmented && this.segmentsWouldChange(parsed)) {
206
+ this.writeParts(parsed, edge => edge === 'start' ? this.#currentParts : this.#currentEndParts);
207
+ }
208
+ });
209
+ /**
210
+ * Rebuilds the segment order when the locale or format changes, carrying the
211
+ * current value across so switching en-US to en-GB reorders the field
212
+ * without emptying it. Reads no tracked state, so it runs on an argument
213
+ * change and never on a keystroke.
214
+ */
215
+ syncSegmentFormat = modifier((_, [locale, format, time]) => {
216
+ if (!this.isSegmented) return;
217
+ // One `Intl.DateTimeFormat` for both edges: the arguments are identical,
218
+ // and the constructor is the expensive part. `carryOver` copies rather
219
+ // than mutates, so the two groups cannot share structure by accident.
220
+ const fresh = buildParts(locale, format, time);
221
+ // Segment by segment rather than through the composed value, so a
222
+ // half-typed entry survives the rebuild.
223
+ this.setParts(carryOver(fresh, this.#currentParts));
224
+ if (this.isRangeMode) {
225
+ this.setEndParts(carryOver(fresh, this.#currentEndParts));
87
226
  }
88
227
  });
89
228
  get formatted() {
90
- return formatValue(this.value, this.locale, this.args.formatOptions);
229
+ return formatValue(this.value, this.locale, this.args.formatOptions ?? (this.hasTime ? DEFAULT_TIME_FORMAT : undefined));
91
230
  }
92
231
  get isEmpty() {
93
232
  return isEmptyValue(this.value);
@@ -121,7 +260,13 @@ class DatePicker extends Component {
121
260
  * calendar and on every day click.
122
261
  */
123
262
  blurTracker = new ControlBlurTracker({
124
- trigger: () => this.triggerRef.current,
263
+ // Resolved through whichever element the popover's `trigger` modifier sits
264
+ // on, because the tracker finds the portaled content by that element's
265
+ // `aria-controls`. On the segmented path there is no button trigger: the
266
+ // calendar button in the end content opens the popover instead, and
267
+ // pointing this at nothing would make a click into the open calendar read
268
+ // as a blur.
269
+ trigger: () => this.triggerRef.current ?? this.containerRef.current?.querySelector('[data-part="calendar-button"]'),
125
270
  container: () => this.containerRef.current,
126
271
  isOpen: () => this.isOpen,
127
272
  isDestroyed: () => this.isDestroyed || this.isDestroying,
@@ -155,12 +300,27 @@ class DatePicker extends Component {
155
300
  * away -- closing would just make them reopen it.
156
301
  */
157
302
  clear = () => {
158
- this.internalValue = null;
159
- this.args.onChange?.(null);
160
- this.notifyForm();
161
- this.triggerRef.current?.focus();
303
+ this.commitValue(null, {
304
+ writeParts: true
305
+ });
306
+ this.focusField();
162
307
  };
163
308
  /**
309
+ * Whatever the field's own focusable thing is: the button trigger, or --
310
+ * when segmented -- the segment the user was last in, falling back to the
311
+ * first one. A recorded segment that has left the DOM is not one focus can
312
+ * go back to.
313
+ */
314
+ focusTarget() {
315
+ if (!this.isSegmented) return this.triggerRef.current;
316
+ const last = this.lastFocusedSegment;
317
+ if (last && last.isConnected) return last;
318
+ return this.containerRef.current?.querySelector('[data-part="segment"]');
319
+ }
320
+ focusField() {
321
+ this.focusTarget()?.focus();
322
+ }
323
+ /**
164
324
  * Whether the selection is finished, and the popover should therefore close.
165
325
  * A range with only its anchor set is not: the user still owes a second
166
326
  * click, and closing would throw away the half they just made.
@@ -170,16 +330,185 @@ class DatePicker extends Component {
170
330
  if (this.mode !== 'range') return true;
171
331
  return value.end !== null;
172
332
  }
173
- handleChange = value => {
333
+ /**
334
+ * The one path a value change takes, whichever editor produced it.
335
+ *
336
+ * `writeParts` says whether the segments are that editor's output or its
337
+ * input. The calendar, the `:footer` block and the clear button are all
338
+ * *other* editors, and the segments have to be rewritten to show what they
339
+ * did. Typing is the segments themselves: rewriting them there would
340
+ * overwrite the buffer the user is still typing into, turning a half-typed
341
+ * year back into a padded one on every completed keystroke.
342
+ */
343
+ commitValue(value, {
344
+ writeParts
345
+ }) {
174
346
  // Internal state updates even when controlled, so the calendar's own
175
347
  // rendering stays responsive; the `value` getter ignores it in that case,
176
348
  // so the consumer still has the last word.
177
349
  this.internalValue = value;
350
+ if (writeParts && this.isSegmented) {
351
+ this.writeParts(value, edge => edge === 'start' ? this.#currentParts : this.#currentEndParts);
352
+ }
178
353
  this.args.onChange?.(value);
179
354
  this.notifyForm();
355
+ }
356
+ handleChange = value => {
357
+ this.commitValue(value, {
358
+ writeParts: true
359
+ });
180
360
  if (this.isComplete(value)) this.close();
181
361
  };
182
362
  /**
363
+ * A day picked in the calendar. The calendar knows days only, so under an
364
+ * `hour` or `minute` granularity the pick takes the time the field already
365
+ * shows -- each end of a range its own -- or midnight when there is none.
366
+ */
367
+ handleCalendarChange = value => {
368
+ if (!this.hasTime || !value) {
369
+ this.handleChange(value);
370
+ return;
371
+ }
372
+ if (!this.isRangeMode) {
373
+ this.handleChange(withTimeOf(value, this.timeAt('start')));
374
+ return;
375
+ }
376
+ const range = value;
377
+ this.handleChange({
378
+ start: withTimeOf(range.start, this.timeAt('start')),
379
+ end: range.end ? withTimeOf(range.end, this.timeAt('end')) : null
380
+ });
381
+ };
382
+ /**
383
+ * The time one end of the field holds: what its segments show -- typed in
384
+ * even before any day was -- or, on the button trigger, which has no
385
+ * segments, the current value's. Midnight when there is none.
386
+ */
387
+ timeAt(edge) {
388
+ const midnight = {
389
+ hours: 0,
390
+ minutes: 0
391
+ };
392
+ if (this.isSegmented) {
393
+ const parts = edge === 'start' ? this.#currentParts : this.#currentEndParts;
394
+ return timeOf(parts) ?? midnight;
395
+ }
396
+ const value = this.value;
397
+ const date = this.isRangeMode ? value?.[edge] : value;
398
+ return date ? {
399
+ hours: date.getHours(),
400
+ minutes: date.getMinutes()
401
+ } : midnight;
402
+ }
403
+ /**
404
+ * Whether an incoming value differs from what the segments already compose.
405
+ *
406
+ * Compared edge by edge in range mode rather than by identity: the two are
407
+ * distinct objects on every report, so an object comparison would always
408
+ * say "changed" and defeat the guard entirely.
409
+ */
410
+ segmentsWouldChange(incoming) {
411
+ if (!this.isRangeMode) {
412
+ return hasDateChanged(toDate(this.#currentParts), incoming);
413
+ }
414
+ const composed = this.rangeFromParts();
415
+ const next = incoming;
416
+ return hasDateChanged(composed?.start ?? null, next?.start ?? null) || hasDateChanged(composed?.end ?? null, next?.end ?? null);
417
+ }
418
+ /**
419
+ * The segments changed. Only value *transitions* are reported: the four
420
+ * keystrokes that fill a month and a day compose no date at all, and report
421
+ * nothing. The popover is deliberately left alone -- typing never opened it,
422
+ * so completing a date by typing has nothing to close.
423
+ */
424
+ handlePartsChange = parts => {
425
+ const before = toDate(this.#currentParts);
426
+ this.setParts(parts);
427
+ const after = toDate(parts);
428
+ if (!hasDateChanged(before, after)) return;
429
+ this.commitValue(after, {
430
+ writeParts: false
431
+ });
432
+ };
433
+ /**
434
+ * The two range groups report separately, but a range is one value: each
435
+ * one recomposes the whole thing and reports only what moved.
436
+ */
437
+ handleStartParts = parts => {
438
+ const before = this.rangeFromParts();
439
+ this.setParts(parts);
440
+ this.reportRange(before);
441
+ };
442
+ handleEndParts = parts => {
443
+ const before = this.rangeFromParts();
444
+ this.setEndParts(parts);
445
+ this.reportRange(before);
446
+ };
447
+ /** Two dates pasted into the start group, which fill both. */
448
+ handleRangePaste = (start, end) => {
449
+ const before = this.rangeFromParts();
450
+ this.setParts(start);
451
+ this.setEndParts(end);
452
+ this.reportRange(before);
453
+ };
454
+ /**
455
+ * The range the two groups currently compose, or `null`.
456
+ *
457
+ * `DateRange.start` is a `Date`, not `Date | null`: a range is anchored at
458
+ * its start, and the half-open shape the calendar produces mid-selection is
459
+ * `{ start, end: null }` -- never the other way round. So segments that
460
+ * compose no start compose no range at all, however complete the end group
461
+ * is. That is what makes clearing the start report `null` rather than
462
+ * leaving a consumer holding a range the field no longer shows; the end's
463
+ * digits stay on screen, exactly as a half-typed single date's do.
464
+ */
465
+ rangeFromParts() {
466
+ const start = toDate(this.#currentParts);
467
+ if (!start) return null;
468
+ return {
469
+ start,
470
+ end: toDate(this.#currentEndParts)
471
+ };
472
+ }
473
+ /**
474
+ * Reports the range only if it moved, which is the single-mode contract
475
+ * applied to two ends: the keystrokes that fill a month and a day compose
476
+ * nothing and report nothing, and either end changing is a change.
477
+ */
478
+ reportRange(before) {
479
+ const after = this.rangeFromParts();
480
+ const moved = hasDateChanged(before?.start ?? null, after?.start ?? null) || hasDateChanged(before?.end ?? null, after?.end ?? null);
481
+ if (!moved) return;
482
+ this.commitValue(after, {
483
+ writeParts: false
484
+ });
485
+ }
486
+ /**
487
+ * The start and end groups' accessible names. Two `role="group"`s cannot
488
+ * share one id or one name, and `FormControl`'s label can only be
489
+ * associated with one element -- so each group names itself, deriving from
490
+ * `@label` so that the visible label is contained in both names.
491
+ */
492
+ get startLabel() {
493
+ return this.args.label ? `${this.args.label} start` : 'start date';
494
+ }
495
+ get endLabel() {
496
+ return this.args.label ? `${this.args.label} end` : 'end date';
497
+ }
498
+ /**
499
+ * The segment that last held focus, so that closing the calendar can hand
500
+ * focus back to where the user was. Recorded from the group's `focusin`
501
+ * rather than captured when the popover opens, because the calendar button
502
+ * is clicked *after* focus has already left the segment.
503
+ */
504
+ lastFocusedSegment = null;
505
+ handleSegmentFocusIn = event => {
506
+ const target = event.target;
507
+ if (target instanceof HTMLElement && target.getAttribute('data-part') === 'segment') {
508
+ this.lastFocusedSegment = target;
509
+ }
510
+ };
511
+ /**
183
512
  * Tells an enclosing `Form` the value moved.
184
513
  *
185
514
  * The hidden inputs are written programmatically, and a programmatic value
@@ -217,14 +546,16 @@ class DatePicker extends Component {
217
546
  */
218
547
  close = () => {
219
548
  this.isOpen = false;
220
- this.triggerRef.current?.focus();
549
+ this.focusField();
221
550
  };
222
551
  get classes() {
223
552
  const {
224
553
  datePicker
225
554
  } = useStyles();
226
555
  return datePicker({
227
- size: this.args.inputSize
556
+ size: this.args.inputSize,
557
+ isSegmented: this.isSegmented,
558
+ isRange: this.isSegmented && this.isRangeMode
228
559
  });
229
560
  }
230
561
  static {
@@ -234,25 +565,33 @@ class DatePicker extends Component {
234
565
  return this.mode === 'range';
235
566
  }
236
567
  /**
568
+ * The segmented field has no button trigger for a click to fall through to,
569
+ * and its calendar icon is a real button, so the cluster has to take pointer
570
+ * events. An explicit argument still wins.
571
+ */
572
+ get endContentPointerEvents() {
573
+ return this.args.endContentPointerEvents ?? (this.isSegmented ? 'auto' : 'none');
574
+ }
575
+ /**
237
576
  * The single-mode wire value, or `''` when there is nothing selected. Only
238
577
  * read from the single-mode branch of the template, so it does not repeat
239
578
  * that branch's mode check.
240
579
  */
241
580
  get wireValue() {
242
- return toWire(this.value);
581
+ return toWire(this.value, this.args.granularity);
243
582
  }
244
583
  get wireRangeStart() {
245
- return toWire(this.value?.start ?? null);
584
+ return toWire(this.value?.start ?? null, this.args.granularity);
246
585
  }
247
586
  get wireRangeEnd() {
248
- return toWire(this.value?.end ?? null);
587
+ return toWire(this.value?.end ?? null, this.args.granularity);
249
588
  }
250
589
  get calendarBlockArg() {
251
590
  return {
252
591
  mode: this.mode,
253
592
  color: this.args.color,
254
593
  value: this.value,
255
- onChange: this.handleChange,
594
+ onChange: this.handleCalendarChange,
256
595
  locale: this.locale,
257
596
  weekStartsOn: this.args.weekStartsOn,
258
597
  minValue: this.args.minValue,
@@ -282,12 +621,14 @@ class DatePicker extends Component {
282
621
  decorateMethodV2(this.prototype, "footerBlockArg", [cached]);
283
622
  }
284
623
  static {
285
- setComponentTemplate(precompileTemplate("<div {{this.syncValue @value}} {{this.containerRef.setup}} class={{this.classes.base class=@classes.base}} data-component=\"date-picker\" data-part=\"base\" ...attributes>\n {{!-- A range's two names use dot notation, the convention Form documents\n for nested data -- so it arrives at a validator and at onSubmit as one\n { start, end } object rather than two loose keys. --}}\n {{#if @name}}\n {{#if this.isRangeMode}}\n <input type=\"hidden\" name={{concat @name \".start\"}} value={{this.wireRangeStart}} />\n <input type=\"hidden\" name={{concat @name \".end\"}} value={{this.wireRangeEnd}} />\n {{else}}\n <input type=\"hidden\" name={{@name}} value={{this.wireValue}} />\n {{/if}}\n {{/if}}\n <FormControl @id={{@id}} @size={{@inputSize}} @label={{@label}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} @isDisabled={{@isDisabled}} as |c|>\n <Popover @placement={{@placement}} @flipOptions={{@flipOptions}} @middleware={{@middleware}} @shiftOptions={{@shiftOptions}} @offsetOptions={{@offsetOptions}} @strategy={{@strategy}} @didClose={{@didClose}} @isOpen={{this.isOpen}} @onOpenChange={{this.onOpenChange}} as |p|>\n <div {{p.anchor}} class={{this.classes.innerContainer class=@classes.innerContainer}} data-part=\"inner-container\">\n <DatePickerTrigger @id={{c.id}} @trigger={{p.trigger}} @placeholder={{@placeholder}} @formatted={{this.formatted}} @isEmpty={{this.isEmpty}} @isDisabled={{@isDisabled}} @isInvalid={{c.isInvalid}} @hasCustomContent={{has-block \"value\"}} @accessibleName={{this.accessibleName}} @triggerRef={{this.triggerRef.setup}} @classes={{this.classes}} @userClasses={{@classes}} @onFocusOut={{this.blurTracker.handleFocusOut}}>\n <:value>\n {{#if (has-block \"value\")}}\n {{yield this.valueBlockArg to=\"value\"}}\n {{/if}}\n </:value>\n </DatePickerTrigger>\n\n <DatePickerEndContent @classes={{this.classes}} @userClasses={{@classes}} @endContentPointerEvents={{@endContentPointerEvents}} @isClearable={{this.isClearable}} @onClear={{this.clear}} />\n </div>\n\n {{!-- preventAutoFocus: overlay's default focus grab runs later()\n after Calendar's autofocus already focused the day; turned off so\n Calendar's autofocus is the only thing moving focus into the grid. --}}\n <p.Content @size={{if @popoverSize @popoverSize \"auto\"}} @target={{@target}} @renderInPlace={{@renderInPlace}} @closeOnOutsideClick={{@closeOnOutsideClick}} @closeOnEscapeKey={{@closeOnEscapeKey}} @transitionDuration={{@transitionDuration}} @disableTransitions={{@disableTransitions}} @blockScroll={{false}} @preventAutoFocus={{true}} role=\"dialog\" aria-label={{@label}}>\n {{#if (has-block \"calendar\")}}\n {{yield this.calendarBlockArg to=\"calendar\"}}\n {{else}}\n <Calendar @mode={{this.mode}} @color={{@color}} @value={{this.value}} @onChange={{this.handleChange}} @locale={{@locale}} @weekStartsOn={{@weekStartsOn}} @minValue={{@minValue}} @maxValue={{@maxValue}} @isDateUnavailable={{@isDateUnavailable}} @visibleMonths={{@visibleMonths}} @captionLayout={{@captionLayout}} @fixedWeeks={{@fixedWeeks}} @showOutsideDays={{@showOutsideDays}} @isReadOnly={{@isReadOnly}} @isDisabled={{@isDisabled}} @labelledBy={{c.id}} @autofocus={{true}} @classes={{hash base=(this.classes.calendar class=@classes.calendar)}} data-part=\"calendar\" />\n {{/if}}\n\n {{#if (has-block \"footer\")}}\n <div data-part=\"footer\" class={{this.classes.footer class=@classes.footer}}>\n {{yield this.footerBlockArg to=\"footer\"}}\n </div>\n {{/if}}\n </p.Content>\n </Popover>\n </FormControl>\n</div>", {
624
+ setComponentTemplate(precompileTemplate("<div {{this.syncSegmentFormat this.locale this.segmentFormat this.timeOptions}} {{this.syncValue @value}} {{this.containerRef.setup}} class={{this.classes.base class=@classes.base}} data-component=\"date-picker\" data-part=\"base\" ...attributes>\n {{!-- A range's two names use dot notation, the convention Form documents\n for nested data -- so it arrives at a validator and at onSubmit as one\n { start, end } object rather than two loose keys. --}}\n {{#if @name}}\n {{#if this.isRangeMode}}\n <input type=\"hidden\" name={{concat @name \".start\"}} value={{this.wireRangeStart}} />\n <input type=\"hidden\" name={{concat @name \".end\"}} value={{this.wireRangeEnd}} />\n {{else}}\n <input type=\"hidden\" name={{@name}} value={{this.wireValue}} />\n {{/if}}\n {{/if}}\n <FormControl @id={{@id}} @size={{@inputSize}} @label={{@label}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} @isDisabled={{@isDisabled}} as |c|>\n <Popover @placement={{@placement}} @flipOptions={{@flipOptions}} @middleware={{@middleware}} @shiftOptions={{@shiftOptions}} @offsetOptions={{@offsetOptions}} @strategy={{@strategy}} @didClose={{@didClose}} @isOpen={{this.isOpen}} @onOpenChange={{this.onOpenChange}} as |p|>\n <div {{p.anchor}} class={{this.classes.innerContainer class=@classes.innerContainer}} data-part=\"inner-container\" {{!-- The shell is on this element when segmented, so its invalid and\n disabled styling has to read from here. `role=\"group\"` inside\n cannot carry aria-invalid, which is why these are data\n attributes. --}} data-invalid={{if c.isInvalid \"true\" \"false\"}} data-disabled={{if @isDisabled \"true\" \"false\"}}>\n {{#if this.isSegmented}}\n {{!-- Blur tracking and focus recording ride on splattributes:\n the group renders `...attributes` on its `role=\"group\"` element,\n and both events bubble there from the segments. --}}\n {{#if this.isRangeMode}}\n {{!-- Two groups, so neither can take `c.id` or `@label`: ids\n must be unique and a name shared by both would leave a screen\n reader unable to tell the ends apart. Each derives its own\n from the field's. --}}\n <SegmentGroup @parts={{this.parts}} @onPartsChange={{this.handleStartParts}} @onRangePaste={{this.handleRangePaste}} @locale={{this.locale}} @placeholderValue={{this.placeholderValue}} @isDisabled={{@isDisabled}} @isReadOnly={{@isReadOnly}} @isInvalid={{c.isInvalid}} @id={{concat c.id \"-start\"}} @label={{this.startLabel}} @describedBy={{c.describedBy @description c.isInvalid}} @segmentLabels={{@segmentLabels}} @classes={{this.classes}} @userClasses={{@classes}} {{on \"focusin\" this.handleSegmentFocusIn}} {{on \"focusout\" this.blurTracker.handleFocusOut}} />\n <span data-part=\"separator\" aria-hidden=\"true\" class={{this.classes.separator class=@classes.separator}}>&ndash;</span>\n {{!-- No `@onRangePaste`: pasting \"20 Jan - 25 Jan\" into the end\n of a range and having it rewrite the start would be\n surprising. --}}\n <SegmentGroup @parts={{this.endParts}} @onPartsChange={{this.handleEndParts}} @locale={{this.locale}} @placeholderValue={{this.placeholderValue}} @isDisabled={{@isDisabled}} @isReadOnly={{@isReadOnly}} @isInvalid={{c.isInvalid}} @id={{concat c.id \"-end\"}} @label={{this.endLabel}} @describedBy={{c.describedBy @description c.isInvalid}} @segmentLabels={{@segmentLabels}} @classes={{this.classes}} @userClasses={{@classes}} {{on \"focusin\" this.handleSegmentFocusIn}} {{on \"focusout\" this.blurTracker.handleFocusOut}} />\n {{else}}\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}} {{on \"focusin\" this.handleSegmentFocusIn}} {{on \"focusout\" this.blurTracker.handleFocusOut}} />\n {{/if}}\n {{else}}\n <DatePickerTrigger @id={{c.id}} @trigger={{p.trigger}} @placeholder={{@placeholder}} @formatted={{this.formatted}} @isEmpty={{this.isEmpty}} @isDisabled={{@isDisabled}} @isInvalid={{c.isInvalid}} @hasCustomContent={{has-block \"value\"}} @accessibleName={{this.accessibleName}} @triggerRef={{this.triggerRef.setup}} @classes={{this.classes}} @userClasses={{@classes}} @onFocusOut={{this.blurTracker.handleFocusOut}}>\n <:value>\n {{#if (has-block \"value\")}}\n {{yield this.valueBlockArg to=\"value\"}}\n {{/if}}\n </:value>\n </DatePickerTrigger>\n {{/if}}\n\n <DatePickerEndContent @classes={{this.classes}} @userClasses={{@classes}} @endContentPointerEvents={{this.endContentPointerEvents}} @isClearable={{this.isClearable}} @onClear={{this.clear}} @isEditable={{this.isSegmented}} @trigger={{p.trigger}} @label={{@label}} @isDisabled={{@isDisabled}} />\n </div>\n\n {{!-- preventAutoFocus: overlay's default focus grab runs later()\n after Calendar's autofocus already focused the day; turned off so\n Calendar's autofocus is the only thing moving focus into the grid. --}}\n <p.Content @size={{if @popoverSize @popoverSize \"auto\"}} @target={{@target}} @renderInPlace={{@renderInPlace}} @closeOnOutsideClick={{@closeOnOutsideClick}} @closeOnEscapeKey={{@closeOnEscapeKey}} @transitionDuration={{@transitionDuration}} @disableTransitions={{@disableTransitions}} @blockScroll={{false}} @preventAutoFocus={{true}} {{!-- Overlay captures document.activeElement when the content\n mounts -- the calendar button, on the segmented path -- and\n refocuses it on teardown, after close() has already put focus back\n on the segment. `close()` is the one answer; this stops the\n overlay giving a second. --}} @preventFocusRestore={{this.isSegmented}} role=\"dialog\" aria-label={{@label}}>\n {{#if (has-block \"calendar\")}}\n {{yield this.calendarBlockArg to=\"calendar\"}}\n {{else}}\n <Calendar @mode={{this.mode}} @color={{@color}} @value={{this.value}} @onChange={{this.handleCalendarChange}} @locale={{@locale}} @weekStartsOn={{@weekStartsOn}} @minValue={{@minValue}} @maxValue={{@maxValue}} @isDateUnavailable={{@isDateUnavailable}} @visibleMonths={{@visibleMonths}} @captionLayout={{@captionLayout}} @fixedWeeks={{@fixedWeeks}} @showOutsideDays={{@showOutsideDays}} @isReadOnly={{@isReadOnly}} @isDisabled={{@isDisabled}} @labelledBy={{c.id}} @autofocus={{true}} @classes={{hash base=(this.classes.calendar class=@classes.calendar)}} data-part=\"calendar\" />\n {{/if}}\n\n {{#if (has-block \"footer\")}}\n <div data-part=\"footer\" class={{this.classes.footer class=@classes.footer}}>\n {{yield this.footerBlockArg to=\"footer\"}}\n </div>\n {{/if}}\n </p.Content>\n </Popover>\n </FormControl>\n</div>", {
286
625
  strictMode: true,
287
626
  scope: () => ({
288
627
  concat,
289
628
  FormControl,
290
629
  Popover,
630
+ SegmentGroup,
631
+ on,
291
632
  DatePickerTrigger,
292
633
  DatePickerEndContent,
293
634
  Calendar,