diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index c21dce0f..7c92ef67 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,5 +1,5 @@ -import { useState, useEffect } from 'react'; -import Editor from '@monaco-editor/react'; +import { useState, useEffect } from "react"; +import Editor from "@monaco-editor/react"; function debounce(fn, delay) { let t; @@ -10,11 +10,15 @@ function debounce(fn, delay) { } export default function App() { - const [params, setParams] = useState([{ name: 'input1', value: '', open: true }]); - const [xslt, setXslt] = useState('\n\n\n\n'); - const [result, setResult] = useState(''); - const [version, setVersion] = useState('1.0'); - const [error, setError] = useState(''); + const [params, setParams] = useState([ + { name: "input1", value: "", open: true }, + ]); + const [xslt, setXslt] = useState( + `\n\n\n\n`, + ); + const [result, setResult] = useState(""); + const [version, setVersion] = useState("1.0"); + const [error, setError] = useState(""); const runTransform = debounce(async (xsltText, ver, p) => { const paramObj = {}; @@ -22,23 +26,27 @@ export default function App() { if (pr.name) paramObj[pr.name] = pr.value; }); try { - const res = await fetch('/transform', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ xslt: xsltText, version: ver, parameters: paramObj }), + const res = await fetch("/transform", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + xslt: xsltText, + version: ver, + parameters: paramObj, + }), }); if (!res.ok) { const txt = await res.text(); setError(txt || res.statusText); - setResult(''); + setResult(""); return; } const data = await res.json(); setResult(data.result); - setError(''); + setError(""); } catch (e) { setError(String(e)); - setResult(''); + setResult(""); } }, 500); @@ -55,7 +63,7 @@ export default function App() { }; const addParam = () => { - setParams((p) => [...p, { name: '', value: '', open: false }]); + setParams((p) => [...p, { name: "", value: "", open: false }]); }; const removeParam = (index) => { @@ -71,9 +79,9 @@ export default function App() { }; const download = (data, filename) => { - const blob = new Blob([data], { type: 'text/xml' }); + const blob = new Blob([data], { type: "text/xml" }); const url = URL.createObjectURL(blob); - const a = document.createElement('a'); + const a = document.createElement("a"); a.href = url; a.download = filename; a.click(); @@ -84,65 +92,99 @@ export default function App() {
-
+
{params.map((p, i) => ( -
-
+
+
updateParam(i, 'name', e.target.value)} + onChange={(e) => updateParam(i, "name", e.target.value)} /> - +
{p.open && ( -
+
updateParam(i, 'value', v || '')} + onChange={(v) => updateParam(i, "value", v || "")} options={{ minimap: { enabled: false } }} /> -
+
loadFile(e, (text) => updateParam(i, 'value', text))} + onChange={(e) => + loadFile(e, (t) => updateParam(i, "value", t)) + } /> -
- ) + )}
))}
-
- setVersion(e.target.value)} + > - loadFile(e, setXslt)} style={{ marginLeft: '0.5rem' }} /> - + loadFile(e, setXslt)} + style={{ marginLeft: "0.5rem" }} + /> +
setXslt(v || '')} + onChange={(v) => setXslt(v || "")} options={{ minimap: { enabled: false } }} />
-
- {error &&
{error}
} +
+ {error && ( +
{error}
+ )}