Commit Graph

143 Commits

Author SHA1 Message Date
Chenlei Hu
8a94232f61 [nit] Remove IDrawOptions.showText (#879)
`showText` is essentially an alias of `!lowQuality`. Removing it from
the interface.
2025-04-03 11:24:51 -04:00
Chenlei Hu
30a7f19a64 Upstream progressbar rendering (#871)
Upstreams progress bar rendering from ComfyUI_frontend.
2025-03-30 17:14:09 -04:00
Chenlei Hu
0eeaf90647 [nit] Rename IDrawBoundingOptions args (#869) 2025-03-30 11:46:45 -04:00
Chenlei Hu
854ac4350f Add LGraphNode.strokeStyles API (#868)
This should allow frontend drop the stroke logic in hijack of
`drawNodeShape`. Example usage:

```ts
node.strokeStyles["executionError"] = (this: LGraphNode) => 
  app.lastNodeErrors?.[this.id] ? { colour: 'red', thickness: 2 } : undefined
```
2025-03-30 11:29:37 -04:00
Chenlei Hu
7fc8f8c897 Add lowQuality param to IWidget.draw (#843)
Currently widget needs to get access to `LGraphCanvas` instance to know
whether the canvas is rendering in low quality (Zoomed out). Usually
canvas object is obtained from `ComfyApp` instance.

This PR passes the lowQuality value to `IWidget.draw` to decouple the
dependency on `LGraphCanvas`.
2025-03-23 20:50:14 -04:00
filtered
05587d8a19 Fix moving existing links can result in loopback (#838)
Prevents nodes connecting links to themselves when moving existing
links.

If moving multiple links with reroutes, this will instead _reconnect_
any links that would become loopbacks, only without any rereoutes.
2025-03-23 19:00:55 +00:00
filtered
642e73773c [CodeHealth] Improve legibility of renderingBoxColor (#832)
Drastically reduces the cognitive complexity of
`LGraphNode.renderingBoxColor` by impl. early returns.
2025-03-22 21:53:42 +00:00
filtered
a44b8d0581 Fix bypass links on delete gives up after corrupt link (#831)
Bypass links will now continue to attempt to connect other links,
instead of silently giving up on the first corrupt link it finds.
2025-03-22 21:50:18 +00:00
filtered
ba7f870e0f [CodeHealth] Improve code readability (#830) 2025-03-22 21:48:26 +00:00
filtered
b254bae5c5 Allow floating reroutes to be chained when creating new (#828)
- Resolves #827
2025-03-23 07:38:11 +11:00
filtered
0dd060a369 [API] Require always-exported node properties be defined (#821)
Now required:

- `type`
- `pos`
- `size`
- `flags`
- `order`
- `mode`
2025-03-23 03:25:57 +11:00
filtered
2dbd5f4cf0 Allow creating floating reroutes from new link menu (#818)
Adds an `Add Reroute` option to the new link menu. Creates a new
floating reroute connected to the source slot.
2025-03-22 09:23:20 +11:00
filtered
87aeab16a0 [API] Fix several floating links issues & add Reroute.totalLinks (#815)
Resolves several issues with floating links.  Highlights:

- Caches floating links on slots, removing some loop checks (inefficient
/ does not scale)
- Simpler APIs
- Adds `Reroute.totalLinks` (regular and floating
2025-03-21 19:17:54 +00:00
filtered
9315a8810e Increase slot context menu hit box (#777)
Previously, gap between slots was the same height as the slot itself.

Gap is now entirely removed, bringing it inline with the
previously-modified snap and link connection hit boxes.
2025-03-13 22:30:22 +00:00
filtered
034692120e [Refactor] Replace deprecated getConnectionPos (#776)
Uses `getInputPos` or `getOutputPos` where appropriate.
2025-03-13 22:19:28 +00:00
filtered
e6a914117b Add floating reroutes (#773)
### Floating reroutes

Native reroutes can now be kept in a disconnected state.

Link chains may be kept provided they are connected to _either_ an input
or an output. By design, reroutes will be automatically removed if both
sides are disconnected.
2025-03-13 19:56:57 +00:00
Chenlei Hu
d0e1998415 [TS] Add null-checks for LGraphNode layouts (#772)
Ref: https://github.com/Comfy-Org/litegraph.js/issues/616
Resolves https://github.com/Comfy-Org/litegraph.js/issues/770

This PR adds null-checks to various part of layout code to avoid we get
into irrecoverable state.
2025-03-13 13:50:04 -04:00
filtered
2e9f877bbd [Cleanup] Reroute and serialisation (#767)
- Fixes root cause of minor in-memory-only corruption when deleting
reroutes from output slots
  - Already automatically corrected via serialisation
- If `reroutes` or `links` are empty arrays, removes them from newer
object-based serialised output entirely
- Minor refactors
- Removes unused code
- Fixes some serialisation types
- Adds `ReadonlyLinkNetwork` interface
2025-03-13 14:40:12 +00:00
filtered
27873d0351 [Cleanup] Remove duplicate code (#754)
- Removes null widget skip - this _should_ throw
- Removes widget locator that was on LGraphCanvas - canvas should not
functions that find things in graph space.
2025-03-11 16:41:37 +00:00
filtered
a7f2ff16a9 [TS] Remove optional from widget y and type (#752)
- Fixes widget `type` marked as optional - it is required
- Fixes widget `y` marked as optional - now initialised to 0
2025-03-11 15:46:10 +00:00
Chenlei Hu
db680c96ad [Bug] Fix node empty space on converted widget (#740)
Resolves https://github.com/Comfy-Org/litegraph.js/issues/739

This is a temporary measurement to fix the issue. We should probably
consider build a more robust layout mechanism later.
2025-03-10 14:31:50 -04:00
filtered
e632f5c69b Fix all unknown slot props are serialised (#732)
Ensures only specified properties are cloned for serialisation.
2025-03-10 12:20:34 +00:00
filtered
c0bfe5489f [API] Add LinkConnector - replaces connecting_links (#726)
### LinkConnector

Replaces the minimal-change effort of `connecting_links` with a more
reliable implementation.

- Subscribable, event-based API
- Uses browser-standard `e.preventDefault()` to cancel `before-*` events
- Uses standard `state` POJO - can be proxied without issue
- Structures code and separates concerns out of `LGraphCanvas`
- Link creation calls can now be made from anywhere, without the need
for a rewrite
- New canvas sub-components now live in `src/canvas/`

### Rendering

- Skips link segments by setting a `_dragging` bool flag on the LLink or
Reroute
- Moves some previously nested code to event listeners, configured in
the `LGraphCanvas` constructor

### Deprecation

`LGraphCanvas.connecting_links` is now deprecated and will later be
removed.

Until it is removed, to prevent breaking extensions it will continue to
be set and cleared by a legacy callback. The contents of this property
are ignored; code search revealed no exentsions actually modifying the
array.
2025-03-08 23:48:45 +00:00
filtered
5ab9d9d25c Warn users if calling connectSlots incorrectly (#724)
Prevents silent failures from going unnoticed.
2025-03-08 18:21:10 +00:00
filtered
20bdc47550 [API] Add convenience methods to LGraphNode (#717)
- getInputOnPos
- getOutputOnPos
- getSlotOnPos
- Follow-up on #716 
- Uses more explicit names for class methods moved to module functions
2025-03-07 14:38:55 +00:00
filtered
3e44f6a0c1 [API] Add improved slot locator functions (#716)
- Returns object with slot, index, and pos
- Locate-by-type returns object with slot & index
- Uses standard `undefined` return for concise chaining & validation
- Free 10x perf increase over getConnectionPos (used basic random data
to test, out of curiosity)
2025-03-07 13:18:06 +00:00
filtered
a5c2464c88 [Refactor] Simplify code - getConnectionOnPos (#710)
Improves readability of `LGraphNode.getConnectionOnPos`.
2025-03-06 12:00:51 +00:00
filtered
7a2af7008b [Refactor] Rename to connectSlots (#708)
- Follow-up on #703 
- Changes name to match original intent
2025-03-05 19:01:26 +11:00
filtered
3411ecbc15 [Refactor] Allow bypassing legacy duck-typed API (#703)
`LGraphNode.connect()` has been altered many times and attempts to
handle too many scenarios in a single public call.

- Moves link creation to a separate function
- Allows the legacy duck-typed API to continue functioning as-is
2025-03-04 14:23:53 +00:00
filtered
8a3487a209 Remove redundant code - LGraphNode (#702)
- Removes unreachable and redundant code.
- Fixes TS type
2025-03-05 00:58:02 +11:00
filtered
8bee428375 [API] Remove unused LGraph.onNodeConnectionChange (#701)
Confirmed unused via code search.
2025-03-04 09:18:38 +00:00
filtered
b227eefbdd Improve connecting link logic (#697)
### Current

- Connections are disconnected the moment a link starts being dragged
- Reseating a connection where it came from creates a new connection
- If the process is somehow interrupted, the links are already gone

### Proposed

- Connection is disconnected after a new connection is made
- Rendering is bypassed for the link segment being moved
- Does nothing if dropping a link exactly where it came from
- Adds early return when trying to connect a node to itself
2025-03-03 17:03:31 +00:00
filtered
af7db40fce [chore] Clean up ignores after strict mode enabled (#680)
- Replaces all `ts-ignore` with `ts-expect-error`
- Resolves https://github.com/Comfy-Org/litegraph.js/issues/578
2025-03-02 14:56:15 +00:00
filtered
b1885ebec8 Remove redundant code - onGetInputs / onGetOutputs (#674)
- Removes unused context menu for optional in/outputs
- At the top of the node context menu, greyed out `Inputs` and `Outputs`
- API does not fit with current design
- If required, rewrite would be simpler
2025-03-02 13:47:48 +00:00
filtered
6cb9131035 [TS] Use strict mode in LGraphCanvas (#673)
- Adds remaining TS nullable types
- Adds type guards to allow strict mode
  - Uses explicit throw in places that would throw regardless
- Adds ts-ignore that must be removed later
  * [ ] #578
2025-03-02 13:34:02 +00:00
filtered
539fa91b0d [TS] Use strict mode in LGraphCanvas (#664)
- Prefer `undefined` over `null`
- Primarily nullable type updates
2025-03-01 21:58:50 +00:00
filtered
b36bf3d4a2 [CodeHealth] Apply modern standards to LGraphCanvas (#650)
- Prefer template string
- Prefer explicit throw to undefined TypeError
- Remove unnecessary `this` assignment
2025-02-28 22:08:23 +00:00
filtered
c4faaf4210 [TS] Fix ContextMenu types (#649)
- No runtime changes
- Drastically improves ContextMenu type accuracy / safety
- Allows TS strict conversion
2025-02-28 14:52:07 +00:00
filtered
0a09ecc7ac [TS] Use strict mode in LGraphNode (#642)
- Adds minor type coercions to resolve type errors
- Deprecates unused public APIs
- 7a0336e3ad7239b7bb588bbbe7912322257e9ae2 works around a bug in the tsc
strict plugin
- Adds ts-ignore that must be removed later
  * [ ] #578
2025-02-27 19:03:42 +00:00
filtered
fab386275c [Refactor] Clean up LGraphNode ahead of TS strict (#641)
Preparation for TS strict conversion. Simplifies code & improves
readability.
2025-02-27 17:55:11 +00:00
filtered
38dd7b7089 [Refactor] Prefer for..of to incremental for loops (#640)
- Converts incremental for loops to for..of loops
- Improves readability
2025-02-27 16:28:10 +00:00
filtered
be8dc6867e [Refactor] Prefer event listeners to callback props (#637)
N.B.: `onerror` replacement is not a `window` or `Element` instance.
2025-02-27 14:50:39 +00:00
filtered
97bf9de83a [Refactor] Standardise code style - modern JS (#636)
Uses unicorn rules to auto-refactor code.  All verified.
2025-02-27 13:13:32 +00:00
filtered
2d9c811aa9 [Cleanup] Remove downstream type (#632)
Removes group node type. Now exists downstream where it is used.
2025-02-27 10:38:24 +00:00
filtered
0d8e0fce17 [Refactor] Fix assignment of this to const (#631)
Refactors using arrows funcs or storing the once-off requirement as an
action, removing the need to dereference this inside the function.
2025-02-27 10:32:53 +00:00
filtered
1e8938ceff Add unicorn lint rules - DOM built-in functions (#628)
- Prefer append(), remove(), replaceAll()
- Wrap nested ternaries in parenthesis
2025-02-27 09:18:25 +00:00
Miguel C
7e6b64f216 Fix widget sizing logic in LGraphCanvas and LGraphNode (#609)
This fixes an issue with widget heights not coinciding with actual
computed heights.
<img
src="https://github.com/user-attachments/assets/50b4b86c-8de8-4844-9a17-6f18d32e7f5e"
height="128" alt="old">old
<img
src="https://github.com/user-attachments/assets/c34e432a-6941-469e-99cd-df15c0a527de"
height="256" alt="new">new
2025-02-26 10:56:30 -05:00
filtered
0e9b8b03b7 Enforce curly braces in multi-line if statements (#619)
Removes formatters' ability to print code that goes to a new line, but
uses no braces to delineate.

It becomes more difficult to follow when using JS-style indents (two
spaces).

No effort required - braces added by auto-fixer.
2025-02-26 15:08:23 +00:00
filtered
3040924d76 [TS] Use strict mode in CanvasPointer, measure, and polyfills (#617)
- Adds runtime type guard
- Adds ts-ignore that must be removed later
  * [ ] #578
2025-02-26 13:05:40 +00:00
filtered
867b9ed316 [nit] Add consistent method chaining linter (#613)
Enforces that chained accessed should **either** all be on one line, or
all on individual lines (same as imports).
2025-02-26 10:11:11 +00:00