@super-calendar/core 2.8.1 → 2.9.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/README.md CHANGED
@@ -43,6 +43,16 @@ import { useDateRange } from "@super-calendar/core";
43
43
  const range = useDateRange({ mode: "range" });
44
44
  ```
45
45
 
46
+ For a custom time-grid drag, `clampMoveStartMinutes` keeps the moved event's
47
+ start inside the visible hour window while allowing its unchanged duration to
48
+ carry the end past midnight:
49
+
50
+ ```ts
51
+ import { clampMoveStartMinutes } from "@super-calendar/core";
52
+
53
+ const startMinutes = clampMoveStartMinutes(rawStartMinutes, minHour, maxHour, snapMinutes);
54
+ ```
55
+
46
56
  ## Documentation
47
57
 
48
58
  See the [full documentation](https://super-calendar.afonsojramos.me) and the [API reference](https://super-calendar.afonsojramos.me/reference/api).
package/dist/index.d.mts CHANGED
@@ -401,6 +401,16 @@ declare function pageStepDays(mode: CalendarMode, date: Date, weekStartsOn: Week
401
401
  * degenerate grid (non-positive height/step).
402
402
  */
403
403
  declare function snapDeltaMinutes(translationPx: number, cellHeightPx: number, stepMinutes: number): number;
404
+ /**
405
+ * Where a moved event may start, in minutes from midnight, given the grid's
406
+ * visible hour window. A move keeps its duration, so only the start is held
407
+ * inside the window: it can reach one `snapMinutes` step before `maxHour`, and
408
+ * the end is free to run past the end of the day, continuing on the following
409
+ * day. That keeps the event starting in the column it was dropped on (a
410
+ * cross-day *move* is the horizontal drag) while still allowing a range that
411
+ * spans midnight. Runs on the UI thread inside the drag gesture.
412
+ */
413
+ declare function clampMoveStartMinutes(startMinutes: number, minHour: number, maxHour: number, snapMinutes: number): number;
404
414
  /** A copy of `date` shifted by `minutes` (may be negative). */
405
415
  declare function shiftMinutes(date: Date, minutes: number): Date;
406
416
  /**
@@ -416,6 +426,26 @@ declare function resolveDraggedBounds(start: Date, end: Date, deltaStartMinutes:
416
426
  start: Date;
417
427
  end: Date;
418
428
  } | null;
429
+ /**
430
+ * The all-day range swept out between two day cells of the month grid, ordered
431
+ * whichever way the sweep ran: `start` is midnight of the first day and `end` is
432
+ * midnight after the last, so a one-day sweep still yields a usable event. Shared
433
+ * by both renderers so a month drag-to-create means the same thing on each.
434
+ */
435
+ declare function monthCreateRange(anchor: Date, hover: Date): {
436
+ start: Date;
437
+ end: Date;
438
+ };
439
+ /**
440
+ * The new bounds for an event picked up on `fromDay` and dropped on `toDay` in
441
+ * the month grid: both ends move by the same number of calendar days, so the
442
+ * event keeps its time of day and duration (DST included). Returns `null` when
443
+ * the drop lands on the day it started, so a stray drag commits nothing.
444
+ */
445
+ declare function monthDropBounds<T>(event: CalendarEvent<T>, fromDay: Date, toDay: Date): {
446
+ start: Date;
447
+ end: Date;
448
+ } | null;
419
449
  /**
420
450
  * The start/end of a new event swept out on `day` by dragging from `startPx` to
421
451
  * `endPx` (vertical pixels from the grid's top, i.e. the `minHour` line). Both
@@ -916,4 +946,4 @@ declare function zonedTimeToUtc(wallClock: Date, timeZone: string): Date;
916
946
  */
917
947
  declare function eventsInTimeZone<T>(events: CalendarEvent<T>[], timeZone: string): CalendarEvent<T>[];
918
948
  //#endregion
919
- export { BusinessHours, BusinessHoursBand, BusinessHoursValue, CalendarColors, CalendarEvent, CalendarMode, CalendarSelection, CalendarSelectionProvider, DateRange, DateSelectionConstraints, DayBadgeKind, DaySelectionState, EventAccessibilityLabelContext, EventAccessibilityLabeler, EventChipLayout, EventKeyExtractor, EventSourceOptions, EventSourceState, ICalEvent, ICalendarEvent, MIN_BOX_HEIGHT_FOR_TIME, MonthEventCapacity, MonthEventSegment, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, MonthWeekEvents, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, TimeGridMode, ToICalendarOptions, UseDateRangeOptions, UseDateRangeResult, UseMonthGridOptions, UseNowOptions, WeekStartsOn, WeekdayFormat, backgroundBandsForDay, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, eventsOverlap, expandRecurringEvents, filterHiddenDays, formatHour, getIsToday, getViewDays, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isBackgroundEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, layoutMonthWeek, lightColors, minutesIntoDay, monthEventCapacity, monthVisibleCount, nextDateRange, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useCalendarSelection, useDateRange, useEventSource, useMonthGrid, useNow, viewDayCount, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };
949
+ export { BusinessHours, BusinessHoursBand, BusinessHoursValue, CalendarColors, CalendarEvent, CalendarMode, CalendarSelection, CalendarSelectionProvider, DateRange, DateSelectionConstraints, DayBadgeKind, DaySelectionState, EventAccessibilityLabelContext, EventAccessibilityLabeler, EventChipLayout, EventKeyExtractor, EventSourceOptions, EventSourceState, ICalEvent, ICalendarEvent, MIN_BOX_HEIGHT_FOR_TIME, MonthEventCapacity, MonthEventSegment, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, MonthWeekEvents, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, TimeGridMode, ToICalendarOptions, UseDateRangeOptions, UseDateRangeResult, UseMonthGridOptions, UseNowOptions, WeekStartsOn, WeekdayFormat, backgroundBandsForDay, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, clampMoveStartMinutes, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, eventsOverlap, expandRecurringEvents, filterHiddenDays, formatHour, getIsToday, getViewDays, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isBackgroundEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, layoutMonthWeek, lightColors, minutesIntoDay, monthCreateRange, monthDropBounds, monthEventCapacity, monthVisibleCount, nextDateRange, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useCalendarSelection, useDateRange, useEventSource, useMonthGrid, useNow, viewDayCount, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };
package/dist/index.d.ts CHANGED
@@ -401,6 +401,16 @@ declare function pageStepDays(mode: CalendarMode, date: Date, weekStartsOn: Week
401
401
  * degenerate grid (non-positive height/step).
402
402
  */
403
403
  declare function snapDeltaMinutes(translationPx: number, cellHeightPx: number, stepMinutes: number): number;
404
+ /**
405
+ * Where a moved event may start, in minutes from midnight, given the grid's
406
+ * visible hour window. A move keeps its duration, so only the start is held
407
+ * inside the window: it can reach one `snapMinutes` step before `maxHour`, and
408
+ * the end is free to run past the end of the day, continuing on the following
409
+ * day. That keeps the event starting in the column it was dropped on (a
410
+ * cross-day *move* is the horizontal drag) while still allowing a range that
411
+ * spans midnight. Runs on the UI thread inside the drag gesture.
412
+ */
413
+ declare function clampMoveStartMinutes(startMinutes: number, minHour: number, maxHour: number, snapMinutes: number): number;
404
414
  /** A copy of `date` shifted by `minutes` (may be negative). */
405
415
  declare function shiftMinutes(date: Date, minutes: number): Date;
406
416
  /**
@@ -416,6 +426,26 @@ declare function resolveDraggedBounds(start: Date, end: Date, deltaStartMinutes:
416
426
  start: Date;
417
427
  end: Date;
418
428
  } | null;
429
+ /**
430
+ * The all-day range swept out between two day cells of the month grid, ordered
431
+ * whichever way the sweep ran: `start` is midnight of the first day and `end` is
432
+ * midnight after the last, so a one-day sweep still yields a usable event. Shared
433
+ * by both renderers so a month drag-to-create means the same thing on each.
434
+ */
435
+ declare function monthCreateRange(anchor: Date, hover: Date): {
436
+ start: Date;
437
+ end: Date;
438
+ };
439
+ /**
440
+ * The new bounds for an event picked up on `fromDay` and dropped on `toDay` in
441
+ * the month grid: both ends move by the same number of calendar days, so the
442
+ * event keeps its time of day and duration (DST included). Returns `null` when
443
+ * the drop lands on the day it started, so a stray drag commits nothing.
444
+ */
445
+ declare function monthDropBounds<T>(event: CalendarEvent<T>, fromDay: Date, toDay: Date): {
446
+ start: Date;
447
+ end: Date;
448
+ } | null;
419
449
  /**
420
450
  * The start/end of a new event swept out on `day` by dragging from `startPx` to
421
451
  * `endPx` (vertical pixels from the grid's top, i.e. the `minHour` line). Both
@@ -916,4 +946,4 @@ declare function zonedTimeToUtc(wallClock: Date, timeZone: string): Date;
916
946
  */
917
947
  declare function eventsInTimeZone<T>(events: CalendarEvent<T>[], timeZone: string): CalendarEvent<T>[];
918
948
  //#endregion
919
- export { BusinessHours, BusinessHoursBand, BusinessHoursValue, CalendarColors, CalendarEvent, CalendarMode, CalendarSelection, CalendarSelectionProvider, DateRange, DateSelectionConstraints, DayBadgeKind, DaySelectionState, EventAccessibilityLabelContext, EventAccessibilityLabeler, EventChipLayout, EventKeyExtractor, EventSourceOptions, EventSourceState, ICalEvent, ICalendarEvent, MIN_BOX_HEIGHT_FOR_TIME, MonthEventCapacity, MonthEventSegment, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, MonthWeekEvents, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, TimeGridMode, ToICalendarOptions, UseDateRangeOptions, UseDateRangeResult, UseMonthGridOptions, UseNowOptions, WeekStartsOn, WeekdayFormat, backgroundBandsForDay, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, eventsOverlap, expandRecurringEvents, filterHiddenDays, formatHour, getIsToday, getViewDays, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isBackgroundEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, layoutMonthWeek, lightColors, minutesIntoDay, monthEventCapacity, monthVisibleCount, nextDateRange, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useCalendarSelection, useDateRange, useEventSource, useMonthGrid, useNow, viewDayCount, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };
949
+ export { BusinessHours, BusinessHoursBand, BusinessHoursValue, CalendarColors, CalendarEvent, CalendarMode, CalendarSelection, CalendarSelectionProvider, DateRange, DateSelectionConstraints, DayBadgeKind, DaySelectionState, EventAccessibilityLabelContext, EventAccessibilityLabeler, EventChipLayout, EventKeyExtractor, EventSourceOptions, EventSourceState, ICalEvent, ICalendarEvent, MIN_BOX_HEIGHT_FOR_TIME, MonthEventCapacity, MonthEventSegment, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, MonthWeekEvents, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, TimeGridMode, ToICalendarOptions, UseDateRangeOptions, UseDateRangeResult, UseMonthGridOptions, UseNowOptions, WeekStartsOn, WeekdayFormat, backgroundBandsForDay, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, clampMoveStartMinutes, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, eventsOverlap, expandRecurringEvents, filterHiddenDays, formatHour, getIsToday, getViewDays, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isBackgroundEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, layoutMonthWeek, lightColors, minutesIntoDay, monthCreateRange, monthDropBounds, monthEventCapacity, monthVisibleCount, nextDateRange, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useCalendarSelection, useDateRange, useEventSource, useMonthGrid, useNow, viewDayCount, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };
package/dist/index.js CHANGED
@@ -313,6 +313,21 @@ function snapDeltaMinutes(translationPx, cellHeightPx, stepMinutes) {
313
313
  const rawMinutes = translationPx / cellHeightPx * 60;
314
314
  return Math.round(rawMinutes / stepMinutes) * stepMinutes;
315
315
  }
316
+ /**
317
+ * Where a moved event may start, in minutes from midnight, given the grid's
318
+ * visible hour window. A move keeps its duration, so only the start is held
319
+ * inside the window: it can reach one `snapMinutes` step before `maxHour`, and
320
+ * the end is free to run past the end of the day, continuing on the following
321
+ * day. That keeps the event starting in the column it was dropped on (a
322
+ * cross-day *move* is the horizontal drag) while still allowing a range that
323
+ * spans midnight. Runs on the UI thread inside the drag gesture.
324
+ */
325
+ function clampMoveStartMinutes(startMinutes, minHour, maxHour, snapMinutes) {
326
+ "worklet";
327
+ const lower = minHour * 60;
328
+ const upper = Math.max(lower, maxHour * 60 - snapMinutes);
329
+ return Math.min(Math.max(startMinutes, lower), upper);
330
+ }
316
331
  /** A copy of `date` shifted by `minutes` (may be negative). */
317
332
  function shiftMinutes(date, minutes) {
318
333
  const next = new Date(date);
@@ -340,6 +355,34 @@ function resolveDraggedBounds(start, end, deltaStartMinutes, deltaEndMinutes, sn
340
355
  };
341
356
  }
342
357
  /**
358
+ * The all-day range swept out between two day cells of the month grid, ordered
359
+ * whichever way the sweep ran: `start` is midnight of the first day and `end` is
360
+ * midnight after the last, so a one-day sweep still yields a usable event. Shared
361
+ * by both renderers so a month drag-to-create means the same thing on each.
362
+ */
363
+ function monthCreateRange(anchor, hover) {
364
+ const a = (0, date_fns.startOfDay)(anchor);
365
+ const b = (0, date_fns.startOfDay)(hover);
366
+ return {
367
+ start: a.getTime() <= b.getTime() ? a : b,
368
+ end: (0, date_fns.addDays)(a.getTime() <= b.getTime() ? b : a, 1)
369
+ };
370
+ }
371
+ /**
372
+ * The new bounds for an event picked up on `fromDay` and dropped on `toDay` in
373
+ * the month grid: both ends move by the same number of calendar days, so the
374
+ * event keeps its time of day and duration (DST included). Returns `null` when
375
+ * the drop lands on the day it started, so a stray drag commits nothing.
376
+ */
377
+ function monthDropBounds(event, fromDay, toDay) {
378
+ const delta = (0, date_fns.differenceInCalendarDays)((0, date_fns.startOfDay)(toDay), (0, date_fns.startOfDay)(fromDay));
379
+ if (delta === 0) return null;
380
+ return {
381
+ start: (0, date_fns.addDays)(event.start, delta),
382
+ end: (0, date_fns.addDays)(event.end, delta)
383
+ };
384
+ }
385
+ /**
343
386
  * The start/end of a new event swept out on `day` by dragging from `startPx` to
344
387
  * `endPx` (vertical pixels from the grid's top, i.e. the `minHour` line). Both
345
388
  * ends snap to `snapMinutes`; the range is ordered (drag up or down) and widened
@@ -1483,6 +1526,7 @@ exports.bandRounding = bandRounding;
1483
1526
  exports.buildMonthGrid = buildMonthGrid;
1484
1527
  exports.buildMonthWeeks = buildMonthWeeks;
1485
1528
  exports.cellRangeFromDrag = cellRangeFromDrag;
1529
+ exports.clampMoveStartMinutes = clampMoveStartMinutes;
1486
1530
  exports.closedHourBands = closedHourBands;
1487
1531
  exports.compareDayEvents = compareDayEvents;
1488
1532
  exports.darkColors = darkColors;
@@ -1514,6 +1558,8 @@ exports.layoutDayEvents = layoutDayEvents;
1514
1558
  exports.layoutMonthWeek = layoutMonthWeek;
1515
1559
  exports.lightColors = lightColors;
1516
1560
  exports.minutesIntoDay = minutesIntoDay;
1561
+ exports.monthCreateRange = monthCreateRange;
1562
+ exports.monthDropBounds = monthDropBounds;
1517
1563
  exports.monthEventCapacity = monthEventCapacity;
1518
1564
  exports.monthVisibleCount = monthVisibleCount;
1519
1565
  exports.nextDateRange = nextDateRange;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { addDays, addMonths, addWeeks, addYears, differenceInMinutes, eachDayOfInterval, endOfMonth, endOfWeek, format, getHours, getMinutes, isAfter, isBefore, isSameDay, isSameMonth, isToday, max, min, startOfDay, startOfMonth, startOfWeek } from "date-fns";
1
+ import { addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, differenceInMinutes, eachDayOfInterval, endOfMonth, endOfWeek, format, getHours, getMinutes, isAfter, isBefore, isSameDay, isSameMonth, isToday, max, min, startOfDay, startOfMonth, startOfWeek } from "date-fns";
2
2
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
3
3
  //#region src/tokens.ts
4
4
  /** The default light-theme colour palette. */
@@ -312,6 +312,21 @@ function snapDeltaMinutes(translationPx, cellHeightPx, stepMinutes) {
312
312
  const rawMinutes = translationPx / cellHeightPx * 60;
313
313
  return Math.round(rawMinutes / stepMinutes) * stepMinutes;
314
314
  }
315
+ /**
316
+ * Where a moved event may start, in minutes from midnight, given the grid's
317
+ * visible hour window. A move keeps its duration, so only the start is held
318
+ * inside the window: it can reach one `snapMinutes` step before `maxHour`, and
319
+ * the end is free to run past the end of the day, continuing on the following
320
+ * day. That keeps the event starting in the column it was dropped on (a
321
+ * cross-day *move* is the horizontal drag) while still allowing a range that
322
+ * spans midnight. Runs on the UI thread inside the drag gesture.
323
+ */
324
+ function clampMoveStartMinutes(startMinutes, minHour, maxHour, snapMinutes) {
325
+ "worklet";
326
+ const lower = minHour * 60;
327
+ const upper = Math.max(lower, maxHour * 60 - snapMinutes);
328
+ return Math.min(Math.max(startMinutes, lower), upper);
329
+ }
315
330
  /** A copy of `date` shifted by `minutes` (may be negative). */
316
331
  function shiftMinutes(date, minutes) {
317
332
  const next = new Date(date);
@@ -339,6 +354,34 @@ function resolveDraggedBounds(start, end, deltaStartMinutes, deltaEndMinutes, sn
339
354
  };
340
355
  }
341
356
  /**
357
+ * The all-day range swept out between two day cells of the month grid, ordered
358
+ * whichever way the sweep ran: `start` is midnight of the first day and `end` is
359
+ * midnight after the last, so a one-day sweep still yields a usable event. Shared
360
+ * by both renderers so a month drag-to-create means the same thing on each.
361
+ */
362
+ function monthCreateRange(anchor, hover) {
363
+ const a = startOfDay(anchor);
364
+ const b = startOfDay(hover);
365
+ return {
366
+ start: a.getTime() <= b.getTime() ? a : b,
367
+ end: addDays(a.getTime() <= b.getTime() ? b : a, 1)
368
+ };
369
+ }
370
+ /**
371
+ * The new bounds for an event picked up on `fromDay` and dropped on `toDay` in
372
+ * the month grid: both ends move by the same number of calendar days, so the
373
+ * event keeps its time of day and duration (DST included). Returns `null` when
374
+ * the drop lands on the day it started, so a stray drag commits nothing.
375
+ */
376
+ function monthDropBounds(event, fromDay, toDay) {
377
+ const delta = differenceInCalendarDays(startOfDay(toDay), startOfDay(fromDay));
378
+ if (delta === 0) return null;
379
+ return {
380
+ start: addDays(event.start, delta),
381
+ end: addDays(event.end, delta)
382
+ };
383
+ }
384
+ /**
342
385
  * The start/end of a new event swept out on `day` by dragging from `startPx` to
343
386
  * `endPx` (vertical pixels from the grid's top, i.e. the `minHour` line). Both
344
387
  * ends snap to `snapMinutes`; the range is ordered (drag up or down) and widened
@@ -1475,4 +1518,4 @@ function expandRecurringEvents(events, rangeStart, rangeEnd) {
1475
1518
  return out;
1476
1519
  }
1477
1520
  //#endregion
1478
- export { CalendarSelectionProvider, MIN_BOX_HEIGHT_FOR_TIME, backgroundBandsForDay, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, eventsOverlap, expandRecurringEvents, filterHiddenDays, formatHour, getIsToday, getViewDays, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isBackgroundEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, layoutMonthWeek, lightColors, minutesIntoDay, monthEventCapacity, monthVisibleCount, nextDateRange, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useCalendarSelection, useDateRange, useEventSource, useMonthGrid, useNow, viewDayCount, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };
1521
+ export { CalendarSelectionProvider, MIN_BOX_HEIGHT_FOR_TIME, backgroundBandsForDay, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, clampMoveStartMinutes, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, eventsOverlap, expandRecurringEvents, filterHiddenDays, formatHour, getIsToday, getViewDays, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isBackgroundEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, layoutMonthWeek, lightColors, minutesIntoDay, monthCreateRange, monthDropBounds, monthEventCapacity, monthVisibleCount, nextDateRange, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useCalendarSelection, useDateRange, useEventSource, useMonthGrid, useNow, viewDayCount, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/core",
3
- "version": "2.8.1",
3
+ "version": "2.9.0",
4
4
  "description": "Render-agnostic core for super-calendar: date math, selection model, event layout, the month-grid builder, headless hooks, and neutral theme tokens. No renderer.",
5
5
  "keywords": [
6
6
  "calendar",
package/src/utils/drag.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { addDays, differenceInCalendarDays, startOfDay } from "date-fns";
1
2
  import type { CalendarEvent, CalendarMode, WeekStartsOn } from "../types";
2
3
  import { getViewDays } from "./dates";
3
4
 
@@ -55,6 +56,27 @@ export function snapDeltaMinutes(
55
56
  return Math.round(rawMinutes / stepMinutes) * stepMinutes;
56
57
  }
57
58
 
59
+ /**
60
+ * Where a moved event may start, in minutes from midnight, given the grid's
61
+ * visible hour window. A move keeps its duration, so only the start is held
62
+ * inside the window: it can reach one `snapMinutes` step before `maxHour`, and
63
+ * the end is free to run past the end of the day, continuing on the following
64
+ * day. That keeps the event starting in the column it was dropped on (a
65
+ * cross-day *move* is the horizontal drag) while still allowing a range that
66
+ * spans midnight. Runs on the UI thread inside the drag gesture.
67
+ */
68
+ export function clampMoveStartMinutes(
69
+ startMinutes: number,
70
+ minHour: number,
71
+ maxHour: number,
72
+ snapMinutes: number,
73
+ ): number {
74
+ "worklet";
75
+ const lower = minHour * 60;
76
+ const upper = Math.max(lower, maxHour * 60 - snapMinutes);
77
+ return Math.min(Math.max(startMinutes, lower), upper);
78
+ }
79
+
58
80
  /** A copy of `date` shifted by `minutes` (may be negative). */
59
81
  export function shiftMinutes(date: Date, minutes: number): Date {
60
82
  const next = new Date(date);
@@ -87,6 +109,36 @@ export function resolveDraggedBounds(
87
109
  return { start: nextStart, end: nextEnd };
88
110
  }
89
111
 
112
+ /**
113
+ * The all-day range swept out between two day cells of the month grid, ordered
114
+ * whichever way the sweep ran: `start` is midnight of the first day and `end` is
115
+ * midnight after the last, so a one-day sweep still yields a usable event. Shared
116
+ * by both renderers so a month drag-to-create means the same thing on each.
117
+ */
118
+ export function monthCreateRange(anchor: Date, hover: Date): { start: Date; end: Date } {
119
+ const a = startOfDay(anchor);
120
+ const b = startOfDay(hover);
121
+ const first = a.getTime() <= b.getTime() ? a : b;
122
+ const last = a.getTime() <= b.getTime() ? b : a;
123
+ return { start: first, end: addDays(last, 1) };
124
+ }
125
+
126
+ /**
127
+ * The new bounds for an event picked up on `fromDay` and dropped on `toDay` in
128
+ * the month grid: both ends move by the same number of calendar days, so the
129
+ * event keeps its time of day and duration (DST included). Returns `null` when
130
+ * the drop lands on the day it started, so a stray drag commits nothing.
131
+ */
132
+ export function monthDropBounds<T>(
133
+ event: CalendarEvent<T>,
134
+ fromDay: Date,
135
+ toDay: Date,
136
+ ): { start: Date; end: Date } | null {
137
+ const delta = differenceInCalendarDays(startOfDay(toDay), startOfDay(fromDay));
138
+ if (delta === 0) return null;
139
+ return { start: addDays(event.start, delta), end: addDays(event.end, delta) };
140
+ }
141
+
90
142
  /**
91
143
  * The start/end of a new event swept out on `day` by dragging from `startPx` to
92
144
  * `endPx` (vertical pixels from the grid's top, i.e. the `minHour` line). Both