@super-calendar/dom 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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 { bandRounding, buildMonthGrid, buildMonthGrid as buildMonthGrid$1, buildMonthWeeks, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventTimeLabel, eventsInTimeZone, expandRecurringEvents, expandRecurringEvents as expandRecurringEvents$1, formatHour, getIsToday, getViewDays, getViewDays as getViewDays$1, getWeekDays, getYearMonths, 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";
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). */
@@ -234,6 +234,183 @@ 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, 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(() => getWeekDays(date, weekStartsOn).map((d) => format(d, weekdayFormatToken$1("narrow"), { locale })), [
251
+ date,
252
+ weekStartsOn,
253
+ locale
254
+ ]);
255
+ const eventDays = useMemo(() => new Set(events && events.length > 0 ? groupEventsByDay(events).keys() : []), [events]);
256
+ return /* @__PURE__ */ jsx("div", {
257
+ className,
258
+ style: {
259
+ fontFamily: theme.fontFamily,
260
+ color: theme.text,
261
+ overflowY: "auto",
262
+ ...style
263
+ },
264
+ children: /* @__PURE__ */ jsx("div", {
265
+ ...slot("grid", { base: {
266
+ display: "grid",
267
+ gridTemplateColumns: `repeat(auto-fill, minmax(${minMonthWidth}px, 1fr))`
268
+ } }),
269
+ children: months.map((month) => {
270
+ const weeks = buildMonthWeeks(month, weekStartsOn);
271
+ const monthLabel = format(month, "MMMM yyyy", { locale });
272
+ const titleContent = format(month, "MMMM", { locale });
273
+ return /* @__PURE__ */ jsxs("div", {
274
+ ...slot("month", { base: { padding: 8 } }),
275
+ children: [
276
+ onPressMonth ? /* @__PURE__ */ jsx("button", {
277
+ type: "button",
278
+ onClick: () => onPressMonth(month),
279
+ "aria-label": monthLabel,
280
+ ...slot("monthTitle", {
281
+ base: {
282
+ display: "block",
283
+ border: "none",
284
+ background: "transparent",
285
+ padding: "0 0 4px",
286
+ cursor: "pointer",
287
+ font: "inherit",
288
+ textAlign: "left"
289
+ },
290
+ themed: {
291
+ fontSize: 13,
292
+ fontWeight: 700,
293
+ color: theme.todayBackground
294
+ }
295
+ }),
296
+ children: titleContent
297
+ }) : /* @__PURE__ */ jsx("div", {
298
+ role: "heading",
299
+ "aria-level": 3,
300
+ "aria-label": monthLabel,
301
+ ...slot("monthTitle", {
302
+ base: { paddingBottom: 4 },
303
+ themed: {
304
+ fontSize: 13,
305
+ fontWeight: 700,
306
+ color: theme.todayBackground
307
+ }
308
+ }),
309
+ children: titleContent
310
+ }),
311
+ /* @__PURE__ */ jsx("div", {
312
+ ...slot("weekdays", { base: {
313
+ display: "grid",
314
+ gridTemplateColumns: "repeat(7, 1fr)"
315
+ } }),
316
+ children: weekdayLabels.map((label, i) => /* @__PURE__ */ jsx("div", {
317
+ "aria-hidden": true,
318
+ ...slot("weekday", {
319
+ base: { textAlign: "center" },
320
+ themed: {
321
+ fontSize: 9,
322
+ fontWeight: 600,
323
+ color: theme.textMuted
324
+ }
325
+ }),
326
+ children: label
327
+ }, i))
328
+ }),
329
+ /* @__PURE__ */ jsx("div", {
330
+ role: "grid",
331
+ "aria-label": monthLabel,
332
+ children: weeks.map((week) => /* @__PURE__ */ jsx("div", {
333
+ role: "row",
334
+ ...slot("week", { base: {
335
+ display: "grid",
336
+ gridTemplateColumns: "repeat(7, 1fr)"
337
+ } }),
338
+ children: week.map((day) => {
339
+ if (day.getMonth() !== month.getMonth()) return /* @__PURE__ */ jsx("div", {
340
+ role: "gridcell",
341
+ "aria-hidden": true,
342
+ style: { aspectRatio: "1" }
343
+ }, day.toISOString());
344
+ const isHighlighted = activeDate ? isSameCalendarDay(day, activeDate) : getIsToday(day);
345
+ const hasEvents = eventDays.has(startOfDay(day).toISOString());
346
+ const label = `${format(day, "EEEE, d LLLL yyyy", { locale })}${getIsToday(day) ? ", today" : ""}${hasEvents ? ", has events" : ""}`;
347
+ const daySlot = slot("day", {
348
+ base: {
349
+ position: "relative",
350
+ aspectRatio: "1",
351
+ display: "flex",
352
+ alignItems: "center",
353
+ justifyContent: "center",
354
+ padding: 0,
355
+ border: "none",
356
+ background: "transparent",
357
+ font: "inherit",
358
+ cursor: onPressDay ? "pointer" : "default",
359
+ boxSizing: "border-box"
360
+ },
361
+ themed: {
362
+ fontSize: 11,
363
+ borderRadius: "50%",
364
+ ...isHighlighted ? {
365
+ background: theme.todayBackground,
366
+ color: theme.todayText
367
+ } : { color: theme.text }
368
+ }
369
+ });
370
+ const states = dataState({
371
+ "data-today": getIsToday(day),
372
+ "data-events": hasEvents
373
+ });
374
+ const dot = hasEvents ? /* @__PURE__ */ jsx("span", {
375
+ "aria-hidden": true,
376
+ ...slot("eventDot", {
377
+ base: {
378
+ position: "absolute",
379
+ bottom: 1,
380
+ left: "50%",
381
+ marginLeft: -1.5,
382
+ width: 3,
383
+ height: 3,
384
+ borderRadius: 2
385
+ },
386
+ themed: { background: isHighlighted ? theme.todayText : theme.todayBackground }
387
+ })
388
+ }) : null;
389
+ return onPressDay ? /* @__PURE__ */ jsxs("button", {
390
+ type: "button",
391
+ role: "gridcell",
392
+ onClick: () => onPressDay(day),
393
+ "aria-label": label,
394
+ ...states,
395
+ ...daySlot,
396
+ children: [day.getDate(), dot]
397
+ }, day.toISOString()) : /* @__PURE__ */ jsxs("div", {
398
+ role: "gridcell",
399
+ "aria-label": label,
400
+ ...states,
401
+ ...daySlot,
402
+ children: [day.getDate(), dot]
403
+ }, day.toISOString());
404
+ })
405
+ }, week[0].toISOString()))
406
+ })
407
+ ]
408
+ }, month.toISOString());
409
+ })
410
+ })
411
+ });
412
+ }
413
+ //#endregion
237
414
  //#region src/MonthView.tsx
