@reach/popover
Advanced tools
Comparing version 0.7.3 to 0.7.4
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var tslib = require('tslib'); | ||
var React = require('react'); | ||
@@ -13,6 +14,35 @@ var React__default = _interopDefault(React); | ||
/** | ||
* Welcome to @reach/popover! | ||
*/ | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
/** | ||
@@ -25,3 +55,3 @@ * Popover | ||
React.forwardRef(function Popover(props, ref) { | ||
return React__default.createElement(Portal, null, React__default.createElement(PopoverImpl, tslib.__assign({ | ||
return React__default.createElement(Portal, null, React__default.createElement(PopoverImpl, Object.assign({ | ||
ref: ref | ||
@@ -41,8 +71,8 @@ }, props))); | ||
/*#__PURE__*/ | ||
React.forwardRef(function PopoverImpl(_a, forwardedRef) { | ||
var targetRef = _a.targetRef, | ||
_b = _a.position, | ||
position = _b === void 0 ? positionDefault : _b, | ||
style = _a.style, | ||
rest = tslib.__rest(_a, ["targetRef", "position", "style"]); | ||
React.forwardRef(function PopoverImpl(_ref, forwardedRef) { | ||
var targetRef = _ref.targetRef, | ||
_ref$position = _ref.position, | ||
position = _ref$position === void 0 ? positionDefault : _ref$position, | ||
style = _ref.style, | ||
rest = _objectWithoutPropertiesLoose(_ref, ["targetRef", "position", "style"]); | ||
@@ -54,8 +84,8 @@ var popoverRef = React.useRef(null); | ||
useSimulateTabNavigationForReactTree(targetRef, popoverRef); | ||
return React__default.createElement("div", tslib.__assign({ | ||
return React__default.createElement("div", Object.assign({ | ||
"data-reach-popover": "", | ||
ref: ref, | ||
style: tslib.__assign(tslib.__assign(tslib.__assign({}, style), { | ||
style: _extends({}, style, { | ||
position: "absolute" | ||
}), getStyles(position, targetRect, popoverRect)) | ||
}, getStyles(position, targetRect, popoverRect)) | ||
}, rest)); | ||
@@ -82,5 +112,5 @@ }); | ||
var _a = getCollisions(targetRect, popoverRect), | ||
directionUp = _a.directionUp, | ||
directionRight = _a.directionRight; | ||
var _getCollisions = getCollisions(targetRect, popoverRect), | ||
directionUp = _getCollisions.directionUp, | ||
directionRight = _getCollisions.directionRight; | ||
@@ -97,3 +127,5 @@ return { | ||
var directionUp = getCollisions(targetRect, popoverRect).directionUp; | ||
var _getCollisions2 = getCollisions(targetRect, popoverRect), | ||
directionUp = _getCollisions2.directionUp; | ||
return { | ||
@@ -204,5 +236,5 @@ width: targetRect.width, | ||
function tabbedOutOfPopover() { | ||
var _a, _b; | ||
var _popoverRef$current; | ||
var inPopover = (_b = (_a = popoverRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.contains(document.activeElement); | ||
var inPopover = popoverRef === null || popoverRef === void 0 ? void 0 : (_popoverRef$current = popoverRef.current) === null || _popoverRef$current === void 0 ? void 0 : _popoverRef$current.contains(document.activeElement); | ||
@@ -253,6 +285,6 @@ if (inPopover) { | ||
function focusTriggerRef(event) { | ||
var _a; | ||
var _triggerRef$current; | ||
event.preventDefault(); | ||
(_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus(); | ||
(_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 ? void 0 : _triggerRef$current.focus(); | ||
} | ||
@@ -290,5 +322,5 @@ | ||
doc.removeEventListener("focusin", enableTabbablesInPopover); | ||
restoreTabIndexTuplés.forEach(function (_a) { | ||
var element = _a[0], | ||
tabIndex = _a[1]; | ||
restoreTabIndexTuplés.forEach(function (_ref2) { | ||
var element = _ref2[0], | ||
tabIndex = _ref2[1]; | ||
element.tabIndex = tabIndex; | ||
@@ -295,0 +327,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=require("tslib"),n=require("react"),r=e(n),i=e(require("@reach/portal")),o=require("@reach/rect"),u=require("@reach/utils"),c=e(require("tabbable")),f=n.forwardRef((function(e,n){return r.createElement(i,null,r.createElement(a,t.__assign({ref:n},e)))}));f.displayName="Popover";var a=n.forwardRef((function(e,i){var f=e.targetRef,a=e.position,l=void 0===a?d:a,p=e.style,v=t.__rest(e,["targetRef","position","style"]),h=n.useRef(null),g=o.useRect(h),w=o.useRect(f),m=u.useForkedRef(h,i);return function(e,t){var r=e.current&&e.current.ownerDocument;function i(n){"Tab"===n.key&&t.current&&0===c(t.current).length||("Tab"===n.key&&n.shiftKey?function(e){if(e.shiftKey){var t=o();return e.target===t}}(n)?function(e){var n=t.current&&c(t.current),r=n&&n[n.length-1];r&&(e.preventDefault(),r.focus())}(n):function(e){var n=t.current&&c(t.current);return!!n&&0!==n.length&&e.target===n[0]}(n)?function(t){var n;t.preventDefault(),null===(n=e.current)||void 0===n||n.focus()}(n):function(e){return!!r&&e.target===c(r)[0]}(n)&&f():"Tab"===n.key&&(e.current===document.activeElement?function(e){var n=t.current&&c(t.current);n&&n[0]&&(e.preventDefault(),n[0].focus())}(n):function(){var e,n;if(null===(n=null===(e=t)||void 0===e?void 0:e.current)||void 0===n?void 0:n.contains(document.activeElement)){var r=t.current&&c(t.current);return Boolean(r&&r[r.length-1]===document.activeElement)}return!1}()?function(e){var t=o();t&&(e.preventDefault(),t.focus())}(n):function(e){var n=r&&t.current?c(r).filter((function(e){return!t.current.contains(e)})):null;return!!n&&e.target===n[n.length-1]}(n)&&f()))}function o(){var t=r&&c(r),n=t&&e.current?t.indexOf(e.current):-1;return t&&t[n+1]}n.useEffect((function(){return r&&r.addEventListener("keydown",i),function(){r&&r.removeEventListener("keydown",i)}}),[]);var u=[];function f(){var e=t.current&&c(t.current);e&&r&&(e.forEach((function(e){u.push([e,e.tabIndex]),e.tabIndex=-1})),r.addEventListener("focusin",a))}function a(){r&&(r.removeEventListener("focusin",a),u.forEach((function(e){e[0].tabIndex=e[1]})))}}(f,h),r.createElement("div",t.__assign({"data-reach-popover":"",ref:m,style:t.__assign(t.__assign(t.__assign({},p),{position:"absolute"}),s(l,w,g))},v))}));function s(e,t,n){return n?e(t,n):{visibility:"hidden"}}a.displayName="PopoverImpl";var d=function(e,t){if(!e||!t)return{};var n=l(e,t);return{left:n.directionRight?e.right-t.width+window.pageXOffset+"px":e.left+window.pageXOffset+"px",top:n.directionUp?e.top-t.height+window.pageYOffset+"px":e.top+e.height+window.pageYOffset+"px"}};function l(e,t,n,r){void 0===n&&(n=0),void 0===r&&(r=0);var i={top:e.top-t.height<0,right:window.innerWidth<e.left+t.width-n,bottom:window.innerHeight<e.bottom+t.height-r,left:e.left-t.width<0};return{directionRight:i.right&&!i.left,directionUp:i.bottom&&!i.top}}exports.default=f,exports.positionDefault=d,exports.positionMatchWidth=function(e,t){if(!e||!t)return{};var n=l(e,t).directionUp;return{width:e.width,left:e.left,top:n?e.top-t.height+window.pageYOffset+"px":e.top+e.height+window.pageYOffset+"px"}}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),r=e(t),n=e(require("@reach/portal")),i=require("@reach/rect"),o=require("@reach/utils"),u=e(require("tabbable"));function c(){return(c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var f=t.forwardRef((function(e,t){return r.createElement(n,null,r.createElement(a,Object.assign({ref:t},e)))}));f.displayName="Popover";var a=t.forwardRef((function(e,n){var f=e.targetRef,a=e.position,s=void 0===a?d:a,p=e.style,v=function(e,t){if(null==e)return{};var r,n,i={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(i[r]=e[r]);return i}(e,["targetRef","position","style"]),h=t.useRef(null),g=i.useRect(h),w=i.useRect(f),b=o.useForkedRef(h,n);return function(e,r){var n=e.current&&e.current.ownerDocument;function i(t){"Tab"===t.key&&r.current&&0===u(r.current).length||("Tab"===t.key&&t.shiftKey?function(e){if(e.shiftKey){var t=o();return e.target===t}}(t)?function(e){var t=r.current&&u(r.current),n=t&&t[t.length-1];n&&(e.preventDefault(),n.focus())}(t):function(e){var t=r.current&&u(r.current);return!!t&&0!==t.length&&e.target===t[0]}(t)?function(t){var r;t.preventDefault(),null===(r=e.current)||void 0===r||r.focus()}(t):function(e){return!!n&&e.target===u(n)[0]}(t)&&f():"Tab"===t.key&&(e.current===document.activeElement?function(e){var t=r.current&&u(r.current);t&&t[0]&&(e.preventDefault(),t[0].focus())}(t):function(){var e;if(null==r?void 0:null===(e=r.current)||void 0===e?void 0:e.contains(document.activeElement)){var t=r.current&&u(r.current);return Boolean(t&&t[t.length-1]===document.activeElement)}return!1}()?function(e){var t=o();t&&(e.preventDefault(),t.focus())}(t):function(e){var t=n&&r.current?u(n).filter((function(e){return!r.current.contains(e)})):null;return!!t&&e.target===t[t.length-1]}(t)&&f()))}function o(){var t=n&&u(n),r=t&&e.current?t.indexOf(e.current):-1;return t&&t[r+1]}t.useEffect((function(){return n&&n.addEventListener("keydown",i),function(){n&&n.removeEventListener("keydown",i)}}),[]);var c=[];function f(){var e=r.current&&u(r.current);e&&n&&(e.forEach((function(e){c.push([e,e.tabIndex]),e.tabIndex=-1})),n.addEventListener("focusin",a))}function a(){n&&(n.removeEventListener("focusin",a),c.forEach((function(e){e[0].tabIndex=e[1]})))}}(f,h),r.createElement("div",Object.assign({"data-reach-popover":"",ref:b,style:c({},p,{position:"absolute"},l(s,w,g))},v))}));function l(e,t,r){return r?e(t,r):{visibility:"hidden"}}a.displayName="PopoverImpl";var d=function(e,t){if(!e||!t)return{};var r=s(e,t);return{left:r.directionRight?e.right-t.width+window.pageXOffset+"px":e.left+window.pageXOffset+"px",top:r.directionUp?e.top-t.height+window.pageYOffset+"px":e.top+e.height+window.pageYOffset+"px"}};function s(e,t,r,n){void 0===r&&(r=0),void 0===n&&(n=0);var i={top:e.top-t.height<0,right:window.innerWidth<e.left+t.width-r,bottom:window.innerHeight<e.bottom+t.height-n,left:e.left-t.width<0};return{directionRight:i.right&&!i.left,directionUp:i.bottom&&!i.top}}exports.default=f,exports.positionDefault=d,exports.positionMatchWidth=function(e,t){if(!e||!t)return{};var r=s(e,t);return{width:e.width,left:e.left,top:r.directionUp?e.top-t.height+window.pageYOffset+"px":e.top+e.height+window.pageYOffset+"px"}}; | ||
//# sourceMappingURL=popover.cjs.production.min.js.map |
@@ -1,2 +0,1 @@ | ||
import { __assign, __rest } from 'tslib'; | ||
import React, { forwardRef, useRef, useEffect } from 'react'; | ||
@@ -8,6 +7,35 @@ import Portal from '@reach/portal'; | ||
/** | ||
* Welcome to @reach/popover! | ||
*/ | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
/** | ||
@@ -20,3 +48,3 @@ * Popover | ||
forwardRef(function Popover(props, ref) { | ||
return React.createElement(Portal, null, React.createElement(PopoverImpl, __assign({ | ||
return React.createElement(Portal, null, React.createElement(PopoverImpl, Object.assign({ | ||
ref: ref | ||
@@ -36,8 +64,8 @@ }, props))); | ||
/*#__PURE__*/ | ||
forwardRef(function PopoverImpl(_a, forwardedRef) { | ||
var targetRef = _a.targetRef, | ||
_b = _a.position, | ||
position = _b === void 0 ? positionDefault : _b, | ||
style = _a.style, | ||
rest = __rest(_a, ["targetRef", "position", "style"]); | ||
forwardRef(function PopoverImpl(_ref, forwardedRef) { | ||
var targetRef = _ref.targetRef, | ||
_ref$position = _ref.position, | ||
position = _ref$position === void 0 ? positionDefault : _ref$position, | ||
style = _ref.style, | ||
rest = _objectWithoutPropertiesLoose(_ref, ["targetRef", "position", "style"]); | ||
@@ -49,8 +77,8 @@ var popoverRef = useRef(null); | ||
useSimulateTabNavigationForReactTree(targetRef, popoverRef); | ||
return React.createElement("div", __assign({ | ||
return React.createElement("div", Object.assign({ | ||
"data-reach-popover": "", | ||
ref: ref, | ||
style: __assign(__assign(__assign({}, style), { | ||
style: _extends({}, style, { | ||
position: "absolute" | ||
}), getStyles(position, targetRect, popoverRect)) | ||
}, getStyles(position, targetRect, popoverRect)) | ||
}, rest)); | ||
@@ -77,5 +105,5 @@ }); | ||
var _a = getCollisions(targetRect, popoverRect), | ||
directionUp = _a.directionUp, | ||
directionRight = _a.directionRight; | ||
var _getCollisions = getCollisions(targetRect, popoverRect), | ||
directionUp = _getCollisions.directionUp, | ||
directionRight = _getCollisions.directionRight; | ||
@@ -92,3 +120,5 @@ return { | ||
var directionUp = getCollisions(targetRect, popoverRect).directionUp; | ||
var _getCollisions2 = getCollisions(targetRect, popoverRect), | ||
directionUp = _getCollisions2.directionUp; | ||
return { | ||
@@ -199,5 +229,5 @@ width: targetRect.width, | ||
function tabbedOutOfPopover() { | ||
var _a, _b; | ||
var _popoverRef$current; | ||
var inPopover = (_b = (_a = popoverRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.contains(document.activeElement); | ||
var inPopover = popoverRef === null || popoverRef === void 0 ? void 0 : (_popoverRef$current = popoverRef.current) === null || _popoverRef$current === void 0 ? void 0 : _popoverRef$current.contains(document.activeElement); | ||
@@ -248,6 +278,6 @@ if (inPopover) { | ||
function focusTriggerRef(event) { | ||
var _a; | ||
var _triggerRef$current; | ||
event.preventDefault(); | ||
(_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus(); | ||
(_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 ? void 0 : _triggerRef$current.focus(); | ||
} | ||
@@ -285,5 +315,5 @@ | ||
doc.removeEventListener("focusin", enableTabbablesInPopover); | ||
restoreTabIndexTuplés.forEach(function (_a) { | ||
var element = _a[0], | ||
tabIndex = _a[1]; | ||
restoreTabIndexTuplés.forEach(function (_ref2) { | ||
var element = _ref2[0], | ||
tabIndex = _ref2[1]; | ||
element.tabIndex = tabIndex; | ||
@@ -290,0 +320,0 @@ }); |
{ | ||
"name": "@reach/popover", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"description": "Render a portal positioned relative to another element.", | ||
@@ -18,5 +18,5 @@ "author": "React Training <hello@reacttraining.com>", | ||
"dependencies": { | ||
"@reach/portal": "^0.7.3", | ||
"@reach/rect": "^0.7.3", | ||
"@reach/utils": "^0.7.3", | ||
"@reach/portal": "^0.7.4", | ||
"@reach/rect": "^0.7.4", | ||
"@reach/utils": "^0.7.4", | ||
"tabbable": "^4.0.0" | ||
@@ -35,3 +35,3 @@ }, | ||
], | ||
"gitHead": "fe739beb1d94cc58c4e72f88ab58efa58e0de8c8" | ||
"gitHead": "f460709e283a60dd5ea62952b7feaf88546a50ff" | ||
} |
@@ -9,3 +9,3 @@ # @reach/popover | ||
export function Example() { | ||
function Example() { | ||
const ref = useRef(null); | ||
@@ -12,0 +12,0 @@ const [value, setValue] = useState(""); |
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
78453
578
Updated@reach/portal@^0.7.4
Updated@reach/rect@^0.7.4
Updated@reach/utils@^0.7.4