@super-calendar/dom 2.5.0 → 2.7.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/dist/index.d.mts +128 -16
- package/dist/index.d.ts +128 -16
- package/dist/index.js +763 -114
- package/dist/index.mjs +741 -117
- package/package.json +2 -2
- package/src/Agenda.tsx +5 -2
- package/src/Calendar.tsx +68 -8
- package/src/MonthList.tsx +3 -1
- package/src/MonthView.tsx +135 -3
- package/src/ResourceTimeline.tsx +269 -20
- package/src/TimeGrid.tsx +364 -80
- package/src/YearView.tsx +293 -0
- package/src/index.ts +6 -0
package/dist/index.js
CHANGED
|
@@ -112,7 +112,7 @@ function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverride
|
|
|
112
112
|
});
|
|
113
113
|
const Renderer = renderEvent;
|
|
114
114
|
const rows = (0, react.useMemo)(() => {
|
|
115
|
-
const sorted =
|
|
115
|
+
const sorted = events.filter((event) => !(0, _super_calendar_core.isBackgroundEvent)(event)).sort((a, b) => a.start.getTime() - b.start.getTime());
|
|
116
116
|
const out = [];
|
|
117
117
|
let currentDay = null;
|
|
118
118
|
sorted.forEach((event, index) => {
|
|
@@ -235,6 +235,184 @@ function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverride
|
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
237
|
//#endregion
|
|
238
|
+
//#region src/YearView.tsx
|
|
239
|
+
/**
|
|
240
|
+
* A year at a glance: the twelve months as compact mini grids, with today
|
|
241
|
+
* highlighted and a dot under days that hold events. It's the view `Calendar`
|
|
242
|
+
* renders for `mode="year"`.
|
|
243
|
+
*/
|
|
244
|
+
function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, activeDate, minMonthWidth = 150, onPressDay, onPressMonth, theme: themeOverrides, className, style, classNames, styles }) {
|
|
245
|
+
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
246
|
+
const slot = createSlots({
|
|
247
|
+
classNames,
|
|
248
|
+
styles
|
|
249
|
+
});
|
|
250
|
+
const months = (0, react.useMemo)(() => (0, _super_calendar_core.getYearMonths)(date), [date]);
|
|
251
|
+
const weekdayLabels = (0, react.useMemo)(() => (0, _super_calendar_core.filterHiddenDays)((0, _super_calendar_core.getWeekDays)(date, weekStartsOn), hiddenDays).map((d) => (0, date_fns.format)(d, (0, _super_calendar_core.weekdayFormatToken)("narrow"), { locale })), [
|
|
252
|
+
date,
|
|
253
|
+
weekStartsOn,
|
|
254
|
+
locale,
|
|
255
|
+
hiddenDays
|
|
256
|
+
]);
|
|
257
|
+
const eventDays = (0, react.useMemo)(() => new Set(events && events.length > 0 ? (0, _super_calendar_core.groupEventsByDay)(events.filter((e) => !(0, _super_calendar_core.isBackgroundEvent)(e))).keys() : []), [events]);
|
|
258
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
259
|
+
className,
|
|
260
|
+
style: {
|
|
261
|
+
fontFamily: theme.fontFamily,
|
|
262
|
+
color: theme.text,
|
|
263
|
+
overflowY: "auto",
|
|
264
|
+
...style
|
|
265
|
+
},
|
|
266
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
267
|
+
...slot("grid", { base: {
|
|
268
|
+
display: "grid",
|
|
269
|
+
gridTemplateColumns: `repeat(auto-fill, minmax(${minMonthWidth}px, 1fr))`
|
|
270
|
+
} }),
|
|
271
|
+
children: months.map((month) => {
|
|
272
|
+
const weeks = (0, _super_calendar_core.buildMonthWeeks)(month, weekStartsOn, { hiddenDays });
|
|
273
|
+
const monthLabel = (0, date_fns.format)(month, "MMMM yyyy", { locale });
|
|
274
|
+
const titleContent = (0, date_fns.format)(month, "MMMM", { locale });
|
|
275
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
276
|
+
...slot("month", { base: { padding: 8 } }),
|
|
277
|
+
children: [
|
|
278
|
+
onPressMonth ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
279
|
+
type: "button",
|
|
280
|
+
onClick: () => onPressMonth(month),
|
|
281
|
+
"aria-label": monthLabel,
|
|
282
|
+
...slot("monthTitle", {
|
|
283
|
+
base: {
|
|
284
|
+
display: "block",
|
|
285
|
+
border: "none",
|
|
286
|
+
background: "transparent",
|
|
287
|
+
padding: "0 0 4px",
|
|
288
|
+
cursor: "pointer",
|
|
289
|
+
font: "inherit",
|
|
290
|
+
textAlign: "left"
|
|
291
|
+
},
|
|
292
|
+
themed: {
|
|
293
|
+
fontSize: 13,
|
|
294
|
+
fontWeight: 700,
|
|
295
|
+
color: theme.todayBackground
|
|
296
|
+
}
|
|
297
|
+
}),
|
|
298
|
+
children: titleContent
|
|
299
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
300
|
+
role: "heading",
|
|
301
|
+
"aria-level": 3,
|
|
302
|
+
"aria-label": monthLabel,
|
|
303
|
+
...slot("monthTitle", {
|
|
304
|
+
base: { paddingBottom: 4 },
|
|
305
|
+
themed: {
|
|
306
|
+
fontSize: 13,
|
|
307
|
+
fontWeight: 700,
|
|
308
|
+
color: theme.todayBackground
|
|
309
|
+
}
|
|
310
|
+
}),
|
|
311
|
+
children: titleContent
|
|
312
|
+
}),
|
|
313
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
314
|
+
...slot("weekdays", { base: {
|
|
315
|
+
display: "grid",
|
|
316
|
+
gridTemplateColumns: "repeat(7, 1fr)"
|
|
317
|
+
} }),
|
|
318
|
+
children: weekdayLabels.map((label, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
319
|
+
"aria-hidden": true,
|
|
320
|
+
...slot("weekday", {
|
|
321
|
+
base: { textAlign: "center" },
|
|
322
|
+
themed: {
|
|
323
|
+
fontSize: 9,
|
|
324
|
+
fontWeight: 600,
|
|
325
|
+
color: theme.textMuted
|
|
326
|
+
}
|
|
327
|
+
}),
|
|
328
|
+
children: label
|
|
329
|
+
}, i))
|
|
330
|
+
}),
|
|
331
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
332
|
+
role: "grid",
|
|
333
|
+
"aria-label": monthLabel,
|
|
334
|
+
children: weeks.map((week) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
335
|
+
role: "row",
|
|
336
|
+
...slot("week", { base: {
|
|
337
|
+
display: "grid",
|
|
338
|
+
gridTemplateColumns: "repeat(7, 1fr)"
|
|
339
|
+
} }),
|
|
340
|
+
children: week.map((day) => {
|
|
341
|
+
if (day.getMonth() !== month.getMonth()) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
342
|
+
role: "gridcell",
|
|
343
|
+
"aria-hidden": true,
|
|
344
|
+
style: { aspectRatio: "1" }
|
|
345
|
+
}, day.toISOString());
|
|
346
|
+
const isHighlighted = activeDate ? (0, _super_calendar_core.isSameCalendarDay)(day, activeDate) : (0, _super_calendar_core.getIsToday)(day);
|
|
347
|
+
const hasEvents = eventDays.has((0, date_fns.startOfDay)(day).toISOString());
|
|
348
|
+
const label = `${(0, date_fns.format)(day, "EEEE, d LLLL yyyy", { locale })}${(0, _super_calendar_core.getIsToday)(day) ? ", today" : ""}${hasEvents ? ", has events" : ""}`;
|
|
349
|
+
const daySlot = slot("day", {
|
|
350
|
+
base: {
|
|
351
|
+
position: "relative",
|
|
352
|
+
aspectRatio: "1",
|
|
353
|
+
display: "flex",
|
|
354
|
+
alignItems: "center",
|
|
355
|
+
justifyContent: "center",
|
|
356
|
+
padding: 0,
|
|
357
|
+
border: "none",
|
|
358
|
+
background: "transparent",
|
|
359
|
+
font: "inherit",
|
|
360
|
+
cursor: onPressDay ? "pointer" : "default",
|
|
361
|
+
boxSizing: "border-box"
|
|
362
|
+
},
|
|
363
|
+
themed: {
|
|
364
|
+
fontSize: 11,
|
|
365
|
+
borderRadius: "50%",
|
|
366
|
+
...isHighlighted ? {
|
|
367
|
+
background: theme.todayBackground,
|
|
368
|
+
color: theme.todayText
|
|
369
|
+
} : { color: theme.text }
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
const states = dataState({
|
|
373
|
+
"data-today": (0, _super_calendar_core.getIsToday)(day),
|
|
374
|
+
"data-events": hasEvents
|
|
375
|
+
});
|
|
376
|
+
const dot = hasEvents ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
377
|
+
"aria-hidden": true,
|
|
378
|
+
...slot("eventDot", {
|
|
379
|
+
base: {
|
|
380
|
+
position: "absolute",
|
|
381
|
+
bottom: 1,
|
|
382
|
+
left: "50%",
|
|
383
|
+
marginLeft: -1.5,
|
|
384
|
+
width: 3,
|
|
385
|
+
height: 3,
|
|
386
|
+
borderRadius: 2
|
|
387
|
+
},
|
|
388
|
+
themed: { background: isHighlighted ? theme.todayText : theme.todayBackground }
|
|
389
|
+
})
|
|
390
|
+
}) : null;
|
|
391
|
+
return onPressDay ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
392
|
+
type: "button",
|
|
393
|
+
role: "gridcell",
|
|
394
|
+
onClick: () => onPressDay(day),
|
|
395
|
+
"aria-label": label,
|
|
396
|
+
...states,
|
|
397
|
+
...daySlot,
|
|
398
|
+
children: [day.getDate(), dot]
|
|
399
|
+
}, day.toISOString()) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
400
|
+
role: "gridcell",
|
|
401
|
+
"aria-label": label,
|
|
402
|
+
...states,
|
|
403
|
+
...daySlot,
|
|
404
|
+
children: [day.getDate(), dot]
|
|
405
|
+
}, day.toISOString());
|
|
406
|
+
})
|
|
407
|
+
}, week[0].toISOString()))
|
|
408
|
+
})
|
|
409
|
+
]
|
|
410
|
+
}, month.toISOString());
|
|
411
|
+
})
|
|
412
|
+
})
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
//#endregion
|
|
238
416
|
//#region src/MonthView.tsx
|
|
239
417
|
const DATE_ROW = 24;
|
|
240
418
|
const CHIP_HEIGHT = 18;
|
|
@@ -422,7 +600,7 @@ function moreButtonDefault(theme) {
|
|
|
422
600
|
* <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
|
|
423
601
|
* ```
|
|
424
602
|
*/
|
|
425
|
-
function MonthView({ date, weekStartsOn = 0, weekdayFormat = "short", events, eventsByDay: eventsByDayProp, renderEvent, eventAccessibilityLabel, maxVisibleEventCount = 3, moreLabel = "{moreCount} More", onPressEvent, onPressMore, selectedRange, selectedDates, showAdjacentMonths = true, fillCellOnSelection = false, showTitle = true, showWeekdays = true, locale, theme: themeOverrides, minDate, maxDate, isDateDisabled, onPressDay, onCreateEvent, keyboardDayNavigation = false, className, style, classNames, styles }) {
|
|
603
|
+
function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short", events, eventsByDay: eventsByDayProp, renderEvent, eventAccessibilityLabel, maxVisibleEventCount = 3, moreLabel = "{moreCount} More", onPressEvent, onPressMore, selectedRange, selectedDates, showAdjacentMonths = true, fillCellOnSelection = false, showTitle = true, showWeekdays = true, locale, theme: themeOverrides, minDate, maxDate, isDateDisabled, onPressDay, onCreateEvent, keyboardDayNavigation = false, className, style, classNames, styles }) {
|
|
426
604
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
427
605
|
const slot = createSlots({
|
|
428
606
|
classNames,
|
|
@@ -432,14 +610,44 @@ function MonthView({ date, weekStartsOn = 0, weekdayFormat = "short", events, ev
|
|
|
432
610
|
const dayRoving = !eventsMode || keyboardDayNavigation;
|
|
433
611
|
const eventsByDay = (0, react.useMemo)(() => {
|
|
434
612
|
if (eventsByDayProp) return eventsByDayProp;
|
|
435
|
-
const map = (0, _super_calendar_core.groupEventsByDay)(events ?? []);
|
|
613
|
+
const map = (0, _super_calendar_core.groupEventsByDay)((events ?? []).filter((event) => !(0, _super_calendar_core.isBackgroundEvent)(event)));
|
|
436
614
|
for (const list of map.values()) list.sort(_super_calendar_core.compareDayEvents);
|
|
437
615
|
return map;
|
|
438
616
|
}, [eventsByDayProp, events]);
|
|
439
617
|
const Chip = renderEvent;
|
|
618
|
+
const [moreOpenFor, setMoreOpenFor] = (0, react.useState)(null);
|
|
619
|
+
const morePopoverRef = (0, react.useRef)(null);
|
|
620
|
+
const moreTriggerRef = (0, react.useRef)(null);
|
|
621
|
+
(0, react.useEffect)(() => {
|
|
622
|
+
if (moreOpenFor) {
|
|
623
|
+
morePopoverRef.current?.querySelector("button")?.focus();
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
moreTriggerRef.current?.focus();
|
|
627
|
+
moreTriggerRef.current = null;
|
|
628
|
+
}, [moreOpenFor]);
|
|
629
|
+
(0, react.useEffect)(() => {
|
|
630
|
+
if (!moreOpenFor) return;
|
|
631
|
+
const onDocPointerDown = (e) => {
|
|
632
|
+
if (!morePopoverRef.current?.contains(e.target)) {
|
|
633
|
+
moreTriggerRef.current = null;
|
|
634
|
+
setMoreOpenFor(null);
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
const onKey = (e) => {
|
|
638
|
+
if (e.key === "Escape") setMoreOpenFor(null);
|
|
639
|
+
};
|
|
640
|
+
document.addEventListener("pointerdown", onDocPointerDown);
|
|
641
|
+
document.addEventListener("keydown", onKey);
|
|
642
|
+
return () => {
|
|
643
|
+
document.removeEventListener("pointerdown", onDocPointerDown);
|
|
644
|
+
document.removeEventListener("keydown", onKey);
|
|
645
|
+
};
|
|
646
|
+
}, [moreOpenFor]);
|
|
440
647
|
const eventRowHeight = 32 + maxVisibleEventCount * 20;
|
|
441
648
|
const { weeks, weekdays } = (0, react.useMemo)(() => (0, _super_calendar_core.buildMonthGrid)(date, {
|
|
442
649
|
weekStartsOn,
|
|
650
|
+
hiddenDays,
|
|
443
651
|
weekdayFormat,
|
|
444
652
|
selectedRange,
|
|
445
653
|
selectedDates,
|
|
@@ -660,39 +868,120 @@ function MonthView({ date, weekStartsOn = 0, weekdayFormat = "short", events, ev
|
|
|
660
868
|
flexDirection: "column",
|
|
661
869
|
gap: CHIP_GAP
|
|
662
870
|
} }),
|
|
663
|
-
children: [
|
|
664
|
-
|
|
665
|
-
|
|
871
|
+
children: [
|
|
872
|
+
shown.map((event) => {
|
|
873
|
+
const onPress = () => onPressEvent?.(event);
|
|
874
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
875
|
+
type: "button",
|
|
876
|
+
onClick: (e) => {
|
|
877
|
+
e.stopPropagation();
|
|
878
|
+
onPress();
|
|
879
|
+
},
|
|
880
|
+
...slot("chipButton", chipButtonDefault),
|
|
881
|
+
title: event.title,
|
|
882
|
+
"aria-label": eventAccessibilityLabel ? eventAccessibilityLabel(event, {
|
|
883
|
+
mode: "month",
|
|
884
|
+
isAllDay: (0, _super_calendar_core.isAllDayEvent)(event),
|
|
885
|
+
ampm: false
|
|
886
|
+
}) : `${event.title}, ${dayLabel}`,
|
|
887
|
+
children: Chip ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chip, {
|
|
888
|
+
event,
|
|
889
|
+
onPress
|
|
890
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
891
|
+
...slot("chip", chipDefault(theme)),
|
|
892
|
+
children: event.title
|
|
893
|
+
})
|
|
894
|
+
}, `${event.start.toISOString()}:${event.title}`);
|
|
895
|
+
}),
|
|
896
|
+
overflow ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
666
897
|
type: "button",
|
|
898
|
+
onPointerDown: onPressMore ? void 0 : (e) => e.stopPropagation(),
|
|
667
899
|
onClick: (e) => {
|
|
668
900
|
e.stopPropagation();
|
|
669
|
-
|
|
901
|
+
if (onPressMore) onPressMore(rest, day.date);
|
|
902
|
+
else {
|
|
903
|
+
moreTriggerRef.current = e.currentTarget;
|
|
904
|
+
setMoreOpenFor((open) => open === day.id ? null : day.id);
|
|
905
|
+
}
|
|
670
906
|
},
|
|
671
|
-
...slot("
|
|
672
|
-
|
|
673
|
-
"aria-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
907
|
+
...slot("more", moreButtonDefault(theme)),
|
|
908
|
+
"aria-label": `${rest.length} more events, ${dayLabel}`,
|
|
909
|
+
"aria-expanded": onPressMore ? void 0 : moreOpenFor === day.id,
|
|
910
|
+
children: moreLabel.replace("{moreCount}", String(rest.length))
|
|
911
|
+
}) : null,
|
|
912
|
+
moreOpenFor === day.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
913
|
+
ref: morePopoverRef,
|
|
914
|
+
role: "dialog",
|
|
915
|
+
"aria-label": dayLabel,
|
|
916
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
917
|
+
onKeyDown: (e) => {
|
|
918
|
+
if (e.key !== "Tab") return;
|
|
919
|
+
const buttons = morePopoverRef.current?.querySelectorAll("button");
|
|
920
|
+
if (!buttons?.length) return;
|
|
921
|
+
const first = buttons[0];
|
|
922
|
+
const last = buttons[buttons.length - 1];
|
|
923
|
+
if (e.shiftKey && document.activeElement === first) {
|
|
924
|
+
e.preventDefault();
|
|
925
|
+
last.focus();
|
|
926
|
+
} else if (!e.shiftKey && document.activeElement === last) {
|
|
927
|
+
e.preventDefault();
|
|
928
|
+
first.focus();
|
|
929
|
+
}
|
|
930
|
+
},
|
|
931
|
+
...slot("morePopover", {
|
|
932
|
+
base: {
|
|
933
|
+
position: "absolute",
|
|
934
|
+
top: 2,
|
|
935
|
+
left: 2,
|
|
936
|
+
right: 2,
|
|
937
|
+
zIndex: 10,
|
|
938
|
+
display: "flex",
|
|
939
|
+
flexDirection: "column",
|
|
940
|
+
gap: 2,
|
|
941
|
+
maxHeight: 240,
|
|
942
|
+
overflowY: "auto"
|
|
943
|
+
},
|
|
944
|
+
themed: {
|
|
945
|
+
background: theme.surface,
|
|
946
|
+
border: `1px solid ${theme.gridLine}`,
|
|
947
|
+
borderRadius: 8,
|
|
948
|
+
padding: 6,
|
|
949
|
+
boxShadow: "0 4px 16px rgba(0,0,0,0.12)"
|
|
950
|
+
}
|
|
951
|
+
}),
|
|
952
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
953
|
+
style: {
|
|
954
|
+
fontSize: 11,
|
|
955
|
+
fontWeight: 600,
|
|
956
|
+
color: theme.textMuted
|
|
957
|
+
},
|
|
958
|
+
children: dayLabel
|
|
959
|
+
}), dayEvents.map((event, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
960
|
+
type: "button",
|
|
961
|
+
onClick: () => {
|
|
962
|
+
setMoreOpenFor(null);
|
|
963
|
+
onPressEvent?.(event);
|
|
964
|
+
},
|
|
965
|
+
style: {
|
|
966
|
+
display: "block",
|
|
967
|
+
width: "100%",
|
|
968
|
+
border: "none",
|
|
969
|
+
background: "transparent",
|
|
970
|
+
padding: 0,
|
|
971
|
+
font: "inherit",
|
|
972
|
+
textAlign: "left",
|
|
973
|
+
cursor: "pointer"
|
|
974
|
+
},
|
|
975
|
+
children: Chip ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chip, {
|
|
976
|
+
event,
|
|
977
|
+
onPress: () => onPressEvent?.(event)
|
|
978
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
979
|
+
...slot("chip", chipDefault(theme)),
|
|
980
|
+
children: event.title
|
|
981
|
+
})
|
|
982
|
+
}, i))]
|
|
983
|
+
}) : null
|
|
984
|
+
]
|
|
696
985
|
})
|
|
697
986
|
]
|
|
698
987
|
}, day.id);
|
|
@@ -730,6 +1019,9 @@ function MonthView({ date, weekStartsOn = 0, weekdayFormat = "short", events, ev
|
|
|
730
1019
|
//#region src/TimeGrid.tsx
|
|
731
1020
|
const GUTTER_WIDTH$1 = 56;
|
|
732
1021
|
const clamp$1 = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
1022
|
+
const EDGE_ZONE = 32;
|
|
1023
|
+
const EDGE_DWELL_MS = 600;
|
|
1024
|
+
const EDGE_REPEAT_MS = 600;
|
|
733
1025
|
const VISUALLY_HIDDEN = {
|
|
734
1026
|
position: "absolute",
|
|
735
1027
|
width: 1,
|
|
@@ -812,17 +1104,6 @@ function DefaultDomEvent({ event, mode, isAllDay, boxHeight, ampm = false, theme
|
|
|
812
1104
|
}) : null]
|
|
813
1105
|
});
|
|
814
1106
|
}
|
|
815
|
-
const NOW_TICK_MS = 6e4;
|
|
816
|
-
function useNow(enabled) {
|
|
817
|
-
const [now, setNow] = (0, react.useState)(() => /* @__PURE__ */ new Date());
|
|
818
|
-
(0, react.useEffect)(() => {
|
|
819
|
-
if (!enabled) return;
|
|
820
|
-
setNow(/* @__PURE__ */ new Date());
|
|
821
|
-
const id = setInterval(() => setNow(/* @__PURE__ */ new Date()), NOW_TICK_MS);
|
|
822
|
-
return () => clearInterval(id);
|
|
823
|
-
}, [enabled]);
|
|
824
|
-
return now;
|
|
825
|
-
}
|
|
826
1107
|
/**
|
|
827
1108
|
* A day / week / N-day time grid rendered with plain DOM elements. Events are
|
|
828
1109
|
* positioned with the library's pure `layoutDayEvents`, so overlap columns and
|
|
@@ -834,7 +1115,7 @@ function useNow(enabled) {
|
|
|
834
1115
|
* <TimeGrid mode="week" date={new Date()} events={events} />
|
|
835
1116
|
* ```
|
|
836
1117
|
*/
|
|
837
|
-
function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStartsOn = 0, weekdayFormat = "short", hourHeight: initialHourHeight = 48, scrollOffsetMinutes = 480, zoomable = true, minHourHeight = 24, maxHourHeight = 160, dragStepMinutes = 15, ampm = false, timeslots = 1, minHour = 0, maxHour = 24, hideHours = false, showWeekNumber = false, weekNumberPrefix = "W", keyboardEventNavigation = false, businessHours, showNowIndicator = true, showAllDayEventCell = true, locale, theme: themeOverrides, height = 600, renderEvent, eventAccessibilityLabel, hourComponent, onPressEvent, onPressDateHeader, onPressCell, onCreateEvent, onDragStart, onDragEvent, className, style, classNames, styles }) {
|
|
1118
|
+
function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStartsOn = 0, weekdayFormat = "short", hourHeight: initialHourHeight = 48, scrollOffsetMinutes = 480, zoomable = true, minHourHeight = 24, maxHourHeight = 160, dragStepMinutes = 15, ampm = false, timeslots = 1, minHour = 0, maxHour = 24, hideHours = false, showWeekNumber = false, weekNumberPrefix = "W", hiddenDays, keyboardEventNavigation = false, businessHours, renderBusinessHours, showNowIndicator = true, highlightWeekends = true, now: nowProp, timeZone, showAllDayEventCell = true, locale, theme: themeOverrides, height = 600, renderEvent, eventAccessibilityLabel, hourComponent, onPressEvent, onPressDateHeader, onPressCell, onCreateEvent, onDragStart, onDragEvent, onChangeDate, className, style, classNames, styles }) {
|
|
838
1119
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
839
1120
|
const slot = createSlots({
|
|
840
1121
|
classNames,
|
|
@@ -848,7 +1129,10 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
848
1129
|
const windowHours = windowEnd - windowStart;
|
|
849
1130
|
const gutterWidth = hideHours ? 0 : GUTTER_WIDTH$1;
|
|
850
1131
|
const visibleHours = (0, react.useMemo)(() => Array.from({ length: windowHours }, (_, i) => windowStart + i), [windowStart, windowHours]);
|
|
851
|
-
const now = useNow(showNowIndicator
|
|
1132
|
+
const now = (0, _super_calendar_core.useNow)(showNowIndicator, {
|
|
1133
|
+
now: nowProp,
|
|
1134
|
+
timeZone
|
|
1135
|
+
});
|
|
852
1136
|
const [hourHeight, setHourHeight] = (0, react.useState)(initialHourHeight);
|
|
853
1137
|
(0, react.useEffect)(() => setHourHeight(initialHourHeight), [initialHourHeight]);
|
|
854
1138
|
const hourHeightRef = (0, react.useRef)(hourHeight);
|
|
@@ -863,16 +1147,48 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
863
1147
|
const [createBox, setCreateBox] = (0, react.useState)(null);
|
|
864
1148
|
const createOrigin = (0, react.useRef)(null);
|
|
865
1149
|
const cellEnabled = !!onPressCell || !!onCreateEvent;
|
|
866
|
-
const days = (0, react.useMemo)(() => (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays), [
|
|
1150
|
+
const days = (0, react.useMemo)(() => (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays, false, void 0, hiddenDays), [
|
|
867
1151
|
mode,
|
|
868
1152
|
date,
|
|
869
1153
|
weekStartsOn,
|
|
870
|
-
numberOfDays
|
|
1154
|
+
numberOfDays,
|
|
1155
|
+
hiddenDays
|
|
871
1156
|
]);
|
|
1157
|
+
const edgeAdvanceEnabled = !!onChangeDate && !!onDragEvent;
|
|
1158
|
+
const columnsRef = (0, react.useRef)(null);
|
|
1159
|
+
const edgeTimer = (0, react.useRef)(null);
|
|
1160
|
+
const edgeSide = (0, react.useRef)(0);
|
|
1161
|
+
const ptr = (0, react.useRef)({
|
|
1162
|
+
x: 0,
|
|
1163
|
+
y: 0
|
|
1164
|
+
});
|
|
1165
|
+
const pagedRef = (0, react.useRef)(false);
|
|
1166
|
+
const [paged, setPaged] = (0, react.useState)(false);
|
|
1167
|
+
const draggedRef = (0, react.useRef)(null);
|
|
1168
|
+
const ghostRef = (0, react.useRef)(null);
|
|
1169
|
+
const docHandlersRef = (0, react.useRef)(null);
|
|
1170
|
+
const daysRef = (0, react.useRef)(days);
|
|
1171
|
+
daysRef.current = days;
|
|
1172
|
+
const pageDepsRef = (0, react.useRef)({
|
|
1173
|
+
date,
|
|
1174
|
+
mode,
|
|
1175
|
+
weekStartsOn,
|
|
1176
|
+
numberOfDays
|
|
1177
|
+
});
|
|
1178
|
+
pageDepsRef.current = {
|
|
1179
|
+
date,
|
|
1180
|
+
mode,
|
|
1181
|
+
weekStartsOn,
|
|
1182
|
+
numberOfDays
|
|
1183
|
+
};
|
|
1184
|
+
const onChangeDateRef = (0, react.useRef)(onChangeDate);
|
|
1185
|
+
onChangeDateRef.current = onChangeDate;
|
|
1186
|
+
const onDragEventRef = (0, react.useRef)(onDragEvent);
|
|
1187
|
+
onDragEventRef.current = onDragEvent;
|
|
872
1188
|
const allDayByDay = (0, react.useMemo)(() => days.map((day) => {
|
|
873
1189
|
const dayStart = (0, date_fns.startOfDay)(day);
|
|
874
1190
|
const dayEnd = (0, date_fns.addDays)(dayStart, 1);
|
|
875
|
-
return events.filter((e) => (0, _super_calendar_core.isAllDayEvent)(e) && e.start < dayEnd && e.end > dayStart);
|
|
1191
|
+
return events.filter((e) => (0, _super_calendar_core.isAllDayEvent)(e) && !(0, _super_calendar_core.isBackgroundEvent)(e) && e.start < dayEnd && e.end > dayStart);
|
|
876
1192
|
}), [days, events]);
|
|
877
1193
|
const hasAllDay = allDayByDay.some((list) => list.length > 0);
|
|
878
1194
|
(0, react.useEffect)(() => {
|
|
@@ -921,47 +1237,59 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
921
1237
|
};
|
|
922
1238
|
const Renderer = renderEvent;
|
|
923
1239
|
const totalHeight = windowHours * hourHeight;
|
|
924
|
-
const
|
|
925
|
-
if (
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
e.target.setPointerCapture?.(e.pointerId);
|
|
929
|
-
} catch {}
|
|
930
|
-
const column = kind === "move" ? e.currentTarget.parentElement : null;
|
|
931
|
-
const dayWidth = column ? column.getBoundingClientRect().width : 0;
|
|
932
|
-
dragOrigin.current = {
|
|
933
|
-
pointerX: e.clientX,
|
|
934
|
-
pointerY: e.clientY,
|
|
935
|
-
startHours,
|
|
936
|
-
durationHours,
|
|
937
|
-
dayIndex,
|
|
938
|
-
dayWidth
|
|
939
|
-
};
|
|
940
|
-
applyDrag({
|
|
941
|
-
key,
|
|
942
|
-
kind,
|
|
943
|
-
startHours,
|
|
944
|
-
durationHours,
|
|
945
|
-
dayDelta: 0,
|
|
946
|
-
dayOffsetPx: 0,
|
|
947
|
-
moved: false
|
|
948
|
-
});
|
|
949
|
-
onDragStart?.(event);
|
|
1240
|
+
const dayAt = (x, y) => {
|
|
1241
|
+
if (typeof document === "undefined" || typeof document.elementFromPoint !== "function") return null;
|
|
1242
|
+
const iso = (document.elementFromPoint(x, y)?.closest?.("[data-date]"))?.getAttribute("data-date");
|
|
1243
|
+
return iso ? new Date(iso) : null;
|
|
950
1244
|
};
|
|
951
|
-
const
|
|
952
|
-
|
|
1245
|
+
const clearEdgeTimer = () => {
|
|
1246
|
+
if (edgeTimer.current) {
|
|
1247
|
+
clearTimeout(edgeTimer.current);
|
|
1248
|
+
edgeTimer.current = null;
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
const fireEdge = () => {
|
|
1252
|
+
const side = edgeSide.current;
|
|
1253
|
+
if (side === 0) return;
|
|
1254
|
+
const p = pageDepsRef.current;
|
|
1255
|
+
const step = (0, _super_calendar_core.pageStepDays)(p.mode, p.date, p.weekStartsOn, p.numberOfDays);
|
|
1256
|
+
onChangeDateRef.current?.((0, date_fns.addDays)(p.date, side * step));
|
|
1257
|
+
pagedRef.current = true;
|
|
1258
|
+
setPaged(true);
|
|
1259
|
+
edgeTimer.current = setTimeout(fireEdge, EDGE_REPEAT_MS);
|
|
1260
|
+
};
|
|
1261
|
+
const detachDocListeners = () => {
|
|
1262
|
+
const h = docHandlersRef.current;
|
|
1263
|
+
if (!h) return;
|
|
1264
|
+
document.removeEventListener("pointermove", h.move);
|
|
1265
|
+
document.removeEventListener("pointerup", h.up);
|
|
1266
|
+
document.removeEventListener("pointercancel", h.cancel);
|
|
1267
|
+
docHandlersRef.current = null;
|
|
1268
|
+
};
|
|
1269
|
+
const finishDrag = () => {
|
|
1270
|
+
detachDocListeners();
|
|
1271
|
+
clearEdgeTimer();
|
|
1272
|
+
edgeSide.current = 0;
|
|
1273
|
+
pagedRef.current = false;
|
|
1274
|
+
setPaged(false);
|
|
1275
|
+
draggedRef.current = null;
|
|
953
1276
|
dragOrigin.current = null;
|
|
1277
|
+
applyDrag(null);
|
|
954
1278
|
};
|
|
955
1279
|
const moveDrag = (e) => {
|
|
956
1280
|
const d = dragRef.current;
|
|
957
1281
|
if (!d || !dragOrigin.current) return;
|
|
1282
|
+
ptr.current = {
|
|
1283
|
+
x: e.clientX,
|
|
1284
|
+
y: e.clientY
|
|
1285
|
+
};
|
|
958
1286
|
const dHours = (e.clientY - dragOrigin.current.pointerY) / hourHeightRef.current;
|
|
959
1287
|
const snap = (v) => Math.round(v / snapHours) * snapHours;
|
|
960
1288
|
if (d.kind === "move") {
|
|
961
1289
|
const startHours = clamp$1(snap(dragOrigin.current.startHours + dHours), windowStart, Math.max(windowStart, windowEnd - d.durationHours));
|
|
962
1290
|
const o = dragOrigin.current;
|
|
963
1291
|
const rawDayDelta = o.dayWidth > 0 ? Math.round((e.clientX - o.pointerX) / o.dayWidth) : 0;
|
|
964
|
-
const dayDelta = clamp$1(o.dayIndex + rawDayDelta, 0,
|
|
1292
|
+
const dayDelta = clamp$1(o.dayIndex + rawDayDelta, 0, daysRef.current.length - 1) - o.dayIndex;
|
|
965
1293
|
applyDrag({
|
|
966
1294
|
...d,
|
|
967
1295
|
startHours,
|
|
@@ -969,6 +1297,21 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
969
1297
|
dayOffsetPx: dayDelta * o.dayWidth,
|
|
970
1298
|
moved: true
|
|
971
1299
|
});
|
|
1300
|
+
const g = ghostRef.current;
|
|
1301
|
+
const held = draggedRef.current;
|
|
1302
|
+
if (g && held) g.style.transform = `translate(${e.clientX - held.grabX}px, ${e.clientY - held.grabY}px)`;
|
|
1303
|
+
if (edgeAdvanceEnabled) {
|
|
1304
|
+
const rect = columnsRef.current?.getBoundingClientRect();
|
|
1305
|
+
if (rect && rect.right > rect.left) {
|
|
1306
|
+
const left = rect.left + gutterWidth;
|
|
1307
|
+
const side = e.clientX <= left + EDGE_ZONE ? -1 : e.clientX >= rect.right - EDGE_ZONE ? 1 : 0;
|
|
1308
|
+
if (side !== edgeSide.current) {
|
|
1309
|
+
clearEdgeTimer();
|
|
1310
|
+
edgeSide.current = side;
|
|
1311
|
+
if (side !== 0) edgeTimer.current = setTimeout(fireEdge, EDGE_DWELL_MS);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
972
1315
|
} else {
|
|
973
1316
|
const durationHours = clamp$1(snap(dragOrigin.current.durationHours + dHours), snapHours, Math.max(snapHours, windowEnd - d.startHours));
|
|
974
1317
|
applyDrag({
|
|
@@ -978,24 +1321,94 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
978
1321
|
});
|
|
979
1322
|
}
|
|
980
1323
|
};
|
|
981
|
-
const endDrag = (e
|
|
1324
|
+
const endDrag = (e) => {
|
|
982
1325
|
const d = dragRef.current;
|
|
983
1326
|
if (!d) return;
|
|
984
1327
|
try {
|
|
985
|
-
e.target
|
|
1328
|
+
e.target?.releasePointerCapture?.(e.pointerId);
|
|
986
1329
|
} catch {}
|
|
1330
|
+
const held = draggedRef.current;
|
|
987
1331
|
if (!d.moved) {
|
|
988
|
-
|
|
989
|
-
onPress();
|
|
1332
|
+
finishDrag();
|
|
1333
|
+
held?.onPress();
|
|
990
1334
|
return;
|
|
991
1335
|
}
|
|
992
|
-
const
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1336
|
+
const originIndex = dragOrigin.current?.dayIndex ?? 0;
|
|
1337
|
+
let base = null;
|
|
1338
|
+
if (d.kind === "move") if (pagedRef.current) {
|
|
1339
|
+
const day = dayAt(e.clientX, e.clientY);
|
|
1340
|
+
base = day ? (0, date_fns.startOfDay)(day) : null;
|
|
1341
|
+
} else base = (0, date_fns.startOfDay)(daysRef.current[originIndex + d.dayDelta] ?? daysRef.current[originIndex]);
|
|
1342
|
+
else base = (0, date_fns.startOfDay)(daysRef.current[originIndex] ?? daysRef.current[0]);
|
|
1343
|
+
if (base && held) {
|
|
1344
|
+
const start = (0, date_fns.addMinutes)(base, Math.round(d.startHours * 60));
|
|
1345
|
+
const end = (0, date_fns.addMinutes)(base, Math.round((d.startHours + d.durationHours) * 60));
|
|
1346
|
+
onDragEventRef.current?.(held.event, start, end);
|
|
1347
|
+
}
|
|
1348
|
+
finishDrag();
|
|
1349
|
+
};
|
|
1350
|
+
const cancelDrag = () => {
|
|
1351
|
+
finishDrag();
|
|
998
1352
|
};
|
|
1353
|
+
const beginDrag = (e, event, key, kind, startHours, durationHours, dayIndex, onPress) => {
|
|
1354
|
+
if (!onDragEvent) return;
|
|
1355
|
+
e.stopPropagation();
|
|
1356
|
+
try {
|
|
1357
|
+
e.target.setPointerCapture?.(e.pointerId);
|
|
1358
|
+
} catch {}
|
|
1359
|
+
const boxEl = e.currentTarget;
|
|
1360
|
+
const column = kind === "move" ? boxEl.parentElement : null;
|
|
1361
|
+
const dayWidth = column ? column.getBoundingClientRect().width : 0;
|
|
1362
|
+
const boxRect = kind === "move" ? boxEl.getBoundingClientRect() : null;
|
|
1363
|
+
dragOrigin.current = {
|
|
1364
|
+
pointerX: e.clientX,
|
|
1365
|
+
pointerY: e.clientY,
|
|
1366
|
+
startHours,
|
|
1367
|
+
durationHours,
|
|
1368
|
+
dayIndex,
|
|
1369
|
+
dayWidth
|
|
1370
|
+
};
|
|
1371
|
+
draggedRef.current = {
|
|
1372
|
+
event,
|
|
1373
|
+
onPress: onPress ?? (() => {}),
|
|
1374
|
+
grabX: boxRect ? e.clientX - boxRect.left : 0,
|
|
1375
|
+
grabY: boxRect ? e.clientY - boxRect.top : 0,
|
|
1376
|
+
w: boxRect ? boxRect.width : 0,
|
|
1377
|
+
h: boxRect ? boxRect.height : 0
|
|
1378
|
+
};
|
|
1379
|
+
ptr.current = {
|
|
1380
|
+
x: e.clientX,
|
|
1381
|
+
y: e.clientY
|
|
1382
|
+
};
|
|
1383
|
+
edgeSide.current = 0;
|
|
1384
|
+
pagedRef.current = false;
|
|
1385
|
+
setPaged(false);
|
|
1386
|
+
clearEdgeTimer();
|
|
1387
|
+
applyDrag({
|
|
1388
|
+
key,
|
|
1389
|
+
kind,
|
|
1390
|
+
startHours,
|
|
1391
|
+
durationHours,
|
|
1392
|
+
dayDelta: 0,
|
|
1393
|
+
dayOffsetPx: 0,
|
|
1394
|
+
moved: false
|
|
1395
|
+
});
|
|
1396
|
+
onDragStart?.(event);
|
|
1397
|
+
detachDocListeners();
|
|
1398
|
+
const handlers = {
|
|
1399
|
+
move: moveDrag,
|
|
1400
|
+
up: endDrag,
|
|
1401
|
+
cancel: cancelDrag
|
|
1402
|
+
};
|
|
1403
|
+
docHandlersRef.current = handlers;
|
|
1404
|
+
document.addEventListener("pointermove", handlers.move);
|
|
1405
|
+
document.addEventListener("pointerup", handlers.up);
|
|
1406
|
+
document.addEventListener("pointercancel", handlers.cancel);
|
|
1407
|
+
};
|
|
1408
|
+
(0, react.useEffect)(() => () => {
|
|
1409
|
+
detachDocListeners();
|
|
1410
|
+
clearEdgeTimer();
|
|
1411
|
+
}, []);
|
|
999
1412
|
const pxFromTop = (el, clientY) => clientY - el.getBoundingClientRect().top;
|
|
1000
1413
|
const beginCreate = (e, dayIndex) => {
|
|
1001
1414
|
if (!cellEnabled || e.pointerType === "touch") return;
|
|
@@ -1117,6 +1530,16 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1117
1530
|
windowStart,
|
|
1118
1531
|
windowEnd
|
|
1119
1532
|
]);
|
|
1533
|
+
const backgroundByDay = (0, react.useMemo)(() => days.map((day) => (0, _super_calendar_core.backgroundBandsForDay)(events, day).map((b) => ({
|
|
1534
|
+
...b,
|
|
1535
|
+
startHours: Math.max(b.startHours, windowStart),
|
|
1536
|
+
endHours: Math.min(b.endHours, windowEnd)
|
|
1537
|
+
})).filter((b) => b.endHours > b.startHours)), [
|
|
1538
|
+
days,
|
|
1539
|
+
events,
|
|
1540
|
+
windowStart,
|
|
1541
|
+
windowEnd
|
|
1542
|
+
]);
|
|
1120
1543
|
const gridLines = (0, react.useMemo)(() => {
|
|
1121
1544
|
const hourLines = `repeating-linear-gradient(to bottom, transparent 0, transparent ${hourHeight - 1}px, ${theme.gridLine} ${hourHeight - 1}px, ${theme.gridLine} ${hourHeight}px)`;
|
|
1122
1545
|
if (timeslots <= 1) return hourLines;
|
|
@@ -1315,6 +1738,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1315
1738
|
touchAction: zoomable ? "pan-y" : "auto"
|
|
1316
1739
|
},
|
|
1317
1740
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1741
|
+
ref: columnsRef,
|
|
1318
1742
|
style: {
|
|
1319
1743
|
display: "flex",
|
|
1320
1744
|
height: totalHeight,
|
|
@@ -1348,6 +1772,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1348
1772
|
const bands = bandsByDay[dayIndex];
|
|
1349
1773
|
const ghost = createBox?.dayIndex === dayIndex ? createBox : null;
|
|
1350
1774
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1775
|
+
"data-date": day.toISOString(),
|
|
1351
1776
|
onPointerDown: cellEnabled ? (e) => beginCreate(e, dayIndex) : void 0,
|
|
1352
1777
|
onPointerMove: cellEnabled ? moveCreate : void 0,
|
|
1353
1778
|
onPointerUp: cellEnabled ? endCreate : void 0,
|
|
@@ -1363,7 +1788,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1363
1788
|
},
|
|
1364
1789
|
themed: {
|
|
1365
1790
|
borderLeft: `1px solid ${theme.gridLine}`,
|
|
1366
|
-
...(0, _super_calendar_core.isWeekend)(day) ? { background: theme.weekendBackground } : null
|
|
1791
|
+
...highlightWeekends && (0, _super_calendar_core.isWeekend)(day) ? { background: theme.weekendBackground } : null
|
|
1367
1792
|
}
|
|
1368
1793
|
}),
|
|
1369
1794
|
children: [
|
|
@@ -1379,9 +1804,30 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1379
1804
|
pointerEvents: "none",
|
|
1380
1805
|
zIndex: 0
|
|
1381
1806
|
},
|
|
1382
|
-
themed: { background: theme.outsideHoursBackground }
|
|
1807
|
+
themed: renderBusinessHours ? void 0 : { background: theme.outsideHoursBackground }
|
|
1808
|
+
}),
|
|
1809
|
+
children: renderBusinessHours?.({
|
|
1810
|
+
date: day,
|
|
1811
|
+
start: b.start,
|
|
1812
|
+
end: b.end
|
|
1383
1813
|
})
|
|
1384
1814
|
}, b.start)),
|
|
1815
|
+
backgroundByDay[dayIndex].map((b, bandIndex) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1816
|
+
"aria-hidden": true,
|
|
1817
|
+
title: b.event.title,
|
|
1818
|
+
...slot("backgroundEvent", {
|
|
1819
|
+
base: {
|
|
1820
|
+
position: "absolute",
|
|
1821
|
+
left: 0,
|
|
1822
|
+
right: 0,
|
|
1823
|
+
top: (b.startHours - windowStart) * hourHeight,
|
|
1824
|
+
height: (b.endHours - b.startHours) * hourHeight,
|
|
1825
|
+
pointerEvents: "none",
|
|
1826
|
+
zIndex: 0
|
|
1827
|
+
},
|
|
1828
|
+
themed: { background: theme.backgroundEvent }
|
|
1829
|
+
})
|
|
1830
|
+
}, `bg-${bandIndex}`)),
|
|
1385
1831
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1386
1832
|
"aria-hidden": true,
|
|
1387
1833
|
...slot("gridLines", {
|
|
@@ -1396,7 +1842,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1396
1842
|
}),
|
|
1397
1843
|
positioned.map((pe, idx) => {
|
|
1398
1844
|
const key = `${dayIndex}:${idx}`;
|
|
1399
|
-
const active = drag?.key === key ? drag : null;
|
|
1845
|
+
const active = !paged && drag?.key === key ? drag : null;
|
|
1400
1846
|
const startHours = active ? active.startHours : pe.startHours;
|
|
1401
1847
|
const durationHours = active ? active.durationHours : pe.durationHours;
|
|
1402
1848
|
if (!active && (pe.startHours >= windowEnd || pe.startHours + pe.durationHours <= windowStart)) return null;
|
|
@@ -1414,7 +1860,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1414
1860
|
ampm,
|
|
1415
1861
|
onPress
|
|
1416
1862
|
};
|
|
1417
|
-
const draggable = !!onDragEvent;
|
|
1863
|
+
const draggable = !!onDragEvent && pe.event.draggable !== false;
|
|
1418
1864
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1419
1865
|
role: "button",
|
|
1420
1866
|
tabIndex: 0,
|
|
@@ -1438,10 +1884,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1438
1884
|
}
|
|
1439
1885
|
if (keyboardEventNavigation) onEventKeyDown(key, e);
|
|
1440
1886
|
},
|
|
1441
|
-
onPointerDown: draggable ? (e) => beginDrag(e, pe.event, key, "move", pe.startHours, pe.durationHours, dayIndex) : void 0,
|
|
1442
|
-
onPointerMove: draggable ? moveDrag : void 0,
|
|
1443
|
-
onPointerUp: draggable ? (e) => endDrag(e, day, pe.event, onPress) : void 0,
|
|
1444
|
-
onPointerCancel: draggable ? cancelDrag : void 0,
|
|
1887
|
+
onPointerDown: draggable ? (e) => beginDrag(e, pe.event, key, "move", pe.startHours, pe.durationHours, dayIndex, onPress) : void 0,
|
|
1445
1888
|
onClick: draggable ? void 0 : onPress,
|
|
1446
1889
|
...dataState({ "data-dragging": !!active }),
|
|
1447
1890
|
...slot("event", { base: {
|
|
@@ -1524,7 +1967,39 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1524
1967
|
}, day.toISOString());
|
|
1525
1968
|
})]
|
|
1526
1969
|
})
|
|
1527
|
-
})
|
|
1970
|
+
}),
|
|
1971
|
+
paged && draggedRef.current ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1972
|
+
ref: ghostRef,
|
|
1973
|
+
"aria-hidden": true,
|
|
1974
|
+
style: {
|
|
1975
|
+
position: "fixed",
|
|
1976
|
+
left: 0,
|
|
1977
|
+
top: 0,
|
|
1978
|
+
width: draggedRef.current.w,
|
|
1979
|
+
height: draggedRef.current.h,
|
|
1980
|
+
transform: `translate(${ptr.current.x - draggedRef.current.grabX}px, ${ptr.current.y - draggedRef.current.grabY}px)`,
|
|
1981
|
+
pointerEvents: "none",
|
|
1982
|
+
zIndex: 1e3,
|
|
1983
|
+
opacity: .85
|
|
1984
|
+
},
|
|
1985
|
+
children: Renderer ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Renderer, {
|
|
1986
|
+
event: draggedRef.current.event,
|
|
1987
|
+
mode,
|
|
1988
|
+
isAllDay: false,
|
|
1989
|
+
boxHeight: draggedRef.current.h,
|
|
1990
|
+
ampm,
|
|
1991
|
+
onPress: () => {}
|
|
1992
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultDomEvent, {
|
|
1993
|
+
event: draggedRef.current.event,
|
|
1994
|
+
mode,
|
|
1995
|
+
isAllDay: false,
|
|
1996
|
+
boxHeight: draggedRef.current.h,
|
|
1997
|
+
ampm,
|
|
1998
|
+
onPress: () => {},
|
|
1999
|
+
theme,
|
|
2000
|
+
boxProps: slot("eventBox")
|
|
2001
|
+
})
|
|
2002
|
+
}) : null
|
|
1528
2003
|
]
|
|
1529
2004
|
});
|
|
1530
2005
|
}
|
|
@@ -1533,11 +2008,13 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1533
2008
|
const EMPTY_EVENTS = [];
|
|
1534
2009
|
function expansionRange(mode, date, weekStartsOn, numberOfDays) {
|
|
1535
2010
|
if (mode === "month") return [(0, date_fns.startOfWeek)((0, date_fns.startOfMonth)(date), { weekStartsOn }), (0, date_fns.endOfWeek)((0, date_fns.endOfMonth)(date), { weekStartsOn })];
|
|
2011
|
+
if (mode === "year") return [(0, date_fns.startOfWeek)((0, date_fns.startOfYear)(date), { weekStartsOn }), (0, date_fns.endOfWeek)((0, date_fns.endOfYear)(date), { weekStartsOn })];
|
|
1536
2012
|
if (mode === "schedule") return [(0, date_fns.startOfDay)(date), (0, date_fns.endOfDay)((0, date_fns.addMonths)(date, 3))];
|
|
1537
2013
|
const days = (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays ?? 1);
|
|
1538
2014
|
return [(0, date_fns.startOfDay)(days[0]), (0, date_fns.endOfDay)(days[days.length - 1])];
|
|
1539
2015
|
}
|
|
1540
2016
|
function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
|
|
2017
|
+
if (mode === "year") return (0, date_fns.addYears)(date, direction);
|
|
1541
2018
|
if (mode === "month") return (0, date_fns.addMonths)(date, direction);
|
|
1542
2019
|
if (mode === "schedule") return (0, date_fns.addDays)(date, direction * 7);
|
|
1543
2020
|
return (0, date_fns.addDays)(date, direction * (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays ?? 1).length);
|
|
@@ -1553,7 +2030,7 @@ function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
|
|
|
1553
2030
|
* <Calendar mode="week" date={new Date()} events={events} />
|
|
1554
2031
|
* ```
|
|
1555
2032
|
*/
|
|
1556
|
-
function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, showNowIndicator, showAllDayEventCell, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }) {
|
|
2033
|
+
function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, hiddenDays, now, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, renderBusinessHours, showNowIndicator, showAllDayEventCell, highlightWeekends, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }) {
|
|
1557
2034
|
const displayEvents = (0, react.useMemo)(() => {
|
|
1558
2035
|
let out = events ?? EMPTY_EVENTS;
|
|
1559
2036
|
if (out.some((e) => e.recurrence)) {
|
|
@@ -1582,7 +2059,24 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
|
|
|
1582
2059
|
e.preventDefault();
|
|
1583
2060
|
};
|
|
1584
2061
|
let view;
|
|
1585
|
-
if (mode === "
|
|
2062
|
+
if (mode === "year") view = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(YearView, {
|
|
2063
|
+
date,
|
|
2064
|
+
events: displayEvents,
|
|
2065
|
+
weekStartsOn,
|
|
2066
|
+
hiddenDays,
|
|
2067
|
+
locale,
|
|
2068
|
+
theme,
|
|
2069
|
+
className,
|
|
2070
|
+
style: height != null ? {
|
|
2071
|
+
height,
|
|
2072
|
+
...style
|
|
2073
|
+
} : style,
|
|
2074
|
+
classNames,
|
|
2075
|
+
styles,
|
|
2076
|
+
onPressDay,
|
|
2077
|
+
onPressMonth
|
|
2078
|
+
});
|
|
2079
|
+
else if (mode === "schedule") view = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Agenda, {
|
|
1586
2080
|
events: displayEvents,
|
|
1587
2081
|
locale,
|
|
1588
2082
|
ampm,
|
|
@@ -1602,6 +2096,7 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
|
|
|
1602
2096
|
date,
|
|
1603
2097
|
events: displayEvents,
|
|
1604
2098
|
weekStartsOn,
|
|
2099
|
+
hiddenDays,
|
|
1605
2100
|
weekdayFormat,
|
|
1606
2101
|
locale,
|
|
1607
2102
|
theme,
|
|
@@ -1631,6 +2126,9 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
|
|
|
1631
2126
|
mode,
|
|
1632
2127
|
events: displayEvents,
|
|
1633
2128
|
weekStartsOn,
|
|
2129
|
+
hiddenDays,
|
|
2130
|
+
now,
|
|
2131
|
+
timeZone,
|
|
1634
2132
|
weekdayFormat,
|
|
1635
2133
|
numberOfDays,
|
|
1636
2134
|
locale,
|
|
@@ -1650,14 +2148,17 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
|
|
|
1650
2148
|
showWeekNumber,
|
|
1651
2149
|
weekNumberPrefix,
|
|
1652
2150
|
businessHours,
|
|
2151
|
+
renderBusinessHours,
|
|
1653
2152
|
showNowIndicator,
|
|
1654
2153
|
showAllDayEventCell,
|
|
2154
|
+
highlightWeekends,
|
|
1655
2155
|
dragStepMinutes,
|
|
1656
2156
|
onPressEvent,
|
|
1657
2157
|
onPressCell,
|
|
1658
2158
|
onCreateEvent,
|
|
1659
2159
|
onDragStart,
|
|
1660
2160
|
onDragEvent,
|
|
2161
|
+
onChangeDate,
|
|
1661
2162
|
onPressDateHeader,
|
|
1662
2163
|
renderEvent: renderTimeEvent,
|
|
1663
2164
|
eventAccessibilityLabel,
|
|
@@ -1704,7 +2205,7 @@ function MonthList({ date, pastMonths = 1, futureMonths = 12, weekdayFormat = "s
|
|
|
1704
2205
|
]);
|
|
1705
2206
|
const eventsByDay = (0, react.useMemo)(() => {
|
|
1706
2207
|
if (!events) return void 0;
|
|
1707
|
-
const map = (0, _super_calendar_core.groupEventsByDay)(events);
|
|
2208
|
+
const map = (0, _super_calendar_core.groupEventsByDay)(events.filter((event) => !(0, _super_calendar_core.isBackgroundEvent)(event)));
|
|
1708
2209
|
for (const list of map.values()) list.sort(_super_calendar_core.compareDayEvents);
|
|
1709
2210
|
return map;
|
|
1710
2211
|
}, [events]);
|
|
@@ -2092,7 +2593,17 @@ function DefaultBar({ event, height, boxProps, theme }) {
|
|
|
2092
2593
|
* />
|
|
2093
2594
|
* ```
|
|
2094
2595
|
*/
|
|
2095
|
-
function ResourceTimeline({ date, orientation = "horizontal", resources, events, resourceId = (event) => event.resourceId, startHour = 0, endHour = 24, hourWidth = 80, hourHeight = 48, rowHeight = 56, labelWidth = 140, ampm = false, theme: themeOverrides, renderEvent, onPressEvent, onDragEvent, onPressCell, onCreateEvent, businessHours, dragStepMinutes = 15, className, style, classNames, styles }) {
|
|
2596
|
+
function ResourceTimeline({ date, orientation = "horizontal", resources: allResources, resourcesPerPage, resourcePage = 0, events, resourceId = (event) => event.resourceId, startHour = 0, endHour = 24, hourWidth = 80, hourHeight = 48, rowHeight = 56, labelWidth = 140, ampm = false, theme: themeOverrides, renderEvent, onPressEvent, onDragEvent, onPressCell, onCreateEvent, businessHours, renderBusinessHours, dragStepMinutes = 15, showNowIndicator = true, now: nowProp, timeZone, className, style, classNames, styles }) {
|
|
2597
|
+
const resources = (0, react.useMemo)(() => {
|
|
2598
|
+
if (!resourcesPerPage || resourcesPerPage <= 0) return allResources;
|
|
2599
|
+
const pages = Math.max(1, Math.ceil(allResources.length / resourcesPerPage));
|
|
2600
|
+
const page = Math.min(Math.max(resourcePage, 0), pages - 1);
|
|
2601
|
+
return allResources.slice(page * resourcesPerPage, (page + 1) * resourcesPerPage);
|
|
2602
|
+
}, [
|
|
2603
|
+
allResources,
|
|
2604
|
+
resourcesPerPage,
|
|
2605
|
+
resourcePage
|
|
2606
|
+
]);
|
|
2096
2607
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
2097
2608
|
const slot = createSlots({
|
|
2098
2609
|
classNames,
|
|
@@ -2102,6 +2613,35 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2102
2613
|
const snapHours = dragStepMinutes / 60;
|
|
2103
2614
|
const vertical = orientation === "vertical";
|
|
2104
2615
|
const hourSize = vertical ? hourHeight : hourWidth;
|
|
2616
|
+
const now = (0, _super_calendar_core.useNow)(showNowIndicator, {
|
|
2617
|
+
now: nowProp,
|
|
2618
|
+
timeZone
|
|
2619
|
+
});
|
|
2620
|
+
const nowHours = now.getHours() + now.getMinutes() / 60;
|
|
2621
|
+
const showNow = showNowIndicator && (0, _super_calendar_core.isSameCalendarDay)(now, date) && nowHours >= startHour && nowHours <= endHour;
|
|
2622
|
+
const nowLine = (resourceKey) => showNow ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2623
|
+
"aria-hidden": true,
|
|
2624
|
+
...slot("nowIndicator", {
|
|
2625
|
+
base: vertical ? {
|
|
2626
|
+
position: "absolute",
|
|
2627
|
+
left: 0,
|
|
2628
|
+
right: 0,
|
|
2629
|
+
top: (nowHours - startHour) * hourSize,
|
|
2630
|
+
height: 2,
|
|
2631
|
+
pointerEvents: "none",
|
|
2632
|
+
zIndex: 2
|
|
2633
|
+
} : {
|
|
2634
|
+
position: "absolute",
|
|
2635
|
+
top: 0,
|
|
2636
|
+
bottom: 0,
|
|
2637
|
+
left: (nowHours - startHour) * hourSize,
|
|
2638
|
+
width: 2,
|
|
2639
|
+
pointerEvents: "none",
|
|
2640
|
+
zIndex: 2
|
|
2641
|
+
},
|
|
2642
|
+
themed: { background: theme.nowIndicator }
|
|
2643
|
+
})
|
|
2644
|
+
}, `now-${resourceKey}`) : null;
|
|
2105
2645
|
const [drag, setDrag] = (0, react.useState)(null);
|
|
2106
2646
|
const dragRef = (0, react.useRef)(null);
|
|
2107
2647
|
const origin = (0, react.useRef)(null);
|
|
@@ -2109,7 +2649,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2109
2649
|
dragRef.current = next;
|
|
2110
2650
|
setDrag(next);
|
|
2111
2651
|
};
|
|
2112
|
-
const beginDrag = (e, key, kind, startHours, durationHours) => {
|
|
2652
|
+
const beginDrag = (e, key, resourceId, kind, startHours, durationHours) => {
|
|
2113
2653
|
if (!onDragEvent) return;
|
|
2114
2654
|
e.stopPropagation();
|
|
2115
2655
|
try {
|
|
@@ -2117,14 +2657,17 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2117
2657
|
} catch {}
|
|
2118
2658
|
origin.current = {
|
|
2119
2659
|
x: vertical ? e.clientY : e.clientX,
|
|
2660
|
+
cross: vertical ? e.clientX : e.clientY,
|
|
2120
2661
|
startHours,
|
|
2121
2662
|
durationHours
|
|
2122
2663
|
};
|
|
2123
2664
|
applyDrag({
|
|
2124
2665
|
key,
|
|
2666
|
+
resourceId,
|
|
2125
2667
|
kind,
|
|
2126
2668
|
startHours,
|
|
2127
2669
|
durationHours,
|
|
2670
|
+
crossPx: 0,
|
|
2128
2671
|
moved: false
|
|
2129
2672
|
});
|
|
2130
2673
|
};
|
|
@@ -2135,9 +2678,11 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2135
2678
|
const snap = (v) => Math.round(v / snapHours) * snapHours;
|
|
2136
2679
|
if (d.kind === "move") {
|
|
2137
2680
|
const startHours = clamp(snap(origin.current.startHours + dHours), startHour, endHour - d.durationHours);
|
|
2681
|
+
const crossPx = (vertical ? e.clientX : e.clientY) - origin.current.cross;
|
|
2138
2682
|
applyDrag({
|
|
2139
2683
|
...d,
|
|
2140
2684
|
startHours,
|
|
2685
|
+
crossPx,
|
|
2141
2686
|
moved: true
|
|
2142
2687
|
});
|
|
2143
2688
|
} else {
|
|
@@ -2149,7 +2694,21 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2149
2694
|
});
|
|
2150
2695
|
}
|
|
2151
2696
|
};
|
|
2152
|
-
const
|
|
2697
|
+
const laneAt = (e, fallback) => {
|
|
2698
|
+
if (typeof document === "undefined" || typeof document.elementFromPoint !== "function") return fallback;
|
|
2699
|
+
const bar = e.currentTarget;
|
|
2700
|
+
const prev = bar.style.pointerEvents;
|
|
2701
|
+
let hit;
|
|
2702
|
+
bar.style.pointerEvents = "none";
|
|
2703
|
+
try {
|
|
2704
|
+
hit = document.elementFromPoint(e.clientX, e.clientY);
|
|
2705
|
+
} finally {
|
|
2706
|
+
bar.style.pointerEvents = prev;
|
|
2707
|
+
}
|
|
2708
|
+
const id = (hit?.closest?.("[data-resource-id]"))?.getAttribute("data-resource-id");
|
|
2709
|
+
return id && resources.find((r) => r.id === id) || fallback;
|
|
2710
|
+
};
|
|
2711
|
+
const endDrag = (e, event, resource, onPress) => {
|
|
2153
2712
|
const d = dragRef.current;
|
|
2154
2713
|
if (!d) return;
|
|
2155
2714
|
try {
|
|
@@ -2160,10 +2719,11 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2160
2719
|
onPress();
|
|
2161
2720
|
return;
|
|
2162
2721
|
}
|
|
2722
|
+
const target = d.kind === "move" ? laneAt(e, resource) : resource;
|
|
2163
2723
|
const base = (0, date_fns.startOfDay)(date);
|
|
2164
2724
|
const start = (0, date_fns.addMinutes)(base, Math.round(d.startHours * 60));
|
|
2165
2725
|
const end = (0, date_fns.addMinutes)(base, Math.round((d.startHours + d.durationHours) * 60));
|
|
2166
|
-
onDragEvent?.(event, start, end);
|
|
2726
|
+
onDragEvent?.(event, start, end, target);
|
|
2167
2727
|
applyDrag(null);
|
|
2168
2728
|
origin.current = null;
|
|
2169
2729
|
};
|
|
@@ -2234,6 +2794,11 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2234
2794
|
onPointerCancel: cancelCreate
|
|
2235
2795
|
} : null;
|
|
2236
2796
|
const bandsFor = (resource) => businessHours ? (0, _super_calendar_core.closedHourBands)(date, (d) => businessHours(d, resource), startHour, endHour) : [];
|
|
2797
|
+
const backgroundBandsFor = (resource) => (0, _super_calendar_core.backgroundBandsForDay)(events.filter((e) => resourceId(e) === resource.id), date).map((b) => ({
|
|
2798
|
+
...b,
|
|
2799
|
+
startHours: Math.max(b.startHours, startHour),
|
|
2800
|
+
endHours: Math.min(b.endHours, endHour)
|
|
2801
|
+
})).filter((b) => b.endHours > b.startHours);
|
|
2237
2802
|
const hours = (0, react.useMemo)(() => Array.from({ length: Math.max(0, endHour - startHour) }, (_, i) => startHour + i), [startHour, endHour]);
|
|
2238
2803
|
const trackWidth = (endHour - startHour) * hourWidth;
|
|
2239
2804
|
const byResource = (0, react.useMemo)(() => {
|
|
@@ -2249,6 +2814,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2249
2814
|
resourceId,
|
|
2250
2815
|
date
|
|
2251
2816
|
]);
|
|
2817
|
+
const dragLaneId = drag?.kind === "move" && drag.moved ? drag.resourceId : null;
|
|
2252
2818
|
if (vertical) {
|
|
2253
2819
|
const trackHeight = (endHour - startHour) * hourHeight;
|
|
2254
2820
|
const vGridLines = `repeating-linear-gradient(to bottom, transparent 0, transparent ${hourHeight - 1}px, ${theme.gridLine} ${hourHeight - 1}px, ${theme.gridLine} ${hourHeight}px)`;
|
|
@@ -2325,11 +2891,16 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2325
2891
|
...slot("row", {
|
|
2326
2892
|
base: {
|
|
2327
2893
|
flex: 1,
|
|
2328
|
-
minWidth: 0
|
|
2894
|
+
minWidth: 0,
|
|
2895
|
+
...dragLaneId === resource.id ? {
|
|
2896
|
+
position: "relative",
|
|
2897
|
+
zIndex: 5
|
|
2898
|
+
} : null
|
|
2329
2899
|
},
|
|
2330
2900
|
themed: { borderLeft: `1px solid ${theme.gridLine}` }
|
|
2331
2901
|
}),
|
|
2332
2902
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2903
|
+
"data-resource-id": resource.id,
|
|
2333
2904
|
...trackInteractionProps(resource),
|
|
2334
2905
|
...slot("track", { base: {
|
|
2335
2906
|
position: "relative",
|
|
@@ -2348,9 +2919,31 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2348
2919
|
pointerEvents: "none",
|
|
2349
2920
|
zIndex: 0
|
|
2350
2921
|
},
|
|
2351
|
-
themed: { background: theme.outsideHoursBackground }
|
|
2922
|
+
themed: renderBusinessHours ? void 0 : { background: theme.outsideHoursBackground }
|
|
2923
|
+
}),
|
|
2924
|
+
children: renderBusinessHours?.({
|
|
2925
|
+
date,
|
|
2926
|
+
start: b.start,
|
|
2927
|
+
end: b.end,
|
|
2928
|
+
resource
|
|
2352
2929
|
})
|
|
2353
2930
|
}, b.start)),
|
|
2931
|
+
backgroundBandsFor(resource).map((b, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2932
|
+
"aria-hidden": true,
|
|
2933
|
+
title: b.event.title,
|
|
2934
|
+
...slot("backgroundEvent", {
|
|
2935
|
+
base: {
|
|
2936
|
+
position: "absolute",
|
|
2937
|
+
left: 0,
|
|
2938
|
+
right: 0,
|
|
2939
|
+
top: (b.startHours - startHour) * hourHeight,
|
|
2940
|
+
height: (b.endHours - b.startHours) * hourHeight,
|
|
2941
|
+
pointerEvents: "none",
|
|
2942
|
+
zIndex: 0
|
|
2943
|
+
},
|
|
2944
|
+
themed: { background: theme.backgroundEvent }
|
|
2945
|
+
})
|
|
2946
|
+
}, `bg-${i}`)),
|
|
2354
2947
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2355
2948
|
"aria-hidden": true,
|
|
2356
2949
|
...slot("gridLines", {
|
|
@@ -2378,15 +2971,15 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2378
2971
|
height,
|
|
2379
2972
|
onPress
|
|
2380
2973
|
};
|
|
2381
|
-
const draggable = !!onDragEvent;
|
|
2974
|
+
const draggable = !!onDragEvent && pe.event.draggable !== false;
|
|
2382
2975
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
2383
2976
|
type: "button",
|
|
2384
2977
|
onClick: draggable ? void 0 : onPress,
|
|
2385
2978
|
"aria-label": pe.event.title,
|
|
2386
2979
|
...dataState({ "data-dragging": !!active }),
|
|
2387
|
-
onPointerDown: draggable ? (e) => beginDrag(e, key, "move", pe.startHours, pe.durationHours) : void 0,
|
|
2980
|
+
onPointerDown: draggable ? (e) => beginDrag(e, key, resource.id, "move", pe.startHours, pe.durationHours) : void 0,
|
|
2388
2981
|
onPointerMove: draggable ? moveDrag : void 0,
|
|
2389
|
-
onPointerUp: draggable ? (e) => endDrag(e, pe.event, onPress) : void 0,
|
|
2982
|
+
onPointerUp: draggable ? (e) => endDrag(e, pe.event, resource, onPress) : void 0,
|
|
2390
2983
|
onPointerCancel: draggable ? cancelDrag : void 0,
|
|
2391
2984
|
...slot("event", { base: {
|
|
2392
2985
|
position: "absolute",
|
|
@@ -2394,6 +2987,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2394
2987
|
height,
|
|
2395
2988
|
left: `${pe.column * lanePct}%`,
|
|
2396
2989
|
width: `${lanePct}%`,
|
|
2990
|
+
transform: active?.kind === "move" ? `translateX(${active.crossPx}px)` : void 0,
|
|
2397
2991
|
padding: 1,
|
|
2398
2992
|
border: "none",
|
|
2399
2993
|
background: "transparent",
|
|
@@ -2413,7 +3007,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2413
3007
|
"aria-hidden": true,
|
|
2414
3008
|
onPointerDown: (e) => {
|
|
2415
3009
|
e.stopPropagation();
|
|
2416
|
-
beginDrag(e, key, "resize", pe.startHours, pe.durationHours);
|
|
3010
|
+
beginDrag(e, key, resource.id, "resize", pe.startHours, pe.durationHours);
|
|
2417
3011
|
},
|
|
2418
3012
|
style: {
|
|
2419
3013
|
position: "absolute",
|
|
@@ -2427,6 +3021,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2427
3021
|
}) : null]
|
|
2428
3022
|
}, idx);
|
|
2429
3023
|
}),
|
|
3024
|
+
nowLine(resource.id),
|
|
2430
3025
|
createBox?.resourceKey === resource.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2431
3026
|
"aria-hidden": true,
|
|
2432
3027
|
...slot("createGhost", {
|
|
@@ -2500,7 +3095,11 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2500
3095
|
...slot("row", {
|
|
2501
3096
|
base: {
|
|
2502
3097
|
display: "flex",
|
|
2503
|
-
height: rowHeight
|
|
3098
|
+
height: rowHeight,
|
|
3099
|
+
...dragLaneId === resource.id ? {
|
|
3100
|
+
position: "relative",
|
|
3101
|
+
zIndex: 5
|
|
3102
|
+
} : null
|
|
2504
3103
|
},
|
|
2505
3104
|
themed: { borderBottom: `1px solid ${theme.gridLine}` }
|
|
2506
3105
|
}),
|
|
@@ -2522,6 +3121,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2522
3121
|
}),
|
|
2523
3122
|
children: resource.title ?? resource.id
|
|
2524
3123
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3124
|
+
"data-resource-id": resource.id,
|
|
2525
3125
|
...trackInteractionProps(resource),
|
|
2526
3126
|
...slot("track", { base: {
|
|
2527
3127
|
position: "relative",
|
|
@@ -2540,9 +3140,31 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2540
3140
|
pointerEvents: "none",
|
|
2541
3141
|
zIndex: 0
|
|
2542
3142
|
},
|
|
2543
|
-
themed: { background: theme.outsideHoursBackground }
|
|
3143
|
+
themed: renderBusinessHours ? void 0 : { background: theme.outsideHoursBackground }
|
|
3144
|
+
}),
|
|
3145
|
+
children: renderBusinessHours?.({
|
|
3146
|
+
date,
|
|
3147
|
+
start: b.start,
|
|
3148
|
+
end: b.end,
|
|
3149
|
+
resource
|
|
2544
3150
|
})
|
|
2545
3151
|
}, b.start)),
|
|
3152
|
+
backgroundBandsFor(resource).map((b, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3153
|
+
"aria-hidden": true,
|
|
3154
|
+
title: b.event.title,
|
|
3155
|
+
...slot("backgroundEvent", {
|
|
3156
|
+
base: {
|
|
3157
|
+
position: "absolute",
|
|
3158
|
+
top: 0,
|
|
3159
|
+
bottom: 0,
|
|
3160
|
+
left: (b.startHours - startHour) * hourWidth,
|
|
3161
|
+
width: (b.endHours - b.startHours) * hourWidth,
|
|
3162
|
+
pointerEvents: "none",
|
|
3163
|
+
zIndex: 0
|
|
3164
|
+
},
|
|
3165
|
+
themed: { background: theme.backgroundEvent }
|
|
3166
|
+
})
|
|
3167
|
+
}, `bg-${i}`)),
|
|
2546
3168
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2547
3169
|
"aria-hidden": true,
|
|
2548
3170
|
...slot("gridLines", {
|
|
@@ -2575,9 +3197,9 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2575
3197
|
onClick: draggable ? void 0 : onPress,
|
|
2576
3198
|
"aria-label": pe.event.title,
|
|
2577
3199
|
...dataState({ "data-dragging": !!active }),
|
|
2578
|
-
onPointerDown: draggable ? (e) => beginDrag(e, key, "move", pe.startHours, pe.durationHours) : void 0,
|
|
3200
|
+
onPointerDown: draggable ? (e) => beginDrag(e, key, resource.id, "move", pe.startHours, pe.durationHours) : void 0,
|
|
2579
3201
|
onPointerMove: draggable ? moveDrag : void 0,
|
|
2580
|
-
onPointerUp: draggable ? (e) => endDrag(e, pe.event, onPress) : void 0,
|
|
3202
|
+
onPointerUp: draggable ? (e) => endDrag(e, pe.event, resource, onPress) : void 0,
|
|
2581
3203
|
onPointerCancel: draggable ? cancelDrag : void 0,
|
|
2582
3204
|
...slot("event", { base: {
|
|
2583
3205
|
position: "absolute",
|
|
@@ -2585,6 +3207,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2585
3207
|
width,
|
|
2586
3208
|
top: pe.column * laneHeight,
|
|
2587
3209
|
height: laneHeight,
|
|
3210
|
+
transform: active?.kind === "move" ? `translateY(${active.crossPx}px)` : void 0,
|
|
2588
3211
|
padding: 1,
|
|
2589
3212
|
border: "none",
|
|
2590
3213
|
background: "transparent",
|
|
@@ -2604,7 +3227,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2604
3227
|
"aria-hidden": true,
|
|
2605
3228
|
onPointerDown: (e) => {
|
|
2606
3229
|
e.stopPropagation();
|
|
2607
|
-
beginDrag(e, key, "resize", pe.startHours, pe.durationHours);
|
|
3230
|
+
beginDrag(e, key, resource.id, "resize", pe.startHours, pe.durationHours);
|
|
2608
3231
|
},
|
|
2609
3232
|
style: {
|
|
2610
3233
|
position: "absolute",
|
|
@@ -2618,6 +3241,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
|
|
|
2618
3241
|
}) : null]
|
|
2619
3242
|
}, idx);
|
|
2620
3243
|
}),
|
|
3244
|
+
nowLine(resource.id),
|
|
2621
3245
|
createBox?.resourceKey === resource.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2622
3246
|
"aria-hidden": true,
|
|
2623
3247
|
...slot("createGhost", {
|
|
@@ -2654,6 +3278,13 @@ exports.MonthList = MonthList;
|
|
|
2654
3278
|
exports.MonthView = MonthView;
|
|
2655
3279
|
exports.ResourceTimeline = ResourceTimeline;
|
|
2656
3280
|
exports.TimeGrid = TimeGrid;
|
|
3281
|
+
exports.YearView = YearView;
|
|
3282
|
+
Object.defineProperty(exports, "backgroundBandsForDay", {
|
|
3283
|
+
enumerable: true,
|
|
3284
|
+
get: function() {
|
|
3285
|
+
return _super_calendar_core.backgroundBandsForDay;
|
|
3286
|
+
}
|
|
3287
|
+
});
|
|
2657
3288
|
Object.defineProperty(exports, "buildMonthGrid", {
|
|
2658
3289
|
enumerable: true,
|
|
2659
3290
|
get: function() {
|
|
@@ -2686,6 +3317,12 @@ Object.defineProperty(exports, "isAllDayEvent", {
|
|
|
2686
3317
|
return _super_calendar_core.isAllDayEvent;
|
|
2687
3318
|
}
|
|
2688
3319
|
});
|
|
3320
|
+
Object.defineProperty(exports, "isBackgroundEvent", {
|
|
3321
|
+
enumerable: true,
|
|
3322
|
+
get: function() {
|
|
3323
|
+
return _super_calendar_core.isBackgroundEvent;
|
|
3324
|
+
}
|
|
3325
|
+
});
|
|
2689
3326
|
Object.defineProperty(exports, "isDateSelectable", {
|
|
2690
3327
|
enumerable: true,
|
|
2691
3328
|
get: function() {
|
|
@@ -2735,12 +3372,24 @@ Object.defineProperty(exports, "useDateRange", {
|
|
|
2735
3372
|
return _super_calendar_core.useDateRange;
|
|
2736
3373
|
}
|
|
2737
3374
|
});
|
|
3375
|
+
Object.defineProperty(exports, "useEventSource", {
|
|
3376
|
+
enumerable: true,
|
|
3377
|
+
get: function() {
|
|
3378
|
+
return _super_calendar_core.useEventSource;
|
|
3379
|
+
}
|
|
3380
|
+
});
|
|
2738
3381
|
Object.defineProperty(exports, "useMonthGrid", {
|
|
2739
3382
|
enumerable: true,
|
|
2740
3383
|
get: function() {
|
|
2741
3384
|
return _super_calendar_core.useMonthGrid;
|
|
2742
3385
|
}
|
|
2743
3386
|
});
|
|
3387
|
+
Object.defineProperty(exports, "useNow", {
|
|
3388
|
+
enumerable: true,
|
|
3389
|
+
get: function() {
|
|
3390
|
+
return _super_calendar_core.useNow;
|
|
3391
|
+
}
|
|
3392
|
+
});
|
|
2744
3393
|
Object.defineProperty(exports, "weekdayFormatToken", {
|
|
2745
3394
|
enumerable: true,
|
|
2746
3395
|
get: function() {
|