@leafygreen-ui/hooks
Advanced tools
Comparing version 7.7.2 to 7.7.3
# @leafygreen-ui/hooks | ||
## 7.7.3 | ||
### Patch Changes | ||
- a3a52e131: Removes call to use React 18's useId hook if found | ||
## 7.7.2 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
import*as n from"react";import r,{useEffect as t,useState as e,useMemo as o,useRef as i,useCallback as u,useLayoutEffect as c}from"react";import a from"lodash/debounce";import f from"lodash/isUndefined";import l from"lodash/isEqual";var v=function(n,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;t((function(){if(n&&n.current&&r&&r.current){var t=n.current.offsetTop,o=r.current,i=o.scrollTop;(t>o.offsetHeight||t<i)&&r.current.scrollTo({top:t-e,behavior:"smooth"})}}),[r,n,e])};function d(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 s(n){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?d(Object(t),!0).forEach((function(r){y(n,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):d(Object(t)).forEach((function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))}))}return n}function p(n){return p="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},p(n)}function y(n,r,t){return 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)return;var e,o,i=[],u=!0,c=!1;try{for(t=t.call(n);!(u=(e=t.next()).done)&&(i.push(e.value),!r||i.length!==r);u=!0);}catch(n){c=!0,o=n}finally{try{u||null==t.return||t.return()}finally{if(c)throw o}}return i}(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 b(n){return function(n){if(Array.isArray(n))return g(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 g(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)?g(n,r):void 0}}function g(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 w(){return{width:window.innerWidth,height:window.innerHeight}}function O(){var n=m(e(null),2),r=n[0],o=n[1];return t((function(){o(w());var n=a((function(){return o(w())}),100);return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[]),r}var j=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,t=O();return o((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 S(n,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=e.options,u=e.enabled,c=void 0===u||u,a=e.dependencies,f=void 0===a?[c,n]:a,l=e.element,v=i((function(){}));t((function(){v.current=r}),[r]),t((function(){if(!1!==c){if("once"===c||!0===c){var r=function(n){v.current(n)},t=s(s({},o),{},{once:"once"===c});return(null!=l?l:document).addEventListener(n,r,t),function(){(null!=l?l:document).removeEventListener(n,r,t)}}console.error("Received value of type ".concat(p(c)," for property `enabled`. Expected a boolean."))}}),f)}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}S("mousedown",(function(n){e(n)||(n.preventDefault(),n.stopPropagation())}),{enabled:t}),S("click",(function(r){e(r)||(r.stopPropagation(),n())}),{options:{capture:!0},enabled:t})}var P=function(n,r){var o=!f(n),i=m(e(null!=n?n:""),2),u=i[0],c=i[1];t((function(){f(n)||c(n)}),[n]);return{isControlled:o,value:u,handleChange:function(n){null==r||r(n),o||c(n.target.value)},setInternalValue:c}},E=new Map;function I(r){return function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";function t(t){if(t){var e=r+"-"+t;if(E.get(e))return E.get(e);var o=n.createRef();return E.set(e,o),o}console.error("useDynamicRefs: Cannot get ref without key")}return t}(r.prefix)}var x=function(n,r){return S("keydown",(function(r){return function(n,r){27===n.keyCode&&(n.stopImmediatePropagation(),r())}(r,n)}),r)};function C(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=r.initialValue,e=r.deps,u=void 0===e?[]:e,c=i(t);return o((function(){return{get current(){return c.current},set current(r){c.current=r,n(r)}}}),[n,c].concat(b(u)))}function T(n,r){var t=u((function(n,r){Array.isArray(n)?n.forEach(t):"function"==typeof n?n(r):n&&(n.current=r)}),[]);return C(u((function(r){return t(n,r)}),[n,t]),{initialValue:r})}var D=0;var k=r.useId;function L(n){var r=n.prefix,o=n.id;if(void 0!==k){var i=k();return null!=o?o:i}return function(n){var r=n.id,o=n.prefix,i=m(e(r),2),u=i[0],c=i[1];return t((function(){null==u&&c(D+=1)}),[u,o]),r||"".concat(null!=o?o:"lg","-").concat(u)}({id:o,prefix:r})}var M=function(){var n="undefined"==typeof window?t:c;return n.apply(void 0,arguments)};function R(n,r,o){var i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=e(),c=m(u,2),a=c[0],f=c[1];return t((function(){if(i){var t=new MutationObserver((function(){f(o.apply(void 0,arguments))}));return n&&t.observe(n,r),function(){return t.disconnect()}}}),[n,r,o,i]),a}function B(n){var r=i();return void 0!==r.current&&l(r.current,n)||(r.current=n),r.current}function V(){var n=function(){return"visible"===document.visibilityState},r=m(e(!0),2),o=r[0],i=r[1];return t((function(){i(n)}),[]),S("visibilitychange",(function(){i(n)})),o}function z(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=r.interval,o=void 0===e?3e4:e,u=r.immediate,c=void 0===u||u,a=r.enabled,f=void 0===a||a,l=i(),v=V(),d=v&&f;t((function(){l.current=n})),t((function(){var n;if(d)return c?e():r(),t;function r(){t(),n=setTimeout(e,o)}function t(){clearTimeout(n)}function e(){var n;Promise.resolve(null===(n=l.current)||void 0===n?void 0:n.call(l)).finally(r)}}),[o,c,d])}function H(n){var r=i();return t((function(){r.current=n})),r.current}function U(n){var r=m(e(n),2),t=r[0],o=r[1],u=i(t);return[t,function(n){o(n),u.current=n},function(){return u.current}]}function q(n){var r=m(e(!1),2),t=r[0],o=r[1];if(f(n)||"function"!=typeof n)return{onBlur:function(){},onChange:function(){}};return{onBlur:function(r){o(!0),null==n||n(r.target.value)},onChange:function(r){t&&(null==n||n(r.target.value))}}}export{v as useAutoScroll,j as useAvailableSpace,A as useBackdropClick,P as useControlledValue,I as useDynamicRefs,x as useEscapeKey,S as useEventListener,T as useForwardedRef,L as useIdAllocator,M as useIsomorphicLayoutEffect,R as useMutationObserver,B as useObjectDependency,C as useObservedRef,z as usePoller,H as usePrevious,U as useStateRef,q as useValidation,O 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 f from"lodash/isEqual";var l=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 v(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 d(n){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?v(Object(t),!0).forEach((function(r){p(n,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):v(Object(t)).forEach((function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))}))}return n}function s(n){return s="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},s(n)}function p(n,r,t){return r in n?Object.defineProperty(n,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[r]=t,n}function y(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)return;var e,o,i=[],u=!0,c=!1;try{for(t=t.call(n);!(u=(e=t.next()).done)&&(i.push(e.value),!r||i.length!==r);u=!0);}catch(n){c=!0,o=n}finally{try{u||null==t.return||t.return()}finally{if(c)throw o}}return i}(n,r)||b(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 m(n){return function(n){if(Array.isArray(n))return h(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||b(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 b(n,r){if(n){if("string"==typeof n)return h(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)?h(n,r):void 0}}function h(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 g(){return{width:window.innerWidth,height:window.innerHeight}}function w(){var n=y(t(null),2),e=n[0],o=n[1];return r((function(){o(g());var n=c((function(){return o(g())}),100);return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[]),e}var O=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,t=w();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 j(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,f=void 0===a?[c,n]:a,l=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=d(d({},i),{},{once:"once"===c});return(null!=l?l:document).addEventListener(n,r,t),function(){(null!=l?l:document).removeEventListener(n,r,t)}}console.error("Received value of type ".concat(s(c)," for property `enabled`. Expected a boolean."))}}),f)}function S(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}j("mousedown",(function(n){e(n)||(n.preventDefault(),n.stopPropagation())}),{enabled:t}),j("click",(function(r){e(r)||(r.stopPropagation(),n())}),{options:{capture:!0},enabled:t})}var A=function(n,e){var o=!a(n),i=y(t(null!=n?n:""),2),u=i[0],c=i[1];r((function(){a(n)||c(n)}),[n]);return{isControlled:o,value:u,handleChange:function(n){null==e||e(n),o||c(n.target.value)},setInternalValue:c}},P=new Map;function E(r){return function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";function t(t){if(t){var e=r+"-"+t;if(P.get(e))return P.get(e);var o=n.createRef();return P.set(e,o),o}console.error("useDynamicRefs: Cannot get ref without key")}return t}(r.prefix)}var x=function(n,r){return j("keydown",(function(r){return function(n,r){27===n.keyCode&&(n.stopImmediatePropagation(),r())}(r,n)}),r)};function C(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(m(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 C(i((function(r){return t(n,r)}),[n,t]),{initialValue:r})}var T=0;function D(n){var e=n.prefix;return function(n){var e=n.id,o=n.prefix,i=y(t(e),2),u=i[0],c=i[1];return r((function(){null==u&&c(T+=1)}),[u,o]),e||"".concat(null!=o?o:"lg","-").concat(u)}({id:n.id,prefix:e})}var k=function(){var n="undefined"==typeof window?r:u;return n.apply(void 0,arguments)};function L(n,e,o){var i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=t(),c=y(u,2),a=c[0],f=c[1];return r((function(){if(i){var r=new MutationObserver((function(){f(o.apply(void 0,arguments))}));return n&&r.observe(n,e),function(){return r.disconnect()}}}),[n,e,o,i]),a}function M(n){var r=o();return void 0!==r.current&&f(r.current,n)||(r.current=n),r.current}function R(){var n=function(){return"visible"===document.visibilityState},e=y(t(!0),2),o=e[0],i=e[1];return r((function(){i(n)}),[]),j("visibilitychange",(function(){i(n)})),o}function B(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=t.interval,i=void 0===e?3e4:e,u=t.immediate,c=void 0===u||u,a=t.enabled,f=void 0===a||a,l=o(),v=R(),d=v&&f;r((function(){l.current=n})),r((function(){var n;if(d)return c?e():r(),t;function r(){t(),n=setTimeout(e,i)}function t(){clearTimeout(n)}function e(){var n;Promise.resolve(null===(n=l.current)||void 0===n?void 0:n.call(l)).finally(r)}}),[i,c,d])}function V(n){var t=o();return r((function(){t.current=n})),t.current}function z(n){var r=y(t(n),2),e=r[0],i=r[1],u=o(e);return[e,function(n){i(n),u.current=n},function(){return u.current}]}function H(n){var r=y(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{l as useAutoScroll,O as useAvailableSpace,S as useBackdropClick,A as useControlledValue,E as useDynamicRefs,x as useEscapeKey,j as useEventListener,I as useForwardedRef,D as useIdAllocator,k as useIsomorphicLayoutEffect,L as useMutationObserver,M as useObjectDependency,C as useObservedRef,B as usePoller,V as usePrevious,z as useStateRef,H as useValidation,w 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("lodash/isEqual")):"function"==typeof define&&define.amd?define(["exports","react","lodash/debounce","lodash/isUndefined","lodash/isEqual"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@leafygreen-ui/hooks"]={},e.React,e.debounce,e.isUndefined,e.isEqual)}(this,(function(e,t,n,r,o){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)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 c=i(t),f=u(t),a=u(n),l=u(r),s=u(o);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 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)return;var r,o,u=[],i=!0,c=!1;try{for(n=n.call(e);!(i=(r=n.next()).done)&&(u.push(r.value),!t||u.length!==t);i=!0);}catch(e){c=!0,o=e}finally{try{i||null==n.return||n.return()}finally{if(c)throw o}}return u}(e,t)||m(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 h(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)||m(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 m(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=a.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,f=void 0===c?[i,e]:c,a=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!=a?a:document).addEventListener(e,t,n),function(){(null!=a?a:document).removeEventListener(e,t,n)}}console.error("Received value of type ".concat(p(i)," for property `enabled`. Expected a boolean."))}}),f)}var S=new Map;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(h(u)))}var P=0;var A=f.default.useId;function R(){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}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){var r=!l.default(e),o=b(t.useState(null!=e?e:""),2),u=o[0],i=o[1];t.useEffect((function(){l.default(e)||i(e)}),[e]);return{isControlled:r,value:u,handleChange:function(e){null==n||n(e),r||i(e.target.value)},setInternalValue:i}},e.useDynamicRefs=function(e){return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";function t(t){if(t){var n=e+"-"+t;if(S.get(n))return S.get(n);var r=c.createRef();return S.set(n,r),r}console.error("useDynamicRefs: Cannot get ref without key")}return t}(e.prefix)},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.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,r=e.id;if(void 0!==A){var o=A();return null!=r?r:o}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(P+=1)}),[u,r]),n||"".concat(null!=r?r:"lg","-").concat(u)}({id:r,prefix:n})},e.useIsomorphicLayoutEffect=function(){var e="undefined"==typeof window?t.useEffect:t.useLayoutEffect;return e.apply(void 0,arguments)},e.useMutationObserver=function(e,n,r){var o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=t.useState(),i=b(u,2),c=i[0],f=i[1];return t.useEffect((function(){if(o){var t=new MutationObserver((function(){f(r.apply(void 0,arguments))}));return e&&t.observe(e,n),function(){return t.disconnect()}}}),[e,n,r,o]),c},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,f=void 0===c||c,a=t.useRef(),l=R(),s=l&&f;t.useEffect((function(){a.current=e})),t.useEffect((function(){var e;if(s)return i?r():t(),n;function t(){n(),e=setTimeout(r,o)}function n(){clearTimeout(e)}function r(){var e;Promise.resolve(null===(e=a.current)||void 0===e?void 0:e.call(a)).finally(t)}}),[o,i,s])},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,function(e){o(e),u.current=e},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,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("lodash/debounce"),require("lodash/isUndefined"),require("lodash/isEqual")):"function"==typeof define&&define.amd?define(["exports","react","lodash/debounce","lodash/isUndefined","lodash/isEqual"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@leafygreen-ui/hooks"]={},e.React,e.debounce,e.isUndefined,e.isEqual)}(this,(function(e,t,n,r,o){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)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 c=i(t),f=u(n),a=u(r),l=u(o);function s(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 d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?s(Object(n),!0).forEach((function(t){p(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function v(e){return v="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},v(e)}function p(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(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)return;var r,o,u=[],i=!0,c=!1;try{for(n=n.call(e);!(i=(r=n.next()).done)&&(u.push(r.value),!t||u.length!==t);i=!0);}catch(e){c=!0,o=e}finally{try{i||null==n.return||n.return()}finally{if(c)throw o}}return u}(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 b(e){return function(e){if(Array.isArray(e))return m(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 m(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)?m(e,t):void 0}}function m(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 g(){return{width:window.innerWidth,height:window.innerHeight}}function w(){var e=y(t.useState(null),2),n=e[0],r=e[1];return t.useEffect((function(){r(g());var e=f.default((function(){return r(g())}),100);return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),n}function O(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,f=void 0===c?[i,e]:c,a=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=d(d({},o),{},{once:"once"===i});return(null!=a?a:document).addEventListener(e,t,n),function(){(null!=a?a:document).removeEventListener(e,t,n)}}console.error("Received value of type ".concat(v(i)," for property `enabled`. Expected a boolean."))}}),f)}var E=new Map;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(b(u)))}var j=0;function P(){var e=function(){return"visible"===document.visibilityState},n=y(t.useState(!0),2),r=n[0],o=n[1];return t.useEffect((function(){o(e)}),[]),O("visibilitychange",(function(){o(e)})),r}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=w();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}O("mousedown",(function(e){r(e)||(e.preventDefault(),e.stopPropagation())}),{enabled:n}),O("click",(function(t){r(t)||(t.stopPropagation(),e())}),{options:{capture:!0},enabled:n})},e.useControlledValue=function(e,n){var r=!a.default(e),o=y(t.useState(null!=e?e:""),2),u=o[0],i=o[1];t.useEffect((function(){a.default(e)||i(e)}),[e]);return{isControlled:r,value:u,handleChange:function(e){null==n||n(e),r||i(e.target.value)},setInternalValue:i}},e.useDynamicRefs=function(e){return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";function t(t){if(t){var n=e+"-"+t;if(E.get(n))return E.get(n);var r=c.createRef();return E.set(n,r),r}console.error("useDynamicRefs: Cannot get ref without key")}return t}(e.prefix)},e.useEscapeKey=function(e,t){return O("keydown",(function(t){return function(e,t){27===e.keyCode&&(e.stopImmediatePropagation(),t())}(t,e)}),t)},e.useEventListener=O,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=y(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(){var e="undefined"==typeof window?t.useEffect:t.useLayoutEffect;return e.apply(void 0,arguments)},e.useMutationObserver=function(e,n,r){var o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=t.useState(),i=y(u,2),c=i[0],f=i[1];return t.useEffect((function(){if(o){var t=new MutationObserver((function(){f(r.apply(void 0,arguments))}));return e&&t.observe(e,n),function(){return t.disconnect()}}}),[e,n,r,o]),c},e.useObjectDependency=function(e){var n=t.useRef();return void 0!==n.current&&l.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,f=void 0===c||c,a=t.useRef(),l=P(),s=l&&f;t.useEffect((function(){a.current=e})),t.useEffect((function(){var e;if(s)return i?r():t(),n;function t(){n(),e=setTimeout(r,o)}function n(){clearTimeout(e)}function r(){var e;Promise.resolve(null===(e=a.current)||void 0===e?void 0:e.call(a)).finally(t)}}),[o,i,s])},e.usePrevious=function(e){var n=t.useRef();return t.useEffect((function(){n.current=e})),n.current},e.useStateRef=function(e){var n=y(t.useState(e),2),r=n[0],o=n[1],u=t.useRef(r);return[r,function(e){o(e),u.current=e},function(){return u.current}]},e.useValidation=function(e){var n=y(t.useState(!1),2),r=n[0],o=n[1];return a.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=w,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@leafygreen-ui/hooks", | ||
"version": "7.7.2", | ||
"version": "7.7.3", | ||
"description": "LeafyGreen UI Kit Custom Hooks", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
// Currently using Material UI useId hook until we can upgrade to React 18's useId | ||
// https://github.com/mui/material-ui/blob/master/packages/mui-utils/src/useId.ts | ||
import React, { useEffect, useState } from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
@@ -31,15 +31,5 @@ interface Params { | ||
// eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814 | ||
const maybeReactUseId: undefined | (() => string) = (React as any)[ | ||
'useId' + '' | ||
]; | ||
export default function useId({ prefix, id: idOverride }: Params): string { | ||
if (maybeReactUseId !== undefined) { | ||
const reactId = maybeReactUseId(); | ||
return idOverride ?? reactId; | ||
} | ||
// eslint-disable-next-line react-hooks/rules-of-hooks -- `React.useId` is invariant at runtime. | ||
return useGlobalId({ id: idOverride, prefix }); | ||
} |
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
183078
1364