@enact/spotlight 3.4.9-experimental-3 → 3.4.9-experimental-7

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.
Files changed (68) hide show
  1. package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
  2. package/Accelerator/Accelerator.js +149 -156
  3. package/CHANGELOG.md +22 -0
  4. package/{build/Pause → Pause}/Pause.d.ts +0 -0
  5. package/Pause/Pause.js +102 -80
  6. package/Pause/tests/Pause-specs.js +65 -97
  7. package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
  8. package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
  9. package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
  10. package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
  11. package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
  12. package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
  13. package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
  14. package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
  15. package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
  16. package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
  17. package/Spottable/Spottable.js +448 -410
  18. package/Spottable/tests/Spottable-specs.js +90 -117
  19. package/package.json +3 -2
  20. package/src/container.js +718 -653
  21. package/src/navigate.js +406 -491
  22. package/src/pointer.js +86 -78
  23. package/{build/src → src}/spotlight.d.ts +0 -0
  24. package/src/spotlight.js +846 -885
  25. package/src/target.js +448 -474
  26. package/src/tests/container-specs.js +643 -1251
  27. package/src/tests/navigate-specs.js +77 -134
  28. package/src/tests/pointer-specs.js +126 -182
  29. package/src/tests/spotlight-specs.js +103 -133
  30. package/src/tests/target-specs.js +597 -960
  31. package/src/tests/utils.js +89 -67
  32. package/src/utils.js +155 -158
  33. package/build/Accelerator/Accelerator.js +0 -162
  34. package/build/Accelerator/package.json +0 -3
  35. package/build/CHANGELOG.md +0 -838
  36. package/build/Pause/Pause.js +0 -164
  37. package/build/Pause/package.json +0 -3
  38. package/build/Pause/tests/Pause-specs.js +0 -65
  39. package/build/README.md +0 -61
  40. package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
  41. package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
  42. package/build/SpotlightContainerDecorator/package.json +0 -3
  43. package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
  44. package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
  45. package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
  46. package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
  47. package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
  48. package/build/SpotlightRootDecorator/package.json +0 -3
  49. package/build/Spottable/Spottable.js +0 -491
  50. package/build/Spottable/package.json +0 -3
  51. package/build/Spottable/tests/Spottable-specs.js +0 -90
  52. package/build/package-lock.json +0 -229
  53. package/build/package.json +0 -28
  54. package/build/src/container.js +0 -1201
  55. package/build/src/navigate.js +0 -419
  56. package/build/src/pointer.js +0 -183
  57. package/build/src/spotlight.js +0 -896
  58. package/build/src/target.js +0 -507
  59. package/build/src/tests/container-specs.js +0 -653
  60. package/build/src/tests/navigate-specs.js +0 -87
  61. package/build/src/tests/pointer-specs.js +0 -130
  62. package/build/src/tests/spotlight-specs.js +0 -112
  63. package/build/src/tests/target-specs.js +0 -614
  64. package/build/src/tests/utils.js +0 -104
  65. package/build/src/utils.js +0 -180
  66. package/build/styles/debug.less +0 -97
  67. package/build/styles/mixins.less +0 -63
  68. package/docs/index.md +0 -364
