Calendarium
repository·main·Indexed 41 days ago
https://github.com/javalent/calendariumAn Obsidian plugin for crafting complex fantasy and science fiction calendars. Version 2.1.0 provides a comprehensive API for managing custom calendar systems, including date translation, event retrieval, seasonal data, and programmatic control of calendar views and stores.
What's inside Calendarium
- Calendarium is an Obsidian plugin used for crafting complex fantasy and science fiction calendars. For detailed technical documentation, visit the official plugin documentation site.
Install Calendarium in Obsidian
mainCalendarium is an Obsidian plugin designed for creating fantasy and sci-fi calendars. You can install it directly through the Obsidian Community Store within the Obsidian application.Manage UI state with EphemeralStore
mainWhile the
CalendarStoremanages the data, theEphemeralStoremanages the user's current view and interface preferences. You can retrieve an ephemeral store usinggetEphemeralStore(id: string)from the main store.Key UI Controls:
- View Mode: Control the current view using
viewState(values:ViewState.Year,ViewState.Month,ViewState.Week,ViewState.Day). - Navigation: Use
goToNext(),goToPrevious(),goToToday(), ordisplayDate(date: CalDate)to move the UI focus. - Display Toggles: Control visibility of UI elements via
displayMoons,displayDayNumber,displayWeeks,hideEra,displayAbsoluteYear,displaySeasonColors,displayWeather, andinterpolateColors. - Location: Manage the currently selected location via the
locationstore.
- View Mode: Control the current view using
Access seasonal data
mainThe
CalendarAPIprovides methods to interact with the calendar's seasonal system:getSeasons(): Returns a list of all definedSeasonobjects on the calendar.getSeasonForDate(date: CalDate): Returns theSeasonapplicable to the provided date, orundefinedif no season is found.
const seasons = api.getSeasons(); const currentSeason = api.getSeasonForDate(api.getCurrentDate());Manage calendar events with EventStore
mainThe
EventStoreclass serves as the source of truth for events within a specificCalendar. It manages a collection ofCalEventobjects, providing methods to query, insert, and remove events.Key Behaviors:
- Source of Truth: It maintains an internal map of
EventId -> CalEvent. - Cache Invalidation: When events are inserted or removed, the store automatically invalidates the internal
EventCache, ensuring that date-based queries remain accurate. - Data Sync Warning: Events added directly to the
EventStoreviainsertEventsare NOT automatically synced back to the underlying calendar data source. - File vs. Manual Events: The store distinguishes between events parsed from files and manually inserted events. This allows for bulk removal of all events associated with a specific file path.
import { EventStore } from 'src/stores/events.store'; // Initialize with a calendar object const eventStore = new EventStore(myCalendar); // Get all events const allEvents = eventStore.getEvents(); // Get events for a specific date const eventsOnDate = eventStore.getEventsForDate(someCalDate);- Source of Truth: It maintains an internal map of
Retrieve a CalendarStore for a specific calendar
mainTo interact with the state of a specific calendar (e.g., to change the current date or manage file events), use
getStoreorgetStoreByCalendar.getStore(calendarId: string): Finds a calendar by its ID and returns its associatedCalendarStore.getStoreByCalendar(calendar: Calendar): Returns theCalendarStorefor a givenCalendarobject.
Each
CalendarStoremanages the reactive state for that specific calendar instance.// Example: Getting a store by calendar ID const store = plugin.getStore('my-calendar-id'); if (store) { // Perform store operations }Check event removability in EventStore
mainThe
EventStoreprovides utility methods to determine the nature of an event, which is important for deciding if an event can be deleted manually:isFileEvent(eventId: string): Returnstrueif the event was added viainsertEventsFromFile.isRemovable(eventId: string): Returnstrueif the event is not a file event. This is a convenience method to check if an event can be safely removed without affecting file-based synchronization logic.
if (eventStore.isRemovable(someEventId)) { eventStore.removeEvents(someEvent); }Manage core calendar state with CalendarStore
mainThe
CalendarStoreprovides methods to manipulate the underlying calendar data and navigate time. Key capabilities include:- Navigation: Use
setCurrentDate(date: CalDate)to change the calendar's reference date, orgetDaysBeforeDate(date: CalDate)to calculate offsets. - Data Access: Access
eventStorefor event management,staticStorefor immutable calendar rules (months, moons, eras), andlocationStorefor location data. - Event Retrieval: Use
getEventsForDate(date: CalDate)to get aReadablestore of all events (including era-based events) occurring on a specific date. - Category Management: Use
addCategory(category: CalEventCategory)to add new event categories orhasCategory(category: string)to check for existence.
- Navigation: Use
Modify the current date in a calendar
mainYou can advance or decrement the current date of a calendar using the
changeDaymethod. This method requires theCalendarobject, its correspondingCalendarStore, and a change function (likeincrementDayordecrementDay).import { incrementDay } from "./stores/calendar.store"; // Advance the day for a specific calendar plugin.changeDay(calendar, store, incrementDay);Calendarium core schema exports
mainThe
src/schemas/index.tsfile serves as the central export point for Calendarium's data structures. It aggregates and re-exports all primary schemas related to:- Calendar: Definitions for calendar structures and logic.
- Events: Definitions for event data and properties.
- Settings: Configuration and user preference schemas.
Use the API class to interact with Calendarium
mainThe
APIclass is the primary entry point for interacting with the Calendarium plugin. It allows you to manage settings callbacks, retrieve available calendar names, and obtain aCalendarAPIinstance for specific calendars to access their data and events.import { API } from "src/api/api"; // Assuming 'plugin' is an instance of Calendarium provided by the environment const api = new API(plugin);Insert and remove events in EventStore
mainYou can modify the event collection using these methods:
insertEvents(...events: CalEvent[]): Adds new events to the store. Note that events withEventType.Undatedare ignored.removeEvents(...events: CalEvent[]): Removes specific events from the store. Events withEventType.Undatedare ignored.insertEventsFromFile(path: string | null, ...events: CalEvent[]): Adds events and associates them with a specific file path. This is useful for tracking which events belong to which file for later bulk removal.removeEventsFromFile(filePath: string): Removes all events associated with the providedfilePath.removeAllFileEvents(): Clears all events that were marked as file events.
// Insert manual events eventStore.insertEvents(event1, event2); // Insert events linked to a file eventStore.insertEventsFromFile('/path/to/file.md', event3); // Remove specific events eventStore.removeEvents(event1); // Bulk remove by file eventStore.removeEventsFromFile('/path/to/file.md'); // Clear all file-based events eventStore.removeAllFileEvents();