@enact/spotlight 4.5.2 → 4.5.4

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 (32) hide show
  1. package/Accelerator/Accelerator.js +11 -31
  2. package/Accelerator/tests/Accelerrator-specs.js +62 -0
  3. package/CHANGELOG.md +10 -0
  4. package/Pause/Pause.js +8 -18
  5. package/Pause/tests/Pause-specs.js +6 -3
  6. package/SpotlightContainerDecorator/SpotlightContainer.js +19 -45
  7. package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +14 -58
  8. package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +5 -10
  9. package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +17 -47
  10. package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +16 -53
  11. package/SpotlightContainerDecorator/useSpotlightContainer.js +4 -15
  12. package/SpotlightRootDecorator/SpotlightRootDecorator.js +4 -58
  13. package/SpotlightRootDecorator/tests/SpotlightRootDecorator-specs.js +38 -0
  14. package/Spottable/Spottable.js +25 -84
  15. package/Spottable/SpottableCore.js +32 -71
  16. package/Spottable/tests/Spottable-specs.js +8 -31
  17. package/Spottable/tests/useSpot-specs.js +27 -105
  18. package/Spottable/useSpottable.js +7 -21
  19. package/package.json +8 -2
  20. package/src/container.js +94 -219
  21. package/src/navigate.js +5 -74
  22. package/src/pointer.js +16 -31
  23. package/src/spotlight.js +42 -171
  24. package/src/target.js +61 -139
  25. package/src/tests/container-specs.js +5 -11
  26. package/src/tests/navigate-specs.js +2 -10
  27. package/src/tests/pointer-specs.js +1 -3
  28. package/src/tests/spotlight-specs.js +42 -24
  29. package/src/tests/target-specs.js +23 -47
  30. package/src/tests/utils-specs.js +54 -0
  31. package/src/tests/utils.js +2 -27
  32. package/src/utils.js +18 -37
package/src/target.js CHANGED
@@ -10,120 +10,85 @@ exports.getTargetByDirectionFromElement = getTargetByDirectionFromElement;
10
10
  exports.getTargetByDirectionFromPosition = getTargetByDirectionFromPosition;
11
11
  exports.getTargetBySelector = getTargetBySelector;
12
12
  exports.isFocusable = isFocusable;
13
-
14
13
  var _clamp = _interopRequireDefault(require("ramda/src/clamp"));
15
-
16
14
  var _last = _interopRequireDefault(require("ramda/src/last"));
17
-
18
15
  var _container = require("./container");
19
-
20
16
  var _navigate = _interopRequireDefault(require("./navigate"));
21
-
22
17
  var _utils = require("./utils");
23
-
24
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
25
-
26
19
  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
-
28
20
  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
-
30
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; }
31
-
32
22
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
33
-
34
23
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
35
-
36
24
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
37
-
38
25
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
39
-
40
26
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
41
-
42
27
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
43
-
44
28
  function isFocusable(elem) {
45
29
  var containers = (0, _container.getContainersForNode)(elem);
46
30
  var verifySelector = true;
47
-
48
31
  for (var i = containers.length - 1; i >= 0; i--) {
49
32
  var containerId = containers[i];
50
-
51
33
  if (!(0, _container.isNavigable)(elem, containerId, verifySelector)) {
52
34
  return false;
53
- } // only verify selector for the first (immediate ancestor) container
54
-
35
+ }
55
36
 
37
+ // only verify selector for the first (immediate ancestor) container
56
38
  verifySelector = false;
57
39
  }
58
-
59
40
  return true;
60
41
  }
