@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,21 +1,47 @@
1
- /**
2
- * Exports the {@link spotlight/SpotlightRootDecorator.SpotlightRootDecorator}
3
- * higher-order component.
4
- *
5
- * @module spotlight/SpotlightRootDecorator
6
- * @exports SpotlightRootDecorator
7
- */
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SpotlightRootDecorator = exports["default"] = void 0;
7
+
8
+ var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
9
+
10
+ var _keymap = require("@enact/core/keymap");
11
+
12
+ var _LS2Request = _interopRequireDefault(require("@enact/webos/LS2Request/LS2Request"));
13
+
14
+ var _react = _interopRequireDefault(require("react"));
15
+
16
+ var _spotlight = _interopRequireDefault(require("../src/spotlight"));
17
+
18
+ var _Spottable = require("../Spottable");
19
+
20
+ var _container = require("../src/container");
8
21
 
9
- import hoc from '@enact/core/hoc';
10
- import {is} from '@enact/core/keymap';
11
- import React from 'react';
22
+ require("../styles/debug.less");
12
23
 
13
- import Spotlight from '../src/spotlight';
14
- import {spottableClass} from '../Spottable';
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
25
 
16
- import {rootContainerId} from '../src/container';
26
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
27
 
18
- import '../styles/debug.less';
28
+ 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); } }
29
+
30
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
31
+
32
+ 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); }
33
+
34
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
35
+
36
+ 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); }; }
37
+
38
+ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
39
+
40
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
41
+
42
+ 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; } }
43
+
44
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
19
45
 
20
46
  /**
21
47
  * Default configuration for SpotlightRootDecorator
@@ -23,18 +49,17 @@ import '../styles/debug.less';
23
49
  * @hocconfig
24
50
  * @memberof spotlight/SpotlightRootDecorator.SpotlightRootDecorator
25
51
  */
