@super-calendar/solid 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/solid",
3
- "version": "2.16.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.16.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
@@ -1,6 +1,7 @@
1
1
  import { type JSX } from "@solidjs/web";
2
2
  import type { CalendarHandle, CalendarLabels } from "@super-calendar/core/vanilla";
3
3
  import {
4
+ buildMultiWeekGrid,
4
5
  type BusinessHours,
5
6
  type BusinessHoursBand,
6
7
  type CalendarEvent,
@@ -10,6 +11,10 @@ import {
10
11
  type DateSelectionConstraints,
11
12
  type EventAccessibilityLabeler,
12
13
  eventsInTimeZone,
14
+ fromZonedRange,
15
+ fromZonedTime,
16
+ zonedDragBounds,
17
+ zonedEventSource,
13
18
  expandRecurringEvents,
14
19
  getViewDays,
15
20
  type WeekdayFormat,
@@ -18,6 +23,7 @@ import {
18
23
  import {
19
24
  addDays,
20
25
  addMonths,
26
+ addWeeks,
21
27
  addYears,
22
28
  endOfDay,
23
29
  endOfMonth,
@@ -32,6 +38,7 @@ import {
32
38
  import { type Component, createMemo, onSettled } from "solid-js";
33
39
  import { Agenda, type AgendaSlot, type SolidAgendaEvent } from "./Agenda";
34
40
  import { MonthView, type MonthViewSlot, type SolidMonthEvent } from "./MonthView";
41
+ import { MultiWeekView } from "./MultiWeekView";
35
42
  import { withDefaults } from "./props";
36
43
  import type { SlotStyleProps } from "./slots";
37
44
  import { css, type CSSProperties, type DomKeyboardEvent, type ElementRef } from "./styles";
@@ -76,19 +83,24 @@ export interface CalendarProps<T = unknown>
76
83
  /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
77
84
  hiddenDays?: number[];
78
85
  /**
79
- * Fixed "now" instant for the current-time indicator (doesn't tick), e.g. a
80
- * server-synced clock. Defaults to the device clock, shifted into `timeZone`
81
- * 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.
82
90
  */
83
91
  now?: Date;
84
92
  /** Column count for `mode="custom"`. */
85
93
  numberOfDays?: number;
94
+ /** Consecutive full week rows for `mode="multiweek"` (default 2). */
95
+ numberOfWeeks?: number;
86
96
  /** date-fns locale for titles, headers, and time labels. */
87
97
  locale?: Locale;
88
98
  /**
89
99
  * Display events in this IANA time zone (e.g. `"America/New_York"`), DST-correct
90
100
  * and independent of the device zone. Display-only: it shifts the wall-clock the
91
- * 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`.
92
104
  */
93
105
  timeZone?: string;
94
106
  /** Theme overrides; falls back to the default light theme. */
@@ -185,8 +197,9 @@ export interface CalendarProps<T = unknown>
185
197
  */
186
198
  onCreateEvent?: (start: Date, end: Date) => void;
187
199
  /**
188
- * A component that draws content inside the time-grid drag-to-create preview;
189
- * 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.
190
203
  */
191
204
  renderCreateGhost?: Component<CreateGhostArgs>;
192
205
  /** Fires when an event drag begins. */
@@ -197,7 +210,7 @@ export interface CalendarProps<T = unknown>
197
210
  * days dragged so the time of day and duration are kept.
198
211
  */
199
212
  onDragEvent?: (event: CalendarEvent<T>, start: Date, end: Date) => void | boolean;
200
- /** 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. */
201
214
  getEventId?: (event: CalendarEvent<T>) => string | number;
202
215
  /** Tap a day's column header. */
203
216
  onPressDateHeader?: (day: Date) => void;
@@ -276,7 +289,12 @@ function expansionRange(
276
289
  date: Date,
277
290
  weekStartsOn: WeekStartsOn,
278
291
  numberOfDays: number | undefined,
292
+ numberOfWeeks: number,
279
293
  ): [Date, Date] {
294
+ if (mode === "multiweek") {
295
+ const { period } = buildMultiWeekGrid(date, { weekStartsOn, numberOfWeeks });
296
+ return [period.start, endOfDay(addDays(period.endExclusive, -1))];
297
+ }
280
298
  if (mode === "month") {
281
299
  return [
282
300
  startOfWeek(startOfMonth(date), {
@@ -314,7 +332,9 @@ function pageStep(
314
332
  direction: number,
315
333
  weekStartsOn: WeekStartsOn,
316
334
  numberOfDays: number | undefined,
335
+ numberOfWeeks: number,
317
336
  ): Date {
337
+ if (mode === "multiweek") return addWeeks(date, direction * numberOfWeeks);
318
338
  if (mode === "year") return addYears(date, direction);
319
339
  if (mode === "month") return addMonths(date, direction);
320
340
  if (mode === "schedule") return addDays(date, direction * 7);
@@ -342,6 +362,7 @@ export function Calendar<T = unknown>(
342
362
  {
343
363
  mode: "week",
344
364
  weekStartsOn: 0,
365
+ numberOfWeeks: 2,
345
366
  } satisfies Partial<
346
367
  CalendarProps<T> & {
347
368
  ref?: (handle: CalendarHandle) => void;
@@ -363,36 +384,110 @@ export function Calendar<T = unknown>(
363
384
  const displayEvents = createMemo(() => {
364
385
  let out: CalendarEvent<T>[] = props.events ?? EMPTY_EVENTS;
365
386
  if (out.some((e) => e.recurrence)) {
366
- let [start, end] = expansionRange(
387
+ const [start, end] = expansionRange(
367
388
  props.mode,
368
389
  props.date,
369
390
  props.weekStartsOn,
370
391
  props.numberOfDays,
392
+ props.numberOfWeeks,
371
393
  );
372
- // A display zone shifts each occurrence's wall-clock by up to ~a day, which
373
- // can move an edge occurrence into a visible column; widen so it's generated.
374
- if (props.timeZone) {
375
- start = addDays(start, -1);
376
- end = addDays(end, 1);
377
- }
378
- 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);
379
402
  }
380
403
  if (props.timeZone) out = eventsInTimeZone(out, props.timeZone);
381
404
  return out;
382
405
  // `date.getTime()`: recompute on the instant, not a re-created Date identity.
383
406
  });
384
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
+
385
466
  // PageDown / PageUp page the calendar when the consumer opts in with
386
467
  // `onChangeDate`; keydowns bubble up from the focused grid to this handler.
387
468
  const handlePageKeys = (e: DomKeyboardEvent) => {
388
469
  if (!props.onChangeDate) return;
389
470
  if (e.key === "PageDown")
390
471
  props.onChangeDate(
391
- pageStep(props.mode, props.date, 1, props.weekStartsOn, props.numberOfDays),
472
+ pageStep(
473
+ props.mode,
474
+ props.date,
475
+ 1,
476
+ props.weekStartsOn,
477
+ props.numberOfDays,
478
+ props.numberOfWeeks,
479
+ ),
392
480
  );
393
481
  else if (e.key === "PageUp")
394
482
  props.onChangeDate(
395
- pageStep(props.mode, props.date, -1, props.weekStartsOn, props.numberOfDays),
483
+ pageStep(
484
+ props.mode,
485
+ props.date,
486
+ -1,
487
+ props.weekStartsOn,
488
+ props.numberOfDays,
489
+ props.numberOfWeeks,
490
+ ),
396
491
  );
397
492
  else return;
398
493
  e.preventDefault();
@@ -408,6 +503,8 @@ export function Calendar<T = unknown>(
408
503
  weekStartsOn={props.weekStartsOn}
409
504
  hiddenDays={props.hiddenDays}
410
505
  locale={props.locale}
506
+ now={props.now}
507
+ timeZone={props.timeZone}
411
508
  labels={props.labels}
412
509
  theme={props.theme}
413
510
  className={props.className}
@@ -437,6 +534,8 @@ export function Calendar<T = unknown>(
437
534
  <Agenda<T>
438
535
  events={displayEvents()}
439
536
  locale={props.locale}
537
+ now={props.now}
538
+ timeZone={props.timeZone}
440
539
  ampm={props.ampm}
441
540
  theme={props.theme}
442
541
  height={props.height}
@@ -447,7 +546,7 @@ export function Calendar<T = unknown>(
447
546
  styles={props.styles}
448
547
  renderEvent={props.renderScheduleEvent}
449
548
  eventAccessibilityLabel={props.eventAccessibilityLabel}
450
- onPressEvent={props.onPressEvent}
549
+ onPressEvent={zoned.onPressEvent()}
451
550
  onPressDay={props.onPressDay}
452
551
  />
453
552
  );
@@ -461,6 +560,8 @@ export function Calendar<T = unknown>(
461
560
  weekdayFormat={props.weekdayFormat}
462
561
  highlightWeekends={props.highlightWeekends}
463
562
  locale={props.locale}
563
+ now={props.now}
564
+ timeZone={props.timeZone}
464
565
  labels={props.labels}
465
566
  theme={props.theme}
466
567
  className={props.className}
@@ -483,13 +584,60 @@ export function Calendar<T = unknown>(
483
584
  onPressDay={props.onPressDay}
484
585
  onPressCell={props.onPressCell}
485
586
  onCreateEvent={props.onCreateEvent}
587
+ renderCreateGhost={props.renderCreateGhost}
486
588
  onSelectDrag={props.onSelectDrag}
487
- onDragEvent={props.onDragEvent}
488
- onDragStart={props.onDragStart}
589
+ onDragEvent={zoned.onDragEvent()}
590
+ onDragStart={zoned.onDragStart()}
489
591
  eventStartEditable={props.eventStartEditable}
490
592
  eventOverlap={props.eventOverlap}
491
- onPressEvent={props.onPressEvent}
492
- onPressMore={props.onPressMore}
593
+ onPressEvent={zoned.onPressEvent()}
594
+ onPressMore={zoned.onPressMore()}
595
+ renderEvent={props.renderMonthEvent}
596
+ eventAccessibilityLabel={props.eventAccessibilityLabel}
597
+ />
598
+ );
599
+ } else if (mode === "multiweek") {
600
+ return (
601
+ <MultiWeekView<T>
602
+ date={props.date}
603
+ numberOfWeeks={props.numberOfWeeks}
604
+ events={displayEvents()}
605
+ weekStartsOn={props.weekStartsOn}
606
+ hiddenDays={props.hiddenDays}
607
+ weekdayFormat={props.weekdayFormat}
608
+ highlightWeekends={props.highlightWeekends}
609
+ locale={props.locale}
610
+ now={props.now}
611
+ timeZone={props.timeZone}
612
+ labels={props.labels}
613
+ theme={props.theme}
614
+ className={props.className}
615
+ style={{ height: props.height, ...props.style }}
616
+ classNames={props.classNames}
617
+ styles={props.styles}
618
+ maxVisibleEventCount={props.maxVisibleEventCount}
619
+ chipHeight={props.chipHeight}
620
+ chipGap={props.chipGap}
621
+ moreLabel={props.moreLabel}
622
+ showTitle={props.showTitle}
623
+ fillCellOnSelection={props.fillCellOnSelection}
624
+ selectedRange={props.selectedRange}
625
+ selectedDates={props.selectedDates}
626
+ minDate={props.minDate}
627
+ maxDate={props.maxDate}
628
+ isDateDisabled={props.isDateDisabled}
629
+ keyboardDayNavigation={props.keyboardDayNavigation}
630
+ onPressDay={props.onPressDay}
631
+ onPressCell={props.onPressCell}
632
+ onCreateEvent={props.onCreateEvent}
633
+ renderCreateGhost={props.renderCreateGhost}
634
+ onSelectDrag={props.onSelectDrag}
635
+ onDragEvent={zoned.onDragEvent()}
636
+ onDragStart={zoned.onDragStart()}
637
+ eventStartEditable={props.eventStartEditable}
638
+ eventOverlap={props.eventOverlap}
639
+ onPressEvent={zoned.onPressEvent()}
640
+ onPressMore={zoned.onPressMore()}
493
641
  renderEvent={props.renderMonthEvent}
494
642
  eventAccessibilityLabel={props.eventAccessibilityLabel}
495
643
  />
@@ -539,12 +687,12 @@ export function Calendar<T = unknown>(
539
687
  dragStepMinutes={props.dragStepMinutes}
540
688
  touchDragDelay={props.touchDragDelay}
541
689
  touchDragThreshold={props.touchDragThreshold}
542
- onPressEvent={props.onPressEvent}
543
- onPressCell={props.onPressCell}
544
- onCreateEvent={props.onCreateEvent}
690
+ onPressEvent={zoned.onPressEvent()}
691
+ onPressCell={zoned.onPressTime()}
692
+ onCreateEvent={zoned.onCreateTimed()}
545
693
  renderCreateGhost={props.renderCreateGhost}
546
- onDragStart={props.onDragStart}
547
- onDragEvent={props.onDragEvent}
694
+ onDragStart={zoned.onDragStart()}
695
+ onDragEvent={zoned.onDragEvent()}
548
696
  getEventId={props.getEventId}
549
697
  onChangeDate={props.onChangeDate}
550
698
  onPressDateHeader={props.onPressDateHeader}