@super-calendar/solid 2.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/solid",
3
- "version": "2.17.0",
3
+ "version": "2.18.0",
4
4
  "description": "Solid 2 calendar and date picker with virtualized views, keyboard navigation, and pointer gestures.",
5
5
  "keywords": [
6
6
  "calendar",
@@ -42,7 +42,7 @@
42
42
  "access": "public"
43
43
  },
44
44
  "dependencies": {
45
- "@super-calendar/core": "^2.17.0",
45
+ "@super-calendar/core": "^2.18.0",
46
46
  "csstype": "^3.1.0"
47
47
  },
48
48
  "devDependencies": {
package/src/Agenda.tsx CHANGED
@@ -3,6 +3,7 @@ import type { CalendarEvent, EventAccessibilityLabeler } from "@super-calendar/c
3
3
  import {
4
4
  eventTimeLabel,
5
5
  getIsToday,
6
+ nowInTimeZone,
6
7
  isAllDayEvent,
7
8
  isBackgroundEvent,
8
9
  } from "@super-calendar/core/vanilla";
@@ -43,6 +44,13 @@ export interface AgendaProps<T = unknown> extends SlotStyleProps<AgendaSlot> {
43
44
  events: CalendarEvent<T>[];
44
45
  /** date-fns locale for the day headers and time labels. */
45
46
  locale?: Locale;
47
+ /**
48
+ * The instant whose calendar day is highlighted as today. Defaults to the
49
+ * device clock, and is read in `timeZone` when one is set.
50
+ */
51
+ now?: Date;
52
+ /** Highlight today as it is in this IANA time zone (default: the device's). */
53
+ timeZone?: string;
46
54
  /** Render times in 12-hour AM/PM (default false, 24h). */
47
55
  ampm?: boolean;
48
56
  /** Highlight this date's header instead of the real "today". */
@@ -176,9 +184,17 @@ export function Agenda<T = unknown>(incoming: AgendaProps<T>): JSX.Element {
176
184
  });
177
185
  return out;
178
186
  });
