mirror of
https://github.com/alexandrev/xslt-lab.git
synced 2026-09-21 04:43:16 +00:00
+1
This commit is contained in:
+5
-12
@@ -30,9 +30,7 @@ function stripParamBlock(text) {
|
|||||||
function getParamBlock(text) {
|
function getParamBlock(text) {
|
||||||
const start = text.indexOf(PARAM_START);
|
const start = text.indexOf(PARAM_START);
|
||||||
const end = text.indexOf(PARAM_END);
|
const end = text.indexOf(PARAM_END);
|
||||||
console.log(`####### ${start} - ${end}`)
|
|
||||||
if (start !== -1 && end !== -1 && end > start) {
|
if (start !== -1 && end !== -1 && end > start) {
|
||||||
console.log(`####### ${start} - ${end}`)
|
|
||||||
return text.slice(start, end);
|
return text.slice(start, end);
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
@@ -52,6 +50,7 @@ function injectParamBlock(text, params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addParams(text, tab) {
|
function addParams(text, tab) {
|
||||||
|
console.log("AQUI!!!!")
|
||||||
const extractedParams = extractParamNames(text);
|
const extractedParams = extractParamNames(text);
|
||||||
const existingNames = new Set(tab.params.map(p => p.name));
|
const existingNames = new Set(tab.params.map(p => p.name));
|
||||||
const newParams = [...tab.params];
|
const newParams = [...tab.params];
|
||||||
@@ -67,12 +66,10 @@ function addParams(text, tab) {
|
|||||||
|
|
||||||
function extractParamNames(text) {
|
function extractParamNames(text) {
|
||||||
const clean = getParamBlock(text);
|
const clean = getParamBlock(text);
|
||||||
console.log(`##########111 ${clean}`)
|
|
||||||
const names = new Set();
|
const names = new Set();
|
||||||
const regex = /<xsl:param[^>]*name="([^"]+)"[^>]*>/g;
|
const regex = /<xsl:param[^>]*name="([^"]+)"[^>]*>/g;
|
||||||
let m;
|
let m;
|
||||||
while ((m = regex.exec(clean))) {
|
while ((m = regex.exec(clean))) {
|
||||||
console.log(`##########-- ${m[1]}`)
|
|
||||||
names.add(m[1]);
|
names.add(m[1]);
|
||||||
}
|
}
|
||||||
return Array.from(names);
|
return Array.from(names);
|
||||||
@@ -155,14 +152,10 @@ export default function App() {
|
|||||||
|
|
||||||
const syncParams = useCallback(() => {
|
const syncParams = useCallback(() => {
|
||||||
const names = extractParamNames(injectParamBlock(activeTab.xslt, activeTab.params));
|
const names = extractParamNames(injectParamBlock(activeTab.xslt, activeTab.params));
|
||||||
console.log(`######### names ${names}`)
|
|
||||||
setTabs((tabs) =>
|
setTabs((tabs) =>
|
||||||
tabs.map((t) => {
|
tabs.map((t) => {
|
||||||
console.log("#####1")
|
|
||||||
if (t.id !== active) return t;
|
if (t.id !== active) return t;
|
||||||
console.log("#####2")
|
|
||||||
let params = [...t.params];
|
let params = [...t.params];
|
||||||
console.log("#####2")
|
|
||||||
let changed = false;
|
let changed = false;
|
||||||
names.forEach((n) => {
|
names.forEach((n) => {
|
||||||
if (!params.some((p) => p.name === n)) {
|
if (!params.some((p) => p.name === n)) {
|
||||||
@@ -171,7 +164,6 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const filtered = params.filter((p) => names.includes(p.name) || p.value);
|
const filtered = params.filter((p) => names.includes(p.name) || p.value);
|
||||||
console.log(`#####3. ${filtered}`)
|
|
||||||
if (filtered.length !== params.length) {
|
if (filtered.length !== params.length) {
|
||||||
params = filtered;
|
params = filtered;
|
||||||
changed = true;
|
changed = true;
|
||||||
@@ -181,6 +173,8 @@ export default function App() {
|
|||||||
);
|
);
|
||||||
}, [active, activeTab.xslt]);
|
}, [active, activeTab.xslt]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const runTransform = debounce(async (xsltText, ver, p) => {
|
const runTransform = debounce(async (xsltText, ver, p) => {
|
||||||
const paramObj = {};
|
const paramObj = {};
|
||||||
p.forEach((pr) => {
|
p.forEach((pr) => {
|
||||||
@@ -473,13 +467,12 @@ export default function App() {
|
|||||||
height="100%"
|
height="100%"
|
||||||
language="xml"
|
language="xml"
|
||||||
wrapperProps={{
|
wrapperProps={{
|
||||||
style: { flex: 1, height: "100%", minHeight: 0 },
|
|
||||||
onDragOver: (e) => e.preventDefault(),
|
onDragOver: (e) => e.preventDefault(),
|
||||||
onDrop: (e) =>
|
onDrop: (e) =>
|
||||||
handleDrop(e, (t) =>
|
handleDrop(e, (t) =>
|
||||||
setTabs((tabs) =>
|
setTabs((tabs) =>
|
||||||
tabs.map((tab) =>
|
tabs.map((tab) =>
|
||||||
tab.id === active ? { ...tab, xslt: stripParamBlock(t) } : tab,
|
tab.id === active ? { ...tab, xslt: stripParamBlock(t), params: addParams(t,tab) } : tab,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -488,7 +481,7 @@ export default function App() {
|
|||||||
onChange={(v) =>
|
onChange={(v) =>
|
||||||
setTabs((tabs) =>
|
setTabs((tabs) =>
|
||||||
tabs.map((tab) =>
|
tabs.map((tab) =>
|
||||||
tab.id === active ? { ...tab, xslt: stripParamBlock(v || "") } : tab,
|
tab.id === active ? { ...tab, xslt: stripParamBlock(v || ""), params: addParams(v,tab) } : tab,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ body,
|
|||||||
|
|
||||||
|
|
||||||
.result {
|
.result {
|
||||||
height: 50vh;
|
height: 40vh;
|
||||||
border-top: 1px solid #ddd;
|
border-top: 1px solid #ddd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user