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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
  2. package/Accelerator/Accelerator.js +149 -156
  3. package/CHANGELOG.md +22 -0
  4. package/{build/Pause → Pause}/Pause.d.ts +0 -0
  5. package/Pause/Pause.js +102 -80
  6. package/Pause/tests/Pause-specs.js +65 -97
  7. package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
  8. package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
  9. package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
  10. package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
  11. package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
  12. package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
  13. package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
  14. package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
  15. package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
  16. package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
  17. package/Spottable/Spottable.js +448 -410
  18. package/Spottable/tests/Spottable-specs.js +90 -117
  19. package/package.json +3 -2
  20. package/src/container.js +718 -653
  21. package/src/navigate.js +406 -491
  22. package/src/pointer.js +86 -78
  23. package/{build/src → src}/spotlight.d.ts +0 -0
  24. package/src/spotlight.js +846 -885
  25. package/src/target.js +448 -474
  26. package/src/tests/container-specs.js +643 -1251
  27. package/src/tests/navigate-specs.js +77 -134
  28. package/src/tests/pointer-specs.js +126 -182
  29. package/src/tests/spotlight-specs.js +103 -133
  30. package/src/tests/target-specs.js +597 -960
  31. package/src/tests/utils.js +89 -67
  32. package/src/utils.js +155 -158
  33. package/build/Accelerator/Accelerator.js +0 -162
  34. package/build/Accelerator/package.json +0 -3
  35. package/build/CHANGELOG.md +0 -838
  36. package/build/Pause/Pause.js +0 -164
  37. package/build/Pause/package.json +0 -3
  38. package/build/Pause/tests/Pause-specs.js +0 -65
  39. package/build/README.md +0 -61
  40. package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
  41. package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
  42. package/build/SpotlightContainerDecorator/package.json +0 -3
  43. package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
  44. package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
  45. package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
  46. package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
  47. package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
  48. package/build/SpotlightRootDecorator/package.json +0 -3
  49. package/build/Spottable/Spottable.js +0 -491
  50. package/build/Spottable/package.json +0 -3
  51. package/build/Spottable/tests/Spottable-specs.js +0 -90
  52. package/build/package-lock.json +0 -229
  53. package/build/package.json +0 -28
  54. package/build/src/container.js +0 -1201
  55. package/build/src/navigate.js +0 -419
  56. package/build/src/pointer.js +0 -183
  57. package/build/src/spotlight.js +0 -896
  58. package/build/src/target.js +0 -507
  59. package/build/src/tests/container-specs.js +0 -653
  60. package/build/src/tests/navigate-specs.js +0 -87
  61. package/build/src/tests/pointer-specs.js +0 -130
  62. package/build/src/tests/spotlight-specs.js +0 -112
  63. package/build/src/tests/target-specs.js +0 -614
  64. package/build/src/tests/utils.js +0 -104
  65. package/build/src/utils.js +0 -180
  66. package/build/styles/debug.less +0 -97
  67. package/build/styles/mixins.less +0 -63
  68. package/docs/index.md +0 -364
package/src/container.js CHANGED
@@ -1,81 +1,134 @@
1
- /**
2
- * Exports methods and members for creating and maintaining spotlight containers.
3
- *
4
- * @module spotlight/container
5
- * @private
6
- */
1
+ "use strict";
7
2
 
8
- import and from 'ramda/src/and';
9
- import concat from 'ramda/src/concat';
10
- import {coerceArray} from '@enact/core/util';
11
- import intersection from 'ramda/src/intersection';
12
- import last from 'ramda/src/last';
13
-
14
- import {contains, matchSelector, getContainerRect, getRect, intersects} from './utils';
15
-
16
- const containerAttribute = 'data-spotlight-id';
17
- const containerConfigs = new Map();
18
- const containerKey = 'spotlightId';
19
- const disabledKey = 'spotlightContainerDisabled';
20
- const containerPrefix = 'container-';
21
- const containerSelector = '[data-spotlight-container]';
22
- const rootContainerId = 'spotlightRootDecorator';
23
- const reverseDirections = {
24
- 'left': 'right',
25
- 'up': 'down',
26
- 'right': 'left',
27
- 'down': 'up'
28
- };
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getContainerDefaultElement = getContainerDefaultElement;
7
+ exports.getContainerLastFocusedElement = getContainerLastFocusedElement;
8
+ exports.getContainerNavigableElements = getContainerNavigableElements;
9
+ exports.getContainersForNode = getContainersForNode;
10
+ exports.setContainerLastFocusedElement = setContainerLastFocusedElement;
11
+ exports.getContainerFocusTarget = getContainerFocusTarget;
12
+ exports.getContainerPreviousTarget = getContainerPreviousTarget;
13
+ exports.getDefaultContainer = getDefaultContainer;
14
+ exports.getLastContainer = getLastContainer;
15
+ exports.getNavigableContainersForNode = getNavigableContainersForNode;
16
+ exports.isWithinOverflowContainer = isWithinOverflowContainer;
17
+ exports.mayActivateContainer = mayActivateContainer;
18
+ exports.notifyLeaveContainer = notifyLeaveContainer;
19
+ exports.notifyLeaveContainerFail = notifyLeaveContainerFail;
20
+ exports.notifyEnterContainer = notifyEnterContainer;
21
+ exports.setContainerPreviousTarget = setContainerPreviousTarget;
22
+ exports.setDefaultContainer = setDefaultContainer;
23
+ exports.setLastContainer = setLastContainer;
24
+ exports.setLastContainerFromTarget = setLastContainerFromTarget;
25
+ 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
+
28
+ var _and = _interopRequireDefault(require("ramda/src/and"));
29
+
30
+ var _concat = _interopRequireDefault(require("ramda/src/concat"));
31
+
32
+ var _util = require("@enact/core/util");
33
+
34
+ var _intersection = _interopRequireDefault(require("ramda/src/intersection"));
35
+
36
+ var _last = _interopRequireDefault(require("ramda/src/last"));
37
+
38
+ var _utils = require("./utils");
39
+
40
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
41
+
42
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
43
+
44
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
29
45
 
30
- // Incrementer for container IDs
31
- let _ids = 0;
46
+ 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; }
32
47
 
33
- let _defaultContainerId = '';
34
- let _lastContainerId = '';
48
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
35
49
 
36
- // Note: an <extSelector> can be one of following types:
50
+ 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."); }
51
+
52
+ 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); }
53
+
54
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
55
+
56
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
57
+
58
+ 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; }
59
+
60
+ var containerAttribute = 'data-spotlight-id';
61
+ exports.containerAttribute = containerAttribute;
62
+ var containerConfigs = new Map();
63
+ var containerKey = 'spotlightId';
64
+ var disabledKey = 'spotlightContainerDisabled';
65
+ var containerPrefix = 'container-';
66
+ var containerSelector = '[data-spotlight-container]';
67
+ var rootContainerId = 'spotlightRootDecorator';
68
+ exports.rootContainerId = rootContainerId;
69
+ var reverseDirections = {
70
+ 'left': 'right',
71
+ 'up': 'down',
72
+ 'right': 'left',
73
+ 'down': 'up'
74
+ }; // Incrementer for container IDs
75
+
76
+ var _ids = 0;
77
+ var _defaultContainerId = '';
78
+ var _lastContainerId = ''; // Note: an <extSelector> can be one of following types:
37
79
  // - a valid selector string for "querySelectorAll"
38
80
  // - a NodeList or an array containing DOM elements
39
81
  // - a single DOM element
40
82
  // - a string "@<containerId>" to indicate the specified container
41
83
  // - a string "@" to indicate the default container
42
- let GlobalConfig = {
43
- // set to false for unmounted containers to omit them from searches
44
- active: true,
45
- continue5WayHold: false,
46
- defaultElement: '', // <extSelector> except "@" syntax.
47
- enterTo: '', // '', 'last-focused', 'default-element'
48
- lastFocusedElement: null,
49
- lastFocusedKey: null,
50
- lastFocusedPersist: (node, all) => {
51
- const container = typeof node === 'string';
52
- return {
53
- container,
54
- element: !container,
55
- key: container ? node : all.indexOf(node)
56
- };
57
- },
58
- lastFocusedRestore: ({container, key}, all) => {
59
- return container ? key : all[key];
60
- },
61
- leaveFor: null, // {left: <extSelector>, right: <extSelector>, up: <extSelector>, down: <extSelector>}
62
- navigableFilter: null,
63
- obliqueMultiplier: 5,
64
- onEnterContainer: null, // @private - notify the container when entering via 5-way
65
- onLeaveContainer: null, // @private - notify the container when leaving via 5-way
66
- onLeaveContainerFail: null, // @private - notify the container when failing to leave via 5-way
67
- overflow: false,
68
- partition: false, // use the container bounds for partitioning when leaving
69
- rememberSource: false,
70
- restrict: 'self-first', // 'self-first', 'self-only', 'none'
71
- selector: '', // can be a valid <extSelector> except "@" syntax.
72
- selectorDisabled: false,
73
- straightMultiplier: 1,
74
- straightOnly: false,
75
- straightOverlapThreshold: 0.5,
76
- tabIndexIgnoreList: 'a, input, select, textarea, button, iframe, [contentEditable=true]'
77
- };
78
84
 
