@enact/ui 4.5.1 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/AnnounceDecorator/Announce.js +1 -40
  2. package/AnnounceDecorator/AnnounceDecorator.js +3 -21
  3. package/AnnounceDecorator/tests/Announce-specs.js +2 -7
  4. package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +2 -6
  5. package/AnnounceDecorator/tests/useAnnounce-specs.js +8 -19
  6. package/AnnounceDecorator/useAnnounce.js +0 -6
  7. package/BodyText/BodyText.d.ts +1 -1
  8. package/BodyText/BodyText.js +8 -28
  9. package/BodyText/tests/BodyText-specs.js +0 -19
  10. package/Button/Button.d.ts +6 -6
  11. package/Button/Button.js +33 -63
  12. package/Button/tests/Button-specs.js +0 -26
  13. package/CHANGELOG.md +36 -0
  14. package/Cancelable/Cancelable.js +8 -47
  15. package/Cancelable/cancelHandler.js +5 -12
  16. package/Cancelable/modalHandler.js +3 -11
  17. package/Cancelable/tests/Cancelable-specs.js +3 -57
  18. package/Changeable/Changeable.js +2 -34
  19. package/Changeable/tests/Changeable-specs.js +20 -66
  20. package/ComponentOverride/ComponentOverride.js +1 -13
  21. package/FloatingLayer/FloatingLayer.js +17 -73
  22. package/FloatingLayer/FloatingLayerContainer.js +0 -15
  23. package/FloatingLayer/FloatingLayerDecorator.js +4 -17
  24. package/FloatingLayer/Scrim.js +9 -53
  25. package/FloatingLayer/index.js +0 -4
  26. package/FloatingLayer/tests/FloatingLayer-specs.js +8 -22
  27. package/FloatingLayer/tests/Scrim-specs.js +0 -9
  28. package/FloatingLayer/tests/useFloatingLayerDecorator-specs.js +0 -13
  29. package/FloatingLayer/useFloatingLayer.js +3 -14
  30. package/FloatingLayer/useFloatingLayerDecorator.js +3 -11
  31. package/ForwardRef/ForwardRef.js +1 -10
  32. package/GridListImageItem/GridListImageItem.d.ts +1 -1
  33. package/GridListImageItem/GridListImageItem.js +18 -51
  34. package/Group/Group.js +5 -36
  35. package/Group/GroupItem.js +16 -33
  36. package/Group/tests/Group-specs.js +0 -32
  37. package/Heading/Heading.js +8 -36
  38. package/Heading/tests/Heading-specs.js +81 -14
  39. package/Icon/Icon.d.ts +4 -4
  40. package/Icon/Icon.js +19 -53
  41. package/Icon/tests/Icon-specs.js +0 -22
  42. package/IconButton/IconButton.d.ts +4 -4
  43. package/IconButton/IconButton.js +17 -55
  44. package/IconButton/tests/IconButton-specs.js +0 -7
  45. package/Image/Image.js +17 -46
  46. package/Image/tests/Image-specs.js +0 -14
  47. package/ImageItem/ImageItem.js +18 -47
  48. package/ImageItem/tests/ImageItem-specs.js +0 -25
  49. package/Item/Item.js +9 -33
  50. package/Item/tests/Item-specs.js +0 -24
  51. package/LabeledIcon/LabeledIcon.d.ts +2 -2
  52. package/LabeledIcon/LabeledIcon.js +22 -53
  53. package/LabeledIcon/tests/LabeledIcon-specs.js +0 -14
  54. package/Layout/Cell.js +18 -44
  55. package/Layout/Layout.d.ts +16 -16
  56. package/Layout/Layout.js +23 -46
  57. package/Layout/tests/Layout-specs.js +10 -39
  58. package/Marquee/MarqueeBase.js +31 -64
  59. package/Marquee/MarqueeController.js +11 -72
  60. package/Marquee/MarqueeDecorator.js +70 -196
  61. package/Marquee/index.js +1 -5
  62. package/Marquee/tests/Marquee-specs.js +295 -87
  63. package/Measurable/Measurable.js +12 -34
  64. package/Measurable/tests/Measurable-specs.js +115 -0
  65. package/Media/Media.js +15 -65
  66. package/Media/tests/Media-specs.js +168 -0
  67. package/Placeholder/PlaceholderControllerDecorator.js +7 -43
  68. package/Placeholder/PlaceholderDecorator.js +7 -38
  69. package/Placeholder/index.js +1 -5
  70. package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +25 -0
  71. package/Placeholder/tests/PlaceholderDecorator-specs.js +28 -0
  72. package/ProgressBar/ProgressBar.js +14 -45
  73. package/ProgressBar/tests/ProgressBar-specs.js +0 -17
  74. package/RadioDecorator/RadioControllerDecorator.js +1 -29
  75. package/RadioDecorator/RadioDecorator.js +4 -42
  76. package/RadioDecorator/tests/RadioDecorator-specs.js +12 -49
  77. package/Repeater/Repeater.js +9 -33
  78. package/Repeater/tests/Repeater-specs.js +0 -38
  79. package/Resizable/Resizable.js +9 -37
  80. package/Resizable/tests/Resizable-specs.js +34 -0
  81. package/Routable/Link.js +11 -47
  82. package/Routable/Routable.d.ts +2 -2
  83. package/Routable/Routable.js +12 -35
  84. package/Routable/Route.js +0 -6
  85. package/Routable/Router.js +15 -58
  86. package/Routable/tests/Routable-specs.js +7 -33
  87. package/Routable/tests/Router-specs.js +18 -44
  88. package/Routable/useLink.js +4 -8
  89. package/Routable/util.js +18 -24
  90. package/Scrollable/ScrollAnimator.js +49 -65
  91. package/Scrollable/ScrollThumb.js +2 -13
  92. package/Scrollable/Scrollable.js +180 -387
  93. package/Scrollable/ScrollableNative.js +189 -392
  94. package/Scrollable/Scrollbar.js +30 -102
  95. package/Scroller/Scroller.js +15 -39
  96. package/Scroller/ScrollerBasic.js +34 -89
  97. package/Scroller/UiScrollerBase.js +31 -84
  98. package/Scroller/tests/Scroller-specs.js +56 -0
  99. package/Skinnable/Skinnable.js +11 -38
  100. package/Skinnable/tests/Skinnable-specs.js +3 -74
  101. package/Skinnable/tests/useSkins-specs.js +1 -13
  102. package/Skinnable/tests/util-specs.js +0 -14
  103. package/Skinnable/useSkins.js +8 -15
  104. package/Skinnable/util.js +9 -20
  105. package/Slider/Knob.js +5 -24
  106. package/Slider/PositionDecorator.js +16 -54
  107. package/Slider/Slider.d.ts +2 -2
  108. package/Slider/Slider.js +29 -67
  109. package/Slider/tests/Slider-specs.js +94 -7
  110. package/Slider/utils.js +0 -2
  111. package/SlotItem/SlotItem.d.ts +1 -1
  112. package/SlotItem/SlotItem.js +17 -43
  113. package/SlotItem/tests/SlotItem-specs.js +0 -5
  114. package/Slottable/Slottable.js +4 -12
  115. package/Slottable/tests/Slottable-specs.js +19 -46
  116. package/Slottable/tests/useSlots-specs.js +27 -65
  117. package/Slottable/useSlots.js +8 -33
  118. package/Spinner/Spinner.d.ts +1 -1
  119. package/Spinner/Spinner.js +16 -43
  120. package/Spinner/tests/Spinner-specs.js +0 -15
  121. package/ToggleIcon/ToggleIcon.js +10 -36
  122. package/ToggleIcon/tests/ToggleIcon-specs.js +0 -16
  123. package/ToggleItem/ToggleItem.d.ts +3 -3
  124. package/ToggleItem/ToggleItem.js +18 -55
  125. package/ToggleItem/tests/ToggleItem-specs.js +0 -30
  126. package/Toggleable/Toggle.js +1 -15
  127. package/Toggleable/Toggleable.js +12 -45
  128. package/Toggleable/tests/Toggleable-specs.js +28 -96
  129. package/Toggleable/useToggle.js +3 -19
  130. package/Touchable/ClickAllow.js +5 -14
  131. package/Touchable/Drag.js +16 -54
  132. package/Touchable/Flick.js +11 -42
  133. package/Touchable/Hold.js +21 -68
  134. package/Touchable/Touch.js +37 -65
  135. package/Touchable/Touchable.js +32 -71
  136. package/Touchable/config.js +8 -22
  137. package/Touchable/tests/Touchable-specs.js +270 -119
  138. package/Touchable/tests/useTouch-specs.js +6 -80
  139. package/Touchable/useTouch.js +17 -34
  140. package/Transition/Transition.js +37 -118
  141. package/Transition/tests/Transition-specs.js +20 -60
  142. package/ViewManager/Arranger.js +10 -22
  143. package/ViewManager/TransitionGroup.js +32 -107
  144. package/ViewManager/View.js +35 -91
  145. package/ViewManager/ViewManager.d.ts +1 -1
  146. package/ViewManager/ViewManager.js +20 -84
  147. package/ViewManager/tests/View-specs.js +0 -17
  148. package/ViewManager/tests/ViewManager-specs.js +236 -305
  149. package/ViewManager/tests/test-utils.js +0 -8
  150. package/VirtualList/UiVirtualListBase.js +259 -409
  151. package/VirtualList/VirtualList.d.ts +4 -4
  152. package/VirtualList/VirtualList.js +29 -69
  153. package/VirtualList/VirtualListBase.js +0 -3
  154. package/VirtualList/VirtualListBasic.js +273 -431
  155. package/VirtualList/tests/VirtualGridList-native-specs.js +161 -0
  156. package/VirtualList/tests/VirtualGridList-specs.js +614 -0
  157. package/VirtualList/tests/VirtualList-native-specs.js +152 -0
  158. package/VirtualList/tests/VirtualList-specs.js +423 -95
  159. package/internal/IdProvider/IdProvider.js +7 -21
  160. package/internal/IdProvider/Provider.js +4 -17
  161. package/internal/IdProvider/tests/IdProvider-specs.js +44 -0
  162. package/internal/IdProvider/tests/useId-specs.js +6 -20
  163. package/internal/IdProvider/useId.js +0 -6
  164. package/internal/Pure/Pure.js +3 -30
  165. package/internal/Pure/tests/Pure-specs.js +88 -0
  166. package/internal/localized-fonts/localized-fonts.js +33 -62
  167. package/internal/localized-fonts/tests/localized-fonts-specs.js +33 -0
  168. package/internal/selection/selection.js +1 -6
  169. package/internal/selection/tests/selection-specs.js +6 -4
  170. package/internal/validators/tests/validators-specs.js +80 -0
  171. package/internal/validators/validators.js +14 -34
  172. package/package.json +9 -3
  173. package/resolution/ResolutionDecorator.js +4 -40
  174. package/resolution/index.js +0 -7
  175. package/resolution/resolution.js +42 -80
  176. package/resolution/tests/ResolutionDecorator-specs.js +4 -11
  177. package/resolution/tests/resolution-specs.js +2 -2
  178. package/useControlledState/tests/useControlledState-specs.js +15 -46
  179. package/useControlledState/useControlledState.js +11 -22
  180. package/useScroll/ScrollAnimator.js +49 -65
  181. package/useScroll/Scrollbar.js +22 -58
  182. package/useScroll/ScrollbarTrack.js +3 -19
  183. package/useScroll/useScroll.js +267 -454
  184. package/useScroll/utilDOM.js +8 -14
  185. package/useScroll/utilEvent.js +0 -4
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = exports.ClickAllow = void 0;
7
-
8
7
  var _platform = require("@enact/core/platform");
