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

@vorlefan/react-hooks

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vorlefan/react-hooks - npm Package Compare versions

Comparing version 1.3.2 to 1.3.4

dist/useBoundingElement/index.d.ts

2

bundlesize.config.json

@@ -5,5 +5,5 @@ {

"path": "./dist/*.js",
"maxSize": "7 kb"
"maxSize": "7.5 kb"
}
]
}

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

# 1.3.5
- This doc needs to be updated xD
- useBoundingElement
# 1.2.0

@@ -2,0 +6,0 @@

@@ -14,1 +14,2 @@ export { default as useBoolean } from './useBoolean';

export { default as useFetch } from './useFetch';
export { default as useBoundingElement } from './useBoundingElement';

@@ -328,2 +328,7 @@ import { useMemo, useState, useEffect, useCallback } from 'react';

var hasDOM$1 = function () {
return typeof window !== 'undefined' &&
!!window.document &&
!!window.document.createElement;
};
function getSize(screenSize, config, margin) {

@@ -373,2 +378,23 @@ if (margin === void 0) { margin = [1, 1]; }

function useScreenSize(margin, config) {
var hasClient = hasDOM$1();
if (!hasClient) {
return {
innerHeight: 640,
outerWidth: 1360,
outerHeight: 640,
ratio: 0.47,
orientation: 'landscape',
difference: 1,
isFullHD: function () {
return false;
},
isHD: function () {
return true;
},
isTablet: function () {
return false;
},
isMobile: function () { return false; },
};
}
var _a = useState(getSize(!!config ? __assign({}, config) : SCREEN_SIZE_DEFAULT_CONFIG, config || SCREEN_SIZE_DEFAULT_CONFIG, margin || [1, 1])), screenSize = _a[0], setScreenSize = _a[1];

@@ -706,3 +732,31 @@ var handleResize = useCallback(function () {

export { useBoolean, useClient, useDebounce, useFetch, useIndex, useKeyboard, useLocalStorage, useMiddleMouse, useMouseIn, useObject, useScreenSize, useScroll, useToggle };
function useBoundingElement(key, callback) {
var inClient = useClient().inClient;
if (!inClient)
return false;
var _a = useState(false), pressed = _a[0], setPressed = _a[1];
var isMatching = useCallback(function (event) {
return event && event.key && key.toLowerCase() === event.key.toLowerCase();
}, [key]);
var onDown = useCallback(function (event) {
if (isMatching(event)) {
setPressed(true);
if (typeof callback === 'function') {
callback(event);
}
}
}, [callback]);
var onUp = useCallback(function (event) { return isMatching(event) && setPressed(false); }, [key]);
useEffect(function () {
window.addEventListener('keydown', onDown);
window.addEventListener('keyup', onUp);
return function () {
window.removeEventListener('keydown', function () { });
window.removeEventListener('keyup', function () { });
};
}, [key]);
return pressed;
}
export { useBoolean, useBoundingElement, useClient, useDebounce, useFetch, useIndex, useKeyboard, useLocalStorage, useMiddleMouse, useMouseIn, useObject, useScreenSize, useScroll, useToggle };
//# sourceMappingURL=index.es.js.map

@@ -332,2 +332,7 @@ 'use strict';

var hasDOM$1 = function () {
return typeof window !== 'undefined' &&
!!window.document &&
!!window.document.createElement;
};
function getSize(screenSize, config, margin) {

@@ -377,2 +382,23 @@ if (margin === void 0) { margin = [1, 1]; }

function useScreenSize(margin, config) {
var hasClient = hasDOM$1();
if (!hasClient) {
return {
innerHeight: 640,
outerWidth: 1360,
outerHeight: 640,
ratio: 0.47,
orientation: 'landscape',
difference: 1,
isFullHD: function () {
return false;
},
isHD: function () {
return true;
},
isTablet: function () {
return false;
},
isMobile: function () { return false; },
};
}
var _a = react.useState(getSize(!!config ? __assign({}, config) : SCREEN_SIZE_DEFAULT_CONFIG, config || SCREEN_SIZE_DEFAULT_CONFIG, margin || [1, 1])), screenSize = _a[0], setScreenSize = _a[1];

@@ -710,3 +736,32 @@ var handleResize = react.useCallback(function () {

function useBoundingElement(key, callback) {
var inClient = useClient().inClient;
if (!inClient)
return false;
var _a = react.useState(false), pressed = _a[0], setPressed = _a[1];
var isMatching = react.useCallback(function (event) {
return event && event.key && key.toLowerCase() === event.key.toLowerCase();
}, [key]);
var onDown = react.useCallback(function (event) {
if (isMatching(event)) {
setPressed(true);
if (typeof callback === 'function') {
callback(event);
}
}
}, [callback]);
var onUp = react.useCallback(function (event) { return isMatching(event) && setPressed(false); }, [key]);
react.useEffect(function () {
window.addEventListener('keydown', onDown);
window.addEventListener('keyup', onUp);
return function () {
window.removeEventListener('keydown', function () { });
window.removeEventListener('keyup', function () { });
};
}, [key]);
return pressed;
}
exports.useBoolean = useBoolean;
exports.useBoundingElement = useBoundingElement;
exports.useClient = useClient;

@@ -713,0 +768,0 @@ exports.useDebounce = useDebounce;

{
"name": "@vorlefan/react-hooks",
"version": "1.3.2",
"version": "1.3.4",
"description": "Useful react hooks for React & Next.js app",

@@ -5,0 +5,0 @@ "author": "DaxSoft",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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