@madflys/react 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @madflys/react might be problematic. Click here for more details.
- package/README.md +1 -0
- package/package.json +27 -0
- package/react/dist/node_modules/react-focus-lock/LICENSE +21 -0
- package/react/dist/node_modules/react-focus-lock/README.md +333 -0
- package/react/dist/node_modules/react-focus-lock/UI/UI.d.ts +38 -0
- package/react/dist/node_modules/react-focus-lock/UI/package.json +8 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/AutoFocusInside.js +41 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/Combination.js +43 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/FocusGuard.js +49 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/FreeFocusInside.js +38 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/Lock.js +238 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/MoveFocusInside.js +68 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/Trap.js +299 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/UI.js +59 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/clientSideEffect.js +67 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/index.js +26 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/medium.js +26 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/sidecar.js +18 -0
- package/react/dist/node_modules/react-focus-lock/dist/cjs/util.js +27 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/AutoFocusInside.es.js +25 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/Combination.es.js +23 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/FocusGuard.es.js +34 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/FreeFocusInside.es.js +22 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/Lock.es.js +208 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/MoveFocusInside.es.js +46 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/Trap.es.js +276 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/UI.es.js +7 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/clientSideEffect.es.js +56 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/index.js +27 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/medium.es.js +14 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/sidecar.es.js +4 -0
- package/react/dist/node_modules/react-focus-lock/dist/es2015/util.es.js +16 -0
- package/react/dist/node_modules/react-focus-lock/interfaces.d.ts +125 -0
- package/react/dist/node_modules/react-focus-lock/package.json +103 -0
- package/react/dist/node_modules/react-focus-lock/react-focus-lock.d.ts +33 -0
- package/react/dist/node_modules/react-focus-lock/sidecar/package.json +7 -0
- package/react/dist/node_modules/react-focus-lock/sidecar/sidecar.d.ts +5 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports["default"] = void 0;
|
|
11
|
+
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
17
|
+
|
|
18
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
19
|
+
|
|
20
|
+
var React = _interopRequireWildcard(require("react"));
|
|
21
|
+
|
|
22
|
+
var _propTypes = require("prop-types");
|
|
23
|
+
|
|
24
|
+
var constants = _interopRequireWildcard(require("focus-lock/constants"));
|
|
25
|
+
|
|
26
|
+
var _useCallbackRef = require("use-callback-ref");
|
|
27
|
+
|
|
28
|
+
var _FocusGuard = require("./FocusGuard");
|
|
29
|
+
|
|
30
|
+
var _medium = require("./medium");
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
var emptyArray = [];
|
|
37
|
+
var FocusLock = /*#__PURE__*/React.forwardRef(function FocusLockUI(props, parentRef) {
|
|
38
|
+
var _objectSpread2;
|
|
39
|
+
|
|
40
|
+
var _React$useState = React.useState(),
|
|
41
|
+
_React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
|
|
42
|
+
realObserved = _React$useState2[0],
|
|
43
|
+
setObserved = _React$useState2[1];
|
|
44
|
+
|
|
45
|
+
var observed = React.useRef();
|
|
46
|
+
var isActive = React.useRef(false);
|
|
47
|
+
var originalFocusedElement = React.useRef(null);
|
|
48
|
+
var children = props.children,
|
|
49
|
+
disabled = props.disabled,
|
|
50
|
+
noFocusGuards = props.noFocusGuards,
|
|
51
|
+
persistentFocus = props.persistentFocus,
|
|
52
|
+
crossFrame = props.crossFrame,
|
|
53
|
+
autoFocus = props.autoFocus,
|
|
54
|
+
allowTextSelection = props.allowTextSelection,
|
|
55
|
+
group = props.group,
|
|
56
|
+
className = props.className,
|
|
57
|
+
whiteList = props.whiteList,
|
|
58
|
+
hasPositiveIndices = props.hasPositiveIndices,
|
|
59
|
+
_props$shards = props.shards,
|
|
60
|
+
shards = _props$shards === void 0 ? emptyArray : _props$shards,
|
|
61
|
+
_props$as = props.as,
|
|
62
|
+
Container = _props$as === void 0 ? 'div' : _props$as,
|
|
63
|
+
_props$lockProps = props.lockProps,
|
|
64
|
+
containerProps = _props$lockProps === void 0 ? {} : _props$lockProps,
|
|
65
|
+
SideCar = props.sideCar,
|
|
66
|
+
shouldReturnFocus = props.returnFocus,
|
|
67
|
+
focusOptions = props.focusOptions,
|
|
68
|
+
onActivationCallback = props.onActivation,
|
|
69
|
+
onDeactivationCallback = props.onDeactivation;
|
|
70
|
+
|
|
71
|
+
var _React$useState3 = React.useState({}),
|
|
72
|
+
_React$useState4 = (0, _slicedToArray2["default"])(_React$useState3, 1),
|
|
73
|
+
id = _React$useState4[0]; // SIDE EFFECT CALLBACKS
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
var onActivation = React.useCallback(function () {
|
|
77
|
+
originalFocusedElement.current = originalFocusedElement.current || document && document.activeElement;
|
|
78
|
+
|
|
79
|
+
if (observed.current && onActivationCallback) {
|
|
80
|
+
onActivationCallback(observed.current);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
isActive.current = true;
|
|
84
|
+
}, [onActivationCallback]);
|
|
85
|
+
var onDeactivation = React.useCallback(function () {
|
|
86
|
+
isActive.current = false;
|
|
87
|
+
|
|
88
|
+
if (onDeactivationCallback) {
|
|
89
|
+
onDeactivationCallback(observed.current);
|
|
90
|
+
}
|
|
91
|
+
}, [onDeactivationCallback]);
|
|
92
|
+
(0, React.useEffect)(function () {
|
|
93
|
+
if (!disabled) {
|
|
94
|
+
// cleanup return focus on trap deactivation
|
|
95
|
+
// sideEffect/returnFocus should happen by this time
|
|
96
|
+
originalFocusedElement.current = null;
|
|
97
|
+
}
|
|
98
|
+
}, []);
|
|
99
|
+
var returnFocus = React.useCallback(function (allowDefer) {
|
|
100
|
+
var returnFocusTo = originalFocusedElement.current;
|
|
101
|
+
|
|
102
|
+
if (returnFocusTo && returnFocusTo.focus) {
|
|
103
|
+
var howToReturnFocus = typeof shouldReturnFocus === 'function' ? shouldReturnFocus(returnFocusTo) : shouldReturnFocus;
|
|
104
|
+
|
|
105
|
+
if (howToReturnFocus) {
|
|
106
|
+
var returnFocusOptions = (0, _typeof2["default"])(howToReturnFocus) === 'object' ? howToReturnFocus : undefined;
|
|
107
|
+
originalFocusedElement.current = null;
|
|
108
|
+
|
|
109
|
+
if (allowDefer) {
|
|
110
|
+
// React might return focus after update
|
|
111
|
+
// it's safer to defer the action
|
|
112
|
+
Promise.resolve().then(function () {
|
|
113
|
+
return returnFocusTo.focus(returnFocusOptions);
|
|
114
|
+
});
|
|
115
|
+
} else {
|
|
116
|
+
returnFocusTo.focus(returnFocusOptions);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, [shouldReturnFocus]); // MEDIUM CALLBACKS
|
|
121
|
+
|
|
122
|
+
var onFocus = React.useCallback(function (event) {
|
|
123
|
+
if (isActive.current) {
|
|
124
|
+
_medium.mediumFocus.useMedium(event);
|
|
125
|
+
}
|
|
126
|
+
}, []);
|
|
127
|
+
var onBlur = _medium.mediumBlur.useMedium; // REF PROPAGATION
|
|
128
|
+
// not using real refs due to race conditions
|
|
129
|
+
|
|
130
|
+
var setObserveNode = React.useCallback(function (newObserved) {
|
|
131
|
+
if (observed.current !== newObserved) {
|
|
132
|
+
observed.current = newObserved;
|
|
133
|
+
setObserved(newObserved);
|
|
134
|
+
}
|
|
135
|
+
}, []);
|
|
136
|
+
|
|
137
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
138
|
+
if (typeof allowTextSelection !== 'undefined') {
|
|
139
|
+
// eslint-disable-next-line no-console
|
|
140
|
+
console.warn('React-Focus-Lock: allowTextSelection is deprecated and enabled by default');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
React.useEffect(function () {
|
|
144
|
+
if (!observed.current) {
|
|
145
|
+
// eslint-disable-next-line no-console
|
|
146
|
+
console.error('FocusLock: could not obtain ref to internal node');
|
|
147
|
+
}
|
|
148
|
+
}, []);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
var lockProps = _objectSpread((_objectSpread2 = {}, (0, _defineProperty2["default"])(_objectSpread2, constants.FOCUS_DISABLED, disabled && 'disabled'), (0, _defineProperty2["default"])(_objectSpread2, constants.FOCUS_GROUP, group), _objectSpread2), containerProps);
|
|
152
|
+
|
|
153
|
+
var hasLeadingGuards = noFocusGuards !== true;
|
|
154
|
+
var hasTailingGuards = hasLeadingGuards && noFocusGuards !== 'tail';
|
|
155
|
+
var mergedRef = (0, _useCallbackRef.useMergeRefs)([parentRef, setObserveNode]);
|
|
156
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, hasLeadingGuards && [
|
|
157
|
+
/*#__PURE__*/
|
|
158
|
+
// nearest focus guard
|
|
159
|
+
React.createElement("div", {
|
|
160
|
+
key: "guard-first",
|
|
161
|
+
"data-focus-guard": true,
|
|
162
|
+
tabIndex: disabled ? -1 : 0,
|
|
163
|
+
style: _FocusGuard.hiddenGuard
|
|
164
|
+
}), // first tabbed element guard
|
|
165
|
+
hasPositiveIndices ? /*#__PURE__*/React.createElement("div", {
|
|
166
|
+
key: "guard-nearest",
|
|
167
|
+
"data-focus-guard": true,
|
|
168
|
+
tabIndex: disabled ? -1 : 1,
|
|
169
|
+
style: _FocusGuard.hiddenGuard
|
|
170
|
+
}) : null], !disabled && /*#__PURE__*/React.createElement(SideCar, {
|
|
171
|
+
id: id,
|
|
172
|
+
sideCar: _medium.mediumSidecar,
|
|
173
|
+
observed: realObserved,
|
|
174
|
+
disabled: disabled,
|
|
175
|
+
persistentFocus: persistentFocus,
|
|
176
|
+
crossFrame: crossFrame,
|
|
177
|
+
autoFocus: autoFocus,
|
|
178
|
+
whiteList: whiteList,
|
|
179
|
+
shards: shards,
|
|
180
|
+
onActivation: onActivation,
|
|
181
|
+
onDeactivation: onDeactivation,
|
|
182
|
+
returnFocus: returnFocus,
|
|
183
|
+
focusOptions: focusOptions
|
|
184
|
+
}), /*#__PURE__*/React.createElement(Container, (0, _extends2["default"])({
|
|
185
|
+
ref: mergedRef
|
|
186
|
+
}, lockProps, {
|
|
187
|
+
className: className,
|
|
188
|
+
onBlur: onBlur,
|
|
189
|
+
onFocus: onFocus
|
|
190
|
+
}), children), hasTailingGuards && /*#__PURE__*/React.createElement("div", {
|
|
191
|
+
"data-focus-guard": true,
|
|
192
|
+
tabIndex: disabled ? -1 : 0,
|
|
193
|
+
style: _FocusGuard.hiddenGuard
|
|
194
|
+
}));
|
|
195
|
+
});
|
|
196
|
+
FocusLock.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
197
|
+
children: _propTypes.node,
|
|
198
|
+
disabled: _propTypes.bool,
|
|
199
|
+
returnFocus: (0, _propTypes.oneOfType)([_propTypes.bool, _propTypes.object, _propTypes.func]),
|
|
200
|
+
focusOptions: _propTypes.object,
|
|
201
|
+
noFocusGuards: _propTypes.bool,
|
|
202
|
+
hasPositiveIndices: _propTypes.bool,
|
|
203
|
+
allowTextSelection: _propTypes.bool,
|
|
204
|
+
autoFocus: _propTypes.bool,
|
|
205
|
+
persistentFocus: _propTypes.bool,
|
|
206
|
+
crossFrame: _propTypes.bool,
|
|
207
|
+
group: _propTypes.string,
|
|
208
|
+
className: _propTypes.string,
|
|
209
|
+
whiteList: _propTypes.func,
|
|
210
|
+
shards: (0, _propTypes.arrayOf)(_propTypes.any),
|
|
211
|
+
as: (0, _propTypes.oneOfType)([_propTypes.string, _propTypes.func, _propTypes.object]),
|
|
212
|
+
lockProps: _propTypes.object,
|
|
213
|
+
onActivation: _propTypes.func,
|
|
214
|
+
onDeactivation: _propTypes.func,
|
|
215
|
+
sideCar: _propTypes.any.isRequired
|
|
216
|
+
} : {};
|
|
217
|
+
FocusLock.defaultProps = {
|
|
218
|
+
children: undefined,
|
|
219
|
+
disabled: false,
|
|
220
|
+
returnFocus: false,
|
|
221
|
+
focusOptions: undefined,
|
|
222
|
+
noFocusGuards: false,
|
|
223
|
+
autoFocus: true,
|
|
224
|
+
persistentFocus: false,
|
|
225
|
+
crossFrame: true,
|
|
226
|
+
hasPositiveIndices: undefined,
|
|
227
|
+
allowTextSelection: undefined,
|
|
228
|
+
group: undefined,
|
|
229
|
+
className: undefined,
|
|
230
|
+
whiteList: undefined,
|
|
231
|
+
shards: undefined,
|
|
232
|
+
as: 'div',
|
|
233
|
+
lockProps: {},
|
|
234
|
+
onActivation: undefined,
|
|
235
|
+
onDeactivation: undefined
|
|
236
|
+
};
|
|
237
|
+
var _default = FocusLock;
|
|
238
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports["default"] = exports.useFocusInside = void 0;
|
|
11
|
+
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
14
|
+
var React = _interopRequireWildcard(require("react"));
|
|
15
|
+
|
|
16
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
17
|
+
|
|
18
|
+
var constants = _interopRequireWildcard(require("focus-lock/constants"));
|
|
19
|
+
|
|
20
|
+
var _util = require("./util");
|
|
21
|
+
|
|
22
|
+
var _medium = require("./medium");
|
|
23
|
+
|
|
24
|
+
var useFocusInside = function useFocusInside(observedRef) {
|
|
25
|
+
React.useEffect(function () {
|
|
26
|
+
var enabled = true;
|
|
27
|
+
|
|
28
|
+
_medium.mediumEffect.useMedium(function (car) {
|
|
29
|
+
var observed = observedRef && observedRef.current;
|
|
30
|
+
|
|
31
|
+
if (enabled && observed) {
|
|
32
|
+
if (!car.focusInside(observed)) {
|
|
33
|
+
car.moveFocusInside(observed, null);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return function () {
|
|
39
|
+
enabled = false;
|
|
40
|
+
};
|
|
41
|
+
}, [observedRef]);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.useFocusInside = useFocusInside;
|
|
45
|
+
|
|
46
|
+
function MoveFocusInside(_ref) {
|
|
47
|
+
var isDisabled = _ref.disabled,
|
|
48
|
+
className = _ref.className,
|
|
49
|
+
children = _ref.children;
|
|
50
|
+
var ref = React.useRef(null);
|
|
51
|
+
useFocusInside(isDisabled ? undefined : ref);
|
|
52
|
+
return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _util.inlineProp)(constants.FOCUS_AUTO, !isDisabled), {
|
|
53
|
+
ref: ref,
|
|
54
|
+
className: className
|
|
55
|
+
}), children);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
MoveFocusInside.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
59
|
+
children: _propTypes["default"].node.isRequired,
|
|
60
|
+
disabled: _propTypes["default"].bool,
|
|
61
|
+
className: _propTypes["default"].string
|
|
62
|
+
} : {};
|
|
63
|
+
MoveFocusInside.defaultProps = {
|
|
64
|
+
disabled: false,
|
|
65
|
+
className: undefined
|
|
66
|
+
};
|
|
67
|
+
var _default = MoveFocusInside;
|
|
68
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports["default"] = void 0;
|
|
11
|
+
|
|
12
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
+
|
|
14
|
+
var React = _interopRequireWildcard(require("react"));
|
|
15
|
+
|
|
16
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
17
|
+
|
|
18
|
+
var _reactClientsideEffect = _interopRequireDefault(require("react-clientside-effect"));
|
|
19
|
+
|
|
20
|
+
var _focusLock = _interopRequireWildcard(require("focus-lock"));
|
|
21
|
+
|
|
22
|
+
var _util = require("./util");
|
|
23
|
+
|
|
24
|
+
var _medium = require("./medium");
|
|
25
|
+
|
|
26
|
+
var focusOnBody = function focusOnBody() {
|
|
27
|
+
return document && document.activeElement === document.body;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var isFreeFocus = function isFreeFocus() {
|
|
31
|
+
return focusOnBody() || (0, _focusLock.focusIsHidden)();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var lastActiveTrap = null;
|
|
35
|
+
var lastActiveFocus = null;
|
|
36
|
+
var lastPortaledElement = null;
|
|
37
|
+
var focusWasOutsideWindow = false;
|
|
38
|
+
|
|
39
|
+
var defaultWhitelist = function defaultWhitelist() {
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var focusWhitelisted = function focusWhitelisted(activeElement) {
|
|
44
|
+
return (lastActiveTrap.whiteList || defaultWhitelist)(activeElement);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
var recordPortal = function recordPortal(observerNode, portaledElement) {
|
|
48
|
+
lastPortaledElement = {
|
|
49
|
+
observerNode: observerNode,
|
|
50
|
+
portaledElement: portaledElement
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var focusIsPortaledPair = function focusIsPortaledPair(element) {
|
|
55
|
+
return lastPortaledElement && lastPortaledElement.portaledElement === element;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function autoGuard(startIndex, end, step, allNodes) {
|
|
59
|
+
var lastGuard = null;
|
|
60
|
+
var i = startIndex;
|
|
61
|
+
|
|
62
|
+
do {
|
|
63
|
+
var item = allNodes[i];
|
|
64
|
+
|
|
65
|
+
if (item.guard) {
|
|
66
|
+
if (item.node.dataset.focusAutoGuard) {
|
|
67
|
+
lastGuard = item;
|
|
68
|
+
}
|
|
69
|
+
} else if (item.lockItem) {
|
|
70
|
+
if (i !== startIndex) {
|
|
71
|
+
// we will tab to the next element
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
lastGuard = null;
|
|
76
|
+
} else {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
} while ((i += step) !== end);
|
|
80
|
+
|
|
81
|
+
if (lastGuard) {
|
|
82
|
+
lastGuard.node.tabIndex = 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var extractRef = function extractRef(ref) {
|
|
87
|
+
return ref && 'current' in ref ? ref.current : ref;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
var focusWasOutside = function focusWasOutside(crossFrameOption) {
|
|
91
|
+
if (crossFrameOption) {
|
|
92
|
+
// with cross frame return true for any value
|
|
93
|
+
return Boolean(focusWasOutsideWindow);
|
|
94
|
+
} // in other case return only of focus went a while aho
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
return focusWasOutsideWindow === 'meanwhile';
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
var checkInHost = function checkInHost(check, el, boundary) {
|
|
101
|
+
return el // find host equal to active element and check nested active element
|
|
102
|
+
&& (el.host === check && (!el.activeElement || boundary.contains(el.activeElement)) // dive up
|
|
103
|
+
|| el.parentNode && checkInHost(check, el.parentNode, boundary));
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
var withinHost = function withinHost(activeElement, workingArea) {
|
|
107
|
+
return workingArea.some(function (area) {
|
|
108
|
+
return checkInHost(activeElement, area, area);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
var activateTrap = function activateTrap() {
|
|
113
|
+
var result = false;
|
|
114
|
+
|
|
115
|
+
if (lastActiveTrap) {
|
|
116
|
+
var _lastActiveTrap = lastActiveTrap,
|
|
117
|
+
observed = _lastActiveTrap.observed,
|
|
118
|
+
persistentFocus = _lastActiveTrap.persistentFocus,
|
|
119
|
+
autoFocus = _lastActiveTrap.autoFocus,
|
|
120
|
+
shards = _lastActiveTrap.shards,
|
|
121
|
+
crossFrame = _lastActiveTrap.crossFrame,
|
|
122
|
+
focusOptions = _lastActiveTrap.focusOptions;
|
|
123
|
+
var workingNode = observed || lastPortaledElement && lastPortaledElement.portaledElement;
|
|
124
|
+
var activeElement = document && document.activeElement;
|
|
125
|
+
|
|
126
|
+
if (workingNode) {
|
|
127
|
+
var workingArea = [workingNode].concat((0, _toConsumableArray2["default"])(shards.map(extractRef).filter(Boolean)));
|
|
128
|
+
|
|
129
|
+
if (!activeElement || focusWhitelisted(activeElement)) {
|
|
130
|
+
if (persistentFocus || focusWasOutside(crossFrame) || !isFreeFocus() || !lastActiveFocus && autoFocus) {
|
|
131
|
+
if (workingNode && !( // active element is "inside" working area
|
|
132
|
+
(0, _focusLock.focusInside)(workingArea) || // check for shadow-dom contained elements
|
|
133
|
+
activeElement && withinHost(activeElement, workingArea) || focusIsPortaledPair(activeElement, workingNode))) {
|
|
134
|
+
if (document && !lastActiveFocus && activeElement && !autoFocus) {
|
|
135
|
+
// Check if blur() exists, which is missing on certain elements on IE
|
|
136
|
+
if (activeElement.blur) {
|
|
137
|
+
activeElement.blur();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
document.body.focus();
|
|
141
|
+
} else {
|
|
142
|
+
result = (0, _focusLock["default"])(workingArea, lastActiveFocus, {
|
|
143
|
+
focusOptions: focusOptions
|
|
144
|
+
});
|
|
145
|
+
lastPortaledElement = {};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
focusWasOutsideWindow = false;
|
|
150
|
+
lastActiveFocus = document && document.activeElement;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (document) {
|
|
155
|
+
var newActiveElement = document && document.activeElement;
|
|
156
|
+
var allNodes = (0, _focusLock.getFocusabledIn)(workingArea);
|
|
157
|
+
var focusedIndex = allNodes.map(function (_ref) {
|
|
158
|
+
var node = _ref.node;
|
|
159
|
+
return node;
|
|
160
|
+
}).indexOf(newActiveElement);
|
|
161
|
+
|
|
162
|
+
if (focusedIndex > -1) {
|
|
163
|
+
// remove old focus
|
|
164
|
+
allNodes.filter(function (_ref2) {
|
|
165
|
+
var guard = _ref2.guard,
|
|
166
|
+
node = _ref2.node;
|
|
167
|
+
return guard && node.dataset.focusAutoGuard;
|
|
168
|
+
}).forEach(function (_ref3) {
|
|
169
|
+
var node = _ref3.node;
|
|
170
|
+
return node.removeAttribute('tabIndex');
|
|
171
|
+
});
|
|
172
|
+
autoGuard(focusedIndex, allNodes.length, +1, allNodes);
|
|
173
|
+
autoGuard(focusedIndex, -1, -1, allNodes);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return result;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
var onTrap = function onTrap(event) {
|
|
183
|
+
if (activateTrap() && event) {
|
|
184
|
+
// prevent scroll jump
|
|
185
|
+
event.stopPropagation();
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
var onBlur = function onBlur() {
|
|
191
|
+
return (0, _util.deferAction)(activateTrap);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
var onFocus = function onFocus(event) {
|
|
195
|
+
// detect portal
|
|
196
|
+
var source = event.target;
|
|
197
|
+
var currentNode = event.currentTarget;
|
|
198
|
+
|
|
199
|
+
if (!currentNode.contains(source)) {
|
|
200
|
+
recordPortal(currentNode, source);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
var FocusWatcher = function FocusWatcher() {
|
|
205
|
+
return null;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
var FocusTrap = function FocusTrap(_ref4) {
|
|
209
|
+
var children = _ref4.children;
|
|
210
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
211
|
+
onBlur: onBlur,
|
|
212
|
+
onFocus: onFocus
|
|
213
|
+
}, children);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
FocusTrap.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
217
|
+
children: _propTypes["default"].node.isRequired
|
|
218
|
+
} : {};
|
|
219
|
+
|
|
220
|
+
var onWindowBlur = function onWindowBlur() {
|
|
221
|
+
focusWasOutsideWindow = 'just'; // using setTimeout to set this variable after React/sidecar reaction
|
|
222
|
+
|
|
223
|
+
setTimeout(function () {
|
|
224
|
+
focusWasOutsideWindow = 'meanwhile';
|
|
225
|
+
}, 0);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
var attachHandler = function attachHandler() {
|
|
229
|
+
document.addEventListener('focusin', onTrap);
|
|
230
|
+
document.addEventListener('focusout', onBlur);
|
|
231
|
+
window.addEventListener('blur', onWindowBlur);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
var detachHandler = function detachHandler() {
|
|
235
|
+
document.removeEventListener('focusin', onTrap);
|
|
236
|
+
document.removeEventListener('focusout', onBlur);
|
|
237
|
+
window.removeEventListener('blur', onWindowBlur);
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
function reducePropsToState(propsList) {
|
|
241
|
+
return propsList.filter(function (_ref5) {
|
|
242
|
+
var disabled = _ref5.disabled;
|
|
243
|
+
return !disabled;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function handleStateChangeOnClient(traps) {
|
|
248
|
+
var trap = traps.slice(-1)[0];
|
|
249
|
+
|
|
250
|
+
if (trap && !lastActiveTrap) {
|
|
251
|
+
attachHandler();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
var lastTrap = lastActiveTrap;
|
|
255
|
+
var sameTrap = lastTrap && trap && trap.id === lastTrap.id;
|
|
256
|
+
lastActiveTrap = trap;
|
|
257
|
+
|
|
258
|
+
if (lastTrap && !sameTrap) {
|
|
259
|
+
lastTrap.onDeactivation(); // return focus only of last trap was removed
|
|
260
|
+
|
|
261
|
+
if (!traps.filter(function (_ref6) {
|
|
262
|
+
var id = _ref6.id;
|
|
263
|
+
return id === lastTrap.id;
|
|
264
|
+
}).length) {
|
|
265
|
+
// allow defer is no other trap is awaiting restore
|
|
266
|
+
lastTrap.returnFocus(!trap);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (trap) {
|
|
271
|
+
lastActiveFocus = null;
|
|
272
|
+
|
|
273
|
+
if (!sameTrap || lastTrap.observed !== trap.observed) {
|
|
274
|
+
trap.onActivation();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
activateTrap(true);
|
|
278
|
+
(0, _util.deferAction)(activateTrap);
|
|
279
|
+
} else {
|
|
280
|
+
detachHandler();
|
|
281
|
+
lastActiveFocus = null;
|
|
282
|
+
}
|
|
283
|
+
} // bind medium
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
_medium.mediumFocus.assignSyncMedium(onFocus);
|
|
287
|
+
|
|
288
|
+
_medium.mediumBlur.assignMedium(onBlur);
|
|
289
|
+
|
|
290
|
+
_medium.mediumEffect.assignMedium(function (cb) {
|
|
291
|
+
return cb({
|
|
292
|
+
moveFocusInside: _focusLock["default"],
|
|
293
|
+
focusInside: _focusLock.focusInside
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
var _default = (0, _reactClientsideEffect["default"])(reducePropsToState, handleStateChangeOnClient)(FocusWatcher);
|
|
298
|
+
|
|
299
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(exports, "FocusLockUI", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _Lock["default"];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "AutoFocusInside", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function get() {
|
|
19
|
+
return _AutoFocusInside["default"];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "MoveFocusInside", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function get() {
|
|
25
|
+
return _MoveFocusInside["default"];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "useFocusInside", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function get() {
|
|
31
|
+
return _MoveFocusInside.useFocusInside;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "FreeFocusInside", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function get() {
|
|
37
|
+
return _FreeFocusInside["default"];
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "InFocusGuard", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function get() {
|
|
43
|
+
return _FocusGuard["default"];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
exports["default"] = void 0;
|
|
47
|
+
|
|
48
|
+
var _Lock = _interopRequireDefault(require("./Lock"));
|
|
49
|
+
|
|
50
|
+
var _AutoFocusInside = _interopRequireDefault(require("./AutoFocusInside"));
|
|
51
|
+
|
|
52
|
+
var _MoveFocusInside = _interopRequireWildcard(require("./MoveFocusInside"));
|
|
53
|
+
|
|
54
|
+
var _FreeFocusInside = _interopRequireDefault(require("./FreeFocusInside"));
|
|
55
|
+
|
|
56
|
+
var _FocusGuard = _interopRequireDefault(require("./FocusGuard"));
|
|
57
|
+
|
|
58
|
+
var _default = _Lock["default"];
|
|
59
|
+
exports["default"] = _default;
|