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