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 = ""; - }} - />
    + + ); -
    -