@mantine-vue/dates 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.cjs +189 -71
- package/cjs/index.cjs.map +1 -1
- package/esm/index.mjs +189 -71
- package/esm/index.mjs.map +1 -1
- package/lib/index.d.mts +120 -12
- package/lib/index.d.ts +120 -12
- package/package.json +3 -3
- package/styles.css +137 -102
- package/styles.layer.css +137 -102
package/esm/index.mjs
CHANGED
|
@@ -4,44 +4,45 @@ import { computed, defineComponent, h, inject, provide, ref, watch } from "vue";
|
|
|
4
4
|
import { useUncontrolled } from "@mantine-vue/hooks";
|
|
5
5
|
import { AccordionChevron, ActionIcon, Box, Button, CheckIcon, CloseButton, Group, InputBase, Modal, Popover, ScrollArea, SimpleGrid, Text, UnstyledButton } from "@mantine-vue/core";
|
|
6
6
|
var Dates_module_default = {
|
|
7
|
-
calendar: "
|
|
8
|
-
calendarLevel: "
|
|
9
|
-
calendarHeader: "
|
|
10
|
-
calendarHeaderLevel: "
|
|
11
|
-
calendarHeaderControl: "
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
7
|
+
calendar: "_calendar_zystn_1",
|
|
8
|
+
calendarLevel: "_calendarLevel_zystn_15",
|
|
9
|
+
calendarHeader: "_calendarHeader_zystn_19",
|
|
10
|
+
calendarHeaderLevel: "_calendarHeaderLevel_zystn_32",
|
|
11
|
+
calendarHeaderControl: "_calendarHeaderControl_zystn_33",
|
|
12
|
+
calendarHeaderSelect: "_calendarHeaderSelect_zystn_79",
|
|
13
|
+
calendarHeaderControlIcon: "_calendarHeaderControlIcon_zystn_109",
|
|
14
|
+
month: "_month_zystn_122",
|
|
15
|
+
monthRow: "_monthRow_zystn_132",
|
|
16
|
+
monthCell: "_monthCell_zystn_136",
|
|
17
|
+
weekday: "_weekday_zystn_145",
|
|
18
|
+
weekNumber: "_weekNumber_zystn_157",
|
|
19
|
+
day: "_day_zystn_163",
|
|
20
|
+
pickerControl: "_pickerControl_zystn_224",
|
|
21
|
+
controlsGrid: "_controlsGrid_zystn_230",
|
|
22
|
+
timePicker: "_timePicker_zystn_290",
|
|
23
|
+
dateTimePicker: "_dateTimePicker_zystn_291",
|
|
24
|
+
datePickerRoot: "_datePickerRoot_zystn_295",
|
|
25
|
+
timeWrapper: "_timeWrapper_zystn_305",
|
|
26
|
+
timeInput: "_timeInput_zystn_311",
|
|
27
|
+
presetsList: "_presetsList_zystn_316",
|
|
28
|
+
presetButton: "_presetButton_zystn_324",
|
|
29
|
+
timePickerPresetsGroup: "_timePickerPresetsGroup_zystn_335",
|
|
30
|
+
dropdown: "_dropdown_zystn_339",
|
|
31
|
+
placeholder: "_placeholder_zystn_343",
|
|
32
|
+
timeGridControl: "_timeGridControl_zystn_347",
|
|
33
|
+
timePickerFieldsRoot: "_timePickerFieldsRoot_zystn_378",
|
|
34
|
+
timePickerFieldsGroup: "_timePickerFieldsGroup_zystn_385",
|
|
35
|
+
timePickerField: "_timePickerField_zystn_378",
|
|
36
|
+
timePickerDropdown: "_timePickerDropdown_zystn_435",
|
|
37
|
+
timePickerControlsListGroup: "_timePickerControlsListGroup_zystn_439",
|
|
38
|
+
timePickerControlsList: "_timePickerControlsList_zystn_439",
|
|
39
|
+
timePickerControl: "_timePickerControl_zystn_439",
|
|
40
|
+
miniCalendarRoot: "_miniCalendarRoot_zystn_468",
|
|
41
|
+
miniCalendarDays: "_miniCalendarDays_zystn_475",
|
|
42
|
+
miniCalendarDay: "_miniCalendarDay_zystn_475",
|
|
43
|
+
miniCalendarDayMonth: "_miniCalendarDayMonth_zystn_510",
|
|
44
|
+
miniCalendarDayNumber: "_miniCalendarDayNumber_zystn_516",
|
|
45
|
+
miniCalendarControl: "_miniCalendarControl_zystn_521"
|
|
45
46
|
};
|
|
46
47
|
//#endregion
|
|
47
48
|
//#region src/index.ts
|
|
@@ -242,6 +243,7 @@ function getDecadeLabel(date) {
|
|
|
242
243
|
var Day = defineComponent({
|
|
243
244
|
name: "Day",
|
|
244
245
|
inheritAttrs: false,
|
|
246
|
+
slots: Object,
|
|
245
247
|
props: {
|
|
246
248
|
date: {
|
|
247
249
|
type: String,
|
|
@@ -276,7 +278,7 @@ var Day = defineComponent({
|
|
|
276
278
|
},
|
|
277
279
|
unstyled: Boolean
|
|
278
280
|
},
|
|
279
|
-
setup(props, { attrs }) {
|
|
281
|
+
setup(props, { attrs, slots }) {
|
|
280
282
|
return () => h(UnstyledButton, {
|
|
281
283
|
...attrs,
|
|
282
284
|
component: props.static ? "div" : "button",
|
|
@@ -295,7 +297,7 @@ var Day = defineComponent({
|
|
|
295
297
|
"data-last-in-range": props.lastInRange && !props.disabled || void 0,
|
|
296
298
|
"data-static": props.static || void 0,
|
|
297
299
|
"data-full-width": props.fullWidth || void 0
|
|
298
|
-
}, () => props.renderDay?.(props.date) || dayjs(props.date).date());
|
|
300
|
+
}, () => (props.renderDay ? props.renderDay(props.date) : (slots.renderDay ?? slots.day)?.({ date: props.date })) || dayjs(props.date).date());
|
|
299
301
|
}
|
|
300
302
|
});
|
|
301
303
|
var PickerControl = defineComponent({
|
|
@@ -359,6 +361,15 @@ var CalendarHeader = defineComponent({
|
|
|
359
361
|
},
|
|
360
362
|
levelControlAriaLabel: String,
|
|
361
363
|
fullWidth: Boolean,
|
|
364
|
+
withNativeLevelSelect: Boolean,
|
|
365
|
+
yearsSelectRange: Array,
|
|
366
|
+
calendarLevel: String,
|
|
367
|
+
date: [String, Date],
|
|
368
|
+
locale: String,
|
|
369
|
+
onDateChange: Function,
|
|
370
|
+
minDate: [String, Date],
|
|
371
|
+
maxDate: [String, Date],
|
|
372
|
+
disableNativeLevelSelect: Boolean,
|
|
362
373
|
onNext: Function,
|
|
363
374
|
onPrevious: Function,
|
|
364
375
|
onLevelClick: Function
|
|
@@ -377,7 +388,40 @@ var CalendarHeader = defineComponent({
|
|
|
377
388
|
"data-direction": "previous",
|
|
378
389
|
size: "45%"
|
|
379
390
|
})) : null;
|
|
380
|
-
const
|
|
391
|
+
const displayed = props.date ? dayjs(props.date) : dayjs();
|
|
392
|
+
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
393
|
+
const rawMinYear = props.yearsSelectRange?.[0] ?? (props.minDate ? dayjs(props.minDate).year() : currentYear - 100);
|
|
394
|
+
const rawMaxYear = props.yearsSelectRange?.[1] ?? (props.maxDate ? dayjs(props.maxDate).year() : currentYear + 50);
|
|
395
|
+
const minYear = Math.min(rawMinYear, rawMaxYear, displayed.year());
|
|
396
|
+
const maxYear = Math.max(rawMinYear, rawMaxYear, displayed.year());
|
|
397
|
+
const updateNativeDate = (next) => {
|
|
398
|
+
let result = next;
|
|
399
|
+
if (props.minDate && result.isBefore(dayjs(props.minDate), "day")) result = dayjs(props.minDate);
|
|
400
|
+
if (props.maxDate && result.isAfter(dayjs(props.maxDate), "day")) result = dayjs(props.maxDate);
|
|
401
|
+
props.onDateChange?.(result.format("YYYY-MM-DD"));
|
|
402
|
+
};
|
|
403
|
+
const levelControl = (props.withNativeLevelSelect && props.date && props.onDateChange && props.calendarLevel !== "decade" ? h("div", {
|
|
404
|
+
class: Dates_module_default.calendarHeaderLevel,
|
|
405
|
+
"data-static": true,
|
|
406
|
+
"data-native-level-select": true
|
|
407
|
+
}, [props.calendarLevel === "month" ? h("select", {
|
|
408
|
+
class: Dates_module_default.calendarHeaderSelect,
|
|
409
|
+
"data-select": "month",
|
|
410
|
+
disabled: props.disableNativeLevelSelect,
|
|
411
|
+
value: displayed.month(),
|
|
412
|
+
"aria-label": props.levelControlAriaLabel,
|
|
413
|
+
onChange: (event) => updateNativeDate(displayed.month(Number(event.target.value)))
|
|
414
|
+
}, Array.from({ length: 12 }, (_, month) => h("option", { value: month }, dayjs().locale(props.locale || "en").month(month).format("MMMM")))) : null, h("select", {
|
|
415
|
+
class: Dates_module_default.calendarHeaderSelect,
|
|
416
|
+
"data-select": "year",
|
|
417
|
+
disabled: props.disableNativeLevelSelect,
|
|
418
|
+
value: displayed.year(),
|
|
419
|
+
"aria-label": props.levelControlAriaLabel,
|
|
420
|
+
onChange: (event) => updateNativeDate(displayed.year(Number(event.target.value)))
|
|
421
|
+
}, Array.from({ length: maxYear - minYear + 1 }, (_, index) => {
|
|
422
|
+
const year = minYear + index;
|
|
423
|
+
return h("option", { value: year }, year);
|
|
424
|
+
}))]) : null) ?? h(UnstyledButton, {
|
|
381
425
|
component: props.hasNextLevel ? "button" : "div",
|
|
382
426
|
class: Dates_module_default.calendarHeaderLevel,
|
|
383
427
|
onClick: props.hasNextLevel ? props.onLevelClick : void 0,
|
|
@@ -434,6 +478,7 @@ var WeekdaysRow = defineComponent({
|
|
|
434
478
|
});
|
|
435
479
|
var Month = defineComponent({
|
|
436
480
|
name: "Month",
|
|
481
|
+
slots: Object,
|
|
437
482
|
props: {
|
|
438
483
|
month: {
|
|
439
484
|
type: String,
|
|
@@ -472,7 +517,7 @@ var Month = defineComponent({
|
|
|
472
517
|
static: Boolean,
|
|
473
518
|
fullWidth: Boolean
|
|
474
519
|
},
|
|
475
|
-
setup(props) {
|
|
520
|
+
setup(props, { slots }) {
|
|
476
521
|
const ctx = useDatesContext();
|
|
477
522
|
const hovered = ref(null);
|
|
478
523
|
const dayRefs = [];
|
|
@@ -531,7 +576,7 @@ var Month = defineComponent({
|
|
|
531
576
|
lastInRange: isSameDate(date, end),
|
|
532
577
|
highlightToday: props.highlightToday,
|
|
533
578
|
fullWidth: props.fullWidth,
|
|
534
|
-
renderDay: props.renderDay,
|
|
579
|
+
renderDay: props.renderDay ?? (slots.renderDay ?? slots.day ? (date) => (slots.renderDay ?? slots.day)?.({ date }) : void 0),
|
|
535
580
|
"aria-label": props.getDayAriaLabel?.(date),
|
|
536
581
|
tabindex: props.static ? void 0 : date === dateInTabOrder ? 0 : -1,
|
|
537
582
|
"data-autofocus": selected || void 0,
|
|
@@ -718,6 +763,7 @@ function clampLevel(level, minLevel, maxLevel) {
|
|
|
718
763
|
}
|
|
719
764
|
var Calendar = defineComponent({
|
|
720
765
|
name: "Calendar",
|
|
766
|
+
slots: Object,
|
|
721
767
|
props: {
|
|
722
768
|
defaultLevel: String,
|
|
723
769
|
level: String,
|
|
@@ -789,9 +835,11 @@ var Calendar = defineComponent({
|
|
|
789
835
|
highlightToday: Boolean,
|
|
790
836
|
withWeekNumbers: Boolean,
|
|
791
837
|
static: Boolean,
|
|
792
|
-
fullWidth: Boolean
|
|
838
|
+
fullWidth: Boolean,
|
|
839
|
+
withNativeLevelSelect: Boolean,
|
|
840
|
+
yearsSelectRange: Array
|
|
793
841
|
},
|
|
794
|
-
setup(props, { attrs }) {
|
|
842
|
+
setup(props, { attrs, slots }) {
|
|
795
843
|
const [_level, setLevel] = useUncontrolled({
|
|
796
844
|
value: computed(() => props.level === void 0 ? void 0 : clampLevel(props.level, props.minLevel, props.maxLevel)),
|
|
797
845
|
defaultValue: props.defaultLevel === void 0 ? void 0 : clampLevel(props.defaultLevel, props.minLevel, props.maxLevel),
|
|
@@ -824,6 +872,15 @@ var Calendar = defineComponent({
|
|
|
824
872
|
withPrevious: column === 0,
|
|
825
873
|
withNext: column === (props.numberOfColumns || 1) - 1,
|
|
826
874
|
fullWidth: props.fullWidth,
|
|
875
|
+
withNativeLevelSelect: props.withNativeLevelSelect,
|
|
876
|
+
yearsSelectRange: props.yearsSelectRange,
|
|
877
|
+
calendarLevel: "month",
|
|
878
|
+
date: currentDate,
|
|
879
|
+
locale: props.locale,
|
|
880
|
+
onDateChange: setDate,
|
|
881
|
+
minDate: props.minDate,
|
|
882
|
+
maxDate: props.maxDate,
|
|
883
|
+
disableNativeLevelSelect: props.date !== void 0 && !props.onDateChange,
|
|
827
884
|
onPrevious: () => updateDate(-scroll, "month"),
|
|
828
885
|
onNext: () => updateDate(scroll, "month"),
|
|
829
886
|
onLevelClick: () => setLevel(getNextLevel(_level.value, "up"))
|
|
@@ -835,7 +892,7 @@ var Calendar = defineComponent({
|
|
|
835
892
|
maxDate: props.maxDate,
|
|
836
893
|
firstDayOfWeek: props.firstDayOfWeek,
|
|
837
894
|
weekendDays: props.weekendDays,
|
|
838
|
-
renderDay: props.renderDay,
|
|
895
|
+
renderDay: props.renderDay ?? (slots.renderDay ?? slots.day ? (date) => (slots.renderDay ?? slots.day)?.({ date }) : void 0),
|
|
839
896
|
getDayProps: props.getDayProps,
|
|
840
897
|
getDayAriaLabel: props.getDayAriaLabel,
|
|
841
898
|
excludeDate: props.excludeDate,
|
|
@@ -854,6 +911,15 @@ var Calendar = defineComponent({
|
|
|
854
911
|
withPrevious: column === 0,
|
|
855
912
|
withNext: column === (props.numberOfColumns || 1) - 1,
|
|
856
913
|
fullWidth: props.fullWidth,
|
|
914
|
+
withNativeLevelSelect: props.withNativeLevelSelect,
|
|
915
|
+
yearsSelectRange: props.yearsSelectRange,
|
|
916
|
+
calendarLevel: "year",
|
|
917
|
+
date: currentDate,
|
|
918
|
+
locale: props.locale,
|
|
919
|
+
onDateChange: setDate,
|
|
920
|
+
minDate: props.minDate,
|
|
921
|
+
maxDate: props.maxDate,
|
|
922
|
+
disableNativeLevelSelect: props.date !== void 0 && !props.onDateChange,
|
|
857
923
|
onPrevious: () => updateDate(-scroll, "year"),
|
|
858
924
|
onNext: () => updateDate(scroll, "year"),
|
|
859
925
|
onLevelClick: () => setLevel(getNextLevel(_level.value, "up"))
|
|
@@ -927,6 +993,7 @@ function getNextPickerValue(value, date, type, sortDates = true) {
|
|
|
927
993
|
}
|
|
928
994
|
var DatePicker = defineComponent({
|
|
929
995
|
name: "DatePicker",
|
|
996
|
+
slots: Object,
|
|
930
997
|
props: {
|
|
931
998
|
type: {
|
|
932
999
|
type: String,
|
|
@@ -951,9 +1018,11 @@ var DatePicker = defineComponent({
|
|
|
951
1018
|
type: Boolean,
|
|
952
1019
|
default: true
|
|
953
1020
|
},
|
|
954
|
-
presets: Array
|
|
1021
|
+
presets: Array,
|
|
1022
|
+
withNativeLevelSelect: Boolean,
|
|
1023
|
+
yearsSelectRange: Array
|
|
955
1024
|
},
|
|
956
|
-
setup(props, { attrs }) {
|
|
1025
|
+
setup(props, { attrs, slots }) {
|
|
957
1026
|
const finalValue = computed(() => props.type === "multiple" ? [] : props.type === "range" ? [null, null] : null);
|
|
958
1027
|
const [_value, setValue] = useUncontrolled({
|
|
959
1028
|
value: computed(() => props.value),
|
|
@@ -984,7 +1053,12 @@ var DatePicker = defineComponent({
|
|
|
984
1053
|
onDateChange: (date) => calendarDate.value = date,
|
|
985
1054
|
level: calendarLevel.value,
|
|
986
1055
|
onLevelChange: (level) => calendarLevel.value = level,
|
|
1056
|
+
withNativeLevelSelect: props.withNativeLevelSelect,
|
|
1057
|
+
yearsSelectRange: props.yearsSelectRange,
|
|
987
1058
|
onDayClick: selectDate
|
|
1059
|
+
}, {
|
|
1060
|
+
renderDay: slots.renderDay,
|
|
1061
|
+
day: slots.day
|
|
988
1062
|
});
|
|
989
1063
|
if (!props.presets?.length) return calendar;
|
|
990
1064
|
return h("div", { class: Dates_module_default.datePickerRoot }, [h("div", { class: Dates_module_default.presetsList }, props.presets.map((preset, index) => h(UnstyledButton, {
|
|
@@ -1023,7 +1097,9 @@ var YearPicker = defineComponent({
|
|
|
1023
1097
|
default: true
|
|
1024
1098
|
},
|
|
1025
1099
|
presets: Array,
|
|
1026
|
-
onYearSelect: Function
|
|
1100
|
+
onYearSelect: Function,
|
|
1101
|
+
withNativeLevelSelect: Boolean,
|
|
1102
|
+
yearsSelectRange: Array
|
|
1027
1103
|
},
|
|
1028
1104
|
setup(props, { attrs }) {
|
|
1029
1105
|
const finalValue = computed(() => props.type === "multiple" ? [] : props.type === "range" ? [null, null] : null);
|
|
@@ -1067,6 +1143,8 @@ var YearPicker = defineComponent({
|
|
|
1067
1143
|
onDateChange: (date) => calendarDate.value = date,
|
|
1068
1144
|
defaultLevel: "decade",
|
|
1069
1145
|
minLevel: "decade",
|
|
1146
|
+
withNativeLevelSelect: props.withNativeLevelSelect,
|
|
1147
|
+
yearsSelectRange: props.yearsSelectRange,
|
|
1070
1148
|
onYearSelect: selectYear,
|
|
1071
1149
|
getYearControlProps: yearControlProps,
|
|
1072
1150
|
onYearMouseEnter: (date) => {
|
|
@@ -1114,7 +1192,9 @@ var MonthPicker = defineComponent({
|
|
|
1114
1192
|
default: true
|
|
1115
1193
|
},
|
|
1116
1194
|
presets: Array,
|
|
1117
|
-
onMonthSelect: Function
|
|
1195
|
+
onMonthSelect: Function,
|
|
1196
|
+
withNativeLevelSelect: Boolean,
|
|
1197
|
+
yearsSelectRange: Array
|
|
1118
1198
|
},
|
|
1119
1199
|
setup(props, { attrs }) {
|
|
1120
1200
|
const finalValue = computed(() => props.type === "multiple" ? [] : props.type === "range" ? [null, null] : null);
|
|
@@ -1158,6 +1238,8 @@ var MonthPicker = defineComponent({
|
|
|
1158
1238
|
onDateChange: (date) => calendarDate.value = date,
|
|
1159
1239
|
defaultLevel: "year",
|
|
1160
1240
|
minLevel: "year",
|
|
1241
|
+
withNativeLevelSelect: props.withNativeLevelSelect,
|
|
1242
|
+
yearsSelectRange: props.yearsSelectRange,
|
|
1161
1243
|
onMonthSelect: selectMonth,
|
|
1162
1244
|
getMonthControlProps: monthControlProps,
|
|
1163
1245
|
onMonthMouseEnter: (date) => {
|
|
@@ -1311,7 +1393,9 @@ function createPickerInput(name, Picker, defaultLevel, defaultValueFormat = "MMM
|
|
|
1311
1393
|
type: Boolean,
|
|
1312
1394
|
default: true
|
|
1313
1395
|
},
|
|
1314
|
-
valueFormatter: Function
|
|
1396
|
+
valueFormatter: Function,
|
|
1397
|
+
withNativeLevelSelect: Boolean,
|
|
1398
|
+
yearsSelectRange: Array
|
|
1315
1399
|
},
|
|
1316
1400
|
setup(props, { attrs }) {
|
|
1317
1401
|
const finalValue = computed(() => props.type === "multiple" ? [] : props.type === "range" ? [null, null] : null);
|
|
@@ -1340,6 +1424,8 @@ function createPickerInput(name, Picker, defaultLevel, defaultValueFormat = "MMM
|
|
|
1340
1424
|
sortDates: props.sortDates,
|
|
1341
1425
|
defaultLevel,
|
|
1342
1426
|
locale: props.locale,
|
|
1427
|
+
withNativeLevelSelect: props.withNativeLevelSelect,
|
|
1428
|
+
yearsSelectRange: props.yearsSelectRange,
|
|
1343
1429
|
onChange: (value) => {
|
|
1344
1430
|
setValue(value);
|
|
1345
1431
|
if (props.closeOnChange && props.type === "default") close();
|
|
@@ -1680,7 +1766,8 @@ var SpinInput = defineComponent({
|
|
|
1680
1766
|
readOnly: Boolean
|
|
1681
1767
|
},
|
|
1682
1768
|
setup(props, { attrs }) {
|
|
1683
|
-
const
|
|
1769
|
+
const finiteMax = () => Number.isFinite(props.max);
|
|
1770
|
+
const maxDigit = () => finiteMax() ? Number(props.max.toFixed(0)[0]) : Infinity;
|
|
1684
1771
|
const arrowsMax = () => props.max + 1 - props.step;
|
|
1685
1772
|
const handleChange = (raw) => {
|
|
1686
1773
|
if (props.readOnly) return;
|
|
@@ -1690,9 +1777,9 @@ var SpinInput = defineComponent({
|
|
|
1690
1777
|
for (let i = 0; i < clearValue.length; i += 1) {
|
|
1691
1778
|
const digit = clearValue.charCodeAt(i) - 48;
|
|
1692
1779
|
const next = parsedValue * 10 + digit;
|
|
1693
|
-
parsedValue = next > props.max ? digit : next;
|
|
1780
|
+
parsedValue = finiteMax() && next > props.max ? digit : next;
|
|
1694
1781
|
}
|
|
1695
|
-
const clampedValue = props.allowTemporaryZero && parsedValue === 0 && props.min > 0 ? 0 : Math.min(Math.max(parsedValue, props.min), props.max);
|
|
1782
|
+
const clampedValue = props.allowTemporaryZero && parsedValue === 0 && props.min > 0 ? 0 : finiteMax() ? Math.min(Math.max(parsedValue, props.min), props.max) : Math.max(parsedValue, props.min);
|
|
1696
1783
|
props.onChange?.(clampedValue);
|
|
1697
1784
|
if (!props.disableAutoAdvance && (clampedValue > maxDigit() || raw.startsWith("00"))) props.onNextInput?.();
|
|
1698
1785
|
};
|
|
@@ -1712,7 +1799,7 @@ var SpinInput = defineComponent({
|
|
|
1712
1799
|
}
|
|
1713
1800
|
if (event.key === "End") {
|
|
1714
1801
|
event.preventDefault();
|
|
1715
|
-
props.onChange?.(props.max);
|
|
1802
|
+
if (finiteMax()) props.onChange?.(props.max);
|
|
1716
1803
|
}
|
|
1717
1804
|
if (event.key === "Backspace" || event.key === "Delete") {
|
|
1718
1805
|
event.preventDefault();
|
|
@@ -1729,12 +1816,12 @@ var SpinInput = defineComponent({
|
|
|
1729
1816
|
}
|
|
1730
1817
|
if (event.key === "ArrowUp") {
|
|
1731
1818
|
event.preventDefault();
|
|
1732
|
-
const newValue = props.value === null ? props.min : Math.min(Math.max(props.value + props.step, props.min), arrowsMax());
|
|
1819
|
+
const newValue = props.value === null ? props.min : finiteMax() ? Math.min(Math.max(props.value + props.step, props.min), arrowsMax()) : Math.max(props.value + props.step, props.min);
|
|
1733
1820
|
props.onChange?.(newValue);
|
|
1734
1821
|
}
|
|
1735
1822
|
if (event.key === "ArrowDown") {
|
|
1736
1823
|
event.preventDefault();
|
|
1737
|
-
const newValue = props.value === null ? arrowsMax() : Math.min(Math.max(props.value - props.step, props.min), arrowsMax());
|
|
1824
|
+
const newValue = props.value === null ? finiteMax() ? arrowsMax() : props.min : Math.min(Math.max(props.value - props.step, props.min), arrowsMax());
|
|
1738
1825
|
props.onChange?.(newValue);
|
|
1739
1826
|
}
|
|
1740
1827
|
};
|
|
@@ -1743,7 +1830,7 @@ var SpinInput = defineComponent({
|
|
|
1743
1830
|
type: "text",
|
|
1744
1831
|
role: "spinbutton",
|
|
1745
1832
|
"aria-valuemin": props.min,
|
|
1746
|
-
"aria-valuemax": props.max,
|
|
1833
|
+
"aria-valuemax": finiteMax() ? props.max : void 0,
|
|
1747
1834
|
"aria-valuenow": props.value === null ? 0 : props.value,
|
|
1748
1835
|
"data-empty": props.value === null || void 0,
|
|
1749
1836
|
inputmode: "numeric",
|
|
@@ -1825,6 +1912,10 @@ var TimePicker = defineComponent({
|
|
|
1825
1912
|
value: String,
|
|
1826
1913
|
defaultValue: String,
|
|
1827
1914
|
onChange: Function,
|
|
1915
|
+
type: {
|
|
1916
|
+
type: String,
|
|
1917
|
+
default: "time"
|
|
1918
|
+
},
|
|
1828
1919
|
withSeconds: Boolean,
|
|
1829
1920
|
min: String,
|
|
1830
1921
|
max: String,
|
|
@@ -1861,6 +1952,7 @@ var TimePicker = defineComponent({
|
|
|
1861
1952
|
hoursRef: Object
|
|
1862
1953
|
},
|
|
1863
1954
|
setup(props, { attrs }) {
|
|
1955
|
+
const effectiveFormat = computed(() => props.type === "duration" ? "24h" : props.format);
|
|
1864
1956
|
const [_value, setValue] = useUncontrolled({
|
|
1865
1957
|
value: computed(() => props.value),
|
|
1866
1958
|
defaultValue: props.defaultValue,
|
|
@@ -1869,7 +1961,7 @@ var TimePicker = defineComponent({
|
|
|
1869
1961
|
});
|
|
1870
1962
|
const parsed = computed(() => getParsedTime({
|
|
1871
1963
|
time: _value.value,
|
|
1872
|
-
format:
|
|
1964
|
+
format: effectiveFormat.value,
|
|
1873
1965
|
amPmLabels: props.amPmLabels
|
|
1874
1966
|
}));
|
|
1875
1967
|
const hours = ref(parsed.value.hours);
|
|
@@ -1879,7 +1971,7 @@ var TimePicker = defineComponent({
|
|
|
1879
1971
|
watch(_value, (value) => {
|
|
1880
1972
|
const next = getParsedTime({
|
|
1881
1973
|
time: value,
|
|
1882
|
-
format:
|
|
1974
|
+
format: effectiveFormat.value,
|
|
1883
1975
|
amPmLabels: props.amPmLabels
|
|
1884
1976
|
});
|
|
1885
1977
|
hours.value = next.hours;
|
|
@@ -1905,7 +1997,7 @@ var TimePicker = defineComponent({
|
|
|
1905
1997
|
hours: hours.value,
|
|
1906
1998
|
minutes: minutes.value,
|
|
1907
1999
|
seconds: seconds.value,
|
|
1908
|
-
format:
|
|
2000
|
+
format: effectiveFormat.value,
|
|
1909
2001
|
withSeconds: props.withSeconds,
|
|
1910
2002
|
amPm: amPm.value,
|
|
1911
2003
|
amPmLabels: props.amPmLabels
|
|
@@ -1914,7 +2006,7 @@ var TimePicker = defineComponent({
|
|
|
1914
2006
|
};
|
|
1915
2007
|
const setHours = (value) => {
|
|
1916
2008
|
let adjusted = value;
|
|
1917
|
-
if (
|
|
2009
|
+
if (effectiveFormat.value === "12h" && typeof value === "number" && value > 12) adjusted = (value - 1) % 12 + 1;
|
|
1918
2010
|
hours.value = adjusted;
|
|
1919
2011
|
commit();
|
|
1920
2012
|
focus("hours");
|
|
@@ -1948,8 +2040,32 @@ var TimePicker = defineComponent({
|
|
|
1948
2040
|
setValue(timeString);
|
|
1949
2041
|
if (props.closeDropdownOnPresetSelect) opened.value = false;
|
|
1950
2042
|
};
|
|
2043
|
+
const handlePaste = (event) => {
|
|
2044
|
+
if (props.readOnly || props.disabled) return;
|
|
2045
|
+
const value = event.clipboardData?.getData("text").trim();
|
|
2046
|
+
if (!value || !/^\d+:\d{2}(?::\d{2})?(?:\s+[aApP][mM])?$/.test(value)) return;
|
|
2047
|
+
const next = getParsedTime({
|
|
2048
|
+
time: value,
|
|
2049
|
+
format: effectiveFormat.value,
|
|
2050
|
+
amPmLabels: props.amPmLabels
|
|
2051
|
+
});
|
|
2052
|
+
if (next.hours === null || next.minutes === null || next.minutes > 59 || props.withSeconds && (next.seconds === null || next.seconds > 59) || props.type === "time" && effectiveFormat.value === "24h" && next.hours > 23) return;
|
|
2053
|
+
event.preventDefault();
|
|
2054
|
+
hours.value = next.hours;
|
|
2055
|
+
minutes.value = next.minutes;
|
|
2056
|
+
seconds.value = props.withSeconds ? next.seconds : null;
|
|
2057
|
+
amPm.value = next.amPm;
|
|
2058
|
+
const result = getTimeString({
|
|
2059
|
+
...next,
|
|
2060
|
+
seconds: props.withSeconds ? next.seconds : null,
|
|
2061
|
+
format: effectiveFormat.value,
|
|
2062
|
+
withSeconds: props.withSeconds,
|
|
2063
|
+
amPmLabels: props.amPmLabels
|
|
2064
|
+
});
|
|
2065
|
+
if (result.valid) setValue(clampTime(result.value, props.min, props.max));
|
|
2066
|
+
};
|
|
1951
2067
|
return () => h(Popover, {
|
|
1952
|
-
opened: props.withDropdown && opened.value,
|
|
2068
|
+
opened: props.type !== "duration" && props.withDropdown && opened.value,
|
|
1953
2069
|
position: "bottom-start",
|
|
1954
2070
|
transitionProps: { duration: 0 }
|
|
1955
2071
|
}, () => [h(Popover.Target, null, () => h(InputBase, {
|
|
@@ -1959,11 +2075,11 @@ var TimePicker = defineComponent({
|
|
|
1959
2075
|
disabled: props.disabled,
|
|
1960
2076
|
onClick: () => {
|
|
1961
2077
|
focus("hours");
|
|
1962
|
-
if (props.withDropdown) opened.value = true;
|
|
2078
|
+
if (props.type !== "duration" && props.withDropdown) opened.value = true;
|
|
1963
2079
|
},
|
|
1964
2080
|
onMousedown: (event) => event.preventDefault(),
|
|
1965
2081
|
onFocusin: () => {
|
|
1966
|
-
if (props.withDropdown) opened.value = true;
|
|
2082
|
+
if (props.type !== "duration" && props.withDropdown) opened.value = true;
|
|
1967
2083
|
},
|
|
1968
2084
|
onFocusout: () => {
|
|
1969
2085
|
if (props.withDropdown) opened.value = false;
|
|
@@ -1982,12 +2098,14 @@ var TimePicker = defineComponent({
|
|
|
1982
2098
|
ref: hoursRef,
|
|
1983
2099
|
class: Dates_module_default.timePickerField,
|
|
1984
2100
|
value: hours.value,
|
|
1985
|
-
min:
|
|
1986
|
-
max: props.
|
|
2101
|
+
min: effectiveFormat.value === "12h" ? 1 : 0,
|
|
2102
|
+
max: props.type === "duration" ? Infinity : effectiveFormat.value === "12h" ? 12 : 23,
|
|
1987
2103
|
step: props.hoursStep,
|
|
1988
2104
|
onChange: setHours,
|
|
1989
2105
|
onNextInput: () => focus("minutes"),
|
|
1990
|
-
allowTemporaryZero:
|
|
2106
|
+
allowTemporaryZero: effectiveFormat.value === "12h",
|
|
2107
|
+
disableAutoAdvance: props.type === "duration",
|
|
2108
|
+
onPaste: handlePaste,
|
|
1991
2109
|
readOnly: props.readOnly,
|
|
1992
2110
|
disabled: props.disabled,
|
|
1993
2111
|
placeholder: "--"
|
|
@@ -2022,7 +2140,7 @@ var TimePicker = defineComponent({
|
|
|
2022
2140
|
disabled: props.disabled,
|
|
2023
2141
|
placeholder: "--"
|
|
2024
2142
|
}) : null,
|
|
2025
|
-
|
|
2143
|
+
effectiveFormat.value === "12h" ? h(AmPmInput, {
|
|
2026
2144
|
ref: amPmRef,
|
|
2027
2145
|
value: amPm.value,
|
|
2028
2146
|
labels: props.amPmLabels,
|
|
@@ -2042,8 +2160,8 @@ var TimePicker = defineComponent({
|
|
|
2042
2160
|
onClick: () => handlePresetSelect(preset.value)
|
|
2043
2161
|
}, () => preset.label))) : h("div", { class: Dates_module_default.timePickerControlsListGroup }, [
|
|
2044
2162
|
h(TimeControlsList, {
|
|
2045
|
-
min:
|
|
2046
|
-
max:
|
|
2163
|
+
min: effectiveFormat.value === "12h" ? 1 : 0,
|
|
2164
|
+
max: effectiveFormat.value === "12h" ? 12 : 23,
|
|
2047
2165
|
step: props.hoursStep,
|
|
2048
2166
|
value: hours.value,
|
|
2049
2167
|
onSelect: setHours
|