@enact/spotlight 4.7.9 → 4.7.11
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 +2 -2
- package/CHANGELOG.md +22 -0
- package/Pause/Pause.js +2 -2
- package/Pause/tests/Pause-specs.js +2 -2
- package/README.md +1 -1
- package/SpotlightContainerDecorator/SpotlightContainer.js +2 -2
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +4 -4
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +2 -2
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +2 -2
- package/SpotlightContainerDecorator/useSpotlightContainer.js +1 -0
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +13 -13
- package/SpotlightRootDecorator/tests/SpotlightRootDecorator-specs.js +2 -2
- package/Spottable/Spottable.js +4 -4
- package/Spottable/SpottableCore.js +2 -2
- package/Spottable/tests/Spottable-specs.js +2 -2
- package/Spottable/tests/useSpot-specs.js +4 -4
- package/Spottable/useSpottable.js +2 -2
- package/package.json +2 -2
- package/src/container.js +28 -7
- package/src/target.js +21 -5
- package/src/tests/container-specs.js +197 -178
- package/src/tests/spotlight-specs.js +5 -6
- package/src/tests/target-specs.js +14 -16
- package/src/tests/utils-specs.js +76 -0
- package/src/tests/utils.js +3 -4
- package/src/utils.js +29 -1
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
var _container4 = require("../container");
|
|
4
4
|
var _spotlight = _interopRequireDefault(require("../spotlight"));
|
|
5
5
|
var _utils = require("./utils");
|
|
6
|
-
var _container, _container2, _container3;
|
|
7
6
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
7
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
-
function _toPropertyKey(
|
|
10
|
-
function _toPrimitive(
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
9
|
+
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); }
|
|
11
10
|
var nonSpottable = function nonSpottable() {
|
|
12
11
|
return (0, _utils.node)({
|
|
13
12
|
className: 'other'
|
|
@@ -16,11 +15,11 @@ var nonSpottable = function nonSpottable() {
|
|
|
16
15
|
var scenarios = {
|
|
17
16
|
complexTree: (0, _utils.join)((0, _utils.spottable)({
|
|
18
17
|
'data-spotlight-id': 's1'
|
|
19
|
-
}), (0, _utils.spottable)(nonSpottable()), (0, _utils.container)((
|
|
18
|
+
}), (0, _utils.spottable)(nonSpottable()), (0, _utils.container)(_defineProperty(_defineProperty({}, _container4.containerAttribute, 'first-container'), "children", (0, _utils.join)((0, _utils.someSpottables)(2), (0, _utils.container)(_defineProperty(_defineProperty({}, _container4.containerAttribute, 'second-container'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
20
19
|
id: 'secondContainerFirstSpottable'
|
|
21
|
-
}), (0, _utils.someSpottables)(2), (0, _utils.container)((
|
|
20
|
+
}), (0, _utils.someSpottables)(2), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container4.containerAttribute, 'third-container'), 'data-spotlight-container-disabled', true), "children", (0, _utils.join)((0, _utils.someSpottables)(4), (0, _utils.node)({
|
|
22
21
|
id: 'child-of-third'
|
|
23
|
-
})))
|
|
22
|
+
})))))))))))
|
|
24
23
|
};
|
|
25
24
|
var setupContainers = function setupContainers() {
|
|
26
25
|
_spotlight["default"].setPointerMode(false);
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
var _container12 = require("../container");
|
|
4
4
|
var _target = require("../target");
|
|
5
5
|
var _utils = require("./utils");
|
|
6
|
-
var _container2, _container3, _container4, _container5, _container6, _container7, _container8, _container9, _container10, _container11;
|
|
7
6
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
function _toPropertyKey(
|
|
9
|
-
function _toPrimitive(
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
8
|
+
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); }
|
|
10
9
|
var nonSpottable = function nonSpottable() {
|
|
11
10
|
return (0, _utils.node)({
|
|
12
11
|
className: 'other'
|
|
@@ -22,18 +21,17 @@ var positionedSpottable = function positionedSpottable(id, top, left) {
|
|
|
22
21
|
});
|
|
23
22
|
};
|
|
24
23
|
var grid = function grid() {
|
|
25
|
-
|
|
26
|
-
return (0, _utils.container)((_container = {}, _defineProperty(_container, _container12.containerAttribute, 'grid'), _defineProperty(_container, "style", 'position: relative; height: 30px; width: 30px;'), _defineProperty(_container, "children", (0, _utils.join)(positionedSpottable('top-left', 0, 0), positionedSpottable('top-center', 0, 10), positionedSpottable('top-right', 0, 20), positionedSpottable('middle-left', 10, 0), positionedSpottable('middle-center', 10, 10), positionedSpottable('middle-right', 10, 20), positionedSpottable('bottom-left', 20, 0), positionedSpottable('bottom-center', 20, 10), positionedSpottable('bottom-right', 20, 20))), _container));
|
|
24
|
+
return (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'grid'), "style", 'position: relative; height: 30px; width: 30px;'), "children", (0, _utils.join)(positionedSpottable('top-left', 0, 0), positionedSpottable('top-center', 0, 10), positionedSpottable('top-right', 0, 20), positionedSpottable('middle-left', 10, 0), positionedSpottable('middle-center', 10, 10), positionedSpottable('middle-right', 10, 20), positionedSpottable('bottom-left', 20, 0), positionedSpottable('bottom-center', 20, 10), positionedSpottable('bottom-right', 20, 20))));
|
|
27
25
|
};
|
|
28
26
|
var scenarios = {
|
|
29
|
-
complexTree: (0, _utils.join)((0, _utils.spottable)(nonSpottable()), (0, _utils.container)((
|
|
27
|
+
complexTree: (0, _utils.join)((0, _utils.spottable)(nonSpottable()), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'first-container'), "children", (0, _utils.join)((0, _utils.someSpottables)(2), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'second-container'), "children", (0, _utils.join)((0, _utils.someSpottables)(3), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'third-container'), 'data-spotlight-container-disabled', true), "children", (0, _utils.join)((0, _utils.someSpottables)(4), (0, _utils.node)({
|
|
30
28
|
id: 'child-of-third'
|
|
31
|
-
})))
|
|
29
|
+
}))))))))))),
|
|
32
30
|
nonSpottableInContainer: (0, _utils.join)((0, _utils.spottable)({
|
|
33
31
|
id: 'in-root'
|
|
34
|
-
}), (0, _utils.container)((
|
|
32
|
+
}), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'first'), "children", (0, _utils.join)(nonSpottable(), (0, _utils.spottable)({
|
|
35
33
|
id: 'in-first'
|
|
36
|
-
})))
|
|
34
|
+
})))), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'second'), "children", (0, _utils.join)(nonSpottable())))),
|
|
37
35
|
grid: (0, _utils.join)((0, _utils.spottable)({
|
|
38
36
|
id: 'before-grid',
|
|
39
37
|
style: 'height: 10px'
|
|
@@ -53,7 +51,7 @@ var scenarios = {
|
|
|
53
51
|
}), (0, _utils.node)({
|
|
54
52
|
// allocate some empty space so that overflow items would be otherwise navigable
|
|
55
53
|
style: 'height: 100px'
|
|
56
|
-
}), (0, _utils.container)((
|
|
54
|
+
}), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'overflow-container'), "style", 'position: relative; height: 30px; width: 30px;'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
57
55
|
id: 'overflow-above',
|
|
58
56
|
style: 'position: absolute; top: -10px; left: 0px; height: 10px; width: 10px;'
|
|
59
57
|
}), (0, _utils.spottable)({
|
|
@@ -62,23 +60,23 @@ var scenarios = {
|
|
|
62
60
|
}), (0, _utils.spottable)({
|
|
63
61
|
id: 'overflow-within',
|
|
64
62
|
style: 'position: absolute; top: 0px; left: 0px; height: 10px; width: 10px;'
|
|
65
|
-
})))
|
|
63
|
+
}))))),
|
|
66
64
|
overflowLargeSubContainer: (0, _utils.join)((0, _utils.spottable)({
|
|
67
65
|
id: 'outside-overflow'
|
|
68
66
|
}), (0, _utils.node)({
|
|
69
67
|
// allocate some empty space so that overflow items would be otherwise navigable
|
|
70
68
|
style: 'height: 100px'
|
|
71
|
-
}), (0, _utils.container)((
|
|
69
|
+
}), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'overflow-container'), "style", 'position: relative; height: 30px; width: 30px;'), "children", (0, _utils.join)((0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'inside'), "style", 'position: absolute; top: -10px; left: 0px; height: 50px; width: 10px;'), "children", (0, _utils.join)((0, _utils.node)({
|
|
72
70
|
// allocate space to push following spottable into view
|
|
73
71
|
style: 'height: 10px'
|
|
74
72
|
}), (0, _utils.spottable)({
|
|
75
73
|
id: 'in-large-container'
|
|
76
|
-
})))
|
|
74
|
+
})))), (0, _utils.spottable)({
|
|
77
75
|
id: 'below-large-container',
|
|
78
76
|
style: 'position: absolute; top: 40px; left: 0px; height: 10px; width: 10px;'
|
|
79
|
-
})))
|
|
80
|
-
emptyContainer: (0, _utils.join)(positionedSpottable('above', 0, 10), (0, _utils.container)((
|
|
81
|
-
emptyContainerOverlap: (0, _utils.join)(positionedSpottable('above', 5, 10), (0, _utils.container)((
|
|
77
|
+
}))))),
|
|
78
|
+
emptyContainer: (0, _utils.join)(positionedSpottable('above', 0, 10), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'empty-container'), "style", position(10, 10))), positionedSpottable('below', 30, 0)),
|
|
79
|
+
emptyContainerOverlap: (0, _utils.join)(positionedSpottable('above', 5, 10), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'empty-container'), "style", position(10, 10))), positionedSpottable('below', 30, 0))
|
|
82
80
|
};
|
|
83
81
|
var safeTarget = function safeTarget(n, fn) {
|
|
84
82
|
return n ? fn(n) : 'NOT FOUND';
|
package/src/tests/utils-specs.js
CHANGED
|
@@ -37,6 +37,82 @@ var scenarios = {
|
|
|
37
37
|
})
|
|
38
38
|
};
|
|
39
39
|
describe('utils', function () {
|
|
40
|
+
describe('#getIntersectionRect', function () {
|
|
41
|
+
test('should return the intersection rect between two given rects', function () {
|
|
42
|
+
var rect1 = {
|
|
43
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
44
|
+
return {
|
|
45
|
+
left: 0,
|
|
46
|
+
top: 0,
|
|
47
|
+
width: 100,
|
|
48
|
+
height: 100
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var rect2 = {
|
|
53
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
54
|
+
return {
|
|
55
|
+
left: 50,
|
|
56
|
+
top: 50,
|
|
57
|
+
width: 100,
|
|
58
|
+
height: 100
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var expected = {
|
|
63
|
+
left: 50,
|
|
64
|
+
top: 50,
|
|
65
|
+
width: 50,
|
|
66
|
+
height: 50,
|
|
67
|
+
right: 100,
|
|
68
|
+
bottom: 100,
|
|
69
|
+
center: {
|
|
70
|
+
x: 75,
|
|
71
|
+
y: 75,
|
|
72
|
+
left: 75,
|
|
73
|
+
right: 75,
|
|
74
|
+
top: 75,
|
|
75
|
+
bottom: 75
|
|
76
|
+
},
|
|
77
|
+
element: rect2
|
|
78
|
+
};
|
|
79
|
+
var actual = (0, _utils.getIntersectionRect)(rect1, rect2);
|
|
80
|
+
expect(actual).toEqual(expected);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('#getRect', function () {
|
|
84
|
+
test('should return the rect value calculated based on the given element', function () {
|
|
85
|
+
var element = {
|
|
86
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
87
|
+
return {
|
|
88
|
+
left: 10,
|
|
89
|
+
top: 20,
|
|
90
|
+
width: 100,
|
|
91
|
+
height: 200
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var expected = {
|
|
96
|
+
left: 10,
|
|
97
|
+
top: 20,
|
|
98
|
+
width: 100,
|
|
99
|
+
height: 200,
|
|
100
|
+
right: 110,
|
|
101
|
+
bottom: 220,
|
|
102
|
+
center: {
|
|
103
|
+
x: 60,
|
|
104
|
+
y: 120,
|
|
105
|
+
left: 60,
|
|
106
|
+
right: 60,
|
|
107
|
+
top: 120,
|
|
108
|
+
bottom: 120
|
|
109
|
+
},
|
|
110
|
+
element: element
|
|
111
|
+
};
|
|
112
|
+
var actual = (0, _utils.getRect)(element);
|
|
113
|
+
expect(actual).toEqual(expected);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
40
116
|
describe('#getPointRect', function () {
|
|
41
117
|
test('should return an rect value calculated based on given position', function () {
|
|
42
118
|
var expected = {
|
package/src/tests/utils.js
CHANGED
|
@@ -10,8 +10,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
10
10
|
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; }
|
|
11
11
|
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; }
|
|
12
12
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
-
function _toPropertyKey(
|
|
14
|
-
function _toPrimitive(
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
14
|
+
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); }
|
|
15
15
|
var join = exports.join = _ramda["default"].unapply(_ramda["default"].join('\n'));
|
|
16
16
|
var testScenario = exports.testScenario = function testScenario(scenario, callback) {
|
|
17
17
|
return function () {
|
|
@@ -65,8 +65,7 @@ var spottable = exports.spottable = function spottable(props) {
|
|
|
65
65
|
}, coerceProps(props)));
|
|
66
66
|
};
|
|
67
67
|
var container = exports.container = function container(props) {
|
|
68
|
-
|
|
69
|
-
return node(_objectSpread((_objectSpread2 = {}, _defineProperty(_objectSpread2, _container.containerAttribute, _id++), _defineProperty(_objectSpread2, 'data-spotlight-container', true), _objectSpread2), coerceProps(props)));
|
|
68
|
+
return node(_objectSpread(_defineProperty(_defineProperty({}, _container.containerAttribute, _id++), 'data-spotlight-container', true), coerceProps(props)));
|
|
70
69
|
};
|
|
71
70
|
|
|
72
71
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
package/src/utils.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.contains = void 0;
|
|
7
7
|
exports.getContainerRect = getContainerRect;
|
|
8
|
+
exports.getIntersectionRect = getIntersectionRect;
|
|
8
9
|
exports.getPointRect = getPointRect;
|
|
9
10
|
exports.getRect = getRect;
|
|
10
11
|
exports.getRects = getRects;
|
|
@@ -73,7 +74,6 @@ var testIntersection = function testIntersection(type, containerRect, elementRec
|
|
|
73
74
|
b > T - epsilon && b < B + epsilon // bottom
|
|
74
75
|
;
|
|
75
76
|
}
|
|
76
|
-
|
|
77
77
|
return true;
|
|
78
78
|
};
|
|
79
79
|
var intersects = exports.intersects = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
@@ -82,6 +82,34 @@ var intersects = exports.intersects = (0, _curry["default"])(function (container
|
|
|
82
82
|
var contains = exports.contains = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
83
83
|
return testIntersection('contains', containerRect, elementRect);
|
|
84
84
|
});
|
|
85
|
+
function getIntersectionRect(container, element) {
|
|
86
|
+
var _container$getBoundin = container.getBoundingClientRect(),
|
|
87
|
+
L = _container$getBoundin.left,
|
|
88
|
+
T = _container$getBoundin.top,
|
|
89
|
+
W = _container$getBoundin.width,
|
|
90
|
+
H = _container$getBoundin.height;
|
|
91
|
+
var _element$getBoundingC = element.getBoundingClientRect(),
|
|
92
|
+
l = _element$getBoundingC.left,
|
|
93
|
+
t = _element$getBoundingC.top,
|
|
94
|
+
w = _element$getBoundingC.width,
|
|
95
|
+
h = _element$getBoundingC.height;
|
|
96
|
+
var intersectionRect = {
|
|
97
|
+
element: element,
|
|
98
|
+
left: Math.max(l, L),
|
|
99
|
+
right: Math.min(l + w, L + W),
|
|
100
|
+
top: Math.max(t, T),
|
|
101
|
+
bottom: Math.min(t + h, T + H)
|
|
102
|
+
};
|
|
103
|
+
intersectionRect.width = intersectionRect.right - intersectionRect.left;
|
|
104
|
+
intersectionRect.height = intersectionRect.bottom - intersectionRect.top;
|
|
105
|
+
intersectionRect.center = {
|
|
106
|
+
x: intersectionRect.left + Math.floor(intersectionRect.width / 2),
|
|
107
|
+
y: intersectionRect.top + Math.floor(intersectionRect.height / 2)
|
|
108
|
+
};
|
|
109
|
+
intersectionRect.center.left = intersectionRect.center.right = intersectionRect.center.x;
|
|
110
|
+
intersectionRect.center.top = intersectionRect.center.bottom = intersectionRect.center.y;
|
|
111
|
+
return intersectionRect;
|
|
112
|
+
}
|
|
85
113
|
function getRect(elem) {
|
|
86
114
|
var cr = elem.getBoundingClientRect();
|
|
87
115
|
var rect = {
|