@super-calendar/dom 2.7.0 → 2.8.1

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.
@@ -141,6 +141,14 @@ export interface ResourceTimelineProps<T = unknown> extends SlotStyleProps<Resou
141
141
  * band stays non-interactive and hidden from assistive tech.
142
142
  */
143
143
  renderBusinessHours?: (band: BusinessHoursBand & { resource: Resource }) => ReactNode;
144
+ /**
145
+ * Render each resource's header cell yourself (an avatar, a subtitle, a status
146
+ * dot). Receives the resource and its index; return the cell's content. The board
147
+ * keeps the header cell's sizing so columns stay aligned, so this replaces only
148
+ * the label content. Falls back to the resource title (or id). Applies to both
149
+ * orientations: the top header cells when vertical, the row labels when horizontal.
150
+ */
151
+ renderResourceHeader?: (resource: Resource, index: number) => ReactNode;
144
152
  /** Snap dragged events to this many minutes (default 15). */
145
153
  dragStepMinutes?: number;
146
154
  /** Show the current-time line when `date` is today (default true). */
@@ -261,6 +269,7 @@ export function ResourceTimeline<T = unknown>({
261
269
  onCreateEvent,
262
270
  businessHours,
263
271
  renderBusinessHours,
272
+ renderResourceHeader,
264
273
  dragStepMinutes = 15,
265
274
  showNowIndicator = true,
266
275
  now: nowProp,
@@ -573,7 +582,7 @@ export function ResourceTimeline<T = unknown>({
573
582
  })}
574
583
  >
575
584
  <div {...slot("corner", { base: { width: GUTTER_WIDTH, flex: "none" } })} />
576
- {resources.map((resource) => (
585
+ {resources.map((resource, index) => (
577
586
  <div
578
587
  key={resource.id}
579
588
  {...slot("resourceLabel", {
@@ -594,7 +603,9 @@ export function ResourceTimeline<T = unknown>({
594
603
  },
595
604
  })}
596
605
  >
597
- {resource.title ?? resource.id}
606
+ {renderResourceHeader
607
+ ? renderResourceHeader(resource, index)
608
+ : (resource.title ?? resource.id)}
598
609
  </div>
599
610
  ))}
600
611
  </div>
@@ -861,7 +872,7 @@ export function ResourceTimeline<T = unknown>({
861
872
  </div>
862
873
 
863
874
  {/* Resource rows */}
864
- {resources.map((resource) => {
875
+ {resources.map((resource, index) => {
865
876
  const positioned = byResource.get(resource.id) ?? [];
866
877
  return (
867
878
  <div
@@ -892,7 +903,9 @@ export function ResourceTimeline<T = unknown>({
892
903
  },
893
904
  })}
894
905
  >
895
- {resource.title ?? resource.id}
906
+ {renderResourceHeader
907
+ ? renderResourceHeader(resource, index)
908
+ : (resource.title ?? resource.id)}
896
909
  </div>
897
910
  <div
898
911
  data-resource-id={resource.id}
package/src/TimeGrid.tsx CHANGED
@@ -32,6 +32,7 @@ import {
32
32
  isSameCalendarDay,
33
33
  isWeekend,
34
34
  layoutDayEvents,
35
+ overlapsOtherEvents,
35
36
  useNow,
36
37
  type TimeGridMode,
37
38
  titleNumberOfLines,
@@ -177,6 +178,13 @@ export interface TimeGridProps<T = unknown> extends SlotStyleProps<TimeGridSlot>
177
178
  /** Tint Saturday/Sunday columns with the weekend background (default true). Set
178
179
  * false to treat weekends like any other day. */
179
180
  highlightWeekends?: boolean;
181
+ /** Allow moving events by default (per-event `startEditable` overrides). Default true. */
182
+ eventStartEditable?: boolean;
183
+ /** Allow resizing events by default (per-event `durationEditable` overrides). Default true. */
184
+ eventDurationEditable?: boolean;
185
+ /** Allow a dragged/resized event to overlap another (default true). Set false to
186
+ * reject a drop that would collide, snapping the event back. */
187
+ eventOverlap?: boolean;
180
188
  /** date-fns locale for the column headers and time labels. */
181
189
  locale?: Locale;
182
190
  /** Theme overrides; falls back to the default light theme. */
@@ -232,7 +240,9 @@ export interface TimeGridProps<T = unknown> extends SlotStyleProps<TimeGridSlot>
232
240
 
233
241
  type DragState = {
234
242
  key: string;
235
- kind: "move" | "resize";
243
+ // "resize" drags the bottom edge (changes the end); "resize-start" drags the
244
+ // top edge (changes the start, end fixed).
245
+ kind: "move" | "resize" | "resize-start";
236
246
  startHours: number;
237
247
  durationHours: number;
238
248
  /** Whole day columns the box has been dragged across, clamped to the view. */
@@ -378,6 +388,9 @@ export function TimeGrid<T = unknown>({
378
388
  renderBusinessHours,
379
389
  showNowIndicator = true,
380
390
  highlightWeekends = true,
391
+ eventStartEditable = true,
392
+ eventDurationEditable = true,
393
+ eventOverlap = true,
381
394
  now: nowProp,
382
395
  timeZone,
383
396
  showAllDayEventCell = true,
@@ -489,8 +502,14 @@ export function TimeGrid<T = unknown>({
489
502
  pageDepsRef.current = { date, mode, weekStartsOn, numberOfDays };
490
503
  const onChangeDateRef = useRef(onChangeDate);
491
504
  onChangeDateRef.current = onChangeDate;
505
+ // Wrap the handler so a drop that would overlap another event is rejected when
506
+ // `eventOverlap` is false, without the consumer wiring it in `onDragEvent`.
492
507
  const onDragEventRef = useRef(onDragEvent);
493
- onDragEventRef.current = onDragEvent;
508
+ onDragEventRef.current =
509
+ onDragEvent && eventOverlap === false
510
+ ? (event, start, end) =>
511
+ overlapsOtherEvents(events, event, start, end) ? false : onDragEvent(event, start, end)
512
+ : onDragEvent;
494
513
 
495
514
  const allDayByDay = useMemo(
496
515
  // A multi-day all-day event shows in every column it overlaps (matching the
@@ -655,13 +674,20 @@ export function TimeGrid<T = unknown>({
655
674
  }
656
675
  }
657
676
  }
658
- } else {
677
+ } else if (d.kind === "resize") {
659
678
  const durationHours = clamp(
660
679
  snap(dragOrigin.current.durationHours + dHours),
661
680
  snapHours,
662
681
  Math.max(snapHours, windowEnd - d.startHours),
663
682
  );
664
683
  applyDrag({ ...d, durationHours, moved: true });
684
+ } else {
685
+ // Top-edge resize: move the start, keep the end fixed. Clamp the start into
686
+ // the window and never past one snap step before the end.
687
+ const o = dragOrigin.current;
688
+ const end = o.startHours + o.durationHours;
689
+ const startHours = clamp(snap(o.startHours + dHours), windowStart, end - snapHours);
690
+ applyDrag({ ...d, startHours, durationHours: end - startHours, moved: true });
665
691
  }
666
692
  };
667
693
 
@@ -713,7 +739,7 @@ export function TimeGrid<T = unknown>({
713
739
  e: ReactPointerEvent,
714
740
  event: CalendarEvent<T>,
715
741
  key: string,
716
- kind: "move" | "resize",
742
+ kind: "move" | "resize" | "resize-start",
717
743
  startHours: number,
718
744
  durationHours: number,
719
745
  dayIndex: number,
@@ -1315,7 +1341,12 @@ export function TimeGrid<T = unknown>({
1315
1341
  };
1316
1342
  // `draggable: false` locks a single event: it keeps its normal
1317
1343
  // look and still responds to clicks, it just can't be dragged.
1318
- const draggable = !!onDragEvent && pe.event.draggable !== false;
1344
+ // `startEditable`/`durationEditable` (per-event, falling back to
1345
+ // the grid props) split whether it can be moved vs resized.
1346
+ const editable = !!onDragEvent && pe.event.draggable !== false;
1347
+ const canMove = editable && (pe.event.startEditable ?? eventStartEditable);
1348
+ const canResize =
1349
+ editable && (pe.event.durationEditable ?? eventDurationEditable);
1319
1350
  return (
1320
1351
  <div
1321
1352
  key={idx}
@@ -1347,7 +1378,7 @@ export function TimeGrid<T = unknown>({
1347
1378
  // (attached in beginDrag) so the drag survives the columns
1348
1379
  // remounting on a page change.
1349
1380
  onPointerDown={
1350
- draggable
1381
+ canMove
1351
1382
  ? (e) =>
1352
1383
  beginDrag(
1353
1384
  e,
@@ -1361,7 +1392,7 @@ export function TimeGrid<T = unknown>({
1361
1392
  )
1362
1393
  : undefined
1363
1394
  }
1364
- onClick={draggable ? undefined : onPress}
1395
+ onClick={canMove ? undefined : onPress}
1365
1396
  {...dataState({ "data-dragging": !!active })}
1366
1397
  {...slot("event", {
1367
1398
  base: {
@@ -1374,8 +1405,8 @@ export function TimeGrid<T = unknown>({
1374
1405
  height: boxHeight,
1375
1406
  left: `calc(${pe.column * widthPct}% + 1px)`,
1376
1407
  width: `calc(${widthPct}% - 2px)`,
1377
- cursor: draggable ? "grab" : "pointer",
1378
- touchAction: draggable ? "none" : "auto",
1408
+ cursor: canMove ? "grab" : "pointer",
1409
+ touchAction: canMove ? "none" : "auto",
1379
1410
  zIndex: active ? 3 : 1,
1380
1411
  opacity: active ? 0.85 : 1,
1381
1412
  // Snap the dragged box over the target day column so the
@@ -1391,7 +1422,32 @@ export function TimeGrid<T = unknown>({
1391
1422
  ) : (
1392
1423
  <DefaultDomEvent {...args} theme={theme} boxProps={slot("eventBox")} />
1393
1424
  )}
1394
- {draggable ? (
1425
+ {canResize && !pe.continuesBefore ? (
1426
+ <div
1427
+ onPointerDown={(e) => {
1428
+ e.stopPropagation();
1429
+ beginDrag(
1430
+ e,
1431
+ pe.event,
1432
+ key,
1433
+ "resize-start",
1434
+ pe.startHours,
1435
+ pe.durationHours,
1436
+ dayIndex,
1437
+ );
1438
+ }}
1439
+ style={{
1440
+ position: "absolute",
1441
+ left: 0,
1442
+ right: 0,
1443
+ top: 0,
1444
+ height: 8,
1445
+ cursor: "ns-resize",
1446
+ touchAction: "none",
1447
+ }}
1448
+ />
1449
+ ) : null}
1450
+ {canResize ? (
1395
1451
  <div
1396
1452
  onPointerDown={(e) => {
1397
1453
  e.stopPropagation();
package/src/index.ts CHANGED
@@ -96,11 +96,14 @@ export {
96
96
  useNow,
97
97
  useMonthGrid,
98
98
  buildMonthGrid,
99
+ layoutMonthWeek,
99
100
  weekdayFormatToken,
101
+ type MonthEventSegment,
100
102
  type MonthGrid,
101
103
  type MonthGridDay,
102
104
  type MonthGridWeek,
103
105
  type MonthGridWeekday,
106
+ type MonthWeekEvents,
104
107
  type UseMonthGridOptions,
105
108
  type WeekdayFormat,
106
109
  } from "@super-calendar/core";