Commit Graph

53 Commits

Author SHA1 Message Date
filtered
c8bd5e43dd Add litegraph input indicator helper class (#842)
Example usage with ComfyUI_frontend, via console / devtools:

```ts
const inputIndicators = new InputIndicators(app.canvas)
// Dispose:
inputIndicators.dispose()
```
2025-03-24 11:43:36 +11:00
filtered
fd4ffbc1f8 Fix render issues after moving floating input links (#841)
- Fixes floating inputs have invisible segment after moving
- Fixes floating input can be moved onto existing input link, resulting
in the slot having two links
2025-03-24 00:16:06 +00: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
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
cd9778bb6c Fix reroutes lost when dropping output links on reroute (#820)
Blocks attempts to drag links from an output onto a reroute in any of
the links.
2025-03-22 13:49:26 +00:00
filtered
7c6245ab1c [Test] Add LinkConnector unit & integration tests (#816)
- Follow-up on #817

### Unit tests

Adds tests for:

- LinkConnector
- LGraph

### Integration tests for LinkConnector

- Uses and configures a real graph + LGraph
- Avoids mocks
  - User input is still mocked
- Performs actual tasks as would be called by LGraphCanvas
- A little verbose in places, but _many_ edge cases are caught by these
tests
2025-03-22 06:47:40 +11:00
filtered
850d1b9652 [API] Finalise LinkConnector design, adding reroute logic (#817)
- Splits link connect logic out of `LinkConnector` to individual
`RenderLink` classes
- Add support for connecting / reconnecting reroutes in various
configurations
- Adds support for moving existing floating links from outputs / inputs
- Fixes numerous corruption issues when reconnecting reroutes / moving
links
- Tests in separate PR #816
2025-03-21 19:41:20 +00:00
filtered
9e64bf7278 [Test] Add LinkConnector tests (#808) 2025-03-20 22:20:11 +11:00
filtered
39a9799db7 [Test] Add unit tests - complex floating links & nodes (#796) 2025-03-17 13:25:57 +11:00
Chenlei Hu
b71150a939 [Test] Add more tests on reroute (#793) 2025-03-16 19:12:57 -04:00
Chenlei Hu
94b9ecec71 [Bug] Fix remove of floatingLinks (#792)
Resolves https://github.com/Comfy-Org/litegraph.js/issues/791

This PR fixes removal of floating links.

---------

Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
2025-03-16 22:13:24 +00:00
filtered
dbc605e4da Add graph ID creation / serialisation (#790)
- Updates UUIDv4 generator
- Adds a unique id & revision support to graphs
- `revision` to be incremented downstream (e.g. on save)
- `id` automatically assigned if not provided
2025-03-16 18:41:08 +00:00
filtered
84dad03f4d Remove static circular dependency workaround (#734)
Workaround originally implemented when converting to ES modules, but is
now redundant.

`DEFAULT_EVENT_LINK_COLOR` confirmed unused in code search (litegraph
events).
2025-03-10 15:29:33 +00: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
68945cb54d Remove getTime workaround and Node.js type bleeding (#723)
- Removes legacy timer workaround (redundant on Chrome v6 / Node.js v16)
- Removes old type workarounds
- Improves type inference speed
2025-03-08 13:27:49 +00:00
Chenlei Hu
c66ca2ae66 Remove magic 10% scale on numeric widget step (#643)
There are external code still dependent on the fact that
Widget.options.step is scaled 10x, so the 10x-ed value is still kept
there, while we use the new unscaled step2 within our code now.

Ref:
https://cs.comfy.org/search?q=context:global+%22step+/+10%22&patternType=keyword&sm=0
2025-02-27 16:23:53 -05:00
filtered
6737828a2b Lint module entry point (#635)
- Adds module entry point tests
- Manually resolved lint rules for module entry point imports / exports
(autofix could not resolve without causing issues)
2025-02-27 12:02:03 +00:00
Chenlei Hu
d20aab757c Serialize NodeInputSlot.widget (#622)
Serialize linked widget on node input slot properly according to current
save format in
76818b54e6/src/extensions/core/widgetInputs.ts
2025-02-26 14:15:31 -05:00
filtered
6224d2dc06 [Cleanup] Update ESLint rules with stricter auto-fixes (#614)
Stylistic plugin falls short in a few areas when it comes to consistent
lists and chaining. Replaced some key rules with antfu's personal
variants.

`eslint` can now be run repo-wide without params.
2025-02-26 11:12:03 +00:00
filtered
477d498d6b [API] Remove unused: optional_inputs & outputs (#597)
Code search shows zero usage. If kept, typing properly would require
effort.

Removed:
- `LGraphNode.optional_inputs`
- `LGraphNode.optional_outputs`
2025-02-25 16:33:21 +00:00
filtered
2c3535c983 [Test] Add integration test: LGraph snapshot (#591)
- Runs basic Litegraph init before performing the snapshot
- Allows a significantly more useful verification of the public API
2025-02-25 08:58:29 +00:00
filtered
630fd00086 [API] Remove unused LiteGraph APIs (#582)
* [API] Remove unused LiteGraph APIs

These features have not been maintained, and would require refactoring / rewrites. As code search revealed them to be unused, they are being removed.

- addNodeMethod
- compareObjects
- auto_sort_node_types

* Udpate API.md
2025-02-24 12:04:07 +00:00
filtered
f3b51a534e [Test] Standardise unit test infrastructure (#572)
* [Test] Revert custom name for test context

- Removes "lgTest", replaces with default "test"

* nit - Rename test extensions file

* Split test graphs out to separate file
2025-02-24 01:56:22 +00:00
Chenlei Hu
f300e37a89 Remove NodeSlot.pos when serializing WidgetInputSlot (#570) 2025-02-23 16:11:56 -05:00
Chenlei Hu
d23a320f9f Upstream frontend widgets layout logic (#531)
* Upstream frontend widgets layout logic

* Add back LGraphNode.freeWidgetSpace

* nit

* update expectations
2025-02-14 19:22:37 -05:00
Chenlei Hu
9abcf0fd32 Remove LGraphNode.horizontal (#521)
* Remove LGraphNode.horizontal

* nit
2025-02-12 15:11:59 -05:00
Chenlei Hu
7813e5207a Revert "Revert "Convert i/o slot to class in LGraphNode.configure"" (#518)
* Revert "Revert "Convert i/o slot to class in LGraphNode.configure (#506)" (#511)"

This reverts commit d029bd8924.

* nit
2025-02-12 11:06:35 -05:00
Chenlei Hu
d029bd8924 Revert "Convert i/o slot to class in LGraphNode.configure (#506)" (#511)
This reverts commit c75157e86e.
2025-02-09 23:35:40 -05:00
Chenlei Hu
c75157e86e Convert i/o slot to class in LGraphNode.configure (#506) 2025-02-09 15:23:38 -05:00
Chenlei Hu
3cd08e9e0c Remove LGraph._subgraph_node (Legacy subgraph) (#456) 2025-02-03 23:36:38 -05:00
Chenlei Hu
b3dbc41368 Remove LGraphNode.subgraph (Legacy subgraph) (#453)
* Remove LGraphNode.subgraph (Legacy subgraph)

* Update snapshot
2025-02-03 23:27:11 -05:00
Chenlei Hu
817214e6da [Refactor] Move strokeShape from LGraphCanvas to draw (#435)
* [Refactor] Move strokeShape from LGraphCanvas to draw

* Fix round radius

* nit

* nit

* nit
2025-02-02 22:29:26 -05:00
bymyself
9a8c3dff89 Remove scaling of context menus (#431)
* remove scaling of context menus based on graph scale

* deprecate scale in interface

* Add option to restore old context scaling behaviour

Revert "remove scaling of context menus based on graph scale"

This reverts commit d91ecaa86c671aea272844c3900a18da1af7bf01.

* Update test expectations

---------

Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
2025-01-27 19:41:08 +11:00
Chenlei Hu
11ce8e0f7b Fix NODE_DEFAULT_SHAPE (#389)
* Fix NODE_DEFAULT_SHAPE

* update snapshot
2024-12-23 20:04:32 -05:00
filtered
71f8a1decf Export Reroute class the same as other similar classes (#378)
* Export Reroute class the same as other similar classes

* Update test expectations
2024-12-15 10:54:50 -08:00
filtered
91077aa20b Redesign invalid node indicator (#358)
* nit

* Remove unused code

Gradient can (and should) be impl. directly by caching a CanvasGradient.

* nit

* nit - Refactor

* Remove redundant code

* Add line width & colour options to shape stroke

* Rename drawSelectionBounding to strokeShape

* nit - Doc

* Fix rounded corners not scaling with padding

* Optimise node badge draw

* Redesign invalid node visual indication

Customisable boundary indicator now used, replacing red background.

* Update snapshot

---------

Co-authored-by: huchenlei <huchenlei@proton.me>
2024-11-29 16:26:25 -05:00
filtered
ee45593558 Move Snap to Grid control to LiteGraphGlobal (#329)
* Fix snap to grid - now toggled at app level

Was impl. as per workflow.

* Update test expectations
2024-11-21 10:19:00 -05:00
pythongosssss
1bec315427 Adds highlight to advanced widgets (#317)
* Adds highlight to advanced widgets

* Update snapshot
2024-11-18 13:16:52 -05:00
filtered
c0e8b33716 Snap everything to grid (#315)
* Implement snap to grid

- Moves positioning logic to LGraph
- Simplifies code
- Adds Pointer API to alt-clone node
- Removes always_round_positions, replaced by always snap to grid (default size is 1 when always snapping)

Fix refator error

* Fix group items snapped without group

* Allow snapping of all items

- Add snapToGrid to Positionable
- Impl. on all types
- Deprecated: alignToGrid is now a wrapper

* Fix test import alias, update expectations

* Prevent desync of before / after change events

Adds ability to perform late binding of finally() during drag start.

* nit - Refactor

* Fix unwanted snap on node/group add

* nit - Doc

* Add shift key state tracking for snap to grid

Private impl., no state API as yet.

* Add snap guides rendering

Nodes, reroutes

* Optimisation - reroute rendering

 Fixes exponential redraw

* Add snap guidelines for groups
2024-11-18 10:12:20 -05:00
filtered
b29a32c1ae Add CanvasPointer API (#308)
* Add position rounding feature

Replaces previous impls. which only worked on some items, and were triggered when unexpected e.g. clicking a node that hadn't been moved.

Update test expectations

* Narrow TS types - readonly

* nit - Clean up, Doc

* nit - Clean up legacy accessors

Marks as deprecated

* Fix TS type - IContextMenuOptions.scale

* [Refactor] dist2 for use in pointer API

* Add CanvasPointer - API for pointer events

Add TS strict types
Add final click drag distance math
Add option to retain events

* nit - Rename

* nit

* Remove Subgraph - unused & not maintained

* Remove live_mode

Unused, not maintained.

* Update README

Remove live_mode reference

* Update delete selected - include reroutes & groups

* Bypass link menu if alt/shift pressed

* Remove old dragged_node interface

Incomplete impl. - unused.
Superceded by selectedItems

* Fix top/left edge of rectangles not in hitbox

* [Refactor] Match function names to interface names

* Add interface to find widgets by Point

LGraphNode.getWidgetOnPos

* Add widget search param - includeDisabled

* nit - Doc

* Rewrite canvas mouse handling

- Rewrites most pointer handling to use CanvasPointer callbacks
- All callbacks are declared ahead of time during the initial pointerdown event, logically grouped together
- Drastically simplifies the alteration or creation of new click / drag interactions
- Click events are all clicks, rather than some processed on mouse down, others on mouse up

- Functions return instead of setting and repeatedly checking multiple state vars
- Removes all lines that needed THIRTEEN tab indents

* Split middle click out from processMouseDown

* Use pointer API for link menus

* Narrow canvas event interfaces

* Fix canvas event types

Replaces original workarounds with final types

* Refactor - deprecated isInsideRectangle

* Add canvas hovering over state

- Centralises cursor set behaviour
- Provides simple downstream override

* nit

* [Refactor] Use measure functions

* Add double-click API to CanvasPointer

a

* nit - Doc

* Allow larger gap between double click events

* Rewrite double-click into CanvasPointer actions

* Improve double-click UX

Prefer down events over up events

* Add production defaults

* Add middle-click handling

* Remove debug code

* Remove redundant code

* Fix add reroute alt-click adds two undo steps

* Fix click on connected input disconnects

Old behaviour was to disconnect, then recreate a new link on drop.

* Add module export: CanvasPointer
2024-11-16 17:35:30 -05:00
filtered
3e28ec5981 Update tests for schema v1 (#289) 2024-11-08 11:12:09 -05:00
filtered
7e21b00cc7 Replace test framework: jest -> vitest (#281)
* Replace test framework: jest -> vitest

* nit - remove deprecated npm scripts

* Add vitest config

* Add a few basic tests

* Update actions with vitest params

* Add correct expectations

* Remove jest config
2024-11-06 17:27:32 -05:00
Chenlei Hu
b663f86c9e Serialize to node pos/size to plain array (#273) 2024-11-04 14:08:09 -05:00
Chenlei Hu
7c0240857c Revert branch to cb6e80a645 (#257) 2024-11-03 09:12:47 -05:00
dmx
79c53e0095 (prettier formatting) 2024-11-03 09:20:57 +04:00
filtered
94f1ca4279 Remove future test (#249) 2024-11-01 19:00:02 -04:00
filtered
edfa5e70f2 ES2022 Output & whitespace-only minification (#201)
* Change vite output to ES2022

* Add whitespace-only minify using default esbuild

Does not work for .es.js output - limitation of vite.
Workaround for .es.js involves adding terser & a plugin.

* Remove @ts-expect-error from tests

* Update vite.config.mts

---------

Co-authored-by: Chenlei Hu <huchenlei@proton.me>
2024-10-10 21:00:45 -04:00
filtered
5d510cd674 Revert "Format all code with prettier (#197)" (#198)
This reverts commit 28382b7e45.
2024-10-08 13:14:36 -04:00
Chenlei Hu
28382b7e45 Format all code with prettier (#197)
* Add formatter support

* Format all code

* Fix moved @ts-expect-error
2024-10-07 14:06:44 -04:00
filtered
6ee95f1201 TypeScript conversion groundwork (#163)
* ContextMenu ES6 class conversion

* Fix compat with extensions

* CurveEditor ES6 class conversion

* Split most of the LiteGraph global out to a class

* Move remainder of LiteGraph global to class file

* Remove IIFE wrapper

* Fix jest tests throwing due to type narrowing
2024-09-27 08:20:30 +09:00