Download source/src/ui/DebugValue.jsx from FormaLau/microduck-reachy-simulator: direct link, hf CLI and curl.
- Browser
- Download file 2.91 kB
-
https://huggingface.co/spaces/FormaLau/microduck-reachy-simulator/resolve/main/source/src/ui/DebugValue.jsx
- Command line
-
hf download hf://spaces/FormaLau/microduck-reachy-simulator/source/src/ui/DebugValue.jsx
-
curl -L -o DebugValue.jsx https://huggingface.co/spaces/FormaLau/microduck-reachy-simulator/resolve/main/source/src/ui/DebugValue.jsx
2.91 kB
| import { useEffect, useState } from 'react'; | |
| export default function DebugValue({ value, path, scope, expanded, toggle, inspectArray, fr }) { | |
| const [start, setStart] = useState(0), [page, setPage] = useState(null), [error, setError] = useState(''); | |
| const key = `${scope}:${path}`, open = expanded.has(key); | |
| const array = value?.kind === 'array'; | |
| useEffect(() => { | |
| if (!array || !open) return; | |
| let active = true; | |
| setPage(null); setError(''); | |
| inspectArray(value.id, start).then(result => { if (active) setPage(result); }, reason => { if (active) setError(reason.message); }); | |
| return () => { active = false; }; | |
| }, [array, open, value?.id, start, inspectArray]); | |
| if (!array) return <code>{String(value)}</code>; | |
| const preview = value.preview ? `[${value.preview.join(', ')}${value.length > value.preview.length ? ', …' : ''}]` : `[${value.length} ${fr ? 'sous-tableaux' : 'subarrays'}]`; | |
| return <div className="debug-array"> | |
| <button type="button" className="debug-array-toggle" aria-expanded={open} aria-label={`${open ? (fr ? 'Replier' : 'Collapse') : (fr ? 'Déplier' : 'Expand')} ${path}`} onClick={() => toggle(key)}> | |
| <span aria-hidden="true">{open ? '▾' : '▸'}</span> <code>{preview}</code> <small>({value.length})</small> | |
| </button> | |
| {open && <div className="debug-array-items"> | |
| {error ? <span role="alert">{error}</span> : !page ? <span>{fr ? 'Chargement…' : 'Loading…'}</span> : <> | |
| {value.length > 64 && <div className="debug-array-pages"> | |
| <button type="button" disabled={!start} aria-label={`${fr ? 'Éléments précédents de' : 'Previous elements of'} ${path}`} onClick={() => setStart(Math.max(0, start - 64))}>‹</button> | |
| <span>{start}–{start + page.items.length - 1} / {value.length}</span> | |
| <button type="button" disabled={start + page.items.length >= value.length} aria-label={`${fr ? 'Éléments suivants de' : 'Next elements of'} ${path}`} onClick={() => setStart(start + 64)}>›</button> | |
| <form onSubmit={event => { event.preventDefault(); const index = Number(new FormData(event.currentTarget).get('index')); if (Number.isInteger(index) && index >= 0 && index < value.length) setStart(Math.floor(index / 64) * 64); }}> | |
| <input type="number" name="index" min="0" max={value.length - 1} required aria-label={`${fr ? 'Indice dans' : 'Index in'} ${path}`} placeholder={fr ? 'Indice' : 'Index'} /> | |
| <button type="submit">{fr ? 'Aller' : 'Go'}</button> | |
| </form> | |
| </div>} | |
| {page.items.map(item => <div className="debug-array-element" key={item.index}> | |
| <code className="debug-array-index">[{item.index}] = </code> | |
| <DebugValue value={item.value} path={`${path}[${item.index}]`} scope={scope} expanded={expanded} toggle={toggle} inspectArray={inspectArray} fr={fr} /> | |
| </div>)} | |
| </>} | |
| </div>} | |
| </div>; | |
| } | |