@enact/spotlight 3.4.9-experimental-3 → 3.4.9-experimental-7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
  2. package/Accelerator/Accelerator.js +149 -156
  3. package/CHANGELOG.md +22 -0
  4. package/{build/Pause → Pause}/Pause.d.ts +0 -0
  5. package/Pause/Pause.js +102 -80
  6. package/Pause/tests/Pause-specs.js +65 -97
  7. package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
  8. package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
  9. package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
  10. package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
  11. package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
  12. package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
  13. package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
  14. package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
  15. package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
  16. package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
  17. package/Spottable/Spottable.js +448 -410
  18. package/Spottable/tests/Spottable-specs.js +90 -117
  19. package/package.json +3 -2
  20. package/src/container.js +718 -653
  21. package/src/navigate.js +406 -491
  22. package/src/pointer.js +86 -78
  23. package/{build/src → src}/spotlight.d.ts +0 -0
  24. package/src/spotlight.js +846 -885
  25. package/src/target.js +448 -474
  26. package/src/tests/container-specs.js +643 -1251
  27. package/src/tests/navigate-specs.js +77 -134
  28. package/src/tests/pointer-specs.js +126 -182
  29. package/src/tests/spotlight-specs.js +103 -133
  30. package/src/tests/target-specs.js +597 -960
  31. package/src/tests/utils.js +89 -67
  32. package/src/utils.js +155 -158
  33. package/build/Accelerator/Accelerator.js +0 -162
  34. package/build/Accelerator/package.json +0 -3
  35. package/build/CHANGELOG.md +0 -838
  36. package/build/Pause/Pause.js +0 -164
  37. package/build/Pause/package.json +0 -3
  38. package/build/Pause/tests/Pause-specs.js +0 -65
  39. package/build/README.md +0 -61
  40. package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
  41. package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
  42. package/build/SpotlightContainerDecorator/package.json +0 -3
  43. package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
  44. package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
  45. package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
  46. package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
  47. package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
  48. package/build/SpotlightRootDecorator/package.json +0 -3
  49. package/build/Spottable/Spottable.js +0 -491
  50. package/build/Spottable/package.json +0 -3
  51. package/build/Spottable/tests/Spottable-specs.js +0 -90
  52. package/build/package-lock.json +0 -229
  53. package/build/package.json +0 -28
  54. package/build/src/container.js +0 -1201
  55. package/build/src/navigate.js +0 -419
  56. package/build/src/pointer.js +0 -183
  57. package/build/src/spotlight.js +0 -896
  58. package/build/src/target.js +0 -507
  59. package/build/src/tests/container-specs.js +0 -653
  60. package/build/src/tests/navigate-specs.js +0 -87
  61. package/build/src/tests/pointer-specs.js +0 -130
  62. package/build/src/tests/spotlight-specs.js +0 -112
  63. package/build/src/tests/target-specs.js +0 -614
  64. package/build/src/tests/utils.js +0 -104
  65. package/build/src/utils.js +0 -180
  66. package/build/styles/debug.less +0 -97
  67. package/build/styles/mixins.less +0 -63
  68. package/docs/index.md +0 -364
@@ -1,20 +1,51 @@
1
- /**
2
- * Adds spottability to components.
3
- *
4
- * @module spotlight/Spottable
5
- * @exports Spottable
6
- * @exports spottableClass
7
- */
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.spottableClass = exports.Spottable = exports["default"] = void 0;
7
+
8
+ var _handle = require("@enact/core/handle");
9
+
10
+ var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
11
+
12
+ var _keymap = require("@enact/core/keymap");
13
+
14
+ var _propTypes = _interopRequireDefault(require("prop-types"));
15
+
16
+ var _react = _interopRequireDefault(require("react"));
17
+
18
+ var _reactDom = _interopRequireDefault(require("react-dom"));
19
+
20
+ var _container = require("../src/container");
21
+
22
+ var _spotlight = require("../src/spotlight");
23
+
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
25
+
26
+ 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; }
8
27
 
9
- import {forward, handle, preventDefault, stop} from '@enact/core/handle';
10
- import hoc from '@enact/core/hoc';
11
- import {is} from '@enact/core/keymap';
12
- import PropTypes from 'prop-types';
13
- import React from 'react';
14
- import ReactDOM from 'react-dom';
28
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15
29
 
