@leafygreen-ui/hooks
Advanced tools
Comparing version 8.1.3 to 8.1.4
# @leafygreen-ui/hooks | ||
## 8.1.4 | ||
### Patch Changes | ||
- c1b8b633b: Fixes re-render after initial render of `useViewportSize` hook | ||
- fe2483937: Makes prefix argument optional for `useDynamicRefs` | ||
## 8.1.3 | ||
@@ -4,0 +11,0 @@ |
@@ -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){b(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){return y="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},y(n)}function b(n,r,t){return(r=function(n){var r=function(n,r){if("object"!=typeof n||null===n)return n;var t=n[Symbol.toPrimitive];if(void 0!==t){var e=t.call(n,r||"default");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(n)}(n,"string");return"symbol"==typeof r?r:String(r)}(r))in n?Object.defineProperty(n,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[r]=t,n}function m(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){if(Object(t)!==t)return;a=!1}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)||h(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 w(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||h(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 h(n,r){if(n){if("string"==typeof n)return w(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)?w(n,r):void 0}}function w(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 O(){return{width:window.innerWidth,height:window.innerHeight}}function j(){var n=m(t(null),2),e=n[0],o=n[1];return r((function(){o(O());var n=c((function(){return o(O())}),100);return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[]),e}var S=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,t=j();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 P(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(y(c)," for property `enabled`. Expected a boolean."))}}),l)}function A(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}P("mousedown",(function(n){e(n)||(n.preventDefault(),n.stopPropagation())}),{enabled:t}),P("click",(function(r){e(r)||(r.stopPropagation(),n())}),{options:{capture:!0},enabled:t})}var E=function(n,o,i){var u=e((function(){return!a(n)}),[]),c=m(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 C(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])}var T=function(n,r){return P("keydown",(function(r){return function(n,r){27===n.keyCode&&(n.stopImmediatePropagation(),r())}(r,n)}),r)};function V(){var n=m(t({}),2)[1];return i((function(){return n({})}),[])}function x(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 I(n,r){var t=i((function(n,r){Array.isArray(n)?n.forEach(t):"function"==typeof n?n(r):n&&(n.current=r)}),[]);return x(i((function(r){return t(n,r)}),[n,t]),{initialValue:r})}var k=0;function D(n){var e=n.prefix;return function(n){var e=n.id,o=n.prefix,i=m(t(e),2),u=i[0],c=i[1];return r((function(){null==u&&c(k+=1)}),[u,o]),e||"".concat(null!=o?o:"lg","-").concat(u)}({id:n.id,prefix:e})}var M=function(){return("undefined"==typeof window?r:u).apply(void 0,arguments)};function R(n,e,o){var i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=m(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 L(n){var r=o();return void 0!==r.current&&v(r.current,n)||(r.current=n),r.current}function B(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=m(t(!0),2),o=e[0],i=e[1];return r((function(){i(n)}),[]),P("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 U(n){var t=o();return r((function(){t.current=n})),t.current}function z(n){var r=m(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 H(n){var r=m(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,S as useAvailableSpace,A as useBackdropClick,E as useControlledValue,C as useDynamicRefs,T as useEscapeKey,P as useEventListener,V as useForceRerender,I as useForwardedRef,D as useIdAllocator,M as useIsomorphicLayoutEffect,R as useMutationObserver,L as useObjectDependency,x as useObservedRef,B as usePoller,U as usePrevious,z as useStateRef,H as useValidation,j as useViewportSize}; | ||
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(){return{width:window.innerWidth,height:window.innerHeight}}function S(){var n=h(t(j()),2),e=n[0],o=n[1];return r((function(){var n=c((function(){return o(j())}),100);return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[]),e}var P=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,t=S();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 A(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 E(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}A("mousedown",(function(n){e(n)||(n.preventDefault(),n.stopPropagation())}),{enabled:t}),A("click",(function(r){e(r)||(r.stopPropagation(),n())}),{options:{capture:!0},enabled:t})}var C=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 T(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 V=function(n,r){return A("keydown",(function(r){return function(n,r){27===n.keyCode&&(n.stopImmediatePropagation(),r())}(r,n)}),r)};function x(){var n=h(t({}),2)[1];return i((function(){return n({})}),[])}function I(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 k(n,r){var t=i((function(n,r){Array.isArray(n)?n.forEach(t):"function"==typeof n?n(r):n&&(n.current=r)}),[]);return I(i((function(r){return t(n,r)}),[n,t]),{initialValue:r})}var D=0;function M(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(D+=1)}),[u,o]),e||"".concat(null!=o?o:"lg","-").concat(u)}({id:n.id,prefix:e})}var R=function(){return("undefined"==typeof window?r:u).apply(void 0,arguments)};function L(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 B(n){var r=o();return void 0!==r.current&&v(r.current,n)||(r.current=n),r.current}function U(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)}),[]),A("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 z(n){var t=o();return r((function(){t.current=n})),t.current}function H(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 W(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,P as useAvailableSpace,E as useBackdropClick,C as useControlledValue,T as useDynamicRefs,V as useEscapeKey,A as useEventListener,x as useForceRerender,k as useForwardedRef,M as useIdAllocator,R as useIsomorphicLayoutEffect,L as useMutationObserver,B as useObjectDependency,I as useObservedRef,U as usePoller,z as usePrevious,H as useStateRef,W as useValidation,S as useViewportSize}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(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"],t):t((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,t,n,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 t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var a=c(t),f=i(n),l=i(r),s=i(u);function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function v(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach((function(t){y(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function p(e){return p="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},p(e)}function y(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,u,i,c=[],a=!0,f=!1;try{if(u=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;a=!1}else for(;!(a=(r=u.call(n)).done)&&(c.push(r.value),c.length!==t);a=!0);}catch(e){f=!0,o=e}finally{try{if(!a&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(f)throw o}}return c}}(e,t)||h(e,t)||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 g(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||h(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 h(e,t){if(e){if("string"==typeof e)return g(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?g(e,t):void 0}}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function w(){return{width:window.innerWidth,height:window.innerHeight}}function O(){var e=b(t.useState(null),2),n=e[0],r=e[1];return t.useEffect((function(){r(w());var e=f.default((function(){return r(w())}),100);return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),n}function E(e,n){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=t.useRef((function(){}));t.useEffect((function(){l.current=n}),[n]),t.useEffect((function(){if(!1!==i){if("once"===i||!0===i){var t=function(e){l.current(e)},n=v(v({},o),{},{once:"once"===i});return(null!=f?f:document).addEventListener(e,t,n),function(){(null!=f?f:document).removeEventListener(e,t,n)}}console.error("Received value of type ".concat(p(i)," for property `enabled`. Expected a boolean."))}}),a)}function S(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.initialValue,o=n.deps,u=void 0===o?[]:o,i=t.useRef(r);return t.useMemo((function(){return{get current(){return i.current},set current(t){i.current=t,e(t)}}}),[e,i].concat(m(u)))}var j=0;e.useAutoScroll=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;t.useEffect((function(){if(e&&e.current&&n&&n.current){var t=e.current.offsetTop,o=n.current,u=o.scrollTop;(t>o.offsetHeight||t<u)&&n.current.scrollTo({top:t-r,behavior:"smooth"})}}),[n,e,r])},e.useAvailableSpace=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,r=O();return t.useMemo((function(){if(r&&e&&e.current){var t=e.current.getBoundingClientRect(),o=t.top,u=t.bottom;return Math.max(r.height-u,o)-n}}),[r,e,n])},e.useBackdropClick=function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];function r(e){var n,r=e.target;return Array.isArray(t)?t.some((function(e){var t;return null===(t=e.current)||void 0===t?void 0:t.contains(r)})):(null===(n=t.current)||void 0===n?void 0:n.contains(r))||!1}E("mousedown",(function(e){r(e)||(e.preventDefault(),e.stopPropagation())}),{enabled:n}),E("click",(function(t){r(t)||(t.stopPropagation(),e())}),{options:{capture:!0},enabled:n})},e.useControlledValue=function(e,n,r){var u=t.useMemo((function(){return!l.default(e)}),[]),i=b(t.useState(r),2),c=i[0],a=i[1],f=function(e){null==n||n(e),u||a(e.target.value)};return t.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,t){if(t.current){t.current.value=e;var n=o.createSyntheticEvent(new Event("change",{cancelable:!0,bubbles:!0}),t.current);f(n)}}}},e.useDynamicRefs=function(e){var t=null==e?void 0:e.prefix;return a.useMemo((function(){var e=function(e){return function(t){if(t){if(e.get(t))return e.get(t);var n=a.createRef();return e.set(t,n),n}o.consoleOnce.error("`useDynamicRefs`: Cannot get ref without key")}}(new Map);return e}),[t])},e.useEscapeKey=function(e,t){return E("keydown",(function(t){return function(e,t){27===e.keyCode&&(e.stopImmediatePropagation(),t())}(t,e)}),t)},e.useEventListener=E,e.useForceRerender=function(){var e=b(t.useState({}),2)[1];return t.useCallback((function(){return e({})}),[])},e.useForwardedRef=function(e,n){var r=t.useCallback((function(e,t){Array.isArray(e)?e.forEach(r):"function"==typeof e?e(t):e&&(e.current=t)}),[]);return S(t.useCallback((function(t){return r(e,t)}),[e,r]),{initialValue:n})},e.useIdAllocator=function(e){var n=e.prefix;return function(e){var n=e.id,r=e.prefix,o=b(t.useState(n),2),u=o[0],i=o[1];return t.useEffect((function(){null==u&&i(j+=1)}),[u,r]),n||"".concat(null!=r?r:"lg","-").concat(u)}({id:e.id,prefix:n})},e.useIsomorphicLayoutEffect=function(){return("undefined"==typeof window?t.useEffect:t.useLayoutEffect).apply(void 0,arguments)},e.useMutationObserver=function(e,n,r){var o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=b(t.useState(),2),i=u[0],c=u[1];return t.useEffect((function(){if(o){var t=new MutationObserver((function(){c(r.apply(void 0,arguments))}));return e&&t.observe(e,n),function(){return t.disconnect()}}}),[e,n,r,o]),i},e.useObjectDependency=function(e){var n=t.useRef();return void 0!==n.current&&s.default(n.current,e)||(n.current=e),n.current},e.useObservedRef=S,e.usePoller=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.interval,o=void 0===r?3e4:r,u=n.immediate,i=void 0===u||u,c=n.enabled,a=void 0===c||c,f=t.useRef(),l=function(){var e=function(){return"visible"===document.visibilityState},n=b(t.useState(!0),2),r=n[0],o=n[1];return t.useEffect((function(){o(e)}),[]),E("visibilitychange",(function(){o(e)})),r}()&&a;t.useEffect((function(){f.current=e})),t.useEffect((function(){var e;if(l)return i?r():t(),n;function t(){n(),e=setTimeout(r,o)}function n(){clearTimeout(e)}function r(){var e;Promise.resolve(null===(e=f.current)||void 0===e?void 0:e.call(f)).finally(t)}}),[o,i,l])},e.usePrevious=function(e){var n=t.useRef();return t.useEffect((function(){n.current=e})),n.current},e.useStateRef=function(e){var n=b(t.useState(e),2),r=n[0],o=n[1],u=t.useRef(r);return[r,t.useCallback((function(e){o(e),u.current=e}),[o]),t.useCallback((function(){return u.current}),[])]},e.useValidation=function(e){var n=b(t.useState(!1),2),r=n[0],o=n[1];return l.default(e)||"function"!=typeof e?{onBlur:function(){},onChange:function(){}}:{onBlur:function(t){o(!0),null==e||e(t.target.value)},onChange:function(t){r&&(null==e||e(t.target.value))}}},e.useViewportSize=O})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(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"],t):t((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,t,n,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 t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var a=c(t),f=i(n),l=i(r),s=i(u);function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function v(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach((function(t){b(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function p(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof t?t:t+""}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,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,u,i,c=[],a=!0,f=!1;try{if(u=(n=n.call(e)).next,0===t);else for(;!(a=(r=u.call(n)).done)&&(c.push(r.value),c.length!==t);a=!0);}catch(e){f=!0,o=e}finally{try{if(!a&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(f)throw o}}return c}}(e,t)||g(e,t)||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,t){if(e){if("string"==typeof e)return w(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?w(e,t):void 0}}function w(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function E(){return{width:window.innerWidth,height:window.innerHeight}}function O(){var e=h(t.useState(E()),2),n=e[0],r=e[1];return t.useEffect((function(){var e=f.default((function(){return r(E())}),100);return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),n}function S(e,n){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=t.useRef((function(){}));t.useEffect((function(){l.current=n}),[n]),t.useEffect((function(){if(!1!==i){if("once"===i||!0===i){var t=function(e){l.current(e)},n=v(v({},o),{},{once:"once"===i});return(null!=f?f:document).addEventListener(e,t,n),function(){(null!=f?f:document).removeEventListener(e,t,n)}}console.error("Received value of type ".concat(y(i)," for property `enabled`. Expected a boolean."))}}),a)}function j(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.initialValue,o=n.deps,u=void 0===o?[]:o,i=t.useRef(r);return t.useMemo((function(){return{get current(){return i.current},set current(t){i.current=t,e(t)}}}),[e,i].concat(m(u)))}var P=0;e.useAutoScroll=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;t.useEffect((function(){if(e&&e.current&&n&&n.current){var t=e.current.offsetTop,o=n.current,u=o.scrollTop;(t>o.offsetHeight||t<u)&&n.current.scrollTo({top:t-r,behavior:"smooth"})}}),[n,e,r])},e.useAvailableSpace=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,r=O();return t.useMemo((function(){if(r&&e&&e.current){var t=e.current.getBoundingClientRect(),o=t.top,u=t.bottom;return Math.max(r.height-u,o)-n}}),[r,e,n])},e.useBackdropClick=function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];function r(e){var n,r=e.target;return Array.isArray(t)?t.some((function(e){var t;return null===(t=e.current)||void 0===t?void 0:t.contains(r)})):(null===(n=t.current)||void 0===n?void 0:n.contains(r))||!1}S("mousedown",(function(e){r(e)||(e.preventDefault(),e.stopPropagation())}),{enabled:n}),S("click",(function(t){r(t)||(t.stopPropagation(),e())}),{options:{capture:!0},enabled:n})},e.useControlledValue=function(e,n,r){var u=t.useMemo((function(){return!l.default(e)}),[]),i=h(t.useState(r),2),c=i[0],a=i[1],f=function(e){null==n||n(e),u||a(e.target.value)};return t.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,t){if(t.current){t.current.value=e;var n=o.createSyntheticEvent(new Event("change",{cancelable:!0,bubbles:!0}),t.current);f(n)}}}},e.useDynamicRefs=function(e){var t=null==e?void 0:e.prefix;return a.useMemo((function(){var e=function(e){return function(t){if(t){if(e.get(t))return e.get(t);var n=a.createRef();return e.set(t,n),n}o.consoleOnce.error("`useDynamicRefs`: Cannot get ref without key")}}(new Map);return e}),t?[t]:[])},e.useEscapeKey=function(e,t){return S("keydown",(function(t){return function(e,t){27===e.keyCode&&(e.stopImmediatePropagation(),t())}(t,e)}),t)},e.useEventListener=S,e.useForceRerender=function(){var e=h(t.useState({}),2)[1];return t.useCallback((function(){return e({})}),[])},e.useForwardedRef=function(e,n){var r=t.useCallback((function(e,t){Array.isArray(e)?e.forEach(r):"function"==typeof e?e(t):e&&(e.current=t)}),[]);return j(t.useCallback((function(t){return r(e,t)}),[e,r]),{initialValue:n})},e.useIdAllocator=function(e){var n=e.prefix;return function(e){var n=e.id,r=e.prefix,o=h(t.useState(n),2),u=o[0],i=o[1];return t.useEffect((function(){null==u&&i(P+=1)}),[u,r]),n||"".concat(null!=r?r:"lg","-").concat(u)}({id:e.id,prefix:n})},e.useIsomorphicLayoutEffect=function(){return("undefined"==typeof window?t.useEffect:t.useLayoutEffect).apply(void 0,arguments)},e.useMutationObserver=function(e,n,r){var o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=h(t.useState(),2),i=u[0],c=u[1];return t.useEffect((function(){if(o){var t=new MutationObserver((function(){c(r.apply(void 0,arguments))}));return e&&t.observe(e,n),function(){return t.disconnect()}}}),[e,n,r,o]),i},e.useObjectDependency=function(e){var n=t.useRef();return void 0!==n.current&&s.default(n.current,e)||(n.current=e),n.current},e.useObservedRef=j,e.usePoller=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.interval,o=void 0===r?3e4:r,u=n.immediate,i=void 0===u||u,c=n.enabled,a=void 0===c||c,f=t.useRef(),l=function(){var e=function(){return"visible"===document.visibilityState},n=h(t.useState(!0),2),r=n[0],o=n[1];return t.useEffect((function(){o(e)}),[]),S("visibilitychange",(function(){o(e)})),r}()&&a;t.useEffect((function(){f.current=e})),t.useEffect((function(){var e;if(l)return i?r():t(),n;function t(){n(),e=setTimeout(r,o)}function n(){clearTimeout(e)}function r(){var e;Promise.resolve(null===(e=f.current)||void 0===e?void 0:e.call(f)).finally(t)}}),[o,i,l])},e.usePrevious=function(e){var n=t.useRef();return t.useEffect((function(){n.current=e})),n.current},e.useStateRef=function(e){var n=h(t.useState(e),2),r=n[0],o=n[1],u=t.useRef(r);return[r,t.useCallback((function(e){o(e),u.current=e}),[o]),t.useCallback((function(){return u.current}),[])]},e.useValidation=function(e){var n=h(t.useState(!1),2),r=n[0],o=n[1];return l.default(e)||"function"!=typeof e?{onBlur:function(){},onChange:function(){}}:{onBlur:function(t){o(!0),null==e||e(t.target.value)},onChange:function(t){r&&(null==e||e(t.target.value))}}},e.useViewportSize=O})); | ||
//# sourceMappingURL=index.js.map |
@@ -6,3 +6,3 @@ /** | ||
export interface UseDynamicRefsArgs { | ||
prefix: string; | ||
prefix?: string; | ||
} | ||
@@ -9,0 +9,0 @@ /** The Map type for a given ref object */ |
@@ -5,4 +5,4 @@ interface ViewportSize { | ||
} | ||
export default function useViewportSize(): ViewportSize | null; | ||
export default function useViewportSize(): ViewportSize; | ||
export {}; | ||
//# sourceMappingURL=useViewportSize.d.ts.map |
{ | ||
"name": "@leafygreen-ui/hooks", | ||
"version": "8.1.3", | ||
"version": "8.1.4", | ||
"description": "LeafyGreen UI Kit Custom Hooks", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -10,3 +10,3 @@ /** | ||
export interface UseDynamicRefsArgs { | ||
prefix: string; | ||
prefix?: string; | ||
} | ||
@@ -57,10 +57,13 @@ | ||
const getRef = React.useMemo(() => { | ||
const refMap: RefMap<T> = new Map<string, React.RefObject<T>>(); | ||
const getter = getGetRef<T>(refMap); | ||
return getter; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [prefix]); | ||
const getRef = React.useMemo( | ||
() => { | ||
const refMap: RefMap<T> = new Map<string, React.RefObject<T>>(); | ||
const getter = getGetRef<T>(refMap); | ||
return getter; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, | ||
prefix ? [prefix] : [], | ||
); | ||
return getRef; | ||
} |
@@ -16,10 +16,8 @@ import { useEffect, useState } from 'react'; | ||
export default function useViewportSize(): ViewportSize | null { | ||
const [viewportSize, setViewportUpdateVal] = useState<ViewportSize | null>( | ||
null, | ||
export default function useViewportSize(): ViewportSize { | ||
const [viewportSize, setViewportUpdateVal] = useState<ViewportSize>( | ||
getViewportSize(), | ||
); | ||
useEffect(() => { | ||
setViewportUpdateVal(getViewportSize()); | ||
const calcResize = debounce( | ||
@@ -26,0 +24,0 @@ () => setViewportUpdateVal(getViewportSize()), |
@@ -13,3 +13,3 @@ [ | ||
"description": "", | ||
"required": true, | ||
"required": false, | ||
"type": { | ||
@@ -16,0 +16,0 @@ "name": "string" |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
177700
1872