-
Notifications
You must be signed in to change notification settings - Fork 447
fix: Vue Nodes 2.0 slot link drag not working on mobile/touch devices #7233
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
95c4224
fix: use elementFromPoint for touch event target resolution in Vue nodes
Myestery f46fbf9
refactor: extract resolvePointerTarget helper for touch event handling
Myestery 91011e5
test: use vi.spyOn for document.elementFromPoint mocking
Myestery b554fdb
Merge branch 'main' into fix/mobile-touch-slot-link-drag
Myestery a23ff49
Merge branch 'main' into fix/mobile-touch-slot-link-drag
Myestery 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
121 changes: 121 additions & 0 deletions
121
src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.test.ts
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,121 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { resolvePointerTarget } from '@/renderer/extensions/vueNodes/composables/useSlotLinkInteraction' | ||
|
|
||
| describe('resolvePointerTarget', () => { | ||
| let originalElementFromPoint: typeof document.elementFromPoint | ||
|
|
||
| beforeEach(() => { | ||
| originalElementFromPoint = document.elementFromPoint | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| document.elementFromPoint = originalElementFromPoint | ||
| vi.restoreAllMocks() | ||
| }) | ||
|
|
||
| it('returns element from elementFromPoint when available', () => { | ||
| const targetElement = document.createElement('div') | ||
| targetElement.className = 'lg-slot' | ||
|
|
||
| document.elementFromPoint = vi.fn().mockReturnValue(targetElement) | ||
|
|
||
| const fallback = document.createElement('span') | ||
| const result = resolvePointerTarget(100, 200, fallback) | ||
|
|
||
| expect(document.elementFromPoint).toHaveBeenCalledWith(100, 200) | ||
| expect(result).toBe(targetElement) | ||
| }) | ||
|
|
||
| it('returns fallback when elementFromPoint returns null', () => { | ||
| document.elementFromPoint = vi.fn().mockReturnValue(null) | ||
|
|
||
| const fallback = document.createElement('span') | ||
| fallback.className = 'fallback-element' | ||
|
|
||
| const result = resolvePointerTarget(100, 200, fallback) | ||
|
|
||
| expect(document.elementFromPoint).toHaveBeenCalledWith(100, 200) | ||
| expect(result).toBe(fallback) | ||
| }) | ||
|
|
||
| it('returns null fallback when both elementFromPoint and fallback are null', () => { | ||
| document.elementFromPoint = vi.fn().mockReturnValue(null) | ||
|
|
||
| const result = resolvePointerTarget(100, 200, null) | ||
|
|
||
| expect(result).toBeNull() | ||
| }) | ||
|
|
||
| describe('touch/mobile pointer capture simulation', () => { | ||
| it('resolves correct target when touch moves over different element', () => { | ||
| // Simulate the touch scenario: | ||
| // - User touches slot A (event.target = slotA) | ||
| // - User drags over slot B (elementFromPoint returns slotB) | ||
| // - resolvePointerTarget should return slotB, not slotA | ||
|
|
||
| const slotA = document.createElement('div') | ||
| slotA.className = 'lg-slot slot-a' | ||
| slotA.setAttribute('data-slot-key', 'node1-0-input') | ||
|
|
||
| const slotB = document.createElement('div') | ||
| slotB.className = 'lg-slot slot-b' | ||
| slotB.setAttribute('data-slot-key', 'node2-0-input') | ||
|
|
||
| // When pointer is over slotB, elementFromPoint returns slotB | ||
| document.elementFromPoint = vi.fn().mockReturnValue(slotB) | ||
|
|
||
| // But the fallback (event.target on touch) is still slotA | ||
| const result = resolvePointerTarget(150, 250, slotA) | ||
|
|
||
| // Should return slotB (the actual element under pointer), not slotA | ||
| expect(result).toBe(slotB) | ||
| expect(result).not.toBe(slotA) | ||
| }) | ||
|
|
||
| it('falls back to original target when pointer is outside viewport', () => { | ||
| // When pointer is outside the document (e.g., dragged off screen), | ||
| // elementFromPoint returns null | ||
|
|
||
| const slotA = document.createElement('div') | ||
| slotA.className = 'lg-slot slot-a' | ||
|
|
||
| document.elementFromPoint = vi.fn().mockReturnValue(null) | ||
|
|
||
| const result = resolvePointerTarget(-100, -100, slotA) | ||
|
|
||
| // Should fall back to the original target | ||
| expect(result).toBe(slotA) | ||
| }) | ||
| }) | ||
|
|
||
| describe('integration with slot detection', () => { | ||
| it('returned element can be used with closest() for slot detection', () => { | ||
| // Create a nested structure like the real DOM | ||
| const nodeContainer = document.createElement('div') | ||
| nodeContainer.setAttribute('data-node-id', 'node123') | ||
|
|
||
| const slotWrapper = document.createElement('div') | ||
| slotWrapper.className = 'lg-slot' | ||
|
|
||
| const slotDot = document.createElement('div') | ||
| slotDot.className = 'slot-dot' | ||
| slotDot.setAttribute('data-slot-key', 'node123-0-input') | ||
|
|
||
| slotWrapper.appendChild(slotDot) | ||
| nodeContainer.appendChild(slotWrapper) | ||
|
|
||
| // elementFromPoint returns the innermost element (slot dot) | ||
| document.elementFromPoint = vi.fn().mockReturnValue(slotDot) | ||
|
|
||
| const result = resolvePointerTarget(100, 100, null) | ||
|
|
||
| // Verify we can use closest() to find parent slot and node | ||
| expect(result).toBeInstanceOf(HTMLElement) | ||
| const htmlResult = result as HTMLElement | ||
| expect(htmlResult.closest('.lg-slot')).toBe(slotWrapper) | ||
| expect(htmlResult.closest('[data-node-id]')).toBe(nodeContainer) | ||
| expect(htmlResult.getAttribute('data-slot-key')).toBe('node123-0-input') | ||
| }) | ||
| }) | ||
| }) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.