@3mo/date-time-fields 0.16.1 → 0.17.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 (85) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +443 -0
  3. package/dist/FieldDateTimePrecision.d.ts +1 -1
  4. package/dist/FieldDateTimePrecision.d.ts.map +1 -1
  5. package/dist/FieldDateTimePrecision.js +0 -1
  6. package/dist/custom-elements.json +369 -3092
  7. package/dist/date-time/FieldDate.d.ts +20 -0
  8. package/dist/date-time/FieldDate.d.ts.map +1 -0
  9. package/dist/date-time/FieldDate.js +23 -0
  10. package/dist/date-time/FieldDateTime.d.ts +42 -0
  11. package/dist/date-time/FieldDateTime.d.ts.map +1 -0
  12. package/dist/date-time/FieldDateTime.js +67 -0
  13. package/dist/date-time/FieldDateTimeBase.d.ts +67 -0
  14. package/dist/date-time/FieldDateTimeBase.d.ts.map +1 -0
  15. package/dist/{FieldDateTimeBase.js → date-time/FieldDateTimeBase.js} +103 -105
  16. package/dist/date-time/FieldDateTimeController.d.ts +30 -0
  17. package/dist/date-time/FieldDateTimeController.d.ts.map +1 -0
  18. package/dist/date-time/FieldDateTimeController.js +87 -0
  19. package/dist/date-time/FieldDateTimeControllerBase.d.ts +81 -0
  20. package/dist/date-time/FieldDateTimeControllerBase.d.ts.map +1 -0
  21. package/dist/date-time/FieldDateTimeControllerBase.js +103 -0
  22. package/dist/date-time/index.d.ts +5 -0
  23. package/dist/date-time/index.d.ts.map +1 -0
  24. package/dist/date-time/index.js +4 -0
  25. package/dist/{DateRangeParser.d.ts → date-time-range/DateRangeParser.d.ts} +1 -1
  26. package/dist/date-time-range/DateRangeParser.d.ts.map +1 -0
  27. package/dist/date-time-range/FieldDateRange.d.ts +20 -0
  28. package/dist/date-time-range/FieldDateRange.d.ts.map +1 -0
  29. package/dist/date-time-range/FieldDateRange.js +23 -0
  30. package/dist/date-time-range/FieldDateTimeRange.d.ts +49 -0
  31. package/dist/date-time-range/FieldDateTimeRange.d.ts.map +1 -0
  32. package/dist/date-time-range/FieldDateTimeRange.js +108 -0
  33. package/dist/date-time-range/FieldDateTimeRangeController.d.ts +44 -0
  34. package/dist/date-time-range/FieldDateTimeRangeController.d.ts.map +1 -0
  35. package/dist/date-time-range/FieldDateTimeRangeController.js +137 -0
  36. package/dist/{FieldToggleableDateTimeRange.d.ts → date-time-range/FieldToggleableDateTimeRange.d.ts} +1 -1
  37. package/dist/date-time-range/FieldToggleableDateTimeRange.d.ts.map +1 -0
  38. package/dist/{FieldToggleableDateTimeRange.js → date-time-range/FieldToggleableDateTimeRange.js} +1 -1
  39. package/dist/date-time-range/index.d.ts +5 -0
  40. package/dist/date-time-range/index.d.ts.map +1 -0
  41. package/dist/date-time-range/index.js +4 -0
  42. package/dist/dateTimeConverter.d.ts +2 -0
  43. package/dist/dateTimeConverter.d.ts.map +1 -0
  44. package/dist/dateTimeConverter.js +10 -0
  45. package/dist/index.d.ts +3 -7
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +3 -7
  48. package/dist/segments/DateTimeSegmenter.d.ts +1 -1
  49. package/dist/segments/DateTimeSegmentsController.d.ts +1 -1
  50. package/dist/segments/DateTimeSegmentsController.d.ts.map +1 -1
  51. package/dist/selection/Calendar.d.ts +2 -2
  52. package/dist/selection/Calendar.d.ts.map +1 -1
  53. package/dist/selection/Calendar.js +4 -3
  54. package/dist/selection/CalendarDatesController.d.ts +5 -5
  55. package/dist/selection/CalendarDatesController.d.ts.map +1 -1
  56. package/dist/{FieldTime.d.ts → time/FieldTime.d.ts} +8 -6
  57. package/dist/time/FieldTime.d.ts.map +1 -0
  58. package/dist/{FieldTime.js → time/FieldTime.js} +8 -6
  59. package/dist/{FieldTimeController.d.ts → time/FieldTimeController.d.ts} +5 -5
  60. package/dist/time/FieldTimeController.d.ts.map +1 -0
  61. package/dist/{FieldTimeController.js → time/FieldTimeController.js} +2 -2
  62. package/dist/time/index.d.ts +3 -0
  63. package/dist/time/index.d.ts.map +1 -0
  64. package/dist/time/index.js +2 -0
  65. package/package.json +15 -8
  66. package/dist/DateRangeParser.d.ts.map +0 -1
  67. package/dist/FieldDate.d.ts +0 -14
  68. package/dist/FieldDate.d.ts.map +0 -1
  69. package/dist/FieldDate.js +0 -17
  70. package/dist/FieldDateRange.d.ts +0 -12
  71. package/dist/FieldDateRange.d.ts.map +0 -1
  72. package/dist/FieldDateRange.js +0 -15
  73. package/dist/FieldDateTime.d.ts +0 -40
  74. package/dist/FieldDateTime.d.ts.map +0 -1
  75. package/dist/FieldDateTime.js +0 -109
  76. package/dist/FieldDateTimeBase.d.ts +0 -59
  77. package/dist/FieldDateTimeBase.d.ts.map +0 -1
  78. package/dist/FieldDateTimeRange.d.ts +0 -53
  79. package/dist/FieldDateTimeRange.d.ts.map +0 -1
  80. package/dist/FieldDateTimeRange.js +0 -167
  81. package/dist/FieldTime.d.ts.map +0 -1
  82. package/dist/FieldTimeController.d.ts.map +0 -1
  83. package/dist/FieldToggleableDateTimeRange.d.ts.map +0 -1
  84. package/dist/tsconfig.tsbuildinfo +0 -1
  85. /package/dist/{DateRangeParser.js → date-time-range/DateRangeParser.js} +0 -0
