@enact/spotlight 4.1.2 → 4.5.0-alpha.1
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.d.ts +2 -5
- package/Accelerator/Accelerator.js +7 -3
- package/CHANGELOG.md +17 -0
- package/Pause/Pause.d.ts +4 -6
- package/Pause/Pause.js +2 -2
- package/Pause/tests/Pause-specs.js +2 -2
- package/README.md +1 -1
- package/SpotlightContainerDecorator/SpotlightContainer.js +4 -4
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +13 -10
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +44 -38
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +106 -52
- package/SpotlightContainerDecorator/useSpotlightContainer.js +4 -2
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +9 -16
- package/Spottable/Spottable.js +11 -9
- package/Spottable/SpottableCore.js +4 -4
- package/Spottable/tests/Spottable-specs.js +66 -37
- package/Spottable/tests/useSpot-specs.js +128 -71
- package/Spottable/useSpottable.js +7 -4
- package/package.json +8 -8
- package/src/container.js +24 -16
- package/src/navigate.js +1 -1
- package/src/spotlight.js +1 -1
- package/src/target.js +3 -3
- package/src/tests/utils.js +2 -2
- package/src/utils.js +11 -9
- package/styles/debug.less +80 -82
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _react = require("@testing-library/react");
|
|
6
|
+
|
|
7
|
+
var _useSpotlightContainer = _interopRequireDefault(require("../useSpotlightContainer"));
|
|
6
8
|
|
|
7
9
|
var _container = require("../../src/container");
|
|
8
10
|
|
|
9
|
-
var
|
|
11
|
+
var _spotlight = _interopRequireDefault(require("../../src/spotlight"));
|
|
10
12
|
|
|
11
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
14
|
|
|
15
|
+
var _excluded = ["containerConfig", "preserveId", "spotlightDisabled", "spotlightId", "spotlightMuted", "spotlightRestrict"];
|
|
16
|
+
|
|
13
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
18
|
|
|
15
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
19
|
+
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; }
|
|
16
20
|
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
21
|
+
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; }
|
|
18
22
|
|
|
19
23
|
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; }
|
|
20
24
|
|
|
@@ -26,6 +30,7 @@ function containerExists(id) {
|
|
|
26
30
|
return (0, _container.getContainerConfig)(id) != null;
|
|
27
31
|
}
|
|
28
32
|
|
|
33
|
+
var testId = 'test-useSpotlightContainer';
|
|
29
34
|
describe('useSpotlightContainer', function () {
|
|
30
35
|
// TODO: Test lifecycle (e.g unload, preserveId)
|
|
31
36
|
function Component(props) {
|
|
@@ -35,7 +40,7 @@ describe('useSpotlightContainer', function () {
|
|
|
35
40
|
spotlightId = props.spotlightId,
|
|
36
41
|
spotlightMuted = props.spotlightMuted,
|
|
37
42
|
spotlightRestrict = props.spotlightRestrict,
|
|
38
|
-
rest = _objectWithoutProperties(props,
|
|
43
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
39
44
|
|
|
40
45
|
var spotlightContainer = (0, _useSpotlightContainer["default"])({
|
|
41
46
|
id: spotlightId,
|
|
@@ -52,77 +57,122 @@ describe('useSpotlightContainer', function () {
|
|
|
52
57
|
|
|
53
58
|
afterEach(_spotlight["default"].clear);
|
|
54
59
|
test('should support omitting the config object', function () {
|
|
55
|
-
function Comp(props) {
|
|
60
|
+
var Comp = function Comp(props) {
|
|
56
61
|
var spotlightContainer = (0, _useSpotlightContainer["default"])();
|
|
57
62
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, props), spotlightContainer.attributes));
|
|
58
|
-
}
|
|
63
|
+
};
|
|
59
64
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
66
|
+
"data-testid": testId
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
var component = _react.screen.getByTestId(testId);
|
|
70
|
+
|
|
71
|
+
var expectedAttribute = 'data-spotlight-container';
|
|
72
|
+
var expectedValue = 'true';
|
|
73
|
+
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
64
74
|
});
|
|
65
75
|
describe('attributes', function () {
|
|
66
76
|
test('should set `data-spotlight-container` attribute', function () {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
78
|
+
"data-testid": testId
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
var component = _react.screen.getByTestId(testId);
|
|
82
|
+
|
|
83
|
+
var expectedAttribute = 'data-spotlight-container';
|
|
84
|
+
var expectedValue = 'true';
|
|
85
|
+
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
71
86
|
});
|
|
72
87
|
test('should generate a `data-spotlight-id` attribute when `id` is unset', function () {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
88
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
89
|
+
"data-testid": testId
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
var component = _react.screen.getByTestId(testId);
|
|
93
|
+
|
|
94
|
+
var expectedAttribute = 'data-spotlight-id';
|
|
95
|
+
var expectedValue = expect.stringMatching(/container-\d+/);
|
|
96
|
+
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
77
97
|
});
|
|
78
98
|
test('should reuse the same generated `data-spotlight-id` attribute on re-render', function () {
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
100
|
+
"data-testid": testId
|
|
101
|
+
})),
|
|
102
|
+
rerender = _render.rerender;
|
|
103
|
+
|
|
104
|
+
var expected = _react.screen.getByTestId(testId).getAttribute('data-spotlight-id');
|
|
105
|
+
|
|
106
|
+
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
107
|
+
"data-testid": testId
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
var actual = _react.screen.getByTestId(testId).getAttribute('data-spotlight-id');
|
|
111
|
+
|
|
112
|
+
expect(actual).toBe(expected);
|
|
84
113
|
});
|
|
85
114
|
test('should set a `data-spotlight-id` attribute when `id` is set', function () {
|
|
86
115
|
var id = 'my-container';
|
|
87
|
-
|
|
116
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
117
|
+
"data-testid": testId,
|
|
88
118
|
spotlightId: id
|
|
89
119
|
}));
|
|
90
|
-
|
|
91
|
-
var
|
|
92
|
-
|
|
120
|
+
|
|
121
|
+
var component = _react.screen.getByTestId(testId);
|
|
122
|
+
|
|
123
|
+
var expectedAttribute = 'data-spotlight-id';
|
|
124
|
+
expect(component).toHaveAttribute(expectedAttribute, id);
|
|
93
125
|
});
|
|
94
126
|
test('should set `data-spotlight-container-disabled` attribute to be falsey when `disabled` is unset', function () {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
127
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
128
|
+
"data-testid": testId
|
|
129
|
+
}));
|
|
130
|
+
|
|
131
|
+
var component = _react.screen.getByTestId(testId);
|
|
132
|
+
|
|
133
|
+
var expectedAttribute = 'data-spotlight-container-disabled';
|
|
134
|
+
expect(component).not.toHaveAttribute(expectedAttribute);
|
|
98
135
|
});
|
|
99
136
|
test('should set `data-spotlight-container-disabled` attribute when `disabled` is set', function () {
|
|
100
|
-
|
|
137
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
138
|
+
"data-testid": testId,
|
|
101
139
|
spotlightDisabled: true
|
|
102
140
|
}));
|
|
103
|
-
|
|
104
|
-
var
|
|
105
|
-
|
|
141
|
+
|
|
142
|
+
var component = _react.screen.getByTestId(testId);
|
|
143
|
+
|
|
144
|
+
var expectedAttribute = 'data-spotlight-container-disabled';
|
|
145
|
+
var expectedValue = 'true';
|
|
146
|
+
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
106
147
|
});
|
|
107
148
|
test('should set `data-spotlight-container-muted` attribute to be falsey when `muted` is unset', function () {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
149
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
150
|
+
"data-testid": testId
|
|
151
|
+
}));
|
|
152
|
+
|
|
153
|
+
var component = _react.screen.getByTestId(testId);
|
|
154
|
+
|
|
155
|
+
var expectedAttribute = 'data-spotlight-container-muted';
|
|
156
|
+
expect(component).not.toHaveAttribute(expectedAttribute);
|
|
111
157
|
});
|
|
112
158
|
test('should set `data-spotlight-container-muted` attribute when `muted` is set', function () {
|
|
113
|
-
|
|
159
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
160
|
+
"data-testid": testId,
|
|
114
161
|
spotlightMuted: true
|
|
115
162
|
}));
|
|
116
|
-
|
|
117
|
-
var
|
|
118
|
-
|
|
163
|
+
|
|
164
|
+
var component = _react.screen.getByTestId(testId);
|
|
165
|
+
|
|
166
|
+
var expectedAttribute = 'data-spotlight-container-muted';
|
|
167
|
+
var expectedValue = 'true';
|
|
168
|
+
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
119
169
|
});
|
|
120
170
|
});
|
|
121
171
|
describe('Spotlight configuration', function () {
|
|
122
172
|
test('should create a new container with the specified id', function () {
|
|
123
173
|
var id = 'my-container';
|
|
124
174
|
expect(containerExists(id)).toBeFalsy();
|
|
125
|
-
(0,
|
|
175
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
126
176
|
spotlightId: id
|
|
127
177
|
}));
|
|
128
178
|
var expected = true;
|
|
@@ -136,12 +186,12 @@ describe('useSpotlightContainer', function () {
|
|
|
136
186
|
restrict: 'self-only',
|
|
137
187
|
defaultElement: 'my-element'
|
|
138
188
|
};
|
|
139
|
-
(0,
|
|
140
|
-
spotlightId: id,
|
|
141
|
-
spotlightRestrict: config.restrict,
|
|
189
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
142
190
|
containerConfig: {
|
|
143
191
|
defaultElement: config.defaultElement
|
|
144
|
-
}
|
|
192
|
+
},
|
|
193
|
+
spotlightId: id,
|
|
194
|
+
spotlightRestrict: config.restrict
|
|
145
195
|
}));
|
|
146
196
|
var expected = config;
|
|
147
197
|
var actual = (0, _container.getContainerConfig)(id);
|
|
@@ -149,13 +199,17 @@ describe('useSpotlightContainer', function () {
|
|
|
149
199
|
});
|
|
150
200
|
test('should update restrict value', function () {
|
|
151
201
|
var id = 'my-container';
|
|
152
|
-
|
|
202
|
+
|
|
203
|
+
var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
153
204
|
spotlightId: id,
|
|
154
205
|
spotlightRestrict: "self-only"
|
|
206
|
+
})),
|
|
207
|
+
rerender = _render2.rerender;
|
|
208
|
+
|
|
209
|
+
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
210
|
+
spotlightId: id,
|
|
211
|
+
spotlightRestrict: "self-first"
|
|
155
212
|
}));
|
|
156
|
-
subject.setProps({
|
|
157
|
-
spotlightRestrict: 'self-first'
|
|
158
|
-
});
|
|
159
213
|
var expected = {
|
|
160
214
|
restrict: 'self-first'
|
|
161
215
|
};
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.useSpotlightContainer = useSpotlightContainer;
|
|
7
6
|
exports["default"] = void 0;
|
|
7
|
+
exports.useSpotlightContainer = useSpotlightContainer;
|
|
8
8
|
|
|
9
9
|
var _useClass = _interopRequireDefault(require("@enact/core/useClass"));
|
|
10
10
|
|
|
@@ -12,6 +12,8 @@ var _react = require("react");
|
|
|
12
12
|
|
|
13
13
|
var _SpotlightContainer = _interopRequireDefault(require("./SpotlightContainer"));
|
|
14
14
|
|
|
15
|
+
var _excluded = ["disabled", "id", "muted", "restrict"];
|
|
16
|
+
|
|
15
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
16
18
|
|
|
17
19
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
@@ -104,7 +106,7 @@ function useSpotlightContainer() {
|
|
|
104
106
|
id = config.id,
|
|
105
107
|
muted = config.muted,
|
|
106
108
|
restrict = config.restrict,
|
|
107
|
-
rest = _objectWithoutProperties(config,
|
|
109
|
+
rest = _objectWithoutProperties(config, _excluded);
|
|
108
110
|
|
|
109
111
|
var spotlightContainer = (0, _useClass["default"])(_SpotlightContainer["default"], rest);
|
|
110
112
|
spotlightContainer.setProps({
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setInputType = exports.getInputType = exports
|
|
6
|
+
exports.setInputType = exports.getInputType = exports["default"] = exports.activateInputType = exports.SpotlightRootDecorator = void 0;
|
|
7
7
|
|
|
8
8
|
var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
|
|
9
9
|
|
|
@@ -23,9 +23,9 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
23
23
|
|
|
24
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
25
25
|
|
|
26
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
26
|
+
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; }
|
|
27
27
|
|
|
28
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
28
|
+
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; }
|
|
29
29
|
|
|
30
30
|
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; }
|
|
31
31
|
|
|
@@ -33,15 +33,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
33
33
|
|
|
34
34
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
35
35
|
|
|
36
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
36
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
37
37
|
|
|
38
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
38
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
39
39
|
|
|
40
40
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
41
41
|
|
|
42
42
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
43
43
|
|
|
44
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
44
|
+
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
45
45
|
|
|
46
46
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
47
47
|
|
|
@@ -122,10 +122,10 @@ var defaultConfig = {
|
|
|
122
122
|
*/
|
|
123
123
|
|
|
124
124
|
var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
|
|
125
|
-
var _class
|
|
125
|
+
var _class;
|
|
126
126
|
|
|
127
127
|
var noAutoFocus = config.noAutoFocus;
|
|
128
|
-
return
|
|
128
|
+
return _class = /*#__PURE__*/function (_Component) {
|
|
129
129
|
_inherits(_class, _Component);
|
|
130
130
|
|
|
131
131
|
var _super = _createSuper(_class);
|
|
@@ -189,13 +189,6 @@ var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (confi
|
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
-
_this.navigableFilter = function (elem) {
|
|
193
|
-
while (elem && elem !== document && elem.nodeType === 1) {
|
|
194
|
-
if (elem.getAttribute('data-spotlight-container-disabled') === 'true') return false;
|
|
195
|
-
elem = elem.parentNode;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
192
|
_this.containerNode = null;
|
|
200
193
|
|
|
201
194
|
if (typeof window === 'object') {
|
|
@@ -276,7 +269,7 @@ var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (confi
|
|
|
276
269
|
}]);
|
|
277
270
|
|
|
278
271
|
return _class;
|
|
279
|
-
}(_react.Component), _class.displayName = 'SpotlightRootDecorator',
|
|
272
|
+
}(_react.Component), _class.displayName = 'SpotlightRootDecorator', _class;
|
|
280
273
|
});
|
|
281
274
|
exports.SpotlightRootDecorator = SpotlightRootDecorator;
|
|
282
275
|
var _default = SpotlightRootDecorator;
|
package/Spottable/Spottable.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports["default"] = exports.Spottable = void 0;
|
|
6
7
|
Object.defineProperty(exports, "spottableClass", {
|
|
7
8
|
enumerable: true,
|
|
8
9
|
get: function get() {
|
|
@@ -15,7 +16,6 @@ Object.defineProperty(exports, "useSpottable", {
|
|
|
15
16
|
return _useSpottable.useSpottable;
|
|
16
17
|
}
|
|
17
18
|
});
|
|
18
|
-
exports.Spottable = exports["default"] = void 0;
|
|
19
19
|
|
|
20
20
|
var _handle = _interopRequireWildcard(require("@enact/core/handle"));
|
|
21
21
|
|
|
@@ -37,25 +37,27 @@ var _useSpottable = require("./useSpottable");
|
|
|
37
37
|
|
|
38
38
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
39
39
|
|
|
40
|
+
var _excluded = ["className", "disabled", "handleForceUpdate", "onSpotlightDisappear", "onSpotlightDown", "onSpotlightLeft", "onSpotlightRight", "onSpotlightUp", "selectionKeys", "spotlightDisabled", "spotlightId", "spotRef"];
|
|
41
|
+
|
|
40
42
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
41
43
|
|
|
42
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
44
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
43
45
|
|
|
44
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
46
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
45
47
|
|
|
46
48
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
47
49
|
|
|
48
50
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
49
51
|
|
|
50
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
52
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
51
53
|
|
|
52
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
54
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
53
55
|
|
|
54
56
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
55
57
|
|
|
56
58
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
57
59
|
|
|
58
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
60
|
+
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
59
61
|
|
|
60
62
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
61
63
|
|
|
@@ -63,9 +65,9 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
63
65
|
|
|
64
66
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
65
67
|
|
|
66
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
68
|
+
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; }
|
|
67
69
|
|
|
68
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
70
|
+
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; }
|
|
69
71
|
|
|
70
72
|
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; }
|
|
71
73
|
|
|
@@ -159,7 +161,7 @@ var Spottable = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
|
|
|
159
161
|
spotlightDisabled = props.spotlightDisabled,
|
|
160
162
|
spotlightId = props.spotlightId,
|
|
161
163
|
spotRef = props.spotRef,
|
|
162
|
-
rest = _objectWithoutProperties(props,
|
|
164
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
163
165
|
|
|
164
166
|
var spot = (0, _useSpottable.useSpottable)({
|
|
165
167
|
disabled: disabled,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.spottableClass = exports
|
|
6
|
+
exports.spottableClass = exports["default"] = exports.SpottableCore = void 0;
|
|
7
7
|
|
|
8
8
|
var _handle = require("@enact/core/handle");
|
|
9
9
|
|
|
@@ -17,7 +17,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
17
17
|
|
|
18
18
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
19
19
|
|
|
20
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
20
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
21
21
|
|
|
22
22
|
var REMOTE_OK_KEY = 16777221;
|
|
23
23
|
/**
|
|
@@ -59,7 +59,7 @@ var SpottableCore = /*#__PURE__*/function () {
|
|
|
59
59
|
|
|
60
60
|
if (_this.isFocused && _this.props.disabled && lastSelectTarget === _this && !selectCancelled) {
|
|
61
61
|
selectCancelled = true;
|
|
62
|
-
(0, _handle.
|
|
62
|
+
(0, _handle.forwardCustom)('onSelectionCancel')(null, _this.props);
|
|
63
63
|
} // if the component became enabled, notify spotlight to enable restoring "lost" focus
|
|
64
64
|
|
|
65
65
|
|
|
@@ -263,7 +263,7 @@ var SpottableCore = /*#__PURE__*/function () {
|
|
|
263
263
|
key: "unload",
|
|
264
264
|
value: function unload() {
|
|
265
265
|
if (this.isFocused) {
|
|
266
|
-
(0, _handle.
|
|
266
|
+
(0, _handle.forwardCustom)('onSpotlightDisappear')(null, this.props);
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
if (lastSelectTarget === this) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
|
+
|
|
5
|
+
var _react = require("@testing-library/react");
|
|
4
6
|
|
|
5
7
|
var _Spottable = _interopRequireDefault(require("../Spottable"));
|
|
6
8
|
|
|
@@ -8,49 +10,68 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
8
10
|
|
|
9
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
12
|
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
13
|
+
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; }
|
|
12
14
|
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
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
|
|
|
15
17
|
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; }
|
|
16
18
|
|
|
19
|
+
var id = 'test-spottable';
|
|
17
20
|
describe('Spottable', function () {
|
|
18
21
|
test('should add the spottable class', function () {
|
|
19
22
|
var Component = (0, _Spottable["default"])('div');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
24
|
+
"data-testid": id
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
var div = _react.screen.getByTestId(id);
|
|
28
|
+
|
|
29
|
+
var expectedClass = 'spottable';
|
|
30
|
+
expect(div).toHaveClass(expectedClass);
|
|
24
31
|
});
|
|
25
32
|
test('should add the spottable class to a {disabled} component', function () {
|
|
26
33
|
var Component = (0, _Spottable["default"])('div');
|
|
27
|
-
|
|
34
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
35
|
+
"data-testid": id,
|
|
28
36
|
disabled: true
|
|
29
37
|
}));
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
|
|
38
|
+
|
|
39
|
+
var div = _react.screen.getByTestId(id);
|
|
40
|
+
|
|
41
|
+
var expectedClass = 'spottable';
|
|
42
|
+
expect(div).toHaveClass(expectedClass);
|
|
33
43
|
});
|
|
34
44
|
test('should not add the spottable class to a {spotlightDisabled} component', function () {
|
|
35
45
|
var Component = (0, _Spottable["default"])('div');
|
|
36
|
-
|
|
46
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
47
|
+
"data-testid": id,
|
|
37
48
|
spotlightDisabled: true
|
|
38
49
|
}));
|
|
39
|
-
|
|
40
|
-
var
|
|
41
|
-
|
|
50
|
+
|
|
51
|
+
var div = _react.screen.getByTestId(id);
|
|
52
|
+
|
|
53
|
+
var expectedClass = 'spottable';
|
|
54
|
+
expect(div).not.toHaveClass(expectedClass);
|
|
42
55
|
});
|
|
43
56
|
test('should emit {onSpotlightDisappear} when unmounted while focused', function () {
|
|
44
57
|
var spy = jest.fn();
|
|
45
58
|
var Component = (0, _Spottable["default"])('div');
|
|
46
|
-
|
|
59
|
+
|
|
60
|
+
var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
61
|
+
"data-testid": id,
|
|
47
62
|
onSpotlightDisappear: spy
|
|
48
|
-
}))
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
})),
|
|
64
|
+
unmount = _render.unmount;
|
|
65
|
+
|
|
66
|
+
var div = _react.screen.getByTestId(id);
|
|
67
|
+
|
|
68
|
+
div.focus();
|
|
69
|
+
unmount();
|
|
51
70
|
var expected = 1;
|
|
52
|
-
|
|
53
|
-
expect(
|
|
71
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
72
|
+
expect(spy).toBeCalledWith({
|
|
73
|
+
type: 'onSpotlightDisappear'
|
|
74
|
+
});
|
|
54
75
|
});
|
|
55
76
|
describe('shouldComponentUpdate', function () {
|
|
56
77
|
test('should re-render when a non-Spottable prop changes', function () {
|
|
@@ -58,39 +79,47 @@ describe('Spottable', function () {
|
|
|
58
79
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
59
80
|
});
|
|
60
81
|
var Component = (0, _Spottable["default"])(spy);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
82
|
+
|
|
83
|
+
var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {})),
|
|
84
|
+
rerender = _render2.rerender;
|
|
85
|
+
|
|
86
|
+
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
87
|
+
"data-id": "123"
|
|
88
|
+
}));
|
|
65
89
|
var expected = 3;
|
|
66
|
-
|
|
67
|
-
expect(actual).toEqual(expected);
|
|
90
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
68
91
|
});
|
|
69
92
|
test('should re-render when {selectionKeys} changes', function () {
|
|
70
93
|
var spy = jest.fn(function (props) {
|
|
71
94
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
72
95
|
});
|
|
73
96
|
var Component = (0, _Spottable["default"])(spy);
|
|
74
|
-
|
|
97
|
+
|
|
98
|
+
var _render3 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
75
99
|
selectionKeys: [1, 2, 3]
|
|
76
|
-
}))
|
|
77
|
-
|
|
100
|
+
})),
|
|
101
|
+
rerender = _render3.rerender;
|
|
102
|
+
|
|
103
|
+
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
78
104
|
selectionKeys: [2, 1, 3]
|
|
79
|
-
});
|
|
105
|
+
}));
|
|
80
106
|
var expected = 3;
|
|
81
|
-
|
|
82
|
-
expect(actual).toEqual(expected);
|
|
107
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
83
108
|
});
|
|
84
109
|
test('should not re-render when focused', function () {
|
|
85
110
|
var spy = jest.fn(function (props) {
|
|
86
111
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
87
112
|
});
|
|
88
113
|
var Component = (0, _Spottable["default"])(spy);
|
|
89
|
-
|
|
90
|
-
|
|
114
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
115
|
+
"data-testid": id
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
var div = _react.screen.getByTestId(id);
|
|
119
|
+
|
|
120
|
+
div.focus();
|
|
91
121
|
var expected = 2;
|
|
92
|
-
|
|
93
|
-
expect(actual).toEqual(expected);
|
|
122
|
+
expect(spy).toHaveBeenCalledTimes(expected);
|
|
94
123
|
});
|
|
95
124
|
});
|
|
96
125
|
});
|