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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
  2. package/Accelerator/Accelerator.js +149 -156
  3. package/CHANGELOG.md +22 -0
  4. package/{build/Pause → Pause}/Pause.d.ts +0 -0
  5. package/Pause/Pause.js +102 -80
  6. package/Pause/tests/Pause-specs.js +65 -97
  7. package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
  8. package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
  9. package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
  10. package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
  11. package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
  12. package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
  13. package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
  14. package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
  15. package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
  16. package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
  17. package/Spottable/Spottable.js +448 -410
  18. package/Spottable/tests/Spottable-specs.js +90 -117
  19. package/package.json +3 -2
  20. package/src/container.js +718 -653
  21. package/src/navigate.js +406 -491
  22. package/src/pointer.js +86 -78
  23. package/{build/src → src}/spotlight.d.ts +0 -0
  24. package/src/spotlight.js +846 -885
  25. package/src/target.js +448 -474
  26. package/src/tests/container-specs.js +643 -1251
  27. package/src/tests/navigate-specs.js +77 -134
  28. package/src/tests/pointer-specs.js +126 -182
  29. package/src/tests/spotlight-specs.js +103 -133
  30. package/src/tests/target-specs.js +597 -960
  31. package/src/tests/utils.js +89 -67
  32. package/src/utils.js +155 -158
  33. package/build/Accelerator/Accelerator.js +0 -162
  34. package/build/Accelerator/package.json +0 -3
  35. package/build/CHANGELOG.md +0 -838
  36. package/build/Pause/Pause.js +0 -164
  37. package/build/Pause/package.json +0 -3
  38. package/build/Pause/tests/Pause-specs.js +0 -65
  39. package/build/README.md +0 -61
  40. package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
  41. package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
  42. package/build/SpotlightContainerDecorator/package.json +0 -3
  43. package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
  44. package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
  45. package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
  46. package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
  47. package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
  48. package/build/SpotlightRootDecorator/package.json +0 -3
  49. package/build/Spottable/Spottable.js +0 -491
  50. package/build/Spottable/package.json +0 -3
  51. package/build/Spottable/tests/Spottable-specs.js +0 -90
  52. package/build/package-lock.json +0 -229
  53. package/build/package.json +0 -28
  54. package/build/src/container.js +0 -1201
  55. package/build/src/navigate.js +0 -419
  56. package/build/src/pointer.js +0 -183
  57. package/build/src/spotlight.js +0 -896
  58. package/build/src/target.js +0 -507
  59. package/build/src/tests/container-specs.js +0 -653
  60. package/build/src/tests/navigate-specs.js +0 -87
  61. package/build/src/tests/pointer-specs.js +0 -130
  62. package/build/src/tests/spotlight-specs.js +0 -112
  63. package/build/src/tests/target-specs.js +0 -614
  64. package/build/src/tests/utils.js +0 -104
  65. package/build/src/utils.js +0 -180
  66. package/build/styles/debug.less +0 -97
  67. package/build/styles/mixins.less +0 -63
  68. package/docs/index.md +0 -364
@@ -1,977 +1,614 @@
1
- import {
2
- configureContainer,
3
- configureDefaults,
4
- containerAttribute,
5
- getAllContainerIds,
6
- removeContainer,
7
- rootContainerId,
8
- setDefaultContainer
9
- } from '../container';
1
+ "use strict";
10
2
 
11
- import {
12
- getNavigableTarget,
13
- getTargetByContainer,
14
- getTargetByDirectionFromElement,
15
- getTargetByDirectionFromPosition,
16
- getTargetBySelector
17
- } from '../target';
3
+ var _container12 = require("../container");
18
4
 
19
- import {
20
- container,
21
- join,
22
- node,
23
- someSpottables,
24
- spottable,
25
- testScenario
26
- } from './utils';
5
+ var _target = require("../target");
27
6
 
28
- const nonSpottable = () => node({className: 'other'});
7
+ var _utils = require("./utils");
29
8
 
30
- const position = (top, left) => `position: absolute; top: ${top}px; left: ${left}px; height: 10px; width: 10px;`;
9
+ var _container2, _container3, _container4, _container5, _container6, _container7, _container8, _container9, _container10, _container11;
31
10
 
32
- const positionedSpottable = (id, top, left) => {
33
- return spottable({
34
- id,
35
- style: position(top, left)
36
- });
37
- };
38
-
39
- const grid = () => container({
40
- [containerAttribute]: 'grid',
41
- style: 'position: relative; height: 30px; width: 30px;',
42
- children: join(
43
- positionedSpottable('top-left', 0, 0),
44
- positionedSpottable('top-center', 0, 10),
45
- positionedSpottable('top-right', 0, 20),
46
- positionedSpottable('middle-left', 10, 0),
47
- positionedSpottable('middle-center', 10, 10),
48
- positionedSpottable('middle-right', 10, 20),
49
- positionedSpottable('bottom-left', 20, 0),
50
- positionedSpottable('bottom-center', 20, 10),
51
- positionedSpottable('bottom-right', 20, 20)
52
- )
53
- });
11
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
54
12
 
