File size: 3,068 Bytes
b09157d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import { useState } from 'react';
import DebugValue from './DebugValue.jsx';
export default function DebugPanel({ point, paused, resume, language, watch, setWatch, inspectArray }) {
const [name, setName] = useState('');
const [expanded, setExpanded] = useState(() => new Set());
const toggle = key => setExpanded(current => { const next = new Set(current); if (next.has(key)) next.delete(key); else next.add(key); return next; });
const fr = language === 'fr';
const variables = point?.variables || [];
const renderValue = (value, path, scope) => <DebugValue value={value} path={path} scope={scope} expanded={expanded} toggle={toggle} inspectArray={inspectArray} fr={fr} />;
return <section className="debug-panel" aria-label="Debugger">
<div className="debug-controls">
<strong>{fr ? 'Débogueur' : 'Debugger'}</strong>
<button disabled={!paused} onClick={() => resume('continue')} title="F5">{fr ? 'Continuer' : 'Continue'}</button>
<button disabled={!paused} onClick={() => resume('over')} title="F10">{fr ? 'Ligne suivante' : 'Step over'}</button>
<button disabled={!paused} onClick={() => resume('into')} title="F11">{fr ? 'Entrer dans la fonction' : 'Step into'}</button>
<button disabled={!paused} onClick={() => resume('out')} title="Shift+F11">{fr ? 'Sortir de la fonction' : 'Step out'}</button>
<span>{paused && point ? `${point.function} · ${fr ? 'ligne' : 'line'} ${point.line}` : (fr ? 'Exécution en cours…' : 'Running…')}</span>
</div>
<div className="debug-values" aria-live="polite">
<div><strong>{fr ? 'Variables visibles' : 'Visible variables'}</strong>
<table aria-label="Variables"><thead><tr><th>{fr ? 'Nom' : 'Name'}</th><th>Type</th><th>{fr ? 'Valeur' : 'Value'}</th></tr></thead>
<tbody>{paused && variables.map(v => <tr key={v.name}><td>{v.name}</td><td>{v.type}</td><td>{renderValue(v.value, v.name, 'locals')}</td></tr>)}</tbody></table>
{paused && !variables.length && <span>{fr ? 'Aucune variable dans cette portée.' : 'No variables in scope.'}</span>}
</div>
<div><strong>Watch</strong>
<form onSubmit={e => { e.preventDefault(); const value = name.trim(); if (/^[A-Za-z_]\w*$/.test(value)) { setWatch(items => [...new Set([...items, value])]); setName(''); } }}>
<input aria-label="Watch variable" placeholder={fr ? 'Nom de variable' : 'Variable name'} pattern="[A-Za-z_][A-Za-z_0-9]*" value={name} onChange={e => setName(e.target.value)} />
<button>{fr ? 'Ajouter' : 'Add'}</button>
</form>
{watch.map(item => { const value = variables.find(v => v.name === item); return <div className="debug-watch" key={item}><div className="debug-watch-value"><code>{item} = </code>{paused ? value ? renderValue(value.value, item, 'watch') : <code>{fr ? 'hors portée' : 'out of scope'}</code> : <code>…</code>}</div><button aria-label={`Remove watch ${item}`} onClick={() => setWatch(items => items.filter(v => v !== item))}>×</button></div>; })}
</div>
</div>
</section>;
}
|