diff --git a/.beads/interactions.jsonl b/.beads/interactions.jsonl index 2bfefce..9907c93 100644 --- a/.beads/interactions.jsonl +++ b/.beads/interactions.jsonl @@ -80,3 +80,4 @@ {"id":"int-546d77a68ba5ad057a169404eb1c03fc","kind":"field_change","created_at":"2026-10-13T09:35:38.973521104Z","actor":"Shinuwa","issue_id":"sokko-g-6zp","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Sélecteurs Aniimo et Timer ciblés, course du scénario de couverture synchronisée, puis npm run check:full validé : 145 tests Node, 178 E2E développement et 2 E2E production."}} {"id":"int-509322d17a6683aaacd412fad424ae68","kind":"field_change","created_at":"2026-10-14T09:42:58.067800508Z","actor":"Shinuwa","issue_id":"sokko-g-9bu","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Mutations IndexedDB atomiques par ressource, conflits explicites et rafraîchissement BroadcastChannel ajoutés. Exports cohérents et médias différés préservés. Validation : npm run check, 181 E2E, 2 E2E production et profil toolbox complet."}} {"id":"int-3406330031f4841c323e62202c4a3c1e","kind":"field_change","created_at":"2026-10-14T14:53:56.830663059Z","actor":"Shinuwa","issue_id":"sokko-g-0la","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Import JSON v2 validé intégralement avant écriture : enveloppes, 17 types, IDs, espaces et références ; refus atomique, remappage global, concurrence, documentation et suites check/E2E vertes."}} +{"id":"int-a4a671aa3d78d0fd93b9b59398a2d7ef","kind":"field_change","created_at":"2026-10-14T17:47:01.41961034Z","actor":"Shinuwa","issue_id":"sokko-g-0lf","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Shared modal behavior implemented and validated across all dialog workflows"}} diff --git a/DESIGN_SYSTEM.md b/DESIGN_SYSTEM.md index 529c951..bff8b00 100644 --- a/DESIGN_SYSTEM.md +++ b/DESIGN_SYSTEM.md @@ -656,7 +656,12 @@ Modales : - fond floute mais pas trop opaque ; - panneau centre ; - fermeture au clic exterieur quand l'action le permet ; -- boutons icones pour fermer/zoomer quand approprie. +- boutons icones pour fermer/zoomer quand approprie ; +- les fenêtres applicatives utilisent la primitive React `Modal`, rendue dans `document.body` avec la surface NDS existante plutôt qu'un `` natif afin de conserver les portails, les raccourcis métier et l'empilement actuel ; +- à l'ouverture, le focus entre dans la fenêtre ; `Tab` et `Shift+Tab` restent confinés, `Échap` ne ferme que la fenêtre au sommet, puis le focus revient au déclencheur encore présent ; +- l'arrière-plan et les fenêtres recouvertes sont `inert` et retirés de l'arbre d'accessibilité jusqu'à leur réactivation ; le scroll de page reste bloqué jusqu'à la fermeture de la dernière fenêtre ; +- une opération non annulable en cours désactive la fermeture par backdrop et par `Échap` ; une confirmation dangereuse place le focus initial sur l'annulation ; +- `data-modal-initial-focus` désigne la cible initiale quand le premier contrôle interactif n'est pas le meilleur point d'entrée. - la visionneuse d'un outil Images peut recevoir la collection du bloc courant : sa galerie utilise de grandes cards commutables entre `4:3` et `1:1`, avec image non recadrée et libellé toujours visible, dans un flux responsive centré et scrollable uniquement verticalement ; un bouton texte affiche le ratio actif, tandis que les boutons `−` et `+` règlent leur largeur de 180 à 420 px par paliers de 40 px ; le ratio et la largeur sont mémorisés comme préférences locales ; les gouttières entre cards restent compactes tandis que le bord de la galerie conserve un padding plus généreux ; - la vue detaillee expose la position, un retour explicite a la galerie et des boutons precedent/suivant bloques aux extremites ; les fleches gauche/droite reprennent cette navigation ; - une visionneuse d'image seule, notamment pour les annotations, ne doit afficher ni galerie ni navigation de collection. diff --git a/e2e/editor-lifecycle.spec.js b/e2e/editor-lifecycle.spec.js index 89beeb6..302939c 100644 --- a/e2e/editor-lifecycle.spec.js +++ b/e2e/editor-lifecycle.spec.js @@ -37,7 +37,9 @@ async function setup(page, kind, props = {}) { } window.editorProbe = mountEditorProbe(element, kind, props); }, { url: probeUrl, kind, props }); - return page.locator("#editor-probe"); + return kind === "cover" || kind === "viewer" + ? page.locator("[data-modal-layer]").last() + : page.locator("#editor-probe"); } test("RNG drafts follow rate and module identity without losing unrelated edits", async ({ page }) => { diff --git a/e2e/fixtures/editor-lifecycle-probe.js b/e2e/fixtures/editor-lifecycle-probe.js index a0726ba..48778db 100644 --- a/e2e/fixtures/editor-lifecycle-probe.js +++ b/e2e/fixtures/editor-lifecycle-probe.js @@ -18,7 +18,10 @@ export function mountEditorProbe(element, kind, initialProps) { const [props, setProps] = useState(initialProps); updateProps = setProps; useLayoutEffect(() => { - snapshots.push(Array.from(element.querySelectorAll("input"), (input) => input.value)); + const renderedSurface = kind === "cover" || kind === "viewer" + ? element.ownerDocument.querySelector("[data-modal-layer]:not([inert])") + : element; + snapshots.push(Array.from(renderedSurface?.querySelectorAll("input") || [], (input) => input.value)); }); const context = { getModuleData: () => props.data, diff --git a/e2e/modal-accessibility.spec.js b/e2e/modal-accessibility.spec.js new file mode 100644 index 0000000..bbabda3 --- /dev/null +++ b/e2e/modal-accessibility.spec.js @@ -0,0 +1,61 @@ +// Rôle : vérifie au clavier le focus, l'arrière-plan et la restitution des modales communes. +import { expect, test } from "@playwright/test"; +import { resetSokkoStorage } from "./helpers/storage.js"; + +test("common modals trap focus, close with Escape and restore their trigger at compact desktop size", async ({ page }) => { + await page.setViewportSize({ width: 768, height: 720 }); + await resetSokkoStorage(page); + await page.goto("/#/toolboxes"); + + const createTrigger = page.getByRole("button", { name: "Nouvelle toolbox", exact: true }); + await createTrigger.click(); + let dialog = page.getByRole("dialog", { name: "Nouvelle toolbox", exact: true }); + const nameInput = dialog.getByLabel("Nom"); + await expect(nameInput).toBeFocused(); + await expect(page.locator("#app")).toHaveAttribute("inert", ""); + await expect(page.locator("#app")).toHaveAttribute("aria-hidden", "true"); + + const createButton = dialog.getByRole("button", { name: "Créer", exact: true }); + await createButton.focus(); + await page.keyboard.press("Tab"); + await expect(nameInput).toBeFocused(); + await page.keyboard.press("Shift+Tab"); + await expect(createButton).toBeFocused(); + await page.keyboard.press("Escape"); + await expect(dialog).toHaveCount(0); + await expect(createTrigger).toBeFocused(); + await expect(page.locator("#app")).not.toHaveAttribute("inert", ""); + await expect(page.locator("#app")).not.toHaveAttribute("aria-hidden", "true"); + + await createTrigger.click(); + dialog = page.getByRole("dialog", { name: "Nouvelle toolbox", exact: true }); + await dialog.getByLabel("Nom").fill("Clavier E2E"); + await dialog.getByRole("button", { name: "Créer", exact: true }).click(); + + const addTrigger = page.getByRole("button", { name: "Ajouter un outil", exact: true }); + await addTrigger.click(); + dialog = page.getByRole("dialog", { name: "Ajouter un outil", exact: true }); + const firstTool = dialog.locator(".tool-add-card").first(); + const lastTool = dialog.locator(".tool-add-card").last(); + const closeButton = dialog.getByRole("button", { name: "Fermer", exact: true }); + await expect(firstTool).toBeFocused(); + await closeButton.focus(); + await page.keyboard.press("Shift+Tab"); + await expect(lastTool).toBeFocused(); + await page.keyboard.press("Tab"); + await expect(closeButton).toBeFocused(); + await page.keyboard.press("Escape"); + await expect(dialog).toHaveCount(0); + await expect(addTrigger).toBeFocused(); + + await page.goto("/#/toolboxes"); + const deleteTrigger = page.getByRole("button", { name: "Supprimer Clavier E2E", exact: true }); + await deleteTrigger.click(); + dialog = page.getByRole("dialog", { name: "Supprimer la toolbox", exact: true }); + await expect(dialog.getByRole("button", { name: "Annuler", exact: true })).toBeFocused(); + await expect(dialog.getByRole("button", { name: "Supprimer", exact: true })).not.toBeFocused(); + await page.keyboard.press("Escape"); + await expect(dialog).toHaveCount(0); + await expect(deleteTrigger).toBeFocused(); + await expect(page.locator("body")).not.toHaveCSS("overflow-y", "hidden"); +}); diff --git a/e2e/persistence.spec.js b/e2e/persistence.spec.js index dd5aa9c..4287faf 100644 --- a/e2e/persistence.spec.js +++ b/e2e/persistence.spec.js @@ -175,7 +175,8 @@ test("a stale toolbox replacement shows a conflict and reloads the confirmed ver await title.blur(); const conflict = page.getByRole("dialog", { name: "Erreur de stockage local" }); await expect(conflict).toContainText("modifiées dans un autre onglet"); - await expect(page.getByRole("heading", { name: "Version distante" })).toBeVisible(); + await expect(title).toHaveText("Version distante"); + await expect(page.locator("#app")).toHaveAttribute("inert", ""); await conflict.getByRole("button", { name: "Compris" }).click(); const confirmed = await page.evaluate(async () => (await import("/src/utils/indexedDbStorage.js")).getToolboxSnapshot()); diff --git a/e2e/shell-behavior.spec.js b/e2e/shell-behavior.spec.js index f565cdc..64dcc72 100644 --- a/e2e/shell-behavior.spec.js +++ b/e2e/shell-behavior.spec.js @@ -83,11 +83,18 @@ test("toast replacement and unmount cancel obsolete expiration callbacks under S test("overlapping modals keep scroll locked until the last unmount under StrictMode", async ({ page }) => { await setup(page, true); await page.evaluate(() => window.shellProbe.render({ confirm: true, create: true })); - await expect(page.getByRole("dialog")).toHaveCount(2); - await expect(page.locator("body")).toHaveCSS("overflow-y", "hidden"); - await page.evaluate(() => window.shellProbe.render({ create: true })); + await expect(page.locator('[role="dialog"]')).toHaveCount(2); await expect(page.getByRole("dialog")).toHaveCount(1); + await expect(page.getByRole("dialog", { name: "Nouvelle toolbox" })).toBeVisible(); await expect(page.locator("body")).toHaveCSS("overflow-y", "hidden"); + await page.keyboard.press("Escape"); + expect(await page.evaluate(() => window.shellProbe.closed)).toEqual([""]); + await page.evaluate(() => window.shellProbe.render({ confirm: true })); + await expect(page.getByRole("dialog")).toHaveCount(1); + await expect(page.getByRole("dialog", { name: "Confirmation test" })).toBeVisible(); + await expect(page.locator("body")).toHaveCSS("overflow-y", "hidden"); + await page.keyboard.press("Escape"); + expect(await page.evaluate(() => window.shellProbe.closed)).toEqual(["", false]); await page.evaluate(() => window.shellProbe.unmount()); await expect(page.getByRole("dialog")).toHaveCount(0); await expect(page.locator("body")).not.toHaveCSS("overflow-y", "hidden"); diff --git a/website/src/components/ImageViewer.jsx b/website/src/components/ImageViewer.jsx index 1068f10..5a26a74 100644 --- a/website/src/components/ImageViewer.jsx +++ b/website/src/components/ImageViewer.jsx @@ -2,10 +2,10 @@ import { useEffect, useRef, useState } from "react"; import { DrawingControls } from "../features/toolboxes/modules/DrawingControls.jsx"; import { DrawingOverlay } from "../features/toolboxes/modules/DrawingOverlay.jsx"; -import { lockBodyScroll } from "../utils/bodyScrollLock.js"; import { DRAWING_COLORS, DRAWING_WIDTHS } from "../utils/drawingOptions.js"; import { Icon } from "./Icon.jsx"; import { ImageGallery } from "./ImageGallery.jsx"; +import { Modal } from "./Modal.jsx"; import { Tooltip } from "./Tooltip.jsx"; const IMAGE_GALLERY_SIZE_STORAGE_KEY = "sokkog:image-gallery-thumbnail-width"; @@ -71,7 +71,6 @@ function formatPositionLabel(template, current, total) { } export function ImageViewer({ image, onClose, createMarkerId = () => globalThis.crypto?.randomUUID?.() || `marker-${Date.now()}` }) { - useEffect(() => lockBodyScroll(), []); const isCollection = image.kind === "collection" && Array.isArray(image.images) && image.images.length > 0; const collection = isCollection ? image.images : [image]; const initialIndex = isCollection ? Math.min(collection.length - 1, Math.max(0, Number(image.activeIndex) || 0)) : 0; @@ -136,10 +135,6 @@ export function ImageViewer({ image, onClose, createMarkerId = () => globalThis. useEffect(() => { const onKeyDown = (event) => { - if (event.key === "Escape") { - onClose(); - return; - } if (!isCollection || view !== "detail") return; if (event.key === "ArrowLeft" && activeIndex > 0) { event.preventDefault(); @@ -152,7 +147,7 @@ export function ImageViewer({ image, onClose, createMarkerId = () => globalThis. }; document.addEventListener("keydown", onKeyDown); return () => document.removeEventListener("keydown", onKeyDown); - }, [activeIndex, collection.length, isCollection, onClose, view]); + }, [activeIndex, collection.length, isCollection, view]); function updateViewerMarkers(nextMarkers) { setViewerMarkers(nextMarkers); @@ -236,9 +231,7 @@ export function ImageViewer({ image, onClose, createMarkerId = () => globalThis. } return ( -
-
-
+
{(view === "gallery" || isCollection || activeImage.label) && ( @@ -361,7 +354,6 @@ export function ImageViewer({ image, onClose, createMarkerId = () => globalThis. )}
} -
-
+ ); } diff --git a/website/src/components/Modal.jsx b/website/src/components/Modal.jsx new file mode 100644 index 0000000..3039fea --- /dev/null +++ b/website/src/components/Modal.jsx @@ -0,0 +1,197 @@ +// Rôle : fournit le comportement clavier, focus et empilement commun aux fenêtres modales. +import { useLayoutEffect, useRef } from "react"; +import { createPortal } from "react-dom"; +import { lockBodyScroll } from "../utils/bodyScrollLock.js"; + +const FOCUSABLE_SELECTOR = [ + "a[href]", + "button:not([disabled])", + "input:not([disabled]):not([type='hidden'])", + "select:not([disabled])", + "textarea:not([disabled])", + "[tabindex]:not([tabindex='-1'])", + "[contenteditable='true']" +].join(","); + +const modalStack = []; +const backgroundStates = new Map(); + +function rememberElementState(element) { + if (backgroundStates.has(element)) return; + backgroundStates.set(element, { + inert: element.inert, + hasAriaHidden: element.hasAttribute("aria-hidden"), + ariaHidden: element.getAttribute("aria-hidden") + }); +} + +function restoreElementState(element) { + const state = backgroundStates.get(element); + if (!state) return; + element.inert = state.inert; + if (state.hasAriaHidden) element.setAttribute("aria-hidden", state.ariaHidden); + else element.removeAttribute("aria-hidden"); +} + +function syncModalLayers() { + const topModal = modalStack.at(-1); + if (!topModal) { + backgroundStates.forEach((_state, element) => restoreElementState(element)); + backgroundStates.clear(); + return; + } + + Array.from(document.body.children).forEach((element) => { + rememberElementState(element); + const isActiveLayer = element === topModal.root; + if (isActiveLayer) { + restoreElementState(element); + return; + } + element.inert = true; + element.setAttribute("aria-hidden", "true"); + }); +} + +function isTopModal(id) { + return modalStack.at(-1)?.id === id; +} + +function getFocusableElements(dialog) { + return Array.from(dialog.querySelectorAll(FOCUSABLE_SELECTOR)).filter((element) => ( + !element.hidden + && element.getAttribute("aria-hidden") !== "true" + && element.getClientRects().length > 0 + )); +} + +function focusInitialElement(dialog, initialFocusRef) { + const requested = initialFocusRef.current?.current; + const target = requested && dialog.contains(requested) + ? requested + : dialog.querySelector("[data-modal-initial-focus], [autofocus]") || getFocusableElements(dialog)[0] || dialog; + target.focus({ preventScroll: true }); +} + +function assignRef(ref, value) { + if (typeof ref === "function") ref(value); + else if (ref) ref.current = value; +} + +export function Modal({ + children, + rootClassName = "confirm-modal-root", + backdropClassName = "confirm-backdrop nds-modal-backdrop", + dialogClassName = "confirm-modal nds-modal", + labelledBy, + describedBy, + ariaLabel, + onRequestClose, + canClose = true, + closeOnBackdrop = true, + closeOnEscape = true, + initialFocusRef, + returnFocusRef, + dialogRef +}) { + const idRef = useRef(Symbol("modal")); + const rootRef = useRef(null); + const internalDialogRef = useRef(null); + const returnTargetRef = useRef(null); + const onRequestCloseRef = useRef(onRequestClose); + const canCloseRef = useRef(canClose); + const closeOnEscapeRef = useRef(closeOnEscape); + const initialFocusRefRef = useRef(initialFocusRef); + const returnFocusRefRef = useRef(returnFocusRef); + + useLayoutEffect(() => { + onRequestCloseRef.current = onRequestClose; + canCloseRef.current = canClose; + closeOnEscapeRef.current = closeOnEscape; + initialFocusRefRef.current = initialFocusRef; + returnFocusRefRef.current = returnFocusRef; + }, [canClose, closeOnEscape, initialFocusRef, onRequestClose, returnFocusRef]); + + useLayoutEffect(() => { + const id = idRef.current; + const root = rootRef.current; + const dialog = internalDialogRef.current; + if (!returnTargetRef.current?.isConnected) returnTargetRef.current = document.activeElement; + const unlockBodyScroll = lockBodyScroll(); + modalStack.push({ id, root, dialog }); + syncModalLayers(); + focusInitialElement(dialog, initialFocusRefRef); + + function handleKeyDown(event) { + if (!isTopModal(id)) return; + if (event.key === "Escape") { + event.preventDefault(); + event.stopPropagation(); + if (closeOnEscapeRef.current && canCloseRef.current) onRequestCloseRef.current?.(); + return; + } + if (event.key !== "Tab") return; + const focusable = getFocusableElements(dialog); + if (!focusable.length) { + event.preventDefault(); + dialog.focus({ preventScroll: true }); + return; + } + const first = focusable[0]; + const last = focusable.at(-1); + if (event.shiftKey && (document.activeElement === first || !dialog.contains(document.activeElement))) { + event.preventDefault(); + last.focus(); + } else if (!event.shiftKey && (document.activeElement === last || !dialog.contains(document.activeElement))) { + event.preventDefault(); + first.focus(); + } + } + + document.addEventListener("keydown", handleKeyDown, true); + return () => { + document.removeEventListener("keydown", handleKeyDown, true); + const index = modalStack.findIndex((entry) => entry.id === id); + if (index >= 0) modalStack.splice(index, 1); + syncModalLayers(); + unlockBodyScroll(); + queueMicrotask(() => { + if (modalStack.some((entry) => entry.id === id)) return; + const requested = returnFocusRefRef.current?.current; + const target = requested?.isConnected ? requested : returnTargetRef.current?.isConnected ? returnTargetRef.current : null; + if (target && typeof target.focus === "function") target.focus({ preventScroll: true }); + else { + const topDialog = modalStack.at(-1)?.dialog; + if (topDialog) focusInitialElement(topDialog, { current: null }); + } + }); + }; + }, []); + + return createPortal( +
+
{ + if (closeOnBackdrop && canClose && isTopModal(idRef.current)) onRequestClose?.(); + }} + /> +
{ + internalDialogRef.current = element; + assignRef(dialogRef, element); + }} + role="dialog" + aria-modal="true" + aria-labelledby={labelledBy} + aria-describedby={describedBy} + aria-label={ariaLabel} + tabIndex={-1} + > + {children} +
+
, + document.body + ); +} diff --git a/website/src/components/ToolboxModals.jsx b/website/src/components/ToolboxModals.jsx index 841a0d8..7b4d323 100644 --- a/website/src/components/ToolboxModals.jsx +++ b/website/src/components/ToolboxModals.jsx @@ -1,27 +1,21 @@ // Rôle : fournit les modales globales liées aux toolboxes et confirmations. -import { useEffect, useState } from "react"; +import { useEffect, useId, useState } from "react"; import { flushSync } from "react-dom"; import { Icon } from "./Icon.jsx"; -import { lockBodyScroll } from "../utils/bodyScrollLock.js"; - -function useModalScrollLock() { - useEffect(() => lockBodyScroll(), []); -} +import { Modal } from "./Modal.jsx"; export function ConfirmModal({ title, message, confirmLabel = "Confirmer", cancelLabel = "Annuler", danger = false, onClose }) { - useModalScrollLock(); + const titleId = useId(); + const messageId = useId(); return ( -
-
onClose(false)} /> -
-

