@sprawlify/primitives 0.1.11 → 0.1.12
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/{collection-BBgC8xCb.cjs → collection-D0Abtxc0.cjs} +68 -0
- package/dist/{collection-DgzidRvr.mjs → collection-GSpaYJ2f.mjs} +45 -1
- package/dist/collection.cjs +5 -1
- package/dist/collection.d.cts +49 -3
- package/dist/collection.d.mts +49 -3
- package/dist/collection.mjs +2 -2
- package/dist/{list-collection-B_8BN0XB.d.cts → list-collection-Cjgbx_9l.d.cts} +1 -1
- package/dist/{list-collection-DkRA5LOq.d.mts → list-collection-IF510iNl.d.mts} +1 -1
- package/dist/machines/accordion/index.d.cts +1 -1
- package/dist/machines/accordion/index.d.mts +1 -1
- package/dist/machines/angle-slider/index.d.cts +1 -1
- package/dist/machines/angle-slider/index.d.mts +1 -1
- package/dist/machines/carousel/index.d.cts +1 -1
- package/dist/machines/carousel/index.d.mts +1 -1
- package/dist/machines/cascade-select/index.cjs +1 -1
- package/dist/machines/cascade-select/index.d.cts +2 -2
- package/dist/machines/cascade-select/index.d.mts +2 -2
- package/dist/machines/cascade-select/index.mjs +1 -1
- package/dist/machines/checkbox/index.d.cts +1 -1
- package/dist/machines/checkbox/index.d.mts +1 -1
- package/dist/machines/clipboard/index.d.cts +1 -1
- package/dist/machines/clipboard/index.d.mts +1 -1
- package/dist/machines/collapsible/index.d.cts +1 -1
- package/dist/machines/collapsible/index.d.mts +1 -1
- package/dist/machines/color-picker/index.d.cts +1 -1
- package/dist/machines/color-picker/index.d.mts +1 -1
- package/dist/machines/combobox/index.cjs +279 -355
- package/dist/machines/combobox/index.d.cts +5 -4
- package/dist/machines/combobox/index.d.mts +5 -4
- package/dist/machines/combobox/index.mjs +279 -355
- package/dist/machines/date-input/index.cjs +1830 -0
- package/dist/machines/date-input/index.d.cts +223 -0
- package/dist/machines/date-input/index.d.mts +223 -0
- package/dist/machines/date-input/index.mjs +1813 -0
- package/dist/machines/date-picker/index.d.cts +1 -1
- package/dist/machines/date-picker/index.d.mts +1 -1
- package/dist/machines/dialog/index.d.cts +1 -1
- package/dist/machines/dialog/index.d.mts +1 -1
- package/dist/machines/drawer/index.d.cts +1 -1
- package/dist/machines/drawer/index.d.mts +1 -1
- package/dist/machines/dropdown-menu/index.d.cts +1 -1
- package/dist/machines/dropdown-menu/index.d.mts +1 -1
- package/dist/machines/editable/index.d.cts +1 -1
- package/dist/machines/editable/index.d.mts +1 -1
- package/dist/machines/file-upload/index.d.cts +1 -1
- package/dist/machines/file-upload/index.d.mts +1 -1
- package/dist/machines/floating-panel/index.d.cts +1 -1
- package/dist/machines/floating-panel/index.d.mts +1 -1
- package/dist/machines/hover-card/index.d.cts +1 -1
- package/dist/machines/hover-card/index.d.mts +1 -1
- package/dist/machines/listbox/index.cjs +41 -16
- package/dist/machines/listbox/index.d.cts +5 -4
- package/dist/machines/listbox/index.d.mts +5 -4
- package/dist/machines/listbox/index.mjs +42 -17
- package/dist/machines/marquee/index.d.cts +3 -3
- package/dist/machines/marquee/index.d.mts +3 -3
- package/dist/machines/navigation-menu/index.d.cts +1 -1
- package/dist/machines/navigation-menu/index.d.mts +1 -1
- package/dist/machines/number-input/index.d.cts +1 -1
- package/dist/machines/number-input/index.d.mts +1 -1
- package/dist/machines/password-input/index.d.cts +1 -1
- package/dist/machines/password-input/index.d.mts +1 -1
- package/dist/machines/pin-input/index.d.cts +1 -1
- package/dist/machines/pin-input/index.d.mts +1 -1
- package/dist/machines/popover/index.d.cts +1 -1
- package/dist/machines/popover/index.d.mts +1 -1
- package/dist/machines/progress/index.d.cts +1 -1
- package/dist/machines/progress/index.d.mts +1 -1
- package/dist/machines/radio-group/index.d.cts +1 -1
- package/dist/machines/radio-group/index.d.mts +1 -1
- package/dist/machines/rating-group/index.d.cts +1 -1
- package/dist/machines/rating-group/index.d.mts +1 -1
- package/dist/machines/select/index.cjs +47 -18
- package/dist/machines/select/index.d.cts +4 -3
- package/dist/machines/select/index.d.mts +4 -3
- package/dist/machines/select/index.mjs +48 -19
- package/dist/machines/signature-pad/index.d.cts +1 -1
- package/dist/machines/signature-pad/index.d.mts +1 -1
- package/dist/machines/slider/index.d.cts +1 -1
- package/dist/machines/slider/index.d.mts +1 -1
- package/dist/machines/steps/index.d.cts +1 -1
- package/dist/machines/steps/index.d.mts +1 -1
- package/dist/machines/switch/index.d.cts +1 -1
- package/dist/machines/switch/index.d.mts +1 -1
- package/dist/machines/tabs/index.d.cts +1 -1
- package/dist/machines/tabs/index.d.mts +1 -1
- package/dist/machines/tags-input/index.d.cts +1 -1
- package/dist/machines/tags-input/index.d.mts +1 -1
- package/dist/machines/timer/index.d.cts +1 -1
- package/dist/machines/timer/index.d.mts +1 -1
- package/dist/machines/toast/index.d.cts +1 -1
- package/dist/machines/toast/index.d.mts +1 -1
- package/dist/machines/tooltip/index.d.cts +1 -1
- package/dist/machines/tooltip/index.d.mts +1 -1
- package/dist/machines/tour/index.d.cts +1 -1
- package/dist/machines/tour/index.d.mts +1 -1
- package/dist/machines/tree-view/index.cjs +1 -1
- package/dist/machines/tree-view/index.d.cts +1 -1
- package/dist/machines/tree-view/index.d.mts +1 -1
- package/dist/machines/tree-view/index.mjs +1 -1
- package/dist/{selection-DdNvrKbj.d.mts → selection-6urf-c8j.d.mts} +1 -1
- package/dist/{selection-Bb_ZSVxe.d.cts → selection-BmS2RDMq.d.cts} +1 -1
- package/package.json +11 -1
|
@@ -0,0 +1,1830 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../../chunk-CKQMccvm.cjs");
|
|
3
|
+
const require_create_anatomy = require("../../create-anatomy-BnwEmNnc.cjs");
|
|
4
|
+
const require_dom_query = require("../../dom-query-BUO7rGsg.cjs");
|
|
5
|
+
const require_defineProperty = require("../../defineProperty-8IOBQ1i_.cjs");
|
|
6
|
+
const require_utils = require("../../utils-ByNiZU8f.cjs");
|
|
7
|
+
const require_core = require("../../core-Bw_czdwX.cjs");
|
|
8
|
+
const require_date_utils = require("../../date-utils-B-dqorZV.cjs");
|
|
9
|
+
const require_live_region = require("../../live-region-TGReV9nm.cjs");
|
|
10
|
+
const require_create_props = require("../../create-props-DP39rHnH.cjs");
|
|
11
|
+
let _internationalized_date = require("@internationalized/date");
|
|
12
|
+
//#region src/machines/date-input/date-input.anatomy.ts
|
|
13
|
+
const anatomy = require_create_anatomy.createAnatomy("date-input").parts("root", "label", "control", "segmentGroup", "segment", "hiddenInput");
|
|
14
|
+
const parts = anatomy.build();
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/machines/date-input/date-input.dom.ts
|
|
17
|
+
const getRootId = (ctx) => ctx.ids?.root ?? `date-input:${ctx.id}`;
|
|
18
|
+
const getLabelId = (ctx, index) => ctx.ids?.label?.(index) ?? `date-input:${ctx.id}:label:${index}`;
|
|
19
|
+
const getControlId = (ctx) => ctx.ids?.control ?? `date-input:${ctx.id}:control`;
|
|
20
|
+
const getSegmentGroupId = (ctx, index) => ctx.ids?.segmentGroup?.(index) ?? `date-input:${ctx.id}:segment-group:${index}`;
|
|
21
|
+
const getHiddenInputId = (ctx, index) => ctx.ids?.hiddenInput?.(index) ?? `date-input:${ctx.id}:hidden-input:${index}`;
|
|
22
|
+
const getControlEl = (ctx) => ctx.getById(getControlId(ctx));
|
|
23
|
+
const getSegmentEls = (ctx) => require_dom_query.queryAll(getControlEl(ctx), `[data-part=segment]`);
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/machines/date-input/utils/locale.ts
|
|
26
|
+
const isValidCharacter = (char, separator) => {
|
|
27
|
+
if (!char) return true;
|
|
28
|
+
return /\d/.test(char) || char === separator || char.length !== 1;
|
|
29
|
+
};
|
|
30
|
+
function getLocaleSeparator(locale) {
|
|
31
|
+
const literalPart = new Intl.DateTimeFormat(locale).formatToParts(/* @__PURE__ */ new Date()).find((part) => part.type === "literal");
|
|
32
|
+
return literalPart ? literalPart.value : "/";
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/machines/date-input/utils/segments.ts
|
|
36
|
+
const EDITABLE_SEGMENTS = {
|
|
37
|
+
year: true,
|
|
38
|
+
month: true,
|
|
39
|
+
day: true,
|
|
40
|
+
hour: true,
|
|
41
|
+
minute: true,
|
|
42
|
+
second: true,
|
|
43
|
+
dayPeriod: true,
|
|
44
|
+
era: true,
|
|
45
|
+
literal: false,
|
|
46
|
+
timeZoneName: false,
|
|
47
|
+
weekday: false,
|
|
48
|
+
unknown: false,
|
|
49
|
+
fractionalSecond: false
|
|
50
|
+
};
|
|
51
|
+
const PAGE_STEP = {
|
|
52
|
+
year: 5,
|
|
53
|
+
month: 2,
|
|
54
|
+
day: 7,
|
|
55
|
+
hour: 2,
|
|
56
|
+
minute: 15,
|
|
57
|
+
second: 15,
|
|
58
|
+
dayPeriod: void 0,
|
|
59
|
+
era: void 0,
|
|
60
|
+
literal: void 0,
|
|
61
|
+
timeZoneName: void 0,
|
|
62
|
+
weekday: void 0,
|
|
63
|
+
unknown: void 0,
|
|
64
|
+
fractionalSecond: void 0
|
|
65
|
+
};
|
|
66
|
+
const SEGMENT_LABELS = {
|
|
67
|
+
era: "Era",
|
|
68
|
+
year: "Year",
|
|
69
|
+
month: "Month",
|
|
70
|
+
day: "Day",
|
|
71
|
+
hour: "Hour",
|
|
72
|
+
minute: "Minute",
|
|
73
|
+
second: "Second",
|
|
74
|
+
dayPeriod: "AM/PM",
|
|
75
|
+
timeZoneName: "Time zone"
|
|
76
|
+
};
|
|
77
|
+
function getSegmentLabel(type) {
|
|
78
|
+
return SEGMENT_LABELS[type] ?? type;
|
|
79
|
+
}
|
|
80
|
+
const TYPE_MAPPING = {
|
|
81
|
+
dayperiod: "dayPeriod",
|
|
82
|
+
relatedYear: "year",
|
|
83
|
+
yearName: "literal",
|
|
84
|
+
unknown: "literal"
|
|
85
|
+
};
|
|
86
|
+
function getSafeType(type) {
|
|
87
|
+
return TYPE_MAPPING[type] ?? type;
|
|
88
|
+
}
|
|
89
|
+
function getPlaceholder(type, translations, locale) {
|
|
90
|
+
return translations.placeholder(locale)[type];
|
|
91
|
+
}
|
|
92
|
+
function isEditableSegment(type) {
|
|
93
|
+
return EDITABLE_SEGMENTS[type] === true;
|
|
94
|
+
}
|
|
95
|
+
function getSafeFormatParts(formatter, dateValue, displayValue) {
|
|
96
|
+
try {
|
|
97
|
+
return formatter.formatToParts(dateValue);
|
|
98
|
+
} catch {
|
|
99
|
+
return formatter.formatToParts(/* @__PURE__ */ new Date()).map((part) => {
|
|
100
|
+
switch (part.type) {
|
|
101
|
+
case "year":
|
|
102
|
+
case "relatedYear": return {
|
|
103
|
+
...part,
|
|
104
|
+
value: String(displayValue.year ?? 0)
|
|
105
|
+
};
|
|
106
|
+
case "month": return {
|
|
107
|
+
...part,
|
|
108
|
+
value: String(displayValue.month ?? 0)
|
|
109
|
+
};
|
|
110
|
+
case "day": return {
|
|
111
|
+
...part,
|
|
112
|
+
value: String(displayValue.day ?? 0)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return part;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function processSegments({ dateValue, displayValue, formatter, locale, translations, granularity }) {
|
|
120
|
+
const timeValue = [
|
|
121
|
+
"hour",
|
|
122
|
+
"minute",
|
|
123
|
+
"second"
|
|
124
|
+
];
|
|
125
|
+
const segments = getSafeFormatParts(formatter, dateValue, displayValue);
|
|
126
|
+
const processedSegments = [];
|
|
127
|
+
for (const segment of segments) {
|
|
128
|
+
const type = getSafeType(segment.type);
|
|
129
|
+
let isEditable = isEditableSegment(type);
|
|
130
|
+
if (type === "era" && displayValue.calendar.getEras().length === 1) isEditable = false;
|
|
131
|
+
const isPlaceholder = isEditable && displayValue[type] == null;
|
|
132
|
+
let placeholder = isEditableSegment(type) ? getPlaceholder(type, translations, locale) : null;
|
|
133
|
+
if ((type === "dayPeriod" || type === "era") && segment.value) placeholder = segment.value;
|
|
134
|
+
const dateSegment = {
|
|
135
|
+
type,
|
|
136
|
+
text: isPlaceholder ? placeholder : segment.value,
|
|
137
|
+
...displayValue.getSegmentLimits(type) ?? {},
|
|
138
|
+
isPlaceholder,
|
|
139
|
+
placeholder,
|
|
140
|
+
isEditable
|
|
141
|
+
};
|
|
142
|
+
if (type === "hour") {
|
|
143
|
+
processedSegments.push({
|
|
144
|
+
type: "literal",
|
|
145
|
+
text: "",
|
|
146
|
+
isPlaceholder: false,
|
|
147
|
+
placeholder: "",
|
|
148
|
+
isEditable: false
|
|
149
|
+
});
|
|
150
|
+
processedSegments.push(dateSegment);
|
|
151
|
+
if (type === granularity) processedSegments.push({
|
|
152
|
+
type: "literal",
|
|
153
|
+
text: "",
|
|
154
|
+
isPlaceholder: false,
|
|
155
|
+
placeholder: "",
|
|
156
|
+
isEditable: false
|
|
157
|
+
});
|
|
158
|
+
} else if (timeValue.includes(type) && type === granularity) {
|
|
159
|
+
processedSegments.push(dateSegment);
|
|
160
|
+
processedSegments.push({
|
|
161
|
+
type: "literal",
|
|
162
|
+
text: "",
|
|
163
|
+
isPlaceholder: false,
|
|
164
|
+
placeholder: "",
|
|
165
|
+
isEditable: false
|
|
166
|
+
});
|
|
167
|
+
} else processedSegments.push(dateSegment);
|
|
168
|
+
}
|
|
169
|
+
return processedSegments;
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/machines/date-input/utils/validity.ts
|
|
173
|
+
function getGroupOffset(allSegments, index) {
|
|
174
|
+
return allSegments.slice(0, index).reduce((acc, segs) => acc + segs.length, 0);
|
|
175
|
+
}
|
|
176
|
+
function resolveActiveSegment(ctx) {
|
|
177
|
+
const { context, computed } = ctx;
|
|
178
|
+
const index = context.get("activeIndex");
|
|
179
|
+
const activeSegmentIndex = context.get("activeSegmentIndex");
|
|
180
|
+
const allSegments = computed("segments");
|
|
181
|
+
const offset = getGroupOffset(allSegments, index);
|
|
182
|
+
return {
|
|
183
|
+
allSegments,
|
|
184
|
+
segments: allSegments[index],
|
|
185
|
+
offset,
|
|
186
|
+
localIndex: activeSegmentIndex - offset
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function getActiveSegment(ctx) {
|
|
190
|
+
const { allSegments, localIndex } = resolveActiveSegment(ctx);
|
|
191
|
+
return allSegments[ctx.context.get("activeIndex")]?.[localIndex];
|
|
192
|
+
}
|
|
193
|
+
function advanceToNextSegment(ctx) {
|
|
194
|
+
const { context } = ctx;
|
|
195
|
+
const index = context.get("activeIndex");
|
|
196
|
+
const { allSegments, segments, offset, localIndex } = resolveActiveSegment(ctx);
|
|
197
|
+
const nextLocalIndex = segments.findIndex((s, i) => i > localIndex && s.isEditable);
|
|
198
|
+
if (nextLocalIndex !== -1) {
|
|
199
|
+
context.set("activeSegmentIndex", offset + nextLocalIndex);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const nextGroupSegments = allSegments[index + 1];
|
|
203
|
+
if (!nextGroupSegments) return;
|
|
204
|
+
const firstNextGroupEditableLocalIndex = nextGroupSegments.findIndex((s) => s.isEditable);
|
|
205
|
+
if (firstNextGroupEditableLocalIndex === -1) return;
|
|
206
|
+
context.set("activeIndex", index + 1);
|
|
207
|
+
context.set("activeSegmentIndex", offset + segments.length + firstNextGroupEditableLocalIndex);
|
|
208
|
+
}
|
|
209
|
+
function getActiveDisplayValue(ctx) {
|
|
210
|
+
const index = ctx.context.get("activeIndex");
|
|
211
|
+
return ctx.context.get("displayValues")[index];
|
|
212
|
+
}
|
|
213
|
+
function setDisplayValue(ctx, index, dv) {
|
|
214
|
+
const displayValues = [...ctx.context.get("displayValues")];
|
|
215
|
+
displayValues[index] = dv;
|
|
216
|
+
ctx.context.set("displayValues", displayValues);
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/machines/date-input/date-input.connect.ts
|
|
220
|
+
function connect(service, normalize) {
|
|
221
|
+
const { state, context, prop, send, computed, scope } = service;
|
|
222
|
+
const disabled = Boolean(prop("disabled"));
|
|
223
|
+
const readOnly = Boolean(prop("readOnly"));
|
|
224
|
+
const invalid = Boolean(prop("invalid"));
|
|
225
|
+
const focused = state.matches("focused");
|
|
226
|
+
const separator = getLocaleSeparator(prop("locale"));
|
|
227
|
+
function getSegmentState(props) {
|
|
228
|
+
const { segment } = props;
|
|
229
|
+
return { editable: !disabled && !readOnly && segment.isEditable };
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
focused,
|
|
233
|
+
disabled,
|
|
234
|
+
invalid,
|
|
235
|
+
groupCount: computed("segments").length,
|
|
236
|
+
value: context.get("value"),
|
|
237
|
+
valueAsDate: context.get("value").filter((date) => date != null).map((date) => date.toDate(prop("timeZone"))),
|
|
238
|
+
valueAsString: computed("valueAsString"),
|
|
239
|
+
placeholderValue: context.get("placeholderValue"),
|
|
240
|
+
displayValues: context.get("displayValues"),
|
|
241
|
+
setValue(values) {
|
|
242
|
+
send({
|
|
243
|
+
type: "VALUE.SET",
|
|
244
|
+
value: values
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
clearValue() {
|
|
248
|
+
send({ type: "VALUE.CLEAR" });
|
|
249
|
+
},
|
|
250
|
+
getSegments(props = {}) {
|
|
251
|
+
const { index = 0 } = props;
|
|
252
|
+
const allSegments = computed("segments");
|
|
253
|
+
const segments = allSegments[index] ?? [];
|
|
254
|
+
const enteredKeys = context.get("enteredKeys");
|
|
255
|
+
const activeIndex = context.get("activeIndex");
|
|
256
|
+
const activeSegmentIndex = context.get("activeSegmentIndex");
|
|
257
|
+
if (focused && enteredKeys && index === activeIndex && activeSegmentIndex >= 0) {
|
|
258
|
+
const localActiveSegmentIndex = activeSegmentIndex - getGroupOffset(allSegments, index);
|
|
259
|
+
return segments.map((seg, i) => {
|
|
260
|
+
if (i !== localActiveSegmentIndex) return seg;
|
|
261
|
+
return {
|
|
262
|
+
...seg,
|
|
263
|
+
text: enteredKeys,
|
|
264
|
+
isPlaceholder: false
|
|
265
|
+
};
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return segments;
|
|
269
|
+
},
|
|
270
|
+
getSegmentState,
|
|
271
|
+
getRootProps() {
|
|
272
|
+
return normalize.element({
|
|
273
|
+
...parts.root.attrs,
|
|
274
|
+
dir: prop("dir"),
|
|
275
|
+
id: getRootId(scope),
|
|
276
|
+
"data-disabled": require_dom_query.dataAttr(disabled),
|
|
277
|
+
"data-readonly": require_dom_query.dataAttr(readOnly),
|
|
278
|
+
"data-invalid": require_dom_query.dataAttr(invalid)
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
getLabelProps(props = {}) {
|
|
282
|
+
const { index = 0 } = props;
|
|
283
|
+
return normalize.label({
|
|
284
|
+
...parts.label.attrs,
|
|
285
|
+
id: getLabelId(scope, index),
|
|
286
|
+
dir: prop("dir"),
|
|
287
|
+
htmlFor: getSegmentGroupId(scope, index),
|
|
288
|
+
"data-disabled": require_dom_query.dataAttr(disabled),
|
|
289
|
+
"data-readonly": require_dom_query.dataAttr(readOnly),
|
|
290
|
+
"data-invalid": require_dom_query.dataAttr(invalid)
|
|
291
|
+
});
|
|
292
|
+
},
|
|
293
|
+
getControlProps() {
|
|
294
|
+
return normalize.element({
|
|
295
|
+
...parts.control.attrs,
|
|
296
|
+
dir: prop("dir"),
|
|
297
|
+
id: getControlId(scope),
|
|
298
|
+
"data-disabled": require_dom_query.dataAttr(disabled),
|
|
299
|
+
"data-readonly": require_dom_query.dataAttr(readOnly),
|
|
300
|
+
"data-invalid": require_dom_query.dataAttr(invalid),
|
|
301
|
+
"data-focus": require_dom_query.dataAttr(focused)
|
|
302
|
+
});
|
|
303
|
+
},
|
|
304
|
+
getSegmentGroupProps(props = {}) {
|
|
305
|
+
const { index = 0 } = props;
|
|
306
|
+
return normalize.element({
|
|
307
|
+
...parts.segmentGroup.attrs,
|
|
308
|
+
id: getSegmentGroupId(scope, index),
|
|
309
|
+
dir: prop("dir"),
|
|
310
|
+
role: "group",
|
|
311
|
+
"aria-labelledby": getLabelId(scope, index),
|
|
312
|
+
"data-disabled": require_dom_query.dataAttr(disabled),
|
|
313
|
+
"data-readonly": require_dom_query.dataAttr(readOnly),
|
|
314
|
+
"data-invalid": require_dom_query.dataAttr(invalid),
|
|
315
|
+
"data-focus": require_dom_query.dataAttr(focused),
|
|
316
|
+
style: { unicodeBidi: "isolate" }
|
|
317
|
+
});
|
|
318
|
+
},
|
|
319
|
+
getSegmentProps(props) {
|
|
320
|
+
const { segment, index = 0 } = props;
|
|
321
|
+
const segmentState = getSegmentState(props);
|
|
322
|
+
if (segment.type === "literal") return normalize.element({
|
|
323
|
+
...parts.segment.attrs,
|
|
324
|
+
dir: prop("dir"),
|
|
325
|
+
"aria-hidden": true,
|
|
326
|
+
"data-type": segment.type,
|
|
327
|
+
"data-readonly": require_dom_query.dataAttr(true),
|
|
328
|
+
"data-disabled": require_dom_query.dataAttr(true)
|
|
329
|
+
});
|
|
330
|
+
return normalize.element({
|
|
331
|
+
...parts.segment.attrs,
|
|
332
|
+
dir: prop("dir"),
|
|
333
|
+
role: "spinbutton",
|
|
334
|
+
tabIndex: disabled ? void 0 : 0,
|
|
335
|
+
autoComplete: "off",
|
|
336
|
+
spellCheck: segmentState.editable ? "false" : void 0,
|
|
337
|
+
autoCorrect: segmentState.editable ? "off" : void 0,
|
|
338
|
+
contentEditable: segmentState.editable,
|
|
339
|
+
suppressContentEditableWarning: segmentState.editable,
|
|
340
|
+
inputMode: disabled || segment.type === "dayPeriod" || segment.type === "era" || !segmentState.editable ? void 0 : "numeric",
|
|
341
|
+
enterKeyHint: "next",
|
|
342
|
+
"aria-label": getSegmentLabel(segment.type),
|
|
343
|
+
"aria-valuenow": segment.isPlaceholder ? void 0 : segment.value,
|
|
344
|
+
"aria-valuetext": segment.isPlaceholder ? segment.placeholder : segment.text,
|
|
345
|
+
"aria-valuemin": segment.minValue,
|
|
346
|
+
"aria-valuemax": segment.maxValue,
|
|
347
|
+
"aria-invalid": require_dom_query.ariaAttr(invalid),
|
|
348
|
+
"aria-readonly": require_dom_query.ariaAttr(!segment.isEditable || readOnly),
|
|
349
|
+
"aria-disabled": require_dom_query.ariaAttr(disabled),
|
|
350
|
+
"data-value": segment.value,
|
|
351
|
+
"data-type": segment.type,
|
|
352
|
+
"data-readonly": require_dom_query.dataAttr(!segment.isEditable || readOnly),
|
|
353
|
+
"data-disabled": require_dom_query.dataAttr(disabled),
|
|
354
|
+
"data-editable": require_dom_query.dataAttr(segment.isEditable && !readOnly && !disabled),
|
|
355
|
+
"data-placeholder": require_dom_query.dataAttr(segment.isPlaceholder),
|
|
356
|
+
style: { caretColor: "transparent" },
|
|
357
|
+
onFocus(event) {
|
|
358
|
+
send({
|
|
359
|
+
type: "SEGMENT.FOCUS",
|
|
360
|
+
dateIndex: index,
|
|
361
|
+
segmentIndex: getSegmentEls(scope).indexOf(event.currentTarget)
|
|
362
|
+
});
|
|
363
|
+
const selection = event.currentTarget?.ownerDocument?.getSelection?.();
|
|
364
|
+
if (selection && event.currentTarget) selection.collapse(event.currentTarget);
|
|
365
|
+
},
|
|
366
|
+
onBlur() {
|
|
367
|
+
send({
|
|
368
|
+
type: "SEGMENT.BLUR",
|
|
369
|
+
index: -1
|
|
370
|
+
});
|
|
371
|
+
},
|
|
372
|
+
onKeyDown(event) {
|
|
373
|
+
if (event.defaultPrevented || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey || readOnly || event.nativeEvent.isComposing) return;
|
|
374
|
+
const exec = {
|
|
375
|
+
ArrowLeft() {
|
|
376
|
+
send({ type: "SEGMENT.ARROW_LEFT" });
|
|
377
|
+
},
|
|
378
|
+
ArrowRight() {
|
|
379
|
+
send({ type: "SEGMENT.ARROW_RIGHT" });
|
|
380
|
+
},
|
|
381
|
+
ArrowUp() {
|
|
382
|
+
send({
|
|
383
|
+
type: "SEGMENT.ADJUST",
|
|
384
|
+
segment,
|
|
385
|
+
amount: 1
|
|
386
|
+
});
|
|
387
|
+
},
|
|
388
|
+
ArrowDown() {
|
|
389
|
+
send({
|
|
390
|
+
type: "SEGMENT.ADJUST",
|
|
391
|
+
segment,
|
|
392
|
+
amount: -1
|
|
393
|
+
});
|
|
394
|
+
},
|
|
395
|
+
PageUp() {
|
|
396
|
+
send({
|
|
397
|
+
type: "SEGMENT.ADJUST",
|
|
398
|
+
segment,
|
|
399
|
+
amount: PAGE_STEP[segment.type] ?? 1
|
|
400
|
+
});
|
|
401
|
+
},
|
|
402
|
+
PageDown() {
|
|
403
|
+
send({
|
|
404
|
+
type: "SEGMENT.ADJUST",
|
|
405
|
+
segment,
|
|
406
|
+
amount: -(PAGE_STEP[segment.type] ?? 1)
|
|
407
|
+
});
|
|
408
|
+
},
|
|
409
|
+
Backspace() {
|
|
410
|
+
send({
|
|
411
|
+
type: "SEGMENT.BACKSPACE",
|
|
412
|
+
segment
|
|
413
|
+
});
|
|
414
|
+
},
|
|
415
|
+
Delete() {
|
|
416
|
+
send({
|
|
417
|
+
type: "SEGMENT.BACKSPACE",
|
|
418
|
+
segment
|
|
419
|
+
});
|
|
420
|
+
},
|
|
421
|
+
Home() {
|
|
422
|
+
send({
|
|
423
|
+
type: "SEGMENT.HOME",
|
|
424
|
+
segment
|
|
425
|
+
});
|
|
426
|
+
},
|
|
427
|
+
End() {
|
|
428
|
+
send({
|
|
429
|
+
type: "SEGMENT.END",
|
|
430
|
+
segment
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}[require_dom_query.getEventKey(event, { dir: prop("dir") })];
|
|
434
|
+
if (exec) {
|
|
435
|
+
exec(event);
|
|
436
|
+
event.preventDefault();
|
|
437
|
+
event.stopPropagation();
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
onPointerDown(event) {
|
|
441
|
+
event.stopPropagation();
|
|
442
|
+
},
|
|
443
|
+
onMouseDown(event) {
|
|
444
|
+
event.stopPropagation();
|
|
445
|
+
},
|
|
446
|
+
onBeforeInput(event) {
|
|
447
|
+
const { data, inputType } = require_dom_query.getNativeEvent(event);
|
|
448
|
+
if ([
|
|
449
|
+
"deleteContentBackward",
|
|
450
|
+
"deleteContentForward",
|
|
451
|
+
"deleteByCut",
|
|
452
|
+
"deleteByDrag"
|
|
453
|
+
].includes(inputType)) {
|
|
454
|
+
event.preventDefault();
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (inputType === "insertFromPaste") {
|
|
458
|
+
event.preventDefault();
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (inputType === "insertCompositionText") {
|
|
462
|
+
if (event.currentTarget || event.target) {
|
|
463
|
+
event.preventDefault();
|
|
464
|
+
if (data != null) send({
|
|
465
|
+
type: "SEGMENT.INPUT",
|
|
466
|
+
segment,
|
|
467
|
+
input: data
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
const isTextSegment = segment.type === "dayPeriod" || segment.type === "era";
|
|
473
|
+
if (data && (isTextSegment || isValidCharacter(data, separator))) {
|
|
474
|
+
event.preventDefault();
|
|
475
|
+
send({
|
|
476
|
+
type: "SEGMENT.INPUT",
|
|
477
|
+
segment,
|
|
478
|
+
input: data
|
|
479
|
+
});
|
|
480
|
+
} else event.preventDefault();
|
|
481
|
+
},
|
|
482
|
+
onPaste(event) {
|
|
483
|
+
event.preventDefault();
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
},
|
|
487
|
+
getHiddenInputProps(props = {}) {
|
|
488
|
+
const { index = 0, name } = props;
|
|
489
|
+
const value = context.get("value");
|
|
490
|
+
const inputName = name || prop("name");
|
|
491
|
+
return normalize.input({
|
|
492
|
+
...parts.hiddenInput.attrs,
|
|
493
|
+
type: "hidden",
|
|
494
|
+
id: getHiddenInputId(scope, index),
|
|
495
|
+
name: inputName ? value.length > 1 ? `${inputName}[${index}]` : inputName : void 0,
|
|
496
|
+
form: prop("form"),
|
|
497
|
+
required: prop("required"),
|
|
498
|
+
disabled,
|
|
499
|
+
readOnly,
|
|
500
|
+
value: computed("valueAsString")[index] ?? "",
|
|
501
|
+
style: require_dom_query.visuallyHiddenStyle
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
//#endregion
|
|
507
|
+
//#region src/machines/date-input/utils/incomplete-date.ts
|
|
508
|
+
var IncompleteDate = class IncompleteDate {
|
|
509
|
+
constructor(calendar, hourCycle, dateValue) {
|
|
510
|
+
require_defineProperty._defineProperty(this, "calendar", void 0);
|
|
511
|
+
require_defineProperty._defineProperty(this, "era", void 0);
|
|
512
|
+
require_defineProperty._defineProperty(this, "year", void 0);
|
|
513
|
+
require_defineProperty._defineProperty(this, "month", void 0);
|
|
514
|
+
require_defineProperty._defineProperty(this, "day", void 0);
|
|
515
|
+
require_defineProperty._defineProperty(this, "hour", void 0);
|
|
516
|
+
require_defineProperty._defineProperty(this, "hourCycle", void 0);
|
|
517
|
+
require_defineProperty._defineProperty(this, "dayPeriod", void 0);
|
|
518
|
+
require_defineProperty._defineProperty(this, "minute", void 0);
|
|
519
|
+
require_defineProperty._defineProperty(this, "second", void 0);
|
|
520
|
+
require_defineProperty._defineProperty(this, "millisecond", void 0);
|
|
521
|
+
require_defineProperty._defineProperty(this, "offset", void 0);
|
|
522
|
+
this.era = dateValue?.era ?? null;
|
|
523
|
+
this.calendar = calendar;
|
|
524
|
+
this.year = dateValue?.year ?? null;
|
|
525
|
+
this.month = dateValue?.month ?? null;
|
|
526
|
+
this.day = dateValue?.day ?? null;
|
|
527
|
+
this.hour = dateValue?.hour ?? null;
|
|
528
|
+
this.hourCycle = hourCycle;
|
|
529
|
+
this.dayPeriod = null;
|
|
530
|
+
this.minute = dateValue?.minute ?? null;
|
|
531
|
+
this.second = dateValue?.second ?? null;
|
|
532
|
+
this.millisecond = dateValue?.millisecond ?? null;
|
|
533
|
+
this.offset = "offset" in (dateValue ?? {}) ? dateValue.offset : null;
|
|
534
|
+
if (this.hour != null) {
|
|
535
|
+
const [dayPeriod, hour] = toHourCycle(this.hour, hourCycle);
|
|
536
|
+
this.dayPeriod = dayPeriod;
|
|
537
|
+
this.hour = hour;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
copy() {
|
|
541
|
+
const res = new IncompleteDate(this.calendar, this.hourCycle);
|
|
542
|
+
res.era = this.era;
|
|
543
|
+
res.year = this.year;
|
|
544
|
+
res.month = this.month;
|
|
545
|
+
res.day = this.day;
|
|
546
|
+
res.hour = this.hour;
|
|
547
|
+
res.dayPeriod = this.dayPeriod;
|
|
548
|
+
res.minute = this.minute;
|
|
549
|
+
res.second = this.second;
|
|
550
|
+
res.millisecond = this.millisecond;
|
|
551
|
+
res.offset = this.offset;
|
|
552
|
+
return res;
|
|
553
|
+
}
|
|
554
|
+
isComplete(segments) {
|
|
555
|
+
return segments.every((segment) => this[segment] != null);
|
|
556
|
+
}
|
|
557
|
+
isCleared(segments) {
|
|
558
|
+
return segments.every((segment) => this[segment] === null);
|
|
559
|
+
}
|
|
560
|
+
set(field, value, placeholder) {
|
|
561
|
+
const result = this.copy();
|
|
562
|
+
result[field] = value;
|
|
563
|
+
if (field === "hour" && result.dayPeriod == null && "hour" in placeholder) result.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];
|
|
564
|
+
if (field === "year" && result.era == null) result.era = placeholder.era;
|
|
565
|
+
if (field !== "second" && field !== "literal" && field !== "timeZoneName") result.offset = null;
|
|
566
|
+
return result;
|
|
567
|
+
}
|
|
568
|
+
clear(field) {
|
|
569
|
+
const result = this.copy();
|
|
570
|
+
result[field] = null;
|
|
571
|
+
if (field === "year") result.era = null;
|
|
572
|
+
result.offset = null;
|
|
573
|
+
return result;
|
|
574
|
+
}
|
|
575
|
+
cycle(field, amount, placeholder, displaySegments) {
|
|
576
|
+
const res = this.copy();
|
|
577
|
+
if (res[field] == null && field !== "dayPeriod" && field !== "era") {
|
|
578
|
+
if (field === "hour" && "hour" in placeholder) {
|
|
579
|
+
const [dayPeriod, hour] = toHourCycle(placeholder.hour, this.hourCycle);
|
|
580
|
+
res.dayPeriod = dayPeriod;
|
|
581
|
+
res.hour = hour;
|
|
582
|
+
} else res[field] = placeholder[field];
|
|
583
|
+
if (field === "year" && res.era == null) res.era = placeholder.era;
|
|
584
|
+
return res;
|
|
585
|
+
}
|
|
586
|
+
switch (field) {
|
|
587
|
+
case "era": {
|
|
588
|
+
const eras = this.calendar.getEras();
|
|
589
|
+
let index = eras.indexOf(res.era);
|
|
590
|
+
index = cycleValue(index, amount, 0, eras.length - 1);
|
|
591
|
+
res.era = eras[index];
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
case "year": {
|
|
595
|
+
let date = new _internationalized_date.CalendarDate(this.calendar, this.era ?? placeholder.era, this.year ?? placeholder.year, this.month ?? 1, this.day ?? 1);
|
|
596
|
+
date = date.cycle(field, amount, { round: field === "year" });
|
|
597
|
+
res.era = date.era;
|
|
598
|
+
res.year = date.year;
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
case "month":
|
|
602
|
+
res.month = cycleValue(res.month ?? 1, amount, 1, this.calendar.getMaximumMonthsInYear());
|
|
603
|
+
break;
|
|
604
|
+
case "day":
|
|
605
|
+
res.day = cycleValue(res.day ?? 1, amount, 1, this.calendar.getMaximumDaysInMonth());
|
|
606
|
+
break;
|
|
607
|
+
case "hour": {
|
|
608
|
+
const hasDateSegments = displaySegments.some((s) => [
|
|
609
|
+
"year",
|
|
610
|
+
"month",
|
|
611
|
+
"day"
|
|
612
|
+
].includes(s));
|
|
613
|
+
if ("timeZone" in placeholder && (!hasDateSegments || res.year != null && res.month != null && res.day != null)) {
|
|
614
|
+
let date = this.toValue(placeholder);
|
|
615
|
+
date = date.cycle("hour", amount, {
|
|
616
|
+
hourCycle: this.hourCycle === "h12" ? 12 : 24,
|
|
617
|
+
round: false
|
|
618
|
+
});
|
|
619
|
+
const [dayPeriod, adjustedHour] = toHourCycle(date.hour, this.hourCycle);
|
|
620
|
+
res.hour = adjustedHour;
|
|
621
|
+
res.dayPeriod = dayPeriod;
|
|
622
|
+
res.offset = date.offset;
|
|
623
|
+
} else {
|
|
624
|
+
const hours = res.hour ?? 0;
|
|
625
|
+
const limits = this.getSegmentLimits("hour");
|
|
626
|
+
res.hour = cycleValue(hours, amount, limits.minValue, limits.maxValue);
|
|
627
|
+
if (res.dayPeriod == null && "hour" in placeholder) res.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];
|
|
628
|
+
}
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
case "dayPeriod":
|
|
632
|
+
res.dayPeriod = cycleValue(res.dayPeriod ?? 0, amount, 0, 1);
|
|
633
|
+
break;
|
|
634
|
+
case "minute":
|
|
635
|
+
res.minute = cycleValue(res.minute ?? 0, amount, 0, 59, true);
|
|
636
|
+
break;
|
|
637
|
+
case "second":
|
|
638
|
+
res.second = cycleValue(res.second ?? 0, amount, 0, 59, true);
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
return res;
|
|
642
|
+
}
|
|
643
|
+
toValue(value) {
|
|
644
|
+
if ("hour" in value) {
|
|
645
|
+
let hour = this.hour;
|
|
646
|
+
if (hour != null) hour = fromHourCycle(hour, this.dayPeriod ?? 0, this.hourCycle);
|
|
647
|
+
else if (this.hourCycle === "h12" || this.hourCycle === "h11") hour = this.dayPeriod === 1 ? 12 : 0;
|
|
648
|
+
const res = value.set({
|
|
649
|
+
era: this.era ?? value.era,
|
|
650
|
+
year: this.year ?? value.year,
|
|
651
|
+
month: this.month ?? value.month,
|
|
652
|
+
day: this.day ?? value.day,
|
|
653
|
+
hour: hour ?? value.hour,
|
|
654
|
+
minute: this.minute ?? value.minute,
|
|
655
|
+
second: this.second ?? value.second,
|
|
656
|
+
millisecond: this.millisecond ?? value.millisecond
|
|
657
|
+
});
|
|
658
|
+
if ("offset" in res && this.offset != null && res.offset !== this.offset) return res.add({ milliseconds: res.offset - this.offset });
|
|
659
|
+
return res;
|
|
660
|
+
} else return value.set({
|
|
661
|
+
era: this.era ?? value.era,
|
|
662
|
+
year: this.year ?? value.year,
|
|
663
|
+
month: this.month ?? value.month,
|
|
664
|
+
day: this.day ?? value.day
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
getSegmentLimits(type) {
|
|
668
|
+
switch (type) {
|
|
669
|
+
case "era": {
|
|
670
|
+
const eras = this.calendar.getEras();
|
|
671
|
+
return {
|
|
672
|
+
value: this.era != null ? eras.indexOf(this.era) : eras.length - 1,
|
|
673
|
+
minValue: 0,
|
|
674
|
+
maxValue: eras.length - 1
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
case "year": return {
|
|
678
|
+
value: this.year,
|
|
679
|
+
minValue: 1,
|
|
680
|
+
maxValue: 9999
|
|
681
|
+
};
|
|
682
|
+
case "month": return {
|
|
683
|
+
value: this.month,
|
|
684
|
+
minValue: 1,
|
|
685
|
+
maxValue: this.calendar.getMaximumMonthsInYear()
|
|
686
|
+
};
|
|
687
|
+
case "day": return {
|
|
688
|
+
value: this.day,
|
|
689
|
+
minValue: 1,
|
|
690
|
+
maxValue: this.calendar.getMaximumDaysInMonth()
|
|
691
|
+
};
|
|
692
|
+
case "dayPeriod": return {
|
|
693
|
+
value: this.dayPeriod,
|
|
694
|
+
minValue: 0,
|
|
695
|
+
maxValue: 1
|
|
696
|
+
};
|
|
697
|
+
case "hour": {
|
|
698
|
+
let minValue = 0;
|
|
699
|
+
let maxValue = 23;
|
|
700
|
+
if (this.hourCycle === "h12") {
|
|
701
|
+
minValue = 1;
|
|
702
|
+
maxValue = 12;
|
|
703
|
+
} else if (this.hourCycle === "h11") {
|
|
704
|
+
minValue = 0;
|
|
705
|
+
maxValue = 11;
|
|
706
|
+
}
|
|
707
|
+
return {
|
|
708
|
+
value: this.hour,
|
|
709
|
+
minValue,
|
|
710
|
+
maxValue
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
case "minute": return {
|
|
714
|
+
value: this.minute,
|
|
715
|
+
minValue: 0,
|
|
716
|
+
maxValue: 59
|
|
717
|
+
};
|
|
718
|
+
case "second": return {
|
|
719
|
+
value: this.second,
|
|
720
|
+
minValue: 0,
|
|
721
|
+
maxValue: 59
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
toString() {
|
|
726
|
+
const fields = {
|
|
727
|
+
era: this.era,
|
|
728
|
+
year: this.year,
|
|
729
|
+
month: this.month,
|
|
730
|
+
day: this.day,
|
|
731
|
+
hour: this.hour,
|
|
732
|
+
dayPeriod: this.dayPeriod,
|
|
733
|
+
minute: this.minute,
|
|
734
|
+
second: this.second
|
|
735
|
+
};
|
|
736
|
+
const parts = Object.entries(fields).filter(([, v]) => v != null).map(([k, v]) => `${k}=${v}`);
|
|
737
|
+
return parts.length > 0 ? parts.join(",") : "-";
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
function cycleValue(value, amount, min, max, round = false) {
|
|
741
|
+
if (round) {
|
|
742
|
+
value += Math.sign(amount);
|
|
743
|
+
if (value < min) value = max;
|
|
744
|
+
const div = Math.abs(amount);
|
|
745
|
+
if (amount > 0) value = Math.ceil(value / div) * div;
|
|
746
|
+
else value = Math.floor(value / div) * div;
|
|
747
|
+
if (value > max) value = min;
|
|
748
|
+
} else {
|
|
749
|
+
value += amount;
|
|
750
|
+
if (value < min) value = max - (min - value - 1);
|
|
751
|
+
else if (value > max) value = min + (value - max - 1);
|
|
752
|
+
}
|
|
753
|
+
return value;
|
|
754
|
+
}
|
|
755
|
+
function toHourCycle(hour, hourCycle) {
|
|
756
|
+
let dayPeriod = hour >= 12 ? 1 : 0;
|
|
757
|
+
switch (hourCycle) {
|
|
758
|
+
case "h11":
|
|
759
|
+
if (hour >= 12) hour -= 12;
|
|
760
|
+
break;
|
|
761
|
+
case "h12":
|
|
762
|
+
if (hour === 0) hour = 12;
|
|
763
|
+
else if (hour > 12) hour -= 12;
|
|
764
|
+
break;
|
|
765
|
+
case "h23":
|
|
766
|
+
dayPeriod = null;
|
|
767
|
+
break;
|
|
768
|
+
case "h24":
|
|
769
|
+
hour += 1;
|
|
770
|
+
dayPeriod = null;
|
|
771
|
+
}
|
|
772
|
+
return [dayPeriod, hour];
|
|
773
|
+
}
|
|
774
|
+
function fromHourCycle(hour, dayPeriod, hourCycle) {
|
|
775
|
+
switch (hourCycle) {
|
|
776
|
+
case "h11":
|
|
777
|
+
if (dayPeriod === 1) hour += 12;
|
|
778
|
+
break;
|
|
779
|
+
case "h12":
|
|
780
|
+
if (hour === 12) hour = 0;
|
|
781
|
+
if (dayPeriod === 1) hour += 12;
|
|
782
|
+
break;
|
|
783
|
+
case "h24":
|
|
784
|
+
hour -= 1;
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
return hour;
|
|
788
|
+
}
|
|
789
|
+
//#endregion
|
|
790
|
+
//#region src/machines/date-input/utils/input.ts
|
|
791
|
+
function isNumberString(value) {
|
|
792
|
+
return !Number.isNaN(Number.parseInt(value));
|
|
793
|
+
}
|
|
794
|
+
function updateSegmentValue(ctx, segment, input) {
|
|
795
|
+
const { context, prop } = ctx;
|
|
796
|
+
const type = segment.type;
|
|
797
|
+
const index = context.get("activeIndex");
|
|
798
|
+
const formatter = prop("formatter");
|
|
799
|
+
const enteredKeys = context.get("enteredKeys");
|
|
800
|
+
const placeholderValue = context.get("placeholderValue");
|
|
801
|
+
let dv = getActiveDisplayValue(ctx);
|
|
802
|
+
switch (type) {
|
|
803
|
+
case "dayPeriod": {
|
|
804
|
+
if (!("hour" in dv.toValue(placeholderValue))) return;
|
|
805
|
+
const amPmFormatter = new _internationalized_date.DateFormatter(prop("locale"), {
|
|
806
|
+
hour: "numeric",
|
|
807
|
+
hour12: true
|
|
808
|
+
});
|
|
809
|
+
const amDate = /* @__PURE__ */ new Date();
|
|
810
|
+
amDate.setHours(0);
|
|
811
|
+
const pmDate = /* @__PURE__ */ new Date();
|
|
812
|
+
pmDate.setHours(12);
|
|
813
|
+
const am = amPmFormatter.formatToParts(amDate).find((p) => p.type === "dayPeriod")?.value || "AM";
|
|
814
|
+
const pm = amPmFormatter.formatToParts(pmDate).find((p) => p.type === "dayPeriod")?.value || "PM";
|
|
815
|
+
const lowerInput = input.toLowerCase();
|
|
816
|
+
if (am.toLowerCase().startsWith(lowerInput)) setDisplayValue(ctx, index, dv.set("dayPeriod", 0, placeholderValue));
|
|
817
|
+
else if (pm.toLowerCase().startsWith(lowerInput)) setDisplayValue(ctx, index, dv.set("dayPeriod", 12, placeholderValue));
|
|
818
|
+
else break;
|
|
819
|
+
advanceToNextSegment(ctx);
|
|
820
|
+
break;
|
|
821
|
+
}
|
|
822
|
+
case "era": {
|
|
823
|
+
const eras = dv.calendar.getEras();
|
|
824
|
+
const eraFormatter = new _internationalized_date.DateFormatter(prop("locale"), { era: "short" });
|
|
825
|
+
const lowerInput = input.toLowerCase();
|
|
826
|
+
for (let i = 0; i < eras.length; i++) {
|
|
827
|
+
const eraDate = dv.toValue(placeholderValue).set({ year: 1 }).toDate(prop("timeZone"));
|
|
828
|
+
const formattedEra = eraFormatter.formatToParts(eraDate).find((p) => p.type === "era")?.value;
|
|
829
|
+
if (formattedEra && formattedEra.toLowerCase().startsWith(lowerInput)) {
|
|
830
|
+
setDisplayValue(ctx, index, dv.set("era", eras[i], placeholderValue));
|
|
831
|
+
advanceToNextSegment(ctx);
|
|
832
|
+
break;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
break;
|
|
836
|
+
}
|
|
837
|
+
case "day":
|
|
838
|
+
case "hour":
|
|
839
|
+
case "minute":
|
|
840
|
+
case "second":
|
|
841
|
+
case "month":
|
|
842
|
+
case "year": {
|
|
843
|
+
let newValue = enteredKeys + input;
|
|
844
|
+
let numberValue = Number.parseInt(newValue);
|
|
845
|
+
let segmentValue = numberValue;
|
|
846
|
+
let allowsZero = segment.minValue === 0;
|
|
847
|
+
if (!isNumberString(input)) return;
|
|
848
|
+
if (segment.type === "hour" && formatter.resolvedOptions().hour12) {
|
|
849
|
+
switch (formatter.resolvedOptions().hourCycle) {
|
|
850
|
+
case "h11":
|
|
851
|
+
if (numberValue > 11) segmentValue = Number.parseInt(input);
|
|
852
|
+
break;
|
|
853
|
+
case "h12":
|
|
854
|
+
allowsZero = false;
|
|
855
|
+
if (numberValue > 12) segmentValue = Number.parseInt(input);
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
858
|
+
if (segment.value !== void 0 && segment.value >= 12 && numberValue > 1) numberValue += 12;
|
|
859
|
+
} else if (segment.maxValue !== void 0 && numberValue > segment.maxValue) segmentValue = Number.parseInt(input);
|
|
860
|
+
if (isNaN(numberValue)) return;
|
|
861
|
+
const shouldSetValue = segmentValue !== 0 || allowsZero;
|
|
862
|
+
if (shouldSetValue) {
|
|
863
|
+
dv = dv.set(type, segmentValue, placeholderValue);
|
|
864
|
+
setDisplayValue(ctx, index, dv);
|
|
865
|
+
}
|
|
866
|
+
if (segment.maxValue !== void 0 && (Number(numberValue + "0") > segment.maxValue || newValue.length >= String(segment.maxValue).length)) {
|
|
867
|
+
context.set("enteredKeys", "");
|
|
868
|
+
if (shouldSetValue) advanceToNextSegment(ctx);
|
|
869
|
+
} else context.set("enteredKeys", newValue);
|
|
870
|
+
break;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
//#endregion
|
|
875
|
+
//#region src/machines/date-input/utils/placeholders.ts
|
|
876
|
+
const LOCALE_PLACEHOLDERS = {
|
|
877
|
+
ach: {
|
|
878
|
+
year: "mwaka",
|
|
879
|
+
month: "dwe",
|
|
880
|
+
day: "nino"
|
|
881
|
+
},
|
|
882
|
+
af: {
|
|
883
|
+
year: "jjjj",
|
|
884
|
+
month: "mm",
|
|
885
|
+
day: "dd"
|
|
886
|
+
},
|
|
887
|
+
am: {
|
|
888
|
+
year: "ዓዓዓዓ",
|
|
889
|
+
month: "ሚሜ",
|
|
890
|
+
day: "ቀቀ"
|
|
891
|
+
},
|
|
892
|
+
an: {
|
|
893
|
+
year: "aaaa",
|
|
894
|
+
month: "mm",
|
|
895
|
+
day: "dd"
|
|
896
|
+
},
|
|
897
|
+
ar: {
|
|
898
|
+
year: "سنة",
|
|
899
|
+
month: "شهر",
|
|
900
|
+
day: "يوم"
|
|
901
|
+
},
|
|
902
|
+
ast: {
|
|
903
|
+
year: "aaaa",
|
|
904
|
+
month: "mm",
|
|
905
|
+
day: "dd"
|
|
906
|
+
},
|
|
907
|
+
az: {
|
|
908
|
+
year: "iiii",
|
|
909
|
+
month: "aa",
|
|
910
|
+
day: "gg"
|
|
911
|
+
},
|
|
912
|
+
be: {
|
|
913
|
+
year: "гггг",
|
|
914
|
+
month: "мм",
|
|
915
|
+
day: "дд"
|
|
916
|
+
},
|
|
917
|
+
bg: {
|
|
918
|
+
year: "гггг",
|
|
919
|
+
month: "мм",
|
|
920
|
+
day: "дд"
|
|
921
|
+
},
|
|
922
|
+
bn: {
|
|
923
|
+
year: "yyyy",
|
|
924
|
+
month: "মিমি",
|
|
925
|
+
day: "dd"
|
|
926
|
+
},
|
|
927
|
+
br: {
|
|
928
|
+
year: "bbbb",
|
|
929
|
+
month: "mm",
|
|
930
|
+
day: "dd"
|
|
931
|
+
},
|
|
932
|
+
bs: {
|
|
933
|
+
year: "gggg",
|
|
934
|
+
month: "mm",
|
|
935
|
+
day: "dd"
|
|
936
|
+
},
|
|
937
|
+
ca: {
|
|
938
|
+
year: "aaaa",
|
|
939
|
+
month: "mm",
|
|
940
|
+
day: "dd"
|
|
941
|
+
},
|
|
942
|
+
cak: {
|
|
943
|
+
year: "jjjj",
|
|
944
|
+
month: "ii",
|
|
945
|
+
day: "q'q'"
|
|
946
|
+
},
|
|
947
|
+
ckb: {
|
|
948
|
+
year: "ساڵ",
|
|
949
|
+
month: "مانگ",
|
|
950
|
+
day: "ڕۆژ"
|
|
951
|
+
},
|
|
952
|
+
cs: {
|
|
953
|
+
year: "rrrr",
|
|
954
|
+
month: "mm",
|
|
955
|
+
day: "dd"
|
|
956
|
+
},
|
|
957
|
+
cy: {
|
|
958
|
+
year: "bbbb",
|
|
959
|
+
month: "mm",
|
|
960
|
+
day: "dd"
|
|
961
|
+
},
|
|
962
|
+
da: {
|
|
963
|
+
year: "åååå",
|
|
964
|
+
month: "mm",
|
|
965
|
+
day: "dd"
|
|
966
|
+
},
|
|
967
|
+
de: {
|
|
968
|
+
year: "jjjj",
|
|
969
|
+
month: "mm",
|
|
970
|
+
day: "tt"
|
|
971
|
+
},
|
|
972
|
+
dsb: {
|
|
973
|
+
year: "llll",
|
|
974
|
+
month: "mm",
|
|
975
|
+
day: "źź"
|
|
976
|
+
},
|
|
977
|
+
el: {
|
|
978
|
+
year: "εεεε",
|
|
979
|
+
month: "μμ",
|
|
980
|
+
day: "ηη"
|
|
981
|
+
},
|
|
982
|
+
en: {
|
|
983
|
+
year: "yyyy",
|
|
984
|
+
month: "mm",
|
|
985
|
+
day: "dd"
|
|
986
|
+
},
|
|
987
|
+
eo: {
|
|
988
|
+
year: "jjjj",
|
|
989
|
+
month: "mm",
|
|
990
|
+
day: "tt"
|
|
991
|
+
},
|
|
992
|
+
es: {
|
|
993
|
+
year: "aaaa",
|
|
994
|
+
month: "mm",
|
|
995
|
+
day: "dd"
|
|
996
|
+
},
|
|
997
|
+
et: {
|
|
998
|
+
year: "aaaa",
|
|
999
|
+
month: "kk",
|
|
1000
|
+
day: "pp"
|
|
1001
|
+
},
|
|
1002
|
+
eu: {
|
|
1003
|
+
year: "uuuu",
|
|
1004
|
+
month: "hh",
|
|
1005
|
+
day: "ee"
|
|
1006
|
+
},
|
|
1007
|
+
fa: {
|
|
1008
|
+
year: "سال",
|
|
1009
|
+
month: "ماه",
|
|
1010
|
+
day: "روز"
|
|
1011
|
+
},
|
|
1012
|
+
ff: {
|
|
1013
|
+
year: "hhhh",
|
|
1014
|
+
month: "ll",
|
|
1015
|
+
day: "ññ"
|
|
1016
|
+
},
|
|
1017
|
+
fi: {
|
|
1018
|
+
year: "vvvv",
|
|
1019
|
+
month: "kk",
|
|
1020
|
+
day: "pp"
|
|
1021
|
+
},
|
|
1022
|
+
fr: {
|
|
1023
|
+
year: "aaaa",
|
|
1024
|
+
month: "mm",
|
|
1025
|
+
day: "jj"
|
|
1026
|
+
},
|
|
1027
|
+
fy: {
|
|
1028
|
+
year: "jjjj",
|
|
1029
|
+
month: "mm",
|
|
1030
|
+
day: "dd"
|
|
1031
|
+
},
|
|
1032
|
+
ga: {
|
|
1033
|
+
year: "bbbb",
|
|
1034
|
+
month: "mm",
|
|
1035
|
+
day: "ll"
|
|
1036
|
+
},
|
|
1037
|
+
gd: {
|
|
1038
|
+
year: "bbbb",
|
|
1039
|
+
month: "mm",
|
|
1040
|
+
day: "ll"
|
|
1041
|
+
},
|
|
1042
|
+
gl: {
|
|
1043
|
+
year: "aaaa",
|
|
1044
|
+
month: "mm",
|
|
1045
|
+
day: "dd"
|
|
1046
|
+
},
|
|
1047
|
+
he: {
|
|
1048
|
+
year: "שנה",
|
|
1049
|
+
month: "חודש",
|
|
1050
|
+
day: "יום"
|
|
1051
|
+
},
|
|
1052
|
+
hr: {
|
|
1053
|
+
year: "gggg",
|
|
1054
|
+
month: "mm",
|
|
1055
|
+
day: "dd"
|
|
1056
|
+
},
|
|
1057
|
+
hsb: {
|
|
1058
|
+
year: "llll",
|
|
1059
|
+
month: "mm",
|
|
1060
|
+
day: "dd"
|
|
1061
|
+
},
|
|
1062
|
+
hu: {
|
|
1063
|
+
year: "éééé",
|
|
1064
|
+
month: "hh",
|
|
1065
|
+
day: "nn"
|
|
1066
|
+
},
|
|
1067
|
+
ia: {
|
|
1068
|
+
year: "aaaa",
|
|
1069
|
+
month: "mm",
|
|
1070
|
+
day: "dd"
|
|
1071
|
+
},
|
|
1072
|
+
id: {
|
|
1073
|
+
year: "tttt",
|
|
1074
|
+
month: "bb",
|
|
1075
|
+
day: "hh"
|
|
1076
|
+
},
|
|
1077
|
+
it: {
|
|
1078
|
+
year: "aaaa",
|
|
1079
|
+
month: "mm",
|
|
1080
|
+
day: "gg"
|
|
1081
|
+
},
|
|
1082
|
+
ja: {
|
|
1083
|
+
year: "年",
|
|
1084
|
+
month: "月",
|
|
1085
|
+
day: "日"
|
|
1086
|
+
},
|
|
1087
|
+
ka: {
|
|
1088
|
+
year: "წწწწ",
|
|
1089
|
+
month: "თთ",
|
|
1090
|
+
day: "რრ"
|
|
1091
|
+
},
|
|
1092
|
+
kk: {
|
|
1093
|
+
year: "жжжж",
|
|
1094
|
+
month: "аа",
|
|
1095
|
+
day: "кк"
|
|
1096
|
+
},
|
|
1097
|
+
kn: {
|
|
1098
|
+
year: "ವವವವ",
|
|
1099
|
+
month: "ಮಿಮೀ",
|
|
1100
|
+
day: "ದಿದಿ"
|
|
1101
|
+
},
|
|
1102
|
+
ko: {
|
|
1103
|
+
year: "연도",
|
|
1104
|
+
month: "월",
|
|
1105
|
+
day: "일"
|
|
1106
|
+
},
|
|
1107
|
+
lb: {
|
|
1108
|
+
year: "jjjj",
|
|
1109
|
+
month: "mm",
|
|
1110
|
+
day: "dd"
|
|
1111
|
+
},
|
|
1112
|
+
lo: {
|
|
1113
|
+
year: "ປປປປ",
|
|
1114
|
+
month: "ດດ",
|
|
1115
|
+
day: "ວວ"
|
|
1116
|
+
},
|
|
1117
|
+
lt: {
|
|
1118
|
+
year: "mmmm",
|
|
1119
|
+
month: "mm",
|
|
1120
|
+
day: "dd"
|
|
1121
|
+
},
|
|
1122
|
+
lv: {
|
|
1123
|
+
year: "gggg",
|
|
1124
|
+
month: "mm",
|
|
1125
|
+
day: "dd"
|
|
1126
|
+
},
|
|
1127
|
+
meh: {
|
|
1128
|
+
year: "aaaa",
|
|
1129
|
+
month: "mm",
|
|
1130
|
+
day: "dd"
|
|
1131
|
+
},
|
|
1132
|
+
ml: {
|
|
1133
|
+
year: "വർഷം",
|
|
1134
|
+
month: "മാസം",
|
|
1135
|
+
day: "തീയതി"
|
|
1136
|
+
},
|
|
1137
|
+
ms: {
|
|
1138
|
+
year: "tttt",
|
|
1139
|
+
month: "mm",
|
|
1140
|
+
day: "hh"
|
|
1141
|
+
},
|
|
1142
|
+
nl: {
|
|
1143
|
+
year: "jjjj",
|
|
1144
|
+
month: "mm",
|
|
1145
|
+
day: "dd"
|
|
1146
|
+
},
|
|
1147
|
+
nn: {
|
|
1148
|
+
year: "åååå",
|
|
1149
|
+
month: "mm",
|
|
1150
|
+
day: "dd"
|
|
1151
|
+
},
|
|
1152
|
+
no: {
|
|
1153
|
+
year: "åååå",
|
|
1154
|
+
month: "mm",
|
|
1155
|
+
day: "dd"
|
|
1156
|
+
},
|
|
1157
|
+
oc: {
|
|
1158
|
+
year: "aaaa",
|
|
1159
|
+
month: "mm",
|
|
1160
|
+
day: "jj"
|
|
1161
|
+
},
|
|
1162
|
+
pl: {
|
|
1163
|
+
year: "rrrr",
|
|
1164
|
+
month: "mm",
|
|
1165
|
+
day: "dd"
|
|
1166
|
+
},
|
|
1167
|
+
pt: {
|
|
1168
|
+
year: "aaaa",
|
|
1169
|
+
month: "mm",
|
|
1170
|
+
day: "dd"
|
|
1171
|
+
},
|
|
1172
|
+
rm: {
|
|
1173
|
+
year: "oooo",
|
|
1174
|
+
month: "mm",
|
|
1175
|
+
day: "dd"
|
|
1176
|
+
},
|
|
1177
|
+
ro: {
|
|
1178
|
+
year: "aaaa",
|
|
1179
|
+
month: "ll",
|
|
1180
|
+
day: "zz"
|
|
1181
|
+
},
|
|
1182
|
+
ru: {
|
|
1183
|
+
year: "гггг",
|
|
1184
|
+
month: "мм",
|
|
1185
|
+
day: "дд"
|
|
1186
|
+
},
|
|
1187
|
+
sc: {
|
|
1188
|
+
year: "aaaa",
|
|
1189
|
+
month: "mm",
|
|
1190
|
+
day: "dd"
|
|
1191
|
+
},
|
|
1192
|
+
scn: {
|
|
1193
|
+
year: "aaaa",
|
|
1194
|
+
month: "mm",
|
|
1195
|
+
day: "jj"
|
|
1196
|
+
},
|
|
1197
|
+
sk: {
|
|
1198
|
+
year: "rrrr",
|
|
1199
|
+
month: "mm",
|
|
1200
|
+
day: "dd"
|
|
1201
|
+
},
|
|
1202
|
+
sl: {
|
|
1203
|
+
year: "llll",
|
|
1204
|
+
month: "mm",
|
|
1205
|
+
day: "dd"
|
|
1206
|
+
},
|
|
1207
|
+
sr: {
|
|
1208
|
+
year: "гггг",
|
|
1209
|
+
month: "мм",
|
|
1210
|
+
day: "дд"
|
|
1211
|
+
},
|
|
1212
|
+
sv: {
|
|
1213
|
+
year: "åååå",
|
|
1214
|
+
month: "mm",
|
|
1215
|
+
day: "dd"
|
|
1216
|
+
},
|
|
1217
|
+
szl: {
|
|
1218
|
+
year: "rrrr",
|
|
1219
|
+
month: "mm",
|
|
1220
|
+
day: "dd"
|
|
1221
|
+
},
|
|
1222
|
+
tg: {
|
|
1223
|
+
year: "сссс",
|
|
1224
|
+
month: "мм",
|
|
1225
|
+
day: "рр"
|
|
1226
|
+
},
|
|
1227
|
+
th: {
|
|
1228
|
+
year: "ปปปป",
|
|
1229
|
+
month: "ดด",
|
|
1230
|
+
day: "วว"
|
|
1231
|
+
},
|
|
1232
|
+
tr: {
|
|
1233
|
+
year: "yyyy",
|
|
1234
|
+
month: "aa",
|
|
1235
|
+
day: "gg"
|
|
1236
|
+
},
|
|
1237
|
+
uk: {
|
|
1238
|
+
year: "рррр",
|
|
1239
|
+
month: "мм",
|
|
1240
|
+
day: "дд"
|
|
1241
|
+
},
|
|
1242
|
+
"zh-CN": {
|
|
1243
|
+
year: "年",
|
|
1244
|
+
month: "月",
|
|
1245
|
+
day: "日"
|
|
1246
|
+
},
|
|
1247
|
+
"zh-TW": {
|
|
1248
|
+
year: "年",
|
|
1249
|
+
month: "月",
|
|
1250
|
+
day: "日"
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
function getLocaleLanguage(locale) {
|
|
1254
|
+
if (typeof Intl !== "undefined" && Intl.Locale) return new Intl.Locale(locale).language;
|
|
1255
|
+
return locale.split("-")[0];
|
|
1256
|
+
}
|
|
1257
|
+
function getLocalePlaceholders(locale) {
|
|
1258
|
+
if (locale in LOCALE_PLACEHOLDERS) return LOCALE_PLACEHOLDERS[locale];
|
|
1259
|
+
const lang = getLocaleLanguage(locale);
|
|
1260
|
+
if (lang in LOCALE_PLACEHOLDERS) return LOCALE_PLACEHOLDERS[lang];
|
|
1261
|
+
return LOCALE_PLACEHOLDERS.en;
|
|
1262
|
+
}
|
|
1263
|
+
const defaultTranslations = { placeholder(locale) {
|
|
1264
|
+
const localized = getLocalePlaceholders(locale);
|
|
1265
|
+
return {
|
|
1266
|
+
day: localized.day,
|
|
1267
|
+
month: localized.month,
|
|
1268
|
+
year: localized.year,
|
|
1269
|
+
hour: "––",
|
|
1270
|
+
minute: "––",
|
|
1271
|
+
second: "––",
|
|
1272
|
+
dayPeriod: "AM/PM",
|
|
1273
|
+
era: "era",
|
|
1274
|
+
timeZoneName: "timeZone",
|
|
1275
|
+
weekday: "weekday",
|
|
1276
|
+
unknown: "unknown",
|
|
1277
|
+
fractionalSecond: "ff"
|
|
1278
|
+
};
|
|
1279
|
+
} };
|
|
1280
|
+
//#endregion
|
|
1281
|
+
//#region src/machines/date-input/utils/formatting.ts
|
|
1282
|
+
function getValueAsString(value, prop) {
|
|
1283
|
+
return value.map((date) => {
|
|
1284
|
+
if (date == null) return "";
|
|
1285
|
+
try {
|
|
1286
|
+
return prop("format")(date, {
|
|
1287
|
+
locale: prop("locale"),
|
|
1288
|
+
timeZone: prop("timeZone")
|
|
1289
|
+
});
|
|
1290
|
+
} catch {
|
|
1291
|
+
return "";
|
|
1292
|
+
}
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
//#endregion
|
|
1296
|
+
//#region src/machines/date-input/date-input.machine.ts
|
|
1297
|
+
function resolvedHourCycle(formatter) {
|
|
1298
|
+
const hc = formatter.resolvedOptions().hourCycle;
|
|
1299
|
+
if (hc === "h11" || hc === "h12" || hc === "h23" || hc === "h24") return hc;
|
|
1300
|
+
return "h23";
|
|
1301
|
+
}
|
|
1302
|
+
function initDisplayValues(value, placeholderValue, hourCycle, count) {
|
|
1303
|
+
const calendar = placeholderValue.calendar;
|
|
1304
|
+
if (value?.length) return Array.from({ length: count }, (_, i) => value[i] ? new IncompleteDate(calendar, hourCycle, value[i]) : new IncompleteDate(calendar, hourCycle));
|
|
1305
|
+
return Array.from({ length: count }, () => new IncompleteDate(calendar, hourCycle));
|
|
1306
|
+
}
|
|
1307
|
+
function incompleteDateHash(dv) {
|
|
1308
|
+
return `${dv.year}|${dv.month}|${dv.day}|${dv.hour}|${dv.dayPeriod}|${dv.minute}|${dv.second}|${dv.era}`;
|
|
1309
|
+
}
|
|
1310
|
+
function incompleteDateEqual(a, b) {
|
|
1311
|
+
return incompleteDateHash(a) === incompleteDateHash(b);
|
|
1312
|
+
}
|
|
1313
|
+
const machine = require_core.createMachine({
|
|
1314
|
+
props({ props }) {
|
|
1315
|
+
const locale = props.locale || "en-US";
|
|
1316
|
+
const timeZone = props.timeZone || "UTC";
|
|
1317
|
+
const selectionMode = props.selectionMode || "single";
|
|
1318
|
+
const granularity = props.granularity || "day";
|
|
1319
|
+
const translations = {
|
|
1320
|
+
...defaultTranslations,
|
|
1321
|
+
...props.translations
|
|
1322
|
+
};
|
|
1323
|
+
const defaultValue = props.defaultValue ? props.defaultValue.map((date) => require_date_utils.constrainValue(date, props.min, props.max)) : void 0;
|
|
1324
|
+
const value = props.value ? props.value.map((date) => require_date_utils.constrainValue(date, props.min, props.max)) : void 0;
|
|
1325
|
+
let placeholderValue = props.placeholderValue || props.defaultPlaceholderValue || value?.[0] || defaultValue?.[0] || require_date_utils.getTodayDate(timeZone);
|
|
1326
|
+
placeholderValue = require_date_utils.constrainValue(placeholderValue, props.min, props.max);
|
|
1327
|
+
if ((granularity === "hour" || granularity === "minute" || granularity === "second") && !("hour" in placeholderValue)) placeholderValue = (0, _internationalized_date.toCalendarDateTime)(placeholderValue);
|
|
1328
|
+
const hourCycle = props.hourCycle === 12 ? "h12" : props.hourCycle === 24 ? "h23" : void 0;
|
|
1329
|
+
const shouldForceLeadingZeros = props.shouldForceLeadingZeros ?? false;
|
|
1330
|
+
const digitStyle = shouldForceLeadingZeros ? "2-digit" : "numeric";
|
|
1331
|
+
const formatterOptions = {
|
|
1332
|
+
timeZone,
|
|
1333
|
+
day: digitStyle,
|
|
1334
|
+
month: digitStyle,
|
|
1335
|
+
year: "numeric",
|
|
1336
|
+
hourCycle
|
|
1337
|
+
};
|
|
1338
|
+
if (granularity === "hour" || granularity === "minute" || granularity === "second") formatterOptions.hour = digitStyle;
|
|
1339
|
+
if (granularity === "minute" || granularity === "second") formatterOptions.minute = "2-digit";
|
|
1340
|
+
if (granularity === "second") formatterOptions.second = "2-digit";
|
|
1341
|
+
const formatter = props.formatter ?? new _internationalized_date.DateFormatter(locale, formatterOptions);
|
|
1342
|
+
const allSegments = props.allSegments ?? (() => {
|
|
1343
|
+
const segs = formatter.formatToParts(/* @__PURE__ */ new Date()).filter((seg) => EDITABLE_SEGMENTS[seg.type]).reduce((p, seg) => {
|
|
1344
|
+
const key = TYPE_MAPPING[seg.type] || seg.type;
|
|
1345
|
+
p[key] = true;
|
|
1346
|
+
return p;
|
|
1347
|
+
}, {});
|
|
1348
|
+
segs.era = true;
|
|
1349
|
+
return segs;
|
|
1350
|
+
})();
|
|
1351
|
+
return {
|
|
1352
|
+
locale,
|
|
1353
|
+
timeZone,
|
|
1354
|
+
selectionMode,
|
|
1355
|
+
format(date, { timeZone }) {
|
|
1356
|
+
const jsd = date.toDate(timeZone);
|
|
1357
|
+
if (date.calendar?.identifier === "gregory" && date.era === "BC") {
|
|
1358
|
+
const prolYear = jsd.getUTCFullYear();
|
|
1359
|
+
const safeDate = new Date(Date.UTC(2e3, jsd.getUTCMonth(), jsd.getUTCDate()));
|
|
1360
|
+
return formatter.formatToParts(safeDate).map((p) => p.type === "year" ? String(prolYear) : p.value).join("");
|
|
1361
|
+
}
|
|
1362
|
+
return formatter.format(jsd);
|
|
1363
|
+
},
|
|
1364
|
+
...props,
|
|
1365
|
+
translations,
|
|
1366
|
+
value,
|
|
1367
|
+
defaultValue: defaultValue ?? [],
|
|
1368
|
+
granularity,
|
|
1369
|
+
shouldForceLeadingZeros,
|
|
1370
|
+
formatter,
|
|
1371
|
+
placeholderValue: typeof props.placeholderValue === "undefined" ? void 0 : placeholderValue,
|
|
1372
|
+
defaultPlaceholderValue: placeholderValue,
|
|
1373
|
+
allSegments
|
|
1374
|
+
};
|
|
1375
|
+
},
|
|
1376
|
+
initialState() {
|
|
1377
|
+
return "idle";
|
|
1378
|
+
},
|
|
1379
|
+
refs() {
|
|
1380
|
+
return {
|
|
1381
|
+
announcer: null,
|
|
1382
|
+
segmentToAnnounceIndex: null
|
|
1383
|
+
};
|
|
1384
|
+
},
|
|
1385
|
+
effects: ["setupLiveRegion"],
|
|
1386
|
+
context({ prop, bindable }) {
|
|
1387
|
+
const hc = resolvedHourCycle(prop("formatter"));
|
|
1388
|
+
const placeholderValue = prop("defaultPlaceholderValue");
|
|
1389
|
+
const groupCount = prop("selectionMode") === "range" ? 2 : 1;
|
|
1390
|
+
const initialValue = prop("value") || prop("defaultValue");
|
|
1391
|
+
return {
|
|
1392
|
+
value: bindable(() => ({
|
|
1393
|
+
defaultValue: prop("defaultValue"),
|
|
1394
|
+
value: prop("value"),
|
|
1395
|
+
isEqual(a, b) {
|
|
1396
|
+
if (a?.length !== b?.length) return false;
|
|
1397
|
+
const len = Math.max(a.length, b.length);
|
|
1398
|
+
for (let i = 0; i < len; i++) if (!require_date_utils.isDateEqual(a[i], b[i])) return false;
|
|
1399
|
+
return true;
|
|
1400
|
+
},
|
|
1401
|
+
hash: (v) => v.map((date) => date?.toString() ?? "").join(","),
|
|
1402
|
+
onChange(value) {
|
|
1403
|
+
const valueAsString = getValueAsString(value, prop);
|
|
1404
|
+
prop("onValueChange")?.({
|
|
1405
|
+
value,
|
|
1406
|
+
valueAsString
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
})),
|
|
1410
|
+
activeIndex: bindable(() => ({
|
|
1411
|
+
defaultValue: 0,
|
|
1412
|
+
sync: true
|
|
1413
|
+
})),
|
|
1414
|
+
activeSegmentIndex: bindable(() => ({
|
|
1415
|
+
defaultValue: -1,
|
|
1416
|
+
sync: true
|
|
1417
|
+
})),
|
|
1418
|
+
placeholderValue: bindable(() => ({
|
|
1419
|
+
defaultValue: prop("defaultPlaceholderValue"),
|
|
1420
|
+
isEqual: require_date_utils.isDateEqual,
|
|
1421
|
+
hash: (v) => v.toString(),
|
|
1422
|
+
onChange(placeholderValue) {
|
|
1423
|
+
prop("onPlaceholderChange")?.({
|
|
1424
|
+
value: prop("value") ?? [],
|
|
1425
|
+
valueAsString: [],
|
|
1426
|
+
placeholderValue
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
})),
|
|
1430
|
+
displayValues: bindable(() => ({
|
|
1431
|
+
defaultValue: initDisplayValues(initialValue, placeholderValue ?? require_date_utils.getTodayDate(prop("timeZone")), hc, groupCount),
|
|
1432
|
+
isEqual: (a, b) => b != null && a.length === b.length && a.every((d, i) => incompleteDateEqual(d, b[i])),
|
|
1433
|
+
hash: (v) => v.map(incompleteDateHash).join("||")
|
|
1434
|
+
})),
|
|
1435
|
+
enteredKeys: bindable(() => ({
|
|
1436
|
+
defaultValue: "",
|
|
1437
|
+
sync: true
|
|
1438
|
+
}))
|
|
1439
|
+
};
|
|
1440
|
+
},
|
|
1441
|
+
computed: {
|
|
1442
|
+
isInteractive: ({ prop }) => !prop("disabled") && !prop("readOnly"),
|
|
1443
|
+
valueAsString: ({ context, prop }) => getValueAsString(context.get("value"), prop),
|
|
1444
|
+
segments: require_core.memo(({ context, prop }) => [
|
|
1445
|
+
context.hash("value"),
|
|
1446
|
+
prop("selectionMode"),
|
|
1447
|
+
context.hash("placeholderValue"),
|
|
1448
|
+
context.hash("displayValues"),
|
|
1449
|
+
prop("allSegments"),
|
|
1450
|
+
prop("timeZone"),
|
|
1451
|
+
prop("translations"),
|
|
1452
|
+
prop("granularity"),
|
|
1453
|
+
prop("formatter"),
|
|
1454
|
+
prop("locale")
|
|
1455
|
+
], (_deps, { context, prop }) => {
|
|
1456
|
+
const value = context.get("value");
|
|
1457
|
+
const selectionMode = prop("selectionMode");
|
|
1458
|
+
const placeholderValue = context.get("placeholderValue");
|
|
1459
|
+
const displayValues = context.get("displayValues");
|
|
1460
|
+
const allSegments = prop("allSegments");
|
|
1461
|
+
const timeZone = prop("timeZone");
|
|
1462
|
+
const translations = prop("translations") || defaultTranslations;
|
|
1463
|
+
const granularity = prop("granularity");
|
|
1464
|
+
const formatter = prop("formatter");
|
|
1465
|
+
const locale = prop("locale");
|
|
1466
|
+
const allSegmentTypes = Object.keys(allSegments);
|
|
1467
|
+
const groupCount = selectionMode === "range" ? 2 : 1;
|
|
1468
|
+
return Array.from({ length: groupCount }, (_, i) => {
|
|
1469
|
+
const dv = displayValues[i] ?? new IncompleteDate(placeholderValue.calendar, resolvedHourCycle(formatter));
|
|
1470
|
+
const committedValue = value?.[i];
|
|
1471
|
+
const displayDate = committedValue && dv.isComplete(allSegmentTypes) ? committedValue : dv.toValue(placeholderValue);
|
|
1472
|
+
const segmentFormatter = dv.era === "BC" && dv.calendar.identifier === "gregory" ? new _internationalized_date.DateFormatter(locale, {
|
|
1473
|
+
...formatter.resolvedOptions(),
|
|
1474
|
+
era: "short"
|
|
1475
|
+
}) : formatter;
|
|
1476
|
+
return processSegments({
|
|
1477
|
+
dateValue: displayDate.toDate(timeZone),
|
|
1478
|
+
displayValue: dv,
|
|
1479
|
+
formatter: segmentFormatter,
|
|
1480
|
+
locale,
|
|
1481
|
+
translations,
|
|
1482
|
+
granularity
|
|
1483
|
+
});
|
|
1484
|
+
});
|
|
1485
|
+
})
|
|
1486
|
+
},
|
|
1487
|
+
watch({ track, context, prop, action }) {
|
|
1488
|
+
track([() => context.hash("value")], () => {
|
|
1489
|
+
action(["syncDisplayValues"]);
|
|
1490
|
+
});
|
|
1491
|
+
track([() => context.get("activeSegmentIndex")], () => {
|
|
1492
|
+
action(["focusActiveSegment"]);
|
|
1493
|
+
});
|
|
1494
|
+
track([() => prop("placeholderValue")?.toString()], () => {
|
|
1495
|
+
action(["syncPlaceholderProp"]);
|
|
1496
|
+
});
|
|
1497
|
+
},
|
|
1498
|
+
on: {
|
|
1499
|
+
"VALUE.SET": { actions: ["setDateValue"] },
|
|
1500
|
+
"VALUE.CLEAR": { actions: [
|
|
1501
|
+
"clearDateValue",
|
|
1502
|
+
"clearDisplayValues",
|
|
1503
|
+
"clearEnteredKeys"
|
|
1504
|
+
] }
|
|
1505
|
+
},
|
|
1506
|
+
states: {
|
|
1507
|
+
idle: { on: { "SEGMENT.FOCUS": {
|
|
1508
|
+
target: "focused",
|
|
1509
|
+
actions: ["setActiveSegmentIndex", "invokeOnFocus"]
|
|
1510
|
+
} } },
|
|
1511
|
+
focused: { on: {
|
|
1512
|
+
"SEGMENT.FOCUS": { actions: ["setActiveSegmentIndex", "clearEnteredKeys"] },
|
|
1513
|
+
"SEGMENT.BLUR": {
|
|
1514
|
+
target: "idle",
|
|
1515
|
+
actions: [
|
|
1516
|
+
"confirmPlaceholder",
|
|
1517
|
+
"clearEnteredKeys",
|
|
1518
|
+
"invokeOnBlur"
|
|
1519
|
+
]
|
|
1520
|
+
},
|
|
1521
|
+
"SEGMENT.INPUT": { actions: ["setSegmentValue", "announceSegmentValue"] },
|
|
1522
|
+
"SEGMENT.ADJUST": { actions: [
|
|
1523
|
+
"invokeOnSegmentAdjust",
|
|
1524
|
+
"clearEnteredKeys",
|
|
1525
|
+
"announceSegmentValue"
|
|
1526
|
+
] },
|
|
1527
|
+
"SEGMENT.ARROW_LEFT": { actions: ["setPreviousActiveSegmentIndex", "clearEnteredKeys"] },
|
|
1528
|
+
"SEGMENT.ARROW_RIGHT": { actions: ["setNextActiveSegmentIndex", "clearEnteredKeys"] },
|
|
1529
|
+
"SEGMENT.BACKSPACE": [{
|
|
1530
|
+
guard: "isActiveSegmentPlaceholder",
|
|
1531
|
+
actions: ["setPreviousActiveSegmentIndex", "clearEnteredKeys"]
|
|
1532
|
+
}, { actions: [
|
|
1533
|
+
"clearSegmentValue",
|
|
1534
|
+
"clearEnteredKeys",
|
|
1535
|
+
"announceSegmentValue"
|
|
1536
|
+
] }],
|
|
1537
|
+
"SEGMENT.HOME": { actions: [
|
|
1538
|
+
"setSegmentToLowestValue",
|
|
1539
|
+
"clearEnteredKeys",
|
|
1540
|
+
"announceSegmentValue"
|
|
1541
|
+
] },
|
|
1542
|
+
"SEGMENT.END": { actions: [
|
|
1543
|
+
"setSegmentToHighestValue",
|
|
1544
|
+
"clearEnteredKeys",
|
|
1545
|
+
"announceSegmentValue"
|
|
1546
|
+
] }
|
|
1547
|
+
} }
|
|
1548
|
+
},
|
|
1549
|
+
implementations: {
|
|
1550
|
+
effects: { setupLiveRegion({ scope, refs }) {
|
|
1551
|
+
const liveRegion = require_live_region.createLiveRegion({
|
|
1552
|
+
level: "assertive",
|
|
1553
|
+
document: scope.getDoc()
|
|
1554
|
+
});
|
|
1555
|
+
refs.set("announcer", liveRegion);
|
|
1556
|
+
return () => liveRegion.destroy();
|
|
1557
|
+
} },
|
|
1558
|
+
guards: { isActiveSegmentPlaceholder: (ctx) => {
|
|
1559
|
+
if (ctx.context.get("enteredKeys") !== "") return false;
|
|
1560
|
+
return getActiveSegment(ctx)?.isPlaceholder === true;
|
|
1561
|
+
} },
|
|
1562
|
+
actions: {
|
|
1563
|
+
invokeOnFocus({ prop }) {
|
|
1564
|
+
prop("onFocusChange")?.({ focused: true });
|
|
1565
|
+
},
|
|
1566
|
+
invokeOnBlur({ prop }) {
|
|
1567
|
+
prop("onFocusChange")?.({ focused: false });
|
|
1568
|
+
},
|
|
1569
|
+
setActiveSegmentIndex({ context, event }) {
|
|
1570
|
+
if (event.dateIndex != null) context.set("activeIndex", event.dateIndex);
|
|
1571
|
+
context.set("activeSegmentIndex", event.segmentIndex);
|
|
1572
|
+
},
|
|
1573
|
+
clearDisplayValues({ context, prop }) {
|
|
1574
|
+
const hc = resolvedHourCycle(prop("formatter"));
|
|
1575
|
+
const placeholderValue = context.get("placeholderValue");
|
|
1576
|
+
const count = prop("selectionMode") === "range" ? 2 : 1;
|
|
1577
|
+
context.set("displayValues", Array.from({ length: count }, () => new IncompleteDate(placeholderValue.calendar, hc)));
|
|
1578
|
+
},
|
|
1579
|
+
clearEnteredKeys({ context }) {
|
|
1580
|
+
context.set("enteredKeys", "");
|
|
1581
|
+
},
|
|
1582
|
+
setPreviousActiveSegmentIndex(ctx) {
|
|
1583
|
+
const { context } = ctx;
|
|
1584
|
+
const index = context.get("activeIndex");
|
|
1585
|
+
const { allSegments, segments, offset, localIndex } = resolveActiveSegment(ctx);
|
|
1586
|
+
const prevLocalIndex = segments.findLastIndex((segment, i) => i < localIndex && segment.isEditable);
|
|
1587
|
+
if (prevLocalIndex !== -1) {
|
|
1588
|
+
context.set("activeSegmentIndex", offset + prevLocalIndex);
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
const prevGroupIndex = index - 1;
|
|
1592
|
+
if (prevGroupIndex < 0) return;
|
|
1593
|
+
const prevGroupSegments = allSegments[prevGroupIndex];
|
|
1594
|
+
if (!prevGroupSegments) return;
|
|
1595
|
+
const lastPrevGroupEditableLocalIndex = prevGroupSegments.findLastIndex((s) => s.isEditable);
|
|
1596
|
+
if (lastPrevGroupEditableLocalIndex === -1) return;
|
|
1597
|
+
context.set("activeIndex", prevGroupIndex);
|
|
1598
|
+
context.set("activeSegmentIndex", getGroupOffset(allSegments, prevGroupIndex) + lastPrevGroupEditableLocalIndex);
|
|
1599
|
+
},
|
|
1600
|
+
setNextActiveSegmentIndex(ctx) {
|
|
1601
|
+
const { context } = ctx;
|
|
1602
|
+
const { segments, offset, localIndex } = resolveActiveSegment(ctx);
|
|
1603
|
+
const nextLocalIndex = segments.findIndex((segment, i) => i > localIndex && segment.isEditable);
|
|
1604
|
+
if (nextLocalIndex === -1) return;
|
|
1605
|
+
context.set("activeSegmentIndex", offset + nextLocalIndex);
|
|
1606
|
+
},
|
|
1607
|
+
focusActiveSegment({ scope, context }) {
|
|
1608
|
+
require_dom_query.raf(() => {
|
|
1609
|
+
getSegmentEls(scope)[context.get("activeSegmentIndex")]?.focus({ preventScroll: true });
|
|
1610
|
+
});
|
|
1611
|
+
},
|
|
1612
|
+
clearSegmentValue(params) {
|
|
1613
|
+
const { context, prop, event } = params;
|
|
1614
|
+
const index = context.get("activeIndex");
|
|
1615
|
+
const allSegments = prop("allSegments");
|
|
1616
|
+
const allSegmentTypes = Object.keys(allSegments);
|
|
1617
|
+
const placeholderValue = context.get("placeholderValue");
|
|
1618
|
+
const segment = getActiveSegment(params) ?? event.segment;
|
|
1619
|
+
const type = segment.type;
|
|
1620
|
+
let dv = getActiveDisplayValue(params);
|
|
1621
|
+
if (type === "dayPeriod") {
|
|
1622
|
+
const cleared = dv.clear(type);
|
|
1623
|
+
setDisplayValue(params, index, cleared);
|
|
1624
|
+
if (cleared.isCleared(allSegmentTypes)) commitClear(params, index);
|
|
1625
|
+
return;
|
|
1626
|
+
}
|
|
1627
|
+
if (type === "hour") {
|
|
1628
|
+
const cleared = dv.clear(type);
|
|
1629
|
+
setDisplayValue(params, index, cleared);
|
|
1630
|
+
if (cleared.isCleared(allSegmentTypes)) commitClear(params, index);
|
|
1631
|
+
return;
|
|
1632
|
+
}
|
|
1633
|
+
const enteredKeys = context.get("enteredKeys");
|
|
1634
|
+
const newValue = (enteredKeys !== "" ? enteredKeys : segment.text).slice(0, -1);
|
|
1635
|
+
if (newValue === "" || newValue === "0") {
|
|
1636
|
+
const cleared = dv.clear(type);
|
|
1637
|
+
setDisplayValue(params, index, cleared);
|
|
1638
|
+
if (cleared.isCleared(allSegmentTypes)) commitClear(params, index);
|
|
1639
|
+
} else {
|
|
1640
|
+
dv = dv.set(type, Number(newValue), placeholderValue);
|
|
1641
|
+
setDisplayValue(params, index, dv);
|
|
1642
|
+
if (dv.isComplete(allSegmentTypes)) commitValue(params, index, dv);
|
|
1643
|
+
}
|
|
1644
|
+
},
|
|
1645
|
+
invokeOnSegmentAdjust(params) {
|
|
1646
|
+
const { context, prop, event } = params;
|
|
1647
|
+
const { segment, amount } = event;
|
|
1648
|
+
const type = segment.type;
|
|
1649
|
+
const index = context.get("activeIndex");
|
|
1650
|
+
const allSegments = prop("allSegments");
|
|
1651
|
+
const allSegmentTypes = Object.keys(allSegments);
|
|
1652
|
+
const placeholderValue = context.get("placeholderValue");
|
|
1653
|
+
const displaySegmentTypes = allSegmentTypes;
|
|
1654
|
+
const next = getActiveDisplayValue(params).cycle(type, amount, placeholderValue, displaySegmentTypes);
|
|
1655
|
+
setDisplayValue(params, index, next);
|
|
1656
|
+
if (next.isComplete(allSegmentTypes)) commitValue(params, index, next);
|
|
1657
|
+
},
|
|
1658
|
+
setSegmentValue(params) {
|
|
1659
|
+
const { event, context, refs } = params;
|
|
1660
|
+
const { segment, input } = event;
|
|
1661
|
+
refs.set("segmentToAnnounceIndex", context.get("activeSegmentIndex"));
|
|
1662
|
+
const index = context.get("activeIndex");
|
|
1663
|
+
updateSegmentValue(params, segment, input);
|
|
1664
|
+
const allSegmentTypes = Object.keys(params.prop("allSegments"));
|
|
1665
|
+
const dv = context.get("displayValues")[index];
|
|
1666
|
+
if (dv && dv.isComplete(allSegmentTypes)) commitValue(params, index, dv);
|
|
1667
|
+
},
|
|
1668
|
+
setSegmentToLowestValue(params) {
|
|
1669
|
+
const { event, context, prop } = params;
|
|
1670
|
+
const { segment } = event;
|
|
1671
|
+
const index = context.get("activeIndex");
|
|
1672
|
+
const allSegmentTypes = Object.keys(prop("allSegments"));
|
|
1673
|
+
const placeholderValue = context.get("placeholderValue");
|
|
1674
|
+
if (segment.minValue == null) return;
|
|
1675
|
+
const dv = getActiveDisplayValue(params).set(segment.type, segment.minValue, placeholderValue);
|
|
1676
|
+
setDisplayValue(params, index, dv);
|
|
1677
|
+
if (dv.isComplete(allSegmentTypes)) commitValue(params, index, dv);
|
|
1678
|
+
},
|
|
1679
|
+
setSegmentToHighestValue(params) {
|
|
1680
|
+
const { event, context, prop } = params;
|
|
1681
|
+
const { segment } = event;
|
|
1682
|
+
const index = context.get("activeIndex");
|
|
1683
|
+
const allSegmentTypes = Object.keys(prop("allSegments"));
|
|
1684
|
+
const placeholderValue = context.get("placeholderValue");
|
|
1685
|
+
if (segment.maxValue == null) return;
|
|
1686
|
+
const dv = getActiveDisplayValue(params).set(segment.type, segment.maxValue, placeholderValue);
|
|
1687
|
+
setDisplayValue(params, index, dv);
|
|
1688
|
+
if (dv.isComplete(allSegmentTypes)) commitValue(params, index, dv);
|
|
1689
|
+
},
|
|
1690
|
+
setDateValue({ context, event, prop }) {
|
|
1691
|
+
if (!Array.isArray(event.value)) return;
|
|
1692
|
+
const value = event.value.map((date) => require_date_utils.constrainValue(date, prop("min"), prop("max")));
|
|
1693
|
+
context.set("value", value);
|
|
1694
|
+
},
|
|
1695
|
+
clearDateValue({ context }) {
|
|
1696
|
+
context.set("value", []);
|
|
1697
|
+
},
|
|
1698
|
+
syncDisplayValues({ context, prop }) {
|
|
1699
|
+
const value = context.get("value");
|
|
1700
|
+
const hc = resolvedHourCycle(prop("formatter"));
|
|
1701
|
+
const placeholderValue = context.get("placeholderValue");
|
|
1702
|
+
const count = prop("selectionMode") === "range" ? 2 : 1;
|
|
1703
|
+
context.set("displayValues", initDisplayValues(value?.length ? value : void 0, placeholderValue, hc, count));
|
|
1704
|
+
},
|
|
1705
|
+
syncPlaceholderProp({ prop, context }) {
|
|
1706
|
+
const propValue = prop("placeholderValue");
|
|
1707
|
+
if (propValue) {
|
|
1708
|
+
context.set("placeholderValue", propValue);
|
|
1709
|
+
const value = context.get("value");
|
|
1710
|
+
if (value?.length) {
|
|
1711
|
+
const hc = resolvedHourCycle(prop("formatter"));
|
|
1712
|
+
const count = prop("selectionMode") === "range" ? 2 : 1;
|
|
1713
|
+
context.set("displayValues", initDisplayValues(value, propValue, hc, count));
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
},
|
|
1717
|
+
announceSegmentValue({ refs, computed, context }) {
|
|
1718
|
+
const announcer = refs.get("announcer");
|
|
1719
|
+
if (!announcer) return;
|
|
1720
|
+
const index = context.get("activeIndex");
|
|
1721
|
+
const activeSegmentIndex = context.get("activeSegmentIndex");
|
|
1722
|
+
const segmentIndexToUse = refs.get("segmentToAnnounceIndex") ?? activeSegmentIndex;
|
|
1723
|
+
refs.set("segmentToAnnounceIndex", null);
|
|
1724
|
+
const allSegments = computed("segments");
|
|
1725
|
+
const segment = allSegments[index]?.[segmentIndexToUse - getGroupOffset(allSegments, index)];
|
|
1726
|
+
if (!segment || segment.type === "literal") return;
|
|
1727
|
+
const valueText = segment.isPlaceholder ? "Empty" : segment.text;
|
|
1728
|
+
announcer.announce(`${getSegmentLabel(segment.type)}, ${valueText}`);
|
|
1729
|
+
},
|
|
1730
|
+
confirmPlaceholder(params) {
|
|
1731
|
+
const { context, prop } = params;
|
|
1732
|
+
const allSegments = prop("allSegments");
|
|
1733
|
+
const allSegmentTypes = Object.keys(allSegments);
|
|
1734
|
+
const dateCount = prop("selectionMode") === "range" ? 2 : 1;
|
|
1735
|
+
const placeholderValue = context.get("placeholderValue");
|
|
1736
|
+
for (let i = 0; i < dateCount; i++) {
|
|
1737
|
+
const dv = context.get("displayValues")[i];
|
|
1738
|
+
if (!dv) continue;
|
|
1739
|
+
const allExceptDayPeriod = allSegmentTypes.filter((s) => s !== "dayPeriod");
|
|
1740
|
+
if (allSegments.dayPeriod && dv.isComplete(allExceptDayPeriod) && dv.dayPeriod == null) {
|
|
1741
|
+
const filled = dv.set("dayPeriod", placeholderValue && "hour" in placeholderValue ? placeholderValue.hour >= 12 ? 1 : 0 : 0, placeholderValue);
|
|
1742
|
+
setDisplayValue(params, i, filled);
|
|
1743
|
+
commitValue(params, i, filled);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
function commitValue(params, index, dv) {
|
|
1751
|
+
const { context, prop } = params;
|
|
1752
|
+
const placeholderValue = context.get("placeholderValue");
|
|
1753
|
+
const date = require_date_utils.constrainValue(dv.toValue(placeholderValue), prop("min"), prop("max"));
|
|
1754
|
+
const values = Array.from(context.get("value"));
|
|
1755
|
+
values[index] = date;
|
|
1756
|
+
context.set("value", values);
|
|
1757
|
+
}
|
|
1758
|
+
function commitClear(params, index) {
|
|
1759
|
+
const { context } = params;
|
|
1760
|
+
const values = context.get("value");
|
|
1761
|
+
if (index < values.length) context.set("value", values.slice(0, index));
|
|
1762
|
+
}
|
|
1763
|
+
//#endregion
|
|
1764
|
+
//#region src/machines/date-input/date-input.parse.ts
|
|
1765
|
+
function parse(value) {
|
|
1766
|
+
if (Array.isArray(value)) return value.map((v) => parse(v));
|
|
1767
|
+
if (value instanceof Date) return new _internationalized_date.CalendarDate(value.getFullYear(), value.getMonth() + 1, value.getDate());
|
|
1768
|
+
return (0, _internationalized_date.parseDate)(value);
|
|
1769
|
+
}
|
|
1770
|
+
//#endregion
|
|
1771
|
+
//#region src/machines/date-input/date-input.props.ts
|
|
1772
|
+
const props = require_create_props.createProps()([
|
|
1773
|
+
"dir",
|
|
1774
|
+
"disabled",
|
|
1775
|
+
"getRootNode",
|
|
1776
|
+
"id",
|
|
1777
|
+
"ids",
|
|
1778
|
+
"invalid",
|
|
1779
|
+
"locale",
|
|
1780
|
+
"max",
|
|
1781
|
+
"min",
|
|
1782
|
+
"name",
|
|
1783
|
+
"form",
|
|
1784
|
+
"onFocusChange",
|
|
1785
|
+
"onPlaceholderChange",
|
|
1786
|
+
"onValueChange",
|
|
1787
|
+
"readOnly",
|
|
1788
|
+
"required",
|
|
1789
|
+
"selectionMode",
|
|
1790
|
+
"timeZone",
|
|
1791
|
+
"translations",
|
|
1792
|
+
"value",
|
|
1793
|
+
"defaultValue",
|
|
1794
|
+
"hourCycle",
|
|
1795
|
+
"granularity",
|
|
1796
|
+
"shouldForceLeadingZeros",
|
|
1797
|
+
"allSegments",
|
|
1798
|
+
"formatter",
|
|
1799
|
+
"placeholderValue",
|
|
1800
|
+
"defaultPlaceholderValue",
|
|
1801
|
+
"format"
|
|
1802
|
+
]);
|
|
1803
|
+
const splitProps = require_utils.createSplitProps(props);
|
|
1804
|
+
const segmentProps = require_create_props.createProps()(["segment", "index"]);
|
|
1805
|
+
const splitSegmentProps = require_utils.createSplitProps(segmentProps);
|
|
1806
|
+
const segmentGroupProps = require_create_props.createProps()(["index"]);
|
|
1807
|
+
const splitSegmentGroupProps = require_utils.createSplitProps(segmentGroupProps);
|
|
1808
|
+
const segmentsProps = require_create_props.createProps()(["index"]);
|
|
1809
|
+
const splitSegmentsProps = require_utils.createSplitProps(segmentsProps);
|
|
1810
|
+
const labelProps = require_create_props.createProps()(["index"]);
|
|
1811
|
+
const splitLabelProps = require_utils.createSplitProps(labelProps);
|
|
1812
|
+
const hiddenInputProps = require_create_props.createProps()(["index", "name"]);
|
|
1813
|
+
const splitHiddenInputProps = require_utils.createSplitProps(hiddenInputProps);
|
|
1814
|
+
//#endregion
|
|
1815
|
+
exports.anatomy = anatomy;
|
|
1816
|
+
exports.connect = connect;
|
|
1817
|
+
exports.hiddenInputProps = hiddenInputProps;
|
|
1818
|
+
exports.labelProps = labelProps;
|
|
1819
|
+
exports.machine = machine;
|
|
1820
|
+
exports.parse = parse;
|
|
1821
|
+
exports.props = props;
|
|
1822
|
+
exports.segmentGroupProps = segmentGroupProps;
|
|
1823
|
+
exports.segmentProps = segmentProps;
|
|
1824
|
+
exports.segmentsProps = segmentsProps;
|
|
1825
|
+
exports.splitHiddenInputProps = splitHiddenInputProps;
|
|
1826
|
+
exports.splitLabelProps = splitLabelProps;
|
|
1827
|
+
exports.splitProps = splitProps;
|
|
1828
|
+
exports.splitSegmentGroupProps = splitSegmentGroupProps;
|
|
1829
|
+
exports.splitSegmentProps = splitSegmentProps;
|
|
1830
|
+
exports.splitSegmentsProps = splitSegmentsProps;
|