@lichta/vue 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # @lichta/vue
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@lichta/vue.svg)](https://www.npmjs.com/package/@lichta/vue)
4
+ [![npm version](https://img.shields.io/npm/v/@lichta/core.svg)](https://www.npmjs.com/package/@lichta/core)
5
+
6
+ 🚀 **[Demo trực tiếp](https://lichta.zeneo.app/)**
4
7
 
5
8
  Component `Calendar` (lịch tháng có ngày âm lịch) cho Vue 3, đóng gói trên [`@lichta/core`](https://www.npmjs.com/package/@lichta/core).
6
9
 
@@ -51,6 +54,48 @@ function onSelect(date: Date, lunar: LunarDate) {
51
54
 
52
55
  > Khác với `@lichta/react`/`@lichta/svelte` (dùng prop `onSelect`), Vue theo đúng convention của framework nên dùng `emit`/`@select` thay vì prop callback. Component cũng chưa hỗ trợ custom render cho từng ô ngày (có ở React/Svelte qua `renderDay`/`dayCell`) hay điều khiển `month`/`year` như controlled prop — thay đổi prop sau khi mount chưa tự động cập nhật lại lịch đang hiển thị.
53
56
 
57
+ ## DatePicker
58
+
59
+ Component `DatePicker` (input + popover chọn ngày, dựng trên `Calendar` ở trên).
60
+
61
+ ```vue
62
+ <script setup>
63
+ import { DatePicker } from '@lichta/vue';
64
+ import '@lichta/core/styles/calendar-base.css';
65
+ import '@lichta/core/styles/calendar-glass.css'; // theme "glass" (tùy chọn)
66
+ import '@lichta/core/styles/datepicker-base.css';
67
+ import '@lichta/core/styles/datepicker-glass.css'; // theme "glass" (tùy chọn)
68
+
69
+ function onSelect(date, lunar) {
70
+ console.log(date, lunar);
71
+ }
72
+ </script>
73
+
74
+ <template>
75
+ <DatePicker theme="glass" locale="vi" @select="onSelect" />
76
+ </template>
77
+ ```
78
+
79
+ > ⚠️ Cần import cả CSS của `Calendar` (dùng trong popover) lẫn `DatePicker` (input + popover chrome) — thiếu 1 trong 2 sẽ hiển thị thiếu style.
80
+
81
+ ### Props / Events
82
+
83
+ | Prop | Kiểu | Mặc định | Mô tả |
84
+ |---|---|---|---|
85
+ | `value` | `Date \| null` | `null` | Ngày đang chọn (uncontrolled — component tự quản lý sau lần mount đầu) |
86
+ | `placeholder` | `string` | `'Chọn ngày'` | Placeholder khi chưa chọn ngày |
87
+ | `locale` | `'vi' \| 'en' \| 'ja' \| 'ko'` | `'vi'` | Ngôn ngữ hiển thị trong popover |
88
+ | `theme` | `'classic' \| 'glass'` | `'classic'` | Giao diện input + popover |
89
+ | `showLunar` | `boolean` | `true` | Hiện ngày âm lịch trong popover |
90
+ | `format` | `(date: Date) => string` | `dd/MM/yyyy` | Hàm format ngày hiển thị trên input |
91
+ | `disabled` | `boolean` | `false` | Vô hiệu hoá input |
92
+
93
+ | Event | Payload | Mô tả |
94
+ |---|---|---|
95
+ | `select` | `(date: Date, lunar: LunarDate)` | Bắn khi chọn ngày trong popover |
96
+
97
+ Popover tự đóng khi: chọn xong 1 ngày, click ra ngoài, hoặc nhấn phím `Escape`.
98
+
54
99
  ## Theming
55
100
 
56
101
  ```css
@@ -66,6 +111,8 @@ function onSelect(date: Date, lunar: LunarDate) {
66
111
  }
67
112
  ```
68
113
 
114
+ `DatePicker` dùng chung biến CSS `--lichta-*` ở trên — không cần custom class riêng.
115
+
69
116
  ## License
70
117
 
71
118
  [MIT](./LICENSE)
@@ -1,18 +1,14 @@
1
- import { type LunarDate, type Locale } from '@lichta/core';
1
+ import { type LunarDate, type Locale, type CalendarDayCell } from '@lichta/core';
2
2
  interface Props {
3
3
  month?: number;
4
4
  year?: number;
5
+ /** Ngày được chọn (controlled). Bỏ qua thì Calendar tự quản lý selection nội bộ (uncontrolled). */
6
+ selectedDate?: Date | null;
5
7
  showLunar?: boolean;
6
8
  locale?: Locale;
7
9
  theme?: 'classic' | 'glass';
8
10
  }
9
- export interface DayCellData {
10
- solar: Date;
11
- lunar: LunarDate;
12
- isToday: boolean;
13
- isSelected: boolean;
14
- isCurrentMonth: boolean;
15
- }
11
+ export type DayCellData = CalendarDayCell;
16
12
  declare var __VLS_1: {};
17
13
  type __VLS_Slots = {} & {
18
14
  default?: (props: typeof __VLS_1) => any;
@@ -24,6 +20,7 @@ declare const __VLS_component: import("vue").DefineComponent<Props, {}, {}, {},
24
20
  }>, {
25
21
  month: number;
26
22
  year: number;
23
+ selectedDate: Date | null;
27
24
  showLunar: boolean;
28
25
  locale: Locale;
29
26
  theme: "classic" | "glass";
@@ -0,0 +1,25 @@
1
+ import { type LunarDate, type Locale } from '@lichta/core';
2
+ interface Props {
3
+ /** Ngày đang chọn (uncontrolled — component tự quản lý sau lần mount đầu) */
4
+ value?: Date | null;
5
+ placeholder?: string;
6
+ locale?: Locale;
7
+ theme?: 'classic' | 'glass';
8
+ showLunar?: boolean;
9
+ format?: (date: Date) => string;
10
+ disabled?: boolean;
11
+ }
12
+ declare const _default: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
13
+ select: (date: Date, lunar: LunarDate) => any;
14
+ }, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
15
+ onSelect?: ((date: Date, lunar: LunarDate) => any) | undefined;
16
+ }>, {
17
+ showLunar: boolean;
18
+ locale: Locale;
19
+ theme: "classic" | "glass";
20
+ value: Date | null;
21
+ placeholder: string;
22
+ format: (date: Date) => string;
23
+ disabled: boolean;
24
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
25
+ export default _default;
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { default as Calendar } from './Calendar.vue';
2
+ export { default as DatePicker } from './DatePicker.vue';
@@ -1,139 +1,224 @@
1
- import { defineComponent as q, ref as $, computed as L, openBlock as i, createElementBlock as d, normalizeClass as b, createElementVNode as l, toDisplayString as o, Fragment as T, renderList as N, createTextVNode as Y, createCommentVNode as x, renderSlot as A } from "vue";
2
- import { getYearDetails as H, LichTa as w } from "@lichta/core";
3
- const J = { class: "lich-ta-calendar-header" }, P = { class: "lich-ta-calendar-title" }, Q = { class: "lich-ta-calendar-month-year" }, R = { class: "lich-ta-calendar-canchi" }, U = { class: "lich-ta-calendar-weekdays" }, X = { class: "lich-ta-calendar-grid" }, Z = ["tabindex", "onClick", "onKeydown"], ee = { class: "solar-day" }, ae = {
1
+ import { defineComponent as V, ref as f, computed as y, watch as K, openBlock as l, createElementBlock as s, normalizeClass as L, createElementVNode as a, toDisplayString as t, Fragment as m, renderList as x, createTextVNode as E, createCommentVNode as S, renderSlot as O, onMounted as z, onBeforeUnmount as A } from "vue";
2
+ import { getYearDetails as P, t as N, getCalendarGrid as G } from "@lichta/core";
3
+ const U = { class: "lich-ta-calendar-header" }, j = { class: "lich-ta-calendar-title" }, q = { class: "lich-ta-calendar-month-year" }, H = { class: "lich-ta-calendar-canchi" }, J = { class: "lich-ta-calendar-weekdays" }, Q = { class: "lich-ta-calendar-grid" }, R = ["tabindex", "onClick", "onKeydown"], W = { class: "solar-day" }, X = {
4
4
  key: 0,
5
5
  class: "lunar-day"
6
- }, te = {
6
+ }, Z = {
7
7
  key: 0,
8
8
  class: "lich-ta-calendar-footer"
9
- }, le = /* @__PURE__ */ q({
9
+ }, pe = /* @__PURE__ */ V({
10
10
  __name: "Calendar",
11
11
  props: {
12
12
  month: { default: (/* @__PURE__ */ new Date()).getMonth() + 1 },
13
13
  year: { default: (/* @__PURE__ */ new Date()).getFullYear() },
14
+ selectedDate: { default: void 0 },
14
15
  showLunar: { type: Boolean, default: !0 },
15
16
  locale: { default: "vi" },
16
17
  theme: { default: "classic" }
17
18
  },
18
19
  emits: ["select"],
19
- setup(F, { emit: B }) {
20
- const v = F, e = $(v.month), s = $(v.year), h = $(null), C = L(() => H(s.value)), E = B, K = [
21
- "Tháng 1",
22
- "Tháng 2",
23
- "Tháng 3",
24
- "Tháng 4",
25
- "Tháng 5",
26
- "Tháng 6",
27
- "Tháng 7",
28
- "Tháng 8",
29
- "Tháng 9",
30
- "Tháng 10",
31
- "Tháng 11",
32
- "Tháng 12"
33
- ], V = ["CN", "T2", "T3", "T4", "T5", "T6", "T7"], I = L(() => {
34
- const t = [], y = new Date(s.value, e.value - 1, 1), a = new Date(s.value, e.value, 0), D = y.getDay(), g = a.getDate(), p = /* @__PURE__ */ new Date(), _ = `${p.getFullYear()}-${p.getMonth() + 1}-${p.getDate()}`;
35
- let f = "";
36
- h.value && (f = `${h.value.getFullYear()}-${h.value.getMonth() + 1}-${h.value.getDate()}`);
37
- const W = new Date(s.value, e.value - 1, 0).getDate();
38
- for (let n = D - 1; n >= 0; n--) {
39
- const r = W - n, c = e.value - 1 < 1 ? 12 : e.value - 1, u = e.value - 1 < 1 ? s.value - 1 : s.value, k = new Date(u, c - 1, r), m = w.toLunar(r, c, u), S = `${u}-${c}-${r}`;
40
- t.push({
41
- solar: k,
42
- lunar: m,
43
- isToday: S === _,
44
- isSelected: S === f,
45
- isCurrentMonth: !1
46
- });
47
- }
48
- for (let n = 1; n <= g; n++) {
49
- const r = new Date(s.value, e.value - 1, n), c = w.toLunar(n, e.value, s.value), u = `${s.value}-${e.value}-${n}`;
50
- t.push({
51
- solar: r,
52
- lunar: c,
53
- isToday: u === _,
54
- isSelected: u === f,
55
- isCurrentMonth: !0
56
- });
57
- }
58
- const j = 42 - t.length;
59
- for (let n = 1; n <= j; n++) {
60
- const r = e.value + 1 > 12 ? 1 : e.value + 1, c = e.value + 1 > 12 ? s.value + 1 : s.value, u = new Date(c, r - 1, n), k = w.toLunar(n, r, c), m = `${c}-${r}-${n}`;
61
- t.push({
62
- solar: u,
63
- lunar: k,
64
- isToday: m === _,
65
- isSelected: m === f,
66
- isCurrentMonth: !1
67
- });
68
- }
69
- return t;
20
+ setup(r, { emit: k }) {
21
+ const e = r, d = f(e.month), i = f(e.year), h = f(null), _ = y(
22
+ () => e.selectedDate !== void 0 ? e.selectedDate : h.value
23
+ );
24
+ K(() => e.month, (o) => {
25
+ d.value = o;
26
+ }), K(() => e.year, (o) => {
27
+ i.value = o;
70
28
  });
71
- function z() {
72
- e.value === 1 ? (e.value = 12, s.value -= 1) : e.value -= 1;
29
+ const g = y(() => P(i.value)), u = k, p = y(() => N(e.locale).weekDays), b = y(() => N(e.locale).solarMonthNames), T = y(
30
+ () => G(d.value, i.value, _.value)
31
+ );
32
+ function Y() {
33
+ d.value === 1 ? (d.value = 12, i.value -= 1) : d.value -= 1;
73
34
  }
74
- function G() {
75
- e.value === 12 ? (e.value = 1, s.value += 1) : e.value += 1;
35
+ function B() {
36
+ d.value === 12 ? (d.value = 1, i.value += 1) : d.value += 1;
76
37
  }
77
- function M(t) {
78
- h.value = t.solar, E("select", t.solar, t.lunar);
38
+ function C(o) {
39
+ e.selectedDate === void 0 && (h.value = o.solar), u("select", o.solar, o.lunar);
79
40
  }
80
- function O(t, y) {
81
- (t.key === "Enter" || t.key === " ") && (t.preventDefault(), M(y));
41
+ function F(o, $) {
42
+ (o.key === "Enter" || o.key === " ") && (o.preventDefault(), C($));
82
43
  }
83
- return (t, y) => (i(), d("div", {
84
- class: b(["lich-ta-calendar", `lichta-theme-${v.theme}`])
44
+ return (o, $) => (l(), s("div", {
45
+ class: L(["lich-ta-calendar", `lichta-theme-${e.theme}`])
85
46
  }, [
86
- l("div", J, [
87
- l("button", {
47
+ a("div", U, [
48
+ a("button", {
88
49
  class: "lich-ta-calendar-nav",
89
50
  "aria-label": "Tháng trước",
90
- onClick: z
51
+ onClick: Y
91
52
  }, "◀"),
92
- l("div", P, [
93
- l("span", Q, o(K[e.value - 1]) + ", " + o(s.value), 1),
94
- l("span", R, o(C.value.can) + " " + o(C.value.chi), 1)
53
+ a("div", j, [
54
+ a("span", q, t(b.value[d.value - 1]) + ", " + t(i.value), 1),
55
+ a("span", H, t(g.value.can) + " " + t(g.value.chi), 1)
95
56
  ]),
96
- l("button", {
57
+ a("button", {
97
58
  class: "lich-ta-calendar-nav",
98
59
  "aria-label": "Tháng sau",
99
- onClick: G
60
+ onClick: B
100
61
  }, "▶")
101
62
  ]),
102
- l("div", U, [
103
- (i(), d(T, null, N(V, (a) => l("div", {
104
- key: a,
63
+ a("div", J, [
64
+ (l(!0), s(m, null, x(p.value, (n) => (l(), s("div", {
65
+ key: n,
105
66
  class: "lich-ta-calendar-weekday"
106
- }, o(a), 1)), 64))
67
+ }, t(n), 1))), 128))
107
68
  ]),
108
- l("div", X, [
109
- (i(!0), d(T, null, N(I.value, (a, D) => (i(), d("button", {
110
- key: D,
111
- class: b(["lich-ta-calendar-day", {
112
- "is-today": a.isToday,
113
- "is-selected": a.isSelected,
114
- "is-other-month": !a.isCurrentMonth,
115
- "is-first-lunar": a.lunar.day === 1
69
+ a("div", Q, [
70
+ (l(!0), s(m, null, x(T.value, (n, M) => (l(), s("button", {
71
+ key: M,
72
+ class: L(["lich-ta-calendar-day", {
73
+ "is-today": n.isToday,
74
+ "is-selected": n.isSelected,
75
+ "is-other-month": !n.isCurrentMonth,
76
+ "is-first-lunar": n.lunar.day === 1
116
77
  }]),
117
- tabindex: a.isCurrentMonth ? 0 : -1,
118
- onClick: (g) => M(a),
119
- onKeydown: (g) => O(g, a)
78
+ tabindex: n.isCurrentMonth ? 0 : -1,
79
+ onClick: (w) => C(n),
80
+ onKeydown: (w) => F(w, n)
120
81
  }, [
121
- l("span", ee, o(a.solar.getDate()), 1),
122
- v.showLunar ? (i(), d("span", ae, [
123
- a.lunar.day === 1 ? (i(), d(T, { key: 0 }, [
124
- Y(o(a.lunar.day) + "/" + o(a.lunar.month) + o(a.lunar.isLeap ? "*" : ""), 1)
125
- ], 64)) : (i(), d(T, { key: 1 }, [
126
- Y(o(a.lunar.day), 1)
82
+ a("span", W, t(n.solar.getDate()), 1),
83
+ e.showLunar ? (l(), s("span", X, [
84
+ n.lunar.day === 1 ? (l(), s(m, { key: 0 }, [
85
+ E(t(n.lunar.day) + "/" + t(n.lunar.month) + t(n.lunar.isLeap ? "*" : ""), 1)
86
+ ], 64)) : (l(), s(m, { key: 1 }, [
87
+ E(t(n.lunar.day), 1)
127
88
  ], 64))
128
- ])) : x("", !0)
129
- ], 42, Z))), 128))
89
+ ])) : S("", !0)
90
+ ], 42, R))), 128))
130
91
  ]),
131
- t.$slots.default ? (i(), d("div", te, [
132
- A(t.$slots, "default")
133
- ])) : x("", !0)
92
+ o.$slots.default ? (l(), s("div", Z, [
93
+ O(o.$slots, "default")
94
+ ])) : S("", !0)
95
+ ], 2));
96
+ }
97
+ }), ee = ["disabled", "placeholder", "value", "aria-expanded"], ae = {
98
+ key: 0,
99
+ class: "lich-ta-datepicker-popover",
100
+ role: "dialog"
101
+ }, te = { class: "lich-ta-datepicker-calendar" }, ne = { class: "lich-ta-datepicker-calendar-header" }, le = { class: "lich-ta-datepicker-calendar-title" }, se = { class: "lich-ta-datepicker-calendar-month-year" }, oe = { class: "lich-ta-datepicker-calendar-canchi" }, ce = { class: "lich-ta-datepicker-calendar-weekdays" }, ie = { class: "lich-ta-datepicker-calendar-grid" }, re = ["tabindex", "onClick"], de = { class: "solar-day" }, ue = {
102
+ key: 0,
103
+ class: "lunar-day"
104
+ }, fe = /* @__PURE__ */ V({
105
+ __name: "DatePicker",
106
+ props: {
107
+ value: { default: null },
108
+ placeholder: { default: "Chọn ngày" },
109
+ locale: { default: "vi" },
110
+ theme: { default: "classic" },
111
+ showLunar: { type: Boolean, default: !0 },
112
+ format: { type: Function, default: (r) => {
113
+ const k = String(r.getDate()).padStart(2, "0"), e = String(r.getMonth() + 1).padStart(2, "0");
114
+ return `${k}/${e}/${r.getFullYear()}`;
115
+ } },
116
+ disabled: { type: Boolean, default: !1 }
117
+ },
118
+ emits: ["select"],
119
+ setup(r, { emit: k }) {
120
+ const e = r, d = k, i = f(e.value), h = f(!1), _ = f(null), g = i.value ?? /* @__PURE__ */ new Date(), u = f(g.getMonth() + 1), p = f(g.getFullYear());
121
+ K(
122
+ () => e.value,
123
+ (v) => {
124
+ const D = v ?? null;
125
+ i.value = D, D && (u.value = D.getMonth() + 1, p.value = D.getFullYear());
126
+ }
127
+ );
128
+ const b = y(() => P(p.value)), T = y(() => N(e.locale).weekDays), Y = y(() => N(e.locale).solarMonthNames), B = y(() => G(u.value, p.value, i.value)), C = y(() => i.value ? e.format(i.value) : "");
129
+ function F() {
130
+ e.disabled || (h.value = !h.value);
131
+ }
132
+ function o() {
133
+ u.value === 1 ? (u.value = 12, p.value -= 1) : u.value -= 1;
134
+ }
135
+ function $() {
136
+ u.value === 12 ? (u.value = 1, p.value += 1) : u.value += 1;
137
+ }
138
+ function n(v) {
139
+ i.value = v.solar, h.value = !1, d("select", v.solar, v.lunar);
140
+ }
141
+ function M(v) {
142
+ _.value && !_.value.contains(v.target) && (h.value = !1);
143
+ }
144
+ function w(v) {
145
+ v.key === "Escape" && (h.value = !1);
146
+ }
147
+ return z(() => {
148
+ document.addEventListener("mousedown", M), document.addEventListener("keydown", w);
149
+ }), A(() => {
150
+ document.removeEventListener("mousedown", M), document.removeEventListener("keydown", w);
151
+ }), (v, D) => (l(), s("div", {
152
+ ref_key: "rootEl",
153
+ ref: _,
154
+ class: L(["lich-ta-datepicker", `lichta-theme-${r.theme}`])
155
+ }, [
156
+ a("input", {
157
+ type: "text",
158
+ class: "lich-ta-datepicker-input",
159
+ readonly: "",
160
+ disabled: r.disabled,
161
+ placeholder: r.placeholder,
162
+ value: C.value,
163
+ "aria-haspopup": "dialog",
164
+ "aria-expanded": h.value,
165
+ onClick: F
166
+ }, null, 8, ee),
167
+ h.value ? (l(), s("div", ae, [
168
+ a("div", te, [
169
+ a("div", ne, [
170
+ a("button", {
171
+ type: "button",
172
+ class: "lich-ta-datepicker-calendar-nav",
173
+ "aria-label": "Tháng trước",
174
+ onClick: o
175
+ }, " ◀ "),
176
+ a("div", le, [
177
+ a("span", se, t(Y.value[u.value - 1]) + ", " + t(p.value), 1),
178
+ a("span", oe, t(b.value.can) + " " + t(b.value.chi), 1)
179
+ ]),
180
+ a("button", {
181
+ type: "button",
182
+ class: "lich-ta-datepicker-calendar-nav",
183
+ "aria-label": "Tháng sau",
184
+ onClick: $
185
+ }, " ▶ ")
186
+ ]),
187
+ a("div", ce, [
188
+ (l(!0), s(m, null, x(T.value, (c) => (l(), s("div", {
189
+ key: c,
190
+ class: "lich-ta-datepicker-calendar-weekday"
191
+ }, t(c), 1))), 128))
192
+ ]),
193
+ a("div", ie, [
194
+ (l(!0), s(m, null, x(B.value, (c, I) => (l(), s("button", {
195
+ key: I,
196
+ type: "button",
197
+ class: L(["lich-ta-datepicker-calendar-day", {
198
+ "is-today": c.isToday,
199
+ "is-selected": c.isSelected,
200
+ "is-other-month": !c.isCurrentMonth,
201
+ "is-first-lunar": c.lunar.day === 1
202
+ }]),
203
+ tabindex: c.isCurrentMonth ? 0 : -1,
204
+ onClick: (he) => n(c)
205
+ }, [
206
+ a("span", de, t(c.solar.getDate()), 1),
207
+ r.showLunar ? (l(), s("span", ue, [
208
+ c.lunar.day === 1 ? (l(), s(m, { key: 0 }, [
209
+ E(t(c.lunar.day) + "/" + t(c.lunar.month) + t(c.lunar.isLeap ? "*" : ""), 1)
210
+ ], 64)) : (l(), s(m, { key: 1 }, [
211
+ E(t(c.lunar.day), 1)
212
+ ], 64))
213
+ ])) : S("", !0)
214
+ ], 10, re))), 128))
215
+ ])
216
+ ])
217
+ ])) : S("", !0)
134
218
  ], 2));
135
219
  }
136
220
  });
137
221
  export {
138
- le as Calendar
222
+ pe as Calendar,
223
+ fe as DatePicker
139
224
  };
@@ -1 +1 @@
1
- (function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@lichta/core")):typeof define=="function"&&define.amd?define(["exports","vue","@lichta/core"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.LichTaVue={},c.Vue,c.LichTaCore))})(this,(function(c,e,h){"use strict";const E={class:"lich-ta-calendar-header"},$={class:"lich-ta-calendar-title"},w={class:"lich-ta-calendar-month-year"},B={class:"lich-ta-calendar-canchi"},N={class:"lich-ta-calendar-weekdays"},V={class:"lich-ta-calendar-grid"},L=["tabindex","onClick","onKeydown"],M={class:"solar-day"},b={key:0,class:"lunar-day"},F={key:0,class:"lich-ta-calendar-footer"},x=e.defineComponent({__name:"Calendar",props:{month:{default:new Date().getMonth()+1},year:{default:new Date().getFullYear()},showLunar:{type:Boolean,default:!0},locale:{default:"vi"},theme:{default:"classic"}},emits:["select"],setup(Y,{emit:K}){const u=Y,t=e.ref(u.month),l=e.ref(u.year),d=e.ref(null),_=e.computed(()=>h.getYearDetails(l.value)),j=K,q=["Tháng 1","Tháng 2","Tháng 3","Tháng 4","Tháng 5","Tháng 6","Tháng 7","Tháng 8","Tháng 9","Tháng 10","Tháng 11","Tháng 12"],v=["CN","T2","T3","T4","T5","T6","T7"],z=e.computed(()=>{const n=[],y=new Date(l.value,t.value-1,1),a=new Date(l.value,t.value,0),f=y.getDay(),m=a.getDate(),D=new Date,T=`${D.getFullYear()}-${D.getMonth()+1}-${D.getDate()}`;let g="";d.value&&(g=`${d.value.getFullYear()}-${d.value.getMonth()+1}-${d.value.getDate()}`);const P=new Date(l.value,t.value-1,0).getDate();for(let o=f-1;o>=0;o--){const s=P-o,r=t.value-1<1?12:t.value-1,i=t.value-1<1?l.value-1:l.value,k=new Date(i,r-1,s),p=h.LichTa.toLunar(s,r,i),C=`${i}-${r}-${s}`;n.push({solar:k,lunar:p,isToday:C===T,isSelected:C===g,isCurrentMonth:!1})}for(let o=1;o<=m;o++){const s=new Date(l.value,t.value-1,o),r=h.LichTa.toLunar(o,t.value,l.value),i=`${l.value}-${t.value}-${o}`;n.push({solar:s,lunar:r,isToday:i===T,isSelected:i===g,isCurrentMonth:!0})}const W=42-n.length;for(let o=1;o<=W;o++){const s=t.value+1>12?1:t.value+1,r=t.value+1>12?l.value+1:l.value,i=new Date(r,s-1,o),k=h.LichTa.toLunar(o,s,r),p=`${r}-${s}-${o}`;n.push({solar:i,lunar:k,isToday:p===T,isSelected:p===g,isCurrentMonth:!1})}return n});function I(){t.value===1?(t.value=12,l.value-=1):t.value-=1}function O(){t.value===12?(t.value=1,l.value+=1):t.value+=1}function S(n){d.value=n.solar,j("select",n.solar,n.lunar)}function G(n,y){(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),S(y))}return(n,y)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["lich-ta-calendar",`lichta-theme-${u.theme}`])},[e.createElementVNode("div",E,[e.createElementVNode("button",{class:"lich-ta-calendar-nav","aria-label":"Tháng trước",onClick:I},"◀"),e.createElementVNode("div",$,[e.createElementVNode("span",w,e.toDisplayString(q[t.value-1])+", "+e.toDisplayString(l.value),1),e.createElementVNode("span",B,e.toDisplayString(_.value.can)+" "+e.toDisplayString(_.value.chi),1)]),e.createElementVNode("button",{class:"lich-ta-calendar-nav","aria-label":"Tháng sau",onClick:O},"▶")]),e.createElementVNode("div",N,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(v,a=>e.createElementVNode("div",{key:a,class:"lich-ta-calendar-weekday"},e.toDisplayString(a),1)),64))]),e.createElementVNode("div",V,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(z.value,(a,f)=>(e.openBlock(),e.createElementBlock("button",{key:f,class:e.normalizeClass(["lich-ta-calendar-day",{"is-today":a.isToday,"is-selected":a.isSelected,"is-other-month":!a.isCurrentMonth,"is-first-lunar":a.lunar.day===1}]),tabindex:a.isCurrentMonth?0:-1,onClick:m=>S(a),onKeydown:m=>G(m,a)},[e.createElementVNode("span",M,e.toDisplayString(a.solar.getDate()),1),u.showLunar?(e.openBlock(),e.createElementBlock("span",b,[a.lunar.day===1?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode(e.toDisplayString(a.lunar.day)+"/"+e.toDisplayString(a.lunar.month)+e.toDisplayString(a.lunar.isLeap?"*":""),1)],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode(e.toDisplayString(a.lunar.day),1)],64))])):e.createCommentVNode("",!0)],42,L))),128))]),n.$slots.default?(e.openBlock(),e.createElementBlock("div",F,[e.renderSlot(n.$slots,"default")])):e.createCommentVNode("",!0)],2))}});c.Calendar=x,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(h,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@lichta/core")):typeof define=="function"&&define.amd?define(["exports","vue","@lichta/core"],e):(h=typeof globalThis<"u"?globalThis:h||self,e(h.LichTaVue={},h.Vue,h.LichTaCore))})(this,(function(h,e,m){"use strict";const w={class:"lich-ta-calendar-header"},b={class:"lich-ta-calendar-title"},$={class:"lich-ta-calendar-month-year"},L={class:"lich-ta-calendar-canchi"},M={class:"lich-ta-calendar-weekdays"},x={class:"lich-ta-calendar-grid"},T=["tabindex","onClick","onKeydown"],F={class:"solar-day"},Y={key:0,class:"lunar-day"},z={key:0,class:"lich-ta-calendar-footer"},K=e.defineComponent({__name:"Calendar",props:{month:{default:new Date().getMonth()+1},year:{default:new Date().getFullYear()},selectedDate:{default:void 0},showLunar:{type:Boolean,default:!0},locale:{default:"vi"},theme:{default:"classic"}},emits:["select"],setup(c,{emit:y}){const t=c,r=e.ref(t.month),o=e.ref(t.year),i=e.ref(null),k=e.computed(()=>t.selectedDate!==void 0?t.selectedDate:i.value);e.watch(()=>t.month,n=>{r.value=n}),e.watch(()=>t.year,n=>{o.value=n});const u=e.computed(()=>m.getYearDetails(o.value)),s=y,p=e.computed(()=>m.t(t.locale).weekDays),_=e.computed(()=>m.t(t.locale).solarMonthNames),N=e.computed(()=>m.getCalendarGrid(r.value,o.value,k.value));function S(){r.value===1?(r.value=12,o.value-=1):r.value-=1}function V(){r.value===12?(r.value=1,o.value+=1):r.value+=1}function E(n){t.selectedDate===void 0&&(i.value=n.solar),s("select",n.solar,n.lunar)}function C(n,D){(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),E(D))}return(n,D)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["lich-ta-calendar",`lichta-theme-${t.theme}`])},[e.createElementVNode("div",w,[e.createElementVNode("button",{class:"lich-ta-calendar-nav","aria-label":"Tháng trước",onClick:S},""),e.createElementVNode("div",b,[e.createElementVNode("span",$,e.toDisplayString(_.value[r.value-1])+", "+e.toDisplayString(o.value),1),e.createElementVNode("span",L,e.toDisplayString(u.value.can)+" "+e.toDisplayString(u.value.chi),1)]),e.createElementVNode("button",{class:"lich-ta-calendar-nav","aria-label":"Tháng sau",onClick:V},"")]),e.createElementVNode("div",M,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value,a=>(e.openBlock(),e.createElementBlock("div",{key:a,class:"lich-ta-calendar-weekday"},e.toDisplayString(a),1))),128))]),e.createElementVNode("div",x,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N.value,(a,B)=>(e.openBlock(),e.createElementBlock("button",{key:B,class:e.normalizeClass(["lich-ta-calendar-day",{"is-today":a.isToday,"is-selected":a.isSelected,"is-other-month":!a.isCurrentMonth,"is-first-lunar":a.lunar.day===1}]),tabindex:a.isCurrentMonth?0:-1,onClick:f=>E(a),onKeydown:f=>C(f,a)},[e.createElementVNode("span",F,e.toDisplayString(a.solar.getDate()),1),t.showLunar?(e.openBlock(),e.createElementBlock("span",Y,[a.lunar.day===1?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode(e.toDisplayString(a.lunar.day)+"/"+e.toDisplayString(a.lunar.month)+e.toDisplayString(a.lunar.isLeap?"*":""),1)],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode(e.toDisplayString(a.lunar.day),1)],64))])):e.createCommentVNode("",!0)],42,T))),128))]),n.$slots.default?(e.openBlock(),e.createElementBlock("div",z,[e.renderSlot(n.$slots,"default")])):e.createCommentVNode("",!0)],2))}}),P=["disabled","placeholder","value","aria-expanded"],G={key:0,class:"lich-ta-datepicker-popover",role:"dialog"},O={class:"lich-ta-datepicker-calendar"},j={class:"lich-ta-datepicker-calendar-header"},q={class:"lich-ta-datepicker-calendar-title"},I={class:"lich-ta-datepicker-calendar-month-year"},A={class:"lich-ta-datepicker-calendar-canchi"},U={class:"lich-ta-datepicker-calendar-weekdays"},H={class:"lich-ta-datepicker-calendar-grid"},J=["tabindex","onClick"],Q={class:"solar-day"},R={key:0,class:"lunar-day"},W=e.defineComponent({__name:"DatePicker",props:{value:{default:null},placeholder:{default:"Chọn ngày"},locale:{default:"vi"},theme:{default:"classic"},showLunar:{type:Boolean,default:!0},format:{type:Function,default:c=>{const y=String(c.getDate()).padStart(2,"0"),t=String(c.getMonth()+1).padStart(2,"0");return`${y}/${t}/${c.getFullYear()}`}},disabled:{type:Boolean,default:!1}},emits:["select"],setup(c,{emit:y}){const t=c,r=y,o=e.ref(t.value),i=e.ref(!1),k=e.ref(null),u=o.value??new Date,s=e.ref(u.getMonth()+1),p=e.ref(u.getFullYear());e.watch(()=>t.value,d=>{const g=d??null;o.value=g,g&&(s.value=g.getMonth()+1,p.value=g.getFullYear())});const _=e.computed(()=>m.getYearDetails(p.value)),N=e.computed(()=>m.t(t.locale).weekDays),S=e.computed(()=>m.t(t.locale).solarMonthNames),V=e.computed(()=>m.getCalendarGrid(s.value,p.value,o.value)),E=e.computed(()=>o.value?t.format(o.value):"");function C(){t.disabled||(i.value=!i.value)}function n(){s.value===1?(s.value=12,p.value-=1):s.value-=1}function D(){s.value===12?(s.value=1,p.value+=1):s.value+=1}function a(d){o.value=d.solar,i.value=!1,r("select",d.solar,d.lunar)}function B(d){k.value&&!k.value.contains(d.target)&&(i.value=!1)}function f(d){d.key==="Escape"&&(i.value=!1)}return e.onMounted(()=>{document.addEventListener("mousedown",B),document.addEventListener("keydown",f)}),e.onBeforeUnmount(()=>{document.removeEventListener("mousedown",B),document.removeEventListener("keydown",f)}),(d,g)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"rootEl",ref:k,class:e.normalizeClass(["lich-ta-datepicker",`lichta-theme-${c.theme}`])},[e.createElementVNode("input",{type:"text",class:"lich-ta-datepicker-input",readonly:"",disabled:c.disabled,placeholder:c.placeholder,value:E.value,"aria-haspopup":"dialog","aria-expanded":i.value,onClick:C},null,8,P),i.value?(e.openBlock(),e.createElementBlock("div",G,[e.createElementVNode("div",O,[e.createElementVNode("div",j,[e.createElementVNode("button",{type:"button",class:"lich-ta-datepicker-calendar-nav","aria-label":"Tháng trước",onClick:n}," "),e.createElementVNode("div",q,[e.createElementVNode("span",I,e.toDisplayString(S.value[s.value-1])+", "+e.toDisplayString(p.value),1),e.createElementVNode("span",A,e.toDisplayString(_.value.can)+" "+e.toDisplayString(_.value.chi),1)]),e.createElementVNode("button",{type:"button",class:"lich-ta-datepicker-calendar-nav","aria-label":"Tháng sau",onClick:D}," ")]),e.createElementVNode("div",U,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N.value,l=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"lich-ta-datepicker-calendar-weekday"},e.toDisplayString(l),1))),128))]),e.createElementVNode("div",H,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(V.value,(l,X)=>(e.openBlock(),e.createElementBlock("button",{key:X,type:"button",class:e.normalizeClass(["lich-ta-datepicker-calendar-day",{"is-today":l.isToday,"is-selected":l.isSelected,"is-other-month":!l.isCurrentMonth,"is-first-lunar":l.lunar.day===1}]),tabindex:l.isCurrentMonth?0:-1,onClick:Z=>a(l)},[e.createElementVNode("span",Q,e.toDisplayString(l.solar.getDate()),1),c.showLunar?(e.openBlock(),e.createElementBlock("span",R,[l.lunar.day===1?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode(e.toDisplayString(l.lunar.day)+"/"+e.toDisplayString(l.lunar.month)+e.toDisplayString(l.lunar.isLeap?"*":""),1)],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode(e.toDisplayString(l.lunar.day),1)],64))])):e.createCommentVNode("",!0)],10,J))),128))])])])):e.createCommentVNode("",!0)],2))}});h.Calendar=K,h.DatePicker=W,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lichta/vue",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Vue components for LichTa",
5
5
  "author": "Zeforc Labs | Stridev",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@
20
20
  "LICENSE"
21
21
  ],
22
22
  "dependencies": {
23
- "@lichta/core": "2.0.1"
23
+ "@lichta/core": "2.1.0"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "vue": "^3.0.0"