Add origEvent Property to Expose Original DOM Events#232
Open
halletj wants to merge 3 commits intoyoannmoinet:masterfrom
Open
Add origEvent Property to Expose Original DOM Events#232halletj wants to merge 3 commits intoyoannmoinet:masterfrom
origEvent Property to Expose Original DOM Events#232halletj wants to merge 3 commits intoyoannmoinet:masterfrom
Conversation
…in multiple HTML files
…tickManager and Joystick interfaces
Owner
|
Thanks for the PR and the very detailed description. I'm currently in the process of rewriting the whole code base. nipplejs/packages/nipplejs/src/utils.ts Lines 172 to 173 in eb69f62 The rewrite fixes a lot of bugs and greatly improve performances as well as redefines the developer experience of the repo entirely. I've been working on it on and off the past year or so. I'm really not that far from the finish line tbh, here's the PR if you wanna tag along. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
origEventProperty to Expose Original DOM Events🎯 Overview
This PR adds access to the original DOM events (MouseEvent, TouchEvent, PointerEvent) that trigger joystick interactions. Developers can now access native event properties like
button,buttons,clientX,clientY,pressure,force, and other event-specific data.🚀 Motivation
Many developers need access to the original DOM events to:
Previously, this information was lost during event processing, limiting the library's flexibility for advanced use cases.
📋 Changes Made
Core Implementation (
src/collection.js)nipple.origEvent = evtin all event processing functions:processOnStart()- Stores original event when joystick interaction beginsprocessOnMove()- Updates original event during movement (multiple locations for different code paths)processOnEnd()- Stores original event when interaction endsorigEvent: nipple.origEventto move event data object to maintain consistency with existing data structureTypeScript Definitions (
types/index.d.ts)origEvent: EventtoJoystickOutputDatainterfaceorigEvent: EventtoJoystickinterfaceJoystickOutputData | Joystickto reflect actual implementation where:JoystickOutputDataobjectsJoystickinstancesExample Updates
codepen-demo.htmlpressure event handler to work with new data structure🔧 Usage Examples
Accessing Original Events
TypeScript Usage
🧪 Testing
📊 Impact
🔍 Implementation Details
The implementation stores the original DOM event in the
nippleinstance and ensures it's available in all event callbacks:nippleinstance → access vianipple.origEventdata.origEvent(copied fromnipple.origEvent)This approach maintains consistency with the existing event system while providing access to the original event data.
Files Changed:
src/collection.js- Core implementation (+10 lines)types/index.d.ts- TypeScript definitions (+6 lines)example/*.html- Context menu prevention for better testing (+20 lines total)Total: +36 lines added, minimal changes for maximum functionality gain.