61
-
62
42
  function getContainersToSearch(containerId) {
63
43
  var range = [];
64
-
65
44
  var addRange = function addRange(id) {
66
45
  var config = (0, _container.getContainerConfig)(id);
67
-
68
46
  if (id && range.indexOf(id) < 0 && config && !config.selectorDisabled) {
69
47
  range.push(id);
70
48
  }
71
49
  };
72
-
73
50
  if (containerId) {
74
51
  addRange(containerId);
75
52
  } else {
76
53
  addRange((0, _container.getDefaultContainer)());
77
54
  addRange((0, _container.getLastContainer)());
78
-
79
55
  _toConsumableArray((0, _container.getAllContainerIds)()).map(addRange);
80
56
  }
81
-
82
57
  return range;
83
58
  }
84
-
85
59
  function getTargetByContainer(containerId, enterTo) {
86
60
  return getContainersToSearch(containerId).reduce(function (next, id) {
87
61
  return next || (0, _container.getContainerFocusTarget)(id, enterTo);
88
62
  }, null);
89
63
  }
90
-
91
64
  function getTargetBySelector(selector) {
92
65
  if (!selector) return null;
93
-
94
66
  if (selector.charAt(0) === '@') {
95
67
  var containerId = selector.length === 1 ? null : selector.substr(1);
96
68
  return getTargetByContainer(containerId);
97
69
  }
98
-
99
70
  var next = (0, _utils.parseSelector)(selector)[0];
100
-
101
71
  if (next) {
102
72
  if ((0, _container.isContainer)(next)) {
103
73
  return getTargetByContainer((0, _container.getContainerId)(next));
104
74
  }
105
-
106
75
  var nextContainerIds = (0, _container.getContainersForNode)(next);
107
-
108
76
  if ((0, _container.isNavigable)(next, (0, _last["default"])(nextContainerIds), true)) {
109
77
  return next;
110
78
  }
111
79
  }
112
-
113
80
  return null;
114
81
  }
115
-
116
82
  function isRestrictedContainer(containerId) {
117
83
  var config = (0, _container.getContainerConfig)(containerId);
118
84
  return config && (config.enterTo === 'last-focused' || config.enterTo === 'default-element');
119
85
  }
120
-
121
86
  function filterRects(elementRects, boundingRect) {
122
87
  if (!boundingRect) {
123
88
  return elementRects;
124
- } // remove elements that are outside of boundingRect, if specified
125
-
89
+ }
126
90
 
91
+ // remove elements that are outside of boundingRect, if specified
127
92
  return elementRects.filter(function (rect) {
128
93
  if ((0, _container.isContainer)(rect.element)) {
129
94
  // For containers, test intersection since they may be larger than the bounding rect
@@ -136,96 +101,88 @@ function filterRects(elementRects, boundingRect) {
136
101
  var topUpdate = rect.top < boundingRect.top;
137
102
  var bottomUpdate = rect.bottom > boundingRect.bottom;
138
103
  var leftUpdate = rect.left < boundingRect.left;
139
- var rightUpdate = rect.right > boundingRect.right; // if the element's rect is larger than the bounding rect, clamp it to the bounding rect and
140
- // recalculate the center based on the new bounds.
104
+ var rightUpdate = rect.right > boundingRect.right;
141
105
 
106
+ // if the element's rect is larger than the bounding rect, clamp it to the bounding rect and
107
+ // recalculate the center based on the new bounds.
142
108
  if (topUpdate || bottomUpdate || leftUpdate || rightUpdate) {
143
109
  var updated = _objectSpread(_objectSpread({}, rect), {}, {
144
110
  center: _objectSpread({}, rect.center)
145
111
  });
146
-
147
112
  if (topUpdate) updated.top = boundingRect.top;
148
113
  if (bottomUpdate) updated.bottom = boundingRect.bottom;
149
114
  if (leftUpdate) updated.left = boundingRect.left;
150
115
  if (rightUpdate) updated.right = boundingRect.right;
151
-
152
116
  if (leftUpdate || rightUpdate) {
153
117
  var centerX = updated.left + (updated.right - updated.left) / 2;
154
118
  updated.center.x = updated.center.left = updated.center.right = centerX;
155
119
  }
156
-
157
120
  if (topUpdate || bottomUpdate) {
158
121
  var centerY = updated.top + (updated.bottom - updated.top) / 2;
159
122
  updated.center.y = updated.center.top = updated.center.bottom = centerY;
160
123
  }
161
-
162
124
  return updated;
163
125
  }
164
-
165
126
  return rect;
166
127
  });
167
128
  }
168
-
169
129
  function getContainerContainingRect(elementRects, elementRect) {
170
130
  // find candidates that are containers and *visually* contain element
171
131
  var overlapping = elementRects.filter(function (rect) {
172
132
  return (0, _container.isContainer)(rect.element) && (0, _utils.contains)(rect, elementRect);
173
- }); // if the next element is a container AND the current element is *visually* contained within
133
+ });
134
+
135
+ // if the next element is a container AND the current element is *visually* contained within
174
136
  // one of the candidate element, we need to ignore container `enterTo` preferences and
