@enact/spotlight 4.7.0 → 4.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Accelerator/Accelerator.js +36 -40
- package/CHANGELOG.md +14 -0
- package/README.md +2 -2
- package/SpotlightContainerDecorator/SpotlightContainer.js +1 -2
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +37 -20
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +37 -54
- package/package.json +3 -3
- package/src/inputType.js +56 -0
- package/src/spotlight.js +2 -1
- package/src/tests/inputType-specs.js +11 -0
- package/src/tests/utils-specs.js +87 -0
- package/src/tests/utils.js +6 -1
|
@@ -31,6 +31,17 @@ function Accelerator() {
|
|
|
31
31
|
var _this = this;
|
|
32
32
|
var frequency = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [3, 3, 3, 2, 2, 2, 1];
|
|
33
33
|
_classCallCheck(this, Accelerator);
|
|
34
|
+
/**
|
|
35
|
+
* Called with the current keydown event and callback, which will be called when the event is
|
|
36
|
+
* allowed through.
|
|
37
|
+
*
|
|
38
|
+
* @function
|
|
39
|
+
* @param {Object} event - The current event to validate.
|
|
40
|
+
* @param {Function} callback - The callback to execute.
|
|
41
|
+
* @returns {Boolean} `true` if the event was consumed by processKey and callback was not called
|
|
42
|
+
* @public
|
|
43
|
+
* @memberof spotlight/Accelerator.Accelerator.prototype
|
|
44
|
+
*/
|
|
34
45
|
this.processKey = function (event, callback) {
|
|
35
46
|
switch (event.type) {
|
|
36
47
|
case 'keydown':
|
|
@@ -68,6 +79,14 @@ function Accelerator() {
|
|
|
68
79
|
return callback(event);
|
|
69
80
|
}
|
|
70
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* Resets the Accelerator instance to the default values.
|
|
84
|
+
*
|
|
85
|
+
* @function
|
|
86
|
+
* @returns {undefined}
|
|
87
|
+
* @public
|
|
88
|
+
* @memberof spotlight/Accelerator.Accelerator.prototype
|
|
89
|
+
*/
|
|
71
90
|
this.reset = function () {
|
|
72
91
|
_this.skipped = 0;
|
|
73
92
|
_this.time = 0;
|
|
@@ -75,9 +94,25 @@ function Accelerator() {
|
|
|
75
94
|
_this.canceled = false;
|
|
76
95
|
_this.accelerating = false;
|
|
77
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* Cancels the Accelerator.
|
|
99
|
+
*
|
|
100
|
+
* @function
|
|
101
|
+
* @returns {undefined}
|
|
102
|
+
* @public
|
|
103
|
+
* @memberof spotlight/Accelerator.Accelerator.prototype
|
|
104
|
+
*/
|
|
78
105
|
this.cancel = function () {
|
|
79
106
|
_this.canceled = true;
|
|
80
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Verifies that the Accelerator is active.
|
|
110
|
+
*
|
|
111
|
+
* @function
|
|
112
|
+
* @returns {Boolean} `true` if the Accelerator is active; otherwise, `false`.
|
|
113
|
+
* @public
|
|
114
|
+
* @memberof spotlight/Accelerator.Accelerator.prototype
|
|
115
|
+
*/
|
|
81
116
|
this.isAccelerating = function () {
|
|
82
117
|
return _this.accelerating;
|
|
83
118
|
};
|
|
@@ -130,46 +165,7 @@ function Accelerator() {
|
|
|
130
165
|
* @public
|
|
131
166
|
*/
|
|
132
167
|
this.frequency = frequency;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Called with the current keydown event and callback, which will be called when the event is
|
|
137
|
-
* allowed through.
|
|
138
|
-
*
|
|
139
|
-
* @function
|
|
140
|
-
* @param {Object} event - The current event to validate.
|
|
141
|
-
* @param {Function} callback - The callback to execute.
|
|
142
|
-
* @returns {Boolean} `true` if the event was consumed by processKey and callback was not called
|
|
143
|
-
* @public
|
|
144
|
-
* @memberof spotlight/Accelerator.Accelerator.prototype
|
|
145
|
-
*/
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Resets the Accelerator instance to the default values.
|
|
149
|
-
*
|
|
150
|
-
* @function
|
|
151
|
-
* @returns {undefined}
|
|
152
|
-
* @public
|
|
153
|
-
* @memberof spotlight/Accelerator.Accelerator.prototype
|
|
154
|
-
*/
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Cancels the Accelerator.
|
|
158
|
-
*
|
|
159
|
-
* @function
|
|
160
|
-
* @returns {undefined}
|
|
161
|
-
* @public
|
|
162
|
-
* @memberof spotlight/Accelerator.Accelerator.prototype
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Verifies that the Accelerator is active.
|
|
167
|
-
*
|
|
168
|
-
* @function
|
|
169
|
-
* @returns {Boolean} `true` if the Accelerator is active; otherwise, `false`.
|
|
170
|
-
* @public
|
|
171
|
-
* @memberof spotlight/Accelerator.Accelerator.prototype
|
|
172
|
-
*/);
|
|
168
|
+
});
|
|
173
169
|
exports.Accelerator = Accelerator;
|
|
174
170
|
var _default = Accelerator;
|
|
175
171
|
exports["default"] = _default;
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
The following is a curated list of changes in the Enact spotlight module, newest changes on the top.
|
|
4
4
|
|
|
5
|
+
## [4.7.2] - 2023-07-14
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `spotlight` to not show the focus effect when pointer mode is changed to `false` by touch while an app is loading
|
|
10
|
+
|
|
11
|
+
## [4.7.1] - 2023-06-02
|
|
12
|
+
|
|
13
|
+
No significant changes.
|
|
14
|
+
|
|
15
|
+
## [4.5.3] - 2023-04-06
|
|
16
|
+
|
|
17
|
+
No significant changes.
|
|
18
|
+
|
|
5
19
|
## [4.7.0] - 2023-04-25
|
|
6
20
|
|
|
7
21
|
### Fixed
|
package/README.md
CHANGED
|
@@ -30,8 +30,8 @@ See the [docs](docs/) for more information.
|
|
|
30
30
|
|
|
31
31
|
## Additional Information
|
|
32
32
|
|
|
33
|
-
When using `@enact/
|
|
34
|
-
|
|
33
|
+
When using `@enact/sandstone`, the `SpotlightRootDecorator` is applied automatically by
|
|
34
|
+
`@enact/sandstone/ThemeDecorator`.
|
|
35
35
|
|
|
36
36
|
## Acknowledgments
|
|
37
37
|
|
|
@@ -20,14 +20,13 @@ var isNewPointerPosition = function isNewPointerPosition(ev) {
|
|
|
20
20
|
return (0, _pointer.hasPointerMoved)(ev.clientX, ev.clientY);
|
|
21
21
|
};
|
|
22
22
|
var SpotlightContainer = /*#__PURE__*/function () {
|
|
23
|
-
// set up context and props so we can use handle binding
|
|
24
|
-
|
|
25
23
|
function SpotlightContainer(_ref) {
|
|
26
24
|
var _this = this;
|
|
27
25
|
var containerConfig = _ref.containerConfig,
|
|
28
26
|
navigableFilter = _ref.navigableFilter,
|
|
29
27
|
preserveId = _ref.preserveId;
|
|
30
28
|
_classCallCheck(this, SpotlightContainer);
|
|
29
|
+
// set up context and props so we can use handle binding
|
|
31
30
|
this.context = {};
|
|
32
31
|
this.props = {};
|
|
33
32
|
this.navigableFilter = function (elem) {
|
|
@@ -9,6 +9,8 @@ var _spotlight = _interopRequireDefault(require("../../src/spotlight"));
|
|
|
9
9
|
var _ElementPrototype = _interopRequireDefault(require("./Element.prototype.closest"));
|
|
10
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
13
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
16
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -32,21 +34,26 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
32
34
|
_spotlight["default"].setActiveContainer(null);
|
|
33
35
|
(0, _pointer.updatePointerPosition)(0, 0);
|
|
34
36
|
});
|
|
35
|
-
test('should set itself as the active container on mouse enter', function () {
|
|
37
|
+
test('should set itself as the active container on mouse enter', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
36
38
|
var Component = (0, _SpotlightContainerDecorator["default"])(Div);
|
|
39
|
+
var user = _userEvent["default"].setup();
|
|
37
40
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
38
41
|
"data-testid": testId,
|
|
39
42
|
spotlightId: "test-container"
|
|
40
43
|
}));
|
|
41
44
|
var component = _react.screen.getByTestId(testId);
|
|
42
|
-
|
|
45
|
+
yield user.pointer({
|
|
46
|
+
target: component,
|
|
47
|
+
coords: hoverPosition
|
|
48
|
+
});
|
|
43
49
|
var expected = 'test-container';
|
|
44
50
|
var actual = _spotlight["default"].getActiveContainer();
|
|
45
51
|
expect(actual).toBe(expected);
|
|
46
|
-
});
|
|
47
|
-
test('should set active container to parent container on mouse leave', function () {
|
|
52
|
+
}));
|
|
53
|
+
test('should set active container to parent container on mouse leave', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
48
54
|
var Component = (0, _SpotlightContainerDecorator["default"])(Div);
|
|
49
55
|
var node = document.createElement('div');
|
|
56
|
+
var user = _userEvent["default"].setup();
|
|
50
57
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
51
58
|
spotlightId: "outer-container",
|
|
52
59
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
@@ -59,18 +66,25 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
59
66
|
var component = _react.screen.getByTestId(testId);
|
|
60
67
|
|
|
61
68
|
// set inner-container as active
|
|
62
|
-
|
|
69
|
+
yield user.pointer({
|
|
70
|
+
target: component,
|
|
71
|
+
coords: hoverPosition
|
|
72
|
+
});
|
|
63
73
|
(0, _pointer.updatePointerPosition)(0, 1);
|
|
64
74
|
|
|
65
75
|
// leave inner-container
|
|
66
|
-
|
|
76
|
+
yield user.pointer({
|
|
77
|
+
target: component.parentNode,
|
|
78
|
+
coords: unhoverPosition
|
|
79
|
+
});
|
|
67
80
|
var expected = 'outer-container';
|
|
68
81
|
var actual = _spotlight["default"].getActiveContainer();
|
|
69
82
|
expect(actual).toBe(expected);
|
|
70
|
-
});
|
|
71
|
-
test('should not set active container on mouse leave if another container is active', function () {
|
|
83
|
+
}));
|
|
84
|
+
test('should not set active container on mouse leave if another container is active', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
72
85
|
var Component = (0, _SpotlightContainerDecorator["default"])(Div);
|
|
73
86
|
var node = document.createElement('div');
|
|
87
|
+
var user = _userEvent["default"].setup();
|
|
74
88
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(Component, {
|
|
75
89
|
spotlightId: "outer-container",
|
|
76
90
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
@@ -85,23 +99,26 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
85
99
|
var component = _react.screen.getByTestId(testId);
|
|
86
100
|
|
|
87
101
|
// set inner-container as active
|
|
88
|
-
|
|
102
|
+
yield user.pointer({
|
|
103
|
+
target: component,
|
|
104
|
+
coords: hoverPosition
|
|
105
|
+
});
|
|
89
106
|
(0, _pointer.updatePointerPosition)(0, 1);
|
|
90
107
|
|
|
91
108
|
// set another container to be active
|
|
92
109
|
_spotlight["default"].setActiveContainer('self-only-container');
|
|
93
110
|
|
|
94
111
|
// leave inner-container
|
|
95
|
-
|
|
112
|
+
yield user.unhover(component);
|
|
96
113
|
var expected = 'self-only-container';
|
|
97
114
|
var actual = _spotlight["default"].getActiveContainer();
|
|
98
115
|
expect(actual).toBe(expected);
|
|
99
|
-
});
|
|
116
|
+
}));
|
|
100
117
|
test('should forward onFocusCapture events', function () {
|
|
101
118
|
var spy = jest.fn();
|
|
102
119
|
var focus;
|
|
103
|
-
var Component = (0, _SpotlightContainerDecorator["default"])(function (
|
|
104
|
-
var onFocusCapture =
|
|
120
|
+
var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref4) {
|
|
121
|
+
var onFocusCapture = _ref4.onFocusCapture;
|
|
105
122
|
focus = onFocusCapture;
|
|
106
123
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
107
124
|
});
|
|
@@ -115,8 +132,8 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
115
132
|
test('should suppress onFocusCapture events when spotlightDisabled', function () {
|
|
116
133
|
var spy = jest.fn();
|
|
117
134
|
var focus;
|
|
118
|
-
var Component = (0, _SpotlightContainerDecorator["default"])(function (
|
|
119
|
-
var onFocusCapture =
|
|
135
|
+
var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref5) {
|
|
136
|
+
var onFocusCapture = _ref5.onFocusCapture;
|
|
120
137
|
focus = onFocusCapture;
|
|
121
138
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
122
139
|
});
|
|
@@ -141,8 +158,8 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
141
158
|
test('should forward onBlurCapture events', function () {
|
|
142
159
|
var spy = jest.fn();
|
|
143
160
|
var _blur;
|
|
144
|
-
var Component = (0, _SpotlightContainerDecorator["default"])(function (
|
|
145
|
-
var onBlurCapture =
|
|
161
|
+
var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref6) {
|
|
162
|
+
var onBlurCapture = _ref6.onBlurCapture;
|
|
146
163
|
_blur = onBlurCapture;
|
|
147
164
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
148
165
|
});
|
|
@@ -169,9 +186,9 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
169
186
|
var spy = jest.fn();
|
|
170
187
|
var _blur2;
|
|
171
188
|
var focus;
|
|
172
|
-
var Component = (0, _SpotlightContainerDecorator["default"])(function (
|
|
173
|
-
var onBlurCapture =
|
|
174
|
-
onFocusCapture =
|
|
189
|
+
var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref7) {
|
|
190
|
+
var onBlurCapture = _ref7.onBlurCapture,
|
|
191
|
+
onFocusCapture = _ref7.onFocusCapture;
|
|
175
192
|
_blur2 = onBlurCapture;
|
|
176
193
|
focus = onFocusCapture;
|
|
177
194
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
@@ -3,13 +3,33 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.SpotlightRootDecorator = void 0;
|
|
7
|
+
Object.defineProperty(exports, "activateInputType", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _inputType.activateInputType;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
exports["default"] = void 0;
|
|
14
|
+
Object.defineProperty(exports, "getInputType", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _inputType.getInputType;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "setInputType", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _inputType.setInputType;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
7
26
|
var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
|
|
8
27
|
var _keymap = require("@enact/core/keymap");
|
|
9
28
|
var _react = require("react");
|
|
10
|
-
var _spotlight = _interopRequireDefault(require("../src/spotlight"));
|
|
11
29
|
var _Spottable = require("../Spottable");
|
|
12
30
|
var _container = require("../src/container");
|
|
31
|
+
var _inputType = require("../src/inputType");
|
|
32
|
+
var _spotlight = _interopRequireDefault(require("../src/spotlight"));
|
|
13
33
|
require("../styles/debug.less");
|
|
14
34
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
35
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -33,43 +53,12 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
33
53
|
*
|
|
34
54
|
* @module spotlight/SpotlightRootDecorator
|
|
35
55
|
* @exports SpotlightRootDecorator
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
mouse: false,
|
|
43
|
-
touch: false
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var activateInputType = function activateInputType(activated) {
|
|
47
|
-
input.activated = activated;
|
|
48
|
-
};
|
|
49
|
-
exports.activateInputType = activateInputType;
|
|
50
|
-
var getInputType = function getInputType() {
|
|
51
|
-
return Object.keys(input.types).find(function (type) {
|
|
52
|
-
return input.types[type];
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
exports.getInputType = getInputType;
|
|
56
|
-
var setInputType = function setInputType(inputType) {
|
|
57
|
-
if (Object.prototype.hasOwnProperty.call(input.types, inputType) && !input.types[inputType]) {
|
|
58
|
-
Object.keys(input.types).map(function (type) {
|
|
59
|
-
input.types[type] = false;
|
|
60
|
-
});
|
|
61
|
-
input.types[inputType] = true;
|
|
62
|
-
input.applied = false;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Default configuration for SpotlightRootDecorator
|
|
68
|
-
*
|
|
69
|
-
* @hocconfig
|
|
70
|
-
* @memberof spotlight/SpotlightRootDecorator.SpotlightRootDecorator
|
|
71
|
-
*/
|
|
72
|
-
exports.setInputType = setInputType;
|
|
56
|
+
*/ /**
|
|
57
|
+
* Default configuration for SpotlightRootDecorator
|
|
58
|
+
*
|
|
59
|
+
* @hocconfig
|
|
60
|
+
* @memberof spotlight/SpotlightRootDecorator.SpotlightRootDecorator
|
|
61
|
+
*/
|
|
73
62
|
var defaultConfig = {
|
|
74
63
|
/**
|
|
75
64
|
* When `true`, the contents of the component will not receive spotlight focus after being rendered.
|
|
@@ -112,20 +101,18 @@ var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (confi
|
|
|
112
101
|
_this = _super.call(this, props);
|
|
113
102
|
_this.applyInputType = function () {
|
|
114
103
|
if (_assertThisInitialized(_this) && _this.containerNode) {
|
|
115
|
-
|
|
116
|
-
_this.containerNode.classList.toggle('spotlight-input-' + type, input.types[type]);
|
|
117
|
-
});
|
|
118
|
-
input.applied = true;
|
|
104
|
+
(0, _inputType.applyInputTypeToNode)(_this.containerNode);
|
|
119
105
|
}
|
|
120
106
|
};
|
|
121
107
|
_this.handleFocusInBeforeMount = function () {
|
|
122
108
|
_this.hasFocusedIn = true;
|
|
123
109
|
};
|
|
124
110
|
_this.handleFocusIn = function () {
|
|
125
|
-
if (!
|
|
111
|
+
if (!(0, _inputType.getInputInfo)().applied) {
|
|
126
112
|
_this.applyInputType();
|
|
127
113
|
}
|
|
128
114
|
};
|
|
115
|
+
// For key input
|
|
129
116
|
_this.handleKeyDown = function (ev) {
|
|
130
117
|
var keyCode = ev.keyCode;
|
|
131
118
|
if ((0, _keymap.is)('enter', keyCode) && _this.containerNode.classList.contains('spotlight-input-touch')) {
|
|
@@ -133,21 +120,23 @@ var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (confi
|
|
|
133
120
|
ev.preventDefault();
|
|
134
121
|
}
|
|
135
122
|
setTimeout(function () {
|
|
136
|
-
if (!
|
|
137
|
-
setInputType('key');
|
|
123
|
+
if (!(0, _inputType.getInputInfo)().activated) {
|
|
124
|
+
(0, _inputType.setInputType)('key');
|
|
138
125
|
}
|
|
139
126
|
_this.applyInputType();
|
|
140
127
|
}, 0);
|
|
141
128
|
};
|
|
129
|
+
// For mouse input
|
|
142
130
|
_this.handlePointerMove = function (ev) {
|
|
143
131
|
if (ev.pointerType === 'mouse') {
|
|
144
|
-
setInputType('mouse');
|
|
132
|
+
(0, _inputType.setInputType)('mouse');
|
|
145
133
|
_this.applyInputType();
|
|
146
134
|
}
|
|
147
135
|
};
|
|
136
|
+
// For touch input
|
|
148
137
|
_this.handlePointerOver = function (ev) {
|
|
149
138
|
if (ev.pointerType === 'touch') {
|
|
150
|
-
setInputType('touch');
|
|
139
|
+
(0, _inputType.setInputType)('touch');
|
|
151
140
|
_this.applyInputType();
|
|
152
141
|
}
|
|
153
142
|
};
|
|
@@ -216,12 +205,6 @@ var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (confi
|
|
|
216
205
|
});
|
|
217
206
|
}
|
|
218
207
|
}
|
|
219
|
-
|
|
220
|
-
// For key input
|
|
221
|
-
|
|
222
|
-
// For mouse input
|
|
223
|
-
|
|
224
|
-
// For touch input
|
|
225
208
|
}, {
|
|
226
209
|
key: "render",
|
|
227
210
|
value: function render() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/spotlight",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.2",
|
|
4
4
|
"description": "A focus management library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@enact/core": "^4.7.
|
|
27
|
+
"@enact/core": "^4.7.2",
|
|
28
28
|
"classnames": "^2.3.2",
|
|
29
29
|
"prop-types": "^15.8.1",
|
|
30
|
-
"ramda": "^0.
|
|
30
|
+
"ramda": "^0.29.0",
|
|
31
31
|
"react": "^18.2.0",
|
|
32
32
|
"react-dom": "^18.2.0",
|
|
33
33
|
"warning": "^4.0.3"
|
package/src/inputType.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setInputType = exports.getInputType = exports.getInputInfo = exports.applyInputTypeToNode = exports.activateInputType = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Exports methods for working with inputType in spotlight
|
|
9
|
+
*
|
|
10
|
+
* @module spotlight/inputType
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
var input = {
|
|
15
|
+
activated: false,
|
|
16
|
+
applied: false,
|
|
17
|
+
types: {
|
|
18
|
+
key: true,
|
|
19
|
+
mouse: false,
|
|
20
|
+
touch: false
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var activateInputType = function activateInputType(activated) {
|
|
24
|
+
input.activated = activated;
|
|
25
|
+
};
|
|
26
|
+
exports.activateInputType = activateInputType;
|
|
27
|
+
var getInputType = function getInputType() {
|
|
28
|
+
return Object.keys(input.types).find(function (type) {
|
|
29
|
+
return input.types[type];
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
exports.getInputType = getInputType;
|
|
33
|
+
var setInputType = function setInputType(inputType) {
|
|
34
|
+
if (Object.prototype.hasOwnProperty.call(input.types, inputType) && !input.types[inputType]) {
|
|
35
|
+
Object.keys(input.types).map(function (type) {
|
|
36
|
+
input.types[type] = false;
|
|
37
|
+
});
|
|
38
|
+
input.types[inputType] = true;
|
|
39
|
+
input.applied = false;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.setInputType = setInputType;
|
|
43
|
+
var applyInputTypeToNode = function applyInputTypeToNode(node) {
|
|
44
|
+
Object.keys(input.types).map(function (type) {
|
|
45
|
+
node.classList.toggle('spotlight-input-' + type, input.types[type]);
|
|
46
|
+
});
|
|
47
|
+
input.applied = true;
|
|
48
|
+
};
|
|
49
|
+
exports.applyInputTypeToNode = applyInputTypeToNode;
|
|
50
|
+
var getInputInfo = function getInputInfo() {
|
|
51
|
+
return {
|
|
52
|
+
activated: input.activated,
|
|
53
|
+
applied: input.applied
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.getInputInfo = getInputInfo;
|
package/src/spotlight.js
CHANGED
|
@@ -11,6 +11,7 @@ var _last = _interopRequireDefault(require("ramda/src/last"));
|
|
|
11
11
|
var _Accelerator = _interopRequireDefault(require("../Accelerator"));
|
|
12
12
|
var _Spottable = require("../Spottable");
|
|
13
13
|
var _Pause = require("../Pause");
|
|
14
|
+
var _inputType = require("./inputType");
|
|
14
15
|
var _utils = require("./utils");
|
|
15
16
|
var _container = require("./container");
|
|
16
17
|
var _pointer = require("./pointer");
|
|
@@ -145,7 +146,7 @@ var Spotlight = function () {
|
|
|
145
146
|
if (!elem) {
|
|
146
147
|
return false;
|
|
147
148
|
}
|
|
148
|
-
if ((0, _pointer.getPointerMode)() && !fromPointer && typeof window !== 'undefined' && (!window.PalmSystem || (_window$PalmSystem$cu = window.PalmSystem.cursor) !== null && _window$PalmSystem$cu !== void 0 && _window$PalmSystem$cu.visibility)) {
|
|
149
|
+
if ((0, _pointer.getPointerMode)() && !fromPointer && ((0, _inputType.getInputType)() === 'touch' || typeof window !== 'undefined' && (!window.PalmSystem || (_window$PalmSystem$cu = window.PalmSystem.cursor) !== null && _window$PalmSystem$cu !== void 0 && _window$PalmSystem$cu.visibility))) {
|
|
149
150
|
(0, _container.setContainerLastFocusedElement)(elem, containerIds);
|
|
150
151
|
return false;
|
|
151
152
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _inputType = require("../inputType");
|
|
4
|
+
describe('inputType', function () {
|
|
5
|
+
test('should set input type properly in internal variable', function () {
|
|
6
|
+
(0, _inputType.setInputType)('touch');
|
|
7
|
+
var expected = 'touch';
|
|
8
|
+
var actual = (0, _inputType.getInputType)();
|
|
9
|
+
expect(actual).toBe(expected);
|
|
10
|
+
});
|
|
11
|
+
});
|
package/src/tests/utils-specs.js
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _utils = require("../utils");
|
|
4
|
+
var _utils2 = require("./utils");
|
|
5
|
+
var focusable = function focusable(props) {
|
|
6
|
+
if (!props) {
|
|
7
|
+
props = {};
|
|
8
|
+
}
|
|
9
|
+
var nodeObject = {
|
|
10
|
+
id: 'child',
|
|
11
|
+
tabindex: 0
|
|
12
|
+
};
|
|
13
|
+
Object.keys(props).forEach(function (key) {
|
|
14
|
+
nodeObject[key] = props[key];
|
|
15
|
+
});
|
|
16
|
+
return (0, _utils2.node)(nodeObject);
|
|
17
|
+
};
|
|
18
|
+
var scenarios = {
|
|
19
|
+
tabIndexMinusOne: (0, _utils2.node)({
|
|
20
|
+
id: 'child',
|
|
21
|
+
tabindex: -1
|
|
22
|
+
}),
|
|
23
|
+
focusable: focusable(),
|
|
24
|
+
button: focusable({
|
|
25
|
+
tag: 'button'
|
|
26
|
+
}),
|
|
27
|
+
buttonWithDisabled: focusable({
|
|
28
|
+
tag: 'button',
|
|
29
|
+
valueOnlyAttribute: 'disabled'
|
|
30
|
+
}),
|
|
31
|
+
link: focusable({
|
|
32
|
+
tag: 'a',
|
|
33
|
+
href: 'www.enactjs.com'
|
|
34
|
+
}),
|
|
35
|
+
input: focusable({
|
|
36
|
+
tag: 'input'
|
|
37
|
+
})
|
|
38
|
+
};
|
|
4
39
|
describe('utils', function () {
|
|
5
40
|
describe('#getPointRect', function () {
|
|
6
41
|
test('should return an rect value calculated based on given position', function () {
|
|
@@ -51,4 +86,56 @@ describe('utils', function () {
|
|
|
51
86
|
expect(actual).toEqual(expected);
|
|
52
87
|
});
|
|
53
88
|
});
|
|
89
|
+
describe('#isStandardFocusable', function () {
|
|
90
|
+
beforeEach(function () {
|
|
91
|
+
global.Element.prototype.getBoundingClientRect = jest.fn(function () {
|
|
92
|
+
return {
|
|
93
|
+
height: 100,
|
|
94
|
+
width: 100
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
test('should return false if tabIndex < 0', (0, _utils2.testScenario)(scenarios.tabIndexMinusOne, function (root) {
|
|
99
|
+
var child = root.querySelector('#child');
|
|
100
|
+
var expected = false;
|
|
101
|
+
var actual = (0, _utils.isStandardFocusable)(child);
|
|
102
|
+
expect(actual).toEqual(expected);
|
|
103
|
+
}));
|
|
104
|
+
test('should return false if hidden', (0, _utils2.testScenario)(scenarios.focusable, function (root) {
|
|
105
|
+
var child = root.querySelector('#child');
|
|
106
|
+
child.getBoundingClientRect = jest.fn(function () {
|
|
107
|
+
return {
|
|
108
|
+
height: 0,
|
|
109
|
+
width: 0
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
var expected = false;
|
|
113
|
+
var actual = (0, _utils.isStandardFocusable)(child);
|
|
114
|
+
expect(actual).toEqual(expected);
|
|
115
|
+
}));
|
|
116
|
+
test('should return true if button tag', (0, _utils2.testScenario)(scenarios.button, function (root) {
|
|
117
|
+
var child = root.querySelector('#child');
|
|
118
|
+
var expected = true;
|
|
119
|
+
var actual = (0, _utils.isStandardFocusable)(child);
|
|
120
|
+
expect(actual).toEqual(expected);
|
|
121
|
+
}));
|
|
122
|
+
test('should return false if button tag with disabled', (0, _utils2.testScenario)(scenarios.buttonWithDisabled, function (root) {
|
|
123
|
+
var child = root.querySelector('#child');
|
|
124
|
+
var expected = false;
|
|
125
|
+
var actual = (0, _utils.isStandardFocusable)(child);
|
|
126
|
+
expect(actual).toEqual(expected);
|
|
127
|
+
}));
|
|
128
|
+
test('should return true if A tag with href', (0, _utils2.testScenario)(scenarios.link, function (root) {
|
|
129
|
+
var child = root.querySelector('#child');
|
|
130
|
+
var expected = true;
|
|
131
|
+
var actual = (0, _utils.isStandardFocusable)(child);
|
|
132
|
+
expect(actual).toEqual(expected);
|
|
133
|
+
}));
|
|
134
|
+
test('should return true if input tag', (0, _utils2.testScenario)(scenarios.input, function (root) {
|
|
135
|
+
var child = root.querySelector('#child');
|
|
136
|
+
var expected = true;
|
|
137
|
+
var actual = (0, _utils.isStandardFocusable)(child);
|
|
138
|
+
expect(actual).toEqual(expected);
|
|
139
|
+
}));
|
|
140
|
+
});
|
|
54
141
|
});
|
package/src/tests/utils.js
CHANGED
|
@@ -46,16 +46,21 @@ var coerceProps = function coerceProps(v) {
|
|
|
46
46
|
var node = function node(props) {
|
|
47
47
|
var children = '';
|
|
48
48
|
var attributes = '';
|
|
49
|
+
var tag = 'div';
|
|
49
50
|
Object.keys(props).forEach(function (key) {
|
|
50
51
|
if (key === 'children') {
|
|
51
52
|
children = props.children;
|
|
53
|
+
} else if (key === 'tag') {
|
|
54
|
+
tag = props[key];
|
|
55
|
+
} else if (key === 'valueOnlyAttribute') {
|
|
56
|
+
attributes += "".concat(props[key], " ");
|
|
52
57
|
} else {
|
|
53
58
|
var value = props[key];
|
|
54
59
|
if (key === 'className') key = 'class';
|
|
55
60
|
attributes += "".concat(key, "=\"").concat(value, "\" ");
|
|
56
61
|
}
|
|
57
62
|
});
|
|
58
|
-
return "<
|
|
63
|
+
return "<".concat(tag, " ").concat(attributes, ">").concat(children, "</").concat(tag, ">");
|
|
59
64
|
};
|
|
60
65
|
exports.node = node;
|
|
61
66
|
var spottable = function spottable(props) {
|