@@ -1,282 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "useSpotlightContainer", {
7
- enumerable: true,
8
- get: function get() {
9
- return _useSpotlightContainer["default"];
10
- }
11
- });
12
- exports.spotlightDefaultClass = exports.SpotlightContainerDecorator = exports["default"] = void 0;
13
-
14
- var _handle = _interopRequireWildcard(require("@enact/core/handle"));
15
-
16
- var _useHandlers = _interopRequireDefault(require("@enact/core/useHandlers"));
17
-
18
- var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
19
-
20
- var _react = _interopRequireDefault(require("react"));
21
-
22
- var _propTypes = _interopRequireDefault(require("prop-types"));
23
-
24
- var _useSpotlightContainer = _interopRequireDefault(require("./useSpotlightContainer"));
25
-
26
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
27
-
28
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
29
-
30
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
31
-
32
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
33
-
34
- 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); } }
35
-
36
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
37
-
38
- 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); }
39
-
40
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
41
-
42
- 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); }; }
43
-
44
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
45
-
46
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
47
-
48
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
49
-
50
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
51
-
52
- 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; }
53
-
54
- 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; }
55
-
56
- var callContext = function callContext(name) {
57
- return function (ev, props, context) {
58
- return context[name](ev, props);
59
- };
60
- };
61
-
62
- var containerHandlers = {
63
- onMouseEnter: (0, _handle["default"])((0, _handle.forward)('onMouseEnter'), callContext('onPointerEnter')),
64
- onMouseLeave: (0, _handle["default"])((0, _handle.forward)('onMouseLeave'), callContext('onPointerLeave')),
65
- onFocusCapture: (0, _handle["default"])(callContext('onFocusCapture'), (0, _handle.forward)('onFocusCapture')),
66
- onBlurCapture: (0, _handle["default"])(callContext('onBlurCapture'), (0, _handle.forward)('onBlurCapture'))
67
- };
68
- /**
69
- * The class name to apply to the default component to focus in a container.
70
- *
71
- * @memberof spotlight/SpotlightContainerDecorator
72
- * @public
73
- */
74
-
75
- var spotlightDefaultClass = 'spottable-default';
76
- /**
77
- * Default config for {@link spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator}
78
- *
79
- * @memberof spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator
80
- * @hocconfig
81
- */
82
-
83
- exports.spotlightDefaultClass = spotlightDefaultClass;
84
- var defaultConfig = {
85
- /**
86
- * When `true`, allows focus to move outside the container to the next spottable element when
87
- * holding 5 way keys.
88
- *
89
- * @type {Boolean}
90
- * @default false
91
- * @memberof spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator.defaultConfig
92
- * @public
93
- */
94
- continue5WayHold: false,
95
-
96
- /**
97
- * The selector for the default spottable element within the container.
98
- *
99
- * @type {String}
100
- * @default '.spottable-default'
101
- * @memberof spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator.defaultConfig
102
- * @public
103
- */
104
- defaultElement: ".".concat(spotlightDefaultClass),
105
-
106
- /**
107
- * Directs which element receives focus when gaining focus from another container. If
108
- * `'default-element'`, the default focused item will be selected. If `'last-focused'`, the
109
- * container will focus the last focused item; if the container has never had focus, the default
110
- * element will receive focus. If `null`, the default 5-way behavior will be applied.
111
- *
112
- * @type {String}
113
- * @default null
114
- * @memberof spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator.defaultConfig
115
- * @public
116
- */
117
- enterTo: null,
118
-
119
- /**
120
- * Filter the navigable elements.
121
- *
122
- * @type {Function}
123
- * @memberof spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator.defaultConfig
124
- * @public
125
- */
126
- navigableFilter: null,
127
-
128
- /**
129
- * Whether the container will preserve the specified `spotlightId` when it unmounts.
130
- *
131
- * @type {Boolean}
132
- * @default false
133
- * @memberof spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator.defaultConfig
134
- * @public
135
- */
136
- preserveId: false
137
- };
138
- /**
139
- * Constructs a higher-order component that allows Spotlight focus to be passed to its own
140
- * configurable hierarchy of spottable child controls.
141
- *
142
- * Note: This HoC passes a number of props to the wrapped component that should be passed to the
143
- * main DOM node.
144
- *
145
- * Example:
146
- * ```
147
- * const Component = ({myProp, ...rest}) => (
148
- * <div {...rest}>{myProp}</div>
149
- * );
150
- * ...
151
- * const DefaultContainer = SpotlightContainerDecorator(Component);
152
- * const FocusDefaultContainer = SpotlightContainerDecorator({enterTo: 'default-element'}, Component);
153
- * ```
154
- *
155
- * To specify a default element to spot in a container, utilize the `spotlightDefaultClass`.
156
- *
157
- * Example:
158
- * ```
159
- * import Spotlight from '@enact/spotlight';
160
- * import SpotlightContainerDecorator from '@enact/spotlight/SpotlightContainerDecorator';
161
- * const ContainerComponent = SpotlightContainerDecorator(Component);
162
- * const View = kind({
163
- * render: () => {
164
- * <ContainerComponent>
165
- * <SpottableComponent>foo</SpottableComponent>
166
- * <SpottableComponent className={spotlightDefaultClass}>spot me first</SpottableComponent>
167
- * </ContainerComponent>
168
- * }
169
- * });
170
- * ```
171
- * @param {Object} defaultConfig Set of default configuration parameters. Additional parameters
172
- * are passed as configuration to {@link spotlight/Spotlight.set}
173
- * @param {Function} higher-order component
174
- *
175
- * @returns {Function} SpotlightContainerDecorator
176
- * @class SpotlightContainerDecorator
177
- * @memberof spotlight/SpotlightContainerDecorator
178
- * @hoc
179
- */
180
-
181
- var SpotlightContainerDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
182
- var navigableFilter = config.navigableFilter,
183
- preserveId = config.preserveId,
184
- containerConfig = _objectWithoutProperties(config, ["navigableFilter", "preserveId"]); // eslint-disable-next-line no-shadow
185
-
186
-
187
- function SpotlightContainerDecorator(props) {
188
- var spotlightDisabled = props.spotlightDisabled,
189
- spotlightId = props.spotlightId,
190
- spotlightMuted = props.spotlightMuted,
191
- spotlightRestrict = props.spotlightRestrict,
192
- rest = _objectWithoutProperties(props, ["spotlightDisabled", "spotlightId", "spotlightMuted", "spotlightRestrict"]);
193
-
194
- var spotlightContainer = (0, _useSpotlightContainer["default"])({
195
- id: spotlightId,
196
- muted: spotlightMuted,
197
- disabled: spotlightDisabled,
198
- restrict: spotlightRestrict,
199
- containerConfig: containerConfig,
200
- // continue5WayHold, defaultElement, and enterTo can be in the containerConfig object.
201
- navigableFilter: navigableFilter,
202
- preserveId: preserveId
203
- });
204
- var handlers = (0, _useHandlers["default"])(containerHandlers, props, spotlightContainer);
205
- return /*#__PURE__*/_react["default"].createElement(Wrapped, Object.assign({}, rest, spotlightContainer.attributes, handlers));
206
- }
207
-
208
- SpotlightContainerDecorator.propTypes =
209
- /** @lends spotlight/SpotlightContainerDecorator.SpotlightContainerDecorator.prototype */
210
- {
211
- /**
212
- * When `true`, controls in the container cannot be navigated.
213
- *
214
- * @type {Boolean}
215
- * @default false
216
- * @public
217
- */
218
- spotlightDisabled: _propTypes["default"].bool,
219
-
220
- /**
221
- * Used to identify this component within the Spotlight system.
222
- *
223
- * If the value is `null`, an id will be generated.
224
- *
225
- * @type {String}
226
- * @public
227
- */
228
- spotlightId: _propTypes["default"].string,
229
-
230
- /**
231
- * Whether or not the container is in muted mode.
232
- *
233
- * @type {Boolean}
234
- * @default false
235
- * @public
236
- */
237
- spotlightMuted: _propTypes["default"].bool,
238
-
239
- /**
240
- * Restricts or prioritizes navigation when focus attempts to leave the container. It
241
- * can be either 'none', 'self-first', or 'self-only'. Specifying 'self-first' indicates that
242
- * elements within the container will have a higher likelihood to be chosen as the next
243
- * navigable element. Specifying 'self-only' indicates that elements in other containers
244
- * cannot be navigated to by using 5-way navigation - however, elements in other containers
245
- * can still receive focus by calling `Spotlight.focus(elem)` explicitly. Specifying 'none'
246
- * indicates there should be no restrictions when 5-way navigating the container.
247
- *
248
- * @type {String}
249
- * @public
250
- */
251
- spotlightRestrict: _propTypes["default"].oneOf(['none', 'self-first', 'self-only'])
252
- };
253
- SpotlightContainerDecorator.defaultProps = {
254
- spotlightDisabled: false,
255
- spotlightMuted: false,
256
- spotlightRestrict: 'self-first'
257
- }; // Wrapping with a React.Component to maintain ref support
258
-
259
- return /*#__PURE__*/function (_React$Component) {
260
- _inherits(SpotlightContainerDecoratorAdapter, _React$Component);
261
-
262
- var _super = _createSuper(SpotlightContainerDecoratorAdapter);
263
-
264
- function SpotlightContainerDecoratorAdapter() {
265
- _classCallCheck(this, SpotlightContainerDecoratorAdapter);
266
-
267
- return _super.apply(this, arguments);
268
- }
269
-
270
- _createClass(SpotlightContainerDecoratorAdapter, [{
271
- key: "render",
272
- value: function render() {
273
- return /*#__PURE__*/_react["default"].createElement(SpotlightContainerDecorator, this.props);
274
- }
275
- }]);
276
-
277
- return SpotlightContainerDecoratorAdapter;
278
- }(_react["default"].Component);
279
- });
280
- exports.SpotlightContainerDecorator = SpotlightContainerDecorator;
281
- var _default = SpotlightContainerDecorator;
282
- exports["default"] = _default;
@@ -1,3 +0,0 @@
1
- {
2
- "main": "SpotlightContainerDecorator.js"
3
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = _default;
7
-
8
- /* global Element */
9
- function _default(set, remove) {
10
- var polyfilled = false;
11
- set(function () {
12
- if (!Element.prototype.closest) {
13
- // we're using detached nodes so we have to find the root node rather than the document
14
- var findRoot = function findRoot(n) {
15
- while (n && n.parentNode) {
16
- n = n.parentNode;
17
- }
18
-
19
- return n;
20
- };
21
-
22
- polyfilled = true;
23
-
24
- Element.prototype.closest = function (s) {
25
- var matches = findRoot(this).querySelectorAll(s),
26
- i,
27
- el = this;
28
-
29
- do {
30
- i = matches.length;
31
-
32
- while (--i >= 0 && matches.item(i) !== el) {// nothing
33
- }
34
- } while (i < 0 && (el = el.parentElement));
35
-
36
- return el;
37
- };
38
- }
39
- });
40
- remove(function () {
41
- if (polyfilled) {
42
- delete Element.prototype.closest;
43
- }
44
- });
45
- }
@@ -1,221 +0,0 @@
1
- "use strict";
2
-
3
- var _enzyme = require("enzyme");
4
-
5
- var _react = _interopRequireDefault(require("react"));
6
-
7
- var _spotlight = _interopRequireDefault(require("../../src/spotlight"));
8
-
9
- var _pointer = require("../../src/pointer");
10
-
11
- var _SpotlightContainerDecorator = _interopRequireDefault(require("../SpotlightContainerDecorator"));
12
-
13
- var _ElementPrototype = _interopRequireDefault(require("./Element.prototype.closest"));
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
16
-
17
- 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; }
18
-
19
- 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) { _defineProperty(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; }
20
-
21
- 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; }
22
-
23
- describe('SpotlightContainerDecorator', function () {
24
- var hoverPosition = {
25
- clientX: 0,
26
- clientY: 1
27
- };
28
- var unhoverPosition = {
29
- clientX: 0,
30
- clientY: 0
31
- };
32
-
33
- var Div = function Div(props) {
34
- return /*#__PURE__*/_react["default"].createElement("div", props);
35
- };
36
-
37
- (0, _ElementPrototype["default"])(beforeAll, afterAll);
38
- beforeEach(function () {
39
- _spotlight["default"].setActiveContainer(null);
40
-
41
- (0, _pointer.updatePointerPosition)(0, 0);
42
- });
43
- test('should set itself as the active container on mouse enter', function () {
44
- var Component = (0, _SpotlightContainerDecorator["default"])(Div);
45
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
46
- spotlightId: "test-container"
47
- }));
48
- subject.find(Div).prop('onMouseEnter')(hoverPosition);
49
- var expected = 'test-container';
50
-
51
- var actual = _spotlight["default"].getActiveContainer();
52
-
53
- expect(actual).toBe(expected);
54
- });
55
- test('should set active container to parent container on mouse leave', function () {
56
- var Component = (0, _SpotlightContainerDecorator["default"])(Div);
57
- var node = document.createElement('div');
58
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
59
- spotlightId: "outer-container"
60
- }, /*#__PURE__*/_react["default"].createElement(Component, {
61
- spotlightId: "inner-container"
62
- })), {
63
- attachTo: node
64
- });
65
- var selector = 'div[data-spotlight-id="inner-container"]';
66
- var innerWrapper = subject.find(selector);
67
- var innerNode = node.querySelector(selector); // set inner-container as active
68
-
69
- innerWrapper.prop('onMouseEnter')(hoverPosition);
70
- (0, _pointer.updatePointerPosition)(0, 1); // leave inner-container
71
-
72
- innerWrapper.prop('onMouseLeave')(_objectSpread(_objectSpread({}, unhoverPosition), {}, {
73
- currentTarget: innerNode
74
- }));
75
- var expected = 'outer-container';
76
-
77
- var actual = _spotlight["default"].getActiveContainer();
78
-
79
- expect(actual).toBe(expected);
80
- });
81
- test('should not set active container on mouse leave if another container is active', function () {
82
- var Component = (0, _SpotlightContainerDecorator["default"])(Div);
83
- var node = document.createElement('div');
84
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
85
- spotlightId: "outer-container"
86
- }, /*#__PURE__*/_react["default"].createElement(Component, {
87
- spotlightId: "inner-container"
88
- }), /*#__PURE__*/_react["default"].createElement(Component, {
89
- spotlightId: "self-only-container"
90
- })), {
91
- attachTo: node
92
- });
93
- var selector = 'div[data-spotlight-id="inner-container"]';
94
- var innerWrapper = subject.find(selector);
95
- var innerNode = node.querySelector(selector); // set inner-container as active
96
-
97
- innerWrapper.prop('onMouseEnter')(hoverPosition);
98
- (0, _pointer.updatePointerPosition)(0, 1); // set another container to be active
99
-
100
- _spotlight["default"].setActiveContainer('self-only-container'); // leave inner-container
101
-
102
-
103
- innerWrapper.prop('onMouseLeave')(_objectSpread(_objectSpread({}, unhoverPosition), {}, {
104
- currentTarget: innerNode
105
- }));
106
- var expected = 'self-only-container';
107
-
108
- var actual = _spotlight["default"].getActiveContainer();
109
-
110
- expect(actual).toBe(expected);
111
- });
112
- test('should forward onFocusCapture events', function () {
113
- var spy = jest.fn();
114
- var focus;
115
- var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref) {
116
- var onFocusCapture = _ref.onFocusCapture;
117
- focus = onFocusCapture;
118
- return /*#__PURE__*/_react["default"].createElement("div", null);
119
- });
120
- (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
121
- onFocusCapture: spy
122
- }));
123
- focus({});
124
- var expected = 1;
125
- var actual = spy.mock.calls.length;
126
- expect(actual).toBe(expected);
127
- });
128
- test('should suppress onFocusCapture events when spotlightDisabled', function () {
129
- var spy = jest.fn();
130
- var focus;
131
- var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref2) {
132
- var onFocusCapture = _ref2.onFocusCapture;
133
- focus = onFocusCapture;
134
- return /*#__PURE__*/_react["default"].createElement("div", null);
135
- });
136
- (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
137
- onFocusCapture: spy,
138
- spotlightDisabled: true
139
- })); // building out the api called on the event object + target
140
-
141
- focus({
142
- stopPropagation: function stopPropagation() {
143
- return true;
144
- },
145
- target: {
146
- blur: function blur() {
147
- return true;
148
- }
149
- }
150
- });
151
- var expected = 0;
152
- var actual = spy.mock.calls.length;
153
- expect(actual).toBe(expected);
154
- });
155
- test('should forward onBlurCapture events', function () {
156
- var spy = jest.fn();
157
-
158
- var _blur;
159
-
160
- var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref3) {
161
- var onBlurCapture = _ref3.onBlurCapture;
162
- _blur = onBlurCapture;
163
- return /*#__PURE__*/_react["default"].createElement("div", null);
164
- });
165
- (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
166
- onBlurCapture: spy,
167
- spotlightDisabled: true
168
- })); // building out the api called on the event object + target
169
-
170
- _blur({
171
- stopPropagation: function stopPropagation() {
172
- return true;
173
- },
174
- target: {
175
- blur: function blur() {
176
- return _blur({});
177
- }
178
- }
179
- });
180
-
181
- var expected = 1;
182
- var actual = spy.mock.calls.length;
183
- expect(actual).toBe(expected);
184
- });
185
- test('should suppress onBlurCapture events when focus was suppressed', function () {
186
- var spy = jest.fn();
187
- var focus;
188
-
189
- var _blur2;
190
-
191
- var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref4) {
192
- var onBlurCapture = _ref4.onBlurCapture,
193
- onFocusCapture = _ref4.onFocusCapture;
194
- _blur2 = onBlurCapture;
195
- focus = onFocusCapture;
196
- return /*#__PURE__*/_react["default"].createElement("div", null);
197
- });
198
- (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
199
- onBlurCapture: spy,
200
- spotlightDisabled: true
201
- })); // building out the api called on the event object + target
202
-
203
- focus({
204
- stopPropagation: function stopPropagation() {
205
- return true;
206
- },
207
- target: {
208
- // the focus handler calls blur() on the target so we're simulating that here by
209
- // wiring our onBlurCapture handler directly to the invocation. This isn't a
210
- // perfect modeling of the system but serves to validate the callback
211
- // suppression logic.
212
- blur: function blur() {
213
- return _blur2({});
214
- }
215
- }
216
- });
217
- var expected = 0;
218
- var actual = spy.mock.calls.length;
219
- expect(actual).toBe(expected);
220
- });
221
- });