@varlet/ui 3.18.1 → 3.19.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.
Files changed (91) hide show
  1. package/es/action-sheet/ActionItem.mjs +28 -8
  2. package/es/action-sheet/actionSheet.css +1 -1
  3. package/es/action-sheet/index.mjs +4 -2
  4. package/es/alert/alert.css +1 -1
  5. package/es/badge/Badge.mjs +20 -10
  6. package/es/badge/badge.css +1 -1
  7. package/es/bottom-navigation-item/BottomNavigationItem.mjs +34 -20
  8. package/es/bottom-navigation-item/bottomNavigationItem.css +1 -1
  9. package/es/checkbox/Checkbox.mjs +95 -46
  10. package/es/checkbox/checkbox.css +1 -1
  11. package/es/chip/Chip.mjs +11 -4
  12. package/es/chip/chip.css +1 -1
  13. package/es/chip/props.mjs +4 -0
  14. package/es/date-input/DateInput.mjs +865 -0
  15. package/es/date-input/DateInputSfc.css +0 -0
  16. package/es/date-input/TimeSelect.mjs +201 -0
  17. package/es/date-input/date-input.css +1 -0
  18. package/es/date-input/index.mjs +12 -0
  19. package/es/date-input/props.mjs +77 -0
  20. package/es/date-input/style/index.mjs +14 -0
  21. package/es/date-picker/DatePicker.mjs +522 -451
  22. package/es/date-picker/DayPickerPanel.mjs +318 -0
  23. package/es/date-picker/MonthPickerPanel.mjs +187 -0
  24. package/es/date-picker/PanelHeader.mjs +332 -0
  25. package/es/date-picker/YearPickerPanel.mjs +199 -0
  26. package/es/date-picker/constants.mjs +31 -0
  27. package/es/date-picker/date-picker.css +1 -1
  28. package/es/date-picker/props.mjs +6 -9
  29. package/es/date-picker/style/index.mjs +0 -1
  30. package/es/date-picker/types.mjs +0 -0
  31. package/es/field-decorator/fieldDecorator.css +1 -1
  32. package/es/icon/icon.css +1 -1
  33. package/es/index.bundle.mjs +7 -1
  34. package/es/index.mjs +6 -1
  35. package/es/input/props.mjs +1 -1
  36. package/es/locale/en-US.mjs +2 -0
  37. package/es/locale/fa-IR.mjs +2 -0
  38. package/es/locale/ja-JP.mjs +2 -0
  39. package/es/locale/zh-CN.mjs +2 -0
  40. package/es/locale/zh-TW.mjs +2 -0
  41. package/es/menu-select/MenuSelect.mjs +11 -2
  42. package/es/menu-select/menuSelect.css +1 -1
  43. package/es/radio/Radio.mjs +61 -22
  44. package/es/radio/radio.css +1 -1
  45. package/es/rail-navigation-item/RailNavigationItem.mjs +33 -19
  46. package/es/rail-navigation-item/railNavigationItem.css +1 -1
  47. package/es/rate/Rate.mjs +23 -12
  48. package/es/rate/rate.css +1 -1
  49. package/es/select/Select.mjs +10 -1
  50. package/es/select/select.css +1 -1
  51. package/es/slider/Slider.mjs +1 -1
  52. package/es/step/Step.mjs +50 -20
  53. package/es/step/step.css +1 -1
  54. package/es/style.mjs +1 -0
  55. package/es/switch/Switch.mjs +1 -1
  56. package/es/themes/dark/alert.mjs +2 -2
  57. package/es/themes/dark/dateInput.mjs +9 -0
  58. package/es/themes/dark/datePicker.mjs +23 -19
  59. package/es/themes/dark/index.mjs +3 -2
  60. package/es/themes/md3-dark/alert.mjs +2 -2
  61. package/es/themes/md3-dark/dateInput.mjs +9 -0
  62. package/es/themes/md3-dark/datePicker.mjs +18 -13
  63. package/es/themes/md3-dark/index.mjs +3 -2
  64. package/es/themes/md3-light/alert.mjs +2 -2
  65. package/es/themes/md3-light/dateInput.mjs +9 -0
  66. package/es/themes/md3-light/datePicker.mjs +18 -13
  67. package/es/themes/md3-light/index.mjs +3 -2
  68. package/es/utils/elements.mjs +7 -0
  69. package/es/utils/shared.mjs +15 -0
  70. package/es/varlet.css +1 -1
  71. package/es/varlet.esm.js +11926 -10653
  72. package/highlight/web-types.en-US.json +599 -73
  73. package/highlight/web-types.zh-CN.json +572 -67
  74. package/lib/varlet.cjs.js +5616 -4186
  75. package/lib/varlet.css +1 -1
  76. package/package.json +7 -7
  77. package/types/actionSheet.d.ts +1 -1
  78. package/types/badge.d.ts +1 -0
  79. package/types/chip.d.ts +3 -0
  80. package/types/dateInput.d.ts +96 -0
  81. package/types/datePicker.d.ts +4 -2
  82. package/types/index.d.ts +2 -0
  83. package/types/locale.d.ts +2 -0
  84. package/types/rate.d.ts +7 -0
  85. package/types/step.d.ts +3 -0
  86. package/types/styleVars.d.ts +14 -4
  87. package/umd/varlet.js +7 -7
  88. package/es/date-picker/src/day-picker-panel.mjs +0 -385
  89. package/es/date-picker/src/month-picker-panel.mjs +0 -300
  90. package/es/date-picker/src/panel-header.mjs +0 -142
  91. package/es/date-picker/src/year-picker-panel.mjs +0 -311
