@enact/spotlight 4.6.1 → 4.6.2
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.d.ts +31 -0
- package/Accelerator/Accelerator.js +3 -1
- package/CHANGELOG.md +4 -0
- package/Pause/Pause.d.ts +33 -0
- package/Pause/Pause.js +3 -1
- package/README.md +1 -1
- package/SpotlightContainerDecorator/SpotlightContainer.js +4 -2
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.d.ts +89 -0
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +4 -2
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +3 -1
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +3 -1
- package/SpotlightRootDecorator/SpotlightRootDecorator.d.ts +22 -0
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +4 -2
- package/SpotlightRootDecorator/tests/SpotlightRootDecorator-specs.js +3 -1
- package/Spottable/Spottable.d.ts +75 -0
- package/Spottable/Spottable.js +4 -2
- package/Spottable/SpottableCore.js +3 -1
- package/Spottable/tests/Spottable-specs.js +3 -1
- package/Spottable/tests/useSpot-specs.js +4 -2
- package/Spottable/useSpottable.js +3 -1
- package/package.json +2 -2
- package/src/container.js +9 -4
- package/src/navigate.js +24 -23
- package/src/spotlight.d.ts +122 -0
- package/src/spotlight.js +16 -0
- package/src/target.js +4 -2
- package/src/tests/container-specs.js +3 -1
- package/src/tests/navigate-specs.js +1 -1
- package/src/tests/spotlight-specs.js +3 -1
- package/src/tests/target-specs.js +3 -1
- package/src/tests/utils.js +3 -1
- package/src/utils.js +36 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Type definitions for spotlight/Accelerator
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
export declare class Accelerator {
|
|
7
|
+
constructor /**
|
|
8
|
+
* Controls the frequency with which the acceleration will
|
|
9
|
+
"freeze". While frozen, the current target item cannot change, and all events are directed
|
|
10
|
+
to it.
|
|
11
|
+
*/(frequency: number[]);
|
|
12
|
+
/**
|
|
13
|
+
* Called with the current keydown event and callback, which will be called when the event is
|
|
14
|
+
allowed through.
|
|
15
|
+
*/
|
|
16
|
+
processKey(event: object, callback: Function): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Resets the Accelerator instance to the default values.
|
|
19
|
+
*/
|
|
20
|
+
reset(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Cancels the Accelerator.
|
|
23
|
+
*/
|
|
24
|
+
cancel(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Verifies that the Accelerator is active.
|
|
27
|
+
*/
|
|
28
|
+
isAccelerating(): boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default Accelerator;
|
|
@@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = exports.Accelerator = void 0;
|
|
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); } }
|
|
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
8
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; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
|
+
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); }
|
|
9
11
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
12
|
/**
|
|
11
13
|
* Provides the {@link spotlight/Accelerator.Accelerator} class.
|
package/CHANGELOG.md
CHANGED
package/Pause/Pause.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Type definitions for spotlight/Pause
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Acts as a semaphore for Spotlight pause state ensuring that only the last Pause instance can
|
|
8
|
+
resume Spotlight.
|
|
9
|
+
*
|
|
10
|
+
* _Note_ will always resume spotlight regardless of what last
|
|
11
|
+
paused spotlight and can be used as an escape hatch to force resumption.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export declare class Pause {
|
|
15
|
+
constructor
|
|
16
|
+
/**
|
|
17
|
+
* The name of the pause instance
|
|
18
|
+
*/(name: string);
|
|
19
|
+
/**
|
|
20
|
+
* Returns `true` when Spotlight is paused by this instance
|
|
21
|
+
*/
|
|
22
|
+
isPaused(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Pauses spotlight if not currently paused
|
|
25
|
+
*/
|
|
26
|
+
pause(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Resumes spotlight if this instance was the last to pause spotlight
|
|
29
|
+
*/
|
|
30
|
+
resume(): boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default Pause;
|
package/Pause/Pause.js
CHANGED
|
@@ -8,8 +8,10 @@ exports.isPaused = isPaused;
|
|
|
8
8
|
exports.pause = pause;
|
|
9
9
|
exports.resume = _resume;
|
|
10
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
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); } }
|
|
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
12
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; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
14
|
+
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); }
|
|
13
15
|
/**
|
|
14
16
|
* Provides a class which allows consumers to safely pause and resume spotlight without resuming
|
|
15
17
|
* another consumer's pause.
|
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ Spotlight is based on a fork of [JavaScript SpatialNavigation](https://github.co
|
|
|
43
43
|
Unless otherwise specified, all content, including all source code files and
|
|
44
44
|
documentation files in this repository are:
|
|
45
45
|
|
|
46
|
-
Copyright (c) 2012-
|
|
46
|
+
Copyright (c) 2012-2023 LG Electronics
|
|
47
47
|
|
|
48
48
|
Unless otherwise specified or set forth in the NOTICE file, all content,
|
|
49
49
|
including all source code files and documentation files in this repository are:
|
|
@@ -10,10 +10,12 @@ var _spotlight = _interopRequireDefault(require("../src/spotlight"));
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
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; }
|
|
12
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; }
|
|
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; }
|
|
13
|
+
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; }
|
|
14
14
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
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); } }
|
|
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
16
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; }
|
|
17
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
18
|
+
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); }
|
|
17
19
|
var isNewPointerPosition = function isNewPointerPosition(ev) {
|
|
18
20
|
return (0, _pointer.hasPointerMoved)(ev.clientX, ev.clientY);
|
|
19
21
|
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Type definitions for spotlight/SpotlightContainerDecorator
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The class name to apply to the default component to focus in a container.
|
|
8
|
+
*/
|
|
9
|
+
export declare const spotlightDefaultClass: string;
|
|
10
|
+
export interface SpotlightContainerDecoratorConfig extends Object {
|
|
11
|
+
/**
|
|
12
|
+
* When `true` , allows focus to move outside the container to the next spottable element when
|
|
13
|
+
holding 5 way keys.
|
|
14
|
+
*/
|
|
15
|
+
continue5WayHold?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The selector for the default spottable element within the container.
|
|
18
|
+
When an array of selectors is provided, the first selector that successfully matches a
|
|
19
|
+
node is used.
|
|
20
|
+
*/
|
|
21
|
+
defaultElement?: string | string[];
|
|
22
|
+
/**
|
|
23
|
+
* Directs which element receives focus when gaining focus from another container. If
|
|
24
|
+
`'default-element'` , the default focused item will be selected. If `'last-focused'` , the
|
|
25
|
+
container will focus the last focused item; if the container has never had focus, the default
|
|
26
|
+
element will receive focus. If `null` , the default 5-way behavior will be applied.
|
|
27
|
+
*/
|
|
28
|
+
enterTo?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Filter the navigable elements.
|
|
31
|
+
*/
|
|
32
|
+
navigableFilter?: Function;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the container will preserve the specified `spotlightId` when it unmounts.
|
|
35
|
+
*/
|
|
36
|
+
preserveId?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Restricts or prioritizes navigation when focus attempts to leave the container. It
|
|
39
|
+
can be either 'none', 'self-first', or 'self-only'. Specifying 'self-first' indicates that
|
|
40
|
+
elements within the container will have a higher likelihood to be chosen as the next
|
|
41
|
+
navigable element. Specifying 'self-only' indicates that elements in other containers
|
|
42
|
+
cannot be navigated to by using 5-way navigation - however, elements in other containers
|
|
43
|
+
can still receive focus by calling `Spotlight.focus(elem)` explicitly. Specifying 'none'
|
|
44
|
+
indicates there should be no restrictions when 5-way navigating the container.
|
|
45
|
+
*/
|
|
46
|
+
restrict?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface SpotlightContainerDecoratorProps {
|
|
49
|
+
/**
|
|
50
|
+
* When `true` , controls in the container cannot be navigated.
|
|
51
|
+
*/
|
|
52
|
+
spotlightDisabled?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Used to identify this component within the Spotlight system.
|
|
55
|
+
*
|
|
56
|
+
* If the value is `null` , an id will be generated.
|
|
57
|
+
To keep the container information for restoring focus, it is required to specify
|
|
58
|
+
a unique identifier.
|
|
59
|
+
*/
|
|
60
|
+
spotlightId?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Whether or not the container is in muted mode.
|
|
63
|
+
*
|
|
64
|
+
* In muted mode, `:focus` CSS styles will not be applied to the
|
|
65
|
+
Spottable controls giving them the appearance of not having focus
|
|
66
|
+
while they still have focus.
|
|
67
|
+
*/
|
|
68
|
+
spotlightMuted?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Restricts or prioritizes navigation when focus attempts to leave the container. It
|
|
71
|
+
can be either 'none', 'self-first', or 'self-only'. Specifying 'self-first' indicates that
|
|
72
|
+
elements within the container will have a higher likelihood to be chosen as the next
|
|
73
|
+
navigable element. Specifying 'self-only' indicates that elements in other containers
|
|
74
|
+
cannot be navigated to by using 5-way navigation - however, elements in other containers
|
|
75
|
+
can still receive focus by calling `Spotlight.focus(elem)` explicitly. Specifying 'none'
|
|
76
|
+
indicates there should be no restrictions when 5-way navigating the container.
|
|
77
|
+
*/
|
|
78
|
+
spotlightRestrict?: string;
|
|
79
|
+
}
|
|
80
|
+
export function SpotlightContainerDecorator<P>(
|
|
81
|
+
config: SpotlightContainerDecoratorConfig,
|
|
82
|
+
Component: React.ComponentType<P> | string
|
|
83
|
+
): React.ComponentType<P & SpotlightContainerDecoratorProps>;
|
|
84
|
+
|
|
85
|
+
export function SpotlightContainerDecorator<P>(
|
|
86
|
+
Component: React.ComponentType<P> | string
|
|
87
|
+
): React.ComponentType<P & SpotlightContainerDecoratorProps>;
|
|
88
|
+
|
|
89
|
+
export default SpotlightContainerDecorator;
|
|
@@ -23,7 +23,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
23
23
|
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); }
|
|
24
24
|
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; }
|
|
25
25
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
26
|
-
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); } }
|
|
26
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
27
27
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
28
28
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
29
29
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
@@ -34,7 +34,9 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
34
34
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
35
35
|
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; }
|
|
36
36
|
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; }
|
|
37
|
-
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; }
|
|
37
|
+
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; }
|
|
38
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
39
|
+
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); }
|
|
38
40
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
39
41
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
40
42
|
var callContext = function callContext(name) {
|
|
@@ -11,7 +11,9 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
12
|
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; }
|
|
13
13
|
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; }
|
|
14
|
-
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; }
|
|
14
|
+
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; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
|
+
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); }
|
|
15
17
|
var testId = 'test-spotlightContainerDecorator';
|
|
16
18
|
describe('SpotlightContainerDecorator', function () {
|
|
17
19
|
var hoverPosition = {
|
|
@@ -10,7 +10,9 @@ var _excluded = ["containerConfig", "preserveId", "spotlightDisabled", "spotligh
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
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; }
|
|
12
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; }
|
|
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; }
|
|
13
|
+
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; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
15
|
+
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); }
|
|
14
16
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
15
17
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
18
|
function containerExists(id) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Type definitions for spotlight/SpotlightRootDecorator
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
export interface SpotlightRootDecoratorConfig extends Object {
|
|
7
|
+
/**
|
|
8
|
+
* When `true` , the contents of the component will not receive spotlight focus after being rendered.
|
|
9
|
+
*/
|
|
10
|
+
noAutoFocus?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface SpotlightRootDecoratorProps {}
|
|
13
|
+
export function SpotlightRootDecorator<P>(
|
|
14
|
+
config: SpotlightRootDecoratorConfig,
|
|
15
|
+
Component: React.ComponentType<P> | string
|
|
16
|
+
): React.ComponentType<P & SpotlightRootDecoratorProps>;
|
|
17
|
+
|
|
18
|
+
export function SpotlightRootDecorator<P>(
|
|
19
|
+
Component: React.ComponentType<P> | string
|
|
20
|
+
): React.ComponentType<P & SpotlightRootDecoratorProps>;
|
|
21
|
+
|
|
22
|
+
export default SpotlightRootDecorator;
|
|
@@ -15,10 +15,12 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
16
16
|
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
17
|
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; }
|
|
18
|
-
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; }
|
|
18
|
+
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; }
|
|
19
19
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
-
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); } }
|
|
20
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
21
21
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
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
24
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
23
25
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
24
26
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
@@ -6,7 +6,9 @@ var _SpotlightRootDecorator = require("../SpotlightRootDecorator");
|
|
|
6
6
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
7
|
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; }
|
|
8
8
|
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; }
|
|
9
|
-
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; }
|
|
9
|
+
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; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
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); }
|
|
10
12
|
describe('SpotlightRootDecorator', function () {
|
|
11
13
|
var AppBase = function AppBase(props) {
|
|
12
14
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Type definitions for spotlight/Spottable
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The class name for spottable components. In general, you do not need to directly access this class
|
|
8
|
+
*/
|
|
9
|
+
export declare const spottableClass: string;
|
|
10
|
+
export interface SpottableConfig extends Object {
|
|
11
|
+
/**
|
|
12
|
+
* Whether or not the component should emulate mouse events as a response
|
|
13
|
+
to Spotlight 5-way events.
|
|
14
|
+
*/
|
|
15
|
+
emulateMouse?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface SpottableProps {
|
|
18
|
+
/**
|
|
19
|
+
* Whether or not the component is in a disabled state.
|
|
20
|
+
*/
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The handler to force update the component.
|
|
24
|
+
*/
|
|
25
|
+
handleForceUpdate?: Function;
|
|
26
|
+
/**
|
|
27
|
+
* The handler to run when the component is removed while retaining focus.
|
|
28
|
+
*/
|
|
29
|
+
onSpotlightDisappear?: Function;
|
|
30
|
+
/**
|
|
31
|
+
* The handler to run when the 5-way down key is pressed.
|
|
32
|
+
*/
|
|
33
|
+
onSpotlightDown?: Function;
|
|
34
|
+
/**
|
|
35
|
+
* The handler to run when the 5-way left key is pressed.
|
|
36
|
+
*/
|
|
37
|
+
onSpotlightLeft?: Function;
|
|
38
|
+
/**
|
|
39
|
+
* The handler to run when the 5-way right key is pressed.
|
|
40
|
+
*/
|
|
41
|
+
onSpotlightRight?: Function;
|
|
42
|
+
/**
|
|
43
|
+
* The handler to run when the 5-way up key is pressed.
|
|
44
|
+
*/
|
|
45
|
+
onSpotlightUp?: Function;
|
|
46
|
+
/**
|
|
47
|
+
* An array of numbers representing keyCodes that should trigger mouse event
|
|
48
|
+
emulation when `emulateMouse` is `true` . If a keyCode equals a directional
|
|
49
|
+
key, then default 5-way navigation will be prevented when that key is pressed.
|
|
50
|
+
*/
|
|
51
|
+
selectionKeys?: number[];
|
|
52
|
+
/**
|
|
53
|
+
* When `true` , the component cannot be navigated using spotlight.
|
|
54
|
+
*/
|
|
55
|
+
spotlightDisabled?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Used to identify this component within the Spotlight system
|
|
58
|
+
*/
|
|
59
|
+
spotlightId?: string;
|
|
60
|
+
/**
|
|
61
|
+
* The tabIndex of the component. This value will default to -1 if left
|
|
62
|
+
unset and the control is spottable.
|
|
63
|
+
*/
|
|
64
|
+
tabIndex?: number;
|
|
65
|
+
}
|
|
66
|
+
export function Spottable<P>(
|
|
67
|
+
config: SpottableConfig,
|
|
68
|
+
Component: React.ComponentType<P> | string
|
|
69
|
+
): React.ComponentType<P & SpottableProps>;
|
|
70
|
+
|
|
71
|
+
export function Spottable<P>(
|
|
72
|
+
Component: React.ComponentType<P> | string
|
|
73
|
+
): React.ComponentType<P & SpottableProps>;
|
|
74
|
+
|
|
75
|
+
export default Spottable;
|
package/Spottable/Spottable.js
CHANGED
|
@@ -31,7 +31,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
31
31
|
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); }
|
|
32
32
|
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; }
|
|
33
33
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
34
|
-
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); } }
|
|
34
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
35
35
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
36
36
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
37
37
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
@@ -42,7 +42,9 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
42
42
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
43
43
|
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; }
|
|
44
44
|
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; }
|
|
45
|
-
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; }
|
|
45
|
+
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; }
|
|
46
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
47
|
+
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); }
|
|
46
48
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
47
49
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
48
50
|
var forwardMouseDown = (0, _handle.forward)('onMouseDown'),
|
|
@@ -9,8 +9,10 @@ var _keymap = require("@enact/core/keymap");
|
|
|
9
9
|
var _container = require("../src/container");
|
|
10
10
|
var _spotlight = require("../src/spotlight");
|
|
11
11
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
-
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); } }
|
|
12
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
13
13
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
15
|
+
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); }
|
|
14
16
|
var REMOTE_OK_KEY = 16777221;
|
|
15
17
|
|
|
16
18
|
/**
|
|
@@ -7,7 +7,9 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
7
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
8
|
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; }
|
|
9
9
|
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; }
|
|
10
|
-
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; }
|
|
10
|
+
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; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
|
+
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); }
|
|
11
13
|
var id = 'test-spottable';
|
|
12
14
|
describe('Spottable', function () {
|
|
13
15
|
test('should add the spottable class', function () {
|
|
@@ -15,7 +15,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
15
15
|
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); }
|
|
16
16
|
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; }
|
|
17
17
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
18
|
-
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); } }
|
|
18
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
19
19
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
20
20
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
21
21
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
@@ -26,7 +26,9 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
26
26
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
27
27
|
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; }
|
|
28
28
|
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; }
|
|
29
|
-
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; }
|
|
29
|
+
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; }
|
|
30
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
31
|
+
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); }
|
|
30
32
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
31
33
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
32
34
|
var forwardMouseUp = (0, _handle.forward)('onMouseUp'),
|
|
@@ -18,7 +18,9 @@ var _excluded = ["spotRef", "emulateMouse", "selectionKeys", "spotlightDisabled"
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
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
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; }
|
|
21
|
-
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
|
+
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
24
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
23
25
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
24
26
|
var ENTER_KEY = 13;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/spotlight",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.2",
|
|
4
4
|
"description": "A focus management library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@enact/core": "^4.6.
|
|
27
|
+
"@enact/core": "^4.6.2",
|
|
28
28
|
"classnames": "^2.3.2",
|
|
29
29
|
"prop-types": "^15.8.1",
|
|
30
30
|
"ramda": "^0.28.0",
|
package/src/container.js
CHANGED
|
@@ -39,13 +39,15 @@ var _utils = require("./utils");
|
|
|
39
39
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
40
40
|
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; }
|
|
41
41
|
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; }
|
|
42
|
-
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; }
|
|
42
|
+
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; }
|
|
43
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
44
|
+
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); }
|
|
43
45
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
44
46
|
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."); }
|
|
45
47
|
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); }
|
|
46
48
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
47
49
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
48
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
50
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
49
51
|
var containerAttribute = 'data-spotlight-id';
|
|
50
52
|
exports.containerAttribute = containerAttribute;
|
|
51
53
|
var containerConfigs = new Map();
|
|
@@ -81,6 +83,8 @@ var GlobalConfig = {
|
|
|
81
83
|
// <extSelector> except "@" syntax.
|
|
82
84
|
enterTo: '',
|
|
83
85
|
// '', 'last-focused', 'default-element'
|
|
86
|
+
isStandardFocusableMode: false,
|
|
87
|
+
// @private - set to true to focus standard focusable element
|
|
84
88
|
lastFocusedElement: null,
|
|
85
89
|
lastFocusedKey: null,
|
|
86
90
|
lastFocusedPersist: function lastFocusedPersist(node, all) {
|
|
@@ -133,7 +137,8 @@ var GlobalConfig = {
|
|
|
133
137
|
* @private
|
|
134
138
|
*/
|
|
135
139
|
var querySelector = function querySelector(node, includeSelector, excludeSelector) {
|
|
136
|
-
var
|
|
140
|
+
var focusables = GlobalConfig.isStandardFocusableMode ? Array.prototype.filter.call(node.getElementsByTagName('*'), _utils.isStandardFocusable) : [];
|
|
141
|
+
var include = new Set([].concat(_toConsumableArray(node.querySelectorAll(includeSelector)), _toConsumableArray(focusables)));
|
|
137
142
|
var exclude = node.querySelectorAll(excludeSelector);
|
|
138
143
|
for (var i = 0; i < exclude.length; i++) {
|
|
139
144
|
include["delete"](exclude[i]);
|
|
@@ -618,7 +623,7 @@ var isNavigable = function isNavigable(node, containerId, verify) {
|
|
|
618
623
|
return false;
|
|
619
624
|
}
|
|
620
625
|
var config = getContainerConfig(containerId);
|
|
621
|
-
if (verify && config && config.selector && !isContainer(node) && !(0, _utils.matchSelector)(config.selector, node)) {
|
|
626
|
+
if (verify && config && config.selector && !isContainer(node) && !(0, _utils.matchSelector)(config.selector, node) && !(GlobalConfig.isStandardFocusableMode && (0, _utils.isStandardFocusable)(node))) {
|
|
622
627
|
return false;
|
|
623
628
|
}
|
|
624
629
|
return navigableFilter(node, containerId);
|
package/src/navigate.js
CHANGED
|
@@ -57,34 +57,35 @@ var calcNextExtendedGridPosition = function calcNextExtendedGridPosition(current
|
|
|
57
57
|
};
|
|
58
58
|
function prioritize(priorities, targetEdge) {
|
|
59
59
|
var destGroup = [];
|
|
60
|
-
|
|
60
|
+
var _loop = function _loop() {
|
|
61
61
|
var destPriority = priorities[index];
|
|
62
62
|
if (destPriority.group.length) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return delta;
|
|
74
|
-
}
|
|
63
|
+
var destDistance = destPriority.distance;
|
|
64
|
+
var destDifference = destPriority.difference;
|
|
65
|
+
var distance = 0;
|
|
66
|
+
var target;
|
|
67
|
+
destPriority.group.sort(function (a, b) {
|
|
68
|
+
for (var i = 0; i < destDistance.length; i++) {
|
|
69
|
+
var calcDistance = destDistance[i];
|
|
70
|
+
var delta = calcDistance(a) - calcDistance(b);
|
|
71
|
+
if (delta) {
|
|
72
|
+
return delta;
|
|
75
73
|
}
|
|
76
|
-
return 0;
|
|
77
|
-
});
|
|
78
|
-
target = destPriority.group[0];
|
|
79
|
-
for (var i = 0; i < destDifference.length; i++) {
|
|
80
|
-
distance += destDifference[i](target);
|
|
81
74
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
return 0;
|
|
76
|
+
});
|
|
77
|
+
target = destPriority.group[0];
|
|
78
|
+
for (var i = 0; i < destDifference.length; i++) {
|
|
79
|
+
distance += destDifference[i](target);
|
|
80
|
+
}
|
|
81
|
+
destGroup.push({
|
|
82
|
+
distance: Math.pow(destPriority.multiplier * (distance || destPriority.minDistance) / targetEdge, 2) + targetEdge,
|
|
83
|
+
target: target
|
|
84
|
+
});
|
|
87
85
|
}
|
|
86
|
+
};
|
|
87
|
+
for (var index = 0; index < priorities.length; index++) {
|
|
88
|
+
_loop();
|
|
88
89
|
}
|
|
89
90
|
if (!destGroup.length) {
|
|
90
91
|
return null;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Type definitions for spotlight
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Translates keyCodes into 5-way direction descriptions (e.g. `'down'` )
|
|
8
|
+
*/
|
|
9
|
+
export function getDirection(keyCode: number): string | false;
|
|
10
|
+
/**
|
|
11
|
+
* Provides 5-way navigation and focus support
|
|
12
|
+
* ```
|
|
13
|
+
import Spotlight from '@enact/Spotlight';
|
|
14
|
+
|
|
15
|
+
// get the currently focused component
|
|
16
|
+
const current = Spotlight.getCurrent();
|
|
17
|
+
|
|
18
|
+
// focus an element by CSS selector
|
|
19
|
+
Spotlight.focus('.my-custom-class');
|
|
20
|
+
|
|
21
|
+
// is `current` focusable?
|
|
22
|
+
const isFocused = Spotlight.isSpottable(current);
|
|
23
|
+
```
|
|
24
|
+
*/
|
|
25
|
+
export declare const Spotlight: {
|
|
26
|
+
/**
|
|
27
|
+
* Initializes Spotlight. This is generally handled by
|
|
28
|
+
.
|
|
29
|
+
*/
|
|
30
|
+
initialize(containerDefaults: object): void;
|
|
31
|
+
/**
|
|
32
|
+
* Terminates Spotlight. This is generally handled by .
|
|
33
|
+
*/
|
|
34
|
+
terminate(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the config for spotlight or the specified containerID
|
|
37
|
+
*/
|
|
38
|
+
set(containerIdOrConfig: string | object, config?: object): void;
|
|
39
|
+
/**
|
|
40
|
+
* Adds the config for a new container. The container ID may be passed in the configuration
|
|
41
|
+
object. If no container ID is supplied, a new container ID will be generated.
|
|
42
|
+
*/
|
|
43
|
+
add(containerIdOrConfig: string | object, config?: object): string;
|
|
44
|
+
/**
|
|
45
|
+
* Removes a container from Spotlight
|
|
46
|
+
*/
|
|
47
|
+
remove(containerId: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Disables the selector rules of the specified container
|
|
50
|
+
*/
|
|
51
|
+
disableSelector(containerId: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Enables the selector rules of the specified container
|
|
54
|
+
*/
|
|
55
|
+
enableSelector(containerId: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Pauses Spotlight
|
|
58
|
+
*/
|
|
59
|
+
pause(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Resumes Spotlight
|
|
62
|
+
*/
|
|
63
|
+
resume(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Focuses the specified component ID, container ID, element selector, or the default
|
|
66
|
+
container.
|
|
67
|
+
*
|
|
68
|
+
* If Spotlight is in pointer mode, focus is not changed but `elem` will be set as the last
|
|
69
|
+
focused element of its spotlight containers.
|
|
70
|
+
*/
|
|
71
|
+
focus(elem?: string | React.ReactNode, containerOption?: object): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Moves focus to the next spottable control in the direction specified. Optionally, a source
|
|
74
|
+
element selector may be supplied as the starting point.
|
|
75
|
+
*/
|
|
76
|
+
move(direction: string, selector: string | void): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Sets or clears the default container that will receive focus.
|
|
79
|
+
*/
|
|
80
|
+
setDefaultContainer(containerId?: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the currently active container.
|
|
83
|
+
*/
|
|
84
|
+
getActiveContainer(): string;
|
|
85
|
+
/**
|
|
86
|
+
* Sets the currently active container.
|
|
87
|
+
*
|
|
88
|
+
* Note: If the current container is restricted to 'self-only' and `containerId` is not
|
|
89
|
+
contained within the current container then the active container will not be updated.
|
|
90
|
+
*/
|
|
91
|
+
setActiveContainer(containerId?: string): void;
|
|
92
|
+
/**
|
|
93
|
+
* Gets the current pointer mode
|
|
94
|
+
*/
|
|
95
|
+
getPointerMode(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Sets the current pointer mode
|
|
98
|
+
*/
|
|
99
|
+
setPointerMode(pointerMode: boolean): void;
|
|
100
|
+
/**
|
|
101
|
+
* Gets the muted mode value of a spottable element.
|
|
102
|
+
*/
|
|
103
|
+
isMuted(elem: object): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Determines whether Spotlight is currently paused.
|
|
106
|
+
*/
|
|
107
|
+
isPaused(): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Determines whether an element is spottable.
|
|
110
|
+
*/
|
|
111
|
+
isSpottable(elem: object): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Returns the currently spotted control.
|
|
114
|
+
*/
|
|
115
|
+
getCurrent(): React.ReactNode;
|
|
116
|
+
/**
|
|
117
|
+
* Returns a list of spottable elements wrapped by the supplied container.
|
|
118
|
+
*/
|
|
119
|
+
getSpottableDescendants(containerId: string): React.ReactNode[];
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default Spotlight;
|
package/src/spotlight.js
CHANGED
|
@@ -85,6 +85,7 @@ var Spotlight = function () {
|
|
|
85
85
|
*/
|
|
86
86
|
var _initialized = false;
|
|
87
87
|
var _duringFocusChange = false;
|
|
88
|
+
var _focusRingElement = null;
|
|
88
89
|
|
|
89
90
|
/*
|
|
90
91
|
* Whether a 5-way directional key is being held.
|
|
@@ -169,6 +170,15 @@ var Spotlight = function () {
|
|
|
169
170
|
return true;
|
|
170
171
|
}
|
|
171
172
|
elem.focus(focusOptions);
|
|
173
|
+
|
|
174
|
+
/* istanbul ignore next */
|
|
175
|
+
if (_focusRingElement) {
|
|
176
|
+
var elemRect = elem.getBoundingClientRect();
|
|
177
|
+
_focusRingElement.style.left = "".concat(elemRect.x + window.scrollX, "px");
|
|
178
|
+
_focusRingElement.style.top = "".concat(elemRect.y + window.scrollY, "px");
|
|
179
|
+
_focusRingElement.style.width = "".concat(elemRect.width, "px");
|
|
180
|
+
_focusRingElement.style.height = "".concat(elemRect.height, "px");
|
|
181
|
+
}
|
|
172
182
|
_duringFocusChange = false;
|
|
173
183
|
focusChanged(elem, containerIds);
|
|
174
184
|
return true;
|
|
@@ -422,6 +432,7 @@ var Spotlight = function () {
|
|
|
422
432
|
*/
|
|
423
433
|
initialize: function initialize(containerDefaults) {
|
|
424
434
|
if (!_initialized) {
|
|
435
|
+
var _getContainerConfig3;
|
|
425
436
|
window.addEventListener('blur', onBlur);
|
|
426
437
|
window.addEventListener('focus', onFocus);
|
|
427
438
|
window.addEventListener('keydown', onKeyDown);
|
|
@@ -441,6 +452,11 @@ var Spotlight = function () {
|
|
|
441
452
|
// by default, pointer mode is off but the platform's current state will override that
|
|
442
453
|
(0, _pointer.setPointerMode)(false);
|
|
443
454
|
setPlatformPointerMode();
|
|
455
|
+
|
|
456
|
+
/* istanbul ignore next */
|
|
457
|
+
if ((_getContainerConfig3 = (0, _container.getContainerConfig)('spotlightRootDecorator')) !== null && _getContainerConfig3 !== void 0 && _getContainerConfig3.isStandardFocusableMode) {
|
|
458
|
+
_focusRingElement = document.querySelector('#spotlightFocusRing');
|
|
459
|
+
}
|
|
444
460
|
_initialized = true;
|
|
445
461
|
}
|
|
446
462
|
},
|
package/src/target.js
CHANGED
|
@@ -18,13 +18,15 @@ var _utils = require("./utils");
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
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
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; }
|
|
21
|
-
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
|
+
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
24
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
23
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."); }
|
|
24
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); }
|
|
25
27
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
26
28
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
27
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
29
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
28
30
|
function isFocusable(elem) {
|
|
29
31
|
var containers = (0, _container.getContainersForNode)(elem);
|
|
30
32
|
var verifySelector = true;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
var _container17 = require("../container");
|
|
4
4
|
var _utils = require("./utils");
|
|
5
5
|
var _node, _container, _container2, _container3, _container4, _container5, _container6, _container7, _container8, _container9, _container10, _container11, _container12, _container13, _container15, _container16;
|
|
6
|
-
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; }
|
|
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; }
|
|
7
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
8
|
+
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); }
|
|
7
9
|
var nonSpottable = function nonSpottable() {
|
|
8
10
|
return (0, _utils.node)({
|
|
9
11
|
className: 'other'
|
|
@@ -7,7 +7,7 @@ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread n
|
|
|
7
7
|
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); }
|
|
8
8
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
9
9
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
10
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
11
|
// loose copy from utils/getRect to fabricate a rect for navigation
|
|
12
12
|
function getRect(top, left, height, width, elem) {
|
|
13
13
|
var rect = {
|
|
@@ -5,7 +5,9 @@ var _spotlight = _interopRequireDefault(require("../spotlight"));
|
|
|
5
5
|
var _utils = require("./utils");
|
|
6
6
|
var _container, _container2, _container3;
|
|
7
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
|
-
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; }
|
|
8
|
+
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(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
|
+
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); }
|
|
9
11
|
var nonSpottable = function nonSpottable() {
|
|
10
12
|
return (0, _utils.node)({
|
|
11
13
|
className: 'other'
|
|
@@ -4,7 +4,9 @@ var _container12 = require("../container");
|
|
|
4
4
|
var _target = require("../target");
|
|
5
5
|
var _utils = require("./utils");
|
|
6
6
|
var _container2, _container3, _container4, _container5, _container6, _container7, _container8, _container9, _container10, _container11;
|
|
7
|
-
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; }
|
|
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; }
|
|
8
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
9
|
+
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); }
|
|
8
10
|
var nonSpottable = function nonSpottable() {
|
|
9
11
|
return (0, _utils.node)({
|
|
10
12
|
className: 'other'
|
package/src/tests/utils.js
CHANGED
|
@@ -9,7 +9,9 @@ var _container = require("../container");
|
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
10
|
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; }
|
|
11
11
|
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; }
|
|
12
|
-
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; }
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
14
|
+
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); }
|
|
13
15
|
var join = _ramda["default"].unapply(_ramda["default"].join('\n'));
|
|
14
16
|
exports.join = join;
|
|
15
17
|
var testScenario = function testScenario(scenario, callback) {
|
package/src/utils.js
CHANGED
|
@@ -8,7 +8,9 @@ exports.getContainerRect = getContainerRect;
|
|
|
8
8
|
exports.getPointRect = getPointRect;
|
|
9
9
|
exports.getRect = getRect;
|
|
10
10
|
exports.getRects = getRects;
|
|
11
|
-
exports.
|
|
11
|
+
exports.intersects = void 0;
|
|
12
|
+
exports.isStandardFocusable = isStandardFocusable;
|
|
13
|
+
exports.matchSelector = void 0;
|
|
12
14
|
exports.parseSelector = parseSelector;
|
|
13
15
|
var _curry = _interopRequireDefault(require("ramda/src/curry"));
|
|
14
16
|
var _warning = _interopRequireDefault(require("warning"));
|
|
@@ -160,4 +162,37 @@ function getContainerRect(containerId) {
|
|
|
160
162
|
return getViewportRect();
|
|
161
163
|
}
|
|
162
164
|
return getRect(containerNode);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// For details see: https://html.spec.whatwg.org/multipage/interaction.html#focusable-area
|
|
168
|
+
function isStandardFocusable(element) {
|
|
169
|
+
if (element.tabIndex < 0) {
|
|
170
|
+
// If the tabIndex value is negative, it is not focusable
|
|
171
|
+
return false;
|
|
172
|
+
} else if (isElementHidden(element)) {
|
|
173
|
+
return false;
|
|
174
|
+
} else if (['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTGROUP', 'OPTION', 'FIELDSET'].includes(element.tagName) && element.disabled) {
|
|
175
|
+
// If the element is actually disabled, it is not focusable
|
|
176
|
+
return false;
|
|
177
|
+
} else if (element.tagName === 'A' && element.getAttribute('href') !== null) {
|
|
178
|
+
// Anchor element that has an href attribute is focusable
|
|
179
|
+
return true;
|
|
180
|
+
} else if (element.tagName === 'INPUT' && element.type !== 'hidden') {
|
|
181
|
+
// Input element whose type attribute is not hidden is focusable
|
|
182
|
+
return true;
|
|
183
|
+
} else if (element.tabIndex >= 0 || !element.parentElement) {
|
|
184
|
+
// If the tabIndex value is more than 0, it is focusable
|
|
185
|
+
// If element is document or iframe, it is focusable
|
|
186
|
+
return true;
|
|
187
|
+
} else {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function isElementHidden(element) {
|
|
192
|
+
var elemRect = element.getBoundingClientRect();
|
|
193
|
+
if (elemRect.width <= 1 && elemRect.height <= 1 || elemRect.x < -3840 || elemRect.y < -2160 || element.getAttribute('hidden')) {
|
|
194
|
+
return true;
|
|
195
|
+
} else {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
163
198
|
}
|