@enact/ui 4.5.2 → 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 +30 -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 +29 -63
  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
package/Touchable/Hold.js CHANGED
@@ -4,50 +4,37 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.holdConfigPropType = exports.defaultHoldConfig = exports["default"] = exports.Hold = void 0;
7
-
8
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
12
9
  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
-
14
10
  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; }
15
-
16
11
  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; }
17
-
18
12
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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
  var Hold = /*#__PURE__*/function () {
25
16
  function Hold() {
26
17
  var _this = this;
27
-
28
18
  _classCallCheck(this, Hold);
29
-
30
19
  this.isHolding = function () {
31
20
  return _this.holdConfig != null;
32
21
  };
33
-
34
22
  this.isWithinTolerance = function (_ref) {
35
23
  var x = _ref.x,
36
- y = _ref.y;
24
+ y = _ref.y;
37
25
  var moveTolerance = _this.holdConfig.moveTolerance;
38
26
  var dx = _this.startX - x;
39
27
  var dy = _this.startY - y;
40
28
  return Math.sqrt(dx * dx + dy * dy) < moveTolerance;
41
29
  };
42
-
43
30
  this.begin = function (defaultConfig, _ref2, _ref3) {
44
31
  var holdConfig = _ref2.holdConfig,
45
- noResume = _ref2.noResume,
46
- onHoldStart = _ref2.onHoldStart,
47
- onHoldEnd = _ref2.onHoldEnd,
48
- onHold = _ref2.onHold;
32
+ noResume = _ref2.noResume,
33
+ onHoldStart = _ref2.onHoldStart,
34
+ onHoldEnd = _ref2.onHoldEnd,
35
+ onHold = _ref2.onHold;
49
36
  var x = _ref3.x,
50
- y = _ref3.y;
37
+ y = _ref3.y;
51
38
  if (!onHoldStart && !onHold) return;
52
39
  _this.startX = x;
53
40
  _this.startY = y;
@@ -56,47 +43,41 @@ var Hold = /*#__PURE__*/function () {
56
43
  });
57
44
  _this.onHold = onHold;
58
45
  _this.onHoldStart = onHoldStart;
59
- _this.onHoldEnd = onHoldEnd; // copy the events array since it is mutated for each hold
46
+ _this.onHoldEnd = onHoldEnd;
60
47
 
48
+ // copy the events array since it is mutated for each hold
61
49
  _this.holdConfig.events = _this.holdConfig.events.slice();
62
-
63
50
  _this.holdConfig.events.sort(function (a, b) {
64
51
  if (a.time < b.time) return -1;
65
52
  if (a.time > b.time) return 1;
66
53
  return 0;
67
54
  });
68
-
69
55
  _this.pulsing = false;
70
56
  _this.next = _this.holdConfig.events.shift();
71
-
72
57
  if (_this.next) {
73
58
  _this.holdStart = window.performance.now();
74
-
75
59
  _this.startJob();
76
60
  }
77
61
  };
78
-
79
62
  this.updateProps = function (_ref4) {
80
63
  var onHoldStart = _ref4.onHoldStart,
81
- onHoldEnd = _ref4.onHoldEnd,
82
- onHold = _ref4.onHold;
64
+ onHoldEnd = _ref4.onHoldEnd,
65
+ onHold = _ref4.onHold;
83
66
  // check `isHolding` gesture is not in progress. Check if gesture exists before updating the references to the `holdConfig`
84
- if (!_this.isHolding()) return; // Update the original values with new values of the gestures
67
+ if (!_this.isHolding()) return;
85
68
 
69
+ // Update the original values with new values of the gestures
86
70
  _this.onHold = onHold;
87
71
  _this.onHoldStart = onHoldStart;
88
72
  _this.onHoldEnd = onHoldEnd;
89
73
  };
90
-
91
74
  this.move = function (coords) {
92
75
  if (!_this.isHolding()) return;
93
76
  var _this$holdConfig = _this.holdConfig,
94
- cancelOnMove = _this$holdConfig.cancelOnMove,
95
- resume = _this$holdConfig.resume;
96
-
77
+ cancelOnMove = _this$holdConfig.cancelOnMove,
78
+ resume = _this$holdConfig.resume;
97
79
  if (cancelOnMove) {
98
80
  var shouldEnd = !_this.isWithinTolerance(coords);
99
-
100
81
  if (shouldEnd) {
101
82
  if (resume) {
102
83
  _this.suspend();
@@ -108,96 +89,75 @@ var Hold = /*#__PURE__*/function () {
108
89
  }
109
90
  }
110
91
  };
111
-
112
92
  this.blur = function () {
113
93
  if (!_this.isHolding()) return;
114
-
115
94
  if (!_this.holdConfig.global) {
116
95
  _this.end();
117
96
  }
118
97
  };
119
-
120
98
  this.end = function () {
121
99
  if (!_this.isHolding()) return;
122
-
123
100
  if (_this.pulsing && _this.onHoldEnd) {
124
101
  var time = window.performance.now() - _this.holdStart;
125
-
126
102
  _this.onHoldEnd({
127
103
  type: 'onHoldEnd',
128
104
  time: time
129
105
  });
130
106
  }
131
-
132
107
  _this.suspend();
133
-
134
108
  _this.pulsing = false;
135
109
  _this.holdConfig = null;
136
110
  };
137
-
138
111
  this.enter = function () {
139
112
  if (!_this.isHolding()) return;
140
113
  var _this$holdConfig2 = _this.holdConfig,
141
- cancelOnMove = _this$holdConfig2.cancelOnMove,
142
- resume = _this$holdConfig2.resume;
143
-
114
+ cancelOnMove = _this$holdConfig2.cancelOnMove,
115
+ resume = _this$holdConfig2.resume;
144
116
  if (resume && !cancelOnMove) {
145
117
  _this.resume();
146
118
  }
147
119
  };
148
-
149
120
  this.leave = function () {
150
121
  if (!_this.isHolding()) return;
151
122
  var _this$holdConfig3 = _this.holdConfig,
152
- isGlobal = _this$holdConfig3.global,
153
- resume = _this$holdConfig3.resume;
123
+ isGlobal = _this$holdConfig3.global,
124
+ resume = _this$holdConfig3.resume;
154
125
  if (isGlobal) return;
155
-
156
126
  if (resume) {
157
127
  _this.suspend();
158
128
  } else {
159
129
  _this.end();
160
130
  }
161
131
  };
162
-
163
132
  this.suspend = function () {
164
133
  clearInterval(_this.holdJob);
165
134
  _this.holdJob = null;
166
135
  };
167
-
168
136
  this.resume = function () {
169
137
  if (_this.holdJob !== null) return;
170
-
171
138
  _this.handlePulse();
172
-
173
139
  _this.startJob();
174
140
  };
175
-
176
141
  this.handlePulse = function () {
177
142
  var holdTime = window.performance.now() - _this.holdStart;
178
-
179
143
  var n = _this.next;
180
-
181
144
  while (n && n.time <= holdTime) {
182
145
  var events = _this.holdConfig.events;
183
146
  _this.pulsing = true;
184
-
185
147
  if (_this.onHoldStart) {
186
148
  _this.onHoldStart(_objectSpread({
187
149
  type: 'onHoldStart'
188
150
  }, n));
189
- } // if the hold is canceled from the onHoldStart handler, we should bail early and prevent
190
- // additional hold/pulse events
191
-
151
+ }
192
152
 
153
+ // if the hold is canceled from the onHoldStart handler, we should bail early and prevent
154
+ // additional hold/pulse events
193
155
  if (!_this.isHolding()) {
194
156
  _this.pulsing = false;
195
157
  break;
196
158
  }
197
-
198
159
  n = _this.next = events && events.shift();
199
160
  }
200
-
201
161
  if (_this.pulsing) {
202
162
  if (_this.onHold) {
203
163
  _this.onHold({
@@ -207,27 +167,22 @@ var Hold = /*#__PURE__*/function () {
207
167
  }
208
168
  }
209
169
  };
210
-
211
170
  this.holdJob = null;
212
171
  this.holdStart = null;
213
172
  this.pulsing = false;
214
173
  this.next = null;
215
174
  }
216
-
217
175
  _createClass(Hold, [{
218
176
  key: "startJob",
219
177
  value: function startJob() {
220
178
  var frequency = this.holdConfig.frequency;
221
-
222
179
  if (!this.holdJob) {
223
180
  this.holdJob = setInterval(this.handlePulse, frequency);
224
181
  }
225
182
  }
226
183
  }]);
227
-
228
184
  return Hold;
229
185
  }();
230
-
231
186
  exports.Hold = Hold;
232
187
  var defaultHoldConfig = {
233
188
  cancelOnMove: false,
@@ -240,7 +195,6 @@ var defaultHoldConfig = {
240
195
  moveTolerance: 16
241
196
  };
242
197
  exports.defaultHoldConfig = defaultHoldConfig;
243
-
244
198
  var holdConfigPropType = _propTypes["default"].shape({
245
199
  cancelOnMove: _propTypes["default"].bool,
246
200
  events: _propTypes["default"].arrayOf(_propTypes["default"].shape({
@@ -251,7 +205,6 @@ var holdConfigPropType = _propTypes["default"].shape({
251
205
  global: _propTypes["default"].bool,
252
206
  moveTolerance: _propTypes["default"].number
253
207
  });
254
-
255
208
  exports.holdConfigPropType = holdConfigPropType;
256
209
  var _default = Hold;
257
210
  exports["default"] = _default;
@@ -4,68 +4,49 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = exports.Touch = void 0;
7
-
8
7
  var _handle = require("@enact/core/handle");
9
-
10
8
  var _dispatcher = require("@enact/core/dispatcher");
11
-
12
9
  var _complement = _interopRequireDefault(require("ramda/src/complement"));
13
-
14
10
  var _platform = _interopRequireDefault(require("@enact/core/platform"));
15
-
16
11
  var _config = require("./config");
17
-
18
12
  var _state = require("./state");
19
-
20
13
  var _ClickAllow = _interopRequireDefault(require("./ClickAllow"));
21
-
22
14
  var _Drag = require("./Drag");
23
-
24
15
  var _Flick = require("./Flick");
25
-
26
16
  var _Hold = require("./Hold");
27
-
28
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
29
-
30
18
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
31
-
32
19
  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); } }
33
-
34
20
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
35
-
36
21
  var getEventCoordinates = function getEventCoordinates(ev) {
37
22
  var x = ev.clientX,
38
- y = ev.clientY,
39
- type = ev.type;
40
-
23
+ y = ev.clientY,
24
+ type = ev.type;
41
25
  if (type.indexOf('touch') === 0) {
42
26
  x = ev.targetTouches[0].clientX;
43
27
  y = ev.targetTouches[0].clientY;
44
28
  }
45
-
46
29
  return {
47
30
  x: x,
48
31
  y: y
49
32
  };
50
- }; // Establish a standard payload for onDown/onUp/onTap events and pass it along to a handler
51
-
33
+ };
52
34
 
35
+ // Establish a standard payload for onDown/onUp/onTap events and pass it along to a handler
53
36
  var makeTouchableEvent = function makeTouchableEvent(type) {
54
37
  return function (ev) {
55
38
  var target = ev.target,
56
- currentTarget = ev.currentTarget;
39
+ currentTarget = ev.currentTarget;
57
40
  var clientX = ev.clientX,
58
- clientY = ev.clientY,
59
- pageX = ev.pageX,
60
- pageY = ev.pageY;
61
-
41
+ clientY = ev.clientY,
42
+ pageX = ev.pageX,
43
+ pageY = ev.pageY;
62
44
  if (ev.changedTouches) {
63
45
  clientX = ev.changedTouches[0].clientX;
64
46
  clientY = ev.changedTouches[0].clientY;
65
47
  pageX = ev.changedTouches[0].pageX;
66
48
  pageY = ev.changedTouches[0].pageY;
67
49
  }
68
-
69
50
  return {
70
51
  type: type,
71
52
  target: target,
@@ -77,45 +58,48 @@ var makeTouchableEvent = function makeTouchableEvent(type) {
77
58
  };
78
59
  };
79
60
  };
80
-
81
61
  var isEnabled = (0, _handle.forProp)('disabled', false);
82
62
  var handleDown = (0, _handle.handle)(isEnabled, (0, _handle.adaptEvent)(makeTouchableEvent('onDown'), (0, _handle.forwardWithPrevent)('onDown')), (0, _handle.call)('activate'), (0, _handle.call)('startGesture')).named('handleDown');
83
63
  var handleUp = (0, _handle.handle)(isEnabled, (0, _handle.call)('endGesture'), (0, _handle.call)('isTracking'), (0, _handle.adaptEvent)(makeTouchableEvent('onUp'), (0, _handle.forwardWithPrevent)('onUp')), (0, _handle.adaptEvent)(makeTouchableEvent('onTap'), (0, _handle.forward)('onTap')))["finally"]((0, _handle.call)('deactivate')).named('handleUp');
84
64
  var handleEnter = (0, _handle.handle)(isEnabled, (0, _handle.forProp)('noResume', false), (0, _handle.call)('enterGesture'), (0, _handle.call)('isPaused'), (0, _handle.call)('activate')).named('handleEnter');
85
- var handleLeave = (0, _handle.handle)(isEnabled, (0, _handle.call)('leaveGesture'), (0, _handle.oneOf)([(0, _handle.forProp)('noResume', false), (0, _handle.call)('pause')], [_handle.returnsTrue, (0, _handle.call)('deactivate')])).named('handleLeave'); // Mouse event handlers
65
+ var handleLeave = (0, _handle.handle)(isEnabled, (0, _handle.call)('leaveGesture'), (0, _handle.oneOf)([(0, _handle.forProp)('noResume', false), (0, _handle.call)('pause')], [_handle.returnsTrue, (0, _handle.call)('deactivate')])).named('handleLeave');
66
+
67
+ // Mouse event handlers
86
68
 
87
69
  var handleMouseDown = (0, _handle.handle)((0, _handle.forward)('onMouseDown'), (0, _handle.call)('shouldAllowMouseEvent'), handleDown);
88
70
  var handleMouseEnter = (0, _handle.handle)((0, _handle.forward)('onMouseEnter'), handleEnter);
89
71
  var handleMouseMove = (0, _handle.handle)((0, _handle.forward)('onMouseMove'), (0, _handle.call)('moveGesture'));
90
72
  var handleMouseLeave = (0, _handle.handle)((0, _handle.forward)('onMouseLeave'), handleLeave);
91
73
  var handleMouseUp = (0, _handle.handle)((0, _handle.returnsTrue)((0, _handle.call)('setLastMouseUp')), (0, _handle.forward)('onMouseUp'), handleUp);
92
- var handleClick = (0, _handle.handle)(isEnabled, // wrapping another handler to always forward onClick but, if onTap should occur, it should
74
+ var handleClick = (0, _handle.handle)(isEnabled,
75
+ // wrapping another handler to always forward onClick but, if onTap should occur, it should
93
76
  // occur first to keep in sync with the up handler which emits onTap first
94
- (0, _handle.handle)((0, _handle.call)('shouldAllowTap'), (0, _handle.call)('activate'), handleUp)["finally"]((0, _handle.forward)('onClick'))); // Touch event handlers
77
+ (0, _handle.handle)((0, _handle.call)('shouldAllowTap'), (0, _handle.call)('activate'), handleUp)["finally"]((0, _handle.forward)('onClick')));
78
+
79
+ // Touch event handlers
95
80
 
96
81
  var handleTouchStart = (0, _handle.handle)((0, _handle.forward)('onTouchStart'), (0, _handle.call)('startTouch'), handleDown);
97
- var handleTouchMove = (0, _handle.handle)((0, _handle.forward)('onTouchMove'), (0, _handle.call)('isTracking'), // we don't receive enter/leave events during a touch so we have to simulate them by
82
+ var handleTouchMove = (0, _handle.handle)((0, _handle.forward)('onTouchMove'), (0, _handle.call)('isTracking'),
83
+ // we don't receive enter/leave events during a touch so we have to simulate them by
98
84
  // detecting when the touch leaves the boundary. oneOf returns the value of whichever
99
85
  // branch it follows so we append moveHold to either to handle moves that aren't
100
86
  // entering or leaving
101
87
  (0, _handle.adaptEvent)(makeTouchableEvent('onMove'), (0, _handle.forward)('onMove')), (0, _handle.oneOf)([(0, _handle.call)('hasTouchLeftTarget'), handleLeave], [_handle.returnsTrue, handleEnter])["finally"]((0, _handle.call)('moveGesture')));
102
- var handleTouchEnd = (0, _handle.handle)((0, _handle.forward)('onTouchEnd'), // block the next mousedown to prevent duplicate touchable events
103
- (0, _handle.returnsTrue)((0, _handle.call)('setLastTouchEnd')), (0, _handle.call)('isTracking'), (0, _complement["default"])((0, _handle.call)('hasTouchLeftTarget')), (0, _handle.returnsTrue)((0, _handle.call)('endTouch')), handleUp); // Global touchend/mouseup event handler to deactivate the component
88
+ var handleTouchEnd = (0, _handle.handle)((0, _handle.forward)('onTouchEnd'),
89
+ // block the next mousedown to prevent duplicate touchable events
90
+ (0, _handle.returnsTrue)((0, _handle.call)('setLastTouchEnd')), (0, _handle.call)('isTracking'), (0, _complement["default"])((0, _handle.call)('hasTouchLeftTarget')), (0, _handle.returnsTrue)((0, _handle.call)('endTouch')), handleUp);
104
91
 
92
+ // Global touchend/mouseup event handler to deactivate the component
105
93
  var handleGlobalUp = (0, _handle.handle)((0, _handle.call)('isTracking'), (0, _handle.call)('deactivate'))["finally"]((0, _handle.call)('endGesture'));
106
94
  var handleGlobalMove = (0, _handle.handle)((0, _handle.call)('isTracking'), (0, _handle.call)('containsCurrentTarget'), (0, _handle.call)('moveGesture'));
107
95
  var handleBlur = (0, _handle.handle)((0, _handle.forward)('onBlur'), (0, _handle.call)('hasFocus'), (0, _handle.call)('blurGesture'));
108
-
109
96
  var Touch = /*#__PURE__*/function () {
110
97
  function Touch() {
111
98
  var _this = this;
112
-
113
99
  _classCallCheck(this, Touch);
114
-
115
100
  this.getHandlers = function () {
116
101
  return _this.handlers;
117
102
  };
118
-
119
103
  this.context = {};
120
104
  this.target = null;
121
105
  this.targetHadFocus = false;
@@ -133,7 +117,6 @@ var Touch = /*#__PURE__*/function () {
133
117
  onMouseLeave: handleMouseLeave.bindAs(this, 'handleMouseLeave'),
134
118
  onMouseUp: handleMouseUp.bindAs(this, 'handleMouseUp')
135
119
  };
136
-
137
120
  if (_platform["default"].touch) {
138
121
  Object.assign(this.handlers, {
139
122
  onTouchStart: handleTouchStart.bindAs(this, 'handleTouchStart'),
@@ -141,11 +124,9 @@ var Touch = /*#__PURE__*/function () {
141
124
  onTouchEnd: handleTouchEnd.bindAs(this, 'handleTouchEnd')
142
125
  });
143
126
  }
144
-
145
127
  handleGlobalUp.bindAs(this, 'handleGlobalUp');
146
128
  handleGlobalMove.bindAs(this, 'handleGlobalMove');
147
129
  }
148
-
149
130
  _createClass(Touch, [{
150
131
  key: "setPropsAndContext",
151
132
  value: function setPropsAndContext(config, state, setState) {
@@ -170,7 +151,6 @@ var Touch = /*#__PURE__*/function () {
170
151
  if (_platform["default"].touch) {
171
152
  (0, _dispatcher.on)('touchend', this.handleGlobalUp, document);
172
153
  }
173
-
174
154
  (0, _dispatcher.on)('mouseup', this.handleGlobalUp, document);
175
155
  (0, _dispatcher.on)('mousemove', this.handleGlobalMove, document);
176
156
  }
@@ -180,11 +160,11 @@ var Touch = /*#__PURE__*/function () {
180
160
  if (_platform["default"].touch) {
181
161
  (0, _dispatcher.off)('touchend', this.handleGlobalUp, document);
182
162
  }
183
-
184
163
  (0, _dispatcher.off)('mouseup', this.handleGlobalUp, document);
185
164
  (0, _dispatcher.off)('mousemove', this.handleGlobalMove, document);
186
- } // State Management
165
+ }
187
166
 
167
+ // State Management
188
168
  }, {
189
169
  key: "setTarget",
190
170
  value: function setTarget(target) {
@@ -199,22 +179,18 @@ var Touch = /*#__PURE__*/function () {
199
179
  key: "activate",
200
180
  value: function activate(ev) {
201
181
  this.setTarget(ev.currentTarget);
202
-
203
182
  if (this.props.getActive) {
204
183
  this.context.setState(_state.States.Active);
205
184
  }
206
-
207
185
  return true;
208
186
  }
209
187
  }, {
210
188
  key: "deactivate",
211
189
  value: function deactivate() {
212
190
  this.clearTarget();
213
-
214
191
  if (this.props.getActive) {
215
192
  this.context.setState(_state.States.Inactive);
216
193
  }
217
-
218
194
  return true;
219
195
  }
220
196
  }, {
@@ -223,7 +199,6 @@ var Touch = /*#__PURE__*/function () {
223
199
  if (this.props.getActive && this.context.state === _state.States.Active) {
224
200
  this.context.setState(_state.States.Paused);
225
201
  }
226
-
227
202
  return true;
228
203
  }
229
204
  }, {
@@ -239,20 +214,19 @@ var Touch = /*#__PURE__*/function () {
239
214
  this.hold.updateProps(props);
240
215
  this.flick.updateProps(props);
241
216
  this.drag.updateProps(props);
242
- } // Gesture Support
217
+ }
243
218
 
219
+ // Gesture Support
244
220
  }, {
245
221
  key: "startTouch",
246
222
  value: function startTouch(_ref) {
247
223
  var target = _ref.target,
248
- currentTarget = _ref.currentTarget;
249
-
224
+ currentTarget = _ref.currentTarget;
250
225
  if (currentTarget.contains(target)) {
251
226
  (0, _dispatcher.on)('contextmenu', _handle.preventDefault);
252
227
  this.targetBounds = currentTarget.getBoundingClientRect();
253
228
  return true;
254
229
  }
255
-
256
230
  return false;
257
231
  }
258
232
  }, {
@@ -266,9 +240,9 @@ var Touch = /*#__PURE__*/function () {
266
240
  value: function startGesture(ev, props) {
267
241
  var coords = getEventCoordinates(ev);
268
242
  var _this$config = this.config,
269
- hold = _this$config.hold,
270
- flick = _this$config.flick,
271
- drag = _this$config.drag;
243
+ hold = _this$config.hold,
244
+ flick = _this$config.flick,
245
+ drag = _this$config.drag;
272
246
  this.hold.begin(hold, props, coords);
273
247
  this.flick.begin(flick, props, coords);
274
248
  this.drag.begin(drag, props, coords, this.target);
@@ -315,8 +289,9 @@ var Touch = /*#__PURE__*/function () {
315
289
  this.flick.end();
316
290
  this.drag.end();
317
291
  return true;
318
- } // Event handler utilities
292
+ }
319
293
 
294
+ // Event handler utilities
320
295
  }, {
321
296
  key: "isTracking",
322
297
  value: function isTracking() {
@@ -337,15 +312,14 @@ var Touch = /*#__PURE__*/function () {
337
312
  key: "hasTouchLeftTarget",
338
313
  value: function hasTouchLeftTarget(ev) {
339
314
  var _this2 = this;
340
-
341
315
  return Array.from(ev.changedTouches).reduce(function (hasLeft, _ref2) {
342
316
  var pageX = _ref2.pageX,
343
- pageY = _ref2.pageY;
317
+ pageY = _ref2.pageY;
344
318
  var _this2$targetBounds = _this2.targetBounds,
345
- left = _this2$targetBounds.left,
346
- right = _this2$targetBounds.right,
347
- top = _this2$targetBounds.top,
348
- bottom = _this2$targetBounds.bottom;
319
+ left = _this2$targetBounds.left,
320
+ right = _this2$targetBounds.right,
321
+ top = _this2$targetBounds.top,
322
+ bottom = _this2$targetBounds.bottom;
349
323
  return hasLeft && left > pageX || right < pageX || top > pageY || bottom < pageY;
350
324
  }, true);
351
325
  }
@@ -376,10 +350,8 @@ var Touch = /*#__PURE__*/function () {
376
350
  this.clickAllow.setLastTouchEnd(ev);
377
351
  }
378
352
  }]);
379
-
380
353
  return Touch;
381
354
  }();
382
-
383
355
  exports.Touch = Touch;
384
356
  var _default = Touch;
385
357
  exports["default"] = _default;