@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/spotlight.js CHANGED
@@ -4,31 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getDirection = exports["default"] = exports.Spotlight = void 0;
7
-
8
7
  var _keymap = require("@enact/core/keymap");
9
-
10
8
  var _snapshot = require("@enact/core/snapshot");
11
-
12
9
  var _platform = _interopRequireDefault(require("@enact/core/platform"));
13
-
14
10
  var _last = _interopRequireDefault(require("ramda/src/last"));
15
-
16
11
  var _Accelerator = _interopRequireDefault(require("../Accelerator"));
17
-
18
12
  var _Spottable = require("../Spottable");
19
-
20
13
  var _Pause = require("../Pause");
21
-
22
14
  var _utils = require("./utils");
23
-
24
15
  var _container = require("./container");
25
-
26
16
  var _pointer = require("./pointer");
27
-
28
17
  var _target = require("./target");
29
-
30
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
31
-
32
19
  /*
33
20
  * A javascript-based implementation of Spatial Navigation.
34
21
  *
@@ -48,11 +35,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
48
35
  * @exports default Spotlight
49
36
  * @exports getDirection
50
37
  */
38
+
51
39
  var isDown = (0, _keymap.is)('down');
52
40
  var isEnter = (0, _keymap.is)('enter');
53
41
  var isLeft = (0, _keymap.is)('left');
54
42
  var isRight = (0, _keymap.is)('right');
55
43
  var isUp = (0, _keymap.is)('up');
44
+
56
45
  /**
57
46
  * Translates keyCodes into 5-way direction descriptions (e.g. `'down'`)
58
47
  *
@@ -62,13 +51,12 @@ var isUp = (0, _keymap.is)('up');
62
51
  * @returns {String|false} - One of `'up'`, `'down'`, `'left'`, `'right'` or `false` if not a direction key
63
52
  * @public
64
53
  */
65
-
66
54
  var getDirection = function getDirection(keyCode) {
67
55
  return isDown(keyCode) && 'down' || isLeft(keyCode) && 'left' || isRight(keyCode) && 'right' || isUp(keyCode) && 'up';
68
56
  };
69
-
70
57
  exports.getDirection = getDirection;
71
58
  var SpotlightAccelerator = new _Accelerator["default"]();
59
+
72
60
  /**
73
61
  * Provides 5-way navigation and focus support
74
62
  *
@@ -89,31 +77,31 @@ var SpotlightAccelerator = new _Accelerator["default"]();
89
77
  * @memberof spotlight
90
78
  * @public
91
79
  */
92
-
93
80
  var Spotlight = function () {
94
81
  'use strict';
82
+
95
83
  /*
96
84
  /* private vars
97
85
  */
98
-
99
86
  var _initialized = false;
100
87
  var _duringFocusChange = false;
88
+
101
89
  /*
102
90
  * Whether a 5-way directional key is being held.
103
91
  *
104
92
  * @type {Boolean}
105
93
  * @default false
106
94
  */
107
-
108
95
  var _5WayKeyHold = false;
96
+
109
97
  /*
110
98
  * Whether to set focus during the next window focus event
111
99
  *
112
100
  * @type {Boolean}
113
101
  * @default false
114
102
  */
115
-
116
103
  var _spotOnWindowFocus = false;
104
+
117
105
  /*
118
106
  * `true` when a pointer move event occurs during a keypress. Used to short circuit key down
119
107
  * handling until the next keyup occurs.
@@ -121,8 +109,8 @@ var Spotlight = function () {
121
109
  * @type {Boolean}
122
110
  * @default false
123
111
  */
124
-
125
112
  var _pointerMoveDuringKeyPress = false;
113
+
126
114
  /*
127
115
  * protected methods
128
116
  */
@@ -132,318 +120,263 @@ var Spotlight = function () {
132
120
  evt.stopPropagation();
133
121
  return false;
134
122
  }
135
-
136
123
  function shouldPreventNavigation() {
137
124
  return (0, _Pause.isPaused)() || (0, _container.getAllContainerIds)().length === 0;
138
125
  }
139
-
140
126
  function _getCurrent() {
141
127
  if (!(0, _snapshot.isWindowReady)()) return;
142
128
  var activeElement = document.activeElement;
143
-
144
129
  if (activeElement && activeElement !== document.body) {
145
130
  return activeElement;
146
131
  }
147
- } // An extension point for updating pointer mode based on the current platform.
148
- // Currently only webOS
149
-
132
+ }
150
133
 
