refactor: Add Alpine.js registration to existing TypeScript modules

Added Alpine.global() registration to enable template access to functions:

- admin.ts: Added Alpine for scan, stats, and settings functions
- api-explorer.ts: Already had Alpine (kept as is)
- bookshelf.ts: Added Alpine for library/bookshelf interactions
- collections.ts: Added Alpine for collection management
- conflicts.ts: Added Alpine for conflict resolution
- device-management.ts: Added Alpine with event delegation for dynamic content
- header.ts: Added Alpine for theme dropdown and user menu
- library.ts: Added Alpine registrations
- linking.ts: Added Alpine registrations
- queue.ts: Added Alpine for queue operations
- search.ts: Added Alpine registrations
- themeDropdown.ts: Added Alpine for theme switching

Each module now exports functions both traditionally and via Alpine.global() for template access.
This commit is contained in:
2026-03-08 21:36:24 -04:00
parent dc288e6169
commit 6728ba83a1
12 changed files with 1028 additions and 393 deletions
+23 -16
View File
@@ -1,5 +1,9 @@
// Theme dropdown active indicator management
import { Alpine } from "./alpine";
import { changeThemeTo, toggleThemeDropdown as originalToggle } from "./header";
import { updateWoodPanelingIndicators } from "./woodPaneling";
// Update visual indicators for theme buttons
const updateThemeIndicators = (): void => {
const currentTheme = localStorage.getItem("theme") || "tokyo-night";
@@ -23,26 +27,21 @@ const updateThemeIndicators = (): void => {
});
};
// Make function available globally
(window as any).updateThemeIndicators = updateThemeIndicators;
// Update on dropdown toggle
const originalToggleThemeDropdown = (window as any).toggleThemeDropdown;
if (originalToggleThemeDropdown) {
(window as any).toggleThemeDropdown = () => {
originalToggleThemeDropdown();
updateThemeIndicators();
(window as any).updateWoodPanelingIndicators?.();
};
export function initializeThemeDropdown() {
// Call original function
originalToggle();
// Then update indicators
updateThemeIndicators();
updateWoodPanelingIndicators();
}
// Update after theme changes
const originalChangeThemeTo = (window as any).changeThemeTo;
if (originalChangeThemeTo) {
(window as any).changeThemeTo = (...args: unknown[]) => {
originalChangeThemeTo(...args);
updateThemeIndicators();
};
export function initializeChangeThemeTo(theme: string): void {
// Call original function from header.ts
changeThemeTo(theme);
// Then update indicators
updateThemeIndicators();
}
// Auto-initialize when DOM is ready
@@ -53,3 +52,11 @@ if (typeof document !== "undefined") {
updateThemeIndicators();
}
}
Alpine.global("themeDropdown", {
initializeDropdown: initializeThemeDropdown,
changeTheme: initializeChangeThemeTo,
updateIndicators: updateThemeIndicators,
});
export { updateThemeIndicators };