2025-07-24 22:17:38 +02:00
|
|
|
// Main entry point for Calendar Plantempus
|
2025-09-23 20:44:15 +02:00
|
|
|
import { eventBus } from './core/EventBus';
|
|
|
|
|
import { calendarConfig } from './core/CalendarConfig';
|
|
|
|
|
import { CalendarTypeFactory } from './factories/CalendarTypeFactory';
|
2025-10-14 22:53:28 +02:00
|
|
|
import { createContainer } from './di/container';
|
|
|
|
|
import { TOKENS } from './di/tokens';
|
2025-09-23 20:44:15 +02:00
|
|
|
import { URLManager } from './utils/URLManager';
|
2025-10-14 22:53:28 +02:00
|
|
|
import { EventManager } from './managers/EventManager';
|
2025-09-04 00:16:35 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle deep linking functionality after managers are initialized
|
|
|
|
|
*/
|
2025-10-14 22:53:28 +02:00
|
|
|
async function handleDeepLinking(eventManager: EventManager): Promise<void> {
|
2025-09-04 00:16:35 +02:00
|
|
|
try {
|
|
|
|
|
const urlManager = new URLManager(eventBus);
|
|
|
|
|
const eventId = urlManager.parseEventIdFromURL();
|
2025-10-14 22:53:28 +02:00
|
|
|
|
2025-09-04 00:16:35 +02:00
|
|
|
if (eventId) {
|
|
|
|
|
console.log(`Deep linking to event ID: ${eventId}`);
|
2025-10-14 22:53:28 +02:00
|
|
|
|
2025-09-04 00:16:35 +02:00
|
|
|
// Wait a bit for managers to be fully ready
|
|
|
|
|
setTimeout(() => {
|
2025-10-14 22:53:28 +02:00
|
|
|
const success = eventManager.navigateToEvent(eventId);
|
2025-09-04 00:16:35 +02:00
|
|
|
if (!success) {
|
|
|
|
|
console.warn(`Deep linking failed: Event with ID ${eventId} not found`);
|
|
|
|
|
}
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.warn('Deep linking failed:', error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
/**
|
2025-10-14 22:53:28 +02:00
|
|
|
* Initialize the calendar application using Brandi DI
|
2025-07-24 22:17:38 +02:00
|
|
|
*/
|
2025-08-09 00:31:44 +02:00
|
|
|
async function initializeCalendar(): Promise<void> {
|
|
|
|
|
try {
|
|
|
|
|
// Use the singleton calendar configuration
|
|
|
|
|
const config = calendarConfig;
|
2025-10-14 22:53:28 +02:00
|
|
|
|
2025-08-09 00:31:44 +02:00
|
|
|
// Initialize the CalendarTypeFactory before creating managers
|
|
|
|
|
CalendarTypeFactory.initialize();
|
2025-10-14 22:53:28 +02:00
|
|
|
|
|
|
|
|
// Create Brandi DI container (all managers instantiated here)
|
|
|
|
|
const container = createContainer();
|
|
|
|
|
|
2025-08-09 00:31:44 +02:00
|
|
|
// Enable debug mode for development
|
|
|
|
|
eventBus.setDebug(true);
|
2025-10-14 22:53:28 +02:00
|
|
|
|
|
|
|
|
// Get managers from container
|
|
|
|
|
const calendarManager = container.get(TOKENS.calendarManager);
|
|
|
|
|
const eventManager = container.get(TOKENS.eventManager);
|
|
|
|
|
const resizeHandleManager = container.get(TOKENS.resizeHandleManager);
|
2025-10-15 20:09:12 +02:00
|
|
|
const headerManager = container.get(TOKENS.headerManager);
|
|
|
|
|
const dragDropManager = container.get(TOKENS.dragDropManager);
|
|
|
|
|
const viewManager = container.get(TOKENS.viewManager);
|
|
|
|
|
const navigationManager = container.get(TOKENS.navigationManager);
|
|
|
|
|
const edgeScrollManager = container.get(TOKENS.edgeScrollManager);
|
|
|
|
|
const dragHoverManager = container.get(TOKENS.dragHoverManager);
|
|
|
|
|
const allDayManager = container.get(TOKENS.allDayManager);
|
2025-10-14 22:53:28 +02:00
|
|
|
|
|
|
|
|
// Initialize managers
|
|
|
|
|
await calendarManager.initialize?.();
|
|
|
|
|
await resizeHandleManager.initialize?.();
|
|
|
|
|
|
2025-09-04 00:16:35 +02:00
|
|
|
// Handle deep linking after managers are initialized
|
2025-10-14 22:53:28 +02:00
|
|
|
await handleDeepLinking(eventManager);
|
|
|
|
|
|
2025-09-23 20:44:15 +02:00
|
|
|
// Expose to window for debugging (with proper typing)
|
2025-10-14 22:53:28 +02:00
|
|
|
(window as Window & {
|
2025-09-23 20:44:15 +02:00
|
|
|
calendarDebug?: {
|
|
|
|
|
eventBus: typeof eventBus;
|
2025-10-14 22:53:28 +02:00
|
|
|
container: typeof container;
|
|
|
|
|
calendarManager: typeof calendarManager;
|
|
|
|
|
eventManager: typeof eventManager;
|
|
|
|
|
};
|
2025-09-23 20:44:15 +02:00
|
|
|
}).calendarDebug = {
|
2025-08-17 23:44:30 +02:00
|
|
|
eventBus,
|
2025-10-14 22:53:28 +02:00
|
|
|
container,
|
|
|
|
|
calendarManager,
|
|
|
|
|
eventManager,
|
2025-08-17 23:44:30 +02:00
|
|
|
};
|
2025-10-14 22:53:28 +02:00
|
|
|
|
2025-08-09 00:31:44 +02:00
|
|
|
} catch (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-09 00:31:44 +02:00
|
|
|
// Initialize when DOM is ready - now handles async properly
|
2025-07-24 22:17:38 +02:00
|
|
|
if (document.readyState === 'loading') {
|
2025-08-09 00:31:44 +02:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
initializeCalendar().catch(error => {
|
2025-10-15 20:09:12 +02:00
|
|
|
});
|
2025-08-09 00:31:44 +02:00
|
|
|
});
|
2025-07-24 22:17:38 +02:00
|
|
|
} else {
|
2025-08-09 00:31:44 +02:00
|
|
|
initializeCalendar().catch(error => {
|
|
|
|
|
});
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|