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