Standardize modal focus and keyboard behavior
This commit is contained in:
parent
e87edda5c7
commit
954240adf9
15 changed files with 331 additions and 139 deletions
|
|
@ -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"}}
|
||||
|
|
|
|||
|
|
@ -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 `<dialog>` 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.
|
||||
|
|
|
|||
|
|
@ -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 }) => {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
61
e2e/modal-accessibility.spec.js
Normal file
61
e2e/modal-accessibility.spec.js
Normal file
|
|
@ -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");
|
||||
});
|
||||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div className="image-viewer-root">
|
||||
<div className="image-viewer-backdrop" onClick={onClose} />
|
||||
<section ref={viewerRef} className={`image-viewer ${view === "gallery" ? "is-gallery" : ""}`} role="dialog" aria-modal="true" aria-label={view === "gallery" ? textContent.galleryTitle || "Galerie d'images" : "Image"}>
|
||||
<Modal rootClassName="image-viewer-root" backdropClassName="image-viewer-backdrop" dialogClassName={`image-viewer ${view === "gallery" ? "is-gallery" : ""}`} ariaLabel={view === "gallery" ? textContent.galleryTitle || "Galerie d'images" : "Image"} onRequestClose={onClose} dialogRef={viewerRef}>
|
||||
<header>
|
||||
<div className="image-viewer-heading">
|
||||
{(view === "gallery" || isCollection || activeImage.label) && (
|
||||
|
|
@ -361,7 +354,6 @@ export function ImageViewer({ image, onClose, createMarkerId = () => globalThis.
|
|||
</aside>
|
||||
)}
|
||||
</div>}
|
||||
</section>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
197
website/src/components/Modal.jsx
Normal file
197
website/src/components/Modal.jsx
Normal file
|
|
@ -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(
|
||||
<div className={rootClassName} data-modal-layer="" ref={rootRef}>
|
||||
<div
|
||||
className={backdropClassName}
|
||||
onClick={() => {
|
||||
if (closeOnBackdrop && canClose && isTopModal(idRef.current)) onRequestClose?.();
|
||||
}}
|
||||
/>
|
||||
<section
|
||||
className={dialogClassName}
|
||||
ref={(element) => {
|
||||
internalDialogRef.current = element;
|
||||
assignRef(dialogRef, element);
|
||||
}}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby={labelledBy}
|
||||
aria-describedby={describedBy}
|
||||
aria-label={ariaLabel}
|
||||
tabIndex={-1}
|
||||
>
|
||||
{children}
|
||||
</section>
|
||||
</div>,
|
||||
document.body
|
||||
);
|
||||
}
|
||||
|
|
@ -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 (
|
||||
<div className="confirm-modal-root">
|
||||
<div className="confirm-backdrop nds-modal-backdrop" onClick={() => onClose(false)} />
|
||||
<section className="confirm-modal nds-modal" role="dialog" aria-modal="true" aria-labelledby="confirm-title" aria-describedby="confirm-message">
|
||||
<header><h2 id="confirm-title">{title}</h2></header>
|
||||
<p id="confirm-message">{message}</p>
|
||||
<Modal labelledBy={titleId} describedBy={messageId} onRequestClose={() => onClose(false)}>
|
||||
<header><h2 id={titleId}>{title}</h2></header>
|
||||
<p id={messageId}>{message}</p>
|
||||
<footer className="nds-modal-footer">
|
||||
<button className="nds-button" data-size="sm" onClick={() => onClose(false)}>{cancelLabel}</button>
|
||||
<button className="nds-button" data-size="sm" data-modal-initial-focus={danger ? "" : undefined} onClick={() => onClose(false)}>{cancelLabel}</button>
|
||||
<button className="confirm-danger nds-button" data-size="sm" data-variant={danger ? "danger" : "primary"} onClick={() => onClose(true)}>{confirmLabel}</button>
|
||||
</footer>
|
||||
</section>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -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 (
|
||||
<div className="confirm-modal-root">
|
||||
<div className="confirm-backdrop nds-modal-backdrop" onClick={() => onClose("")} />
|
||||
<section className="confirm-modal nds-modal toolbox-create-modal" role="dialog" aria-modal="true" aria-labelledby="toolbox-create-title">
|
||||
<Modal dialogClassName="confirm-modal nds-modal toolbox-create-modal" labelledBy="toolbox-create-title" onRequestClose={() => onClose("")}>
|
||||
<header><h2 id="toolbox-create-title">{gameId ? "Créer et associer une toolbox" : "Nouvelle toolbox"}</h2></header>
|
||||
<form onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
if (name.trim()) onClose(name.trim());
|
||||
}}>
|
||||
<label className="field"><span>Nom</span><input className="nds-input" data-size="sm" name="name" type="text" autoComplete="off" placeholder="Nom de la toolbox" required value={name} onChange={(event) => setName(event.target.value)} autoFocus /></label>
|
||||
<label className="field"><span>Nom</span><input className="nds-input" data-size="sm" name="name" type="text" autoComplete="off" placeholder="Nom de la toolbox" required value={name} onChange={(event) => setName(event.target.value)} data-modal-initial-focus="" /></label>
|
||||
<footer className="nds-modal-footer"><button className="nds-button" data-size="sm" type="button" onClick={() => onClose("")}>Annuler</button><button className="nds-button" data-size="sm" data-variant="primary" type="submit">Créer</button></footer>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
export function LinkToolboxModal({ toolboxes, selectedId, onClose }) {
|
||||
useModalScrollLock();
|
||||
const [toolboxId, setToolboxId] = useState(selectedId);
|
||||
return (
|
||||
<div className="confirm-modal-root">
|
||||
<div className="confirm-backdrop nds-modal-backdrop" onClick={() => onClose(null)} />
|
||||
<section className="confirm-modal nds-modal toolbox-link-modal" role="dialog" aria-modal="true" aria-labelledby="toolbox-link-title">
|
||||
<Modal dialogClassName="confirm-modal nds-modal toolbox-link-modal" labelledBy="toolbox-link-title" onRequestClose={() => onClose(null)}>
|
||||
<header><h2 id="toolbox-link-title">Lier une toolbox</h2></header>
|
||||
<form onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
onClose(toolboxId);
|
||||
}}>
|
||||
<label className="field"><span>Toolbox associée</span><select className="nds-select" data-size="sm" value={toolboxId} onChange={(event) => setToolboxId(event.target.value)} autoFocus><option value="">Aucune</option>{toolboxes.map((toolbox) => <option key={toolbox.id} value={toolbox.id}>{toolbox.name}</option>)}</select></label>
|
||||
<label className="field"><span>Toolbox associée</span><select className="nds-select" data-size="sm" value={toolboxId} onChange={(event) => setToolboxId(event.target.value)} data-modal-initial-focus=""><option value="">Aucune</option>{toolboxes.map((toolbox) => <option key={toolbox.id} value={toolbox.id}>{toolbox.name}</option>)}</select></label>
|
||||
<footer className="nds-modal-footer"><button className="nds-button" data-size="sm" type="button" onClick={() => onClose(null)}>Annuler</button><button className="nds-button" data-size="sm" data-variant="primary" type="submit">Valider</button></footer>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<div className="confirm-modal-root auto-backup-modal-root">
|
||||
<div className="confirm-backdrop nds-modal-backdrop" onClick={onClose} />
|
||||
<section className="confirm-modal nds-modal auto-backup-modal themed-scrollbar" role="dialog" aria-modal="true" aria-labelledby="auto-backup-title">
|
||||
<Modal rootClassName="confirm-modal-root auto-backup-modal-root" dialogClassName="confirm-modal nds-modal auto-backup-modal themed-scrollbar" labelledBy="auto-backup-title" onRequestClose={onClose} canClose={!backup.busy}>
|
||||
<header className="auto-backup-modal-header">
|
||||
<div>
|
||||
<p className="eyebrow">{content.eyebrow}</p>
|
||||
<h2 id="auto-backup-title">{content.title}</h2>
|
||||
</div>
|
||||
<button className="nds-icon-button" data-size="sm" type="button" onClick={onClose} aria-label={content.close} title={content.close}><Icon name="close" /></button>
|
||||
<button className="nds-icon-button" data-size="sm" type="button" disabled={backup.busy} onClick={onClose} aria-label={content.close} title={content.close}><Icon name="close" /></button>
|
||||
</header>
|
||||
<p className="auto-backup-description">{content.description}</p>
|
||||
<div className="auto-backup-compatibility">
|
||||
|
|
@ -138,9 +121,8 @@ export function AutoBackupModal({ backup, content, onClose }) {
|
|||
</>
|
||||
)}
|
||||
<footer className="nds-modal-footer auto-backup-close-footer">
|
||||
<button className="nds-button" data-size="sm" type="button" onClick={onClose}>{content.close}</button>
|
||||
<button className="nds-button" data-size="sm" type="button" disabled={backup.busy} onClick={onClose}>{content.close}</button>
|
||||
</footer>
|
||||
</section>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
<div className="confirm-modal-root results-checklist-modal-root">
|
||||
<div className="confirm-backdrop nds-modal-backdrop" onClick={() => !creating && onClose()} />
|
||||
<section className="confirm-modal nds-modal results-checklist-modal" role="dialog" aria-modal="true" aria-labelledby={titleId} aria-describedby={descriptionId}>
|
||||
return (
|
||||
<Modal rootClassName="confirm-modal-root results-checklist-modal-root" dialogClassName="confirm-modal nds-modal results-checklist-modal" labelledBy={titleId} describedBy={descriptionId} onRequestClose={onClose} canClose={!creating}>
|
||||
<header className="results-checklist-modal-header">
|
||||
<h2 id={titleId}>{content.resultsModalTitle || "Utiliser les résultats visibles"}</h2>
|
||||
<button className="nds-icon-button" data-size="sm" type="button" disabled={creating} onClick={onClose} aria-label={content.resultsClose || "Fermer"} title={content.resultsClose || "Fermer"}>
|
||||
|
|
@ -119,7 +103,7 @@ function ChecklistResultsModal({ checklistTitle, content, linkedToolbox, text, o
|
|||
)}
|
||||
{error && <p className="results-checklist-modal-error nds-inline-notice" data-variant="danger" role="alert"><Icon name="close" /><span>{error}</span></p>}
|
||||
<footer className="nds-modal-footer results-checklist-modal-actions">
|
||||
<button className="nds-button" data-size="sm" type="button" disabled={creating} onClick={() => void copyItems()} autoFocus>
|
||||
<button className="nds-button" data-size="sm" type="button" disabled={creating} onClick={() => void copyItems()} data-modal-initial-focus="">
|
||||
<Icon name="copy" />{content.resultsCopyLabel || "Copier le format texte"}
|
||||
</button>
|
||||
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={!linkedToolbox || creating} onClick={() => void createChecklist()}>
|
||||
|
|
@ -127,9 +111,7 @@ function ChecklistResultsModal({ checklistTitle, content, linkedToolbox, text, o
|
|||
{creating ? content.resultsCreatingLabel || "Création…" : content.resultsCreateLabel || "Créer dans la toolbox"}
|
||||
</button>
|
||||
</footer>
|
||||
</section>
|
||||
</div>,
|
||||
document.body
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div className="confirm-modal-root toolbox-cover-editor-root">
|
||||
<div className="confirm-backdrop nds-modal-backdrop" onClick={onClose} />
|
||||
<section className="confirm-modal nds-modal toolbox-cover-editor" role="dialog" aria-modal="true" aria-labelledby="toolbox-cover-editor-title">
|
||||
<Modal rootClassName="confirm-modal-root toolbox-cover-editor-root" dialogClassName="confirm-modal nds-modal toolbox-cover-editor" labelledBy="toolbox-cover-editor-title" onRequestClose={onClose}>
|
||||
<header>
|
||||
<h2 id="toolbox-cover-editor-title">Image de card</h2>
|
||||
<button className="nds-icon-button" data-size="xs" type="button" onClick={onClose} aria-label="Fermer" title="Fermer"><Icon name="close" /></button>
|
||||
|
|
@ -198,7 +194,6 @@ export function ToolboxCoverEditor({ file, existingCover = "", onClose, onSave }
|
|||
<button className="nds-button" data-size="sm" type="button" onClick={onClose}>Annuler</button>
|
||||
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={!imageSize.width || Boolean(error)} onClick={saveCover}>Valider</button>
|
||||
</footer>
|
||||
</section>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div className="confirm-modal-root">
|
||||
<div className="confirm-backdrop nds-modal-backdrop" onClick={() => onClose("")} />
|
||||
<section className="confirm-modal nds-modal toolbox-space-modal" role="dialog" aria-modal="true" aria-labelledby="toolbox-space-modal-title">
|
||||
<Modal dialogClassName="confirm-modal nds-modal toolbox-space-modal" labelledBy="toolbox-space-modal-title" onRequestClose={() => onClose("")}>
|
||||
<header><h2 id="toolbox-space-modal-title">{title}</h2></header>
|
||||
<form onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
if (name.trim()) onClose(name.trim());
|
||||
}}>
|
||||
<label className="field"><span>{text.nameLabel}</span><input className="nds-input" data-size="sm" value={name} onChange={(event) => setName(event.target.value)} autoComplete="off" autoFocus required /></label>
|
||||
<label className="field"><span>{text.nameLabel}</span><input className="nds-input" data-size="sm" value={name} onChange={(event) => setName(event.target.value)} autoComplete="off" data-modal-initial-focus="" required /></label>
|
||||
<footer className="nds-modal-footer">
|
||||
<button className="nds-button" data-size="sm" type="button" onClick={() => onClose("")}>{text.cancelLabel}</button>
|
||||
<button className="nds-button" data-size="sm" data-variant="primary" type="submit">{text.saveLabel}</button>
|
||||
</footer>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<button key={type} className="tool-add-card" type="button" onClick={() => addTool(type)}>
|
||||
<button key={type} className="tool-add-card" type="button" data-modal-initial-focus={type === moduleCategories[0]?.types[0] ? "" : undefined} onClick={() => addTool(type)}>
|
||||
<span className="module-icon" aria-hidden="true">
|
||||
<span className={`module-icon-svg module-icon-${module.icon}`} />
|
||||
</span>
|
||||
|
|
@ -103,10 +97,8 @@ export function AddToolControls({ categories, descriptions, onAdd }) {
|
|||
)}
|
||||
</CompactDropdown>
|
||||
</div>
|
||||
{open && createPortal(
|
||||
<div className="tool-add-modal-root">
|
||||
<div className="confirm-backdrop nds-modal-backdrop" onClick={() => setOpen(false)} />
|
||||
<section className="confirm-modal nds-modal tool-add-modal" role="dialog" aria-modal="true" aria-labelledby="tool-add-modal-title">
|
||||
{open && (
|
||||
<Modal rootClassName="tool-add-modal-root" dialogClassName="confirm-modal nds-modal tool-add-modal" labelledBy="tool-add-modal-title" onRequestClose={() => setOpen(false)}>
|
||||
<header>
|
||||
<h2 id="tool-add-modal-title">Ajouter un outil</h2>
|
||||
<button className="drawer-close-button nds-icon-button" data-size="sm" type="button" onClick={() => setOpen(false)} aria-label="Fermer" title="Fermer">
|
||||
|
|
@ -121,9 +113,7 @@ export function AddToolControls({ categories, descriptions, onAdd }) {
|
|||
</section>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</div>,
|
||||
document.body
|
||||
</Modal>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
<div className="confirm-modal-root text-import-modal-root">
|
||||
<div className="confirm-backdrop nds-modal-backdrop" onClick={onClose} />
|
||||
<section className="confirm-modal nds-modal text-import-modal-dialog" role="dialog" aria-modal="true" aria-labelledby="text-import-title">
|
||||
return (
|
||||
<Modal rootClassName="confirm-modal-root text-import-modal-root" dialogClassName="confirm-modal nds-modal text-import-modal-dialog" labelledBy="text-import-title" onRequestClose={onClose}>
|
||||
<header>
|
||||
<h2 id="text-import-title">{title}</h2>
|
||||
<button className="drawer-close-button nds-icon-button" data-size="sm" type="button" onClick={onClose} aria-label="Fermer" title="Fermer">
|
||||
|
|
@ -33,7 +13,7 @@ export function TextImportModal({ title, value, placeholder, submitLabel, readOn
|
|||
</header>
|
||||
<form className="text-import-modal-form" onSubmit={onSubmit}>
|
||||
<textarea
|
||||
autoFocus
|
||||
data-modal-initial-focus=""
|
||||
className={`nds-textarea ${error ? "has-error" : ""}`.trim()}
|
||||
data-size="sm"
|
||||
readOnly={readOnly}
|
||||
|
|
@ -65,8 +45,6 @@ export function TextImportModal({ title, value, placeholder, submitLabel, readOn
|
|||
)}
|
||||
</footer>
|
||||
</form>
|
||||
</section>
|
||||
</div>,
|
||||
document.body
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue