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