85
+ var GlobalConfig = {
86
+ // set to false for unmounted containers to omit them from searches
87
+ active: true,
88
+ continue5WayHold: false,
89
+ defaultElement: '',
90
+ // <extSelector> except "@" syntax.
91
+ enterTo: '',
92
+ // '', 'last-focused', 'default-element'
93
+ lastFocusedElement: null,
94
+ lastFocusedKey: null,
95
+ lastFocusedPersist: function lastFocusedPersist(node, all) {
96
+ var container = typeof node === 'string';
97
+ return {
98
+ container: container,
99
+ element: !container,
100
+ key: container ? node : all.indexOf(node)
101
+ };
102
+ },
103
+ lastFocusedRestore: function lastFocusedRestore(_ref, all) {
104
+ var container = _ref.container,
105
+ key = _ref.key;
106
+ return container ? key : all[key];
107
+ },
108
+ leaveFor: null,
109
+ // {left: <extSelector>, right: <extSelector>, up: <extSelector>, down: <extSelector>}
110
+ navigableFilter: null,
111
+ obliqueMultiplier: 5,
112
+ onEnterContainer: null,
113
+ // @private - notify the container when entering via 5-way
114
+ onLeaveContainer: null,
115
+ // @private - notify the container when leaving via 5-way
116
+ onLeaveContainerFail: null,
117
+ // @private - notify the container when failing to leave via 5-way
118
+ overflow: false,
119
+ partition: false,
120
+ // use the container bounds for partitioning when leaving
121
+ rememberSource: false,
122
+ restrict: 'self-first',
123
+ // 'self-first', 'self-only', 'none'
124
+ selector: '',
125
+ // can be a valid <extSelector> except "@" syntax.
126
+ selectorDisabled: false,
127
+ straightMultiplier: 1,
128
+ straightOnly: false,
129
+ straightOverlapThreshold: 0.5,
130
+ tabIndexIgnoreList: 'a, input, select, textarea, button, iframe, [contentEditable=true]'
131
+ };
79
132
  /**
80
133
  * Calculates nodes within `node` that match `includeSelector` and do not match `excludeSelector`
81
134
  *
@@ -87,20 +140,21 @@ let GlobalConfig = {
87
140
  * @memberof spotlight/container
88
141
  * @private
89
142
  */
90
- const querySelector = (node, includeSelector, excludeSelector) => {
91
- const include = Array.prototype.slice.call(node.querySelectorAll(includeSelector));
92
- const exclude = node.querySelectorAll(excludeSelector);
93
-
94
- for (let i = 0; i < exclude.length; i++) {
95
- const index = include.indexOf(exclude.item(i));
96
- if (index >= 0) {
97
- include.splice(index, 1);
98
- }
99
- }
100
-
101
- return include;
102
- };
103
143
 
144
+ var querySelector = function querySelector(node, includeSelector, excludeSelector) {
145
+ var include = Array.prototype.slice.call(node.querySelectorAll(includeSelector));
146
+ var exclude = node.querySelectorAll(excludeSelector);
147
+
148
+ for (var i = 0; i < exclude.length; i++) {
149
+ var index = include.indexOf(exclude.item(i));
150
+
151
+ if (index >= 0) {
152
+ include.splice(index, 1);
153
+ }
154
+ }
155
+
156
+ return include;
157
+ };
104
158
  /**
105
159
  * Determines if `node` is a spotlight container
106
160
  *
@@ -110,10 +164,11 @@ const querySelector = (node, includeSelector, excludeSelector) => {
110
164
  * @memberof spotlight/container
111
165
  * @private
112
166
  */
113
- const isContainerNode = (node) => {
114
- return node && node.dataset && 'spotlightContainer' in node.dataset;
115
- };
116
167
 
168
+
169
+ var isContainerNode = function isContainerNode(node) {
170
+ return node && node.dataset && 'spotlightContainer' in node.dataset;
171
+ };
117
172
  /**
118
173
  * Walks up the node hierarchy calling `fn` on each node that is a container
119
174
  *
@@ -127,19 +182,21 @@ const isContainerNode = (node) => {
127
182
  * @memberof spotlight/container
128
183
  * @private
129
184
  */
130
- const mapContainers = (node, fn) => {
131
- const result = [];
132
185
 
133
- while (node && node !== document) {
134
- if (isContainerNode(node)) {
135
- result.unshift(fn(node));
136
- }
137
- node = node.parentNode;
138
- }
139
186
 
140
- return result;
141
- };
187
+ var mapContainers = function mapContainers(node, fn) {
188
+ var result = [];
142
189
 
190
+ while (node && node !== document) {
191
+ if (isContainerNode(node)) {
192
+ result.unshift(fn(node));
193
+ }
194
+
195
+ node = node.parentNode;
196
+ }
197
+
198
+ return result;
199
+ };
143
200
  /**
144
201
  * Returns the container config for `containerId`
145
202
  *
@@ -149,10 +206,11 @@ const mapContainers = (node, fn) => {
149
206
  * @memberof spotlight/container
150
207
  * @private
151
208
  */
152
- const getContainerConfig = (id) => {
153
- return containerConfigs.get(id);
154
- };
155
209
 
210
+
211
+ var getContainerConfig = function getContainerConfig(id) {
212
+ return containerConfigs.get(id);
213
+ };
156
214
  /**
157
215
  * Determines if node or a container id represents a spotlight container
158
216
  *
@@ -162,14 +220,17 @@ const getContainerConfig = (id) => {
162
220
  * @memberof spotlight/container
163
221
  * @private
164
222
  */
165
- const isContainer = (nodeOrId) => {
166
- if (typeof nodeOrId === 'string') {
167
- return containerConfigs.has(nodeOrId);
168
- }
169
223
 
170
- return isContainerNode(nodeOrId);
171
- };
172
224
 
225
+ exports.getContainerConfig = getContainerConfig;
226
+
227
+ var isContainer = function isContainer(nodeOrId) {
228
+ if (typeof nodeOrId === 'string') {
229
+ return containerConfigs.has(nodeOrId);
230
+ }
231
+
232
+ return isContainerNode(nodeOrId);
233
+ };
173
234
  /**
174
235
  * Determines if any of the containers at or above `node` are disabled and, if so, returns `false`.
175
236
  *
@@ -179,12 +240,15 @@ const isContainer = (nodeOrId) => {
179
240
  * @memberof spotlight/container
180
241
  * @private
181
242
  */
182
- const isContainerEnabled = (node) => {
183
- return mapContainers(node, container => {
184
- return container.dataset[disabledKey] !== 'true';
185
- }).reduce(and, true);
186
- };
187
243
 
244
+
245
+ exports.isContainer = isContainer;
246
+
247
+ var isContainerEnabled = function isContainerEnabled(node) {
248
+ return mapContainers(node, function (container) {
249
+ return container.dataset[disabledKey] !== 'true';
250
+ }).reduce(_and["default"], true);
251
+ };
188
252
  /**
189
253
  * Returns the container ID for `node`
190
254
  *
@@ -194,8 +258,11 @@ const isContainerEnabled = (node) => {
194
258
  * @memberof spotlight/container
195
259
  * @private
196
260
  */
197
- const getContainerId = (node) => node.dataset[containerKey];
198
261
 
262
+
263
+ var getContainerId = function getContainerId(node) {
264
+ return node.dataset[containerKey];
265
+ };
199
266
  /**
200
267
  * Generates a CSS selector string for a current container if `node` is a container
201
268
  *
@@ -205,14 +272,17 @@ const getContainerId = (node) => node.dataset[containerKey];
205
272
  * @memberof spotlight/container
206
273
  * @private
207
274
  */
208
- const getContainerSelector = (node) => {
209
- if (isContainerNode(node)) {
210
- return `[${containerAttribute}="${getContainerId(node)}"]`;
211
- }
212
275
 
213
- return '';
214
- };
215
276
 
