UNPKG

@crescender/calendar

Version:

A comprehensive TypeScript calendar library with musician-specific capabilities, architected for client/server separation.

316 lines (304 loc) 10.8 kB
import { IEvent, IEventIncome, IEventExpense, IVenue, ICalendar, IContact } from '../shared/index.js'; export { API_CONFIG, AUSTRALIAN_STATES, CALENDAR_TYPES, CALENDAR_VIEWS, CURRENCIES, CalendarType, Changes, DATE_FORMATS, DEFAULT_CURRENCY, DEFAULT_EVENT_DURATION_MINUTES, DEFAULT_START_OF_WEEK, DIFFICULTY_LEVELS, DifficultyLevel, EVENT_STATUS, EVENT_TYPES, EventStatus, EventType, FILE_UPLOAD, FinancialSummary, GENRES, Genre, INSTRUMENTS, Instrument, MAX_EVENT_DURATION_HOURS, MAX_LENGTHS, MAX_RECURRENCE_OCCURRENCES, PAYMENT_STATUS, PaymentStatus, STUDENT_LEVELS, StudentLevel, SyncToken, TIME_FORMATS, VALIDATION_PATTERNS, formatDateAustralian, generateTempId, getDurationMinutes, getEndOfWeek, getStartOfWeek, isSameDay, isValidEmail, isValidPhone } from '../shared/index.js'; import React from 'react'; interface ClientEvent extends IEvent { income?: IEventIncome[]; expenses?: IEventExpense[]; totalIncome?: number; totalExpenses?: number; profit?: number; netProfit?: number; duration?: number; isUpcoming?: boolean; isPast?: boolean; daysUntil?: number; formattedDate?: string; formattedTime?: string; formattedDuration?: string; displayDate?: string; venueDetails?: IVenue; calendarDetails?: ICalendar; contacts?: IContact[]; } interface EventFormData { title: string; description?: string; startDate: string; endDate?: string; startTime: string; endTime?: string; eventType: string; status: string; venueId?: string; calendarId: string; isRecurring?: boolean; recurrenceRule?: string; recurrenceEndDate?: string; maxOccurrences?: number; contactIds?: string[]; notes?: string; isAllDay?: boolean; } interface CreateEventData extends Omit<EventFormData, 'contactIds'> { contacts?: string[]; } interface UpdateEventData extends Partial<CreateEventData> { id: string; } interface EventFilters { eventType?: string[]; status?: string[]; calendarId?: string[]; venueId?: string[]; dateRange?: { start: Date; end: Date; }; searchQuery?: string; isUpcoming?: boolean; isPast?: boolean; } interface EventsByDate { [date: string]: ClientEvent[]; } interface EventsByType { [eventType: string]: ClientEvent[]; } interface EventsByVenue { [venueId: string]: { venue: IVenue; events: ClientEvent[]; }; } interface EventFinancialSummary { totalIncome: number; totalExpenses: number; netProfit: number; eventCount: number; averageProfit: number; } interface FinancialSummaryByType { [eventType: string]: EventFinancialSummary; } interface ClientCalendar extends ICalendar { eventCount?: number; upcomingEventCount?: number; totalIncome?: number; totalExpenses?: number; netProfit?: number; lastEventDate?: Date; nextEventDate?: Date; } interface CalendarFormData { name: string; description?: string; color?: string; isDefault?: boolean; isVisible?: boolean; timeZone?: string; } interface CreateCalendarData extends CalendarFormData { } interface UpdateCalendarData extends Partial<CreateCalendarData> { id: string; } interface CalendarViewData { calendar: ClientCalendar; events: ClientEvent[]; venues: IVenue[]; contacts: IContact[]; } interface CalendarStats { totalEvents: number; upcomingEvents: number; pastEvents: number; eventsByType: { [type: string]: number; }; eventsByStatus: { [status: string]: number; }; monthlyEventCounts: { [month: string]: number; }; totalIncome: number; totalExpenses: number; netProfit: number; } interface CalendarFilters { isVisible?: boolean; hasEvents?: boolean; searchQuery?: string; } interface CalendarSettings { defaultView: 'month' | 'week' | 'day' | 'list'; startOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6; timeFormat: '12h' | '24h'; dateFormat: 'DD/MM/YYYY' | 'MM/DD/YYYY' | 'YYYY-MM-DD'; showWeekends: boolean; showTime: boolean; defaultEventDuration: number; } /** * Pure date utility functions - browser-safe */ declare const formatTimeAustralian: (date: Date | string) => string; declare const formatDateTimeAustralian: (date: Date | string) => string; declare const daysUntil: (date: Date | string) => number; declare const isToday: (date: Date | string) => boolean; declare const isPast: (date: Date | string) => boolean; declare const isFuture: (date: Date | string) => boolean; declare const isThisWeek: (date: Date | string) => boolean; declare const isThisMonth: (date: Date | string) => boolean; declare const startOfDay: (date: Date | string) => Date; declare const endOfDay: (date: Date | string) => Date; declare const addDays: (date: Date | string, days: number) => Date; declare const addMonths: (date: Date | string, months: number) => Date; declare const getMonthName: (date: Date | string) => string; declare const getDayName: (date: Date | string) => string; /** * Australian formatting utilities - browser-safe */ declare const formatCurrencyAUD: (amount: number) => string; declare const formatPhoneAustralian: (phone: string) => string; declare const formatAddressAustralian: (address: { street?: string; suburb?: string; state?: string; postcode?: string; country?: string; }) => string; declare const formatPercentage: (value: number, decimals?: number) => string; declare const formatNumber: (value: number, decimals?: number) => string; declare const formatDuration: (minutes: number) => string; declare const formatFileSize: (bytes: number) => string; declare const capitalizeWords: (text: string) => string; declare const truncateText: (text: string, maxLength: number) => string; declare const getInitials: (name: string) => string; /** * @file Client-side validation for the calendar library. * These validation functions are safe for browser environments. */ interface ValidationResult { isValid: boolean; errors: Record<string, string[]>; } interface IncomeFormData { description: string; amount: number; currency: string; notes?: string; } interface ExpenseFormData { description: string; amount: number; currency: string; notes?: string; receipt?: string; } /** * Validates event form data. */ declare function validateEvent(data: Partial<EventFormData>): ValidationResult; /** * Validates income form data. */ declare function validateIncome(data: Partial<IncomeFormData>): ValidationResult; /** * Validates expense form data. */ declare function validateExpense(data: Partial<ExpenseFormData>): ValidationResult; /** * Validates calendar form data. */ declare function validateCalendar(data: Partial<CalendarFormData>): ValidationResult; /** * Validates venue form data. */ declare function validateVenue(data: { name?: string; address?: string; city?: string; state?: string; country?: string; website?: string; contactEmail?: string; contactPhone?: string; notes?: string; }): ValidationResult; /** * Validates contact form data. */ declare function validateContact(data: { name?: string; email?: string; phone?: string; role?: string; notes?: string; }): ValidationResult; /** * Validates recurrence rule format. */ declare function validateRecurrenceRule(rule: string): ValidationResult; /** * @file Client-side event processing utilities. * These utilities are safe for browser environments and work with rrule for recurrence. */ /** * Expands a recurring event into multiple occurrences within a date range. */ declare function expandRecurrence(event: IEvent, startRange: Date, endRange: Date, maxOccurrences?: number): IEvent[]; /** * Enhances a client event with computed properties. */ declare function enhanceClientEvent(event: ClientEvent): ClientEvent; /** * Filters events based on provided criteria. */ declare function filterEvents(events: ClientEvent[], filters: EventFilters): ClientEvent[]; /** * Sorts events based on criteria. */ type EventSortOptions = { field: 'start' | 'end' | 'summary' | 'type' | 'createdAt'; direction: 'asc' | 'desc'; }; declare function sortEvents(events: ClientEvent[], sortOptions: EventSortOptions): ClientEvent[]; /** * Groups events by date. */ declare function groupEventsByDate(events: ClientEvent[]): EventsByDate; /** * Gets upcoming events (future events). */ declare function getUpcomingEvents(events: ClientEvent[]): ClientEvent[]; /** * Gets today's events. */ declare function getTodaysEvents(events: ClientEvent[]): ClientEvent[]; /** * Calculates financial summary for a set of events. */ declare function calculateFinancialSummary(events: ClientEvent[]): EventFinancialSummary; interface EventCardProps { event: ClientEvent; onClick?: (event: ClientEvent) => void; onEdit?: (event: ClientEvent) => void; onDelete?: (event: ClientEvent) => void; showFinancials?: boolean; className?: string; } declare const EventCard: React.FC<EventCardProps>; interface CalendarViewProps { calendar: ClientCalendar; events: ClientEvent[]; view?: 'month' | 'week' | 'day' | 'list'; onEventClick?: (event: ClientEvent) => void; onEventEdit?: (event: ClientEvent) => void; onEventDelete?: (event: ClientEvent) => void; onViewChange?: (view: 'month' | 'week' | 'day' | 'list') => void; showFinancials?: boolean; className?: string; } declare const CalendarView: React.FC<CalendarViewProps>; export { type CalendarFilters, type CalendarFormData, type CalendarSettings, type CalendarStats, CalendarView, type CalendarViewData, type CalendarViewProps, type ClientCalendar, type ClientEvent, type CreateCalendarData, type CreateEventData, EventCard, type EventCardProps, type EventFilters, type EventFinancialSummary, type EventFormData, type EventSortOptions, type EventsByDate, type EventsByType, type EventsByVenue, type ExpenseFormData, type FinancialSummaryByType, ICalendar, IContact, IEvent, IEventExpense, IEventIncome, IVenue, type IncomeFormData, type UpdateCalendarData, type UpdateEventData, type ValidationResult, addDays, addMonths, calculateFinancialSummary, capitalizeWords, daysUntil, endOfDay, enhanceClientEvent, expandRecurrence, filterEvents, formatAddressAustralian, formatCurrencyAUD, formatDateTimeAustralian, formatDuration, formatFileSize, formatNumber, formatPercentage, formatPhoneAustralian, formatTimeAustralian, getDayName, getInitials, getMonthName, getTodaysEvents, getUpcomingEvents, groupEventsByDate, isFuture, isPast, isThisMonth, isThisWeek, isToday, sortEvents, startOfDay, truncateText, validateCalendar, validateContact, validateEvent, validateExpense, validateIncome, validateRecurrenceRule, validateVenue };