@super-calendar/dom 2.14.2 → 2.16.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,9 +1,9 @@
1
1
  import { LegendList } from "@legendapp/list/react";
2
2
  import { addDays, addMonths, addYears, differenceInCalendarDays, endOfDay, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, isSameDay, isSameMonth, startOfDay, startOfMonth, startOfWeek, startOfYear } from "date-fns";
3
- import { forwardRef, useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from "react";
3
+ import { createElement, forwardRef, useCallback, useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from "react";
4
4
  import { backgroundBandsForDay, backgroundBandsForDay as backgroundBandsForDay$1, bandRounding, buildMonthGrid, buildMonthGrid as buildMonthGrid$1, buildMonthWeeks, cellRangeFromDrag, clampMoveStartMinutes, closedHourBands, compareDayEvents, darkColors, dayAccessibilityLabel, dayBadgeKind, daySelectionState, daySelectionState as daySelectionState$1, defaultCalendarLabels, 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, layoutMonthWeek, layoutMonthWeek as layoutMonthWeek$1, lightColors, monthCreateRange, monthDropBounds, movedClockSpan, nextDateRange, nextDateRange as nextDateRange$1, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveCalendarLabels, resolveDraggedBounds, shiftMinutes, 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
- //#region src/slots.ts
6
+ // src/slots.ts
7
7
  /** Join truthy class names (a dependency-free clsx-lite). */
8
8
  function cn(...parts) {
9
9
  return parts.filter(Boolean).join(" ") || void 0;
@@ -39,8 +39,7 @@ function dataState(flags) {
39
39
  for (const key in flags) if (flags[key]) out[key] = "";
40
40
  return out;
41
41
  }
42
- //#endregion
43
- //#region src/theme.ts
42
+ // src/theme.ts
44
43
  const METRICS = {
45
44
  cellHeight: 48,
46
45
  dayBadgeSize: 34,
@@ -64,8 +63,7 @@ function mergeDomTheme(overrides, base = defaultDomTheme) {
64
63
  ...overrides
65
64
  } : base;
66
65
  }
67
- //#endregion
68
- //#region src/Agenda.tsx
66
+ // src/Agenda.tsx
69
67
  function DefaultAgendaRow({ event, isAllDay, ampm = false, cardProps }) {
70
68
  const time = eventTimeLabel({
71
69
  mode: "schedule",
@@ -233,8 +231,7 @@ function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverride
233
231
  }) : null]
234
232
  });
235
233
  }
236
- //#endregion
237
- //#region src/YearView.tsx
234
+ // src/YearView.tsx
238
235
  /**
239
236
  * A year at a glance: the twelve months as compact mini grids, with today
240
237
  * highlighted and a dot under days that hold events. It's the view `Calendar`
@@ -544,8 +541,7 @@ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, labels:
544
541
  })
545
542
  });
546
543
  }
547
- //#endregion
548
- //#region src/MonthView.tsx
544
+ // src/MonthView.tsx
549
545
  const EMPTY_LAYOUT = {
550
546
  segments: [],
551
547
  laneCount: 0
@@ -843,7 +839,12 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
843
839
  const initialFocusRef = useRef(initialFocus);
844
840
  initialFocusRef.current = initialFocus;
845
841
  const monthKey = format(date, "yyyy-MM");
846
- useEffect(() => setFocusedDate(initialFocusRef.current), [monthKey]);
842
+ const focusedMonth = useRef(monthKey);
843
+ useEffect(() => {
844
+ if (monthKey === focusedMonth.current) return;
845
+ focusedMonth.current = monthKey;
846
+ setFocusedDate(initialFocusRef.current);
847
+ }, [monthKey]);
847
848
  const [hoveredKey, setHoveredKey] = useState(null);
848
849
  const gridRef = useRef(null);
849
850
  const focusKey = format(focusedDate, "yyyy-MM-dd");
@@ -1055,6 +1056,9 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1055
1056
  return /* @__PURE__ */ jsxs("div", {
1056
1057
  role: "gridcell",
1057
1058
  "data-day": day.id,
1059
+ onFocus: (event) => {
1060
+ if (event.target === event.currentTarget) setFocusedDate(day.date);
1061
+ },
1058
1062
  ...dayData,
1059
1063
  tabIndex: keyboardDayNavigation ? day.id === focusKey ? 0 : -1 : void 0,
1060
1064
  "aria-disabled": day.isDisabled || void 0,
@@ -1265,11 +1269,14 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1265
1269
  type: "button",
1266
1270
  role: "gridcell",
1267
1271
  "data-day": day.id,
1272
+ onFocus: (event) => {
1273
+ if (event.target === event.currentTarget) setFocusedDate(day.date);
1274
+ },
1268
1275
  ...dayData,
1269
1276
  tabIndex: day.id === focusKey ? 0 : -1,
1270
1277
  "aria-disabled": day.isDisabled || void 0,
1271
1278
  "aria-label": label,
1272
- "aria-pressed": day.isSelected || day.isInRange,
1279
+ "aria-selected": day.isSelected || day.isInRange,
1273
1280
  ...slot("day", dayCellDefault(day, theme, highlightWeekends)),
1274
1281
  onClick: day.isDisabled ? void 0 : () => {
1275
1282
  onPressDay?.(day.date);
@@ -1294,8 +1301,373 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1294
1301
  ]
1295
1302
  });
1296
1303
  }
