Frontend Helpers (JS)
These are the essential helper functions from BaseNode that you will use to build your node’s frontend.
Widget Management
Section titled “Widget Management”this.addPropertyWidget(type, label, propertyKey, options)
Section titled “this.addPropertyWidget(type, label, propertyKey, options)”The Best Way to add widgets.
Automatically binds the UI widget to this.properties, ensuring values are saved and sent to the backend.
- type:
"number","slider","combo","text","toggle"
// Slider Examplethis.addPropertyWidget("slider", "Strength", "strength", { min: 0.0, max: 1.0});
// Dropdown Examplethis.addPropertyWidget("combo", "Mode", "mode", { values: ["Fast", "Quality", "Extreme"]});this.addReactColorWidget(label, propertyKey, defaultColor)
Section titled “this.addReactColorWidget(label, propertyKey, defaultColor)”Adds a Color Picker. Opens a system color dialog when clicked.
this.addReactColorWidget("Text Color", "textColor", "#FFFFFF");this.updateWidgets()
Section titled “this.updateWidgets()”Syncs UI with Data.
Call this if you change this.properties in your code and want the sliders/inputs to update visually.
// Example: Resetting a value programmaticallythis.properties.strength = 0.5;this.updateWidgets(); // Now the slider jumps to 0.5Server Communication
Section titled “Server Communication”this.normalizeUrl(path)
Section titled “this.normalizeUrl(path)”Fixes file paths for images/video.
Converts a backend path (like temp/image.png) into a working browser URL (like http://localhost:5555/temp/image.png).
// Usage in onDrawBackgroundconst safeUrl = this.normalizeUrl(this.properties.preview_path);const img = new Image();img.src = safeUrl;Drawing Updates
Section titled “Drawing Updates”this.setDirtyCanvas(fg, bg)
Section titled “this.setDirtyCanvas(fg, bg)”Forces a Redraw. Essential for custom rendering. Blobit only repaints when it thinks it needs to. If you load an image or change an animation frame, you must tell it to repaint.
- fg: detailed boolean (foreground/widgets).
- bg: detailed boolean (background/connections).
// Example: Redraw after image loadsimg.onload = () => { this.setDirtyCanvas(true, true);};