Commit Graph

691 Commits

Author SHA1 Message Date
Chenlei Hu
a9940da05f Add LGraph.empty (#371) 2024-12-06 17:49:50 -05:00
filtered
1238f83728 Prevent distortion of area select rectangle (#368) 2024-12-05 11:33:51 -05:00
Chenlei Hu
c69bbdfb10 Export LGraphEventMode (#369) 2024-12-05 11:32:08 -05:00
filtered
8cda1ac48a Add CanvasPointer callback for node widgets (#363)
* Add CanvasPointer callback for node widgets

* Add API documentation

* nit - Docs
2024-12-01 20:31:48 -05:00
pythongosssss
a0b50dcf15 Fix cloning pinned nodes (#364) 2024-12-01 20:31:12 -05: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
2a39b21578 Fix Zoom Centre (#135) 2024-11-28 11:54:09 -05:00
filtered
24db9e2572 Add maximum FPS feature (#356) 2024-11-28 09:45:59 -05:00
Chenlei Hu
83ba7a8df7 Export ISerialisedGraph for frontend repo DTS (#354) 2024-11-27 23:50:16 -05:00
Chenlei Hu
e981fa01a0 Export types for frontend repo DTS (#353) 2024-11-27 22:13:59 -05:00
filtered
304e229dc2 Fix custom widget pointerup receives NaN pos (#351) 2024-11-27 12:40:39 -05:00
filtered
f6e885f015 Ensure click_time is available to custom widgets (#349) 2024-11-26 13:05:47 -05:00
filtered
ffa2a24cb1 Fix slider regression caused by CanvasPointer (#347) 2024-11-26 13:05:24 -05:00
filtered
e35748faa4 Fix widget.mouse callback does not receive pointerup events (#342)
* Provide pointerup events to widget.mouse callback

* Fix regression in widget mouse cb

pointerup events are now sent to mouse() callback regardless of CanvasPointer state.
2024-11-25 11:05:50 -05:00
filtered
a95d8ebc87 Fix invalid callback return value preventing canvas redraw (#343)
* Fix invalid callback prevents redraw

When widget.mouse() is incorrectly implemented (no return value), it evaluates as falsy and prevents canvas redraw.

Changes default behaviour to ignore the return value when nullish.

* Fix pointermove for custom widget outside nodes

Events are now also sent when the pointer moves outside the bounds of the node.
2024-11-25 10:43:28 -05:00
filtered
696b8b2c63 Fix custom widget mouseover (#339) 2024-11-23 17:44:13 -05:00
filtered
2d69a87419 Use device scaling for drag-from-link checks (#334) 2024-11-22 10:57:37 -05:00
filtered
a6c3f5c1c7 Fix widget changed callback not called (#333) 2024-11-22 10:48:35 -05:00
filtered
ae6422bad1 Fix custom widgets not receiving pointermove events (#335) 2024-11-22 10:45:39 -05:00
filtered
75960485d3 Snapsize (#331)
* Improve group resize UX

Removes the teleport of the group corner to the pointer, on the first move event.

* Select groups when clicking titles

* Add snap to grid for groups

* Apply new group resize UX to nodes
2024-11-21 14:11:38 -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
b4b68c7e75 Fix fast widget conversion (#323) 2024-11-20 09:28:33 -05:00
filtered
ecb7fa4f0b Fix widget not updating on combo click (#321) 2024-11-19 18:26:36 -05:00
filtered
31c25b4ea1 Fixes pinned group contents moving (#316) 2024-11-18 13:17:24 -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
Chenlei Hu
8345b980f6 Add DragAndScaleState for external proxy (#311) 2024-11-16 18:34:49 -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
Chenlei Hu
75678ee43c Fix NODE_TEXT_SIZE style option (#298) 2024-11-10 09:54:07 -05:00
filtered
ca8e31c695 Emit only one change when deleting nodes (#296) 2024-11-10 09:40:36 -05:00
Chenlei Hu
34f8d3408b Add LGraphCavnas.fitViewToSelectionAnimated (#292) 2024-11-08 14:22:18 -05:00
Chenlei Hu
c7d5c863ec Move createBounds to measure.ts (#290)
* nit

* Move createBounds to measure

* Export createBounds
2024-11-08 13:49:30 -05:00
Zoltán Dócs
6ad864bc20 Animate view to multiple nodes (#282)
* animateToNodes
- modify existing animation method to support passing multiple nodes, in which case the view is fit to the bounding box around them

* animateToBounds

* amend

* format

* amend
2024-11-08 13:40:15 -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
e1aac5cf61 Improve hitbox for group resize (#277)
Now the same as the visual area

Co-authored-by: Chenlei Hu <huchenlei@proton.me>
2024-11-06 19:35:56 -05:00
filtered
2ba048de52 Remove hard-coded modifications to nodes (#247)
* Remove arbitrary 5 graph unit margin around nodes

* Remove arbitrary +1 pixel added to node width

---------

Co-authored-by: Chenlei Hu <huchenlei@proton.me>
2024-11-05 18:35:59 -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
filtered
ce8d39f650 Group update - titlebar, resize, config (#270)
* Backport group header from frontend

* nit - TS types & redundant code

* Refactor - simplify group resize

* Fix group resize can be inverted

* Move group resize check to group class

* Add config for group padding & default colour

* nit - Remove redundant code
2024-11-03 18:27:41 -05:00
filtered
3be1937c41 Update delete selected (#269)
* Standardise naming - deleteSelected

Renamed from deleteSelectedItems

* nit - Refactor to match future state
2024-11-03 18:10:46 -05:00