55
- const scenarios = {
56
- complexTree: join(
57
- spottable(nonSpottable()),
58
- container({[containerAttribute]: 'first-container', children: join(
59
- someSpottables(2),
60
- container({[containerAttribute]: 'second-container', children: join(
61
- someSpottables(3),
62
- container({
63
- [containerAttribute]: 'third-container',
64
- 'data-spotlight-container-disabled': true,
65
- children: join(
66
- someSpottables(4),
67
- node({id: 'child-of-third'})
68
- )
69
- })
70
- )})
71
- )})
72
- ),
73
- nonSpottableInContainer: join(
74
- spottable({id: 'in-root'}),
75
- container({[containerAttribute]: 'first', children: join(
76
- nonSpottable(),
77
- spottable({id: 'in-first'})
78
- )}),
79
- container({[containerAttribute]: 'second', children: join(
80
- nonSpottable()
81
- )})
82
- ),
83
- grid: join(
84
- spottable({id: 'before-grid', style: 'height: 10px'}),
85
- grid(),
86
- spottable({id: 'after-grid', style: 'height: 10px'})
87
- ),
88
- overlap: node({
89
- style: 'position: relative',
90
- children: join(
91
- grid(),
92
- spottable({
93
- id: 'over-middle-center',
94
- style: 'position: absolute; top: 12px; left: 15px; height: 1px; width: 1px;'
95
- })
96
- )
97
- }),
98
- overflow: join(
99
- spottable({id: 'outside-overflow'}),
100
- node({
101
- // allocate some empty space so that overflow items would be otherwise navigable
102
- style: 'height: 100px'
103
- }),
104
- container({
105
- [containerAttribute]: 'overflow-container',
106
- style: 'position: relative; height: 30px; width: 30px;',
107
- children: join(
108
- spottable({
109
- id: 'overflow-above',
110
- style: 'position: absolute; top: -10px; left: 0px; height: 10px; width: 10px;'
111
- }),
112
- spottable({
113
- id: 'overflow-below',
114
- style: 'position: absolute; top: 30px; left: 0px; height: 10px; width: 10px;'
115
- }),
116
- spottable({
117
- id: 'overflow-within',
118
- style: 'position: absolute; top: 0px; left: 0px; height: 10px; width: 10px;'
119
- })
120
- )
121
- })
122
- ),
123
- overflowLargeSubContainer: join(
124
- spottable({id: 'outside-overflow'}),
125
- node({
126
- // allocate some empty space so that overflow items would be otherwise navigable
127
- style: 'height: 100px'
128
- }),
129
- container({
130
- [containerAttribute]: 'overflow-container',
131
- style: 'position: relative; height: 30px; width: 30px;',
132
- children: join(
133
- container({
134
- [containerAttribute]: 'inside',
135
- // subcontainer is taller than overflow-container
136
- style: 'position: absolute; top: -10px; left: 0px; height: 50px; width: 10px;',
137
- children: join(
138
- node({
139
- // allocate space to push following spottable into view
140
- style: 'height: 10px'
141
- }),
142
- spottable({
143
- id: 'in-large-container'
144
- })
145
- )
146
- }),
147
- spottable({
148
- id: 'below-large-container',
149
- style: 'position: absolute; top: 40px; left: 0px; height: 10px; width: 10px;'
150
- })
151
- )
152
- })
153
- ),
154
- emptyContainer: join(
155
- positionedSpottable('above', 0, 10),
156
- container({
157
- [containerAttribute]: 'empty-container',
158
- style: position(10, 10)
159
- }),
160
- positionedSpottable('below', 30, 0)
161
- ),
162
- emptyContainerOverlap: join(
163
- positionedSpottable('above', 5, 10),
164
- container({
165
- [containerAttribute]: 'empty-container',
166
- style: position(10, 10)
167
- }),
168
- positionedSpottable('below', 30, 0)
169
- )
13
+ var nonSpottable = function nonSpottable() {
14
+ return (0, _utils.node)({
15
+ className: 'other'
16
+ });
170
17
  };
171
18
 
172
- const safeTarget = (n, fn) => n ? fn(n) : 'NOT FOUND';
173
-
174
- const setupContainers = () => {
175
- configureDefaults({
176
- selector: '.spottable'
177
- });
178
- configureContainer(rootContainerId);
19
+ var position = function position(top, left) {
20
+ return "position: absolute; top: ".concat(top, "px; left: ").concat(left, "px; height: 10px; width: 10px;");
179
21
  };
180
22
 
181
- const teardownContainers = () => {
182
- // clean up any containers we create for safe tests
183
- getAllContainerIds().forEach(removeContainer);
184
- setDefaultContainer();
23
+ var positionedSpottable = function positionedSpottable(id, top, left) {
24
+ return (0, _utils.spottable)({
25
+ id: id,
26
+ style: position(top, left)
27
+ });
185
28
  };
186
29
 
187
- // NOTE: Skipping most tests because JSDOM does not support measurments
188
- describe('target', () => {
189
- beforeEach(setupContainers);
190
- afterEach(teardownContainers);
191
-
192
- describe.skip('#getNavigableTarget', () => {
193
- test('should find spottable parent', testScenario(
194
- scenarios.complexTree,
195
- (root) => {
196
- const other = root.querySelector('.other');
197
-
198
- const expected = other.parentNode;
199
- const actual = getNavigableTarget(other);
200
-
201
- expect(actual).toBe(expected);
202
- }
203
- ));
204
-
205
- test('should skip containers', testScenario(
206
- scenarios.nonSpottableInContainer,
207
- (root) => {
208
- configureContainer('first');
209
- const other = root.querySelector('.other');
210
-
211
- const expected = null;
212
- const actual = getNavigableTarget(other);
213
-
214
- expect(actual).toBe(expected);
215
- }
216
- ));
217
-
218
- test('should respect container-specific selector', testScenario(
219
- scenarios.nonSpottableInContainer,
220
- (root) => {
221
- // make '.other' a valid spottable element
222
- configureContainer('first', {
223
- selector: '.other'
224
- });
225
- const other = root.querySelector('.other');
226
-
227
- const expected = other;
228
- const actual = getNavigableTarget(other);
229
-
230
- expect(actual).toBe(expected);
231
- }
232
- ));
233
-
234
- test('should respect disabled containers', testScenario(
235
- scenarios.complexTree,
236
- (root) => {
237
- configureContainer('third-container');
238
- const other = root.querySelector(`[${containerAttribute}='third-container'] .spottable`);
239
-
240
- const expected = null;
241
- const actual = getNavigableTarget(other);
242
-
243
- expect(actual).toBe(expected);
244
- }
245
- ));
246
- });
247
-
248
- describe('#getTargetByContainer', () => {
249
- test('should find spottable element within provided container', testScenario(
250
- scenarios.complexTree,
251
- () => {
252
- configureContainer('first-container');
253
-
254
- const expected = 'spottable';
255
- const actual = safeTarget(
256
- getTargetByContainer('first-container'),
257
- t => t.className
258
- );
259
-
260
- expect(actual).toBe(expected);
261
- }
262
- ));
263
-
264
- test(
265
- 'should return null when container does not contain any spottable elements',
266
- testScenario(
267
- scenarios.nonSpottableInContainer,
268
- () => {
269
- configureContainer('first');
270
- configureContainer('second');
271
-
272
- const expected = null;
273
- const actual = getTargetByContainer('second');
274
-
275
- expect(actual).toBe(expected);
276
- }
277
- )
278
- );
279
-
280
- test(
281
- 'should find the first spottable in the root when no container specified',
282
- testScenario(
283
- scenarios.nonSpottableInContainer,
284
- () => {
285
- configureContainer('first');
286
- configureContainer('second');
287
-
288
- const expected = 'in-root';
289
- const actual = safeTarget(
290
- getTargetByContainer(),
291
- t => t.id
292
- );
293
-
294
- expect(actual).toBe(expected);
295
- }
296
- )
297
- );
298
-
299
- test(
300
- 'should find the first spottable in the default container when set and no container specified',
301
- testScenario(
302
- scenarios.nonSpottableInContainer,
303
- () => {
304
- configureContainer('first');
305
- configureContainer('second');
306
- setDefaultContainer('first');
307
-
308
- const expected = 'spottable';
309
- const actual = safeTarget(
310
- getTargetByContainer(),
311
- t => t.className
312
- );
313
-
314
- expect(actual).toBe(expected);
315
- }
316
- )
317
- );
318
-
319
- test('should return `default-element` when last focused is unset', testScenario(
320
- scenarios.grid,
321
- () => {
322
- configureContainer('grid', {
323
- enterTo: 'last-focused',
324
- defaultElement: '#middle-center'
325
- });
326
-
327
- const expected = 'middle-center';
328
- const actual = safeTarget(
329
- getTargetByContainer('grid'),
330
- t => t.id
331
- );
332
-
333
- expect(actual).toBe(expected);
334
- }
335
- ));
336
-
337
- test('should return `default-element` when `last-focused` is requested but is unset', testScenario(
338
- scenarios.grid,
339
- () => {
340
- configureContainer('grid', {
341
- defaultElement: '#middle-center'
342
- });
343
-
344
- const expected = 'middle-center';
345
- const actual = safeTarget(
346
- getTargetByContainer('grid', 'last-focused'),
347
- t => t.id
348
- );
349
-
350
- expect(actual).toBe(expected);
351
- }
352
- ));
353
-
354
- test('should return default element when configured for `last-focused` but requested `default-element`', testScenario(
355
- scenarios.grid,
356
- () => {
357
- configureContainer('grid', {
358
- enterTo: 'last-focused',
359
- lastFocusedElement: document.querySelector('#top-left'),
360
- defaultElement: '#middle-center'
361
- });
362
-
363
- const expected = 'middle-center';
364
- const actual = safeTarget(
365
- getTargetByContainer('grid', 'default-element'),
366
- t => t.id
367
- );
368
-
369
- expect(actual).toBe(expected);
370
- }
371
- ));
372
-
373
- test('should return last focused element when configured for `default-element` but requested `last-focused`', testScenario(
374
- scenarios.grid,
375
- () => {
376
- configureContainer('grid', {
377
- enterTo: 'default-element',
378
- lastFocusedElement: document.querySelector('#top-left'),
379
- defaultElement: '#middle-center'
380
- });
381
-
382
- const expected = 'top-left';
383
- const actual = safeTarget(
384
- getTargetByContainer('grid', 'last-focused'),
385
- t => t.id
386
- );
387
-
388
- expect(actual).toBe(expected);
389
- }
390
- ));
391
- });
392
-
393
- describe('#getTargetBySelector', () => {
394
- test(
395
- 'should find spottable element within container when "@" prefix used',
396
- testScenario(
397
- scenarios.nonSpottableInContainer,
398
- () => {
399
- configureContainer('first');
400
-
401
- const expected = 'spottable';
402
- const actual = safeTarget(
403
- getTargetBySelector('@first'),
404
- t => t.className
405
- );
406
-
407
- expect(actual).toBe(expected);
408
- }
409
- )
410
- );
411
-
412
- test(
413
- 'should find spottable element within container when "#" prefix used',
414
- testScenario(
415
- scenarios.nonSpottableInContainer,
416
- () => {
417
- configureContainer('first');
418
-
419
- const expected = 'in-first';
420
- const actual = safeTarget(
421
- getTargetBySelector('#in-first'),
422
- t => t.id
423
- );
424
-
425
- expect(actual).toBe(expected);
426
- }
427
- )
428
- );
429
-
430
- test(
431
- 'should return null when the node exists but is not navigable within its container',
432
- testScenario(
433
- scenarios.nonSpottableInContainer,
434
- () => {
435
- configureContainer('first', {
436
- navigableFilter: () => false
437
- });
438
-
439
- const expected = null;
440
- const actual = getTargetBySelector('#in-first');
441
-
442
- expect(actual).toBe(expected);
443
- }
444
- )
445
- );
446
-
447
- test(
448
- 'should return null when the node exists but does not match the container\'s selector',
449
- testScenario(
450
- scenarios.nonSpottableInContainer,
451
- () => {
452
- configureContainer('first');
453
-
454
- const expected = null;
455
- const actual = getTargetBySelector(`[${containerAttribute}='first'] .other`);
456
-
457
- expect(actual).toBe(expected);
458
- }
459
- )
460
- );
461
-
462
- test('should return null for an empty selectors', testScenario(
463
- scenarios.nonSpottableInContainer,
464
- () => {
465
- const expected = null;
466
-
467
- // eslint-disable-next-line no-undefined
468
- expect(getTargetBySelector(undefined)).toBe(expected);
469
- expect(getTargetBySelector(null)).toBe(expected);
470
- expect(getTargetBySelector('')).toBe(expected);
471
- }
472
- ));
473
- });
474
-
475
- describe.skip('#getTargetByDirectionFromElement', () => {
476
- test('should find target within container by direction', testScenario(
477
- scenarios.grid,
478
- (root) => {
479
- configureContainer('grid');
480
- const center = root.querySelector('#middle-center');
481
-
482
- expect(safeTarget(
483
- getTargetByDirectionFromElement('up', center),
484
- t => t.id
485
- )).toBe('top-center');
486
-
487
- expect(safeTarget(
488
- getTargetByDirectionFromElement('down', center),
489
- t => t.id
490
- )).toBe('bottom-center');
491
-
492
- expect(safeTarget(
493
- getTargetByDirectionFromElement('left', center),
494
- t => t.id
495
- )).toBe('middle-left');
496
-
497
- expect(safeTarget(
498
- getTargetByDirectionFromElement('right', center),
499
- t => t.id
500
- )).toBe('middle-right');
501
- }
502
- ));
503
-
504
- test('should find target within container from floating element', testScenario(
505
- scenarios.overlap,
506
- (root) => {
507
- configureContainer('grid', {
508
- enterTo: 'default-element',
509
- defaultElement: '#bottom-right'
510
- });
511
-
512
- const overlap = root.querySelector('#over-middle-center');
513
-
514
- expect(safeTarget(
515
- getTargetByDirectionFromElement('down', overlap),
516
- t => t.id
517
- )).toBe('middle-center');
518
- }
519
- ));
520
-
521
- test(
522
- 'should ignore targets outside the bounds of an overflow container',
523
- testScenario(
524
- scenarios.overflow,
525
- (root) => {
526
- configureContainer('overflow-container', {
527
- overflow: true
528
- });
30
+ var grid = function grid() {
31
+ var _container;
529
32
 
530
- const element = root.querySelector('#outside-overflow');
531
-
532
- expect(safeTarget(
533
- getTargetByDirectionFromElement('down', element),
534
- t => t.id
535
- )).toBe('overflow-within');
536
- }
537
- )
538
- );
539
-
540
- test(
541
- 'should find target within container larger than overflow container',
542
- testScenario(
543
- scenarios.overflowLargeSubContainer,
544
- (root) => {
545
- configureContainer('overflow-container', {
546
- overflow: true
547
- });
548
- configureContainer('inside', {
549
- enterTo: null
550
- });
551
-
552
- const element = root.querySelector('#outside-overflow');
553
-
554
- expect(safeTarget(
555
- getTargetByDirectionFromElement('down', element),
556
- t => t.id
557
- )).toBe('in-large-container');
558
- }
559
- )
560
- );
561
-
562
- test(
563
- 'should find target out of bounds of overflow container from within container',
564
- testScenario(
565
- scenarios.overflow,
566
- (root) => {
567
- configureContainer('overflow-container', {
568
- overflow: true
569
- });
570
-
571
- const element = root.querySelector('#overflow-within');
572
-
573
- expect(safeTarget(
574
- getTargetByDirectionFromElement('down', element),
575
- t => t.id
576
- )).toBe('overflow-below');
577
-
578
- expect(safeTarget(
579
- getTargetByDirectionFromElement('up', element),
580
- t => t.id
581
- )).toBe('overflow-above');
582
- }
583
- )
584
- );
585
-
586
- test('should stop at restrict="self-only" boundaries', testScenario(
587
- scenarios.complexTree,
588
- (root) => {
589
- configureContainer('first-container', {
590
- restrict: 'none'
591
- });
592
- configureContainer('second-container', {
593
- restrict: 'self-only'
594
- });
595
-
596
- const element = root.querySelector(`[${containerAttribute}="second-container"] .spottable`);
597
-
598
- expect(safeTarget(
599
- getTargetByDirectionFromElement('up', element),
600
- t => t.id
601
- )).toBe('NOT FOUND');
602
- }
603
- ));
604
-
605
- test('should respect enterTo="default-element" containers', testScenario(
606
- scenarios.grid,
607
- (root) => {
608
- configureContainer('grid', {
609
- restrict: 'none',
610
- enterTo: 'default-element',
611
- defaultElement: '#bottom-right'
612
- });
613
-
614
- const element = root.querySelector('#before-grid');
615
-
616
- expect(safeTarget(
617
- getTargetByDirectionFromElement('down', element),
618
- t => t.id
619
- )).toBe('bottom-right');
620
- }
621
- ));
622
-
623
- test('should respect enterTo="last-focused" containers', testScenario(
624
- scenarios.grid,
625
- (root) => {
626
- configureContainer('grid', {
627
- restrict: 'none',
628
- enterTo: 'last-focused',
629
- lastFocusedKey: {
630
- container: false,
631
- element: true,
632
- key: 8
633
- }
634
- });
635
-
636
- const element = root.querySelector('#before-grid');
637
-
638
- expect(safeTarget(
639
- getTargetByDirectionFromElement('down', element),
640
- t => t.id
641
- )).toBe('bottom-right');
642
- }
643
- ));
644
-
645
- test(
646
- 'should follow the leaveFor config when no target is found within the container in the given direction',
647
- testScenario(
648
- scenarios.grid,
649
- (root) => {
650
- configureContainer('grid', {
651
- restrict: 'none',
652
- leaveFor: {
653
- up: '#after-grid'
654
- }
655
- });
656
-
657
- const element = root.querySelector('#top-center');
658
-
659
- expect(safeTarget(
660
- getTargetByDirectionFromElement('up', element),
661
- t => t.id
662
- )).toBe('after-grid');
663
- }
664
- )
665
- );
666
-
667
- test(
668
- 'should not follow the leaveFor config when a target is found within the container in the given direction',
669
- testScenario(
670
- scenarios.grid,
671
- (root) => {
672
- configureContainer('grid', {
673
- restrict: 'none',
674
- leaveFor: {
675
- up: '#after-grid'
676
- }
677
- });
678
-
679
- const element = root.querySelector('#middle-center');
680
-
681
- expect(safeTarget(
682
- getTargetByDirectionFromElement('up', element),
683
- t => t.id
684
- )).toBe('top-center');
685
- }
686
- )
687
- );
688
-
689
- test(
690
- 'should not follow the leaveFor config when the selector does not match an element',
691
- testScenario(
692
- scenarios.grid,
693
- (root) => {
694
- configureContainer('grid', {
695
- restrict: 'none',
696
- leaveFor: {
697
- up: '#does-not-exist'
698
- }
699
- });
700
-
701
- const element = root.querySelector('#top-center');
702
-
703
- expect(safeTarget(
704
- getTargetByDirectionFromElement('up', element),
705
- t => t.id
706
- )).toBe('before-grid');
707
- }
708
- )
709
- );
710
-
711
- test('should ignore empty containers', testScenario(
712
- scenarios.emptyContainer,
713
- (root) => {
714
- configureContainer('empty-container');
715
- const element = root.querySelector('#above');
716
-
717
- expect(safeTarget(
718
- getTargetByDirectionFromElement('down', element),
719
- t => t.id
720
- )).toBe('below');
721
- }
722
- ));
723
-
724
- test('should ignore overlapping empty containers', testScenario(
725
- scenarios.emptyContainerOverlap,
726
- (root) => {
727
- configureContainer('empty-container');
728
- const element = root.querySelector('#above');
729
-
730
- expect(safeTarget(
731
- getTargetByDirectionFromElement('down', element),
732
- t => t.id
733
- )).toBe('below');
734
- }
735
- ));
736
- });
737
-
738
- describe.skip('#getTargetByDirectionFromPosition', () => {
739
- test('should find target within container', testScenario(
740
- scenarios.grid,
741
- (root) => {
742
- configureContainer('grid');
743
- const rect = root.querySelector('#middle-center').getBoundingClientRect();
744
- const center = {
745
- x: rect.left + rect.width / 2,
746
- y: rect.top + rect.height / 2
747
- };
748
-
749
- expect(safeTarget(
750
- getTargetByDirectionFromPosition('up', center, 'grid'),
751
- t => t.id
752
- )).toBe('top-center');
753
-
754
- expect(safeTarget(
755
- getTargetByDirectionFromPosition('down', center, 'grid'),
756
- t => t.id
757
- )).toBe('bottom-center');
758
-
759
- expect(safeTarget(
760
- getTargetByDirectionFromPosition('left', center, 'grid'),
761
- t => t.id
762
- )).toBe('middle-left');
763
-
764
- expect(safeTarget(
765
- getTargetByDirectionFromPosition('right', center, 'grid'),
766
- t => t.id
767
- )).toBe('middle-right');
768
- }
769
- ));
770
-
771
- test(
772
- 'should not find a target when at bounds of container with restrict="self-only"',
773
- testScenario(
774
- scenarios.grid,
775
- (root) => {
776
- configureContainer('grid', {
777
- restrict: 'self-only'
778
- });
779
- const rect = root.querySelector('#top-center').getBoundingClientRect();
780
- const topCenterOfGrid = {
781
- x: rect.left + rect.width / 2,
782
- y: rect.top
783
- };
784
-
785
- expect(safeTarget(
786
- getTargetByDirectionFromPosition('up', topCenterOfGrid, 'grid'),
787
- t => t.id
788
- )).toBe('NOT FOUND');
789
- }
790
- )
791
- );
792
-
793
- test(
794
- 'should not find a target outside of container when restrict is not set',
795
- testScenario(
796
- scenarios.grid,
797
- (root) => {
798
- configureContainer('grid', {
799
- restrict: 'none'
800
- });
801
- const rect = root.querySelector('#top-center').getBoundingClientRect();
802
- const topCenterOfGrid = {
803
- x: rect.left + rect.width / 2,
804
- y: rect.top
805
- };
806
-
807
- expect(safeTarget(
808
- getTargetByDirectionFromPosition('up', topCenterOfGrid, 'grid'),
809
- t => t.id
810
- )).toBe('before-grid');
811
- }
812
- )
813
- );
814
-
815
- test('should cascade into unrestricted subcontainers', testScenario(
816
- scenarios.grid,
817
- (root) => {
818
- configureContainer('grid', {
819
- restrict: 'none'
820
- });
821
- const rect = root.querySelector('#top-center').getBoundingClientRect();
822
- const aboveCenterOfGrid = {
823
- x: rect.left + rect.width / 2,
824
- y: rect.top - 1
825
- };
826
-
827
- expect(safeTarget(
828
- getTargetByDirectionFromPosition('down', aboveCenterOfGrid, rootContainerId),
829
- t => t.id
830
- )).toBe('top-center');
831
- }
832
- ));
833
-
834
- test('should ignore enterTo config of restricted subcontainers', testScenario(
835
- scenarios.grid,
836
- (root) => {
837
- configureContainer('grid', {
838
- restrict: 'none',
839
- enterTo: 'default-element',
840
- defaultElement: '#bottom-right'
841
- });
842
- const rect = root.querySelector('#top-center').getBoundingClientRect();
843
- const aboveCenterOfGrid = {
844
- x: rect.left + rect.width / 2,
845
- y: rect.top - 1
846
- };
847
-
848
- expect(safeTarget(
849
- getTargetByDirectionFromPosition('down', aboveCenterOfGrid, rootContainerId),
850
- t => t.id
851
- )).toBe('top-center');
852
- }
853
- ));
854
-
855
- test('should find target within container from floating element', testScenario(
856
- scenarios.overlap,
857
- (root) => {
858
- configureContainer('grid', {
859
- enterTo: 'default-element',
860
- defaultElement: '#bottom-right'
861
- });
862
-
863
- const overlap = root.querySelector('#over-middle-center');
864
- const {left: x, top: y} = overlap.getBoundingClientRect();
865
-
866
- expect(safeTarget(
867
- getTargetByDirectionFromPosition('down', {x, y}, rootContainerId),
868
- t => t.id
869
- )).toBe('middle-center');
870
- }
871
- ));
872
-
873
- test(
874
- 'should ignore targets outside the bounds of an overflow container',
875
- testScenario(
876
- scenarios.overflow,
877
- (root) => {
878
- configureContainer('overflow-container', {
879
- overflow: true
880
- });
881
-
882
- const element = root.querySelector('#outside-overflow');
883
- const {left: x, top: y} = element.getBoundingClientRect();
884
-
885
- expect(safeTarget(
886
- getTargetByDirectionFromPosition('down', {x, y}, rootContainerId),
887
- t => t.id
888
- )).toBe('overflow-within');
889
- }
890
- )
891
- );
892
-
893
- test(
894
- 'should find target within container larger than overflow container',
895
- testScenario(
896
- scenarios.overflowLargeSubContainer,
897
- (root) => {
898
- configureContainer('overflow-container', {
899
- overflow: true
900
- });
901
- configureContainer('inside', {
902
- enterTo: null
903
- });
904
-
905
- const element = root.querySelector('#outside-overflow');
906
- const {left: x, top: y} = element.getBoundingClientRect();
907
-
908
- expect(safeTarget(
909
- getTargetByDirectionFromPosition('down', {x, y}, rootContainerId),
910
- t => t.id
911
- )).toBe('in-large-container');
912
- }
913
- )
914
- );
915
-
916
- test(
917
- 'should find target out of bounds of overflow container from within container',
918
- testScenario(
919
- scenarios.overflow,
920
- (root) => {
921
- configureContainer('overflow-container', {
922
- overflow: true
923
- });
924
-
925
- const element = root.querySelector('#overflow-within');
926
- const {left, width, top, height} = element.getBoundingClientRect();
927
- const x = left + width / 2;
928
- const y = top + height / 2;
929
-
930
- expect(safeTarget(
931
- getTargetByDirectionFromPosition('down', {x, y: y + 1}, rootContainerId),
932
- t => t.id
933
- )).toBe('overflow-below');
934
-
935
- expect(safeTarget(
936
- getTargetByDirectionFromPosition('up', {x, y: y - 1}, rootContainerId),
937
- t => t.id
938
- )).toBe('overflow-above');
939
- }
940
- )
941
- );
942
-
943
- test('should ignore empty containers', testScenario(
944
- scenarios.emptyContainer,
945
- (root) => {
946
- configureContainer('empty-container');
947
- const element = root.querySelector('#above');
948
-
949
- const {left, width, top, height} = element.getBoundingClientRect();
950
- const x = left + width / 2;
951
- const y = top + height - 1; // just inside the bottom of 'above'
33
+ return (0, _utils.container)((_container = {}, _defineProperty(_container, _container12.containerAttribute, 'grid'), _defineProperty(_container, "style", 'position: relative; height: 30px; width: 30px;'), _defineProperty(_container, "children", (0, _utils.join)(positionedSpottable('top-left', 0, 0), positionedSpottable('top-center', 0, 10), positionedSpottable('top-right', 0, 20), positionedSpottable('middle-left', 10, 0), positionedSpottable('middle-center', 10, 10), positionedSpottable('middle-right', 10, 20), positionedSpottable('bottom-left', 20, 0), positionedSpottable('bottom-center', 20, 10), positionedSpottable('bottom-right', 20, 20))), _container));
34
+ };
952
35
 
953
- expect(safeTarget(
954
- getTargetByDirectionFromPosition('down', {x, y}, rootContainerId),
955
- t => t.id
956
- )).toBe('below');
957
- }
958
- ));
36
+ var scenarios = {
37
+ complexTree: (0, _utils.join)((0, _utils.spottable)(nonSpottable()), (0, _utils.container)((_container4 = {}, _defineProperty(_container4, _container12.containerAttribute, 'first-container'), _defineProperty(_container4, "children", (0, _utils.join)((0, _utils.someSpottables)(2), (0, _utils.container)((_container3 = {}, _defineProperty(_container3, _container12.containerAttribute, 'second-container'), _defineProperty(_container3, "children", (0, _utils.join)((0, _utils.someSpottables)(3), (0, _utils.container)((_container2 = {}, _defineProperty(_container2, _container12.containerAttribute, 'third-container'), _defineProperty(_container2, 'data-spotlight-container-disabled', true), _defineProperty(_container2, "children", (0, _utils.join)((0, _utils.someSpottables)(4), (0, _utils.node)({
38
+ id: 'child-of-third'
39
+ }))), _container2)))), _container3)))), _container4))),
40
+ nonSpottableInContainer: (0, _utils.join)((0, _utils.spottable)({
41
+ id: 'in-root'
42
+ }), (0, _utils.container)((_container5 = {}, _defineProperty(_container5, _container12.containerAttribute, 'first'), _defineProperty(_container5, "children", (0, _utils.join)(nonSpottable(), (0, _utils.spottable)({
43
+ id: 'in-first'
44
+ }))), _container5)), (0, _utils.container)((_container6 = {}, _defineProperty(_container6, _container12.containerAttribute, 'second'), _defineProperty(_container6, "children", (0, _utils.join)(nonSpottable())), _container6))),
45
+ grid: (0, _utils.join)((0, _utils.spottable)({
46
+ id: 'before-grid',
47
+ style: 'height: 10px'
48
+ }), grid(), (0, _utils.spottable)({
49
+ id: 'after-grid',
50
+ style: 'height: 10px'
51
+ })),
52
+ overlap: (0, _utils.node)({
53
+ style: 'position: relative',
54
+ children: (0, _utils.join)(grid(), (0, _utils.spottable)({
55
+ id: 'over-middle-center',
56
+ style: 'position: absolute; top: 12px; left: 15px; height: 1px; width: 1px;'
57
+ }))
58
+ }),
59
+ overflow: (0, _utils.join)((0, _utils.spottable)({
60
+ id: 'outside-overflow'
61
+ }), (0, _utils.node)({
62
+ // allocate some empty space so that overflow items would be otherwise navigable
63
+ style: 'height: 100px'
64
+ }), (0, _utils.container)((_container7 = {}, _defineProperty(_container7, _container12.containerAttribute, 'overflow-container'), _defineProperty(_container7, "style", 'position: relative; height: 30px; width: 30px;'), _defineProperty(_container7, "children", (0, _utils.join)((0, _utils.spottable)({
65
+ id: 'overflow-above',
66
+ style: 'position: absolute; top: -10px; left: 0px; height: 10px; width: 10px;'
67
+ }), (0, _utils.spottable)({
68
+ id: 'overflow-below',
69
+ style: 'position: absolute; top: 30px; left: 0px; height: 10px; width: 10px;'
70
+ }), (0, _utils.spottable)({
71
+ id: 'overflow-within',
72
+ style: 'position: absolute; top: 0px; left: 0px; height: 10px; width: 10px;'
73
+ }))), _container7))),
74
+ overflowLargeSubContainer: (0, _utils.join)((0, _utils.spottable)({
75
+ id: 'outside-overflow'
76
+ }), (0, _utils.node)({
77
+ // allocate some empty space so that overflow items would be otherwise navigable
78
+ style: 'height: 100px'
79
+ }), (0, _utils.container)((_container9 = {}, _defineProperty(_container9, _container12.containerAttribute, 'overflow-container'), _defineProperty(_container9, "style", 'position: relative; height: 30px; width: 30px;'), _defineProperty(_container9, "children", (0, _utils.join)((0, _utils.container)((_container8 = {}, _defineProperty(_container8, _container12.containerAttribute, 'inside'), _defineProperty(_container8, "style", 'position: absolute; top: -10px; left: 0px; height: 50px; width: 10px;'), _defineProperty(_container8, "children", (0, _utils.join)((0, _utils.node)({
80
+ // allocate space to push following spottable into view
81
+ style: 'height: 10px'
82
+ }), (0, _utils.spottable)({
83
+ id: 'in-large-container'
84
+ }))), _container8)), (0, _utils.spottable)({
85
+ id: 'below-large-container',
86
+ style: 'position: absolute; top: 40px; left: 0px; height: 10px; width: 10px;'
87
+ }))), _container9))),
88
+ emptyContainer: (0, _utils.join)(positionedSpottable('above', 0, 10), (0, _utils.container)((_container10 = {}, _defineProperty(_container10, _container12.containerAttribute, 'empty-container'), _defineProperty(_container10, "style", position(10, 10)), _container10)), positionedSpottable('below', 30, 0)),
89
+ emptyContainerOverlap: (0, _utils.join)(positionedSpottable('above', 5, 10), (0, _utils.container)((_container11 = {}, _defineProperty(_container11, _container12.containerAttribute, 'empty-container'), _defineProperty(_container11, "style", position(10, 10)), _container11)), positionedSpottable('below', 30, 0))
90
+ };
959
91
 
960
- test('should ignore overlapping empty containers', testScenario(
961
- scenarios.emptyContainer,
962
- (root) => {
963
- configureContainer('empty-container');
964
- const element = root.querySelector('#above');
92
+ var safeTarget = function safeTarget(n, fn) {
93
+ return n ? fn(n) : 'NOT FOUND';
94
+ };
965
95
 
966
- const {left, width, top, height} = element.getBoundingClientRect();
967
- const x = left + width / 2;
968
- const y = top + height + 1; // just inside the empty container
96
+ var setupContainers = function setupContainers() {
97
+ (0, _container12.configureDefaults)({
98
+ selector: '.spottable'
99
+ });
100
+ (0, _container12.configureContainer)(_container12.rootContainerId);
101
+ };
969
102
 
970
- expect(safeTarget(
971
- getTargetByDirectionFromPosition('down', {x, y}, rootContainerId),
972
- t => t.id
973
- )).toBe('below');
974
- }
975
- ));
976
- });
977
- });
103
+ var teardownContainers = function teardownContainers() {
104
+ // clean up any containers we create for safe tests
105
+ (0, _container12.getAllContainerIds)().forEach(_container12.removeContainer);
106
+ (0, _container12.setDefaultContainer)();
107
+ }; // NOTE: Skipping most tests because JSDOM does not support measurments
108
+
109
+
110
+ describe('target', function () {
111
+ beforeEach(setupContainers);
112
+ afterEach(teardownContainers);
113
+ describe.skip('#getNavigableTarget', function () {
114
+ test('should find spottable parent', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
115
+ var other = root.querySelector('.other');
116
+ var expected = other.parentNode;
117
+ var actual = (0, _target.getNavigableTarget)(other);
118
+ expect(actual).toBe(expected);
119
+ }));
120
+ test('should skip containers', (0, _utils.testScenario)(scenarios.nonSpottableInContainer, function (root) {
121
+ (0, _container12.configureContainer)('first');
122
+ var other = root.querySelector('.other');
123
+ var expected = null;
124
+ var actual = (0, _target.getNavigableTarget)(other);
125
+ expect(actual).toBe(expected);
126
+ }));
127
+ test('should respect container-specific selector', (0, _utils.testScenario)(scenarios.nonSpottableInContainer, function (root) {
128
+ // make '.other' a valid spottable element
129
+ (0, _container12.configureContainer)('first', {
130
+ selector: '.other'
131
+ });
132
+ var other = root.querySelector('.other');
133
+ var expected = other;
134
+ var actual = (0, _target.getNavigableTarget)(other);
135
+ expect(actual).toBe(expected);
136
+ }));
137
+ test('should respect disabled containers', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
138
+ (0, _container12.configureContainer)('third-container');
139
+ var other = root.querySelector("[".concat(_container12.containerAttribute, "='third-container'] .spottable"));
140
+ var expected = null;
141
+ var actual = (0, _target.getNavigableTarget)(other);
142
+ expect(actual).toBe(expected);
143
+ }));
144
+ });
145
+ describe('#getTargetByContainer', function () {
146
+ test('should find spottable element within provided container', (0, _utils.testScenario)(scenarios.complexTree, function () {
147
+ (0, _container12.configureContainer)('first-container');
148
+ var expected = 'spottable';
149
+ var actual = safeTarget((0, _target.getTargetByContainer)('first-container'), function (t) {
150
+ return t.className;
151
+ });
152
+ expect(actual).toBe(expected);
153
+ }));
154
+ test('should return null when container does not contain any spottable elements', (0, _utils.testScenario)(scenarios.nonSpottableInContainer, function () {
155
+ (0, _container12.configureContainer)('first');
156
+ (0, _container12.configureContainer)('second');
157
+ var expected = null;
158
+ var actual = (0, _target.getTargetByContainer)('second');
159
+ expect(actual).toBe(expected);
160
+ }));
161
+ test('should find the first spottable in the root when no container specified', (0, _utils.testScenario)(scenarios.nonSpottableInContainer, function () {
162
+ (0, _container12.configureContainer)('first');
163
+ (0, _container12.configureContainer)('second');
164
+ var expected = 'in-root';
165
+ var actual = safeTarget((0, _target.getTargetByContainer)(), function (t) {
166
+ return t.id;
167
+ });
168
+ expect(actual).toBe(expected);
169
+ }));
170
+ test('should find the first spottable in the default container when set and no container specified', (0, _utils.testScenario)(scenarios.nonSpottableInContainer, function () {
171
+ (0, _container12.configureContainer)('first');
172
+ (0, _container12.configureContainer)('second');
173
+ (0, _container12.setDefaultContainer)('first');
174
+ var expected = 'spottable';
175
+ var actual = safeTarget((0, _target.getTargetByContainer)(), function (t) {
176
+ return t.className;
177
+ });
178
+ expect(actual).toBe(expected);
179
+ }));
180
+ test('should return `default-element` when last focused is unset', (0, _utils.testScenario)(scenarios.grid, function () {
181
+ (0, _container12.configureContainer)('grid', {
182
+ enterTo: 'last-focused',
183
+ defaultElement: '#middle-center'
184
+ });
185
+ var expected = 'middle-center';
186
+ var actual = safeTarget((0, _target.getTargetByContainer)('grid'), function (t) {
187
+ return t.id;
188
+ });
189
+ expect(actual).toBe(expected);
190
+ }));
191
+ test('should return `default-element` when `last-focused` is requested but is unset', (0, _utils.testScenario)(scenarios.grid, function () {
192
+ (0, _container12.configureContainer)('grid', {
193
+ defaultElement: '#middle-center'
194
+ });
195
+ var expected = 'middle-center';
196
+ var actual = safeTarget((0, _target.getTargetByContainer)('grid', 'last-focused'), function (t) {
197
+ return t.id;
198
+ });
199
+ expect(actual).toBe(expected);
200
+ }));
201
+ test('should return default element when configured for `last-focused` but requested `default-element`', (0, _utils.testScenario)(scenarios.grid, function () {
202
+ (0, _container12.configureContainer)('grid', {
203
+ enterTo: 'last-focused',
204
+ lastFocusedElement: document.querySelector('#top-left'),
205
+ defaultElement: '#middle-center'
206
+ });
207
+ var expected = 'middle-center';
208
+ var actual = safeTarget((0, _target.getTargetByContainer)('grid', 'default-element'), function (t) {
209
+ return t.id;
210
+ });
211
+ expect(actual).toBe(expected);
212
+ }));
213
+ test('should return last focused element when configured for `default-element` but requested `last-focused`', (0, _utils.testScenario)(scenarios.grid, function () {
214
+ (0, _container12.configureContainer)('grid', {
215
+ enterTo: 'default-element',
216
+ lastFocusedElement: document.querySelector('#top-left'),
217
+ defaultElement: '#middle-center'
218
+ });
219
+ var expected = 'top-left';
220
+ var actual = safeTarget((0, _target.getTargetByContainer)('grid', 'last-focused'), function (t) {
221
+ return t.id;
222
+ });
223
+ expect(actual).toBe(expected);
224
+ }));
225
+ });
226
+ describe('#getTargetBySelector', function () {
227
+ test('should find spottable element within container when "@" prefix used', (0, _utils.testScenario)(scenarios.nonSpottableInContainer, function () {
228
+ (0, _container12.configureContainer)('first');
229
+ var expected = 'spottable';
230
+ var actual = safeTarget((0, _target.getTargetBySelector)('@first'), function (t) {
231
+ return t.className;
232
+ });
233
+ expect(actual).toBe(expected);
234
+ }));
235
+ test('should find spottable element within container when "#" prefix used', (0, _utils.testScenario)(scenarios.nonSpottableInContainer, function () {
236
+ (0, _container12.configureContainer)('first');
237
+ var expected = 'in-first';
238
+ var actual = safeTarget((0, _target.getTargetBySelector)('#in-first'), function (t) {
239
+ return t.id;
240
+ });
241
+ expect(actual).toBe(expected);
242
+ }));
243
+ test('should return null when the node exists but is not navigable within its container', (0, _utils.testScenario)(scenarios.nonSpottableInContainer, function () {
244
+ (0, _container12.configureContainer)('first', {
245
+ navigableFilter: function navigableFilter() {
246
+ return false;
247
+ }
248
+ });
249
+ var expected = null;
250
+ var actual = (0, _target.getTargetBySelector)('#in-first');
251
+ expect(actual).toBe(expected);
252
+ }));
253
+ test('should return null when the node exists but does not match the container\'s selector', (0, _utils.testScenario)(scenarios.nonSpottableInContainer, function () {
254
+ (0, _container12.configureContainer)('first');
255
+ var expected = null;
256
+ var actual = (0, _target.getTargetBySelector)("[".concat(_container12.containerAttribute, "='first'] .other"));
257
+ expect(actual).toBe(expected);
258
+ }));
259
+ test('should return null for an empty selectors', (0, _utils.testScenario)(scenarios.nonSpottableInContainer, function () {
260
+ var expected = null; // eslint-disable-next-line no-undefined
261
+
262
+ expect((0, _target.getTargetBySelector)(undefined)).toBe(expected);
263
+ expect((0, _target.getTargetBySelector)(null)).toBe(expected);
264
+ expect((0, _target.getTargetBySelector)('')).toBe(expected);
265
+ }));
266
+ });
267
+ describe.skip('#getTargetByDirectionFromElement', function () {
268
+ test('should find target within container by direction', (0, _utils.testScenario)(scenarios.grid, function (root) {
269
+ (0, _container12.configureContainer)('grid');
270
+ var center = root.querySelector('#middle-center');
271
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('up', center), function (t) {
272
+ return t.id;
273
+ })).toBe('top-center');
274
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('down', center), function (t) {
275
+ return t.id;
276
+ })).toBe('bottom-center');
277
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('left', center), function (t) {
278
+ return t.id;
279
+ })).toBe('middle-left');
280
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('right', center), function (t) {
281
+ return t.id;
282
+ })).toBe('middle-right');
283
+ }));
284
+ test('should find target within container from floating element', (0, _utils.testScenario)(scenarios.overlap, function (root) {
285
+ (0, _container12.configureContainer)('grid', {
286
+ enterTo: 'default-element',
287
+ defaultElement: '#bottom-right'
288
+ });
289
+ var overlap = root.querySelector('#over-middle-center');
290
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('down', overlap), function (t) {
291
+ return t.id;
292
+ })).toBe('middle-center');
293
+ }));
294
+ test('should ignore targets outside the bounds of an overflow container', (0, _utils.testScenario)(scenarios.overflow, function (root) {
295
+ (0, _container12.configureContainer)('overflow-container', {
296
+ overflow: true
297
+ });
298
+ var element = root.querySelector('#outside-overflow');
299
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('down', element), function (t) {
300
+ return t.id;
301
+ })).toBe('overflow-within');
302
+ }));
303
+ test('should find target within container larger than overflow container', (0, _utils.testScenario)(scenarios.overflowLargeSubContainer, function (root) {
304
+ (0, _container12.configureContainer)('overflow-container', {
305
+ overflow: true
306
+ });
307
+ (0, _container12.configureContainer)('inside', {
308
+ enterTo: null
309
+ });
310
+ var element = root.querySelector('#outside-overflow');
311
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('down', element), function (t) {
312
+ return t.id;
313
+ })).toBe('in-large-container');
314
+ }));
315
+ test('should find target out of bounds of overflow container from within container', (0, _utils.testScenario)(scenarios.overflow, function (root) {
316
+ (0, _container12.configureContainer)('overflow-container', {
317
+ overflow: true
318
+ });
319
+ var element = root.querySelector('#overflow-within');
320
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('down', element), function (t) {
321
+ return t.id;
322
+ })).toBe('overflow-below');
323
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('up', element), function (t) {
324
+ return t.id;
325
+ })).toBe('overflow-above');
326
+ }));
327
+ test('should stop at restrict="self-only" boundaries', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
328
+ (0, _container12.configureContainer)('first-container', {
329
+ restrict: 'none'
330
+ });
331
+ (0, _container12.configureContainer)('second-container', {
332
+ restrict: 'self-only'
333
+ });
334
+ var element = root.querySelector("[".concat(_container12.containerAttribute, "=\"second-container\"] .spottable"));
335
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('up', element), function (t) {
336
+ return t.id;
337
+ })).toBe('NOT FOUND');
338
+ }));
339
+ test('should respect enterTo="default-element" containers', (0, _utils.testScenario)(scenarios.grid, function (root) {
340
+ (0, _container12.configureContainer)('grid', {
341
+ restrict: 'none',
342
+ enterTo: 'default-element',
343
+ defaultElement: '#bottom-right'
344
+ });
345
+ var element = root.querySelector('#before-grid');
346
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('down', element), function (t) {
347
+ return t.id;
348
+ })).toBe('bottom-right');
349
+ }));
350
+ test('should respect enterTo="last-focused" containers', (0, _utils.testScenario)(scenarios.grid, function (root) {
351
+ (0, _container12.configureContainer)('grid', {
352
+ restrict: 'none',
353
+ enterTo: 'last-focused',
354
+ lastFocusedKey: {
355
+ container: false,
356
+ element: true,
357
+ key: 8
358
+ }
359
+ });
360
+ var element = root.querySelector('#before-grid');
361
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('down', element), function (t) {
362
+ return t.id;
363
+ })).toBe('bottom-right');
364
+ }));
365
+ test('should follow the leaveFor config when no target is found within the container in the given direction', (0, _utils.testScenario)(scenarios.grid, function (root) {
366
+ (0, _container12.configureContainer)('grid', {
367
+ restrict: 'none',
368
+ leaveFor: {
369
+ up: '#after-grid'
370
+ }
371
+ });
372
+ var element = root.querySelector('#top-center');
373
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('up', element), function (t) {
374
+ return t.id;
375
+ })).toBe('after-grid');
376
+ }));
377
+ test('should not follow the leaveFor config when a target is found within the container in the given direction', (0, _utils.testScenario)(scenarios.grid, function (root) {
378
+ (0, _container12.configureContainer)('grid', {
379
+ restrict: 'none',
380
+ leaveFor: {
381
+ up: '#after-grid'
382
+ }
383
+ });
384
+ var element = root.querySelector('#middle-center');
385
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('up', element), function (t) {
386
+ return t.id;
387
+ })).toBe('top-center');
388
+ }));
389
+ test('should not follow the leaveFor config when the selector does not match an element', (0, _utils.testScenario)(scenarios.grid, function (root) {
390
+ (0, _container12.configureContainer)('grid', {
391
+ restrict: 'none',
392
+ leaveFor: {
393
+ up: '#does-not-exist'
394
+ }
395
+ });
396
+ var element = root.querySelector('#top-center');
397
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('up', element), function (t) {
398
+ return t.id;
399
+ })).toBe('before-grid');
400
+ }));
401
+ test('should ignore empty containers', (0, _utils.testScenario)(scenarios.emptyContainer, function (root) {
402
+ (0, _container12.configureContainer)('empty-container');
403
+ var element = root.querySelector('#above');
404
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('down', element), function (t) {
405
+ return t.id;
406
+ })).toBe('below');
407
+ }));
408
+ test('should ignore overlapping empty containers', (0, _utils.testScenario)(scenarios.emptyContainerOverlap, function (root) {
409
+ (0, _container12.configureContainer)('empty-container');
410
+ var element = root.querySelector('#above');
411
+ expect(safeTarget((0, _target.getTargetByDirectionFromElement)('down', element), function (t) {
412
+ return t.id;
413
+ })).toBe('below');
414
+ }));
415
+ });
416
+ describe.skip('#getTargetByDirectionFromPosition', function () {
417
+ test('should find target within container', (0, _utils.testScenario)(scenarios.grid, function (root) {
418
+ (0, _container12.configureContainer)('grid');
419
+ var rect = root.querySelector('#middle-center').getBoundingClientRect();
420
+ var center = {
421
+ x: rect.left + rect.width / 2,
422
+ y: rect.top + rect.height / 2
423
+ };
424
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('up', center, 'grid'), function (t) {
425
+ return t.id;
426
+ })).toBe('top-center');
427
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('down', center, 'grid'), function (t) {
428
+ return t.id;
429
+ })).toBe('bottom-center');
430
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('left', center, 'grid'), function (t) {
431
+ return t.id;
432
+ })).toBe('middle-left');
433
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('right', center, 'grid'), function (t) {
434
+ return t.id;
435
+ })).toBe('middle-right');
436
+ }));
437
+ test('should not find a target when at bounds of container with restrict="self-only"', (0, _utils.testScenario)(scenarios.grid, function (root) {
438
+ (0, _container12.configureContainer)('grid', {
439
+ restrict: 'self-only'
440
+ });
441
+ var rect = root.querySelector('#top-center').getBoundingClientRect();
442
+ var topCenterOfGrid = {
443
+ x: rect.left + rect.width / 2,
444
+ y: rect.top
445
+ };
446
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('up', topCenterOfGrid, 'grid'), function (t) {
447
+ return t.id;
448
+ })).toBe('NOT FOUND');
449
+ }));
450
+ test('should not find a target outside of container when restrict is not set', (0, _utils.testScenario)(scenarios.grid, function (root) {
451
+ (0, _container12.configureContainer)('grid', {
452
+ restrict: 'none'
453
+ });
454
+ var rect = root.querySelector('#top-center').getBoundingClientRect();
455
+ var topCenterOfGrid = {
456
+ x: rect.left + rect.width / 2,
457
+ y: rect.top
458
+ };
459
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('up', topCenterOfGrid, 'grid'), function (t) {
460
+ return t.id;
461
+ })).toBe('before-grid');
462
+ }));
463
+ test('should cascade into unrestricted subcontainers', (0, _utils.testScenario)(scenarios.grid, function (root) {
464
+ (0, _container12.configureContainer)('grid', {
465
+ restrict: 'none'
466
+ });
467
+ var rect = root.querySelector('#top-center').getBoundingClientRect();
468
+ var aboveCenterOfGrid = {
469
+ x: rect.left + rect.width / 2,
470
+ y: rect.top - 1
471
+ };
472
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('down', aboveCenterOfGrid, _container12.rootContainerId), function (t) {
473
+ return t.id;
474
+ })).toBe('top-center');
475
+ }));
476
+ test('should ignore enterTo config of restricted subcontainers', (0, _utils.testScenario)(scenarios.grid, function (root) {
477
+ (0, _container12.configureContainer)('grid', {
478
+ restrict: 'none',
479
+ enterTo: 'default-element',
480
+ defaultElement: '#bottom-right'
481
+ });
482
+ var rect = root.querySelector('#top-center').getBoundingClientRect();
483
+ var aboveCenterOfGrid = {
484
+ x: rect.left + rect.width / 2,
485
+ y: rect.top - 1
486
+ };
487
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('down', aboveCenterOfGrid, _container12.rootContainerId), function (t) {
488
+ return t.id;
489
+ })).toBe('top-center');
490
+ }));
491
+ test('should find target within container from floating element', (0, _utils.testScenario)(scenarios.overlap, function (root) {
492
+ (0, _container12.configureContainer)('grid', {
493
+ enterTo: 'default-element',
494
+ defaultElement: '#bottom-right'
495
+ });
496
+ var overlap = root.querySelector('#over-middle-center');
497
+
498
+ var _overlap$getBoundingC = overlap.getBoundingClientRect(),
499
+ x = _overlap$getBoundingC.left,
500
+ y = _overlap$getBoundingC.top;
501
+
502
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('down', {
503
+ x: x,
504
+ y: y
505
+ }, _container12.rootContainerId), function (t) {
506
+ return t.id;
507
+ })).toBe('middle-center');
508
+ }));
509
+ test('should ignore targets outside the bounds of an overflow container', (0, _utils.testScenario)(scenarios.overflow, function (root) {
510
+ (0, _container12.configureContainer)('overflow-container', {
511
+ overflow: true
512
+ });
513
+ var element = root.querySelector('#outside-overflow');
514
+
515
+ var _element$getBoundingC = element.getBoundingClientRect(),
516
+ x = _element$getBoundingC.left,
517
+ y = _element$getBoundingC.top;
518
+
519
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('down', {
520
+ x: x,
521
+ y: y
522
+ }, _container12.rootContainerId), function (t) {
523
+ return t.id;
524
+ })).toBe('overflow-within');
525
+ }));
526
+ test('should find target within container larger than overflow container', (0, _utils.testScenario)(scenarios.overflowLargeSubContainer, function (root) {
527
+ (0, _container12.configureContainer)('overflow-container', {
528
+ overflow: true
529
+ });
530
+ (0, _container12.configureContainer)('inside', {
531
+ enterTo: null
532
+ });
533
+ var element = root.querySelector('#outside-overflow');
534
+
535
+ var _element$getBoundingC2 = element.getBoundingClientRect(),
536
+ x = _element$getBoundingC2.left,
537
+ y = _element$getBoundingC2.top;
538
+
539
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('down', {
540
+ x: x,
541
+ y: y
542
+ }, _container12.rootContainerId), function (t) {
543
+ return t.id;
544
+ })).toBe('in-large-container');
545
+ }));
546
+ test('should find target out of bounds of overflow container from within container', (0, _utils.testScenario)(scenarios.overflow, function (root) {
547
+ (0, _container12.configureContainer)('overflow-container', {
548
+ overflow: true
549
+ });
550
+ var element = root.querySelector('#overflow-within');
551
+
552
+ var _element$getBoundingC3 = element.getBoundingClientRect(),
553
+ left = _element$getBoundingC3.left,
554
+ width = _element$getBoundingC3.width,
555
+ top = _element$getBoundingC3.top,
556
+ height = _element$getBoundingC3.height;
557
+
558
+ var x = left + width / 2;
559
+ var y = top + height / 2;
560
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('down', {
561
+ x: x,
562
+ y: y + 1
563
+ }, _container12.rootContainerId), function (t) {
564
+ return t.id;
565
+ })).toBe('overflow-below');
566
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('up', {
567
+ x: x,
568
+ y: y - 1
569
+ }, _container12.rootContainerId), function (t) {
570
+ return t.id;
571
+ })).toBe('overflow-above');
572
+ }));
573
+ test('should ignore empty containers', (0, _utils.testScenario)(scenarios.emptyContainer, function (root) {
574
+ (0, _container12.configureContainer)('empty-container');
575
+ var element = root.querySelector('#above');
576
+
577
+ var _element$getBoundingC4 = element.getBoundingClientRect(),
578
+ left = _element$getBoundingC4.left,
579
+ width = _element$getBoundingC4.width,
580
+ top = _element$getBoundingC4.top,
581
+ height = _element$getBoundingC4.height;
582
+
583
+ var x = left + width / 2;
584
+ var y = top + height - 1; // just inside the bottom of 'above'
585
+
586
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('down', {
587
+ x: x,
588
+ y: y
589
+ }, _container12.rootContainerId), function (t) {
590
+ return t.id;
591
+ })).toBe('below');
592
+ }));
593
+ test('should ignore overlapping empty containers', (0, _utils.testScenario)(scenarios.emptyContainer, function (root) {
594
+ (0, _container12.configureContainer)('empty-container');
595
+ var element = root.querySelector('#above');
596
+
597
+ var _element$getBoundingC5 = element.getBoundingClientRect(),
598
+ left = _element$getBoundingC5.left,
599
+ width = _element$getBoundingC5.width,
600
+ top = _element$getBoundingC5.top,
601
+ height = _element$getBoundingC5.height;
602
+
603
+ var x = left + width / 2;
604
+ var y = top + height + 1; // just inside the empty container
605
+
606
+ expect(safeTarget((0, _target.getTargetByDirectionFromPosition)('down', {
607
+ x: x,
608
+ y: y
609
+ }, _container12.rootContainerId), function (t) {
610
+ return t.id;
611
+ })).toBe('below');
612
+ }));
613
+ });
614
+ });