238
415
  const DATE_ROW = 24;
239
416
  const CHIP_HEIGHT = 18;
@@ -1532,11 +1709,13 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1532
1709
  const EMPTY_EVENTS = [];
1533
1710
  function expansionRange(mode, date, weekStartsOn, numberOfDays) {
1534
1711
  if (mode === "month") return [startOfWeek(startOfMonth(date), { weekStartsOn }), endOfWeek(endOfMonth(date), { weekStartsOn })];
1712
+ if (mode === "year") return [startOfWeek(startOfYear(date), { weekStartsOn }), endOfWeek(endOfYear(date), { weekStartsOn })];
1535
1713
  if (mode === "schedule") return [startOfDay(date), endOfDay(addMonths(date, 3))];
1536
1714
  const days = getViewDays$1(mode, date, weekStartsOn, numberOfDays ?? 1);
1537
1715
  return [startOfDay(days[0]), endOfDay(days[days.length - 1])];
1538
1716
  }
1539
1717
  function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
1718
+ if (mode === "year") return addYears(date, direction);
1540
1719
  if (mode === "month") return addMonths(date, direction);
1541
1720
  if (mode === "schedule") return addDays(date, direction * 7);
1542
1721
  return addDays(date, direction * getViewDays$1(mode, date, weekStartsOn, numberOfDays ?? 1).length);
