fix(viewer): rendu unifié type markdown pour fichiers texte/JSON/CSV + autofocus arborescence apres import (#89)
This commit is contained in:
+10
-1
@@ -11,7 +11,7 @@
|
||||
import { api } from './auth.js';
|
||||
import { t } from './i18n.js';
|
||||
import { showToast } from './ui.js';
|
||||
import { refreshSidebarTreePreservingState } from './sidebar.js';
|
||||
import { refreshSidebarTreePreservingState, focusPathInSidebar } from './sidebar.js';
|
||||
|
||||
/**
|
||||
* Recursively read all FileSystemEntry items (files and directories) from DataTransferItemList.
|
||||
@@ -209,6 +209,15 @@ export async function handleVaultDropUpload(vault, targetDir, items) {
|
||||
showToast(`${t('upload.error') || 'Upload failed'}: ${errDetail}`, 'error');
|
||||
}
|
||||
await refreshSidebarTreePreservingState();
|
||||
if (chosenTargetDir) {
|
||||
try {
|
||||
await focusPathInSidebar(chosenVault, chosenTargetDir, { alignToTop: true, expandTarget: true });
|
||||
} catch (_) { /* ignore */ }
|
||||
} else if (res?.uploaded?.[0]) {
|
||||
try {
|
||||
await focusPathInSidebar(chosenVault, res.uploaded[0], { alignToTop: true, expandTarget: true });
|
||||
} catch (_) { /* ignore */ }
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Batch upload error:', err);
|
||||
showToast(`${t('upload.error') || 'Upload failed'}: ${err.message || err}`, 'error');
|
||||
|
||||
+9
-46
@@ -513,49 +513,6 @@ export function renderFile(data) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle CSV
|
||||
if (data.is_csv) {
|
||||
area.innerHTML = `
|
||||
<div class="text-viewer-container">
|
||||
<div class="file-toolbar">
|
||||
<span class="file-info">CSV — ${escapeHtml(data.title)}</span>
|
||||
<button class="btn-action" onclick="window.open('/api/file/${encodeURIComponent(data.vault)}/download?path=${encodeURIComponent(data.path)}', '_blank')">
|
||||
<i data-lucide="download" style="width:14px;height:14px"></i> Télécharger
|
||||
</button>
|
||||
</div>
|
||||
<div class="text-viewer-body">${data.html}</div>
|
||||
</div>`;
|
||||
lucide.createIcons();
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle JSON and plain text
|
||||
if (data.is_json || data.extension === '.txt' || data.extension === '.log' || data.extension === '.yml' || data.extension === '.yaml' || data.extension === '.sh' || data.extension === '.py' || data.extension === '.js' || data.extension === '.toml' || data.extension === '.ini' || data.extension === '.cfg' || data.extension === '.conf' || data.extension === '.env') {
|
||||
// Read raw content for plain text
|
||||
fetch(`/api/file/${encodeURIComponent(data.vault)}/raw?path=${encodeURIComponent(data.path)}`)
|
||||
.then(r => r.text())
|
||||
.then(text => {
|
||||
const extClass = `lang-${data.extension.replace('.', '')}`;
|
||||
area.innerHTML = `
|
||||
<div class="text-viewer-container">
|
||||
<div class="file-toolbar">
|
||||
<span class="file-info">${escapeHtml(data.title)}</span>
|
||||
<button class="btn-action" onclick="window.open('/api/file/${encodeURIComponent(data.vault)}/download?path=${encodeURIComponent(data.path)}', '_blank')">
|
||||
<i data-lucide="download" style="width:14px;height:14px"></i> Télécharger
|
||||
</button>
|
||||
</div>
|
||||
<div class="text-viewer-body">
|
||||
<pre class="${extClass}"><code>${escapeHtml(text)}</code></pre>
|
||||
</div>
|
||||
</div>`;
|
||||
lucide.createIcons();
|
||||
})
|
||||
.catch(() => {
|
||||
area.innerHTML = `<p class="error">Erreur lors du chargement du fichier.</p>`;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle unsupported (binary) files
|
||||
if (data.unsupported) {
|
||||
const sizeStr = data.size_bytes
|
||||
@@ -652,8 +609,8 @@ export function renderFile(data) {
|
||||
|
||||
const sourceBtn = el("button", { class: "btn-action", title: "Voir la source" }, [icon("code", 14), document.createTextNode("Source")]);
|
||||
|
||||
// MD download button
|
||||
const mdBtn = el("button", { class: "btn-action", title: t("viewer.download_md") }, [icon("file-text", 14), document.createTextNode(".md")]);
|
||||
// Download raw file button (extension shown; .md label for markdown)
|
||||
const mdBtn = el("button", { class: "btn-action", title: t("viewer.download_file") || t("viewer.download_md") }, [icon("file-text", 14), document.createTextNode(data.extension || ".md")]);
|
||||
mdBtn.addEventListener("click", () => {
|
||||
const dlUrl = `/api/file/${encodeURIComponent(data.vault)}/download?path=${encodeURIComponent(data.path)}`;
|
||||
const a = document.createElement("a");
|
||||
@@ -817,10 +774,16 @@ export function renderFile(data) {
|
||||
}
|
||||
});
|
||||
|
||||
const fileActions = [copyBtn, sourceBtn];
|
||||
if (!data.is_image) fileActions.push(mdBtn);
|
||||
if (data.is_markdown) fileActions.push(pdfBtn, exportWrap, forgeBtn, tocBtn);
|
||||
if (!data.unsupported) fileActions.push(editBtn);
|
||||
fileActions.push(openNewWindowBtn, shareBtn, bookmarkBtn);
|
||||
|
||||
// Assemble
|
||||
area.innerHTML = "";
|
||||
area.appendChild(breadcrumb);
|
||||
area.appendChild(el("div", { class: "file-header" }, [el("div", { class: "file-title" }, [document.createTextNode(data.title)]), tagsDiv, el("div", { class: "file-actions" }, [copyBtn, sourceBtn, mdBtn, pdfBtn, exportWrap, editBtn, forgeBtn, openNewWindowBtn, tocBtn, shareBtn, bookmarkBtn])]));
|
||||
area.appendChild(el("div", { class: "file-header" }, [el("div", { class: "file-title" }, [document.createTextNode(data.title)]), tagsDiv, el("div", { class: "file-actions" }, fileActions)]));
|
||||
if (fmSection) area.appendChild(fmSection);
|
||||
area.appendChild(mdDiv);
|
||||
area.appendChild(rawDiv);
|
||||
|
||||
@@ -1686,6 +1686,7 @@
|
||||
"viewer.copy_error": "Copy error",
|
||||
"viewer.download": "Download",
|
||||
"viewer.download_md": "Download as .md",
|
||||
"viewer.download_file": "Download file",
|
||||
"viewer.download_pdf": "Download as PDF",
|
||||
"viewer.edit": "Edit",
|
||||
"viewer.error": "Loading error",
|
||||
|
||||
@@ -1686,6 +1686,7 @@
|
||||
"viewer.copy_error": "Erreur lors de la copie",
|
||||
"viewer.download": "Télécharger",
|
||||
"viewer.download_md": "Télécharger en .md",
|
||||
"viewer.download_file": "Télécharger le fichier",
|
||||
"viewer.download_pdf": "Télécharger en PDF",
|
||||
"viewer.edit": "Éditer",
|
||||
"viewer.error": "Erreur de chargement",
|
||||
|
||||
Reference in New Issue
Block a user