@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.
- package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
- package/Accelerator/Accelerator.js +149 -156
- package/CHANGELOG.md +22 -0
- package/{build/Pause → Pause}/Pause.d.ts +0 -0
- package/Pause/Pause.js +102 -80
- package/Pause/tests/Pause-specs.js +65 -97
- package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
- package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
- package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
- package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
- package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
- package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
- package/Spottable/Spottable.js +448 -410
- package/Spottable/tests/Spottable-specs.js +90 -117
- package/package.json +3 -2
- package/src/container.js +718 -653
- package/src/navigate.js +406 -491
- package/src/pointer.js +86 -78
- package/{build/src → src}/spotlight.d.ts +0 -0
- package/src/spotlight.js +846 -885
- package/src/target.js +448 -474
- package/src/tests/container-specs.js +643 -1251
- package/src/tests/navigate-specs.js +77 -134
- package/src/tests/pointer-specs.js +126 -182
- package/src/tests/spotlight-specs.js +103 -133
- package/src/tests/target-specs.js +597 -960
- package/src/tests/utils.js +89 -67
- package/src/utils.js +155 -158
- package/build/Accelerator/Accelerator.js +0 -162
- package/build/Accelerator/package.json +0 -3
- package/build/CHANGELOG.md +0 -838
- package/build/Pause/Pause.js +0 -164
- package/build/Pause/package.json +0 -3
- package/build/Pause/tests/Pause-specs.js +0 -65
- package/build/README.md +0 -61
- package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
- package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
- package/build/SpotlightContainerDecorator/package.json +0 -3
- package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
- package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
- package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
- package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
- package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
- package/build/SpotlightRootDecorator/package.json +0 -3
- package/build/Spottable/Spottable.js +0 -491
- package/build/Spottable/package.json +0 -3
- package/build/Spottable/tests/Spottable-specs.js +0 -90
- package/build/package-lock.json +0 -229
- package/build/package.json +0 -28
- package/build/src/container.js +0 -1201
- package/build/src/navigate.js +0 -419
- package/build/src/pointer.js +0 -183
- package/build/src/spotlight.js +0 -896
- package/build/src/target.js +0 -507
- package/build/src/tests/container-specs.js +0 -653
- package/build/src/tests/navigate-specs.js +0 -87
- package/build/src/tests/pointer-specs.js +0 -130
- package/build/src/tests/spotlight-specs.js +0 -112
- package/build/src/tests/target-specs.js +0 -614
- package/build/src/tests/utils.js +0 -104
- package/build/src/utils.js +0 -180
- package/build/styles/debug.less +0 -97
- package/build/styles/mixins.less +0 -63
- package/docs/index.md +0 -364
package/build/src/container.js
DELETED
|
@@ -1,1201 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
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; }
|
|
45
|
-
|
|
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; }
|
|
47
|
-
|
|
48
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
49
|
-
|
|
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:
|
|
79
|
-
// - a valid selector string for "querySelectorAll"
|
|
80
|
-
// - a NodeList or an array containing DOM elements
|
|
81
|
-
// - a single DOM element
|
|
82
|
-
// - a string "@<containerId>" to indicate the specified container
|
|
83
|
-
// - a string "@" to indicate the default container
|
|
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
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Calculates nodes within `node` that match `includeSelector` and do not match `excludeSelector`
|
|
134
|
-
*
|
|
135
|
-
* @param {Node} node DOM Node to query
|
|
136
|
-
* @param {String} includeSelector CSS selector of nodes to include
|
|
137
|
-
* @param {String} excludeSelector CSS selector for nodes to exclude
|
|
138
|
-
*
|
|
139
|
-
* @returns {Node[]} Array of nodes
|
|
140
|
-
* @memberof spotlight/container
|
|
141
|
-
* @private
|
|
142
|
-
*/
|
|
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
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* Determines if `node` is a spotlight container
|
|
160
|
-
*
|
|
161
|
-
* @param {Node} node Node to check
|
|
162
|
-
*
|
|
163
|
-
* @returns {Boolean} `true` if `node` is a spotlight container
|
|
164
|
-
* @memberof spotlight/container
|
|
165
|
-
* @private
|
|
166
|
-
*/
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
var isContainerNode = function isContainerNode(node) {
|
|
170
|
-
return node && node.dataset && 'spotlightContainer' in node.dataset;
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Walks up the node hierarchy calling `fn` on each node that is a container
|
|
174
|
-
*
|
|
175
|
-
* @param {Node} node Node from which to start the search
|
|
176
|
-
* @param {Function} fn Called once for each container with the container node as the first
|
|
177
|
-
* argument. The return value is accumulated in the array returned by
|
|
178
|
-
* `mapContainers`
|
|
179
|
-
*
|
|
180
|
-
* @returns {Array} Array of values returned by `fn` in order of outermost container to
|
|
181
|
-
* innermost container
|
|
182
|
-
* @memberof spotlight/container
|
|
183
|
-
* @private
|
|
184
|
-
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
var mapContainers = function mapContainers(node, fn) {
|
|
188
|
-
var result = [];
|
|
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
|
-
};
|
|
200
|
-
/**
|
|
201
|
-
* Returns the container config for `containerId`
|
|
202
|
-
*
|
|
203
|
-
* @param {String} id Container ID
|
|
204
|
-
*
|
|
205
|
-
* @returns {Object} Container config
|
|
206
|
-
* @memberof spotlight/container
|
|
207
|
-
* @private
|
|
208
|
-
*/
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
var getContainerConfig = function getContainerConfig(id) {
|
|
212
|
-
return containerConfigs.get(id);
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* Determines if node or a container id represents a spotlight container
|
|
216
|
-
*
|
|
217
|
-
* @param {Node|String} nodeOrId Node or container ID
|
|
218
|
-
*
|
|
219
|
-
* @returns {Boolean} `true` if `nodeOrId` represents a spotlight container
|
|
220
|
-
* @memberof spotlight/container
|
|
221
|
-
* @private
|
|
222
|
-
*/
|
|
223
|
-
|
|
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
|
-
};
|
|
234
|
-
/**
|
|
235
|
-
* Determines if any of the containers at or above `node` are disabled and, if so, returns `false`.
|
|
236
|
-
*
|
|
237
|
-
* @param {Node} node Spottable node or spotlight container
|
|
238
|
-
*
|
|
239
|
-
* @returns {Boolean} `true` if all container ancestors are enabled
|
|
240
|
-
* @memberof spotlight/container
|
|
241
|
-
* @private
|
|
242
|
-
*/
|
|
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
|
-
};
|
|
252
|
-
/**
|
|
253
|
-
* Returns the container ID for `node`
|
|
254
|
-
*
|
|
255
|
-
* @param {Node} node Container Node
|
|
256
|
-
*
|
|
257
|
-
* @returns {String} Container ID
|
|
258
|
-
* @memberof spotlight/container
|
|
259
|
-
* @private
|
|
260
|
-
*/
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
var getContainerId = function getContainerId(node) {
|
|
264
|
-
return node.dataset[containerKey];
|
|
265
|
-
};
|
|
266
|
-
/**
|
|
267
|
-
* Generates a CSS selector string for a current container if `node` is a container
|
|
268
|
-
*
|
|
269
|
-
* @param {Node} node Container Node
|
|
270
|
-
*
|
|
271
|
-
* @returns {String} CSS selector
|
|
272
|
-
* @memberof spotlight/container
|
|
273
|
-
* @private
|
|
274
|
-
*/
|
|
275
|
-
|
|
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
|
-
};
|
|
286
|
-
/**
|
|
287
|
-
* Generates a CSS selector string for containers within `node` if it is a container
|
|
288
|
-
*
|
|
289
|
-
* @param {Node} node Container Node
|
|
290
|
-
*
|
|
291
|
-
* @returns {String} CSS selector
|
|
292
|
-
* @memberof spotlight/container
|
|
293
|
-
* @private
|
|
294
|
-
*/
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
var getSubContainerSelector = function getSubContainerSelector(node) {
|
|
298
|
-
if (isContainerNode(node)) {
|
|
299
|
-
return "".concat(getContainerSelector(node), " ").concat(containerSelector);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
return containerSelector;
|
|
303
|
-
};
|
|
304
|
-
/**
|
|
305
|
-
* Returns the node for a container
|
|
306
|
-
*
|
|
307
|
-
* @param {String} containerId ID of container
|
|
308
|
-
*
|
|
309
|
-
* @returns {Node} DOM node of the container
|
|
310
|
-
* @memberof spotlight/container
|
|
311
|
-
* @private
|
|
312
|
-
*/
|
|
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
|
-
};
|
|
324
|
-
/**
|
|
325
|
-
* Calls the `navigableFilter` function for the container if defined.
|
|
326
|
-
*
|
|
327
|
-
* @param {Node} node DOM node to check if it is navigable
|
|
328
|
-
* @param {String} containerId ID of container
|
|
329
|
-
*
|
|
330
|
-
* @returns {Boolean} `true` if it passes the `navigableFilter` method or if that
|
|
331
|
-
* method is not defined for the container
|
|
332
|
-
* @memberof spotlight/container
|
|
333
|
-
* @private
|
|
334
|
-
*/
|
|
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
|
-
};
|
|
350
|
-
/**
|
|
351
|
-
* Determines nodes that are owned by `node` based on `aria-owns`.
|
|
352
|
-
*
|
|
353
|
-
* @param {Node} node Owner
|
|
354
|
-
*
|
|
355
|
-
* @returns {Node[]} Array of owned nodes
|
|
356
|
-
* @memberof spotlight/container
|
|
357
|
-
* @private
|
|
358
|
-
*/
|
|
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
|
-
};
|
|
376
|
-
/**
|
|
377
|
-
* Determines all spottable elements and containers that are directly contained by the container
|
|
378
|
-
* identified by `containerId` and no other subcontainers.
|
|
379
|
-
*
|
|
380
|
-
* @param {String} containerId ID of container
|
|
381
|
-
*
|
|
382
|
-
* @returns {Node[]} Array of spottable elements and containers.
|
|
383
|
-
* @memberof spotlight/container
|
|
384
|
-
* @public
|
|
385
|
-
*/
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
var getSpottableDescendants = function getSpottableDescendants(containerId) {
|
|
389
|
-
var node = getContainerNode(containerId); // if it's falsy or is a disabled container, return an empty set
|
|
390
|
-
|
|
391
|
-
if (!node || isContainerNode(node) && !isContainerEnabled(node)) {
|
|
392
|
-
return [];
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
var _ref2 = getContainerConfig(containerId) || {},
|
|
396
|
-
selector = _ref2.selector,
|
|
397
|
-
selectorDisabled = _ref2.selectorDisabled;
|
|
398
|
-
|
|
399
|
-
if (!selector || selectorDisabled) {
|
|
400
|
-
return [];
|
|
401
|
-
}
|
|
402
|
-
|
|
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
|
-
});
|
|
410
|
-
};
|
|
411
|
-
/**
|
|
412
|
-
* Recursively get spottable descendants by including elements within sub-containers that do not
|
|
413
|
-
* have `enterTo` configured
|
|
414
|
-
*
|
|
415
|
-
* @param {String} containerId ID of container
|
|
416
|
-
* @param {String[]} [excludedContainers] IDs of containers to exclude from result set
|
|
417
|
-
*
|
|
418
|
-
* @returns {Node[]} Array of spottable elements and containers
|
|
419
|
-
* @memberof spotlight/container
|
|
420
|
-
* @private
|
|
421
|
-
*/
|
|
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
|
-
};
|
|
442
|
-
/**
|
|
443
|
-
* Determines if a container allows 5-way key hold to be preserved or not.
|
|
444
|
-
*
|
|
445
|
-
* @param {String} containerId Container Id
|
|
446
|
-
* @returns {Boolean} `true` if a container is 5 way holdable
|
|
447
|
-
* @memberof spotlight/container
|
|
448
|
-
* @private
|
|
449
|
-
*/
|
|
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
|
-
};
|
|
458
|
-
/**
|
|
459
|
-
* Returns an array of ids for containers that wrap the element, in order of outer-to-inner, with
|
|
460
|
-
* the last array item being the immediate container id of the element.
|
|
461
|
-
*
|
|
462
|
-
* @param {Node} node Node from which to start the search
|
|
463
|
-
*
|
|
464
|
-
* @returns {String[]} Array on container IDs
|
|
465
|
-
* @memberof spotlight/container
|
|
466
|
-
* @private
|
|
467
|
-
*/
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
exports.isContainer5WayHoldable = isContainer5WayHoldable;
|
|
471
|
-
|
|
472
|
-
function getContainersForNode(node) {
|
|
473
|
-
var containers = mapContainers(node, getContainerId);
|
|
474
|
-
containers.unshift(rootContainerId);
|
|
475
|
-
return containers;
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* Returns an array of ids for containers that wrap the element, in order of outer-to-inner, with
|
|
479
|
-
* the last array item being the immediate container id of the element. The container ids are
|
|
480
|
-
* limited to only those between `node` and the first restrict="self-only" container.
|
|
481
|
-
*
|
|
482
|
-
* @param {Node} node Node from which to start the search
|
|
483
|
-
*
|
|
484
|
-
* @returns {String[]} Array on container IDs
|
|
485
|
-
* @memberof spotlight/container
|
|
486
|
-
* @private
|
|
487
|
-
*/
|
|
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
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Generates a new unique identifier for a container
|
|
511
|
-
*
|
|
512
|
-
* @returns {String} Container ID
|
|
513
|
-
* @memberof spotlight/container
|
|
514
|
-
* @private
|
|
515
|
-
*/
|
|
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
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Merges two container configurations while only allowing keys from `updated` which are defined in
|
|
534
|
-
* `GlobalConfig`
|
|
535
|
-
*
|
|
536
|
-
* @param {Object} current Current container configuration
|
|
537
|
-
* @param {Object} updated Updated configuration which may only be a partial configuration
|
|
538
|
-
*
|
|
539
|
-
* @returns {Object} Merged configuration
|
|
540
|
-
* @memberof spotlight/container
|
|
541
|
-
* @private
|
|
542
|
-
*/
|
|
543
|
-
|
|
544
|
-
|
|
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
|
-
}
|
|
553
|
-
|
|
554
|
-
cfg[key] = updated[key];
|
|
555
|
-
}
|
|
556
|
-
});
|
|
557
|
-
return cfg || current;
|
|
558
|
-
};
|
|
559
|
-
/**
|
|
560
|
-
* Adds or updates a container. When a container id is not specified, it will be generated.
|
|
561
|
-
*
|
|
562
|
-
* @param {String|Object} containerIdOrConfig Either a string container id or a configuration
|
|
563
|
-
* object.
|
|
564
|
-
* @param {Object} [config] Container configuration when `containerIdOrConfig`
|
|
565
|
-
* is a string. When omitted, the container will have
|
|
566
|
-
* the default `GlobalConfig`.
|
|
567
|
-
*
|
|
568
|
-
* @returns {String} The container id
|
|
569
|
-
* @memberof spotlight/container
|
|
570
|
-
* @public
|
|
571
|
-
*/
|
|
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
|
-
};
|
|
596
|
-
/**
|
|
597
|
-
* Adds a container and marks it active. When a container id is not specified, it will be generated.
|
|
598
|
-
*
|
|
599
|
-
* @param {String|Object} containerIdOrConfig Either a string container id or a configuration
|
|
600
|
-
* object.
|
|
601
|
-
* @param {Object} [config] Container configuration when `containerIdOrConfig`
|
|
602
|
-
* is a string. When omitted, the container will have
|
|
603
|
-
* the default `GlobalConfig`.
|
|
604
|
-
*
|
|
605
|
-
* @returns {String} The container id
|
|
606
|
-
* @memberof spotlight/container
|
|
607
|
-
* @public
|
|
608
|
-
*/
|
|
609
|
-
|
|
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
|
-
};
|
|
619
|
-
/**
|
|
620
|
-
* Removes a container
|
|
621
|
-
*
|
|
622
|
-
* @param {String} containerId ID of the container to remove
|
|
623
|
-
*
|
|
624
|
-
* @returns {undefined}
|
|
625
|
-
* @memberof spotlight/container
|
|
626
|
-
* @public
|
|
627
|
-
*/
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
exports.addContainer = addContainer;
|
|
631
|
-
|
|
632
|
-
var removeContainer = function removeContainer(containerId) {
|
|
633
|
-
containerConfigs["delete"](containerId);
|
|
634
|
-
};
|
|
635
|
-
/**
|
|
636
|
-
* Removes all containers
|
|
637
|
-
*
|
|
638
|
-
* @returns {undefined}
|
|
639
|
-
* @memberof spotlight/container
|
|
640
|
-
* @public
|
|
641
|
-
*/
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
exports.removeContainer = removeContainer;
|
|
645
|
-
|
|
646
|
-
var removeAllContainers = function removeAllContainers() {
|
|
647
|
-
containerConfigs.clear();
|
|
648
|
-
};
|
|
649
|
-
/**
|
|
650
|
-
* Configures the `GlobalConfig` for containers
|
|
651
|
-
*
|
|
652
|
-
* @param {Object} config New global configuration. Cannot introduce new keys
|
|
653
|
-
*
|
|
654
|
-
* @returns {undefined}
|
|
655
|
-
* @memberof spotlight/container
|
|
656
|
-
* @public
|
|
657
|
-
*/
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
exports.removeAllContainers = removeAllContainers;
|
|
661
|
-
|
|
662
|
-
var configureDefaults = function configureDefaults(config) {
|
|
663
|
-
GlobalConfig = mergeConfig(GlobalConfig, config);
|
|
664
|
-
};
|
|
665
|
-
/**
|
|
666
|
-
* Determines if `node` is a navigable element within the container identified by `containerId`.
|
|
667
|
-
*
|
|
668
|
-
* @param {Node} node DOM node to check if it is navigable
|
|
669
|
-
* @param {String} containerId ID of the container containing `node`
|
|
670
|
-
* @param {Boolean} verify `true` to verify the node matches the container's `selector`
|
|
671
|
-
*
|
|
672
|
-
* @returns {Boolean} `true` if `node` is navigable
|
|
673
|
-
* @memberof spotlight/container
|
|
674
|
-
* @public
|
|
675
|
-
*/
|
|
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
|
-
};
|
|
700
|
-
/**
|
|
701
|
-
* Returns the IDs of all containers
|
|
702
|
-
*
|
|
703
|
-
* @returns {String[]} Array of container IDs
|
|
704
|
-
* @memberof spotlight/container
|
|
705
|
-
* @private
|
|
706
|
-
*/
|
|
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
|
-
};
|
|
725
|
-
/**
|
|
726
|
-
* Returns the default focus element for a container
|
|
727
|
-
*
|
|
728
|
-
* @param {String} containerId ID of container
|
|
729
|
-
* @param {('last-focused'|'default-element')} [preferredEnterTo] Prefer the given enterTo
|
|
730
|
-
* configuration
|
|
731
|
-
*
|
|
732
|
-
* @returns {Node|null} Default focus element
|
|
733
|
-
* @memberof spotlight/container
|
|
734
|
-
* @public
|
|
735
|
-
*/
|
|
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
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* Gets the element last focused within the container.
|
|
773
|
-
*
|
|
774
|
-
* @param {String} containerId ID of container
|
|
775
|
-
*
|
|
776
|
-
* @returns {Node|String|null} DOM Node last focused
|
|
777
|
-
* @memberof spotlight/container
|
|
778
|
-
* @public
|
|
779
|
-
*/
|
|
780
|
-
|
|
781
|
-
|
|
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
|
|
788
|
-
|
|
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
|
-
}
|
|
799
|
-
/**
|
|
800
|
-
* Sets the element last focused within the container
|
|
801
|
-
*
|
|
802
|
-
* @param {Node} node DOM node last focused
|
|
803
|
-
* @param {String[]} containerId ID of container
|
|
804
|
-
*
|
|
805
|
-
* @returns {undefined}
|
|
806
|
-
* @memberof spotlight/container
|
|
807
|
-
* @public
|
|
808
|
-
*/
|
|
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
|
-
}
|
|
828
|
-
/**
|
|
829
|
-
* Returns all navigable nodes (spottable nodes or containers) visible from outside the container.
|
|
830
|
-
* If the container is restricting navigation into itself via `enterTo`, this method will attempt to
|
|
831
|
-
* return that element as the only element in an array. If that fails or if navigation is not
|
|
832
|
-
* restricted, it will return an array of all possible navigable nodes.
|
|
833
|
-
*
|
|
834
|
-
* @param {String} containerId Container ID
|
|
835
|
-
* @param {('last-focused'|'default-element')} [preferredEnterTo] Prefer the given enterTo
|
|
836
|
-
* configuration
|
|
837
|
-
*
|
|
838
|
-
* @returns {Node[]} Navigable elements within container
|
|
839
|
-
* @memberof spotlight/container
|
|
840
|
-
* @public
|
|
841
|
-
*/
|
|
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
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* Determines the preferred focus target, traversing any sub-containers as necessary, for the given
|
|
892
|
-
* container.
|
|
893
|
-
*
|
|
894
|
-
* @param {String} containerId ID of container
|
|
895
|
-
* @param {('last-focused'|'default-element')} [preferredEnterTo] Prefer the given enterTo
|
|
896
|
-
* configuration
|
|
897
|
-
*
|
|
898
|
-
* @returns {Node} Preferred target as either a DOM node or container-id
|
|
899
|
-
* @memberof spotlight/container
|
|
900
|
-
* @public
|
|
901
|
-
*/
|
|
902
|
-
|
|
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;
|
|
920
|
-
}
|
|
921
|
-
|
|
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
|
-
}
|
|
928
|
-
}
|
|
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
|
-
}
|
|
943
|
-
/**
|
|
944
|
-
* Saves the last focused element into `lastFocusedKey` using a container-defined serialization
|
|
945
|
-
* method configured in `lastFocusedPersist`.
|
|
946
|
-
*
|
|
947
|
-
* @param {String} containerId ID of container
|
|
948
|
-
*
|
|
949
|
-
* @returns {undefined}
|
|
950
|
-
* @memberof spotlight/container
|
|
951
|
-
* @public
|
|
952
|
-
*/
|
|
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
|
-
}
|
|
970
|
-
/**
|
|
971
|
-
* Restores the last focused element from `lastFocusedKey` using a container-defined deserialization
|
|
972
|
-
* method configured in `lastFocusedRestore`.
|
|
973
|
-
*
|
|
974
|
-
* @param {String} containerId ID of container
|
|
975
|
-
*
|
|
976
|
-
* @returns {undefined}
|
|
977
|
-
* @memberof spotlight/container
|
|
978
|
-
* @public
|
|
979
|
-
*/
|
|
980
|
-
|
|
981
|
-
|
|
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
|
|
988
|
-
|
|
989
|
-
cfg.lastFocusedKey = null;
|
|
990
|
-
cfg.lastFocusedElement = lastFocusedElement;
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
|
|
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
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
function isActiveContainer(containerId) {
|
|
1008
|
-
var config = getContainerConfig(containerId);
|
|
1009
|
-
return config && config.active;
|
|
1010
|
-
}
|
|
1011
|
-
/**
|
|
1012
|
-
* Determines if the provided container has a configured restriction.
|
|
1013
|
-
*
|
|
1014
|
-
* By default, returns `true` for `'self-only'` restrictions but the type of restriction can be
|
|
1015
|
-
* passed as well.
|
|
1016
|
-
*
|
|
1017
|
-
* @param {String} containerId The container id
|
|
1018
|
-
* @param {String} [restrict] The container restriction defaulted to `'self-only'`
|
|
1019
|
-
* @returns {Boolean} `true` if the container has the specified restriction
|
|
1020
|
-
* @private
|
|
1021
|
-
*/
|
|
1022
|
-
|
|
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
|
-
}
|
|
1029
|
-
/**
|
|
1030
|
-
* Determines if `innerContainerId` is inside `outerContainerId`.
|
|
1031
|
-
*
|
|
1032
|
-
* @param {String} outerContainerId The outer container id
|
|
1033
|
-
* @param {String} innerContainerId The inner container id
|
|
1034
|
-
* @returns {Boolean} `true` if both containers exist and `innerContainerId` is within
|
|
1035
|
-
* `outerContainerId`
|
|
1036
|
-
* @private
|
|
1037
|
-
*/
|
|
1038
|
-
|
|
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
|
-
}
|
|
1045
|
-
/**
|
|
1046
|
-
* Determines if `containerId` may become the active container.
|
|
1047
|
-
*
|
|
1048
|
-
* @param {String} containerId Spotlight container to which focus is leaving
|
|
1049
|
-
* @returns {Boolean} `true` if the active container can change to `containerId`
|
|
1050
|
-
* @private
|
|
1051
|
-
*/
|
|
1052
|
-
|
|
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);
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
function getDefaultContainer() {
|
|
1063
|
-
return isActiveContainer(_defaultContainerId) ? _defaultContainerId : '';
|
|
1064
|
-
}
|
|
1065
|
-
|
|
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
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
function getLastContainer() {
|
|
1077
|
-
return isActiveContainer(_lastContainerId) ? _lastContainerId : '';
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
function setLastContainer(containerId) {
|
|
1081
|
-
_lastContainerId = containerId || '';
|
|
1082
|
-
}
|
|
1083
|
-
/**
|
|
1084
|
-
* Updates the last container based on the current focus and target focus.
|
|
1085
|
-
*
|
|
1086
|
-
* @param {Node} current Currently focused node
|
|
1087
|
-
* @param {Node} target Target node. May or may not be focusable
|
|
1088
|
-
* @memberof spotlight/container
|
|
1089
|
-
* @public
|
|
1090
|
-
*/
|
|
1091
|
-
|
|
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
|
-
}
|
|
1110
|
-
}
|
|
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
|
-
}
|
|
1123
|
-
/**
|
|
1124
|
-
* Notifies any affected containers that focus has left one of their children for another container
|
|
1125
|
-
*
|
|
1126
|
-
* @param {String} direction up/down/left/right
|
|
1127
|
-
* @param {Node} current currently focused element
|
|
1128
|
-
* @param {String[]} currentContainerIds Containers for current
|
|
1129
|
-
* @param {Node} next To be focused element
|
|
1130
|
-
* @param {String[]} nextContainerIds Containers for next
|
|
1131
|
-
* @private
|
|
1132
|
-
*/
|
|
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
|
-
}
|
|
1151
|
-
/**
|
|
1152
|
-
* Notifies any containers that focus attempted to move but failed to find a target
|
|
1153
|
-
*
|
|
1154
|
-
* @param {String} direction up/down/left/right
|
|
1155
|
-
* @param {Node} current currently focused element
|
|
1156
|
-
* @param {String[]} currentContainerIds Containers for current
|
|
1157
|
-
* @private
|
|
1158
|
-
*/
|
|
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
|
-
}
|
|
1174
|
-
/**
|
|
1175
|
-
* Notifies any affected containers that one of their children has received focus.
|
|
1176
|
-
*
|
|
1177
|
-
* @param {String} direction up/down/left/right
|
|
1178
|
-
* @param {Node} previous Previously focused element
|
|
1179
|
-
* @param {String[]} previousContainerIds Containers for previous
|
|
1180
|
-
* @param {Node} current Currently focused element
|
|
1181
|
-
* @param {String[]} currentContainerIds Containers for current
|
|
1182
|
-
* @private
|
|
1183
|
-
*/
|
|
1184
|
-
|
|
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
|
-
}
|