@enact/spotlight 4.7.8 → 4.7.10
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 +22 -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 +3 -3
- package/src/container.js +46 -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 +117 -100
- 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 +15 -26
- package/src/utils.js +32 -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,80 +228,82 @@ 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
|
}
|
|
296
298
|
function getTargetByDirectionFromElement(direction, element) {
|
|
299
|
+
var _getContainerConfig;
|
|
297
300
|
var extSelector = element.getAttribute('data-spot-' + direction);
|
|
298
301
|
if (typeof extSelector === 'string') {
|
|
299
302
|
return getTargetBySelector(extSelector);
|
|
300
303
|
}
|
|
301
|
-
var
|
|
304
|
+
var elementContainerId = (0, _container.getContainersForNode)(element).pop();
|
|
302
305
|
var next = (0, _container.getNavigableContainersForNode)(element).reduceRight(function (result, containerId, index, elementContainerIds) {
|
|
303
|
-
result = result || getTargetInContainerByDirectionFromElement(direction, containerId, element,
|
|
306
|
+
result = result || getTargetInContainerByDirectionFromElement(direction, containerId, element, (0, _utils.getRect)(element), elementContainerIds);
|
|
304
307
|
if (!result) {
|
|
305
308
|
result = getLeaveForTarget(containerId, direction);
|
|
306
309
|
|
|
@@ -313,6 +316,22 @@ function getTargetByDirectionFromElement(direction, element) {
|
|
|
313
316
|
}
|
|
314
317
|
return result;
|
|
315
318
|
}, null);
|
|
319
|
+
if (next === element && elementContainerId !== _container.rootContainerId && (_getContainerConfig = (0, _container.getContainerConfig)(elementContainerId)) !== null && _getContainerConfig !== void 0 && _getContainerConfig.overflow) {
|
|
320
|
+
next = (0, _container.getNavigableContainersForNode)(element).reduceRight(function (result, containerId, index, elementContainerIds) {
|
|
321
|
+
result = result || getTargetInContainerByDirectionFromElement(direction, containerId, element, (0, _utils.getIntersectionRect)((0, _container.getContainerNode)(elementContainerId), element), elementContainerIds);
|
|
322
|
+
if (!result) {
|
|
323
|
+
result = getLeaveForTarget(containerId, direction);
|
|
324
|
+
|
|
325
|
+
// To support a `leaveFor` configuration with navigation disallowed in the current
|
|
326
|
+
// `direction`, we return the current element to prevent further searches for a
|
|
327
|
+
// target in this reduction.
|
|
328
|
+
if (result === false) {
|
|
329
|
+
result = element;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return result;
|
|
333
|
+
}, null);
|
|
334
|
+
}
|
|
316
335
|
|
|
317
336
|
// if the reduce above returns the original element, it means it hit a `leaveFor` config that
|
|
318
337
|
// prevents navigation so we enforce that here by returning null.
|
|
@@ -360,7 +379,6 @@ function getNavigableTarget(target) {
|
|
|
360
379
|
parent = target.parentNode;
|
|
361
380
|
target = parent === document ? null : parent; // calling isNavigable on document is problematic
|
|
362
381
|
}
|
|
363
|
-
|
|
364
382
|
return target;
|
|
365
383
|
}
|
|
366
384
|
var getOffsetDistanceToTargetFromPosition = function getOffsetDistanceToTargetFromPosition(distance, direction, _ref, _ref2) {
|
|
@@ -425,7 +443,6 @@ var getNearestTargetInContainerFromPosition = function getNearestTargetInContain
|
|
|
425
443
|
});
|
|
426
444
|
return targets[0].target;
|
|
427
445
|
};
|
|
428
|
-
var getNearestTargetFromPosition = function getNearestTargetFromPosition(position, containerId) {
|
|
446
|
+
var getNearestTargetFromPosition = exports.getNearestTargetFromPosition = function getNearestTargetFromPosition(position, containerId) {
|
|
429
447
|
return getNavigableTarget(document.elementFromPoint(position.x, position.y)) || getNearestTargetInContainerFromPosition(position, containerId);
|
|
430
|
-
};
|
|
431
|
-
exports.getNearestTargetFromPosition = getNearestTargetFromPosition;
|
|
448
|
+
};
|