1
0
mirror of https://github.com/alexandrev/xslt-lab.git synced 2026-09-20 04:23:16 +00:00

Merge pull request #8 from alexandrev/7fe9nr-codex/update-toggle-section-with-combobox-and-align-buttons

Add dropdown for XSLT version and align file actions
This commit is contained in:
2025-07-03 09:17:55 +02:00
committed by GitHub
2 changed files with 70 additions and 43 deletions
+57 -42
View File
@@ -57,6 +57,19 @@ function debounce(fn, delay) {
}; };
} }
function setStylesheetVersion(text, version) {
const regex = /<xsl:stylesheet\b([^>]*)>/;
const match = text.match(regex);
if (!match) return text;
let attrs = match[1];
if (/version=['"][^'"]*['"]/.test(attrs)) {
attrs = attrs.replace(/version=['"][^'"]*['"]/, `version="${version}"`);
} else {
attrs += ` version="${version}"`;
}
return text.replace(regex, `<xsl:stylesheet${attrs}>`);
}
const goPro = import.meta.env.VITE_GO_PRO === "true"; const goPro = import.meta.env.VITE_GO_PRO === "true";
function defaultTab() { function defaultTab() {
@@ -351,55 +364,57 @@ export default function App() {
</div> </div>
<div className="editor"> <div className="editor">
<div style={{ marginBottom: "0.5rem" }} className="toggle"> <div style={{ marginBottom: "0.5rem" }} className="toggle">
<button <select
className={activeTab.version === "1.0" ? "active" : ""} value={activeTab.version}
onClick={() => onChange={(e) =>
setTabs((tabs) => setTabs((tabs) =>
tabs.map((t) => (t.id === active ? { ...t, version: "1.0" } : t)), tabs.map((t) =>
t.id === active
? {
...t,
version: e.target.value,
xslt: setStylesheetVersion(t.xslt, e.target.value),
}
: t,
),
) )
} }
> >
XSLT 1.0 <option value="1.0">XSLT 1.0</option>
</button> <option value="2.0">XSLT 2.0</option>
<button </select>
className={activeTab.version === "2.0" ? "active" : ""} <div className="right-actions">
onClick={() => <label className="icon-button file-label">
setTabs((tabs) => 📤
tabs.map((t) => (t.id === active ? { ...t, version: "2.0" } : t)), <input
) type="file"
} accept=".xsl,.xslt"
> className="file-input"
XSLT 2.0 onChange={(e) =>
</button> loadFile(e, (t) =>
<label className="icon-button file-label" style={{ marginLeft: "0.5rem" }}> setTabs((tabs) =>
📤 tabs.map((tab) =>
<input tab.id === active
type="file" ? { ...tab, xslt: stripParamBlock(t) }
accept=".xsl,.xslt" : tab,
className="file-input" ),
onChange={(e) => )
loadFile(e, (t) =>
setTabs((tabs) =>
tabs.map((tab) =>
tab.id === active ? { ...tab, xslt: stripParamBlock(t) } : tab,
),
) )
}
/>
</label>
<button
className="icon-button"
onClick={() =>
download(
injectParamBlock(activeTab.xslt, activeTab.params),
"transform.xsl",
) )
} }
/> >
</label> 📥
<button </button>
className="icon-button" </div>
onClick={() =>
download(
injectParamBlock(activeTab.xslt, activeTab.params),
"transform.xsl",
)
}
style={{ marginLeft: "0.5rem" }}
>
📥
</button>
</div> </div>
<Editor <Editor
height="100%" height="100%"
+13 -1
View File
@@ -39,10 +39,22 @@ body,
font-weight: bold; font-weight: bold;
} }
.toggle button { .toggle {
display: flex;
align-items: center;
}
.toggle button,
.toggle select {
margin-right: 0.25rem; margin-right: 0.25rem;
} }
.toggle .right-actions {
margin-left: auto;
display: flex;
align-items: center;
}
.error-box { .error-box {
background: #fee; background: #fee;
color: #900; color: #900;