1297
- //#endregion
1298
- //#region src/touch.ts
1304
+ // src/EventActions.tsx
1305
+ function moveFocus(event, container) {
1306
+ const buttons = [...container?.querySelectorAll("button") ?? []];
1307
+ const index = buttons.indexOf(document.activeElement);
1308
+ const target = event.key === "ArrowDown" ? buttons[(index + 1) % buttons.length] : event.key === "ArrowUp" ? buttons[index < 0 ? buttons.length - 1 : (index - 1 + buttons.length) % buttons.length] : event.key === "Home" ? buttons[0] : event.key === "End" ? buttons[buttons.length - 1] : void 0;
1309
+ if (!target) return;
1310
+ event.preventDefault();
1311
+ target.focus();
1312
+ }
1313
+ function describeEventDates(event) {
1314
+ const start = format(event.start, "yyyy-MM-dd");
1315
+ const end = format(event.end, "yyyy-MM-dd");
1316
+ return start === end ? start : `${start} - ${end}`;
1317
+ }
1318
+ /**
1319
+ * Open/close state for one component's actions dialog. `commit` applies an
1320
+ * action through the component's drag path and returns a matcher for the event
1321
+ * the consumer will render in its place, or null when the change was refused.
1322
+ * The dialog follows that replacement so repeated steps keep working, and
1323
+ * closes when its event disappears or can no longer be edited.
1324
+ */
1325
+ function useEventActions(events, actionsFor, commit, getEventId) {
1326
+ const [openEvent, setOpenEvent] = useState(null);
1327
+ const [rejections, setRejections] = useState(0);
1328
+ const identity = useRef(null);
1329
+ const openRef = useRef(null);
1330
+ const show = (event) => {
1331
+ openRef.current = event;
1332
+ setOpenEvent(event);
1333
+ };
1334
+ const triggers = useRef(/* @__PURE__ */ new WeakMap());
1335
+ const dialogRef = useRef(null);
1336
+ const rootRef = useRef(null);
1337
+ const pending = useRef(null);
1338
+ const current = () => {
1339
+ const event = openRef.current;
1340
+ if (!event) return void 0;
1341
+ if (identity.current) {
1342
+ if (!getEventId) return void 0;
1343
+ const id = identity.current.id;
1344
+ const matches = events.filter((candidate) => getEventId(candidate) === id);
1345
+ return matches.length === 1 ? matches[0] : void 0;
1346
+ }
1347
+ if (getEventId) return void 0;
1348
+ if (events.includes(event)) return event;
1349
+ const committed = pending.current;
1350
+ if (committed?.from !== event) return void 0;
1351
+ if (committed.events.some((previous) => previous !== event && !events.includes(previous))) return void 0;
1352
+ const replacements = events.filter((candidate) => !committed.events.includes(candidate) && committed.matches(candidate));
1353
+ return replacements.length === 1 ? replacements[0] : void 0;
1354
+ };
1355
+ const close = (restoreFocus, fallbackToRoot = false) => {
1356
+ const event = openRef.current;
1357
+ if (!event) return;
1358
+ const shown = current() ?? event;
1359
+ pending.current = null;
1360
+ const dialog = dialogRef.current;
1361
+ if (dialog?.open) {
1362
+ if (typeof dialog.close === "function") dialog.close();
1363
+ else dialog.removeAttribute("open");
1364
+ }
1365
+ if (restoreFocus) {
1366
+ const trigger = triggers.current.get(shown);
1367
+ (fallbackToRoot ? rootRef.current : trigger?.isConnected ? trigger : [...rootRef.current?.querySelectorAll("button:not(:disabled), [tabindex=\"0\"]") ?? []].find((element) => !dialog?.contains(element)) ?? rootRef.current)?.focus();
1368
+ }
1369
+ show(null);
1370
+ };
1371
+ useEffect(() => {
1372
+ if (!openRef.current) return;
1373
+ const next = current();
1374
+ if (pending.current && pending.current.events !== events) pending.current = null;
1375
+ if (next && actionsFor(next).length > 0) {
1376
+ if (next !== openEvent) show(next);
1377
+ return;
1378
+ }
1379
+ close(document.activeElement === document.body || !!dialogRef.current?.contains(document.activeElement), true);
1380
+ });
1381
+ const run = (actionId) => {
1382
+ const event = current();
1383
+ if (!event) return;
1384
+ openRef.current = event;
1385
+ pending.current = null;
1386
+ const matches = commit(event, actionId);
1387
+ setRejections((count) => matches ? 0 : count + 1);
1388
+ if (matches) pending.current = {
1389
+ from: event,
1390
+ events,
1391
+ matches
1392
+ };
1393
+ };
1394
+ const select = (event, trigger) => {
1395
+ const id = getEventId?.(event);
1396
+ identity.current = typeof id === "string" || typeof id === "number" ? { id } : null;
1397
+ setRejections(0);
1398
+ triggers.current.set(event, trigger);
1399
+ show(event);
1400
+ };
1401
+ return {
1402
+ openEvent,
1403
+ close,
1404
+ run,
1405
+ select,
1406
+ dialogRef,
1407
+ rootRef,
1408
+ rejections
1409
+ };
1410
+ }
1411
+ function EventActionsMenu({ events, label, labelFor, descriptionFor, onSelect, rootRef, slot, theme }) {
1412
+ const [expanded, setExpanded] = useState(false);
1413
+ const trigger = useRef(null);
1414
+ const listRef = useRef(null);
1415
+ useEffect(() => {
1416
+ if (expanded) listRef.current?.querySelector("button")?.focus();
1417
+ }, [expanded]);
1418
+ const id = useId();
1419
+ const focused = useRef(null);
1420
+ const keys = useRef(/* @__PURE__ */ new WeakMap());
1421
+ const nextKey = useRef(0);
1422
+ const keyFor = (event) => {
1423
+ let key = keys.current.get(event);
1424
+ if (key === void 0) {
1425
+ key = nextKey.current++;
1426
+ keys.current.set(event, key);
1427
+ }
1428
+ return key;
1429
+ };
1430
+ useEffect(() => {
1431
+ const previous = focused.current;
1432
+ if (!previous || document.activeElement !== document.body) return;
1433
+ (previous.isConnected ? previous : trigger.current ?? rootRef.current)?.focus();
1434
+ });
1435
+ if (!events.length) return null;
1436
+ return /* @__PURE__ */ jsxs("div", {
1437
+ onFocusCapture: (e) => {
1438
+ focused.current = e.target;
1439
+ },
1440
+ onBlurCapture: (e) => {
1441
+ if (e.relatedTarget && !e.currentTarget.contains(e.relatedTarget)) focused.current = null;
1442
+ },
1443
+ onKeyDown: (e) => {
1444
+ if (!expanded) return;
1445
+ if (e.key !== "Escape") {
1446
+ moveFocus(e, listRef.current);
1447
+ return;
1448
+ }
1449
+ e.preventDefault();
1450
+ e.stopPropagation();
1451
+ setExpanded(false);
1452
+ trigger.current?.focus();
1453
+ },
1454
+ children: [/* @__PURE__ */ jsx("button", {
1455
+ ref: trigger,
1456
+ id,
1457
+ type: "button",
1458
+ "aria-expanded": expanded,
1459
+ "aria-controls": expanded ? id + "-list" : void 0,
1460
+ onClick: () => setExpanded(!expanded),
1461
+ ...slot("eventActionsTrigger", {
1462
+ base: {
1463
+ minHeight: 32,
1464
+ font: "inherit",
1465
+ cursor: "pointer"
1466
+ },
1467
+ themed: {
1468
+ margin: "4px 0",
1469
+ padding: "4px 10px",
1470
+ border: `1px solid ${theme.gridLine}`,
1471
+ borderRadius: 6,
1472
+ background: theme.surface,
1473
+ color: theme.text
1474
+ }
1475
+ }),
1476
+ children: label
1477
+ }), expanded ? /* @__PURE__ */ jsx("div", {
1478
+ ref: listRef,
1479
+ id: id + "-list",
1480
+ role: "group",
1481
+ "aria-labelledby": id,
1482
+ ...slot("eventActionsList", {
1483
+ base: {
1484
+ display: "flex",
1485
+ flexDirection: "column",
1486
+ gap: 4,
1487
+ maxHeight: "min(20rem, 50vh)",
1488
+ overflowY: "auto"
1489
+ },
1490
+ themed: {
1491
+ padding: 4,
1492
+ background: theme.surface,
1493
+ border: `1px solid ${theme.gridLine}`,
1494
+ borderRadius: 6
1495
+ }
1496
+ }),
1497
+ children: events.map((event, index) => /* @__PURE__ */ jsxs("button", {
1498
+ type: "button",
1499
+ "aria-haspopup": "dialog",
1500
+ "aria-label": labelFor(event),
1501
+ "aria-describedby": id + "-" + index,
1502
+ onClick: () => {
1503
+ setExpanded(false);
1504
+ focused.current = null;
1505
+ onSelect(event, trigger.current);
1506
+ },
1507
+ ...slot("eventAction", {
1508
+ base: {
1509
+ minHeight: 32,
1510
+ flexShrink: 0,
1511
+ overflowWrap: "anywhere",
1512
+ font: "inherit",
1513
+ cursor: "pointer",
1514
+ textAlign: "left"
1515
+ },
1516
+ themed: {
1517
+ padding: "6px 10px",
1518
+ border: `1px solid ${theme.gridLine}`,
1519
+ borderRadius: 6,
1520
+ background: theme.surface,
1521
+ color: theme.text
1522
+ }
1523
+ }),
1524
+ children: [/* @__PURE__ */ jsx("span", { children: labelFor(event) }), /* @__PURE__ */ jsx("small", {
1525
+ id: id + "-" + index,
1526
+ style: { display: "block" },
1527
+ children: descriptionFor(event)
1528
+ })]
1529
+ }, keyFor(event)))
1530
+ }) : null]
1531
+ });
1532
+ }
1533
+ /** The modal dialog listing an event's move and resize actions. */
1534
+ function EventActionsDialog({ dialogRef, title, description, actions, closeLabel, rejectedLabel, rejections, onAction, onClose, slot, theme }) {
1535
+ const titleId = useId();
1536
+ const descriptionId = useId();
1537
+ useEffect(() => {
1538
+ const dialog = dialogRef.current;
1539
+ if (!dialog || dialog.open) return;
1540
+ if (typeof dialog.showModal === "function") dialog.showModal();
1541
+ else dialog.setAttribute("open", "");
1542
+ }, [dialogRef]);
1543
+ useEffect(() => {
1544
+ const dialog = dialogRef.current;
1545
+ if (dialog && !dialog.contains(document.activeElement)) dialog.querySelector("button")?.focus();
1546
+ });
1547
+ const buttonSlot = (available) => slot("eventAction", {
1548
+ base: {
1549
+ display: "block",
1550
+ width: "100%",
1551
+ minHeight: 32,
1552
+ boxSizing: "border-box",
1553
+ textAlign: "left",
1554
+ font: "inherit",
1555
+ cursor: available ? "pointer" : "default"
1556
+ },
1557
+ themed: {
1558
+ padding: "6px 10px",
1559
+ border: `1px solid ${theme.gridLine}`,
1560
+ borderRadius: 8,
1561
+ background: theme.surface,
1562
+ color: theme.text,
1563
+ fontSize: 13,
1564
+ opacity: available ? 1 : .5
1565
+ }
1566
+ });
1567
+ return /* @__PURE__ */ jsx("dialog", {
1568
+ ref: dialogRef,
1569
+ "aria-labelledby": titleId,
1570
+ "aria-describedby": descriptionId,
1571
+ onClose: () => onClose(),
1572
+ onCancel: (e) => {
1573
+ e.preventDefault();
1574
+ onClose();
1575
+ },
1576
+ onClick: (e) => {
1577
+ if (e.target === e.currentTarget) onClose();
1578
+ },
1579
+ onKeyDown: (e) => {
1580
+ if (e.key === "PageUp" || e.key === "PageDown") e.stopPropagation();
1581
+ if (e.key === "Escape") {
1582
+ e.preventDefault();
1583
+ e.stopPropagation();
1584
+ onClose();
1585
+ return;
1586
+ }
1587
+ moveFocus(e, e.currentTarget);
1588
+ },
1589
+ ...slot("eventActions", {
1590
+ base: {
1591
+ margin: "auto",
1592
+ overflowWrap: "anywhere",
1593
+ padding: 0,
1594
+ width: "max-content",
1595
+ maxWidth: "min(22rem, calc(100vw - 32px))",
1596
+ maxHeight: "calc(100vh - 32px)",
1597
+ overflowY: "auto",
1598
+ boxSizing: "border-box"
1599
+ },
1600
+ themed: {
1601
+ fontFamily: theme.fontFamily,
1602
+ background: theme.surface,
1603
+ color: theme.text,
1604
+ border: `1px solid ${theme.gridLine}`,
1605
+ borderRadius: 12,
1606
+ boxShadow: "0 8px 24px rgba(0,0,0,0.18)"
1607
+ }
1608
+ }),
1609
+ children: /* @__PURE__ */ jsxs("div", {
1610
+ style: {
1611
+ display: "flex",
1612
+ flexDirection: "column",
1613
+ gap: 6,
1614
+ padding: 12
1615
+ },
1616
+ children: [
1617
+ /* @__PURE__ */ jsx("p", {
1618
+ id: titleId,
1619
+ style: {
1620
+ margin: 0,
1621
+ fontWeight: 600,
1622
+ fontSize: 14
1623
+ },
1624
+ children: title
1625
+ }),
1626
+ /* @__PURE__ */ jsx("p", {
1627
+ id: descriptionId,
1628
+ "aria-live": "polite",
1629
+ style: {
1630
+ margin: "0 0 4px",
1631
+ fontSize: 12,
1632
+ color: theme.textMuted
1633
+ },
1634
+ children: description
1635
+ }),
1636
+ actions.map((action) => /* @__PURE__ */ jsx("button", {
1637
+ type: "button",
1638
+ "data-action": action.id,
1639
+ "aria-disabled": action.available ? void 0 : true,
1640
+ onClick: () => {
1641
+ if (action.available) onAction(action.id);
1642
+ },
1643
+ ...buttonSlot(action.available),
1644
+ children: action.label
1645
+ }, action.id)),
1646
+ /* @__PURE__ */ jsx("div", {
1647
+ role: "status",
1648
+ "aria-atomic": "true",
1649
+ style: { fontSize: 13 },
1650
+ children: rejections > 0 ? /* @__PURE__ */ jsx("span", { children: rejectedLabel }, rejections) : null
1651
+ }),
1652
+ /* @__PURE__ */ jsx("button", {
1653
+ type: "button",
1654
+ "data-action": "close",
1655
+ onClick: () => onClose(),
1656
+ ...buttonSlot(true),
1657
+ children: closeLabel
1658
+ })
1659
+ ]
1660
+ })
1661
+ });
1662
+ }
1663
+ // src/InertDiv.ts
1664
+ function InertDiv(props) {
1665
+ return createElement("div", {
1666
+ ...props,
1667
+ inert: props.inert ? "inert" : void 0
1668
+ });
1669
+ }
1670
+ // src/touch.ts
1299
1671
  function waitForHold(grab, delay, threshold, onHold, onTap, onCancel) {
1300
1672
  const detach = () => {
1301
1673
  clearTimeout(timer);
@@ -1333,13 +1705,26 @@ function waitForHold(grab, delay, threshold, onHold, onTap, onCancel) {
1333
1705
  document.addEventListener("pointerdown", anotherPointer);
1334
1706
  return cancel;
1335
1707
  }
1336
- //#endregion
1337
- //#region src/TimeGrid.tsx
1708
+ // src/TimeGrid.tsx
1338
1709
  const GUTTER_WIDTH$1 = 56;
1339
1710
  const HOURS_PER_DAY = 24;
1340
1711
  const DEFAULT_MIN_EVENT_HEIGHT = 14;
1341
1712
  const DEFAULT_EVENT_GAP = 1;
1342
1713
  const clamp$1 = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
1714
+ const CREATE_PREVIEW_MIN_HEIGHT = 2;
1715
+ function createPreviewPlacement(topPx, heightPx, gridHeight) {
1716
+ const start = clamp$1(topPx, 0, gridHeight);
1717
+ const end = clamp$1(topPx + heightPx, 0, gridHeight);
1718
+ const height = Math.min(gridHeight, Math.max(end - start, CREATE_PREVIEW_MIN_HEIGHT));
1719
+ const top = Math.min(start, gridHeight - height);
1720
+ return top + height / 2 > gridHeight / 2 ? {
1721
+ bottom: gridHeight - top - height,
1722
+ height
1723
+ } : {
1724
+ top,
1725
+ height
1726
+ };
1727
+ }
1343
1728
  const EDGE_ZONE = 32;
1344
1729
  const EDGE_DWELL_MS = 600;
1345
1730
  const EDGE_REPEAT_MS = 600;
@@ -1442,7 +1827,7 @@ function DefaultDomEvent({ event, mode, isAllDay, boxHeight, ampm = false, theme
1442
1827
  * ```
1443
1828
  */
1444
1829
  const TimeGrid = forwardRef(TimeGridInner);
1445
- function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, weekStartsOn = 0, weekdayFormat = "short", hourHeight: initialHourHeight = 48, scrollOffsetMinutes = 480, zoomable = true, minHourHeight = 24, maxHourHeight = 160, minEventHeight = DEFAULT_MIN_EVENT_HEIGHT, eventGap = DEFAULT_EVENT_GAP, dragStepMinutes = 15, touchDragDelay = 300, touchDragThreshold = 8, ampm = false, timeslots = 1, minHour = 0, maxHour = 24, hideHours = false, showWeekNumber = false, weekNumberPrefix = "W", hiddenDays, keyboardEventNavigation = false, businessHours, renderBusinessHours, renderBackgroundEvent, showNowIndicator = true, highlightWeekends = true, eventStartEditable = true, eventDurationEditable = true, eventOverlap = true, now: nowProp, timeZone, showAllDayEventCell = true, showAllDayLabel = false, labels: labelsProp, locale, theme: themeOverrides, height = 600, renderEvent, eventAccessibilityLabel: eventAccessibilityLabel$1, hourComponent, onPressEvent, onPressDateHeader, onPressCell, onCreateEvent, onDragStart, onDragEvent, onChangeDate, className, style, classNames, styles }, ref) {
1830
+ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, weekStartsOn = 0, weekdayFormat = "short", hourHeight: initialHourHeight = 48, scrollOffsetMinutes = 480, zoomable = true, minHourHeight = 24, maxHourHeight = 160, minEventHeight = DEFAULT_MIN_EVENT_HEIGHT, eventGap = DEFAULT_EVENT_GAP, dragStepMinutes = 15, touchDragDelay = 300, touchDragThreshold = 8, ampm = false, timeslots = 1, minHour = 0, maxHour = 24, hideHours = false, showWeekNumber = false, weekNumberPrefix = "W", hiddenDays, keyboardEventNavigation = false, businessHours, renderBusinessHours, renderBackgroundEvent, showNowIndicator = true, highlightWeekends = true, eventStartEditable = true, eventDurationEditable = true, eventOverlap = true, now: nowProp, timeZone, showAllDayEventCell = true, showAllDayLabel = false, labels: labelsProp, locale, theme: themeOverrides, height = 600, renderEvent, eventAccessibilityLabel: eventAccessibilityLabel$1, hourComponent, onPressEvent, onPressDateHeader, onPressCell, onCreateEvent, renderCreateGhost, onDragStart, onDragEvent, getEventId, onChangeDate, className, style, classNames, styles }, ref) {
1446
1831
  const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
1447
1832
  const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
1448
1833
  const slot = createSlots({
@@ -1458,6 +1843,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
1458
1843
  const windowHours = windowEnd - windowStart;
1459
1844
  const gutterWidth = hideHours ? 0 : GUTTER_WIDTH$1;
1460
1845
  const RenderBackground = renderBackgroundEvent;
1846
+ const RenderCreateGhost = renderCreateGhost;
1461
1847
  const visibleHours = useMemo(() => Array.from({ length: windowHours }, (_, i) => windowStart + i), [windowStart, windowHours]);
1462
1848
  const now = useNow$1(showNowIndicator, {
1463
1849
  now: nowProp,
@@ -1476,6 +1862,21 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
1476
1862
  };
1477
1863
  const [createBox, setCreateBox] = useState(null);
1478
1864
  const createOrigin = useRef(null);
1865
+ const createActive = createBox !== null;
1866
+ useEffect(() => {
1867
+ if (!createActive) return;
1868
+ const onScroll = () => {
1869
+ const origin = createOrigin.current;
1870
+ if (!origin) return;
1871
+ const curPx = origin.clientY - origin.el.getBoundingClientRect().top;
1872
+ setCreateBox((current) => current && current.curPx !== curPx ? {
1873
+ ...current,
1874
+ curPx
1875
+ } : current);
1876
+ };
1877
+ window.addEventListener("scroll", onScroll, true);
1878
+ return () => window.removeEventListener("scroll", onScroll, true);
1879
+ }, [createActive]);
1479
1880
  const cellTouchRef = useRef(null);
1480
1881
  const cellEnabled = !!onPressCell || !!onCreateEvent;
1481
1882
  const days = useMemo(() => getViewDays$1(mode, date, weekStartsOn, numberOfDays, false, void 0, hiddenDays), [
@@ -1520,6 +1921,62 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
1520
1921
  onChangeDateRef.current = onChangeDate;
1521
1922
  const onDragEventRef = useRef(onDragEvent);
1522
1923
  onDragEventRef.current = onDragEvent && eventOverlap === false ? (event, start, end) => overlapsOtherEvents(events, event, start, end) ? false : onDragEvent(event, start, end) : onDragEvent;
1924
+ const editability = (event) => {
1925
+ const editable = !!onDragEvent && event.draggable !== false;
1926
+ return {
1927
+ canMove: editable && (event.startEditable ?? eventStartEditable),
1928
+ canResize: editable && (event.durationEditable ?? eventDurationEditable)
1929
+ };
1930
+ };
1931
+ const eventLabel = (event) => eventAccessibilityLabel$1 ? eventAccessibilityLabel$1(event, {
1932
+ mode,
1933
+ isAllDay: false,
1934
+ ampm
1935
+ }) : eventAccessibilityLabel({
1936
+ title: event.title,
1937
+ isAllDay: false,
1938
+ start: event.start,
1939
+ end: event.end,
1940
+ ampm,
1941
+ labels
1942
+ });
1943
+ const eventDescription = (event) => `${describeEventDates(event)}, ${eventLabel(event)}`;
1944
+ const pageDays = pageStepDays(mode, date, weekStartsOn, numberOfDays);
1945
+ const actionDelta = (id) => {
1946
+ const page = pageDays * HOURS_PER_DAY * 60;
1947
+ switch (id) {
1948
+ case "move-later": return [snapMinutes, snapMinutes];
1949
+ case "move-earlier": return [-snapMinutes, -snapMinutes];
1950
+ case "extend": return [0, snapMinutes];
1951
+ case "shorten": return [0, -snapMinutes];
1952
+ case "move-next-page": return [page, page];
1953
+ case "move-previous-page": return [-page, -page];
1954
+ default: return null;
1955
+ }
1956
+ };
1957
+ const editActions = (event) => {
1958
+ if (isAllDayEvent$1(event) || isBackgroundEvent$1(event)) return [];
1959
+ const { canMove, canResize } = editability(event);
1960
+ const action = (id, label) => {
1961
+ const [startDelta, endDelta] = actionDelta(id) ?? [0, 0];
1962
+ return {
1963
+ id,
1964
+ label,
1965
+ available: resolveDraggedBounds(event.start, event.end, startDelta, endDelta, snapMinutes) !== null
1966
+ };
1967
+ };
1968
+ return [
1969
+ ...canMove ? [action("move-later", labels.moveLater(snapMinutes)), action("move-earlier", labels.moveEarlier(snapMinutes))] : [],
1970
+ ...canResize ? [action("extend", labels.extend(snapMinutes)), action("shorten", labels.shorten(snapMinutes))] : [],
1971
+ ...canMove ? [action("move-next-page", labels.moveToNextPage(pageDays, mode)), action("move-previous-page", labels.moveToPreviousPage(pageDays, mode))] : []
1972
+ ];
1973
+ };
1974
+ const eventActions = useEventActions(events, editActions, (event, id) => {
1975
+ const delta = actionDelta(id);
1976
+ const next = delta && resolveDraggedBounds(event.start, event.end, delta[0], delta[1], snapMinutes);
1977
+ if (!next || onDragEventRef.current?.(event, next.start, next.end) === false) return null;
1978
+ return (candidate) => candidate !== event && candidate.start.getTime() === next.start.getTime() && candidate.end.getTime() === next.end.getTime() && candidate.title === event.title;
1979
+ }, getEventId);
1523
1980
  const allDayByDay = useMemo(() => days.map((day) => {
1524
1981
  const dayStart = startOfDay(day);
1525
1982
  const dayEnd = addDays(dayStart, 1);
@@ -1876,15 +2333,21 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
1876
2333
  try {
1877
2334
  el.setPointerCapture?.(e.pointerId);
1878
2335
  } catch {}
2336
+ const dayTime = days[dayIndex].getTime();
1879
2337
  createOrigin.current = {
2338
+ pointerId: e.pointerId,
2339
+ clientY: e.clientY,
1880
2340
  el,
1881
2341
  dayIndex,
2342
+ dayTime,
2343
+ creating: !!onCreateEvent,
1882
2344
  startPx
1883
2345
  };
1884
2346
  setCreateBox({
1885
2347
  dayIndex,
1886
- topPx: startPx,
1887
- heightPx: 0
2348
+ dayTime,
2349
+ startPx,
2350
+ curPx: startPx
1888
2351
  });
1889
2352
  };
1890
2353
  const moveCreate = (e) => {
@@ -1892,11 +2355,12 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
1892
2355
  if (touch && e.pointerId === touch.pointerId && Math.hypot(e.clientX - touch.x, e.clientY - touch.y) > CELL_TOUCH_SLOP_PX) cellTouchRef.current = null;
1893
2356
  const o = createOrigin.current;
1894
2357
  if (!o) return;
1895
- const cur = pxFromTop(o.el, e.clientY);
2358
+ o.clientY = e.clientY;
1896
2359
  setCreateBox({
1897
2360
  dayIndex: o.dayIndex,
1898
- topPx: Math.min(o.startPx, cur),
1899
- heightPx: Math.abs(cur - o.startPx)
2361
+ dayTime: o.dayTime,
2362
+ startPx: o.startPx,
2363
+ curPx: pxFromTop(o.el, e.clientY)
1900
2364
  });
1901
2365
  };
1902
2366
  const endCreate = (e) => {
@@ -1928,11 +2392,43 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
1928
2392
  const at = cellRangeFromDrag(day, px, px, hourHeightRef.current, windowStart, snapMinutes);
1929
2393
  if (at) onPressCell(at.start);
1930
2394
  };
1931
- const cancelCreate = () => {
1932
- cellTouchRef.current = null;
2395
+ const clearCreate = useCallback(() => {
2396
+ const previous = createOrigin.current;
1933
2397
  createOrigin.current = null;
1934
2398
  setCreateBox(null);
2399
+ try {
2400
+ previous?.el.releasePointerCapture?.(previous.pointerId);
2401
+ } catch {}
2402
+ }, []);
2403
+ const cancelCreate = () => {
2404
+ cellTouchRef.current = null;
2405
+ clearCreate();
2406
+ };
2407
+ const loseCreateCapture = (e) => {
2408
+ if (createOrigin.current?.pointerId !== e.pointerId) return;
2409
+ clearCreate();
1935
2410
  };
2411
+ useEffect(() => {
2412
+ const onKeyDown = (event) => {
2413
+ if (event.key !== "Escape" || !createOrigin.current) return;
2414
+ event.preventDefault();
2415
+ event.stopPropagation();
2416
+ clearCreate();
2417
+ };
2418
+ document.addEventListener("keydown", onKeyDown);
2419
+ return () => document.removeEventListener("keydown", onKeyDown);
2420
+ }, [clearCreate]);
2421
+ const liveRange = createBox && RenderCreateGhost && onCreateEvent && days[createBox.dayIndex]?.getTime() === createBox.dayTime ? cellRangeFromDrag(days[createBox.dayIndex], createBox.startPx, createBox.curPx, hourHeight, windowStart, snapMinutes) : null;
2422
+ const liveStart = liveRange?.start.getTime();
2423
+ const liveEnd = liveRange?.end.getTime();
2424
+ const createRange = useMemo(() => liveStart === void 0 || liveEnd === void 0 ? null : {
2425
+ start: new Date(liveStart),
2426
+ end: new Date(liveEnd)
2427
+ }, [liveStart, liveEnd]);
2428
+ useEffect(() => {
2429
+ const origin = createOrigin.current;
2430
+ if (origin && (!origin.el.isConnected || !cellEnabled || origin.creating && !onCreateEvent || days[origin.dayIndex]?.getTime() !== origin.dayTime)) clearCreate();
2431
+ });
1936
2432
  const positionedByDay = useMemo(() => days.map((day) => layoutDayEvents$1(events, day)), [days, events]);
1937
2433
  const moveOrigin = dragOrigin.current;
1938
2434
  const heldEvent = draggedRef.current?.event;
@@ -2059,7 +2555,10 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2059
2555
  timeslots,
2060
2556
  theme.gridLine
2061
2557
  ]);
2558
+ const openActionsEvent = eventActions.openEvent;
2062
2559
  return /* @__PURE__ */ jsxs("div", {
2560
+ ref: eventActions.rootRef,
2561
+ tabIndex: -1,
2063
2562
  className,
2064
2563
  style: {
2065
2564
  fontFamily: theme.fontFamily,
@@ -2069,6 +2568,16 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2069
2568
  ...style
2070
2569
  },
2071
2570
  children: [
2571
+ /* @__PURE__ */ jsx(EventActionsMenu, {
2572
+ events: [...new Set(positionedByDay.flat().filter((pe) => pe.startHours < windowEnd && pe.startHours + pe.durationHours > windowStart).map((pe) => pe.event))].filter((event) => editActions(event).length > 0),
2573
+ label: labels.editEvents,
2574
+ labelFor: (event) => labels.eventActions(event.title ?? ""),
2575
+ descriptionFor: eventDescription,
2576
+ onSelect: eventActions.select,
2577
+ rootRef: eventActions.rootRef,
2578
+ slot,
2579
+ theme
2580
+ }),
2072
2581
  /* @__PURE__ */ jsxs("div", {
2073
2582
  ...slot("header", {
2074
2583
  base: { display: "flex" },
@@ -2280,7 +2789,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2280
2789
  const showNow = showNowIndicator && isSameCalendarDay(day, now) && nowHours >= windowStart && nowHours <= windowEnd;
2281
2790
  const nowTop = (nowHours - windowStart) * hourHeight;
2282
2791
  const bands = bandsByDay[dayIndex];
2283
- const ghost = createBox?.dayIndex === dayIndex ? createBox : null;
2792
+ const ghost = createBox?.dayIndex === dayIndex && createBox.dayTime === day.getTime() ? createBox : null;
2793
+ const ghostRange = ghost ? createRange : null;
2284
2794
  const spill = multiDayMove ? null : spillPreviewFor(dayIndex);
2285
2795
  const moveSegment = multiDayMove ? layoutDayEvents$1([multiDayMove], day)[0] : void 0;
2286
2796
  return /* @__PURE__ */ jsxs("div", {
@@ -2289,6 +2799,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2289
2799
  onPointerMove: cellEnabled ? moveCreate : void 0,
2290
2800
  onPointerUp: cellEnabled ? endCreate : void 0,
2291
2801
  onPointerCancel: cellEnabled ? cancelCreate : void 0,
2802
+ onLostPointerCapture: cellEnabled ? loseCreateCapture : void 0,
2292
2803
  onClick: cellEnabled ? (e) => tapCell(e, dayIndex) : void 0,
2293
2804
  ...dataState({
2294
2805
  "data-today": getIsToday(day),
@@ -2398,25 +2909,12 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2398
2909
  ampm,
2399
2910
  onPress
2400
2911
  };
2401
- const editable = !!onDragEvent && pe.event.draggable !== false;
2402
- const canMove = editable && (pe.event.startEditable ?? eventStartEditable);
2403
- const canResize = editable && (pe.event.durationEditable ?? eventDurationEditable);
2912
+ const { canMove, canResize } = editability(pe.event);
2404
2913
  return /* @__PURE__ */ jsxs("div", {
2405
2914
  role: "button",
2406
2915
  tabIndex: 0,
2407
2916
  "data-event-key": keyboardEventNavigation ? key : void 0,
2408
- "aria-label": eventAccessibilityLabel$1 ? eventAccessibilityLabel$1(pe.event, {
2409
- mode,
2410
- isAllDay: false,
2411
- ampm
2412
- }) : eventAccessibilityLabel({
2413
- title: pe.event.title,
2414
- isAllDay: false,
2415
- start: pe.event.start,
2416
- end: pe.event.end,
2417
- ampm,
2418
- labels
2419
- }),
2917
+ "aria-label": eventLabel(pe.event),
2420
2918
  onKeyDown: (e) => {
2421
2919
  if (e.key === "Enter" || e.key === " ") {
2422
2920
  e.preventDefault();
@@ -2558,15 +3056,17 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2558
3056
  background: theme.nowIndicator
2559
3057
  } })]
2560
3058
  }) : null,
2561
- ghost ? /* @__PURE__ */ jsx("div", {
3059
+ ghost ? /* @__PURE__ */ jsx(InertDiv, {
2562
3060
  "aria-hidden": true,
3061
+ inert: !!ghostRange,
2563
3062
  ...slot("createGhost", {
2564
3063
  base: {
2565
3064
  position: "absolute",
2566
3065
  left: eventGap,
2567
3066
  right: eventGap,
2568
- top: ghost.topPx,
2569
- height: Math.max(ghost.heightPx, 2),
3067
+ ...createPreviewPlacement(Math.min(ghost.startPx, ghost.curPx), Math.abs(ghost.curPx - ghost.startPx), totalHeight),
3068
+ boxSizing: "border-box",
3069
+ ...ghostRange ? { overflow: "hidden" } : null,
2570
3070
  opacity: .7,
2571
3071
  pointerEvents: "none",
2572
3072
  zIndex: 2
@@ -2576,7 +3076,11 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2576
3076
  border: `1px solid ${theme.selectedBackground}`,
2577
3077
  borderRadius: 6
2578
3078
  }
2579
- })
3079
+ }),
3080
+ children: ghostRange && RenderCreateGhost ? /* @__PURE__ */ jsx(RenderCreateGhost, {
3081
+ start: ghostRange.start,
3082
+ end: ghostRange.end
3083
+ }) : null
2580
3084
  }) : null
2581
3085
  ]
2582
3086
  }, day.toISOString());
@@ -2614,12 +3118,24 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2614
3118
  theme,
2615
3119
  boxProps: slot("eventBox")
2616
3120
  })
3121
+ }) : null,
3122
+ openActionsEvent ? /* @__PURE__ */ jsx(EventActionsDialog, {
3123
+ dialogRef: eventActions.dialogRef,
3124
+ title: labels.eventActions(openActionsEvent.title ?? ""),
3125
+ description: eventDescription(openActionsEvent),
3126
+ actions: editActions(openActionsEvent),
3127
+ closeLabel: labels.close,
3128
+ rejectedLabel: labels.eventChangeRejected,
3129
+ rejections: eventActions.rejections,
3130
+ onAction: eventActions.run,
3131
+ onClose: () => eventActions.close(true),
3132
+ slot,
3133
+ theme
2617
3134
  }) : null
2618
3135
  ]
2619
3136
  });
2620
3137
  }
2621
- //#endregion
2622
- //#region src/Calendar.tsx
3138
+ // src/Calendar.tsx
2623
3139
  const EMPTY_EVENTS = [];
2624
3140
  function expansionRange(mode, date, weekStartsOn, numberOfDays) {
2625
3141
  if (mode === "month") return [startOfWeek(startOfMonth(date), { weekStartsOn }), endOfWeek(endOfMonth(date), { weekStartsOn })];
@@ -2646,7 +3162,7 @@ function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
2646
3162
  * ```
2647
3163
  */
2648
3164
  const Calendar = forwardRef(CalendarInner);
2649
- function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, hiddenDays, now, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, minEventHeight, eventGap, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, renderBusinessHours, renderBackgroundEvent, showNowIndicator, showAllDayEventCell, showAllDayLabel, highlightWeekends, eventStartEditable, eventDurationEditable, eventOverlap, dragStepMinutes, touchDragDelay, touchDragThreshold, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, chipHeight, chipGap, moreLabel, labels, showAdjacentMonths, showTitle, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onSelectDrag, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }, ref) {
3165
+ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, hiddenDays, now, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, minEventHeight, eventGap, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, renderBusinessHours, renderBackgroundEvent, showNowIndicator, showAllDayEventCell, showAllDayLabel, highlightWeekends, eventStartEditable, eventDurationEditable, eventOverlap, dragStepMinutes, touchDragDelay, touchDragThreshold, onPressCell, onCreateEvent, renderCreateGhost, onDragStart, onDragEvent, getEventId, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, chipHeight, chipGap, moreLabel, labels, showAdjacentMonths, showTitle, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onSelectDrag, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }, ref) {
2650
3166
  const timeGridRef = useRef(null);
2651
3167
  useImperativeHandle(ref, () => ({ scrollToTime: (minutes, options) => timeGridRef.current?.scrollToTime(minutes, options) }), []);
2652
3168
  const displayEvents = useMemo(() => {
@@ -2804,8 +3320,10 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
2804
3320
  onPressEvent,
2805
3321
  onPressCell,
2806
3322
  onCreateEvent,
3323
+ renderCreateGhost,
2807
3324
  onDragStart,
2808
3325
  onDragEvent,
3326
+ getEventId,
2809
3327
  onChangeDate,
2810
3328
  onPressDateHeader,
2811
3329
  renderEvent: renderTimeEvent,
@@ -2819,8 +3337,7 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
2819
3337
  children: view
2820
3338
  });
2821
3339
  }
2822
- //#endregion
2823
- //#region src/MonthList.tsx
3340
+ // src/MonthList.tsx
2824
3341
  /**
2825
3342
  * A vertically scrolling, virtualized list of months: the date picker. Built on
2826
3343
  * Legend List's DOM renderer and the library's headless grid logic. Selection is
@@ -2857,18 +3374,61 @@ function MonthList({ date, pastMonths = 1, futureMonths = 12, weekdayFormat = "s
2857
3374
  for (const list of map.values()) list.sort(compareDayEvents);
2858
3375
  return map;
2859
3376
  }, [events]);
2860
- const extraData = useMemo(() => [
2861
- selectedRange,
2862
- selectedDates,
3377
+ const renderMonth = useCallback(({ item }) => /* @__PURE__ */ jsx(MonthView, {
3378
+ date: item,
3379
+ weekStartsOn,
3380
+ highlightWeekends,
2863
3381
  events,
3382
+ eventsByDay,
3383
+ renderEvent,
3384
+ eventAccessibilityLabel,
3385
+ maxVisibleEventCount,
2864
3386
  chipHeight,
2865
- chipGap
2866
- ], [
3387
+ chipGap,
3388
+ moreLabel,
3389
+ labels,
3390
+ onPressEvent,
3391
+ onPressMore,
2867
3392
  selectedRange,
2868
3393
  selectedDates,
3394
+ fillCellOnSelection,
3395
+ showAdjacentMonths: false,
3396
+ showWeekdays: false,
3397
+ locale,
3398
+ theme: themeOverrides,
3399
+ minDate,
3400
+ maxDate,
3401
+ isDateDisabled,
3402
+ keyboardDayNavigation,
3403
+ onPressDay,
3404
+ classNames,
3405
+ styles
3406
+ }), [
3407
+ weekStartsOn,
3408
+ highlightWeekends,
2869
3409
  events,
3410
+ eventsByDay,
3411
+ renderEvent,
3412
+ eventAccessibilityLabel,
3413
+ maxVisibleEventCount,
2870
3414
  chipHeight,
2871
- chipGap
3415
+ chipGap,
3416
+ moreLabel,
3417
+ labels,
3418
+ onPressEvent,
3419
+ onPressMore,
3420
+ selectedRange,
3421
+ selectedDates,
3422
+ fillCellOnSelection,
3423
+ locale,
3424
+ themeOverrides,
3425
+ minDate,
3426
+ maxDate,
3427
+ isDateDisabled,
3428
+ keyboardDayNavigation,
3429
+ onPressDay,
3430
+ classNames,
3431
+ styles
2872
3432
  ]);
