New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@atomico/use-keyboard

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atomico/use-keyboard - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

test/element.tsx

7

dist/index.js
import { useCurrentValue } from "@atomico/use-current-value";
import { useRefValues } from "@atomico/use-ref-values";
import { addListener } from "@atomico/use-listener";
import { useRefEffect } from "atomico";
export function useKeyboard(ref, keys, callback) {
const value = useCurrentValue(callback);
useRefValues(([current]) => {
useRefEffect(() => {
const { current } = ref;
if (!current)
return;
const history = new Set();

@@ -8,0 +11,0 @@ const check = () => {

{
"name": "@atomico/use-keyboard",
"description": "Series of utilities in hooks format to extend the operation of Atomico",
"version": "1.0.1",
"version": "1.1.0",
"type": "module",

@@ -30,7 +30,6 @@ "license": "MIT",

"@atomico/use-current-value": "*",
"@atomico/use-listener": "*",
"@atomico/use-ref-values": "*"
"@atomico/use-listener": "*"
},
"peerDependencies": {
"atomico": "^1.75.1"
"atomico": "^1.76.4"
},

@@ -37,0 +36,0 @@ "types": "dist/index.d.ts",

@@ -1,46 +0,40 @@

import { it, expect } from "vitest";
import { createHooks } from "atomico/test-hooks";
import { useKeyboard } from "../src/";
import { asyncEventListener } from "atomico/test-dom";
import { it } from "vitest";
import { Element } from "./element";
it("useKeyboard", () => {
const ref = { current: document };
const hooks = createHooks();
const capture = [];
hooks.load(() => {
useKeyboard(ref, ["KeyA", "KeyQ"], (event) => {
capture.push(event);
});
});
it("useKeyboard", async () => {
const element = new Element();
hooks.cleanEffects()()();
document.body.append(element);
ref.current.dispatchEvent(
new KeyboardEvent("keydown", { code: "KeyQ", key: "1" }),
);
await element.updated;
ref.current.dispatchEvent(
new KeyboardEvent("keydown", { code: "KeyA", key: "1" }),
);
const input = element.querySelector("input");
ref.current.dispatchEvent(
new KeyboardEvent("keyup", { code: "KeyQ", key: "1" }),
);
setTimeout(() => {
input.dispatchEvent(
new KeyboardEvent("keydown", { code: "KeyQ", key: "1" }),
);
ref.current.dispatchEvent(
new KeyboardEvent("keyup", { code: "KeyA", key: "1" }),
);
input.dispatchEvent(
new KeyboardEvent("keydown", { code: "KeyA", key: "1" }),
);
ref.current.dispatchEvent(
new KeyboardEvent("keydown", { code: "KeyA", key: "2" }),
);
ref.current.dispatchEvent(
new KeyboardEvent("keydown", { code: "KeyQ", key: "2" }),
);
input.dispatchEvent(
new KeyboardEvent("keyup", { code: "KeyQ", key: "1" }),
);
expect(capture.length).to.equal(1);
input.dispatchEvent(
new KeyboardEvent("keyup", { code: "KeyA", key: "1" }),
);
const [event] = capture;
input.dispatchEvent(
new KeyboardEvent("keydown", { code: "KeyA", key: "2" }),
);
input.dispatchEvent(
new KeyboardEvent("keydown", { code: "KeyQ", key: "2" }),
);
}, 100);
// The captured event defines key as 2, if it is 1 the hook ignores the convination
expect(event.key).to.equal("2");
await asyncEventListener(element, "matchKeys");
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc