@enact/spotlight 4.5.1 → 4.6.0
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.js +11 -31
- package/Accelerator/tests/Accelerrator-specs.js +62 -0
- package/CHANGELOG.md +28 -0
- package/Pause/Pause.js +12 -22
- package/Pause/tests/Pause-specs.js +6 -3
- package/SpotlightContainerDecorator/SpotlightContainer.js +19 -45
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +14 -58
- package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +5 -10
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +17 -47
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +16 -53
- package/SpotlightContainerDecorator/useSpotlightContainer.js +4 -15
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +4 -58
- package/SpotlightRootDecorator/tests/SpotlightRootDecorator-specs.js +38 -0
- package/Spottable/Spottable.js +26 -85
- package/Spottable/SpottableCore.js +32 -71
- package/Spottable/tests/Spottable-specs.js +8 -31
- package/Spottable/tests/useSpot-specs.js +27 -105
- package/Spottable/useSpottable.js +7 -21
- package/package.json +9 -3
- package/src/container.js +94 -219
- package/src/navigate.js +5 -74
- package/src/pointer.js +16 -31
- package/src/spotlight.js +40 -170
- package/src/target.js +61 -139
- package/src/tests/container-specs.js +5 -11
- package/src/tests/navigate-specs.js +2 -10
- package/src/tests/pointer-specs.js +1 -3
- package/src/tests/spotlight-specs.js +42 -24
- package/src/tests/target-specs.js +23 -47
- package/src/tests/utils-specs.js +54 -0
- package/src/tests/utils.js +2 -27
- package/src/utils.js +18 -37
|
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = exports.Accelerator = void 0;
|
|
7
|
-
|
|
8
7
|
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); } }
|
|
9
|
-
|
|
10
8
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
|
-
|
|
12
9
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* Provides the {@link spotlight/Accelerator.Accelerator} class.
|
|
16
12
|
*
|
|
17
13
|
* @module spotlight/Accelerator
|
|
18
14
|
* @exports Accelerator
|
|
19
15
|
*/
|
|
20
|
-
|
|
21
16
|
/**
|
|
22
17
|
* @class Accelerator
|
|
23
18
|
* @memberof spotlight/Accelerator
|
|
@@ -32,17 +27,13 @@ var Accelerator = /*#__PURE__*/_createClass(
|
|
|
32
27
|
*/
|
|
33
28
|
function Accelerator() {
|
|
34
29
|
var _this = this;
|
|
35
|
-
|
|
36
30
|
var frequency = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [3, 3, 3, 2, 2, 2, 1];
|
|
37
|
-
|
|
38
31
|
_classCallCheck(this, Accelerator);
|
|
39
|
-
|
|
40
32
|
this.processKey = function (event, callback) {
|
|
41
33
|
switch (event.type) {
|
|
42
34
|
case 'keydown':
|
|
43
35
|
if (event.keyCode !== _this.keyCode) {
|
|
44
36
|
_this.reset();
|
|
45
|
-
|
|
46
37
|
_this.time = Date.now();
|
|
47
38
|
_this.keyCode = event.keyCode;
|
|
48
39
|
return callback(event);
|
|
@@ -52,36 +43,29 @@ function Accelerator() {
|
|
|
52
43
|
return true;
|
|
53
44
|
} else {
|
|
54
45
|
var elapsedTime = Date.now() - _this.time,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
seconds = Math.floor(elapsedTime / 1000),
|
|
47
|
+
toSkip = 0;
|
|
58
48
|
seconds = seconds > _this.frequency.length - 1 ? _this.frequency.length - 1 : seconds;
|
|
59
49
|
toSkip = _this.frequency[seconds] - 1;
|
|
60
|
-
|
|
61
50
|
if (toSkip < 0) {
|
|
62
51
|
toSkip = 0;
|
|
63
52
|
}
|
|
64
|
-
|
|
65
53
|
_this.accelerating = !(seconds === 0 && _this.skipped === 0);
|
|
66
|
-
|
|
67
54
|
if (_this.skipped >= toSkip) {
|
|
68
55
|
_this.skipped = 0;
|
|
69
56
|
return callback(event);
|
|
70
57
|
} else {
|
|
71
|
-
_this.skipped++;
|
|
72
|
-
|
|
58
|
+
_this.skipped++;
|
|
59
|
+
// Prevent skipped keydown events from bubbling
|
|
73
60
|
event.preventDefault();
|
|
74
61
|
return true;
|
|
75
62
|
}
|
|
76
63
|
}
|
|
77
|
-
|
|
78
64
|
case 'keyup':
|
|
79
65
|
_this.reset();
|
|
80
|
-
|
|
81
66
|
return callback(event);
|
|
82
67
|
}
|
|
83
68
|
};
|
|
84
|
-
|
|
85
69
|
this.reset = function () {
|
|
86
70
|
_this.skipped = 0;
|
|
87
71
|
_this.time = 0;
|
|
@@ -89,15 +73,12 @@ function Accelerator() {
|
|
|
89
73
|
_this.canceled = false;
|
|
90
74
|
_this.accelerating = false;
|
|
91
75
|
};
|
|
92
|
-
|
|
93
76
|
this.cancel = function () {
|
|
94
77
|
_this.canceled = true;
|
|
95
78
|
};
|
|
96
|
-
|
|
97
79
|
this.isAccelerating = function () {
|
|
98
80
|
return _this.accelerating;
|
|
99
81
|
};
|
|
100
|
-
|
|
101
82
|
/*
|
|
102
83
|
* Whether the instance is currently in an accelerating state.
|
|
103
84
|
*
|
|
@@ -105,38 +86,39 @@ function Accelerator() {
|
|
|
105
86
|
* @default false
|
|
106
87
|
*/
|
|
107
88
|
this.accelerating = false;
|
|
89
|
+
|
|
108
90
|
/*
|
|
109
91
|
* The current count of skipped events.
|
|
110
92
|
*
|
|
111
93
|
* @type {Number}
|
|
112
94
|
* @default 0
|
|
113
95
|
*/
|
|
114
|
-
|
|
115
96
|
this.skipped = 0;
|
|
97
|
+
|
|
116
98
|
/*
|
|
117
99
|
* The timestamp of the last evaluated event.
|
|
118
100
|
*
|
|
119
101
|
* @type {Number}
|
|
120
102
|
* @default 0
|
|
121
103
|
*/
|
|
122
|
-
|
|
123
104
|
this.time = 0;
|
|
105
|
+
|
|
124
106
|
/*
|
|
125
107
|
* The keyCode of the last evaluated event.
|
|
126
108
|
*
|
|
127
109
|
* @type {Number}
|
|
128
110
|
* @default 0
|
|
129
111
|
*/
|
|
130
|
-
|
|
131
112
|
this.keyCode = 0;
|
|
113
|
+
|
|
132
114
|
/*
|
|
133
115
|
* Whether the instance is in a state of being canceled.
|
|
134
116
|
*
|
|
135
117
|
* @type {Boolean}
|
|
136
118
|
* @default false
|
|
137
119
|
*/
|
|
138
|
-
|
|
139
120
|
this.canceled = false;
|
|
121
|
+
|
|
140
122
|
/*
|
|
141
123
|
* Controls the frequency with which the acceleration will "freeze". While frozen,
|
|
142
124
|
* the current target item cannot change, and all events are directed to it.
|
|
@@ -145,9 +127,9 @@ function Accelerator() {
|
|
|
145
127
|
* @default [3, 3, 3, 2, 2, 2, 1]
|
|
146
128
|
* @public
|
|
147
129
|
*/
|
|
148
|
-
|
|
149
130
|
this.frequency = frequency;
|
|
150
131
|
}
|
|
132
|
+
|
|
151
133
|
/**
|
|
152
134
|
* Called with the current keydown event and callback, which will be called when the event is
|
|
153
135
|
* allowed through.
|
|
@@ -158,9 +140,7 @@ function Accelerator() {
|
|
|
158
140
|
* @returns {Boolean} `true` if the event was consumed by processKey and callback was not called
|
|
159
141
|
* @public
|
|
160
142
|
* @memberof spotlight/Accelerator.Accelerator.prototype
|
|
161
|
-
*/
|
|
162
|
-
);
|
|
163
|
-
|
|
143
|
+
*/);
|
|
164
144
|
exports.Accelerator = Accelerator;
|
|
165
145
|
var _default = Accelerator;
|
|
166
146
|
exports["default"] = _default;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Accelerator = _interopRequireDefault(require("../Accelerator"));
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
5
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
6
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
7
|
+
describe('Accelerator', function () {
|
|
8
|
+
test('should invoke callback function passed by processKey method', function () {
|
|
9
|
+
var SpotlightAccelerator = new _Accelerator["default"]([3, 2]);
|
|
10
|
+
var acceleratorCallback = jest.fn();
|
|
11
|
+
var handleKeyDown = function handleKeyDown(ev) {
|
|
12
|
+
SpotlightAccelerator.processKey(ev, acceleratorCallback);
|
|
13
|
+
};
|
|
14
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
15
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
16
|
+
onKeyDown: handleKeyDown,
|
|
17
|
+
children: "button"
|
|
18
|
+
})
|
|
19
|
+
}));
|
|
20
|
+
var button = _react.screen.queryByText('button');
|
|
21
|
+
_react.fireEvent.keyDown(button, {
|
|
22
|
+
which: 13,
|
|
23
|
+
keyCode: 13,
|
|
24
|
+
code: 13
|
|
25
|
+
});
|
|
26
|
+
expect(acceleratorCallback).toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
test('should set \'accelerating\' true when keyDown event occurs several time', function () {
|
|
29
|
+
var SpotlightAccelerator = new _Accelerator["default"]([3, 2]);
|
|
30
|
+
var acceleratorCallback = jest.fn();
|
|
31
|
+
var actual = false;
|
|
32
|
+
var handleKeyDown = function handleKeyDown(ev) {
|
|
33
|
+
SpotlightAccelerator.processKey(ev, acceleratorCallback);
|
|
34
|
+
};
|
|
35
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
36
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
37
|
+
onKeyDown: handleKeyDown,
|
|
38
|
+
children: "button"
|
|
39
|
+
})
|
|
40
|
+
}));
|
|
41
|
+
var button = _react.screen.queryByText('button');
|
|
42
|
+
_react.fireEvent.keyDown(button, {
|
|
43
|
+
which: 13,
|
|
44
|
+
keyCode: 13,
|
|
45
|
+
code: 13
|
|
46
|
+
});
|
|
47
|
+
actual = actual | SpotlightAccelerator.isAccelerating();
|
|
48
|
+
_react.fireEvent.keyDown(button, {
|
|
49
|
+
which: 13,
|
|
50
|
+
keyCode: 13,
|
|
51
|
+
code: 13
|
|
52
|
+
});
|
|
53
|
+
actual = actual | SpotlightAccelerator.isAccelerating();
|
|
54
|
+
_react.fireEvent.keyDown(button, {
|
|
55
|
+
which: 13,
|
|
56
|
+
keyCode: 13,
|
|
57
|
+
code: 13
|
|
58
|
+
});
|
|
59
|
+
actual = actual | SpotlightAccelerator.isAccelerating();
|
|
60
|
+
expect(actual).toBe(1);
|
|
61
|
+
});
|
|
62
|
+
});
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
The following is a curated list of changes in the Enact spotlight module, newest changes on the top.
|
|
4
4
|
|
|
5
|
+
## [4.6.0] - 2022-12-05
|
|
6
|
+
|
|
7
|
+
No significant changes.
|
|
8
|
+
|
|
9
|
+
## [4.0.12] - 2022-09-16
|
|
10
|
+
|
|
11
|
+
No significant changes.
|
|
12
|
+
|
|
13
|
+
## [4.5.2] - 2022-08-17
|
|
14
|
+
|
|
15
|
+
No significant changes.
|
|
16
|
+
|
|
5
17
|
## [4.5.1] - 2022-08-03
|
|
6
18
|
|
|
7
19
|
No significant changes.
|
|
@@ -32,10 +44,18 @@ No significant changes.
|
|
|
32
44
|
|
|
33
45
|
- `spotlight` to not focus on an invisible element
|
|
34
46
|
|
|
47
|
+
## [4.0.11] - 2022-04-25
|
|
48
|
+
|
|
49
|
+
No significant changes.
|
|
50
|
+
|
|
35
51
|
## [4.5.0-alpha.1] - 2022-04-15
|
|
36
52
|
|
|
37
53
|
No significant changes.
|
|
38
54
|
|
|
55
|
+
## [4.0.10] - 2022-04-05
|
|
56
|
+
|
|
57
|
+
No significant changes.
|
|
58
|
+
|
|
39
59
|
## [4.1.4] - 2022-03-24
|
|
40
60
|
|
|
41
61
|
No significant changes.
|
|
@@ -49,10 +69,18 @@ No significant changes.
|
|
|
49
69
|
- `spotlight` to correctly control focus when boundaries of an element are not integers
|
|
50
70
|
- Styles for `debug spotlight` option in samplers to work properly
|
|
51
71
|
|
|
72
|
+
## [3.2.7] - 2022-01-17
|
|
73
|
+
|
|
74
|
+
No significant changes.
|
|
75
|
+
|
|
52
76
|
## [4.1.2] - 2021-12-22
|
|
53
77
|
|
|
54
78
|
No significant changes.
|
|
55
79
|
|
|
80
|
+
## [4.0.9] - 2021-12-15
|
|
81
|
+
|
|
82
|
+
No significant changes.
|
|
83
|
+
|
|
56
84
|
## [4.1.1] - 2021-11-30
|
|
57
85
|
|
|
58
86
|
No significant changes.
|
package/Pause/Pause.js
CHANGED
|
@@ -7,20 +7,16 @@ exports["default"] = exports.Pause = void 0;
|
|
|
7
7
|
exports.isPaused = isPaused;
|
|
8
8
|
exports.pause = pause;
|
|
9
9
|
exports.resume = _resume;
|
|
10
|
-
|
|
11
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
-
|
|
13
11
|
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); } }
|
|
14
|
-
|
|
15
12
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
-
|
|
17
13
|
/**
|
|
18
14
|
* Provides a class which allows consumers to safely pause and resume spotlight without resuming
|
|
19
15
|
* another consumer's pause.
|
|
20
16
|
*
|
|
21
17
|
* When multiple components attempt to pause and resume spotlight at overlapping times using
|
|
22
|
-
*
|
|
23
|
-
*
|
|
18
|
+
* {@link spotlight.Spotlight.pause|Spotlight.pause()} and
|
|
19
|
+
* {@link spotlight.Spotlight.resume|Spotlight.resume()}, one component might resume spotlight when
|
|
24
20
|
* another expected it to still be paused.
|
|
25
21
|
*
|
|
26
22
|
* `Pause` helps to address this by setting a "soft lock" on the pause which informs other instances
|
|
@@ -28,8 +24,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
28
24
|
* by the instance that locked it. Subsequent calls to `pause` and `resume` on another instance of
|
|
29
25
|
* `Pause` have no effect.
|
|
30
26
|
*
|
|
31
|
-
* *Note:* The top-level
|
|
32
|
-
*
|
|
27
|
+
* *Note:* The top-level {@link spotlight.Spotlight.pause|Spotlight.pause()} and
|
|
28
|
+
* {@link spotlight.Spotlight.resume|Spotlight.resume()} do not respect the pause locks and act as
|
|
33
29
|
* a user-space escape hatch.
|
|
34
30
|
*
|
|
35
31
|
* ```
|
|
@@ -58,19 +54,21 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
58
54
|
* @exports pause
|
|
59
55
|
* @exports resume
|
|
60
56
|
*/
|
|
61
|
-
|
|
57
|
+
|
|
58
|
+
var paused = false;
|
|
59
|
+
|
|
60
|
+
// Private, exported methods used by Spotlight to set and query the pause state from its public API
|
|
62
61
|
|
|
63
62
|
function pause() {
|
|
64
63
|
paused = true;
|
|
65
64
|
}
|
|
66
|
-
|
|
67
65
|
function _resume() {
|
|
68
66
|
paused = false;
|
|
69
67
|
}
|
|
70
|
-
|
|
71
68
|
function isPaused() {
|
|
72
69
|
return paused !== false;
|
|
73
70
|
}
|
|
71
|
+
|
|
74
72
|
/**
|
|
75
73
|
* Acts as a semaphore for Spotlight pause state ensuring that only the last Pause instance can
|
|
76
74
|
* resume Spotlight.
|
|
@@ -82,8 +80,6 @@ function isPaused() {
|
|
|
82
80
|
* @memberof spotlight/Pause
|
|
83
81
|
* @public
|
|
84
82
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
83
|
var Pause = /*#__PURE__*/function () {
|
|
88
84
|
/**
|
|
89
85
|
* Accepts a name for the instance
|
|
@@ -98,15 +94,14 @@ var Pause = /*#__PURE__*/function () {
|
|
|
98
94
|
*/
|
|
99
95
|
function Pause(name) {
|
|
100
96
|
_classCallCheck(this, Pause);
|
|
101
|
-
|
|
102
97
|
this.name = name;
|
|
103
98
|
}
|
|
104
|
-
|
|
105
99
|
_createClass(Pause, [{
|
|
106
100
|
key: "toString",
|
|
107
101
|
value: function toString() {
|
|
108
102
|
return "Pause<".concat(this.name, ">");
|
|
109
103
|
}
|
|
104
|
+
|
|
110
105
|
/**
|
|
111
106
|
* Returns `true` when Spotlight is paused by this instance
|
|
112
107
|
*
|
|
@@ -114,12 +109,12 @@ var Pause = /*#__PURE__*/function () {
|
|
|
114
109
|
* @memberof spotlight/Pause.Pause.prototype
|
|
115
110
|
* @public
|
|
116
111
|
*/
|
|
117
|
-
|
|
118
112
|
}, {
|
|
119
113
|
key: "isPaused",
|
|
120
114
|
value: function isPaused() {
|
|
121
115
|
return paused === this;
|
|
122
116
|
}
|
|
117
|
+
|
|
123
118
|
/**
|
|
124
119
|
* Pauses spotlight if not currently paused
|
|
125
120
|
*
|
|
@@ -127,7 +122,6 @@ var Pause = /*#__PURE__*/function () {
|
|
|
127
122
|
* @memberof spotlight/Pause.Pause.prototype
|
|
128
123
|
* @public
|
|
129
124
|
*/
|
|
130
|
-
|
|
131
125
|
}, {
|
|
132
126
|
key: "pause",
|
|
133
127
|
value: function pause() {
|
|
@@ -135,6 +129,7 @@ var Pause = /*#__PURE__*/function () {
|
|
|
135
129
|
paused = this;
|
|
136
130
|
}
|
|
137
131
|
}
|
|
132
|
+
|
|
138
133
|
/**
|
|
139
134
|
* Resumes spotlight if this instance was the last to pause spotlight
|
|
140
135
|
*
|
|
@@ -142,23 +137,18 @@ var Pause = /*#__PURE__*/function () {
|
|
|
142
137
|
* @memberof spotlight/Pause.Pause.prototype
|
|
143
138
|
* @public
|
|
144
139
|
*/
|
|
145
|
-
|
|
146
140
|
}, {
|
|
147
141
|
key: "resume",
|
|
148
142
|
value: function resume() {
|
|
149
143
|
if (this.isPaused()) {
|
|
150
144
|
_resume();
|
|
151
|
-
|
|
152
145
|
return true;
|
|
153
146
|
}
|
|
154
|
-
|
|
155
147
|
return false;
|
|
156
148
|
}
|
|
157
149
|
}]);
|
|
158
|
-
|
|
159
150
|
return Pause;
|
|
160
151
|
}();
|
|
161
|
-
|
|
162
152
|
exports.Pause = Pause;
|
|
163
153
|
var _default = Pause;
|
|
164
154
|
exports["default"] = _default;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Pause = _interopRequireWildcard(require("../Pause"));
|
|
4
|
-
|
|
5
4
|
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); }
|
|
6
|
-
|
|
7
5
|
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; }
|
|
8
|
-
|
|
9
6
|
var PAUSED = 'Paused';
|
|
10
7
|
var NOT_PAUSED = 'Not Paused';
|
|
11
8
|
describe('Pause', function () {
|
|
@@ -62,4 +59,10 @@ describe('Pause', function () {
|
|
|
62
59
|
var actual = (0, _Pause.isPaused)() ? PAUSED : NOT_PAUSED;
|
|
63
60
|
expect(actual).toBe(expected);
|
|
64
61
|
});
|
|
62
|
+
test('should return name of the pause instance', function () {
|
|
63
|
+
var subject = new _Pause["default"]('paused');
|
|
64
|
+
var expected = 'Pause<paused>';
|
|
65
|
+
var actual = subject.toString();
|
|
66
|
+
expect(actual).toBe(expected);
|
|
67
|
+
});
|
|
65
68
|
});
|
|
@@ -4,45 +4,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = exports.SpotlightContainer = void 0;
|
|
7
|
-
|
|
8
7
|
var _handle = require("@enact/core/handle");
|
|
9
|
-
|
|
10
8
|
var _pointer = require("../src/pointer");
|
|
11
|
-
|
|
12
9
|
var _spotlight = _interopRequireDefault(require("../src/spotlight"));
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
|
-
|
|
16
11
|
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; }
|
|
17
|
-
|
|
18
12
|
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; }
|
|
19
|
-
|
|
20
13
|
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; }
|
|
21
|
-
|
|
22
14
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
|
-
|
|
24
15
|
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); } }
|
|
25
|
-
|
|
26
16
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
27
|
-
|
|
28
17
|
var isNewPointerPosition = function isNewPointerPosition(ev) {
|
|
29
18
|
return (0, _pointer.hasPointerMoved)(ev.clientX, ev.clientY);
|
|
30
19
|
};
|
|
31
|
-
|
|
32
20
|
var SpotlightContainer = /*#__PURE__*/function () {
|
|
33
21
|
// set up context and props so we can use handle binding
|
|
22
|
+
|
|
34
23
|
function SpotlightContainer(_ref) {
|
|
35
24
|
var _this = this;
|
|
36
|
-
|
|
37
25
|
var containerConfig = _ref.containerConfig,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
navigableFilter = _ref.navigableFilter,
|
|
27
|
+
preserveId = _ref.preserveId;
|
|
41
28
|
_classCallCheck(this, SpotlightContainer);
|
|
42
|
-
|
|
43
29
|
this.context = {};
|
|
44
30
|
this.props = {};
|
|
45
|
-
|
|
46
31
|
this.navigableFilter = function (elem) {
|
|
47
32
|
// If the component to which this was applied specified a navigableFilter, run it
|
|
48
33
|
if (typeof _this.filter === 'function') {
|
|
@@ -50,65 +35,59 @@ var SpotlightContainer = /*#__PURE__*/function () {
|
|
|
50
35
|
return false;
|
|
51
36
|
}
|
|
52
37
|
}
|
|
53
|
-
|
|
54
38
|
return true;
|
|
55
39
|
};
|
|
56
|
-
|
|
57
40
|
this.onBlurCapture = function (ev) {
|
|
58
41
|
if (_this.shouldPreventBlur) {
|
|
59
42
|
(0, _handle.stop)(ev);
|
|
60
43
|
return false;
|
|
61
44
|
}
|
|
62
|
-
|
|
63
45
|
return true;
|
|
64
46
|
};
|
|
65
|
-
|
|
66
47
|
this.onFocusCapture = function (ev) {
|
|
67
48
|
if (_this.props.disabled === true) {
|
|
68
49
|
(0, _handle.stop)(ev);
|
|
69
|
-
|
|
70
50
|
_this.silentBlur(ev);
|
|
71
|
-
|
|
72
51
|
return false;
|
|
73
52
|
}
|
|
74
|
-
|
|
75
53
|
return true;
|
|
76
54
|
};
|
|
77
|
-
|
|
78
55
|
this.onPointerEnter = (0, _handle.handle)(isNewPointerPosition, function () {
|
|
79
56
|
return _spotlight["default"].setActiveContainer(_this.id);
|
|
80
57
|
}).bindAs(this, 'onPointerEnter');
|
|
81
58
|
this.onPointerLeave = (0, _handle.handle)((0, _handle.not)((0, _handle.forProp)('restrict', 'self-only')), isNewPointerPosition, function (ev) {
|
|
82
59
|
var parentContainer = ev.currentTarget.parentNode.closest('[data-spotlight-container]');
|
|
60
|
+
var activeContainer = _spotlight["default"].getActiveContainer();
|
|
83
61
|
|
|
84
|
-
|
|
62
|
+
// if this container is wrapped by another and this is the currently active
|
|
85
63
|
// container, move the active container to the parent
|
|
86
|
-
|
|
87
|
-
|
|
88
64
|
if (parentContainer && activeContainer === _this.id) {
|
|
89
65
|
activeContainer = parentContainer.dataset.spotlightId;
|
|
90
|
-
|
|
91
66
|
_spotlight["default"].setActiveContainer(activeContainer);
|
|
92
67
|
}
|
|
93
68
|
}).bindAs(this, 'onPointerLeave');
|
|
94
69
|
// spotlight id - set either via props or generated by Spotlight
|
|
95
|
-
this.id = null;
|
|
70
|
+
this.id = null;
|
|
96
71
|
|
|
72
|
+
// Preserve the spotlight id across instances when it is set via props and preserveId is set
|
|
97
73
|
this.canPreserveId = preserveId;
|
|
98
|
-
this.preserveId = false;
|
|
74
|
+
this.preserveId = false;
|
|
99
75
|
|
|
100
|
-
|
|
76
|
+
// container config - set once when the container is added
|
|
77
|
+
this.config = containerConfig;
|
|
101
78
|
|
|
102
|
-
|
|
79
|
+
// optional filter function to limit the spottable candidates for this container
|
|
80
|
+
this.filter = navigableFilter;
|
|
103
81
|
|
|
82
|
+
// private hash of spotlight DOM attributes
|
|
104
83
|
this.attr = {
|
|
105
84
|
'data-spotlight-container': true
|
|
106
|
-
};
|
|
107
|
-
// result of this component imperatively blurring itself on focus when spotlightDisabled
|
|
85
|
+
};
|
|
108
86
|
|
|
87
|
+
// Used to indicate that we want to stop propagation on blur events that occur as a
|
|
88
|
+
// result of this component imperatively blurring itself on focus when spotlightDisabled
|
|
109
89
|
this.shouldPreventBlur = false;
|
|
110
90
|
}
|
|
111
|
-
|
|
112
91
|
_createClass(SpotlightContainer, [{
|
|
113
92
|
key: "attributes",
|
|
114
93
|
get: function get() {
|
|
@@ -118,16 +97,14 @@ var SpotlightContainer = /*#__PURE__*/function () {
|
|
|
118
97
|
key: "setProps",
|
|
119
98
|
value: function setProps(props) {
|
|
120
99
|
var disabled = props.disabled,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
100
|
+
id = props.id,
|
|
101
|
+
muted = props.muted,
|
|
102
|
+
restrict = props.restrict;
|
|
124
103
|
this.props = props;
|
|
125
|
-
|
|
126
104
|
if (this.id == null || id && this.id !== id) {
|
|
127
105
|
if (this.id) {
|
|
128
106
|
this.releaseContainer(this.id);
|
|
129
107
|
}
|
|
130
|
-
|
|
131
108
|
this.id = _spotlight["default"].add(_objectSpread(_objectSpread({}, this.config), {}, {
|
|
132
109
|
id: id,
|
|
133
110
|
restrict: restrict,
|
|
@@ -139,7 +116,6 @@ var SpotlightContainer = /*#__PURE__*/function () {
|
|
|
139
116
|
restrict: restrict
|
|
140
117
|
});
|
|
141
118
|
}
|
|
142
|
-
|
|
143
119
|
this.attr['data-spotlight-id'] = this.id;
|
|
144
120
|
this.attr['data-spotlight-container-disabled'] = disabled;
|
|
145
121
|
this.attr['data-spotlight-container-muted'] = muted;
|
|
@@ -167,10 +143,8 @@ var SpotlightContainer = /*#__PURE__*/function () {
|
|
|
167
143
|
this.shouldPreventBlur = false;
|
|
168
144
|
}
|
|
169
145
|
}]);
|
|
170
|
-
|
|
171
146
|
return SpotlightContainer;
|
|
172
147
|
}();
|
|
173
|
-
|
|
174
148
|
exports.SpotlightContainer = SpotlightContainer;
|
|
175
149
|
var _default = SpotlightContainer;
|
|
176
150
|
exports["default"] = _default;
|