@enact/spotlight 4.1.2 → 4.5.0-alpha.1
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.d.ts +2 -5
- package/Accelerator/Accelerator.js +7 -3
- package/CHANGELOG.md +17 -0
- package/Pause/Pause.d.ts +4 -6
- package/Pause/Pause.js +2 -2
- package/Pause/tests/Pause-specs.js +2 -2
- package/README.md +1 -1
- package/SpotlightContainerDecorator/SpotlightContainer.js +4 -4
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +13 -10
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +44 -38
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +106 -52
- package/SpotlightContainerDecorator/useSpotlightContainer.js +4 -2
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +9 -16
- package/Spottable/Spottable.js +11 -9
- package/Spottable/SpottableCore.js +4 -4
- package/Spottable/tests/Spottable-specs.js +66 -37
- package/Spottable/tests/useSpot-specs.js +128 -71
- package/Spottable/useSpottable.js +7 -4
- package/package.json +8 -8
- package/src/container.js +24 -16
- package/src/navigate.js +1 -1
- package/src/spotlight.js +1 -1
- package/src/target.js +3 -3
- package/src/tests/utils.js +2 -2
- package/src/utils.js +11 -9
- package/styles/debug.less +80 -82
|
@@ -4,11 +4,13 @@ var _handle = _interopRequireWildcard(require("@enact/core/handle"));
|
|
|
4
4
|
|
|
5
5
|
var _useHandlers = _interopRequireDefault(require("@enact/core/useHandlers"));
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
require("@testing-library/jest-dom");
|
|
8
|
+
|
|
9
|
+
var _react = require("@testing-library/react");
|
|
8
10
|
|
|
9
|
-
var
|
|
11
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
12
|
|
|
11
|
-
var
|
|
13
|
+
var _react2 = require("react");
|
|
12
14
|
|
|
13
15
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
14
16
|
|
|
@@ -18,25 +20,27 @@ var _useSpottable = _interopRequireDefault(require("../useSpottable"));
|
|
|
18
20
|
|
|
19
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
22
|
|
|
23
|
+
var _excluded = ["className", "component", "componentRef", "disabled", "emulateMouse", "onSelectionCancel", "onSpotlightDisappear", "onSpotlightDown", "onSpotlightLeft", "onSpotlightRight", "onSpotlightUp", "selectionKeys", "spotlightDisabled", "spotlightId"];
|
|
24
|
+
|
|
21
25
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
22
26
|
|
|
23
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
27
|
+
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); }
|
|
24
28
|
|
|
25
|
-
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; }
|
|
29
|
+
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; }
|
|
26
30
|
|
|
27
31
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
28
32
|
|
|
29
33
|
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); } }
|
|
30
34
|
|
|
31
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
35
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
32
36
|
|
|
33
|
-
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); }
|
|
37
|
+
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); }
|
|
34
38
|
|
|
35
39
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
36
40
|
|
|
37
41
|
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); }; }
|
|
38
42
|
|
|
39
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
43
|
+
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); }
|
|
40
44
|
|
|
41
45
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
42
46
|
|
|
@@ -44,9 +48,9 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
44
48
|
|
|
45
49
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
46
50
|
|
|
47
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
51
|
+
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; }
|
|
48
52
|
|
|
49
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
53
|
+
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; }
|
|
50
54
|
|
|
51
55
|
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; }
|
|
52
56
|
|
|
@@ -57,7 +61,8 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
57
61
|
var forwardMouseUp = (0, _handle.forward)('onMouseUp'),
|
|
58
62
|
forwardMouseDown = (0, _handle.forward)('onMouseDown'),
|
|
59
63
|
forwardKeyDown = (0, _handle.forward)('onKeyDown'),
|
|
60
|
-
forwardKeyUp = (0, _handle.forward)('onKeyUp')
|
|
64
|
+
forwardKeyUp = (0, _handle.forward)('onKeyUp'),
|
|
65
|
+
id = 'test-useSpot';
|
|
61
66
|
|
|
62
67
|
var makeKeyEvent = function makeKeyEvent(keyCode) {
|
|
63
68
|
return {
|
|
@@ -100,7 +105,7 @@ describe('useSpottable', function () {
|
|
|
100
105
|
selectionKeys = props.selectionKeys,
|
|
101
106
|
spotlightDisabled = props.spotlightDisabled,
|
|
102
107
|
spotlightId = props.spotlightId,
|
|
103
|
-
rest = _objectWithoutProperties(props,
|
|
108
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
104
109
|
|
|
105
110
|
var spot = (0, _useSpottable["default"])({
|
|
106
111
|
disabled: disabled,
|
|
@@ -158,7 +163,7 @@ describe('useSpottable', function () {
|
|
|
158
163
|
}]);
|
|
159
164
|
|
|
160
165
|
return SpottableComponent;
|
|
161
|
-
}(
|
|
166
|
+
}(_react2.Component);
|
|
162
167
|
|
|
163
168
|
beforeEach(function () {
|
|
164
169
|
// Spotlight.getCurrent() did not work in unit tests. It always returns `undefined`.
|
|
@@ -172,92 +177,127 @@ describe('useSpottable', function () {
|
|
|
172
177
|
_spotlight["default"].getCurrent = getCurrent;
|
|
173
178
|
});
|
|
174
179
|
test('should add the spottable class', function () {
|
|
175
|
-
|
|
180
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
181
|
+
"data-testid": id
|
|
182
|
+
}));
|
|
183
|
+
|
|
184
|
+
var div = _react.screen.getByTestId(id);
|
|
185
|
+
|
|
176
186
|
var expected = 'spottable';
|
|
177
|
-
|
|
178
|
-
expect(actual).toEqual(expected);
|
|
187
|
+
expect(div).toHaveClass(expected);
|
|
179
188
|
});
|
|
180
189
|
test('should add the spottable class to a {disabled} component', function () {
|
|
181
|
-
|
|
190
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
191
|
+
"data-testid": id,
|
|
182
192
|
disabled: true
|
|
183
193
|
}));
|
|
194
|
+
|
|
195
|
+
var div = _react.screen.getByTestId(id);
|
|
196
|
+
|
|
184
197
|
var expected = 'spottable';
|
|
185
|
-
|
|
186
|
-
expect(actual).toEqual(expected);
|
|
198
|
+
expect(div).toHaveClass(expected);
|
|
187
199
|
});
|
|
188
200
|
test('should not add the spottable class to a {spotlightDisabled} component', function () {
|
|
189
|
-
|
|
201
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
202
|
+
"data-testid": id,
|
|
190
203
|
spotlightDisabled: true
|
|
191
204
|
}));
|
|
205
|
+
|
|
206
|
+
var div = _react.screen.getByTestId(id);
|
|
207
|
+
|
|
192
208
|
var expected = 'spottable';
|
|
193
|
-
|
|
194
|
-
expect(actual).not.toEqual(expected);
|
|
209
|
+
expect(div).not.toHaveClass(expected);
|
|
195
210
|
});
|
|
196
211
|
describe('should emit event properly', function () {
|
|
197
212
|
test('should emit {onSpotlightUp} when the the {keydown} is emitted with 38 keycode', function () {
|
|
198
213
|
var spy = jest.fn();
|
|
199
|
-
|
|
214
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
215
|
+
"data-testid": id,
|
|
200
216
|
onSpotlightUp: spy
|
|
201
217
|
}));
|
|
202
|
-
|
|
218
|
+
|
|
219
|
+
var div = _react.screen.getByTestId(id);
|
|
220
|
+
|
|
221
|
+
_react.fireEvent.keyDown(div, makeKeyEvent(38));
|
|
222
|
+
|
|
203
223
|
var expected = 1;
|
|
204
|
-
|
|
205
|
-
expect(actual).toEqual(expected);
|
|
224
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
206
225
|
});
|
|
207
226
|
test('should emit {onSpotlightDown} when the the {keydown} is emitted with 40 keycode', function () {
|
|
208
227
|
var spy = jest.fn();
|
|
209
|
-
|
|
228
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
229
|
+
"data-testid": id,
|
|
210
230
|
onSpotlightDown: spy
|
|
211
231
|
}));
|
|
212
|
-
|
|
232
|
+
|
|
233
|
+
var div = _react.screen.getByTestId(id);
|
|
234
|
+
|
|
235
|
+
_react.fireEvent.keyDown(div, makeKeyEvent(40));
|
|
236
|
+
|
|
213
237
|
var expected = 1;
|
|
214
|
-
|
|
215
|
-
expect(actual).toEqual(expected);
|
|
238
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
216
239
|
});
|
|
217
240
|
test('should emit {onSpotlightLeft} when the the {keydown} is emitted with 37 keycode', function () {
|
|
218
241
|
var spy = jest.fn();
|
|
219
|
-
|
|
242
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
243
|
+
"data-testid": id,
|
|
220
244
|
onSpotlightLeft: spy
|
|
221
245
|
}));
|
|
222
|
-
|
|
246
|
+
|
|
247
|
+
var div = _react.screen.getByTestId(id);
|
|
248
|
+
|
|
249
|
+
_react.fireEvent.keyDown(div, makeKeyEvent(37));
|
|
250
|
+
|
|
223
251
|
var expected = 1;
|
|
224
|
-
|
|
225
|
-
expect(actual).toEqual(expected);
|
|
252
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
226
253
|
});
|
|
227
254
|
test('should emit {onSpotlightRight} when the the {keydown} is emitted with 39 keycode', function () {
|
|
228
255
|
var spy = jest.fn();
|
|
229
|
-
|
|
256
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
257
|
+
"data-testid": id,
|
|
230
258
|
onSpotlightRight: spy
|
|
231
259
|
}));
|
|
232
|
-
|
|
260
|
+
|
|
261
|
+
var div = _react.screen.getByTestId(id);
|
|
262
|
+
|
|
263
|
+
_react.fireEvent.keyDown(div, makeKeyEvent(39));
|
|
264
|
+
|
|
233
265
|
var expected = 1;
|
|
234
|
-
|
|
235
|
-
expect(actual).toEqual(expected);
|
|
266
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
236
267
|
});
|
|
237
268
|
test('should emulate {onMouseDown} when REMOTE_OK_KEY key is pressed', function () {
|
|
238
269
|
var spy = jest.fn();
|
|
239
|
-
|
|
270
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
271
|
+
"data-testid": id,
|
|
240
272
|
emulateMouse: true,
|
|
241
273
|
onMouseDown: spy,
|
|
242
274
|
selectionKeys: [13]
|
|
243
275
|
}));
|
|
244
|
-
|
|
276
|
+
|
|
277
|
+
var div = _react.screen.getByTestId(id);
|
|
278
|
+
|
|
279
|
+
_react.fireEvent.keyDown(div, makeKeyEvent(REMOTE_OK_KEY));
|
|
280
|
+
|
|
245
281
|
var expected = 1;
|
|
246
|
-
|
|
247
|
-
expect(actual).toEqual(expected);
|
|
282
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
248
283
|
});
|
|
249
284
|
test('should emulate {onMouseUp} when {REMOTE_OK_KEY} key is pressed and released', function () {
|
|
250
285
|
var spy = jest.fn();
|
|
251
|
-
|
|
286
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
287
|
+
"data-testid": id,
|
|
252
288
|
emulateMouse: true,
|
|
253
289
|
onMouseUp: spy,
|
|
254
290
|
selectionKeys: [13]
|
|
255
291
|
}));
|
|
256
|
-
|
|
257
|
-
|
|
292
|
+
|
|
293
|
+
var div = _react.screen.getByTestId(id);
|
|
294
|
+
|
|
295
|
+
_react.fireEvent.keyDown(div, makeKeyEvent(REMOTE_OK_KEY));
|
|
296
|
+
|
|
297
|
+
_react.fireEvent.keyUp(div, makeKeyEvent(REMOTE_OK_KEY));
|
|
298
|
+
|
|
258
299
|
var expected = 1;
|
|
259
|
-
|
|
260
|
-
expect(actual).toEqual(expected);
|
|
300
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
261
301
|
});
|
|
262
302
|
test('should not emulate {onMouseUp} if the default behavior is prevented even though {REMOTE_OK_KEY} key is pressed', function () {
|
|
263
303
|
var spy = jest.fn();
|
|
@@ -266,17 +306,21 @@ describe('useSpottable', function () {
|
|
|
266
306
|
ev.preventDefault();
|
|
267
307
|
}
|
|
268
308
|
|
|
269
|
-
|
|
309
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
310
|
+
"data-testid": id,
|
|
270
311
|
emulateMouse: true,
|
|
271
312
|
onKeyUp: onKeyUp,
|
|
272
313
|
onMouseUp: spy,
|
|
273
314
|
selectionKeys: [13]
|
|
274
315
|
}));
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
316
|
+
|
|
317
|
+
var div = _react.screen.getByTestId(id);
|
|
318
|
+
|
|
319
|
+
_react.fireEvent.keyDown(div, makeKeyEvent(REMOTE_OK_KEY));
|
|
320
|
+
|
|
321
|
+
_react.fireEvent.keyUp(div, makeKeyEvent(REMOTE_OK_KEY));
|
|
322
|
+
|
|
323
|
+
expect(spy).not.toHaveBeenCalled();
|
|
280
324
|
});
|
|
281
325
|
});
|
|
282
326
|
describe('shouldComponentUpdate', function () {
|
|
@@ -284,42 +328,55 @@ describe('useSpottable', function () {
|
|
|
284
328
|
var spy = jest.fn(function (props) {
|
|
285
329
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
286
330
|
});
|
|
287
|
-
|
|
288
|
-
|
|
331
|
+
|
|
332
|
+
var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
333
|
+
component: spy,
|
|
334
|
+
"data-testid": id
|
|
335
|
+
})),
|
|
336
|
+
rerender = _render.rerender;
|
|
337
|
+
|
|
338
|
+
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
339
|
+
component: spy,
|
|
340
|
+
"data-id": "123",
|
|
341
|
+
"data-testid": id
|
|
289
342
|
}));
|
|
290
|
-
subject.setProps({
|
|
291
|
-
'data-id': '123'
|
|
292
|
-
});
|
|
293
343
|
var expected = 2;
|
|
294
|
-
|
|
295
|
-
expect(actual).toEqual(expected);
|
|
344
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
296
345
|
});
|
|
297
346
|
test('should re-render when {selectionKeys} changes', function () {
|
|
298
347
|
var spy = jest.fn(function (props) {
|
|
299
348
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
300
349
|
});
|
|
301
|
-
|
|
350
|
+
|
|
351
|
+
var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
302
352
|
component: spy,
|
|
353
|
+
"data-testid": id,
|
|
303
354
|
selectionKeys: [1, 2, 3]
|
|
304
|
-
}))
|
|
305
|
-
|
|
355
|
+
})),
|
|
356
|
+
rerender = _render2.rerender;
|
|
357
|
+
|
|
358
|
+
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
359
|
+
component: spy,
|
|
360
|
+
"data-testid": id,
|
|
306
361
|
selectionKeys: [2, 1, 3]
|
|
307
|
-
});
|
|
362
|
+
}));
|
|
308
363
|
var expected = 2;
|
|
309
|
-
|
|
310
|
-
expect(actual).toEqual(expected);
|
|
364
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
311
365
|
});
|
|
312
366
|
test('should not re-render when focused', function () {
|
|
313
367
|
var spy = jest.fn(function (props) {
|
|
314
368
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
315
369
|
});
|
|
316
|
-
|
|
317
|
-
component: spy
|
|
370
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
371
|
+
component: spy,
|
|
372
|
+
"data-testid": id
|
|
318
373
|
}));
|
|
319
|
-
|
|
374
|
+
|
|
375
|
+
var div = _react.screen.getByTestId(id);
|
|
376
|
+
|
|
377
|
+
div.focus();
|
|
320
378
|
var expected = 1;
|
|
321
|
-
|
|
322
|
-
expect(actual).toEqual(expected);
|
|
379
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
323
380
|
});
|
|
324
381
|
});
|
|
325
382
|
});
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports["default"] = void 0;
|
|
6
7
|
Object.defineProperty(exports, "spottableClass", {
|
|
7
8
|
enumerable: true,
|
|
8
9
|
get: function get() {
|
|
9
10
|
return _SpottableCore.spottableClass;
|
|
10
11
|
}
|
|
11
12
|
});
|
|
12
|
-
exports.useSpottable =
|
|
13
|
+
exports.useSpottable = void 0;
|
|
13
14
|
|
|
14
15
|
var _useClass = _interopRequireDefault(require("@enact/core/useClass"));
|
|
15
16
|
|
|
@@ -19,11 +20,13 @@ var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
|
19
20
|
|
|
20
21
|
var _SpottableCore = require("./SpottableCore");
|
|
21
22
|
|
|
23
|
+
var _excluded = ["spotRef", "emulateMouse", "selectionKeys", "spotlightDisabled"];
|
|
24
|
+
|
|
22
25
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
23
26
|
|
|
24
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
27
|
+
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; }
|
|
25
28
|
|
|
26
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
29
|
+
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; }
|
|
27
30
|
|
|
28
31
|
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; }
|
|
29
32
|
|
|
@@ -88,7 +91,7 @@ var useSpottable = function useSpottable() {
|
|
|
88
91
|
_ref$selectionKeys = _ref.selectionKeys,
|
|
89
92
|
selectionKeys = _ref$selectionKeys === void 0 ? [ENTER_KEY, REMOTE_OK_KEY] : _ref$selectionKeys,
|
|
90
93
|
spotlightDisabled = _ref.spotlightDisabled,
|
|
91
|
-
props = _objectWithoutProperties(_ref,
|
|
94
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
92
95
|
|
|
93
96
|
var hook = (0, _useClass["default"])(_SpottableCore.SpottableCore, {
|
|
94
97
|
emulateMouse: emulateMouse
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/spotlight",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.5.0-alpha.1",
|
|
4
4
|
"description": "A focus management library",
|
|
5
5
|
"main": "src/spotlight.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@enact/core": "^4.1
|
|
22
|
-
"classnames": "^2.
|
|
23
|
-
"prop-types": "^15.
|
|
24
|
-
"ramda": "^0.
|
|
25
|
-
"react": "^
|
|
26
|
-
"react-dom": "^
|
|
27
|
-
"warning": "^
|
|
21
|
+
"@enact/core": "^4.5.0-alpha.1",
|
|
22
|
+
"classnames": "^2.3.1",
|
|
23
|
+
"prop-types": "^15.8.1",
|
|
24
|
+
"ramda": "^0.28.0",
|
|
25
|
+
"react": "^18.0.0",
|
|
26
|
+
"react-dom": "^18.0.0",
|
|
27
|
+
"warning": "^4.0.3"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/container.js
CHANGED
|
@@ -3,27 +3,32 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getContainerConfig = exports.getAllContainerIds = exports.containerAttribute = exports.configureDefaults = exports.configureContainer = exports.addContainer = void 0;
|
|
6
7
|
exports.getContainerDefaultElement = getContainerDefaultElement;
|
|
8
|
+
exports.getContainerFocusTarget = getContainerFocusTarget;
|
|
9
|
+
exports.getContainerId = void 0;
|
|
7
10
|
exports.getContainerLastFocusedElement = getContainerLastFocusedElement;
|
|
8
11
|
exports.getContainerNavigableElements = getContainerNavigableElements;
|
|
9
|
-
exports.
|
|
10
|
-
exports.setContainerLastFocusedElement = setContainerLastFocusedElement;
|
|
11
|
-
exports.getContainerFocusTarget = getContainerFocusTarget;
|
|
12
|
+
exports.getContainerNode = void 0;
|
|
12
13
|
exports.getContainerPreviousTarget = getContainerPreviousTarget;
|
|
14
|
+
exports.getContainersForNode = getContainersForNode;
|
|
15
|
+
exports.getDeepSpottableDescendants = void 0;
|
|
13
16
|
exports.getDefaultContainer = getDefaultContainer;
|
|
14
17
|
exports.getLastContainer = getLastContainer;
|
|
15
18
|
exports.getNavigableContainersForNode = getNavigableContainersForNode;
|
|
19
|
+
exports.isNavigable = exports.isContainer5WayHoldable = exports.isContainer = exports.getSpottableDescendants = void 0;
|
|
16
20
|
exports.isWithinOverflowContainer = isWithinOverflowContainer;
|
|
17
21
|
exports.mayActivateContainer = mayActivateContainer;
|
|
22
|
+
exports.notifyEnterContainer = notifyEnterContainer;
|
|
18
23
|
exports.notifyLeaveContainer = notifyLeaveContainer;
|
|
19
24
|
exports.notifyLeaveContainerFail = notifyLeaveContainerFail;
|
|
20
|
-
exports.
|
|
25
|
+
exports.rootContainerId = exports.removeContainer = exports.removeAllContainers = void 0;
|
|
26
|
+
exports.setContainerLastFocusedElement = setContainerLastFocusedElement;
|
|
21
27
|
exports.setContainerPreviousTarget = setContainerPreviousTarget;
|
|
22
28
|
exports.setDefaultContainer = setDefaultContainer;
|
|
23
29
|
exports.setLastContainer = setLastContainer;
|
|
24
30
|
exports.setLastContainerFromTarget = setLastContainerFromTarget;
|
|
25
31
|
exports.unmountContainer = unmountContainer;
|
|
26
|
-
exports.rootContainerId = exports.removeContainer = exports.removeAllContainers = exports.isNavigable = exports.isContainer = exports.getSpottableDescendants = exports.getDeepSpottableDescendants = exports.getContainerId = exports.configureContainer = exports.configureDefaults = exports.containerAttribute = exports.addContainer = exports.isContainer5WayHoldable = exports.getContainerConfig = exports.getContainerNode = exports.getAllContainerIds = void 0;
|
|
27
32
|
|
|
28
33
|
var _and = _interopRequireDefault(require("ramda/src/and"));
|
|
29
34
|
|
|
@@ -39,9 +44,9 @@ var _utils = require("./utils");
|
|
|
39
44
|
|
|
40
45
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
41
46
|
|
|
42
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
47
|
+
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; }
|
|
43
48
|
|
|
44
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
49
|
+
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; }
|
|
45
50
|
|
|
46
51
|
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; }
|
|
47
52
|
|
|
@@ -725,9 +730,8 @@ var getAllContainerIds = function getAllContainerIds() {
|
|
|
725
730
|
/**
|
|
726
731
|
* Returns the default focus element for a container
|
|
727
732
|
*
|
|
728
|
-
* @param {String}
|
|
729
|
-
* @param {('last-focused'|'default-element')} [preferredEnterTo] Prefer the given enterTo
|
|
730
|
-
* configuration
|
|
733
|
+
* @param {String} containerId Container ID
|
|
734
|
+
* @param {('last-focused'|'default-element'|'topmost')} [preferredEnterTo] Prefer the given enterTo configuration
|
|
731
735
|
*
|
|
732
736
|
* @returns {Node|null} Default focus element
|
|
733
737
|
* @memberof spotlight/container
|
|
@@ -831,9 +835,8 @@ function setContainerLastFocusedElement(node, containerIds) {
|
|
|
831
835
|
* return that element as the only element in an array. If that fails or if navigation is not
|
|
832
836
|
* restricted, it will return an array of all possible navigable nodes.
|
|
833
837
|
*
|
|
834
|
-
* @param {String}
|
|
835
|
-
* @param {('last-focused'|'default-element')} [preferredEnterTo] Prefer the given enterTo
|
|
836
|
-
* configuration
|
|
838
|
+
* @param {String} containerId Container ID
|
|
839
|
+
* @param {('last-focused'|'default-element'|'topmost')} [preferredEnterTo] Prefer the given enterTo configuration
|
|
837
840
|
*
|
|
838
841
|
* @returns {Node[]} Navigable elements within container
|
|
839
842
|
* @memberof spotlight/container
|
|
@@ -877,6 +880,12 @@ function getContainerNavigableElements(containerId, preferredEnterTo) {
|
|
|
877
880
|
|
|
878
881
|
return (0, _utils.contains)(containerRect, (0, _utils.getRect)(element));
|
|
879
882
|
});
|
|
883
|
+
|
|
884
|
+
if (next && preferredEnterTo === 'topmost') {
|
|
885
|
+
next.sort(function (a, b) {
|
|
886
|
+
return (0, _utils.getRect)(a).top - (0, _utils.getRect)(b).top;
|
|
887
|
+
});
|
|
888
|
+
}
|
|
880
889
|
} // otherwise, return all spottables within the container
|
|
881
890
|
|
|
882
891
|
|
|
@@ -891,9 +900,8 @@ function getContainerNavigableElements(containerId, preferredEnterTo) {
|
|
|
891
900
|
* Determines the preferred focus target, traversing any sub-containers as necessary, for the given
|
|
892
901
|
* container.
|
|
893
902
|
*
|
|
894
|
-
* @param {String}
|
|
895
|
-
* @param {('last-focused'|'default-element')} [preferredEnterTo] Prefer the given enterTo
|
|
896
|
-
* configuration
|
|
903
|
+
* @param {String} containerId Container ID
|
|
904
|
+
* @param {('last-focused'|'default-element'|'topmost')} [preferredEnterTo] Prefer the given enterTo configuration
|
|
897
905
|
*
|
|
898
906
|
* @returns {Node} Preferred target as either a DOM node or container-id
|
|
899
907
|
* @memberof spotlight/container
|
package/src/navigate.js
CHANGED
package/src/spotlight.js
CHANGED
package/src/target.js
CHANGED
|
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getNavigableTarget = getNavigableTarget;
|
|
7
|
+
exports.getNearestTargetFromPosition = void 0;
|
|
7
8
|
exports.getTargetByContainer = getTargetByContainer;
|
|
8
9
|
exports.getTargetByDirectionFromElement = getTargetByDirectionFromElement;
|
|
9
10
|
exports.getTargetByDirectionFromPosition = getTargetByDirectionFromPosition;
|
|
10
11
|
exports.getTargetBySelector = getTargetBySelector;
|
|
11
12
|
exports.isFocusable = isFocusable;
|
|
12
|
-
exports.getNearestTargetFromPosition = void 0;
|
|
13
13
|
|
|
14
14
|
var _clamp = _interopRequireDefault(require("ramda/src/clamp"));
|
|
15
15
|
|
|
@@ -23,9 +23,9 @@ var _utils = require("./utils");
|
|
|
23
23
|
|
|
24
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
25
25
|
|
|
26
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
26
|
+
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; }
|
|
27
27
|
|
|
28
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
28
|
+
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; }
|
|
29
29
|
|
|
30
30
|
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; }
|
|
31
31
|
|
package/src/tests/utils.js
CHANGED
|
@@ -11,9 +11,9 @@ var _container = require("../container");
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
13
|
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
14
|
+
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; }
|
|
15
15
|
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
16
|
+
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; }
|
|
17
17
|
|
|
18
18
|
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; }
|
|
19
19
|
|
package/src/utils.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.contains = void 0;
|
|
6
7
|
exports.getContainerRect = getContainerRect;
|
|
7
8
|
exports.getPointRect = getPointRect;
|
|
8
9
|
exports.getRect = getRect;
|
|
9
10
|
exports.getRects = getRects;
|
|
11
|
+
exports.matchSelector = exports.intersects = void 0;
|
|
10
12
|
exports.parseSelector = parseSelector;
|
|
11
|
-
exports.matchSelector = exports.intersects = exports.contains = void 0;
|
|
12
13
|
|
|
13
14
|
var _curry = _interopRequireDefault(require("ramda/src/curry"));
|
|
14
15
|
|
|
@@ -67,17 +68,18 @@ var testIntersection = function testIntersection(type, containerRect, elementRec
|
|
|
67
68
|
r = elementRect.right,
|
|
68
69
|
t = elementRect.top,
|
|
69
70
|
b = elementRect.bottom;
|
|
70
|
-
var right = r >= L && r <= R;
|
|
71
|
-
var left = l >= L && l <= R;
|
|
72
|
-
var top = t >= T && t <= B;
|
|
73
|
-
var bottom = b >= T && b <= B;
|
|
74
71
|
|
|
75
72
|
if (type === 'intersects') {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return (top || bottom || aroundV) && (left || right || aroundH);
|
|
73
|
+
// Test intersection by eliminating the area of the element that is outside of the container
|
|
74
|
+
return !(b < T || t > B || r < L || l > R);
|
|
79
75
|
} else if (type === 'contains') {
|
|
80
|
-
|
|
76
|
+
var epsilon = 1; // Test whether all bounds are within the container
|
|
77
|
+
|
|
78
|
+
return r > L - epsilon && r < R + epsilon && // right
|
|
79
|
+
l > L - epsilon && l < R + epsilon && // left
|
|
80
|
+
t > T - epsilon && t < B + epsilon && // top
|
|
81
|
+
b > T - epsilon && b < B + epsilon // bottom
|
|
82
|
+
;
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
return true;
|