134
+ // An extension point for updating pointer mode based on the current platform.
135
+ // Currently only webOS
151
136
  function setPlatformPointerMode() {
152
137
  var palmSystem = window.PalmSystem;
153
-
154
138
  if (palmSystem && palmSystem.cursor) {
155
139
  (0, _pointer.setPointerMode)(palmSystem.cursor.visibility);
156
140
  }
157
141
  }
158
-
159
142
  function focusElement(elem, containerIds, fromPointer) {
143
+ var _window$PalmSystem$cu;
160
144
  if (!elem) {
161
145
  return false;
162
146
  }
163
-
164
- if ((0, _pointer.getPointerMode)() && !fromPointer) {
147
+ if ((0, _pointer.getPointerMode)() && !fromPointer && typeof window !== 'undefined' && (!window.PalmSystem || (_window$PalmSystem$cu = window.PalmSystem.cursor) !== null && _window$PalmSystem$cu !== void 0 && _window$PalmSystem$cu.visibility)) {
165
148
  (0, _container.setContainerLastFocusedElement)(elem, containerIds);
166
149
  return false;
167
150
  }
168
-
169
151
  var currentFocusedElement = _getCurrent();
170
-
171
152
  if (elem === currentFocusedElement) {
172
153
  return true;
173
154
  }
174
-
175
155
  var focusOptions = (0, _container.isWithinOverflowContainer)(elem, containerIds) ? {
176
156
  preventScroll: true
177
157
  } : null;
178
-
179
158
  var silentFocus = function silentFocus() {
180
159
  elem.focus(focusOptions);
181
160
  focusChanged(elem, containerIds);
182
161
  };
183
-
184
162
  if (_duringFocusChange) {
185
163
  silentFocus();
186
164
  return true;
187
165
  }
188
-
189
166
  _duringFocusChange = true;
190
-
191
167
  if ((0, _Pause.isPaused)()) {
192
168
  silentFocus();
193
169
  _duringFocusChange = false;
194
170
  return true;
195
171
  }
196
-
197
172
  elem.focus(focusOptions);
198
173
  _duringFocusChange = false;
199
174
  focusChanged(elem, containerIds);
200
175
  return true;
201
176
  }
202
-
203
177
  function focusChanged(elem, containerIds) {
204
178
  if (!containerIds || !containerIds.length) {
205
179
  containerIds = (0, _container.getContainersForNode)(elem);
206
180
  }
207
-
208
181
  var containerId = (0, _last["default"])(containerIds);
209
-
210
182
  if (containerId) {
211
183
  (0, _container.setContainerLastFocusedElement)(elem, containerIds);
212
184
  (0, _container.setLastContainer)(containerId);
213
185
  }
214
-
215
186
  if (process.env.NODE_ENV !== "production") {
216
187
  assignFocusPreview(elem);
217
188
  }
218
189
  }
219
-
220
190
  function restoreFocus() {
221
191
  var lastContainerId = (0, _container.getLastContainer)();
222
192
  var next;
223
-
224
193
  if (lastContainerId) {
225
- var position = (0, _pointer.getLastPointerPosition)(); // walk up the chain of containers from the last to attempt to find a target
194
+ var position = (0, _pointer.getLastPointerPosition)();
226
195
 
227
- next = (0, _container.getContainersForNode)((0, _container.getContainerNode)(lastContainerId)).reverse(); // only prepend last focused if it exists so that Spotlight.focus() doesn't receive
228
- // a falsy target
196
+ // walk up the chain of containers from the last to attempt to find a target
197
+ next = (0, _container.getContainersForNode)((0, _container.getContainerNode)(lastContainerId)).reverse();
229
198
 
199
+ // only prepend last focused if it exists so that Spotlight.focus() doesn't receive
200
+ // a falsy target
230
201
  var lastFocusedElement = (0, _container.getContainerLastFocusedElement)(lastContainerId);
231
-
232
202
  while ((0, _container.isContainer)(lastFocusedElement)) {
233
203
  var _getContainerConfig = (0, _container.getContainerConfig)(lastFocusedElement);
234
-
235
204
  lastFocusedElement = _getContainerConfig.lastFocusedElement;
236
205
  }
237
-
238
206
  var lastContainerNode = (0, _container.getContainerNode)(lastContainerId);
239
-
240
207
  if (!lastFocusedElement || lastContainerNode.getBoundingClientRect && lastFocusedElement.getBoundingClientRect && !(0, _utils.contains)(lastContainerNode.getBoundingClientRect(), lastFocusedElement.getBoundingClientRect())) {
241
208
  lastFocusedElement = (0, _container.getContainerConfig)(lastContainerId).overflow && (0, _target.getNearestTargetFromPosition)(position, lastContainerId);
242
209
  }
243
-
244
210
  if (lastFocusedElement) {
245
211
  next.unshift(lastFocusedElement);
246
212
  }
247
213
  } else {
248
214
  next = [_container.rootContainerId];
249
- } // attempt to find a target starting with the last focused element in the last
250
- // container, followed by the last container, and finally the root container
251
-
215
+ }
252
216
 
217
+ // attempt to find a target starting with the last focused element in the last
218
+ // container, followed by the last container, and finally the root container
253
219
  return next.reduce(function (focused, target) {
254
220
  return focused || Spotlight.focus(target);
255
221
  }, false);
256
- } // The below should be gated on non-production environment only.
257
-
222
+ }
258
223
 
