@twreporter/react-article-components 2.2.0-rc.0 → 2.2.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/lib/components/article-page.js +39 -108
- package/lib/components/aside/desktop-aside.js +25 -65
- package/lib/components/aside/desktop-tools.js +11 -57
- package/lib/components/aside/metadata.js +22 -89
- package/lib/components/aside/mobile-tool-bar.js +79 -175
- package/lib/components/aside/utils/theme.js +5 -11
- package/lib/components/body/annotation.js +15 -73
- package/lib/components/body/audio/audio-contexts.js +4 -16
- package/lib/components/body/audio/audio-provider.js +13 -48
- package/lib/components/body/audio/control-button.js +4 -28
- package/lib/components/body/audio/index.js +10 -56
- package/lib/components/body/audio/seek-bar.js +6 -23
- package/lib/components/body/audio/time.js +0 -6
- package/lib/components/body/blockquote.js +11 -52
- package/lib/components/body/brief.js +10 -55
- package/lib/components/body/centered-quote.js +10 -52
- package/lib/components/body/embedded-code.js +22 -101
- package/lib/components/body/headings.js +6 -23
- package/lib/components/body/image-diff.js +13 -66
- package/lib/components/body/image.js +11 -46
- package/lib/components/body/index.js +21 -118
- package/lib/components/body/infobox.js +13 -58
- package/lib/components/body/list.js +8 -29
- package/lib/components/body/multimedia.js +10 -29
- package/lib/components/body/paragraph.js +5 -23
- package/lib/components/body/slider/index.js +28 -96
- package/lib/components/body/slideshow/index.js +36 -107
- package/lib/components/body/tracking-section.js +7 -46
- package/lib/components/body/youtube.js +8 -41
- package/lib/components/donation-box.js +10 -44
- package/lib/components/img-with-placeholder/index.js +34 -106
- package/lib/components/leading/extend.js +6 -25
- package/lib/components/leading/fullscreen.js +17 -63
- package/lib/components/leading/index.js +2 -10
- package/lib/components/leading/normal.js +19 -64
- package/lib/components/leading/pink.js +20 -59
- package/lib/components/leading/small.js +6 -25
- package/lib/components/license.js +9 -40
- package/lib/components/link.js +8 -37
- package/lib/components/related/card.js +20 -73
- package/lib/components/related/index.js +25 -71
- package/lib/components/related/list.js +16 -70
- package/lib/components/related/mockup.js +10 -12
- package/lib/components/separation-curve.js +0 -15
- package/lib/components/table-of-contents/index.js +17 -46
- package/lib/components/table-of-contents/styled.js +10 -38
- package/lib/constants/anchor.js +4 -8
- package/lib/constants/css.js +2 -15
- package/lib/constants/element-alignment.js +2 -3
- package/lib/constants/prop-types/article-page.js +2 -7
- package/lib/constants/prop-types/aside.js +2 -8
- package/lib/constants/prop-types/body.js +4 -9
- package/lib/constants/prop-types/img-with-placeholder.js +2 -7
- package/lib/constants/prop-types/leading.js +8 -13
- package/lib/constants/prop-types/related.js +2 -7
- package/lib/constants/theme.js +2 -3
- package/lib/constants/typography.js +2 -5
- package/lib/contexts/dynamic-components-context.js +2 -8
- package/lib/managers/layout-manager.js +13 -28
- package/lib/managers/theme-manager.js +13 -32
- package/lib/managers/ui-manager.js +14 -26
- package/lib/utils/image.js +5 -14
- package/package.json +6 -6
|
@@ -1,54 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports["default"] = exports.Rail = exports.Progress = exports.Indicator = void 0;
|
|
9
|
-
|
|
10
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
8
|
var _react = _interopRequireDefault(require("react"));
|
|
13
|
-
|
|
14
9
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
15
|
-
|
|
16
10
|
var _color = require("@twreporter/core/lib/constants/color");
|
|
17
|
-
|
|
18
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
|
-
|
|
12
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
20
13
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
21
|
-
|
|
22
|
-
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
|
-
|
|
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
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
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
27
|
-
|
|
28
17
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
29
|
-
|
|
30
18
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
31
|
-
|
|
32
19
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
33
|
-
|
|
34
20
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
35
|
-
|
|
36
21
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
37
|
-
|
|
38
22
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
39
|
-
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
var Rail = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
|
23
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
25
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
26
|
+
var Rail = exports.Rail = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
|
43
27
|
displayName: "slider__Rail",
|
|
44
28
|
componentId: "sc-1pt06t8-0"
|
|
45
29
|
})(["width:100%;height:100%;background:", ";position:relative;cursor:", ";"], _color.colorGrayscale.gray400, function (props) {
|
|
46
30
|
return props.$isHeld ? 'grabbing' : 'pointer';
|
|
47
31
|
});
|
|
48
|
-
|
|
49
|
-
exports.Rail = Rail;
|
|
50
|
-
|
|
51
|
-
var Progress = /*#__PURE__*/_styledComponents["default"].div.attrs(function (_ref) {
|
|
32
|
+
var Progress = exports.Progress = /*#__PURE__*/_styledComponents["default"].div.attrs(function (_ref) {
|
|
52
33
|
var w = _ref.w;
|
|
53
34
|
return {
|
|
54
35
|
style: {
|
|
@@ -59,10 +40,7 @@ var Progress = /*#__PURE__*/_styledComponents["default"].div.attrs(function (_re
|
|
|
59
40
|
displayName: "slider__Progress",
|
|
60
41
|
componentId: "sc-1pt06t8-1"
|
|
61
42
|
})(["background:white;height:100%;position:absolute;top:0;left:0;"]);
|
|
62
|
-
|
|
63
|
-
exports.Progress = Progress;
|
|
64
|
-
|
|
65
|
-
var Indicator = /*#__PURE__*/_styledComponents["default"].div.attrs(function (_ref2) {
|
|
43
|
+
var Indicator = exports.Indicator = /*#__PURE__*/_styledComponents["default"].div.attrs(function (_ref2) {
|
|
66
44
|
var x = _ref2.x;
|
|
67
45
|
return {
|
|
68
46
|
style: {
|
|
@@ -75,19 +53,15 @@ var Indicator = /*#__PURE__*/_styledComponents["default"].div.attrs(function (_r
|
|
|
75
53
|
})(["width:10px;height:100%;background:", ";position:absolute;top:0;cursor:", ";"], _color.colorGrayscale.black, function (props) {
|
|
76
54
|
return props.$isHeld ? 'grabbing' : 'grab';
|
|
77
55
|
});
|
|
78
|
-
|
|
79
|
-
exports.Indicator = Indicator;
|
|
80
|
-
|
|
81
56
|
function funcWarn(funcName, err) {
|
|
82
57
|
console.warn("Error on `".concat(funcName, "`"), err);
|
|
83
58
|
}
|
|
59
|
+
|
|
84
60
|
/**
|
|
85
61
|
* Get the x coordinate (in pixel) of the left edge of browser viewport relative to the left edge of document.
|
|
86
62
|
*
|
|
87
63
|
* @returns {number}
|
|
88
64
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
65
|
function getViewportPositionX() {
|
|
92
66
|
try {
|
|
93
67
|
// `window.pageXOffset` works at most modern browsers.
|
|
@@ -100,14 +74,13 @@ function getViewportPositionX() {
|
|
|
100
74
|
return 0;
|
|
101
75
|
}
|
|
102
76
|
}
|
|
77
|
+
|
|
103
78
|
/**
|
|
104
79
|
* Get the x coordinate (in pixel) of the mouse position relative to the left edge of document
|
|
105
80
|
*
|
|
106
81
|
* @param {MouseEvent} mouseEvent
|
|
107
82
|
* @returns {number}
|
|
108
83
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
84
|
function getMousePositionX(mouseEvent) {
|
|
112
85
|
try {
|
|
113
86
|
return mouseEvent.pageX || mouseEvent.clientX + getViewportPositionX();
|
|
@@ -116,14 +89,13 @@ function getMousePositionX(mouseEvent) {
|
|
|
116
89
|
return 0;
|
|
117
90
|
}
|
|
118
91
|
}
|
|
92
|
+
|
|
119
93
|
/**
|
|
120
94
|
* Get the x coordinate (in pixel) of the touch position relative to the left edge of document
|
|
121
95
|
*
|
|
122
96
|
* @param {TouchEvent} touchEvent
|
|
123
97
|
* @returns {number}
|
|
124
98
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
99
|
function getTouchPositionX(touchEvent) {
|
|
128
100
|
try {
|
|
129
101
|
return touchEvent.touches[0].pageX;
|
|
@@ -132,14 +104,13 @@ function getTouchPositionX(touchEvent) {
|
|
|
132
104
|
return 0;
|
|
133
105
|
}
|
|
134
106
|
}
|
|
107
|
+
|
|
135
108
|
/**
|
|
136
109
|
* Get the x coordinates (in pixel) of left and right edges of the element relative to document.
|
|
137
110
|
*
|
|
138
111
|
* @param {Element} element
|
|
139
112
|
* @returns {Object}
|
|
140
113
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
114
|
function getHorizontalEdgeOfElement(element) {
|
|
144
115
|
try {
|
|
145
116
|
var elementEdgeRelaToViewport = element.getBoundingClientRect();
|
|
@@ -153,14 +124,13 @@ function getHorizontalEdgeOfElement(element) {
|
|
|
153
124
|
return {};
|
|
154
125
|
}
|
|
155
126
|
}
|
|
127
|
+
|
|
156
128
|
/**
|
|
157
129
|
* Get the element out bound width (includes border) in pixel
|
|
158
130
|
*
|
|
159
131
|
* @param {Element} element
|
|
160
132
|
* @returns {number}
|
|
161
133
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
134
|
function getElementOutBoundWidth(element) {
|
|
165
135
|
try {
|
|
166
136
|
var bound = element.getBoundingClientRect();
|
|
@@ -170,6 +140,7 @@ function getElementOutBoundWidth(element) {
|
|
|
170
140
|
return 0;
|
|
171
141
|
}
|
|
172
142
|
}
|
|
143
|
+
|
|
173
144
|
/**
|
|
174
145
|
* Calculate the relative position in target range with the same ratio in source range.
|
|
175
146
|
*
|
|
@@ -180,55 +151,44 @@ function getElementOutBoundWidth(element) {
|
|
|
180
151
|
* @param {number} targetMax
|
|
181
152
|
* @returns
|
|
182
153
|
*/
|
|
183
|
-
|
|
184
|
-
|
|
185
154
|
function project(sourceValue, sourceMin, sourceMax, targetMin, targetMax) {
|
|
186
155
|
if (sourceValue === sourceMin) return targetMin;
|
|
187
156
|
if (sourceValue === sourceMax) return targetMax;
|
|
188
157
|
var targetSourceRatio = (targetMax - targetMin) / (sourceMax - sourceMin);
|
|
189
158
|
return sourceValue * targetSourceRatio + targetMin;
|
|
190
159
|
}
|
|
160
|
+
|
|
191
161
|
/**
|
|
192
162
|
*
|
|
193
163
|
*
|
|
194
164
|
* @param {Event} e
|
|
195
165
|
*/
|
|
196
|
-
|
|
197
|
-
|
|
198
166
|
function pauseEvent(e) {
|
|
199
167
|
e.stopPropagation();
|
|
200
168
|
e.preventDefault();
|
|
201
169
|
}
|
|
170
|
+
|
|
202
171
|
/**
|
|
203
172
|
* Return the boolean value indicating that if there are multiple fingers on device
|
|
204
173
|
*
|
|
205
174
|
* @param {TouchEvent} e
|
|
206
175
|
* @returns {Boolean}
|
|
207
176
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
210
177
|
function isNotSimpleTouch(e) {
|
|
211
178
|
return e.touches.length > 1 || e.type.toLowerCase() === 'touchend' && e.touches.length > 0;
|
|
212
179
|
}
|
|
213
|
-
|
|
214
180
|
function ensureValueInRange(value, min, max) {
|
|
215
181
|
if (value < min) return min;
|
|
216
182
|
if (value > max) return max;
|
|
217
183
|
return value;
|
|
218
184
|
}
|
|
219
|
-
|
|
220
185
|
function noop() {}
|
|
221
|
-
|
|
222
|
-
var Slider = /*#__PURE__*/function (_React$Component) {
|
|
186
|
+
var Slider = exports["default"] = /*#__PURE__*/function (_React$Component) {
|
|
223
187
|
_inherits(Slider, _React$Component);
|
|
224
|
-
|
|
225
188
|
var _super = _createSuper(Slider);
|
|
226
|
-
|
|
227
189
|
function Slider(props) {
|
|
228
190
|
var _this;
|
|
229
|
-
|
|
230
191
|
_classCallCheck(this, Slider);
|
|
231
|
-
|
|
232
192
|
_this = _super.call(this, props);
|
|
233
193
|
_this.state = {
|
|
234
194
|
isIndicatorHeld: false,
|
|
@@ -238,8 +198,8 @@ var Slider = /*#__PURE__*/function (_React$Component) {
|
|
|
238
198
|
indicatorXMax: 10,
|
|
239
199
|
// The distance between the left edge of indicator at start and the left edge of it at end
|
|
240
200
|
indicatorOffset: 0 // The distance between where mousedown invoked and the left edge of indicator
|
|
241
|
-
|
|
242
201
|
};
|
|
202
|
+
|
|
243
203
|
_this._rail = /*#__PURE__*/_react["default"].createRef();
|
|
244
204
|
_this._indicator = /*#__PURE__*/_react["default"].createRef();
|
|
245
205
|
_this.handleResize = _this._handleResize.bind(_assertThisInitialized(_this));
|
|
@@ -252,21 +212,17 @@ var Slider = /*#__PURE__*/function (_React$Component) {
|
|
|
252
212
|
_this.preventNativeDragging = _this._preventNativeDragging.bind(_assertThisInitialized(_this));
|
|
253
213
|
return _this;
|
|
254
214
|
}
|
|
255
|
-
|
|
256
215
|
_createClass(Slider, [{
|
|
257
216
|
key: "componentDidMount",
|
|
258
217
|
value: function componentDidMount() {
|
|
259
218
|
this._setIndicatorXMaxToStateIfChanged();
|
|
260
|
-
|
|
261
219
|
window.addEventListener('resize', this.handleResize);
|
|
262
220
|
}
|
|
263
221
|
}, {
|
|
264
222
|
key: "componentWillUnMount",
|
|
265
223
|
value: function componentWillUnMount() {
|
|
266
224
|
window.removeEventListener('resize', this.handleResize);
|
|
267
|
-
|
|
268
225
|
this._removeDocumentMouseEvent();
|
|
269
|
-
|
|
270
226
|
this._removeDocumentTouchEvent();
|
|
271
227
|
}
|
|
272
228
|
}, {
|
|
@@ -297,10 +253,9 @@ var Slider = /*#__PURE__*/function (_React$Component) {
|
|
|
297
253
|
key: "_calcIndicatorXByValue",
|
|
298
254
|
value: function _calcIndicatorXByValue(value) {
|
|
299
255
|
var _value = value || this.props.value;
|
|
300
|
-
|
|
301
256
|
var _this$props = this.props,
|
|
302
|
-
|
|
303
|
-
|
|
257
|
+
min = _this$props.min,
|
|
258
|
+
max = _this$props.max;
|
|
304
259
|
var indicatorXMax = this.state.indicatorXMax;
|
|
305
260
|
return project(_value, min, max, 0, indicatorXMax);
|
|
306
261
|
}
|
|
@@ -308,19 +263,18 @@ var Slider = /*#__PURE__*/function (_React$Component) {
|
|
|
308
263
|
key: "_calcValueByIndicatorX",
|
|
309
264
|
value: function _calcValueByIndicatorX(indicatorX) {
|
|
310
265
|
var _indicatorX = indicatorX || this.state.indicatorX;
|
|
311
|
-
|
|
312
266
|
var indicatorXMax = this.state.indicatorXMax;
|
|
313
267
|
var _this$props2 = this.props,
|
|
314
|
-
|
|
315
|
-
|
|
268
|
+
min = _this$props2.min,
|
|
269
|
+
max = _this$props2.max;
|
|
316
270
|
return project(_indicatorX, 0, indicatorXMax, min, max);
|
|
317
271
|
}
|
|
318
272
|
}, {
|
|
319
273
|
key: "_calcIndicatorXByPointerX",
|
|
320
274
|
value: function _calcIndicatorXByPointerX(pointerX, forcedOffset) {
|
|
321
275
|
var _this$state = this.state,
|
|
322
|
-
|
|
323
|
-
|
|
276
|
+
indicatorOffset = _this$state.indicatorOffset,
|
|
277
|
+
indicatorXMax = _this$state.indicatorXMax;
|
|
324
278
|
var indicatorX = pointerX - (forcedOffset || indicatorOffset) - getHorizontalEdgeOfElement(this._rail.current).left;
|
|
325
279
|
return ensureValueInRange(indicatorX, 0, indicatorXMax);
|
|
326
280
|
}
|
|
@@ -333,14 +287,12 @@ var Slider = /*#__PURE__*/function (_React$Component) {
|
|
|
333
287
|
key: "_setIndicatorXMaxToStateIfChanged",
|
|
334
288
|
value: function _setIndicatorXMaxToStateIfChanged() {
|
|
335
289
|
var railRect = this._rail.current.getBoundingClientRect();
|
|
336
|
-
|
|
337
290
|
var nextIndicatorMax = railRect.right - railRect.left - getElementOutBoundWidth(this._indicator.current);
|
|
338
291
|
var _this$props3 = this.props,
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
292
|
+
value = _this$props3.value,
|
|
293
|
+
defaultValue = _this$props3.defaultValue,
|
|
294
|
+
min = _this$props3.min,
|
|
295
|
+
max = _this$props3.max;
|
|
344
296
|
if (nextIndicatorMax !== this.state.indicatorXMax) {
|
|
345
297
|
this.setState({
|
|
346
298
|
indicatorX: project(value || defaultValue, min, max, 0, nextIndicatorMax),
|
|
@@ -352,7 +304,6 @@ var Slider = /*#__PURE__*/function (_React$Component) {
|
|
|
352
304
|
key: "_handlePointerStart",
|
|
353
305
|
value: function _handlePointerStart(pointerOnIndicator, pointerX) {
|
|
354
306
|
var _this2 = this;
|
|
355
|
-
|
|
356
307
|
var indicatorOffset = pointerOnIndicator ? this._calcGrabOffset(pointerX) : getElementOutBoundWidth(this._indicator.current) / 2;
|
|
357
308
|
this.setState({
|
|
358
309
|
isIndicatorHeld: true,
|
|
@@ -366,12 +317,9 @@ var Slider = /*#__PURE__*/function (_React$Component) {
|
|
|
366
317
|
key: "_handleMouseDown",
|
|
367
318
|
value: function _handleMouseDown(e) {
|
|
368
319
|
if (e.button !== 0) return; // Do nothing if it's not the main button be clicked
|
|
369
|
-
|
|
370
320
|
var isMouseOnIndicator = e.target === this._indicator.current;
|
|
371
321
|
var mouseX = getMousePositionX(e);
|
|
372
|
-
|
|
373
322
|
this._handlePointerStart(isMouseOnIndicator, mouseX);
|
|
374
|
-
|
|
375
323
|
this._addDocumentMouseEvent();
|
|
376
324
|
}
|
|
377
325
|
}, {
|
|
@@ -380,24 +328,19 @@ var Slider = /*#__PURE__*/function (_React$Component) {
|
|
|
380
328
|
if (isNotSimpleTouch(e)) return;
|
|
381
329
|
var isTouchOnIndicator = e.target === this._indicator.current;
|
|
382
330
|
var touchX = getTouchPositionX(e);
|
|
383
|
-
|
|
384
331
|
this._handlePointerStart(isTouchOnIndicator, touchX);
|
|
385
|
-
|
|
386
332
|
this._addDocumentTouchEvent();
|
|
387
|
-
|
|
388
333
|
pauseEvent(e); // Prevent `onmousedown` event to be triggered
|
|
389
334
|
}
|
|
390
335
|
}, {
|
|
391
336
|
key: "_handlePointerMove",
|
|
392
337
|
value: function _handlePointerMove(nextIndicatorX) {
|
|
393
338
|
var _this3 = this;
|
|
394
|
-
|
|
395
339
|
if (this.state.indicatorX !== nextIndicatorX) {
|
|
396
340
|
this.setState({
|
|
397
341
|
indicatorX: nextIndicatorX
|
|
398
342
|
}, function () {
|
|
399
343
|
var onSeeking = _this3.props.onSeeking;
|
|
400
|
-
|
|
401
344
|
if (onSeeking !== noop) {
|
|
402
345
|
onSeeking({
|
|
403
346
|
value: _this3._calcValueByIndicatorX()
|
|
@@ -410,14 +353,12 @@ var Slider = /*#__PURE__*/function (_React$Component) {
|
|
|
410
353
|
key: "_handleMouseMove",
|
|
411
354
|
value: function _handleMouseMove(e) {
|
|
412
355
|
var nextIndicatorX = this._calcIndicatorXByPointerX(getMousePositionX(e));
|
|
413
|
-
|
|
414
356
|
this._handlePointerMove(nextIndicatorX);
|
|
415
357
|
}
|
|
416
358
|
}, {
|
|
417
359
|
key: "_handleTouchMove",
|
|
418
360
|
value: function _handleTouchMove(e) {
|
|
419
361
|
var nextIndicatorX = this._calcIndicatorXByPointerX(getTouchPositionX(e));
|
|
420
|
-
|
|
421
362
|
this._handlePointerMove(nextIndicatorX);
|
|
422
363
|
}
|
|
423
364
|
}, {
|
|
@@ -435,26 +376,22 @@ var Slider = /*#__PURE__*/function (_React$Component) {
|
|
|
435
376
|
key: "_handleMouseUp",
|
|
436
377
|
value: function _handleMouseUp(e) {
|
|
437
378
|
this._handlePointerEnd();
|
|
438
|
-
|
|
439
379
|
this._removeDocumentMouseEvent();
|
|
440
380
|
}
|
|
441
381
|
}, {
|
|
442
382
|
key: "_handleTouchEnd",
|
|
443
383
|
value: function _handleTouchEnd(e) {
|
|
444
384
|
this._handlePointerEnd();
|
|
445
|
-
|
|
446
385
|
this._removeDocumentTouchEvent();
|
|
447
386
|
}
|
|
448
387
|
}, {
|
|
449
388
|
key: "_calcGrabOffset",
|
|
450
389
|
value: function _calcGrabOffset(pointerX) {
|
|
451
390
|
var indicatorEdge = getHorizontalEdgeOfElement(this._indicator.current);
|
|
452
|
-
|
|
453
391
|
if (pointerX < indicatorEdge.left || pointerX > indicatorEdge.right) {
|
|
454
392
|
console.warn('Error on `_calcGrabOffset`: The pointer is not located in the indicator, return grab offset as 0.');
|
|
455
393
|
return 0;
|
|
456
394
|
}
|
|
457
|
-
|
|
458
395
|
return pointerX - indicatorEdge.left;
|
|
459
396
|
}
|
|
460
397
|
}, {
|
|
@@ -481,12 +418,8 @@ var Slider = /*#__PURE__*/function (_React$Component) {
|
|
|
481
418
|
}));
|
|
482
419
|
}
|
|
483
420
|
}]);
|
|
484
|
-
|
|
485
421
|
return Slider;
|
|
486
422
|
}(_react["default"].Component);
|
|
487
|
-
|
|
488
|
-
exports["default"] = Slider;
|
|
489
|
-
|
|
490
423
|
_defineProperty(Slider, "propTypes", {
|
|
491
424
|
// The `defaultValue`, `value`, `min`, and `max` share the same unit given by the consumer of this component.
|
|
492
425
|
defaultValue: _propTypes["default"].number,
|
|
@@ -504,7 +437,6 @@ _defineProperty(Slider, "propTypes", {
|
|
|
504
437
|
onSeekStart: _propTypes["default"].func,
|
|
505
438
|
onSeeking: _propTypes["default"].func
|
|
506
439
|
});
|
|
507
|
-
|
|
508
440
|
_defineProperty(Slider, "defaultProps", {
|
|
509
441
|
defaultValue: 0,
|
|
510
442
|
min: 0,
|