@gobrand/calendar-core 0.0.15 → 0.0.17

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/dist/index.cjs CHANGED
@@ -557,7 +557,8 @@ function createCalendar(options) {
557
557
  getWeek: getWeekImpl,
558
558
  getDay: getDayImpl,
559
559
  getTitle(view, locales, options2) {
560
- switch (view) {
560
+ const effectiveView = view ?? store.state.currentView ?? defaultView;
561
+ switch (effectiveView) {
561
562
  case "month": {
562
563
  const month = getMonthImpl();
563
564
  const date = month.month.toPlainDate({ day: 1 });
@@ -594,6 +595,8 @@ function createCalendar(options) {
594
595
  ...options2
595
596
  });
596
597
  }
598
+ default:
599
+ throw new Error(`Unknown view: ${effectiveView}`);
597
600
  }
598
601
  },
599
602
  getState() {
@@ -622,7 +625,8 @@ function createCalendar(options) {
622
625
  }));
623
626
  },
624
627
  next(view) {
625
- switch (view) {
628
+ const effectiveView = view ?? store.state.currentView ?? defaultView;
629
+ switch (effectiveView) {
626
630
  case "month":
627
631
  nextMonthImpl();
628
632
  break;
@@ -635,7 +639,8 @@ function createCalendar(options) {
635
639
  }
636
640
  },
637
641
  previous(view) {
638
- switch (view) {
642
+ const effectiveView = view ?? store.state.currentView ?? defaultView;
643
+ switch (effectiveView) {
639
644
  case "month":
640
645
  previousMonthImpl();
641
646
  break;
package/dist/index.d.cts CHANGED
@@ -115,13 +115,13 @@ type ValidViews<Options> = Options extends {
115
115
  views: infer V;
116
116
  } ? keyof V & string : never;
117
117
  type BaseCalendarMethods<Options> = {
118
- getTitle(view: ValidViews<Options>, locales?: Temporal.LocalesArgument, options?: globalThis.Intl.DateTimeFormatOptions): string;
118
+ getTitle(view?: ValidViews<Options>, locales?: Temporal.LocalesArgument, options?: globalThis.Intl.DateTimeFormatOptions): string;
119
119
  getState(): CalendarState;
120
120
  setState(updater: CalendarState | ((old: CalendarState) => Partial<CalendarState>)): void;
121
121
  goToToday(): void;
122
122
  goToDate(date: Temporal.PlainDate): void;
123
- next(view: ValidViews<Options>): void;
124
- previous(view: ValidViews<Options>): void;
123
+ next(view?: ValidViews<Options>): void;
124
+ previous(view?: ValidViews<Options>): void;
125
125
  views: ReadonlyArray<ValidViews<Options>>;
126
126
  currentView: ValidViews<Options>;
127
127
  setCurrentView(view: ValidViews<Options>): void;
package/dist/index.d.ts CHANGED
@@ -115,13 +115,13 @@ type ValidViews<Options> = Options extends {
115
115
  views: infer V;
116
116
  } ? keyof V & string : never;
117
117
  type BaseCalendarMethods<Options> = {
118
- getTitle(view: ValidViews<Options>, locales?: Temporal.LocalesArgument, options?: globalThis.Intl.DateTimeFormatOptions): string;
118
+ getTitle(view?: ValidViews<Options>, locales?: Temporal.LocalesArgument, options?: globalThis.Intl.DateTimeFormatOptions): string;
119
119
  getState(): CalendarState;
120
120
  setState(updater: CalendarState | ((old: CalendarState) => Partial<CalendarState>)): void;
121
121
  goToToday(): void;
122
122
  goToDate(date: Temporal.PlainDate): void;
123
- next(view: ValidViews<Options>): void;
124
- previous(view: ValidViews<Options>): void;
123
+ next(view?: ValidViews<Options>): void;
124
+ previous(view?: ValidViews<Options>): void;
125
125
  views: ReadonlyArray<ValidViews<Options>>;
126
126
  currentView: ValidViews<Options>;
127
127
  setCurrentView(view: ValidViews<Options>): void;
package/dist/index.js CHANGED
@@ -503,7 +503,8 @@ function createCalendar(options) {
503
503
  getWeek: getWeekImpl,
504
504
  getDay: getDayImpl,
505
505
  getTitle(view, locales, options2) {
506
- switch (view) {
506
+ const effectiveView = view ?? store.state.currentView ?? defaultView;
507
+ switch (effectiveView) {
507
508
  case "month": {
508
509
  const month = getMonthImpl();
509
510
  const date = month.month.toPlainDate({ day: 1 });
@@ -540,6 +541,8 @@ function createCalendar(options) {
540
541
  ...options2
541
542
  });
542
543
  }
544
+ default:
545
+ throw new Error(`Unknown view: ${effectiveView}`);
543
546
  }
544
547
  },
545
548
  getState() {
@@ -568,7 +571,8 @@ function createCalendar(options) {
568
571
  }));
569
572
  },
570
573
  next(view) {
571
- switch (view) {
574
+ const effectiveView = view ?? store.state.currentView ?? defaultView;
575
+ switch (effectiveView) {
572
576
  case "month":
573
577
  nextMonthImpl();
574
578
  break;
@@ -581,7 +585,8 @@ function createCalendar(options) {
581
585
  }
582
586
  },
583
587
  previous(view) {
584
- switch (view) {
588
+ const effectiveView = view ?? store.state.currentView ?? defaultView;
589
+ switch (effectiveView) {
585
590
  case "month":
586
591
  previousMonthImpl();
587
592
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobrand/calendar-core",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Lightweight utility library for building calendars using the Temporal API",
5
5
  "private": false,
6
6
  "publishConfig": {