react-focus-lock
Advanced tools
Comparing version 2.9.7 to 2.9.8
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,19 +9,15 @@ value: true | ||
exports["default"] = void 0; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var constants = _interopRequireWildcard(require("focus-lock/constants")); | ||
var _util = require("./util"); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } | ||
var AutoFocusInside = function AutoFocusInside(_ref) { | ||
var _ref$disabled = _ref.disabled, | ||
disabled = _ref$disabled === void 0 ? false : _ref$disabled, | ||
children = _ref.children, | ||
_ref$className = _ref.className, | ||
className = _ref$className === void 0 ? undefined : _ref$className; | ||
disabled = _ref$disabled === void 0 ? false : _ref$disabled, | ||
children = _ref.children, | ||
_ref$className = _ref.className, | ||
className = _ref$className === void 0 ? undefined : _ref$className; | ||
return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _util.inlineProp)(constants.FOCUS_AUTO, !disabled), { | ||
@@ -33,3 +27,2 @@ className: className | ||
}; | ||
AutoFocusInside.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -40,3 +33,2 @@ children: _propTypes["default"].node.isRequired, | ||
} : {}; | ||
var _default = AutoFocusInside; | ||
exports["default"] = _default; | ||
var _default = exports["default"] = AutoFocusInside; |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,5 +8,5 @@ value: true | ||
exports["default"] = void 0; | ||
var React = _interopRequireWildcard(require("react")); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } | ||
function withSideEffect(reducePropsToState, handleStateChangeOnClient) { | ||
@@ -18,3 +17,2 @@ if (process.env.NODE_ENV !== 'production') { | ||
} | ||
if (typeof handleStateChangeOnClient !== 'function') { | ||
@@ -24,3 +22,2 @@ throw new Error('Expected handleStateChangeOnClient to be a function.'); | ||
} | ||
return function wrap(WrappedComponent) { | ||
@@ -32,5 +29,3 @@ if (process.env.NODE_ENV !== 'production') { | ||
} | ||
var mountedInstances = []; | ||
function emitChange() { | ||
@@ -43,3 +38,2 @@ console.log('emitting'); | ||
} | ||
var SideEffect = function SideEffect(props) { | ||
@@ -61,8 +55,5 @@ var lastProps = React.useRef(props); | ||
}; | ||
return SideEffect; | ||
}; | ||
} | ||
var _default = withSideEffect; | ||
exports["default"] = _default; | ||
var _default = exports["default"] = withSideEffect; |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,13 +9,9 @@ value: true | ||
exports["default"] = void 0; | ||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _Lock = _interopRequireDefault(require("./Lock")); | ||
var _Trap = _interopRequireDefault(require("./Trap")); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } | ||
var FocusLockCombination = /*#__PURE__*/React.forwardRef(function FocusLockUICombination(props, ref) { | ||
@@ -29,9 +23,6 @@ return /*#__PURE__*/React.createElement(_Lock["default"], (0, _extends2["default"])({ | ||
}); | ||
var _ref = _Lock["default"].propTypes || {}, | ||
sideCar = _ref.sideCar, | ||
propTypes = (0, _objectWithoutProperties2["default"])(_ref, ["sideCar"]); | ||
sideCar = _ref.sideCar, | ||
propTypes = (0, _objectWithoutProperties2["default"])(_ref, ["sideCar"]); | ||
FocusLockCombination.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {}; | ||
var _default = FocusLockCombination; | ||
exports["default"] = _default; | ||
var _default = exports["default"] = FocusLockCombination; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = exports.hiddenGuard = void 0; | ||
exports.hiddenGuard = exports["default"] = void 0; | ||
var React = _interopRequireWildcard(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var hiddenGuard = { | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } | ||
var hiddenGuard = exports.hiddenGuard = { | ||
width: '1px', | ||
@@ -25,7 +22,5 @@ height: '0px', | ||
}; | ||
exports.hiddenGuard = hiddenGuard; | ||
var InFocusGuard = function InFocusGuard(_ref) { | ||
var _ref$children = _ref.children, | ||
children = _ref$children === void 0 ? null : _ref$children; | ||
children = _ref$children === void 0 ? null : _ref$children; | ||
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", { | ||
@@ -43,7 +38,5 @@ key: "guard-first", | ||
}; | ||
InFocusGuard.propTypes = process.env.NODE_ENV !== "production" ? { | ||
children: _propTypes["default"].node | ||
} : {}; | ||
var _default = InFocusGuard; | ||
exports["default"] = _default; | ||
var _default = exports["default"] = InFocusGuard; |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,16 +9,12 @@ value: true | ||
exports["default"] = void 0; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var constants = _interopRequireWildcard(require("focus-lock/constants")); | ||
var _util = require("./util"); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } | ||
var FreeFocusInside = function FreeFocusInside(_ref) { | ||
var children = _ref.children, | ||
className = _ref.className; | ||
className = _ref.className; | ||
return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _util.inlineProp)(constants.FOCUS_ALLOW, true), { | ||
@@ -30,3 +24,2 @@ className: className | ||
}; | ||
FreeFocusInside.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -36,3 +29,2 @@ children: _propTypes["default"].node.isRequired, | ||
} : {}; | ||
var _default = FreeFocusInside; | ||
exports["default"] = _default; | ||
var _default = exports["default"] = FreeFocusInside; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,10 +9,8 @@ value: true | ||
exports["default"] = void 0; | ||
var _Combination = _interopRequireDefault(require("./Combination")); | ||
var _UI = require("./UI"); | ||
Object.keys(_UI).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
if (key in exports && exports[key] === _UI[key]) return; | ||
Object.defineProperty(exports, key, { | ||
@@ -26,3 +23,2 @@ enumerable: true, | ||
}); | ||
var _default = _Combination["default"]; | ||
exports["default"] = _default; | ||
var _default = exports["default"] = _Combination["default"]; |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof3 = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,36 +9,23 @@ value: true | ||
exports["default"] = void 0; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _react = _interopRequireWildcard(require("react")); | ||
var React = _react; | ||
var _propTypes = require("prop-types"); | ||
var constants = _interopRequireWildcard(require("focus-lock/constants")); | ||
var _useCallbackRef = require("use-callback-ref"); | ||
var _FocusGuard = require("./FocusGuard"); | ||
var _medium = require("./medium"); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } | ||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } | ||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } | ||
var emptyArray = []; | ||
var FocusLock = /*#__PURE__*/React.forwardRef(function FocusLockUI(props, parentRef) { | ||
var _objectSpread2; | ||
var _React$useState = React.useState(), | ||
_React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2), | ||
realObserved = _React$useState2[0], | ||
setObserved = _React$useState2[1]; | ||
_React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2), | ||
realObserved = _React$useState2[0], | ||
setObserved = _React$useState2[1]; | ||
var observed = React.useRef(); | ||
@@ -50,41 +35,37 @@ var isActive = React.useRef(false); | ||
var children = props.children, | ||
_props$disabled = props.disabled, | ||
disabled = _props$disabled === void 0 ? false : _props$disabled, | ||
_props$noFocusGuards = props.noFocusGuards, | ||
noFocusGuards = _props$noFocusGuards === void 0 ? false : _props$noFocusGuards, | ||
_props$persistentFocu = props.persistentFocus, | ||
persistentFocus = _props$persistentFocu === void 0 ? false : _props$persistentFocu, | ||
_props$crossFrame = props.crossFrame, | ||
crossFrame = _props$crossFrame === void 0 ? true : _props$crossFrame, | ||
_props$autoFocus = props.autoFocus, | ||
autoFocus = _props$autoFocus === void 0 ? true : _props$autoFocus, | ||
allowTextSelection = props.allowTextSelection, | ||
group = props.group, | ||
className = props.className, | ||
whiteList = props.whiteList, | ||
hasPositiveIndices = props.hasPositiveIndices, | ||
_props$shards = props.shards, | ||
shards = _props$shards === void 0 ? emptyArray : _props$shards, | ||
_props$as = props.as, | ||
Container = _props$as === void 0 ? 'div' : _props$as, | ||
_props$lockProps = props.lockProps, | ||
containerProps = _props$lockProps === void 0 ? {} : _props$lockProps, | ||
SideCar = props.sideCar, | ||
_props$returnFocus = props.returnFocus, | ||
shouldReturnFocus = _props$returnFocus === void 0 ? false : _props$returnFocus, | ||
focusOptions = props.focusOptions, | ||
onActivationCallback = props.onActivation, | ||
onDeactivationCallback = props.onDeactivation; | ||
_props$disabled = props.disabled, | ||
disabled = _props$disabled === void 0 ? false : _props$disabled, | ||
_props$noFocusGuards = props.noFocusGuards, | ||
noFocusGuards = _props$noFocusGuards === void 0 ? false : _props$noFocusGuards, | ||
_props$persistentFocu = props.persistentFocus, | ||
persistentFocus = _props$persistentFocu === void 0 ? false : _props$persistentFocu, | ||
_props$crossFrame = props.crossFrame, | ||
crossFrame = _props$crossFrame === void 0 ? true : _props$crossFrame, | ||
_props$autoFocus = props.autoFocus, | ||
autoFocus = _props$autoFocus === void 0 ? true : _props$autoFocus, | ||
allowTextSelection = props.allowTextSelection, | ||
group = props.group, | ||
className = props.className, | ||
whiteList = props.whiteList, | ||
hasPositiveIndices = props.hasPositiveIndices, | ||
_props$shards = props.shards, | ||
shards = _props$shards === void 0 ? emptyArray : _props$shards, | ||
_props$as = props.as, | ||
Container = _props$as === void 0 ? 'div' : _props$as, | ||
_props$lockProps = props.lockProps, | ||
containerProps = _props$lockProps === void 0 ? {} : _props$lockProps, | ||
SideCar = props.sideCar, | ||
_props$returnFocus = props.returnFocus, | ||
shouldReturnFocus = _props$returnFocus === void 0 ? false : _props$returnFocus, | ||
focusOptions = props.focusOptions, | ||
onActivationCallback = props.onActivation, | ||
onDeactivationCallback = props.onDeactivation; | ||
var _React$useState3 = React.useState({}), | ||
_React$useState4 = (0, _slicedToArray2["default"])(_React$useState3, 1), | ||
id = _React$useState4[0]; | ||
_React$useState4 = (0, _slicedToArray2["default"])(_React$useState3, 1), | ||
id = _React$useState4[0]; | ||
var onActivation = React.useCallback(function () { | ||
originalFocusedElement.current = originalFocusedElement.current || document && document.activeElement; | ||
if (observed.current && onActivationCallback) { | ||
onActivationCallback(observed.current); | ||
} | ||
isActive.current = true; | ||
@@ -94,3 +75,2 @@ }, [onActivationCallback]); | ||
isActive.current = false; | ||
if (onDeactivationCallback) { | ||
@@ -100,3 +80,3 @@ onDeactivationCallback(observed.current); | ||
}, [onDeactivationCallback]); | ||
(0, React.useEffect)(function () { | ||
(0, _react.useEffect)(function () { | ||
if (!disabled) { | ||
@@ -108,10 +88,7 @@ originalFocusedElement.current = null; | ||
var returnFocusTo = originalFocusedElement.current; | ||
if (returnFocusTo && returnFocusTo.focus) { | ||
var howToReturnFocus = typeof shouldReturnFocus === 'function' ? shouldReturnFocus(returnFocusTo) : shouldReturnFocus; | ||
if (howToReturnFocus) { | ||
var returnFocusOptions = (0, _typeof2["default"])(howToReturnFocus) === 'object' ? howToReturnFocus : undefined; | ||
originalFocusedElement.current = null; | ||
if (allowDefer) { | ||
@@ -139,3 +116,2 @@ Promise.resolve().then(function () { | ||
}, []); | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -145,3 +121,2 @@ if (typeof allowTextSelection !== 'undefined') { | ||
} | ||
React.useEffect(function () { | ||
@@ -153,5 +128,3 @@ if (!observed.current && typeof Container !== 'string') { | ||
} | ||
var lockProps = _objectSpread((_objectSpread2 = {}, (0, _defineProperty2["default"])(_objectSpread2, constants.FOCUS_DISABLED, disabled && 'disabled'), (0, _defineProperty2["default"])(_objectSpread2, constants.FOCUS_GROUP, group), _objectSpread2), containerProps); | ||
var lockProps = _objectSpread((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, constants.FOCUS_DISABLED, disabled && 'disabled'), constants.FOCUS_GROUP, group), containerProps); | ||
var hasLeadingGuards = noFocusGuards !== true; | ||
@@ -219,3 +192,2 @@ var hasTailingGuards = hasLeadingGuards && noFocusGuards !== 'tail'; | ||
} : {}; | ||
var _default = FocusLock; | ||
exports["default"] = _default; | ||
var _default = exports["default"] = FocusLock; |
@@ -6,9 +6,7 @@ "use strict"; | ||
}); | ||
exports.mediumSidecar = exports.mediumEffect = exports.mediumBlur = exports.mediumFocus = void 0; | ||
exports.mediumSidecar = exports.mediumFocus = exports.mediumEffect = exports.mediumBlur = void 0; | ||
var _useSidecar = require("use-sidecar"); | ||
var mediumFocus = (0, _useSidecar.createMedium)({}, function (_ref) { | ||
var mediumFocus = exports.mediumFocus = (0, _useSidecar.createMedium)({}, function (_ref) { | ||
var target = _ref.target, | ||
currentTarget = _ref.currentTarget; | ||
currentTarget = _ref.currentTarget; | ||
return { | ||
@@ -19,10 +17,6 @@ target: target, | ||
}); | ||
exports.mediumFocus = mediumFocus; | ||
var mediumBlur = (0, _useSidecar.createMedium)(); | ||
exports.mediumBlur = mediumBlur; | ||
var mediumEffect = (0, _useSidecar.createMedium)(); | ||
exports.mediumEffect = mediumEffect; | ||
var mediumSidecar = (0, _useSidecar.createSidecarMedium)({ | ||
var mediumBlur = exports.mediumBlur = (0, _useSidecar.createMedium)(); | ||
var mediumEffect = exports.mediumEffect = (0, _useSidecar.createMedium)(); | ||
var mediumSidecar = exports.mediumSidecar = (0, _useSidecar.createSidecarMedium)({ | ||
async: true | ||
}); | ||
exports.mediumSidecar = mediumSidecar; | ||
}); |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = exports.useFocusInside = void 0; | ||
exports.useFocusInside = exports["default"] = void 0; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var constants = _interopRequireWildcard(require("focus-lock/constants")); | ||
var _util = require("./util"); | ||
var _medium = require("./medium"); | ||
var useFocusInside = function useFocusInside(observedRef) { | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } | ||
var useFocusInside = exports.useFocusInside = function useFocusInside(observedRef) { | ||
React.useEffect(function () { | ||
var enabled = true; | ||
_medium.mediumEffect.useMedium(function (car) { | ||
var observed = observedRef && observedRef.current; | ||
if (enabled && observed) { | ||
@@ -37,3 +28,2 @@ if (!car.focusInside(observed)) { | ||
}); | ||
return function () { | ||
@@ -44,10 +34,7 @@ enabled = false; | ||
}; | ||
exports.useFocusInside = useFocusInside; | ||
function MoveFocusInside(_ref) { | ||
var _ref$disabled = _ref.disabled, | ||
isDisabled = _ref$disabled === void 0 ? false : _ref$disabled, | ||
className = _ref.className, | ||
children = _ref.children; | ||
isDisabled = _ref$disabled === void 0 ? false : _ref$disabled, | ||
className = _ref.className, | ||
children = _ref.children; | ||
var ref = React.useRef(null); | ||
@@ -60,3 +47,2 @@ useFocusInside(isDisabled ? undefined : ref); | ||
} | ||
MoveFocusInside.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -67,3 +53,2 @@ children: _propTypes["default"].node.isRequired, | ||
} : {}; | ||
var _default = MoveFocusInside; | ||
exports["default"] = _default; | ||
var _default = exports["default"] = MoveFocusInside; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,11 +8,5 @@ value: true | ||
exports["default"] = void 0; | ||
var _useSidecar = require("use-sidecar"); | ||
var _Trap = _interopRequireDefault(require("./Trap")); | ||
var _medium = require("./medium"); | ||
var _default = (0, _useSidecar.exportSidecar)(_medium.mediumSidecar, _Trap["default"]); | ||
exports["default"] = _default; | ||
var _default = exports["default"] = (0, _useSidecar.exportSidecar)(_medium.mediumSidecar, _Trap["default"]); |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,25 +9,17 @@ value: true | ||
exports["default"] = void 0; | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _reactClientsideEffect = _interopRequireDefault(require("react-clientside-effect")); | ||
var _focusLock = require("focus-lock"); | ||
var _util = require("./util"); | ||
var _medium = require("./medium"); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } | ||
var focusOnBody = function focusOnBody() { | ||
return document && document.activeElement === document.body; | ||
}; | ||
var isFreeFocus = function isFreeFocus() { | ||
return focusOnBody() || (0, _focusLock.focusIsHidden)(); | ||
}; | ||
var lastActiveTrap = null; | ||
@@ -39,11 +29,8 @@ var lastActiveFocus = null; | ||
var focusWasOutsideWindow = false; | ||
var defaultWhitelist = function defaultWhitelist() { | ||
return true; | ||
}; | ||
var focusWhitelisted = function focusWhitelisted(activeElement) { | ||
return (lastActiveTrap.whiteList || defaultWhitelist)(activeElement); | ||
}; | ||
var recordPortal = function recordPortal(observerNode, portaledElement) { | ||
@@ -55,14 +42,10 @@ lastPortaledElement = { | ||
}; | ||
var focusIsPortaledPair = function focusIsPortaledPair(element) { | ||
return lastPortaledElement && lastPortaledElement.portaledElement === element; | ||
}; | ||
function autoGuard(startIndex, end, step, allNodes) { | ||
var lastGuard = null; | ||
var i = startIndex; | ||
do { | ||
var item = allNodes[i]; | ||
if (item.guard) { | ||
@@ -76,3 +59,2 @@ if (item.node.dataset.focusAutoGuard) { | ||
} | ||
lastGuard = null; | ||
@@ -83,3 +65,2 @@ } else { | ||
} while ((i += step) !== end); | ||
if (lastGuard) { | ||
@@ -89,7 +70,5 @@ lastGuard.node.tabIndex = 0; | ||
} | ||
var extractRef = function extractRef(ref) { | ||
return ref && 'current' in ref ? ref.current : ref; | ||
}; | ||
var focusWasOutside = function focusWasOutside(crossFrameOption) { | ||
@@ -99,10 +78,7 @@ if (crossFrameOption) { | ||
} | ||
return focusWasOutsideWindow === 'meanwhile'; | ||
}; | ||
var checkInHost = function checkInHost(check, el, boundary) { | ||
return el && (el.host === check && (!el.activeElement || boundary.contains(el.activeElement)) || el.parentNode && checkInHost(check, el.parentNode, boundary)); | ||
}; | ||
var withinHost = function withinHost(activeElement, workingArea) { | ||
@@ -113,20 +89,16 @@ return workingArea.some(function (area) { | ||
}; | ||
var activateTrap = function activateTrap() { | ||
var result = false; | ||
if (lastActiveTrap) { | ||
var _lastActiveTrap = lastActiveTrap, | ||
observed = _lastActiveTrap.observed, | ||
persistentFocus = _lastActiveTrap.persistentFocus, | ||
autoFocus = _lastActiveTrap.autoFocus, | ||
shards = _lastActiveTrap.shards, | ||
crossFrame = _lastActiveTrap.crossFrame, | ||
focusOptions = _lastActiveTrap.focusOptions; | ||
observed = _lastActiveTrap.observed, | ||
persistentFocus = _lastActiveTrap.persistentFocus, | ||
autoFocus = _lastActiveTrap.autoFocus, | ||
shards = _lastActiveTrap.shards, | ||
crossFrame = _lastActiveTrap.crossFrame, | ||
focusOptions = _lastActiveTrap.focusOptions; | ||
var workingNode = observed || lastPortaledElement && lastPortaledElement.portaledElement; | ||
var activeElement = document && document.activeElement; | ||
if (workingNode) { | ||
var workingArea = [workingNode].concat((0, _toConsumableArray2["default"])(shards.map(extractRef).filter(Boolean))); | ||
if (!activeElement || focusWhitelisted(activeElement)) { | ||
@@ -139,3 +111,2 @@ if (persistentFocus || focusWasOutside(crossFrame) || !isFreeFocus() || !lastActiveFocus && autoFocus) { | ||
} | ||
document.body.focus(); | ||
@@ -149,3 +120,2 @@ } else { | ||
} | ||
focusWasOutsideWindow = false; | ||
@@ -155,3 +125,2 @@ lastActiveFocus = document && document.activeElement; | ||
} | ||
if (document) { | ||
@@ -164,7 +133,6 @@ var newActiveElement = document && document.activeElement; | ||
}).indexOf(newActiveElement); | ||
if (focusedIndex > -1) { | ||
allNodes.filter(function (_ref2) { | ||
var guard = _ref2.guard, | ||
node = _ref2.node; | ||
node = _ref2.node; | ||
return guard && node.dataset.focusAutoGuard; | ||
@@ -181,6 +149,4 @@ }).forEach(function (_ref3) { | ||
} | ||
return result; | ||
}; | ||
var onTrap = function onTrap(event) { | ||
@@ -192,11 +158,8 @@ if (activateTrap() && event) { | ||
}; | ||
var onBlur = function onBlur() { | ||
return (0, _util.deferAction)(activateTrap); | ||
}; | ||
var onFocus = function onFocus(event) { | ||
var source = event.target; | ||
var currentNode = event.currentTarget; | ||
if (!currentNode.contains(source)) { | ||
@@ -206,7 +169,5 @@ recordPortal(currentNode, source); | ||
}; | ||
var FocusWatcher = function FocusWatcher() { | ||
return null; | ||
}; | ||
var FocusTrap = function FocusTrap(_ref4) { | ||
@@ -219,7 +180,5 @@ var children = _ref4.children; | ||
}; | ||
FocusTrap.propTypes = process.env.NODE_ENV !== "production" ? { | ||
children: _propTypes["default"].node.isRequired | ||
} : {}; | ||
var onWindowBlur = function onWindowBlur() { | ||
@@ -231,3 +190,2 @@ focusWasOutsideWindow = 'just'; | ||
}; | ||
var attachHandler = function attachHandler() { | ||
@@ -238,3 +196,2 @@ document.addEventListener('focusin', onTrap); | ||
}; | ||
var detachHandler = function detachHandler() { | ||
@@ -245,3 +202,2 @@ document.removeEventListener('focusin', onTrap); | ||
}; | ||
function reducePropsToState(propsList) { | ||
@@ -253,17 +209,12 @@ return propsList.filter(function (_ref5) { | ||
} | ||
function handleStateChangeOnClient(traps) { | ||
var trap = traps.slice(-1)[0]; | ||
if (trap && !lastActiveTrap) { | ||
attachHandler(); | ||
} | ||
var lastTrap = lastActiveTrap; | ||
var sameTrap = lastTrap && trap && trap.id === lastTrap.id; | ||
lastActiveTrap = trap; | ||
if (lastTrap && !sameTrap) { | ||
lastTrap.onDeactivation(); | ||
if (!traps.filter(function (_ref6) { | ||
@@ -276,10 +227,7 @@ var id = _ref6.id; | ||
} | ||
if (trap) { | ||
lastActiveFocus = null; | ||
if (!sameTrap || lastTrap.observed !== trap.observed) { | ||
trap.onActivation(); | ||
} | ||
activateTrap(true); | ||
@@ -292,7 +240,4 @@ (0, _util.deferAction)(activateTrap); | ||
} | ||
_medium.mediumFocus.assignSyncMedium(onFocus); | ||
_medium.mediumBlur.assignMedium(onBlur); | ||
_medium.mediumEffect.assignMedium(function (cb) { | ||
@@ -304,5 +249,2 @@ return cb({ | ||
}); | ||
var _default = (0, _reactClientsideEffect["default"])(reducePropsToState, handleStateChangeOnClient)(FocusWatcher); | ||
exports["default"] = _default; | ||
var _default = exports["default"] = (0, _reactClientsideEffect["default"])(reducePropsToState, handleStateChangeOnClient)(FocusWatcher); |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "FocusLockUI", { | ||
Object.defineProperty(exports, "AutoFocusInside", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Lock["default"]; | ||
return _AutoFocusInside["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "AutoFocusInside", { | ||
Object.defineProperty(exports, "FocusLockUI", { | ||
enumerable: true, | ||
get: function get() { | ||
return _AutoFocusInside["default"]; | ||
return _Lock["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "MoveFocusInside", { | ||
Object.defineProperty(exports, "FreeFocusInside", { | ||
enumerable: true, | ||
get: function get() { | ||
return _MoveFocusInside["default"]; | ||
return _FreeFocusInside["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useFocusInside", { | ||
Object.defineProperty(exports, "InFocusGuard", { | ||
enumerable: true, | ||
get: function get() { | ||
return _MoveFocusInside.useFocusInside; | ||
return _FocusGuard["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "FreeFocusInside", { | ||
Object.defineProperty(exports, "MoveFocusInside", { | ||
enumerable: true, | ||
get: function get() { | ||
return _FreeFocusInside["default"]; | ||
return _MoveFocusInside["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "InFocusGuard", { | ||
exports["default"] = void 0; | ||
Object.defineProperty(exports, "useFocusInside", { | ||
enumerable: true, | ||
get: function get() { | ||
return _FocusGuard["default"]; | ||
return _MoveFocusInside.useFocusInside; | ||
} | ||
}); | ||
exports["default"] = void 0; | ||
var _Lock = _interopRequireDefault(require("./Lock")); | ||
var _AutoFocusInside = _interopRequireDefault(require("./AutoFocusInside")); | ||
var _MoveFocusInside = _interopRequireWildcard(require("./MoveFocusInside")); | ||
var _FreeFocusInside = _interopRequireDefault(require("./FreeFocusInside")); | ||
var _FocusGuard = _interopRequireDefault(require("./FocusGuard")); | ||
var _default = _Lock["default"]; | ||
exports["default"] = _default; | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } | ||
var _default = exports["default"] = _Lock["default"]; |
@@ -8,13 +8,9 @@ "use strict"; | ||
exports.inlineProp = void 0; | ||
function deferAction(action) { | ||
setTimeout(action, 1); | ||
} | ||
var inlineProp = function inlineProp(name, value) { | ||
var inlineProp = exports.inlineProp = function inlineProp(name, value) { | ||
var obj = {}; | ||
obj[name] = value; | ||
return obj; | ||
}; | ||
exports.inlineProp = inlineProp; | ||
}; |
@@ -6,9 +6,8 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import { inlineProp } from './util'; | ||
var AutoFocusInside = function AutoFocusInside(_ref) { | ||
var _ref$disabled = _ref.disabled, | ||
disabled = _ref$disabled === void 0 ? false : _ref$disabled, | ||
children = _ref.children, | ||
_ref$className = _ref.className, | ||
className = _ref$className === void 0 ? undefined : _ref$className; | ||
disabled = _ref$disabled === void 0 ? false : _ref$disabled, | ||
children = _ref.children, | ||
_ref$className = _ref.className, | ||
className = _ref$className === void 0 ? undefined : _ref$className; | ||
return /*#__PURE__*/React.createElement("div", _extends({}, inlineProp(constants.FOCUS_AUTO, !disabled), { | ||
@@ -18,3 +17,2 @@ className: className | ||
}; | ||
AutoFocusInside.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -21,0 +19,0 @@ children: PropTypes.node.isRequired, |
import * as React from 'react'; | ||
function withSideEffect(reducePropsToState, handleStateChangeOnClient) { | ||
@@ -8,3 +7,2 @@ if (process.env.NODE_ENV !== 'production') { | ||
} | ||
if (typeof handleStateChangeOnClient !== 'function') { | ||
@@ -14,3 +12,2 @@ throw new Error('Expected handleStateChangeOnClient to be a function.'); | ||
} | ||
return function wrap(WrappedComponent) { | ||
@@ -22,5 +19,3 @@ if (process.env.NODE_ENV !== 'production') { | ||
} | ||
var mountedInstances = []; | ||
function emitChange() { | ||
@@ -33,3 +28,2 @@ console.log('emitting'); | ||
} | ||
var SideEffect = function SideEffect(props) { | ||
@@ -51,7 +45,5 @@ var lastProps = React.useRef(props); | ||
}; | ||
return SideEffect; | ||
}; | ||
} | ||
export default withSideEffect; |
@@ -12,8 +12,6 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; | ||
}); | ||
var _ref = FocusLockUI.propTypes || {}, | ||
sideCar = _ref.sideCar, | ||
propTypes = _objectWithoutPropertiesLoose(_ref, ["sideCar"]); | ||
sideCar = _ref.sideCar, | ||
propTypes = _objectWithoutPropertiesLoose(_ref, ["sideCar"]); | ||
FocusLockCombination.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {}; | ||
export default FocusLockCombination; |
@@ -12,6 +12,5 @@ import * as React from 'react'; | ||
}; | ||
var InFocusGuard = function InFocusGuard(_ref) { | ||
var _ref$children = _ref.children, | ||
children = _ref$children === void 0 ? null : _ref$children; | ||
children = _ref$children === void 0 ? null : _ref$children; | ||
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", { | ||
@@ -29,3 +28,2 @@ key: "guard-first", | ||
}; | ||
InFocusGuard.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -32,0 +30,0 @@ children: PropTypes.node |
@@ -6,6 +6,5 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import { inlineProp } from './util'; | ||
var FreeFocusInside = function FreeFocusInside(_ref) { | ||
var children = _ref.children, | ||
className = _ref.className; | ||
className = _ref.className; | ||
return /*#__PURE__*/React.createElement("div", _extends({}, inlineProp(constants.FOCUS_ALLOW, true), { | ||
@@ -15,3 +14,2 @@ className: className | ||
}; | ||
FreeFocusInside.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -18,0 +16,0 @@ children: PropTypes.node.isRequired, |
@@ -12,7 +12,5 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
var _extends2; | ||
var _React$useState = React.useState(), | ||
realObserved = _React$useState[0], | ||
setObserved = _React$useState[1]; | ||
realObserved = _React$useState[0], | ||
setObserved = _React$useState[1]; | ||
var observed = React.useRef(); | ||
@@ -22,40 +20,36 @@ var isActive = React.useRef(false); | ||
var children = props.children, | ||
_props$disabled = props.disabled, | ||
disabled = _props$disabled === void 0 ? false : _props$disabled, | ||
_props$noFocusGuards = props.noFocusGuards, | ||
noFocusGuards = _props$noFocusGuards === void 0 ? false : _props$noFocusGuards, | ||
_props$persistentFocu = props.persistentFocus, | ||
persistentFocus = _props$persistentFocu === void 0 ? false : _props$persistentFocu, | ||
_props$crossFrame = props.crossFrame, | ||
crossFrame = _props$crossFrame === void 0 ? true : _props$crossFrame, | ||
_props$autoFocus = props.autoFocus, | ||
autoFocus = _props$autoFocus === void 0 ? true : _props$autoFocus, | ||
allowTextSelection = props.allowTextSelection, | ||
group = props.group, | ||
className = props.className, | ||
whiteList = props.whiteList, | ||
hasPositiveIndices = props.hasPositiveIndices, | ||
_props$shards = props.shards, | ||
shards = _props$shards === void 0 ? emptyArray : _props$shards, | ||
_props$as = props.as, | ||
Container = _props$as === void 0 ? 'div' : _props$as, | ||
_props$lockProps = props.lockProps, | ||
containerProps = _props$lockProps === void 0 ? {} : _props$lockProps, | ||
SideCar = props.sideCar, | ||
_props$returnFocus = props.returnFocus, | ||
shouldReturnFocus = _props$returnFocus === void 0 ? false : _props$returnFocus, | ||
focusOptions = props.focusOptions, | ||
onActivationCallback = props.onActivation, | ||
onDeactivationCallback = props.onDeactivation; | ||
_props$disabled = props.disabled, | ||
disabled = _props$disabled === void 0 ? false : _props$disabled, | ||
_props$noFocusGuards = props.noFocusGuards, | ||
noFocusGuards = _props$noFocusGuards === void 0 ? false : _props$noFocusGuards, | ||
_props$persistentFocu = props.persistentFocus, | ||
persistentFocus = _props$persistentFocu === void 0 ? false : _props$persistentFocu, | ||
_props$crossFrame = props.crossFrame, | ||
crossFrame = _props$crossFrame === void 0 ? true : _props$crossFrame, | ||
_props$autoFocus = props.autoFocus, | ||
autoFocus = _props$autoFocus === void 0 ? true : _props$autoFocus, | ||
allowTextSelection = props.allowTextSelection, | ||
group = props.group, | ||
className = props.className, | ||
whiteList = props.whiteList, | ||
hasPositiveIndices = props.hasPositiveIndices, | ||
_props$shards = props.shards, | ||
shards = _props$shards === void 0 ? emptyArray : _props$shards, | ||
_props$as = props.as, | ||
Container = _props$as === void 0 ? 'div' : _props$as, | ||
_props$lockProps = props.lockProps, | ||
containerProps = _props$lockProps === void 0 ? {} : _props$lockProps, | ||
SideCar = props.sideCar, | ||
_props$returnFocus = props.returnFocus, | ||
shouldReturnFocus = _props$returnFocus === void 0 ? false : _props$returnFocus, | ||
focusOptions = props.focusOptions, | ||
onActivationCallback = props.onActivation, | ||
onDeactivationCallback = props.onDeactivation; | ||
var _React$useState2 = React.useState({}), | ||
id = _React$useState2[0]; | ||
id = _React$useState2[0]; | ||
var onActivation = React.useCallback(function () { | ||
originalFocusedElement.current = originalFocusedElement.current || document && document.activeElement; | ||
if (observed.current && onActivationCallback) { | ||
onActivationCallback(observed.current); | ||
} | ||
isActive.current = true; | ||
@@ -65,3 +59,2 @@ }, [onActivationCallback]); | ||
isActive.current = false; | ||
if (onDeactivationCallback) { | ||
@@ -78,10 +71,7 @@ onDeactivationCallback(observed.current); | ||
var returnFocusTo = originalFocusedElement.current; | ||
if (returnFocusTo && returnFocusTo.focus) { | ||
var howToReturnFocus = typeof shouldReturnFocus === 'function' ? shouldReturnFocus(returnFocusTo) : shouldReturnFocus; | ||
if (howToReturnFocus) { | ||
var returnFocusOptions = typeof howToReturnFocus === 'object' ? howToReturnFocus : undefined; | ||
originalFocusedElement.current = null; | ||
if (allowDefer) { | ||
@@ -109,3 +99,2 @@ Promise.resolve().then(function () { | ||
}, []); | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -115,3 +104,2 @@ if (typeof allowTextSelection !== 'undefined') { | ||
} | ||
React.useEffect(function () { | ||
@@ -123,5 +111,3 @@ if (!observed.current && typeof Container !== 'string') { | ||
} | ||
var lockProps = _extends((_extends2 = {}, _extends2[constants.FOCUS_DISABLED] = disabled && 'disabled', _extends2[constants.FOCUS_GROUP] = group, _extends2), containerProps); | ||
var hasLeadingGuards = noFocusGuards !== true; | ||
@@ -128,0 +114,0 @@ var hasTailingGuards = hasLeadingGuards && noFocusGuards !== 'tail'; |
import { createMedium, createSidecarMedium } from 'use-sidecar'; | ||
export var mediumFocus = createMedium({}, function (_ref) { | ||
var target = _ref.target, | ||
currentTarget = _ref.currentTarget; | ||
currentTarget = _ref.currentTarget; | ||
return { | ||
@@ -6,0 +6,0 @@ target: target, |
@@ -12,3 +12,2 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
var observed = observedRef && observedRef.current; | ||
if (enabled && observed) { | ||
@@ -25,8 +24,7 @@ if (!car.focusInside(observed)) { | ||
}; | ||
function MoveFocusInside(_ref) { | ||
var _ref$disabled = _ref.disabled, | ||
isDisabled = _ref$disabled === void 0 ? false : _ref$disabled, | ||
className = _ref.className, | ||
children = _ref.children; | ||
isDisabled = _ref$disabled === void 0 ? false : _ref$disabled, | ||
className = _ref.className, | ||
children = _ref.children; | ||
var ref = React.useRef(null); | ||
@@ -39,3 +37,2 @@ useFocusInside(isDisabled ? undefined : ref); | ||
} | ||
MoveFocusInside.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -42,0 +39,0 @@ children: PropTypes.node.isRequired, |
@@ -7,11 +7,8 @@ import * as React from 'react'; | ||
import { mediumFocus, mediumBlur, mediumEffect } from './medium'; | ||
var focusOnBody = function focusOnBody() { | ||
return document && document.activeElement === document.body; | ||
}; | ||
var isFreeFocus = function isFreeFocus() { | ||
return focusOnBody() || focusIsHidden(); | ||
}; | ||
var lastActiveTrap = null; | ||
@@ -21,11 +18,8 @@ var lastActiveFocus = null; | ||
var focusWasOutsideWindow = false; | ||
var defaultWhitelist = function defaultWhitelist() { | ||
return true; | ||
}; | ||
var focusWhitelisted = function focusWhitelisted(activeElement) { | ||
return (lastActiveTrap.whiteList || defaultWhitelist)(activeElement); | ||
}; | ||
var recordPortal = function recordPortal(observerNode, portaledElement) { | ||
@@ -37,14 +31,10 @@ lastPortaledElement = { | ||
}; | ||
var focusIsPortaledPair = function focusIsPortaledPair(element) { | ||
return lastPortaledElement && lastPortaledElement.portaledElement === element; | ||
}; | ||
function autoGuard(startIndex, end, step, allNodes) { | ||
var lastGuard = null; | ||
var i = startIndex; | ||
do { | ||
var item = allNodes[i]; | ||
if (item.guard) { | ||
@@ -58,3 +48,2 @@ if (item.node.dataset.focusAutoGuard) { | ||
} | ||
lastGuard = null; | ||
@@ -65,3 +54,2 @@ } else { | ||
} while ((i += step) !== end); | ||
if (lastGuard) { | ||
@@ -71,7 +59,5 @@ lastGuard.node.tabIndex = 0; | ||
} | ||
var extractRef = function extractRef(ref) { | ||
return ref && 'current' in ref ? ref.current : ref; | ||
}; | ||
var focusWasOutside = function focusWasOutside(crossFrameOption) { | ||
@@ -81,10 +67,7 @@ if (crossFrameOption) { | ||
} | ||
return focusWasOutsideWindow === 'meanwhile'; | ||
}; | ||
var checkInHost = function checkInHost(check, el, boundary) { | ||
return el && (el.host === check && (!el.activeElement || boundary.contains(el.activeElement)) || el.parentNode && checkInHost(check, el.parentNode, boundary)); | ||
}; | ||
var withinHost = function withinHost(activeElement, workingArea) { | ||
@@ -95,20 +78,16 @@ return workingArea.some(function (area) { | ||
}; | ||
var activateTrap = function activateTrap() { | ||
var result = false; | ||
if (lastActiveTrap) { | ||
var _lastActiveTrap = lastActiveTrap, | ||
observed = _lastActiveTrap.observed, | ||
persistentFocus = _lastActiveTrap.persistentFocus, | ||
autoFocus = _lastActiveTrap.autoFocus, | ||
shards = _lastActiveTrap.shards, | ||
crossFrame = _lastActiveTrap.crossFrame, | ||
focusOptions = _lastActiveTrap.focusOptions; | ||
observed = _lastActiveTrap.observed, | ||
persistentFocus = _lastActiveTrap.persistentFocus, | ||
autoFocus = _lastActiveTrap.autoFocus, | ||
shards = _lastActiveTrap.shards, | ||
crossFrame = _lastActiveTrap.crossFrame, | ||
focusOptions = _lastActiveTrap.focusOptions; | ||
var workingNode = observed || lastPortaledElement && lastPortaledElement.portaledElement; | ||
var activeElement = document && document.activeElement; | ||
if (workingNode) { | ||
var workingArea = [workingNode].concat(shards.map(extractRef).filter(Boolean)); | ||
if (!activeElement || focusWhitelisted(activeElement)) { | ||
@@ -121,3 +100,2 @@ if (persistentFocus || focusWasOutside(crossFrame) || !isFreeFocus() || !lastActiveFocus && autoFocus) { | ||
} | ||
document.body.focus(); | ||
@@ -131,3 +109,2 @@ } else { | ||
} | ||
focusWasOutsideWindow = false; | ||
@@ -137,3 +114,2 @@ lastActiveFocus = document && document.activeElement; | ||
} | ||
if (document) { | ||
@@ -146,7 +122,6 @@ var newActiveElement = document && document.activeElement; | ||
}).indexOf(newActiveElement); | ||
if (focusedIndex > -1) { | ||
allNodes.filter(function (_ref2) { | ||
var guard = _ref2.guard, | ||
node = _ref2.node; | ||
node = _ref2.node; | ||
return guard && node.dataset.focusAutoGuard; | ||
@@ -163,6 +138,4 @@ }).forEach(function (_ref3) { | ||
} | ||
return result; | ||
}; | ||
var onTrap = function onTrap(event) { | ||
@@ -174,11 +147,8 @@ if (activateTrap() && event) { | ||
}; | ||
var onBlur = function onBlur() { | ||
return deferAction(activateTrap); | ||
}; | ||
var onFocus = function onFocus(event) { | ||
var source = event.target; | ||
var currentNode = event.currentTarget; | ||
if (!currentNode.contains(source)) { | ||
@@ -188,7 +158,5 @@ recordPortal(currentNode, source); | ||
}; | ||
var FocusWatcher = function FocusWatcher() { | ||
return null; | ||
}; | ||
var FocusTrap = function FocusTrap(_ref4) { | ||
@@ -201,7 +169,5 @@ var children = _ref4.children; | ||
}; | ||
FocusTrap.propTypes = process.env.NODE_ENV !== "production" ? { | ||
children: PropTypes.node.isRequired | ||
} : {}; | ||
var onWindowBlur = function onWindowBlur() { | ||
@@ -213,3 +179,2 @@ focusWasOutsideWindow = 'just'; | ||
}; | ||
var attachHandler = function attachHandler() { | ||
@@ -220,3 +185,2 @@ document.addEventListener('focusin', onTrap); | ||
}; | ||
var detachHandler = function detachHandler() { | ||
@@ -227,3 +191,2 @@ document.removeEventListener('focusin', onTrap); | ||
}; | ||
function reducePropsToState(propsList) { | ||
@@ -235,17 +198,12 @@ return propsList.filter(function (_ref5) { | ||
} | ||
function handleStateChangeOnClient(traps) { | ||
var trap = traps.slice(-1)[0]; | ||
if (trap && !lastActiveTrap) { | ||
attachHandler(); | ||
} | ||
var lastTrap = lastActiveTrap; | ||
var sameTrap = lastTrap && trap && trap.id === lastTrap.id; | ||
lastActiveTrap = trap; | ||
if (lastTrap && !sameTrap) { | ||
lastTrap.onDeactivation(); | ||
if (!traps.filter(function (_ref6) { | ||
@@ -258,10 +216,7 @@ var id = _ref6.id; | ||
} | ||
if (trap) { | ||
lastActiveFocus = null; | ||
if (!sameTrap || lastTrap.observed !== trap.observed) { | ||
trap.onActivation(); | ||
} | ||
activateTrap(true); | ||
@@ -274,3 +229,2 @@ deferAction(activateTrap); | ||
} | ||
mediumFocus.assignSyncMedium(onFocus); | ||
@@ -277,0 +231,0 @@ mediumBlur.assignMedium(onBlur); |
{ | ||
"name": "react-focus-lock", | ||
"version": "2.9.7", | ||
"version": "2.9.8", | ||
"description": "It is a trap! (for a focus)", | ||
@@ -104,3 +104,3 @@ "main": "dist/cjs/index.js", | ||
"@babel/runtime": "^7.0.0", | ||
"focus-lock": "^1.0.0", | ||
"focus-lock": "^1.0.1", | ||
"prop-types": "^15.6.2", | ||
@@ -107,0 +107,0 @@ "react-clientside-effect": "^1.2.6", |
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
80244
1481
Updatedfocus-lock@^1.0.1