Historique des versions : snapshots horodatés, différences, restauration

- Avant d'écraser un schéma, le contenu précédent est copié dans
  DATA_DIR/.history/<chemin>/<date>.excalidraw, au plus une version par
  HISTORY_INTERVAL (10 min) ; rétention HISTORY_KEEP (50) et HISTORY_MAX_AGE.
  Pas de git : l'image reste distroless.
- API : GET /api/history, GET /api/history/version, POST /api/history/snapshot,
  POST /api/history/restore (le contenu remplacé devient une version).
- L'historique suit renommages et déplacements, part à la corbeille avec le
  schéma supprimé.
- Dialogue Historique (barre du haut, menu de l'explorateur) : aperçu,
  différences colorées avec l'état actuel, restaurer, restaurer en copie,
  créer une version.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H6J7vKwXx7uopxKhWfFJpm
This commit is contained in:
claude BotandClaude Opus 5.5 committed 2026-10-07 18:03:08 +02:00
1 parent 88f7750577
commit 9f9ec3b3a4
14 files changed
+1005 -7

No files matched your search

+47 -1
View File
@@ -16,7 +16,8 @@ import type {
import type { OrderedExcalidrawElement } from "@excalidraw/excalidraw/element/types";
import { api, ApiError, basename, stripExt, type Settings } from "./api";
import { Explorer } from "./Explorer";
import { CloseIcon, MenuIcon, MoonIcon, SaveIcon, SettingsIcon, SunIcon, UpdateIcon } from "./icons";
import { CloseIcon, HistoryIcon, MenuIcon, MoonIcon, SaveIcon, SettingsIcon, SunIcon, UpdateIcon } from "./icons";
import { HistoryDialog } from "./HistoryDialog";
import { Splitter } from "./Splitter";
import { SettingsDialog, DEFAULT_TITLE } from "./SettingsDialog";
import { pendingVersion, useUpdateStatus } from "./update";
@@ -91,6 +92,7 @@ export default function App() {
const updateStatus = useUpdateStatus();
const pending = pendingVersion(updateStatus, settings.channel);
const [customizing, setCustomizing] = useState<false | "all" | "excalidraw">(false);
const [historyFor, setHistoryFor] = useState<string | null>(null);
const excalidraw = useRef<ExcalidrawImperativeAPI | null>(null);
const pathRef = useRef<string | null>(null); // schéma ouvert (survit aux renommages)
@@ -335,6 +337,28 @@ export default function App() {
[closeFile],
);
// --- Historique -------------------------------------------------------------
/** Les modifications en cours sont enregistrées avant d'afficher l'historique. */
const showHistory = useCallback(
async (path: string) => {
if (path === pathRef.current) await save();
setHistoryFor(path);
},
[save],
);
const restoreVersion = useCallback(
async (path: string, id: string) => {
const open = path === pathRef.current;
if (open) await save();
await api.restore(path, id);
if (open) await openFile(path, { skipFlush: true });
setRefreshKey((k) => k + 1);
},
[save, openFile],
);
// --- Rendu -----------------------------------------------------------------
return (
@@ -378,6 +402,14 @@ export default function App() {
<SaveIcon />
<span className="save-label">Enregistrer</span>
</button>
<button
className="icon-btn"
aria-label="Historique des versions"
title="Historique des versions"
onClick={() => showHistory(scene.path)}
>
<HistoryIcon />
</button>
<button
className="icon-btn"
aria-label="Fermer le schéma"
@@ -425,6 +457,7 @@ export default function App() {
onOpen={(p) => openFile(p)}
onMoved={onMoved}
onDeleted={onDeleted}
onHistory={showHistory}
/>
</aside>
<Splitter
@@ -461,6 +494,19 @@ export default function App() {
)}
</main>
{historyFor && (
<HistoryDialog
path={historyFor}
theme={theme}
onRestore={(id) => restoreVersion(historyFor, id)}
onCopied={(p) => {
setRefreshKey((k) => k + 1);
openFile(p);
}}
onClose={() => setHistoryFor(null)}
/>
)}
{customizing && (
<SettingsDialog
settings={settings}