175
137
  // retrieve its spottable descendants and try to navigate to them.
176
-
177
138
  if (overlapping.length) {
178
139
  return overlapping[0].element.dataset.spotlightId;
179
140
  }
180
-
181
141
  return false;
182
142
  }
183
-
184
143
  function getOverflowContainerRect(containerId) {
185
144
  // if the target container has overflowing content, update the boundingRect to match its
186
145
  // bounds to prevent finding elements within the container's hierarchy but not visible.
187
146
  // This filter only applies when waterfalling to prevent filtering out elements that share
188
147
  // a container tree with `element`
189
148
  var nextConfig = (0, _container.getContainerConfig)(containerId);
190
-
191
149
  if (nextConfig && nextConfig.overflow) {
192
150
  return (0, _utils.getContainerRect)(containerId);
193
151
  }
194
152
  }
195
-
196
153
  function getTargetInContainerByDirectionFromPosition(direction, containerId, positionRect, elementContainerIds, boundingRect) {
197
154
  var elements = (0, _container.getDeepSpottableDescendants)(containerId);
198
155
  var elementRects = filterRects((0, _utils.getRects)(elements), boundingRect);
199
156
  var next = null;
200
-
201
157
  var _loop = function _loop() {
202
- var overlappingContainerId = getContainerContainingRect(elementRects, positionRect); // if the pointer is within a container that is a candidate element, we need to ignore container
203
- // `enterTo` preferences and retrieve its spottable descendants and try to navigate to them.
158
+ var overlappingContainerId = getContainerContainingRect(elementRects, positionRect);
204
159
 
160
+ // if the pointer is within a container that is a candidate element, we need to ignore container
161
+ // `enterTo` preferences and retrieve its spottable descendants and try to navigate to them.
205
162
  if (overlappingContainerId) {
206
163
  next = getTargetInContainerByDirectionFromPosition(direction, overlappingContainerId, positionRect, elementContainerIds, boundingRect);
207
-
208
164
  if (!next) {
209
165
  // filter out the container and try again
210
166
  elementRects = elementRects.filter(function (rect) {
211
167
  return rect.element.dataset.spotlightId !== overlappingContainerId;
212
168
  });
213
169
  return "continue";
214
- } // found a target so break out and return
215
-
170
+ }
216
171
 
172
+ // found a target so break out and return
217
173
  return "break";
218
- } // try to navigate from position to one of the candidates in containerId
219
-
174
+ }
220
175
 
221
- next = (0, _navigate["default"])(positionRect, direction, elementRects, (0, _container.getContainerConfig)(containerId)); // if we match a container, recurse into it
176
+ // try to navigate from position to one of the candidates in containerId
177
+ next = (0, _navigate["default"])(positionRect, direction, elementRects, (0, _container.getContainerConfig)(containerId));
222
178
 
