@astryxdesign/core 0.7.8-canary.ea33daf → 0.7.8-canary.eb985e5
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/BottomSheet/BottomSheetPanel.d.ts +1 -1
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +30 -14
- package/dist/BottomSheet/bottomSheetStack.js +1 -1
- package/dist/BottomSheet/useSheetGestures.d.ts +3 -1
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
- package/dist/BottomSheet/useSheetGestures.js +4 -0
- package/dist/CheckboxList/CheckboxList.d.ts +13 -2
- package/dist/CheckboxList/CheckboxList.d.ts.map +1 -1
- package/dist/CheckboxList/CheckboxList.js +10 -4
- package/dist/CheckboxList/CheckboxListContext.d.ts +7 -0
- package/dist/CheckboxList/CheckboxListContext.d.ts.map +1 -1
- package/dist/CheckboxList/CheckboxListContext.js +2 -1
- package/dist/CheckboxList/CheckboxListItem.d.ts.map +1 -1
- package/dist/CheckboxList/CheckboxListItem.js +14 -2
- package/dist/CheckboxList/requiredGroup.d.ts +22 -0
- package/dist/CheckboxList/requiredGroup.d.ts.map +1 -0
- package/dist/CheckboxList/requiredGroup.js +52 -0
- package/dist/DateInput/PickerWheel.d.ts +1 -1
- package/dist/DateInput/PickerWheel.d.ts.map +1 -1
- package/dist/DateInput/PickerWheel.js +27 -6
- package/dist/DateInput/Wheel.d.ts +2 -2
- package/dist/DateInput/Wheel.d.ts.map +1 -1
- package/dist/DateInput/Wheel.js +20 -6
- package/dist/DateInput/datePickerTouch.d.ts +13 -0
- package/dist/DateInput/datePickerTouch.d.ts.map +1 -0
- package/dist/DateInput/datePickerTouch.js +14 -0
- package/dist/DateInput/wheelOptions.d.ts +22 -2
- package/dist/DateInput/wheelOptions.d.ts.map +1 -1
- package/dist/DateInput/wheelOptions.js +14 -2
- package/dist/DateTimeInput/TouchDateTimeField.d.ts.map +1 -1
- package/dist/DateTimeInput/TouchDateTimeField.js +62 -119
- package/dist/HoverCard/useHoverCard.d.ts.map +1 -1
- package/dist/HoverCard/useHoverCard.js +6 -1
- package/dist/Overlay/Overlay.d.ts.map +1 -1
- package/dist/Overlay/Overlay.js +7 -2
- package/dist/PowerSearch/PowerSearch.d.ts +4 -2
- package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts +24 -1
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchBottomSheet.js +172 -50
- package/dist/TimeInput/TimeWheels.d.ts +32 -0
- package/dist/TimeInput/TimeWheels.d.ts.map +1 -0
- package/dist/TimeInput/TimeWheels.js +144 -0
- package/dist/TimeInput/TouchTimeField.d.ts.map +1 -1
- package/dist/TimeInput/TouchTimeField.js +63 -118
- package/dist/TimeInput/timeWheelRules.d.ts +124 -0
- package/dist/TimeInput/timeWheelRules.d.ts.map +1 -0
- package/dist/TimeInput/timeWheelRules.js +277 -0
- package/dist/Tokenizer/TokenizerBottomSheet.js +8 -12
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +6 -0
- package/dist/astryx.css +3 -1
- package/dist/gestures/GestureHost.d.ts.map +1 -1
- package/dist/gestures/GestureHost.js +3 -0
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts.map +1 -1
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.js +5 -2
- package/dist/i18n/generated-english/TimeInput/TimeWheels.generated.d.ts +8 -0
- package/dist/i18n/generated-english/TimeInput/TimeWheels.generated.d.ts.map +1 -0
- package/dist/i18n/generated-english/TimeInput/TimeWheels.generated.js +17 -0
- package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/en.generated.js +5 -2
- package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/pseudo.generated.js +5 -2
- package/dist/keyboard/index.d.ts +17 -0
- package/dist/keyboard/index.d.ts.map +1 -0
- package/dist/keyboard/index.js +19 -0
- package/dist/keyboard/keyboardHeight.d.ts +149 -0
- package/dist/keyboard/keyboardHeight.d.ts.map +1 -0
- package/dist/keyboard/keyboardHeight.js +432 -0
- package/dist/keyboard/keyboardLayoutGuide.d.ts +59 -0
- package/dist/keyboard/keyboardLayoutGuide.d.ts.map +1 -0
- package/dist/keyboard/keyboardLayoutGuide.js +207 -0
- package/dist/keyboard/keyboardModel.d.ts +93 -0
- package/dist/keyboard/keyboardModel.d.ts.map +1 -0
- package/dist/keyboard/keyboardModel.js +220 -0
- package/dist/keyboard/rideKeyboard.d.ts +42 -0
- package/dist/keyboard/rideKeyboard.d.ts.map +1 -0
- package/dist/keyboard/rideKeyboard.js +77 -0
- package/dist/keyboard/useMobileKeyboard.d.ts +61 -0
- package/dist/keyboard/useMobileKeyboard.d.ts.map +1 -0
- package/dist/keyboard/useMobileKeyboard.js +699 -0
- package/dist/motion/android/index.d.ts +16 -0
- package/dist/motion/android/index.d.ts.map +1 -0
- package/dist/motion/android/index.js +18 -0
- package/dist/motion/android/keyboard.d.ts +83 -0
- package/dist/motion/android/keyboard.d.ts.map +1 -0
- package/dist/motion/android/keyboard.js +96 -0
- package/dist/motion/uikit/datePicker.d.ts +58 -0
- package/dist/motion/uikit/datePicker.d.ts.map +1 -0
- package/dist/motion/uikit/datePicker.js +60 -0
- package/dist/motion/uikit/index.d.ts +4 -3
- package/dist/motion/uikit/index.d.ts.map +1 -1
- package/dist/motion/uikit/index.js +4 -3
- package/dist/utils/interactionOverlay.stylex.d.ts +3 -2
- package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
- package/dist/utils/interactionOverlay.stylex.js +3 -2
- package/dist/utils/layoutViewport.d.ts +25 -0
- package/dist/utils/layoutViewport.d.ts.map +1 -0
- package/dist/utils/layoutViewport.js +102 -0
- package/dist/utils/pressFeedback.d.ts.map +1 -1
- package/dist/utils/pressFeedback.js +74 -9
- package/dist/utils/pressGesture.d.ts +4 -2
- package/dist/utils/pressGesture.d.ts.map +1 -1
- package/dist/utils/pressGesture.js +3 -1
- package/dist/utils/selectionLock.d.ts +10 -1
- package/dist/utils/selectionLock.d.ts.map +1 -1
- package/dist/utils/selectionLock.js +31 -5
- package/dist/utils/sharedMutationObserver.d.ts +2 -1
- package/dist/utils/sharedMutationObserver.d.ts.map +1 -1
- package/dist/utils/sharedMutationObserver.js +2 -1
- package/dist/utils/timeParser.d.ts +2 -1
- package/dist/utils/timeParser.d.ts.map +1 -1
- package/dist/utils/timeParser.js +29 -3
- package/locales/en.json +21 -9
- package/locales/pseudo.json +15 -6
- package/package.json +4 -4
- package/src/BottomSheet/BottomSheet.doc.mjs +1 -1
- package/src/BottomSheet/BottomSheetPanel.tsx +41 -13
- package/src/BottomSheet/bottomSheetStack.ts +1 -1
- package/src/BottomSheet/useSheetGestures.ts +6 -0
- package/src/CheckboxList/CheckboxList.doc.mjs +7 -0
- package/src/CheckboxList/CheckboxList.tsx +34 -2
- package/src/CheckboxList/CheckboxListContext.tsx +9 -1
- package/src/CheckboxList/CheckboxListItem.tsx +23 -2
- package/src/CheckboxList/requiredGroup.ts +77 -0
- package/src/DateInput/PickerWheel.tsx +37 -4
- package/src/DateInput/Wheel.tsx +30 -3
- package/src/DateInput/datePickerTouch.ts +15 -0
- package/src/DateInput/wheelOptions.ts +31 -2
- package/src/DateTimeInput/TouchDateTimeField.tsx +94 -178
- package/src/HoverCard/useHoverCard.tsx +6 -1
- package/src/Overlay/Overlay.tsx +7 -2
- package/src/PowerSearch/PowerSearch.doc.mjs +2 -2
- package/src/PowerSearch/PowerSearch.tsx +4 -2
- package/src/PowerSearch/PowerSearchBottomSheet.tsx +237 -62
- package/src/TimeInput/TimeWheels.tsx +218 -0
- package/src/TimeInput/TouchTimeField.tsx +93 -157
- package/src/TimeInput/timeWheelRules.ts +352 -0
- package/src/Tokenizer/TokenizerBottomSheet.tsx +8 -12
- package/src/Tooltip/useTooltip.tsx +6 -0
- package/src/gestures/GestureHost.ts +5 -4
- package/src/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.ts +5 -2
- package/src/i18n/generated-english/TimeInput/TimeWheels.generated.ts +18 -0
- package/src/i18n/generated-locales/en.generated.ts +6 -4
- package/src/i18n/generated-locales/pseudo.generated.ts +6 -4
- package/src/keyboard/README.md +197 -0
- package/src/keyboard/index.ts +48 -0
- package/src/keyboard/keyboardHeight.ts +543 -0
- package/src/keyboard/keyboardLayoutGuide.ts +266 -0
- package/src/keyboard/keyboardModel.ts +301 -0
- package/src/keyboard/rideKeyboard.ts +100 -0
- package/src/keyboard/useMobileKeyboard.ts +866 -0
- package/src/motion/MEASUREMENTS.md +10 -0
- package/src/motion/README.md +2 -0
- package/src/motion/android/index.ts +18 -0
- package/src/motion/android/keyboard.ts +96 -0
- package/src/motion/uikit/datePicker.ts +60 -0
- package/src/motion/uikit/index.ts +4 -3
- package/src/utils/interactionOverlay.stylex.ts +3 -2
- package/src/utils/layoutViewport.ts +104 -0
- package/src/utils/pressFeedback.ts +99 -21
- package/src/utils/pressGesture.ts +4 -2
- package/src/utils/selectionLock.ts +40 -6
- package/src/utils/sharedMutationObserver.ts +2 -1
- package/src/utils/timeParser.ts +40 -3
- package/dist/BottomSheet/useMobileKeyboard.d.ts +0 -21
- package/dist/BottomSheet/useMobileKeyboard.d.ts.map +0 -1
- package/dist/BottomSheet/useMobileKeyboard.js +0 -413
- package/src/BottomSheet/useMobileKeyboard.ts +0 -542
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file TouchTimeField.tsx
|
|
7
|
-
* @input Uses React, Field, BottomSheet,
|
|
8
|
-
*
|
|
7
|
+
* @input Uses React, Field, BottomSheet, the wheels (TimeWheels under a finger,
|
|
8
|
+
* Wheel with a mouse), DateInput touch geometry tokens and time utilities
|
|
9
9
|
* @output Exports TouchTimeField — the bottom-sheet surface behind TimeInput
|
|
10
10
|
* @position Internal component; consumed by TimeInput.tsx for `presentation`
|
|
11
|
-
* sheet surfaces
|
|
11
|
+
* sheet surfaces
|
|
12
12
|
*
|
|
13
13
|
* SYNC: When modified, update these files to stay in sync:
|
|
14
14
|
* - /packages/core/src/TimeInput/TimeInput.tsx
|
|
@@ -38,15 +38,18 @@ import { useSize } from "../SizeContext/SizeContext.js";
|
|
|
38
38
|
import { Spinner } from "../Spinner/index.js";
|
|
39
39
|
import { useTooltip } from "../Tooltip/index.js";
|
|
40
40
|
import { Wheel } from "../DateInput/Wheel.js";
|
|
41
|
+
import { useTouchPresentation } from "../utils/touchPresentation.js";
|
|
41
42
|
import "../DateInput/tokens.stylex.js";
|
|
42
43
|
import { dateInputTouchGeometry } from "../DateInput/tokens.stylex.js";
|
|
43
44
|
import { focusOutlineStyles } from "../utils/focusOutline.stylex.js";
|
|
44
45
|
import { themeProps } from "../utils/themeProps.js";
|
|
45
46
|
import { clampTime, formatISOTime, getInputARIA, isTimeInRange, mergeProps, parseISOTime } from "../utils/index.js";
|
|
46
47
|
import { chainEventHandlers } from "../utils/chainEventHandlers.js";
|
|
48
|
+
import { TimeWheels } from "../DateInput/datePickerTouch.js";
|
|
49
|
+
import { hour12From24, hour24From12, hourRowsInHalf, meridiemRows, minuteRows, secondRows, wheelBounds } from "./timeWheelRules.js";
|
|
47
50
|
import { registerEnglishFallback, useComponentTranslator } from "../i18n/useComponentTranslator.js";
|
|
48
51
|
import english from "../i18n/generated-english/TimeInput/TouchTimeField.generated.js";
|
|
49
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
52
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
50
53
|
registerEnglishFallback(english);
|
|
51
54
|
const sizeStyles = {
|
|
52
55
|
sm: {
|
|
@@ -80,30 +83,6 @@ const styles = {
|
|
|
80
83
|
$$css: true
|
|
81
84
|
}
|
|
82
85
|
};
|
|
83
|
-
function twoDigits(value) {
|
|
84
|
-
return String(value).padStart(2, '0');
|
|
85
|
-
}
|
|
86
|
-
function hour12From24(hour) {
|
|
87
|
-
return hour === 0 ? 12 : hour > 12 ? hour - 12 : hour;
|
|
88
|
-
}
|
|
89
|
-
function hour24From12(hour, meridiem) {
|
|
90
|
-
if (meridiem === 0) {
|
|
91
|
-
return hour === 12 ? 0 : hour;
|
|
92
|
-
}
|
|
93
|
-
return hour === 12 ? 12 : hour + 12;
|
|
94
|
-
}
|
|
95
|
-
function timeToSeconds(time) {
|
|
96
|
-
if (time == null) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
const parsed = parseISOTime(time);
|
|
100
|
-
return parsed == null ? null : parsed.hour * 3600 + parsed.minute * 60 + parsed.second;
|
|
101
|
-
}
|
|
102
|
-
function rangeOverlaps(startSecond, endSecond, min, max) {
|
|
103
|
-
const minSecond = timeToSeconds(min);
|
|
104
|
-
const maxSecond = timeToSeconds(max);
|
|
105
|
-
return (minSecond == null || endSecond >= minSecond) && (maxSecond == null || startSecond <= maxSecond);
|
|
106
|
-
}
|
|
107
86
|
|
|
108
87
|
/**
|
|
109
88
|
* The Astryx bottom-sheet time surface: a read-only closed field that opens
|
|
@@ -179,6 +158,9 @@ export function TouchTimeField({
|
|
|
179
158
|
const mergedInputRef = useMergedRefs(ref, inputRef);
|
|
180
159
|
const inputGroup = useInputGroup();
|
|
181
160
|
const [isSheetOpen, setIsSheetOpen] = useState(false);
|
|
161
|
+
const {
|
|
162
|
+
isTouch
|
|
163
|
+
} = useTouchPresentation();
|
|
182
164
|
const [, startTransition] = useTransition();
|
|
183
165
|
const [optimisticValue, setOptimisticValue] = useOptimistic(value);
|
|
184
166
|
const isBusy = isLoading || optimisticValue !== value;
|
|
@@ -254,61 +236,14 @@ export function TouchTimeField({
|
|
|
254
236
|
fireChange(next);
|
|
255
237
|
}
|
|
256
238
|
}, [fireChange, hasSeconds, max, min, optimisticValue]);
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}));
|
|
266
|
-
}
|
|
267
|
-
const meridiem = parsedWheelTime.hour < 12 ? 0 : 1;
|
|
268
|
-
return Array.from({
|
|
269
|
-
length: 12
|
|
270
|
-
}, (_, index) => {
|
|
271
|
-
const hour = index + 1;
|
|
272
|
-
const hour24 = hour24From12(hour, meridiem);
|
|
273
|
-
return {
|
|
274
|
-
value: hour,
|
|
275
|
-
label: String(hour),
|
|
276
|
-
// Keys step in time order: 12 PM comes before 1 PM.
|
|
277
|
-
order: hour24,
|
|
278
|
-
isDisabled: !rangeOverlaps(hour24 * 3600, hour24 * 3600 + 3599, min, max)
|
|
279
|
-
};
|
|
280
|
-
});
|
|
281
|
-
}, [hourFormat, max, min, parsedWheelTime.hour]);
|
|
282
|
-
const minuteOptions = useMemo(() => Array.from({
|
|
283
|
-
length: 60
|
|
284
|
-
}, (_, minute) => {
|
|
285
|
-
const start = parsedWheelTime.hour * 3600 + minute * 60;
|
|
286
|
-
return {
|
|
287
|
-
value: minute,
|
|
288
|
-
label: twoDigits(minute),
|
|
289
|
-
isDisabled: !rangeOverlaps(start, start + (hasSeconds ? 59 : 0), min, max)
|
|
290
|
-
};
|
|
291
|
-
}), [hasSeconds, max, min, parsedWheelTime.hour]);
|
|
292
|
-
const secondOptions = useMemo(() => Array.from({
|
|
293
|
-
length: 60
|
|
294
|
-
}, (_, second) => ({
|
|
295
|
-
value: second,
|
|
296
|
-
label: twoDigits(second),
|
|
297
|
-
isDisabled: !isTimeInRange(formatISOTime({
|
|
298
|
-
hour: parsedWheelTime.hour,
|
|
299
|
-
minute: parsedWheelTime.minute,
|
|
300
|
-
second
|
|
301
|
-
}, true), min, max)
|
|
302
|
-
})), [max, min, parsedWheelTime.hour, parsedWheelTime.minute]);
|
|
303
|
-
const meridiemOptions = useMemo(() => [{
|
|
304
|
-
value: 0,
|
|
305
|
-
label: t('@astryx.dateTimeInput.meridiemAM'),
|
|
306
|
-
isDisabled: !rangeOverlaps(0, 11 * 3600 + 3599, min, max)
|
|
307
|
-
}, {
|
|
308
|
-
value: 1,
|
|
309
|
-
label: t('@astryx.dateTimeInput.meridiemPM'),
|
|
310
|
-
isDisabled: !rangeOverlaps(12 * 3600, 23 * 3600 + 3599, min, max)
|
|
311
|
-
}], [max, min, t]);
|
|
239
|
+
const bounds = useMemo(() => wheelBounds(min, max), [min, max]);
|
|
240
|
+
const hourOptions = useMemo(() => hourRowsInHalf(parsedWheelTime.hour, hourFormat, bounds), [bounds, hourFormat, parsedWheelTime.hour]);
|
|
241
|
+
const minuteOptions = useMemo(() => minuteRows(parsedWheelTime.hour, hasSeconds, bounds), [bounds, hasSeconds, parsedWheelTime.hour]);
|
|
242
|
+
const secondOptions = useMemo(() => secondRows(parsedWheelTime.hour, parsedWheelTime.minute, bounds), [bounds, parsedWheelTime.hour, parsedWheelTime.minute]);
|
|
243
|
+
const meridiemOptions = useMemo(() => meridiemRows({
|
|
244
|
+
am: t('@astryx.dateTimeInput.meridiemAM'),
|
|
245
|
+
pm: t('@astryx.dateTimeInput.meridiemPM')
|
|
246
|
+
}, bounds), [bounds, t]);
|
|
312
247
|
const openSheet = useCallback(() => {
|
|
313
248
|
if (!isEffectivelyDisabled) {
|
|
314
249
|
setIsSheetOpen(true);
|
|
@@ -391,45 +326,55 @@ export function TouchTimeField({
|
|
|
391
326
|
...{
|
|
392
327
|
className: "x9f619 x78zum5 xdt5ytf xh8yej3 xeuugli x1txdalj x1pzlopt x1adxfkp x1awphl8"
|
|
393
328
|
},
|
|
394
|
-
children: [/*#__PURE__*/
|
|
329
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
395
330
|
...{
|
|
396
331
|
className: "x78zum5 xh8yej3 xeuugli xm8gem x1txdalj"
|
|
397
332
|
},
|
|
398
|
-
children:
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
hour24: hour
|
|
405
|
-
}) : composeWheelTime({
|
|
406
|
-
hour12: hour
|
|
407
|
-
}))
|
|
408
|
-
}), /*#__PURE__*/_jsx(Wheel, {
|
|
409
|
-
label: t('@astryx.dateTimeInput.minuteWheel'),
|
|
410
|
-
options: minuteOptions,
|
|
411
|
-
value: parsedWheelTime.minute,
|
|
333
|
+
children: isTouch ? /*#__PURE__*/_jsx(TimeWheels, {
|
|
334
|
+
time: parsedWheelTime,
|
|
335
|
+
hourFormat: hourFormat,
|
|
336
|
+
hasSeconds: hasSeconds,
|
|
337
|
+
min: min,
|
|
338
|
+
max: max,
|
|
412
339
|
isActive: isSheetOpen,
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
340
|
+
onCommit: time => commitWheelTime(formatISOTime(time, hasSeconds))
|
|
341
|
+
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
342
|
+
children: [/*#__PURE__*/_jsx(Wheel, {
|
|
343
|
+
label: t('@astryx.dateTimeInput.hourWheel'),
|
|
344
|
+
options: hourOptions,
|
|
345
|
+
value: hourFormat === '24h' ? parsedWheelTime.hour : hour12From24(parsedWheelTime.hour),
|
|
346
|
+
isActive: isSheetOpen,
|
|
347
|
+
onChange: hour => commitWheelTime(hourFormat === '24h' ? composeWheelTime({
|
|
348
|
+
hour24: hour
|
|
349
|
+
}) : composeWheelTime({
|
|
350
|
+
hour12: hour
|
|
351
|
+
}))
|
|
352
|
+
}), /*#__PURE__*/_jsx(Wheel, {
|
|
353
|
+
label: t('@astryx.dateTimeInput.minuteWheel'),
|
|
354
|
+
options: minuteOptions,
|
|
355
|
+
value: parsedWheelTime.minute,
|
|
356
|
+
isActive: isSheetOpen,
|
|
357
|
+
onChange: minute => commitWheelTime(composeWheelTime({
|
|
358
|
+
minute
|
|
359
|
+
}))
|
|
360
|
+
}), hasSeconds && /*#__PURE__*/_jsx(Wheel, {
|
|
361
|
+
label: t('@astryx.dateTimeInput.secondWheel'),
|
|
362
|
+
options: secondOptions,
|
|
363
|
+
value: parsedWheelTime.second,
|
|
364
|
+
isActive: isSheetOpen,
|
|
365
|
+
onChange: second => commitWheelTime(composeWheelTime({
|
|
366
|
+
second
|
|
367
|
+
}))
|
|
368
|
+
}), hourFormat === '12h' && /*#__PURE__*/_jsx(Wheel, {
|
|
369
|
+
label: t('@astryx.dateTimeInput.meridiemWheel'),
|
|
370
|
+
options: meridiemOptions,
|
|
371
|
+
value: parsedWheelTime.hour < 12 ? 0 : 1,
|
|
372
|
+
isActive: isSheetOpen,
|
|
373
|
+
onChange: meridiem => commitWheelTime(composeWheelTime({
|
|
374
|
+
meridiem
|
|
375
|
+
}))
|
|
376
|
+
})]
|
|
377
|
+
})
|
|
433
378
|
}), /*#__PURE__*/_jsx("div", {
|
|
434
379
|
...{
|
|
435
380
|
className: "x78zum5 xr1yuqi xfsso4q"
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file timeWheelRules.ts
|
|
3
|
+
* @input A time of day, the hour format and the bounds
|
|
4
|
+
* @output Pure rules of UIDatePicker's time wheels: the columns' rows, the
|
|
5
|
+
* time a turned column makes, and which other columns turn with it
|
|
6
|
+
* @position Internal helper of the TimeInput and DateTimeInput sheets: the
|
|
7
|
+
* rows of both their finger and their mouse wheels
|
|
8
|
+
*
|
|
9
|
+
* The columns do not loop. Each rule follows a leaf of motion/uikit/
|
|
10
|
+
* datePicker.ts `wheels`. Pure functions keep the rules testable without a
|
|
11
|
+
* layout engine.
|
|
12
|
+
*
|
|
13
|
+
* SYNC: When modified, update timeWheelRules.test.ts and TimeWheels.tsx.
|
|
14
|
+
*/
|
|
15
|
+
import { type ISOTimeString } from '../utils/timeParser.js';
|
|
16
|
+
/** A time of day, 24-hour. */
|
|
17
|
+
export interface TimeParts {
|
|
18
|
+
hour: number;
|
|
19
|
+
minute: number;
|
|
20
|
+
second: number;
|
|
21
|
+
}
|
|
22
|
+
/** A time wheel column. */
|
|
23
|
+
export type TimeColumn = 'hour' | 'minute' | 'second' | 'meridiem';
|
|
24
|
+
/** One row of a column: the value it stands for and its label. */
|
|
25
|
+
export interface TimeRow {
|
|
26
|
+
value: number;
|
|
27
|
+
label: string;
|
|
28
|
+
isDisabled: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Where the row falls when a key steps the column. An hour row holds the hour
|
|
31
|
+
* it stands for, so a key follows the full time: 12 PM comes before 1 PM.
|
|
32
|
+
*/
|
|
33
|
+
order?: number;
|
|
34
|
+
}
|
|
35
|
+
/** Inclusive bounds in seconds since midnight; `null` is unbounded. */
|
|
36
|
+
export interface TimeBounds {
|
|
37
|
+
min: number | null;
|
|
38
|
+
max: number | null;
|
|
39
|
+
}
|
|
40
|
+
/** The bounds of a field's `min` and `max` times. */
|
|
41
|
+
export declare function wheelBounds(min: ISOTimeString | undefined, max: ISOTimeString | undefined): TimeBounds;
|
|
42
|
+
/** Whether the hour falls in the PM half (1) or the AM half (0). */
|
|
43
|
+
export declare function meridiemOf(hour: number): 0 | 1;
|
|
44
|
+
/** The 12-hour clock's label for a 24-hour hour: 0 → 12, 13 → 1. */
|
|
45
|
+
export declare function hour12From24(hour: number): number;
|
|
46
|
+
/** The 24-hour hour for a 12-hour hour in a half of the day: 12 AM → 0. */
|
|
47
|
+
export declare function hour24From12(hour: number, meridiem: number): number;
|
|
48
|
+
/**
|
|
49
|
+
* The time the wheels show for `time`: its seconds kept when the picker has a
|
|
50
|
+
* seconds column and dropped when it has none. A time outside the bounds is
|
|
51
|
+
* shown as it is, on its disabled rows: opening the sheet never moves an
|
|
52
|
+
* untouched value.
|
|
53
|
+
*/
|
|
54
|
+
export declare function displayedTime(time: TimeParts, hasSeconds: boolean): TimeParts;
|
|
55
|
+
/**
|
|
56
|
+
* The time a column's rest commits when it would make `time`: the nearest
|
|
57
|
+
* time inside the bounds that the columns have a row for. Past a bound, that
|
|
58
|
+
* is the bound itself, or, with no seconds column, the nearest whole minute
|
|
59
|
+
* inside it (a 16:55:30 maximum: 16:55). Inside the bounds, `time` itself.
|
|
60
|
+
*/
|
|
61
|
+
export declare function restingTime(time: TimeParts, hasSeconds: boolean, bounds: TimeBounds): TimeParts;
|
|
62
|
+
/**
|
|
63
|
+
* The hour the hour column makes when it comes to rest on `row` from the row
|
|
64
|
+
* that showed `from` (24-hour). In 24-hour time the row is the hour. In 12-hour
|
|
65
|
+
* time the half of the day changes only when the move passes between 11 and 12.
|
|
66
|
+
* The column (1 … 12) does not loop, so 12 counts as next to 1. A move between
|
|
67
|
+
* 12 and 1 to 6 keeps the half of the day. A move between 12 and 7 to 11
|
|
68
|
+
* changes it.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```
|
|
72
|
+
* hourAfterTurn(11, 12, '12h'); // 12: 11 AM → 12 PM
|
|
73
|
+
* hourAfterTurn(12, 1, '12h'); // 13: 12 PM → 1 PM
|
|
74
|
+
* hourAfterTurn(13, 9, '12h'); // 21: 1 PM → 9 PM
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function hourAfterTurn(from: number, row: number, hourFormat: '12h' | '24h'): number;
|
|
78
|
+
/**
|
|
79
|
+
* The hour column under a finger. In 24-hour time its rows are 00 … 23. In
|
|
80
|
+
* 12-hour time they are 1 … 12, each row standing for the hour a turn onto it
|
|
81
|
+
* from `from` makes (`hourAfterTurn`). A row is disabled when no minute of that
|
|
82
|
+
* hour is inside the bounds.
|
|
83
|
+
*/
|
|
84
|
+
export declare function hourRows(from: number, hourFormat: '12h' | '24h', bounds: TimeBounds): TimeRow[];
|
|
85
|
+
/**
|
|
86
|
+
* The hour column under a mouse, whose columns turn one at a time. A 12-hour
|
|
87
|
+
* row stands for its hour in the half of the day that `from` is in.
|
|
88
|
+
*/
|
|
89
|
+
export declare function hourRowsInHalf(from: number, hourFormat: '12h' | '24h', bounds: TimeBounds): TimeRow[];
|
|
90
|
+
/**
|
|
91
|
+
* The minute column for `hour`: every minute. A row is disabled when it is
|
|
92
|
+
* outside the bounds (its whole minute, when the picker shows seconds).
|
|
93
|
+
*/
|
|
94
|
+
export declare function minuteRows(hour: number, hasSeconds: boolean, bounds: TimeBounds): TimeRow[];
|
|
95
|
+
/** The second column for `hour`:`minute`. */
|
|
96
|
+
export declare function secondRows(hour: number, minute: number, bounds: TimeBounds): TimeRow[];
|
|
97
|
+
/** The AM/PM column: a half is disabled when none of its hours is in bounds. */
|
|
98
|
+
export declare function meridiemRows(labels: {
|
|
99
|
+
am: string;
|
|
100
|
+
pm: string;
|
|
101
|
+
}, bounds: TimeBounds): TimeRow[];
|
|
102
|
+
/**
|
|
103
|
+
* The time made by turning `column` to `value` (its row's value) from `from`
|
|
104
|
+
* (the time the wheels show). Only that column changes, and the AM/PM column
|
|
105
|
+
* moves the hour by twelve.
|
|
106
|
+
*/
|
|
107
|
+
export declare function turnColumn(from: TimeParts, column: TimeColumn, value: number, hourFormat: '12h' | '24h'): TimeParts;
|
|
108
|
+
/** What a column shows for a time: its row's value. */
|
|
109
|
+
export declare function columnValue(time: TimeParts, column: TimeColumn, hourFormat: '12h' | '24h'): number;
|
|
110
|
+
/**
|
|
111
|
+
* The columns that must turn after `column` came to rest on `value`. That is
|
|
112
|
+
* every column whose row for the committed time differs from the row it shows
|
|
113
|
+
* now. The column that moved shows `value`; the others show `from`. An hour
|
|
114
|
+
* that crossed 11 ↔ 12 turns the AM/PM column; a time brought back onto a bound
|
|
115
|
+
* turns every column whose row changed.
|
|
116
|
+
*/
|
|
117
|
+
export declare function columnsToTurn(from: TimeParts, column: TimeColumn, value: number, committed: TimeParts, options: {
|
|
118
|
+
hourFormat: '12h' | '24h';
|
|
119
|
+
hasSeconds: boolean;
|
|
120
|
+
}): {
|
|
121
|
+
column: TimeColumn;
|
|
122
|
+
value: number;
|
|
123
|
+
}[];
|
|
124
|
+
//# sourceMappingURL=timeWheelRules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeWheelRules.d.ts","sourceRoot":"","sources":["../../src/TimeInput/timeWheelRules.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,qBAAqB,CAAC;AAE7B,8BAA8B;AAC9B,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,2BAA2B;AAC3B,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEnE,kEAAkE;AAClE,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,uEAAuE;AACvE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAcD,qDAAqD;AACrD,wBAAgB,WAAW,CACzB,GAAG,EAAE,aAAa,GAAG,SAAS,EAC9B,GAAG,EAAE,aAAa,GAAG,SAAS,GAC7B,UAAU,CAEZ;AAED,oEAAoE;AACpE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,CAAC,CAE9C;AAED,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGjD;AAED,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEnE;AAmBD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,GAAG,SAAS,CAE7E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,SAAS,EACf,UAAU,EAAE,OAAO,EACnB,MAAM,EAAE,UAAU,GACjB,SAAS,CAUX;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,KAAK,GAAG,KAAK,GACxB,MAAM,CAYR;AAsBD;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,KAAK,GAAG,KAAK,EACzB,MAAM,EAAE,UAAU,GACjB,OAAO,EAAE,CAMX;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,KAAK,GAAG,KAAK,EACzB,MAAM,EAAE,UAAU,GACjB,OAAO,EAAE,CAOX;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,OAAO,EACnB,MAAM,EAAE,UAAU,GACjB,OAAO,EAAE,CASX;AAED,6CAA6C;AAC7C,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,UAAU,GACjB,OAAO,EAAE,CASX;AAED,gFAAgF;AAChF,wBAAgB,YAAY,CAC1B,MAAM,EAAE;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAC,EAChC,MAAM,EAAE,UAAU,GACjB,OAAO,EAAE,CAaX;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,KAAK,GAAG,KAAK,GACxB,SAAS,CAWX;AAED,uDAAuD;AACvD,wBAAgB,WAAW,CACzB,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,KAAK,GAAG,KAAK,GACxB,MAAM,CAWR;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE;IAAC,UAAU,EAAE,KAAK,GAAG,KAAK,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAC,GACxD;IAAC,MAAM,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,EAAE,CAkBvC"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file timeWheelRules.ts
|
|
5
|
+
* @input A time of day, the hour format and the bounds
|
|
6
|
+
* @output Pure rules of UIDatePicker's time wheels: the columns' rows, the
|
|
7
|
+
* time a turned column makes, and which other columns turn with it
|
|
8
|
+
* @position Internal helper of the TimeInput and DateTimeInput sheets: the
|
|
9
|
+
* rows of both their finger and their mouse wheels
|
|
10
|
+
*
|
|
11
|
+
* The columns do not loop. Each rule follows a leaf of motion/uikit/
|
|
12
|
+
* datePicker.ts `wheels`. Pure functions keep the rules testable without a
|
|
13
|
+
* layout engine.
|
|
14
|
+
*
|
|
15
|
+
* SYNC: When modified, update timeWheelRules.test.ts and TimeWheels.tsx.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { clampTime, formatISOTime, parseISOTime } from "../utils/timeParser.js";
|
|
19
|
+
|
|
20
|
+
/** A time of day, 24-hour. */
|
|
21
|
+
|
|
22
|
+
/** A time wheel column. */
|
|
23
|
+
|
|
24
|
+
/** One row of a column: the value it stands for and its label. */
|
|
25
|
+
|
|
26
|
+
/** Inclusive bounds in seconds since midnight; `null` is unbounded. */
|
|
27
|
+
|
|
28
|
+
const SECONDS_PER_DAY = 24 * 3600;
|
|
29
|
+
function secondsOfISO(time) {
|
|
30
|
+
if (time == null) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const parsed = parseISOTime(time);
|
|
34
|
+
return parsed == null ? null : parsed.hour * 3600 + parsed.minute * 60 + parsed.second;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The bounds of a field's `min` and `max` times. */
|
|
38
|
+
export function wheelBounds(min, max) {
|
|
39
|
+
return {
|
|
40
|
+
min: secondsOfISO(min),
|
|
41
|
+
max: secondsOfISO(max)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Whether the hour falls in the PM half (1) or the AM half (0). */
|
|
46
|
+
export function meridiemOf(hour) {
|
|
47
|
+
return hour < 12 ? 0 : 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The 12-hour clock's label for a 24-hour hour: 0 → 12, 13 → 1. */
|
|
51
|
+
export function hour12From24(hour) {
|
|
52
|
+
const h = hour % 12;
|
|
53
|
+
return h === 0 ? 12 : h;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The 24-hour hour for a 12-hour hour in a half of the day: 12 AM → 0. */
|
|
57
|
+
export function hour24From12(hour, meridiem) {
|
|
58
|
+
return hour % 12 + (meridiem === 1 ? 12 : 0);
|
|
59
|
+
}
|
|
60
|
+
function partsOf(seconds) {
|
|
61
|
+
const s = (seconds % SECONDS_PER_DAY + SECONDS_PER_DAY) % SECONDS_PER_DAY;
|
|
62
|
+
return {
|
|
63
|
+
hour: Math.floor(s / 3600),
|
|
64
|
+
minute: Math.floor(s % 3600 / 60),
|
|
65
|
+
second: s % 60
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Whether [start, end] (seconds) overlaps the bounds. */
|
|
70
|
+
function overlaps(start, end, bounds) {
|
|
71
|
+
return (bounds.min == null || end >= bounds.min) && (bounds.max == null || start <= bounds.max);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The time the wheels show for `time`: its seconds kept when the picker has a
|
|
76
|
+
* seconds column and dropped when it has none. A time outside the bounds is
|
|
77
|
+
* shown as it is, on its disabled rows: opening the sheet never moves an
|
|
78
|
+
* untouched value.
|
|
79
|
+
*/
|
|
80
|
+
export function displayedTime(time, hasSeconds) {
|
|
81
|
+
return {
|
|
82
|
+
...time,
|
|
83
|
+
second: hasSeconds ? time.second : 0
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The time a column's rest commits when it would make `time`: the nearest
|
|
89
|
+
* time inside the bounds that the columns have a row for. Past a bound, that
|
|
90
|
+
* is the bound itself, or, with no seconds column, the nearest whole minute
|
|
91
|
+
* inside it (a 16:55:30 maximum: 16:55). Inside the bounds, `time` itself.
|
|
92
|
+
*/
|
|
93
|
+
export function restingTime(time, hasSeconds, bounds) {
|
|
94
|
+
const boundAt = seconds => seconds == null ? undefined : formatISOTime(partsOf(seconds), true);
|
|
95
|
+
const resting = clampTime(formatISOTime(time, hasSeconds), boundAt(bounds.min), boundAt(bounds.max), hasSeconds);
|
|
96
|
+
return parseISOTime(resting) ?? time;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The hour the hour column makes when it comes to rest on `row` from the row
|
|
101
|
+
* that showed `from` (24-hour). In 24-hour time the row is the hour. In 12-hour
|
|
102
|
+
* time the half of the day changes only when the move passes between 11 and 12.
|
|
103
|
+
* The column (1 … 12) does not loop, so 12 counts as next to 1. A move between
|
|
104
|
+
* 12 and 1 to 6 keeps the half of the day. A move between 12 and 7 to 11
|
|
105
|
+
* changes it.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```
|
|
109
|
+
* hourAfterTurn(11, 12, '12h'); // 12: 11 AM → 12 PM
|
|
110
|
+
* hourAfterTurn(12, 1, '12h'); // 13: 12 PM → 1 PM
|
|
111
|
+
* hourAfterTurn(13, 9, '12h'); // 21: 1 PM → 9 PM
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export function hourAfterTurn(from, row, hourFormat) {
|
|
115
|
+
if (hourFormat === '24h') {
|
|
116
|
+
return row;
|
|
117
|
+
}
|
|
118
|
+
const shown = hour12From24(from);
|
|
119
|
+
if (row === shown) {
|
|
120
|
+
return from;
|
|
121
|
+
}
|
|
122
|
+
const half = meridiemOf(from);
|
|
123
|
+
const passes11And12 = shown === 12 && row >= 7 || row === 12 && shown >= 7;
|
|
124
|
+
return hour24From12(row, passes11And12 ? 1 - half : half);
|
|
125
|
+
}
|
|
126
|
+
function hourRowsFor(hourFormat, hourOf, bounds) {
|
|
127
|
+
const rows = hourFormat === '24h' ? Array.from({
|
|
128
|
+
length: 24
|
|
129
|
+
}, (_, hour) => hour) : Array.from({
|
|
130
|
+
length: 12
|
|
131
|
+
}, (_, index) => index + 1);
|
|
132
|
+
return rows.map(row => {
|
|
133
|
+
const hour = hourOf(row);
|
|
134
|
+
return {
|
|
135
|
+
value: row,
|
|
136
|
+
label: hourFormat === '24h' ? String(row).padStart(2, '0') : String(row),
|
|
137
|
+
isDisabled: !overlaps(hour * 3600, hour * 3600 + 3599, bounds),
|
|
138
|
+
order: hour
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The hour column under a finger. In 24-hour time its rows are 00 … 23. In
|
|
145
|
+
* 12-hour time they are 1 … 12, each row standing for the hour a turn onto it
|
|
146
|
+
* from `from` makes (`hourAfterTurn`). A row is disabled when no minute of that
|
|
147
|
+
* hour is inside the bounds.
|
|
148
|
+
*/
|
|
149
|
+
export function hourRows(from, hourFormat, bounds) {
|
|
150
|
+
return hourRowsFor(hourFormat, row => hourAfterTurn(from, row, hourFormat), bounds);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The hour column under a mouse, whose columns turn one at a time. A 12-hour
|
|
155
|
+
* row stands for its hour in the half of the day that `from` is in.
|
|
156
|
+
*/
|
|
157
|
+
export function hourRowsInHalf(from, hourFormat, bounds) {
|
|
158
|
+
const half = meridiemOf(from);
|
|
159
|
+
return hourRowsFor(hourFormat, row => hourFormat === '24h' ? row : hour24From12(row, half), bounds);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The minute column for `hour`: every minute. A row is disabled when it is
|
|
164
|
+
* outside the bounds (its whole minute, when the picker shows seconds).
|
|
165
|
+
*/
|
|
166
|
+
export function minuteRows(hour, hasSeconds, bounds) {
|
|
167
|
+
return Array.from({
|
|
168
|
+
length: 60
|
|
169
|
+
}, (_, minute) => {
|
|
170
|
+
const start = hour * 3600 + minute * 60;
|
|
171
|
+
return {
|
|
172
|
+
value: minute,
|
|
173
|
+
label: String(minute).padStart(2, '0'),
|
|
174
|
+
isDisabled: !overlaps(start, start + (hasSeconds ? 59 : 0), bounds)
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** The second column for `hour`:`minute`. */
|
|
180
|
+
export function secondRows(hour, minute, bounds) {
|
|
181
|
+
return Array.from({
|
|
182
|
+
length: 60
|
|
183
|
+
}, (_, second) => {
|
|
184
|
+
const at = hour * 3600 + minute * 60 + second;
|
|
185
|
+
return {
|
|
186
|
+
value: second,
|
|
187
|
+
label: String(second).padStart(2, '0'),
|
|
188
|
+
isDisabled: !overlaps(at, at, bounds)
|
|
189
|
+
};
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The AM/PM column: a half is disabled when none of its hours is in bounds. */
|
|
194
|
+
export function meridiemRows(labels, bounds) {
|
|
195
|
+
return [{
|
|
196
|
+
value: 0,
|
|
197
|
+
label: labels.am,
|
|
198
|
+
isDisabled: !overlaps(0, 12 * 3600 - 1, bounds)
|
|
199
|
+
}, {
|
|
200
|
+
value: 1,
|
|
201
|
+
label: labels.pm,
|
|
202
|
+
isDisabled: !overlaps(12 * 3600, SECONDS_PER_DAY - 1, bounds)
|
|
203
|
+
}];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The time made by turning `column` to `value` (its row's value) from `from`
|
|
208
|
+
* (the time the wheels show). Only that column changes, and the AM/PM column
|
|
209
|
+
* moves the hour by twelve.
|
|
210
|
+
*/
|
|
211
|
+
export function turnColumn(from, column, value, hourFormat) {
|
|
212
|
+
switch (column) {
|
|
213
|
+
case 'hour':
|
|
214
|
+
return {
|
|
215
|
+
...from,
|
|
216
|
+
hour: hourAfterTurn(from.hour, value, hourFormat)
|
|
217
|
+
};
|
|
218
|
+
case 'minute':
|
|
219
|
+
return {
|
|
220
|
+
...from,
|
|
221
|
+
minute: value
|
|
222
|
+
};
|
|
223
|
+
case 'second':
|
|
224
|
+
return {
|
|
225
|
+
...from,
|
|
226
|
+
second: value
|
|
227
|
+
};
|
|
228
|
+
case 'meridiem':
|
|
229
|
+
return {
|
|
230
|
+
...from,
|
|
231
|
+
hour: hour24From12(hour12From24(from.hour), value)
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** What a column shows for a time: its row's value. */
|
|
237
|
+
export function columnValue(time, column, hourFormat) {
|
|
238
|
+
switch (column) {
|
|
239
|
+
case 'hour':
|
|
240
|
+
return hourFormat === '24h' ? time.hour : hour12From24(time.hour);
|
|
241
|
+
case 'minute':
|
|
242
|
+
return time.minute;
|
|
243
|
+
case 'second':
|
|
244
|
+
return time.second;
|
|
245
|
+
case 'meridiem':
|
|
246
|
+
return meridiemOf(time.hour);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The columns that must turn after `column` came to rest on `value`. That is
|
|
252
|
+
* every column whose row for the committed time differs from the row it shows
|
|
253
|
+
* now. The column that moved shows `value`; the others show `from`. An hour
|
|
254
|
+
* that crossed 11 ↔ 12 turns the AM/PM column; a time brought back onto a bound
|
|
255
|
+
* turns every column whose row changed.
|
|
256
|
+
*/
|
|
257
|
+
export function columnsToTurn(from, column, value, committed, options) {
|
|
258
|
+
const columns = ['hour', 'minute'];
|
|
259
|
+
if (options.hasSeconds) {
|
|
260
|
+
columns.push('second');
|
|
261
|
+
}
|
|
262
|
+
if (options.hourFormat === '12h') {
|
|
263
|
+
columns.push('meridiem');
|
|
264
|
+
}
|
|
265
|
+
const turns = [];
|
|
266
|
+
for (const each of columns) {
|
|
267
|
+
const shown = each === column ? value : columnValue(from, each, options.hourFormat);
|
|
268
|
+
const target = columnValue(committed, each, options.hourFormat);
|
|
269
|
+
if (shown !== target) {
|
|
270
|
+
turns.push({
|
|
271
|
+
column: each,
|
|
272
|
+
value: target
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return turns;
|
|
277
|
+
}
|