@super-calendar/dom 2.13.0 → 2.14.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/src/MonthView.tsx CHANGED
@@ -127,6 +127,10 @@ export interface MonthViewProps<T = unknown>
127
127
  * per day, so a long bar can push a lightly-booked day's own events into "+N more".
128
128
  */
129
129
  maxVisibleEventCount?: number;
130
+ /** Height of an event chip and of the "+N more" row, in px (default 18). */
131
+ chipHeight?: number;
132
+ /** Vertical gap between event chips, in px (default 2). */
133
+ chipGap?: number;
130
134
  /** Template for the overflow row; `{moreCount}` is replaced (default "{moreCount} More"). */
131
135
  moreLabel?: string;
132
136
  /** Translations for the screen-reader words and gutter text; omitted keys use English. */
@@ -328,6 +332,7 @@ function eventCellDefault(
328
332
  // True while a drag is over this day: a create sweep covering it, or a move
329
333
  // about to land on it. Tinted over the weekend shading so the drag reads live.
330
334
  isDragTarget: boolean,
335
+ chipGap: number,
331
336
  ): SlotDefault {
332
337
  return {
333
338
  base: {
@@ -338,7 +343,7 @@ function eventCellDefault(
338
343
  cursor: day.isDisabled ? "default" : "pointer",
339
344
  display: "flex",
340
345
  flexDirection: "column",
341
- gap: CHIP_GAP,
346
+ gap: chipGap,
342
347
  padding: CELL_PAD,
343
348
  boxSizing: "border-box",
344
349
  textAlign: "left",
@@ -397,12 +402,12 @@ const chipButtonDefault: SlotDefault = {
397
402
  },
398
403
  };
399
404
 
400
- function chipDefault(theme: DomCalendarTheme): SlotDefault {
405
+ function chipDefault(theme: DomCalendarTheme, chipHeight: number): SlotDefault {
401
406
  return {
402
407
  base: {
403
408
  display: "block",
404
- height: CHIP_HEIGHT,
405
- lineHeight: `${CHIP_HEIGHT}px`,
409
+ height: chipHeight,
410
+ lineHeight: `${chipHeight}px`,
406
411
  whiteSpace: "nowrap",
407
412
  overflow: "hidden",
408
413
  textOverflow: "ellipsis",
@@ -418,7 +423,7 @@ function chipDefault(theme: DomCalendarTheme): SlotDefault {
418
423
  };
419
424
  }
420
425
 
421
- function moreButtonDefault(theme: DomCalendarTheme): SlotDefault {
426
+ function moreButtonDefault(theme: DomCalendarTheme, chipHeight: number): SlotDefault {
422
427
  return {
423
428
  base: {
424
429
  position: "relative",
@@ -427,8 +432,8 @@ function moreButtonDefault(theme: DomCalendarTheme): SlotDefault {
427
432
  background: "transparent",
428
433
  cursor: "pointer",
429
434
  textAlign: "left",
430
- height: CHIP_HEIGHT,
431
- lineHeight: `${CHIP_HEIGHT}px`,
435
+ height: chipHeight,
436
+ lineHeight: `${chipHeight}px`,
432
437
  fontFamily: "inherit",
433
438
  },
434
439
  themed: {
@@ -487,6 +492,8 @@ export function MonthView<T = unknown>({
487
492
  renderEvent,
488
493
  eventAccessibilityLabel,
489
494
  maxVisibleEventCount = 3,
495
+ chipHeight = CHIP_HEIGHT,
496
+ chipGap = CHIP_GAP,
490
497
  moreLabel = "{moreCount} More",
491
498
  labels: labelsProp,
492
499
  onPressEvent,
@@ -579,7 +586,7 @@ export function MonthView<T = unknown>({
579
586
  }, [moreOpenFor]);
580
587
  // Reserve `maxVisibleEventCount` rows below the date so every cell is uniform;
581
588
  // when a day overflows, the last row becomes the "+N more" affordance.
582
- const eventRowHeight = CELL_PAD * 2 + DATE_ROW + maxVisibleEventCount * (CHIP_HEIGHT + CHIP_GAP);
589
+ const eventRowHeight = CELL_PAD * 2 + DATE_ROW + maxVisibleEventCount * (chipHeight + chipGap);
583
590
  const { weeks, weekdays } = useMemo(
584
591
  () =>
585
592
  buildMonthGrid(date, {
@@ -833,7 +840,7 @@ export function MonthView<T = unknown>({
833
840
  })
834
841
  .filter((b) => b.startCol <= b.endCol);
835
842
  const barChipButton = slot("chipButton", chipButtonDefault);
836
- const barChip = slot("chip", chipDefault(theme));
843
+ const barChip = slot("chip", chipDefault(theme, chipHeight));
837
844
  return (
838
845
  <div
839
846
  key={week.id}
@@ -897,6 +904,7 @@ export function MonthView<T = unknown>({
897
904
  cellHeight,
898
905
  highlightWeekends,
899
906
  inCreate || isDropTarget,
907
+ chipGap,
900
908
  ),
901
909
  );
902
910
  return (
@@ -1019,9 +1027,9 @@ export function MonthView<T = unknown>({
1019
1027
  top:
1020
1028
  CELL_PAD +
1021
1029
  DATE_ROW +
1022
- CHIP_GAP +
1023
- b.seg.lane * (CHIP_HEIGHT + CHIP_GAP),
1024
- height: CHIP_HEIGHT,
1030
+ chipGap +
1031
+ b.seg.lane * (chipHeight + chipGap),
1032
+ height: chipHeight,
1025
1033
  pointerEvents: isDragging ? "none" : "auto",
1026
1034
  // Fade the bar being carried, so the tinted drop
1027
1035
  // target reads as where it is going.
@@ -1057,13 +1065,13 @@ export function MonthView<T = unknown>({
1057
1065
  })}
1058
1066
  <div
1059
1067
  {...slot("events", {
1060
- base: { display: "flex", flexDirection: "column", gap: CHIP_GAP },
1068
+ base: { display: "flex", flexDirection: "column", gap: chipGap },
1061
1069
  })}
1062
1070
  >
1063
1071
  {/* Reserve one row per visible lane so the absolute bars have
1064
1072
  space and "+more" sits below them. */}
1065
1073
  {Array.from({ length: visibleLanes }, (_, i) => (
1066
- <div key={`lane-${i}`} aria-hidden style={{ height: CHIP_HEIGHT }} />
1074
+ <div key={`lane-${i}`} aria-hidden style={{ height: chipHeight }} />
1067
1075
  ))}
1068
1076
  {hiddenEvents.length > 0 ? (
1069
1077
  <button
@@ -1080,7 +1088,7 @@ export function MonthView<T = unknown>({
1080
1088
  setMoreOpenFor((open) => (open === day.id ? null : day.id));
1081
1089
  }
1082
1090
  }}
1083
- {...slot("more", moreButtonDefault(theme))}
1091
+ {...slot("more", moreButtonDefault(theme, chipHeight))}
1084
1092
  aria-label={`${labels.moreEvents(hiddenEvents.length)}, ${dayLabel}`}
1085
1093
  aria-expanded={onPressMore ? undefined : moreOpenFor === day.id}
1086
1094
  >
@@ -1160,7 +1168,9 @@ export function MonthView<T = unknown>({
1160
1168
  {Chip ? (
1161
1169
  <Chip event={event} onPress={() => onPressEvent?.(event)} />
1162
1170
  ) : (
1163
- <span {...slot("chip", chipDefault(theme))}>{event.title}</span>
1171
+ <span {...slot("chip", chipDefault(theme, chipHeight))}>
1172
+ {event.title}
1173
+ </span>
1164
1174
  )}
1165
1175
  </button>
1166
1176
  ))}
package/src/TimeGrid.tsx CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  type ForwardedRef,
14
14
  forwardRef,
15
15
  type KeyboardEvent as ReactKeyboardEvent,
16
+ type MouseEvent as ReactMouseEvent,
16
17
  type PointerEvent as ReactPointerEvent,
17
18
  type ReactElement,
18
19
  type ReactNode,
@@ -59,6 +60,7 @@ import {
59
60
  } from "@super-calendar/core";
60
61
  import { createSlots, dataState, type ResolvedSlot, type SlotStyleProps } from "./slots";
61
62
  import { type DomCalendarTheme, mergeDomTheme } from "./theme";
63
+ import { type EventGrab, waitForHold } from "./touch";
62
64
 
63
65
  /**
64
66
  * Styleable parts of {@link TimeGrid}. Pass a class or inline style per slot via
@@ -101,6 +103,7 @@ const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v
101
103
  const EDGE_ZONE = 32;
102
104
  const EDGE_DWELL_MS = 600;
103
105
  const EDGE_REPEAT_MS = 600;
106
+ const CELL_TOUCH_SLOP_PX = 8;
104
107
 
105
108
  // Off-screen but readable by assistive tech: gives an element an accessible name
106
109
  // without changing the visible layout.
@@ -177,6 +180,10 @@ export interface TimeGridProps<T = unknown> extends SlotStyleProps<TimeGridSlot>
177
180
  eventGap?: number;
178
181
  /** Snap dragged events to this many minutes (default 15). */
179
182
  dragStepMinutes?: number;
183
+ /** Hold duration before a DOM touch or pen drag, in ms (default 300). */
184
+ touchDragDelay?: number;
185
+ /** Movement tolerance for a DOM touch or pen hold, in px (default 8). */
186
+ touchDragThreshold?: number;
180
187
  /** Render event time ranges in 12-hour AM/PM (default false, 24h). */
181
188
  ampm?: boolean;
182
189
  /** Sub-divisions per hour for the grid lines, e.g. 2 for half-hour (default 1). */
@@ -437,6 +444,8 @@ function TimeGridInner<T = unknown>(
437
444
  minEventHeight = DEFAULT_MIN_EVENT_HEIGHT,
438
445
  eventGap = DEFAULT_EVENT_GAP,
439
446
  dragStepMinutes = 15,
447
+ touchDragDelay = 300,
448
+ touchDragThreshold = 8,
440
449
  ampm = false,
441
450
  timeslots = 1,
442
451
  minHour = 0,
@@ -517,6 +526,7 @@ function TimeGridInner<T = unknown>(
517
526
  const dragOrigin = useRef<{
518
527
  pointerX: number;
519
528
  pointerY: number;
529
+ pointerType: string;
520
530
  startHours: number;
521
531
  durationHours: number;
522
532
  dayIndex: number;
@@ -541,6 +551,9 @@ function TimeGridInner<T = unknown>(
541
551
  heightPx: number;
542
552
  } | null>(null);
543
553
  const createOrigin = useRef<{ el: HTMLElement; dayIndex: number; startPx: number } | null>(null);
554
+ // Touch never sweeps, so a tap presses the cell from its click, which the
555
+ // browser skips when the finger scrolled the grid instead.
556
+ const cellTouchRef = useRef<{ pointerId: number; x: number; y: number } | null>(null);
544
557
  const cellEnabled = !!onPressCell || !!onCreateEvent;
545
558
 
546
559
  const days = useMemo(
@@ -569,6 +582,13 @@ function TimeGridInner<T = unknown>(
569
582
  h: number;
570
583
  } | null>(null);
571
584
  const ghostRef = useRef<HTMLDivElement>(null);
585
+ // A held touch or pen drag stops touchmove from scrolling the grid.
586
+ const touchDragRef = useRef(false);
587
+ const activeGrabRef = useRef<EventGrab | null>(null);
588
+ // Cancels a touch or pen press that has not become a drag yet.
589
+ const cancelHoldRef = useRef<(() => void) | null>(null);
590
+ // A touch or pen tap ended on an event; its click presses the event.
591
+ const tappedRef = useRef<HTMLElement | null>(null);
572
592
  const docHandlersRef = useRef<{
573
593
  move: (e: PointerEvent) => void;
574
594
  up: (e: PointerEvent) => void;
@@ -643,6 +663,30 @@ function TimeGridInner<T = unknown>(
643
663
  return () => el.removeEventListener("wheel", onWheel);
644
664
  }, [zoomable, minHourHeight, maxHourHeight]);
645
665
 
666
+ // Browser touch-action is fixed for the gesture; cancel touchmove only during a held drag.
667
+ useEffect(() => {
668
+ const el = scrollRef.current;
669
+ if (!el) {
670
+ return;
671
+ }
672
+ const onTouchMove = (e: TouchEvent) => {
673
+ if (touchDragRef.current && e.cancelable) {
674
+ e.preventDefault();
675
+ }
676
+ };
677
+ const onContextMenu = (e: Event) => {
678
+ if (touchDragRef.current || cancelHoldRef.current) {
679
+ e.preventDefault();
680
+ }
681
+ };
682
+ el.addEventListener("touchmove", onTouchMove, { passive: false });
683
+ el.addEventListener("contextmenu", onContextMenu);
684
+ return () => {
685
+ el.removeEventListener("touchmove", onTouchMove);
686
+ el.removeEventListener("contextmenu", onContextMenu);
687
+ };
688
+ }, []);
689
+
646
690
  const pinch = useRef<Map<number, number>>(new Map());
647
691
  const pinchBase = useRef<{ dist: number; height: number } | null>(null);
648
692
  const onBodyPointerDown = (e: ReactPointerEvent) => {
@@ -717,6 +761,8 @@ function TimeGridInner<T = unknown>(
717
761
  edgeSide.current = 0;
718
762
  pagedRef.current = false;
719
763
  setPaged(false);
764
+ touchDragRef.current = false;
765
+ activeGrabRef.current = null;
720
766
  draggedRef.current = null;
721
767
  dragOrigin.current = null;
722
768
  applyDrag(null);
@@ -725,6 +771,16 @@ function TimeGridInner<T = unknown>(
725
771
  const moveDrag = (e: PointerEvent) => {
726
772
  const d = dragRef.current;
727
773
  if (!d || !dragOrigin.current) return;
774
+ if (
775
+ touchDragRef.current &&
776
+ !d.moved &&
777
+ Math.hypot(
778
+ e.clientX - dragOrigin.current.pointerX,
779
+ e.clientY - dragOrigin.current.pointerY,
780
+ ) <= touchDragThreshold
781
+ ) {
782
+ return;
783
+ }
728
784
  ptr.current = { x: e.clientX, y: e.clientY };
729
785
  // Read the live row height (ref, not the state closure) so a mid-drag zoom
730
786
  // keeps the math aligned with what's on screen.
@@ -784,7 +840,7 @@ function TimeGridInner<T = unknown>(
784
840
  }
785
841
  // Edge auto-advance: dwell near a horizontal edge to page the view. Read the
786
842
  // columns rect live so a mid-drag scroll/layout shift can't stale it.
787
- if (edgeAdvanceEnabled) {
843
+ if (edgeAdvanceEnabled && o.pointerType === "mouse") {
788
844
  const rect = columnsRef.current?.getBoundingClientRect();
789
845
  if (rect && rect.right > rect.left) {
790
846
  const left = rect.left + gutterWidth;
@@ -818,14 +874,20 @@ function TimeGridInner<T = unknown>(
818
874
  const d = dragRef.current;
819
875
  if (!d) return;
820
876
  try {
821
- (e.target as HTMLElement)?.releasePointerCapture?.(e.pointerId);
877
+ activeGrabRef.current?.box.releasePointerCapture?.(e.pointerId);
822
878
  } catch {
823
879
  // Best-effort release; ignore if the capture was never granted.
824
880
  }
825
881
  const held = draggedRef.current;
826
882
  if (!d.moved) {
883
+ const wasTouch = touchDragRef.current;
884
+ const tapBox = activeGrabRef.current?.box ?? null;
827
885
  finishDrag();
828
- held?.onPress();
886
+ if (wasTouch) {
887
+ tappedRef.current = tapBox;
888
+ } else {
889
+ held?.onPress();
890
+ }
829
891
  return;
830
892
  }
831
893
  const origin = dragOrigin.current;
@@ -876,25 +938,25 @@ function TimeGridInner<T = unknown>(
876
938
  // `continues*` flags are the same type, so passing them positionally invites a
877
939
  // silent transposition.
878
940
  const beginDrag = (
879
- e: ReactPointerEvent,
941
+ e: EventGrab,
880
942
  pe: PositionedEvent<T>,
881
943
  key: string,
882
944
  kind: "move" | "resize" | "resize-start",
883
945
  dayIndex: number,
884
946
  onPress?: () => void,
885
947
  ) => {
886
- if (!onDragEvent) return;
887
948
  const { event, startHours, durationHours, continuesBefore, continuesAfter } = pe;
888
- e.stopPropagation();
889
949
  try {
890
- (e.target as HTMLElement).setPointerCapture?.(e.pointerId);
950
+ e.box.setPointerCapture?.(e.pointerId);
891
951
  } catch {
892
952
  // Pointer capture is best-effort; some environments reject it.
893
953
  }
954
+ touchDragRef.current = e.pointerType !== "mouse";
955
+ activeGrabRef.current = e;
894
956
  // The event box sits inside its day column, so the parent's width is one day;
895
957
  // columns are equal-width, so measuring one is enough. Resizes never move
896
958
  // across days, so 0 is fine there.
897
- const boxEl = e.currentTarget as HTMLElement;
959
+ const boxEl = e.box;
898
960
  const column = kind === "move" ? boxEl.parentElement : null;
899
961
  const dayWidth = column ? column.getBoundingClientRect().width : 0;
900
962
  const boxRect = kind === "move" ? boxEl.getBoundingClientRect() : null;
@@ -902,6 +964,7 @@ function TimeGridInner<T = unknown>(
902
964
  dragOrigin.current = {
903
965
  pointerX: e.clientX,
904
966
  pointerY: e.clientY,
967
+ pointerType: e.pointerType,
905
968
  startHours,
906
969
  durationHours,
907
970
  dayIndex,
@@ -940,26 +1003,98 @@ function TimeGridInner<T = unknown>(
940
1003
  // columns unmounting on a page change (the dragged box's own node disappears).
941
1004
  // Detach any prior set first so a second beginDrag can't leak listeners.
942
1005
  detachDocListeners();
943
- const handlers = { move: moveDrag, up: endDrag, cancel: cancelDrag };
1006
+ const handlers = {
1007
+ move: (event: PointerEvent) => {
1008
+ if (event.pointerId === e.pointerId) {
1009
+ moveDrag(event);
1010
+ }
1011
+ },
1012
+ up: (event: PointerEvent) => {
1013
+ if (event.pointerId === e.pointerId) {
1014
+ endDrag(event);
1015
+ }
1016
+ },
1017
+ cancel: (event: PointerEvent) => {
1018
+ if (event.pointerId === e.pointerId) {
1019
+ cancelDrag();
1020
+ }
1021
+ },
1022
+ };
944
1023
  docHandlersRef.current = handlers;
945
1024
  document.addEventListener("pointermove", handlers.move);
946
1025
  document.addEventListener("pointerup", handlers.up);
947
1026
  document.addEventListener("pointercancel", handlers.cancel);
948
1027
  };
949
1028
 
1029
+ const pressEvent = (
1030
+ e: ReactPointerEvent<HTMLElement>,
1031
+ pe: PositionedEvent<T>,
1032
+ key: string,
1033
+ kind: "move" | "resize" | "resize-start",
1034
+ dayIndex: number,
1035
+ onPress?: () => void,
1036
+ ) => {
1037
+ if (!onDragEvent || e.button > 0) {
1038
+ return;
1039
+ }
1040
+ e.stopPropagation();
1041
+ const hadPendingHold = cancelHoldRef.current !== null;
1042
+ cancelHoldRef.current?.();
1043
+ tappedRef.current = null;
1044
+ if (hadPendingHold || activeGrabRef.current || (e.pointerType !== "mouse" && !e.isPrimary)) {
1045
+ return;
1046
+ }
1047
+ const grab: EventGrab = {
1048
+ box: e.currentTarget,
1049
+ pointerId: e.pointerId,
1050
+ pointerType: e.pointerType,
1051
+ clientX: e.clientX,
1052
+ clientY: e.clientY,
1053
+ };
1054
+ if (e.pointerType === "mouse") {
1055
+ beginDrag(grab, pe, key, kind, dayIndex, onPress);
1056
+ return;
1057
+ }
1058
+ cancelHoldRef.current = waitForHold(
1059
+ grab,
1060
+ touchDragDelay,
1061
+ touchDragThreshold,
1062
+ () => {
1063
+ cancelHoldRef.current = null;
1064
+ beginDrag(grab, pe, key, kind, dayIndex, onPress);
1065
+ },
1066
+ () => {
1067
+ cancelHoldRef.current = null;
1068
+ tappedRef.current = grab.box;
1069
+ },
1070
+ () => {
1071
+ cancelHoldRef.current = null;
1072
+ },
1073
+ );
1074
+ };
1075
+
950
1076
  // Remove any lingering document listeners / dwell timer if we unmount mid-drag.
951
1077
  useEffect(
952
1078
  () => () => {
1079
+ cancelHoldRef.current?.();
953
1080
  detachDocListeners();
954
1081
  clearEdgeTimer();
955
1082
  },
956
1083
  [],
957
1084
  );
958
1085
 
1086
+ useEffect(() => {
1087
+ cancelHoldRef.current?.();
1088
+ }, [date, events, onDragEvent]);
1089
+
959
1090
  const pxFromTop = (el: HTMLElement, clientY: number) => clientY - el.getBoundingClientRect().top;
960
1091
  const beginCreate = (e: ReactPointerEvent, dayIndex: number) => {
961
1092
  // Mouse / pen only: on touch the column must stay free to scroll the grid.
962
1093
  // Only from the column background, primary button, never on an event.
1094
+ cellTouchRef.current =
1095
+ e.pointerType === "touch" && e.target === e.currentTarget
1096
+ ? { pointerId: e.pointerId, x: e.clientX, y: e.clientY }
1097
+ : null;
963
1098
  if (!cellEnabled || e.pointerType === "touch") return;
964
1099
  if (e.target !== e.currentTarget || e.button > 0) return;
965
1100
  const el = e.currentTarget as HTMLElement;
@@ -973,6 +1108,14 @@ function TimeGridInner<T = unknown>(
973
1108
  setCreateBox({ dayIndex, topPx: startPx, heightPx: 0 });
974
1109
  };
975
1110
  const moveCreate = (e: ReactPointerEvent) => {
1111
+ const touch = cellTouchRef.current;
1112
+ if (
1113
+ touch &&
1114
+ e.pointerId === touch.pointerId &&
1115
+ Math.hypot(e.clientX - touch.x, e.clientY - touch.y) > CELL_TOUCH_SLOP_PX
1116
+ ) {
1117
+ cellTouchRef.current = null;
1118
+ }
976
1119
  const o = createOrigin.current;
977
1120
  if (!o) return;
978
1121
  const cur = pxFromTop(o.el, e.clientY);
@@ -1004,9 +1147,23 @@ function TimeGridInner<T = unknown>(
1004
1147
  createOrigin.current = null;
1005
1148
  setCreateBox(null);
1006
1149
  };
1150
+ const tapCell = (e: ReactMouseEvent<HTMLDivElement>, dayIndex: number) => {
1151
+ const touch = cellTouchRef.current;
1152
+ cellTouchRef.current = null;
1153
+ const day = days[dayIndex];
1154
+ if (!touch || !onPressCell || !day || e.target !== e.currentTarget) {
1155
+ return;
1156
+ }
1157
+ const px = pxFromTop(e.currentTarget, e.clientY);
1158
+ const at = cellRangeFromDrag(day, px, px, hourHeightRef.current, windowStart, snapMinutes);
1159
+ if (at) {
1160
+ onPressCell(at.start);
1161
+ }
1162
+ };
1007
1163
  // A gesture the browser/OS cancels (scroll takeover, etc.) must not commit a
1008
1164
  // create — just drop the in-progress state.
1009
1165
  const cancelCreate = () => {
1166
+ cellTouchRef.current = null;
1010
1167
  createOrigin.current = null;
1011
1168
  setCreateBox(null);
1012
1169
  };
@@ -1470,6 +1627,7 @@ function TimeGridInner<T = unknown>(
1470
1627
  onPointerMove={cellEnabled ? moveCreate : undefined}
1471
1628
  onPointerUp={cellEnabled ? endCreate : undefined}
1472
1629
  onPointerCancel={cellEnabled ? cancelCreate : undefined}
1630
+ onClick={cellEnabled ? (e) => tapCell(e, dayIndex) : undefined}
1473
1631
  {...dataState({ "data-today": getIsToday(day), "data-weekend": isWeekend(day) })}
1474
1632
  {...slot("dayColumn", {
1475
1633
  base: { flex: 1, position: "relative" },
@@ -1639,10 +1797,22 @@ function TimeGridInner<T = unknown>(
1639
1797
  // remounting on a page change.
1640
1798
  onPointerDown={
1641
1799
  canMove
1642
- ? (e) => beginDrag(e, pe, key, "move", dayIndex, onPress)
1800
+ ? (e) => pressEvent(e, pe, key, "move", dayIndex, onPress)
1643
1801
  : undefined
1644
1802
  }
1645
- onClick={canMove ? undefined : onPress}
1803
+ onClick={
1804
+ canMove
1805
+ ? (e) => {
1806
+ if (
1807
+ e.detail === 0 ||
1808
+ (tappedRef.current && e.currentTarget.contains(tappedRef.current))
1809
+ ) {
1810
+ tappedRef.current = null;
1811
+ onPress();
1812
+ }
1813
+ }
1814
+ : onPress
1815
+ }
1646
1816
  {...dataState({ "data-dragging": !!active && !hiddenForMove })}
1647
1817
  {...slot("event", {
1648
1818
  base: {
@@ -1656,7 +1826,9 @@ function TimeGridInner<T = unknown>(
1656
1826
  left: `calc(${pe.column * widthPct}% + ${eventGap}px)`,
1657
1827
  width: `calc(${widthPct}% - ${eventGap * 2}px)`,
1658
1828
  cursor: canMove ? "grab" : "pointer",
1659
- touchAction: canMove ? "none" : "auto",
1829
+ touchAction: canMove ? "pan-y" : "auto",
1830
+ userSelect: canMove ? "none" : undefined,
1831
+ WebkitTouchCallout: canMove ? "none" : undefined,
1660
1832
  zIndex: active ? 3 : 1,
1661
1833
  opacity: active ? 0.85 : 1,
1662
1834
  visibility: hiddenForMove ? "hidden" : undefined,
@@ -1679,8 +1851,7 @@ function TimeGridInner<T = unknown>(
1679
1851
  {canResize && !pe.continuesBefore ? (
1680
1852
  <div
1681
1853
  onPointerDown={(e) => {
1682
- e.stopPropagation();
1683
- beginDrag(
1854
+ pressEvent(
1684
1855
  e,
1685
1856
  pe,
1686
1857
  key,
@@ -1696,7 +1867,7 @@ function TimeGridInner<T = unknown>(
1696
1867
  top: 0,
1697
1868
  height: 8,
1698
1869
  cursor: "ns-resize",
1699
- touchAction: "none",
1870
+ touchAction: "pan-y",
1700
1871
  }}
1701
1872
  />
1702
1873
  ) : null}
@@ -1708,8 +1879,7 @@ function TimeGridInner<T = unknown>(
1708
1879
  {canResize && !pe.continuesAfter ? (
1709
1880
  <div
1710
1881
  onPointerDown={(e) => {
1711
- e.stopPropagation();
1712
- beginDrag(
1882
+ pressEvent(
1713
1883
  e,
1714
1884
  pe,
1715
1885
  key,
@@ -1725,7 +1895,7 @@ function TimeGridInner<T = unknown>(
1725
1895
  bottom: 0,
1726
1896
  height: 8,
1727
1897
  cursor: "ns-resize",
1728
- touchAction: "none",
1898
+ touchAction: "pan-y",
1729
1899
  }}
1730
1900
  />
1731
1901
  ) : null}
package/src/touch.ts ADDED
@@ -0,0 +1,61 @@
1
+ export type EventGrab = {
2
+ readonly box: HTMLElement;
3
+ readonly pointerId: number;
4
+ readonly pointerType: string;
5
+ readonly clientX: number;
6
+ readonly clientY: number;
7
+ };
8
+
9
+ export function waitForHold(
10
+ grab: EventGrab,
11
+ delay: number,
12
+ threshold: number,
13
+ onHold: () => void,
14
+ onTap: () => void,
15
+ onCancel: () => void,
16
+ ): () => void {
17
+ const detach = () => {
18
+ clearTimeout(timer);
19
+ document.removeEventListener("pointermove", move);
20
+ document.removeEventListener("pointerup", up);
21
+ document.removeEventListener("pointercancel", cancelPointer);
22
+ document.removeEventListener("pointerdown", anotherPointer);
23
+ };
24
+ const cancel = () => {
25
+ detach();
26
+ onCancel();
27
+ };
28
+ const move = (event: PointerEvent) => {
29
+ if (
30
+ event.pointerId === grab.pointerId &&
31
+ Math.hypot(event.clientX - grab.clientX, event.clientY - grab.clientY) > threshold
32
+ ) {
33
+ cancel();
34
+ }
35
+ };
36
+ const up = (event: PointerEvent) => {
37
+ if (event.pointerId === grab.pointerId) {
38
+ detach();
39
+ onTap();
40
+ }
41
+ };
42
+ const cancelPointer = (event: PointerEvent) => {
43
+ if (event.pointerId === grab.pointerId) {
44
+ cancel();
45
+ }
46
+ };
47
+ const anotherPointer = (event: PointerEvent) => {
48
+ if (event.pointerId !== grab.pointerId) {
49
+ cancel();
50
+ }
51
+ };
52
+ const timer = setTimeout(() => {
53
+ detach();
54
+ onHold();
55
+ }, delay);
56
+ document.addEventListener("pointermove", move);
57
+ document.addEventListener("pointerup", up);
58
+ document.addEventListener("pointercancel", cancelPointer);
59
+ document.addEventListener("pointerdown", anotherPointer);
60
+ return cancel;
61
+ }