@@ -1552,7 +1731,7 @@ function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
1552
1731
  * <Calendar mode="week" date={new Date()} events={events} />
1553
1732
  * ```
1554
1733
  */
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 }) {
1734
+ 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, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }) {
1556
1735
  const displayEvents = useMemo(() => {
1557
1736
  let out = events ?? EMPTY_EVENTS;
1558
1737
  if (out.some((e) => e.recurrence)) {
@@ -1581,7 +1760,23 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
1581
1760
  e.preventDefault();
1582
1761
  };
1583
1762
  let view;
1584
- if (mode === "schedule") view = /* @__PURE__ */ jsx(Agenda, {
1763
+ if (mode === "year") view = /* @__PURE__ */ jsx(YearView, {
1764
+ date,
1765
+ events: displayEvents,
1766
+ weekStartsOn,
1767
+ locale,
1768
+ theme,
1769
+ className,
1770
+ style: height != null ? {
1771
+ height,
1772
+ ...style
1773
+ } : style,
1774
+ classNames,
1775
+ styles,
1776
+ onPressDay,
1777
+ onPressMonth
1778
+ });
1779
+ else if (mode === "schedule") view = /* @__PURE__ */ jsx(Agenda, {
1585
1780
  events: displayEvents,
1586
1781
  locale,
1587
1782
  ampm,
@@ -2091,7 +2286,7 @@ function DefaultBar({ event, height, boxProps, theme }) {
2091
2286
  * />
2092
2287
  * ```
