@enact/spotlight 5.5.1 → 5.5.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 CHANGED
@@ -2,6 +2,16 @@
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
+ ## [5.5.2] - 2026-07-08
6
+
7
+ ### Added
8
+
9
+ - Developer guide section on using `@enact/spotlight` as a standalone library
10
+
11
+ ### Changed
12
+
13
+ - `spotlight/SpotlightRootDecorator` to use a functional component
14
+
5
15
  ## [5.5.1] - 2026-06-01
6
16
 
7
17
  No significant changes.
@@ -43,18 +43,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default":
43
43
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
44
44
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
45
45
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
46
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
47
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
48
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
49
46
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
50
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
51
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
52
- function _possibleConstructorReturn(t, e) { if (e && ("object" == typeof e || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
53
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
54
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
55
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
56
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
57
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } /**
47
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
58
48
  * Exports the {@link spotlight/SpotlightRootDecorator.SpotlightRootDecorator}
59
49
  * higher-order component.
60
50
  *
@@ -123,57 +113,63 @@ var defaultConfig = {
123
113
  * @hoc
124
114
  */
125
115
  var SpotlightRootDecorator = exports.SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
126
- var _Class;
127
116
  var focusEffectClass = config.focusEffectClass,
128
117
  noAutoFocus = config.noAutoFocus,
129
118
  rootId = config.rootId;
130
- return _Class = /*#__PURE__*/function (_Component) {
131
- function _Class(props) {
132
- var _this;
133
- _classCallCheck(this, _Class);
134
- _this = _callSuper(this, _Class, [props]);
135
- _this.applyInputType = function () {
136
- if (_this && _this.containerNode) {
137
- (0, _inputType.applyInputTypeToNode)(_this.containerNode);
138
- }
139
- };
140
- _this.handleFocusInBeforeMount = function () {
141
- _this.hasFocusedIn = true;
142
- };
143
- _this.handleFocusIn = function () {
144
- if (!(0, _inputType.getInputInfo)().applied) {
145
- _this.applyInputType();
146
- }
147
- };
148
- // For key input
149
- _this.handleKeyDown = function (ev) {
150
- var keyCode = ev.keyCode;
151
- if ((0, _keymap.is)('enter', keyCode) && _this.containerNode.classList.contains('spotlight-input-touch')) {
152
- // Prevent onclick event trigger by enter key
153
- ev.preventDefault();
154
- }
155
- setTimeout(function () {
156
- if (!(0, _inputType.getInputInfo)().activated) {
157
- (0, _inputType.setInputType)('key');
158
- }
159
- _this.applyInputType();
160
- }, 0);
161
- };
162
- // For mouse input
163
- _this.handlePointerMove = function (ev) {
164
- if (ev.pointerType === 'mouse') {
165
- (0, _inputType.setInputType)('mouse');
166
- _this.applyInputType();
167
- }
168
- };
169
- // For touch input
170
- _this.handlePointerOver = function (ev) {
171
- if (ev.pointerType === 'touch') {
172
- (0, _inputType.setInputType)('touch');
173
- _this.applyInputType();
119
+ function SpotlightRootDecoratorBase(props) {
120
+ var containerNode = (0, _react.useRef)(null);
121
+ var hasFocusedIn = (0, _react.useRef)(false);
122
+ var applyInputType = (0, _react.useCallback)(function () {
123
+ if (containerNode.current) {
124
+ (0, _inputType.applyInputTypeToNode)(containerNode.current);
125
+ }
126
+ }, []);
127
+ var handleFocusInBeforeMount = (0, _react.useCallback)(function () {
128
+ hasFocusedIn.current = true;
129
+ }, []);
130
+ var handleFocusIn = (0, _react.useCallback)(function () {
131
+ if (!(0, _inputType.getInputInfo)().applied) {
132
+ applyInputType();
133
+ }
134
+ }, [applyInputType]);
135
+
136
+ // For key input
137
+ var handleKeyDown = (0, _react.useCallback)(function (ev) {
138
+ var keyCode = ev.keyCode;
139
+ if ((0, _keymap.is)('enter', keyCode) && containerNode.current.classList.contains('spotlight-input-touch')) {
140
+ // Prevent onclick event trigger by enter key
141
+ ev.preventDefault();
142
+ }
143
+ setTimeout(function () {
144
+ if (!(0, _inputType.getInputInfo)().activated) {
145
+ (0, _inputType.setInputType)('key');
174
146
  }
175
- };
176
- _this.containerNode = null;
147
+ applyInputType();
148
+ }, 0);
149
+ }, [applyInputType]);
150
+
151
+ // For mouse input
152
+ var handlePointerMove = (0, _react.useCallback)(function (ev) {
153
+ if (ev.pointerType === 'mouse') {
154
+ (0, _inputType.setInputType)('mouse');
155
+ applyInputType();
156
+ }
157
+ }, [applyInputType]);
158
+
159
+ // For touch input
160
+ var handlePointerOver = (0, _react.useCallback)(function (ev) {
161
+ if (ev.pointerType === 'touch') {
162
+ (0, _inputType.setInputType)('touch');
163
+ applyInputType();
164
+ }
165
+ }, [applyInputType]);
166
+
167
+ // One-time initialization equivalent to the class constructor.
168
+ // Runs synchronously on first render so the focusin listener is in place
169
+ // before the component mounts (mirrors the constructor behaviour).
170
+ var initialized = (0, _react.useRef)(false);
171
+ if (!initialized.current) {
172
+ initialized.current = true;
177
173
  if (focusEffectClass) {
178
174
  (0, _focusEffect.setFocusEffectClass)(focusEffectClass);
179
175
  }
@@ -186,68 +182,60 @@ var SpotlightRootDecorator = exports.SpotlightRootDecorator = (0, _hoc["default"
186
182
  overflow: true
187
183
  });
188
184
 
189
- // Sometimes the focusin event is fired before componentDidMount.
190
- document.addEventListener('focusin', _this.handleFocusInBeforeMount, {
185
+ // Sometimes the focusin event is fired before the effect runs.
186
+ document.addEventListener('focusin', handleFocusInBeforeMount, {
191
187
  capture: true
192
188
  });
193
189
  }
194
- return _this;
195
190
  }
196
- _inherits(_Class, _Component);
197
- return _createClass(_Class, [{
198
- key: "componentDidMount",
199
- value: function componentDidMount() {
200
- if (!noAutoFocus) {
201
- _spotlight["default"].focus();
202
- }
203
- if (typeof document === 'object') {
204
- this.containerNode = document.querySelector('#' + rootId);
205
- document.addEventListener('focusin', this.handleFocusIn, {
206
- capture: true
207
- });
208
- document.addEventListener('keydown', this.handleKeyDown, {
209
- capture: true
210
- });
211
- document.addEventListener('pointermove', this.handlePointerMove, {
212
- capture: true
213
- });
214
- document.addEventListener('pointerover', this.handlePointerOver, {
215
- capture: true
216
- });
217
- document.removeEventListener('focusin', this.handleFocusInBeforeMount, {
218
- capture: true
219
- });
220
- }
221
- if (this.hasFocusedIn) {
222
- this.hasFocusedIn = false;
223
- this.handleFocusIn();
224
- }
191
+ (0, _react.useEffect)(function () {
192
+ if (!noAutoFocus) {
193
+ _spotlight["default"].focus();
194
+ }
195
+ if (typeof document === 'object') {
196
+ containerNode.current = document.querySelector('#' + rootId);
197
+ document.addEventListener('focusin', handleFocusIn, {
198
+ capture: true
199
+ });
200
+ document.addEventListener('keydown', handleKeyDown, {
201
+ capture: true
202
+ });
203
+ document.addEventListener('pointermove', handlePointerMove, {
204
+ capture: true
205
+ });
206
+ document.addEventListener('pointerover', handlePointerOver, {
207
+ capture: true
208
+ });
209
+ document.removeEventListener('focusin', handleFocusInBeforeMount, {
210
+ capture: true
211
+ });
212
+ }
213
+ if (hasFocusedIn.current) {
214
+ hasFocusedIn.current = false;
215
+ handleFocusIn();
225
216
  }
226
- }, {
227
- key: "componentWillUnmount",
228
- value: function componentWillUnmount() {
217
+ return function () {
229
218
  _spotlight["default"].terminate();
230
219
  if (typeof document === 'object') {
231
- document.removeEventListener('focusin', this.handleFocusIn, {
220
+ document.removeEventListener('focusin', handleFocusIn, {
232
221
  capture: true
233
222
  });
234
- document.removeEventListener('keydown', this.handleKeyDown, {
223
+ document.removeEventListener('keydown', handleKeyDown, {
235
224
  capture: true
236
225
  });
237
- document.removeEventListener('pointermove', this.handlePointerMove, {
226
+ document.removeEventListener('pointermove', handlePointerMove, {
238
227
  capture: true
239
228
  });
240
- document.removeEventListener('pointerover', this.handlePointerOver, {
229
+ document.removeEventListener('pointerover', handlePointerOver, {
241
230
  capture: true
242
231
  });
243
232
  }
244
- }
245
- }, {
246
- key: "render",
247
- value: function render() {
248
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread({}, this.props));
249
- }
250
- }]);
251
- }(_react.Component), _Class.displayName = 'SpotlightRootDecorator', _Class;
233
+ };
234
+ // eslint-disable-next-line react-hooks/exhaustive-deps
235
+ }, []);
236
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread({}, props));
237
+ }
238
+ SpotlightRootDecoratorBase.displayName = 'SpotlightRootDecorator';
239
+ return SpotlightRootDecoratorBase;
252
240
  });
253
241
  var _default = exports["default"] = SpotlightRootDecorator;
@@ -2,10 +2,13 @@
2
2
 
3
3
  require("@testing-library/jest-dom");
4
4
  var _react = require("@testing-library/react");
5
+ var _react2 = require("react");
5
6
  var _SpotlightRootDecorator = require("../SpotlightRootDecorator");
6
7
  var _container = require("../../src/container");
7
8
  var _focusEffect = require("../../src/focusEffect");
8
9
  var _jsxRuntime = require("react/jsx-runtime");
10
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
11
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
9
12
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
13
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
14
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -22,6 +25,11 @@ describe('SpotlightRootDecorator', function () {
22
25
  })
23
26
  }));
24
27
  };
28
+ afterEach(function () {
29
+ jest.restoreAllMocks();
30
+ jest.useRealTimers();
31
+ delete document.elementFromPoint;
32
+ });
25
33
  test('should set `spotlight-input-key` class when the app is focused for the first time', function () {
26
34
  var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppBase);
27
35
  (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
@@ -67,4 +75,86 @@ describe('SpotlightRootDecorator', function () {
67
75
  var actual = containerConfig.enterTo;
68
76
  expect(actual).toBe(expected);
69
77
  });
78
+ test('should set `spotlight-input-key` class on keydown event', /*#__PURE__*/_asyncToGenerator(function* () {
79
+ jest.useFakeTimers();
80
+ // jsdom does not implement elementFromPoint; mock it to prevent Spotlight internals from throwing
81
+ document.elementFromPoint = jest.fn().mockReturnValue(null);
82
+ var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppBase);
83
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
84
+ var element = _react.screen.getByTestId('root');
85
+ _react.fireEvent.keyDown(document, {
86
+ keyCode: 38
87
+ }); // up arrow — avoids enter+touch-input branch
88
+
89
+ yield (0, _react.act)(/*#__PURE__*/_asyncToGenerator(function* () {
90
+ jest.runAllTimers();
91
+ }));
92
+ expect(element).toHaveClass('spotlight-input-key');
93
+ }));
94
+ test('should set `spotlight-input-mouse` class on pointermove event with mouse pointer', function () {
95
+ var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppBase);
96
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
97
+ var element = _react.screen.getByTestId('root');
98
+ _react.fireEvent.focus(_react.screen.queryByText('123'));
99
+ var pointerMoveEvent = Object.assign(new Event('pointermove', {
100
+ bubbles: true,
101
+ cancelable: true
102
+ }), {
103
+ pointerType: 'mouse'
104
+ });
105
+ document.dispatchEvent(pointerMoveEvent);
106
+ expect(element).toHaveClass('spotlight-input-mouse');
107
+ });
108
+ test('should set `spotlight-input-touch` class on pointerover event with touch pointer', function () {
109
+ var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppBase);
110
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
111
+ var element = _react.screen.getByTestId('root');
112
+ _react.fireEvent.focus(_react.screen.queryByText('123'));
113
+ var pointerOverEvent = Object.assign(new Event('pointerover', {
114
+ bubbles: true,
115
+ cancelable: true
116
+ }), {
117
+ pointerType: 'touch'
118
+ });
119
+ document.dispatchEvent(pointerOverEvent);
120
+ expect(element).toHaveClass('spotlight-input-touch');
121
+ });
122
+ test('should handle focusin that fires during child mount without throwing', function () {
123
+ var ChildFiringFocusin = function ChildFiringFocusin() {
124
+ (0, _react2.useLayoutEffect)(function () {
125
+ document.dispatchEvent(new Event('focusin', {
126
+ bubbles: true
127
+ }));
128
+ }, []);
129
+ return 123;
130
+ };
131
+ var AppWithChild = function AppWithChild(props) {
132
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({
133
+ id: "root",
134
+ "data-testid": "root"
135
+ }, props), {}, {
136
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChildFiringFocusin, {})
137
+ }));
138
+ };
139
+ var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppWithChild);
140
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
141
+ expect(_react.screen.getByTestId('root')).toBeInTheDocument();
142
+ });
143
+ test('should prevent default for enter key when container has touch input class', /*#__PURE__*/_asyncToGenerator(function* () {
144
+ jest.useFakeTimers();
145
+ document.elementFromPoint = jest.fn().mockReturnValue(null);
146
+ var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppBase);
147
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
148
+
149
+ // Add the touch class directly to the container to satisfy the condition in handleKeyDown
150
+ document.querySelector('#root').classList.add('spotlight-input-touch');
151
+ var preventDefaultSpy = jest.spyOn(Event.prototype, 'preventDefault');
152
+ _react.fireEvent.keyDown(document, {
153
+ keyCode: 13
154
+ });
155
+ expect(preventDefaultSpy).toHaveBeenCalled();
156
+ yield (0, _react.act)(/*#__PURE__*/_asyncToGenerator(function* () {
157
+ jest.runAllTimers();
158
+ }));
159
+ }));
70
160
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/spotlight",
3
- "version": "5.5.1",
3
+ "version": "5.5.2",
4
4
  "description": "A focus management library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,17 +25,12 @@
25
25
  }
26
26
  },
27
27
  "dependencies": {
28
- "@enact/core": "^5.5.1",
28
+ "@enact/core": "^5.5.2",
29
29
  "classnames": "^2.5.1",
30
30
  "prop-types": "^15.8.1",
31
31
  "ramda": "^0.32.0",
32
- "react": "^19.2.6",
33
- "react-dom": "^19.2.6",
32
+ "react": "^19.2.7",
33
+ "react-dom": "^19.2.7",
34
34
  "warning": "^4.0.3"
35
- },
36
- "overrides": {
37
- "prop-types": {
38
- "react-is": "^19.2.3"
39
- }
40
35
  }
41
36
  }