@object-ui/plugin-calendar 17.5.0 → 17.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +248 -0
- package/README.md +134 -38
- package/dist/CalendarView.d.ts +24 -4
- package/dist/CalendarView.d.ts.map +1 -1
- package/dist/ObjectCalendar.d.ts +18 -2
- package/dist/ObjectCalendar.d.ts.map +1 -1
- package/dist/index.d.ts +27 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +131 -140
- package/dist/index.umd.cjs +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import * as e from "react";
|
|
2
2
|
import t, { useCallback as n, useEffect as r, useMemo as i, useRef as a, useState as o } from "react";
|
|
3
|
-
import { ComponentRegistry as s, buildExpandFields as c,
|
|
4
|
-
import { ElementDataSourceGate as
|
|
5
|
-
import { CalendarIcon as
|
|
6
|
-
import { Button as
|
|
7
|
-
import { createSafeTranslation as
|
|
8
|
-
import { Fragment as
|
|
9
|
-
import { usePullToRefresh as
|
|
10
|
-
import { RecordDetailDrawer as
|
|
3
|
+
import { ComponentRegistry as s, buildExpandFields as c, convertSortToQueryParams as l, extractRecords as u, getRecordDisplayName as d } from "@object-ui/core";
|
|
4
|
+
import { ElementDataSourceGate as f, extractWriteErrorMessage as p, isPermissionError as m, useNavigationOverlay as h, useSafeTranslate as g, useSchemaContext as _ } from "@object-ui/react";
|
|
5
|
+
import { CalendarIcon as v, ChevronLeftIcon as y, ChevronRightIcon as b, PlusIcon as x } from "lucide-react";
|
|
6
|
+
import { Button as S, Calendar as C, Dialog as w, DialogContent as T, DialogDescription as E, DialogFooter as D, DialogHeader as ee, DialogTitle as te, Input as O, Label as ne, Popover as k, PopoverContent as A, PopoverTrigger as j, Select as M, SelectContent as N, SelectItem as P, SelectTrigger as re, SelectValue as F, cn as I, toast as ie, useIsMobile as ae } from "@object-ui/components";
|
|
7
|
+
import { createSafeTranslation as oe } from "@object-ui/i18n";
|
|
8
|
+
import { Fragment as se, jsx as L, jsxs as R } from "react/jsx-runtime";
|
|
9
|
+
import { usePullToRefresh as ce } from "@object-ui/mobile";
|
|
10
|
+
import { RecordDetailDrawer as le, deriveRecordPageHref as ue } from "@object-ui/plugin-detail";
|
|
11
11
|
//#region src/CalendarView.tsx
|
|
12
|
-
var z = "bg-blue-100 text-blue-900 border border-blue-200",
|
|
12
|
+
var z = "bg-blue-100 text-blue-900 border border-blue-200", de = /* @__PURE__ */ new Date(), fe = [
|
|
13
13
|
"bg-blue-100 text-blue-900 border border-blue-200",
|
|
14
14
|
"bg-emerald-100 text-emerald-900 border border-emerald-200",
|
|
15
15
|
"bg-amber-100 text-amber-900 border border-amber-200",
|
|
@@ -18,19 +18,19 @@ var z = "bg-blue-100 text-blue-900 border border-blue-200", ue = /* @__PURE__ */
|
|
|
18
18
|
"bg-cyan-100 text-cyan-900 border border-cyan-200",
|
|
19
19
|
"bg-orange-100 text-orange-900 border border-orange-200",
|
|
20
20
|
"bg-fuchsia-100 text-fuchsia-900 border border-fuchsia-200"
|
|
21
|
-
],
|
|
21
|
+
], pe = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i, me = /(^|\s)(bg|text|from|to|via)-/;
|
|
22
22
|
function B(e) {
|
|
23
23
|
if (!e) return { className: z };
|
|
24
|
-
if (
|
|
24
|
+
if (pe.test(e)) return {
|
|
25
25
|
className: "text-white",
|
|
26
26
|
inlineColor: e
|
|
27
27
|
};
|
|
28
|
-
if (
|
|
28
|
+
if (me.test(e)) return { className: e };
|
|
29
29
|
let t = 0;
|
|
30
30
|
for (let n = 0; n < e.length; n++) t = (t << 5) - t + e.charCodeAt(n) | 0;
|
|
31
|
-
return { className:
|
|
31
|
+
return { className: fe[Math.abs(t) % fe.length] };
|
|
32
32
|
}
|
|
33
|
-
var V =
|
|
33
|
+
var V = oe({
|
|
34
34
|
"calendar.today": "Today",
|
|
35
35
|
"calendar.month": "Month",
|
|
36
36
|
"calendar.week": "Week",
|
|
@@ -39,10 +39,10 @@ var V = I({
|
|
|
39
39
|
"calendar.moreEvents": "+{{count}} more",
|
|
40
40
|
"calendar.allDay": "all-day"
|
|
41
41
|
}, "calendar.today");
|
|
42
|
-
function
|
|
43
|
-
let [m, h] = e.useState(n), [g,
|
|
42
|
+
function he({ events: t = [], view: n = "month", currentDate: r = de, locale: i = "default", onEventClick: a, onDateClick: o, onViewChange: s, onNavigate: c, onAddClick: l, onEventDrop: u, onTimeRangeSelect: d, slotMinutes: f = 30, className: p }) {
|
|
43
|
+
let [m, h] = e.useState(n), [g, _] = e.useState(r), { t: w, language: T } = V(), E = i === "default" ? T : i;
|
|
44
44
|
e.useEffect(() => {
|
|
45
|
-
|
|
45
|
+
_(r);
|
|
46
46
|
}, [r]), e.useEffect(() => {
|
|
47
47
|
h(n);
|
|
48
48
|
}, [n]);
|
|
@@ -55,16 +55,16 @@ function me({ events: t = [], view: n = "month", currentDate: r = ue, locale: i
|
|
|
55
55
|
}, []);
|
|
56
56
|
let ee = () => {
|
|
57
57
|
let e = new Date(g);
|
|
58
|
-
m === "month" ? e.setMonth(e.getMonth() - 1) : m === "week" ? e.setDate(e.getDate() - 7) : e.setDate(e.getDate() - 1),
|
|
58
|
+
m === "month" ? e.setMonth(e.getMonth() - 1) : m === "week" ? e.setDate(e.getDate() - 7) : e.setDate(e.getDate() - 1), _(e), c?.(e);
|
|
59
59
|
}, te = () => {
|
|
60
60
|
let e = new Date(g);
|
|
61
|
-
m === "month" ? e.setMonth(e.getMonth() + 1) : m === "week" ? e.setDate(e.getDate() + 7) : e.setDate(e.getDate() + 1),
|
|
61
|
+
m === "month" ? e.setMonth(e.getMonth() + 1) : m === "week" ? e.setDate(e.getDate() + 7) : e.setDate(e.getDate() + 1), _(e), c?.(e);
|
|
62
62
|
}, O = () => {
|
|
63
63
|
let e = /* @__PURE__ */ new Date();
|
|
64
|
-
|
|
65
|
-
},
|
|
64
|
+
_(e), c?.(e);
|
|
65
|
+
}, ne = (e) => {
|
|
66
66
|
h(e), s?.(e);
|
|
67
|
-
},
|
|
67
|
+
}, ie = () => {
|
|
68
68
|
if (m === "month") return g.toLocaleDateString(E, {
|
|
69
69
|
month: "long",
|
|
70
70
|
year: "numeric"
|
|
@@ -86,11 +86,11 @@ function me({ events: t = [], view: n = "month", currentDate: r = ue, locale: i
|
|
|
86
86
|
day: "numeric",
|
|
87
87
|
year: "numeric"
|
|
88
88
|
});
|
|
89
|
-
},
|
|
89
|
+
}, ae = e.useRef(0);
|
|
90
90
|
return /* @__PURE__ */ R("div", {
|
|
91
91
|
role: "region",
|
|
92
92
|
"aria-label": "Calendar",
|
|
93
|
-
className:
|
|
93
|
+
className: I("flex flex-col h-full bg-background min-w-0 overflow-hidden", p),
|
|
94
94
|
children: [/* @__PURE__ */ R("div", {
|
|
95
95
|
className: "flex flex-wrap items-center justify-between gap-2 p-2 sm:p-4 border-b min-w-0",
|
|
96
96
|
children: [/* @__PURE__ */ R("div", {
|
|
@@ -98,7 +98,7 @@ function me({ events: t = [], view: n = "month", currentDate: r = ue, locale: i
|
|
|
98
98
|
children: [/* @__PURE__ */ R("div", {
|
|
99
99
|
className: "flex items-center bg-muted/50 rounded-lg p-1 gap-1",
|
|
100
100
|
children: [
|
|
101
|
-
/* @__PURE__ */ L(
|
|
101
|
+
/* @__PURE__ */ L(S, {
|
|
102
102
|
variant: "ghost",
|
|
103
103
|
size: "sm",
|
|
104
104
|
onClick: O,
|
|
@@ -107,39 +107,39 @@ function me({ events: t = [], view: n = "month", currentDate: r = ue, locale: i
|
|
|
107
107
|
children: w("calendar.today")
|
|
108
108
|
}),
|
|
109
109
|
/* @__PURE__ */ L("div", { className: "h-4 w-px bg-border mx-1" }),
|
|
110
|
-
/* @__PURE__ */ L(
|
|
110
|
+
/* @__PURE__ */ L(S, {
|
|
111
111
|
variant: "ghost",
|
|
112
112
|
size: "icon",
|
|
113
113
|
"aria-label": "Previous period",
|
|
114
114
|
onClick: ee,
|
|
115
115
|
className: "h-8 w-8",
|
|
116
|
-
children: /* @__PURE__ */ L(
|
|
116
|
+
children: /* @__PURE__ */ L(y, { className: "h-4 w-4" })
|
|
117
117
|
}),
|
|
118
|
-
/* @__PURE__ */ L(
|
|
118
|
+
/* @__PURE__ */ L(S, {
|
|
119
119
|
variant: "ghost",
|
|
120
120
|
size: "icon",
|
|
121
121
|
"aria-label": "Next period",
|
|
122
122
|
onClick: te,
|
|
123
123
|
className: "h-8 w-8",
|
|
124
|
-
children: /* @__PURE__ */ L(
|
|
124
|
+
children: /* @__PURE__ */ L(b, { className: "h-4 w-4" })
|
|
125
125
|
})
|
|
126
126
|
]
|
|
127
|
-
}), /* @__PURE__ */ R(
|
|
127
|
+
}), /* @__PURE__ */ R(k, { children: [/* @__PURE__ */ L(j, {
|
|
128
128
|
asChild: !0,
|
|
129
|
-
children: /* @__PURE__ */ R(
|
|
129
|
+
children: /* @__PURE__ */ R(S, {
|
|
130
130
|
variant: "ghost",
|
|
131
|
-
"aria-label": `Current date: ${
|
|
132
|
-
className:
|
|
133
|
-
children: [/* @__PURE__ */ L(
|
|
131
|
+
"aria-label": `Current date: ${ie()}`,
|
|
132
|
+
className: I("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"),
|
|
133
|
+
children: [/* @__PURE__ */ L(v, { className: "h-5 w-5 text-muted-foreground" }), /* @__PURE__ */ L("span", { children: ie() })]
|
|
134
134
|
})
|
|
135
|
-
}), /* @__PURE__ */ L(
|
|
135
|
+
}), /* @__PURE__ */ L(A, {
|
|
136
136
|
className: "w-auto p-0",
|
|
137
137
|
align: "start",
|
|
138
|
-
children: /* @__PURE__ */ L(
|
|
138
|
+
children: /* @__PURE__ */ L(C, {
|
|
139
139
|
mode: "single",
|
|
140
140
|
selected: g,
|
|
141
141
|
onSelect: (e) => {
|
|
142
|
-
e && (
|
|
142
|
+
e && (_(e), c?.(e));
|
|
143
143
|
},
|
|
144
144
|
autoFocus: !0,
|
|
145
145
|
startMonth: new Date(2e3, 0),
|
|
@@ -148,47 +148,47 @@ function me({ events: t = [], view: n = "month", currentDate: r = ue, locale: i
|
|
|
148
148
|
})] })]
|
|
149
149
|
}), /* @__PURE__ */ R("div", {
|
|
150
150
|
className: "flex items-center gap-2",
|
|
151
|
-
children: [/* @__PURE__ */ R(
|
|
151
|
+
children: [/* @__PURE__ */ R(M, {
|
|
152
152
|
value: m,
|
|
153
|
-
onValueChange:
|
|
153
|
+
onValueChange: ne,
|
|
154
154
|
children: [/* @__PURE__ */ L(re, {
|
|
155
155
|
className: "w-32 bg-background",
|
|
156
|
-
children: /* @__PURE__ */ L(
|
|
157
|
-
}), /* @__PURE__ */ R(
|
|
158
|
-
/* @__PURE__ */ L(
|
|
156
|
+
children: /* @__PURE__ */ L(F, {})
|
|
157
|
+
}), /* @__PURE__ */ R(N, { children: [
|
|
158
|
+
/* @__PURE__ */ L(P, {
|
|
159
159
|
value: "day",
|
|
160
160
|
children: w("calendar.day")
|
|
161
161
|
}),
|
|
162
|
-
/* @__PURE__ */ L(
|
|
162
|
+
/* @__PURE__ */ L(P, {
|
|
163
163
|
value: "week",
|
|
164
164
|
children: w("calendar.week")
|
|
165
165
|
}),
|
|
166
|
-
/* @__PURE__ */ L(
|
|
166
|
+
/* @__PURE__ */ L(P, {
|
|
167
167
|
value: "month",
|
|
168
168
|
children: w("calendar.month")
|
|
169
169
|
})
|
|
170
170
|
] })]
|
|
171
|
-
}), l && /* @__PURE__ */ R(
|
|
171
|
+
}), l && /* @__PURE__ */ R(S, {
|
|
172
172
|
onClick: l,
|
|
173
173
|
size: "sm",
|
|
174
174
|
className: "gap-1",
|
|
175
|
-
children: [/* @__PURE__ */ L(
|
|
175
|
+
children: [/* @__PURE__ */ L(x, { className: "h-4 w-4" }), w("calendar.newEvent")]
|
|
176
176
|
})]
|
|
177
177
|
})]
|
|
178
178
|
}), /* @__PURE__ */ R("div", {
|
|
179
179
|
className: "flex-1 overflow-auto",
|
|
180
180
|
onTouchStart: (e) => {
|
|
181
|
-
|
|
181
|
+
ae.current = e.touches[0].clientX;
|
|
182
182
|
},
|
|
183
183
|
onTouchEnd: (e) => {
|
|
184
|
-
let t =
|
|
184
|
+
let t = ae.current - e.changedTouches[0].clientX;
|
|
185
185
|
if (Math.abs(t) > 50) {
|
|
186
186
|
let e = new Date(g);
|
|
187
|
-
m === "day" ? e.setDate(e.getDate() + (t > 0 ? 1 : -1)) : m === "week" ? e.setDate(e.getDate() + (t > 0 ? 7 : -7)) : e.setMonth(e.getMonth() + (t > 0 ? 1 : -1)),
|
|
187
|
+
m === "day" ? e.setDate(e.getDate() + (t > 0 ? 1 : -1)) : m === "week" ? e.setDate(e.getDate() + (t > 0 ? 7 : -7)) : e.setMonth(e.getMonth() + (t > 0 ? 1 : -1)), _(e), c?.(e);
|
|
188
188
|
}
|
|
189
189
|
},
|
|
190
190
|
children: [
|
|
191
|
-
m === "month" && /* @__PURE__ */ L(
|
|
191
|
+
m === "month" && /* @__PURE__ */ L(_e, {
|
|
192
192
|
date: g,
|
|
193
193
|
events: t,
|
|
194
194
|
locale: E,
|
|
@@ -224,7 +224,7 @@ function H(e) {
|
|
|
224
224
|
let t = new Date(e), n = t.getDay(), r = t.getDate() - n;
|
|
225
225
|
return t.setDate(r), t;
|
|
226
226
|
}
|
|
227
|
-
function
|
|
227
|
+
function ge(e) {
|
|
228
228
|
let t = e.getFullYear(), n = e.getMonth(), r = new Date(t, n, 1), i = new Date(t, n + 1, 0), a = r.getDay(), o = [];
|
|
229
229
|
for (let e = a - 1; e >= 0; e--) {
|
|
230
230
|
let t = new Date(r.getTime());
|
|
@@ -241,8 +241,8 @@ function he(e) {
|
|
|
241
241
|
function U(e, t) {
|
|
242
242
|
return e.getFullYear() === t.getFullYear() && e.getMonth() === t.getMonth() && e.getDate() === t.getDate();
|
|
243
243
|
}
|
|
244
|
-
function
|
|
245
|
-
let s = e.useMemo(() =>
|
|
244
|
+
function _e({ date: t, events: n, locale: r = "default", onEventClick: i, onDateClick: a, onEventDrop: o }) {
|
|
245
|
+
let s = e.useMemo(() => ge(t), [t.getFullYear(), t.getMonth()]), c = e.useMemo(() => /* @__PURE__ */ new Date(), []), { t: l } = V(), u = e.useMemo(() => {
|
|
246
246
|
let e = new Date(2024, 0, 7);
|
|
247
247
|
return Array.from({ length: 7 }, (t, n) => {
|
|
248
248
|
let i = new Date(e);
|
|
@@ -337,13 +337,13 @@ function ge({ date: t, events: n, locale: r = "default", onEventClick: i, onDate
|
|
|
337
337
|
day: "numeric",
|
|
338
338
|
year: "numeric"
|
|
339
339
|
})}${s.length > 0 ? `, ${s.length} event${s.length > 1 ? "s" : ""}` : ""}`,
|
|
340
|
-
className:
|
|
340
|
+
className: I("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"),
|
|
341
341
|
onClick: () => a?.(e),
|
|
342
342
|
onDragOver: (e) => v(e, n),
|
|
343
343
|
onDragLeave: y,
|
|
344
344
|
onDrop: (t) => b(t, e),
|
|
345
345
|
children: [/* @__PURE__ */ L("div", {
|
|
346
|
-
className:
|
|
346
|
+
className: I("text-sm font-medium mb-2", f && "inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-6 w-6"),
|
|
347
347
|
...f ? { "aria-current": "date" } : {},
|
|
348
348
|
children: e.getDate()
|
|
349
349
|
}), /* @__PURE__ */ R("div", {
|
|
@@ -357,7 +357,7 @@ function ge({ date: t, events: n, locale: r = "default", onEventClick: i, onDate
|
|
|
357
357
|
draggable: !!o,
|
|
358
358
|
onDragStart: (n) => g(n, t, "move", e),
|
|
359
359
|
onDragEnd: _,
|
|
360
|
-
className:
|
|
360
|
+
className: I("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"),
|
|
361
361
|
style: u ? { backgroundColor: u } : void 0,
|
|
362
362
|
onClick: (e) => {
|
|
363
363
|
e.stopPropagation(), i?.(t);
|
|
@@ -674,12 +674,12 @@ function J({ mode: t, date: n, events: r, locale: i = "default", slotMinutes: a
|
|
|
674
674
|
"aria-hidden": !0
|
|
675
675
|
}), ee.map((e, t) => /* @__PURE__ */ R("div", {
|
|
676
676
|
role: "columnheader",
|
|
677
|
-
className:
|
|
677
|
+
className: I("flex-1 p-2 text-center text-sm border-r last:border-r-0", e.isToday && "bg-primary/5"),
|
|
678
678
|
children: [/* @__PURE__ */ L("div", {
|
|
679
679
|
className: "text-xs text-muted-foreground",
|
|
680
680
|
children: e.weekday
|
|
681
681
|
}), /* @__PURE__ */ L("div", {
|
|
682
|
-
className:
|
|
682
|
+
className: I("font-medium", e.isToday && "inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-6 w-6 mx-auto"),
|
|
683
683
|
children: e.day
|
|
684
684
|
})]
|
|
685
685
|
}, t))]
|
|
@@ -701,7 +701,7 @@ function J({ mode: t, date: n, events: r, locale: i = "default", slotMinutes: a
|
|
|
701
701
|
onClick: (t) => {
|
|
702
702
|
t.stopPropagation(), o?.(e);
|
|
703
703
|
},
|
|
704
|
-
className:
|
|
704
|
+
className: I("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),
|
|
705
705
|
style: a ? { backgroundColor: a } : void 0,
|
|
706
706
|
children: t ? e.title : "\xA0"
|
|
707
707
|
}, `${e.id}-${r}`);
|
|
@@ -763,7 +763,7 @@ function J({ mode: t, date: n, events: r, locale: i = "default", slotMinutes: a
|
|
|
763
763
|
}
|
|
764
764
|
e.stopPropagation(), o?.(n.event);
|
|
765
765
|
},
|
|
766
|
-
className:
|
|
766
|
+
className: I("absolute rounded text-xs px-2 py-1 overflow-hidden shadow-sm", s ? "cursor-move" : "cursor-pointer", d, p && "opacity-40"),
|
|
767
767
|
style: {
|
|
768
768
|
top: r,
|
|
769
769
|
height: a,
|
|
@@ -815,7 +815,7 @@ function Y(e, t, n, r) {
|
|
|
815
815
|
}
|
|
816
816
|
//#endregion
|
|
817
817
|
//#region src/ObjectCalendar.tsx
|
|
818
|
-
function
|
|
818
|
+
function ve(e) {
|
|
819
819
|
return "data" in e && e.data ? e.data : "staticData" in e && e.staticData ? {
|
|
820
820
|
provider: "value",
|
|
821
821
|
items: e.staticData
|
|
@@ -824,15 +824,6 @@ function _e(e) {
|
|
|
824
824
|
object: e.objectName
|
|
825
825
|
} : null;
|
|
826
826
|
}
|
|
827
|
-
function ve(e) {
|
|
828
|
-
if (e) {
|
|
829
|
-
if (typeof e == "string") {
|
|
830
|
-
let t = e.split(" "), n = t[0], r = t[1]?.toLowerCase() === "desc" ? "desc" : "asc";
|
|
831
|
-
return { [n]: r };
|
|
832
|
-
}
|
|
833
|
-
if (Array.isArray(e)) return e.reduce((e, t) => (t.field && t.order && (e[t.field] = t.order), e), {});
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
827
|
function ye(e) {
|
|
837
828
|
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 ? {
|
|
838
829
|
startDateField: e.startDateField || e.dateField,
|
|
@@ -842,30 +833,30 @@ function ye(e) {
|
|
|
842
833
|
allDayField: e.allDayField
|
|
843
834
|
} : null;
|
|
844
835
|
}
|
|
845
|
-
var be = ({ schema: e, dataSource: t, className: s, data:
|
|
846
|
-
let
|
|
836
|
+
var be = ({ schema: e, dataSource: t, className: s, data: f, loading: _, onEventClick: v, onRowClick: y, onDateClick: b, onNavigate: x, onViewChange: C, onEventDrop: k, locale: A }) => {
|
|
837
|
+
let j = g(), M = Array.isArray(f), [N, P] = o(M ? f : []), [re, F] = o(M ? _ ?? !1 : !0), [I, oe] = o(null), [z, de] = o(null), [fe, pe] = o(/* @__PURE__ */ new Date()), me = ae(), B = e.defaultView, [V, H] = o(() => {
|
|
847
838
|
let e = B === "day" || !B;
|
|
848
839
|
return typeof window < "u" && window.innerWidth < 768 && e ? "month" : B || "month";
|
|
849
840
|
});
|
|
850
841
|
r(() => {
|
|
851
|
-
|
|
852
|
-
}, [
|
|
853
|
-
let [
|
|
842
|
+
me && V === "day" && (B === "day" || !B) && H("month");
|
|
843
|
+
}, [me]);
|
|
844
|
+
let [ge, U] = o(0);
|
|
854
845
|
r(() => {
|
|
855
|
-
if (!
|
|
846
|
+
if (!M && !(!t?.onMutation || !e.objectName)) return t.onMutation((t) => {
|
|
856
847
|
t.resource === e.objectName && U((e) => e + 1);
|
|
857
848
|
});
|
|
858
849
|
}, [
|
|
859
850
|
t,
|
|
860
851
|
e.objectName,
|
|
861
|
-
|
|
852
|
+
M
|
|
862
853
|
]);
|
|
863
|
-
let
|
|
854
|
+
let _e = n(async () => {
|
|
864
855
|
U((e) => e + 1);
|
|
865
|
-
}, []), { ref: W, isRefreshing: G, pullDistance: K } =
|
|
866
|
-
onRefresh:
|
|
856
|
+
}, []), { ref: W, isRefreshing: G, pullDistance: K } = ce({
|
|
857
|
+
onRefresh: _e,
|
|
867
858
|
enabled: !!t && !!e.objectName
|
|
868
|
-
}), q = i(() =>
|
|
859
|
+
}), q = i(() => ve(e), [
|
|
869
860
|
e.data,
|
|
870
861
|
e.staticData,
|
|
871
862
|
e.objectName
|
|
@@ -878,43 +869,43 @@ var be = ({ schema: e, dataSource: t, className: s, data: d, loading: g, onEvent
|
|
|
878
869
|
e.colorField
|
|
879
870
|
]), Y = q?.provider === "value", be = a(null);
|
|
880
871
|
be.current = z, r(() => {
|
|
881
|
-
|
|
882
|
-
}, [
|
|
883
|
-
|
|
884
|
-
}, [
|
|
885
|
-
if (
|
|
872
|
+
M && P(f);
|
|
873
|
+
}, [f, M]), r(() => {
|
|
874
|
+
M && _ !== void 0 && F(_);
|
|
875
|
+
}, [_, M]), r(() => {
|
|
876
|
+
if (M) return;
|
|
886
877
|
let n = !0;
|
|
887
878
|
return (async () => {
|
|
888
879
|
try {
|
|
889
880
|
if (!n) return;
|
|
890
|
-
if (
|
|
891
|
-
n && (
|
|
881
|
+
if (F(!0), Y && q?.provider === "value") {
|
|
882
|
+
n && (P(q.items), F(!1));
|
|
892
883
|
return;
|
|
893
884
|
}
|
|
894
885
|
if (!t || typeof t.find != "function") throw Error("DataSource required for object/api providers");
|
|
895
886
|
if (q?.provider === "object") {
|
|
896
887
|
let r = q.object, i = c(be.current?.fields), a = await t.find(r, {
|
|
897
888
|
$filter: e.filter,
|
|
898
|
-
$orderby:
|
|
889
|
+
$orderby: l(e.sort),
|
|
899
890
|
...i.length > 0 ? { $expand: i } : {}
|
|
900
|
-
}), o =
|
|
901
|
-
n &&
|
|
902
|
-
} else q?.provider === "api" && (console.warn("API provider not yet implemented for ObjectCalendar"), n &&
|
|
903
|
-
n &&
|
|
891
|
+
}), o = u(a);
|
|
892
|
+
n && P(o);
|
|
893
|
+
} else q?.provider === "api" && (console.warn("API provider not yet implemented for ObjectCalendar"), n && P([]));
|
|
894
|
+
n && F(!1);
|
|
904
895
|
} catch (e) {
|
|
905
|
-
console.error("[ObjectCalendar] Error fetching data:", e), n && (
|
|
896
|
+
console.error("[ObjectCalendar] Error fetching data:", e), n && (oe(e), F(!1));
|
|
906
897
|
}
|
|
907
898
|
})(), () => {
|
|
908
899
|
n = !1;
|
|
909
900
|
};
|
|
910
901
|
}, [
|
|
911
|
-
|
|
902
|
+
M,
|
|
912
903
|
q,
|
|
913
904
|
t,
|
|
914
905
|
Y,
|
|
915
906
|
e.filter,
|
|
916
907
|
e.sort,
|
|
917
|
-
|
|
908
|
+
ge
|
|
918
909
|
]), r(() => {
|
|
919
910
|
!Y && t && (async () => {
|
|
920
911
|
try {
|
|
@@ -922,7 +913,7 @@ var be = ({ schema: e, dataSource: t, className: s, data: d, loading: g, onEvent
|
|
|
922
913
|
let n = q?.provider === "object" ? q.object : e.objectName;
|
|
923
914
|
if (!n) return;
|
|
924
915
|
let r = await t.getObjectSchema(n);
|
|
925
|
-
|
|
916
|
+
de(r);
|
|
926
917
|
} catch (e) {
|
|
927
918
|
console.error("Failed to fetch object schema:", e);
|
|
928
919
|
}
|
|
@@ -934,15 +925,15 @@ var be = ({ schema: e, dataSource: t, className: s, data: d, loading: g, onEvent
|
|
|
934
925
|
q
|
|
935
926
|
]);
|
|
936
927
|
let xe = i(() => {
|
|
937
|
-
if (!J || !
|
|
928
|
+
if (!J || !N.length) return [];
|
|
938
929
|
let { startDateField: e, endDateField: t, titleField: n, colorField: r } = J, i = (e) => {
|
|
939
930
|
if (n) {
|
|
940
931
|
let t = e[n], r = typeof t == "string" ? t.trim() : t;
|
|
941
932
|
if (r) return String(r);
|
|
942
933
|
}
|
|
943
|
-
return
|
|
934
|
+
return d(z, e);
|
|
944
935
|
};
|
|
945
|
-
return
|
|
936
|
+
return N.map((n, a) => {
|
|
946
937
|
let o = n[e], s = t ? n[t] : null, c = i(n), l = r ? n[r] : void 0;
|
|
947
938
|
return {
|
|
948
939
|
id: n.id || n._id || `event-${a}`,
|
|
@@ -955,42 +946,42 @@ var be = ({ schema: e, dataSource: t, className: s, data: d, loading: g, onEvent
|
|
|
955
946
|
};
|
|
956
947
|
}).filter((e) => !isNaN(e.start.getTime()));
|
|
957
948
|
}, [
|
|
958
|
-
|
|
949
|
+
N,
|
|
959
950
|
J,
|
|
960
951
|
z
|
|
961
952
|
]);
|
|
962
953
|
n(() => {
|
|
963
|
-
|
|
964
|
-
}, [
|
|
954
|
+
b?.(/* @__PURE__ */ new Date());
|
|
955
|
+
}, [b]);
|
|
965
956
|
let X = e.navigation ?? {
|
|
966
957
|
mode: "drawer",
|
|
967
958
|
width: "min(960px, 60vw)"
|
|
968
|
-
}, Se = X.mode === "drawer" || X.mode === "modal" || X.mode === "split" || X.mode === "popover", Z =
|
|
959
|
+
}, Se = X.mode === "drawer" || X.mode === "modal" || X.mode === "split" || X.mode === "popover", Z = h({
|
|
969
960
|
navigation: X,
|
|
970
961
|
objectName: e.objectName,
|
|
971
|
-
onRowClick: Se ? void 0 :
|
|
962
|
+
onRowClick: Se ? void 0 : y
|
|
972
963
|
}), Ce = n(async (n, r, i) => {
|
|
973
964
|
if (!J) return;
|
|
974
965
|
let { startDateField: a, endDateField: o } = J, s = n?.id ?? n?._id;
|
|
975
966
|
if (!s || !e.objectName || !t?.update) return;
|
|
976
967
|
let c = { [a]: r.toISOString() };
|
|
977
968
|
o && i && (c[o] = i.toISOString());
|
|
978
|
-
let l =
|
|
979
|
-
|
|
969
|
+
let l = N;
|
|
970
|
+
P((e) => e.map((e) => (e?.id ?? e?._id) === s ? {
|
|
980
971
|
...e,
|
|
981
972
|
...c
|
|
982
973
|
} : e));
|
|
983
974
|
try {
|
|
984
975
|
await t.update(e.objectName, s, c);
|
|
985
976
|
} catch (e) {
|
|
986
|
-
|
|
977
|
+
P(l), console.error("[ObjectCalendar] Failed to persist drag-and-drop reschedule:", e), ie.error(m(e) ? j("errors.unauthorized", "You are not authorized to perform this action.") : p(e) ?? j("table.saveFailed", "Save failed"));
|
|
987
978
|
}
|
|
988
979
|
}, [
|
|
989
980
|
J,
|
|
990
981
|
e.objectName,
|
|
991
982
|
t,
|
|
992
|
-
|
|
993
|
-
|
|
983
|
+
N,
|
|
984
|
+
j
|
|
994
985
|
]), [Q, $] = o(null), we = n((n) => {
|
|
995
986
|
!J || !e.objectName || !t?.create || $({
|
|
996
987
|
start: n,
|
|
@@ -1051,7 +1042,7 @@ var be = ({ schema: e, dataSource: t, className: s, data: d, loading: g, onEvent
|
|
|
1051
1042
|
}
|
|
1052
1043
|
try {
|
|
1053
1044
|
let n = await t.create(e.objectName, o), r = (n && (n.record || n.data || n)) ?? null;
|
|
1054
|
-
r && (r.id !== void 0 || r._id !== void 0) &&
|
|
1045
|
+
r && (r.id !== void 0 || r._id !== void 0) && P((e) => [...e, r]), $(null);
|
|
1055
1046
|
} catch (e) {
|
|
1056
1047
|
let t = e?.message || String(e);
|
|
1057
1048
|
$((e) => e && {
|
|
@@ -1076,13 +1067,13 @@ var be = ({ schema: e, dataSource: t, className: s, data: d, loading: g, onEvent
|
|
|
1076
1067
|
children: "Loading calendar..."
|
|
1077
1068
|
})
|
|
1078
1069
|
})
|
|
1079
|
-
}) :
|
|
1070
|
+
}) : I ? /* @__PURE__ */ L("div", {
|
|
1080
1071
|
className: s,
|
|
1081
1072
|
children: /* @__PURE__ */ L("div", {
|
|
1082
1073
|
className: "flex items-center justify-center h-96",
|
|
1083
1074
|
children: /* @__PURE__ */ R("div", {
|
|
1084
1075
|
className: "text-destructive",
|
|
1085
|
-
children: ["Error: ",
|
|
1076
|
+
children: ["Error: ", I.message]
|
|
1086
1077
|
})
|
|
1087
1078
|
})
|
|
1088
1079
|
}) : J ? /* @__PURE__ */ R("div", {
|
|
@@ -1096,50 +1087,50 @@ var be = ({ schema: e, dataSource: t, className: s, data: d, loading: g, onEvent
|
|
|
1096
1087
|
}),
|
|
1097
1088
|
/* @__PURE__ */ L("div", {
|
|
1098
1089
|
className: "bg-background h-[calc(100vh-120px)] sm:h-[calc(100vh-160px)] md:h-[calc(100vh-200px)] min-h-[400px] sm:min-h-[600px]",
|
|
1099
|
-
children: /* @__PURE__ */ L(
|
|
1090
|
+
children: /* @__PURE__ */ L(he, {
|
|
1100
1091
|
events: xe,
|
|
1101
|
-
currentDate:
|
|
1092
|
+
currentDate: fe,
|
|
1102
1093
|
view: V,
|
|
1103
|
-
locale:
|
|
1094
|
+
locale: A,
|
|
1104
1095
|
onEventClick: (e) => {
|
|
1105
|
-
Z.handleClick(e.data), Se ||
|
|
1096
|
+
Z.handleClick(e.data), Se || v?.(e.data);
|
|
1106
1097
|
},
|
|
1107
1098
|
onDateClick: (e) => {
|
|
1108
|
-
|
|
1099
|
+
b ? b(e) : we(e);
|
|
1109
1100
|
},
|
|
1110
1101
|
onNavigate: (e) => {
|
|
1111
|
-
|
|
1102
|
+
pe(e), x?.(e);
|
|
1112
1103
|
},
|
|
1113
1104
|
onViewChange: (e) => {
|
|
1114
|
-
H(e),
|
|
1105
|
+
H(e), C?.(e);
|
|
1115
1106
|
},
|
|
1116
1107
|
onAddClick: void 0,
|
|
1117
1108
|
onEventDrop: (e, t, n) => {
|
|
1118
|
-
|
|
1109
|
+
k ? k(e.data, t, n) : Ce(e.data, t, n);
|
|
1119
1110
|
},
|
|
1120
1111
|
onTimeRangeSelect: Te
|
|
1121
1112
|
})
|
|
1122
1113
|
}),
|
|
1123
|
-
/* @__PURE__ */ L(
|
|
1114
|
+
/* @__PURE__ */ L(w, {
|
|
1124
1115
|
open: !!Q,
|
|
1125
1116
|
onOpenChange: (e) => {
|
|
1126
1117
|
e || $(null);
|
|
1127
1118
|
},
|
|
1128
|
-
children: /* @__PURE__ */ R(
|
|
1119
|
+
children: /* @__PURE__ */ R(T, {
|
|
1129
1120
|
className: "sm:max-w-md",
|
|
1130
1121
|
children: [
|
|
1131
|
-
/* @__PURE__ */ R(
|
|
1132
|
-
let e = Q.end && Q.end.getTime() !== Q.start.getTime(), t = Q.start.toLocaleDateString(
|
|
1122
|
+
/* @__PURE__ */ R(ee, { children: [/* @__PURE__ */ L(te, { children: "New event" }), /* @__PURE__ */ L(E, { children: Q && (() => {
|
|
1123
|
+
let e = Q.end && Q.end.getTime() !== Q.start.getTime(), t = Q.start.toLocaleDateString(A, {
|
|
1133
1124
|
year: "numeric",
|
|
1134
1125
|
month: "long",
|
|
1135
1126
|
day: "numeric"
|
|
1136
1127
|
});
|
|
1137
1128
|
if (e) {
|
|
1138
|
-
let e = (e) => e.toLocaleTimeString(
|
|
1129
|
+
let e = (e) => e.toLocaleTimeString(A, {
|
|
1139
1130
|
hour: "numeric",
|
|
1140
1131
|
minute: "2-digit"
|
|
1141
1132
|
});
|
|
1142
|
-
return /* @__PURE__ */ R(
|
|
1133
|
+
return /* @__PURE__ */ R(se, { children: [
|
|
1143
1134
|
t,
|
|
1144
1135
|
" · ",
|
|
1145
1136
|
e(Q.start),
|
|
@@ -1147,16 +1138,16 @@ var be = ({ schema: e, dataSource: t, className: s, data: d, loading: g, onEvent
|
|
|
1147
1138
|
e(Q.end)
|
|
1148
1139
|
] });
|
|
1149
1140
|
}
|
|
1150
|
-
return /* @__PURE__ */ R(
|
|
1141
|
+
return /* @__PURE__ */ R(se, { children: ["On ", t] });
|
|
1151
1142
|
})() })] }),
|
|
1152
1143
|
/* @__PURE__ */ R("div", {
|
|
1153
1144
|
className: "space-y-2",
|
|
1154
1145
|
children: [
|
|
1155
|
-
/* @__PURE__ */ L(
|
|
1146
|
+
/* @__PURE__ */ L(ne, {
|
|
1156
1147
|
htmlFor: "quick-create-title",
|
|
1157
1148
|
children: "Title"
|
|
1158
1149
|
}),
|
|
1159
|
-
/* @__PURE__ */ L(
|
|
1150
|
+
/* @__PURE__ */ L(O, {
|
|
1160
1151
|
id: "quick-create-title",
|
|
1161
1152
|
autoFocus: !0,
|
|
1162
1153
|
value: Q?.title ?? "",
|
|
@@ -1177,12 +1168,12 @@ var be = ({ schema: e, dataSource: t, className: s, data: d, loading: g, onEvent
|
|
|
1177
1168
|
})
|
|
1178
1169
|
]
|
|
1179
1170
|
}),
|
|
1180
|
-
/* @__PURE__ */ R(
|
|
1171
|
+
/* @__PURE__ */ R(D, { children: [/* @__PURE__ */ L(S, {
|
|
1181
1172
|
variant: "outline",
|
|
1182
1173
|
onClick: () => $(null),
|
|
1183
1174
|
disabled: Q?.submitting,
|
|
1184
1175
|
children: "Cancel"
|
|
1185
|
-
}), /* @__PURE__ */ L(
|
|
1176
|
+
}), /* @__PURE__ */ L(S, {
|
|
1186
1177
|
onClick: () => void Ee(),
|
|
1187
1178
|
disabled: Q?.submitting || !Q?.title.trim(),
|
|
1188
1179
|
children: Q?.submitting ? "Creating…" : "Create"
|
|
@@ -1194,7 +1185,7 @@ var be = ({ schema: e, dataSource: t, className: s, data: d, loading: g, onEvent
|
|
|
1194
1185
|
let n = q?.provider === "object" ? q.object : e.objectName, r = Z.selectedRecord, i = r.id ?? r._id;
|
|
1195
1186
|
if (!n || i == null) return null;
|
|
1196
1187
|
let a = J?.titleField ? String(r[J.titleField] ?? "Event Details") : "Event Details";
|
|
1197
|
-
return /* @__PURE__ */ L(
|
|
1188
|
+
return /* @__PURE__ */ L(le, {
|
|
1198
1189
|
open: !0,
|
|
1199
1190
|
onClose: Z.close,
|
|
1200
1191
|
title: a,
|
|
@@ -1204,15 +1195,15 @@ var be = ({ schema: e, dataSource: t, className: s, data: d, loading: g, onEvent
|
|
|
1204
1195
|
dataSource: t,
|
|
1205
1196
|
objectSchema: z,
|
|
1206
1197
|
width: Z.width ?? "min(960px, 60vw)",
|
|
1207
|
-
fullPageHref:
|
|
1198
|
+
fullPageHref: ue(n, i) ?? void 0,
|
|
1208
1199
|
onFieldSave: async (e, r) => {
|
|
1209
|
-
t?.update && (await t.update(n, String(i), { [e]: r }),
|
|
1200
|
+
t?.update && (await t.update(n, String(i), { [e]: r }), P((t) => t.map((t) => String(t.id ?? t._id) === String(i) ? {
|
|
1210
1201
|
...t,
|
|
1211
1202
|
[e]: r
|
|
1212
1203
|
} : t)));
|
|
1213
1204
|
},
|
|
1214
1205
|
onDelete: async () => {
|
|
1215
|
-
t?.delete && (await t.delete(n, String(i)),
|
|
1206
|
+
t?.delete && (await t.delete(n, String(i)), P((e) => e.filter((e) => String(e.id ?? e._id) !== String(i))));
|
|
1216
1207
|
}
|
|
1217
1208
|
});
|
|
1218
1209
|
})()
|
|
@@ -1304,7 +1295,7 @@ s.register("calendar-view", ({ schema: e, className: n, onAction: r, events: i,
|
|
|
1304
1295
|
payload: {}
|
|
1305
1296
|
});
|
|
1306
1297
|
};
|
|
1307
|
-
return /* @__PURE__ */ L(
|
|
1298
|
+
return /* @__PURE__ */ L(he, {
|
|
1308
1299
|
className: n,
|
|
1309
1300
|
events: l,
|
|
1310
1301
|
currentDate: u,
|
|
@@ -1470,8 +1461,8 @@ function je(e) {
|
|
|
1470
1461
|
return e && typeof e.find == "function" ? e : void 0;
|
|
1471
1462
|
}
|
|
1472
1463
|
var Me = ({ schema: e, className: t, ...n }) => {
|
|
1473
|
-
let { dataSource: r } =
|
|
1474
|
-
return /* @__PURE__ */ L(
|
|
1464
|
+
let { dataSource: r } = _() || {}, i = De(n), a = Oe(n.locale), o = ke(n.data), s = Ae(n.loading), c = je(n.dataSource);
|
|
1465
|
+
return /* @__PURE__ */ L(f, {
|
|
1475
1466
|
schema: e,
|
|
1476
1467
|
mapping: Te,
|
|
1477
1468
|
dataSource: r,
|
|
@@ -1520,4 +1511,4 @@ s.register("object-calendar", Me, {
|
|
|
1520
1511
|
}]
|
|
1521
1512
|
});
|
|
1522
1513
|
//#endregion
|
|
1523
|
-
export {
|
|
1514
|
+
export { he as CalendarView, be as ObjectCalendar, Me as ObjectCalendarRenderer };
|