Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solid-primitives/keyboard

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solid-primitives/keyboard - npm Package Compare versions

Comparing version 1.0.9-beta.0 to 1.0.9

34

dist/index.d.ts

@@ -1,2 +0,2 @@

import { Accessor } from "solid-js";
import { Accessor } from 'solid-js';

@@ -26,8 +26,5 @@ type ModifierKey = "Alt" | "Control" | "Meta" | "Shift";

*/
declare const useKeyDownList: () => [
keys: Accessor<string[]>,
other: {
declare const useKeyDownList: () => [keys: Accessor<string[]>, other: {
event: Accessor<KeyboardEvent | null>;
},
];
}];
/**

@@ -98,8 +95,5 @@ * Provides a signal with the currently held single key. Pressing any other key at the same time will reset the signal to `null`.

*/
declare function createKeyHold(
key: KbdKey,
options?: {
declare function createKeyHold(key: KbdKey, options?: {
preventDefault?: boolean;
},
): Accessor<boolean>;
}): Accessor<boolean>;
/**

@@ -123,19 +117,7 @@ * Creates a keyboard shotcut observer. The provided {@link callback} will be called when the specified {@link keys} are pressed.

*/
declare function createShortcut(
keys: KbdKey[],
callback: VoidFunction,
options?: {
declare function createShortcut(keys: KbdKey[], callback: VoidFunction, options?: {
preventDefault?: boolean;
requireReset?: boolean;
},
): void;
}): void;
export {
KbdKey,
ModifierKey,
createKeyHold,
createShortcut,
useCurrentlyHeldKey,
useKeyDownList,
useKeyDownSequence,
};
export { KbdKey, ModifierKey, createKeyHold, createShortcut, useCurrentlyHeldKey, useKeyDownList, useKeyDownSequence };

@@ -1,5 +0,5 @@

import { makeEventListener } from "@solid-primitives/event-listener";
import { createSharedRoot } from "@solid-primitives/rootless";
import { arrayEquals } from "@solid-primitives/utils";
import { createSignal, batch, untrack, createMemo, createEffect, on } from "solid-js";
import { makeEventListener } from '@solid-primitives/event-listener';
import { createSharedRoot } from '@solid-primitives/rootless';
import { arrayEquals } from '@solid-primitives/utils';
import { createSignal, batch, untrack, createMemo, createEffect, on } from 'solid-js';

@@ -10,3 +10,4 @@ // src/index.ts

const _model = model.slice(0, i + 1);
if (!arrayEquals(sequence[i], _model)) return false;
if (!arrayEquals(sequence[i], _model))
return false;
}

@@ -19,18 +20,21 @@ return true;

const reset = () => setPressedKeys([]);
makeEventListener(window, "keydown", e => {
if (e.repeat || typeof e.key !== "string") return;
makeEventListener(window, "keydown", (e) => {
if (e.repeat || typeof e.key !== "string")
return;
const key = e.key.toUpperCase();
if (pressedKeys().includes(key)) return;
if (pressedKeys().includes(key))
return;
batch(() => {
setEvent(e);
setPressedKeys(prev => [...prev, key]);
setPressedKeys((prev) => [...prev, key]);
});
});
makeEventListener(window, "keyup", e => {
if (typeof e.key !== "string") return;
makeEventListener(window, "keyup", (e) => {
if (typeof e.key !== "string")
return;
const key = e.key.toUpperCase();
setPressedKeys(prev => prev.filter(_key => _key !== key));
setPressedKeys((prev) => prev.filter((_key) => _key !== key));
});
makeEventListener(window, "blur", reset);
makeEventListener(window, "contextmenu", e => {
makeEventListener(window, "contextmenu", (e) => {
e.defaultPrevented || reset();

@@ -47,3 +51,4 @@ });

prevKeys = _keys;
if (prev.length === 0 && _keys.length === 1) return _keys[0];
if (prev.length === 0 && _keys.length === 1)
return _keys[0];
return null;

@@ -54,4 +59,5 @@ });

const [keys] = useKeyDownList();
return createMemo(prev => {
if (keys().length === 0) return [];
return createMemo((prev) => {
if (keys().length === 0)
return [];
return [...prev, keys()];

@@ -77,3 +83,3 @@ }, []);

}
keys = keys.map(key => key.toUpperCase());
keys = keys.map((key) => key.toUpperCase());
const { preventDefault = true, requireReset = false } = options;

@@ -83,5 +89,7 @@ const [, { event }] = useKeyDownList();

let reset = false;
const handleSequenceWithReset = sequence2 => {
if (!sequence2.length) return (reset = false);
if (reset) return;
const handleSequenceWithReset = (sequence2) => {
if (!sequence2.length)
return reset = false;
if (reset)
return;
if (sequence2.length < keys.length) {

@@ -101,5 +109,6 @@ if (equalsKeyHoldSequence(sequence2, keys.slice(0, sequence2.length))) {

};
const handleSequenceWithoutReset = sequence2 => {
const handleSequenceWithoutReset = (sequence2) => {
const last = sequence2.at(-1);
if (!last) return;
if (!last)
return;
if (preventDefault && last.length < keys.length) {

@@ -106,0 +115,0 @@ if (arrayEquals(last, keys.slice(0, keys.length - 1))) {

{
"name": "@solid-primitives/keyboard",
"version": "1.0.9-beta.0",
"version": "1.0.9",
"description": "A library of reactive promitives helping handling user's keyboard input.",

@@ -84,5 +84,5 @@ "author": "Damian Tarnwski <gthetarnav@gmail.com>",

"dependencies": {
"@solid-primitives/event-listener": "^2.2.8-beta.0",
"@solid-primitives/rootless": "^1.2.6-beta.0",
"@solid-primitives/utils": "^5.4.0-beta.0"
"@solid-primitives/event-listener": "^2.2.8",
"@solid-primitives/rootless": "^1.2.6",
"@solid-primitives/utils": "^5.4.0"
},

@@ -89,0 +89,0 @@ "peerDependencies": {

@@ -0,0 +0,0 @@ <p>

Sorry, the diff of this file is not supported yet

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