224
+ // The below should be gated on non-production environment only.
259
225
  function assignFocusPreview(elem) {
260
226
  var directions = ['up', 'right', 'down', 'left'],
261
- nextClassBase = _Spottable.spottableClass + '-next-'; // Remove all previous targets
227
+ nextClassBase = _Spottable.spottableClass + '-next-';
262
228
 
229
+ // Remove all previous targets
263
230
  directions.forEach(function (dir) {
264
231
  var nextClass = nextClassBase + dir,
265
- prevElems = (0, _utils.parseSelector)('.' + nextClass);
266
-
232
+ prevElems = (0, _utils.parseSelector)('.' + nextClass);
267
233
  if (prevElems && prevElems.length !== 0) {
268
234
  prevElems.forEach(function (prevElem) {
269
235
  return prevElem.classList.remove(nextClass);
270
236
  });
271
237
  }
272
- }); // Find all next targets and identify them
238
+ });
273
239
 
240
+ // Find all next targets and identify them
274
241
  directions.forEach(function (dir) {
275
242
  var nextElem = (0, _target.getTargetByDirectionFromElement)(dir, elem);
276
-
277
243
  if (nextElem) {
278
244
  nextElem.classList.add(nextClassBase + dir);
279
245
  }
280
246
  });
281
247
  }
282
-
283
248
  function spotNextFromPoint(direction, position) {
284
249
  var containerId = Spotlight.getActiveContainer();
285
250
  var next = (0, _target.getTargetByDirectionFromPosition)(direction, position, containerId);
286
-
287
251
  if (next) {
288
252
  (0, _container.setContainerPreviousTarget)(containerId, direction, next, (0, _container.getContainerLastFocusedElement)(containerId));
289
253
  return focusElement(next, (0, _container.getContainersForNode)(next));
290
254
  }
291
-
292
255
  return false;
293
256
  }
