feat(forge): assistant IA partage et plein ecran Forge/Editer (#101)
This commit is contained in:
@@ -645,5 +645,15 @@ export function init() {
|
||||
// (inline mode) and re-renders the document read view.
|
||||
closeEditor();
|
||||
}
|
||||
if (e.data.type === 'forge-open-ai') {
|
||||
// #101 — Forge has no rich AI panel of its own: its AI button asks the
|
||||
// parent to open the shared AI Assistant (same provider/model, skills,
|
||||
// context and history).
|
||||
import('./bookslm.js').then(function(m) {
|
||||
if (m && m.default) m.default.openForCurrentContext();
|
||||
}).catch(function(err) {
|
||||
console.warn('[Forge] Unable to open AI assistant', err);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+54
-2
@@ -1,5 +1,6 @@
|
||||
import { state } from './state.js';
|
||||
import { api } from './auth.js';
|
||||
import { t } from './i18n.js';
|
||||
import { openFile, showWelcome } from './viewer.js';
|
||||
import { refreshSidebarForContext, refreshTagsForContext } from './sidebar.js';
|
||||
import { createAIToolbar } from './ai.js';
|
||||
@@ -586,6 +587,11 @@ function closeEditor() {
|
||||
if (!modal) return;
|
||||
modal.classList.remove("active");
|
||||
resetSaveButton();
|
||||
// Leaving the editor must also leave native fullscreen. #101
|
||||
if (isEditorFullscreen() && document.exitFullscreen) {
|
||||
const fsPromise = document.exitFullscreen();
|
||||
if (fsPromise && fsPromise.catch) fsPromise.catch(() => {});
|
||||
}
|
||||
stopCollab();
|
||||
if (state.editorView) {
|
||||
state.editorView.destroy();
|
||||
@@ -832,19 +838,65 @@ async function deleteFile() {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Fullscreen (#101)
|
||||
// ---------------------------------------------------------------------------
|
||||
const FS_ENTER_SVG = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/></svg>';
|
||||
const FS_EXIT_SVG = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"/></svg>';
|
||||
|
||||
/** True when the editor container currently owns the fullscreen viewport. */
|
||||
function isEditorFullscreen() {
|
||||
if (!document.fullscreenElement) return false;
|
||||
const container = getEditorContainer();
|
||||
return !!(container && (document.fullscreenElement === container || container.contains(document.fullscreenElement)));
|
||||
}
|
||||
|
||||
/** Toggle native fullscreen on the editor container (modal or inline). */
|
||||
function toggleEditorFullscreen() {
|
||||
const container = getEditorContainer();
|
||||
if (!container) return;
|
||||
if (document.fullscreenElement) {
|
||||
if (document.exitFullscreen) {
|
||||
const p = document.exitFullscreen();
|
||||
if (p && p.catch) p.catch(() => {});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (container.requestFullscreen) {
|
||||
const p = container.requestFullscreen();
|
||||
if (p && p.catch) p.catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
/** Sync the fullscreen button icon/label with the current fullscreen state. */
|
||||
function updateFullscreenButton() {
|
||||
const btn = document.getElementById("editor-fullscreen");
|
||||
if (!btn) return;
|
||||
const on = isEditorFullscreen();
|
||||
btn.innerHTML = on ? FS_EXIT_SVG : FS_ENTER_SVG;
|
||||
const label = t(on ? "editor.exit_fullscreen" : "editor.fullscreen");
|
||||
btn.title = label;
|
||||
btn.setAttribute("aria-label", label);
|
||||
btn.classList.toggle("active", on);
|
||||
}
|
||||
|
||||
function initEditor() {
|
||||
const cancelBtn = document.getElementById("editor-cancel");
|
||||
const deleteBtn = document.getElementById("editor-delete");
|
||||
const saveBtn = document.getElementById("editor-save");
|
||||
const fullscreenBtn = document.getElementById("editor-fullscreen");
|
||||
const modal = document.getElementById("editor-modal");
|
||||
|
||||
cancelBtn.addEventListener("click", closeEditor);
|
||||
deleteBtn.addEventListener("click", deleteFile);
|
||||
saveBtn.addEventListener("click", () => saveFile());
|
||||
if (fullscreenBtn) fullscreenBtn.addEventListener("click", toggleEditorFullscreen);
|
||||
document.addEventListener("fullscreenchange", updateFullscreenButton);
|
||||
|
||||
// ESC to close
|
||||
// ESC to close — unless we are in native fullscreen, where Escape exits
|
||||
// fullscreen first (the editor must stay open). #101
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape" && modal.classList.contains("active")) {
|
||||
if (e.key === "Escape" && !document.fullscreenElement && modal.classList.contains("active")) {
|
||||
closeEditor();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -781,6 +781,9 @@ export function renderFile(data) {
|
||||
var iframe = document.createElement("iframe");
|
||||
iframe.id = "forge-iframe";
|
||||
iframe.src = "/editor-poc?vault=" + encodeURIComponent(data.vault) + "&path=" + encodeURIComponent(data.path) + "&_ts=" + Date.now();
|
||||
// #101 — allow the Forge editor's own Fullscreen button to work.
|
||||
iframe.setAttribute("allow", "fullscreen");
|
||||
iframe.setAttribute("allowfullscreen", "");
|
||||
// Inline: the iframe fills the content area; overlay: the original 82vh.
|
||||
iframe.style.cssText = "width:100%;height:" + (inline ? "100%" : "82vh") + ";border:none;display:block;";
|
||||
bodyEl.appendChild(iframe);
|
||||
|
||||
Reference in New Issue
Block a user