Commit Graph

50 Commits

Author SHA1 Message Date
Chenlei Hu
75f067dbb3 Implement BooleanWidget (#466)
* Implement BooleanWidget

* Merge function of addWidget

* Class conversion

* nit
2025-02-07 17:10:30 -05:00
Chenlei Hu
c900df750e Simplify LGraphNode.onDrawBackground signature (#463) 2025-02-05 03:53:49 +11:00
Chenlei Hu
5acb656b15 [Refactor] Add LGraphCanvas.drawTitleText (#462) 2025-02-04 11:19:49 -05:00
Chenlei Hu
530fa874b0 [Refactor] Add LGraphNode.drawTitleBox (#461)
* [Refactor] Add LGraphNode.drawTitleBox

* nit
2025-02-04 10:57:50 -05:00
Chenlei Hu
7ea9a8405d [Reland][Refactor] Move node title background draw logic to LGraphNode (#459)
* [Refactor] Move node title background draw logic to LGraphNode (#452)

* Fix collapsed
2025-02-04 00:33:19 -05:00
Chenlei Hu
dc24c6617f Revert "[Refactor] Move node title background draw logic to LGraphNode (#452)" (#455)
This reverts commit 047bf68dc9.
2025-02-03 23:34:46 -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
047bf68dc9 [Refactor] Move node title background draw logic to LGraphNode (#452) 2025-02-03 23:20:51 -05:00
Chenlei Hu
6cf1f2d627 [Refactor] Move shape fallback from LGraphCanvas to LGraphNode (#451)
* [Refactor] Move shape fallback from LGraphCanvas to LGraphNode

* nit
2025-02-03 23:02:42 -05:00
Chenlei Hu
9d8e49b8f8 Remove LGraphNode.supported_extensions (#448) 2025-02-03 20:26:37 -05:00
Chenlei Hu
1da2c8a914 [Refactor] Move node color fallback from LGraphCanvas to LGraphNode (#444)
* [Refactor] Move node color fallback from LGraphCanvas to LGraphNode

* nit
2025-02-03 16:51:01 -05:00
Chenlei Hu
4844311f3b Add ts-strict-ignore plugin (#443)
* Add ts-strict-ignore plugin

* nit
2025-02-03 15:49:58 -05:00
Chenlei Hu
3e133b71e6 [Refactor] Add LGraphNode.title_mode (#439) 2025-02-03 13:57:14 -05:00
Chenlei Hu
00de6ae960 Fix LGraphNode.height (#438)
* Fix LGraphNode.height

* nit
2025-02-03 12:42:27 -05:00
Chenlei Hu
0048b5a0fe [i18n] Add INodeSlot.localized_name field (#376)
* [i18n] Add INodeSlot.localized_name field

* nit
2024-12-13 12:01:21 -08:00
pythongosssss
a0b50dcf15 Fix cloning pinned nodes (#364) 2024-12-01 20:31:12 -05:00
Chenlei Hu
e981fa01a0 Export types for frontend repo DTS (#353) 2024-11-27 22:13:59 -05:00
filtered
f79133659f Clean up JSDoc (#327)
* Convert comments to JSDoc

* Clean JSdoc

* nit

* Clean up all JSDoc & ESLint warnings

Disables max-len for now
Removes redundant JSDoc tags (empty, same name, wrong name, etc)
2024-11-21 10:11:53 -05:00
filtered
5469bfdd52 Add ESLint, pre-commit hook & format all files (#319)
* Add ESLint config

* Add ESLint packages

* Add prettier config

* Fix ESLint package version

* Format all files

* Format static assets

* Format project root config

* Add pre-commit code formatting

Formats .css & .js files automatically.  If any .ts or .mts files are staged, the entire project is type-checked.

Packages:
- lint-staged
- husky
- prettier
2024-11-20 21:50:58 -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
3d6adf0225 Add Reroutes (#301)
* Add Reroute

- Initial Reroute implementation
- LLink and Reroute both implement the new LinkSegment interface
- LinkSegments can have a parentId, which always points to a Reroute

* Narrow TS type of schema v0.4 extras

* Add reroutes to schema 0.4

Use extras.reroutes to store additional data

* Add Reroute POC to LLink

* Add Reroute rendering

* Add Reroute context menu - Delete Reroute

* Update delete selected - include reroutes & groups

* Add Reroute select & move

* Include reroutes in area-select

* Move disconnect link logic to LLink

* Add Reroute connect

* nit

* Add Reroute support - connecting links

* Add Add Reroute from link menu (menu)

* nit

* Add shift-drag from reroute to add new link

* Prevent Reroutes from disappearing

Add keepReroutes option to prevent Reroute GC

* Add fourth param to connectInputToOutput

* Allow both connecting in/out to be null

* Move ConnectingLink start pos to Reroute

* Add link render options

* Refactor renderLink - spline / bezier

* Refactor renderLink - linear, straight

* Fix centre points on all link types

Improves link render time

* [Refactor] Generic recursive interface / flat set

* nit

* Allow Reroutes to be members of groups

* Start links from the closest reroute

For the "shift-click drag link from link" feature

* Add Reroutes using alt-click on link paths

* nit - Refactor

* nit - Refactor

* Fix reroute deselect UX

Temporary workaround

* Add Reroute link centre-marker handling

* Add optional link arrow markers

Add enum for link markers
-> Pointing the way forward ->
Set default centre marker to arrow

* Add module export: LinkMarkerShape

* Add link arrow direction for all link types

* Add Reroute auto-swivel with custom curves

* Add state switch to disable reroutes

Works at root of all canvas interactions, should leave existing reroutes untouched but invisible until e.g. links are edited / changed.

* Fix cannot deselect when reroutes disabled

* Include reroutes in select-all
2024-11-12 11:18:48 -05:00
filtered
87c6d59546 Keep links connected when deleting nodes (#288)
* Allow node delete to keep more links connected

* Allow node delete to match every link

* Add config for connectInputToOutput
2024-11-08 11:13:14 -05:00
filtered
fc0b8087db Graph serialisation update - Links & Reroutes (#279)
* nit

* Add LGraph state POCO

Moves last_link_id, last_node_id and creates same for group and reroute

fix import

* Add new serialisation to LGraph

Add LGraph schema 1
Remove reroute from old serialised graph
Remove brittle inherited types
Ensure stale links are not kept when clearing graph

* Add serialisable exports

* Ensure valid LGraph.state during deserialise
2024-11-07 18:33:54 -05:00
filtered
1c40aad87c Fix pin not respected by multi-select move (#284) 2024-11-07 15:58:49 -05:00
filtered
e6961f1c5a Code cleanup, docs, TS types (#278)
* Fix test TS types

Prefer relative imports over @imports

* Add tuple names SerialisedLLinkArray

* nit

* [Refactor] LGraphCanvas.computeConnectionPoint

* [Refactor] Add LGraphCanvas.#dirty()

* Remove string LLink IDs

No downstream support for strings at present.

* nit - Rename

* nit

* nit

* nit - Remove unused code

* nit - Doc

* nit

* nit - Remove redundant code

* Remove unused: LGraphCanvas.isOverNodeBox

* Optimise - remove 2d context save/restore

* [Refactor] Move node collapsed check to class

* Add minor code change to support stricter types

* Revert accidental deletion in 0f2d04d

0f2d04d09e5e8a27a6d46d8c910dc077ed2d9071
2024-11-04 21:08:59 -05:00
Chenlei Hu
5edfc185c5 Unify pin/unpin interface between LGraphNode and LGraphGroup (#274) 2024-11-04 15:09:17 -05:00
Chenlei Hu
b663f86c9e Serialize to node pos/size to plain array (#273) 2024-11-04 14:08:09 -05:00
filtered
ba52402851 Replace canvas "action" magic strings (#271) 2024-11-03 18:30:19 -05:00
Chenlei Hu
6180f5ef55 Backspace delete selected (Nodes + Groups) (#265)
* Backspace delete selected (Nodes + Groups)

* nit

* nit
2024-11-03 17:22:08 -05:00
filtered
e661decddc Positionable: Common interface for canvas items (#256)
* Add Positionable interface to canvas elements

* Add group resizeTo children

Refactor out duplicated code from Node

* Remove redundant "is_selected" check

* Improve measure pass - interface, caching

Node bounds once per render
Cached results

* Use cached bounds for repeat canvas calls

- Removes margin param from getNodeOnPos
- Removes margin param from getGroupOnPos
- Hitboxes now uniform for render / mouse features
- Simplifies code

* nit - Refactor

* Fix top-left edge of hitbox missing

* Add ID to groups
2024-11-03 11:12:21 -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
1dfe824239 Shared measure functions (#254)
* Add findPointOnCurve function

* Add measure functions: contains centre/rect

* Improve measure interfaces (ReadOnlyPoint/Rect)

* nit - Doc

* Add TS strict types

* Add TS strict types

* Add TS strict types

* Add TS type
2024-11-02 10:35:36 -04:00
filtered
c0217dbb7e Remove _ctor pattern from Node & Group (#248)
Convert to initializers
2024-11-01 23:12:03 -04:00
filtered
020c912a8d Convert Links to ES6 Map & LLink Serialisation (#246)
* Fix intermittent links bug - graph.links Map()

Replaces graph.links with Map()
Adds a Proxy to provide for...in and indexer access
Temporarily uses merged Map+Record type, to ease downstream migration

* nit - Remove redundant code

* nit - Remove redundant null checks

* Add Serializable interface, used in LLink

Allows LLink to be serialised as an object rather than an array, bringing it inline with the rest of LiteGraph.
2024-10-31 21:53:00 -04:00
pythongosssss
eaaa0a4c39 Support for hidden & advanced widgets (#250) 2024-10-31 21:41:31 -04:00
filtered
d9d0837423 Code clean up (#244)
* Replace global var with enums

* Remove unused interface

* Add TS types

* Remove unused code

* nit - Clean up

* Add TS types

* nit - Refactor / clean up

* nit - Add TS types, clean up

* nit - Doc

* nit

* nit

* nit

* nit - Doc

* nit

* nit

* nit - let/const

* nit - Remove redundant code
2024-10-31 14:17:13 -04:00
filtered
002c955bf3 Minor bug fixes & refactors (#245)
* Fix TS errors - use correct property

* Fix graph version bumped without change

* Fix onDrawForeground callback has wrong area

* Move node pos getter/setter to class decl
2024-10-31 14:16:24 -04:00
filtered
95af20c1c4 Snaps for Comfy 🫰 (#239)
* Add Snaps for Comfy

* Add snap visual effects

* Update node measure to work everywhere

* Fix findConnectByTypeSlot does not work for "*"

* Fix regression in fast widget conversion
2024-10-30 12:02:41 -04:00
filtered
94223b2846 Fix minor debug log spam when dragging link (#238) 2024-10-29 22:08:47 -04:00
filtered
5070866299 Add / improve Node interfaces: Find slots & before connect callback (#226)
* Add connectByType wrappers

Can find slots without actually connecting.  Will be used for link snapping.

* Refactor - generic find free slot

* Fix link/links TS types - should not be undefined

* Fix / add TS types, docs

* Refactor - fix overloads TS types

* Refactor - optional chaining

* Extend node before-connect callback

The callback can now determine if connection is to a specific input, or just trying to connect any valid slot on the node.

* Add TS types - finish IOptionalInputsData
2024-10-28 18:59:43 -04:00
filtered
748d35b610 Add hover highlight and link dragging features (#222)
* Add new hover highlight and link dragging features

- Hovering effects added for node inputs and outputs
- Adds "mouseout" handler to properly clear node state when mousing off a node
- Fixes bug that causes outputs to always be dimmed out when connecting from inputs
- Slight performance improvement

* Add node highlight text colour option

* Add slot highlight colour fallback
2024-10-27 16:57:41 -04:00
filtered
70edfe2a33 Fix node shape not set by menu / setter (#214) 2024-10-25 21:07:26 -04:00
filtered
96866e8624 Typescript LGraphNode (#207)
* nit - Fix whitespace

* nit - Remove outdated comments

* nit - Remove redundant jsdoc tag

* Format only

* Add TS types

* nit - Auto let/const

* Convert special-case vars

* nit - Redeclared params / vars

* nit - const/let

* Refactor - minor logic change

* Add TS types - overloads w/workaround

* Refactor - prefer typeof over constructor check

* Add TS types

* Remove unused params

* nit - Refactor

* Refactor LGraphNode.findSlotByType

* nit - Refactor / format

* Refactor - optional chaining

* Fix TS type - node shape
2024-10-12 10:53:25 -04:00
filtered
d69a2ae9b0 Typescript LGraphCanvas (#202)
* Format only

* Revert accidental change

* Fix redundant falsy check - uninit. var

* nit - Refactor const/let

* nit - Refactor const/let (manual)

* nit - Redeclared params

* Add TS types & minor refactor only

* Refactor - Clean up / reformat

- Add strings.ts helper functions
- Remove unused vars & local function params
- Simplifies code
- Rename vars for clarity
- Add TODOs and other comments
- Add ts-expect-error

* Redirect draw.ts enums to global file (temp.)

Should be revisited after TS merge complete
Corrects import of types from draw.ts into interfaces

* Add measure.ts - move util funcs from Global

* Add all imports required for TS conversion

* Refactor - TS narrowing

* nit - TS types & minor refactor

* Add missing types from recent PRs

Removes duplicate declarations
Fixes some type mismatches

* nit - Refactor recent PRs

* Revert incorrect decls backported

* Remove unused params

* Add TS types only

* Fix minor TS type coercion issues

Also removes redundant code

* nit - Refactor

* Remove @ts-nocheck

* Fix refactor regression - drag link to output

Issue was the result of fixing var declared outside of closure

* Restore original logic

---------

Co-authored-by: huchenlei <huchenlei@proton.me>
2024-10-11 12:21:10 -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
Chenlei Hu
142c22ea41 Typescript conversion 0.7.84 (#194)
* Convert litegraph.js to TS

* Overhaul static litegraph.d.ts with updated types

* Fix rename oversights and revert fix unused param

- Some functions were broken by merging updated TS function signatures which included param renames
- Removal of unused params does not belong in the TS conversion PR, and has been reverted

* Remove legacy static .d.ts file

* Add callback decl from #180

Support allowing links to widgets (#180)
c23e610c11

* Convert NodeId to string | number

Results in significantly less downstream changes, despite being a change from the old static file.

---------

Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
2024-10-07 11:15:29 -04:00
filtered
1c835b04dc Split LGraphNode out to TS file 2024-09-27 09:56:19 +09:00