-
Notifications
You must be signed in to change notification settings - Fork 374
Increase vue slot/link functionality #5710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benceruleanlu
wants to merge
41
commits into
main
Choose a base branch
from
bl-more-slots
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,138
−270
Open
Changes from 36 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
9a18d37
Add dragging test
benceruleanlu 939cbe0
Litegraph? Never heard if it
benceruleanlu e3e1d2e
Add more test cases
benceruleanlu 5c6c21c
Update test expectations [skip ci]
invalid-email-address f624940
Merge branch 'bl-tests' into bl-more-slots
benceruleanlu 48f5087
More test cases v1
benceruleanlu 369da53
review comments
benceruleanlu 22a1c61
Merge remote-tracking branch 'origin/bl-tests' into bl-more-slots
benceruleanlu 70651dc
Allow moving links and support reroutes
benceruleanlu c227d60
Add dragging input to input drags existing link test
benceruleanlu 9d668a1
Merge remote-tracking branch 'origin/main' into bl-more-slots
benceruleanlu b99d70d
nit
benceruleanlu 19c538c
Support dragging from output to output
benceruleanlu 263b280
Add snapshot
benceruleanlu bef712e
o-o shift test
benceruleanlu e7f0ee4
Update test expectation
benceruleanlu 20d136d
Switch to adapter approach
benceruleanlu 3f4a806
clean up onPointerDown
benceruleanlu e136b89
Add reroute anchor tests
benceruleanlu 6685e00
Fix double links
benceruleanlu 0aa971b
Merge remote-tracking branch 'origin/main' into bl-more-slots
benceruleanlu 9d32b4c
temp screenshots
benceruleanlu e879bd5
improve typing
benceruleanlu f348902
nit
benceruleanlu d780296
cleanup unused
benceruleanlu 8eec7fb
huh?
benceruleanlu f99d8c1
I am the one who knocks
benceruleanlu 65ec322
Those who type
benceruleanlu a2be36a
fix bad fallback and remove logging
benceruleanlu 88cd60f
nit
benceruleanlu 381d97a
nit
benceruleanlu e9ffce4
nit
benceruleanlu 99aaa4e
Merge remote-tracking branch 'origin/main' into bl-more-slots
benceruleanlu 57810b9
nit
benceruleanlu 9b39835
refactor linkInteraction.spec.ts
benceruleanlu c050115
those who know
benceruleanlu 839d8a5
sure
benceruleanlu 0627a71
those who know cont
benceruleanlu 1ca3d75
nit
benceruleanlu ecc5bed
type
benceruleanlu 1c11dcc
Merge remote-tracking branch 'origin/main' into bl-more-slots
benceruleanlu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file modified
BIN
-105 Bytes
(100%)
...des/linkInteraction.spec.ts-snapshots/vue-node-dragging-link-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+50.8 KB
...nkInteraction.spec.ts-snapshots/vue-node-input-drag-ctrl-alt-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+51.4 KB
...eraction.spec.ts-snapshots/vue-node-input-drag-reuses-origin-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+52.8 KB
...inkInteraction.spec.ts-snapshots/vue-node-reroute-input-drag-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+55.3 KB
...raction.spec.ts-snapshots/vue-node-reroute-output-shift-drag-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+53.3 KB
...teraction.spec.ts-snapshots/vue-node-shift-output-multi-link-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import type { LGraph } from '@/lib/litegraph/src/LGraph' | ||
import type { NodeId } from '@/lib/litegraph/src/LGraphNode' | ||
import type { RerouteId } from '@/lib/litegraph/src/Reroute' | ||
import { LinkConnector } from '@/lib/litegraph/src/canvas/LinkConnector' | ||
import type { RenderLink } from '@/lib/litegraph/src/canvas/RenderLink' | ||
import type { ConnectingLink } from '@/lib/litegraph/src/interfaces' | ||
import { app } from '@/scripts/app' | ||
|
||
// Keep one adapter per graph so rendering and interaction share state. | ||
const adapterByGraph = new WeakMap<LGraph, LinkConnectorAdapter>() | ||
|
||
/** | ||
* Renderer‑agnostic adapter around LiteGraph's LinkConnector. | ||
* | ||
* - Uses layoutStore for hit‑testing (nodes/reroutes). | ||
* - Exposes minimal, imperative APIs to begin link drags and query drop validity. | ||
* - Preserves existing Vue composable behavior. | ||
*/ | ||
export class LinkConnectorAdapter { | ||
readonly linkConnector: LinkConnector | ||
|
||
constructor( | ||
/** Network the links belong to (typically `app.canvas.graph`). */ | ||
readonly network: LGraph | ||
) { | ||
// No-op legacy setter to avoid side effects when connectors update | ||
const setConnectingLinks: (value: ConnectingLink[]) => void = () => {} | ||
this.linkConnector = new LinkConnector(setConnectingLinks) | ||
} | ||
|
||
/** | ||
* The currently rendered/dragged links, typed for consumer use. | ||
* Prefer this over accessing `linkConnector.renderLinks` directly. | ||
*/ | ||
get renderLinks(): ReadonlyArray<RenderLink> { | ||
return this.linkConnector.renderLinks | ||
} | ||
|
||
// Drag helpers | ||
|
||
/** | ||
* Begin dragging from an output slot. | ||
* @param nodeId Output node id | ||
* @param outputIndex Output slot index | ||
* @param opts Optional: moveExisting (shift), fromRerouteId | ||
*/ | ||
beginFromOutput( | ||
nodeId: NodeId, | ||
outputIndex: number, | ||
opts?: { moveExisting?: boolean; fromRerouteId?: RerouteId } | ||
): void { | ||
const node = this.network.getNodeById(nodeId) | ||
const output = node?.outputs?.[outputIndex] | ||
if (!node || !output) return | ||
|
||
const fromReroute = this.network.getReroute(opts?.fromRerouteId) | ||
|
||
if (opts?.moveExisting) { | ||
this.linkConnector.moveOutputLink(this.network, output) | ||
} else { | ||
this.linkConnector.dragNewFromOutput( | ||
this.network, | ||
node, | ||
output, | ||
fromReroute | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Begin dragging from an input slot. | ||
* @param nodeId Input node id | ||
* @param inputIndex Input slot index | ||
* @param opts Optional: moveExisting (when a link/floating exists), fromRerouteId | ||
*/ | ||
beginFromInput( | ||
nodeId: NodeId, | ||
inputIndex: number, | ||
opts?: { moveExisting?: boolean; fromRerouteId?: RerouteId } | ||
): void { | ||
const node = this.network.getNodeById(nodeId) | ||
const input = node?.inputs?.[inputIndex] | ||
if (!node || !input) return | ||
|
||
const fromReroute = this.network.getReroute(opts?.fromRerouteId) | ||
|
||
if (opts?.moveExisting) { | ||
this.linkConnector.moveInputLink(this.network, input) | ||
} else { | ||
this.linkConnector.dragNewFromInput( | ||
this.network, | ||
node, | ||
input, | ||
fromReroute | ||
) | ||
} | ||
} | ||
|
||
// Validation helpers | ||
|
||
isNodeValidDrop(nodeId: NodeId): boolean { | ||
const node = this.network.getNodeById(nodeId) | ||
if (!node) return false | ||
return this.linkConnector.isNodeValidDrop(node) | ||
} | ||
|
||
isInputValidDrop(nodeId: NodeId, inputIndex: number): boolean { | ||
const node = this.network.getNodeById(nodeId) | ||
const input = node?.inputs?.[inputIndex] | ||
if (!node || !input) return false | ||
return this.linkConnector.isInputValidDrop(node, input) | ||
} | ||
|
||
isOutputValidDrop(nodeId: NodeId, outputIndex: number): boolean { | ||
const node = this.network.getNodeById(nodeId) | ||
const output = node?.outputs?.[outputIndex] | ||
if (!node || !output) return false | ||
return this.linkConnector.renderLinks.some((link) => | ||
link.canConnectToOutput(node, output) | ||
) | ||
} | ||
|
||
isRerouteValidDrop(rerouteId: RerouteId): boolean { | ||
const reroute = this.network.getReroute(rerouteId) | ||
if (!reroute) return false | ||
return this.linkConnector.isRerouteValidDrop(reroute) | ||
} | ||
|
||
// Drop/cancel helpers for future flows | ||
|
||
/** Disconnects moving links (drop on canvas/no target). */ | ||
disconnectMovingLinks(): void { | ||
this.linkConnector.disconnectLinks() | ||
} | ||
|
||
/** Resets connector state and clears any temporary flags. */ | ||
reset(): void { | ||
this.linkConnector.reset() | ||
} | ||
} | ||
|
||
/** Convenience creator using the current app canvas graph. */ | ||
export function createLinkConnectorAdapter(): LinkConnectorAdapter | null { | ||
const graph = app.canvas?.graph as LGraph | undefined | ||
if (!graph) return null | ||
let adapter = adapterByGraph.get(graph) | ||
if (!adapter) { | ||
adapter = new LinkConnectorAdapter(graph) | ||
adapterByGraph.set(graph, adapter) | ||
} | ||
return adapter | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question (non-blocking): Can you explain these changes briefly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was for testing/iteration, and was supposed to be removed in the 'those who know' commit, but wasn't cleaned up fully
it didn't have any callers, I just removed it now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was I supposed to know that?