The smokesignal.events web application
at main 56 lines 1.6 kB view raw
1/** 2 * Core module - initializes htmx, extensions, and Alpine.js 3 * 4 * This module bundles all core libraries that are needed on every page: 5 * - htmx for hypermedia-driven interactions 6 * - htmx extensions (loading-states, sse) 7 * - Alpine.js for declarative reactivity 8 * 9 * Heavy libraries (maps, cropper) are NOT loaded here - they are lazy-loaded 10 * only when needed via the features modules. 11 */ 12 13// Import Alpine.js 14import Alpine from 'alpinejs' 15// Import htmx 16import htmx from 'htmx.org' 17// Import auth utilities 18import { authFetch, authPostJson, refreshAuth, refreshSession } from './auth' 19// Import htmx extensions 20import { initAuthRefreshExtension } from './htmx-extensions/auth-refresh' 21import { initLoadingStatesExtension } from './htmx-extensions/loading-states' 22import { initSSEExtension } from './htmx-extensions/sse' 23 24// Import types 25import type { HtmxApi } from './types' 26 27// Expose htmx globally (required for some inline attributes) 28declare global { 29 interface Window { 30 htmx: HtmxApi 31 Alpine: typeof Alpine 32 } 33} 34 35// Cast and expose htmx globally 36const htmxApi = htmx as unknown as HtmxApi 37window.htmx = htmxApi 38 39// Initialize htmx extensions 40initAuthRefreshExtension(htmxApi) 41initLoadingStatesExtension(htmxApi) 42initSSEExtension(htmxApi) 43 44// Expose Alpine globally 45window.Alpine = Alpine 46 47// Start Alpine when DOM is ready 48if (document.readyState === 'loading') { 49 document.addEventListener('DOMContentLoaded', () => { 50 Alpine.start() 51 }) 52} else { 53 Alpine.start() 54} 55 56export { htmxApi as htmx, Alpine, refreshSession, refreshAuth, authFetch, authPostJson }