2873
3433
  return /* @__PURE__ */ jsxs("div", {
2874
3434
  className,
@@ -2899,7 +3459,7 @@ function MonthList({ date, pastMonths = 1, futureMonths = 12, weekdayFormat = "s
2899
3459
  }, wd.label))
2900
3460
  }), /* @__PURE__ */ jsx(LegendList, {
2901
3461
  data: months,
2902
- extraData,
3462
+ extraData: renderMonth,
2903
3463
  keyExtractor: (m) => m.toISOString(),
2904
3464
  recycleItems: false,
2905
3465
  estimatedItemSize: theme.cellHeight * 7 + 40,
@@ -2908,41 +3468,11 @@ function MonthList({ date, pastMonths = 1, futureMonths = 12, weekdayFormat = "s
2908
3468
  height,
2909
3469
  overflowY: "auto"
2910
3470
  },
2911
- renderItem: ({ item }) => /* @__PURE__ */ jsx(MonthView, {
2912
- date: item,
2913
- weekStartsOn,
2914
- highlightWeekends,
2915
- events,
2916
- eventsByDay,
2917
- renderEvent,
2918
- eventAccessibilityLabel,
2919
- maxVisibleEventCount,
2920
- chipHeight,
2921
- chipGap,
2922
- moreLabel,
2923
- labels,
2924
- onPressEvent,
2925
- onPressMore,
2926
- selectedRange,
2927
- selectedDates,
2928
- fillCellOnSelection,
2929
- showAdjacentMonths: false,
2930
- showWeekdays: false,
2931
- locale,
2932
- theme: themeOverrides,
2933
- minDate,
2934
- maxDate,
2935
- isDateDisabled,
2936
- keyboardDayNavigation,
2937
- onPressDay,
2938
- classNames,
2939
- styles
2940
- })
3471
+ renderItem: renderMonth
2941
3472
  })]
