From daa1afff2cb133a1954c00e426c2773f8edbfd18 Mon Sep 17 00:00:00 2001 From: Alexandre Vazquez Date: Tue, 1 Jul 2025 20:55:01 +0200 Subject: [PATCH] feat: sync params with xslt and icon buttons --- frontend/src/App.jsx | 91 +++++++++++++++++++++++++++++++----------- frontend/src/style.css | 17 ++++++++ 2 files changed, 85 insertions(+), 23 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index bad43a82..3e611e9e 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -38,6 +38,17 @@ function injectParamBlock(text, params) { return clean.slice(0, idx) + block + clean.slice(idx); } +function extractParamNames(text) { + const clean = stripParamBlock(text); + const names = new Set(); + const regex = /]*name="([^"]+)"[^>]*>/g; + let m; + while ((m = regex.exec(clean))) { + names.add(m[1]); + } + return Array.from(names); +} + function debounce(fn, delay) { let t; return (...args) => { @@ -135,6 +146,29 @@ export default function App() { ); }, [activeTab]); + useEffect(() => { + const names = extractParamNames(activeTab.xslt); + setTabs((tabs) => + tabs.map((t) => { + if (t.id !== active) return t; + let params = [...t.params]; + let changed = false; + names.forEach((n) => { + if (!params.some((p) => p.name === n)) { + params.push({ name: n, value: "", open: false }); + changed = true; + } + }); + const filtered = params.filter((p) => names.includes(p.name) || p.value); + if (filtered.length !== params.length) { + params = filtered; + changed = true; + } + return changed ? { ...t, params } : t; + }), + ); + }, [activeTab.xslt]); + const updateParam = (index, field, value) => { setTabs((tabs) => tabs.map((t) => { @@ -247,13 +281,14 @@ export default function App() { ))} )} @@ -264,7 +299,7 @@ export default function App() { onDrop={handleDropNewParam} >
- +
{activeTab.params.map((p, i) => (
@@ -275,8 +310,8 @@ export default function App() { value={p.name} onChange={(e) => updateParam(i, "name", e.target.value)} /> - - + +
{p.open && (
- loadFile(e, (t) => updateParam(i, "value", t))} - /> - + +
)} @@ -328,19 +367,25 @@ export default function App() { > XSLT 2.0 - loadFile(e, (t) => - setTabs((tabs) => - tabs.map((tab) => - tab.id === active ? { ...tab, xslt: stripParamBlock(t) } : tab, - ), - ) - )} - style={{ marginLeft: "0.5rem" }} - /> +