remons-calendar 1.0.0-beta.1
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/dist/components/AddScheduleModal.d.ts +16 -0
- package/dist/components/AddScheduleModal.d.ts.map +1 -0
- package/dist/components/AddTodoModal.d.ts +16 -0
- package/dist/components/AddTodoModal.d.ts.map +1 -0
- package/dist/components/Calendar/CalendarHeader.d.ts +16 -0
- package/dist/components/Calendar/CalendarHeader.d.ts.map +1 -0
- package/dist/components/Calendar/DayCell.d.ts +26 -0
- package/dist/components/Calendar/DayCell.d.ts.map +1 -0
- package/dist/components/Calendar/DayPanel.d.ts +21 -0
- package/dist/components/Calendar/DayPanel.d.ts.map +1 -0
- package/dist/components/Calendar/TodoLanes.d.ts +12 -0
- package/dist/components/Calendar/TodoLanes.d.ts.map +1 -0
- package/dist/components/Calendar/index.d.ts +5 -0
- package/dist/components/Calendar/index.d.ts.map +1 -0
- package/dist/components/Calendar/layout.d.ts +20 -0
- package/dist/components/Calendar/layout.d.ts.map +1 -0
- package/dist/components/Calendar/types.d.ts +46 -0
- package/dist/components/Calendar/types.d.ts.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/hooks/useLocalStorage.d.ts +3 -0
- package/dist/hooks/useLocalStorage.d.ts.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +755 -0
- package/dist/services/holiday.d.ts +8 -0
- package/dist/services/holiday.d.ts.map +1 -0
- package/dist/style.css +1 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/date.d.ts +24 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/holidayDisplay.d.ts +18 -0
- package/dist/utils/holidayDisplay.d.ts.map +1 -0
- package/package.json +56 -0
- package/readme.md +62 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,755 @@
|
|
|
1
|
+
import { jsx as r, jsxs as g, Fragment as ye } from "react/jsx-runtime";
|
|
2
|
+
import { useState as W, useEffect as J, useMemo as j } from "react";
|
|
3
|
+
import { Form as k, Modal as me, Input as ue, Row as oe, Col as G, DatePicker as te, TimePicker as ne, Space as ae, Button as C, Tooltip as ge, Segmented as Te, Spin as Se, Empty as X } from "antd";
|
|
4
|
+
import S from "dayjs";
|
|
5
|
+
import { Solar as Ee } from "lunar-javascript";
|
|
6
|
+
import { LeftOutlined as ve, RightOutlined as Ne } from "@ant-design/icons";
|
|
7
|
+
const ke = "holiday_cache_v2_", $e = (n) => `${ke}${n}`;
|
|
8
|
+
async function we(n) {
|
|
9
|
+
const e = $e(n), t = localStorage.getItem(e);
|
|
10
|
+
if (t)
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(t);
|
|
13
|
+
} catch {
|
|
14
|
+
localStorage.removeItem(e);
|
|
15
|
+
}
|
|
16
|
+
localStorage.removeItem(`holiday_cache_${n}`);
|
|
17
|
+
const o = await fetch(`https://timor.tech/api/holiday/year/${n}`);
|
|
18
|
+
if (!o.ok)
|
|
19
|
+
throw new Error(`节假日接口请求失败: ${o.status}`);
|
|
20
|
+
const a = await o.json(), i = (a == null ? void 0 : a.holiday) ?? (a == null ? void 0 : a.data) ?? {}, l = {};
|
|
21
|
+
return Object.entries(i).forEach(([m, f]) => {
|
|
22
|
+
if (!f || typeof f != "object") return;
|
|
23
|
+
const [h, y] = m.split("-"), s = h == null ? void 0 : h.padStart(2, "0"), d = y == null ? void 0 : y.padStart(2, "0");
|
|
24
|
+
!s || !d || s.length !== 2 || d.length !== 2 || (l[`${n}-${s}-${d}`] = {
|
|
25
|
+
holiday: !!f.holiday,
|
|
26
|
+
name: String(f.name ?? ""),
|
|
27
|
+
target: f.target != null ? String(f.target) : void 0
|
|
28
|
+
});
|
|
29
|
+
}), Object.keys(l).length > 0 ? localStorage.setItem(e, JSON.stringify(l)) : localStorage.removeItem(e), l;
|
|
30
|
+
}
|
|
31
|
+
const I = (n) => n.format("YYYY-MM-DD"), ce = (n) => n.startTime ?? "00:00";
|
|
32
|
+
function Q(n) {
|
|
33
|
+
return n.startTime && n.endTime ? `${n.startTime}-${n.endTime}` : n.startTime ?? n.endTime ?? "";
|
|
34
|
+
}
|
|
35
|
+
function Me(n, e) {
|
|
36
|
+
const o = S(`${n}-${e + 1}-01`).startOf("week");
|
|
37
|
+
return Array.from({ length: 42 }, (a, i) => {
|
|
38
|
+
const l = o.add(i, "day");
|
|
39
|
+
return { date: l, inMonth: l.month() === e };
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function De(n, e) {
|
|
43
|
+
const t = /* @__PURE__ */ new Date(`${n}T00:00:00`);
|
|
44
|
+
t.setDate(t.getDate() + e);
|
|
45
|
+
const o = t.getFullYear(), a = String(t.getMonth() + 1).padStart(2, "0"), i = String(t.getDate()).padStart(2, "0");
|
|
46
|
+
return `${o}-${a}-${i}`;
|
|
47
|
+
}
|
|
48
|
+
function be(n) {
|
|
49
|
+
const e = Object.keys(n).sort(), t = (i) => n[i], o = (i) => {
|
|
50
|
+
const l = De(i, -1), m = t(l);
|
|
51
|
+
if (m)
|
|
52
|
+
return !m.holiday;
|
|
53
|
+
const f = n[i].target ?? "";
|
|
54
|
+
return f ? !e.some((h) => {
|
|
55
|
+
if (h >= i) return !1;
|
|
56
|
+
const y = t(h);
|
|
57
|
+
return !!y && y.holiday && (y.target ?? "") === f;
|
|
58
|
+
}) : !0;
|
|
59
|
+
}, a = {};
|
|
60
|
+
return e.forEach((i) => {
|
|
61
|
+
const l = n[i];
|
|
62
|
+
if (l) {
|
|
63
|
+
if (!l.holiday) {
|
|
64
|
+
a[i] = { name: "", off: !1 };
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
a[i] = {
|
|
68
|
+
name: o(i) ? l.name : "",
|
|
69
|
+
off: !0
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}), a;
|
|
73
|
+
}
|
|
74
|
+
function Ie(n, e) {
|
|
75
|
+
const [t, o] = W(() => {
|
|
76
|
+
try {
|
|
77
|
+
const a = localStorage.getItem(n);
|
|
78
|
+
return a ? JSON.parse(a) : e;
|
|
79
|
+
} catch {
|
|
80
|
+
return e;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return J(() => {
|
|
84
|
+
try {
|
|
85
|
+
localStorage.setItem(n, JSON.stringify(t));
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
}, [n, t]), [t, o];
|
|
89
|
+
}
|
|
90
|
+
const Z = [
|
|
91
|
+
"#f5222d",
|
|
92
|
+
"#fa8c16",
|
|
93
|
+
"#fadb14",
|
|
94
|
+
"#52c41a",
|
|
95
|
+
"#13c2c2",
|
|
96
|
+
"#1677ff",
|
|
97
|
+
"#722ed1",
|
|
98
|
+
"#eb2f96"
|
|
99
|
+
];
|
|
100
|
+
function Ce({ value: n = Z[5], onChange: e }) {
|
|
101
|
+
return /* @__PURE__ */ r("div", { className: "color-swatches", children: Z.map((t) => /* @__PURE__ */ r(
|
|
102
|
+
"span",
|
|
103
|
+
{
|
|
104
|
+
className: `swatch ${n === t ? "active" : ""}`,
|
|
105
|
+
style: { background: t },
|
|
106
|
+
onClick: () => e == null ? void 0 : e(t)
|
|
107
|
+
},
|
|
108
|
+
t
|
|
109
|
+
)) });
|
|
110
|
+
}
|
|
111
|
+
function He({ open: n, editing: e, initialStart: t, initialEnd: o, onClose: a, onSave: i, onDelete: l }) {
|
|
112
|
+
const [m] = k.useForm(), f = !!e;
|
|
113
|
+
J(() => {
|
|
114
|
+
n && setTimeout(() => {
|
|
115
|
+
e ? m.setFieldsValue({
|
|
116
|
+
name: e.name,
|
|
117
|
+
start: S(e.start),
|
|
118
|
+
end: S(e.end),
|
|
119
|
+
startTime: e.startTime ? S(e.startTime, "HH:mm") : null,
|
|
120
|
+
endTime: e.endTime ? S(e.endTime, "HH:mm") : null,
|
|
121
|
+
color: e.color
|
|
122
|
+
}) : (m.setFieldsValue({
|
|
123
|
+
color: Z[5],
|
|
124
|
+
start: t ? S(t) : S(),
|
|
125
|
+
end: o ? S(o) : S(),
|
|
126
|
+
startTime: null,
|
|
127
|
+
endTime: null
|
|
128
|
+
}), m.resetFields(["name"]));
|
|
129
|
+
}, 100);
|
|
130
|
+
}, [n, e, t, o, m]);
|
|
131
|
+
const h = {
|
|
132
|
+
validator: (T, v) => {
|
|
133
|
+
const u = m.getFieldValue("start");
|
|
134
|
+
return !v || !u || !v.isBefore(u, "day") ? Promise.resolve() : Promise.reject(new Error("结束日期不能早于开始日期"));
|
|
135
|
+
}
|
|
136
|
+
}, y = {
|
|
137
|
+
validator: () => {
|
|
138
|
+
const T = m.getFieldValue("start"), v = m.getFieldValue("end");
|
|
139
|
+
return !T || !v ? Promise.resolve() : v.isSame(T, "day") ? Promise.reject(new Error("待办必须跨天(结束日期需晚于开始日期);单日事件请创建日程")) : Promise.resolve();
|
|
140
|
+
}
|
|
141
|
+
}, s = {
|
|
142
|
+
validator: (T, v) => {
|
|
143
|
+
var F;
|
|
144
|
+
const u = m.getFieldValue("start"), w = m.getFieldValue("end");
|
|
145
|
+
if (!u || !w || !w.isSame(u, "day")) return Promise.resolve();
|
|
146
|
+
const H = ((F = m.getFieldValue("startTime")) == null ? void 0 : F.format("HH:mm")) ?? "00:00";
|
|
147
|
+
return ((v == null ? void 0 : v.format("HH:mm")) ?? "24:00") < H ? Promise.reject(new Error("结束时间不能早于开始时间")) : Promise.resolve();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
return /* @__PURE__ */ r(
|
|
151
|
+
me,
|
|
152
|
+
{
|
|
153
|
+
title: f ? "编辑待办" : "添加待办",
|
|
154
|
+
open: n,
|
|
155
|
+
onCancel: a,
|
|
156
|
+
okText: "保存",
|
|
157
|
+
cancelText: "取消",
|
|
158
|
+
destroyOnClose: !0,
|
|
159
|
+
footer: /* @__PURE__ */ g(ae, { children: [
|
|
160
|
+
f && /* @__PURE__ */ r(C, { danger: !0, onClick: () => {
|
|
161
|
+
e && l(e.id), a();
|
|
162
|
+
}, children: "删除" }),
|
|
163
|
+
/* @__PURE__ */ r(C, { onClick: a, children: "取消" }),
|
|
164
|
+
/* @__PURE__ */ r(C, { type: "primary", onClick: async () => {
|
|
165
|
+
const T = await m.validateFields(), v = T.startTime, u = T.endTime;
|
|
166
|
+
i({
|
|
167
|
+
id: (e == null ? void 0 : e.id) ?? crypto.randomUUID(),
|
|
168
|
+
name: T.name.trim(),
|
|
169
|
+
start: T.start.format("YYYY-MM-DD"),
|
|
170
|
+
end: T.end.format("YYYY-MM-DD"),
|
|
171
|
+
startTime: v ? v.format("HH:mm") : void 0,
|
|
172
|
+
endTime: u ? u.format("HH:mm") : void 0,
|
|
173
|
+
color: T.color
|
|
174
|
+
}), a();
|
|
175
|
+
}, children: "保存" })
|
|
176
|
+
] }),
|
|
177
|
+
children: /* @__PURE__ */ g(k, { form: m, layout: "vertical", preserve: !1, children: [
|
|
178
|
+
/* @__PURE__ */ r(k.Item, { label: "事件名称", name: "name", rules: [{ required: !0, message: "请输入事件名称" }, { max: 30 }], children: /* @__PURE__ */ r(ue, { placeholder: "如:年度项目冲刺", maxLength: 30 }) }),
|
|
179
|
+
/* @__PURE__ */ g(oe, { gutter: 8, children: [
|
|
180
|
+
/* @__PURE__ */ r(G, { span: 12, children: /* @__PURE__ */ r(
|
|
181
|
+
k.Item,
|
|
182
|
+
{
|
|
183
|
+
label: "开始日期",
|
|
184
|
+
name: "start",
|
|
185
|
+
dependencies: ["end"],
|
|
186
|
+
rules: [{ required: !0, message: "请选择开始日期" }, y],
|
|
187
|
+
children: /* @__PURE__ */ r(te, { style: { width: "100%" }, format: "YYYY-MM-DD" })
|
|
188
|
+
}
|
|
189
|
+
) }),
|
|
190
|
+
/* @__PURE__ */ r(G, { span: 12, children: /* @__PURE__ */ r(k.Item, { label: "开始时间", name: "startTime", children: /* @__PURE__ */ r(
|
|
191
|
+
ne,
|
|
192
|
+
{
|
|
193
|
+
style: { width: "100%" },
|
|
194
|
+
format: "HH:mm",
|
|
195
|
+
minuteStep: 30,
|
|
196
|
+
placeholder: "首日开始时间,可选",
|
|
197
|
+
allowClear: !0
|
|
198
|
+
}
|
|
199
|
+
) }) })
|
|
200
|
+
] }),
|
|
201
|
+
/* @__PURE__ */ g(oe, { gutter: 8, children: [
|
|
202
|
+
/* @__PURE__ */ r(G, { span: 12, children: /* @__PURE__ */ r(
|
|
203
|
+
k.Item,
|
|
204
|
+
{
|
|
205
|
+
label: "结束日期",
|
|
206
|
+
name: "end",
|
|
207
|
+
dependencies: ["start"],
|
|
208
|
+
rules: [{ required: !0, message: "请选择结束日期" }, h, y],
|
|
209
|
+
children: /* @__PURE__ */ r(te, { style: { width: "100%" }, format: "YYYY-MM-DD" })
|
|
210
|
+
}
|
|
211
|
+
) }),
|
|
212
|
+
/* @__PURE__ */ r(G, { span: 12, children: /* @__PURE__ */ r(k.Item, { label: "结束时间", name: "endTime", rules: [s], children: /* @__PURE__ */ r(
|
|
213
|
+
ne,
|
|
214
|
+
{
|
|
215
|
+
style: { width: "100%" },
|
|
216
|
+
format: "HH:mm",
|
|
217
|
+
minuteStep: 30,
|
|
218
|
+
placeholder: "末日结束时间,可选",
|
|
219
|
+
allowClear: !0
|
|
220
|
+
}
|
|
221
|
+
) }) })
|
|
222
|
+
] }),
|
|
223
|
+
/* @__PURE__ */ r(k.Item, { label: "颜色标记", name: "color", initialValue: Z[5], children: /* @__PURE__ */ r(Ce, {}) })
|
|
224
|
+
] })
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
function Ye({ icons: n, onChange: e }) {
|
|
229
|
+
return /* @__PURE__ */ r("div", { className: "emoji-grid", children: Object.entries(n).map(([t, o]) => /* @__PURE__ */ r("span", { className: "emoji-item", onClick: () => e == null ? void 0 : e(t), children: o }, t)) });
|
|
230
|
+
}
|
|
231
|
+
function xe({
|
|
232
|
+
open: n,
|
|
233
|
+
editing: e,
|
|
234
|
+
initialDate: t,
|
|
235
|
+
icons: o,
|
|
236
|
+
onClose: a,
|
|
237
|
+
onSave: i,
|
|
238
|
+
onDelete: l
|
|
239
|
+
}) {
|
|
240
|
+
const [m] = k.useForm(), f = !!e, h = Object.keys(o);
|
|
241
|
+
J(() => {
|
|
242
|
+
n && setTimeout(() => {
|
|
243
|
+
e ? m.setFieldsValue({
|
|
244
|
+
icon: e.icon,
|
|
245
|
+
date: S(e.date),
|
|
246
|
+
name: e.name,
|
|
247
|
+
timeRange: e.startTime && e.endTime ? [S(e.startTime, "HH:mm"), S(e.endTime, "HH:mm")] : null
|
|
248
|
+
}) : (m.setFieldsValue({
|
|
249
|
+
icon: h[0],
|
|
250
|
+
date: t ? S(t) : S(),
|
|
251
|
+
timeRange: null
|
|
252
|
+
}), m.resetFields(["name"]));
|
|
253
|
+
}, 100);
|
|
254
|
+
}, [n, e, t, m, o]);
|
|
255
|
+
const y = async () => {
|
|
256
|
+
const d = await m.validateFields(), p = d.timeRange;
|
|
257
|
+
i({
|
|
258
|
+
id: (e == null ? void 0 : e.id) ?? crypto.randomUUID(),
|
|
259
|
+
icon: d.icon,
|
|
260
|
+
date: d.date.format("YYYY-MM-DD"),
|
|
261
|
+
name: d.name.trim(),
|
|
262
|
+
startTime: p != null && p[0] ? p[0].format("HH:mm") : void 0,
|
|
263
|
+
endTime: p != null && p[1] ? p[1].format("HH:mm") : void 0
|
|
264
|
+
}), a();
|
|
265
|
+
};
|
|
266
|
+
return /* @__PURE__ */ r(
|
|
267
|
+
me,
|
|
268
|
+
{
|
|
269
|
+
title: f ? "编辑日程" : "添加日程",
|
|
270
|
+
open: n,
|
|
271
|
+
onOk: y,
|
|
272
|
+
onCancel: a,
|
|
273
|
+
okText: "保存",
|
|
274
|
+
cancelText: "取消",
|
|
275
|
+
destroyOnClose: !0,
|
|
276
|
+
footer: /* @__PURE__ */ g(ae, { children: [
|
|
277
|
+
f && /* @__PURE__ */ r(C, { danger: !0, onClick: () => {
|
|
278
|
+
e && l(e.id), a();
|
|
279
|
+
}, children: "删除" }),
|
|
280
|
+
/* @__PURE__ */ r(C, { onClick: a, children: "取消" }),
|
|
281
|
+
/* @__PURE__ */ r(C, { type: "primary", onClick: y, children: "保存" })
|
|
282
|
+
] }),
|
|
283
|
+
children: /* @__PURE__ */ g(k, { form: m, layout: "vertical", preserve: !1, children: [
|
|
284
|
+
/* @__PURE__ */ r(k.Item, { label: "图标", name: "icon", initialValue: h[0], rules: [{ required: !0 }], children: /* @__PURE__ */ r(Ye, { icons: o }) }),
|
|
285
|
+
/* @__PURE__ */ r(k.Item, { label: "日期", name: "date", rules: [{ required: !0, message: "请选择日期" }], children: /* @__PURE__ */ r(te, { style: { width: "100%" }, format: "YYYY-MM-DD" }) }),
|
|
286
|
+
/* @__PURE__ */ r(k.Item, { label: "时间范围", name: "timeRange", children: /* @__PURE__ */ r(
|
|
287
|
+
ne.RangePicker,
|
|
288
|
+
{
|
|
289
|
+
style: { width: "100%" },
|
|
290
|
+
format: "HH:mm",
|
|
291
|
+
minuteStep: 30,
|
|
292
|
+
placeholder: ["开始时间", "结束时间"],
|
|
293
|
+
allowClear: !0
|
|
294
|
+
}
|
|
295
|
+
) }),
|
|
296
|
+
/* @__PURE__ */ r(k.Item, { label: "名称", name: "name", rules: [{ required: !0, message: "请输入名称" }, { max: 30 }], children: /* @__PURE__ */ r(ue, { placeholder: "如:牙医复诊", maxLength: 30 }) })
|
|
297
|
+
] })
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
const Oe = 2;
|
|
302
|
+
function he(n) {
|
|
303
|
+
try {
|
|
304
|
+
const [e, t, o] = n.split("-").map(Number), a = Ee.fromYmd(e, t, o).getLunar(), i = a.getFestivals();
|
|
305
|
+
if (i.length > 0) return i[0];
|
|
306
|
+
const l = a.getJieQi();
|
|
307
|
+
return l || (a.getDay() === 1 ? `${a.getMonthInChinese()}月初一` : a.getDayInChinese());
|
|
308
|
+
} catch {
|
|
309
|
+
return "";
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function Fe(n) {
|
|
313
|
+
const { dateStr: e, day: t, inMonth: o, isToday: a, isWeekend: i, holiday: l, todoLanes: m, schedules: f, onEditSchedule: h, selected: y, onSelect: s, icons: d } = n, p = ["day-cell"];
|
|
314
|
+
o || p.push("out"), a && p.push("today"), i && p.push("weekend"), y && p.push("selected"), l && p.push(l != null && l.off ? "holiday-off" : "holiday-work");
|
|
315
|
+
const T = f.slice(0, Oe), v = f.length - T.length;
|
|
316
|
+
return /* @__PURE__ */ g(
|
|
317
|
+
"div",
|
|
318
|
+
{
|
|
319
|
+
className: p.join(" "),
|
|
320
|
+
onClick: (u) => {
|
|
321
|
+
u.stopPropagation(), s == null || s(e);
|
|
322
|
+
},
|
|
323
|
+
children: [
|
|
324
|
+
/* @__PURE__ */ g("div", { className: "day-top", children: [
|
|
325
|
+
/* @__PURE__ */ r("span", { className: "day-num", children: t }),
|
|
326
|
+
/* @__PURE__ */ g("span", { className: "day-lunar", children: [
|
|
327
|
+
(l == null ? void 0 : l.name) || he(e),
|
|
328
|
+
l && /* @__PURE__ */ r("div", { className: `day-holiday ${l.off ? "off" : "work"}`, children: l.off ? "休" : "班" })
|
|
329
|
+
] })
|
|
330
|
+
] }),
|
|
331
|
+
m > 0 && /* @__PURE__ */ r("div", { className: "todo-spacer", style: { height: m * 22 } }),
|
|
332
|
+
/* @__PURE__ */ g("div", { className: "schedule-list", children: [
|
|
333
|
+
T.map((u) => /* @__PURE__ */ r(ge, { title: [u.name, Q(u)].filter(Boolean).join(" "), children: /* @__PURE__ */ g(
|
|
334
|
+
"span",
|
|
335
|
+
{
|
|
336
|
+
className: "schedule-item",
|
|
337
|
+
onClick: (w) => {
|
|
338
|
+
w.stopPropagation(), h(u, e);
|
|
339
|
+
},
|
|
340
|
+
children: [
|
|
341
|
+
/* @__PURE__ */ r("span", { className: "schedule-icon", children: d == null ? void 0 : d[u.icon] }),
|
|
342
|
+
/* @__PURE__ */ r("span", { className: "schedule-name", children: u.name })
|
|
343
|
+
]
|
|
344
|
+
}
|
|
345
|
+
) }, u.id)),
|
|
346
|
+
v > 0 && /* @__PURE__ */ g("span", { className: "schedule-more", children: [
|
|
347
|
+
"+",
|
|
348
|
+
v,
|
|
349
|
+
" 更多"
|
|
350
|
+
] })
|
|
351
|
+
] })
|
|
352
|
+
]
|
|
353
|
+
}
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
function Le({
|
|
357
|
+
year: n,
|
|
358
|
+
month: e,
|
|
359
|
+
viewMode: t,
|
|
360
|
+
loading: o,
|
|
361
|
+
onViewModeChange: a,
|
|
362
|
+
onToday: i,
|
|
363
|
+
onPrevMonth: l,
|
|
364
|
+
onNextMonth: m,
|
|
365
|
+
isPreview: f
|
|
366
|
+
}) {
|
|
367
|
+
return /* @__PURE__ */ g("div", { className: "calendar-header", children: [
|
|
368
|
+
/* @__PURE__ */ g("span", { className: "calendar-title", children: [
|
|
369
|
+
n,
|
|
370
|
+
"年",
|
|
371
|
+
e + 1,
|
|
372
|
+
"月"
|
|
373
|
+
] }),
|
|
374
|
+
/* @__PURE__ */ r(
|
|
375
|
+
Te,
|
|
376
|
+
{
|
|
377
|
+
size: "small",
|
|
378
|
+
options: [
|
|
379
|
+
{ label: "日历", value: "all" },
|
|
380
|
+
{ label: "事项", value: "items" }
|
|
381
|
+
],
|
|
382
|
+
value: t,
|
|
383
|
+
onChange: (h) => a(h)
|
|
384
|
+
}
|
|
385
|
+
),
|
|
386
|
+
!f && /* @__PURE__ */ g(ae, { children: [
|
|
387
|
+
/* @__PURE__ */ r(C, { shape: "circle", size: "small", onClick: i, children: "今" }),
|
|
388
|
+
/* @__PURE__ */ r(C, { shape: "circle", size: "small", onClick: l, children: /* @__PURE__ */ r(ve, {}) }),
|
|
389
|
+
/* @__PURE__ */ r(C, { shape: "circle", size: "small", onClick: m, children: /* @__PURE__ */ r(Ne, {}) }),
|
|
390
|
+
o && /* @__PURE__ */ r(Se, { size: "small" })
|
|
391
|
+
] })
|
|
392
|
+
] });
|
|
393
|
+
}
|
|
394
|
+
function Re({ segs: n, onEditTodo: e }) {
|
|
395
|
+
return /* @__PURE__ */ r("div", { className: "todo-lanes", children: n.map((t, o) => {
|
|
396
|
+
const a = t.todo, i = `${a.start}${a.startTime ? ` ${a.startTime}` : ""} ~ ${a.end}${a.endTime ? ` ${a.endTime}` : ""}`, l = a.start === a.end ? Q(a) : "";
|
|
397
|
+
return /* @__PURE__ */ r(
|
|
398
|
+
"span",
|
|
399
|
+
{
|
|
400
|
+
className: `todo-bar${t.roundLeft ? " round-left" : ""}${t.roundRight ? " round-right" : ""}`,
|
|
401
|
+
title: `${a.name}(${i})`,
|
|
402
|
+
style: {
|
|
403
|
+
top: 54 + t.lane * 22,
|
|
404
|
+
left: `${t.leftEdge / 7 * 100}%`,
|
|
405
|
+
width: `${(Math.max(t.rightEdge, t.leftEdge) - t.leftEdge) / 7 * 100}%`,
|
|
406
|
+
background: a.color
|
|
407
|
+
},
|
|
408
|
+
onClick: (m) => {
|
|
409
|
+
m.stopPropagation(), e(a);
|
|
410
|
+
},
|
|
411
|
+
children: t.showLabel && /* @__PURE__ */ r("span", { className: "todo-bar-label", children: l ? `${a.name} ${l}` : a.name })
|
|
412
|
+
},
|
|
413
|
+
`${a.id}-${o}`
|
|
414
|
+
);
|
|
415
|
+
}) });
|
|
416
|
+
}
|
|
417
|
+
const _e = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
|
|
418
|
+
function ie(n, e) {
|
|
419
|
+
const t = S(n);
|
|
420
|
+
return t.year() === e ? `${t.month() + 1}月${t.date()}日` : `${t.year()}年${t.month() + 1}月${t.date()}日`;
|
|
421
|
+
}
|
|
422
|
+
function Ve({
|
|
423
|
+
dateStr: n,
|
|
424
|
+
holiday: e,
|
|
425
|
+
todos: t,
|
|
426
|
+
schedules: o,
|
|
427
|
+
onEditTodo: a,
|
|
428
|
+
onEditSchedule: i,
|
|
429
|
+
onAddTodo: l,
|
|
430
|
+
onAddSchedule: m,
|
|
431
|
+
isPreview: f
|
|
432
|
+
}) {
|
|
433
|
+
const h = S(n), y = h.year();
|
|
434
|
+
return /* @__PURE__ */ g("div", { className: "day-panel", children: [
|
|
435
|
+
/* @__PURE__ */ g("div", { className: "day-panel-header", children: [
|
|
436
|
+
/* @__PURE__ */ g("div", { className: "day-panel-title", children: [
|
|
437
|
+
h.year(),
|
|
438
|
+
"年",
|
|
439
|
+
h.month() + 1,
|
|
440
|
+
"月",
|
|
441
|
+
h.date(),
|
|
442
|
+
"日 ",
|
|
443
|
+
_e[h.day()],
|
|
444
|
+
!f && /* @__PURE__ */ g("div", { className: "day-panel-actions", children: [
|
|
445
|
+
/* @__PURE__ */ r(C, { size: "small", onClick: l, children: "添加待办" }),
|
|
446
|
+
/* @__PURE__ */ r(C, { size: "small", onClick: m, children: "添加日程" })
|
|
447
|
+
] })
|
|
448
|
+
] }),
|
|
449
|
+
/* @__PURE__ */ r("span", { className: "day-panel-sub", children: e != null && e.name ? e.name : he(n) || " " })
|
|
450
|
+
] }),
|
|
451
|
+
!!t.length && /* @__PURE__ */ g("div", { className: "day-panel-section", children: [
|
|
452
|
+
/* @__PURE__ */ g("div", { className: "day-panel-subtitle", children: [
|
|
453
|
+
"待办(",
|
|
454
|
+
t.length,
|
|
455
|
+
")"
|
|
456
|
+
] }),
|
|
457
|
+
t.map((s) => /* @__PURE__ */ g(
|
|
458
|
+
"div",
|
|
459
|
+
{
|
|
460
|
+
className: "day-panel-todo",
|
|
461
|
+
onClick: () => a(s),
|
|
462
|
+
title: "点击编辑",
|
|
463
|
+
children: [
|
|
464
|
+
/* @__PURE__ */ r("span", { className: "day-panel-todo-dot", style: { background: s.color } }),
|
|
465
|
+
/* @__PURE__ */ r("span", { className: "day-panel-todo-name", children: s.name }),
|
|
466
|
+
/* @__PURE__ */ g("span", { className: "day-panel-todo-range", children: [
|
|
467
|
+
ie(s.start, y),
|
|
468
|
+
s.startTime ? ` ${s.startTime}` : "",
|
|
469
|
+
" ~ ",
|
|
470
|
+
ie(s.end, y),
|
|
471
|
+
s.endTime ? ` ${s.endTime}` : ""
|
|
472
|
+
] })
|
|
473
|
+
]
|
|
474
|
+
},
|
|
475
|
+
s.id
|
|
476
|
+
))
|
|
477
|
+
] }),
|
|
478
|
+
!!o.length && /* @__PURE__ */ g("div", { className: "day-panel-section", children: [
|
|
479
|
+
/* @__PURE__ */ g("div", { className: "day-panel-subtitle", children: [
|
|
480
|
+
"日程(",
|
|
481
|
+
o.length,
|
|
482
|
+
")"
|
|
483
|
+
] }),
|
|
484
|
+
o.map((s) => /* @__PURE__ */ g(
|
|
485
|
+
"div",
|
|
486
|
+
{
|
|
487
|
+
className: "day-panel-schedule",
|
|
488
|
+
onClick: () => i(s),
|
|
489
|
+
title: "点击编辑",
|
|
490
|
+
children: [
|
|
491
|
+
/* @__PURE__ */ r("span", { className: "day-panel-schedule-icon", children: s.icon }),
|
|
492
|
+
/* @__PURE__ */ r("span", { className: "day-panel-schedule-name", children: s.name }),
|
|
493
|
+
Q(s) && /* @__PURE__ */ r("span", { className: "day-panel-schedule-time", children: Q(s) })
|
|
494
|
+
]
|
|
495
|
+
},
|
|
496
|
+
s.id
|
|
497
|
+
))
|
|
498
|
+
] }),
|
|
499
|
+
o.length === 0 && /* @__PURE__ */ r(X, { image: X.PRESENTED_IMAGE_SIMPLE, description: "本月暂无待办和日程" })
|
|
500
|
+
] });
|
|
501
|
+
}
|
|
502
|
+
function de(n) {
|
|
503
|
+
const [e, t] = n.split(":").map(Number);
|
|
504
|
+
return e * 60 + t;
|
|
505
|
+
}
|
|
506
|
+
function je(n, e) {
|
|
507
|
+
const t = n.startTime ? de(n.startTime) : 0, o = n.endTime ? de(n.endTime) : 1440, a = I(e);
|
|
508
|
+
return n.start === n.end ? [t, o] : a === n.start ? [t, 1440] : a === n.end ? [0, o] : [0, 1440];
|
|
509
|
+
}
|
|
510
|
+
function Ae(n, e) {
|
|
511
|
+
const t = {};
|
|
512
|
+
e.forEach((s, d) => {
|
|
513
|
+
t[I(s.date)] = d;
|
|
514
|
+
});
|
|
515
|
+
const o = I(e[0].date), a = I(e[e.length - 1].date), i = new Array(e.length).fill(0), l = [], f = [...n].sort((s, d) => {
|
|
516
|
+
if (s.start !== d.start) return s.start.localeCompare(d.start);
|
|
517
|
+
const p = s.startTime ?? "00:00", T = d.startTime ?? "00:00";
|
|
518
|
+
return p !== T ? p.localeCompare(T) : s.end !== d.end ? s.end.localeCompare(d.end) : (s.endTime ?? "23:59").localeCompare(d.endTime ?? "23:59");
|
|
519
|
+
}).filter((s) => !(s.end < o || s.start > a)).map((s) => ({
|
|
520
|
+
original: s,
|
|
521
|
+
cs: s.start < o ? o : s.start,
|
|
522
|
+
ce: s.end > a ? a : s.end
|
|
523
|
+
})).filter((s) => {
|
|
524
|
+
const d = t[s.cs], p = t[s.ce];
|
|
525
|
+
return d !== void 0 && p !== void 0;
|
|
526
|
+
}), h = Math.ceil(e.length / 7);
|
|
527
|
+
for (let s = 0; s < h; s++) {
|
|
528
|
+
const d = s * 7, p = Math.min(d + 6, e.length - 1), T = Array.from({ length: 7 }, () => [[], [], []]), v = f.filter((u) => {
|
|
529
|
+
const w = t[u.cs];
|
|
530
|
+
return t[u.ce] >= d && w <= p;
|
|
531
|
+
});
|
|
532
|
+
for (const { original: u, cs: w, ce: H } of v) {
|
|
533
|
+
const A = t[w], F = t[H], $ = Math.max(A, d) - d, Y = Math.min(F, p) - d, x = [];
|
|
534
|
+
for (let E = $; E <= Y; E++)
|
|
535
|
+
x.push(je(u, e[d + E].date));
|
|
536
|
+
let _ = -1;
|
|
537
|
+
for (let E = 0; E < 3; E++) {
|
|
538
|
+
let O = !0;
|
|
539
|
+
for (let b = $; b <= Y && O; b++) {
|
|
540
|
+
const [V, P] = x[b - $];
|
|
541
|
+
V >= P || (O = !T[b][E].some((B) => B.s < P && V < B.e));
|
|
542
|
+
}
|
|
543
|
+
if (O) {
|
|
544
|
+
_ = E;
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (_ === -1) continue;
|
|
549
|
+
const q = A >= d && w === u.start, M = F <= p && H === u.end, [L] = x[0], [, R] = x[x.length - 1], U = $ + (q ? L / 1440 : 0), K = M ? Y + R / 1440 : Y + 1;
|
|
550
|
+
l.push({
|
|
551
|
+
todo: u,
|
|
552
|
+
weekRow: s,
|
|
553
|
+
startCol: $,
|
|
554
|
+
endCol: Y,
|
|
555
|
+
leftEdge: U,
|
|
556
|
+
rightEdge: K,
|
|
557
|
+
lane: _,
|
|
558
|
+
// ✅ 相对于本周的泳道号,每周从0开始
|
|
559
|
+
showLabel: q,
|
|
560
|
+
roundLeft: q,
|
|
561
|
+
roundRight: M
|
|
562
|
+
});
|
|
563
|
+
for (let E = $; E <= Y; E++) {
|
|
564
|
+
const [O, b] = x[E - $];
|
|
565
|
+
O < b && T[E][_].push({ s: O, e: b });
|
|
566
|
+
}
|
|
567
|
+
for (let E = $; E <= Y; E++) {
|
|
568
|
+
const [O, b] = x[E - $];
|
|
569
|
+
if (O < b) {
|
|
570
|
+
const V = d + E;
|
|
571
|
+
i[V] < _ + 1 && (i[V] = _ + 1);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
const y = {};
|
|
577
|
+
return e.forEach((s, d) => {
|
|
578
|
+
i[d] > 0 && (y[I(s.date)] = i[d]);
|
|
579
|
+
}), { todoSegs: l, todoLanesByDate: y };
|
|
580
|
+
}
|
|
581
|
+
function Pe(n, e, t, o, a) {
|
|
582
|
+
const i = `${o}-${String(a + 1).padStart(2, "0")}-01`, l = S(new Date(o, a + 1, 0)), m = `${l.year()}-${String(l.month() + 1).padStart(2, "0")}-${String(l.date()).padStart(2, "0")}`, f = /* @__PURE__ */ new Set();
|
|
583
|
+
return n.forEach((h) => {
|
|
584
|
+
const y = h.start < i ? i : h.start, s = h.end > m ? m : h.end;
|
|
585
|
+
if (s < y) return;
|
|
586
|
+
let d = S(y);
|
|
587
|
+
for (; I(d) <= s; ) {
|
|
588
|
+
const p = t[I(d)];
|
|
589
|
+
p !== void 0 && f.add(Math.floor(p / 7)), d = d.add(1, "day");
|
|
590
|
+
}
|
|
591
|
+
}), e.forEach((h) => {
|
|
592
|
+
if (h.date >= i && h.date <= m) {
|
|
593
|
+
const y = t[h.date];
|
|
594
|
+
y !== void 0 && f.add(Math.floor(y / 7));
|
|
595
|
+
}
|
|
596
|
+
}), f.size === 0 ? null : { min: Math.min(...f), max: Math.max(...f) };
|
|
597
|
+
}
|
|
598
|
+
function ze(n, e, t) {
|
|
599
|
+
if (e === "all")
|
|
600
|
+
return n.map((a, i) => ({ week: a, rowIndex: i }));
|
|
601
|
+
if (!t) return [];
|
|
602
|
+
const o = [];
|
|
603
|
+
for (let a = t.min; a <= t.max; a++)
|
|
604
|
+
o.push({ week: n[a], rowIndex: a });
|
|
605
|
+
return o;
|
|
606
|
+
}
|
|
607
|
+
const We = ["日", "一", "二", "三", "四", "五", "六"];
|
|
608
|
+
function Xe({
|
|
609
|
+
todos: n,
|
|
610
|
+
schedules: e,
|
|
611
|
+
onSaveTodo: t,
|
|
612
|
+
onDeleteTodo: o,
|
|
613
|
+
onSaveSchedule: a,
|
|
614
|
+
onDeleteSchedule: i,
|
|
615
|
+
isPreview: l,
|
|
616
|
+
icons: m
|
|
617
|
+
}) {
|
|
618
|
+
const [f, h] = W(S()), [y, s] = W({}), [d, p] = W(!1), [T, v] = Ie("calendar_view_mode", l ? "items" : "all"), [u, w] = W(I(S())), [H, A] = W({ open: !1, editing: null }), [F, $] = W({ open: !1, editing: null }), Y = (c) => {
|
|
619
|
+
l || A({ open: !0, editing: c });
|
|
620
|
+
}, x = (c, N) => {
|
|
621
|
+
l || $({ open: !0, editing: c });
|
|
622
|
+
}, _ = (c) => {
|
|
623
|
+
l || A({ open: !0, editing: null, initialStart: c, initialEnd: c });
|
|
624
|
+
}, q = (c) => {
|
|
625
|
+
l || $({ open: !0, editing: null, initialDate: c });
|
|
626
|
+
}, M = f.year(), L = f.month();
|
|
627
|
+
J(() => {
|
|
628
|
+
let c = !1;
|
|
629
|
+
return p(!0), we(M).then((N) => {
|
|
630
|
+
c || s(N);
|
|
631
|
+
}).catch(() => {
|
|
632
|
+
c || s({});
|
|
633
|
+
}).finally(() => {
|
|
634
|
+
c || p(!1);
|
|
635
|
+
}), () => {
|
|
636
|
+
c = !0;
|
|
637
|
+
};
|
|
638
|
+
}, [M]);
|
|
639
|
+
const R = j(() => Me(M, L), [M, L]), U = j(() => be(y), [y]), K = j(() => {
|
|
640
|
+
const c = {};
|
|
641
|
+
return e.forEach((N) => {
|
|
642
|
+
var D;
|
|
643
|
+
(c[D = N.date] ?? (c[D] = [])).push(N);
|
|
644
|
+
}), Object.values(c).forEach(
|
|
645
|
+
(N) => N.sort((D, ee) => ce(D).localeCompare(ce(ee)))
|
|
646
|
+
), c;
|
|
647
|
+
}, [e]), E = j(() => {
|
|
648
|
+
const c = [];
|
|
649
|
+
for (let N = 0; N < R.length; N += 7) c.push(R.slice(N, N + 7));
|
|
650
|
+
return c;
|
|
651
|
+
}, [R]), { todoSegs: O, todoLanesByDate: b } = j(() => Ae(n, R), [n, R]), V = I(S()), P = j(() => {
|
|
652
|
+
const c = {};
|
|
653
|
+
return R.forEach((N, D) => {
|
|
654
|
+
c[I(N.date)] = D;
|
|
655
|
+
}), c;
|
|
656
|
+
}, [R]), B = `${M}-${String(L + 1).padStart(2, "0")}-01`;
|
|
657
|
+
J(() => {
|
|
658
|
+
if (!u || P[u] !== void 0) return;
|
|
659
|
+
const c = V;
|
|
660
|
+
w(P[c] !== void 0 && c.startsWith(B.slice(0, 8)) ? c : B);
|
|
661
|
+
}, [M, L]);
|
|
662
|
+
const fe = (c) => {
|
|
663
|
+
w((N) => N === c ? null : c);
|
|
664
|
+
}, re = j(
|
|
665
|
+
() => Pe(n, e, P, M, L),
|
|
666
|
+
[n, e, M, L, P]
|
|
667
|
+
), se = j(
|
|
668
|
+
() => ze(E, T, re),
|
|
669
|
+
[E, T, re]
|
|
670
|
+
);
|
|
671
|
+
return /* @__PURE__ */ g(ye, { children: [
|
|
672
|
+
/* @__PURE__ */ g("div", { className: "calendar", children: [
|
|
673
|
+
/* @__PURE__ */ r(
|
|
674
|
+
Le,
|
|
675
|
+
{
|
|
676
|
+
isPreview: l,
|
|
677
|
+
year: M,
|
|
678
|
+
month: L,
|
|
679
|
+
viewMode: T,
|
|
680
|
+
loading: d,
|
|
681
|
+
onViewModeChange: v,
|
|
682
|
+
onToday: () => h(S()),
|
|
683
|
+
onPrevMonth: () => h(f.subtract(1, "month")),
|
|
684
|
+
onNextMonth: () => h(f.add(1, "month"))
|
|
685
|
+
}
|
|
686
|
+
),
|
|
687
|
+
/* @__PURE__ */ r("div", { className: "week-row", children: We.map((c) => /* @__PURE__ */ r("div", { className: "week-cell", children: c }, c)) }),
|
|
688
|
+
/* @__PURE__ */ r("div", { className: "day-grid", children: se.length === 0 ? /* @__PURE__ */ r("div", { className: "calendar-empty", children: /* @__PURE__ */ r(X, { image: X.PRESENTED_IMAGE_SIMPLE, description: "本月暂无待办和日程" }) }) : se.map(({ week: c, rowIndex: N }) => /* @__PURE__ */ g("div", { className: "day-week", children: [
|
|
689
|
+
c.map(({ date: D, inMonth: ee }) => {
|
|
690
|
+
const z = I(D), le = D.day(), pe = le === 0 || le === 6;
|
|
691
|
+
return /* @__PURE__ */ r(
|
|
692
|
+
Fe,
|
|
693
|
+
{
|
|
694
|
+
dateStr: z,
|
|
695
|
+
day: D.date(),
|
|
696
|
+
inMonth: ee,
|
|
697
|
+
isToday: z === V,
|
|
698
|
+
isWeekend: pe,
|
|
699
|
+
holiday: U[z],
|
|
700
|
+
todoLanes: b[z] ?? 0,
|
|
701
|
+
schedules: K[z] ?? [],
|
|
702
|
+
onEditSchedule: x,
|
|
703
|
+
icons: m,
|
|
704
|
+
selected: u === z,
|
|
705
|
+
onSelect: fe
|
|
706
|
+
},
|
|
707
|
+
z
|
|
708
|
+
);
|
|
709
|
+
}),
|
|
710
|
+
/* @__PURE__ */ r(Re, { segs: O.filter((D) => D.weekRow === N), onEditTodo: Y })
|
|
711
|
+
] }, N)) })
|
|
712
|
+
] }),
|
|
713
|
+
u && /* @__PURE__ */ r(
|
|
714
|
+
Ve,
|
|
715
|
+
{
|
|
716
|
+
dateStr: u,
|
|
717
|
+
holiday: U[u],
|
|
718
|
+
todos: n.filter((c) => c.start <= u && u <= c.end),
|
|
719
|
+
schedules: K[u] ?? [],
|
|
720
|
+
onEditTodo: Y,
|
|
721
|
+
onEditSchedule: (c) => x(c),
|
|
722
|
+
onAddTodo: () => _(u),
|
|
723
|
+
onAddSchedule: () => q(u),
|
|
724
|
+
isPreview: l
|
|
725
|
+
}
|
|
726
|
+
),
|
|
727
|
+
/* @__PURE__ */ r(
|
|
728
|
+
He,
|
|
729
|
+
{
|
|
730
|
+
open: H.open,
|
|
731
|
+
editing: H.editing,
|
|
732
|
+
initialStart: H.initialStart,
|
|
733
|
+
initialEnd: H.initialEnd,
|
|
734
|
+
onClose: () => A({ open: !1, editing: null }),
|
|
735
|
+
onSave: (c) => t == null ? void 0 : t(c),
|
|
736
|
+
onDelete: (c) => o == null ? void 0 : o(c)
|
|
737
|
+
}
|
|
738
|
+
),
|
|
739
|
+
/* @__PURE__ */ r(
|
|
740
|
+
xe,
|
|
741
|
+
{
|
|
742
|
+
open: F.open,
|
|
743
|
+
editing: F.editing,
|
|
744
|
+
initialDate: F.initialDate,
|
|
745
|
+
icons: m ?? {},
|
|
746
|
+
onClose: () => $({ open: !1, editing: null }),
|
|
747
|
+
onSave: (c) => a == null ? void 0 : a(c),
|
|
748
|
+
onDelete: (c) => i == null ? void 0 : i(c)
|
|
749
|
+
}
|
|
750
|
+
)
|
|
751
|
+
] });
|
|
752
|
+
}
|
|
753
|
+
export {
|
|
754
|
+
Xe as Calendar
|
|
755
|
+
};
|