feat: Forge opens in editor modal instead of new tab
Forge button now reuses the existing editor-modal with an iframe. Same position as the Edit/CodeMirror modal. On close, the forge iframe is removed and the current file is refreshed (picks up changes saved by the POC's auto-save). Updated both frontend/js/viewer.js and frontend/app.js.
This commit is contained in:
+18
-2
@@ -3294,8 +3294,18 @@
|
||||
|
||||
const forgeBtn = el("button", { class: "btn-action btn-forge", title: "Forge (nouvel editeur)" }, [icon("hammer", 14), document.createTextNode("Forge")]);
|
||||
forgeBtn.addEventListener("click", () => {
|
||||
var forgeUrl = "/editor-poc?vault=" + encodeURIComponent(data.vault) + "&path=" + encodeURIComponent(data.path);
|
||||
window.open(forgeUrl, "_blank");
|
||||
var modal = document.getElementById("editor-modal");
|
||||
var titleEl = document.getElementById("editor-title");
|
||||
var bodyEl = document.getElementById("editor-body");
|
||||
titleEl.textContent = "Forge: " + data.path.split("/").pop();
|
||||
bodyEl.innerHTML = "";
|
||||
var iframe = document.createElement("iframe");
|
||||
iframe.id = "forge-iframe";
|
||||
iframe.src = "/editor-poc?vault=" + encodeURIComponent(data.vault) + "&path=" + encodeURIComponent(data.path);
|
||||
iframe.style.cssText = "width:100%;height:100%;border:none;";
|
||||
bodyEl.appendChild(iframe);
|
||||
modal.classList.add("active");
|
||||
safeCreateIcons();
|
||||
});
|
||||
|
||||
const openNewWindowBtn = el("button", { class: "btn-action", title: "Ouvrir dans une nouvelle fenetre" }, [icon("external-link", 14), document.createTextNode("pop-out")]);
|
||||
@@ -6312,6 +6322,12 @@
|
||||
editorView = null;
|
||||
}
|
||||
fallbackEditorEl = null;
|
||||
// Remove forge iframe if present + refresh current file
|
||||
var forgeFrame = document.getElementById("forge-iframe");
|
||||
if (forgeFrame) {
|
||||
forgeFrame.remove();
|
||||
if (currentVault && currentPath) openFile(currentVault, currentPath);
|
||||
}
|
||||
editorVault = null;
|
||||
editorPath = null;
|
||||
}
|
||||
|
||||
@@ -459,6 +459,12 @@ function closeEditor() {
|
||||
state.editorView = null;
|
||||
}
|
||||
state.fallbackEditorEl = null;
|
||||
// Remove forge iframe if present + refresh current file
|
||||
var forgeFrame = document.getElementById("forge-iframe");
|
||||
if (forgeFrame) {
|
||||
forgeFrame.remove();
|
||||
if (state.currentVault && state.currentPath) openFile(state.currentVault, state.currentPath);
|
||||
}
|
||||
state.editorVault = null;
|
||||
state.editorPath = null;
|
||||
// Refresh file content if we're viewing the edited file
|
||||
|
||||
+12
-2
@@ -499,8 +499,18 @@ export function renderFile(data) {
|
||||
|
||||
const forgeBtn = el("button", { class: "btn-action btn-forge", title: "Forge (nouvel editeur)" }, [icon("hammer", 14), document.createTextNode("Forge")]);
|
||||
forgeBtn.addEventListener("click", () => {
|
||||
var forgeUrl = "/editor-poc?vault=" + encodeURIComponent(data.vault) + "&path=" + encodeURIComponent(data.path);
|
||||
window.open(forgeUrl, "_blank");
|
||||
var modal = document.getElementById("editor-modal");
|
||||
var titleEl = document.getElementById("editor-title");
|
||||
var bodyEl = document.getElementById("editor-body");
|
||||
titleEl.textContent = "Forge: " + data.path.split("/").pop();
|
||||
bodyEl.innerHTML = "";
|
||||
var iframe = document.createElement("iframe");
|
||||
iframe.id = "forge-iframe";
|
||||
iframe.src = "/editor-poc?vault=" + encodeURIComponent(data.vault) + "&path=" + encodeURIComponent(data.path);
|
||||
iframe.style.cssText = "width:100%;height:100%;border:none;";
|
||||
bodyEl.appendChild(iframe);
|
||||
modal.classList.add("active");
|
||||
safeCreateIcons();
|
||||
});
|
||||
|
||||
const openNewWindowBtn = el("button", { class: "btn-action", title: "Ouvrir dans une nouvelle fenetre" }, [icon("external-link", 14), document.createTextNode("pop-out")]);
|
||||
|
||||
Reference in New Issue
Block a user