@enact/ui 4.5.2 → 4.6.1
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/AnnounceDecorator/Announce.js +1 -40
- package/AnnounceDecorator/AnnounceDecorator.js +3 -21
- package/AnnounceDecorator/tests/Announce-specs.js +2 -7
- package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +2 -6
- package/AnnounceDecorator/tests/useAnnounce-specs.js +8 -19
- package/AnnounceDecorator/useAnnounce.js +0 -6
- package/BodyText/BodyText.js +8 -28
- package/BodyText/tests/BodyText-specs.js +0 -19
- package/Button/Button.js +33 -63
- package/Button/tests/Button-specs.js +0 -26
- package/CHANGELOG.md +45 -0
- package/Cancelable/Cancelable.js +8 -47
- package/Cancelable/cancelHandler.js +5 -12
- package/Cancelable/modalHandler.js +3 -11
- package/Cancelable/tests/Cancelable-specs.js +3 -57
- package/Changeable/Changeable.js +2 -34
- package/Changeable/tests/Changeable-specs.js +20 -66
- package/ComponentOverride/ComponentOverride.js +1 -13
- package/FloatingLayer/FloatingLayer.js +17 -73
- package/FloatingLayer/FloatingLayerContainer.js +0 -15
- package/FloatingLayer/FloatingLayerDecorator.js +4 -17
- package/FloatingLayer/Scrim.js +9 -53
- package/FloatingLayer/index.js +0 -4
- package/FloatingLayer/package.json +3 -0
- package/FloatingLayer/tests/FloatingLayer-specs.js +8 -22
- package/FloatingLayer/tests/Scrim-specs.js +0 -9
- package/FloatingLayer/tests/useFloatingLayerDecorator-specs.js +0 -13
- package/FloatingLayer/useFloatingLayer.js +3 -14
- package/FloatingLayer/useFloatingLayerDecorator.js +3 -11
- package/ForwardRef/ForwardRef.js +1 -10
- package/GridListImageItem/GridListImageItem.js +18 -51
- package/Group/Group.js +5 -36
- package/Group/GroupItem.js +16 -33
- package/Group/tests/Group-specs.js +0 -32
- package/Heading/Heading.js +8 -36
- package/Heading/tests/Heading-specs.js +81 -14
- package/Icon/Icon.js +19 -53
- package/Icon/tests/Icon-specs.js +0 -22
- package/IconButton/IconButton.js +24 -57
- package/IconButton/tests/IconButton-specs.js +0 -7
- package/Image/Image.js +17 -46
- package/Image/tests/Image-specs.js +0 -14
- package/ImageItem/ImageItem.js +18 -47
- package/ImageItem/tests/ImageItem-specs.js +0 -25
- package/Item/Item.js +9 -33
- package/Item/tests/Item-specs.js +0 -24
- package/LabeledIcon/LabeledIcon.js +22 -53
- package/LabeledIcon/tests/LabeledIcon-specs.js +0 -14
- package/Layout/Cell.js +18 -44
- package/Layout/Layout.js +23 -46
- package/Layout/tests/Layout-specs.js +10 -39
- package/Marquee/MarqueeBase.js +29 -63
- package/Marquee/MarqueeController.js +11 -72
- package/Marquee/MarqueeDecorator.js +70 -196
- package/Marquee/index.js +1 -5
- package/Marquee/tests/Marquee-specs.js +295 -87
- package/Measurable/Measurable.js +12 -34
- package/Measurable/tests/Measurable-specs.js +115 -0
- package/Media/Media.js +15 -65
- package/Media/tests/Media-specs.js +168 -0
- package/Placeholder/PlaceholderControllerDecorator.js +7 -43
- package/Placeholder/PlaceholderDecorator.js +7 -38
- package/Placeholder/index.js +1 -5
- package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +25 -0
- package/Placeholder/tests/PlaceholderDecorator-specs.js +28 -0
- package/ProgressBar/ProgressBar.js +14 -45
- package/ProgressBar/tests/ProgressBar-specs.js +0 -17
- package/RadioDecorator/RadioControllerDecorator.js +7 -29
- package/RadioDecorator/RadioDecorator.js +9 -42
- package/RadioDecorator/tests/RadioDecorator-specs.js +12 -49
- package/Repeater/Repeater.js +9 -33
- package/Repeater/tests/Repeater-specs.js +0 -38
- package/Resizable/Resizable.js +9 -37
- package/Resizable/tests/Resizable-specs.js +34 -0
- package/Routable/Link.js +11 -47
- package/Routable/Routable.js +12 -35
- package/Routable/Route.js +0 -6
- package/Routable/Router.js +15 -58
- package/Routable/tests/Routable-specs.js +7 -33
- package/Routable/tests/Router-specs.js +18 -44
- package/Routable/useLink.js +4 -8
- package/Routable/util.js +18 -24
- package/Scrollable/ScrollAnimator.js +49 -65
- package/Scrollable/ScrollThumb.js +2 -13
- package/Scrollable/Scrollable.js +180 -387
- package/Scrollable/ScrollableNative.js +189 -392
- package/Scrollable/Scrollbar.js +30 -102
- package/Scroller/Scroller.js +15 -39
- package/Scroller/ScrollerBasic.js +34 -89
- package/Scroller/UiScrollerBase.js +37 -84
- package/Scroller/tests/Scroller-specs.js +56 -0
- package/Skinnable/Skinnable.js +11 -38
- package/Skinnable/tests/Skinnable-specs.js +3 -74
- package/Skinnable/tests/useSkins-specs.js +1 -13
- package/Skinnable/tests/util-specs.js +0 -14
- package/Skinnable/useSkins.js +8 -15
- package/Skinnable/util.js +9 -20
- package/Slider/Knob.js +5 -24
- package/Slider/PositionDecorator.js +16 -54
- package/Slider/Slider.js +29 -67
- package/Slider/tests/Slider-specs.js +94 -7
- package/Slider/utils.js +0 -2
- package/SlotItem/SlotItem.js +23 -45
- package/SlotItem/tests/SlotItem-specs.js +0 -5
- package/Slottable/Slottable.js +4 -12
- package/Slottable/tests/Slottable-specs.js +19 -46
- package/Slottable/tests/useSlots-specs.js +27 -65
- package/Slottable/useSlots.js +8 -33
- package/Spinner/Spinner.js +16 -43
- package/Spinner/tests/Spinner-specs.js +0 -15
- package/ToggleIcon/ToggleIcon.js +10 -36
- package/ToggleIcon/tests/ToggleIcon-specs.js +0 -16
- package/ToggleItem/ToggleItem.js +24 -57
- package/ToggleItem/tests/ToggleItem-specs.js +0 -30
- package/Toggleable/Toggle.js +1 -15
- package/Toggleable/Toggleable.js +12 -45
- package/Toggleable/tests/Toggleable-specs.js +28 -96
- package/Toggleable/useToggle.js +3 -19
- package/Touchable/ClickAllow.js +5 -14
- package/Touchable/Drag.js +16 -54
- package/Touchable/Flick.js +11 -42
- package/Touchable/Hold.js +21 -68
- package/Touchable/Pinch.js +185 -0
- package/Touchable/Touch.js +71 -76
- package/Touchable/Touchable.js +95 -75
- package/Touchable/config.js +27 -24
- package/Touchable/tests/Touchable-specs.js +360 -119
- package/Touchable/tests/useTouch-specs.js +6 -80
- package/Touchable/useTouch.js +57 -65
- package/Transition/Transition.js +37 -118
- package/Transition/tests/Transition-specs.js +20 -60
- package/ViewManager/Arranger.js +10 -22
- package/ViewManager/TransitionGroup.js +32 -107
- package/ViewManager/View.js +35 -91
- package/ViewManager/ViewManager.js +20 -84
- package/ViewManager/tests/View-specs.js +0 -17
- package/ViewManager/tests/ViewManager-specs.js +236 -305
- package/ViewManager/tests/test-utils.js +0 -8
- package/VirtualList/UiVirtualListBase.js +265 -409
- package/VirtualList/VirtualList.js +29 -69
- package/VirtualList/VirtualListBase.js +0 -3
- package/VirtualList/VirtualListBasic.js +273 -431
- package/VirtualList/tests/VirtualGridList-native-specs.js +161 -0
- package/VirtualList/tests/VirtualGridList-specs.js +614 -0
- package/VirtualList/tests/VirtualList-native-specs.js +152 -0
- package/VirtualList/tests/VirtualList-specs.js +423 -95
- package/internal/IdProvider/IdProvider.js +7 -21
- package/internal/IdProvider/Provider.js +4 -17
- package/internal/IdProvider/tests/IdProvider-specs.js +44 -0
- package/internal/IdProvider/tests/useId-specs.js +6 -20
- package/internal/IdProvider/useId.js +0 -6
- package/internal/Pure/Pure.js +3 -30
- package/internal/Pure/tests/Pure-specs.js +88 -0
- package/internal/localized-fonts/localized-fonts.js +33 -62
- package/internal/localized-fonts/tests/localized-fonts-specs.js +33 -0
- package/internal/selection/selection.js +1 -6
- package/internal/selection/tests/selection-specs.js +6 -4
- package/internal/validators/tests/validators-specs.js +80 -0
- package/internal/validators/validators.js +14 -34
- package/package.json +9 -3
- package/resolution/ResolutionDecorator.js +4 -40
- package/resolution/index.js +0 -7
- package/resolution/resolution.js +42 -80
- package/resolution/tests/ResolutionDecorator-specs.js +4 -11
- package/resolution/tests/resolution-specs.js +2 -2
- package/useControlledState/tests/useControlledState-specs.js +15 -46
- package/useControlledState/useControlledState.js +11 -22
- package/useScroll/ScrollAnimator.js +49 -65
- package/useScroll/Scrollbar.js +22 -58
- package/useScroll/ScrollbarTrack.js +3 -19
- package/useScroll/useScroll.js +267 -454
- package/useScroll/utilDOM.js +8 -14
- package/useScroll/utilEvent.js +0 -4
- package/AnnounceDecorator/AnnounceDecorator.d.ts +0 -64
- package/BodyText/BodyText.d.ts +0 -66
- package/Button/Button.d.ts +0 -125
- package/Cancelable/Cancelable.d.ts +0 -64
- package/Changeable/Changeable.d.ts +0 -54
- package/ComponentOverride/ComponentOverride.d.ts +0 -52
- package/ForwardRef/ForwardRef.d.ts +0 -22
- package/GridListImageItem/GridListImageItem.d.ts +0 -85
- package/Group/Group.d.ts +0 -107
- package/Heading/Heading.d.ts +0 -90
- package/Icon/Icon.d.ts +0 -88
- package/IconButton/IconButton.d.ts +0 -115
- package/Image/Image.d.ts +0 -113
- package/ImageItem/ImageItem.d.ts +0 -83
- package/Item/Item.d.ts +0 -64
- package/LabeledIcon/LabeledIcon.d.ts +0 -130
- package/Layout/Layout.d.ts +0 -247
- package/Marquee/index.d.ts +0 -258
- package/Measurable/Measurable.d.ts +0 -26
- package/Media/Media.d.ts +0 -99
- package/Placeholder/index.d.ts +0 -53
- package/ProgressBar/ProgressBar.d.ts +0 -92
- package/RadioDecorator/RadioDecorator.d.ts +0 -35
- package/Repeater/Repeater.d.ts +0 -83
- package/Resizable/Resizable.d.ts +0 -31
- package/Routable/Routable.d.ts +0 -148
- package/Scrollable/Scrollable.d.ts +0 -0
- package/Scroller/Scroller.d.ts +0 -276
- package/Skinnable/Skinnable.d.ts +0 -94
- package/Slider/Slider.d.ts +0 -202
- package/SlotItem/SlotItem.d.ts +0 -118
- package/Slottable/Slottable.d.ts +0 -22
- package/Spinner/Spinner.d.ts +0 -95
- package/ToggleIcon/ToggleIcon.d.ts +0 -90
- package/ToggleItem/ToggleItem.d.ts +0 -134
- package/Toggleable/Toggleable.d.ts +0 -103
- package/Touchable/Touchable.d.ts +0 -175
- package/Transition/Transition.d.ts +0 -196
- package/ViewManager/ViewManager.d.ts +0 -191
- package/VirtualList/VirtualList.d.ts +0 -530
- package/index.d.ts +0 -0
- package/internal/IdProvider/IdProvider.d.ts +0 -0
- package/internal/Pure/Pure.d.ts +0 -0
- package/internal/localized-fonts/localized-fonts.d.ts +0 -53
- package/internal/selection/selection.d.ts +0 -0
- package/internal/validators/validators.d.ts +0 -0
- package/resolution/index.d.ts +0 -187
- package/useControlledState/useControlledState.d.ts +0 -0
- package/useScroll/useScroll.d.ts +0 -0
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
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
32
|
+
noResume = _ref2.noResume,
|
|
33
|
+
onHoldStart = _ref2.onHoldStart,
|
|
34
|
+
onHoldEnd = _ref2.onHoldEnd,
|
|
35
|
+
onHold = _ref2.onHold;
|
|
49
36
|
var x = _ref3.x,
|
|
50
|
-
|
|
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;
|
|
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
|
-
|
|
82
|
-
|
|
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;
|
|
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
|
-
|
|
95
|
-
|
|
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
|
-
|
|
142
|
-
|
|
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
|
-
|
|
153
|
-
|
|
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
|
-
}
|
|
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;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.pinchConfigPropType = exports.defaultPinchConfig = exports["default"] = exports.Pinch = void 0;
|
|
7
|
+
var _clamp = _interopRequireDefault(require("ramda/src/clamp"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
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
|
+
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; }
|
|
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); } }
|
|
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; }
|
|
15
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
16
|
+
var Pinch = /*#__PURE__*/_createClass(function Pinch() {
|
|
17
|
+
var _this = this;
|
|
18
|
+
_classCallCheck(this, Pinch);
|
|
19
|
+
this.pinchConfig = null;
|
|
20
|
+
this.startScale = 1.0;
|
|
21
|
+
this.scale = 1.0;
|
|
22
|
+
this.isPinching = function () {
|
|
23
|
+
return _this.pinchConfig != null;
|
|
24
|
+
};
|
|
25
|
+
this.setContainerBounds = function (node) {
|
|
26
|
+
var _this$pinchConfig = _this.pinchConfig,
|
|
27
|
+
isGlobal = _this$pinchConfig.global,
|
|
28
|
+
boxSizing = _this$pinchConfig.boxSizing;
|
|
29
|
+
var bounds = null;
|
|
30
|
+
if (typeof window === 'undefined' || !node) return;
|
|
31
|
+
if (isGlobal) {
|
|
32
|
+
bounds = {
|
|
33
|
+
minX: 0,
|
|
34
|
+
minY: 0,
|
|
35
|
+
maxX: window.innerWidth,
|
|
36
|
+
maxY: window.innerHeight
|
|
37
|
+
};
|
|
38
|
+
} else {
|
|
39
|
+
bounds = node.getBoundingClientRect();
|
|
40
|
+
|
|
41
|
+
// adjust for padding when using content-box
|
|
42
|
+
if (boxSizing === 'content-box') {
|
|
43
|
+
var computedStyle = window.getComputedStyle(node);
|
|
44
|
+
bounds = {
|
|
45
|
+
minX: bounds.left + parseInt(computedStyle.paddingLeft),
|
|
46
|
+
minY: bounds.top + parseInt(computedStyle.paddingTop),
|
|
47
|
+
maxX: bounds.right - parseInt(computedStyle.paddingRight),
|
|
48
|
+
maxY: bounds.bottom - parseInt(computedStyle.paddingBottom)
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
bounds = {
|
|
52
|
+
minX: bounds.left,
|
|
53
|
+
minY: bounds.top,
|
|
54
|
+
maxX: bounds.right,
|
|
55
|
+
maxY: bounds.bottom
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
_this.bounds = bounds;
|
|
60
|
+
};
|
|
61
|
+
this.getBoundsCoords = function (_ref) {
|
|
62
|
+
var x = _ref.x,
|
|
63
|
+
y = _ref.y;
|
|
64
|
+
var _this$bounds = _this.bounds,
|
|
65
|
+
maxX = _this$bounds.maxX,
|
|
66
|
+
maxY = _this$bounds.maxY,
|
|
67
|
+
minX = _this$bounds.minX,
|
|
68
|
+
minY = _this$bounds.minY;
|
|
69
|
+
return {
|
|
70
|
+
x: (0, _clamp["default"])(minX, maxX, x) - minX,
|
|
71
|
+
y: (0, _clamp["default"])(minY, maxY, y) - minY
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
this.getDistance = function (coords) {
|
|
75
|
+
if (Array.isArray(coords)) {
|
|
76
|
+
var _this$getBoundsCoords = _this.getBoundsCoords(coords[0]),
|
|
77
|
+
x1 = _this$getBoundsCoords.x,
|
|
78
|
+
y1 = _this$getBoundsCoords.y;
|
|
79
|
+
var _this$getBoundsCoords2 = _this.getBoundsCoords(coords[1]),
|
|
80
|
+
x2 = _this$getBoundsCoords2.x,
|
|
81
|
+
y2 = _this$getBoundsCoords2.y;
|
|
82
|
+
var dx = x1 - x2;
|
|
83
|
+
var dy = y1 - y2;
|
|
84
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
85
|
+
}
|
|
86
|
+
return 0;
|
|
87
|
+
};
|
|
88
|
+
this.updateScale = function (scale) {
|
|
89
|
+
var _this$pinchConfig2 = _this.pinchConfig,
|
|
90
|
+
maxScale = _this$pinchConfig2.maxScale,
|
|
91
|
+
minScale = _this$pinchConfig2.minScale;
|
|
92
|
+
var newScale = (0, _clamp["default"])(minScale, maxScale, scale);
|
|
93
|
+
if (newScale !== _this.scale) {
|
|
94
|
+
_this.scale = newScale;
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
};
|
|
99
|
+
this.begin = function (config, _ref2, coords, node) {
|
|
100
|
+
var noResume = _ref2.noResume,
|
|
101
|
+
onPinch = _ref2.onPinch,
|
|
102
|
+
onPinchEnd = _ref2.onPinchEnd,
|
|
103
|
+
onPinchStart = _ref2.onPinchStart;
|
|
104
|
+
if (!onPinch && !onPinchStart && !onPinchEnd) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
_this.pinchConfig = _objectSpread(_objectSpread({}, config), {}, {
|
|
108
|
+
node: node,
|
|
109
|
+
resume: !noResume
|
|
110
|
+
});
|
|
111
|
+
_this.setContainerBounds(node);
|
|
112
|
+
_this.startDist = _this.getDistance(coords);
|
|
113
|
+
_this.previousDist = _this.startDist;
|
|
114
|
+
_this.startScale = _this.scale;
|
|
115
|
+
_this.onPinch = onPinch;
|
|
116
|
+
_this.onPinchStart = onPinchStart;
|
|
117
|
+
_this.onPinchEnd = onPinchEnd;
|
|
118
|
+
if (_this.onPinchStart) {
|
|
119
|
+
_this.onPinchStart({
|
|
120
|
+
type: 'onPinchStart',
|
|
121
|
+
coords: coords
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
this.updateProps = function (_ref3) {
|
|
126
|
+
var onPinch = _ref3.onPinch,
|
|
127
|
+
onPinchEnd = _ref3.onPinchEnd,
|
|
128
|
+
onPinchStart = _ref3.onPinchStart;
|
|
129
|
+
// Check `isPinching` gesture is not in progress. Check if gesture exists before updating the references to the `pinchConfig`
|
|
130
|
+
if (!_this.isPinching()) return;
|
|
131
|
+
|
|
132
|
+
// This will update the `pinchConfig` with the new value
|
|
133
|
+
_this.onPinch = onPinch;
|
|
134
|
+
_this.onPinchStart = onPinchStart;
|
|
135
|
+
_this.onPinchEnd = onPinchEnd;
|
|
136
|
+
};
|
|
137
|
+
this.move = function (coords) {
|
|
138
|
+
if (!_this.isPinching()) return;
|
|
139
|
+
var moveTolerance = _this.pinchConfig.moveTolerance;
|
|
140
|
+
var currentDist = _this.getDistance(coords);
|
|
141
|
+
var scale = currentDist / _this.startDist * _this.startScale;
|
|
142
|
+
if (Math.abs(_this.previousDist - currentDist) > moveTolerance && _this.onPinch && _this.updateScale(scale)) {
|
|
143
|
+
_this.onPinch({
|
|
144
|
+
type: 'onPinch',
|
|
145
|
+
scale: _this.scale,
|
|
146
|
+
coords: coords
|
|
147
|
+
});
|
|
148
|
+
_this.previousDist = currentDist;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
this.blur = function () {
|
|
152
|
+
if (!_this.isPinching()) return;
|
|
153
|
+
if (!_this.pinchConfig.global) {
|
|
154
|
+
_this.end();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
this.end = function () {
|
|
158
|
+
if (!_this.isPinching()) return;
|
|
159
|
+
if (_this.onPinchEnd) {
|
|
160
|
+
_this.onPinchEnd({
|
|
161
|
+
type: 'onPinchEnd'
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
_this.pinchConfig = null;
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
exports.Pinch = Pinch;
|
|
168
|
+
var defaultPinchConfig = {
|
|
169
|
+
boxSizing: 'border-box',
|
|
170
|
+
global: false,
|
|
171
|
+
maxScale: 4,
|
|
172
|
+
minScale: 0.5,
|
|
173
|
+
moveTolerance: 16
|
|
174
|
+
};
|
|
175
|
+
exports.defaultPinchConfig = defaultPinchConfig;
|
|
176
|
+
var pinchConfigPropType = _propTypes["default"].shape({
|
|
177
|
+
boxSizing: _propTypes["default"].string,
|
|
178
|
+
global: _propTypes["default"].bool,
|
|
179
|
+
maxScale: _propTypes["default"].number,
|
|
180
|
+
minScale: _propTypes["default"].number,
|
|
181
|
+
moveTolerance: _propTypes["default"].number
|
|
182
|
+
});
|
|
183
|
+
exports.pinchConfigPropType = pinchConfigPropType;
|
|
184
|
+
var _default = Pinch;
|
|
185
|
+
exports["default"] = _default;
|