reakit-utils
Advanced tools
Comparing version 0.14.2 to 0.14.3
@@ -6,2 +6,14 @@ # Change Log | ||
## [0.14.3](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/compare/reakit-utils@0.14.2...reakit-utils@0.14.3) (2020-08-24) | ||
### Bug Fixes | ||
* **reakit-utils:** Fix `canUseDOM` to support IE11 window object ([#720](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/issues/720)) ([ca9d94a](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/commit/ca9d94aae947e88aae872ce15d7bc82712e1056f)) | ||
* Fix SSR check ([#717](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/issues/717)) ([1f09fc9](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/commit/1f09fc9879ecd9516d514c7a848b7a62a1b93358)) | ||
## [0.14.2](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/compare/reakit-utils@0.14.1...reakit-utils@0.14.2) (2020-08-17) | ||
@@ -8,0 +20,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReakitUtils={},e.React)}(this,(function(e,t){"use strict";function n(e,t){return"matches"in e?e.matches(t):"msMatchesSelector"in e?e.msMatchesSelector(t):e.webkitMatchesSelector(t)}function r(e,t){if("closest"in e)return e.closest(t);do{if(n(e,t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null}function o(e,t){return e===t||e.contains(t)}function i(e){return e?e.ownerDocument||e:window.document}function u(e,t,n){if("function"==typeof Event)return new Event(t,n);var r=i(e).createEvent("Event");return r.initEvent(t,null==n?void 0:n.bubbles,null==n?void 0:n.cancelable),r}function c(e){return i(e).activeElement}function a(e){var t=c(e);if(!t)return!1;if(t===e)return!0;var n=t.getAttribute("aria-activedescendant");return!!n&&n===e.id}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(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 s(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach((function(t){f(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function v(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 b(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return v(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)?v(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}function d(e,t,n){return void 0===n&&(n={}),"function"==typeof FocusEvent?new FocusEvent(t,n):u(e,t,n)}function y(e){return i(e).defaultView||window}var p="undefined"!=typeof window&&"msCrypto"in window;var g=["button","color","file","image","reset","submit"];function h(e){return"object"==typeof e&&null!=e}function m(e,t){return-1===t?e:[].concat(e.slice(0,t),e.slice(t+1))}var O="input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false'])";function E(e){return n(e,O)&&function(e){var t=e;return t.offsetWidth>0||t.offsetHeight>0||e.getClientRects().length>0}(e)}function w(e){return E(e)&&!function(e){return parseInt(e.getAttribute("tabindex")||"0",10)<0}(e)}function j(e){var t=Array.from(e.querySelectorAll(O));return t.unshift(e),t.filter(E)}function A(e,t){var n=Array.from(e.querySelectorAll(O)),r=n.filter(w);return w(e)&&r.unshift(e),!r.length&&t?n:r}function S(e,t){void 0===t&&(t=null),e&&("function"==typeof e?e(t):e.current=t)}var T="undefined"==typeof window?t.useEffect:t.useLayoutEffect;e.applyState=function(e,t){return function(e){return"function"==typeof e}(e)?e(t):e},e.closest=r,e.contains=o,e.createEvent=u,e.createOnKeyDown=function(e){var t=void 0===e?{}:e,n=t.keyMap,r=t.onKey,o=t.stopPropagation,i=t.onKeyDown,u=t.shouldKeyDown,c=void 0===u?function(){return!0}:u,a=t.preventDefault,f=void 0===a||a;return function(e){if(n){var t,u="function"==typeof n?n(e):n,a="function"==typeof f?f(e):f,l="function"==typeof o?o(e):o;if(e.key in u){var s=u[e.key];if("function"==typeof s&&c(e))return a&&e.preventDefault(),l&&e.stopPropagation(),r&&r(e),void s(e)}if(i&&"current"in i)null===(t=i.current)||void 0===t||t.call(i,e);else null==i||i(e)}}},e.ensureFocus=function(e,t){var n=void 0===t?{}:t,r=n.preventScroll,o=n.isActive,i=void 0===o?a:o;return i(e)?-1:(e.focus({preventScroll:r}),i(e)?-1:requestAnimationFrame((function(){e.focus({preventScroll:r})})))},e.fireBlurEvent=function(e,t){var n=d(e,"blur",t),r=e.dispatchEvent(n),o=s(s({},t),{},{bubbles:!0});return e.dispatchEvent(d(e,"focusout",o)),r},e.fireEvent=function(e,t,n){return e.dispatchEvent(u(e,t,n))},e.fireKeyboardEvent=function(e,t,n){return e.dispatchEvent(function(e,t,n){if(void 0===n&&(n={}),"function"==typeof KeyboardEvent)return new KeyboardEvent(t,n);var r=i(e).createEvent("KeyboardEvent");return r.initKeyboardEvent(t,n.bubbles,n.cancelable,y(e),n.key,n.location,n.ctrlKey,n.altKey,n.shiftKey,n.metaKey),r}(e,t,n))},e.flatten=function e(t){for(var n,r=[],o=b(t);!(n=o()).done;){var i=n.value;Array.isArray(i)?r.push.apply(r,e(i)):r.push(i)}return r},e.getActiveElement=c,e.getAllFocusableIn=j,e.getAllTabbableIn=A,e.getClosestFocusable=function(e){for(;e&&!E(e);)e=r(e,O);return e},e.getDefaultView=y,e.getDocument=i,e.getFirstFocusableIn=function(e){return j(e)[0]||null},e.getFirstTabbableIn=function(e,t){return A(e,t)[0]||null},e.getLastTabbableIn=function(e,t){var n=A(e,t);return n[n.length-1]||null},e.getNextActiveElementOnBlur=function(e){return p?c(e.currentTarget):e.relatedTarget},e.getNextTabbableIn=function(e,t){var n=c(e),r=j(e),o=r.indexOf(n),i=r.slice(o+1);return i.find(w)||r.find(w)||(t?i[0]:null)},e.getPreviousTabbableIn=function(e,t){var n=c(e),r=j(e).reverse(),o=r.indexOf(n),i=r.slice(o+1);return i.find(w)||r.find(w)||(t?i[0]:null)},e.hasFocus=a,e.hasFocusWithin=function(e){var t=c(e);if(!t)return!1;if(o(e,t))return!0;var n=t.getAttribute("aria-activedescendant");return!!n&&(n===e.id||!!e.querySelector("#"+n))},e.isButton=function(e){if("BUTTON"===e.tagName)return!0;if("INPUT"===e.tagName){var t=e;return-1!==g.indexOf(t.type)}return!1},e.isEmpty=function(e){return Array.isArray(e)?!e.length:h(e)?!Object.keys(e).length:null==e||""===e},e.isFocusable=E,e.isInteger=function(e){return"number"==typeof e?Math.floor(e)===e:String(Math.floor(Number(e)))===e},e.isObject=h,e.isPlainObject=function(e){var t;if(!h(e))return!1;var n=Object.getPrototypeOf(e);return null==n||(null===(t=n.constructor)||void 0===t?void 0:t.toString())===Object.toString()},e.isPortalEvent=function(e){return!o(e.currentTarget,e.target)},e.isPromise=function(e){return Boolean(e&&"then"in e&&e.then)},e.isSelfTarget=function(e){return e.target===e.currentTarget},e.isTabbable=w,e.isTextField=function(e){try{var t=e instanceof HTMLInputElement&&null!==e.selectionStart,n="TEXTAREA"===e.tagName,r="true"===e.contentEditable;return t||n||r||!1}catch(e){return!1}},e.matches=n,e.omit=function(e,t){for(var n=Object.keys(e),r={},o=0;o<n.length;o+=1){var i=n[o];-1===t.indexOf(i)&&(r[i]=e[i])}return r},e.pick=function(e,t){for(var n=Object.keys(e),r={},o=0;o<n.length;o+=1){var i=n[o];t.indexOf(i)>=0&&(r[i]=e[i])}return r},e.removeIndexFromArray=m,e.removeItemFromArray=function(e,t){var n=e.indexOf(t);return m(e,n)},e.shallowEqual=function(e,t){if(e===t)return!0;if(!e)return!1;if(!t)return!1;if("object"!=typeof e)return!1;if("object"!=typeof t)return!1;var n=Object.keys(e),r=Object.keys(t),o=n.length;if(r.length!==o)return!1;for(var i=0,u=n;i<u.length;i++){var c=u[i];if(e[c]!==t[c])return!1}return!0},e.splitProps=function(e,t){for(var n={},r={},o=0,i=Object.keys(e);o<i.length;o++){var u=i[o];t.indexOf(u)>=0?n[u]=e[u]:r[u]=e[u]}return[n,r]},e.toArray=function(e){return Array.isArray(e)?e:void 0!==e?[e]:[]},e.useForkRef=function(e,n){return t.useMemo((function(){return null==e&&null==n?null:function(t){S(e,t),S(n,t)}}),[e,n])},e.useLiveRef=function(e){var n=t.useRef(e);return T((function(){n.current=e})),n},e.useSealedState=function(e){return t.useState(e)[0]},e.useUpdateEffect=function(e,n){var r=t.useRef(!1);t.useEffect((function(){if(r.current)return e();r.current=!0}),n)},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReakitUtils={},e.React)}(this,(function(e,t){"use strict";function n(e){return e?e.ownerDocument||e:document}var r;try{r=window}catch(e){}function o(e){return e&&n(e).defaultView||r}var u=function(){var e=o();return Boolean(void 0!==e&&e.document&&e.document.createElement)}();function i(e,t){return"matches"in e?e.matches(t):"msMatchesSelector"in e?e.msMatchesSelector(t):e.webkitMatchesSelector(t)}function c(e,t){if("closest"in e)return e.closest(t);do{if(i(e,t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null}function a(e,t){return e===t||e.contains(t)}function f(e,t,r){if("function"==typeof Event)return new Event(t,r);var o=n(e).createEvent("Event");return o.initEvent(t,null==r?void 0:r.bubbles,null==r?void 0:r.cancelable),o}function l(e){return n(e).activeElement}function s(e){var t=l(e);if(!t)return!1;if(t===e)return!0;var n=t.getAttribute("aria-activedescendant");return!!n&&n===e.id}function v(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){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?b(Object(n),!0).forEach((function(t){v(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):b(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function y(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 p(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return y(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)?y(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}function g(e,t,n){return void 0===n&&(n={}),"function"==typeof FocusEvent?new FocusEvent(t,n):f(e,t,n)}var m=u&&"msCrypto"in window;var h=["button","color","file","image","reset","submit"];function O(e){return"object"==typeof e&&null!=e}function E(e,t){return-1===t?e:[].concat(e.slice(0,t),e.slice(t+1))}var j="input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false'])";function A(e){return i(e,j)&&function(e){var t=e;return t.offsetWidth>0||t.offsetHeight>0||e.getClientRects().length>0}(e)}function w(e){return A(e)&&!function(e){return parseInt(e.getAttribute("tabindex")||"0",10)<0}(e)}function S(e){var t=Array.from(e.querySelectorAll(j));return t.unshift(e),t.filter(A)}function T(e,t){var n=Array.from(e.querySelectorAll(j)),r=n.filter(w);return w(e)&&r.unshift(e),!r.length&&t?n:r}function P(e,t){void 0===t&&(t=null),e&&("function"==typeof e?e(t):e.current=t)}var x=u?t.useLayoutEffect:t.useEffect;e.applyState=function(e,t){return function(e){return"function"==typeof e}(e)?e(t):e},e.canUseDOM=u,e.closest=c,e.contains=a,e.createEvent=f,e.createOnKeyDown=function(e){var t=void 0===e?{}:e,n=t.keyMap,r=t.onKey,o=t.stopPropagation,u=t.onKeyDown,i=t.shouldKeyDown,c=void 0===i?function(){return!0}:i,a=t.preventDefault,f=void 0===a||a;return function(e){if(n){var t,i="function"==typeof n?n(e):n,a="function"==typeof f?f(e):f,l="function"==typeof o?o(e):o;if(e.key in i){var s=i[e.key];if("function"==typeof s&&c(e))return a&&e.preventDefault(),l&&e.stopPropagation(),r&&r(e),void s(e)}if(u&&"current"in u)null===(t=u.current)||void 0===t||t.call(u,e);else null==u||u(e)}}},e.ensureFocus=function(e,t){var n=void 0===t?{}:t,r=n.preventScroll,o=n.isActive,u=void 0===o?s:o;return u(e)?-1:(e.focus({preventScroll:r}),u(e)?-1:requestAnimationFrame((function(){e.focus({preventScroll:r})})))},e.fireBlurEvent=function(e,t){var n=g(e,"blur",t),r=e.dispatchEvent(n),o=d(d({},t),{},{bubbles:!0});return e.dispatchEvent(g(e,"focusout",o)),r},e.fireEvent=function(e,t,n){return e.dispatchEvent(f(e,t,n))},e.fireKeyboardEvent=function(e,t,r){return e.dispatchEvent(function(e,t,r){if(void 0===r&&(r={}),"function"==typeof KeyboardEvent)return new KeyboardEvent(t,r);var u=n(e).createEvent("KeyboardEvent");return u.initKeyboardEvent(t,r.bubbles,r.cancelable,o(e),r.key,r.location,r.ctrlKey,r.altKey,r.shiftKey,r.metaKey),u}(e,t,r))},e.flatten=function e(t){for(var n,r=[],o=p(t);!(n=o()).done;){var u=n.value;Array.isArray(u)?r.push.apply(r,e(u)):r.push(u)}return r},e.getActiveElement=l,e.getAllFocusableIn=S,e.getAllTabbableIn=T,e.getClosestFocusable=function(e){for(;e&&!A(e);)e=c(e,j);return e},e.getDocument=n,e.getFirstFocusableIn=function(e){return S(e)[0]||null},e.getFirstTabbableIn=function(e,t){return T(e,t)[0]||null},e.getLastTabbableIn=function(e,t){var n=T(e,t);return n[n.length-1]||null},e.getNextActiveElementOnBlur=function(e){return m?l(e.currentTarget):e.relatedTarget},e.getNextTabbableIn=function(e,t){var n=l(e),r=S(e),o=r.indexOf(n),u=r.slice(o+1);return u.find(w)||r.find(w)||(t?u[0]:null)},e.getPreviousTabbableIn=function(e,t){var n=l(e),r=S(e).reverse(),o=r.indexOf(n),u=r.slice(o+1);return u.find(w)||r.find(w)||(t?u[0]:null)},e.getWindow=o,e.hasFocus=s,e.hasFocusWithin=function(e){var t=l(e);if(!t)return!1;if(a(e,t))return!0;var n=t.getAttribute("aria-activedescendant");return!!n&&(n===e.id||!!e.querySelector("#"+n))},e.isButton=function(e){if("BUTTON"===e.tagName)return!0;if("INPUT"===e.tagName){var t=e;return-1!==h.indexOf(t.type)}return!1},e.isEmpty=function(e){return Array.isArray(e)?!e.length:O(e)?!Object.keys(e).length:null==e||""===e},e.isFocusable=A,e.isInteger=function(e){return"number"==typeof e?Math.floor(e)===e:String(Math.floor(Number(e)))===e},e.isObject=O,e.isPlainObject=function(e){var t;if(!O(e))return!1;var n=Object.getPrototypeOf(e);return null==n||(null===(t=n.constructor)||void 0===t?void 0:t.toString())===Object.toString()},e.isPortalEvent=function(e){return!a(e.currentTarget,e.target)},e.isPromise=function(e){return Boolean(e&&"then"in e&&e.then)},e.isSelfTarget=function(e){return e.target===e.currentTarget},e.isTabbable=w,e.isTextField=function(e){try{var t=e instanceof HTMLInputElement&&null!==e.selectionStart,n="TEXTAREA"===e.tagName,r="true"===e.contentEditable;return t||n||r||!1}catch(e){return!1}},e.matches=i,e.omit=function(e,t){for(var n=Object.keys(e),r={},o=0;o<n.length;o+=1){var u=n[o];-1===t.indexOf(u)&&(r[u]=e[u])}return r},e.pick=function(e,t){for(var n=Object.keys(e),r={},o=0;o<n.length;o+=1){var u=n[o];t.indexOf(u)>=0&&(r[u]=e[u])}return r},e.removeIndexFromArray=E,e.removeItemFromArray=function(e,t){var n=e.indexOf(t);return E(e,n)},e.shallowEqual=function(e,t){if(e===t)return!0;if(!e)return!1;if(!t)return!1;if("object"!=typeof e)return!1;if("object"!=typeof t)return!1;var n=Object.keys(e),r=Object.keys(t),o=n.length;if(r.length!==o)return!1;for(var u=0,i=n;u<i.length;u++){var c=i[u];if(e[c]!==t[c])return!1}return!0},e.splitProps=function(e,t){for(var n={},r={},o=0,u=Object.keys(e);o<u.length;o++){var i=u[o];t.indexOf(i)>=0?n[i]=e[i]:r[i]=e[i]}return[n,r]},e.toArray=function(e){return Array.isArray(e)?e:void 0!==e?[e]:[]},e.useForkRef=function(e,n){return t.useMemo((function(){return null==e&&null==n?null:function(t){P(e,t),P(n,t)}}),[e,n])},e.useLiveRef=function(e){var n=t.useRef(e);return x((function(){n.current=e})),n},e.useSealedState=function(e){return t.useState(e)[0]},e.useUpdateEffect=function(e,n){var r=t.useRef(!1);t.useEffect((function(){if(r.current)return e();r.current=!0}),n)},Object.defineProperty(e,"__esModule",{value:!0})})); |
import { getDocument } from './getDocument.js'; | ||
import { getDefaultView } from './getDefaultView.js'; | ||
import { getWindow } from './getWindow.js'; | ||
@@ -15,3 +15,3 @@ function createKeyboardEvent(element, type, eventInit) { | ||
var event = getDocument(element).createEvent("KeyboardEvent"); | ||
event.initKeyboardEvent(type, eventInit.bubbles, eventInit.cancelable, getDefaultView(element), eventInit.key, eventInit.location, eventInit.ctrlKey, eventInit.altKey, eventInit.shiftKey, eventInit.metaKey); | ||
event.initKeyboardEvent(type, eventInit.bubbles, eventInit.cancelable, getWindow(element), eventInit.key, eventInit.location, eventInit.ctrlKey, eventInit.altKey, eventInit.shiftKey, eventInit.metaKey); | ||
return event; | ||
@@ -18,0 +18,0 @@ } |
/** | ||
* Returns `element.ownerDocument || window.document`. | ||
* Returns `element.ownerDocument || document`. | ||
*/ | ||
function getDocument(element) { | ||
return element ? element.ownerDocument || element : window.document; | ||
return element ? element.ownerDocument || element : document; | ||
} | ||
export { getDocument }; |
import './getDocument.js'; | ||
import './getWindow.js'; | ||
import { canUseDOM } from './canUseDOM.js'; | ||
import { getActiveElement } from './getActiveElement.js'; | ||
var isIE11 = typeof window !== "undefined" && "msCrypto" in window; | ||
var isIE11 = canUseDOM && "msCrypto" in window; | ||
/** | ||
@@ -6,0 +8,0 @@ * Cross-browser method that returns the next active element (the element that |
import 'react'; | ||
export { useUpdateEffect } from './useUpdateEffect.js'; | ||
export { useSealedState } from './useSealedState.js'; | ||
export { getDocument } from './getDocument.js'; | ||
export { getWindow } from './getWindow.js'; | ||
export { canUseDOM } from './canUseDOM.js'; | ||
import './useIsomorphicEffect.js'; | ||
@@ -10,3 +13,2 @@ export { useLiveRef } from './useLiveRef.js'; | ||
export { closest } from './closest.js'; | ||
export { getDocument } from './getDocument.js'; | ||
export { getActiveElement } from './getActiveElement.js'; | ||
@@ -38,3 +40,2 @@ export { getAllFocusableIn, getAllTabbableIn, getClosestFocusable, getFirstFocusableIn, getFirstTabbableIn, getLastTabbableIn, getNextTabbableIn, getPreviousTabbableIn, isFocusable, isTabbable } from './tabbable.js'; | ||
export { fireBlurEvent } from './fireBlurEvent.js'; | ||
export { getDefaultView } from './getDefaultView.js'; | ||
export { fireKeyboardEvent } from './fireKeyboardEvent.js'; | ||
@@ -41,0 +42,0 @@ export { flatten } from './flatten.js'; |
@@ -0,4 +1,4 @@ | ||
import './getDocument.js'; | ||
import { matches } from './matches.js'; | ||
import { closest } from './closest.js'; | ||
import './getDocument.js'; | ||
import { getActiveElement } from './getActiveElement.js'; | ||
@@ -5,0 +5,0 @@ |
import { useEffect, useLayoutEffect } from 'react'; | ||
import './getDocument.js'; | ||
import './getWindow.js'; | ||
import { canUseDOM } from './canUseDOM.js'; | ||
@@ -8,4 +11,4 @@ /** | ||
var useIsomorphicEffect = typeof window === "undefined" ? useEffect : useLayoutEffect; | ||
var useIsomorphicEffect = !canUseDOM ? useEffect : useLayoutEffect; | ||
export { useIsomorphicEffect }; |
import { useRef } from 'react'; | ||
import './getDocument.js'; | ||
import './getWindow.js'; | ||
import './canUseDOM.js'; | ||
import { useIsomorphicEffect } from './useIsomorphicEffect.js'; | ||
@@ -3,0 +6,0 @@ |
@@ -6,3 +6,3 @@ 'use strict'; | ||
var getDocument = require('./getDocument.js'); | ||
var getDefaultView = require('./getDefaultView.js'); | ||
var getWindow = require('./getWindow.js'); | ||
@@ -20,3 +20,3 @@ function createKeyboardEvent(element, type, eventInit) { | ||
var event = getDocument.getDocument(element).createEvent("KeyboardEvent"); | ||
event.initKeyboardEvent(type, eventInit.bubbles, eventInit.cancelable, getDefaultView.getDefaultView(element), eventInit.key, eventInit.location, eventInit.ctrlKey, eventInit.altKey, eventInit.shiftKey, eventInit.metaKey); | ||
event.initKeyboardEvent(type, eventInit.bubbles, eventInit.cancelable, getWindow.getWindow(element), eventInit.key, eventInit.location, eventInit.ctrlKey, eventInit.altKey, eventInit.shiftKey, eventInit.metaKey); | ||
return event; | ||
@@ -23,0 +23,0 @@ } |
@@ -6,8 +6,8 @@ 'use strict'; | ||
/** | ||
* Returns `element.ownerDocument || window.document`. | ||
* Returns `element.ownerDocument || document`. | ||
*/ | ||
function getDocument(element) { | ||
return element ? element.ownerDocument || element : window.document; | ||
return element ? element.ownerDocument || element : document; | ||
} | ||
exports.getDocument = getDocument; |
@@ -6,5 +6,7 @@ 'use strict'; | ||
require('./getDocument.js'); | ||
require('./getWindow.js'); | ||
var canUseDOM = require('./canUseDOM.js'); | ||
var getActiveElement = require('./getActiveElement.js'); | ||
var isIE11 = typeof window !== "undefined" && "msCrypto" in window; | ||
var isIE11 = canUseDOM.canUseDOM && "msCrypto" in window; | ||
/** | ||
@@ -11,0 +13,0 @@ * Cross-browser method that returns the next active element (the element that |
@@ -8,2 +8,5 @@ 'use strict'; | ||
var useSealedState = require('./useSealedState.js'); | ||
var getDocument = require('./getDocument.js'); | ||
var getWindow = require('./getWindow.js'); | ||
var canUseDOM = require('./canUseDOM.js'); | ||
require('./useIsomorphicEffect.js'); | ||
@@ -15,3 +18,2 @@ var useLiveRef = require('./useLiveRef.js'); | ||
var closest = require('./closest.js'); | ||
var getDocument = require('./getDocument.js'); | ||
var getActiveElement = require('./getActiveElement.js'); | ||
@@ -43,3 +45,2 @@ var tabbable = require('./tabbable.js'); | ||
var fireBlurEvent = require('./fireBlurEvent.js'); | ||
var getDefaultView = require('./getDefaultView.js'); | ||
var fireKeyboardEvent = require('./fireKeyboardEvent.js'); | ||
@@ -54,2 +55,5 @@ var flatten = require('./flatten.js'); | ||
exports.useSealedState = useSealedState.useSealedState; | ||
exports.getDocument = getDocument.getDocument; | ||
exports.getWindow = getWindow.getWindow; | ||
exports.canUseDOM = canUseDOM.canUseDOM; | ||
exports.useLiveRef = useLiveRef.useLiveRef; | ||
@@ -60,3 +64,2 @@ exports.useForkRef = useForkRef.useForkRef; | ||
exports.closest = closest.closest; | ||
exports.getDocument = getDocument.getDocument; | ||
exports.getActiveElement = getActiveElement.getActiveElement; | ||
@@ -96,3 +99,2 @@ exports.getAllFocusableIn = tabbable.getAllFocusableIn; | ||
exports.fireBlurEvent = fireBlurEvent.fireBlurEvent; | ||
exports.getDefaultView = getDefaultView.getDefaultView; | ||
exports.fireKeyboardEvent = fireKeyboardEvent.fireKeyboardEvent; | ||
@@ -99,0 +101,0 @@ exports.flatten = flatten.flatten; |
@@ -5,5 +5,5 @@ 'use strict'; | ||
require('./getDocument.js'); | ||
var matches = require('./matches.js'); | ||
var closest = require('./closest.js'); | ||
require('./getDocument.js'); | ||
var getActiveElement = require('./getActiveElement.js'); | ||
@@ -10,0 +10,0 @@ |
@@ -6,2 +6,5 @@ 'use strict'; | ||
var React = require('react'); | ||
require('./getDocument.js'); | ||
require('./getWindow.js'); | ||
var canUseDOM = require('./canUseDOM.js'); | ||
@@ -13,4 +16,4 @@ /** | ||
var useIsomorphicEffect = typeof window === "undefined" ? React.useEffect : React.useLayoutEffect; | ||
var useIsomorphicEffect = !canUseDOM.canUseDOM ? React.useEffect : React.useLayoutEffect; | ||
exports.useIsomorphicEffect = useIsomorphicEffect; |
@@ -6,2 +6,5 @@ 'use strict'; | ||
var React = require('react'); | ||
require('./getDocument.js'); | ||
require('./getWindow.js'); | ||
require('./canUseDOM.js'); | ||
var useIsomorphicEffect = require('./useIsomorphicEffect.js'); | ||
@@ -8,0 +11,0 @@ |
{ | ||
"name": "reakit-utils", | ||
"version": "0.14.2", | ||
"version": "0.14.3", | ||
"description": "Reakit utils", | ||
@@ -37,3 +37,3 @@ "sideEffects": false, | ||
}, | ||
"gitHead": "81d92c28127d33325742a0e5be8ef16930043086" | ||
"gitHead": "2b9a11c7d44c6159662e4e8261d8852211d66c30" | ||
} |
@@ -28,2 +28,3 @@ # reakit-utils | ||
- [applyState](#applystate) | ||
- [canUseDOM](#canusedom) | ||
- [closest](#closest) | ||
@@ -39,5 +40,5 @@ - [contains](#contains) | ||
- [getActiveElement](#getactiveelement) | ||
- [getDefaultView](#getdefaultview) | ||
- [getDocument](#getdocument) | ||
- [getNextActiveElementOnBlur](#getnextactiveelementonblur) | ||
- [getWindow](#getwindow) | ||
- [hasFocus](#hasfocus) | ||
@@ -89,2 +90,14 @@ - [hasFocusWithin](#hasfocuswithin) | ||
### canUseDOM | ||
It's `true` if it is running in a browser environment or `false` if it is not (SSR). | ||
#### Examples | ||
```javascript | ||
import { canUseDOM } from "reakit-utils"; | ||
const title = canUseDOM ? document.title : ""; | ||
``` | ||
### closest | ||
@@ -282,15 +295,5 @@ | ||
### getDefaultView | ||
Returns `element.ownerDocument.defaultView || window`. | ||
#### Parameters | ||
- `element` **[Element](https://developer.mozilla.org/docs/Web/API/Element)?** | ||
Returns **[Window](https://developer.mozilla.org/docs/Web/API/Window)** | ||
### getDocument | ||
Returns `element.ownerDocument || window.document`. | ||
Returns `element.ownerDocument || document`. | ||
@@ -324,2 +327,12 @@ #### Parameters | ||
### getWindow | ||
Returns `element.ownerDocument.defaultView || window`. | ||
#### Parameters | ||
- `element` **[Element](https://developer.mozilla.org/docs/Web/API/Element)?** | ||
Returns **[Window](https://developer.mozilla.org/docs/Web/API/Window)** | ||
### hasFocus | ||
@@ -326,0 +339,0 @@ |
import { getDocument } from "./getDocument"; | ||
import { getDefaultView } from "./getDefaultView"; | ||
import { getWindow } from "./getWindow"; | ||
@@ -18,3 +18,3 @@ function createKeyboardEvent( | ||
eventInit.cancelable, | ||
getDefaultView(element), | ||
getWindow(element), | ||
eventInit.key, | ||
@@ -21,0 +21,0 @@ eventInit.location, |
/** | ||
* Returns `element.ownerDocument || window.document`. | ||
* Returns `element.ownerDocument || document`. | ||
*/ | ||
export function getDocument(element?: Element | Document | null): Document { | ||
return element | ||
? element.ownerDocument || (element as Document) | ||
: window.document; | ||
return element ? element.ownerDocument || (element as Document) : document; | ||
} |
import * as React from "react"; | ||
import { getActiveElement } from "./getActiveElement"; | ||
import { canUseDOM } from "./canUseDOM"; | ||
const isIE11 = typeof window !== "undefined" && "msCrypto" in window; | ||
const isIE11 = canUseDOM && "msCrypto" in window; | ||
@@ -6,0 +7,0 @@ /** |
export * from "./applyState"; | ||
export * from "./canUseDOM"; | ||
export * from "./closest"; | ||
@@ -12,3 +13,3 @@ export * from "./contains"; | ||
export * from "./getActiveElement"; | ||
export * from "./getDefaultView"; | ||
export * from "./getWindow"; | ||
export * from "./getDocument"; | ||
@@ -15,0 +16,0 @@ export * from "./getNextActiveElementOnBlur"; |
import * as React from "react"; | ||
import { canUseDOM } from "./canUseDOM"; | ||
@@ -7,3 +8,4 @@ /** | ||
*/ | ||
export const useIsomorphicEffect = | ||
typeof window === "undefined" ? React.useEffect : React.useLayoutEffect; | ||
export const useIsomorphicEffect = !canUseDOM | ||
? React.useEffect | ||
: React.useLayoutEffect; |
/** | ||
* Returns `element.ownerDocument || window.document`. | ||
* Returns `element.ownerDocument || document`. | ||
*/ | ||
export declare function getDocument(element?: Element | Document | null): Document; |
export * from "./applyState"; | ||
export * from "./canUseDOM"; | ||
export * from "./closest"; | ||
@@ -12,3 +13,3 @@ export * from "./contains"; | ||
export * from "./getActiveElement"; | ||
export * from "./getDefaultView"; | ||
export * from "./getWindow"; | ||
export * from "./getDocument"; | ||
@@ -15,0 +16,0 @@ export * from "./getNextActiveElementOnBlur"; |
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
197735
272
4479
915