frontend/js/ structure: state.js (55 lines) — Shared mutable state, constants utils.js (510 lines) — EXT_ICONS, getFileIcon, escapeHtml, safeCreateIcons auth.js (547 lines) — api(), AuthManager, initLoginForm, AdminPanel search.js (1106 lines)— SearchHistory, QueryParser, Autocomplete, performSearch sidebar.js (1091 lines)— Vault tree, sidebar filter, TagFilterService, loadTags viewer.js (1554 lines)— openFile, Outline, ScrollSpy, Frontmatter, Editor ui.js (2250 lines)— Theme, Toast, Sidebar, Dropdowns, Tabs, ContextMenu dashboard.js (461 lines) — Dashboard widgets (Recent, Stats, Bookmarks) config.js (999 lines) — Config panel, Hidden files, About, Sidebar tabs sync.js (436 lines) — SSE/IndexUpdateManager, PWA registration graph.js (401 lines) — GraphViewManager (force-directed canvas graph) legacy.js (550 lines) — Remaining bridge functions (goHome, showWelcome, initSearch) app.js (80 lines) — Thin orchestrator: imports all modules, calls init() index.html: switched from <script src="app.js"> to <script type="module" src="js/app.js"> Original app.js preserved for backward compatibility. All 14 modules pass node --check syntax validation.
84 lines
2.6 KiB
JavaScript
84 lines
2.6 KiB
JavaScript
/* ObsiGate — Module orchestrator (ES modules).
|
|
Replaces the monolithic frontend/app.js IIFE.
|
|
All code lives in frontend/js/*.js modules. */
|
|
|
|
import * as UI from './ui.js';
|
|
import * as Sidebar from './sidebar.js';
|
|
import * as Auth from './auth.js';
|
|
import * as Viewer from './viewer.js';
|
|
import * as Utils from './utils.js';
|
|
import * as Sync from './sync.js';
|
|
import { initGraphView } from './graph.js';
|
|
import * as Legacy from './legacy.js';
|
|
|
|
// =========================================================================
|
|
// Initialization — mirrors the original app.js init() ordering
|
|
// =========================================================================
|
|
async function init() {
|
|
UI.initTheme();
|
|
UI.initHeaderMenu();
|
|
UI.initCustomDropdowns();
|
|
|
|
document.getElementById("theme-toggle").addEventListener("click", UI.toggleTheme);
|
|
document.getElementById("header-logo").addEventListener("click", Legacy.goHome);
|
|
const refreshBtn = document.getElementById("header-refresh-btn");
|
|
if (refreshBtn) refreshBtn.addEventListener("click", Legacy.goHome);
|
|
|
|
Legacy.initSearch();
|
|
UI.initSidebarToggle();
|
|
UI.initMobile();
|
|
Sidebar.initVaultContext();
|
|
Legacy.initSidebarTabs();
|
|
Legacy.initHelpModal();
|
|
Legacy.initConfigModal();
|
|
Sidebar.initSidebarFilter();
|
|
UI.initSidebarResize();
|
|
Utils.initEditor();
|
|
Auth.initLoginForm();
|
|
Legacy.initRecentTab();
|
|
|
|
UI.RightSidebarManager.init();
|
|
UI.FindInPageManager.init();
|
|
UI.ContextMenuManager.init();
|
|
|
|
const authOk = await Auth.AuthManager.initAuth();
|
|
|
|
if (authOk) {
|
|
Legacy.initSyncStatus();
|
|
|
|
try {
|
|
await Promise.all([Legacy.loadVaultSettings(), Sidebar.loadVaults(), Sidebar.loadTags()]);
|
|
|
|
Legacy.DashboardRecentWidget.init();
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
if (urlParams.get("popup") === "true") {
|
|
document.body.classList.add("popup-mode");
|
|
}
|
|
|
|
if (window.location.hash && window.location.hash.startsWith("#file=")) {
|
|
const hashVal = window.location.hash.substring(6);
|
|
const sepIndex = hashVal.indexOf(":");
|
|
if (sepIndex > -1) {
|
|
const vault = decodeURIComponent(hashVal.substring(0, sepIndex));
|
|
const path = decodeURIComponent(hashVal.substring(sepIndex + 1));
|
|
Viewer.openFile(vault, path);
|
|
}
|
|
} else if (urlParams.get("popup") !== "true") {
|
|
Legacy.showWelcome();
|
|
}
|
|
} catch (err) {
|
|
console.error("Failed to initialize ObsiGate:", err);
|
|
UI.showToast("Erreur lors de l'initialisation", "error");
|
|
}
|
|
}
|
|
|
|
initGraphView();
|
|
Utils.safeCreateIcons();
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
init();
|
|
Sync.init();
|
|
});
|