294
-
295
257
  function spotNext(direction, currentFocusedElement, currentContainerIds) {
296
258
  var next = (0, _target.getTargetByDirectionFromElement)(direction, currentFocusedElement);
297
-
298
259
  if (next) {
299
260
  var currentContainerId = (0, _last["default"])(currentContainerIds);
300
- var nextContainerIds = (0, _container.getContainersForNode)(next); // prevent focus if 5-way is being held and the next element isn't wrapped by
301
- // the current element's immediate container
261
+ var nextContainerIds = (0, _container.getContainersForNode)(next);
302
262
 
263
+ // prevent focus if 5-way is being held and the next element isn't wrapped by
264
+ // the current element's immediate container
303
265
  if (_5WayKeyHold && nextContainerIds.indexOf(currentContainerId) < 0 && !(0, _container.isContainer5WayHoldable)(currentContainerId)) {
304
266
  return false;
305
267
  }
306
-
307
268
  (0, _container.notifyLeaveContainer)(direction, currentFocusedElement, currentContainerIds, next, nextContainerIds);
308
269
  (0, _container.setContainerPreviousTarget)(currentContainerId, direction, next, currentFocusedElement);
309
270
  var focused = focusElement(next, nextContainerIds);
310
271
  (0, _container.notifyEnterContainer)(direction, currentFocusedElement, currentContainerIds, next, nextContainerIds);
311
272
  return focused;
312
273
  }
313
-
314
274
  (0, _container.notifyLeaveContainerFail)(direction, currentFocusedElement, currentContainerIds);
315
275
  return false;
316
276
  }
317
-
318
277
  function onAcceleratedKeyDown(evt) {
319
278
  var direction = getDirection(evt.keyCode);
320
279
  if (!direction) return;
321
-
322
280
  var currentFocusedElement = _getCurrent();
323
-
324
281
  var currentContainerIds = (0, _container.getContainersForNode)(currentFocusedElement);
325
282
  spotNext(direction, currentFocusedElement, currentContainerIds);
326
283
  }
327
-
328
284
  function onBlur() {
329
285
  var current = _getCurrent();
330
-
331
286
  if (current) {
332
287
  current.blur();
333
288
  }
334
-
335
289
  Spotlight.setPointerMode(false);
336
290
  _spotOnWindowFocus = true;
337
291
  _pointerMoveDuringKeyPress = false;
338
292
  }
339
-
340
293
  function handleWebOSMouseEvent(ev) {
341
294
  if (!(0, _Pause.isPaused)() && ev && ev.detail && ev.detail.type === 'Leave') {
342
295
  onBlur();
343
296
  }
344
297
  }
345
-
346
298
  function handleKeyboardStateChangeEvent(_ref) {
347
299
  var visibility = _ref.visibility;
348
-
349
300
  if (!visibility) {
350
301
  setPlatformPointerMode();
351
302
  }
352
303
  }
353
-
354
304
  function onFocus() {
355
305
  // Normally, there isn't focus here unless the window has been blurred above. On webOS, the
356
306
  // platform may focus the window after the app has already focused a component so we prevent
357
307
  // trying to focus something else (potentially) unless the window was previously blurred
358
308
  if (_spotOnWindowFocus) {
359
- setPlatformPointerMode(); // If the window was previously blurred while in pointer mode, the last active containerId may
309
+ setPlatformPointerMode();
310
+
311
+ // If the window was previously blurred while in pointer mode, the last active containerId may
360
312
  // not have yet set focus to its spottable elements. For this reason we can't rely on setting focus
361
313
  // to the last focused element of the last active containerId, so we use rootContainerId instead
362
-
363
314
  var lastFocusedElement = (0, _container.getContainerLastFocusedElement)(_container.rootContainerId);
364
-
365
315
  while ((0, _container.isContainer)(lastFocusedElement)) {
366
316
  var _getContainerConfig2 = (0, _container.getContainerConfig)(lastFocusedElement);
367
-
368
317
  lastFocusedElement = _getContainerConfig2.lastFocusedElement;
369
318
  }
370
-
371
319
  if (!Spotlight.focus(lastFocusedElement)) {
372
320
  // If the last focused element was previously also disabled (or no longer exists), we
373
321
  // need to set focus somewhere
374
322
  Spotlight.focus();
375
323
  }
376
-
377
324
  _spotOnWindowFocus = false;
378
325
  }
379
326
  }
