feat(useMouse): support custom event extractor #2991
Merged
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.
Add
target
option andtype
enhancementBefore submitting the PR, please make sure you do the following
fixes #123
).Description
target
option to listen for events only on the target element and not onwindow
. It's helpful for performance improvement to do not triggers refs update then you not need it. Also it's allows to use some event properties which relative to target element (e.g.event.offsetX
)type
option to be used as a function that retrieves thex
andy
values from the event object. If the function returnsnull | undefined
refs will not be updated.Additional context
🤖 Generated by Copilot at 0d9e2ac
Enhanced
useMouse
function to support custom elements and coordinate extractors. Updated demo, types, and documentation accordingly.🤖 Generated by Copilot at 0d9e2ac
target
andtype
options touseMouse
function (link, link, link)target
option allows specifying a custom element to listen to mouse events, using a direct value or a function that returns a value (link, link, link)type
option allows providing a custom function to extract the mouse coordinates from the event, or choosing from predefined coordinate systems (link, link, link, link, link)useMouse
function (link, link)extractor
variable to store the function that gets the mouse coordinates from the event, either from thetype
option or from theEXTRACTORS
object (link, link)x
,y
, andsourceType
refs with the mouse coordinates and the event source (link, link)eventFilter
option if provided, or directly call the handler functions otherwise (link)target
parameter instead of thewindow
object for theuseEventListener
hooks (link)target
andtype
options (link)