179
+ // if we match a container, recurse into it
223
180
  if (next && (0, _container.isContainer)(next)) {
224
- var nextContainerId = next.dataset.spotlightId; // need to cache this reference so we can filter it out later if necessary
181
+ var nextContainerId = next.dataset.spotlightId;
225
182
 
183
+ // need to cache this reference so we can filter it out later if necessary
226
184
  var lastNavigated = next;
227
185
  next = getTargetInContainerByDirectionFromPosition(direction, nextContainerId, positionRect, elementContainerIds, getOverflowContainerRect(nextContainerId) || boundingRect);
228
-
229
186
  if (!next) {
230
187
  // filter out the container and try again
231
188
  elementRects = elementRects.filter(function (rect) {
@@ -233,150 +190,139 @@ function getTargetInContainerByDirectionFromPosition(direction, containerId, pos
233
190
  });
234
191
  return "continue";
235
192
  }
236
- } // If we've met every condition and haven't explicitly retried the search via `continue`,
237
- // break out and return
238
-
193
+ }
239
194
 
195
+ // If we've met every condition and haven't explicitly retried the search via `continue`,
196
+ // break out and return
240
197
  return "break";
241
198
  };
242
-
243
199
  while (elementRects.length > 0) {
244
200
  var _ret = _loop();
245
-
246
201
  if (_ret === "continue") continue;
247
202
  if (_ret === "break") break;
248
203
  }
249
-
250
204
  return next;
251
205
  }
252
-
253
206
  function getTargetInContainerByDirectionFromElement(direction, containerId, element, elementRect, elementContainerIds, boundingRect) {
254
- var elements = (0, _container.getDeepSpottableDescendants)(containerId); // shortcut for previous target from element if it were saved
207
+ var elements = (0, _container.getDeepSpottableDescendants)(containerId);
255
208
 
209
+ // shortcut for previous target from element if it were saved
256
210
  var previous = (0, _container.getContainerPreviousTarget)(containerId, direction, element);
257
-
258
211
  if (previous && elements.indexOf(previous) !== -1) {
259
212
  return previous;
260
- } // `spotlightOverflow` is a private, and likely temporary, API to allow a component within an
213
+ }
214
+
215
+ // `spotlightOverflow` is a private, and likely temporary, API to allow a component within an
261
216
  // spotlight container with `overflow: true` to be treated as if it were outside of the
262
217
  // container. The result is that the candidates, `elements` are filtered by the bounds of the
263
218
  // overflow container effectively hiding those that have overflowed and are visually hidden.
264
219
  //
265
220
  // Currently only used by moonstone/Scroller.Scrollbar as a means to allow 5-way navigation to
266
221
  // escape the Scrollable from paging controls rather than focusing contents that are out of view
267
-
268
-
269
222
  if (element.dataset.spotlightOverflow === 'ignore') {
270
223
  boundingRect = getOverflowContainerRect(containerId) || boundingRect;
271
224
  }
272
-
273
225
  var elementRects = filterRects((0, _utils.getRects)(elements), boundingRect);
274
226
  var next = null;
275
-
276
227
  var _loop2 = function _loop2() {
277
- var overlappingContainerId = getContainerContainingRect(elementRects, elementRect); // if the next element is a container AND the current element is *visually* contained within
228
+ var overlappingContainerId = getContainerContainingRect(elementRects, elementRect);
229
+
230
+ // if the next element is a container AND the current element is *visually* contained within
278
231
  // one of the candidate elements, we need to ignore container `enterTo` preferences and
279
232
  // retrieve its spottable descendants and try to navigate to them.
280
-
281
233
  if (overlappingContainerId) {
282
234
  next = getTargetInContainerByDirectionFromElement(direction, overlappingContainerId, element, elementRect, elementContainerIds, boundingRect);
283
-
284
235
  if (!next) {
285
236
  // filter out the container and try again
286
237
  elementRects = elementRects.filter(function (rect) {
287
238
  return rect.element.dataset.spotlightId !== overlappingContainerId;
288
239
  });
289
240
  return "continue";
290
- } // found a target so break out and return
291
-
241
+ }
292
242
 
243
+ // found a target so break out and return
293
244
  return "break";
294
- } // If one of the downstream containers is configured for partition, we use that
295
- // container's bounds as the partition rect for navigation.
296
-
245
+ }
297
246
 
