@enact/spotlight 3.4.9-experimental-3 → 3.4.9-experimental-7

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.
Files changed (68) hide show
  1. package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
  2. package/Accelerator/Accelerator.js +149 -156
  3. package/CHANGELOG.md +22 -0
  4. package/{build/Pause → Pause}/Pause.d.ts +0 -0
  5. package/Pause/Pause.js +102 -80
  6. package/Pause/tests/Pause-specs.js +65 -97
  7. package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
  8. package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
  9. package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
  10. package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
  11. package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
  12. package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
  13. package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
  14. package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
  15. package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
  16. package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
  17. package/Spottable/Spottable.js +448 -410
  18. package/Spottable/tests/Spottable-specs.js +90 -117
  19. package/package.json +3 -2
  20. package/src/container.js +718 -653
  21. package/src/navigate.js +406 -491
  22. package/src/pointer.js +86 -78
  23. package/{build/src → src}/spotlight.d.ts +0 -0
  24. package/src/spotlight.js +846 -885
  25. package/src/target.js +448 -474
  26. package/src/tests/container-specs.js +643 -1251
  27. package/src/tests/navigate-specs.js +77 -134
  28. package/src/tests/pointer-specs.js +126 -182
  29. package/src/tests/spotlight-specs.js +103 -133
  30. package/src/tests/target-specs.js +597 -960
  31. package/src/tests/utils.js +89 -67
  32. package/src/utils.js +155 -158
  33. package/build/Accelerator/Accelerator.js +0 -162
  34. package/build/Accelerator/package.json +0 -3
  35. package/build/CHANGELOG.md +0 -838
  36. package/build/Pause/Pause.js +0 -164
  37. package/build/Pause/package.json +0 -3
  38. package/build/Pause/tests/Pause-specs.js +0 -65
  39. package/build/README.md +0 -61
  40. package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
  41. package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
  42. package/build/SpotlightContainerDecorator/package.json +0 -3
  43. package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
  44. package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
  45. package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
  46. package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
  47. package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
  48. package/build/SpotlightRootDecorator/package.json +0 -3
  49. package/build/Spottable/Spottable.js +0 -491
  50. package/build/Spottable/package.json +0 -3
  51. package/build/Spottable/tests/Spottable-specs.js +0 -90
  52. package/build/package-lock.json +0 -229
  53. package/build/package.json +0 -28
  54. package/build/src/container.js +0 -1201
  55. package/build/src/navigate.js +0 -419
  56. package/build/src/pointer.js +0 -183
  57. package/build/src/spotlight.js +0 -896
  58. package/build/src/target.js +0 -507
  59. package/build/src/tests/container-specs.js +0 -653
  60. package/build/src/tests/navigate-specs.js +0 -87
  61. package/build/src/tests/pointer-specs.js +0 -130
  62. package/build/src/tests/spotlight-specs.js +0 -112
  63. package/build/src/tests/target-specs.js +0 -614
  64. package/build/src/tests/utils.js +0 -104
  65. package/build/src/utils.js +0 -180
  66. package/build/styles/debug.less +0 -97
  67. package/build/styles/mixins.less +0 -63
  68. package/docs/index.md +0 -364
