@enact/spotlight 4.5.1 → 4.5.3
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.
- package/Accelerator/Accelerator.js +11 -31
- package/Accelerator/tests/Accelerrator-specs.js +62 -0
- package/CHANGELOG.md +10 -0
- package/Pause/Pause.js +8 -18
- package/Pause/tests/Pause-specs.js +6 -3
- package/SpotlightContainerDecorator/SpotlightContainer.js +19 -45
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +14 -58
- package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +5 -10
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +17 -47
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +16 -53
- package/SpotlightContainerDecorator/useSpotlightContainer.js +4 -15
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +4 -58
- package/SpotlightRootDecorator/tests/SpotlightRootDecorator-specs.js +38 -0
- package/Spottable/Spottable.js +25 -84
- package/Spottable/SpottableCore.js +32 -71
- package/Spottable/tests/Spottable-specs.js +8 -31
- package/Spottable/tests/useSpot-specs.js +27 -105
- package/Spottable/useSpottable.js +7 -21
- package/package.json +8 -2
- package/src/container.js +94 -219
- package/src/navigate.js +5 -74
- package/src/pointer.js +16 -31
- package/src/spotlight.js +42 -171
- package/src/target.js +61 -139
- package/src/tests/container-specs.js +5 -11
- package/src/tests/navigate-specs.js +2 -10
- package/src/tests/pointer-specs.js +1 -3
- package/src/tests/spotlight-specs.js +42 -24
- package/src/tests/target-specs.js +23 -47
- package/src/tests/utils-specs.js +54 -0
- package/src/tests/utils.js +2 -27
- package/src/utils.js +18 -37
|
@@ -10,87 +10,59 @@ Object.defineProperty(exports, "useSpotlightContainer", {
|
|
|
10
10
|
return _useSpotlightContainer["default"];
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
|
-
|
|
14
13
|
var _handle = _interopRequireWildcard(require("@enact/core/handle"));
|
|
15
|
-
|
|
16
14
|
var _useHandlers = _interopRequireDefault(require("@enact/core/useHandlers"));
|
|
17
|
-
|
|
18
15
|
var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
|
|
19
|
-
|
|
20
16
|
var _react = require("react");
|
|
21
|
-
|
|
22
17
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
23
|
-
|
|
24
18
|
var _useSpotlightContainer = _interopRequireDefault(require("./useSpotlightContainer"));
|
|
25
|
-
|
|
26
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
|
-
|
|
28
20
|
var _excluded = ["navigableFilter", "preserveId"],
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
_excluded2 = ["spotlightDisabled", "spotlightId", "spotlightMuted", "spotlightRestrict"];
|
|
31
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
32
|
-
|
|
33
23
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
34
|
-
|
|
35
24
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
36
|
-
|
|
37
25
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
38
|
-
|
|
39
26
|
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); } }
|
|
40
|
-
|
|
41
27
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
42
|
-
|
|
43
28
|
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
44
|
-
|
|
45
29
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
46
|
-
|
|
47
30
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
48
|
-
|
|
49
31
|
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
50
|
-
|
|
51
32
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
52
|
-
|
|
53
33
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
54
|
-
|
|
55
34
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
56
|
-
|
|
57
35
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
58
|
-
|
|
59
36
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
60
|
-
|
|
61
37
|
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; }
|
|
62
|
-
|
|
63
38
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
64
|
-
|
|
65
39
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
66
|
-
|
|
67
40
|
var callContext = function callContext(name) {
|
|
68
41
|
return function (ev, props, context) {
|
|
69
42
|
return context[name](ev, props);
|
|
70
43
|
};
|
|
71
44
|
};
|
|
72
|
-
|
|
73
45
|
var containerHandlers = {
|
|
74
46
|
onMouseEnter: (0, _handle["default"])((0, _handle.forward)('onMouseEnter'), callContext('onPointerEnter')),
|
|
75
47
|
onMouseLeave: (0, _handle["default"])((0, _handle.forward)('onMouseLeave'), callContext('onPointerLeave')),
|
|
76
48
|
onFocusCapture: (0, _handle["default"])(callContext('onFocusCapture'), (0, _handle.forward)('onFocusCapture')),
|
|
77
49
|
onBlurCapture: (0, _handle["default"])(callContext('onBlurCapture'), (0, _handle.forward)('onBlurCapture'))
|
|
78
50
|
};
|
|
51
|
+
|
|
79
52
|
/**
|
|
80
53
|
* The class name to apply to the default component to focus in a container.
|
|
81
54
|
*
|
|
82
55
|
* @memberof spotlight/SpotlightContainerDecorator
|
|
83
56
|
* @public
|
|
84
57
|
*/
|
|
85
|
-
|
|
86
58
|
var spotlightDefaultClass = 'spottable-default';
|
|
59
|
+
|
|
87
60
|
/**
|
|
88
61
|
* Default config for {@link spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator}
|
|
89
62
|
*
|
|
90
63
|
* @memberof spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator
|
|
91
64
|
* @hocconfig
|
|
92
65
|
*/
|
|
93
|
-
|
|
94
66
|
exports.spotlightDefaultClass = spotlightDefaultClass;
|
|
95
67
|
var defaultConfig = {
|
|
96
68
|
/**
|
|
@@ -103,7 +75,6 @@ var defaultConfig = {
|
|
|
103
75
|
* @public
|
|
104
76
|
*/
|
|
105
77
|
continue5WayHold: false,
|
|
106
|
-
|
|
107
78
|
/**
|
|
108
79
|
* The selector for the default spottable element within the container.
|
|
109
80
|
* When an array of selectors is provided, the first selector that successfully matches a
|
|
@@ -115,7 +86,6 @@ var defaultConfig = {
|
|
|
115
86
|
* @public
|
|
116
87
|
*/
|
|
117
88
|
defaultElement: ".".concat(spotlightDefaultClass),
|
|
118
|
-
|
|
119
89
|
/**
|
|
120
90
|
* Directs which element receives focus when gaining focus from another container. If
|
|
121
91
|
* `'default-element'`, the default focused item will be selected. If `'last-focused'`, the
|
|
@@ -128,7 +98,6 @@ var defaultConfig = {
|
|
|
128
98
|
* @public
|
|
129
99
|
*/
|
|
130
100
|
enterTo: null,
|
|
131
|
-
|
|
132
101
|
/**
|
|
133
102
|
* Filter the navigable elements.
|
|
134
103
|
*
|
|
@@ -137,7 +106,6 @@ var defaultConfig = {
|
|
|
137
106
|
* @public
|
|
138
107
|
*/
|
|
139
108
|
navigableFilter: null,
|
|
140
|
-
|
|
141
109
|
/**
|
|
142
110
|
* Whether the container will preserve the specified `spotlightId` when it unmounts.
|
|
143
111
|
*
|
|
@@ -147,7 +115,6 @@ var defaultConfig = {
|
|
|
147
115
|
* @public
|
|
148
116
|
*/
|
|
149
117
|
preserveId: false,
|
|
150
|
-
|
|
151
118
|
/**
|
|
152
119
|
* Restricts or prioritizes navigation when focus attempts to leave the container. It
|
|
153
120
|
* can be either 'none', 'self-first', or 'self-only'. Specifying 'self-first' indicates that
|
|
@@ -164,6 +131,7 @@ var defaultConfig = {
|
|
|
164
131
|
*/
|
|
165
132
|
restrict: _propTypes["default"].oneOf(['none', 'self-first', 'self-only'])
|
|
166
133
|
};
|
|
134
|
+
|
|
167
135
|
/**
|
|
168
136
|
* Constructs a higher-order component that allows Spotlight focus to be passed to its own
|
|
169
137
|
* configurable hierarchy of spottable child controls.
|
|
@@ -206,20 +174,18 @@ var defaultConfig = {
|
|
|
206
174
|
* @memberof spotlight/SpotlightContainerDecorator
|
|
207
175
|
* @hoc
|
|
208
176
|
*/
|
|
209
|
-
|
|
210
177
|
var SpotlightContainerDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
|
|
211
178
|
var navigableFilter = config.navigableFilter,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
179
|
+
preserveId = config.preserveId,
|
|
180
|
+
containerConfig = _objectWithoutProperties(config, _excluded);
|
|
215
181
|
|
|
182
|
+
// eslint-disable-next-line no-shadow
|
|
216
183
|
function SpotlightContainerDecorator(props) {
|
|
217
184
|
var spotlightDisabled = props.spotlightDisabled,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
185
|
+
spotlightId = props.spotlightId,
|
|
186
|
+
spotlightMuted = props.spotlightMuted,
|
|
187
|
+
spotlightRestrict = props.spotlightRestrict,
|
|
188
|
+
rest = _objectWithoutProperties(props, _excluded2);
|
|
223
189
|
var spotlightContainer = (0, _useSpotlightContainer["default"])({
|
|
224
190
|
id: spotlightId,
|
|
225
191
|
muted: spotlightMuted,
|
|
@@ -233,10 +199,7 @@ var SpotlightContainerDecorator = (0, _hoc["default"])(defaultConfig, function (
|
|
|
233
199
|
var handlers = (0, _useHandlers["default"])(containerHandlers, props, spotlightContainer);
|
|
234
200
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread(_objectSpread(_objectSpread({}, rest), spotlightContainer.attributes), handlers));
|
|
235
201
|
}
|
|
236
|
-
|
|
237
|
-
SpotlightContainerDecorator.propTypes =
|
|
238
|
-
/** @lends spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator.prototype */
|
|
239
|
-
{
|
|
202
|
+
SpotlightContainerDecorator.propTypes = /** @lends spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator.prototype */{
|
|
240
203
|
/**
|
|
241
204
|
* When `true`, controls in the container cannot be navigated.
|
|
242
205
|
*
|
|
@@ -245,7 +208,6 @@ var SpotlightContainerDecorator = (0, _hoc["default"])(defaultConfig, function (
|
|
|
245
208
|
* @public
|
|
246
209
|
*/
|
|
247
210
|
spotlightDisabled: _propTypes["default"].bool,
|
|
248
|
-
|
|
249
211
|
/**
|
|
250
212
|
* Used to identify this component within the Spotlight system.
|
|
251
213
|
*
|
|
@@ -257,7 +219,6 @@ var SpotlightContainerDecorator = (0, _hoc["default"])(defaultConfig, function (
|
|
|
257
219
|
* @public
|
|
258
220
|
*/
|
|
259
221
|
spotlightId: _propTypes["default"].string,
|
|
260
|
-
|
|
261
222
|
/**
|
|
262
223
|
* Whether or not the container is in muted mode.
|
|
263
224
|
*
|
|
@@ -270,7 +231,6 @@ var SpotlightContainerDecorator = (0, _hoc["default"])(defaultConfig, function (
|
|
|
270
231
|
* @public
|
|
271
232
|
*/
|
|
272
233
|
spotlightMuted: _propTypes["default"].bool,
|
|
273
|
-
|
|
274
234
|
/**
|
|
275
235
|
* Restricts or prioritizes navigation when focus attempts to leave the container. It
|
|
276
236
|
* can be either 'none', 'self-first', or 'self-only'. Specifying 'self-first' indicates that
|
|
@@ -290,26 +250,22 @@ var SpotlightContainerDecorator = (0, _hoc["default"])(defaultConfig, function (
|
|
|
290
250
|
spotlightDisabled: false,
|
|
291
251
|
spotlightMuted: false,
|
|
292
252
|
spotlightRestrict: 'self-first'
|
|
293
|
-
};
|
|
253
|
+
};
|
|
294
254
|
|
|
255
|
+
// Wrapping with a React.Component to maintain ref support
|
|
295
256
|
return /*#__PURE__*/function (_Component) {
|
|
296
257
|
_inherits(SpotlightContainerDecoratorAdapter, _Component);
|
|
297
|
-
|
|
298
258
|
var _super = _createSuper(SpotlightContainerDecoratorAdapter);
|
|
299
|
-
|
|
300
259
|
function SpotlightContainerDecoratorAdapter() {
|
|
301
260
|
_classCallCheck(this, SpotlightContainerDecoratorAdapter);
|
|
302
|
-
|
|
303
261
|
return _super.apply(this, arguments);
|
|
304
262
|
}
|
|
305
|
-
|
|
306
263
|
_createClass(SpotlightContainerDecoratorAdapter, [{
|
|
307
264
|
key: "render",
|
|
308
265
|
value: function render() {
|
|
309
266
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(SpotlightContainerDecorator, _objectSpread({}, this.props));
|
|
310
267
|
}
|
|
311
268
|
}]);
|
|
312
|
-
|
|
313
269
|
return SpotlightContainerDecoratorAdapter;
|
|
314
270
|
}(_react.Component);
|
|
315
271
|
});
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = _default;
|
|
7
|
-
|
|
8
7
|
/* global Element */
|
|
8
|
+
|
|
9
9
|
function _default(set, remove) {
|
|
10
10
|
var polyfilled = false;
|
|
11
11
|
set(function () {
|
|
@@ -15,24 +15,19 @@ function _default(set, remove) {
|
|
|
15
15
|
while (n && n.parentNode) {
|
|
16
16
|
n = n.parentNode;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
18
|
return n;
|
|
20
19
|
};
|
|
21
|
-
|
|
22
20
|
polyfilled = true;
|
|
23
|
-
|
|
24
21
|
Element.prototype.closest = function (s) {
|
|
25
22
|
var matches = findRoot(this).querySelectorAll(s),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
i,
|
|
24
|
+
el = this;
|
|
29
25
|
do {
|
|
30
26
|
i = matches.length;
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
while (--i >= 0 && matches.item(i) !== el) {
|
|
28
|
+
// nothing
|
|
33
29
|
}
|
|
34
30
|
} while (i < 0 && (el = el.parentElement));
|
|
35
|
-
|
|
36
31
|
return el;
|
|
37
32
|
};
|
|
38
33
|
}
|
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
|
-
|
|
5
4
|
var _react = require("@testing-library/react");
|
|
6
|
-
|
|
7
5
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
8
|
-
|
|
9
6
|
var _SpotlightContainerDecorator = _interopRequireDefault(require("../SpotlightContainerDecorator"));
|
|
10
|
-
|
|
11
7
|
var _pointer = require("../../src/pointer");
|
|
12
|
-
|
|
13
8
|
var _spotlight = _interopRequireDefault(require("../../src/spotlight"));
|
|
14
|
-
|
|
15
9
|
var _ElementPrototype = _interopRequireDefault(require("./Element.prototype.closest"));
|
|
16
|
-
|
|
17
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
|
|
19
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
20
|
-
|
|
21
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
22
|
-
|
|
23
13
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
24
|
-
|
|
25
14
|
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; }
|
|
26
|
-
|
|
27
15
|
var testId = 'test-spotlightContainerDecorator';
|
|
28
16
|
describe('SpotlightContainerDecorator', function () {
|
|
29
17
|
var hoverPosition = {
|
|
@@ -34,15 +22,12 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
34
22
|
clientX: 0,
|
|
35
23
|
clientY: 0
|
|
36
24
|
};
|
|
37
|
-
|
|
38
25
|
var Div = function Div(props) {
|
|
39
26
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
40
27
|
};
|
|
41
|
-
|
|
42
28
|
(0, _ElementPrototype["default"])(beforeAll, afterAll);
|
|
43
29
|
beforeEach(function () {
|
|
44
30
|
_spotlight["default"].setActiveContainer(null);
|
|
45
|
-
|
|
46
31
|
(0, _pointer.updatePointerPosition)(0, 0);
|
|
47
32
|
});
|
|
48
33
|
test('should set itself as the active container on mouse enter', function () {
|
|
@@ -51,15 +36,10 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
51
36
|
"data-testid": testId,
|
|
52
37
|
spotlightId: "test-container"
|
|
53
38
|
}));
|
|
54
|
-
|
|
55
39
|
var component = _react.screen.getByTestId(testId);
|
|
56
|
-
|
|
57
40
|
_userEvent["default"].hover(component, hoverPosition);
|
|
58
|
-
|
|
59
41
|
var expected = 'test-container';
|
|
60
|
-
|
|
61
42
|
var actual = _spotlight["default"].getActiveContainer();
|
|
62
|
-
|
|
63
43
|
expect(actual).toBe(expected);
|
|
64
44
|
});
|
|
65
45
|
test('should set active container to parent container on mouse leave', function () {
|
|
@@ -74,20 +54,16 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
74
54
|
}), {
|
|
75
55
|
attachTo: node
|
|
76
56
|
});
|
|
57
|
+
var component = _react.screen.getByTestId(testId);
|
|
77
58
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
59
|
+
// set inner-container as active
|
|
81
60
|
_userEvent["default"].hover(component, hoverPosition);
|
|
61
|
+
(0, _pointer.updatePointerPosition)(0, 1);
|
|
82
62
|
|
|
83
|
-
|
|
84
|
-
|
|
63
|
+
// leave inner-container
|
|
85
64
|
_userEvent["default"].unhover(component, unhoverPosition);
|
|
86
|
-
|
|
87
65
|
var expected = 'outer-container';
|
|
88
|
-
|
|
89
66
|
var actual = _spotlight["default"].getActiveContainer();
|
|
90
|
-
|
|
91
67
|
expect(actual).toBe(expected);
|
|
92
68
|
});
|
|
93
69
|
test('should not set active container on mouse leave if another container is active', function () {
|
|
@@ -104,23 +80,19 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
104
80
|
}), {
|
|
105
81
|
attachTo: node
|
|
106
82
|
});
|
|
83
|
+
var component = _react.screen.getByTestId(testId);
|
|
107
84
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
85
|
+
// set inner-container as active
|
|
111
86
|
_userEvent["default"].hover(component, hoverPosition);
|
|
87
|
+
(0, _pointer.updatePointerPosition)(0, 1);
|
|
112
88
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
_spotlight["default"].setActiveContainer('self-only-container'); // leave inner-container
|
|
116
|
-
|
|
89
|
+
// set another container to be active
|
|
90
|
+
_spotlight["default"].setActiveContainer('self-only-container');
|
|
117
91
|
|
|
92
|
+
// leave inner-container
|
|
118
93
|
_userEvent["default"].unhover(component, unhoverPosition);
|
|
119
|
-
|
|
120
94
|
var expected = 'self-only-container';
|
|
121
|
-
|
|
122
95
|
var actual = _spotlight["default"].getActiveContainer();
|
|
123
|
-
|
|
124
96
|
expect(actual).toBe(expected);
|
|
125
97
|
});
|
|
126
98
|
test('should forward onFocusCapture events', function () {
|
|
@@ -149,8 +121,9 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
149
121
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
150
122
|
onFocusCapture: spy,
|
|
151
123
|
spotlightDisabled: true
|
|
152
|
-
}));
|
|
124
|
+
}));
|
|
153
125
|
|
|
126
|
+
// building out the api called on the event object + target
|
|
154
127
|
focus({
|
|
155
128
|
stopPropagation: function stopPropagation() {
|
|
156
129
|
return true;
|
|
@@ -165,9 +138,7 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
165
138
|
});
|
|
166
139
|
test('should forward onBlurCapture events', function () {
|
|
167
140
|
var spy = jest.fn();
|
|
168
|
-
|
|
169
141
|
var _blur;
|
|
170
|
-
|
|
171
142
|
var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref3) {
|
|
172
143
|
var onBlurCapture = _ref3.onBlurCapture;
|
|
173
144
|
_blur = onBlurCapture;
|
|
@@ -176,8 +147,9 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
176
147
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
177
148
|
onBlurCapture: spy,
|
|
178
149
|
spotlightDisabled: true
|
|
179
|
-
}));
|
|
150
|
+
}));
|
|
180
151
|
|
|
152
|
+
// building out the api called on the event object + target
|
|
181
153
|
_blur({
|
|
182
154
|
stopPropagation: function stopPropagation() {
|
|
183
155
|
return true;
|
|
@@ -188,19 +160,16 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
188
160
|
}
|
|
189
161
|
}
|
|
190
162
|
});
|
|
191
|
-
|
|
192
163
|
var expected = 1;
|
|
193
164
|
expect(spy).toHaveBeenCalledTimes(expected);
|
|
194
165
|
});
|
|
195
166
|
test('should suppress onBlurCapture events when focus was suppressed', function () {
|
|
196
167
|
var spy = jest.fn();
|
|
197
|
-
|
|
198
168
|
var _blur2;
|
|
199
|
-
|
|
200
169
|
var focus;
|
|
201
170
|
var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref4) {
|
|
202
171
|
var onBlurCapture = _ref4.onBlurCapture,
|
|
203
|
-
|
|
172
|
+
onFocusCapture = _ref4.onFocusCapture;
|
|
204
173
|
_blur2 = onBlurCapture;
|
|
205
174
|
focus = onFocusCapture;
|
|
206
175
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
@@ -208,8 +177,9 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
208
177
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
209
178
|
onBlurCapture: spy,
|
|
210
179
|
spotlightDisabled: true
|
|
211
|
-
}));
|
|
180
|
+
}));
|
|
212
181
|
|
|
182
|
+
// building out the api called on the event object + target
|
|
213
183
|
focus({
|
|
214
184
|
stopPropagation: function stopPropagation() {
|
|
215
185
|
return true;
|
|
@@ -1,47 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
|
-
|
|
5
4
|
var _react = require("@testing-library/react");
|
|
6
|
-
|
|
7
5
|
var _useSpotlightContainer = _interopRequireDefault(require("../useSpotlightContainer"));
|
|
8
|
-
|
|
9
6
|
var _container = require("../../src/container");
|
|
10
|
-
|
|
11
7
|
var _spotlight = _interopRequireDefault(require("../../src/spotlight"));
|
|
12
|
-
|
|
13
8
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
|
|
15
9
|
var _excluded = ["containerConfig", "preserveId", "spotlightDisabled", "spotlightId", "spotlightMuted", "spotlightRestrict"];
|
|
16
|
-
|
|
17
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
18
|
-
|
|
19
11
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
|
-
|
|
21
12
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
22
|
-
|
|
23
13
|
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; }
|
|
24
|
-
|
|
25
14
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
26
|
-
|
|
27
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
28
|
-
|
|
29
16
|
function containerExists(id) {
|
|
30
17
|
return (0, _container.getContainerConfig)(id) != null;
|
|
31
18
|
}
|
|
32
|
-
|
|
33
19
|
var testId = 'test-useSpotlightContainer';
|
|
34
20
|
describe('useSpotlightContainer', function () {
|
|
35
21
|
// TODO: Test lifecycle (e.g unload, preserveId)
|
|
22
|
+
|
|
36
23
|
function Component(props) {
|
|
37
24
|
var containerConfig = props.containerConfig,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
25
|
+
preserveId = props.preserveId,
|
|
26
|
+
spotlightDisabled = props.spotlightDisabled,
|
|
27
|
+
spotlightId = props.spotlightId,
|
|
28
|
+
spotlightMuted = props.spotlightMuted,
|
|
29
|
+
spotlightRestrict = props.spotlightRestrict,
|
|
30
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
45
31
|
var spotlightContainer = (0, _useSpotlightContainer["default"])({
|
|
46
32
|
id: spotlightId,
|
|
47
33
|
muted: spotlightMuted,
|
|
@@ -52,22 +38,19 @@ describe('useSpotlightContainer', function () {
|
|
|
52
38
|
preserveId: preserveId
|
|
53
39
|
});
|
|
54
40
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), spotlightContainer.attributes));
|
|
55
|
-
}
|
|
56
|
-
|
|
41
|
+
}
|
|
57
42
|
|
|
43
|
+
// remove all containers after each test
|
|
58
44
|
afterEach(_spotlight["default"].clear);
|
|
59
45
|
test('should support omitting the config object', function () {
|
|
60
46
|
var Comp = function Comp(props) {
|
|
61
47
|
var spotlightContainer = (0, _useSpotlightContainer["default"])();
|
|
62
48
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, props), spotlightContainer.attributes));
|
|
63
49
|
};
|
|
64
|
-
|
|
65
50
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
66
51
|
"data-testid": testId
|
|
67
52
|
}));
|
|
68
|
-
|
|
69
53
|
var component = _react.screen.getByTestId(testId);
|
|
70
|
-
|
|
71
54
|
var expectedAttribute = 'data-spotlight-container';
|
|
72
55
|
var expectedValue = 'true';
|
|
73
56
|
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
@@ -77,9 +60,7 @@ describe('useSpotlightContainer', function () {
|
|
|
77
60
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
78
61
|
"data-testid": testId
|
|
79
62
|
}));
|
|
80
|
-
|
|
81
63
|
var component = _react.screen.getByTestId(testId);
|
|
82
|
-
|
|
83
64
|
var expectedAttribute = 'data-spotlight-container';
|
|
84
65
|
var expectedValue = 'true';
|
|
85
66
|
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
@@ -88,27 +69,21 @@ describe('useSpotlightContainer', function () {
|
|
|
88
69
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
89
70
|
"data-testid": testId
|
|
90
71
|
}));
|
|
91
|
-
|
|
92
72
|
var component = _react.screen.getByTestId(testId);
|
|
93
|
-
|
|
94
73
|
var expectedAttribute = 'data-spotlight-id';
|
|
95
74
|
var expectedValue = expect.stringMatching(/container-\d+/);
|
|
96
75
|
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
97
76
|
});
|
|
98
77
|
test('should reuse the same generated `data-spotlight-id` attribute on re-render', function () {
|
|
99
78
|
var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
79
|
+
"data-testid": testId
|
|
80
|
+
})),
|
|
81
|
+
rerender = _render.rerender;
|
|
104
82
|
var expected = _react.screen.getByTestId(testId).getAttribute('data-spotlight-id');
|
|
105
|
-
|
|
106
83
|
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
107
84
|
"data-testid": testId
|
|
108
85
|
}));
|
|
109
|
-
|
|
110
86
|
var actual = _react.screen.getByTestId(testId).getAttribute('data-spotlight-id');
|
|
111
|
-
|
|
112
87
|
expect(actual).toBe(expected);
|
|
113
88
|
});
|
|
114
89
|
test('should set a `data-spotlight-id` attribute when `id` is set', function () {
|
|
@@ -117,9 +92,7 @@ describe('useSpotlightContainer', function () {
|
|
|
117
92
|
"data-testid": testId,
|
|
118
93
|
spotlightId: id
|
|
119
94
|
}));
|
|
120
|
-
|
|
121
95
|
var component = _react.screen.getByTestId(testId);
|
|
122
|
-
|
|
123
96
|
var expectedAttribute = 'data-spotlight-id';
|
|
124
97
|
expect(component).toHaveAttribute(expectedAttribute, id);
|
|
125
98
|
});
|
|
@@ -127,9 +100,7 @@ describe('useSpotlightContainer', function () {
|
|
|
127
100
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
128
101
|
"data-testid": testId
|
|
129
102
|
}));
|
|
130
|
-
|
|
131
103
|
var component = _react.screen.getByTestId(testId);
|
|
132
|
-
|
|
133
104
|
var expectedAttribute = 'data-spotlight-container-disabled';
|
|
134
105
|
expect(component).not.toHaveAttribute(expectedAttribute);
|
|
135
106
|
});
|
|
@@ -138,9 +109,7 @@ describe('useSpotlightContainer', function () {
|
|
|
138
109
|
"data-testid": testId,
|
|
139
110
|
spotlightDisabled: true
|
|
140
111
|
}));
|
|
141
|
-
|
|
142
112
|
var component = _react.screen.getByTestId(testId);
|
|
143
|
-
|
|
144
113
|
var expectedAttribute = 'data-spotlight-container-disabled';
|
|
145
114
|
var expectedValue = 'true';
|
|
146
115
|
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
@@ -149,9 +118,7 @@ describe('useSpotlightContainer', function () {
|
|
|
149
118
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
150
119
|
"data-testid": testId
|
|
151
120
|
}));
|
|
152
|
-
|
|
153
121
|
var component = _react.screen.getByTestId(testId);
|
|
154
|
-
|
|
155
122
|
var expectedAttribute = 'data-spotlight-container-muted';
|
|
156
123
|
expect(component).not.toHaveAttribute(expectedAttribute);
|
|
157
124
|
});
|
|
@@ -160,9 +127,7 @@ describe('useSpotlightContainer', function () {
|
|
|
160
127
|
"data-testid": testId,
|
|
161
128
|
spotlightMuted: true
|
|
162
129
|
}));
|
|
163
|
-
|
|
164
130
|
var component = _react.screen.getByTestId(testId);
|
|
165
|
-
|
|
166
131
|
var expectedAttribute = 'data-spotlight-container-muted';
|
|
167
132
|
var expectedValue = 'true';
|
|
168
133
|
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
@@ -199,13 +164,11 @@ describe('useSpotlightContainer', function () {
|
|
|
199
164
|
});
|
|
200
165
|
test('should update restrict value', function () {
|
|
201
166
|
var id = 'my-container';
|
|
202
|
-
|
|
203
167
|
var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
168
|
+
spotlightId: id,
|
|
169
|
+
spotlightRestrict: "self-only"
|
|
170
|
+
})),
|
|
171
|
+
rerender = _render2.rerender;
|
|
209
172
|
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
210
173
|
spotlightId: id,
|
|
211
174
|
spotlightRestrict: "self-first"
|