@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/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(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; }
20
- 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
+ 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(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
23
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
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
- var overlappingContainerId = getContainerContainingRect(elementRects, positionRect);
160
+ var overlappingContainerId = getContainerContainingRect(elementRects, positionRect);
161
161
 
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 "continue";
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
- // found a target so break out and return
175
- return "break";
176
- }
174
+ // found a target so break out and return
175
+ return 1; // break
176
+ }
177
177
 
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));
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
- // if we match a container, recurse into it
182
- if (next && (0, _container.isContainer)(next)) {
183
- var nextContainerId = next.dataset.spotlightId;
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
- // 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 "continue";
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
- // If we've met every condition and haven't explicitly retried the search via `continue`,
198
- // break out and return
199
- return "break";
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
- var _ret = _loop();
203
- if (_ret === "continue") continue;
204
- if (_ret === "break") break;
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
- var overlappingContainerId = getContainerContainingRect(elementRects, elementRect);
231
+ var overlappingContainerId = getContainerContainingRect(elementRects, elementRect);
231
232
 
232
- // if the next element is a container AND the current element is *visually* contained within
233
- // one of the candidate elements, we need to ignore container `enterTo` preferences and
234
- // retrieve its spottable descendants and try to navigate to them.
235
- if (overlappingContainerId) {
236
- next = getTargetInContainerByDirectionFromElement(direction, overlappingContainerId, element, elementRect, elementContainerIds, boundingRect);
237
- if (!next) {
238
- // filter out the container and try again
239
- elementRects = elementRects.filter(function (rect) {
240
- return rect.element.dataset.spotlightId !== overlappingContainerId;
241
- });
242
- return "continue";
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
- // found a target so break out and return
246
- return "break";
247
- }
246
+ // found a target so break out and return
247
+ return 1; // break
248
+ }
248
249
 
249
- // If one of the downstream containers is configured for partition, we use that
250
- // container's bounds as the partition rect for navigation.
251
- var partitionContainer = elementContainerIds.slice(elementContainerIds.indexOf(containerId) + 1).find(function (id) {
252
- var cfg = (0, _container.getContainerConfig)(id);
253
- return cfg && cfg.partition;
254
- });
255
- var partitionRect = elementRect;
256
- if (partitionContainer) {
257
- partitionRect = (0, _utils.getContainerRect)(partitionContainer);
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
- // try to navigate from element to one of the candidates in containerId
261
- next = (0, _navigate["default"])(elementRect, direction, elementRects, (0, _container.getContainerConfig)(containerId), partitionRect);
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
- // if we match a container,
264
- if (next && (0, _container.isContainer)(next)) {
265
- var nextContainerId = next.dataset.spotlightId;
264
+ // if we match a container,
265
+ if (next && (0, _container.isContainer)(next)) {
266
+ var nextContainerId = next.dataset.spotlightId;
266
267
 
267
- // need to cache this reference so we can filter it out later if necessary
268
- var lastNavigated = next;
268
+ // need to cache this reference so we can filter it out later if necessary
269
+ var lastNavigated = next;
269
270
 
270
- // and it is restricted, return its target
271
- if (isRestrictedContainer(nextContainerId)) {
272
- next = getTargetByContainer(nextContainerId);
273
- } else {
274
- // otherwise, recurse into it
275
- next = getTargetInContainerByDirectionFromElement(direction, nextContainerId, element, elementRect, elementContainerIds, getOverflowContainerRect(nextContainerId) || boundingRect);
276
- }
277
- if (!next) {
278
- elementRects = elementRects.filter(function (rect) {
279
- return rect.element !== lastNavigated;
280
- });
281
- return "continue";
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
- // If we've met every condition and haven't explicitly retried the search via `continue`,
286
- // break out and return
287
- return "break";
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
- var _ret2 = _loop2();
291
- if (_ret2 === "continue") continue;
292
- if (_ret2 === "break") break;
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 elementRect = (0, _utils.getRect)(element);
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, elementRect, elementContainerIds);
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
+ };