@object-ui/plugin-calendar 4.0.7 → 4.0.8
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/CHANGELOG.md +14 -0
- package/README.md +61 -0
- package/dist/index.js +912 -366
- package/dist/index.umd.cjs +1 -1
- package/dist/packages/plugin-calendar/src/CalendarView.d.ts +26 -1
- package/dist/packages/plugin-calendar/src/CalendarView.d.ts.map +1 -1
- package/dist/packages/plugin-calendar/src/ObjectCalendar.d.ts.map +1 -1
- package/package.json +11 -10
package/dist/index.js
CHANGED
|
@@ -3,25 +3,48 @@ import t, { useCallback as n, useEffect as r, useMemo as i, useRef as a, useStat
|
|
|
3
3
|
import { ComponentRegistry as s, buildExpandFields as c, extractRecords as l } from "@object-ui/core";
|
|
4
4
|
import { useNavigationOverlay as u, useSchemaContext as d } from "@object-ui/react";
|
|
5
5
|
import { CalendarIcon as f, ChevronLeftIcon as p, ChevronRightIcon as m, PlusIcon as h } from "lucide-react";
|
|
6
|
-
import { Button as g, Calendar as _,
|
|
7
|
-
import { useObjectTranslation as
|
|
8
|
-
import { jsx as
|
|
9
|
-
import { usePullToRefresh as
|
|
6
|
+
import { Button as g, Calendar as _, Dialog as v, DialogContent as y, DialogDescription as b, DialogFooter as x, DialogHeader as S, DialogTitle as C, Input as w, Label as T, Popover as E, PopoverContent as D, PopoverTrigger as O, Select as k, SelectContent as A, SelectItem as j, SelectTrigger as ee, SelectValue as M, cn as N, useIsMobile as P } from "@object-ui/components";
|
|
7
|
+
import { useObjectTranslation as F } from "@object-ui/i18n";
|
|
8
|
+
import { Fragment as te, jsx as I, jsxs as L } from "react/jsx-runtime";
|
|
9
|
+
import { usePullToRefresh as ne } from "@object-ui/mobile";
|
|
10
|
+
import { RecordDetailDrawer as re, deriveRecordPageHref as ie } from "@object-ui/plugin-detail";
|
|
10
11
|
//#region src/CalendarView.tsx
|
|
11
|
-
var
|
|
12
|
+
var R = "bg-blue-500 text-white", ae = /* @__PURE__ */ new Date(), z = [
|
|
13
|
+
"bg-blue-500 text-white",
|
|
14
|
+
"bg-emerald-500 text-white",
|
|
15
|
+
"bg-amber-500 text-black",
|
|
16
|
+
"bg-rose-500 text-white",
|
|
17
|
+
"bg-violet-500 text-white",
|
|
18
|
+
"bg-cyan-500 text-black",
|
|
19
|
+
"bg-orange-500 text-white",
|
|
20
|
+
"bg-fuchsia-500 text-white"
|
|
21
|
+
], oe = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i, se = /(^|\s)(bg|text|from|to|via)-/;
|
|
22
|
+
function B(e) {
|
|
23
|
+
if (!e) return { className: R };
|
|
24
|
+
if (oe.test(e)) return {
|
|
25
|
+
className: "text-white",
|
|
26
|
+
inlineColor: e
|
|
27
|
+
};
|
|
28
|
+
if (se.test(e)) return { className: e };
|
|
29
|
+
let t = 0;
|
|
30
|
+
for (let n = 0; n < e.length; n++) t = (t << 5) - t + e.charCodeAt(n) | 0;
|
|
31
|
+
return { className: z[Math.abs(t) % z.length] };
|
|
32
|
+
}
|
|
33
|
+
var V = {
|
|
12
34
|
"calendar.today": "Today",
|
|
13
35
|
"calendar.month": "Month",
|
|
14
36
|
"calendar.week": "Week",
|
|
15
37
|
"calendar.day": "Day",
|
|
16
38
|
"calendar.newEvent": "New event",
|
|
17
|
-
"calendar.moreEvents": "+{{count}} more"
|
|
39
|
+
"calendar.moreEvents": "+{{count}} more",
|
|
40
|
+
"calendar.allDay": "all-day"
|
|
18
41
|
};
|
|
19
|
-
function
|
|
42
|
+
function H() {
|
|
20
43
|
try {
|
|
21
|
-
let e =
|
|
44
|
+
let e = F();
|
|
22
45
|
return e.t("calendar.today") === "calendar.today" ? {
|
|
23
46
|
t: (e, t) => {
|
|
24
|
-
let n =
|
|
47
|
+
let n = V[e] || e;
|
|
25
48
|
if (t) for (let [e, r] of Object.entries(t)) n = n.replace(`{{${e}}}`, String(r));
|
|
26
49
|
return n;
|
|
27
50
|
},
|
|
@@ -33,7 +56,7 @@ function I() {
|
|
|
33
56
|
} catch {
|
|
34
57
|
return {
|
|
35
58
|
t: (e, t) => {
|
|
36
|
-
let n =
|
|
59
|
+
let n = V[e] || e;
|
|
37
60
|
if (t) for (let [e, r] of Object.entries(t)) n = n.replace(`{{${e}}}`, String(r));
|
|
38
61
|
return n;
|
|
39
62
|
},
|
|
@@ -41,184 +64,191 @@ function I() {
|
|
|
41
64
|
};
|
|
42
65
|
}
|
|
43
66
|
}
|
|
44
|
-
function
|
|
45
|
-
let [
|
|
67
|
+
function ce({ events: t = [], view: n = "month", currentDate: r = ae, locale: i = "default", onEventClick: a, onDateClick: o, onViewChange: s, onNavigate: c, onAddClick: l, onEventDrop: u, onTimeRangeSelect: d, slotMinutes: v = 30, className: y }) {
|
|
68
|
+
let [b, x] = e.useState(n), [S, C] = e.useState(r), { t: w, language: T } = H(), P = i === "default" ? T : i;
|
|
46
69
|
e.useEffect(() => {
|
|
47
|
-
|
|
70
|
+
C(r);
|
|
48
71
|
}, [r]), e.useEffect(() => {
|
|
49
|
-
|
|
72
|
+
x(n);
|
|
50
73
|
}, [n]);
|
|
51
|
-
let
|
|
52
|
-
|
|
74
|
+
let F = e.useRef(s);
|
|
75
|
+
F.current = s, e.useEffect(() => {
|
|
53
76
|
let e = window.matchMedia("(max-width: 639px)"), t = (e) => {
|
|
54
|
-
e.matches && (
|
|
77
|
+
e.matches && (x("day"), F.current?.("day"));
|
|
55
78
|
};
|
|
56
79
|
return t(e), e.addEventListener("change", t), () => e.removeEventListener("change", t);
|
|
57
80
|
}, []);
|
|
58
|
-
let
|
|
59
|
-
let e = new Date(
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
let e = new Date(
|
|
63
|
-
|
|
64
|
-
},
|
|
81
|
+
let te = () => {
|
|
82
|
+
let e = new Date(S);
|
|
83
|
+
b === "month" ? e.setMonth(e.getMonth() - 1) : b === "week" ? e.setDate(e.getDate() - 7) : e.setDate(e.getDate() - 1), C(e), c?.(e);
|
|
84
|
+
}, ne = () => {
|
|
85
|
+
let e = new Date(S);
|
|
86
|
+
b === "month" ? e.setMonth(e.getMonth() + 1) : b === "week" ? e.setDate(e.getDate() + 7) : e.setDate(e.getDate() + 1), C(e), c?.(e);
|
|
87
|
+
}, re = () => {
|
|
65
88
|
let e = /* @__PURE__ */ new Date();
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
if (
|
|
89
|
+
C(e), c?.(e);
|
|
90
|
+
}, ie = (e) => {
|
|
91
|
+
x(e), s?.(e);
|
|
92
|
+
}, R = () => {
|
|
93
|
+
if (b === "month") return S.toLocaleDateString(P, {
|
|
71
94
|
month: "long",
|
|
72
95
|
year: "numeric"
|
|
73
96
|
});
|
|
74
|
-
if (
|
|
75
|
-
let e =
|
|
76
|
-
return t.setDate(t.getDate() + 6), `${e.toLocaleDateString(
|
|
97
|
+
if (b === "week") {
|
|
98
|
+
let e = le(S), t = new Date(e);
|
|
99
|
+
return t.setDate(t.getDate() + 6), `${e.toLocaleDateString(P, {
|
|
77
100
|
month: "short",
|
|
78
101
|
day: "numeric"
|
|
79
|
-
})} - ${t.toLocaleDateString(
|
|
102
|
+
})} - ${t.toLocaleDateString(P, {
|
|
80
103
|
month: "short",
|
|
81
104
|
day: "numeric",
|
|
82
105
|
year: "numeric"
|
|
83
106
|
})}`;
|
|
84
|
-
} else return
|
|
107
|
+
} else return S.toLocaleDateString(P, {
|
|
85
108
|
weekday: "long",
|
|
86
109
|
month: "long",
|
|
87
110
|
day: "numeric",
|
|
88
111
|
year: "numeric"
|
|
89
112
|
});
|
|
90
|
-
},
|
|
91
|
-
return /* @__PURE__ */
|
|
113
|
+
}, z = e.useRef(0);
|
|
114
|
+
return /* @__PURE__ */ L("div", {
|
|
92
115
|
role: "region",
|
|
93
116
|
"aria-label": "Calendar",
|
|
94
|
-
className:
|
|
95
|
-
children: [/* @__PURE__ */
|
|
117
|
+
className: N("flex flex-col h-full bg-background min-w-0 overflow-hidden", y),
|
|
118
|
+
children: [/* @__PURE__ */ L("div", {
|
|
96
119
|
className: "flex flex-wrap items-center justify-between gap-2 p-2 sm:p-4 border-b min-w-0",
|
|
97
|
-
children: [/* @__PURE__ */
|
|
120
|
+
children: [/* @__PURE__ */ L("div", {
|
|
98
121
|
className: "flex items-center gap-4",
|
|
99
|
-
children: [/* @__PURE__ */
|
|
122
|
+
children: [/* @__PURE__ */ L("div", {
|
|
100
123
|
className: "flex items-center bg-muted/50 rounded-lg p-1 gap-1",
|
|
101
124
|
children: [
|
|
102
|
-
/* @__PURE__ */
|
|
125
|
+
/* @__PURE__ */ I(g, {
|
|
103
126
|
variant: "ghost",
|
|
104
127
|
size: "sm",
|
|
105
|
-
onClick:
|
|
128
|
+
onClick: re,
|
|
106
129
|
className: "h-8",
|
|
107
130
|
"aria-label": "Go to today",
|
|
108
|
-
children:
|
|
131
|
+
children: w("calendar.today")
|
|
109
132
|
}),
|
|
110
|
-
/* @__PURE__ */
|
|
111
|
-
/* @__PURE__ */
|
|
133
|
+
/* @__PURE__ */ I("div", { className: "h-4 w-px bg-border mx-1" }),
|
|
134
|
+
/* @__PURE__ */ I(g, {
|
|
112
135
|
variant: "ghost",
|
|
113
136
|
size: "icon",
|
|
114
137
|
"aria-label": "Previous period",
|
|
115
|
-
onClick:
|
|
138
|
+
onClick: te,
|
|
116
139
|
className: "h-8 w-8",
|
|
117
|
-
children: /* @__PURE__ */
|
|
140
|
+
children: /* @__PURE__ */ I(p, { className: "h-4 w-4" })
|
|
118
141
|
}),
|
|
119
|
-
/* @__PURE__ */
|
|
142
|
+
/* @__PURE__ */ I(g, {
|
|
120
143
|
variant: "ghost",
|
|
121
144
|
size: "icon",
|
|
122
145
|
"aria-label": "Next period",
|
|
123
|
-
onClick:
|
|
146
|
+
onClick: ne,
|
|
124
147
|
className: "h-8 w-8",
|
|
125
|
-
children: /* @__PURE__ */
|
|
148
|
+
children: /* @__PURE__ */ I(m, { className: "h-4 w-4" })
|
|
126
149
|
})
|
|
127
150
|
]
|
|
128
|
-
}), /* @__PURE__ */
|
|
151
|
+
}), /* @__PURE__ */ L(E, { children: [/* @__PURE__ */ I(O, {
|
|
129
152
|
asChild: !0,
|
|
130
|
-
children: /* @__PURE__ */
|
|
153
|
+
children: /* @__PURE__ */ L(g, {
|
|
131
154
|
variant: "ghost",
|
|
132
|
-
"aria-label": `Current date: ${
|
|
133
|
-
className:
|
|
134
|
-
children: [/* @__PURE__ */
|
|
155
|
+
"aria-label": `Current date: ${R()}`,
|
|
156
|
+
className: N("text-base sm:text-xl font-semibold h-auto px-2 sm:px-3 py-1 hover:bg-muted/50 transition-colors", "flex items-center gap-2"),
|
|
157
|
+
children: [/* @__PURE__ */ I(f, { className: "h-5 w-5 text-muted-foreground" }), /* @__PURE__ */ I("span", { children: R() })]
|
|
135
158
|
})
|
|
136
|
-
}), /* @__PURE__ */
|
|
159
|
+
}), /* @__PURE__ */ I(D, {
|
|
137
160
|
className: "w-auto p-0",
|
|
138
161
|
align: "start",
|
|
139
|
-
children: /* @__PURE__ */
|
|
162
|
+
children: /* @__PURE__ */ I(_, {
|
|
140
163
|
mode: "single",
|
|
141
|
-
selected:
|
|
164
|
+
selected: S,
|
|
142
165
|
onSelect: (e) => {
|
|
143
|
-
e && (
|
|
166
|
+
e && (C(e), c?.(e));
|
|
144
167
|
},
|
|
145
168
|
initialFocus: !0,
|
|
146
169
|
fromYear: 2e3,
|
|
147
170
|
toYear: 2050
|
|
148
171
|
})
|
|
149
172
|
})] })]
|
|
150
|
-
}), /* @__PURE__ */
|
|
173
|
+
}), /* @__PURE__ */ L("div", {
|
|
151
174
|
className: "flex items-center gap-2",
|
|
152
|
-
children: [/* @__PURE__ */
|
|
153
|
-
value:
|
|
154
|
-
onValueChange:
|
|
155
|
-
children: [/* @__PURE__ */
|
|
175
|
+
children: [/* @__PURE__ */ L(k, {
|
|
176
|
+
value: b,
|
|
177
|
+
onValueChange: ie,
|
|
178
|
+
children: [/* @__PURE__ */ I(ee, {
|
|
156
179
|
className: "w-32 bg-background",
|
|
157
|
-
children: /* @__PURE__ */
|
|
158
|
-
}), /* @__PURE__ */
|
|
159
|
-
/* @__PURE__ */
|
|
180
|
+
children: /* @__PURE__ */ I(M, {})
|
|
181
|
+
}), /* @__PURE__ */ L(A, { children: [
|
|
182
|
+
/* @__PURE__ */ I(j, {
|
|
160
183
|
value: "day",
|
|
161
|
-
children:
|
|
184
|
+
children: w("calendar.day")
|
|
162
185
|
}),
|
|
163
|
-
/* @__PURE__ */
|
|
186
|
+
/* @__PURE__ */ I(j, {
|
|
164
187
|
value: "week",
|
|
165
|
-
children:
|
|
188
|
+
children: w("calendar.week")
|
|
166
189
|
}),
|
|
167
|
-
/* @__PURE__ */
|
|
190
|
+
/* @__PURE__ */ I(j, {
|
|
168
191
|
value: "month",
|
|
169
|
-
children:
|
|
192
|
+
children: w("calendar.month")
|
|
170
193
|
})
|
|
171
194
|
] })]
|
|
172
|
-
}), l && /* @__PURE__ */
|
|
195
|
+
}), l && /* @__PURE__ */ L(g, {
|
|
173
196
|
onClick: l,
|
|
174
197
|
size: "sm",
|
|
175
198
|
className: "gap-1",
|
|
176
|
-
children: [/* @__PURE__ */
|
|
199
|
+
children: [/* @__PURE__ */ I(h, { className: "h-4 w-4" }), w("calendar.newEvent")]
|
|
177
200
|
})]
|
|
178
201
|
})]
|
|
179
|
-
}), /* @__PURE__ */
|
|
202
|
+
}), /* @__PURE__ */ L("div", {
|
|
180
203
|
className: "flex-1 overflow-auto",
|
|
181
204
|
onTouchStart: (e) => {
|
|
182
|
-
|
|
205
|
+
z.current = e.touches[0].clientX;
|
|
183
206
|
},
|
|
184
207
|
onTouchEnd: (e) => {
|
|
185
|
-
let t =
|
|
208
|
+
let t = z.current - e.changedTouches[0].clientX;
|
|
186
209
|
if (Math.abs(t) > 50) {
|
|
187
|
-
let e = new Date(
|
|
188
|
-
|
|
210
|
+
let e = new Date(S);
|
|
211
|
+
b === "day" ? e.setDate(e.getDate() + (t > 0 ? 1 : -1)) : b === "week" ? e.setDate(e.getDate() + (t > 0 ? 7 : -7)) : e.setMonth(e.getMonth() + (t > 0 ? 1 : -1)), C(e), c?.(e);
|
|
189
212
|
}
|
|
190
213
|
},
|
|
191
214
|
children: [
|
|
192
|
-
|
|
193
|
-
date:
|
|
215
|
+
b === "month" && /* @__PURE__ */ I(fe, {
|
|
216
|
+
date: S,
|
|
194
217
|
events: t,
|
|
195
|
-
locale:
|
|
218
|
+
locale: P,
|
|
196
219
|
onEventClick: a,
|
|
197
220
|
onDateClick: o,
|
|
198
221
|
onEventDrop: u
|
|
199
222
|
}),
|
|
200
|
-
|
|
201
|
-
|
|
223
|
+
b === "week" && /* @__PURE__ */ I(q, {
|
|
224
|
+
mode: "week",
|
|
225
|
+
date: S,
|
|
202
226
|
events: t,
|
|
203
|
-
locale:
|
|
227
|
+
locale: P,
|
|
228
|
+
slotMinutes: v,
|
|
204
229
|
onEventClick: a,
|
|
205
|
-
|
|
230
|
+
onEventDrop: u,
|
|
231
|
+
onTimeRangeSelect: d
|
|
206
232
|
}),
|
|
207
|
-
|
|
208
|
-
|
|
233
|
+
b === "day" && /* @__PURE__ */ I(q, {
|
|
234
|
+
mode: "day",
|
|
235
|
+
date: S,
|
|
209
236
|
events: t,
|
|
237
|
+
locale: P,
|
|
238
|
+
slotMinutes: v,
|
|
210
239
|
onEventClick: a,
|
|
211
|
-
|
|
240
|
+
onEventDrop: u,
|
|
241
|
+
onTimeRangeSelect: d
|
|
212
242
|
})
|
|
213
243
|
]
|
|
214
244
|
})]
|
|
215
245
|
});
|
|
216
246
|
}
|
|
217
|
-
function
|
|
247
|
+
function le(e) {
|
|
218
248
|
let t = new Date(e), n = t.getDay(), r = t.getDate() - n;
|
|
219
249
|
return t.setDate(r), t;
|
|
220
250
|
}
|
|
221
|
-
function
|
|
251
|
+
function ue(e) {
|
|
222
252
|
let t = e.getFullYear(), n = e.getMonth(), r = new Date(t, n, 1), i = new Date(t, n + 1, 0), a = r.getDay(), o = [];
|
|
223
253
|
for (let e = a - 1; e >= 0; e--) {
|
|
224
254
|
let t = new Date(r.getTime());
|
|
@@ -232,23 +262,11 @@ function z(e) {
|
|
|
232
262
|
}
|
|
233
263
|
return o;
|
|
234
264
|
}
|
|
235
|
-
function
|
|
265
|
+
function de(e, t) {
|
|
236
266
|
return e.getFullYear() === t.getFullYear() && e.getMonth() === t.getMonth() && e.getDate() === t.getDate();
|
|
237
267
|
}
|
|
238
|
-
function
|
|
239
|
-
|
|
240
|
-
let n = new Date(t.start), r = t.end ? new Date(t.end) : new Date(n), i = new Date(e);
|
|
241
|
-
i.setHours(0, 0, 0, 0);
|
|
242
|
-
let a = new Date(e);
|
|
243
|
-
a.setHours(23, 59, 59, 999);
|
|
244
|
-
let o = new Date(n);
|
|
245
|
-
o.setHours(0, 0, 0, 0);
|
|
246
|
-
let s = new Date(r);
|
|
247
|
-
return s.setHours(23, 59, 59, 999), i <= s && a >= o;
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
function H({ date: t, events: n, locale: r = "default", onEventClick: i, onDateClick: a, onEventDrop: o }) {
|
|
251
|
-
let s = e.useMemo(() => z(t), [t.getFullYear(), t.getMonth()]), c = e.useMemo(() => /* @__PURE__ */ new Date(), []), { t: l } = I(), u = e.useMemo(() => {
|
|
268
|
+
function fe({ date: t, events: n, locale: r = "default", onEventClick: i, onDateClick: a, onEventDrop: o }) {
|
|
269
|
+
let s = e.useMemo(() => ue(t), [t.getFullYear(), t.getMonth()]), c = e.useMemo(() => /* @__PURE__ */ new Date(), []), { t: l } = H(), u = e.useMemo(() => {
|
|
252
270
|
let e = new Date(2024, 0, 7);
|
|
253
271
|
return Array.from({ length: 7 }, (t, n) => {
|
|
254
272
|
let i = new Date(e);
|
|
@@ -261,13 +279,24 @@ function H({ date: t, events: n, locale: r = "default", onEventClick: i, onDateC
|
|
|
261
279
|
n.setHours(0, 0, 0, 0), r.setHours(0, 0, 0, 0);
|
|
262
280
|
let i = new Date(n);
|
|
263
281
|
for (; i <= r;) {
|
|
264
|
-
let
|
|
265
|
-
|
|
282
|
+
let a = `${i.getFullYear()}-${i.getMonth()}-${i.getDate()}`, o = i.getTime() === n.getTime(), s = i.getTime() === r.getTime(), c = o || s || i.getDay() === 0, l = e.get(a), u = {
|
|
283
|
+
event: t,
|
|
284
|
+
isTitleDay: c,
|
|
285
|
+
isSpanStart: o,
|
|
286
|
+
isSpanEnd: s
|
|
287
|
+
};
|
|
288
|
+
l ? l.push(u) : e.set(a, [u]), i.setDate(i.getDate() + 1);
|
|
266
289
|
}
|
|
267
290
|
}
|
|
268
291
|
return e;
|
|
269
|
-
}, [n]), g = (e, t) => {
|
|
270
|
-
f(t.id), e.dataTransfer.effectAllowed = "move"
|
|
292
|
+
}, [n]), g = (e, t, n = "move", r) => {
|
|
293
|
+
f(t.id), e.dataTransfer.effectAllowed = "move";
|
|
294
|
+
let i = {
|
|
295
|
+
id: t.id,
|
|
296
|
+
mode: n,
|
|
297
|
+
...r ? { sourceDay: `${r.getFullYear()}-${r.getMonth()}-${r.getDate()}` } : {}
|
|
298
|
+
};
|
|
299
|
+
e.dataTransfer.setData("text/plain", JSON.stringify(i)), n === "resize-end" && e.stopPropagation();
|
|
271
300
|
}, _ = () => {
|
|
272
301
|
f(null), m(null);
|
|
273
302
|
}, v = (e, t) => {
|
|
@@ -276,34 +305,55 @@ function H({ date: t, events: n, locale: r = "default", onEventClick: i, onDateC
|
|
|
276
305
|
e.currentTarget.contains(e.relatedTarget) || m(null);
|
|
277
306
|
}, b = (e, t) => {
|
|
278
307
|
if (e.preventDefault(), m(null), f(null), !o) return;
|
|
279
|
-
let r = e.dataTransfer.getData("text/plain"), i
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
308
|
+
let r = e.dataTransfer.getData("text/plain"), i;
|
|
309
|
+
try {
|
|
310
|
+
i = JSON.parse(r);
|
|
311
|
+
} catch {
|
|
312
|
+
i = {
|
|
313
|
+
id: r,
|
|
314
|
+
mode: "move"
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
let a = n.find((e) => String(e.id) === String(i.id));
|
|
318
|
+
if (!a) return;
|
|
319
|
+
let s = new Date(t);
|
|
320
|
+
if (s.setHours(0, 0, 0, 0), i.mode === "resize-end") {
|
|
321
|
+
let e = a.end ? new Date(a.end) : new Date(a.start), t = new Date(e);
|
|
322
|
+
if (t.setHours(0, 0, 0, 0), s.getTime() === t.getTime()) return;
|
|
323
|
+
let n = new Date(a.start);
|
|
324
|
+
if (n.setHours(0, 0, 0, 0), s.getTime() < n.getTime()) return;
|
|
325
|
+
let r = new Date(s);
|
|
326
|
+
r.setHours(e.getHours(), e.getMinutes(), e.getSeconds(), 0), o(a, new Date(a.start), r);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
let c = new Date(a.start), l;
|
|
330
|
+
if (i.sourceDay) {
|
|
331
|
+
let [e, t, n] = i.sourceDay.split("-").map((e) => parseInt(e, 10));
|
|
332
|
+
l = new Date(e, t, n);
|
|
333
|
+
} else l = new Date(c);
|
|
334
|
+
l.setHours(0, 0, 0, 0);
|
|
335
|
+
let u = s.getTime() - l.getTime();
|
|
336
|
+
if (u === 0) return;
|
|
337
|
+
let d = new Date(c.getTime() + u), p;
|
|
338
|
+
a.end && (p = new Date(new Date(a.end).getTime() + u)), o(a, d, p);
|
|
289
339
|
};
|
|
290
|
-
return /* @__PURE__ */
|
|
340
|
+
return /* @__PURE__ */ L("div", {
|
|
291
341
|
className: "flex flex-col h-full",
|
|
292
|
-
children: [/* @__PURE__ */
|
|
342
|
+
children: [/* @__PURE__ */ I("div", {
|
|
293
343
|
role: "row",
|
|
294
344
|
className: "grid grid-cols-7 border-b",
|
|
295
|
-
children: u.map((e) => /* @__PURE__ */
|
|
345
|
+
children: u.map((e) => /* @__PURE__ */ I("div", {
|
|
296
346
|
role: "columnheader",
|
|
297
347
|
className: "p-2 text-center text-sm font-medium text-muted-foreground border-r last:border-r-0",
|
|
298
348
|
children: e
|
|
299
349
|
}, e))
|
|
300
|
-
}), /* @__PURE__ */
|
|
350
|
+
}), /* @__PURE__ */ I("div", {
|
|
301
351
|
role: "grid",
|
|
302
352
|
"aria-label": "Calendar grid",
|
|
303
353
|
className: "grid grid-cols-7 flex-1 auto-rows-fr",
|
|
304
354
|
children: s.map((e, n) => {
|
|
305
|
-
let r = `${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`, s = h.get(r) || [], u = e.getMonth() === t.getMonth(), f =
|
|
306
|
-
return /* @__PURE__ */
|
|
355
|
+
let r = `${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`, s = h.get(r) || [], u = e.getMonth() === t.getMonth(), f = de(e, c);
|
|
356
|
+
return /* @__PURE__ */ L("div", {
|
|
307
357
|
role: "gridcell",
|
|
308
358
|
"aria-label": `${e.toLocaleDateString("default", {
|
|
309
359
|
weekday: "long",
|
|
@@ -311,33 +361,45 @@ function H({ date: t, events: n, locale: r = "default", onEventClick: i, onDateC
|
|
|
311
361
|
day: "numeric",
|
|
312
362
|
year: "numeric"
|
|
313
363
|
})}${s.length > 0 ? `, ${s.length} event${s.length > 1 ? "s" : ""}` : ""}`,
|
|
314
|
-
className:
|
|
364
|
+
className: N("border-b border-r last:border-r-0 p-2 min-h-[100px] cursor-pointer hover:bg-accent/50", !u && "bg-muted/50 text-muted-foreground opacity-50", p === n && "ring-2 ring-primary"),
|
|
315
365
|
onClick: () => a?.(e),
|
|
316
366
|
onDragOver: (e) => v(e, n),
|
|
317
367
|
onDragLeave: y,
|
|
318
368
|
onDrop: (t) => b(t, e),
|
|
319
|
-
children: [/* @__PURE__ */
|
|
320
|
-
className:
|
|
369
|
+
children: [/* @__PURE__ */ I("div", {
|
|
370
|
+
className: N("text-sm font-medium mb-2", f && "inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-6 w-6"),
|
|
321
371
|
...f ? { "aria-current": "date" } : {},
|
|
322
372
|
children: e.getDate()
|
|
323
|
-
}), /* @__PURE__ */
|
|
324
|
-
className: "space-y-
|
|
325
|
-
children: [s.slice(0,
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
373
|
+
}), /* @__PURE__ */ L("div", {
|
|
374
|
+
className: "space-y-0.5",
|
|
375
|
+
children: [s.slice(0, 4).map(({ event: t, isTitleDay: n, isSpanStart: r, isSpanEnd: a }, s) => {
|
|
376
|
+
let c = !n, { className: l, inlineColor: u } = B(t.color), f = !!o && a;
|
|
377
|
+
return /* @__PURE__ */ L("div", {
|
|
378
|
+
role: "button",
|
|
379
|
+
title: t.title,
|
|
380
|
+
"aria-label": t.title,
|
|
381
|
+
draggable: !!o,
|
|
382
|
+
onDragStart: (n) => g(n, t, "move", e),
|
|
383
|
+
onDragEnd: _,
|
|
384
|
+
className: N("relative text-xs hover:opacity-80 truncate", o ? "cursor-move" : "cursor-pointer", c ? "h-1.5" : "px-2 py-0.5", r ? "rounded-l" : "rounded-l-none", a ? "rounded-r" : "rounded-r-none", !a && "-mr-2", l, d === t.id && "opacity-50"),
|
|
385
|
+
style: u ? { backgroundColor: u } : void 0,
|
|
386
|
+
onClick: (e) => {
|
|
387
|
+
e.stopPropagation(), i?.(t);
|
|
388
|
+
},
|
|
389
|
+
children: [c ? "" : t.title, f && /* @__PURE__ */ I("span", {
|
|
390
|
+
role: "separator",
|
|
391
|
+
"aria-label": "Resize event end",
|
|
392
|
+
title: "Drag to change end date",
|
|
393
|
+
draggable: !0,
|
|
394
|
+
onDragStart: (n) => g(n, t, "resize-end", e),
|
|
395
|
+
onDragEnd: _,
|
|
396
|
+
onClick: (e) => e.stopPropagation(),
|
|
397
|
+
className: "absolute inset-y-0 right-0 w-2 cursor-ew-resize bg-black/25 hover:bg-black/50 rounded-r"
|
|
398
|
+
})]
|
|
399
|
+
}, `${t.id}-${s}`);
|
|
400
|
+
}), s.length > 4 && /* @__PURE__ */ I("div", {
|
|
339
401
|
className: "text-xs text-muted-foreground px-2",
|
|
340
|
-
children: l("calendar.moreEvents", { count: s.length -
|
|
402
|
+
children: l("calendar.moreEvents", { count: s.length - 4 })
|
|
341
403
|
})]
|
|
342
404
|
})]
|
|
343
405
|
}, n);
|
|
@@ -345,134 +407,437 @@ function H({ date: t, events: n, locale: r = "default", onEventClick: i, onDateC
|
|
|
345
407
|
})]
|
|
346
408
|
});
|
|
347
409
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
410
|
+
var U = 48;
|
|
411
|
+
function W(e) {
|
|
412
|
+
let t = new Date(e);
|
|
413
|
+
return t.setHours(0, 0, 0, 0), t;
|
|
414
|
+
}
|
|
415
|
+
function G(e) {
|
|
416
|
+
return e.getHours() * 60 + e.getMinutes();
|
|
417
|
+
}
|
|
418
|
+
function K(e) {
|
|
419
|
+
return `${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`;
|
|
420
|
+
}
|
|
421
|
+
function q({ mode: t, date: n, events: r, locale: i = "default", slotMinutes: a = 30, onEventClick: o, onEventDrop: s, onTimeRangeSelect: c }) {
|
|
422
|
+
let { t: l } = H(), u = U * a / 60, d = U * 24, f = e.useMemo(() => {
|
|
423
|
+
if (t === "day") return [W(n)];
|
|
424
|
+
let e = le(n);
|
|
425
|
+
return Array.from({ length: 7 }, (t, n) => {
|
|
426
|
+
let r = new Date(e);
|
|
427
|
+
return r.setDate(e.getDate() + n), W(r);
|
|
428
|
+
});
|
|
429
|
+
}, [
|
|
430
|
+
t,
|
|
431
|
+
n.getFullYear(),
|
|
432
|
+
n.getMonth(),
|
|
433
|
+
n.getDate()
|
|
434
|
+
]), p = e.useMemo(() => /* @__PURE__ */ new Date(), []), m = e.useCallback((e) => {
|
|
435
|
+
if (e.allDay) return !0;
|
|
436
|
+
let t = new Date(e.start), n = e.end ? new Date(e.end) : new Date(t), r = t.getHours() === 0 && t.getMinutes() === 0 && t.getSeconds() === 0, i = n.getHours() === 0 && n.getMinutes() === 0 && n.getSeconds() === 0, a = n.getTime() - t.getTime();
|
|
437
|
+
return !!(r && i || a >= 1440 * 60 * 1e3);
|
|
438
|
+
}, []), { allDayEvents: h, timedEvents: g } = e.useMemo(() => {
|
|
439
|
+
let e = [], t = [];
|
|
440
|
+
for (let n of r) m(n) ? e.push(n) : t.push(n);
|
|
441
|
+
return {
|
|
442
|
+
allDayEvents: e,
|
|
443
|
+
timedEvents: t
|
|
444
|
+
};
|
|
445
|
+
}, [r, m]), _ = e.useMemo(() => {
|
|
446
|
+
let e = /* @__PURE__ */ new Map();
|
|
447
|
+
for (let t of f) e.set(K(t), []);
|
|
448
|
+
for (let t of h) {
|
|
449
|
+
let n = W(new Date(t.start)), r = t.end ? new Date(t.end) : new Date(t.start), i = W(r);
|
|
450
|
+
r.getHours() === 0 && r.getMinutes() === 0 && r.getSeconds() === 0 && r.getTime() > n.getTime() && (i = new Date(i), i.setDate(i.getDate() - 1));
|
|
451
|
+
for (let r of f) {
|
|
452
|
+
let a = W(r);
|
|
453
|
+
a < n || a > i || e.get(K(r)).push({
|
|
454
|
+
event: t,
|
|
455
|
+
isStart: a.getTime() === n.getTime(),
|
|
456
|
+
isEnd: a.getTime() === i.getTime()
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return e;
|
|
461
|
+
}, [f, h]), v = e.useMemo(() => {
|
|
462
|
+
let e = /* @__PURE__ */ new Map();
|
|
463
|
+
for (let t of f) e.set(K(t), []);
|
|
464
|
+
for (let t of g) {
|
|
465
|
+
let n = new Date(t.start), r = t.end ? new Date(t.end) : new Date(n.getTime() + 3600 * 1e3);
|
|
466
|
+
for (let i of f) {
|
|
467
|
+
let a = W(i), o = new Date(a);
|
|
468
|
+
if (o.setDate(o.getDate() + 1), r <= a || n >= o) continue;
|
|
469
|
+
let s = n < a ? a : n, c = r > o ? o : r, l = G(s), u = c.getTime() === o.getTime() ? 1440 : G(c);
|
|
470
|
+
e.get(K(i)).push({
|
|
471
|
+
event: t,
|
|
472
|
+
startMin: l,
|
|
473
|
+
endMin: Math.max(u, l + 15),
|
|
474
|
+
isStart: s.getTime() === n.getTime(),
|
|
475
|
+
isEnd: c.getTime() === r.getTime()
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return e;
|
|
480
|
+
}, [f, g]), y = e.useMemo(() => {
|
|
481
|
+
let e = /* @__PURE__ */ new Map();
|
|
482
|
+
for (let [t, n] of v) {
|
|
483
|
+
let r = [...n].sort((e, t) => e.startMin - t.startMin || e.endMin - t.endMin), i = [], a = [], o = [];
|
|
484
|
+
for (let e of r) {
|
|
485
|
+
let t = 0;
|
|
486
|
+
for (; i[t] && i[t].endMin > e.startMin;) t++;
|
|
487
|
+
i[t] = { endMin: e.endMin }, a.push({
|
|
488
|
+
entry: e,
|
|
489
|
+
col: t
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
for (let e = 0; e < a.length; e++) {
|
|
493
|
+
let t = a[e], n = t.col;
|
|
494
|
+
for (let r = 0; r < a.length; r++) {
|
|
495
|
+
if (r === e) continue;
|
|
496
|
+
let i = a[r];
|
|
497
|
+
i.entry.startMin < t.entry.endMin && i.entry.endMin > t.entry.startMin && i.col > n && (n = i.col);
|
|
498
|
+
}
|
|
499
|
+
o.push({
|
|
500
|
+
...t.entry,
|
|
501
|
+
col: t.col,
|
|
502
|
+
cols: n + 1
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
e.set(t, o);
|
|
506
|
+
}
|
|
507
|
+
return e;
|
|
508
|
+
}, [v]), b = e.useRef(null), x = e.useRef([]), [S, C] = e.useState(null), w = e.useRef(null);
|
|
509
|
+
w.current = S;
|
|
510
|
+
let T = e.useRef(!1), E = e.useCallback((e, t) => {
|
|
511
|
+
let n = x.current[t];
|
|
512
|
+
if (!n) return 0;
|
|
513
|
+
let r = (e - n.getBoundingClientRect().top + n.scrollTop) / U * 60, i = Math.round(r / a) * a;
|
|
514
|
+
return Math.max(0, Math.min(1440, i));
|
|
515
|
+
}, [a]), D = e.useCallback((e) => {
|
|
516
|
+
for (let t = 0; t < x.current.length; t++) {
|
|
517
|
+
let n = x.current[t];
|
|
518
|
+
if (!n) continue;
|
|
519
|
+
let r = n.getBoundingClientRect();
|
|
520
|
+
if (e >= r.left && e <= r.right) return t;
|
|
521
|
+
}
|
|
522
|
+
return -1;
|
|
523
|
+
}, []);
|
|
524
|
+
e.useEffect(() => {
|
|
525
|
+
if (!S) return;
|
|
526
|
+
let e = (e) => {
|
|
527
|
+
let t = S.kind === "select" || S.kind === "move" ? D(e.clientX) : S.dayIndex, n = t < 0 ? S.dayIndex ?? 0 : t, r = E(e.clientY, n);
|
|
528
|
+
C((e) => e && (e.kind === "select" ? {
|
|
529
|
+
...e,
|
|
530
|
+
dayIndex: n >= 0 ? n : e.dayIndex,
|
|
531
|
+
headMinutes: r
|
|
532
|
+
} : e.kind === "move" ? {
|
|
533
|
+
...e,
|
|
534
|
+
dayIndex: n,
|
|
535
|
+
minutes: r
|
|
536
|
+
} : {
|
|
537
|
+
...e,
|
|
538
|
+
minutes: r
|
|
539
|
+
}));
|
|
540
|
+
}, t = (e) => {
|
|
541
|
+
let t = w.current;
|
|
542
|
+
if (!t) {
|
|
543
|
+
C(null);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
try {
|
|
547
|
+
if (t.kind === "select" && c) {
|
|
548
|
+
let e = Math.min(t.anchorMinutes, t.headMinutes), n = Math.max(t.anchorMinutes, t.headMinutes), r = e, i = n === e ? Math.min(1440, e + a) : n, o = f[t.dayIndex] ?? f[0], s = new Date(o);
|
|
549
|
+
s.setHours(0, Math.round(r), 0, 0);
|
|
550
|
+
let l = new Date(o);
|
|
551
|
+
l.setHours(0, Math.round(i), 0, 0), T.current = !0, c(s, l);
|
|
552
|
+
} else if (t.kind === "move" && s) {
|
|
553
|
+
let e = r.find((e) => String(e.id) === String(t.eventId));
|
|
554
|
+
if (e) {
|
|
555
|
+
let n = t.dayIndex < 0 ? 0 : t.dayIndex, r = t.minutes - t.grabMinuteOffset, i = Math.max(0, Math.min(1440 - t.durationMin, Math.round(r / a) * a)), o = f[n] ?? f[0], c = new Date(o);
|
|
556
|
+
c.setHours(0, i, 0, 0);
|
|
557
|
+
let l = new Date(c.getTime() + t.durationMin * 60 * 1e3);
|
|
558
|
+
T.current = !0, s(e, c, l);
|
|
559
|
+
}
|
|
560
|
+
} else if (t.kind === "resize-top" && s) {
|
|
561
|
+
let e = r.find((e) => String(e.id) === String(t.eventId));
|
|
562
|
+
if (e) {
|
|
563
|
+
let n = f[t.dayIndex] ?? f[0], r = Math.min(t.anchorEndMin - a, Math.max(0, t.minutes)), i = new Date(n);
|
|
564
|
+
i.setHours(0, r, 0, 0);
|
|
565
|
+
let o = new Date(n);
|
|
566
|
+
o.setHours(0, t.anchorEndMin, 0, 0), T.current = !0, s(e, i, o);
|
|
567
|
+
}
|
|
568
|
+
} else if (t.kind === "resize-bottom" && s) {
|
|
569
|
+
let e = r.find((e) => String(e.id) === String(t.eventId));
|
|
570
|
+
if (e) {
|
|
571
|
+
let n = f[t.dayIndex] ?? f[0], r = Math.max(t.anchorStartMin + a, Math.min(1440, t.minutes)), i = new Date(n);
|
|
572
|
+
i.setHours(0, t.anchorStartMin, 0, 0);
|
|
573
|
+
let o = new Date(n);
|
|
574
|
+
o.setHours(0, r, 0, 0), T.current = !0, s(e, i, o);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
} finally {
|
|
578
|
+
C(null), setTimeout(() => {
|
|
579
|
+
T.current = !1;
|
|
580
|
+
}, 50);
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
return window.addEventListener("pointermove", e), window.addEventListener("pointerup", t), () => {
|
|
584
|
+
window.removeEventListener("pointermove", e), window.removeEventListener("pointerup", t);
|
|
585
|
+
};
|
|
586
|
+
}, [
|
|
587
|
+
S,
|
|
588
|
+
f,
|
|
589
|
+
r,
|
|
590
|
+
a,
|
|
591
|
+
s,
|
|
592
|
+
c,
|
|
593
|
+
D,
|
|
594
|
+
E
|
|
595
|
+
]);
|
|
596
|
+
let O = e.useMemo(() => f.map((e) => ({
|
|
597
|
+
weekday: e.toLocaleDateString(i, { weekday: "short" }),
|
|
598
|
+
day: e.getDate(),
|
|
599
|
+
month: e.toLocaleDateString(i, { month: "short" }),
|
|
600
|
+
isToday: de(e, p)
|
|
601
|
+
})), [
|
|
602
|
+
f,
|
|
603
|
+
i,
|
|
604
|
+
p
|
|
605
|
+
]), k = e.useMemo(() => Array.from({ length: 24 }, (e, t) => new Date(2024, 0, 1, t, 0).toLocaleTimeString(i, { hour: "numeric" })), [i]), A = (e, t, n, r) => {
|
|
606
|
+
if (!s || e.button !== 0) return;
|
|
607
|
+
e.stopPropagation(), e.preventDefault();
|
|
608
|
+
let i = E(e.clientY, n);
|
|
609
|
+
C(r === "body" ? {
|
|
610
|
+
kind: "move",
|
|
611
|
+
eventId: t.event.id,
|
|
612
|
+
grabMinuteOffset: Math.max(0, i - t.startMin),
|
|
613
|
+
durationMin: t.endMin - t.startMin,
|
|
614
|
+
dayIndex: n,
|
|
615
|
+
minutes: i
|
|
616
|
+
} : r === "top" ? {
|
|
617
|
+
kind: "resize-top",
|
|
618
|
+
eventId: t.event.id,
|
|
619
|
+
anchorEndMin: t.endMin,
|
|
620
|
+
dayIndex: n,
|
|
621
|
+
minutes: i
|
|
622
|
+
} : {
|
|
623
|
+
kind: "resize-bottom",
|
|
624
|
+
eventId: t.event.id,
|
|
625
|
+
anchorStartMin: t.startMin,
|
|
626
|
+
dayIndex: n,
|
|
627
|
+
minutes: i
|
|
628
|
+
});
|
|
629
|
+
}, j = (e, t) => {
|
|
630
|
+
if (!c || e.button !== 0) return;
|
|
631
|
+
e.preventDefault();
|
|
632
|
+
let n = E(e.clientY, t);
|
|
633
|
+
C({
|
|
634
|
+
kind: "select",
|
|
635
|
+
dayIndex: t,
|
|
636
|
+
anchorMinutes: n,
|
|
637
|
+
headMinutes: n
|
|
638
|
+
});
|
|
639
|
+
}, ee = (e) => {
|
|
640
|
+
if (!S) return null;
|
|
641
|
+
if (S.kind === "select" && S.dayIndex === e) {
|
|
642
|
+
let t = Math.min(S.anchorMinutes, S.headMinutes), n = Math.max(S.anchorMinutes, S.headMinutes);
|
|
643
|
+
return /* @__PURE__ */ I("div", {
|
|
644
|
+
className: "absolute left-1 right-1 rounded bg-primary/30 border border-primary pointer-events-none z-10",
|
|
645
|
+
style: {
|
|
646
|
+
top: t / 60 * U,
|
|
647
|
+
height: Math.max(u, (n - t) / 60 * U)
|
|
648
|
+
},
|
|
649
|
+
"aria-hidden": !0,
|
|
650
|
+
children: /* @__PURE__ */ I("div", {
|
|
651
|
+
className: "px-2 py-0.5 text-xs font-medium text-primary",
|
|
652
|
+
children: J(f[e], t, n, i)
|
|
653
|
+
})
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
if (S.kind === "move" && S.dayIndex === e) {
|
|
657
|
+
let t = S.minutes - S.grabMinuteOffset, n = Math.max(0, Math.min(1440 - S.durationMin, Math.round(t / a) * a));
|
|
658
|
+
return /* @__PURE__ */ I("div", {
|
|
659
|
+
className: "absolute left-1 right-1 rounded border-2 border-dashed border-primary bg-primary/10 pointer-events-none z-10",
|
|
660
|
+
style: {
|
|
661
|
+
top: n / 60 * U,
|
|
662
|
+
height: S.durationMin / 60 * U
|
|
663
|
+
},
|
|
664
|
+
"aria-hidden": !0,
|
|
665
|
+
children: /* @__PURE__ */ I("div", {
|
|
666
|
+
className: "px-2 py-0.5 text-xs font-medium text-primary",
|
|
667
|
+
children: J(f[e], n, n + S.durationMin, i)
|
|
668
|
+
})
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
if ((S.kind === "resize-top" || S.kind === "resize-bottom") && S.dayIndex === e) {
|
|
672
|
+
let t, n;
|
|
673
|
+
return S.kind === "resize-top" ? (t = Math.min(S.anchorEndMin - a, Math.max(0, S.minutes)), n = S.anchorEndMin) : (t = S.anchorStartMin, n = Math.max(S.anchorStartMin + a, Math.min(1440, S.minutes))), /* @__PURE__ */ I("div", {
|
|
674
|
+
className: "absolute left-1 right-1 rounded border-2 border-dashed border-primary bg-primary/10 pointer-events-none z-10",
|
|
675
|
+
style: {
|
|
676
|
+
top: t / 60 * U,
|
|
677
|
+
height: (n - t) / 60 * U
|
|
678
|
+
},
|
|
679
|
+
"aria-hidden": !0,
|
|
680
|
+
children: /* @__PURE__ */ I("div", {
|
|
681
|
+
className: "px-2 py-0.5 text-xs font-medium text-primary",
|
|
682
|
+
children: J(f[e], t, n, i)
|
|
683
|
+
})
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
return null;
|
|
687
|
+
};
|
|
688
|
+
return /* @__PURE__ */ L("div", {
|
|
360
689
|
className: "flex flex-col h-full",
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
className: "
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
690
|
+
ref: b,
|
|
691
|
+
children: [
|
|
692
|
+
/* @__PURE__ */ L("div", {
|
|
693
|
+
className: "flex border-b sticky top-0 bg-background z-20",
|
|
694
|
+
children: [/* @__PURE__ */ I("div", {
|
|
695
|
+
className: "w-14 shrink-0 border-r",
|
|
696
|
+
"aria-hidden": !0
|
|
697
|
+
}), O.map((e, t) => /* @__PURE__ */ L("div", {
|
|
698
|
+
role: "columnheader",
|
|
699
|
+
className: N("flex-1 p-2 text-center text-sm border-r last:border-r-0", e.isToday && "bg-primary/5"),
|
|
700
|
+
children: [/* @__PURE__ */ I("div", {
|
|
701
|
+
className: "text-xs text-muted-foreground",
|
|
702
|
+
children: e.weekday
|
|
703
|
+
}), /* @__PURE__ */ I("div", {
|
|
704
|
+
className: N("font-medium", e.isToday && "inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-6 w-6 mx-auto"),
|
|
705
|
+
children: e.day
|
|
373
706
|
})]
|
|
374
|
-
},
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
707
|
+
}, t))]
|
|
708
|
+
}),
|
|
709
|
+
h.length > 0 && /* @__PURE__ */ L("div", {
|
|
710
|
+
className: "flex border-b bg-muted/20 max-h-[140px] overflow-y-auto",
|
|
711
|
+
children: [/* @__PURE__ */ I("div", {
|
|
712
|
+
className: "w-14 shrink-0 border-r flex items-start justify-end pr-1 pt-1 text-[10px] text-muted-foreground sticky left-0 bg-muted/20",
|
|
713
|
+
children: l("calendar.allDay") === "calendar.allDay" ? "all-day" : l("calendar.allDay")
|
|
714
|
+
}), f.map((e) => {
|
|
715
|
+
let t = K(e);
|
|
716
|
+
return /* @__PURE__ */ I("div", {
|
|
717
|
+
className: "flex-1 border-r last:border-r-0 min-h-[28px] p-0.5 space-y-0.5",
|
|
718
|
+
children: (_.get(t) ?? []).map(({ event: e, isStart: t, isEnd: n }, r) => {
|
|
719
|
+
let { className: i, inlineColor: a } = B(e.color);
|
|
720
|
+
return /* @__PURE__ */ I("div", {
|
|
721
|
+
role: "button",
|
|
722
|
+
title: e.title,
|
|
723
|
+
onClick: (t) => {
|
|
724
|
+
t.stopPropagation(), o?.(e);
|
|
725
|
+
},
|
|
726
|
+
className: N("text-[11px] px-2 py-0.5 truncate cursor-pointer hover:opacity-80", t ? "rounded-l" : "rounded-l-none -ml-0.5", n ? "rounded-r" : "rounded-r-none -mr-0.5", i),
|
|
727
|
+
style: a ? { backgroundColor: a } : void 0,
|
|
728
|
+
children: t ? e.title : "\xA0"
|
|
729
|
+
}, `${e.id}-${r}`);
|
|
730
|
+
})
|
|
731
|
+
}, t);
|
|
732
|
+
})]
|
|
733
|
+
}),
|
|
734
|
+
/* @__PURE__ */ I("div", {
|
|
735
|
+
className: "flex-1 overflow-auto",
|
|
736
|
+
children: /* @__PURE__ */ L("div", {
|
|
737
|
+
className: "flex",
|
|
738
|
+
style: { height: d },
|
|
739
|
+
children: [/* @__PURE__ */ I("div", {
|
|
740
|
+
className: "w-14 shrink-0 border-r relative",
|
|
741
|
+
children: k.map((e, t) => /* @__PURE__ */ I("div", {
|
|
742
|
+
className: "absolute right-1 text-[10px] text-muted-foreground -translate-y-1/2",
|
|
743
|
+
style: { top: t * U },
|
|
744
|
+
children: t === 0 ? "" : e
|
|
745
|
+
}, t))
|
|
746
|
+
}), f.map((e, t) => {
|
|
747
|
+
let n = K(e), r = y.get(n) ?? [];
|
|
748
|
+
return /* @__PURE__ */ L("div", {
|
|
749
|
+
ref: (e) => {
|
|
750
|
+
x.current[t] = e;
|
|
403
751
|
},
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
752
|
+
className: "flex-1 border-r last:border-r-0 relative select-none",
|
|
753
|
+
style: { height: d },
|
|
754
|
+
onPointerDown: (e) => j(e, t),
|
|
755
|
+
"aria-label": e.toLocaleDateString(i, {
|
|
756
|
+
weekday: "long",
|
|
757
|
+
month: "long",
|
|
758
|
+
day: "numeric",
|
|
759
|
+
year: "numeric"
|
|
760
|
+
}),
|
|
761
|
+
children: [
|
|
762
|
+
Array.from({ length: 24 }, (e, t) => /* @__PURE__ */ I("div", {
|
|
763
|
+
className: "absolute left-0 right-0 border-t border-muted/60 pointer-events-none",
|
|
764
|
+
style: { top: t * U }
|
|
765
|
+
}, t)),
|
|
766
|
+
a < 60 && Array.from({ length: Math.floor(1440 / a) }, (e, t) => {
|
|
767
|
+
let n = t * a;
|
|
768
|
+
return n % 60 == 0 ? null : /* @__PURE__ */ I("div", {
|
|
769
|
+
className: "absolute left-0 right-0 border-t border-dashed border-muted/30 pointer-events-none",
|
|
770
|
+
style: { top: n / 60 * U }
|
|
771
|
+
}, t);
|
|
772
|
+
}),
|
|
773
|
+
r.map((n) => {
|
|
774
|
+
let r = n.startMin / 60 * U, a = Math.max(u, (n.endMin - n.startMin) / 60 * U), c = 100 / n.cols, l = n.col * c, { className: d, inlineColor: f } = B(n.event.color), p = S && S.eventId === n.event.id;
|
|
775
|
+
return /* @__PURE__ */ L("div", {
|
|
776
|
+
role: "button",
|
|
777
|
+
tabIndex: 0,
|
|
778
|
+
title: n.event.title,
|
|
779
|
+
"aria-label": n.event.title,
|
|
780
|
+
onPointerDown: (e) => A(e, n, t, "body"),
|
|
781
|
+
onClick: (e) => {
|
|
782
|
+
if (T.current) {
|
|
783
|
+
e.stopPropagation();
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
e.stopPropagation(), o?.(n.event);
|
|
787
|
+
},
|
|
788
|
+
className: N("absolute rounded text-xs px-2 py-1 overflow-hidden shadow-sm", s ? "cursor-move" : "cursor-pointer", d, p && "opacity-40"),
|
|
789
|
+
style: {
|
|
790
|
+
top: r,
|
|
791
|
+
height: a,
|
|
792
|
+
left: `calc(${l}% + 2px)`,
|
|
793
|
+
width: `calc(${c}% - 4px)`,
|
|
794
|
+
...f ? { backgroundColor: f } : {}
|
|
795
|
+
},
|
|
796
|
+
children: [
|
|
797
|
+
/* @__PURE__ */ I("div", {
|
|
798
|
+
className: "font-medium truncate",
|
|
799
|
+
children: n.event.title
|
|
800
|
+
}),
|
|
801
|
+
/* @__PURE__ */ I("div", {
|
|
802
|
+
className: "text-[10px] opacity-80 truncate",
|
|
803
|
+
children: J(e, n.startMin, n.endMin, i)
|
|
804
|
+
}),
|
|
805
|
+
s && n.isStart && /* @__PURE__ */ I("div", {
|
|
806
|
+
onPointerDown: (e) => A(e, n, t, "top"),
|
|
807
|
+
className: "absolute top-0 left-0 right-0 h-1.5 cursor-ns-resize",
|
|
808
|
+
"aria-label": "Resize start"
|
|
809
|
+
}),
|
|
810
|
+
s && n.isEnd && /* @__PURE__ */ I("div", {
|
|
811
|
+
onPointerDown: (e) => A(e, n, t, "bottom"),
|
|
812
|
+
className: "absolute bottom-0 left-0 right-0 h-1.5 cursor-ns-resize",
|
|
813
|
+
"aria-label": "Resize end"
|
|
814
|
+
})
|
|
815
|
+
]
|
|
816
|
+
}, `${n.event.id}-${n.startMin}`);
|
|
817
|
+
}),
|
|
818
|
+
ee(t)
|
|
819
|
+
]
|
|
820
|
+
}, n);
|
|
821
|
+
})]
|
|
822
|
+
})
|
|
417
823
|
})
|
|
418
|
-
|
|
824
|
+
]
|
|
419
825
|
});
|
|
420
826
|
}
|
|
421
|
-
function
|
|
422
|
-
let
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
};
|
|
430
|
-
return /* @__PURE__ */ A("div", {
|
|
431
|
-
className: "flex flex-col h-full",
|
|
432
|
-
children: /* @__PURE__ */ A("div", {
|
|
433
|
-
role: "list",
|
|
434
|
-
className: "flex-1 overflow-auto",
|
|
435
|
-
children: o.map((e) => {
|
|
436
|
-
let t = a.filter((t) => t.allDay ? e === 0 : t.start.getHours() === e);
|
|
437
|
-
return /* @__PURE__ */ j("div", {
|
|
438
|
-
role: "listitem",
|
|
439
|
-
className: "flex border-b min-h-[60px]",
|
|
440
|
-
children: [/* @__PURE__ */ A("div", {
|
|
441
|
-
className: "w-20 p-2 text-sm text-muted-foreground border-r",
|
|
442
|
-
children: e === 0 ? "12 AM" : e < 12 ? `${e} AM` : e === 12 ? "12 PM" : `${e - 12} PM`
|
|
443
|
-
}), /* @__PURE__ */ A("div", {
|
|
444
|
-
className: "flex-1 p-2 space-y-2",
|
|
445
|
-
onTouchStart: () => c(e),
|
|
446
|
-
onTouchEnd: l,
|
|
447
|
-
children: t.map((e) => /* @__PURE__ */ j("div", {
|
|
448
|
-
title: e.title,
|
|
449
|
-
"aria-label": e.title,
|
|
450
|
-
className: D("px-2 sm:px-3 py-1.5 sm:py-2 rounded cursor-pointer hover:opacity-80", e.color?.startsWith("#") ? "text-white" : e.color || N),
|
|
451
|
-
style: e.color && e.color.startsWith("#") ? { backgroundColor: e.color } : void 0,
|
|
452
|
-
onClick: () => r?.(e),
|
|
453
|
-
children: [/* @__PURE__ */ A("div", {
|
|
454
|
-
className: "font-medium truncate",
|
|
455
|
-
children: e.title
|
|
456
|
-
}), !e.allDay && /* @__PURE__ */ j("div", {
|
|
457
|
-
className: "text-xs opacity-90 mt-1",
|
|
458
|
-
children: [e.start.toLocaleTimeString("default", {
|
|
459
|
-
hour: "numeric",
|
|
460
|
-
minute: "2-digit"
|
|
461
|
-
}), e.end && ` - ${e.end.toLocaleTimeString("default", {
|
|
462
|
-
hour: "numeric",
|
|
463
|
-
minute: "2-digit"
|
|
464
|
-
})}`]
|
|
465
|
-
})]
|
|
466
|
-
}, e.id))
|
|
467
|
-
})]
|
|
468
|
-
}, e);
|
|
469
|
-
})
|
|
470
|
-
})
|
|
827
|
+
function J(e, t, n, r) {
|
|
828
|
+
let i = new Date(e);
|
|
829
|
+
i.setHours(0, Math.round(t), 0, 0);
|
|
830
|
+
let a = new Date(e);
|
|
831
|
+
a.setHours(0, Math.round(n), 0, 0);
|
|
832
|
+
let o = (e) => e.toLocaleTimeString(r, {
|
|
833
|
+
hour: "numeric",
|
|
834
|
+
minute: "2-digit"
|
|
471
835
|
});
|
|
836
|
+
return `${o(i)} – ${o(a)}`;
|
|
472
837
|
}
|
|
473
838
|
//#endregion
|
|
474
839
|
//#region src/ObjectCalendar.tsx
|
|
475
|
-
function
|
|
840
|
+
function pe(e) {
|
|
476
841
|
return "data" in e && e.data ? e.data : "staticData" in e && e.staticData ? {
|
|
477
842
|
provider: "value",
|
|
478
843
|
items: e.staticData
|
|
@@ -481,7 +846,7 @@ function G(e) {
|
|
|
481
846
|
object: e.objectName
|
|
482
847
|
} : null;
|
|
483
848
|
}
|
|
484
|
-
function
|
|
849
|
+
function me(e) {
|
|
485
850
|
if (e) {
|
|
486
851
|
if (typeof e == "string") {
|
|
487
852
|
let t = e.split(" "), n = t[0], r = t[1]?.toLowerCase() === "desc" ? "desc" : "asc";
|
|
@@ -490,7 +855,7 @@ function K(e) {
|
|
|
490
855
|
if (Array.isArray(e)) return e.reduce((e, t) => (t.field && t.order && (e[t.field] = t.order), e), {});
|
|
491
856
|
}
|
|
492
857
|
}
|
|
493
|
-
function
|
|
858
|
+
function he(e) {
|
|
494
859
|
return "filter" in e && e.filter && typeof e.filter == "object" && "calendar" in e.filter ? e.filter.calendar : e.calendar ? e.calendar : e.startDateField || e.dateField ? {
|
|
495
860
|
startDateField: e.startDateField || e.dateField,
|
|
496
861
|
endDateField: e.endDateField || e.endField,
|
|
@@ -499,86 +864,86 @@ function q(e) {
|
|
|
499
864
|
allDayField: e.allDayField
|
|
500
865
|
} : null;
|
|
501
866
|
}
|
|
502
|
-
var
|
|
503
|
-
let
|
|
504
|
-
let e =
|
|
505
|
-
return typeof window < "u" && window.innerWidth < 768 && e ? "month" :
|
|
867
|
+
var Y = ({ schema: e, dataSource: t, className: s, data: d, loading: f, onEventClick: p, onRowClick: m, onDateClick: h, onNavigate: _, onViewChange: E, onEventDrop: D, locale: O }) => {
|
|
868
|
+
let k = Array.isArray(d), [A, j] = o(k ? d : []), [ee, M] = o(k ? f ?? !1 : !0), [N, F] = o(null), [R, ae] = o(null), [z, oe] = o(/* @__PURE__ */ new Date()), se = P(), B = e.defaultView, [V, H] = o(() => {
|
|
869
|
+
let e = B === "day" || !B;
|
|
870
|
+
return typeof window < "u" && window.innerWidth < 768 && e ? "month" : B || "month";
|
|
506
871
|
});
|
|
507
872
|
r(() => {
|
|
508
|
-
|
|
509
|
-
}, [
|
|
510
|
-
let [
|
|
873
|
+
se && V === "day" && (B === "day" || !B) && H("month");
|
|
874
|
+
}, [se]);
|
|
875
|
+
let [le, ue] = o(0);
|
|
511
876
|
r(() => {
|
|
512
|
-
if (!
|
|
513
|
-
t.resource === e.objectName &&
|
|
877
|
+
if (!k && !(!t?.onMutation || !e.objectName)) return t.onMutation((t) => {
|
|
878
|
+
t.resource === e.objectName && ue((e) => e + 1);
|
|
514
879
|
});
|
|
515
880
|
}, [
|
|
516
881
|
t,
|
|
517
882
|
e.objectName,
|
|
518
|
-
|
|
883
|
+
k
|
|
519
884
|
]);
|
|
520
|
-
let { ref:
|
|
885
|
+
let { ref: de, isRefreshing: fe, pullDistance: U } = ne({
|
|
521
886
|
onRefresh: n(async () => {
|
|
522
|
-
|
|
887
|
+
ue((e) => e + 1);
|
|
523
888
|
}, []),
|
|
524
889
|
enabled: !!t && !!e.objectName
|
|
525
|
-
}),
|
|
890
|
+
}), W = i(() => pe(e), [
|
|
526
891
|
e.data,
|
|
527
892
|
e.staticData,
|
|
528
893
|
e.objectName
|
|
529
|
-
]),
|
|
894
|
+
]), G = i(() => he(e), [
|
|
530
895
|
e.filter,
|
|
531
896
|
e.calendar,
|
|
532
897
|
e.dateField,
|
|
533
898
|
e.endField,
|
|
534
899
|
e.titleField,
|
|
535
900
|
e.colorField
|
|
536
|
-
]),
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
}, [d,
|
|
540
|
-
|
|
541
|
-
}, [f,
|
|
542
|
-
if (
|
|
901
|
+
]), K = W?.provider === "value", q = a(null);
|
|
902
|
+
q.current = R, r(() => {
|
|
903
|
+
k && j(d);
|
|
904
|
+
}, [d, k]), r(() => {
|
|
905
|
+
k && f !== void 0 && M(f);
|
|
906
|
+
}, [f, k]), r(() => {
|
|
907
|
+
if (k) return;
|
|
543
908
|
let n = !0;
|
|
544
909
|
return (async () => {
|
|
545
910
|
try {
|
|
546
911
|
if (!n) return;
|
|
547
|
-
if (
|
|
548
|
-
n && (
|
|
912
|
+
if (M(!0), K && W?.provider === "value") {
|
|
913
|
+
n && (j(W.items), M(!1));
|
|
549
914
|
return;
|
|
550
915
|
}
|
|
551
916
|
if (!t || typeof t.find != "function") throw Error("DataSource required for object/api providers");
|
|
552
|
-
if (
|
|
553
|
-
let r =
|
|
917
|
+
if (W?.provider === "object") {
|
|
918
|
+
let r = W.object, i = c(q.current?.fields), a = l(await t.find(r, {
|
|
554
919
|
$filter: e.filter,
|
|
555
|
-
$orderby:
|
|
920
|
+
$orderby: me(e.sort),
|
|
556
921
|
...i.length > 0 ? { $expand: i } : {}
|
|
557
922
|
}));
|
|
558
|
-
n &&
|
|
559
|
-
} else
|
|
560
|
-
n &&
|
|
923
|
+
n && j(a);
|
|
924
|
+
} else W?.provider === "api" && (console.warn("API provider not yet implemented for ObjectCalendar"), n && j([]));
|
|
925
|
+
n && M(!1);
|
|
561
926
|
} catch (e) {
|
|
562
|
-
console.error("[ObjectCalendar] Error fetching data:", e), n && (
|
|
927
|
+
console.error("[ObjectCalendar] Error fetching data:", e), n && (F(e), M(!1));
|
|
563
928
|
}
|
|
564
929
|
})(), () => {
|
|
565
930
|
n = !1;
|
|
566
931
|
};
|
|
567
932
|
}, [
|
|
568
|
-
|
|
569
|
-
|
|
933
|
+
k,
|
|
934
|
+
W,
|
|
570
935
|
t,
|
|
571
|
-
|
|
936
|
+
K,
|
|
572
937
|
e.filter,
|
|
573
938
|
e.sort,
|
|
574
|
-
|
|
939
|
+
le
|
|
575
940
|
]), r(() => {
|
|
576
|
-
!
|
|
941
|
+
!K && t && (async () => {
|
|
577
942
|
try {
|
|
578
943
|
if (!t) return;
|
|
579
|
-
let n =
|
|
944
|
+
let n = W?.provider === "object" ? W.object : e.objectName;
|
|
580
945
|
if (!n) return;
|
|
581
|
-
|
|
946
|
+
ae(await t.getObjectSchema(n));
|
|
582
947
|
} catch (e) {
|
|
583
948
|
console.error("Failed to fetch object schema:", e);
|
|
584
949
|
}
|
|
@@ -586,12 +951,12 @@ var J = ({ schema: e, dataSource: t, className: s, data: d, loading: f, onEventC
|
|
|
586
951
|
}, [
|
|
587
952
|
e.objectName,
|
|
588
953
|
t,
|
|
589
|
-
|
|
590
|
-
|
|
954
|
+
K,
|
|
955
|
+
W
|
|
591
956
|
]);
|
|
592
|
-
let
|
|
593
|
-
if (!
|
|
594
|
-
let { startDateField: e, endDateField: t, titleField: n, colorField: r } =
|
|
957
|
+
let J = i(() => {
|
|
958
|
+
if (!G || !A.length) return [];
|
|
959
|
+
let { startDateField: e, endDateField: t, titleField: n, colorField: r } = G, i = R?.titleFormat, a = typeof i == "string" ? i : i && typeof i == "object" && typeof i.source == "string" ? i.source : void 0, o = R?.NAME_FIELD_KEY, s = [
|
|
595
960
|
"name",
|
|
596
961
|
"full_name",
|
|
597
962
|
"fullName",
|
|
@@ -625,7 +990,7 @@ var J = ({ schema: e, dataSource: t, className: s, data: d, loading: f, onEventC
|
|
|
625
990
|
}
|
|
626
991
|
return t || "Untitled";
|
|
627
992
|
};
|
|
628
|
-
return
|
|
993
|
+
return A.map((n, i) => {
|
|
629
994
|
let a = n[e], o = t ? n[t] : null, s = l(n), c = r ? n[r] : void 0;
|
|
630
995
|
return {
|
|
631
996
|
id: n.id || n._id || `event-${i}`,
|
|
@@ -638,91 +1003,272 @@ var J = ({ schema: e, dataSource: t, className: s, data: d, loading: f, onEventC
|
|
|
638
1003
|
};
|
|
639
1004
|
}).filter((e) => !isNaN(e.start.getTime()));
|
|
640
1005
|
}, [
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
1006
|
+
A,
|
|
1007
|
+
G,
|
|
1008
|
+
R
|
|
644
1009
|
]);
|
|
645
1010
|
n(() => {
|
|
646
1011
|
h?.(/* @__PURE__ */ new Date());
|
|
647
1012
|
}, [h]);
|
|
648
|
-
let
|
|
649
|
-
|
|
1013
|
+
let Y = e.navigation ?? {
|
|
1014
|
+
mode: "drawer",
|
|
1015
|
+
width: "min(960px, 60vw)"
|
|
1016
|
+
}, X = Y.mode === "drawer" || Y.mode === "modal" || Y.mode === "split" || Y.mode === "popover", Z = u({
|
|
1017
|
+
navigation: Y,
|
|
650
1018
|
objectName: e.objectName,
|
|
651
|
-
onRowClick: m
|
|
652
|
-
})
|
|
653
|
-
|
|
1019
|
+
onRowClick: X ? void 0 : m
|
|
1020
|
+
}), ge = n(async (n, r, i) => {
|
|
1021
|
+
if (!G) return;
|
|
1022
|
+
let { startDateField: a, endDateField: o } = G, s = n?.id ?? n?._id;
|
|
1023
|
+
if (!s || !e.objectName || !t?.update) return;
|
|
1024
|
+
let c = { [a]: r.toISOString() };
|
|
1025
|
+
o && i && (c[o] = i.toISOString());
|
|
1026
|
+
let l = A;
|
|
1027
|
+
j((e) => e.map((e) => (e?.id ?? e?._id) === s ? {
|
|
1028
|
+
...e,
|
|
1029
|
+
...c
|
|
1030
|
+
} : e));
|
|
1031
|
+
try {
|
|
1032
|
+
await t.update(e.objectName, s, c);
|
|
1033
|
+
} catch (e) {
|
|
1034
|
+
j(l), console.error("[ObjectCalendar] Failed to persist drag-and-drop reschedule:", e);
|
|
1035
|
+
}
|
|
1036
|
+
}, [
|
|
1037
|
+
G,
|
|
1038
|
+
e.objectName,
|
|
1039
|
+
t,
|
|
1040
|
+
A
|
|
1041
|
+
]), [Q, $] = o(null), _e = n((n) => {
|
|
1042
|
+
!G || !e.objectName || !t?.create || $({
|
|
1043
|
+
start: n,
|
|
1044
|
+
title: "",
|
|
1045
|
+
submitting: !1
|
|
1046
|
+
});
|
|
1047
|
+
}, [
|
|
1048
|
+
G,
|
|
1049
|
+
e.objectName,
|
|
1050
|
+
t
|
|
1051
|
+
]), ve = n((n, r) => {
|
|
1052
|
+
!G || !e.objectName || !t?.create || $({
|
|
1053
|
+
start: n,
|
|
1054
|
+
end: r,
|
|
1055
|
+
title: "",
|
|
1056
|
+
submitting: !1
|
|
1057
|
+
});
|
|
1058
|
+
}, [
|
|
1059
|
+
G,
|
|
1060
|
+
e.objectName,
|
|
1061
|
+
t
|
|
1062
|
+
]), ye = n(async () => {
|
|
1063
|
+
if (!Q || !G) return;
|
|
1064
|
+
let n = Q.title.trim();
|
|
1065
|
+
if (!n) {
|
|
1066
|
+
$((e) => e && {
|
|
1067
|
+
...e,
|
|
1068
|
+
error: "Title is required"
|
|
1069
|
+
});
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
if (!e.objectName || !t?.create) return;
|
|
1073
|
+
$((e) => e && {
|
|
1074
|
+
...e,
|
|
1075
|
+
submitting: !0,
|
|
1076
|
+
error: void 0
|
|
1077
|
+
});
|
|
1078
|
+
let { startDateField: r, endDateField: i, titleField: a } = G, o = {
|
|
1079
|
+
[a || "name"]: n,
|
|
1080
|
+
[r]: Q.start.toISOString()
|
|
1081
|
+
};
|
|
1082
|
+
i && (o[i] = (Q.end ?? Q.start).toISOString());
|
|
1083
|
+
let s = R?.fields;
|
|
1084
|
+
if (s && typeof s == "object") {
|
|
1085
|
+
let e = Array.isArray(s) ? s.map((e) => [e.name ?? e.apiName, e]) : Object.entries(s);
|
|
1086
|
+
for (let [t, n] of e) {
|
|
1087
|
+
if (!t || t in o || !n?.required) continue;
|
|
1088
|
+
if (n.defaultValue !== void 0 && n.defaultValue !== null) {
|
|
1089
|
+
o[t] = n.defaultValue;
|
|
1090
|
+
continue;
|
|
1091
|
+
}
|
|
1092
|
+
let e = n.type;
|
|
1093
|
+
if (e === "select" || e === "picklist" || e === "status") {
|
|
1094
|
+
let e = (n.options || n.choices || [])[0];
|
|
1095
|
+
e !== void 0 && (o[t] = typeof e == "object" ? e.value ?? e.id : e);
|
|
1096
|
+
} else e === "boolean" || e === "checkbox" ? o[t] = !1 : (e === "number" || e === "integer" || e === "decimal" || e === "currency" || e === "percent") && (o[t] = 0);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
try {
|
|
1100
|
+
let n = await t.create(e.objectName, o), r = (n && (n.record || n.data || n)) ?? null;
|
|
1101
|
+
r && (r.id !== void 0 || r._id !== void 0) && j((e) => [...e, r]), $(null);
|
|
1102
|
+
} catch (e) {
|
|
1103
|
+
let t = e?.message || String(e);
|
|
1104
|
+
$((e) => e && {
|
|
1105
|
+
...e,
|
|
1106
|
+
submitting: !1,
|
|
1107
|
+
error: t
|
|
1108
|
+
}), console.error("[ObjectCalendar] Quick-create failed:", e);
|
|
1109
|
+
}
|
|
1110
|
+
}, [
|
|
1111
|
+
Q,
|
|
1112
|
+
G,
|
|
1113
|
+
e.objectName,
|
|
1114
|
+
t,
|
|
1115
|
+
R
|
|
1116
|
+
]);
|
|
1117
|
+
return ee ? /* @__PURE__ */ I("div", {
|
|
654
1118
|
className: s,
|
|
655
|
-
children: /* @__PURE__ */
|
|
1119
|
+
children: /* @__PURE__ */ I("div", {
|
|
656
1120
|
className: "flex items-center justify-center h-96",
|
|
657
|
-
children: /* @__PURE__ */
|
|
1121
|
+
children: /* @__PURE__ */ I("div", {
|
|
658
1122
|
className: "text-muted-foreground",
|
|
659
1123
|
children: "Loading calendar..."
|
|
660
1124
|
})
|
|
661
1125
|
})
|
|
662
|
-
}) :
|
|
1126
|
+
}) : N ? /* @__PURE__ */ I("div", {
|
|
663
1127
|
className: s,
|
|
664
|
-
children: /* @__PURE__ */
|
|
1128
|
+
children: /* @__PURE__ */ I("div", {
|
|
665
1129
|
className: "flex items-center justify-center h-96",
|
|
666
|
-
children: /* @__PURE__ */
|
|
1130
|
+
children: /* @__PURE__ */ L("div", {
|
|
667
1131
|
className: "text-destructive",
|
|
668
|
-
children: ["Error: ",
|
|
1132
|
+
children: ["Error: ", N.message]
|
|
669
1133
|
})
|
|
670
1134
|
})
|
|
671
|
-
}) :
|
|
672
|
-
ref:
|
|
1135
|
+
}) : G ? /* @__PURE__ */ L("div", {
|
|
1136
|
+
ref: de,
|
|
673
1137
|
className: s,
|
|
674
1138
|
children: [
|
|
675
|
-
|
|
1139
|
+
U > 0 && /* @__PURE__ */ I("div", {
|
|
676
1140
|
className: "flex items-center justify-center text-xs text-muted-foreground",
|
|
677
|
-
style: { height:
|
|
678
|
-
children:
|
|
1141
|
+
style: { height: U },
|
|
1142
|
+
children: fe ? "Refreshing…" : "Pull to refresh"
|
|
679
1143
|
}),
|
|
680
|
-
/* @__PURE__ */
|
|
1144
|
+
/* @__PURE__ */ I("div", {
|
|
681
1145
|
className: "border rounded-lg bg-background h-[calc(100vh-120px)] sm:h-[calc(100vh-160px)] md:h-[calc(100vh-200px)] min-h-[400px] sm:min-h-[600px]",
|
|
682
|
-
children: /* @__PURE__ */
|
|
683
|
-
events:
|
|
684
|
-
currentDate:
|
|
685
|
-
view:
|
|
686
|
-
locale:
|
|
1146
|
+
children: /* @__PURE__ */ I(ce, {
|
|
1147
|
+
events: J,
|
|
1148
|
+
currentDate: z,
|
|
1149
|
+
view: V,
|
|
1150
|
+
locale: O,
|
|
687
1151
|
onEventClick: (e) => {
|
|
688
|
-
|
|
1152
|
+
Z.handleClick(e.data), X || p?.(e.data);
|
|
1153
|
+
},
|
|
1154
|
+
onDateClick: (e) => {
|
|
1155
|
+
h ? h(e) : _e(e);
|
|
689
1156
|
},
|
|
690
|
-
onDateClick: h,
|
|
691
1157
|
onNavigate: (e) => {
|
|
692
|
-
|
|
1158
|
+
oe(e), _?.(e);
|
|
693
1159
|
},
|
|
694
1160
|
onViewChange: (e) => {
|
|
695
|
-
|
|
1161
|
+
H(e), E?.(e);
|
|
696
1162
|
},
|
|
697
1163
|
onAddClick: void 0,
|
|
698
|
-
onEventDrop:
|
|
699
|
-
|
|
700
|
-
}
|
|
1164
|
+
onEventDrop: (e, t, n) => {
|
|
1165
|
+
D ? D(e.data, t, n) : ge(e.data, t, n);
|
|
1166
|
+
},
|
|
1167
|
+
onTimeRangeSelect: ve
|
|
701
1168
|
})
|
|
702
1169
|
}),
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
1170
|
+
/* @__PURE__ */ I(v, {
|
|
1171
|
+
open: !!Q,
|
|
1172
|
+
onOpenChange: (e) => {
|
|
1173
|
+
e || $(null);
|
|
1174
|
+
},
|
|
1175
|
+
children: /* @__PURE__ */ L(y, {
|
|
1176
|
+
className: "sm:max-w-md",
|
|
1177
|
+
children: [
|
|
1178
|
+
/* @__PURE__ */ L(S, { children: [/* @__PURE__ */ I(C, { children: "New event" }), /* @__PURE__ */ I(b, { children: Q && (() => {
|
|
1179
|
+
let e = Q.end && Q.end.getTime() !== Q.start.getTime(), t = Q.start.toLocaleDateString(O, {
|
|
1180
|
+
year: "numeric",
|
|
1181
|
+
month: "long",
|
|
1182
|
+
day: "numeric"
|
|
1183
|
+
});
|
|
1184
|
+
if (e) {
|
|
1185
|
+
let e = (e) => e.toLocaleTimeString(O, {
|
|
1186
|
+
hour: "numeric",
|
|
1187
|
+
minute: "2-digit"
|
|
1188
|
+
});
|
|
1189
|
+
return /* @__PURE__ */ L(te, { children: [
|
|
1190
|
+
t,
|
|
1191
|
+
" · ",
|
|
1192
|
+
e(Q.start),
|
|
1193
|
+
" – ",
|
|
1194
|
+
e(Q.end)
|
|
1195
|
+
] });
|
|
1196
|
+
}
|
|
1197
|
+
return /* @__PURE__ */ L(te, { children: ["On ", t] });
|
|
1198
|
+
})() })] }),
|
|
1199
|
+
/* @__PURE__ */ L("div", {
|
|
1200
|
+
className: "space-y-2",
|
|
1201
|
+
children: [
|
|
1202
|
+
/* @__PURE__ */ I(T, {
|
|
1203
|
+
htmlFor: "quick-create-title",
|
|
1204
|
+
children: "Title"
|
|
1205
|
+
}),
|
|
1206
|
+
/* @__PURE__ */ I(w, {
|
|
1207
|
+
id: "quick-create-title",
|
|
1208
|
+
autoFocus: !0,
|
|
1209
|
+
value: Q?.title ?? "",
|
|
1210
|
+
onChange: (e) => $((t) => t && {
|
|
1211
|
+
...t,
|
|
1212
|
+
title: e.target.value,
|
|
1213
|
+
error: void 0
|
|
1214
|
+
}),
|
|
1215
|
+
onKeyDown: (e) => {
|
|
1216
|
+
e.key === "Enter" && !Q?.submitting && (e.preventDefault(), ye());
|
|
1217
|
+
},
|
|
1218
|
+
placeholder: "What's this event about?",
|
|
1219
|
+
disabled: Q?.submitting
|
|
1220
|
+
}),
|
|
1221
|
+
Q?.error && /* @__PURE__ */ I("p", {
|
|
1222
|
+
className: "text-sm text-destructive",
|
|
1223
|
+
children: Q.error
|
|
1224
|
+
})
|
|
1225
|
+
]
|
|
1226
|
+
}),
|
|
1227
|
+
/* @__PURE__ */ L(x, { children: [/* @__PURE__ */ I(g, {
|
|
1228
|
+
variant: "outline",
|
|
1229
|
+
onClick: () => $(null),
|
|
1230
|
+
disabled: Q?.submitting,
|
|
1231
|
+
children: "Cancel"
|
|
1232
|
+
}), /* @__PURE__ */ I(g, {
|
|
1233
|
+
onClick: () => void ye(),
|
|
1234
|
+
disabled: Q?.submitting || !Q?.title.trim(),
|
|
1235
|
+
children: Q?.submitting ? "Creating…" : "Create"
|
|
1236
|
+
})] })
|
|
1237
|
+
]
|
|
718
1238
|
})
|
|
719
|
-
})
|
|
1239
|
+
}),
|
|
1240
|
+
Z.isOverlay && Z.isOpen && Z.selectedRecord && (() => {
|
|
1241
|
+
let n = W?.provider === "object" ? W.object : e.objectName, r = Z.selectedRecord, i = r.id ?? r._id;
|
|
1242
|
+
if (!n || i == null) return null;
|
|
1243
|
+
let a = G?.titleField ? String(r[G.titleField] ?? "Event Details") : "Event Details";
|
|
1244
|
+
return /* @__PURE__ */ I(re, {
|
|
1245
|
+
open: !0,
|
|
1246
|
+
onClose: Z.close,
|
|
1247
|
+
title: a,
|
|
1248
|
+
record: r,
|
|
1249
|
+
objectName: n,
|
|
1250
|
+
recordId: i,
|
|
1251
|
+
dataSource: t,
|
|
1252
|
+
objectSchema: R,
|
|
1253
|
+
width: Z.width ?? "min(960px, 60vw)",
|
|
1254
|
+
fullPageHref: ie(n, i) ?? void 0,
|
|
1255
|
+
onFieldSave: async (e, r) => {
|
|
1256
|
+
t?.update && (await t.update(n, String(i), { [e]: r }), j((t) => t.map((t) => String(t.id ?? t._id) === String(i) ? {
|
|
1257
|
+
...t,
|
|
1258
|
+
[e]: r
|
|
1259
|
+
} : t)));
|
|
1260
|
+
},
|
|
1261
|
+
onDelete: async () => {
|
|
1262
|
+
t?.delete && (await t.delete(n, String(i)), j((e) => e.filter((e) => String(e.id ?? e._id) !== String(i))));
|
|
1263
|
+
}
|
|
1264
|
+
});
|
|
1265
|
+
})()
|
|
720
1266
|
]
|
|
721
|
-
}) : /* @__PURE__ */
|
|
1267
|
+
}) : /* @__PURE__ */ I("div", {
|
|
722
1268
|
className: s,
|
|
723
|
-
children: /* @__PURE__ */
|
|
1269
|
+
children: /* @__PURE__ */ I("div", {
|
|
724
1270
|
className: "flex items-center justify-center h-96",
|
|
725
|
-
children: /* @__PURE__ */
|
|
1271
|
+
children: /* @__PURE__ */ I("div", {
|
|
726
1272
|
className: "text-muted-foreground",
|
|
727
1273
|
children: "Calendar configuration required. Please specify startDateField and titleField."
|
|
728
1274
|
})
|
|
@@ -731,7 +1277,7 @@ var J = ({ schema: e, dataSource: t, className: s, data: d, loading: f, onEventC
|
|
|
731
1277
|
};
|
|
732
1278
|
//#endregion
|
|
733
1279
|
//#region src/calendar-view-renderer.tsx
|
|
734
|
-
s.register("calendar-view", ({ schema: e, className: n, onAction: r, ...i }) => /* @__PURE__ */
|
|
1280
|
+
s.register("calendar-view", ({ schema: e, className: n, onAction: r, ...i }) => /* @__PURE__ */ I(ce, {
|
|
735
1281
|
className: n,
|
|
736
1282
|
events: t.useMemo(() => !e.data || !Array.isArray(e.data) ? [] : e.data.map((t, n) => {
|
|
737
1283
|
let r = e.titleField || "title", i = e.startDateField || "start", a = e.endDateField || "end", o = e.colorField || "color", s = e.allDayField || "allDay";
|
|
@@ -879,15 +1425,15 @@ s.register("calendar-view", ({ schema: e, className: n, onAction: r, ...i }) =>
|
|
|
879
1425
|
});
|
|
880
1426
|
//#endregion
|
|
881
1427
|
//#region src/index.tsx
|
|
882
|
-
var
|
|
1428
|
+
var X = ({ schema: e, ...t }) => {
|
|
883
1429
|
let { dataSource: n } = d() || {};
|
|
884
|
-
return /* @__PURE__ */
|
|
1430
|
+
return /* @__PURE__ */ I(Y, {
|
|
885
1431
|
schema: e,
|
|
886
1432
|
dataSource: n,
|
|
887
1433
|
...t
|
|
888
1434
|
});
|
|
889
1435
|
};
|
|
890
|
-
s.register("object-calendar",
|
|
1436
|
+
s.register("object-calendar", X, {
|
|
891
1437
|
namespace: "plugin-calendar",
|
|
892
1438
|
label: "Object Calendar",
|
|
893
1439
|
category: "view",
|
|
@@ -902,7 +1448,7 @@ s.register("object-calendar", Y, {
|
|
|
902
1448
|
label: "Calendar Config",
|
|
903
1449
|
description: "startDateField, endDateField, titleField, colorField"
|
|
904
1450
|
}]
|
|
905
|
-
}), s.register("calendar",
|
|
1451
|
+
}), s.register("calendar", X, {
|
|
906
1452
|
namespace: "view",
|
|
907
1453
|
label: "Calendar View",
|
|
908
1454
|
category: "view",
|
|
@@ -919,4 +1465,4 @@ s.register("object-calendar", Y, {
|
|
|
919
1465
|
}]
|
|
920
1466
|
});
|
|
921
1467
|
//#endregion
|
|
922
|
-
export {
|
|
1468
|
+
export { ce as CalendarView, Y as ObjectCalendar, X as ObjectCalendarRenderer };
|