247
+ // If one of the downstream containers is configured for partition, we use that
248
+ // container's bounds as the partition rect for navigation.
298
249
  var partitionContainer = elementContainerIds.slice(elementContainerIds.indexOf(containerId) + 1).find(function (id) {
299
250
  var cfg = (0, _container.getContainerConfig)(id);
300
251
  return cfg && cfg.partition;
301
252
  });
302
253
  var partitionRect = elementRect;
303
-
304
254
  if (partitionContainer) {
305
255
  partitionRect = (0, _utils.getContainerRect)(partitionContainer);
306
- } // try to navigate from element to one of the candidates in containerId
307
-
256
+ }
308
257
 
309
- next = (0, _navigate["default"])(elementRect, direction, elementRects, (0, _container.getContainerConfig)(containerId), partitionRect); // if we match a container,
258
+ // try to navigate from element to one of the candidates in containerId
259
+ next = (0, _navigate["default"])(elementRect, direction, elementRects, (0, _container.getContainerConfig)(containerId), partitionRect);
310
260
 
261
+ // if we match a container,
311
262
  if (next && (0, _container.isContainer)(next)) {
312
- var nextContainerId = next.dataset.spotlightId; // need to cache this reference so we can filter it out later if necessary
263
+ var nextContainerId = next.dataset.spotlightId;
313
264
 
314
- var lastNavigated = next; // and it is restricted, return its target
265
+ // need to cache this reference so we can filter it out later if necessary
266
+ var lastNavigated = next;
315
267
 
268
+ // and it is restricted, return its target
316
269
  if (isRestrictedContainer(nextContainerId)) {
317
270
  next = getTargetByContainer(nextContainerId);
318
271
  } else {
319
272
  // otherwise, recurse into it
320
273
  next = getTargetInContainerByDirectionFromElement(direction, nextContainerId, element, elementRect, elementContainerIds, getOverflowContainerRect(nextContainerId) || boundingRect);
321
274
  }
322
-
323
275
  if (!next) {
324
276
  elementRects = elementRects.filter(function (rect) {
325
277
  return rect.element !== lastNavigated;
326
278
  });
327
279
  return "continue";
328
280
  }
329
- } // If we've met every condition and haven't explicitly retried the search via `continue`,
330
- // break out and return
331
-
281
+ }
332
282
 
283
+ // If we've met every condition and haven't explicitly retried the search via `continue`,
284
+ // break out and return
333
285
  return "break";
334
286
  };
335
-
336
287
  while (elementRects.length > 0) {
337
288
  var _ret2 = _loop2();
338
-
339
289
  if (_ret2 === "continue") continue;
340
290
  if (_ret2 === "break") break;
341
291
  }
342
-
343
292
  return next;
344
293
  }
345
-
346
294
  function getTargetByDirectionFromElement(direction, element) {
347
295
  var extSelector = element.getAttribute('data-spot-' + direction);
348
-
349
296
  if (typeof extSelector === 'string') {
350
297
  return getTargetBySelector(extSelector);
351
298
  }
352
-
353
299
  var elementRect = (0, _utils.getRect)(element);
354
300
  var next = (0, _container.getNavigableContainersForNode)(element).reduceRight(function (result, containerId, index, elementContainerIds) {
355
301
  result = result || getTargetInContainerByDirectionFromElement(direction, containerId, element, elementRect, elementContainerIds);
356
-
357
302
  if (!result) {
358
- result = getLeaveForTarget(containerId, direction); // To support a `leaveFor` configuration with navigation disallowed in the current
303
+ result = getLeaveForTarget(containerId, direction);
304
+
305
+ // To support a `leaveFor` configuration with navigation disallowed in the current
359
306
  // `direction`, we return the current element to prevent further searches for a
360
307
  // target in this reduction.
361
-
362
308
  if (result === false) {
363
309
  result = element;
364
310
  }
365
311
  }
366
-
367
312
  return result;
368
- }, null); // if the reduce above returns the original element, it means it hit a `leaveFor` config that
369
- // prevents navigation so we enforce that here by returning null.
313
+ }, null);
370
314
 