2093
2288
  */
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, dragStepMinutes = 15, className, style, classNames, styles }) {
2289
+ 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 }) {
2095
2290
  const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
2096
2291
  const slot = createSlots({
2097
2292
  classNames,
@@ -2170,6 +2365,69 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
2170
2365
  applyDrag(null);
2171
2366
  origin.current = null;
2172
2367
  };
2368
+ const [createBox, setCreateBox] = useState(null);
2369
+ const createOrigin = useRef(null);
2370
+ const cellEnabled = !!onPressCell || !!onCreateEvent;
2371
+ const pxAlongAxis = (el, e) => {
2372
+ const rect = el.getBoundingClientRect();
2373
+ return vertical ? e.clientY - rect.top : e.clientX - rect.left;
2374
+ };
2375
+ const beginCreate = (e, resource) => {
2376
+ if (!cellEnabled || e.pointerType === "touch") return;
2377
+ if (e.target !== e.currentTarget || e.button > 0) return;
2378
+ const el = e.currentTarget;
2379
+ const startPx = pxAlongAxis(el, e);
2380
+ try {
2381
+ el.setPointerCapture?.(e.pointerId);
2382
+ } catch {}
2383
+ createOrigin.current = {
2384
+ el,
2385
+ resource,
2386
+ startPx
2387
+ };
2388
+ if (onCreateEvent) setCreateBox({
2389
+ resourceKey: resource.id,
2390
+ startPx,
2391
+ curPx: startPx
2392
+ });
2393
+ };
2394
+ const moveCreate = (e) => {
2395
+ const o = createOrigin.current;
2396
+ if (!o || !onCreateEvent) return;
2397
+ setCreateBox({
2398
+ resourceKey: o.resource.id,
2399
+ startPx: o.startPx,
2400
+ curPx: pxAlongAxis(o.el, e)
2401
+ });
2402
+ };
2403
+ const endCreate = (e) => {
2404
+ const o = createOrigin.current;
2405
+ if (!o) return;
2406
+ try {
2407
+ o.el.releasePointerCapture?.(e.pointerId);
2408
+ } catch {}
2409
+ const endPx = pxAlongAxis(o.el, e);
2410
+ if (Math.abs(endPx - o.startPx) > 4 && onCreateEvent) {
2411
+ const range = cellRangeFromDrag(date, o.startPx, endPx, hourSize, startHour, dragStepMinutes);
2412
+ if (range) onCreateEvent(range.start, range.end, o.resource);
2413
+ } else if (onPressCell) {
2414
+ const at = cellRangeFromDrag(date, o.startPx, o.startPx, hourSize, startHour, dragStepMinutes);
2415
+ if (at) onPressCell(at.start, o.resource);
2416
+ }
2417
+ createOrigin.current = null;
2418
+ setCreateBox(null);
2419
+ };
2420
+ const cancelCreate = () => {
2421
+ createOrigin.current = null;
2422
+ setCreateBox(null);
2423
+ };
2424
+ const trackInteractionProps = (resource) => cellEnabled ? {
2425
+ onPointerDown: (e) => beginCreate(e, resource),
2426
+ onPointerMove: moveCreate,
2427
+ onPointerUp: endCreate,
2428
+ onPointerCancel: cancelCreate
2429
+ } : null;
2430
+ const bandsFor = (resource) => businessHours ? closedHourBands(date, (d) => businessHours(d, resource), startHour, endHour) : [];
2173
2431
  const hours = useMemo(() => Array.from({ length: Math.max(0, endHour - startHour) }, (_, i) => startHour + i), [startHour, endHour]);
2174
2432
  const trackWidth = (endHour - startHour) * hourWidth;
2175
2433
  const byResource = useMemo(() => {
@@ -2266,85 +2524,124 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
2266
2524
  themed: { borderLeft: `1px solid ${theme.gridLine}` }
2267
2525
  }),
2268
2526
  children: /* @__PURE__ */ jsxs("div", {
2527
+ ...trackInteractionProps(resource),
2269
2528
  ...slot("track", { base: {
2270
2529
  position: "relative",
2271
2530
  height: trackHeight
2272
2531
  } }),
2273
- children: [/* @__PURE__ */ jsx("div", {
2274
- "aria-hidden": true,
2275
- ...slot("gridLines", {
2276
- base: {
2277
- position: "absolute",
2278
- inset: 0,
2279
- pointerEvents: "none"
2280
- },
2281
- themed: { backgroundImage: vGridLines }
2282
- })
2283
- }), positioned.map((pe, idx) => {
2284
- const key = `${resource.id}:${idx}`;
2285
- const active = drag?.key === key ? drag : null;
2286
- const startH = active ? active.startHours : pe.startHours;
2287
- const durH = active ? active.durationHours : pe.durationHours;
2288
- const top = clamp(startH - startHour, 0, endHour - startHour) * hourHeight;
2289
- const bottom = clamp(startH + durH - startHour, 0, endHour - startHour) * hourHeight;
2290
- const height = Math.max(bottom - top, 2);
2291
- const lanePct = 100 / pe.columns;
2292
- const onPress = () => onPressEvent?.(pe.event);
2293
- const args = {
2294
- event: pe.event,
2295
- width: 0,
2296
- height,
2297
- onPress
2298
- };
2299
- const draggable = !!onDragEvent;
2300
- return /* @__PURE__ */ jsxs("button", {
2301
- type: "button",
2302
- onClick: draggable ? void 0 : onPress,
2303
- "aria-label": pe.event.title,
2304
- ...dataState({ "data-dragging": !!active }),
2305
- onPointerDown: draggable ? (e) => beginDrag(e, key, "move", pe.startHours, pe.durationHours) : void 0,
2306
- onPointerMove: draggable ? moveDrag : void 0,
2307
- onPointerUp: draggable ? (e) => endDrag(e, pe.event, onPress) : void 0,
2308
- onPointerCancel: draggable ? cancelDrag : void 0,
2309
- ...slot("event", { base: {
2310
- position: "absolute",
2311
- top,
2312
- height,
2313
- left: `${pe.column * lanePct}%`,
2314
- width: `${lanePct}%`,
2315
- padding: 1,
2316
- border: "none",
2317
- background: "transparent",
2318
- cursor: draggable ? "grab" : "pointer",
2319
- touchAction: draggable ? "none" : "auto",
2320
- font: "inherit",
2321
- textAlign: "left",
2322
- boxSizing: "border-box",
2323
- zIndex: active ? 3 : 1,
2324
- opacity: active ? .85 : 1
2325
- } }),
2326
- children: [Renderer ? /* @__PURE__ */ jsx(Renderer, { ...args }) : /* @__PURE__ */ jsx(DefaultBar, {
2327
- ...args,
2328
- theme,
2329
- boxProps: slot("eventBox")
2330
- }), draggable ? /* @__PURE__ */ jsx("span", {
2331
- "aria-hidden": true,
2332
- onPointerDown: (e) => {
2333
- e.stopPropagation();
2334
- beginDrag(e, key, "resize", pe.startHours, pe.durationHours);
2335
- },
2336
- style: {
2532
+ children: [
2533
+ bandsFor(resource).map((b) => /* @__PURE__ */ jsx("div", {
2534
+ "aria-hidden": true,
2535
+ ...slot("businessHours", {
2536
+ base: {
2337
2537
  position: "absolute",
2338
2538
  left: 0,
2339
2539
  right: 0,
2340
- bottom: 0,
2341
- height: 8,
2342
- cursor: "ns-resize",
2343
- touchAction: "none"
2540
+ top: (b.start - startHour) * hourHeight,
2541
+ height: (b.end - b.start) * hourHeight,
2542
+ pointerEvents: "none",
2543
+ zIndex: 0
2544
+ },
2545
+ themed: { background: theme.outsideHoursBackground }
2546
+ })
2547
+ }, b.start)),
2548
+ /* @__PURE__ */ jsx("div", {
2549
+ "aria-hidden": true,
2550
+ ...slot("gridLines", {
2551
+ base: {
2552
+ position: "absolute",
2553
+ inset: 0,
2554
+ pointerEvents: "none"
2555
+ },
2556
+ themed: { backgroundImage: vGridLines }
2557
+ })
2558
+ }),
2559
+ positioned.map((pe, idx) => {
2560
+ const key = `${resource.id}:${idx}`;
2561
+ const active = drag?.key === key ? drag : null;
2562
+ const startH = active ? active.startHours : pe.startHours;
2563
+ const durH = active ? active.durationHours : pe.durationHours;
2564
+ const top = clamp(startH - startHour, 0, endHour - startHour) * hourHeight;
2565
+ const bottom = clamp(startH + durH - startHour, 0, endHour - startHour) * hourHeight;
2566
+ const height = Math.max(bottom - top, 2);
2567
+ const lanePct = 100 / pe.columns;
2568
+ const onPress = () => onPressEvent?.(pe.event);
2569
+ const args = {
2570
+ event: pe.event,
2571
+ width: 0,
2572
+ height,
2573
+ onPress
2574
+ };
2575
+ const draggable = !!onDragEvent;
2576
+ return /* @__PURE__ */ jsxs("button", {
2577
+ type: "button",
2578
+ onClick: draggable ? void 0 : onPress,
2579
+ "aria-label": pe.event.title,
2580
+ ...dataState({ "data-dragging": !!active }),
2581
+ onPointerDown: draggable ? (e) => beginDrag(e, key, "move", pe.startHours, pe.durationHours) : void 0,
2582
+ onPointerMove: draggable ? moveDrag : void 0,
2583
+ onPointerUp: draggable ? (e) => endDrag(e, pe.event, onPress) : void 0,
2584
+ onPointerCancel: draggable ? cancelDrag : void 0,
2585
+ ...slot("event", { base: {
2586
+ position: "absolute",
2587
+ top,
2588
+ height,
2589
+ left: `${pe.column * lanePct}%`,
2590
+ width: `${lanePct}%`,
2591
+ padding: 1,
2592
+ border: "none",
2593
+ background: "transparent",
2594
+ cursor: draggable ? "grab" : "pointer",
2595
+ touchAction: draggable ? "none" : "auto",
2596
+ font: "inherit",
2597
+ textAlign: "left",
2598
+ boxSizing: "border-box",
2599
+ zIndex: active ? 3 : 1,
2600
+ opacity: active ? .85 : 1
2601
+ } }),
2602
+ children: [Renderer ? /* @__PURE__ */ jsx(Renderer, { ...args }) : /* @__PURE__ */ jsx(DefaultBar, {
2603
+ ...args,
2604
+ theme,
2605
+ boxProps: slot("eventBox")
2606
+ }), draggable ? /* @__PURE__ */ jsx("span", {
2607
+ "aria-hidden": true,
2608
+ onPointerDown: (e) => {
2609
+ e.stopPropagation();
2610
+ beginDrag(e, key, "resize", pe.startHours, pe.durationHours);
2611
+ },
2612
+ style: {
2613
+ position: "absolute",
2614
+ left: 0,
2615
+ right: 0,
2616
+ bottom: 0,
2617
+ height: 8,
2618
+ cursor: "ns-resize",
2619
+ touchAction: "none"
2620
+ }
2621
+ }) : null]
2622
+ }, idx);
2623
+ }),
2624
+ createBox?.resourceKey === resource.id ? /* @__PURE__ */ jsx("div", {
2625
+ "aria-hidden": true,
2626
+ ...slot("createGhost", {
2627
+ base: {
2628
+ position: "absolute",
2629
+ left: 1,
2630
+ right: 1,
2631
+ top: Math.min(createBox.startPx, createBox.curPx),
2632
+ height: Math.max(Math.abs(createBox.curPx - createBox.startPx), 2),
2633
+ opacity: .7,
2634
+ pointerEvents: "none",
2635
+ zIndex: 2
2636
+ },
2637
+ themed: {
2638
+ background: theme.rangeBackground,
2639
+ border: `1px solid ${theme.selectedBackground}`,
2640
+ borderRadius: 6
2344
2641
  }
2345
- }) : null]
2346
- }, idx);
2347
- })]
2642
+ })
2643
+ }) : null
2644
+ ]
2348
2645
  })
2349
2646
  }, resource.id);
2350
2647
  })]