9
-
10
8
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
-
12
9
  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); } }
13
-
14
10
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
-
16
11
  // It's possible that emitting `onTap` will cause a DOM change before the mousedown fires resulting
17
12
  // in multiple tap/click events for the same user action. To avoid this, we store the last touchend
18
13
  // target and timestamp to compare against the next mouse down. If the timestamp is different (e.g
@@ -23,19 +18,15 @@ var _lastTouchEnd = {
23
18
  target: null,
24
19
  timeStamp: 0
25
20
  };
26
-
27
21
  var shouldAllowMouseDown = function shouldAllowMouseDown(ev) {
28
22
  return ev.timeStamp !== _lastTouchEnd.timeStamp || ev.target === _lastTouchEnd.target || _lastTouchEnd.target === null;
29
23
  };
30
-
31
24
  var ClickAllow = /*#__PURE__*/function () {
32
25
  function ClickAllow() {
33
26
  _classCallCheck(this, ClickAllow);
34
-
35
27
  this.lastTouchEndTime = 0;
36
28
  this.lastMouseUpTime = 0;
37
29
  }
38
-
39
30
  _createClass(ClickAllow, [{
40
31
  key: "setLastTouchEnd",
41
32
  value: function setLastTouchEnd(ev) {
@@ -55,24 +46,24 @@ var ClickAllow = /*#__PURE__*/function () {
55
46
  }, {
56
47
  key: "shouldAllowMouseEvent",
57
48
  value: function shouldAllowMouseEvent(ev) {
58
- var timeStamp = ev.timeStamp; // iOS Safari sends both touch and mouse events (with differing timestamps)
49
+ var timeStamp = ev.timeStamp;
59
50
 
51
+ // iOS Safari sends both touch and mouse events (with differing timestamps)
60
52
  return !_platform.platform.ios && this.lastTouchEndTime !== timeStamp && shouldAllowMouseDown(ev);
61
53
  }
62
54
  }, {
63
55
  key: "shouldAllowTap",
64
56
  value: function shouldAllowTap(ev) {
65
57
  var type = ev.type,
66
- timeStamp = ev.timeStamp; // Allow the custom tap event for a “click” when it’s actually a click and it’s not from the
67
- // last mouseup event which would have fired the click for us
58
+ timeStamp = ev.timeStamp;
68
59
 
60
+ // Allow the custom tap event for a “click” when it’s actually a click and it’s not from the
61
+ // last mouseup event which would have fired the click for us
69
62
  return type === 'click' && this.lastMouseUpTime !== timeStamp;
70
63
  }
71
64
  }]);
72
-
73
65
  return ClickAllow;
74
66
  }();
75
-
76
67
  exports.ClickAllow = ClickAllow;
77
68
  var _default = ClickAllow;
78
69
  exports["default"] = _default;
package/Touchable/Drag.js CHANGED
@@ -4,49 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.dragConfigPropType = exports.defaultDragConfig = exports["default"] = exports.Drag = void 0;
7
-
8
7
  var _clamp = _interopRequireDefault(require("ramda/src/clamp"));
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
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; }
15
-
16
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; }
17
-
18
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; }
19
-
20
13
  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); } }