@@ -0,0 +1,87 @@
1
+ import { Localizer } from '@3mo/localization';
2
+ import { FieldDateTimeControllerBase } from './FieldDateTimeControllerBase.js';
3
+ import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
4
+ Localizer.dictionaries.add('de', {
5
+ 'Today': 'Heute',
6
+ 'Yesterday': 'Gestern',
7
+ 'Tomorrow': 'Morgen',
8
+ 'Week start': 'Wochenstart',
9
+ 'Week end': 'Wochenende',
10
+ 'Month start': 'Monatsanfang',
11
+ 'Month end': 'Monatsende',
12
+ 'Year start': 'Jahresanfang',
13
+ 'Year end': 'Jahresende',
14
+ });
15
+ /**
16
+ * Everything a date or date-time field does, for a host which only renders it: the segments at the
17
+ * field's precision, where a picker stands and what picking in it means, the presets, and the validity.
18
+ *
19
+ * ```html
20
+ * <div ${this.controller.group.ref()}>
21
+ * ${this.controller.segments.segments.map(segment => html`<span ${this.controller.segment.ref(segment)}></span>`)}
22
+ * </div>
23
+ * ```
24
+ *
25
+ * A picker is the host's to render: it opens on `handlePickerOpen`, scrolls with `navigationDate`,
26
+ * marks `calendarValue`, and hands what was chosen to `pick`.
27
+ *
28
+ * @ssr false
29
+ */
30
+ export class FieldDateTimeController extends FieldDateTimeControllerBase {
31
+ constructor() {
32
+ super(...arguments);
33
+ this.segments = this.createSegments(controller => ({
34
+ get value() { return controller.selectedDate; },
35
+ handleInput: value => controller.options.handleInput?.(value),
36
+ handleChange: value => controller.options.handleChange?.(value),
37
+ }));
38
+ }
39
+ get group() {
40
+ return this.segments.group;
41
+ }
42
+ get segment() {
43
+ return this.segments.segment;
44
+ }
45
+ get segmentsControllers() {
46
+ return [this.segments];
47
+ }
48
+ get selectedDate() {
49
+ return this.options.value ? new DateTime(this.options.value) : undefined;
50
+ }
51
+ get calendarValue() {
52
+ return new DateTimeRange(this.selectedDate, this.selectedDate);
53
+ }
54
+ /** A picked day keeps the time the picker stands at; the value starts at the precision's unit. */
55
+ pick(date) {
56
+ const { hour, minute, second } = this.navigationDate;
57
+ this.options.handleChange?.(this.precision.getRange(date.with({ hour, minute, second })).start);
58
+ }
59
+ datesOf(value) {
60
+ return [new DateTime(value)];
61
+ }
62
+ get defaultPresets() {
63
+ if (this.precision < FieldDateTimePrecision.Day) {
64
+ return [];
65
+ }
66
+ const now = new DateTime();
67
+ return [
68
+ [
69
+ { label: t('Today'), value: now.dayStart },
70
+ { label: t('Yesterday'), value: now.subtract({ days: 1 }).dayStart },
71
+ { label: t('Tomorrow'), value: now.add({ days: 1 }).dayStart },
72
+ ],
73
+ [
74
+ { label: t('Week start'), value: now.weekStart.dayStart },
75
+ { label: t('Week end'), value: now.weekEnd.dayEnd },
76
+ ],
77
+ [
78
+ { label: t('Month start'), value: now.monthStart.dayStart },
79
+ { label: t('Month end'), value: now.monthEnd.dayEnd },
80
+ ],
81
+ [
82
+ { label: t('Year start'), value: now.yearStart.dayStart },
83
+ { label: t('Year end'), value: now.yearEnd.dayEnd },
84
+ ],
85
+ ];
86
+ }
87
+ }
@@ -0,0 +1,81 @@
1
+ import { Controller, type ReactiveControllerHost } from '@a11d/lit';
2
+ import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
3
+ import { DateTimeSegmentsController, type DateTimeSegmentsControllerOptions, type HourCycle } from '../segments/index.js';
4
+ export type FieldDateTimeControllerOptions<T> = {
5
+ readonly value?: T;
6
+ /** Defaults to 'minute'. */
7
+ readonly precision?: FieldDateTimePrecision;
8
+ /** Defaults to the language's convention. */
9
+ readonly hourCycle?: HourCycle;
10
+ /** Where the units the user leaves out are taken from, and what relative shortcuts count from. Defaults to now. */
11
+ readonly referenceDate?: DateTime;
12
+ /** The earliest date which may be chosen, inclusive. */
13
+ readonly min?: DateTime;
14
+ /** The latest date which may be chosen, inclusive. */
15
+ readonly max?: DateTime;
16
+ readonly dateDisabled?: (date: DateTime) => boolean;
17
+ /** The field's name, appended to every segment's own. */
18
+ readonly label?: string;
19
+ readonly disabled?: boolean;
20
+ readonly readonly?: boolean;
21
+ readonly required?: boolean;
22
+ readonly invalid?: boolean;
23
+ /** Fired while editing, once every unit is filled. */
24
+ handleInput?(value: T | undefined): void;
25
+ /** Fired on commit: leaving the segments, Enter, a shortcut, or a date picked. */
26
+ handleChange?(value: T | undefined): void;
27
+ /** Alt+ArrowDown in the segments, as on a native date input. Left out, the field has no picker. */
28
+ handlePickerOpen?(): void;
29
+ };
30
+ export type FieldDateTimePreset<T> = {
31
+ readonly label: string;
32
+ readonly value: T;
33
+ };
34
+ export type FieldDateTimeControllerOptionsOrFactory<T, THost> = FieldDateTimeControllerOptions<T> | ((host: THost) => FieldDateTimeControllerOptions<T>);
35
+ /** What one group of segments is told beyond what the field tells every group. */
36
+ type SegmentsBinding = Pick<DateTimeSegmentsControllerOptions, 'value' | 'handleInput' | 'handleChange' | 'handleFocusChange' | 'handleMoveBeyond' | 'parseShortcut'>;
37
+ /**
38
+ * What every date field does, whether it holds one date or a range: the groups of segments, where a
39
+ * picker stands and what picking in it means, the presets it offers, and the field's validity.
40
+ *
41
+ * @ssr false
42
+ */
43
+ export declare abstract class FieldDateTimeControllerBase<T, THost extends ReactiveControllerHost = ReactiveControllerHost> extends Controller implements EventListenerObject {
44
+ protected readonly host: THost;
45
+ protected readonly options: FieldDateTimeControllerOptions<T>;
46
+ private customValidity;
47
+ private navigatedValue?;
48
+ private _navigationDate?;
49
+ constructor(host: THost, options: FieldDateTimeControllerOptionsOrFactory<T, THost>);
50
+ /** Every group of segments the field renders, in order. */
51
+ protected abstract get segmentsControllers(): ReadonlyArray<DateTimeSegmentsController<THost>>;
52
+ /** The date a picker marks and scrolls to. */
53
+ abstract get selectedDate(): DateTime | undefined;
54
+ /** The dates a calendar marks. */
55
+ abstract get calendarValue(): DateTimeRange | undefined;
56
+ /** Commits a date chosen in a picker, at the precision it was chosen at: a day in a calendar, or an hour in a list. */
57
+ abstract pick(date: DateTime, precision: FieldDateTimePrecision): void;
58
+ protected abstract datesOf(value: T): ReadonlyArray<DateTime>;
59
+ protected abstract get defaultPresets(): ReadonlyArray<ReadonlyArray<FieldDateTimePreset<T>>>;
60
+ get precision(): FieldDateTimePrecision;
61
+ /** Where a picker stands: at the selected date, until it is scrolled elsewhere, and back there whenever the value changes. */
62
+ get navigationDate(): import("@3mo/date-time").DateTime;
63
+ set navigationDate(value: import("@3mo/date-time").DateTime);
64
+ protected resetNavigationDate(date?: import("@3mo/date-time").DateTime | undefined): void;
65
+ /** The presets a picker offers, in groups, leaving out any the field would refuse. */
66
+ get presets(): ReadonlyArray<ReadonlyArray<FieldDateTimePreset<T>>>;
67
+ /** Whether the field shows anything: a value, or units typed on the way to one. */
68
+ get isPopulated(): boolean;
69
+ private get hasValue();
70
+ /** Whether the value holds a date before `min`, after `max`, or refused by `dateDisabled`. */
71
+ isDisabled(value: T): boolean;
72
+ hostUpdate(): void;
73
+ hostUpdated(): void;
74
+ handleEvent(event: Event): void;
75
+ focus(): void;
76
+ setCustomValidity(message: string): void;
77
+ checkValidity(): boolean;
78
+ protected createSegments(binding: (controller: this) => SegmentsBinding): DateTimeSegmentsController<THost>;
79
+ }
80
+ export {};
81
+ //# sourceMappingURL=FieldDateTimeControllerBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldDateTimeControllerBase.d.ts","sourceRoot":"","sources":["../../date-time/FieldDateTimeControllerBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,sBAAsB,EAAE,MAAM,WAAW,CAAA;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,0BAA0B,EAAE,KAAK,iCAAiC,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAEzH,MAAM,MAAM,8BAA8B,CAAC,CAAC,IAAI;IAC/C,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAClB,4BAA4B;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,sBAAsB,CAAA;IAC3C,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAA;IAC9B,mHAAmH;IACnH,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAA;IACjC,wDAAwD;IACxD,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAA;IACvB,sDAAsD;IACtD,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAA;IACnD,yDAAyD;IACzD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,QAAQ,CA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ments/index.js';
4
+ /**
5
+ * What every date field does, whether it holds one date or a range: the groups of segments, where a
6
+ * picker stands and what picking in it means, the presets it offers, and the field's validity.
7
+ *
8
+ * @ssr false
9
+ */
10
+ export class FieldDateTimeControllerBase extends Controller {
11
+ constructor(host, options) {
12
+ super(host);
13
+ this.host = host;
14
+ this.customValidity = '';
15
+ this.options = typeof options === 'function' ? options(host) : options;
16
+ }
17
+ get precision() {
18
+ return this.options.precision ?? FieldDateTimePrecision.Minute;
19
+ }
20
+ /** Where a picker stands: at the selected date, until it is scrolled elsewhere, and back there whenever the value changes. */
21
+ get navigationDate() {
22
+ return this._navigationDate ??= this.selectedDate ?? new DateTime();
23
+ }
24
+ set navigationDate(value) {
25
+ this._navigationDate = value;
26
+ this.host.requestUpdate();
27
+ }
28
+ resetNavigationDate(date = this.selectedDate) {
29
+ this._navigationDate = date;
30
+ }
31
+ /** The presets a picker offers, in groups, leaving out any the field would refuse. */
32
+ get presets() {
33
+ return this.defaultPresets
34
+ .map(group => group.filter(preset => !this.isDisabled(preset.value)))
35
+ .filter(group => group.length > 0);
36
+ }
37
+ /** Whether the field shows anything: a value, or units typed on the way to one. */
38
+ get isPopulated() {
39
+ return this.hasValue || this.segmentsControllers.some(segments => !segments.isEmpty);
40
+ }
41
+ get hasValue() {
42
+ return this.options.value !== undefined && this.datesOf(this.options.value).length > 0;
43
+ }
44
+ /** Whether the value holds a date before `min`, after `max`, or refused by `dateDisabled`. */
45
+ isDisabled(value) {
46
+ const { min, max, dateDisabled } = this.options;
47
+ const precision = this.precision > FieldDateTimePrecision.Day ? FieldDateTimePrecision.Day : this.precision;
48
+ return this.datesOf(value).some(date => (!!min && precision.isSmallerThan(date, min) && !precision.equals(date, min))
49
+ || (!!max && precision.isSmallerThan(max, date) && !precision.equals(max, date))
50
+ || (dateDisabled?.(date) ?? false));
51
+ }
52
+ hostUpdate() {
53
+ if (this.options.value !== this.navigatedValue) {
54
+ this.navigatedValue = this.options.value;
55
+ this.resetNavigationDate();
56
+ }
57
+ }
58
+ // Idempotent for one and the same listener, so re-declaring it on every update costs nothing.
59
+ hostUpdated() {
60
+ for (const segments of this.segmentsControllers) {
61
+ segments.group.value?.addEventListener('keydown', this);
62
+ }
63
+ }
64
+ handleEvent(event) {
65
+ const { key, altKey } = event;
66
+ if (altKey && key === 'ArrowDown' && this.options.handlePickerOpen) {
67
+ event.preventDefault();
68
+ this.options.handlePickerOpen();
69
+ }
70
+ }
71
+ focus() {
72
+ this.segmentsControllers[0]?.focus();
73
+ }
74
+ setCustomValidity(message) {
75
+ this.customValidity = message;
76
+ }
77
+ checkValidity() {
78
+ const { value, required } = this.options;
79
+ return !this.customValidity
80
+ && !(required && !this.hasValue)
81
+ && !(value !== undefined && this.isDisabled(value));
82
+ }
83
+ createSegments(binding) {
84
+ const controller = this;
85
+ const bound = binding(this);
86
+ return new DateTimeSegmentsController(this.host, {
87
+ get value() { return bound.value; },
88
+ get precision() { return controller.precision; },
89
+ get referenceDate() { return controller.options.referenceDate; },
90
+ get hourCycle() { return controller.options.hourCycle; },
91
+ get label() { return controller.options.label; },
92
+ get disabled() { return controller.options.disabled; },
93
+ get readonly() { return controller.options.readonly; },
94
+ get required() { return controller.options.required; },
95
+ get invalid() { return controller.options.invalid; },
96
+ handleInput: bound.handleInput,
97
+ handleChange: bound.handleChange,
98
+ handleFocusChange: bound.handleFocusChange,
99
+ handleMoveBeyond: bound.handleMoveBeyond,
100
+ parseShortcut: bound.parseShortcut,
101
+ });
102
+ }
103
+ }
@@ -0,0 +1,5 @@
1
+ export * from './FieldDateTimeControllerBase.js';
2
+ export * from './FieldDateTimeController.js';
3
+ export * from './FieldDateTime.js';
4
+ export * from './FieldDate.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../date-time/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAC5C,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './FieldDateTimeControllerBase.js';
2
+ export * from './FieldDateTimeController.js';
3
+ export * from './FieldDateTime.js';
4
+ export * from './FieldDate.js';
@@ -1,7 +1,7 @@
1
1
  export declare class DateRangeParser {
2
2
  static readonly dateRangeSeparator = " \u2013 ";
3
3
  static readonly userDateRangeSeparators: string[];
4
- static parse(dateRangeText: string, referenceDate?: import("@3mo/date-time/DateTime.js").DateTime): import("@3mo/date-time/DateTimeRange.js").DateTimeRange;
4
+ static parse(dateRangeText: string, referenceDate?: import("@3mo/date-time").DateTime): import("@3mo/date-time").DateTimeRange;
5
5
  private static parseDateRangeFromKeyword;
6
6
  }