@@ -2419,84 +2716,123 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
2419
2716
  }),
2420
2717
  children: resource.title ?? resource.id
2421
2718
  }), /* @__PURE__ */ jsxs("div", {
2719
+ ...trackInteractionProps(resource),
2422
2720
  ...slot("track", { base: {
2423
2721
  position: "relative",
2424
2722
  width: trackWidth
2425
2723
  } }),
2426
- children: [/* @__PURE__ */ jsx("div", {
2427
- "aria-hidden": true,
2428
- ...slot("gridLines", {
2429
- base: {
2430
- position: "absolute",
2431
- inset: 0,
2432
- pointerEvents: "none"
2433
- },
2434
- themed: { backgroundImage: gridLines }
2435
- })
2436
- }), positioned.map((pe, idx) => {
2437
- const key = `${resource.id}:${idx}`;
2438
- const active = drag?.key === key ? drag : null;
2439
- const startH = active ? active.startHours : pe.startHours;
2440
- const durH = active ? active.durationHours : pe.durationHours;
2441
- const left = clamp(startH - startHour, 0, endHour - startHour) * hourWidth;
2442
- const right = clamp(startH + durH - startHour, 0, endHour - startHour) * hourWidth;
2443
- const width = Math.max(right - left, 2);
2444
- const laneHeight = rowHeight / pe.columns;
2445
- const onPress = () => onPressEvent?.(pe.event);
2446
- const args = {
2447
- event: pe.event,
2448
- width,
2449
- onPress
2450
- };
2451
- const draggable = !!onDragEvent;
2452
- return /* @__PURE__ */ jsxs("button", {
2453
- type: "button",
2454
- onClick: draggable ? void 0 : onPress,
2455
- "aria-label": pe.event.title,
2456
- ...dataState({ "data-dragging": !!active }),
2457
- onPointerDown: draggable ? (e) => beginDrag(e, key, "move", pe.startHours, pe.durationHours) : void 0,
2458
- onPointerMove: draggable ? moveDrag : void 0,
2459
- onPointerUp: draggable ? (e) => endDrag(e, pe.event, onPress) : void 0,
2460
- onPointerCancel: draggable ? cancelDrag : void 0,
2461
- ...slot("event", { base: {
2462
- position: "absolute",
2463
- left,
2464
- width,
2465
- top: pe.column * laneHeight,
2466
- height: laneHeight,
2467
- padding: 1,
2468
- border: "none",
2469
- background: "transparent",
2470
- cursor: draggable ? "grab" : "pointer",
2471
- touchAction: draggable ? "none" : "auto",
2472
- font: "inherit",
2473
- textAlign: "left",
2474
- boxSizing: "border-box",
2475
- zIndex: active ? 3 : 1,
2476
- opacity: active ? .85 : 1
2477
- } }),
2478
- children: [Renderer ? /* @__PURE__ */ jsx(Renderer, { ...args }) : /* @__PURE__ */ jsx(DefaultBar, {
2479
- ...args,
2480
- theme,
2481
- boxProps: slot("eventBox")
2482
- }), draggable ? /* @__PURE__ */ jsx("span", {
2483
- "aria-hidden": true,
2484
- onPointerDown: (e) => {
2485
- e.stopPropagation();
2486
- beginDrag(e, key, "resize", pe.startHours, pe.durationHours);
2487
- },
2488
- style: {
2724
+ children: [
2725
+ bandsFor(resource).map((b) => /* @__PURE__ */ jsx("div", {
2726
+ "aria-hidden": true,
2727
+ ...slot("businessHours", {
2728
+ base: {
2489
2729
  position: "absolute",
2490
2730
  top: 0,
2491
2731
  bottom: 0,
2492
- right: 0,
2493
- width: 8,
2494
- cursor: "ew-resize",
2495
- touchAction: "none"
2732
+ left: (b.start - startHour) * hourWidth,
2733
+ width: (b.end - b.start) * hourWidth,
2734
+ pointerEvents: "none",
2735
+ zIndex: 0
2736
+ },
2737
+ themed: { background: theme.outsideHoursBackground }
2738
+ })
2739
+ }, b.start)),
2740
+ /* @__PURE__ */ jsx("div", {
2741
+ "aria-hidden": true,
2742
+ ...slot("gridLines", {
2743
+ base: {
2744
+ position: "absolute",
2745
+ inset: 0,
2746
+ pointerEvents: "none"
2747
+ },
2748
+ themed: { backgroundImage: gridLines }
2749
+ })
2750
+ }),
2751
+ positioned.map((pe, idx) => {
2752
+ const key = `${resource.id}:${idx}`;
2753
+ const active = drag?.key === key ? drag : null;
2754
+ const startH = active ? active.startHours : pe.startHours;
2755
+ const durH = active ? active.durationHours : pe.durationHours;
2756
+ const left = clamp(startH - startHour, 0, endHour - startHour) * hourWidth;
2757
+ const right = clamp(startH + durH - startHour, 0, endHour - startHour) * hourWidth;
2758
+ const width = Math.max(right - left, 2);
2759
+ const laneHeight = rowHeight / pe.columns;
2760
+ const onPress = () => onPressEvent?.(pe.event);
2761
+ const args = {
2762
+ event: pe.event,
2763
+ width,
2764
+ onPress
2765
+ };
2766
+ const draggable = !!onDragEvent;
2767
+ return /* @__PURE__ */ jsxs("button", {
2768
+ type: "button",
2769
+ onClick: draggable ? void 0 : onPress,
2770
+ "aria-label": pe.event.title,
2771
+ ...dataState({ "data-dragging": !!active }),
2772
+ onPointerDown: draggable ? (e) => beginDrag(e, key, "move", pe.startHours, pe.durationHours) : void 0,
2773
+ onPointerMove: draggable ? moveDrag : void 0,
2774
+ onPointerUp: draggable ? (e) => endDrag(e, pe.event, onPress) : void 0,
2775
+ onPointerCancel: draggable ? cancelDrag : void 0,
2776
+ ...slot("event", { base: {
2777
+ position: "absolute",
2778
+ left,
2779
+ width,
2780
+ top: pe.column * laneHeight,
2781
+ height: laneHeight,
2782
+ padding: 1,
2783
+ border: "none",
2784
+ background: "transparent",
2785
+ cursor: draggable ? "grab" : "pointer",
2786
+ touchAction: draggable ? "none" : "auto",
2787
+ font: "inherit",
2788
+ textAlign: "left",
2789
+ boxSizing: "border-box",
2790
+ zIndex: active ? 3 : 1,
2791
+ opacity: active ? .85 : 1
2792
+ } }),
2793
+ children: [Renderer ? /* @__PURE__ */ jsx(Renderer, { ...args }) : /* @__PURE__ */ jsx(DefaultBar, {
2794
+ ...args,
2795
+ theme,
2796
+ boxProps: slot("eventBox")
2797
+ }), draggable ? /* @__PURE__ */ jsx("span", {
2798
+ "aria-hidden": true,
2799
+ onPointerDown: (e) => {
2800
+ e.stopPropagation();
2801
+ beginDrag(e, key, "resize", pe.startHours, pe.durationHours);
2802
+ },
2803
+ style: {
2804
+ position: "absolute",
2805
+ top: 0,
2806
+ bottom: 0,
2807
+ right: 0,
2808
+ width: 8,
2809
+ cursor: "ew-resize",
2810
+ touchAction: "none"
2811
+ }
2812
+ }) : null]
2813
+ }, idx);
2814
+ }),
2815
+ createBox?.resourceKey === resource.id ? /* @__PURE__ */ jsx("div", {
2816
+ "aria-hidden": true,
2817
+ ...slot("createGhost", {
2818
+ base: {
2819
+ position: "absolute",
2820
+ top: 1,
2821
+ bottom: 1,
2822
+ left: Math.min(createBox.startPx, createBox.curPx),
2823
+ width: Math.max(Math.abs(createBox.curPx - createBox.startPx), 2),
2824
+ opacity: .7,
2825
+ pointerEvents: "none",
2826
+ zIndex: 2
2827
+ },
2828
+ themed: {
2829
+ background: theme.rangeBackground,
2830
+ border: `1px solid ${theme.selectedBackground}`,
2831
+ borderRadius: 6
2496
2832
  }
2497
- }) : null]
2498
- }, idx);
2499
- })]
2833
+ })
2834
+ }) : null
2835
+ ]
2500
2836
  })]
2501
2837
  }, resource.id);
2502
2838
  })]
@@ -2504,4 +2840,4 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
2504
2840
  });
2505
2841
  }
2506
2842
  //#endregion
2507
- 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 };
2843
+ export { Agenda, Calendar, DatePicker, DateRangePicker, MonthList, MonthView, ResourceTimeline, TimeGrid, YearView, buildMonthGrid, darkDomTheme, daySelectionState, defaultDomTheme, expandRecurringEvents, getViewDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, mergeDomTheme, nextDateRange, parseICalendar, toICalendar, useDateRange, useMonthGrid, weekdayFormatToken };