21
-
22
14
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
23
-
24
15
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25
-
26
16
  var Tracking = {
27
17
  Untracked: 0,
28
18
  Active: 1,
29
19
  Paused: 2
30
20
  };
31
-
32
21
  var Drag = /*#__PURE__*/_createClass(function Drag() {
33
22
  var _this = this;
34
-
35
23
  _classCallCheck(this, Drag);
36
-
37
24
  this.dragConfig = null;
38
-
39
25
  this.isDragging = function () {
40
26
  return _this.dragConfig != null;
41
27
  };
42
-
43
28
  this.setContainerBounds = function (node) {
44
29
  var _this$dragConfig = _this.dragConfig,
45
- isGlobal = _this$dragConfig.global,
46
- boxSizing = _this$dragConfig.boxSizing;
30
+ isGlobal = _this$dragConfig.global,
31
+ boxSizing = _this$dragConfig.boxSizing;
47
32
  var bounds = null;
48
33
  if (!node) return;
49
-
50
34
  if (isGlobal) {
51
35
  bounds = {
52
36
  minX: 0,
@@ -55,8 +39,9 @@ var Drag = /*#__PURE__*/_createClass(function Drag() {
55
39
  maxY: window.innerHeight
56
40
  };
57
41
  } else {
58
- bounds = node.getBoundingClientRect(); // adjust for padding when using content-box
42
+ bounds = node.getBoundingClientRect();
59
43
 
44
+ // adjust for padding when using content-box
60
45
  if (boxSizing === 'content-box') {
61
46
  var computedStyle = window.getComputedStyle(node);
62
47
  bounds = {
@@ -67,36 +52,31 @@ var Drag = /*#__PURE__*/_createClass(function Drag() {
67
52
  };
68
53
  }
69
54
  }
70
-
71
55
  _this.bounds = bounds;
72
56
  };
73
-
74
57
  this.updatePosition = function (clientX, clientY) {
75
58
  var _this$bounds = _this.bounds,
76
- maxX = _this$bounds.maxX,
77
- maxY = _this$bounds.maxY,
78
- minX = _this$bounds.minX,
79
- minY = _this$bounds.minY;
59
+ maxX = _this$bounds.maxX,
60
+ maxY = _this$bounds.maxY,
61
+ minX = _this$bounds.minX,
62
+ minY = _this$bounds.minY;
80
63
  var x = (0, _clamp["default"])(minX, maxX, clientX) - minX;
81
64
  var y = (0, _clamp["default"])(minY, maxY, clientY) - minY;
82
-
83
65
  if (x !== _this.x || y !== _this.y) {
84
66
  _this.x = x;
85
67
  _this.y = y;
86
68
  return true;
87
69
  }
88
-
89
70
  return false;
90
71
  };
91
-
92
72
  this.begin = function (config, _ref, coords, node) {
93
73
  var noResume = _ref.noResume,
94
- onDrag = _ref.onDrag,
95
- onDragEnd = _ref.onDragEnd,
96
- onDragStart = _ref.onDragStart;
74
+ onDrag = _ref.onDrag,
75
+ onDragEnd = _ref.onDragEnd,
76
+ onDragStart = _ref.onDragStart;
97
77
  if (!onDrag && !onDragStart && !onDragEnd) return;
98
78
  var x = coords.x,
99
- y = coords.y;
79
+ y = coords.y;
100
80
  _this.tracking = Tracking.Untracked;
101
81
  _this.startX = x;
102
82
  _this.startY = y;
@@ -107,35 +87,29 @@ var Drag = /*#__PURE__*/_createClass(function Drag() {
107
87
  _this.onDrag = onDrag;
108
88
  _this.onDragStart = onDragStart;
109
89
  _this.onDragEnd = onDragEnd;
110
-
111
90
  _this.setContainerBounds(node);
112
-
113
91
  _this.move(coords);
114
92
  };
115
-
116
93
  this.updateProps = function (_ref2) {
117
94
  var onDrag = _ref2.onDrag,
118
- onDragEnd = _ref2.onDragEnd,
119
- onDragStart = _ref2.onDragStart;
95
+ onDragEnd = _ref2.onDragEnd,
96
+ onDragStart = _ref2.onDragStart;
120
97
  // Check `isDragging` gesture is not in progress. Check if gesture exists before updating the references to the `dragConfig`
121
- if (!_this.isDragging()) return; // This will update the `dragConfig` with the new value
98
+ if (!_this.isDragging()) return;
122
99
 
100
+ // This will update the `dragConfig` with the new value
123
101
  _this.onDrag = onDrag;
124
102
  _this.onDragStart = onDragStart;
125
103
  _this.onDragEnd = onDragEnd;
126
104
  };
127
-
128
105
  this.move = function (coords) {
129
106
  if (!_this.isDragging()) return;
130
107
  var moveTolerance = _this.dragConfig.moveTolerance;
131
-
132
108
  if (_this.tracking === Tracking.Untracked) {
133
109
  var dx = coords.x - _this.startX;
134
110
  var dy = coords.y - _this.startY;
135
-
136
111
  if (Math.sqrt(dx * dx + dy * dy) >= moveTolerance) {
137
112
  _this.tracking = Tracking.Active;
138
-
139
113
  if (_this.onDragStart) {
140
114
  _this.onDragStart(_objectSpread({
141
115
  type: 'onDragStart'
@@ -148,45 +122,35 @@ var Drag = /*#__PURE__*/_createClass(function Drag() {
148
122
  }, coords));
149
123
  }
150
124
  };
151
-
152
125
  this.blur = function () {
153
126
  if (!_this.isDragging()) return;
154
-
155
127
  if (!_this.dragConfig.global) {
156
128
  _this.end();
157
129
  }
158
130
  };
159
-
160
131
  this.end = function () {
161
132
  if (!_this.isDragging()) return;
162
-
163
133
  if (_this.onDragEnd && _this.tracking !== Tracking.Untracked) {
164
134
  _this.onDragEnd({
165
135
  type: 'onDragEnd'
166
136
  });
167
137
  }
168
-
169
138
  _this.tracking = Tracking.Untracked;
170
139
  _this.dragConfig = null;
171
140
  };
172
-
173
141
  this.enter = function () {
174
142
  if (!_this.isDragging()) return;
175
-
176
143
  if (_this.dragConfig.resume && _this.tracking === Tracking.Paused) {
177
144
  _this.tracking = Tracking.Active;
178
145
  }
179
146
  };
180
-
181
147
  this.leave = function () {
182
148
  if (!_this.isDragging()) return;
183
-
184
149
  if (!_this.dragConfig.global && _this.tracking === Tracking.Active) {
185
150
  _this.tracking = Tracking.Paused;
186
151
  }
187
152
  };
188
153
  });
189
-
190
154
  exports.Drag = Drag;
191
155
  var defaultDragConfig = {
192
156
  boxSizing: 'border-box',
@@ -194,13 +158,11 @@ var defaultDragConfig = {
194
158
  moveTolerance: 16
195
159
  };
196
160
  exports.defaultDragConfig = defaultDragConfig;
197
-
198
161
  var dragConfigPropType = _propTypes["default"].shape({
199
162
  boxSizing: _propTypes["default"].string,
200
163
  global: _propTypes["default"].bool,
201
164
  moveTolerance: _propTypes["default"].number
202
165
  });
203
-
204
166
  exports.dragConfigPropType = dragConfigPropType;
205
167
  var _default = Drag;
206
168
  exports["default"] = _default;
@@ -4,116 +4,92 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.flickConfigPropType = exports.defaultFlickConfig = exports["default"] = exports.Flick = void 0;
7
-
8
7
  var _util = require("@enact/core/util");
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
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; }
15
-
16
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; }
17
-
18
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; }
19
-
20
13
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
-
22
14
  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); } }
23
-
24
15
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
25
-
26
16
  var Flick = /*#__PURE__*/function () {
27
17
  function Flick() {
28
18
  var _this = this;
29
-
30
19
  _classCallCheck(this, Flick);
31
-
32
20
  this.begin = function (config, _ref, coords) {
33
21
  var onFlick = _ref.onFlick;
34
22
  _this.flickConfig = _objectSpread({}, config);
35
-
36
23
  if (_this.flickConfig.maxDuration !== null) {
37
24
  _this.cancelJob.startAfter(_this.flickConfig.maxDuration);
38
25
  }
39
-
40
26
  _this.tracking = !!onFlick;
41
27
  _this.moves.length = 0;
42
28
  _this.onFlick = onFlick;
43
-
44
29
  _this.move(coords);
45
30
  };
46
-
47
31
  this.updateProps = function (_ref2) {
48
32
  var onFlick = _ref2.onFlick;
49
33
  // Check `tracking` gesture is not in progress. Check if gesture exists before updating the references to the `onFlick`
50
- if (!_this.tracking) return; // This will update the `onFlick` with the new value
34
+ if (!_this.tracking) return;
51
35
 
36
+ // This will update the `onFlick` with the new value
52
37
  _this.onFlick = onFlick;
53
38
  };
54
-
55
39
  this.move = function (_ref3) {
56
40
  var x = _ref3.x,
57
- y = _ref3.y;
41
+ y = _ref3.y;
58
42
  if (!_this.tracking) return;
59
43
  var maxMoves = _this.flickConfig.maxMoves;
60
-
61
44
  _this.moves.push({
62
45
  x: x,
63
46
  y: y,
64
47
  t: window.performance.now()
65
- }); // track specified # of points
66
-
48
+ });
67
49
 
50
+ // track specified # of points
68
51
  if (_this.moves.length > maxMoves) {
69
52
  _this.moves.shift();
70
53
  }
71
54
  };
72
-
73
55
  this.blur = function () {
74
56
  _this.end();
75
57
  };
76
-
77
58
  this.cancel = function () {
78
59
  _this.tracking = false;
79
60
  };
80
-
81
61
  this.cancelJob = new _util.Job(this.cancel);
82
-
83
62
  this.end = function () {
84
63
  if (!_this.tracking) return;
85
64
  var minVelocity = _this.flickConfig.minVelocity;
86
-
87
65
  _this.cancelJob.stop();
88
-
89
66
  var moves = _this.moves;
90
-
91
67
  if (moves.length > 1) {
92
68
  // note: important to use up time to reduce flick
93
69
  // velocity based on time between move and up.
94
70
  var last = moves[moves.length - 1];
95
71
  var t = window.performance.now();
96
72
  var x = 0,
97
- y = 0; // take the greatest of flick between each tracked move and last move
73
+ y = 0;
98
74
 
75
+ // take the greatest of flick between each tracked move and last move
99
76
  for (var i = moves.length - 2, m; m = moves[i]; i--) {
100
77
  // this flick (this move - last move) / (this time - last time)
101
78
  var dt = t - m.t;
102
79
  var vx = (last.x - m.x) / dt;
103
- var vy = (last.y - m.y) / dt; // if either axis is a greater flick than previously recorded use this one
80
+ var vy = (last.y - m.y) / dt;
104
81
 
82
+ // if either axis is a greater flick than previously recorded use this one
105
83
  if (Math.abs(vx) > Math.abs(x) || Math.abs(vy) > Math.abs(y)) {
106
84
  x = vx;
107
85
  y = vy;
108
86
  }
109
87
  }
110
-
111
88
  var v = Math.sqrt(x * x + y * y);
112
-
113
89
  if (v > minVelocity) {
114
- var vertical = Math.abs(y) > Math.abs(x); // generate the flick using the start event so it has those coordinates
90
+ var vertical = Math.abs(y) > Math.abs(x);
91
+ // generate the flick using the start event so it has those coordinates
115
92
  // this.sendFlick(ti.startEvent, x, y, v);
116
-
117
93
  _this.onFlick({
118
94
  type: 'onFlick',
119
95
  direction: vertical ? 'vertical' : 'horizontal',
@@ -123,24 +99,19 @@ var Flick = /*#__PURE__*/function () {
123
99
  });
124
100
  }
125
101
  }
126
-
127
102
  _this.tracking = false;
128
103
  };
129
-
130
104
  this.tracking = false;
131
105
  this.moves = [];
132
106
  }
133
-
134
107
  _createClass(Flick, [{
135
108
  key: "isTracking",
136
109
  value: function isTracking() {
137
110
  return this.tracking;
138
111
  }
139
112
  }]);
140
-
141
113
  return Flick;
142
114
  }();
143
-
144
115
  exports.Flick = Flick;
145
116
  var defaultFlickConfig = {
146
117
  maxDuration: 250,
@@ -148,13 +119,11 @@ var defaultFlickConfig = {
148
119
  minVelocity: 0.1
149
120
  };
150
121
  exports.defaultFlickConfig = defaultFlickConfig;
151
-
152
122
  var flickConfigPropType = _propTypes["default"].shape({
153
123
  maxDuration: _propTypes["default"].number,
154
124
  maxMoves: _propTypes["default"].number,
155
125
  maxVelocity: _propTypes["default"].number
156
126
  });
157
-
158
127
  exports.flickConfigPropType = flickConfigPropType;
159
128
  var _default = Flick;
160
129
  exports["default"] = _default;