import { useState } from "react"; import { Icon } from "../../../components/Icon.jsx"; export function ScreenshotsModule({ toolboxId, moduleId, context, editing }) { const data = context.getModuleData(toolboxId, moduleId, { shots: [] }); const textContent = context.moduleText?.screenshots || {}; const [dragOver, setDragOver] = useState(false); const pastePlaceholder = textContent.pastePlaceholder || "Coller une image ici"; async function addFiles(files) { if (await context.addScreenshotFiles(toolboxId, moduleId, files)) { setDragOver(false); } } function updateShot(shotId, patch) { context.setModuleData(toolboxId, moduleId, { shots: data.shots.map((shot) => shot.id === shotId ? { ...shot, ...patch } : shot) }); } return ( <> {editing && (
{ if (event.currentTarget.textContent.trim() === pastePlaceholder) event.currentTarget.textContent = ""; }} onBlur={(event) => { if (!event.currentTarget.textContent.trim()) event.currentTarget.textContent = pastePlaceholder; }} onPaste={(event) => { const files = [...(event.clipboardData?.items || [])] .filter((item) => item.type.startsWith("image/")) .map((item) => item.getAsFile()) .filter(Boolean); if (!files.length) return; event.preventDefault(); event.currentTarget.textContent = pastePlaceholder; addFiles(files); }} > {pastePlaceholder}
)}
{data.shots.map((shot) => (
{editing ? ( updateShot(shot.id, { label: event.target.value })} aria-label={textContent.labelAriaLabel || "Libellé de l'image"} /> ) : shot.label ? (
{shot.label}
) : null}
))}
); }