- Chaque modification est écrite dans src/config.draft.json ; config.json ne change qu'au clic sur Enregistrer. L'aperçu affiche le brouillon tant qu'il existe. - Nouveau bouton "Rétablir l'original" qui abandonne le brouillon. - Le catalogue YunoHost est filtré côté éditeur selon l'état courant : une app retirée avec la croix y réapparaît immédiatement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
632 lines
20 KiB
JavaScript
632 lines
20 KiB
JavaScript
let state = null;
|
|
let dirty = false;
|
|
let dragSource = null; // { appId }, { groupId } or { catalogApp } currently being dragged
|
|
let catalog = []; // toutes les apps installees sur YunoHost (voir /__catalog)
|
|
let catalogError = null;
|
|
|
|
const PALETTE = [
|
|
"#1db9c3", "#ff5a1f", "#2094f3", "#ffc230", "#00a651", "#e6721a",
|
|
"#b71c1c", "#f39c12", "#0d3b66", "#3b8a8c", "#568d34", "#609926",
|
|
"#d24939", "#0066cc", "#8e44ad", "#16a085", "#c0392b", "#2c3e50",
|
|
];
|
|
|
|
function uid(prefix) {
|
|
return `${prefix}-${Math.random().toString(36).slice(2, 8)}`;
|
|
}
|
|
|
|
function initialsOf(name) {
|
|
const words = name.trim().split(/\s+/);
|
|
if (words.length === 1) return words[0].slice(0, 2).toUpperCase();
|
|
return (words[0][0] + words[1][0]).toUpperCase();
|
|
}
|
|
|
|
function colorOf(name) {
|
|
let hash = 0;
|
|
for (let i = 0; i < name.length; i++) hash = (hash * 31 + name.charCodeAt(i)) >>> 0;
|
|
return PALETTE[hash % PALETTE.length];
|
|
}
|
|
|
|
function setStatus(text, kind) {
|
|
const el = document.getElementById("status");
|
|
el.textContent = text;
|
|
el.className = "status" + (kind ? " " + kind : "");
|
|
}
|
|
|
|
// Les modifications sont ecrites dans un brouillon (config.draft.json) que
|
|
// l'apercu utilise ; config.json ne change qu'au clic sur Enregistrer.
|
|
let draftTimer = null;
|
|
let draftWrite = Promise.resolve();
|
|
|
|
function setDirty(value) {
|
|
dirty = value;
|
|
document.getElementById("revert-btn").disabled = !value;
|
|
if (value) setStatus("Brouillon non enregistré");
|
|
}
|
|
|
|
function writeDraft() {
|
|
draftTimer = null;
|
|
const body = JSON.stringify(state, null, 2);
|
|
draftWrite = draftWrite
|
|
.then(() => fetch("/__draft", { method: "POST", headers: { "Content-Type": "application/json" }, body }))
|
|
.then((res) => { if (!res.ok) throw new Error(res.statusText); })
|
|
.catch((err) => {
|
|
setStatus("Erreur d'écriture du brouillon", "error");
|
|
console.error(err);
|
|
});
|
|
return draftWrite;
|
|
}
|
|
|
|
function cancelPendingDraft() {
|
|
if (draftTimer) clearTimeout(draftTimer);
|
|
draftTimer = null;
|
|
}
|
|
|
|
function markDirty() {
|
|
setDirty(true);
|
|
cancelPendingDraft();
|
|
draftTimer = setTimeout(writeDraft, 300);
|
|
}
|
|
|
|
function normalizeUrl(url) {
|
|
return (url || "").replace(/^https?:\/\//, "").replace(/\/+$/, "").toLowerCase();
|
|
}
|
|
|
|
// Apps du catalogue YunoHost pas encore presentes dans le portail. Calcule
|
|
// a chaque rendu depuis l'etat courant : une app supprimee avec la croix
|
|
// y reapparait aussitot, une app ajoutee en disparait.
|
|
function availableCatalog() {
|
|
const used = new Set();
|
|
const all = [...(state.pinned || []), ...state.ungrouped, ...state.groups.flatMap((g) => g.apps)];
|
|
all.forEach((a) => used.add(normalizeUrl(a.url)));
|
|
return catalog.filter((a) => !used.has(normalizeUrl(a.url)));
|
|
}
|
|
|
|
function findAppLocation(appId) {
|
|
const pinnedIdx = (state.pinned || []).findIndex((a) => a.id === appId);
|
|
if (pinnedIdx !== -1) return { list: state.pinned, index: pinnedIdx };
|
|
for (const group of state.groups) {
|
|
const idx = group.apps.findIndex((a) => a.id === appId);
|
|
if (idx !== -1) return { list: group.apps, index: idx };
|
|
}
|
|
const idx = state.ungrouped.findIndex((a) => a.id === appId);
|
|
if (idx !== -1) return { list: state.ungrouped, index: idx };
|
|
return null;
|
|
}
|
|
|
|
function computeDropIndexGrid(containerEl, clientX, clientY) {
|
|
const items = Array.from(containerEl.querySelectorAll(":scope > .app-tile"));
|
|
if (items.length === 0) return 0;
|
|
let closestIndex = items.length;
|
|
let closestDist = Infinity;
|
|
items.forEach((item, i) => {
|
|
const rect = item.getBoundingClientRect();
|
|
const cx = rect.left + rect.width / 2;
|
|
const cy = rect.top + rect.height / 2;
|
|
const dist = Math.hypot(clientX - cx, clientY - cy);
|
|
if (dist < closestDist) {
|
|
closestDist = dist;
|
|
closestIndex = clientX < cx ? i : i + 1;
|
|
}
|
|
});
|
|
return closestIndex;
|
|
}
|
|
|
|
function computeDropIndexList(containerEl, selector, clientY) {
|
|
const items = Array.from(containerEl.querySelectorAll(selector));
|
|
if (items.length === 0) return 0;
|
|
let closestIndex = items.length;
|
|
let closestDist = Infinity;
|
|
items.forEach((item, i) => {
|
|
const rect = item.getBoundingClientRect();
|
|
const cy = rect.top + rect.height / 2;
|
|
const dist = Math.abs(clientY - cy);
|
|
if (dist < closestDist) {
|
|
closestDist = dist;
|
|
closestIndex = clientY < cy ? i : i + 1;
|
|
}
|
|
});
|
|
return closestIndex;
|
|
}
|
|
|
|
function renderTile(app) {
|
|
const tile = document.createElement("div");
|
|
tile.className = "app-tile";
|
|
tile.draggable = true;
|
|
tile.dataset.appId = app.id;
|
|
|
|
tile.addEventListener("dragstart", (e) => {
|
|
e.stopPropagation();
|
|
dragSource = { appId: app.id };
|
|
e.dataTransfer.effectAllowed = "move";
|
|
e.dataTransfer.setData("text/plain", app.id);
|
|
tile.classList.add("dragging");
|
|
});
|
|
tile.addEventListener("dragend", (e) => {
|
|
e.stopPropagation();
|
|
tile.classList.remove("dragging");
|
|
dragSource = null;
|
|
});
|
|
|
|
const removeBtn = document.createElement("button");
|
|
removeBtn.className = "remove-btn";
|
|
removeBtn.textContent = "✕";
|
|
removeBtn.title = "Supprimer cette application";
|
|
removeBtn.addEventListener("click", () => {
|
|
if (!confirm(`Retirer "${app.name}" de la page ?`)) return;
|
|
const loc = findAppLocation(app.id);
|
|
if (loc) loc.list.splice(loc.index, 1);
|
|
markDirty();
|
|
render();
|
|
});
|
|
|
|
const icon = document.createElement("div");
|
|
icon.className = "tile-icon";
|
|
if (app.icon) {
|
|
const img = document.createElement("img");
|
|
img.src = app.icon;
|
|
img.alt = "";
|
|
icon.appendChild(img);
|
|
} else {
|
|
icon.style.background = app.color || "#8e8e8e";
|
|
icon.textContent = app.initials || initialsOf(app.name);
|
|
}
|
|
|
|
const name = document.createElement("div");
|
|
name.className = "tile-name";
|
|
name.textContent = app.name;
|
|
|
|
tile.appendChild(removeBtn);
|
|
tile.appendChild(icon);
|
|
tile.appendChild(name);
|
|
return tile;
|
|
}
|
|
|
|
function renderAddTile(onAdd) {
|
|
const add = document.createElement("button");
|
|
add.className = "add-tile";
|
|
add.type = "button";
|
|
add.textContent = "+";
|
|
add.title = "Ajouter une application";
|
|
add.addEventListener("click", onAdd);
|
|
return add;
|
|
}
|
|
|
|
function attachGridDropzone(gridEl, targetListGetter) {
|
|
gridEl.addEventListener("dragover", (e) => {
|
|
if (!dragSource || (!dragSource.appId && !dragSource.catalogApp)) return;
|
|
e.preventDefault();
|
|
gridEl.classList.add("drag-over");
|
|
});
|
|
gridEl.addEventListener("dragleave", () => {
|
|
gridEl.classList.remove("drag-over");
|
|
});
|
|
gridEl.addEventListener("drop", (e) => {
|
|
e.preventDefault();
|
|
gridEl.classList.remove("drag-over");
|
|
if (!dragSource) return;
|
|
const targetList = targetListGetter();
|
|
const dropIndex = computeDropIndexGrid(gridEl, e.clientX, e.clientY);
|
|
|
|
if (dragSource.catalogApp) {
|
|
const app = { ...dragSource.catalogApp };
|
|
targetList.splice(Math.min(dropIndex, targetList.length), 0, app);
|
|
markDirty();
|
|
render();
|
|
return;
|
|
}
|
|
|
|
if (dragSource.appId) {
|
|
const loc = findAppLocation(dragSource.appId);
|
|
if (!loc) return;
|
|
const [app] = loc.list.splice(loc.index, 1);
|
|
targetList.splice(Math.min(dropIndex, targetList.length), 0, app);
|
|
markDirty();
|
|
render();
|
|
}
|
|
});
|
|
}
|
|
|
|
function addCatalogAppTo(app, targetList) {
|
|
targetList.push({ ...app });
|
|
markDirty();
|
|
render();
|
|
}
|
|
|
|
function renderCatalogTile(app) {
|
|
const tile = document.createElement("div");
|
|
tile.className = "app-tile catalog-tile";
|
|
tile.draggable = true;
|
|
tile.title = "Glisser dans le portail, ou cliquer pour ajouter dans \"Sans groupe\"";
|
|
|
|
tile.addEventListener("dragstart", (e) => {
|
|
e.stopPropagation();
|
|
dragSource = { catalogApp: app };
|
|
e.dataTransfer.effectAllowed = "copy";
|
|
e.dataTransfer.setData("text/plain", app.id);
|
|
tile.classList.add("dragging");
|
|
});
|
|
tile.addEventListener("dragend", (e) => {
|
|
e.stopPropagation();
|
|
tile.classList.remove("dragging");
|
|
dragSource = null;
|
|
});
|
|
tile.addEventListener("click", () => {
|
|
state.ungrouped = state.ungrouped || [];
|
|
addCatalogAppTo(app, state.ungrouped);
|
|
});
|
|
|
|
const icon = document.createElement("div");
|
|
icon.className = "tile-icon";
|
|
if (app.icon) {
|
|
const img = document.createElement("img");
|
|
img.src = app.icon;
|
|
img.alt = "";
|
|
icon.appendChild(img);
|
|
} else {
|
|
icon.style.background = app.color || "#8e8e8e";
|
|
icon.textContent = app.initials || initialsOf(app.name);
|
|
}
|
|
|
|
const name = document.createElement("div");
|
|
name.className = "tile-name";
|
|
name.textContent = app.name;
|
|
|
|
tile.appendChild(icon);
|
|
tile.appendChild(name);
|
|
return tile;
|
|
}
|
|
|
|
function renderCatalogColumn(title, apps) {
|
|
const column = document.createElement("aside");
|
|
column.className = "catalog-column";
|
|
|
|
const heading = document.createElement("h2");
|
|
heading.textContent = title;
|
|
column.appendChild(heading);
|
|
|
|
if (catalogError) {
|
|
const msg = document.createElement("p");
|
|
msg.className = "catalog-message catalog-error";
|
|
msg.textContent = catalogError;
|
|
column.appendChild(msg);
|
|
return column;
|
|
}
|
|
|
|
if (apps.length === 0) {
|
|
const msg = document.createElement("p");
|
|
msg.className = "catalog-message";
|
|
msg.textContent = "Aucune app à ajouter.";
|
|
column.appendChild(msg);
|
|
return column;
|
|
}
|
|
|
|
const list = document.createElement("div");
|
|
list.className = "catalog-list";
|
|
apps.forEach((app) => list.appendChild(renderCatalogTile(app)));
|
|
column.appendChild(list);
|
|
return column;
|
|
}
|
|
|
|
function openAppForm(onSubmit) {
|
|
const backdrop = document.createElement("div");
|
|
backdrop.className = "app-form-backdrop";
|
|
|
|
const form = document.createElement("form");
|
|
form.className = "app-form";
|
|
form.innerHTML = `
|
|
<h3>Nouvelle application</h3>
|
|
<label>Nom
|
|
<input type="text" name="name" required placeholder="Ex: Navidrome" />
|
|
</label>
|
|
<label>URL
|
|
<input type="url" name="url" required placeholder="https://sous-domaine.tondomaine.exemple/" />
|
|
</label>
|
|
<label>Icône (optionnel, sinon détection auto)
|
|
<input type="url" name="icon" placeholder="https://..." />
|
|
</label>
|
|
<div class="app-form-actions">
|
|
<button type="button" class="btn btn-outline" data-cancel>Annuler</button>
|
|
<button type="submit" class="btn btn-primary">Ajouter</button>
|
|
</div>
|
|
`;
|
|
|
|
backdrop.appendChild(form);
|
|
document.body.appendChild(backdrop);
|
|
form.querySelector('input[name="name"]').focus();
|
|
|
|
backdrop.addEventListener("click", (e) => {
|
|
if (e.target === backdrop) backdrop.remove();
|
|
});
|
|
form.querySelector("[data-cancel]").addEventListener("click", () => backdrop.remove());
|
|
|
|
form.addEventListener("submit", (e) => {
|
|
e.preventDefault();
|
|
const data = new FormData(form);
|
|
const name = data.get("name").trim();
|
|
const url = data.get("url").trim();
|
|
const icon = data.get("icon").trim();
|
|
if (!name || !url) return;
|
|
const app = {
|
|
id: uid("app"),
|
|
name,
|
|
url,
|
|
color: colorOf(name),
|
|
initials: initialsOf(name),
|
|
};
|
|
if (icon) app.icon = icon;
|
|
onSubmit(app);
|
|
backdrop.remove();
|
|
});
|
|
}
|
|
|
|
function renderGroup(group, index) {
|
|
const card = document.createElement("section");
|
|
card.className = "group-card";
|
|
card.draggable = true;
|
|
card.dataset.groupId = group.id;
|
|
|
|
card.addEventListener("dragstart", (e) => {
|
|
dragSource = { groupId: group.id };
|
|
e.dataTransfer.effectAllowed = "move";
|
|
e.dataTransfer.setData("text/plain", group.id);
|
|
card.classList.add("dragging");
|
|
});
|
|
card.addEventListener("dragend", () => {
|
|
card.classList.remove("dragging");
|
|
dragSource = null;
|
|
});
|
|
|
|
const header = document.createElement("div");
|
|
header.className = "group-header";
|
|
|
|
const handle = document.createElement("span");
|
|
handle.className = "drag-handle";
|
|
handle.textContent = "⠿";
|
|
handle.title = "Glisser pour réordonner les groupes";
|
|
|
|
const nameInput = document.createElement("input");
|
|
nameInput.className = "group-name-input";
|
|
nameInput.value = group.name;
|
|
nameInput.draggable = false;
|
|
nameInput.addEventListener("input", () => {
|
|
group.name = nameInput.value;
|
|
markDirty();
|
|
});
|
|
nameInput.addEventListener("mousedown", (e) => e.stopPropagation());
|
|
|
|
const collapsedLabel = document.createElement("label");
|
|
collapsedLabel.className = "group-collapsed-label";
|
|
const collapsedCheckbox = document.createElement("input");
|
|
collapsedCheckbox.type = "checkbox";
|
|
collapsedCheckbox.checked = !!group.collapsed;
|
|
collapsedCheckbox.addEventListener("change", () => {
|
|
group.collapsed = collapsedCheckbox.checked;
|
|
markDirty();
|
|
});
|
|
collapsedLabel.appendChild(collapsedCheckbox);
|
|
collapsedLabel.appendChild(document.createTextNode("replié par défaut"));
|
|
|
|
const deleteBtn = document.createElement("button");
|
|
deleteBtn.className = "icon-btn";
|
|
deleteBtn.textContent = "✕";
|
|
deleteBtn.title = "Supprimer le groupe (les apps repassent en \"Sans groupe\")";
|
|
deleteBtn.addEventListener("click", () => {
|
|
if (!confirm(`Supprimer le groupe "${group.name}" ? Les apps repasseront en "Sans groupe".`)) return;
|
|
state.ungrouped.push(...group.apps);
|
|
state.groups.splice(index, 1);
|
|
markDirty();
|
|
render();
|
|
});
|
|
|
|
header.appendChild(handle);
|
|
header.appendChild(nameInput);
|
|
header.appendChild(collapsedLabel);
|
|
header.appendChild(deleteBtn);
|
|
|
|
const grid = document.createElement("div");
|
|
grid.className = "tile-grid";
|
|
group.apps.forEach((app) => grid.appendChild(renderTile(app)));
|
|
grid.appendChild(renderAddTile(() => {
|
|
openAppForm((app) => {
|
|
group.apps.push(app);
|
|
markDirty();
|
|
render();
|
|
});
|
|
}));
|
|
attachGridDropzone(grid, () => group.apps);
|
|
|
|
card.appendChild(header);
|
|
card.appendChild(grid);
|
|
return card;
|
|
}
|
|
|
|
function attachGroupsDropzone(containerEl) {
|
|
containerEl.addEventListener("dragover", (e) => {
|
|
if (!dragSource || !dragSource.groupId) return;
|
|
e.preventDefault();
|
|
});
|
|
containerEl.addEventListener("drop", (e) => {
|
|
if (!dragSource || !dragSource.groupId) return;
|
|
e.preventDefault();
|
|
const groupId = dragSource.groupId;
|
|
const fromIndex = state.groups.findIndex((g) => g.id === groupId);
|
|
if (fromIndex === -1) return;
|
|
const [group] = state.groups.splice(fromIndex, 1);
|
|
const dropIndex = computeDropIndexList(containerEl, ".group-card", e.clientY);
|
|
state.groups.splice(Math.min(dropIndex, state.groups.length), 0, group);
|
|
markDirty();
|
|
render();
|
|
});
|
|
}
|
|
|
|
function render() {
|
|
const root = document.getElementById("editor-root");
|
|
root.innerHTML = "";
|
|
|
|
const layout = document.createElement("div");
|
|
layout.className = "editor-layout";
|
|
|
|
const available = availableCatalog();
|
|
const half = Math.ceil(available.length / 2);
|
|
const leftCatalog = renderCatalogColumn("Catalogue YunoHost", available.slice(0, half));
|
|
const rightCatalog = renderCatalogColumn("Catalogue YunoHost", available.slice(half));
|
|
|
|
const center = document.createElement("div");
|
|
center.className = "editor-center";
|
|
|
|
layout.appendChild(leftCatalog);
|
|
layout.appendChild(center);
|
|
layout.appendChild(rightCatalog);
|
|
root.appendChild(layout);
|
|
|
|
const pinnedSection = document.createElement("section");
|
|
pinnedSection.className = "pinned-section";
|
|
const pinnedHeading = document.createElement("h2");
|
|
pinnedHeading.textContent = "Épinglées (en haut de la page)";
|
|
pinnedSection.appendChild(pinnedHeading);
|
|
|
|
const pinnedGrid = document.createElement("div");
|
|
pinnedGrid.className = "tile-grid";
|
|
(state.pinned || []).forEach((app) => pinnedGrid.appendChild(renderTile(app)));
|
|
pinnedGrid.appendChild(renderAddTile(() => {
|
|
openAppForm((app) => {
|
|
state.pinned = state.pinned || [];
|
|
state.pinned.push(app);
|
|
markDirty();
|
|
render();
|
|
});
|
|
}));
|
|
attachGridDropzone(pinnedGrid, () => (state.pinned = state.pinned || []));
|
|
pinnedSection.appendChild(pinnedGrid);
|
|
center.appendChild(pinnedSection);
|
|
|
|
const groupsList = document.createElement("div");
|
|
groupsList.id = "groups-list";
|
|
state.groups.forEach((group, i) => groupsList.appendChild(renderGroup(group, i)));
|
|
attachGroupsDropzone(groupsList);
|
|
center.appendChild(groupsList);
|
|
|
|
const addGroupBtn = document.createElement("button");
|
|
addGroupBtn.className = "add-group-btn";
|
|
addGroupBtn.type = "button";
|
|
addGroupBtn.textContent = "+ Nouveau groupe";
|
|
addGroupBtn.addEventListener("click", () => {
|
|
state.groups.push({ id: uid("group"), name: "Nouveau groupe", collapsed: false, apps: [] });
|
|
markDirty();
|
|
render();
|
|
});
|
|
center.appendChild(addGroupBtn);
|
|
|
|
const ungroupedSection = document.createElement("section");
|
|
ungroupedSection.className = "ungrouped-section";
|
|
const heading = document.createElement("h2");
|
|
heading.textContent = "Sans groupe";
|
|
ungroupedSection.appendChild(heading);
|
|
|
|
const ungroupedGrid = document.createElement("div");
|
|
ungroupedGrid.className = "tile-grid";
|
|
state.ungrouped.forEach((app) => ungroupedGrid.appendChild(renderTile(app)));
|
|
ungroupedGrid.appendChild(renderAddTile(() => {
|
|
openAppForm((app) => {
|
|
state.ungrouped.push(app);
|
|
markDirty();
|
|
render();
|
|
});
|
|
}));
|
|
attachGridDropzone(ungroupedGrid, () => state.ungrouped);
|
|
ungroupedSection.appendChild(ungroupedGrid);
|
|
|
|
center.appendChild(ungroupedSection);
|
|
}
|
|
|
|
async function loadCatalog() {
|
|
try {
|
|
const res = await fetch("/__catalog", { cache: "no-store" });
|
|
const data = await res.json();
|
|
if (data.error) {
|
|
catalog = [];
|
|
catalogError = data.error;
|
|
} else {
|
|
catalog = data.apps || [];
|
|
catalogError = null;
|
|
}
|
|
} catch (err) {
|
|
catalog = [];
|
|
catalogError = "Catalogue indisponible (aperçu local requis).";
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
async function load() {
|
|
const res = await fetch("config.json", { cache: "no-store" });
|
|
state = await res.json();
|
|
setDirty(res.headers.get("X-Homepage-Draft") === "1");
|
|
await loadCatalog();
|
|
render();
|
|
}
|
|
|
|
async function revert() {
|
|
if (!confirm("Abandonner toutes les modifications non enregistrées et revenir à la dernière version enregistrée ?")) return;
|
|
cancelPendingDraft();
|
|
try {
|
|
await draftWrite;
|
|
const res = await fetch("/__discard", { method: "POST" });
|
|
if (!res.ok) throw new Error(await res.text());
|
|
const orig = await fetch("/__original", { cache: "no-store" });
|
|
state = await orig.json();
|
|
setDirty(false);
|
|
render();
|
|
setStatus("Original rétabli ✓", "saved");
|
|
setTimeout(() => setStatus(""), 2000);
|
|
} catch (err) {
|
|
setStatus("Erreur lors du rétablissement", "error");
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
async function save() {
|
|
cancelPendingDraft();
|
|
await draftWrite;
|
|
try {
|
|
const res = await fetch("/__save", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(state, null, 2),
|
|
});
|
|
if (!res.ok) throw new Error(await res.text());
|
|
setDirty(false);
|
|
setStatus("Enregistré ✓", "saved");
|
|
setTimeout(() => setStatus(""), 2000);
|
|
} catch (err) {
|
|
setStatus("Erreur d'enregistrement", "error");
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
async function exportToOutput() {
|
|
await save();
|
|
try {
|
|
const res = await fetch("/__export", { method: "POST" });
|
|
if (!res.ok) throw new Error(await res.text());
|
|
setStatus("Exporté vers output/ ✓", "saved");
|
|
setTimeout(() => setStatus(""), 2500);
|
|
} catch (err) {
|
|
setStatus("Erreur d'export", "error");
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
document.getElementById("save-btn").addEventListener("click", save);
|
|
document.getElementById("export-btn").addEventListener("click", exportToOutput);
|
|
document.getElementById("revert-btn").addEventListener("click", revert);
|
|
|
|
// Le brouillon est sur disque : fermer ou recharger l'editeur ne perd rien,
|
|
// il suffit d'envoyer la derniere modification si elle est encore en attente.
|
|
window.addEventListener("pagehide", () => {
|
|
if (!draftTimer) return;
|
|
cancelPendingDraft();
|
|
navigator.sendBeacon("/__draft", new Blob([JSON.stringify(state)], { type: "application/json" }));
|
|
});
|
|
|
|
load();
|