@enact/spotlight 4.7.8 → 4.8.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 +4 -6
- package/CHANGELOG.md +16 -0
- package/Pause/Pause.js +4 -6
- package/Pause/tests/Pause-specs.js +2 -2
- package/README.md +1 -1
- package/SpotlightContainerDecorator/SpotlightContainer.js +6 -8
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +9 -12
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +4 -4
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +4 -4
- package/SpotlightContainerDecorator/useSpotlightContainer.js +2 -2
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +17 -19
- package/SpotlightRootDecorator/tests/SpotlightRootDecorator-specs.js +4 -4
- package/Spottable/Spottable.js +8 -10
- package/Spottable/SpottableCore.js +5 -8
- package/Spottable/tests/Spottable-specs.js +4 -4
- package/Spottable/tests/useSpot-specs.js +6 -6
- package/Spottable/useSpottable.js +6 -8
- package/package.json +5 -4
- package/src/container.js +25 -41
- package/src/inputType.js +6 -11
- package/src/navigate.js +1 -2
- package/src/pointer.js +8 -15
- package/src/spotlight.js +3 -6
- package/src/target.js +98 -98
- package/src/tests/container-specs.js +21 -22
- package/src/tests/spotlight-specs.js +5 -6
- package/src/tests/target-specs.js +14 -16
- package/src/tests/utils.js +15 -26
- package/src/utils.js +3 -7
package/src/target.js
CHANGED
|
@@ -16,11 +16,11 @@ var _container = require("./container");
|
|
|
16
16
|
var _navigate = _interopRequireDefault(require("./navigate"));
|
|
17
17
|
var _utils = require("./utils");
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
|
-
function ownKeys(
|
|
20
|
-
function _objectSpread(
|
|
19
|
+
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; }
|
|
20
|
+
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; }
|
|
21
21
|
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; }
|
|
22
|
-
function _toPropertyKey(
|
|
23
|
-
function _toPrimitive(
|
|
22
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
23
|
+
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); }
|
|
24
24
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
25
25
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
26
26
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -157,51 +157,52 @@ function getTargetInContainerByDirectionFromPosition(direction, containerId, pos
|
|
|
157
157
|
var elementRects = filterRects((0, _utils.getRects)(elements), boundingRect);
|
|
158
158
|
var next = null;
|
|
159
159
|
var _loop = function _loop() {
|
|
160
|
-
|
|
160
|
+
var overlappingContainerId = getContainerContainingRect(elementRects, positionRect);
|
|
161
161
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
162
|
+
// if the pointer is within a container that is a candidate element, we need to ignore container
|
|
163
|
+
// `enterTo` preferences and retrieve its spottable descendants and try to navigate to them.
|
|
164
|
+
if (overlappingContainerId) {
|
|
165
|
+
next = getTargetInContainerByDirectionFromPosition(direction, overlappingContainerId, positionRect, elementContainerIds, boundingRect);
|
|
166
|
+
if (!next) {
|
|
167
|
+
// filter out the container and try again
|
|
168
|
+
elementRects = elementRects.filter(function (rect) {
|
|
169
|
+
return rect.element.dataset.spotlightId !== overlappingContainerId;
|
|
170
|
+
});
|
|
171
|
+
return 0; // continue
|
|
172
|
+
}
|
|
173
173
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
// found a target so break out and return
|
|
175
|
+
return 1; // break
|
|
176
|
+
}
|
|
177
177
|
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
// try to navigate from position to one of the candidates in containerId
|
|
179
|
+
next = (0, _navigate["default"])(positionRect, direction, elementRects, (0, _container.getContainerConfig)(containerId));
|
|
180
180
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
// if we match a container, recurse into it
|
|
182
|
+
if (next && (0, _container.isContainer)(next)) {
|
|
183
|
+
var nextContainerId = next.dataset.spotlightId;
|
|
184
184
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
185
|
+
// need to cache this reference so we can filter it out later if necessary
|
|
186
|
+
var lastNavigated = next;
|
|
187
|
+
next = getTargetInContainerByDirectionFromPosition(direction, nextContainerId, positionRect, elementContainerIds, getOverflowContainerRect(nextContainerId) || boundingRect);
|
|
188
|
+
if (!next) {
|
|
189
|
+
// filter out the container and try again
|
|
190
|
+
elementRects = elementRects.filter(function (rect) {
|
|
191
|
+
return rect.element !== lastNavigated;
|
|
192
|
+
});
|
|
193
|
+
return 0; // continue
|
|
194
|
+
}
|
|
194
195
|
}
|
|
195
|
-
}
|
|
196
196
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
// If we've met every condition and haven't explicitly retried the search via `continue`,
|
|
198
|
+
// break out and return
|
|
199
|
+
return 1; // break
|
|
200
|
+
},
|
|
201
|
+
_ret;
|
|
201
202
|
while (elementRects.length > 0) {
|
|
202
|
-
|
|
203
|
-
if (_ret ===
|
|
204
|
-
if (_ret ===
|
|
203
|
+
_ret = _loop();
|
|
204
|
+
if (_ret === 0) continue;
|
|
205
|
+
if (_ret === 1) break;
|
|
205
206
|
}
|
|
206
207
|
return next;
|
|
207
208
|
}
|
|
@@ -227,69 +228,70 @@ function getTargetInContainerByDirectionFromElement(direction, containerId, elem
|
|
|
227
228
|
var elementRects = filterRects((0, _utils.getRects)(elements), boundingRect);
|
|
228
229
|
var next = null;
|
|
229
230
|
var _loop2 = function _loop2() {
|
|
230
|
-
|
|
231
|
+
var overlappingContainerId = getContainerContainingRect(elementRects, elementRect);
|
|
231
232
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
233
|
+
// if the next element is a container AND the current element is *visually* contained within
|
|
234
|
+
// one of the candidate elements, we need to ignore container `enterTo` preferences and
|
|
235
|
+
// retrieve its spottable descendants and try to navigate to them.
|
|
236
|
+
if (overlappingContainerId) {
|
|
237
|
+
next = getTargetInContainerByDirectionFromElement(direction, overlappingContainerId, element, elementRect, elementContainerIds, boundingRect);
|
|
238
|
+
if (!next) {
|
|
239
|
+
// filter out the container and try again
|
|
240
|
+
elementRects = elementRects.filter(function (rect) {
|
|
241
|
+
return rect.element.dataset.spotlightId !== overlappingContainerId;
|
|
242
|
+
});
|
|
243
|
+
return 0; // continue
|
|
244
|
+
}
|
|
244
245
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
// found a target so break out and return
|
|
247
|
+
return 1; // break
|
|
248
|
+
}
|
|
248
249
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
250
|
+
// If one of the downstream containers is configured for partition, we use that
|
|
251
|
+
// container's bounds as the partition rect for navigation.
|
|
252
|
+
var partitionContainer = elementContainerIds.slice(elementContainerIds.indexOf(containerId) + 1).find(function (id) {
|
|
253
|
+
var cfg = (0, _container.getContainerConfig)(id);
|
|
254
|
+
return cfg && cfg.partition;
|
|
255
|
+
});
|
|
256
|
+
var partitionRect = elementRect;
|
|
257
|
+
if (partitionContainer) {
|
|
258
|
+
partitionRect = (0, _utils.getContainerRect)(partitionContainer);
|
|
259
|
+
}
|
|
259
260
|
|
|
260
|
-
|
|
261
|
-
|
|
261
|
+
// try to navigate from element to one of the candidates in containerId
|
|
262
|
+
next = (0, _navigate["default"])(elementRect, direction, elementRects, (0, _container.getContainerConfig)(containerId), partitionRect);
|
|
262
263
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
264
|
+
// if we match a container,
|
|
265
|
+
if (next && (0, _container.isContainer)(next)) {
|
|
266
|
+
var nextContainerId = next.dataset.spotlightId;
|
|
266
267
|
|
|
267
|
-
|
|
268
|
-
|
|
268
|
+
// need to cache this reference so we can filter it out later if necessary
|
|
269
|
+
var lastNavigated = next;
|
|
269
270
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
271
|
+
// and it is restricted, return its target
|
|
272
|
+
if (isRestrictedContainer(nextContainerId)) {
|
|
273
|
+
next = getTargetByContainer(nextContainerId);
|
|
274
|
+
} else {
|
|
275
|
+
// otherwise, recurse into it
|
|
276
|
+
next = getTargetInContainerByDirectionFromElement(direction, nextContainerId, element, elementRect, elementContainerIds, getOverflowContainerRect(nextContainerId) || boundingRect);
|
|
277
|
+
}
|
|
278
|
+
if (!next) {
|
|
279
|
+
elementRects = elementRects.filter(function (rect) {
|
|
280
|
+
return rect.element !== lastNavigated;
|
|
281
|
+
});
|
|
282
|
+
return 0; // continue
|
|
283
|
+
}
|
|
282
284
|
}
|
|
283
|
-
}
|
|
284
285
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
// If we've met every condition and haven't explicitly retried the search via `continue`,
|
|
287
|
+
// break out and return
|
|
288
|
+
return 1; // break
|
|
289
|
+
},
|
|
290
|
+
_ret2;
|
|
289
291
|
while (elementRects.length > 0) {
|
|
290
|
-
|
|
291
|
-
if (_ret2 ===
|
|
292
|
-
if (_ret2 ===
|
|
292
|
+
_ret2 = _loop2();
|
|
293
|
+
if (_ret2 === 0) continue;
|
|
294
|
+
if (_ret2 === 1) break;
|
|
293
295
|
}
|
|
294
296
|
return next;
|
|
295
297
|
}
|
|
@@ -360,7 +362,6 @@ function getNavigableTarget(target) {
|
|
|
360
362
|
parent = target.parentNode;
|
|
361
363
|
target = parent === document ? null : parent; // calling isNavigable on document is problematic
|
|
362
364
|
}
|
|
363
|
-
|
|
364
365
|
return target;
|
|
365
366
|
}
|
|
366
367
|
var getOffsetDistanceToTargetFromPosition = function getOffsetDistanceToTargetFromPosition(distance, direction, _ref, _ref2) {
|
|
@@ -425,7 +426,6 @@ var getNearestTargetInContainerFromPosition = function getNearestTargetInContain
|
|
|
425
426
|
});
|
|
426
427
|
return targets[0].target;
|
|
427
428
|
};
|
|
428
|
-
var getNearestTargetFromPosition = function getNearestTargetFromPosition(position, containerId) {
|
|
429
|
+
var getNearestTargetFromPosition = exports.getNearestTargetFromPosition = function getNearestTargetFromPosition(position, containerId) {
|
|
429
430
|
return getNavigableTarget(document.elementFromPoint(position.x, position.y)) || getNearestTargetInContainerFromPosition(position, containerId);
|
|
430
|
-
};
|
|
431
|
-
exports.getNearestTargetFromPosition = getNearestTargetFromPosition;
|
|
431
|
+
};
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var _container17 = require("../container");
|
|
4
4
|
var _utils = require("./utils");
|
|
5
|
-
var _node, _container, _container2, _container3, _container4, _container5, _container6, _container7, _container8, _container9, _container10, _container11, _container12, _container13, _container15, _container16;
|
|
6
5
|
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; }
|
|
7
|
-
function _toPropertyKey(
|
|
8
|
-
function _toPrimitive(
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
7
|
+
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); }
|
|
9
8
|
var nonSpottable = function nonSpottable() {
|
|
10
9
|
return (0, _utils.node)({
|
|
11
10
|
className: 'other'
|
|
@@ -17,50 +16,50 @@ var scenarios = {
|
|
|
17
16
|
spottableAndContainers: (0, _utils.someSpottablesAndContainers)(5),
|
|
18
17
|
nonSpottableSiblings: (0, _utils.join)((0, _utils.someSpottables)(5), (0, _utils.someNodes)(nonSpottable, 5)),
|
|
19
18
|
nestedContainers: (0, _utils.container)((0, _utils.container)((0, _utils.container)())),
|
|
20
|
-
disabledContainers: (0, _utils.join)((0, _utils.someSpottables)(5), (0, _utils.someContainers)(5), (0, _utils.node)((
|
|
19
|
+
disabledContainers: (0, _utils.join)((0, _utils.someSpottables)(5), (0, _utils.someContainers)(5), (0, _utils.node)(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'disabled-container'), 'data-spotlight-container-disabled', true))),
|
|
21
20
|
nestedContainersWithSpottables: (0, _utils.join)((0, _utils.someSpottables)(5), (0, _utils.container)({
|
|
22
21
|
children: (0, _utils.someSpottables)(5)
|
|
23
22
|
})),
|
|
24
|
-
siblingContainers: (0, _utils.join)((0, _utils.container)((
|
|
25
|
-
mixedOrder: (0, _utils.join)((0, _utils.container)((
|
|
23
|
+
siblingContainers: (0, _utils.join)((0, _utils.container)(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'first'), "children", (0, _utils.someSpottables)(5))), (0, _utils.container)(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'second'), "children", (0, _utils.someSpottables)(5)))),
|
|
24
|
+
mixedOrder: (0, _utils.join)((0, _utils.container)(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'first'), "name", 'c1')), (0, _utils.spottable)({
|
|
26
25
|
name: 's1'
|
|
27
|
-
}), (0, _utils.container)((
|
|
26
|
+
}), (0, _utils.container)(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'second'), "name", 'c2')), (0, _utils.spottable)({
|
|
28
27
|
name: 's2'
|
|
29
28
|
})),
|
|
30
|
-
complexTree: (0, _utils.join)((0, _utils.spottable)(nonSpottable()), (0, _utils.container)((
|
|
29
|
+
complexTree: (0, _utils.join)((0, _utils.spottable)(nonSpottable()), (0, _utils.container)(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'first-container'), "children", (0, _utils.join)((0, _utils.someSpottables)(2), (0, _utils.container)(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'second-container'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
31
30
|
id: 'secondContainerFirstSpottable'
|
|
32
|
-
}), (0, _utils.someSpottables)(2), (0, _utils.container)((
|
|
31
|
+
}), (0, _utils.someSpottables)(2), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'third-container'), 'data-spotlight-container-disabled', true), "children", (0, _utils.join)((0, _utils.someSpottables)(4), (0, _utils.node)({
|
|
33
32
|
id: 'child-of-third'
|
|
34
|
-
})))
|
|
35
|
-
spottablesInDisabledContainer: (0, _utils.container)((
|
|
36
|
-
spottablesInNestedDisabledContainer: (0, _utils.container)((
|
|
37
|
-
containerWithDefaultAndLastFocused: (0, _utils.container)((
|
|
33
|
+
}))))))))))),
|
|
34
|
+
spottablesInDisabledContainer: (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'container'), 'data-spotlight-container-disabled', true), "children", (0, _utils.someSpottables)(5))),
|
|
35
|
+
spottablesInNestedDisabledContainer: (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'container'), 'data-spotlight-container-disabled', true), "children", (0, _utils.container)(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'child'), "children", (0, _utils.someSpottables)(5))))),
|
|
36
|
+
containerWithDefaultAndLastFocused: (0, _utils.container)(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'container'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
38
37
|
id: 'firstSpottable'
|
|
39
38
|
}), (0, _utils.someSpottables)(5), (0, _utils.node)({
|
|
40
39
|
id: 'spottableDefault',
|
|
41
40
|
className: 'spottable spottable-default'
|
|
42
41
|
}), (0, _utils.spottable)({
|
|
43
42
|
id: 'lastFocused'
|
|
44
|
-
})))
|
|
45
|
-
nestedContainersWithDefaultAndLastFocused: (0, _utils.container)((
|
|
43
|
+
})))),
|
|
44
|
+
nestedContainersWithDefaultAndLastFocused: (0, _utils.container)(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'container'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
46
45
|
id: 'firstSpottable'
|
|
47
|
-
}), (0, _utils.someSpottables)(5), (0, _utils.container)((
|
|
46
|
+
}), (0, _utils.someSpottables)(5), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'child'), "id", 'spottableDefault'), "className", 'spottable-default'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
48
47
|
id: 'firstChildSpottable'
|
|
49
48
|
}), (0, _utils.someSpottables)(5), (0, _utils.spottable)({
|
|
50
49
|
id: 'lastChildFocused'
|
|
51
|
-
})))
|
|
50
|
+
})))), (0, _utils.spottable)({
|
|
52
51
|
id: 'lastFocused'
|
|
53
|
-
})))
|
|
54
|
-
emptySubcontainer: (0, _utils.container)((
|
|
52
|
+
})))),
|
|
53
|
+
emptySubcontainer: (0, _utils.container)(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'container'), "children", (0, _utils.join)((0, _utils.container)(_defineProperty({}, _container17.containerAttribute, 'subcontainer')), (0, _utils.spottable)({
|
|
55
54
|
id: 'afterSubcontainer'
|
|
56
|
-
})))
|
|
55
|
+
})))),
|
|
57
56
|
owned: (0, _utils.join)((0, _utils.spottable)({
|
|
58
57
|
id: 's1'
|
|
59
58
|
}), (0, _utils.node)({
|
|
60
59
|
id: 'n1'
|
|
61
|
-
}), (0, _utils.container)((
|
|
60
|
+
}), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container17.containerAttribute, 'container'), 'aria-owns', 's1 n1'), "children", (0, _utils.spottable)({
|
|
62
61
|
id: 's2'
|
|
63
|
-
}))
|
|
62
|
+
}))))
|
|
64
63
|
};
|
|
65
64
|
var setupContainers = function setupContainers() {
|
|
66
65
|
(0, _container17.configureDefaults)({
|
|
@@ -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.js
CHANGED
|
@@ -7,14 +7,13 @@ exports.testScenario = exports.spottable = exports.someSpottablesAndContainers =
|
|
|
7
7
|
var _ramda = _interopRequireDefault(require("ramda"));
|
|
8
8
|
var _container = require("../container");
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
-
function ownKeys(
|
|
11
|
-
function _objectSpread(
|
|
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
|
+
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(
|
|
15
|
-
var join = _ramda["default"].unapply(_ramda["default"].join('\n'));
|
|
16
|
-
exports.
|
|
17
|
-
var testScenario = function testScenario(scenario, callback) {
|
|
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
|
+
var join = exports.join = _ramda["default"].unapply(_ramda["default"].join('\n'));
|
|
16
|
+
var testScenario = exports.testScenario = function testScenario(scenario, callback) {
|
|
18
17
|
return function () {
|
|
19
18
|
var rootId = 'test-root';
|
|
20
19
|
var html = join("<div id=\"".concat(rootId, "\">"), scenario, '</div>');
|
|
@@ -28,12 +27,10 @@ var testScenario = function testScenario(scenario, callback) {
|
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
29
|
};
|
|
31
|
-
exports.testScenario = testScenario;
|
|
32
30
|
var _id = 1;
|
|
33
|
-
var generateContainerId = function generateContainerId() {
|
|
31
|
+
var generateContainerId = exports.generateContainerId = function generateContainerId() {
|
|
34
32
|
return "".concat(_container.containerAttribute, "=").concat(_id++);
|
|
35
33
|
};
|
|
36
|
-
exports.generateContainerId = generateContainerId;
|
|
37
34
|
var coerceProps = function coerceProps(v) {
|
|
38
35
|
if (typeof v === 'object') {
|
|
39
36
|
return v;
|
|
@@ -43,7 +40,7 @@ var coerceProps = function coerceProps(v) {
|
|
|
43
40
|
};
|
|
44
41
|
}
|
|
45
42
|
};
|
|
46
|
-
var node = function node(props) {
|
|
43
|
+
var node = exports.node = function node(props) {
|
|
47
44
|
var children = '';
|
|
48
45
|
var attributes = '';
|
|
49
46
|
var tag = 'div';
|
|
@@ -62,25 +59,17 @@ var node = function node(props) {
|
|
|
62
59
|
});
|
|
63
60
|
return "<".concat(tag, " ").concat(attributes, ">").concat(children, "</").concat(tag, ">");
|
|
64
61
|
};
|
|
65
|
-
exports.
|
|
66
|
-
var spottable = function spottable(props) {
|
|
62
|
+
var spottable = exports.spottable = function spottable(props) {
|
|
67
63
|
return node(_objectSpread({
|
|
68
64
|
className: 'spottable'
|
|
69
65
|
}, coerceProps(props)));
|
|
70
66
|
};
|
|
71
|
-
exports.
|
|
72
|
-
|
|
73
|
-
var _objectSpread2;
|
|
74
|
-
return node(_objectSpread((_objectSpread2 = {}, _defineProperty(_objectSpread2, _container.containerAttribute, _id++), _defineProperty(_objectSpread2, 'data-spotlight-container', true), _objectSpread2), coerceProps(props)));
|
|
67
|
+
var container = exports.container = function container(props) {
|
|
68
|
+
return node(_objectSpread(_defineProperty(_defineProperty({}, _container.containerAttribute, _id++), 'data-spotlight-container', true), coerceProps(props)));
|
|
75
69
|
};
|
|
76
70
|
|
|
77
71
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
78
|
-
exports.
|
|
79
|
-
var
|
|
80
|
-
exports.
|
|
81
|
-
var
|
|
82
|
-
exports.someSpottables = someSpottables;
|
|
83
|
-
var someContainers = someNodes(container);
|
|
84
|
-
exports.someContainers = someContainers;
|
|
85
|
-
var someSpottablesAndContainers = _ramda["default"].converge(_ramda["default"].concat, [someSpottables, someContainers]);
|
|
86
|
-
exports.someSpottablesAndContainers = someSpottablesAndContainers;
|
|
72
|
+
var someNodes = exports.someNodes = _ramda["default"].useWith(_ramda["default"].compose(_ramda["default"].join('\n'), _ramda["default"].map), [_ramda["default"].identity, _ramda["default"].range(0)]);
|
|
73
|
+
var someSpottables = exports.someSpottables = someNodes(spottable);
|
|
74
|
+
var someContainers = exports.someContainers = someNodes(container);
|
|
75
|
+
var someSpottablesAndContainers = exports.someSpottablesAndContainers = _ramda["default"].converge(_ramda["default"].concat, [someSpottables, someContainers]);
|
package/src/utils.js
CHANGED
|
@@ -23,7 +23,7 @@ var elementMatchesSelector = function elementMatchesSelector(selector) {
|
|
|
23
23
|
if (typeof window === 'object') {
|
|
24
24
|
elementMatchesSelector = window.Element.prototype.matches || window.Element.prototype.matchesSelector || window.Element.prototype.mozMatchesSelector || window.Element.prototype.webkitMatchesSelector || window.Element.prototype.msMatchesSelector || window.Element.prototype.oMatchesSelector || elementMatchesSelector;
|
|
25
25
|
}
|
|
26
|
-
var matchSelector = (0, _curry["default"])(function (selector, elem) {
|
|
26
|
+
var matchSelector = exports.matchSelector = (0, _curry["default"])(function (selector, elem) {
|
|
27
27
|
if (typeof selector === 'string') {
|
|
28
28
|
return elementMatchesSelector.call(elem, selector);
|
|
29
29
|
} else if (typeof selector === 'object' && selector.length) {
|
|
@@ -33,7 +33,6 @@ var matchSelector = (0, _curry["default"])(function (selector, elem) {
|
|
|
33
33
|
}
|
|
34
34
|
return false;
|
|
35
35
|
});
|
|
36
|
-
exports.matchSelector = matchSelector;
|
|
37
36
|
function parseSelector(selector) {
|
|
38
37
|
var result = [];
|
|
39
38
|
try {
|
|
@@ -74,17 +73,14 @@ var testIntersection = function testIntersection(type, containerRect, elementRec
|
|
|
74
73
|
b > T - epsilon && b < B + epsilon // bottom
|
|
75
74
|
;
|
|
76
75
|
}
|
|
77
|
-
|
|
78
76
|
return true;
|
|
79
77
|
};
|
|
80
|
-
var intersects = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
78
|
+
var intersects = exports.intersects = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
81
79
|
return testIntersection('intersects', containerRect, elementRect);
|
|
82
80
|
});
|
|
83
|
-
exports.
|
|
84
|
-
var contains = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
81
|
+
var contains = exports.contains = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
85
82
|
return testIntersection('contains', containerRect, elementRect);
|
|
86
83
|
});
|
|
87
|
-
exports.contains = contains;
|
|
88
84
|
function getRect(elem) {
|
|
89
85
|
var cr = elem.getBoundingClientRect();
|
|
90
86
|
var rect = {
|