@super-calendar/dom 2.16.0 → 2.18.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/YearView.tsx CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  monthCreateRange,
12
12
  daySelectionState,
13
13
  getIsToday,
14
+ nowInTimeZone,
14
15
  filterHiddenDays,
15
16
  getWeekDays,
16
17
  getYearMonths,
@@ -59,6 +60,13 @@ export interface YearViewProps<T = unknown>
59
60
  /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
60
61
  hiddenDays?: number[];
61
62
  locale?: Locale;
63
+ /**
64
+ * The instant whose calendar day is highlighted as today. Defaults to the
65
+ * device clock, and is read in `timeZone` when one is set.
66
+ */
67
+ now?: Date;
68
+ /** Highlight today as it is in this IANA time zone (default: the device's). */
69
+ timeZone?: string;
62
70
  /** Translations for the screen-reader words; omitted keys use English. */
63
71
  labels?: Partial<CalendarLabels>;
64
72
  /** Highlight this date instead of the real "today". */
@@ -111,6 +119,8 @@ export function YearView<T = unknown>({
111
119
  weekStartsOn = 0,
112
120
  hiddenDays,
113
121
  locale,
122
+ now,
123
+ timeZone,
114
124
  labels: labelsProp,
115
125
  activeDate,
116
126
  selectedRange,
@@ -179,6 +189,7 @@ export function YearView<T = unknown>({
179
189
  return () => window.removeEventListener("pointerup", finish);
180
190
  }, [isCreating, onCreateEvent]);
181
191
 
192
+ const today = nowInTimeZone(now, timeZone);
182
193
  const months = useMemo(() => getYearMonths(date), [date]);
183
194
  const weekdayLabels = useMemo(
184
195
  () =>
@@ -294,7 +305,7 @@ export function YearView<T = unknown>({
294
305
  />
295
306
  );
296
307
  }
297
- const isToday = getIsToday(day);
308
+ const isToday = getIsToday(day, today);
298
309
  const isHighlighted = activeDate
299
310
  ? isSameCalendarDay(day, activeDate)
300
311
  : isToday;
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ export {
42
42
  type MonthViewSlot,
43
43
  } from "./MonthView";
44
44
  export { MonthList, type MonthListProps, type MonthListSlot } from "./MonthList";
45
+ export { MultiWeekView, type MultiWeekViewProps } from "./MultiWeekView";
45
46
  export { YearView, type YearViewProps, type YearViewSlot } from "./YearView";
46
47
  export {
47
48
  type Resource,
@@ -101,6 +102,7 @@ export {
101
102
  useNow,
102
103
  useMonthGrid,
103
104
  buildMonthGrid,
105
+ buildMultiWeekGrid,
104
106
  layoutMonthWeek,
105
107
  weekdayFormatToken,
106
108
  type MonthEventSegment,
@@ -109,6 +111,11 @@ export {
109
111
  type MonthGridWeek,
110
112
  type MonthGridWeekday,
111
113
  type MonthWeekEvents,
114
+ type MultiWeekGrid,
115
+ type MultiWeekGridDay,
116
+ type MultiWeekGridInterval,
117
+ type MultiWeekGridOptions,
118
+ type MultiWeekGridWeek,
112
119
  type UseMonthGridOptions,
113
120
  type WeekdayFormat,
114
121
  } from "@super-calendar/core";
package/src/touch.ts CHANGED
@@ -59,3 +59,73 @@ export function waitForHold(
59
59
  document.addEventListener("pointerdown", anotherPointer);
60
60
  return cancel;
61
61
  }
62
+
63
+ /** A quick swipe scrolls; a held pointer owns a date-row drag until release. */
64
+ export function holdDateDrag(
65
+ grab: EventGrab,
66
+ start: () => void,
67
+ move: (clientX: number, clientY: number) => void,
68
+ cancel: () => void,
69
+ release: () => void,
70
+ ): () => void {
71
+ const doc = grab.box.ownerDocument;
72
+ let active = false;
73
+ let finished = false;
74
+ let cancelWait: (() => void) | undefined;
75
+ const detach = () => {
76
+ doc.removeEventListener("pointermove", onMove);
77
+ doc.removeEventListener("pointerup", onUp);
78
+ doc.removeEventListener("pointercancel", onCancel);
79
+ doc.removeEventListener("pointerdown", onAnotherPointer);
80
+ doc.removeEventListener("touchmove", onTouchMove);
81
+ doc.removeEventListener("contextmenu", onContextMenu);
82
+ };
83
+ const stop = () => {
84
+ if (finished) return;
85
+ finished = true;
86
+ detach();
87
+ cancelWait?.();
88
+ cancel();
89
+ release();
90
+ };
91
+ const onMove = (event: PointerEvent) => {
92
+ if (active && event.pointerId === grab.pointerId) move(event.clientX, event.clientY);
93
+ };
94
+ const onUp = (event: PointerEvent) => {
95
+ if (event.pointerId !== grab.pointerId) return;
96
+ finished = true;
97
+ detach();
98
+ release();
99
+ // The view's window pointerup handler commits the current range.
100
+ };
101
+ const onCancel = (event: PointerEvent) => {
102
+ if (event.pointerId === grab.pointerId) stop();
103
+ };
104
+ const onAnotherPointer = (event: PointerEvent) => {
105
+ if (event.pointerId !== grab.pointerId) stop();
106
+ };
107
+ const onTouchMove = (event: TouchEvent) => {
108
+ if (active && event.cancelable) event.preventDefault();
109
+ };
110
+ const onContextMenu = (event: Event) => {
111
+ event.preventDefault();
112
+ };
113
+ doc.addEventListener("pointermove", onMove);
114
+ doc.addEventListener("pointerup", onUp);
115
+ doc.addEventListener("pointercancel", onCancel);
116
+ doc.addEventListener("pointerdown", onAnotherPointer);
117
+ doc.addEventListener("touchmove", onTouchMove, { passive: false });
118
+ doc.addEventListener("contextmenu", onContextMenu);
119
+ cancelWait = waitForHold(
120
+ grab,
121
+ 400,
122
+ 8,
123
+ () => {
124
+ active = true;
125
+ start();
126
+ },
127
+ release,
128
+ stop,
129
+ );
130
+ return stop;
131
+ }