From 99b088acf6e46a72b30e6cfbec31c20ba798b659 Mon Sep 17 00:00:00 2001 From: claude Date: Mon, 19 Oct 2026 12:59:25 +0200 Subject: [PATCH] =?UTF-8?q?Explorateur=20:=20vue=20Galerie,=20panneau=20D?= =?UTF-8?q?=C3=A9tails=20et=20tri?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Troisième vue de l'explorateur : il couvre toute la zone de travail, dossiers en cartes et schémas en grandes tuiles (miniature 640 px, nom complet, date relative et dernier auteur, taille, versions, partages, compteurs d'éléments, tags). Le panneau Détails (bouton ⓘ ou menu) affiche création, dimensions, fond, cadres, dernières versions et liens de partage. Ouvrir un schéma referme la galerie ; ☰ ou Échap y ramène. Tri par nom, date de modification ou taille dans toutes les vues. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01PbFY8ZmoErQdPvgvAN3MBU --- frontend/src/App.tsx | 27 +- frontend/src/DetailsPanel.tsx | 201 +++++++++++ frontend/src/Explorer.tsx | 650 ++++++++++++++++++++++++---------- frontend/src/Thumb.tsx | 18 +- frontend/src/api.ts | 38 +- frontend/src/format.ts | 24 ++ frontend/src/icons.tsx | 58 +++ frontend/src/styles.css | 480 +++++++++++++++++++++++++ frontend/src/thumbs.ts | 11 +- 9 files changed, 1294 insertions(+), 213 deletions(-) create mode 100644 frontend/src/DetailsPanel.tsx create mode 100644 frontend/src/format.ts diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index e5af936..0b50dfd 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -15,7 +15,7 @@ import type { } from "@excalidraw/excalidraw/types"; import type { OrderedExcalidrawElement } from "@excalidraw/excalidraw/element/types"; import { api, ApiError, basename, displayPath, stripExt, type Settings } from "./api"; -import { Explorer } from "./Explorer"; +import { Explorer, initialView, type View } from "./Explorer"; import { CloseIcon, HistoryIcon, MenuIcon, MoonIcon, PinIcon, SaveIcon, SettingsIcon, ShareIcon, SunIcon, UpdateIcon } from "./icons"; import { ShareDialog } from "./ShareDialog"; import { HistoryDialog } from "./HistoryDialog"; @@ -97,8 +97,11 @@ export default function App() { const [scene, setScene] = useState(null); const [saveState, setSaveState] = useState("saved"); const [pinned, setPinned] = useState(initialPinned); - // Non épinglé : ouvert d'office tant qu'aucun schéma n'est demandé. - const [drawerOpen, setDrawerOpen] = useState(() => !isMobile() && (pinned || !pathFromHash())); + // Vue Galerie : l'explorateur couvre toute la zone de travail, comme un panneau + // flottant (il se referme à l'ouverture d'un schéma). + const [gallery, setGallery] = useState(() => initialView() === "gallery"); + // Non épinglé ou Galerie : ouvert d'office tant qu'aucun schéma n'est demandé. + const [drawerOpen, setDrawerOpen] = useState(() => !isMobile() && ((pinned && !gallery) || !pathFromHash())); const [instant, setInstant] = useState(false); // bascule sans animation de la grille const [refreshKey, setRefreshKey] = useState(0); const [loadError, setLoadError] = useState(null); @@ -126,6 +129,8 @@ export default function App() { const openRef = useRef<(path: string, opts?: { skipFlush?: boolean }) => Promise>(async () => {}); const pinnedRef = useRef(pinned); pinnedRef.current = pinned; + const galleryRef = useRef(gallery); + galleryRef.current = gallery; const peek = useRef<"hover" | "click" | null>(null); // comment le panneau non épinglé a été ouvert const peekTimer = useRef(undefined); const scrollShift = useRef(0); // décalage du canevas à compenser après une bascule épinglé/non épinglé @@ -240,7 +245,7 @@ export default function App() { setSaveState("saved"); if (location.hash !== `#/${path}`) history.replaceState(null, "", `#/${encodeURI(path)}`); store("lastScene", path); - if (isMobile() || !pinnedRef.current) setDrawerOpen(false); + if (isMobile() || !pinnedRef.current || galleryRef.current) setDrawerOpen(false); } catch (e) { setLoadError(`Impossible d'ouvrir « ${path} » : ${e instanceof Error ? e.message : e}`); } @@ -254,8 +259,8 @@ export default function App() { excalidraw.current = null; setScene(null); history.replaceState(null, "", location.pathname); - // Non épinglé : l'explorateur revient pour choisir le schéma suivant. - if (!pinnedRef.current && !isMobile()) { + // Non épinglé ou Galerie : l'explorateur revient pour choisir le schéma suivant. + if ((!pinnedRef.current || galleryRef.current) && !isMobile()) { peek.current = "click"; setDrawerOpen(true); } @@ -431,7 +436,10 @@ export default function App() { return () => cancelAnimationFrame(id); }, [pinned, instant]); - const floating = !pinned && drawerOpen; + // Panneau par-dessus le schéma : non épinglé, ou Galerie quand un schéma est ouvert. + const floating = drawerOpen && (!pinned || (gallery && !!scene)); + + const onViewChange = useCallback((v: View) => setGallery(v === "gallery"), []); const peekOpen = () => { clearTimeout(peekTimer.current); @@ -517,7 +525,7 @@ export default function App() { return (
@@ -626,6 +634,7 @@ export default function App() { onDeleted={onDeleted} onHistory={showHistory} onShare={setShareFor} + onViewChange={onViewChange} toolbarEnd={ +
+ + +
+ + + + +
+ +
+
Modifié
+
+ {fmtDate(e.modTime)} ({fmtRelative(e.modTime)}) + {who(e.editedBy) && par {e.editedBy}} +
+ {d.created && ( + <> +
Créé
+
+ {fmtDate(d.created)} + {who(d.createdBy) ? ( + par {d.createdBy} + ) : ( + + {" "} + (plus ancienne version) + + )} +
+ + )} +
Taille
+
{fmtSize(e.size)}
+
Contenu
+
{content.join(", ")}
+ {!!d.width && !!d.height && ( + <> +
Dimensions
+
+ {d.width.toLocaleString()} × {d.height.toLocaleString()} px +
+ + )} + {d.background && ( + <> +
Fond
+
+ + {d.background} +
+ + )} + {!!e.tags?.length && ( + <> +
Tags
+
+ {e.tags.map((t) => ( + + ))} +
+ + )} +
+ + {!!d.frameNames?.length && ( +
+

Cadres

+
    + {d.frameNames.map((f, i) => ( +
  • {f}
  • + ))} + {(d.frames ?? 0) > d.frameNames.length && ( +
  • et {d.frames! - d.frameNames.length} autres
  • + )} +
+
+ )} + +
+

Versions{versions && versions.length > 0 ? ` (${versions.length})` : ""}

+ {versions === null ? ( +

Chargement…

+ ) : versions.length === 0 ? ( +

Aucune version enregistrée

+ ) : ( +
    + {versions.slice(0, LAST_VERSIONS).map((v) => ( +
  • + {fmtDate(v.time)} + {fmtSize(v.size)} +
  • + ))} + {versions.length > LAST_VERSIONS && ( +
  • + +
  • + )} +
+ )} +
+ +
+

Partages actifs{shares && shares.length > 0 ? ` (${shares.length})` : ""}

+ {shares === null ? ( +

Chargement…

+ ) : shares.length === 0 ? ( +

Aucun lien de partage

+ ) : ( +
    + {shares.map((s) => ( +
  • + Créé le {fmtDate(s.created)} + {s.expires ? `expire le ${fmtDate(s.expires)}` : "sans expiration"} +
  • + ))} +
+ )} +
+ + ); +} diff --git a/frontend/src/Explorer.tsx b/frontend/src/Explorer.tsx index 1ae6490..2ff66ac 100644 --- a/frontend/src/Explorer.tsx +++ b/frontend/src/Explorer.tsx @@ -19,6 +19,8 @@ import { type TagCount, } from "./api"; import { + ArrowIcon, + ClockIcon, CloseIcon, DeselectIcon, CopyIcon, @@ -30,18 +32,26 @@ import { FolderIcon, FolderPlusIcon, FolderUploadIcon, + FrameIcon, + GalleryIcon, GridIcon, HistoryIcon, + InfoIcon, ListIcon, MoveIcon, + PhotoIcon, RefreshIcon, RestoreIcon, SearchIcon, SelectAllIcon, + ShapesIcon, ShareIcon, + SizeIcon, + SortIcon, StarFilledIcon, StarIcon, TagIcon, + TextIcon, TrashFullIcon, TrashIcon, UpIcon, @@ -49,12 +59,15 @@ import { UserIcon, } from "./icons"; import { ActionMenu } from "./ActionMenu"; +import { DetailsPanel } from "./DetailsPanel"; +import { fmtDate, fmtRelative, fmtSize, plural, who } from "./format"; import { FolderGlyph } from "./folderIcons"; import { IconDialog } from "./IconDialog"; import { collectDrop, collectFiles, hasFiles, type Collected } from "./importer"; import { MoveDialog } from "./MoveDialog"; import { TagsDialog } from "./TagsDialog"; import { Thumb } from "./Thumb"; +import { expectedThumb } from "./thumbs"; export const EMPTY_SCENE = JSON.stringify({ type: "excalidraw", @@ -81,38 +94,64 @@ interface Props { onShare: (path: string) => void; /** Contenu ajouté au bout de la barre de recherche (bouton d'épinglage du panneau). */ toolbarEnd?: ReactNode; + /** Changement de vue : la Galerie occupe toute la zone de travail (App). */ + onViewChange?: (view: View) => void; } -type View = "list" | "grid"; +/** Vignettes, liste, ou Galerie (grandes tuiles avec métadonnées, pleine largeur). */ +export type View = "list" | "grid" | "gallery"; -const fmtDate = (iso: string) => - new Date(iso).toLocaleString(undefined, { dateStyle: "short", timeStyle: "short" }); - -const fmtSize = (n: number) => - n < 1024 ? `${n} o` : n < 1 << 20 ? `${(n / 1024).toFixed(1)} Ko` : `${(n / (1 << 20)).toFixed(1)} Mo`; - -const plural = (n: number, word: string) => `${n} ${word}${n > 1 ? "s" : ""}`; +/** Tri de l'affichage : nom (ordre du serveur), date de modification ou taille. */ +type Sort = "name" | "modified" | "size"; const DND_TYPE = "application/x-excalidraw-paths"; -const initialView = (): View => { +const stored = (key: string, allowed: readonly T[], fallback: T): T => { try { - return localStorage.getItem("explorerView") === "list" ? "list" : "grid"; + const v = localStorage.getItem(key) as T | null; + return v && allowed.includes(v) ? v : fallback; } catch { - return "grid"; + return fallback; } }; +export const initialView = () => stored("explorerView", ["list", "grid", "gallery"], "grid"); +const initialSort = () => stored("explorerSort", ["name", "modified", "size"], "name"); + +/** Rang d'affichage : dossiers virtuels, puis dossiers, puis schémas. */ +const rank = (e: Entry) => (e.special ? 0 : e.isDir ? 1 : 2); + +const sortEntries = (list: T[], sort: Sort): T[] => { + if (sort === "name") return list; // ordre du serveur (nom ; pertinence pour une recherche) + const by = + sort === "modified" + ? (a: T, b: T) => Date.parse(b.modTime) - Date.parse(a.modTime) + : (a: T, b: T) => (a.isDir ? 0 : b.size - a.size); + return [...list].sort((a, b) => rank(a) - rank(b) || (a.special ? 0 : by(a, b))); +}; + /** Un élément peut-il être déplacé dans targetDir ? (pas sur place, pas dans lui-même) */ const canMoveInto = (path: string, targetDir: string) => dirname(path) !== targetDir && targetDir !== path && !targetDir.startsWith(path + "/"); -export function Explorer({ current, refreshKey, onOpen, onMoved, onDeleted, onHistory, onShare, toolbarEnd }: Props) { +export function Explorer({ + current, + refreshKey, + onOpen, + onMoved, + onDeleted, + onHistory, + onShare, + toolbarEnd, + onViewChange, +}: Props) { const [dir, setDir] = useState(() => (current ? dirname(current) : "")); const [entries, setEntries] = useState([]); const [query, setQuery] = useState(""); const [results, setResults] = useState(null); const [view, setView] = useState(initialView); + const [sort, setSort] = useState(initialSort); + const [inspect, setInspect] = useState(null); // schéma du panneau Détails (Galerie) const [selected, setSelected] = useState>(new Set()); const [anchor, setAnchor] = useState(null); // origine d'une sélection Maj+clic const [menu, setMenu] = useState<{ entry: Hit; anchor: HTMLElement } | null>(null); // menu « … » ouvert @@ -132,6 +171,8 @@ export function Explorer({ current, refreshKey, onOpen, onMoved, onDeleted, onHi const stay = useRef(null); // schéma ouvert depuis Favoris : on reste dans Favoris const list = results ?? entries; + const shown = sortEntries(list, sort); + const gallery = view === "gallery"; const filter = { tag: tagFilter }; const filtering = query.trim() !== "" || tagFilter !== null; // Dossier Favoris : des liens vers les originaux, ni création ni déplacement. @@ -143,6 +184,7 @@ export function Explorer({ current, refreshKey, onOpen, onMoved, onDeleted, onHi const closeMenu = useCallback(() => setMenu(null), []); // La liste change de forme : le bouton « … » d'origine disparaît. useEffect(closeMenu, [view, dir, results, closeMenu]); + useEffect(() => setInspect(null), [dir, results === null, view]); const guard = useCallback(async (fn: () => Promise) => { setError(null); @@ -156,7 +198,7 @@ export function Explorer({ current, refreshKey, onOpen, onMoved, onDeleted, onHi const refresh = useCallback( () => guard(async () => { - const [next, tagList] = await Promise.all([api.list(dir), api.tags()]); + const [next, tagList] = await Promise.all([api.list(dir, gallery), api.tags()]); setEntries(next); setTags(tagList); // Tag filtré qui n'existe plus : filtre retiré. @@ -169,7 +211,7 @@ export function Explorer({ current, refreshKey, onOpen, onMoved, onDeleted, onHi return new Set([...s].filter((p) => still.has(p))); }); }), - [dir, guard], + [dir, gallery, guard], ); useEffect(() => { @@ -194,15 +236,15 @@ export function Explorer({ current, refreshKey, onOpen, onMoved, onDeleted, onHi setResults(null); return; } - const t = setTimeout(() => guard(async () => setResults(await api.search(query, filter))), 250); + const t = setTimeout(() => guard(async () => setResults(await api.search(query, filter, gallery))), 250); return () => clearTimeout(t); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [query, tagFilter, guard, refreshKey]); + }, [query, tagFilter, guard, refreshKey, gallery]); /** Recharge le dossier et, si une recherche est affichée, ses résultats. */ const reload = async () => { await refresh(); - if (filtering) setResults(await api.search(query, filter)); + if (filtering) setResults(await api.search(query, filter, gallery)); }; // Délai de purge, affiché dans la poubelle (réglé dans les paramètres). @@ -220,7 +262,16 @@ export function Explorer({ current, refreshKey, onOpen, onMoved, onDeleted, onHi } catch { /* stockage indisponible */ } - }, [view]); + onViewChange?.(view); + }, [view, onViewChange]); + + useEffect(() => { + try { + localStorage.setItem("explorerSort", sort); + } catch { + /* stockage indisponible */ + } + }, [sort]); // --- Sélection ----------------------------------------------------------- @@ -247,7 +298,7 @@ export function Explorer({ current, refreshKey, onOpen, onMoved, onDeleted, onHi setSelected((s) => new Set([...s, ...paths.slice(lo, hi + 1)])); }; - const selectable = list.filter((e) => !e.special); + const selectable = shown.filter((e) => !e.special); const selectAll = () => setSelected(new Set(selectable.map((e) => e.path))); const onItemClick = (ev: MouseEvent, e: Entry) => { @@ -269,7 +320,10 @@ export function Explorer({ current, refreshKey, onOpen, onMoved, onDeleted, onHi const onKeyDown = (ev: KeyboardEvent) => { if ((ev.target as HTMLElement).tagName === "INPUT") return; - if (ev.key === "Escape" && selected.size > 0) { + if (ev.key === "Escape" && inspect) { + ev.preventDefault(); + setInspect(null); + } else if (ev.key === "Escape" && selected.size > 0) { ev.preventDefault(); clearSelection(); } else if ((ev.ctrlKey || ev.metaKey) && ev.key.toLowerCase() === "a") { @@ -548,7 +602,7 @@ export function Explorer({ current, refreshKey, onOpen, onMoved, onDeleted, onHi }, }; - const big = view === "grid" ? 40 : 20; + const big = view === "grid" ? 40 : gallery ? 28 : 20; const icon = (e: Entry) => e.special ? ( @@ -583,6 +637,7 @@ export function Explorer({ current, refreshKey, onOpen, onMoved, onDeleted, onHi // Dans Favoris : actions sur l'original, retrait du lien à la place de la suppression. const favActions = (e: Entry) => ( <> + {detailsAction(e)} {!e.broken && ( <> + ); + const actions = (e: Entry) => ( <> + {detailsAction(e)} + ); + + const tagChips = (e: Hit) => + !!e.tags?.length && ( + + {e.tags.map((t) => ( + + ))} + + ); + + /** Galerie : contenu d'un dossier sous son nom. */ + const dirSummary = (e: Hit) => { + const d = e.details; + if (!d) return null; + const parts = [d.files ? plural(d.files, "schéma") : "", d.dirs ? plural(d.dirs, "dossier") : ""].filter(Boolean); + return {parts.length ? parts.join(" · ") : "vide"}; + }; + + const item = (e: Hit) => { return ( -
  • +
  • onDragStart(ev, e)} {...(e.isDir ? dropProps(e.path) : {})} > - {!e.special && ( - { - ev.stopPropagation(); - if (ev.shiftKey) { - ev.preventDefault(); - selectRange(e.path); - } - }} - onChange={() => toggle(e.path)} - /> - )} + {checkbox(e)} - {!!e.tags?.length && ( - - {e.tags.map((t) => ( - - ))} + {tagChips(e)} + {(!e.isDir || trashView) && view !== "grid" && {fmtDate(e.modTime)}} + {moreButton(e)} +
    +
  • + ); + }; + + /** Galerie : tuile d'un schéma, grande miniature et métadonnées. */ + const tile = (e: Hit) => { + const d = e.details ?? {}; + const by = who(e.editedBy); + return ( +
  • +
    onDragStart(ev, e)}> + {checkbox(e)} + + {e.favorite && ( + + )} - {(!e.isDir || trashView) && view === "list" && {fmtDate(e.modTime)}} - {!e.special && ( - + + {!e.broken && ( + + )} + {moreButton(e)} + + {!e.broken && ( +
    + {(results || favView) && {where(e.path)}} + + + + {fmtRelative(e.modTime)} + {by && · {by}} + + + + + + {fmtSize(e.size)} + + {!!d.versions && ( + + + {plural(d.versions, "version")} + + )} + {!!d.shares && ( + + + {plural(d.shares, "partage")} + + )} + + + + + {d.elements ? plural(d.elements, "élément") : "vide"} + + {!!d.texts && ( + + + {plural(d.texts, "texte")} + + )} + {!!d.arrows && ( + + + {plural(d.arrows, "flèche")} + + )} + {!!d.images && ( + + + {plural(d.images, "image")} + + )} + {!!d.frames && ( + + + {plural(d.frames, "cadre")} + + )} + + {tagChips(e)} + {e.snippet && {e.snippet}} +
    )}
  • ); }; - return ( -
    -
    - - - - - { - if (ev.target.files) importTree(collectFiles(ev.target.files), importDir); - ev.target.value = ""; - }} - /> - { - if (ev.target.files) importTree(collectFiles(ev.target.files), importDir); - ev.target.value = ""; - }} - />
    + + ); -
    -