Skip to content

Commit

Permalink
🐛 fix dom widget mount timing
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzLuke96 committed May 22, 2024
1 parent d19a081 commit 534b890
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@litegraph-ts/core",
"version": "0.2.6",
"version": "0.2.7",
"description": "A graph node editor similar to PD or UDK Blueprints. It works in an HTML5 Canvas and allows to export graphs to be included in applications.",
"source": "src/index.ts",
"types": "src/index.ts",
Expand Down
28 changes: 18 additions & 10 deletions packages/core/src/widgets/DOMWidget.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { default as IWidget, WidgetCallback } from "../IWidget";
import LGraph from "../LGraph";
import LGraphNode, { SerializedLGraphNode } from "../LGraphNode";
import LiteGraph from "../LiteGraph";
import { NodeMode, Vector2 } from "../types";
Expand Down Expand Up @@ -275,17 +276,24 @@ export class DOMWidget implements IWidget {
});
}

const mountParentElement = (graph: LGraph) => {
const parentElement =
this.options.parentElement ||
graph.list_of_graphcanvas[0].canvas.offsetParent ||
document.body;
parentElement.appendChild(element);
};

if (!element.parentElement) {
const onAdded = this.node.onAdded;
this.node.onAdded = (graph) => {
onAdded?.(graph);

const parentElement =
this.options.parentElement ||
graph.list_of_graphcanvas[0].canvas.offsetParent ||
document.body;
parentElement.appendChild(element);
};
if (node.graph) {
mountParentElement(node.graph);
} else {
const onAdded = this.node.onAdded;
this.node.onAdded = (graph) => {
onAdded?.(graph);
mountParentElement(graph);
};
}
}
}

Expand Down

0 comments on commit 534b890

Please sign in to comment.