feat: Add new Alpine.js component TypeScript files

Extracted inline JavaScript from templates into proper TypeScript modules:

- api-explorer-docs.ts: API explorer page functionality
- collection-rules.ts: Collection rules management page
- index.ts: Homepage theme and auth redirect
- login.ts: Login page theme initialization
- profile-modal.ts: Profile modal close and escape key
- profile.ts: Profile page delete account
- register.ts: Registration page theme init
- toast-error.ts: Error toast with retry button
- unlinked_books.ts: Unlinked books management page

Each file:
- Uses ES imports (showToast, getToken, etc.)
- Has proper TypeScript types
- Registers with Alpine.js via Alpine.global()
- Uses async/await for API calls
This commit is contained in:
2026-03-08 21:35:47 -04:00
parent 0af319fef9
commit b78aacd320
9 changed files with 1219 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
import { Alpine } from "./alpine";
let escapeHandler: ((e: KeyboardEvent) => void) | null = null;
function closeProfileModal(): void {
const modal = document.getElementById("profile-modal");
if (modal) {
modal.remove();
}
// Remove escape key listener when modal closes
if (escapeHandler) {
document.removeEventListener("keydown", escapeHandler);
escapeHandler = null;
}
}
function setupProfileModal(): void {
// Set up escape key listener to close modal
escapeHandler = (e: KeyboardEvent) => {
if (e.key === "Escape") {
closeProfileModal();
}
};
document.addEventListener("keydown", escapeHandler);
}
export { closeProfileModal, setupProfileModal };
Alpine.global("profileModal", {
closeProfileModal,
setupProfileModal,
});