277
+ exports.getContainerId = getContainerId;
278
+
279
+ var getContainerSelector = function getContainerSelector(node) {
280
+ if (isContainerNode(node)) {
281
+ return "[".concat(containerAttribute, "=\"").concat(getContainerId(node), "\"]");
282
+ }
283
+
284
+ return '';
285
+ };
216
286
  /**
217
287
  * Generates a CSS selector string for containers within `node` if it is a container
218
288
  *
@@ -222,14 +292,15 @@ const getContainerSelector = (node) => {
222
292
  * @memberof spotlight/container
223
293
  * @private
224
294
  */
225
- const getSubContainerSelector = (node) => {
226
- if (isContainerNode(node)) {
227
- return `${getContainerSelector(node)} ${containerSelector}`;
228
- }
229
295
 
230
- return containerSelector;
231
- };
232
296
 
297
+ var getSubContainerSelector = function getSubContainerSelector(node) {
298
+ if (isContainerNode(node)) {
299
+ return "".concat(getContainerSelector(node), " ").concat(containerSelector);
300
+ }
301
+
302
+ return containerSelector;
303
+ };
233
304
  /**
234
305
  * Returns the node for a container
235
306
  *
@@ -239,16 +310,17 @@ const getSubContainerSelector = (node) => {
239
310
  * @memberof spotlight/container
240
311
  * @private
241
312
  */
242
- const getContainerNode = (containerId) => {
243
- if (!containerId) {
244
- return null;
245
- } else if (containerId === rootContainerId) {
246
- return document;
247
- }
248
-
249
- return document.querySelector(`[${containerAttribute}="${containerId}"]`);
250
- };
251
313
 
314
+
315
+ var getContainerNode = function getContainerNode(containerId) {
316
+ if (!containerId) {
317
+ return null;
318
+ } else if (containerId === rootContainerId) {
319
+ return document;
320
+ }
321
+
322
+ return document.querySelector("[".concat(containerAttribute, "=\"").concat(containerId, "\"]"));
323
+ };
252
324
  /**
253
325
  * Calls the `navigableFilter` function for the container if defined.
254
326
  *
@@ -260,17 +332,21 @@ const getContainerNode = (containerId) => {
260
332
  * @memberof spotlight/container
261
333
  * @private
262
334
  */
263
- const navigableFilter = (node, containerId) => {
264
- const config = getContainerConfig(containerId);
265
- if (config && typeof config.navigableFilter === 'function') {
266
- if (config.navigableFilter(node, containerId) === false) {
267
- return false;
268
- }
269
- }
270
-
271
- return true;
272
- };
273
335
 
336
+
337
+ exports.getContainerNode = getContainerNode;
338
+
339
+ var navigableFilter = function navigableFilter(node, containerId) {
340
+ var config = getContainerConfig(containerId);
341
+
342
+ if (config && typeof config.navigableFilter === 'function') {
343
+ if (config.navigableFilter(node, containerId) === false) {
344
+ return false;
345
+ }
346
+ }
347
+
348
+ return true;
349
+ };
274
350
  /**
275
351
  * Determines nodes that are owned by `node` based on `aria-owns`.
276
352
  *
@@ -280,20 +356,23 @@ const navigableFilter = (node, containerId) => {
280
356
  * @memberof spotlight/container
281
357
  * @private
282
358
  */
283
- const getOwnedNodes = (node, selector) => {
284
- // if node is document, it will not have getAttribute and therefore can't have aria-owns
285
- const owns = node && node.getAttribute && node.getAttribute('aria-owns');
286
- if (owns) {
287
- const ids = owns.split(' ');
288
- return ids
289
- .map(id => id && document.getElementById(id))
290
- .filter(Boolean)
291
- .filter(n => isContainerNode(n) || matchSelector(selector, n));
292
- }
293
-
294
- return [];
295
- };
296
359
 
360
+
361
+ var getOwnedNodes = function getOwnedNodes(node, selector) {
362
+ // if node is document, it will not have getAttribute and therefore can't have aria-owns
363
+ var owns = node && node.getAttribute && node.getAttribute('aria-owns');
364
+
365
+ if (owns) {
366
+ var ids = owns.split(' ');
367
+ return ids.map(function (id) {
368
+ return id && document.getElementById(id);
369
+ }).filter(Boolean).filter(function (n) {
370
+ return isContainerNode(n) || (0, _utils.matchSelector)(selector, n);
371
+ });
372
+ }
373
+
374
+ return [];
375
+ };
297
376
  /**
298
377
  * Determines all spottable elements and containers that are directly contained by the container
299
378
  * identified by `containerId` and no other subcontainers.
@@ -304,33 +383,31 @@ const getOwnedNodes = (node, selector) => {
304
383
  * @memberof spotlight/container
305
384
  * @public
306
385
  */
