fix: AI toolbar créée hors try/catch + simplifié imports circulaires
Some checks failed
CI / lint (push) Failing after 4s
CI / test (push) Has been skipped
CI / build (push) Has been skipped
CI / security (push) Successful in 8s

This commit is contained in:
Bruno Charest 2026-05-30 17:48:11 -04:00
parent b76fc64325
commit 281636efa0
3 changed files with 14 additions and 21 deletions

View File

@ -57,9 +57,9 @@ function replaceSelection(editorView, newText, mode = 'replace') {
// ── Show toast notification ──
function showToast(msg, type = 'info') {
// Use the global showToast if available (from ui.js)
if (typeof window._showToast === 'function') {
window._showToast(msg, type);
// Use global showToast if available, otherwise console
if (typeof window._obsigateShowToast === 'function') {
window._obsigateShowToast(msg, type);
}
}
@ -357,6 +357,3 @@ function createSeparator() {
sep.style.cssText = 'width:1px;height:16px;background:var(--border-color);margin:0 2px';
return sep;
}
// Export showToast for the module
export function setToast(fn) { window._showToast = fn; }

View File

@ -3,10 +3,13 @@
All code lives in frontend/js/*.js modules. */
import * as UI from './ui.js';
import * as Utils from './utils.js';
// Wire up AI toolbar toast (avoids circular import in utils.js)
window._obsigateShowToast = UI.showToast;
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';

View File

@ -2,10 +2,7 @@ import { state } from './state.js';
import { api } from './auth.js';
import { openFile, showWelcome } from './viewer.js';
import { refreshSidebarForContext, refreshTagsForContext } from './sidebar.js';
import { createAIToolbar, setToast } from './ai.js';
import { showToast } from './ui.js';
let _aiToolbarCreated = false;
import { createAIToolbar } from './ai.js';
// ---------------------------------------------------------------------------
// File extension → Lucide icon mapping
@ -367,16 +364,6 @@ async function openEditor(vaultName, filePath) {
state: cmState,
parent: bodyEl,
});
// Set up AI toolbar (once)
if (!_aiToolbarCreated) {
setToast(showToast);
const container = document.getElementById('ai-toolbar-container');
if (container) {
createAIToolbar(container, () => state.editorView);
_aiToolbarCreated = true;
}
}
} catch (err) {
console.error("CodeMirror init failed, falling back to textarea:", err);
state.fallbackEditorEl = document.createElement("textarea");
@ -385,6 +372,12 @@ async function openEditor(vaultName, filePath) {
bodyEl.appendChild(state.fallbackEditorEl);
}
// Set up AI toolbar (recreate each time editor opens)
const container = document.getElementById('ai-toolbar-container');
if (container && !container.querySelector('.ai-toolbar')) {
createAIToolbar(container, () => state.editorView || null);
}
modal.classList.add("active");
safeCreateIcons();
}