{title}

-

{message}

+ onClose(false)}> +

{title}

+

{message}

- +
-
-
+ ); } @@ -47,62 +41,51 @@ export function NotificationToast({ id, message, durationMs = 6000, actionLabel } export function CreateToolboxModal({ gameId, initialName = "", onClose }) { - useModalScrollLock(); const [name, setName] = useState(initialName); return ( -
-
onClose("")} /> -
+ onClose("")}>

{gameId ? "Créer et associer une toolbox" : "Nouvelle toolbox"}

{ event.preventDefault(); if (name.trim()) onClose(name.trim()); }}> - +
-
-
+ ); } export function LinkToolboxModal({ toolboxes, selectedId, onClose }) { - useModalScrollLock(); const [toolboxId, setToolboxId] = useState(selectedId); return ( -
-
onClose(null)} /> -
+ onClose(null)}>
{ event.preventDefault(); onClose(toolboxId); }}> - +
-
-
+ ); } export function AutoBackupModal({ backup, content, onClose }) { - useModalScrollLock(); const folderName = backup.config.directoryHandle?.name || content.noFolder; const lastBackup = backup.config.lastBackup ? new Date(backup.config.lastBackup).toLocaleString() : content.never; return ( -
-
-
+

{content.eyebrow}

{content.title}

- +

{content.description}

@@ -138,9 +121,8 @@ export function AutoBackupModal({ backup, content, onClose }) { )}
- +
-
-
+ ); } diff --git a/website/src/features/games/CopyChecklistItemsButton.jsx b/website/src/features/games/CopyChecklistItemsButton.jsx index 6453943..5a30dfc 100644 --- a/website/src/features/games/CopyChecklistItemsButton.jsx +++ b/website/src/features/games/CopyChecklistItemsButton.jsx @@ -1,9 +1,8 @@ // Rôle : copie ou crée en checklist les données visibles des pages de jeu. /* eslint-disable react-refresh/only-export-components -- expose aussi les formatters publics testés pour l'import checklist. */ -import { useEffect, useId, useState } from "react"; -import { createPortal } from "react-dom"; +import { useId, useState } from "react"; import { Icon } from "../../components/Icon.jsx"; -import { lockBodyScroll } from "../../utils/bodyScrollLock.js"; +import { Modal } from "../../components/Modal.jsx"; async function copyText(value) { try { @@ -52,19 +51,6 @@ function ChecklistResultsModal({ checklistTitle, content, linkedToolbox, text, o const [creating, setCreating] = useState(false); const [error, setError] = useState(""); - useEffect(() => { - function handleKeyDown(event) { - if (event.key === "Escape" && !creating) onClose(); - } - - const unlock = lockBodyScroll(); - document.addEventListener("keydown", handleKeyDown); - return () => { - unlock(); - document.removeEventListener("keydown", handleKeyDown); - }; - }, [creating, onClose]); - async function copyItems() { setError(""); if (!await copyText(text)) { @@ -89,10 +75,8 @@ function ChecklistResultsModal({ checklistTitle, content, linkedToolbox, text, o } } - return createPortal( -
-
!creating && onClose()} /> -
+ return ( +

{content.resultsModalTitle || "Utiliser les résultats visibles"}

-
-
, - document.body + ); } diff --git a/website/src/features/toolboxes/ToolboxCoverEditor.jsx b/website/src/features/toolboxes/ToolboxCoverEditor.jsx index 5bcf446..02501ea 100644 --- a/website/src/features/toolboxes/ToolboxCoverEditor.jsx +++ b/website/src/features/toolboxes/ToolboxCoverEditor.jsx @@ -2,8 +2,8 @@ /* eslint-disable react-refresh/only-export-components -- expose aussi les helpers purs de calcul/export du crop. */ import { useEffect, useRef, useState } from "react"; import { Icon } from "../../components/Icon.jsx"; +import { Modal } from "../../components/Modal.jsx"; import { useKeyedState } from "../../hooks/useKeyedState.js"; -import { lockBodyScroll } from "../../utils/bodyScrollLock.js"; const OUTPUT_WIDTH = 620; const OUTPUT_HEIGHT = 248; @@ -75,8 +75,6 @@ export function ToolboxCoverEditor({ file, existingCover = "", onClose, onSave } const [transform, setTransform] = useKeyedState(transformKey, () => ({ x: 0, y: 0, scale: baseScale })); const maxScale = baseScale * 4; - useEffect(() => lockBodyScroll(), []); - useEffect(() => { const nextSource = createPreviewSource(file, existingCover); if (!nextSource) return undefined; @@ -160,9 +158,7 @@ export function ToolboxCoverEditor({ file, existingCover = "", onClose, onSave } } return ( -
-
-
+

Image de card

@@ -198,7 +194,6 @@ export function ToolboxCoverEditor({ file, existingCover = "", onClose, onSave } -
-
+ ); } diff --git a/website/src/features/toolboxes/ToolboxSpaces.jsx b/website/src/features/toolboxes/ToolboxSpaces.jsx index dcce7d6..1422010 100644 --- a/website/src/features/toolboxes/ToolboxSpaces.jsx +++ b/website/src/features/toolboxes/ToolboxSpaces.jsx @@ -1,8 +1,8 @@ // Rôle : affiche et gère les onglets d'espaces persistants d'une toolbox. import { useEffect, useState } from "react"; import { Icon } from "../../components/Icon.jsx"; +import { Modal } from "../../components/Modal.jsx"; import { useGroupedReorder } from "../../hooks/useGroupedReorder.js"; -import { lockBodyScroll } from "../../utils/bodyScrollLock.js"; import { MAX_TOOLBOX_SPACES } from "./storage/toolboxStorage.js"; import { createToolboxSpace, deleteToolboxSpace, reorderToolboxSpaces } from "./toolboxSpaceUtils.js"; @@ -10,24 +10,20 @@ const SPACE_HOVER_DELAY_MS = 600; function SpaceNameModal({ initialName = "", title, text, onClose }) { const [name, setName] = useState(initialName); - useEffect(() => lockBodyScroll(), []); return ( -
-
onClose("")} /> -
+ onClose("")}>

{title}

{ event.preventDefault(); if (name.trim()) onClose(name.trim()); }}> - +
-
-
+ ); } diff --git a/website/src/features/toolboxes/modules/AddToolControls.jsx b/website/src/features/toolboxes/modules/AddToolControls.jsx index 4055e93..5835ba1 100644 --- a/website/src/features/toolboxes/modules/AddToolControls.jsx +++ b/website/src/features/toolboxes/modules/AddToolControls.jsx @@ -1,10 +1,9 @@ // Rôle : rend les contrôles modal et quick-add d'ajout d'outils toolbox. -import { useEffect, useState } from "react"; -import { createPortal } from "react-dom"; +import { useState } from "react"; import { CompactDropdown } from "../../../components/CompactDropdown.jsx"; import { Icon } from "../../../components/Icon.jsx"; +import { Modal } from "../../../components/Modal.jsx"; import { Tooltip } from "../../../components/Tooltip.jsx"; -import { lockBodyScroll } from "../../../utils/bodyScrollLock.js"; import { LIBRARY_CATEGORY_DEFINITIONS, TOOLBOX_MODULES } from "../toolboxModuleRegistry.js"; export function AddToolControls({ categories, descriptions, onAdd }) { @@ -15,11 +14,6 @@ export function AddToolControls({ categories, descriptions, onAdd }) { title: categories[category.key] })); - useEffect(() => { - if (!open) return undefined; - return lockBodyScroll(); - }, [open]); - function addTool(type) { onAdd(type); setOpen(false); @@ -28,7 +22,7 @@ export function AddToolControls({ categories, descriptions, onAdd }) { function renderToolCard(type) { const module = TOOLBOX_MODULES[type]; return ( -
- {open && createPortal( -
-
setOpen(false)} /> -
+ {open && ( + setOpen(false)}>

Ajouter un outil

))}
- -
, - document.body + )} ); diff --git a/website/src/features/toolboxes/modules/TextImportModal.jsx b/website/src/features/toolboxes/modules/TextImportModal.jsx index 1b35033..336088d 100644 --- a/website/src/features/toolboxes/modules/TextImportModal.jsx +++ b/website/src/features/toolboxes/modules/TextImportModal.jsx @@ -1,30 +1,10 @@ // Rôle : affiche la modale d'import/export texte partagée par les outils compatibles. -import { useEffect } from "react"; -import { createPortal } from "react-dom"; import { Icon } from "../../../components/Icon.jsx"; -import { lockBodyScroll } from "../../../utils/bodyScrollLock.js"; +import { Modal } from "../../../components/Modal.jsx"; export function TextImportModal({ title, value, placeholder, submitLabel, readOnly = false, error = "", info = "", onChange, onSubmit, onCopy, onClose }) { - useEffect(() => { - function handleKeyDown(event) { - if (event.key === "Escape") { - event.stopPropagation(); - onClose(); - } - } - - const unlock = lockBodyScroll(); - document.addEventListener("keydown", handleKeyDown); - return () => { - unlock(); - document.removeEventListener("keydown", handleKeyDown); - }; - }, [onClose]); - - return createPortal( -
-
-
+ return ( +

{title}