@enact/spotlight 4.7.1 → 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/CHANGELOG.md +6 -0
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +34 -48
- package/package.json +2 -2
- 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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
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
|
+
|
|
5
11
|
## [4.7.1] - 2023-06-02
|
|
6
12
|
|
|
7
13
|
No significant changes.
|
|
@@ -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,17 +101,14 @@ 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
|
};
|
|
@@ -134,8 +120,8 @@ var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (confi
|
|
|
134
120
|
ev.preventDefault();
|
|
135
121
|
}
|
|
136
122
|
setTimeout(function () {
|
|
137
|
-
if (!
|
|
138
|
-
setInputType('key');
|
|
123
|
+
if (!(0, _inputType.getInputInfo)().activated) {
|
|
124
|
+
(0, _inputType.setInputType)('key');
|
|
139
125
|
}
|
|
140
126
|
_this.applyInputType();
|
|
141
127
|
}, 0);
|
|
@@ -143,14 +129,14 @@ var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (confi
|
|
|
143
129
|
// For mouse input
|
|
144
130
|
_this.handlePointerMove = function (ev) {
|
|
145
131
|
if (ev.pointerType === 'mouse') {
|
|
146
|
-
setInputType('mouse');
|
|
132
|
+
(0, _inputType.setInputType)('mouse');
|
|
147
133
|
_this.applyInputType();
|
|
148
134
|
}
|
|
149
135
|
};
|
|
150
136
|
// For touch input
|
|
151
137
|
_this.handlePointerOver = function (ev) {
|
|
152
138
|
if (ev.pointerType === 'touch') {
|
|
153
|
-
setInputType('touch');
|
|
139
|
+
(0, _inputType.setInputType)('touch');
|
|
154
140
|
_this.applyInputType();
|
|
155
141
|
}
|
|
156
142
|
};
|
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,7 +24,7 @@
|
|
|
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
30
|
"ramda": "^0.29.0",
|
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) {
|