7
7
  //# sourceMappingURL=DateRangeParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DateRangeParser.d.ts","sourceRoot":"","sources":["../../date-time-range/DateRangeParser.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAe;IAC3B,MAAM,CAAC,QAAQ,CAAC,kBAAkB,cAAQ;IAC1C,MAAM,CAAC,QAAQ,CAAC,uBAAuB,WAAsD;IAE7F,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,MAAM,EAAE,aAAa,oCAAe;IAqBhE,OAAO,CAAC,MAAM,CAAC,yBAAyB;CAiBxC"}
@@ -0,0 +1,20 @@
1
+ import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
2
+ import { FieldDateTimeRange } from './FieldDateTimeRange.js';
3
+ /**
4
+ * A date range field, with segments for each end and a calendar that picks the start and then the end.
5
+ *
6
+ * @element mo-field-date-range
7
+ *
8
+ * @accessibility
9
+ * The segments follow the [segmented input](?path=/docs/behaviors-segmented-input--overview): a `group` named after the `label`, with one `spinbutton` per part, and one tab stop for the group. `aria-invalid`, `aria-required` and `aria-readonly` follow the field.
10
+ * `Alt` `ArrowDown` opens the picker. The picker's calendar cannot be operated with the keyboard yet, so the segments are the keyboard's way in.
11
+ */
12
+ export declare class FieldDateRange extends FieldDateTimeRange {
13
+ precision: FieldDateTimePrecision;
14
+ }
15
+ declare global {
16
+ interface HTMLElementTagNameMap {
17
+ 'mo-field-date-range': FieldDateRange;
18
+ }
19
+ }
20
+ //# sourceMappingURL=FieldDateRange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldDateRange.d.ts","sourceRoot":"","sources":["../../date-time-range/FieldDateRange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D;;;;;;;;GAQG;AACH,qBACa,cAAe,SAAQ,kBAAkB;IAC5C,SAAS,yBAA6B;CAC/C;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,qBAAqB,EAAE,cAAc,CAAA;KACrC;CACD"}
@@ -0,0 +1,23 @@
1
+ import { __decorate } from "tslib";
2
+ import { component } from '@a11d/lit';
3
+ import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
4
+ import { FieldDateTimeRange } from './FieldDateTimeRange.js';
5
+ /**
6
+ * A date range field, with segments for each end and a calendar that picks the start and then the end.
7
+ *
8
+ * @element mo-field-date-range
9
+ *
10
+ * @accessibility
11
+ * The segments follow the [segmented input](?path=/docs/behaviors-segmented-input--overview): a `group` named after the `label`, with one `spinbutton` per part, and one tab stop for the group. `aria-invalid`, `aria-required` and `aria-readonly` follow the field.
12
+ * `Alt` `ArrowDown` opens the picker. The picker's calendar cannot be operated with the keyboard yet, so the segments are the keyboard's way in.
13
+ */
14
+ let FieldDateRange = class FieldDateRange extends FieldDateTimeRange {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.precision = FieldDateTimePrecision.Day;
18
+ }
19
+ };
20
+ FieldDateRange = __decorate([
21
+ component('mo-field-date-range')
22
+ ], FieldDateRange);
23
+ export { FieldDateRange };
@@ -0,0 +1,49 @@
1
+ import { type MaterialIcon } from '@3mo/icon';
2
+ import { FieldDateTimeBase } from '../date-time/FieldDateTimeBase.js';
3
+ import { FieldDateTimeRangeController } from './FieldDateTimeRangeController.js';
4
+ /**
5
+ * A date and time range field, with segments for each end and a picker that edits one end at a time.
6
+ *
7
+ * Its behaviour is {@link FieldDateTimeRangeController}, for a date range field of another design.
8
+ *
9
+ * @element mo-field-date-time-range
10
+ *
11
+ * @attr value - The selected date range.
12
+ *
13
+ * @csspart segments-range - Both ends' segments and the delimiter between them
14
+ *
15
+ * @i18n "Period"
16
+ * @i18n "Start"
17
+ * @i18n "End"
18
+ * @i18n "Last ${count:number} days"
19
+ * @i18n "Last week"
20
+ * @i18n "This week"
21
+ * @i18n "Next week"
22
+ * @i18n "Last month"
23
+ * @i18n "This month"
24
+ * @i18n "Next month"
25
+ * @i18n "Last year"
26
+ * @i18n "This year"
27
+ * @i18n "Next year"
28
+ *
29
+ * @accessibility
30
+ * The segments follow the [segmented input](?path=/docs/behaviors-segmented-input--overview): a `group` named after the `label`, with one `spinbutton` per part, and one tab stop for the group. `aria-invalid`, `aria-required` and `aria-readonly` follow the field.
31
+ * `Alt` `ArrowDown` opens the picker. The picker's calendar cannot be operated with the keyboard yet, so the segments are the keyboard's way in.
32
+ */
33
+ export declare class FieldDateTimeRange extends FieldDateTimeBase<DateTimeRange | undefined> {
34
+ value?: DateTimeRange;
35
+ readonly controller: FieldDateTimeRangeController<this>;
36
+ protected get segmentsTemplate(): import("lit-html").HTMLTemplateResult;
37
+ protected get _label(): string;
38
+ static get styles(): import("@a11d/lit").CSSResult;
39
+ protected calendarIconButtonIcon: MaterialIcon;
40
+ protected get popoverSelectionTemplate(): import("lit-html").HTMLTemplateResult;
41
+ protected get popoverToolbarTemplate(): import("lit-html").HTMLTemplateResult;
42
+ private get startEndTabBarTemplate();
43
+ }
44
+ declare global {
45
+ interface HTMLElementTagNameMap {
46
+ 'mo-field-date-time-range': FieldDateTimeRange;
47
+ }
48
+ }
49
+ //# sourceMappingURL=FieldDateTimeRange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldDateTimeRange.d.ts","sourceRoot":"","sources":["../../date-time-range/FieldDateTimeRange.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAA;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,4BAA4B,EAAoC,MAAM,mCAAmC,CAAA;AAQlH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBACa,kBAAmB,SAAQ,iBAAiB,CAAC,aAAa,GAAG,SAAS,CAAC;IACvD,KAAK,CAAC,EAAE,aAAa,CAAA;IAEjD,QAAQ,CAAC,UAAU,qCAAiE;IAEpF,SAAS,KAAK,gBAAgB,0CAQ7B;IAED,cAAuB,MAAM,WAE5B;IAED,WAAoB,MAAM,kCAmBzB;IAED,UAAmB,sBAAsB,EAAE,YAAY,CAAe;IAEtE,cAAuB,wBAAwB,0CAO9C;IAED,SAAS,KAAK,sBAAsB,0CAInC;IAED,OAAO,KAAK,sBAAsB,GASjC;CACD;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,0BAA0B,EAAE,kBAAkB,CAAA;KAC9C;CACD"}
@@ -0,0 +1,108 @@
1
+ import { __decorate } from "tslib";
2
+ import { component, css, html, property } from '@a11d/lit';
3
+ import { Localizer } from '@3mo/localization';
4
+ import { FieldDateTimeBase } from '../date-time/FieldDateTimeBase.js';
5
+ import { FieldDateTimeRangeController } from './FieldDateTimeRangeController.js';
6
+ Localizer.dictionaries.add('de', {
7
+ 'Period': 'Zeitraum',
8
+ 'Start': 'Start',
9
+ 'End': 'Ende',
10
+ });
11
+ /**
12
+ * A date and time range field, with segments for each end and a picker that edits one end at a time.
13
+ *
14
+ * Its behaviour is {@link FieldDateTimeRangeController}, for a date range field of another design.
15
+ *
16
+ * @element mo-field-date-time-range
17
+ *
18
+ * @attr value - The selected date range.
19
+ *
20
+ * @csspart segments-range - Both ends' segments and the delimiter between them
21
+ *
22
+ * @i18n "Period"
23
+ * @i18n "Start"
24
+ * @i18n "End"
25
+ * @i18n "Last ${count:number} days"
26
+ * @i18n "Last week"
27
+ * @i18n "This week"
28
+ * @i18n "Next week"
29
+ * @i18n "Last month"
30
+ * @i18n "This month"
31
+ * @i18n "Next month"
32
+ * @i18n "Last year"
33
+ * @i18n "This year"
34
+ * @i18n "Next year"
35
+ *
36
+ * @accessibility
37
+ * The segments follow the [segmented input](?path=/docs/behaviors-segmented-input--overview): a `group` named after the `label`, with one `spinbutton` per part, and one tab stop for the group. `aria-invalid`, `aria-required` and `aria-readonly` follow the field.
38
+ * `Alt` `ArrowDown` opens the picker. The picker's calendar cannot be operated with the keyboard yet, so the segments are the keyboard's way in.
39
+ */
40
+ let FieldDateTimeRange = class FieldDateTimeRange extends FieldDateTimeBase {
41
+ constructor() {
42
+ super(...arguments);
43
+ this.controller = new FieldDateTimeRangeController(this, this.controllerOptions);
44
+ this.calendarIconButtonIcon = 'date_range';
45
+ }
46
+ get segmentsTemplate() {
47
+ return html `
48
+ <div part='segments-range' dir=${this.controller.startSegments.segmenter.direction}>
49
+ ${this.getSegmentsTemplate(this.controller.startSegments, 'start')}
50
+ <span part='literal' aria-hidden='true'> ${DateTimeRange.getUntilDelimiter()} </span>
51
+ ${this.getSegmentsTemplate(this.controller.endSegments, 'end')}
52
+ </div>
53
+ `;
54
+ }
55
+ get _label() {
56
+ return super._label || t('Period');
57
+ }
58
+ static get styles() {
59
+ return css `
60
+ ${super.styles}
61
+
62
+ mo-tab-bar {
63
+ max-width: 200px;
64
+ place-self: center;
65
+ padding-block: 4px;
66
+ mo-tab {
67
+ &:not([active]) {
68
+ opacity: 0.5;
69
+ }
70
+ }
71
+ }
72
+
73
+ #selector {
74
+ flex: none !important;
75
+ }
76
+ `;
77
+ }
78
+ get popoverSelectionTemplate() {
79
+ return html `
80
+ <mo-flex style='flex: 1'>
81
+ ${this.popoverToolbarTemplate}
82
+ ${super.popoverSelectionTemplate}
83
+ </mo-flex>
84
+ `;
85
+ }
86
+ get popoverToolbarTemplate() {
87
+ return html `
88
+ ${this.startEndTabBarTemplate}
89
+ `;
90
+ }
91
+ get startEndTabBarTemplate() {
92
+ return html `
93
+ <mo-flex style='border-inline-start: 1px solid var(--mo-color-transparent-gray-3)'>
94
+ <mo-tab-bar .value=${this.controller.selection} @change=${(e) => this.controller.selection = e.detail}>
95
+ <mo-tab value='start'>${t('Start')}</mo-tab>
96
+ <mo-tab value='end'>${t('End')}</mo-tab>
97
+ </mo-tab-bar>
98
+ </mo-flex>
99
+ `;
100
+ }
101
+ };
102
+ __decorate([
103
+ property({ type: Object })
104
+ ], FieldDateTimeRange.prototype, "value", void 0);
105
+ FieldDateTimeRange = __decorate([
106
+ component('mo-field-date-time-range')
107
+ ], FieldDateTimeRange);
108
+ export { FieldDateTimeRange };
@@ -0,0 +1,44 @@
1
+ import { type ReactiveControllerHost } from '@a11d/lit';
2
+ import { FieldDateTimeControllerBase, type FieldDateTimePreset } from '../date-time/FieldDateTimeControllerBase.js';
3
+ import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
4
+ /** The end of the range a picker edits. */
5
+ export type FieldDateTimeRangeSelection = 'start' | 'end';
6
+ /**
7
+ * Everything a date range field does, for a host which only renders it: a group of segments for
8
+ * each end with the arrow keys crossing between them, the end a picker edits, range shortcuts, the
9
+ * presets, and the validity.
10
+ *
11
+ * ```html
12
+ * <div ${this.controller.startSegments.group.ref()}>
13
+ * ${this.controller.startSegments.segments.map(segment => html`<span ${this.controller.startSegments.segment.ref(segment)}></span>`)}
14
+ * </div>
15
+ * <div ${this.controller.endSegments.group.ref()}>…</div>
16
+ * ```
17
+ *
18
+ * A picker is the host's to render: it opens on `handlePickerOpen`, edits the `selection` end, scrolls
19
+ * with `navigationDate`, marks `calendarValue`, and hands what was chosen to `pick`. Picking an end at
20
+ * the field's precision moves the selection on to the other end.
21
+ *
22
+ * @ssr false
23
+ */
24
+ export declare class FieldDateTimeRangeController<THost extends ReactiveControllerHost = ReactiveControllerHost> extends FieldDateTimeControllerBase<DateTimeRange, THost> {
25
+ private _selection;
26
+ readonly startSegments: import("../index.js").DateTimeSegmentsController<THost>;
27
+ readonly endSegments: import("../index.js").DateTimeSegmentsController<THost>;
28
+ /** The end a picker edits. Entering an end's segments selects it. */
29
+ get selection(): FieldDateTimeRangeSelection;
30
+ set selection(value: FieldDateTimeRangeSelection);
31
+ protected get segmentsControllers(): import("../index.js").DateTimeSegmentsController<THost>[];
32
+ get selectedDate(): import("@3mo/date-time").DateTime | undefined;
33
+ get calendarValue(): import("@3mo/date-time").DateTimeRange | undefined;
34
+ /** An end without a date leaves the picker where it stands. */
35
+ protected resetNavigationDate(): void;
36
+ /** A picked day keeps the time the picker stands at; the start begins the precision's unit and the end ends it. */
37
+ pick(date: DateTime, precision: FieldDateTimePrecision): void;
38
+ private withEnd;
39
+ /** Range keywords ("m", "lw") set both ends at once; anything else resolves to the focused end. */
40
+ private parseShortcut;
41
+ protected datesOf(value: DateTimeRange): import("@3mo/date-time").DateTime[];
42
+ protected get defaultPresets(): ReadonlyArray<ReadonlyArray<FieldDateTimePreset<DateTimeRange>>>;
43
+ }
44
+ //# sourceMappingURL=FieldDateTimeRangeController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldDateTimeRangeController.d.ts","sourceRoot":"","sources":["../../date-time-range/FieldDateTimeRangeController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAEvD,OAAO,EAAE,2BAA2B,EAAE,KAAK,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AACnH,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAgBrE,2CAA2C;AAC3C,MAAM,MAAM,2BAA2B,GAAG,OAAO,GAAG,KAAK,CAAA;AAEzD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,4BAA4B,CAAC,KAAK,SAAS,sBAAsB,GAAG,sBAAsB,CAAE,SAAQ,2BAA2B,CAAC,aAAa,EAAE,KAAK,CAAC;IACjK,OAAO,CAAC,UAAU,CAAuC;IAEzD,QAAQ,CAAC,aAAa,0DAOnB;IAEH,QAAQ,CAAC,WAAW,0DAOjB;IAEH,qEAAqE;IACrE,IAAI,SAAS,gCAEZ;IAED,IAAI,SAAS,CAAC,KAAK,6BAAA,EAMlB;IAED,SAAS,KAAK,mBAAmB,8DAEhC;IAED,IAAI,YAAY,kDAEf;IAED,IAAI,aAAa,uDAEhB;IAED,+DAA+D;cAC5C,mBAAmB;IAItC,mHAAmH;IACnH,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,sBAAsB;IAYtD,OAAO,CAAC,OAAO;IAMf,mGAAmG;IACnG,OAAO,CAAC,aAAa;IASrB,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,aAAa;IAItC,SAAS,KAAK,cAAc,IAAI,aAAa,CAAC,aAAa,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC,CAAC,CAuB/F;CACD"}