@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,87 +0,0 @@
1
- "use strict";
2
-
3
- var _navigate = _interopRequireDefault(require("../navigate"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6
-
7
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
-
9
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
-
11
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
-
13
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
14
-
15
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
-
17
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
18
-
19
- // loose copy from utils/getRect to fabricate a rect for navigation
20
- function getRect(top, left, height, width, elem) {
21
- var rect = {
22
- left: left,
23
- top: top,
24
- width: width,
25
- height: height
26
- };
27
- rect.element = elem;
28
- rect.right = rect.left + rect.width;
29
- rect.bottom = rect.top + rect.height;
30
- rect.center = {
31
- x: rect.left + Math.floor(rect.width / 2),
32
- y: rect.top + Math.floor(rect.height / 2)
33
- };
34
- rect.center.left = rect.center.right = rect.center.x;
35
- rect.center.top = rect.center.bottom = rect.center.y;
36
- return rect;
37
- }
38
-
39
- describe('navigate', function () {
40
- test('should return the element above when direction="up"', function () {
41
- var targetRect = getRect(100, 100, 10, 10);
42
- var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 100, 10, 10, 'above'], [110, 100, 10, 10, 'below']].map(function (args) {
43
- return getRect.apply(void 0, _toConsumableArray(args));
44
- });
45
- var expected = 'above';
46
- var actual = (0, _navigate["default"])(targetRect, 'up', rects, {});
47
- expect(actual).toBe(expected);
48
- });
49
- test('should return the element to the left when direction="left"', function () {
50
- var targetRect = getRect(100, 100, 10, 10);
51
- var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 100, 10, 10, 'above'], [110, 100, 10, 10, 'below']].map(function (args) {
52
- return getRect.apply(void 0, _toConsumableArray(args));
53
- });
54
- var expected = 'left';
55
- var actual = (0, _navigate["default"])(targetRect, 'left', rects, {});
56
- expect(actual).toBe(expected);
57
- });
58
- test('should return the element below when direction="down"', function () {
59
- var targetRect = getRect(100, 100, 10, 10);
60
- var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 100, 10, 10, 'above'], [110, 100, 10, 10, 'below']].map(function (args) {
61
- return getRect.apply(void 0, _toConsumableArray(args));
62
- });
63
- var expected = 'below';
64
- var actual = (0, _navigate["default"])(targetRect, 'down', rects, {});
65
- expect(actual).toBe(expected);
66
- });
67
- test('should return the element to the right when direction="right"', function () {
68
- var targetRect = getRect(100, 100, 10, 10);
69
- var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 100, 10, 10, 'above'], [110, 100, 10, 10, 'below']].map(function (args) {
70
- return getRect.apply(void 0, _toConsumableArray(args));
71
- });
72
- var expected = 'right';
73
- var actual = (0, _navigate["default"])(targetRect, 'right', rects, {});
74
- expect(actual).toBe(expected);
75
- });
76
- test('should return the element "under" when its center is nearest in that direction', function () {
77
- var targetRect = getRect(105, 100, 10, 10);
78
- var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 90, 30, 30, 'under'], // completely contains the targetRect
79
- [110, 100, 10, 10, 'below']].map(function (args) {
80
- return getRect.apply(void 0, _toConsumableArray(args));
81
- });
82
- expect((0, _navigate["default"])(targetRect, 'up', rects, {})).toBe('under');
83
- expect((0, _navigate["default"])(targetRect, 'down', rects, {})).toBe('below');
84
- expect((0, _navigate["default"])(targetRect, 'left', rects, {})).toBe('left');
85
- expect((0, _navigate["default"])(targetRect, 'right', rects, {})).toBe('right');
86
- });
87
- });
@@ -1,130 +0,0 @@
1
- "use strict";
2
-
3
- var _keymap = require("@enact/core/keymap");
4
-
5
- var _pointer = require("../pointer");
6
-
7
- var reset = function reset() {
8
- (0, _pointer.updatePointerPosition)(null, null);
9
- (0, _pointer.setPointerMode)(true);
10
- };
11
-
12
- describe('pointer', function () {
13
- afterEach(reset);
14
- describe('#getLastPointerPosition', function () {
15
- test('should return an object with x and y keys', function () {
16
- var expected = ['x', 'y'];
17
- var actual = Object.keys((0, _pointer.getLastPointerPosition)());
18
- expect(actual).toEqual(expected);
19
- });
20
- });
21
- describe('#notifyKeyDown', function () {
22
- // notifyKeyDown() will start a job which will set pointer mode for `pointerHide` key
23
- // events. If adding async tests, be sure to pass a callback to notifyKeyDown() to be
24
- // notified when the job completes before continuing.
25
- var keyMap = {
26
- pointerHide: 999,
27
- pointerShow: 888
28
- };
29
- beforeAll(function () {
30
- return (0, _keymap.addAll)(keyMap);
31
- });
32
- afterAll(function () {
33
- return (0, _keymap.removeAll)(keyMap);
34
- });
35
- beforeEach(function () {
36
- // establish a consistent pointer mode state for each test
37
- (0, _pointer.setPointerMode)(false);
38
- });
39
- test('should return true for pointer hide key events', function () {
40
- var expected = true;
41
- var actual = (0, _pointer.notifyKeyDown)(keyMap.pointerHide);
42
- expect(actual).toBe(expected);
43
- });
44
- test('should return true for pointer show key events', function () {
45
- var expected = true;
46
- var actual = (0, _pointer.notifyKeyDown)(keyMap.pointerShow);
47
- expect(actual).toBe(expected);
48
- });
49
- test('should enable pointer mode for pointer show key events', function () {
50
- (0, _pointer.notifyKeyDown)(keyMap.pointerShow);
51
- var expected = true;
52
- var actual = (0, _pointer.getPointerMode)();
53
- expect(actual).toBe(expected);
54
- });
55
- test('should disable pointer mode for pointer show key events', function (done) {
56
- (0, _pointer.setPointerMode)(true);
57
- (0, _pointer.notifyKeyDown)(keyMap.pointerHide, function () {
58
- var expected = false;
59
- var actual = (0, _pointer.getPointerMode)();
60
- expect(actual).toBe(expected);
61
- done();
62
- });
63
- });
64
- test('should disable pointer mode for non-pointer key events', function () {
65
- (0, _pointer.setPointerMode)(true);
66
- (0, _pointer.notifyKeyDown)(12);
67
- var expected = false;
68
- var actual = (0, _pointer.getPointerMode)();
69
- expect(actual).toBe(expected);
70
- });
71
- });
72
- describe('#notifyPointerMove', function () {
73
- test('should update the pointer position if x changes', function () {
74
- var x = 20;
75
- (0, _pointer.notifyPointerMove)(null, null, x, null);
76
- var expected = 20;
77
- var actual = (0, _pointer.getLastPointerPosition)().x;
78
- expect(actual).toBe(expected);
79
- });
80
- test('should update the pointer position if y changes', function () {
81
- var y = 20;
82
- (0, _pointer.notifyPointerMove)(null, null, null, y);
83
- var expected = 20;
84
- var actual = (0, _pointer.getLastPointerPosition)().y;
85
- expect(actual).toBe(expected);
86
- });
87
- test('should enable pointer mode if the pointer positionchanges', function () {
88
- (0, _pointer.setPointerMode)(false);
89
- (0, _pointer.notifyPointerMove)(null, null, 5, 5);
90
- var expected = true;
91
- var actual = (0, _pointer.getPointerMode)();
92
- expect(actual).toBe(expected);
93
- });
94
- test('should return false if the pointer has not moved', function () {
95
- (0, _pointer.notifyPointerMove)(null, null, 5, 5);
96
- var expected = false;
97
- var actual = (0, _pointer.notifyPointerMove)(null, null, 5, 5);
98
- expect(actual).toBe(expected);
99
- });
100
- test('should return true if pointer mode was disabled', function () {
101
- // change into pointer mode indicates a potential for change of focus
102
- (0, _pointer.setPointerMode)(false);
103
- var expected = true;
104
- var actual = (0, _pointer.notifyPointerMove)(null, null, 5, 5);
105
- expect(actual).toBe(expected);
106
- });
107
- test('should return true if the pointer has moved and current is falsy', function () {
108
- var expected = true;
109
- var actual = (0, _pointer.notifyPointerMove)(null, null, 5, 5);
110
- expect(actual).toBe(expected);
111
- });
112
- test('should return false if the pointer has moved and target is within current', function () {
113
- var current = document.createElement('div');
114
- var target = document.createElement('div');
115
- current.appendChild(target);
116
- (0, _pointer.notifyPointerMove)(null, current, 5, 5);
117
- var expected = false;
118
- var actual = (0, _pointer.notifyPointerMove)(current, target, 10, 10);
119
- expect(actual).toBe(expected);
120
- });
121
- test('should return true if the pointer has moved and target is not within current', function () {
122
- var current = document.createElement('div');
123
- var target = document.createElement('div');
124
- (0, _pointer.notifyPointerMove)(null, current, 5, 5);
125
- var expected = true;
126
- var actual = (0, _pointer.notifyPointerMove)(current, target, 10, 10);
127
- expect(actual).toBe(expected);
128
- });
129
- });
130
- });
@@ -1,112 +0,0 @@
1
- "use strict";
2
-
3
- var _container4 = require("../container");
4
-
5
- var _spotlight = _interopRequireDefault(require("../spotlight"));
6
-
7
- var _utils = require("./utils");
8
-
9
- var _container, _container2, _container3;
10
-
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
-
13
- 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; }
14
-
15
- var nonSpottable = function nonSpottable() {
16
- return (0, _utils.node)({
17
- className: 'other'
18
- });
19
- };
20
-
21
- var scenarios = {
22
- complexTree: (0, _utils.join)((0, _utils.spottable)({
23
- 'data-spotlight-id': 's1'
24
- }), (0, _utils.spottable)(nonSpottable()), (0, _utils.container)((_container3 = {}, _defineProperty(_container3, _container4.containerAttribute, 'first-container'), _defineProperty(_container3, "children", (0, _utils.join)((0, _utils.someSpottables)(2), (0, _utils.container)((_container2 = {}, _defineProperty(_container2, _container4.containerAttribute, 'second-container'), _defineProperty(_container2, "children", (0, _utils.join)((0, _utils.spottable)({
25
- id: 'secondContainerFirstSpottable'
26
- }), (0, _utils.someSpottables)(2), (0, _utils.container)((_container = {}, _defineProperty(_container, _container4.containerAttribute, 'third-container'), _defineProperty(_container, 'data-spotlight-container-disabled', true), _defineProperty(_container, "children", (0, _utils.join)((0, _utils.someSpottables)(4), (0, _utils.node)({
27
- id: 'child-of-third'
28
- }))), _container)))), _container2)))), _container3)))
29
- };
30
-
31
- var setupContainers = function setupContainers() {
32
- _spotlight["default"].setPointerMode(false);
33
-
34
- (0, _container4.configureDefaults)({
35
- selector: '.spottable'
36
- });
37
- (0, _container4.configureContainer)(_container4.rootContainerId);
38
- (0, _container4.setLastContainer)(_container4.rootContainerId);
39
- };
40
-
41
- var teardownContainers = function teardownContainers() {
42
- // clean up any containers we create for safe tests
43
- (0, _container4.removeAllContainers)();
44
- };
45
-
46
- var mockFocus = function mockFocus(n) {
47
- var fn = jest.fn().mockImplementation(function () {
48
- return true;
49
- });
50
- Object.defineProperty(n, 'focus', {
51
- get: function get() {
52
- return fn;
53
- }
54
- });
55
- return fn;
56
- };
57
-
58
- describe('Spotlight', function () {
59
- describe('#focus', function () {
60
- beforeEach(setupContainers);
61
- afterEach(teardownContainers);
62
- test('should focus spottable by id', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
63
- var fn = mockFocus(root.querySelector('[data-spotlight-id="s1"]'));
64
-
65
- _spotlight["default"].focus('s1');
66
-
67
- expect(fn).toBeCalled();
68
- }));
69
- test('should focus container by id', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
70
- (0, _container4.configureContainer)('first-container');
71
- var fn = mockFocus(root.querySelector('[data-spotlight-id="first-container"] > .spottable'));
72
-
73
- _spotlight["default"].focus('first-container');
74
-
75
- expect(fn).toBeCalled();
76
- }));
77
- test('should focus spottable by node', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
78
- var n = root.querySelector('[data-spotlight-id="s1"]');
79
- var fn = mockFocus(n);
80
-
81
- _spotlight["default"].focus(n);
82
-
83
- expect(fn).toBeCalled();
84
- }));
85
- test('should focus container by node', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
86
- (0, _container4.configureContainer)('first-container');
87
- var n = root.querySelector('[data-spotlight-id="first-container"]');
88
- var fn = mockFocus(n.querySelector('.spottable'));
89
-
90
- _spotlight["default"].focus(n);
91
-
92
- expect(fn).toBeCalled();
93
- }));
94
- test('should focus spottable by selector', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
95
- var n = root.querySelector('[data-spotlight-id="s1"]');
96
- var fn = mockFocus(n);
97
-
98
- _spotlight["default"].focus('[data-spotlight-id="s1"]');
99
-
100
- expect(fn).toBeCalled();
101
- }));
102
- test('should focus container by node', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
103
- (0, _container4.configureContainer)('first-container');
104
- var n = root.querySelector('[data-spotlight-id="first-container"]');
105
- var fn = mockFocus(n.querySelector('.spottable'));
106
-
107
- _spotlight["default"].focus('[data-spotlight-id="first-container"]');
108
-
109
- expect(fn).toBeCalled();
110
- }));
111
- });
112
- });