2942
3473
  });
2943
3474
  }
2944
- //#endregion
2945
- //#region src/DateRangePicker.tsx
3475
+ // src/DateRangePicker.tsx
2946
3476
  const triggerDefault = {
2947
3477
  display: "inline-flex",
2948
3478
  alignItems: "center",
@@ -2963,17 +3493,25 @@ const popoverDefault = {
2963
3493
  borderRadius: 12,
2964
3494
  minWidth: 300
2965
3495
  };
3496
+ function initialPickerFocus(dialog, day) {
3497
+ const usable = ":not([aria-disabled=\"true\"]):not([data-outside])";
3498
+ return dialog.querySelector(`[data-day="${day}"]${usable}`) ?? dialog.querySelector(`[data-day^="${day.slice(0, 7)}"][tabindex="0"]${usable}`) ?? dialog.querySelector(`[data-day^="${day.slice(0, 7)}"]${usable}`);
3499
+ }
2966
3500
  /**
2967
3501
  * The shared popover shell: a trigger button and a calendar panel that closes on
2968
3502
  * outside-click and Escape, and returns focus to the trigger. `renderCalendar`
2969
3503
  * gets a close callback so a single-date pick can dismiss immediately.
2970
3504
  */
2971
- function usePopover() {
3505
+ function usePopover(disabled) {
2972
3506
  const [open, setOpen] = useState(false);
2973
3507
  const rootRef = useRef(null);
2974
3508
  const triggerRef = useRef(null);
2975
3509
  useEffect(() => {
2976
3510
  if (!open) return;
3511
+ if (disabled) {
3512
+ setOpen(false);
3513
+ return;
3514
+ }
2977
3515
  const onDown = (e) => {
2978
3516
  if (!rootRef.current?.contains(e.target)) setOpen(false);
2979
3517
  };
@@ -2989,16 +3527,43 @@ function usePopover() {
2989
3527
  document.removeEventListener("mousedown", onDown);
2990
3528
  document.removeEventListener("keydown", onKey);
2991
3529
  };
2992
- }, [open]);
3530
+ }, [open, disabled]);
2993
3531
  return {
2994
- open,
3532
+ open: open && !disabled,
2995
3533
  setOpen,
2996
3534
  rootRef,
2997
3535
  triggerRef
2998
3536
  };
2999
3537
  }
