Commit Graph

61 Commits

Author SHA1 Message Date
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
bcaeccfc45 Fix #346 last reroute is never deleted (#766)
Clears the reroutes in extras when exporting for serialisation, if none
exist.

- Resolves #346
2025-03-13 00:35:05 +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
filtered
8bee428375 [API] Remove unused LGraph.onNodeConnectionChange (#701)
Confirmed unused via code search.
2025-03-04 09:18:38 +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
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
78175e2c1b [TS] Add strict nullability to LGraphCanvas (#669)
- Updates typing in copy & paste
- Clean up
2025-03-02 08:34:26 +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
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
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
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
5cdd0581fa Add import / export sort rules (#612)
- Adds ESLint package
- Applies import/export rules to all files
- Uses newline delineated grouping, with type-only imports first
2025-02-26 09:21:33 +00:00
filtered
9ded97d189 [Doc] Add JSDoc linter & general comment clean up (#611)
- Prefer comments above lines over end-of-line comments
  - Makes auto-formatting easier
  - Subjective, but it is generally easier to read in JS
- Standardises JSdoc format
- Auto-fixes for many issues (applies on save w/ESLint extension)
2025-02-26 08:54:18 +00:00
filtered
4636367de2 [TS] Use strict mode in LGraphNode - initial (#598)
- Part of effort to convert LGraphNode to TS strict
- Adds some small runtime changes - no impact expected, but it is
possible
- Runtime changes are in separate commits from compile-time type changes
- Risk of downstream impact is low
2025-02-25 17:19:27 +00:00
filtered
0b84ca83d8 [TS] Use strict mode in LGraphGroup (#599)
- Adds `NullGraphError` to reduce boilerplate null check code
- Prefer optional `undefined` to explicit `null`
  - Related: https://github.com/Comfy-Org/litegraph.js/issues/595
- Adds strict types
2025-02-25 17:15:48 +00:00
filtered
c8ffacf172 [TS] Use strict mode in LGraph (#579)
* [TS] Undefined is not a valid object key

* Deprecate unused code

Adds ts-expect-error to TS strict issues on unmaintained public interfaces.

* [TS] Fix nullability: asSerialisable return type

* nit - Remove outdated comment

* [TS] Strict mode: LGraph

- Adds minor coercion changes; would need extremely specific hacks performed to result in runtime change

* [TMP] Work around typescript-strict-plugin

Must be reverted once plugin removed.
See #578
2025-02-24 11:12:46 +00:00
filtered
bcd5a77837 [TS] Strict initializers - LGraph (#573)
Duplicates values from clear() to property initializers.
2025-02-24 03:30:20 +00:00
filtered
1800d31a5a [Refactor] Prefer modern for..of loops 2 (#569)
* [Refactor] Prefer for..of

* [Refactor] Prefer for..of - manual refactoring

* Partially revert change - potential conflict

Not worth time investment to fix - reverted.
2025-02-23 16:36:52 -05:00
filtered
4163cb04b8 [Refactor] Prefer modern for..of loops (#566)
- Replaces traditional incrementing `for` loops and `forEach()` calls with modern `for..of` syntax
- Improves readability
- Semantic checking used; not expecting issues to arise from this portion
2025-02-23 19:59:41 +00:00
filtered
b67f34e7f3 [Cleanup] Remove lint bypass, remove unused vars (#554) 2025-02-20 11:17:35 +11:00
filtered
485bfd1628 [Cleanup] Remove unused code (#553) 2025-02-20 10:54:24 +11:00
Chenlei Hu
9b5f67aadf [Cleanup] Remove remaining legacy subgraph content (#458) 2025-02-03 23:45:17 -05:00
Chenlei Hu
3cd08e9e0c Remove LGraph._subgraph_node (Legacy subgraph) (#456) 2025-02-03 23:36:38 -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
filtered
6956973be1 Fix reroutes ignore change in radius (#379) 2024-12-15 10:55:46 -08:00
filtered
1c1241bdb1 Optimise positionableItems / empty getters (#373)
* Optimise LGraph.empty() getter

* Optimise positionableItems getters

- No change to internal functionality
- Replaces forced spread of all items on every property access with generator function
- Consumers that require an array can very cleanly spread into one
2024-12-07 00:00:29 -05:00
Chenlei Hu
a9940da05f Add LGraph.empty (#371) 2024-12-06 17:49:50 -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
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
Chenlei Hu
f26f7dbe2c Revert "Add canvas update events (#297)" (#310)
This reverts commit 0e8f02f32f.
2024-11-16 17:32:53 -05:00
ArtificialLab
0e8f02f32f Add canvas update events (#297)
* (add) onNodeUpdated, onPositionChanged and onZoomChanged

* (fix) onPositionChanged

* (add) onNodeWidgetChanged callback
2024-11-16 07:01:59 +04:00
filtered
cc084811d9 Copy & Paste all items (#302)
* Add copy & paste of groups & reroutes

Complete rewrite of copy & paste
Fixes a bug where failure to clone a node would corrupt all subsequent nodes
No longer mutates nodes when copying

* Fix name collision

* Fix cannot copy specified nodes to clipboard

* Allow mapping of original IDs to pasted clones
2024-11-13 10:21:23 -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
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
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
filtered
ba52402851 Replace canvas "action" magic strings (#271) 2024-11-03 18:30:19 -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
78426148ac fix TS error 'Timeout' is not assignable to type 'number' 2024-11-03 10:00:38 +04:00
dmx
c8bac1aa40 add onNodeUpdated event in LGraph 2024-11-03 09:44:48 +04: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
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
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
b74662fbad Fix group order unexpectedly reversing (#242) 2024-10-30 19:48:48 -04:00