@@ -1,97 +1,65 @@
1
- import Pause, {isPaused, pause, resume} from '../Pause';
2
-
3
- const PAUSED = 'Paused';
4
- const NOT_PAUSED = 'Not Paused';
5
-
6
- describe('Pause', () => {
7
- test('should pause spotlight', () => {
8
- const subject = new Pause();
9
-
10
- subject.pause();
11
-
12
- const expected = PAUSED;
13
- const actual = isPaused() ? PAUSED : NOT_PAUSED;
14
-
15
- subject.resume();
16
-
17
- expect(actual).toBe(expected);
18
- });
19
-
20
- test('should resume spotlight', () => {
21
- const subject = new Pause();
22
-
23
- subject.pause();
24
- subject.resume();
25
-
26
- const expected = NOT_PAUSED;
27
- const actual = isPaused() ? PAUSED : NOT_PAUSED;
28
-
29
- expect(actual).toBe(expected);
30
- });
31
-
32
- test(
33
- 'should not resume spotlight when another Paused instance is in control',
34
- () => {
35
- const subject = new Pause();
36
- const another = new Pause();
37
-
38
- another.pause();
39
- subject.pause();
40
-
41
- const expected = PAUSED;
42
- const actual = isPaused() ? PAUSED : NOT_PAUSED;
43
-
44
- another.resume();
45
-
46
- expect(actual).toBe(expected);
47
- }
48
- );
49
-
50
- test(
51
- 'should not report paused when another Paused instance is in control',
52
- () => {
53
- const subject = new Pause();
54
- const another = new Pause();
55
-
56
- another.pause();
57
- subject.pause();
58
-
59
- const expected = NOT_PAUSED;
60
- const actual = subject.isPaused() ? PAUSED : NOT_PAUSED;
61
-
62
- another.resume();
63
-
64
- expect(actual).toBe(expected);
65
- }
66
- );
67
-
68
- test(
69
- 'should not report paused when the global Spotlight is paused',
70
- () => {
71
- const subject = new Pause();
72
-
73
- pause();
74
- subject.pause();
75
-
76
- const expected = NOT_PAUSED;
77
- const actual = subject.isPaused() ? PAUSED : NOT_PAUSED;
78
-
79
- resume();
80
-
81
- expect(actual).toBe(expected);
82
- }
83
- );
84
-
85
- test('should allow the global Spotlight to resume', () => {
86
- const subject = new Pause();
87
-
88
- subject.pause();
89
- resume();
90
-
91
- const expected = NOT_PAUSED;
92
- const actual = isPaused() ? PAUSED : NOT_PAUSED;
93
-
94
- expect(actual).toBe(expected);
95
- });
96
-
97
- });
1
+ "use strict";
2
+
3
+ var _Pause = _interopRequireWildcard(require("../Pause"));
4
+
5
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
6
+
7
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
8
+
9
+ var PAUSED = 'Paused';
10
+ var NOT_PAUSED = 'Not Paused';
11
+ describe('Pause', function () {
12
+ test('should pause spotlight', function () {
13
+ var subject = new _Pause["default"]();
14
+ subject.pause();
15
+ var expected = PAUSED;
16
+ var actual = (0, _Pause.isPaused)() ? PAUSED : NOT_PAUSED;
17
+ subject.resume();
18
+ expect(actual).toBe(expected);
19
+ });
20
+ test('should resume spotlight', function () {
21
+ var subject = new _Pause["default"]();
22
+ subject.pause();
23
+ subject.resume();
24
+ var expected = NOT_PAUSED;
25
+ var actual = (0, _Pause.isPaused)() ? PAUSED : NOT_PAUSED;
26
+ expect(actual).toBe(expected);
27
+ });
28
+ test('should not resume spotlight when another Paused instance is in control', function () {
29
+ var subject = new _Pause["default"]();
30
+ var another = new _Pause["default"]();
31
+ another.pause();
32
+ subject.pause();
33
+ var expected = PAUSED;
34
+ var actual = (0, _Pause.isPaused)() ? PAUSED : NOT_PAUSED;
35
+ another.resume();
36
+ expect(actual).toBe(expected);
37
+ });
38
+ test('should not report paused when another Paused instance is in control', function () {
39
+ var subject = new _Pause["default"]();
40
+ var another = new _Pause["default"]();
41
+ another.pause();
42
+ subject.pause();
43
+ var expected = NOT_PAUSED;
44
+ var actual = subject.isPaused() ? PAUSED : NOT_PAUSED;
45
+ another.resume();
46
+ expect(actual).toBe(expected);
47
+ });
48
+ test('should not report paused when the global Spotlight is paused', function () {
49
+ var subject = new _Pause["default"]();
50
+ (0, _Pause.pause)();
51
+ subject.pause();
52
+ var expected = NOT_PAUSED;
53
+ var actual = subject.isPaused() ? PAUSED : NOT_PAUSED;
54
+ (0, _Pause.resume)();
55
+ expect(actual).toBe(expected);
56
+ });
57
+ test('should allow the global Spotlight to resume', function () {
58
+ var subject = new _Pause["default"]();
59
+ subject.pause();
60
+ (0, _Pause.resume)();
61
+ var expected = NOT_PAUSED;
62
+ var actual = (0, _Pause.isPaused)() ? PAUSED : NOT_PAUSED;
63
+ expect(actual).toBe(expected);
64
+ });
65
+ });
@@ -1,141 +1,176 @@
1
- import {forProp, handle, not, stop} from '@enact/core/handle';
2
-
3
- import {hasPointerMoved} from '../src/pointer';
4
- import Spotlight from '../src/spotlight';
5
-
6
- const isNewPointerPosition = (ev) => hasPointerMoved(ev.clientX, ev.clientY);
7
-
8
- class SpotlightContainer {
9
- // set up context and props so we can use handle binding
10
- context = {};
11
- props = {};
12
-
13
- constructor ({containerConfig, navigableFilter, preserveId}) {
14
- // spotlight id - set either via props or generated by Spotlight
15
- this.id = null;
16
-
17
- // Preserve the spotlight id across instances when it is set via props and preserveId is set
18
- this.canPreserveId = preserveId;
19
- this.preserveId = false;
20
-
21
- // container config - set once when the container is added
22
- this.config = containerConfig;
23
-
24
- // optional filter function to limit the spottable candidates for this container
25
- this.filter = navigableFilter;
26
-
27
- // private hash of spotlight DOM attributes
28
- this.attr = {
29
- 'data-spotlight-container': true
30
- };
31
-
32
- // Used to indicate that we want to stop propagation on blur events that occur as a
33
- // result of this component imperatively blurring itself on focus when spotlightDisabled
34
- this.shouldPreventBlur = false;
35
- }
36
-
37
- get attributes () {
38
- return this.attr;
39
- }
40
-
41
- setProps (props) {
42
- const {disabled, id, muted, restrict} = props;
43
- this.props = props;
44
-
45
- if (this.id == null || (id && this.id !== id)) {
46
- if (this.id) {
47
- this.releaseContainer(this.id);
48
- }
49
-
50
- this.id = Spotlight.add({
51
- ...this.config,
52
- id,
53
- restrict,
54
- navigableFilter: this.navigableFilter
55
- });
56
- this.preserveId = this.canPreserveId && this.id === id;
57
- } else {
58
- Spotlight.set(this.id, {restrict});
59
- }
60
-
61
- this.attr['data-spotlight-id'] = this.id;
62
- this.attr['data-spotlight-container-disabled'] = disabled;
63
- this.attr['data-spotlight-container-muted'] = muted;
64
- }
65
-
66
- unload () {
67
- this.releaseContainer();
68
- }
69
-
70
- releaseContainer () {
71
- if (this.preserveId) {
72
- Spotlight.unmount(this.id);
73
- } else {
74
- Spotlight.remove(this.id);
75
- }
76
- }
77
-
78
- navigableFilter = (elem) => {
79
- // If the component to which this was applied specified a navigableFilter, run it
80
- if (typeof this.filter === 'function') {
81
- if (this.filter(elem) === false) {
82
- return false;
83
- }
84
- }
85
-
86
- return true;
87
- };
88
-
89
- silentBlur ({target}) {
90
- this.shouldPreventBlur = true;
91
- target.blur();
92
- this.shouldPreventBlur = false;
93
- }
94
-
95
- onBlurCapture = (ev) => {
96
- if (this.shouldPreventBlur) {
97
- stop(ev);
98
-
99
- return false;
100
- }
101
-
102
- return true;
103
- };
104
-
105
- onFocusCapture = (ev) => {
106
- if (this.props.disabled === true) {
107
- stop(ev);
108
- this.silentBlur(ev);
109
-
110
- return false;
111
- }
112
-
113
- return true;
114
- };
115
-
116
- onPointerEnter = handle(
117
- isNewPointerPosition,
118
- () => Spotlight.setActiveContainer(this.id)
119
- ).bindAs(this, 'onPointerEnter');
120
-
121
- onPointerLeave = handle(
122
- not(forProp('restrict', 'self-only')),
123
- isNewPointerPosition,
124
- (ev) => {
125
- const parentContainer = ev.currentTarget.parentNode.closest('[data-spotlight-container]');
126
- let activeContainer = Spotlight.getActiveContainer();
127
-
128
- // if this container is wrapped by another and this is the currently active
129
- // container, move the active container to the parent
130
- if (parentContainer && activeContainer === this.id) {
131
- activeContainer = parentContainer.dataset.spotlightId;
132
- Spotlight.setActiveContainer(activeContainer);
133
- }
134
- }
135
- ).bindAs(this, 'onPointerLeave');
136
- }
137
-
138
- export default SpotlightContainer;
139
- export {
140
- SpotlightContainer
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SpotlightContainer = exports["default"] = void 0;
7
+
8
+ var _handle = require("@enact/core/handle");
9
+
10
+ var _pointer = require("../src/pointer");
11
+
12
+ var _spotlight = _interopRequireDefault(require("../src/spotlight"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
+
20
+ 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
+
22
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
+
24
+ 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); } }
25
+
26
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
27
+
28
+ var isNewPointerPosition = function isNewPointerPosition(ev) {
29
+ return (0, _pointer.hasPointerMoved)(ev.clientX, ev.clientY);
141
30
  };
