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

@leafygreen-ui/hooks

Package Overview
Dependencies
Maintainers
5
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafygreen-ui/hooks - npm Package Compare versions

Comparing version 8.2.0 to 8.2.1

dist/useAvailableSpace/index.d.ts

17

CHANGELOG.md
# @leafygreen-ui/hooks
## 8.2.1
### Patch Changes
- 84028dc5d: Removes `useMemo` from `useAvailableSpace`, which was preventing the hook from returning the correct value.
On first render, the `triggerRef` is not available but `useViewportSize` is. When the menu is opened, the `triggerRef` is available but the viewport size remains the same so the memo callback is not triggered since refs do not trigger a re-render.
Previously, `useViewportSize` returned null and then re-rendered with the correct dimensions, which would trigger the memo callback.
These changes should affect the following components:
- `Select`
- `Combobox`
- `Menu`
- `SearchInput`
## 8.2.0

@@ -4,0 +21,0 @@

2

dist/esm/index.js

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

import*as n from"react";import{useEffect as r,useState as t,useMemo as e,useRef as o,useCallback as i,useLayoutEffect as u}from"react";import c from"lodash/debounce";import a from"lodash/isUndefined";import{consoleOnce as l,createSyntheticEvent as f}from"@leafygreen-ui/lib";import v from"lodash/isEqual";var d=function(n,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;r((function(){if(n&&n.current&&t&&t.current){var r=n.current.offsetTop,o=t.current,i=o.scrollTop;(r>o.offsetHeight||r<i)&&t.current.scrollTo({top:r-e,behavior:"smooth"})}}),[t,n,e])};function s(n,r){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(n);r&&(e=e.filter((function(r){return Object.getOwnPropertyDescriptor(n,r).enumerable}))),t.push.apply(t,e)}return t}function p(n){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?s(Object(t),!0).forEach((function(r){m(n,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):s(Object(t)).forEach((function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))}))}return n}function y(n){var r=function(n,r){if("object"!=typeof n||!n)return n;var t=n[Symbol.toPrimitive];if(void 0!==t){var e=t.call(n,r);if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(n)}(n,"string");return"symbol"==typeof r?r:r+""}function b(n){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},b(n)}function m(n,r,t){return(r=y(r))in n?Object.defineProperty(n,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[r]=t,n}function h(n,r){return function(n){if(Array.isArray(n))return n}(n)||function(n,r){var t=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=t){var e,o,i,u,c=[],a=!0,l=!1;try{if(i=(t=t.call(n)).next,0===r);else for(;!(a=(e=i.call(t)).done)&&(c.push(e.value),c.length!==r);a=!0);}catch(n){l=!0,o=n}finally{try{if(!a&&null!=t.return&&(u=t.return(),Object(u)!==u))return}finally{if(l)throw o}}return c}}(n,r)||w(n,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(n){return function(n){if(Array.isArray(n))return O(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||w(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(n,r){if(n){if("string"==typeof n)return O(n,r);var t=Object.prototype.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?O(n,r):void 0}}function O(n,r){(null==r||r>n.length)&&(r=n.length);for(var t=0,e=new Array(r);t<r;t++)e[t]=n[t];return e}function j(){var n=h(t("undefined"==typeof window),2),e=n[0],o=n[1];return r((function(){o(!1)}),[]),e}function S(){return{width:window.innerWidth,height:window.innerHeight}}function P(){var n=j(),e=h(t(n?null:S()),2),o=e[0],i=e[1];return r((function(){var n=c((function(){return i(S())}),100);return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[]),o}var A=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,t=P();return e((function(){if(t&&n&&n.current){var e=n.current.getBoundingClientRect(),o=e.top,i=e.bottom;return Math.max(t.height-i,o)-r}}),[t,n,r])};function E(n,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=e.options,u=e.enabled,c=void 0===u||u,a=e.dependencies,l=void 0===a?[c,n]:a,f=e.element,v=o((function(){}));r((function(){v.current=t}),[t]),r((function(){if(!1!==c){if("once"===c||!0===c){var r=function(n){v.current(n)},t=p(p({},i),{},{once:"once"===c});return(null!=f?f:document).addEventListener(n,r,t),function(){(null!=f?f:document).removeEventListener(n,r,t)}}console.error("Received value of type ".concat(b(c)," for property `enabled`. Expected a boolean."))}}),l)}function C(n,r){var t=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];function e(n){var t,e=n.target;return Array.isArray(r)?r.some((function(n){var r;return null===(r=n.current)||void 0===r?void 0:r.contains(e)})):(null===(t=r.current)||void 0===t?void 0:t.contains(e))||!1}E("mousedown",(function(n){e(n)||(n.preventDefault(),n.stopPropagation())}),{enabled:t}),E("click",(function(r){e(r)||(r.stopPropagation(),n())}),{options:{capture:!0},enabled:t})}var T=function(n,o,i){var u=e((function(){return!a(n)}),[]),c=h(t(i),2),v=c[0],d=c[1],s=function(n){null==o||o(n),u||d(n.target.value)};return r((function(){a(n)&&a(i)&&l.error("Warning: `useControlledValue` hook is being used without a value or initialValue. This will cause a React warning when the input changes. Please decide between using a controlled or uncontrolled input element, and provide either a controlledValue or initialValue to `useControlledValue`")}),[n,i]),{isControlled:u,value:u?n:v,handleChange:s,setUncontrolledValue:d,updateValue:function(n,r){if(r.current){r.current.value=n;var t=f(new Event("change",{cancelable:!0,bubbles:!0}),r.current);s(t)}}}};function V(r){var t=null==r?void 0:r.prefix;return n.useMemo((function(){var r=function(r){return function(t){if(t){if(r.get(t))return r.get(t);var e=n.createRef();return r.set(t,e),e}l.error("`useDynamicRefs`: Cannot get ref without key")}}(new Map);return r}),t?[t]:[])}var x=function(n,r){return E("keydown",(function(r){return function(n,r){27===n.keyCode&&(n.stopImmediatePropagation(),r())}(r,n)}),r)};function I(){var n=h(t({}),2)[1];return i((function(){return n({})}),[])}function k(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=r.initialValue,i=r.deps,u=void 0===i?[]:i,c=o(t);return e((function(){return{get current(){return c.current},set current(r){c.current=r,n(r)}}}),[n,c].concat(g(u)))}function D(n,r){var t=i((function(n,r){Array.isArray(n)?n.forEach(t):"function"==typeof n?n(r):n&&(n.current=r)}),[]);return k(i((function(r){return t(n,r)}),[n,t]),{initialValue:r})}var M=0;function R(n){var e=n.prefix;return function(n){var e=n.id,o=n.prefix,i=h(t(e),2),u=i[0],c=i[1];return r((function(){null==u&&c(M+=1)}),[u,o]),e||"".concat(null!=o?o:"lg","-").concat(u)}({id:n.id,prefix:e})}var L=function(){return("undefined"==typeof window?r:u).apply(void 0,arguments)};function B(n,e,o){var i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=h(t(),2),c=u[0],a=u[1];return r((function(){if(i){var r=new MutationObserver((function(){a(o.apply(void 0,arguments))}));return n&&r.observe(n,e),function(){return r.disconnect()}}}),[n,e,o,i]),c}function U(n){var r=o();return void 0!==r.current&&v(r.current,n)||(r.current=n),r.current}function z(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=e.interval,u=void 0===i?3e4:i,c=e.immediate,a=void 0===c||c,l=e.enabled,f=void 0===l||l,v=o(),d=function(){var n=function(){return"visible"===document.visibilityState},e=h(t(!0),2),o=e[0],i=e[1];return r((function(){i(n)}),[]),E("visibilitychange",(function(){i(n)})),o}()&&f;r((function(){v.current=n})),r((function(){var n;if(d)return a?e():r(),t;function r(){t(),n=setTimeout(e,u)}function t(){clearTimeout(n)}function e(){var n;Promise.resolve(null===(n=v.current)||void 0===n?void 0:n.call(v)).finally(r)}}),[u,a,d])}function H(n){var t=o();return r((function(){t.current=n})),t.current}function W(n){var r=h(t(n),2),e=r[0],u=r[1],c=o(e);return[e,i((function(n){u(n),c.current=n}),[u]),i((function(){return c.current}),[])]}function q(n){var r=h(t(!1),2),e=r[0],o=r[1];if(a(n)||"function"!=typeof n)return{onBlur:function(){},onChange:function(){}};return{onBlur:function(r){o(!0),null==n||n(r.target.value)},onChange:function(r){e&&(null==n||n(r.target.value))}}}export{d as useAutoScroll,A as useAvailableSpace,C as useBackdropClick,T as useControlledValue,V as useDynamicRefs,x as useEscapeKey,E as useEventListener,I as useForceRerender,D as useForwardedRef,R as useIdAllocator,L as useIsomorphicLayoutEffect,B as useMutationObserver,U as useObjectDependency,k as useObservedRef,z as usePoller,H as usePrevious,j as useSsrCheck,W as useStateRef,q as useValidation,P as useViewportSize};
import*as n from"react";import{useEffect as r,useState as t,useRef as e,useMemo as o,useCallback as i,useLayoutEffect as u}from"react";import c from"lodash/debounce";import a from"lodash/isUndefined";import{consoleOnce as l,createSyntheticEvent as f}from"@leafygreen-ui/lib";import v from"lodash/isEqual";var d=function(n,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;r((function(){if(n&&n.current&&t&&t.current){var r=n.current.offsetTop,o=t.current,i=o.scrollTop;(r>o.offsetHeight||r<i)&&t.current.scrollTo({top:r-e,behavior:"smooth"})}}),[t,n,e])};function s(n,r){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(n);r&&(e=e.filter((function(r){return Object.getOwnPropertyDescriptor(n,r).enumerable}))),t.push.apply(t,e)}return t}function p(n){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?s(Object(t),!0).forEach((function(r){m(n,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):s(Object(t)).forEach((function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))}))}return n}function y(n){var r=function(n,r){if("object"!=typeof n||!n)return n;var t=n[Symbol.toPrimitive];if(void 0!==t){var e=t.call(n,r);if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(n)}(n,"string");return"symbol"==typeof r?r:r+""}function b(n){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},b(n)}function m(n,r,t){return(r=y(r))in n?Object.defineProperty(n,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[r]=t,n}function h(n,r){return function(n){if(Array.isArray(n))return n}(n)||function(n,r){var t=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=t){var e,o,i,u,c=[],a=!0,l=!1;try{if(i=(t=t.call(n)).next,0===r);else for(;!(a=(e=i.call(t)).done)&&(c.push(e.value),c.length!==r);a=!0);}catch(n){l=!0,o=n}finally{try{if(!a&&null!=t.return&&(u=t.return(),Object(u)!==u))return}finally{if(l)throw o}}return c}}(n,r)||w(n,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(n){return function(n){if(Array.isArray(n))return O(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||w(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(n,r){if(n){if("string"==typeof n)return O(n,r);var t=Object.prototype.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?O(n,r):void 0}}function O(n,r){(null==r||r>n.length)&&(r=n.length);for(var t=0,e=new Array(r);t<r;t++)e[t]=n[t];return e}function j(){var n=h(t("undefined"==typeof window),2),e=n[0],o=n[1];return r((function(){o(!1)}),[]),e}function S(){return{width:window.innerWidth,height:window.innerHeight}}function P(){var n=j(),e=h(t(n?null:S()),2),o=e[0],i=e[1];return r((function(){var n=c((function(){return i(S())}),100);return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[]),o}var A=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,t=P();if(t&&n&&n.current){var e=n.current.getBoundingClientRect(),o=e.top,i=e.bottom;return Math.max(t.height-i,o)-r}};function E(n,t){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=o.options,u=o.enabled,c=void 0===u||u,a=o.dependencies,l=void 0===a?[c,n]:a,f=o.element,v=e((function(){}));r((function(){v.current=t}),[t]),r((function(){if(!1!==c){if("once"===c||!0===c){var r=function(n){v.current(n)},t=p(p({},i),{},{once:"once"===c});return(null!=f?f:document).addEventListener(n,r,t),function(){(null!=f?f:document).removeEventListener(n,r,t)}}console.error("Received value of type ".concat(b(c)," for property `enabled`. Expected a boolean."))}}),l)}function C(n,r){var t=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];function e(n){var t,e=n.target;return Array.isArray(r)?r.some((function(n){var r;return null===(r=n.current)||void 0===r?void 0:r.contains(e)})):(null===(t=r.current)||void 0===t?void 0:t.contains(e))||!1}E("mousedown",(function(n){e(n)||(n.preventDefault(),n.stopPropagation())}),{enabled:t}),E("click",(function(r){e(r)||(r.stopPropagation(),n())}),{options:{capture:!0},enabled:t})}var T=function(n,e,i){var u=o((function(){return!a(n)}),[]),c=h(t(i),2),v=c[0],d=c[1],s=function(n){null==e||e(n),u||d(n.target.value)};return r((function(){a(n)&&a(i)&&l.error("Warning: `useControlledValue` hook is being used without a value or initialValue. This will cause a React warning when the input changes. Please decide between using a controlled or uncontrolled input element, and provide either a controlledValue or initialValue to `useControlledValue`")}),[n,i]),{isControlled:u,value:u?n:v,handleChange:s,setUncontrolledValue:d,updateValue:function(n,r){if(r.current){r.current.value=n;var t=f(new Event("change",{cancelable:!0,bubbles:!0}),r.current);s(t)}}}};function V(r){var t=null==r?void 0:r.prefix;return n.useMemo((function(){var r=function(r){return function(t){if(t){if(r.get(t))return r.get(t);var e=n.createRef();return r.set(t,e),e}l.error("`useDynamicRefs`: Cannot get ref without key")}}(new Map);return r}),t?[t]:[])}var x=function(n,r){return E("keydown",(function(r){return function(n,r){27===n.keyCode&&(n.stopImmediatePropagation(),r())}(r,n)}),r)};function I(){var n=h(t({}),2)[1];return i((function(){return n({})}),[])}function k(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=r.initialValue,i=r.deps,u=void 0===i?[]:i,c=e(t);return o((function(){return{get current(){return c.current},set current(r){c.current=r,n(r)}}}),[n,c].concat(g(u)))}function D(n,r){var t=i((function(n,r){Array.isArray(n)?n.forEach(t):"function"==typeof n?n(r):n&&(n.current=r)}),[]);return k(i((function(r){return t(n,r)}),[n,t]),{initialValue:r})}var M=0;function R(n){var e=n.prefix;return function(n){var e=n.id,o=n.prefix,i=h(t(e),2),u=i[0],c=i[1];return r((function(){null==u&&c(M+=1)}),[u,o]),e||"".concat(null!=o?o:"lg","-").concat(u)}({id:n.id,prefix:e})}var L=function(){return("undefined"==typeof window?r:u).apply(void 0,arguments)};function B(n,e,o){var i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=h(t(),2),c=u[0],a=u[1];return r((function(){if(i){var r=new MutationObserver((function(){a(o.apply(void 0,arguments))}));return n&&r.observe(n,e),function(){return r.disconnect()}}}),[n,e,o,i]),c}function U(n){var r=e();return void 0!==r.current&&v(r.current,n)||(r.current=n),r.current}function z(n){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=o.interval,u=void 0===i?3e4:i,c=o.immediate,a=void 0===c||c,l=o.enabled,f=void 0===l||l,v=e(),d=function(){var n=function(){return"visible"===document.visibilityState},e=h(t(!0),2),o=e[0],i=e[1];return r((function(){i(n)}),[]),E("visibilitychange",(function(){i(n)})),o}()&&f;r((function(){v.current=n})),r((function(){var n;if(d)return a?e():r(),t;function r(){t(),n=setTimeout(e,u)}function t(){clearTimeout(n)}function e(){var n;Promise.resolve(null===(n=v.current)||void 0===n?void 0:n.call(v)).finally(r)}}),[u,a,d])}function H(n){var t=e();return r((function(){t.current=n})),t.current}function W(n){var r=h(t(n),2),o=r[0],u=r[1],c=e(o);return[o,i((function(n){u(n),c.current=n}),[u]),i((function(){return c.current}),[])]}function q(n){var r=h(t(!1),2),e=r[0],o=r[1];if(a(n)||"function"!=typeof n)return{onBlur:function(){},onChange:function(){}};return{onBlur:function(r){o(!0),null==n||n(r.target.value)},onChange:function(r){e&&(null==n||n(r.target.value))}}}export{d as useAutoScroll,A as useAvailableSpace,C as useBackdropClick,T as useControlledValue,V as useDynamicRefs,x as useEscapeKey,E as useEventListener,I as useForceRerender,D as useForwardedRef,R as useIdAllocator,L as useIsomorphicLayoutEffect,B as useMutationObserver,U as useObjectDependency,k as useObservedRef,z as usePoller,H as usePrevious,j as useSsrCheck,W as useStateRef,q as useValidation,P as useViewportSize};
//# sourceMappingURL=index.js.map

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react"),require("lodash/debounce"),require("lodash/isUndefined"),require("@leafygreen-ui/lib"),require("lodash/isEqual")):"function"==typeof define&&define.amd?define(["exports","react","lodash/debounce","lodash/isUndefined","@leafygreen-ui/lib","lodash/isEqual"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["@leafygreen-ui/hooks"]={},e.React,e["/debounce"],e["/isUndefined"],e["@leafygreen-ui/lib"],e["/isEqual"])}(this,(function(e,n,t,r,o,u){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&"object"==typeof e&&"default"in e)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}})),n.default=e,Object.freeze(n)}var a=c(n),f=i(t),l=i(r),s=i(u);function d(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function v(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?d(Object(t),!0).forEach((function(n){b(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):d(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function p(e){var n=function(e,n){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof n?n:n+""}function y(e){return y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},y(e)}function b(e,n,t){return(n=p(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function h(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var r,o,u,i,c=[],a=!0,f=!1;try{if(u=(t=t.call(e)).next,0===n);else for(;!(a=(r=u.call(t)).done)&&(c.push(r.value),c.length!==n);a=!0);}catch(e){f=!0,o=e}finally{try{if(!a&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(f)throw o}}return c}}(e,n)||g(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e){return function(e){if(Array.isArray(e))return w(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||g(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,n){if(e){if("string"==typeof e)return w(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?w(e,n):void 0}}function w(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function E(){var e=h(n.useState("undefined"==typeof window),2),t=e[0],r=e[1];return n.useEffect((function(){r(!1)}),[]),t}function O(){return{width:window.innerWidth,height:window.innerHeight}}function S(){var e=E(),t=h(n.useState(e?null:O()),2),r=t[0],o=t[1];return n.useEffect((function(){var e=f.default((function(){return o(O())}),100);return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),r}function j(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=r.options,u=r.enabled,i=void 0===u||u,c=r.dependencies,a=void 0===c?[i,e]:c,f=r.element,l=n.useRef((function(){}));n.useEffect((function(){l.current=t}),[t]),n.useEffect((function(){if(!1!==i){if("once"===i||!0===i){var n=function(e){l.current(e)},t=v(v({},o),{},{once:"once"===i});return(null!=f?f:document).addEventListener(e,n,t),function(){(null!=f?f:document).removeEventListener(e,n,t)}}console.error("Received value of type ".concat(y(i)," for property `enabled`. Expected a boolean."))}}),a)}function P(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.initialValue,o=t.deps,u=void 0===o?[]:o,i=n.useRef(r);return n.useMemo((function(){return{get current(){return i.current},set current(n){i.current=n,e(n)}}}),[e,i].concat(m(u)))}var C=0;e.useAutoScroll=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n.useEffect((function(){if(e&&e.current&&t&&t.current){var n=e.current.offsetTop,o=t.current,u=o.scrollTop;(n>o.offsetHeight||n<u)&&t.current.scrollTo({top:n-r,behavior:"smooth"})}}),[t,e,r])},e.useAvailableSpace=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,r=S();return n.useMemo((function(){if(r&&e&&e.current){var n=e.current.getBoundingClientRect(),o=n.top,u=n.bottom;return Math.max(r.height-u,o)-t}}),[r,e,t])},e.useBackdropClick=function(e,n){var t=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];function r(e){var t,r=e.target;return Array.isArray(n)?n.some((function(e){var n;return null===(n=e.current)||void 0===n?void 0:n.contains(r)})):(null===(t=n.current)||void 0===t?void 0:t.contains(r))||!1}j("mousedown",(function(e){r(e)||(e.preventDefault(),e.stopPropagation())}),{enabled:t}),j("click",(function(n){r(n)||(n.stopPropagation(),e())}),{options:{capture:!0},enabled:t})},e.useControlledValue=function(e,t,r){var u=n.useMemo((function(){return!l.default(e)}),[]),i=h(n.useState(r),2),c=i[0],a=i[1],f=function(e){null==t||t(e),u||a(e.target.value)};return n.useEffect((function(){l.default(e)&&l.default(r)&&o.consoleOnce.error("Warning: `useControlledValue` hook is being used without a value or initialValue. This will cause a React warning when the input changes. Please decide between using a controlled or uncontrolled input element, and provide either a controlledValue or initialValue to `useControlledValue`")}),[e,r]),{isControlled:u,value:u?e:c,handleChange:f,setUncontrolledValue:a,updateValue:function(e,n){if(n.current){n.current.value=e;var t=o.createSyntheticEvent(new Event("change",{cancelable:!0,bubbles:!0}),n.current);f(t)}}}},e.useDynamicRefs=function(e){var n=null==e?void 0:e.prefix;return a.useMemo((function(){var e=function(e){return function(n){if(n){if(e.get(n))return e.get(n);var t=a.createRef();return e.set(n,t),t}o.consoleOnce.error("`useDynamicRefs`: Cannot get ref without key")}}(new Map);return e}),n?[n]:[])},e.useEscapeKey=function(e,n){return j("keydown",(function(n){return function(e,n){27===e.keyCode&&(e.stopImmediatePropagation(),n())}(n,e)}),n)},e.useEventListener=j,e.useForceRerender=function(){var e=h(n.useState({}),2)[1];return n.useCallback((function(){return e({})}),[])},e.useForwardedRef=function(e,t){var r=n.useCallback((function(e,n){Array.isArray(e)?e.forEach(r):"function"==typeof e?e(n):e&&(e.current=n)}),[]);return P(n.useCallback((function(n){return r(e,n)}),[e,r]),{initialValue:t})},e.useIdAllocator=function(e){var t=e.prefix;return function(e){var t=e.id,r=e.prefix,o=h(n.useState(t),2),u=o[0],i=o[1];return n.useEffect((function(){null==u&&i(C+=1)}),[u,r]),t||"".concat(null!=r?r:"lg","-").concat(u)}({id:e.id,prefix:t})},e.useIsomorphicLayoutEffect=function(){return("undefined"==typeof window?n.useEffect:n.useLayoutEffect).apply(void 0,arguments)},e.useMutationObserver=function(e,t,r){var o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=h(n.useState(),2),i=u[0],c=u[1];return n.useEffect((function(){if(o){var n=new MutationObserver((function(){c(r.apply(void 0,arguments))}));return e&&n.observe(e,t),function(){return n.disconnect()}}}),[e,t,r,o]),i},e.useObjectDependency=function(e){var t=n.useRef();return void 0!==t.current&&s.default(t.current,e)||(t.current=e),t.current},e.useObservedRef=P,e.usePoller=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.interval,o=void 0===r?3e4:r,u=t.immediate,i=void 0===u||u,c=t.enabled,a=void 0===c||c,f=n.useRef(),l=function(){var e=function(){return"visible"===document.visibilityState},t=h(n.useState(!0),2),r=t[0],o=t[1];return n.useEffect((function(){o(e)}),[]),j("visibilitychange",(function(){o(e)})),r}()&&a;n.useEffect((function(){f.current=e})),n.useEffect((function(){var e;if(l)return i?r():n(),t;function n(){t(),e=setTimeout(r,o)}function t(){clearTimeout(e)}function r(){var e;Promise.resolve(null===(e=f.current)||void 0===e?void 0:e.call(f)).finally(n)}}),[o,i,l])},e.usePrevious=function(e){var t=n.useRef();return n.useEffect((function(){t.current=e})),t.current},e.useSsrCheck=E,e.useStateRef=function(e){var t=h(n.useState(e),2),r=t[0],o=t[1],u=n.useRef(r);return[r,n.useCallback((function(e){o(e),u.current=e}),[o]),n.useCallback((function(){return u.current}),[])]},e.useValidation=function(e){var t=h(n.useState(!1),2),r=t[0],o=t[1];return l.default(e)||"function"!=typeof e?{onBlur:function(){},onChange:function(){}}:{onBlur:function(n){o(!0),null==e||e(n.target.value)},onChange:function(n){r&&(null==e||e(n.target.value))}}},e.useViewportSize=S}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react"),require("lodash/debounce"),require("lodash/isUndefined"),require("@leafygreen-ui/lib"),require("lodash/isEqual")):"function"==typeof define&&define.amd?define(["exports","react","lodash/debounce","lodash/isUndefined","@leafygreen-ui/lib","lodash/isEqual"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["@leafygreen-ui/hooks"]={},e.React,e["/debounce"],e["/isUndefined"],e["@leafygreen-ui/lib"],e["/isEqual"])}(this,(function(e,n,t,r,o,u){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&"object"==typeof e&&"default"in e)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}})),n.default=e,Object.freeze(n)}var a=c(n),f=i(t),l=i(r),s=i(u);function d(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function v(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?d(Object(t),!0).forEach((function(n){b(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):d(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function p(e){var n=function(e,n){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof n?n:n+""}function y(e){return y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},y(e)}function b(e,n,t){return(n=p(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function h(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var r,o,u,i,c=[],a=!0,f=!1;try{if(u=(t=t.call(e)).next,0===n);else for(;!(a=(r=u.call(t)).done)&&(c.push(r.value),c.length!==n);a=!0);}catch(e){f=!0,o=e}finally{try{if(!a&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(f)throw o}}return c}}(e,n)||g(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e){return function(e){if(Array.isArray(e))return w(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||g(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,n){if(e){if("string"==typeof e)return w(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?w(e,n):void 0}}function w(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function E(){var e=h(n.useState("undefined"==typeof window),2),t=e[0],r=e[1];return n.useEffect((function(){r(!1)}),[]),t}function O(){return{width:window.innerWidth,height:window.innerHeight}}function S(){var e=E(),t=h(n.useState(e?null:O()),2),r=t[0],o=t[1];return n.useEffect((function(){var e=f.default((function(){return o(O())}),100);return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),r}function j(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=r.options,u=r.enabled,i=void 0===u||u,c=r.dependencies,a=void 0===c?[i,e]:c,f=r.element,l=n.useRef((function(){}));n.useEffect((function(){l.current=t}),[t]),n.useEffect((function(){if(!1!==i){if("once"===i||!0===i){var n=function(e){l.current(e)},t=v(v({},o),{},{once:"once"===i});return(null!=f?f:document).addEventListener(e,n,t),function(){(null!=f?f:document).removeEventListener(e,n,t)}}console.error("Received value of type ".concat(y(i)," for property `enabled`. Expected a boolean."))}}),a)}function P(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.initialValue,o=t.deps,u=void 0===o?[]:o,i=n.useRef(r);return n.useMemo((function(){return{get current(){return i.current},set current(n){i.current=n,e(n)}}}),[e,i].concat(m(u)))}var C=0;e.useAutoScroll=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n.useEffect((function(){if(e&&e.current&&t&&t.current){var n=e.current.offsetTop,o=t.current,u=o.scrollTop;(n>o.offsetHeight||n<u)&&t.current.scrollTo({top:n-r,behavior:"smooth"})}}),[t,e,r])},e.useAvailableSpace=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,t=S();if(t&&e&&e.current){var r=e.current.getBoundingClientRect(),o=r.top,u=r.bottom;return Math.max(t.height-u,o)-n}},e.useBackdropClick=function(e,n){var t=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];function r(e){var t,r=e.target;return Array.isArray(n)?n.some((function(e){var n;return null===(n=e.current)||void 0===n?void 0:n.contains(r)})):(null===(t=n.current)||void 0===t?void 0:t.contains(r))||!1}j("mousedown",(function(e){r(e)||(e.preventDefault(),e.stopPropagation())}),{enabled:t}),j("click",(function(n){r(n)||(n.stopPropagation(),e())}),{options:{capture:!0},enabled:t})},e.useControlledValue=function(e,t,r){var u=n.useMemo((function(){return!l.default(e)}),[]),i=h(n.useState(r),2),c=i[0],a=i[1],f=function(e){null==t||t(e),u||a(e.target.value)};return n.useEffect((function(){l.default(e)&&l.default(r)&&o.consoleOnce.error("Warning: `useControlledValue` hook is being used without a value or initialValue. This will cause a React warning when the input changes. Please decide between using a controlled or uncontrolled input element, and provide either a controlledValue or initialValue to `useControlledValue`")}),[e,r]),{isControlled:u,value:u?e:c,handleChange:f,setUncontrolledValue:a,updateValue:function(e,n){if(n.current){n.current.value=e;var t=o.createSyntheticEvent(new Event("change",{cancelable:!0,bubbles:!0}),n.current);f(t)}}}},e.useDynamicRefs=function(e){var n=null==e?void 0:e.prefix;return a.useMemo((function(){var e=function(e){return function(n){if(n){if(e.get(n))return e.get(n);var t=a.createRef();return e.set(n,t),t}o.consoleOnce.error("`useDynamicRefs`: Cannot get ref without key")}}(new Map);return e}),n?[n]:[])},e.useEscapeKey=function(e,n){return j("keydown",(function(n){return function(e,n){27===e.keyCode&&(e.stopImmediatePropagation(),n())}(n,e)}),n)},e.useEventListener=j,e.useForceRerender=function(){var e=h(n.useState({}),2)[1];return n.useCallback((function(){return e({})}),[])},e.useForwardedRef=function(e,t){var r=n.useCallback((function(e,n){Array.isArray(e)?e.forEach(r):"function"==typeof e?e(n):e&&(e.current=n)}),[]);return P(n.useCallback((function(n){return r(e,n)}),[e,r]),{initialValue:t})},e.useIdAllocator=function(e){var t=e.prefix;return function(e){var t=e.id,r=e.prefix,o=h(n.useState(t),2),u=o[0],i=o[1];return n.useEffect((function(){null==u&&i(C+=1)}),[u,r]),t||"".concat(null!=r?r:"lg","-").concat(u)}({id:e.id,prefix:t})},e.useIsomorphicLayoutEffect=function(){return("undefined"==typeof window?n.useEffect:n.useLayoutEffect).apply(void 0,arguments)},e.useMutationObserver=function(e,t,r){var o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=h(n.useState(),2),i=u[0],c=u[1];return n.useEffect((function(){if(o){var n=new MutationObserver((function(){c(r.apply(void 0,arguments))}));return e&&n.observe(e,t),function(){return n.disconnect()}}}),[e,t,r,o]),i},e.useObjectDependency=function(e){var t=n.useRef();return void 0!==t.current&&s.default(t.current,e)||(t.current=e),t.current},e.useObservedRef=P,e.usePoller=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.interval,o=void 0===r?3e4:r,u=t.immediate,i=void 0===u||u,c=t.enabled,a=void 0===c||c,f=n.useRef(),l=function(){var e=function(){return"visible"===document.visibilityState},t=h(n.useState(!0),2),r=t[0],o=t[1];return n.useEffect((function(){o(e)}),[]),j("visibilitychange",(function(){o(e)})),r}()&&a;n.useEffect((function(){f.current=e})),n.useEffect((function(){var e;if(l)return i?r():n(),t;function n(){t(),e=setTimeout(r,o)}function t(){clearTimeout(e)}function r(){var e;Promise.resolve(null===(e=f.current)||void 0===e?void 0:e.call(f)).finally(n)}}),[o,i,l])},e.usePrevious=function(e){var t=n.useRef();return n.useEffect((function(){t.current=e})),t.current},e.useSsrCheck=E,e.useStateRef=function(e){var t=h(n.useState(e),2),r=t[0],o=t[1],u=n.useRef(r);return[r,n.useCallback((function(e){o(e),u.current=e}),[o]),n.useCallback((function(){return u.current}),[])]},e.useValidation=function(e){var t=h(n.useState(!1),2),r=t[0],o=t[1];return l.default(e)||"function"!=typeof e?{onBlur:function(){},onChange:function(){}}:{onBlur:function(n){o(!0),null==e||e(n.target.value)},onChange:function(n){r&&(null==e||e(n.target.value))}}},e.useViewportSize=S}));
//# sourceMappingURL=index.js.map
{
"name": "@leafygreen-ui/hooks",
"version": "8.2.0",
"version": "8.2.1",
"description": "LeafyGreen UI Kit Custom Hooks",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

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