187
+ // One memo for every header, yielding the day (not the instant) so the headers
188
+ // re-run only when it changes. Tracking `events` re-reads the clock with new rows.
189
+ const todayKey = createMemo(() => {
190
+ void props.events;
191
+ return startOfDay(nowInTimeZone(props.now, props.timeZone)).getTime();
192
+ });
179
193
  const Header = (row: { date: Date }): JSX.Element => {
180
194
  const highlighted = createMemo(() =>
181
- props.activeDate ? isSameDay(row.date, props.activeDate) : getIsToday(row.date),
195
+ props.activeDate
196
+ ? isSameDay(row.date, props.activeDate)
197
+ : getIsToday(row.date, new Date(todayKey())),
182
198
  );
183
199
  const label = createMemo(() => format(row.date, "EEEE, d LLLL", { locale: props.locale }));
184
200
  const headerProps = createMemo(() =>
package/src/Calendar.tsx CHANGED
@@ -11,6 +11,10 @@ import {
11
11
  type DateSelectionConstraints,
12
12
  type EventAccessibilityLabeler,
13
13
  eventsInTimeZone,
14
+ fromZonedRange,
15
+ fromZonedTime,
16
+ zonedDragBounds,
17
+ zonedEventSource,
14
18
  expandRecurringEvents,
15
19
  getViewDays,
16
20
  type WeekdayFormat,
@@ -79,9 +83,10 @@ export interface CalendarProps<T = unknown>
79
83
  /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
80
84
  hiddenDays?: number[];
81
85
  /**
82
- * Fixed "now" instant for the current-time indicator (doesn't tick), e.g. a
83
- * server-synced clock. Defaults to the device clock, shifted into `timeZone`
84
- * when one is set so the line matches the displayed events.
86
+ * Fixed "now" instant for the current-time indicator (doesn't tick) and for
87
+ * the day highlighted as today in every mode, e.g. a server-synced clock.
88
+ * Defaults to the device clock, shifted into `timeZone` when one is set so
89
+ * both match the displayed events.
85
90
  */
86
91
  now?: Date;
87
92
  /** Column count for `mode="custom"`. */
@@ -93,7 +98,9 @@ export interface CalendarProps<T = unknown>
93
98
  /**
94
99
  * Display events in this IANA time zone (e.g. `"America/New_York"`), DST-correct
95
100
  * and independent of the device zone. Display-only: it shifts the wall-clock the
96
- * grid lays out from, it doesn't change your `Date`s. Uses `eventsInTimeZone`.
101
+ * grid lays out from, it doesn't change your `Date`s, and callbacks report your
102
+ * own events and real instants. All-day events stay on their days. Uses
103
+ * `eventsInTimeZone`.
97
104
  */
98
105
  timeZone?: string;
99
106
  /** Theme overrides; falls back to the default light theme. */
@@ -190,8 +197,9 @@ export interface CalendarProps<T = unknown>
190
197
  */
191
198
  onCreateEvent?: (start: Date, end: Date) => void;
192
199
  /**
193
- * A component that draws content inside the time-grid drag-to-create preview;
194
- * see `TimeGrid`'s prop of the same name. Applies to the week/day grid only.
200
+ * A component that draws content inside a creation preview in time-grid, month
201
+ * and multi-week modes. Month rows receive the full all-day range with an
202
+ * exclusive end, once per covered row. Requires onCreateEvent.
195
203
  */
196
204
  renderCreateGhost?: Component<CreateGhostArgs>;
197
205
  /** Fires when an event drag begins. */
@@ -202,7 +210,7 @@ export interface CalendarProps<T = unknown>
202
210
  * days dragged so the time of day and duration are kept.
203
211
  */
204
212
  onDragEvent?: (event: CalendarEvent<T>, start: Date, end: Date) => void | boolean;
205
- /** Stable, unique event identity for the web editing dialog across data refreshes. */
213
+ /** Stable, unique identity for the editing dialog and time-grid all-day bars across data refreshes. */
206
214
  getEventId?: (event: CalendarEvent<T>) => string | number;
207
215
  /** Tap a day's column header. */
208
216
  onPressDateHeader?: (day: Date) => void;
@@ -376,26 +384,85 @@ export function Calendar<T = unknown>(
376
384
  const displayEvents = createMemo(() => {
377
385
  let out: CalendarEvent<T>[] = props.events ?? EMPTY_EVENTS;
378
386
  if (out.some((e) => e.recurrence)) {
379
- let [start, end] = expansionRange(
387
+ const [start, end] = expansionRange(
380
388
  props.mode,
381
389
  props.date,
382
390
  props.weekStartsOn,
383
391
  props.numberOfDays,
384
392
  props.numberOfWeeks,
385
393
  );
386
- // A display zone shifts each occurrence's wall-clock by up to ~a day, which
387
- // can move an edge occurrence into a visible column; widen so it's generated.
388
- if (props.timeZone) {
389
- start = addDays(start, -1);
390
- end = addDays(end, 1);
391
- }
392
- out = expandRecurringEvents(out, start, end);
394
+ // The range is the days on screen, which under a display zone are that
395
+ // zone's days: expand on its clock, over the instants those days cover.
396
+ const timeZone = props.timeZone;
397
+ out = timeZone
398
+ ? expandRecurringEvents(out, fromZonedTime(start, timeZone), fromZonedTime(end, timeZone), {
399
+ timeZone,
400
+ })
401
+ : expandRecurringEvents(out, start, end);
393
402
  }
394
403
  if (props.timeZone) out = eventsInTimeZone(out, props.timeZone);
395
404
  return out;
396
405
  // `date.getTime()`: recompute on the instant, not a re-created Date identity.
397
406
  });
398
407
 
408
+ // With a display zone the views lay out wall-clock copies of the events and
409
+ // report wall-clock dates. Hand back the consumer's own events and real
410
+ // instants. Whole days (`onPressDay`, a month sweep, ...) stay device-local
411
+ // dates, as `date` is, so only the time grid's cell callbacks convert.
412
+ const zoned = {
413
+ onPressEvent: createMemo(() => {
414
+ const handler = props.onPressEvent;
415
+ return handler && props.timeZone
416
+ ? (event: CalendarEvent<T>) => handler(zonedEventSource(event))
417
+ : handler;
418
+ }),
419
+ onDragStart: createMemo(() => {
420
+ const handler = props.onDragStart;
421
+ return handler && props.timeZone
422
+ ? (event: CalendarEvent<T>) => handler(zonedEventSource(event))
423
+ : handler;
424
+ }),
425
+ onDragEvent: createMemo(() => {
426
+ const handler = props.onDragEvent;
427
+ return handler && props.timeZone
428
+ ? (event: CalendarEvent<T>, start: Date, end: Date) => {
429
+ // A time-grid move keeps the event's elapsed duration; a month drop
430
+ // keeps the clock time of both edges.
431
+ const bounds = zonedDragBounds(event, start, end, {
432
+ keepDuration: props.mode !== "month" && props.mode !== "multiweek",
433
+ });
434
+ // An edge dropped into an hour the zone's clock skips can leave no
435
+ // usable span; reject the drop, so the event snaps back.
436
+ if (!bounds) return false;
437
+ return handler(zonedEventSource(event), bounds.start, bounds.end);
438
+ }
439
+ : handler;
440
+ }),
441
+ onPressMore: createMemo(() => {
442
+ const handler = props.onPressMore;
443
+ return handler && props.timeZone
444
+ ? (dayEvents: CalendarEvent<T>[], day: Date) =>
445
+ handler(dayEvents.map(zonedEventSource), day)
446
+ : handler;
447
+ }),
448
+ onPressTime: createMemo(() => {
449
+ const handler = props.onPressCell;
450
+ const timeZone = props.timeZone;
451
+ return handler && timeZone ? (time: Date) => handler(fromZonedTime(time, timeZone)) : handler;
452
+ }),
453
+ onCreateTimed: createMemo(() => {
454
+ const handler = props.onCreateEvent;
455
+ const timeZone = props.timeZone;
456
+ return handler && timeZone
457
+ ? (start: Date, end: Date) => {
458
+ // A sweep that collapses inside a skipped hour creates nothing.
459
+ const range = fromZonedRange(start, end, timeZone);
460
+ if (range) handler(range.start, range.end);
461
+ }
462
+ : handler;
463
+ }),
464
+ };
465
+
399
466
  // PageDown / PageUp page the calendar when the consumer opts in with
400
467
  // `onChangeDate`; keydowns bubble up from the focused grid to this handler.
401
468
  const handlePageKeys = (e: DomKeyboardEvent) => {
@@ -436,6 +503,8 @@ export function Calendar<T = unknown>(
436
503
  weekStartsOn={props.weekStartsOn}
437
504
  hiddenDays={props.hiddenDays}
438
505
  locale={props.locale}
506
+ now={props.now}
507
+ timeZone={props.timeZone}
439
508
  labels={props.labels}
440
509
  theme={props.theme}
441
510
  className={props.className}
@@ -465,6 +534,8 @@ export function Calendar<T = unknown>(
465
534
  <Agenda<T>
466
535
  events={displayEvents()}
467
536
  locale={props.locale}
537
+ now={props.now}
538
+ timeZone={props.timeZone}
468
539
  ampm={props.ampm}
469
540
  theme={props.theme}
470
541
  height={props.height}
@@ -475,7 +546,7 @@ export function Calendar<T = unknown>(
475
546
  styles={props.styles}
476
547
  renderEvent={props.renderScheduleEvent}
477
548
  eventAccessibilityLabel={props.eventAccessibilityLabel}
478
- onPressEvent={props.onPressEvent}
549
+ onPressEvent={zoned.onPressEvent()}
479
550
  onPressDay={props.onPressDay}
480
551
  />
481
552
  );
@@ -489,6 +560,8 @@ export function Calendar<T = unknown>(
489
560
  weekdayFormat={props.weekdayFormat}
490
561
  highlightWeekends={props.highlightWeekends}
491
562
  locale={props.locale}
563
+ now={props.now}
564
+ timeZone={props.timeZone}
492
565
  labels={props.labels}
493
566
  theme={props.theme}
494
567
  className={props.className}
@@ -511,13 +584,14 @@ export function Calendar<T = unknown>(
511
584
  onPressDay={props.onPressDay}
512
585
  onPressCell={props.onPressCell}
513
586
  onCreateEvent={props.onCreateEvent}
587
+ renderCreateGhost={props.renderCreateGhost}
514
588
  onSelectDrag={props.onSelectDrag}
515
- onDragEvent={props.onDragEvent}
516
- onDragStart={props.onDragStart}
589
+ onDragEvent={zoned.onDragEvent()}
590
+ onDragStart={zoned.onDragStart()}
517
591
  eventStartEditable={props.eventStartEditable}
518
592
  eventOverlap={props.eventOverlap}
519
- onPressEvent={props.onPressEvent}
520
- onPressMore={props.onPressMore}
593
+ onPressEvent={zoned.onPressEvent()}
594
+ onPressMore={zoned.onPressMore()}
521
595
  renderEvent={props.renderMonthEvent}
522
596
  eventAccessibilityLabel={props.eventAccessibilityLabel}
523
597
  />
@@ -533,6 +607,8 @@ export function Calendar<T = unknown>(
533
607
  weekdayFormat={props.weekdayFormat}
534
608
  highlightWeekends={props.highlightWeekends}
535
609
  locale={props.locale}
610
+ now={props.now}
611
+ timeZone={props.timeZone}
536
612
  labels={props.labels}
537
613
  theme={props.theme}
538
614
  className={props.className}
@@ -554,13 +630,14 @@ export function Calendar<T = unknown>(
554
630
  onPressDay={props.onPressDay}
555
631
  onPressCell={props.onPressCell}
556
632
  onCreateEvent={props.onCreateEvent}
633
+ renderCreateGhost={props.renderCreateGhost}
557
634
  onSelectDrag={props.onSelectDrag}
558
- onDragEvent={props.onDragEvent}
559
- onDragStart={props.onDragStart}
635
+ onDragEvent={zoned.onDragEvent()}
636
+ onDragStart={zoned.onDragStart()}
560
637
  eventStartEditable={props.eventStartEditable}
561
638
  eventOverlap={props.eventOverlap}
562
- onPressEvent={props.onPressEvent}
563
- onPressMore={props.onPressMore}
639
+ onPressEvent={zoned.onPressEvent()}
640
+ onPressMore={zoned.onPressMore()}
564
641
  renderEvent={props.renderMonthEvent}
565
642
  eventAccessibilityLabel={props.eventAccessibilityLabel}
566
643
  />
@@ -610,12 +687,12 @@ export function Calendar<T = unknown>(
610
687
  dragStepMinutes={props.dragStepMinutes}
611
688
  touchDragDelay={props.touchDragDelay}
612
689
  touchDragThreshold={props.touchDragThreshold}
613
- onPressEvent={props.onPressEvent}
614
- onPressCell={props.onPressCell}
615
- onCreateEvent={props.onCreateEvent}
690
+ onPressEvent={zoned.onPressEvent()}
691
+ onPressCell={zoned.onPressTime()}
692
+ onCreateEvent={zoned.onCreateTimed()}
616
693
  renderCreateGhost={props.renderCreateGhost}
617
- onDragStart={props.onDragStart}
618
- onDragEvent={props.onDragEvent}
694
+ onDragStart={zoned.onDragStart()}
695
+ onDragEvent={zoned.onDragEvent()}
619
696
  getEventId={props.getEventId}
620
697
  onChangeDate={props.onChangeDate}
621
698
  onPressDateHeader={props.onPressDateHeader}