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