315
+ // if the reduce above returns the original element, it means it hit a `leaveFor` config that
316
+ // prevents navigation so we enforce that here by returning null.
371
317
  return next !== element ? next : null;
372
318
  }
373
-
374
319
  function getTargetByDirectionFromPosition(direction, position, containerId) {
375
320
  var pointerRect = (0, _utils.getPointRect)(position);
376
321
  return (0, _container.getNavigableContainersForNode)((0, _container.getContainerNode)(containerId)).reduceRight(function (result, id, index, elementContainerIds) {
377
322
  return result || getTargetInContainerByDirectionFromPosition(direction, id, pointerRect, elementContainerIds);
378
323
  }, null);
379
324
  }
325
+
380
326
  /**
381
327
  * Returns the target identified by the selector configured for the container identified by
382
328
  * `containerId` for the given `direction`. If the selector is an empty string, the method returns
@@ -388,36 +334,26 @@ function getTargetByDirectionFromPosition(direction, position, containerId) {
388
334
  * @returns {Node|Boolean} Target, if found, or `false` if navigation is disallowed
389
335
  * @private
390
336
  */
391
-
392
-
393
337
  function getLeaveForTarget(containerId, direction) {
394
338
  var config = (0, _container.getContainerConfig)(containerId);
395
-
396
339
  if (config) {
397
340
  var target = config.restrict !== 'self-only' && config.leaveFor && config.leaveFor[direction];
398
-
399
341
  if (typeof target === 'string') {
400
342
  if (target === '') {
401
343
  return false;
402
344
  }
403
-
404
345
  return getTargetBySelector(target);
405
346
  }
406
-
407
347
  var nextContainerIds = (0, _container.getContainersForNode)(target);
408
-
409
348
  if ((0, _container.isNavigable)(target, (0, _last["default"])(nextContainerIds))) {
410
349
  return target;
411
350
  }
412
351
  }
413
-
414
352
  return null;
415
353
  }
