@component-hook/picker 1.1.5 → 1.2.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.
@@ -1,95 +1,95 @@
1
1
  import "./index.css";
2
- import { ref as Y, readonly as Z, isRef as j, defineComponent as E, toRef as re, createElementBlock as P, openBlock as C, unref as T, createElementVNode as I, normalizeStyle as q, Fragment as R, renderList as ue, toDisplayString as A, watch as ce, createBlock as L, Teleport as me, createVNode as J, Transition as Q, withCtx as z, withDirectives as W, vShow as ee, renderSlot as _, computed as O, watchEffect as de, withModifiers as fe, nextTick as pe } from "vue";
3
- const ve = Array.isArray;
4
- function he(e, a) {
5
- if (ae(e)) return "multiple";
6
- const [n] = e;
7
- return n?.[a.children] ? "cascade" : "single";
2
+ import { ref as R, readonly as Z, isRef as j, defineComponent as L, toRef as re, createElementBlock as Y, openBlock as k, unref as v, withModifiers as oe, createElementVNode as C, normalizeStyle as q, Fragment as U, renderList as le, toDisplayString as ie, mergeModels as V, useModel as $, useTemplateRef as ce, computed as I, watchEffect as me, renderSlot as J, createBlock as B, nextTick as fe } from "vue";
3
+ const de = Array.isArray;
4
+ function pe(e, s) {
5
+ if (ue(e)) return "multiple";
6
+ const [f] = e;
7
+ return f?.[s.children] ? "cascade" : "single";
8
8
  }
9
- function Te(e) {
9
+ function ve(e) {
10
10
  return {
11
11
  children: e?.children || "children",
12
12
  label: e?.label || "label",
13
13
  value: e?.value || "value"
14
14
  };
15
15
  }
16
- function ge(e, a, n) {
17
- if (ae(e)) return [];
18
- const u = [];
19
- let o = e, i = 0;
20
- for (; o; ) {
21
- const d = a[i];
22
- let f = se(o, d, n);
23
- f === -1 && (f = 0), u.push(o), i += 1, o = o[f]?.[n.children];
16
+ function he(e, s, f) {
17
+ if (ue(e)) return [];
18
+ const o = [];
19
+ let u = e, i = 0;
20
+ for (; u; ) {
21
+ const h = s[i];
22
+ let m = se(u, h, f);
23
+ m === -1 && (m = 0), o.push(u), i += 1, u = u[m]?.[f.children];
24
24
  }
25
- return u;
25
+ return o;
26
26
  }
27
- function ke(e, a, n, u) {
28
- const o = [...n];
29
- let i = e, d = a + 1;
30
- for (; i?.[u.children]; ) {
31
- const f = i[u.children][0];
32
- o[d] = f.value, i = f, d += 1;
27
+ function ge(e, s, f, o) {
28
+ const u = [...f];
29
+ let i = e, h = s + 1;
30
+ for (; i?.[o.children]; ) {
31
+ const m = i[o.children][0];
32
+ u[h] = m.value, i = m, h += 1;
33
33
  }
34
- return o;
34
+ return u;
35
35
  }
36
- function se(e, a, n) {
37
- return e.findIndex((u) => u?.[n.value] === a);
36
+ function se(e, s, f) {
37
+ return e.findIndex((o) => o?.[f.value] === s);
38
38
  }
39
- function ae(e) {
40
- const [a] = e;
41
- return ve(a);
39
+ function ue(e) {
40
+ const [s] = e;
41
+ return de(s);
42
42
  }
43
- function Me(e, a) {
44
- return e > a ? "horizontal" : a > e ? "vertical" : "";
43
+ function Te(e, s) {
44
+ return e > s ? "horizontal" : s > e ? "vertical" : "";
45
45
  }
46
- function F(e, a, n) {
47
- const u = [];
48
- for (let o = e; o <= a; o++) {
49
- const i = n(`${o}`);
50
- u.push({ label: i, value: o });
46
+ function b(e, s, f) {
47
+ const o = [];
48
+ for (let u = e; u <= s; u++) {
49
+ const i = f(`${u}`);
50
+ o.push({ label: i, value: u });
51
51
  }
52
- return u;
52
+ return o;
53
53
  }
54
- function te(e, a) {
55
- return e === a.getFullYear();
54
+ function Q(e, s) {
55
+ return e === s.getFullYear();
56
56
  }
57
- function ne(e, a) {
58
- return e === a.getFullYear();
57
+ function W(e, s) {
58
+ return e === s.getFullYear();
59
59
  }
60
- function Ve(e, a) {
61
- return e === a.getMonth() + 1;
60
+ function Me(e, s) {
61
+ return e === s.getMonth() + 1;
62
62
  }
63
- function ye(e, a) {
64
- return e === a.getMonth() + 1;
63
+ function xe(e, s) {
64
+ return e === s.getMonth() + 1;
65
65
  }
66
- function we(e, a) {
67
- return new Date(e, a, 0).getDate();
66
+ function De(e, s) {
67
+ return new Date(e, s, 0).getDate();
68
68
  }
69
- function xe(e, a, n) {
70
- const u = /* @__PURE__ */ new Date(), o = Date.now(), i = e.getTime(), d = a.getTime(), f = o >= i && o <= d;
71
- return n === "year" ? f ? u.getFullYear() : e.getFullYear() : n === "month" ? f ? u.getMonth() + 1 : e.getMonth() + 1 : f ? u.getDate() : e.getDate();
69
+ function _(e, s, f) {
70
+ const o = /* @__PURE__ */ new Date(), u = Date.now(), i = e.getTime(), h = s.getTime(), m = u >= i && u <= h;
71
+ return f === "year" ? m ? o.getFullYear() : e.getFullYear() : f === "month" ? m ? o.getMonth() + 1 : e.getMonth() + 1 : m ? o.getDate() : e.getDate();
72
72
  }
73
- function H(e) {
73
+ function N(e) {
74
74
  return e;
75
75
  }
76
- function De(e) {
76
+ function ye(e) {
77
77
  return /^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/.test(e);
78
78
  }
79
- function oe(e) {
80
- if (!De(e)) return null;
81
- const [a, n, u] = e.split(":");
82
- return { hour: Number(a), minute: Number(n), second: Number(u) };
79
+ function ee(e) {
80
+ if (!ye(e)) return null;
81
+ const [s, f, o] = e.split(":");
82
+ return { hour: Number(s), minute: Number(f), second: Number(o) };
83
83
  }
84
- function U(e) {
84
+ function H(e) {
85
85
  return e.padStart(2, "0");
86
86
  }
87
- function Se(e, a, n) {
88
- const u = Date.now(), { hour: o, minute: i, second: d } = e, { hour: f, minute: p, second: m } = a, M = (/* @__PURE__ */ new Date()).setHours(o, i, d), g = (/* @__PURE__ */ new Date()).setHours(f, p, m), w = u >= M && u <= g;
89
- return n === "hour" ? w ? (/* @__PURE__ */ new Date()).getHours() : o : n === "minute" ? w ? (/* @__PURE__ */ new Date()).getMinutes() : i : w ? (/* @__PURE__ */ new Date()).getSeconds() : d;
87
+ function te(e, s, f) {
88
+ const o = Date.now(), { hour: u, minute: i, second: h } = e, { hour: m, minute: d, second: p } = s, g = (/* @__PURE__ */ new Date()).setHours(u, i, h), M = (/* @__PURE__ */ new Date()).setHours(m, d, p), r = o >= g && o <= M;
89
+ return f === "hour" ? r ? (/* @__PURE__ */ new Date()).getHours() : u : f === "minute" ? r ? (/* @__PURE__ */ new Date()).getMinutes() : i : r ? (/* @__PURE__ */ new Date()).getSeconds() : h;
90
90
  }
91
- const be = 16, N = 48, Ce = 0.52, le = 150, X = 300, Ie = 15, Ye = 8e-3, Oe = "Select Date", Pe = ["year", "month", "day"], Fe = "Select Time", Le = ["hour", "minute", "second"];
92
- function Ee() {
91
+ const ke = 16, F = 48, Se = 0.52, ne = 150, X = 300, Ye = 15, Ie = 8e-3, Oe = ["year", "month", "day"], be = ["hour", "minute", "second"];
92
+ function Ve() {
93
93
  const e = {
94
94
  startX: 0,
95
95
  startY: 0,
@@ -98,88 +98,88 @@ function Ee() {
98
98
  offsetX: 0,
99
99
  offsetY: 0
100
100
  };
101
- let a = "";
102
- const n = () => a === "vertical", u = () => a === "horizontal";
103
- function o() {
104
- e.deltaX = 0, e.deltaY = 0, e.offsetX = 0, e.offsetY = 0, a = "";
101
+ let s = "";
102
+ const f = () => s === "vertical", o = () => s === "horizontal";
103
+ function u() {
104
+ e.deltaX = 0, e.deltaY = 0, e.offsetX = 0, e.offsetY = 0, s = "";
105
105
  }
106
- function i(p) {
107
- const m = "touches" in p ? p.touches[0] : p;
108
- o(), e.startX = m.clientX, e.startY = m.clientY;
106
+ function i(d) {
107
+ const p = "touches" in d ? d.touches[0] : d;
108
+ u(), e.startX = p.clientX, e.startY = p.clientY;
109
109
  }
110
- function d(p) {
110
+ function h(d) {
111
111
  if (!e.startX || !e.startY) return !0;
112
- const m = "touches" in p ? p.touches[0] : p;
113
- e.deltaX = Math.max(m.clientX, 0) - e.startX, e.deltaY = m.clientY - e.startY, e.offsetX = Math.abs(e.deltaX), e.offsetY = Math.abs(e.deltaY);
114
- const M = 10;
115
- (!a || e.offsetX < M && e.offsetY < M) && (a = Me(e.offsetX, e.offsetY));
112
+ const p = "touches" in d ? d.touches[0] : d;
113
+ e.deltaX = Math.max(p.clientX, 0) - e.startX, e.deltaY = p.clientY - e.startY, e.offsetX = Math.abs(e.deltaX), e.offsetY = Math.abs(e.deltaY);
114
+ const g = 10;
115
+ (!s || e.offsetX < g && e.offsetY < g) && (s = Te(e.offsetX, e.offsetY));
116
116
  }
117
- function f() {
117
+ function m() {
118
118
  e.startX = 0, e.startY = 0;
119
119
  }
120
120
  return {
121
121
  pointer: e,
122
- move: d,
122
+ move: h,
123
123
  start: i,
124
- stop: f,
125
- reset: o,
126
- isVertical: n,
127
- isHorizontal: u
124
+ stop: m,
125
+ reset: u,
126
+ isVertical: f,
127
+ isHorizontal: o
128
128
  };
129
129
  }
130
- function Be({ column: e, onChange: a }) {
131
- const u = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) / be, o = Y(0), i = Y(0), { pointer: d, start: f, move: p, stop: m } = Ee();
132
- let M = 0, g = 0, w = 0, V = !1, x = null;
133
- function y(v) {
134
- f(v), V = !0, i.value = 0, g = Date.now(), M = o.value, w = M, x = null;
130
+ function Ce({ column: e, onChange: s }) {
131
+ const o = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) / ke, u = R(0), i = R(0), { pointer: h, start: m, move: d, stop: p } = Ve();
132
+ let g = 0, M = 0, r = 0, l = !1, t = null;
133
+ function n(T) {
134
+ m(T), l = !0, i.value = 0, M = Date.now(), g = u.value, r = g, t = null;
135
135
  }
136
- function s(v) {
137
- if (p(v)) return;
138
- const b = j(e) ? e.value.length : e.length, B = M + d.deltaY, $ = D((b - 1) * -N), G = Math.min(Math.max(B, $), 0), K = Date.now();
139
- o.value = G, !(K - g <= X) && (g = K, w = G);
136
+ function a(T) {
137
+ if (d(T)) return;
138
+ const y = j(e) ? e.value.length : e.length, E = g + h.deltaY, A = P((y - 1) * -F), G = Math.min(Math.max(E, A), 0), K = Date.now();
139
+ u.value = G, !(K - M <= X) && (M = K, r = G);
140
140
  }
141
- function r() {
142
- m();
143
- const v = o.value - w, k = Date.now() - g;
144
- if (k < X && Math.abs(v) > Ie) {
145
- t(v, k);
141
+ function c() {
142
+ p();
143
+ const T = u.value - r, x = Date.now() - M;
144
+ if (x < X && Math.abs(T) > Ye) {
145
+ D(T, x);
146
146
  return;
147
147
  }
148
- const b = h(o.value);
149
- i.value = le, c(b), V = !1;
148
+ const y = w(u.value);
149
+ i.value = ne, O(y), l = !1;
150
150
  }
151
- function t(v, k) {
152
- const b = Math.abs(v / k), B = o.value + b / Ye * (v < 0 ? -1 : 1), $ = h(B);
153
- i.value = X, c($);
151
+ function D(T, x) {
152
+ const y = Math.abs(T / x), E = u.value + y / Ie * (T < 0 ? -1 : 1), A = w(E);
153
+ i.value = X, O(A);
154
154
  }
155
- function l() {
156
- i.value = 0, V = !1, x && (x(), x = null);
155
+ function S() {
156
+ i.value = 0, l = !1, t && (t(), t = null);
157
157
  }
158
- function c(v) {
159
- const k = -v * D(N), b = () => a?.(v);
160
- V && k !== o.value ? x = b : b(), o.value = k;
158
+ function O(T) {
159
+ const x = -T * P(F), y = () => s?.(T);
160
+ l && x !== u.value ? t = y : y(), u.value = x;
161
161
  }
162
- function h(v) {
163
- const k = j(e) ? e.value.length : e.length, b = Math.round(-v / D(N));
164
- return b < 0 ? 0 : b >= k ? k - 1 : b;
162
+ function w(T) {
163
+ const x = j(e) ? e.value.length : e.length, y = Math.round(-T / P(F));
164
+ return y < 0 ? 0 : y >= x ? x - 1 : y;
165
165
  }
166
- function D(v) {
167
- return v * u;
166
+ function P(T) {
167
+ return T * o;
168
168
  }
169
- function S(v, k = "auto") {
170
- V && k === "smooth" || (x = null, V = k === "smooth", i.value = k === "smooth" ? le : 0, c(v));
169
+ function z(T, x = "auto") {
170
+ l && x === "smooth" || (t = null, l = x === "smooth", i.value = x === "smooth" ? ne : 0, O(T));
171
171
  }
172
172
  return {
173
- offsetY: Z(o),
173
+ offsetY: Z(u),
174
174
  transitionDuration: Z(i),
175
- onPointerDown: y,
176
- onPointerMove: s,
177
- onPointerUp: r,
178
- stopInertialSliding: l,
179
- scrollToIndex: S
175
+ onPointerDown: n,
176
+ onPointerMove: a,
177
+ onPointerUp: c,
178
+ stopInertialSliding: S,
179
+ scrollToIndex: z
180
180
  };
181
181
  }
182
- const Ae = ["onClick"], Ne = /* @__PURE__ */ E({
182
+ const we = ["onClick"], Pe = /* @__PURE__ */ L({
183
183
  __name: "PickerColumn",
184
184
  props: {
185
185
  column: {},
@@ -187,379 +187,260 @@ const Ae = ["onClick"], Ne = /* @__PURE__ */ E({
187
187
  selectedIndex: { default: 0 }
188
188
  },
189
189
  emits: ["change"],
190
- setup(e, { expose: a, emit: n }) {
191
- const u = e, o = n, { offsetY: i, transitionDuration: d, onPointerDown: f, onPointerMove: p, onPointerUp: m, stopInertialSliding: M, scrollToIndex: g } = Be({
192
- column: re(u, "column"),
193
- onChange: w
190
+ setup(e, { expose: s, emit: f }) {
191
+ const o = e, u = f, { offsetY: i, transitionDuration: h, onPointerDown: m, onPointerMove: d, onPointerUp: p, stopInertialSliding: g, scrollToIndex: M } = Ce({
192
+ column: re(o, "column"),
193
+ onChange: r
194
194
  });
195
- function w(y) {
196
- y !== u.selectedIndex && o("change", y);
195
+ function r(n) {
196
+ n !== o.selectedIndex && u("change", n);
197
197
  }
198
- function V(y = u.selectedIndex, s) {
199
- g(y, s);
198
+ function l(n = o.selectedIndex, a) {
199
+ M(n, a);
200
200
  }
201
- function x(y) {
202
- y !== u.selectedIndex && V(y, "smooth");
201
+ function t(n) {
202
+ n !== o.selectedIndex && l(n, "smooth");
203
203
  }
204
- return a({ scrollToSelected: V }), (y, s) => (C(), P("div", {
204
+ return s({ scrollToSelected: l }), (n, a) => (k(), Y("div", {
205
205
  class: "chook-picker-column",
206
- onTouchstartPassive: s[1] || (s[1] = //@ts-ignore
207
- (...r) => T(f) && T(f)(...r)),
208
- onTouchmovePassive: s[2] || (s[2] = //@ts-ignore
209
- (...r) => T(p) && T(p)(...r)),
210
- onTouchendPassive: s[3] || (s[3] = //@ts-ignore
211
- (...r) => T(m) && T(m)(...r)),
212
- onTouchcancel: s[4] || (s[4] = //@ts-ignore
213
- (...r) => T(m) && T(m)(...r)),
214
- onMousedownPassive: s[5] || (s[5] = //@ts-ignore
215
- (...r) => T(f) && T(f)(...r)),
216
- onMousemovePassive: s[6] || (s[6] = //@ts-ignore
217
- (...r) => T(p) && T(p)(...r)),
218
- onMouseupPassive: s[7] || (s[7] = //@ts-ignore
219
- (...r) => T(m) && T(m)(...r))
206
+ "aria-label": "Picker column",
207
+ onTouchstartPassive: a[1] || (a[1] = //@ts-ignore
208
+ (...c) => v(m) && v(m)(...c)),
209
+ onTouchmove: a[2] || (a[2] = oe(
210
+ //@ts-ignore
211
+ (...c) => v(d) && v(d)(...c),
212
+ ["prevent"]
213
+ )),
214
+ onTouchendPassive: a[3] || (a[3] = //@ts-ignore
215
+ (...c) => v(p) && v(p)(...c)),
216
+ onTouchcancel: a[4] || (a[4] = //@ts-ignore
217
+ (...c) => v(p) && v(p)(...c)),
218
+ onMousedownPassive: a[5] || (a[5] = //@ts-ignore
219
+ (...c) => v(m) && v(m)(...c)),
220
+ onMousemovePassive: a[6] || (a[6] = //@ts-ignore
221
+ (...c) => v(d) && v(d)(...c)),
222
+ onMouseupPassive: a[7] || (a[7] = //@ts-ignore
223
+ (...c) => v(p) && v(p)(...c)),
224
+ onMouseleavePassive: a[8] || (a[8] = //@ts-ignore
225
+ (...c) => v(p) && v(p)(...c))
220
226
  }, [
221
- I("ul", {
227
+ C("ul", {
222
228
  style: q({
223
229
  overflowY: "hidden",
224
- transform: `translate3d(0, ${T(i)}px, 0)`,
225
- transitionDuration: `${T(d)}ms`,
226
- transitionProperty: T(d) ? "all" : "none"
230
+ transform: `translate3d(0, ${v(i)}px, 0)`,
231
+ transitionDuration: `${v(h)}ms`,
232
+ transitionProperty: v(h) ? "all" : "none"
227
233
  }),
228
- onTransitionend: s[0] || (s[0] = //@ts-ignore
229
- (...r) => T(M) && T(M)(...r))
234
+ onTransitionend: a[0] || (a[0] = //@ts-ignore
235
+ (...c) => v(g) && v(g)(...c))
230
236
  }, [
231
- (C(!0), P(R, null, ue(y.column, (r, t) => (C(), P("li", {
232
- key: r?.[y.fields.value],
237
+ (k(!0), Y(U, null, le(e.column, (c, D) => (k(), Y("li", {
238
+ key: c?.[e.fields.value],
233
239
  class: "chook-picker-column-item",
234
240
  role: "button",
235
241
  tabindex: "0",
236
- onClick: (l) => x(t)
242
+ onClick: (S) => t(D)
237
243
  }, [
238
- I("p", {
244
+ C("p", {
239
245
  class: "chook-picker-column-label",
240
246
  style: q({
241
- transform: `rotate3d(1, 0, 0, ${(t * T(N) + T(i)) * T(Ce)}deg)`
247
+ transform: `rotate3d(1, 0, 0, ${(D * v(F) + v(i)) * v(Se)}deg)`
242
248
  })
243
- }, A(r?.[y.fields.label]), 5)
244
- ], 8, Ae))), 128))
249
+ }, ie(c?.[e.fields.label]), 5)
250
+ ], 8, we))), 128))
245
251
  ], 36)
246
252
  ], 32));
247
253
  }
248
- }), $e = { class: "chook-picker-container" }, He = /* @__PURE__ */ E({
249
- __name: "Popup",
250
- props: {
251
- teleport: { default: "body" },
252
- modelValue: { type: Boolean }
253
- },
254
- emits: ["update:modelValue", "open", "close", "closed"],
255
- setup(e, { emit: a }) {
256
- const n = e, u = a;
257
- return ce(
258
- () => n.modelValue,
259
- (o) => {
260
- o ? (document.body.style.overflow = "hidden", u("open")) : (document.body.style.overflow = "", u("close"));
261
- },
262
- { immediate: !0 }
263
- ), (o, i) => (C(), L(me, { to: o.teleport }, [
264
- J(Q, { name: "chook-picker-fade" }, {
265
- default: z(() => [
266
- W(I("div", {
267
- class: "chook-picker-mask",
268
- onClick: i[0] || (i[0] = (d) => o.$emit("update:modelValue", !1))
269
- }, null, 512), [
270
- [ee, o.modelValue]
271
- ])
272
- ]),
273
- _: 1
274
- }),
275
- J(Q, {
276
- name: "chook-picker-slide",
277
- onAfterLeave: i[1] || (i[1] = (d) => o.$emit("closed"))
278
- }, {
279
- default: z(() => [
280
- W(I("div", $e, [
281
- _(o.$slots, "default")
282
- ], 512), [
283
- [ee, o.modelValue]
284
- ])
285
- ]),
286
- _: 3
287
- })
288
- ], 8, ["to"]));
289
- }
290
- }), Ue = { class: "chook-picker-header" }, Xe = { class: "chook-picker-title" }, Re = { class: "chook-picker-loading" }, ze = {
254
+ }), Fe = {
255
+ class: "chook-picker-container",
256
+ "aria-label": "Picker"
257
+ }, Le = { class: "chook-picker-loading" }, Ee = {
291
258
  key: 1,
292
259
  class: "chook-picker-columns"
293
- }, ie = /* @__PURE__ */ E({
260
+ }, ae = /* @__PURE__ */ L({
294
261
  __name: "Picker",
295
- props: {
296
- show: { type: Boolean },
297
- modelValue: {},
298
- title: {},
262
+ props: /* @__PURE__ */ V({
299
263
  columns: {},
300
- linkage: { type: Boolean },
301
264
  loading: { type: Boolean },
302
- teleport: {},
303
- confirmButtonText: { default: "Confirm" },
304
- cancelButtonText: { default: "Cancel" },
305
265
  columnsFieldNames: {}
306
- },
307
- emits: ["update:show", "update:modelValue", "confirm", "cancel", "open", "closed"],
308
- setup(e, { emit: a }) {
309
- const n = e, u = a, o = Y([]), i = Y([]), d = Y([]), f = Y(null), p = O({
310
- get: () => n.show,
311
- set: (t) => u("update:show", t)
312
- }), m = O(() => Te(n.columnsFieldNames)), M = O(() => he(n.columns, m.value)), g = O(() => {
313
- const { columns: t } = n;
314
- return M.value === "single" ? [t] : M.value === "multiple" ? t : ge(t, i.value, m.value);
266
+ }, {
267
+ modelValue: { default: [] },
268
+ modelModifiers: {}
269
+ }),
270
+ emits: /* @__PURE__ */ V(["change"], ["update:modelValue"]),
271
+ setup(e, { emit: s }) {
272
+ const f = e, o = s, u = $(e, "modelValue"), i = R([]), h = ce("columnsRef"), m = I(() => ve(f.columnsFieldNames)), d = I(() => pe(f.columns, m.value)), p = I(() => {
273
+ const { columns: r } = f;
274
+ return d.value === "single" ? [r] : d.value === "multiple" ? r : he(r, u.value, m.value);
315
275
  });
316
- function w(t, l) {
317
- const c = g.value[t], h = c[l]?.[m.value.value], D = i.value[t];
318
- if (h === D) return;
319
- const S = [...i.value];
320
- if (S[t] = h, M.value === "cascade") {
321
- const v = c[l];
322
- i.value = ke(v, t, S, m.value);
276
+ function g(r, l) {
277
+ const t = p.value[r], n = t[l]?.[m.value.value], a = u.value[r];
278
+ if (n === a) return;
279
+ const c = [...u.value];
280
+ if (c[r] = n, d.value === "cascade") {
281
+ const D = t[l];
282
+ u.value = ge(D, r, c, m.value);
323
283
  } else
324
- i.value = S;
325
- n.linkage && V();
326
- }
327
- function V() {
328
- u("update:modelValue", i.value), o.value = i.value;
329
- }
330
- function x() {
331
- u("update:show", !1);
332
- }
333
- async function y() {
334
- u("open"), await pe(), i.value = n.modelValue ? [...n.modelValue] : [...o.value];
335
- }
336
- function s() {
337
- n.linkage || V(), x(), u("confirm", i.value);
338
- }
339
- function r() {
340
- x(), u("cancel");
284
+ u.value = c;
285
+ fe(() => {
286
+ o("change", u.value);
287
+ });
341
288
  }
342
- return de(() => {
343
- const t = g.value.length, l = [];
344
- for (let c = 0; c < t; c++) {
345
- const h = g.value[c], D = i.value[c], S = se(h, D, m.value);
346
- if (S === -1) {
347
- const k = (d.value[c] ?? 0) >= h.length ? Math.max(h.length - 1, 0) : 0;
348
- i.value[c] = h[k]?.[m.value.value], l[c] = k;
289
+ function M() {
290
+ const r = p.value.length, l = [];
291
+ for (let t = 0; t < r; t++) {
292
+ const n = p.value[t], a = u.value[t], c = se(n, a, m.value);
293
+ if (c === -1) {
294
+ const S = (i.value[t] ?? 0) >= n.length ? Math.max(n.length - 1, 0) : 0;
295
+ u.value[t] = n[S]?.[m.value.value], l[t] = S;
349
296
  } else
350
- l[c] = S;
351
- l[c] !== d.value[c] && f.value?.[c].scrollToSelected(l[c]);
297
+ l[t] = c;
298
+ l[t] !== i.value[t] && h.value?.[t]?.scrollToSelected(l[t]);
352
299
  }
353
- d.value = l;
354
- }), (t, l) => (C(), L(He, {
355
- modelValue: p.value,
356
- "onUpdate:modelValue": l[1] || (l[1] = (c) => p.value = c),
357
- teleport: t.teleport,
358
- onOpen: y,
359
- onClosed: l[2] || (l[2] = (c) => t.$emit("closed"))
360
- }, {
361
- default: z(() => [
362
- I("div", Ue, [
363
- I("button", {
364
- class: "chook-picker-cancel",
365
- onClick: r
366
- }, A(t.cancelButtonText), 1),
367
- I("p", Xe, A(t.title), 1),
368
- I("button", {
369
- class: "chook-picker-confirm",
370
- onClick: s
371
- }, A(t.confirmButtonText), 1)
300
+ i.value = l;
301
+ }
302
+ return me(
303
+ () => {
304
+ M();
305
+ },
306
+ { flush: "post" }
307
+ ), (r, l) => (k(), Y("div", Fe, [
308
+ e.loading ? (k(), Y(U, { key: 0 }, [
309
+ C("div", Le, [
310
+ J(r.$slots, "loading")
372
311
  ]),
373
- t.loading ? (C(), P(R, { key: 0 }, [
374
- I("div", Re, [
375
- _(t.$slots, "loading")
376
- ]),
377
- l[3] || (l[3] = I("div", { class: "chook-picker-columns" }, null, -1))
378
- ], 64)) : t.columns.length ? (C(), P("div", {
379
- key: 2,
380
- class: "chook-picker-columns chook-picker-columns-backdrop",
381
- onTouchmove: l[0] || (l[0] = fe(() => {
382
- }, ["stop"]))
383
- }, [
384
- (C(!0), P(R, null, ue(g.value, (c, h) => (C(), L(Ne, {
385
- key: h,
386
- ref_for: !0,
387
- ref_key: "columnsRef",
388
- ref: f,
389
- column: c,
390
- fields: m.value,
391
- "selected-index": d.value[h],
392
- onChange: (D) => w(h, D)
393
- }, null, 8, ["column", "fields", "selected-index", "onChange"]))), 128)),
394
- l[4] || (l[4] = I("div", { class: "chook-picker-mask-backdrop" }, null, -1))
395
- ], 32)) : (C(), P("div", ze, [
396
- _(t.$slots, "empty")
397
- ]))
398
- ]),
399
- _: 3
400
- }, 8, ["modelValue", "teleport"]));
312
+ l[1] || (l[1] = C("div", { class: "chook-picker-columns" }, null, -1))
313
+ ], 64)) : e.columns.length ? (k(), Y("div", {
314
+ key: 2,
315
+ class: "chook-picker-columns chook-picker-columns-backdrop",
316
+ onTouchmove: l[0] || (l[0] = oe(() => {
317
+ }, ["stop"]))
318
+ }, [
319
+ (k(!0), Y(U, null, le(p.value, (t, n) => (k(), B(Pe, {
320
+ key: n,
321
+ ref_for: !0,
322
+ ref_key: "columnsRef",
323
+ ref: h,
324
+ column: t,
325
+ fields: m.value,
326
+ "selected-index": i.value[n],
327
+ onChange: (a) => g(n, a)
328
+ }, null, 8, ["column", "fields", "selected-index", "onChange"]))), 128)),
329
+ l[2] || (l[2] = C("div", { class: "chook-picker-mask-backdrop" }, null, -1))
330
+ ], 32)) : (k(), Y("div", Ee, [
331
+ J(r.$slots, "empty")
332
+ ]))
333
+ ]));
401
334
  }
402
- }), Ge = /* @__PURE__ */ E({
335
+ }), Ne = /* @__PURE__ */ L({
403
336
  __name: "DatePicker",
404
- props: {
405
- show: { type: Boolean },
406
- modelValue: {},
407
- title: { default: Oe },
408
- columnsType: { default: () => Pe },
337
+ props: /* @__PURE__ */ V({
338
+ columnsType: { default: () => Oe },
409
339
  minDate: { default: () => new Date((/* @__PURE__ */ new Date()).getFullYear() - 10, 0, 1) },
410
340
  maxDate: { default: () => new Date((/* @__PURE__ */ new Date()).getFullYear() + 10, 11, 31) },
411
- teleport: {},
412
- confirmButtonText: {},
413
- cancelButtonText: {},
414
- formatYearLabel: { type: Function, default: H },
415
- formatMonthLabel: { type: Function, default: H },
416
- formatDayLabel: { type: Function, default: H }
417
- },
418
- emits: ["update:show", "update:modelValue", "confirm", "cancel", "open", "closed"],
419
- setup(e, { emit: a }) {
420
- const n = e, u = a, o = Y([]), i = Y([]), d = O({
421
- get: () => n.show,
422
- set: (s) => u("update:show", s)
423
- }), f = O(() => {
424
- const { columnsType: s, minDate: r, maxDate: t } = n, l = {
425
- year: p,
426
- month: m,
427
- day: M
341
+ formatYearLabel: { type: Function, default: N },
342
+ formatMonthLabel: { type: Function, default: N },
343
+ formatDayLabel: { type: Function, default: N }
344
+ }, {
345
+ modelValue: { default: [] },
346
+ modelModifiers: {}
347
+ }),
348
+ emits: /* @__PURE__ */ V(["change"], ["update:modelValue"]),
349
+ setup(e, { expose: s, emit: f }) {
350
+ const o = e, u = f, i = $(e, "modelValue"), h = I(() => {
351
+ const { columnsType: r, minDate: l, maxDate: t } = o, n = {
352
+ year: m,
353
+ month: d,
354
+ day: p
428
355
  };
429
- return s.map((c) => l[c](r, t));
356
+ return r.map((a) => n[a](l, t));
430
357
  });
431
- function p(s, r) {
432
- const t = s.getFullYear(), l = r.getFullYear();
433
- return F(t, l, n.formatYearLabel);
434
- }
435
- function m(s, r) {
436
- const t = g("year"), l = te(t, s) ? s.getMonth() + 1 : 1, c = ne(t, r) ? r.getMonth() + 1 : 12;
437
- return F(l, c, n.formatMonthLabel);
438
- }
439
- function M(s, r) {
440
- const t = g("year"), l = g("month"), c = te(t, s) && Ve(l, s), h = ne(t, r) && ye(l, r), D = c ? s.getDate() : 1, S = h ? r.getDate() : we(t, l);
441
- return F(D, S, n.formatDayLabel);
442
- }
443
- function g(s) {
444
- const { columnsType: r } = n, t = r.indexOf(s), l = o.value[t];
445
- return l ? Number(l) : xe(n.minDate, n.maxDate, s);
358
+ i.value.length || M();
359
+ function m(r, l) {
360
+ const t = r.getFullYear(), n = l.getFullYear();
361
+ return b(t, n, o.formatYearLabel);
446
362
  }
447
- function w(s) {
448
- u("update:modelValue", s), i.value = s, u("confirm", s);
363
+ function d(r, l) {
364
+ const t = g("year"), n = Q(t, r) ? r.getMonth() + 1 : 1, a = W(t, l) ? l.getMonth() + 1 : 12;
365
+ return b(n, a, o.formatMonthLabel);
449
366
  }
450
- function V() {
451
- u("cancel");
367
+ function p(r, l) {
368
+ const t = g("year"), n = g("month"), a = Q(t, r) && Me(n, r), c = W(t, l) && xe(n, l), D = a ? r.getDate() : 1, S = c ? l.getDate() : De(t, n);
369
+ return b(D, S, o.formatDayLabel);
452
370
  }
453
- function x() {
454
- if (u("open"), n.modelValue && n.modelValue.length) {
455
- o.value = [...n.modelValue];
456
- return;
457
- }
458
- const { columnsType: s } = n;
459
- o.value = s.map((r) => g(r));
371
+ function g(r) {
372
+ const { columnsType: l } = o, t = l.indexOf(r), n = i.value[t];
373
+ return n ? Number(n) : _(o.minDate, o.maxDate, r);
460
374
  }
461
- function y() {
462
- o.value = n.modelValue ? [...n.modelValue] : [...i.value], u("closed");
375
+ function M() {
376
+ const { columnsType: r } = o;
377
+ i.value = r.map((l) => _(o.minDate, o.maxDate, l));
463
378
  }
464
- return (s, r) => (C(), L(ie, {
465
- modelValue: o.value,
466
- "onUpdate:modelValue": r[0] || (r[0] = (t) => o.value = t),
467
- show: d.value,
468
- "onUpdate:show": r[1] || (r[1] = (t) => d.value = t),
469
- title: s.title,
470
- columns: f.value,
471
- teleport: s.teleport,
472
- "confirm-button-text": s.confirmButtonText,
473
- "cancel-button-text": s.cancelButtonText,
474
- linkage: "",
475
- onConfirm: w,
476
- onCancel: V,
477
- onOpen: x,
478
- onClosed: y
479
- }, null, 8, ["modelValue", "show", "title", "columns", "teleport", "confirm-button-text", "cancel-button-text"]));
379
+ return s({
380
+ setCurrentDate: M
381
+ }), (r, l) => (k(), B(ae, {
382
+ modelValue: i.value,
383
+ "onUpdate:modelValue": l[0] || (l[0] = (t) => i.value = t),
384
+ columns: h.value,
385
+ onChange: l[1] || (l[1] = (t) => u("change", t))
386
+ }, null, 8, ["modelValue", "columns"]));
480
387
  }
481
- }), Ke = /* @__PURE__ */ E({
388
+ }), He = /* @__PURE__ */ L({
482
389
  __name: "TimePicker",
483
- props: {
484
- show: { type: Boolean },
485
- modelValue: {},
486
- title: { default: Fe },
487
- columnsType: { default: () => Le },
390
+ props: /* @__PURE__ */ V({
391
+ columnsType: { default: () => be },
488
392
  minTime: {},
489
393
  maxTime: {},
490
- teleport: {},
491
- confirmButtonText: {},
492
- cancelButtonText: {},
493
- formatHourLabel: { type: Function, default: U },
494
- formatMinuteLabel: { type: Function, default: U },
495
- formatSecondLabel: { type: Function, default: U }
496
- },
497
- emits: ["update:show", "update:modelValue", "confirm", "cancel", "open", "closed"],
498
- setup(e, { emit: a }) {
499
- const n = e, u = a, o = Y([]), i = Y([]), d = O({
500
- get: () => n.show,
501
- set: (t) => u("update:show", t)
502
- }), f = O(() => {
503
- const { columnsType: t } = n, l = {
504
- hour: M,
394
+ formatHourLabel: { type: Function, default: H },
395
+ formatMinuteLabel: { type: Function, default: H },
396
+ formatSecondLabel: { type: Function, default: H }
397
+ }, {
398
+ modelValue: { default: [] },
399
+ modelModifiers: {}
400
+ }),
401
+ emits: /* @__PURE__ */ V(["change"], ["update:modelValue"]),
402
+ setup(e, { expose: s, emit: f }) {
403
+ const o = e, u = f, i = $(e, "modelValue"), h = I(() => {
404
+ const { columnsType: t } = o, n = {
405
+ hour: p,
505
406
  minute: g,
506
- second: w
407
+ second: M
507
408
  };
508
- return t.map((c) => l[c]());
509
- }), p = O(() => oe(n.minTime ?? "") ?? { hour: 0, minute: 0, second: 0 }), m = O(() => oe(n.maxTime ?? "") ?? { hour: 23, minute: 59, second: 59 });
510
- function M() {
511
- const t = p.value.hour, l = m.value.hour;
512
- return F(t, l, n.formatHourLabel);
409
+ return t.map((a) => n[a]());
410
+ }), m = I(() => ee(o.minTime ?? "") ?? { hour: 0, minute: 0, second: 0 }), d = I(() => ee(o.maxTime ?? "") ?? { hour: 23, minute: 59, second: 59 });
411
+ i.value.length || l();
412
+ function p() {
413
+ const t = m.value.hour, n = d.value.hour;
414
+ return b(t, n, o.formatHourLabel);
513
415
  }
514
416
  function g() {
515
- const t = V("hour"), { hour: l, minute: c } = p.value, { hour: h, minute: D } = m.value;
516
- return F(t === l ? c : 0, t === h ? D : 59, n.formatMinuteLabel);
417
+ const t = r("hour"), { hour: n, minute: a } = m.value, { hour: c, minute: D } = d.value;
418
+ return b(t === n ? a : 0, t === c ? D : 59, o.formatMinuteLabel);
517
419
  }
518
- function w() {
519
- const t = V("hour"), l = V("minute"), { hour: c, minute: h, second: D } = p.value, { hour: S, minute: v, second: k } = m.value;
520
- return F(t === c && l === h ? D : 0, t === S && l === v ? k : 59, n.formatSecondLabel);
521
- }
522
- function V(t) {
523
- const { columnsType: l } = n, c = l.indexOf(t), h = o.value[c];
524
- return h !== void 0 ? Number(h) : Se(p.value, m.value, t);
525
- }
526
- function x(t) {
527
- u("update:modelValue", t), i.value = t, u("confirm", t);
528
- }
529
- function y() {
530
- u("cancel");
420
+ function M() {
421
+ const t = r("hour"), n = r("minute"), { hour: a, minute: c, second: D } = m.value, { hour: S, minute: O, second: w } = d.value;
422
+ return b(t === a && n === c ? D : 0, t === S && n === O ? w : 59, o.formatSecondLabel);
531
423
  }
532
- function s() {
533
- if (u("open"), n.modelValue && n.modelValue.length) {
534
- o.value = [...n.modelValue];
535
- return;
536
- }
537
- const { columnsType: t } = n;
538
- o.value = t.map((l) => V(l));
424
+ function r(t) {
425
+ const { columnsType: n } = o, a = n.indexOf(t), c = i.value[a];
426
+ return c !== void 0 ? Number(c) : te(m.value, d.value, t);
539
427
  }
540
- function r() {
541
- o.value = n.modelValue ? [...n.modelValue] : [...i.value], u("closed");
428
+ function l() {
429
+ const { columnsType: t } = o;
430
+ i.value = t.map((n) => te(m.value, d.value, n));
542
431
  }
543
- return (t, l) => (C(), L(ie, {
544
- modelValue: o.value,
545
- "onUpdate:modelValue": l[0] || (l[0] = (c) => o.value = c),
546
- show: d.value,
547
- "onUpdate:show": l[1] || (l[1] = (c) => d.value = c),
548
- title: t.title,
549
- columns: f.value,
550
- teleport: t.teleport,
551
- "confirm-button-text": t.confirmButtonText,
552
- "cancel-button-text": t.cancelButtonText,
553
- linkage: "",
554
- onConfirm: x,
555
- onCancel: y,
556
- onOpen: s,
557
- onClosed: r
558
- }, null, 8, ["modelValue", "show", "title", "columns", "teleport", "confirm-button-text", "cancel-button-text"]));
432
+ return s({
433
+ setCurrentTime: l
434
+ }), (t, n) => (k(), B(ae, {
435
+ modelValue: i.value,
436
+ "onUpdate:modelValue": n[0] || (n[0] = (a) => i.value = a),
437
+ columns: h.value,
438
+ onChange: n[1] || (n[1] = (a) => u("change", a))
439
+ }, null, 8, ["modelValue", "columns"]));
559
440
  }
560
441
  });
561
442
  export {
562
- Ge as DatePicker,
563
- ie as Picker,
564
- Ke as TimePicker
443
+ Ne as DatePicker,
444
+ ae as Picker,
445
+ He as TimePicker
565
446
  };