Comments (2)
LGraph.onchange() will be fired even when zooming and dragging canvas, without graph nodes values change
LGraph.onAfterChange() will not be fired when a node widget value change, either not fired when configure() a new graph....🫠
this is what I'm doing now but I don't think this is accurate:
document.addEventListener("click", (e) => {
if (
app.canvas.node_over != null ||
app.canvas.node_capturing_input != null ||
app.canvas.node_widget != null
) {
onIsDirty();
}
});
document.addEventListener("keydown", async function (event) {
if (document.visibilityState === "hidden") return;
const matchResult = await matchShortcut(event);
if (matchResult) {
shortcutListener(matchResult);
} else if (
// @ts-expect-error
event.target?.matches("input, textarea") &&
Object.keys(app.canvas.selected_nodes ?? {}).length
) {
onIsDirty();
}
});
```
from litegraph.js.
Perhaps someone needs it, I'll leave the code here that I'm sure can be used (there might be performance issues, but it can ensure that the graph change event is triggered correctly):
class LGraphPro extends LGraph {
private _graph_cache = {} as serializedLGraph;
emit(...args: any[]) { /* ... */ }
change(): void {
super.change();
this.emit("change");
this.checkGraphChange();
}
connectionChange(node: LGraphNode): void {
super.connectionChange?.(node);
this.emit("connection_change", node);
this.checkGraphChange();
}
serializeDeep(options?: {
skip_inputs?: boolean;
skip_outputs?: boolean;
skip_properties?: boolean;
skip_links?: boolean;
skip_nodes?: boolean;
}) {
const graph_obj = this.serialize();
graph_obj.nodes.sort((a, b) => a.id - b.id);
if (options?.skip_inputs) {
graph_obj.nodes.map((x) => (x.inputs = []));
}
if (options?.skip_outputs) {
graph_obj.nodes.map((x) => (x.outputs = []));
}
if (options?.skip_properties) {
graph_obj.nodes.map((x) => (x.properties = {}));
}
if (options?.skip_links) {
graph_obj.links = [];
}
if (options?.skip_nodes) {
graph_obj.nodes = [];
}
return cloneDeep(graph_obj);
}
private checkGraphChange() {
const graph_obj = this.serializeDeep({
skip_inputs: true,
skip_outputs: true,
skip_properties: true,
});
if (deepEqual(graph_obj, this._graph_cache)) {
return;
}
this._graph_cache = graph_obj;
this.events?.emit("graph_change", this.serializeDeep());
}
}
from litegraph.js.
Related Issues (20)
- Create a Basic Color node or Widget HOT 1
- computeConnectionPoint doesn't respect links_render_mode
- question: how to use ui for (*custom*) python code generation? HOT 2
- The method mounted on global in the ES Modules environment throws an error
- Linting question HOT 3
- Preview of what link is sending to node doesn't work after saving and reloading with configure HOT 1
- Text button and prompt dialog HOT 1
- Background turns black when zooming out HOT 2
- how to render a different link color when mouseover a link? HOT 1
- Getting the coordinates on a graph HOT 1
- How to realize redo and undo? HOT 2
- When the canvas attribute size and CSS style size are inconsistent, interactive events such as clicking on nodes fail. HOT 1
- Bootstrap 5.0.2 makes "Add Node" invisible
- Issue with Output Port Position Adjustment
- Numberpad enter creates a new line in input field of the properties. HOT 1
- Issue with Editor Resizing Not Centered on Mouse Position HOT 1
- npm run build error
- How do I change the color of a slot? HOT 3
- [question] How to clear all previously defined nodes? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from litegraph.js.