26
- const defaultConfig = {
27
- /**
28
- * When `true`, the contents of the component will not receive spotlight focus after being rendered.
29
- *
30
- * @type {Boolean}
31
- * @default false
32
- * @public
33
- * @memberof spotlight/SpotlightRootDecorator.SpotlightRootDecorator.defaultConfig
34
- */
35
- noAutoFocus: false
52
+ var defaultConfig = {
53
+ /**
54
+ * When `true`, the contents of the component will not receive spotlight focus after being rendered.
55
+ *
56
+ * @type {Boolean}
57
+ * @default false
58
+ * @public
59
+ * @memberof spotlight/SpotlightRootDecorator.SpotlightRootDecorator.defaultConfig
60
+ */
61
+ noAutoFocus: false
36
62
  };
37
-
38
63
  /**
39
64
  * Constructs a higher-order component that initializes and enables Spotlight 5-way navigation
40
65
  * within an application.
@@ -53,90 +78,160 @@ const defaultConfig = {
53
78
  * @returns {Function} SpotlightRootDecorator
54
79
  * @hoc
55
80
  */
56
- const SpotlightRootDecorator = hoc(defaultConfig, (config, Wrapped) => {
57
- const {noAutoFocus} = config;
58
-
59
- return class extends React.Component {
60
- static displayName = 'SpotlightRootDecorator';
61
-
62
- constructor (props) {
63
- super(props);
64
-
65
- // In other modules, this reference DOM element could be referred by `#root > div`.
66
- this.containerRef = React.createRef();
67
-
68
- if (typeof window === 'object') {
69
- Spotlight.initialize({
70
- selector: '.' + spottableClass,
71
- restrict: 'none'
72
- });
73
-
74
- Spotlight.set(rootContainerId, {
75
- overflow: true
76
- });
77
- }
78
- }
79
-
80
- componentDidMount () {
81
- if (!noAutoFocus) {
82
- Spotlight.focus();
83
- }
84
-
85
- this.containerRef.current.classList.add('non-touch-mode');
86
-
87
- document.addEventListener('pointerover', this.handlePointerOver, {capture: true});
88
- document.addEventListener('keydown', this.handleKeyDown, {capture: true});
89
- }
90
-
91
- componentWillUnmount () {
92
- Spotlight.terminate();
93
-
94
- document.removeEventListener('pointerover', this.handlePointerOver, {capture: true});
95
- document.removeEventListener('keydown', this.handleKeyDown, {capture: true});
96
- }
97
-
98
- handlePointerOver = (ev) => {
99
- if (ev.pointerType === 'touch') {
100
- this.containerRef.current.classList.remove('non-touch-mode');
101
- this.containerRef.current.classList.add('touch-mode');
102
- } else if (ev.pointerType === 'mouse') {
103
- this.containerRef.current.classList.add('non-touch-mode');
104
- this.containerRef.current.classList.remove('touch-mode');
105
- } else {
106
- this.containerRef.current.classList.remove('non-touch-mode');
107
- this.containerRef.current.classList.remove('touch-mode');
108
- }
109
- };
110
-
111
- handleKeyDown = (ev) => {
112
- const {keyCode} = ev;
113
- if (is('enter', keyCode) && this.containerRef.current.classList.contains('touch-mode')) {
114
- // Prevent onclick event trigger by enter key
115
- ev.preventDefault();
116
- }
117
-
118
- this.containerRef.current.classList.add('non-touch-mode');
119
- this.containerRef.current.classList.remove('touch-mode');
120
- };
121
-
122
- navigableFilter = (elem) => {
123
- while (elem && elem !== document && elem.nodeType === 1) {
124
- if (elem.getAttribute('data-spotlight-container-disabled') === 'true') return false;
125
- elem = elem.parentNode;
126
- }
127
- };
128
-
129
- render () {
130
- return (
131
- <div ref={this.containerRef}>
132
- <Wrapped {...this.props} />
133
- </div>
134
- );
135
- }
136
- };
137
- });
138
81
 
139
- export default SpotlightRootDecorator;
140
- export {
141
- SpotlightRootDecorator
142
- };
82
+ var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
83
+ var _class, _temp;
84
+
85
+ var noAutoFocus = config.noAutoFocus;
86
+ var lastInputType = 'key';
87
+ var needChangeTouchMode = false;
88
+ return _temp = _class = /*#__PURE__*/function (_React$Component) {
89
+ _inherits(_class, _React$Component);
90
+
91
+ var _super = _createSuper(_class);
92
+
93
+ function _class(props) {
94
+ var _this;
95
+
96
+ _classCallCheck(this, _class);
97
+
98
+ _this = _super.call(this, props); // In other modules, this reference DOM element could be referred by `#root > div`.
99
+
100
+ _this.getLastInputType = function () {
101
+ return new Promise(function (resolve, reject) {
102
+ if (window.PalmSystem) {
103
+ new _LS2Request["default"]().send({
104
+ service: 'luna://com.webos.surfacemanager',
105
+ method: 'getLastInputType',
106
+ subscribe: true,
107
+ onSuccess: function onSuccess(res) {
108
+ lastInputType = res.lastInputType;
109
+ needChangeTouchMode = true;
110
+ resolve();
111
+ },
112
+ onFailure: function onFailure(err) {
113
+ reject('Failed to get system LastInputType: ' + JSON.stringify(err));
114
+ }
115
+ });
116
+ } else {
117
+ resolve();
118
+ }
119
+ });
120
+ };
121
+
122
+ _this.handlePointerOver = function (ev) {
123
+ return _this.setTouchModeClass(ev.pointerType);
124
+ };
125
+
126
+ _this.handleFocusIn = function () {
127
+ if (needChangeTouchMode) {
128
+ _this.setTouchModeClass(lastInputType);
129
+ }
130
+ };
131
+
132
+ _this.handleKeyDown = function (ev) {
133
+ var keyCode = ev.keyCode;
134
+
135
+ if ((0, _keymap.is)('enter', keyCode) && _this.containerRef.current.classList.contains('touch-mode')) {
136
+ // Prevent onclick event trigger by enter key
137
+ ev.preventDefault();
138
+ }
139
+
140
+ setTimeout(function () {
141
+ _this.setTouchModeClass(lastInputType);
142
+ }, 0);
143
+ };
144
+
145
+ _this.navigableFilter = function (elem) {
146
+ while (elem && elem !== document && elem.nodeType === 1) {
147
+ if (elem.getAttribute('data-spotlight-container-disabled') === 'true') return false;
148
+ elem = elem.parentNode;
149
+ }
150
+ };
151
+
152
+ _this.containerRef = /*#__PURE__*/_react["default"].createRef();
153
+
154
+ if (typeof window === 'object') {
155
+ _spotlight["default"].initialize({
156
+ selector: '.' + _Spottable.spottableClass,
157
+ restrict: 'none'
158
+ });
159
+
160
+ _spotlight["default"].set(_container.rootContainerId, {
161
+ overflow: true
162
+ });
163
+ }
164
+
165
+ return _this;
166
+ }
167
+
168
+ _createClass(_class, [{
169
+ key: "componentDidMount",
170
+ value: function componentDidMount() {
171
+ var _this2 = this;
172
+
173
+ this.getLastInputType()["finally"](function () {
174
+ if (_this2 && _this2.containerRef && _this2.containerRef.current) {
175
+ // Set initial mode
176
+ _this2.setTouchModeClass(lastInputType);
177
+ }
178
+ });
179
+
180
+ if (!noAutoFocus) {
181
+ _spotlight["default"].focus();
182
+ }
183
+
184
+ document.addEventListener('focusin', this.handleFocusIn, {
185
+ capture: true
186
+ });
187
+ document.addEventListener('pointerover', this.handlePointerOver, {
188
+ capture: true
189
+ });
190
+ document.addEventListener('keydown', this.handleKeyDown, {
191
+ capture: true
192
+ });
193
+ }
194
+ }, {
195
+ key: "componentWillUnmount",
196
+ value: function componentWillUnmount() {
197
+ _spotlight["default"].terminate();
198
+
199
+ document.removeEventListener('focusin', this.handleFocusIn, {
200
+ capture: true
201
+ });
202
+ document.removeEventListener('pointerover', this.handlePointerOver, {
203
+ capture: true
204
+ });
205
+ document.removeEventListener('keydown', this.handleKeyDown, {
206
+ capture: true
207
+ });
208
+ } // FIXME: This is a temporary support for NMRM
209
+
210
+ }, {
211
+ key: "setTouchModeClass",
212
+ value: function setTouchModeClass(inputType) {
213
+ if (inputType === 'touch') {
214
+ this.containerRef.current.classList.remove('non-touch-mode');
215
+ this.containerRef.current.classList.add('touch-mode');
216
+ } else {
217
+ this.containerRef.current.classList.add('non-touch-mode');
218
+ this.containerRef.current.classList.remove('touch-mode');
219
+ }
220
+
221
+ needChangeTouchMode = false;
222
+ }
223
+ }, {
224
+ key: "render",
225
+ value: function render() {
226
+ return /*#__PURE__*/_react["default"].createElement("div", {
227
+ ref: this.containerRef
228
+ }, /*#__PURE__*/_react["default"].createElement(Wrapped, this.props));
229
+ }
230
+ }]);
231
+
232
+ return _class;
233
+ }(_react["default"].Component), _class.displayName = 'SpotlightRootDecorator', _temp;
234
+ });
235
+ exports.SpotlightRootDecorator = SpotlightRootDecorator;
236
+ var _default = SpotlightRootDecorator;
237
+ exports["default"] = _default;
File without changes