-
Notifications
You must be signed in to change notification settings - Fork 448
Support on slot click listeners in vue #7059
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
Changes from 2 commits
c5629f6
ba2a334
cdb22e1
b0ef7bc
a5a847d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { tryOnScopeDispose, useEventListener } from '@vueuse/core' | |
| import type { Fn } from '@vueuse/core' | ||
|
|
||
| import { useSharedCanvasPositionConversion } from '@/composables/element/useCanvasPositionConversion' | ||
| import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' | ||
| import type { LGraph } from '@/lib/litegraph/src/LGraph' | ||
| import type { LGraphNode, NodeId } from '@/lib/litegraph/src/LGraphNode' | ||
| import { LLink } from '@/lib/litegraph/src/LLink' | ||
|
|
@@ -29,6 +30,7 @@ import { layoutStore } from '@/renderer/core/layout/store/layoutStore' | |
| import type { Point } from '@/renderer/core/layout/types' | ||
| import { toPoint } from '@/renderer/core/layout/utils/geometry' | ||
| import { createSlotLinkDragContext } from '@/renderer/extensions/vueNodes/composables/slotLinkDragContext' | ||
| import { translateEvent } from '@/renderer/extensions/vueNodes/utils/eventUtils' | ||
| import { app } from '@/scripts/app' | ||
| import { createRafBatch } from '@/utils/rafBatch' | ||
|
|
||
|
|
@@ -39,6 +41,8 @@ interface SlotInteractionOptions { | |
| } | ||
|
|
||
| interface SlotInteractionHandlers { | ||
| onClick: (event: PointerEvent) => void | ||
| onDoubleClick: (event: PointerEvent) => void | ||
| onPointerDown: (event: PointerEvent) => void | ||
| } | ||
|
|
||
|
|
@@ -500,7 +504,7 @@ export function useSlotLinkInteraction({ | |
|
|
||
| const hasConnected = connectByPriority(canvasEvent.target, snappedCandidate) | ||
|
|
||
| if (!hasConnected) { | ||
| if (!hasConnected && event.target === app.canvas?.canvas) { | ||
| activeAdapter?.dropOnCanvas(canvasEvent) | ||
| } | ||
|
|
||
|
|
@@ -716,7 +720,28 @@ export function useSlotLinkInteraction({ | |
| } | ||
| }) | ||
|
|
||
| function onDoubleClick(e: PointerEvent) { | ||
| const canvas = useCanvasStore().getCanvas() | ||
| const { graph } = canvas | ||
| if (!graph) return | ||
| const node = graph.getNodeById(nodeId) | ||
| if (!node) return | ||
| translateEvent(app.canvas, node, e) | ||
| node.onInputDblClick?.(index, e) | ||
| } | ||
| function onClick(e: PointerEvent) { | ||
| const canvas = useCanvasStore().getCanvas() | ||
| const { graph } = canvas | ||
| if (!graph) return | ||
| const node = graph.getNodeById(nodeId) | ||
| if (!node) return | ||
| translateEvent(app.canvas, node, e) | ||
| node.onInputClick?.(index, e) | ||
| } | ||
|
Comment on lines
722
to
737
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For later (probably) Question: Is there a reason we get the canvas from the canvasStore in one place but use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, the rabbit noticed too 🐇
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. From testing, Wasn't able to find a satifactory answer for "why" though. The app reference here had
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if you replace
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A tragic I'm no longer able to reproduce the earlier issues with |
||
|
|
||
| return { | ||
| onClick, | ||
| onDoubleClick, | ||
| onPointerDown | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' | ||
| import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' | ||
| import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events' | ||
|
|
||
| export function translateEvent( | ||
| canvas: LGraphCanvas, | ||
| node: LGraphNode, | ||
| e: PointerEvent | ||
| ): asserts e is CanvasPointerEvent { | ||
|
||
| canvas.adjustMouseEvent(e) | ||
| canvas.graph_mouse[0] = e.offsetX + node.pos[0] | ||
| canvas.graph_mouse[1] = e.offsetY + node.pos[1] | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.