416
-
417
354
  function getNavigableTarget(target) {
418
355
  if (target === document) return null;
419
356
  var parent;
420
-
421
357
  while (target && ((0, _container.isContainer)(target) || !isFocusable(target))) {
422
358
  parent = target.parentNode;
423
359
  target = parent === document ? null : parent; // calling isNavigable on document is problematic
@@ -425,15 +361,13 @@ function getNavigableTarget(target) {
425
361
 
426
362
  return target;
427
363
  }
428
-
429
364
  var getOffsetDistanceToTargetFromPosition = function getOffsetDistanceToTargetFromPosition(distance, direction, _ref, _ref2) {
430
365
  var x = _ref.x,
431
- y = _ref.y;
366
+ y = _ref.y;
432
367
  var left = _ref2.left,
433
- right = _ref2.right,
434
- top = _ref2.top,
435
- bottom = _ref2.bottom;
436
-
368
+ right = _ref2.right,
369
+ top = _ref2.top,
370
+ bottom = _ref2.bottom;
437
371
  if (direction === 'left' || direction === 'right') {
438
372
  if (y > bottom) {
439
373
  distance += y - bottom;
@@ -445,15 +379,12 @@ var getOffsetDistanceToTargetFromPosition = function getOffsetDistanceToTargetFr
445
379
  } else if (x < left) {
446
380
  distance += left - x;
447
381
  }
448
-
449
382
  return distance;
450
383
  };
451
-
452
384
  var getDistanceToTargetFromPosition = function getDistanceToTargetFromPosition(direction, position, elementRect) {
453
385
  var x = position.x,
454
- y = position.y;
386
+ y = position.y;
455
387
  var distance;
456
-
457
388
  if (direction === 'left') {
458
389
  distance = x - elementRect.right;
459
390
  } else if (direction === 'right') {
@@ -463,35 +394,28 @@ var getDistanceToTargetFromPosition = function getDistanceToTargetFromPosition(d
463
394
  } else if (direction === 'down') {
464
395
  distance = elementRect.top - y;
465
396
  }
466
-
467
397
  return getOffsetDistanceToTargetFromPosition((0, _clamp["default"])(0, Math.abs(distance), distance), direction, position, elementRect);
468
398
  };
469
-
470
399
  var getNearestTargetsInContainerFromPosition = function getNearestTargetsInContainerFromPosition(position, containerId) {
471
400
  return ['up', 'left', 'right', 'down'].reduce(function (result, direction) {
472
401
  var target = getTargetByDirectionFromPosition(direction, position, containerId);
473
-
474
402
  if (target) {
475
403
  result.push({
476
404
  direction: direction,
477
405
  target: target
478
406
  });
479
407
  }
480
-
481
408
  return result;
482
409
  }, []);
483
410
  };
484
-
485
411
  var getNearestTargetInContainerFromPosition = function getNearestTargetInContainerFromPosition(position, containerId) {
486
412
  var targets = getNearestTargetsInContainerFromPosition(position, containerId);
487
-
488
413
  if (!targets.length) {
489
414
  return;
490
415
  }
491
-
492
416
  targets.forEach(function (item) {
493
417
  var direction = item.direction,
494
- target = item.target;
418
+ target = item.target;
495
419
  item.distance = getDistanceToTargetFromPosition(direction, position, (0, _utils.getRect)(target));
496
420
  });
497
421
  targets.sort(function (a, b) {
@@ -499,9 +423,7 @@ var getNearestTargetInContainerFromPosition = function getNearestTargetInContain
499
423
  });
500
424
  return targets[0].target;
501
425
  };
502
-
503
426
  var getNearestTargetFromPosition = function getNearestTargetFromPosition(position, containerId) {
504
427
  return getNavigableTarget(document.elementFromPoint(position.x, position.y)) || getNearestTargetInContainerFromPosition(position, containerId);
505
428
  };
506
-
507
429
  exports.getNearestTargetFromPosition = getNearestTargetFromPosition;
@@ -1,19 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  var _container17 = require("../container");
4
-
5
4
  var _utils = require("./utils");
6
-
7
5
  var _node, _container, _container2, _container3, _container4, _container5, _container6, _container7, _container8, _container9, _container10, _container11, _container12, _container13, _container15, _container16;
8
-
9
6
  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; }
10
-
11
7
  var nonSpottable = function nonSpottable() {
12
8
  return (0, _utils.node)({
13
9
  className: 'other'
14
10
  });
15
11
  };
16
-
17
12
  var scenarios = {
18
13
  onlySpottables: (0, _utils.someSpottables)(5),
19
14
  onlyContainers: (0, _utils.someContainers)(5),
@@ -65,7 +60,6 @@ var scenarios = {
65
60
  id: 's2'
66
61
  })), _container16)))
67
62
  };
