diff --git a/src/@types/api.d.ts b/src/@types/api.d.ts index 11f906c..b75731f 100644 --- a/src/@types/api.d.ts +++ b/src/@types/api.d.ts @@ -1,16 +1,16 @@ import { Moon, Phase, - FcEvent, - FcDate, + CalEvent, + CalDate, LeapDay, - FcEventCategory + CalEventCategory } from "."; declare class API { getCalendars(): Calendar[]; getMoons( - date?: FcDate, + date?: CalDate, name?: string ): Array<{ moon: Moon; phase: Phase; icon: HTMLSpanElement }>; getDay( @@ -28,15 +28,15 @@ declare class API { ): Day; addCategoryToCalendar( - category: FcEventCategory, + category: CalEventCategory, calendar: Calendar | string = this.plugin.defaultCalendar ): Promise; } export type Day = { moons: [Moon, Phase][]; - events: FcEvent[]; - date: FcDate; + events: CalEvent[]; + date: CalDate; longDate: { day: number; month: string; diff --git a/src/main.ts b/src/main.ts index b824c37..e7c6493 100644 --- a/src/main.ts +++ b/src/main.ts @@ -46,13 +46,12 @@ declare module "obsidian" { declare global { interface Window { - CalendariumAPI?: API; + Calendarium?: Calendarium; } } export const MODIFIER_KEY = Platform.isMacOS ? "Meta" : "Control"; export default class Calendarium extends Plugin { - api = new API(); watcher: Watcher; async addNewCalendar(calendar: Calendar, existing?: Calendar) { let shouldParse = @@ -83,6 +82,14 @@ export default class Calendarium extends Plugin { get calendars() { return this.$settingsService.getCalendars(); } + + getAPI(calendarName: string): API { + const store = this.getStore(calendarName); + if (!store) + throw new ReferenceError("No calendar store by that name exists."); + return new API(store); + } + private readonly stores: WeakMap = new WeakMap(); getStore(calendar: string) { if (!calendar) return null; @@ -125,8 +132,8 @@ export default class Calendarium extends Plugin { await this.$settingsService.loadData(); this.watcher = new Watcher(this); - (window["CalendariumAPI"] = this.api) && - this.register(() => delete window["CalendariumAPI"]); + (window["Calendarium"] = this) && + this.register(() => delete window["Calendarium"]); this.registerView( VIEW_TYPE,