380
-
381
327
  function onKeyUp(evt) {
382
328
  _pointerMoveDuringKeyPress = false;
383
329
  var keyCode = evt.keyCode;
384
-
385
330
  if (getDirection(keyCode) || isEnter(keyCode)) {
386
331
  SpotlightAccelerator.reset();
387
332
  _5WayKeyHold = false;
388
333
  }
389
334
  }
390
-
391
335
  function handlePointerHide() {
392
336
  if (!_getCurrent()) {
393
337
  restoreFocus();
394
338
  }
395
339
  }
396
-
397
340
  function onKeyDown(evt) {
398
341
  if (shouldPreventNavigation()) {
399
342
  (0, _pointer.notifyKeyDown)(evt.keyCode);
400
343
  return;
401
344
  }
402
-
403
345
  var keyCode = evt.keyCode;
404
346
  var direction = getDirection(keyCode);
405
347
  var pointerHandled = (0, _pointer.notifyKeyDown)(keyCode, handlePointerHide);
406
-
407
348
  if (pointerHandled || !(direction || isEnter(keyCode))) {
408
349
  return;
409
350
  }
410
-
411
351
  if (!(0, _Pause.isPaused)() && !_pointerMoveDuringKeyPress) {
412
352
  if (_getCurrent()) {
413
353
  SpotlightAccelerator.processKey(evt, onAcceleratedKeyDown);
414
354
  } else if (!spotNextFromPoint(direction, (0, _pointer.getLastPointerPosition)())) {
415
355
  restoreFocus();
416
356
  }
417
-
418
357
  _5WayKeyHold = true;
419
358
  }
420
-
421
359
  if (direction) {
422
360
  preventDefault(evt);
423
361
  }
424
362
  }
