@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,210 +1,221 @@
1
- import {mount} from 'enzyme';
2
- import React from 'react';
3
- import Spotlight from '../../src/spotlight';
4
- import {updatePointerPosition} from '../../src/pointer';
5
-
6
- import SpotlightContainerDecorator from '../SpotlightContainerDecorator';
7
-
8
- import closest from './Element.prototype.closest';
9
-
10
- describe('SpotlightContainerDecorator', () => {
11
-
12
- const hoverPosition = {clientX: 0, clientY: 1};
13
- const unhoverPosition = {clientX: 0, clientY: 0};
14
-
15
- const Div = (props) => (
16
- <div {...props} />
17
- );
18
-
19
- closest(beforeAll, afterAll);
20
-
21
- beforeEach(() => {
22
- Spotlight.setActiveContainer(null);
23
- updatePointerPosition(0, 0);
24
- });
25
-
26
- test('should set itself as the active container on mouse enter', () => {
27
- const Component = SpotlightContainerDecorator(Div);
28
-
29
- const subject = mount(
30
- <Component spotlightId="test-container" />
31
- );
32
-
33
- subject.find(Div).prop('onMouseEnter')(hoverPosition);
34
-
35
- const expected = 'test-container';
36
- const actual = Spotlight.getActiveContainer();
37
-
38
- expect(actual).toBe(expected);
39
- });
40
-
41
- test(
42
- 'should set active container to parent container on mouse leave',
43
- () => {
44
- const Component = SpotlightContainerDecorator(Div);
45
-
46
- const node = document.createElement('div');
47
- const subject = mount(
48
- <Component spotlightId="outer-container">
49
- <Component spotlightId="inner-container" />
50
- </Component>,
51
- {attachTo: node}
52
- );
53
-
54
- const selector = 'div[data-spotlight-id="inner-container"]';
55
- const innerWrapper = subject.find(selector);
56
- const innerNode = node.querySelector(selector);
57
-
58
- // set inner-container as active
59
- innerWrapper.prop('onMouseEnter')(hoverPosition);
60
- updatePointerPosition(0, 1);
61
-
62
- // leave inner-container
63
- innerWrapper.prop('onMouseLeave')({...unhoverPosition, currentTarget: innerNode});
64
-
65
- const expected = 'outer-container';
66
- const actual = Spotlight.getActiveContainer();
67
-
68
- expect(actual).toBe(expected);
69
- }
70
- );
71
-
72
- test(
73
- 'should not set active container on mouse leave if another container is active',
74
- () => {
75
- const Component = SpotlightContainerDecorator(Div);
76
-
77
- const node = document.createElement('div');
78
- const subject = mount(
79
- <Component spotlightId="outer-container">
80
- <Component spotlightId="inner-container" />
81
- <Component spotlightId="self-only-container" />
82
- </Component>,
83
- {attachTo: node}
84
- );
85
-
86
- const selector = 'div[data-spotlight-id="inner-container"]';
87
- const innerWrapper = subject.find(selector);
88
- const innerNode = node.querySelector(selector);
89
-
90
- // set inner-container as active
91
- innerWrapper.prop('onMouseEnter')(hoverPosition);
92
- updatePointerPosition(0, 1);
93
-
94
- // set another container to be active
95
- Spotlight.setActiveContainer('self-only-container');
96
-
97
- // leave inner-container
98
- innerWrapper.prop('onMouseLeave')({...unhoverPosition, currentTarget: innerNode});
99
-
100
- const expected = 'self-only-container';
101
- const actual = Spotlight.getActiveContainer();
102
-
103
- expect(actual).toBe(expected);
104
- }
105
- );
106
-
107
- test(
108
- 'should forward onFocusCapture events',
109
- () => {
110
- const spy = jest.fn();
111
- let focus;
112
-
113
- const Component = SpotlightContainerDecorator(({onFocusCapture}) => {
114
- focus = onFocusCapture;
115
- return <div />;
116
- });
117
- mount(<Component onFocusCapture={spy} />);
118
-
119
- focus({});
120
-
121
- const expected = 1;
122
- const actual = spy.mock.calls.length;
123
- expect(actual).toBe(expected);
124
- }
125
- );
126
-
127
- test(
128
- 'should suppress onFocusCapture events when spotlightDisabled',
129
- () => {
130
- const spy = jest.fn();
131
- let focus;
132
-
133
- const Component = SpotlightContainerDecorator(({onFocusCapture}) => {
134
- focus = onFocusCapture;
135
- return <div />;
136
- });
137
- mount(<Component onFocusCapture={spy} spotlightDisabled />);
138
-
139
- // building out the api called on the event object + target
140
- focus({
141
- stopPropagation: () => true,
142
- target: {
143
- blur: () => true
144
- }
145
- });
146
-
147
- const expected = 0;
148
- const actual = spy.mock.calls.length;
149
- expect(actual).toBe(expected);
150
- }
151
- );
152
-
153
- test(
154
- 'should forward onBlurCapture events',
155
- () => {
156
- const spy = jest.fn();
157
- let blur;
158
-
159
- const Component = SpotlightContainerDecorator(({onBlurCapture}) => {
160
- blur = onBlurCapture;
161
- return <div />;
162
- });
163
- mount(<Component onBlurCapture={spy} spotlightDisabled />);
164
-
165
- // building out the api called on the event object + target
166
- blur({
167
- stopPropagation: () => true,
168
- target: {
169
- blur: () => blur({})
170
- }
171
- });
172
-
173
- const expected = 1;
174
- const actual = spy.mock.calls.length;
175
- expect(actual).toBe(expected);
176
- }
177
- );
178
-
179
- test(
180
- 'should suppress onBlurCapture events when focus was suppressed',
181
- () => {
182
- const spy = jest.fn();
183
- let focus;
184
- let blur;
185
-
186
- const Component = SpotlightContainerDecorator(({onBlurCapture, onFocusCapture}) => {
187
- blur = onBlurCapture;
188
- focus = onFocusCapture;
189
- return <div />;
190
- });
191
- mount(<Component onBlurCapture={spy} spotlightDisabled />);
192
-
193
- // building out the api called on the event object + target
194
- focus({
195
- stopPropagation: () => true,
196
- target: {
197
- // the focus handler calls blur() on the target so we're simulating that here by
198
- // wiring our onBlurCapture handler directly to the invocation. This isn't a
199
- // perfect modeling of the system but serves to validate the callback
200
- // suppression logic.
201
- blur: () => blur({})
202
- }
203
- });
204
-
205
- const expected = 0;
206
- const actual = spy.mock.calls.length;
207
- expect(actual).toBe(expected);
208
- }
209
- );
210
- });
1
+ "use strict";
2
+
3
+ var _enzyme = require("enzyme");
4
+
5
+ var _react = _interopRequireDefault(require("react"));
6
+
7
+ var _spotlight = _interopRequireDefault(require("../../src/spotlight"));
8
+
9
+ var _pointer = require("../../src/pointer");
10
+
11
+ var _SpotlightContainerDecorator = _interopRequireDefault(require("../SpotlightContainerDecorator"));
12
+
13
+ var _ElementPrototype = _interopRequireDefault(require("./Element.prototype.closest"));
14
+
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
16
+
17
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
18
+
19
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
20
+
21
+ 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; }
22
+
23
+ describe('SpotlightContainerDecorator', function () {
24
+ var hoverPosition = {
25
+ clientX: 0,
26
+ clientY: 1
27
+ };
28
+ var unhoverPosition = {
29
+ clientX: 0,
30
+ clientY: 0
31
+ };
32
+
33
+ var Div = function Div(props) {
34
+ return /*#__PURE__*/_react["default"].createElement("div", props);
35
+ };
36
+
37
+ (0, _ElementPrototype["default"])(beforeAll, afterAll);
38
+ beforeEach(function () {
39
+ _spotlight["default"].setActiveContainer(null);
40
+
41
+ (0, _pointer.updatePointerPosition)(0, 0);
42
+ });
43
+ test('should set itself as the active container on mouse enter', function () {
44
+ var Component = (0, _SpotlightContainerDecorator["default"])(Div);
45
+ var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
46
+ spotlightId: "test-container"
47
+ }));
48
+ subject.find(Div).prop('onMouseEnter')(hoverPosition);
49
+ var expected = 'test-container';
50
+
51
+ var actual = _spotlight["default"].getActiveContainer();
52
+
53
+ expect(actual).toBe(expected);
54
+ });
55
+ test('should set active container to parent container on mouse leave', function () {
56
+ var Component = (0, _SpotlightContainerDecorator["default"])(Div);
57
+ var node = document.createElement('div');
58
+ var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
59
+ spotlightId: "outer-container"
60
+ }, /*#__PURE__*/_react["default"].createElement(Component, {
61
+ spotlightId: "inner-container"
62
+ })), {
63
+ attachTo: node
64
+ });
65
+ var selector = 'div[data-spotlight-id="inner-container"]';
66
+ var innerWrapper = subject.find(selector);
67
+ var innerNode = node.querySelector(selector); // set inner-container as active
68
+
69
+ innerWrapper.prop('onMouseEnter')(hoverPosition);
70
+ (0, _pointer.updatePointerPosition)(0, 1); // leave inner-container
71
+
72
+ innerWrapper.prop('onMouseLeave')(_objectSpread(_objectSpread({}, unhoverPosition), {}, {
73
+ currentTarget: innerNode
74
+ }));
75
+ var expected = 'outer-container';
76
+
77
+ var actual = _spotlight["default"].getActiveContainer();
78
+
79
+ expect(actual).toBe(expected);
80
+ });
81
+ test('should not set active container on mouse leave if another container is active', function () {
82
+ var Component = (0, _SpotlightContainerDecorator["default"])(Div);
83
+ var node = document.createElement('div');
84
+ var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
85
+ spotlightId: "outer-container"
86
+ }, /*#__PURE__*/_react["default"].createElement(Component, {
87
+ spotlightId: "inner-container"
88
+ }), /*#__PURE__*/_react["default"].createElement(Component, {
89
+ spotlightId: "self-only-container"
90
+ })), {
91
+ attachTo: node
92
+ });
93
+ var selector = 'div[data-spotlight-id="inner-container"]';
94
+ var innerWrapper = subject.find(selector);
95
+ var innerNode = node.querySelector(selector); // set inner-container as active
96
+
97
+ innerWrapper.prop('onMouseEnter')(hoverPosition);
98
+ (0, _pointer.updatePointerPosition)(0, 1); // set another container to be active
99
+
100
+ _spotlight["default"].setActiveContainer('self-only-container'); // leave inner-container
101
+
102
+
103
+ innerWrapper.prop('onMouseLeave')(_objectSpread(_objectSpread({}, unhoverPosition), {}, {
104
+ currentTarget: innerNode
105
+ }));
106
+ var expected = 'self-only-container';
107
+
108
+ var actual = _spotlight["default"].getActiveContainer();
109
+
110
+ expect(actual).toBe(expected);
111
+ });
112
+ test('should forward onFocusCapture events', function () {
113
+ var spy = jest.fn();
114
+ var focus;
115
+ var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref) {
116
+ var onFocusCapture = _ref.onFocusCapture;
117
+ focus = onFocusCapture;
118
+ return /*#__PURE__*/_react["default"].createElement("div", null);
119
+ });
120
+ (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
121
+ onFocusCapture: spy
122
+ }));
123
+ focus({});
124
+ var expected = 1;
125
+ var actual = spy.mock.calls.length;
126
+ expect(actual).toBe(expected);
127
+ });
128
+ test('should suppress onFocusCapture events when spotlightDisabled', function () {
129
+ var spy = jest.fn();
130
+ var focus;
131
+ var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref2) {
132
+ var onFocusCapture = _ref2.onFocusCapture;
133
+ focus = onFocusCapture;
134
+ return /*#__PURE__*/_react["default"].createElement("div", null);
135
+ });
136
+ (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
137
+ onFocusCapture: spy,
138
+ spotlightDisabled: true
139
+ })); // building out the api called on the event object + target
140
+
141
+ focus({
142
+ stopPropagation: function stopPropagation() {
143
+ return true;
144
+ },
145
+ target: {
146
+ blur: function blur() {
147
+ return true;
148
+ }
149
+ }
150
+ });
151
+ var expected = 0;
152
+ var actual = spy.mock.calls.length;
153
+ expect(actual).toBe(expected);
154
+ });
155
+ test('should forward onBlurCapture events', function () {
156
+ var spy = jest.fn();
157
+
158
+ var _blur;
159
+
160
+ var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref3) {
161
+ var onBlurCapture = _ref3.onBlurCapture;
162
+ _blur = onBlurCapture;
163
+ return /*#__PURE__*/_react["default"].createElement("div", null);
164
+ });
165
+ (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
166
+ onBlurCapture: spy,
167
+ spotlightDisabled: true
168
+ })); // building out the api called on the event object + target
169
+
170
+ _blur({
171
+ stopPropagation: function stopPropagation() {
172
+ return true;
173
+ },
174
+ target: {
175
+ blur: function blur() {
176
+ return _blur({});
177
+ }
178
+ }
179
+ });
180
+
181
+ var expected = 1;
182
+ var actual = spy.mock.calls.length;
183
+ expect(actual).toBe(expected);
184
+ });
185
+ test('should suppress onBlurCapture events when focus was suppressed', function () {
186
+ var spy = jest.fn();
187
+ var focus;
188
+
189
+ var _blur2;
190
+
191
+ var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref4) {
192
+ var onBlurCapture = _ref4.onBlurCapture,
193
+ onFocusCapture = _ref4.onFocusCapture;
194
+ _blur2 = onBlurCapture;
195
+ focus = onFocusCapture;
196
+ return /*#__PURE__*/_react["default"].createElement("div", null);
197
+ });
198
+ (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
199
+ onBlurCapture: spy,
200
+ spotlightDisabled: true
201
+ })); // building out the api called on the event object + target
202
+
203
+ focus({
204
+ stopPropagation: function stopPropagation() {
205
+ return true;
206
+ },
207
+ target: {
208
+ // the focus handler calls blur() on the target so we're simulating that here by
209
+ // wiring our onBlurCapture handler directly to the invocation. This isn't a
210
+ // perfect modeling of the system but serves to validate the callback
211
+ // suppression logic.
212
+ blur: function blur() {
213
+ return _blur2({});
214
+ }
215
+ }
216
+ });
217
+ var expected = 0;
218
+ var actual = spy.mock.calls.length;
219
+ expect(actual).toBe(expected);
220
+ });
221
+ });