31
+
32
+ var SpotlightContainer = /*#__PURE__*/function () {
33
+ // set up context and props so we can use handle binding
34
+ function SpotlightContainer(_ref) {
35
+ var _this = this;
36
+
37
+ var containerConfig = _ref.containerConfig,
38
+ navigableFilter = _ref.navigableFilter,
39
+ preserveId = _ref.preserveId;
40
+
41
+ _classCallCheck(this, SpotlightContainer);
42
+
43
+ this.context = {};
44
+ this.props = {};
45
+
46
+ this.navigableFilter = function (elem) {
47
+ // If the component to which this was applied specified a navigableFilter, run it
48
+ if (typeof _this.filter === 'function') {
49
+ if (_this.filter(elem) === false) {
50
+ return false;
51
+ }
52
+ }
53
+
54
+ return true;
55
+ };
56
+
57
+ this.onBlurCapture = function (ev) {
58
+ if (_this.shouldPreventBlur) {
59
+ (0, _handle.stop)(ev);
60
+ return false;
61
+ }
62
+
63
+ return true;
64
+ };
65
+
66
+ this.onFocusCapture = function (ev) {
67
+ if (_this.props.disabled === true) {
68
+ (0, _handle.stop)(ev);
69
+
70
+ _this.silentBlur(ev);
71
+
72
+ return false;
73
+ }
74
+
75
+ return true;
76
+ };
77
+
78
+ this.onPointerEnter = (0, _handle.handle)(isNewPointerPosition, function () {
79
+ return _spotlight["default"].setActiveContainer(_this.id);
80
+ }).bindAs(this, 'onPointerEnter');
81
+ this.onPointerLeave = (0, _handle.handle)((0, _handle.not)((0, _handle.forProp)('restrict', 'self-only')), isNewPointerPosition, function (ev) {
82
+ var parentContainer = ev.currentTarget.parentNode.closest('[data-spotlight-container]');
83
+
84
+ var activeContainer = _spotlight["default"].getActiveContainer(); // if this container is wrapped by another and this is the currently active
85
+ // container, move the active container to the parent
86
+
87
+
88
+ if (parentContainer && activeContainer === _this.id) {
89
+ activeContainer = parentContainer.dataset.spotlightId;
90
+
91
+ _spotlight["default"].setActiveContainer(activeContainer);
92
+ }
93
+ }).bindAs(this, 'onPointerLeave');
94
+ // spotlight id - set either via props or generated by Spotlight
95
+ this.id = null; // Preserve the spotlight id across instances when it is set via props and preserveId is set
96
+
97
+ this.canPreserveId = preserveId;
98
+ this.preserveId = false; // container config - set once when the container is added
99
+
100
+ this.config = containerConfig; // optional filter function to limit the spottable candidates for this container
101
+
102
+ this.filter = navigableFilter; // private hash of spotlight DOM attributes
103
+
104
+ this.attr = {
105
+ 'data-spotlight-container': true
106
+ }; // Used to indicate that we want to stop propagation on blur events that occur as a
107
+ // result of this component imperatively blurring itself on focus when spotlightDisabled
108
+
109
+ this.shouldPreventBlur = false;
110
+ }
111
+
112
+ _createClass(SpotlightContainer, [{
113
+ key: "setProps",
114
+ value: function setProps(props) {
115
+ var disabled = props.disabled,
116
+ id = props.id,
117
+ muted = props.muted,
118
+ restrict = props.restrict;
119
+ this.props = props;
120
+
121
+ if (this.id == null || id && this.id !== id) {
122
+ if (this.id) {
123
+ this.releaseContainer(this.id);
124
+ }
125
+
126
+ this.id = _spotlight["default"].add(_objectSpread(_objectSpread({}, this.config), {}, {
127
+ id: id,
128
+ restrict: restrict,
129
+ navigableFilter: this.navigableFilter
130
+ }));
131
+ this.preserveId = this.canPreserveId && this.id === id;
132
+ } else {
133
+ _spotlight["default"].set(this.id, {
134
+ restrict: restrict
135
+ });
136
+ }
137
+
138
+ this.attr['data-spotlight-id'] = this.id;
139
+ this.attr['data-spotlight-container-disabled'] = disabled;
140
+ this.attr['data-spotlight-container-muted'] = muted;
141
+ }
142
+ }, {
143
+ key: "unload",
144
+ value: function unload() {
145
+ this.releaseContainer();
146
+ }
147
+ }, {
148
+ key: "releaseContainer",
149
+ value: function releaseContainer() {
150
+ if (this.preserveId) {
151
+ _spotlight["default"].unmount(this.id);
152
+ } else {
153
+ _spotlight["default"].remove(this.id);
154
+ }
155
+ }
156
+ }, {
157
+ key: "silentBlur",
158
+ value: function silentBlur(_ref2) {
159
+ var target = _ref2.target;
160
+ this.shouldPreventBlur = true;
161
+ target.blur();
162
+ this.shouldPreventBlur = false;
163
+ }
164
+ }, {
165
+ key: "attributes",
166
+ get: function get() {
167
+ return this.attr;
168
+ }
169
+ }]);
170
+
171
+ return SpotlightContainer;
172
+ }();
173
+
174
+ exports.SpotlightContainer = SpotlightContainer;
175
+ var _default = SpotlightContainer;
176
+ exports["default"] = _default;