307
- const getSpottableDescendants = (containerId) => {
308
- const node = getContainerNode(containerId);
309
386
 
310
- // if it's falsy or is a disabled container, return an empty set
311
- if (!node || (isContainerNode(node) && !isContainerEnabled(node))) {
312
- return [];
313
- }
314
387
 
315
- const {selector, selectorDisabled} = getContainerConfig(containerId) || {};
388
+ var getSpottableDescendants = function getSpottableDescendants(containerId) {
389
+ var node = getContainerNode(containerId); // if it's falsy or is a disabled container, return an empty set
316
390
 
317
- if (!selector || selectorDisabled) {
318
- return [];
319
- }
391
+ if (!node || isContainerNode(node) && !isContainerEnabled(node)) {
392
+ return [];
393
+ }
320
394
 
321
- const spottableSelector = selector;
322
- const subContainerSelector = getSubContainerSelector(node);
323
- const candidates = querySelector(
324
- node,
325
- `${spottableSelector}, ${getContainerSelector(node)} ${containerSelector}:not([data-spotlight-container-disabled="true"])`,
326
- `${subContainerSelector} ${spottableSelector}, ${subContainerSelector} ${containerSelector}`
327
- );
395
+ var _ref2 = getContainerConfig(containerId) || {},
396
+ selector = _ref2.selector,
397
+ selectorDisabled = _ref2.selectorDisabled;
328
398
 
329
- candidates.push(...getOwnedNodes(node, selector));
399
+ if (!selector || selectorDisabled) {
400
+ return [];
401
+ }
330
402
 
331
- return candidates.filter(n => navigableFilter(n, containerId));
403
+ var spottableSelector = selector;
404
+ var subContainerSelector = getSubContainerSelector(node);
405
+ var candidates = querySelector(node, "".concat(spottableSelector, ", ").concat(getContainerSelector(node), " ").concat(containerSelector, ":not([data-spotlight-container-disabled=\"true\"])"), "".concat(subContainerSelector, " ").concat(spottableSelector, ", ").concat(subContainerSelector, " ").concat(containerSelector));
406
+ candidates.push.apply(candidates, _toConsumableArray(getOwnedNodes(node, selector)));
407
+ return candidates.filter(function (n) {
408
+ return navigableFilter(n, containerId);
409
+ });
332
410
  };
333
-
334
411
  /**
335
412
  * Recursively get spottable descendants by including elements within sub-containers that do not
336
413
  * have `enterTo` configured
@@ -342,24 +419,26 @@ const getSpottableDescendants = (containerId) => {
342
419
  * @memberof spotlight/container
343
420
  * @private
344
421
  */
345
- const getDeepSpottableDescendants = (containerId, excludedContainers) => {
346
- return getSpottableDescendants(containerId)
347
- .map(n => {
348
- if (isContainer(n)) {
349
- const id = getContainerId(n);
350
- const config = getContainerConfig(id);
351
- if (excludedContainers && excludedContainers.indexOf(id) >= 0) {
352
- return [];
353
- } else if (config && !config.enterTo) {
354
- return getDeepSpottableDescendants(id, excludedContainers);
355
- }
356
- }
357
-
358
- return [n];
359
- })
360
- .reduce(concat, []);
361
- };
362
422
 
423
+
424
+ exports.getSpottableDescendants = getSpottableDescendants;
425
+
426
+ var getDeepSpottableDescendants = function getDeepSpottableDescendants(containerId, excludedContainers) {
427
+ return getSpottableDescendants(containerId).map(function (n) {
428
+ if (isContainer(n)) {
429
+ var id = getContainerId(n);
430
+ var config = getContainerConfig(id);
431
+
432
+ if (excludedContainers && excludedContainers.indexOf(id) >= 0) {
433
+ return [];
434
+ } else if (config && !config.enterTo) {
435
+ return getDeepSpottableDescendants(id, excludedContainers);
436
+ }
437
+ }
438
+
439
+ return [n];
440
+ }).reduce(_concat["default"], []);
441
+ };
363
442
  /**
364
443
  * Determines if a container allows 5-way key hold to be preserved or not.
365
444
  *
@@ -368,11 +447,14 @@ const getDeepSpottableDescendants = (containerId, excludedContainers) => {
368
447
  * @memberof spotlight/container
369
448
  * @private
370
449
  */
371
- const isContainer5WayHoldable = (containerId) => {
372
- const config = getContainerConfig(containerId);
373
- return (config && config.continue5WayHold) || false;
374
- };
375
450
 
451
+
452
+ exports.getDeepSpottableDescendants = getDeepSpottableDescendants;
453
+
454
+ var isContainer5WayHoldable = function isContainer5WayHoldable(containerId) {
455
+ var config = getContainerConfig(containerId);
456
+ return config && config.continue5WayHold || false;
457
+ };
376
458
  /**
377
459
  * Returns an array of ids for containers that wrap the element, in order of outer-to-inner, with
378
460
  * the last array item being the immediate container id of the element.
@@ -383,13 +465,15 @@ const isContainer5WayHoldable = (containerId) => {
383
465
  * @memberof spotlight/container
384
466
  * @private
385
467
  */
386
- function getContainersForNode (node) {
387
- const containers = mapContainers(node, getContainerId);
388
- containers.unshift(rootContainerId);
389
468
 
390
- return containers;
391
- }
392
469
 
470
+ exports.isContainer5WayHoldable = isContainer5WayHoldable;
471
+
472
+ function getContainersForNode(node) {
473
+ var containers = mapContainers(node, getContainerId);
474
+ containers.unshift(rootContainerId);
475
+ return containers;
476
+ }
393
477
  /**
394
478
  * Returns an array of ids for containers that wrap the element, in order of outer-to-inner, with
395
479
  * the last array item being the immediate container id of the element. The container ids are
@@ -401,29 +485,27 @@ function getContainersForNode (node) {
401
485
  * @memberof spotlight/container
402
486
  * @private
403
487
  */
404
- function getNavigableContainersForNode (node) {
405
- const containerIds = getContainersForNode(node);
406
-
407
- // find first self-only container id
408
- const selfOnlyIndex = containerIds
409
- .map(getContainerConfig)
410
- .filter(config => config != null)
411
- .reduceRight((index, config, i) => {
412
- if (index === -1 && config.restrict === 'self-only') {
413
- return i;
414
- }
415
-
416
- return index;
417
- }, -1);
418
-
419
- // if we found one (and it's not the root), slice those off and return
420
- if (selfOnlyIndex > 0) {
421
- return containerIds.slice(selfOnlyIndex);
422
- }
423
-
424
- return containerIds;
425
- }
426
488
 
489
+
490
+ function getNavigableContainersForNode(node) {
491
+ var containerIds = getContainersForNode(node); // find first self-only container id
492
+
493
+ var selfOnlyIndex = containerIds.map(getContainerConfig).filter(function (config) {
494
+ return config != null;
495
+ }).reduceRight(function (index, config, i) {
496
+ if (index === -1 && config.restrict === 'self-only') {
497
+ return i;
498
+ }
499
+
500
+ return index;
501
+ }, -1); // if we found one (and it's not the root), slice those off and return
502
+
503
+ if (selfOnlyIndex > 0) {
504
+ return containerIds.slice(selfOnlyIndex);
505
+ }
506
+
507
+ return containerIds;
508
+ }
427
509
  /**
428
510
  * Generates a new unique identifier for a container
429
511
  *
@@ -431,18 +513,22 @@ function getNavigableContainersForNode (node) {
431
513
  * @memberof spotlight/container
432
514
  * @private
433
515
  */
434
- function generateId () {
435
- let id;
436
- /* eslint no-constant-condition: ["error", { "checkLoops": false }] */
437
- while (true) {
438
- id = containerPrefix + String(++_ids);
439
- if (!isContainer(id)) {
440
- break;
441
- }
442
- }
443
- return id;
444
- }
445
516
 
517
+
518
+ function generateId() {
519
+ var id;
520
+ /* eslint no-constant-condition: ["error", { "checkLoops": false }] */
521
+
522
+ while (true) {
523
+ id = containerPrefix + String(++_ids);
524
+
525
+ if (!isContainer(id)) {
526
+ break;
527
+ }
528
+ }
529
+
530
+ return id;
531
+ }
446
532
  /**
447
533
  * Merges two container configurations while only allowing keys from `updated` which are defined in
448
534
  * `GlobalConfig`
@@ -454,23 +540,22 @@ function generateId () {
454
540
  * @memberof spotlight/container
455
541
  * @private
456
542
  */
457
- const mergeConfig = (current, updated) => {
458
- if (!updated) return current;
459
543
 
460
- let cfg = null;
461
544
 
462
- Object.keys(updated).forEach(key => {
463
- if (key in GlobalConfig && current[key] !== updated[key]) {
464
- if (cfg == null) {
465
- cfg = Object.assign({}, current);
466
- }
467
- cfg[key] = updated[key];
468
- }
469
- });
545
+ var mergeConfig = function mergeConfig(current, updated) {
546
+ if (!updated) return current;
547
+ var cfg = null;
548
+ Object.keys(updated).forEach(function (key) {
549
+ if (key in GlobalConfig && current[key] !== updated[key]) {
550
+ if (cfg == null) {
551
+ cfg = Object.assign({}, current);
552
+ }
470
553
 
471
- return cfg || current;
554
+ cfg[key] = updated[key];
555
+ }
556
+ });
557
+ return cfg || current;
472
558
  };
473
-
474
559
  /**
475
560
  * Adds or updates a container. When a container id is not specified, it will be generated.
476
561
  *
@@ -484,29 +569,30 @@ const mergeConfig = (current, updated) => {
484
569
  * @memberof spotlight/container
485
570
  * @public
486
571
  */
487
- const configureContainer = (...args) => {
488
- let containerId, config;
489
-
490
- if (typeof args[0] === 'object') {
491
- config = args[0];
492
- containerId = config.id;
493
- } else if (typeof args[0] === 'string') {
494
- containerId = args[0];
495
- if (typeof args[1] === 'object') {
496
- config = args[1];
497
- }
498
- }
499
-
500
- if (!containerId) {
501
- containerId = generateId();
502
- }
503
-
504
- config = mergeConfig(containerConfigs.get(containerId) || {...GlobalConfig}, config);
505
- containerConfigs.set(containerId, config);
506
-
507
- return containerId;
508
- };
509
572
 
573
+
574
+ var configureContainer = function configureContainer() {
575
+ var containerId, config;
576
+
577
+ if (typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'object') {
578
+ config = arguments.length <= 0 ? undefined : arguments[0];
579
+ containerId = config.id;
580
+ } else if (typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') {
581
+ containerId = arguments.length <= 0 ? undefined : arguments[0];
582
+
583
+ if (typeof (arguments.length <= 1 ? undefined : arguments[1]) === 'object') {
584
+ config = arguments.length <= 1 ? undefined : arguments[1];
585
+ }
586
+ }
587
+
588
+ if (!containerId) {
589
+ containerId = generateId();
590
+ }
591
+
592
+ config = mergeConfig(containerConfigs.get(containerId) || _objectSpread({}, GlobalConfig), config);
593
+ containerConfigs.set(containerId, config);
594
+ return containerId;
595
+ };
510
596
  /**
511
597
  * Adds a container and marks it active. When a container id is not specified, it will be generated.
512
598
  *
@@ -520,14 +606,16 @@ const configureContainer = (...args) => {
520
606
  * @memberof spotlight/container
521
607
  * @public
522
608
  */
523
- const addContainer = (...args) => {
524
- const containerId = configureContainer(...args);
525
- const config = getContainerConfig(containerId);
526
- config.active = true;
527
609
 
528
- return containerId;
529
- };
530
610
 
611
+ exports.configureContainer = configureContainer;
612
+
613
+ var addContainer = function addContainer() {
614
+ var containerId = configureContainer.apply(void 0, arguments);
615
+ var config = getContainerConfig(containerId);
616
+ config.active = true;
617
+ return containerId;
618
+ };
531
619
  /**
532
620
  * Removes a container
533
621
  *
@@ -537,10 +625,13 @@ const addContainer = (...args) => {
537
625
  * @memberof spotlight/container
538
626
  * @public
539
627
  */
540
- const removeContainer = (containerId) => {
541
- containerConfigs.delete(containerId);
542
- };
543
628
 
629
+
630
+ exports.addContainer = addContainer;
631
+
632
+ var removeContainer = function removeContainer(containerId) {
633
+ containerConfigs["delete"](containerId);
634
+ };
544
635
  /**
545
636
  * Removes all containers
546
637
  *
@@ -548,10 +639,13 @@ const removeContainer = (containerId) => {
548
639
  * @memberof spotlight/container
549
640
  * @public
550
641
  */
551
- const removeAllContainers = () => {
552
- containerConfigs.clear();
553
- };
554
642
 
643
+
644
+ exports.removeContainer = removeContainer;
645
+
646
+ var removeAllContainers = function removeAllContainers() {
647
+ containerConfigs.clear();
648
+ };
555
649
  /**
556
650
  * Configures the `GlobalConfig` for containers
557
651
  *
@@ -561,10 +655,13 @@ const removeAllContainers = () => {
561
655
  * @memberof spotlight/container
562
656
  * @public
563
657
  */
564
- const configureDefaults = (config) => {
565
- GlobalConfig = mergeConfig(GlobalConfig, config);
566
- };
567
658
 
659
+
660
+ exports.removeAllContainers = removeAllContainers;
661
+
662
+ var configureDefaults = function configureDefaults(config) {
663
+ GlobalConfig = mergeConfig(GlobalConfig, config);
664
+ };
568
665
  /**
569
666
  * Determines if `node` is a navigable element within the container identified by `containerId`.
570
667
  *
@@ -576,28 +673,30 @@ const configureDefaults = (config) => {
576
673
  * @memberof spotlight/container
577
674
  * @public
578
675
  */
579
- const isNavigable = (node, containerId, verify) => {
580
- if (!node || (
581
- // jsdom reports all nodes as having no size so we must skip this condition in our tests
582
- process.env.NODE_ENV !== 'test' &&
583
- node.offsetWidth <= 0 && node.offsetHeight <= 0
584
- )) {
585
- return false;
586
- }
587
-
588
- const containerNode = getContainerNode(containerId);
589
- if (containerNode !== document && containerNode.dataset[disabledKey] === 'true') {
590
- return false;
591
- }
592
-
593
- const config = getContainerConfig(containerId);
594
- if (verify && config && config.selector && !isContainer(node) && !matchSelector(config.selector, node)) {
595
- return false;
596
- }
597
-
598
- return navigableFilter(node, containerId);
599
- };
600
676
 
677
+
678
+ exports.configureDefaults = configureDefaults;
679
+
680
+ var isNavigable = function isNavigable(node, containerId, verify) {
681
+ if (!node || // jsdom reports all nodes as having no size so we must skip this condition in our tests
682
+ process.env.NODE_ENV !== 'test' && node.offsetWidth <= 0 && node.offsetHeight <= 0) {
683
+ return false;
684
+ }
685
+
686
+ var containerNode = getContainerNode(containerId);
687
+
688
+ if (containerNode !== document && containerNode.dataset[disabledKey] === 'true') {
689
+ return false;
690
+ }
691
+
692
+ var config = getContainerConfig(containerId);
693
+
694
+ if (verify && config && config.selector && !isContainer(node) && !(0, _utils.matchSelector)(config.selector, node)) {
695
+ return false;
696
+ }
697
+
698
+ return navigableFilter(node, containerId);
699
+ };
601
700
  /**
602
701
  * Returns the IDs of all containers
603
702
  *
@@ -605,21 +704,24 @@ const isNavigable = (node, containerId, verify) => {
605
704
  * @memberof spotlight/container
606
705
  * @private
607
706
  */
608
- const getAllContainerIds = () => {
609
- const ids = [];
610
- const keys = containerConfigs.keys();
611
-
612
- // PhantomJS-friendly iterator->array conversion
613
- let id;
614
- while ((id = keys.next()) && !id.done) {
615
- if (isActiveContainer(id.value)) {
616
- ids.push(id.value);
617
- }
618
- }
619
-
620
- return ids;
621
- };
622
707
 
708
+
709
+ exports.isNavigable = isNavigable;
710
+
711
+ var getAllContainerIds = function getAllContainerIds() {
712
+ var ids = [];
713
+ var keys = containerConfigs.keys(); // PhantomJS-friendly iterator->array conversion
714
+
715
+ var id;
716
+
717
+ while ((id = keys.next()) && !id.done) {
718
+ if (isActiveContainer(id.value)) {
719
+ ids.push(id.value);
720
+ }
721
+ }
722
+
723
+ return ids;
724
+ };
623
725
  /**
624
726
  * Returns the default focus element for a container
625
727
  *
@@ -631,40 +733,41 @@ const getAllContainerIds = () => {
631
733
  * @memberof spotlight/container
632
734
  * @public
633
735
  */
634
- function getContainerDefaultElement (containerId, preferredEnterTo) {
635
- const config = getContainerConfig(containerId);
636
-
637
- let defaultElementSelector = config && config.defaultElement;
638
- if (!defaultElementSelector) {
639
- return null;
640
- }
641
-
642
- defaultElementSelector = coerceArray(defaultElementSelector);
643
-
644
- // If a preferred enterTo has been provided, we will favor it by making it first in search array
645
- if (preferredEnterTo && typeof preferredEnterTo === 'string' && preferredEnterTo !== 'default-element') {
646
- defaultElementSelector.unshift(preferredEnterTo);
647
- }
648
-
649
- const spottables = getDeepSpottableDescendants(containerId);
650
-
651
- return defaultElementSelector.reduce((result, selector) => {
652
- if (result) {
653
- return result;
654
- }
655
-
656
- if (typeof selector === 'string') {
657
- return spottables.filter(elem => {
658
- return matchSelector(selector, elem) && isNavigable(elem, containerId, true);
659
- })[0];
660
- }
661
-
662
- // FIXME: There is some prior implicit support for `defaultElement` to be an element rather
663
- // than a selector. This continues that support but should eventually be removed.
664
- return selector;
665
- }, null);
666
- }
667
736
 
737
+
738
+ exports.getAllContainerIds = getAllContainerIds;
739
+
740
+ function getContainerDefaultElement(containerId, preferredEnterTo) {
741
+ var config = getContainerConfig(containerId);
742
+ var defaultElementSelector = config && config.defaultElement;
743
+
744
+ if (!defaultElementSelector) {
745
+ return null;
746
+ }
747
+
748
+ defaultElementSelector = (0, _util.coerceArray)(defaultElementSelector); // If a preferred enterTo has been provided, we will favor it by making it first in search array
749
+
750
+ if (preferredEnterTo && typeof preferredEnterTo === 'string' && preferredEnterTo !== 'default-element') {
751
+ defaultElementSelector.unshift(preferredEnterTo);
752
+ }
753
+
754
+ var spottables = getDeepSpottableDescendants(containerId);
755
+ return defaultElementSelector.reduce(function (result, selector) {
756
+ if (result) {
757
+ return result;
758
+ }
759
+
760
+ if (typeof selector === 'string') {
761
+ return spottables.filter(function (elem) {
762
+ return (0, _utils.matchSelector)(selector, elem) && isNavigable(elem, containerId, true);
763
+ })[0];
764
+ } // FIXME: There is some prior implicit support for `defaultElement` to be an element rather
765
+ // than a selector. This continues that support but should eventually be removed.
766
+
767
+
768
+ return selector;
769
+ }, null);
770
+ }
668
771
  /**
669
772
  * Gets the element last focused within the container.
670
773
  *
@@ -674,23 +777,25 @@ function getContainerDefaultElement (containerId, preferredEnterTo) {
674
777
  * @memberof spotlight/container
675
778
  * @public
676
779
  */
677
- function getContainerLastFocusedElement (containerId) {
678
- const config = getContainerConfig(containerId);
679
780
 
680
- if (!config || !config.lastFocusedElement) {
681
- return null;
682
- }
683
781
 
684
- // lastFocusedElement may be a container ID so try to convert it to a node to test navigability
685
- const {lastFocusedElement} = config;
686
- let node = lastFocusedElement;
687
- if (typeof node === 'string') {
688
- node = getContainerNode(lastFocusedElement);
689
- }
782
+ function getContainerLastFocusedElement(containerId) {
783
+ var config = getContainerConfig(containerId);
784
+
785
+ if (!config || !config.lastFocusedElement) {
786
+ return null;
787
+ } // lastFocusedElement may be a container ID so try to convert it to a node to test navigability
690
788
 
691
- return isNavigable(node, containerId, true) ? lastFocusedElement : null;
692
- }
693
789
 
790
+ var lastFocusedElement = config.lastFocusedElement;
791
+ var node = lastFocusedElement;
792
+
793
+ if (typeof node === 'string') {
794
+ node = getContainerNode(lastFocusedElement);
795
+ }
796
+
797
+ return isNavigable(node, containerId, true) ? lastFocusedElement : null;
798
+ }
694
799
  /**
695
800
  * Sets the element last focused within the container
696
801
  *
@@ -701,21 +806,25 @@ function getContainerLastFocusedElement (containerId) {
701
806
  * @memberof spotlight/container
702
807
  * @public
703
808
  */
704
- function setContainerLastFocusedElement (node, containerIds) {
705
- let lastFocusedElement = node;
706
- for (let i = containerIds.length - 1; i > -1; i--) {
707
- const id = containerIds[i];
708
- configureContainer(id, {lastFocusedElement});
709
-
710
- // If any container in the stack is controlling entering focus, use its container id as the
711
- // lastFocusedElement instead of the node
712
- const config = getContainerConfig(id);
713
- if (config.enterTo) {
714
- lastFocusedElement = id;
715
- }
716
- }
717
- }
718
809
 
810
+
811
+ function setContainerLastFocusedElement(node, containerIds) {
812
+ var lastFocusedElement = node;
813
+
814
+ for (var i = containerIds.length - 1; i > -1; i--) {
815
+ var id = containerIds[i];
816
+ configureContainer(id, {
817
+ lastFocusedElement: lastFocusedElement
818
+ }); // If any container in the stack is controlling entering focus, use its container id as the
819
+ // lastFocusedElement instead of the node
820
+
821
+ var config = getContainerConfig(id);
822
+
823
+ if (config.enterTo) {
824
+ lastFocusedElement = id;
825
+ }
826
+ }
827
+ }
719
828
  /**
720
829
  * Returns all navigable nodes (spottable nodes or containers) visible from outside the container.
721
830
  * If the container is restricting navigation into itself via `enterTo`, this method will attempt to
@@ -730,56 +839,54 @@ function setContainerLastFocusedElement (node, containerIds) {
730
839
  * @memberof spotlight/container
731
840
  * @public
732
841
  */
733
- function getContainerNavigableElements (containerId, preferredEnterTo) {
734
- if (!isContainer(containerId)) {
735
- return [];
736
- }
737
-
738
- const config = getContainerConfig(containerId);
739
- const {enterTo, overflow} = config;
740
-
741
- const enterLast = preferredEnterTo === 'last-focused' || (enterTo === 'last-focused' && !preferredEnterTo);
742
- let next;
743
-
744
- // if the container has a preferred entry point, try to find it first
745
- if (enterLast) {
746
- next = getContainerLastFocusedElement(containerId);
747
- }
748
-
749
- // try default element if last focused can't be focused
750
- if (!next) {
751
- next = getContainerDefaultElement(containerId, preferredEnterTo);
752
- }
753
-
754
- if (!next) {
755
- let spottables = overflow ?
756
- // overflow requires deep recursion to handle selecting the children of unrestricted
757
- // containers or restricted containers larger than the container
758
- getDeepSpottableDescendants(containerId) :
759
- getSpottableDescendants(containerId);
760
-
761
- // if there isn't a preferred entry on an overflow container, filter the visible elements
762
- if (overflow) {
763
- const containerRect = getContainerRect(containerId);
764
- next = containerRect && spottables.filter(element => {
765
- const elementRect = getRect(element);
766
- if (isContainer(element)) {
767
- return intersects(containerRect, elementRect);
768
- }
769
-
770
- return contains(containerRect, getRect(element));
771
- });
772
- }
773
-
774
- // otherwise, return all spottables within the container
775
- if (!next) {
776
- next = spottables;
777
- }
778
- }
779
-
780
- return next ? coerceArray(next) : [];
781
- }
782
842
 
843
+
844
+ function getContainerNavigableElements(containerId, preferredEnterTo) {
845
+ if (!isContainer(containerId)) {
846
+ return [];
847
+ }
848
+
849
+ var config = getContainerConfig(containerId);
850
+ var enterTo = config.enterTo,
851
+ overflow = config.overflow;
852
+ var enterLast = preferredEnterTo === 'last-focused' || enterTo === 'last-focused' && !preferredEnterTo;
853
+ var next; // if the container has a preferred entry point, try to find it first
854
+
855
+ if (enterLast) {
856
+ next = getContainerLastFocusedElement(containerId);
857
+ } // try default element if last focused can't be focused
858
+
859
+
860
+ if (!next) {
861
+ next = getContainerDefaultElement(containerId, preferredEnterTo);
862
+ }
863
+
864
+ if (!next) {
865
+ var spottables = overflow ? // overflow requires deep recursion to handle selecting the children of unrestricted
866
+ // containers or restricted containers larger than the container
867
+ getDeepSpottableDescendants(containerId) : getSpottableDescendants(containerId); // if there isn't a preferred entry on an overflow container, filter the visible elements
868
+
869
+ if (overflow) {
870
+ var containerRect = (0, _utils.getContainerRect)(containerId);
871
+ next = containerRect && spottables.filter(function (element) {
872
+ var elementRect = (0, _utils.getRect)(element);
873
+
874
+ if (isContainer(element)) {
875
+ return (0, _utils.intersects)(containerRect, elementRect);
876
+ }
877
+
878
+ return (0, _utils.contains)(containerRect, (0, _utils.getRect)(element));
879
+ });
880
+ } // otherwise, return all spottables within the container
881
+
882
+
883
+ if (!next) {
884
+ next = spottables;
885
+ }
886
+ }
887
+
888
+ return next ? (0, _util.coerceArray)(next) : [];
889
+ }
783
890
  /**
784
891
  * Determines the preferred focus target, traversing any sub-containers as necessary, for the given
785
892
  * container.
@@ -792,52 +899,47 @@ function getContainerNavigableElements (containerId, preferredEnterTo) {
792
899
  * @memberof spotlight/container
793
900
  * @public
794
901
  */
795
- function getContainerFocusTarget (containerId, preferredEnterTo) {
796
- // deferring restoration until it's requested to allow containers to prepare first
797
- restoreLastFocusedElement(containerId);
798
-
799
- let next = getContainerNavigableElements(containerId, preferredEnterTo);
800
- // If multiple candidates returned, we need to find the first viable target since some may
801
- // be empty containers which should be skipped.
802
- return next.reduce((result, element) => {
803
- if (result) {
804
- return result;
805
- } else if (isContainer(element)) {
806
- const nextId = isContainerNode(element) ? getContainerId(element) : element;
807
- return getContainerFocusTarget(nextId);
808
- }
809
-
810
- return element;
811
- }, null) || null;
812
- }
813
902
 
814
- function getContainerPreviousTarget (containerId, direction, destination) {
815
- const config = getContainerConfig(containerId);
816
-
817
- if (config &&
818
- config.rememberSource &&
819
- config.previous &&
820
- config.previous.reverse === direction &&
821
- config.previous.destination === destination
822
- ) {
823
- return config.previous.target;
824
- }
903
+
904
+ function getContainerFocusTarget(containerId, preferredEnterTo) {
905
+ // deferring restoration until it's requested to allow containers to prepare first
906
+ restoreLastFocusedElement(containerId);
907
+ var next = getContainerNavigableElements(containerId, preferredEnterTo); // If multiple candidates returned, we need to find the first viable target since some may
908
+ // be empty containers which should be skipped.
909
+
910
+ return next.reduce(function (result, element) {
911
+ if (result) {
912
+ return result;
913
+ } else if (isContainer(element)) {
914
+ var nextId = isContainerNode(element) ? getContainerId(element) : element;
915
+ return getContainerFocusTarget(nextId);
916
+ }
917
+
918
+ return element;
919
+ }, null) || null;
825
920
  }
826
921
 
827
- function setContainerPreviousTarget (containerId, direction, destination, target) {
828
- const config = getContainerConfig(containerId);
829
-
830
- if (config && config.rememberSource) {
831
- configureContainer(containerId, {
832
- previous: {
833
- target,
834
- destination,
835
- reverse: reverseDirections[direction]
836
- }
837
- });
838
- }
922
+ function getContainerPreviousTarget(containerId, direction, destination) {
923
+ var config = getContainerConfig(containerId);
924
+
925
+ if (config && config.rememberSource && config.previous && config.previous.reverse === direction && config.previous.destination === destination) {
926
+ return config.previous.target;
927
+ }
839
928
  }
840
929
 
930
+ function setContainerPreviousTarget(containerId, direction, destination, target) {
931
+ var config = getContainerConfig(containerId);
932
+
933
+ if (config && config.rememberSource) {
934
+ configureContainer(containerId, {
935
+ previous: {
936
+ target: target,
937
+ destination: destination,
938
+ reverse: reverseDirections[direction]
939
+ }
940
+ });
941
+ }
942
+ }
841
943
  /**
842
944
  * Saves the last focused element into `lastFocusedKey` using a container-defined serialization
843
945
  * method configured in `lastFocusedPersist`.
@@ -848,21 +950,23 @@ function setContainerPreviousTarget (containerId, direction, destination, target
848
950
  * @memberof spotlight/container
849
951
  * @public
850
952
  */
851
- function persistLastFocusedElement (containerId) {
852
- const cfg = getContainerConfig(containerId);
853
- if (cfg) {
854
- const {lastFocusedElement} = cfg;
855
- if (lastFocusedElement) {
856
- const all = getDeepSpottableDescendants(containerId);
857
- const lastFocusedKey = cfg.lastFocusedPersist(lastFocusedElement, all);
858
-
859
- // store lastFocusedKey and release node reference to lastFocusedElement
860
- cfg.lastFocusedKey = lastFocusedKey;
861
- cfg.lastFocusedElement = null;
862
- }
863
- }
864
- }
865
953
 
954
+
955
+ function persistLastFocusedElement(containerId) {
956
+ var cfg = getContainerConfig(containerId);
957
+
958
+ if (cfg) {
959
+ var lastFocusedElement = cfg.lastFocusedElement;
960
+
961
+ if (lastFocusedElement) {
962
+ var all = getDeepSpottableDescendants(containerId);
963
+ var lastFocusedKey = cfg.lastFocusedPersist(lastFocusedElement, all); // store lastFocusedKey and release node reference to lastFocusedElement
964
+
965
+ cfg.lastFocusedKey = lastFocusedKey;
966
+ cfg.lastFocusedElement = null;
967
+ }
968
+ }
969
+ }
866
970
  /**
867
971
  * Restores the last focused element from `lastFocusedKey` using a container-defined deserialization
868
972
  * method configured in `lastFocusedRestore`.
@@ -873,36 +977,37 @@ function persistLastFocusedElement (containerId) {
873
977
  * @memberof spotlight/container
874
978
  * @public
875
979
  */
876
- function restoreLastFocusedElement (containerId) {
877
- const cfg = getContainerConfig(containerId);
878
- if (cfg && cfg.lastFocusedKey) {
879
- const all = getDeepSpottableDescendants(containerId);
880
- const lastFocusedElement = cfg.lastFocusedRestore(cfg.lastFocusedKey, all);
881
-
882
- // restore lastFocusedElement and release lastFocusedKey
883
- cfg.lastFocusedKey = null;
884
- cfg.lastFocusedElement = lastFocusedElement;
885
- }
886
- }
887
980
 
888
- function unmountContainer (containerId) {
889
- const config = getContainerConfig(containerId);
890
981
 
891
- if (config) {
892
- config.active = false;
893
- persistLastFocusedElement(containerId);
982
+ function restoreLastFocusedElement(containerId) {
983
+ var cfg = getContainerConfig(containerId);
984
+
985
+ if (cfg && cfg.lastFocusedKey) {
986
+ var all = getDeepSpottableDescendants(containerId);
987
+ var lastFocusedElement = cfg.lastFocusedRestore(cfg.lastFocusedKey, all); // restore lastFocusedElement and release lastFocusedKey
894
988
 
895
- if (typeof config.defaultElement !== 'string') {
896
- config.defaultElement = null;
897
- }
898
- }
989
+ cfg.lastFocusedKey = null;
990
+ cfg.lastFocusedElement = lastFocusedElement;
991
+ }
899
992
  }
900
993
 
901
- function isActiveContainer (containerId) {
902
- const config = getContainerConfig(containerId);
903
- return config && config.active;
994
+ function unmountContainer(containerId) {
995
+ var config = getContainerConfig(containerId);
996
+
997
+ if (config) {
998
+ config.active = false;
999
+ persistLastFocusedElement(containerId);
1000
+
1001
+ if (typeof config.defaultElement !== 'string') {
1002
+ config.defaultElement = null;
1003
+ }
1004
+ }
904
1005
  }
905
1006
 
1007
+ function isActiveContainer(containerId) {
1008
+ var config = getContainerConfig(containerId);
1009
+ return config && config.active;
1010
+ }
906
1011
  /**
907
1012
  * Determines if the provided container has a configured restriction.
908
1013
  *
@@ -914,12 +1019,13 @@ function isActiveContainer (containerId) {
914
1019
  * @returns {Boolean} `true` if the container has the specified restriction
915
1020
  * @private
916
1021
  */
917
- function isRestrictedContainer (containerId, restrict = 'self-only') {
918
- const config = getContainerConfig(containerId);
919
1022
 
920
- return Boolean(config && config.restrict === restrict);
921
- }
922
1023
 
1024
+ function isRestrictedContainer(containerId) {
1025
+ var restrict = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'self-only';
1026
+ var config = getContainerConfig(containerId);
1027
+ return Boolean(config && config.restrict === restrict);
1028
+ }
923
1029
  /**
924
1030
  * Determines if `innerContainerId` is inside `outerContainerId`.
925
1031
  *
@@ -929,13 +1035,13 @@ function isRestrictedContainer (containerId, restrict = 'self-only') {
929
1035
  * `outerContainerId`
930
1036
  * @private
931
1037
  */
932
- function containsContainer (outerContainerId, innerContainerId) {
933
- const outer = getContainerNode(outerContainerId);
934
- const inner = getContainerNode(innerContainerId);
935
1038
 
936
- return Boolean(outer && inner && outer.contains(inner));
937
- }
938
1039
 
1040
+ function containsContainer(outerContainerId, innerContainerId) {
1041
+ var outer = getContainerNode(outerContainerId);
1042
+ var inner = getContainerNode(innerContainerId);
1043
+ return Boolean(outer && inner && outer.contains(inner));
1044
+ }
939
1045
  /**
940
1046
  * Determines if `containerId` may become the active container.
941
1047
  *
@@ -943,40 +1049,37 @@ function containsContainer (outerContainerId, innerContainerId) {
943
1049
  * @returns {Boolean} `true` if the active container can change to `containerId`
944
1050
  * @private
945
1051
  */
946
- function mayActivateContainer (containerId) {
947
- const currentContainerId = getLastContainer();
948
-
949
- // If the current container is restricted to 'self-only' and if the next container to be
950
- // activated is not inside the currently activated container, the next container should not be
951
- // activated.
952
- return (
953
- !isRestrictedContainer(currentContainerId) ||
954
- containsContainer(currentContainerId, containerId)
955
- );
956
- }
957
1052
 
958
- function getDefaultContainer () {
959
- return isActiveContainer(_defaultContainerId) ? _defaultContainerId : '';
1053
+
1054
+ function mayActivateContainer(containerId) {
1055
+ var currentContainerId = getLastContainer(); // If the current container is restricted to 'self-only' and if the next container to be
1056
+ // activated is not inside the currently activated container, the next container should not be
1057
+ // activated.
1058
+
1059
+ return !isRestrictedContainer(currentContainerId) || containsContainer(currentContainerId, containerId);
960
1060
  }
961
1061
 
962
- function setDefaultContainer (containerId) {
963
- if (!containerId) {
964
- _defaultContainerId = '';
965
- } else if (!getContainerConfig(containerId)) {
966
- throw new Error('Container "' + containerId + '" doesn\'t exist!');
967
- } else {
968
- _defaultContainerId = containerId;
969
- }
1062
+ function getDefaultContainer() {
1063
+ return isActiveContainer(_defaultContainerId) ? _defaultContainerId : '';
970
1064
  }
971
1065
 
972
- function getLastContainer () {
973
- return isActiveContainer(_lastContainerId) ? _lastContainerId : '';
1066
+ function setDefaultContainer(containerId) {
1067
+ if (!containerId) {
1068
+ _defaultContainerId = '';
1069
+ } else if (!getContainerConfig(containerId)) {
1070
+ throw new Error('Container "' + containerId + '" doesn\'t exist!');
1071
+ } else {
1072
+ _defaultContainerId = containerId;
1073
+ }
974
1074
  }
975
1075
 
976
- function setLastContainer (containerId) {
977
- _lastContainerId = containerId || '';
1076
+ function getLastContainer() {
1077
+ return isActiveContainer(_lastContainerId) ? _lastContainerId : '';
978
1078
  }
979
1079
 
1080
+ function setLastContainer(containerId) {
1081
+ _lastContainerId = containerId || '';
1082
+ }
980
1083
  /**
981
1084
  * Updates the last container based on the current focus and target focus.
982
1085
  *
@@ -985,36 +1088,38 @@ function setLastContainer (containerId) {
985
1088
  * @memberof spotlight/container
986
1089
  * @public
987
1090
  */
988
- function setLastContainerFromTarget (current, target) {
989
- const currentContainers = getNavigableContainersForNode(current);
990
- const currentOuterContainerId = currentContainers[0];
991
- const currentContainerConfig = getContainerConfig(currentOuterContainerId);
992
- const targetContainers = getContainersForNode(target);
993
- const targetInnerContainer = last(targetContainers);
994
-
995
- const sharedContainer = last(intersection(currentContainers, targetContainers));
996
-
997
- if (sharedContainer || !currentContainerConfig || currentContainerConfig.restrict !== 'self-only') {
998
- // If the target shares a container with the current container stack or the current
999
- // element isn't within a self-only container, use the target's nearest container
1000
- setLastContainer(targetInnerContainer);
1001
- } else {
1002
- // Otherwise, the target is not within the current container stack and the current
1003
- // element was within a 'self-only' container, use the current's outer container
1004
- setLastContainer(currentOuterContainerId);
1005
- }
1006
- }
1007
1091
 
1008
- function isWithinOverflowContainer (target, containerIds = getContainersForNode(target)) {
1009
- return containerIds
1010
- // ignore the root container id which is set to overflow by the root decorator
1011
- .filter(id => id !== rootContainerId)
1012
- // get the config for each container
1013
- .map(getContainerConfig)
1014
- // and check if any are set to overflow
1015
- .some(config => config && config.overflow);
1092
+
1093
+ function setLastContainerFromTarget(current, target) {
1094
+ var currentContainers = getNavigableContainersForNode(current);
1095
+ var currentOuterContainerId = currentContainers[0];
1096
+ var currentContainerConfig = getContainerConfig(currentOuterContainerId);
1097
+ var targetContainers = getContainersForNode(target);
1098
+ var targetInnerContainer = (0, _last["default"])(targetContainers);
1099
+ var sharedContainer = (0, _last["default"])((0, _intersection["default"])(currentContainers, targetContainers));
1100
+
1101
+ if (sharedContainer || !currentContainerConfig || currentContainerConfig.restrict !== 'self-only') {
1102
+ // If the target shares a container with the current container stack or the current
1103
+ // element isn't within a self-only container, use the target's nearest container
1104
+ setLastContainer(targetInnerContainer);
1105
+ } else {
1106
+ // Otherwise, the target is not within the current container stack and the current
1107
+ // element was within a 'self-only' container, use the current's outer container
1108
+ setLastContainer(currentOuterContainerId);
1109
+ }
1016
1110
  }
1017
1111
 
1112
+ function isWithinOverflowContainer(target) {
1113
+ var containerIds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getContainersForNode(target);
1114
+ return containerIds // ignore the root container id which is set to overflow by the root decorator
1115
+ .filter(function (id) {
1116
+ return id !== rootContainerId;
1117
+ }) // get the config for each container
1118
+ .map(getContainerConfig) // and check if any are set to overflow
1119
+ .some(function (config) {
1120
+ return config && config.overflow;
1121
+ });
1122
+ }
1018
1123
  /**
1019
1124
  * Notifies any affected containers that focus has left one of their children for another container
1020
1125
  *
@@ -1025,23 +1130,24 @@ function isWithinOverflowContainer (target, containerIds = getContainersForNode(
1025
1130
  * @param {String[]} nextContainerIds Containers for next
1026
1131
  * @private
1027
1132
  */
1028
- function notifyLeaveContainer (direction, current, currentContainerIds, next, nextContainerIds) {
1029
- currentContainerIds.forEach(containerId => {
1030
- if (!nextContainerIds.includes(containerId)) {
1031
- const config = getContainerConfig(containerId);
1032
-
1033
- if (config && config.onLeaveContainer) {
1034
- config.onLeaveContainer({
1035
- type: 'onLeaveContainer',
1036
- direction,
1037
- target: current,
1038
- relatedTarget: next
1039
- });
1040
- }
1041
- }
1042
- });
1043
- }
1044
1133
 
1134
+
1135
+ function notifyLeaveContainer(direction, current, currentContainerIds, next, nextContainerIds) {
1136
+ currentContainerIds.forEach(function (containerId) {
1137
+ if (!nextContainerIds.includes(containerId)) {
1138
+ var config = getContainerConfig(containerId);
1139
+
1140
+ if (config && config.onLeaveContainer) {
1141
+ config.onLeaveContainer({
1142
+ type: 'onLeaveContainer',
1143
+ direction: direction,
1144
+ target: current,
1145
+ relatedTarget: next
1146
+ });
1147
+ }
1148
+ }
1149
+ });
1150
+ }
1045
1151
  /**
1046
1152
  * Notifies any containers that focus attempted to move but failed to find a target
1047
1153
  *
@@ -1050,20 +1156,21 @@ function notifyLeaveContainer (direction, current, currentContainerIds, next, ne
1050
1156
  * @param {String[]} currentContainerIds Containers for current
1051
1157
  * @private
1052
1158
  */
1053
- function notifyLeaveContainerFail (direction, current, currentContainerIds) {
1054
- currentContainerIds.forEach(containerId => {
1055
- const config = getContainerConfig(containerId);
1056
-
1057
- if (config && config.onLeaveContainerFail) {
1058
- config.onLeaveContainerFail({
1059
- type: 'onLeaveContainerFail',
1060
- direction,
1061
- target: current
1062
- });
1063
- }
1064
- });
1065
- }
1066
1159
 
1160
+
1161
+ function notifyLeaveContainerFail(direction, current, currentContainerIds) {
1162
+ currentContainerIds.forEach(function (containerId) {
1163
+ var config = getContainerConfig(containerId);
1164
+
1165
+ if (config && config.onLeaveContainerFail) {
1166
+ config.onLeaveContainerFail({
1167
+ type: 'onLeaveContainerFail',
1168
+ direction: direction,
1169
+ target: current
1170
+ });
1171
+ }
1172
+ });
1173
+ }
1067
1174
  /**
1068
1175
  * Notifies any affected containers that one of their children has received focus.
1069
1176
  *
@@ -1074,63 +1181,21 @@ function notifyLeaveContainerFail (direction, current, currentContainerIds) {
1074
1181
  * @param {String[]} currentContainerIds Containers for current
1075
1182
  * @private
1076
1183
  */
1077
- function notifyEnterContainer (direction, previous, previousContainerIds, current, currentContainerIds) {
1078
- currentContainerIds.forEach(containerId => {
1079
- if (!previousContainerIds.includes(containerId)) {
1080
- const config = getContainerConfig(containerId);
1081
-
1082
- if (config && config.onEnterContainer) {
1083
- config.onEnterContainer({
1084
- type: 'onEnterContainer',
1085
- direction,
1086
- target: current,
1087
- relatedTarget: previous
1088
- });
1089
- }
1090
- }
1091
- });
1092
- }
1093
1184
 
1094
- export {
1095
- // Remove
1096
- getAllContainerIds,
1097
- getContainerNode,
1098
-
1099
- // Maybe
1100
- getContainerConfig,
1101
- getContainerDefaultElement,
1102
- getContainerLastFocusedElement,
1103
- getContainerNavigableElements,
1104
- getContainersForNode,
1105
- isContainer5WayHoldable,
1106
- setContainerLastFocusedElement,
1107
-
1108
- // Keep
1109
- addContainer,
1110
- containerAttribute,
1111
- configureDefaults,
1112
- configureContainer,
1113
- getContainerFocusTarget,
1114
- getContainerId,
1115
- getContainerPreviousTarget,
1116
- getDeepSpottableDescendants,
1117
- getDefaultContainer,
1118
- getLastContainer,
1119
- getNavigableContainersForNode,
1120
- getSpottableDescendants,
1121
- isContainer,
1122
- isNavigable,
1123
- isWithinOverflowContainer,
1124
- mayActivateContainer,
1125
- notifyLeaveContainer,
1126
- notifyLeaveContainerFail,
1127
- notifyEnterContainer,
1128
- removeAllContainers,
1129
- removeContainer,
1130
- rootContainerId,
1131
- setContainerPreviousTarget,
1132
- setDefaultContainer,
1133
- setLastContainer,
1134
- setLastContainerFromTarget,
1135
- unmountContainer
1136
- };
1185
+
1186
+ function notifyEnterContainer(direction, previous, previousContainerIds, current, currentContainerIds) {
1187
+ currentContainerIds.forEach(function (containerId) {
1188
+ if (!previousContainerIds.includes(containerId)) {
1189
+ var config = getContainerConfig(containerId);
1190
+
1191
+ if (config && config.onEnterContainer) {
1192
+ config.onEnterContainer({
1193
+ type: 'onEnterContainer',
1194
+ direction: direction,
1195
+ target: current,
1196
+ relatedTarget: previous
1197
+ });
1198
+ }
1199
+ }
1200
+ });
1201
+ }