68
-
69
63
  var setupContainers = function setupContainers() {
70
64
  (0, _container17.configureDefaults)({
71
65
  selector: '.spottable'
@@ -73,12 +67,10 @@ var setupContainers = function setupContainers() {
73
67
  (0, _container17.configureContainer)(_container17.rootContainerId);
74
68
  (0, _container17.setLastContainer)(_container17.rootContainerId);
75
69
  };
76
-
77
70
  var teardownContainers = function teardownContainers() {
78
71
  // clean up any containers we create for safe tests
79
72
  (0, _container17.removeAllContainers)();
80
73
  };
81
-
82
74
  describe('container', function () {
83
75
  describe('#getSpottableDescendants', function () {
84
76
  beforeEach(setupContainers);
@@ -153,8 +145,9 @@ describe('container', function () {
153
145
  expect(actual).toEqual(expected);
154
146
  }));
155
147
  test('should include owned nodes', (0, _utils.testScenario)(scenarios.owned, function () {
156
- (0, _container17.configureContainer)('container'); // owned nodes follow internal nodes
148
+ (0, _container17.configureContainer)('container');
157
149
 
150
+ // owned nodes follow internal nodes
158
151
  var expected = ['s2', 's1'];
159
152
  var actual = (0, _container17.getSpottableDescendants)('container').map(function (n) {
160
153
  return n.getAttribute('id');
@@ -269,9 +262,10 @@ describe('container', function () {
269
262
  var expected = 'spottableDefault';
270
263
  var actual = (0, _container17.getContainerFocusTarget)('container').id;
271
264
  expect(actual).toBe(expected);
272
- })); // FIXME: This is testing a previously supported feature (setting a node as defaultElement)
273
- // which was never documented and should be removed in a future release.
265
+ }));
274
266
 
267
+ // FIXME: This is testing a previously supported feature (setting a node as defaultElement)
268
+ // which was never documented and should be removed in a future release.
275
269
  test('should return the default spottable element when enterTo is "default-element" and defaultElement contains an array of selectors wiht a node reference', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function (root) {
276
270
  (0, _container17.configureContainer)('container', {
277
271
  enterTo: 'default-element',
@@ -1,21 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _navigate = _interopRequireDefault(require("../navigate"));
4
-
5
4
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6
-
7
5
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
-
9
6
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
-
11
7
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
-
13
8
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
-
15
9
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
-
17
10
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
18
-
19
11
  // loose copy from utils/getRect to fabricate a rect for navigation
20
12
  function getRect(top, left, height, width, elem) {
21
13
  var rect = {
@@ -35,7 +27,6 @@ function getRect(top, left, height, width, elem) {
35
27
  rect.center.top = rect.center.bottom = rect.center.y;
36
28
  return rect;
37
29
  }
38
-
39
30
  describe('navigate', function () {
40
31
  test('should return the element above when direction="up"', function () {
41
32
  var targetRect = getRect(100, 100, 10, 10);
@@ -75,7 +66,8 @@ describe('navigate', function () {
75
66
  });
76
67
  test('should return the element "under" when its center is nearest in that direction', function () {
77
68
  var targetRect = getRect(105, 100, 10, 10);
78
- var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 90, 30, 30, 'under'], // completely contains the targetRect
69
+ var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 90, 30, 30, 'under'],
70
+ // completely contains the targetRect
79
71
  [110, 100, 10, 10, 'below']].map(function (args) {
80
72
  return getRect.apply(void 0, _toConsumableArray(args));
81
73
  });
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
 
3
3
  var _keymap = require("@enact/core/keymap");
4
-
5
4
  var _pointer = require("../pointer");
6
-
7
5
  var reset = function reset() {
8
6
  (0, _pointer.updatePointerPosition)(null, null);
9
7
  (0, _pointer.setPointerMode)(true);
10
8
  };
11
-
12
9
  describe('pointer', function () {
13
10
  afterEach(reset);
14
11
  describe('#getLastPointerPosition', function () {
@@ -22,6 +19,7 @@ describe('pointer', function () {
22
19
  // notifyKeyDown() will start a job which will set pointer mode for `pointerHide` key
23
20
  // events. If adding async tests, be sure to pass a callback to notifyKeyDown() to be
24
21
  // notified when the job completes before continuing.
22
+
25
23
  var keyMap = {
26
24
  pointerHide: 999,
27
25
  pointerShow: 888