-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feat: Key Events - Key Modifiers #13
Conversation
Warning Rate Limit Exceeded@jorenrui has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 26 minutes and 42 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. WalkthroughThis update enhances the event handling system, focusing on keyboard interactions. It introduces new key constants like Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 4
Configuration used: CodeRabbit UI
Files selected for processing (1)
- lib/entity/events.js (5 hunks)
Additional comments: 4
lib/entity/events.js (4)
- 17-17: The
SPECIAL_KEYS
constant is correctly defined and relevant for handling special key modifiers. Ensure that all special keys your application needs to support are included in this list.- 60-60: The addition of the
keysPressed
object property is appropriate for tracking multiple simultaneous key presses. Verify that this property is consistently updated and cleared to prevent memory leaks or incorrect state tracking.- 199-199: The
setKeyEvent
method correctly splits the attribute to separate the event from keycodes. Ensure that the method properly handles cases where no keycodes are specified.- 243-243: Storing the key press state in
ctx.keysPressed
is a good approach. Ensure that keys are correctly removed onkeyup
to avoid incorrect state.
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.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (1)
- lib/entity/events.js (5 hunks)
Additional comments: 3
lib/entity/events.js (3)
- 68-72: The
isKeyEvent
method is a good refactor, improving clarity and reusability of the key event check logic.- 77-77: Adding
keysPressed
as an object property is appropriate for tracking pressed keys, aligning with the PR objectives.- 116-120: The logic to determine if an attribute represents a key event has been correctly refactored based on previous feedback.
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.
Review Status
Actionable comments generated: 3
Configuration used: CodeRabbit UI
Files selected for processing (1)
- lib/entity/events.js (4 hunks)
Additional comments: 1
lib/entity/events.js (1)
- 68-72: The addition of the
isKeyEvent
method is a good practice for encapsulating the logic to determine if an attribute represents a key event. This enhances code readability and reusability, aligning with the previous suggestion to refactor this logic into a separate method. Well done on implementing this improvement.
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.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (4)
- lib/entity/attributes.js (3 hunks)
- lib/entity/events.js (7 hunks)
- lib/helpers/strings.js (1 hunks)
- readme.md (2 hunks)
Additional comments: 10
lib/helpers/strings.js (2)
- 1-5: The
kebabToCamelCase
function correctly converts kebab-case strings to camelCase. It uses a regular expression to find hyphenated characters and converts them to uppercase. This is a common and efficient approach for this task.- 7-12: The
camelToKebabCase
function correctly converts camelCase strings to kebab-case. The regular expression used here is well-crafted to handle edge cases, such as consecutive uppercase letters that should not be preceded by a hyphen. The use of a function in thereplace
method to conditionally add a hyphen based on the offset is a clever solution to avoid leading hyphens.lib/entity/attributes.js (3)
- 3-3: The import statement for
kebabToCamelCase
correctly brings in the necessary function from../helpers/strings
. This ensures that theAttributes
class can utilize the function for attribute name transformation.- 25-25: The use of
kebabToCamelCase
inisValidAttribute
for transforming attribute names from kebab-case to camelCase is appropriate. This change aligns with the PR's objective to standardize attribute name handling and improves consistency across the library.- 159-159: The application of
kebabToCamelCase
inevaluateOtherAttributes
for converting dynamic attribute names to camelCase before accessing them on the element is correct. This ensures that custom attributes defined in kebab-case are properly handled and mapped to their corresponding properties on DOM elements.lib/entity/events.js (4)
- 19-20: The addition of
SPECIAL_KEYS
andDIRECTION_KEYS
constant arrays is a good practice for managing lists of special and directional keys. This makes the code more readable and maintainable by centralizing the key definitions.- 22-48: The
mapKey
function provides a comprehensive mapping from various keycode formats to a standardized format. This function is well-designed, covering a wide range of keycodes including special keys and direction keys. The use ofcamelToKebabCase
for general keycode conversion ensures consistency with the rest of the library's naming conventions.- 87-91: Extracting the logic to determine if an attribute represents a key event into a separate method
isKeyEvent
improves clarity and reusability. This change aligns with best practices for code organization and modularity.- 238-368: The
setKeyEvents
method has been significantly refactored to handle key events more efficiently. The method now correctly separates special keys from normal keys and sets up event listeners forkeydown
,keyup
, andkeypress
events based on the attributes specified. This approach enhances the library's ability to handle complex keyboard interactions. Ensure that the logic for determining if keys are pressed (areKeysPressed
function) and the event handling logic (handleKeyPress
function) are thoroughly tested to prevent issues with key event detection.readme.md (1)
- 148-152: The introduction of special variables
event
andthis
in events is a significant enhancement. It's important to ensure that these variables are consistently documented and their usage is clear to the users of the library. This change enhances the flexibility and power of event handling in MiniJS.
🚀 PR was released in |
Description
Keyboard Events
For keyboard events, you can listen to them using
:keyup
,:keydown
, and:keypress
:Key Modifiers
You can also use key modifiers to listen to specific keys. Modifiers are appended to the event name using a dot:
You can chain multiple key modifiers together:
For key values that have multiple words like
BracketLeft
, except for arrow keys, kebab case is used:The following are the available key modifiers:
Summary by CodeRabbit
SPECIAL_KEYS
andDIRECTION_KEYS
constant arrays for enhanced keyboard event handling.keysPressed
object property andmapKey
function for keycode mapping.:keyup
,:keydown
, and:keypress
with key modifiers.camelToKebabCase
function for string format conversion.📦 Published PR as canary version:
1.0.1-canary.13.d0074c8.0
✨ Test out this PR locally via:
npm install tonic-minijs@1.0.1-canary.13.d0074c8.0 # or yarn add tonic-minijs@1.0.1-canary.13.d0074c8.0