16
- import {getContainersForNode} from '../src/container';
17
- import {getDirection, Spotlight} from '../src/spotlight';
30
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
31
+
32
+ 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); } }
33
+
34
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
35
+
36
+ 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); }
37
+
38
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
39
+
40
+ 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); }; }
41
+
42
+ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
43
+
44
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
45
+
46
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
47
+
48
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
18
49
 
19
50
  /**
20
51
  * The class name for spottable components. In general, you do not need to directly access this class
@@ -22,55 +53,45 @@ import {getDirection, Spotlight} from '../src/spotlight';
22
53
  * @memberof spotlight/Spottable
23
54
  * @public
24
55
  */
25
- const spottableClass = 'spottable';
26
-
27
- const ENTER_KEY = 13;
28
- const REMOTE_OK_KEY = 16777221;
29
-
30
- const isKeyboardAccessible = (node) => {
31
- if (!node) return false;
32
- const name = node.nodeName.toUpperCase();
33
- const type = node.type ? node.type.toUpperCase() : null;
34
- return (
35
- name === 'BUTTON' ||
36
- name === 'A' ||
37
- name === 'INPUT' && (
38
- type === 'BUTTON' ||
39
- type === 'CHECKBOX' ||
40
- type === 'IMAGE' ||
41
- type === 'RADIO' ||
42
- type === 'RESET' ||
43
- type === 'SUBMIT'
44
- )
45
- );
56
+ var spottableClass = 'spottable';
57
+ exports.spottableClass = spottableClass;
58
+ var ENTER_KEY = 13;
59
+ var REMOTE_OK_KEY = 16777221;
60
+
61
+ var isKeyboardAccessible = function isKeyboardAccessible(node) {
62
+ if (!node) return false;
63
+ var name = node.nodeName.toUpperCase();
64
+ var type = node.type ? node.type.toUpperCase() : null;
65
+ return name === 'BUTTON' || name === 'A' || name === 'INPUT' && (type === 'BUTTON' || type === 'CHECKBOX' || type === 'IMAGE' || type === 'RADIO' || type === 'RESET' || type === 'SUBMIT');
46
66
  };
47
67
 
48
- const isSpottable = (props) => !props.spotlightDisabled;
68
+ var isSpottable = function isSpottable(props) {
69
+ return !props.spotlightDisabled;
70
+ }; // Last instance of spottable to be focused
49
71
 
50
- // Last instance of spottable to be focused
51
- let lastSelectTarget = null;
52
- // Should we prevent select being passed through
53
- let selectCancelled = false;
54
72
 
73
+ var lastSelectTarget = null; // Should we prevent select being passed through
74
+
75
+ var selectCancelled = false;
55
76
  /**
56
77
  * Default configuration for Spottable
57
78
  *
58
79
  * @hocconfig
59
80
  * @memberof spotlight/Spottable.Spottable
60
81
  */
61
- const defaultConfig = {
62
- /**
63
- * Whether or not the component should emulate mouse events as a response
64
- * to Spotlight 5-way events.
65
- *
66
- * @type {Boolean}
67
- * @default false
68
- * @public
69
- * @memberof spotlight/Spottable.Spottable.defaultConfig
70
- */
71
- emulateMouse: true
72
- };
73
82
 
83
+ var defaultConfig = {
84
+ /**
85
+ * Whether or not the component should emulate mouse events as a response
86
+ * to Spotlight 5-way events.
87
+ *
88
+ * @type {Boolean}
89
+ * @default false
90
+ * @public
91
+ * @memberof spotlight/Spottable.Spottable.defaultConfig
92
+ */
93
+ emulateMouse: true
94
+ };
74
95
  /**
75
96
  * Constructs a Spotlight 5-way navigation-enabled higher-order component.
76
97
  *
@@ -93,361 +114,378 @@ const defaultConfig = {
93
114
  * @hoc
94
115
  * @returns {Function} Spottable
95
116
  */
96
- const Spottable = hoc(defaultConfig, (config, Wrapped) => {
97
- const {emulateMouse} = config;
98
-
99
- return class extends React.Component {
100
- static displayName = 'Spottable';
101
-
102
- static propTypes = /** @lends spotlight/Spottable.Spottable.prototype */ {
103
- /**
104
- * Whether or not the component is in a disabled state.
105
- *
106
- * @type {Boolean}
107
- * @default false
108
- * @public
109
- */
110
- disabled: PropTypes.bool,
111
-
112
- /**
113
- * The handler to run when the component is removed while retaining focus.
114
- *
115
- * @type {Function}
116
- * @param {Object} event
117
- * @public
118
- */
119
- onSpotlightDisappear: PropTypes.func,
120
-
121
- /**
122
- * The handler to run when the 5-way down key is pressed.
123
- *
124
- * @type {Function}
125
- * @param {Object} event
126
- * @public
127
- */
128
- onSpotlightDown: PropTypes.func,
129
-
130
- /**
131
- * The handler to run when the 5-way left key is pressed.
132
- *
133
- * @type {Function}
134
- * @param {Object} event
135
- * @public
136
- */
137
- onSpotlightLeft: PropTypes.func,
138
-
139
- /**
140
- * The handler to run when the 5-way right key is pressed.
141
- *
142
- * @type {Function}
143
- * @param {Object} event
144
- * @public
145
- */
146
- onSpotlightRight: PropTypes.func,
147
-
148
- /**
149
- * The handler to run when the 5-way up key is pressed.
150
- *
151
- * @type {Function}
152
- * @param {Object} event
153
- * @public
154
- */
155
- onSpotlightUp: PropTypes.func,
156
-
157
- /**
158
- * An array of numbers representing keyCodes that should trigger mouse event
159
- * emulation when `emulateMouse` is `true`. If a keyCode equals a directional
160
- * key, then default 5-way navigation will be prevented when that key is pressed.
161
- *
162
- * @type {Number[]}
163
- * @default [13, 16777221]
164
- * @public
165
- */
166
- selectionKeys: PropTypes.arrayOf(PropTypes.number),
167
-
168
- /**
169
- * When `true`, the component cannot be navigated using spotlight.
170
- *
171
- * @type {Boolean}
172
- * @default false
173
- * @public
174
- */
175
- spotlightDisabled: PropTypes.bool,
176
-
177
- /**
178
- * Used to identify this component within the Spotlight system
179
- *
180
- * @type {String}
181
- * @public
182
- */
183
- spotlightId: PropTypes.string,
184
-
185
- /**
186
- * The tabIndex of the component. This value will default to -1 if left
187
- * unset and the control is spottable.
188
- *
189
- * @type {Number}
190
- * @public
191
- */
192
- tabIndex: PropTypes.number
193
- };
194
-
195
- static defaultProps = {
196
- selectionKeys: [ENTER_KEY, REMOTE_OK_KEY]
197
- };
198
-
199
- constructor (props) {
200
- super(props);
201
- this.isHovered = false;
202
- // Used to indicate that we want to stop propagation on blur events that occur as a
203
- // result of this component imperatively blurring itself on focus when spotlightDisabled
204
- this.shouldPreventBlur = false;
205
- this.isFocused = false;
206
- this.focusedWhenDisabled = false;
207
- }
208
-
209
- componentDidMount () {
210
- // eslint-disable-next-line react/no-find-dom-node
211
- this.node = ReactDOM.findDOMNode(this);
212
- }
213
-
214
- componentDidUpdate (prevProps) {
215
- this.isFocused = this.node && Spotlight.getCurrent() === this.node;
216
-
217
- // if the component is focused and became disabled
218
- if (this.isFocused && this.props.disabled && lastSelectTarget === this && !selectCancelled) {
219
- selectCancelled = true;
220
- forward('onMouseUp', null, this.props);
221
- }
222
-
223
- // if the component became enabled, notify spotlight to enable restoring "lost" focus
224
- if (isSpottable(this.props) && !isSpottable(prevProps) && !Spotlight.isPaused()) {
225
- if (Spotlight.getPointerMode()) {
226
- if (this.isHovered) {
227
- Spotlight.setPointerMode(false);
228
- Spotlight.focus(this.node);
229
- Spotlight.setPointerMode(true);
230
- }
231
- } else if (!Spotlight.getCurrent()) {
232
- const containers = getContainersForNode(this.node);
233
- const containerId = Spotlight.getActiveContainer();
234
- if (containers.indexOf(containerId) >= 0) {
235
- Spotlight.focus(containerId);
236
- }
237
- }
238
- }
239
- }
240
-
241
- componentWillUnmount () {
242
- if (this.isFocused) {
243
- forward('onSpotlightDisappear', null, this.props);
244
- }
245
- if (lastSelectTarget === this) {
246
- lastSelectTarget = null;
247
- }
248
- }
249
-
250
- shouldEmulateMouse = (ev, props) => {
251
- if (!emulateMouse) {
252
- return;
253
- }
254
-
255
- const {currentTarget, repeat, type, which} = ev;
256
- const {selectionKeys} = props;
257
- const keyboardAccessible = isKeyboardAccessible(currentTarget);
258
-
259
- const keyCode = selectionKeys.find((value) => (
260
- // emulate mouse events for any remote okay button event
261
- which === REMOTE_OK_KEY ||
262
- // or a non-keypress selection event or any selection event on a non-keyboard accessible
263
- // control
264
- (
265
- which === value &&
266
- (type !== 'keypress' || !keyboardAccessible)
267
- )
268
- ));
269
-
270
- if (getDirection(keyCode)) {
271
- preventDefault(ev);
272
- stop(ev);
273
- } else if (keyCode && keyboardAccessible) {
274
- preventDefault(ev);
275
- }
276
-
277
- return keyCode && !repeat;
278
- };
279
-
280
- forwardSpotlightEvents = (ev, {onSpotlightDown, onSpotlightLeft, onSpotlightRight, onSpotlightUp}) => {
281
- const {keyCode} = ev;
282
-
283
- if (onSpotlightDown && is('down', keyCode)) {
284
- onSpotlightDown(ev);
285
- } else if (onSpotlightLeft && is('left', keyCode)) {
286
- onSpotlightLeft(ev);
287
- } else if (onSpotlightRight && is('right', keyCode)) {
288
- onSpotlightRight(ev);
289
- } else if (onSpotlightUp && is('up', keyCode)) {
290
- onSpotlightUp(ev);
291
- }
292
-
293
- return true;
294
- };
295
-
296
- handleSelect = ({which}, props) => {
297
- const {selectionKeys} = props;
298
-
299
- // Only apply accelerator if handling a selection key
300
- if (selectionKeys.find((value) => which === value)) {
301
- if (selectCancelled || (lastSelectTarget && lastSelectTarget !== this)) {
302
- return false;
303
- }
304
- lastSelectTarget = this;
305
- }
306
- return true;
307
- };
308
-
309
- forwardAndResetLastSelectTarget = (ev, props) => {
310
- const {keyCode} = ev;
311
- const {selectionKeys} = props;
312
- const key = selectionKeys.find((value) => keyCode === value);
313
-
314
- // FIXME: temporary patch to maintain compatibility with moonstone 3.2.5 which
315
- // deconstructs `preventDefault` from the event which is incompatible with React's
316
- // synthetic event.
317
- ev.preventDefault = ev.preventDefault.bind(ev);
318
-
319
- forward('onKeyUp', ev, props);
320
- const notPrevented = !ev.defaultPrevented;
321
-
322
- // bail early for non-selection keyup to avoid clearing lastSelectTarget prematurely
323
- if (!key && (!is('enter', keyCode) || !getDirection(keyCode))) {
324
- return notPrevented;
325
- }
326
-
327
- const allow = lastSelectTarget === this;
328
- selectCancelled = false;
329
- lastSelectTarget = null;
330
- return notPrevented && allow;
331
- };
332
-
333
- isActionable = (ev, props) => isSpottable(props);
334
-
335
- handle = handle.bind(this);
336
-
337
- handleKeyDown = this.handle(
338
- forward('onKeyDown'),
339
- (ev) => !ev.defaultPrevented,
340
- this.forwardSpotlightEvents,
341
- this.isActionable,
342
- this.handleSelect,
343
- this.shouldEmulateMouse,
344
- forward('onMouseDown')
345
- );
346
-
347
- handleKeyUp = this.handle(
348
- this.forwardAndResetLastSelectTarget,
349
- this.isActionable,
350
- this.shouldEmulateMouse,
351
- forward('onMouseUp'),
352
- forward('onClick')
353
- );
354
-
355
- handleBlur = (ev) => {
356
- if (this.shouldPreventBlur) return;
357
- if (ev.currentTarget === ev.target) {
358
- this.isFocused = false;
359
- if (this.focusedWhenDisabled) {
360
- this.focusedWhenDisabled = false;
361
- // We only need to trigger a rerender if a focused item becomes disabled and still needs its focus.
362
- // Once it blurs we need to rerender to remove the spottable class so it will not spot again.
363
- // The reason we don't use state is for performance reasons to avoid updates.
364
- this.forceUpdate();
365
- }
366
- }
367
-
368
- if (Spotlight.isMuted(ev.target)) {
369
- ev.stopPropagation();
370
- } else {
371
- forward('onBlur', ev, this.props);
372
- }
373
- };
374
-
375
- handleFocus = (ev) => {
376
- if (this.props.spotlightDisabled) {
377
- this.shouldPreventBlur = true;
378
- ev.target.blur();
379
- this.shouldPreventBlur = false;
380
- return;
381
- }
382
-
383
- if (ev.currentTarget === ev.target) {
384
- this.isFocused = true;
385
- }
386
-
387
- if (Spotlight.isMuted(ev.target)) {
388
- ev.stopPropagation();
389
- } else {
390
- forward('onFocus', ev, this.props);
391
- }
392
- };
393
-
394
- handleEnter = (ev) => {
395
- forward('onMouseEnter', ev, this.props);
396
- this.isHovered = true;
397
- };
398
-
399
- handleLeave = (ev) => {
400
- forward('onMouseLeave', ev, this.props);
401
- this.isHovered = false;
402
- };
403
-
404
- render () {
405
- const {disabled, spotlightId, spotlightDisabled, ...rest} = this.props;
406
- this.focusedWhenDisabled = this.isFocused && spotlightDisabled;
407
- const spottable = this.focusedWhenDisabled || isSpottable(this.props);
408
-
409
- let tabIndex = rest.tabIndex;
410
-
411
- delete rest.onSpotlightDisappear;
412
- delete rest.onSpotlightDown;
413
- delete rest.onSpotlightLeft;
414
- delete rest.onSpotlightRight;
415
- delete rest.onSpotlightUp;
416
- delete rest.selectionKeys;
417
- delete rest.spotlightDisabled;
418
-
419
- if (tabIndex == null) {
420
- tabIndex = -1;
421
- }
422
-
423
- if (spottable) {
424
- if (rest.className) {
425
- rest.className += ' ' + spottableClass;
426
- } else {
427
- rest.className = spottableClass;
428
- }
429
- }
430
-
431
- if (spotlightId) {
432
- rest['data-spotlight-id'] = spotlightId;
433
- }
434
-
435
- return (
436
- <Wrapped
437
- {...rest}
438
- onBlur={this.handleBlur}
439
- onFocus={this.handleFocus}
440
- onMouseEnter={this.handleEnter}
441
- onMouseLeave={this.handleLeave}
442
- onKeyDown={this.handleKeyDown}
443
- onKeyUp={this.handleKeyUp}
444
- disabled={disabled}
445
- tabIndex={tabIndex}
446
- />
447
- );
448
- }
449
- };
450
- });
451
117
 
452
- export default Spottable;
453
- export {Spottable, spottableClass};
118
+ var Spottable = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
119
+ var _class, _temp;
120
+
121
+ var emulateMouse = config.emulateMouse;
122
+ return _temp = _class = /*#__PURE__*/function (_React$Component) {
123
+ _inherits(_class, _React$Component);
124
+
125
+ var _super = _createSuper(_class);
126
+
127
+ function _class(_props) {
128
+ var _this;
129
+
130
+ _classCallCheck(this, _class);
131
+
132
+ _this = _super.call(this, _props);
133
+
134
+ _this.shouldEmulateMouse = function (ev, props) {
135
+ if (!emulateMouse) {
136
+ return;
137
+ }
138
+
139
+ var currentTarget = ev.currentTarget,
140
+ repeat = ev.repeat,
141
+ type = ev.type,
142
+ which = ev.which;
143
+ var selectionKeys = props.selectionKeys;
144
+ var keyboardAccessible = isKeyboardAccessible(currentTarget);
145
+ var keyCode = selectionKeys.find(function (value) {
146
+ return (// emulate mouse events for any remote okay button event
147
+ which === REMOTE_OK_KEY || // or a non-keypress selection event or any selection event on a non-keyboard accessible
148
+ // control
149
+ which === value && (type !== 'keypress' || !keyboardAccessible)
150
+ );
151
+ });
152
+
153
+ if ((0, _spotlight.getDirection)(keyCode)) {
154
+ (0, _handle.preventDefault)(ev);
155
+ (0, _handle.stop)(ev);
156
+ } else if (keyCode && keyboardAccessible) {
157
+ (0, _handle.preventDefault)(ev);
158
+ }
159
+
160
+ return keyCode && !repeat;
161
+ };
162
+
163
+ _this.forwardSpotlightEvents = function (ev, _ref) {
164
+ var onSpotlightDown = _ref.onSpotlightDown,
165
+ onSpotlightLeft = _ref.onSpotlightLeft,
166
+ onSpotlightRight = _ref.onSpotlightRight,
167
+ onSpotlightUp = _ref.onSpotlightUp;
168
+ var keyCode = ev.keyCode;
169
+
170
+ if (onSpotlightDown && (0, _keymap.is)('down', keyCode)) {
171
+ onSpotlightDown(ev);
172
+ } else if (onSpotlightLeft && (0, _keymap.is)('left', keyCode)) {
173
+ onSpotlightLeft(ev);
174
+ } else if (onSpotlightRight && (0, _keymap.is)('right', keyCode)) {
175
+ onSpotlightRight(ev);
176
+ } else if (onSpotlightUp && (0, _keymap.is)('up', keyCode)) {
177
+ onSpotlightUp(ev);
178
+ }
179
+
180
+ return true;
181
+ };
182
+
183
+ _this.handleSelect = function (_ref2, props) {
184
+ var which = _ref2.which;
185
+ var selectionKeys = props.selectionKeys; // Only apply accelerator if handling a selection key
186
+
187
+ if (selectionKeys.find(function (value) {
188
+ return which === value;
189
+ })) {
190
+ if (selectCancelled || lastSelectTarget && lastSelectTarget !== _assertThisInitialized(_this)) {
191
+ return false;
192
+ }
193
+
194
+ lastSelectTarget = _assertThisInitialized(_this);
195
+ }
196
+
197
+ return true;
198
+ };
199
+
200
+ _this.forwardAndResetLastSelectTarget = function (ev, props) {
201
+ var keyCode = ev.keyCode;
202
+ var selectionKeys = props.selectionKeys;
203
+ var key = selectionKeys.find(function (value) {
204
+ return keyCode === value;
205
+ }); // FIXME: temporary patch to maintain compatibility with moonstone 3.2.5 which
206
+ // deconstructs `preventDefault` from the event which is incompatible with React's
207
+ // synthetic event.
208
+
209
+ ev.preventDefault = ev.preventDefault.bind(ev);
210
+ (0, _handle.forward)('onKeyUp', ev, props);
211
+ var notPrevented = !ev.defaultPrevented; // bail early for non-selection keyup to avoid clearing lastSelectTarget prematurely
212
+
213
+ if (!key && (!(0, _keymap.is)('enter', keyCode) || !(0, _spotlight.getDirection)(keyCode))) {
214
+ return notPrevented;
215
+ }
216
+
217
+ var allow = lastSelectTarget === _assertThisInitialized(_this);
218
+
219
+ selectCancelled = false;
220
+ lastSelectTarget = null;
221
+ return notPrevented && allow;
222
+ };
223
+
224
+ _this.isActionable = function (ev, props) {
225
+ return isSpottable(props);
226
+ };
227
+
228
+ _this.handle = _handle.handle.bind(_assertThisInitialized(_this));
229
+ _this.handleKeyDown = _this.handle((0, _handle.forward)('onKeyDown'), function (ev) {
230
+ return !ev.defaultPrevented;
231
+ }, _this.forwardSpotlightEvents, _this.isActionable, _this.handleSelect, _this.shouldEmulateMouse, (0, _handle.forward)('onMouseDown'));
232
+ _this.handleKeyUp = _this.handle(_this.forwardAndResetLastSelectTarget, _this.isActionable, _this.shouldEmulateMouse, (0, _handle.forward)('onMouseUp'), (0, _handle.forward)('onClick'));
233
+
234
+ _this.handleBlur = function (ev) {
235
+ if (_this.shouldPreventBlur) return;
236
+
237
+ if (ev.currentTarget === ev.target) {
238
+ _this.isFocused = false;
239
+
240
+ if (_this.focusedWhenDisabled) {
241
+ _this.focusedWhenDisabled = false; // We only need to trigger a rerender if a focused item becomes disabled and still needs its focus.
242
+ // Once it blurs we need to rerender to remove the spottable class so it will not spot again.
243
+ // The reason we don't use state is for performance reasons to avoid updates.
244
+
245
+ _this.forceUpdate();
246
+ }
247
+ }
248
+
249
+ if (_spotlight.Spotlight.isMuted(ev.target)) {
250
+ ev.stopPropagation();
251
+ } else {
252
+ (0, _handle.forward)('onBlur', ev, _this.props);
253
+ }
254
+ };
255
+
256
+ _this.handleFocus = function (ev) {
257
+ if (_this.props.spotlightDisabled) {
258
+ _this.shouldPreventBlur = true;
259
+ ev.target.blur();
260
+ _this.shouldPreventBlur = false;
261
+ return;
262
+ }
263
+
264
+ if (ev.currentTarget === ev.target) {
265
+ _this.isFocused = true;
266
+ }
267
+
268
+ if (_spotlight.Spotlight.isMuted(ev.target)) {
269
+ ev.stopPropagation();
270
+ } else {
271
+ (0, _handle.forward)('onFocus', ev, _this.props);
272
+ }
273
+ };
274
+
275
+ _this.handleEnter = function (ev) {
276
+ (0, _handle.forward)('onMouseEnter', ev, _this.props);
277
+ _this.isHovered = true;
278
+ };
279
+
280
+ _this.handleLeave = function (ev) {
281
+ (0, _handle.forward)('onMouseLeave', ev, _this.props);
282
+ _this.isHovered = false;
283
+ };
284
+
285
+ _this.isHovered = false; // Used to indicate that we want to stop propagation on blur events that occur as a
286
+ // result of this component imperatively blurring itself on focus when spotlightDisabled
287
+
288
+ _this.shouldPreventBlur = false;
289
+ _this.isFocused = false;
290
+ _this.focusedWhenDisabled = false;
291
+ return _this;
292
+ }
293
+
294
+ _createClass(_class, [{
295
+ key: "componentDidMount",
296
+ value: function componentDidMount() {
297
+ // eslint-disable-next-line react/no-find-dom-node
298
+ this.node = _reactDom["default"].findDOMNode(this);
299
+ }
300
+ }, {
301
+ key: "componentDidUpdate",
302
+ value: function componentDidUpdate(prevProps) {
303
+ this.isFocused = this.node && _spotlight.Spotlight.getCurrent() === this.node; // if the component is focused and became disabled
304
+
305
+ if (this.isFocused && this.props.disabled && lastSelectTarget === this && !selectCancelled) {
306
+ selectCancelled = true;
307
+ (0, _handle.forward)('onMouseUp', null, this.props);
308
+ } // if the component became enabled, notify spotlight to enable restoring "lost" focus
309
+
310
+
311
+ if (isSpottable(this.props) && !isSpottable(prevProps) && !_spotlight.Spotlight.isPaused()) {
312
+ if (_spotlight.Spotlight.getPointerMode()) {
313
+ if (this.isHovered) {
314
+ _spotlight.Spotlight.setPointerMode(false);
315
+
316
+ _spotlight.Spotlight.focus(this.node);
317
+
318
+ _spotlight.Spotlight.setPointerMode(true);
319
+ }
320
+ } else if (!_spotlight.Spotlight.getCurrent()) {
321
+ var containers = (0, _container.getContainersForNode)(this.node);
322
+
323
+ var containerId = _spotlight.Spotlight.getActiveContainer();
324
+
325
+ if (containers.indexOf(containerId) >= 0) {
326
+ _spotlight.Spotlight.focus(containerId);
327
+ }
328
+ }
329
+ }
330
+ }
331
+ }, {
332
+ key: "componentWillUnmount",
333
+ value: function componentWillUnmount() {
334
+ if (this.isFocused) {
335
+ (0, _handle.forward)('onSpotlightDisappear', null, this.props);
336
+ }
337
+
338
+ if (lastSelectTarget === this) {
339
+ lastSelectTarget = null;
340
+ }
341
+ }
342
+ }, {
343
+ key: "render",
344
+ value: function render() {
345
+ var _this$props = this.props,
346
+ disabled = _this$props.disabled,
347
+ spotlightId = _this$props.spotlightId,
348
+ spotlightDisabled = _this$props.spotlightDisabled,
349
+ rest = _objectWithoutProperties(_this$props, ["disabled", "spotlightId", "spotlightDisabled"]);
350
+
351
+ this.focusedWhenDisabled = this.isFocused && spotlightDisabled;
352
+ var spottable = this.focusedWhenDisabled || isSpottable(this.props);
353
+ var tabIndex = rest.tabIndex;
354
+ delete rest.onSpotlightDisappear;
355
+ delete rest.onSpotlightDown;
356
+ delete rest.onSpotlightLeft;
357
+ delete rest.onSpotlightRight;
358
+ delete rest.onSpotlightUp;
359
+ delete rest.selectionKeys;
360
+ delete rest.spotlightDisabled;
361
+
362
+ if (tabIndex == null) {
363
+ tabIndex = -1;
364
+ }
365
+
366
+ if (spottable) {
367
+ if (rest.className) {
368
+ rest.className += ' ' + spottableClass;
369
+ } else {
370
+ rest.className = spottableClass;
371
+ }
372
+ }
373
+
374
+ if (spotlightId) {
375
+ rest['data-spotlight-id'] = spotlightId;
376
+ }
377
+
378
+ return /*#__PURE__*/_react["default"].createElement(Wrapped, Object.assign({}, rest, {
379
+ onBlur: this.handleBlur,
380
+ onFocus: this.handleFocus,
381
+ onMouseEnter: this.handleEnter,
382
+ onMouseLeave: this.handleLeave,
383
+ onKeyDown: this.handleKeyDown,
384
+ onKeyUp: this.handleKeyUp,
385
+ disabled: disabled,
386
+ tabIndex: tabIndex
387
+ }));
388
+ }
389
+ }]);
390
+
391
+ return _class;
392
+ }(_react["default"].Component), _class.displayName = 'Spottable', _class.propTypes =
393
+ /** @lends spotlight/Spottable.Spottable.prototype */
394
+ {
395
+ /**
396
+ * Whether or not the component is in a disabled state.
397
+ *
398
+ * @type {Boolean}
399
+ * @default false
400
+ * @public
401
+ */
402
+ disabled: _propTypes["default"].bool,
403
+
404
+ /**
405
+ * The handler to run when the component is removed while retaining focus.
406
+ *
407
+ * @type {Function}
408
+ * @param {Object} event
409
+ * @public
410
+ */
411
+ onSpotlightDisappear: _propTypes["default"].func,
412
+
413
+ /**
414
+ * The handler to run when the 5-way down key is pressed.
415
+ *
416
+ * @type {Function}
417
+ * @param {Object} event
418
+ * @public
419
+ */
420
+ onSpotlightDown: _propTypes["default"].func,
421
+
422
+ /**
423
+ * The handler to run when the 5-way left key is pressed.
424
+ *
425
+ * @type {Function}
426
+ * @param {Object} event
427
+ * @public
428
+ */
429
+ onSpotlightLeft: _propTypes["default"].func,
430
+
431
+ /**
432
+ * The handler to run when the 5-way right key is pressed.
433
+ *
434
+ * @type {Function}
435
+ * @param {Object} event
436
+ * @public
437
+ */
438
+ onSpotlightRight: _propTypes["default"].func,
439
+
440
+ /**
441
+ * The handler to run when the 5-way up key is pressed.
442
+ *
443
+ * @type {Function}
444
+ * @param {Object} event
445
+ * @public
446
+ */
447
+ onSpotlightUp: _propTypes["default"].func,
448
+
449
+ /**
450
+ * An array of numbers representing keyCodes that should trigger mouse event
451
+ * emulation when `emulateMouse` is `true`. If a keyCode equals a directional
452
+ * key, then default 5-way navigation will be prevented when that key is pressed.
453
+ *
454
+ * @type {Number[]}
455
+ * @default [13, 16777221]
456
+ * @public
457
+ */
458
+ selectionKeys: _propTypes["default"].arrayOf(_propTypes["default"].number),
459
+
460
+ /**
461
+ * When `true`, the component cannot be navigated using spotlight.
462
+ *
463
+ * @type {Boolean}
464
+ * @default false
465
+ * @public
466
+ */
467
+ spotlightDisabled: _propTypes["default"].bool,
468
+
469
+ /**
470
+ * Used to identify this component within the Spotlight system
471
+ *
472
+ * @type {String}
473
+ * @public
474
+ */
475
+ spotlightId: _propTypes["default"].string,
476
+
477
+ /**
478
+ * The tabIndex of the component. This value will default to -1 if left
479
+ * unset and the control is spottable.
480
+ *
481
+ * @type {Number}
482
+ * @public
483
+ */
484
+ tabIndex: _propTypes["default"].number
485
+ }, _class.defaultProps = {
486
+ selectionKeys: [ENTER_KEY, REMOTE_OK_KEY]
487
+ }, _temp;
488
+ });
489
+ exports.Spottable = Spottable;
490
+ var _default = Spottable;
491
+ exports["default"] = _default;