fix refresh
This commit is contained in:
+76
-57
@@ -58,70 +58,89 @@ app.registerExtension({
|
||||
|
||||
this.lastKnownNodeTitles = null;
|
||||
|
||||
const discoverAndBuildUI = () => {
|
||||
const groupIDWidget = this.widgets.find(w => w.name === "group_id");
|
||||
if (!groupIDWidget) return;
|
||||
const groupID = groupIDWidget.value;
|
||||
if (!groupID) return;
|
||||
const discoverAndBuildUI = () => {
|
||||
const groupIDWidget = this.widgets.find(w => w.name === "group_id");
|
||||
if (!groupIDWidget) return;
|
||||
|
||||
const activeWidget = this.widgets.find(w => w.type === 'toggle' && w.value);
|
||||
const activeTagName = activeWidget ? activeWidget.name : null;
|
||||
|
||||
this.widgets = this.widgets.filter(w => w.name === "group_id");
|
||||
|
||||
const discoveredTags = new Set();
|
||||
for (const node of getAllNodesInGraph()) {
|
||||
if (node.title) {
|
||||
const allMatches = [...node.title.matchAll(/\[\[(.*?):(.*?)\]\]/g)];
|
||||
for (const match of allMatches) {
|
||||
if (match[1] === groupID) {
|
||||
discoveredTags.add(match[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const groupID = groupIDWidget.value;
|
||||
if (!groupID) return;
|
||||
|
||||
let activeTagInGraph = null;
|
||||
const regexForScan = /\[\[(.*?):(.*?)\]\]/g;
|
||||
// MODIFICATION N°1
|
||||
for (const node of getAllNodesInGraph()) {
|
||||
if (node.mode === 0 && node.title) {
|
||||
for (const match of node.title.matchAll(regexForScan)) {
|
||||
if (match[1] === groupID) {
|
||||
activeTagInGraph = match[2];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (activeTagInGraph) break;
|
||||
}
|
||||
|
||||
this.widgets = this.widgets.filter(w => w.name === "group_id");
|
||||
|
||||
const discoveredTags = new Set();
|
||||
const regex = /\[\[(.*?):(.*?)\]\]/g;
|
||||
|
||||
const WORKFLOW_TAGS = Array.from(discoveredTags).sort();
|
||||
|
||||
if (WORKFLOW_TAGS.length === 0) {
|
||||
const currentWidth = this.size[0];
|
||||
const newComputedSize = this.computeSize();
|
||||
this.size = [currentWidth, newComputedSize[1]];
|
||||
return;
|
||||
}
|
||||
// MODIFICATION N°2
|
||||
for (const node of getAllNodesInGraph()) {
|
||||
if (node.title) {
|
||||
const allMatches = [...node.title.matchAll(regex)];
|
||||
for (const match of allMatches) {
|
||||
if (match[1] === groupID) {
|
||||
discoveredTags.add(match[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.widgets.push({ name: "top_spacer", type: "CUSTOM_SPACER", draw: () => {}, computeSize: () => [0, 10] });
|
||||
const WORKFLOW_TAGS = Array.from(discoveredTags).sort();
|
||||
|
||||
if (WORKFLOW_TAGS.length === 0) {
|
||||
const currentWidth = this.size[0];
|
||||
const newComputedSize = this.computeSize();
|
||||
this.size = [currentWidth, newComputedSize[1]];
|
||||
return;
|
||||
}
|
||||
|
||||
const handleToggleClick = (toggledTagName, isTurningOn) => {
|
||||
let newSelectedTag = isTurningOn ? toggledTagName : null;
|
||||
if (isTurningOn) {
|
||||
for (const w of this.widgets) {
|
||||
if (WORKFLOW_TAGS.includes(w.name) && w.name !== toggledTagName) {
|
||||
w.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
updateNodeStates(newSelectedTag, groupID, WORKFLOW_TAGS);
|
||||
};
|
||||
this.widgets.push({ name: "top_spacer", type: "CUSTOM_SPACER", draw: () => {}, computeSize: () => [0, 10] });
|
||||
|
||||
for (const tag of WORKFLOW_TAGS) {
|
||||
const isEnabled = (tag === activeTagName);
|
||||
this.addWidget("toggle", tag, isEnabled, (value) => { handleToggleClick(tag, value); });
|
||||
}
|
||||
const handleToggleClick = (toggledTagName, isTurningOn) => {
|
||||
let newSelectedTag = isTurningOn ? toggledTagName : null;
|
||||
|
||||
const anyTogglesOn = this.widgets.some(w => w.type === 'toggle' && w.value);
|
||||
if (WORKFLOW_TAGS.length > 0 && !anyTogglesOn) {
|
||||
const firstToggle = this.widgets.find(w => w.type === 'toggle');
|
||||
if(firstToggle) firstToggle.value = true;
|
||||
}
|
||||
|
||||
updateNodeStates(this.widgets.find(w => w.type === 'toggle' && w.value)?.name || null, groupID, WORKFLOW_TAGS);
|
||||
if (isTurningOn) {
|
||||
for (const w of this.widgets) {
|
||||
if (WORKFLOW_TAGS.includes(w.name) && w.name !== toggledTagName) {
|
||||
w.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateNodeStates(newSelectedTag, groupID, WORKFLOW_TAGS);
|
||||
};
|
||||
|
||||
const currentWidth = this.size[0];
|
||||
const newComputedSize = this.computeSize();
|
||||
this.size = [Math.max(currentWidth, newComputedSize[0]), newComputedSize[1]];
|
||||
app.graph.setDirtyCanvas(true, true);
|
||||
};
|
||||
// La création de vos widgets, conservée à l'identique
|
||||
for (const tag of WORKFLOW_TAGS) {
|
||||
this.addWidget("toggle", tag, false, (value) => { handleToggleClick(tag, value); });
|
||||
}
|
||||
|
||||
// Votre logique de restauration, conservée à l'identique
|
||||
if (activeTagInGraph) {
|
||||
const widgetToActivate = this.widgets.find(w => w.name === activeTagInGraph);
|
||||
if (widgetToActivate) {
|
||||
widgetToActivate.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
const currentWidth = this.size[0];
|
||||
const newComputedSize = this.computeSize();
|
||||
this.size = [currentWidth, newComputedSize[1]];
|
||||
|
||||
app.graph.setDirtyCanvas(true, true);
|
||||
};
|
||||
|
||||
const groupIDWidget = this.addWidget("STRING", "group_id", "DEFAULT", discoverAndBuildUI);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user