@reach/utils
Advanced tools
Comparing version 0.11.1 to 0.11.2
@@ -148,3 +148,3 @@ import React from "react"; | ||
*/ | ||
export declare function isRightClick(nativeEvent: MouseEvent): boolean; | ||
export declare function isRightClick(nativeEvent: MouseEvent | PointerEvent | TouchEvent): boolean; | ||
/** | ||
@@ -227,2 +227,6 @@ * Checks whether or not a value is a string. | ||
/** | ||
* Forces a re-render, similar to `forceUpdate` in class components. | ||
*/ | ||
export declare function useForceUpdate(): () => void; | ||
/** | ||
* Passes or assigns a value to multiple refs (typically a DOM node). Useful for | ||
@@ -229,0 +233,0 @@ * dealing with components that need an explicit ref for DOM calculations but |
@@ -270,3 +270,3 @@ 'use strict'; | ||
function isRightClick(nativeEvent) { | ||
return nativeEvent.which === 3 || nativeEvent.button === 2; | ||
return "which" in nativeEvent ? nativeEvent.which === 3 : "button" in nativeEvent ? nativeEvent.button === 2 : false; | ||
} | ||
@@ -511,2 +511,14 @@ /** | ||
/** | ||
* Forces a re-render, similar to `forceUpdate` in class components. | ||
*/ | ||
function useForceUpdate() { | ||
var _useState2 = React.useState(Object.create(null)), | ||
dispatch = _useState2[1]; | ||
return React.useCallback(function () { | ||
dispatch(Object.create(null)); | ||
}, []); | ||
} | ||
/** | ||
* Passes or assigns a value to multiple refs (typically a DOM node). Useful for | ||
@@ -650,2 +662,3 @@ * dealing with components that need an explicit ref for DOM calculations but | ||
exports.useFocusChange = useFocusChange; | ||
exports.useForceUpdate = useForceUpdate; | ||
exports.useForkedRef = useForkedRef; | ||
@@ -652,0 +665,0 @@ exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("warning");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e),o=n(t),u=l()?r.default.useLayoutEffect:r.default.useEffect,i=w,c="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();function f(e,t){if(null!=e)if(p(e))e(t);else try{e.current=t}catch(n){throw new Error('Cannot assign value "'+t+'" to ref "'+e+'"')}}function l(){return!("undefined"==typeof window||!window.document||!window.document.createElement)}function s(e){return e&&e.ownerDocument?e.ownerDocument:l()?document:null}function a(e){var t=e?s(e):null;return t?t.defaultView||window:null}function d(e){return"boolean"==typeof e}function p(e){return!(!e||"[object Function]"!={}.toString.call(e))}function w(){}var m=w,v=w,x=w;Object.defineProperty(exports,"warning",{enumerable:!0,get:function(){return o.default}}),exports.assignRef=f,exports.boolOrBoolString=function(e){return"true"===e||!!d(e)&&e},exports.canUseDOM=l,exports.checkStyles=i,exports.cloneValidElement=function(t,n){for(var r=arguments.length,o=new Array(r>2?r-2:0),u=2;u<r;u++)o[u-2]=arguments[u];return e.isValidElement(t)?e.cloneElement.apply(void 0,[t,n].concat(o)):t},exports.createNamedContext=function(t,n){var r=e.createContext(n);return r.displayName=t,r},exports.forwardRefWithAs=function(e){return r.default.forwardRef(e)},exports.getDocumentDimensions=function(e){if(!l())return{width:0,height:0};var t=e?s(e):document,n=e?a(e):window;return{width:t.documentElement.clientWidth||n.innerWidth,height:t.documentElement.clientHeight||n.innerHeight}},exports.getElementComputedStyle=function(e,t){var n=null,r=s(e);return e.currentStyle?n=e.currentStyle[t]:r&&r.defaultView&&p(r.defaultView.getComputedStyle)&&(n=r.defaultView.getComputedStyle(e,null).getPropertyValue(t)),n},exports.getOwnerDocument=s,exports.getOwnerWindow=a,exports.getScrollPosition=function(e){if(!l())return{scrollX:0,scrollY:0};var t=e?a(e):window;return{scrollX:t.scrollX,scrollY:t.scrollY}},exports.getScrollbarOffset=function(){try{if(window.innerWidth>document.documentElement.clientWidth)return window.innerWidth-document.documentElement.clientWidth}catch(e){}return 0},exports.isBoolean=d,exports.isFunction=p,exports.isNumber=function(e){return"number"==typeof e&&!isNaN(e)},exports.isRightClick=function(e){return 3===e.which||2===e.button},exports.isString=function(e){return"string"==typeof e},exports.makeId=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.filter((function(e){return null!=e})).join("--")},exports.memoWithAs=function(e,t){return r.default.memo(e,t)},exports.noop=w,exports.ponyfillGlobal=c,exports.stateToAttributeString=function(e){return String(e).replace(/([\s_]+)/g,"-").toLowerCase()},exports.useCallbackProp=function(t){var n=e.useRef(t);return e.useEffect((function(){n.current=t})),e.useCallback((function(){return n.current&&n.current.apply(n,arguments)}),[])},exports.useCheckStyles=v,exports.useConstant=function(e){var t=r.default.useRef();return t.current||(t.current={v:e()}),t.current.v},exports.useControlledState=function(t,n){var r=e.useRef(null!=t),o=e.useState(n),u=o[0],i=o[1],c=e.useCallback((function(e){r.current||i(e)}),[]);return[r.current?t:u,c]},exports.useControlledSwitchWarning=m,exports.useEventCallback=function(t){var n=e.useRef(t);return u((function(){n.current=t})),e.useCallback((function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];return n.current.apply(n,[e].concat(r))}),[])},exports.useEventListener=function(t,n,r){void 0===r&&(r=window);var o=e.useRef(n);e.useEffect((function(){o.current=n}),[n]),e.useEffect((function(){if(r&&r.addEventListener)return r.addEventListener(t,e),function(){r.removeEventListener(t,e)};function e(e){o.current(e)}}),[t,r])},exports.useFocusChange=function(t,n,r){void 0===t&&(t=console.log),void 0===n&&(n="focus"),void 0===r&&(r=document);var o=e.useRef(r.activeElement);e.useEffect((function(){function e(e){o.current!==r.activeElement&&(t(r.activeElement,o.current,e),o.current=r.activeElement)}return o.current=r.activeElement,r.addEventListener(n,e,!0),function(){r.removeEventListener(n,e)}}),[n,t,r])},exports.useForkedRef=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return e.useMemo((function(){return n.every((function(e){return null==e}))?null:function(e){n.forEach((function(t){f(t,e)}))}}),[].concat(n))},exports.useIsomorphicLayoutEffect=u,exports.usePrevious=function(t){var n=e.useRef(null);return e.useEffect((function(){n.current=t}),[t]),n.current},exports.useStateLogger=x,exports.useUpdateEffect=function(t,n){var r=e.useRef(!1);e.useEffect((function(){r.current?t():r.current=!0}),n)},exports.wrapEvent=function(e,t){return function(n){if(e&&e(n),!n.defaultPrevented)return t(n)}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("warning");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e),u=n(t),o=l()?r.default.useLayoutEffect:r.default.useEffect,c=w,i="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();function f(e,t){if(null!=e)if(p(e))e(t);else try{e.current=t}catch(n){throw new Error('Cannot assign value "'+t+'" to ref "'+e+'"')}}function l(){return!("undefined"==typeof window||!window.document||!window.document.createElement)}function s(e){return e&&e.ownerDocument?e.ownerDocument:l()?document:null}function a(e){var t=e?s(e):null;return t?t.defaultView||window:null}function d(e){return"boolean"==typeof e}function p(e){return!(!e||"[object Function]"!={}.toString.call(e))}function w(){}var v=w,m=w,x=w;Object.defineProperty(exports,"warning",{enumerable:!0,get:function(){return u.default}}),exports.assignRef=f,exports.boolOrBoolString=function(e){return"true"===e||!!d(e)&&e},exports.canUseDOM=l,exports.checkStyles=c,exports.cloneValidElement=function(t,n){for(var r=arguments.length,u=new Array(r>2?r-2:0),o=2;o<r;o++)u[o-2]=arguments[o];return e.isValidElement(t)?e.cloneElement.apply(void 0,[t,n].concat(u)):t},exports.createNamedContext=function(t,n){var r=e.createContext(n);return r.displayName=t,r},exports.forwardRefWithAs=function(e){return r.default.forwardRef(e)},exports.getDocumentDimensions=function(e){if(!l())return{width:0,height:0};var t=e?s(e):document,n=e?a(e):window;return{width:t.documentElement.clientWidth||n.innerWidth,height:t.documentElement.clientHeight||n.innerHeight}},exports.getElementComputedStyle=function(e,t){var n=null,r=s(e);return e.currentStyle?n=e.currentStyle[t]:r&&r.defaultView&&p(r.defaultView.getComputedStyle)&&(n=r.defaultView.getComputedStyle(e,null).getPropertyValue(t)),n},exports.getOwnerDocument=s,exports.getOwnerWindow=a,exports.getScrollPosition=function(e){if(!l())return{scrollX:0,scrollY:0};var t=e?a(e):window;return{scrollX:t.scrollX,scrollY:t.scrollY}},exports.getScrollbarOffset=function(){try{if(window.innerWidth>document.documentElement.clientWidth)return window.innerWidth-document.documentElement.clientWidth}catch(e){}return 0},exports.isBoolean=d,exports.isFunction=p,exports.isNumber=function(e){return"number"==typeof e&&!isNaN(e)},exports.isRightClick=function(e){return"which"in e?3===e.which:"button"in e&&2===e.button},exports.isString=function(e){return"string"==typeof e},exports.makeId=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.filter((function(e){return null!=e})).join("--")},exports.memoWithAs=function(e,t){return r.default.memo(e,t)},exports.noop=w,exports.ponyfillGlobal=i,exports.stateToAttributeString=function(e){return String(e).replace(/([\s_]+)/g,"-").toLowerCase()},exports.useCallbackProp=function(t){var n=e.useRef(t);return e.useEffect((function(){n.current=t})),e.useCallback((function(){return n.current&&n.current.apply(n,arguments)}),[])},exports.useCheckStyles=m,exports.useConstant=function(e){var t=r.default.useRef();return t.current||(t.current={v:e()}),t.current.v},exports.useControlledState=function(t,n){var r=e.useRef(null!=t),u=e.useState(n),o=u[0],c=u[1],i=e.useCallback((function(e){r.current||c(e)}),[]);return[r.current?t:o,i]},exports.useControlledSwitchWarning=v,exports.useEventCallback=function(t){var n=e.useRef(t);return o((function(){n.current=t})),e.useCallback((function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),u=1;u<t;u++)r[u-1]=arguments[u];return n.current.apply(n,[e].concat(r))}),[])},exports.useEventListener=function(t,n,r){void 0===r&&(r=window);var u=e.useRef(n);e.useEffect((function(){u.current=n}),[n]),e.useEffect((function(){if(r&&r.addEventListener)return r.addEventListener(t,e),function(){r.removeEventListener(t,e)};function e(e){u.current(e)}}),[t,r])},exports.useFocusChange=function(t,n,r){void 0===t&&(t=console.log),void 0===n&&(n="focus"),void 0===r&&(r=document);var u=e.useRef(r.activeElement);e.useEffect((function(){function e(e){u.current!==r.activeElement&&(t(r.activeElement,u.current,e),u.current=r.activeElement)}return u.current=r.activeElement,r.addEventListener(n,e,!0),function(){r.removeEventListener(n,e)}}),[n,t,r])},exports.useForceUpdate=function(){var t=e.useState(Object.create(null))[1];return e.useCallback((function(){t(Object.create(null))}),[])},exports.useForkedRef=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return e.useMemo((function(){return n.every((function(e){return null==e}))?null:function(e){n.forEach((function(t){f(t,e)}))}}),[].concat(n))},exports.useIsomorphicLayoutEffect=o,exports.usePrevious=function(t){var n=e.useRef(null);return e.useEffect((function(){n.current=t}),[t]),n.current},exports.useStateLogger=x,exports.useUpdateEffect=function(t,n){var r=e.useRef(!1);e.useEffect((function(){r.current?t():r.current=!0}),n)},exports.wrapEvent=function(e,t){return function(n){if(e&&e(n),!n.defaultPrevented)return t(n)}}; | ||
//# sourceMappingURL=utils.cjs.production.min.js.map |
@@ -261,3 +261,3 @@ import React, { isValidElement, cloneElement, createContext, useRef, useState, useCallback, useEffect, useMemo } from 'react'; | ||
function isRightClick(nativeEvent) { | ||
return nativeEvent.which === 3 || nativeEvent.button === 2; | ||
return "which" in nativeEvent ? nativeEvent.which === 3 : "button" in nativeEvent ? nativeEvent.button === 2 : false; | ||
} | ||
@@ -502,2 +502,14 @@ /** | ||
/** | ||
* Forces a re-render, similar to `forceUpdate` in class components. | ||
*/ | ||
function useForceUpdate() { | ||
var _useState2 = useState(Object.create(null)), | ||
dispatch = _useState2[1]; | ||
return useCallback(function () { | ||
dispatch(Object.create(null)); | ||
}, []); | ||
} | ||
/** | ||
* Passes or assigns a value to multiple refs (typically a DOM node). Useful for | ||
@@ -607,3 +619,3 @@ * dealing with components that need an explicit ref for DOM calculations but | ||
export { assignRef, boolOrBoolString, canUseDOM, checkStyles, cloneValidElement, createNamedContext, forwardRefWithAs, getDocumentDimensions, getElementComputedStyle, getOwnerDocument, getOwnerWindow, getScrollPosition, getScrollbarOffset, isBoolean, isFunction, isNumber, isRightClick, isString, makeId, memoWithAs, noop, ponyfillGlobal, stateToAttributeString, useCallbackProp, useCheckStyles, useConstant, useControlledState, useControlledSwitchWarning, useEventCallback, useEventListener, useFocusChange, useForkedRef, useIsomorphicLayoutEffect, usePrevious, useStateLogger, useUpdateEffect, wrapEvent }; | ||
export { assignRef, boolOrBoolString, canUseDOM, checkStyles, cloneValidElement, createNamedContext, forwardRefWithAs, getDocumentDimensions, getElementComputedStyle, getOwnerDocument, getOwnerWindow, getScrollPosition, getScrollbarOffset, isBoolean, isFunction, isNumber, isRightClick, isString, makeId, memoWithAs, noop, ponyfillGlobal, stateToAttributeString, useCallbackProp, useCheckStyles, useConstant, useControlledState, useControlledSwitchWarning, useEventCallback, useEventListener, useFocusChange, useForceUpdate, useForkedRef, useIsomorphicLayoutEffect, usePrevious, useStateLogger, useUpdateEffect, wrapEvent }; | ||
//# sourceMappingURL=utils.esm.js.map |
{ | ||
"name": "@reach/utils", | ||
"version": "0.11.1", | ||
"version": "0.11.2", | ||
"description": "Internal, shared utilities for Reach UI.", | ||
@@ -31,3 +31,3 @@ "author": "React Training <hello@reacttraining.com>", | ||
}, | ||
"gitHead": "5c6de02db35c1bb69e28d52bf345ea5c5c484013" | ||
"gitHead": "2aa6f03c5eed8c2b7525a29db1c69fe6bc540e5d" | ||
} |
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
152240
1567