3000
- function PickerShell({ open, setOpen, rootRef, triggerRef, theme, slot, label, hasValue, placeholder, disabled, className, style, ariaLabel, children }) {
3538
+ function PickerShell({ open, setOpen, rootRef, triggerRef, theme, slot, label, hasValue, placeholder, disabled, className, style, ariaLabel, focusDay, children }) {
3001
3539
  const dialogId = useId();
3540
+ const dialogRef = useRef(null);
3541
+ const focusDayRef = useRef(focusDay);
3542
+ focusDayRef.current = focusDay;
3543
+ useEffect(() => {
3544
+ if (!open) return;
3545
+ const dialog = dialogRef.current;
3546
+ if (!dialog) return;
3547
+ const place = () => {
3548
+ if (dialog.contains(document.activeElement)) {
3549
+ observer.disconnect();
3550
+ return;
3551
+ }
3552
+ const target = initialPickerFocus(dialog, focusDayRef.current);
3553
+ const monthMounted = dialog.querySelector(`[data-day^="${focusDayRef.current.slice(0, 7)}"]:not([data-outside])`);
3554
+ if (target || monthMounted) {
3555
+ (target ?? dialog).focus();
3556
+ observer.disconnect();
3557
+ }
3558
+ };
3559
+ const observer = new MutationObserver(place);
3560
+ observer.observe(dialog, {
3561
+ childList: true,
3562
+ subtree: true
3563
+ });
3564
+ place();
3565
+ return () => observer.disconnect();
3566
+ }, [open]);
3002
3567
  return /* @__PURE__ */ jsxs("div", {
3003
3568
  ref: rootRef,
3004
3569
  className,
@@ -3030,8 +3595,10 @@ function PickerShell({ open, setOpen, rootRef, triggerRef, theme, slot, label, h
3030
3595
  children: "▾"
3031
3596
  })]
3032
3597
  }), open ? /* @__PURE__ */ jsx("div", {
3598
+ ref: dialogRef,
3033
3599
  id: dialogId,
3034
3600
  role: "dialog",
3601
+ tabIndex: -1,
3035
3602
  "aria-label": ariaLabel,
3036
3603
  ...slot("popover", {
3037
3604
  base: popoverDefault,
@@ -3061,7 +3628,7 @@ function DatePicker({ value, onChange, formatLabel = (d) => format(d, "d MMM yyy
3061
3628
  classNames,
3062
3629
  styles
3063
3630
  });
3064
- const { open, setOpen, rootRef, triggerRef } = usePopover();
3631
+ const { open, setOpen, rootRef, triggerRef } = usePopover(disabled);
3065
3632
  return /* @__PURE__ */ jsx(PickerShell, {
3066
3633
  open,
3067
3634
  setOpen,
@@ -3076,7 +3643,9 @@ function DatePicker({ value, onChange, formatLabel = (d) => format(d, "d MMM yyy
3076
3643
  className,
3077
3644
  style,
3078
3645
  ariaLabel: "Choose a date",
3646
+ focusDay: format(value ?? /* @__PURE__ */ new Date(), "yyyy-MM-dd"),
3079
3647
  children: /* @__PURE__ */ jsx(MonthList, {
3648
+ theme: themeOverrides,
3080
3649
  date: value ?? /* @__PURE__ */ new Date(),
3081
3650
  weekStartsOn,
3082
3651
  selectedDates: value ? [value] : [],
@@ -3115,7 +3684,7 @@ function DateRangePicker({ value, onChange, formatLabel = defaultRangeLabel, wee
3115
3684
  classNames,
3116
3685
  styles
3117
3686
  });
3118
- const { open, setOpen, rootRef, triggerRef } = usePopover();
3687
+ const { open, setOpen, rootRef, triggerRef } = usePopover(disabled);
3119
3688
  const constraints = {
3120
3689
  minDate,
3121
3690
  maxDate,
@@ -3135,7 +3704,9 @@ function DateRangePicker({ value, onChange, formatLabel = defaultRangeLabel, wee
3135
3704
  className,
3136
3705
  style,
3137
3706
  ariaLabel: "Choose a date range",
3707
+ focusDay: format(value?.start ?? /* @__PURE__ */ new Date(), "yyyy-MM-dd"),
3138
3708
  children: [/* @__PURE__ */ jsx(MonthList, {
3709
+ theme: themeOverrides,
3139
3710
  date: value?.start ?? /* @__PURE__ */ new Date(),
3140
3711
  weekStartsOn,
3141
3712
  selectedRange: value ?? void 0,
@@ -3179,8 +3750,7 @@ function DateRangePicker({ value, onChange, formatLabel = defaultRangeLabel, wee
3179
3750
  })]
3180
3751
  });
3181
3752
  }
3182
- //#endregion
3183
- //#region src/ResourceTimeline.tsx
3753
+ // src/ResourceTimeline.tsx
3184
3754
  const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
3185
3755
  const GUTTER_WIDTH = 56;
3186
3756
  function DefaultBar({ event, height, boxProps, theme }) {
@@ -3249,7 +3819,7 @@ function DefaultBar({ event, height, boxProps, theme }) {
3249
3819
  * />
3250
3820
  * ```
3251
3821
  */
3252
- 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, renderResourceHeader, dragStepMinutes = 15, showNowIndicator = true, now: nowProp, timeZone, className, style, classNames, styles }) {
3822
+ 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, getEventId, onPressCell, onCreateEvent, renderCreateGhost, businessHours, renderBusinessHours, renderResourceHeader, dragStepMinutes = 15, labels: labelsProp, showNowIndicator = true, now: nowProp, timeZone, className, style, classNames, styles }) {
3253
3823
  const resources = useMemo(() => {
3254
3824
  if (!resourcesPerPage || resourcesPerPage <= 0) return allResources;
3255
3825
  const pages = Math.max(1, Math.ceil(allResources.length / resourcesPerPage));
@@ -3261,6 +3831,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3261
3831
  resourcePage
3262
3832
  ]);
3263
3833
  const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
3834
+ const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
3264
3835
  const slot = createSlots({
3265
3836
  classNames,
3266
3837
  styles
@@ -3300,19 +3871,33 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3300
3871
  }, `now-${resourceKey}`) : null;
3301
3872
  const [drag, setDrag] = useState(null);
3302
3873
  const dragRef = useRef(null);
3874
+ const handledClick = useRef(null);
3303
3875
  const origin = useRef(null);
3304
3876
  const applyDrag = (next) => {
3305
3877
  dragRef.current = next;
3306
3878
  setDrag(next);
3307
3879
  };
3308
- const beginDrag = (e, key, resourceId, kind, pe) => {
3880
+ const clearDrag = () => {
3881
+ const previous = dragRef.current;
3882
+ const element = origin.current?.element;
3883
+ applyDrag(null);
3884
+ origin.current = null;
3885
+ try {
3886
+ if (previous) element?.releasePointerCapture?.(previous.pointerId);
3887
+ } catch {}
3888
+ };
3889
+ const beginDrag = (e, resource, kind, pe) => {
3309
3890
  const { startHours, durationHours } = pe;
3310
- if (!onDragEvent) return;
3891
+ if (e.button === 0 && e.isPrimary !== false && !dragRef.current) handledClick.current = null;
3892
+ if (!onDragEvent || pe.event.draggable === false || dragRef.current || createOrigin.current || e.isPrimary === false || e.button !== 0) return;
3893
+ const element = e.currentTarget.closest("button");
3894
+ if (!element) return;
3311
3895
  e.stopPropagation();
3312
3896
  try {
3313
- e.target.setPointerCapture?.(e.pointerId);
3897
+ element.setPointerCapture?.(e.pointerId);
3314
3898
  } catch {}
3315
3899
  origin.current = {
3900
+ element,
3316
3901
  x: vertical ? e.clientY : e.clientX,
3317
3902
  cross: vertical ? e.clientX : e.clientY,
3318
3903
  startHours,
@@ -3323,8 +3908,9 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3323
3908
  }
3324
3909
  };
3325
3910
  applyDrag({
3326
- key,
3327
- resourceId,
3911
+ pointerId: e.pointerId,
3912
+ event: pe.event,
3913
+ resource,
3328
3914
  kind,
3329
3915
  startHours,
3330
3916
  durationHours,
@@ -3334,7 +3920,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3334
3920
  };
3335
3921
  const moveDrag = (e) => {
3336
3922
  const d = dragRef.current;
3337
- if (!d || !origin.current) return;
3923
+ if (!d || d.pointerId !== e.pointerId || !origin.current) return;
3338
3924
  const dHours = ((vertical ? e.clientY : e.clientX) - origin.current.x) / hourSize;
3339
3925
  const snap = (v) => Math.round(v / snapHours) * snapHours;
3340
3926
  if (d.kind === "move") {
@@ -3375,39 +3961,76 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3375
3961
  const id = (hit?.closest?.("[data-resource-id]"))?.getAttribute("data-resource-id");
3376
3962
  return id && resources.find((r) => r.id === id) || fallback;
3377
3963
  };
3378
- const endDrag = (e, event, resource, onPress) => {
3964
+ const endDrag = (e) => {
3379
3965
  const d = dragRef.current;
3380
- if (!d) return;
3381
- try {
3382
- e.target.releasePointerCapture?.(e.pointerId);
3383
- } catch {}
3966
+ if (!d || d.pointerId !== e.pointerId) return;
3967
+ handledClick.current = origin.current?.element ?? null;
3384
3968
  if (!d.moved) {
3385
- applyDrag(null);
3386
- onPress();
3969
+ clearDrag();
3970
+ onPressEvent?.(d.event);
3971
+ return;
3972
+ }
3973
+ const resource = resources.find((resource) => resource.id === d.resource.id);
3974
+ if (!resource) {
3975
+ clearDrag();
3387
3976
  return;
3388
3977
  }
3389
3978
  const target = d.kind === "move" ? laneAt(e, resource) : resource;
3390
3979
  const o = origin.current;
3391
3980
  const startDelta = o ? Math.round((d.startHours - o.startHours) * 60) : 0;
3392
3981
  const endDelta = d.kind === "move" ? startDelta : o ? Math.round((d.durationHours - o.durationHours) * 60) : 0;
3393
- const next = resolveDraggedBounds(event.start, event.end, startDelta, endDelta, dragStepMinutes);
3394
- if (next) onDragEvent?.(event, next.start, next.end, target);
3395
- applyDrag(null);
3396
- origin.current = null;
3982
+ const next = resolveDraggedBounds(d.event.start, d.event.end, startDelta, endDelta, dragStepMinutes);
3983
+ clearDrag();
3984
+ if (next) onDragEvent?.(d.event, next.start, next.end, target);
3397
3985
  };
3398
- const cancelDrag = () => {
3399
- applyDrag(null);
3400
- origin.current = null;
3986
+ const cancelDrag = (e) => {
3987
+ if (dragRef.current?.pointerId !== e.pointerId) return;
3988
+ handledClick.current = origin.current?.element ?? null;
3989
+ clearDrag();
3401
3990
  };
3402
3991
  const [createBox, setCreateBox] = useState(null);
3403
3992
  const createOrigin = useRef(null);
3993
+ const createActive = createBox !== null;
3994
+ useEffect(() => {
3995
+ if (!createActive) return;
3996
+ const onScroll = () => {
3997
+ const origin = createOrigin.current;
3998
+ if (!origin) return;
3999
+ const rect = origin.el.getBoundingClientRect();
4000
+ const curPx = vertical ? origin.clientY - rect.top : origin.clientX - rect.left;
4001
+ setCreateBox((current) => current && current.curPx !== curPx ? {
4002
+ ...current,
4003
+ curPx
4004
+ } : current);
4005
+ };
4006
+ window.addEventListener("scroll", onScroll, true);
4007
+ return () => window.removeEventListener("scroll", onScroll, true);
4008
+ }, [createActive, vertical]);
4009
+ const clearCreate = useCallback(() => {
4010
+ const previous = createOrigin.current;
4011
+ createOrigin.current = null;
4012
+ setCreateBox(null);
4013
+ try {
4014
+ previous?.el.releasePointerCapture?.(previous.pointerId);
4015
+ } catch {}
4016
+ }, []);
4017
+ useEffect(() => {
4018
+ const onKeyDown = (event) => {
4019
+ if (event.key !== "Escape" || !createOrigin.current) return;
4020
+ event.preventDefault();
4021
+ event.stopPropagation();
4022
+ clearCreate();
4023
+ };
4024
+ document.addEventListener("keydown", onKeyDown);
4025
+ return () => document.removeEventListener("keydown", onKeyDown);
4026
+ }, [clearCreate]);
3404
4027
  const cellEnabled = !!onPressCell || !!onCreateEvent;
3405
4028
  const pxAlongAxis = (el, e) => {
3406
4029
  const rect = el.getBoundingClientRect();
3407
4030
  return vertical ? e.clientY - rect.top : e.clientX - rect.left;
3408
4031
  };
3409
4032
  const beginCreate = (e, resource) => {
3410
- if (!cellEnabled || e.pointerType === "touch") return;
4033
+ if (!cellEnabled || e.pointerType === "touch" || e.isPrimary === false || createOrigin.current || dragRef.current) return;
3411
4034
  if (e.target !== e.currentTarget || e.button > 0) return;
3412
4035
  const el = e.currentTarget;
3413
4036
  const startPx = pxAlongAxis(el, e);
@@ -3415,9 +4038,14 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3415
4038
  el.setPointerCapture?.(e.pointerId);
3416
4039
  } catch {}
3417
4040
  createOrigin.current = {
4041
+ pointerId: e.pointerId,
4042
+ clientX: e.clientX,
4043
+ clientY: e.clientY,
3418
4044
  el,
3419
4045
  resource,
3420
- startPx
4046
+ startPx,
4047
+ dayKey: date.toDateString(),
4048
+ creating: !!onCreateEvent
3421
4049
  };
3422
4050
  if (onCreateEvent) setCreateBox({
3423
4051
  resourceKey: resource.id,
@@ -3427,7 +4055,9 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3427
4055
  };
3428
4056
  const moveCreate = (e) => {
3429
4057
  const o = createOrigin.current;
3430
- if (!o || !onCreateEvent) return;
4058
+ if (!o || o.pointerId !== e.pointerId || !onCreateEvent) return;
4059
+ o.clientX = e.clientX;
4060
+ o.clientY = e.clientY;
3431
4061
  setCreateBox({
3432
4062
  resourceKey: o.resource.id,
3433
4063
  startPx: o.startPx,
@@ -3436,31 +4066,155 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3436
4066
  };
3437
4067
  const endCreate = (e) => {
3438
4068
  const o = createOrigin.current;
3439
- if (!o) return;
3440
- try {
3441
- o.el.releasePointerCapture?.(e.pointerId);
3442
- } catch {}
4069
+ if (!o || o.pointerId !== e.pointerId) return;
3443
4070
  const endPx = pxAlongAxis(o.el, e);
3444
- if (Math.abs(endPx - o.startPx) > 4 && onCreateEvent) {
4071
+ const moved = Math.abs(endPx - o.startPx) > 4;
4072
+ clearCreate();
4073
+ const resource = resources.find((resource) => resource.id === o.resource.id);
4074
+ if (!resource) return;
4075
+ if (moved && onCreateEvent) {
3445
4076
  const range = cellRangeFromDrag(date, o.startPx, endPx, hourSize, startHour, dragStepMinutes);
3446
- if (range) onCreateEvent(range.start, range.end, o.resource);
4077
+ if (range) onCreateEvent(range.start, range.end, resource);
3447
4078
  } else if (onPressCell) {
3448
4079
  const at = cellRangeFromDrag(date, o.startPx, o.startPx, hourSize, startHour, dragStepMinutes);
3449
- if (at) onPressCell(at.start, o.resource);
4080
+ if (at) onPressCell(at.start, resource);
3450
4081
  }
3451
- createOrigin.current = null;
3452
- setCreateBox(null);
3453
4082
  };
3454
- const cancelCreate = () => {
3455
- createOrigin.current = null;
3456
- setCreateBox(null);
4083
+ const cancelCreate = (e) => {
4084
+ if (createOrigin.current?.pointerId !== e.pointerId) return;
4085
+ clearCreate();
3457
4086
  };
3458
- const trackInteractionProps = (resource) => cellEnabled ? {
4087
+ const RenderCreateGhost = renderCreateGhost;
4088
+ const liveRange = createBox && RenderCreateGhost && onCreateEvent ? cellRangeFromDrag(date, createBox.startPx, createBox.curPx, hourSize, startHour, dragStepMinutes) : null;
4089
+ const liveStart = liveRange?.start.getTime();
4090
+ const liveEnd = liveRange?.end.getTime();
4091
+ const createRange = useMemo(() => liveStart === void 0 || liveEnd === void 0 ? null : {
4092
+ start: new Date(liveStart),
4093
+ end: new Date(liveEnd)
4094
+ }, [liveStart, liveEnd]);
4095
+ const trackInteractionProps = (resource) => ({
3459
4096
  onPointerDown: (e) => beginCreate(e, resource),
3460
4097
  onPointerMove: moveCreate,
3461
4098
  onPointerUp: endCreate,
3462
- onPointerCancel: cancelCreate
3463
- } : null;
4099
+ onPointerCancel: cancelCreate,
4100
+ onLostPointerCapture: cancelCreate
4101
+ });
4102
+ useEffect(() => {
4103
+ if (dragRef.current && (!origin.current?.element.isConnected || !events.includes(dragRef.current.event))) clearDrag();
4104
+ const creating = createOrigin.current;
4105
+ if (creating && (!creating.el.isConnected || !cellEnabled || creating.creating && !onCreateEvent || creating.dayKey !== date.toDateString())) clearCreate();
4106
+ });
4107
+ useEffect(() => () => {
4108
+ const captured = origin.current;
4109
+ const currentDrag = dragRef.current;
4110
+ const currentCreate = createOrigin.current;
4111
+ origin.current = null;
4112
+ dragRef.current = null;
4113
+ createOrigin.current = null;
4114
+ try {
4115
+ if (currentDrag) captured?.element.releasePointerCapture?.(currentDrag.pointerId);
4116
+ currentCreate?.el.releasePointerCapture?.(currentCreate.pointerId);
4117
+ } catch {}
4118
+ }, []);
4119
+ const eventKeys = useRef(/* @__PURE__ */ new WeakMap());
4120
+ const nextEventKey = useRef(0);
4121
+ const eventKey = (event) => {
4122
+ let key = eventKeys.current.get(event);
4123
+ if (key === void 0) {
4124
+ key = nextEventKey.current++;
4125
+ eventKeys.current.set(event, key);
4126
+ }
4127
+ return key;
4128
+ };
4129
+ const laneOf = (event) => resources.findIndex((resource) => resource.id === resourceId(event));
4130
+ const eventDescription = (event) => `${resources.find((resource) => resource.id === resourceId(event))?.title ?? ""}, ${describeEventDates(event)}, ${eventAccessibilityLabel({
4131
+ title: event.title,
4132
+ isAllDay: false,
4133
+ start: event.start,
4134
+ end: event.end,
4135
+ ampm,
4136
+ labels
4137
+ })}`;
4138
+ const actionDelta = (id) => {
4139
+ switch (id) {
4140
+ case "move-later": return [
4141
+ dragStepMinutes,
4142
+ dragStepMinutes,
4143
+ 0
4144
+ ];
4145
+ case "move-earlier": return [
4146
+ -dragStepMinutes,
4147
+ -dragStepMinutes,
4148
+ 0
4149
+ ];
4150
+ case "extend": return [
4151
+ 0,
4152
+ dragStepMinutes,
4153
+ 0
4154
+ ];
4155
+ case "shorten": return [
4156
+ 0,
4157
+ -dragStepMinutes,
4158
+ 0
4159
+ ];
4160
+ case "move-next-resource": return [
4161
+ 0,
4162
+ 0,
4163
+ 1
4164
+ ];
4165
+ case "move-previous-resource": return [
4166
+ 0,
4167
+ 0,
4168
+ -1
4169
+ ];
4170
+ default: return null;
4171
+ }
4172
+ };
4173
+ const editActions = (event) => {
4174
+ if (isAllDayEvent$1(event) || isBackgroundEvent$1(event)) return [];
4175
+ const lane = laneOf(event);
4176
+ if (!onDragEvent || event.draggable === false || lane < 0) return [];
4177
+ const action = (id, label) => {
4178
+ const [startDelta, endDelta] = actionDelta(id) ?? [0, 0];
4179
+ return {
4180
+ id,
4181
+ label,
4182
+ available: resolveDraggedBounds(event.start, event.end, startDelta, endDelta, dragStepMinutes) !== null
4183
+ };
4184
+ };
4185
+ const laneTitle = (resource) => resource && (resource.title || resource.id);
4186
+ const nextLane = laneTitle(resources[lane + 1]);
4187
+ const previousLane = laneTitle(resources[lane - 1]);
4188
+ return [
4189
+ action("move-later", labels.moveLater(dragStepMinutes)),
4190
+ action("move-earlier", labels.moveEarlier(dragStepMinutes)),
4191
+ action("extend", labels.extend(dragStepMinutes)),
4192
+ action("shorten", labels.shorten(dragStepMinutes)),
4193
+ ...nextLane ? [action("move-next-resource", labels.moveToResource(nextLane))] : [],
4194
+ ...previousLane ? [action("move-previous-resource", labels.moveToResource(previousLane))] : []
4195
+ ];
4196
+ };
4197
+ const eventActions = useEventActions(events, editActions, (event, id) => {
4198
+ const delta = actionDelta(id);
4199
+ const target = delta ? resources[laneOf(event) + delta[2]] : void 0;
4200
+ const next = delta && target && resolveDraggedBounds(event.start, event.end, delta[0], delta[1], dragStepMinutes);
4201
+ if (!next || !target || onDragEvent?.(event, next.start, next.end, target) === false) return null;
4202
+ return (candidate) => candidate !== event && candidate.start.getTime() === next.start.getTime() && candidate.end.getTime() === next.end.getTime() && candidate.title === event.title && resourceId(candidate) === target.id;
4203
+ }, getEventId);
4204
+ const openActionsEvent = eventActions.openEvent;
4205
+ const actionsDialog = openActionsEvent ? /* @__PURE__ */ jsx(EventActionsDialog, {
4206
+ dialogRef: eventActions.dialogRef,
4207
+ title: labels.eventActions(openActionsEvent.title ?? ""),
4208
+ description: eventDescription(openActionsEvent),
4209
+ actions: editActions(openActionsEvent),
4210
+ closeLabel: labels.close,
4211
+ rejectedLabel: labels.eventChangeRejected,
4212
+ rejections: eventActions.rejections,
4213
+ onAction: eventActions.run,
4214
+ onClose: () => eventActions.close(true),
4215
+ slot,
4216
+ theme
4217
+ }) : null;
3464
4218
  const bandsFor = (resource) => businessHours ? closedHourBands(date, (d) => businessHours(d, resource), startHour, endHour) : [];
3465
4219
  const backgroundBandsFor = (resource) => backgroundBandsForDay$1(events.filter((e) => resourceId(e) === resource.id), date).map((b) => ({
3466
4220
  ...b,
@@ -3482,11 +4236,13 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3482
4236
  resourceId,
3483
4237
  date
3484
4238
  ]);
3485
- const dragLaneId = drag?.kind === "move" && drag.moved ? drag.resourceId : null;
4239
+ const dragLaneId = drag?.kind === "move" && drag.moved ? drag.resource.id : null;
3486
4240
  if (vertical) {
3487
4241
  const trackHeight = (endHour - startHour) * hourHeight;
3488
4242
  const vGridLines = `repeating-linear-gradient(to bottom, transparent 0, transparent ${hourHeight - 1}px, ${theme.gridLine} ${hourHeight - 1}px, ${theme.gridLine} ${hourHeight}px)`;
3489
4243
  return /* @__PURE__ */ jsxs("div", {
4244
+ ref: eventActions.rootRef,
4245
+ tabIndex: -1,
3490
4246
  className,
3491
4247
  style: {
3492
4248
  fontFamily: theme.fontFamily,
@@ -3494,85 +4250,347 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3494
4250
  overflowY: "auto",
3495
4251
  ...style
3496
4252
  },
3497
- children: [/* @__PURE__ */ jsxs("div", {
3498
- ...slot("header", {
3499
- base: {
3500
- display: "flex",
3501
- position: "sticky",
3502
- top: 0,
3503
- zIndex: 2
3504
- },
3505
- themed: {
3506
- borderBottom: `1px solid ${theme.gridLine}`,
3507
- background: theme.surface
3508
- }
4253
+ children: [
4254
+ /* @__PURE__ */ jsx(EventActionsMenu, {
4255
+ events: [...new Set([...byResource.values()].flat().map((pe) => pe.event))].filter((event) => editActions(event).length > 0),
4256
+ label: labels.editEvents,
4257
+ labelFor: (event) => labels.eventActions(event.title ?? ""),
4258
+ descriptionFor: eventDescription,
4259
+ onSelect: eventActions.select,
4260
+ rootRef: eventActions.rootRef,
4261
+ slot,
4262
+ theme
3509
4263
  }),
3510
- children: [/* @__PURE__ */ jsx("div", { ...slot("corner", { base: {
3511
- width: GUTTER_WIDTH,
3512
- flex: "none"
3513
- } }) }), resources.map((resource, index) => /* @__PURE__ */ jsx("div", {
3514
- ...slot("resourceLabel", {
4264
+ /* @__PURE__ */ jsxs("div", {
4265
+ ...slot("header", {
3515
4266
  base: {
3516
- flex: 1,
3517
- minWidth: 0,
3518
- padding: "6px 4px",
3519
- textAlign: "center",
3520
- overflow: "hidden",
3521
- textOverflow: "ellipsis",
3522
- whiteSpace: "nowrap",
3523
- boxSizing: "border-box"
4267
+ display: "flex",
4268
+ position: "sticky",
4269
+ top: 0,
4270
+ zIndex: 2
3524
4271
  },
3525
4272
  themed: {
3526
- fontSize: 13,
3527
- fontWeight: 600,
3528
- borderLeft: `1px solid ${theme.gridLine}`
4273
+ borderBottom: `1px solid ${theme.gridLine}`,
4274
+ background: theme.surface
3529
4275
  }
3530
4276
  }),
3531
- children: renderResourceHeader ? renderResourceHeader(resource, index) : resource.title ?? resource.id
3532
- }, resource.id))]
3533
- }), /* @__PURE__ */ jsxs("div", {
3534
- style: { display: "flex" },
3535
- children: [/* @__PURE__ */ jsx("div", {
3536
- ...slot("timeAxis", { base: {
3537
- position: "relative",
4277
+ children: [/* @__PURE__ */ jsx("div", { ...slot("corner", { base: {
3538
4278
  width: GUTTER_WIDTH,
3539
- flex: "none",
3540
- height: trackHeight
3541
- } }),
3542
- children: hours.map((h) => /* @__PURE__ */ jsx("div", {
3543
- ...slot("hourTick", {
4279
+ flex: "none"
4280
+ } }) }), resources.map((resource, index) => /* @__PURE__ */ jsx("div", {
4281
+ ...slot("resourceLabel", {
3544
4282
  base: {
3545
- position: "absolute",
3546
- top: Math.max(0, (h - startHour) * hourHeight - 6),
3547
- right: 6
4283
+ flex: 1,
4284
+ minWidth: 0,
4285
+ padding: "6px 4px",
4286
+ textAlign: "center",
4287
+ overflow: "hidden",
4288
+ textOverflow: "ellipsis",
4289
+ whiteSpace: "nowrap",
4290
+ boxSizing: "border-box"
3548
4291
  },
3549
4292
  themed: {
3550
- fontSize: 10,
3551
- color: theme.textMuted
4293
+ fontSize: 13,
4294
+ fontWeight: 600,
4295
+ borderLeft: `1px solid ${theme.gridLine}`
3552
4296
  }
3553
4297
  }),
3554
- children: formatHour(h, { ampm })
3555
- }, h))
3556
- }), resources.map((resource) => {
4298
+ children: renderResourceHeader ? renderResourceHeader(resource, index) : resource.title ?? resource.id
4299
+ }, resource.id))]
4300
+ }),
4301
+ /* @__PURE__ */ jsxs("div", {
4302
+ style: { display: "flex" },
4303
+ children: [/* @__PURE__ */ jsx("div", {
4304
+ ...slot("timeAxis", { base: {
4305
+ position: "relative",
4306
+ width: GUTTER_WIDTH,
4307
+ flex: "none",
4308
+ height: trackHeight
4309
+ } }),
4310
+ children: hours.map((h) => /* @__PURE__ */ jsx("div", {
4311
+ ...slot("hourTick", {
4312
+ base: {
4313
+ position: "absolute",
4314
+ top: Math.max(0, (h - startHour) * hourHeight - 6),
4315
+ right: 6
4316
+ },
4317
+ themed: {
4318
+ fontSize: 10,
4319
+ color: theme.textMuted
4320
+ }
4321
+ }),
4322
+ children: formatHour(h, { ampm })
4323
+ }, h))
4324
+ }), resources.map((resource) => {
4325
+ const positioned = byResource.get(resource.id) ?? [];
4326
+ return /* @__PURE__ */ jsx("div", {
4327
+ ...slot("row", {
4328
+ base: {
4329
+ flex: 1,
4330
+ minWidth: 0,
4331
+ ...dragLaneId === resource.id ? {
4332
+ position: "relative",
4333
+ zIndex: 5
4334
+ } : null
4335
+ },
4336
+ themed: { borderLeft: `1px solid ${theme.gridLine}` }
4337
+ }),
4338
+ children: /* @__PURE__ */ jsxs("div", {
4339
+ "data-resource-id": resource.id,
4340
+ ...trackInteractionProps(resource),
4341
+ ...slot("track", { base: {
4342
+ position: "relative",
4343
+ height: trackHeight
4344
+ } }),
4345
+ children: [
4346
+ bandsFor(resource).map((b) => /* @__PURE__ */ jsx("div", {
4347
+ "aria-hidden": true,
4348
+ ...slot("businessHours", {
4349
+ base: {
4350
+ position: "absolute",
4351
+ left: 0,
4352
+ right: 0,
4353
+ top: (b.start - startHour) * hourHeight,
4354
+ height: (b.end - b.start) * hourHeight,
4355
+ pointerEvents: "none",
4356
+ zIndex: 0
4357
+ },
4358
+ themed: renderBusinessHours ? void 0 : { background: theme.outsideHoursBackground }
4359
+ }),
4360
+ children: renderBusinessHours?.({
4361
+ date,
4362
+ start: b.start,
4363
+ end: b.end,
4364
+ resource
4365
+ })
4366
+ }, b.start)),
4367
+ backgroundBandsFor(resource).map((b, i) => /* @__PURE__ */ jsx("div", {
4368
+ "aria-hidden": true,
4369
+ title: b.event.title,
4370
+ ...slot("backgroundEvent", {
4371
+ base: {
4372
+ position: "absolute",
4373
+ left: 0,
4374
+ right: 0,
4375
+ top: (b.startHours - startHour) * hourHeight,
4376
+ height: (b.endHours - b.startHours) * hourHeight,
4377
+ pointerEvents: "none",
4378
+ zIndex: 0
4379
+ },
4380
+ themed: { background: theme.backgroundEvent }
4381
+ })
4382
+ }, `bg-${i}`)),
4383
+ /* @__PURE__ */ jsx("div", {
4384
+ "aria-hidden": true,
4385
+ ...slot("gridLines", {
4386
+ base: {
4387
+ position: "absolute",
4388
+ inset: 0,
4389
+ pointerEvents: "none"
4390
+ },
4391
+ themed: { backgroundImage: vGridLines }
4392
+ })
4393
+ }),
4394
+ positioned.map((pe) => {
4395
+ const key = eventKey(pe.event);
4396
+ const active = drag?.event === pe.event && drag.resource.id === resource.id ? drag : null;
4397
+ const startH = active ? active.startHours : pe.startHours;
4398
+ const durH = active ? active.durationHours : pe.durationHours;
4399
+ const top = clamp(startH - startHour, 0, endHour - startHour) * hourHeight;
4400
+ const bottom = clamp(startH + durH - startHour, 0, endHour - startHour) * hourHeight;
4401
+ const height = Math.max(bottom - top, 2);
4402
+ const lanePct = 100 / pe.columns;
4403
+ const onPress = () => onPressEvent?.(pe.event);
4404
+ const args = {
4405
+ event: pe.event,
4406
+ width: 0,
4407
+ height,
4408
+ onPress
4409
+ };
4410
+ const draggable = !!onDragEvent && pe.event.draggable !== false;
4411
+ return /* @__PURE__ */ jsxs("button", {
4412
+ type: "button",
4413
+ onClick: (e) => {
4414
+ if (e.detail !== 0 && handledClick.current === e.currentTarget) {
4415
+ handledClick.current = null;
4416
+ return;
4417
+ }
4418
+ if (!draggable || e.detail === 0) onPress();
4419
+ },
4420
+ "aria-label": pe.event.title,
4421
+ ...dataState({ "data-dragging": !!active }),
4422
+ onPointerDown: (e) => beginDrag(e, resource, "move", pe),
4423
+ onPointerMove: moveDrag,
4424
+ onPointerUp: endDrag,
4425
+ onPointerCancel: cancelDrag,
4426
+ onLostPointerCapture: cancelDrag,
4427
+ ...slot("event", { base: {
4428
+ position: "absolute",
4429
+ top,
4430
+ height,
4431
+ left: `${pe.column * lanePct}%`,
4432
+ width: `${lanePct}%`,
4433
+ transform: active?.kind === "move" ? `translateX(${active.crossPx}px)` : void 0,
4434
+ padding: 1,
4435
+ border: "none",
4436
+ background: "transparent",
4437
+ cursor: draggable ? "grab" : "pointer",
4438
+ touchAction: draggable ? "none" : "auto",
4439
+ font: "inherit",
4440
+ textAlign: "left",
4441
+ boxSizing: "border-box",
4442
+ zIndex: active ? 3 : 1,
4443
+ opacity: active ? .85 : 1
4444
+ } }),
4445
+ children: [Renderer ? /* @__PURE__ */ jsx(Renderer, { ...args }) : /* @__PURE__ */ jsx(DefaultBar, {
4446
+ ...args,
4447
+ theme,
4448
+ boxProps: slot("eventBox")
4449
+ }), draggable ? /* @__PURE__ */ jsx("span", {
4450
+ "aria-hidden": true,
4451
+ onPointerDown: (e) => {
4452
+ e.stopPropagation();
4453
+ beginDrag(e, resource, "resize", pe);
4454
+ },
4455
+ style: {
4456
+ position: "absolute",
4457
+ left: 0,
4458
+ right: 0,
4459
+ bottom: 0,
4460
+ height: 8,
4461
+ cursor: "ns-resize",
4462
+ touchAction: "none"
4463
+ }
4464
+ }) : null]
4465
+ }, key);
4466
+ }),
4467
+ nowLine(resource.id),
4468
+ createBox?.resourceKey === resource.id ? /* @__PURE__ */ jsx(InertDiv, {
4469
+ "aria-hidden": true,
4470
+ inert: !!createRange,
4471
+ ...slot("createGhost", {
4472
+ base: {
4473
+ position: "absolute",
4474
+ left: 1,
4475
+ right: 1,
4476
+ top: Math.min(createBox.startPx, createBox.curPx),
4477
+ height: Math.max(Math.abs(createBox.curPx - createBox.startPx), 2),
4478
+ ...createRange ? { overflow: "hidden" } : null,
4479
+ opacity: .7,
4480
+ pointerEvents: "none",
4481
+ zIndex: 2
4482
+ },
4483
+ themed: {
4484
+ background: theme.rangeBackground,
4485
+ border: `1px solid ${theme.selectedBackground}`,
4486
+ borderRadius: 6
4487
+ }
4488
+ }),
4489
+ children: createRange && RenderCreateGhost ? /* @__PURE__ */ jsx(RenderCreateGhost, {
4490
+ start: createRange.start,
4491
+ end: createRange.end,
4492
+ resource
4493
+ }) : null
4494
+ }) : null
4495
+ ]
4496
+ })
4497
+ }, resource.id);
4498
+ })]
4499
+ }),
4500
+ actionsDialog
4501
+ ]
4502
+ });
4503
+ }
4504
+ const gridLines = `repeating-linear-gradient(to right, transparent 0, transparent ${hourWidth - 1}px, ${theme.gridLine} ${hourWidth - 1}px, ${theme.gridLine} ${hourWidth}px)`;
4505
+ return /* @__PURE__ */ jsxs("div", {
4506
+ ref: eventActions.rootRef,
4507
+ tabIndex: -1,
4508
+ className,
4509
+ style: {
4510
+ fontFamily: theme.fontFamily,
4511
+ color: theme.text,
4512
+ overflowX: "auto",
4513
+ ...style
4514
+ },
4515
+ children: [
4516
+ /* @__PURE__ */ jsx(EventActionsMenu, {
4517
+ events: [...new Set([...byResource.values()].flat().map((pe) => pe.event))].filter((event) => editActions(event).length > 0),
4518
+ label: labels.editEvents,
4519
+ labelFor: (event) => labels.eventActions(event.title ?? ""),
4520
+ descriptionFor: eventDescription,
4521
+ onSelect: eventActions.select,
4522
+ rootRef: eventActions.rootRef,
4523
+ slot,
4524
+ theme
4525
+ }),
4526
+ /* @__PURE__ */ jsxs("div", {
4527
+ style: { minWidth: labelWidth + trackWidth },
4528
+ children: [/* @__PURE__ */ jsxs("div", {
4529
+ ...slot("header", {
4530
+ base: { display: "flex" },
4531
+ themed: { borderBottom: `1px solid ${theme.gridLine}` }
4532
+ }),
4533
+ children: [/* @__PURE__ */ jsx("div", { ...slot("corner", { base: {
4534
+ width: labelWidth,
4535
+ flex: "none"
4536
+ } }) }), /* @__PURE__ */ jsx("div", {
4537
+ ...slot("timeAxis", { base: {
4538
+ position: "relative",
4539
+ height: 24,
4540
+ width: trackWidth
4541
+ } }),
4542
+ children: hours.map((h) => /* @__PURE__ */ jsx("div", {
4543
+ ...slot("hourTick", {
4544
+ base: {
4545
+ position: "absolute",
4546
+ left: (h - startHour) * hourWidth,
4547
+ top: 4
4548
+ },
4549
+ themed: {
4550
+ fontSize: 10,
4551
+ color: theme.textMuted
4552
+ }
4553
+ }),
4554
+ children: formatHour(h, { ampm })
4555
+ }, h))
4556
+ })]
4557
+ }), resources.map((resource, index) => {
3557
4558
  const positioned = byResource.get(resource.id) ?? [];
3558
- return /* @__PURE__ */ jsx("div", {
4559
+ return /* @__PURE__ */ jsxs("div", {
3559
4560
  ...slot("row", {
3560
4561
  base: {
3561
- flex: 1,
3562
- minWidth: 0,
4562
+ display: "flex",
4563
+ height: rowHeight,
3563
4564
  ...dragLaneId === resource.id ? {
3564
4565
  position: "relative",
3565
4566
  zIndex: 5
3566
4567
  } : null
3567
4568
  },
3568
- themed: { borderLeft: `1px solid ${theme.gridLine}` }
4569
+ themed: { borderBottom: `1px solid ${theme.gridLine}` }
3569
4570
  }),
3570
- children: /* @__PURE__ */ jsxs("div", {
4571
+ children: [/* @__PURE__ */ jsx("div", {
4572
+ ...slot("resourceLabel", {
4573
+ base: {
4574
+ width: labelWidth,
4575
+ flex: "none",
4576
+ display: "flex",
4577
+ alignItems: "center",
4578
+ padding: "0 10px",
4579
+ boxSizing: "border-box"
4580
+ },
4581
+ themed: {
4582
+ fontSize: 13,
4583
+ fontWeight: 600,
4584
+ borderRight: `1px solid ${theme.gridLine}`
4585
+ }
4586
+ }),
4587
+ children: renderResourceHeader ? renderResourceHeader(resource, index) : resource.title ?? resource.id
4588
+ }), /* @__PURE__ */ jsxs("div", {
3571
4589
  "data-resource-id": resource.id,
3572
4590
  ...trackInteractionProps(resource),
3573
4591
  ...slot("track", { base: {
3574
4592
  position: "relative",
3575
- height: trackHeight
4593
+ width: trackWidth
3576
4594
  } }),
3577
4595
  children: [
3578
4596
  bandsFor(resource).map((b) => /* @__PURE__ */ jsx("div", {
@@ -3580,10 +4598,10 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3580
4598
  ...slot("businessHours", {
3581
4599
  base: {
3582
4600
  position: "absolute",
3583
- left: 0,
3584
- right: 0,
3585
- top: (b.start - startHour) * hourHeight,
3586
- height: (b.end - b.start) * hourHeight,
4601
+ top: 0,
4602
+ bottom: 0,
4603
+ left: (b.start - startHour) * hourWidth,
4604
+ width: (b.end - b.start) * hourWidth,
3587
4605
  pointerEvents: "none",
3588
4606
  zIndex: 0
3589
4607
  },
@@ -3602,10 +4620,10 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3602
4620
  ...slot("backgroundEvent", {
3603
4621
  base: {
3604
4622
  position: "absolute",
3605
- left: 0,
3606
- right: 0,
3607
- top: (b.startHours - startHour) * hourHeight,
3608
- height: (b.endHours - b.startHours) * hourHeight,
4623
+ top: 0,
4624
+ bottom: 0,
4625
+ left: (b.startHours - startHour) * hourWidth,
4626
+ width: (b.endHours - b.startHours) * hourWidth,
3609
4627
  pointerEvents: "none",
3610
4628
  zIndex: 0
3611
4629
  },
@@ -3620,42 +4638,48 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3620
4638
  inset: 0,
3621
4639
  pointerEvents: "none"
3622
4640
  },
3623
- themed: { backgroundImage: vGridLines }
4641
+ themed: { backgroundImage: gridLines }
3624
4642
  })
3625
4643
  }),
3626
- positioned.map((pe, idx) => {
3627
- const key = `${resource.id}:${idx}`;
3628
- const active = drag?.key === key ? drag : null;
4644
+ positioned.map((pe) => {
4645
+ const key = eventKey(pe.event);
4646
+ const active = drag?.event === pe.event && drag.resource.id === resource.id ? drag : null;
3629
4647
  const startH = active ? active.startHours : pe.startHours;
3630
4648
  const durH = active ? active.durationHours : pe.durationHours;
3631
- const top = clamp(startH - startHour, 0, endHour - startHour) * hourHeight;
3632
- const bottom = clamp(startH + durH - startHour, 0, endHour - startHour) * hourHeight;
3633
- const height = Math.max(bottom - top, 2);
3634
- const lanePct = 100 / pe.columns;
4649
+ const left = clamp(startH - startHour, 0, endHour - startHour) * hourWidth;
4650
+ const right = clamp(startH + durH - startHour, 0, endHour - startHour) * hourWidth;
4651
+ const width = Math.max(right - left, 2);
4652
+ const laneHeight = rowHeight / pe.columns;
3635
4653
  const onPress = () => onPressEvent?.(pe.event);
3636
4654
  const args = {
3637
4655
  event: pe.event,
3638
- width: 0,
3639
- height,
4656
+ width,
3640
4657
  onPress
3641
4658
  };
3642
4659
  const draggable = !!onDragEvent && pe.event.draggable !== false;
3643
4660
  return /* @__PURE__ */ jsxs("button", {
3644
4661
  type: "button",
3645
- onClick: draggable ? void 0 : onPress,
4662
+ onClick: (e) => {
4663
+ if (e.detail !== 0 && handledClick.current === e.currentTarget) {
4664
+ handledClick.current = null;
4665
+ return;
4666
+ }
4667
+ if (!draggable || e.detail === 0) onPress();
4668
+ },
3646
4669
  "aria-label": pe.event.title,
3647
4670
  ...dataState({ "data-dragging": !!active }),
3648
- onPointerDown: draggable ? (e) => beginDrag(e, key, resource.id, "move", pe) : void 0,
3649
- onPointerMove: draggable ? moveDrag : void 0,
3650
- onPointerUp: draggable ? (e) => endDrag(e, pe.event, resource, onPress) : void 0,
3651
- onPointerCancel: draggable ? cancelDrag : void 0,
4671
+ onPointerDown: (e) => beginDrag(e, resource, "move", pe),
4672
+ onPointerMove: moveDrag,
4673
+ onPointerUp: endDrag,
4674
+ onPointerCancel: cancelDrag,
4675
+ onLostPointerCapture: cancelDrag,
3652
4676
  ...slot("event", { base: {
3653
4677
  position: "absolute",
3654
- top,
3655
- height,
3656
- left: `${pe.column * lanePct}%`,
3657
- width: `${lanePct}%`,
3658
- transform: active?.kind === "move" ? `translateX(${active.crossPx}px)` : void 0,
4678
+ left,
4679
+ width,
4680
+ top: pe.column * laneHeight,
4681
+ height: laneHeight,
4682
+ transform: active?.kind === "move" ? `translateY(${active.crossPx}px)` : void 0,
3659
4683
  padding: 1,
3660
4684
  border: "none",
3661
4685
  background: "transparent",
@@ -3675,30 +4699,32 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3675
4699
  "aria-hidden": true,
3676
4700
  onPointerDown: (e) => {
3677
4701
  e.stopPropagation();
3678
- beginDrag(e, key, resource.id, "resize", pe);
4702
+ beginDrag(e, resource, "resize", pe);
3679
4703
  },
3680
4704
  style: {
3681
4705
  position: "absolute",
3682
- left: 0,
3683
- right: 0,
4706
+ top: 0,
3684
4707
  bottom: 0,
3685
- height: 8,
3686
- cursor: "ns-resize",
4708
+ right: 0,
4709
+ width: 8,
4710
+ cursor: "ew-resize",
3687
4711
  touchAction: "none"
3688
4712
  }
3689
4713
  }) : null]
3690
- }, idx);
4714
+ }, key);
3691
4715
  }),
3692
4716
  nowLine(resource.id),
3693
- createBox?.resourceKey === resource.id ? /* @__PURE__ */ jsx("div", {
4717
+ createBox?.resourceKey === resource.id ? /* @__PURE__ */ jsx(InertDiv, {
3694
4718
  "aria-hidden": true,
4719
+ inert: !!createRange,
3695
4720
  ...slot("createGhost", {
3696
4721
  base: {
3697
4722
  position: "absolute",
3698
- left: 1,
3699
- right: 1,
3700
- top: Math.min(createBox.startPx, createBox.curPx),
3701
- height: Math.max(Math.abs(createBox.curPx - createBox.startPx), 2),
4723
+ top: 1,
4724
+ bottom: 1,
4725
+ left: Math.min(createBox.startPx, createBox.curPx),
4726
+ width: Math.max(Math.abs(createBox.curPx - createBox.startPx), 2),
4727
+ ...createRange ? { overflow: "hidden" } : null,
3702
4728
  opacity: .7,
3703
4729
  pointerEvents: "none",
3704
4730
  zIndex: 2
@@ -3708,234 +4734,20 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
3708
4734
  border: `1px solid ${theme.selectedBackground}`,
3709
4735
  borderRadius: 6
3710
4736
  }
3711
- })
4737
+ }),
4738
+ children: createRange && RenderCreateGhost ? /* @__PURE__ */ jsx(RenderCreateGhost, {
4739
+ start: createRange.start,
4740
+ end: createRange.end,
4741
+ resource
4742
+ }) : null
3712
4743
  }) : null
3713
4744
  ]
3714
- })
4745
+ })]
3715
4746
  }, resource.id);
3716
4747
  })]
3717
- })]
3718
- });
3719
- }
3720
- const gridLines = `repeating-linear-gradient(to right, transparent 0, transparent ${hourWidth - 1}px, ${theme.gridLine} ${hourWidth - 1}px, ${theme.gridLine} ${hourWidth}px)`;
3721
- return /* @__PURE__ */ jsx("div", {
3722
- className,
3723
- style: {
3724
- fontFamily: theme.fontFamily,
3725
- color: theme.text,
3726
- overflowX: "auto",
3727
- ...style
3728
- },
3729
- children: /* @__PURE__ */ jsxs("div", {
3730
- style: { minWidth: labelWidth + trackWidth },
3731
- children: [/* @__PURE__ */ jsxs("div", {
3732
- ...slot("header", {
3733
- base: { display: "flex" },
3734
- themed: { borderBottom: `1px solid ${theme.gridLine}` }
3735
- }),
3736
- children: [/* @__PURE__ */ jsx("div", { ...slot("corner", { base: {
3737
- width: labelWidth,
3738
- flex: "none"
3739
- } }) }), /* @__PURE__ */ jsx("div", {
3740
- ...slot("timeAxis", { base: {
3741
- position: "relative",
3742
- height: 24,
3743
- width: trackWidth
3744
- } }),
3745
- children: hours.map((h) => /* @__PURE__ */ jsx("div", {
3746
- ...slot("hourTick", {
3747
- base: {
3748
- position: "absolute",
3749
- left: (h - startHour) * hourWidth,
3750
- top: 4
3751
- },
3752
- themed: {
3753
- fontSize: 10,
3754
- color: theme.textMuted
3755
- }
3756
- }),
3757
- children: formatHour(h, { ampm })
3758
- }, h))
3759
- })]
3760
- }), resources.map((resource, index) => {
3761
- const positioned = byResource.get(resource.id) ?? [];
3762
- return /* @__PURE__ */ jsxs("div", {
3763
- ...slot("row", {
3764
- base: {
3765
- display: "flex",
3766
- height: rowHeight,
3767
- ...dragLaneId === resource.id ? {
3768
- position: "relative",
3769
- zIndex: 5
3770
- } : null
3771
- },
3772
- themed: { borderBottom: `1px solid ${theme.gridLine}` }
3773
- }),
3774
- children: [/* @__PURE__ */ jsx("div", {
3775
- ...slot("resourceLabel", {
3776
- base: {
3777
- width: labelWidth,
3778
- flex: "none",
3779
- display: "flex",
3780
- alignItems: "center",
3781
- padding: "0 10px",
3782
- boxSizing: "border-box"
3783
- },
3784
- themed: {
3785
- fontSize: 13,
3786
- fontWeight: 600,
3787
- borderRight: `1px solid ${theme.gridLine}`
3788
- }
3789
- }),
3790
- children: renderResourceHeader ? renderResourceHeader(resource, index) : resource.title ?? resource.id
3791
- }), /* @__PURE__ */ jsxs("div", {
3792
- "data-resource-id": resource.id,
3793
- ...trackInteractionProps(resource),
3794
- ...slot("track", { base: {
3795
- position: "relative",
3796
- width: trackWidth
3797
- } }),
3798
- children: [
3799
- bandsFor(resource).map((b) => /* @__PURE__ */ jsx("div", {
3800
- "aria-hidden": true,
3801
- ...slot("businessHours", {
3802
- base: {
3803
- position: "absolute",
3804
- top: 0,
3805
- bottom: 0,
3806
- left: (b.start - startHour) * hourWidth,
3807
- width: (b.end - b.start) * hourWidth,
3808
- pointerEvents: "none",
3809
- zIndex: 0
3810
- },
3811
- themed: renderBusinessHours ? void 0 : { background: theme.outsideHoursBackground }
3812
- }),
3813
- children: renderBusinessHours?.({
3814
- date,
3815
- start: b.start,
3816
- end: b.end,
3817
- resource
3818
- })
3819
- }, b.start)),
3820
- backgroundBandsFor(resource).map((b, i) => /* @__PURE__ */ jsx("div", {
3821
- "aria-hidden": true,
3822
- title: b.event.title,
3823
- ...slot("backgroundEvent", {
3824
- base: {
3825
- position: "absolute",
3826
- top: 0,
3827
- bottom: 0,
3828
- left: (b.startHours - startHour) * hourWidth,
3829
- width: (b.endHours - b.startHours) * hourWidth,
3830
- pointerEvents: "none",
3831
- zIndex: 0
3832
- },
3833
- themed: { background: theme.backgroundEvent }
3834
- })
3835
- }, `bg-${i}`)),
3836
- /* @__PURE__ */ jsx("div", {
3837
- "aria-hidden": true,
3838
- ...slot("gridLines", {
3839
- base: {
3840
- position: "absolute",
3841
- inset: 0,
3842
- pointerEvents: "none"
3843
- },
3844
- themed: { backgroundImage: gridLines }
3845
- })
3846
- }),
3847
- positioned.map((pe, idx) => {
3848
- const key = `${resource.id}:${idx}`;
3849
- const active = drag?.key === key ? drag : null;
3850
- const startH = active ? active.startHours : pe.startHours;
3851
- const durH = active ? active.durationHours : pe.durationHours;
3852
- const left = clamp(startH - startHour, 0, endHour - startHour) * hourWidth;
3853
- const right = clamp(startH + durH - startHour, 0, endHour - startHour) * hourWidth;
3854
- const width = Math.max(right - left, 2);
3855
- const laneHeight = rowHeight / pe.columns;
3856
- const onPress = () => onPressEvent?.(pe.event);
3857
- const args = {
3858
- event: pe.event,
3859
- width,
3860
- onPress
3861
- };
3862
- const draggable = !!onDragEvent;
3863
- return /* @__PURE__ */ jsxs("button", {
3864
- type: "button",
3865
- onClick: draggable ? void 0 : onPress,
3866
- "aria-label": pe.event.title,
3867
- ...dataState({ "data-dragging": !!active }),
3868
- onPointerDown: draggable ? (e) => beginDrag(e, key, resource.id, "move", pe) : void 0,
3869
- onPointerMove: draggable ? moveDrag : void 0,
3870
- onPointerUp: draggable ? (e) => endDrag(e, pe.event, resource, onPress) : void 0,
3871
- onPointerCancel: draggable ? cancelDrag : void 0,
3872
- ...slot("event", { base: {
3873
- position: "absolute",
3874
- left,
3875
- width,
3876
- top: pe.column * laneHeight,
3877
- height: laneHeight,
3878
- transform: active?.kind === "move" ? `translateY(${active.crossPx}px)` : void 0,
3879
- padding: 1,
3880
- border: "none",
3881
- background: "transparent",
3882
- cursor: draggable ? "grab" : "pointer",
3883
- touchAction: draggable ? "none" : "auto",
3884
- font: "inherit",
3885
- textAlign: "left",
3886
- boxSizing: "border-box",
3887
- zIndex: active ? 3 : 1,
3888
- opacity: active ? .85 : 1
3889
- } }),
3890
- children: [Renderer ? /* @__PURE__ */ jsx(Renderer, { ...args }) : /* @__PURE__ */ jsx(DefaultBar, {
3891
- ...args,
3892
- theme,
3893
- boxProps: slot("eventBox")
3894
- }), draggable ? /* @__PURE__ */ jsx("span", {
3895
- "aria-hidden": true,
3896
- onPointerDown: (e) => {
3897
- e.stopPropagation();
3898
- beginDrag(e, key, resource.id, "resize", pe);
3899
- },
3900
- style: {
3901
- position: "absolute",
3902
- top: 0,
3903
- bottom: 0,
3904
- right: 0,
3905
- width: 8,
3906
- cursor: "ew-resize",
3907
- touchAction: "none"
3908
- }
3909
- }) : null]
3910
- }, idx);
3911
- }),
3912
- nowLine(resource.id),
3913
- createBox?.resourceKey === resource.id ? /* @__PURE__ */ jsx("div", {
3914
- "aria-hidden": true,
3915
- ...slot("createGhost", {
3916
- base: {
3917
- position: "absolute",
3918
- top: 1,
3919
- bottom: 1,
3920
- left: Math.min(createBox.startPx, createBox.curPx),
3921
- width: Math.max(Math.abs(createBox.curPx - createBox.startPx), 2),
3922
- opacity: .7,
3923
- pointerEvents: "none",
3924
- zIndex: 2
3925
- },
3926
- themed: {
3927
- background: theme.rangeBackground,
3928
- border: `1px solid ${theme.selectedBackground}`,
3929
- borderRadius: 6
3930
- }
3931
- })
3932
- }) : null
3933
- ]
3934
- })]
3935
- }, resource.id);
3936
- })]
3937
- })
4748
+ }),
4749
+ actionsDialog
4750
+ ]
3938
4751
  });
3939
4752
  }
3940
- //#endregion
3941
4753
  export { Agenda, Calendar, DatePicker, DateRangePicker, MonthList, MonthView, ResourceTimeline, TimeGrid, YearView, backgroundBandsForDay, buildMonthGrid, darkDomTheme, daySelectionState, defaultCalendarLabels, defaultDomTheme, expandRecurringEvents, getViewDays, isAllDayEvent, isBackgroundEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, layoutMonthWeek, mergeDomTheme, nextDateRange, parseICalendar, toICalendar, useDateRange, useEventSource, useMonthGrid, useNow, weekdayFormatToken };