Skip to content

Releases: silvaezequias/nextkeyboard

v1.1.1

19 Dec 13:25
Compare
Choose a tag to compare

Release v1.1.1

Overview

This release focuses on resolving build issues in Next.js and enhancing the robustness of environment handling within the library. With a centralized environment detection function, the library now ensures seamless compatibility between server-side rendering (SSR) and client-side environments, requiring no manual adjustments from developers.


What's New

1. Centralized Environment Detection

  • Introduced a unified getWindow function to safely handle environment detection:
    • getWindow(): Window | undefined:
      • Returns the window object when in a browser environment.
      • Returns undefined when running in a server environment.
    • Example implementation:
      export function getWindow(): Window | undefined {
        if (typeof window === "undefined") {
          return undefined;
        }
        return window;
      }
    • Benefit: This centralization simplifies code and eliminates the need for developers to manage environment-specific checks.

2. Seamless Compatibility

  • The library now automatically adapts to the runtime environment, whether it’s server-side (Next.js SSR) or client-side (browser).
  • No additional setup or configuration is required by developers.

3. Improved Error Handling

  • Enhanced error messages when browser-specific features are used incorrectly, making it easier for developers to diagnose potential issues.

4. Comprehensive Testing

  • Expanded the test suite to cover:
    • Behavior of the getWindow function in SSR and client environments.
    • Integration with key features like Hotkeys and GlobalKeyboardListener in both development and production scenarios.

Bug Fixes

  • Fixed a critical issue where the library caused build failures in Next.js due to accessing the window object during SSR.

v1.1.0

15 Dec 16:29
Compare
Choose a tag to compare

Release v1.1.0

Overview

This release introduces several new features, enhancements, and refactors while maintaining backward compatibility. It focuses on improving the flexibility and robustness of the library, as well as adding thorough test coverage.


What's New

1. Unique Key IDs

  • Every Key instance now has a unique id based on its key and code properties.
  • Ensures consistent comparison of keys across the library.

2. New Methods in Key Class

  • equals(other: Key): boolean:
    • Compares two Key instances based on their id.
  • Key.isEquals(key1: Key, key2: Key): boolean:
    • A static method for comparing two keys without requiring an instance.
  • toString(): string:
    • Returns a readable representation of the key, e.g., Key(A, KeyA).

3. Improved Long Press Handling

  • Encapsulated with after:
    • Allows additional actions after a long press via an encodable after callback.
  • Available in:
    • GlobalKeyboardListener
    • Hotkeys
    • SomeOfKeys

4. Refactored Comparison Logic

  • All classes now use id for consistent comparisons:
    • GlobalKeyboardListener
    • Hotkeys
    • SomeOfKeys

5. Test Suite Expansion

  • Comprehensive unit tests added for:
    • Key (IDs, equality, onPress, onRelease, and onLongPress behaviors)
    • Hotkeys (key combinations, onPress, and long press handling)
    • SomeOfKeys (groups of keys and individual key detection)
    • GlobalKeyboardListener (global event tracking, sequence validation, long press)
    • Predefined keys (e.g., A, LeftControl)
    • Custom keys (e.g., user-defined keys like KeyZ)
  • Introduced simulateKeyEvent utility for dispatching keyboard events in tests.

6. Utility Enhancements

  • Added simulateKeyEvent function to simplify testing by dispatching keydown and keyup events programmatically.

Breaking Changes

None. All changes are backward compatible.


Bug Fixes

  • Fixed issues where Set and Map comparisons would fail for Key instances due to reference mismatches.

Contributors

Thanks to everyone who contributed to this release!

v1.0.1

14 Dec 01:13
Compare
Choose a tag to compare

Full Changelog: v1.0.0...v1.0.1

v1.0.0

09 Dec 16:21
Compare
Choose a tag to compare

NextKeyboard v1.0.0 Release

The first stable release of NextKeyboard introduces a robust and intuitive solution for managing keyboard events in React and TypeScript projects. This version includes essential features to simplify event handling and empower developers to build rich keyboard interactions.


What's New in v1.0.0

  • Predefined Keys: Access over 100 common keys, including letters, numbers, modifiers, navigation, and function keys.
  • Hotkeys Support: Easily define and manage key combinations like Command + A or Ctrl + Shift + B.
  • SomeOfKeys Utility: Monitor any key from a group, such as LeftCommand or RightCommand.
  • Global Listeners: Handle keydown and keyup events globally with callbacks.
  • State Monitoring: Check the active state of keys like CapsLock or NumLock.
  • Reset Listeners: Dynamically reset key listeners when needed.
  • Full TypeScript Support: Ensures strong typing and smooth integration into modern React projects.

Get Started

Install the library:

npm install nextkeyboard

Define your first hotkey:

import { Hotkeys, Keyboard } from "nextkeyboard";

const { A, LeftCommand } = Keyboard;

const shortcut = new Hotkeys([LeftCommand, A]);

shortcut.onPress(() => {
  console.log("Command + A was pressed!");
});

Future Plans

We aim to expand support for more keyboard layouts, advanced customization, and additional utilities for complex interactions. Feedback and contributions are welcome!


Happy coding with NextKeyboard! 🚀

Full Changelog: https://github.com/silvaezequias/nextkeyboard/commits/v1.0.0