@manik02/vue3-timepicker 0.1.0 → 0.1.2
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/README.md +26 -3
- package/dist/TimePicker/TimePicker.vue.d.ts +11 -0
- package/dist/TimePicker/types.d.ts +5 -0
- package/dist/vue-timepicker.css +1 -1
- package/dist/vue-timepicker.js +228 -210
- package/dist/vue-timepicker.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Vue3 Timepicker
|
|
2
2
|
|
|
3
3
|
A flexible, customisable timepicker component for Vue 3 with TypeScript support.
|
|
4
4
|
|
|
5
|
+
| Demo | Default | Dark |
|
|
6
|
+
|------|---------|------|
|
|
7
|
+
|  |  |  |
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
5
11
|
- Single and range time selection
|
|
6
12
|
- Multiple hour formats: 24-hour (`HH`/`H`), 12-hour (`hh`/`h` with AM/PM), 1-24 (`kk`/`k`)
|
|
7
13
|
- Optional seconds
|
|
@@ -41,6 +47,7 @@ const time = ref("14:30:00");
|
|
|
41
47
|
| `hourStep` | `number` | `1` | Step interval for the hour column. |
|
|
42
48
|
| `minuteStep` | `number` | `1` | Step interval for the minute column. |
|
|
43
49
|
| `secondStep` | `number` | `1` | Step interval for the second column. |
|
|
50
|
+
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Size preset that maps to CSS variables. |
|
|
44
51
|
|
|
45
52
|
## Format tokens
|
|
46
53
|
|
|
@@ -81,8 +88,10 @@ When `range` is `true`, `modelValue` must be a `[string, string]` array.
|
|
|
81
88
|
## 12-hour format
|
|
82
89
|
|
|
83
90
|
```vue
|
|
84
|
-
<TimePicker v-model="time" format="hh:mm A" />
|
|
85
|
-
|
|
91
|
+
<TimePicker v-model="time" format="hh:mm A" />
|
|
92
|
+
// AM/PM
|
|
93
|
+
<TimePicker v-model="time" format="hh:mm a" />
|
|
94
|
+
// am/pm
|
|
86
95
|
```
|
|
87
96
|
|
|
88
97
|
Press `a` or `p` while focused to toggle between AM and PM.
|
|
@@ -95,6 +104,20 @@ Press `a` or `p` while focused to toggle between AM and PM.
|
|
|
95
104
|
|
|
96
105
|
The dropdown columns will show values at the specified intervals (e.g. 00, 15, 30, 45 for a 15-minute step).
|
|
97
106
|
|
|
107
|
+
## Size presets
|
|
108
|
+
|
|
109
|
+
```vue
|
|
110
|
+
<template>
|
|
111
|
+
<div class="sizes">
|
|
112
|
+
<TimePicker v-model="time" format="HH:mm" size="sm" />
|
|
113
|
+
<TimePicker v-model="time" format="HH:mm" size="md" />
|
|
114
|
+
<TimePicker v-model="time" format="HH:mm" size="lg" />
|
|
115
|
+
</div>
|
|
116
|
+
</template>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Each preset sets a handful of CSS custom properties (`--vtp-font-size`, `--vtp-padding`, `--vtp-option-padding`, `--vtp-dropdown-radius`). You can still override any of them manually.
|
|
120
|
+
|
|
98
121
|
## CSS custom properties
|
|
99
122
|
|
|
100
123
|
Style the component by setting CSS custom properties on `.timepicker-shell` or any ancestor element.
|
|
@@ -25,6 +25,11 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
25
25
|
readonly default: "HH:mm";
|
|
26
26
|
readonly validator: (fmt: string) => boolean;
|
|
27
27
|
};
|
|
28
|
+
readonly size: {
|
|
29
|
+
readonly type: import('vue').PropType<"sm" | "md" | "lg">;
|
|
30
|
+
readonly default: "md";
|
|
31
|
+
readonly validator: (v: string) => v is "sm" | "md" | "lg";
|
|
32
|
+
};
|
|
28
33
|
}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
29
34
|
"update:modelValue": (v: string | [string, string] | null) => any;
|
|
30
35
|
open: () => any;
|
|
@@ -60,6 +65,11 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
60
65
|
readonly default: "HH:mm";
|
|
61
66
|
readonly validator: (fmt: string) => boolean;
|
|
62
67
|
};
|
|
68
|
+
readonly size: {
|
|
69
|
+
readonly type: import('vue').PropType<"sm" | "md" | "lg">;
|
|
70
|
+
readonly default: "md";
|
|
71
|
+
readonly validator: (v: string) => v is "sm" | "md" | "lg";
|
|
72
|
+
};
|
|
63
73
|
}>> & Readonly<{
|
|
64
74
|
"onUpdate:modelValue"?: ((v: string | [string, string] | null) => any) | undefined;
|
|
65
75
|
onOpen?: (() => any) | undefined;
|
|
@@ -75,6 +85,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
75
85
|
readonly minuteStep: number;
|
|
76
86
|
readonly secondStep: number;
|
|
77
87
|
readonly format: import('./types').TimeFormat;
|
|
88
|
+
readonly size: "sm" | "md" | "lg";
|
|
78
89
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {
|
|
79
90
|
secondInputRef: HTMLInputElement;
|
|
80
91
|
}, any>;
|
|
@@ -42,6 +42,11 @@ export declare const timePickerProps: {
|
|
|
42
42
|
readonly default: "HH:mm";
|
|
43
43
|
readonly validator: (fmt: string) => boolean;
|
|
44
44
|
};
|
|
45
|
+
readonly size: {
|
|
46
|
+
readonly type: PropType<"sm" | "md" | "lg">;
|
|
47
|
+
readonly default: "md";
|
|
48
|
+
readonly validator: (v: string) => v is "sm" | "md" | "lg";
|
|
49
|
+
};
|
|
45
50
|
};
|
|
46
51
|
export type TimePickerProps = ExtractPropTypes<typeof timePickerProps>;
|
|
47
52
|
export declare const TimeSelectionProps: {
|
package/dist/vue-timepicker.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.timepicker-shell,.timepicker-shell *,.timepicker-shell *:before,.timepicker-shell *:after{box-sizing:border-box}.timepicker-shell{position:relative;display:inline-block;font-family:var(--vtp-font-family, inherit);font-size:var(--vtp-font-size, inherit);color:var(--vtp-color, inherit)}.timepicker-shell__input{display:inline-flex;align-items:center;gap:.25rem;padding:var(--vtp-padding, .375rem .5rem);border-radius:var(--vtp-border-radius, 6px);background:var(--vtp-bg, #fff);border:1px solid var(--vtp-border, #ccc);color:var(--vtp-color, inherit);transition:border-color .15s,box-shadow .15s}.timepicker-shell__input:focus-within{border-color:var(--vtp-focus-border, #66afe9);box-shadow:var(--vtp-focus-ring, 0 0 0 2px rgba(102, 175, 233, .3))}.timepicker-shell__input--error{border-color:var(--vtp-error-border, #e74c3c);box-shadow:var(--vtp-error-ring, 0 0 0 2px rgba(231, 76, 60, .15))}.timepicker-shell__input .timepicker-separator{color:var(--vtp-separator-color, currentColor);opacity:.5;flex:0 0 auto;-webkit-user-select:none;user-select:none;line-height:1}.timepicker-field{flex:0 0 auto;width:auto;min-width:0;border:0;background:transparent;font:inherit;color:inherit;padding:0;margin:0;text-align:center}.timepicker-field:focus{outline:none}.timepicker-field::placeholder{color:var(--vtp-color, inherit);opacity:.4}.timepicker-dropdown{display:inline-block}.timepicker-dropdown__panel{min-width:48px;max-height:var(--vtp-dropdown-max-height, 220px);overflow-y:auto;overflow-x:hidden;padding:.25rem .125rem .25rem .25rem;border:1px solid var(--vtp-dropdown-border, var(--vtp-border, #ccc));border-radius:var(--vtp-dropdown-radius, .5rem);background:var(--vtp-dropdown-bg, var(--vtp-bg, #fff));box-shadow:var(--vtp-dropdown-shadow, 0 4px 12px rgba(0, 0, 0, .08));outline:none;scrollbar-width:thin;scrollbar-color:rgba(0,0,0,.25) transparent;scrollbar-gutter:stable}.timepicker-dropdown__panel::-webkit-scrollbar{width:5px}.timepicker-dropdown__panel::-webkit-scrollbar-thumb{background-color:#00000040;border-radius:3px}.timepicker-dropdown__panel::-webkit-scrollbar-track{background:transparent}.timepicker-option{padding:var(--vtp-option-padding, .3rem .5rem);border-radius:var(--vtp-option-radius, 4px);cursor:pointer;line-height:1.4;text-align:center;transition:background .1s}.timepicker-option--focused,.timepicker-option:hover{background:var(--vtp-option-hover-bg, rgba(0, 0, 0, .06))}.timepicker-option--active{background:var(--vtp-option-active-bg, #e8f0fe);color:var(--vtp-option-active-color, inherit);font-weight:var(--vtp-option-active-weight, 600)}.timepicker-option--disabled{opacity:.35;pointer-events:none}.vtp-cols{display:inline-flex;flex-wrap:nowrap;gap:var(--vtp-columns-gap, .25rem)}
|
|
1
|
+
.timepicker-shell,.timepicker-shell *,.timepicker-shell *:before,.timepicker-shell *:after{box-sizing:border-box}.timepicker-shell{position:relative;display:inline-block;font-family:var(--vtp-font-family, inherit);font-size:var(--vtp-font-size, inherit);color:var(--vtp-color, inherit)}.timepicker-shell[data-size=sm]{--vtp-font-size: .875rem;--vtp-padding: .25rem .375rem;--vtp-option-padding: .2rem .375rem;--vtp-dropdown-radius: .4rem}.timepicker-shell[data-size=md]{--vtp-font-size: 1rem;--vtp-padding: .375rem .5rem;--vtp-option-padding: .3rem .5rem;--vtp-dropdown-radius: .5rem}.timepicker-shell[data-size=lg]{--vtp-font-size: 1.125rem;--vtp-padding: .5rem .65rem;--vtp-option-padding: .4rem .65rem;--vtp-dropdown-radius: .6rem}.timepicker-shell__input{display:inline-flex;align-items:center;gap:.25rem;padding:var(--vtp-padding, .375rem .5rem);border-radius:var(--vtp-border-radius, 6px);background:var(--vtp-bg, #fff);border:1px solid var(--vtp-border, #ccc);color:var(--vtp-color, inherit);transition:border-color .15s,box-shadow .15s}.timepicker-shell__input:focus-within{border-color:var(--vtp-focus-border, #66afe9);box-shadow:var(--vtp-focus-ring, 0 0 0 2px rgba(102, 175, 233, .3))}.timepicker-shell__input--error{border-color:var(--vtp-error-border, #e74c3c);box-shadow:var(--vtp-error-ring, 0 0 0 2px rgba(231, 76, 60, .15))}.timepicker-shell__input .timepicker-separator{color:var(--vtp-separator-color, currentColor);opacity:.5;flex:0 0 auto;-webkit-user-select:none;user-select:none;line-height:1}.timepicker-field{flex:0 0 auto;width:auto;min-width:0;border:0;background:transparent;font:inherit;color:inherit;padding:0;margin:0;text-align:center}.timepicker-field:focus{outline:none}.timepicker-field::placeholder{color:var(--vtp-color, inherit);opacity:.4}.timepicker-dropdown{display:inline-block}.timepicker-dropdown__panel{min-width:48px;max-height:var(--vtp-dropdown-max-height, 220px);overflow-y:auto;overflow-x:hidden;padding:.25rem .125rem .25rem .25rem;border:1px solid var(--vtp-dropdown-border, var(--vtp-border, #ccc));border-radius:var(--vtp-dropdown-radius, .5rem);background:var(--vtp-dropdown-bg, var(--vtp-bg, #fff));box-shadow:var(--vtp-dropdown-shadow, 0 4px 12px rgba(0, 0, 0, .08));outline:none;scrollbar-width:thin;scrollbar-color:rgba(0,0,0,.25) transparent;scrollbar-gutter:stable}.timepicker-dropdown__panel::-webkit-scrollbar{width:5px}.timepicker-dropdown__panel::-webkit-scrollbar-thumb{background-color:#00000040;border-radius:3px}.timepicker-dropdown__panel::-webkit-scrollbar-track{background:transparent}.timepicker-option{padding:var(--vtp-option-padding, .3rem .5rem);border-radius:var(--vtp-option-radius, 4px);cursor:pointer;line-height:1.4;text-align:center;transition:background .1s}.timepicker-option--focused,.timepicker-option:hover{background:var(--vtp-option-hover-bg, rgba(0, 0, 0, .06))}.timepicker-option--active{background:var(--vtp-option-active-bg, #e8f0fe);color:var(--vtp-option-active-color, inherit);font-weight:var(--vtp-option-active-weight, 600)}.timepicker-option--disabled{opacity:.35;pointer-events:none}.vtp-cols{display:inline-flex;flex-wrap:nowrap;gap:var(--vtp-columns-gap, .25rem)}
|
package/dist/vue-timepicker.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
const
|
|
1
|
+
import { defineComponent as X, ref as w, onMounted as O, watch as E, createElementBlock as D, openBlock as b, createElementVNode as K, Fragment as ce, renderList as de, normalizeClass as q, toDisplayString as pe, nextTick as Y, computed as y, onBeforeUnmount as ee, createCommentVNode as B, createVNode as W, createBlock as J, unref as T, normalizeStyle as R } from "vue";
|
|
2
|
+
const ve = { class: "timepicker-dropdown" }, fe = ["tabindex", "onClick", "onMousemove"], C = /* @__PURE__ */ X({
|
|
3
3
|
__name: "TimeColumn",
|
|
4
4
|
props: {
|
|
5
5
|
items: {},
|
|
6
6
|
activeIndex: {}
|
|
7
7
|
},
|
|
8
8
|
emits: ["update:activeIndex", "select"],
|
|
9
|
-
setup(
|
|
10
|
-
const
|
|
9
|
+
setup(s, { emit: r }) {
|
|
10
|
+
const l = s, o = r, p = w(null);
|
|
11
11
|
function a() {
|
|
12
|
-
|
|
12
|
+
Y(() => {
|
|
13
13
|
const v = p.value;
|
|
14
14
|
if (!v) return;
|
|
15
15
|
const g = v.querySelector(
|
|
@@ -21,12 +21,12 @@ const pe = { class: "timepicker-dropdown" }, ve = ["tabindex", "onClick", "onMou
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
O(a), E(() => l.activeIndex, a);
|
|
25
25
|
function f(v) {
|
|
26
|
-
o("update:activeIndex", v), o("select",
|
|
26
|
+
o("update:activeIndex", v), o("select", l.items[v]?.value);
|
|
27
27
|
}
|
|
28
|
-
const c =
|
|
29
|
-
return (v, g) => (
|
|
28
|
+
const c = w(l.activeIndex ?? 0);
|
|
29
|
+
return (v, g) => (b(), D("div", ve, [
|
|
30
30
|
K("div", {
|
|
31
31
|
ref_key: "menu",
|
|
32
32
|
ref: p,
|
|
@@ -34,7 +34,7 @@ const pe = { class: "timepicker-dropdown" }, ve = ["tabindex", "onClick", "onMou
|
|
|
34
34
|
role: "listbox",
|
|
35
35
|
tabindex: "-1"
|
|
36
36
|
}, [
|
|
37
|
-
(
|
|
37
|
+
(b(!0), D(ce, null, de(v.items, (h, x) => (b(), D("div", {
|
|
38
38
|
key: h.key,
|
|
39
39
|
class: q(["timepicker-option", {
|
|
40
40
|
"timepicker-option--active": x === v.activeIndex,
|
|
@@ -45,46 +45,46 @@ const pe = { class: "timepicker-dropdown" }, ve = ["tabindex", "onClick", "onMou
|
|
|
45
45
|
tabindex: h.disabled ? -1 : 0,
|
|
46
46
|
onClick: (m) => !h.disabled && f(x),
|
|
47
47
|
onMousemove: (m) => !h.disabled && (c.value = x)
|
|
48
|
-
},
|
|
48
|
+
}, pe(h.text), 43, fe))), 128))
|
|
49
49
|
], 512)
|
|
50
50
|
]));
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
|
-
function
|
|
54
|
-
return /(a|A|p|P)/.test(
|
|
53
|
+
function se(s) {
|
|
54
|
+
return /(a|A|p|P)/.test(s);
|
|
55
55
|
}
|
|
56
|
-
function
|
|
57
|
-
return /(p|P)/.test(
|
|
56
|
+
function he(s) {
|
|
57
|
+
return /(p|P)/.test(s);
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
return /k{1,2}/.test(
|
|
59
|
+
function Q(s) {
|
|
60
|
+
return /k{1,2}/.test(s);
|
|
61
61
|
}
|
|
62
|
-
function
|
|
63
|
-
if (!
|
|
64
|
-
const
|
|
65
|
-
let o =
|
|
66
|
-
const p = +
|
|
62
|
+
function z(s, r) {
|
|
63
|
+
if (!s) return { h: 0, m: 0, s: 0 };
|
|
64
|
+
const l = s.match(/\d+/g) || [];
|
|
65
|
+
let o = l[0] !== void 0 ? +l[0] : 0;
|
|
66
|
+
const p = +l[1] || 0, a = +l[2] || 0;
|
|
67
67
|
return { h: o, m: p, s: a };
|
|
68
68
|
}
|
|
69
|
-
function
|
|
70
|
-
const
|
|
71
|
-
return
|
|
69
|
+
function ge(s) {
|
|
70
|
+
const r = s % 12;
|
|
71
|
+
return r === 0 ? 12 : r;
|
|
72
72
|
}
|
|
73
|
-
function
|
|
74
|
-
return
|
|
73
|
+
function te(s, r) {
|
|
74
|
+
return r ? s % 12 + 12 : s % 12;
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
return /(s|ss)/.test(
|
|
76
|
+
function ke(s) {
|
|
77
|
+
return /(s|ss)/.test(s);
|
|
78
78
|
}
|
|
79
|
-
function
|
|
80
|
-
let { h:
|
|
81
|
-
const a =
|
|
82
|
-
a && (
|
|
83
|
-
const c =
|
|
84
|
-
HH: String(
|
|
85
|
-
H: String(
|
|
86
|
-
hh: String(
|
|
87
|
-
h: String(
|
|
79
|
+
function _(s, r) {
|
|
80
|
+
let { h: l, m: o, s: p } = r;
|
|
81
|
+
const a = se(s), f = l >= 12 ? "PM" : "AM";
|
|
82
|
+
a && (l = ge(l));
|
|
83
|
+
const c = l === 0 ? 24 : l, v = {
|
|
84
|
+
HH: String(l).padStart(2, "0"),
|
|
85
|
+
H: String(l),
|
|
86
|
+
hh: String(l).padStart(2, "0"),
|
|
87
|
+
h: String(l),
|
|
88
88
|
kk: String(c).padStart(2, "0"),
|
|
89
89
|
k: String(c),
|
|
90
90
|
mm: String(o).padStart(2, "0"),
|
|
@@ -96,9 +96,9 @@ function B(l, i) {
|
|
|
96
96
|
P: f,
|
|
97
97
|
p: f.toLowerCase()
|
|
98
98
|
};
|
|
99
|
-
return
|
|
99
|
+
return s.replace(/HH|hh|kk|mm|ss|H|h|k|m|s|A|a|P|p/g, (g) => v[g] ?? g);
|
|
100
100
|
}
|
|
101
|
-
const
|
|
101
|
+
const ne = /* @__PURE__ */ X({
|
|
102
102
|
__name: "TimeSelection",
|
|
103
103
|
props: {
|
|
104
104
|
open: { type: Boolean },
|
|
@@ -109,33 +109,33 @@ const te = /* @__PURE__ */ Q({
|
|
|
109
109
|
secondStep: {}
|
|
110
110
|
},
|
|
111
111
|
emits: ["update:initTime", "open", "close", "update:open"],
|
|
112
|
-
setup(
|
|
113
|
-
const
|
|
112
|
+
setup(s, { emit: r }) {
|
|
113
|
+
const l = y(() => se(a.format)), o = y(() => ke(a.format)), p = y(() => Q(a.format)), a = s, f = r, c = y({
|
|
114
114
|
get: () => a.open ?? !1,
|
|
115
115
|
set: (u) => {
|
|
116
116
|
const k = a.open ?? !1;
|
|
117
117
|
u !== k && (f("update:open", u), f(u ? "open" : "close"));
|
|
118
118
|
}
|
|
119
|
-
}), v =
|
|
119
|
+
}), v = w(null);
|
|
120
120
|
function g(u) {
|
|
121
121
|
if (!c.value) return;
|
|
122
122
|
const k = u.target;
|
|
123
123
|
v.value && !v.value.contains(k) && (c.value = !1);
|
|
124
124
|
}
|
|
125
|
-
|
|
125
|
+
O(() => document.addEventListener("mousedown", g)), ee(
|
|
126
126
|
() => document.removeEventListener("mousedown", g)
|
|
127
127
|
);
|
|
128
128
|
function h(u) {
|
|
129
129
|
u.key === "Escape" && c.value && (c.value = !1);
|
|
130
130
|
}
|
|
131
|
-
|
|
132
|
-
const x =
|
|
133
|
-
|
|
131
|
+
O(() => document.addEventListener("keydown", h)), ee(() => document.removeEventListener("keydown", h));
|
|
132
|
+
const x = w(Math.floor(a.initTime.h / a.hourStep) || 0), m = w(Math.floor(a.initTime.m / a.minuteStep) || 0), H = w(Math.floor(a.initTime.s / a.secondStep) || 0);
|
|
133
|
+
E(
|
|
134
134
|
() => a.initTime,
|
|
135
135
|
(u) => {
|
|
136
136
|
const k = Math.max(1, a.hourStep), M = Math.max(1, a.minuteStep), A = Math.max(1, a.secondStep);
|
|
137
|
-
let
|
|
138
|
-
|
|
137
|
+
let I = u.h;
|
|
138
|
+
l.value ? ($.value = u.h >= 12 ? 1 : 0, I = u.h % 12) : p.value && u.h === 0 && (I = 24), x.value = Math.floor(I / k), m.value = Math.floor(u.m / M), H.value = Math.floor(u.s / A);
|
|
139
139
|
}
|
|
140
140
|
);
|
|
141
141
|
function P(u, k) {
|
|
@@ -144,103 +144,105 @@ const te = /* @__PURE__ */ Q({
|
|
|
144
144
|
M.push({ key: A, value: A, text: String(A).padStart(2, "0") });
|
|
145
145
|
return M;
|
|
146
146
|
}
|
|
147
|
-
function
|
|
147
|
+
function N(u, k) {
|
|
148
148
|
const M = Math.max(1, k), A = [];
|
|
149
|
-
for (let
|
|
150
|
-
const
|
|
151
|
-
A.push({ key:
|
|
149
|
+
for (let I = 0; I < 12; I += M) {
|
|
150
|
+
const me = I === 0 ? 12 : I, Z = u ? I === 0 ? 12 : I + 12 : I;
|
|
151
|
+
A.push({ key: Z, value: Z, text: String(me).padStart(2, "0") });
|
|
152
152
|
}
|
|
153
153
|
return A;
|
|
154
154
|
}
|
|
155
|
-
function
|
|
155
|
+
function L(u) {
|
|
156
156
|
const k = Math.max(1, u), M = [];
|
|
157
157
|
for (let A = 0; A < 24; A += k) {
|
|
158
|
-
const
|
|
159
|
-
M.push({ key: A, value: A, text: String(
|
|
158
|
+
const I = A === 0 ? 24 : A;
|
|
159
|
+
M.push({ key: A, value: A, text: String(I).padStart(2, "0") });
|
|
160
160
|
}
|
|
161
161
|
return M;
|
|
162
162
|
}
|
|
163
|
-
const
|
|
164
|
-
if (!
|
|
165
|
-
return p.value ?
|
|
166
|
-
const u =
|
|
167
|
-
return
|
|
168
|
-
}),
|
|
163
|
+
const $ = w(he(a.format) ? 1 : 0), F = y(() => {
|
|
164
|
+
if (!l.value)
|
|
165
|
+
return p.value ? L(a.hourStep) : P(24, a.hourStep);
|
|
166
|
+
const u = $.value === 1;
|
|
167
|
+
return N(u, a.hourStep);
|
|
168
|
+
}), V = y(() => P(60, a.minuteStep)), e = y(() => P(60, a.secondStep)), t = y(() => /\s[ap]$/.test(a.format)), n = y(() => {
|
|
169
169
|
const u = t.value ? "am" : "AM", k = t.value ? "pm" : "PM";
|
|
170
170
|
return [
|
|
171
171
|
{ key: "AM", value: "AM", text: u },
|
|
172
172
|
{ key: "PM", value: "PM", text: k }
|
|
173
173
|
];
|
|
174
|
-
}), d = y(() =>
|
|
175
|
-
const u = Number(
|
|
176
|
-
return
|
|
174
|
+
}), d = y(() => $.value === 1 ? "PM" : "AM"), i = y(() => {
|
|
175
|
+
const u = Number(F.value[x.value]?.value ?? 0);
|
|
176
|
+
return l.value ? d.value === "PM" ? te(u, !0) : te(u, !1) : p.value && u === 24 ? 0 : u;
|
|
177
177
|
}), S = y(
|
|
178
|
-
() => Number(
|
|
179
|
-
),
|
|
180
|
-
() => Number(e.value[
|
|
178
|
+
() => Number(V.value[m.value]?.value ?? 0)
|
|
179
|
+
), U = y(
|
|
180
|
+
() => Number(e.value[H.value]?.value ?? 0)
|
|
181
181
|
);
|
|
182
|
-
function le(u) {
|
|
183
|
-
!o.value && !s.value && R();
|
|
184
|
-
}
|
|
185
182
|
function re(u) {
|
|
186
|
-
|
|
183
|
+
!o.value && !l.value && G();
|
|
184
|
+
}
|
|
185
|
+
function ie(u) {
|
|
186
|
+
l.value || G();
|
|
187
187
|
}
|
|
188
188
|
function ue(u) {
|
|
189
|
-
|
|
189
|
+
G();
|
|
190
190
|
}
|
|
191
|
-
function
|
|
191
|
+
function G() {
|
|
192
192
|
c.value = !1;
|
|
193
193
|
}
|
|
194
|
-
return
|
|
195
|
-
[
|
|
194
|
+
return E(
|
|
195
|
+
[i, S, U],
|
|
196
196
|
([u, k, M]) => {
|
|
197
197
|
f("update:initTime", { h: u, m: k, s: M });
|
|
198
198
|
},
|
|
199
199
|
{ immediate: !0 }
|
|
200
|
-
), (u, k) => c.value ? (
|
|
200
|
+
), (u, k) => c.value ? (b(), D("div", {
|
|
201
201
|
key: 0,
|
|
202
202
|
class: "vtp-cols",
|
|
203
203
|
ref_key: "root",
|
|
204
204
|
ref: v
|
|
205
205
|
}, [
|
|
206
|
-
|
|
206
|
+
W(C, {
|
|
207
207
|
activeIndex: x.value,
|
|
208
208
|
"onUpdate:activeIndex": k[0] || (k[0] = (M) => x.value = M),
|
|
209
|
-
items:
|
|
209
|
+
items: F.value,
|
|
210
210
|
label: "Hours"
|
|
211
211
|
}, null, 8, ["activeIndex", "items"]),
|
|
212
|
-
|
|
212
|
+
W(C, {
|
|
213
213
|
activeIndex: m.value,
|
|
214
214
|
"onUpdate:activeIndex": k[1] || (k[1] = (M) => m.value = M),
|
|
215
|
-
items:
|
|
215
|
+
items: V.value,
|
|
216
216
|
label: "Minutes",
|
|
217
|
-
onSelect:
|
|
217
|
+
onSelect: re
|
|
218
218
|
}, null, 8, ["activeIndex", "items"]),
|
|
219
|
-
o.value ? (
|
|
219
|
+
o.value ? (b(), J(C, {
|
|
220
220
|
key: 0,
|
|
221
|
-
activeIndex:
|
|
222
|
-
"onUpdate:activeIndex": k[2] || (k[2] = (M) =>
|
|
221
|
+
activeIndex: H.value,
|
|
222
|
+
"onUpdate:activeIndex": k[2] || (k[2] = (M) => H.value = M),
|
|
223
223
|
items: e.value,
|
|
224
224
|
label: "Seconds",
|
|
225
|
-
onSelect:
|
|
226
|
-
}, null, 8, ["activeIndex", "items"])) :
|
|
227
|
-
|
|
225
|
+
onSelect: ie
|
|
226
|
+
}, null, 8, ["activeIndex", "items"])) : B("", !0),
|
|
227
|
+
l.value ? (b(), J(C, {
|
|
228
228
|
key: 1,
|
|
229
|
-
activeIndex:
|
|
230
|
-
"onUpdate:activeIndex": k[3] || (k[3] = (M) =>
|
|
229
|
+
activeIndex: $.value,
|
|
230
|
+
"onUpdate:activeIndex": k[3] || (k[3] = (M) => $.value = M),
|
|
231
231
|
items: n.value,
|
|
232
232
|
label: "AM/PM",
|
|
233
233
|
onSelect: ue
|
|
234
|
-
}, null, 8, ["activeIndex", "items"])) :
|
|
235
|
-
], 512)) :
|
|
234
|
+
}, null, 8, ["activeIndex", "items"])) : B("", !0)
|
|
235
|
+
], 512)) : B("", !0);
|
|
236
236
|
}
|
|
237
|
-
}),
|
|
237
|
+
}), le = /^(HH|H|hh|h|kk|k):(mm|m)(?::(ss|s))?(?:\s*(A|a|P|p))?$/, oe = /^([01]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?$/, j = typeof __DEV__ < "u" ? __DEV__ : typeof process < "u" && process.env && process.env.NODE_ENV !== "production", ye = {
|
|
238
238
|
modelValue: {
|
|
239
239
|
type: [String, Array],
|
|
240
240
|
default: void 0,
|
|
241
|
-
validator: (
|
|
242
|
-
let
|
|
243
|
-
return Array.isArray(
|
|
241
|
+
validator: (s) => {
|
|
242
|
+
let r;
|
|
243
|
+
return Array.isArray(s) ? r = s.length === 2 && s.every((l) => oe.test(l)) : r = s == null || oe.test(s), !r && j && console.error(
|
|
244
|
+
`[VueTimepicker] \`modelValue\` is wrong. Received: ${s}`
|
|
245
|
+
), r;
|
|
244
246
|
}
|
|
245
247
|
},
|
|
246
248
|
range: {
|
|
@@ -253,44 +255,57 @@ const te = /* @__PURE__ */ Q({
|
|
|
253
255
|
format: {
|
|
254
256
|
type: String,
|
|
255
257
|
default: "HH:mm",
|
|
256
|
-
validator: (
|
|
258
|
+
validator: (s) => {
|
|
259
|
+
const r = le.test(s);
|
|
260
|
+
return !r && j && console.error(
|
|
261
|
+
`[VueTimepicker] \`format\` format is wrong. Received: ${s}`
|
|
262
|
+
), r;
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
size: {
|
|
266
|
+
type: String,
|
|
267
|
+
default: "md",
|
|
268
|
+
validator: (s) => {
|
|
269
|
+
const r = s === "sm" || s === "md" || s === "lg";
|
|
270
|
+
return !r && j && console.error(`[VueTimepicker] \`size\` is wrong. Received: ${s}`), r;
|
|
271
|
+
}
|
|
257
272
|
}
|
|
258
273
|
};
|
|
259
|
-
function
|
|
260
|
-
const
|
|
261
|
-
if (!
|
|
262
|
-
const [,
|
|
274
|
+
function Se(s) {
|
|
275
|
+
const r = le.exec(s);
|
|
276
|
+
if (!r) throw new Error(`[useTimeMask] Invalid format: ${s}`);
|
|
277
|
+
const [, l, o, p, a] = r, f = [], c = !!a, v = /^k{1,2}$/.test(l);
|
|
263
278
|
let g = 0, h = 23;
|
|
264
|
-
return c ? (g = 1, h = 12) : v && (g = 1, h = 24), f.push({ token:
|
|
279
|
+
return c ? (g = 1, h = 12) : v && (g = 1, h = 24), f.push({ token: l, min: g, max: h }), f.push({ token: o, min: 0, max: 59 }), p && f.push({ token: p, min: 0, max: 59 }), {
|
|
265
280
|
digitGroups: f,
|
|
266
281
|
hasAmPm: !!a,
|
|
267
282
|
ampmLowercase: a === "a" || a === "p"
|
|
268
283
|
};
|
|
269
284
|
}
|
|
270
|
-
function
|
|
271
|
-
const
|
|
285
|
+
function ae(s) {
|
|
286
|
+
const r = y(() => Se(s.value)), l = y(() => r.value.digitGroups.length * 2), o = w([]), p = w("AM"), a = w("");
|
|
272
287
|
function f() {
|
|
273
|
-
const { digitGroups: e, hasAmPm: t } =
|
|
288
|
+
const { digitGroups: e, hasAmPm: t } = r.value;
|
|
274
289
|
let n = "", d = 0;
|
|
275
|
-
for (let
|
|
290
|
+
for (let i = 0; i < e.length; i++) {
|
|
276
291
|
for (let S = 0; S < 2; S++)
|
|
277
292
|
d < o.value.length && (n += String(o.value[d]), d++);
|
|
278
|
-
d === (
|
|
293
|
+
d === (i + 1) * 2 && i < e.length - 1 && (n += ":");
|
|
279
294
|
}
|
|
280
|
-
if (t && d >=
|
|
281
|
-
const
|
|
282
|
-
n += " " +
|
|
295
|
+
if (t && d >= l.value) {
|
|
296
|
+
const i = r.value.ampmLowercase ? p.value.toLowerCase() : p.value;
|
|
297
|
+
n += " " + i;
|
|
283
298
|
}
|
|
284
299
|
return n;
|
|
285
300
|
}
|
|
286
301
|
function c(e) {
|
|
287
302
|
const t = e * 2;
|
|
288
303
|
if (o.value.length < t + 2) return;
|
|
289
|
-
const n = o.value[t] * 10 + o.value[t + 1], { min: d, max:
|
|
304
|
+
const n = o.value[t] * 10 + o.value[t + 1], { min: d, max: i } = r.value.digitGroups[e], S = Math.max(d, Math.min(i, n));
|
|
290
305
|
S !== n && (o.value[t] = Math.floor(S / 10), o.value[t + 1] = S % 10);
|
|
291
306
|
}
|
|
292
307
|
function v() {
|
|
293
|
-
for (let e = 0; e <
|
|
308
|
+
for (let e = 0; e < r.value.digitGroups.length; e++)
|
|
294
309
|
c(e);
|
|
295
310
|
}
|
|
296
311
|
function g(e) {
|
|
@@ -304,122 +319,122 @@ function oe(l) {
|
|
|
304
319
|
return e + Math.floor(e / 2);
|
|
305
320
|
}
|
|
306
321
|
function x(e, t) {
|
|
307
|
-
if (e >=
|
|
322
|
+
if (e >= l.value) return l.value;
|
|
308
323
|
const n = [...o.value];
|
|
309
324
|
n[e] = t, o.value = n;
|
|
310
325
|
const d = Math.floor(e / 2);
|
|
311
|
-
return c(d), Math.min(e + 1,
|
|
326
|
+
return c(d), Math.min(e + 1, l.value);
|
|
312
327
|
}
|
|
313
328
|
function m(e, t) {
|
|
314
329
|
const n = f();
|
|
315
330
|
a.value = n, e.value = n;
|
|
316
331
|
const d = t !== void 0 ? Math.min(h(t), n.length) : n.length;
|
|
317
|
-
e.selectionStart = e.selectionEnd = d,
|
|
332
|
+
e.selectionStart = e.selectionEnd = d, Y(() => {
|
|
318
333
|
document.activeElement === e && (e.selectionStart = e.selectionEnd = d);
|
|
319
334
|
});
|
|
320
335
|
}
|
|
321
|
-
function
|
|
336
|
+
function H(e) {
|
|
322
337
|
const t = e.key, n = e.target;
|
|
323
338
|
if (["Tab", "Escape", "ArrowLeft", "ArrowRight", "Home", "End"].includes(
|
|
324
339
|
t
|
|
325
340
|
) || e.metaKey || e.ctrlKey)
|
|
326
341
|
return;
|
|
327
342
|
e.preventDefault();
|
|
328
|
-
const d = n.selectionStart ?? 0,
|
|
343
|
+
const d = n.selectionStart ?? 0, i = g(d);
|
|
329
344
|
if (t === "Backspace") {
|
|
330
|
-
|
|
345
|
+
i > 0 && m(n, i - 1);
|
|
331
346
|
return;
|
|
332
347
|
}
|
|
333
348
|
if (t !== "Delete") {
|
|
334
|
-
if (
|
|
349
|
+
if (r.value.hasAmPm) {
|
|
335
350
|
const S = t.toLowerCase();
|
|
336
351
|
if (S === "a") {
|
|
337
|
-
p.value = "AM", m(n,
|
|
352
|
+
p.value = "AM", m(n, i);
|
|
338
353
|
return;
|
|
339
354
|
}
|
|
340
355
|
if (S === "p") {
|
|
341
|
-
p.value = "PM", m(n,
|
|
356
|
+
p.value = "PM", m(n, i);
|
|
342
357
|
return;
|
|
343
358
|
}
|
|
344
359
|
}
|
|
345
360
|
if (/^\d$/.test(t)) {
|
|
346
|
-
const S = x(
|
|
361
|
+
const S = x(i, +t);
|
|
347
362
|
m(n, S);
|
|
348
363
|
return;
|
|
349
364
|
}
|
|
350
365
|
}
|
|
351
366
|
}
|
|
352
367
|
function P(e) {
|
|
353
|
-
const t = e.target, n = t.value.replace(/\D/g, "").split("").map(Number).slice(0,
|
|
354
|
-
o.value = n, v(),
|
|
368
|
+
const t = e.target, n = t.value.replace(/\D/g, "").split("").map(Number).slice(0, l.value);
|
|
369
|
+
o.value = n, v(), r.value.hasAmPm && (/p/i.test(t.value) ? p.value = "PM" : /a/i.test(t.value) && (p.value = "AM")), m(t);
|
|
355
370
|
}
|
|
356
|
-
function
|
|
371
|
+
function N(e) {
|
|
357
372
|
e.preventDefault();
|
|
358
|
-
const t = e.clipboardData?.getData("text") ?? "", n = e.target, d = n.selectionStart ?? 0,
|
|
373
|
+
const t = e.clipboardData?.getData("text") ?? "", n = e.target, d = n.selectionStart ?? 0, i = t.replace(/\D/g, "").split("").map(Number);
|
|
359
374
|
let S = g(d);
|
|
360
|
-
for (const
|
|
361
|
-
if (S >=
|
|
362
|
-
S = x(S,
|
|
375
|
+
for (const U of i) {
|
|
376
|
+
if (S >= l.value) break;
|
|
377
|
+
S = x(S, U);
|
|
363
378
|
}
|
|
364
|
-
|
|
379
|
+
r.value.hasAmPm && (/p\.?m\.?/i.test(t) ? p.value = "PM" : /a\.?m\.?/i.test(t) && (p.value = "AM")), m(n, S);
|
|
365
380
|
}
|
|
366
|
-
function
|
|
367
|
-
const { digitGroups: t, hasAmPm: n } =
|
|
368
|
-
let
|
|
369
|
-
n ? (p.value = e.h >= 12 ? "PM" : "AM",
|
|
381
|
+
function L(e) {
|
|
382
|
+
const { digitGroups: t, hasAmPm: n } = r.value, d = [];
|
|
383
|
+
let i = e.h;
|
|
384
|
+
n ? (p.value = e.h >= 12 ? "PM" : "AM", i = e.h % 12, i === 0 && (i = 12)) : Q(s.value) && (i = e.h === 0 ? 24 : e.h), d.push(Math.floor(i / 10), i % 10), d.push(Math.floor(e.m / 10), e.m % 10), t.length > 2 && d.push(Math.floor(e.s / 10), e.s % 10), o.value = d, a.value = f();
|
|
370
385
|
}
|
|
371
|
-
function
|
|
372
|
-
if (o.value.length <
|
|
386
|
+
function $() {
|
|
387
|
+
if (o.value.length < l.value) return null;
|
|
373
388
|
const e = [];
|
|
374
|
-
for (let
|
|
375
|
-
const S =
|
|
389
|
+
for (let i = 0; i < r.value.digitGroups.length; i++) {
|
|
390
|
+
const S = i * 2;
|
|
376
391
|
e.push(o.value[S] * 10 + o.value[S + 1]);
|
|
377
392
|
}
|
|
378
393
|
let t = e[0];
|
|
379
394
|
const n = e[1], d = e[2] ?? 0;
|
|
380
|
-
return
|
|
395
|
+
return r.value.hasAmPm && (t = p.value === "PM" ? t === 12 ? 12 : t + 12 : t === 12 ? 0 : t), Q(s.value) && t === 24 && (t = 0), { h: t, m: n, s: d };
|
|
381
396
|
}
|
|
382
|
-
const
|
|
383
|
-
() => o.value.length >=
|
|
384
|
-
),
|
|
397
|
+
const F = y(
|
|
398
|
+
() => o.value.length >= l.value
|
|
399
|
+
), V = y(() => r.value.ampmLowercase);
|
|
385
400
|
return {
|
|
386
401
|
inputValue: a,
|
|
387
|
-
handleKeydown:
|
|
402
|
+
handleKeydown: H,
|
|
388
403
|
handleInput: P,
|
|
389
|
-
handlePaste:
|
|
390
|
-
setFromTime:
|
|
391
|
-
getParsedTime:
|
|
392
|
-
isComplete:
|
|
393
|
-
totalDigits:
|
|
404
|
+
handlePaste: N,
|
|
405
|
+
setFromTime: L,
|
|
406
|
+
getParsedTime: $,
|
|
407
|
+
isComplete: F,
|
|
408
|
+
totalDigits: l,
|
|
394
409
|
displayPosToDigitIndex: g,
|
|
395
410
|
ampm: p,
|
|
396
|
-
ampmLowercase:
|
|
411
|
+
ampmLowercase: V
|
|
397
412
|
};
|
|
398
413
|
}
|
|
399
|
-
const
|
|
414
|
+
const Me = ["data-size"], xe = ["value", "placeholder"], Ae = ["value", "placeholder"], Pe = ["value", "placeholder"], we = /* @__PURE__ */ X({
|
|
400
415
|
__name: "TimePicker",
|
|
401
|
-
props:
|
|
416
|
+
props: ye,
|
|
402
417
|
emits: ["update:modelValue", "open", "close", "error"],
|
|
403
|
-
setup(
|
|
404
|
-
const
|
|
405
|
-
|
|
418
|
+
setup(s, { emit: r }) {
|
|
419
|
+
const l = w(null), o = s, p = r, a = w(!1), f = w(!1);
|
|
420
|
+
E(a, (e) => {
|
|
406
421
|
e && (f.value = !1);
|
|
407
|
-
}),
|
|
422
|
+
}), E(f, (e) => {
|
|
408
423
|
e && (a.value = !1);
|
|
409
424
|
});
|
|
410
425
|
const c = y({
|
|
411
426
|
get() {
|
|
412
427
|
if (Array.isArray(o.modelValue)) {
|
|
413
428
|
const [e, t] = o.modelValue;
|
|
414
|
-
return [
|
|
429
|
+
return [z(e, o.format), z(t, o.format)];
|
|
415
430
|
} else
|
|
416
|
-
return
|
|
431
|
+
return z(o.modelValue, o.format);
|
|
417
432
|
},
|
|
418
433
|
set(e) {
|
|
419
434
|
Array.isArray(e) ? p("update:modelValue", [
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
]) : p("update:modelValue",
|
|
435
|
+
_("HH:mm:ss", e[0]),
|
|
436
|
+
_("HH:mm:ss", e[1])
|
|
437
|
+
]) : p("update:modelValue", _("HH:mm:ss", e));
|
|
423
438
|
}
|
|
424
439
|
}), v = y({
|
|
425
440
|
get() {
|
|
@@ -438,9 +453,9 @@ const Se = { class: "timepicker-shell" }, Me = ["value", "placeholder"], xe = ["
|
|
|
438
453
|
});
|
|
439
454
|
y(() => {
|
|
440
455
|
if (!o.modelValue) return "—";
|
|
441
|
-
const e = (t) =>
|
|
456
|
+
const e = (t) => _(o.format, t);
|
|
442
457
|
return o.range ? `${e(v.value)} → ${e(g.value)}` : e(v.value);
|
|
443
|
-
}),
|
|
458
|
+
}), E(
|
|
444
459
|
() => o.range,
|
|
445
460
|
(e) => {
|
|
446
461
|
if (e) {
|
|
@@ -458,14 +473,14 @@ const Se = { class: "timepicker-shell" }, Me = ["value", "placeholder"], xe = ["
|
|
|
458
473
|
const h = y(() => o.format ?? "HH:mm:ss"), x = y(() => {
|
|
459
474
|
let e = h.value.length;
|
|
460
475
|
return /[AaPp]$/.test(h.value) && (e += 1), `${Math.min(12, Math.max(4, e))}ch`;
|
|
461
|
-
}), m =
|
|
462
|
-
|
|
476
|
+
}), m = ae(h), H = m.inputValue, P = ae(h), N = P.inputValue;
|
|
477
|
+
E(
|
|
463
478
|
() => [v.value, h.value],
|
|
464
479
|
([e]) => {
|
|
465
480
|
m.setFromTime(e);
|
|
466
481
|
},
|
|
467
482
|
{ immediate: !0 }
|
|
468
|
-
),
|
|
483
|
+
), E(
|
|
469
484
|
() => [g.value, h.value, o.range],
|
|
470
485
|
([e, , t]) => {
|
|
471
486
|
if (!t) {
|
|
@@ -476,94 +491,97 @@ const Se = { class: "timepicker-shell" }, Me = ["value", "placeholder"], xe = ["
|
|
|
476
491
|
},
|
|
477
492
|
{ immediate: !0 }
|
|
478
493
|
);
|
|
479
|
-
const
|
|
480
|
-
function
|
|
494
|
+
const L = w(null);
|
|
495
|
+
function $(e) {
|
|
481
496
|
if (e.key === "Enter") {
|
|
482
|
-
e.preventDefault(),
|
|
497
|
+
e.preventDefault(), V("first");
|
|
483
498
|
return;
|
|
484
499
|
}
|
|
485
500
|
/^\d$/.test(e.key) && (a.value = !1, f.value = !1);
|
|
486
501
|
const t = e.target, n = m.displayPosToDigitIndex(t.selectionStart ?? 0), d = /^\d$/.test(e.key) && n >= m.totalDigits.value - 1;
|
|
487
502
|
if (m.handleKeydown(e), /^\d$/.test(e.key)) {
|
|
488
|
-
const
|
|
489
|
-
|
|
503
|
+
const i = m.getParsedTime();
|
|
504
|
+
i && (l.value = null, v.value = i);
|
|
490
505
|
}
|
|
491
|
-
o.range && d &&
|
|
492
|
-
const
|
|
493
|
-
|
|
506
|
+
o.range && d && L.value && (V("first"), Y(() => {
|
|
507
|
+
const i = L.value;
|
|
508
|
+
i && (i.focus(), i.selectionStart = i.selectionEnd = 0);
|
|
494
509
|
}));
|
|
495
510
|
}
|
|
496
|
-
function
|
|
511
|
+
function F(e) {
|
|
497
512
|
if (e.key === "Enter") {
|
|
498
|
-
e.preventDefault(),
|
|
513
|
+
e.preventDefault(), V("second");
|
|
499
514
|
return;
|
|
500
515
|
}
|
|
501
516
|
if (/^\d$/.test(e.key) && (a.value = !1, f.value = !1), P.handleKeydown(e), /^\d$/.test(e.key)) {
|
|
502
517
|
const t = P.getParsedTime();
|
|
503
|
-
t && (
|
|
518
|
+
t && (l.value = null, g.value = t);
|
|
504
519
|
}
|
|
505
520
|
}
|
|
506
|
-
function
|
|
521
|
+
function V(e) {
|
|
507
522
|
const n = (e === "first" ? m : P).getParsedTime();
|
|
508
|
-
n && (
|
|
523
|
+
n && (l.value = null, e === "first" ? v.value = n : o.range && (g.value = n)), e === "first" ? m.setFromTime(v.value) : o.range && P.setFromTime(g.value);
|
|
509
524
|
}
|
|
510
|
-
return (e, t) => (
|
|
511
|
-
|
|
525
|
+
return (e, t) => (b(), D("div", {
|
|
526
|
+
class: "timepicker-shell",
|
|
527
|
+
"data-size": o.size
|
|
528
|
+
}, [
|
|
529
|
+
o.range ? (b(), D("div", {
|
|
512
530
|
key: 1,
|
|
513
|
-
class: q(["timepicker-shell__input", { "timepicker-shell__input--error":
|
|
531
|
+
class: q(["timepicker-shell__input", { "timepicker-shell__input--error": l.value }])
|
|
514
532
|
}, [
|
|
515
533
|
K("input", {
|
|
516
534
|
type: "text",
|
|
517
535
|
class: "timepicker-field",
|
|
518
|
-
value:
|
|
536
|
+
value: T(H),
|
|
519
537
|
placeholder: h.value,
|
|
520
|
-
style:
|
|
538
|
+
style: R({ width: x.value }),
|
|
521
539
|
onFocus: t[4] || (t[4] = (n) => a.value = !0),
|
|
522
|
-
onKeydown:
|
|
540
|
+
onKeydown: $,
|
|
523
541
|
onInput: t[5] || (t[5] = //@ts-ignore
|
|
524
|
-
(...n) =>
|
|
542
|
+
(...n) => T(m).handleInput && T(m).handleInput(...n)),
|
|
525
543
|
onPaste: t[6] || (t[6] = //@ts-ignore
|
|
526
|
-
(...n) =>
|
|
527
|
-
onBlur: t[7] || (t[7] = (n) =>
|
|
528
|
-
}, null, 44,
|
|
544
|
+
(...n) => T(m).handlePaste && T(m).handlePaste(...n)),
|
|
545
|
+
onBlur: t[7] || (t[7] = (n) => V("first"))
|
|
546
|
+
}, null, 44, Ae),
|
|
529
547
|
t[16] || (t[16] = K("span", { class: "timepicker-separator" }, "–", -1)),
|
|
530
548
|
K("input", {
|
|
531
549
|
ref_key: "secondInputRef",
|
|
532
|
-
ref:
|
|
550
|
+
ref: L,
|
|
533
551
|
type: "text",
|
|
534
552
|
class: "timepicker-field",
|
|
535
|
-
value:
|
|
553
|
+
value: T(N),
|
|
536
554
|
placeholder: h.value,
|
|
537
|
-
style:
|
|
555
|
+
style: R({ width: x.value }),
|
|
538
556
|
onFocus: t[8] || (t[8] = (n) => f.value = !0),
|
|
539
|
-
onKeydown:
|
|
557
|
+
onKeydown: F,
|
|
540
558
|
onInput: t[9] || (t[9] = //@ts-ignore
|
|
541
|
-
(...n) =>
|
|
559
|
+
(...n) => T(P).handleInput && T(P).handleInput(...n)),
|
|
542
560
|
onPaste: t[10] || (t[10] = //@ts-ignore
|
|
543
|
-
(...n) =>
|
|
544
|
-
onBlur: t[11] || (t[11] = (n) =>
|
|
545
|
-
}, null, 44,
|
|
546
|
-
], 2)) : (
|
|
561
|
+
(...n) => T(P).handlePaste && T(P).handlePaste(...n)),
|
|
562
|
+
onBlur: t[11] || (t[11] = (n) => V("second"))
|
|
563
|
+
}, null, 44, Pe)
|
|
564
|
+
], 2)) : (b(), D("div", {
|
|
547
565
|
key: 0,
|
|
548
|
-
class: q(["timepicker-shell__input", { "timepicker-shell__input--error":
|
|
566
|
+
class: q(["timepicker-shell__input", { "timepicker-shell__input--error": l.value }])
|
|
549
567
|
}, [
|
|
550
568
|
K("input", {
|
|
551
569
|
type: "text",
|
|
552
570
|
class: "timepicker-field",
|
|
553
|
-
value:
|
|
571
|
+
value: T(H),
|
|
554
572
|
placeholder: h.value,
|
|
555
|
-
style:
|
|
573
|
+
style: R({ width: x.value }),
|
|
556
574
|
onFocus: t[0] || (t[0] = (n) => a.value = !0),
|
|
557
|
-
onKeydown:
|
|
575
|
+
onKeydown: $,
|
|
558
576
|
onInput: t[1] || (t[1] = //@ts-ignore
|
|
559
|
-
(...n) =>
|
|
577
|
+
(...n) => T(m).handleInput && T(m).handleInput(...n)),
|
|
560
578
|
onPaste: t[2] || (t[2] = //@ts-ignore
|
|
561
|
-
(...n) =>
|
|
562
|
-
onBlur: t[3] || (t[3] = (n) =>
|
|
563
|
-
}, null, 44,
|
|
579
|
+
(...n) => T(m).handlePaste && T(m).handlePaste(...n)),
|
|
580
|
+
onBlur: t[3] || (t[3] = (n) => V("first"))
|
|
581
|
+
}, null, 44, xe)
|
|
564
582
|
], 2)),
|
|
565
583
|
K("div", null, [
|
|
566
|
-
|
|
584
|
+
W(ne, {
|
|
567
585
|
open: a.value,
|
|
568
586
|
"onUpdate:open": t[12] || (t[12] = (n) => a.value = n),
|
|
569
587
|
initTime: v.value,
|
|
@@ -573,7 +591,7 @@ const Se = { class: "timepicker-shell" }, Me = ["value", "placeholder"], xe = ["
|
|
|
573
591
|
"minute-step": o.minuteStep,
|
|
574
592
|
"second-step": o.secondStep
|
|
575
593
|
}, null, 8, ["open", "initTime", "format", "hour-step", "minute-step", "second-step"]),
|
|
576
|
-
o.range ? (
|
|
594
|
+
o.range ? (b(), J(ne, {
|
|
577
595
|
key: 0,
|
|
578
596
|
open: f.value,
|
|
579
597
|
"onUpdate:open": t[14] || (t[14] = (n) => f.value = n),
|
|
@@ -583,11 +601,11 @@ const Se = { class: "timepicker-shell" }, Me = ["value", "placeholder"], xe = ["
|
|
|
583
601
|
"hour-step": o.hourStep,
|
|
584
602
|
"minute-step": o.minuteStep,
|
|
585
603
|
"second-step": o.secondStep
|
|
586
|
-
}, null, 8, ["open", "initTime", "format", "hour-step", "minute-step", "second-step"])) :
|
|
604
|
+
}, null, 8, ["open", "initTime", "format", "hour-step", "minute-step", "second-step"])) : B("", !0)
|
|
587
605
|
])
|
|
588
|
-
]));
|
|
606
|
+
], 8, Me));
|
|
589
607
|
}
|
|
590
608
|
});
|
|
591
609
|
export {
|
|
592
|
-
|
|
610
|
+
we as TimePicker
|
|
593
611
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(E,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(E=typeof globalThis<"u"?globalThis:E||self,e(E.VueTimepicker={},E.Vue))})(this,(function(E,e){"use strict";const q={class:"timepicker-dropdown"},O=["tabindex","onClick","onMousemove"],$=e.defineComponent({__name:"TimeColumn",props:{items:{},activeIndex:{}},emits:["update:activeIndex","select"],setup(s,{emit:c}){const r=s,a=c,f=e.ref(null);function l(){e.nextTick(()=>{const h=f.value;if(!h)return;const g=h.querySelector(".timepicker-option--active");if(g){const k=h.clientHeight,x=g.offsetTop,m=g.offsetHeight;h.scrollTop=x-k/2+m/2}})}e.onMounted(l),e.watch(()=>r.activeIndex,l);function v(h){a("update:activeIndex",h),a("select",r.items[h]?.value)}const d=e.ref(r.activeIndex??0);return(h,g)=>(e.openBlock(),e.createElementBlock("div",q,[e.createElementVNode("div",{ref_key:"menu",ref:f,class:"timepicker-dropdown__panel",role:"listbox",tabindex:"-1"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.items,(k,x)=>(e.openBlock(),e.createElementBlock("div",{key:k.key,class:e.normalizeClass(["timepicker-option",{"timepicker-option--active":x===h.activeIndex,"timepicker-option--disabled":k.disabled,"timepicker-option--focused":x===d.value}]),role:"option",tabindex:k.disabled?-1:0,onClick:m=>!k.disabled&&v(x),onMousemove:m=>!k.disabled&&(d.value=x)},e.toDisplayString(k.text),43,O))),128))],512)]))}});function K(s){return/(a|A|p|P)/.test(s)}function W(s){return/(p|P)/.test(s)}function N(s){return/k{1,2}/.test(s)}function C(s,c){if(!s)return{h:0,m:0,s:0};const r=s.match(/\d+/g)||[];let a=r[0]!==void 0?+r[0]:0;const f=+r[1]||0,l=+r[2]||0;return{h:a,m:f,s:l}}function J(s){const c=s%12;return c===0?12:c}function U(s,c){return c?s%12+12:s%12}function Q(s){return/(s|ss)/.test(s)}function L(s,c){let{h:r,m:a,s:f}=c;const l=K(s),v=r>=12?"PM":"AM";l&&(r=J(r));const d=r===0?24:r,h={HH:String(r).padStart(2,"0"),H:String(r),hh:String(r).padStart(2,"0"),h:String(r),kk:String(d).padStart(2,"0"),k:String(d),mm:String(a).padStart(2,"0"),m:String(a),ss:String(f).padStart(2,"0"),s:String(f),A:v,a:v.toLowerCase(),P:v,p:v.toLowerCase()};return s.replace(/HH|hh|kk|mm|ss|H|h|k|m|s|A|a|P|p/g,g=>h[g]??g)}const G=e.defineComponent({__name:"TimeSelection",props:{open:{type:Boolean},initTime:{},format:{},hourStep:{},minuteStep:{},secondStep:{}},emits:["update:initTime","open","close","update:open"],setup(s,{emit:c}){const r=e.computed(()=>K(l.format)),a=e.computed(()=>Q(l.format)),f=e.computed(()=>N(l.format)),l=s,v=c,d=e.computed({get:()=>l.open??!1,set:u=>{const y=l.open??!1;u!==y&&(v("update:open",u),v(u?"open":"close"))}}),h=e.ref(null);function g(u){if(!d.value)return;const y=u.target;h.value&&!h.value.contains(y)&&(d.value=!1)}e.onMounted(()=>document.addEventListener("mousedown",g)),e.onBeforeUnmount(()=>document.removeEventListener("mousedown",g));function k(u){u.key==="Escape"&&d.value&&(d.value=!1)}e.onMounted(()=>document.addEventListener("keydown",k)),e.onBeforeUnmount(()=>document.removeEventListener("keydown",k));const x=e.ref(Math.floor(l.initTime.h/l.hourStep)||0),m=e.ref(Math.floor(l.initTime.m/l.minuteStep)||0),V=e.ref(Math.floor(l.initTime.s/l.secondStep)||0);e.watch(()=>l.initTime,u=>{const y=Math.max(1,l.hourStep),M=Math.max(1,l.minuteStep),A=Math.max(1,l.secondStep);let w=u.h;r.value?(I.value=u.h>=12?1:0,w=u.h%12):f.value&&u.h===0&&(w=24),x.value=Math.floor(w/y),m.value=Math.floor(u.m/M),V.value=Math.floor(u.s/A)});function P(u,y){const M=[];for(let A=0;A<u;A+=Math.max(1,y))M.push({key:A,value:A,text:String(A).padStart(2,"0")});return M}function H(u,y){const M=Math.max(1,y),A=[];for(let w=0;w<12;w+=M){const se=w===0?12:w,_=u?w===0?12:w+12:w;A.push({key:_,value:_,text:String(se).padStart(2,"0")})}return A}function b(u){const y=Math.max(1,u),M=[];for(let A=0;A<24;A+=y){const w=A===0?24:A;M.push({key:A,value:A,text:String(w).padStart(2,"0")})}return M}const I=e.ref(W(l.format)?1:0),B=e.computed(()=>{if(!r.value)return f.value?b(l.hourStep):P(24,l.hourStep);const u=I.value===1;return H(u,l.hourStep)}),T=e.computed(()=>P(60,l.minuteStep)),t=e.computed(()=>P(60,l.secondStep)),n=e.computed(()=>/\s[ap]$/.test(l.format)),o=e.computed(()=>{const u=n.value?"am":"AM",y=n.value?"pm":"PM";return[{key:"AM",value:"AM",text:u},{key:"PM",value:"PM",text:y}]}),p=e.computed(()=>I.value===1?"PM":"AM"),i=e.computed(()=>{const u=Number(B.value[x.value]?.value??0);return r.value?p.value==="PM"?U(u,!0):U(u,!1):f.value&&u===24?0:u}),S=e.computed(()=>Number(T.value[m.value]?.value??0)),F=e.computed(()=>Number(t.value[V.value]?.value??0));function ae(u){!a.value&&!r.value&&D()}function le(u){r.value||D()}function re(u){D()}function D(){d.value=!1}return e.watch([i,S,F],([u,y,M])=>{v("update:initTime",{h:u,m:y,s:M})},{immediate:!0}),(u,y)=>d.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"vtp-cols",ref_key:"root",ref:h},[e.createVNode($,{activeIndex:x.value,"onUpdate:activeIndex":y[0]||(y[0]=M=>x.value=M),items:B.value,label:"Hours"},null,8,["activeIndex","items"]),e.createVNode($,{activeIndex:m.value,"onUpdate:activeIndex":y[1]||(y[1]=M=>m.value=M),items:T.value,label:"Minutes",onSelect:ae},null,8,["activeIndex","items"]),a.value?(e.openBlock(),e.createBlock($,{key:0,activeIndex:V.value,"onUpdate:activeIndex":y[2]||(y[2]=M=>V.value=M),items:t.value,label:"Seconds",onSelect:le},null,8,["activeIndex","items"])):e.createCommentVNode("",!0),r.value?(e.openBlock(),e.createBlock($,{key:1,activeIndex:I.value,"onUpdate:activeIndex":y[3]||(y[3]=M=>I.value=M),items:o.value,label:"AM/PM",onSelect:re},null,8,["activeIndex","items"])):e.createCommentVNode("",!0)],512)):e.createCommentVNode("",!0)}}),z=/^(HH|H|hh|h|kk|k):(mm|m)(?::(ss|s))?(?:\s*(A|a|P|p))?$/,R=/^([01]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?$/,X={modelValue:{type:[String,Array],default:void 0,validator:s=>{let c;return Array.isArray(s)?c=s.length===2&&s.every(r=>R.test(r)):c=s==null||R.test(s),c}},range:{type:Boolean,default:!1},hourStep:{type:Number,default:1},minuteStep:{type:Number,default:1},secondStep:{type:Number,default:1},format:{type:String,default:"HH:mm",validator:s=>z.test(s)}};function Y(s){const c=z.exec(s);if(!c)throw new Error(`[useTimeMask] Invalid format: ${s}`);const[,r,a,f,l]=c,v=[],d=!!l,h=/^k{1,2}$/.test(r);let g=0,k=23;return d?(g=1,k=12):h&&(g=1,k=24),v.push({token:r,min:g,max:k}),v.push({token:a,min:0,max:59}),f&&v.push({token:f,min:0,max:59}),{digitGroups:v,hasAmPm:!!l,ampmLowercase:l==="a"||l==="p"}}function j(s){const c=e.computed(()=>Y(s.value)),r=e.computed(()=>c.value.digitGroups.length*2),a=e.ref([]),f=e.ref("AM"),l=e.ref("");function v(){const{digitGroups:t,hasAmPm:n}=c.value;let o="",p=0;for(let i=0;i<t.length;i++){for(let S=0;S<2;S++)p<a.value.length&&(o+=String(a.value[p]),p++);p===(i+1)*2&&i<t.length-1&&(o+=":")}if(n&&p>=r.value){const i=c.value.ampmLowercase?f.value.toLowerCase():f.value;o+=" "+i}return o}function d(t){const n=t*2;if(a.value.length<n+2)return;const o=a.value[n]*10+a.value[n+1],{min:p,max:i}=c.value.digitGroups[t],S=Math.max(p,Math.min(i,o));S!==o&&(a.value[n]=Math.floor(S/10),a.value[n+1]=S%10)}function h(){for(let t=0;t<c.value.digitGroups.length;t++)d(t)}function g(t){const n=v();let o=0;for(let p=0;p<Math.min(t,n.length);p++)/\d/.test(n[p])&&o++;return o}function k(t){return t+Math.floor(t/2)}function x(t,n){if(t>=r.value)return r.value;const o=[...a.value];o[t]=n,a.value=o;const p=Math.floor(t/2);return d(p),Math.min(t+1,r.value)}function m(t,n){const o=v();l.value=o,t.value=o;const p=n!==void 0?Math.min(k(n),o.length):o.length;t.selectionStart=t.selectionEnd=p,e.nextTick(()=>{document.activeElement===t&&(t.selectionStart=t.selectionEnd=p)})}function V(t){const n=t.key,o=t.target;if(["Tab","Escape","ArrowLeft","ArrowRight","Home","End"].includes(n)||t.metaKey||t.ctrlKey)return;t.preventDefault();const p=o.selectionStart??0,i=g(p);if(n==="Backspace"){i>0&&m(o,i-1);return}if(n!=="Delete"){if(c.value.hasAmPm){const S=n.toLowerCase();if(S==="a"){f.value="AM",m(o,i);return}if(S==="p"){f.value="PM",m(o,i);return}}if(/^\d$/.test(n)){const S=x(i,+n);m(o,S);return}}}function P(t){const n=t.target,o=n.value.replace(/\D/g,"").split("").map(Number).slice(0,r.value);a.value=o,h(),c.value.hasAmPm&&(/p/i.test(n.value)?f.value="PM":/a/i.test(n.value)&&(f.value="AM")),m(n)}function H(t){t.preventDefault();const n=t.clipboardData?.getData("text")??"",o=t.target,p=o.selectionStart??0,i=n.replace(/\D/g,"").split("").map(Number);let S=g(p);for(const F of i){if(S>=r.value)break;S=x(S,F)}c.value.hasAmPm&&(/p\.?m\.?/i.test(n)?f.value="PM":/a\.?m\.?/i.test(n)&&(f.value="AM")),m(o,S)}function b(t){const{digitGroups:n,hasAmPm:o}=c.value,p=[];let i=t.h;o?(f.value=t.h>=12?"PM":"AM",i=t.h%12,i===0&&(i=12)):N(s.value)&&(i=t.h===0?24:t.h),p.push(Math.floor(i/10),i%10),p.push(Math.floor(t.m/10),t.m%10),n.length>2&&p.push(Math.floor(t.s/10),t.s%10),a.value=p,l.value=v()}function I(){if(a.value.length<r.value)return null;const t=[];for(let i=0;i<c.value.digitGroups.length;i++){const S=i*2;t.push(a.value[S]*10+a.value[S+1])}let n=t[0];const o=t[1],p=t[2]??0;return c.value.hasAmPm&&(n=f.value==="PM"?n===12?12:n+12:n===12?0:n),N(s.value)&&n===24&&(n=0),{h:n,m:o,s:p}}const B=e.computed(()=>a.value.length>=r.value),T=e.computed(()=>c.value.ampmLowercase);return{inputValue:l,handleKeydown:V,handleInput:P,handlePaste:H,setFromTime:b,getParsedTime:I,isComplete:B,totalDigits:r,displayPosToDigitIndex:g,ampm:f,ampmLowercase:T}}const Z={class:"timepicker-shell"},ee=["value","placeholder"],te=["value","placeholder"],ne=["value","placeholder"],oe=e.defineComponent({__name:"TimePicker",props:X,emits:["update:modelValue","open","close","error"],setup(s,{emit:c}){const r=e.ref(null),a=s,f=c,l=e.ref(!1),v=e.ref(!1);e.watch(l,t=>{t&&(v.value=!1)}),e.watch(v,t=>{t&&(l.value=!1)});const d=e.computed({get(){if(Array.isArray(a.modelValue)){const[t,n]=a.modelValue;return[C(t,a.format),C(n,a.format)]}else return C(a.modelValue,a.format)},set(t){Array.isArray(t)?f("update:modelValue",[L("HH:mm:ss",t[0]),L("HH:mm:ss",t[1])]):f("update:modelValue",L("HH:mm:ss",t))}}),h=e.computed({get(){return Array.isArray(d.value)?d.value[0]:d.value},set(t){Array.isArray(d.value)?d.value=[t,d.value[1]]:d.value=t}}),g=e.computed({get(){return Array.isArray(d.value)?d.value[1]:d.value},set(t){Array.isArray(d.value)&&(d.value=[d.value[0],t])}});e.computed(()=>{if(!a.modelValue)return"—";const t=n=>L(a.format,n);return a.range?`${t(h.value)} → ${t(g.value)}`:t(h.value)}),e.watch(()=>a.range,t=>{if(t){if(!Array.isArray(a.modelValue))throw new RangeError(`Model value must be an array for range selection: ${a.modelValue}`)}else if(Array.isArray(a.modelValue))throw new RangeError(`Model value must be a single string for single time selection: ${a.modelValue}`)},{immediate:!0});const k=e.computed(()=>a.format??"HH:mm:ss"),x=e.computed(()=>{let t=k.value.length;return/[AaPp]$/.test(k.value)&&(t+=1),`${Math.min(12,Math.max(4,t))}ch`}),m=j(k),V=m.inputValue,P=j(k),H=P.inputValue;e.watch(()=>[h.value,k.value],([t])=>{m.setFromTime(t)},{immediate:!0}),e.watch(()=>[g.value,k.value,a.range],([t,,n])=>{if(!n){P.setFromTime({h:0,m:0,s:0});return}P.setFromTime(t)},{immediate:!0});const b=e.ref(null);function I(t){if(t.key==="Enter"){t.preventDefault(),T("first");return}/^\d$/.test(t.key)&&(l.value=!1,v.value=!1);const n=t.target,o=m.displayPosToDigitIndex(n.selectionStart??0),p=/^\d$/.test(t.key)&&o>=m.totalDigits.value-1;if(m.handleKeydown(t),/^\d$/.test(t.key)){const i=m.getParsedTime();i&&(r.value=null,h.value=i)}a.range&&p&&b.value&&(T("first"),e.nextTick(()=>{const i=b.value;i&&(i.focus(),i.selectionStart=i.selectionEnd=0)}))}function B(t){if(t.key==="Enter"){t.preventDefault(),T("second");return}if(/^\d$/.test(t.key)&&(l.value=!1,v.value=!1),P.handleKeydown(t),/^\d$/.test(t.key)){const n=P.getParsedTime();n&&(r.value=null,g.value=n)}}function T(t){const o=(t==="first"?m:P).getParsedTime();o&&(r.value=null,t==="first"?h.value=o:a.range&&(g.value=o)),t==="first"?m.setFromTime(h.value):a.range&&P.setFromTime(g.value)}return(t,n)=>(e.openBlock(),e.createElementBlock("div",Z,[a.range?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["timepicker-shell__input",{"timepicker-shell__input--error":r.value}])},[e.createElementVNode("input",{type:"text",class:"timepicker-field",value:e.unref(V),placeholder:k.value,style:e.normalizeStyle({width:x.value}),onFocus:n[4]||(n[4]=o=>l.value=!0),onKeydown:I,onInput:n[5]||(n[5]=(...o)=>e.unref(m).handleInput&&e.unref(m).handleInput(...o)),onPaste:n[6]||(n[6]=(...o)=>e.unref(m).handlePaste&&e.unref(m).handlePaste(...o)),onBlur:n[7]||(n[7]=o=>T("first"))},null,44,te),n[16]||(n[16]=e.createElementVNode("span",{class:"timepicker-separator"},"–",-1)),e.createElementVNode("input",{ref_key:"secondInputRef",ref:b,type:"text",class:"timepicker-field",value:e.unref(H),placeholder:k.value,style:e.normalizeStyle({width:x.value}),onFocus:n[8]||(n[8]=o=>v.value=!0),onKeydown:B,onInput:n[9]||(n[9]=(...o)=>e.unref(P).handleInput&&e.unref(P).handleInput(...o)),onPaste:n[10]||(n[10]=(...o)=>e.unref(P).handlePaste&&e.unref(P).handlePaste(...o)),onBlur:n[11]||(n[11]=o=>T("second"))},null,44,ne)],2)):(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["timepicker-shell__input",{"timepicker-shell__input--error":r.value}])},[e.createElementVNode("input",{type:"text",class:"timepicker-field",value:e.unref(V),placeholder:k.value,style:e.normalizeStyle({width:x.value}),onFocus:n[0]||(n[0]=o=>l.value=!0),onKeydown:I,onInput:n[1]||(n[1]=(...o)=>e.unref(m).handleInput&&e.unref(m).handleInput(...o)),onPaste:n[2]||(n[2]=(...o)=>e.unref(m).handlePaste&&e.unref(m).handlePaste(...o)),onBlur:n[3]||(n[3]=o=>T("first"))},null,44,ee)],2)),e.createElementVNode("div",null,[e.createVNode(G,{open:l.value,"onUpdate:open":n[12]||(n[12]=o=>l.value=o),initTime:h.value,"onUpdate:initTime":n[13]||(n[13]=o=>h.value=o),format:a.format,"hour-step":a.hourStep,"minute-step":a.minuteStep,"second-step":a.secondStep},null,8,["open","initTime","format","hour-step","minute-step","second-step"]),a.range?(e.openBlock(),e.createBlock(G,{key:0,open:v.value,"onUpdate:open":n[14]||(n[14]=o=>v.value=o),initTime:g.value,"onUpdate:initTime":n[15]||(n[15]=o=>g.value=o),format:a.format,"hour-step":a.hourStep,"minute-step":a.minuteStep,"second-step":a.secondStep},null,8,["open","initTime","format","hour-step","minute-step","second-step"])):e.createCommentVNode("",!0)])]))}});E.TimePicker=oe,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(E,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(E=typeof globalThis<"u"?globalThis:E||self,e(E.VueTimepicker={},E.Vue))})(this,(function(E,e){"use strict";const q={class:"timepicker-dropdown"},W=["tabindex","onClick","onMousemove"],H=e.defineComponent({__name:"TimeColumn",props:{items:{},activeIndex:{}},emits:["update:activeIndex","select"],setup(s,{emit:i}){const l=s,a=i,f=e.ref(null);function r(){e.nextTick(()=>{const h=f.value;if(!h)return;const g=h.querySelector(".timepicker-option--active");if(g){const k=h.clientHeight,x=g.offsetTop,m=g.offsetHeight;h.scrollTop=x-k/2+m/2}})}e.onMounted(r),e.watch(()=>l.activeIndex,r);function v(h){a("update:activeIndex",h),a("select",l.items[h]?.value)}const d=e.ref(l.activeIndex??0);return(h,g)=>(e.openBlock(),e.createElementBlock("div",q,[e.createElementVNode("div",{ref_key:"menu",ref:f,class:"timepicker-dropdown__panel",role:"listbox",tabindex:"-1"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.items,(k,x)=>(e.openBlock(),e.createElementBlock("div",{key:k.key,class:e.normalizeClass(["timepicker-option",{"timepicker-option--active":x===h.activeIndex,"timepicker-option--disabled":k.disabled,"timepicker-option--focused":x===d.value}]),role:"option",tabindex:k.disabled?-1:0,onClick:m=>!k.disabled&&v(x),onMousemove:m=>!k.disabled&&(d.value=x)},e.toDisplayString(k.text),43,W))),128))],512)]))}});function _(s){return/(a|A|p|P)/.test(s)}function J(s){return/(p|P)/.test(s)}function N(s){return/k{1,2}/.test(s)}function D(s,i){if(!s)return{h:0,m:0,s:0};const l=s.match(/\d+/g)||[];let a=l[0]!==void 0?+l[0]:0;const f=+l[1]||0,r=+l[2]||0;return{h:a,m:f,s:r}}function Q(s){const i=s%12;return i===0?12:i}function U(s,i){return i?s%12+12:s%12}function X(s){return/(s|ss)/.test(s)}function L(s,i){let{h:l,m:a,s:f}=i;const r=_(s),v=l>=12?"PM":"AM";r&&(l=Q(l));const d=l===0?24:l,h={HH:String(l).padStart(2,"0"),H:String(l),hh:String(l).padStart(2,"0"),h:String(l),kk:String(d).padStart(2,"0"),k:String(d),mm:String(a).padStart(2,"0"),m:String(a),ss:String(f).padStart(2,"0"),s:String(f),A:v,a:v.toLowerCase(),P:v,p:v.toLowerCase()};return s.replace(/HH|hh|kk|mm|ss|H|h|k|m|s|A|a|P|p/g,g=>h[g]??g)}const z=e.defineComponent({__name:"TimeSelection",props:{open:{type:Boolean},initTime:{},format:{},hourStep:{},minuteStep:{},secondStep:{}},emits:["update:initTime","open","close","update:open"],setup(s,{emit:i}){const l=e.computed(()=>_(r.format)),a=e.computed(()=>X(r.format)),f=e.computed(()=>N(r.format)),r=s,v=i,d=e.computed({get:()=>r.open??!1,set:c=>{const y=r.open??!1;c!==y&&(v("update:open",c),v(c?"open":"close"))}}),h=e.ref(null);function g(c){if(!d.value)return;const y=c.target;h.value&&!h.value.contains(y)&&(d.value=!1)}e.onMounted(()=>document.addEventListener("mousedown",g)),e.onBeforeUnmount(()=>document.removeEventListener("mousedown",g));function k(c){c.key==="Escape"&&d.value&&(d.value=!1)}e.onMounted(()=>document.addEventListener("keydown",k)),e.onBeforeUnmount(()=>document.removeEventListener("keydown",k));const x=e.ref(Math.floor(r.initTime.h/r.hourStep)||0),m=e.ref(Math.floor(r.initTime.m/r.minuteStep)||0),V=e.ref(Math.floor(r.initTime.s/r.secondStep)||0);e.watch(()=>r.initTime,c=>{const y=Math.max(1,r.hourStep),M=Math.max(1,r.minuteStep),w=Math.max(1,r.secondStep);let P=c.h;l.value?(I.value=c.h>=12?1:0,P=c.h%12):f.value&&c.h===0&&(P=24),x.value=Math.floor(P/y),m.value=Math.floor(c.m/M),V.value=Math.floor(c.s/w)});function A(c,y){const M=[];for(let w=0;w<c;w+=Math.max(1,y))M.push({key:w,value:w,text:String(w).padStart(2,"0")});return M}function B(c,y){const M=Math.max(1,y),w=[];for(let P=0;P<12;P+=M){const ie=P===0?12:P,O=c?P===0?12:P+12:P;w.push({key:O,value:O,text:String(ie).padStart(2,"0")})}return w}function b(c){const y=Math.max(1,c),M=[];for(let w=0;w<24;w+=y){const P=w===0?24:w;M.push({key:w,value:w,text:String(P).padStart(2,"0")})}return M}const I=e.ref(J(r.format)?1:0),$=e.computed(()=>{if(!l.value)return f.value?b(r.hourStep):A(24,r.hourStep);const c=I.value===1;return B(c,r.hourStep)}),T=e.computed(()=>A(60,r.minuteStep)),t=e.computed(()=>A(60,r.secondStep)),n=e.computed(()=>/\s[ap]$/.test(r.format)),o=e.computed(()=>{const c=n.value?"am":"AM",y=n.value?"pm":"PM";return[{key:"AM",value:"AM",text:c},{key:"PM",value:"PM",text:y}]}),p=e.computed(()=>I.value===1?"PM":"AM"),u=e.computed(()=>{const c=Number($.value[x.value]?.value??0);return l.value?p.value==="PM"?U(c,!0):U(c,!1):f.value&&c===24?0:c}),S=e.computed(()=>Number(T.value[m.value]?.value??0)),F=e.computed(()=>Number(t.value[V.value]?.value??0));function re(c){!a.value&&!l.value&&K()}function se(c){l.value||K()}function le(c){K()}function K(){d.value=!1}return e.watch([u,S,F],([c,y,M])=>{v("update:initTime",{h:c,m:y,s:M})},{immediate:!0}),(c,y)=>d.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"vtp-cols",ref_key:"root",ref:h},[e.createVNode(H,{activeIndex:x.value,"onUpdate:activeIndex":y[0]||(y[0]=M=>x.value=M),items:$.value,label:"Hours"},null,8,["activeIndex","items"]),e.createVNode(H,{activeIndex:m.value,"onUpdate:activeIndex":y[1]||(y[1]=M=>m.value=M),items:T.value,label:"Minutes",onSelect:re},null,8,["activeIndex","items"]),a.value?(e.openBlock(),e.createBlock(H,{key:0,activeIndex:V.value,"onUpdate:activeIndex":y[2]||(y[2]=M=>V.value=M),items:t.value,label:"Seconds",onSelect:se},null,8,["activeIndex","items"])):e.createCommentVNode("",!0),l.value?(e.openBlock(),e.createBlock(H,{key:1,activeIndex:I.value,"onUpdate:activeIndex":y[3]||(y[3]=M=>I.value=M),items:o.value,label:"AM/PM",onSelect:le},null,8,["activeIndex","items"])):e.createCommentVNode("",!0)],512)):e.createCommentVNode("",!0)}}),G=/^(HH|H|hh|h|kk|k):(mm|m)(?::(ss|s))?(?:\s*(A|a|P|p))?$/,R=/^([01]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?$/,C=typeof __DEV__<"u"?__DEV__:typeof process<"u"&&process.env&&process.env.NODE_ENV!=="production",Y={modelValue:{type:[String,Array],default:void 0,validator:s=>{let i;return Array.isArray(s)?i=s.length===2&&s.every(l=>R.test(l)):i=s==null||R.test(s),!i&&C&&console.error(`[VueTimepicker] \`modelValue\` is wrong. Received: ${s}`),i}},range:{type:Boolean,default:!1},hourStep:{type:Number,default:1},minuteStep:{type:Number,default:1},secondStep:{type:Number,default:1},format:{type:String,default:"HH:mm",validator:s=>{const i=G.test(s);return!i&&C&&console.error(`[VueTimepicker] \`format\` format is wrong. Received: ${s}`),i}},size:{type:String,default:"md",validator:s=>{const i=s==="sm"||s==="md"||s==="lg";return!i&&C&&console.error(`[VueTimepicker] \`size\` is wrong. Received: ${s}`),i}}};function Z(s){const i=G.exec(s);if(!i)throw new Error(`[useTimeMask] Invalid format: ${s}`);const[,l,a,f,r]=i,v=[],d=!!r,h=/^k{1,2}$/.test(l);let g=0,k=23;return d?(g=1,k=12):h&&(g=1,k=24),v.push({token:l,min:g,max:k}),v.push({token:a,min:0,max:59}),f&&v.push({token:f,min:0,max:59}),{digitGroups:v,hasAmPm:!!r,ampmLowercase:r==="a"||r==="p"}}function j(s){const i=e.computed(()=>Z(s.value)),l=e.computed(()=>i.value.digitGroups.length*2),a=e.ref([]),f=e.ref("AM"),r=e.ref("");function v(){const{digitGroups:t,hasAmPm:n}=i.value;let o="",p=0;for(let u=0;u<t.length;u++){for(let S=0;S<2;S++)p<a.value.length&&(o+=String(a.value[p]),p++);p===(u+1)*2&&u<t.length-1&&(o+=":")}if(n&&p>=l.value){const u=i.value.ampmLowercase?f.value.toLowerCase():f.value;o+=" "+u}return o}function d(t){const n=t*2;if(a.value.length<n+2)return;const o=a.value[n]*10+a.value[n+1],{min:p,max:u}=i.value.digitGroups[t],S=Math.max(p,Math.min(u,o));S!==o&&(a.value[n]=Math.floor(S/10),a.value[n+1]=S%10)}function h(){for(let t=0;t<i.value.digitGroups.length;t++)d(t)}function g(t){const n=v();let o=0;for(let p=0;p<Math.min(t,n.length);p++)/\d/.test(n[p])&&o++;return o}function k(t){return t+Math.floor(t/2)}function x(t,n){if(t>=l.value)return l.value;const o=[...a.value];o[t]=n,a.value=o;const p=Math.floor(t/2);return d(p),Math.min(t+1,l.value)}function m(t,n){const o=v();r.value=o,t.value=o;const p=n!==void 0?Math.min(k(n),o.length):o.length;t.selectionStart=t.selectionEnd=p,e.nextTick(()=>{document.activeElement===t&&(t.selectionStart=t.selectionEnd=p)})}function V(t){const n=t.key,o=t.target;if(["Tab","Escape","ArrowLeft","ArrowRight","Home","End"].includes(n)||t.metaKey||t.ctrlKey)return;t.preventDefault();const p=o.selectionStart??0,u=g(p);if(n==="Backspace"){u>0&&m(o,u-1);return}if(n!=="Delete"){if(i.value.hasAmPm){const S=n.toLowerCase();if(S==="a"){f.value="AM",m(o,u);return}if(S==="p"){f.value="PM",m(o,u);return}}if(/^\d$/.test(n)){const S=x(u,+n);m(o,S);return}}}function A(t){const n=t.target,o=n.value.replace(/\D/g,"").split("").map(Number).slice(0,l.value);a.value=o,h(),i.value.hasAmPm&&(/p/i.test(n.value)?f.value="PM":/a/i.test(n.value)&&(f.value="AM")),m(n)}function B(t){t.preventDefault();const n=t.clipboardData?.getData("text")??"",o=t.target,p=o.selectionStart??0,u=n.replace(/\D/g,"").split("").map(Number);let S=g(p);for(const F of u){if(S>=l.value)break;S=x(S,F)}i.value.hasAmPm&&(/p\.?m\.?/i.test(n)?f.value="PM":/a\.?m\.?/i.test(n)&&(f.value="AM")),m(o,S)}function b(t){const{digitGroups:n,hasAmPm:o}=i.value,p=[];let u=t.h;o?(f.value=t.h>=12?"PM":"AM",u=t.h%12,u===0&&(u=12)):N(s.value)&&(u=t.h===0?24:t.h),p.push(Math.floor(u/10),u%10),p.push(Math.floor(t.m/10),t.m%10),n.length>2&&p.push(Math.floor(t.s/10),t.s%10),a.value=p,r.value=v()}function I(){if(a.value.length<l.value)return null;const t=[];for(let u=0;u<i.value.digitGroups.length;u++){const S=u*2;t.push(a.value[S]*10+a.value[S+1])}let n=t[0];const o=t[1],p=t[2]??0;return i.value.hasAmPm&&(n=f.value==="PM"?n===12?12:n+12:n===12?0:n),N(s.value)&&n===24&&(n=0),{h:n,m:o,s:p}}const $=e.computed(()=>a.value.length>=l.value),T=e.computed(()=>i.value.ampmLowercase);return{inputValue:r,handleKeydown:V,handleInput:A,handlePaste:B,setFromTime:b,getParsedTime:I,isComplete:$,totalDigits:l,displayPosToDigitIndex:g,ampm:f,ampmLowercase:T}}const ee=["data-size"],te=["value","placeholder"],ne=["value","placeholder"],oe=["value","placeholder"],ae=e.defineComponent({__name:"TimePicker",props:Y,emits:["update:modelValue","open","close","error"],setup(s,{emit:i}){const l=e.ref(null),a=s,f=i,r=e.ref(!1),v=e.ref(!1);e.watch(r,t=>{t&&(v.value=!1)}),e.watch(v,t=>{t&&(r.value=!1)});const d=e.computed({get(){if(Array.isArray(a.modelValue)){const[t,n]=a.modelValue;return[D(t,a.format),D(n,a.format)]}else return D(a.modelValue,a.format)},set(t){Array.isArray(t)?f("update:modelValue",[L("HH:mm:ss",t[0]),L("HH:mm:ss",t[1])]):f("update:modelValue",L("HH:mm:ss",t))}}),h=e.computed({get(){return Array.isArray(d.value)?d.value[0]:d.value},set(t){Array.isArray(d.value)?d.value=[t,d.value[1]]:d.value=t}}),g=e.computed({get(){return Array.isArray(d.value)?d.value[1]:d.value},set(t){Array.isArray(d.value)&&(d.value=[d.value[0],t])}});e.computed(()=>{if(!a.modelValue)return"—";const t=n=>L(a.format,n);return a.range?`${t(h.value)} → ${t(g.value)}`:t(h.value)}),e.watch(()=>a.range,t=>{if(t){if(!Array.isArray(a.modelValue))throw new RangeError(`Model value must be an array for range selection: ${a.modelValue}`)}else if(Array.isArray(a.modelValue))throw new RangeError(`Model value must be a single string for single time selection: ${a.modelValue}`)},{immediate:!0});const k=e.computed(()=>a.format??"HH:mm:ss"),x=e.computed(()=>{let t=k.value.length;return/[AaPp]$/.test(k.value)&&(t+=1),`${Math.min(12,Math.max(4,t))}ch`}),m=j(k),V=m.inputValue,A=j(k),B=A.inputValue;e.watch(()=>[h.value,k.value],([t])=>{m.setFromTime(t)},{immediate:!0}),e.watch(()=>[g.value,k.value,a.range],([t,,n])=>{if(!n){A.setFromTime({h:0,m:0,s:0});return}A.setFromTime(t)},{immediate:!0});const b=e.ref(null);function I(t){if(t.key==="Enter"){t.preventDefault(),T("first");return}/^\d$/.test(t.key)&&(r.value=!1,v.value=!1);const n=t.target,o=m.displayPosToDigitIndex(n.selectionStart??0),p=/^\d$/.test(t.key)&&o>=m.totalDigits.value-1;if(m.handleKeydown(t),/^\d$/.test(t.key)){const u=m.getParsedTime();u&&(l.value=null,h.value=u)}a.range&&p&&b.value&&(T("first"),e.nextTick(()=>{const u=b.value;u&&(u.focus(),u.selectionStart=u.selectionEnd=0)}))}function $(t){if(t.key==="Enter"){t.preventDefault(),T("second");return}if(/^\d$/.test(t.key)&&(r.value=!1,v.value=!1),A.handleKeydown(t),/^\d$/.test(t.key)){const n=A.getParsedTime();n&&(l.value=null,g.value=n)}}function T(t){const o=(t==="first"?m:A).getParsedTime();o&&(l.value=null,t==="first"?h.value=o:a.range&&(g.value=o)),t==="first"?m.setFromTime(h.value):a.range&&A.setFromTime(g.value)}return(t,n)=>(e.openBlock(),e.createElementBlock("div",{class:"timepicker-shell","data-size":a.size},[a.range?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["timepicker-shell__input",{"timepicker-shell__input--error":l.value}])},[e.createElementVNode("input",{type:"text",class:"timepicker-field",value:e.unref(V),placeholder:k.value,style:e.normalizeStyle({width:x.value}),onFocus:n[4]||(n[4]=o=>r.value=!0),onKeydown:I,onInput:n[5]||(n[5]=(...o)=>e.unref(m).handleInput&&e.unref(m).handleInput(...o)),onPaste:n[6]||(n[6]=(...o)=>e.unref(m).handlePaste&&e.unref(m).handlePaste(...o)),onBlur:n[7]||(n[7]=o=>T("first"))},null,44,ne),n[16]||(n[16]=e.createElementVNode("span",{class:"timepicker-separator"},"–",-1)),e.createElementVNode("input",{ref_key:"secondInputRef",ref:b,type:"text",class:"timepicker-field",value:e.unref(B),placeholder:k.value,style:e.normalizeStyle({width:x.value}),onFocus:n[8]||(n[8]=o=>v.value=!0),onKeydown:$,onInput:n[9]||(n[9]=(...o)=>e.unref(A).handleInput&&e.unref(A).handleInput(...o)),onPaste:n[10]||(n[10]=(...o)=>e.unref(A).handlePaste&&e.unref(A).handlePaste(...o)),onBlur:n[11]||(n[11]=o=>T("second"))},null,44,oe)],2)):(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["timepicker-shell__input",{"timepicker-shell__input--error":l.value}])},[e.createElementVNode("input",{type:"text",class:"timepicker-field",value:e.unref(V),placeholder:k.value,style:e.normalizeStyle({width:x.value}),onFocus:n[0]||(n[0]=o=>r.value=!0),onKeydown:I,onInput:n[1]||(n[1]=(...o)=>e.unref(m).handleInput&&e.unref(m).handleInput(...o)),onPaste:n[2]||(n[2]=(...o)=>e.unref(m).handlePaste&&e.unref(m).handlePaste(...o)),onBlur:n[3]||(n[3]=o=>T("first"))},null,44,te)],2)),e.createElementVNode("div",null,[e.createVNode(z,{open:r.value,"onUpdate:open":n[12]||(n[12]=o=>r.value=o),initTime:h.value,"onUpdate:initTime":n[13]||(n[13]=o=>h.value=o),format:a.format,"hour-step":a.hourStep,"minute-step":a.minuteStep,"second-step":a.secondStep},null,8,["open","initTime","format","hour-step","minute-step","second-step"]),a.range?(e.openBlock(),e.createBlock(z,{key:0,open:v.value,"onUpdate:open":n[14]||(n[14]=o=>v.value=o),initTime:g.value,"onUpdate:initTime":n[15]||(n[15]=o=>g.value=o),format:a.format,"hour-step":a.hourStep,"minute-step":a.minuteStep,"second-step":a.secondStep},null,8,["open","initTime","format","hour-step","minute-step","second-step"])):e.createCommentVNode("",!0)])],8,ee))}});E.TimePicker=ae,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manik02/vue3-timepicker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A flexible Vue 3 timepicker component with multiple format support, range selection, and fully customisable styling",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Manos Savvides",
|