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