425
-
426
363
  function onMouseMove(_ref2) {
427
364
  var target = _ref2.target,
428
- clientX = _ref2.clientX,
429
- clientY = _ref2.clientY;
430
-
365
+ clientX = _ref2.clientX,
366
+ clientY = _ref2.clientY;
431
367
  if (shouldPreventNavigation()) {
432
368
  (0, _pointer.notifyPointerMove)(null, target, clientX, clientY);
433
369
  return;
434
370
  }
435
-
436
371
  var current = _getCurrent();
437
-
438
372
  var update = (0, _pointer.notifyPointerMove)(current, target, clientX, clientY);
439
-
440
373
  if (update) {
441
374
  if (_5WayKeyHold) {
442
375
  _pointerMoveDuringKeyPress = true;
443
376
  }
377
+ var next = (0, _target.getNavigableTarget)(target);
444
378
 
445
- var next = (0, _target.getNavigableTarget)(target); // TODO: Consider encapsulating this work within focusElement
446
-
379
+ // TODO: Consider encapsulating this work within focusElement
447
380
  if (next !== current) {
448
381
  if (next) {
449
382
  focusElement(next, (0, _container.getContainersForNode)(next), true);
@@ -455,11 +388,9 @@ var Spotlight = function () {
455
388
  }
456
389
  }
457
390
  }
458
-
459
391
  function onMouseOver(evt) {
460
392
  if (shouldPreventNavigation()) return;
461
393
  var target = evt.target;
462
-
463
394
  if ((0, _pointer.getPointerMode)() && (0, _pointer.hasPointerMoved)(evt.clientX, evt.clientY)) {
464
395
  var next = (0, _target.getNavigableTarget)(target); // account for child controls
465
396
 
@@ -467,28 +398,21 @@ var Spotlight = function () {
467
398
  focusElement(next, (0, _container.getContainersForNode)(next), true);
468
399
  return true;
469
400
  }
470
-
471
401
  preventDefault(evt);
472
402
  }
473
403
  }
474
-
475
404
  function onTouchEnd(evt) {
476
405
  var current = _getCurrent();
477
-
478
406
  if (current && !current.contains(evt.target)) {
479
407
  current.blur();
480
408
  }
481
409
  }
410
+
482
411
  /*
483
412
  * public methods
484
413
  */
485
-
486
-
487
- var exports =
488
- /** @lends spotlight.Spotlight */
489
- {
414
+ var exports = /** @lends spotlight.Spotlight */{
490
415
  // eslint-disable-line no-shadow
491
-
492
416
  /**
493
417
  * Initializes Spotlight. This is generally handled by
494
418
  * {@link spotlight/SpotlightRootDecorator.SpotlightRootDecorator}.
@@ -505,26 +429,22 @@ var Spotlight = function () {
505
429
  window.addEventListener('keyup', onKeyUp);
506
430
  window.addEventListener('mouseover', onMouseOver);
507
431
  window.addEventListener('mousemove', onMouseMove);
508
-
509
432
  if (_platform["default"].touch) {
510
433
  window.addEventListener('touchend', onTouchEnd);
511
434
  }
512
-
513
435
  if (_platform["default"].webos) {
514
436
  window.top.document.addEventListener('webOSMouse', handleWebOSMouseEvent);
515
437
  window.top.document.addEventListener('keyboardStateChange', handleKeyboardStateChangeEvent);
516
438
  }
517
-
518
439
  (0, _container.setLastContainer)(_container.rootContainerId);
519
440
  (0, _container.configureDefaults)(containerDefaults);
520
- (0, _container.configureContainer)(_container.rootContainerId); // by default, pointer mode is off but the platform's current state will override that
521
-
441
+ (0, _container.configureContainer)(_container.rootContainerId);
442
+ // by default, pointer mode is off but the platform's current state will override that
522
443
  (0, _pointer.setPointerMode)(false);
523
444
  setPlatformPointerMode();
524
445
  _initialized = true;
525
446
  }
526
447
  },
527
-
528
448
  /**
529
449
  * Terminates Spotlight. This is generally handled by {@link spotlight.SpotlightRootDecorator}.
530
450
  *
@@ -537,20 +457,16 @@ var Spotlight = function () {
537
457
  window.removeEventListener('keyup', onKeyUp);
538
458
  window.removeEventListener('mouseover', onMouseOver);
539
459
  window.removeEventListener('mousemove', onMouseMove);
540
-
541
460
  if (_platform["default"].touch) {
542
461
  window.removeEventListener('touchend', onTouchEnd);
543
462
  }
544
-
545
463
  if (_platform["default"].webos) {
546
464
  window.top.document.removeEventListener('webOSMouse', handleWebOSMouseEvent);
547
465
  window.top.document.removeEventListener('keyboardStateChange', handleKeyboardStateChangeEvent);
548
466
  }
549
-
550
467
  Spotlight.clear();
551
468
  _initialized = false;
552
469
  },
553
-
554
470
  /**
555
471
  * Resets spotlight container information
556
472
  *
@@ -564,7 +480,6 @@ var Spotlight = function () {
564
480
  },
565
481
  // set(<config>);
566
482
  // set(<containerId>, <config>);
567
-
568
483
  /**
569
484
  * Sets the config for spotlight or the specified containerID
570
485
  *
@@ -578,7 +493,6 @@ var Spotlight = function () {
578
493
  set: _container.configureContainer,
579
494
  // add(<config>);
580
495
  // add(<containerId>, <config>);
581
-
582
496
  /**
583
497
  * Adds the config for a new container. The container ID may be passed in the configuration
584
498
  * object. If no container ID is supplied, a new container ID will be generated.
@@ -595,10 +509,8 @@ var Spotlight = function () {
595
509
  if (!containerId || typeof containerId !== 'string') {
596
510
  throw new Error('Please assign the "containerId"!');
597
511
  }
598
-
599
512
  (0, _container.unmountContainer)(containerId);
600
513
  },
601
-
602
514
  /**
603
515
  * Removes a container from Spotlight
604
516
  *
@@ -610,20 +522,15 @@ var Spotlight = function () {
610
522
  if (!containerId || typeof containerId !== 'string') {
611
523
  throw new Error('Please assign the "containerId"!');
612
524
  }
613
-
614
525
  if ((0, _container.getContainerConfig)(containerId)) {
615
526
  (0, _container.removeContainer)(containerId);
616
-
617
527
  if ((0, _container.getLastContainer)() === containerId) {
618
528
  Spotlight.setActiveContainer(null);
619
529
  }
620
-
621
530
  return true;
622
531
  }
623
-
624
532
  return false;
625
533
  },
626
-
627
534
  /**
628
535
  * Disables the selector rules of the specified container
629
536
  *
@@ -638,10 +545,8 @@ var Spotlight = function () {
638
545
  });
639
546
  return true;
640
547
  }
641
-
642
548
  return false;
643
549
  },
644
-
645
550
  /**
646
551
  * Enables the selector rules of the specified container
647
552
  *
@@ -656,10 +561,8 @@ var Spotlight = function () {
656
561
  });
657
562
  return true;
658
563
  }
659
-
660
564
  return false;
661
565
  },
662
-
663
566
  /**
664
567
  * Pauses Spotlight
665
568
  *
@@ -668,7 +571,6 @@ var Spotlight = function () {
668
571
  * @public
669
572
  */
670
573
  pause: _Pause.pause,
671
-
672
574
  /**
673
575
  * Resumes Spotlight
674
576
  *
@@ -680,7 +582,6 @@ var Spotlight = function () {
680
582
  // focus()
681
583
  // focus(<containerId>)
682
584
  // focus(<extSelector>)
683
-
684
585
  /**
685
586
  * Focuses the specified component ID, container ID, element selector, or the default
686
587
  * container.
@@ -705,7 +606,6 @@ var Spotlight = function () {
705
606
  var target = elem;
706
607
  var wasContainerId = false;
707
608
  var currentContainerNode = null;
708
-
709
609
  if (!elem) {
710
610
  target = (0, _target.getTargetByContainer)();
711
611
  } else if (typeof elem === 'string') {
@@ -723,37 +623,29 @@ var Spotlight = function () {
723
623
  target = (0, _target.getTargetByContainer)((0, _container.getContainerId)(elem), containerOption.enterTo);
724
624
  currentContainerNode = elem;
725
625
  }
726
-
727
626
  var nextContainerIds = (0, _container.getContainersForNode)(target);
728
627
  var nextContainerId = (0, _last["default"])(nextContainerIds);
729
-
730
628
  if ((0, _container.isNavigable)(target, nextContainerId, true)) {
731
629
  var focused = focusElement(target, nextContainerIds);
732
-
733
630
  if (!focused && wasContainerId) {
734
631
  (0, _container.setLastContainer)(elem);
735
632
  }
736
-
737
633
  return focused;
738
634
  } else if (wasContainerId) {
739
635
  // if we failed to find a spottable target within the provided container, we'll set
740
636
  // it as the active container to allow it to focus itself if its contents change
741
637
  (0, _container.setLastContainer)(elem);
742
638
  }
743
-
744
639
  if (containerOption.toOuterContainer && currentContainerNode) {
745
640
  var outerContainer = (0, _container.getContainersForNode)(currentContainerNode.parentElement).pop();
746
-
747
641
  if (outerContainer) {
748
642
  return this.focus(outerContainer, containerOption);
749
643
  }
750
644
  }
751
-
752
645
  return false;
753
646
  },
754
647
  // move(<direction>)
755
648
  // move(<direction>, <selector>)
756
-
757
649
  /**
758
650
  * Moves focus to the next spottable control in the direction specified. Optionally, a source
759
651
  * element selector may be supplied as the starting point.
@@ -766,26 +658,19 @@ var Spotlight = function () {
766
658
  */
767
659
  move: function move(direction, selector) {
768
660
  direction = direction.toLowerCase();
769
-
770
661
  if (direction !== 'up' && direction !== 'down' && direction !== 'left' && direction !== 'right') {
771
662
  return false;
772
663
  }
773
-
774
664
  var elem = selector ? (0, _utils.parseSelector)(selector)[0] : _getCurrent();
775
-
776
665
  if (!elem) {
777
666
  return false;
778
667
  }
779
-
780
668
  var containerIds = (0, _container.getContainersForNode)(elem);
781
-
782
669
  if (!containerIds.length) {
783
670
  return false;
784
671
  }
785
-
786
672
  return spotNext(direction, elem, containerIds);
787
673
  },
788
-
789
674
  /**
790
675
  * Sets or clears the default container that will receive focus.
791
676
  *
@@ -796,7 +681,6 @@ var Spotlight = function () {
796
681
  * @public
797
682
  */
798
683
  setDefaultContainer: _container.setDefaultContainer,
799
-
800
684
  /**
801
685
  * Gets the currently active container.
802
686
  *
@@ -806,7 +690,6 @@ var Spotlight = function () {
806
690
  getActiveContainer: function getActiveContainer() {
807
691
  return (0, _container.getLastContainer)() || _container.rootContainerId;
808
692
  },
809
-
810
693
  /**
811
694
  * Sets the currently active container.
812
695
  *
@@ -822,7 +705,6 @@ var Spotlight = function () {
822
705
  (0, _container.setLastContainer)(containerId || _container.rootContainerId);
823
706
  }
824
707
  },
825
-
826
708
  /**
827
709
  * Gets the current pointer mode
828
710
  *
@@ -831,7 +713,6 @@ var Spotlight = function () {
831
713
  * @public
832
714
  */
833
715
  getPointerMode: _pointer.getPointerMode,
834
-
835
716
  /**
836
717
  * Sets the current pointer mode
837
718
  *
@@ -841,7 +722,6 @@ var Spotlight = function () {
841
722
  * @public
842
723
  */
843
724
  setPointerMode: _pointer.setPointerMode,
844
-
845
725
  /**
846
726
  * Gets the muted mode value of a spottable element.
847
727
  *
@@ -853,10 +733,8 @@ var Spotlight = function () {
853
733
  if (!elem) {
854
734
  return false;
855
735
  }
856
-
857
736
  return (0, _utils.matchSelector)('[data-spotlight-container-muted="true"] .' + _Spottable.spottableClass, elem);
858
737
  },
859
-
860
738
  /**
861
739
  * Determines whether Spotlight is currently paused.
862
740
  *
@@ -865,7 +743,6 @@ var Spotlight = function () {
865
743
  * @public
866
744
  */
867
745
  isPaused: _Pause.isPaused,
868
-
869
746
  /**
870
747
  * Determines whether an element is spottable.
871
748
  *
@@ -877,10 +754,8 @@ var Spotlight = function () {
877
754
  if (!elem) {
878
755
  return false;
879
756
  }
880
-
881
757
  return (0, _target.isFocusable)(elem);
882
758
  },
883
-
884
759
  /**
885
760
  * Returns the currently spotted control.
886
761
  *
@@ -890,7 +765,6 @@ var Spotlight = function () {
890
765
  getCurrent: function getCurrent() {
891
766
  return _getCurrent();
892
767
  },
893
-
894
768
  /**
895
769
  * Returns a list of spottable elements wrapped by the supplied container.
896
770
  *
@@ -902,10 +776,8 @@ var Spotlight = function () {
902
776
  if (!containerId || typeof containerId !== 'string') {
903
777
  throw new Error('Please assign the "containerId"!');
904
778
  }
905
-
906
779
  return (0, _container.getSpottableDescendants)(containerId);
907
780
  },
908
-
909
781
  /**
910
782
  * Focuses the next spottable control from the position specified in the direction specified.
911
783
  *
@@ -917,7 +789,6 @@ var Spotlight = function () {
917
789
  };
918
790
  return exports;
919
791
  }();
920
-
921
792
  exports.Spotlight = Spotlight;
922
793
  var _default = Spotlight;
923
794
  exports["default"] = _default;