@@ -0,0 +1,865 @@
1
+ import { call, isArray, isDate, isEqual, isNumber, isTruthy, preventDefault } from "@varlet/shared";
2
+ import { computed, defineComponent, nextTick, ref, watch } from "vue";
3
+ import VarDatePicker from "../date-picker/index.mjs";
4
+ import VarFormDetails from "../form-details/index.mjs";
5
+ import { useForm } from "../form/provide.mjs";
6
+ import VarIcon from "../icon/index.mjs";
7
+ import VarInput from "../input/index.mjs";
8
+ import VarMenu from "../menu/index.mjs";
9
+ import { createNamespace, useValidation } from "../utils/components.mjs";
10
+ import { createDayjs } from "../utils/shared.mjs";
11
+ import {
12
+ props
13
+ } from "./props.mjs";
14
+ import TimeSelect from "./TimeSelect.mjs";
15
+ const DateInputDefaultFormats = {
16
+ Year: "YYYY",
17
+ Month: "YYYY-MM",
18
+ Date: "YYYY-MM-DD",
19
+ Datetime: "YYYY-MM-DD HH:mm:ss",
20
+ DatetimeMinute: "YYYY-MM-DD HH:mm"
21
+ };
22
+ const dayjs = createDayjs();
23
+ const { name, n, classes } = createNamespace("date-input");
24
+ import { renderSlot as _renderSlot, resolveComponent as _resolveComponent, normalizeClass as _normalizeClass, createVNode as _createVNode, withModifiers as _withModifiers, createElementVNode as _createElementVNode, withCtx as _withCtx, createSlots as _createSlots, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue";
25
+ function __render__(_ctx, _cache) {
26
+ const _component_var_icon = _resolveComponent("var-icon");
27
+ const _component_var_input = _resolveComponent("var-input");
28
+ const _component_time_select = _resolveComponent("time-select");
29
+ const _component_var_date_picker = _resolveComponent("var-date-picker");
30
+ const _component_var_menu = _resolveComponent("var-menu");
31
+ const _component_var_form_details = _resolveComponent("var-form-details");
32
+ return _openBlock(), _createElementBlock(
33
+ "div",
34
+ {
35
+ class: _normalizeClass(_ctx.classes(_ctx.n(), _ctx.n("$--box")))
36
+ },
37
+ [
38
+ _createVNode(_component_var_menu, {
39
+ show: _ctx.showMenu,
40
+ "onUpdate:show": _cache[5] || (_cache[5] = ($event) => _ctx.showMenu = $event),
41
+ "var-date-input-cover": "",
42
+ trigger: "manual",
43
+ placement: "bottom-start",
44
+ disabled: _ctx.disabled || _ctx.readonly || _ctx.formDisabled || _ctx.formReadonly,
45
+ "popover-class": _ctx.menuPopoverClass
46
+ }, {
47
+ menu: _withCtx(() => [
48
+ _createElementVNode(
49
+ "div",
50
+ {
51
+ onPointerdown: _cache[4] || (_cache[4] = _withModifiers(() => {
52
+ }, ["prevent"]))
53
+ },
54
+ [
55
+ _createVNode(_component_var_date_picker, {
56
+ ref: "picker",
57
+ class: _normalizeClass(_ctx.n("picker")),
58
+ "model-value": _ctx.pickerValue,
59
+ type: _ctx.pickerType,
60
+ multiple: _ctx.isMultiple,
61
+ range: _ctx.range,
62
+ "allowed-dates": _ctx.allowedDates,
63
+ min: _ctx.pickerMin,
64
+ max: _ctx.pickerMax,
65
+ "first-day-of-week": _ctx.firstDayOfWeek,
66
+ "show-title": false,
67
+ elevation: false,
68
+ onChange: _ctx.handlePickerChange
69
+ }, _createSlots({
70
+ _: 2
71
+ /* DYNAMIC */
72
+ }, [
73
+ _ctx.isDatetime ? {
74
+ name: "actions",
75
+ fn: _withCtx(() => [
76
+ _createElementVNode(
77
+ "div",
78
+ {
79
+ class: _normalizeClass(_ctx.n("datetime"))
80
+ },
81
+ [
82
+ _ctx.range ? (_openBlock(), _createElementBlock(
83
+ "div",
84
+ {
85
+ key: 0,
86
+ class: _normalizeClass(_ctx.classes(_ctx.n("datetime-row"), _ctx.n("datetime-row--range")))
87
+ },
88
+ [
89
+ _createVNode(_component_time_select, {
90
+ hour: _ctx.rangeTimes[0].hour,
91
+ minute: _ctx.rangeTimes[0].minute,
92
+ second: _ctx.rangeTimes[0].second,
93
+ "use-seconds": _ctx.useSeconds,
94
+ readonly: _ctx.readonly || _ctx.formReadonly,
95
+ disabled: _ctx.disabled || _ctx.formDisabled || _ctx.isRangeTimeSelectDisabled,
96
+ "is-hour-allowed": _ctx.startAllowFns.isHourAllowed,
97
+ "is-minute-allowed": _ctx.startAllowFns.isMinuteAllowed,
98
+ "is-second-allowed": _ctx.startAllowFns.isSecondAllowed,
99
+ onChange: _cache[2] || (_cache[2] = (time, unit) => _ctx.handleRangeTimeChange(0, time, unit))
100
+ }, null, 8, ["hour", "minute", "second", "use-seconds", "readonly", "disabled", "is-hour-allowed", "is-minute-allowed", "is-second-allowed"]),
101
+ _createVNode(_component_var_icon, {
102
+ class: _normalizeClass(_ctx.n("datetime-arrow")),
103
+ name: "arrow-right"
104
+ }, null, 8, ["class"]),
105
+ _createVNode(_component_time_select, {
106
+ hour: _ctx.rangeTimes[1].hour,
107
+ minute: _ctx.rangeTimes[1].minute,
108
+ second: _ctx.rangeTimes[1].second,
109
+ "use-seconds": _ctx.useSeconds,
110
+ readonly: _ctx.readonly || _ctx.formReadonly,
111
+ disabled: _ctx.disabled || _ctx.formDisabled || _ctx.isRangeTimeSelectDisabled,
112
+ "is-hour-allowed": _ctx.endAllowFns.isHourAllowed,
113
+ "is-minute-allowed": _ctx.endAllowFns.isMinuteAllowed,
114
+ "is-second-allowed": _ctx.endAllowFns.isSecondAllowed,
115
+ onChange: _cache[3] || (_cache[3] = (time, unit) => _ctx.handleRangeTimeChange(1, time, unit))
116
+ }, null, 8, ["hour", "minute", "second", "use-seconds", "readonly", "disabled", "is-hour-allowed", "is-minute-allowed", "is-second-allowed"])
117
+ ],
118
+ 2
119
+ /* CLASS */
120
+ )) : (_openBlock(), _createElementBlock(
121
+ "div",
122
+ {
123
+ key: 1,
124
+ class: _normalizeClass(_ctx.n("datetime-row"))
125
+ },
126
+ [
127
+ _createVNode(_component_time_select, {
128
+ hour: _ctx.singleTime.hour,
129
+ minute: _ctx.singleTime.minute,
130
+ second: _ctx.singleTime.second,
131
+ "use-seconds": _ctx.useSeconds,
132
+ readonly: _ctx.readonly || _ctx.formReadonly,
133
+ disabled: _ctx.disabled || _ctx.formDisabled,
134
+ "is-hour-allowed": _ctx.singleAllowFns.isHourAllowed,
135
+ "is-minute-allowed": _ctx.singleAllowFns.isMinuteAllowed,
136
+ "is-second-allowed": _ctx.singleAllowFns.isSecondAllowed,
137
+ onChange: _ctx.handleTimeChange
138
+ }, null, 8, ["hour", "minute", "second", "use-seconds", "readonly", "disabled", "is-hour-allowed", "is-minute-allowed", "is-second-allowed", "onChange"])
139
+ ],
140
+ 2
141
+ /* CLASS */
142
+ ))
143
+ ],
144
+ 2
145
+ /* CLASS */
146
+ )
147
+ ]),
148
+ key: "0"
149
+ } : void 0
150
+ ]), 1032, ["class", "model-value", "type", "multiple", "range", "allowed-dates", "min", "max", "first-day-of-week", "onChange"])
151
+ ],
152
+ 32
153
+ /* NEED_HYDRATION */
154
+ )
155
+ ]),
156
+ default: _withCtx(() => [
157
+ _createVNode(_component_var_input, {
158
+ ref: "inputEl",
159
+ "model-value": _ctx.displayValue,
160
+ size: _ctx.size,
161
+ variant: _ctx.variant,
162
+ placeholder: _ctx.placeholder,
163
+ line: _ctx.line,
164
+ hint: _ctx.hint,
165
+ "text-color": _ctx.textColor,
166
+ "focus-color": _ctx.focusColor,
167
+ "blur-color": _ctx.blurColor,
168
+ tabindex: _ctx.tabindex,
169
+ disabled: _ctx.disabled || _ctx.formDisabled,
170
+ readonly: _ctx.readonly || _ctx.formReadonly,
171
+ clearable: _ctx.clearable,
172
+ "is-force-focusing-effect": _ctx.isFocusing,
173
+ "is-force-error-effect": !!_ctx.errorMessage,
174
+ "is-show-form-details": false,
175
+ onFocus: _ctx.handleFocus,
176
+ onBlur: _ctx.handleBlur,
177
+ onClick: _ctx.handleClick,
178
+ onKeydown: _ctx.handleKeydown,
179
+ onClear: _ctx.handleClear,
180
+ onChange: _ctx.handleChange,
181
+ "onUpdate:modelValue": _ctx.handleInput
182
+ }, _createSlots({
183
+ "clear-icon": _withCtx(({ clear }) => [
184
+ _createElementVNode(
185
+ "span",
186
+ {
187
+ class: _normalizeClass(_ctx.n("clear-icon-container")),
188
+ onMousedown: _cache[0] || (_cache[0] = _withModifiers(() => {
189
+ }, ["stop"])),
190
+ onClick: _cache[1] || (_cache[1] = _withModifiers(() => {
191
+ }, ["stop"]))
192
+ },
193
+ [
194
+ _renderSlot(_ctx.$slots, "clear-icon", { clear }, () => [
195
+ _createVNode(_component_var_icon, {
196
+ class: _normalizeClass(_ctx.n("clear-icon")),
197
+ name: "close-circle",
198
+ onClick: clear
199
+ }, null, 8, ["class", "onClick"])
200
+ ])
201
+ ],
202
+ 34
203
+ /* CLASS, NEED_HYDRATION */
204
+ )
205
+ ]),
206
+ "append-icon": _withCtx(() => [
207
+ _renderSlot(_ctx.$slots, "append-icon", {}, () => [
208
+ _createElementVNode(
209
+ "span",
210
+ {
211
+ class: _normalizeClass(_ctx.n("calendar-icon-container"))
212
+ },
213
+ [
214
+ _createVNode(_component_var_icon, {
215
+ class: _normalizeClass(_ctx.n("calendar-icon")),
216
+ name: "calendar-month-outline"
217
+ }, null, 8, ["class"])
218
+ ],
219
+ 2
220
+ /* CLASS */
221
+ )
222
+ ])
223
+ ]),
224
+ _: 2
225
+ /* DYNAMIC */
226
+ }, [
227
+ _ctx.$slots["prepend-icon"] ? {
228
+ name: "prepend-icon",
229
+ fn: _withCtx(() => [
230
+ _renderSlot(_ctx.$slots, "prepend-icon")
231
+ ]),
232
+ key: "0"
233
+ } : void 0,
234
+ _ctx.$slots["extra-message"] ? {
235
+ name: "extra-message",
236
+ fn: _withCtx(() => [
237
+ _renderSlot(_ctx.$slots, "extra-message")
238
+ ]),
239
+ key: "1"
240
+ } : void 0
241
+ ]), 1032, ["model-value", "size", "variant", "placeholder", "line", "hint", "text-color", "focus-color", "blur-color", "tabindex", "disabled", "readonly", "clearable", "is-force-focusing-effect", "is-force-error-effect", "onFocus", "onBlur", "onClick", "onKeydown", "onClear", "onChange", "onUpdate:modelValue"])
242
+ ]),
243
+ _: 3
244
+ /* FORWARDED */
245
+ }, 8, ["show", "disabled", "popover-class"]),
246
+ _createVNode(_component_var_form_details, { "error-message": _ctx.errorMessage }, _createSlots({
247
+ _: 2
248
+ /* DYNAMIC */
249
+ }, [
250
+ _ctx.$slots["extra-message"] ? {
251
+ name: "extra-message",
252
+ fn: _withCtx(() => [
253
+ _renderSlot(_ctx.$slots, "extra-message")
254
+ ]),
255
+ key: "0"
256
+ } : void 0
257
+ ]), 1032, ["error-message"])
258
+ ],
259
+ 2
260
+ /* CLASS */
261
+ );
262
+ }
263
+ const __sfc__ = defineComponent({
264
+ name,
265
+ components: {
266
+ VarIcon,
267
+ VarInput,
268
+ VarMenu,
269
+ VarFormDetails,
270
+ VarDatePicker,
271
+ TimeSelect
272
+ },
273
+ props,
274
+ setup(props2) {
275
+ const inputEl = ref(null);
276
+ const picker = ref(null);
277
+ const displayValue = ref("");
278
+ const pickerValue = ref();
279
+ const showMenu = ref(false);
280
+ const isFocusing = ref(false);
281
+ const { bindForm, form } = useForm();
282
+ const { errorMessage, validateWithTrigger: vt, validate: v, resetValidation } = useValidation();
283
+ const formDisabled = computed(() => {
284
+ var _a;
285
+ return (_a = form == null ? void 0 : form.disabled.value) != null ? _a : false;
286
+ });
287
+ const formReadonly = computed(() => {
288
+ var _a;
289
+ return (_a = form == null ? void 0 : form.readonly.value) != null ? _a : false;
290
+ });
291
+ const isDisabled = computed(() => props2.disabled || formDisabled.value);
292
+ const isReadonly = computed(() => props2.readonly || formReadonly.value);
293
+ const isDatetime = computed(() => props2.type === "datetime");
294
+ const isMultiple = computed(() => props2.multiple && !isDatetime.value);
295
+ const isMultipleOrRange = computed(() => isMultiple.value || props2.range);
296
+ const pickerType = computed(() => isDatetime.value ? "date" : props2.type);
297
+ const pickerMin = computed(() => getPickerBound(props2.min));
298
+ const pickerMax = computed(() => getPickerBound(props2.max));
299
+ const rangeSelecting = computed(() => {
300
+ var _a;
301
+ return Boolean((_a = picker.value) == null ? void 0 : _a.rangeSelecting);
302
+ });
303
+ const isRangeTimeSelectDisabled = computed(
304
+ () => isDatetime.value && props2.range && (rangeSelecting.value || getDayjsObjectsByModelValue().length < 2)
305
+ );
306
+ const minDayjsObject = computed(() => props2.min ? dayjs(props2.min) : void 0);
307
+ const maxDayjsObject = computed(() => props2.max ? dayjs(props2.max) : void 0);
308
+ const singleTime = computed(() => getTimeParts(getDayjsObjectsByModelValue()[0]));
309
+ const rangeTimes = computed(() => {
310
+ const dayjsObjects = getDayjsObjectsByModelValue();
311
+ return [getTimeParts(dayjsObjects[0]), getTimeParts(dayjsObjects[1])];
312
+ });
313
+ const menuPopoverClass = computed(() => {
314
+ const marginClass = props2.variant === "standard" ? n("--standard-menu-margin") : props2.variant === "filled" ? n("--filled-menu-margin") : "";
315
+ return [n("--menu"), marginClass].filter(isTruthy).join(" ");
316
+ });
317
+ const displayValues = computed(() => {
318
+ const separator = props2.range ? props2.rangeSeparator : props2.separator;
319
+ return displayValue.value.split(separator).map((item) => item.trim()).filter(isTruthy);
320
+ });
321
+ const dateInputProvider = {
322
+ reset,
323
+ validate,
324
+ resetValidation
325
+ };
326
+ watch(
327
+ () => [
328
+ props2.modelValue,
329
+ props2.format,
330
+ props2.valueFormat,
331
+ props2.type,
332
+ props2.useSeconds,
333
+ props2.multiple,
334
+ props2.range,
335
+ props2.separator,
336
+ props2.rangeSeparator
337
+ ],
338
+ () => updateStatesByModelValue(),
339
+ { immediate: true }
340
+ );
341
+ call(bindForm, dateInputProvider);
342
+ function getDefaultFormat(type = props2.type) {
343
+ if (type === "year") {
344
+ return DateInputDefaultFormats.Year;
345
+ }
346
+ if (type === "month") {
347
+ return DateInputDefaultFormats.Month;
348
+ }
349
+ if (type === "datetime") {
350
+ return props2.useSeconds ? DateInputDefaultFormats.Datetime : DateInputDefaultFormats.DatetimeMinute;
351
+ }
352
+ return DateInputDefaultFormats.Date;
353
+ }
354
+ function getPickerFormat() {
355
+ return isDatetime.value ? DateInputDefaultFormats.Date : getDefaultFormat();
356
+ }
357
+ function getDisplayFormat() {
358
+ return props2.format || getDefaultFormat();
359
+ }
360
+ function getPickerBound(value) {
361
+ if (!value || !isDatetime.value) {
362
+ return value;
363
+ }
364
+ return dayjs(value).format(DateInputDefaultFormats.Date);
365
+ }
366
+ function getTimeParts(dayjsObject) {
367
+ var _a, _b, _c;
368
+ return {
369
+ hour: (_a = dayjsObject == null ? void 0 : dayjsObject.hour()) != null ? _a : 0,
370
+ minute: (_b = dayjsObject == null ? void 0 : dayjsObject.minute()) != null ? _b : 0,
371
+ second: (_c = dayjsObject == null ? void 0 : dayjsObject.second()) != null ? _c : 0
372
+ };
373
+ }
374
+ function clampDatetime(dayjsObject) {
375
+ const min = minDayjsObject.value;
376
+ const max = maxDayjsObject.value;
377
+ if (min && dayjsObject.isBefore(min)) {
378
+ return min;
379
+ }
380
+ if (max && dayjsObject.isAfter(max)) {
381
+ return max;
382
+ }
383
+ return dayjsObject;
384
+ }
385
+ function createTimeSelectValidators(getDayjsObjectByModelValue, getTimeParts2, position) {
386
+ function getAllowedTimeValidators() {
387
+ var _a, _b;
388
+ const date = ((_a = getDayjsObjectByModelValue()) != null ? _a : dayjs()).format(DateInputDefaultFormats.Date);
389
+ return (_b = props2.allowedTimes) == null ? void 0 : _b.call(props2, date, position);
390
+ }
391
+ function isAllowed(unit, value) {
392
+ var _a;
393
+ const time = getTimeParts2();
394
+ const timeOptionDayjsObject = ((_a = getDayjsObjectByModelValue()) != null ? _a : dayjs()).hour(unit === "hour" ? value : time.hour).minute(unit === "minute" ? value : time.minute).second(unit === "second" ? value : time.second);
395
+ const min = minDayjsObject.value;
396
+ const max = maxDayjsObject.value;
397
+ if (min && timeOptionDayjsObject.endOf(unit).isBefore(min)) {
398
+ return false;
399
+ }
400
+ if (max && timeOptionDayjsObject.startOf(unit).isAfter(max)) {
401
+ return false;
402
+ }
403
+ const validators = getAllowedTimeValidators();
404
+ if (unit === "hour") {
405
+ return (validators == null ? void 0 : validators.hours) ? validators.hours(value) : true;
406
+ }
407
+ if (unit === "minute") {
408
+ return (validators == null ? void 0 : validators.minutes) ? validators.minutes(value, time.hour) : true;
409
+ }
410
+ return (validators == null ? void 0 : validators.seconds) ? validators.seconds(value, time.minute, time.hour) : true;
411
+ }
412
+ return {
413
+ isHourAllowed: (hour) => isAllowed("hour", hour),
414
+ isMinuteAllowed: (minute) => isAllowed("minute", minute),
415
+ isSecondAllowed: (second) => isAllowed("second", second)
416
+ };
417
+ }
418
+ const singleAllowFns = createTimeSelectValidators(
419
+ () => getDayjsObjectsByModelValue()[0],
420
+ () => singleTime.value
421
+ );
422
+ const startAllowFns = createTimeSelectValidators(
423
+ () => getDayjsObjectsByModelValue()[0],
424
+ () => rangeTimes.value[0],
425
+ "start"
426
+ );
427
+ const endAllowFns = createTimeSelectValidators(
428
+ () => getDayjsObjectsByModelValue()[1],
429
+ () => rangeTimes.value[1],
430
+ "end"
431
+ );
432
+ function applyTime(base, time) {
433
+ return clampDatetime(base.hour(time.hour).minute(time.minute).second(time.second).millisecond(0));
434
+ }
435
+ function getOrderedValues(preferred, count, fixed) {
436
+ if (fixed) {
437
+ return [preferred];
438
+ }
439
+ return [preferred, ...Array.from({ length: count }, (_, value) => value).filter((value) => value !== preferred)];
440
+ }
441
+ function isTimeCandidateAllowed(candidateDayjsObject, validators) {
442
+ const min = minDayjsObject.value;
443
+ const max = maxDayjsObject.value;
444
+ const hour = candidateDayjsObject.hour();
445
+ const minute = candidateDayjsObject.minute();
446
+ const second = candidateDayjsObject.second();
447
+ return (!min || !candidateDayjsObject.isBefore(min)) && (!max || !candidateDayjsObject.isAfter(max)) && (!validators.hours || validators.hours(hour)) && (!validators.minutes || validators.minutes(minute, hour)) && (!props2.useSeconds || !validators.seconds || validators.seconds(second, minute, hour)) && (!props2.allowedDates || props2.allowedDates(candidateDayjsObject.format(getPickerFormat())));
448
+ }
449
+ function resolveSelectableDateTime(base, time, position, changedUnit) {
450
+ var _a, _b;
451
+ const date = base.format(DateInputDefaultFormats.Date);
452
+ const validators = (_b = (_a = props2.allowedTimes) == null ? void 0 : _a.call(props2, date, position)) != null ? _b : {};
453
+ const hours = getOrderedValues(
454
+ time.hour,
455
+ 24,
456
+ changedUnit === "hour" || changedUnit === "minute" || changedUnit === "second"
457
+ );
458
+ for (const hour of hours) {
459
+ if (validators.hours && !validators.hours(hour)) {
460
+ continue;
461
+ }
462
+ const minutes = getOrderedValues(time.minute, 60, changedUnit === "minute" || changedUnit === "second");
463
+ for (const minute of minutes) {
464
+ if (validators.minutes && !validators.minutes(minute, hour)) {
465
+ continue;
466
+ }
467
+ const seconds = props2.useSeconds ? getOrderedValues(time.second, 60, changedUnit === "second") : [0];
468
+ for (const second of seconds) {
469
+ const candidateDayjsObject = base.hour(hour).minute(minute).second(second).millisecond(0);
470
+ if (isTimeCandidateAllowed(candidateDayjsObject, validators)) {
471
+ return candidateDayjsObject;
472
+ }
473
+ }
474
+ }
475
+ }
476
+ }
477
+ function normalizeDateTimes(dayjsObjects) {
478
+ return props2.range ? [...dayjsObjects].sort((a, b) => a.valueOf() - b.valueOf()) : dayjsObjects;
479
+ }
480
+ function commitDateTimes(dayjsObjects) {
481
+ const nextDayjsObjects = normalizeDateTimes(dayjsObjects);
482
+ if (props2.range) {
483
+ if (!isDayjsObjectSelectable(nextDayjsObjects[0], "start") || !isDayjsObjectSelectable(nextDayjsObjects[1], "end")) {
484
+ return false;
485
+ }
486
+ pickerValue.value = nextDayjsObjects.map((dayjsObject2) => dayjsObject2.format(getPickerFormat()));
487
+ displayValue.value = nextDayjsObjects.map((dayjsObject2) => dayjsObject2.format(getDisplayFormat())).join(props2.rangeSeparator);
488
+ updateModelValue(nextDayjsObjects.map(dayjsObjectToModelValue));
489
+ return true;
490
+ }
491
+ const [dayjsObject] = nextDayjsObjects;
492
+ if (!isDayjsObjectSelectable(dayjsObject)) {
493
+ return false;
494
+ }
495
+ pickerValue.value = dayjsObject.format(getPickerFormat());
496
+ displayValue.value = dayjsObject.format(getDisplayFormat());
497
+ updateModelValue(dayjsObjectToModelValue(dayjsObject));
498
+ return true;
499
+ }
500
+ function handleTimeChange(time, changedUnit) {
501
+ if (isDisabled.value || isReadonly.value) {
502
+ return;
503
+ }
504
+ const [dayjsObject] = getDayjsObjectsByModelValue();
505
+ const base = dayjsObject != null ? dayjsObject : dayjs();
506
+ const resolved = changedUnit ? resolveSelectableDateTime(base, time, void 0, changedUnit) : applyTime(base, time);
507
+ if (resolved) {
508
+ commitDateTimes([resolved]);
509
+ }
510
+ }
511
+ function handleRangeTimeChange(index, time, changedUnit) {
512
+ if (isDisabled.value || isReadonly.value) {
513
+ return;
514
+ }
515
+ const dayjsObjects = getDayjsObjectsByModelValue();
516
+ if (dayjsObjects.length < 2) {
517
+ return;
518
+ }
519
+ const next = [...dayjsObjects];
520
+ const position = index === 0 ? "start" : "end";
521
+ const resolved = changedUnit ? resolveSelectableDateTime(dayjsObjects[index], time, position, changedUnit) : applyTime(dayjsObjects[index], time);
522
+ if (resolved) {
523
+ next[index] = resolved;
524
+ commitDateTimes(next);
525
+ }
526
+ }
527
+ function stringToDayjsObject(value, format) {
528
+ const dayjsObject = dayjs(value, format, true);
529
+ return dayjsObject.isValid() ? dayjsObject : void 0;
530
+ }
531
+ function isAllowedTime(dayjsObject, position) {
532
+ var _a;
533
+ if (!isDatetime.value || !props2.allowedTimes) {
534
+ return true;
535
+ }
536
+ const validators = (_a = props2.allowedTimes(dayjsObject.format(DateInputDefaultFormats.Date), position)) != null ? _a : {};
537
+ const hour = dayjsObject.hour();
538
+ const minute = dayjsObject.minute();
539
+ const second = dayjsObject.second();
540
+ return (!validators.hours || validators.hours(hour)) && (!validators.minutes || validators.minutes(minute, hour)) && (!props2.useSeconds || !validators.seconds || validators.seconds(second, minute, hour));
541
+ }
542
+ function isDayjsObjectSelectable(dayjsObject, position) {
543
+ const min = minDayjsObject.value;
544
+ const max = maxDayjsObject.value;
545
+ const unit = props2.type === "year" ? "year" : props2.type === "month" ? "month" : props2.type === "date" ? "day" : void 0;
546
+ if (min && (unit ? dayjsObject.isBefore(min, unit) : dayjsObject.isBefore(min))) {
547
+ return false;
548
+ }
549
+ if (max && (unit ? dayjsObject.isAfter(max, unit) : dayjsObject.isAfter(max))) {
550
+ return false;
551
+ }
552
+ if (props2.allowedDates && !props2.allowedDates(dayjsObject.format(getPickerFormat()))) {
553
+ return false;
554
+ }
555
+ if (!isAllowedTime(dayjsObject, position)) {
556
+ return false;
557
+ }
558
+ return true;
559
+ }
560
+ function modelValueToDayjsObject(value) {
561
+ var _a;
562
+ if (value == null || value === "") {
563
+ return;
564
+ }
565
+ if (isDate(value) || isNumber(value)) {
566
+ const dayjsObject = dayjs(value);
567
+ return dayjsObject.isValid() ? dayjsObject : void 0;
568
+ }
569
+ return stringToDayjsObject(value, (_a = props2.valueFormat) != null ? _a : getDisplayFormat());
570
+ }
571
+ function dayjsObjectToModelValue(dayjsObject) {
572
+ if (props2.valueFormat === "timestamp") {
573
+ return dayjsObject.valueOf();
574
+ }
575
+ if (props2.valueFormat === "date") {
576
+ return dayjsObject.toDate();
577
+ }
578
+ if (!props2.valueFormat) {
579
+ return dayjsObject.format(getDisplayFormat());
580
+ }
581
+ return dayjsObject.format(props2.valueFormat);
582
+ }
583
+ function getDayjsObjectsByModelValue() {
584
+ if (isMultipleOrRange.value) {
585
+ return (isArray(props2.modelValue) ? props2.modelValue : []).map(modelValueToDayjsObject).filter(isTruthy);
586
+ }
587
+ const dayjsObject = isArray(props2.modelValue) ? void 0 : modelValueToDayjsObject(props2.modelValue);
588
+ return dayjsObject ? [dayjsObject] : [];
589
+ }
590
+ function updateDisplayValueByDayjsObjects(dayjsObjects) {
591
+ displayValue.value = dayjsObjects.map((dayjsObject) => dayjsObject.format(getDisplayFormat())).join(props2.range ? props2.rangeSeparator : props2.separator);
592
+ }
593
+ function updateStatesByModelValue() {
594
+ const dayjsObjects = getDayjsObjectsByModelValue();
595
+ if (isMultipleOrRange.value) {
596
+ pickerValue.value = dayjsObjects.map((dayjsObject) => dayjsObject.format(getPickerFormat()));
597
+ } else {
598
+ const [dayjsObject] = dayjsObjects;
599
+ pickerValue.value = dayjsObject ? dayjsObject.format(getPickerFormat()) : void 0;
600
+ }
601
+ if (!isFocusing.value) {
602
+ updateDisplayValueByDayjsObjects(dayjsObjects);
603
+ }
604
+ }
605
+ function updateModelValue(value) {
606
+ if (isEqual(value, props2.modelValue)) {
607
+ return;
608
+ }
609
+ call(props2["onUpdate:modelValue"], value);
610
+ call(props2.onChange, value);
611
+ validateWithTrigger("onChange");
612
+ }
613
+ function validateWithTrigger(trigger) {
614
+ nextTick(() => {
615
+ const { validateTrigger, rules, modelValue } = props2;
616
+ vt(validateTrigger, trigger, rules, modelValue);
617
+ });
618
+ }
619
+ function handleFocus(e) {
620
+ isFocusing.value = true;
621
+ call(props2.onFocus, e);
622
+ validateWithTrigger("onFocus");
623
+ }
624
+ function handleBlur(e) {
625
+ isFocusing.value = false;
626
+ showMenu.value = false;
627
+ call(props2.onBlur, e);
628
+ validateWithTrigger("onBlur");
629
+ }
630
+ function handleClick() {
631
+ if (isDisabled.value || isReadonly.value) {
632
+ return;
633
+ }
634
+ showMenu.value = true;
635
+ nextTick(() => {
636
+ var _a;
637
+ return (_a = picker.value) == null ? void 0 : _a.syncModelValue();
638
+ });
639
+ validateWithTrigger("onClick");
640
+ }
641
+ function handleKeydown(e) {
642
+ if (isDisabled.value || isReadonly.value || e.key !== "Enter") {
643
+ return;
644
+ }
645
+ preventDefault(e);
646
+ showMenu.value = true;
647
+ nextTick(() => {
648
+ var _a;
649
+ return (_a = picker.value) == null ? void 0 : _a.syncModelValue();
650
+ });
651
+ }
652
+ function updateSingleStatesByDisplayValue(value) {
653
+ const dayjsObject = stringToDayjsObject(value, getDisplayFormat());
654
+ if (!dayjsObject || !isDayjsObjectSelectable(dayjsObject)) {
655
+ return;
656
+ }
657
+ pickerValue.value = dayjsObject.format(getPickerFormat());
658
+ updateModelValue(dayjsObjectToModelValue(dayjsObject));
659
+ }
660
+ function updateMultipleOrRangeStatesByDisplayValue() {
661
+ const isInvalidDisplayValueCount = props2.range ? displayValues.value.length !== 2 : !displayValues.value.length;
662
+ if (isInvalidDisplayValueCount) {
663
+ return;
664
+ }
665
+ const dayjsObjects = displayValues.value.map((item) => stringToDayjsObject(item, getDisplayFormat()));
666
+ if (dayjsObjects.some((dayjsObject) => !dayjsObject)) {
667
+ return;
668
+ }
669
+ const validDayjsObjects = dayjsObjects.filter(isTruthy);
670
+ if (props2.range && validDayjsObjects[0].isAfter(validDayjsObjects[1])) {
671
+ return;
672
+ }
673
+ if (validDayjsObjects.some((dayjsObject, index) => {
674
+ const position = props2.range ? index === 0 ? "start" : "end" : void 0;
675
+ return !isDayjsObjectSelectable(dayjsObject, position);
676
+ })) {
677
+ return;
678
+ }
679
+ const modelValue = validDayjsObjects.map(dayjsObjectToModelValue);
680
+ pickerValue.value = validDayjsObjects.map((dayjsObject) => dayjsObject.format(getPickerFormat()));
681
+ updateModelValue(modelValue);
682
+ }
683
+ function handleInput(value) {
684
+ if (isDisabled.value || isReadonly.value) {
685
+ return;
686
+ }
687
+ if (value === displayValue.value) {
688
+ return;
689
+ }
690
+ displayValue.value = value;
691
+ if (value === "") {
692
+ clearValue();
693
+ updateModelValue(getEmptyModelValue());
694
+ validateWithTrigger("onInput");
695
+ return;
696
+ }
697
+ if (isMultipleOrRange.value) {
698
+ updateMultipleOrRangeStatesByDisplayValue();
699
+ } else {
700
+ updateSingleStatesByDisplayValue(value);
701
+ }
702
+ validateWithTrigger("onInput");
703
+ }
704
+ function handleChange() {
705
+ if (isDisabled.value || isReadonly.value) {
706
+ return;
707
+ }
708
+ updateDisplayValueByDayjsObjects(getDayjsObjectsByModelValue());
709
+ }
710
+ function handleDatetimeRangePickerChange(dayjsObjects) {
711
+ if (dayjsObjects.length < 2) {
712
+ return;
713
+ }
714
+ const times = rangeTimes.value;
715
+ const resolved = dayjsObjects.map(
716
+ (dayjsObject, index) => {
717
+ var _a;
718
+ return resolveSelectableDateTime(dayjsObject, (_a = times[index]) != null ? _a : getTimeParts(), index === 0 ? "start" : "end");
719
+ }
720
+ );
721
+ if (resolved.every(isTruthy)) {
722
+ if (!commitDateTimes(resolved.filter(isTruthy))) {
723
+ updateStatesByModelValue();
724
+ }
725
+ } else {
726
+ updateStatesByModelValue();
727
+ }
728
+ }
729
+ function handlePickerArrayChange(value) {
730
+ const dayjsObjects = value.map((item) => dayjs(item, getPickerFormat(), true)).filter((dayjsObject) => dayjsObject.isValid());
731
+ if (isDatetime.value && props2.range) {
732
+ handleDatetimeRangePickerChange(dayjsObjects);
733
+ return;
734
+ }
735
+ const modelValue = dayjsObjects.map(dayjsObjectToModelValue);
736
+ displayValue.value = dayjsObjects.map((dayjsObject) => dayjsObject.format(getDisplayFormat())).join(props2.range ? props2.rangeSeparator : props2.separator);
737
+ updateModelValue(modelValue);
738
+ }
739
+ function handleDatetimePickerChange(dayjsObject) {
740
+ const resolved = resolveSelectableDateTime(dayjsObject, singleTime.value);
741
+ if (resolved) {
742
+ if (!commitDateTimes([resolved])) {
743
+ updateStatesByModelValue();
744
+ }
745
+ } else {
746
+ updateStatesByModelValue();
747
+ }
748
+ }
749
+ function handlePickerSingleChange(value) {
750
+ const dayjsObject = dayjs(value, getPickerFormat(), true);
751
+ if (!dayjsObject.isValid()) {
752
+ return;
753
+ }
754
+ if (isDatetime.value) {
755
+ handleDatetimePickerChange(dayjsObject);
756
+ return;
757
+ }
758
+ displayValue.value = dayjsObject.format(getDisplayFormat());
759
+ updateModelValue(dayjsObjectToModelValue(dayjsObject));
760
+ if (!isMultipleOrRange.value) {
761
+ showMenu.value = false;
762
+ }
763
+ }
764
+ function handlePickerChange(value) {
765
+ if (isDisabled.value || isReadonly.value) {
766
+ return;
767
+ }
768
+ pickerValue.value = value;
769
+ if (isArray(value)) {
770
+ handlePickerArrayChange(value);
771
+ return;
772
+ }
773
+ handlePickerSingleChange(value);
774
+ }
775
+ function getEmptyModelValue() {
776
+ return isMultipleOrRange.value ? [] : void 0;
777
+ }
778
+ function clearValue() {
779
+ displayValue.value = "";
780
+ pickerValue.value = isMultipleOrRange.value ? [] : void 0;
781
+ }
782
+ function handleClear() {
783
+ if (isDisabled.value || isReadonly.value || !props2.clearable) {
784
+ return;
785
+ }
786
+ clearValue();
787
+ showMenu.value = false;
788
+ const emptyModelValue = getEmptyModelValue();
789
+ call(props2["onUpdate:modelValue"], emptyModelValue);
790
+ call(props2.onClear, "");
791
+ call(props2.onChange, emptyModelValue);
792
+ validateWithTrigger("onChange");
793
+ validateWithTrigger("onClear");
794
+ }
795
+ function focus() {
796
+ var _a;
797
+ (_a = inputEl.value) == null ? void 0 : _a.focus();
798
+ }
799
+ function blur() {
800
+ var _a;
801
+ (_a = inputEl.value) == null ? void 0 : _a.blur();
802
+ }
803
+ function select() {
804
+ var _a;
805
+ (_a = inputEl.value) == null ? void 0 : _a.select();
806
+ }
807
+ function validate() {
808
+ return v(props2.rules, props2.modelValue);
809
+ }
810
+ function reset() {
811
+ const emptyModelValue = getEmptyModelValue();
812
+ clearValue();
813
+ showMenu.value = false;
814
+ !isEqual(props2.modelValue, emptyModelValue) && call(props2["onUpdate:modelValue"], emptyModelValue);
815
+ resetValidation();
816
+ }
817
+ return {
818
+ inputEl,
819
+ picker,
820
+ displayValue,
821
+ pickerValue,
822
+ showMenu,
823
+ isFocusing,
824
+ rangeSelecting,
825
+ isRangeTimeSelectDisabled,
826
+ formDisabled,
827
+ formReadonly,
828
+ errorMessage,
829
+ menuPopoverClass,
830
+ isDatetime,
831
+ isMultiple,
832
+ pickerType,
833
+ pickerMin,
834
+ pickerMax,
835
+ singleTime,
836
+ rangeTimes,
837
+ singleAllowFns,
838
+ startAllowFns,
839
+ endAllowFns,
840
+ n,
841
+ classes,
842
+ handleTimeChange,
843
+ handleRangeTimeChange,
844
+ handleFocus,
845
+ handleBlur,
846
+ handleClick,
847
+ handleKeydown,
848
+ handleInput,
849
+ handleChange,
850
+ handlePickerChange,
851
+ handleClear,
852
+ focus,
853
+ blur,
854
+ select,
855
+ validate,
856
+ resetValidation,
857
+ reset
858
+ };
859
+ }
860
+ });
861
+ __sfc__.render = __render__;
862
+ var stdin_default = __sfc__;
863
+ export {
864
+ stdin_default as default
865
+ };