react-focus-lock
Advanced tools
Comparing version 1.16.1 to 1.16.2
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,19 +6,16 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = void 0; | ||
var _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; }; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _react = require('react'); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _focusLock = require("focus-lock"); | ||
var _propTypes = require('prop-types'); | ||
var _util = require("./util"); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _focusLock = require('focus-lock'); | ||
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); } | ||
var _util = require('./util'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var AutoFocusInside = function AutoFocusInside(_ref) { | ||
@@ -28,7 +25,5 @@ var disabled = _ref.disabled, | ||
className = _ref.className; | ||
return _react2.default.createElement( | ||
'div', | ||
_extends({}, (0, _util.inlineProp)(_focusLock.constants.FOCUS_AUTO, !disabled), { className: className }), | ||
children | ||
); | ||
return _react.default.createElement("div", _extends({}, (0, _util.inlineProp)(_focusLock.constants.FOCUS_AUTO, !disabled), { | ||
className: className | ||
}), children); | ||
}; | ||
@@ -38,5 +33,5 @@ | ||
AutoFocusInside.propTypes = { | ||
children: _propTypes2.default.node.isRequired, | ||
disabled: _propTypes2.default.bool, | ||
className: _propTypes2.default.string | ||
children: _propTypes.default.node.isRequired, | ||
disabled: _propTypes.default.bool, | ||
className: _propTypes.default.string | ||
}; | ||
@@ -49,3 +44,3 @@ } | ||
}; | ||
exports.default = AutoFocusInside; | ||
var _default = AutoFocusInside; | ||
exports.default = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,27 +6,22 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = void 0; | ||
var _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; }; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _react = require('react'); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _focusLock = require("focus-lock"); | ||
var _propTypes = require('prop-types'); | ||
var _util = require("./util"); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _focusLock = require('focus-lock'); | ||
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); } | ||
var _util = require('./util'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var FreeFocusInside = function FreeFocusInside(_ref) { | ||
var children = _ref.children, | ||
className = _ref.className; | ||
return _react2.default.createElement( | ||
'div', | ||
_extends({}, (0, _util.inlineProp)(_focusLock.constants.FOCUS_ALLOW, true), { className: className }), | ||
children | ||
); | ||
return _react.default.createElement("div", _extends({}, (0, _util.inlineProp)(_focusLock.constants.FOCUS_ALLOW, true), { | ||
className: className | ||
}), children); | ||
}; | ||
@@ -36,4 +31,4 @@ | ||
FreeFocusInside.propTypes = { | ||
children: _propTypes2.default.node.isRequired, | ||
className: _propTypes2.default.string | ||
children: _propTypes.default.node.isRequired, | ||
className: _propTypes.default.string | ||
}; | ||
@@ -46,3 +41,3 @@ } | ||
}; | ||
exports.default = FreeFocusInside; | ||
var _default = FreeFocusInside; | ||
exports.default = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,25 +6,33 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.FreeFocusInside = exports.MoveFocusInside = exports.AutoFocusInside = undefined; | ||
Object.defineProperty(exports, "AutoFocusInside", { | ||
enumerable: true, | ||
get: function get() { | ||
return _AutoFocusInside.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "MoveFocusInside", { | ||
enumerable: true, | ||
get: function get() { | ||
return _MoveFocusInside.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "FreeFocusInside", { | ||
enumerable: true, | ||
get: function get() { | ||
return _FreeFocusInside.default; | ||
} | ||
}); | ||
exports.default = void 0; | ||
var _Lock = require('./Lock'); | ||
var _Lock = _interopRequireDefault(require("./Lock")); | ||
var _Lock2 = _interopRequireDefault(_Lock); | ||
var _AutoFocusInside = _interopRequireDefault(require("./AutoFocusInside")); | ||
var _AutoFocusInside = require('./AutoFocusInside'); | ||
var _MoveFocusInside = _interopRequireDefault(require("./MoveFocusInside")); | ||
var _AutoFocusInside2 = _interopRequireDefault(_AutoFocusInside); | ||
var _FreeFocusInside = _interopRequireDefault(require("./FreeFocusInside")); | ||
var _MoveFocusInside = require('./MoveFocusInside'); | ||
var _MoveFocusInside2 = _interopRequireDefault(_MoveFocusInside); | ||
var _FreeFocusInside = require('./FreeFocusInside'); | ||
var _FreeFocusInside2 = _interopRequireDefault(_FreeFocusInside); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.AutoFocusInside = _AutoFocusInside2.default; | ||
exports.MoveFocusInside = _MoveFocusInside2.default; | ||
exports.FreeFocusInside = _FreeFocusInside2.default; | ||
exports.default = _Lock2.default; | ||
var _default = _Lock.default; | ||
exports.default = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,44 +6,49 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = void 0; | ||
var _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; }; | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _react = require('react'); | ||
var _focusLock = require("focus-lock"); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _Trap = _interopRequireWildcard(require("./Trap")); | ||
var _propTypes = require('prop-types'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
var _focusLock = require('focus-lock'); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _Trap = require('./Trap'); | ||
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); } | ||
var _Trap2 = _interopRequireDefault(_Trap); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var RenderChildren = function RenderChildren(_ref) { | ||
var children = _ref.children; | ||
return _react2.default.createElement( | ||
'div', | ||
null, | ||
children | ||
); | ||
return _react.default.createElement("div", null, children); | ||
}; | ||
RenderChildren.propTypes = { | ||
children: _propTypes2.default.node.isRequired | ||
children: _propTypes.default.node.isRequired | ||
}; | ||
var Fragment = _react2.default.Fragment ? _react2.default.Fragment : RenderChildren; | ||
var Fragment = _react.default.Fragment ? _react.default.Fragment : RenderChildren; | ||
var hidden = { | ||
@@ -59,36 +64,51 @@ width: '1px', | ||
var FocusLock = function (_Component) { | ||
var FocusLock = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(FocusLock, _Component); | ||
function FocusLock() { | ||
var _ref2; | ||
var _getPrototypeOf2; | ||
var _temp, _this, _ret; | ||
var _this; | ||
_classCallCheck(this, FocusLock); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref2 = FocusLock.__proto__ || Object.getPrototypeOf(FocusLock)).call.apply(_ref2, [this].concat(args))), _this), _this.state = { | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(FocusLock)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", { | ||
observed: undefined | ||
}, _this.onActivation = function () { | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onActivation", function () { | ||
_this.originalFocusedElement = _this.originalFocusedElement || document && document.activeElement; | ||
if (_this.state.observed && _this.props.onActivation) { | ||
_this.props.onActivation(_this.state.observed); | ||
} | ||
}, _this.onDeactivation = function () { | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onDeactivation", function () { | ||
if (_this.props.returnFocus && _this.originalFocusedElement && _this.originalFocusedElement.focus) { | ||
_this.originalFocusedElement.focus(); | ||
_this.originalFocusedElement = null; | ||
} | ||
if (_this.props.onDeactivation) { | ||
_this.props.onDeactivation(_this.state.observed); | ||
} | ||
}, _this.setObserveNode = function (observed) { | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "setObserveNode", function (observed) { | ||
return _this.setState({ | ||
observed: observed | ||
}); | ||
}, _this.update = function () { | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "update", function () { | ||
return _this.setState(function (prevState) { | ||
@@ -99,27 +119,30 @@ return { | ||
}); | ||
}, _this.originalFocusedElement = null, _temp), _possibleConstructorReturn(_this, _ret); | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "originalFocusedElement", null); | ||
return _this; | ||
} | ||
_createClass(FocusLock, [{ | ||
key: 'render', | ||
key: "render", | ||
value: function render() { | ||
var _Object$assign; | ||
var _objectSpread2; | ||
var _props = this.props, | ||
children = _props.children, | ||
disabled = _props.disabled, | ||
noFocusGuards = _props.noFocusGuards, | ||
persistentFocus = _props.persistentFocus, | ||
autoFocus = _props.autoFocus, | ||
allowTextSelection = _props.allowTextSelection, | ||
group = _props.group, | ||
className = _props.className, | ||
whiteList = _props.whiteList, | ||
_props$as = _props.as, | ||
Container = _props$as === undefined ? 'div' : _props$as, | ||
_props$lockProps = _props.lockProps, | ||
containerProps = _props$lockProps === undefined ? {} : _props$lockProps; | ||
var _this$props = this.props, | ||
children = _this$props.children, | ||
disabled = _this$props.disabled, | ||
noFocusGuards = _this$props.noFocusGuards, | ||
persistentFocus = _this$props.persistentFocus, | ||
autoFocus = _this$props.autoFocus, | ||
allowTextSelection = _this$props.allowTextSelection, | ||
group = _this$props.group, | ||
className = _this$props.className, | ||
whiteList = _this$props.whiteList, | ||
_this$props$as = _this$props.as, | ||
Container = _this$props$as === void 0 ? 'div' : _this$props$as, | ||
_this$props$lockProps = _this$props.lockProps, | ||
containerProps = _this$props$lockProps === void 0 ? {} : _this$props$lockProps; | ||
var observed = this.state.observed; | ||
if (typeof allowTextSelection !== 'undefined') { | ||
@@ -130,31 +153,34 @@ // eslint-disable-next-line no-console | ||
var lockProps = Object.assign((_Object$assign = {}, _defineProperty(_Object$assign, _focusLock.constants.FOCUS_DISABLED, disabled && 'disabled'), _defineProperty(_Object$assign, _focusLock.constants.FOCUS_GROUP, group), _Object$assign), containerProps); | ||
var lockProps = _objectSpread((_objectSpread2 = {}, _defineProperty(_objectSpread2, _focusLock.constants.FOCUS_DISABLED, disabled && 'disabled'), _defineProperty(_objectSpread2, _focusLock.constants.FOCUS_GROUP, group), _objectSpread2), containerProps); | ||
return _react2.default.createElement( | ||
Fragment, | ||
null, | ||
!noFocusGuards && [_react2.default.createElement('div', { key: 'guard-first', 'data-focus-guard': true, tabIndex: disabled ? -1 : 0, style: hidden }), // nearest focus guard | ||
_react2.default.createElement('div', { key: 'guard-nearest', 'data-focus-guard': true, tabIndex: disabled ? -1 : 1, style: hidden })], | ||
_react2.default.createElement( | ||
Container, | ||
_extends({ | ||
ref: this.setObserveNode | ||
}, lockProps, { | ||
className: className, | ||
onBlur: _Trap.onBlur, | ||
onFocus: _Trap.onFocus | ||
}), | ||
_react2.default.createElement(_Trap2.default, { | ||
observed: observed, | ||
disabled: disabled, | ||
persistentFocus: persistentFocus, | ||
autoFocus: autoFocus, | ||
whiteList: whiteList, | ||
onActivation: this.onActivation, | ||
onDeactivation: this.onDeactivation | ||
}), | ||
children | ||
), | ||
!noFocusGuards && _react2.default.createElement('div', { 'data-focus-guard': true, tabIndex: disabled ? -1 : 0, style: hidden }) | ||
); | ||
return _react.default.createElement(Fragment, null, !noFocusGuards && [_react.default.createElement("div", { | ||
key: "guard-first", | ||
"data-focus-guard": true, | ||
tabIndex: disabled ? -1 : 0, | ||
style: hidden | ||
}), // nearest focus guard | ||
_react.default.createElement("div", { | ||
key: "guard-nearest", | ||
"data-focus-guard": true, | ||
tabIndex: disabled ? -1 : 1, | ||
style: hidden | ||
})], _react.default.createElement(Container, _extends({ | ||
ref: this.setObserveNode | ||
}, lockProps, { | ||
className: className, | ||
onBlur: _Trap.onBlur, | ||
onFocus: _Trap.onFocus | ||
}), _react.default.createElement(_Trap.default, { | ||
observed: observed, | ||
disabled: disabled, | ||
persistentFocus: persistentFocus, | ||
autoFocus: autoFocus, | ||
whiteList: whiteList, | ||
onActivation: this.onActivation, | ||
onDeactivation: this.onDeactivation | ||
}), children), !noFocusGuards && _react.default.createElement("div", { | ||
"data-focus-guard": true, | ||
tabIndex: disabled ? -1 : 0, | ||
style: hidden | ||
})); | ||
} | ||
@@ -168,21 +194,16 @@ }]); | ||
FocusLock.propTypes = { | ||
children: _propTypes2.default.node.isRequired, | ||
disabled: _propTypes2.default.bool, | ||
returnFocus: _propTypes2.default.bool, | ||
noFocusGuards: _propTypes2.default.bool, | ||
allowTextSelection: _propTypes2.default.bool, | ||
autoFocus: _propTypes2.default.bool, | ||
persistentFocus: _propTypes2.default.bool, | ||
group: _propTypes2.default.string, | ||
className: _propTypes2.default.string, | ||
whiteList: _propTypes2.default.func, | ||
as: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]), | ||
lockProps: _propTypes2.default.object, | ||
onActivation: _propTypes2.default.func, | ||
onDeactivation: _propTypes2.default.func | ||
children: _propTypes.default.node.isRequired, | ||
disabled: _propTypes.default.bool, | ||
returnFocus: _propTypes.default.bool, | ||
noFocusGuards: _propTypes.default.bool, | ||
allowTextSelection: _propTypes.default.bool, | ||
autoFocus: _propTypes.default.bool, | ||
persistentFocus: _propTypes.default.bool, | ||
group: _propTypes.default.string, | ||
className: _propTypes.default.string, | ||
whiteList: _propTypes.default.func, | ||
as: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func]), | ||
lockProps: _propTypes.default.object, | ||
onActivation: _propTypes.default.func, | ||
onDeactivation: _propTypes.default.func | ||
}; | ||
@@ -206,3 +227,3 @@ } | ||
}; | ||
exports.default = FocusLock; | ||
var _default = FocusLock; | ||
exports.default = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,51 +6,67 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = void 0; | ||
var _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; }; | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _react = require('react'); | ||
var _focusLock = _interopRequireWildcard(require("focus-lock")); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _util = require("./util"); | ||
var _propTypes = require('prop-types'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
var _focusLock = require('focus-lock'); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _focusLock2 = _interopRequireDefault(_focusLock); | ||
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); } | ||
var _util = require('./util'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var MoveFocusInside = function (_Component) { | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var MoveFocusInside = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(MoveFocusInside, _Component); | ||
function MoveFocusInside() { | ||
var _ref; | ||
var _getPrototypeOf2; | ||
var _temp, _this, _ret; | ||
var _this; | ||
_classCallCheck(this, MoveFocusInside); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = MoveFocusInside.__proto__ || Object.getPrototypeOf(MoveFocusInside)).call.apply(_ref, [this].concat(args))), _this), _this.setObserveNode = function (ref) { | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(MoveFocusInside)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "setObserveNode", function (ref) { | ||
_this.observed = ref; | ||
_this.moveFocus(); | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
}); | ||
return _this; | ||
} | ||
_createClass(MoveFocusInside, [{ | ||
key: 'componentDidMount', | ||
key: "componentDidMount", | ||
value: function componentDidMount() { | ||
@@ -60,3 +76,3 @@ this.moveFocus(); | ||
}, { | ||
key: 'componentDidUpdate', | ||
key: "componentDidUpdate", | ||
value: function componentDidUpdate(prevProps) { | ||
@@ -68,8 +84,9 @@ if (prevProps.disabled && !this.props.disabled) { | ||
}, { | ||
key: 'moveFocus', | ||
key: "moveFocus", | ||
value: function moveFocus() { | ||
var observed = this.observed; | ||
if (!this.props.disabled && observed) { | ||
if (!(0, _focusLock.focusInside)(observed)) { | ||
(0, _focusLock2.default)(observed, null); | ||
(0, _focusLock.default)(observed, null); | ||
} | ||
@@ -79,17 +96,12 @@ } | ||
}, { | ||
key: 'render', | ||
key: "render", | ||
value: function render() { | ||
var _props = this.props, | ||
children = _props.children, | ||
disabled = _props.disabled, | ||
className = _props.className; | ||
return _react2.default.createElement( | ||
'div', | ||
_extends({}, (0, _util.inlineProp)(_focusLock.constants.FOCUS_AUTO, !disabled), { | ||
ref: this.setObserveNode, | ||
className: className | ||
}), | ||
children | ||
); | ||
var _this$props = this.props, | ||
children = _this$props.children, | ||
disabled = _this$props.disabled, | ||
className = _this$props.className; | ||
return _react.default.createElement("div", _extends({}, (0, _util.inlineProp)(_focusLock.constants.FOCUS_AUTO, !disabled), { | ||
ref: this.setObserveNode, | ||
className: className | ||
}), children); | ||
} | ||
@@ -101,15 +113,15 @@ }]); | ||
MoveFocusInside.defaultProps = { | ||
exports.default = MoveFocusInside; | ||
_defineProperty(MoveFocusInside, "defaultProps", { | ||
disabled: false, | ||
className: undefined | ||
}; | ||
exports.default = MoveFocusInside; | ||
}); | ||
if (process.env.NODE_ENV !== 'production') { | ||
MoveFocusInside.propTypes = { | ||
children: _propTypes2.default.node.isRequired, | ||
disabled: _propTypes2.default.bool, | ||
className: _propTypes2.default.string | ||
children: _propTypes.default.node.isRequired, | ||
disabled: _propTypes.default.bool, | ||
className: _propTypes.default.string | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,22 +6,16 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.onFocus = exports.onBlur = undefined; | ||
exports.default = exports.onFocus = exports.onBlur = void 0; | ||
var _react = require('react'); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _propTypes = require('prop-types'); | ||
var _reactClientsideEffect = _interopRequireDefault(require("react-clientside-effect")); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
var _focusLock = _interopRequireWildcard(require("focus-lock")); | ||
var _reactClientsideEffect = require('react-clientside-effect'); | ||
var _util = require("./util"); | ||
var _reactClientsideEffect2 = _interopRequireDefault(_reactClientsideEffect); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
var _focusLock = require('focus-lock'); | ||
var _focusLock2 = _interopRequireDefault(_focusLock); | ||
var _util = require('./util'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -39,3 +33,2 @@ | ||
var lastActiveFocus = null; | ||
var lastPortaledElement = null; | ||
@@ -52,3 +45,6 @@ | ||
var recordPortal = function recordPortal(observerNode, portaledElement) { | ||
lastPortaledElement = { observerNode: observerNode, portaledElement: portaledElement }; | ||
lastPortaledElement = { | ||
observerNode: observerNode, | ||
portaledElement: portaledElement | ||
}; | ||
}; | ||
@@ -62,2 +58,3 @@ | ||
var result = false; | ||
if (lastActiveTrap) { | ||
@@ -68,3 +65,2 @@ var _lastActiveTrap = lastActiveTrap, | ||
autoFocus = _lastActiveTrap.autoFocus; | ||
var workingNode = observed || lastPortaledElement && lastPortaledElement.portaledElement; | ||
@@ -80,6 +76,7 @@ var activeElement = document && document.activeElement; | ||
} else { | ||
result = (0, _focusLock2.default)(workingNode, lastActiveFocus); | ||
result = (0, _focusLock.default)(workingNode, lastActiveFocus); | ||
lastPortaledElement = {}; | ||
} | ||
} | ||
lastActiveFocus = document && document.activeElement; | ||
@@ -89,2 +86,3 @@ } | ||
} | ||
return result; | ||
@@ -101,10 +99,13 @@ }; | ||
var onBlur = exports.onBlur = function onBlur() { | ||
var onBlur = function onBlur() { | ||
return (0, _util.deferAction)(activateTrap); | ||
}; | ||
var onFocus = exports.onFocus = function onFocus(event) { | ||
exports.onBlur = onBlur; | ||
var onFocus = function onFocus(event) { | ||
// detect portal | ||
var source = event.target; | ||
var currentNode = event.currentTarget; | ||
if (!currentNode.contains(source)) { | ||
@@ -115,2 +116,4 @@ recordPortal(currentNode, source); | ||
exports.onFocus = onFocus; | ||
var FocusWatcher = function FocusWatcher() { | ||
@@ -122,7 +125,6 @@ return null; | ||
var children = _ref.children; | ||
return _react2.default.createElement( | ||
'div', | ||
{ onBlur: onBlur, onFocus: onFocus }, | ||
children | ||
); | ||
return _react.default.createElement("div", { | ||
onBlur: onBlur, | ||
onFocus: onFocus | ||
}, children); | ||
}; | ||
@@ -132,3 +134,3 @@ | ||
FocusTrap.propTypes = { | ||
children: _propTypes2.default.node.isRequired | ||
children: _propTypes.default.node.isRequired | ||
}; | ||
@@ -161,3 +163,2 @@ } | ||
var sameTrap = lastTrap && trap && trap.onActivation === lastTrap.onActivation; | ||
lastActiveTrap = trap; | ||
@@ -171,5 +172,7 @@ | ||
lastActiveFocus = null; | ||
if (!sameTrap || lastTrap.observed !== trap.observed) { | ||
trap.onActivation(); | ||
} | ||
activateTrap(true); | ||
@@ -183,2 +186,4 @@ (0, _util.deferAction)(activateTrap); | ||
exports.default = (0, _reactClientsideEffect2.default)(reducePropsToState, handleStateChangeOnClient)(FocusWatcher); | ||
var _default = (0, _reactClientsideEffect.default)(reducePropsToState, handleStateChangeOnClient)(FocusWatcher); | ||
exports.default = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -7,2 +7,4 @@ Object.defineProperty(exports, "__esModule", { | ||
exports.deferAction = deferAction; | ||
exports.inlineProp = void 0; | ||
function deferAction(action) { | ||
@@ -16,6 +18,8 @@ if (typeof setImmediate !== 'undefined') { | ||
var inlineProp = exports.inlineProp = function inlineProp(name, value) { | ||
var inlineProp = function inlineProp(name, value) { | ||
var obj = {}; | ||
obj[name] = value; | ||
return obj; | ||
}; | ||
}; | ||
exports.inlineProp = inlineProp; |
@@ -1,2 +0,2 @@ | ||
var _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; }; | ||
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); } | ||
@@ -12,7 +12,5 @@ import React from 'react'; | ||
className = _ref.className; | ||
return React.createElement( | ||
'div', | ||
_extends({}, inlineProp(constants.FOCUS_AUTO, !disabled), { className: className }), | ||
children | ||
); | ||
return React.createElement("div", _extends({}, inlineProp(constants.FOCUS_AUTO, !disabled), { | ||
className: className | ||
}), children); | ||
}; | ||
@@ -32,3 +30,2 @@ | ||
}; | ||
export default AutoFocusInside; |
@@ -1,2 +0,2 @@ | ||
var _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; }; | ||
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); } | ||
@@ -11,7 +11,5 @@ import React from 'react'; | ||
className = _ref.className; | ||
return React.createElement( | ||
'div', | ||
_extends({}, inlineProp(constants.FOCUS_ALLOW, true), { className: className }), | ||
children | ||
); | ||
return React.createElement("div", _extends({}, inlineProp(constants.FOCUS_ALLOW, true), { | ||
className: className | ||
}), children); | ||
}; | ||
@@ -30,3 +28,2 @@ | ||
}; | ||
export default FreeFocusInside; |
@@ -5,5 +5,3 @@ import FocusLock from './Lock'; | ||
import FreeFocusInside from './FreeFocusInside'; | ||
export { AutoFocusInside, MoveFocusInside, FreeFocusInside }; | ||
export default FocusLock; |
@@ -1,13 +0,25 @@ | ||
var _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; }; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
import React, { Component } from 'react'; | ||
@@ -20,8 +32,5 @@ import PropTypes from 'prop-types'; | ||
var children = _ref.children; | ||
return React.createElement( | ||
'div', | ||
null, | ||
children | ||
); | ||
return React.createElement("div", null, children); | ||
}; | ||
RenderChildren.propTypes = { | ||
@@ -31,3 +40,2 @@ children: PropTypes.node.isRequired | ||
var Fragment = React.Fragment ? React.Fragment : RenderChildren; | ||
var hidden = { | ||
@@ -43,36 +51,51 @@ width: '1px', | ||
var FocusLock = function (_Component) { | ||
var FocusLock = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(FocusLock, _Component); | ||
function FocusLock() { | ||
var _ref2; | ||
var _getPrototypeOf2; | ||
var _temp, _this, _ret; | ||
var _this; | ||
_classCallCheck(this, FocusLock); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref2 = FocusLock.__proto__ || Object.getPrototypeOf(FocusLock)).call.apply(_ref2, [this].concat(args))), _this), _this.state = { | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(FocusLock)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", { | ||
observed: undefined | ||
}, _this.onActivation = function () { | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onActivation", function () { | ||
_this.originalFocusedElement = _this.originalFocusedElement || document && document.activeElement; | ||
if (_this.state.observed && _this.props.onActivation) { | ||
_this.props.onActivation(_this.state.observed); | ||
} | ||
}, _this.onDeactivation = function () { | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onDeactivation", function () { | ||
if (_this.props.returnFocus && _this.originalFocusedElement && _this.originalFocusedElement.focus) { | ||
_this.originalFocusedElement.focus(); | ||
_this.originalFocusedElement = null; | ||
} | ||
if (_this.props.onDeactivation) { | ||
_this.props.onDeactivation(_this.state.observed); | ||
} | ||
}, _this.setObserveNode = function (observed) { | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "setObserveNode", function (observed) { | ||
return _this.setState({ | ||
observed: observed | ||
}); | ||
}, _this.update = function () { | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "update", function () { | ||
return _this.setState(function (prevState) { | ||
@@ -83,27 +106,30 @@ return { | ||
}); | ||
}, _this.originalFocusedElement = null, _temp), _possibleConstructorReturn(_this, _ret); | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "originalFocusedElement", null); | ||
return _this; | ||
} | ||
_createClass(FocusLock, [{ | ||
key: 'render', | ||
key: "render", | ||
value: function render() { | ||
var _Object$assign; | ||
var _objectSpread2; | ||
var _props = this.props, | ||
children = _props.children, | ||
disabled = _props.disabled, | ||
noFocusGuards = _props.noFocusGuards, | ||
persistentFocus = _props.persistentFocus, | ||
autoFocus = _props.autoFocus, | ||
allowTextSelection = _props.allowTextSelection, | ||
group = _props.group, | ||
className = _props.className, | ||
whiteList = _props.whiteList, | ||
_props$as = _props.as, | ||
Container = _props$as === undefined ? 'div' : _props$as, | ||
_props$lockProps = _props.lockProps, | ||
containerProps = _props$lockProps === undefined ? {} : _props$lockProps; | ||
var _this$props = this.props, | ||
children = _this$props.children, | ||
disabled = _this$props.disabled, | ||
noFocusGuards = _this$props.noFocusGuards, | ||
persistentFocus = _this$props.persistentFocus, | ||
autoFocus = _this$props.autoFocus, | ||
allowTextSelection = _this$props.allowTextSelection, | ||
group = _this$props.group, | ||
className = _this$props.className, | ||
whiteList = _this$props.whiteList, | ||
_this$props$as = _this$props.as, | ||
Container = _this$props$as === void 0 ? 'div' : _this$props$as, | ||
_this$props$lockProps = _this$props.lockProps, | ||
containerProps = _this$props$lockProps === void 0 ? {} : _this$props$lockProps; | ||
var observed = this.state.observed; | ||
if (typeof allowTextSelection !== 'undefined') { | ||
@@ -114,31 +140,34 @@ // eslint-disable-next-line no-console | ||
var lockProps = Object.assign((_Object$assign = {}, _defineProperty(_Object$assign, constants.FOCUS_DISABLED, disabled && 'disabled'), _defineProperty(_Object$assign, constants.FOCUS_GROUP, group), _Object$assign), containerProps); | ||
var lockProps = _objectSpread((_objectSpread2 = {}, _defineProperty(_objectSpread2, constants.FOCUS_DISABLED, disabled && 'disabled'), _defineProperty(_objectSpread2, constants.FOCUS_GROUP, group), _objectSpread2), containerProps); | ||
return React.createElement( | ||
Fragment, | ||
null, | ||
!noFocusGuards && [React.createElement('div', { key: 'guard-first', 'data-focus-guard': true, tabIndex: disabled ? -1 : 0, style: hidden }), // nearest focus guard | ||
React.createElement('div', { key: 'guard-nearest', 'data-focus-guard': true, tabIndex: disabled ? -1 : 1, style: hidden })], | ||
React.createElement( | ||
Container, | ||
_extends({ | ||
ref: this.setObserveNode | ||
}, lockProps, { | ||
className: className, | ||
onBlur: onBlur, | ||
onFocus: onFocus | ||
}), | ||
React.createElement(FocusTrap, { | ||
observed: observed, | ||
disabled: disabled, | ||
persistentFocus: persistentFocus, | ||
autoFocus: autoFocus, | ||
whiteList: whiteList, | ||
onActivation: this.onActivation, | ||
onDeactivation: this.onDeactivation | ||
}), | ||
children | ||
), | ||
!noFocusGuards && React.createElement('div', { 'data-focus-guard': true, tabIndex: disabled ? -1 : 0, style: hidden }) | ||
); | ||
return React.createElement(Fragment, null, !noFocusGuards && [React.createElement("div", { | ||
key: "guard-first", | ||
"data-focus-guard": true, | ||
tabIndex: disabled ? -1 : 0, | ||
style: hidden | ||
}), // nearest focus guard | ||
React.createElement("div", { | ||
key: "guard-nearest", | ||
"data-focus-guard": true, | ||
tabIndex: disabled ? -1 : 1, | ||
style: hidden | ||
})], React.createElement(Container, _extends({ | ||
ref: this.setObserveNode | ||
}, lockProps, { | ||
className: className, | ||
onBlur: onBlur, | ||
onFocus: onFocus | ||
}), React.createElement(FocusTrap, { | ||
observed: observed, | ||
disabled: disabled, | ||
persistentFocus: persistentFocus, | ||
autoFocus: autoFocus, | ||
whiteList: whiteList, | ||
onActivation: this.onActivation, | ||
onDeactivation: this.onDeactivation | ||
}), children), !noFocusGuards && React.createElement("div", { | ||
"data-focus-guard": true, | ||
tabIndex: disabled ? -1 : 0, | ||
style: hidden | ||
})); | ||
} | ||
@@ -156,15 +185,10 @@ }]); | ||
noFocusGuards: PropTypes.bool, | ||
allowTextSelection: PropTypes.bool, | ||
autoFocus: PropTypes.bool, | ||
persistentFocus: PropTypes.bool, | ||
group: PropTypes.string, | ||
className: PropTypes.string, | ||
whiteList: PropTypes.func, | ||
as: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), | ||
lockProps: PropTypes.object, | ||
onActivation: PropTypes.func, | ||
@@ -190,3 +214,2 @@ onDeactivation: PropTypes.func | ||
}; | ||
export default FocusLock; |
@@ -1,11 +0,23 @@ | ||
var _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; }; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
import React, { Component } from 'react'; | ||
@@ -16,24 +28,31 @@ import PropTypes from 'prop-types'; | ||
var MoveFocusInside = function (_Component) { | ||
var MoveFocusInside = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(MoveFocusInside, _Component); | ||
function MoveFocusInside() { | ||
var _ref; | ||
var _getPrototypeOf2; | ||
var _temp, _this, _ret; | ||
var _this; | ||
_classCallCheck(this, MoveFocusInside); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = MoveFocusInside.__proto__ || Object.getPrototypeOf(MoveFocusInside)).call.apply(_ref, [this].concat(args))), _this), _this.setObserveNode = function (ref) { | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(MoveFocusInside)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "setObserveNode", function (ref) { | ||
_this.observed = ref; | ||
_this.moveFocus(); | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
}); | ||
return _this; | ||
} | ||
_createClass(MoveFocusInside, [{ | ||
key: 'componentDidMount', | ||
key: "componentDidMount", | ||
value: function componentDidMount() { | ||
@@ -43,3 +62,3 @@ this.moveFocus(); | ||
}, { | ||
key: 'componentDidUpdate', | ||
key: "componentDidUpdate", | ||
value: function componentDidUpdate(prevProps) { | ||
@@ -51,5 +70,6 @@ if (prevProps.disabled && !this.props.disabled) { | ||
}, { | ||
key: 'moveFocus', | ||
key: "moveFocus", | ||
value: function moveFocus() { | ||
var observed = this.observed; | ||
if (!this.props.disabled && observed) { | ||
@@ -62,17 +82,12 @@ if (!focusInside(observed)) { | ||
}, { | ||
key: 'render', | ||
key: "render", | ||
value: function render() { | ||
var _props = this.props, | ||
children = _props.children, | ||
disabled = _props.disabled, | ||
className = _props.className; | ||
return React.createElement( | ||
'div', | ||
_extends({}, inlineProp(constants.FOCUS_AUTO, !disabled), { | ||
ref: this.setObserveNode, | ||
className: className | ||
}), | ||
children | ||
); | ||
var _this$props = this.props, | ||
children = _this$props.children, | ||
disabled = _this$props.disabled, | ||
className = _this$props.className; | ||
return React.createElement("div", _extends({}, inlineProp(constants.FOCUS_AUTO, !disabled), { | ||
ref: this.setObserveNode, | ||
className: className | ||
}), children); | ||
} | ||
@@ -84,8 +99,8 @@ }]); | ||
MoveFocusInside.defaultProps = { | ||
_defineProperty(MoveFocusInside, "defaultProps", { | ||
disabled: false, | ||
className: undefined | ||
}; | ||
export default MoveFocusInside; | ||
}); | ||
export { MoveFocusInside as default }; | ||
@@ -92,0 +107,0 @@ if (process.env.NODE_ENV !== 'production') { |
@@ -17,3 +17,2 @@ import React from 'react'; | ||
var lastActiveFocus = null; | ||
var lastPortaledElement = null; | ||
@@ -30,3 +29,6 @@ | ||
var recordPortal = function recordPortal(observerNode, portaledElement) { | ||
lastPortaledElement = { observerNode: observerNode, portaledElement: portaledElement }; | ||
lastPortaledElement = { | ||
observerNode: observerNode, | ||
portaledElement: portaledElement | ||
}; | ||
}; | ||
@@ -40,2 +42,3 @@ | ||
var result = false; | ||
if (lastActiveTrap) { | ||
@@ -46,3 +49,2 @@ var _lastActiveTrap = lastActiveTrap, | ||
autoFocus = _lastActiveTrap.autoFocus; | ||
var workingNode = observed || lastPortaledElement && lastPortaledElement.portaledElement; | ||
@@ -62,2 +64,3 @@ var activeElement = document && document.activeElement; | ||
} | ||
lastActiveFocus = document && document.activeElement; | ||
@@ -67,2 +70,3 @@ } | ||
} | ||
return result; | ||
@@ -82,3 +86,2 @@ }; | ||
}; | ||
export var onFocus = function onFocus(event) { | ||
@@ -88,2 +91,3 @@ // detect portal | ||
var currentNode = event.currentTarget; | ||
if (!currentNode.contains(source)) { | ||
@@ -100,7 +104,6 @@ recordPortal(currentNode, source); | ||
var children = _ref.children; | ||
return React.createElement( | ||
'div', | ||
{ onBlur: onBlur, onFocus: onFocus }, | ||
children | ||
); | ||
return React.createElement("div", { | ||
onBlur: onBlur, | ||
onFocus: onFocus | ||
}, children); | ||
}; | ||
@@ -138,3 +141,2 @@ | ||
var sameTrap = lastTrap && trap && trap.onActivation === lastTrap.onActivation; | ||
lastActiveTrap = trap; | ||
@@ -148,5 +150,7 @@ | ||
lastActiveFocus = null; | ||
if (!sameTrap || lastTrap.observed !== trap.observed) { | ||
trap.onActivation(); | ||
} | ||
activateTrap(true); | ||
@@ -153,0 +157,0 @@ deferAction(activateTrap); |
@@ -8,3 +8,2 @@ export function deferAction(action) { | ||
} | ||
export var inlineProp = function inlineProp(name, value) { | ||
@@ -11,0 +10,0 @@ var obj = {}; |
{ | ||
"name": "react-focus-lock", | ||
"version": "1.16.1", | ||
"version": "1.16.2", | ||
"description": "It is a trap! (for a focus)", | ||
@@ -14,3 +14,3 @@ "main": "dist/cjs/index.js", | ||
"test": "npm run test:pick -- '_tests/**/*spec.js'", | ||
"test:pick": "NODE_ENV=cjs mocha --require _tests/spinup/scaffolding --compilers js:babel-core/register -r jsdom-global/register", | ||
"test:pick": "NODE_ENV=cjs mocha --require _tests/spinup/scaffolding --compilers js:@babel/register -r jsdom-global/register", | ||
"prepublish": "npm run build", | ||
@@ -44,12 +44,15 @@ "lint": "eslint src tests", | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0", | ||
"@babel/core": "^7.0.0", | ||
"@babel/plugin-proposal-class-properties": "^7.0.0", | ||
"@babel/plugin-transform-runtime": "^7.1.0", | ||
"@babel/polyfill": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"@babel/register": "^7.0.0", | ||
"@babel/runtime": "^7.1.2", | ||
"@storybook/addon-actions": "^3.2.14", | ||
"@storybook/addon-links": "^3.2.14", | ||
"@storybook/react": "^3.2.14", | ||
"babel-cli": "^6.24.1", | ||
"babel-core": "^6.25.0", | ||
"babel-eslint": "^7.2.3", | ||
"babel-plugin-transform-class-properties": "6.24.1", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-preset-env": "1.6.0", | ||
"babel-preset-react": "^6.24.1", | ||
"babel-eslint": "^9.0.0", | ||
"chai": "^4.1.0", | ||
@@ -56,0 +59,0 @@ "chai-enzyme": "^1.0.0-beta.0", |
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
81081
1053
35