fix: AI toolbar créée hors try/catch + simplifié imports circulaires
This commit is contained in:
parent
b76fc64325
commit
281636efa0
@ -57,9 +57,9 @@ function replaceSelection(editorView, newText, mode = 'replace') {
|
|||||||
|
|
||||||
// ── Show toast notification ──
|
// ── Show toast notification ──
|
||||||
function showToast(msg, type = 'info') {
|
function showToast(msg, type = 'info') {
|
||||||
// Use the global showToast if available (from ui.js)
|
// Use global showToast if available, otherwise console
|
||||||
if (typeof window._showToast === 'function') {
|
if (typeof window._obsigateShowToast === 'function') {
|
||||||
window._showToast(msg, type);
|
window._obsigateShowToast(msg, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,6 +357,3 @@ function createSeparator() {
|
|||||||
sep.style.cssText = 'width:1px;height:16px;background:var(--border-color);margin:0 2px';
|
sep.style.cssText = 'width:1px;height:16px;background:var(--border-color);margin:0 2px';
|
||||||
return sep;
|
return sep;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export showToast for the module
|
|
||||||
export function setToast(fn) { window._showToast = fn; }
|
|
||||||
|
|||||||
@ -3,10 +3,13 @@
|
|||||||
All code lives in frontend/js/*.js modules. */
|
All code lives in frontend/js/*.js modules. */
|
||||||
|
|
||||||
import * as UI from './ui.js';
|
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 Sidebar from './sidebar.js';
|
||||||
import * as Auth from './auth.js';
|
import * as Auth from './auth.js';
|
||||||
import * as Viewer from './viewer.js';
|
import * as Viewer from './viewer.js';
|
||||||
import * as Utils from './utils.js';
|
|
||||||
import * as Sync from './sync.js';
|
import * as Sync from './sync.js';
|
||||||
import { initGraphView } from './graph.js';
|
import { initGraphView } from './graph.js';
|
||||||
import * as Legacy from './legacy.js';
|
import * as Legacy from './legacy.js';
|
||||||
|
|||||||
@ -2,10 +2,7 @@ import { state } from './state.js';
|
|||||||
import { api } from './auth.js';
|
import { api } from './auth.js';
|
||||||
import { openFile, showWelcome } from './viewer.js';
|
import { openFile, showWelcome } from './viewer.js';
|
||||||
import { refreshSidebarForContext, refreshTagsForContext } from './sidebar.js';
|
import { refreshSidebarForContext, refreshTagsForContext } from './sidebar.js';
|
||||||
import { createAIToolbar, setToast } from './ai.js';
|
import { createAIToolbar } from './ai.js';
|
||||||
import { showToast } from './ui.js';
|
|
||||||
|
|
||||||
let _aiToolbarCreated = false;
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// File extension → Lucide icon mapping
|
// File extension → Lucide icon mapping
|
||||||
@ -367,16 +364,6 @@ async function openEditor(vaultName, filePath) {
|
|||||||
state: cmState,
|
state: cmState,
|
||||||
parent: bodyEl,
|
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) {
|
} catch (err) {
|
||||||
console.error("CodeMirror init failed, falling back to textarea:", err);
|
console.error("CodeMirror init failed, falling back to textarea:", err);
|
||||||
state.fallbackEditorEl = document.createElement("textarea");
|
state.fallbackEditorEl = document.createElement("textarea");
|
||||||
@ -385,6 +372,12 @@ async function openEditor(vaultName, filePath) {
|
|||||||
bodyEl.appendChild(state.fallbackEditorEl);
|
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");
|
modal.classList.add("active");
|
||||||
safeCreateIcons();
|
safeCreateIcons();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user