@3mo/date-time-fields 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FieldDateTimePrecision.d.ts.map +1 -1
- package/dist/FieldDateTimePrecision.js +0 -1
- package/dist/custom-elements.json +993 -1154
- package/dist/{FieldDate.d.ts → date-time/FieldDate.d.ts} +1 -1
- package/dist/date-time/FieldDate.d.ts.map +1 -0
- package/dist/{FieldDate.js → date-time/FieldDate.js} +1 -1
- package/dist/date-time/FieldDateTime.d.ts +36 -0
- package/dist/date-time/FieldDateTime.d.ts.map +1 -0
- package/dist/date-time/FieldDateTime.js +61 -0
- package/dist/{FieldDateTimeBase.d.ts → date-time/FieldDateTimeBase.d.ts} +30 -22
- package/dist/date-time/FieldDateTimeBase.d.ts.map +1 -0
- package/dist/{FieldDateTimeBase.js → date-time/FieldDateTimeBase.js} +103 -105
- package/dist/date-time/FieldDateTimeController.d.ts +30 -0
- package/dist/date-time/FieldDateTimeController.d.ts.map +1 -0
- package/dist/date-time/FieldDateTimeController.js +87 -0
- package/dist/date-time/FieldDateTimeControllerBase.d.ts +81 -0
- package/dist/date-time/FieldDateTimeControllerBase.d.ts.map +1 -0
- package/dist/date-time/FieldDateTimeControllerBase.js +103 -0
- package/dist/date-time/index.d.ts +5 -0
- package/dist/date-time/index.d.ts.map +1 -0
- package/dist/date-time/index.js +4 -0
- package/dist/date-time-range/DateRangeParser.d.ts.map +1 -0
- package/dist/{FieldDateRange.d.ts → date-time-range/FieldDateRange.d.ts} +1 -1
- package/dist/date-time-range/FieldDateRange.d.ts.map +1 -0
- package/dist/{FieldDateRange.js → date-time-range/FieldDateRange.js} +1 -1
- package/dist/date-time-range/FieldDateTimeRange.d.ts +41 -0
- package/dist/date-time-range/FieldDateTimeRange.d.ts.map +1 -0
- package/dist/date-time-range/FieldDateTimeRange.js +100 -0
- package/dist/date-time-range/FieldDateTimeRangeController.d.ts +44 -0
- package/dist/date-time-range/FieldDateTimeRangeController.d.ts.map +1 -0
- package/dist/date-time-range/FieldDateTimeRangeController.js +137 -0
- package/dist/{FieldToggleableDateTimeRange.d.ts → date-time-range/FieldToggleableDateTimeRange.d.ts} +1 -1
- package/dist/date-time-range/FieldToggleableDateTimeRange.d.ts.map +1 -0
- package/dist/{FieldToggleableDateTimeRange.js → date-time-range/FieldToggleableDateTimeRange.js} +1 -1
- package/dist/date-time-range/index.d.ts +5 -0
- package/dist/date-time-range/index.d.ts.map +1 -0
- package/dist/date-time-range/index.js +4 -0
- package/dist/dateTimeConverter.d.ts +2 -0
- package/dist/dateTimeConverter.d.ts.map +1 -0
- package/dist/dateTimeConverter.js +10 -0
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -6
- package/dist/selection/Calendar.d.ts.map +1 -1
- package/dist/selection/Calendar.js +4 -3
- package/dist/{FieldTime.d.ts → time/FieldTime.d.ts} +6 -12
- package/dist/time/FieldTime.d.ts.map +1 -0
- package/dist/{FieldTime.js → time/FieldTime.js} +25 -69
- package/dist/time/FieldTimeController.d.ts +72 -0
- package/dist/time/FieldTimeController.d.ts.map +1 -0
- package/dist/time/FieldTimeController.js +110 -0
- package/dist/time/index.d.ts +3 -0
- package/dist/time/index.d.ts.map +1 -0
- package/dist/time/index.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/DateRangeParser.d.ts.map +0 -1
- package/dist/FieldDate.d.ts.map +0 -1
- package/dist/FieldDateRange.d.ts.map +0 -1
- package/dist/FieldDateTime.d.ts +0 -40
- package/dist/FieldDateTime.d.ts.map +0 -1
- package/dist/FieldDateTime.js +0 -109
- package/dist/FieldDateTimeBase.d.ts.map +0 -1
- package/dist/FieldDateTimeRange.d.ts +0 -53
- package/dist/FieldDateTimeRange.d.ts.map +0 -1
- package/dist/FieldDateTimeRange.js +0 -167
- package/dist/FieldTime.d.ts.map +0 -1
- package/dist/FieldToggleableDateTimeRange.d.ts.map +0 -1
- /package/dist/{DateRangeParser.d.ts → date-time-range/DateRangeParser.d.ts} +0 -0
- /package/dist/{DateRangeParser.js → date-time-range/DateRangeParser.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldToggleableDateTimeRange.d.ts","sourceRoot":"","sources":["../../date-time-range/FieldToggleableDateTimeRange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAMrE;;;;GAIG;AACH,qBACa,4BAA6B,SAAQ,kBAAkB;IAC1D,SAAS,yBAA6B;IAE/C,IAAI,WAAW,YAA8D;IAC7E,IAAI,WAAW,CAAC,WAAW,SAAA,EAA+F;IAE1H,cAAuB,sBAAsB,0CAO5C;IAED,OAAO,KAAK,cAAc,GAIzB;CACD"}
|
package/dist/{FieldToggleableDateTimeRange.js → date-time-range/FieldToggleableDateTimeRange.js}
RENAMED
|
@@ -2,7 +2,7 @@ import { __decorate } from "tslib";
|
|
|
2
2
|
import { bind, component, html } from '@a11d/lit';
|
|
3
3
|
import { Localizer } from '@3mo/localization';
|
|
4
4
|
import { FieldDateTimeRange } from './FieldDateTimeRange.js';
|
|
5
|
-
import { FieldDateTimePrecision } from '
|
|
5
|
+
import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
|
|
6
6
|
Localizer.dictionaries.add('de', {
|
|
7
7
|
'Include time': 'Zeitauswahl',
|
|
8
8
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../date-time-range/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA;AACjD,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mCAAmC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateTimeConverter.d.ts","sourceRoot":"","sources":["../dateTimeConverter.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,GAAI,OAAO,OAAO,8DAW/C,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const dateTimeConverter = (value) => {
|
|
2
|
+
if (value instanceof DateTime) {
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
5
|
+
if (value instanceof Date || typeof value === 'string' || typeof value === 'number') {
|
|
6
|
+
const date = new DateTime(value);
|
|
7
|
+
return isNaN(date.getTime()) ? undefined : date;
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -12,11 +12,8 @@ import '@3mo/line';
|
|
|
12
12
|
import '@3mo/switch';
|
|
13
13
|
export * from './segments/index.js';
|
|
14
14
|
export * from './selection/index.js';
|
|
15
|
-
export * from './FieldTime.js';
|
|
16
15
|
export * from './FieldDateTimePrecision.js';
|
|
17
|
-
export * from './
|
|
18
|
-
export * from './
|
|
19
|
-
export * from './
|
|
20
|
-
export * from './FieldDate.js';
|
|
21
|
-
export * from './FieldToggleableDateTimeRange.js';
|
|
16
|
+
export * from './time/index.js';
|
|
17
|
+
export * from './date-time/index.js';
|
|
18
|
+
export * from './date-time-range/index.js';
|
|
22
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAA;AACvB,OAAO,WAAW,CAAA;AAClB,OAAO,kBAAkB,CAAA;AACzB,OAAO,cAAc,CAAA;AACrB,OAAO,WAAW,CAAA;AAClB,OAAO,WAAW,CAAA;AAClB,OAAO,YAAY,CAAA;AACnB,OAAO,UAAU,CAAA;AACjB,OAAO,eAAe,CAAA;AACtB,OAAO,WAAW,CAAA;AAClB,OAAO,WAAW,CAAA;AAClB,OAAO,aAAa,CAAA;AACpB,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAA;AACvB,OAAO,WAAW,CAAA;AAClB,OAAO,kBAAkB,CAAA;AACzB,OAAO,cAAc,CAAA;AACrB,OAAO,WAAW,CAAA;AAClB,OAAO,WAAW,CAAA;AAClB,OAAO,YAAY,CAAA;AACnB,OAAO,UAAU,CAAA;AACjB,OAAO,eAAe,CAAA;AACtB,OAAO,WAAW,CAAA;AAClB,OAAO,WAAW,CAAA;AAClB,OAAO,aAAa,CAAA;AACpB,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA;AACpC,cAAc,4BAA4B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -12,10 +12,7 @@ import '@3mo/line';
|
|
|
12
12
|
import '@3mo/switch';
|
|
13
13
|
export * from './segments/index.js';
|
|
14
14
|
export * from './selection/index.js';
|
|
15
|
-
export * from './FieldTime.js';
|
|
16
15
|
export * from './FieldDateTimePrecision.js';
|
|
17
|
-
export * from './
|
|
18
|
-
export * from './
|
|
19
|
-
export * from './
|
|
20
|
-
export * from './FieldDate.js';
|
|
21
|
-
export * from './FieldToggleableDateTimeRange.js';
|
|
16
|
+
export * from './time/index.js';
|
|
17
|
+
export * from './date-time/index.js';
|
|
18
|
+
export * from './date-time-range/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calendar.d.ts","sourceRoot":"","sources":["../../selection/Calendar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmE,MAAM,WAAW,CAAA;AAGtG,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAErE;;GAEG;AACH,qBACa,QA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,kDAAiD;IAC7D,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,GAAE,SAAS,GAAG,QAAoB;IAcnF,WAAoB,MAAM,kCAyKzB;IAED,OAAO,KAAK,iBAAiB,GAE5B;IAED,OAAO,KAAK,OAAO,GAKlB;IAED,OAAO,CAAC,aAAa;IAIrB,cAAuB,QAAQ,0CAM9B;IAED,OAAO,CAAC,eAAe;IAsBvB,OAAO,CAAC,MAAM,KAAK,gBAAgB,GAiBlC;IAED,OAAO,CAAC,gBAAgB;IA0BxB,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC;IA0BxE,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,eAAe,CAmBtB;IAED,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,SAAS;CAKjB;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,aAAa,EAAE,QAAQ,CAAA;KACvB;CACD"}
|
|
@@ -108,13 +108,14 @@ let Calendar = Calendar_1 = class Calendar extends Component {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
&[data-start], &[data-end] {
|
|
111
|
-
background: var(--mo-color-accent-transparent);
|
|
112
111
|
opacity: 1;
|
|
113
|
-
|
|
112
|
+
background: var(--mo-color-selected);
|
|
113
|
+
color: var(--mo-color-on-selected);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
&[data-in-range] {
|
|
117
|
-
background: color-mix(in srgb, var(--mo-color-
|
|
117
|
+
background: color-mix(in srgb, var(--mo-color-selected), transparent 42%);
|
|
118
|
+
border-radius: initial;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
&[data-disabled] {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { FieldComponent } from '@3mo/field';
|
|
2
|
-
import { FieldDateTimePrecision } from '
|
|
3
|
-
import {
|
|
2
|
+
import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
|
|
3
|
+
import { FieldTimeController } from './FieldTimeController.js';
|
|
4
|
+
import { type HourCycle } from '../segments/index.js';
|
|
4
5
|
/**
|
|
5
6
|
* A time-of-day field. Its value is the 24-hour `HH:mm` (or `HH:mm:ss` at second precision) string the
|
|
6
7
|
* native time input uses, so that it drops in where one was, while the segments follow the language's
|
|
7
8
|
* own clock — "02:07 PM" for English, "14:07" for German — and the popover offers the hour and minute wheels.
|
|
8
9
|
*
|
|
10
|
+
* Its behaviour is {@link FieldTimeController}, for a time field of another design.
|
|
11
|
+
*
|
|
9
12
|
* @element mo-field-time
|
|
10
13
|
*
|
|
11
14
|
* @attr value - The time as `HH:mm` or `HH:mm:ss`
|
|
@@ -31,19 +34,11 @@ export declare class FieldTime extends FieldComponent<string> {
|
|
|
31
34
|
precision: FieldDateTimePrecision;
|
|
32
35
|
hourCycle?: HourCycle;
|
|
33
36
|
shortcutReferenceDate: import("@3mo/date-time/DateTime.js").DateTime;
|
|
34
|
-
|
|
35
|
-
readonly segments: DateTimeSegmentsController<this>;
|
|
36
|
-
/** Alt+ArrowDown opens the picker, as it does on a native date-time input. */
|
|
37
|
-
protected handlePickerKey(event: KeyboardEvent): void;
|
|
38
|
-
/** The value as a time on the reference day, which is all the segments need to render and edit it. */
|
|
39
|
-
get selectedDate(): DateTime | undefined;
|
|
40
|
-
protected toValue(date: DateTime | undefined): string | undefined;
|
|
41
|
-
protected valueUpdated(): void;
|
|
37
|
+
readonly controller: FieldTimeController<this>;
|
|
42
38
|
protected get isActive(): boolean;
|
|
43
39
|
protected get isDense(): boolean;
|
|
44
40
|
protected get isPopulated(): boolean;
|
|
45
41
|
focus(): void;
|
|
46
|
-
private customValidity;
|
|
47
42
|
setCustomValidity(error: string): void;
|
|
48
43
|
checkValidity(): Promise<boolean>;
|
|
49
44
|
reportValidity(): void;
|
|
@@ -52,7 +47,6 @@ export declare class FieldTime extends FieldComponent<string> {
|
|
|
52
47
|
protected get inputTemplate(): import("lit-html").HTMLTemplateResult;
|
|
53
48
|
protected get endSlotTemplate(): import("lit-html").HTMLTemplateResult;
|
|
54
49
|
protected get popoverTemplate(): import("lit-html").HTMLTemplateResult;
|
|
55
|
-
private handleListChange;
|
|
56
50
|
}
|
|
57
51
|
declare global {
|
|
58
52
|
interface HTMLElementTagNameMap {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldTime.d.ts","sourceRoot":"","sources":["../../time/FieldTime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAErE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAMzF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBACa,SAAU,SAAQ,cAAc,CAAC,MAAM,CAAC;IAC/B,KAAK,SAAY;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAA;IACkB,IAAI,UAAQ;IAC3B,YAAY,UAAQ;IACpB,KAAK,UAAQ;IACwD,SAAS,yBAAgC;IAChF,SAAS,CAAC,EAAE,SAAS,CAAA;IACtB,qBAAqB,gDAAiB;IAEhG,QAAQ,CAAC,UAAU,4BAahB;IAEH,cAAuB,QAAQ,YAE9B;IAED,cAAuB,OAAO,YAE7B;IAED,cAAuB,WAAW,YAEjC;IAEQ,KAAK;IAIL,iBAAiB,CAAC,KAAK,EAAE,MAAM;IAIzB,aAAa;IAKnB,cAAc;IAIvB,WAAoB,MAAM,kCAgCzB;IAED,cAAuB,QAAQ,0CAK9B;IAED,cAAuB,aAAa,0CAMnC;IAED,cAAuB,eAAe,0CASrC;IAED,SAAS,KAAK,eAAe,0CAiB5B;CACD;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,eAAe,EAAE,SAAS,CAAA;KAC1B;CACD"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { bind, cache, component, css, html, property,
|
|
2
|
+
import { bind, cache, component, css, html, property, style } from '@a11d/lit';
|
|
3
3
|
import { FieldComponent } from '@3mo/field';
|
|
4
4
|
import { Localizer } from '@3mo/localization';
|
|
5
|
-
import { FieldDateTimePrecision } from '
|
|
6
|
-
import { dateTimeConverter } from '
|
|
7
|
-
import {
|
|
5
|
+
import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
|
|
6
|
+
import { dateTimeConverter } from '../dateTimeConverter.js';
|
|
7
|
+
import { FieldTimeController } from './FieldTimeController.js';
|
|
8
|
+
import { hourCycleConverter, segmentsStyles } from '../segments/index.js';
|
|
8
9
|
Localizer.dictionaries.add('de', {
|
|
9
10
|
'Time': 'Uhrzeit',
|
|
10
11
|
});
|
|
11
|
-
const timePattern = /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/;
|
|
12
12
|
/**
|
|
13
13
|
* A time-of-day field. Its value is the 24-hour `HH:mm` (or `HH:mm:ss` at second precision) string the
|
|
14
14
|
* native time input uses, so that it drops in where one was, while the segments follow the language's
|
|
15
15
|
* own clock — "02:07 PM" for English, "14:07" for German — and the popover offers the hour and minute wheels.
|
|
16
16
|
*
|
|
17
|
+
* Its behaviour is {@link FieldTimeController}, for a time field of another design.
|
|
18
|
+
*
|
|
17
19
|
* @element mo-field-time
|
|
18
20
|
*
|
|
19
21
|
* @attr value - The time as `HH:mm` or `HH:mm:ss`
|
|
@@ -39,50 +41,20 @@ let FieldTime = class FieldTime extends FieldComponent {
|
|
|
39
41
|
this.dense = false;
|
|
40
42
|
this.precision = FieldDateTimePrecision.Minute;
|
|
41
43
|
this.shortcutReferenceDate = new DateTime();
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
timeOnly: true,
|
|
45
|
-
get value() { return host.selectedDate; },
|
|
44
|
+
this.controller = new FieldTimeController(this, host => ({
|
|
45
|
+
get value() { return host.value; },
|
|
46
46
|
get precision() { return host.precision; },
|
|
47
|
-
get referenceDate() { return host.shortcutReferenceDate; },
|
|
48
47
|
get hourCycle() { return host.hourCycle; },
|
|
48
|
+
get referenceDate() { return host.shortcutReferenceDate; },
|
|
49
49
|
get label() { return host._label; },
|
|
50
50
|
get disabled() { return host.disabled; },
|
|
51
51
|
get readonly() { return host.readonly; },
|
|
52
52
|
get required() { return host.required; },
|
|
53
53
|
get invalid() { return host.invalid; },
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
get handlePickerOpen() { return host.pickerHidden ? undefined : () => host.open = true; },
|
|
55
|
+
handleInput: value => host.handleInput(value),
|
|
56
|
+
handleChange: value => host.handleChange(value),
|
|
56
57
|
}));
|
|
57
|
-
this.customValidity = '';
|
|
58
|
-
}
|
|
59
|
-
/** Alt+ArrowDown opens the picker, as it does on a native date-time input. */
|
|
60
|
-
handlePickerKey(event) {
|
|
61
|
-
if (event.altKey && event.key === 'ArrowDown' && !this.pickerHidden) {
|
|
62
|
-
event.preventDefault();
|
|
63
|
-
this.open = true;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/** The value as a time on the reference day, which is all the segments need to render and edit it. */
|
|
67
|
-
get selectedDate() {
|
|
68
|
-
const match = this.value?.match(timePattern);
|
|
69
|
-
if (!match) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
const [, hour, minute, second] = match.map(Number);
|
|
73
|
-
return this.shortcutReferenceDate.dayStart.with({ hour, minute, second: second || 0 });
|
|
74
|
-
}
|
|
75
|
-
toValue(date) {
|
|
76
|
-
if (!date) {
|
|
77
|
-
return undefined;
|
|
78
|
-
}
|
|
79
|
-
const pad = (value) => String(value).padStart(2, '0');
|
|
80
|
-
const time = `${pad(date.hour)}:${pad(date.minute)}`;
|
|
81
|
-
return this.precision >= FieldDateTimePrecision.Second ? `${time}:${pad(date.second)}` : time;
|
|
82
|
-
}
|
|
83
|
-
valueUpdated() {
|
|
84
|
-
super.valueUpdated();
|
|
85
|
-
this.navigationDate = this.selectedDate ?? new DateTime();
|
|
86
58
|
}
|
|
87
59
|
get isActive() {
|
|
88
60
|
return super.isActive || this.open;
|
|
@@ -91,17 +63,17 @@ let FieldTime = class FieldTime extends FieldComponent {
|
|
|
91
63
|
return this.dense;
|
|
92
64
|
}
|
|
93
65
|
get isPopulated() {
|
|
94
|
-
return
|
|
66
|
+
return this.controller.isPopulated;
|
|
95
67
|
}
|
|
96
68
|
focus() {
|
|
97
|
-
this.
|
|
69
|
+
this.controller.focus();
|
|
98
70
|
}
|
|
99
71
|
setCustomValidity(error) {
|
|
100
|
-
this.
|
|
72
|
+
this.controller.setCustomValidity(error);
|
|
101
73
|
}
|
|
102
74
|
async checkValidity() {
|
|
103
75
|
await this.updateComplete;
|
|
104
|
-
return
|
|
76
|
+
return this.controller.checkValidity();
|
|
105
77
|
}
|
|
106
78
|
reportValidity() {
|
|
107
79
|
this.focus();
|
|
@@ -147,8 +119,8 @@ let FieldTime = class FieldTime extends FieldComponent {
|
|
|
147
119
|
}
|
|
148
120
|
get inputTemplate() {
|
|
149
121
|
return html `
|
|
150
|
-
<div part='segments'
|
|
151
|
-
${this.segments.segments.map(segment => html `<span part=${segment.editable ? 'segment' : 'literal'} ${this.
|
|
122
|
+
<div part='segments' ${this.controller.group.ref()}>
|
|
123
|
+
${this.controller.segments.segments.map(segment => html `<span part=${segment.editable ? 'segment' : 'literal'} ${this.controller.segment.ref(segment)}></span>`)}
|
|
152
124
|
</div>
|
|
153
125
|
`;
|
|
154
126
|
}
|
|
@@ -163,36 +135,23 @@ let FieldTime = class FieldTime extends FieldComponent {
|
|
|
163
135
|
`;
|
|
164
136
|
}
|
|
165
137
|
get popoverTemplate() {
|
|
138
|
+
const { controller } = this;
|
|
139
|
+
const navigate = (e) => controller.navigationDate = e.detail;
|
|
140
|
+
const pick = (e) => controller.pick(e.detail);
|
|
166
141
|
return this.pickerHidden ? html.nothing : html `
|
|
167
142
|
<mo-popover tabindex='-1' .anchor=${this} target='picker' ?open=${bind(this, 'open')}>
|
|
168
143
|
${cache(!this.open ? html.nothing : html `
|
|
169
144
|
<mo-flex id='selector' direction='horizontal'>
|
|
170
|
-
<mo-hour-list style='flex: 1'
|
|
171
|
-
|
|
172
|
-
.navigationDate=${bind(this, 'navigationDate')}
|
|
173
|
-
.value=${this.selectedDate}
|
|
174
|
-
@change=${(e) => this.handleListChange(e.detail)}
|
|
175
|
-
></mo-hour-list>
|
|
176
|
-
<mo-minute-list style='flex: 1'
|
|
177
|
-
.navigationDate=${bind(this, 'navigationDate')}
|
|
178
|
-
.value=${this.selectedDate}
|
|
179
|
-
@change=${(e) => this.handleListChange(e.detail)}
|
|
180
|
-
></mo-minute-list>
|
|
145
|
+
<mo-hour-list style='flex: 1' .hourCycle=${this.hourCycle} .navigationDate=${controller.navigationDate} .value=${controller.selectedDate} @navigate=${navigate} @change=${pick}></mo-hour-list>
|
|
146
|
+
<mo-minute-list style='flex: 1' .navigationDate=${controller.navigationDate} .value=${controller.selectedDate} @navigate=${navigate} @change=${pick}></mo-minute-list>
|
|
181
147
|
${this.precision < FieldDateTimePrecision.Second ? html.nothing : html `
|
|
182
|
-
<mo-second-list style='flex: 1'
|
|
183
|
-
.navigationDate=${bind(this, 'navigationDate')}
|
|
184
|
-
.value=${this.selectedDate}
|
|
185
|
-
@change=${(e) => this.handleListChange(e.detail)}
|
|
186
|
-
></mo-second-list>
|
|
148
|
+
<mo-second-list style='flex: 1' .navigationDate=${controller.navigationDate} .value=${controller.selectedDate} @navigate=${navigate} @change=${pick}></mo-second-list>
|
|
187
149
|
`}
|
|
188
150
|
</mo-flex>
|
|
189
151
|
`)}
|
|
190
152
|
</mo-popover>
|
|
191
153
|
`;
|
|
192
154
|
}
|
|
193
|
-
handleListChange(date) {
|
|
194
|
-
this.handleChange(this.toValue(date));
|
|
195
|
-
}
|
|
196
155
|
};
|
|
197
156
|
__decorate([
|
|
198
157
|
property()
|
|
@@ -218,9 +177,6 @@ __decorate([
|
|
|
218
177
|
__decorate([
|
|
219
178
|
property({ type: Object, converter: dateTimeConverter })
|
|
220
179
|
], FieldTime.prototype, "shortcutReferenceDate", void 0);
|
|
221
|
-
__decorate([
|
|
222
|
-
state()
|
|
223
|
-
], FieldTime.prototype, "navigationDate", void 0);
|
|
224
180
|
FieldTime = __decorate([
|
|
225
181
|
component('mo-field-time')
|
|
226
182
|
], FieldTime);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Controller, type ReactiveControllerHost } from '@a11d/lit';
|
|
2
|
+
import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
|
|
3
|
+
import { DateTimeSegmentsController, type HourCycle } from '../segments/index.js';
|
|
4
|
+
export type FieldTimeControllerOptions = {
|
|
5
|
+
/** `HH:mm`, or `HH:mm:ss` at second precision: what a native time input holds. */
|
|
6
|
+
readonly value?: string;
|
|
7
|
+
/** 'minute' (default) or 'second'. */
|
|
8
|
+
readonly precision?: FieldDateTimePrecision;
|
|
9
|
+
/** Defaults to the language's convention. */
|
|
10
|
+
readonly hourCycle?: HourCycle;
|
|
11
|
+
/** The day the time is edited on, and where the units the user leaves out are taken from. Defaults to now. */
|
|
12
|
+
readonly referenceDate?: DateTime;
|
|
13
|
+
/** The field's name, appended to every segment's own. */
|
|
14
|
+
readonly label?: string;
|
|
15
|
+
readonly disabled?: boolean;
|
|
16
|
+
readonly readonly?: boolean;
|
|
17
|
+
readonly required?: boolean;
|
|
18
|
+
readonly invalid?: boolean;
|
|
19
|
+
/** Fired while editing, once every unit is filled. */
|
|
20
|
+
handleInput?(value: string | undefined): void;
|
|
21
|
+
/** Fired on commit: leaving the segments, Enter, or a time picked. */
|
|
22
|
+
handleChange?(value: string | undefined): void;
|
|
23
|
+
/** Alt+ArrowDown in the segments, as on a native time input. Left out, the field has no picker. */
|
|
24
|
+
handlePickerOpen?(): void;
|
|
25
|
+
};
|
|
26
|
+
type OptionsOrFactory<THost> = FieldTimeControllerOptions | ((host: THost) => FieldTimeControllerOptions);
|
|
27
|
+
/**
|
|
28
|
+
* Everything a time-of-day field does, for a host which only renders it: the segments, the value as the
|
|
29
|
+
* `HH:mm` string of a native time input, where a picker stands, and the field's validity.
|
|
30
|
+
*
|
|
31
|
+
* ```html
|
|
32
|
+
* <div ${this.controller.group.ref()}>
|
|
33
|
+
* ${this.controller.segments.segments.map(segment => html`<span ${this.controller.segment.ref(segment)}></span>`)}
|
|
34
|
+
* </div>
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* A picker is the host's to render: it opens on `handlePickerOpen`, scrolls with `navigationDate` and
|
|
38
|
+
* hands what was chosen to `pick`.
|
|
39
|
+
*
|
|
40
|
+
* @ssr false
|
|
41
|
+
*/
|
|
42
|
+
export declare class FieldTimeController<THost extends ReactiveControllerHost = ReactiveControllerHost> extends Controller implements EventListenerObject {
|
|
43
|
+
protected readonly host: THost;
|
|
44
|
+
private static readonly pattern;
|
|
45
|
+
protected readonly options: FieldTimeControllerOptions;
|
|
46
|
+
readonly segments: DateTimeSegmentsController<THost>;
|
|
47
|
+
private customValidity;
|
|
48
|
+
private navigatedValue?;
|
|
49
|
+
private _navigationDate?;
|
|
50
|
+
constructor(host: THost, options: OptionsOrFactory<THost>);
|
|
51
|
+
get group(): import("@a11d/lit").ElementRef<HTMLElement, void>;
|
|
52
|
+
get segment(): import("@a11d/lit").ElementRefs<HTMLElement, import("../segments/DateTimeSegment.js").DateTimeSegment>;
|
|
53
|
+
get precision(): FieldDateTimePrecision;
|
|
54
|
+
/** The value as a time on the reference day, which is what the segments and a picker work with. */
|
|
55
|
+
get selectedDate(): DateTime | undefined;
|
|
56
|
+
/** Where a picker stands: at the value, until it is scrolled elsewhere, and back there whenever the value changes. */
|
|
57
|
+
get navigationDate(): import("@3mo/date-time/DateTime.js").DateTime;
|
|
58
|
+
set navigationDate(value: import("@3mo/date-time/DateTime.js").DateTime);
|
|
59
|
+
/** Whether the field shows anything: a value, or units typed on the way to one. */
|
|
60
|
+
get isPopulated(): boolean;
|
|
61
|
+
hostUpdate(): void;
|
|
62
|
+
hostUpdated(): void;
|
|
63
|
+
handleEvent(event: Event): void;
|
|
64
|
+
focus(): void;
|
|
65
|
+
/** Commits a time chosen outside the segments, e.g. in a picker. */
|
|
66
|
+
pick(date: DateTime): void;
|
|
67
|
+
setCustomValidity(message: string): void;
|
|
68
|
+
checkValidity(): boolean;
|
|
69
|
+
private toValue;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=FieldTimeController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldTimeController.d.ts","sourceRoot":"","sources":["../../time/FieldTimeController.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,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAEjF,MAAM,MAAM,0BAA0B,GAAG;IACxC,kFAAkF;IAClF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,sCAAsC;IACtC,QAAQ,CAAC,SAAS,CAAC,EAAE,sBAAsB,CAAA;IAC3C,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAA;IAC9B,8GAA8G;IAC9G,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAA;IACjC,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,CAAC,EAAE,OAAO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E,KAAK;IAQxB,KAAK;IAIL,oEAAoE;IACpE,IAAI,CAAC,IAAI,EAAE,QAAQ;IAInB,iBAAiB,CAAC,OAAO,EAAE,MAAM;IAIjC,aAAa;IAIb,OAAO,CAAC,OAAO;CAQf"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Controller } from '@a11d/lit';
|
|
2
|
+
import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
|
|
3
|
+
import { DateTimeSegmentsController } from '../segments/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Everything a time-of-day field does, for a host which only renders it: the segments, the value as the
|
|
6
|
+
* `HH:mm` string of a native time input, where a picker stands, and the field's validity.
|
|
7
|
+
*
|
|
8
|
+
* ```html
|
|
9
|
+
* <div ${this.controller.group.ref()}>
|
|
10
|
+
* ${this.controller.segments.segments.map(segment => html`<span ${this.controller.segment.ref(segment)}></span>`)}
|
|
11
|
+
* </div>
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* A picker is the host's to render: it opens on `handlePickerOpen`, scrolls with `navigationDate` and
|
|
15
|
+
* hands what was chosen to `pick`.
|
|
16
|
+
*
|
|
17
|
+
* @ssr false
|
|
18
|
+
*/
|
|
19
|
+
export class FieldTimeController extends Controller {
|
|
20
|
+
static { this.pattern = /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/; }
|
|
21
|
+
constructor(host, options) {
|
|
22
|
+
super(host);
|
|
23
|
+
this.host = host;
|
|
24
|
+
this.customValidity = '';
|
|
25
|
+
this.options = typeof options === 'function' ? options(host) : options;
|
|
26
|
+
const controller = this;
|
|
27
|
+
this.segments = new DateTimeSegmentsController(host, {
|
|
28
|
+
timeOnly: true,
|
|
29
|
+
get value() { return controller.selectedDate; },
|
|
30
|
+
get precision() { return controller.precision; },
|
|
31
|
+
get referenceDate() { return controller.options.referenceDate; },
|
|
32
|
+
get hourCycle() { return controller.options.hourCycle; },
|
|
33
|
+
get label() { return controller.options.label; },
|
|
34
|
+
get disabled() { return controller.options.disabled; },
|
|
35
|
+
get readonly() { return controller.options.readonly; },
|
|
36
|
+
get required() { return controller.options.required; },
|
|
37
|
+
get invalid() { return controller.options.invalid; },
|
|
38
|
+
handleInput: value => controller.options.handleInput?.(controller.toValue(value)),
|
|
39
|
+
handleChange: value => controller.options.handleChange?.(controller.toValue(value)),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
get group() {
|
|
43
|
+
return this.segments.group;
|
|
44
|
+
}
|
|
45
|
+
get segment() {
|
|
46
|
+
return this.segments.segment;
|
|
47
|
+
}
|
|
48
|
+
get precision() {
|
|
49
|
+
return this.options.precision ?? FieldDateTimePrecision.Minute;
|
|
50
|
+
}
|
|
51
|
+
/** The value as a time on the reference day, which is what the segments and a picker work with. */
|
|
52
|
+
get selectedDate() {
|
|
53
|
+
const match = this.options.value?.match(FieldTimeController.pattern);
|
|
54
|
+
if (!match) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const [, hour, minute, second] = match.map(Number);
|
|
58
|
+
return (this.options.referenceDate ?? new DateTime()).dayStart.with({ hour, minute, second: second || 0 });
|
|
59
|
+
}
|
|
60
|
+
/** Where a picker stands: at the value, until it is scrolled elsewhere, and back there whenever the value changes. */
|
|
61
|
+
get navigationDate() {
|
|
62
|
+
return this._navigationDate ??= this.selectedDate ?? new DateTime();
|
|
63
|
+
}
|
|
64
|
+
set navigationDate(value) {
|
|
65
|
+
this._navigationDate = value;
|
|
66
|
+
this.host.requestUpdate();
|
|
67
|
+
}
|
|
68
|
+
/** Whether the field shows anything: a value, or units typed on the way to one. */
|
|
69
|
+
get isPopulated() {
|
|
70
|
+
return !!this.options.value || !this.segments.isEmpty;
|
|
71
|
+
}
|
|
72
|
+
hostUpdate() {
|
|
73
|
+
if (this.options.value !== this.navigatedValue) {
|
|
74
|
+
this.navigatedValue = this.options.value;
|
|
75
|
+
this._navigationDate = undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Idempotent for one and the same listener, so re-declaring it on every update costs nothing.
|
|
79
|
+
hostUpdated() {
|
|
80
|
+
this.group.value?.addEventListener('keydown', this);
|
|
81
|
+
}
|
|
82
|
+
handleEvent(event) {
|
|
83
|
+
const { key, altKey } = event;
|
|
84
|
+
if (altKey && key === 'ArrowDown' && this.options.handlePickerOpen) {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
this.options.handlePickerOpen();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
focus() {
|
|
90
|
+
this.segments.focus();
|
|
91
|
+
}
|
|
92
|
+
/** Commits a time chosen outside the segments, e.g. in a picker. */
|
|
93
|
+
pick(date) {
|
|
94
|
+
this.options.handleChange?.(this.toValue(date));
|
|
95
|
+
}
|
|
96
|
+
setCustomValidity(message) {
|
|
97
|
+
this.customValidity = message;
|
|
98
|
+
}
|
|
99
|
+
checkValidity() {
|
|
100
|
+
return !this.customValidity && !(this.options.required && !this.options.value);
|
|
101
|
+
}
|
|
102
|
+
toValue(date) {
|
|
103
|
+
if (!date) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
107
|
+
const time = `${pad(date.hour)}:${pad(date.minute)}`;
|
|
108
|
+
return this.precision >= FieldDateTimePrecision.Second ? `${time}:${pad(date.second)}` : time;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../time/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,gBAAgB,CAAA"}
|